patch-grsec 3.9 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688106689106690106691106692106693106694106695106696106697106698106699106700106701106702106703106704106705106706106707106708106709106710106711106712106713106714106715106716106717106718106719106720106721106722106723106724106725106726106727106728106729106730106731106732106733106734106735106736106737106738106739106740106741106742106743106744106745106746106747106748106749106750106751106752106753106754106755106756106757106758106759106760106761106762106763106764106765106766106767106768106769106770106771106772106773106774106775106776106777106778106779106780106781106782106783106784106785106786106787106788106789106790106791106792106793106794106795106796106797106798106799106800106801106802106803106804106805106806106807106808106809106810106811106812106813106814106815106816106817106818106819106820106821106822106823106824106825106826106827106828106829106830106831106832106833106834106835106836106837106838106839106840106841106842106843106844106845106846106847106848106849106850106851106852106853106854106855106856106857106858106859106860106861106862106863106864106865106866106867106868106869106870106871106872106873106874106875106876106877106878106879106880106881106882106883106884106885106886106887106888106889106890106891106892106893106894106895106896106897106898106899106900106901106902106903106904106905106906106907106908106909106910106911106912106913106914106915106916106917106918106919106920106921106922106923106924106925106926106927106928106929106930106931106932106933106934106935106936106937106938106939106940106941106942106943106944106945106946106947106948106949106950106951106952106953106954106955106956106957106958106959106960106961106962106963106964106965106966106967106968106969106970106971106972106973106974106975106976106977106978106979106980106981106982106983106984106985106986106987106988106989106990106991106992106993106994106995106996106997106998106999107000107001107002107003107004107005107006107007107008107009107010107011107012107013107014107015107016107017107018107019107020107021107022107023107024107025107026107027107028107029107030107031107032107033107034107035107036107037107038107039107040107041107042107043107044107045107046107047107048107049107050107051107052107053107054107055107056107057107058107059107060107061107062107063107064107065107066107067107068107069107070107071107072107073107074107075107076107077107078107079107080107081107082107083107084107085107086107087107088107089107090107091107092107093107094107095107096107097107098107099107100107101107102107103107104107105107106107107107108107109107110107111107112107113107114107115107116107117107118107119107120107121107122107123107124107125107126107127107128107129107130107131107132107133107134107135107136107137107138107139107140107141107142107143107144107145107146107147107148107149107150107151107152107153107154107155107156107157107158107159107160107161107162107163107164107165107166107167107168107169107170107171107172107173107174107175107176107177107178107179107180107181107182107183107184107185107186107187107188107189107190107191107192107193107194107195107196107197107198107199107200107201107202107203107204107205107206107207107208107209107210107211107212107213107214107215107216107217107218107219107220107221107222107223107224107225107226107227107228107229107230107231107232107233107234107235107236107237107238107239107240107241107242107243107244107245107246107247107248107249107250107251107252107253107254107255107256107257107258107259107260107261107262107263107264107265107266107267107268107269107270107271107272107273107274107275107276107277107278107279107280107281107282107283107284107285107286107287107288107289107290107291107292107293107294107295107296107297107298107299107300107301107302107303107304107305107306107307107308107309107310107311107312107313107314107315107316107317107318107319107320107321107322107323107324107325107326107327107328107329107330107331107332107333107334107335107336107337107338107339107340107341107342107343107344107345107346107347107348107349107350107351107352107353107354107355107356107357107358107359107360107361107362107363107364107365107366107367107368107369107370107371107372107373107374107375107376107377107378107379107380107381107382107383107384107385107386107387107388107389107390107391107392107393107394107395107396107397107398107399107400107401107402107403107404107405107406107407107408107409107410107411107412107413107414107415107416107417107418107419107420107421107422107423107424107425107426107427107428107429107430107431107432107433107434107435107436107437107438107439107440107441107442107443107444107445107446107447107448107449107450107451107452107453107454107455107456107457107458107459107460107461107462107463107464107465107466107467107468107469107470107471107472107473107474107475107476107477107478107479107480107481107482107483107484107485107486107487107488107489107490107491107492107493107494107495107496107497107498107499107500107501107502107503107504107505107506107507107508107509107510107511107512107513107514107515107516107517107518107519107520107521107522107523107524107525107526107527107528107529107530107531107532107533107534107535107536107537107538107539107540107541107542107543107544107545107546107547107548107549107550107551107552107553107554107555107556107557107558107559107560107561107562107563107564107565107566107567107568107569107570107571107572107573107574107575107576107577107578107579107580107581107582107583107584107585107586107587107588107589107590107591107592107593107594107595107596107597107598107599107600107601107602107603107604107605107606107607107608107609107610107611107612107613107614107615107616107617107618107619107620107621107622107623107624107625107626107627107628107629107630107631107632107633107634107635107636107637107638107639107640107641107642107643107644107645107646107647107648107649107650107651107652107653107654107655107656107657107658107659107660107661107662107663107664107665107666107667107668107669107670107671107672107673107674107675107676107677107678107679107680107681107682107683107684107685107686107687107688107689107690107691107692107693107694107695107696107697107698107699107700107701107702107703107704107705107706107707107708107709107710107711107712107713107714107715107716107717107718107719107720107721107722107723107724107725107726107727107728107729107730107731107732107733107734107735107736107737107738107739107740107741107742107743107744107745107746107747107748107749107750107751107752107753107754107755107756107757107758107759107760107761107762107763107764107765107766107767107768107769107770107771107772107773107774107775107776107777107778107779107780107781107782107783107784107785107786107787107788107789107790107791107792107793107794107795107796107797107798107799107800107801107802107803107804107805107806107807107808107809107810107811107812107813107814107815107816107817107818107819107820107821107822107823107824107825107826107827107828107829107830107831107832107833107834107835107836107837107838107839107840107841107842107843107844107845107846107847107848107849107850107851107852107853107854107855107856107857107858107859107860107861107862107863107864107865107866107867107868107869107870107871107872107873107874107875107876107877107878107879107880107881107882107883107884107885107886107887107888107889107890107891107892107893107894107895107896107897107898107899107900107901107902107903107904107905107906107907107908107909107910107911107912107913107914107915107916107917107918107919107920107921107922107923107924107925107926107927107928107929107930107931107932107933107934107935107936107937107938107939107940107941107942107943107944107945107946107947107948107949107950107951107952107953107954107955107956107957107958107959107960107961107962107963107964107965107966107967107968107969107970107971107972107973107974107975107976107977107978107979107980107981107982107983107984107985107986107987107988107989107990107991107992107993107994107995107996107997107998107999108000108001108002108003108004108005108006108007108008108009108010108011108012108013108014108015108016108017108018108019108020108021108022108023108024108025108026108027108028108029108030108031108032108033108034108035108036108037108038108039108040108041108042108043108044108045108046108047108048108049108050108051108052108053108054108055108056108057108058108059108060108061108062108063108064108065108066108067108068108069108070108071108072108073108074108075108076108077108078108079108080108081108082108083108084108085108086108087108088108089108090108091108092108093108094108095108096108097108098108099108100108101108102108103108104108105108106108107108108108109108110108111108112108113108114108115108116108117108118108119108120108121108122108123108124108125108126108127108128108129108130108131108132108133108134108135108136108137108138108139108140108141108142108143108144108145108146108147108148108149108150108151108152108153108154108155108156108157108158108159108160108161108162108163108164108165108166108167108168108169108170108171108172108173108174108175108176108177108178108179108180108181108182108183108184108185108186108187108188108189108190108191108192108193108194108195108196108197108198108199108200108201108202108203108204108205108206108207108208108209108210108211108212108213108214108215108216108217108218108219108220108221108222108223108224108225108226108227108228108229108230108231108232108233108234108235108236108237108238108239108240108241108242108243108244108245108246108247108248108249108250108251108252108253108254108255108256108257108258108259108260108261108262108263108264108265108266108267108268108269108270108271108272108273108274108275108276108277108278108279108280108281108282108283108284108285108286108287108288108289108290108291108292108293108294108295108296108297108298108299108300108301108302108303108304108305108306108307108308108309108310108311108312108313108314108315108316108317108318108319108320108321108322108323108324108325108326108327108328108329108330108331108332108333108334108335108336108337108338108339108340108341108342108343108344108345108346108347108348108349108350108351108352108353108354108355108356108357108358108359108360108361108362108363108364108365108366108367108368108369108370108371108372108373108374108375108376108377108378108379108380108381108382108383108384108385108386108387108388108389108390108391108392108393108394108395108396108397108398108399108400108401108402108403108404108405108406108407108408108409108410108411108412108413108414108415108416108417108418108419108420108421108422108423108424108425108426108427108428108429108430108431108432108433108434108435108436108437108438108439108440108441108442108443108444108445108446108447108448108449108450108451108452108453108454108455108456108457108458108459108460108461108462108463108464108465108466108467108468108469108470108471108472108473108474108475108476108477108478108479108480108481108482108483108484108485108486108487108488108489108490108491108492108493108494108495108496108497108498108499108500108501108502108503108504108505108506108507108508108509108510108511108512108513108514108515108516108517108518108519108520108521108522108523108524108525108526108527108528108529108530108531108532108533108534108535108536108537108538108539108540108541108542108543108544108545108546108547108548108549108550108551108552108553108554108555108556108557108558108559108560108561108562108563108564108565108566108567108568108569108570108571108572108573108574108575108576108577108578108579108580108581108582108583108584108585108586108587108588108589108590108591108592108593108594108595108596108597108598108599108600108601108602108603108604108605108606108607108608108609108610108611108612108613108614108615108616108617108618108619108620108621108622108623108624108625108626108627108628108629108630108631108632108633108634108635108636108637108638108639108640108641108642108643108644108645108646108647108648108649108650108651108652108653108654108655108656108657108658108659108660108661108662108663108664108665108666108667108668108669108670108671108672108673108674108675108676108677108678108679108680108681108682108683108684108685108686108687108688108689108690108691108692108693108694108695108696108697108698108699108700108701108702108703108704108705108706108707108708108709108710108711108712108713108714108715108716108717108718108719108720108721108722108723108724108725108726108727108728108729108730108731108732108733108734108735108736108737108738108739108740108741108742108743108744108745108746108747108748108749108750108751108752108753108754108755108756108757108758108759108760108761108762108763108764108765108766108767108768108769108770108771108772108773108774108775108776108777108778108779108780108781108782108783108784108785108786108787108788108789108790108791108792108793108794108795108796108797108798108799108800108801108802108803108804108805108806108807108808108809108810108811108812108813108814108815108816108817108818108819108820108821108822108823108824108825108826108827108828108829108830108831108832108833108834108835108836108837108838108839108840108841108842108843108844108845108846108847108848108849108850108851108852108853108854108855108856108857108858108859108860108861108862108863108864108865108866108867108868108869108870108871108872108873108874108875108876108877108878108879108880108881108882108883108884108885108886108887108888108889108890108891108892108893108894108895108896108897108898108899108900108901108902108903108904108905108906108907108908108909108910108911108912108913108914108915108916108917108918108919108920108921108922108923108924108925108926108927108928108929108930108931108932108933108934108935108936108937108938108939108940108941108942108943108944108945108946108947108948108949108950108951108952108953108954108955108956108957108958108959108960108961108962108963108964108965108966108967108968108969108970108971108972108973108974108975108976108977108978108979108980108981108982108983108984108985108986108987108988108989108990108991108992108993108994108995108996108997108998108999109000109001109002109003109004109005109006109007109008109009109010109011109012109013109014109015109016109017109018109019109020109021109022109023109024109025109026109027109028109029109030109031109032109033109034109035109036109037109038109039109040109041109042109043109044109045109046109047109048109049109050109051109052109053109054109055109056109057109058109059109060109061109062109063109064109065109066109067109068109069109070109071109072109073109074109075109076109077109078109079109080109081109082109083109084109085109086109087109088109089109090109091109092109093109094109095109096109097109098109099109100109101109102109103109104109105109106109107109108109109109110109111109112109113109114109115109116109117109118109119109120109121109122109123109124109125109126109127109128109129109130109131109132109133109134109135109136109137109138109139109140109141109142109143109144109145109146109147109148109149109150109151109152109153109154109155109156109157109158109159109160109161109162109163109164109165109166109167109168109169109170109171109172109173109174109175109176109177109178109179109180109181109182109183109184109185109186109187109188109189109190109191109192109193109194109195109196109197109198109199109200109201109202109203109204109205109206109207109208109209109210109211109212109213109214109215109216109217109218109219109220109221109222109223109224109225109226109227109228109229109230109231109232109233109234109235109236109237109238109239109240109241109242109243109244109245109246109247109248109249109250109251109252109253109254109255109256109257109258109259109260109261109262109263109264109265109266109267109268109269109270109271109272109273109274109275109276109277109278109279109280109281109282109283109284109285109286109287109288109289109290109291109292109293109294109295109296109297109298109299109300109301109302109303109304109305109306109307109308109309109310109311109312109313109314109315109316109317109318109319109320109321109322109323109324109325109326109327109328109329109330109331109332109333109334109335109336109337109338109339109340109341109342109343109344109345109346109347109348109349109350109351109352109353109354109355109356109357109358109359109360109361109362109363109364109365109366109367109368109369109370109371109372109373109374109375109376109377109378109379109380109381109382109383109384109385109386109387109388109389109390109391109392109393109394109395109396109397109398109399109400109401109402109403109404109405109406109407109408109409109410109411109412109413109414109415109416109417109418109419109420109421109422109423109424109425109426109427109428109429109430109431109432109433109434109435109436109437109438109439109440109441109442109443109444109445109446109447109448109449109450109451109452109453109454109455109456109457109458109459109460109461109462109463109464109465109466109467109468109469109470109471109472109473109474109475109476109477109478109479109480109481109482109483109484109485109486109487109488109489109490109491109492109493109494109495109496109497109498109499109500109501109502109503109504109505109506109507109508109509109510109511109512109513109514109515109516109517109518109519109520109521109522109523109524109525109526109527109528109529109530109531109532109533109534109535109536109537109538109539109540109541109542109543109544109545109546109547109548109549109550109551109552109553109554109555109556109557109558109559109560109561109562109563109564109565109566109567109568109569109570109571109572109573109574109575109576109577109578109579109580109581109582109583109584109585109586109587109588109589109590109591109592109593109594109595109596109597109598109599109600109601109602109603109604109605109606109607109608109609109610109611109612109613109614109615109616109617109618109619109620109621109622109623109624109625109626109627109628109629109630109631109632109633109634109635109636109637109638109639109640109641109642109643109644109645109646109647109648109649109650109651109652109653109654109655109656109657109658109659109660109661109662109663109664109665109666109667109668109669109670109671109672109673109674109675109676109677109678109679109680109681109682109683109684109685109686109687109688109689109690109691109692109693109694109695109696109697109698109699109700109701109702109703109704109705109706109707109708109709109710109711109712109713109714109715109716109717109718109719109720109721109722109723109724109725109726109727109728109729109730109731109732109733109734109735109736109737109738109739109740109741109742109743109744109745109746109747109748109749109750109751109752109753109754109755109756109757109758109759109760109761109762109763109764109765109766109767109768109769109770109771109772109773109774109775109776109777109778109779109780109781109782109783109784109785109786109787109788109789109790109791109792109793109794109795109796109797109798109799109800109801109802109803109804109805109806109807109808109809109810109811109812109813109814109815109816109817109818109819109820109821109822109823109824109825109826109827109828109829109830109831109832109833109834109835109836109837109838109839109840109841109842109843109844109845109846109847109848109849109850109851109852109853109854109855109856109857109858109859109860109861109862109863109864109865109866109867109868109869109870109871109872109873109874109875109876109877109878109879109880109881109882109883109884109885109886109887109888109889109890109891109892109893109894109895109896109897109898109899109900109901109902109903109904109905109906109907109908109909109910109911109912109913109914109915109916109917109918109919109920109921109922109923109924109925109926109927109928109929109930109931109932109933109934109935109936109937109938109939109940109941109942109943109944109945109946109947109948109949109950109951109952109953109954109955109956109957109958109959109960109961109962109963109964109965109966109967109968109969109970109971109972109973109974109975109976109977109978109979109980109981109982109983109984109985109986109987109988109989109990109991109992109993109994109995109996109997109998109999110000110001110002110003110004110005110006110007110008110009110010110011110012110013110014110015110016110017110018110019110020110021110022110023110024110025110026110027110028110029110030110031110032110033110034110035110036110037110038110039110040110041110042110043110044110045110046110047110048110049110050110051110052110053110054110055110056110057110058110059110060110061110062110063110064110065110066110067110068110069110070110071110072110073110074110075110076110077110078110079110080110081110082110083110084110085110086110087110088110089110090110091110092110093110094110095110096110097110098110099110100110101110102110103110104110105110106110107110108110109110110110111110112110113110114110115110116110117110118110119110120110121110122110123110124110125110126110127110128110129110130110131110132110133110134110135110136110137110138110139110140110141110142110143110144110145110146110147110148110149110150110151110152110153110154110155110156110157110158110159110160110161110162110163110164110165110166110167110168110169110170110171110172110173110174110175110176110177110178110179110180110181110182110183110184110185110186110187110188110189110190110191110192110193110194110195110196110197110198110199110200110201110202110203110204110205110206110207110208110209110210110211110212110213110214110215110216110217110218110219110220110221110222110223110224110225110226110227110228110229110230110231110232110233110234110235110236110237110238110239110240110241110242110243110244110245110246110247110248110249110250110251110252110253110254110255110256110257110258110259110260110261110262110263110264110265110266110267110268110269110270110271110272110273110274110275110276110277110278110279110280110281110282110283110284110285110286110287110288110289110290110291110292110293110294110295110296110297110298110299110300110301110302110303110304110305110306110307110308110309110310110311110312110313110314110315110316110317110318110319110320110321110322110323110324110325110326110327110328110329110330110331110332110333110334110335110336110337110338110339110340110341110342110343110344110345110346110347110348110349110350110351110352110353110354110355110356110357110358110359110360110361110362110363110364110365110366110367110368110369110370110371110372110373110374110375110376110377110378110379110380110381110382110383110384110385110386110387110388110389110390110391110392110393110394110395110396110397110398110399110400110401110402110403110404110405110406110407110408110409110410110411110412110413110414110415110416110417110418110419110420110421110422110423110424110425110426110427110428110429110430110431110432110433110434110435110436110437110438110439110440110441110442110443110444110445110446110447110448110449110450110451110452110453110454110455110456110457110458110459110460110461110462110463110464110465110466110467110468110469110470110471110472110473110474110475110476110477110478110479110480110481110482110483110484110485110486110487110488110489110490110491110492110493110494110495110496110497110498110499110500110501110502110503110504110505110506110507110508110509110510110511110512110513110514110515110516110517110518110519110520110521110522110523110524110525110526110527110528110529110530110531110532110533110534110535110536110537110538110539110540110541110542110543110544110545110546110547110548110549110550110551110552110553110554110555110556110557110558110559110560110561110562110563110564110565110566110567110568110569110570110571110572110573110574110575110576110577110578110579110580110581110582110583110584110585110586110587110588110589110590110591110592110593110594110595110596110597110598110599110600110601110602110603110604110605110606110607110608110609110610110611110612110613110614110615110616110617110618110619110620110621110622110623110624110625110626110627110628110629110630110631110632110633110634110635110636110637110638110639110640110641110642110643110644110645110646110647110648110649110650110651110652110653110654110655110656110657110658110659110660110661110662110663110664110665110666110667110668110669110670110671110672110673110674110675110676110677110678110679110680110681110682110683110684110685110686110687110688110689110690110691110692110693110694110695110696110697110698110699110700110701110702110703110704110705110706110707110708110709110710110711110712110713110714110715110716110717110718110719110720110721110722110723110724110725110726110727110728110729110730110731110732110733110734110735110736110737110738110739110740110741110742110743110744110745110746110747110748110749110750110751110752110753110754110755110756110757110758110759110760110761110762110763110764110765110766110767110768110769110770110771110772110773110774110775110776110777110778110779110780110781110782110783110784110785110786110787110788110789110790110791110792110793110794110795110796110797110798110799110800110801110802110803110804110805110806110807110808110809110810110811110812110813110814110815110816110817110818110819110820110821110822110823110824110825110826110827110828110829110830110831110832110833110834110835110836110837110838110839110840110841110842110843110844110845110846110847110848110849110850110851110852110853110854110855110856110857110858110859110860110861110862110863110864110865110866110867110868110869110870110871110872110873110874110875110876110877110878110879110880110881110882110883110884110885110886110887110888110889110890110891110892110893110894110895110896110897110898110899110900110901110902110903110904110905110906110907110908110909110910110911110912110913110914110915110916110917110918110919110920110921110922110923110924110925110926110927110928110929110930110931110932110933110934110935110936110937110938110939110940110941110942110943110944110945110946110947110948110949110950110951110952110953110954110955110956110957110958110959110960110961110962110963110964110965110966110967110968110969110970110971110972110973110974110975110976110977110978110979110980110981110982110983110984110985110986110987110988110989110990110991110992110993110994110995110996110997110998110999111000111001111002111003111004111005111006111007111008111009111010111011111012111013111014111015111016111017111018111019111020111021111022111023111024111025111026111027111028111029111030111031111032111033111034111035111036111037111038111039111040111041111042111043111044111045111046111047111048111049111050111051111052111053111054111055111056111057111058111059111060111061111062111063111064111065111066111067111068111069111070111071111072111073111074111075111076111077111078111079111080111081111082111083111084111085111086111087111088111089111090111091111092111093111094111095111096111097111098111099111100111101111102111103111104111105111106111107111108111109111110111111111112111113111114111115111116111117111118111119111120111121111122111123111124111125111126111127111128111129111130111131111132111133111134111135111136111137111138111139111140111141111142111143111144111145111146111147111148111149111150111151111152111153111154111155111156111157111158111159111160111161111162111163111164111165111166111167111168111169111170111171111172111173111174111175111176111177111178111179111180111181111182111183111184111185111186111187111188111189111190111191111192111193111194111195111196111197111198111199111200111201111202111203111204111205111206111207111208111209111210111211111212111213111214111215111216111217111218111219111220111221111222111223111224111225111226111227111228111229111230111231111232111233111234111235111236111237111238111239111240111241111242111243111244111245111246111247111248111249111250111251111252111253111254111255111256111257111258111259111260111261111262111263111264111265111266111267111268111269111270111271111272111273111274111275111276111277111278111279111280111281111282111283111284111285111286111287111288111289111290111291111292111293111294111295111296111297111298111299111300111301111302111303111304111305111306111307111308111309111310111311111312111313111314111315111316111317111318111319111320111321111322111323111324111325111326111327111328111329111330111331111332111333111334111335111336111337111338111339111340111341111342111343111344111345111346111347111348111349111350111351111352111353111354111355111356111357111358111359111360111361111362111363111364111365111366111367111368111369111370111371111372111373111374111375111376111377111378111379111380111381111382111383111384111385111386111387111388111389111390111391111392111393111394111395111396111397111398111399111400111401111402111403111404111405111406111407111408111409111410111411111412111413111414111415111416111417111418111419111420111421111422111423111424111425111426111427111428111429111430111431111432111433111434111435111436111437111438111439111440111441111442111443111444111445111446111447111448111449111450111451111452111453111454111455111456111457111458111459111460111461111462111463111464111465111466111467111468111469111470111471111472111473111474111475111476111477111478111479111480111481111482111483111484111485111486111487111488111489111490111491111492111493111494111495111496111497111498111499111500111501111502111503111504111505111506111507111508111509111510111511111512111513111514111515111516111517111518111519111520111521111522111523111524111525111526111527111528111529111530111531111532111533111534111535111536111537111538111539111540111541111542111543111544111545111546111547111548111549111550111551111552111553111554111555111556111557111558111559111560111561111562111563111564111565111566111567111568111569111570111571111572111573111574111575111576111577111578111579111580111581111582111583111584111585111586111587111588111589111590111591111592111593111594111595111596111597111598111599111600111601111602111603111604111605111606111607111608111609111610111611111612111613111614111615111616111617111618111619111620111621111622111623111624111625111626111627111628111629111630111631111632111633111634111635111636111637111638111639111640111641111642111643111644111645111646111647111648111649111650111651111652111653111654111655111656111657111658111659111660111661111662111663111664111665111666111667111668111669111670111671111672111673111674111675111676111677111678111679111680111681111682111683111684111685111686111687111688111689111690111691111692111693111694111695111696111697111698111699111700111701111702111703111704111705111706111707111708111709111710111711111712111713111714111715111716111717111718111719111720111721111722111723111724111725111726111727111728111729111730111731111732111733111734111735111736111737111738111739111740111741111742111743111744111745111746111747111748111749111750111751111752111753111754111755111756111757111758111759111760111761111762111763111764111765111766111767111768111769111770111771111772111773111774111775111776111777111778111779111780111781111782111783111784111785111786111787111788111789111790111791111792111793111794111795111796111797111798111799111800111801111802111803111804111805111806111807111808111809111810111811111812111813111814111815111816111817111818111819111820111821111822111823111824111825111826111827111828111829111830111831111832111833111834111835111836111837111838111839111840111841111842111843111844111845111846111847111848111849111850111851111852111853111854111855111856111857111858111859111860111861111862111863111864111865111866111867111868111869111870111871111872111873111874111875111876111877111878111879111880111881111882111883111884111885111886111887111888111889111890111891111892111893111894111895111896111897111898111899111900111901111902111903111904111905111906111907111908111909111910111911111912111913111914111915111916111917111918111919111920111921111922111923111924111925111926111927111928111929111930111931111932111933111934111935111936111937111938111939111940111941111942111943111944111945111946111947111948111949111950111951111952111953111954111955111956111957111958111959111960111961111962111963111964111965111966111967111968111969111970111971111972111973111974111975111976111977111978111979111980111981111982111983111984111985111986111987111988111989111990111991111992111993111994111995111996111997111998111999112000112001112002112003112004112005112006112007112008112009112010112011112012112013112014112015112016112017112018112019112020112021112022112023112024112025112026112027112028112029112030112031112032112033112034112035112036112037112038112039112040112041112042112043112044112045112046112047112048112049112050112051112052112053112054112055112056112057112058112059112060112061112062112063112064112065112066112067112068112069112070112071112072112073112074112075112076112077112078112079112080112081112082112083112084112085112086112087112088112089112090112091112092112093112094112095112096112097112098112099112100112101112102112103112104112105112106112107112108112109112110112111112112112113112114112115112116112117112118112119112120112121112122112123112124112125112126112127112128112129112130112131112132112133112134112135112136112137112138112139112140112141112142112143112144112145112146112147112148112149112150112151112152112153112154112155112156112157112158112159112160112161112162112163112164112165112166112167112168112169112170112171112172112173112174112175112176112177112178112179112180112181112182112183112184112185112186112187112188112189112190112191112192112193112194112195112196112197112198112199112200112201112202112203112204112205112206112207112208112209112210112211112212112213112214112215112216112217112218112219112220112221112222112223112224112225112226112227112228112229112230112231112232112233112234112235112236112237112238112239112240112241112242112243112244112245112246112247112248112249112250112251112252112253112254112255112256112257112258112259112260112261112262112263112264112265112266112267112268112269112270112271112272112273112274112275112276112277112278112279112280112281112282112283112284112285112286112287112288112289112290112291112292112293112294112295112296112297112298112299112300112301112302112303112304112305112306112307112308112309112310112311112312112313112314112315112316112317112318112319112320112321112322112323112324112325112326112327112328112329112330112331112332112333112334112335112336112337112338112339112340112341112342112343112344112345112346112347112348112349112350112351112352112353112354112355112356112357112358112359112360112361112362112363112364112365112366112367112368112369112370112371112372112373112374112375112376112377112378112379112380112381112382112383112384112385112386112387112388112389112390112391112392112393112394112395112396112397112398112399112400112401112402112403112404112405112406112407112408112409112410112411112412112413112414112415112416112417112418112419112420112421112422112423112424112425112426112427112428112429112430112431112432112433112434112435112436112437112438112439112440112441112442112443112444112445112446112447112448112449112450112451112452112453112454112455112456112457112458112459112460112461112462112463112464112465112466112467112468112469112470112471112472112473112474112475112476112477112478112479112480112481112482112483112484112485112486112487112488112489112490112491112492112493112494112495112496112497112498112499112500112501112502112503112504112505112506112507112508112509112510112511112512112513112514112515112516112517112518112519112520112521112522112523112524112525112526112527112528112529112530112531112532112533112534112535112536112537112538112539112540112541112542112543112544112545112546112547112548112549112550112551112552112553112554112555112556112557112558112559112560112561112562112563112564112565112566112567112568112569112570112571112572112573112574112575112576112577112578112579112580112581112582112583112584112585112586112587112588112589112590112591112592112593112594112595112596112597112598112599112600112601112602112603112604112605112606112607112608112609112610112611112612112613112614112615112616112617112618112619112620112621112622112623112624112625112626112627112628112629112630112631112632112633112634112635112636112637112638112639112640112641112642112643112644112645112646112647112648112649112650112651112652112653112654112655112656112657112658112659112660112661112662112663112664112665112666112667112668112669112670112671112672112673112674112675112676112677112678112679112680112681112682112683112684112685112686112687112688112689112690112691112692112693112694112695112696112697112698112699112700112701112702112703112704112705112706112707112708112709112710112711112712112713112714112715112716112717112718112719112720112721112722112723112724112725112726112727112728112729112730112731112732112733112734112735112736112737112738112739112740112741112742112743112744112745112746112747112748112749112750112751112752112753112754112755112756112757112758112759112760112761112762112763112764112765112766112767112768112769112770112771112772112773112774112775112776112777112778112779112780112781112782112783112784112785112786112787112788112789112790112791112792112793112794112795112796112797112798112799112800112801112802112803112804112805112806112807112808112809112810112811112812112813112814112815112816112817112818112819112820112821112822112823112824112825112826112827112828112829112830112831112832112833112834112835112836112837112838112839112840112841112842112843112844112845112846112847112848112849112850112851112852112853112854112855112856112857112858112859112860112861112862112863112864112865112866112867112868112869112870112871112872112873112874112875112876112877112878112879112880112881112882112883112884112885112886112887112888112889112890112891112892112893112894112895112896112897112898112899112900112901112902112903112904112905112906112907112908112909112910112911112912112913112914112915112916112917112918112919112920112921112922112923112924112925112926112927112928112929112930112931112932112933112934112935112936112937112938112939112940112941112942112943112944112945112946112947112948112949112950112951112952112953112954112955112956112957112958112959112960112961112962112963112964112965112966112967112968112969112970112971112972112973112974112975112976112977112978112979112980112981112982112983112984112985112986112987112988112989112990112991112992112993112994112995112996112997112998112999113000113001113002113003113004113005113006113007113008113009113010113011113012113013113014113015113016113017113018113019113020113021113022113023113024113025113026113027113028113029113030113031113032113033113034113035113036113037113038113039113040113041113042113043113044113045113046113047113048113049113050113051113052113053113054113055113056113057113058113059113060113061113062113063113064113065113066113067113068113069113070113071113072113073113074113075113076113077113078113079113080113081113082113083113084113085113086113087113088113089113090113091113092113093113094113095113096113097113098113099113100113101113102113103113104113105113106113107113108113109113110113111113112113113113114113115113116113117113118113119113120113121113122113123113124113125113126113127113128113129113130113131113132113133113134113135113136113137113138113139113140113141113142113143113144113145113146113147113148113149113150113151113152113153113154113155113156113157113158113159113160113161113162113163113164113165113166113167113168113169113170113171113172113173113174113175113176113177113178113179113180113181113182113183113184113185113186113187113188113189113190113191113192113193113194113195113196113197113198113199113200113201113202113203113204113205113206113207113208113209113210113211113212113213113214113215113216113217113218113219113220113221113222113223113224113225113226113227113228113229113230113231113232113233113234113235113236113237113238113239113240113241113242113243113244113245113246113247113248113249113250113251113252113253113254113255113256113257113258113259113260113261113262113263113264113265113266113267113268113269113270113271113272113273113274113275113276113277113278113279113280113281113282113283113284113285113286113287113288113289113290113291113292113293113294113295113296113297113298113299113300113301113302113303113304113305113306113307113308113309113310113311113312113313113314113315113316113317113318113319113320113321113322113323113324113325113326113327113328113329113330113331113332113333113334113335113336113337113338113339113340113341113342113343113344113345113346113347113348113349113350113351113352113353113354113355113356113357113358113359113360113361113362113363113364113365113366113367113368113369113370113371113372113373113374113375113376113377113378113379113380113381113382113383113384113385113386113387113388113389113390113391113392113393113394113395113396113397113398113399113400113401113402113403113404113405113406113407113408113409113410113411113412113413113414113415113416113417113418113419113420113421113422113423113424113425113426113427113428113429113430113431113432113433113434113435113436113437113438113439113440113441113442113443113444113445113446113447113448113449113450113451113452113453113454113455113456113457113458113459113460113461113462113463113464113465113466113467113468113469113470113471113472113473113474113475113476113477113478113479113480113481113482113483113484113485113486113487113488113489113490113491113492113493113494113495113496113497113498113499113500113501113502113503113504113505113506113507113508113509113510113511113512113513113514113515113516113517113518113519113520113521113522113523113524113525113526113527113528113529113530113531113532113533113534113535113536113537113538113539113540113541113542113543113544113545113546113547113548113549113550113551113552113553113554113555113556113557113558113559113560113561113562113563113564113565113566113567113568113569113570113571113572113573113574113575113576113577113578113579113580113581113582113583113584113585113586113587113588113589113590113591113592113593113594113595113596113597113598113599113600113601113602113603113604113605113606113607113608113609113610113611113612113613113614113615113616113617113618113619113620113621113622113623113624113625113626113627113628113629113630113631113632113633113634113635113636113637113638113639113640113641113642113643113644113645113646113647113648113649113650113651113652113653113654113655113656113657113658113659113660113661113662113663113664113665113666113667113668113669113670113671113672113673113674113675113676113677113678113679113680113681113682113683113684113685113686113687113688113689113690113691113692113693113694113695113696113697113698113699113700113701113702113703113704113705113706113707113708113709113710113711113712113713113714113715113716113717113718113719113720113721113722113723113724113725113726113727113728113729113730113731113732113733113734113735113736113737113738113739113740113741113742113743113744113745113746113747113748113749113750113751113752113753113754113755113756113757113758113759113760113761113762113763113764113765113766113767113768113769113770113771113772113773113774113775113776113777113778113779113780113781113782113783113784113785113786113787113788113789113790113791113792113793113794113795113796113797113798113799113800113801113802113803113804113805113806113807113808113809113810113811113812113813113814113815113816113817113818113819113820113821113822113823113824113825113826113827113828113829113830113831113832113833113834113835113836113837113838113839113840113841113842113843113844113845113846113847113848113849113850113851113852113853113854113855113856113857113858113859113860113861113862113863113864113865113866113867113868113869113870113871113872113873113874113875113876113877113878113879113880113881113882113883113884113885113886113887113888113889113890113891113892113893113894113895113896113897113898113899113900113901113902113903113904113905113906113907113908113909113910113911113912113913113914113915113916113917113918113919113920113921113922113923113924113925113926113927113928113929113930113931113932113933113934113935113936113937113938113939113940113941113942113943113944113945113946113947113948113949113950113951113952113953113954113955113956113957113958113959113960113961113962113963113964113965113966113967113968113969113970113971113972113973113974113975113976113977113978113979113980113981113982113983113984113985113986113987113988113989113990113991113992113993113994113995113996113997113998113999114000114001114002114003114004114005114006114007114008114009114010114011114012114013114014114015114016114017114018114019114020114021114022114023114024114025114026114027114028114029114030114031114032114033114034114035114036114037114038114039114040114041114042114043114044114045114046114047114048114049114050114051114052114053114054114055114056114057114058114059114060114061114062114063114064114065114066114067114068114069114070114071114072114073114074114075114076114077114078114079114080114081114082114083114084114085114086114087114088114089114090114091114092114093114094114095114096114097114098114099114100114101114102114103114104114105114106114107114108114109114110114111114112114113114114114115114116114117114118114119114120114121114122114123114124114125114126114127114128114129114130114131114132114133114134114135114136114137114138114139114140114141114142114143114144114145114146114147114148114149114150114151114152114153114154114155114156114157114158114159114160114161114162114163114164114165114166114167114168114169114170114171114172114173114174114175114176114177114178114179114180114181114182114183114184114185114186114187114188114189114190114191114192114193114194114195114196114197114198114199114200114201114202114203114204114205114206114207114208114209114210114211114212114213114214114215114216114217114218114219114220114221114222114223114224114225114226114227114228114229114230114231114232114233114234114235114236114237114238114239114240114241114242114243114244114245114246114247114248114249114250114251114252114253114254114255114256114257114258114259114260114261114262114263114264114265114266114267114268114269114270114271114272114273114274114275114276114277114278114279114280114281114282114283114284114285114286114287114288114289114290114291114292114293114294114295114296114297114298114299114300114301114302114303114304114305114306114307114308114309114310114311114312114313114314114315114316114317114318114319114320114321114322114323114324114325114326114327114328114329114330114331114332114333114334114335114336114337114338114339114340114341114342114343114344114345114346114347114348114349114350114351114352114353114354114355114356114357114358114359114360114361114362114363114364114365114366114367114368114369114370114371114372114373114374114375114376114377114378114379114380114381114382114383114384114385114386114387114388114389114390114391114392114393114394114395114396114397114398114399114400114401114402114403114404114405114406114407114408114409114410114411114412114413114414114415114416114417114418114419114420114421114422114423114424114425114426114427114428114429114430114431114432114433114434114435114436114437114438114439114440114441114442114443114444114445114446114447114448114449114450114451114452114453114454114455114456114457114458114459114460114461114462114463114464114465114466114467114468114469114470114471114472114473114474114475114476114477114478114479114480114481114482114483114484114485114486114487114488114489114490114491114492114493114494114495114496114497114498114499114500114501114502114503114504114505114506114507114508114509114510114511114512114513114514114515114516114517114518114519114520114521114522114523114524114525114526114527114528114529114530114531114532114533114534114535114536114537114538114539114540114541114542114543114544114545114546114547114548114549114550114551114552114553114554114555114556114557114558114559114560114561114562114563114564114565114566114567114568114569114570114571114572114573114574114575114576114577114578114579114580114581114582114583114584114585114586114587114588114589114590114591114592114593114594114595114596114597114598114599114600114601114602114603114604114605114606114607114608114609114610114611114612114613114614114615114616114617114618114619114620114621114622114623114624114625114626114627114628114629114630114631114632114633114634114635114636114637114638114639114640114641114642114643114644114645114646114647114648114649114650114651114652114653114654114655114656114657114658114659114660114661114662114663114664114665114666114667114668114669114670114671114672114673114674114675114676114677114678114679114680114681114682114683114684114685114686114687114688114689114690114691114692114693114694114695114696114697114698114699114700114701114702114703114704114705114706114707114708114709114710114711114712114713114714114715114716114717114718114719114720114721114722114723114724114725114726114727114728114729114730114731114732114733114734114735114736114737114738114739114740114741114742114743114744114745114746114747114748114749114750114751114752114753114754114755114756114757114758114759114760114761114762114763114764114765114766114767114768114769114770114771114772114773114774114775114776114777114778114779114780114781114782114783114784114785114786114787114788114789114790114791114792114793114794114795114796114797114798114799114800114801114802114803114804114805114806114807114808114809114810114811114812114813114814114815114816114817114818114819114820114821114822114823114824114825114826114827114828114829114830114831114832114833114834114835114836114837114838114839114840114841114842114843114844114845114846114847114848114849114850114851114852114853114854114855114856114857114858114859114860114861114862114863114864114865114866114867114868114869114870114871114872114873114874114875114876114877114878114879114880114881114882114883114884114885114886114887114888114889114890114891114892114893114894114895114896114897114898114899114900114901114902114903114904114905114906114907114908114909114910114911114912114913114914114915114916114917114918114919114920114921114922114923114924114925114926114927114928114929114930114931114932114933114934114935114936114937114938114939114940114941114942114943114944114945114946114947114948114949114950114951114952114953114954114955114956114957114958114959114960114961114962114963114964114965114966114967114968114969114970114971114972114973114974114975114976114977114978114979114980114981114982114983114984114985114986114987114988114989114990114991114992114993114994114995114996114997114998114999115000115001115002115003115004115005115006115007115008115009115010115011115012115013115014115015115016115017115018115019115020115021115022115023115024115025115026115027115028115029115030115031115032115033115034115035115036115037115038115039115040115041115042115043115044115045115046115047115048115049115050115051115052115053115054115055115056115057115058115059115060115061115062115063115064115065115066115067115068115069115070115071115072115073115074115075115076115077115078115079115080115081115082115083115084115085115086115087115088115089115090115091115092115093115094115095115096115097115098115099115100115101115102115103115104115105115106115107115108115109115110115111115112115113115114115115115116115117115118115119115120115121115122115123115124115125115126115127115128115129115130115131115132115133115134115135115136115137115138115139115140115141115142115143115144115145115146115147115148115149115150115151115152115153115154115155115156115157115158115159115160115161115162115163115164115165115166115167115168115169115170115171115172115173115174115175115176115177115178115179115180115181115182115183115184115185115186115187115188115189115190115191115192115193115194115195115196115197115198115199115200115201115202115203115204115205115206115207115208115209115210115211115212115213115214115215115216115217115218115219115220115221115222115223115224115225115226115227115228115229115230115231115232115233115234115235115236115237115238115239115240115241115242115243115244115245115246115247115248115249115250115251115252115253115254115255115256115257115258115259115260115261115262115263115264115265115266115267115268115269115270115271115272115273115274115275115276115277115278115279115280115281115282115283115284115285115286115287115288115289115290115291115292115293115294115295115296115297115298115299115300115301115302115303115304115305115306115307115308115309115310115311115312115313115314115315115316115317115318115319115320115321115322115323115324115325115326115327115328115329115330115331115332115333115334115335115336115337115338115339115340115341115342115343115344115345115346115347115348115349115350115351115352115353115354115355115356115357115358115359115360115361115362115363115364115365115366115367115368115369115370115371115372115373115374115375115376115377115378115379115380115381115382115383115384115385115386115387115388115389115390115391115392115393115394115395115396115397115398115399115400115401115402115403115404115405115406115407115408115409115410115411115412115413115414115415115416115417115418115419115420115421115422115423115424115425115426115427115428115429115430115431115432115433115434115435115436115437115438115439115440115441115442115443115444115445115446115447115448115449115450115451115452115453115454115455115456115457115458115459115460115461115462115463115464115465115466115467115468115469115470115471115472115473115474115475115476115477115478115479115480115481115482115483115484115485115486115487115488115489115490115491115492115493115494115495115496115497115498115499115500115501115502115503115504115505115506115507115508115509115510115511115512115513115514115515115516115517115518115519115520115521115522115523115524115525115526115527115528115529115530115531115532115533115534115535115536115537115538115539115540115541115542115543115544115545115546115547115548115549115550115551115552115553115554115555115556115557115558115559115560115561115562115563115564115565115566115567115568115569115570115571115572115573115574115575115576115577115578115579115580115581115582115583115584115585115586115587115588115589115590115591115592115593115594115595115596115597115598115599115600115601115602115603115604115605115606115607115608115609115610115611115612115613115614115615115616115617115618115619115620115621115622115623115624115625115626115627115628115629115630115631115632115633115634115635115636115637115638115639115640115641115642115643115644115645115646115647115648115649115650115651115652115653115654115655115656115657115658115659115660115661115662115663115664115665115666115667115668115669115670115671115672115673115674115675115676115677115678115679115680115681115682115683115684115685115686115687115688115689115690115691115692115693115694115695115696115697115698115699115700115701115702115703115704115705115706115707115708115709115710115711115712115713115714115715115716115717115718115719115720115721115722115723115724115725115726115727115728115729115730115731115732115733115734115735115736115737115738115739115740115741115742115743115744115745115746115747115748115749115750115751115752115753115754115755115756115757115758115759115760115761115762115763115764115765115766115767115768115769115770115771115772115773115774115775115776115777115778115779115780115781115782115783115784115785115786115787115788115789115790115791115792115793115794115795115796115797115798115799115800115801115802115803115804115805115806115807115808115809115810115811115812115813115814115815115816115817115818115819115820115821115822115823115824115825115826115827115828115829115830115831115832115833115834115835115836115837115838115839115840115841115842115843115844115845115846115847115848115849115850115851115852115853115854115855115856115857115858115859115860115861115862115863115864115865115866115867115868115869115870115871115872115873115874115875115876115877115878115879115880115881115882115883115884115885115886115887115888115889115890115891115892115893115894115895115896115897115898115899115900115901115902115903115904115905115906115907115908115909115910115911115912115913115914115915115916115917115918115919115920115921115922115923115924115925115926115927115928115929115930115931115932115933115934115935115936115937115938115939115940115941115942115943115944115945115946115947115948115949115950115951115952115953115954115955115956115957115958115959115960115961115962115963115964115965115966115967115968115969115970115971115972115973115974115975115976115977115978115979115980115981115982115983115984115985115986115987115988115989115990115991115992115993115994115995115996115997115998115999116000116001116002116003116004116005116006116007116008116009116010116011116012116013116014116015116016116017116018116019116020116021116022116023116024116025116026116027116028116029116030116031116032116033116034116035116036116037116038116039116040116041116042116043116044116045116046116047116048116049116050116051116052116053116054116055116056116057116058116059116060116061116062116063116064116065116066116067116068116069116070116071116072116073116074116075116076116077116078116079116080116081116082116083116084116085116086116087116088116089116090116091116092116093116094116095116096116097116098116099116100116101116102116103116104116105116106116107116108116109116110116111116112116113116114116115116116116117116118116119116120116121116122116123116124116125116126116127116128116129116130116131116132116133116134116135116136116137116138116139116140116141116142116143116144116145116146116147116148116149116150116151116152116153116154116155116156116157116158116159116160116161116162116163116164116165116166116167116168116169116170116171116172116173116174116175116176116177116178116179116180116181116182116183116184116185116186116187116188116189116190116191116192116193116194116195116196116197116198116199116200116201116202116203116204116205116206116207116208116209116210116211116212116213116214116215116216116217116218116219116220116221116222116223116224116225116226116227116228116229116230116231116232116233116234116235116236116237116238116239116240116241116242116243116244116245116246116247116248116249116250116251116252116253116254116255116256116257116258116259116260116261116262116263116264116265116266116267116268116269116270116271116272116273116274116275116276116277116278116279116280116281116282116283116284116285116286116287116288116289116290116291116292116293116294116295116296116297116298116299116300116301116302116303116304116305116306116307116308116309116310116311116312116313116314116315116316116317116318116319116320116321116322116323116324116325116326116327116328116329116330116331116332116333116334116335116336116337116338116339116340116341116342116343116344116345116346116347116348116349116350116351116352116353116354116355116356116357116358116359116360116361116362116363116364116365116366116367116368116369116370116371116372116373116374116375116376116377116378116379116380116381116382116383116384116385116386116387116388116389116390116391116392116393116394116395116396116397116398116399116400116401116402116403116404116405116406116407116408116409116410116411116412116413116414116415116416116417116418116419116420116421116422116423116424116425116426116427116428116429116430116431116432116433116434116435116436116437116438116439116440116441116442116443116444116445116446116447116448116449116450116451116452116453116454116455116456116457116458116459116460116461116462116463116464116465116466116467116468116469116470116471116472116473116474116475116476116477116478116479116480116481116482116483116484116485116486116487116488116489116490116491116492116493116494116495116496116497116498116499116500116501116502116503116504116505116506116507116508116509116510116511116512116513116514116515116516116517116518116519116520116521116522116523116524116525116526116527116528116529116530116531116532116533116534116535116536116537116538116539116540116541116542116543116544116545116546116547116548116549116550116551116552116553116554116555116556116557116558116559116560116561116562116563116564116565116566116567116568116569116570116571116572116573116574116575116576116577116578116579116580116581116582116583116584116585116586116587116588116589116590116591116592116593116594116595116596116597116598116599116600116601116602116603116604116605116606116607116608116609116610116611116612116613116614116615116616116617116618116619116620116621116622116623116624116625116626116627116628116629116630116631116632116633116634116635116636116637116638116639116640116641116642116643116644116645116646116647116648116649116650116651116652116653116654116655116656116657116658116659116660116661116662116663116664116665116666116667116668116669116670116671116672116673116674116675116676116677116678116679116680116681116682116683116684116685116686116687116688116689116690116691116692116693116694116695116696116697116698116699116700116701116702116703116704116705116706116707116708116709116710116711116712116713116714116715116716116717116718116719116720116721116722116723116724116725116726116727116728116729116730116731116732116733116734116735116736116737116738116739116740116741116742116743116744116745116746116747116748116749116750116751116752116753116754116755116756116757116758116759116760116761116762116763116764116765116766116767116768116769116770116771116772116773116774116775116776116777116778116779116780116781116782116783116784116785116786116787116788116789116790116791116792116793116794116795116796116797116798116799116800116801116802116803116804116805116806116807116808116809116810116811116812116813116814116815116816116817116818116819116820116821116822116823116824116825116826116827116828116829116830116831116832116833116834116835116836116837116838116839116840116841116842116843116844116845116846116847116848116849116850116851116852116853116854116855116856116857116858116859116860116861116862116863116864116865116866116867116868116869116870116871116872116873116874116875116876116877116878116879116880116881116882116883116884116885116886116887116888116889116890116891116892116893116894116895116896116897116898116899116900116901116902116903116904116905116906116907116908116909116910116911116912116913116914116915116916116917116918116919116920116921116922116923116924116925116926116927116928116929116930116931116932116933116934116935116936116937116938116939116940116941116942116943116944116945116946116947116948116949116950116951116952116953116954116955116956116957116958116959116960116961116962116963116964116965116966116967116968116969116970116971116972116973116974116975116976116977116978116979116980116981116982116983116984116985116986116987116988116989116990116991116992116993116994116995116996116997116998116999117000117001117002117003117004117005117006117007117008117009117010117011117012117013117014117015117016117017117018117019117020117021117022117023117024117025117026117027117028117029117030117031117032117033117034117035117036117037117038117039117040117041117042117043117044117045117046117047117048117049117050117051117052117053117054117055117056117057117058117059117060117061117062117063117064117065117066117067117068117069117070117071117072117073117074117075117076117077117078117079117080117081117082117083117084117085117086117087117088117089117090117091117092117093117094117095117096117097117098117099117100117101117102117103117104117105117106117107117108117109117110117111117112117113117114117115117116117117117118117119117120117121117122117123117124117125117126117127117128117129117130117131117132117133117134117135117136117137117138117139117140117141117142117143117144117145117146117147117148117149117150117151117152117153117154117155117156117157117158117159117160117161117162117163117164117165117166117167117168117169117170117171117172117173117174117175117176117177117178117179117180117181117182117183117184117185117186117187117188117189117190117191117192117193117194117195117196117197117198117199117200117201117202117203117204117205117206117207117208117209117210117211117212117213117214117215117216117217117218117219117220117221117222117223117224117225117226117227117228117229117230117231117232117233117234117235117236117237117238117239117240117241117242117243117244117245117246117247117248117249117250117251117252117253117254117255117256117257117258117259117260117261117262117263117264117265117266117267117268117269117270117271117272117273117274117275117276117277117278117279117280117281117282117283117284117285117286117287117288117289117290117291117292117293117294117295117296117297117298117299117300117301117302117303117304117305117306117307117308117309117310117311117312117313117314117315117316117317117318117319117320117321117322117323117324117325117326117327117328117329117330117331117332117333117334117335117336117337117338117339117340117341117342117343117344117345117346117347117348117349117350117351117352117353117354117355117356117357117358117359117360117361117362117363117364117365117366117367117368117369117370117371117372117373117374117375117376117377117378117379117380117381117382117383117384117385117386117387117388117389117390117391117392117393117394117395117396117397117398117399117400117401117402117403117404117405117406117407117408117409117410117411117412117413117414117415117416117417117418117419117420117421117422117423117424117425117426117427117428117429117430117431117432117433117434117435117436117437117438117439117440117441117442117443117444117445117446117447117448117449117450117451117452117453117454117455117456117457117458117459117460117461117462117463117464117465117466117467117468117469117470117471117472117473117474117475117476117477117478117479117480117481117482117483117484117485117486117487117488117489117490117491117492117493117494117495117496117497117498117499117500117501117502117503117504117505117506117507117508117509117510117511117512117513117514117515117516117517117518117519117520117521117522117523117524117525117526117527117528117529117530117531117532117533117534117535117536117537117538117539117540117541117542117543117544117545117546117547117548117549117550117551117552117553117554117555117556117557117558117559117560117561117562117563117564117565117566117567117568117569117570117571117572117573117574117575117576117577117578117579117580117581117582117583117584117585117586117587117588117589117590117591117592117593117594117595117596117597117598117599117600117601117602117603117604117605117606117607117608117609117610117611117612117613117614117615117616117617117618117619117620117621117622117623117624117625117626117627117628117629117630117631117632117633117634117635117636117637117638117639117640117641117642117643117644117645117646117647117648117649117650117651117652117653117654117655117656117657117658117659117660117661117662117663117664117665117666117667117668117669117670117671117672117673117674117675117676117677117678117679117680117681117682117683117684117685117686117687117688117689117690117691117692117693117694117695117696117697117698117699117700117701117702117703117704117705117706117707117708117709117710117711117712117713117714117715117716117717117718117719117720117721117722117723117724117725117726117727117728117729117730117731117732117733117734117735117736117737117738117739117740117741117742117743117744117745117746117747117748117749117750117751117752117753117754117755117756117757117758117759117760117761117762117763117764117765117766117767117768117769117770117771117772117773117774117775117776117777117778117779117780117781117782117783117784117785117786117787117788117789117790117791117792117793117794117795117796117797117798117799117800117801117802117803117804117805117806117807117808117809117810117811117812117813117814117815117816117817117818117819117820117821117822117823117824117825117826117827117828117829117830117831117832117833117834117835117836117837117838117839117840117841117842117843117844117845117846117847117848117849117850117851117852117853117854117855117856117857117858117859117860117861117862117863117864117865117866117867117868117869117870117871117872117873117874117875117876117877117878117879117880117881117882117883117884117885117886117887117888117889117890117891117892117893117894117895117896117897117898117899117900117901117902117903117904117905117906117907117908117909117910117911117912117913117914117915117916117917117918117919117920117921117922117923117924117925117926117927117928117929117930117931117932117933117934117935117936117937117938117939117940117941117942117943117944117945117946117947117948117949117950117951117952117953117954117955117956117957117958117959117960117961117962117963117964117965117966117967117968117969117970117971117972117973117974117975117976117977117978117979117980117981117982117983117984117985117986117987117988117989117990117991117992117993117994117995117996117997117998117999118000118001118002118003118004118005118006118007118008118009118010118011118012118013118014118015118016118017118018118019118020118021118022118023118024118025118026118027118028118029118030118031118032118033118034118035118036118037118038118039118040118041118042118043118044118045118046118047118048118049118050118051118052118053118054118055118056118057118058118059118060118061118062118063118064118065118066118067118068118069118070118071118072118073118074118075118076118077118078118079118080118081118082118083118084118085118086118087118088118089118090118091118092118093118094118095118096118097118098118099118100118101118102118103118104118105118106118107118108118109118110118111118112118113118114118115118116118117118118118119118120118121118122118123118124118125118126118127118128118129118130118131118132118133118134118135118136118137118138118139118140118141118142118143118144118145118146118147118148118149118150118151118152118153118154118155118156118157118158118159118160118161118162118163118164118165118166118167118168118169118170118171118172118173118174118175118176118177118178118179118180118181118182118183118184118185118186118187118188118189118190118191118192118193118194118195118196118197118198118199118200118201118202118203118204118205118206118207118208118209118210118211118212118213118214118215118216118217118218118219118220118221118222118223118224118225118226118227118228118229118230118231118232118233118234118235118236118237118238118239118240118241118242118243118244118245118246118247118248118249118250118251118252118253118254118255118256118257118258118259118260118261118262118263118264118265118266118267118268118269118270118271118272118273118274118275118276118277118278118279118280118281118282118283118284118285118286118287118288118289118290118291118292118293118294118295118296118297118298118299118300118301118302118303118304118305118306118307118308118309118310118311118312118313118314118315118316118317118318118319118320118321118322118323118324118325118326118327118328118329118330118331118332118333118334118335118336118337118338118339118340118341118342118343118344118345118346118347118348118349118350118351118352118353118354118355118356118357118358118359118360118361118362118363118364118365118366118367118368118369118370118371118372118373118374118375118376118377118378118379118380118381118382118383118384118385118386118387118388118389118390118391118392118393118394118395118396118397118398118399118400118401118402118403118404118405118406118407118408118409118410118411118412118413118414118415118416118417118418118419118420118421118422118423118424118425118426118427118428118429118430118431118432118433118434118435118436118437118438118439118440118441118442118443118444118445118446118447118448118449118450118451118452118453118454118455118456118457118458118459118460118461118462118463118464118465118466118467118468118469118470118471118472118473118474118475118476118477118478118479118480118481118482118483118484118485118486118487118488118489118490118491118492118493118494118495118496118497118498118499118500118501118502118503118504118505118506118507118508118509118510118511118512118513118514118515118516118517118518118519118520118521118522118523118524118525118526118527118528118529118530118531118532118533118534118535118536118537118538118539118540118541118542118543118544118545118546118547118548118549118550118551118552118553118554118555118556118557118558118559118560118561118562118563118564118565118566118567118568118569118570118571118572118573118574118575118576118577118578118579118580118581118582118583118584118585118586118587118588118589118590118591118592118593118594118595118596118597118598118599118600118601118602118603118604118605118606118607118608118609118610118611118612118613118614118615118616118617118618118619118620118621118622118623118624118625118626118627118628118629118630118631118632118633118634118635118636118637118638118639118640118641118642118643118644118645118646118647118648118649118650118651118652118653118654118655118656118657118658118659118660118661118662118663118664118665118666118667118668118669118670118671118672118673118674118675118676118677118678118679118680118681118682118683118684118685118686118687118688118689118690118691118692118693118694118695118696118697118698118699118700118701118702118703118704118705118706118707118708118709118710118711118712118713118714118715118716118717118718118719118720118721118722118723118724118725118726118727118728118729118730118731118732118733118734118735118736118737118738118739118740118741118742118743118744118745118746118747118748118749118750118751118752118753118754118755118756118757118758118759118760118761118762118763118764118765118766118767118768118769118770118771118772118773118774118775118776118777118778118779118780118781118782118783118784118785118786118787118788118789118790118791118792118793118794118795118796118797118798118799118800118801118802118803118804118805118806118807118808118809118810118811118812118813118814118815118816118817118818118819118820118821118822118823118824118825118826118827118828118829118830118831118832118833118834118835118836118837118838118839118840118841118842118843118844118845118846118847118848118849118850118851118852118853118854118855118856118857118858118859118860118861118862118863118864118865118866118867118868118869118870118871118872118873118874118875118876118877118878118879118880118881118882118883118884118885118886118887118888118889118890118891118892118893118894118895118896118897118898118899118900118901118902118903118904118905118906118907118908118909118910118911118912118913118914118915118916118917118918118919118920118921118922118923118924118925118926118927118928118929118930118931118932118933118934118935118936118937118938118939118940118941118942118943118944118945118946118947118948118949118950118951118952118953118954118955118956118957118958118959118960118961118962118963118964118965118966118967118968118969118970118971118972118973118974118975118976118977118978118979118980118981118982118983118984118985118986118987118988118989118990118991118992118993118994118995118996118997118998118999119000119001119002119003119004119005119006119007119008119009119010119011119012119013119014119015119016119017119018119019119020119021119022119023119024119025119026119027119028119029119030119031119032119033119034119035119036119037119038119039119040119041119042119043119044119045119046119047119048119049119050119051119052119053119054119055119056119057119058119059119060119061119062119063119064119065119066119067119068119069119070119071119072119073119074119075119076119077119078119079119080119081119082119083119084119085119086119087119088119089119090119091119092119093119094119095119096119097119098119099119100119101119102119103119104119105119106119107119108119109119110119111119112119113119114119115119116119117119118119119119120119121119122119123119124119125119126119127119128119129119130119131119132119133119134119135119136119137119138119139119140119141119142119143119144119145119146119147119148119149119150119151119152119153119154119155119156119157119158119159119160119161119162119163119164119165119166119167119168119169119170119171119172119173119174119175119176119177119178119179119180119181119182119183119184119185119186119187119188119189119190119191119192119193119194119195119196119197119198119199119200119201119202119203119204119205119206119207119208119209119210119211119212119213119214119215119216119217119218119219119220119221119222119223119224119225119226119227119228119229119230119231119232119233119234119235119236119237119238119239119240119241119242119243119244119245119246119247119248119249119250119251119252119253119254119255119256119257119258119259119260119261119262119263119264119265119266119267119268119269119270119271119272119273119274119275119276119277119278119279119280119281119282119283119284119285119286119287119288119289119290119291119292119293119294119295119296119297119298119299119300119301119302119303119304119305119306119307119308119309119310119311119312119313119314119315119316119317119318119319119320119321119322119323119324119325119326119327119328119329119330119331119332119333119334119335119336119337119338119339119340119341119342119343119344119345119346119347119348119349119350119351119352119353119354119355119356119357119358119359119360119361119362119363119364119365119366119367119368119369119370119371119372119373119374119375119376119377119378119379119380119381119382119383119384119385119386119387119388119389119390119391119392119393119394119395119396119397119398119399119400119401119402119403119404119405119406119407119408119409119410119411119412119413119414119415119416119417119418119419119420119421119422119423119424119425119426119427119428119429119430119431119432119433119434119435119436119437119438119439119440119441119442119443119444119445119446119447119448119449119450119451119452119453119454119455119456119457119458119459119460119461119462119463119464119465119466119467119468119469119470119471119472119473119474119475119476119477119478119479119480119481119482119483119484119485119486119487119488119489119490119491119492119493119494119495119496119497119498119499119500119501119502119503119504119505119506119507119508119509119510119511119512119513119514119515119516119517119518119519119520119521119522119523119524119525119526119527119528119529119530119531119532119533119534119535119536119537119538119539119540119541119542119543119544119545119546119547119548119549119550119551119552119553119554119555119556119557119558119559119560119561119562119563119564119565119566119567119568119569119570119571119572119573119574119575119576119577119578119579119580119581119582119583119584119585119586119587119588119589119590119591119592119593119594119595119596119597119598119599119600119601119602119603119604119605119606119607119608119609119610119611119612119613119614119615119616119617119618119619119620119621119622119623119624119625119626119627119628119629119630119631119632119633119634119635119636119637119638119639119640119641119642119643119644119645119646119647119648119649119650119651119652119653119654119655119656119657119658119659119660119661119662119663119664119665119666119667119668119669119670119671119672119673119674119675119676119677119678119679119680119681119682119683119684119685119686119687119688119689119690119691119692119693119694119695119696119697119698119699119700119701119702119703119704119705119706119707119708119709119710119711119712119713119714119715119716119717119718119719119720119721119722119723119724119725119726119727119728119729119730119731119732119733119734119735119736119737119738119739119740119741119742119743119744119745119746119747119748119749119750119751119752119753119754119755119756119757119758119759119760119761119762119763119764119765119766119767119768119769119770119771119772119773119774119775119776119777119778119779119780119781119782119783119784119785119786119787119788119789119790119791119792119793119794119795119796119797119798119799119800119801119802119803119804119805119806119807119808119809119810119811119812119813119814119815119816119817119818119819119820119821119822119823119824119825119826119827119828119829119830119831119832119833119834119835119836119837119838119839119840119841119842119843119844119845119846119847119848119849119850119851119852119853119854119855119856119857119858119859119860119861119862119863119864119865119866119867119868119869119870119871119872119873119874119875119876119877119878119879119880119881119882119883119884119885119886119887119888119889119890119891119892119893119894119895119896119897119898119899119900119901119902119903119904119905119906119907119908119909119910119911119912119913119914119915119916119917119918119919119920119921119922119923119924119925119926119927119928119929119930119931119932119933119934119935119936119937119938119939119940119941119942119943119944119945119946119947119948119949119950119951119952119953119954119955119956119957119958119959119960119961119962119963119964119965119966119967119968119969119970119971119972119973119974119975119976119977119978119979119980119981119982119983119984119985119986119987119988119989119990119991119992119993119994119995119996119997119998119999120000120001120002120003120004120005120006120007120008120009120010120011120012120013120014120015120016120017120018120019120020120021120022120023120024120025120026120027120028120029120030120031120032120033120034120035120036120037120038120039120040120041120042120043120044120045120046120047120048120049120050120051120052120053120054120055120056120057120058120059120060120061120062120063120064120065120066120067120068120069120070120071120072120073120074120075120076120077120078120079120080120081120082120083120084120085120086120087120088120089120090120091120092120093120094120095120096120097120098120099120100120101120102120103120104120105120106120107120108120109120110120111120112120113120114120115120116120117120118120119120120120121120122120123120124120125120126120127120128120129120130120131120132120133120134120135120136120137120138120139120140120141120142120143120144120145120146120147120148120149120150120151120152120153120154120155120156120157120158120159120160120161120162120163120164120165120166120167120168120169120170120171120172120173120174120175120176120177120178120179120180120181120182120183120184120185120186120187120188120189120190120191120192120193120194120195120196120197120198120199120200120201120202120203120204120205120206120207120208120209120210120211120212120213120214120215120216120217120218120219120220120221120222120223120224120225120226120227120228120229120230120231120232120233120234120235120236120237120238120239120240120241120242120243120244120245120246120247120248120249120250120251120252120253120254120255120256120257120258120259120260120261120262120263120264120265120266120267120268120269120270120271120272120273120274120275120276120277120278120279120280120281120282120283120284120285120286120287120288120289120290120291120292120293120294120295120296120297120298120299120300120301120302120303120304120305120306120307120308120309120310120311120312120313120314120315120316120317120318120319120320120321120322120323120324120325120326120327120328120329120330120331120332120333120334120335120336120337120338120339120340120341120342120343120344120345120346120347120348120349120350120351120352120353120354120355120356120357120358120359120360120361120362120363120364120365120366120367120368120369120370120371120372120373120374120375120376120377120378120379120380120381120382120383120384120385120386120387120388120389120390120391120392120393120394120395120396120397120398120399120400120401120402120403120404120405120406120407120408120409120410120411120412120413120414120415120416120417120418120419120420120421120422120423120424120425120426120427120428120429120430120431120432120433120434120435120436120437120438120439120440120441120442120443120444120445120446120447120448120449120450120451120452120453120454120455120456120457120458120459120460120461120462120463120464120465120466120467120468120469120470120471120472120473120474120475120476120477120478120479120480120481120482120483120484120485120486120487120488120489120490120491120492120493120494120495120496120497120498120499120500120501120502120503120504120505120506120507120508120509120510120511120512120513120514120515120516120517120518120519120520120521120522120523120524120525120526120527120528120529120530120531120532120533120534120535120536120537120538120539120540120541120542120543120544120545120546120547120548120549120550120551120552120553120554120555120556120557120558120559120560120561120562120563120564120565120566120567120568120569120570120571120572120573120574120575120576120577120578120579120580120581120582120583120584120585120586120587120588120589120590120591120592120593120594120595120596120597120598120599120600120601120602120603120604120605120606120607120608120609120610120611120612120613120614120615120616120617120618120619120620120621120622120623120624120625120626120627120628120629120630120631120632120633120634120635120636120637120638120639120640120641120642120643120644120645120646120647120648120649120650120651120652120653120654120655120656120657120658120659120660120661120662120663120664120665120666120667120668120669120670120671120672120673120674120675120676120677120678120679120680120681120682120683120684120685120686120687120688120689120690120691120692120693120694120695120696120697120698120699120700120701120702120703120704120705120706120707120708120709120710120711120712120713120714120715120716120717120718120719120720120721120722120723120724120725120726120727120728120729120730120731120732120733120734120735120736120737120738120739120740120741120742120743120744120745120746120747120748120749120750120751120752120753120754120755120756120757120758120759120760120761120762120763120764120765120766120767120768120769120770120771120772120773120774120775120776120777120778120779120780120781120782120783120784120785120786120787120788120789120790120791120792120793120794120795120796120797120798120799120800120801120802120803120804120805120806120807120808120809120810120811120812120813120814120815120816120817120818120819120820120821120822120823120824120825120826120827120828120829120830120831120832120833120834120835120836120837120838120839120840120841120842120843120844120845120846120847120848120849120850120851120852120853120854120855120856120857120858120859120860120861120862120863120864120865120866120867120868120869120870120871120872120873120874120875120876120877120878120879120880120881120882120883120884120885120886120887120888120889120890120891120892120893120894120895120896120897120898120899120900120901120902120903120904120905120906120907120908120909120910120911120912120913120914120915120916120917120918120919120920120921120922120923120924120925120926120927120928120929120930120931120932120933120934120935120936120937120938120939120940120941120942120943120944120945120946120947120948120949120950120951120952120953120954120955120956120957120958120959120960120961120962120963120964120965120966120967120968120969120970120971120972120973120974120975120976120977120978120979120980120981120982120983120984120985120986120987120988120989120990120991120992120993120994120995120996120997120998120999121000121001121002121003121004121005121006121007121008121009121010121011121012121013121014121015121016121017121018121019121020121021121022121023121024121025121026121027121028121029121030121031121032121033121034121035121036121037121038121039121040121041121042121043121044121045121046121047121048121049121050121051121052121053121054121055121056121057121058121059121060121061121062121063121064121065121066121067121068121069121070121071121072121073121074121075121076121077121078121079121080121081121082121083121084121085121086121087121088121089121090121091121092121093121094121095121096121097121098121099121100121101121102121103121104121105121106121107121108121109121110121111121112121113121114121115121116121117121118121119121120121121121122121123121124121125121126121127121128121129121130121131121132121133121134121135121136121137121138121139121140121141121142121143121144121145121146121147121148121149121150121151121152121153121154121155121156121157121158121159121160121161121162121163121164121165121166121167121168121169121170121171121172121173121174121175121176121177121178121179121180121181121182121183121184121185121186121187121188121189121190121191121192121193121194121195121196121197121198121199121200121201121202121203121204121205121206121207121208121209121210121211121212121213121214121215121216121217121218121219121220121221121222121223121224121225121226121227121228121229121230121231121232121233121234121235121236121237121238121239121240121241121242121243121244121245121246121247121248121249121250121251121252121253121254121255121256121257121258121259121260121261121262121263121264121265121266121267121268121269121270121271121272121273121274121275121276121277121278121279121280121281121282121283121284121285121286121287121288121289121290121291121292121293121294121295121296121297121298121299121300121301121302121303121304121305121306121307121308121309121310121311121312121313121314121315121316121317121318121319121320121321121322121323121324121325121326121327121328121329121330121331121332121333121334121335121336121337121338121339121340121341121342121343121344121345121346121347121348121349121350121351121352121353121354121355121356121357121358121359121360121361121362121363121364121365121366121367121368121369121370121371121372121373121374121375121376121377121378121379121380121381121382121383121384121385121386121387121388121389121390121391121392121393121394121395121396121397121398121399121400121401121402121403121404121405121406121407121408121409121410121411121412121413121414121415121416121417121418121419121420121421121422121423121424121425121426121427121428121429121430121431121432121433121434121435121436121437121438121439121440121441121442121443121444121445121446121447121448121449121450121451121452121453121454121455121456121457
  1. diff --git a/Documentation/dontdiff b/Documentation/dontdiff
  2. index b89a739..e289b9b 100644
  3. --- a/Documentation/dontdiff
  4. +++ b/Documentation/dontdiff
  5. @@ -2,9 +2,11 @@
  6. *.aux
  7. *.bin
  8. *.bz2
  9. +*.c.[012]*.*
  10. *.cis
  11. *.cpio
  12. *.csp
  13. +*.dbg
  14. *.dsp
  15. *.dvi
  16. *.elf
  17. @@ -14,6 +16,7 @@
  18. *.gcov
  19. *.gen.S
  20. *.gif
  21. +*.gmo
  22. *.grep
  23. *.grp
  24. *.gz
  25. @@ -48,14 +51,17 @@
  26. *.tab.h
  27. *.tex
  28. *.ver
  29. +*.vim
  30. *.xml
  31. *.xz
  32. *_MODULES
  33. +*_reg_safe.h
  34. *_vga16.c
  35. *~
  36. \#*#
  37. *.9
  38. -.*
  39. +.[^g]*
  40. +.gen*
  41. .*.d
  42. .mm
  43. 53c700_d.h
  44. @@ -69,9 +75,11 @@ Image
  45. Module.markers
  46. Module.symvers
  47. PENDING
  48. +PERF*
  49. SCCS
  50. System.map*
  51. TAGS
  52. +TRACEEVENT-CFLAGS
  53. aconf
  54. af_names.h
  55. aic7*reg.h*
  56. @@ -80,6 +88,7 @@ aic7*seq.h*
  57. aicasm
  58. aicdb.h*
  59. altivec*.c
  60. +ashldi3.S
  61. asm-offsets.h
  62. asm_offsets.h
  63. autoconf.h*
  64. @@ -92,32 +101,40 @@ bounds.h
  65. bsetup
  66. btfixupprep
  67. build
  68. +builtin-policy.h
  69. bvmlinux
  70. bzImage*
  71. capability_names.h
  72. capflags.c
  73. classlist.h*
  74. +clut_vga16.c
  75. +common-cmds.h
  76. comp*.log
  77. compile.h*
  78. conf
  79. config
  80. config-*
  81. config_data.h*
  82. +config.c
  83. config.mak
  84. config.mak.autogen
  85. +config.tmp
  86. conmakehash
  87. consolemap_deftbl.c*
  88. cpustr.h
  89. crc32table.h*
  90. cscope.*
  91. defkeymap.c
  92. +devicetable-offsets.h
  93. devlist.h*
  94. dnotify_test
  95. docproc
  96. dslm
  97. +dtc-lexer.lex.c
  98. elf2ecoff
  99. elfconfig.h*
  100. evergreen_reg_safe.h
  101. +exception_policy.conf
  102. fixdep
  103. flask.h
  104. fore200e_mkfirm
  105. @@ -125,12 +142,15 @@ fore200e_pca_fw.c*
  106. gconf
  107. gconf.glade.h
  108. gen-devlist
  109. +gen-kdb_cmds.c
  110. gen_crc32table
  111. gen_init_cpio
  112. generated
  113. genheaders
  114. genksyms
  115. *_gray256.c
  116. +hash
  117. +hid-example
  118. hpet_example
  119. hugepage-mmap
  120. hugepage-shm
  121. @@ -145,14 +165,14 @@ int32.c
  122. int4.c
  123. int8.c
  124. kallsyms
  125. -kconfig
  126. +kern_constants.h
  127. keywords.c
  128. ksym.c*
  129. ksym.h*
  130. kxgettext
  131. lex.c
  132. lex.*.c
  133. -linux
  134. +lib1funcs.S
  135. logo_*.c
  136. logo_*_clut224.c
  137. logo_*_mono.c
  138. @@ -162,14 +182,15 @@ mach-types.h
  139. machtypes.h
  140. map
  141. map_hugetlb
  142. -media
  143. mconf
  144. +mdp
  145. miboot*
  146. mk_elfconfig
  147. mkboot
  148. mkbugboot
  149. mkcpustr
  150. mkdep
  151. +mkpiggy
  152. mkprep
  153. mkregtable
  154. mktables
  155. @@ -185,6 +206,8 @@ oui.c*
  156. page-types
  157. parse.c
  158. parse.h
  159. +parse-events*
  160. +pasyms.h
  161. patches*
  162. pca200e.bin
  163. pca200e_ecd.bin2
  164. @@ -194,6 +217,7 @@ perf-archive
  165. piggyback
  166. piggy.gzip
  167. piggy.S
  168. +pmu-*
  169. pnmtologo
  170. ppc_defs.h*
  171. pss_boot.h
  172. @@ -203,7 +227,12 @@ r200_reg_safe.h
  173. r300_reg_safe.h
  174. r420_reg_safe.h
  175. r600_reg_safe.h
  176. +randomize_layout_hash.h
  177. +randomize_layout_seed.h
  178. +realmode.lds
  179. +realmode.relocs
  180. recordmcount
  181. +regdb.c
  182. relocs
  183. rlim_names.h
  184. rn50_reg_safe.h
  185. @@ -213,8 +242,12 @@ series
  186. setup
  187. setup.bin
  188. setup.elf
  189. +signing_key*
  190. +size_overflow_hash.h
  191. sImage
  192. +slabinfo
  193. sm_tbl*
  194. +sortextable
  195. split-include
  196. syscalltab.h
  197. tables.c
  198. @@ -224,6 +257,7 @@ tftpboot.img
  199. timeconst.h
  200. times.h*
  201. trix_boot.h
  202. +user_constants.h
  203. utsrelease.h*
  204. vdso-syms.lds
  205. vdso.lds
  206. @@ -235,13 +269,17 @@ vdso32.lds
  207. vdso32.so.dbg
  208. vdso64.lds
  209. vdso64.so.dbg
  210. +vdsox32.lds
  211. +vdsox32-syms.lds
  212. version.h*
  213. vmImage
  214. vmlinux
  215. vmlinux-*
  216. vmlinux.aout
  217. vmlinux.bin.all
  218. +vmlinux.bin.bz2
  219. vmlinux.lds
  220. +vmlinux.relocs
  221. vmlinuz
  222. voffset.h
  223. vsyscall.lds
  224. @@ -249,9 +287,12 @@ vsyscall_32.lds
  225. wanxlfw.inc
  226. uImage
  227. unifdef
  228. +utsrelease.h
  229. wakeup.bin
  230. wakeup.elf
  231. wakeup.lds
  232. +x509*
  233. zImage*
  234. zconf.hash.c
  235. +zconf.lex.c
  236. zoffset.h
  237. diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
  238. index 7116fda..d8ed6e8 100644
  239. --- a/Documentation/kernel-parameters.txt
  240. +++ b/Documentation/kernel-parameters.txt
  241. @@ -1084,6 +1084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
  242. Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
  243. Default: 1024
  244. + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
  245. + ignore grsecurity's /proc restrictions
  246. +
  247. +
  248. hashdist= [KNL,NUMA] Large hashes allocated during boot
  249. are distributed across NUMA nodes. Defaults on
  250. for 64-bit NUMA, off otherwise.
  251. @@ -2080,6 +2084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
  252. noexec=on: enable non-executable mappings (default)
  253. noexec=off: disable non-executable mappings
  254. + nopcid [X86-64]
  255. + Disable PCID (Process-Context IDentifier) even if it
  256. + is supported by the processor.
  257. +
  258. nosmap [X86]
  259. Disable SMAP (Supervisor Mode Access Prevention)
  260. even if it is supported by processor.
  261. @@ -2347,6 +2355,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
  262. the specified number of seconds. This is to be used if
  263. your oopses keep scrolling off the screen.
  264. + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
  265. + virtualization environments that don't cope well with the
  266. + expand down segment used by UDEREF on X86-32 or the frequent
  267. + page table updates on X86-64.
  268. +
  269. + pax_sanitize_slab=
  270. + 0/1 to disable/enable slab object sanitization (enabled by
  271. + default).
  272. +
  273. + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
  274. +
  275. + pax_extra_latent_entropy
  276. + Enable a very simple form of latent entropy extraction
  277. + from the first 4GB of memory as the bootmem allocator
  278. + passes the memory pages to the buddy allocator.
  279. +
  280. + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
  281. + when the processor supports PCID.
  282. +
  283. pcbit= [HW,ISDN]
  284. pcd. [PARIDE]
  285. diff --git a/Makefile b/Makefile
  286. index d7c07fd..d6d4bfa 100644
  287. --- a/Makefile
  288. +++ b/Makefile
  289. @@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
  290. HOSTCC = gcc
  291. HOSTCXX = g++
  292. -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
  293. -HOSTCXXFLAGS = -O2
  294. +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
  295. +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
  296. +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
  297. # Decide whether to build built-in, modular, or both.
  298. # Normally, just do built-in.
  299. @@ -423,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
  300. # Rules shared between *config targets and build targets
  301. # Basic helpers built in scripts/
  302. -PHONY += scripts_basic
  303. -scripts_basic:
  304. +PHONY += scripts_basic gcc-plugins
  305. +scripts_basic: gcc-plugins
  306. $(Q)$(MAKE) $(build)=scripts/basic
  307. $(Q)rm -f .tmp_quiet_recordmcount
  308. @@ -585,6 +586,72 @@ else
  309. KBUILD_CFLAGS += -O2
  310. endif
  311. +ifndef DISABLE_PAX_PLUGINS
  312. +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
  313. +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
  314. +else
  315. +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
  316. +endif
  317. +ifneq ($(PLUGINCC),)
  318. +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
  319. +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
  320. +endif
  321. +ifdef CONFIG_PAX_MEMORY_STACKLEAK
  322. +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
  323. +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
  324. +endif
  325. +ifdef CONFIG_KALLOCSTAT_PLUGIN
  326. +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
  327. +endif
  328. +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
  329. +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
  330. +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
  331. +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
  332. +endif
  333. +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
  334. +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
  335. +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
  336. +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
  337. +endif
  338. +endif
  339. +ifdef CONFIG_CHECKER_PLUGIN
  340. +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
  341. +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
  342. +endif
  343. +endif
  344. +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
  345. +ifdef CONFIG_PAX_SIZE_OVERFLOW
  346. +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
  347. +endif
  348. +ifdef CONFIG_PAX_LATENT_ENTROPY
  349. +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
  350. +endif
  351. +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
  352. +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
  353. +endif
  354. +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
  355. +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
  356. +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
  357. +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
  358. +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
  359. +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
  360. +ifeq ($(KBUILD_EXTMOD),)
  361. +gcc-plugins:
  362. + $(Q)$(MAKE) $(build)=tools/gcc
  363. +else
  364. +gcc-plugins: ;
  365. +endif
  366. +else
  367. +gcc-plugins:
  368. +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
  369. + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
  370. +else
  371. + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
  372. +endif
  373. + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
  374. +endif
  375. +endif
  376. +
  377. include $(srctree)/arch/$(SRCARCH)/Makefile
  378. ifdef CONFIG_READABLE_ASM
  379. @@ -779,7 +846,7 @@ export mod_sign_cmd
  380. ifeq ($(KBUILD_EXTMOD),)
  381. -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
  382. +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
  383. vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
  384. $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
  385. @@ -828,6 +895,8 @@ endif
  386. # The actual objects are generated when descending,
  387. # make sure no implicit rule kicks in
  388. +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  389. +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  390. $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
  391. # Handle descending into subdirectories listed in $(vmlinux-dirs)
  392. @@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
  393. # Error messages still appears in the original language
  394. PHONY += $(vmlinux-dirs)
  395. -$(vmlinux-dirs): prepare scripts
  396. +$(vmlinux-dirs): gcc-plugins prepare scripts
  397. $(Q)$(MAKE) $(build)=$@
  398. define filechk_kernel.release
  399. @@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
  400. archprepare: archheaders archscripts prepare1 scripts_basic
  401. +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  402. +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  403. prepare0: archprepare FORCE
  404. $(Q)$(MAKE) $(build)=.
  405. # All the preparing..
  406. +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
  407. prepare: prepare0
  408. # Generate some files
  409. @@ -991,6 +1063,8 @@ all: modules
  410. # using awk while concatenating to the final file.
  411. PHONY += modules
  412. +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  413. +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  414. modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
  415. $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
  416. @$(kecho) ' Building modules, stage 2.';
  417. @@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
  418. # Target to prepare building external modules
  419. PHONY += modules_prepare
  420. -modules_prepare: prepare scripts
  421. +modules_prepare: gcc-plugins prepare scripts
  422. # Target to install modules
  423. PHONY += modules_install
  424. @@ -1072,7 +1146,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
  425. Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
  426. signing_key.priv signing_key.x509 x509.genkey \
  427. extra_certificates signing_key.x509.keyid \
  428. - signing_key.x509.signer
  429. + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
  430. + tools/gcc/randomize_layout_seed.h
  431. # clean - Delete most, but leave enough to build external modules
  432. #
  433. @@ -1112,6 +1187,7 @@ distclean: mrproper
  434. \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
  435. -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
  436. -o -name '.*.rej' \
  437. + -o -name '.*.rej' -o -name '*.so' \
  438. -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
  439. -type f -print | xargs rm -f
  440. @@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
  441. $(module-dirs): crmodverdir $(objtree)/Module.symvers
  442. $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
  443. +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  444. +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  445. modules: $(module-dirs)
  446. @$(kecho) ' Building modules, stage 2.';
  447. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
  448. @@ -1412,17 +1490,21 @@ else
  449. target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
  450. endif
  451. -%.s: %.c prepare scripts FORCE
  452. +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  453. +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  454. +%.s: %.c gcc-plugins prepare scripts FORCE
  455. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  456. %.i: %.c prepare scripts FORCE
  457. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  458. -%.o: %.c prepare scripts FORCE
  459. +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  460. +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  461. +%.o: %.c gcc-plugins prepare scripts FORCE
  462. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  463. %.lst: %.c prepare scripts FORCE
  464. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  465. -%.s: %.S prepare scripts FORCE
  466. +%.s: %.S gcc-plugins prepare scripts FORCE
  467. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  468. -%.o: %.S prepare scripts FORCE
  469. +%.o: %.S gcc-plugins prepare scripts FORCE
  470. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  471. %.symtypes: %.c prepare scripts FORCE
  472. $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  473. @@ -1432,11 +1514,15 @@ endif
  474. $(cmd_crmodverdir)
  475. $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
  476. $(build)=$(build-dir)
  477. -%/: prepare scripts FORCE
  478. +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  479. +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  480. +%/: gcc-plugins prepare scripts FORCE
  481. $(cmd_crmodverdir)
  482. $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
  483. $(build)=$(build-dir)
  484. -%.ko: prepare scripts FORCE
  485. +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  486. +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
  487. +%.ko: gcc-plugins prepare scripts FORCE
  488. $(cmd_crmodverdir)
  489. $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
  490. $(build)=$(build-dir) $(@:.ko=.o)
  491. diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
  492. index 78b03ef..da28a51 100644
  493. --- a/arch/alpha/include/asm/atomic.h
  494. +++ b/arch/alpha/include/asm/atomic.h
  495. @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
  496. #define atomic_dec(v) atomic_sub(1,(v))
  497. #define atomic64_dec(v) atomic64_sub(1,(v))
  498. +#define atomic64_read_unchecked(v) atomic64_read(v)
  499. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  500. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  501. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  502. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  503. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  504. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  505. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  506. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  507. +
  508. #define smp_mb__before_atomic_dec() smp_mb()
  509. #define smp_mb__after_atomic_dec() smp_mb()
  510. #define smp_mb__before_atomic_inc() smp_mb()
  511. diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
  512. index ad368a9..fbe0f25 100644
  513. --- a/arch/alpha/include/asm/cache.h
  514. +++ b/arch/alpha/include/asm/cache.h
  515. @@ -4,19 +4,19 @@
  516. #ifndef __ARCH_ALPHA_CACHE_H
  517. #define __ARCH_ALPHA_CACHE_H
  518. +#include <linux/const.h>
  519. /* Bytes per L1 (data) cache line. */
  520. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
  521. -# define L1_CACHE_BYTES 64
  522. # define L1_CACHE_SHIFT 6
  523. #else
  524. /* Both EV4 and EV5 are write-through, read-allocate,
  525. direct-mapped, physical.
  526. */
  527. -# define L1_CACHE_BYTES 32
  528. # define L1_CACHE_SHIFT 5
  529. #endif
  530. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  531. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  532. #endif
  533. diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
  534. index 968d999..d36b2df 100644
  535. --- a/arch/alpha/include/asm/elf.h
  536. +++ b/arch/alpha/include/asm/elf.h
  537. @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
  538. #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
  539. +#ifdef CONFIG_PAX_ASLR
  540. +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
  541. +
  542. +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
  543. +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
  544. +#endif
  545. +
  546. /* $0 is set by ld.so to a pointer to a function which might be
  547. registered using atexit. This provides a mean for the dynamic
  548. linker to call DT_FINI functions for shared libraries that have
  549. diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
  550. index aab14a0..b4fa3e7 100644
  551. --- a/arch/alpha/include/asm/pgalloc.h
  552. +++ b/arch/alpha/include/asm/pgalloc.h
  553. @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
  554. pgd_set(pgd, pmd);
  555. }
  556. +static inline void
  557. +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
  558. +{
  559. + pgd_populate(mm, pgd, pmd);
  560. +}
  561. +
  562. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  563. static inline void
  564. diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
  565. index d8f9b7e..f6222fa 100644
  566. --- a/arch/alpha/include/asm/pgtable.h
  567. +++ b/arch/alpha/include/asm/pgtable.h
  568. @@ -102,6 +102,17 @@ struct vm_area_struct;
  569. #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
  570. #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
  571. #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
  572. +
  573. +#ifdef CONFIG_PAX_PAGEEXEC
  574. +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
  575. +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
  576. +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
  577. +#else
  578. +# define PAGE_SHARED_NOEXEC PAGE_SHARED
  579. +# define PAGE_COPY_NOEXEC PAGE_COPY
  580. +# define PAGE_READONLY_NOEXEC PAGE_READONLY
  581. +#endif
  582. +
  583. #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
  584. #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
  585. diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
  586. index 2fd00b7..cfd5069 100644
  587. --- a/arch/alpha/kernel/module.c
  588. +++ b/arch/alpha/kernel/module.c
  589. @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
  590. /* The small sections were sorted to the end of the segment.
  591. The following should definitely cover them. */
  592. - gp = (u64)me->module_core + me->core_size - 0x8000;
  593. + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
  594. got = sechdrs[me->arch.gotsecindex].sh_addr;
  595. for (i = 0; i < n; i++) {
  596. diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
  597. index 1402fcc..0b1abd2 100644
  598. --- a/arch/alpha/kernel/osf_sys.c
  599. +++ b/arch/alpha/kernel/osf_sys.c
  600. @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
  601. generic version except that we know how to honor ADDR_LIMIT_32BIT. */
  602. static unsigned long
  603. -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
  604. - unsigned long limit)
  605. +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
  606. + unsigned long limit, unsigned long flags)
  607. {
  608. struct vm_unmapped_area_info info;
  609. + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
  610. info.flags = 0;
  611. info.length = len;
  612. @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
  613. info.high_limit = limit;
  614. info.align_mask = 0;
  615. info.align_offset = 0;
  616. + info.threadstack_offset = offset;
  617. return vm_unmapped_area(&info);
  618. }
  619. @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  620. merely specific addresses, but regions of memory -- perhaps
  621. this feature should be incorporated into all ports? */
  622. +#ifdef CONFIG_PAX_RANDMMAP
  623. + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
  624. +#endif
  625. +
  626. if (addr) {
  627. - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
  628. + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
  629. if (addr != (unsigned long) -ENOMEM)
  630. return addr;
  631. }
  632. /* Next, try allocating at TASK_UNMAPPED_BASE. */
  633. - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
  634. - len, limit);
  635. + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
  636. +
  637. if (addr != (unsigned long) -ENOMEM)
  638. return addr;
  639. /* Finally, try allocating in low memory. */
  640. - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
  641. + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
  642. return addr;
  643. }
  644. diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
  645. index 98838a0..b304fb4 100644
  646. --- a/arch/alpha/mm/fault.c
  647. +++ b/arch/alpha/mm/fault.c
  648. @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
  649. __reload_thread(pcb);
  650. }
  651. +#ifdef CONFIG_PAX_PAGEEXEC
  652. +/*
  653. + * PaX: decide what to do with offenders (regs->pc = fault address)
  654. + *
  655. + * returns 1 when task should be killed
  656. + * 2 when patched PLT trampoline was detected
  657. + * 3 when unpatched PLT trampoline was detected
  658. + */
  659. +static int pax_handle_fetch_fault(struct pt_regs *regs)
  660. +{
  661. +
  662. +#ifdef CONFIG_PAX_EMUPLT
  663. + int err;
  664. +
  665. + do { /* PaX: patched PLT emulation #1 */
  666. + unsigned int ldah, ldq, jmp;
  667. +
  668. + err = get_user(ldah, (unsigned int *)regs->pc);
  669. + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
  670. + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
  671. +
  672. + if (err)
  673. + break;
  674. +
  675. + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
  676. + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
  677. + jmp == 0x6BFB0000U)
  678. + {
  679. + unsigned long r27, addr;
  680. + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
  681. + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
  682. +
  683. + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
  684. + err = get_user(r27, (unsigned long *)addr);
  685. + if (err)
  686. + break;
  687. +
  688. + regs->r27 = r27;
  689. + regs->pc = r27;
  690. + return 2;
  691. + }
  692. + } while (0);
  693. +
  694. + do { /* PaX: patched PLT emulation #2 */
  695. + unsigned int ldah, lda, br;
  696. +
  697. + err = get_user(ldah, (unsigned int *)regs->pc);
  698. + err |= get_user(lda, (unsigned int *)(regs->pc+4));
  699. + err |= get_user(br, (unsigned int *)(regs->pc+8));
  700. +
  701. + if (err)
  702. + break;
  703. +
  704. + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
  705. + (lda & 0xFFFF0000U) == 0xA77B0000U &&
  706. + (br & 0xFFE00000U) == 0xC3E00000U)
  707. + {
  708. + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
  709. + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
  710. + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
  711. +
  712. + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
  713. + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
  714. + return 2;
  715. + }
  716. + } while (0);
  717. +
  718. + do { /* PaX: unpatched PLT emulation */
  719. + unsigned int br;
  720. +
  721. + err = get_user(br, (unsigned int *)regs->pc);
  722. +
  723. + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
  724. + unsigned int br2, ldq, nop, jmp;
  725. + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
  726. +
  727. + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
  728. + err = get_user(br2, (unsigned int *)addr);
  729. + err |= get_user(ldq, (unsigned int *)(addr+4));
  730. + err |= get_user(nop, (unsigned int *)(addr+8));
  731. + err |= get_user(jmp, (unsigned int *)(addr+12));
  732. + err |= get_user(resolver, (unsigned long *)(addr+16));
  733. +
  734. + if (err)
  735. + break;
  736. +
  737. + if (br2 == 0xC3600000U &&
  738. + ldq == 0xA77B000CU &&
  739. + nop == 0x47FF041FU &&
  740. + jmp == 0x6B7B0000U)
  741. + {
  742. + regs->r28 = regs->pc+4;
  743. + regs->r27 = addr+16;
  744. + regs->pc = resolver;
  745. + return 3;
  746. + }
  747. + }
  748. + } while (0);
  749. +#endif
  750. +
  751. + return 1;
  752. +}
  753. +
  754. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  755. +{
  756. + unsigned long i;
  757. +
  758. + printk(KERN_ERR "PAX: bytes at PC: ");
  759. + for (i = 0; i < 5; i++) {
  760. + unsigned int c;
  761. + if (get_user(c, (unsigned int *)pc+i))
  762. + printk(KERN_CONT "???????? ");
  763. + else
  764. + printk(KERN_CONT "%08x ", c);
  765. + }
  766. + printk("\n");
  767. +}
  768. +#endif
  769. /*
  770. * This routine handles page faults. It determines the address,
  771. @@ -133,8 +251,29 @@ retry:
  772. good_area:
  773. si_code = SEGV_ACCERR;
  774. if (cause < 0) {
  775. - if (!(vma->vm_flags & VM_EXEC))
  776. + if (!(vma->vm_flags & VM_EXEC)) {
  777. +
  778. +#ifdef CONFIG_PAX_PAGEEXEC
  779. + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
  780. + goto bad_area;
  781. +
  782. + up_read(&mm->mmap_sem);
  783. + switch (pax_handle_fetch_fault(regs)) {
  784. +
  785. +#ifdef CONFIG_PAX_EMUPLT
  786. + case 2:
  787. + case 3:
  788. + return;
  789. +#endif
  790. +
  791. + }
  792. + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
  793. + do_group_exit(SIGKILL);
  794. +#else
  795. goto bad_area;
  796. +#endif
  797. +
  798. + }
  799. } else if (!cause) {
  800. /* Allow reads even for write-only mappings */
  801. if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
  802. diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
  803. index 44298ad..29a20c0 100644
  804. --- a/arch/arm/Kconfig
  805. +++ b/arch/arm/Kconfig
  806. @@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
  807. config UACCESS_WITH_MEMCPY
  808. bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
  809. - depends on MMU
  810. + depends on MMU && !PAX_MEMORY_UDEREF
  811. default y if CPU_FEROCEON
  812. help
  813. Implement faster copy_to_user and clear_user methods for CPU
  814. @@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
  815. config KEXEC
  816. bool "Kexec system call (EXPERIMENTAL)"
  817. depends on (!SMP || PM_SLEEP_SMP)
  818. + depends on !GRKERNSEC_KMEM
  819. help
  820. kexec is a system call that implements the ability to shutdown your
  821. current kernel, and to start another kernel. It is like a reboot
  822. diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
  823. index 62d2cb5..09d45e3 100644
  824. --- a/arch/arm/include/asm/atomic.h
  825. +++ b/arch/arm/include/asm/atomic.h
  826. @@ -18,17 +18,35 @@
  827. #include <asm/barrier.h>
  828. #include <asm/cmpxchg.h>
  829. +#ifdef CONFIG_GENERIC_ATOMIC64
  830. +#include <asm-generic/atomic64.h>
  831. +#endif
  832. +
  833. #define ATOMIC_INIT(i) { (i) }
  834. #ifdef __KERNEL__
  835. +#define _ASM_EXTABLE(from, to) \
  836. +" .pushsection __ex_table,\"a\"\n"\
  837. +" .align 3\n" \
  838. +" .long " #from ", " #to"\n" \
  839. +" .popsection"
  840. +
  841. /*
  842. * On ARM, ordinary assignment (str instruction) doesn't clear the local
  843. * strex/ldrex monitor on some implementations. The reason we can use it for
  844. * atomic_set() is the clrex or dummy strex done on every exception return.
  845. */
  846. #define atomic_read(v) (*(volatile int *)&(v)->counter)
  847. +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
  848. +{
  849. + return v->counter;
  850. +}
  851. #define atomic_set(v,i) (((v)->counter) = (i))
  852. +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
  853. +{
  854. + v->counter = i;
  855. +}
  856. #if __LINUX_ARM_ARCH__ >= 6
  857. @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
  858. prefetchw(&v->counter);
  859. __asm__ __volatile__("@ atomic_add\n"
  860. +"1: ldrex %1, [%3]\n"
  861. +" adds %0, %1, %4\n"
  862. +
  863. +#ifdef CONFIG_PAX_REFCOUNT
  864. +" bvc 3f\n"
  865. +"2: bkpt 0xf103\n"
  866. +"3:\n"
  867. +#endif
  868. +
  869. +" strex %1, %0, [%3]\n"
  870. +" teq %1, #0\n"
  871. +" bne 1b"
  872. +
  873. +#ifdef CONFIG_PAX_REFCOUNT
  874. +"\n4:\n"
  875. + _ASM_EXTABLE(2b, 4b)
  876. +#endif
  877. +
  878. + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  879. + : "r" (&v->counter), "Ir" (i)
  880. + : "cc");
  881. +}
  882. +
  883. +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
  884. +{
  885. + unsigned long tmp;
  886. + int result;
  887. +
  888. + prefetchw(&v->counter);
  889. + __asm__ __volatile__("@ atomic_add_unchecked\n"
  890. "1: ldrex %0, [%3]\n"
  891. " add %0, %0, %4\n"
  892. " strex %1, %0, [%3]\n"
  893. @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
  894. smp_mb();
  895. __asm__ __volatile__("@ atomic_add_return\n"
  896. +"1: ldrex %1, [%3]\n"
  897. +" adds %0, %1, %4\n"
  898. +
  899. +#ifdef CONFIG_PAX_REFCOUNT
  900. +" bvc 3f\n"
  901. +" mov %0, %1\n"
  902. +"2: bkpt 0xf103\n"
  903. +"3:\n"
  904. +#endif
  905. +
  906. +" strex %1, %0, [%3]\n"
  907. +" teq %1, #0\n"
  908. +" bne 1b"
  909. +
  910. +#ifdef CONFIG_PAX_REFCOUNT
  911. +"\n4:\n"
  912. + _ASM_EXTABLE(2b, 4b)
  913. +#endif
  914. +
  915. + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  916. + : "r" (&v->counter), "Ir" (i)
  917. + : "cc");
  918. +
  919. + smp_mb();
  920. +
  921. + return result;
  922. +}
  923. +
  924. +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
  925. +{
  926. + unsigned long tmp;
  927. + int result;
  928. +
  929. + smp_mb();
  930. +
  931. + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
  932. "1: ldrex %0, [%3]\n"
  933. " add %0, %0, %4\n"
  934. " strex %1, %0, [%3]\n"
  935. @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
  936. prefetchw(&v->counter);
  937. __asm__ __volatile__("@ atomic_sub\n"
  938. +"1: ldrex %1, [%3]\n"
  939. +" subs %0, %1, %4\n"
  940. +
  941. +#ifdef CONFIG_PAX_REFCOUNT
  942. +" bvc 3f\n"
  943. +"2: bkpt 0xf103\n"
  944. +"3:\n"
  945. +#endif
  946. +
  947. +" strex %1, %0, [%3]\n"
  948. +" teq %1, #0\n"
  949. +" bne 1b"
  950. +
  951. +#ifdef CONFIG_PAX_REFCOUNT
  952. +"\n4:\n"
  953. + _ASM_EXTABLE(2b, 4b)
  954. +#endif
  955. +
  956. + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  957. + : "r" (&v->counter), "Ir" (i)
  958. + : "cc");
  959. +}
  960. +
  961. +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
  962. +{
  963. + unsigned long tmp;
  964. + int result;
  965. +
  966. + prefetchw(&v->counter);
  967. + __asm__ __volatile__("@ atomic_sub_unchecked\n"
  968. "1: ldrex %0, [%3]\n"
  969. " sub %0, %0, %4\n"
  970. " strex %1, %0, [%3]\n"
  971. @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
  972. smp_mb();
  973. __asm__ __volatile__("@ atomic_sub_return\n"
  974. -"1: ldrex %0, [%3]\n"
  975. -" sub %0, %0, %4\n"
  976. +"1: ldrex %1, [%3]\n"
  977. +" subs %0, %1, %4\n"
  978. +
  979. +#ifdef CONFIG_PAX_REFCOUNT
  980. +" bvc 3f\n"
  981. +" mov %0, %1\n"
  982. +"2: bkpt 0xf103\n"
  983. +"3:\n"
  984. +#endif
  985. +
  986. " strex %1, %0, [%3]\n"
  987. " teq %1, #0\n"
  988. " bne 1b"
  989. +
  990. +#ifdef CONFIG_PAX_REFCOUNT
  991. +"\n4:\n"
  992. + _ASM_EXTABLE(2b, 4b)
  993. +#endif
  994. +
  995. : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  996. : "r" (&v->counter), "Ir" (i)
  997. : "cc");
  998. @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
  999. return oldval;
  1000. }
  1001. +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
  1002. +{
  1003. + unsigned long oldval, res;
  1004. +
  1005. + smp_mb();
  1006. +
  1007. + do {
  1008. + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
  1009. + "ldrex %1, [%3]\n"
  1010. + "mov %0, #0\n"
  1011. + "teq %1, %4\n"
  1012. + "strexeq %0, %5, [%3]\n"
  1013. + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
  1014. + : "r" (&ptr->counter), "Ir" (old), "r" (new)
  1015. + : "cc");
  1016. + } while (res);
  1017. +
  1018. + smp_mb();
  1019. +
  1020. + return oldval;
  1021. +}
  1022. +
  1023. #else /* ARM_ARCH_6 */
  1024. #ifdef CONFIG_SMP
  1025. @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
  1026. return val;
  1027. }
  1028. +
  1029. +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
  1030. +{
  1031. + return atomic_add_return(i, v);
  1032. +}
  1033. +
  1034. #define atomic_add(i, v) (void) atomic_add_return(i, v)
  1035. +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
  1036. +{
  1037. + (void) atomic_add_return(i, v);
  1038. +}
  1039. static inline int atomic_sub_return(int i, atomic_t *v)
  1040. {
  1041. @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
  1042. return val;
  1043. }
  1044. #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
  1045. +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
  1046. +{
  1047. + (void) atomic_sub_return(i, v);
  1048. +}
  1049. static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
  1050. {
  1051. @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
  1052. return ret;
  1053. }
  1054. +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
  1055. +{
  1056. + return atomic_cmpxchg(v, old, new);
  1057. +}
  1058. +
  1059. #endif /* __LINUX_ARM_ARCH__ */
  1060. #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
  1061. +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
  1062. +{
  1063. + return xchg(&v->counter, new);
  1064. +}
  1065. static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  1066. {
  1067. @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  1068. }
  1069. #define atomic_inc(v) atomic_add(1, v)
  1070. +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
  1071. +{
  1072. + atomic_add_unchecked(1, v);
  1073. +}
  1074. #define atomic_dec(v) atomic_sub(1, v)
  1075. +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
  1076. +{
  1077. + atomic_sub_unchecked(1, v);
  1078. +}
  1079. #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
  1080. +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
  1081. +{
  1082. + return atomic_add_return_unchecked(1, v) == 0;
  1083. +}
  1084. #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
  1085. #define atomic_inc_return(v) (atomic_add_return(1, v))
  1086. +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
  1087. +{
  1088. + return atomic_add_return_unchecked(1, v);
  1089. +}
  1090. #define atomic_dec_return(v) (atomic_sub_return(1, v))
  1091. #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
  1092. @@ -221,6 +410,14 @@ typedef struct {
  1093. long long counter;
  1094. } atomic64_t;
  1095. +#ifdef CONFIG_PAX_REFCOUNT
  1096. +typedef struct {
  1097. + long long counter;
  1098. +} atomic64_unchecked_t;
  1099. +#else
  1100. +typedef atomic64_t atomic64_unchecked_t;
  1101. +#endif
  1102. +
  1103. #define ATOMIC64_INIT(i) { (i) }
  1104. #ifdef CONFIG_ARM_LPAE
  1105. @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
  1106. return result;
  1107. }
  1108. +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
  1109. +{
  1110. + long long result;
  1111. +
  1112. + __asm__ __volatile__("@ atomic64_read_unchecked\n"
  1113. +" ldrd %0, %H0, [%1]"
  1114. + : "=&r" (result)
  1115. + : "r" (&v->counter), "Qo" (v->counter)
  1116. + );
  1117. +
  1118. + return result;
  1119. +}
  1120. +
  1121. static inline void atomic64_set(atomic64_t *v, long long i)
  1122. {
  1123. __asm__ __volatile__("@ atomic64_set\n"
  1124. @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
  1125. : "r" (&v->counter), "r" (i)
  1126. );
  1127. }
  1128. +
  1129. +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
  1130. +{
  1131. + __asm__ __volatile__("@ atomic64_set_unchecked\n"
  1132. +" strd %2, %H2, [%1]"
  1133. + : "=Qo" (v->counter)
  1134. + : "r" (&v->counter), "r" (i)
  1135. + );
  1136. +}
  1137. #else
  1138. static inline long long atomic64_read(const atomic64_t *v)
  1139. {
  1140. @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
  1141. return result;
  1142. }
  1143. +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
  1144. +{
  1145. + long long result;
  1146. +
  1147. + __asm__ __volatile__("@ atomic64_read_unchecked\n"
  1148. +" ldrexd %0, %H0, [%1]"
  1149. + : "=&r" (result)
  1150. + : "r" (&v->counter), "Qo" (v->counter)
  1151. + );
  1152. +
  1153. + return result;
  1154. +}
  1155. +
  1156. static inline void atomic64_set(atomic64_t *v, long long i)
  1157. {
  1158. long long tmp;
  1159. @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
  1160. : "r" (&v->counter), "r" (i)
  1161. : "cc");
  1162. }
  1163. +
  1164. +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
  1165. +{
  1166. + long long tmp;
  1167. +
  1168. + prefetchw(&v->counter);
  1169. + __asm__ __volatile__("@ atomic64_set_unchecked\n"
  1170. +"1: ldrexd %0, %H0, [%2]\n"
  1171. +" strexd %0, %3, %H3, [%2]\n"
  1172. +" teq %0, #0\n"
  1173. +" bne 1b"
  1174. + : "=&r" (tmp), "=Qo" (v->counter)
  1175. + : "r" (&v->counter), "r" (i)
  1176. + : "cc");
  1177. +}
  1178. #endif
  1179. static inline void atomic64_add(long long i, atomic64_t *v)
  1180. @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
  1181. __asm__ __volatile__("@ atomic64_add\n"
  1182. "1: ldrexd %0, %H0, [%3]\n"
  1183. " adds %Q0, %Q0, %Q4\n"
  1184. +" adcs %R0, %R0, %R4\n"
  1185. +
  1186. +#ifdef CONFIG_PAX_REFCOUNT
  1187. +" bvc 3f\n"
  1188. +"2: bkpt 0xf103\n"
  1189. +"3:\n"
  1190. +#endif
  1191. +
  1192. +" strexd %1, %0, %H0, [%3]\n"
  1193. +" teq %1, #0\n"
  1194. +" bne 1b"
  1195. +
  1196. +#ifdef CONFIG_PAX_REFCOUNT
  1197. +"\n4:\n"
  1198. + _ASM_EXTABLE(2b, 4b)
  1199. +#endif
  1200. +
  1201. + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  1202. + : "r" (&v->counter), "r" (i)
  1203. + : "cc");
  1204. +}
  1205. +
  1206. +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
  1207. +{
  1208. + long long result;
  1209. + unsigned long tmp;
  1210. +
  1211. + prefetchw(&v->counter);
  1212. + __asm__ __volatile__("@ atomic64_add_unchecked\n"
  1213. +"1: ldrexd %0, %H0, [%3]\n"
  1214. +" adds %Q0, %Q0, %Q4\n"
  1215. " adc %R0, %R0, %R4\n"
  1216. " strexd %1, %0, %H0, [%3]\n"
  1217. " teq %1, #0\n"
  1218. @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
  1219. __asm__ __volatile__("@ atomic64_add_return\n"
  1220. "1: ldrexd %0, %H0, [%3]\n"
  1221. " adds %Q0, %Q0, %Q4\n"
  1222. +" adcs %R0, %R0, %R4\n"
  1223. +
  1224. +#ifdef CONFIG_PAX_REFCOUNT
  1225. +" bvc 3f\n"
  1226. +" mov %0, %1\n"
  1227. +" mov %H0, %H1\n"
  1228. +"2: bkpt 0xf103\n"
  1229. +"3:\n"
  1230. +#endif
  1231. +
  1232. +" strexd %1, %0, %H0, [%3]\n"
  1233. +" teq %1, #0\n"
  1234. +" bne 1b"
  1235. +
  1236. +#ifdef CONFIG_PAX_REFCOUNT
  1237. +"\n4:\n"
  1238. + _ASM_EXTABLE(2b, 4b)
  1239. +#endif
  1240. +
  1241. + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  1242. + : "r" (&v->counter), "r" (i)
  1243. + : "cc");
  1244. +
  1245. + smp_mb();
  1246. +
  1247. + return result;
  1248. +}
  1249. +
  1250. +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
  1251. +{
  1252. + long long result;
  1253. + unsigned long tmp;
  1254. +
  1255. + smp_mb();
  1256. +
  1257. + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
  1258. +"1: ldrexd %0, %H0, [%3]\n"
  1259. +" adds %Q0, %Q0, %Q4\n"
  1260. " adc %R0, %R0, %R4\n"
  1261. " strexd %1, %0, %H0, [%3]\n"
  1262. " teq %1, #0\n"
  1263. @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
  1264. __asm__ __volatile__("@ atomic64_sub\n"
  1265. "1: ldrexd %0, %H0, [%3]\n"
  1266. " subs %Q0, %Q0, %Q4\n"
  1267. +" sbcs %R0, %R0, %R4\n"
  1268. +
  1269. +#ifdef CONFIG_PAX_REFCOUNT
  1270. +" bvc 3f\n"
  1271. +"2: bkpt 0xf103\n"
  1272. +"3:\n"
  1273. +#endif
  1274. +
  1275. +" strexd %1, %0, %H0, [%3]\n"
  1276. +" teq %1, #0\n"
  1277. +" bne 1b"
  1278. +
  1279. +#ifdef CONFIG_PAX_REFCOUNT
  1280. +"\n4:\n"
  1281. + _ASM_EXTABLE(2b, 4b)
  1282. +#endif
  1283. +
  1284. + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  1285. + : "r" (&v->counter), "r" (i)
  1286. + : "cc");
  1287. +}
  1288. +
  1289. +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
  1290. +{
  1291. + long long result;
  1292. + unsigned long tmp;
  1293. +
  1294. + prefetchw(&v->counter);
  1295. + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
  1296. +"1: ldrexd %0, %H0, [%3]\n"
  1297. +" subs %Q0, %Q0, %Q4\n"
  1298. " sbc %R0, %R0, %R4\n"
  1299. " strexd %1, %0, %H0, [%3]\n"
  1300. " teq %1, #0\n"
  1301. @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
  1302. __asm__ __volatile__("@ atomic64_sub_return\n"
  1303. "1: ldrexd %0, %H0, [%3]\n"
  1304. " subs %Q0, %Q0, %Q4\n"
  1305. -" sbc %R0, %R0, %R4\n"
  1306. +" sbcs %R0, %R0, %R4\n"
  1307. +
  1308. +#ifdef CONFIG_PAX_REFCOUNT
  1309. +" bvc 3f\n"
  1310. +" mov %0, %1\n"
  1311. +" mov %H0, %H1\n"
  1312. +"2: bkpt 0xf103\n"
  1313. +"3:\n"
  1314. +#endif
  1315. +
  1316. " strexd %1, %0, %H0, [%3]\n"
  1317. " teq %1, #0\n"
  1318. " bne 1b"
  1319. +
  1320. +#ifdef CONFIG_PAX_REFCOUNT
  1321. +"\n4:\n"
  1322. + _ASM_EXTABLE(2b, 4b)
  1323. +#endif
  1324. +
  1325. : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  1326. : "r" (&v->counter), "r" (i)
  1327. : "cc");
  1328. - smp_mb();
  1329. -
  1330. return result;
  1331. }
  1332. @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
  1333. return oldval;
  1334. }
  1335. +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
  1336. + long long new)
  1337. +{
  1338. + long long oldval;
  1339. + unsigned long res;
  1340. +
  1341. + smp_mb();
  1342. +
  1343. + do {
  1344. + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
  1345. + "ldrexd %1, %H1, [%3]\n"
  1346. + "mov %0, #0\n"
  1347. + "teq %1, %4\n"
  1348. + "teqeq %H1, %H4\n"
  1349. + "strexdeq %0, %5, %H5, [%3]"
  1350. + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
  1351. + : "r" (&ptr->counter), "r" (old), "r" (new)
  1352. + : "cc");
  1353. + } while (res);
  1354. +
  1355. + smp_mb();
  1356. +
  1357. + return oldval;
  1358. +}
  1359. +
  1360. static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
  1361. {
  1362. long long result;
  1363. @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
  1364. static inline long long atomic64_dec_if_positive(atomic64_t *v)
  1365. {
  1366. long long result;
  1367. - unsigned long tmp;
  1368. + u64 tmp;
  1369. smp_mb();
  1370. __asm__ __volatile__("@ atomic64_dec_if_positive\n"
  1371. -"1: ldrexd %0, %H0, [%3]\n"
  1372. -" subs %Q0, %Q0, #1\n"
  1373. -" sbc %R0, %R0, #0\n"
  1374. +"1: ldrexd %1, %H1, [%3]\n"
  1375. +" subs %Q0, %Q1, #1\n"
  1376. +" sbcs %R0, %R1, #0\n"
  1377. +
  1378. +#ifdef CONFIG_PAX_REFCOUNT
  1379. +" bvc 3f\n"
  1380. +" mov %Q0, %Q1\n"
  1381. +" mov %R0, %R1\n"
  1382. +"2: bkpt 0xf103\n"
  1383. +"3:\n"
  1384. +#endif
  1385. +
  1386. " teq %R0, #0\n"
  1387. -" bmi 2f\n"
  1388. +" bmi 4f\n"
  1389. " strexd %1, %0, %H0, [%3]\n"
  1390. " teq %1, #0\n"
  1391. " bne 1b\n"
  1392. -"2:"
  1393. +"4:\n"
  1394. +
  1395. +#ifdef CONFIG_PAX_REFCOUNT
  1396. + _ASM_EXTABLE(2b, 4b)
  1397. +#endif
  1398. +
  1399. : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
  1400. : "r" (&v->counter)
  1401. : "cc");
  1402. @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
  1403. " teq %0, %5\n"
  1404. " teqeq %H0, %H5\n"
  1405. " moveq %1, #0\n"
  1406. -" beq 2f\n"
  1407. +" beq 4f\n"
  1408. " adds %Q0, %Q0, %Q6\n"
  1409. -" adc %R0, %R0, %R6\n"
  1410. +" adcs %R0, %R0, %R6\n"
  1411. +
  1412. +#ifdef CONFIG_PAX_REFCOUNT
  1413. +" bvc 3f\n"
  1414. +"2: bkpt 0xf103\n"
  1415. +"3:\n"
  1416. +#endif
  1417. +
  1418. " strexd %2, %0, %H0, [%4]\n"
  1419. " teq %2, #0\n"
  1420. " bne 1b\n"
  1421. -"2:"
  1422. +"4:\n"
  1423. +
  1424. +#ifdef CONFIG_PAX_REFCOUNT
  1425. + _ASM_EXTABLE(2b, 4b)
  1426. +#endif
  1427. +
  1428. : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
  1429. : "r" (&v->counter), "r" (u), "r" (a)
  1430. : "cc");
  1431. @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
  1432. #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
  1433. #define atomic64_inc(v) atomic64_add(1LL, (v))
  1434. +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
  1435. #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
  1436. +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
  1437. #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
  1438. #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
  1439. #define atomic64_dec(v) atomic64_sub(1LL, (v))
  1440. +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
  1441. #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
  1442. #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
  1443. #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
  1444. diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
  1445. index 75fe66b..ba3dee4 100644
  1446. --- a/arch/arm/include/asm/cache.h
  1447. +++ b/arch/arm/include/asm/cache.h
  1448. @@ -4,8 +4,10 @@
  1449. #ifndef __ASMARM_CACHE_H
  1450. #define __ASMARM_CACHE_H
  1451. +#include <linux/const.h>
  1452. +
  1453. #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
  1454. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  1455. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  1456. /*
  1457. * Memory returned by kmalloc() may be used for DMA, so we must make
  1458. @@ -24,5 +26,6 @@
  1459. #endif
  1460. #define __read_mostly __attribute__((__section__(".data..read_mostly")))
  1461. +#define __read_only __attribute__ ((__section__(".data..read_only")))
  1462. #endif
  1463. diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
  1464. index 8b8b616..d973d24 100644
  1465. --- a/arch/arm/include/asm/cacheflush.h
  1466. +++ b/arch/arm/include/asm/cacheflush.h
  1467. @@ -116,7 +116,7 @@ struct cpu_cache_fns {
  1468. void (*dma_unmap_area)(const void *, size_t, int);
  1469. void (*dma_flush_range)(const void *, const void *);
  1470. -};
  1471. +} __no_const;
  1472. /*
  1473. * Select the calling method
  1474. diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
  1475. index 5233151..87a71fa 100644
  1476. --- a/arch/arm/include/asm/checksum.h
  1477. +++ b/arch/arm/include/asm/checksum.h
  1478. @@ -37,7 +37,19 @@ __wsum
  1479. csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
  1480. __wsum
  1481. -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
  1482. +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
  1483. +
  1484. +static inline __wsum
  1485. +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
  1486. +{
  1487. + __wsum ret;
  1488. + pax_open_userland();
  1489. + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
  1490. + pax_close_userland();
  1491. + return ret;
  1492. +}
  1493. +
  1494. +
  1495. /*
  1496. * Fold a partial checksum without adding pseudo headers
  1497. diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
  1498. index df2fbba..63fe3e1 100644
  1499. --- a/arch/arm/include/asm/cmpxchg.h
  1500. +++ b/arch/arm/include/asm/cmpxchg.h
  1501. @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
  1502. #define xchg(ptr,x) \
  1503. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  1504. +#define xchg_unchecked(ptr,x) \
  1505. + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  1506. #include <asm-generic/cmpxchg-local.h>
  1507. diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
  1508. index 6ddbe44..b5e38b1 100644
  1509. --- a/arch/arm/include/asm/domain.h
  1510. +++ b/arch/arm/include/asm/domain.h
  1511. @@ -48,18 +48,37 @@
  1512. * Domain types
  1513. */
  1514. #define DOMAIN_NOACCESS 0
  1515. -#define DOMAIN_CLIENT 1
  1516. #ifdef CONFIG_CPU_USE_DOMAINS
  1517. +#define DOMAIN_USERCLIENT 1
  1518. +#define DOMAIN_KERNELCLIENT 1
  1519. #define DOMAIN_MANAGER 3
  1520. +#define DOMAIN_VECTORS DOMAIN_USER
  1521. #else
  1522. +
  1523. +#ifdef CONFIG_PAX_KERNEXEC
  1524. #define DOMAIN_MANAGER 1
  1525. +#define DOMAIN_KERNEXEC 3
  1526. +#else
  1527. +#define DOMAIN_MANAGER 1
  1528. +#endif
  1529. +
  1530. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  1531. +#define DOMAIN_USERCLIENT 0
  1532. +#define DOMAIN_UDEREF 1
  1533. +#define DOMAIN_VECTORS DOMAIN_KERNEL
  1534. +#else
  1535. +#define DOMAIN_USERCLIENT 1
  1536. +#define DOMAIN_VECTORS DOMAIN_USER
  1537. +#endif
  1538. +#define DOMAIN_KERNELCLIENT 1
  1539. +
  1540. #endif
  1541. #define domain_val(dom,type) ((type) << (2*(dom)))
  1542. #ifndef __ASSEMBLY__
  1543. -#ifdef CONFIG_CPU_USE_DOMAINS
  1544. +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  1545. static inline void set_domain(unsigned val)
  1546. {
  1547. asm volatile(
  1548. @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
  1549. isb();
  1550. }
  1551. -#define modify_domain(dom,type) \
  1552. - do { \
  1553. - struct thread_info *thread = current_thread_info(); \
  1554. - unsigned int domain = thread->cpu_domain; \
  1555. - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
  1556. - thread->cpu_domain = domain | domain_val(dom, type); \
  1557. - set_domain(thread->cpu_domain); \
  1558. - } while (0)
  1559. -
  1560. +extern void modify_domain(unsigned int dom, unsigned int type);
  1561. #else
  1562. static inline void set_domain(unsigned val) { }
  1563. static inline void modify_domain(unsigned dom, unsigned type) { }
  1564. diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
  1565. index f4b46d3..abc9b2b 100644
  1566. --- a/arch/arm/include/asm/elf.h
  1567. +++ b/arch/arm/include/asm/elf.h
  1568. @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
  1569. the loader. We need to make sure that it is out of the way of the program
  1570. that it will "exec", and that there is sufficient room for the brk. */
  1571. -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
  1572. +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
  1573. +
  1574. +#ifdef CONFIG_PAX_ASLR
  1575. +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
  1576. +
  1577. +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
  1578. +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
  1579. +#endif
  1580. /* When the program starts, a1 contains a pointer to a function to be
  1581. registered with atexit, as per the SVR4 ABI. A value of 0 means we
  1582. @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
  1583. extern void elf_set_personality(const struct elf32_hdr *);
  1584. #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
  1585. -struct mm_struct;
  1586. -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
  1587. -#define arch_randomize_brk arch_randomize_brk
  1588. -
  1589. #ifdef CONFIG_MMU
  1590. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
  1591. struct linux_binprm;
  1592. diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
  1593. index de53547..52b9a28 100644
  1594. --- a/arch/arm/include/asm/fncpy.h
  1595. +++ b/arch/arm/include/asm/fncpy.h
  1596. @@ -81,7 +81,9 @@
  1597. BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
  1598. (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
  1599. \
  1600. + pax_open_kernel(); \
  1601. memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
  1602. + pax_close_kernel(); \
  1603. flush_icache_range((unsigned long)(dest_buf), \
  1604. (unsigned long)(dest_buf) + (size)); \
  1605. \
  1606. diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
  1607. index 2aff798..099eb15 100644
  1608. --- a/arch/arm/include/asm/futex.h
  1609. +++ b/arch/arm/include/asm/futex.h
  1610. @@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  1611. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  1612. return -EFAULT;
  1613. + pax_open_userland();
  1614. +
  1615. smp_mb();
  1616. __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
  1617. "1: ldrex %1, [%4]\n"
  1618. @@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  1619. : "cc", "memory");
  1620. smp_mb();
  1621. + pax_close_userland();
  1622. +
  1623. *uval = val;
  1624. return ret;
  1625. }
  1626. @@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  1627. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  1628. return -EFAULT;
  1629. + pax_open_userland();
  1630. +
  1631. __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
  1632. "1: " TUSER(ldr) " %1, [%4]\n"
  1633. " teq %1, %2\n"
  1634. @@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  1635. : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
  1636. : "cc", "memory");
  1637. + pax_close_userland();
  1638. +
  1639. *uval = val;
  1640. return ret;
  1641. }
  1642. @@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
  1643. return -EFAULT;
  1644. pagefault_disable(); /* implies preempt_disable() */
  1645. + pax_open_userland();
  1646. switch (op) {
  1647. case FUTEX_OP_SET:
  1648. @@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
  1649. ret = -ENOSYS;
  1650. }
  1651. + pax_close_userland();
  1652. pagefault_enable(); /* subsumes preempt_enable() */
  1653. if (!ret) {
  1654. diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
  1655. index 83eb2f7..ed77159 100644
  1656. --- a/arch/arm/include/asm/kmap_types.h
  1657. +++ b/arch/arm/include/asm/kmap_types.h
  1658. @@ -4,6 +4,6 @@
  1659. /*
  1660. * This is the "bare minimum". AIO seems to require this.
  1661. */
  1662. -#define KM_TYPE_NR 16
  1663. +#define KM_TYPE_NR 17
  1664. #endif
  1665. diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
  1666. index 9e614a1..3302cca 100644
  1667. --- a/arch/arm/include/asm/mach/dma.h
  1668. +++ b/arch/arm/include/asm/mach/dma.h
  1669. @@ -22,7 +22,7 @@ struct dma_ops {
  1670. int (*residue)(unsigned int, dma_t *); /* optional */
  1671. int (*setspeed)(unsigned int, dma_t *, int); /* optional */
  1672. const char *type;
  1673. -};
  1674. +} __do_const;
  1675. struct dma_struct {
  1676. void *addr; /* single DMA address */
  1677. diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
  1678. index f98c7f3..e5c626d 100644
  1679. --- a/arch/arm/include/asm/mach/map.h
  1680. +++ b/arch/arm/include/asm/mach/map.h
  1681. @@ -23,17 +23,19 @@ struct map_desc {
  1682. /* types 0-3 are defined in asm/io.h */
  1683. enum {
  1684. - MT_UNCACHED = 4,
  1685. - MT_CACHECLEAN,
  1686. - MT_MINICLEAN,
  1687. + MT_UNCACHED_RW = 4,
  1688. + MT_CACHECLEAN_RO,
  1689. + MT_MINICLEAN_RO,
  1690. MT_LOW_VECTORS,
  1691. MT_HIGH_VECTORS,
  1692. - MT_MEMORY_RWX,
  1693. + __MT_MEMORY_RWX,
  1694. MT_MEMORY_RW,
  1695. - MT_ROM,
  1696. - MT_MEMORY_RWX_NONCACHED,
  1697. + MT_MEMORY_RX,
  1698. + MT_ROM_RX,
  1699. + MT_MEMORY_RW_NONCACHED,
  1700. + MT_MEMORY_RX_NONCACHED,
  1701. MT_MEMORY_RW_DTCM,
  1702. - MT_MEMORY_RWX_ITCM,
  1703. + MT_MEMORY_RX_ITCM,
  1704. MT_MEMORY_RW_SO,
  1705. MT_MEMORY_DMA_READY,
  1706. };
  1707. diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
  1708. index f94784f..9a09a4a 100644
  1709. --- a/arch/arm/include/asm/outercache.h
  1710. +++ b/arch/arm/include/asm/outercache.h
  1711. @@ -35,7 +35,7 @@ struct outer_cache_fns {
  1712. #endif
  1713. void (*set_debug)(unsigned long);
  1714. void (*resume)(void);
  1715. -};
  1716. +} __no_const;
  1717. extern struct outer_cache_fns outer_cache;
  1718. diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
  1719. index 4355f0e..cd9168e 100644
  1720. --- a/arch/arm/include/asm/page.h
  1721. +++ b/arch/arm/include/asm/page.h
  1722. @@ -23,6 +23,7 @@
  1723. #else
  1724. +#include <linux/compiler.h>
  1725. #include <asm/glue.h>
  1726. /*
  1727. @@ -114,7 +115,7 @@ struct cpu_user_fns {
  1728. void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
  1729. void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
  1730. unsigned long vaddr, struct vm_area_struct *vma);
  1731. -};
  1732. +} __no_const;
  1733. #ifdef MULTI_USER
  1734. extern struct cpu_user_fns cpu_user;
  1735. diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
  1736. index 78a7793..e3dc06c 100644
  1737. --- a/arch/arm/include/asm/pgalloc.h
  1738. +++ b/arch/arm/include/asm/pgalloc.h
  1739. @@ -17,6 +17,7 @@
  1740. #include <asm/processor.h>
  1741. #include <asm/cacheflush.h>
  1742. #include <asm/tlbflush.h>
  1743. +#include <asm/system_info.h>
  1744. #define check_pgt_cache() do { } while (0)
  1745. @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  1746. set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
  1747. }
  1748. +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  1749. +{
  1750. + pud_populate(mm, pud, pmd);
  1751. +}
  1752. +
  1753. #else /* !CONFIG_ARM_LPAE */
  1754. /*
  1755. @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  1756. #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
  1757. #define pmd_free(mm, pmd) do { } while (0)
  1758. #define pud_populate(mm,pmd,pte) BUG()
  1759. +#define pud_populate_kernel(mm,pmd,pte) BUG()
  1760. #endif /* CONFIG_ARM_LPAE */
  1761. @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  1762. __free_page(pte);
  1763. }
  1764. +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
  1765. +{
  1766. +#ifdef CONFIG_ARM_LPAE
  1767. + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
  1768. +#else
  1769. + if (addr & SECTION_SIZE)
  1770. + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
  1771. + else
  1772. + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
  1773. +#endif
  1774. + flush_pmd_entry(pmdp);
  1775. +}
  1776. +
  1777. static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
  1778. pmdval_t prot)
  1779. {
  1780. @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  1781. static inline void
  1782. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
  1783. {
  1784. - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
  1785. + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
  1786. }
  1787. #define pmd_pgtable(pmd) pmd_page(pmd)
  1788. diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
  1789. index 5cfba15..f415e1a 100644
  1790. --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
  1791. +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
  1792. @@ -20,12 +20,15 @@
  1793. #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
  1794. #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
  1795. #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
  1796. +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
  1797. #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
  1798. #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
  1799. #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
  1800. +
  1801. /*
  1802. * - section
  1803. */
  1804. +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
  1805. #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
  1806. #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
  1807. #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
  1808. @@ -37,6 +40,7 @@
  1809. #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
  1810. #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
  1811. #define PMD_SECT_AF (_AT(pmdval_t, 0))
  1812. +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
  1813. #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
  1814. #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
  1815. @@ -66,6 +70,7 @@
  1816. * - extended small page/tiny page
  1817. */
  1818. #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
  1819. +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
  1820. #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
  1821. #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
  1822. #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
  1823. diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
  1824. index 219ac88..73ec32a 100644
  1825. --- a/arch/arm/include/asm/pgtable-2level.h
  1826. +++ b/arch/arm/include/asm/pgtable-2level.h
  1827. @@ -126,6 +126,9 @@
  1828. #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
  1829. #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
  1830. +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
  1831. +#define L_PTE_PXN (_AT(pteval_t, 0))
  1832. +
  1833. /*
  1834. * These are the memory types, defined to be compatible with
  1835. * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
  1836. diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
  1837. index 626989f..9d67a33 100644
  1838. --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
  1839. +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
  1840. @@ -75,6 +75,7 @@
  1841. #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
  1842. #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
  1843. #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
  1844. +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
  1845. #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
  1846. /*
  1847. diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
  1848. index 85c60ad..b0bbd7e 100644
  1849. --- a/arch/arm/include/asm/pgtable-3level.h
  1850. +++ b/arch/arm/include/asm/pgtable-3level.h
  1851. @@ -82,6 +82,7 @@
  1852. #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
  1853. #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
  1854. #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
  1855. +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
  1856. #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
  1857. #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
  1858. #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
  1859. @@ -95,6 +96,7 @@
  1860. /*
  1861. * To be used in assembly code with the upper page attributes.
  1862. */
  1863. +#define L_PTE_PXN_HIGH (1 << (53 - 32))
  1864. #define L_PTE_XN_HIGH (1 << (54 - 32))
  1865. #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
  1866. diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
  1867. index 7d59b52..27a12f8 100644
  1868. --- a/arch/arm/include/asm/pgtable.h
  1869. +++ b/arch/arm/include/asm/pgtable.h
  1870. @@ -33,6 +33,9 @@
  1871. #include <asm/pgtable-2level.h>
  1872. #endif
  1873. +#define ktla_ktva(addr) (addr)
  1874. +#define ktva_ktla(addr) (addr)
  1875. +
  1876. /*
  1877. * Just any arbitrary offset to the start of the vmalloc VM area: the
  1878. * current 8MB value just means that there will be a 8MB "hole" after the
  1879. @@ -48,6 +51,9 @@
  1880. #define LIBRARY_TEXT_START 0x0c000000
  1881. #ifndef __ASSEMBLY__
  1882. +extern pteval_t __supported_pte_mask;
  1883. +extern pmdval_t __supported_pmd_mask;
  1884. +
  1885. extern void __pte_error(const char *file, int line, pte_t);
  1886. extern void __pmd_error(const char *file, int line, pmd_t);
  1887. extern void __pgd_error(const char *file, int line, pgd_t);
  1888. @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
  1889. #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
  1890. #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
  1891. +#define __HAVE_ARCH_PAX_OPEN_KERNEL
  1892. +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
  1893. +
  1894. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  1895. +#include <asm/domain.h>
  1896. +#include <linux/thread_info.h>
  1897. +#include <linux/preempt.h>
  1898. +
  1899. +static inline int test_domain(int domain, int domaintype)
  1900. +{
  1901. + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
  1902. +}
  1903. +#endif
  1904. +
  1905. +#ifdef CONFIG_PAX_KERNEXEC
  1906. +static inline unsigned long pax_open_kernel(void) {
  1907. +#ifdef CONFIG_ARM_LPAE
  1908. + /* TODO */
  1909. +#else
  1910. + preempt_disable();
  1911. + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
  1912. + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
  1913. +#endif
  1914. + return 0;
  1915. +}
  1916. +
  1917. +static inline unsigned long pax_close_kernel(void) {
  1918. +#ifdef CONFIG_ARM_LPAE
  1919. + /* TODO */
  1920. +#else
  1921. + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
  1922. + /* DOMAIN_MANAGER = "client" under KERNEXEC */
  1923. + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
  1924. + preempt_enable_no_resched();
  1925. +#endif
  1926. + return 0;
  1927. +}
  1928. +#else
  1929. +static inline unsigned long pax_open_kernel(void) { return 0; }
  1930. +static inline unsigned long pax_close_kernel(void) { return 0; }
  1931. +#endif
  1932. +
  1933. /*
  1934. * This is the lowest virtual address we can permit any user space
  1935. * mapping to be mapped at. This is particularly important for
  1936. @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
  1937. /*
  1938. * The pgprot_* and protection_map entries will be fixed up in runtime
  1939. * to include the cachable and bufferable bits based on memory policy,
  1940. - * as well as any architecture dependent bits like global/ASID and SMP
  1941. - * shared mapping bits.
  1942. + * as well as any architecture dependent bits like global/ASID, PXN,
  1943. + * and SMP shared mapping bits.
  1944. */
  1945. #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
  1946. @@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  1947. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  1948. {
  1949. const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
  1950. - L_PTE_NONE | L_PTE_VALID;
  1951. + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
  1952. pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
  1953. return pte;
  1954. }
  1955. diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
  1956. index c4ae171..ea0c0c2 100644
  1957. --- a/arch/arm/include/asm/psci.h
  1958. +++ b/arch/arm/include/asm/psci.h
  1959. @@ -29,7 +29,7 @@ struct psci_operations {
  1960. int (*cpu_off)(struct psci_power_state state);
  1961. int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
  1962. int (*migrate)(unsigned long cpuid);
  1963. -};
  1964. +} __no_const;
  1965. extern struct psci_operations psci_ops;
  1966. extern struct smp_operations psci_smp_ops;
  1967. diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
  1968. index 22a3b9b..7f214ee 100644
  1969. --- a/arch/arm/include/asm/smp.h
  1970. +++ b/arch/arm/include/asm/smp.h
  1971. @@ -112,7 +112,7 @@ struct smp_operations {
  1972. int (*cpu_disable)(unsigned int cpu);
  1973. #endif
  1974. #endif
  1975. -};
  1976. +} __no_const;
  1977. /*
  1978. * set platform specific SMP operations
  1979. diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
  1980. index 71a06b2..8bb9ae1 100644
  1981. --- a/arch/arm/include/asm/thread_info.h
  1982. +++ b/arch/arm/include/asm/thread_info.h
  1983. @@ -88,9 +88,9 @@ struct thread_info {
  1984. .flags = 0, \
  1985. .preempt_count = INIT_PREEMPT_COUNT, \
  1986. .addr_limit = KERNEL_DS, \
  1987. - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
  1988. - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
  1989. - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
  1990. + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
  1991. + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
  1992. + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
  1993. .restart_block = { \
  1994. .fn = do_no_restart_syscall, \
  1995. }, \
  1996. @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
  1997. #define TIF_SYSCALL_AUDIT 9
  1998. #define TIF_SYSCALL_TRACEPOINT 10
  1999. #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
  2000. -#define TIF_NOHZ 12 /* in adaptive nohz mode */
  2001. +/* within 8 bits of TIF_SYSCALL_TRACE
  2002. + * to meet flexible second operand requirements
  2003. + */
  2004. +#define TIF_GRSEC_SETXID 12
  2005. +#define TIF_NOHZ 13 /* in adaptive nohz mode */
  2006. #define TIF_USING_IWMMXT 17
  2007. #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
  2008. #define TIF_RESTORE_SIGMASK 20
  2009. @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
  2010. #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
  2011. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  2012. #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
  2013. +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
  2014. /* Checks for any syscall work in entry-common.S */
  2015. #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  2016. - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
  2017. + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
  2018. /*
  2019. * Change these and you break ASM code in entry-common.S
  2020. diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
  2021. index 72abdc5..35acac1 100644
  2022. --- a/arch/arm/include/asm/uaccess.h
  2023. +++ b/arch/arm/include/asm/uaccess.h
  2024. @@ -18,6 +18,7 @@
  2025. #include <asm/domain.h>
  2026. #include <asm/unified.h>
  2027. #include <asm/compiler.h>
  2028. +#include <asm/pgtable.h>
  2029. #if __LINUX_ARM_ARCH__ < 6
  2030. #include <asm-generic/uaccess-unaligned.h>
  2031. @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
  2032. static inline void set_fs(mm_segment_t fs)
  2033. {
  2034. current_thread_info()->addr_limit = fs;
  2035. - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
  2036. + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
  2037. }
  2038. #define segment_eq(a,b) ((a) == (b))
  2039. +#define __HAVE_ARCH_PAX_OPEN_USERLAND
  2040. +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
  2041. +
  2042. +static inline void pax_open_userland(void)
  2043. +{
  2044. +
  2045. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2046. + if (segment_eq(get_fs(), USER_DS)) {
  2047. + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
  2048. + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
  2049. + }
  2050. +#endif
  2051. +
  2052. +}
  2053. +
  2054. +static inline void pax_close_userland(void)
  2055. +{
  2056. +
  2057. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2058. + if (segment_eq(get_fs(), USER_DS)) {
  2059. + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
  2060. + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
  2061. + }
  2062. +#endif
  2063. +
  2064. +}
  2065. +
  2066. #define __addr_ok(addr) ({ \
  2067. unsigned long flag; \
  2068. __asm__("cmp %2, %0; movlo %0, #0" \
  2069. @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
  2070. #define get_user(x,p) \
  2071. ({ \
  2072. + int __e; \
  2073. might_fault(); \
  2074. - __get_user_check(x,p); \
  2075. + pax_open_userland(); \
  2076. + __e = __get_user_check(x,p); \
  2077. + pax_close_userland(); \
  2078. + __e; \
  2079. })
  2080. extern int __put_user_1(void *, unsigned int);
  2081. @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
  2082. #define put_user(x,p) \
  2083. ({ \
  2084. + int __e; \
  2085. might_fault(); \
  2086. - __put_user_check(x,p); \
  2087. + pax_open_userland(); \
  2088. + __e = __put_user_check(x,p); \
  2089. + pax_close_userland(); \
  2090. + __e; \
  2091. })
  2092. #else /* CONFIG_MMU */
  2093. @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
  2094. #endif /* CONFIG_MMU */
  2095. +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
  2096. #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
  2097. #define user_addr_max() \
  2098. @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
  2099. #define __get_user(x,ptr) \
  2100. ({ \
  2101. long __gu_err = 0; \
  2102. + pax_open_userland(); \
  2103. __get_user_err((x),(ptr),__gu_err); \
  2104. + pax_close_userland(); \
  2105. __gu_err; \
  2106. })
  2107. #define __get_user_error(x,ptr,err) \
  2108. ({ \
  2109. + pax_open_userland(); \
  2110. __get_user_err((x),(ptr),err); \
  2111. + pax_close_userland(); \
  2112. (void) 0; \
  2113. })
  2114. @@ -319,13 +360,17 @@ do { \
  2115. #define __put_user(x,ptr) \
  2116. ({ \
  2117. long __pu_err = 0; \
  2118. + pax_open_userland(); \
  2119. __put_user_err((x),(ptr),__pu_err); \
  2120. + pax_close_userland(); \
  2121. __pu_err; \
  2122. })
  2123. #define __put_user_error(x,ptr,err) \
  2124. ({ \
  2125. + pax_open_userland(); \
  2126. __put_user_err((x),(ptr),err); \
  2127. + pax_close_userland(); \
  2128. (void) 0; \
  2129. })
  2130. @@ -425,11 +470,44 @@ do { \
  2131. #ifdef CONFIG_MMU
  2132. -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
  2133. -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
  2134. +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
  2135. +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
  2136. +
  2137. +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
  2138. +{
  2139. + unsigned long ret;
  2140. +
  2141. + check_object_size(to, n, false);
  2142. + pax_open_userland();
  2143. + ret = ___copy_from_user(to, from, n);
  2144. + pax_close_userland();
  2145. + return ret;
  2146. +}
  2147. +
  2148. +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
  2149. +{
  2150. + unsigned long ret;
  2151. +
  2152. + check_object_size(from, n, true);
  2153. + pax_open_userland();
  2154. + ret = ___copy_to_user(to, from, n);
  2155. + pax_close_userland();
  2156. + return ret;
  2157. +}
  2158. +
  2159. extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
  2160. -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
  2161. +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
  2162. extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
  2163. +
  2164. +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
  2165. +{
  2166. + unsigned long ret;
  2167. + pax_open_userland();
  2168. + ret = ___clear_user(addr, n);
  2169. + pax_close_userland();
  2170. + return ret;
  2171. +}
  2172. +
  2173. #else
  2174. #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
  2175. #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
  2176. @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
  2177. static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
  2178. {
  2179. + if ((long)n < 0)
  2180. + return n;
  2181. +
  2182. if (access_ok(VERIFY_READ, from, n))
  2183. n = __copy_from_user(to, from, n);
  2184. else /* security hole - plug it */
  2185. @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
  2186. static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
  2187. {
  2188. + if ((long)n < 0)
  2189. + return n;
  2190. +
  2191. if (access_ok(VERIFY_WRITE, to, n))
  2192. n = __copy_to_user(to, from, n);
  2193. return n;
  2194. diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
  2195. index 5af0ed1..cea83883 100644
  2196. --- a/arch/arm/include/uapi/asm/ptrace.h
  2197. +++ b/arch/arm/include/uapi/asm/ptrace.h
  2198. @@ -92,7 +92,7 @@
  2199. * ARMv7 groups of PSR bits
  2200. */
  2201. #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
  2202. -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
  2203. +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
  2204. #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
  2205. #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
  2206. diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
  2207. index 85e664b..419a1cd 100644
  2208. --- a/arch/arm/kernel/armksyms.c
  2209. +++ b/arch/arm/kernel/armksyms.c
  2210. @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
  2211. /* networking */
  2212. EXPORT_SYMBOL(csum_partial);
  2213. -EXPORT_SYMBOL(csum_partial_copy_from_user);
  2214. +EXPORT_SYMBOL(__csum_partial_copy_from_user);
  2215. EXPORT_SYMBOL(csum_partial_copy_nocheck);
  2216. EXPORT_SYMBOL(__csum_ipv6_magic);
  2217. @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
  2218. #ifdef CONFIG_MMU
  2219. EXPORT_SYMBOL(copy_page);
  2220. -EXPORT_SYMBOL(__copy_from_user);
  2221. -EXPORT_SYMBOL(__copy_to_user);
  2222. -EXPORT_SYMBOL(__clear_user);
  2223. +EXPORT_SYMBOL(___copy_from_user);
  2224. +EXPORT_SYMBOL(___copy_to_user);
  2225. +EXPORT_SYMBOL(___clear_user);
  2226. EXPORT_SYMBOL(__get_user_1);
  2227. EXPORT_SYMBOL(__get_user_2);
  2228. diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
  2229. index 1879e8d..b2207fc 100644
  2230. --- a/arch/arm/kernel/entry-armv.S
  2231. +++ b/arch/arm/kernel/entry-armv.S
  2232. @@ -47,6 +47,87 @@
  2233. 9997:
  2234. .endm
  2235. + .macro pax_enter_kernel
  2236. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2237. + @ make aligned space for saved DACR
  2238. + sub sp, sp, #8
  2239. + @ save regs
  2240. + stmdb sp!, {r1, r2}
  2241. + @ read DACR from cpu_domain into r1
  2242. + mov r2, sp
  2243. + @ assume 8K pages, since we have to split the immediate in two
  2244. + bic r2, r2, #(0x1fc0)
  2245. + bic r2, r2, #(0x3f)
  2246. + ldr r1, [r2, #TI_CPU_DOMAIN]
  2247. + @ store old DACR on stack
  2248. + str r1, [sp, #8]
  2249. +#ifdef CONFIG_PAX_KERNEXEC
  2250. + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
  2251. + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
  2252. + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
  2253. +#endif
  2254. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2255. + @ set current DOMAIN_USER to DOMAIN_NOACCESS
  2256. + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
  2257. +#endif
  2258. + @ write r1 to current_thread_info()->cpu_domain
  2259. + str r1, [r2, #TI_CPU_DOMAIN]
  2260. + @ write r1 to DACR
  2261. + mcr p15, 0, r1, c3, c0, 0
  2262. + @ instruction sync
  2263. + instr_sync
  2264. + @ restore regs
  2265. + ldmia sp!, {r1, r2}
  2266. +#endif
  2267. + .endm
  2268. +
  2269. + .macro pax_open_userland
  2270. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2271. + @ save regs
  2272. + stmdb sp!, {r0, r1}
  2273. + @ read DACR from cpu_domain into r1
  2274. + mov r0, sp
  2275. + @ assume 8K pages, since we have to split the immediate in two
  2276. + bic r0, r0, #(0x1fc0)
  2277. + bic r0, r0, #(0x3f)
  2278. + ldr r1, [r0, #TI_CPU_DOMAIN]
  2279. + @ set current DOMAIN_USER to DOMAIN_CLIENT
  2280. + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
  2281. + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
  2282. + @ write r1 to current_thread_info()->cpu_domain
  2283. + str r1, [r0, #TI_CPU_DOMAIN]
  2284. + @ write r1 to DACR
  2285. + mcr p15, 0, r1, c3, c0, 0
  2286. + @ instruction sync
  2287. + instr_sync
  2288. + @ restore regs
  2289. + ldmia sp!, {r0, r1}
  2290. +#endif
  2291. + .endm
  2292. +
  2293. + .macro pax_close_userland
  2294. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2295. + @ save regs
  2296. + stmdb sp!, {r0, r1}
  2297. + @ read DACR from cpu_domain into r1
  2298. + mov r0, sp
  2299. + @ assume 8K pages, since we have to split the immediate in two
  2300. + bic r0, r0, #(0x1fc0)
  2301. + bic r0, r0, #(0x3f)
  2302. + ldr r1, [r0, #TI_CPU_DOMAIN]
  2303. + @ set current DOMAIN_USER to DOMAIN_NOACCESS
  2304. + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
  2305. + @ write r1 to current_thread_info()->cpu_domain
  2306. + str r1, [r0, #TI_CPU_DOMAIN]
  2307. + @ write r1 to DACR
  2308. + mcr p15, 0, r1, c3, c0, 0
  2309. + @ instruction sync
  2310. + instr_sync
  2311. + @ restore regs
  2312. + ldmia sp!, {r0, r1}
  2313. +#endif
  2314. + .endm
  2315. +
  2316. .macro pabt_helper
  2317. @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
  2318. #ifdef MULTI_PABORT
  2319. @@ -89,11 +170,15 @@
  2320. * Invalid mode handlers
  2321. */
  2322. .macro inv_entry, reason
  2323. +
  2324. + pax_enter_kernel
  2325. +
  2326. sub sp, sp, #S_FRAME_SIZE
  2327. ARM( stmib sp, {r1 - lr} )
  2328. THUMB( stmia sp, {r0 - r12} )
  2329. THUMB( str sp, [sp, #S_SP] )
  2330. THUMB( str lr, [sp, #S_LR] )
  2331. +
  2332. mov r1, #\reason
  2333. .endm
  2334. @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
  2335. .macro svc_entry, stack_hole=0
  2336. UNWIND(.fnstart )
  2337. UNWIND(.save {r0 - pc} )
  2338. +
  2339. + pax_enter_kernel
  2340. +
  2341. sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
  2342. +
  2343. #ifdef CONFIG_THUMB2_KERNEL
  2344. SPFIX( str r0, [sp] ) @ temporarily saved
  2345. SPFIX( mov r0, sp )
  2346. @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
  2347. ldmia r0, {r3 - r5}
  2348. add r7, sp, #S_SP - 4 @ here for interlock avoidance
  2349. mov r6, #-1 @ "" "" "" ""
  2350. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2351. + @ offset sp by 8 as done in pax_enter_kernel
  2352. + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
  2353. +#else
  2354. add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
  2355. +#endif
  2356. SPFIX( addeq r2, r2, #4 )
  2357. str r3, [sp, #-4]! @ save the "real" r0 copied
  2358. @ from the exception stack
  2359. @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
  2360. .macro usr_entry
  2361. UNWIND(.fnstart )
  2362. UNWIND(.cantunwind ) @ don't unwind the user space
  2363. +
  2364. + pax_enter_kernel_user
  2365. +
  2366. sub sp, sp, #S_FRAME_SIZE
  2367. ARM( stmib sp, {r1 - r12} )
  2368. THUMB( stmia sp, {r0 - r12} )
  2369. @@ -416,7 +513,9 @@ __und_usr:
  2370. tst r3, #PSR_T_BIT @ Thumb mode?
  2371. bne __und_usr_thumb
  2372. sub r4, r2, #4 @ ARM instr at LR - 4
  2373. + pax_open_userland
  2374. 1: ldrt r0, [r4]
  2375. + pax_close_userland
  2376. ARM_BE8(rev r0, r0) @ little endian instruction
  2377. @ r0 = 32-bit ARM instruction which caused the exception
  2378. @@ -450,11 +549,15 @@ __und_usr_thumb:
  2379. */
  2380. .arch armv6t2
  2381. #endif
  2382. + pax_open_userland
  2383. 2: ldrht r5, [r4]
  2384. + pax_close_userland
  2385. ARM_BE8(rev16 r5, r5) @ little endian instruction
  2386. cmp r5, #0xe800 @ 32bit instruction if xx != 0
  2387. blo __und_usr_fault_16 @ 16bit undefined instruction
  2388. + pax_open_userland
  2389. 3: ldrht r0, [r2]
  2390. + pax_close_userland
  2391. ARM_BE8(rev16 r0, r0) @ little endian instruction
  2392. add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
  2393. str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
  2394. @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
  2395. */
  2396. .pushsection .fixup, "ax"
  2397. .align 2
  2398. -4: mov pc, r9
  2399. +4: pax_close_userland
  2400. + mov pc, r9
  2401. .popsection
  2402. .pushsection __ex_table,"a"
  2403. .long 1b, 4b
  2404. @@ -694,7 +798,7 @@ ENTRY(__switch_to)
  2405. THUMB( str lr, [ip], #4 )
  2406. ldr r4, [r2, #TI_TP_VALUE]
  2407. ldr r5, [r2, #TI_TP_VALUE + 4]
  2408. -#ifdef CONFIG_CPU_USE_DOMAINS
  2409. +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2410. ldr r6, [r2, #TI_CPU_DOMAIN]
  2411. #endif
  2412. switch_tls r1, r4, r5, r3, r7
  2413. @@ -703,7 +807,7 @@ ENTRY(__switch_to)
  2414. ldr r8, =__stack_chk_guard
  2415. ldr r7, [r7, #TSK_STACK_CANARY]
  2416. #endif
  2417. -#ifdef CONFIG_CPU_USE_DOMAINS
  2418. +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2419. mcr p15, 0, r6, c3, c0, 0 @ Set domain register
  2420. #endif
  2421. mov r5, r0
  2422. diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
  2423. index a2dcafd..1048b5a 100644
  2424. --- a/arch/arm/kernel/entry-common.S
  2425. +++ b/arch/arm/kernel/entry-common.S
  2426. @@ -10,18 +10,46 @@
  2427. #include <asm/unistd.h>
  2428. #include <asm/ftrace.h>
  2429. +#include <asm/domain.h>
  2430. #include <asm/unwind.h>
  2431. +#include "entry-header.S"
  2432. +
  2433. #ifdef CONFIG_NEED_RET_TO_USER
  2434. #include <mach/entry-macro.S>
  2435. #else
  2436. .macro arch_ret_to_user, tmp1, tmp2
  2437. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2438. + @ save regs
  2439. + stmdb sp!, {r1, r2}
  2440. + @ read DACR from cpu_domain into r1
  2441. + mov r2, sp
  2442. + @ assume 8K pages, since we have to split the immediate in two
  2443. + bic r2, r2, #(0x1fc0)
  2444. + bic r2, r2, #(0x3f)
  2445. + ldr r1, [r2, #TI_CPU_DOMAIN]
  2446. +#ifdef CONFIG_PAX_KERNEXEC
  2447. + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
  2448. + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
  2449. + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
  2450. +#endif
  2451. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2452. + @ set current DOMAIN_USER to DOMAIN_UDEREF
  2453. + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
  2454. + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
  2455. +#endif
  2456. + @ write r1 to current_thread_info()->cpu_domain
  2457. + str r1, [r2, #TI_CPU_DOMAIN]
  2458. + @ write r1 to DACR
  2459. + mcr p15, 0, r1, c3, c0, 0
  2460. + @ instruction sync
  2461. + instr_sync
  2462. + @ restore regs
  2463. + ldmia sp!, {r1, r2}
  2464. +#endif
  2465. .endm
  2466. #endif
  2467. -#include "entry-header.S"
  2468. -
  2469. -
  2470. .align 5
  2471. /*
  2472. * This is the fast syscall return path. We do as little as
  2473. @@ -411,6 +439,12 @@ ENTRY(vector_swi)
  2474. USER( ldr scno, [lr, #-4] ) @ get SWI instruction
  2475. #endif
  2476. + /*
  2477. + * do this here to avoid a performance hit of wrapping the code above
  2478. + * that directly dereferences userland to parse the SWI instruction
  2479. + */
  2480. + pax_enter_kernel_user
  2481. +
  2482. adr tbl, sys_call_table @ load syscall table pointer
  2483. #if defined(CONFIG_OABI_COMPAT)
  2484. diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
  2485. index 39f89fb..d612bd9 100644
  2486. --- a/arch/arm/kernel/entry-header.S
  2487. +++ b/arch/arm/kernel/entry-header.S
  2488. @@ -184,6 +184,60 @@
  2489. msr cpsr_c, \rtemp @ switch back to the SVC mode
  2490. .endm
  2491. + .macro pax_enter_kernel_user
  2492. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2493. + @ save regs
  2494. + stmdb sp!, {r0, r1}
  2495. + @ read DACR from cpu_domain into r1
  2496. + mov r0, sp
  2497. + @ assume 8K pages, since we have to split the immediate in two
  2498. + bic r0, r0, #(0x1fc0)
  2499. + bic r0, r0, #(0x3f)
  2500. + ldr r1, [r0, #TI_CPU_DOMAIN]
  2501. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  2502. + @ set current DOMAIN_USER to DOMAIN_NOACCESS
  2503. + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
  2504. +#endif
  2505. +#ifdef CONFIG_PAX_KERNEXEC
  2506. + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
  2507. + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
  2508. + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
  2509. +#endif
  2510. + @ write r1 to current_thread_info()->cpu_domain
  2511. + str r1, [r0, #TI_CPU_DOMAIN]
  2512. + @ write r1 to DACR
  2513. + mcr p15, 0, r1, c3, c0, 0
  2514. + @ instruction sync
  2515. + instr_sync
  2516. + @ restore regs
  2517. + ldmia sp!, {r0, r1}
  2518. +#endif
  2519. + .endm
  2520. +
  2521. + .macro pax_exit_kernel
  2522. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  2523. + @ save regs
  2524. + stmdb sp!, {r0, r1}
  2525. + @ read old DACR from stack into r1
  2526. + ldr r1, [sp, #(8 + S_SP)]
  2527. + sub r1, r1, #8
  2528. + ldr r1, [r1]
  2529. +
  2530. + @ write r1 to current_thread_info()->cpu_domain
  2531. + mov r0, sp
  2532. + @ assume 8K pages, since we have to split the immediate in two
  2533. + bic r0, r0, #(0x1fc0)
  2534. + bic r0, r0, #(0x3f)
  2535. + str r1, [r0, #TI_CPU_DOMAIN]
  2536. + @ write r1 to DACR
  2537. + mcr p15, 0, r1, c3, c0, 0
  2538. + @ instruction sync
  2539. + instr_sync
  2540. + @ restore regs
  2541. + ldmia sp!, {r0, r1}
  2542. +#endif
  2543. + .endm
  2544. +
  2545. #ifndef CONFIG_THUMB2_KERNEL
  2546. .macro svc_exit, rpsr, irq = 0
  2547. .if \irq != 0
  2548. @@ -203,6 +257,9 @@
  2549. blne trace_hardirqs_off
  2550. #endif
  2551. .endif
  2552. +
  2553. + pax_exit_kernel
  2554. +
  2555. msr spsr_cxsf, \rpsr
  2556. #if defined(CONFIG_CPU_V6)
  2557. ldr r0, [sp]
  2558. @@ -266,6 +323,9 @@
  2559. blne trace_hardirqs_off
  2560. #endif
  2561. .endif
  2562. +
  2563. + pax_exit_kernel
  2564. +
  2565. ldr lr, [sp, #S_SP] @ top of the stack
  2566. ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
  2567. clrex @ clear the exclusive monitor
  2568. diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
  2569. index 918875d..cd5fa27 100644
  2570. --- a/arch/arm/kernel/fiq.c
  2571. +++ b/arch/arm/kernel/fiq.c
  2572. @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
  2573. void *base = vectors_page;
  2574. unsigned offset = FIQ_OFFSET;
  2575. + pax_open_kernel();
  2576. memcpy(base + offset, start, length);
  2577. + pax_close_kernel();
  2578. +
  2579. if (!cache_is_vipt_nonaliasing())
  2580. flush_icache_range((unsigned long)base + offset, offset +
  2581. length);
  2582. diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
  2583. index f5f381d..a6f36a1 100644
  2584. --- a/arch/arm/kernel/head.S
  2585. +++ b/arch/arm/kernel/head.S
  2586. @@ -437,7 +437,7 @@ __enable_mmu:
  2587. mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
  2588. domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
  2589. domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
  2590. - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
  2591. + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
  2592. mcr p15, 0, r5, c3, c0, 0 @ load domain access register
  2593. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  2594. #endif
  2595. diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
  2596. index 45e4781..8eac93d 100644
  2597. --- a/arch/arm/kernel/module.c
  2598. +++ b/arch/arm/kernel/module.c
  2599. @@ -38,12 +38,39 @@
  2600. #endif
  2601. #ifdef CONFIG_MMU
  2602. -void *module_alloc(unsigned long size)
  2603. +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
  2604. {
  2605. + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
  2606. + return NULL;
  2607. return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
  2608. - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
  2609. + GFP_KERNEL, prot, NUMA_NO_NODE,
  2610. __builtin_return_address(0));
  2611. }
  2612. +
  2613. +void *module_alloc(unsigned long size)
  2614. +{
  2615. +
  2616. +#ifdef CONFIG_PAX_KERNEXEC
  2617. + return __module_alloc(size, PAGE_KERNEL);
  2618. +#else
  2619. + return __module_alloc(size, PAGE_KERNEL_EXEC);
  2620. +#endif
  2621. +
  2622. +}
  2623. +
  2624. +#ifdef CONFIG_PAX_KERNEXEC
  2625. +void module_free_exec(struct module *mod, void *module_region)
  2626. +{
  2627. + module_free(mod, module_region);
  2628. +}
  2629. +EXPORT_SYMBOL(module_free_exec);
  2630. +
  2631. +void *module_alloc_exec(unsigned long size)
  2632. +{
  2633. + return __module_alloc(size, PAGE_KERNEL_EXEC);
  2634. +}
  2635. +EXPORT_SYMBOL(module_alloc_exec);
  2636. +#endif
  2637. #endif
  2638. int
  2639. diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
  2640. index 07314af..c46655c 100644
  2641. --- a/arch/arm/kernel/patch.c
  2642. +++ b/arch/arm/kernel/patch.c
  2643. @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
  2644. bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
  2645. int size;
  2646. + pax_open_kernel();
  2647. if (thumb2 && __opcode_is_thumb16(insn)) {
  2648. *(u16 *)addr = __opcode_to_mem_thumb16(insn);
  2649. size = sizeof(u16);
  2650. @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
  2651. *(u32 *)addr = insn;
  2652. size = sizeof(u32);
  2653. }
  2654. + pax_close_kernel();
  2655. flush_icache_range((uintptr_t)(addr),
  2656. (uintptr_t)(addr) + size);
  2657. diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
  2658. index 92f7b15..7048500 100644
  2659. --- a/arch/arm/kernel/process.c
  2660. +++ b/arch/arm/kernel/process.c
  2661. @@ -217,6 +217,7 @@ void machine_power_off(void)
  2662. if (pm_power_off)
  2663. pm_power_off();
  2664. + BUG();
  2665. }
  2666. /*
  2667. @@ -230,7 +231,7 @@ void machine_power_off(void)
  2668. * executing pre-reset code, and using RAM that the primary CPU's code wishes
  2669. * to use. Implementing such co-ordination would be essentially impossible.
  2670. */
  2671. -void machine_restart(char *cmd)
  2672. +__noreturn void machine_restart(char *cmd)
  2673. {
  2674. local_irq_disable();
  2675. smp_send_stop();
  2676. @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
  2677. show_regs_print_info(KERN_DEFAULT);
  2678. - print_symbol("PC is at %s\n", instruction_pointer(regs));
  2679. - print_symbol("LR is at %s\n", regs->ARM_lr);
  2680. + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
  2681. + printk("LR is at %pA\n", (void *)regs->ARM_lr);
  2682. printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
  2683. "sp : %08lx ip : %08lx fp : %08lx\n",
  2684. regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
  2685. @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
  2686. return 0;
  2687. }
  2688. -unsigned long arch_randomize_brk(struct mm_struct *mm)
  2689. -{
  2690. - unsigned long range_end = mm->brk + 0x02000000;
  2691. - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
  2692. -}
  2693. -
  2694. #ifdef CONFIG_MMU
  2695. #ifdef CONFIG_KUSER_HELPERS
  2696. /*
  2697. @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
  2698. static int __init gate_vma_init(void)
  2699. {
  2700. - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
  2701. + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
  2702. return 0;
  2703. }
  2704. arch_initcall(gate_vma_init);
  2705. @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
  2706. const char *arch_vma_name(struct vm_area_struct *vma)
  2707. {
  2708. - return is_gate_vma(vma) ? "[vectors]" :
  2709. - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
  2710. - "[sigpage]" : NULL;
  2711. + return is_gate_vma(vma) ? "[vectors]" : NULL;
  2712. }
  2713. -static struct page *signal_page;
  2714. -extern struct page *get_signal_page(void);
  2715. -
  2716. int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  2717. {
  2718. struct mm_struct *mm = current->mm;
  2719. - unsigned long addr;
  2720. - int ret;
  2721. -
  2722. - if (!signal_page)
  2723. - signal_page = get_signal_page();
  2724. - if (!signal_page)
  2725. - return -ENOMEM;
  2726. down_write(&mm->mmap_sem);
  2727. - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  2728. - if (IS_ERR_VALUE(addr)) {
  2729. - ret = addr;
  2730. - goto up_fail;
  2731. - }
  2732. -
  2733. - ret = install_special_mapping(mm, addr, PAGE_SIZE,
  2734. - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
  2735. - &signal_page);
  2736. -
  2737. - if (ret == 0)
  2738. - mm->context.sigpage = addr;
  2739. -
  2740. - up_fail:
  2741. + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
  2742. up_write(&mm->mmap_sem);
  2743. - return ret;
  2744. + return 0;
  2745. }
  2746. #endif
  2747. diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
  2748. index 4693188..4596c5e 100644
  2749. --- a/arch/arm/kernel/psci.c
  2750. +++ b/arch/arm/kernel/psci.c
  2751. @@ -24,7 +24,7 @@
  2752. #include <asm/opcodes-virt.h>
  2753. #include <asm/psci.h>
  2754. -struct psci_operations psci_ops;
  2755. +struct psci_operations psci_ops __read_only;
  2756. static int (*invoke_psci_fn)(u32, u32, u32, u32);
  2757. diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
  2758. index 0dd3b79..e018f64 100644
  2759. --- a/arch/arm/kernel/ptrace.c
  2760. +++ b/arch/arm/kernel/ptrace.c
  2761. @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
  2762. return current_thread_info()->syscall;
  2763. }
  2764. +#ifdef CONFIG_GRKERNSEC_SETXID
  2765. +extern void gr_delayed_cred_worker(void);
  2766. +#endif
  2767. +
  2768. asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
  2769. {
  2770. current_thread_info()->syscall = scno;
  2771. +#ifdef CONFIG_GRKERNSEC_SETXID
  2772. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  2773. + gr_delayed_cred_worker();
  2774. +#endif
  2775. +
  2776. /* Do the secure computing check first; failures should be fast. */
  2777. if (secure_computing(scno) == -1)
  2778. return -1;
  2779. diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
  2780. index 1e8b030..37c3022 100644
  2781. --- a/arch/arm/kernel/setup.c
  2782. +++ b/arch/arm/kernel/setup.c
  2783. @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
  2784. unsigned int elf_hwcap __read_mostly;
  2785. EXPORT_SYMBOL(elf_hwcap);
  2786. +pteval_t __supported_pte_mask __read_only;
  2787. +pmdval_t __supported_pmd_mask __read_only;
  2788. #ifdef MULTI_CPU
  2789. -struct processor processor __read_mostly;
  2790. +struct processor processor __read_only;
  2791. #endif
  2792. #ifdef MULTI_TLB
  2793. -struct cpu_tlb_fns cpu_tlb __read_mostly;
  2794. +struct cpu_tlb_fns cpu_tlb __read_only;
  2795. #endif
  2796. #ifdef MULTI_USER
  2797. -struct cpu_user_fns cpu_user __read_mostly;
  2798. +struct cpu_user_fns cpu_user __read_only;
  2799. #endif
  2800. #ifdef MULTI_CACHE
  2801. -struct cpu_cache_fns cpu_cache __read_mostly;
  2802. +struct cpu_cache_fns cpu_cache __read_only;
  2803. #endif
  2804. #ifdef CONFIG_OUTER_CACHE
  2805. -struct outer_cache_fns outer_cache __read_mostly;
  2806. +struct outer_cache_fns outer_cache __read_only;
  2807. EXPORT_SYMBOL(outer_cache);
  2808. #endif
  2809. @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
  2810. asm("mrc p15, 0, %0, c0, c1, 4"
  2811. : "=r" (mmfr0));
  2812. if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
  2813. - (mmfr0 & 0x000000f0) >= 0x00000030)
  2814. + (mmfr0 & 0x000000f0) >= 0x00000030) {
  2815. cpu_arch = CPU_ARCH_ARMv7;
  2816. - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
  2817. + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
  2818. + __supported_pte_mask |= L_PTE_PXN;
  2819. + __supported_pmd_mask |= PMD_PXNTABLE;
  2820. + }
  2821. + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
  2822. (mmfr0 & 0x000000f0) == 0x00000020)
  2823. cpu_arch = CPU_ARCH_ARMv6;
  2824. else
  2825. diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
  2826. index 04d6388..5115238 100644
  2827. --- a/arch/arm/kernel/signal.c
  2828. +++ b/arch/arm/kernel/signal.c
  2829. @@ -23,8 +23,6 @@
  2830. extern const unsigned long sigreturn_codes[7];
  2831. -static unsigned long signal_return_offset;
  2832. -
  2833. #ifdef CONFIG_CRUNCH
  2834. static int preserve_crunch_context(struct crunch_sigframe __user *frame)
  2835. {
  2836. @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
  2837. * except when the MPU has protected the vectors
  2838. * page from PL0
  2839. */
  2840. - retcode = mm->context.sigpage + signal_return_offset +
  2841. - (idx << 2) + thumb;
  2842. + retcode = mm->context.sigpage + (idx << 2) + thumb;
  2843. } else
  2844. #endif
  2845. {
  2846. @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
  2847. } while (thread_flags & _TIF_WORK_MASK);
  2848. return 0;
  2849. }
  2850. -
  2851. -struct page *get_signal_page(void)
  2852. -{
  2853. - unsigned long ptr;
  2854. - unsigned offset;
  2855. - struct page *page;
  2856. - void *addr;
  2857. -
  2858. - page = alloc_pages(GFP_KERNEL, 0);
  2859. -
  2860. - if (!page)
  2861. - return NULL;
  2862. -
  2863. - addr = page_address(page);
  2864. -
  2865. - /* Give the signal return code some randomness */
  2866. - offset = 0x200 + (get_random_int() & 0x7fc);
  2867. - signal_return_offset = offset;
  2868. -
  2869. - /*
  2870. - * Copy signal return handlers into the vector page, and
  2871. - * set sigreturn to be a pointer to these.
  2872. - */
  2873. - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
  2874. -
  2875. - ptr = (unsigned long)addr + offset;
  2876. - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
  2877. -
  2878. - return page;
  2879. -}
  2880. diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
  2881. index b7b4c86..47c4f77 100644
  2882. --- a/arch/arm/kernel/smp.c
  2883. +++ b/arch/arm/kernel/smp.c
  2884. @@ -73,7 +73,7 @@ enum ipi_msg_type {
  2885. static DECLARE_COMPLETION(cpu_running);
  2886. -static struct smp_operations smp_ops;
  2887. +static struct smp_operations smp_ops __read_only;
  2888. void __init smp_set_ops(struct smp_operations *ops)
  2889. {
  2890. diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
  2891. index 7a3be1d..b00c7de 100644
  2892. --- a/arch/arm/kernel/tcm.c
  2893. +++ b/arch/arm/kernel/tcm.c
  2894. @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
  2895. .virtual = ITCM_OFFSET,
  2896. .pfn = __phys_to_pfn(ITCM_OFFSET),
  2897. .length = 0,
  2898. - .type = MT_MEMORY_RWX_ITCM,
  2899. + .type = MT_MEMORY_RX_ITCM,
  2900. }
  2901. };
  2902. @@ -267,7 +267,9 @@ no_dtcm:
  2903. start = &__sitcm_text;
  2904. end = &__eitcm_text;
  2905. ram = &__itcm_start;
  2906. + pax_open_kernel();
  2907. memcpy(start, ram, itcm_code_sz);
  2908. + pax_close_kernel();
  2909. pr_debug("CPU ITCM: copied code from %p - %p\n",
  2910. start, end);
  2911. itcm_present = true;
  2912. diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
  2913. index 172ee18..ce4ec3d 100644
  2914. --- a/arch/arm/kernel/traps.c
  2915. +++ b/arch/arm/kernel/traps.c
  2916. @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
  2917. void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
  2918. {
  2919. #ifdef CONFIG_KALLSYMS
  2920. - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
  2921. + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
  2922. #else
  2923. printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
  2924. #endif
  2925. @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
  2926. static int die_owner = -1;
  2927. static unsigned int die_nest_count;
  2928. +extern void gr_handle_kernel_exploit(void);
  2929. +
  2930. static unsigned long oops_begin(void)
  2931. {
  2932. int cpu;
  2933. @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
  2934. panic("Fatal exception in interrupt");
  2935. if (panic_on_oops)
  2936. panic("Fatal exception");
  2937. +
  2938. + gr_handle_kernel_exploit();
  2939. +
  2940. if (signr)
  2941. do_exit(signr);
  2942. }
  2943. @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
  2944. * The user helper at 0xffff0fe0 must be used instead.
  2945. * (see entry-armv.S for details)
  2946. */
  2947. + pax_open_kernel();
  2948. *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
  2949. + pax_close_kernel();
  2950. }
  2951. return 0;
  2952. @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
  2953. kuser_init(vectors_base);
  2954. flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
  2955. - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
  2956. +
  2957. +#ifndef CONFIG_PAX_MEMORY_UDEREF
  2958. + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
  2959. +#endif
  2960. +
  2961. #else /* ifndef CONFIG_CPU_V7M */
  2962. /*
  2963. * on V7-M there is no need to copy the vector table to a dedicated
  2964. diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
  2965. index 7bcee5c..e2f3249 100644
  2966. --- a/arch/arm/kernel/vmlinux.lds.S
  2967. +++ b/arch/arm/kernel/vmlinux.lds.S
  2968. @@ -8,7 +8,11 @@
  2969. #include <asm/thread_info.h>
  2970. #include <asm/memory.h>
  2971. #include <asm/page.h>
  2972. -
  2973. +
  2974. +#ifdef CONFIG_PAX_KERNEXEC
  2975. +#include <asm/pgtable.h>
  2976. +#endif
  2977. +
  2978. #define PROC_INFO \
  2979. . = ALIGN(4); \
  2980. VMLINUX_SYMBOL(__proc_info_begin) = .; \
  2981. @@ -34,7 +38,7 @@
  2982. #endif
  2983. #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
  2984. - defined(CONFIG_GENERIC_BUG)
  2985. + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
  2986. #define ARM_EXIT_KEEP(x) x
  2987. #define ARM_EXIT_DISCARD(x)
  2988. #else
  2989. @@ -90,6 +94,11 @@ SECTIONS
  2990. _text = .;
  2991. HEAD_TEXT
  2992. }
  2993. +
  2994. +#ifdef CONFIG_PAX_KERNEXEC
  2995. + . = ALIGN(1<<SECTION_SHIFT);
  2996. +#endif
  2997. +
  2998. .text : { /* Real text segment */
  2999. _stext = .; /* Text and read-only data */
  3000. __exception_text_start = .;
  3001. @@ -112,6 +121,8 @@ SECTIONS
  3002. ARM_CPU_KEEP(PROC_INFO)
  3003. }
  3004. + _etext = .; /* End of text section */
  3005. +
  3006. RO_DATA(PAGE_SIZE)
  3007. . = ALIGN(4);
  3008. @@ -142,7 +153,9 @@ SECTIONS
  3009. NOTES
  3010. - _etext = .; /* End of text and rodata section */
  3011. +#ifdef CONFIG_PAX_KERNEXEC
  3012. + . = ALIGN(1<<SECTION_SHIFT);
  3013. +#endif
  3014. #ifndef CONFIG_XIP_KERNEL
  3015. . = ALIGN(PAGE_SIZE);
  3016. @@ -220,6 +233,11 @@ SECTIONS
  3017. . = PAGE_OFFSET + TEXT_OFFSET;
  3018. #else
  3019. __init_end = .;
  3020. +
  3021. +#ifdef CONFIG_PAX_KERNEXEC
  3022. + . = ALIGN(1<<SECTION_SHIFT);
  3023. +#endif
  3024. +
  3025. . = ALIGN(THREAD_SIZE);
  3026. __data_loc = .;
  3027. #endif
  3028. diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
  3029. index bd18bb8..87ede26 100644
  3030. --- a/arch/arm/kvm/arm.c
  3031. +++ b/arch/arm/kvm/arm.c
  3032. @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
  3033. static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
  3034. /* The VMID used in the VTTBR */
  3035. -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
  3036. +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
  3037. static u8 kvm_next_vmid;
  3038. static DEFINE_SPINLOCK(kvm_vmid_lock);
  3039. @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
  3040. */
  3041. static bool need_new_vmid_gen(struct kvm *kvm)
  3042. {
  3043. - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
  3044. + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
  3045. }
  3046. /**
  3047. @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
  3048. /* First user of a new VMID generation? */
  3049. if (unlikely(kvm_next_vmid == 0)) {
  3050. - atomic64_inc(&kvm_vmid_gen);
  3051. + atomic64_inc_unchecked(&kvm_vmid_gen);
  3052. kvm_next_vmid = 1;
  3053. /*
  3054. @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
  3055. kvm_call_hyp(__kvm_flush_vm_context);
  3056. }
  3057. - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
  3058. + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
  3059. kvm->arch.vmid = kvm_next_vmid;
  3060. kvm_next_vmid++;
  3061. diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
  3062. index 14a0d98..7771a7d 100644
  3063. --- a/arch/arm/lib/clear_user.S
  3064. +++ b/arch/arm/lib/clear_user.S
  3065. @@ -12,14 +12,14 @@
  3066. .text
  3067. -/* Prototype: int __clear_user(void *addr, size_t sz)
  3068. +/* Prototype: int ___clear_user(void *addr, size_t sz)
  3069. * Purpose : clear some user memory
  3070. * Params : addr - user memory address to clear
  3071. * : sz - number of bytes to clear
  3072. * Returns : number of bytes NOT cleared
  3073. */
  3074. ENTRY(__clear_user_std)
  3075. -WEAK(__clear_user)
  3076. +WEAK(___clear_user)
  3077. stmfd sp!, {r1, lr}
  3078. mov r2, #0
  3079. cmp r1, #4
  3080. @@ -44,7 +44,7 @@ WEAK(__clear_user)
  3081. USER( strnebt r2, [r0])
  3082. mov r0, #0
  3083. ldmfd sp!, {r1, pc}
  3084. -ENDPROC(__clear_user)
  3085. +ENDPROC(___clear_user)
  3086. ENDPROC(__clear_user_std)
  3087. .pushsection .fixup,"ax"
  3088. diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
  3089. index 66a477a..bee61d3 100644
  3090. --- a/arch/arm/lib/copy_from_user.S
  3091. +++ b/arch/arm/lib/copy_from_user.S
  3092. @@ -16,7 +16,7 @@
  3093. /*
  3094. * Prototype:
  3095. *
  3096. - * size_t __copy_from_user(void *to, const void *from, size_t n)
  3097. + * size_t ___copy_from_user(void *to, const void *from, size_t n)
  3098. *
  3099. * Purpose:
  3100. *
  3101. @@ -84,11 +84,11 @@
  3102. .text
  3103. -ENTRY(__copy_from_user)
  3104. +ENTRY(___copy_from_user)
  3105. #include "copy_template.S"
  3106. -ENDPROC(__copy_from_user)
  3107. +ENDPROC(___copy_from_user)
  3108. .pushsection .fixup,"ax"
  3109. .align 0
  3110. diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
  3111. index 6ee2f67..d1cce76 100644
  3112. --- a/arch/arm/lib/copy_page.S
  3113. +++ b/arch/arm/lib/copy_page.S
  3114. @@ -10,6 +10,7 @@
  3115. * ASM optimised string functions
  3116. */
  3117. #include <linux/linkage.h>
  3118. +#include <linux/const.h>
  3119. #include <asm/assembler.h>
  3120. #include <asm/asm-offsets.h>
  3121. #include <asm/cache.h>
  3122. diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
  3123. index d066df6..df28194 100644
  3124. --- a/arch/arm/lib/copy_to_user.S
  3125. +++ b/arch/arm/lib/copy_to_user.S
  3126. @@ -16,7 +16,7 @@
  3127. /*
  3128. * Prototype:
  3129. *
  3130. - * size_t __copy_to_user(void *to, const void *from, size_t n)
  3131. + * size_t ___copy_to_user(void *to, const void *from, size_t n)
  3132. *
  3133. * Purpose:
  3134. *
  3135. @@ -88,11 +88,11 @@
  3136. .text
  3137. ENTRY(__copy_to_user_std)
  3138. -WEAK(__copy_to_user)
  3139. +WEAK(___copy_to_user)
  3140. #include "copy_template.S"
  3141. -ENDPROC(__copy_to_user)
  3142. +ENDPROC(___copy_to_user)
  3143. ENDPROC(__copy_to_user_std)
  3144. .pushsection .fixup,"ax"
  3145. diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
  3146. index 7d08b43..f7ca7ea 100644
  3147. --- a/arch/arm/lib/csumpartialcopyuser.S
  3148. +++ b/arch/arm/lib/csumpartialcopyuser.S
  3149. @@ -57,8 +57,8 @@
  3150. * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
  3151. */
  3152. -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
  3153. -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
  3154. +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
  3155. +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
  3156. #include "csumpartialcopygeneric.S"
  3157. diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
  3158. index 5306de3..aed6d03 100644
  3159. --- a/arch/arm/lib/delay.c
  3160. +++ b/arch/arm/lib/delay.c
  3161. @@ -28,7 +28,7 @@
  3162. /*
  3163. * Default to the loop-based delay implementation.
  3164. */
  3165. -struct arm_delay_ops arm_delay_ops = {
  3166. +struct arm_delay_ops arm_delay_ops __read_only = {
  3167. .delay = __loop_delay,
  3168. .const_udelay = __loop_const_udelay,
  3169. .udelay = __loop_udelay,
  3170. diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
  3171. index 3e58d71..029817c 100644
  3172. --- a/arch/arm/lib/uaccess_with_memcpy.c
  3173. +++ b/arch/arm/lib/uaccess_with_memcpy.c
  3174. @@ -136,7 +136,7 @@ out:
  3175. }
  3176. unsigned long
  3177. -__copy_to_user(void __user *to, const void *from, unsigned long n)
  3178. +___copy_to_user(void __user *to, const void *from, unsigned long n)
  3179. {
  3180. /*
  3181. * This test is stubbed out of the main function above to keep
  3182. @@ -190,7 +190,7 @@ out:
  3183. return n;
  3184. }
  3185. -unsigned long __clear_user(void __user *addr, unsigned long n)
  3186. +unsigned long ___clear_user(void __user *addr, unsigned long n)
  3187. {
  3188. /* See rational for this in __copy_to_user() above. */
  3189. if (n < 64)
  3190. diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
  3191. index f7ca97b..3d7e719 100644
  3192. --- a/arch/arm/mach-at91/setup.c
  3193. +++ b/arch/arm/mach-at91/setup.c
  3194. @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
  3195. desc->pfn = __phys_to_pfn(base);
  3196. desc->length = length;
  3197. - desc->type = MT_MEMORY_RWX_NONCACHED;
  3198. + desc->type = MT_MEMORY_RW_NONCACHED;
  3199. pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
  3200. base, length, desc->virtual);
  3201. diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
  3202. index f3407a5..bd4256f 100644
  3203. --- a/arch/arm/mach-kirkwood/common.c
  3204. +++ b/arch/arm/mach-kirkwood/common.c
  3205. @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
  3206. clk_gate_ops.disable(hw);
  3207. }
  3208. -static struct clk_ops clk_gate_fn_ops;
  3209. +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
  3210. +{
  3211. + return clk_gate_ops.is_enabled(hw);
  3212. +}
  3213. +
  3214. +static struct clk_ops clk_gate_fn_ops = {
  3215. + .enable = clk_gate_fn_enable,
  3216. + .disable = clk_gate_fn_disable,
  3217. + .is_enabled = clk_gate_fn_is_enabled,
  3218. +};
  3219. static struct clk __init *clk_register_gate_fn(struct device *dev,
  3220. const char *name,
  3221. @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
  3222. gate_fn->fn_en = fn_en;
  3223. gate_fn->fn_dis = fn_dis;
  3224. - /* ops is the gate ops, but with our enable/disable functions */
  3225. - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
  3226. - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
  3227. - clk_gate_fn_ops = clk_gate_ops;
  3228. - clk_gate_fn_ops.enable = clk_gate_fn_enable;
  3229. - clk_gate_fn_ops.disable = clk_gate_fn_disable;
  3230. - }
  3231. -
  3232. clk = clk_register(dev, &gate_fn->gate.hw);
  3233. if (IS_ERR(clk))
  3234. diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
  3235. index aead77a..a2253fa 100644
  3236. --- a/arch/arm/mach-omap2/board-n8x0.c
  3237. +++ b/arch/arm/mach-omap2/board-n8x0.c
  3238. @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
  3239. }
  3240. #endif
  3241. -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
  3242. +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
  3243. .late_init = n8x0_menelaus_late_init,
  3244. };
  3245. diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
  3246. index ab43755..ccfa231 100644
  3247. --- a/arch/arm/mach-omap2/gpmc.c
  3248. +++ b/arch/arm/mach-omap2/gpmc.c
  3249. @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
  3250. };
  3251. static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
  3252. -static struct irq_chip gpmc_irq_chip;
  3253. static int gpmc_irq_start;
  3254. static struct resource gpmc_mem_root;
  3255. @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
  3256. static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
  3257. +static struct irq_chip gpmc_irq_chip = {
  3258. + .name = "gpmc",
  3259. + .irq_startup = gpmc_irq_noop_ret,
  3260. + .irq_enable = gpmc_irq_enable,
  3261. + .irq_disable = gpmc_irq_disable,
  3262. + .irq_shutdown = gpmc_irq_noop,
  3263. + .irq_ack = gpmc_irq_noop,
  3264. + .irq_mask = gpmc_irq_noop,
  3265. + .irq_unmask = gpmc_irq_noop,
  3266. +
  3267. +};
  3268. +
  3269. static int gpmc_setup_irq(void)
  3270. {
  3271. int i;
  3272. @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
  3273. return gpmc_irq_start;
  3274. }
  3275. - gpmc_irq_chip.name = "gpmc";
  3276. - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
  3277. - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
  3278. - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
  3279. - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
  3280. - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
  3281. - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
  3282. - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
  3283. -
  3284. gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
  3285. gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
  3286. diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
  3287. index 667915d..2ee1219 100644
  3288. --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
  3289. +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
  3290. @@ -84,7 +84,7 @@ struct cpu_pm_ops {
  3291. int (*finish_suspend)(unsigned long cpu_state);
  3292. void (*resume)(void);
  3293. void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
  3294. -};
  3295. +} __no_const;
  3296. static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
  3297. static struct powerdomain *mpuss_pd;
  3298. @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
  3299. static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
  3300. {}
  3301. -struct cpu_pm_ops omap_pm_ops = {
  3302. +static struct cpu_pm_ops omap_pm_ops __read_only = {
  3303. .finish_suspend = default_finish_suspend,
  3304. .resume = dummy_cpu_resume,
  3305. .scu_prepare = dummy_scu_prepare,
  3306. diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
  3307. index 3664562..72f85c6 100644
  3308. --- a/arch/arm/mach-omap2/omap-wakeupgen.c
  3309. +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
  3310. @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
  3311. return NOTIFY_OK;
  3312. }
  3313. -static struct notifier_block __refdata irq_hotplug_notifier = {
  3314. +static struct notifier_block irq_hotplug_notifier = {
  3315. .notifier_call = irq_cpu_hotplug_notify,
  3316. };
  3317. diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
  3318. index 01ef59d..32ae28a8 100644
  3319. --- a/arch/arm/mach-omap2/omap_device.c
  3320. +++ b/arch/arm/mach-omap2/omap_device.c
  3321. @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
  3322. struct platform_device __init *omap_device_build(const char *pdev_name,
  3323. int pdev_id,
  3324. struct omap_hwmod *oh,
  3325. - void *pdata, int pdata_len)
  3326. + const void *pdata, int pdata_len)
  3327. {
  3328. struct omap_hwmod *ohs[] = { oh };
  3329. @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
  3330. struct platform_device __init *omap_device_build_ss(const char *pdev_name,
  3331. int pdev_id,
  3332. struct omap_hwmod **ohs,
  3333. - int oh_cnt, void *pdata,
  3334. + int oh_cnt, const void *pdata,
  3335. int pdata_len)
  3336. {
  3337. int ret = -ENOMEM;
  3338. diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
  3339. index 78c02b3..c94109a 100644
  3340. --- a/arch/arm/mach-omap2/omap_device.h
  3341. +++ b/arch/arm/mach-omap2/omap_device.h
  3342. @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
  3343. /* Core code interface */
  3344. struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
  3345. - struct omap_hwmod *oh, void *pdata,
  3346. + struct omap_hwmod *oh, const void *pdata,
  3347. int pdata_len);
  3348. struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
  3349. struct omap_hwmod **oh, int oh_cnt,
  3350. - void *pdata, int pdata_len);
  3351. + const void *pdata, int pdata_len);
  3352. struct omap_device *omap_device_alloc(struct platform_device *pdev,
  3353. struct omap_hwmod **ohs, int oh_cnt);
  3354. diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
  3355. index 66c60fe..c78950d 100644
  3356. --- a/arch/arm/mach-omap2/omap_hwmod.c
  3357. +++ b/arch/arm/mach-omap2/omap_hwmod.c
  3358. @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
  3359. int (*init_clkdm)(struct omap_hwmod *oh);
  3360. void (*update_context_lost)(struct omap_hwmod *oh);
  3361. int (*get_context_lost)(struct omap_hwmod *oh);
  3362. -};
  3363. +} __no_const;
  3364. /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
  3365. -static struct omap_hwmod_soc_ops soc_ops;
  3366. +static struct omap_hwmod_soc_ops soc_ops __read_only;
  3367. /* omap_hwmod_list contains all registered struct omap_hwmods */
  3368. static LIST_HEAD(omap_hwmod_list);
  3369. diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
  3370. index 95fee54..cfa9cf1 100644
  3371. --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
  3372. +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
  3373. @@ -10,6 +10,7 @@
  3374. #include <linux/kernel.h>
  3375. #include <linux/init.h>
  3376. +#include <asm/pgtable.h>
  3377. #include "powerdomain.h"
  3378. @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
  3379. void __init am43xx_powerdomains_init(void)
  3380. {
  3381. - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
  3382. + pax_open_kernel();
  3383. + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
  3384. + pax_close_kernel();
  3385. pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
  3386. pwrdm_register_pwrdms(powerdomains_am43xx);
  3387. pwrdm_complete_init();
  3388. diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
  3389. index d15c7bb..b2d1f0c 100644
  3390. --- a/arch/arm/mach-omap2/wd_timer.c
  3391. +++ b/arch/arm/mach-omap2/wd_timer.c
  3392. @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
  3393. struct omap_hwmod *oh;
  3394. char *oh_name = "wd_timer2";
  3395. char *dev_name = "omap_wdt";
  3396. - struct omap_wd_timer_platform_data pdata;
  3397. + static struct omap_wd_timer_platform_data pdata = {
  3398. + .read_reset_sources = prm_read_reset_sources
  3399. + };
  3400. if (!cpu_class_is_omap2() || of_have_populated_dt())
  3401. return 0;
  3402. @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
  3403. return -EINVAL;
  3404. }
  3405. - pdata.read_reset_sources = prm_read_reset_sources;
  3406. -
  3407. pdev = omap_device_build(dev_name, id, oh, &pdata,
  3408. sizeof(struct omap_wd_timer_platform_data));
  3409. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
  3410. diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
  3411. index b82dcae..44ee5b6 100644
  3412. --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
  3413. +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
  3414. @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
  3415. bool entered_lp2 = false;
  3416. if (tegra_pending_sgi())
  3417. - ACCESS_ONCE(abort_flag) = true;
  3418. + ACCESS_ONCE_RW(abort_flag) = true;
  3419. cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
  3420. diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
  3421. index 2dea8b5..6499da2 100644
  3422. --- a/arch/arm/mach-ux500/setup.h
  3423. +++ b/arch/arm/mach-ux500/setup.h
  3424. @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
  3425. .type = MT_DEVICE, \
  3426. }
  3427. -#define __MEM_DEV_DESC(x, sz) { \
  3428. - .virtual = IO_ADDRESS(x), \
  3429. - .pfn = __phys_to_pfn(x), \
  3430. - .length = sz, \
  3431. - .type = MT_MEMORY_RWX, \
  3432. -}
  3433. -
  3434. extern struct smp_operations ux500_smp_ops;
  3435. extern void ux500_cpu_die(unsigned int cpu);
  3436. diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
  3437. index ca8ecde..58ba893 100644
  3438. --- a/arch/arm/mm/Kconfig
  3439. +++ b/arch/arm/mm/Kconfig
  3440. @@ -446,6 +446,7 @@ config CPU_32v5
  3441. config CPU_32v6
  3442. bool
  3443. + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
  3444. select TLS_REG_EMUL if !CPU_32v6K && !MMU
  3445. config CPU_32v6K
  3446. @@ -600,6 +601,7 @@ config CPU_CP15_MPU
  3447. config CPU_USE_DOMAINS
  3448. bool
  3449. + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
  3450. help
  3451. This option enables or disables the use of domain switching
  3452. via the set_fs() function.
  3453. @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
  3454. config KUSER_HELPERS
  3455. bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
  3456. default y
  3457. + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
  3458. help
  3459. Warning: disabling this option may break user programs.
  3460. @@ -811,7 +814,7 @@ config KUSER_HELPERS
  3461. See Documentation/arm/kernel_user_helpers.txt for details.
  3462. However, the fixed address nature of these helpers can be used
  3463. - by ROP (return orientated programming) authors when creating
  3464. + by ROP (Return Oriented Programming) authors when creating
  3465. exploits.
  3466. If all of the binaries and libraries which run on your platform
  3467. diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
  3468. index 9240364..a2b8cf3 100644
  3469. --- a/arch/arm/mm/alignment.c
  3470. +++ b/arch/arm/mm/alignment.c
  3471. @@ -212,10 +212,12 @@ union offset_union {
  3472. #define __get16_unaligned_check(ins,val,addr) \
  3473. do { \
  3474. unsigned int err = 0, v, a = addr; \
  3475. + pax_open_userland(); \
  3476. __get8_unaligned_check(ins,v,a,err); \
  3477. val = v << ((BE) ? 8 : 0); \
  3478. __get8_unaligned_check(ins,v,a,err); \
  3479. val |= v << ((BE) ? 0 : 8); \
  3480. + pax_close_userland(); \
  3481. if (err) \
  3482. goto fault; \
  3483. } while (0)
  3484. @@ -229,6 +231,7 @@ union offset_union {
  3485. #define __get32_unaligned_check(ins,val,addr) \
  3486. do { \
  3487. unsigned int err = 0, v, a = addr; \
  3488. + pax_open_userland(); \
  3489. __get8_unaligned_check(ins,v,a,err); \
  3490. val = v << ((BE) ? 24 : 0); \
  3491. __get8_unaligned_check(ins,v,a,err); \
  3492. @@ -237,6 +240,7 @@ union offset_union {
  3493. val |= v << ((BE) ? 8 : 16); \
  3494. __get8_unaligned_check(ins,v,a,err); \
  3495. val |= v << ((BE) ? 0 : 24); \
  3496. + pax_close_userland(); \
  3497. if (err) \
  3498. goto fault; \
  3499. } while (0)
  3500. @@ -250,6 +254,7 @@ union offset_union {
  3501. #define __put16_unaligned_check(ins,val,addr) \
  3502. do { \
  3503. unsigned int err = 0, v = val, a = addr; \
  3504. + pax_open_userland(); \
  3505. __asm__( FIRST_BYTE_16 \
  3506. ARM( "1: "ins" %1, [%2], #1\n" ) \
  3507. THUMB( "1: "ins" %1, [%2]\n" ) \
  3508. @@ -269,6 +274,7 @@ union offset_union {
  3509. " .popsection\n" \
  3510. : "=r" (err), "=&r" (v), "=&r" (a) \
  3511. : "0" (err), "1" (v), "2" (a)); \
  3512. + pax_close_userland(); \
  3513. if (err) \
  3514. goto fault; \
  3515. } while (0)
  3516. @@ -282,6 +288,7 @@ union offset_union {
  3517. #define __put32_unaligned_check(ins,val,addr) \
  3518. do { \
  3519. unsigned int err = 0, v = val, a = addr; \
  3520. + pax_open_userland(); \
  3521. __asm__( FIRST_BYTE_32 \
  3522. ARM( "1: "ins" %1, [%2], #1\n" ) \
  3523. THUMB( "1: "ins" %1, [%2]\n" ) \
  3524. @@ -311,6 +318,7 @@ union offset_union {
  3525. " .popsection\n" \
  3526. : "=r" (err), "=&r" (v), "=&r" (a) \
  3527. : "0" (err), "1" (v), "2" (a)); \
  3528. + pax_close_userland(); \
  3529. if (err) \
  3530. goto fault; \
  3531. } while (0)
  3532. diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
  3533. index 7abde2c..9df495f 100644
  3534. --- a/arch/arm/mm/cache-l2x0.c
  3535. +++ b/arch/arm/mm/cache-l2x0.c
  3536. @@ -46,7 +46,7 @@ struct l2x0_of_data {
  3537. void (*setup)(const struct device_node *, u32 *, u32 *);
  3538. void (*save)(void);
  3539. struct outer_cache_fns outer_cache;
  3540. -};
  3541. +} __do_const;
  3542. static bool of_init = false;
  3543. diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
  3544. index 6eb97b3..ac509f6 100644
  3545. --- a/arch/arm/mm/context.c
  3546. +++ b/arch/arm/mm/context.c
  3547. @@ -43,7 +43,7 @@
  3548. #define NUM_USER_ASIDS ASID_FIRST_VERSION
  3549. static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
  3550. -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
  3551. +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
  3552. static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
  3553. static DEFINE_PER_CPU(atomic64_t, active_asids);
  3554. @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
  3555. {
  3556. static u32 cur_idx = 1;
  3557. u64 asid = atomic64_read(&mm->context.id);
  3558. - u64 generation = atomic64_read(&asid_generation);
  3559. + u64 generation = atomic64_read_unchecked(&asid_generation);
  3560. if (asid != 0 && is_reserved_asid(asid)) {
  3561. /*
  3562. @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
  3563. */
  3564. asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
  3565. if (asid == NUM_USER_ASIDS) {
  3566. - generation = atomic64_add_return(ASID_FIRST_VERSION,
  3567. + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
  3568. &asid_generation);
  3569. flush_context(cpu);
  3570. asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
  3571. @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
  3572. cpu_set_reserved_ttbr0();
  3573. asid = atomic64_read(&mm->context.id);
  3574. - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
  3575. + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
  3576. && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
  3577. goto switch_mm_fastpath;
  3578. raw_spin_lock_irqsave(&cpu_asid_lock, flags);
  3579. /* Check that our ASID belongs to the current generation. */
  3580. asid = atomic64_read(&mm->context.id);
  3581. - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
  3582. + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
  3583. asid = new_context(mm, cpu);
  3584. atomic64_set(&mm->context.id, asid);
  3585. }
  3586. diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
  3587. index eb8830a..5360ce7 100644
  3588. --- a/arch/arm/mm/fault.c
  3589. +++ b/arch/arm/mm/fault.c
  3590. @@ -25,6 +25,7 @@
  3591. #include <asm/system_misc.h>
  3592. #include <asm/system_info.h>
  3593. #include <asm/tlbflush.h>
  3594. +#include <asm/sections.h>
  3595. #include "fault.h"
  3596. @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
  3597. if (fixup_exception(regs))
  3598. return;
  3599. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  3600. + if (addr < TASK_SIZE) {
  3601. + if (current->signal->curr_ip)
  3602. + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
  3603. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
  3604. + else
  3605. + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
  3606. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
  3607. + }
  3608. +#endif
  3609. +
  3610. +#ifdef CONFIG_PAX_KERNEXEC
  3611. + if ((fsr & FSR_WRITE) &&
  3612. + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
  3613. + (MODULES_VADDR <= addr && addr < MODULES_END)))
  3614. + {
  3615. + if (current->signal->curr_ip)
  3616. + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
  3617. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
  3618. + else
  3619. + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
  3620. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
  3621. + }
  3622. +#endif
  3623. +
  3624. /*
  3625. * No handler, we'll have to terminate things with extreme prejudice.
  3626. */
  3627. @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
  3628. }
  3629. #endif
  3630. +#ifdef CONFIG_PAX_PAGEEXEC
  3631. + if (fsr & FSR_LNX_PF) {
  3632. + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
  3633. + do_group_exit(SIGKILL);
  3634. + }
  3635. +#endif
  3636. +
  3637. tsk->thread.address = addr;
  3638. tsk->thread.error_code = fsr;
  3639. tsk->thread.trap_no = 14;
  3640. @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  3641. }
  3642. #endif /* CONFIG_MMU */
  3643. +#ifdef CONFIG_PAX_PAGEEXEC
  3644. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  3645. +{
  3646. + long i;
  3647. +
  3648. + printk(KERN_ERR "PAX: bytes at PC: ");
  3649. + for (i = 0; i < 20; i++) {
  3650. + unsigned char c;
  3651. + if (get_user(c, (__force unsigned char __user *)pc+i))
  3652. + printk(KERN_CONT "?? ");
  3653. + else
  3654. + printk(KERN_CONT "%02x ", c);
  3655. + }
  3656. + printk("\n");
  3657. +
  3658. + printk(KERN_ERR "PAX: bytes at SP-4: ");
  3659. + for (i = -1; i < 20; i++) {
  3660. + unsigned long c;
  3661. + if (get_user(c, (__force unsigned long __user *)sp+i))
  3662. + printk(KERN_CONT "???????? ");
  3663. + else
  3664. + printk(KERN_CONT "%08lx ", c);
  3665. + }
  3666. + printk("\n");
  3667. +}
  3668. +#endif
  3669. +
  3670. /*
  3671. * First Level Translation Fault Handler
  3672. *
  3673. @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  3674. const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
  3675. struct siginfo info;
  3676. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  3677. + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
  3678. + if (current->signal->curr_ip)
  3679. + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
  3680. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
  3681. + else
  3682. + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
  3683. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
  3684. + goto die;
  3685. + }
  3686. +#endif
  3687. +
  3688. if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
  3689. return;
  3690. +die:
  3691. printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
  3692. inf->name, fsr, addr);
  3693. @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
  3694. ifsr_info[nr].name = name;
  3695. }
  3696. +asmlinkage int sys_sigreturn(struct pt_regs *regs);
  3697. +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
  3698. +
  3699. asmlinkage void __exception
  3700. do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
  3701. {
  3702. const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
  3703. struct siginfo info;
  3704. + unsigned long pc = instruction_pointer(regs);
  3705. +
  3706. + if (user_mode(regs)) {
  3707. + unsigned long sigpage = current->mm->context.sigpage;
  3708. +
  3709. + if (sigpage <= pc && pc < sigpage + 7*4) {
  3710. + if (pc < sigpage + 3*4)
  3711. + sys_sigreturn(regs);
  3712. + else
  3713. + sys_rt_sigreturn(regs);
  3714. + return;
  3715. + }
  3716. + if (pc == 0xffff0f60UL) {
  3717. + /*
  3718. + * PaX: __kuser_cmpxchg64 emulation
  3719. + */
  3720. + // TODO
  3721. + //regs->ARM_pc = regs->ARM_lr;
  3722. + //return;
  3723. + }
  3724. + if (pc == 0xffff0fa0UL) {
  3725. + /*
  3726. + * PaX: __kuser_memory_barrier emulation
  3727. + */
  3728. + // dmb(); implied by the exception
  3729. + regs->ARM_pc = regs->ARM_lr;
  3730. + return;
  3731. + }
  3732. + if (pc == 0xffff0fc0UL) {
  3733. + /*
  3734. + * PaX: __kuser_cmpxchg emulation
  3735. + */
  3736. + // TODO
  3737. + //long new;
  3738. + //int op;
  3739. +
  3740. + //op = FUTEX_OP_SET << 28;
  3741. + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
  3742. + //regs->ARM_r0 = old != new;
  3743. + //regs->ARM_pc = regs->ARM_lr;
  3744. + //return;
  3745. + }
  3746. + if (pc == 0xffff0fe0UL) {
  3747. + /*
  3748. + * PaX: __kuser_get_tls emulation
  3749. + */
  3750. + regs->ARM_r0 = current_thread_info()->tp_value[0];
  3751. + regs->ARM_pc = regs->ARM_lr;
  3752. + return;
  3753. + }
  3754. + }
  3755. +
  3756. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  3757. + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
  3758. + if (current->signal->curr_ip)
  3759. + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
  3760. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
  3761. + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
  3762. + else
  3763. + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
  3764. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
  3765. + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
  3766. + goto die;
  3767. + }
  3768. +#endif
  3769. +
  3770. +#ifdef CONFIG_PAX_REFCOUNT
  3771. + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
  3772. + unsigned int bkpt;
  3773. +
  3774. + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
  3775. + current->thread.error_code = ifsr;
  3776. + current->thread.trap_no = 0;
  3777. + pax_report_refcount_overflow(regs);
  3778. + fixup_exception(regs);
  3779. + return;
  3780. + }
  3781. + }
  3782. +#endif
  3783. if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
  3784. return;
  3785. +die:
  3786. printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
  3787. inf->name, ifsr, addr);
  3788. diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
  3789. index cf08bdf..772656c 100644
  3790. --- a/arch/arm/mm/fault.h
  3791. +++ b/arch/arm/mm/fault.h
  3792. @@ -3,6 +3,7 @@
  3793. /*
  3794. * Fault status register encodings. We steal bit 31 for our own purposes.
  3795. + * Set when the FSR value is from an instruction fault.
  3796. */
  3797. #define FSR_LNX_PF (1 << 31)
  3798. #define FSR_WRITE (1 << 11)
  3799. @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
  3800. }
  3801. #endif
  3802. +/* valid for LPAE and !LPAE */
  3803. +static inline int is_xn_fault(unsigned int fsr)
  3804. +{
  3805. + return ((fsr_fs(fsr) & 0x3c) == 0xc);
  3806. +}
  3807. +
  3808. +static inline int is_domain_fault(unsigned int fsr)
  3809. +{
  3810. + return ((fsr_fs(fsr) & 0xD) == 0x9);
  3811. +}
  3812. +
  3813. void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
  3814. unsigned long search_exception_table(unsigned long addr);
  3815. diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
  3816. index 804d615..fcec50a 100644
  3817. --- a/arch/arm/mm/init.c
  3818. +++ b/arch/arm/mm/init.c
  3819. @@ -30,6 +30,8 @@
  3820. #include <asm/setup.h>
  3821. #include <asm/tlb.h>
  3822. #include <asm/fixmap.h>
  3823. +#include <asm/system_info.h>
  3824. +#include <asm/cp15.h>
  3825. #include <asm/mach/arch.h>
  3826. #include <asm/mach/map.h>
  3827. @@ -625,7 +627,46 @@ void free_initmem(void)
  3828. {
  3829. #ifdef CONFIG_HAVE_TCM
  3830. extern char __tcm_start, __tcm_end;
  3831. +#endif
  3832. +#ifdef CONFIG_PAX_KERNEXEC
  3833. + unsigned long addr;
  3834. + pgd_t *pgd;
  3835. + pud_t *pud;
  3836. + pmd_t *pmd;
  3837. + int cpu_arch = cpu_architecture();
  3838. + unsigned int cr = get_cr();
  3839. +
  3840. + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  3841. + /* make pages tables, etc before .text NX */
  3842. + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
  3843. + pgd = pgd_offset_k(addr);
  3844. + pud = pud_offset(pgd, addr);
  3845. + pmd = pmd_offset(pud, addr);
  3846. + __section_update(pmd, addr, PMD_SECT_XN);
  3847. + }
  3848. + /* make init NX */
  3849. + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
  3850. + pgd = pgd_offset_k(addr);
  3851. + pud = pud_offset(pgd, addr);
  3852. + pmd = pmd_offset(pud, addr);
  3853. + __section_update(pmd, addr, PMD_SECT_XN);
  3854. + }
  3855. + /* make kernel code/rodata RX */
  3856. + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
  3857. + pgd = pgd_offset_k(addr);
  3858. + pud = pud_offset(pgd, addr);
  3859. + pmd = pmd_offset(pud, addr);
  3860. +#ifdef CONFIG_ARM_LPAE
  3861. + __section_update(pmd, addr, PMD_SECT_RDONLY);
  3862. +#else
  3863. + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
  3864. +#endif
  3865. + }
  3866. + }
  3867. +#endif
  3868. +
  3869. +#ifdef CONFIG_HAVE_TCM
  3870. poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
  3871. free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
  3872. #endif
  3873. diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
  3874. index f9c32ba..8540068 100644
  3875. --- a/arch/arm/mm/ioremap.c
  3876. +++ b/arch/arm/mm/ioremap.c
  3877. @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
  3878. unsigned int mtype;
  3879. if (cached)
  3880. - mtype = MT_MEMORY_RWX;
  3881. + mtype = MT_MEMORY_RX;
  3882. else
  3883. - mtype = MT_MEMORY_RWX_NONCACHED;
  3884. + mtype = MT_MEMORY_RX_NONCACHED;
  3885. return __arm_ioremap_caller(phys_addr, size, mtype,
  3886. __builtin_return_address(0));
  3887. diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
  3888. index 5e85ed3..b10a7ed 100644
  3889. --- a/arch/arm/mm/mmap.c
  3890. +++ b/arch/arm/mm/mmap.c
  3891. @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  3892. struct vm_area_struct *vma;
  3893. int do_align = 0;
  3894. int aliasing = cache_is_vipt_aliasing();
  3895. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  3896. struct vm_unmapped_area_info info;
  3897. /*
  3898. @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  3899. if (len > TASK_SIZE)
  3900. return -ENOMEM;
  3901. +#ifdef CONFIG_PAX_RANDMMAP
  3902. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  3903. +#endif
  3904. +
  3905. if (addr) {
  3906. if (do_align)
  3907. addr = COLOUR_ALIGN(addr, pgoff);
  3908. @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  3909. addr = PAGE_ALIGN(addr);
  3910. vma = find_vma(mm, addr);
  3911. - if (TASK_SIZE - len >= addr &&
  3912. - (!vma || addr + len <= vma->vm_start))
  3913. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  3914. return addr;
  3915. }
  3916. @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  3917. info.high_limit = TASK_SIZE;
  3918. info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  3919. info.align_offset = pgoff << PAGE_SHIFT;
  3920. + info.threadstack_offset = offset;
  3921. return vm_unmapped_area(&info);
  3922. }
  3923. @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  3924. unsigned long addr = addr0;
  3925. int do_align = 0;
  3926. int aliasing = cache_is_vipt_aliasing();
  3927. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  3928. struct vm_unmapped_area_info info;
  3929. /*
  3930. @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  3931. return addr;
  3932. }
  3933. +#ifdef CONFIG_PAX_RANDMMAP
  3934. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  3935. +#endif
  3936. +
  3937. /* requesting a specific address */
  3938. if (addr) {
  3939. if (do_align)
  3940. @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  3941. else
  3942. addr = PAGE_ALIGN(addr);
  3943. vma = find_vma(mm, addr);
  3944. - if (TASK_SIZE - len >= addr &&
  3945. - (!vma || addr + len <= vma->vm_start))
  3946. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  3947. return addr;
  3948. }
  3949. @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  3950. info.high_limit = mm->mmap_base;
  3951. info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  3952. info.align_offset = pgoff << PAGE_SHIFT;
  3953. + info.threadstack_offset = offset;
  3954. addr = vm_unmapped_area(&info);
  3955. /*
  3956. @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  3957. {
  3958. unsigned long random_factor = 0UL;
  3959. +#ifdef CONFIG_PAX_RANDMMAP
  3960. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  3961. +#endif
  3962. +
  3963. /* 8 bits of randomness in 20 address space bits */
  3964. if ((current->flags & PF_RANDOMIZE) &&
  3965. !(current->personality & ADDR_NO_RANDOMIZE))
  3966. @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  3967. if (mmap_is_legacy()) {
  3968. mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
  3969. +
  3970. +#ifdef CONFIG_PAX_RANDMMAP
  3971. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  3972. + mm->mmap_base += mm->delta_mmap;
  3973. +#endif
  3974. +
  3975. mm->get_unmapped_area = arch_get_unmapped_area;
  3976. } else {
  3977. mm->mmap_base = mmap_base(random_factor);
  3978. +
  3979. +#ifdef CONFIG_PAX_RANDMMAP
  3980. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  3981. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  3982. +#endif
  3983. +
  3984. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  3985. }
  3986. }
  3987. diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
  3988. index b68c6b2..f66c492 100644
  3989. --- a/arch/arm/mm/mmu.c
  3990. +++ b/arch/arm/mm/mmu.c
  3991. @@ -39,6 +39,22 @@
  3992. #include "mm.h"
  3993. #include "tcm.h"
  3994. +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  3995. +void modify_domain(unsigned int dom, unsigned int type)
  3996. +{
  3997. + struct thread_info *thread = current_thread_info();
  3998. + unsigned int domain = thread->cpu_domain;
  3999. + /*
  4000. + * DOMAIN_MANAGER might be defined to some other value,
  4001. + * use the arch-defined constant
  4002. + */
  4003. + domain &= ~domain_val(dom, 3);
  4004. + thread->cpu_domain = domain | domain_val(dom, type);
  4005. + set_domain(thread->cpu_domain);
  4006. +}
  4007. +EXPORT_SYMBOL(modify_domain);
  4008. +#endif
  4009. +
  4010. /*
  4011. * empty_zero_page is a special page that is used for
  4012. * zero-initialized data and COW.
  4013. @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
  4014. #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
  4015. #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
  4016. -static struct mem_type mem_types[] = {
  4017. +#ifdef CONFIG_PAX_KERNEXEC
  4018. +#define L_PTE_KERNEXEC L_PTE_RDONLY
  4019. +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
  4020. +#else
  4021. +#define L_PTE_KERNEXEC L_PTE_DIRTY
  4022. +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
  4023. +#endif
  4024. +
  4025. +static struct mem_type mem_types[] __read_only = {
  4026. [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
  4027. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
  4028. L_PTE_SHARED,
  4029. @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
  4030. .prot_sect = PROT_SECT_DEVICE,
  4031. .domain = DOMAIN_IO,
  4032. },
  4033. - [MT_UNCACHED] = {
  4034. + [MT_UNCACHED_RW] = {
  4035. .prot_pte = PROT_PTE_DEVICE,
  4036. .prot_l1 = PMD_TYPE_TABLE,
  4037. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  4038. .domain = DOMAIN_IO,
  4039. },
  4040. - [MT_CACHECLEAN] = {
  4041. - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  4042. + [MT_CACHECLEAN_RO] = {
  4043. + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
  4044. .domain = DOMAIN_KERNEL,
  4045. },
  4046. #ifndef CONFIG_ARM_LPAE
  4047. - [MT_MINICLEAN] = {
  4048. - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
  4049. + [MT_MINICLEAN_RO] = {
  4050. + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
  4051. .domain = DOMAIN_KERNEL,
  4052. },
  4053. #endif
  4054. @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
  4055. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  4056. L_PTE_RDONLY,
  4057. .prot_l1 = PMD_TYPE_TABLE,
  4058. - .domain = DOMAIN_USER,
  4059. + .domain = DOMAIN_VECTORS,
  4060. },
  4061. [MT_HIGH_VECTORS] = {
  4062. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  4063. L_PTE_USER | L_PTE_RDONLY,
  4064. .prot_l1 = PMD_TYPE_TABLE,
  4065. - .domain = DOMAIN_USER,
  4066. + .domain = DOMAIN_VECTORS,
  4067. },
  4068. - [MT_MEMORY_RWX] = {
  4069. + [__MT_MEMORY_RWX] = {
  4070. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  4071. .prot_l1 = PMD_TYPE_TABLE,
  4072. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  4073. @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
  4074. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  4075. .domain = DOMAIN_KERNEL,
  4076. },
  4077. - [MT_ROM] = {
  4078. - .prot_sect = PMD_TYPE_SECT,
  4079. + [MT_MEMORY_RX] = {
  4080. + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
  4081. + .prot_l1 = PMD_TYPE_TABLE,
  4082. + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
  4083. + .domain = DOMAIN_KERNEL,
  4084. + },
  4085. + [MT_ROM_RX] = {
  4086. + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
  4087. .domain = DOMAIN_KERNEL,
  4088. },
  4089. - [MT_MEMORY_RWX_NONCACHED] = {
  4090. + [MT_MEMORY_RW_NONCACHED] = {
  4091. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  4092. L_PTE_MT_BUFFERABLE,
  4093. .prot_l1 = PMD_TYPE_TABLE,
  4094. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  4095. .domain = DOMAIN_KERNEL,
  4096. },
  4097. + [MT_MEMORY_RX_NONCACHED] = {
  4098. + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
  4099. + L_PTE_MT_BUFFERABLE,
  4100. + .prot_l1 = PMD_TYPE_TABLE,
  4101. + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
  4102. + .domain = DOMAIN_KERNEL,
  4103. + },
  4104. [MT_MEMORY_RW_DTCM] = {
  4105. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  4106. L_PTE_XN,
  4107. @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
  4108. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  4109. .domain = DOMAIN_KERNEL,
  4110. },
  4111. - [MT_MEMORY_RWX_ITCM] = {
  4112. - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  4113. + [MT_MEMORY_RX_ITCM] = {
  4114. + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
  4115. .prot_l1 = PMD_TYPE_TABLE,
  4116. + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
  4117. .domain = DOMAIN_KERNEL,
  4118. },
  4119. [MT_MEMORY_RW_SO] = {
  4120. @@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
  4121. * Mark cache clean areas and XIP ROM read only
  4122. * from SVC mode and no access from userspace.
  4123. */
  4124. - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4125. - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4126. - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4127. + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4128. +#ifdef CONFIG_PAX_KERNEXEC
  4129. + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4130. + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4131. + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4132. +#endif
  4133. + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4134. + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  4135. #endif
  4136. if (is_smp()) {
  4137. @@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
  4138. mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
  4139. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
  4140. mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
  4141. - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
  4142. - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
  4143. + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
  4144. + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
  4145. mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
  4146. mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
  4147. + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
  4148. + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
  4149. mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
  4150. - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
  4151. - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
  4152. + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
  4153. + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
  4154. + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
  4155. + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
  4156. }
  4157. }
  4158. @@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
  4159. if (cpu_arch >= CPU_ARCH_ARMv6) {
  4160. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  4161. /* Non-cacheable Normal is XCB = 001 */
  4162. - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
  4163. + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
  4164. + PMD_SECT_BUFFERED;
  4165. + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
  4166. PMD_SECT_BUFFERED;
  4167. } else {
  4168. /* For both ARMv6 and non-TEX-remapping ARMv7 */
  4169. - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
  4170. + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
  4171. + PMD_SECT_TEX(1);
  4172. + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
  4173. PMD_SECT_TEX(1);
  4174. }
  4175. } else {
  4176. - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
  4177. + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
  4178. + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
  4179. }
  4180. #ifdef CONFIG_ARM_LPAE
  4181. @@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
  4182. vecs_pgprot |= PTE_EXT_AF;
  4183. #endif
  4184. + user_pgprot |= __supported_pte_mask;
  4185. +
  4186. for (i = 0; i < 16; i++) {
  4187. pteval_t v = pgprot_val(protection_map[i]);
  4188. protection_map[i] = __pgprot(v | user_pgprot);
  4189. @@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
  4190. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  4191. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  4192. - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
  4193. - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
  4194. + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
  4195. + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
  4196. mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
  4197. mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
  4198. + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
  4199. + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
  4200. mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
  4201. - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
  4202. - mem_types[MT_ROM].prot_sect |= cp->pmd;
  4203. + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
  4204. + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
  4205. + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
  4206. switch (cp->pmd) {
  4207. case PMD_SECT_WT:
  4208. - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  4209. + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
  4210. break;
  4211. case PMD_SECT_WB:
  4212. case PMD_SECT_WBWA:
  4213. - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  4214. + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
  4215. break;
  4216. }
  4217. pr_info("Memory policy: %sData cache %s\n",
  4218. @@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
  4219. return;
  4220. }
  4221. - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  4222. + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
  4223. md->virtual >= PAGE_OFFSET &&
  4224. (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
  4225. printk(KERN_WARNING "BUG: mapping for 0x%08llx"
  4226. @@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
  4227. * called function. This means you can't use any function or debugging
  4228. * method which may touch any device, otherwise the kernel _will_ crash.
  4229. */
  4230. +
  4231. +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
  4232. +
  4233. static void __init devicemaps_init(const struct machine_desc *mdesc)
  4234. {
  4235. struct map_desc map;
  4236. unsigned long addr;
  4237. - void *vectors;
  4238. - /*
  4239. - * Allocate the vector page early.
  4240. - */
  4241. - vectors = early_alloc(PAGE_SIZE * 2);
  4242. -
  4243. - early_trap_init(vectors);
  4244. + early_trap_init(&vectors);
  4245. for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
  4246. pmd_clear(pmd_off_k(addr));
  4247. @@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
  4248. map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
  4249. map.virtual = MODULES_VADDR;
  4250. map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
  4251. - map.type = MT_ROM;
  4252. + map.type = MT_ROM_RX;
  4253. create_mapping(&map);
  4254. #endif
  4255. @@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
  4256. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
  4257. map.virtual = FLUSH_BASE;
  4258. map.length = SZ_1M;
  4259. - map.type = MT_CACHECLEAN;
  4260. + map.type = MT_CACHECLEAN_RO;
  4261. create_mapping(&map);
  4262. #endif
  4263. #ifdef FLUSH_BASE_MINICACHE
  4264. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
  4265. map.virtual = FLUSH_BASE_MINICACHE;
  4266. map.length = SZ_1M;
  4267. - map.type = MT_MINICLEAN;
  4268. + map.type = MT_MINICLEAN_RO;
  4269. create_mapping(&map);
  4270. #endif
  4271. @@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
  4272. * location (0xffff0000). If we aren't using high-vectors, also
  4273. * create a mapping at the low-vectors virtual address.
  4274. */
  4275. - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
  4276. + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
  4277. map.virtual = 0xffff0000;
  4278. map.length = PAGE_SIZE;
  4279. #ifdef CONFIG_KUSER_HELPERS
  4280. @@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
  4281. static void __init map_lowmem(void)
  4282. {
  4283. struct memblock_region *reg;
  4284. +#ifndef CONFIG_PAX_KERNEXEC
  4285. unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
  4286. unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
  4287. +#endif
  4288. /* Map all the lowmem memory banks. */
  4289. for_each_memblock(memory, reg) {
  4290. @@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
  4291. if (start >= end)
  4292. break;
  4293. +#ifdef CONFIG_PAX_KERNEXEC
  4294. + map.pfn = __phys_to_pfn(start);
  4295. + map.virtual = __phys_to_virt(start);
  4296. + map.length = end - start;
  4297. +
  4298. + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
  4299. + struct map_desc kernel;
  4300. + struct map_desc initmap;
  4301. +
  4302. + /* when freeing initmem we will make this RW */
  4303. + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
  4304. + initmap.virtual = (unsigned long)__init_begin;
  4305. + initmap.length = _sdata - __init_begin;
  4306. + initmap.type = __MT_MEMORY_RWX;
  4307. + create_mapping(&initmap);
  4308. +
  4309. + /* when freeing initmem we will make this RX */
  4310. + kernel.pfn = __phys_to_pfn(__pa(_stext));
  4311. + kernel.virtual = (unsigned long)_stext;
  4312. + kernel.length = __init_begin - _stext;
  4313. + kernel.type = __MT_MEMORY_RWX;
  4314. + create_mapping(&kernel);
  4315. +
  4316. + if (map.virtual < (unsigned long)_stext) {
  4317. + map.length = (unsigned long)_stext - map.virtual;
  4318. + map.type = __MT_MEMORY_RWX;
  4319. + create_mapping(&map);
  4320. + }
  4321. +
  4322. + map.pfn = __phys_to_pfn(__pa(_sdata));
  4323. + map.virtual = (unsigned long)_sdata;
  4324. + map.length = end - __pa(_sdata);
  4325. + }
  4326. +
  4327. + map.type = MT_MEMORY_RW;
  4328. + create_mapping(&map);
  4329. +#else
  4330. if (end < kernel_x_start || start >= kernel_x_end) {
  4331. map.pfn = __phys_to_pfn(start);
  4332. map.virtual = __phys_to_virt(start);
  4333. map.length = end - start;
  4334. - map.type = MT_MEMORY_RWX;
  4335. + map.type = __MT_MEMORY_RWX;
  4336. create_mapping(&map);
  4337. } else {
  4338. @@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
  4339. map.pfn = __phys_to_pfn(kernel_x_start);
  4340. map.virtual = __phys_to_virt(kernel_x_start);
  4341. map.length = kernel_x_end - kernel_x_start;
  4342. - map.type = MT_MEMORY_RWX;
  4343. + map.type = __MT_MEMORY_RWX;
  4344. create_mapping(&map);
  4345. @@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
  4346. create_mapping(&map);
  4347. }
  4348. }
  4349. +#endif
  4350. }
  4351. }
  4352. diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
  4353. index 5b217f4..c23f40e 100644
  4354. --- a/arch/arm/plat-iop/setup.c
  4355. +++ b/arch/arm/plat-iop/setup.c
  4356. @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
  4357. .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
  4358. .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
  4359. .length = IOP3XX_PERIPHERAL_SIZE,
  4360. - .type = MT_UNCACHED,
  4361. + .type = MT_UNCACHED_RW,
  4362. },
  4363. };
  4364. diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
  4365. index a5bc92d..0bb4730 100644
  4366. --- a/arch/arm/plat-omap/sram.c
  4367. +++ b/arch/arm/plat-omap/sram.c
  4368. @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
  4369. * Looks like we need to preserve some bootloader code at the
  4370. * beginning of SRAM for jumping to flash for reboot to work...
  4371. */
  4372. + pax_open_kernel();
  4373. memset_io(omap_sram_base + omap_sram_skip, 0,
  4374. omap_sram_size - omap_sram_skip);
  4375. + pax_close_kernel();
  4376. }
  4377. diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
  4378. index ce6d763..cfea917 100644
  4379. --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
  4380. +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
  4381. @@ -47,7 +47,7 @@ struct samsung_dma_ops {
  4382. int (*started)(unsigned ch);
  4383. int (*flush)(unsigned ch);
  4384. int (*stop)(unsigned ch);
  4385. -};
  4386. +} __no_const;
  4387. extern void *samsung_dmadev_get_ops(void);
  4388. extern void *s3c_dma_get_ops(void);
  4389. diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
  4390. index 6c0f684..5faea9d 100644
  4391. --- a/arch/arm64/include/asm/uaccess.h
  4392. +++ b/arch/arm64/include/asm/uaccess.h
  4393. @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
  4394. flag; \
  4395. })
  4396. +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
  4397. #define access_ok(type, addr, size) __range_ok(addr, size)
  4398. #define user_addr_max get_fs
  4399. diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
  4400. index c3a58a1..78fbf54 100644
  4401. --- a/arch/avr32/include/asm/cache.h
  4402. +++ b/arch/avr32/include/asm/cache.h
  4403. @@ -1,8 +1,10 @@
  4404. #ifndef __ASM_AVR32_CACHE_H
  4405. #define __ASM_AVR32_CACHE_H
  4406. +#include <linux/const.h>
  4407. +
  4408. #define L1_CACHE_SHIFT 5
  4409. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  4410. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4411. /*
  4412. * Memory returned by kmalloc() may be used for DMA, so we must make
  4413. diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
  4414. index d232888..87c8df1 100644
  4415. --- a/arch/avr32/include/asm/elf.h
  4416. +++ b/arch/avr32/include/asm/elf.h
  4417. @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
  4418. the loader. We need to make sure that it is out of the way of the program
  4419. that it will "exec", and that there is sufficient room for the brk. */
  4420. -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
  4421. +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
  4422. +#ifdef CONFIG_PAX_ASLR
  4423. +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
  4424. +
  4425. +#define PAX_DELTA_MMAP_LEN 15
  4426. +#define PAX_DELTA_STACK_LEN 15
  4427. +#endif
  4428. /* This yields a mask that user programs can use to figure out what
  4429. instruction set this CPU supports. This could be done in user space,
  4430. diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
  4431. index 479330b..53717a8 100644
  4432. --- a/arch/avr32/include/asm/kmap_types.h
  4433. +++ b/arch/avr32/include/asm/kmap_types.h
  4434. @@ -2,9 +2,9 @@
  4435. #define __ASM_AVR32_KMAP_TYPES_H
  4436. #ifdef CONFIG_DEBUG_HIGHMEM
  4437. -# define KM_TYPE_NR 29
  4438. +# define KM_TYPE_NR 30
  4439. #else
  4440. -# define KM_TYPE_NR 14
  4441. +# define KM_TYPE_NR 15
  4442. #endif
  4443. #endif /* __ASM_AVR32_KMAP_TYPES_H */
  4444. diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
  4445. index 0eca933..eb78c7b 100644
  4446. --- a/arch/avr32/mm/fault.c
  4447. +++ b/arch/avr32/mm/fault.c
  4448. @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
  4449. int exception_trace = 1;
  4450. +#ifdef CONFIG_PAX_PAGEEXEC
  4451. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  4452. +{
  4453. + unsigned long i;
  4454. +
  4455. + printk(KERN_ERR "PAX: bytes at PC: ");
  4456. + for (i = 0; i < 20; i++) {
  4457. + unsigned char c;
  4458. + if (get_user(c, (unsigned char *)pc+i))
  4459. + printk(KERN_CONT "???????? ");
  4460. + else
  4461. + printk(KERN_CONT "%02x ", c);
  4462. + }
  4463. + printk("\n");
  4464. +}
  4465. +#endif
  4466. +
  4467. /*
  4468. * This routine handles page faults. It determines the address and the
  4469. * problem, and then passes it off to one of the appropriate routines.
  4470. @@ -176,6 +193,16 @@ bad_area:
  4471. up_read(&mm->mmap_sem);
  4472. if (user_mode(regs)) {
  4473. +
  4474. +#ifdef CONFIG_PAX_PAGEEXEC
  4475. + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
  4476. + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
  4477. + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
  4478. + do_group_exit(SIGKILL);
  4479. + }
  4480. + }
  4481. +#endif
  4482. +
  4483. if (exception_trace && printk_ratelimit())
  4484. printk("%s%s[%d]: segfault at %08lx pc %08lx "
  4485. "sp %08lx ecr %lu\n",
  4486. diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
  4487. index 568885a..f8008df 100644
  4488. --- a/arch/blackfin/include/asm/cache.h
  4489. +++ b/arch/blackfin/include/asm/cache.h
  4490. @@ -7,6 +7,7 @@
  4491. #ifndef __ARCH_BLACKFIN_CACHE_H
  4492. #define __ARCH_BLACKFIN_CACHE_H
  4493. +#include <linux/const.h>
  4494. #include <linux/linkage.h> /* for asmlinkage */
  4495. /*
  4496. @@ -14,7 +15,7 @@
  4497. * Blackfin loads 32 bytes for cache
  4498. */
  4499. #define L1_CACHE_SHIFT 5
  4500. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  4501. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4502. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  4503. #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
  4504. diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
  4505. index aea2718..3639a60 100644
  4506. --- a/arch/cris/include/arch-v10/arch/cache.h
  4507. +++ b/arch/cris/include/arch-v10/arch/cache.h
  4508. @@ -1,8 +1,9 @@
  4509. #ifndef _ASM_ARCH_CACHE_H
  4510. #define _ASM_ARCH_CACHE_H
  4511. +#include <linux/const.h>
  4512. /* Etrax 100LX have 32-byte cache-lines. */
  4513. -#define L1_CACHE_BYTES 32
  4514. #define L1_CACHE_SHIFT 5
  4515. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4516. #endif /* _ASM_ARCH_CACHE_H */
  4517. diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
  4518. index 7caf25d..ee65ac5 100644
  4519. --- a/arch/cris/include/arch-v32/arch/cache.h
  4520. +++ b/arch/cris/include/arch-v32/arch/cache.h
  4521. @@ -1,11 +1,12 @@
  4522. #ifndef _ASM_CRIS_ARCH_CACHE_H
  4523. #define _ASM_CRIS_ARCH_CACHE_H
  4524. +#include <linux/const.h>
  4525. #include <arch/hwregs/dma.h>
  4526. /* A cache-line is 32 bytes. */
  4527. -#define L1_CACHE_BYTES 32
  4528. #define L1_CACHE_SHIFT 5
  4529. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4530. #define __read_mostly __attribute__((__section__(".data..read_mostly")))
  4531. diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
  4532. index b86329d..6709906 100644
  4533. --- a/arch/frv/include/asm/atomic.h
  4534. +++ b/arch/frv/include/asm/atomic.h
  4535. @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
  4536. #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
  4537. #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
  4538. +#define atomic64_read_unchecked(v) atomic64_read(v)
  4539. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  4540. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  4541. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  4542. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  4543. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  4544. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  4545. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  4546. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  4547. +
  4548. static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  4549. {
  4550. int c, old;
  4551. diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
  4552. index 2797163..c2a401d 100644
  4553. --- a/arch/frv/include/asm/cache.h
  4554. +++ b/arch/frv/include/asm/cache.h
  4555. @@ -12,10 +12,11 @@
  4556. #ifndef __ASM_CACHE_H
  4557. #define __ASM_CACHE_H
  4558. +#include <linux/const.h>
  4559. /* bytes per L1 cache line */
  4560. #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
  4561. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  4562. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4563. #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
  4564. #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
  4565. diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
  4566. index 43901f2..0d8b865 100644
  4567. --- a/arch/frv/include/asm/kmap_types.h
  4568. +++ b/arch/frv/include/asm/kmap_types.h
  4569. @@ -2,6 +2,6 @@
  4570. #ifndef _ASM_KMAP_TYPES_H
  4571. #define _ASM_KMAP_TYPES_H
  4572. -#define KM_TYPE_NR 17
  4573. +#define KM_TYPE_NR 18
  4574. #endif
  4575. diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
  4576. index 836f147..4cf23f5 100644
  4577. --- a/arch/frv/mm/elf-fdpic.c
  4578. +++ b/arch/frv/mm/elf-fdpic.c
  4579. @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  4580. {
  4581. struct vm_area_struct *vma;
  4582. struct vm_unmapped_area_info info;
  4583. + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
  4584. if (len > TASK_SIZE)
  4585. return -ENOMEM;
  4586. @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  4587. if (addr) {
  4588. addr = PAGE_ALIGN(addr);
  4589. vma = find_vma(current->mm, addr);
  4590. - if (TASK_SIZE - len >= addr &&
  4591. - (!vma || addr + len <= vma->vm_start))
  4592. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  4593. goto success;
  4594. }
  4595. @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  4596. info.high_limit = (current->mm->start_stack - 0x00200000);
  4597. info.align_mask = 0;
  4598. info.align_offset = 0;
  4599. + info.threadstack_offset = offset;
  4600. addr = vm_unmapped_area(&info);
  4601. if (!(addr & ~PAGE_MASK))
  4602. goto success;
  4603. diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
  4604. index f4ca594..adc72fd6 100644
  4605. --- a/arch/hexagon/include/asm/cache.h
  4606. +++ b/arch/hexagon/include/asm/cache.h
  4607. @@ -21,9 +21,11 @@
  4608. #ifndef __ASM_CACHE_H
  4609. #define __ASM_CACHE_H
  4610. +#include <linux/const.h>
  4611. +
  4612. /* Bytes per L1 cache line */
  4613. -#define L1_CACHE_SHIFT (5)
  4614. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  4615. +#define L1_CACHE_SHIFT 5
  4616. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4617. #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
  4618. #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
  4619. diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
  4620. index 0c8e553..112d734 100644
  4621. --- a/arch/ia64/Kconfig
  4622. +++ b/arch/ia64/Kconfig
  4623. @@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
  4624. config KEXEC
  4625. bool "kexec system call"
  4626. depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
  4627. + depends on !GRKERNSEC_KMEM
  4628. help
  4629. kexec is a system call that implements the ability to shutdown your
  4630. current kernel, and to start another kernel. It is like a reboot
  4631. diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
  4632. index 6e6fe18..a6ae668 100644
  4633. --- a/arch/ia64/include/asm/atomic.h
  4634. +++ b/arch/ia64/include/asm/atomic.h
  4635. @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
  4636. #define atomic64_inc(v) atomic64_add(1, (v))
  4637. #define atomic64_dec(v) atomic64_sub(1, (v))
  4638. +#define atomic64_read_unchecked(v) atomic64_read(v)
  4639. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  4640. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  4641. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  4642. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  4643. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  4644. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  4645. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  4646. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  4647. +
  4648. /* Atomic operations are already serializing */
  4649. #define smp_mb__before_atomic_dec() barrier()
  4650. #define smp_mb__after_atomic_dec() barrier()
  4651. diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
  4652. index 988254a..e1ee885 100644
  4653. --- a/arch/ia64/include/asm/cache.h
  4654. +++ b/arch/ia64/include/asm/cache.h
  4655. @@ -1,6 +1,7 @@
  4656. #ifndef _ASM_IA64_CACHE_H
  4657. #define _ASM_IA64_CACHE_H
  4658. +#include <linux/const.h>
  4659. /*
  4660. * Copyright (C) 1998-2000 Hewlett-Packard Co
  4661. @@ -9,7 +10,7 @@
  4662. /* Bytes per L1 (data) cache line. */
  4663. #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
  4664. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  4665. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  4666. #ifdef CONFIG_SMP
  4667. # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
  4668. diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
  4669. index 5a83c5c..4d7f553 100644
  4670. --- a/arch/ia64/include/asm/elf.h
  4671. +++ b/arch/ia64/include/asm/elf.h
  4672. @@ -42,6 +42,13 @@
  4673. */
  4674. #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
  4675. +#ifdef CONFIG_PAX_ASLR
  4676. +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
  4677. +
  4678. +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
  4679. +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
  4680. +#endif
  4681. +
  4682. #define PT_IA_64_UNWIND 0x70000001
  4683. /* IA-64 relocations: */
  4684. diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
  4685. index 5767cdf..7462574 100644
  4686. --- a/arch/ia64/include/asm/pgalloc.h
  4687. +++ b/arch/ia64/include/asm/pgalloc.h
  4688. @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
  4689. pgd_val(*pgd_entry) = __pa(pud);
  4690. }
  4691. +static inline void
  4692. +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
  4693. +{
  4694. + pgd_populate(mm, pgd_entry, pud);
  4695. +}
  4696. +
  4697. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  4698. {
  4699. return quicklist_alloc(0, GFP_KERNEL, NULL);
  4700. @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
  4701. pud_val(*pud_entry) = __pa(pmd);
  4702. }
  4703. +static inline void
  4704. +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
  4705. +{
  4706. + pud_populate(mm, pud_entry, pmd);
  4707. +}
  4708. +
  4709. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  4710. {
  4711. return quicklist_alloc(0, GFP_KERNEL, NULL);
  4712. diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
  4713. index 7935115..c0eca6a 100644
  4714. --- a/arch/ia64/include/asm/pgtable.h
  4715. +++ b/arch/ia64/include/asm/pgtable.h
  4716. @@ -12,7 +12,7 @@
  4717. * David Mosberger-Tang <davidm@hpl.hp.com>
  4718. */
  4719. -
  4720. +#include <linux/const.h>
  4721. #include <asm/mman.h>
  4722. #include <asm/page.h>
  4723. #include <asm/processor.h>
  4724. @@ -142,6 +142,17 @@
  4725. #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
  4726. #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
  4727. #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
  4728. +
  4729. +#ifdef CONFIG_PAX_PAGEEXEC
  4730. +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
  4731. +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
  4732. +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
  4733. +#else
  4734. +# define PAGE_SHARED_NOEXEC PAGE_SHARED
  4735. +# define PAGE_READONLY_NOEXEC PAGE_READONLY
  4736. +# define PAGE_COPY_NOEXEC PAGE_COPY
  4737. +#endif
  4738. +
  4739. #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
  4740. #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
  4741. #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
  4742. diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
  4743. index 45698cd..e8e2dbc 100644
  4744. --- a/arch/ia64/include/asm/spinlock.h
  4745. +++ b/arch/ia64/include/asm/spinlock.h
  4746. @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
  4747. unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
  4748. asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
  4749. - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
  4750. + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
  4751. }
  4752. static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
  4753. diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
  4754. index 449c8c0..3d4b1e9 100644
  4755. --- a/arch/ia64/include/asm/uaccess.h
  4756. +++ b/arch/ia64/include/asm/uaccess.h
  4757. @@ -70,6 +70,7 @@
  4758. && ((segment).seg == KERNEL_DS.seg \
  4759. || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
  4760. })
  4761. +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
  4762. #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
  4763. /*
  4764. @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
  4765. static inline unsigned long
  4766. __copy_to_user (void __user *to, const void *from, unsigned long count)
  4767. {
  4768. + if (count > INT_MAX)
  4769. + return count;
  4770. +
  4771. + if (!__builtin_constant_p(count))
  4772. + check_object_size(from, count, true);
  4773. +
  4774. return __copy_user(to, (__force void __user *) from, count);
  4775. }
  4776. static inline unsigned long
  4777. __copy_from_user (void *to, const void __user *from, unsigned long count)
  4778. {
  4779. + if (count > INT_MAX)
  4780. + return count;
  4781. +
  4782. + if (!__builtin_constant_p(count))
  4783. + check_object_size(to, count, false);
  4784. +
  4785. return __copy_user((__force void __user *) to, from, count);
  4786. }
  4787. @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
  4788. ({ \
  4789. void __user *__cu_to = (to); \
  4790. const void *__cu_from = (from); \
  4791. - long __cu_len = (n); \
  4792. + unsigned long __cu_len = (n); \
  4793. \
  4794. - if (__access_ok(__cu_to, __cu_len, get_fs())) \
  4795. + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
  4796. + if (!__builtin_constant_p(n)) \
  4797. + check_object_size(__cu_from, __cu_len, true); \
  4798. __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
  4799. + } \
  4800. __cu_len; \
  4801. })
  4802. @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
  4803. ({ \
  4804. void *__cu_to = (to); \
  4805. const void __user *__cu_from = (from); \
  4806. - long __cu_len = (n); \
  4807. + unsigned long __cu_len = (n); \
  4808. \
  4809. __chk_user_ptr(__cu_from); \
  4810. - if (__access_ok(__cu_from, __cu_len, get_fs())) \
  4811. + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
  4812. + if (!__builtin_constant_p(n)) \
  4813. + check_object_size(__cu_to, __cu_len, false); \
  4814. __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
  4815. + } \
  4816. __cu_len; \
  4817. })
  4818. diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
  4819. index 24603be..948052d 100644
  4820. --- a/arch/ia64/kernel/module.c
  4821. +++ b/arch/ia64/kernel/module.c
  4822. @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
  4823. void
  4824. module_free (struct module *mod, void *module_region)
  4825. {
  4826. - if (mod && mod->arch.init_unw_table &&
  4827. - module_region == mod->module_init) {
  4828. + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
  4829. unw_remove_unwind_table(mod->arch.init_unw_table);
  4830. mod->arch.init_unw_table = NULL;
  4831. }
  4832. @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
  4833. }
  4834. static inline int
  4835. +in_init_rx (const struct module *mod, uint64_t addr)
  4836. +{
  4837. + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
  4838. +}
  4839. +
  4840. +static inline int
  4841. +in_init_rw (const struct module *mod, uint64_t addr)
  4842. +{
  4843. + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
  4844. +}
  4845. +
  4846. +static inline int
  4847. in_init (const struct module *mod, uint64_t addr)
  4848. {
  4849. - return addr - (uint64_t) mod->module_init < mod->init_size;
  4850. + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
  4851. +}
  4852. +
  4853. +static inline int
  4854. +in_core_rx (const struct module *mod, uint64_t addr)
  4855. +{
  4856. + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
  4857. +}
  4858. +
  4859. +static inline int
  4860. +in_core_rw (const struct module *mod, uint64_t addr)
  4861. +{
  4862. + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
  4863. }
  4864. static inline int
  4865. in_core (const struct module *mod, uint64_t addr)
  4866. {
  4867. - return addr - (uint64_t) mod->module_core < mod->core_size;
  4868. + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
  4869. }
  4870. static inline int
  4871. @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
  4872. break;
  4873. case RV_BDREL:
  4874. - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
  4875. + if (in_init_rx(mod, val))
  4876. + val -= (uint64_t) mod->module_init_rx;
  4877. + else if (in_init_rw(mod, val))
  4878. + val -= (uint64_t) mod->module_init_rw;
  4879. + else if (in_core_rx(mod, val))
  4880. + val -= (uint64_t) mod->module_core_rx;
  4881. + else if (in_core_rw(mod, val))
  4882. + val -= (uint64_t) mod->module_core_rw;
  4883. break;
  4884. case RV_LTV:
  4885. @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
  4886. * addresses have been selected...
  4887. */
  4888. uint64_t gp;
  4889. - if (mod->core_size > MAX_LTOFF)
  4890. + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
  4891. /*
  4892. * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
  4893. * at the end of the module.
  4894. */
  4895. - gp = mod->core_size - MAX_LTOFF / 2;
  4896. + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
  4897. else
  4898. - gp = mod->core_size / 2;
  4899. - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
  4900. + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
  4901. + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
  4902. mod->arch.gp = gp;
  4903. DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
  4904. }
  4905. diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
  4906. index ab33328..f39506c 100644
  4907. --- a/arch/ia64/kernel/palinfo.c
  4908. +++ b/arch/ia64/kernel/palinfo.c
  4909. @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
  4910. return NOTIFY_OK;
  4911. }
  4912. -static struct notifier_block __refdata palinfo_cpu_notifier =
  4913. +static struct notifier_block palinfo_cpu_notifier =
  4914. {
  4915. .notifier_call = palinfo_cpu_callback,
  4916. .priority = 0,
  4917. diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
  4918. index 41e33f8..65180b2a 100644
  4919. --- a/arch/ia64/kernel/sys_ia64.c
  4920. +++ b/arch/ia64/kernel/sys_ia64.c
  4921. @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
  4922. unsigned long align_mask = 0;
  4923. struct mm_struct *mm = current->mm;
  4924. struct vm_unmapped_area_info info;
  4925. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  4926. if (len > RGN_MAP_LIMIT)
  4927. return -ENOMEM;
  4928. @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
  4929. if (REGION_NUMBER(addr) == RGN_HPAGE)
  4930. addr = 0;
  4931. #endif
  4932. +
  4933. +#ifdef CONFIG_PAX_RANDMMAP
  4934. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  4935. + addr = mm->free_area_cache;
  4936. + else
  4937. +#endif
  4938. +
  4939. if (!addr)
  4940. addr = TASK_UNMAPPED_BASE;
  4941. @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
  4942. info.high_limit = TASK_SIZE;
  4943. info.align_mask = align_mask;
  4944. info.align_offset = 0;
  4945. + info.threadstack_offset = offset;
  4946. return vm_unmapped_area(&info);
  4947. }
  4948. diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
  4949. index 84f8a52..7c76178 100644
  4950. --- a/arch/ia64/kernel/vmlinux.lds.S
  4951. +++ b/arch/ia64/kernel/vmlinux.lds.S
  4952. @@ -192,7 +192,7 @@ SECTIONS {
  4953. /* Per-cpu data: */
  4954. . = ALIGN(PERCPU_PAGE_SIZE);
  4955. PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
  4956. - __phys_per_cpu_start = __per_cpu_load;
  4957. + __phys_per_cpu_start = per_cpu_load;
  4958. /*
  4959. * ensure percpu data fits
  4960. * into percpu page size
  4961. diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
  4962. index 7225dad..2a7c8256 100644
  4963. --- a/arch/ia64/mm/fault.c
  4964. +++ b/arch/ia64/mm/fault.c
  4965. @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
  4966. return pte_present(pte);
  4967. }
  4968. +#ifdef CONFIG_PAX_PAGEEXEC
  4969. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  4970. +{
  4971. + unsigned long i;
  4972. +
  4973. + printk(KERN_ERR "PAX: bytes at PC: ");
  4974. + for (i = 0; i < 8; i++) {
  4975. + unsigned int c;
  4976. + if (get_user(c, (unsigned int *)pc+i))
  4977. + printk(KERN_CONT "???????? ");
  4978. + else
  4979. + printk(KERN_CONT "%08x ", c);
  4980. + }
  4981. + printk("\n");
  4982. +}
  4983. +#endif
  4984. +
  4985. # define VM_READ_BIT 0
  4986. # define VM_WRITE_BIT 1
  4987. # define VM_EXEC_BIT 2
  4988. @@ -151,8 +168,21 @@ retry:
  4989. if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
  4990. goto bad_area;
  4991. - if ((vma->vm_flags & mask) != mask)
  4992. + if ((vma->vm_flags & mask) != mask) {
  4993. +
  4994. +#ifdef CONFIG_PAX_PAGEEXEC
  4995. + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
  4996. + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
  4997. + goto bad_area;
  4998. +
  4999. + up_read(&mm->mmap_sem);
  5000. + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
  5001. + do_group_exit(SIGKILL);
  5002. + }
  5003. +#endif
  5004. +
  5005. goto bad_area;
  5006. + }
  5007. /*
  5008. * If for any reason at all we couldn't handle the fault, make
  5009. diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
  5010. index 68232db..6ca80af 100644
  5011. --- a/arch/ia64/mm/hugetlbpage.c
  5012. +++ b/arch/ia64/mm/hugetlbpage.c
  5013. @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
  5014. unsigned long pgoff, unsigned long flags)
  5015. {
  5016. struct vm_unmapped_area_info info;
  5017. + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
  5018. if (len > RGN_MAP_LIMIT)
  5019. return -ENOMEM;
  5020. @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
  5021. info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
  5022. info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
  5023. info.align_offset = 0;
  5024. + info.threadstack_offset = offset;
  5025. return vm_unmapped_area(&info);
  5026. }
  5027. diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
  5028. index 25c3502..560dae7 100644
  5029. --- a/arch/ia64/mm/init.c
  5030. +++ b/arch/ia64/mm/init.c
  5031. @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
  5032. vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
  5033. vma->vm_end = vma->vm_start + PAGE_SIZE;
  5034. vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
  5035. +
  5036. +#ifdef CONFIG_PAX_PAGEEXEC
  5037. + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
  5038. + vma->vm_flags &= ~VM_EXEC;
  5039. +
  5040. +#ifdef CONFIG_PAX_MPROTECT
  5041. + if (current->mm->pax_flags & MF_PAX_MPROTECT)
  5042. + vma->vm_flags &= ~VM_MAYEXEC;
  5043. +#endif
  5044. +
  5045. + }
  5046. +#endif
  5047. +
  5048. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  5049. down_write(&current->mm->mmap_sem);
  5050. if (insert_vm_struct(current->mm, vma)) {
  5051. diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
  5052. index 40b3ee9..8c2c112 100644
  5053. --- a/arch/m32r/include/asm/cache.h
  5054. +++ b/arch/m32r/include/asm/cache.h
  5055. @@ -1,8 +1,10 @@
  5056. #ifndef _ASM_M32R_CACHE_H
  5057. #define _ASM_M32R_CACHE_H
  5058. +#include <linux/const.h>
  5059. +
  5060. /* L1 cache line size */
  5061. #define L1_CACHE_SHIFT 4
  5062. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  5063. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  5064. #endif /* _ASM_M32R_CACHE_H */
  5065. diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
  5066. index 82abd15..d95ae5d 100644
  5067. --- a/arch/m32r/lib/usercopy.c
  5068. +++ b/arch/m32r/lib/usercopy.c
  5069. @@ -14,6 +14,9 @@
  5070. unsigned long
  5071. __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
  5072. {
  5073. + if ((long)n < 0)
  5074. + return n;
  5075. +
  5076. prefetch(from);
  5077. if (access_ok(VERIFY_WRITE, to, n))
  5078. __copy_user(to,from,n);
  5079. @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
  5080. unsigned long
  5081. __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
  5082. {
  5083. + if ((long)n < 0)
  5084. + return n;
  5085. +
  5086. prefetchw(to);
  5087. if (access_ok(VERIFY_READ, from, n))
  5088. __copy_user_zeroing(to,from,n);
  5089. diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
  5090. index 0395c51..5f26031 100644
  5091. --- a/arch/m68k/include/asm/cache.h
  5092. +++ b/arch/m68k/include/asm/cache.h
  5093. @@ -4,9 +4,11 @@
  5094. #ifndef __ARCH_M68K_CACHE_H
  5095. #define __ARCH_M68K_CACHE_H
  5096. +#include <linux/const.h>
  5097. +
  5098. /* bytes per L1 cache line */
  5099. #define L1_CACHE_SHIFT 4
  5100. -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
  5101. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  5102. #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
  5103. diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
  5104. index 0424315..defcca9 100644
  5105. --- a/arch/metag/mm/hugetlbpage.c
  5106. +++ b/arch/metag/mm/hugetlbpage.c
  5107. @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
  5108. info.high_limit = TASK_SIZE;
  5109. info.align_mask = PAGE_MASK & HUGEPT_MASK;
  5110. info.align_offset = 0;
  5111. + info.threadstack_offset = 0;
  5112. return vm_unmapped_area(&info);
  5113. }
  5114. diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
  5115. index 4efe96a..60e8699 100644
  5116. --- a/arch/microblaze/include/asm/cache.h
  5117. +++ b/arch/microblaze/include/asm/cache.h
  5118. @@ -13,11 +13,12 @@
  5119. #ifndef _ASM_MICROBLAZE_CACHE_H
  5120. #define _ASM_MICROBLAZE_CACHE_H
  5121. +#include <linux/const.h>
  5122. #include <asm/registers.h>
  5123. #define L1_CACHE_SHIFT 5
  5124. /* word-granular cache in microblaze */
  5125. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  5126. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  5127. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  5128. diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
  5129. index 95fa1f1..56a6fa2 100644
  5130. --- a/arch/mips/Kconfig
  5131. +++ b/arch/mips/Kconfig
  5132. @@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
  5133. config KEXEC
  5134. bool "Kexec system call"
  5135. + depends on !GRKERNSEC_KMEM
  5136. help
  5137. kexec is a system call that implements the ability to shutdown your
  5138. current kernel, and to start another kernel. It is like a reboot
  5139. diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
  5140. index 02f2444..506969c 100644
  5141. --- a/arch/mips/cavium-octeon/dma-octeon.c
  5142. +++ b/arch/mips/cavium-octeon/dma-octeon.c
  5143. @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
  5144. if (dma_release_from_coherent(dev, order, vaddr))
  5145. return;
  5146. - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
  5147. + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
  5148. }
  5149. static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
  5150. diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
  5151. index 7eed2f2..c4e385d 100644
  5152. --- a/arch/mips/include/asm/atomic.h
  5153. +++ b/arch/mips/include/asm/atomic.h
  5154. @@ -21,15 +21,39 @@
  5155. #include <asm/cmpxchg.h>
  5156. #include <asm/war.h>
  5157. +#ifdef CONFIG_GENERIC_ATOMIC64
  5158. +#include <asm-generic/atomic64.h>
  5159. +#endif
  5160. +
  5161. #define ATOMIC_INIT(i) { (i) }
  5162. +#ifdef CONFIG_64BIT
  5163. +#define _ASM_EXTABLE(from, to) \
  5164. +" .section __ex_table,\"a\"\n" \
  5165. +" .dword " #from ", " #to"\n" \
  5166. +" .previous\n"
  5167. +#else
  5168. +#define _ASM_EXTABLE(from, to) \
  5169. +" .section __ex_table,\"a\"\n" \
  5170. +" .word " #from ", " #to"\n" \
  5171. +" .previous\n"
  5172. +#endif
  5173. +
  5174. /*
  5175. * atomic_read - read atomic variable
  5176. * @v: pointer of type atomic_t
  5177. *
  5178. * Atomically reads the value of @v.
  5179. */
  5180. -#define atomic_read(v) (*(volatile int *)&(v)->counter)
  5181. +static inline int atomic_read(const atomic_t *v)
  5182. +{
  5183. + return (*(volatile const int *) &v->counter);
  5184. +}
  5185. +
  5186. +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
  5187. +{
  5188. + return (*(volatile const int *) &v->counter);
  5189. +}
  5190. /*
  5191. * atomic_set - set atomic variable
  5192. @@ -38,7 +62,15 @@
  5193. *
  5194. * Atomically sets the value of @v to @i.
  5195. */
  5196. -#define atomic_set(v, i) ((v)->counter = (i))
  5197. +static inline void atomic_set(atomic_t *v, int i)
  5198. +{
  5199. + v->counter = i;
  5200. +}
  5201. +
  5202. +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
  5203. +{
  5204. + v->counter = i;
  5205. +}
  5206. /*
  5207. * atomic_add - add integer to atomic variable
  5208. @@ -47,7 +79,67 @@
  5209. *
  5210. * Atomically adds @i to @v.
  5211. */
  5212. -static __inline__ void atomic_add(int i, atomic_t * v)
  5213. +static __inline__ void atomic_add(int i, atomic_t *v)
  5214. +{
  5215. + int temp;
  5216. +
  5217. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5218. + __asm__ __volatile__(
  5219. + " .set mips3 \n"
  5220. + "1: ll %0, %1 # atomic_add \n"
  5221. +#ifdef CONFIG_PAX_REFCOUNT
  5222. + /* Exception on overflow. */
  5223. + "2: add %0, %2 \n"
  5224. +#else
  5225. + " addu %0, %2 \n"
  5226. +#endif
  5227. + " sc %0, %1 \n"
  5228. + " beqzl %0, 1b \n"
  5229. +#ifdef CONFIG_PAX_REFCOUNT
  5230. + "3: \n"
  5231. + _ASM_EXTABLE(2b, 3b)
  5232. +#endif
  5233. + " .set mips0 \n"
  5234. + : "=&r" (temp), "+m" (v->counter)
  5235. + : "Ir" (i));
  5236. + } else if (kernel_uses_llsc) {
  5237. + __asm__ __volatile__(
  5238. + " .set mips3 \n"
  5239. + "1: ll %0, %1 # atomic_add \n"
  5240. +#ifdef CONFIG_PAX_REFCOUNT
  5241. + /* Exception on overflow. */
  5242. + "2: add %0, %2 \n"
  5243. +#else
  5244. + " addu %0, %2 \n"
  5245. +#endif
  5246. + " sc %0, %1 \n"
  5247. + " beqz %0, 1b \n"
  5248. +#ifdef CONFIG_PAX_REFCOUNT
  5249. + "3: \n"
  5250. + _ASM_EXTABLE(2b, 3b)
  5251. +#endif
  5252. + " .set mips0 \n"
  5253. + : "=&r" (temp), "+m" (v->counter)
  5254. + : "Ir" (i));
  5255. + } else {
  5256. + unsigned long flags;
  5257. +
  5258. + raw_local_irq_save(flags);
  5259. + __asm__ __volatile__(
  5260. +#ifdef CONFIG_PAX_REFCOUNT
  5261. + /* Exception on overflow. */
  5262. + "1: add %0, %1 \n"
  5263. + "2: \n"
  5264. + _ASM_EXTABLE(1b, 2b)
  5265. +#else
  5266. + " addu %0, %1 \n"
  5267. +#endif
  5268. + : "+r" (v->counter) : "Ir" (i));
  5269. + raw_local_irq_restore(flags);
  5270. + }
  5271. +}
  5272. +
  5273. +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
  5274. {
  5275. if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5276. int temp;
  5277. @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
  5278. *
  5279. * Atomically subtracts @i from @v.
  5280. */
  5281. -static __inline__ void atomic_sub(int i, atomic_t * v)
  5282. +static __inline__ void atomic_sub(int i, atomic_t *v)
  5283. +{
  5284. + int temp;
  5285. +
  5286. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5287. + __asm__ __volatile__(
  5288. + " .set mips3 \n"
  5289. + "1: ll %0, %1 # atomic64_sub \n"
  5290. +#ifdef CONFIG_PAX_REFCOUNT
  5291. + /* Exception on overflow. */
  5292. + "2: sub %0, %2 \n"
  5293. +#else
  5294. + " subu %0, %2 \n"
  5295. +#endif
  5296. + " sc %0, %1 \n"
  5297. + " beqzl %0, 1b \n"
  5298. +#ifdef CONFIG_PAX_REFCOUNT
  5299. + "3: \n"
  5300. + _ASM_EXTABLE(2b, 3b)
  5301. +#endif
  5302. + " .set mips0 \n"
  5303. + : "=&r" (temp), "+m" (v->counter)
  5304. + : "Ir" (i));
  5305. + } else if (kernel_uses_llsc) {
  5306. + __asm__ __volatile__(
  5307. + " .set mips3 \n"
  5308. + "1: ll %0, %1 # atomic64_sub \n"
  5309. +#ifdef CONFIG_PAX_REFCOUNT
  5310. + /* Exception on overflow. */
  5311. + "2: sub %0, %2 \n"
  5312. +#else
  5313. + " subu %0, %2 \n"
  5314. +#endif
  5315. + " sc %0, %1 \n"
  5316. + " beqz %0, 1b \n"
  5317. +#ifdef CONFIG_PAX_REFCOUNT
  5318. + "3: \n"
  5319. + _ASM_EXTABLE(2b, 3b)
  5320. +#endif
  5321. + " .set mips0 \n"
  5322. + : "=&r" (temp), "+m" (v->counter)
  5323. + : "Ir" (i));
  5324. + } else {
  5325. + unsigned long flags;
  5326. +
  5327. + raw_local_irq_save(flags);
  5328. + __asm__ __volatile__(
  5329. +#ifdef CONFIG_PAX_REFCOUNT
  5330. + /* Exception on overflow. */
  5331. + "1: sub %0, %1 \n"
  5332. + "2: \n"
  5333. + _ASM_EXTABLE(1b, 2b)
  5334. +#else
  5335. + " subu %0, %1 \n"
  5336. +#endif
  5337. + : "+r" (v->counter) : "Ir" (i));
  5338. + raw_local_irq_restore(flags);
  5339. + }
  5340. +}
  5341. +
  5342. +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
  5343. {
  5344. if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5345. int temp;
  5346. @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
  5347. /*
  5348. * Same as above, but return the result value
  5349. */
  5350. -static __inline__ int atomic_add_return(int i, atomic_t * v)
  5351. +static __inline__ int atomic_add_return(int i, atomic_t *v)
  5352. +{
  5353. + int result;
  5354. + int temp;
  5355. +
  5356. + smp_mb__before_llsc();
  5357. +
  5358. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5359. + __asm__ __volatile__(
  5360. + " .set mips3 \n"
  5361. + "1: ll %1, %2 # atomic_add_return \n"
  5362. +#ifdef CONFIG_PAX_REFCOUNT
  5363. + "2: add %0, %1, %3 \n"
  5364. +#else
  5365. + " addu %0, %1, %3 \n"
  5366. +#endif
  5367. + " sc %0, %2 \n"
  5368. + " beqzl %0, 1b \n"
  5369. +#ifdef CONFIG_PAX_REFCOUNT
  5370. + " b 4f \n"
  5371. + " .set noreorder \n"
  5372. + "3: b 5f \n"
  5373. + " move %0, %1 \n"
  5374. + " .set reorder \n"
  5375. + _ASM_EXTABLE(2b, 3b)
  5376. +#endif
  5377. + "4: addu %0, %1, %3 \n"
  5378. +#ifdef CONFIG_PAX_REFCOUNT
  5379. + "5: \n"
  5380. +#endif
  5381. + " .set mips0 \n"
  5382. + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
  5383. + : "Ir" (i));
  5384. + } else if (kernel_uses_llsc) {
  5385. + __asm__ __volatile__(
  5386. + " .set mips3 \n"
  5387. + "1: ll %1, %2 # atomic_add_return \n"
  5388. +#ifdef CONFIG_PAX_REFCOUNT
  5389. + "2: add %0, %1, %3 \n"
  5390. +#else
  5391. + " addu %0, %1, %3 \n"
  5392. +#endif
  5393. + " sc %0, %2 \n"
  5394. + " bnez %0, 4f \n"
  5395. + " b 1b \n"
  5396. +#ifdef CONFIG_PAX_REFCOUNT
  5397. + " .set noreorder \n"
  5398. + "3: b 5f \n"
  5399. + " move %0, %1 \n"
  5400. + " .set reorder \n"
  5401. + _ASM_EXTABLE(2b, 3b)
  5402. +#endif
  5403. + "4: addu %0, %1, %3 \n"
  5404. +#ifdef CONFIG_PAX_REFCOUNT
  5405. + "5: \n"
  5406. +#endif
  5407. + " .set mips0 \n"
  5408. + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
  5409. + : "Ir" (i));
  5410. + } else {
  5411. + unsigned long flags;
  5412. +
  5413. + raw_local_irq_save(flags);
  5414. + __asm__ __volatile__(
  5415. + " lw %0, %1 \n"
  5416. +#ifdef CONFIG_PAX_REFCOUNT
  5417. + /* Exception on overflow. */
  5418. + "1: add %0, %2 \n"
  5419. +#else
  5420. + " addu %0, %2 \n"
  5421. +#endif
  5422. + " sw %0, %1 \n"
  5423. +#ifdef CONFIG_PAX_REFCOUNT
  5424. + /* Note: Dest reg is not modified on overflow */
  5425. + "2: \n"
  5426. + _ASM_EXTABLE(1b, 2b)
  5427. +#endif
  5428. + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
  5429. + raw_local_irq_restore(flags);
  5430. + }
  5431. +
  5432. + smp_llsc_mb();
  5433. +
  5434. + return result;
  5435. +}
  5436. +
  5437. +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
  5438. {
  5439. int result;
  5440. @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
  5441. return result;
  5442. }
  5443. -static __inline__ int atomic_sub_return(int i, atomic_t * v)
  5444. +static __inline__ int atomic_sub_return(int i, atomic_t *v)
  5445. +{
  5446. + int result;
  5447. + int temp;
  5448. +
  5449. + smp_mb__before_llsc();
  5450. +
  5451. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5452. + __asm__ __volatile__(
  5453. + " .set mips3 \n"
  5454. + "1: ll %1, %2 # atomic_sub_return \n"
  5455. +#ifdef CONFIG_PAX_REFCOUNT
  5456. + "2: sub %0, %1, %3 \n"
  5457. +#else
  5458. + " subu %0, %1, %3 \n"
  5459. +#endif
  5460. + " sc %0, %2 \n"
  5461. + " beqzl %0, 1b \n"
  5462. +#ifdef CONFIG_PAX_REFCOUNT
  5463. + " b 4f \n"
  5464. + " .set noreorder \n"
  5465. + "3: b 5f \n"
  5466. + " move %0, %1 \n"
  5467. + " .set reorder \n"
  5468. + _ASM_EXTABLE(2b, 3b)
  5469. +#endif
  5470. + "4: subu %0, %1, %3 \n"
  5471. +#ifdef CONFIG_PAX_REFCOUNT
  5472. + "5: \n"
  5473. +#endif
  5474. + " .set mips0 \n"
  5475. + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  5476. + : "Ir" (i), "m" (v->counter)
  5477. + : "memory");
  5478. + } else if (kernel_uses_llsc) {
  5479. + __asm__ __volatile__(
  5480. + " .set mips3 \n"
  5481. + "1: ll %1, %2 # atomic_sub_return \n"
  5482. +#ifdef CONFIG_PAX_REFCOUNT
  5483. + "2: sub %0, %1, %3 \n"
  5484. +#else
  5485. + " subu %0, %1, %3 \n"
  5486. +#endif
  5487. + " sc %0, %2 \n"
  5488. + " bnez %0, 4f \n"
  5489. + " b 1b \n"
  5490. +#ifdef CONFIG_PAX_REFCOUNT
  5491. + " .set noreorder \n"
  5492. + "3: b 5f \n"
  5493. + " move %0, %1 \n"
  5494. + " .set reorder \n"
  5495. + _ASM_EXTABLE(2b, 3b)
  5496. +#endif
  5497. + "4: subu %0, %1, %3 \n"
  5498. +#ifdef CONFIG_PAX_REFCOUNT
  5499. + "5: \n"
  5500. +#endif
  5501. + " .set mips0 \n"
  5502. + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
  5503. + : "Ir" (i));
  5504. + } else {
  5505. + unsigned long flags;
  5506. +
  5507. + raw_local_irq_save(flags);
  5508. + __asm__ __volatile__(
  5509. + " lw %0, %1 \n"
  5510. +#ifdef CONFIG_PAX_REFCOUNT
  5511. + /* Exception on overflow. */
  5512. + "1: sub %0, %2 \n"
  5513. +#else
  5514. + " subu %0, %2 \n"
  5515. +#endif
  5516. + " sw %0, %1 \n"
  5517. +#ifdef CONFIG_PAX_REFCOUNT
  5518. + /* Note: Dest reg is not modified on overflow */
  5519. + "2: \n"
  5520. + _ASM_EXTABLE(1b, 2b)
  5521. +#endif
  5522. + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
  5523. + raw_local_irq_restore(flags);
  5524. + }
  5525. +
  5526. + smp_llsc_mb();
  5527. +
  5528. + return result;
  5529. +}
  5530. +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
  5531. {
  5532. int result;
  5533. @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
  5534. * Atomically test @v and subtract @i if @v is greater or equal than @i.
  5535. * The function returns the old value of @v minus @i.
  5536. */
  5537. -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
  5538. +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
  5539. {
  5540. int result;
  5541. @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
  5542. return result;
  5543. }
  5544. -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
  5545. -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
  5546. +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
  5547. +{
  5548. + return cmpxchg(&v->counter, old, new);
  5549. +}
  5550. +
  5551. +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
  5552. + int new)
  5553. +{
  5554. + return cmpxchg(&(v->counter), old, new);
  5555. +}
  5556. +
  5557. +static inline int atomic_xchg(atomic_t *v, int new)
  5558. +{
  5559. + return xchg(&v->counter, new);
  5560. +}
  5561. +
  5562. +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
  5563. +{
  5564. + return xchg(&(v->counter), new);
  5565. +}
  5566. /**
  5567. * __atomic_add_unless - add unless the number is a given value
  5568. @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  5569. #define atomic_dec_return(v) atomic_sub_return(1, (v))
  5570. #define atomic_inc_return(v) atomic_add_return(1, (v))
  5571. +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
  5572. +{
  5573. + return atomic_add_return_unchecked(1, v);
  5574. +}
  5575. /*
  5576. * atomic_sub_and_test - subtract value from variable and test result
  5577. @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  5578. * other cases.
  5579. */
  5580. #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
  5581. +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
  5582. +{
  5583. + return atomic_add_return_unchecked(1, v) == 0;
  5584. +}
  5585. /*
  5586. * atomic_dec_and_test - decrement by 1 and test
  5587. @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  5588. * Atomically increments @v by 1.
  5589. */
  5590. #define atomic_inc(v) atomic_add(1, (v))
  5591. +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
  5592. +{
  5593. + atomic_add_unchecked(1, v);
  5594. +}
  5595. /*
  5596. * atomic_dec - decrement and test
  5597. @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  5598. * Atomically decrements @v by 1.
  5599. */
  5600. #define atomic_dec(v) atomic_sub(1, (v))
  5601. +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
  5602. +{
  5603. + atomic_sub_unchecked(1, v);
  5604. +}
  5605. /*
  5606. * atomic_add_negative - add and test if negative
  5607. @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  5608. * @v: pointer of type atomic64_t
  5609. *
  5610. */
  5611. -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
  5612. +static inline long atomic64_read(const atomic64_t *v)
  5613. +{
  5614. + return (*(volatile const long *) &v->counter);
  5615. +}
  5616. +
  5617. +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
  5618. +{
  5619. + return (*(volatile const long *) &v->counter);
  5620. +}
  5621. /*
  5622. * atomic64_set - set atomic variable
  5623. * @v: pointer of type atomic64_t
  5624. * @i: required value
  5625. */
  5626. -#define atomic64_set(v, i) ((v)->counter = (i))
  5627. +static inline void atomic64_set(atomic64_t *v, long i)
  5628. +{
  5629. + v->counter = i;
  5630. +}
  5631. +
  5632. +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
  5633. +{
  5634. + v->counter = i;
  5635. +}
  5636. /*
  5637. * atomic64_add - add integer to atomic variable
  5638. @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  5639. *
  5640. * Atomically adds @i to @v.
  5641. */
  5642. -static __inline__ void atomic64_add(long i, atomic64_t * v)
  5643. +static __inline__ void atomic64_add(long i, atomic64_t *v)
  5644. +{
  5645. + long temp;
  5646. +
  5647. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5648. + __asm__ __volatile__(
  5649. + " .set mips3 \n"
  5650. + "1: lld %0, %1 # atomic64_add \n"
  5651. +#ifdef CONFIG_PAX_REFCOUNT
  5652. + /* Exception on overflow. */
  5653. + "2: dadd %0, %2 \n"
  5654. +#else
  5655. + " daddu %0, %2 \n"
  5656. +#endif
  5657. + " scd %0, %1 \n"
  5658. + " beqzl %0, 1b \n"
  5659. +#ifdef CONFIG_PAX_REFCOUNT
  5660. + "3: \n"
  5661. + _ASM_EXTABLE(2b, 3b)
  5662. +#endif
  5663. + " .set mips0 \n"
  5664. + : "=&r" (temp), "+m" (v->counter)
  5665. + : "Ir" (i));
  5666. + } else if (kernel_uses_llsc) {
  5667. + __asm__ __volatile__(
  5668. + " .set mips3 \n"
  5669. + "1: lld %0, %1 # atomic64_add \n"
  5670. +#ifdef CONFIG_PAX_REFCOUNT
  5671. + /* Exception on overflow. */
  5672. + "2: dadd %0, %2 \n"
  5673. +#else
  5674. + " daddu %0, %2 \n"
  5675. +#endif
  5676. + " scd %0, %1 \n"
  5677. + " beqz %0, 1b \n"
  5678. +#ifdef CONFIG_PAX_REFCOUNT
  5679. + "3: \n"
  5680. + _ASM_EXTABLE(2b, 3b)
  5681. +#endif
  5682. + " .set mips0 \n"
  5683. + : "=&r" (temp), "+m" (v->counter)
  5684. + : "Ir" (i));
  5685. + } else {
  5686. + unsigned long flags;
  5687. +
  5688. + raw_local_irq_save(flags);
  5689. + __asm__ __volatile__(
  5690. +#ifdef CONFIG_PAX_REFCOUNT
  5691. + /* Exception on overflow. */
  5692. + "1: dadd %0, %1 \n"
  5693. + "2: \n"
  5694. + _ASM_EXTABLE(1b, 2b)
  5695. +#else
  5696. + " daddu %0, %1 \n"
  5697. +#endif
  5698. + : "+r" (v->counter) : "Ir" (i));
  5699. + raw_local_irq_restore(flags);
  5700. + }
  5701. +}
  5702. +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
  5703. {
  5704. if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5705. long temp;
  5706. @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
  5707. *
  5708. * Atomically subtracts @i from @v.
  5709. */
  5710. -static __inline__ void atomic64_sub(long i, atomic64_t * v)
  5711. +static __inline__ void atomic64_sub(long i, atomic64_t *v)
  5712. +{
  5713. + long temp;
  5714. +
  5715. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5716. + __asm__ __volatile__(
  5717. + " .set mips3 \n"
  5718. + "1: lld %0, %1 # atomic64_sub \n"
  5719. +#ifdef CONFIG_PAX_REFCOUNT
  5720. + /* Exception on overflow. */
  5721. + "2: dsub %0, %2 \n"
  5722. +#else
  5723. + " dsubu %0, %2 \n"
  5724. +#endif
  5725. + " scd %0, %1 \n"
  5726. + " beqzl %0, 1b \n"
  5727. +#ifdef CONFIG_PAX_REFCOUNT
  5728. + "3: \n"
  5729. + _ASM_EXTABLE(2b, 3b)
  5730. +#endif
  5731. + " .set mips0 \n"
  5732. + : "=&r" (temp), "+m" (v->counter)
  5733. + : "Ir" (i));
  5734. + } else if (kernel_uses_llsc) {
  5735. + __asm__ __volatile__(
  5736. + " .set mips3 \n"
  5737. + "1: lld %0, %1 # atomic64_sub \n"
  5738. +#ifdef CONFIG_PAX_REFCOUNT
  5739. + /* Exception on overflow. */
  5740. + "2: dsub %0, %2 \n"
  5741. +#else
  5742. + " dsubu %0, %2 \n"
  5743. +#endif
  5744. + " scd %0, %1 \n"
  5745. + " beqz %0, 1b \n"
  5746. +#ifdef CONFIG_PAX_REFCOUNT
  5747. + "3: \n"
  5748. + _ASM_EXTABLE(2b, 3b)
  5749. +#endif
  5750. + " .set mips0 \n"
  5751. + : "=&r" (temp), "+m" (v->counter)
  5752. + : "Ir" (i));
  5753. + } else {
  5754. + unsigned long flags;
  5755. +
  5756. + raw_local_irq_save(flags);
  5757. + __asm__ __volatile__(
  5758. +#ifdef CONFIG_PAX_REFCOUNT
  5759. + /* Exception on overflow. */
  5760. + "1: dsub %0, %1 \n"
  5761. + "2: \n"
  5762. + _ASM_EXTABLE(1b, 2b)
  5763. +#else
  5764. + " dsubu %0, %1 \n"
  5765. +#endif
  5766. + : "+r" (v->counter) : "Ir" (i));
  5767. + raw_local_irq_restore(flags);
  5768. + }
  5769. +}
  5770. +
  5771. +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
  5772. {
  5773. if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5774. long temp;
  5775. @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
  5776. /*
  5777. * Same as above, but return the result value
  5778. */
  5779. -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
  5780. +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
  5781. +{
  5782. + long result;
  5783. + long temp;
  5784. +
  5785. + smp_mb__before_llsc();
  5786. +
  5787. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5788. + __asm__ __volatile__(
  5789. + " .set mips3 \n"
  5790. + "1: lld %1, %2 # atomic64_add_return \n"
  5791. +#ifdef CONFIG_PAX_REFCOUNT
  5792. + "2: dadd %0, %1, %3 \n"
  5793. +#else
  5794. + " daddu %0, %1, %3 \n"
  5795. +#endif
  5796. + " scd %0, %2 \n"
  5797. + " beqzl %0, 1b \n"
  5798. +#ifdef CONFIG_PAX_REFCOUNT
  5799. + " b 4f \n"
  5800. + " .set noreorder \n"
  5801. + "3: b 5f \n"
  5802. + " move %0, %1 \n"
  5803. + " .set reorder \n"
  5804. + _ASM_EXTABLE(2b, 3b)
  5805. +#endif
  5806. + "4: daddu %0, %1, %3 \n"
  5807. +#ifdef CONFIG_PAX_REFCOUNT
  5808. + "5: \n"
  5809. +#endif
  5810. + " .set mips0 \n"
  5811. + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
  5812. + : "Ir" (i));
  5813. + } else if (kernel_uses_llsc) {
  5814. + __asm__ __volatile__(
  5815. + " .set mips3 \n"
  5816. + "1: lld %1, %2 # atomic64_add_return \n"
  5817. +#ifdef CONFIG_PAX_REFCOUNT
  5818. + "2: dadd %0, %1, %3 \n"
  5819. +#else
  5820. + " daddu %0, %1, %3 \n"
  5821. +#endif
  5822. + " scd %0, %2 \n"
  5823. + " bnez %0, 4f \n"
  5824. + " b 1b \n"
  5825. +#ifdef CONFIG_PAX_REFCOUNT
  5826. + " .set noreorder \n"
  5827. + "3: b 5f \n"
  5828. + " move %0, %1 \n"
  5829. + " .set reorder \n"
  5830. + _ASM_EXTABLE(2b, 3b)
  5831. +#endif
  5832. + "4: daddu %0, %1, %3 \n"
  5833. +#ifdef CONFIG_PAX_REFCOUNT
  5834. + "5: \n"
  5835. +#endif
  5836. + " .set mips0 \n"
  5837. + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  5838. + : "Ir" (i), "m" (v->counter)
  5839. + : "memory");
  5840. + } else {
  5841. + unsigned long flags;
  5842. +
  5843. + raw_local_irq_save(flags);
  5844. + __asm__ __volatile__(
  5845. + " ld %0, %1 \n"
  5846. +#ifdef CONFIG_PAX_REFCOUNT
  5847. + /* Exception on overflow. */
  5848. + "1: dadd %0, %2 \n"
  5849. +#else
  5850. + " daddu %0, %2 \n"
  5851. +#endif
  5852. + " sd %0, %1 \n"
  5853. +#ifdef CONFIG_PAX_REFCOUNT
  5854. + /* Note: Dest reg is not modified on overflow */
  5855. + "2: \n"
  5856. + _ASM_EXTABLE(1b, 2b)
  5857. +#endif
  5858. + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
  5859. + raw_local_irq_restore(flags);
  5860. + }
  5861. +
  5862. + smp_llsc_mb();
  5863. +
  5864. + return result;
  5865. +}
  5866. +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
  5867. {
  5868. long result;
  5869. @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
  5870. return result;
  5871. }
  5872. -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
  5873. +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
  5874. +{
  5875. + long result;
  5876. + long temp;
  5877. +
  5878. + smp_mb__before_llsc();
  5879. +
  5880. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  5881. + long temp;
  5882. +
  5883. + __asm__ __volatile__(
  5884. + " .set mips3 \n"
  5885. + "1: lld %1, %2 # atomic64_sub_return \n"
  5886. +#ifdef CONFIG_PAX_REFCOUNT
  5887. + "2: dsub %0, %1, %3 \n"
  5888. +#else
  5889. + " dsubu %0, %1, %3 \n"
  5890. +#endif
  5891. + " scd %0, %2 \n"
  5892. + " beqzl %0, 1b \n"
  5893. +#ifdef CONFIG_PAX_REFCOUNT
  5894. + " b 4f \n"
  5895. + " .set noreorder \n"
  5896. + "3: b 5f \n"
  5897. + " move %0, %1 \n"
  5898. + " .set reorder \n"
  5899. + _ASM_EXTABLE(2b, 3b)
  5900. +#endif
  5901. + "4: dsubu %0, %1, %3 \n"
  5902. +#ifdef CONFIG_PAX_REFCOUNT
  5903. + "5: \n"
  5904. +#endif
  5905. + " .set mips0 \n"
  5906. + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  5907. + : "Ir" (i), "m" (v->counter)
  5908. + : "memory");
  5909. + } else if (kernel_uses_llsc) {
  5910. + __asm__ __volatile__(
  5911. + " .set mips3 \n"
  5912. + "1: lld %1, %2 # atomic64_sub_return \n"
  5913. +#ifdef CONFIG_PAX_REFCOUNT
  5914. + "2: dsub %0, %1, %3 \n"
  5915. +#else
  5916. + " dsubu %0, %1, %3 \n"
  5917. +#endif
  5918. + " scd %0, %2 \n"
  5919. + " bnez %0, 4f \n"
  5920. + " b 1b \n"
  5921. +#ifdef CONFIG_PAX_REFCOUNT
  5922. + " .set noreorder \n"
  5923. + "3: b 5f \n"
  5924. + " move %0, %1 \n"
  5925. + " .set reorder \n"
  5926. + _ASM_EXTABLE(2b, 3b)
  5927. +#endif
  5928. + "4: dsubu %0, %1, %3 \n"
  5929. +#ifdef CONFIG_PAX_REFCOUNT
  5930. + "5: \n"
  5931. +#endif
  5932. + " .set mips0 \n"
  5933. + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  5934. + : "Ir" (i), "m" (v->counter)
  5935. + : "memory");
  5936. + } else {
  5937. + unsigned long flags;
  5938. +
  5939. + raw_local_irq_save(flags);
  5940. + __asm__ __volatile__(
  5941. + " ld %0, %1 \n"
  5942. +#ifdef CONFIG_PAX_REFCOUNT
  5943. + /* Exception on overflow. */
  5944. + "1: dsub %0, %2 \n"
  5945. +#else
  5946. + " dsubu %0, %2 \n"
  5947. +#endif
  5948. + " sd %0, %1 \n"
  5949. +#ifdef CONFIG_PAX_REFCOUNT
  5950. + /* Note: Dest reg is not modified on overflow */
  5951. + "2: \n"
  5952. + _ASM_EXTABLE(1b, 2b)
  5953. +#endif
  5954. + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
  5955. + raw_local_irq_restore(flags);
  5956. + }
  5957. +
  5958. + smp_llsc_mb();
  5959. +
  5960. + return result;
  5961. +}
  5962. +
  5963. +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
  5964. {
  5965. long result;
  5966. @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
  5967. * Atomically test @v and subtract @i if @v is greater or equal than @i.
  5968. * The function returns the old value of @v minus @i.
  5969. */
  5970. -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
  5971. +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
  5972. {
  5973. long result;
  5974. @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
  5975. return result;
  5976. }
  5977. -#define atomic64_cmpxchg(v, o, n) \
  5978. - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
  5979. -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
  5980. +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
  5981. +{
  5982. + return cmpxchg(&v->counter, old, new);
  5983. +}
  5984. +
  5985. +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
  5986. + long new)
  5987. +{
  5988. + return cmpxchg(&(v->counter), old, new);
  5989. +}
  5990. +
  5991. +static inline long atomic64_xchg(atomic64_t *v, long new)
  5992. +{
  5993. + return xchg(&v->counter, new);
  5994. +}
  5995. +
  5996. +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
  5997. +{
  5998. + return xchg(&(v->counter), new);
  5999. +}
  6000. /**
  6001. * atomic64_add_unless - add unless the number is a given value
  6002. @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
  6003. #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
  6004. #define atomic64_inc_return(v) atomic64_add_return(1, (v))
  6005. +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
  6006. /*
  6007. * atomic64_sub_and_test - subtract value from variable and test result
  6008. @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
  6009. * other cases.
  6010. */
  6011. #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
  6012. +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
  6013. /*
  6014. * atomic64_dec_and_test - decrement by 1 and test
  6015. @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
  6016. * Atomically increments @v by 1.
  6017. */
  6018. #define atomic64_inc(v) atomic64_add(1, (v))
  6019. +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
  6020. /*
  6021. * atomic64_dec - decrement and test
  6022. @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
  6023. * Atomically decrements @v by 1.
  6024. */
  6025. #define atomic64_dec(v) atomic64_sub(1, (v))
  6026. +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
  6027. /*
  6028. * atomic64_add_negative - add and test if negative
  6029. diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
  6030. index b4db69f..8f3b093 100644
  6031. --- a/arch/mips/include/asm/cache.h
  6032. +++ b/arch/mips/include/asm/cache.h
  6033. @@ -9,10 +9,11 @@
  6034. #ifndef _ASM_CACHE_H
  6035. #define _ASM_CACHE_H
  6036. +#include <linux/const.h>
  6037. #include <kmalloc.h>
  6038. #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
  6039. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  6040. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  6041. #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
  6042. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  6043. diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
  6044. index d414405..6bb4ba2 100644
  6045. --- a/arch/mips/include/asm/elf.h
  6046. +++ b/arch/mips/include/asm/elf.h
  6047. @@ -398,13 +398,16 @@ extern const char *__elf_platform;
  6048. #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
  6049. #endif
  6050. +#ifdef CONFIG_PAX_ASLR
  6051. +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
  6052. +
  6053. +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
  6054. +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
  6055. +#endif
  6056. +
  6057. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
  6058. struct linux_binprm;
  6059. extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  6060. int uses_interp);
  6061. -struct mm_struct;
  6062. -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
  6063. -#define arch_randomize_brk arch_randomize_brk
  6064. -
  6065. #endif /* _ASM_ELF_H */
  6066. diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
  6067. index c1f6afa..38cc6e9 100644
  6068. --- a/arch/mips/include/asm/exec.h
  6069. +++ b/arch/mips/include/asm/exec.h
  6070. @@ -12,6 +12,6 @@
  6071. #ifndef _ASM_EXEC_H
  6072. #define _ASM_EXEC_H
  6073. -extern unsigned long arch_align_stack(unsigned long sp);
  6074. +#define arch_align_stack(x) ((x) & ~0xfUL)
  6075. #endif /* _ASM_EXEC_H */
  6076. diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
  6077. index 9e8ef59..1139d6b 100644
  6078. --- a/arch/mips/include/asm/hw_irq.h
  6079. +++ b/arch/mips/include/asm/hw_irq.h
  6080. @@ -10,7 +10,7 @@
  6081. #include <linux/atomic.h>
  6082. -extern atomic_t irq_err_count;
  6083. +extern atomic_unchecked_t irq_err_count;
  6084. /*
  6085. * interrupt-retrigger: NOP for now. This may not be appropriate for all
  6086. diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
  6087. index d44622c..64990d2 100644
  6088. --- a/arch/mips/include/asm/local.h
  6089. +++ b/arch/mips/include/asm/local.h
  6090. @@ -12,15 +12,25 @@ typedef struct
  6091. atomic_long_t a;
  6092. } local_t;
  6093. +typedef struct {
  6094. + atomic_long_unchecked_t a;
  6095. +} local_unchecked_t;
  6096. +
  6097. #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
  6098. #define local_read(l) atomic_long_read(&(l)->a)
  6099. +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
  6100. #define local_set(l, i) atomic_long_set(&(l)->a, (i))
  6101. +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
  6102. #define local_add(i, l) atomic_long_add((i), (&(l)->a))
  6103. +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
  6104. #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
  6105. +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
  6106. #define local_inc(l) atomic_long_inc(&(l)->a)
  6107. +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
  6108. #define local_dec(l) atomic_long_dec(&(l)->a)
  6109. +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
  6110. /*
  6111. * Same as above, but return the result value
  6112. @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
  6113. return result;
  6114. }
  6115. +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
  6116. +{
  6117. + unsigned long result;
  6118. +
  6119. + if (kernel_uses_llsc && R10000_LLSC_WAR) {
  6120. + unsigned long temp;
  6121. +
  6122. + __asm__ __volatile__(
  6123. + " .set mips3 \n"
  6124. + "1:" __LL "%1, %2 # local_add_return \n"
  6125. + " addu %0, %1, %3 \n"
  6126. + __SC "%0, %2 \n"
  6127. + " beqzl %0, 1b \n"
  6128. + " addu %0, %1, %3 \n"
  6129. + " .set mips0 \n"
  6130. + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
  6131. + : "Ir" (i), "m" (l->a.counter)
  6132. + : "memory");
  6133. + } else if (kernel_uses_llsc) {
  6134. + unsigned long temp;
  6135. +
  6136. + __asm__ __volatile__(
  6137. + " .set mips3 \n"
  6138. + "1:" __LL "%1, %2 # local_add_return \n"
  6139. + " addu %0, %1, %3 \n"
  6140. + __SC "%0, %2 \n"
  6141. + " beqz %0, 1b \n"
  6142. + " addu %0, %1, %3 \n"
  6143. + " .set mips0 \n"
  6144. + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
  6145. + : "Ir" (i), "m" (l->a.counter)
  6146. + : "memory");
  6147. + } else {
  6148. + unsigned long flags;
  6149. +
  6150. + local_irq_save(flags);
  6151. + result = l->a.counter;
  6152. + result += i;
  6153. + l->a.counter = result;
  6154. + local_irq_restore(flags);
  6155. + }
  6156. +
  6157. + return result;
  6158. +}
  6159. +
  6160. static __inline__ long local_sub_return(long i, local_t * l)
  6161. {
  6162. unsigned long result;
  6163. @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
  6164. #define local_cmpxchg(l, o, n) \
  6165. ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
  6166. +#define local_cmpxchg_unchecked(l, o, n) \
  6167. + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
  6168. #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
  6169. /**
  6170. diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
  6171. index 5e08bcc..cfedefc 100644
  6172. --- a/arch/mips/include/asm/page.h
  6173. +++ b/arch/mips/include/asm/page.h
  6174. @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
  6175. #ifdef CONFIG_CPU_MIPS32
  6176. typedef struct { unsigned long pte_low, pte_high; } pte_t;
  6177. #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
  6178. - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
  6179. + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
  6180. #else
  6181. typedef struct { unsigned long long pte; } pte_t;
  6182. #define pte_val(x) ((x).pte)
  6183. diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
  6184. index b336037..5b874cc 100644
  6185. --- a/arch/mips/include/asm/pgalloc.h
  6186. +++ b/arch/mips/include/asm/pgalloc.h
  6187. @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  6188. {
  6189. set_pud(pud, __pud((unsigned long)pmd));
  6190. }
  6191. +
  6192. +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  6193. +{
  6194. + pud_populate(mm, pud, pmd);
  6195. +}
  6196. #endif
  6197. /*
  6198. diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
  6199. index 008324d..f67c239 100644
  6200. --- a/arch/mips/include/asm/pgtable.h
  6201. +++ b/arch/mips/include/asm/pgtable.h
  6202. @@ -20,6 +20,9 @@
  6203. #include <asm/io.h>
  6204. #include <asm/pgtable-bits.h>
  6205. +#define ktla_ktva(addr) (addr)
  6206. +#define ktva_ktla(addr) (addr)
  6207. +
  6208. struct mm_struct;
  6209. struct vm_area_struct;
  6210. diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
  6211. index 25da651..ae2a259 100644
  6212. --- a/arch/mips/include/asm/smtc_proc.h
  6213. +++ b/arch/mips/include/asm/smtc_proc.h
  6214. @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
  6215. /* Count of number of recoveries of "stolen" FPU access rights on 34K */
  6216. -extern atomic_t smtc_fpu_recoveries;
  6217. +extern atomic_unchecked_t smtc_fpu_recoveries;
  6218. #endif /* __ASM_SMTC_PROC_H */
  6219. diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
  6220. index 24846f9..61c49f0 100644
  6221. --- a/arch/mips/include/asm/thread_info.h
  6222. +++ b/arch/mips/include/asm/thread_info.h
  6223. @@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
  6224. #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
  6225. #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
  6226. #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
  6227. +/* li takes a 32bit immediate */
  6228. +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
  6229. #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
  6230. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  6231. @@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
  6232. #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
  6233. #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
  6234. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  6235. +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
  6236. #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
  6237. - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
  6238. + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
  6239. /* work to do in syscall_trace_leave() */
  6240. #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
  6241. - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
  6242. + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
  6243. /* work to do on interrupt/exception return */
  6244. #define _TIF_WORK_MASK \
  6245. @@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
  6246. /* work to do on any return to u-space */
  6247. #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
  6248. _TIF_WORK_SYSCALL_EXIT | \
  6249. - _TIF_SYSCALL_TRACEPOINT)
  6250. + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
  6251. /*
  6252. * We stash processor id into a COP0 register to retrieve it fast
  6253. diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
  6254. index f3fa375..3af6637 100644
  6255. --- a/arch/mips/include/asm/uaccess.h
  6256. +++ b/arch/mips/include/asm/uaccess.h
  6257. @@ -128,6 +128,7 @@ extern u64 __ua_limit;
  6258. __ok == 0; \
  6259. })
  6260. +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
  6261. #define access_ok(type, addr, size) \
  6262. likely(__access_ok((addr), (size), __access_mask))
  6263. diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
  6264. index 1188e00..41cf144 100644
  6265. --- a/arch/mips/kernel/binfmt_elfn32.c
  6266. +++ b/arch/mips/kernel/binfmt_elfn32.c
  6267. @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
  6268. #undef ELF_ET_DYN_BASE
  6269. #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
  6270. +#ifdef CONFIG_PAX_ASLR
  6271. +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
  6272. +
  6273. +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
  6274. +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
  6275. +#endif
  6276. +
  6277. #include <asm/processor.h>
  6278. #include <linux/module.h>
  6279. #include <linux/elfcore.h>
  6280. diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
  6281. index 7faf5f2..f3d3cf4 100644
  6282. --- a/arch/mips/kernel/binfmt_elfo32.c
  6283. +++ b/arch/mips/kernel/binfmt_elfo32.c
  6284. @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
  6285. #undef ELF_ET_DYN_BASE
  6286. #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
  6287. +#ifdef CONFIG_PAX_ASLR
  6288. +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
  6289. +
  6290. +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
  6291. +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
  6292. +#endif
  6293. +
  6294. #include <asm/processor.h>
  6295. /*
  6296. diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
  6297. index 2b91fe8..fe4f6b4 100644
  6298. --- a/arch/mips/kernel/i8259.c
  6299. +++ b/arch/mips/kernel/i8259.c
  6300. @@ -205,7 +205,7 @@ spurious_8259A_irq:
  6301. printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
  6302. spurious_irq_mask |= irqmask;
  6303. }
  6304. - atomic_inc(&irq_err_count);
  6305. + atomic_inc_unchecked(&irq_err_count);
  6306. /*
  6307. * Theoretically we do not have to handle this IRQ,
  6308. * but in Linux this does not cause problems and is
  6309. diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
  6310. index 44a1f79..2bd6aa3 100644
  6311. --- a/arch/mips/kernel/irq-gt641xx.c
  6312. +++ b/arch/mips/kernel/irq-gt641xx.c
  6313. @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
  6314. }
  6315. }
  6316. - atomic_inc(&irq_err_count);
  6317. + atomic_inc_unchecked(&irq_err_count);
  6318. }
  6319. void __init gt641xx_irq_init(void)
  6320. diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
  6321. index d1fea7a..2e591b0 100644
  6322. --- a/arch/mips/kernel/irq.c
  6323. +++ b/arch/mips/kernel/irq.c
  6324. @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
  6325. printk("unexpected IRQ # %d\n", irq);
  6326. }
  6327. -atomic_t irq_err_count;
  6328. +atomic_unchecked_t irq_err_count;
  6329. int arch_show_interrupts(struct seq_file *p, int prec)
  6330. {
  6331. - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  6332. + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
  6333. return 0;
  6334. }
  6335. asmlinkage void spurious_interrupt(void)
  6336. {
  6337. - atomic_inc(&irq_err_count);
  6338. + atomic_inc_unchecked(&irq_err_count);
  6339. }
  6340. void __init init_IRQ(void)
  6341. @@ -110,7 +110,10 @@ void __init init_IRQ(void)
  6342. #endif
  6343. }
  6344. +
  6345. #ifdef DEBUG_STACKOVERFLOW
  6346. +extern void gr_handle_kernel_exploit(void);
  6347. +
  6348. static inline void check_stack_overflow(void)
  6349. {
  6350. unsigned long sp;
  6351. @@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
  6352. printk("do_IRQ: stack overflow: %ld\n",
  6353. sp - sizeof(struct thread_info));
  6354. dump_stack();
  6355. + gr_handle_kernel_exploit();
  6356. }
  6357. }
  6358. #else
  6359. diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
  6360. index 6ae540e..b7396dc 100644
  6361. --- a/arch/mips/kernel/process.c
  6362. +++ b/arch/mips/kernel/process.c
  6363. @@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
  6364. out:
  6365. return pc;
  6366. }
  6367. -
  6368. -/*
  6369. - * Don't forget that the stack pointer must be aligned on a 8 bytes
  6370. - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
  6371. - */
  6372. -unsigned long arch_align_stack(unsigned long sp)
  6373. -{
  6374. - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  6375. - sp -= get_random_int() & ~PAGE_MASK;
  6376. -
  6377. - return sp & ALMASK;
  6378. -}
  6379. diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
  6380. index 7da9b76..21578be 100644
  6381. --- a/arch/mips/kernel/ptrace.c
  6382. +++ b/arch/mips/kernel/ptrace.c
  6383. @@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
  6384. return ret;
  6385. }
  6386. +#ifdef CONFIG_GRKERNSEC_SETXID
  6387. +extern void gr_delayed_cred_worker(void);
  6388. +#endif
  6389. +
  6390. /*
  6391. * Notification of system call entry/exit
  6392. * - triggered by current->work.syscall_trace
  6393. @@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
  6394. tracehook_report_syscall_entry(regs))
  6395. ret = -1;
  6396. +#ifdef CONFIG_GRKERNSEC_SETXID
  6397. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  6398. + gr_delayed_cred_worker();
  6399. +#endif
  6400. +
  6401. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  6402. trace_sys_enter(regs, regs->regs[2]);
  6403. diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
  6404. index 07fc524..b9d7f28 100644
  6405. --- a/arch/mips/kernel/reset.c
  6406. +++ b/arch/mips/kernel/reset.c
  6407. @@ -13,6 +13,7 @@
  6408. #include <linux/reboot.h>
  6409. #include <asm/reboot.h>
  6410. +#include <asm/bug.h>
  6411. /*
  6412. * Urgs ... Too many MIPS machines to handle this in a generic way.
  6413. @@ -29,16 +30,19 @@ void machine_restart(char *command)
  6414. {
  6415. if (_machine_restart)
  6416. _machine_restart(command);
  6417. + BUG();
  6418. }
  6419. void machine_halt(void)
  6420. {
  6421. if (_machine_halt)
  6422. _machine_halt();
  6423. + BUG();
  6424. }
  6425. void machine_power_off(void)
  6426. {
  6427. if (pm_power_off)
  6428. pm_power_off();
  6429. + BUG();
  6430. }
  6431. diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
  6432. index c10aa84..9ec2e60 100644
  6433. --- a/arch/mips/kernel/smtc-proc.c
  6434. +++ b/arch/mips/kernel/smtc-proc.c
  6435. @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
  6436. struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
  6437. -atomic_t smtc_fpu_recoveries;
  6438. +atomic_unchecked_t smtc_fpu_recoveries;
  6439. static int smtc_proc_show(struct seq_file *m, void *v)
  6440. {
  6441. @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
  6442. for(i = 0; i < NR_CPUS; i++)
  6443. seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
  6444. seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
  6445. - atomic_read(&smtc_fpu_recoveries));
  6446. + atomic_read_unchecked(&smtc_fpu_recoveries));
  6447. return 0;
  6448. }
  6449. @@ -73,7 +73,7 @@ void init_smtc_stats(void)
  6450. smtc_cpu_stats[i].selfipis = 0;
  6451. }
  6452. - atomic_set(&smtc_fpu_recoveries, 0);
  6453. + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
  6454. proc_create("smtc", 0444, NULL, &smtc_proc_fops);
  6455. }
  6456. diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
  6457. index dfc1b91..11a2c07 100644
  6458. --- a/arch/mips/kernel/smtc.c
  6459. +++ b/arch/mips/kernel/smtc.c
  6460. @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
  6461. }
  6462. smtc_ipi_qdump();
  6463. printk("%d Recoveries of \"stolen\" FPU\n",
  6464. - atomic_read(&smtc_fpu_recoveries));
  6465. + atomic_read_unchecked(&smtc_fpu_recoveries));
  6466. }
  6467. diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
  6468. index c24ad5f..9983ab2 100644
  6469. --- a/arch/mips/kernel/sync-r4k.c
  6470. +++ b/arch/mips/kernel/sync-r4k.c
  6471. @@ -20,8 +20,8 @@
  6472. #include <asm/mipsregs.h>
  6473. static atomic_t count_start_flag = ATOMIC_INIT(0);
  6474. -static atomic_t count_count_start = ATOMIC_INIT(0);
  6475. -static atomic_t count_count_stop = ATOMIC_INIT(0);
  6476. +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
  6477. +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
  6478. static atomic_t count_reference = ATOMIC_INIT(0);
  6479. #define COUNTON 100
  6480. @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
  6481. for (i = 0; i < NR_LOOPS; i++) {
  6482. /* slaves loop on '!= 2' */
  6483. - while (atomic_read(&count_count_start) != 1)
  6484. + while (atomic_read_unchecked(&count_count_start) != 1)
  6485. mb();
  6486. - atomic_set(&count_count_stop, 0);
  6487. + atomic_set_unchecked(&count_count_stop, 0);
  6488. smp_wmb();
  6489. /* this lets the slaves write their count register */
  6490. - atomic_inc(&count_count_start);
  6491. + atomic_inc_unchecked(&count_count_start);
  6492. /*
  6493. * Everyone initialises count in the last loop:
  6494. @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
  6495. /*
  6496. * Wait for all slaves to leave the synchronization point:
  6497. */
  6498. - while (atomic_read(&count_count_stop) != 1)
  6499. + while (atomic_read_unchecked(&count_count_stop) != 1)
  6500. mb();
  6501. - atomic_set(&count_count_start, 0);
  6502. + atomic_set_unchecked(&count_count_start, 0);
  6503. smp_wmb();
  6504. - atomic_inc(&count_count_stop);
  6505. + atomic_inc_unchecked(&count_count_stop);
  6506. }
  6507. /* Arrange for an interrupt in a short while */
  6508. write_c0_compare(read_c0_count() + COUNTON);
  6509. @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
  6510. initcount = atomic_read(&count_reference);
  6511. for (i = 0; i < NR_LOOPS; i++) {
  6512. - atomic_inc(&count_count_start);
  6513. - while (atomic_read(&count_count_start) != 2)
  6514. + atomic_inc_unchecked(&count_count_start);
  6515. + while (atomic_read_unchecked(&count_count_start) != 2)
  6516. mb();
  6517. /*
  6518. @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
  6519. if (i == NR_LOOPS-1)
  6520. write_c0_count(initcount);
  6521. - atomic_inc(&count_count_stop);
  6522. - while (atomic_read(&count_count_stop) != 2)
  6523. + atomic_inc_unchecked(&count_count_stop);
  6524. + while (atomic_read_unchecked(&count_count_stop) != 2)
  6525. mb();
  6526. }
  6527. /* Arrange for an interrupt in a short while */
  6528. diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
  6529. index e0b4996..6b43ce7 100644
  6530. --- a/arch/mips/kernel/traps.c
  6531. +++ b/arch/mips/kernel/traps.c
  6532. @@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
  6533. siginfo_t info;
  6534. prev_state = exception_enter();
  6535. - die_if_kernel("Integer overflow", regs);
  6536. + if (unlikely(!user_mode(regs))) {
  6537. +
  6538. +#ifdef CONFIG_PAX_REFCOUNT
  6539. + if (fixup_exception(regs)) {
  6540. + pax_report_refcount_overflow(regs);
  6541. + exception_exit(prev_state);
  6542. + return;
  6543. + }
  6544. +#endif
  6545. +
  6546. + die("Integer overflow", regs);
  6547. + }
  6548. info.si_code = FPE_INTOVF;
  6549. info.si_signo = SIGFPE;
  6550. diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
  6551. index becc42b..9e43d4b 100644
  6552. --- a/arch/mips/mm/fault.c
  6553. +++ b/arch/mips/mm/fault.c
  6554. @@ -28,6 +28,23 @@
  6555. #include <asm/highmem.h> /* For VMALLOC_END */
  6556. #include <linux/kdebug.h>
  6557. +#ifdef CONFIG_PAX_PAGEEXEC
  6558. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  6559. +{
  6560. + unsigned long i;
  6561. +
  6562. + printk(KERN_ERR "PAX: bytes at PC: ");
  6563. + for (i = 0; i < 5; i++) {
  6564. + unsigned int c;
  6565. + if (get_user(c, (unsigned int *)pc+i))
  6566. + printk(KERN_CONT "???????? ");
  6567. + else
  6568. + printk(KERN_CONT "%08x ", c);
  6569. + }
  6570. + printk("\n");
  6571. +}
  6572. +#endif
  6573. +
  6574. /*
  6575. * This routine handles page faults. It determines the address,
  6576. * and the problem, and then passes it off to one of the appropriate
  6577. @@ -199,6 +216,14 @@ bad_area:
  6578. bad_area_nosemaphore:
  6579. /* User mode accesses just cause a SIGSEGV */
  6580. if (user_mode(regs)) {
  6581. +
  6582. +#ifdef CONFIG_PAX_PAGEEXEC
  6583. + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
  6584. + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
  6585. + do_group_exit(SIGKILL);
  6586. + }
  6587. +#endif
  6588. +
  6589. tsk->thread.cp0_badvaddr = address;
  6590. tsk->thread.error_code = write;
  6591. #if 0
  6592. diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
  6593. index f1baadd..5472dca 100644
  6594. --- a/arch/mips/mm/mmap.c
  6595. +++ b/arch/mips/mm/mmap.c
  6596. @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
  6597. struct vm_area_struct *vma;
  6598. unsigned long addr = addr0;
  6599. int do_color_align;
  6600. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  6601. struct vm_unmapped_area_info info;
  6602. if (unlikely(len > TASK_SIZE))
  6603. @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
  6604. do_color_align = 1;
  6605. /* requesting a specific address */
  6606. +
  6607. +#ifdef CONFIG_PAX_RANDMMAP
  6608. + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
  6609. +#endif
  6610. +
  6611. if (addr) {
  6612. if (do_color_align)
  6613. addr = COLOUR_ALIGN(addr, pgoff);
  6614. @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
  6615. addr = PAGE_ALIGN(addr);
  6616. vma = find_vma(mm, addr);
  6617. - if (TASK_SIZE - len >= addr &&
  6618. - (!vma || addr + len <= vma->vm_start))
  6619. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  6620. return addr;
  6621. }
  6622. info.length = len;
  6623. info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
  6624. info.align_offset = pgoff << PAGE_SHIFT;
  6625. + info.threadstack_offset = offset;
  6626. if (dir == DOWN) {
  6627. info.flags = VM_UNMAPPED_AREA_TOPDOWN;
  6628. @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  6629. {
  6630. unsigned long random_factor = 0UL;
  6631. +#ifdef CONFIG_PAX_RANDMMAP
  6632. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  6633. +#endif
  6634. +
  6635. if (current->flags & PF_RANDOMIZE) {
  6636. random_factor = get_random_int();
  6637. random_factor = random_factor << PAGE_SHIFT;
  6638. @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  6639. if (mmap_is_legacy()) {
  6640. mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
  6641. +
  6642. +#ifdef CONFIG_PAX_RANDMMAP
  6643. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  6644. + mm->mmap_base += mm->delta_mmap;
  6645. +#endif
  6646. +
  6647. mm->get_unmapped_area = arch_get_unmapped_area;
  6648. } else {
  6649. mm->mmap_base = mmap_base(random_factor);
  6650. +
  6651. +#ifdef CONFIG_PAX_RANDMMAP
  6652. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  6653. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  6654. +#endif
  6655. +
  6656. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  6657. }
  6658. }
  6659. -static inline unsigned long brk_rnd(void)
  6660. -{
  6661. - unsigned long rnd = get_random_int();
  6662. -
  6663. - rnd = rnd << PAGE_SHIFT;
  6664. - /* 8MB for 32bit, 256MB for 64bit */
  6665. - if (TASK_IS_32BIT_ADDR)
  6666. - rnd = rnd & 0x7ffffful;
  6667. - else
  6668. - rnd = rnd & 0xffffffful;
  6669. -
  6670. - return rnd;
  6671. -}
  6672. -
  6673. -unsigned long arch_randomize_brk(struct mm_struct *mm)
  6674. -{
  6675. - unsigned long base = mm->brk;
  6676. - unsigned long ret;
  6677. -
  6678. - ret = PAGE_ALIGN(base + brk_rnd());
  6679. -
  6680. - if (ret < mm->brk)
  6681. - return mm->brk;
  6682. -
  6683. - return ret;
  6684. -}
  6685. -
  6686. int __virt_addr_valid(const volatile void *kaddr)
  6687. {
  6688. return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
  6689. diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
  6690. index 59cccd9..f39ac2f 100644
  6691. --- a/arch/mips/pci/pci-octeon.c
  6692. +++ b/arch/mips/pci/pci-octeon.c
  6693. @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
  6694. static struct pci_ops octeon_pci_ops = {
  6695. - octeon_read_config,
  6696. - octeon_write_config,
  6697. + .read = octeon_read_config,
  6698. + .write = octeon_write_config,
  6699. };
  6700. static struct resource octeon_pci_mem_resource = {
  6701. diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
  6702. index 5e36c33..eb4a17b 100644
  6703. --- a/arch/mips/pci/pcie-octeon.c
  6704. +++ b/arch/mips/pci/pcie-octeon.c
  6705. @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
  6706. }
  6707. static struct pci_ops octeon_pcie0_ops = {
  6708. - octeon_pcie0_read_config,
  6709. - octeon_pcie0_write_config,
  6710. + .read = octeon_pcie0_read_config,
  6711. + .write = octeon_pcie0_write_config,
  6712. };
  6713. static struct resource octeon_pcie0_mem_resource = {
  6714. @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
  6715. };
  6716. static struct pci_ops octeon_pcie1_ops = {
  6717. - octeon_pcie1_read_config,
  6718. - octeon_pcie1_write_config,
  6719. + .read = octeon_pcie1_read_config,
  6720. + .write = octeon_pcie1_write_config,
  6721. };
  6722. static struct resource octeon_pcie1_mem_resource = {
  6723. @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
  6724. };
  6725. static struct pci_ops octeon_dummy_ops = {
  6726. - octeon_dummy_read_config,
  6727. - octeon_dummy_write_config,
  6728. + .read = octeon_dummy_read_config,
  6729. + .write = octeon_dummy_write_config,
  6730. };
  6731. static struct resource octeon_dummy_mem_resource = {
  6732. diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
  6733. index a2358b4..7cead4f 100644
  6734. --- a/arch/mips/sgi-ip27/ip27-nmi.c
  6735. +++ b/arch/mips/sgi-ip27/ip27-nmi.c
  6736. @@ -187,9 +187,9 @@ void
  6737. cont_nmi_dump(void)
  6738. {
  6739. #ifndef REAL_NMI_SIGNAL
  6740. - static atomic_t nmied_cpus = ATOMIC_INIT(0);
  6741. + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
  6742. - atomic_inc(&nmied_cpus);
  6743. + atomic_inc_unchecked(&nmied_cpus);
  6744. #endif
  6745. /*
  6746. * Only allow 1 cpu to proceed
  6747. @@ -233,7 +233,7 @@ cont_nmi_dump(void)
  6748. udelay(10000);
  6749. }
  6750. #else
  6751. - while (atomic_read(&nmied_cpus) != num_online_cpus());
  6752. + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
  6753. #endif
  6754. /*
  6755. diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
  6756. index a046b30..6799527 100644
  6757. --- a/arch/mips/sni/rm200.c
  6758. +++ b/arch/mips/sni/rm200.c
  6759. @@ -270,7 +270,7 @@ spurious_8259A_irq:
  6760. "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
  6761. spurious_irq_mask |= irqmask;
  6762. }
  6763. - atomic_inc(&irq_err_count);
  6764. + atomic_inc_unchecked(&irq_err_count);
  6765. /*
  6766. * Theoretically we do not have to handle this IRQ,
  6767. * but in Linux this does not cause problems and is
  6768. diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
  6769. index 41e873b..34d33a7 100644
  6770. --- a/arch/mips/vr41xx/common/icu.c
  6771. +++ b/arch/mips/vr41xx/common/icu.c
  6772. @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
  6773. printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
  6774. - atomic_inc(&irq_err_count);
  6775. + atomic_inc_unchecked(&irq_err_count);
  6776. return -1;
  6777. }
  6778. diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
  6779. index ae0e4ee..e8f0692 100644
  6780. --- a/arch/mips/vr41xx/common/irq.c
  6781. +++ b/arch/mips/vr41xx/common/irq.c
  6782. @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
  6783. irq_cascade_t *cascade;
  6784. if (irq >= NR_IRQS) {
  6785. - atomic_inc(&irq_err_count);
  6786. + atomic_inc_unchecked(&irq_err_count);
  6787. return;
  6788. }
  6789. @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
  6790. ret = cascade->get_irq(irq);
  6791. irq = ret;
  6792. if (ret < 0)
  6793. - atomic_inc(&irq_err_count);
  6794. + atomic_inc_unchecked(&irq_err_count);
  6795. else
  6796. irq_dispatch(irq);
  6797. if (!irqd_irq_disabled(idata) && chip->irq_unmask)
  6798. diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
  6799. index 967d144..db12197 100644
  6800. --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
  6801. +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
  6802. @@ -11,12 +11,14 @@
  6803. #ifndef _ASM_PROC_CACHE_H
  6804. #define _ASM_PROC_CACHE_H
  6805. +#include <linux/const.h>
  6806. +
  6807. /* L1 cache */
  6808. #define L1_CACHE_NWAYS 4 /* number of ways in caches */
  6809. #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
  6810. -#define L1_CACHE_BYTES 16 /* bytes per entry */
  6811. #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
  6812. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
  6813. #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
  6814. #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
  6815. diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
  6816. index bcb5df2..84fabd2 100644
  6817. --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
  6818. +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
  6819. @@ -16,13 +16,15 @@
  6820. #ifndef _ASM_PROC_CACHE_H
  6821. #define _ASM_PROC_CACHE_H
  6822. +#include <linux/const.h>
  6823. +
  6824. /*
  6825. * L1 cache
  6826. */
  6827. #define L1_CACHE_NWAYS 4 /* number of ways in caches */
  6828. #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
  6829. -#define L1_CACHE_BYTES 32 /* bytes per entry */
  6830. #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
  6831. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
  6832. #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
  6833. #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
  6834. diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
  6835. index 4ce7a01..449202a 100644
  6836. --- a/arch/openrisc/include/asm/cache.h
  6837. +++ b/arch/openrisc/include/asm/cache.h
  6838. @@ -19,11 +19,13 @@
  6839. #ifndef __ASM_OPENRISC_CACHE_H
  6840. #define __ASM_OPENRISC_CACHE_H
  6841. +#include <linux/const.h>
  6842. +
  6843. /* FIXME: How can we replace these with values from the CPU...
  6844. * they shouldn't be hard-coded!
  6845. */
  6846. -#define L1_CACHE_BYTES 16
  6847. #define L1_CACHE_SHIFT 4
  6848. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  6849. #endif /* __ASM_OPENRISC_CACHE_H */
  6850. diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
  6851. index 472886c..00e7df9 100644
  6852. --- a/arch/parisc/include/asm/atomic.h
  6853. +++ b/arch/parisc/include/asm/atomic.h
  6854. @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
  6855. return dec;
  6856. }
  6857. +#define atomic64_read_unchecked(v) atomic64_read(v)
  6858. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  6859. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  6860. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  6861. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  6862. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  6863. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  6864. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  6865. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  6866. +
  6867. #endif /* !CONFIG_64BIT */
  6868. diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
  6869. index 47f11c7..3420df2 100644
  6870. --- a/arch/parisc/include/asm/cache.h
  6871. +++ b/arch/parisc/include/asm/cache.h
  6872. @@ -5,6 +5,7 @@
  6873. #ifndef __ARCH_PARISC_CACHE_H
  6874. #define __ARCH_PARISC_CACHE_H
  6875. +#include <linux/const.h>
  6876. /*
  6877. * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
  6878. @@ -15,13 +16,13 @@
  6879. * just ruin performance.
  6880. */
  6881. #ifdef CONFIG_PA20
  6882. -#define L1_CACHE_BYTES 64
  6883. #define L1_CACHE_SHIFT 6
  6884. #else
  6885. -#define L1_CACHE_BYTES 32
  6886. #define L1_CACHE_SHIFT 5
  6887. #endif
  6888. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  6889. +
  6890. #ifndef __ASSEMBLY__
  6891. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  6892. diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
  6893. index 3391d06..c23a2cc 100644
  6894. --- a/arch/parisc/include/asm/elf.h
  6895. +++ b/arch/parisc/include/asm/elf.h
  6896. @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
  6897. #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
  6898. +#ifdef CONFIG_PAX_ASLR
  6899. +#define PAX_ELF_ET_DYN_BASE 0x10000UL
  6900. +
  6901. +#define PAX_DELTA_MMAP_LEN 16
  6902. +#define PAX_DELTA_STACK_LEN 16
  6903. +#endif
  6904. +
  6905. /* This yields a mask that user programs can use to figure out what
  6906. instruction set this CPU supports. This could be done in user space,
  6907. but it's not easy, and we've already done it here. */
  6908. diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
  6909. index f213f5b..0af3e8e 100644
  6910. --- a/arch/parisc/include/asm/pgalloc.h
  6911. +++ b/arch/parisc/include/asm/pgalloc.h
  6912. @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
  6913. (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
  6914. }
  6915. +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
  6916. +{
  6917. + pgd_populate(mm, pgd, pmd);
  6918. +}
  6919. +
  6920. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  6921. {
  6922. pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
  6923. @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  6924. #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
  6925. #define pmd_free(mm, x) do { } while (0)
  6926. #define pgd_populate(mm, pmd, pte) BUG()
  6927. +#define pgd_populate_kernel(mm, pmd, pte) BUG()
  6928. #endif
  6929. diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
  6930. index 22b89d1..ce34230 100644
  6931. --- a/arch/parisc/include/asm/pgtable.h
  6932. +++ b/arch/parisc/include/asm/pgtable.h
  6933. @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
  6934. #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
  6935. #define PAGE_COPY PAGE_EXECREAD
  6936. #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
  6937. +
  6938. +#ifdef CONFIG_PAX_PAGEEXEC
  6939. +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
  6940. +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
  6941. +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
  6942. +#else
  6943. +# define PAGE_SHARED_NOEXEC PAGE_SHARED
  6944. +# define PAGE_COPY_NOEXEC PAGE_COPY
  6945. +# define PAGE_READONLY_NOEXEC PAGE_READONLY
  6946. +#endif
  6947. +
  6948. #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
  6949. #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
  6950. #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
  6951. diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
  6952. index 4006964..fcb3cc2 100644
  6953. --- a/arch/parisc/include/asm/uaccess.h
  6954. +++ b/arch/parisc/include/asm/uaccess.h
  6955. @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
  6956. const void __user *from,
  6957. unsigned long n)
  6958. {
  6959. - int sz = __compiletime_object_size(to);
  6960. + size_t sz = __compiletime_object_size(to);
  6961. int ret = -EFAULT;
  6962. - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
  6963. + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
  6964. ret = __copy_from_user(to, from, n);
  6965. else
  6966. copy_from_user_overflow();
  6967. diff --git a/arch/parisc/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
  6968. index 8b06343..090483c 100644
  6969. --- a/arch/parisc/include/uapi/asm/resource.h
  6970. +++ b/arch/parisc/include/uapi/asm/resource.h
  6971. @@ -1,7 +1,6 @@
  6972. #ifndef _ASM_PARISC_RESOURCE_H
  6973. #define _ASM_PARISC_RESOURCE_H
  6974. -#define _STK_LIM_MAX 10 * _STK_LIM
  6975. #include <asm-generic/resource.h>
  6976. #endif
  6977. diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
  6978. index 50dfafc..b9fc230 100644
  6979. --- a/arch/parisc/kernel/module.c
  6980. +++ b/arch/parisc/kernel/module.c
  6981. @@ -98,16 +98,38 @@
  6982. /* three functions to determine where in the module core
  6983. * or init pieces the location is */
  6984. +static inline int in_init_rx(struct module *me, void *loc)
  6985. +{
  6986. + return (loc >= me->module_init_rx &&
  6987. + loc < (me->module_init_rx + me->init_size_rx));
  6988. +}
  6989. +
  6990. +static inline int in_init_rw(struct module *me, void *loc)
  6991. +{
  6992. + return (loc >= me->module_init_rw &&
  6993. + loc < (me->module_init_rw + me->init_size_rw));
  6994. +}
  6995. +
  6996. static inline int in_init(struct module *me, void *loc)
  6997. {
  6998. - return (loc >= me->module_init &&
  6999. - loc <= (me->module_init + me->init_size));
  7000. + return in_init_rx(me, loc) || in_init_rw(me, loc);
  7001. +}
  7002. +
  7003. +static inline int in_core_rx(struct module *me, void *loc)
  7004. +{
  7005. + return (loc >= me->module_core_rx &&
  7006. + loc < (me->module_core_rx + me->core_size_rx));
  7007. +}
  7008. +
  7009. +static inline int in_core_rw(struct module *me, void *loc)
  7010. +{
  7011. + return (loc >= me->module_core_rw &&
  7012. + loc < (me->module_core_rw + me->core_size_rw));
  7013. }
  7014. static inline int in_core(struct module *me, void *loc)
  7015. {
  7016. - return (loc >= me->module_core &&
  7017. - loc <= (me->module_core + me->core_size));
  7018. + return in_core_rx(me, loc) || in_core_rw(me, loc);
  7019. }
  7020. static inline int in_local(struct module *me, void *loc)
  7021. @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
  7022. }
  7023. /* align things a bit */
  7024. - me->core_size = ALIGN(me->core_size, 16);
  7025. - me->arch.got_offset = me->core_size;
  7026. - me->core_size += gots * sizeof(struct got_entry);
  7027. + me->core_size_rw = ALIGN(me->core_size_rw, 16);
  7028. + me->arch.got_offset = me->core_size_rw;
  7029. + me->core_size_rw += gots * sizeof(struct got_entry);
  7030. - me->core_size = ALIGN(me->core_size, 16);
  7031. - me->arch.fdesc_offset = me->core_size;
  7032. - me->core_size += fdescs * sizeof(Elf_Fdesc);
  7033. + me->core_size_rw = ALIGN(me->core_size_rw, 16);
  7034. + me->arch.fdesc_offset = me->core_size_rw;
  7035. + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
  7036. me->arch.got_max = gots;
  7037. me->arch.fdesc_max = fdescs;
  7038. @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
  7039. BUG_ON(value == 0);
  7040. - got = me->module_core + me->arch.got_offset;
  7041. + got = me->module_core_rw + me->arch.got_offset;
  7042. for (i = 0; got[i].addr; i++)
  7043. if (got[i].addr == value)
  7044. goto out;
  7045. @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
  7046. #ifdef CONFIG_64BIT
  7047. static Elf_Addr get_fdesc(struct module *me, unsigned long value)
  7048. {
  7049. - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
  7050. + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
  7051. if (!value) {
  7052. printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
  7053. @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
  7054. /* Create new one */
  7055. fdesc->addr = value;
  7056. - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
  7057. + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
  7058. return (Elf_Addr)fdesc;
  7059. }
  7060. #endif /* CONFIG_64BIT */
  7061. @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
  7062. table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
  7063. end = table + sechdrs[me->arch.unwind_section].sh_size;
  7064. - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
  7065. + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
  7066. DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
  7067. me->arch.unwind_section, table, end, gp);
  7068. diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
  7069. index b7cadc4..bf4a32d 100644
  7070. --- a/arch/parisc/kernel/sys_parisc.c
  7071. +++ b/arch/parisc/kernel/sys_parisc.c
  7072. @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  7073. unsigned long task_size = TASK_SIZE;
  7074. int do_color_align, last_mmap;
  7075. struct vm_unmapped_area_info info;
  7076. + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
  7077. if (len > task_size)
  7078. return -ENOMEM;
  7079. @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  7080. goto found_addr;
  7081. }
  7082. +#ifdef CONFIG_PAX_RANDMMAP
  7083. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  7084. +#endif
  7085. +
  7086. if (addr) {
  7087. if (do_color_align && last_mmap)
  7088. addr = COLOR_ALIGN(addr, last_mmap, pgoff);
  7089. @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  7090. info.high_limit = mmap_upper_limit();
  7091. info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  7092. info.align_offset = shared_align_offset(last_mmap, pgoff);
  7093. + info.threadstack_offset = offset;
  7094. addr = vm_unmapped_area(&info);
  7095. found_addr:
  7096. @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  7097. unsigned long addr = addr0;
  7098. int do_color_align, last_mmap;
  7099. struct vm_unmapped_area_info info;
  7100. + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
  7101. #ifdef CONFIG_64BIT
  7102. /* This should only ever run for 32-bit processes. */
  7103. @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  7104. }
  7105. /* requesting a specific address */
  7106. +#ifdef CONFIG_PAX_RANDMMAP
  7107. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  7108. +#endif
  7109. +
  7110. if (addr) {
  7111. if (do_color_align && last_mmap)
  7112. addr = COLOR_ALIGN(addr, last_mmap, pgoff);
  7113. @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  7114. info.high_limit = mm->mmap_base;
  7115. info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  7116. info.align_offset = shared_align_offset(last_mmap, pgoff);
  7117. + info.threadstack_offset = offset;
  7118. addr = vm_unmapped_area(&info);
  7119. if (!(addr & ~PAGE_MASK))
  7120. goto found_addr;
  7121. @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  7122. mm->mmap_legacy_base = mmap_legacy_base();
  7123. mm->mmap_base = mmap_upper_limit();
  7124. +#ifdef CONFIG_PAX_RANDMMAP
  7125. + if (mm->pax_flags & MF_PAX_RANDMMAP) {
  7126. + mm->mmap_legacy_base += mm->delta_mmap;
  7127. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  7128. + }
  7129. +#endif
  7130. +
  7131. if (mmap_is_legacy()) {
  7132. mm->mmap_base = mm->mmap_legacy_base;
  7133. mm->get_unmapped_area = arch_get_unmapped_area;
  7134. diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
  7135. index 1cd1d0c..44ec918 100644
  7136. --- a/arch/parisc/kernel/traps.c
  7137. +++ b/arch/parisc/kernel/traps.c
  7138. @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
  7139. down_read(&current->mm->mmap_sem);
  7140. vma = find_vma(current->mm,regs->iaoq[0]);
  7141. - if (vma && (regs->iaoq[0] >= vma->vm_start)
  7142. - && (vma->vm_flags & VM_EXEC)) {
  7143. -
  7144. + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
  7145. fault_address = regs->iaoq[0];
  7146. fault_space = regs->iasq[0];
  7147. diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
  7148. index 9d08c71..e2b4d20 100644
  7149. --- a/arch/parisc/mm/fault.c
  7150. +++ b/arch/parisc/mm/fault.c
  7151. @@ -15,6 +15,7 @@
  7152. #include <linux/sched.h>
  7153. #include <linux/interrupt.h>
  7154. #include <linux/module.h>
  7155. +#include <linux/unistd.h>
  7156. #include <asm/uaccess.h>
  7157. #include <asm/traps.h>
  7158. @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
  7159. static unsigned long
  7160. parisc_acctyp(unsigned long code, unsigned int inst)
  7161. {
  7162. - if (code == 6 || code == 16)
  7163. + if (code == 6 || code == 7 || code == 16)
  7164. return VM_EXEC;
  7165. switch (inst & 0xf0000000) {
  7166. @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
  7167. }
  7168. #endif
  7169. +#ifdef CONFIG_PAX_PAGEEXEC
  7170. +/*
  7171. + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
  7172. + *
  7173. + * returns 1 when task should be killed
  7174. + * 2 when rt_sigreturn trampoline was detected
  7175. + * 3 when unpatched PLT trampoline was detected
  7176. + */
  7177. +static int pax_handle_fetch_fault(struct pt_regs *regs)
  7178. +{
  7179. +
  7180. +#ifdef CONFIG_PAX_EMUPLT
  7181. + int err;
  7182. +
  7183. + do { /* PaX: unpatched PLT emulation */
  7184. + unsigned int bl, depwi;
  7185. +
  7186. + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
  7187. + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
  7188. +
  7189. + if (err)
  7190. + break;
  7191. +
  7192. + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
  7193. + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
  7194. +
  7195. + err = get_user(ldw, (unsigned int *)addr);
  7196. + err |= get_user(bv, (unsigned int *)(addr+4));
  7197. + err |= get_user(ldw2, (unsigned int *)(addr+8));
  7198. +
  7199. + if (err)
  7200. + break;
  7201. +
  7202. + if (ldw == 0x0E801096U &&
  7203. + bv == 0xEAC0C000U &&
  7204. + ldw2 == 0x0E881095U)
  7205. + {
  7206. + unsigned int resolver, map;
  7207. +
  7208. + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
  7209. + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
  7210. + if (err)
  7211. + break;
  7212. +
  7213. + regs->gr[20] = instruction_pointer(regs)+8;
  7214. + regs->gr[21] = map;
  7215. + regs->gr[22] = resolver;
  7216. + regs->iaoq[0] = resolver | 3UL;
  7217. + regs->iaoq[1] = regs->iaoq[0] + 4;
  7218. + return 3;
  7219. + }
  7220. + }
  7221. + } while (0);
  7222. +#endif
  7223. +
  7224. +#ifdef CONFIG_PAX_EMUTRAMP
  7225. +
  7226. +#ifndef CONFIG_PAX_EMUSIGRT
  7227. + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
  7228. + return 1;
  7229. +#endif
  7230. +
  7231. + do { /* PaX: rt_sigreturn emulation */
  7232. + unsigned int ldi1, ldi2, bel, nop;
  7233. +
  7234. + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
  7235. + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
  7236. + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
  7237. + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
  7238. +
  7239. + if (err)
  7240. + break;
  7241. +
  7242. + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
  7243. + ldi2 == 0x3414015AU &&
  7244. + bel == 0xE4008200U &&
  7245. + nop == 0x08000240U)
  7246. + {
  7247. + regs->gr[25] = (ldi1 & 2) >> 1;
  7248. + regs->gr[20] = __NR_rt_sigreturn;
  7249. + regs->gr[31] = regs->iaoq[1] + 16;
  7250. + regs->sr[0] = regs->iasq[1];
  7251. + regs->iaoq[0] = 0x100UL;
  7252. + regs->iaoq[1] = regs->iaoq[0] + 4;
  7253. + regs->iasq[0] = regs->sr[2];
  7254. + regs->iasq[1] = regs->sr[2];
  7255. + return 2;
  7256. + }
  7257. + } while (0);
  7258. +#endif
  7259. +
  7260. + return 1;
  7261. +}
  7262. +
  7263. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  7264. +{
  7265. + unsigned long i;
  7266. +
  7267. + printk(KERN_ERR "PAX: bytes at PC: ");
  7268. + for (i = 0; i < 5; i++) {
  7269. + unsigned int c;
  7270. + if (get_user(c, (unsigned int *)pc+i))
  7271. + printk(KERN_CONT "???????? ");
  7272. + else
  7273. + printk(KERN_CONT "%08x ", c);
  7274. + }
  7275. + printk("\n");
  7276. +}
  7277. +#endif
  7278. +
  7279. int fixup_exception(struct pt_regs *regs)
  7280. {
  7281. const struct exception_table_entry *fix;
  7282. @@ -210,8 +321,33 @@ retry:
  7283. good_area:
  7284. - if ((vma->vm_flags & acc_type) != acc_type)
  7285. + if ((vma->vm_flags & acc_type) != acc_type) {
  7286. +
  7287. +#ifdef CONFIG_PAX_PAGEEXEC
  7288. + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
  7289. + (address & ~3UL) == instruction_pointer(regs))
  7290. + {
  7291. + up_read(&mm->mmap_sem);
  7292. + switch (pax_handle_fetch_fault(regs)) {
  7293. +
  7294. +#ifdef CONFIG_PAX_EMUPLT
  7295. + case 3:
  7296. + return;
  7297. +#endif
  7298. +
  7299. +#ifdef CONFIG_PAX_EMUTRAMP
  7300. + case 2:
  7301. + return;
  7302. +#endif
  7303. +
  7304. + }
  7305. + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
  7306. + do_group_exit(SIGKILL);
  7307. + }
  7308. +#endif
  7309. +
  7310. goto bad_area;
  7311. + }
  7312. /*
  7313. * If for any reason at all we couldn't handle the fault, make
  7314. diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
  7315. index 957bf34..3430cc8 100644
  7316. --- a/arch/powerpc/Kconfig
  7317. +++ b/arch/powerpc/Kconfig
  7318. @@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
  7319. config KEXEC
  7320. bool "kexec system call"
  7321. depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
  7322. + depends on !GRKERNSEC_KMEM
  7323. help
  7324. kexec is a system call that implements the ability to shutdown your
  7325. current kernel, and to start another kernel. It is like a reboot
  7326. diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
  7327. index e3b1d41..8e81edf 100644
  7328. --- a/arch/powerpc/include/asm/atomic.h
  7329. +++ b/arch/powerpc/include/asm/atomic.h
  7330. @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
  7331. return t1;
  7332. }
  7333. +#define atomic64_read_unchecked(v) atomic64_read(v)
  7334. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  7335. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  7336. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  7337. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  7338. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  7339. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  7340. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  7341. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  7342. +
  7343. #endif /* __powerpc64__ */
  7344. #endif /* __KERNEL__ */
  7345. diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
  7346. index ed0afc1..0332825 100644
  7347. --- a/arch/powerpc/include/asm/cache.h
  7348. +++ b/arch/powerpc/include/asm/cache.h
  7349. @@ -3,6 +3,7 @@
  7350. #ifdef __KERNEL__
  7351. +#include <linux/const.h>
  7352. /* bytes per L1 cache line */
  7353. #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
  7354. @@ -22,7 +23,7 @@
  7355. #define L1_CACHE_SHIFT 7
  7356. #endif
  7357. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  7358. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  7359. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  7360. diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
  7361. index 935b5e7..7001d2d 100644
  7362. --- a/arch/powerpc/include/asm/elf.h
  7363. +++ b/arch/powerpc/include/asm/elf.h
  7364. @@ -28,8 +28,19 @@
  7365. the loader. We need to make sure that it is out of the way of the program
  7366. that it will "exec", and that there is sufficient room for the brk. */
  7367. -extern unsigned long randomize_et_dyn(unsigned long base);
  7368. -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
  7369. +#define ELF_ET_DYN_BASE (0x20000000)
  7370. +
  7371. +#ifdef CONFIG_PAX_ASLR
  7372. +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
  7373. +
  7374. +#ifdef __powerpc64__
  7375. +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
  7376. +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
  7377. +#else
  7378. +#define PAX_DELTA_MMAP_LEN 15
  7379. +#define PAX_DELTA_STACK_LEN 15
  7380. +#endif
  7381. +#endif
  7382. #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
  7383. @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  7384. (0x7ff >> (PAGE_SHIFT - 12)) : \
  7385. (0x3ffff >> (PAGE_SHIFT - 12)))
  7386. -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
  7387. -#define arch_randomize_brk arch_randomize_brk
  7388. -
  7389. -
  7390. #ifdef CONFIG_SPU_BASE
  7391. /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
  7392. #define NT_SPU 1
  7393. diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
  7394. index 8196e9c..d83a9f3 100644
  7395. --- a/arch/powerpc/include/asm/exec.h
  7396. +++ b/arch/powerpc/include/asm/exec.h
  7397. @@ -4,6 +4,6 @@
  7398. #ifndef _ASM_POWERPC_EXEC_H
  7399. #define _ASM_POWERPC_EXEC_H
  7400. -extern unsigned long arch_align_stack(unsigned long sp);
  7401. +#define arch_align_stack(x) ((x) & ~0xfUL)
  7402. #endif /* _ASM_POWERPC_EXEC_H */
  7403. diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
  7404. index 5acabbd..7ea14fa 100644
  7405. --- a/arch/powerpc/include/asm/kmap_types.h
  7406. +++ b/arch/powerpc/include/asm/kmap_types.h
  7407. @@ -10,7 +10,7 @@
  7408. * 2 of the License, or (at your option) any later version.
  7409. */
  7410. -#define KM_TYPE_NR 16
  7411. +#define KM_TYPE_NR 17
  7412. #endif /* __KERNEL__ */
  7413. #endif /* _ASM_POWERPC_KMAP_TYPES_H */
  7414. diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
  7415. index b8da913..60b608a 100644
  7416. --- a/arch/powerpc/include/asm/local.h
  7417. +++ b/arch/powerpc/include/asm/local.h
  7418. @@ -9,15 +9,26 @@ typedef struct
  7419. atomic_long_t a;
  7420. } local_t;
  7421. +typedef struct
  7422. +{
  7423. + atomic_long_unchecked_t a;
  7424. +} local_unchecked_t;
  7425. +
  7426. #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
  7427. #define local_read(l) atomic_long_read(&(l)->a)
  7428. +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
  7429. #define local_set(l,i) atomic_long_set(&(l)->a, (i))
  7430. +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
  7431. #define local_add(i,l) atomic_long_add((i),(&(l)->a))
  7432. +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
  7433. #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
  7434. +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
  7435. #define local_inc(l) atomic_long_inc(&(l)->a)
  7436. +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
  7437. #define local_dec(l) atomic_long_dec(&(l)->a)
  7438. +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
  7439. static __inline__ long local_add_return(long a, local_t *l)
  7440. {
  7441. @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
  7442. return t;
  7443. }
  7444. +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
  7445. #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
  7446. @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
  7447. return t;
  7448. }
  7449. +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
  7450. static __inline__ long local_inc_return(local_t *l)
  7451. {
  7452. @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
  7453. #define local_cmpxchg(l, o, n) \
  7454. (cmpxchg_local(&((l)->a.counter), (o), (n)))
  7455. +#define local_cmpxchg_unchecked(l, o, n) \
  7456. + (cmpxchg_local(&((l)->a.counter), (o), (n)))
  7457. #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
  7458. /**
  7459. diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
  7460. index 8565c25..2865190 100644
  7461. --- a/arch/powerpc/include/asm/mman.h
  7462. +++ b/arch/powerpc/include/asm/mman.h
  7463. @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
  7464. }
  7465. #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
  7466. -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
  7467. +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
  7468. {
  7469. return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
  7470. }
  7471. diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
  7472. index 32e4e21..62afb12 100644
  7473. --- a/arch/powerpc/include/asm/page.h
  7474. +++ b/arch/powerpc/include/asm/page.h
  7475. @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
  7476. * and needs to be executable. This means the whole heap ends
  7477. * up being executable.
  7478. */
  7479. -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  7480. - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  7481. +#define VM_DATA_DEFAULT_FLAGS32 \
  7482. + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
  7483. + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  7484. #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  7485. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  7486. @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
  7487. #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
  7488. #endif
  7489. +#define ktla_ktva(addr) (addr)
  7490. +#define ktva_ktla(addr) (addr)
  7491. +
  7492. #ifndef CONFIG_PPC_BOOK3S_64
  7493. /*
  7494. * Use the top bit of the higher-level page table entries to indicate whether
  7495. diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
  7496. index 88693ce..ac6f9ab 100644
  7497. --- a/arch/powerpc/include/asm/page_64.h
  7498. +++ b/arch/powerpc/include/asm/page_64.h
  7499. @@ -153,15 +153,18 @@ do { \
  7500. * stack by default, so in the absence of a PT_GNU_STACK program header
  7501. * we turn execute permission off.
  7502. */
  7503. -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  7504. - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  7505. +#define VM_STACK_DEFAULT_FLAGS32 \
  7506. + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
  7507. + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  7508. #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  7509. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  7510. +#ifndef CONFIG_PAX_PAGEEXEC
  7511. #define VM_STACK_DEFAULT_FLAGS \
  7512. (is_32bit_task() ? \
  7513. VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
  7514. +#endif
  7515. #include <asm-generic/getorder.h>
  7516. diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
  7517. index 4b0be20..c15a27d 100644
  7518. --- a/arch/powerpc/include/asm/pgalloc-64.h
  7519. +++ b/arch/powerpc/include/asm/pgalloc-64.h
  7520. @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  7521. #ifndef CONFIG_PPC_64K_PAGES
  7522. #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
  7523. +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
  7524. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  7525. {
  7526. @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  7527. pud_set(pud, (unsigned long)pmd);
  7528. }
  7529. +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  7530. +{
  7531. + pud_populate(mm, pud, pmd);
  7532. +}
  7533. +
  7534. #define pmd_populate(mm, pmd, pte_page) \
  7535. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  7536. #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
  7537. @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
  7538. #endif
  7539. #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
  7540. +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
  7541. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  7542. pte_t *pte)
  7543. diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
  7544. index 3ebb188..e17dddf 100644
  7545. --- a/arch/powerpc/include/asm/pgtable.h
  7546. +++ b/arch/powerpc/include/asm/pgtable.h
  7547. @@ -2,6 +2,7 @@
  7548. #define _ASM_POWERPC_PGTABLE_H
  7549. #ifdef __KERNEL__
  7550. +#include <linux/const.h>
  7551. #ifndef __ASSEMBLY__
  7552. #include <linux/mmdebug.h>
  7553. #include <asm/processor.h> /* For TASK_SIZE */
  7554. diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
  7555. index 4aad413..85d86bf 100644
  7556. --- a/arch/powerpc/include/asm/pte-hash32.h
  7557. +++ b/arch/powerpc/include/asm/pte-hash32.h
  7558. @@ -21,6 +21,7 @@
  7559. #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
  7560. #define _PAGE_USER 0x004 /* usermode access allowed */
  7561. #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
  7562. +#define _PAGE_EXEC _PAGE_GUARDED
  7563. #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
  7564. #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
  7565. #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
  7566. diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
  7567. index ce17815..c5574cc 100644
  7568. --- a/arch/powerpc/include/asm/reg.h
  7569. +++ b/arch/powerpc/include/asm/reg.h
  7570. @@ -249,6 +249,7 @@
  7571. #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
  7572. #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
  7573. #define DSISR_NOHPTE 0x40000000 /* no translation found */
  7574. +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
  7575. #define DSISR_PROTFAULT 0x08000000 /* protection fault */
  7576. #define DSISR_ISSTORE 0x02000000 /* access was a store */
  7577. #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
  7578. diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
  7579. index 084e080..9415a3d 100644
  7580. --- a/arch/powerpc/include/asm/smp.h
  7581. +++ b/arch/powerpc/include/asm/smp.h
  7582. @@ -51,7 +51,7 @@ struct smp_ops_t {
  7583. int (*cpu_disable)(void);
  7584. void (*cpu_die)(unsigned int nr);
  7585. int (*cpu_bootable)(unsigned int nr);
  7586. -};
  7587. +} __no_const;
  7588. extern void smp_send_debugger_break(void);
  7589. extern void start_secondary_resume(void);
  7590. diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
  7591. index b034ecd..af7e31f 100644
  7592. --- a/arch/powerpc/include/asm/thread_info.h
  7593. +++ b/arch/powerpc/include/asm/thread_info.h
  7594. @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
  7595. #if defined(CONFIG_PPC64)
  7596. #define TIF_ELF2ABI 18 /* function descriptors must die! */
  7597. #endif
  7598. +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
  7599. +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
  7600. /* as above, but as bit values */
  7601. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  7602. @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
  7603. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  7604. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  7605. #define _TIF_NOHZ (1<<TIF_NOHZ)
  7606. +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
  7607. #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  7608. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
  7609. - _TIF_NOHZ)
  7610. + _TIF_NOHZ | _TIF_GRSEC_SETXID)
  7611. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  7612. _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  7613. diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
  7614. index 9485b43..3bd3c16 100644
  7615. --- a/arch/powerpc/include/asm/uaccess.h
  7616. +++ b/arch/powerpc/include/asm/uaccess.h
  7617. @@ -58,6 +58,7 @@
  7618. #endif
  7619. +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
  7620. #define access_ok(type, addr, size) \
  7621. (__chk_user_ptr(addr), \
  7622. __access_ok((__force unsigned long)(addr), (size), get_fs()))
  7623. @@ -318,52 +319,6 @@ do { \
  7624. extern unsigned long __copy_tofrom_user(void __user *to,
  7625. const void __user *from, unsigned long size);
  7626. -#ifndef __powerpc64__
  7627. -
  7628. -static inline unsigned long copy_from_user(void *to,
  7629. - const void __user *from, unsigned long n)
  7630. -{
  7631. - unsigned long over;
  7632. -
  7633. - if (access_ok(VERIFY_READ, from, n))
  7634. - return __copy_tofrom_user((__force void __user *)to, from, n);
  7635. - if ((unsigned long)from < TASK_SIZE) {
  7636. - over = (unsigned long)from + n - TASK_SIZE;
  7637. - return __copy_tofrom_user((__force void __user *)to, from,
  7638. - n - over) + over;
  7639. - }
  7640. - return n;
  7641. -}
  7642. -
  7643. -static inline unsigned long copy_to_user(void __user *to,
  7644. - const void *from, unsigned long n)
  7645. -{
  7646. - unsigned long over;
  7647. -
  7648. - if (access_ok(VERIFY_WRITE, to, n))
  7649. - return __copy_tofrom_user(to, (__force void __user *)from, n);
  7650. - if ((unsigned long)to < TASK_SIZE) {
  7651. - over = (unsigned long)to + n - TASK_SIZE;
  7652. - return __copy_tofrom_user(to, (__force void __user *)from,
  7653. - n - over) + over;
  7654. - }
  7655. - return n;
  7656. -}
  7657. -
  7658. -#else /* __powerpc64__ */
  7659. -
  7660. -#define __copy_in_user(to, from, size) \
  7661. - __copy_tofrom_user((to), (from), (size))
  7662. -
  7663. -extern unsigned long copy_from_user(void *to, const void __user *from,
  7664. - unsigned long n);
  7665. -extern unsigned long copy_to_user(void __user *to, const void *from,
  7666. - unsigned long n);
  7667. -extern unsigned long copy_in_user(void __user *to, const void __user *from,
  7668. - unsigned long n);
  7669. -
  7670. -#endif /* __powerpc64__ */
  7671. -
  7672. static inline unsigned long __copy_from_user_inatomic(void *to,
  7673. const void __user *from, unsigned long n)
  7674. {
  7675. @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
  7676. if (ret == 0)
  7677. return 0;
  7678. }
  7679. +
  7680. + if (!__builtin_constant_p(n))
  7681. + check_object_size(to, n, false);
  7682. +
  7683. return __copy_tofrom_user((__force void __user *)to, from, n);
  7684. }
  7685. @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
  7686. if (ret == 0)
  7687. return 0;
  7688. }
  7689. +
  7690. + if (!__builtin_constant_p(n))
  7691. + check_object_size(from, n, true);
  7692. +
  7693. return __copy_tofrom_user(to, (__force const void __user *)from, n);
  7694. }
  7695. @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
  7696. return __copy_to_user_inatomic(to, from, size);
  7697. }
  7698. +#ifndef __powerpc64__
  7699. +
  7700. +static inline unsigned long __must_check copy_from_user(void *to,
  7701. + const void __user *from, unsigned long n)
  7702. +{
  7703. + unsigned long over;
  7704. +
  7705. + if ((long)n < 0)
  7706. + return n;
  7707. +
  7708. + if (access_ok(VERIFY_READ, from, n)) {
  7709. + if (!__builtin_constant_p(n))
  7710. + check_object_size(to, n, false);
  7711. + return __copy_tofrom_user((__force void __user *)to, from, n);
  7712. + }
  7713. + if ((unsigned long)from < TASK_SIZE) {
  7714. + over = (unsigned long)from + n - TASK_SIZE;
  7715. + if (!__builtin_constant_p(n - over))
  7716. + check_object_size(to, n - over, false);
  7717. + return __copy_tofrom_user((__force void __user *)to, from,
  7718. + n - over) + over;
  7719. + }
  7720. + return n;
  7721. +}
  7722. +
  7723. +static inline unsigned long __must_check copy_to_user(void __user *to,
  7724. + const void *from, unsigned long n)
  7725. +{
  7726. + unsigned long over;
  7727. +
  7728. + if ((long)n < 0)
  7729. + return n;
  7730. +
  7731. + if (access_ok(VERIFY_WRITE, to, n)) {
  7732. + if (!__builtin_constant_p(n))
  7733. + check_object_size(from, n, true);
  7734. + return __copy_tofrom_user(to, (__force void __user *)from, n);
  7735. + }
  7736. + if ((unsigned long)to < TASK_SIZE) {
  7737. + over = (unsigned long)to + n - TASK_SIZE;
  7738. + if (!__builtin_constant_p(n))
  7739. + check_object_size(from, n - over, true);
  7740. + return __copy_tofrom_user(to, (__force void __user *)from,
  7741. + n - over) + over;
  7742. + }
  7743. + return n;
  7744. +}
  7745. +
  7746. +#else /* __powerpc64__ */
  7747. +
  7748. +#define __copy_in_user(to, from, size) \
  7749. + __copy_tofrom_user((to), (from), (size))
  7750. +
  7751. +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
  7752. +{
  7753. + if ((long)n < 0 || n > INT_MAX)
  7754. + return n;
  7755. +
  7756. + if (!__builtin_constant_p(n))
  7757. + check_object_size(to, n, false);
  7758. +
  7759. + if (likely(access_ok(VERIFY_READ, from, n)))
  7760. + n = __copy_from_user(to, from, n);
  7761. + else
  7762. + memset(to, 0, n);
  7763. + return n;
  7764. +}
  7765. +
  7766. +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
  7767. +{
  7768. + if ((long)n < 0 || n > INT_MAX)
  7769. + return n;
  7770. +
  7771. + if (likely(access_ok(VERIFY_WRITE, to, n))) {
  7772. + if (!__builtin_constant_p(n))
  7773. + check_object_size(from, n, true);
  7774. + n = __copy_to_user(to, from, n);
  7775. + }
  7776. + return n;
  7777. +}
  7778. +
  7779. +extern unsigned long copy_in_user(void __user *to, const void __user *from,
  7780. + unsigned long n);
  7781. +
  7782. +#endif /* __powerpc64__ */
  7783. +
  7784. extern unsigned long __clear_user(void __user *addr, unsigned long size);
  7785. static inline unsigned long clear_user(void __user *addr, unsigned long size)
  7786. diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
  7787. index fcc9a89..07be2bb 100644
  7788. --- a/arch/powerpc/kernel/Makefile
  7789. +++ b/arch/powerpc/kernel/Makefile
  7790. @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
  7791. CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
  7792. endif
  7793. +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
  7794. +
  7795. obj-y := cputable.o ptrace.o syscalls.o \
  7796. irq.o align.o signal_32.o pmc.o vdso.o \
  7797. process.o systbl.o idle.o \
  7798. diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
  7799. index 063b65d..7a26e9d 100644
  7800. --- a/arch/powerpc/kernel/exceptions-64e.S
  7801. +++ b/arch/powerpc/kernel/exceptions-64e.S
  7802. @@ -771,6 +771,7 @@ storage_fault_common:
  7803. std r14,_DAR(r1)
  7804. std r15,_DSISR(r1)
  7805. addi r3,r1,STACK_FRAME_OVERHEAD
  7806. + bl .save_nvgprs
  7807. mr r4,r14
  7808. mr r5,r15
  7809. ld r14,PACA_EXGEN+EX_R14(r13)
  7810. @@ -779,8 +780,7 @@ storage_fault_common:
  7811. cmpdi r3,0
  7812. bne- 1f
  7813. b .ret_from_except_lite
  7814. -1: bl .save_nvgprs
  7815. - mr r5,r3
  7816. +1: mr r5,r3
  7817. addi r3,r1,STACK_FRAME_OVERHEAD
  7818. ld r4,_DAR(r1)
  7819. bl .bad_page_fault
  7820. diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
  7821. index 38d5073..f00af8d 100644
  7822. --- a/arch/powerpc/kernel/exceptions-64s.S
  7823. +++ b/arch/powerpc/kernel/exceptions-64s.S
  7824. @@ -1584,10 +1584,10 @@ handle_page_fault:
  7825. 11: ld r4,_DAR(r1)
  7826. ld r5,_DSISR(r1)
  7827. addi r3,r1,STACK_FRAME_OVERHEAD
  7828. + bl .save_nvgprs
  7829. bl .do_page_fault
  7830. cmpdi r3,0
  7831. beq+ 12f
  7832. - bl .save_nvgprs
  7833. mr r5,r3
  7834. addi r3,r1,STACK_FRAME_OVERHEAD
  7835. lwz r4,_DAR(r1)
  7836. diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
  7837. index 1d0848b..d74685f 100644
  7838. --- a/arch/powerpc/kernel/irq.c
  7839. +++ b/arch/powerpc/kernel/irq.c
  7840. @@ -447,6 +447,8 @@ void migrate_irqs(void)
  7841. }
  7842. #endif
  7843. +extern void gr_handle_kernel_exploit(void);
  7844. +
  7845. static inline void check_stack_overflow(void)
  7846. {
  7847. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  7848. @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
  7849. printk("do_IRQ: stack overflow: %ld\n",
  7850. sp - sizeof(struct thread_info));
  7851. dump_stack();
  7852. + gr_handle_kernel_exploit();
  7853. }
  7854. #endif
  7855. }
  7856. diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
  7857. index 6cff040..74ac5d1 100644
  7858. --- a/arch/powerpc/kernel/module_32.c
  7859. +++ b/arch/powerpc/kernel/module_32.c
  7860. @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
  7861. me->arch.core_plt_section = i;
  7862. }
  7863. if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
  7864. - printk("Module doesn't contain .plt or .init.plt sections.\n");
  7865. + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
  7866. return -ENOEXEC;
  7867. }
  7868. @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
  7869. DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
  7870. /* Init, or core PLT? */
  7871. - if (location >= mod->module_core
  7872. - && location < mod->module_core + mod->core_size)
  7873. + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
  7874. + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
  7875. entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
  7876. - else
  7877. + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
  7878. + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
  7879. entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
  7880. + else {
  7881. + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
  7882. + return ~0UL;
  7883. + }
  7884. /* Find this entry, or if that fails, the next avail. entry */
  7885. while (entry->jump[0]) {
  7886. @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
  7887. }
  7888. #ifdef CONFIG_DYNAMIC_FTRACE
  7889. module->arch.tramp =
  7890. - do_plt_call(module->module_core,
  7891. + do_plt_call(module->module_core_rx,
  7892. (unsigned long)ftrace_caller,
  7893. sechdrs, module);
  7894. #endif
  7895. diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
  7896. index 31d0215..206af70 100644
  7897. --- a/arch/powerpc/kernel/process.c
  7898. +++ b/arch/powerpc/kernel/process.c
  7899. @@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
  7900. * Lookup NIP late so we have the best change of getting the
  7901. * above info out without failing
  7902. */
  7903. - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
  7904. - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
  7905. + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
  7906. + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
  7907. #endif
  7908. show_stack(current, (unsigned long *) regs->gpr[1]);
  7909. if (!user_mode(regs))
  7910. @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
  7911. newsp = stack[0];
  7912. ip = stack[STACK_FRAME_LR_SAVE];
  7913. if (!firstframe || ip != lr) {
  7914. - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
  7915. + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
  7916. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  7917. if ((ip == rth || ip == mrth) && curr_frame >= 0) {
  7918. - printk(" (%pS)",
  7919. + printk(" (%pA)",
  7920. (void *)current->ret_stack[curr_frame].ret);
  7921. curr_frame--;
  7922. }
  7923. @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
  7924. struct pt_regs *regs = (struct pt_regs *)
  7925. (sp + STACK_FRAME_OVERHEAD);
  7926. lr = regs->link;
  7927. - printk("--- Exception: %lx at %pS\n LR = %pS\n",
  7928. + printk("--- Exception: %lx at %pA\n LR = %pA\n",
  7929. regs->trap, (void *)regs->nip, (void *)lr);
  7930. firstframe = 1;
  7931. }
  7932. @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
  7933. mtspr(SPRN_CTRLT, ctrl);
  7934. }
  7935. #endif /* CONFIG_PPC64 */
  7936. -
  7937. -unsigned long arch_align_stack(unsigned long sp)
  7938. -{
  7939. - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  7940. - sp -= get_random_int() & ~PAGE_MASK;
  7941. - return sp & ~0xf;
  7942. -}
  7943. -
  7944. -static inline unsigned long brk_rnd(void)
  7945. -{
  7946. - unsigned long rnd = 0;
  7947. -
  7948. - /* 8MB for 32bit, 1GB for 64bit */
  7949. - if (is_32bit_task())
  7950. - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
  7951. - else
  7952. - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
  7953. -
  7954. - return rnd << PAGE_SHIFT;
  7955. -}
  7956. -
  7957. -unsigned long arch_randomize_brk(struct mm_struct *mm)
  7958. -{
  7959. - unsigned long base = mm->brk;
  7960. - unsigned long ret;
  7961. -
  7962. -#ifdef CONFIG_PPC_STD_MMU_64
  7963. - /*
  7964. - * If we are using 1TB segments and we are allowed to randomise
  7965. - * the heap, we can put it above 1TB so it is backed by a 1TB
  7966. - * segment. Otherwise the heap will be in the bottom 1TB
  7967. - * which always uses 256MB segments and this may result in a
  7968. - * performance penalty.
  7969. - */
  7970. - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
  7971. - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
  7972. -#endif
  7973. -
  7974. - ret = PAGE_ALIGN(base + brk_rnd());
  7975. -
  7976. - if (ret < mm->brk)
  7977. - return mm->brk;
  7978. -
  7979. - return ret;
  7980. -}
  7981. -
  7982. -unsigned long randomize_et_dyn(unsigned long base)
  7983. -{
  7984. - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
  7985. -
  7986. - if (ret < base)
  7987. - return base;
  7988. -
  7989. - return ret;
  7990. -}
  7991. diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
  7992. index 2e3d2bf..35df241 100644
  7993. --- a/arch/powerpc/kernel/ptrace.c
  7994. +++ b/arch/powerpc/kernel/ptrace.c
  7995. @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
  7996. return ret;
  7997. }
  7998. +#ifdef CONFIG_GRKERNSEC_SETXID
  7999. +extern void gr_delayed_cred_worker(void);
  8000. +#endif
  8001. +
  8002. /*
  8003. * We must return the syscall number to actually look up in the table.
  8004. * This can be -1L to skip running any syscall at all.
  8005. @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
  8006. secure_computing_strict(regs->gpr[0]);
  8007. +#ifdef CONFIG_GRKERNSEC_SETXID
  8008. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  8009. + gr_delayed_cred_worker();
  8010. +#endif
  8011. +
  8012. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  8013. tracehook_report_syscall_entry(regs))
  8014. /*
  8015. @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
  8016. {
  8017. int step;
  8018. +#ifdef CONFIG_GRKERNSEC_SETXID
  8019. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  8020. + gr_delayed_cred_worker();
  8021. +#endif
  8022. +
  8023. audit_syscall_exit(regs);
  8024. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  8025. diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
  8026. index 4e47db6..6dcc96e 100644
  8027. --- a/arch/powerpc/kernel/signal_32.c
  8028. +++ b/arch/powerpc/kernel/signal_32.c
  8029. @@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
  8030. /* Save user registers on the stack */
  8031. frame = &rt_sf->uc.uc_mcontext;
  8032. addr = frame;
  8033. - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
  8034. + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
  8035. sigret = 0;
  8036. tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
  8037. } else {
  8038. diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
  8039. index d501dc4..e5a0de0 100644
  8040. --- a/arch/powerpc/kernel/signal_64.c
  8041. +++ b/arch/powerpc/kernel/signal_64.c
  8042. @@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
  8043. current->thread.fp_state.fpscr = 0;
  8044. /* Set up to return from userspace. */
  8045. - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
  8046. + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
  8047. regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
  8048. } else {
  8049. err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
  8050. diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
  8051. index 33cd7a0..d615344 100644
  8052. --- a/arch/powerpc/kernel/traps.c
  8053. +++ b/arch/powerpc/kernel/traps.c
  8054. @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
  8055. return flags;
  8056. }
  8057. +extern void gr_handle_kernel_exploit(void);
  8058. +
  8059. static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
  8060. int signr)
  8061. {
  8062. @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
  8063. panic("Fatal exception in interrupt");
  8064. if (panic_on_oops)
  8065. panic("Fatal exception");
  8066. +
  8067. + gr_handle_kernel_exploit();
  8068. +
  8069. do_exit(signr);
  8070. }
  8071. diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
  8072. index 094e45c..d82b848 100644
  8073. --- a/arch/powerpc/kernel/vdso.c
  8074. +++ b/arch/powerpc/kernel/vdso.c
  8075. @@ -35,6 +35,7 @@
  8076. #include <asm/vdso.h>
  8077. #include <asm/vdso_datapage.h>
  8078. #include <asm/setup.h>
  8079. +#include <asm/mman.h>
  8080. #undef DEBUG
  8081. @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  8082. vdso_base = VDSO32_MBASE;
  8083. #endif
  8084. - current->mm->context.vdso_base = 0;
  8085. + current->mm->context.vdso_base = ~0UL;
  8086. /* vDSO has a problem and was disabled, just don't "enable" it for the
  8087. * process
  8088. @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  8089. vdso_base = get_unmapped_area(NULL, vdso_base,
  8090. (vdso_pages << PAGE_SHIFT) +
  8091. ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
  8092. - 0, 0);
  8093. + 0, MAP_PRIVATE | MAP_EXECUTABLE);
  8094. if (IS_ERR_VALUE(vdso_base)) {
  8095. rc = vdso_base;
  8096. goto fail_mmapsem;
  8097. diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
  8098. index 3cf541a..ab2d825 100644
  8099. --- a/arch/powerpc/kvm/powerpc.c
  8100. +++ b/arch/powerpc/kvm/powerpc.c
  8101. @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
  8102. }
  8103. EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
  8104. -int kvm_arch_init(void *opaque)
  8105. +int kvm_arch_init(const void *opaque)
  8106. {
  8107. return 0;
  8108. }
  8109. diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
  8110. index 5eea6f3..5d10396 100644
  8111. --- a/arch/powerpc/lib/usercopy_64.c
  8112. +++ b/arch/powerpc/lib/usercopy_64.c
  8113. @@ -9,22 +9,6 @@
  8114. #include <linux/module.h>
  8115. #include <asm/uaccess.h>
  8116. -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
  8117. -{
  8118. - if (likely(access_ok(VERIFY_READ, from, n)))
  8119. - n = __copy_from_user(to, from, n);
  8120. - else
  8121. - memset(to, 0, n);
  8122. - return n;
  8123. -}
  8124. -
  8125. -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
  8126. -{
  8127. - if (likely(access_ok(VERIFY_WRITE, to, n)))
  8128. - n = __copy_to_user(to, from, n);
  8129. - return n;
  8130. -}
  8131. -
  8132. unsigned long copy_in_user(void __user *to, const void __user *from,
  8133. unsigned long n)
  8134. {
  8135. @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
  8136. return n;
  8137. }
  8138. -EXPORT_SYMBOL(copy_from_user);
  8139. -EXPORT_SYMBOL(copy_to_user);
  8140. EXPORT_SYMBOL(copy_in_user);
  8141. diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
  8142. index 51ab9e7..7d3c78b 100644
  8143. --- a/arch/powerpc/mm/fault.c
  8144. +++ b/arch/powerpc/mm/fault.c
  8145. @@ -33,6 +33,10 @@
  8146. #include <linux/magic.h>
  8147. #include <linux/ratelimit.h>
  8148. #include <linux/context_tracking.h>
  8149. +#include <linux/slab.h>
  8150. +#include <linux/pagemap.h>
  8151. +#include <linux/compiler.h>
  8152. +#include <linux/unistd.h>
  8153. #include <asm/firmware.h>
  8154. #include <asm/page.h>
  8155. @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
  8156. }
  8157. #endif
  8158. +#ifdef CONFIG_PAX_PAGEEXEC
  8159. +/*
  8160. + * PaX: decide what to do with offenders (regs->nip = fault address)
  8161. + *
  8162. + * returns 1 when task should be killed
  8163. + */
  8164. +static int pax_handle_fetch_fault(struct pt_regs *regs)
  8165. +{
  8166. + return 1;
  8167. +}
  8168. +
  8169. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  8170. +{
  8171. + unsigned long i;
  8172. +
  8173. + printk(KERN_ERR "PAX: bytes at PC: ");
  8174. + for (i = 0; i < 5; i++) {
  8175. + unsigned int c;
  8176. + if (get_user(c, (unsigned int __user *)pc+i))
  8177. + printk(KERN_CONT "???????? ");
  8178. + else
  8179. + printk(KERN_CONT "%08x ", c);
  8180. + }
  8181. + printk("\n");
  8182. +}
  8183. +#endif
  8184. +
  8185. /*
  8186. * Check whether the instruction at regs->nip is a store using
  8187. * an update addressing form which will update r1.
  8188. @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
  8189. * indicate errors in DSISR but can validly be set in SRR1.
  8190. */
  8191. if (trap == 0x400)
  8192. - error_code &= 0x48200000;
  8193. + error_code &= 0x58200000;
  8194. else
  8195. is_write = error_code & DSISR_ISSTORE;
  8196. #else
  8197. @@ -378,7 +409,7 @@ good_area:
  8198. * "undefined". Of those that can be set, this is the only
  8199. * one which seems bad.
  8200. */
  8201. - if (error_code & 0x10000000)
  8202. + if (error_code & DSISR_GUARDED)
  8203. /* Guarded storage error. */
  8204. goto bad_area;
  8205. #endif /* CONFIG_8xx */
  8206. @@ -393,7 +424,7 @@ good_area:
  8207. * processors use the same I/D cache coherency mechanism
  8208. * as embedded.
  8209. */
  8210. - if (error_code & DSISR_PROTFAULT)
  8211. + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
  8212. goto bad_area;
  8213. #endif /* CONFIG_PPC_STD_MMU */
  8214. @@ -483,6 +514,23 @@ bad_area:
  8215. bad_area_nosemaphore:
  8216. /* User mode accesses cause a SIGSEGV */
  8217. if (user_mode(regs)) {
  8218. +
  8219. +#ifdef CONFIG_PAX_PAGEEXEC
  8220. + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
  8221. +#ifdef CONFIG_PPC_STD_MMU
  8222. + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
  8223. +#else
  8224. + if (is_exec && regs->nip == address) {
  8225. +#endif
  8226. + switch (pax_handle_fetch_fault(regs)) {
  8227. + }
  8228. +
  8229. + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
  8230. + do_group_exit(SIGKILL);
  8231. + }
  8232. + }
  8233. +#endif
  8234. +
  8235. _exception(SIGSEGV, regs, code, address);
  8236. goto bail;
  8237. }
  8238. diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
  8239. index cb8bdbe..cde4bc7 100644
  8240. --- a/arch/powerpc/mm/mmap.c
  8241. +++ b/arch/powerpc/mm/mmap.c
  8242. @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
  8243. return sysctl_legacy_va_layout;
  8244. }
  8245. -static unsigned long mmap_rnd(void)
  8246. +static unsigned long mmap_rnd(struct mm_struct *mm)
  8247. {
  8248. unsigned long rnd = 0;
  8249. +#ifdef CONFIG_PAX_RANDMMAP
  8250. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  8251. +#endif
  8252. +
  8253. if (current->flags & PF_RANDOMIZE) {
  8254. /* 8MB for 32bit, 1GB for 64bit */
  8255. if (is_32bit_task())
  8256. @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
  8257. return rnd << PAGE_SHIFT;
  8258. }
  8259. -static inline unsigned long mmap_base(void)
  8260. +static inline unsigned long mmap_base(struct mm_struct *mm)
  8261. {
  8262. unsigned long gap = rlimit(RLIMIT_STACK);
  8263. @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
  8264. else if (gap > MAX_GAP)
  8265. gap = MAX_GAP;
  8266. - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
  8267. + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
  8268. }
  8269. /*
  8270. @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  8271. */
  8272. if (mmap_is_legacy()) {
  8273. mm->mmap_base = TASK_UNMAPPED_BASE;
  8274. +
  8275. +#ifdef CONFIG_PAX_RANDMMAP
  8276. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8277. + mm->mmap_base += mm->delta_mmap;
  8278. +#endif
  8279. +
  8280. mm->get_unmapped_area = arch_get_unmapped_area;
  8281. } else {
  8282. - mm->mmap_base = mmap_base();
  8283. + mm->mmap_base = mmap_base(mm);
  8284. +
  8285. +#ifdef CONFIG_PAX_RANDMMAP
  8286. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8287. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  8288. +#endif
  8289. +
  8290. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  8291. }
  8292. }
  8293. diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
  8294. index b0c75cc..ef7fb93 100644
  8295. --- a/arch/powerpc/mm/slice.c
  8296. +++ b/arch/powerpc/mm/slice.c
  8297. @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
  8298. if ((mm->task_size - len) < addr)
  8299. return 0;
  8300. vma = find_vma(mm, addr);
  8301. - return (!vma || (addr + len) <= vma->vm_start);
  8302. + return check_heap_stack_gap(vma, addr, len, 0);
  8303. }
  8304. static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
  8305. @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
  8306. info.align_offset = 0;
  8307. addr = TASK_UNMAPPED_BASE;
  8308. +
  8309. +#ifdef CONFIG_PAX_RANDMMAP
  8310. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8311. + addr += mm->delta_mmap;
  8312. +#endif
  8313. +
  8314. while (addr < TASK_SIZE) {
  8315. info.low_limit = addr;
  8316. if (!slice_scan_available(addr, available, 1, &addr))
  8317. @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
  8318. if (fixed && addr > (mm->task_size - len))
  8319. return -ENOMEM;
  8320. +#ifdef CONFIG_PAX_RANDMMAP
  8321. + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
  8322. + addr = 0;
  8323. +#endif
  8324. +
  8325. /* If hint, make sure it matches our alignment restrictions */
  8326. if (!fixed && addr) {
  8327. addr = _ALIGN_UP(addr, 1ul << pshift);
  8328. diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
  8329. index 4278acf..67fd0e6 100644
  8330. --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
  8331. +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
  8332. @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
  8333. }
  8334. static struct pci_ops scc_pciex_pci_ops = {
  8335. - scc_pciex_read_config,
  8336. - scc_pciex_write_config,
  8337. + .read = scc_pciex_read_config,
  8338. + .write = scc_pciex_write_config,
  8339. };
  8340. static void pciex_clear_intr_all(unsigned int __iomem *base)
  8341. diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
  8342. index 9098692..3d54cd1 100644
  8343. --- a/arch/powerpc/platforms/cell/spufs/file.c
  8344. +++ b/arch/powerpc/platforms/cell/spufs/file.c
  8345. @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  8346. return VM_FAULT_NOPAGE;
  8347. }
  8348. -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
  8349. +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
  8350. unsigned long address,
  8351. - void *buf, int len, int write)
  8352. + void *buf, size_t len, int write)
  8353. {
  8354. struct spu_context *ctx = vma->vm_file->private_data;
  8355. unsigned long offset = address - vma->vm_start;
  8356. diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
  8357. index 1d47061..0714963 100644
  8358. --- a/arch/s390/include/asm/atomic.h
  8359. +++ b/arch/s390/include/asm/atomic.h
  8360. @@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
  8361. #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
  8362. #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
  8363. +#define atomic64_read_unchecked(v) atomic64_read(v)
  8364. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  8365. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  8366. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  8367. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  8368. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  8369. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  8370. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  8371. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  8372. +
  8373. #define smp_mb__before_atomic_dec() smp_mb()
  8374. #define smp_mb__after_atomic_dec() smp_mb()
  8375. #define smp_mb__before_atomic_inc() smp_mb()
  8376. diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
  8377. index 4d7ccac..d03d0ad 100644
  8378. --- a/arch/s390/include/asm/cache.h
  8379. +++ b/arch/s390/include/asm/cache.h
  8380. @@ -9,8 +9,10 @@
  8381. #ifndef __ARCH_S390_CACHE_H
  8382. #define __ARCH_S390_CACHE_H
  8383. -#define L1_CACHE_BYTES 256
  8384. +#include <linux/const.h>
  8385. +
  8386. #define L1_CACHE_SHIFT 8
  8387. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  8388. #define NET_SKB_PAD 32
  8389. #define __read_mostly __attribute__((__section__(".data..read_mostly")))
  8390. diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
  8391. index 78f4f87..598ce39 100644
  8392. --- a/arch/s390/include/asm/elf.h
  8393. +++ b/arch/s390/include/asm/elf.h
  8394. @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
  8395. the loader. We need to make sure that it is out of the way of the program
  8396. that it will "exec", and that there is sufficient room for the brk. */
  8397. -extern unsigned long randomize_et_dyn(unsigned long base);
  8398. -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
  8399. +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
  8400. +
  8401. +#ifdef CONFIG_PAX_ASLR
  8402. +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
  8403. +
  8404. +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
  8405. +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
  8406. +#endif
  8407. /* This yields a mask that user programs can use to figure out what
  8408. instruction set this CPU supports. */
  8409. @@ -222,9 +228,6 @@ struct linux_binprm;
  8410. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
  8411. int arch_setup_additional_pages(struct linux_binprm *, int);
  8412. -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
  8413. -#define arch_randomize_brk arch_randomize_brk
  8414. -
  8415. void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
  8416. #endif
  8417. diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
  8418. index c4a93d6..4d2a9b4 100644
  8419. --- a/arch/s390/include/asm/exec.h
  8420. +++ b/arch/s390/include/asm/exec.h
  8421. @@ -7,6 +7,6 @@
  8422. #ifndef __ASM_EXEC_H
  8423. #define __ASM_EXEC_H
  8424. -extern unsigned long arch_align_stack(unsigned long sp);
  8425. +#define arch_align_stack(x) ((x) & ~0xfUL)
  8426. #endif /* __ASM_EXEC_H */
  8427. diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
  8428. index 79330af..254cf37 100644
  8429. --- a/arch/s390/include/asm/uaccess.h
  8430. +++ b/arch/s390/include/asm/uaccess.h
  8431. @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
  8432. __range_ok((unsigned long)(addr), (size)); \
  8433. })
  8434. +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
  8435. #define access_ok(type, addr, size) __access_ok(addr, size)
  8436. /*
  8437. @@ -245,6 +246,10 @@ static inline unsigned long __must_check
  8438. copy_to_user(void __user *to, const void *from, unsigned long n)
  8439. {
  8440. might_fault();
  8441. +
  8442. + if ((long)n < 0)
  8443. + return n;
  8444. +
  8445. return __copy_to_user(to, from, n);
  8446. }
  8447. @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
  8448. static inline unsigned long __must_check
  8449. __copy_from_user(void *to, const void __user *from, unsigned long n)
  8450. {
  8451. + if ((long)n < 0)
  8452. + return n;
  8453. +
  8454. return uaccess.copy_from_user(n, from, to);
  8455. }
  8456. @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
  8457. static inline unsigned long __must_check
  8458. copy_from_user(void *to, const void __user *from, unsigned long n)
  8459. {
  8460. - unsigned int sz = __compiletime_object_size(to);
  8461. + size_t sz = __compiletime_object_size(to);
  8462. might_fault();
  8463. - if (unlikely(sz != -1 && sz < n)) {
  8464. +
  8465. + if ((long)n < 0)
  8466. + return n;
  8467. +
  8468. + if (unlikely(sz != (size_t)-1 && sz < n)) {
  8469. copy_from_user_overflow();
  8470. return n;
  8471. }
  8472. diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
  8473. index b89b591..fd9609d 100644
  8474. --- a/arch/s390/kernel/module.c
  8475. +++ b/arch/s390/kernel/module.c
  8476. @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
  8477. /* Increase core size by size of got & plt and set start
  8478. offsets for got and plt. */
  8479. - me->core_size = ALIGN(me->core_size, 4);
  8480. - me->arch.got_offset = me->core_size;
  8481. - me->core_size += me->arch.got_size;
  8482. - me->arch.plt_offset = me->core_size;
  8483. - me->core_size += me->arch.plt_size;
  8484. + me->core_size_rw = ALIGN(me->core_size_rw, 4);
  8485. + me->arch.got_offset = me->core_size_rw;
  8486. + me->core_size_rw += me->arch.got_size;
  8487. + me->arch.plt_offset = me->core_size_rx;
  8488. + me->core_size_rx += me->arch.plt_size;
  8489. return 0;
  8490. }
  8491. @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
  8492. if (info->got_initialized == 0) {
  8493. Elf_Addr *gotent;
  8494. - gotent = me->module_core + me->arch.got_offset +
  8495. + gotent = me->module_core_rw + me->arch.got_offset +
  8496. info->got_offset;
  8497. *gotent = val;
  8498. info->got_initialized = 1;
  8499. @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
  8500. rc = apply_rela_bits(loc, val, 0, 64, 0);
  8501. else if (r_type == R_390_GOTENT ||
  8502. r_type == R_390_GOTPLTENT) {
  8503. - val += (Elf_Addr) me->module_core - loc;
  8504. + val += (Elf_Addr) me->module_core_rw - loc;
  8505. rc = apply_rela_bits(loc, val, 1, 32, 1);
  8506. }
  8507. break;
  8508. @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
  8509. case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
  8510. if (info->plt_initialized == 0) {
  8511. unsigned int *ip;
  8512. - ip = me->module_core + me->arch.plt_offset +
  8513. + ip = me->module_core_rx + me->arch.plt_offset +
  8514. info->plt_offset;
  8515. #ifndef CONFIG_64BIT
  8516. ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
  8517. @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
  8518. val - loc + 0xffffUL < 0x1ffffeUL) ||
  8519. (r_type == R_390_PLT32DBL &&
  8520. val - loc + 0xffffffffULL < 0x1fffffffeULL)))
  8521. - val = (Elf_Addr) me->module_core +
  8522. + val = (Elf_Addr) me->module_core_rx +
  8523. me->arch.plt_offset +
  8524. info->plt_offset;
  8525. val += rela->r_addend - loc;
  8526. @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
  8527. case R_390_GOTOFF32: /* 32 bit offset to GOT. */
  8528. case R_390_GOTOFF64: /* 64 bit offset to GOT. */
  8529. val = val + rela->r_addend -
  8530. - ((Elf_Addr) me->module_core + me->arch.got_offset);
  8531. + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
  8532. if (r_type == R_390_GOTOFF16)
  8533. rc = apply_rela_bits(loc, val, 0, 16, 0);
  8534. else if (r_type == R_390_GOTOFF32)
  8535. @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
  8536. break;
  8537. case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
  8538. case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
  8539. - val = (Elf_Addr) me->module_core + me->arch.got_offset +
  8540. + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
  8541. rela->r_addend - loc;
  8542. if (r_type == R_390_GOTPC)
  8543. rc = apply_rela_bits(loc, val, 1, 32, 0);
  8544. diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
  8545. index dd14532..1dfc145 100644
  8546. --- a/arch/s390/kernel/process.c
  8547. +++ b/arch/s390/kernel/process.c
  8548. @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
  8549. }
  8550. return 0;
  8551. }
  8552. -
  8553. -unsigned long arch_align_stack(unsigned long sp)
  8554. -{
  8555. - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  8556. - sp -= get_random_int() & ~PAGE_MASK;
  8557. - return sp & ~0xf;
  8558. -}
  8559. -
  8560. -static inline unsigned long brk_rnd(void)
  8561. -{
  8562. - /* 8MB for 32bit, 1GB for 64bit */
  8563. - if (is_32bit_task())
  8564. - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
  8565. - else
  8566. - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
  8567. -}
  8568. -
  8569. -unsigned long arch_randomize_brk(struct mm_struct *mm)
  8570. -{
  8571. - unsigned long ret;
  8572. -
  8573. - ret = PAGE_ALIGN(mm->brk + brk_rnd());
  8574. - return (ret > mm->brk) ? ret : mm->brk;
  8575. -}
  8576. -
  8577. -unsigned long randomize_et_dyn(unsigned long base)
  8578. -{
  8579. - unsigned long ret;
  8580. -
  8581. - if (!(current->flags & PF_RANDOMIZE))
  8582. - return base;
  8583. - ret = PAGE_ALIGN(base + brk_rnd());
  8584. - return (ret > base) ? ret : base;
  8585. -}
  8586. diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
  8587. index 9b436c2..54fbf0a 100644
  8588. --- a/arch/s390/mm/mmap.c
  8589. +++ b/arch/s390/mm/mmap.c
  8590. @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  8591. */
  8592. if (mmap_is_legacy()) {
  8593. mm->mmap_base = mmap_base_legacy();
  8594. +
  8595. +#ifdef CONFIG_PAX_RANDMMAP
  8596. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8597. + mm->mmap_base += mm->delta_mmap;
  8598. +#endif
  8599. +
  8600. mm->get_unmapped_area = arch_get_unmapped_area;
  8601. } else {
  8602. mm->mmap_base = mmap_base();
  8603. +
  8604. +#ifdef CONFIG_PAX_RANDMMAP
  8605. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8606. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  8607. +#endif
  8608. +
  8609. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  8610. }
  8611. }
  8612. @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  8613. */
  8614. if (mmap_is_legacy()) {
  8615. mm->mmap_base = mmap_base_legacy();
  8616. +
  8617. +#ifdef CONFIG_PAX_RANDMMAP
  8618. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8619. + mm->mmap_base += mm->delta_mmap;
  8620. +#endif
  8621. +
  8622. mm->get_unmapped_area = s390_get_unmapped_area;
  8623. } else {
  8624. mm->mmap_base = mmap_base();
  8625. +
  8626. +#ifdef CONFIG_PAX_RANDMMAP
  8627. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8628. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  8629. +#endif
  8630. +
  8631. mm->get_unmapped_area = s390_get_unmapped_area_topdown;
  8632. }
  8633. }
  8634. diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
  8635. index ae3d59f..f65f075 100644
  8636. --- a/arch/score/include/asm/cache.h
  8637. +++ b/arch/score/include/asm/cache.h
  8638. @@ -1,7 +1,9 @@
  8639. #ifndef _ASM_SCORE_CACHE_H
  8640. #define _ASM_SCORE_CACHE_H
  8641. +#include <linux/const.h>
  8642. +
  8643. #define L1_CACHE_SHIFT 4
  8644. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  8645. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  8646. #endif /* _ASM_SCORE_CACHE_H */
  8647. diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
  8648. index f9f3cd5..58ff438 100644
  8649. --- a/arch/score/include/asm/exec.h
  8650. +++ b/arch/score/include/asm/exec.h
  8651. @@ -1,6 +1,6 @@
  8652. #ifndef _ASM_SCORE_EXEC_H
  8653. #define _ASM_SCORE_EXEC_H
  8654. -extern unsigned long arch_align_stack(unsigned long sp);
  8655. +#define arch_align_stack(x) (x)
  8656. #endif /* _ASM_SCORE_EXEC_H */
  8657. diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
  8658. index a1519ad3..e8ac1ff 100644
  8659. --- a/arch/score/kernel/process.c
  8660. +++ b/arch/score/kernel/process.c
  8661. @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
  8662. return task_pt_regs(task)->cp0_epc;
  8663. }
  8664. -
  8665. -unsigned long arch_align_stack(unsigned long sp)
  8666. -{
  8667. - return sp;
  8668. -}
  8669. diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
  8670. index ef9e555..331bd29 100644
  8671. --- a/arch/sh/include/asm/cache.h
  8672. +++ b/arch/sh/include/asm/cache.h
  8673. @@ -9,10 +9,11 @@
  8674. #define __ASM_SH_CACHE_H
  8675. #ifdef __KERNEL__
  8676. +#include <linux/const.h>
  8677. #include <linux/init.h>
  8678. #include <cpu/cache.h>
  8679. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  8680. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  8681. #define __read_mostly __attribute__((__section__(".data..read_mostly")))
  8682. diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
  8683. index 6777177..cb5e44f 100644
  8684. --- a/arch/sh/mm/mmap.c
  8685. +++ b/arch/sh/mm/mmap.c
  8686. @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  8687. struct mm_struct *mm = current->mm;
  8688. struct vm_area_struct *vma;
  8689. int do_colour_align;
  8690. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  8691. struct vm_unmapped_area_info info;
  8692. if (flags & MAP_FIXED) {
  8693. @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  8694. if (filp || (flags & MAP_SHARED))
  8695. do_colour_align = 1;
  8696. +#ifdef CONFIG_PAX_RANDMMAP
  8697. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  8698. +#endif
  8699. +
  8700. if (addr) {
  8701. if (do_colour_align)
  8702. addr = COLOUR_ALIGN(addr, pgoff);
  8703. @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  8704. addr = PAGE_ALIGN(addr);
  8705. vma = find_vma(mm, addr);
  8706. - if (TASK_SIZE - len >= addr &&
  8707. - (!vma || addr + len <= vma->vm_start))
  8708. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  8709. return addr;
  8710. }
  8711. info.flags = 0;
  8712. info.length = len;
  8713. - info.low_limit = TASK_UNMAPPED_BASE;
  8714. + info.low_limit = mm->mmap_base;
  8715. info.high_limit = TASK_SIZE;
  8716. info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
  8717. info.align_offset = pgoff << PAGE_SHIFT;
  8718. @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  8719. struct mm_struct *mm = current->mm;
  8720. unsigned long addr = addr0;
  8721. int do_colour_align;
  8722. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  8723. struct vm_unmapped_area_info info;
  8724. if (flags & MAP_FIXED) {
  8725. @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  8726. if (filp || (flags & MAP_SHARED))
  8727. do_colour_align = 1;
  8728. +#ifdef CONFIG_PAX_RANDMMAP
  8729. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  8730. +#endif
  8731. +
  8732. /* requesting a specific address */
  8733. if (addr) {
  8734. if (do_colour_align)
  8735. @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  8736. addr = PAGE_ALIGN(addr);
  8737. vma = find_vma(mm, addr);
  8738. - if (TASK_SIZE - len >= addr &&
  8739. - (!vma || addr + len <= vma->vm_start))
  8740. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  8741. return addr;
  8742. }
  8743. @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  8744. VM_BUG_ON(addr != -ENOMEM);
  8745. info.flags = 0;
  8746. info.low_limit = TASK_UNMAPPED_BASE;
  8747. +
  8748. +#ifdef CONFIG_PAX_RANDMMAP
  8749. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  8750. + info.low_limit += mm->delta_mmap;
  8751. +#endif
  8752. +
  8753. info.high_limit = TASK_SIZE;
  8754. addr = vm_unmapped_area(&info);
  8755. }
  8756. diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
  8757. index be56a24..443328f 100644
  8758. --- a/arch/sparc/include/asm/atomic_64.h
  8759. +++ b/arch/sparc/include/asm/atomic_64.h
  8760. @@ -14,18 +14,40 @@
  8761. #define ATOMIC64_INIT(i) { (i) }
  8762. #define atomic_read(v) (*(volatile int *)&(v)->counter)
  8763. +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
  8764. +{
  8765. + return v->counter;
  8766. +}
  8767. #define atomic64_read(v) (*(volatile long *)&(v)->counter)
  8768. +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
  8769. +{
  8770. + return v->counter;
  8771. +}
  8772. #define atomic_set(v, i) (((v)->counter) = i)
  8773. +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
  8774. +{
  8775. + v->counter = i;
  8776. +}
  8777. #define atomic64_set(v, i) (((v)->counter) = i)
  8778. +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
  8779. +{
  8780. + v->counter = i;
  8781. +}
  8782. extern void atomic_add(int, atomic_t *);
  8783. +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
  8784. extern void atomic64_add(long, atomic64_t *);
  8785. +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
  8786. extern void atomic_sub(int, atomic_t *);
  8787. +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
  8788. extern void atomic64_sub(long, atomic64_t *);
  8789. +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
  8790. extern int atomic_add_ret(int, atomic_t *);
  8791. +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
  8792. extern long atomic64_add_ret(long, atomic64_t *);
  8793. +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
  8794. extern int atomic_sub_ret(int, atomic_t *);
  8795. extern long atomic64_sub_ret(long, atomic64_t *);
  8796. @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
  8797. #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
  8798. #define atomic_inc_return(v) atomic_add_ret(1, v)
  8799. +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
  8800. +{
  8801. + return atomic_add_ret_unchecked(1, v);
  8802. +}
  8803. #define atomic64_inc_return(v) atomic64_add_ret(1, v)
  8804. +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
  8805. +{
  8806. + return atomic64_add_ret_unchecked(1, v);
  8807. +}
  8808. #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
  8809. #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
  8810. #define atomic_add_return(i, v) atomic_add_ret(i, v)
  8811. +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
  8812. +{
  8813. + return atomic_add_ret_unchecked(i, v);
  8814. +}
  8815. #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
  8816. +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
  8817. +{
  8818. + return atomic64_add_ret_unchecked(i, v);
  8819. +}
  8820. /*
  8821. * atomic_inc_and_test - increment and test
  8822. @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
  8823. * other cases.
  8824. */
  8825. #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
  8826. +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
  8827. +{
  8828. + return atomic_inc_return_unchecked(v) == 0;
  8829. +}
  8830. #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
  8831. #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
  8832. @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
  8833. #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
  8834. #define atomic_inc(v) atomic_add(1, v)
  8835. +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
  8836. +{
  8837. + atomic_add_unchecked(1, v);
  8838. +}
  8839. #define atomic64_inc(v) atomic64_add(1, v)
  8840. +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
  8841. +{
  8842. + atomic64_add_unchecked(1, v);
  8843. +}
  8844. #define atomic_dec(v) atomic_sub(1, v)
  8845. +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
  8846. +{
  8847. + atomic_sub_unchecked(1, v);
  8848. +}
  8849. #define atomic64_dec(v) atomic64_sub(1, v)
  8850. +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
  8851. +{
  8852. + atomic64_sub_unchecked(1, v);
  8853. +}
  8854. #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
  8855. #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
  8856. #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
  8857. +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
  8858. +{
  8859. + return cmpxchg(&v->counter, old, new);
  8860. +}
  8861. #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
  8862. +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
  8863. +{
  8864. + return xchg(&v->counter, new);
  8865. +}
  8866. static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  8867. {
  8868. - int c, old;
  8869. + int c, old, new;
  8870. c = atomic_read(v);
  8871. for (;;) {
  8872. - if (unlikely(c == (u)))
  8873. + if (unlikely(c == u))
  8874. break;
  8875. - old = atomic_cmpxchg((v), c, c + (a));
  8876. +
  8877. + asm volatile("addcc %2, %0, %0\n"
  8878. +
  8879. +#ifdef CONFIG_PAX_REFCOUNT
  8880. + "tvs %%icc, 6\n"
  8881. +#endif
  8882. +
  8883. + : "=r" (new)
  8884. + : "0" (c), "ir" (a)
  8885. + : "cc");
  8886. +
  8887. + old = atomic_cmpxchg(v, c, new);
  8888. if (likely(old == c))
  8889. break;
  8890. c = old;
  8891. @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  8892. #define atomic64_cmpxchg(v, o, n) \
  8893. ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
  8894. #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
  8895. +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
  8896. +{
  8897. + return xchg(&v->counter, new);
  8898. +}
  8899. static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
  8900. {
  8901. - long c, old;
  8902. + long c, old, new;
  8903. c = atomic64_read(v);
  8904. for (;;) {
  8905. - if (unlikely(c == (u)))
  8906. + if (unlikely(c == u))
  8907. break;
  8908. - old = atomic64_cmpxchg((v), c, c + (a));
  8909. +
  8910. + asm volatile("addcc %2, %0, %0\n"
  8911. +
  8912. +#ifdef CONFIG_PAX_REFCOUNT
  8913. + "tvs %%xcc, 6\n"
  8914. +#endif
  8915. +
  8916. + : "=r" (new)
  8917. + : "0" (c), "ir" (a)
  8918. + : "cc");
  8919. +
  8920. + old = atomic64_cmpxchg(v, c, new);
  8921. if (likely(old == c))
  8922. break;
  8923. c = old;
  8924. }
  8925. - return c != (u);
  8926. + return c != u;
  8927. }
  8928. #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
  8929. diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
  8930. index 5bb6991..5c2132e 100644
  8931. --- a/arch/sparc/include/asm/cache.h
  8932. +++ b/arch/sparc/include/asm/cache.h
  8933. @@ -7,10 +7,12 @@
  8934. #ifndef _SPARC_CACHE_H
  8935. #define _SPARC_CACHE_H
  8936. +#include <linux/const.h>
  8937. +
  8938. #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
  8939. #define L1_CACHE_SHIFT 5
  8940. -#define L1_CACHE_BYTES 32
  8941. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  8942. #ifdef CONFIG_SPARC32
  8943. #define SMP_CACHE_BYTES_SHIFT 5
  8944. diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
  8945. index a24e41f..47677ff 100644
  8946. --- a/arch/sparc/include/asm/elf_32.h
  8947. +++ b/arch/sparc/include/asm/elf_32.h
  8948. @@ -114,6 +114,13 @@ typedef struct {
  8949. #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
  8950. +#ifdef CONFIG_PAX_ASLR
  8951. +#define PAX_ELF_ET_DYN_BASE 0x10000UL
  8952. +
  8953. +#define PAX_DELTA_MMAP_LEN 16
  8954. +#define PAX_DELTA_STACK_LEN 16
  8955. +#endif
  8956. +
  8957. /* This yields a mask that user programs can use to figure out what
  8958. instruction set this cpu supports. This can NOT be done in userspace
  8959. on Sparc. */
  8960. diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
  8961. index 370ca1e..d4f4a98 100644
  8962. --- a/arch/sparc/include/asm/elf_64.h
  8963. +++ b/arch/sparc/include/asm/elf_64.h
  8964. @@ -189,6 +189,13 @@ typedef struct {
  8965. #define ELF_ET_DYN_BASE 0x0000010000000000UL
  8966. #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
  8967. +#ifdef CONFIG_PAX_ASLR
  8968. +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
  8969. +
  8970. +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
  8971. +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
  8972. +#endif
  8973. +
  8974. extern unsigned long sparc64_elf_hwcap;
  8975. #define ELF_HWCAP sparc64_elf_hwcap
  8976. diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
  8977. index 9b1c36d..209298b 100644
  8978. --- a/arch/sparc/include/asm/pgalloc_32.h
  8979. +++ b/arch/sparc/include/asm/pgalloc_32.h
  8980. @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
  8981. }
  8982. #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
  8983. +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
  8984. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
  8985. unsigned long address)
  8986. diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
  8987. index bcfe063..b333142 100644
  8988. --- a/arch/sparc/include/asm/pgalloc_64.h
  8989. +++ b/arch/sparc/include/asm/pgalloc_64.h
  8990. @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  8991. }
  8992. #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
  8993. +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
  8994. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  8995. {
  8996. diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
  8997. index 59ba6f6..4518128 100644
  8998. --- a/arch/sparc/include/asm/pgtable.h
  8999. +++ b/arch/sparc/include/asm/pgtable.h
  9000. @@ -5,4 +5,8 @@
  9001. #else
  9002. #include <asm/pgtable_32.h>
  9003. #endif
  9004. +
  9005. +#define ktla_ktva(addr) (addr)
  9006. +#define ktva_ktla(addr) (addr)
  9007. +
  9008. #endif
  9009. diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
  9010. index 502f632..da1917f 100644
  9011. --- a/arch/sparc/include/asm/pgtable_32.h
  9012. +++ b/arch/sparc/include/asm/pgtable_32.h
  9013. @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
  9014. #define PAGE_SHARED SRMMU_PAGE_SHARED
  9015. #define PAGE_COPY SRMMU_PAGE_COPY
  9016. #define PAGE_READONLY SRMMU_PAGE_RDONLY
  9017. +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
  9018. +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
  9019. +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
  9020. #define PAGE_KERNEL SRMMU_PAGE_KERNEL
  9021. /* Top-level page directory - dummy used by init-mm.
  9022. @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
  9023. /* xwr */
  9024. #define __P000 PAGE_NONE
  9025. -#define __P001 PAGE_READONLY
  9026. -#define __P010 PAGE_COPY
  9027. -#define __P011 PAGE_COPY
  9028. +#define __P001 PAGE_READONLY_NOEXEC
  9029. +#define __P010 PAGE_COPY_NOEXEC
  9030. +#define __P011 PAGE_COPY_NOEXEC
  9031. #define __P100 PAGE_READONLY
  9032. #define __P101 PAGE_READONLY
  9033. #define __P110 PAGE_COPY
  9034. #define __P111 PAGE_COPY
  9035. #define __S000 PAGE_NONE
  9036. -#define __S001 PAGE_READONLY
  9037. -#define __S010 PAGE_SHARED
  9038. -#define __S011 PAGE_SHARED
  9039. +#define __S001 PAGE_READONLY_NOEXEC
  9040. +#define __S010 PAGE_SHARED_NOEXEC
  9041. +#define __S011 PAGE_SHARED_NOEXEC
  9042. #define __S100 PAGE_READONLY
  9043. #define __S101 PAGE_READONLY
  9044. #define __S110 PAGE_SHARED
  9045. diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
  9046. index 0f9e945..a949e55 100644
  9047. --- a/arch/sparc/include/asm/pgtable_64.h
  9048. +++ b/arch/sparc/include/asm/pgtable_64.h
  9049. @@ -71,6 +71,23 @@
  9050. #include <linux/sched.h>
  9051. +extern unsigned long sparc64_valid_addr_bitmap[];
  9052. +
  9053. +/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  9054. +static inline bool __kern_addr_valid(unsigned long paddr)
  9055. +{
  9056. + if ((paddr >> MAX_PHYS_ADDRESS_BITS) != 0UL)
  9057. + return false;
  9058. + return test_bit(paddr >> ILOG2_4MB, sparc64_valid_addr_bitmap);
  9059. +}
  9060. +
  9061. +static inline bool kern_addr_valid(unsigned long addr)
  9062. +{
  9063. + unsigned long paddr = __pa(addr);
  9064. +
  9065. + return __kern_addr_valid(paddr);
  9066. +}
  9067. +
  9068. /* Entries per page directory level. */
  9069. #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
  9070. #define PTRS_PER_PMD (1UL << PMD_BITS)
  9071. @@ -79,9 +96,12 @@
  9072. /* Kernel has a separate 44bit address space. */
  9073. #define FIRST_USER_ADDRESS 0
  9074. -#define pte_ERROR(e) __builtin_trap()
  9075. -#define pmd_ERROR(e) __builtin_trap()
  9076. -#define pgd_ERROR(e) __builtin_trap()
  9077. +#define pmd_ERROR(e) \
  9078. + pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
  9079. + __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
  9080. +#define pgd_ERROR(e) \
  9081. + pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
  9082. + __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
  9083. #endif /* !(__ASSEMBLY__) */
  9084. @@ -633,7 +653,7 @@ static inline unsigned long pmd_large(pmd_t pmd)
  9085. {
  9086. pte_t pte = __pte(pmd_val(pmd));
  9087. - return (pte_val(pte) & _PAGE_PMD_HUGE) && pte_present(pte);
  9088. + return pte_val(pte) & _PAGE_PMD_HUGE;
  9089. }
  9090. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  9091. @@ -719,20 +739,6 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
  9092. return __pmd(pte_val(pte));
  9093. }
  9094. -static inline pmd_t pmd_mknotpresent(pmd_t pmd)
  9095. -{
  9096. - unsigned long mask;
  9097. -
  9098. - if (tlb_type == hypervisor)
  9099. - mask = _PAGE_PRESENT_4V;
  9100. - else
  9101. - mask = _PAGE_PRESENT_4U;
  9102. -
  9103. - pmd_val(pmd) &= ~mask;
  9104. -
  9105. - return pmd;
  9106. -}
  9107. -
  9108. static inline pmd_t pmd_mksplitting(pmd_t pmd)
  9109. {
  9110. pte_t pte = __pte(pmd_val(pmd));
  9111. @@ -757,6 +763,20 @@ static inline int pmd_present(pmd_t pmd)
  9112. #define pmd_none(pmd) (!pmd_val(pmd))
  9113. +/* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
  9114. + * very simple, it's just the physical address. PTE tables are of
  9115. + * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
  9116. + * the top bits outside of the range of any physical address size we
  9117. + * support are clear as well. We also validate the physical itself.
  9118. + */
  9119. +#define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) || \
  9120. + !__kern_addr_valid(pmd_val(pmd)))
  9121. +
  9122. +#define pud_none(pud) (!pud_val(pud))
  9123. +
  9124. +#define pud_bad(pud) ((pud_val(pud) & ~PAGE_MASK) || \
  9125. + !__kern_addr_valid(pud_val(pud)))
  9126. +
  9127. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  9128. extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  9129. pmd_t *pmdp, pmd_t pmd);
  9130. @@ -790,10 +810,7 @@ static inline unsigned long __pmd_page(pmd_t pmd)
  9131. #define pud_page_vaddr(pud) \
  9132. ((unsigned long) __va(pud_val(pud)))
  9133. #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
  9134. -#define pmd_bad(pmd) (0)
  9135. #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
  9136. -#define pud_none(pud) (!pud_val(pud))
  9137. -#define pud_bad(pud) (0)
  9138. #define pud_present(pud) (pud_val(pud) != 0U)
  9139. #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
  9140. @@ -893,6 +910,10 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
  9141. extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
  9142. pmd_t *pmd);
  9143. +#define __HAVE_ARCH_PMDP_INVALIDATE
  9144. +extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  9145. + pmd_t *pmdp);
  9146. +
  9147. #define __HAVE_ARCH_PGTABLE_DEPOSIT
  9148. extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  9149. pgtable_t pgtable);
  9150. @@ -919,18 +940,6 @@ extern unsigned long pte_file(pte_t);
  9151. extern pte_t pgoff_to_pte(unsigned long);
  9152. #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
  9153. -extern unsigned long sparc64_valid_addr_bitmap[];
  9154. -
  9155. -/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  9156. -static inline bool kern_addr_valid(unsigned long addr)
  9157. -{
  9158. - unsigned long paddr = __pa(addr);
  9159. -
  9160. - if ((paddr >> 41UL) != 0UL)
  9161. - return false;
  9162. - return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
  9163. -}
  9164. -
  9165. extern int page_in_phys_avail(unsigned long paddr);
  9166. /*
  9167. diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
  9168. index 79da178..c2eede8 100644
  9169. --- a/arch/sparc/include/asm/pgtsrmmu.h
  9170. +++ b/arch/sparc/include/asm/pgtsrmmu.h
  9171. @@ -115,6 +115,11 @@
  9172. SRMMU_EXEC | SRMMU_REF)
  9173. #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
  9174. SRMMU_EXEC | SRMMU_REF)
  9175. +
  9176. +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
  9177. +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
  9178. +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
  9179. +
  9180. #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
  9181. SRMMU_DIRTY | SRMMU_REF)
  9182. diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
  9183. index 9689176..63c18ea 100644
  9184. --- a/arch/sparc/include/asm/spinlock_64.h
  9185. +++ b/arch/sparc/include/asm/spinlock_64.h
  9186. @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
  9187. /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
  9188. -static void inline arch_read_lock(arch_rwlock_t *lock)
  9189. +static inline void arch_read_lock(arch_rwlock_t *lock)
  9190. {
  9191. unsigned long tmp1, tmp2;
  9192. __asm__ __volatile__ (
  9193. "1: ldsw [%2], %0\n"
  9194. " brlz,pn %0, 2f\n"
  9195. -"4: add %0, 1, %1\n"
  9196. +"4: addcc %0, 1, %1\n"
  9197. +
  9198. +#ifdef CONFIG_PAX_REFCOUNT
  9199. +" tvs %%icc, 6\n"
  9200. +#endif
  9201. +
  9202. " cas [%2], %0, %1\n"
  9203. " cmp %0, %1\n"
  9204. " bne,pn %%icc, 1b\n"
  9205. @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
  9206. " .previous"
  9207. : "=&r" (tmp1), "=&r" (tmp2)
  9208. : "r" (lock)
  9209. - : "memory");
  9210. + : "memory", "cc");
  9211. }
  9212. -static int inline arch_read_trylock(arch_rwlock_t *lock)
  9213. +static inline int arch_read_trylock(arch_rwlock_t *lock)
  9214. {
  9215. int tmp1, tmp2;
  9216. @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
  9217. "1: ldsw [%2], %0\n"
  9218. " brlz,a,pn %0, 2f\n"
  9219. " mov 0, %0\n"
  9220. -" add %0, 1, %1\n"
  9221. +" addcc %0, 1, %1\n"
  9222. +
  9223. +#ifdef CONFIG_PAX_REFCOUNT
  9224. +" tvs %%icc, 6\n"
  9225. +#endif
  9226. +
  9227. " cas [%2], %0, %1\n"
  9228. " cmp %0, %1\n"
  9229. " bne,pn %%icc, 1b\n"
  9230. @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
  9231. return tmp1;
  9232. }
  9233. -static void inline arch_read_unlock(arch_rwlock_t *lock)
  9234. +static inline void arch_read_unlock(arch_rwlock_t *lock)
  9235. {
  9236. unsigned long tmp1, tmp2;
  9237. __asm__ __volatile__(
  9238. "1: lduw [%2], %0\n"
  9239. -" sub %0, 1, %1\n"
  9240. +" subcc %0, 1, %1\n"
  9241. +
  9242. +#ifdef CONFIG_PAX_REFCOUNT
  9243. +" tvs %%icc, 6\n"
  9244. +#endif
  9245. +
  9246. " cas [%2], %0, %1\n"
  9247. " cmp %0, %1\n"
  9248. " bne,pn %%xcc, 1b\n"
  9249. @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
  9250. : "memory");
  9251. }
  9252. -static void inline arch_write_lock(arch_rwlock_t *lock)
  9253. +static inline void arch_write_lock(arch_rwlock_t *lock)
  9254. {
  9255. unsigned long mask, tmp1, tmp2;
  9256. @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
  9257. : "memory");
  9258. }
  9259. -static void inline arch_write_unlock(arch_rwlock_t *lock)
  9260. +static inline void arch_write_unlock(arch_rwlock_t *lock)
  9261. {
  9262. __asm__ __volatile__(
  9263. " stw %%g0, [%0]"
  9264. @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
  9265. : "memory");
  9266. }
  9267. -static int inline arch_write_trylock(arch_rwlock_t *lock)
  9268. +static inline int arch_write_trylock(arch_rwlock_t *lock)
  9269. {
  9270. unsigned long mask, tmp1, tmp2, result;
  9271. diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
  9272. index 96efa7a..16858bf 100644
  9273. --- a/arch/sparc/include/asm/thread_info_32.h
  9274. +++ b/arch/sparc/include/asm/thread_info_32.h
  9275. @@ -49,6 +49,8 @@ struct thread_info {
  9276. unsigned long w_saved;
  9277. struct restart_block restart_block;
  9278. +
  9279. + unsigned long lowest_stack;
  9280. };
  9281. /*
  9282. diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
  9283. index a5f01ac..703b554 100644
  9284. --- a/arch/sparc/include/asm/thread_info_64.h
  9285. +++ b/arch/sparc/include/asm/thread_info_64.h
  9286. @@ -63,6 +63,8 @@ struct thread_info {
  9287. struct pt_regs *kern_una_regs;
  9288. unsigned int kern_una_insn;
  9289. + unsigned long lowest_stack;
  9290. +
  9291. unsigned long fpregs[0] __attribute__ ((aligned(64)));
  9292. };
  9293. @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
  9294. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  9295. /* flag bit 4 is available */
  9296. #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
  9297. -/* flag bit 6 is available */
  9298. +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
  9299. #define TIF_32BIT 7 /* 32-bit binary */
  9300. #define TIF_NOHZ 8 /* in adaptive nohz mode */
  9301. #define TIF_SECCOMP 9 /* secure computing */
  9302. #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
  9303. #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
  9304. +
  9305. /* NOTE: Thread flags >= 12 should be ones we have no interest
  9306. * in using in assembly, else we can't use the mask as
  9307. * an immediate value in instructions such as andcc.
  9308. @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
  9309. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  9310. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  9311. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  9312. +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
  9313. #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
  9314. _TIF_DO_NOTIFY_RESUME_MASK | \
  9315. _TIF_NEED_RESCHED)
  9316. #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
  9317. +#define _TIF_WORK_SYSCALL \
  9318. + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
  9319. + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
  9320. +
  9321. +
  9322. /*
  9323. * Thread-synchronous status.
  9324. *
  9325. diff --git a/arch/sparc/include/asm/tsb.h b/arch/sparc/include/asm/tsb.h
  9326. index 2230f80..90916f9 100644
  9327. --- a/arch/sparc/include/asm/tsb.h
  9328. +++ b/arch/sparc/include/asm/tsb.h
  9329. @@ -171,7 +171,8 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
  9330. andcc REG1, REG2, %g0; \
  9331. be,pt %xcc, 700f; \
  9332. sethi %hi(4 * 1024 * 1024), REG2; \
  9333. - andn REG1, REG2, REG1; \
  9334. + brgez,pn REG1, FAIL_LABEL; \
  9335. + andn REG1, REG2, REG1; \
  9336. and VADDR, REG2, REG2; \
  9337. brlz,pt REG1, PTE_LABEL; \
  9338. or REG1, REG2, REG1; \
  9339. diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
  9340. index 0167d26..767bb0c 100644
  9341. --- a/arch/sparc/include/asm/uaccess.h
  9342. +++ b/arch/sparc/include/asm/uaccess.h
  9343. @@ -1,5 +1,6 @@
  9344. #ifndef ___ASM_SPARC_UACCESS_H
  9345. #define ___ASM_SPARC_UACCESS_H
  9346. +
  9347. #if defined(__sparc__) && defined(__arch64__)
  9348. #include <asm/uaccess_64.h>
  9349. #else
  9350. diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
  9351. index 53a28dd..50c38c3 100644
  9352. --- a/arch/sparc/include/asm/uaccess_32.h
  9353. +++ b/arch/sparc/include/asm/uaccess_32.h
  9354. @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
  9355. static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
  9356. {
  9357. - if (n && __access_ok((unsigned long) to, n))
  9358. + if ((long)n < 0)
  9359. + return n;
  9360. +
  9361. + if (n && __access_ok((unsigned long) to, n)) {
  9362. + if (!__builtin_constant_p(n))
  9363. + check_object_size(from, n, true);
  9364. return __copy_user(to, (__force void __user *) from, n);
  9365. - else
  9366. + } else
  9367. return n;
  9368. }
  9369. static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
  9370. {
  9371. + if ((long)n < 0)
  9372. + return n;
  9373. +
  9374. + if (!__builtin_constant_p(n))
  9375. + check_object_size(from, n, true);
  9376. +
  9377. return __copy_user(to, (__force void __user *) from, n);
  9378. }
  9379. static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
  9380. {
  9381. - if (n && __access_ok((unsigned long) from, n))
  9382. + if ((long)n < 0)
  9383. + return n;
  9384. +
  9385. + if (n && __access_ok((unsigned long) from, n)) {
  9386. + if (!__builtin_constant_p(n))
  9387. + check_object_size(to, n, false);
  9388. return __copy_user((__force void __user *) to, from, n);
  9389. - else
  9390. + } else
  9391. return n;
  9392. }
  9393. static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
  9394. {
  9395. + if ((long)n < 0)
  9396. + return n;
  9397. +
  9398. return __copy_user((__force void __user *) to, from, n);
  9399. }
  9400. diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
  9401. index ad7e178..c9e7423 100644
  9402. --- a/arch/sparc/include/asm/uaccess_64.h
  9403. +++ b/arch/sparc/include/asm/uaccess_64.h
  9404. @@ -10,6 +10,7 @@
  9405. #include <linux/compiler.h>
  9406. #include <linux/string.h>
  9407. #include <linux/thread_info.h>
  9408. +#include <linux/kernel.h>
  9409. #include <asm/asi.h>
  9410. #include <asm/spitfire.h>
  9411. #include <asm-generic/uaccess-unaligned.h>
  9412. @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
  9413. static inline unsigned long __must_check
  9414. copy_from_user(void *to, const void __user *from, unsigned long size)
  9415. {
  9416. - unsigned long ret = ___copy_from_user(to, from, size);
  9417. + unsigned long ret;
  9418. + if ((long)size < 0 || size > INT_MAX)
  9419. + return size;
  9420. +
  9421. + if (!__builtin_constant_p(size))
  9422. + check_object_size(to, size, false);
  9423. +
  9424. + ret = ___copy_from_user(to, from, size);
  9425. if (unlikely(ret))
  9426. ret = copy_from_user_fixup(to, from, size);
  9427. @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
  9428. static inline unsigned long __must_check
  9429. copy_to_user(void __user *to, const void *from, unsigned long size)
  9430. {
  9431. - unsigned long ret = ___copy_to_user(to, from, size);
  9432. + unsigned long ret;
  9433. + if ((long)size < 0 || size > INT_MAX)
  9434. + return size;
  9435. +
  9436. + if (!__builtin_constant_p(size))
  9437. + check_object_size(from, size, true);
  9438. +
  9439. + ret = ___copy_to_user(to, from, size);
  9440. if (unlikely(ret))
  9441. ret = copy_to_user_fixup(to, from, size);
  9442. return ret;
  9443. diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
  9444. index d15cc17..d0ae796 100644
  9445. --- a/arch/sparc/kernel/Makefile
  9446. +++ b/arch/sparc/kernel/Makefile
  9447. @@ -4,7 +4,7 @@
  9448. #
  9449. asflags-y := -ansi
  9450. -ccflags-y := -Werror
  9451. +#ccflags-y := -Werror
  9452. extra-y := head_$(BITS).o
  9453. diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
  9454. index 510baec..9ff2607 100644
  9455. --- a/arch/sparc/kernel/process_32.c
  9456. +++ b/arch/sparc/kernel/process_32.c
  9457. @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
  9458. printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
  9459. r->psr, r->pc, r->npc, r->y, print_tainted());
  9460. - printk("PC: <%pS>\n", (void *) r->pc);
  9461. + printk("PC: <%pA>\n", (void *) r->pc);
  9462. printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  9463. r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
  9464. r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
  9465. printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  9466. r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
  9467. r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
  9468. - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
  9469. + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
  9470. printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  9471. rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
  9472. @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
  9473. rw = (struct reg_window32 *) fp;
  9474. pc = rw->ins[7];
  9475. printk("[%08lx : ", pc);
  9476. - printk("%pS ] ", (void *) pc);
  9477. + printk("%pA ] ", (void *) pc);
  9478. fp = rw->ins[6];
  9479. } while (++count < 16);
  9480. printk("\n");
  9481. diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
  9482. index d7b4967..2edf827 100644
  9483. --- a/arch/sparc/kernel/process_64.c
  9484. +++ b/arch/sparc/kernel/process_64.c
  9485. @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
  9486. printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
  9487. rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
  9488. if (regs->tstate & TSTATE_PRIV)
  9489. - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
  9490. + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
  9491. }
  9492. void show_regs(struct pt_regs *regs)
  9493. @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
  9494. printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
  9495. regs->tpc, regs->tnpc, regs->y, print_tainted());
  9496. - printk("TPC: <%pS>\n", (void *) regs->tpc);
  9497. + printk("TPC: <%pA>\n", (void *) regs->tpc);
  9498. printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
  9499. regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
  9500. regs->u_regs[3]);
  9501. @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
  9502. printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
  9503. regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
  9504. regs->u_regs[15]);
  9505. - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
  9506. + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
  9507. show_regwindow(regs);
  9508. show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
  9509. }
  9510. @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
  9511. ((tp && tp->task) ? tp->task->pid : -1));
  9512. if (gp->tstate & TSTATE_PRIV) {
  9513. - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
  9514. + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
  9515. (void *) gp->tpc,
  9516. (void *) gp->o7,
  9517. (void *) gp->i7,
  9518. diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
  9519. index 79cc0d1..ec62734 100644
  9520. --- a/arch/sparc/kernel/prom_common.c
  9521. +++ b/arch/sparc/kernel/prom_common.c
  9522. @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
  9523. unsigned int prom_early_allocated __initdata;
  9524. -static struct of_pdt_ops prom_sparc_ops __initdata = {
  9525. +static struct of_pdt_ops prom_sparc_ops __initconst = {
  9526. .nextprop = prom_common_nextprop,
  9527. .getproplen = prom_getproplen,
  9528. .getproperty = prom_getproperty,
  9529. diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
  9530. index c13c9f2..d572c34 100644
  9531. --- a/arch/sparc/kernel/ptrace_64.c
  9532. +++ b/arch/sparc/kernel/ptrace_64.c
  9533. @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
  9534. return ret;
  9535. }
  9536. +#ifdef CONFIG_GRKERNSEC_SETXID
  9537. +extern void gr_delayed_cred_worker(void);
  9538. +#endif
  9539. +
  9540. asmlinkage int syscall_trace_enter(struct pt_regs *regs)
  9541. {
  9542. int ret = 0;
  9543. @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
  9544. if (test_thread_flag(TIF_NOHZ))
  9545. user_exit();
  9546. +#ifdef CONFIG_GRKERNSEC_SETXID
  9547. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  9548. + gr_delayed_cred_worker();
  9549. +#endif
  9550. +
  9551. if (test_thread_flag(TIF_SYSCALL_TRACE))
  9552. ret = tracehook_report_syscall_entry(regs);
  9553. @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
  9554. if (test_thread_flag(TIF_NOHZ))
  9555. user_exit();
  9556. +#ifdef CONFIG_GRKERNSEC_SETXID
  9557. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  9558. + gr_delayed_cred_worker();
  9559. +#endif
  9560. +
  9561. audit_syscall_exit(regs);
  9562. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  9563. diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
  9564. index b085311..6f885f7 100644
  9565. --- a/arch/sparc/kernel/smp_64.c
  9566. +++ b/arch/sparc/kernel/smp_64.c
  9567. @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
  9568. extern unsigned long xcall_flush_dcache_page_spitfire;
  9569. #ifdef CONFIG_DEBUG_DCFLUSH
  9570. -extern atomic_t dcpage_flushes;
  9571. -extern atomic_t dcpage_flushes_xcall;
  9572. +extern atomic_unchecked_t dcpage_flushes;
  9573. +extern atomic_unchecked_t dcpage_flushes_xcall;
  9574. #endif
  9575. static inline void __local_flush_dcache_page(struct page *page)
  9576. @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
  9577. return;
  9578. #ifdef CONFIG_DEBUG_DCFLUSH
  9579. - atomic_inc(&dcpage_flushes);
  9580. + atomic_inc_unchecked(&dcpage_flushes);
  9581. #endif
  9582. this_cpu = get_cpu();
  9583. @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
  9584. xcall_deliver(data0, __pa(pg_addr),
  9585. (u64) pg_addr, cpumask_of(cpu));
  9586. #ifdef CONFIG_DEBUG_DCFLUSH
  9587. - atomic_inc(&dcpage_flushes_xcall);
  9588. + atomic_inc_unchecked(&dcpage_flushes_xcall);
  9589. #endif
  9590. }
  9591. }
  9592. @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
  9593. preempt_disable();
  9594. #ifdef CONFIG_DEBUG_DCFLUSH
  9595. - atomic_inc(&dcpage_flushes);
  9596. + atomic_inc_unchecked(&dcpage_flushes);
  9597. #endif
  9598. data0 = 0;
  9599. pg_addr = page_address(page);
  9600. @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
  9601. xcall_deliver(data0, __pa(pg_addr),
  9602. (u64) pg_addr, cpu_online_mask);
  9603. #ifdef CONFIG_DEBUG_DCFLUSH
  9604. - atomic_inc(&dcpage_flushes_xcall);
  9605. + atomic_inc_unchecked(&dcpage_flushes_xcall);
  9606. #endif
  9607. }
  9608. __local_flush_dcache_page(page);
  9609. diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
  9610. index 3a8d184..49498a8 100644
  9611. --- a/arch/sparc/kernel/sys_sparc_32.c
  9612. +++ b/arch/sparc/kernel/sys_sparc_32.c
  9613. @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  9614. if (len > TASK_SIZE - PAGE_SIZE)
  9615. return -ENOMEM;
  9616. if (!addr)
  9617. - addr = TASK_UNMAPPED_BASE;
  9618. + addr = current->mm->mmap_base;
  9619. info.flags = 0;
  9620. info.length = len;
  9621. diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
  9622. index beb0b5a..5a153f7 100644
  9623. --- a/arch/sparc/kernel/sys_sparc_64.c
  9624. +++ b/arch/sparc/kernel/sys_sparc_64.c
  9625. @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  9626. struct vm_area_struct * vma;
  9627. unsigned long task_size = TASK_SIZE;
  9628. int do_color_align;
  9629. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  9630. struct vm_unmapped_area_info info;
  9631. if (flags & MAP_FIXED) {
  9632. /* We do not accept a shared mapping if it would violate
  9633. * cache aliasing constraints.
  9634. */
  9635. - if ((flags & MAP_SHARED) &&
  9636. + if ((filp || (flags & MAP_SHARED)) &&
  9637. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  9638. return -EINVAL;
  9639. return addr;
  9640. @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  9641. if (filp || (flags & MAP_SHARED))
  9642. do_color_align = 1;
  9643. +#ifdef CONFIG_PAX_RANDMMAP
  9644. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  9645. +#endif
  9646. +
  9647. if (addr) {
  9648. if (do_color_align)
  9649. addr = COLOR_ALIGN(addr, pgoff);
  9650. @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
  9651. addr = PAGE_ALIGN(addr);
  9652. vma = find_vma(mm, addr);
  9653. - if (task_size - len >= addr &&
  9654. - (!vma || addr + len <= vma->vm_start))
  9655. + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  9656. return addr;
  9657. }
  9658. info.flags = 0;
  9659. info.length = len;
  9660. - info.low_limit = TASK_UNMAPPED_BASE;
  9661. + info.low_limit = mm->mmap_base;
  9662. info.high_limit = min(task_size, VA_EXCLUDE_START);
  9663. info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  9664. info.align_offset = pgoff << PAGE_SHIFT;
  9665. + info.threadstack_offset = offset;
  9666. addr = vm_unmapped_area(&info);
  9667. if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
  9668. VM_BUG_ON(addr != -ENOMEM);
  9669. info.low_limit = VA_EXCLUDE_END;
  9670. +
  9671. +#ifdef CONFIG_PAX_RANDMMAP
  9672. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  9673. + info.low_limit += mm->delta_mmap;
  9674. +#endif
  9675. +
  9676. info.high_limit = task_size;
  9677. addr = vm_unmapped_area(&info);
  9678. }
  9679. @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  9680. unsigned long task_size = STACK_TOP32;
  9681. unsigned long addr = addr0;
  9682. int do_color_align;
  9683. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  9684. struct vm_unmapped_area_info info;
  9685. /* This should only ever run for 32-bit processes. */
  9686. @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  9687. /* We do not accept a shared mapping if it would violate
  9688. * cache aliasing constraints.
  9689. */
  9690. - if ((flags & MAP_SHARED) &&
  9691. + if ((filp || (flags & MAP_SHARED)) &&
  9692. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  9693. return -EINVAL;
  9694. return addr;
  9695. @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  9696. if (filp || (flags & MAP_SHARED))
  9697. do_color_align = 1;
  9698. +#ifdef CONFIG_PAX_RANDMMAP
  9699. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  9700. +#endif
  9701. +
  9702. /* requesting a specific address */
  9703. if (addr) {
  9704. if (do_color_align)
  9705. @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  9706. addr = PAGE_ALIGN(addr);
  9707. vma = find_vma(mm, addr);
  9708. - if (task_size - len >= addr &&
  9709. - (!vma || addr + len <= vma->vm_start))
  9710. + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  9711. return addr;
  9712. }
  9713. @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  9714. info.high_limit = mm->mmap_base;
  9715. info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  9716. info.align_offset = pgoff << PAGE_SHIFT;
  9717. + info.threadstack_offset = offset;
  9718. addr = vm_unmapped_area(&info);
  9719. /*
  9720. @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  9721. VM_BUG_ON(addr != -ENOMEM);
  9722. info.flags = 0;
  9723. info.low_limit = TASK_UNMAPPED_BASE;
  9724. +
  9725. +#ifdef CONFIG_PAX_RANDMMAP
  9726. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  9727. + info.low_limit += mm->delta_mmap;
  9728. +#endif
  9729. +
  9730. info.high_limit = STACK_TOP32;
  9731. addr = vm_unmapped_area(&info);
  9732. }
  9733. @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
  9734. EXPORT_SYMBOL(get_fb_unmapped_area);
  9735. /* Essentially the same as PowerPC. */
  9736. -static unsigned long mmap_rnd(void)
  9737. +static unsigned long mmap_rnd(struct mm_struct *mm)
  9738. {
  9739. unsigned long rnd = 0UL;
  9740. +#ifdef CONFIG_PAX_RANDMMAP
  9741. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  9742. +#endif
  9743. +
  9744. if (current->flags & PF_RANDOMIZE) {
  9745. unsigned long val = get_random_int();
  9746. if (test_thread_flag(TIF_32BIT))
  9747. @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
  9748. void arch_pick_mmap_layout(struct mm_struct *mm)
  9749. {
  9750. - unsigned long random_factor = mmap_rnd();
  9751. + unsigned long random_factor = mmap_rnd(mm);
  9752. unsigned long gap;
  9753. /*
  9754. @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  9755. gap == RLIM_INFINITY ||
  9756. sysctl_legacy_va_layout) {
  9757. mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
  9758. +
  9759. +#ifdef CONFIG_PAX_RANDMMAP
  9760. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  9761. + mm->mmap_base += mm->delta_mmap;
  9762. +#endif
  9763. +
  9764. mm->get_unmapped_area = arch_get_unmapped_area;
  9765. } else {
  9766. /* We know it's 32-bit */
  9767. @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
  9768. gap = (task_size / 6 * 5);
  9769. mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
  9770. +
  9771. +#ifdef CONFIG_PAX_RANDMMAP
  9772. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  9773. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  9774. +#endif
  9775. +
  9776. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  9777. }
  9778. }
  9779. diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
  9780. index 33a17e7..d87fb1f 100644
  9781. --- a/arch/sparc/kernel/syscalls.S
  9782. +++ b/arch/sparc/kernel/syscalls.S
  9783. @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
  9784. #endif
  9785. .align 32
  9786. 1: ldx [%g6 + TI_FLAGS], %l5
  9787. - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
  9788. + andcc %l5, _TIF_WORK_SYSCALL, %g0
  9789. be,pt %icc, rtrap
  9790. nop
  9791. call syscall_trace_leave
  9792. @@ -184,7 +184,7 @@ linux_sparc_syscall32:
  9793. srl %i3, 0, %o3 ! IEU0
  9794. srl %i2, 0, %o2 ! IEU0 Group
  9795. - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
  9796. + andcc %l0, _TIF_WORK_SYSCALL, %g0
  9797. bne,pn %icc, linux_syscall_trace32 ! CTI
  9798. mov %i0, %l5 ! IEU1
  9799. 5: call %l7 ! CTI Group brk forced
  9800. @@ -208,7 +208,7 @@ linux_sparc_syscall:
  9801. mov %i3, %o3 ! IEU1
  9802. mov %i4, %o4 ! IEU0 Group
  9803. - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
  9804. + andcc %l0, _TIF_WORK_SYSCALL, %g0
  9805. bne,pn %icc, linux_syscall_trace ! CTI Group
  9806. mov %i0, %l5 ! IEU0
  9807. 2: call %l7 ! CTI Group brk forced
  9808. @@ -223,7 +223,7 @@ ret_sys_call:
  9809. cmp %o0, -ERESTART_RESTARTBLOCK
  9810. bgeu,pn %xcc, 1f
  9811. - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
  9812. + andcc %l0, _TIF_WORK_SYSCALL, %g0
  9813. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  9814. 2:
  9815. diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
  9816. index 6629829..036032d 100644
  9817. --- a/arch/sparc/kernel/traps_32.c
  9818. +++ b/arch/sparc/kernel/traps_32.c
  9819. @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
  9820. #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
  9821. #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
  9822. +extern void gr_handle_kernel_exploit(void);
  9823. +
  9824. void die_if_kernel(char *str, struct pt_regs *regs)
  9825. {
  9826. static int die_counter;
  9827. @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
  9828. count++ < 30 &&
  9829. (((unsigned long) rw) >= PAGE_OFFSET) &&
  9830. !(((unsigned long) rw) & 0x7)) {
  9831. - printk("Caller[%08lx]: %pS\n", rw->ins[7],
  9832. + printk("Caller[%08lx]: %pA\n", rw->ins[7],
  9833. (void *) rw->ins[7]);
  9834. rw = (struct reg_window32 *)rw->ins[6];
  9835. }
  9836. }
  9837. printk("Instruction DUMP:");
  9838. instruction_dump ((unsigned long *) regs->pc);
  9839. - if(regs->psr & PSR_PS)
  9840. + if(regs->psr & PSR_PS) {
  9841. + gr_handle_kernel_exploit();
  9842. do_exit(SIGKILL);
  9843. + }
  9844. do_exit(SIGSEGV);
  9845. }
  9846. diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
  9847. index 4ced92f..965eeed 100644
  9848. --- a/arch/sparc/kernel/traps_64.c
  9849. +++ b/arch/sparc/kernel/traps_64.c
  9850. @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
  9851. i + 1,
  9852. p->trapstack[i].tstate, p->trapstack[i].tpc,
  9853. p->trapstack[i].tnpc, p->trapstack[i].tt);
  9854. - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
  9855. + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
  9856. }
  9857. }
  9858. @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
  9859. lvl -= 0x100;
  9860. if (regs->tstate & TSTATE_PRIV) {
  9861. +
  9862. +#ifdef CONFIG_PAX_REFCOUNT
  9863. + if (lvl == 6)
  9864. + pax_report_refcount_overflow(regs);
  9865. +#endif
  9866. +
  9867. sprintf(buffer, "Kernel bad sw trap %lx", lvl);
  9868. die_if_kernel(buffer, regs);
  9869. }
  9870. @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
  9871. void bad_trap_tl1(struct pt_regs *regs, long lvl)
  9872. {
  9873. char buffer[32];
  9874. -
  9875. +
  9876. if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
  9877. 0, lvl, SIGTRAP) == NOTIFY_STOP)
  9878. return;
  9879. +#ifdef CONFIG_PAX_REFCOUNT
  9880. + if (lvl == 6)
  9881. + pax_report_refcount_overflow(regs);
  9882. +#endif
  9883. +
  9884. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  9885. sprintf (buffer, "Bad trap %lx at tl>0", lvl);
  9886. @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
  9887. regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
  9888. printk("%s" "ERROR(%d): ",
  9889. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
  9890. - printk("TPC<%pS>\n", (void *) regs->tpc);
  9891. + printk("TPC<%pA>\n", (void *) regs->tpc);
  9892. printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
  9893. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  9894. (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
  9895. @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
  9896. smp_processor_id(),
  9897. (type & 0x1) ? 'I' : 'D',
  9898. regs->tpc);
  9899. - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
  9900. + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
  9901. panic("Irrecoverable Cheetah+ parity error.");
  9902. }
  9903. @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
  9904. smp_processor_id(),
  9905. (type & 0x1) ? 'I' : 'D',
  9906. regs->tpc);
  9907. - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
  9908. + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
  9909. }
  9910. struct sun4v_error_entry {
  9911. @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
  9912. /*0x38*/u64 reserved_5;
  9913. };
  9914. -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
  9915. -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
  9916. +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
  9917. +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
  9918. static const char *sun4v_err_type_to_str(u8 type)
  9919. {
  9920. @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
  9921. }
  9922. static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
  9923. - int cpu, const char *pfx, atomic_t *ocnt)
  9924. + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
  9925. {
  9926. u64 *raw_ptr = (u64 *) ent;
  9927. u32 attrs;
  9928. @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
  9929. show_regs(regs);
  9930. - if ((cnt = atomic_read(ocnt)) != 0) {
  9931. - atomic_set(ocnt, 0);
  9932. + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
  9933. + atomic_set_unchecked(ocnt, 0);
  9934. wmb();
  9935. printk("%s: Queue overflowed %d times.\n",
  9936. pfx, cnt);
  9937. @@ -2046,7 +2057,7 @@ out:
  9938. */
  9939. void sun4v_resum_overflow(struct pt_regs *regs)
  9940. {
  9941. - atomic_inc(&sun4v_resum_oflow_cnt);
  9942. + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
  9943. }
  9944. /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
  9945. @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
  9946. /* XXX Actually even this can make not that much sense. Perhaps
  9947. * XXX we should just pull the plug and panic directly from here?
  9948. */
  9949. - atomic_inc(&sun4v_nonresum_oflow_cnt);
  9950. + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
  9951. }
  9952. unsigned long sun4v_err_itlb_vaddr;
  9953. @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
  9954. printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
  9955. regs->tpc, tl);
  9956. - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
  9957. + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
  9958. printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
  9959. - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
  9960. + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
  9961. (void *) regs->u_regs[UREG_I7]);
  9962. printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
  9963. "pte[%lx] error[%lx]\n",
  9964. @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
  9965. printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
  9966. regs->tpc, tl);
  9967. - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
  9968. + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
  9969. printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
  9970. - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
  9971. + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
  9972. (void *) regs->u_regs[UREG_I7]);
  9973. printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
  9974. "pte[%lx] error[%lx]\n",
  9975. @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
  9976. fp = (unsigned long)sf->fp + STACK_BIAS;
  9977. }
  9978. - printk(" [%016lx] %pS\n", pc, (void *) pc);
  9979. + printk(" [%016lx] %pA\n", pc, (void *) pc);
  9980. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  9981. if ((pc + 8UL) == (unsigned long) &return_to_handler) {
  9982. int index = tsk->curr_ret_stack;
  9983. if (tsk->ret_stack && index >= graph) {
  9984. pc = tsk->ret_stack[index - graph].ret;
  9985. - printk(" [%016lx] %pS\n", pc, (void *) pc);
  9986. + printk(" [%016lx] %pA\n", pc, (void *) pc);
  9987. graph++;
  9988. }
  9989. }
  9990. @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
  9991. return (struct reg_window *) (fp + STACK_BIAS);
  9992. }
  9993. +extern void gr_handle_kernel_exploit(void);
  9994. +
  9995. void die_if_kernel(char *str, struct pt_regs *regs)
  9996. {
  9997. static int die_counter;
  9998. @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
  9999. while (rw &&
  10000. count++ < 30 &&
  10001. kstack_valid(tp, (unsigned long) rw)) {
  10002. - printk("Caller[%016lx]: %pS\n", rw->ins[7],
  10003. + printk("Caller[%016lx]: %pA\n", rw->ins[7],
  10004. (void *) rw->ins[7]);
  10005. rw = kernel_stack_up(rw);
  10006. @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
  10007. }
  10008. user_instruction_dump ((unsigned int __user *) regs->tpc);
  10009. }
  10010. - if (regs->tstate & TSTATE_PRIV)
  10011. + if (regs->tstate & TSTATE_PRIV) {
  10012. + gr_handle_kernel_exploit();
  10013. do_exit(SIGKILL);
  10014. + }
  10015. do_exit(SIGSEGV);
  10016. }
  10017. EXPORT_SYMBOL(die_if_kernel);
  10018. diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
  10019. index 3c1a7cb..9046547 100644
  10020. --- a/arch/sparc/kernel/unaligned_64.c
  10021. +++ b/arch/sparc/kernel/unaligned_64.c
  10022. @@ -166,17 +166,23 @@ static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
  10023. unsigned long compute_effective_address(struct pt_regs *regs,
  10024. unsigned int insn, unsigned int rd)
  10025. {
  10026. + int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  10027. unsigned int rs1 = (insn >> 14) & 0x1f;
  10028. unsigned int rs2 = insn & 0x1f;
  10029. - int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  10030. + unsigned long addr;
  10031. if (insn & 0x2000) {
  10032. maybe_flush_windows(rs1, 0, rd, from_kernel);
  10033. - return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
  10034. + addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
  10035. } else {
  10036. maybe_flush_windows(rs1, rs2, rd, from_kernel);
  10037. - return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
  10038. + addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
  10039. }
  10040. +
  10041. + if (!from_kernel && test_thread_flag(TIF_32BIT))
  10042. + addr &= 0xffffffff;
  10043. +
  10044. + return addr;
  10045. }
  10046. /* This is just to make gcc think die_if_kernel does return... */
  10047. @@ -289,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
  10048. static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
  10049. if (__ratelimit(&ratelimit)) {
  10050. - printk("Kernel unaligned access at TPC[%lx] %pS\n",
  10051. + printk("Kernel unaligned access at TPC[%lx] %pA\n",
  10052. regs->tpc, (void *) regs->tpc);
  10053. }
  10054. }
  10055. diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
  10056. index dbe119b..089c7c1 100644
  10057. --- a/arch/sparc/lib/Makefile
  10058. +++ b/arch/sparc/lib/Makefile
  10059. @@ -2,7 +2,7 @@
  10060. #
  10061. asflags-y := -ansi -DST_DIV0=0x02
  10062. -ccflags-y := -Werror
  10063. +#ccflags-y := -Werror
  10064. lib-$(CONFIG_SPARC32) += ashrdi3.o
  10065. lib-$(CONFIG_SPARC32) += memcpy.o memset.o
  10066. diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
  10067. index 85c233d..68500e0 100644
  10068. --- a/arch/sparc/lib/atomic_64.S
  10069. +++ b/arch/sparc/lib/atomic_64.S
  10070. @@ -17,7 +17,12 @@
  10071. ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
  10072. BACKOFF_SETUP(%o2)
  10073. 1: lduw [%o1], %g1
  10074. - add %g1, %o0, %g7
  10075. + addcc %g1, %o0, %g7
  10076. +
  10077. +#ifdef CONFIG_PAX_REFCOUNT
  10078. + tvs %icc, 6
  10079. +#endif
  10080. +
  10081. cas [%o1], %g1, %g7
  10082. cmp %g1, %g7
  10083. bne,pn %icc, BACKOFF_LABEL(2f, 1b)
  10084. @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
  10085. 2: BACKOFF_SPIN(%o2, %o3, 1b)
  10086. ENDPROC(atomic_add)
  10087. +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
  10088. + BACKOFF_SETUP(%o2)
  10089. +1: lduw [%o1], %g1
  10090. + add %g1, %o0, %g7
  10091. + cas [%o1], %g1, %g7
  10092. + cmp %g1, %g7
  10093. + bne,pn %icc, 2f
  10094. + nop
  10095. + retl
  10096. + nop
  10097. +2: BACKOFF_SPIN(%o2, %o3, 1b)
  10098. +ENDPROC(atomic_add_unchecked)
  10099. +
  10100. ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
  10101. BACKOFF_SETUP(%o2)
  10102. 1: lduw [%o1], %g1
  10103. - sub %g1, %o0, %g7
  10104. + subcc %g1, %o0, %g7
  10105. +
  10106. +#ifdef CONFIG_PAX_REFCOUNT
  10107. + tvs %icc, 6
  10108. +#endif
  10109. +
  10110. cas [%o1], %g1, %g7
  10111. cmp %g1, %g7
  10112. bne,pn %icc, BACKOFF_LABEL(2f, 1b)
  10113. @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
  10114. 2: BACKOFF_SPIN(%o2, %o3, 1b)
  10115. ENDPROC(atomic_sub)
  10116. +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
  10117. + BACKOFF_SETUP(%o2)
  10118. +1: lduw [%o1], %g1
  10119. + sub %g1, %o0, %g7
  10120. + cas [%o1], %g1, %g7
  10121. + cmp %g1, %g7
  10122. + bne,pn %icc, 2f
  10123. + nop
  10124. + retl
  10125. + nop
  10126. +2: BACKOFF_SPIN(%o2, %o3, 1b)
  10127. +ENDPROC(atomic_sub_unchecked)
  10128. +
  10129. ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
  10130. BACKOFF_SETUP(%o2)
  10131. 1: lduw [%o1], %g1
  10132. - add %g1, %o0, %g7
  10133. + addcc %g1, %o0, %g7
  10134. +
  10135. +#ifdef CONFIG_PAX_REFCOUNT
  10136. + tvs %icc, 6
  10137. +#endif
  10138. +
  10139. cas [%o1], %g1, %g7
  10140. cmp %g1, %g7
  10141. bne,pn %icc, BACKOFF_LABEL(2f, 1b)
  10142. @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
  10143. 2: BACKOFF_SPIN(%o2, %o3, 1b)
  10144. ENDPROC(atomic_add_ret)
  10145. +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
  10146. + BACKOFF_SETUP(%o2)
  10147. +1: lduw [%o1], %g1
  10148. + addcc %g1, %o0, %g7
  10149. + cas [%o1], %g1, %g7
  10150. + cmp %g1, %g7
  10151. + bne,pn %icc, 2f
  10152. + add %g7, %o0, %g7
  10153. + sra %g7, 0, %o0
  10154. + retl
  10155. + nop
  10156. +2: BACKOFF_SPIN(%o2, %o3, 1b)
  10157. +ENDPROC(atomic_add_ret_unchecked)
  10158. +
  10159. ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
  10160. BACKOFF_SETUP(%o2)
  10161. 1: lduw [%o1], %g1
  10162. - sub %g1, %o0, %g7
  10163. + subcc %g1, %o0, %g7
  10164. +
  10165. +#ifdef CONFIG_PAX_REFCOUNT
  10166. + tvs %icc, 6
  10167. +#endif
  10168. +
  10169. cas [%o1], %g1, %g7
  10170. cmp %g1, %g7
  10171. bne,pn %icc, BACKOFF_LABEL(2f, 1b)
  10172. @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
  10173. ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
  10174. BACKOFF_SETUP(%o2)
  10175. 1: ldx [%o1], %g1
  10176. - add %g1, %o0, %g7
  10177. + addcc %g1, %o0, %g7
  10178. +
  10179. +#ifdef CONFIG_PAX_REFCOUNT
  10180. + tvs %xcc, 6
  10181. +#endif
  10182. +
  10183. casx [%o1], %g1, %g7
  10184. cmp %g1, %g7
  10185. bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
  10186. @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
  10187. 2: BACKOFF_SPIN(%o2, %o3, 1b)
  10188. ENDPROC(atomic64_add)
  10189. +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
  10190. + BACKOFF_SETUP(%o2)
  10191. +1: ldx [%o1], %g1
  10192. + addcc %g1, %o0, %g7
  10193. + casx [%o1], %g1, %g7
  10194. + cmp %g1, %g7
  10195. + bne,pn %xcc, 2f
  10196. + nop
  10197. + retl
  10198. + nop
  10199. +2: BACKOFF_SPIN(%o2, %o3, 1b)
  10200. +ENDPROC(atomic64_add_unchecked)
  10201. +
  10202. ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
  10203. BACKOFF_SETUP(%o2)
  10204. 1: ldx [%o1], %g1
  10205. - sub %g1, %o0, %g7
  10206. + subcc %g1, %o0, %g7
  10207. +
  10208. +#ifdef CONFIG_PAX_REFCOUNT
  10209. + tvs %xcc, 6
  10210. +#endif
  10211. +
  10212. casx [%o1], %g1, %g7
  10213. cmp %g1, %g7
  10214. bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
  10215. @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
  10216. 2: BACKOFF_SPIN(%o2, %o3, 1b)
  10217. ENDPROC(atomic64_sub)
  10218. +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
  10219. + BACKOFF_SETUP(%o2)
  10220. +1: ldx [%o1], %g1
  10221. + subcc %g1, %o0, %g7
  10222. + casx [%o1], %g1, %g7
  10223. + cmp %g1, %g7
  10224. + bne,pn %xcc, 2f
  10225. + nop
  10226. + retl
  10227. + nop
  10228. +2: BACKOFF_SPIN(%o2, %o3, 1b)
  10229. +ENDPROC(atomic64_sub_unchecked)
  10230. +
  10231. ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
  10232. BACKOFF_SETUP(%o2)
  10233. 1: ldx [%o1], %g1
  10234. - add %g1, %o0, %g7
  10235. + addcc %g1, %o0, %g7
  10236. +
  10237. +#ifdef CONFIG_PAX_REFCOUNT
  10238. + tvs %xcc, 6
  10239. +#endif
  10240. +
  10241. casx [%o1], %g1, %g7
  10242. cmp %g1, %g7
  10243. bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
  10244. @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
  10245. 2: BACKOFF_SPIN(%o2, %o3, 1b)
  10246. ENDPROC(atomic64_add_ret)
  10247. +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
  10248. + BACKOFF_SETUP(%o2)
  10249. +1: ldx [%o1], %g1
  10250. + addcc %g1, %o0, %g7
  10251. + casx [%o1], %g1, %g7
  10252. + cmp %g1, %g7
  10253. + bne,pn %xcc, 2f
  10254. + add %g7, %o0, %g7
  10255. + mov %g7, %o0
  10256. + retl
  10257. + nop
  10258. +2: BACKOFF_SPIN(%o2, %o3, 1b)
  10259. +ENDPROC(atomic64_add_ret_unchecked)
  10260. +
  10261. ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
  10262. BACKOFF_SETUP(%o2)
  10263. 1: ldx [%o1], %g1
  10264. - sub %g1, %o0, %g7
  10265. + subcc %g1, %o0, %g7
  10266. +
  10267. +#ifdef CONFIG_PAX_REFCOUNT
  10268. + tvs %xcc, 6
  10269. +#endif
  10270. +
  10271. casx [%o1], %g1, %g7
  10272. cmp %g1, %g7
  10273. bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
  10274. diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
  10275. index 323335b..ed85ea2 100644
  10276. --- a/arch/sparc/lib/ksyms.c
  10277. +++ b/arch/sparc/lib/ksyms.c
  10278. @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
  10279. /* Atomic counter implementation. */
  10280. EXPORT_SYMBOL(atomic_add);
  10281. +EXPORT_SYMBOL(atomic_add_unchecked);
  10282. EXPORT_SYMBOL(atomic_add_ret);
  10283. +EXPORT_SYMBOL(atomic_add_ret_unchecked);
  10284. EXPORT_SYMBOL(atomic_sub);
  10285. +EXPORT_SYMBOL(atomic_sub_unchecked);
  10286. EXPORT_SYMBOL(atomic_sub_ret);
  10287. EXPORT_SYMBOL(atomic64_add);
  10288. +EXPORT_SYMBOL(atomic64_add_unchecked);
  10289. EXPORT_SYMBOL(atomic64_add_ret);
  10290. +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
  10291. EXPORT_SYMBOL(atomic64_sub);
  10292. +EXPORT_SYMBOL(atomic64_sub_unchecked);
  10293. EXPORT_SYMBOL(atomic64_sub_ret);
  10294. EXPORT_SYMBOL(atomic64_dec_if_positive);
  10295. diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
  10296. index 30c3ecc..736f015 100644
  10297. --- a/arch/sparc/mm/Makefile
  10298. +++ b/arch/sparc/mm/Makefile
  10299. @@ -2,7 +2,7 @@
  10300. #
  10301. asflags-y := -ansi
  10302. -ccflags-y := -Werror
  10303. +#ccflags-y := -Werror
  10304. obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
  10305. obj-y += fault_$(BITS).o
  10306. diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
  10307. index 59dbd46..1dd7f5e 100644
  10308. --- a/arch/sparc/mm/fault_32.c
  10309. +++ b/arch/sparc/mm/fault_32.c
  10310. @@ -21,6 +21,9 @@
  10311. #include <linux/perf_event.h>
  10312. #include <linux/interrupt.h>
  10313. #include <linux/kdebug.h>
  10314. +#include <linux/slab.h>
  10315. +#include <linux/pagemap.h>
  10316. +#include <linux/compiler.h>
  10317. #include <asm/page.h>
  10318. #include <asm/pgtable.h>
  10319. @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
  10320. return safe_compute_effective_address(regs, insn);
  10321. }
  10322. +#ifdef CONFIG_PAX_PAGEEXEC
  10323. +#ifdef CONFIG_PAX_DLRESOLVE
  10324. +static void pax_emuplt_close(struct vm_area_struct *vma)
  10325. +{
  10326. + vma->vm_mm->call_dl_resolve = 0UL;
  10327. +}
  10328. +
  10329. +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  10330. +{
  10331. + unsigned int *kaddr;
  10332. +
  10333. + vmf->page = alloc_page(GFP_HIGHUSER);
  10334. + if (!vmf->page)
  10335. + return VM_FAULT_OOM;
  10336. +
  10337. + kaddr = kmap(vmf->page);
  10338. + memset(kaddr, 0, PAGE_SIZE);
  10339. + kaddr[0] = 0x9DE3BFA8U; /* save */
  10340. + flush_dcache_page(vmf->page);
  10341. + kunmap(vmf->page);
  10342. + return VM_FAULT_MAJOR;
  10343. +}
  10344. +
  10345. +static const struct vm_operations_struct pax_vm_ops = {
  10346. + .close = pax_emuplt_close,
  10347. + .fault = pax_emuplt_fault
  10348. +};
  10349. +
  10350. +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
  10351. +{
  10352. + int ret;
  10353. +
  10354. + INIT_LIST_HEAD(&vma->anon_vma_chain);
  10355. + vma->vm_mm = current->mm;
  10356. + vma->vm_start = addr;
  10357. + vma->vm_end = addr + PAGE_SIZE;
  10358. + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
  10359. + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  10360. + vma->vm_ops = &pax_vm_ops;
  10361. +
  10362. + ret = insert_vm_struct(current->mm, vma);
  10363. + if (ret)
  10364. + return ret;
  10365. +
  10366. + ++current->mm->total_vm;
  10367. + return 0;
  10368. +}
  10369. +#endif
  10370. +
  10371. +/*
  10372. + * PaX: decide what to do with offenders (regs->pc = fault address)
  10373. + *
  10374. + * returns 1 when task should be killed
  10375. + * 2 when patched PLT trampoline was detected
  10376. + * 3 when unpatched PLT trampoline was detected
  10377. + */
  10378. +static int pax_handle_fetch_fault(struct pt_regs *regs)
  10379. +{
  10380. +
  10381. +#ifdef CONFIG_PAX_EMUPLT
  10382. + int err;
  10383. +
  10384. + do { /* PaX: patched PLT emulation #1 */
  10385. + unsigned int sethi1, sethi2, jmpl;
  10386. +
  10387. + err = get_user(sethi1, (unsigned int *)regs->pc);
  10388. + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
  10389. + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
  10390. +
  10391. + if (err)
  10392. + break;
  10393. +
  10394. + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
  10395. + (sethi2 & 0xFFC00000U) == 0x03000000U &&
  10396. + (jmpl & 0xFFFFE000U) == 0x81C06000U)
  10397. + {
  10398. + unsigned int addr;
  10399. +
  10400. + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
  10401. + addr = regs->u_regs[UREG_G1];
  10402. + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
  10403. + regs->pc = addr;
  10404. + regs->npc = addr+4;
  10405. + return 2;
  10406. + }
  10407. + } while (0);
  10408. +
  10409. + do { /* PaX: patched PLT emulation #2 */
  10410. + unsigned int ba;
  10411. +
  10412. + err = get_user(ba, (unsigned int *)regs->pc);
  10413. +
  10414. + if (err)
  10415. + break;
  10416. +
  10417. + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
  10418. + unsigned int addr;
  10419. +
  10420. + if ((ba & 0xFFC00000U) == 0x30800000U)
  10421. + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
  10422. + else
  10423. + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
  10424. + regs->pc = addr;
  10425. + regs->npc = addr+4;
  10426. + return 2;
  10427. + }
  10428. + } while (0);
  10429. +
  10430. + do { /* PaX: patched PLT emulation #3 */
  10431. + unsigned int sethi, bajmpl, nop;
  10432. +
  10433. + err = get_user(sethi, (unsigned int *)regs->pc);
  10434. + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
  10435. + err |= get_user(nop, (unsigned int *)(regs->pc+8));
  10436. +
  10437. + if (err)
  10438. + break;
  10439. +
  10440. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  10441. + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
  10442. + nop == 0x01000000U)
  10443. + {
  10444. + unsigned int addr;
  10445. +
  10446. + addr = (sethi & 0x003FFFFFU) << 10;
  10447. + regs->u_regs[UREG_G1] = addr;
  10448. + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
  10449. + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
  10450. + else
  10451. + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
  10452. + regs->pc = addr;
  10453. + regs->npc = addr+4;
  10454. + return 2;
  10455. + }
  10456. + } while (0);
  10457. +
  10458. + do { /* PaX: unpatched PLT emulation step 1 */
  10459. + unsigned int sethi, ba, nop;
  10460. +
  10461. + err = get_user(sethi, (unsigned int *)regs->pc);
  10462. + err |= get_user(ba, (unsigned int *)(regs->pc+4));
  10463. + err |= get_user(nop, (unsigned int *)(regs->pc+8));
  10464. +
  10465. + if (err)
  10466. + break;
  10467. +
  10468. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  10469. + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
  10470. + nop == 0x01000000U)
  10471. + {
  10472. + unsigned int addr, save, call;
  10473. +
  10474. + if ((ba & 0xFFC00000U) == 0x30800000U)
  10475. + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
  10476. + else
  10477. + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
  10478. +
  10479. + err = get_user(save, (unsigned int *)addr);
  10480. + err |= get_user(call, (unsigned int *)(addr+4));
  10481. + err |= get_user(nop, (unsigned int *)(addr+8));
  10482. + if (err)
  10483. + break;
  10484. +
  10485. +#ifdef CONFIG_PAX_DLRESOLVE
  10486. + if (save == 0x9DE3BFA8U &&
  10487. + (call & 0xC0000000U) == 0x40000000U &&
  10488. + nop == 0x01000000U)
  10489. + {
  10490. + struct vm_area_struct *vma;
  10491. + unsigned long call_dl_resolve;
  10492. +
  10493. + down_read(&current->mm->mmap_sem);
  10494. + call_dl_resolve = current->mm->call_dl_resolve;
  10495. + up_read(&current->mm->mmap_sem);
  10496. + if (likely(call_dl_resolve))
  10497. + goto emulate;
  10498. +
  10499. + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  10500. +
  10501. + down_write(&current->mm->mmap_sem);
  10502. + if (current->mm->call_dl_resolve) {
  10503. + call_dl_resolve = current->mm->call_dl_resolve;
  10504. + up_write(&current->mm->mmap_sem);
  10505. + if (vma)
  10506. + kmem_cache_free(vm_area_cachep, vma);
  10507. + goto emulate;
  10508. + }
  10509. +
  10510. + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
  10511. + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
  10512. + up_write(&current->mm->mmap_sem);
  10513. + if (vma)
  10514. + kmem_cache_free(vm_area_cachep, vma);
  10515. + return 1;
  10516. + }
  10517. +
  10518. + if (pax_insert_vma(vma, call_dl_resolve)) {
  10519. + up_write(&current->mm->mmap_sem);
  10520. + kmem_cache_free(vm_area_cachep, vma);
  10521. + return 1;
  10522. + }
  10523. +
  10524. + current->mm->call_dl_resolve = call_dl_resolve;
  10525. + up_write(&current->mm->mmap_sem);
  10526. +
  10527. +emulate:
  10528. + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
  10529. + regs->pc = call_dl_resolve;
  10530. + regs->npc = addr+4;
  10531. + return 3;
  10532. + }
  10533. +#endif
  10534. +
  10535. + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
  10536. + if ((save & 0xFFC00000U) == 0x05000000U &&
  10537. + (call & 0xFFFFE000U) == 0x85C0A000U &&
  10538. + nop == 0x01000000U)
  10539. + {
  10540. + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
  10541. + regs->u_regs[UREG_G2] = addr + 4;
  10542. + addr = (save & 0x003FFFFFU) << 10;
  10543. + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
  10544. + regs->pc = addr;
  10545. + regs->npc = addr+4;
  10546. + return 3;
  10547. + }
  10548. + }
  10549. + } while (0);
  10550. +
  10551. + do { /* PaX: unpatched PLT emulation step 2 */
  10552. + unsigned int save, call, nop;
  10553. +
  10554. + err = get_user(save, (unsigned int *)(regs->pc-4));
  10555. + err |= get_user(call, (unsigned int *)regs->pc);
  10556. + err |= get_user(nop, (unsigned int *)(regs->pc+4));
  10557. + if (err)
  10558. + break;
  10559. +
  10560. + if (save == 0x9DE3BFA8U &&
  10561. + (call & 0xC0000000U) == 0x40000000U &&
  10562. + nop == 0x01000000U)
  10563. + {
  10564. + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
  10565. +
  10566. + regs->u_regs[UREG_RETPC] = regs->pc;
  10567. + regs->pc = dl_resolve;
  10568. + regs->npc = dl_resolve+4;
  10569. + return 3;
  10570. + }
  10571. + } while (0);
  10572. +#endif
  10573. +
  10574. + return 1;
  10575. +}
  10576. +
  10577. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  10578. +{
  10579. + unsigned long i;
  10580. +
  10581. + printk(KERN_ERR "PAX: bytes at PC: ");
  10582. + for (i = 0; i < 8; i++) {
  10583. + unsigned int c;
  10584. + if (get_user(c, (unsigned int *)pc+i))
  10585. + printk(KERN_CONT "???????? ");
  10586. + else
  10587. + printk(KERN_CONT "%08x ", c);
  10588. + }
  10589. + printk("\n");
  10590. +}
  10591. +#endif
  10592. +
  10593. static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
  10594. int text_fault)
  10595. {
  10596. @@ -229,6 +503,24 @@ good_area:
  10597. if (!(vma->vm_flags & VM_WRITE))
  10598. goto bad_area;
  10599. } else {
  10600. +
  10601. +#ifdef CONFIG_PAX_PAGEEXEC
  10602. + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
  10603. + up_read(&mm->mmap_sem);
  10604. + switch (pax_handle_fetch_fault(regs)) {
  10605. +
  10606. +#ifdef CONFIG_PAX_EMUPLT
  10607. + case 2:
  10608. + case 3:
  10609. + return;
  10610. +#endif
  10611. +
  10612. + }
  10613. + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
  10614. + do_group_exit(SIGKILL);
  10615. + }
  10616. +#endif
  10617. +
  10618. /* Allow reads even for write-only mappings */
  10619. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  10620. goto bad_area;
  10621. diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
  10622. index 69bb818..3542236 100644
  10623. --- a/arch/sparc/mm/fault_64.c
  10624. +++ b/arch/sparc/mm/fault_64.c
  10625. @@ -22,6 +22,9 @@
  10626. #include <linux/kdebug.h>
  10627. #include <linux/percpu.h>
  10628. #include <linux/context_tracking.h>
  10629. +#include <linux/slab.h>
  10630. +#include <linux/pagemap.h>
  10631. +#include <linux/compiler.h>
  10632. #include <asm/page.h>
  10633. #include <asm/pgtable.h>
  10634. @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
  10635. printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
  10636. regs->tpc);
  10637. printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
  10638. - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
  10639. + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
  10640. printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
  10641. dump_stack();
  10642. unhandled_fault(regs->tpc, current, regs);
  10643. @@ -96,38 +99,51 @@ static unsigned int get_user_insn(unsigned long tpc)
  10644. pte_t *ptep, pte;
  10645. unsigned long pa;
  10646. u32 insn = 0;
  10647. - unsigned long pstate;
  10648. - if (pgd_none(*pgdp))
  10649. - goto outret;
  10650. + if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
  10651. + goto out;
  10652. pudp = pud_offset(pgdp, tpc);
  10653. - if (pud_none(*pudp))
  10654. - goto outret;
  10655. - pmdp = pmd_offset(pudp, tpc);
  10656. - if (pmd_none(*pmdp))
  10657. - goto outret;
  10658. + if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
  10659. + goto out;
  10660. /* This disables preemption for us as well. */
  10661. - __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  10662. - __asm__ __volatile__("wrpr %0, %1, %%pstate"
  10663. - : : "r" (pstate), "i" (PSTATE_IE));
  10664. - ptep = pte_offset_map(pmdp, tpc);
  10665. - pte = *ptep;
  10666. - if (!pte_present(pte))
  10667. - goto out;
  10668. + local_irq_disable();
  10669. - pa = (pte_pfn(pte) << PAGE_SHIFT);
  10670. - pa += (tpc & ~PAGE_MASK);
  10671. + pmdp = pmd_offset(pudp, tpc);
  10672. + if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
  10673. + goto out_irq_enable;
  10674. - /* Use phys bypass so we don't pollute dtlb/dcache. */
  10675. - __asm__ __volatile__("lduwa [%1] %2, %0"
  10676. - : "=r" (insn)
  10677. - : "r" (pa), "i" (ASI_PHYS_USE_EC));
  10678. +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
  10679. + if (pmd_trans_huge(*pmdp)) {
  10680. + if (pmd_trans_splitting(*pmdp))
  10681. + goto out_irq_enable;
  10682. + pa = pmd_pfn(*pmdp) << PAGE_SHIFT;
  10683. + pa += tpc & ~HPAGE_MASK;
  10684. +
  10685. + /* Use phys bypass so we don't pollute dtlb/dcache. */
  10686. + __asm__ __volatile__("lduwa [%1] %2, %0"
  10687. + : "=r" (insn)
  10688. + : "r" (pa), "i" (ASI_PHYS_USE_EC));
  10689. + } else
  10690. +#endif
  10691. + {
  10692. + ptep = pte_offset_map(pmdp, tpc);
  10693. + pte = *ptep;
  10694. + if (pte_present(pte)) {
  10695. + pa = (pte_pfn(pte) << PAGE_SHIFT);
  10696. + pa += (tpc & ~PAGE_MASK);
  10697. +
  10698. + /* Use phys bypass so we don't pollute dtlb/dcache. */
  10699. + __asm__ __volatile__("lduwa [%1] %2, %0"
  10700. + : "=r" (insn)
  10701. + : "r" (pa), "i" (ASI_PHYS_USE_EC));
  10702. + }
  10703. + pte_unmap(ptep);
  10704. + }
  10705. +out_irq_enable:
  10706. + local_irq_enable();
  10707. out:
  10708. - pte_unmap(ptep);
  10709. - __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
  10710. -outret:
  10711. return insn;
  10712. }
  10713. @@ -153,7 +169,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code,
  10714. }
  10715. static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
  10716. - unsigned int insn, int fault_code)
  10717. + unsigned long fault_addr, unsigned int insn,
  10718. + int fault_code)
  10719. {
  10720. unsigned long addr;
  10721. siginfo_t info;
  10722. @@ -161,10 +178,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
  10723. info.si_code = code;
  10724. info.si_signo = sig;
  10725. info.si_errno = 0;
  10726. - if (fault_code & FAULT_CODE_ITLB)
  10727. + if (fault_code & FAULT_CODE_ITLB) {
  10728. addr = regs->tpc;
  10729. - else
  10730. - addr = compute_effective_address(regs, insn, 0);
  10731. + } else {
  10732. + /* If we were able to probe the faulting instruction, use it
  10733. + * to compute a precise fault address. Otherwise use the fault
  10734. + * time provided address which may only have page granularity.
  10735. + */
  10736. + if (insn)
  10737. + addr = compute_effective_address(regs, insn, 0);
  10738. + else
  10739. + addr = fault_addr;
  10740. + }
  10741. info.si_addr = (void __user *) addr;
  10742. info.si_trapno = 0;
  10743. @@ -239,7 +264,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
  10744. /* The si_code was set to make clear whether
  10745. * this was a SEGV_MAPERR or SEGV_ACCERR fault.
  10746. */
  10747. - do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code);
  10748. + do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
  10749. return;
  10750. }
  10751. @@ -271,6 +296,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
  10752. show_regs(regs);
  10753. }
  10754. +#ifdef CONFIG_PAX_PAGEEXEC
  10755. +#ifdef CONFIG_PAX_DLRESOLVE
  10756. +static void pax_emuplt_close(struct vm_area_struct *vma)
  10757. +{
  10758. + vma->vm_mm->call_dl_resolve = 0UL;
  10759. +}
  10760. +
  10761. +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  10762. +{
  10763. + unsigned int *kaddr;
  10764. +
  10765. + vmf->page = alloc_page(GFP_HIGHUSER);
  10766. + if (!vmf->page)
  10767. + return VM_FAULT_OOM;
  10768. +
  10769. + kaddr = kmap(vmf->page);
  10770. + memset(kaddr, 0, PAGE_SIZE);
  10771. + kaddr[0] = 0x9DE3BFA8U; /* save */
  10772. + flush_dcache_page(vmf->page);
  10773. + kunmap(vmf->page);
  10774. + return VM_FAULT_MAJOR;
  10775. +}
  10776. +
  10777. +static const struct vm_operations_struct pax_vm_ops = {
  10778. + .close = pax_emuplt_close,
  10779. + .fault = pax_emuplt_fault
  10780. +};
  10781. +
  10782. +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
  10783. +{
  10784. + int ret;
  10785. +
  10786. + INIT_LIST_HEAD(&vma->anon_vma_chain);
  10787. + vma->vm_mm = current->mm;
  10788. + vma->vm_start = addr;
  10789. + vma->vm_end = addr + PAGE_SIZE;
  10790. + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
  10791. + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  10792. + vma->vm_ops = &pax_vm_ops;
  10793. +
  10794. + ret = insert_vm_struct(current->mm, vma);
  10795. + if (ret)
  10796. + return ret;
  10797. +
  10798. + ++current->mm->total_vm;
  10799. + return 0;
  10800. +}
  10801. +#endif
  10802. +
  10803. +/*
  10804. + * PaX: decide what to do with offenders (regs->tpc = fault address)
  10805. + *
  10806. + * returns 1 when task should be killed
  10807. + * 2 when patched PLT trampoline was detected
  10808. + * 3 when unpatched PLT trampoline was detected
  10809. + */
  10810. +static int pax_handle_fetch_fault(struct pt_regs *regs)
  10811. +{
  10812. +
  10813. +#ifdef CONFIG_PAX_EMUPLT
  10814. + int err;
  10815. +
  10816. + do { /* PaX: patched PLT emulation #1 */
  10817. + unsigned int sethi1, sethi2, jmpl;
  10818. +
  10819. + err = get_user(sethi1, (unsigned int *)regs->tpc);
  10820. + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
  10821. + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
  10822. +
  10823. + if (err)
  10824. + break;
  10825. +
  10826. + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
  10827. + (sethi2 & 0xFFC00000U) == 0x03000000U &&
  10828. + (jmpl & 0xFFFFE000U) == 0x81C06000U)
  10829. + {
  10830. + unsigned long addr;
  10831. +
  10832. + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
  10833. + addr = regs->u_regs[UREG_G1];
  10834. + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
  10835. +
  10836. + if (test_thread_flag(TIF_32BIT))
  10837. + addr &= 0xFFFFFFFFUL;
  10838. +
  10839. + regs->tpc = addr;
  10840. + regs->tnpc = addr+4;
  10841. + return 2;
  10842. + }
  10843. + } while (0);
  10844. +
  10845. + do { /* PaX: patched PLT emulation #2 */
  10846. + unsigned int ba;
  10847. +
  10848. + err = get_user(ba, (unsigned int *)regs->tpc);
  10849. +
  10850. + if (err)
  10851. + break;
  10852. +
  10853. + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
  10854. + unsigned long addr;
  10855. +
  10856. + if ((ba & 0xFFC00000U) == 0x30800000U)
  10857. + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
  10858. + else
  10859. + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
  10860. +
  10861. + if (test_thread_flag(TIF_32BIT))
  10862. + addr &= 0xFFFFFFFFUL;
  10863. +
  10864. + regs->tpc = addr;
  10865. + regs->tnpc = addr+4;
  10866. + return 2;
  10867. + }
  10868. + } while (0);
  10869. +
  10870. + do { /* PaX: patched PLT emulation #3 */
  10871. + unsigned int sethi, bajmpl, nop;
  10872. +
  10873. + err = get_user(sethi, (unsigned int *)regs->tpc);
  10874. + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
  10875. + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
  10876. +
  10877. + if (err)
  10878. + break;
  10879. +
  10880. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  10881. + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
  10882. + nop == 0x01000000U)
  10883. + {
  10884. + unsigned long addr;
  10885. +
  10886. + addr = (sethi & 0x003FFFFFU) << 10;
  10887. + regs->u_regs[UREG_G1] = addr;
  10888. + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
  10889. + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
  10890. + else
  10891. + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
  10892. +
  10893. + if (test_thread_flag(TIF_32BIT))
  10894. + addr &= 0xFFFFFFFFUL;
  10895. +
  10896. + regs->tpc = addr;
  10897. + regs->tnpc = addr+4;
  10898. + return 2;
  10899. + }
  10900. + } while (0);
  10901. +
  10902. + do { /* PaX: patched PLT emulation #4 */
  10903. + unsigned int sethi, mov1, call, mov2;
  10904. +
  10905. + err = get_user(sethi, (unsigned int *)regs->tpc);
  10906. + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
  10907. + err |= get_user(call, (unsigned int *)(regs->tpc+8));
  10908. + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
  10909. +
  10910. + if (err)
  10911. + break;
  10912. +
  10913. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  10914. + mov1 == 0x8210000FU &&
  10915. + (call & 0xC0000000U) == 0x40000000U &&
  10916. + mov2 == 0x9E100001U)
  10917. + {
  10918. + unsigned long addr;
  10919. +
  10920. + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
  10921. + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
  10922. +
  10923. + if (test_thread_flag(TIF_32BIT))
  10924. + addr &= 0xFFFFFFFFUL;
  10925. +
  10926. + regs->tpc = addr;
  10927. + regs->tnpc = addr+4;
  10928. + return 2;
  10929. + }
  10930. + } while (0);
  10931. +
  10932. + do { /* PaX: patched PLT emulation #5 */
  10933. + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
  10934. +
  10935. + err = get_user(sethi, (unsigned int *)regs->tpc);
  10936. + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
  10937. + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
  10938. + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
  10939. + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
  10940. + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
  10941. + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
  10942. + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
  10943. +
  10944. + if (err)
  10945. + break;
  10946. +
  10947. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  10948. + (sethi1 & 0xFFC00000U) == 0x03000000U &&
  10949. + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
  10950. + (or1 & 0xFFFFE000U) == 0x82106000U &&
  10951. + (or2 & 0xFFFFE000U) == 0x8A116000U &&
  10952. + sllx == 0x83287020U &&
  10953. + jmpl == 0x81C04005U &&
  10954. + nop == 0x01000000U)
  10955. + {
  10956. + unsigned long addr;
  10957. +
  10958. + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
  10959. + regs->u_regs[UREG_G1] <<= 32;
  10960. + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
  10961. + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
  10962. + regs->tpc = addr;
  10963. + regs->tnpc = addr+4;
  10964. + return 2;
  10965. + }
  10966. + } while (0);
  10967. +
  10968. + do { /* PaX: patched PLT emulation #6 */
  10969. + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
  10970. +
  10971. + err = get_user(sethi, (unsigned int *)regs->tpc);
  10972. + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
  10973. + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
  10974. + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
  10975. + err |= get_user(or, (unsigned int *)(regs->tpc+16));
  10976. + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
  10977. + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
  10978. +
  10979. + if (err)
  10980. + break;
  10981. +
  10982. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  10983. + (sethi1 & 0xFFC00000U) == 0x03000000U &&
  10984. + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
  10985. + sllx == 0x83287020U &&
  10986. + (or & 0xFFFFE000U) == 0x8A116000U &&
  10987. + jmpl == 0x81C04005U &&
  10988. + nop == 0x01000000U)
  10989. + {
  10990. + unsigned long addr;
  10991. +
  10992. + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
  10993. + regs->u_regs[UREG_G1] <<= 32;
  10994. + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
  10995. + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
  10996. + regs->tpc = addr;
  10997. + regs->tnpc = addr+4;
  10998. + return 2;
  10999. + }
  11000. + } while (0);
  11001. +
  11002. + do { /* PaX: unpatched PLT emulation step 1 */
  11003. + unsigned int sethi, ba, nop;
  11004. +
  11005. + err = get_user(sethi, (unsigned int *)regs->tpc);
  11006. + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
  11007. + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
  11008. +
  11009. + if (err)
  11010. + break;
  11011. +
  11012. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  11013. + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
  11014. + nop == 0x01000000U)
  11015. + {
  11016. + unsigned long addr;
  11017. + unsigned int save, call;
  11018. + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
  11019. +
  11020. + if ((ba & 0xFFC00000U) == 0x30800000U)
  11021. + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
  11022. + else
  11023. + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
  11024. +
  11025. + if (test_thread_flag(TIF_32BIT))
  11026. + addr &= 0xFFFFFFFFUL;
  11027. +
  11028. + err = get_user(save, (unsigned int *)addr);
  11029. + err |= get_user(call, (unsigned int *)(addr+4));
  11030. + err |= get_user(nop, (unsigned int *)(addr+8));
  11031. + if (err)
  11032. + break;
  11033. +
  11034. +#ifdef CONFIG_PAX_DLRESOLVE
  11035. + if (save == 0x9DE3BFA8U &&
  11036. + (call & 0xC0000000U) == 0x40000000U &&
  11037. + nop == 0x01000000U)
  11038. + {
  11039. + struct vm_area_struct *vma;
  11040. + unsigned long call_dl_resolve;
  11041. +
  11042. + down_read(&current->mm->mmap_sem);
  11043. + call_dl_resolve = current->mm->call_dl_resolve;
  11044. + up_read(&current->mm->mmap_sem);
  11045. + if (likely(call_dl_resolve))
  11046. + goto emulate;
  11047. +
  11048. + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  11049. +
  11050. + down_write(&current->mm->mmap_sem);
  11051. + if (current->mm->call_dl_resolve) {
  11052. + call_dl_resolve = current->mm->call_dl_resolve;
  11053. + up_write(&current->mm->mmap_sem);
  11054. + if (vma)
  11055. + kmem_cache_free(vm_area_cachep, vma);
  11056. + goto emulate;
  11057. + }
  11058. +
  11059. + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
  11060. + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
  11061. + up_write(&current->mm->mmap_sem);
  11062. + if (vma)
  11063. + kmem_cache_free(vm_area_cachep, vma);
  11064. + return 1;
  11065. + }
  11066. +
  11067. + if (pax_insert_vma(vma, call_dl_resolve)) {
  11068. + up_write(&current->mm->mmap_sem);
  11069. + kmem_cache_free(vm_area_cachep, vma);
  11070. + return 1;
  11071. + }
  11072. +
  11073. + current->mm->call_dl_resolve = call_dl_resolve;
  11074. + up_write(&current->mm->mmap_sem);
  11075. +
  11076. +emulate:
  11077. + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
  11078. + regs->tpc = call_dl_resolve;
  11079. + regs->tnpc = addr+4;
  11080. + return 3;
  11081. + }
  11082. +#endif
  11083. +
  11084. + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
  11085. + if ((save & 0xFFC00000U) == 0x05000000U &&
  11086. + (call & 0xFFFFE000U) == 0x85C0A000U &&
  11087. + nop == 0x01000000U)
  11088. + {
  11089. + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
  11090. + regs->u_regs[UREG_G2] = addr + 4;
  11091. + addr = (save & 0x003FFFFFU) << 10;
  11092. + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
  11093. +
  11094. + if (test_thread_flag(TIF_32BIT))
  11095. + addr &= 0xFFFFFFFFUL;
  11096. +
  11097. + regs->tpc = addr;
  11098. + regs->tnpc = addr+4;
  11099. + return 3;
  11100. + }
  11101. +
  11102. + /* PaX: 64-bit PLT stub */
  11103. + err = get_user(sethi1, (unsigned int *)addr);
  11104. + err |= get_user(sethi2, (unsigned int *)(addr+4));
  11105. + err |= get_user(or1, (unsigned int *)(addr+8));
  11106. + err |= get_user(or2, (unsigned int *)(addr+12));
  11107. + err |= get_user(sllx, (unsigned int *)(addr+16));
  11108. + err |= get_user(add, (unsigned int *)(addr+20));
  11109. + err |= get_user(jmpl, (unsigned int *)(addr+24));
  11110. + err |= get_user(nop, (unsigned int *)(addr+28));
  11111. + if (err)
  11112. + break;
  11113. +
  11114. + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
  11115. + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
  11116. + (or1 & 0xFFFFE000U) == 0x88112000U &&
  11117. + (or2 & 0xFFFFE000U) == 0x8A116000U &&
  11118. + sllx == 0x89293020U &&
  11119. + add == 0x8A010005U &&
  11120. + jmpl == 0x89C14000U &&
  11121. + nop == 0x01000000U)
  11122. + {
  11123. + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
  11124. + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
  11125. + regs->u_regs[UREG_G4] <<= 32;
  11126. + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
  11127. + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
  11128. + regs->u_regs[UREG_G4] = addr + 24;
  11129. + addr = regs->u_regs[UREG_G5];
  11130. + regs->tpc = addr;
  11131. + regs->tnpc = addr+4;
  11132. + return 3;
  11133. + }
  11134. + }
  11135. + } while (0);
  11136. +
  11137. +#ifdef CONFIG_PAX_DLRESOLVE
  11138. + do { /* PaX: unpatched PLT emulation step 2 */
  11139. + unsigned int save, call, nop;
  11140. +
  11141. + err = get_user(save, (unsigned int *)(regs->tpc-4));
  11142. + err |= get_user(call, (unsigned int *)regs->tpc);
  11143. + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
  11144. + if (err)
  11145. + break;
  11146. +
  11147. + if (save == 0x9DE3BFA8U &&
  11148. + (call & 0xC0000000U) == 0x40000000U &&
  11149. + nop == 0x01000000U)
  11150. + {
  11151. + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
  11152. +
  11153. + if (test_thread_flag(TIF_32BIT))
  11154. + dl_resolve &= 0xFFFFFFFFUL;
  11155. +
  11156. + regs->u_regs[UREG_RETPC] = regs->tpc;
  11157. + regs->tpc = dl_resolve;
  11158. + regs->tnpc = dl_resolve+4;
  11159. + return 3;
  11160. + }
  11161. + } while (0);
  11162. +#endif
  11163. +
  11164. + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
  11165. + unsigned int sethi, ba, nop;
  11166. +
  11167. + err = get_user(sethi, (unsigned int *)regs->tpc);
  11168. + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
  11169. + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
  11170. +
  11171. + if (err)
  11172. + break;
  11173. +
  11174. + if ((sethi & 0xFFC00000U) == 0x03000000U &&
  11175. + (ba & 0xFFF00000U) == 0x30600000U &&
  11176. + nop == 0x01000000U)
  11177. + {
  11178. + unsigned long addr;
  11179. +
  11180. + addr = (sethi & 0x003FFFFFU) << 10;
  11181. + regs->u_regs[UREG_G1] = addr;
  11182. + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
  11183. +
  11184. + if (test_thread_flag(TIF_32BIT))
  11185. + addr &= 0xFFFFFFFFUL;
  11186. +
  11187. + regs->tpc = addr;
  11188. + regs->tnpc = addr+4;
  11189. + return 2;
  11190. + }
  11191. + } while (0);
  11192. +
  11193. +#endif
  11194. +
  11195. + return 1;
  11196. +}
  11197. +
  11198. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  11199. +{
  11200. + unsigned long i;
  11201. +
  11202. + printk(KERN_ERR "PAX: bytes at PC: ");
  11203. + for (i = 0; i < 8; i++) {
  11204. + unsigned int c;
  11205. + if (get_user(c, (unsigned int *)pc+i))
  11206. + printk(KERN_CONT "???????? ");
  11207. + else
  11208. + printk(KERN_CONT "%08x ", c);
  11209. + }
  11210. + printk("\n");
  11211. +}
  11212. +#endif
  11213. +
  11214. asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
  11215. {
  11216. enum ctx_state prev_state = exception_enter();
  11217. @@ -344,6 +829,29 @@ retry:
  11218. if (!vma)
  11219. goto bad_area;
  11220. +#ifdef CONFIG_PAX_PAGEEXEC
  11221. + /* PaX: detect ITLB misses on non-exec pages */
  11222. + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
  11223. + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
  11224. + {
  11225. + if (address != regs->tpc)
  11226. + goto good_area;
  11227. +
  11228. + up_read(&mm->mmap_sem);
  11229. + switch (pax_handle_fetch_fault(regs)) {
  11230. +
  11231. +#ifdef CONFIG_PAX_EMUPLT
  11232. + case 2:
  11233. + case 3:
  11234. + return;
  11235. +#endif
  11236. +
  11237. + }
  11238. + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
  11239. + do_group_exit(SIGKILL);
  11240. + }
  11241. +#endif
  11242. +
  11243. /* Pure DTLB misses do not tell us whether the fault causing
  11244. * load/store/atomic was a write or not, it only says that there
  11245. * was no match. So in such a case we (carefully) read the
  11246. @@ -525,7 +1033,7 @@ do_sigbus:
  11247. * Send a sigbus, regardless of whether we were in kernel
  11248. * or user mode.
  11249. */
  11250. - do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code);
  11251. + do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
  11252. /* Kernel mode? Handle exceptions or die */
  11253. if (regs->tstate & TSTATE_PRIV)
  11254. diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
  11255. index c4d3da6..1aed043 100644
  11256. --- a/arch/sparc/mm/gup.c
  11257. +++ b/arch/sparc/mm/gup.c
  11258. @@ -73,7 +73,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
  11259. struct page *head, *page, *tail;
  11260. int refs;
  11261. - if (!pmd_large(pmd))
  11262. + if (!(pmd_val(pmd) & _PAGE_VALID))
  11263. return 0;
  11264. if (write && !pmd_write(pmd))
  11265. diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
  11266. index 9bd9ce8..dc84852 100644
  11267. --- a/arch/sparc/mm/hugetlbpage.c
  11268. +++ b/arch/sparc/mm/hugetlbpage.c
  11269. @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
  11270. unsigned long addr,
  11271. unsigned long len,
  11272. unsigned long pgoff,
  11273. - unsigned long flags)
  11274. + unsigned long flags,
  11275. + unsigned long offset)
  11276. {
  11277. + struct mm_struct *mm = current->mm;
  11278. unsigned long task_size = TASK_SIZE;
  11279. struct vm_unmapped_area_info info;
  11280. @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
  11281. info.flags = 0;
  11282. info.length = len;
  11283. - info.low_limit = TASK_UNMAPPED_BASE;
  11284. + info.low_limit = mm->mmap_base;
  11285. info.high_limit = min(task_size, VA_EXCLUDE_START);
  11286. info.align_mask = PAGE_MASK & ~HPAGE_MASK;
  11287. info.align_offset = 0;
  11288. + info.threadstack_offset = offset;
  11289. addr = vm_unmapped_area(&info);
  11290. if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
  11291. VM_BUG_ON(addr != -ENOMEM);
  11292. info.low_limit = VA_EXCLUDE_END;
  11293. +
  11294. +#ifdef CONFIG_PAX_RANDMMAP
  11295. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  11296. + info.low_limit += mm->delta_mmap;
  11297. +#endif
  11298. +
  11299. info.high_limit = task_size;
  11300. addr = vm_unmapped_area(&info);
  11301. }
  11302. @@ -55,7 +64,8 @@ static unsigned long
  11303. hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  11304. const unsigned long len,
  11305. const unsigned long pgoff,
  11306. - const unsigned long flags)
  11307. + const unsigned long flags,
  11308. + const unsigned long offset)
  11309. {
  11310. struct mm_struct *mm = current->mm;
  11311. unsigned long addr = addr0;
  11312. @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  11313. info.high_limit = mm->mmap_base;
  11314. info.align_mask = PAGE_MASK & ~HPAGE_MASK;
  11315. info.align_offset = 0;
  11316. + info.threadstack_offset = offset;
  11317. addr = vm_unmapped_area(&info);
  11318. /*
  11319. @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  11320. VM_BUG_ON(addr != -ENOMEM);
  11321. info.flags = 0;
  11322. info.low_limit = TASK_UNMAPPED_BASE;
  11323. +
  11324. +#ifdef CONFIG_PAX_RANDMMAP
  11325. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  11326. + info.low_limit += mm->delta_mmap;
  11327. +#endif
  11328. +
  11329. info.high_limit = STACK_TOP32;
  11330. addr = vm_unmapped_area(&info);
  11331. }
  11332. @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  11333. struct mm_struct *mm = current->mm;
  11334. struct vm_area_struct *vma;
  11335. unsigned long task_size = TASK_SIZE;
  11336. + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
  11337. if (test_thread_flag(TIF_32BIT))
  11338. task_size = STACK_TOP32;
  11339. @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  11340. return addr;
  11341. }
  11342. +#ifdef CONFIG_PAX_RANDMMAP
  11343. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  11344. +#endif
  11345. +
  11346. if (addr) {
  11347. addr = ALIGN(addr, HPAGE_SIZE);
  11348. vma = find_vma(mm, addr);
  11349. - if (task_size - len >= addr &&
  11350. - (!vma || addr + len <= vma->vm_start))
  11351. + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  11352. return addr;
  11353. }
  11354. if (mm->get_unmapped_area == arch_get_unmapped_area)
  11355. return hugetlb_get_unmapped_area_bottomup(file, addr, len,
  11356. - pgoff, flags);
  11357. + pgoff, flags, offset);
  11358. else
  11359. return hugetlb_get_unmapped_area_topdown(file, addr, len,
  11360. - pgoff, flags);
  11361. + pgoff, flags, offset);
  11362. }
  11363. pte_t *huge_pte_alloc(struct mm_struct *mm,
  11364. diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
  11365. index eafbc65..5a8070d 100644
  11366. --- a/arch/sparc/mm/init_64.c
  11367. +++ b/arch/sparc/mm/init_64.c
  11368. @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
  11369. int num_kernel_image_mappings;
  11370. #ifdef CONFIG_DEBUG_DCFLUSH
  11371. -atomic_t dcpage_flushes = ATOMIC_INIT(0);
  11372. +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
  11373. #ifdef CONFIG_SMP
  11374. -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  11375. +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  11376. #endif
  11377. #endif
  11378. @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
  11379. {
  11380. BUG_ON(tlb_type == hypervisor);
  11381. #ifdef CONFIG_DEBUG_DCFLUSH
  11382. - atomic_inc(&dcpage_flushes);
  11383. + atomic_inc_unchecked(&dcpage_flushes);
  11384. #endif
  11385. #ifdef DCACHE_ALIASING_POSSIBLE
  11386. @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
  11387. #ifdef CONFIG_DEBUG_DCFLUSH
  11388. seq_printf(m, "DCPageFlushes\t: %d\n",
  11389. - atomic_read(&dcpage_flushes));
  11390. + atomic_read_unchecked(&dcpage_flushes));
  11391. #ifdef CONFIG_SMP
  11392. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  11393. - atomic_read(&dcpage_flushes_xcall));
  11394. + atomic_read_unchecked(&dcpage_flushes_xcall));
  11395. #endif /* CONFIG_SMP */
  11396. #endif /* CONFIG_DEBUG_DCFLUSH */
  11397. }
  11398. diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
  11399. index b12cb5e..b89aba2 100644
  11400. --- a/arch/sparc/mm/tlb.c
  11401. +++ b/arch/sparc/mm/tlb.c
  11402. @@ -134,7 +134,7 @@ no_cache_flush:
  11403. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  11404. static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
  11405. - pmd_t pmd, bool exec)
  11406. + pmd_t pmd)
  11407. {
  11408. unsigned long end;
  11409. pte_t *pte;
  11410. @@ -142,8 +142,11 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
  11411. pte = pte_offset_map(&pmd, vaddr);
  11412. end = vaddr + HPAGE_SIZE;
  11413. while (vaddr < end) {
  11414. - if (pte_val(*pte) & _PAGE_VALID)
  11415. + if (pte_val(*pte) & _PAGE_VALID) {
  11416. + bool exec = pte_exec(*pte);
  11417. +
  11418. tlb_batch_add_one(mm, vaddr, exec);
  11419. + }
  11420. pte++;
  11421. vaddr += PAGE_SIZE;
  11422. }
  11423. @@ -177,19 +180,30 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  11424. }
  11425. if (!pmd_none(orig)) {
  11426. - pte_t orig_pte = __pte(pmd_val(orig));
  11427. - bool exec = pte_exec(orig_pte);
  11428. -
  11429. addr &= HPAGE_MASK;
  11430. if (pmd_trans_huge(orig)) {
  11431. + pte_t orig_pte = __pte(pmd_val(orig));
  11432. + bool exec = pte_exec(orig_pte);
  11433. +
  11434. tlb_batch_add_one(mm, addr, exec);
  11435. tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec);
  11436. } else {
  11437. - tlb_batch_pmd_scan(mm, addr, orig, exec);
  11438. + tlb_batch_pmd_scan(mm, addr, orig);
  11439. }
  11440. }
  11441. }
  11442. +void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  11443. + pmd_t *pmdp)
  11444. +{
  11445. + pmd_t entry = *pmdp;
  11446. +
  11447. + pmd_val(entry) &= ~_PAGE_VALID;
  11448. +
  11449. + set_pmd_at(vma->vm_mm, address, pmdp, entry);
  11450. + flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  11451. +}
  11452. +
  11453. void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  11454. pgtable_t pgtable)
  11455. {
  11456. diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
  11457. index b3692ce..e4517c9 100644
  11458. --- a/arch/tile/Kconfig
  11459. +++ b/arch/tile/Kconfig
  11460. @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
  11461. config KEXEC
  11462. bool "kexec system call"
  11463. + depends on !GRKERNSEC_KMEM
  11464. ---help---
  11465. kexec is a system call that implements the ability to shutdown your
  11466. current kernel, and to start another kernel. It is like a reboot
  11467. diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
  11468. index ad220ee..2f537b3 100644
  11469. --- a/arch/tile/include/asm/atomic_64.h
  11470. +++ b/arch/tile/include/asm/atomic_64.h
  11471. @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
  11472. #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
  11473. +#define atomic64_read_unchecked(v) atomic64_read(v)
  11474. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  11475. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  11476. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  11477. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  11478. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  11479. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  11480. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  11481. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  11482. +
  11483. /* Atomic dec and inc don't implement barrier, so provide them if needed. */
  11484. #define smp_mb__before_atomic_dec() smp_mb()
  11485. #define smp_mb__after_atomic_dec() smp_mb()
  11486. diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
  11487. index 6160761..00cac88 100644
  11488. --- a/arch/tile/include/asm/cache.h
  11489. +++ b/arch/tile/include/asm/cache.h
  11490. @@ -15,11 +15,12 @@
  11491. #ifndef _ASM_TILE_CACHE_H
  11492. #define _ASM_TILE_CACHE_H
  11493. +#include <linux/const.h>
  11494. #include <arch/chip.h>
  11495. /* bytes per L1 data cache line */
  11496. #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
  11497. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  11498. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  11499. /* bytes per L2 cache line */
  11500. #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
  11501. diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
  11502. index b6cde32..c0cb736 100644
  11503. --- a/arch/tile/include/asm/uaccess.h
  11504. +++ b/arch/tile/include/asm/uaccess.h
  11505. @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
  11506. const void __user *from,
  11507. unsigned long n)
  11508. {
  11509. - int sz = __compiletime_object_size(to);
  11510. + size_t sz = __compiletime_object_size(to);
  11511. - if (likely(sz == -1 || sz >= n))
  11512. + if (likely(sz == (size_t)-1 || sz >= n))
  11513. n = _copy_from_user(to, from, n);
  11514. else
  11515. copy_from_user_overflow();
  11516. diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
  11517. index 0cb3bba..7338b2d 100644
  11518. --- a/arch/tile/mm/hugetlbpage.c
  11519. +++ b/arch/tile/mm/hugetlbpage.c
  11520. @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
  11521. info.high_limit = TASK_SIZE;
  11522. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  11523. info.align_offset = 0;
  11524. + info.threadstack_offset = 0;
  11525. return vm_unmapped_area(&info);
  11526. }
  11527. @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
  11528. info.high_limit = current->mm->mmap_base;
  11529. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  11530. info.align_offset = 0;
  11531. + info.threadstack_offset = 0;
  11532. addr = vm_unmapped_area(&info);
  11533. /*
  11534. diff --git a/arch/um/Makefile b/arch/um/Makefile
  11535. index 36e658a..71a5c5a 100644
  11536. --- a/arch/um/Makefile
  11537. +++ b/arch/um/Makefile
  11538. @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
  11539. $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
  11540. $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
  11541. +ifdef CONSTIFY_PLUGIN
  11542. +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
  11543. +endif
  11544. +
  11545. #This will adjust *FLAGS accordingly to the platform.
  11546. include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
  11547. diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
  11548. index 19e1bdd..3665b77 100644
  11549. --- a/arch/um/include/asm/cache.h
  11550. +++ b/arch/um/include/asm/cache.h
  11551. @@ -1,6 +1,7 @@
  11552. #ifndef __UM_CACHE_H
  11553. #define __UM_CACHE_H
  11554. +#include <linux/const.h>
  11555. #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
  11556. # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
  11557. @@ -12,6 +13,6 @@
  11558. # define L1_CACHE_SHIFT 5
  11559. #endif
  11560. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  11561. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  11562. #endif
  11563. diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
  11564. index 2e0a6b1..a64d0f5 100644
  11565. --- a/arch/um/include/asm/kmap_types.h
  11566. +++ b/arch/um/include/asm/kmap_types.h
  11567. @@ -8,6 +8,6 @@
  11568. /* No more #include "asm/arch/kmap_types.h" ! */
  11569. -#define KM_TYPE_NR 14
  11570. +#define KM_TYPE_NR 15
  11571. #endif
  11572. diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
  11573. index 5ff53d9..5850cdf 100644
  11574. --- a/arch/um/include/asm/page.h
  11575. +++ b/arch/um/include/asm/page.h
  11576. @@ -14,6 +14,9 @@
  11577. #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
  11578. #define PAGE_MASK (~(PAGE_SIZE-1))
  11579. +#define ktla_ktva(addr) (addr)
  11580. +#define ktva_ktla(addr) (addr)
  11581. +
  11582. #ifndef __ASSEMBLY__
  11583. struct page;
  11584. diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
  11585. index 0032f92..cd151e0 100644
  11586. --- a/arch/um/include/asm/pgtable-3level.h
  11587. +++ b/arch/um/include/asm/pgtable-3level.h
  11588. @@ -58,6 +58,7 @@
  11589. #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
  11590. #define pud_populate(mm, pud, pmd) \
  11591. set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
  11592. +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
  11593. #ifdef CONFIG_64BIT
  11594. #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
  11595. diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
  11596. index eecc414..48adb87 100644
  11597. --- a/arch/um/kernel/process.c
  11598. +++ b/arch/um/kernel/process.c
  11599. @@ -356,22 +356,6 @@ int singlestepping(void * t)
  11600. return 2;
  11601. }
  11602. -/*
  11603. - * Only x86 and x86_64 have an arch_align_stack().
  11604. - * All other arches have "#define arch_align_stack(x) (x)"
  11605. - * in their asm/system.h
  11606. - * As this is included in UML from asm-um/system-generic.h,
  11607. - * we can use it to behave as the subarch does.
  11608. - */
  11609. -#ifndef arch_align_stack
  11610. -unsigned long arch_align_stack(unsigned long sp)
  11611. -{
  11612. - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  11613. - sp -= get_random_int() % 8192;
  11614. - return sp & ~0xf;
  11615. -}
  11616. -#endif
  11617. -
  11618. unsigned long get_wchan(struct task_struct *p)
  11619. {
  11620. unsigned long stack_page, sp, ip;
  11621. diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
  11622. index ad8f795..2c7eec6 100644
  11623. --- a/arch/unicore32/include/asm/cache.h
  11624. +++ b/arch/unicore32/include/asm/cache.h
  11625. @@ -12,8 +12,10 @@
  11626. #ifndef __UNICORE_CACHE_H__
  11627. #define __UNICORE_CACHE_H__
  11628. -#define L1_CACHE_SHIFT (5)
  11629. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  11630. +#include <linux/const.h>
  11631. +
  11632. +#define L1_CACHE_SHIFT 5
  11633. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  11634. /*
  11635. * Memory returned by kmalloc() may be used for DMA, so we must make
  11636. diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
  11637. index 0af5250..59f9597 100644
  11638. --- a/arch/x86/Kconfig
  11639. +++ b/arch/x86/Kconfig
  11640. @@ -126,7 +126,7 @@ config X86
  11641. select RTC_LIB
  11642. select HAVE_DEBUG_STACKOVERFLOW
  11643. select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
  11644. - select HAVE_CC_STACKPROTECTOR
  11645. + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
  11646. config INSTRUCTION_DECODER
  11647. def_bool y
  11648. @@ -251,7 +251,7 @@ config X86_HT
  11649. config X86_32_LAZY_GS
  11650. def_bool y
  11651. - depends on X86_32 && !CC_STACKPROTECTOR
  11652. + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
  11653. config ARCH_HWEIGHT_CFLAGS
  11654. string
  11655. @@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
  11656. menuconfig HYPERVISOR_GUEST
  11657. bool "Linux guest support"
  11658. + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
  11659. ---help---
  11660. Say Y here to enable options for running Linux under various hyper-
  11661. visors. This option enables basic hypervisor detection and platform
  11662. @@ -1111,7 +1112,7 @@ choice
  11663. config NOHIGHMEM
  11664. bool "off"
  11665. - depends on !X86_NUMAQ
  11666. + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
  11667. ---help---
  11668. Linux can use up to 64 Gigabytes of physical memory on x86 systems.
  11669. However, the address space of 32-bit x86 processors is only 4
  11670. @@ -1148,7 +1149,7 @@ config NOHIGHMEM
  11671. config HIGHMEM4G
  11672. bool "4GB"
  11673. - depends on !X86_NUMAQ
  11674. + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
  11675. ---help---
  11676. Select this if you have a 32-bit processor and between 1 and 4
  11677. gigabytes of physical RAM.
  11678. @@ -1201,7 +1202,7 @@ config PAGE_OFFSET
  11679. hex
  11680. default 0xB0000000 if VMSPLIT_3G_OPT
  11681. default 0x80000000 if VMSPLIT_2G
  11682. - default 0x78000000 if VMSPLIT_2G_OPT
  11683. + default 0x70000000 if VMSPLIT_2G_OPT
  11684. default 0x40000000 if VMSPLIT_1G
  11685. default 0xC0000000
  11686. depends on X86_32
  11687. @@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
  11688. config KEXEC
  11689. bool "kexec system call"
  11690. + depends on !GRKERNSEC_KMEM
  11691. ---help---
  11692. kexec is a system call that implements the ability to shutdown your
  11693. current kernel, and to start another kernel. It is like a reboot
  11694. @@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
  11695. config PHYSICAL_ALIGN
  11696. hex "Alignment value to which kernel should be aligned"
  11697. - default "0x200000"
  11698. + default "0x1000000"
  11699. + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
  11700. + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
  11701. range 0x2000 0x1000000 if X86_32
  11702. range 0x200000 0x1000000 if X86_64
  11703. ---help---
  11704. @@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
  11705. If unsure, say N.
  11706. config COMPAT_VDSO
  11707. - def_bool y
  11708. + def_bool n
  11709. prompt "Compat VDSO support"
  11710. depends on X86_32 || IA32_EMULATION
  11711. + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
  11712. ---help---
  11713. Map the 32-bit VDSO to the predictable old-style address too.
  11714. diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
  11715. index f3aaf23..a1d3c49 100644
  11716. --- a/arch/x86/Kconfig.cpu
  11717. +++ b/arch/x86/Kconfig.cpu
  11718. @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
  11719. config X86_F00F_BUG
  11720. def_bool y
  11721. - depends on M586MMX || M586TSC || M586 || M486
  11722. + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
  11723. config X86_INVD_BUG
  11724. def_bool y
  11725. @@ -327,7 +327,7 @@ config X86_INVD_BUG
  11726. config X86_ALIGNMENT_16
  11727. def_bool y
  11728. - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
  11729. + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
  11730. config X86_INTEL_USERCOPY
  11731. def_bool y
  11732. @@ -369,7 +369,7 @@ config X86_CMPXCHG64
  11733. # generates cmov.
  11734. config X86_CMOV
  11735. def_bool y
  11736. - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
  11737. + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
  11738. config X86_MINIMUM_CPU_FAMILY
  11739. int
  11740. diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
  11741. index 321a52c..3d51a5e 100644
  11742. --- a/arch/x86/Kconfig.debug
  11743. +++ b/arch/x86/Kconfig.debug
  11744. @@ -84,7 +84,7 @@ config X86_PTDUMP
  11745. config DEBUG_RODATA
  11746. bool "Write protect kernel read-only data structures"
  11747. default y
  11748. - depends on DEBUG_KERNEL
  11749. + depends on DEBUG_KERNEL && BROKEN
  11750. ---help---
  11751. Mark the kernel read-only data as write-protected in the pagetables,
  11752. in order to catch accidental (and incorrect) writes to such const
  11753. @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
  11754. config DEBUG_SET_MODULE_RONX
  11755. bool "Set loadable kernel module data as NX and text as RO"
  11756. - depends on MODULES
  11757. + depends on MODULES && BROKEN
  11758. ---help---
  11759. This option helps catch unintended modifications to loadable
  11760. kernel module's text and read-only data. It also prevents execution
  11761. diff --git a/arch/x86/Makefile b/arch/x86/Makefile
  11762. index 0dd99ea..4a63d82 100644
  11763. --- a/arch/x86/Makefile
  11764. +++ b/arch/x86/Makefile
  11765. @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
  11766. # CPU-specific tuning. Anything which can be shared with UML should go here.
  11767. include $(srctree)/arch/x86/Makefile_32.cpu
  11768. KBUILD_CFLAGS += $(cflags-y)
  11769. -
  11770. - # temporary until string.h is fixed
  11771. - KBUILD_CFLAGS += -ffreestanding
  11772. else
  11773. BITS := 64
  11774. UTS_MACHINE := x86_64
  11775. @@ -112,6 +109,9 @@ else
  11776. KBUILD_CFLAGS += -maccumulate-outgoing-args
  11777. endif
  11778. +# temporary until string.h is fixed
  11779. +KBUILD_CFLAGS += -ffreestanding
  11780. +
  11781. # Make sure compiler does not have buggy stack-protector support.
  11782. ifdef CONFIG_CC_STACKPROTECTOR
  11783. cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
  11784. @@ -269,3 +269,12 @@ define archhelp
  11785. echo ' FDINITRD=file initrd for the booted kernel'
  11786. echo ' kvmconfig - Enable additional options for guest kernel support'
  11787. endef
  11788. +
  11789. +define OLD_LD
  11790. +
  11791. +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
  11792. +*** Please upgrade your binutils to 2.18 or newer
  11793. +endef
  11794. +
  11795. +archprepare:
  11796. + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
  11797. diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
  11798. index 878df7e..a803913 100644
  11799. --- a/arch/x86/boot/Makefile
  11800. +++ b/arch/x86/boot/Makefile
  11801. @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
  11802. # ---------------------------------------------------------------------------
  11803. KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
  11804. +ifdef CONSTIFY_PLUGIN
  11805. +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
  11806. +endif
  11807. KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
  11808. GCOV_PROFILE := n
  11809. diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
  11810. index 878e4b9..20537ab 100644
  11811. --- a/arch/x86/boot/bitops.h
  11812. +++ b/arch/x86/boot/bitops.h
  11813. @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
  11814. u8 v;
  11815. const u32 *p = (const u32 *)addr;
  11816. - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
  11817. + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
  11818. return v;
  11819. }
  11820. @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
  11821. static inline void set_bit(int nr, void *addr)
  11822. {
  11823. - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
  11824. + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
  11825. }
  11826. #endif /* BOOT_BITOPS_H */
  11827. diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
  11828. index 50f8c5e..4f84fff 100644
  11829. --- a/arch/x86/boot/boot.h
  11830. +++ b/arch/x86/boot/boot.h
  11831. @@ -84,7 +84,7 @@ static inline void io_delay(void)
  11832. static inline u16 ds(void)
  11833. {
  11834. u16 seg;
  11835. - asm("movw %%ds,%0" : "=rm" (seg));
  11836. + asm volatile("movw %%ds,%0" : "=rm" (seg));
  11837. return seg;
  11838. }
  11839. @@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
  11840. static inline int memcmp(const void *s1, const void *s2, size_t len)
  11841. {
  11842. u8 diff;
  11843. - asm("repe; cmpsb; setnz %0"
  11844. + asm volatile("repe; cmpsb; setnz %0"
  11845. : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
  11846. return diff;
  11847. }
  11848. diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
  11849. index 0fcd913..3bb5c42 100644
  11850. --- a/arch/x86/boot/compressed/Makefile
  11851. +++ b/arch/x86/boot/compressed/Makefile
  11852. @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
  11853. KBUILD_CFLAGS += -mno-mmx -mno-sse
  11854. KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
  11855. KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
  11856. +ifdef CONSTIFY_PLUGIN
  11857. +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
  11858. +endif
  11859. KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
  11860. GCOV_PROFILE := n
  11861. diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
  11862. index a53440e..c3dbf1e 100644
  11863. --- a/arch/x86/boot/compressed/efi_stub_32.S
  11864. +++ b/arch/x86/boot/compressed/efi_stub_32.S
  11865. @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
  11866. * parameter 2, ..., param n. To make things easy, we save the return
  11867. * address of efi_call_phys in a global variable.
  11868. */
  11869. - popl %ecx
  11870. - movl %ecx, saved_return_addr(%edx)
  11871. - /* get the function pointer into ECX*/
  11872. - popl %ecx
  11873. - movl %ecx, efi_rt_function_ptr(%edx)
  11874. + popl saved_return_addr(%edx)
  11875. + popl efi_rt_function_ptr(%edx)
  11876. /*
  11877. * 3. Call the physical function.
  11878. */
  11879. - call *%ecx
  11880. + call *efi_rt_function_ptr(%edx)
  11881. /*
  11882. * 4. Balance the stack. And because EAX contain the return value,
  11883. @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
  11884. 1: popl %edx
  11885. subl $1b, %edx
  11886. - movl efi_rt_function_ptr(%edx), %ecx
  11887. - pushl %ecx
  11888. + pushl efi_rt_function_ptr(%edx)
  11889. /*
  11890. * 10. Push the saved return address onto the stack and return.
  11891. */
  11892. - movl saved_return_addr(%edx), %ecx
  11893. - pushl %ecx
  11894. - ret
  11895. + jmpl *saved_return_addr(%edx)
  11896. ENDPROC(efi_call_phys)
  11897. .previous
  11898. diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
  11899. index f45ab7a..ebc015f 100644
  11900. --- a/arch/x86/boot/compressed/head_32.S
  11901. +++ b/arch/x86/boot/compressed/head_32.S
  11902. @@ -119,10 +119,10 @@ preferred_addr:
  11903. addl %eax, %ebx
  11904. notl %eax
  11905. andl %eax, %ebx
  11906. - cmpl $LOAD_PHYSICAL_ADDR, %ebx
  11907. + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
  11908. jge 1f
  11909. #endif
  11910. - movl $LOAD_PHYSICAL_ADDR, %ebx
  11911. + movl $____LOAD_PHYSICAL_ADDR, %ebx
  11912. 1:
  11913. /* Target address to relocate to for decompression */
  11914. diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
  11915. index b10fa66..5ee0472 100644
  11916. --- a/arch/x86/boot/compressed/head_64.S
  11917. +++ b/arch/x86/boot/compressed/head_64.S
  11918. @@ -94,10 +94,10 @@ ENTRY(startup_32)
  11919. addl %eax, %ebx
  11920. notl %eax
  11921. andl %eax, %ebx
  11922. - cmpl $LOAD_PHYSICAL_ADDR, %ebx
  11923. + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
  11924. jge 1f
  11925. #endif
  11926. - movl $LOAD_PHYSICAL_ADDR, %ebx
  11927. + movl $____LOAD_PHYSICAL_ADDR, %ebx
  11928. 1:
  11929. /* Target address to relocate to for decompression */
  11930. @@ -268,10 +268,10 @@ preferred_addr:
  11931. addq %rax, %rbp
  11932. notq %rax
  11933. andq %rax, %rbp
  11934. - cmpq $LOAD_PHYSICAL_ADDR, %rbp
  11935. + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
  11936. jge 1f
  11937. #endif
  11938. - movq $LOAD_PHYSICAL_ADDR, %rbp
  11939. + movq $____LOAD_PHYSICAL_ADDR, %rbp
  11940. 1:
  11941. /* Target address to relocate to for decompression */
  11942. @@ -363,8 +363,8 @@ gdt:
  11943. .long gdt
  11944. .word 0
  11945. .quad 0x0000000000000000 /* NULL descriptor */
  11946. - .quad 0x00af9a000000ffff /* __KERNEL_CS */
  11947. - .quad 0x00cf92000000ffff /* __KERNEL_DS */
  11948. + .quad 0x00af9b000000ffff /* __KERNEL_CS */
  11949. + .quad 0x00cf93000000ffff /* __KERNEL_DS */
  11950. .quad 0x0080890000000000 /* TS descriptor */
  11951. .quad 0x0000000000000000 /* TS continued */
  11952. gdt_end:
  11953. diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
  11954. index 196eaf3..c96716d 100644
  11955. --- a/arch/x86/boot/compressed/misc.c
  11956. +++ b/arch/x86/boot/compressed/misc.c
  11957. @@ -218,7 +218,7 @@ void __putstr(const char *s)
  11958. void *memset(void *s, int c, size_t n)
  11959. {
  11960. - int i;
  11961. + size_t i;
  11962. char *ss = s;
  11963. for (i = 0; i < n; i++)
  11964. @@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
  11965. * Calculate the delta between where vmlinux was linked to load
  11966. * and where it was actually loaded.
  11967. */
  11968. - delta = min_addr - LOAD_PHYSICAL_ADDR;
  11969. + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
  11970. if (!delta) {
  11971. debug_putstr("No relocation needed... ");
  11972. return;
  11973. @@ -347,7 +347,7 @@ static void parse_elf(void *output)
  11974. Elf32_Ehdr ehdr;
  11975. Elf32_Phdr *phdrs, *phdr;
  11976. #endif
  11977. - void *dest;
  11978. + void *dest, *prev;
  11979. int i;
  11980. memcpy(&ehdr, output, sizeof(ehdr));
  11981. @@ -374,13 +374,16 @@ static void parse_elf(void *output)
  11982. case PT_LOAD:
  11983. #ifdef CONFIG_RELOCATABLE
  11984. dest = output;
  11985. - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
  11986. + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
  11987. #else
  11988. dest = (void *)(phdr->p_paddr);
  11989. #endif
  11990. memcpy(dest,
  11991. output + phdr->p_offset,
  11992. phdr->p_filesz);
  11993. + if (i)
  11994. + memset(prev, 0xff, dest - prev);
  11995. + prev = dest + phdr->p_filesz;
  11996. break;
  11997. default: /* Ignore other PT_* */ break;
  11998. }
  11999. @@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
  12000. error("Destination address too large");
  12001. #endif
  12002. #ifndef CONFIG_RELOCATABLE
  12003. - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
  12004. + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
  12005. error("Wrong destination address");
  12006. #endif
  12007. diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
  12008. index 100a9a1..bb3bdb0 100644
  12009. --- a/arch/x86/boot/cpucheck.c
  12010. +++ b/arch/x86/boot/cpucheck.c
  12011. @@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
  12012. u32 ecx = MSR_K7_HWCR;
  12013. u32 eax, edx;
  12014. - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
  12015. + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
  12016. eax &= ~(1 << 15);
  12017. - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
  12018. + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
  12019. get_cpuflags(); /* Make sure it really did something */
  12020. err = check_cpuflags();
  12021. @@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
  12022. u32 ecx = MSR_VIA_FCR;
  12023. u32 eax, edx;
  12024. - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
  12025. + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
  12026. eax |= (1<<1)|(1<<7);
  12027. - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
  12028. + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
  12029. set_bit(X86_FEATURE_CX8, cpu.flags);
  12030. err = check_cpuflags();
  12031. @@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
  12032. u32 eax, edx;
  12033. u32 level = 1;
  12034. - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
  12035. - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
  12036. - asm("cpuid"
  12037. + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
  12038. + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
  12039. + asm volatile("cpuid"
  12040. : "+a" (level), "=d" (cpu.flags[0])
  12041. : : "ecx", "ebx");
  12042. - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
  12043. + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
  12044. err = check_cpuflags();
  12045. }
  12046. diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
  12047. index ec3b8ba..6a0db1f 100644
  12048. --- a/arch/x86/boot/header.S
  12049. +++ b/arch/x86/boot/header.S
  12050. @@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
  12051. # single linked list of
  12052. # struct setup_data
  12053. -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
  12054. +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
  12055. #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
  12056. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  12057. +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
  12058. +#else
  12059. #define VO_INIT_SIZE (VO__end - VO__text)
  12060. +#endif
  12061. #if ZO_INIT_SIZE > VO_INIT_SIZE
  12062. #define INIT_SIZE ZO_INIT_SIZE
  12063. #else
  12064. diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
  12065. index db75d07..8e6d0af 100644
  12066. --- a/arch/x86/boot/memory.c
  12067. +++ b/arch/x86/boot/memory.c
  12068. @@ -19,7 +19,7 @@
  12069. static int detect_memory_e820(void)
  12070. {
  12071. - int count = 0;
  12072. + unsigned int count = 0;
  12073. struct biosregs ireg, oreg;
  12074. struct e820entry *desc = boot_params.e820_map;
  12075. static struct e820entry buf; /* static so it is zeroed */
  12076. diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
  12077. index 11e8c6e..fdbb1ed 100644
  12078. --- a/arch/x86/boot/video-vesa.c
  12079. +++ b/arch/x86/boot/video-vesa.c
  12080. @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
  12081. boot_params.screen_info.vesapm_seg = oreg.es;
  12082. boot_params.screen_info.vesapm_off = oreg.di;
  12083. + boot_params.screen_info.vesapm_size = oreg.cx;
  12084. }
  12085. /*
  12086. diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
  12087. index 43eda28..5ab5fdb 100644
  12088. --- a/arch/x86/boot/video.c
  12089. +++ b/arch/x86/boot/video.c
  12090. @@ -96,7 +96,7 @@ static void store_mode_params(void)
  12091. static unsigned int get_entry(void)
  12092. {
  12093. char entry_buf[4];
  12094. - int i, len = 0;
  12095. + unsigned int i, len = 0;
  12096. int key;
  12097. unsigned int v;
  12098. diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
  12099. index 9105655..41779c1 100644
  12100. --- a/arch/x86/crypto/aes-x86_64-asm_64.S
  12101. +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
  12102. @@ -8,6 +8,8 @@
  12103. * including this sentence is retained in full.
  12104. */
  12105. +#include <asm/alternative-asm.h>
  12106. +
  12107. .extern crypto_ft_tab
  12108. .extern crypto_it_tab
  12109. .extern crypto_fl_tab
  12110. @@ -70,6 +72,8 @@
  12111. je B192; \
  12112. leaq 32(r9),r9;
  12113. +#define ret pax_force_retaddr; ret
  12114. +
  12115. #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
  12116. movq r1,r2; \
  12117. movq r3,r4; \
  12118. diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
  12119. index 477e9d7..c92c7d8 100644
  12120. --- a/arch/x86/crypto/aesni-intel_asm.S
  12121. +++ b/arch/x86/crypto/aesni-intel_asm.S
  12122. @@ -31,6 +31,7 @@
  12123. #include <linux/linkage.h>
  12124. #include <asm/inst.h>
  12125. +#include <asm/alternative-asm.h>
  12126. #ifdef __x86_64__
  12127. .data
  12128. @@ -205,7 +206,7 @@ enc: .octa 0x2
  12129. * num_initial_blocks = b mod 4
  12130. * encrypt the initial num_initial_blocks blocks and apply ghash on
  12131. * the ciphertext
  12132. -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
  12133. +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
  12134. * are clobbered
  12135. * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
  12136. */
  12137. @@ -214,8 +215,8 @@ enc: .octa 0x2
  12138. .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
  12139. XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
  12140. mov arg7, %r10 # %r10 = AAD
  12141. - mov arg8, %r12 # %r12 = aadLen
  12142. - mov %r12, %r11
  12143. + mov arg8, %r15 # %r15 = aadLen
  12144. + mov %r15, %r11
  12145. pxor %xmm\i, %xmm\i
  12146. _get_AAD_loop\num_initial_blocks\operation:
  12147. movd (%r10), \TMP1
  12148. @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
  12149. psrldq $4, %xmm\i
  12150. pxor \TMP1, %xmm\i
  12151. add $4, %r10
  12152. - sub $4, %r12
  12153. + sub $4, %r15
  12154. jne _get_AAD_loop\num_initial_blocks\operation
  12155. cmp $16, %r11
  12156. je _get_AAD_loop2_done\num_initial_blocks\operation
  12157. - mov $16, %r12
  12158. + mov $16, %r15
  12159. _get_AAD_loop2\num_initial_blocks\operation:
  12160. psrldq $4, %xmm\i
  12161. - sub $4, %r12
  12162. - cmp %r11, %r12
  12163. + sub $4, %r15
  12164. + cmp %r11, %r15
  12165. jne _get_AAD_loop2\num_initial_blocks\operation
  12166. _get_AAD_loop2_done\num_initial_blocks\operation:
  12167. movdqa SHUF_MASK(%rip), %xmm14
  12168. @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
  12169. * num_initial_blocks = b mod 4
  12170. * encrypt the initial num_initial_blocks blocks and apply ghash on
  12171. * the ciphertext
  12172. -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
  12173. +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
  12174. * are clobbered
  12175. * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
  12176. */
  12177. @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
  12178. .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
  12179. XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
  12180. mov arg7, %r10 # %r10 = AAD
  12181. - mov arg8, %r12 # %r12 = aadLen
  12182. - mov %r12, %r11
  12183. + mov arg8, %r15 # %r15 = aadLen
  12184. + mov %r15, %r11
  12185. pxor %xmm\i, %xmm\i
  12186. _get_AAD_loop\num_initial_blocks\operation:
  12187. movd (%r10), \TMP1
  12188. @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
  12189. psrldq $4, %xmm\i
  12190. pxor \TMP1, %xmm\i
  12191. add $4, %r10
  12192. - sub $4, %r12
  12193. + sub $4, %r15
  12194. jne _get_AAD_loop\num_initial_blocks\operation
  12195. cmp $16, %r11
  12196. je _get_AAD_loop2_done\num_initial_blocks\operation
  12197. - mov $16, %r12
  12198. + mov $16, %r15
  12199. _get_AAD_loop2\num_initial_blocks\operation:
  12200. psrldq $4, %xmm\i
  12201. - sub $4, %r12
  12202. - cmp %r11, %r12
  12203. + sub $4, %r15
  12204. + cmp %r11, %r15
  12205. jne _get_AAD_loop2\num_initial_blocks\operation
  12206. _get_AAD_loop2_done\num_initial_blocks\operation:
  12207. movdqa SHUF_MASK(%rip), %xmm14
  12208. @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
  12209. *
  12210. *****************************************************************************/
  12211. ENTRY(aesni_gcm_dec)
  12212. - push %r12
  12213. + push %r15
  12214. push %r13
  12215. push %r14
  12216. mov %rsp, %r14
  12217. @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
  12218. */
  12219. sub $VARIABLE_OFFSET, %rsp
  12220. and $~63, %rsp # align rsp to 64 bytes
  12221. - mov %arg6, %r12
  12222. - movdqu (%r12), %xmm13 # %xmm13 = HashKey
  12223. + mov %arg6, %r15
  12224. + movdqu (%r15), %xmm13 # %xmm13 = HashKey
  12225. movdqa SHUF_MASK(%rip), %xmm2
  12226. PSHUFB_XMM %xmm2, %xmm13
  12227. @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
  12228. movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
  12229. mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
  12230. and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
  12231. - mov %r13, %r12
  12232. - and $(3<<4), %r12
  12233. + mov %r13, %r15
  12234. + and $(3<<4), %r15
  12235. jz _initial_num_blocks_is_0_decrypt
  12236. - cmp $(2<<4), %r12
  12237. + cmp $(2<<4), %r15
  12238. jb _initial_num_blocks_is_1_decrypt
  12239. je _initial_num_blocks_is_2_decrypt
  12240. _initial_num_blocks_is_3_decrypt:
  12241. @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
  12242. sub $16, %r11
  12243. add %r13, %r11
  12244. movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
  12245. - lea SHIFT_MASK+16(%rip), %r12
  12246. - sub %r13, %r12
  12247. + lea SHIFT_MASK+16(%rip), %r15
  12248. + sub %r13, %r15
  12249. # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
  12250. # (%r13 is the number of bytes in plaintext mod 16)
  12251. - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
  12252. + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
  12253. PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
  12254. movdqa %xmm1, %xmm2
  12255. pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
  12256. - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
  12257. + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
  12258. # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
  12259. pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
  12260. pand %xmm1, %xmm2
  12261. @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
  12262. sub $1, %r13
  12263. jne _less_than_8_bytes_left_decrypt
  12264. _multiple_of_16_bytes_decrypt:
  12265. - mov arg8, %r12 # %r13 = aadLen (number of bytes)
  12266. - shl $3, %r12 # convert into number of bits
  12267. - movd %r12d, %xmm15 # len(A) in %xmm15
  12268. + mov arg8, %r15 # %r13 = aadLen (number of bytes)
  12269. + shl $3, %r15 # convert into number of bits
  12270. + movd %r15d, %xmm15 # len(A) in %xmm15
  12271. shl $3, %arg4 # len(C) in bits (*128)
  12272. MOVQ_R64_XMM %arg4, %xmm1
  12273. pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
  12274. @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
  12275. mov %r14, %rsp
  12276. pop %r14
  12277. pop %r13
  12278. - pop %r12
  12279. + pop %r15
  12280. + pax_force_retaddr
  12281. ret
  12282. ENDPROC(aesni_gcm_dec)
  12283. @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
  12284. * poly = x^128 + x^127 + x^126 + x^121 + 1
  12285. ***************************************************************************/
  12286. ENTRY(aesni_gcm_enc)
  12287. - push %r12
  12288. + push %r15
  12289. push %r13
  12290. push %r14
  12291. mov %rsp, %r14
  12292. @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
  12293. #
  12294. sub $VARIABLE_OFFSET, %rsp
  12295. and $~63, %rsp
  12296. - mov %arg6, %r12
  12297. - movdqu (%r12), %xmm13
  12298. + mov %arg6, %r15
  12299. + movdqu (%r15), %xmm13
  12300. movdqa SHUF_MASK(%rip), %xmm2
  12301. PSHUFB_XMM %xmm2, %xmm13
  12302. @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
  12303. movdqa %xmm13, HashKey(%rsp)
  12304. mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
  12305. and $-16, %r13
  12306. - mov %r13, %r12
  12307. + mov %r13, %r15
  12308. # Encrypt first few blocks
  12309. - and $(3<<4), %r12
  12310. + and $(3<<4), %r15
  12311. jz _initial_num_blocks_is_0_encrypt
  12312. - cmp $(2<<4), %r12
  12313. + cmp $(2<<4), %r15
  12314. jb _initial_num_blocks_is_1_encrypt
  12315. je _initial_num_blocks_is_2_encrypt
  12316. _initial_num_blocks_is_3_encrypt:
  12317. @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
  12318. sub $16, %r11
  12319. add %r13, %r11
  12320. movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
  12321. - lea SHIFT_MASK+16(%rip), %r12
  12322. - sub %r13, %r12
  12323. + lea SHIFT_MASK+16(%rip), %r15
  12324. + sub %r13, %r15
  12325. # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
  12326. # (%r13 is the number of bytes in plaintext mod 16)
  12327. - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
  12328. + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
  12329. PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
  12330. pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
  12331. - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
  12332. + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
  12333. # get the appropriate mask to mask out top 16-r13 bytes of xmm0
  12334. pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
  12335. movdqa SHUF_MASK(%rip), %xmm10
  12336. @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
  12337. sub $1, %r13
  12338. jne _less_than_8_bytes_left_encrypt
  12339. _multiple_of_16_bytes_encrypt:
  12340. - mov arg8, %r12 # %r12 = addLen (number of bytes)
  12341. - shl $3, %r12
  12342. - movd %r12d, %xmm15 # len(A) in %xmm15
  12343. + mov arg8, %r15 # %r15 = addLen (number of bytes)
  12344. + shl $3, %r15
  12345. + movd %r15d, %xmm15 # len(A) in %xmm15
  12346. shl $3, %arg4 # len(C) in bits (*128)
  12347. MOVQ_R64_XMM %arg4, %xmm1
  12348. pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
  12349. @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
  12350. mov %r14, %rsp
  12351. pop %r14
  12352. pop %r13
  12353. - pop %r12
  12354. + pop %r15
  12355. + pax_force_retaddr
  12356. ret
  12357. ENDPROC(aesni_gcm_enc)
  12358. @@ -1722,6 +1725,7 @@ _key_expansion_256a:
  12359. pxor %xmm1, %xmm0
  12360. movaps %xmm0, (TKEYP)
  12361. add $0x10, TKEYP
  12362. + pax_force_retaddr
  12363. ret
  12364. ENDPROC(_key_expansion_128)
  12365. ENDPROC(_key_expansion_256a)
  12366. @@ -1748,6 +1752,7 @@ _key_expansion_192a:
  12367. shufps $0b01001110, %xmm2, %xmm1
  12368. movaps %xmm1, 0x10(TKEYP)
  12369. add $0x20, TKEYP
  12370. + pax_force_retaddr
  12371. ret
  12372. ENDPROC(_key_expansion_192a)
  12373. @@ -1768,6 +1773,7 @@ _key_expansion_192b:
  12374. movaps %xmm0, (TKEYP)
  12375. add $0x10, TKEYP
  12376. + pax_force_retaddr
  12377. ret
  12378. ENDPROC(_key_expansion_192b)
  12379. @@ -1781,6 +1787,7 @@ _key_expansion_256b:
  12380. pxor %xmm1, %xmm2
  12381. movaps %xmm2, (TKEYP)
  12382. add $0x10, TKEYP
  12383. + pax_force_retaddr
  12384. ret
  12385. ENDPROC(_key_expansion_256b)
  12386. @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
  12387. #ifndef __x86_64__
  12388. popl KEYP
  12389. #endif
  12390. + pax_force_retaddr
  12391. ret
  12392. ENDPROC(aesni_set_key)
  12393. @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
  12394. popl KLEN
  12395. popl KEYP
  12396. #endif
  12397. + pax_force_retaddr
  12398. ret
  12399. ENDPROC(aesni_enc)
  12400. @@ -1974,6 +1983,7 @@ _aesni_enc1:
  12401. AESENC KEY STATE
  12402. movaps 0x70(TKEYP), KEY
  12403. AESENCLAST KEY STATE
  12404. + pax_force_retaddr
  12405. ret
  12406. ENDPROC(_aesni_enc1)
  12407. @@ -2083,6 +2093,7 @@ _aesni_enc4:
  12408. AESENCLAST KEY STATE2
  12409. AESENCLAST KEY STATE3
  12410. AESENCLAST KEY STATE4
  12411. + pax_force_retaddr
  12412. ret
  12413. ENDPROC(_aesni_enc4)
  12414. @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
  12415. popl KLEN
  12416. popl KEYP
  12417. #endif
  12418. + pax_force_retaddr
  12419. ret
  12420. ENDPROC(aesni_dec)
  12421. @@ -2164,6 +2176,7 @@ _aesni_dec1:
  12422. AESDEC KEY STATE
  12423. movaps 0x70(TKEYP), KEY
  12424. AESDECLAST KEY STATE
  12425. + pax_force_retaddr
  12426. ret
  12427. ENDPROC(_aesni_dec1)
  12428. @@ -2273,6 +2286,7 @@ _aesni_dec4:
  12429. AESDECLAST KEY STATE2
  12430. AESDECLAST KEY STATE3
  12431. AESDECLAST KEY STATE4
  12432. + pax_force_retaddr
  12433. ret
  12434. ENDPROC(_aesni_dec4)
  12435. @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
  12436. popl KEYP
  12437. popl LEN
  12438. #endif
  12439. + pax_force_retaddr
  12440. ret
  12441. ENDPROC(aesni_ecb_enc)
  12442. @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
  12443. popl KEYP
  12444. popl LEN
  12445. #endif
  12446. + pax_force_retaddr
  12447. ret
  12448. ENDPROC(aesni_ecb_dec)
  12449. @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
  12450. popl LEN
  12451. popl IVP
  12452. #endif
  12453. + pax_force_retaddr
  12454. ret
  12455. ENDPROC(aesni_cbc_enc)
  12456. @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
  12457. popl LEN
  12458. popl IVP
  12459. #endif
  12460. + pax_force_retaddr
  12461. ret
  12462. ENDPROC(aesni_cbc_dec)
  12463. @@ -2550,6 +2568,7 @@ _aesni_inc_init:
  12464. mov $1, TCTR_LOW
  12465. MOVQ_R64_XMM TCTR_LOW INC
  12466. MOVQ_R64_XMM CTR TCTR_LOW
  12467. + pax_force_retaddr
  12468. ret
  12469. ENDPROC(_aesni_inc_init)
  12470. @@ -2579,6 +2598,7 @@ _aesni_inc:
  12471. .Linc_low:
  12472. movaps CTR, IV
  12473. PSHUFB_XMM BSWAP_MASK IV
  12474. + pax_force_retaddr
  12475. ret
  12476. ENDPROC(_aesni_inc)
  12477. @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
  12478. .Lctr_enc_ret:
  12479. movups IV, (IVP)
  12480. .Lctr_enc_just_ret:
  12481. + pax_force_retaddr
  12482. ret
  12483. ENDPROC(aesni_ctr_enc)
  12484. @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
  12485. pxor INC, STATE4
  12486. movdqu STATE4, 0x70(OUTP)
  12487. + pax_force_retaddr
  12488. ret
  12489. ENDPROC(aesni_xts_crypt8)
  12490. diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
  12491. index 246c670..466e2d6 100644
  12492. --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
  12493. +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
  12494. @@ -21,6 +21,7 @@
  12495. */
  12496. #include <linux/linkage.h>
  12497. +#include <asm/alternative-asm.h>
  12498. .file "blowfish-x86_64-asm.S"
  12499. .text
  12500. @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
  12501. jnz .L__enc_xor;
  12502. write_block();
  12503. + pax_force_retaddr
  12504. ret;
  12505. .L__enc_xor:
  12506. xor_block();
  12507. + pax_force_retaddr
  12508. ret;
  12509. ENDPROC(__blowfish_enc_blk)
  12510. @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
  12511. movq %r11, %rbp;
  12512. + pax_force_retaddr
  12513. ret;
  12514. ENDPROC(blowfish_dec_blk)
  12515. @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
  12516. popq %rbx;
  12517. popq %rbp;
  12518. + pax_force_retaddr
  12519. ret;
  12520. .L__enc_xor4:
  12521. @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
  12522. popq %rbx;
  12523. popq %rbp;
  12524. + pax_force_retaddr
  12525. ret;
  12526. ENDPROC(__blowfish_enc_blk_4way)
  12527. @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
  12528. popq %rbx;
  12529. popq %rbp;
  12530. + pax_force_retaddr
  12531. ret;
  12532. ENDPROC(blowfish_dec_blk_4way)
  12533. diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
  12534. index ce71f92..1dce7ec 100644
  12535. --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
  12536. +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
  12537. @@ -16,6 +16,7 @@
  12538. */
  12539. #include <linux/linkage.h>
  12540. +#include <asm/alternative-asm.h>
  12541. #define CAMELLIA_TABLE_BYTE_LEN 272
  12542. @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
  12543. roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
  12544. %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
  12545. %rcx, (%r9));
  12546. + pax_force_retaddr
  12547. ret;
  12548. ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
  12549. @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
  12550. roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
  12551. %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
  12552. %rax, (%r9));
  12553. + pax_force_retaddr
  12554. ret;
  12555. ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
  12556. @@ -780,6 +783,7 @@ __camellia_enc_blk16:
  12557. %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
  12558. %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
  12559. + pax_force_retaddr
  12560. ret;
  12561. .align 8
  12562. @@ -865,6 +869,7 @@ __camellia_dec_blk16:
  12563. %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
  12564. %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
  12565. + pax_force_retaddr
  12566. ret;
  12567. .align 8
  12568. @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
  12569. %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
  12570. %xmm8, %rsi);
  12571. + pax_force_retaddr
  12572. ret;
  12573. ENDPROC(camellia_ecb_enc_16way)
  12574. @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
  12575. %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
  12576. %xmm8, %rsi);
  12577. + pax_force_retaddr
  12578. ret;
  12579. ENDPROC(camellia_ecb_dec_16way)
  12580. @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
  12581. %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
  12582. %xmm8, %rsi);
  12583. + pax_force_retaddr
  12584. ret;
  12585. ENDPROC(camellia_cbc_dec_16way)
  12586. @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
  12587. %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
  12588. %xmm8, %rsi);
  12589. + pax_force_retaddr
  12590. ret;
  12591. ENDPROC(camellia_ctr_16way)
  12592. @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
  12593. %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
  12594. %xmm8, %rsi);
  12595. + pax_force_retaddr
  12596. ret;
  12597. ENDPROC(camellia_xts_crypt_16way)
  12598. diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
  12599. index 0e0b886..5a3123c 100644
  12600. --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
  12601. +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
  12602. @@ -11,6 +11,7 @@
  12603. */
  12604. #include <linux/linkage.h>
  12605. +#include <asm/alternative-asm.h>
  12606. #define CAMELLIA_TABLE_BYTE_LEN 272
  12607. @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
  12608. roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
  12609. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
  12610. %rcx, (%r9));
  12611. + pax_force_retaddr
  12612. ret;
  12613. ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
  12614. @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
  12615. roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
  12616. %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
  12617. %rax, (%r9));
  12618. + pax_force_retaddr
  12619. ret;
  12620. ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
  12621. @@ -820,6 +823,7 @@ __camellia_enc_blk32:
  12622. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  12623. %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
  12624. + pax_force_retaddr
  12625. ret;
  12626. .align 8
  12627. @@ -905,6 +909,7 @@ __camellia_dec_blk32:
  12628. %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
  12629. %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
  12630. + pax_force_retaddr
  12631. ret;
  12632. .align 8
  12633. @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
  12634. vzeroupper;
  12635. + pax_force_retaddr
  12636. ret;
  12637. ENDPROC(camellia_ecb_enc_32way)
  12638. @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
  12639. vzeroupper;
  12640. + pax_force_retaddr
  12641. ret;
  12642. ENDPROC(camellia_ecb_dec_32way)
  12643. @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
  12644. vzeroupper;
  12645. + pax_force_retaddr
  12646. ret;
  12647. ENDPROC(camellia_cbc_dec_32way)
  12648. @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
  12649. vzeroupper;
  12650. + pax_force_retaddr
  12651. ret;
  12652. ENDPROC(camellia_ctr_32way)
  12653. @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
  12654. vzeroupper;
  12655. + pax_force_retaddr
  12656. ret;
  12657. ENDPROC(camellia_xts_crypt_32way)
  12658. diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
  12659. index 310319c..db3d7b5 100644
  12660. --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
  12661. +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
  12662. @@ -21,6 +21,7 @@
  12663. */
  12664. #include <linux/linkage.h>
  12665. +#include <asm/alternative-asm.h>
  12666. .file "camellia-x86_64-asm_64.S"
  12667. .text
  12668. @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
  12669. enc_outunpack(mov, RT1);
  12670. movq RRBP, %rbp;
  12671. + pax_force_retaddr
  12672. ret;
  12673. .L__enc_xor:
  12674. enc_outunpack(xor, RT1);
  12675. movq RRBP, %rbp;
  12676. + pax_force_retaddr
  12677. ret;
  12678. ENDPROC(__camellia_enc_blk)
  12679. @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
  12680. dec_outunpack();
  12681. movq RRBP, %rbp;
  12682. + pax_force_retaddr
  12683. ret;
  12684. ENDPROC(camellia_dec_blk)
  12685. @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
  12686. movq RRBP, %rbp;
  12687. popq %rbx;
  12688. + pax_force_retaddr
  12689. ret;
  12690. .L__enc2_xor:
  12691. @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
  12692. movq RRBP, %rbp;
  12693. popq %rbx;
  12694. + pax_force_retaddr
  12695. ret;
  12696. ENDPROC(__camellia_enc_blk_2way)
  12697. @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
  12698. movq RRBP, %rbp;
  12699. movq RXOR, %rbx;
  12700. + pax_force_retaddr
  12701. ret;
  12702. ENDPROC(camellia_dec_blk_2way)
  12703. diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
  12704. index c35fd5d..2d8c7db 100644
  12705. --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
  12706. +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
  12707. @@ -24,6 +24,7 @@
  12708. */
  12709. #include <linux/linkage.h>
  12710. +#include <asm/alternative-asm.h>
  12711. .file "cast5-avx-x86_64-asm_64.S"
  12712. @@ -281,6 +282,7 @@ __cast5_enc_blk16:
  12713. outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
  12714. outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
  12715. + pax_force_retaddr
  12716. ret;
  12717. ENDPROC(__cast5_enc_blk16)
  12718. @@ -352,6 +354,7 @@ __cast5_dec_blk16:
  12719. outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
  12720. outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
  12721. + pax_force_retaddr
  12722. ret;
  12723. .L__skip_dec:
  12724. @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
  12725. vmovdqu RR4, (6*4*4)(%r11);
  12726. vmovdqu RL4, (7*4*4)(%r11);
  12727. + pax_force_retaddr
  12728. ret;
  12729. ENDPROC(cast5_ecb_enc_16way)
  12730. @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
  12731. vmovdqu RR4, (6*4*4)(%r11);
  12732. vmovdqu RL4, (7*4*4)(%r11);
  12733. + pax_force_retaddr
  12734. ret;
  12735. ENDPROC(cast5_ecb_dec_16way)
  12736. @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
  12737. * %rdx: src
  12738. */
  12739. - pushq %r12;
  12740. + pushq %r14;
  12741. movq %rsi, %r11;
  12742. - movq %rdx, %r12;
  12743. + movq %rdx, %r14;
  12744. vmovdqu (0*16)(%rdx), RL1;
  12745. vmovdqu (1*16)(%rdx), RR1;
  12746. @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
  12747. call __cast5_dec_blk16;
  12748. /* xor with src */
  12749. - vmovq (%r12), RX;
  12750. + vmovq (%r14), RX;
  12751. vpshufd $0x4f, RX, RX;
  12752. vpxor RX, RR1, RR1;
  12753. - vpxor 0*16+8(%r12), RL1, RL1;
  12754. - vpxor 1*16+8(%r12), RR2, RR2;
  12755. - vpxor 2*16+8(%r12), RL2, RL2;
  12756. - vpxor 3*16+8(%r12), RR3, RR3;
  12757. - vpxor 4*16+8(%r12), RL3, RL3;
  12758. - vpxor 5*16+8(%r12), RR4, RR4;
  12759. - vpxor 6*16+8(%r12), RL4, RL4;
  12760. + vpxor 0*16+8(%r14), RL1, RL1;
  12761. + vpxor 1*16+8(%r14), RR2, RR2;
  12762. + vpxor 2*16+8(%r14), RL2, RL2;
  12763. + vpxor 3*16+8(%r14), RR3, RR3;
  12764. + vpxor 4*16+8(%r14), RL3, RL3;
  12765. + vpxor 5*16+8(%r14), RR4, RR4;
  12766. + vpxor 6*16+8(%r14), RL4, RL4;
  12767. vmovdqu RR1, (0*16)(%r11);
  12768. vmovdqu RL1, (1*16)(%r11);
  12769. @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
  12770. vmovdqu RR4, (6*16)(%r11);
  12771. vmovdqu RL4, (7*16)(%r11);
  12772. - popq %r12;
  12773. + popq %r14;
  12774. + pax_force_retaddr
  12775. ret;
  12776. ENDPROC(cast5_cbc_dec_16way)
  12777. @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
  12778. * %rcx: iv (big endian, 64bit)
  12779. */
  12780. - pushq %r12;
  12781. + pushq %r14;
  12782. movq %rsi, %r11;
  12783. - movq %rdx, %r12;
  12784. + movq %rdx, %r14;
  12785. vpcmpeqd RTMP, RTMP, RTMP;
  12786. vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
  12787. @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
  12788. call __cast5_enc_blk16;
  12789. /* dst = src ^ iv */
  12790. - vpxor (0*16)(%r12), RR1, RR1;
  12791. - vpxor (1*16)(%r12), RL1, RL1;
  12792. - vpxor (2*16)(%r12), RR2, RR2;
  12793. - vpxor (3*16)(%r12), RL2, RL2;
  12794. - vpxor (4*16)(%r12), RR3, RR3;
  12795. - vpxor (5*16)(%r12), RL3, RL3;
  12796. - vpxor (6*16)(%r12), RR4, RR4;
  12797. - vpxor (7*16)(%r12), RL4, RL4;
  12798. + vpxor (0*16)(%r14), RR1, RR1;
  12799. + vpxor (1*16)(%r14), RL1, RL1;
  12800. + vpxor (2*16)(%r14), RR2, RR2;
  12801. + vpxor (3*16)(%r14), RL2, RL2;
  12802. + vpxor (4*16)(%r14), RR3, RR3;
  12803. + vpxor (5*16)(%r14), RL3, RL3;
  12804. + vpxor (6*16)(%r14), RR4, RR4;
  12805. + vpxor (7*16)(%r14), RL4, RL4;
  12806. vmovdqu RR1, (0*16)(%r11);
  12807. vmovdqu RL1, (1*16)(%r11);
  12808. vmovdqu RR2, (2*16)(%r11);
  12809. @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
  12810. vmovdqu RR4, (6*16)(%r11);
  12811. vmovdqu RL4, (7*16)(%r11);
  12812. - popq %r12;
  12813. + popq %r14;
  12814. + pax_force_retaddr
  12815. ret;
  12816. ENDPROC(cast5_ctr_16way)
  12817. diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
  12818. index e3531f8..e123f35 100644
  12819. --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
  12820. +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
  12821. @@ -24,6 +24,7 @@
  12822. */
  12823. #include <linux/linkage.h>
  12824. +#include <asm/alternative-asm.h>
  12825. #include "glue_helper-asm-avx.S"
  12826. .file "cast6-avx-x86_64-asm_64.S"
  12827. @@ -295,6 +296,7 @@ __cast6_enc_blk8:
  12828. outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
  12829. outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
  12830. + pax_force_retaddr
  12831. ret;
  12832. ENDPROC(__cast6_enc_blk8)
  12833. @@ -340,6 +342,7 @@ __cast6_dec_blk8:
  12834. outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
  12835. outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
  12836. + pax_force_retaddr
  12837. ret;
  12838. ENDPROC(__cast6_dec_blk8)
  12839. @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
  12840. store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12841. + pax_force_retaddr
  12842. ret;
  12843. ENDPROC(cast6_ecb_enc_8way)
  12844. @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
  12845. store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12846. + pax_force_retaddr
  12847. ret;
  12848. ENDPROC(cast6_ecb_dec_8way)
  12849. @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
  12850. * %rdx: src
  12851. */
  12852. - pushq %r12;
  12853. + pushq %r14;
  12854. movq %rsi, %r11;
  12855. - movq %rdx, %r12;
  12856. + movq %rdx, %r14;
  12857. load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12858. call __cast6_dec_blk8;
  12859. - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12860. + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12861. - popq %r12;
  12862. + popq %r14;
  12863. + pax_force_retaddr
  12864. ret;
  12865. ENDPROC(cast6_cbc_dec_8way)
  12866. @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
  12867. * %rcx: iv (little endian, 128bit)
  12868. */
  12869. - pushq %r12;
  12870. + pushq %r14;
  12871. movq %rsi, %r11;
  12872. - movq %rdx, %r12;
  12873. + movq %rdx, %r14;
  12874. load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
  12875. RD2, RX, RKR, RKM);
  12876. call __cast6_enc_blk8;
  12877. - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12878. + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12879. - popq %r12;
  12880. + popq %r14;
  12881. + pax_force_retaddr
  12882. ret;
  12883. ENDPROC(cast6_ctr_8way)
  12884. @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
  12885. /* dst <= regs xor IVs(in dst) */
  12886. store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12887. + pax_force_retaddr
  12888. ret;
  12889. ENDPROC(cast6_xts_enc_8way)
  12890. @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
  12891. /* dst <= regs xor IVs(in dst) */
  12892. store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12893. + pax_force_retaddr
  12894. ret;
  12895. ENDPROC(cast6_xts_dec_8way)
  12896. diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
  12897. index dbc4339..de6e120 100644
  12898. --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
  12899. +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
  12900. @@ -45,6 +45,7 @@
  12901. #include <asm/inst.h>
  12902. #include <linux/linkage.h>
  12903. +#include <asm/alternative-asm.h>
  12904. ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
  12905. @@ -312,6 +313,7 @@ do_return:
  12906. popq %rsi
  12907. popq %rdi
  12908. popq %rbx
  12909. + pax_force_retaddr
  12910. ret
  12911. ################################################################
  12912. diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
  12913. index 185fad4..ff4cd36 100644
  12914. --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
  12915. +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
  12916. @@ -18,6 +18,7 @@
  12917. #include <linux/linkage.h>
  12918. #include <asm/inst.h>
  12919. +#include <asm/alternative-asm.h>
  12920. .data
  12921. @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
  12922. psrlq $1, T2
  12923. pxor T2, T1
  12924. pxor T1, DATA
  12925. + pax_force_retaddr
  12926. ret
  12927. ENDPROC(__clmul_gf128mul_ble)
  12928. @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
  12929. call __clmul_gf128mul_ble
  12930. PSHUFB_XMM BSWAP DATA
  12931. movups DATA, (%rdi)
  12932. + pax_force_retaddr
  12933. ret
  12934. ENDPROC(clmul_ghash_mul)
  12935. @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
  12936. PSHUFB_XMM BSWAP DATA
  12937. movups DATA, (%rdi)
  12938. .Lupdate_just_ret:
  12939. + pax_force_retaddr
  12940. ret
  12941. ENDPROC(clmul_ghash_update)
  12942. diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
  12943. index 9279e0b..c4b3d2c 100644
  12944. --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
  12945. +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
  12946. @@ -1,4 +1,5 @@
  12947. #include <linux/linkage.h>
  12948. +#include <asm/alternative-asm.h>
  12949. # enter salsa20_encrypt_bytes
  12950. ENTRY(salsa20_encrypt_bytes)
  12951. @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
  12952. add %r11,%rsp
  12953. mov %rdi,%rax
  12954. mov %rsi,%rdx
  12955. + pax_force_retaddr
  12956. ret
  12957. # bytesatleast65:
  12958. ._bytesatleast65:
  12959. @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
  12960. add %r11,%rsp
  12961. mov %rdi,%rax
  12962. mov %rsi,%rdx
  12963. + pax_force_retaddr
  12964. ret
  12965. ENDPROC(salsa20_keysetup)
  12966. @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
  12967. add %r11,%rsp
  12968. mov %rdi,%rax
  12969. mov %rsi,%rdx
  12970. + pax_force_retaddr
  12971. ret
  12972. ENDPROC(salsa20_ivsetup)
  12973. diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
  12974. index 2f202f4..d9164d6 100644
  12975. --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
  12976. +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
  12977. @@ -24,6 +24,7 @@
  12978. */
  12979. #include <linux/linkage.h>
  12980. +#include <asm/alternative-asm.h>
  12981. #include "glue_helper-asm-avx.S"
  12982. .file "serpent-avx-x86_64-asm_64.S"
  12983. @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
  12984. write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
  12985. write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
  12986. + pax_force_retaddr
  12987. ret;
  12988. ENDPROC(__serpent_enc_blk8_avx)
  12989. @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
  12990. write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
  12991. write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
  12992. + pax_force_retaddr
  12993. ret;
  12994. ENDPROC(__serpent_dec_blk8_avx)
  12995. @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
  12996. store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  12997. + pax_force_retaddr
  12998. ret;
  12999. ENDPROC(serpent_ecb_enc_8way_avx)
  13000. @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
  13001. store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
  13002. + pax_force_retaddr
  13003. ret;
  13004. ENDPROC(serpent_ecb_dec_8way_avx)
  13005. @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
  13006. store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
  13007. + pax_force_retaddr
  13008. ret;
  13009. ENDPROC(serpent_cbc_dec_8way_avx)
  13010. @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
  13011. store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  13012. + pax_force_retaddr
  13013. ret;
  13014. ENDPROC(serpent_ctr_8way_avx)
  13015. @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
  13016. /* dst <= regs xor IVs(in dst) */
  13017. store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  13018. + pax_force_retaddr
  13019. ret;
  13020. ENDPROC(serpent_xts_enc_8way_avx)
  13021. @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
  13022. /* dst <= regs xor IVs(in dst) */
  13023. store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
  13024. + pax_force_retaddr
  13025. ret;
  13026. ENDPROC(serpent_xts_dec_8way_avx)
  13027. diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
  13028. index b222085..abd483c 100644
  13029. --- a/arch/x86/crypto/serpent-avx2-asm_64.S
  13030. +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
  13031. @@ -15,6 +15,7 @@
  13032. */
  13033. #include <linux/linkage.h>
  13034. +#include <asm/alternative-asm.h>
  13035. #include "glue_helper-asm-avx2.S"
  13036. .file "serpent-avx2-asm_64.S"
  13037. @@ -610,6 +611,7 @@ __serpent_enc_blk16:
  13038. write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
  13039. write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
  13040. + pax_force_retaddr
  13041. ret;
  13042. ENDPROC(__serpent_enc_blk16)
  13043. @@ -664,6 +666,7 @@ __serpent_dec_blk16:
  13044. write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
  13045. write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
  13046. + pax_force_retaddr
  13047. ret;
  13048. ENDPROC(__serpent_dec_blk16)
  13049. @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
  13050. vzeroupper;
  13051. + pax_force_retaddr
  13052. ret;
  13053. ENDPROC(serpent_ecb_enc_16way)
  13054. @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
  13055. vzeroupper;
  13056. + pax_force_retaddr
  13057. ret;
  13058. ENDPROC(serpent_ecb_dec_16way)
  13059. @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
  13060. vzeroupper;
  13061. + pax_force_retaddr
  13062. ret;
  13063. ENDPROC(serpent_cbc_dec_16way)
  13064. @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
  13065. vzeroupper;
  13066. + pax_force_retaddr
  13067. ret;
  13068. ENDPROC(serpent_ctr_16way)
  13069. @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
  13070. vzeroupper;
  13071. + pax_force_retaddr
  13072. ret;
  13073. ENDPROC(serpent_xts_enc_16way)
  13074. @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
  13075. vzeroupper;
  13076. + pax_force_retaddr
  13077. ret;
  13078. ENDPROC(serpent_xts_dec_16way)
  13079. diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
  13080. index acc066c..1559cc4 100644
  13081. --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
  13082. +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
  13083. @@ -25,6 +25,7 @@
  13084. */
  13085. #include <linux/linkage.h>
  13086. +#include <asm/alternative-asm.h>
  13087. .file "serpent-sse2-x86_64-asm_64.S"
  13088. .text
  13089. @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
  13090. write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
  13091. write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
  13092. + pax_force_retaddr
  13093. ret;
  13094. .L__enc_xor8:
  13095. xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
  13096. xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
  13097. + pax_force_retaddr
  13098. ret;
  13099. ENDPROC(__serpent_enc_blk_8way)
  13100. @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
  13101. write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
  13102. write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
  13103. + pax_force_retaddr
  13104. ret;
  13105. ENDPROC(serpent_dec_blk_8way)
  13106. diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
  13107. index a410950..9dfe7ad 100644
  13108. --- a/arch/x86/crypto/sha1_ssse3_asm.S
  13109. +++ b/arch/x86/crypto/sha1_ssse3_asm.S
  13110. @@ -29,6 +29,7 @@
  13111. */
  13112. #include <linux/linkage.h>
  13113. +#include <asm/alternative-asm.h>
  13114. #define CTX %rdi // arg1
  13115. #define BUF %rsi // arg2
  13116. @@ -75,9 +76,9 @@
  13117. push %rbx
  13118. push %rbp
  13119. - push %r12
  13120. + push %r14
  13121. - mov %rsp, %r12
  13122. + mov %rsp, %r14
  13123. sub $64, %rsp # allocate workspace
  13124. and $~15, %rsp # align stack
  13125. @@ -99,11 +100,12 @@
  13126. xor %rax, %rax
  13127. rep stosq
  13128. - mov %r12, %rsp # deallocate workspace
  13129. + mov %r14, %rsp # deallocate workspace
  13130. - pop %r12
  13131. + pop %r14
  13132. pop %rbp
  13133. pop %rbx
  13134. + pax_force_retaddr
  13135. ret
  13136. ENDPROC(\name)
  13137. diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
  13138. index 642f156..51a513c 100644
  13139. --- a/arch/x86/crypto/sha256-avx-asm.S
  13140. +++ b/arch/x86/crypto/sha256-avx-asm.S
  13141. @@ -49,6 +49,7 @@
  13142. #ifdef CONFIG_AS_AVX
  13143. #include <linux/linkage.h>
  13144. +#include <asm/alternative-asm.h>
  13145. ## assume buffers not aligned
  13146. #define VMOVDQ vmovdqu
  13147. @@ -460,6 +461,7 @@ done_hash:
  13148. popq %r13
  13149. popq %rbp
  13150. popq %rbx
  13151. + pax_force_retaddr
  13152. ret
  13153. ENDPROC(sha256_transform_avx)
  13154. diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
  13155. index 9e86944..3795e6a 100644
  13156. --- a/arch/x86/crypto/sha256-avx2-asm.S
  13157. +++ b/arch/x86/crypto/sha256-avx2-asm.S
  13158. @@ -50,6 +50,7 @@
  13159. #ifdef CONFIG_AS_AVX2
  13160. #include <linux/linkage.h>
  13161. +#include <asm/alternative-asm.h>
  13162. ## assume buffers not aligned
  13163. #define VMOVDQ vmovdqu
  13164. @@ -720,6 +721,7 @@ done_hash:
  13165. popq %r12
  13166. popq %rbp
  13167. popq %rbx
  13168. + pax_force_retaddr
  13169. ret
  13170. ENDPROC(sha256_transform_rorx)
  13171. diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
  13172. index f833b74..8c62a9e 100644
  13173. --- a/arch/x86/crypto/sha256-ssse3-asm.S
  13174. +++ b/arch/x86/crypto/sha256-ssse3-asm.S
  13175. @@ -47,6 +47,7 @@
  13176. ########################################################################
  13177. #include <linux/linkage.h>
  13178. +#include <asm/alternative-asm.h>
  13179. ## assume buffers not aligned
  13180. #define MOVDQ movdqu
  13181. @@ -471,6 +472,7 @@ done_hash:
  13182. popq %rbp
  13183. popq %rbx
  13184. + pax_force_retaddr
  13185. ret
  13186. ENDPROC(sha256_transform_ssse3)
  13187. diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
  13188. index 974dde9..a823ff9 100644
  13189. --- a/arch/x86/crypto/sha512-avx-asm.S
  13190. +++ b/arch/x86/crypto/sha512-avx-asm.S
  13191. @@ -49,6 +49,7 @@
  13192. #ifdef CONFIG_AS_AVX
  13193. #include <linux/linkage.h>
  13194. +#include <asm/alternative-asm.h>
  13195. .text
  13196. @@ -364,6 +365,7 @@ updateblock:
  13197. mov frame_RSPSAVE(%rsp), %rsp
  13198. nowork:
  13199. + pax_force_retaddr
  13200. ret
  13201. ENDPROC(sha512_transform_avx)
  13202. diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
  13203. index 568b961..ed20c37 100644
  13204. --- a/arch/x86/crypto/sha512-avx2-asm.S
  13205. +++ b/arch/x86/crypto/sha512-avx2-asm.S
  13206. @@ -51,6 +51,7 @@
  13207. #ifdef CONFIG_AS_AVX2
  13208. #include <linux/linkage.h>
  13209. +#include <asm/alternative-asm.h>
  13210. .text
  13211. @@ -678,6 +679,7 @@ done_hash:
  13212. # Restore Stack Pointer
  13213. mov frame_RSPSAVE(%rsp), %rsp
  13214. + pax_force_retaddr
  13215. ret
  13216. ENDPROC(sha512_transform_rorx)
  13217. diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
  13218. index fb56855..6edd768 100644
  13219. --- a/arch/x86/crypto/sha512-ssse3-asm.S
  13220. +++ b/arch/x86/crypto/sha512-ssse3-asm.S
  13221. @@ -48,6 +48,7 @@
  13222. ########################################################################
  13223. #include <linux/linkage.h>
  13224. +#include <asm/alternative-asm.h>
  13225. .text
  13226. @@ -363,6 +364,7 @@ updateblock:
  13227. mov frame_RSPSAVE(%rsp), %rsp
  13228. nowork:
  13229. + pax_force_retaddr
  13230. ret
  13231. ENDPROC(sha512_transform_ssse3)
  13232. diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
  13233. index 0505813..b067311 100644
  13234. --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
  13235. +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
  13236. @@ -24,6 +24,7 @@
  13237. */
  13238. #include <linux/linkage.h>
  13239. +#include <asm/alternative-asm.h>
  13240. #include "glue_helper-asm-avx.S"
  13241. .file "twofish-avx-x86_64-asm_64.S"
  13242. @@ -284,6 +285,7 @@ __twofish_enc_blk8:
  13243. outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
  13244. outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
  13245. + pax_force_retaddr
  13246. ret;
  13247. ENDPROC(__twofish_enc_blk8)
  13248. @@ -324,6 +326,7 @@ __twofish_dec_blk8:
  13249. outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
  13250. outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
  13251. + pax_force_retaddr
  13252. ret;
  13253. ENDPROC(__twofish_dec_blk8)
  13254. @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
  13255. store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
  13256. + pax_force_retaddr
  13257. ret;
  13258. ENDPROC(twofish_ecb_enc_8way)
  13259. @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
  13260. store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  13261. + pax_force_retaddr
  13262. ret;
  13263. ENDPROC(twofish_ecb_dec_8way)
  13264. @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
  13265. * %rdx: src
  13266. */
  13267. - pushq %r12;
  13268. + pushq %r14;
  13269. movq %rsi, %r11;
  13270. - movq %rdx, %r12;
  13271. + movq %rdx, %r14;
  13272. load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
  13273. call __twofish_dec_blk8;
  13274. - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  13275. + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  13276. - popq %r12;
  13277. + popq %r14;
  13278. + pax_force_retaddr
  13279. ret;
  13280. ENDPROC(twofish_cbc_dec_8way)
  13281. @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
  13282. * %rcx: iv (little endian, 128bit)
  13283. */
  13284. - pushq %r12;
  13285. + pushq %r14;
  13286. movq %rsi, %r11;
  13287. - movq %rdx, %r12;
  13288. + movq %rdx, %r14;
  13289. load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
  13290. RD2, RX0, RX1, RY0);
  13291. call __twofish_enc_blk8;
  13292. - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
  13293. + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
  13294. - popq %r12;
  13295. + popq %r14;
  13296. + pax_force_retaddr
  13297. ret;
  13298. ENDPROC(twofish_ctr_8way)
  13299. @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
  13300. /* dst <= regs xor IVs(in dst) */
  13301. store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
  13302. + pax_force_retaddr
  13303. ret;
  13304. ENDPROC(twofish_xts_enc_8way)
  13305. @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
  13306. /* dst <= regs xor IVs(in dst) */
  13307. store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
  13308. + pax_force_retaddr
  13309. ret;
  13310. ENDPROC(twofish_xts_dec_8way)
  13311. diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
  13312. index 1c3b7ce..02f578d 100644
  13313. --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
  13314. +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
  13315. @@ -21,6 +21,7 @@
  13316. */
  13317. #include <linux/linkage.h>
  13318. +#include <asm/alternative-asm.h>
  13319. .file "twofish-x86_64-asm-3way.S"
  13320. .text
  13321. @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
  13322. popq %r13;
  13323. popq %r14;
  13324. popq %r15;
  13325. + pax_force_retaddr
  13326. ret;
  13327. .L__enc_xor3:
  13328. @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
  13329. popq %r13;
  13330. popq %r14;
  13331. popq %r15;
  13332. + pax_force_retaddr
  13333. ret;
  13334. ENDPROC(__twofish_enc_blk_3way)
  13335. @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
  13336. popq %r13;
  13337. popq %r14;
  13338. popq %r15;
  13339. + pax_force_retaddr
  13340. ret;
  13341. ENDPROC(twofish_dec_blk_3way)
  13342. diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
  13343. index a039d21..524b8b2 100644
  13344. --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
  13345. +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
  13346. @@ -22,6 +22,7 @@
  13347. #include <linux/linkage.h>
  13348. #include <asm/asm-offsets.h>
  13349. +#include <asm/alternative-asm.h>
  13350. #define a_offset 0
  13351. #define b_offset 4
  13352. @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
  13353. popq R1
  13354. movq $1,%rax
  13355. + pax_force_retaddr
  13356. ret
  13357. ENDPROC(twofish_enc_blk)
  13358. @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
  13359. popq R1
  13360. movq $1,%rax
  13361. + pax_force_retaddr
  13362. ret
  13363. ENDPROC(twofish_dec_blk)
  13364. diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
  13365. index d21ff89..6da8e6e 100644
  13366. --- a/arch/x86/ia32/ia32_aout.c
  13367. +++ b/arch/x86/ia32/ia32_aout.c
  13368. @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
  13369. unsigned long dump_start, dump_size;
  13370. struct user32 dump;
  13371. + memset(&dump, 0, sizeof(dump));
  13372. +
  13373. fs = get_fs();
  13374. set_fs(KERNEL_DS);
  13375. has_dumped = 1;
  13376. diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
  13377. index 2206757..85cbcfa 100644
  13378. --- a/arch/x86/ia32/ia32_signal.c
  13379. +++ b/arch/x86/ia32/ia32_signal.c
  13380. @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
  13381. if (__get_user(set.sig[0], &frame->sc.oldmask)
  13382. || (_COMPAT_NSIG_WORDS > 1
  13383. && __copy_from_user((((char *) &set.sig) + 4),
  13384. - &frame->extramask,
  13385. + frame->extramask,
  13386. sizeof(frame->extramask))))
  13387. goto badframe;
  13388. @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
  13389. sp -= frame_size;
  13390. /* Align the stack pointer according to the i386 ABI,
  13391. * i.e. so that on function entry ((sp + 4) & 15) == 0. */
  13392. - sp = ((sp + 4) & -16ul) - 4;
  13393. + sp = ((sp - 12) & -16ul) - 4;
  13394. return (void __user *) sp;
  13395. }
  13396. @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
  13397. restorer = VDSO32_SYMBOL(current->mm->context.vdso,
  13398. sigreturn);
  13399. else
  13400. - restorer = &frame->retcode;
  13401. + restorer = frame->retcode;
  13402. }
  13403. put_user_try {
  13404. @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
  13405. * These are actually not used anymore, but left because some
  13406. * gdb versions depend on them as a marker.
  13407. */
  13408. - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
  13409. + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
  13410. } put_user_catch(err);
  13411. if (err)
  13412. @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
  13413. 0xb8,
  13414. __NR_ia32_rt_sigreturn,
  13415. 0x80cd,
  13416. - 0,
  13417. + 0
  13418. };
  13419. frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
  13420. @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
  13421. if (ksig->ka.sa.sa_flags & SA_RESTORER)
  13422. restorer = ksig->ka.sa.sa_restorer;
  13423. + else if (current->mm->context.vdso)
  13424. + /* Return stub is in 32bit vsyscall page */
  13425. + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
  13426. else
  13427. - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
  13428. - rt_sigreturn);
  13429. + restorer = frame->retcode;
  13430. put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
  13431. /*
  13432. * Not actually used anymore, but left because some gdb
  13433. * versions need it.
  13434. */
  13435. - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
  13436. + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
  13437. } put_user_catch(err);
  13438. err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
  13439. diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
  13440. index 4299eb0..c0687a7 100644
  13441. --- a/arch/x86/ia32/ia32entry.S
  13442. +++ b/arch/x86/ia32/ia32entry.S
  13443. @@ -15,8 +15,10 @@
  13444. #include <asm/irqflags.h>
  13445. #include <asm/asm.h>
  13446. #include <asm/smap.h>
  13447. +#include <asm/pgtable.h>
  13448. #include <linux/linkage.h>
  13449. #include <linux/err.h>
  13450. +#include <asm/alternative-asm.h>
  13451. /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
  13452. #include <linux/elf-em.h>
  13453. @@ -62,12 +64,12 @@
  13454. */
  13455. .macro LOAD_ARGS32 offset, _r9=0
  13456. .if \_r9
  13457. - movl \offset+16(%rsp),%r9d
  13458. + movl \offset+R9(%rsp),%r9d
  13459. .endif
  13460. - movl \offset+40(%rsp),%ecx
  13461. - movl \offset+48(%rsp),%edx
  13462. - movl \offset+56(%rsp),%esi
  13463. - movl \offset+64(%rsp),%edi
  13464. + movl \offset+RCX(%rsp),%ecx
  13465. + movl \offset+RDX(%rsp),%edx
  13466. + movl \offset+RSI(%rsp),%esi
  13467. + movl \offset+RDI(%rsp),%edi
  13468. movl %eax,%eax /* zero extension */
  13469. .endm
  13470. @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
  13471. ENDPROC(native_irq_enable_sysexit)
  13472. #endif
  13473. + .macro pax_enter_kernel_user
  13474. + pax_set_fptr_mask
  13475. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13476. + call pax_enter_kernel_user
  13477. +#endif
  13478. + .endm
  13479. +
  13480. + .macro pax_exit_kernel_user
  13481. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13482. + call pax_exit_kernel_user
  13483. +#endif
  13484. +#ifdef CONFIG_PAX_RANDKSTACK
  13485. + pushq %rax
  13486. + pushq %r11
  13487. + call pax_randomize_kstack
  13488. + popq %r11
  13489. + popq %rax
  13490. +#endif
  13491. + .endm
  13492. +
  13493. + .macro pax_erase_kstack
  13494. +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
  13495. + call pax_erase_kstack
  13496. +#endif
  13497. + .endm
  13498. +
  13499. /*
  13500. * 32bit SYSENTER instruction entry.
  13501. *
  13502. @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
  13503. CFI_REGISTER rsp,rbp
  13504. SWAPGS_UNSAFE_STACK
  13505. movq PER_CPU_VAR(kernel_stack), %rsp
  13506. - addq $(KERNEL_STACK_OFFSET),%rsp
  13507. - /*
  13508. - * No need to follow this irqs on/off section: the syscall
  13509. - * disabled irqs, here we enable it straight after entry:
  13510. - */
  13511. - ENABLE_INTERRUPTS(CLBR_NONE)
  13512. movl %ebp,%ebp /* zero extension */
  13513. pushq_cfi $__USER32_DS
  13514. /*CFI_REL_OFFSET ss,0*/
  13515. @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
  13516. CFI_REL_OFFSET rsp,0
  13517. pushfq_cfi
  13518. /*CFI_REL_OFFSET rflags,0*/
  13519. - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
  13520. - CFI_REGISTER rip,r10
  13521. + orl $X86_EFLAGS_IF,(%rsp)
  13522. + GET_THREAD_INFO(%r11)
  13523. + movl TI_sysenter_return(%r11), %r11d
  13524. + CFI_REGISTER rip,r11
  13525. pushq_cfi $__USER32_CS
  13526. /*CFI_REL_OFFSET cs,0*/
  13527. movl %eax, %eax
  13528. - pushq_cfi %r10
  13529. + pushq_cfi %r11
  13530. CFI_REL_OFFSET rip,0
  13531. pushq_cfi %rax
  13532. cld
  13533. SAVE_ARGS 0,1,0
  13534. + pax_enter_kernel_user
  13535. +
  13536. +#ifdef CONFIG_PAX_RANDKSTACK
  13537. + pax_erase_kstack
  13538. +#endif
  13539. +
  13540. + /*
  13541. + * No need to follow this irqs on/off section: the syscall
  13542. + * disabled irqs, here we enable it straight after entry:
  13543. + */
  13544. + ENABLE_INTERRUPTS(CLBR_NONE)
  13545. /* no need to do an access_ok check here because rbp has been
  13546. 32bit zero extended */
  13547. +
  13548. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13549. + addq pax_user_shadow_base,%rbp
  13550. + ASM_PAX_OPEN_USERLAND
  13551. +#endif
  13552. +
  13553. ASM_STAC
  13554. 1: movl (%rbp),%ebp
  13555. _ASM_EXTABLE(1b,ia32_badarg)
  13556. ASM_CLAC
  13557. - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13558. - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13559. +
  13560. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13561. + ASM_PAX_CLOSE_USERLAND
  13562. +#endif
  13563. +
  13564. + GET_THREAD_INFO(%r11)
  13565. + orl $TS_COMPAT,TI_status(%r11)
  13566. + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
  13567. CFI_REMEMBER_STATE
  13568. jnz sysenter_tracesys
  13569. cmpq $(IA32_NR_syscalls-1),%rax
  13570. @@ -162,15 +209,18 @@ sysenter_do_call:
  13571. sysenter_dispatch:
  13572. call *ia32_sys_call_table(,%rax,8)
  13573. movq %rax,RAX-ARGOFFSET(%rsp)
  13574. + GET_THREAD_INFO(%r11)
  13575. DISABLE_INTERRUPTS(CLBR_NONE)
  13576. TRACE_IRQS_OFF
  13577. - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13578. + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
  13579. jnz sysexit_audit
  13580. sysexit_from_sys_call:
  13581. - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13582. + pax_exit_kernel_user
  13583. + pax_erase_kstack
  13584. + andl $~TS_COMPAT,TI_status(%r11)
  13585. /* clear IF, that popfq doesn't enable interrupts early */
  13586. - andl $~0x200,EFLAGS-R11(%rsp)
  13587. - movl RIP-R11(%rsp),%edx /* User %eip */
  13588. + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
  13589. + movl RIP(%rsp),%edx /* User %eip */
  13590. CFI_REGISTER rip,rdx
  13591. RESTORE_ARGS 0,24,0,0,0,0
  13592. xorq %r8,%r8
  13593. @@ -193,6 +243,9 @@ sysexit_from_sys_call:
  13594. movl %eax,%esi /* 2nd arg: syscall number */
  13595. movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
  13596. call __audit_syscall_entry
  13597. +
  13598. + pax_erase_kstack
  13599. +
  13600. movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
  13601. cmpq $(IA32_NR_syscalls-1),%rax
  13602. ja ia32_badsys
  13603. @@ -204,7 +257,7 @@ sysexit_from_sys_call:
  13604. .endm
  13605. .macro auditsys_exit exit
  13606. - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13607. + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
  13608. jnz ia32_ret_from_sys_call
  13609. TRACE_IRQS_ON
  13610. ENABLE_INTERRUPTS(CLBR_NONE)
  13611. @@ -215,11 +268,12 @@ sysexit_from_sys_call:
  13612. 1: setbe %al /* 1 if error, 0 if not */
  13613. movzbl %al,%edi /* zero-extend that into %edi */
  13614. call __audit_syscall_exit
  13615. + GET_THREAD_INFO(%r11)
  13616. movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
  13617. movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
  13618. DISABLE_INTERRUPTS(CLBR_NONE)
  13619. TRACE_IRQS_OFF
  13620. - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13621. + testl %edi,TI_flags(%r11)
  13622. jz \exit
  13623. CLEAR_RREGS -ARGOFFSET
  13624. jmp int_with_check
  13625. @@ -237,7 +291,7 @@ sysexit_audit:
  13626. sysenter_tracesys:
  13627. #ifdef CONFIG_AUDITSYSCALL
  13628. - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13629. + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
  13630. jz sysenter_auditsys
  13631. #endif
  13632. SAVE_REST
  13633. @@ -249,6 +303,9 @@ sysenter_tracesys:
  13634. RESTORE_REST
  13635. cmpq $(IA32_NR_syscalls-1),%rax
  13636. ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
  13637. +
  13638. + pax_erase_kstack
  13639. +
  13640. jmp sysenter_do_call
  13641. CFI_ENDPROC
  13642. ENDPROC(ia32_sysenter_target)
  13643. @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
  13644. ENTRY(ia32_cstar_target)
  13645. CFI_STARTPROC32 simple
  13646. CFI_SIGNAL_FRAME
  13647. - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
  13648. + CFI_DEF_CFA rsp,0
  13649. CFI_REGISTER rip,rcx
  13650. /*CFI_REGISTER rflags,r11*/
  13651. SWAPGS_UNSAFE_STACK
  13652. movl %esp,%r8d
  13653. CFI_REGISTER rsp,r8
  13654. movq PER_CPU_VAR(kernel_stack),%rsp
  13655. + SAVE_ARGS 8*6,0,0
  13656. + pax_enter_kernel_user
  13657. +
  13658. +#ifdef CONFIG_PAX_RANDKSTACK
  13659. + pax_erase_kstack
  13660. +#endif
  13661. +
  13662. /*
  13663. * No need to follow this irqs on/off section: the syscall
  13664. * disabled irqs and here we enable it straight after entry:
  13665. */
  13666. ENABLE_INTERRUPTS(CLBR_NONE)
  13667. - SAVE_ARGS 8,0,0
  13668. movl %eax,%eax /* zero extension */
  13669. movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
  13670. movq %rcx,RIP-ARGOFFSET(%rsp)
  13671. @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
  13672. /* no need to do an access_ok check here because r8 has been
  13673. 32bit zero extended */
  13674. /* hardware stack frame is complete now */
  13675. +
  13676. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13677. + ASM_PAX_OPEN_USERLAND
  13678. + movq pax_user_shadow_base,%r8
  13679. + addq RSP-ARGOFFSET(%rsp),%r8
  13680. +#endif
  13681. +
  13682. ASM_STAC
  13683. 1: movl (%r8),%r9d
  13684. _ASM_EXTABLE(1b,ia32_badarg)
  13685. ASM_CLAC
  13686. - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13687. - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13688. +
  13689. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13690. + ASM_PAX_CLOSE_USERLAND
  13691. +#endif
  13692. +
  13693. + GET_THREAD_INFO(%r11)
  13694. + orl $TS_COMPAT,TI_status(%r11)
  13695. + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
  13696. CFI_REMEMBER_STATE
  13697. jnz cstar_tracesys
  13698. cmpq $IA32_NR_syscalls-1,%rax
  13699. @@ -319,13 +395,16 @@ cstar_do_call:
  13700. cstar_dispatch:
  13701. call *ia32_sys_call_table(,%rax,8)
  13702. movq %rax,RAX-ARGOFFSET(%rsp)
  13703. + GET_THREAD_INFO(%r11)
  13704. DISABLE_INTERRUPTS(CLBR_NONE)
  13705. TRACE_IRQS_OFF
  13706. - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13707. + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
  13708. jnz sysretl_audit
  13709. sysretl_from_sys_call:
  13710. - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13711. - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
  13712. + pax_exit_kernel_user
  13713. + pax_erase_kstack
  13714. + andl $~TS_COMPAT,TI_status(%r11)
  13715. + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
  13716. movl RIP-ARGOFFSET(%rsp),%ecx
  13717. CFI_REGISTER rip,rcx
  13718. movl EFLAGS-ARGOFFSET(%rsp),%r11d
  13719. @@ -352,7 +431,7 @@ sysretl_audit:
  13720. cstar_tracesys:
  13721. #ifdef CONFIG_AUDITSYSCALL
  13722. - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13723. + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
  13724. jz cstar_auditsys
  13725. #endif
  13726. xchgl %r9d,%ebp
  13727. @@ -366,11 +445,19 @@ cstar_tracesys:
  13728. xchgl %ebp,%r9d
  13729. cmpq $(IA32_NR_syscalls-1),%rax
  13730. ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
  13731. +
  13732. + pax_erase_kstack
  13733. +
  13734. jmp cstar_do_call
  13735. END(ia32_cstar_target)
  13736. ia32_badarg:
  13737. ASM_CLAC
  13738. +
  13739. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  13740. + ASM_PAX_CLOSE_USERLAND
  13741. +#endif
  13742. +
  13743. movq $-EFAULT,%rax
  13744. jmp ia32_sysret
  13745. CFI_ENDPROC
  13746. @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
  13747. CFI_REL_OFFSET rip,RIP-RIP
  13748. PARAVIRT_ADJUST_EXCEPTION_FRAME
  13749. SWAPGS
  13750. - /*
  13751. - * No need to follow this irqs on/off section: the syscall
  13752. - * disabled irqs and here we enable it straight after entry:
  13753. - */
  13754. - ENABLE_INTERRUPTS(CLBR_NONE)
  13755. movl %eax,%eax
  13756. pushq_cfi %rax
  13757. cld
  13758. /* note the registers are not zero extended to the sf.
  13759. this could be a problem. */
  13760. SAVE_ARGS 0,1,0
  13761. - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13762. - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  13763. + pax_enter_kernel_user
  13764. +
  13765. +#ifdef CONFIG_PAX_RANDKSTACK
  13766. + pax_erase_kstack
  13767. +#endif
  13768. +
  13769. + /*
  13770. + * No need to follow this irqs on/off section: the syscall
  13771. + * disabled irqs and here we enable it straight after entry:
  13772. + */
  13773. + ENABLE_INTERRUPTS(CLBR_NONE)
  13774. + GET_THREAD_INFO(%r11)
  13775. + orl $TS_COMPAT,TI_status(%r11)
  13776. + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
  13777. jnz ia32_tracesys
  13778. cmpq $(IA32_NR_syscalls-1),%rax
  13779. ja ia32_badsys
  13780. @@ -442,6 +536,9 @@ ia32_tracesys:
  13781. RESTORE_REST
  13782. cmpq $(IA32_NR_syscalls-1),%rax
  13783. ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
  13784. +
  13785. + pax_erase_kstack
  13786. +
  13787. jmp ia32_do_call
  13788. END(ia32_syscall)
  13789. diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
  13790. index 8e0ceec..af13504 100644
  13791. --- a/arch/x86/ia32/sys_ia32.c
  13792. +++ b/arch/x86/ia32/sys_ia32.c
  13793. @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
  13794. */
  13795. static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
  13796. {
  13797. - typeof(ubuf->st_uid) uid = 0;
  13798. - typeof(ubuf->st_gid) gid = 0;
  13799. + typeof(((struct stat64 *)0)->st_uid) uid = 0;
  13800. + typeof(((struct stat64 *)0)->st_gid) gid = 0;
  13801. SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
  13802. SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
  13803. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
  13804. diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
  13805. index 372231c..51b537d 100644
  13806. --- a/arch/x86/include/asm/alternative-asm.h
  13807. +++ b/arch/x86/include/asm/alternative-asm.h
  13808. @@ -18,6 +18,45 @@
  13809. .endm
  13810. #endif
  13811. +#ifdef KERNEXEC_PLUGIN
  13812. + .macro pax_force_retaddr_bts rip=0
  13813. + btsq $63,\rip(%rsp)
  13814. + .endm
  13815. +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
  13816. + .macro pax_force_retaddr rip=0, reload=0
  13817. + btsq $63,\rip(%rsp)
  13818. + .endm
  13819. + .macro pax_force_fptr ptr
  13820. + btsq $63,\ptr
  13821. + .endm
  13822. + .macro pax_set_fptr_mask
  13823. + .endm
  13824. +#endif
  13825. +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
  13826. + .macro pax_force_retaddr rip=0, reload=0
  13827. + .if \reload
  13828. + pax_set_fptr_mask
  13829. + .endif
  13830. + orq %r12,\rip(%rsp)
  13831. + .endm
  13832. + .macro pax_force_fptr ptr
  13833. + orq %r12,\ptr
  13834. + .endm
  13835. + .macro pax_set_fptr_mask
  13836. + movabs $0x8000000000000000,%r12
  13837. + .endm
  13838. +#endif
  13839. +#else
  13840. + .macro pax_force_retaddr rip=0, reload=0
  13841. + .endm
  13842. + .macro pax_force_fptr ptr
  13843. + .endm
  13844. + .macro pax_force_retaddr_bts rip=0
  13845. + .endm
  13846. + .macro pax_set_fptr_mask
  13847. + .endm
  13848. +#endif
  13849. +
  13850. .macro altinstruction_entry orig alt feature orig_len alt_len
  13851. .long \orig - .
  13852. .long \alt - .
  13853. diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
  13854. index 0a3f9c9..c9d081d 100644
  13855. --- a/arch/x86/include/asm/alternative.h
  13856. +++ b/arch/x86/include/asm/alternative.h
  13857. @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
  13858. ".pushsection .discard,\"aw\",@progbits\n" \
  13859. DISCARD_ENTRY(1) \
  13860. ".popsection\n" \
  13861. - ".pushsection .altinstr_replacement, \"ax\"\n" \
  13862. + ".pushsection .altinstr_replacement, \"a\"\n" \
  13863. ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
  13864. ".popsection"
  13865. @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
  13866. DISCARD_ENTRY(1) \
  13867. DISCARD_ENTRY(2) \
  13868. ".popsection\n" \
  13869. - ".pushsection .altinstr_replacement, \"ax\"\n" \
  13870. + ".pushsection .altinstr_replacement, \"a\"\n" \
  13871. ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
  13872. ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
  13873. ".popsection"
  13874. diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
  13875. index 1d2091a..f5074c1 100644
  13876. --- a/arch/x86/include/asm/apic.h
  13877. +++ b/arch/x86/include/asm/apic.h
  13878. @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
  13879. #ifdef CONFIG_X86_LOCAL_APIC
  13880. -extern unsigned int apic_verbosity;
  13881. +extern int apic_verbosity;
  13882. extern int local_apic_timer_c2_ok;
  13883. extern int disable_apic;
  13884. diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
  13885. index 20370c6..a2eb9b0 100644
  13886. --- a/arch/x86/include/asm/apm.h
  13887. +++ b/arch/x86/include/asm/apm.h
  13888. @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
  13889. __asm__ __volatile__(APM_DO_ZERO_SEGS
  13890. "pushl %%edi\n\t"
  13891. "pushl %%ebp\n\t"
  13892. - "lcall *%%cs:apm_bios_entry\n\t"
  13893. + "lcall *%%ss:apm_bios_entry\n\t"
  13894. "setc %%al\n\t"
  13895. "popl %%ebp\n\t"
  13896. "popl %%edi\n\t"
  13897. @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
  13898. __asm__ __volatile__(APM_DO_ZERO_SEGS
  13899. "pushl %%edi\n\t"
  13900. "pushl %%ebp\n\t"
  13901. - "lcall *%%cs:apm_bios_entry\n\t"
  13902. + "lcall *%%ss:apm_bios_entry\n\t"
  13903. "setc %%bl\n\t"
  13904. "popl %%ebp\n\t"
  13905. "popl %%edi\n\t"
  13906. diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
  13907. index b17f4f4..9620151 100644
  13908. --- a/arch/x86/include/asm/atomic.h
  13909. +++ b/arch/x86/include/asm/atomic.h
  13910. @@ -23,7 +23,18 @@
  13911. */
  13912. static inline int atomic_read(const atomic_t *v)
  13913. {
  13914. - return (*(volatile int *)&(v)->counter);
  13915. + return (*(volatile const int *)&(v)->counter);
  13916. +}
  13917. +
  13918. +/**
  13919. + * atomic_read_unchecked - read atomic variable
  13920. + * @v: pointer of type atomic_unchecked_t
  13921. + *
  13922. + * Atomically reads the value of @v.
  13923. + */
  13924. +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
  13925. +{
  13926. + return (*(volatile const int *)&(v)->counter);
  13927. }
  13928. /**
  13929. @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
  13930. }
  13931. /**
  13932. + * atomic_set_unchecked - set atomic variable
  13933. + * @v: pointer of type atomic_unchecked_t
  13934. + * @i: required value
  13935. + *
  13936. + * Atomically sets the value of @v to @i.
  13937. + */
  13938. +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
  13939. +{
  13940. + v->counter = i;
  13941. +}
  13942. +
  13943. +/**
  13944. * atomic_add - add integer to atomic variable
  13945. * @i: integer value to add
  13946. * @v: pointer of type atomic_t
  13947. @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
  13948. */
  13949. static inline void atomic_add(int i, atomic_t *v)
  13950. {
  13951. - asm volatile(LOCK_PREFIX "addl %1,%0"
  13952. + asm volatile(LOCK_PREFIX "addl %1,%0\n"
  13953. +
  13954. +#ifdef CONFIG_PAX_REFCOUNT
  13955. + "jno 0f\n"
  13956. + LOCK_PREFIX "subl %1,%0\n"
  13957. + "int $4\n0:\n"
  13958. + _ASM_EXTABLE(0b, 0b)
  13959. +#endif
  13960. +
  13961. + : "+m" (v->counter)
  13962. + : "ir" (i));
  13963. +}
  13964. +
  13965. +/**
  13966. + * atomic_add_unchecked - add integer to atomic variable
  13967. + * @i: integer value to add
  13968. + * @v: pointer of type atomic_unchecked_t
  13969. + *
  13970. + * Atomically adds @i to @v.
  13971. + */
  13972. +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
  13973. +{
  13974. + asm volatile(LOCK_PREFIX "addl %1,%0\n"
  13975. : "+m" (v->counter)
  13976. : "ir" (i));
  13977. }
  13978. @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
  13979. */
  13980. static inline void atomic_sub(int i, atomic_t *v)
  13981. {
  13982. - asm volatile(LOCK_PREFIX "subl %1,%0"
  13983. + asm volatile(LOCK_PREFIX "subl %1,%0\n"
  13984. +
  13985. +#ifdef CONFIG_PAX_REFCOUNT
  13986. + "jno 0f\n"
  13987. + LOCK_PREFIX "addl %1,%0\n"
  13988. + "int $4\n0:\n"
  13989. + _ASM_EXTABLE(0b, 0b)
  13990. +#endif
  13991. +
  13992. + : "+m" (v->counter)
  13993. + : "ir" (i));
  13994. +}
  13995. +
  13996. +/**
  13997. + * atomic_sub_unchecked - subtract integer from atomic variable
  13998. + * @i: integer value to subtract
  13999. + * @v: pointer of type atomic_unchecked_t
  14000. + *
  14001. + * Atomically subtracts @i from @v.
  14002. + */
  14003. +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
  14004. +{
  14005. + asm volatile(LOCK_PREFIX "subl %1,%0\n"
  14006. : "+m" (v->counter)
  14007. : "ir" (i));
  14008. }
  14009. @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
  14010. */
  14011. static inline int atomic_sub_and_test(int i, atomic_t *v)
  14012. {
  14013. - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
  14014. + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
  14015. }
  14016. /**
  14017. @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
  14018. */
  14019. static inline void atomic_inc(atomic_t *v)
  14020. {
  14021. - asm volatile(LOCK_PREFIX "incl %0"
  14022. + asm volatile(LOCK_PREFIX "incl %0\n"
  14023. +
  14024. +#ifdef CONFIG_PAX_REFCOUNT
  14025. + "jno 0f\n"
  14026. + LOCK_PREFIX "decl %0\n"
  14027. + "int $4\n0:\n"
  14028. + _ASM_EXTABLE(0b, 0b)
  14029. +#endif
  14030. +
  14031. + : "+m" (v->counter));
  14032. +}
  14033. +
  14034. +/**
  14035. + * atomic_inc_unchecked - increment atomic variable
  14036. + * @v: pointer of type atomic_unchecked_t
  14037. + *
  14038. + * Atomically increments @v by 1.
  14039. + */
  14040. +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
  14041. +{
  14042. + asm volatile(LOCK_PREFIX "incl %0\n"
  14043. : "+m" (v->counter));
  14044. }
  14045. @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
  14046. */
  14047. static inline void atomic_dec(atomic_t *v)
  14048. {
  14049. - asm volatile(LOCK_PREFIX "decl %0"
  14050. + asm volatile(LOCK_PREFIX "decl %0\n"
  14051. +
  14052. +#ifdef CONFIG_PAX_REFCOUNT
  14053. + "jno 0f\n"
  14054. + LOCK_PREFIX "incl %0\n"
  14055. + "int $4\n0:\n"
  14056. + _ASM_EXTABLE(0b, 0b)
  14057. +#endif
  14058. +
  14059. + : "+m" (v->counter));
  14060. +}
  14061. +
  14062. +/**
  14063. + * atomic_dec_unchecked - decrement atomic variable
  14064. + * @v: pointer of type atomic_unchecked_t
  14065. + *
  14066. + * Atomically decrements @v by 1.
  14067. + */
  14068. +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
  14069. +{
  14070. + asm volatile(LOCK_PREFIX "decl %0\n"
  14071. : "+m" (v->counter));
  14072. }
  14073. @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
  14074. */
  14075. static inline int atomic_dec_and_test(atomic_t *v)
  14076. {
  14077. - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
  14078. + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
  14079. }
  14080. /**
  14081. @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
  14082. */
  14083. static inline int atomic_inc_and_test(atomic_t *v)
  14084. {
  14085. - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
  14086. + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
  14087. +}
  14088. +
  14089. +/**
  14090. + * atomic_inc_and_test_unchecked - increment and test
  14091. + * @v: pointer of type atomic_unchecked_t
  14092. + *
  14093. + * Atomically increments @v by 1
  14094. + * and returns true if the result is zero, or false for all
  14095. + * other cases.
  14096. + */
  14097. +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
  14098. +{
  14099. + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
  14100. }
  14101. /**
  14102. @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
  14103. */
  14104. static inline int atomic_add_negative(int i, atomic_t *v)
  14105. {
  14106. - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
  14107. + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
  14108. }
  14109. /**
  14110. @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
  14111. */
  14112. static inline int atomic_add_return(int i, atomic_t *v)
  14113. {
  14114. + return i + xadd_check_overflow(&v->counter, i);
  14115. +}
  14116. +
  14117. +/**
  14118. + * atomic_add_return_unchecked - add integer and return
  14119. + * @i: integer value to add
  14120. + * @v: pointer of type atomic_unchecked_t
  14121. + *
  14122. + * Atomically adds @i to @v and returns @i + @v
  14123. + */
  14124. +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
  14125. +{
  14126. return i + xadd(&v->counter, i);
  14127. }
  14128. @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
  14129. }
  14130. #define atomic_inc_return(v) (atomic_add_return(1, v))
  14131. +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
  14132. +{
  14133. + return atomic_add_return_unchecked(1, v);
  14134. +}
  14135. #define atomic_dec_return(v) (atomic_sub_return(1, v))
  14136. -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
  14137. +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
  14138. +{
  14139. + return cmpxchg(&v->counter, old, new);
  14140. +}
  14141. +
  14142. +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
  14143. {
  14144. return cmpxchg(&v->counter, old, new);
  14145. }
  14146. @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
  14147. return xchg(&v->counter, new);
  14148. }
  14149. +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
  14150. +{
  14151. + return xchg(&v->counter, new);
  14152. +}
  14153. +
  14154. /**
  14155. * __atomic_add_unless - add unless the number is already a given value
  14156. * @v: pointer of type atomic_t
  14157. @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
  14158. * Atomically adds @a to @v, so long as @v was not already @u.
  14159. * Returns the old value of @v.
  14160. */
  14161. -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  14162. +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
  14163. {
  14164. - int c, old;
  14165. + int c, old, new;
  14166. c = atomic_read(v);
  14167. for (;;) {
  14168. - if (unlikely(c == (u)))
  14169. + if (unlikely(c == u))
  14170. break;
  14171. - old = atomic_cmpxchg((v), c, c + (a));
  14172. +
  14173. + asm volatile("addl %2,%0\n"
  14174. +
  14175. +#ifdef CONFIG_PAX_REFCOUNT
  14176. + "jno 0f\n"
  14177. + "subl %2,%0\n"
  14178. + "int $4\n0:\n"
  14179. + _ASM_EXTABLE(0b, 0b)
  14180. +#endif
  14181. +
  14182. + : "=r" (new)
  14183. + : "0" (c), "ir" (a));
  14184. +
  14185. + old = atomic_cmpxchg(v, c, new);
  14186. if (likely(old == c))
  14187. break;
  14188. c = old;
  14189. @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  14190. }
  14191. /**
  14192. + * atomic_inc_not_zero_hint - increment if not null
  14193. + * @v: pointer of type atomic_t
  14194. + * @hint: probable value of the atomic before the increment
  14195. + *
  14196. + * This version of atomic_inc_not_zero() gives a hint of probable
  14197. + * value of the atomic. This helps processor to not read the memory
  14198. + * before doing the atomic read/modify/write cycle, lowering
  14199. + * number of bus transactions on some arches.
  14200. + *
  14201. + * Returns: 0 if increment was not done, 1 otherwise.
  14202. + */
  14203. +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
  14204. +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
  14205. +{
  14206. + int val, c = hint, new;
  14207. +
  14208. + /* sanity test, should be removed by compiler if hint is a constant */
  14209. + if (!hint)
  14210. + return __atomic_add_unless(v, 1, 0);
  14211. +
  14212. + do {
  14213. + asm volatile("incl %0\n"
  14214. +
  14215. +#ifdef CONFIG_PAX_REFCOUNT
  14216. + "jno 0f\n"
  14217. + "decl %0\n"
  14218. + "int $4\n0:\n"
  14219. + _ASM_EXTABLE(0b, 0b)
  14220. +#endif
  14221. +
  14222. + : "=r" (new)
  14223. + : "0" (c));
  14224. +
  14225. + val = atomic_cmpxchg(v, c, new);
  14226. + if (val == c)
  14227. + return 1;
  14228. + c = val;
  14229. + } while (c);
  14230. +
  14231. + return 0;
  14232. +}
  14233. +
  14234. +/**
  14235. * atomic_inc_short - increment of a short integer
  14236. * @v: pointer to type int
  14237. *
  14238. @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
  14239. #endif
  14240. /* These are x86-specific, used by some header files */
  14241. -#define atomic_clear_mask(mask, addr) \
  14242. - asm volatile(LOCK_PREFIX "andl %0,%1" \
  14243. - : : "r" (~(mask)), "m" (*(addr)) : "memory")
  14244. +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
  14245. +{
  14246. + asm volatile(LOCK_PREFIX "andl %1,%0"
  14247. + : "+m" (v->counter)
  14248. + : "r" (~(mask))
  14249. + : "memory");
  14250. +}
  14251. -#define atomic_set_mask(mask, addr) \
  14252. - asm volatile(LOCK_PREFIX "orl %0,%1" \
  14253. - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
  14254. - : "memory")
  14255. +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
  14256. +{
  14257. + asm volatile(LOCK_PREFIX "andl %1,%0"
  14258. + : "+m" (v->counter)
  14259. + : "r" (~(mask))
  14260. + : "memory");
  14261. +}
  14262. +
  14263. +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
  14264. +{
  14265. + asm volatile(LOCK_PREFIX "orl %1,%0"
  14266. + : "+m" (v->counter)
  14267. + : "r" (mask)
  14268. + : "memory");
  14269. +}
  14270. +
  14271. +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
  14272. +{
  14273. + asm volatile(LOCK_PREFIX "orl %1,%0"
  14274. + : "+m" (v->counter)
  14275. + : "r" (mask)
  14276. + : "memory");
  14277. +}
  14278. /* Atomic operations are already serializing on x86 */
  14279. #define smp_mb__before_atomic_dec() barrier()
  14280. diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
  14281. index b154de7..bf18a5a 100644
  14282. --- a/arch/x86/include/asm/atomic64_32.h
  14283. +++ b/arch/x86/include/asm/atomic64_32.h
  14284. @@ -12,6 +12,14 @@ typedef struct {
  14285. u64 __aligned(8) counter;
  14286. } atomic64_t;
  14287. +#ifdef CONFIG_PAX_REFCOUNT
  14288. +typedef struct {
  14289. + u64 __aligned(8) counter;
  14290. +} atomic64_unchecked_t;
  14291. +#else
  14292. +typedef atomic64_t atomic64_unchecked_t;
  14293. +#endif
  14294. +
  14295. #define ATOMIC64_INIT(val) { (val) }
  14296. #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
  14297. @@ -37,21 +45,31 @@ typedef struct {
  14298. ATOMIC64_DECL_ONE(sym##_386)
  14299. ATOMIC64_DECL_ONE(add_386);
  14300. +ATOMIC64_DECL_ONE(add_unchecked_386);
  14301. ATOMIC64_DECL_ONE(sub_386);
  14302. +ATOMIC64_DECL_ONE(sub_unchecked_386);
  14303. ATOMIC64_DECL_ONE(inc_386);
  14304. +ATOMIC64_DECL_ONE(inc_unchecked_386);
  14305. ATOMIC64_DECL_ONE(dec_386);
  14306. +ATOMIC64_DECL_ONE(dec_unchecked_386);
  14307. #endif
  14308. #define alternative_atomic64(f, out, in...) \
  14309. __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
  14310. ATOMIC64_DECL(read);
  14311. +ATOMIC64_DECL(read_unchecked);
  14312. ATOMIC64_DECL(set);
  14313. +ATOMIC64_DECL(set_unchecked);
  14314. ATOMIC64_DECL(xchg);
  14315. ATOMIC64_DECL(add_return);
  14316. +ATOMIC64_DECL(add_return_unchecked);
  14317. ATOMIC64_DECL(sub_return);
  14318. +ATOMIC64_DECL(sub_return_unchecked);
  14319. ATOMIC64_DECL(inc_return);
  14320. +ATOMIC64_DECL(inc_return_unchecked);
  14321. ATOMIC64_DECL(dec_return);
  14322. +ATOMIC64_DECL(dec_return_unchecked);
  14323. ATOMIC64_DECL(dec_if_positive);
  14324. ATOMIC64_DECL(inc_not_zero);
  14325. ATOMIC64_DECL(add_unless);
  14326. @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
  14327. }
  14328. /**
  14329. + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
  14330. + * @p: pointer to type atomic64_unchecked_t
  14331. + * @o: expected value
  14332. + * @n: new value
  14333. + *
  14334. + * Atomically sets @v to @n if it was equal to @o and returns
  14335. + * the old value.
  14336. + */
  14337. +
  14338. +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
  14339. +{
  14340. + return cmpxchg64(&v->counter, o, n);
  14341. +}
  14342. +
  14343. +/**
  14344. * atomic64_xchg - xchg atomic64 variable
  14345. * @v: pointer to type atomic64_t
  14346. * @n: value to assign
  14347. @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
  14348. }
  14349. /**
  14350. + * atomic64_set_unchecked - set atomic64 variable
  14351. + * @v: pointer to type atomic64_unchecked_t
  14352. + * @n: value to assign
  14353. + *
  14354. + * Atomically sets the value of @v to @n.
  14355. + */
  14356. +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
  14357. +{
  14358. + unsigned high = (unsigned)(i >> 32);
  14359. + unsigned low = (unsigned)i;
  14360. + alternative_atomic64(set, /* no output */,
  14361. + "S" (v), "b" (low), "c" (high)
  14362. + : "eax", "edx", "memory");
  14363. +}
  14364. +
  14365. +/**
  14366. * atomic64_read - read atomic64 variable
  14367. * @v: pointer to type atomic64_t
  14368. *
  14369. @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
  14370. }
  14371. /**
  14372. + * atomic64_read_unchecked - read atomic64 variable
  14373. + * @v: pointer to type atomic64_unchecked_t
  14374. + *
  14375. + * Atomically reads the value of @v and returns it.
  14376. + */
  14377. +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
  14378. +{
  14379. + long long r;
  14380. + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
  14381. + return r;
  14382. + }
  14383. +
  14384. +/**
  14385. * atomic64_add_return - add and return
  14386. * @i: integer value to add
  14387. * @v: pointer to type atomic64_t
  14388. @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
  14389. return i;
  14390. }
  14391. +/**
  14392. + * atomic64_add_return_unchecked - add and return
  14393. + * @i: integer value to add
  14394. + * @v: pointer to type atomic64_unchecked_t
  14395. + *
  14396. + * Atomically adds @i to @v and returns @i + *@v
  14397. + */
  14398. +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
  14399. +{
  14400. + alternative_atomic64(add_return_unchecked,
  14401. + ASM_OUTPUT2("+A" (i), "+c" (v)),
  14402. + ASM_NO_INPUT_CLOBBER("memory"));
  14403. + return i;
  14404. +}
  14405. +
  14406. /*
  14407. * Other variants with different arithmetic operators:
  14408. */
  14409. @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
  14410. return a;
  14411. }
  14412. +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
  14413. +{
  14414. + long long a;
  14415. + alternative_atomic64(inc_return_unchecked, "=&A" (a),
  14416. + "S" (v) : "memory", "ecx");
  14417. + return a;
  14418. +}
  14419. +
  14420. static inline long long atomic64_dec_return(atomic64_t *v)
  14421. {
  14422. long long a;
  14423. @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
  14424. }
  14425. /**
  14426. + * atomic64_add_unchecked - add integer to atomic64 variable
  14427. + * @i: integer value to add
  14428. + * @v: pointer to type atomic64_unchecked_t
  14429. + *
  14430. + * Atomically adds @i to @v.
  14431. + */
  14432. +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
  14433. +{
  14434. + __alternative_atomic64(add_unchecked, add_return_unchecked,
  14435. + ASM_OUTPUT2("+A" (i), "+c" (v)),
  14436. + ASM_NO_INPUT_CLOBBER("memory"));
  14437. + return i;
  14438. +}
  14439. +
  14440. +/**
  14441. * atomic64_sub - subtract the atomic64 variable
  14442. * @i: integer value to subtract
  14443. * @v: pointer to type atomic64_t
  14444. diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
  14445. index 46e9052..ae45136 100644
  14446. --- a/arch/x86/include/asm/atomic64_64.h
  14447. +++ b/arch/x86/include/asm/atomic64_64.h
  14448. @@ -18,7 +18,19 @@
  14449. */
  14450. static inline long atomic64_read(const atomic64_t *v)
  14451. {
  14452. - return (*(volatile long *)&(v)->counter);
  14453. + return (*(volatile const long *)&(v)->counter);
  14454. +}
  14455. +
  14456. +/**
  14457. + * atomic64_read_unchecked - read atomic64 variable
  14458. + * @v: pointer of type atomic64_unchecked_t
  14459. + *
  14460. + * Atomically reads the value of @v.
  14461. + * Doesn't imply a read memory barrier.
  14462. + */
  14463. +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
  14464. +{
  14465. + return (*(volatile const long *)&(v)->counter);
  14466. }
  14467. /**
  14468. @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
  14469. }
  14470. /**
  14471. + * atomic64_set_unchecked - set atomic64 variable
  14472. + * @v: pointer to type atomic64_unchecked_t
  14473. + * @i: required value
  14474. + *
  14475. + * Atomically sets the value of @v to @i.
  14476. + */
  14477. +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
  14478. +{
  14479. + v->counter = i;
  14480. +}
  14481. +
  14482. +/**
  14483. * atomic64_add - add integer to atomic64 variable
  14484. * @i: integer value to add
  14485. * @v: pointer to type atomic64_t
  14486. @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
  14487. */
  14488. static inline void atomic64_add(long i, atomic64_t *v)
  14489. {
  14490. + asm volatile(LOCK_PREFIX "addq %1,%0\n"
  14491. +
  14492. +#ifdef CONFIG_PAX_REFCOUNT
  14493. + "jno 0f\n"
  14494. + LOCK_PREFIX "subq %1,%0\n"
  14495. + "int $4\n0:\n"
  14496. + _ASM_EXTABLE(0b, 0b)
  14497. +#endif
  14498. +
  14499. + : "=m" (v->counter)
  14500. + : "er" (i), "m" (v->counter));
  14501. +}
  14502. +
  14503. +/**
  14504. + * atomic64_add_unchecked - add integer to atomic64 variable
  14505. + * @i: integer value to add
  14506. + * @v: pointer to type atomic64_unchecked_t
  14507. + *
  14508. + * Atomically adds @i to @v.
  14509. + */
  14510. +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
  14511. +{
  14512. asm volatile(LOCK_PREFIX "addq %1,%0"
  14513. : "=m" (v->counter)
  14514. : "er" (i), "m" (v->counter));
  14515. @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
  14516. */
  14517. static inline void atomic64_sub(long i, atomic64_t *v)
  14518. {
  14519. - asm volatile(LOCK_PREFIX "subq %1,%0"
  14520. + asm volatile(LOCK_PREFIX "subq %1,%0\n"
  14521. +
  14522. +#ifdef CONFIG_PAX_REFCOUNT
  14523. + "jno 0f\n"
  14524. + LOCK_PREFIX "addq %1,%0\n"
  14525. + "int $4\n0:\n"
  14526. + _ASM_EXTABLE(0b, 0b)
  14527. +#endif
  14528. +
  14529. + : "=m" (v->counter)
  14530. + : "er" (i), "m" (v->counter));
  14531. +}
  14532. +
  14533. +/**
  14534. + * atomic64_sub_unchecked - subtract the atomic64 variable
  14535. + * @i: integer value to subtract
  14536. + * @v: pointer to type atomic64_unchecked_t
  14537. + *
  14538. + * Atomically subtracts @i from @v.
  14539. + */
  14540. +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
  14541. +{
  14542. + asm volatile(LOCK_PREFIX "subq %1,%0\n"
  14543. : "=m" (v->counter)
  14544. : "er" (i), "m" (v->counter));
  14545. }
  14546. @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
  14547. */
  14548. static inline int atomic64_sub_and_test(long i, atomic64_t *v)
  14549. {
  14550. - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
  14551. + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
  14552. }
  14553. /**
  14554. @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
  14555. */
  14556. static inline void atomic64_inc(atomic64_t *v)
  14557. {
  14558. + asm volatile(LOCK_PREFIX "incq %0\n"
  14559. +
  14560. +#ifdef CONFIG_PAX_REFCOUNT
  14561. + "jno 0f\n"
  14562. + LOCK_PREFIX "decq %0\n"
  14563. + "int $4\n0:\n"
  14564. + _ASM_EXTABLE(0b, 0b)
  14565. +#endif
  14566. +
  14567. + : "=m" (v->counter)
  14568. + : "m" (v->counter));
  14569. +}
  14570. +
  14571. +/**
  14572. + * atomic64_inc_unchecked - increment atomic64 variable
  14573. + * @v: pointer to type atomic64_unchecked_t
  14574. + *
  14575. + * Atomically increments @v by 1.
  14576. + */
  14577. +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
  14578. +{
  14579. asm volatile(LOCK_PREFIX "incq %0"
  14580. : "=m" (v->counter)
  14581. : "m" (v->counter));
  14582. @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
  14583. */
  14584. static inline void atomic64_dec(atomic64_t *v)
  14585. {
  14586. - asm volatile(LOCK_PREFIX "decq %0"
  14587. + asm volatile(LOCK_PREFIX "decq %0\n"
  14588. +
  14589. +#ifdef CONFIG_PAX_REFCOUNT
  14590. + "jno 0f\n"
  14591. + LOCK_PREFIX "incq %0\n"
  14592. + "int $4\n0:\n"
  14593. + _ASM_EXTABLE(0b, 0b)
  14594. +#endif
  14595. +
  14596. + : "=m" (v->counter)
  14597. + : "m" (v->counter));
  14598. +}
  14599. +
  14600. +/**
  14601. + * atomic64_dec_unchecked - decrement atomic64 variable
  14602. + * @v: pointer to type atomic64_t
  14603. + *
  14604. + * Atomically decrements @v by 1.
  14605. + */
  14606. +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
  14607. +{
  14608. + asm volatile(LOCK_PREFIX "decq %0\n"
  14609. : "=m" (v->counter)
  14610. : "m" (v->counter));
  14611. }
  14612. @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
  14613. */
  14614. static inline int atomic64_dec_and_test(atomic64_t *v)
  14615. {
  14616. - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
  14617. + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
  14618. }
  14619. /**
  14620. @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
  14621. */
  14622. static inline int atomic64_inc_and_test(atomic64_t *v)
  14623. {
  14624. - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
  14625. + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
  14626. }
  14627. /**
  14628. @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
  14629. */
  14630. static inline int atomic64_add_negative(long i, atomic64_t *v)
  14631. {
  14632. - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
  14633. + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
  14634. }
  14635. /**
  14636. @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
  14637. */
  14638. static inline long atomic64_add_return(long i, atomic64_t *v)
  14639. {
  14640. + return i + xadd_check_overflow(&v->counter, i);
  14641. +}
  14642. +
  14643. +/**
  14644. + * atomic64_add_return_unchecked - add and return
  14645. + * @i: integer value to add
  14646. + * @v: pointer to type atomic64_unchecked_t
  14647. + *
  14648. + * Atomically adds @i to @v and returns @i + @v
  14649. + */
  14650. +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
  14651. +{
  14652. return i + xadd(&v->counter, i);
  14653. }
  14654. @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
  14655. }
  14656. #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
  14657. +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
  14658. +{
  14659. + return atomic64_add_return_unchecked(1, v);
  14660. +}
  14661. #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
  14662. static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
  14663. @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
  14664. return cmpxchg(&v->counter, old, new);
  14665. }
  14666. +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
  14667. +{
  14668. + return cmpxchg(&v->counter, old, new);
  14669. +}
  14670. +
  14671. static inline long atomic64_xchg(atomic64_t *v, long new)
  14672. {
  14673. return xchg(&v->counter, new);
  14674. @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
  14675. */
  14676. static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
  14677. {
  14678. - long c, old;
  14679. + long c, old, new;
  14680. c = atomic64_read(v);
  14681. for (;;) {
  14682. - if (unlikely(c == (u)))
  14683. + if (unlikely(c == u))
  14684. break;
  14685. - old = atomic64_cmpxchg((v), c, c + (a));
  14686. +
  14687. + asm volatile("add %2,%0\n"
  14688. +
  14689. +#ifdef CONFIG_PAX_REFCOUNT
  14690. + "jno 0f\n"
  14691. + "sub %2,%0\n"
  14692. + "int $4\n0:\n"
  14693. + _ASM_EXTABLE(0b, 0b)
  14694. +#endif
  14695. +
  14696. + : "=r" (new)
  14697. + : "0" (c), "ir" (a));
  14698. +
  14699. + old = atomic64_cmpxchg(v, c, new);
  14700. if (likely(old == c))
  14701. break;
  14702. c = old;
  14703. }
  14704. - return c != (u);
  14705. + return c != u;
  14706. }
  14707. #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
  14708. diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
  14709. index 9fc1af7..fc71228 100644
  14710. --- a/arch/x86/include/asm/bitops.h
  14711. +++ b/arch/x86/include/asm/bitops.h
  14712. @@ -49,7 +49,7 @@
  14713. * a mask operation on a byte.
  14714. */
  14715. #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
  14716. -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
  14717. +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
  14718. #define CONST_MASK(nr) (1 << ((nr) & 7))
  14719. /**
  14720. @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
  14721. */
  14722. static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
  14723. {
  14724. - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
  14725. + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
  14726. }
  14727. /**
  14728. @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
  14729. */
  14730. static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
  14731. {
  14732. - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
  14733. + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
  14734. }
  14735. /**
  14736. @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
  14737. */
  14738. static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
  14739. {
  14740. - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
  14741. + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
  14742. }
  14743. static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
  14744. @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
  14745. *
  14746. * Undefined if no bit exists, so code should check against 0 first.
  14747. */
  14748. -static inline unsigned long __ffs(unsigned long word)
  14749. +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
  14750. {
  14751. asm("rep; bsf %1,%0"
  14752. : "=r" (word)
  14753. @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
  14754. *
  14755. * Undefined if no zero exists, so code should check against ~0UL first.
  14756. */
  14757. -static inline unsigned long ffz(unsigned long word)
  14758. +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
  14759. {
  14760. asm("rep; bsf %1,%0"
  14761. : "=r" (word)
  14762. @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
  14763. *
  14764. * Undefined if no set bit exists, so code should check against 0 first.
  14765. */
  14766. -static inline unsigned long __fls(unsigned long word)
  14767. +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
  14768. {
  14769. asm("bsr %1,%0"
  14770. : "=r" (word)
  14771. @@ -436,7 +436,7 @@ static inline int ffs(int x)
  14772. * set bit if value is nonzero. The last (most significant) bit is
  14773. * at position 32.
  14774. */
  14775. -static inline int fls(int x)
  14776. +static inline int __intentional_overflow(-1) fls(int x)
  14777. {
  14778. int r;
  14779. @@ -478,7 +478,7 @@ static inline int fls(int x)
  14780. * at position 64.
  14781. */
  14782. #ifdef CONFIG_X86_64
  14783. -static __always_inline int fls64(__u64 x)
  14784. +static __always_inline long fls64(__u64 x)
  14785. {
  14786. int bitpos = -1;
  14787. /*
  14788. diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
  14789. index 4fa687a..60f2d39 100644
  14790. --- a/arch/x86/include/asm/boot.h
  14791. +++ b/arch/x86/include/asm/boot.h
  14792. @@ -6,10 +6,15 @@
  14793. #include <uapi/asm/boot.h>
  14794. /* Physical address where kernel should be loaded. */
  14795. -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
  14796. +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
  14797. + (CONFIG_PHYSICAL_ALIGN - 1)) \
  14798. & ~(CONFIG_PHYSICAL_ALIGN - 1))
  14799. +#ifndef __ASSEMBLY__
  14800. +extern unsigned char __LOAD_PHYSICAL_ADDR[];
  14801. +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
  14802. +#endif
  14803. +
  14804. /* Minimum kernel alignment, as a power of two */
  14805. #ifdef CONFIG_X86_64
  14806. #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
  14807. diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
  14808. index 48f99f1..d78ebf9 100644
  14809. --- a/arch/x86/include/asm/cache.h
  14810. +++ b/arch/x86/include/asm/cache.h
  14811. @@ -5,12 +5,13 @@
  14812. /* L1 cache line size */
  14813. #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
  14814. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  14815. +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
  14816. #define __read_mostly __attribute__((__section__(".data..read_mostly")))
  14817. +#define __read_only __attribute__((__section__(".data..read_only")))
  14818. #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
  14819. -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
  14820. +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
  14821. #ifdef CONFIG_X86_VSMP
  14822. #ifdef CONFIG_SMP
  14823. diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
  14824. index 9863ee3..4a1f8e1 100644
  14825. --- a/arch/x86/include/asm/cacheflush.h
  14826. +++ b/arch/x86/include/asm/cacheflush.h
  14827. @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
  14828. unsigned long pg_flags = pg->flags & _PGMT_MASK;
  14829. if (pg_flags == _PGMT_DEFAULT)
  14830. - return -1;
  14831. + return ~0UL;
  14832. else if (pg_flags == _PGMT_WC)
  14833. return _PAGE_CACHE_WC;
  14834. else if (pg_flags == _PGMT_UC_MINUS)
  14835. diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
  14836. index cb4c73b..c473c29 100644
  14837. --- a/arch/x86/include/asm/calling.h
  14838. +++ b/arch/x86/include/asm/calling.h
  14839. @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
  14840. #define RSP 152
  14841. #define SS 160
  14842. -#define ARGOFFSET R11
  14843. -#define SWFRAME ORIG_RAX
  14844. +#define ARGOFFSET R15
  14845. .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
  14846. - subq $9*8+\addskip, %rsp
  14847. - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
  14848. - movq_cfi rdi, 8*8
  14849. - movq_cfi rsi, 7*8
  14850. - movq_cfi rdx, 6*8
  14851. + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
  14852. + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
  14853. + movq_cfi rdi, RDI
  14854. + movq_cfi rsi, RSI
  14855. + movq_cfi rdx, RDX
  14856. .if \save_rcx
  14857. - movq_cfi rcx, 5*8
  14858. + movq_cfi rcx, RCX
  14859. .endif
  14860. - movq_cfi rax, 4*8
  14861. + movq_cfi rax, RAX
  14862. .if \save_r891011
  14863. - movq_cfi r8, 3*8
  14864. - movq_cfi r9, 2*8
  14865. - movq_cfi r10, 1*8
  14866. - movq_cfi r11, 0*8
  14867. + movq_cfi r8, R8
  14868. + movq_cfi r9, R9
  14869. + movq_cfi r10, R10
  14870. + movq_cfi r11, R11
  14871. .endif
  14872. +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
  14873. + movq_cfi r12, R12
  14874. +#endif
  14875. +
  14876. .endm
  14877. -#define ARG_SKIP (9*8)
  14878. +#define ARG_SKIP ORIG_RAX
  14879. .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
  14880. rstor_r8910=1, rstor_rdx=1
  14881. +
  14882. +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
  14883. + movq_cfi_restore R12, r12
  14884. +#endif
  14885. +
  14886. .if \rstor_r11
  14887. - movq_cfi_restore 0*8, r11
  14888. + movq_cfi_restore R11, r11
  14889. .endif
  14890. .if \rstor_r8910
  14891. - movq_cfi_restore 1*8, r10
  14892. - movq_cfi_restore 2*8, r9
  14893. - movq_cfi_restore 3*8, r8
  14894. + movq_cfi_restore R10, r10
  14895. + movq_cfi_restore R9, r9
  14896. + movq_cfi_restore R8, r8
  14897. .endif
  14898. .if \rstor_rax
  14899. - movq_cfi_restore 4*8, rax
  14900. + movq_cfi_restore RAX, rax
  14901. .endif
  14902. .if \rstor_rcx
  14903. - movq_cfi_restore 5*8, rcx
  14904. + movq_cfi_restore RCX, rcx
  14905. .endif
  14906. .if \rstor_rdx
  14907. - movq_cfi_restore 6*8, rdx
  14908. + movq_cfi_restore RDX, rdx
  14909. .endif
  14910. - movq_cfi_restore 7*8, rsi
  14911. - movq_cfi_restore 8*8, rdi
  14912. + movq_cfi_restore RSI, rsi
  14913. + movq_cfi_restore RDI, rdi
  14914. - .if ARG_SKIP+\addskip > 0
  14915. - addq $ARG_SKIP+\addskip, %rsp
  14916. - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
  14917. + .if ORIG_RAX+\addskip > 0
  14918. + addq $ORIG_RAX+\addskip, %rsp
  14919. + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
  14920. .endif
  14921. .endm
  14922. - .macro LOAD_ARGS offset, skiprax=0
  14923. - movq \offset(%rsp), %r11
  14924. - movq \offset+8(%rsp), %r10
  14925. - movq \offset+16(%rsp), %r9
  14926. - movq \offset+24(%rsp), %r8
  14927. - movq \offset+40(%rsp), %rcx
  14928. - movq \offset+48(%rsp), %rdx
  14929. - movq \offset+56(%rsp), %rsi
  14930. - movq \offset+64(%rsp), %rdi
  14931. + .macro LOAD_ARGS skiprax=0
  14932. + movq R11(%rsp), %r11
  14933. + movq R10(%rsp), %r10
  14934. + movq R9(%rsp), %r9
  14935. + movq R8(%rsp), %r8
  14936. + movq RCX(%rsp), %rcx
  14937. + movq RDX(%rsp), %rdx
  14938. + movq RSI(%rsp), %rsi
  14939. + movq RDI(%rsp), %rdi
  14940. .if \skiprax
  14941. .else
  14942. - movq \offset+72(%rsp), %rax
  14943. + movq RAX(%rsp), %rax
  14944. .endif
  14945. .endm
  14946. -#define REST_SKIP (6*8)
  14947. -
  14948. .macro SAVE_REST
  14949. - subq $REST_SKIP, %rsp
  14950. - CFI_ADJUST_CFA_OFFSET REST_SKIP
  14951. - movq_cfi rbx, 5*8
  14952. - movq_cfi rbp, 4*8
  14953. - movq_cfi r12, 3*8
  14954. - movq_cfi r13, 2*8
  14955. - movq_cfi r14, 1*8
  14956. - movq_cfi r15, 0*8
  14957. + movq_cfi rbx, RBX
  14958. + movq_cfi rbp, RBP
  14959. +
  14960. +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
  14961. + movq_cfi r12, R12
  14962. +#endif
  14963. +
  14964. + movq_cfi r13, R13
  14965. + movq_cfi r14, R14
  14966. + movq_cfi r15, R15
  14967. .endm
  14968. .macro RESTORE_REST
  14969. - movq_cfi_restore 0*8, r15
  14970. - movq_cfi_restore 1*8, r14
  14971. - movq_cfi_restore 2*8, r13
  14972. - movq_cfi_restore 3*8, r12
  14973. - movq_cfi_restore 4*8, rbp
  14974. - movq_cfi_restore 5*8, rbx
  14975. - addq $REST_SKIP, %rsp
  14976. - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
  14977. + movq_cfi_restore R15, r15
  14978. + movq_cfi_restore R14, r14
  14979. + movq_cfi_restore R13, r13
  14980. +
  14981. +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
  14982. + movq_cfi_restore R12, r12
  14983. +#endif
  14984. +
  14985. + movq_cfi_restore RBP, rbp
  14986. + movq_cfi_restore RBX, rbx
  14987. .endm
  14988. .macro SAVE_ALL
  14989. diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
  14990. index f50de69..2b0a458 100644
  14991. --- a/arch/x86/include/asm/checksum_32.h
  14992. +++ b/arch/x86/include/asm/checksum_32.h
  14993. @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
  14994. int len, __wsum sum,
  14995. int *src_err_ptr, int *dst_err_ptr);
  14996. +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
  14997. + int len, __wsum sum,
  14998. + int *src_err_ptr, int *dst_err_ptr);
  14999. +
  15000. +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
  15001. + int len, __wsum sum,
  15002. + int *src_err_ptr, int *dst_err_ptr);
  15003. +
  15004. /*
  15005. * Note: when you get a NULL pointer exception here this means someone
  15006. * passed in an incorrect kernel address to one of these functions.
  15007. @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
  15008. might_sleep();
  15009. stac();
  15010. - ret = csum_partial_copy_generic((__force void *)src, dst,
  15011. + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
  15012. len, sum, err_ptr, NULL);
  15013. clac();
  15014. @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
  15015. might_sleep();
  15016. if (access_ok(VERIFY_WRITE, dst, len)) {
  15017. stac();
  15018. - ret = csum_partial_copy_generic(src, (__force void *)dst,
  15019. + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
  15020. len, sum, NULL, err_ptr);
  15021. clac();
  15022. return ret;
  15023. diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
  15024. index d47786a..2d8883e 100644
  15025. --- a/arch/x86/include/asm/cmpxchg.h
  15026. +++ b/arch/x86/include/asm/cmpxchg.h
  15027. @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
  15028. __compiletime_error("Bad argument size for cmpxchg");
  15029. extern void __xadd_wrong_size(void)
  15030. __compiletime_error("Bad argument size for xadd");
  15031. +extern void __xadd_check_overflow_wrong_size(void)
  15032. + __compiletime_error("Bad argument size for xadd_check_overflow");
  15033. extern void __add_wrong_size(void)
  15034. __compiletime_error("Bad argument size for add");
  15035. +extern void __add_check_overflow_wrong_size(void)
  15036. + __compiletime_error("Bad argument size for add_check_overflow");
  15037. /*
  15038. * Constants for operation sizes. On 32-bit, the 64-bit size it set to
  15039. @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
  15040. __ret; \
  15041. })
  15042. +#ifdef CONFIG_PAX_REFCOUNT
  15043. +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
  15044. + ({ \
  15045. + __typeof__ (*(ptr)) __ret = (arg); \
  15046. + switch (sizeof(*(ptr))) { \
  15047. + case __X86_CASE_L: \
  15048. + asm volatile (lock #op "l %0, %1\n" \
  15049. + "jno 0f\n" \
  15050. + "mov %0,%1\n" \
  15051. + "int $4\n0:\n" \
  15052. + _ASM_EXTABLE(0b, 0b) \
  15053. + : "+r" (__ret), "+m" (*(ptr)) \
  15054. + : : "memory", "cc"); \
  15055. + break; \
  15056. + case __X86_CASE_Q: \
  15057. + asm volatile (lock #op "q %q0, %1\n" \
  15058. + "jno 0f\n" \
  15059. + "mov %0,%1\n" \
  15060. + "int $4\n0:\n" \
  15061. + _ASM_EXTABLE(0b, 0b) \
  15062. + : "+r" (__ret), "+m" (*(ptr)) \
  15063. + : : "memory", "cc"); \
  15064. + break; \
  15065. + default: \
  15066. + __ ## op ## _check_overflow_wrong_size(); \
  15067. + } \
  15068. + __ret; \
  15069. + })
  15070. +#else
  15071. +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
  15072. +#endif
  15073. +
  15074. /*
  15075. * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
  15076. * Since this is generally used to protect other memory information, we
  15077. @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
  15078. #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
  15079. #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
  15080. +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
  15081. +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
  15082. +
  15083. #define __add(ptr, inc, lock) \
  15084. ({ \
  15085. __typeof__ (*(ptr)) __ret = (inc); \
  15086. diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
  15087. index 59c6c40..5e0b22c 100644
  15088. --- a/arch/x86/include/asm/compat.h
  15089. +++ b/arch/x86/include/asm/compat.h
  15090. @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
  15091. typedef u32 compat_uint_t;
  15092. typedef u32 compat_ulong_t;
  15093. typedef u64 __attribute__((aligned(4))) compat_u64;
  15094. -typedef u32 compat_uptr_t;
  15095. +typedef u32 __user compat_uptr_t;
  15096. struct compat_timespec {
  15097. compat_time_t tv_sec;
  15098. diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
  15099. index 5f12968..a383517 100644
  15100. --- a/arch/x86/include/asm/cpufeature.h
  15101. +++ b/arch/x86/include/asm/cpufeature.h
  15102. @@ -203,7 +203,7 @@
  15103. #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
  15104. #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
  15105. #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
  15106. -
  15107. +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
  15108. /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
  15109. #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
  15110. @@ -211,7 +211,7 @@
  15111. #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
  15112. #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
  15113. #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
  15114. -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
  15115. +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
  15116. #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
  15117. #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
  15118. #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
  15119. @@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
  15120. #undef cpu_has_centaur_mcr
  15121. #define cpu_has_centaur_mcr 0
  15122. +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
  15123. #endif /* CONFIG_X86_64 */
  15124. #if __GNUC__ >= 4
  15125. @@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
  15126. #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
  15127. t_warn:
  15128. - warn_pre_alternatives();
  15129. + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
  15130. + warn_pre_alternatives();
  15131. return false;
  15132. #endif
  15133. @@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
  15134. ".section .discard,\"aw\",@progbits\n"
  15135. " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
  15136. ".previous\n"
  15137. - ".section .altinstr_replacement,\"ax\"\n"
  15138. + ".section .altinstr_replacement,\"a\"\n"
  15139. "3: movb $1,%0\n"
  15140. "4:\n"
  15141. ".previous\n"
  15142. @@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
  15143. " .byte 2b - 1b\n" /* src len */
  15144. " .byte 4f - 3f\n" /* repl len */
  15145. ".previous\n"
  15146. - ".section .altinstr_replacement,\"ax\"\n"
  15147. + ".section .altinstr_replacement,\"a\"\n"
  15148. "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
  15149. "4:\n"
  15150. ".previous\n"
  15151. @@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
  15152. ".section .discard,\"aw\",@progbits\n"
  15153. " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
  15154. ".previous\n"
  15155. - ".section .altinstr_replacement,\"ax\"\n"
  15156. + ".section .altinstr_replacement,\"a\"\n"
  15157. "3: movb $0,%0\n"
  15158. "4:\n"
  15159. ".previous\n"
  15160. @@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
  15161. ".section .discard,\"aw\",@progbits\n"
  15162. " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
  15163. ".previous\n"
  15164. - ".section .altinstr_replacement,\"ax\"\n"
  15165. + ".section .altinstr_replacement,\"a\"\n"
  15166. "5: movb $1,%0\n"
  15167. "6:\n"
  15168. ".previous\n"
  15169. diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
  15170. index 50d033a..37deb26 100644
  15171. --- a/arch/x86/include/asm/desc.h
  15172. +++ b/arch/x86/include/asm/desc.h
  15173. @@ -4,6 +4,7 @@
  15174. #include <asm/desc_defs.h>
  15175. #include <asm/ldt.h>
  15176. #include <asm/mmu.h>
  15177. +#include <asm/pgtable.h>
  15178. #include <linux/smp.h>
  15179. #include <linux/percpu.h>
  15180. @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
  15181. desc->type = (info->read_exec_only ^ 1) << 1;
  15182. desc->type |= info->contents << 2;
  15183. + desc->type |= info->seg_not_present ^ 1;
  15184. desc->s = 1;
  15185. desc->dpl = 0x3;
  15186. @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
  15187. }
  15188. extern struct desc_ptr idt_descr;
  15189. -extern gate_desc idt_table[];
  15190. -extern struct desc_ptr debug_idt_descr;
  15191. -extern gate_desc debug_idt_table[];
  15192. -
  15193. -struct gdt_page {
  15194. - struct desc_struct gdt[GDT_ENTRIES];
  15195. -} __attribute__((aligned(PAGE_SIZE)));
  15196. -
  15197. -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
  15198. +extern gate_desc idt_table[IDT_ENTRIES];
  15199. +extern const struct desc_ptr debug_idt_descr;
  15200. +extern gate_desc debug_idt_table[IDT_ENTRIES];
  15201. +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
  15202. static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
  15203. {
  15204. - return per_cpu(gdt_page, cpu).gdt;
  15205. + return cpu_gdt_table[cpu];
  15206. }
  15207. #ifdef CONFIG_X86_64
  15208. @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
  15209. unsigned long base, unsigned dpl, unsigned flags,
  15210. unsigned short seg)
  15211. {
  15212. - gate->a = (seg << 16) | (base & 0xffff);
  15213. - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
  15214. + gate->gate.offset_low = base;
  15215. + gate->gate.seg = seg;
  15216. + gate->gate.reserved = 0;
  15217. + gate->gate.type = type;
  15218. + gate->gate.s = 0;
  15219. + gate->gate.dpl = dpl;
  15220. + gate->gate.p = 1;
  15221. + gate->gate.offset_high = base >> 16;
  15222. }
  15223. #endif
  15224. @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
  15225. static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
  15226. {
  15227. + pax_open_kernel();
  15228. memcpy(&idt[entry], gate, sizeof(*gate));
  15229. + pax_close_kernel();
  15230. }
  15231. static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
  15232. {
  15233. + pax_open_kernel();
  15234. memcpy(&ldt[entry], desc, 8);
  15235. + pax_close_kernel();
  15236. }
  15237. static inline void
  15238. @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
  15239. default: size = sizeof(*gdt); break;
  15240. }
  15241. + pax_open_kernel();
  15242. memcpy(&gdt[entry], desc, size);
  15243. + pax_close_kernel();
  15244. }
  15245. static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
  15246. @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
  15247. static inline void native_load_tr_desc(void)
  15248. {
  15249. + pax_open_kernel();
  15250. asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
  15251. + pax_close_kernel();
  15252. }
  15253. static inline void native_load_gdt(const struct desc_ptr *dtr)
  15254. @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
  15255. struct desc_struct *gdt = get_cpu_gdt_table(cpu);
  15256. unsigned int i;
  15257. + pax_open_kernel();
  15258. for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
  15259. gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
  15260. + pax_close_kernel();
  15261. }
  15262. #define _LDT_empty(info) \
  15263. @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
  15264. preempt_enable();
  15265. }
  15266. -static inline unsigned long get_desc_base(const struct desc_struct *desc)
  15267. +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
  15268. {
  15269. return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
  15270. }
  15271. @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
  15272. }
  15273. #ifdef CONFIG_X86_64
  15274. -static inline void set_nmi_gate(int gate, void *addr)
  15275. +static inline void set_nmi_gate(int gate, const void *addr)
  15276. {
  15277. gate_desc s;
  15278. @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
  15279. #endif
  15280. #ifdef CONFIG_TRACING
  15281. -extern struct desc_ptr trace_idt_descr;
  15282. -extern gate_desc trace_idt_table[];
  15283. +extern const struct desc_ptr trace_idt_descr;
  15284. +extern gate_desc trace_idt_table[IDT_ENTRIES];
  15285. static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
  15286. {
  15287. write_idt_entry(trace_idt_table, entry, gate);
  15288. }
  15289. -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
  15290. +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
  15291. unsigned dpl, unsigned ist, unsigned seg)
  15292. {
  15293. gate_desc s;
  15294. @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
  15295. #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
  15296. #endif
  15297. -static inline void _set_gate(int gate, unsigned type, void *addr,
  15298. +static inline void _set_gate(int gate, unsigned type, const void *addr,
  15299. unsigned dpl, unsigned ist, unsigned seg)
  15300. {
  15301. gate_desc s;
  15302. @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
  15303. #define set_intr_gate(n, addr) \
  15304. do { \
  15305. BUG_ON((unsigned)n > 0xFF); \
  15306. - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
  15307. + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
  15308. __KERNEL_CS); \
  15309. - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
  15310. + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
  15311. 0, 0, __KERNEL_CS); \
  15312. } while (0)
  15313. @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
  15314. /*
  15315. * This routine sets up an interrupt gate at directory privilege level 3.
  15316. */
  15317. -static inline void set_system_intr_gate(unsigned int n, void *addr)
  15318. +static inline void set_system_intr_gate(unsigned int n, const void *addr)
  15319. {
  15320. BUG_ON((unsigned)n > 0xFF);
  15321. _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
  15322. }
  15323. -static inline void set_system_trap_gate(unsigned int n, void *addr)
  15324. +static inline void set_system_trap_gate(unsigned int n, const void *addr)
  15325. {
  15326. BUG_ON((unsigned)n > 0xFF);
  15327. _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
  15328. }
  15329. -static inline void set_trap_gate(unsigned int n, void *addr)
  15330. +static inline void set_trap_gate(unsigned int n, const void *addr)
  15331. {
  15332. BUG_ON((unsigned)n > 0xFF);
  15333. _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
  15334. @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
  15335. static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
  15336. {
  15337. BUG_ON((unsigned)n > 0xFF);
  15338. - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
  15339. + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
  15340. }
  15341. -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
  15342. +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
  15343. {
  15344. BUG_ON((unsigned)n > 0xFF);
  15345. _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
  15346. }
  15347. -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
  15348. +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
  15349. {
  15350. BUG_ON((unsigned)n > 0xFF);
  15351. _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
  15352. @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
  15353. else
  15354. load_idt((const struct desc_ptr *)&idt_descr);
  15355. }
  15356. +
  15357. +#ifdef CONFIG_X86_32
  15358. +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
  15359. +{
  15360. + struct desc_struct d;
  15361. +
  15362. + if (likely(limit))
  15363. + limit = (limit - 1UL) >> PAGE_SHIFT;
  15364. + pack_descriptor(&d, base, limit, 0xFB, 0xC);
  15365. + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
  15366. +}
  15367. +#endif
  15368. +
  15369. #endif /* _ASM_X86_DESC_H */
  15370. diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
  15371. index 278441f..b95a174 100644
  15372. --- a/arch/x86/include/asm/desc_defs.h
  15373. +++ b/arch/x86/include/asm/desc_defs.h
  15374. @@ -31,6 +31,12 @@ struct desc_struct {
  15375. unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
  15376. unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
  15377. };
  15378. + struct {
  15379. + u16 offset_low;
  15380. + u16 seg;
  15381. + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
  15382. + unsigned offset_high: 16;
  15383. + } gate;
  15384. };
  15385. } __attribute__((packed));
  15386. diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
  15387. index ced283a..ffe04cc 100644
  15388. --- a/arch/x86/include/asm/div64.h
  15389. +++ b/arch/x86/include/asm/div64.h
  15390. @@ -39,7 +39,7 @@
  15391. __mod; \
  15392. })
  15393. -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  15394. +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  15395. {
  15396. union {
  15397. u64 v64;
  15398. diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
  15399. index 9c999c1..3860cb8 100644
  15400. --- a/arch/x86/include/asm/elf.h
  15401. +++ b/arch/x86/include/asm/elf.h
  15402. @@ -243,7 +243,25 @@ extern int force_personality32;
  15403. the loader. We need to make sure that it is out of the way of the program
  15404. that it will "exec", and that there is sufficient room for the brk. */
  15405. +#ifdef CONFIG_PAX_SEGMEXEC
  15406. +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
  15407. +#else
  15408. #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
  15409. +#endif
  15410. +
  15411. +#ifdef CONFIG_PAX_ASLR
  15412. +#ifdef CONFIG_X86_32
  15413. +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
  15414. +
  15415. +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
  15416. +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
  15417. +#else
  15418. +#define PAX_ELF_ET_DYN_BASE 0x400000UL
  15419. +
  15420. +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
  15421. +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
  15422. +#endif
  15423. +#endif
  15424. /* This yields a mask that user programs can use to figure out what
  15425. instruction set this CPU supports. This could be done in user space,
  15426. @@ -296,16 +314,12 @@ do { \
  15427. #define ARCH_DLINFO \
  15428. do { \
  15429. - if (vdso_enabled) \
  15430. - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  15431. - (unsigned long)current->mm->context.vdso); \
  15432. + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
  15433. } while (0)
  15434. #define ARCH_DLINFO_X32 \
  15435. do { \
  15436. - if (vdso_enabled) \
  15437. - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  15438. - (unsigned long)current->mm->context.vdso); \
  15439. + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
  15440. } while (0)
  15441. #define AT_SYSINFO 32
  15442. @@ -320,7 +334,7 @@ else \
  15443. #endif /* !CONFIG_X86_32 */
  15444. -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
  15445. +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
  15446. #define VDSO_ENTRY \
  15447. ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
  15448. @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
  15449. extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
  15450. #define compat_arch_setup_additional_pages syscall32_setup_pages
  15451. -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
  15452. -#define arch_randomize_brk arch_randomize_brk
  15453. -
  15454. /*
  15455. * True on X86_32 or when emulating IA32 on X86_64
  15456. */
  15457. diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
  15458. index 77a99ac..39ff7f5 100644
  15459. --- a/arch/x86/include/asm/emergency-restart.h
  15460. +++ b/arch/x86/include/asm/emergency-restart.h
  15461. @@ -1,6 +1,6 @@
  15462. #ifndef _ASM_X86_EMERGENCY_RESTART_H
  15463. #define _ASM_X86_EMERGENCY_RESTART_H
  15464. -extern void machine_emergency_restart(void);
  15465. +extern void machine_emergency_restart(void) __noreturn;
  15466. #endif /* _ASM_X86_EMERGENCY_RESTART_H */
  15467. diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
  15468. index d3d7469..677ef72 100644
  15469. --- a/arch/x86/include/asm/floppy.h
  15470. +++ b/arch/x86/include/asm/floppy.h
  15471. @@ -229,18 +229,18 @@ static struct fd_routine_l {
  15472. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  15473. } fd_routine[] = {
  15474. {
  15475. - request_dma,
  15476. - free_dma,
  15477. - get_dma_residue,
  15478. - dma_mem_alloc,
  15479. - hard_dma_setup
  15480. + ._request_dma = request_dma,
  15481. + ._free_dma = free_dma,
  15482. + ._get_dma_residue = get_dma_residue,
  15483. + ._dma_mem_alloc = dma_mem_alloc,
  15484. + ._dma_setup = hard_dma_setup
  15485. },
  15486. {
  15487. - vdma_request_dma,
  15488. - vdma_nop,
  15489. - vdma_get_dma_residue,
  15490. - vdma_mem_alloc,
  15491. - vdma_dma_setup
  15492. + ._request_dma = vdma_request_dma,
  15493. + ._free_dma = vdma_nop,
  15494. + ._get_dma_residue = vdma_get_dma_residue,
  15495. + ._dma_mem_alloc = vdma_mem_alloc,
  15496. + ._dma_setup = vdma_dma_setup
  15497. }
  15498. };
  15499. diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
  15500. index cea1c76..6c0d79b 100644
  15501. --- a/arch/x86/include/asm/fpu-internal.h
  15502. +++ b/arch/x86/include/asm/fpu-internal.h
  15503. @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
  15504. #define user_insn(insn, output, input...) \
  15505. ({ \
  15506. int err; \
  15507. + pax_open_userland(); \
  15508. asm volatile(ASM_STAC "\n" \
  15509. - "1:" #insn "\n\t" \
  15510. + "1:" \
  15511. + __copyuser_seg \
  15512. + #insn "\n\t" \
  15513. "2: " ASM_CLAC "\n" \
  15514. ".section .fixup,\"ax\"\n" \
  15515. "3: movl $-1,%[err]\n" \
  15516. @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
  15517. _ASM_EXTABLE(1b, 3b) \
  15518. : [err] "=r" (err), output \
  15519. : "0"(0), input); \
  15520. + pax_close_userland(); \
  15521. err; \
  15522. })
  15523. @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
  15524. "fnclex\n\t"
  15525. "emms\n\t"
  15526. "fildl %P[addr]" /* set F?P to defined value */
  15527. - : : [addr] "m" (tsk->thread.fpu.has_fpu));
  15528. + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
  15529. }
  15530. return fpu_restore_checking(&tsk->thread.fpu);
  15531. diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
  15532. index b4c1f54..e290c08 100644
  15533. --- a/arch/x86/include/asm/futex.h
  15534. +++ b/arch/x86/include/asm/futex.h
  15535. @@ -12,6 +12,7 @@
  15536. #include <asm/smap.h>
  15537. #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
  15538. + typecheck(u32 __user *, uaddr); \
  15539. asm volatile("\t" ASM_STAC "\n" \
  15540. "1:\t" insn "\n" \
  15541. "2:\t" ASM_CLAC "\n" \
  15542. @@ -20,15 +21,16 @@
  15543. "\tjmp\t2b\n" \
  15544. "\t.previous\n" \
  15545. _ASM_EXTABLE(1b, 3b) \
  15546. - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
  15547. + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
  15548. : "i" (-EFAULT), "0" (oparg), "1" (0))
  15549. #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
  15550. + typecheck(u32 __user *, uaddr); \
  15551. asm volatile("\t" ASM_STAC "\n" \
  15552. "1:\tmovl %2, %0\n" \
  15553. "\tmovl\t%0, %3\n" \
  15554. "\t" insn "\n" \
  15555. - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
  15556. + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
  15557. "\tjnz\t1b\n" \
  15558. "3:\t" ASM_CLAC "\n" \
  15559. "\t.section .fixup,\"ax\"\n" \
  15560. @@ -38,7 +40,7 @@
  15561. _ASM_EXTABLE(1b, 4b) \
  15562. _ASM_EXTABLE(2b, 4b) \
  15563. : "=&a" (oldval), "=&r" (ret), \
  15564. - "+m" (*uaddr), "=&r" (tem) \
  15565. + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
  15566. : "r" (oparg), "i" (-EFAULT), "1" (0))
  15567. static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
  15568. @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
  15569. pagefault_disable();
  15570. + pax_open_userland();
  15571. switch (op) {
  15572. case FUTEX_OP_SET:
  15573. - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
  15574. + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
  15575. break;
  15576. case FUTEX_OP_ADD:
  15577. - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
  15578. + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
  15579. uaddr, oparg);
  15580. break;
  15581. case FUTEX_OP_OR:
  15582. @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
  15583. default:
  15584. ret = -ENOSYS;
  15585. }
  15586. + pax_close_userland();
  15587. pagefault_enable();
  15588. diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
  15589. index 67d69b8..50e4b77 100644
  15590. --- a/arch/x86/include/asm/hw_irq.h
  15591. +++ b/arch/x86/include/asm/hw_irq.h
  15592. @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
  15593. extern void enable_IO_APIC(void);
  15594. /* Statistics */
  15595. -extern atomic_t irq_err_count;
  15596. -extern atomic_t irq_mis_count;
  15597. +extern atomic_unchecked_t irq_err_count;
  15598. +extern atomic_unchecked_t irq_mis_count;
  15599. /* EISA */
  15600. extern void eisa_set_level_irq(unsigned int irq);
  15601. diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
  15602. index a203659..9889f1c 100644
  15603. --- a/arch/x86/include/asm/i8259.h
  15604. +++ b/arch/x86/include/asm/i8259.h
  15605. @@ -62,7 +62,7 @@ struct legacy_pic {
  15606. void (*init)(int auto_eoi);
  15607. int (*irq_pending)(unsigned int irq);
  15608. void (*make_irq)(unsigned int irq);
  15609. -};
  15610. +} __do_const;
  15611. extern struct legacy_pic *legacy_pic;
  15612. extern struct legacy_pic null_legacy_pic;
  15613. diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
  15614. index 91d9c69..dfae7d0 100644
  15615. --- a/arch/x86/include/asm/io.h
  15616. +++ b/arch/x86/include/asm/io.h
  15617. @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
  15618. "m" (*(volatile type __force *)addr) barrier); }
  15619. build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
  15620. -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
  15621. -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
  15622. +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
  15623. +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
  15624. build_mmio_read(__readb, "b", unsigned char, "=q", )
  15625. -build_mmio_read(__readw, "w", unsigned short, "=r", )
  15626. -build_mmio_read(__readl, "l", unsigned int, "=r", )
  15627. +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
  15628. +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
  15629. build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
  15630. build_mmio_write(writew, "w", unsigned short, "r", :"memory")
  15631. @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
  15632. return ioremap_nocache(offset, size);
  15633. }
  15634. -extern void iounmap(volatile void __iomem *addr);
  15635. +extern void iounmap(const volatile void __iomem *addr);
  15636. extern void set_iounmap_nonlazy(void);
  15637. @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
  15638. #include <linux/vmalloc.h>
  15639. +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
  15640. +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
  15641. +{
  15642. + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
  15643. +}
  15644. +
  15645. +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
  15646. +{
  15647. + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
  15648. +}
  15649. +
  15650. /*
  15651. * Convert a virtual cached pointer to an uncached pointer
  15652. */
  15653. diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
  15654. index bba3cf8..06bc8da 100644
  15655. --- a/arch/x86/include/asm/irqflags.h
  15656. +++ b/arch/x86/include/asm/irqflags.h
  15657. @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
  15658. sti; \
  15659. sysexit
  15660. +#define GET_CR0_INTO_RDI mov %cr0, %rdi
  15661. +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
  15662. +#define GET_CR3_INTO_RDI mov %cr3, %rdi
  15663. +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
  15664. +
  15665. #else
  15666. #define INTERRUPT_RETURN iret
  15667. #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
  15668. diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
  15669. index 9454c16..e4100e3 100644
  15670. --- a/arch/x86/include/asm/kprobes.h
  15671. +++ b/arch/x86/include/asm/kprobes.h
  15672. @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
  15673. #define RELATIVEJUMP_SIZE 5
  15674. #define RELATIVECALL_OPCODE 0xe8
  15675. #define RELATIVE_ADDR_SIZE 4
  15676. -#define MAX_STACK_SIZE 64
  15677. -#define MIN_STACK_SIZE(ADDR) \
  15678. - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
  15679. - THREAD_SIZE - (unsigned long)(ADDR))) \
  15680. - ? (MAX_STACK_SIZE) \
  15681. - : (((unsigned long)current_thread_info()) + \
  15682. - THREAD_SIZE - (unsigned long)(ADDR)))
  15683. +#define MAX_STACK_SIZE 64UL
  15684. +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
  15685. #define flush_insn_slot(p) do { } while (0)
  15686. diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
  15687. index 4ad6560..75c7bdd 100644
  15688. --- a/arch/x86/include/asm/local.h
  15689. +++ b/arch/x86/include/asm/local.h
  15690. @@ -10,33 +10,97 @@ typedef struct {
  15691. atomic_long_t a;
  15692. } local_t;
  15693. +typedef struct {
  15694. + atomic_long_unchecked_t a;
  15695. +} local_unchecked_t;
  15696. +
  15697. #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
  15698. #define local_read(l) atomic_long_read(&(l)->a)
  15699. +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
  15700. #define local_set(l, i) atomic_long_set(&(l)->a, (i))
  15701. +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
  15702. static inline void local_inc(local_t *l)
  15703. {
  15704. - asm volatile(_ASM_INC "%0"
  15705. + asm volatile(_ASM_INC "%0\n"
  15706. +
  15707. +#ifdef CONFIG_PAX_REFCOUNT
  15708. + "jno 0f\n"
  15709. + _ASM_DEC "%0\n"
  15710. + "int $4\n0:\n"
  15711. + _ASM_EXTABLE(0b, 0b)
  15712. +#endif
  15713. +
  15714. + : "+m" (l->a.counter));
  15715. +}
  15716. +
  15717. +static inline void local_inc_unchecked(local_unchecked_t *l)
  15718. +{
  15719. + asm volatile(_ASM_INC "%0\n"
  15720. : "+m" (l->a.counter));
  15721. }
  15722. static inline void local_dec(local_t *l)
  15723. {
  15724. - asm volatile(_ASM_DEC "%0"
  15725. + asm volatile(_ASM_DEC "%0\n"
  15726. +
  15727. +#ifdef CONFIG_PAX_REFCOUNT
  15728. + "jno 0f\n"
  15729. + _ASM_INC "%0\n"
  15730. + "int $4\n0:\n"
  15731. + _ASM_EXTABLE(0b, 0b)
  15732. +#endif
  15733. +
  15734. + : "+m" (l->a.counter));
  15735. +}
  15736. +
  15737. +static inline void local_dec_unchecked(local_unchecked_t *l)
  15738. +{
  15739. + asm volatile(_ASM_DEC "%0\n"
  15740. : "+m" (l->a.counter));
  15741. }
  15742. static inline void local_add(long i, local_t *l)
  15743. {
  15744. - asm volatile(_ASM_ADD "%1,%0"
  15745. + asm volatile(_ASM_ADD "%1,%0\n"
  15746. +
  15747. +#ifdef CONFIG_PAX_REFCOUNT
  15748. + "jno 0f\n"
  15749. + _ASM_SUB "%1,%0\n"
  15750. + "int $4\n0:\n"
  15751. + _ASM_EXTABLE(0b, 0b)
  15752. +#endif
  15753. +
  15754. + : "+m" (l->a.counter)
  15755. + : "ir" (i));
  15756. +}
  15757. +
  15758. +static inline void local_add_unchecked(long i, local_unchecked_t *l)
  15759. +{
  15760. + asm volatile(_ASM_ADD "%1,%0\n"
  15761. : "+m" (l->a.counter)
  15762. : "ir" (i));
  15763. }
  15764. static inline void local_sub(long i, local_t *l)
  15765. {
  15766. - asm volatile(_ASM_SUB "%1,%0"
  15767. + asm volatile(_ASM_SUB "%1,%0\n"
  15768. +
  15769. +#ifdef CONFIG_PAX_REFCOUNT
  15770. + "jno 0f\n"
  15771. + _ASM_ADD "%1,%0\n"
  15772. + "int $4\n0:\n"
  15773. + _ASM_EXTABLE(0b, 0b)
  15774. +#endif
  15775. +
  15776. + : "+m" (l->a.counter)
  15777. + : "ir" (i));
  15778. +}
  15779. +
  15780. +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
  15781. +{
  15782. + asm volatile(_ASM_SUB "%1,%0\n"
  15783. : "+m" (l->a.counter)
  15784. : "ir" (i));
  15785. }
  15786. @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
  15787. */
  15788. static inline int local_sub_and_test(long i, local_t *l)
  15789. {
  15790. - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
  15791. + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
  15792. }
  15793. /**
  15794. @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
  15795. */
  15796. static inline int local_dec_and_test(local_t *l)
  15797. {
  15798. - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
  15799. + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
  15800. }
  15801. /**
  15802. @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
  15803. */
  15804. static inline int local_inc_and_test(local_t *l)
  15805. {
  15806. - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
  15807. + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
  15808. }
  15809. /**
  15810. @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
  15811. */
  15812. static inline int local_add_negative(long i, local_t *l)
  15813. {
  15814. - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
  15815. + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
  15816. }
  15817. /**
  15818. @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
  15819. static inline long local_add_return(long i, local_t *l)
  15820. {
  15821. long __i = i;
  15822. + asm volatile(_ASM_XADD "%0, %1\n"
  15823. +
  15824. +#ifdef CONFIG_PAX_REFCOUNT
  15825. + "jno 0f\n"
  15826. + _ASM_MOV "%0,%1\n"
  15827. + "int $4\n0:\n"
  15828. + _ASM_EXTABLE(0b, 0b)
  15829. +#endif
  15830. +
  15831. + : "+r" (i), "+m" (l->a.counter)
  15832. + : : "memory");
  15833. + return i + __i;
  15834. +}
  15835. +
  15836. +/**
  15837. + * local_add_return_unchecked - add and return
  15838. + * @i: integer value to add
  15839. + * @l: pointer to type local_unchecked_t
  15840. + *
  15841. + * Atomically adds @i to @l and returns @i + @l
  15842. + */
  15843. +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
  15844. +{
  15845. + long __i = i;
  15846. asm volatile(_ASM_XADD "%0, %1;"
  15847. : "+r" (i), "+m" (l->a.counter)
  15848. : : "memory");
  15849. @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
  15850. #define local_cmpxchg(l, o, n) \
  15851. (cmpxchg_local(&((l)->a.counter), (o), (n)))
  15852. +#define local_cmpxchg_unchecked(l, o, n) \
  15853. + (cmpxchg_local(&((l)->a.counter), (o), (n)))
  15854. /* Always has a lock prefix */
  15855. #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
  15856. diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
  15857. new file mode 100644
  15858. index 0000000..2bfd3ba
  15859. --- /dev/null
  15860. +++ b/arch/x86/include/asm/mman.h
  15861. @@ -0,0 +1,15 @@
  15862. +#ifndef _X86_MMAN_H
  15863. +#define _X86_MMAN_H
  15864. +
  15865. +#include <uapi/asm/mman.h>
  15866. +
  15867. +#ifdef __KERNEL__
  15868. +#ifndef __ASSEMBLY__
  15869. +#ifdef CONFIG_X86_32
  15870. +#define arch_mmap_check i386_mmap_check
  15871. +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
  15872. +#endif
  15873. +#endif
  15874. +#endif
  15875. +
  15876. +#endif /* X86_MMAN_H */
  15877. diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
  15878. index 5f55e69..e20bfb1 100644
  15879. --- a/arch/x86/include/asm/mmu.h
  15880. +++ b/arch/x86/include/asm/mmu.h
  15881. @@ -9,7 +9,7 @@
  15882. * we put the segment information here.
  15883. */
  15884. typedef struct {
  15885. - void *ldt;
  15886. + struct desc_struct *ldt;
  15887. int size;
  15888. #ifdef CONFIG_X86_64
  15889. @@ -18,7 +18,19 @@ typedef struct {
  15890. #endif
  15891. struct mutex lock;
  15892. - void *vdso;
  15893. + unsigned long vdso;
  15894. +
  15895. +#ifdef CONFIG_X86_32
  15896. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  15897. + unsigned long user_cs_base;
  15898. + unsigned long user_cs_limit;
  15899. +
  15900. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
  15901. + cpumask_t cpu_user_cs_mask;
  15902. +#endif
  15903. +
  15904. +#endif
  15905. +#endif
  15906. } mm_context_t;
  15907. #ifdef CONFIG_SMP
  15908. diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
  15909. index be12c53..4d24039 100644
  15910. --- a/arch/x86/include/asm/mmu_context.h
  15911. +++ b/arch/x86/include/asm/mmu_context.h
  15912. @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
  15913. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  15914. {
  15915. +
  15916. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  15917. + if (!(static_cpu_has(X86_FEATURE_PCID))) {
  15918. + unsigned int i;
  15919. + pgd_t *pgd;
  15920. +
  15921. + pax_open_kernel();
  15922. + pgd = get_cpu_pgd(smp_processor_id(), kernel);
  15923. + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
  15924. + set_pgd_batched(pgd+i, native_make_pgd(0));
  15925. + pax_close_kernel();
  15926. + }
  15927. +#endif
  15928. +
  15929. #ifdef CONFIG_SMP
  15930. if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
  15931. this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
  15932. @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  15933. struct task_struct *tsk)
  15934. {
  15935. unsigned cpu = smp_processor_id();
  15936. +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
  15937. + int tlbstate = TLBSTATE_OK;
  15938. +#endif
  15939. if (likely(prev != next)) {
  15940. #ifdef CONFIG_SMP
  15941. +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
  15942. + tlbstate = this_cpu_read(cpu_tlbstate.state);
  15943. +#endif
  15944. this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  15945. this_cpu_write(cpu_tlbstate.active_mm, next);
  15946. #endif
  15947. cpumask_set_cpu(cpu, mm_cpumask(next));
  15948. /* Re-load page tables */
  15949. +#ifdef CONFIG_PAX_PER_CPU_PGD
  15950. + pax_open_kernel();
  15951. +
  15952. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  15953. + if (static_cpu_has(X86_FEATURE_PCID))
  15954. + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
  15955. + else
  15956. +#endif
  15957. +
  15958. + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
  15959. + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
  15960. + pax_close_kernel();
  15961. + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
  15962. +
  15963. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  15964. + if (static_cpu_has(X86_FEATURE_PCID)) {
  15965. + if (static_cpu_has(X86_FEATURE_INVPCID)) {
  15966. + u64 descriptor[2];
  15967. + descriptor[0] = PCID_USER;
  15968. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
  15969. + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
  15970. + descriptor[0] = PCID_KERNEL;
  15971. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
  15972. + }
  15973. + } else {
  15974. + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
  15975. + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
  15976. + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
  15977. + else
  15978. + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
  15979. + }
  15980. + } else
  15981. +#endif
  15982. +
  15983. + load_cr3(get_cpu_pgd(cpu, kernel));
  15984. +#else
  15985. load_cr3(next->pgd);
  15986. +#endif
  15987. /* Stop flush ipis for the previous mm */
  15988. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  15989. @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  15990. /* Load the LDT, if the LDT is different: */
  15991. if (unlikely(prev->context.ldt != next->context.ldt))
  15992. load_LDT_nolock(&next->context);
  15993. +
  15994. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
  15995. + if (!(__supported_pte_mask & _PAGE_NX)) {
  15996. + smp_mb__before_clear_bit();
  15997. + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
  15998. + smp_mb__after_clear_bit();
  15999. + cpu_set(cpu, next->context.cpu_user_cs_mask);
  16000. + }
  16001. +#endif
  16002. +
  16003. +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
  16004. + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
  16005. + prev->context.user_cs_limit != next->context.user_cs_limit))
  16006. + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
  16007. +#ifdef CONFIG_SMP
  16008. + else if (unlikely(tlbstate != TLBSTATE_OK))
  16009. + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
  16010. +#endif
  16011. +#endif
  16012. +
  16013. }
  16014. + else {
  16015. +
  16016. +#ifdef CONFIG_PAX_PER_CPU_PGD
  16017. + pax_open_kernel();
  16018. +
  16019. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  16020. + if (static_cpu_has(X86_FEATURE_PCID))
  16021. + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
  16022. + else
  16023. +#endif
  16024. +
  16025. + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
  16026. + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
  16027. + pax_close_kernel();
  16028. + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
  16029. +
  16030. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  16031. + if (static_cpu_has(X86_FEATURE_PCID)) {
  16032. + if (static_cpu_has(X86_FEATURE_INVPCID)) {
  16033. + u64 descriptor[2];
  16034. + descriptor[0] = PCID_USER;
  16035. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
  16036. + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
  16037. + descriptor[0] = PCID_KERNEL;
  16038. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
  16039. + }
  16040. + } else {
  16041. + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
  16042. + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
  16043. + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
  16044. + else
  16045. + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
  16046. + }
  16047. + } else
  16048. +#endif
  16049. +
  16050. + load_cr3(get_cpu_pgd(cpu, kernel));
  16051. +#endif
  16052. +
  16053. #ifdef CONFIG_SMP
  16054. - else {
  16055. this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  16056. BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
  16057. @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  16058. * tlb flush IPI delivery. We must reload CR3
  16059. * to make sure to use no freed page tables.
  16060. */
  16061. +
  16062. +#ifndef CONFIG_PAX_PER_CPU_PGD
  16063. load_cr3(next->pgd);
  16064. +#endif
  16065. +
  16066. load_LDT_nolock(&next->context);
  16067. +
  16068. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
  16069. + if (!(__supported_pte_mask & _PAGE_NX))
  16070. + cpu_set(cpu, next->context.cpu_user_cs_mask);
  16071. +#endif
  16072. +
  16073. +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
  16074. +#ifdef CONFIG_PAX_PAGEEXEC
  16075. + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
  16076. +#endif
  16077. + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
  16078. +#endif
  16079. +
  16080. }
  16081. +#endif
  16082. }
  16083. -#endif
  16084. }
  16085. #define activate_mm(prev, next) \
  16086. diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
  16087. index e3b7819..b257c64 100644
  16088. --- a/arch/x86/include/asm/module.h
  16089. +++ b/arch/x86/include/asm/module.h
  16090. @@ -5,6 +5,7 @@
  16091. #ifdef CONFIG_X86_64
  16092. /* X86_64 does not define MODULE_PROC_FAMILY */
  16093. +#define MODULE_PROC_FAMILY ""
  16094. #elif defined CONFIG_M486
  16095. #define MODULE_PROC_FAMILY "486 "
  16096. #elif defined CONFIG_M586
  16097. @@ -57,8 +58,20 @@
  16098. #error unknown processor family
  16099. #endif
  16100. -#ifdef CONFIG_X86_32
  16101. -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
  16102. +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
  16103. +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
  16104. +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
  16105. +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
  16106. +#else
  16107. +#define MODULE_PAX_KERNEXEC ""
  16108. #endif
  16109. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  16110. +#define MODULE_PAX_UDEREF "UDEREF "
  16111. +#else
  16112. +#define MODULE_PAX_UDEREF ""
  16113. +#endif
  16114. +
  16115. +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
  16116. +
  16117. #endif /* _ASM_X86_MODULE_H */
  16118. diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
  16119. index 86f9301..b365cda 100644
  16120. --- a/arch/x86/include/asm/nmi.h
  16121. +++ b/arch/x86/include/asm/nmi.h
  16122. @@ -40,11 +40,11 @@ struct nmiaction {
  16123. nmi_handler_t handler;
  16124. unsigned long flags;
  16125. const char *name;
  16126. -};
  16127. +} __do_const;
  16128. #define register_nmi_handler(t, fn, fg, n, init...) \
  16129. ({ \
  16130. - static struct nmiaction init fn##_na = { \
  16131. + static const struct nmiaction init fn##_na = { \
  16132. .handler = (fn), \
  16133. .name = (n), \
  16134. .flags = (fg), \
  16135. @@ -52,7 +52,7 @@ struct nmiaction {
  16136. __register_nmi_handler((t), &fn##_na); \
  16137. })
  16138. -int __register_nmi_handler(unsigned int, struct nmiaction *);
  16139. +int __register_nmi_handler(unsigned int, const struct nmiaction *);
  16140. void unregister_nmi_handler(unsigned int, const char *);
  16141. diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
  16142. index 775873d..de5f0304 100644
  16143. --- a/arch/x86/include/asm/page.h
  16144. +++ b/arch/x86/include/asm/page.h
  16145. @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
  16146. __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
  16147. #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
  16148. +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
  16149. #define __boot_va(x) __va(x)
  16150. #define __boot_pa(x) __pa(x)
  16151. diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
  16152. index 0f1ddee..e2fc3d1 100644
  16153. --- a/arch/x86/include/asm/page_64.h
  16154. +++ b/arch/x86/include/asm/page_64.h
  16155. @@ -7,9 +7,9 @@
  16156. /* duplicated to the one in bootmem.h */
  16157. extern unsigned long max_pfn;
  16158. -extern unsigned long phys_base;
  16159. +extern const unsigned long phys_base;
  16160. -static inline unsigned long __phys_addr_nodebug(unsigned long x)
  16161. +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
  16162. {
  16163. unsigned long y = x - __START_KERNEL_map;
  16164. diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
  16165. index cd6e1610..70f4418 100644
  16166. --- a/arch/x86/include/asm/paravirt.h
  16167. +++ b/arch/x86/include/asm/paravirt.h
  16168. @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
  16169. return (pmd_t) { ret };
  16170. }
  16171. -static inline pmdval_t pmd_val(pmd_t pmd)
  16172. +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
  16173. {
  16174. pmdval_t ret;
  16175. @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
  16176. val);
  16177. }
  16178. +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
  16179. +{
  16180. + pgdval_t val = native_pgd_val(pgd);
  16181. +
  16182. + if (sizeof(pgdval_t) > sizeof(long))
  16183. + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
  16184. + val, (u64)val >> 32);
  16185. + else
  16186. + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
  16187. + val);
  16188. +}
  16189. +
  16190. static inline void pgd_clear(pgd_t *pgdp)
  16191. {
  16192. set_pgd(pgdp, __pgd(0));
  16193. @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
  16194. pv_mmu_ops.set_fixmap(idx, phys, flags);
  16195. }
  16196. +#ifdef CONFIG_PAX_KERNEXEC
  16197. +static inline unsigned long pax_open_kernel(void)
  16198. +{
  16199. + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
  16200. +}
  16201. +
  16202. +static inline unsigned long pax_close_kernel(void)
  16203. +{
  16204. + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
  16205. +}
  16206. +#else
  16207. +static inline unsigned long pax_open_kernel(void) { return 0; }
  16208. +static inline unsigned long pax_close_kernel(void) { return 0; }
  16209. +#endif
  16210. +
  16211. #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
  16212. static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
  16213. @@ -906,7 +933,7 @@ extern void default_banner(void);
  16214. #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
  16215. #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
  16216. -#define PARA_INDIRECT(addr) *%cs:addr
  16217. +#define PARA_INDIRECT(addr) *%ss:addr
  16218. #endif
  16219. #define INTERRUPT_RETURN \
  16220. @@ -981,6 +1008,21 @@ extern void default_banner(void);
  16221. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
  16222. CLBR_NONE, \
  16223. jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
  16224. +
  16225. +#define GET_CR0_INTO_RDI \
  16226. + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
  16227. + mov %rax,%rdi
  16228. +
  16229. +#define SET_RDI_INTO_CR0 \
  16230. + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
  16231. +
  16232. +#define GET_CR3_INTO_RDI \
  16233. + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
  16234. + mov %rax,%rdi
  16235. +
  16236. +#define SET_RDI_INTO_CR3 \
  16237. + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
  16238. +
  16239. #endif /* CONFIG_X86_32 */
  16240. #endif /* __ASSEMBLY__ */
  16241. diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
  16242. index 7549b8b..f0edfda 100644
  16243. --- a/arch/x86/include/asm/paravirt_types.h
  16244. +++ b/arch/x86/include/asm/paravirt_types.h
  16245. @@ -84,7 +84,7 @@ struct pv_init_ops {
  16246. */
  16247. unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
  16248. unsigned long addr, unsigned len);
  16249. -};
  16250. +} __no_const __no_randomize_layout;
  16251. struct pv_lazy_ops {
  16252. @@ -92,13 +92,13 @@ struct pv_lazy_ops {
  16253. void (*enter)(void);
  16254. void (*leave)(void);
  16255. void (*flush)(void);
  16256. -};
  16257. +} __no_randomize_layout;
  16258. struct pv_time_ops {
  16259. unsigned long long (*sched_clock)(void);
  16260. unsigned long long (*steal_clock)(int cpu);
  16261. unsigned long (*get_tsc_khz)(void);
  16262. -};
  16263. +} __no_const __no_randomize_layout;
  16264. struct pv_cpu_ops {
  16265. /* hooks for various privileged instructions */
  16266. @@ -192,7 +192,7 @@ struct pv_cpu_ops {
  16267. void (*start_context_switch)(struct task_struct *prev);
  16268. void (*end_context_switch)(struct task_struct *next);
  16269. -};
  16270. +} __no_const __no_randomize_layout;
  16271. struct pv_irq_ops {
  16272. /*
  16273. @@ -215,7 +215,7 @@ struct pv_irq_ops {
  16274. #ifdef CONFIG_X86_64
  16275. void (*adjust_exception_frame)(void);
  16276. #endif
  16277. -};
  16278. +} __no_randomize_layout;
  16279. struct pv_apic_ops {
  16280. #ifdef CONFIG_X86_LOCAL_APIC
  16281. @@ -223,7 +223,7 @@ struct pv_apic_ops {
  16282. unsigned long start_eip,
  16283. unsigned long start_esp);
  16284. #endif
  16285. -};
  16286. +} __no_const __no_randomize_layout;
  16287. struct pv_mmu_ops {
  16288. unsigned long (*read_cr2)(void);
  16289. @@ -313,6 +313,7 @@ struct pv_mmu_ops {
  16290. struct paravirt_callee_save make_pud;
  16291. void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
  16292. + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
  16293. #endif /* PAGETABLE_LEVELS == 4 */
  16294. #endif /* PAGETABLE_LEVELS >= 3 */
  16295. @@ -324,7 +325,13 @@ struct pv_mmu_ops {
  16296. an mfn. We can tell which is which from the index. */
  16297. void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
  16298. phys_addr_t phys, pgprot_t flags);
  16299. -};
  16300. +
  16301. +#ifdef CONFIG_PAX_KERNEXEC
  16302. + unsigned long (*pax_open_kernel)(void);
  16303. + unsigned long (*pax_close_kernel)(void);
  16304. +#endif
  16305. +
  16306. +} __no_randomize_layout;
  16307. struct arch_spinlock;
  16308. #ifdef CONFIG_SMP
  16309. @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
  16310. struct pv_lock_ops {
  16311. struct paravirt_callee_save lock_spinning;
  16312. void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
  16313. -};
  16314. +} __no_randomize_layout;
  16315. /* This contains all the paravirt structures: we get a convenient
  16316. * number for each function using the offset which we use to indicate
  16317. - * what to patch. */
  16318. + * what to patch.
  16319. + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
  16320. + */
  16321. +
  16322. struct paravirt_patch_template {
  16323. struct pv_init_ops pv_init_ops;
  16324. struct pv_time_ops pv_time_ops;
  16325. @@ -349,7 +359,7 @@ struct paravirt_patch_template {
  16326. struct pv_apic_ops pv_apic_ops;
  16327. struct pv_mmu_ops pv_mmu_ops;
  16328. struct pv_lock_ops pv_lock_ops;
  16329. -};
  16330. +} __no_randomize_layout;
  16331. extern struct pv_info pv_info;
  16332. extern struct pv_init_ops pv_init_ops;
  16333. diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
  16334. index c4412e9..90e88c5 100644
  16335. --- a/arch/x86/include/asm/pgalloc.h
  16336. +++ b/arch/x86/include/asm/pgalloc.h
  16337. @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
  16338. pmd_t *pmd, pte_t *pte)
  16339. {
  16340. paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
  16341. + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
  16342. +}
  16343. +
  16344. +static inline void pmd_populate_user(struct mm_struct *mm,
  16345. + pmd_t *pmd, pte_t *pte)
  16346. +{
  16347. + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
  16348. set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
  16349. }
  16350. @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
  16351. #ifdef CONFIG_X86_PAE
  16352. extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
  16353. +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
  16354. +{
  16355. + pud_populate(mm, pudp, pmd);
  16356. +}
  16357. #else /* !CONFIG_X86_PAE */
  16358. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  16359. {
  16360. paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
  16361. set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
  16362. }
  16363. +
  16364. +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  16365. +{
  16366. + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
  16367. + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
  16368. +}
  16369. #endif /* CONFIG_X86_PAE */
  16370. #if PAGETABLE_LEVELS > 3
  16371. @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
  16372. set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
  16373. }
  16374. +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
  16375. +{
  16376. + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
  16377. + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
  16378. +}
  16379. +
  16380. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  16381. {
  16382. return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  16383. diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
  16384. index 0d193e2..bf59aeb 100644
  16385. --- a/arch/x86/include/asm/pgtable-2level.h
  16386. +++ b/arch/x86/include/asm/pgtable-2level.h
  16387. @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
  16388. static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  16389. {
  16390. + pax_open_kernel();
  16391. *pmdp = pmd;
  16392. + pax_close_kernel();
  16393. }
  16394. static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
  16395. diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
  16396. index 81bb91b..9392125 100644
  16397. --- a/arch/x86/include/asm/pgtable-3level.h
  16398. +++ b/arch/x86/include/asm/pgtable-3level.h
  16399. @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
  16400. static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  16401. {
  16402. + pax_open_kernel();
  16403. set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
  16404. + pax_close_kernel();
  16405. }
  16406. static inline void native_set_pud(pud_t *pudp, pud_t pud)
  16407. {
  16408. + pax_open_kernel();
  16409. set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
  16410. + pax_close_kernel();
  16411. }
  16412. /*
  16413. diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
  16414. index bbc8b12..f228861 100644
  16415. --- a/arch/x86/include/asm/pgtable.h
  16416. +++ b/arch/x86/include/asm/pgtable.h
  16417. @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
  16418. #ifndef __PAGETABLE_PUD_FOLDED
  16419. #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
  16420. +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
  16421. #define pgd_clear(pgd) native_pgd_clear(pgd)
  16422. #endif
  16423. @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
  16424. #define arch_end_context_switch(prev) do {} while(0)
  16425. +#define pax_open_kernel() native_pax_open_kernel()
  16426. +#define pax_close_kernel() native_pax_close_kernel()
  16427. #endif /* CONFIG_PARAVIRT */
  16428. +#define __HAVE_ARCH_PAX_OPEN_KERNEL
  16429. +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
  16430. +
  16431. +#ifdef CONFIG_PAX_KERNEXEC
  16432. +static inline unsigned long native_pax_open_kernel(void)
  16433. +{
  16434. + unsigned long cr0;
  16435. +
  16436. + preempt_disable();
  16437. + barrier();
  16438. + cr0 = read_cr0() ^ X86_CR0_WP;
  16439. + BUG_ON(cr0 & X86_CR0_WP);
  16440. + write_cr0(cr0);
  16441. + return cr0 ^ X86_CR0_WP;
  16442. +}
  16443. +
  16444. +static inline unsigned long native_pax_close_kernel(void)
  16445. +{
  16446. + unsigned long cr0;
  16447. +
  16448. + cr0 = read_cr0() ^ X86_CR0_WP;
  16449. + BUG_ON(!(cr0 & X86_CR0_WP));
  16450. + write_cr0(cr0);
  16451. + barrier();
  16452. + preempt_enable_no_resched();
  16453. + return cr0 ^ X86_CR0_WP;
  16454. +}
  16455. +#else
  16456. +static inline unsigned long native_pax_open_kernel(void) { return 0; }
  16457. +static inline unsigned long native_pax_close_kernel(void) { return 0; }
  16458. +#endif
  16459. +
  16460. /*
  16461. * The following only work if pte_present() is true.
  16462. * Undefined behaviour if not..
  16463. */
  16464. +static inline int pte_user(pte_t pte)
  16465. +{
  16466. + return pte_val(pte) & _PAGE_USER;
  16467. +}
  16468. +
  16469. static inline int pte_dirty(pte_t pte)
  16470. {
  16471. return pte_flags(pte) & _PAGE_DIRTY;
  16472. @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
  16473. return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
  16474. }
  16475. +static inline unsigned long pgd_pfn(pgd_t pgd)
  16476. +{
  16477. + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
  16478. +}
  16479. +
  16480. #define pte_page(pte) pfn_to_page(pte_pfn(pte))
  16481. static inline int pmd_large(pmd_t pte)
  16482. @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
  16483. return pte_clear_flags(pte, _PAGE_RW);
  16484. }
  16485. +static inline pte_t pte_mkread(pte_t pte)
  16486. +{
  16487. + return __pte(pte_val(pte) | _PAGE_USER);
  16488. +}
  16489. +
  16490. static inline pte_t pte_mkexec(pte_t pte)
  16491. {
  16492. - return pte_clear_flags(pte, _PAGE_NX);
  16493. +#ifdef CONFIG_X86_PAE
  16494. + if (__supported_pte_mask & _PAGE_NX)
  16495. + return pte_clear_flags(pte, _PAGE_NX);
  16496. + else
  16497. +#endif
  16498. + return pte_set_flags(pte, _PAGE_USER);
  16499. +}
  16500. +
  16501. +static inline pte_t pte_exprotect(pte_t pte)
  16502. +{
  16503. +#ifdef CONFIG_X86_PAE
  16504. + if (__supported_pte_mask & _PAGE_NX)
  16505. + return pte_set_flags(pte, _PAGE_NX);
  16506. + else
  16507. +#endif
  16508. + return pte_clear_flags(pte, _PAGE_USER);
  16509. }
  16510. static inline pte_t pte_mkdirty(pte_t pte)
  16511. @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
  16512. #endif
  16513. #ifndef __ASSEMBLY__
  16514. +
  16515. +#ifdef CONFIG_PAX_PER_CPU_PGD
  16516. +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
  16517. +enum cpu_pgd_type {kernel = 0, user = 1};
  16518. +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
  16519. +{
  16520. + return cpu_pgd[cpu][type];
  16521. +}
  16522. +#endif
  16523. +
  16524. #include <linux/mm_types.h>
  16525. #include <linux/mmdebug.h>
  16526. #include <linux/log2.h>
  16527. @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
  16528. * Currently stuck as a macro due to indirect forward reference to
  16529. * linux/mmzone.h's __section_mem_map_addr() definition:
  16530. */
  16531. -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
  16532. +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
  16533. /* Find an entry in the second-level page table.. */
  16534. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
  16535. @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
  16536. * Currently stuck as a macro due to indirect forward reference to
  16537. * linux/mmzone.h's __section_mem_map_addr() definition:
  16538. */
  16539. -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
  16540. +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
  16541. /* to find an entry in a page-table-directory. */
  16542. static inline unsigned long pud_index(unsigned long address)
  16543. @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
  16544. static inline int pgd_bad(pgd_t pgd)
  16545. {
  16546. - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
  16547. + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
  16548. }
  16549. static inline int pgd_none(pgd_t pgd)
  16550. @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
  16551. * pgd_offset() returns a (pgd_t *)
  16552. * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
  16553. */
  16554. -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
  16555. +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  16556. +
  16557. +#ifdef CONFIG_PAX_PER_CPU_PGD
  16558. +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
  16559. +#endif
  16560. +
  16561. /*
  16562. * a shortcut which implies the use of the kernel's pgd, instead
  16563. * of a process's
  16564. @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
  16565. #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
  16566. #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
  16567. +#ifdef CONFIG_X86_32
  16568. +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
  16569. +#else
  16570. +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
  16571. +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
  16572. +
  16573. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  16574. +#ifdef __ASSEMBLY__
  16575. +#define pax_user_shadow_base pax_user_shadow_base(%rip)
  16576. +#else
  16577. +extern unsigned long pax_user_shadow_base;
  16578. +extern pgdval_t clone_pgd_mask;
  16579. +#endif
  16580. +#endif
  16581. +
  16582. +#endif
  16583. +
  16584. #ifndef __ASSEMBLY__
  16585. extern int direct_gbpages;
  16586. @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
  16587. * dst and src can be on the same page, but the range must not overlap,
  16588. * and must not cross a page boundary.
  16589. */
  16590. -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
  16591. +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
  16592. {
  16593. - memcpy(dst, src, count * sizeof(pgd_t));
  16594. + pax_open_kernel();
  16595. + while (count--)
  16596. + *dst++ = *src++;
  16597. + pax_close_kernel();
  16598. }
  16599. +#ifdef CONFIG_PAX_PER_CPU_PGD
  16600. +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
  16601. +#endif
  16602. +
  16603. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  16604. +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
  16605. +#else
  16606. +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
  16607. +#endif
  16608. +
  16609. #define PTE_SHIFT ilog2(PTRS_PER_PTE)
  16610. static inline int page_level_shift(enum pg_level level)
  16611. {
  16612. diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
  16613. index 9ee3221..b979c6b 100644
  16614. --- a/arch/x86/include/asm/pgtable_32.h
  16615. +++ b/arch/x86/include/asm/pgtable_32.h
  16616. @@ -25,9 +25,6 @@
  16617. struct mm_struct;
  16618. struct vm_area_struct;
  16619. -extern pgd_t swapper_pg_dir[1024];
  16620. -extern pgd_t initial_page_table[1024];
  16621. -
  16622. static inline void pgtable_cache_init(void) { }
  16623. static inline void check_pgt_cache(void) { }
  16624. void paging_init(void);
  16625. @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
  16626. # include <asm/pgtable-2level.h>
  16627. #endif
  16628. +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  16629. +extern pgd_t initial_page_table[PTRS_PER_PGD];
  16630. +#ifdef CONFIG_X86_PAE
  16631. +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
  16632. +#endif
  16633. +
  16634. #if defined(CONFIG_HIGHPTE)
  16635. #define pte_offset_map(dir, address) \
  16636. ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
  16637. @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
  16638. /* Clear a kernel PTE and flush it from the TLB */
  16639. #define kpte_clear_flush(ptep, vaddr) \
  16640. do { \
  16641. + pax_open_kernel(); \
  16642. pte_clear(&init_mm, (vaddr), (ptep)); \
  16643. + pax_close_kernel(); \
  16644. __flush_tlb_one((vaddr)); \
  16645. } while (0)
  16646. #endif /* !__ASSEMBLY__ */
  16647. +#define HAVE_ARCH_UNMAPPED_AREA
  16648. +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  16649. +
  16650. /*
  16651. * kern_addr_valid() is (1) for FLATMEM and (0) for
  16652. * SPARSEMEM and DISCONTIGMEM
  16653. diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
  16654. index ed5903b..c7fe163 100644
  16655. --- a/arch/x86/include/asm/pgtable_32_types.h
  16656. +++ b/arch/x86/include/asm/pgtable_32_types.h
  16657. @@ -8,7 +8,7 @@
  16658. */
  16659. #ifdef CONFIG_X86_PAE
  16660. # include <asm/pgtable-3level_types.h>
  16661. -# define PMD_SIZE (1UL << PMD_SHIFT)
  16662. +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
  16663. # define PMD_MASK (~(PMD_SIZE - 1))
  16664. #else
  16665. # include <asm/pgtable-2level_types.h>
  16666. @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
  16667. # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
  16668. #endif
  16669. +#ifdef CONFIG_PAX_KERNEXEC
  16670. +#ifndef __ASSEMBLY__
  16671. +extern unsigned char MODULES_EXEC_VADDR[];
  16672. +extern unsigned char MODULES_EXEC_END[];
  16673. +#endif
  16674. +#include <asm/boot.h>
  16675. +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
  16676. +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
  16677. +#else
  16678. +#define ktla_ktva(addr) (addr)
  16679. +#define ktva_ktla(addr) (addr)
  16680. +#endif
  16681. +
  16682. #define MODULES_VADDR VMALLOC_START
  16683. #define MODULES_END VMALLOC_END
  16684. #define MODULES_LEN (MODULES_VADDR - MODULES_END)
  16685. diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
  16686. index e22c1db..23a625a 100644
  16687. --- a/arch/x86/include/asm/pgtable_64.h
  16688. +++ b/arch/x86/include/asm/pgtable_64.h
  16689. @@ -16,10 +16,14 @@
  16690. extern pud_t level3_kernel_pgt[512];
  16691. extern pud_t level3_ident_pgt[512];
  16692. +extern pud_t level3_vmalloc_start_pgt[512];
  16693. +extern pud_t level3_vmalloc_end_pgt[512];
  16694. +extern pud_t level3_vmemmap_pgt[512];
  16695. +extern pud_t level2_vmemmap_pgt[512];
  16696. extern pmd_t level2_kernel_pgt[512];
  16697. extern pmd_t level2_fixmap_pgt[512];
  16698. -extern pmd_t level2_ident_pgt[512];
  16699. -extern pgd_t init_level4_pgt[];
  16700. +extern pmd_t level2_ident_pgt[512*2];
  16701. +extern pgd_t init_level4_pgt[512];
  16702. #define swapper_pg_dir init_level4_pgt
  16703. @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
  16704. static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  16705. {
  16706. + pax_open_kernel();
  16707. *pmdp = pmd;
  16708. + pax_close_kernel();
  16709. }
  16710. static inline void native_pmd_clear(pmd_t *pmd)
  16711. @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
  16712. static inline void native_set_pud(pud_t *pudp, pud_t pud)
  16713. {
  16714. + pax_open_kernel();
  16715. *pudp = pud;
  16716. + pax_close_kernel();
  16717. }
  16718. static inline void native_pud_clear(pud_t *pud)
  16719. @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
  16720. static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
  16721. {
  16722. + pax_open_kernel();
  16723. + *pgdp = pgd;
  16724. + pax_close_kernel();
  16725. +}
  16726. +
  16727. +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
  16728. +{
  16729. *pgdp = pgd;
  16730. }
  16731. diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
  16732. index c883bf7..19970b3 100644
  16733. --- a/arch/x86/include/asm/pgtable_64_types.h
  16734. +++ b/arch/x86/include/asm/pgtable_64_types.h
  16735. @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
  16736. #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
  16737. #define MODULES_END _AC(0xffffffffff000000, UL)
  16738. #define MODULES_LEN (MODULES_END - MODULES_VADDR)
  16739. +#define MODULES_EXEC_VADDR MODULES_VADDR
  16740. +#define MODULES_EXEC_END MODULES_END
  16741. +
  16742. +#define ktla_ktva(addr) (addr)
  16743. +#define ktva_ktla(addr) (addr)
  16744. #define EARLY_DYNAMIC_PAGE_TABLES 64
  16745. diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
  16746. index 94e40f1..ebd03e4 100644
  16747. --- a/arch/x86/include/asm/pgtable_types.h
  16748. +++ b/arch/x86/include/asm/pgtable_types.h
  16749. @@ -16,13 +16,12 @@
  16750. #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
  16751. #define _PAGE_BIT_PAT 7 /* on 4KB pages */
  16752. #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
  16753. -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
  16754. +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
  16755. #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
  16756. #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
  16757. #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
  16758. -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
  16759. -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
  16760. -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
  16761. +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
  16762. +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
  16763. #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
  16764. /* If _PAGE_BIT_PRESENT is clear, we use these: */
  16765. @@ -40,7 +39,6 @@
  16766. #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
  16767. #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
  16768. #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
  16769. -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
  16770. #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
  16771. #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
  16772. #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
  16773. @@ -87,8 +85,10 @@
  16774. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  16775. #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
  16776. -#else
  16777. +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
  16778. #define _PAGE_NX (_AT(pteval_t, 0))
  16779. +#else
  16780. +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
  16781. #endif
  16782. #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
  16783. @@ -147,6 +147,9 @@
  16784. #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
  16785. _PAGE_ACCESSED)
  16786. +#define PAGE_READONLY_NOEXEC PAGE_READONLY
  16787. +#define PAGE_SHARED_NOEXEC PAGE_SHARED
  16788. +
  16789. #define __PAGE_KERNEL_EXEC \
  16790. (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
  16791. #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
  16792. @@ -157,7 +160,7 @@
  16793. #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
  16794. #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
  16795. #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
  16796. -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
  16797. +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
  16798. #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
  16799. #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
  16800. #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
  16801. @@ -219,8 +222,8 @@
  16802. * bits are combined, this will alow user to access the high address mapped
  16803. * VDSO in the presence of CONFIG_COMPAT_VDSO
  16804. */
  16805. -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
  16806. -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
  16807. +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
  16808. +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
  16809. #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
  16810. #endif
  16811. @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
  16812. {
  16813. return native_pgd_val(pgd) & PTE_FLAGS_MASK;
  16814. }
  16815. +#endif
  16816. +#if PAGETABLE_LEVELS == 3
  16817. +#include <asm-generic/pgtable-nopud.h>
  16818. +#endif
  16819. +
  16820. +#if PAGETABLE_LEVELS == 2
  16821. +#include <asm-generic/pgtable-nopmd.h>
  16822. +#endif
  16823. +
  16824. +#ifndef __ASSEMBLY__
  16825. #if PAGETABLE_LEVELS > 3
  16826. typedef struct { pudval_t pud; } pud_t;
  16827. @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
  16828. return pud.pud;
  16829. }
  16830. #else
  16831. -#include <asm-generic/pgtable-nopud.h>
  16832. -
  16833. static inline pudval_t native_pud_val(pud_t pud)
  16834. {
  16835. return native_pgd_val(pud.pgd);
  16836. @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
  16837. return pmd.pmd;
  16838. }
  16839. #else
  16840. -#include <asm-generic/pgtable-nopmd.h>
  16841. -
  16842. static inline pmdval_t native_pmd_val(pmd_t pmd)
  16843. {
  16844. return native_pgd_val(pmd.pud.pgd);
  16845. @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
  16846. extern pteval_t __supported_pte_mask;
  16847. extern void set_nx(void);
  16848. -extern int nx_enabled;
  16849. #define pgprot_writecombine pgprot_writecombine
  16850. extern pgprot_t pgprot_writecombine(pgprot_t prot);
  16851. diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
  16852. index c8b0519..fd29e73 100644
  16853. --- a/arch/x86/include/asm/preempt.h
  16854. +++ b/arch/x86/include/asm/preempt.h
  16855. @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
  16856. */
  16857. static __always_inline bool __preempt_count_dec_and_test(void)
  16858. {
  16859. - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
  16860. + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
  16861. }
  16862. /*
  16863. diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
  16864. index fdedd38..95c02c2 100644
  16865. --- a/arch/x86/include/asm/processor.h
  16866. +++ b/arch/x86/include/asm/processor.h
  16867. @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
  16868. /* Index into per_cpu list: */
  16869. u16 cpu_index;
  16870. u32 microcode;
  16871. -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
  16872. +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
  16873. #define X86_VENDOR_INTEL 0
  16874. #define X86_VENDOR_CYRIX 1
  16875. @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
  16876. : "memory");
  16877. }
  16878. +/* invpcid (%rdx),%rax */
  16879. +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
  16880. +
  16881. +#define INVPCID_SINGLE_ADDRESS 0UL
  16882. +#define INVPCID_SINGLE_CONTEXT 1UL
  16883. +#define INVPCID_ALL_GLOBAL 2UL
  16884. +#define INVPCID_ALL_MONGLOBAL 3UL
  16885. +
  16886. +#define PCID_KERNEL 0UL
  16887. +#define PCID_USER 1UL
  16888. +#define PCID_NOFLUSH (1UL << 63)
  16889. +
  16890. static inline void load_cr3(pgd_t *pgdir)
  16891. {
  16892. - write_cr3(__pa(pgdir));
  16893. + write_cr3(__pa(pgdir) | PCID_KERNEL);
  16894. }
  16895. #ifdef CONFIG_X86_32
  16896. @@ -283,7 +295,7 @@ struct tss_struct {
  16897. } ____cacheline_aligned;
  16898. -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
  16899. +extern struct tss_struct init_tss[NR_CPUS];
  16900. /*
  16901. * Save the original ist values for checking stack pointers during debugging
  16902. @@ -470,6 +482,7 @@ struct thread_struct {
  16903. unsigned short ds;
  16904. unsigned short fsindex;
  16905. unsigned short gsindex;
  16906. + unsigned short ss;
  16907. #endif
  16908. #ifdef CONFIG_X86_32
  16909. unsigned long ip;
  16910. @@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
  16911. extern unsigned long mmu_cr4_features;
  16912. extern u32 *trampoline_cr4_features;
  16913. -static inline void set_in_cr4(unsigned long mask)
  16914. -{
  16915. - unsigned long cr4;
  16916. -
  16917. - mmu_cr4_features |= mask;
  16918. - if (trampoline_cr4_features)
  16919. - *trampoline_cr4_features = mmu_cr4_features;
  16920. - cr4 = read_cr4();
  16921. - cr4 |= mask;
  16922. - write_cr4(cr4);
  16923. -}
  16924. -
  16925. -static inline void clear_in_cr4(unsigned long mask)
  16926. -{
  16927. - unsigned long cr4;
  16928. -
  16929. - mmu_cr4_features &= ~mask;
  16930. - if (trampoline_cr4_features)
  16931. - *trampoline_cr4_features = mmu_cr4_features;
  16932. - cr4 = read_cr4();
  16933. - cr4 &= ~mask;
  16934. - write_cr4(cr4);
  16935. -}
  16936. +extern void set_in_cr4(unsigned long mask);
  16937. +extern void clear_in_cr4(unsigned long mask);
  16938. typedef struct {
  16939. unsigned long seg;
  16940. @@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
  16941. */
  16942. #define TASK_SIZE PAGE_OFFSET
  16943. #define TASK_SIZE_MAX TASK_SIZE
  16944. +
  16945. +#ifdef CONFIG_PAX_SEGMEXEC
  16946. +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
  16947. +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
  16948. +#else
  16949. #define STACK_TOP TASK_SIZE
  16950. -#define STACK_TOP_MAX STACK_TOP
  16951. +#endif
  16952. +
  16953. +#define STACK_TOP_MAX TASK_SIZE
  16954. #define INIT_THREAD { \
  16955. - .sp0 = sizeof(init_stack) + (long)&init_stack, \
  16956. + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
  16957. .vm86_info = NULL, \
  16958. .sysenter_cs = __KERNEL_CS, \
  16959. .io_bitmap_ptr = NULL, \
  16960. @@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
  16961. */
  16962. #define INIT_TSS { \
  16963. .x86_tss = { \
  16964. - .sp0 = sizeof(init_stack) + (long)&init_stack, \
  16965. + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
  16966. .ss0 = __KERNEL_DS, \
  16967. .ss1 = __KERNEL_CS, \
  16968. .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
  16969. @@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
  16970. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  16971. #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
  16972. -#define KSTK_TOP(info) \
  16973. -({ \
  16974. - unsigned long *__ptr = (unsigned long *)(info); \
  16975. - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
  16976. -})
  16977. +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
  16978. /*
  16979. * The below -8 is to reserve 8 bytes on top of the ring0 stack.
  16980. @@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
  16981. #define task_pt_regs(task) \
  16982. ({ \
  16983. struct pt_regs *__regs__; \
  16984. - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
  16985. + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
  16986. __regs__ - 1; \
  16987. })
  16988. @@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
  16989. /*
  16990. * User space process size. 47bits minus one guard page.
  16991. */
  16992. -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
  16993. +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
  16994. /* This decides where the kernel will search for a free chunk of vm
  16995. * space during mmap's.
  16996. */
  16997. #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
  16998. - 0xc0000000 : 0xFFFFe000)
  16999. + 0xc0000000 : 0xFFFFf000)
  17000. #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
  17001. IA32_PAGE_OFFSET : TASK_SIZE_MAX)
  17002. @@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
  17003. #define STACK_TOP_MAX TASK_SIZE_MAX
  17004. #define INIT_THREAD { \
  17005. - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
  17006. + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
  17007. }
  17008. #define INIT_TSS { \
  17009. - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
  17010. + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
  17011. }
  17012. /*
  17013. @@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
  17014. */
  17015. #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
  17016. +#ifdef CONFIG_PAX_SEGMEXEC
  17017. +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
  17018. +#endif
  17019. +
  17020. #define KSTK_EIP(task) (task_pt_regs(task)->ip)
  17021. /* Get/set a process' ability to use the timestamp counter instruction */
  17022. @@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
  17023. return 0;
  17024. }
  17025. -extern unsigned long arch_align_stack(unsigned long sp);
  17026. +#define arch_align_stack(x) ((x) & ~0xfUL)
  17027. extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
  17028. void default_idle(void);
  17029. @@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
  17030. #define xen_set_default_idle 0
  17031. #endif
  17032. -void stop_this_cpu(void *dummy);
  17033. +void stop_this_cpu(void *dummy) __noreturn;
  17034. void df_debug(struct pt_regs *regs, long error_code);
  17035. #endif /* _ASM_X86_PROCESSOR_H */
  17036. diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
  17037. index 14fd6fd..6740420 100644
  17038. --- a/arch/x86/include/asm/ptrace.h
  17039. +++ b/arch/x86/include/asm/ptrace.h
  17040. @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
  17041. }
  17042. /*
  17043. - * user_mode_vm(regs) determines whether a register set came from user mode.
  17044. + * user_mode(regs) determines whether a register set came from user mode.
  17045. * This is true if V8086 mode was enabled OR if the register set was from
  17046. * protected mode with RPL-3 CS value. This tricky test checks that with
  17047. * one comparison. Many places in the kernel can bypass this full check
  17048. - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
  17049. + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
  17050. + * be used.
  17051. */
  17052. -static inline int user_mode(struct pt_regs *regs)
  17053. +static inline int user_mode_novm(struct pt_regs *regs)
  17054. {
  17055. #ifdef CONFIG_X86_32
  17056. return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
  17057. #else
  17058. - return !!(regs->cs & 3);
  17059. + return !!(regs->cs & SEGMENT_RPL_MASK);
  17060. #endif
  17061. }
  17062. -static inline int user_mode_vm(struct pt_regs *regs)
  17063. +static inline int user_mode(struct pt_regs *regs)
  17064. {
  17065. #ifdef CONFIG_X86_32
  17066. return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
  17067. USER_RPL;
  17068. #else
  17069. - return user_mode(regs);
  17070. + return user_mode_novm(regs);
  17071. #endif
  17072. }
  17073. @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
  17074. #ifdef CONFIG_X86_64
  17075. static inline bool user_64bit_mode(struct pt_regs *regs)
  17076. {
  17077. + unsigned long cs = regs->cs & 0xffff;
  17078. #ifndef CONFIG_PARAVIRT
  17079. /*
  17080. * On non-paravirt systems, this is the only long mode CPL 3
  17081. * selector. We do not allow long mode selectors in the LDT.
  17082. */
  17083. - return regs->cs == __USER_CS;
  17084. + return cs == __USER_CS;
  17085. #else
  17086. /* Headers are too twisted for this to go in paravirt.h. */
  17087. - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
  17088. + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
  17089. #endif
  17090. }
  17091. @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
  17092. * Traps from the kernel do not save sp and ss.
  17093. * Use the helper function to retrieve sp.
  17094. */
  17095. - if (offset == offsetof(struct pt_regs, sp) &&
  17096. - regs->cs == __KERNEL_CS)
  17097. - return kernel_stack_pointer(regs);
  17098. + if (offset == offsetof(struct pt_regs, sp)) {
  17099. + unsigned long cs = regs->cs & 0xffff;
  17100. + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
  17101. + return kernel_stack_pointer(regs);
  17102. + }
  17103. #endif
  17104. return *(unsigned long *)((unsigned long)regs + offset);
  17105. }
  17106. diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
  17107. index 9c6b890..5305f53 100644
  17108. --- a/arch/x86/include/asm/realmode.h
  17109. +++ b/arch/x86/include/asm/realmode.h
  17110. @@ -22,16 +22,14 @@ struct real_mode_header {
  17111. #endif
  17112. /* APM/BIOS reboot */
  17113. u32 machine_real_restart_asm;
  17114. -#ifdef CONFIG_X86_64
  17115. u32 machine_real_restart_seg;
  17116. -#endif
  17117. };
  17118. /* This must match data at trampoline_32/64.S */
  17119. struct trampoline_header {
  17120. #ifdef CONFIG_X86_32
  17121. u32 start;
  17122. - u16 gdt_pad;
  17123. + u16 boot_cs;
  17124. u16 gdt_limit;
  17125. u32 gdt_base;
  17126. #else
  17127. diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
  17128. index a82c4f1..ac45053 100644
  17129. --- a/arch/x86/include/asm/reboot.h
  17130. +++ b/arch/x86/include/asm/reboot.h
  17131. @@ -6,13 +6,13 @@
  17132. struct pt_regs;
  17133. struct machine_ops {
  17134. - void (*restart)(char *cmd);
  17135. - void (*halt)(void);
  17136. - void (*power_off)(void);
  17137. + void (* __noreturn restart)(char *cmd);
  17138. + void (* __noreturn halt)(void);
  17139. + void (* __noreturn power_off)(void);
  17140. void (*shutdown)(void);
  17141. void (*crash_shutdown)(struct pt_regs *);
  17142. - void (*emergency_restart)(void);
  17143. -};
  17144. + void (* __noreturn emergency_restart)(void);
  17145. +} __no_const;
  17146. extern struct machine_ops machine_ops;
  17147. diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
  17148. index 8f7866a..e442f20 100644
  17149. --- a/arch/x86/include/asm/rmwcc.h
  17150. +++ b/arch/x86/include/asm/rmwcc.h
  17151. @@ -3,7 +3,34 @@
  17152. #ifdef CC_HAVE_ASM_GOTO
  17153. -#define __GEN_RMWcc(fullop, var, cc, ...) \
  17154. +#ifdef CONFIG_PAX_REFCOUNT
  17155. +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
  17156. +do { \
  17157. + asm_volatile_goto (fullop \
  17158. + ";jno 0f\n" \
  17159. + fullantiop \
  17160. + ";int $4\n0:\n" \
  17161. + _ASM_EXTABLE(0b, 0b) \
  17162. + ";j" cc " %l[cc_label]" \
  17163. + : : "m" (var), ## __VA_ARGS__ \
  17164. + : "memory" : cc_label); \
  17165. + return 0; \
  17166. +cc_label: \
  17167. + return 1; \
  17168. +} while (0)
  17169. +#else
  17170. +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
  17171. +do { \
  17172. + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
  17173. + : : "m" (var), ## __VA_ARGS__ \
  17174. + : "memory" : cc_label); \
  17175. + return 0; \
  17176. +cc_label: \
  17177. + return 1; \
  17178. +} while (0)
  17179. +#endif
  17180. +
  17181. +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
  17182. do { \
  17183. asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
  17184. : : "m" (var), ## __VA_ARGS__ \
  17185. @@ -13,15 +40,46 @@ cc_label: \
  17186. return 1; \
  17187. } while (0)
  17188. -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
  17189. - __GEN_RMWcc(op " " arg0, var, cc)
  17190. +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
  17191. + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
  17192. -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
  17193. - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
  17194. +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
  17195. + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
  17196. +
  17197. +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
  17198. + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
  17199. +
  17200. +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
  17201. + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
  17202. #else /* !CC_HAVE_ASM_GOTO */
  17203. -#define __GEN_RMWcc(fullop, var, cc, ...) \
  17204. +#ifdef CONFIG_PAX_REFCOUNT
  17205. +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
  17206. +do { \
  17207. + char c; \
  17208. + asm volatile (fullop \
  17209. + ";jno 0f\n" \
  17210. + fullantiop \
  17211. + ";int $4\n0:\n" \
  17212. + _ASM_EXTABLE(0b, 0b) \
  17213. + "; set" cc " %1" \
  17214. + : "+m" (var), "=qm" (c) \
  17215. + : __VA_ARGS__ : "memory"); \
  17216. + return c != 0; \
  17217. +} while (0)
  17218. +#else
  17219. +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
  17220. +do { \
  17221. + char c; \
  17222. + asm volatile (fullop "; set" cc " %1" \
  17223. + : "+m" (var), "=qm" (c) \
  17224. + : __VA_ARGS__ : "memory"); \
  17225. + return c != 0; \
  17226. +} while (0)
  17227. +#endif
  17228. +
  17229. +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
  17230. do { \
  17231. char c; \
  17232. asm volatile (fullop "; set" cc " %1" \
  17233. @@ -30,11 +88,17 @@ do { \
  17234. return c != 0; \
  17235. } while (0)
  17236. -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
  17237. - __GEN_RMWcc(op " " arg0, var, cc)
  17238. +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
  17239. + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
  17240. +
  17241. +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
  17242. + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
  17243. +
  17244. +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
  17245. + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
  17246. -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
  17247. - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
  17248. +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
  17249. + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
  17250. #endif /* CC_HAVE_ASM_GOTO */
  17251. diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
  17252. index cad82c9..2e5c5c1 100644
  17253. --- a/arch/x86/include/asm/rwsem.h
  17254. +++ b/arch/x86/include/asm/rwsem.h
  17255. @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
  17256. {
  17257. asm volatile("# beginning down_read\n\t"
  17258. LOCK_PREFIX _ASM_INC "(%1)\n\t"
  17259. +
  17260. +#ifdef CONFIG_PAX_REFCOUNT
  17261. + "jno 0f\n"
  17262. + LOCK_PREFIX _ASM_DEC "(%1)\n"
  17263. + "int $4\n0:\n"
  17264. + _ASM_EXTABLE(0b, 0b)
  17265. +#endif
  17266. +
  17267. /* adds 0x00000001 */
  17268. " jns 1f\n"
  17269. " call call_rwsem_down_read_failed\n"
  17270. @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
  17271. "1:\n\t"
  17272. " mov %1,%2\n\t"
  17273. " add %3,%2\n\t"
  17274. +
  17275. +#ifdef CONFIG_PAX_REFCOUNT
  17276. + "jno 0f\n"
  17277. + "sub %3,%2\n"
  17278. + "int $4\n0:\n"
  17279. + _ASM_EXTABLE(0b, 0b)
  17280. +#endif
  17281. +
  17282. " jle 2f\n\t"
  17283. LOCK_PREFIX " cmpxchg %2,%0\n\t"
  17284. " jnz 1b\n\t"
  17285. @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
  17286. long tmp;
  17287. asm volatile("# beginning down_write\n\t"
  17288. LOCK_PREFIX " xadd %1,(%2)\n\t"
  17289. +
  17290. +#ifdef CONFIG_PAX_REFCOUNT
  17291. + "jno 0f\n"
  17292. + "mov %1,(%2)\n"
  17293. + "int $4\n0:\n"
  17294. + _ASM_EXTABLE(0b, 0b)
  17295. +#endif
  17296. +
  17297. /* adds 0xffff0001, returns the old value */
  17298. " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
  17299. /* was the active mask 0 before? */
  17300. @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
  17301. long tmp;
  17302. asm volatile("# beginning __up_read\n\t"
  17303. LOCK_PREFIX " xadd %1,(%2)\n\t"
  17304. +
  17305. +#ifdef CONFIG_PAX_REFCOUNT
  17306. + "jno 0f\n"
  17307. + "mov %1,(%2)\n"
  17308. + "int $4\n0:\n"
  17309. + _ASM_EXTABLE(0b, 0b)
  17310. +#endif
  17311. +
  17312. /* subtracts 1, returns the old value */
  17313. " jns 1f\n\t"
  17314. " call call_rwsem_wake\n" /* expects old value in %edx */
  17315. @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
  17316. long tmp;
  17317. asm volatile("# beginning __up_write\n\t"
  17318. LOCK_PREFIX " xadd %1,(%2)\n\t"
  17319. +
  17320. +#ifdef CONFIG_PAX_REFCOUNT
  17321. + "jno 0f\n"
  17322. + "mov %1,(%2)\n"
  17323. + "int $4\n0:\n"
  17324. + _ASM_EXTABLE(0b, 0b)
  17325. +#endif
  17326. +
  17327. /* subtracts 0xffff0001, returns the old value */
  17328. " jns 1f\n\t"
  17329. " call call_rwsem_wake\n" /* expects old value in %edx */
  17330. @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
  17331. {
  17332. asm volatile("# beginning __downgrade_write\n\t"
  17333. LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
  17334. +
  17335. +#ifdef CONFIG_PAX_REFCOUNT
  17336. + "jno 0f\n"
  17337. + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
  17338. + "int $4\n0:\n"
  17339. + _ASM_EXTABLE(0b, 0b)
  17340. +#endif
  17341. +
  17342. /*
  17343. * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
  17344. * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
  17345. @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
  17346. */
  17347. static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
  17348. {
  17349. - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
  17350. + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
  17351. +
  17352. +#ifdef CONFIG_PAX_REFCOUNT
  17353. + "jno 0f\n"
  17354. + LOCK_PREFIX _ASM_SUB "%1,%0\n"
  17355. + "int $4\n0:\n"
  17356. + _ASM_EXTABLE(0b, 0b)
  17357. +#endif
  17358. +
  17359. : "+m" (sem->count)
  17360. : "er" (delta));
  17361. }
  17362. @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
  17363. */
  17364. static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
  17365. {
  17366. - return delta + xadd(&sem->count, delta);
  17367. + return delta + xadd_check_overflow(&sem->count, delta);
  17368. }
  17369. #endif /* __KERNEL__ */
  17370. diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
  17371. index 6f1c3a8..7744f19 100644
  17372. --- a/arch/x86/include/asm/segment.h
  17373. +++ b/arch/x86/include/asm/segment.h
  17374. @@ -64,10 +64,15 @@
  17375. * 26 - ESPFIX small SS
  17376. * 27 - per-cpu [ offset to per-cpu data area ]
  17377. * 28 - stack_canary-20 [ for stack protector ]
  17378. - * 29 - unused
  17379. - * 30 - unused
  17380. + * 29 - PCI BIOS CS
  17381. + * 30 - PCI BIOS DS
  17382. * 31 - TSS for double fault handler
  17383. */
  17384. +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
  17385. +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
  17386. +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
  17387. +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
  17388. +
  17389. #define GDT_ENTRY_TLS_MIN 6
  17390. #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
  17391. @@ -79,6 +84,8 @@
  17392. #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
  17393. +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
  17394. +
  17395. #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
  17396. #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
  17397. @@ -104,6 +111,12 @@
  17398. #define __KERNEL_STACK_CANARY 0
  17399. #endif
  17400. +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
  17401. +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
  17402. +
  17403. +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
  17404. +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
  17405. +
  17406. #define GDT_ENTRY_DOUBLEFAULT_TSS 31
  17407. /*
  17408. @@ -141,7 +154,7 @@
  17409. */
  17410. /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
  17411. -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
  17412. +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
  17413. #else
  17414. @@ -165,6 +178,8 @@
  17415. #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
  17416. #define __USER32_DS __USER_DS
  17417. +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
  17418. +
  17419. #define GDT_ENTRY_TSS 8 /* needs two entries */
  17420. #define GDT_ENTRY_LDT 10 /* needs two entries */
  17421. #define GDT_ENTRY_TLS_MIN 12
  17422. @@ -173,6 +188,8 @@
  17423. #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
  17424. #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
  17425. +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
  17426. +
  17427. /* TLS indexes for 64bit - hardcoded in arch_prctl */
  17428. #define FS_TLS 0
  17429. #define GS_TLS 1
  17430. @@ -180,12 +197,14 @@
  17431. #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
  17432. #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
  17433. -#define GDT_ENTRIES 16
  17434. +#define GDT_ENTRIES 17
  17435. #endif
  17436. #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
  17437. +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
  17438. #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
  17439. +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
  17440. #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
  17441. #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
  17442. #ifndef CONFIG_PARAVIRT
  17443. @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
  17444. {
  17445. unsigned long __limit;
  17446. asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
  17447. - return __limit + 1;
  17448. + return __limit;
  17449. }
  17450. #endif /* !__ASSEMBLY__ */
  17451. diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
  17452. index 8d3120f..352b440 100644
  17453. --- a/arch/x86/include/asm/smap.h
  17454. +++ b/arch/x86/include/asm/smap.h
  17455. @@ -25,11 +25,40 @@
  17456. #include <asm/alternative-asm.h>
  17457. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  17458. +#define ASM_PAX_OPEN_USERLAND \
  17459. + 661: jmp 663f; \
  17460. + .pushsection .altinstr_replacement, "a" ; \
  17461. + 662: pushq %rax; nop; \
  17462. + .popsection ; \
  17463. + .pushsection .altinstructions, "a" ; \
  17464. + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
  17465. + .popsection ; \
  17466. + call __pax_open_userland; \
  17467. + popq %rax; \
  17468. + 663:
  17469. +
  17470. +#define ASM_PAX_CLOSE_USERLAND \
  17471. + 661: jmp 663f; \
  17472. + .pushsection .altinstr_replacement, "a" ; \
  17473. + 662: pushq %rax; nop; \
  17474. + .popsection; \
  17475. + .pushsection .altinstructions, "a" ; \
  17476. + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
  17477. + .popsection; \
  17478. + call __pax_close_userland; \
  17479. + popq %rax; \
  17480. + 663:
  17481. +#else
  17482. +#define ASM_PAX_OPEN_USERLAND
  17483. +#define ASM_PAX_CLOSE_USERLAND
  17484. +#endif
  17485. +
  17486. #ifdef CONFIG_X86_SMAP
  17487. #define ASM_CLAC \
  17488. 661: ASM_NOP3 ; \
  17489. - .pushsection .altinstr_replacement, "ax" ; \
  17490. + .pushsection .altinstr_replacement, "a" ; \
  17491. 662: __ASM_CLAC ; \
  17492. .popsection ; \
  17493. .pushsection .altinstructions, "a" ; \
  17494. @@ -38,7 +67,7 @@
  17495. #define ASM_STAC \
  17496. 661: ASM_NOP3 ; \
  17497. - .pushsection .altinstr_replacement, "ax" ; \
  17498. + .pushsection .altinstr_replacement, "a" ; \
  17499. 662: __ASM_STAC ; \
  17500. .popsection ; \
  17501. .pushsection .altinstructions, "a" ; \
  17502. @@ -56,6 +85,37 @@
  17503. #include <asm/alternative.h>
  17504. +#define __HAVE_ARCH_PAX_OPEN_USERLAND
  17505. +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
  17506. +
  17507. +extern void __pax_open_userland(void);
  17508. +static __always_inline unsigned long pax_open_userland(void)
  17509. +{
  17510. +
  17511. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  17512. + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
  17513. + :
  17514. + : [open] "i" (__pax_open_userland)
  17515. + : "memory", "rax");
  17516. +#endif
  17517. +
  17518. + return 0;
  17519. +}
  17520. +
  17521. +extern void __pax_close_userland(void);
  17522. +static __always_inline unsigned long pax_close_userland(void)
  17523. +{
  17524. +
  17525. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  17526. + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
  17527. + :
  17528. + : [close] "i" (__pax_close_userland)
  17529. + : "memory", "rax");
  17530. +#endif
  17531. +
  17532. + return 0;
  17533. +}
  17534. +
  17535. #ifdef CONFIG_X86_SMAP
  17536. static __always_inline void clac(void)
  17537. diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
  17538. index 8cd27e0..7f05ec8 100644
  17539. --- a/arch/x86/include/asm/smp.h
  17540. +++ b/arch/x86/include/asm/smp.h
  17541. @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
  17542. /* cpus sharing the last level cache: */
  17543. DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
  17544. DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
  17545. -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  17546. +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
  17547. static inline struct cpumask *cpu_sibling_mask(int cpu)
  17548. {
  17549. @@ -78,7 +78,7 @@ struct smp_ops {
  17550. void (*send_call_func_ipi)(const struct cpumask *mask);
  17551. void (*send_call_func_single_ipi)(int cpu);
  17552. -};
  17553. +} __no_const;
  17554. /* Globals due to paravirt */
  17555. extern void set_cpu_sibling_map(int cpu);
  17556. @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
  17557. extern int safe_smp_processor_id(void);
  17558. #elif defined(CONFIG_X86_64_SMP)
  17559. -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
  17560. -
  17561. -#define stack_smp_processor_id() \
  17562. -({ \
  17563. - struct thread_info *ti; \
  17564. - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  17565. - ti->cpu; \
  17566. -})
  17567. +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
  17568. +#define stack_smp_processor_id() raw_smp_processor_id()
  17569. #define safe_smp_processor_id() smp_processor_id()
  17570. #endif
  17571. diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
  17572. index 0f62f54..cb5d0dd 100644
  17573. --- a/arch/x86/include/asm/spinlock.h
  17574. +++ b/arch/x86/include/asm/spinlock.h
  17575. @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
  17576. static inline void arch_read_lock(arch_rwlock_t *rw)
  17577. {
  17578. asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
  17579. +
  17580. +#ifdef CONFIG_PAX_REFCOUNT
  17581. + "jno 0f\n"
  17582. + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
  17583. + "int $4\n0:\n"
  17584. + _ASM_EXTABLE(0b, 0b)
  17585. +#endif
  17586. +
  17587. "jns 1f\n"
  17588. "call __read_lock_failed\n\t"
  17589. "1:\n"
  17590. @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
  17591. static inline void arch_write_lock(arch_rwlock_t *rw)
  17592. {
  17593. asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
  17594. +
  17595. +#ifdef CONFIG_PAX_REFCOUNT
  17596. + "jno 0f\n"
  17597. + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
  17598. + "int $4\n0:\n"
  17599. + _ASM_EXTABLE(0b, 0b)
  17600. +#endif
  17601. +
  17602. "jz 1f\n"
  17603. "call __write_lock_failed\n\t"
  17604. "1:\n"
  17605. @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
  17606. static inline void arch_read_unlock(arch_rwlock_t *rw)
  17607. {
  17608. - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
  17609. + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
  17610. +
  17611. +#ifdef CONFIG_PAX_REFCOUNT
  17612. + "jno 0f\n"
  17613. + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
  17614. + "int $4\n0:\n"
  17615. + _ASM_EXTABLE(0b, 0b)
  17616. +#endif
  17617. +
  17618. :"+m" (rw->lock) : : "memory");
  17619. }
  17620. static inline void arch_write_unlock(arch_rwlock_t *rw)
  17621. {
  17622. - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
  17623. + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
  17624. +
  17625. +#ifdef CONFIG_PAX_REFCOUNT
  17626. + "jno 0f\n"
  17627. + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
  17628. + "int $4\n0:\n"
  17629. + _ASM_EXTABLE(0b, 0b)
  17630. +#endif
  17631. +
  17632. : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
  17633. }
  17634. diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
  17635. index 6a99859..03cb807 100644
  17636. --- a/arch/x86/include/asm/stackprotector.h
  17637. +++ b/arch/x86/include/asm/stackprotector.h
  17638. @@ -47,7 +47,7 @@
  17639. * head_32 for boot CPU and setup_per_cpu_areas() for others.
  17640. */
  17641. #define GDT_STACK_CANARY_INIT \
  17642. - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
  17643. + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
  17644. /*
  17645. * Initialize the stackprotector canary value.
  17646. @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
  17647. static inline void load_stack_canary_segment(void)
  17648. {
  17649. -#ifdef CONFIG_X86_32
  17650. +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
  17651. asm volatile ("mov %0, %%gs" : : "r" (0));
  17652. #endif
  17653. }
  17654. diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
  17655. index 70bbe39..4ae2bd4 100644
  17656. --- a/arch/x86/include/asm/stacktrace.h
  17657. +++ b/arch/x86/include/asm/stacktrace.h
  17658. @@ -11,28 +11,20 @@
  17659. extern int kstack_depth_to_print;
  17660. -struct thread_info;
  17661. +struct task_struct;
  17662. struct stacktrace_ops;
  17663. -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
  17664. - unsigned long *stack,
  17665. - unsigned long bp,
  17666. - const struct stacktrace_ops *ops,
  17667. - void *data,
  17668. - unsigned long *end,
  17669. - int *graph);
  17670. +typedef unsigned long walk_stack_t(struct task_struct *task,
  17671. + void *stack_start,
  17672. + unsigned long *stack,
  17673. + unsigned long bp,
  17674. + const struct stacktrace_ops *ops,
  17675. + void *data,
  17676. + unsigned long *end,
  17677. + int *graph);
  17678. -extern unsigned long
  17679. -print_context_stack(struct thread_info *tinfo,
  17680. - unsigned long *stack, unsigned long bp,
  17681. - const struct stacktrace_ops *ops, void *data,
  17682. - unsigned long *end, int *graph);
  17683. -
  17684. -extern unsigned long
  17685. -print_context_stack_bp(struct thread_info *tinfo,
  17686. - unsigned long *stack, unsigned long bp,
  17687. - const struct stacktrace_ops *ops, void *data,
  17688. - unsigned long *end, int *graph);
  17689. +extern walk_stack_t print_context_stack;
  17690. +extern walk_stack_t print_context_stack_bp;
  17691. /* Generic stack tracer with callbacks */
  17692. @@ -40,7 +32,7 @@ struct stacktrace_ops {
  17693. void (*address)(void *data, unsigned long address, int reliable);
  17694. /* On negative return stop dumping */
  17695. int (*stack)(void *data, char *name);
  17696. - walk_stack_t walk_stack;
  17697. + walk_stack_t *walk_stack;
  17698. };
  17699. void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
  17700. diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
  17701. index d7f3b3b..3cc39f1 100644
  17702. --- a/arch/x86/include/asm/switch_to.h
  17703. +++ b/arch/x86/include/asm/switch_to.h
  17704. @@ -108,7 +108,7 @@ do { \
  17705. "call __switch_to\n\t" \
  17706. "movq "__percpu_arg([current_task])",%%rsi\n\t" \
  17707. __switch_canary \
  17708. - "movq %P[thread_info](%%rsi),%%r8\n\t" \
  17709. + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
  17710. "movq %%rax,%%rdi\n\t" \
  17711. "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
  17712. "jnz ret_from_fork\n\t" \
  17713. @@ -119,7 +119,7 @@ do { \
  17714. [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
  17715. [ti_flags] "i" (offsetof(struct thread_info, flags)), \
  17716. [_tif_fork] "i" (_TIF_FORK), \
  17717. - [thread_info] "i" (offsetof(struct task_struct, stack)), \
  17718. + [thread_info] "m" (current_tinfo), \
  17719. [current_task] "m" (current_task) \
  17720. __switch_canary_iparam \
  17721. : "memory", "cc" __EXTRA_CLOBBER)
  17722. diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
  17723. index e1940c0..ac50dd8 100644
  17724. --- a/arch/x86/include/asm/thread_info.h
  17725. +++ b/arch/x86/include/asm/thread_info.h
  17726. @@ -10,6 +10,7 @@
  17727. #include <linux/compiler.h>
  17728. #include <asm/page.h>
  17729. #include <asm/types.h>
  17730. +#include <asm/percpu.h>
  17731. /*
  17732. * low level task data that entry.S needs immediate access to
  17733. @@ -23,7 +24,6 @@ struct exec_domain;
  17734. #include <linux/atomic.h>
  17735. struct thread_info {
  17736. - struct task_struct *task; /* main task structure */
  17737. struct exec_domain *exec_domain; /* execution domain */
  17738. __u32 flags; /* low level flags */
  17739. __u32 status; /* thread synchronous flags */
  17740. @@ -32,19 +32,13 @@ struct thread_info {
  17741. mm_segment_t addr_limit;
  17742. struct restart_block restart_block;
  17743. void __user *sysenter_return;
  17744. -#ifdef CONFIG_X86_32
  17745. - unsigned long previous_esp; /* ESP of the previous stack in
  17746. - case of nested (IRQ) stacks
  17747. - */
  17748. - __u8 supervisor_stack[0];
  17749. -#endif
  17750. + unsigned long lowest_stack;
  17751. unsigned int sig_on_uaccess_error:1;
  17752. unsigned int uaccess_err:1; /* uaccess failed */
  17753. };
  17754. -#define INIT_THREAD_INFO(tsk) \
  17755. +#define INIT_THREAD_INFO \
  17756. { \
  17757. - .task = &tsk, \
  17758. .exec_domain = &default_exec_domain, \
  17759. .flags = 0, \
  17760. .cpu = 0, \
  17761. @@ -55,7 +49,7 @@ struct thread_info {
  17762. }, \
  17763. }
  17764. -#define init_thread_info (init_thread_union.thread_info)
  17765. +#define init_thread_info (init_thread_union.stack)
  17766. #define init_stack (init_thread_union.stack)
  17767. #else /* !__ASSEMBLY__ */
  17768. @@ -95,6 +89,7 @@ struct thread_info {
  17769. #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
  17770. #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
  17771. #define TIF_X32 30 /* 32-bit native x86-64 binary */
  17772. +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
  17773. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  17774. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  17775. @@ -118,17 +113,18 @@ struct thread_info {
  17776. #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
  17777. #define _TIF_ADDR32 (1 << TIF_ADDR32)
  17778. #define _TIF_X32 (1 << TIF_X32)
  17779. +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
  17780. /* work to do in syscall_trace_enter() */
  17781. #define _TIF_WORK_SYSCALL_ENTRY \
  17782. (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
  17783. _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
  17784. - _TIF_NOHZ)
  17785. + _TIF_NOHZ | _TIF_GRSEC_SETXID)
  17786. /* work to do in syscall_trace_leave() */
  17787. #define _TIF_WORK_SYSCALL_EXIT \
  17788. (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
  17789. - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
  17790. + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
  17791. /* work to do on interrupt/exception return */
  17792. #define _TIF_WORK_MASK \
  17793. @@ -139,7 +135,7 @@ struct thread_info {
  17794. /* work to do on any return to user space */
  17795. #define _TIF_ALLWORK_MASK \
  17796. ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
  17797. - _TIF_NOHZ)
  17798. + _TIF_NOHZ | _TIF_GRSEC_SETXID)
  17799. /* Only used for 64 bit */
  17800. #define _TIF_DO_NOTIFY_MASK \
  17801. @@ -153,6 +149,23 @@ struct thread_info {
  17802. #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
  17803. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
  17804. +#ifdef __ASSEMBLY__
  17805. +/* how to get the thread information struct from ASM */
  17806. +#define GET_THREAD_INFO(reg) \
  17807. + mov PER_CPU_VAR(current_tinfo), reg
  17808. +
  17809. +/* use this one if reg already contains %esp */
  17810. +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
  17811. +#else
  17812. +/* how to get the thread information struct from C */
  17813. +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
  17814. +
  17815. +static __always_inline struct thread_info *current_thread_info(void)
  17816. +{
  17817. + return this_cpu_read_stable(current_tinfo);
  17818. +}
  17819. +#endif
  17820. +
  17821. #ifdef CONFIG_X86_32
  17822. #define STACK_WARN (THREAD_SIZE/8)
  17823. @@ -169,31 +182,10 @@ struct thread_info {
  17824. sp; \
  17825. })
  17826. -/* how to get the thread information struct from C */
  17827. -static inline struct thread_info *current_thread_info(void)
  17828. -{
  17829. - return (struct thread_info *)
  17830. - (current_stack_pointer & ~(THREAD_SIZE - 1));
  17831. -}
  17832. -
  17833. -#else /* !__ASSEMBLY__ */
  17834. -
  17835. -/* how to get the thread information struct from ASM */
  17836. -#define GET_THREAD_INFO(reg) \
  17837. - movl $-THREAD_SIZE, reg; \
  17838. - andl %esp, reg
  17839. -
  17840. -/* use this one if reg already contains %esp */
  17841. -#define GET_THREAD_INFO_WITH_ESP(reg) \
  17842. - andl $-THREAD_SIZE, reg
  17843. -
  17844. #endif
  17845. #else /* X86_32 */
  17846. -#include <asm/percpu.h>
  17847. -#define KERNEL_STACK_OFFSET (5*8)
  17848. -
  17849. /*
  17850. * macros/functions for gaining access to the thread information structure
  17851. * preempt_count needs to be 1 initially, until the scheduler is functional.
  17852. @@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
  17853. #ifndef __ASSEMBLY__
  17854. DECLARE_PER_CPU(unsigned long, kernel_stack);
  17855. -static inline struct thread_info *current_thread_info(void)
  17856. -{
  17857. - struct thread_info *ti;
  17858. - ti = (void *)(this_cpu_read_stable(kernel_stack) +
  17859. - KERNEL_STACK_OFFSET - THREAD_SIZE);
  17860. - return ti;
  17861. -}
  17862. -
  17863. -#else /* !__ASSEMBLY__ */
  17864. -
  17865. -/* how to get the thread information struct from ASM */
  17866. -#define GET_THREAD_INFO(reg) \
  17867. - movq PER_CPU_VAR(kernel_stack),reg ; \
  17868. - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
  17869. -
  17870. -/*
  17871. - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
  17872. - * a certain register (to be used in assembler memory operands).
  17873. - */
  17874. -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
  17875. -
  17876. +/* how to get the current stack pointer from C */
  17877. +register unsigned long current_stack_pointer asm("rsp") __used;
  17878. #endif
  17879. #endif /* !X86_32 */
  17880. @@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
  17881. extern void arch_task_cache_init(void);
  17882. extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  17883. extern void arch_release_task_struct(struct task_struct *tsk);
  17884. +
  17885. +#define __HAVE_THREAD_FUNCTIONS
  17886. +#define task_thread_info(task) (&(task)->tinfo)
  17887. +#define task_stack_page(task) ((task)->stack)
  17888. +#define setup_thread_stack(p, org) do {} while (0)
  17889. +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
  17890. +
  17891. #endif
  17892. #endif /* _ASM_X86_THREAD_INFO_H */
  17893. diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
  17894. index 04905bf..49203ca 100644
  17895. --- a/arch/x86/include/asm/tlbflush.h
  17896. +++ b/arch/x86/include/asm/tlbflush.h
  17897. @@ -17,18 +17,44 @@
  17898. static inline void __native_flush_tlb(void)
  17899. {
  17900. + if (static_cpu_has(X86_FEATURE_INVPCID)) {
  17901. + u64 descriptor[2];
  17902. +
  17903. + descriptor[0] = PCID_KERNEL;
  17904. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
  17905. + return;
  17906. + }
  17907. +
  17908. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  17909. + if (static_cpu_has(X86_FEATURE_PCID)) {
  17910. + unsigned int cpu = raw_get_cpu();
  17911. +
  17912. + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
  17913. + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
  17914. + raw_put_cpu_no_resched();
  17915. + return;
  17916. + }
  17917. +#endif
  17918. +
  17919. native_write_cr3(native_read_cr3());
  17920. }
  17921. static inline void __native_flush_tlb_global_irq_disabled(void)
  17922. {
  17923. - unsigned long cr4;
  17924. + if (static_cpu_has(X86_FEATURE_INVPCID)) {
  17925. + u64 descriptor[2];
  17926. - cr4 = native_read_cr4();
  17927. - /* clear PGE */
  17928. - native_write_cr4(cr4 & ~X86_CR4_PGE);
  17929. - /* write old PGE again and flush TLBs */
  17930. - native_write_cr4(cr4);
  17931. + descriptor[0] = PCID_KERNEL;
  17932. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
  17933. + } else {
  17934. + unsigned long cr4;
  17935. +
  17936. + cr4 = native_read_cr4();
  17937. + /* clear PGE */
  17938. + native_write_cr4(cr4 & ~X86_CR4_PGE);
  17939. + /* write old PGE again and flush TLBs */
  17940. + native_write_cr4(cr4);
  17941. + }
  17942. }
  17943. static inline void __native_flush_tlb_global(void)
  17944. @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
  17945. static inline void __native_flush_tlb_single(unsigned long addr)
  17946. {
  17947. + if (static_cpu_has(X86_FEATURE_INVPCID)) {
  17948. + u64 descriptor[2];
  17949. +
  17950. + descriptor[0] = PCID_KERNEL;
  17951. + descriptor[1] = addr;
  17952. +
  17953. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  17954. + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
  17955. + if (addr < TASK_SIZE_MAX)
  17956. + descriptor[1] += pax_user_shadow_base;
  17957. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
  17958. + }
  17959. +
  17960. + descriptor[0] = PCID_USER;
  17961. + descriptor[1] = addr;
  17962. +#endif
  17963. +
  17964. + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
  17965. + return;
  17966. + }
  17967. +
  17968. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  17969. + if (static_cpu_has(X86_FEATURE_PCID)) {
  17970. + unsigned int cpu = raw_get_cpu();
  17971. +
  17972. + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
  17973. + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
  17974. + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
  17975. + raw_put_cpu_no_resched();
  17976. +
  17977. + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
  17978. + addr += pax_user_shadow_base;
  17979. + }
  17980. +#endif
  17981. +
  17982. asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
  17983. }
  17984. diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
  17985. index 0d592e0..f58a222 100644
  17986. --- a/arch/x86/include/asm/uaccess.h
  17987. +++ b/arch/x86/include/asm/uaccess.h
  17988. @@ -7,6 +7,7 @@
  17989. #include <linux/compiler.h>
  17990. #include <linux/thread_info.h>
  17991. #include <linux/string.h>
  17992. +#include <linux/spinlock.h>
  17993. #include <asm/asm.h>
  17994. #include <asm/page.h>
  17995. #include <asm/smap.h>
  17996. @@ -29,7 +30,12 @@
  17997. #define get_ds() (KERNEL_DS)
  17998. #define get_fs() (current_thread_info()->addr_limit)
  17999. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
  18000. +void __set_fs(mm_segment_t x);
  18001. +void set_fs(mm_segment_t x);
  18002. +#else
  18003. #define set_fs(x) (current_thread_info()->addr_limit = (x))
  18004. +#endif
  18005. #define segment_eq(a, b) ((a).seg == (b).seg)
  18006. @@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
  18007. * checks that the pointer is in the user space range - after calling
  18008. * this function, memory access functions may still return -EFAULT.
  18009. */
  18010. -#define access_ok(type, addr, size) \
  18011. - likely(!__range_not_ok(addr, size, user_addr_max()))
  18012. +extern int _cond_resched(void);
  18013. +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
  18014. +#define access_ok(type, addr, size) \
  18015. +({ \
  18016. + long __size = size; \
  18017. + unsigned long __addr = (unsigned long)addr; \
  18018. + unsigned long __addr_ao = __addr & PAGE_MASK; \
  18019. + unsigned long __end_ao = __addr + __size - 1; \
  18020. + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
  18021. + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
  18022. + while(__addr_ao <= __end_ao) { \
  18023. + char __c_ao; \
  18024. + __addr_ao += PAGE_SIZE; \
  18025. + if (__size > PAGE_SIZE) \
  18026. + _cond_resched(); \
  18027. + if (__get_user(__c_ao, (char __user *)__addr)) \
  18028. + break; \
  18029. + if (type != VERIFY_WRITE) { \
  18030. + __addr = __addr_ao; \
  18031. + continue; \
  18032. + } \
  18033. + if (__put_user(__c_ao, (char __user *)__addr)) \
  18034. + break; \
  18035. + __addr = __addr_ao; \
  18036. + } \
  18037. + } \
  18038. + __ret_ao; \
  18039. +})
  18040. /*
  18041. * The exception table consists of pairs of addresses relative to the
  18042. @@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
  18043. register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
  18044. __chk_user_ptr(ptr); \
  18045. might_fault(); \
  18046. + pax_open_userland(); \
  18047. asm volatile("call __get_user_%P3" \
  18048. : "=a" (__ret_gu), "=r" (__val_gu) \
  18049. : "0" (ptr), "i" (sizeof(*(ptr)))); \
  18050. (x) = (__typeof__(*(ptr))) __val_gu; \
  18051. + pax_close_userland(); \
  18052. __ret_gu; \
  18053. })
  18054. @@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
  18055. asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
  18056. : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
  18057. -
  18058. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
  18059. +#define __copyuser_seg "gs;"
  18060. +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
  18061. +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
  18062. +#else
  18063. +#define __copyuser_seg
  18064. +#define __COPYUSER_SET_ES
  18065. +#define __COPYUSER_RESTORE_ES
  18066. +#endif
  18067. #ifdef CONFIG_X86_32
  18068. #define __put_user_asm_u64(x, addr, err, errret) \
  18069. asm volatile(ASM_STAC "\n" \
  18070. - "1: movl %%eax,0(%2)\n" \
  18071. - "2: movl %%edx,4(%2)\n" \
  18072. + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
  18073. + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
  18074. "3: " ASM_CLAC "\n" \
  18075. ".section .fixup,\"ax\"\n" \
  18076. "4: movl %3,%0\n" \
  18077. @@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
  18078. #define __put_user_asm_ex_u64(x, addr) \
  18079. asm volatile(ASM_STAC "\n" \
  18080. - "1: movl %%eax,0(%1)\n" \
  18081. - "2: movl %%edx,4(%1)\n" \
  18082. + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
  18083. + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
  18084. "3: " ASM_CLAC "\n" \
  18085. _ASM_EXTABLE_EX(1b, 2b) \
  18086. _ASM_EXTABLE_EX(2b, 3b) \
  18087. @@ -257,7 +299,8 @@ extern void __put_user_8(void);
  18088. __typeof__(*(ptr)) __pu_val; \
  18089. __chk_user_ptr(ptr); \
  18090. might_fault(); \
  18091. - __pu_val = x; \
  18092. + __pu_val = (x); \
  18093. + pax_open_userland(); \
  18094. switch (sizeof(*(ptr))) { \
  18095. case 1: \
  18096. __put_user_x(1, __pu_val, ptr, __ret_pu); \
  18097. @@ -275,6 +318,7 @@ extern void __put_user_8(void);
  18098. __put_user_x(X, __pu_val, ptr, __ret_pu); \
  18099. break; \
  18100. } \
  18101. + pax_close_userland(); \
  18102. __ret_pu; \
  18103. })
  18104. @@ -355,8 +399,10 @@ do { \
  18105. } while (0)
  18106. #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
  18107. +do { \
  18108. + pax_open_userland(); \
  18109. asm volatile(ASM_STAC "\n" \
  18110. - "1: mov"itype" %2,%"rtype"1\n" \
  18111. + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
  18112. "2: " ASM_CLAC "\n" \
  18113. ".section .fixup,\"ax\"\n" \
  18114. "3: mov %3,%0\n" \
  18115. @@ -364,8 +410,10 @@ do { \
  18116. " jmp 2b\n" \
  18117. ".previous\n" \
  18118. _ASM_EXTABLE(1b, 3b) \
  18119. - : "=r" (err), ltype(x) \
  18120. - : "m" (__m(addr)), "i" (errret), "0" (err))
  18121. + : "=r" (err), ltype (x) \
  18122. + : "m" (__m(addr)), "i" (errret), "0" (err)); \
  18123. + pax_close_userland(); \
  18124. +} while (0)
  18125. #define __get_user_size_ex(x, ptr, size) \
  18126. do { \
  18127. @@ -389,7 +437,7 @@ do { \
  18128. } while (0)
  18129. #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
  18130. - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
  18131. + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
  18132. "2:\n" \
  18133. _ASM_EXTABLE_EX(1b, 2b) \
  18134. : ltype(x) : "m" (__m(addr)))
  18135. @@ -406,13 +454,24 @@ do { \
  18136. int __gu_err; \
  18137. unsigned long __gu_val; \
  18138. __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
  18139. - (x) = (__force __typeof__(*(ptr)))__gu_val; \
  18140. + (x) = (__typeof__(*(ptr)))__gu_val; \
  18141. __gu_err; \
  18142. })
  18143. /* FIXME: this hack is definitely wrong -AK */
  18144. struct __large_struct { unsigned long buf[100]; };
  18145. -#define __m(x) (*(struct __large_struct __user *)(x))
  18146. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  18147. +#define ____m(x) \
  18148. +({ \
  18149. + unsigned long ____x = (unsigned long)(x); \
  18150. + if (____x < pax_user_shadow_base) \
  18151. + ____x += pax_user_shadow_base; \
  18152. + (typeof(x))____x; \
  18153. +})
  18154. +#else
  18155. +#define ____m(x) (x)
  18156. +#endif
  18157. +#define __m(x) (*(struct __large_struct __user *)____m(x))
  18158. /*
  18159. * Tell gcc we read from memory instead of writing: this is because
  18160. @@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
  18161. * aliasing issues.
  18162. */
  18163. #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
  18164. +do { \
  18165. + pax_open_userland(); \
  18166. asm volatile(ASM_STAC "\n" \
  18167. - "1: mov"itype" %"rtype"1,%2\n" \
  18168. + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
  18169. "2: " ASM_CLAC "\n" \
  18170. ".section .fixup,\"ax\"\n" \
  18171. "3: mov %3,%0\n" \
  18172. @@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
  18173. ".previous\n" \
  18174. _ASM_EXTABLE(1b, 3b) \
  18175. : "=r"(err) \
  18176. - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
  18177. + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
  18178. + pax_close_userland(); \
  18179. +} while (0)
  18180. #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
  18181. - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
  18182. + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
  18183. "2:\n" \
  18184. _ASM_EXTABLE_EX(1b, 2b) \
  18185. : : ltype(x), "m" (__m(addr)))
  18186. @@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
  18187. */
  18188. #define uaccess_try do { \
  18189. current_thread_info()->uaccess_err = 0; \
  18190. + pax_open_userland(); \
  18191. stac(); \
  18192. barrier();
  18193. #define uaccess_catch(err) \
  18194. clac(); \
  18195. + pax_close_userland(); \
  18196. (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
  18197. } while (0)
  18198. @@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
  18199. * On error, the variable @x is set to zero.
  18200. */
  18201. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  18202. +#define __get_user(x, ptr) get_user((x), (ptr))
  18203. +#else
  18204. #define __get_user(x, ptr) \
  18205. __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
  18206. +#endif
  18207. /**
  18208. * __put_user: - Write a simple value into user space, with less checking.
  18209. @@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
  18210. * Returns zero on success, or -EFAULT on error.
  18211. */
  18212. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  18213. +#define __put_user(x, ptr) put_user((x), (ptr))
  18214. +#else
  18215. #define __put_user(x, ptr) \
  18216. __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
  18217. +#endif
  18218. #define __get_user_unaligned __get_user
  18219. #define __put_user_unaligned __put_user
  18220. @@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
  18221. #define get_user_ex(x, ptr) do { \
  18222. unsigned long __gue_val; \
  18223. __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
  18224. - (x) = (__force __typeof__(*(ptr)))__gue_val; \
  18225. + (x) = (__typeof__(*(ptr)))__gue_val; \
  18226. } while (0)
  18227. #define put_user_try uaccess_try
  18228. @@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
  18229. __typeof__(ptr) __uval = (uval); \
  18230. __typeof__(*(ptr)) __old = (old); \
  18231. __typeof__(*(ptr)) __new = (new); \
  18232. + pax_open_userland(); \
  18233. switch (size) { \
  18234. case 1: \
  18235. { \
  18236. asm volatile("\t" ASM_STAC "\n" \
  18237. - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
  18238. + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
  18239. "2:\t" ASM_CLAC "\n" \
  18240. "\t.section .fixup, \"ax\"\n" \
  18241. "3:\tmov %3, %0\n" \
  18242. "\tjmp 2b\n" \
  18243. "\t.previous\n" \
  18244. _ASM_EXTABLE(1b, 3b) \
  18245. - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
  18246. + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
  18247. : "i" (-EFAULT), "q" (__new), "1" (__old) \
  18248. : "memory" \
  18249. ); \
  18250. @@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
  18251. case 2: \
  18252. { \
  18253. asm volatile("\t" ASM_STAC "\n" \
  18254. - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
  18255. + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
  18256. "2:\t" ASM_CLAC "\n" \
  18257. "\t.section .fixup, \"ax\"\n" \
  18258. "3:\tmov %3, %0\n" \
  18259. "\tjmp 2b\n" \
  18260. "\t.previous\n" \
  18261. _ASM_EXTABLE(1b, 3b) \
  18262. - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
  18263. + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
  18264. : "i" (-EFAULT), "r" (__new), "1" (__old) \
  18265. : "memory" \
  18266. ); \
  18267. @@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
  18268. case 4: \
  18269. { \
  18270. asm volatile("\t" ASM_STAC "\n" \
  18271. - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
  18272. + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
  18273. "2:\t" ASM_CLAC "\n" \
  18274. "\t.section .fixup, \"ax\"\n" \
  18275. "3:\tmov %3, %0\n" \
  18276. "\tjmp 2b\n" \
  18277. "\t.previous\n" \
  18278. _ASM_EXTABLE(1b, 3b) \
  18279. - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
  18280. + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
  18281. : "i" (-EFAULT), "r" (__new), "1" (__old) \
  18282. : "memory" \
  18283. ); \
  18284. @@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
  18285. __cmpxchg_wrong_size(); \
  18286. \
  18287. asm volatile("\t" ASM_STAC "\n" \
  18288. - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
  18289. + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
  18290. "2:\t" ASM_CLAC "\n" \
  18291. "\t.section .fixup, \"ax\"\n" \
  18292. "3:\tmov %3, %0\n" \
  18293. "\tjmp 2b\n" \
  18294. "\t.previous\n" \
  18295. _ASM_EXTABLE(1b, 3b) \
  18296. - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
  18297. + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
  18298. : "i" (-EFAULT), "r" (__new), "1" (__old) \
  18299. : "memory" \
  18300. ); \
  18301. @@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
  18302. default: \
  18303. __cmpxchg_wrong_size(); \
  18304. } \
  18305. + pax_close_userland(); \
  18306. *__uval = __old; \
  18307. __ret; \
  18308. })
  18309. @@ -636,17 +711,6 @@ extern struct movsl_mask {
  18310. #define ARCH_HAS_NOCACHE_UACCESS 1
  18311. -#ifdef CONFIG_X86_32
  18312. -# include <asm/uaccess_32.h>
  18313. -#else
  18314. -# include <asm/uaccess_64.h>
  18315. -#endif
  18316. -
  18317. -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
  18318. - unsigned n);
  18319. -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
  18320. - unsigned n);
  18321. -
  18322. #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
  18323. # define copy_user_diag __compiletime_error
  18324. #else
  18325. @@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
  18326. extern void copy_user_diag("copy_from_user() buffer size is too small")
  18327. copy_from_user_overflow(void);
  18328. extern void copy_user_diag("copy_to_user() buffer size is too small")
  18329. -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
  18330. +copy_to_user_overflow(void);
  18331. #undef copy_user_diag
  18332. @@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
  18333. extern void
  18334. __compiletime_warning("copy_to_user() buffer size is not provably correct")
  18335. -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
  18336. +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
  18337. #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
  18338. #else
  18339. @@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
  18340. #endif
  18341. +#ifdef CONFIG_X86_32
  18342. +# include <asm/uaccess_32.h>
  18343. +#else
  18344. +# include <asm/uaccess_64.h>
  18345. +#endif
  18346. +
  18347. static inline unsigned long __must_check
  18348. copy_from_user(void *to, const void __user *from, unsigned long n)
  18349. {
  18350. - int sz = __compiletime_object_size(to);
  18351. + size_t sz = __compiletime_object_size(to);
  18352. might_fault();
  18353. @@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
  18354. * case, and do only runtime checking for non-constant sizes.
  18355. */
  18356. - if (likely(sz < 0 || sz >= n))
  18357. - n = _copy_from_user(to, from, n);
  18358. - else if(__builtin_constant_p(n))
  18359. - copy_from_user_overflow();
  18360. - else
  18361. - __copy_from_user_overflow(sz, n);
  18362. + if (likely(sz != (size_t)-1 && sz < n)) {
  18363. + if(__builtin_constant_p(n))
  18364. + copy_from_user_overflow();
  18365. + else
  18366. + __copy_from_user_overflow(sz, n);
  18367. + } if (access_ok(VERIFY_READ, from, n))
  18368. + n = __copy_from_user(to, from, n);
  18369. + else if ((long)n > 0)
  18370. + memset(to, 0, n);
  18371. return n;
  18372. }
  18373. @@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
  18374. static inline unsigned long __must_check
  18375. copy_to_user(void __user *to, const void *from, unsigned long n)
  18376. {
  18377. - int sz = __compiletime_object_size(from);
  18378. + size_t sz = __compiletime_object_size(from);
  18379. might_fault();
  18380. /* See the comment in copy_from_user() above. */
  18381. - if (likely(sz < 0 || sz >= n))
  18382. - n = _copy_to_user(to, from, n);
  18383. - else if(__builtin_constant_p(n))
  18384. - copy_to_user_overflow();
  18385. - else
  18386. - __copy_to_user_overflow(sz, n);
  18387. + if (likely(sz != (size_t)-1 && sz < n)) {
  18388. + if(__builtin_constant_p(n))
  18389. + copy_to_user_overflow();
  18390. + else
  18391. + __copy_to_user_overflow(sz, n);
  18392. + } else if (access_ok(VERIFY_WRITE, to, n))
  18393. + n = __copy_to_user(to, from, n);
  18394. return n;
  18395. }
  18396. diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
  18397. index 3c03a5d..1071638 100644
  18398. --- a/arch/x86/include/asm/uaccess_32.h
  18399. +++ b/arch/x86/include/asm/uaccess_32.h
  18400. @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
  18401. static __always_inline unsigned long __must_check
  18402. __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
  18403. {
  18404. + if ((long)n < 0)
  18405. + return n;
  18406. +
  18407. + check_object_size(from, n, true);
  18408. +
  18409. if (__builtin_constant_p(n)) {
  18410. unsigned long ret;
  18411. @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
  18412. __copy_to_user(void __user *to, const void *from, unsigned long n)
  18413. {
  18414. might_fault();
  18415. +
  18416. return __copy_to_user_inatomic(to, from, n);
  18417. }
  18418. static __always_inline unsigned long
  18419. __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
  18420. {
  18421. + if ((long)n < 0)
  18422. + return n;
  18423. +
  18424. /* Avoid zeroing the tail if the copy fails..
  18425. * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
  18426. * but as the zeroing behaviour is only significant when n is not
  18427. @@ -137,6 +146,12 @@ static __always_inline unsigned long
  18428. __copy_from_user(void *to, const void __user *from, unsigned long n)
  18429. {
  18430. might_fault();
  18431. +
  18432. + if ((long)n < 0)
  18433. + return n;
  18434. +
  18435. + check_object_size(to, n, false);
  18436. +
  18437. if (__builtin_constant_p(n)) {
  18438. unsigned long ret;
  18439. @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
  18440. const void __user *from, unsigned long n)
  18441. {
  18442. might_fault();
  18443. +
  18444. + if ((long)n < 0)
  18445. + return n;
  18446. +
  18447. if (__builtin_constant_p(n)) {
  18448. unsigned long ret;
  18449. @@ -181,7 +200,10 @@ static __always_inline unsigned long
  18450. __copy_from_user_inatomic_nocache(void *to, const void __user *from,
  18451. unsigned long n)
  18452. {
  18453. - return __copy_from_user_ll_nocache_nozero(to, from, n);
  18454. + if ((long)n < 0)
  18455. + return n;
  18456. +
  18457. + return __copy_from_user_ll_nocache_nozero(to, from, n);
  18458. }
  18459. #endif /* _ASM_X86_UACCESS_32_H */
  18460. diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
  18461. index 12a26b9..206c200 100644
  18462. --- a/arch/x86/include/asm/uaccess_64.h
  18463. +++ b/arch/x86/include/asm/uaccess_64.h
  18464. @@ -10,6 +10,9 @@
  18465. #include <asm/alternative.h>
  18466. #include <asm/cpufeature.h>
  18467. #include <asm/page.h>
  18468. +#include <asm/pgtable.h>
  18469. +
  18470. +#define set_fs(x) (current_thread_info()->addr_limit = (x))
  18471. /*
  18472. * Copy To/From Userspace
  18473. @@ -17,14 +20,14 @@
  18474. /* Handles exceptions in both to and from, but doesn't do access_ok */
  18475. __must_check unsigned long
  18476. -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
  18477. +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
  18478. __must_check unsigned long
  18479. -copy_user_generic_string(void *to, const void *from, unsigned len);
  18480. +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
  18481. __must_check unsigned long
  18482. -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
  18483. +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
  18484. static __always_inline __must_check unsigned long
  18485. -copy_user_generic(void *to, const void *from, unsigned len)
  18486. +copy_user_generic(void *to, const void *from, unsigned long len)
  18487. {
  18488. unsigned ret;
  18489. @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
  18490. }
  18491. __must_check unsigned long
  18492. -copy_in_user(void __user *to, const void __user *from, unsigned len);
  18493. +copy_in_user(void __user *to, const void __user *from, unsigned long len);
  18494. static __always_inline __must_check
  18495. -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
  18496. +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
  18497. {
  18498. - int ret = 0;
  18499. + size_t sz = __compiletime_object_size(dst);
  18500. + unsigned ret = 0;
  18501. +
  18502. + if (size > INT_MAX)
  18503. + return size;
  18504. +
  18505. + check_object_size(dst, size, false);
  18506. +
  18507. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  18508. + if (!access_ok_noprefault(VERIFY_READ, src, size))
  18509. + return size;
  18510. +#endif
  18511. +
  18512. + if (unlikely(sz != (size_t)-1 && sz < size)) {
  18513. + if(__builtin_constant_p(size))
  18514. + copy_from_user_overflow();
  18515. + else
  18516. + __copy_from_user_overflow(sz, size);
  18517. + return size;
  18518. + }
  18519. if (!__builtin_constant_p(size))
  18520. - return copy_user_generic(dst, (__force void *)src, size);
  18521. + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
  18522. switch (size) {
  18523. - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
  18524. + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
  18525. ret, "b", "b", "=q", 1);
  18526. return ret;
  18527. - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
  18528. + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
  18529. ret, "w", "w", "=r", 2);
  18530. return ret;
  18531. - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
  18532. + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
  18533. ret, "l", "k", "=r", 4);
  18534. return ret;
  18535. - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
  18536. + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
  18537. ret, "q", "", "=r", 8);
  18538. return ret;
  18539. case 10:
  18540. - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
  18541. + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
  18542. ret, "q", "", "=r", 10);
  18543. if (unlikely(ret))
  18544. return ret;
  18545. __get_user_asm(*(u16 *)(8 + (char *)dst),
  18546. - (u16 __user *)(8 + (char __user *)src),
  18547. + (const u16 __user *)(8 + (const char __user *)src),
  18548. ret, "w", "w", "=r", 2);
  18549. return ret;
  18550. case 16:
  18551. - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
  18552. + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
  18553. ret, "q", "", "=r", 16);
  18554. if (unlikely(ret))
  18555. return ret;
  18556. __get_user_asm(*(u64 *)(8 + (char *)dst),
  18557. - (u64 __user *)(8 + (char __user *)src),
  18558. + (const u64 __user *)(8 + (const char __user *)src),
  18559. ret, "q", "", "=r", 8);
  18560. return ret;
  18561. default:
  18562. - return copy_user_generic(dst, (__force void *)src, size);
  18563. + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
  18564. }
  18565. }
  18566. static __always_inline __must_check
  18567. -int __copy_from_user(void *dst, const void __user *src, unsigned size)
  18568. +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
  18569. {
  18570. might_fault();
  18571. return __copy_from_user_nocheck(dst, src, size);
  18572. }
  18573. static __always_inline __must_check
  18574. -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
  18575. +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
  18576. {
  18577. - int ret = 0;
  18578. + size_t sz = __compiletime_object_size(src);
  18579. + unsigned ret = 0;
  18580. +
  18581. + if (size > INT_MAX)
  18582. + return size;
  18583. +
  18584. + check_object_size(src, size, true);
  18585. +
  18586. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  18587. + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
  18588. + return size;
  18589. +#endif
  18590. +
  18591. + if (unlikely(sz != (size_t)-1 && sz < size)) {
  18592. + if(__builtin_constant_p(size))
  18593. + copy_to_user_overflow();
  18594. + else
  18595. + __copy_to_user_overflow(sz, size);
  18596. + return size;
  18597. + }
  18598. if (!__builtin_constant_p(size))
  18599. - return copy_user_generic((__force void *)dst, src, size);
  18600. + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
  18601. switch (size) {
  18602. - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
  18603. + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
  18604. ret, "b", "b", "iq", 1);
  18605. return ret;
  18606. - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
  18607. + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
  18608. ret, "w", "w", "ir", 2);
  18609. return ret;
  18610. - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
  18611. + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
  18612. ret, "l", "k", "ir", 4);
  18613. return ret;
  18614. - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
  18615. + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
  18616. ret, "q", "", "er", 8);
  18617. return ret;
  18618. case 10:
  18619. - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
  18620. + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
  18621. ret, "q", "", "er", 10);
  18622. if (unlikely(ret))
  18623. return ret;
  18624. asm("":::"memory");
  18625. - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
  18626. + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
  18627. ret, "w", "w", "ir", 2);
  18628. return ret;
  18629. case 16:
  18630. - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
  18631. + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
  18632. ret, "q", "", "er", 16);
  18633. if (unlikely(ret))
  18634. return ret;
  18635. asm("":::"memory");
  18636. - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
  18637. + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
  18638. ret, "q", "", "er", 8);
  18639. return ret;
  18640. default:
  18641. - return copy_user_generic((__force void *)dst, src, size);
  18642. + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
  18643. }
  18644. }
  18645. static __always_inline __must_check
  18646. -int __copy_to_user(void __user *dst, const void *src, unsigned size)
  18647. +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
  18648. {
  18649. might_fault();
  18650. return __copy_to_user_nocheck(dst, src, size);
  18651. }
  18652. static __always_inline __must_check
  18653. -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
  18654. +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
  18655. {
  18656. - int ret = 0;
  18657. + unsigned ret = 0;
  18658. might_fault();
  18659. +
  18660. + if (size > INT_MAX)
  18661. + return size;
  18662. +
  18663. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  18664. + if (!access_ok_noprefault(VERIFY_READ, src, size))
  18665. + return size;
  18666. + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
  18667. + return size;
  18668. +#endif
  18669. +
  18670. if (!__builtin_constant_p(size))
  18671. - return copy_user_generic((__force void *)dst,
  18672. - (__force void *)src, size);
  18673. + return copy_user_generic((__force_kernel void *)____m(dst),
  18674. + (__force_kernel const void *)____m(src), size);
  18675. switch (size) {
  18676. case 1: {
  18677. u8 tmp;
  18678. - __get_user_asm(tmp, (u8 __user *)src,
  18679. + __get_user_asm(tmp, (const u8 __user *)src,
  18680. ret, "b", "b", "=q", 1);
  18681. if (likely(!ret))
  18682. __put_user_asm(tmp, (u8 __user *)dst,
  18683. @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
  18684. }
  18685. case 2: {
  18686. u16 tmp;
  18687. - __get_user_asm(tmp, (u16 __user *)src,
  18688. + __get_user_asm(tmp, (const u16 __user *)src,
  18689. ret, "w", "w", "=r", 2);
  18690. if (likely(!ret))
  18691. __put_user_asm(tmp, (u16 __user *)dst,
  18692. @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
  18693. case 4: {
  18694. u32 tmp;
  18695. - __get_user_asm(tmp, (u32 __user *)src,
  18696. + __get_user_asm(tmp, (const u32 __user *)src,
  18697. ret, "l", "k", "=r", 4);
  18698. if (likely(!ret))
  18699. __put_user_asm(tmp, (u32 __user *)dst,
  18700. @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
  18701. }
  18702. case 8: {
  18703. u64 tmp;
  18704. - __get_user_asm(tmp, (u64 __user *)src,
  18705. + __get_user_asm(tmp, (const u64 __user *)src,
  18706. ret, "q", "", "=r", 8);
  18707. if (likely(!ret))
  18708. __put_user_asm(tmp, (u64 __user *)dst,
  18709. @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
  18710. return ret;
  18711. }
  18712. default:
  18713. - return copy_user_generic((__force void *)dst,
  18714. - (__force void *)src, size);
  18715. + return copy_user_generic((__force_kernel void *)____m(dst),
  18716. + (__force_kernel const void *)____m(src), size);
  18717. }
  18718. }
  18719. -static __must_check __always_inline int
  18720. -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
  18721. +static __must_check __always_inline unsigned long
  18722. +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
  18723. {
  18724. return __copy_from_user_nocheck(dst, src, size);
  18725. }
  18726. -static __must_check __always_inline int
  18727. -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
  18728. +static __must_check __always_inline unsigned long
  18729. +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
  18730. {
  18731. return __copy_to_user_nocheck(dst, src, size);
  18732. }
  18733. -extern long __copy_user_nocache(void *dst, const void __user *src,
  18734. - unsigned size, int zerorest);
  18735. +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
  18736. + unsigned long size, int zerorest);
  18737. -static inline int
  18738. -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
  18739. +static inline unsigned long
  18740. +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
  18741. {
  18742. might_fault();
  18743. +
  18744. + if (size > INT_MAX)
  18745. + return size;
  18746. +
  18747. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  18748. + if (!access_ok_noprefault(VERIFY_READ, src, size))
  18749. + return size;
  18750. +#endif
  18751. +
  18752. return __copy_user_nocache(dst, src, size, 1);
  18753. }
  18754. -static inline int
  18755. +static inline unsigned long
  18756. __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
  18757. - unsigned size)
  18758. + unsigned long size)
  18759. {
  18760. + if (size > INT_MAX)
  18761. + return size;
  18762. +
  18763. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  18764. + if (!access_ok_noprefault(VERIFY_READ, src, size))
  18765. + return size;
  18766. +#endif
  18767. +
  18768. return __copy_user_nocache(dst, src, size, 0);
  18769. }
  18770. unsigned long
  18771. -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
  18772. +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
  18773. #endif /* _ASM_X86_UACCESS_64_H */
  18774. diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
  18775. index 5b238981..77fdd78 100644
  18776. --- a/arch/x86/include/asm/word-at-a-time.h
  18777. +++ b/arch/x86/include/asm/word-at-a-time.h
  18778. @@ -11,7 +11,7 @@
  18779. * and shift, for example.
  18780. */
  18781. struct word_at_a_time {
  18782. - const unsigned long one_bits, high_bits;
  18783. + unsigned long one_bits, high_bits;
  18784. };
  18785. #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
  18786. diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
  18787. index e45e4da..44e8572 100644
  18788. --- a/arch/x86/include/asm/x86_init.h
  18789. +++ b/arch/x86/include/asm/x86_init.h
  18790. @@ -129,7 +129,7 @@ struct x86_init_ops {
  18791. struct x86_init_timers timers;
  18792. struct x86_init_iommu iommu;
  18793. struct x86_init_pci pci;
  18794. -};
  18795. +} __no_const;
  18796. /**
  18797. * struct x86_cpuinit_ops - platform specific cpu hotplug setups
  18798. @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
  18799. void (*setup_percpu_clockev)(void);
  18800. void (*early_percpu_clock_init)(void);
  18801. void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
  18802. -};
  18803. +} __no_const;
  18804. struct timespec;
  18805. @@ -168,7 +168,7 @@ struct x86_platform_ops {
  18806. void (*save_sched_clock_state)(void);
  18807. void (*restore_sched_clock_state)(void);
  18808. void (*apic_post_init)(void);
  18809. -};
  18810. +} __no_const;
  18811. struct pci_dev;
  18812. struct msi_msg;
  18813. @@ -185,7 +185,7 @@ struct x86_msi_ops {
  18814. int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
  18815. u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
  18816. u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
  18817. -};
  18818. +} __no_const;
  18819. struct IO_APIC_route_entry;
  18820. struct io_apic_irq_attr;
  18821. @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
  18822. unsigned int destination, int vector,
  18823. struct io_apic_irq_attr *attr);
  18824. void (*eoi_ioapic_pin)(int apic, int pin, int vector);
  18825. -};
  18826. +} __no_const;
  18827. extern struct x86_init_ops x86_init;
  18828. extern struct x86_cpuinit_ops x86_cpuinit;
  18829. diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
  18830. index 3e276eb..2eb3c30 100644
  18831. --- a/arch/x86/include/asm/xen/page.h
  18832. +++ b/arch/x86/include/asm/xen/page.h
  18833. @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
  18834. extern struct page *m2p_find_override(unsigned long mfn);
  18835. extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
  18836. -static inline unsigned long pfn_to_mfn(unsigned long pfn)
  18837. +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
  18838. {
  18839. unsigned long mfn;
  18840. diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
  18841. index 6c1d741..39e6ecf 100644
  18842. --- a/arch/x86/include/asm/xsave.h
  18843. +++ b/arch/x86/include/asm/xsave.h
  18844. @@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
  18845. if (unlikely(err))
  18846. return -EFAULT;
  18847. + pax_open_userland();
  18848. __asm__ __volatile__(ASM_STAC "\n"
  18849. - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
  18850. + "1:"
  18851. + __copyuser_seg
  18852. + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
  18853. "2: " ASM_CLAC "\n"
  18854. ".section .fixup,\"ax\"\n"
  18855. "3: movl $-1,%[err]\n"
  18856. @@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
  18857. : [err] "=r" (err)
  18858. : "D" (buf), "a" (-1), "d" (-1), "0" (0)
  18859. : "memory");
  18860. + pax_close_userland();
  18861. return err;
  18862. }
  18863. static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
  18864. {
  18865. int err;
  18866. - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
  18867. + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
  18868. u32 lmask = mask;
  18869. u32 hmask = mask >> 32;
  18870. + pax_open_userland();
  18871. __asm__ __volatile__(ASM_STAC "\n"
  18872. - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
  18873. + "1:"
  18874. + __copyuser_seg
  18875. + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
  18876. "2: " ASM_CLAC "\n"
  18877. ".section .fixup,\"ax\"\n"
  18878. "3: movl $-1,%[err]\n"
  18879. @@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
  18880. : [err] "=r" (err)
  18881. : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
  18882. : "memory"); /* memory required? */
  18883. + pax_close_userland();
  18884. return err;
  18885. }
  18886. diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
  18887. index bbae024..e1528f9 100644
  18888. --- a/arch/x86/include/uapi/asm/e820.h
  18889. +++ b/arch/x86/include/uapi/asm/e820.h
  18890. @@ -63,7 +63,7 @@ struct e820map {
  18891. #define ISA_START_ADDRESS 0xa0000
  18892. #define ISA_END_ADDRESS 0x100000
  18893. -#define BIOS_BEGIN 0x000a0000
  18894. +#define BIOS_BEGIN 0x000c0000
  18895. #define BIOS_END 0x00100000
  18896. #define BIOS_ROM_BASE 0xffe00000
  18897. diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
  18898. index 7b0a55a..ad115bf 100644
  18899. --- a/arch/x86/include/uapi/asm/ptrace-abi.h
  18900. +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
  18901. @@ -49,7 +49,6 @@
  18902. #define EFLAGS 144
  18903. #define RSP 152
  18904. #define SS 160
  18905. -#define ARGOFFSET R11
  18906. #endif /* __ASSEMBLY__ */
  18907. /* top of stack page */
  18908. diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
  18909. index cb648c8..91cb07e 100644
  18910. --- a/arch/x86/kernel/Makefile
  18911. +++ b/arch/x86/kernel/Makefile
  18912. @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
  18913. obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
  18914. obj-$(CONFIG_IRQ_WORK) += irq_work.o
  18915. obj-y += probe_roms.o
  18916. -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
  18917. +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
  18918. obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
  18919. obj-y += syscall_$(BITS).o
  18920. obj-$(CONFIG_X86_64) += vsyscall_64.o
  18921. diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
  18922. index 1dac942..19c8b0c 100644
  18923. --- a/arch/x86/kernel/acpi/boot.c
  18924. +++ b/arch/x86/kernel/acpi/boot.c
  18925. @@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
  18926. * If your system is blacklisted here, but you find that acpi=force
  18927. * works for you, please contact linux-acpi@vger.kernel.org
  18928. */
  18929. -static struct dmi_system_id __initdata acpi_dmi_table[] = {
  18930. +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
  18931. /*
  18932. * Boxes that need ACPI disabled
  18933. */
  18934. @@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
  18935. };
  18936. /* second table for DMI checks that should run after early-quirks */
  18937. -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
  18938. +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
  18939. /*
  18940. * HP laptops which use a DSDT reporting as HP/SB400/10000,
  18941. * which includes some code which overrides all temperature
  18942. diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
  18943. index 3a2ae4c..9db31d6 100644
  18944. --- a/arch/x86/kernel/acpi/sleep.c
  18945. +++ b/arch/x86/kernel/acpi/sleep.c
  18946. @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
  18947. #else /* CONFIG_64BIT */
  18948. #ifdef CONFIG_SMP
  18949. stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
  18950. +
  18951. + pax_open_kernel();
  18952. early_gdt_descr.address =
  18953. (unsigned long)get_cpu_gdt_table(smp_processor_id());
  18954. + pax_close_kernel();
  18955. +
  18956. initial_gs = per_cpu_offset(smp_processor_id());
  18957. #endif
  18958. initial_code = (unsigned long)wakeup_long64;
  18959. diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
  18960. index 665c6b7..eae4d56 100644
  18961. --- a/arch/x86/kernel/acpi/wakeup_32.S
  18962. +++ b/arch/x86/kernel/acpi/wakeup_32.S
  18963. @@ -29,13 +29,11 @@ wakeup_pmode_return:
  18964. # and restore the stack ... but you need gdt for this to work
  18965. movl saved_context_esp, %esp
  18966. - movl %cs:saved_magic, %eax
  18967. - cmpl $0x12345678, %eax
  18968. + cmpl $0x12345678, saved_magic
  18969. jne bogus_magic
  18970. # jump to place where we left off
  18971. - movl saved_eip, %eax
  18972. - jmp *%eax
  18973. + jmp *(saved_eip)
  18974. bogus_magic:
  18975. jmp bogus_magic
  18976. diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
  18977. index df94598..f3b29bf 100644
  18978. --- a/arch/x86/kernel/alternative.c
  18979. +++ b/arch/x86/kernel/alternative.c
  18980. @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
  18981. */
  18982. for (a = start; a < end; a++) {
  18983. instr = (u8 *)&a->instr_offset + a->instr_offset;
  18984. +
  18985. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  18986. + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  18987. + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
  18988. + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  18989. +#endif
  18990. +
  18991. replacement = (u8 *)&a->repl_offset + a->repl_offset;
  18992. BUG_ON(a->replacementlen > a->instrlen);
  18993. BUG_ON(a->instrlen > sizeof(insnbuf));
  18994. @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
  18995. for (poff = start; poff < end; poff++) {
  18996. u8 *ptr = (u8 *)poff + *poff;
  18997. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  18998. + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  18999. + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
  19000. + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  19001. +#endif
  19002. +
  19003. if (!*poff || ptr < text || ptr >= text_end)
  19004. continue;
  19005. /* turn DS segment override prefix into lock prefix */
  19006. - if (*ptr == 0x3e)
  19007. + if (*ktla_ktva(ptr) == 0x3e)
  19008. text_poke(ptr, ((unsigned char []){0xf0}), 1);
  19009. }
  19010. mutex_unlock(&text_mutex);
  19011. @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
  19012. for (poff = start; poff < end; poff++) {
  19013. u8 *ptr = (u8 *)poff + *poff;
  19014. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  19015. + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  19016. + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
  19017. + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  19018. +#endif
  19019. +
  19020. if (!*poff || ptr < text || ptr >= text_end)
  19021. continue;
  19022. /* turn lock prefix into DS segment override prefix */
  19023. - if (*ptr == 0xf0)
  19024. + if (*ktla_ktva(ptr) == 0xf0)
  19025. text_poke(ptr, ((unsigned char []){0x3E}), 1);
  19026. }
  19027. mutex_unlock(&text_mutex);
  19028. @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
  19029. BUG_ON(p->len > MAX_PATCH_LEN);
  19030. /* prep the buffer with the original instructions */
  19031. - memcpy(insnbuf, p->instr, p->len);
  19032. + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
  19033. used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
  19034. (unsigned long)p->instr, p->len);
  19035. @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
  19036. if (!uniproc_patched || num_possible_cpus() == 1)
  19037. free_init_pages("SMP alternatives",
  19038. (unsigned long)__smp_locks,
  19039. - (unsigned long)__smp_locks_end);
  19040. + PAGE_ALIGN((unsigned long)__smp_locks_end));
  19041. #endif
  19042. apply_paravirt(__parainstructions, __parainstructions_end);
  19043. @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
  19044. * instructions. And on the local CPU you need to be protected again NMI or MCE
  19045. * handlers seeing an inconsistent instruction while you patch.
  19046. */
  19047. -void *__init_or_module text_poke_early(void *addr, const void *opcode,
  19048. +void *__kprobes text_poke_early(void *addr, const void *opcode,
  19049. size_t len)
  19050. {
  19051. unsigned long flags;
  19052. local_irq_save(flags);
  19053. - memcpy(addr, opcode, len);
  19054. +
  19055. + pax_open_kernel();
  19056. + memcpy(ktla_ktva(addr), opcode, len);
  19057. sync_core();
  19058. + pax_close_kernel();
  19059. +
  19060. local_irq_restore(flags);
  19061. /* Could also do a CLFLUSH here to speed up CPU recovery; but
  19062. that causes hangs on some VIA CPUs. */
  19063. @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
  19064. */
  19065. void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
  19066. {
  19067. - unsigned long flags;
  19068. - char *vaddr;
  19069. + unsigned char *vaddr = ktla_ktva(addr);
  19070. struct page *pages[2];
  19071. - int i;
  19072. + size_t i;
  19073. if (!core_kernel_text((unsigned long)addr)) {
  19074. - pages[0] = vmalloc_to_page(addr);
  19075. - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
  19076. + pages[0] = vmalloc_to_page(vaddr);
  19077. + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
  19078. } else {
  19079. - pages[0] = virt_to_page(addr);
  19080. + pages[0] = virt_to_page(vaddr);
  19081. WARN_ON(!PageReserved(pages[0]));
  19082. - pages[1] = virt_to_page(addr + PAGE_SIZE);
  19083. + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
  19084. }
  19085. BUG_ON(!pages[0]);
  19086. - local_irq_save(flags);
  19087. - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
  19088. - if (pages[1])
  19089. - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
  19090. - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
  19091. - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
  19092. - clear_fixmap(FIX_TEXT_POKE0);
  19093. - if (pages[1])
  19094. - clear_fixmap(FIX_TEXT_POKE1);
  19095. - local_flush_tlb();
  19096. - sync_core();
  19097. - /* Could also do a CLFLUSH here to speed up CPU recovery; but
  19098. - that causes hangs on some VIA CPUs. */
  19099. + text_poke_early(addr, opcode, len);
  19100. for (i = 0; i < len; i++)
  19101. - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
  19102. - local_irq_restore(flags);
  19103. + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
  19104. return addr;
  19105. }
  19106. @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
  19107. if (likely(!bp_patching_in_progress))
  19108. return 0;
  19109. - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
  19110. + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
  19111. return 0;
  19112. /* set up the specified breakpoint handler */
  19113. @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
  19114. */
  19115. void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
  19116. {
  19117. - unsigned char int3 = 0xcc;
  19118. + const unsigned char int3 = 0xcc;
  19119. bp_int3_handler = handler;
  19120. bp_int3_addr = (u8 *)addr + sizeof(int3);
  19121. diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
  19122. index 7f26c9a..694544e 100644
  19123. --- a/arch/x86/kernel/apic/apic.c
  19124. +++ b/arch/x86/kernel/apic/apic.c
  19125. @@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
  19126. /*
  19127. * Debug level, exported for io_apic.c
  19128. */
  19129. -unsigned int apic_verbosity;
  19130. +int apic_verbosity;
  19131. int pic_mode;
  19132. @@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
  19133. apic_write(APIC_ESR, 0);
  19134. v = apic_read(APIC_ESR);
  19135. ack_APIC_irq();
  19136. - atomic_inc(&irq_err_count);
  19137. + atomic_inc_unchecked(&irq_err_count);
  19138. apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
  19139. smp_processor_id(), v);
  19140. diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
  19141. index 2c621a6..fa2b1ae 100644
  19142. --- a/arch/x86/kernel/apic/apic_flat_64.c
  19143. +++ b/arch/x86/kernel/apic/apic_flat_64.c
  19144. @@ -154,7 +154,7 @@ static int flat_probe(void)
  19145. return 1;
  19146. }
  19147. -static struct apic apic_flat = {
  19148. +static struct apic apic_flat __read_only = {
  19149. .name = "flat",
  19150. .probe = flat_probe,
  19151. .acpi_madt_oem_check = flat_acpi_madt_oem_check,
  19152. @@ -268,7 +268,7 @@ static int physflat_probe(void)
  19153. return 0;
  19154. }
  19155. -static struct apic apic_physflat = {
  19156. +static struct apic apic_physflat __read_only = {
  19157. .name = "physical flat",
  19158. .probe = physflat_probe,
  19159. diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
  19160. index 191ce75..2db6d63 100644
  19161. --- a/arch/x86/kernel/apic/apic_noop.c
  19162. +++ b/arch/x86/kernel/apic/apic_noop.c
  19163. @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
  19164. WARN_ON_ONCE(cpu_has_apic && !disable_apic);
  19165. }
  19166. -struct apic apic_noop = {
  19167. +struct apic apic_noop __read_only = {
  19168. .name = "noop",
  19169. .probe = noop_probe,
  19170. .acpi_madt_oem_check = NULL,
  19171. diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
  19172. index d50e364..543bee3 100644
  19173. --- a/arch/x86/kernel/apic/bigsmp_32.c
  19174. +++ b/arch/x86/kernel/apic/bigsmp_32.c
  19175. @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
  19176. return dmi_bigsmp;
  19177. }
  19178. -static struct apic apic_bigsmp = {
  19179. +static struct apic apic_bigsmp __read_only = {
  19180. .name = "bigsmp",
  19181. .probe = probe_bigsmp,
  19182. diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
  19183. index c552247..587a316 100644
  19184. --- a/arch/x86/kernel/apic/es7000_32.c
  19185. +++ b/arch/x86/kernel/apic/es7000_32.c
  19186. @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
  19187. return ret && es7000_apic_is_cluster();
  19188. }
  19189. -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
  19190. -static struct apic __refdata apic_es7000_cluster = {
  19191. +static struct apic apic_es7000_cluster __read_only = {
  19192. .name = "es7000",
  19193. .probe = probe_es7000,
  19194. @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
  19195. .x86_32_early_logical_apicid = es7000_early_logical_apicid,
  19196. };
  19197. -static struct apic __refdata apic_es7000 = {
  19198. +static struct apic apic_es7000 __read_only = {
  19199. .name = "es7000",
  19200. .probe = probe_es7000,
  19201. diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
  19202. index 6ad4658..38a7b5c 100644
  19203. --- a/arch/x86/kernel/apic/io_apic.c
  19204. +++ b/arch/x86/kernel/apic/io_apic.c
  19205. @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
  19206. }
  19207. EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
  19208. -void lock_vector_lock(void)
  19209. +void lock_vector_lock(void) __acquires(vector_lock)
  19210. {
  19211. /* Used to the online set of cpus does not change
  19212. * during assign_irq_vector.
  19213. @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
  19214. raw_spin_lock(&vector_lock);
  19215. }
  19216. -void unlock_vector_lock(void)
  19217. +void unlock_vector_lock(void) __releases(vector_lock)
  19218. {
  19219. raw_spin_unlock(&vector_lock);
  19220. }
  19221. @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
  19222. ack_APIC_irq();
  19223. }
  19224. -atomic_t irq_mis_count;
  19225. +atomic_unchecked_t irq_mis_count;
  19226. #ifdef CONFIG_GENERIC_PENDING_IRQ
  19227. static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
  19228. @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
  19229. * at the cpu.
  19230. */
  19231. if (!(v & (1 << (i & 0x1f)))) {
  19232. - atomic_inc(&irq_mis_count);
  19233. + atomic_inc_unchecked(&irq_mis_count);
  19234. eoi_ioapic_irq(irq, cfg);
  19235. }
  19236. diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
  19237. index 1e42e8f..daacf44 100644
  19238. --- a/arch/x86/kernel/apic/numaq_32.c
  19239. +++ b/arch/x86/kernel/apic/numaq_32.c
  19240. @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
  19241. (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
  19242. }
  19243. -/* Use __refdata to keep false positive warning calm. */
  19244. -static struct apic __refdata apic_numaq = {
  19245. +static struct apic apic_numaq __read_only = {
  19246. .name = "NUMAQ",
  19247. .probe = probe_numaq,
  19248. diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
  19249. index eb35ef9..f184a21 100644
  19250. --- a/arch/x86/kernel/apic/probe_32.c
  19251. +++ b/arch/x86/kernel/apic/probe_32.c
  19252. @@ -72,7 +72,7 @@ static int probe_default(void)
  19253. return 1;
  19254. }
  19255. -static struct apic apic_default = {
  19256. +static struct apic apic_default __read_only = {
  19257. .name = "default",
  19258. .probe = probe_default,
  19259. diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
  19260. index 00146f9..5e299b8 100644
  19261. --- a/arch/x86/kernel/apic/summit_32.c
  19262. +++ b/arch/x86/kernel/apic/summit_32.c
  19263. @@ -485,7 +485,7 @@ void setup_summit(void)
  19264. }
  19265. #endif
  19266. -static struct apic apic_summit = {
  19267. +static struct apic apic_summit __read_only = {
  19268. .name = "summit",
  19269. .probe = probe_summit,
  19270. diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
  19271. index cac85ee..01fa741 100644
  19272. --- a/arch/x86/kernel/apic/x2apic_cluster.c
  19273. +++ b/arch/x86/kernel/apic/x2apic_cluster.c
  19274. @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
  19275. return notifier_from_errno(err);
  19276. }
  19277. -static struct notifier_block __refdata x2apic_cpu_notifier = {
  19278. +static struct notifier_block x2apic_cpu_notifier = {
  19279. .notifier_call = update_clusterinfo,
  19280. };
  19281. @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
  19282. cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
  19283. }
  19284. -static struct apic apic_x2apic_cluster = {
  19285. +static struct apic apic_x2apic_cluster __read_only = {
  19286. .name = "cluster x2apic",
  19287. .probe = x2apic_cluster_probe,
  19288. diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
  19289. index de231e3..1d1b2ee 100644
  19290. --- a/arch/x86/kernel/apic/x2apic_phys.c
  19291. +++ b/arch/x86/kernel/apic/x2apic_phys.c
  19292. @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
  19293. return apic == &apic_x2apic_phys;
  19294. }
  19295. -static struct apic apic_x2apic_phys = {
  19296. +static struct apic apic_x2apic_phys __read_only = {
  19297. .name = "physical x2apic",
  19298. .probe = x2apic_phys_probe,
  19299. diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
  19300. index d263b13..963258b 100644
  19301. --- a/arch/x86/kernel/apic/x2apic_uv_x.c
  19302. +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
  19303. @@ -350,7 +350,7 @@ static int uv_probe(void)
  19304. return apic == &apic_x2apic_uv_x;
  19305. }
  19306. -static struct apic __refdata apic_x2apic_uv_x = {
  19307. +static struct apic apic_x2apic_uv_x __read_only = {
  19308. .name = "UV large system",
  19309. .probe = uv_probe,
  19310. diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
  19311. index 3ab0343..814c4787 100644
  19312. --- a/arch/x86/kernel/apm_32.c
  19313. +++ b/arch/x86/kernel/apm_32.c
  19314. @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
  19315. * This is for buggy BIOS's that refer to (real mode) segment 0x40
  19316. * even though they are called in protected mode.
  19317. */
  19318. -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
  19319. +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
  19320. (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
  19321. static const char driver_version[] = "1.16ac"; /* no spaces */
  19322. @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
  19323. BUG_ON(cpu != 0);
  19324. gdt = get_cpu_gdt_table(cpu);
  19325. save_desc_40 = gdt[0x40 / 8];
  19326. +
  19327. + pax_open_kernel();
  19328. gdt[0x40 / 8] = bad_bios_desc;
  19329. + pax_close_kernel();
  19330. apm_irq_save(flags);
  19331. APM_DO_SAVE_SEGS;
  19332. @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
  19333. &call->esi);
  19334. APM_DO_RESTORE_SEGS;
  19335. apm_irq_restore(flags);
  19336. +
  19337. + pax_open_kernel();
  19338. gdt[0x40 / 8] = save_desc_40;
  19339. + pax_close_kernel();
  19340. +
  19341. put_cpu();
  19342. return call->eax & 0xff;
  19343. @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
  19344. BUG_ON(cpu != 0);
  19345. gdt = get_cpu_gdt_table(cpu);
  19346. save_desc_40 = gdt[0x40 / 8];
  19347. +
  19348. + pax_open_kernel();
  19349. gdt[0x40 / 8] = bad_bios_desc;
  19350. + pax_close_kernel();
  19351. apm_irq_save(flags);
  19352. APM_DO_SAVE_SEGS;
  19353. @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
  19354. &call->eax);
  19355. APM_DO_RESTORE_SEGS;
  19356. apm_irq_restore(flags);
  19357. +
  19358. + pax_open_kernel();
  19359. gdt[0x40 / 8] = save_desc_40;
  19360. + pax_close_kernel();
  19361. +
  19362. put_cpu();
  19363. return error;
  19364. }
  19365. @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
  19366. * code to that CPU.
  19367. */
  19368. gdt = get_cpu_gdt_table(0);
  19369. +
  19370. + pax_open_kernel();
  19371. set_desc_base(&gdt[APM_CS >> 3],
  19372. (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
  19373. set_desc_base(&gdt[APM_CS_16 >> 3],
  19374. (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
  19375. set_desc_base(&gdt[APM_DS >> 3],
  19376. (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
  19377. + pax_close_kernel();
  19378. proc_create("apm", 0, NULL, &apm_file_ops);
  19379. diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
  19380. index 9f6b934..cf5ffb3 100644
  19381. --- a/arch/x86/kernel/asm-offsets.c
  19382. +++ b/arch/x86/kernel/asm-offsets.c
  19383. @@ -32,6 +32,8 @@ void common(void) {
  19384. OFFSET(TI_flags, thread_info, flags);
  19385. OFFSET(TI_status, thread_info, status);
  19386. OFFSET(TI_addr_limit, thread_info, addr_limit);
  19387. + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
  19388. + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
  19389. BLANK();
  19390. OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
  19391. @@ -52,8 +54,26 @@ void common(void) {
  19392. OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
  19393. OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
  19394. OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
  19395. +
  19396. +#ifdef CONFIG_PAX_KERNEXEC
  19397. + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
  19398. #endif
  19399. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  19400. + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
  19401. + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
  19402. +#ifdef CONFIG_X86_64
  19403. + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
  19404. +#endif
  19405. +#endif
  19406. +
  19407. +#endif
  19408. +
  19409. + BLANK();
  19410. + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
  19411. + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
  19412. + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
  19413. +
  19414. #ifdef CONFIG_XEN
  19415. BLANK();
  19416. OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
  19417. diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
  19418. index e7c798b..2b2019b 100644
  19419. --- a/arch/x86/kernel/asm-offsets_64.c
  19420. +++ b/arch/x86/kernel/asm-offsets_64.c
  19421. @@ -77,6 +77,7 @@ int main(void)
  19422. BLANK();
  19423. #undef ENTRY
  19424. + DEFINE(TSS_size, sizeof(struct tss_struct));
  19425. OFFSET(TSS_ist, tss_struct, x86_tss.ist);
  19426. BLANK();
  19427. diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
  19428. index 7fd54f0..0691410 100644
  19429. --- a/arch/x86/kernel/cpu/Makefile
  19430. +++ b/arch/x86/kernel/cpu/Makefile
  19431. @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
  19432. CFLAGS_REMOVE_perf_event.o = -pg
  19433. endif
  19434. -# Make sure load_percpu_segment has no stackprotector
  19435. -nostackp := $(call cc-option, -fno-stack-protector)
  19436. -CFLAGS_common.o := $(nostackp)
  19437. -
  19438. obj-y := intel_cacheinfo.o scattered.o topology.o
  19439. obj-y += proc.o capflags.o powerflags.o common.o
  19440. obj-y += rdrand.o
  19441. diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
  19442. index c67ffa6..f41fbbf 100644
  19443. --- a/arch/x86/kernel/cpu/amd.c
  19444. +++ b/arch/x86/kernel/cpu/amd.c
  19445. @@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
  19446. static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  19447. {
  19448. /* AMD errata T13 (order #21922) */
  19449. - if ((c->x86 == 6)) {
  19450. + if (c->x86 == 6) {
  19451. /* Duron Rev A0 */
  19452. if (c->x86_model == 3 && c->x86_mask == 0)
  19453. size = 64;
  19454. diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
  19455. index 8e28bf2..bf5c0d2 100644
  19456. --- a/arch/x86/kernel/cpu/common.c
  19457. +++ b/arch/x86/kernel/cpu/common.c
  19458. @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
  19459. static const struct cpu_dev *this_cpu = &default_cpu;
  19460. -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
  19461. -#ifdef CONFIG_X86_64
  19462. - /*
  19463. - * We need valid kernel segments for data and code in long mode too
  19464. - * IRET will check the segment types kkeil 2000/10/28
  19465. - * Also sysret mandates a special GDT layout
  19466. - *
  19467. - * TLS descriptors are currently at a different place compared to i386.
  19468. - * Hopefully nobody expects them at a fixed place (Wine?)
  19469. - */
  19470. - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
  19471. - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
  19472. - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
  19473. - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
  19474. - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
  19475. - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
  19476. -#else
  19477. - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
  19478. - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
  19479. - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
  19480. - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
  19481. - /*
  19482. - * Segments used for calling PnP BIOS have byte granularity.
  19483. - * They code segments and data segments have fixed 64k limits,
  19484. - * the transfer segment sizes are set at run time.
  19485. - */
  19486. - /* 32-bit code */
  19487. - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
  19488. - /* 16-bit code */
  19489. - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
  19490. - /* 16-bit data */
  19491. - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
  19492. - /* 16-bit data */
  19493. - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
  19494. - /* 16-bit data */
  19495. - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
  19496. - /*
  19497. - * The APM segments have byte granularity and their bases
  19498. - * are set at run time. All have 64k limits.
  19499. - */
  19500. - /* 32-bit code */
  19501. - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
  19502. - /* 16-bit code */
  19503. - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
  19504. - /* data */
  19505. - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
  19506. -
  19507. - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
  19508. - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
  19509. - GDT_STACK_CANARY_INIT
  19510. -#endif
  19511. -} };
  19512. -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
  19513. -
  19514. static int __init x86_xsave_setup(char *s)
  19515. {
  19516. setup_clear_cpu_cap(X86_FEATURE_XSAVE);
  19517. @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
  19518. }
  19519. }
  19520. +#ifdef CONFIG_X86_64
  19521. +static __init int setup_disable_pcid(char *arg)
  19522. +{
  19523. + setup_clear_cpu_cap(X86_FEATURE_PCID);
  19524. + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
  19525. +
  19526. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  19527. + if (clone_pgd_mask != ~(pgdval_t)0UL)
  19528. + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
  19529. +#endif
  19530. +
  19531. + return 1;
  19532. +}
  19533. +__setup("nopcid", setup_disable_pcid);
  19534. +
  19535. +static void setup_pcid(struct cpuinfo_x86 *c)
  19536. +{
  19537. + if (!cpu_has(c, X86_FEATURE_PCID)) {
  19538. + clear_cpu_cap(c, X86_FEATURE_INVPCID);
  19539. +
  19540. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  19541. + if (clone_pgd_mask != ~(pgdval_t)0UL) {
  19542. + pax_open_kernel();
  19543. + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
  19544. + pax_close_kernel();
  19545. + printk("PAX: slow and weak UDEREF enabled\n");
  19546. + } else
  19547. + printk("PAX: UDEREF disabled\n");
  19548. +#endif
  19549. +
  19550. + return;
  19551. + }
  19552. +
  19553. + printk("PAX: PCID detected\n");
  19554. + set_in_cr4(X86_CR4_PCIDE);
  19555. +
  19556. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  19557. + pax_open_kernel();
  19558. + clone_pgd_mask = ~(pgdval_t)0UL;
  19559. + pax_close_kernel();
  19560. + if (pax_user_shadow_base)
  19561. + printk("PAX: weak UDEREF enabled\n");
  19562. + else {
  19563. + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
  19564. + printk("PAX: strong UDEREF enabled\n");
  19565. + }
  19566. +#endif
  19567. +
  19568. + if (cpu_has(c, X86_FEATURE_INVPCID))
  19569. + printk("PAX: INVPCID detected\n");
  19570. +}
  19571. +#endif
  19572. +
  19573. /*
  19574. * Some CPU features depend on higher CPUID levels, which may not always
  19575. * be available due to CPUID level capping or broken virtualization
  19576. @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
  19577. {
  19578. struct desc_ptr gdt_descr;
  19579. - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
  19580. + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
  19581. gdt_descr.size = GDT_SIZE - 1;
  19582. load_gdt(&gdt_descr);
  19583. /* Reload the per-cpu base */
  19584. @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
  19585. setup_smep(c);
  19586. setup_smap(c);
  19587. +#ifdef CONFIG_X86_64
  19588. + setup_pcid(c);
  19589. +#endif
  19590. +
  19591. /*
  19592. * The vendor-specific functions might have changed features.
  19593. * Now we do "generic changes."
  19594. @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
  19595. /* Filter out anything that depends on CPUID levels we don't have */
  19596. filter_cpuid_features(c, true);
  19597. +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
  19598. + setup_clear_cpu_cap(X86_FEATURE_SEP);
  19599. +#endif
  19600. +
  19601. /* If the model name is still unset, do table lookup. */
  19602. if (!c->x86_model_id[0]) {
  19603. const char *p;
  19604. @@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
  19605. }
  19606. __setup("clearcpuid=", setup_disablecpuid);
  19607. +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
  19608. +EXPORT_PER_CPU_SYMBOL(current_tinfo);
  19609. +
  19610. #ifdef CONFIG_X86_64
  19611. -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
  19612. -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
  19613. - (unsigned long) debug_idt_table };
  19614. +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
  19615. +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
  19616. DEFINE_PER_CPU_FIRST(union irq_stack_union,
  19617. irq_stack_union) __aligned(PAGE_SIZE) __visible;
  19618. @@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
  19619. EXPORT_PER_CPU_SYMBOL(current_task);
  19620. DEFINE_PER_CPU(unsigned long, kernel_stack) =
  19621. - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
  19622. + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
  19623. EXPORT_PER_CPU_SYMBOL(kernel_stack);
  19624. DEFINE_PER_CPU(char *, irq_stack_ptr) =
  19625. @@ -1245,7 +1254,7 @@ void cpu_init(void)
  19626. load_ucode_ap();
  19627. cpu = stack_smp_processor_id();
  19628. - t = &per_cpu(init_tss, cpu);
  19629. + t = init_tss + cpu;
  19630. oist = &per_cpu(orig_ist, cpu);
  19631. #ifdef CONFIG_NUMA
  19632. @@ -1280,7 +1289,6 @@ void cpu_init(void)
  19633. wrmsrl(MSR_KERNEL_GS_BASE, 0);
  19634. barrier();
  19635. - x86_configure_nx();
  19636. enable_x2apic();
  19637. /*
  19638. @@ -1332,7 +1340,7 @@ void cpu_init(void)
  19639. {
  19640. int cpu = smp_processor_id();
  19641. struct task_struct *curr = current;
  19642. - struct tss_struct *t = &per_cpu(init_tss, cpu);
  19643. + struct tss_struct *t = init_tss + cpu;
  19644. struct thread_struct *thread = &curr->thread;
  19645. show_ucode_info_early();
  19646. diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
  19647. index 0641113..06f5ba4 100644
  19648. --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
  19649. +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
  19650. @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
  19651. };
  19652. #ifdef CONFIG_AMD_NB
  19653. +static struct attribute *default_attrs_amd_nb[] = {
  19654. + &type.attr,
  19655. + &level.attr,
  19656. + &coherency_line_size.attr,
  19657. + &physical_line_partition.attr,
  19658. + &ways_of_associativity.attr,
  19659. + &number_of_sets.attr,
  19660. + &size.attr,
  19661. + &shared_cpu_map.attr,
  19662. + &shared_cpu_list.attr,
  19663. + NULL,
  19664. + NULL,
  19665. + NULL,
  19666. + NULL
  19667. +};
  19668. +
  19669. static struct attribute **amd_l3_attrs(void)
  19670. {
  19671. static struct attribute **attrs;
  19672. @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
  19673. n = ARRAY_SIZE(default_attrs);
  19674. - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
  19675. - n += 2;
  19676. -
  19677. - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
  19678. - n += 1;
  19679. -
  19680. - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
  19681. - if (attrs == NULL)
  19682. - return attrs = default_attrs;
  19683. -
  19684. - for (n = 0; default_attrs[n]; n++)
  19685. - attrs[n] = default_attrs[n];
  19686. + attrs = default_attrs_amd_nb;
  19687. if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
  19688. attrs[n++] = &cache_disable_0.attr;
  19689. @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
  19690. .default_attrs = default_attrs,
  19691. };
  19692. +#ifdef CONFIG_AMD_NB
  19693. +static struct kobj_type ktype_cache_amd_nb = {
  19694. + .sysfs_ops = &sysfs_ops,
  19695. + .default_attrs = default_attrs_amd_nb,
  19696. +};
  19697. +#endif
  19698. +
  19699. static struct kobj_type ktype_percpu_entry = {
  19700. .sysfs_ops = &sysfs_ops,
  19701. };
  19702. @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
  19703. return retval;
  19704. }
  19705. +#ifdef CONFIG_AMD_NB
  19706. + amd_l3_attrs();
  19707. +#endif
  19708. +
  19709. for (i = 0; i < num_cache_leaves; i++) {
  19710. + struct kobj_type *ktype;
  19711. +
  19712. this_object = INDEX_KOBJECT_PTR(cpu, i);
  19713. this_object->cpu = cpu;
  19714. this_object->index = i;
  19715. this_leaf = CPUID4_INFO_IDX(cpu, i);
  19716. - ktype_cache.default_attrs = default_attrs;
  19717. + ktype = &ktype_cache;
  19718. #ifdef CONFIG_AMD_NB
  19719. if (this_leaf->base.nb)
  19720. - ktype_cache.default_attrs = amd_l3_attrs();
  19721. + ktype = &ktype_cache_amd_nb;
  19722. #endif
  19723. retval = kobject_init_and_add(&(this_object->kobj),
  19724. - &ktype_cache,
  19725. + ktype,
  19726. per_cpu(ici_cache_kobject, cpu),
  19727. "index%1lu", i);
  19728. if (unlikely(retval)) {
  19729. diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
  19730. index 4d5419b..95f11bb 100644
  19731. --- a/arch/x86/kernel/cpu/mcheck/mce.c
  19732. +++ b/arch/x86/kernel/cpu/mcheck/mce.c
  19733. @@ -45,6 +45,7 @@
  19734. #include <asm/processor.h>
  19735. #include <asm/mce.h>
  19736. #include <asm/msr.h>
  19737. +#include <asm/local.h>
  19738. #include "mce-internal.h"
  19739. @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
  19740. !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
  19741. m->cs, m->ip);
  19742. - if (m->cs == __KERNEL_CS)
  19743. + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
  19744. print_symbol("{%s}", m->ip);
  19745. pr_cont("\n");
  19746. }
  19747. @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
  19748. #define PANIC_TIMEOUT 5 /* 5 seconds */
  19749. -static atomic_t mce_paniced;
  19750. +static atomic_unchecked_t mce_paniced;
  19751. static int fake_panic;
  19752. -static atomic_t mce_fake_paniced;
  19753. +static atomic_unchecked_t mce_fake_paniced;
  19754. /* Panic in progress. Enable interrupts and wait for final IPI */
  19755. static void wait_for_panic(void)
  19756. @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
  19757. /*
  19758. * Make sure only one CPU runs in machine check panic
  19759. */
  19760. - if (atomic_inc_return(&mce_paniced) > 1)
  19761. + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
  19762. wait_for_panic();
  19763. barrier();
  19764. @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
  19765. console_verbose();
  19766. } else {
  19767. /* Don't log too much for fake panic */
  19768. - if (atomic_inc_return(&mce_fake_paniced) > 1)
  19769. + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
  19770. return;
  19771. }
  19772. /* First print corrected ones that are still unlogged */
  19773. @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
  19774. if (!fake_panic) {
  19775. if (panic_timeout == 0)
  19776. panic_timeout = mca_cfg.panic_timeout;
  19777. - panic(msg);
  19778. + panic("%s", msg);
  19779. } else
  19780. pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
  19781. }
  19782. @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
  19783. * might have been modified by someone else.
  19784. */
  19785. rmb();
  19786. - if (atomic_read(&mce_paniced))
  19787. + if (atomic_read_unchecked(&mce_paniced))
  19788. wait_for_panic();
  19789. if (!mca_cfg.monarch_timeout)
  19790. goto out;
  19791. @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
  19792. }
  19793. /* Call the installed machine check handler for this CPU setup. */
  19794. -void (*machine_check_vector)(struct pt_regs *, long error_code) =
  19795. +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
  19796. unexpected_machine_check;
  19797. /*
  19798. @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
  19799. return;
  19800. }
  19801. + pax_open_kernel();
  19802. machine_check_vector = do_machine_check;
  19803. + pax_close_kernel();
  19804. __mcheck_cpu_init_generic();
  19805. __mcheck_cpu_init_vendor(c);
  19806. @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
  19807. */
  19808. static DEFINE_SPINLOCK(mce_chrdev_state_lock);
  19809. -static int mce_chrdev_open_count; /* #times opened */
  19810. +static local_t mce_chrdev_open_count; /* #times opened */
  19811. static int mce_chrdev_open_exclu; /* already open exclusive? */
  19812. static int mce_chrdev_open(struct inode *inode, struct file *file)
  19813. @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
  19814. spin_lock(&mce_chrdev_state_lock);
  19815. if (mce_chrdev_open_exclu ||
  19816. - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
  19817. + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
  19818. spin_unlock(&mce_chrdev_state_lock);
  19819. return -EBUSY;
  19820. @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
  19821. if (file->f_flags & O_EXCL)
  19822. mce_chrdev_open_exclu = 1;
  19823. - mce_chrdev_open_count++;
  19824. + local_inc(&mce_chrdev_open_count);
  19825. spin_unlock(&mce_chrdev_state_lock);
  19826. @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
  19827. {
  19828. spin_lock(&mce_chrdev_state_lock);
  19829. - mce_chrdev_open_count--;
  19830. + local_dec(&mce_chrdev_open_count);
  19831. mce_chrdev_open_exclu = 0;
  19832. spin_unlock(&mce_chrdev_state_lock);
  19833. @@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
  19834. for (i = 0; i < mca_cfg.banks; i++) {
  19835. struct mce_bank *b = &mce_banks[i];
  19836. - struct device_attribute *a = &b->attr;
  19837. + device_attribute_no_const *a = &b->attr;
  19838. sysfs_attr_init(&a->attr);
  19839. a->attr.name = b->attrname;
  19840. @@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
  19841. static void mce_reset(void)
  19842. {
  19843. cpu_missing = 0;
  19844. - atomic_set(&mce_fake_paniced, 0);
  19845. + atomic_set_unchecked(&mce_fake_paniced, 0);
  19846. atomic_set(&mce_executing, 0);
  19847. atomic_set(&mce_callin, 0);
  19848. atomic_set(&global_nwo, 0);
  19849. diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
  19850. index a304298..49b6d06 100644
  19851. --- a/arch/x86/kernel/cpu/mcheck/p5.c
  19852. +++ b/arch/x86/kernel/cpu/mcheck/p5.c
  19853. @@ -10,6 +10,7 @@
  19854. #include <asm/processor.h>
  19855. #include <asm/mce.h>
  19856. #include <asm/msr.h>
  19857. +#include <asm/pgtable.h>
  19858. /* By default disabled */
  19859. int mce_p5_enabled __read_mostly;
  19860. @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
  19861. if (!cpu_has(c, X86_FEATURE_MCE))
  19862. return;
  19863. + pax_open_kernel();
  19864. machine_check_vector = pentium_machine_check;
  19865. + pax_close_kernel();
  19866. /* Make sure the vector pointer is visible before we enable MCEs: */
  19867. wmb();
  19868. diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
  19869. index 7dc5564..1273569 100644
  19870. --- a/arch/x86/kernel/cpu/mcheck/winchip.c
  19871. +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
  19872. @@ -9,6 +9,7 @@
  19873. #include <asm/processor.h>
  19874. #include <asm/mce.h>
  19875. #include <asm/msr.h>
  19876. +#include <asm/pgtable.h>
  19877. /* Machine check handler for WinChip C6: */
  19878. static void winchip_machine_check(struct pt_regs *regs, long error_code)
  19879. @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
  19880. {
  19881. u32 lo, hi;
  19882. + pax_open_kernel();
  19883. machine_check_vector = winchip_machine_check;
  19884. + pax_close_kernel();
  19885. /* Make sure the vector pointer is visible before we enable MCEs: */
  19886. wmb();
  19887. diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
  19888. index 15c9876..0a43909 100644
  19889. --- a/arch/x86/kernel/cpu/microcode/core.c
  19890. +++ b/arch/x86/kernel/cpu/microcode/core.c
  19891. @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
  19892. return NOTIFY_OK;
  19893. }
  19894. -static struct notifier_block __refdata mc_cpu_notifier = {
  19895. +static struct notifier_block mc_cpu_notifier = {
  19896. .notifier_call = mc_cpu_callback,
  19897. };
  19898. diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
  19899. index a276fa7..e66810f 100644
  19900. --- a/arch/x86/kernel/cpu/microcode/intel.c
  19901. +++ b/arch/x86/kernel/cpu/microcode/intel.c
  19902. @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
  19903. static int get_ucode_user(void *to, const void *from, size_t n)
  19904. {
  19905. - return copy_from_user(to, from, n);
  19906. + return copy_from_user(to, (const void __force_user *)from, n);
  19907. }
  19908. static enum ucode_state
  19909. request_microcode_user(int cpu, const void __user *buf, size_t size)
  19910. {
  19911. - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
  19912. + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
  19913. }
  19914. static void microcode_fini_cpu(int cpu)
  19915. diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
  19916. index f961de9..8a9d332 100644
  19917. --- a/arch/x86/kernel/cpu/mtrr/main.c
  19918. +++ b/arch/x86/kernel/cpu/mtrr/main.c
  19919. @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
  19920. u64 size_or_mask, size_and_mask;
  19921. static bool mtrr_aps_delayed_init;
  19922. -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
  19923. +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
  19924. const struct mtrr_ops *mtrr_if;
  19925. diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
  19926. index df5e41f..816c719 100644
  19927. --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
  19928. +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
  19929. @@ -25,7 +25,7 @@ struct mtrr_ops {
  19930. int (*validate_add_page)(unsigned long base, unsigned long size,
  19931. unsigned int type);
  19932. int (*have_wrcomb)(void);
  19933. -};
  19934. +} __do_const;
  19935. extern int generic_get_free_region(unsigned long base, unsigned long size,
  19936. int replace_reg);
  19937. diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
  19938. index 79f9f84..38ace52 100644
  19939. --- a/arch/x86/kernel/cpu/perf_event.c
  19940. +++ b/arch/x86/kernel/cpu/perf_event.c
  19941. @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
  19942. pr_info("no hardware sampling interrupt available.\n");
  19943. }
  19944. -static struct attribute_group x86_pmu_format_group = {
  19945. +static attribute_group_no_const x86_pmu_format_group = {
  19946. .name = "format",
  19947. .attrs = NULL,
  19948. };
  19949. @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
  19950. NULL,
  19951. };
  19952. -static struct attribute_group x86_pmu_events_group = {
  19953. +static attribute_group_no_const x86_pmu_events_group = {
  19954. .name = "events",
  19955. .attrs = events_attr,
  19956. };
  19957. @@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
  19958. if (idx > GDT_ENTRIES)
  19959. return 0;
  19960. - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
  19961. + desc = get_cpu_gdt_table(smp_processor_id());
  19962. }
  19963. return get_desc_base(desc + idx);
  19964. @@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
  19965. break;
  19966. perf_callchain_store(entry, frame.return_address);
  19967. - fp = frame.next_frame;
  19968. + fp = (const void __force_user *)frame.next_frame;
  19969. }
  19970. }
  19971. diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
  19972. index 639d128..e92d7e5 100644
  19973. --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
  19974. +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
  19975. @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
  19976. static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
  19977. {
  19978. struct attribute **attrs;
  19979. - struct attribute_group *attr_group;
  19980. + attribute_group_no_const *attr_group;
  19981. int i = 0, j;
  19982. while (amd_iommu_v2_event_descs[i].attr.attr.name)
  19983. diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
  19984. index aa333d9..f9db700 100644
  19985. --- a/arch/x86/kernel/cpu/perf_event_intel.c
  19986. +++ b/arch/x86/kernel/cpu/perf_event_intel.c
  19987. @@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
  19988. x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
  19989. if (boot_cpu_has(X86_FEATURE_PDCM)) {
  19990. - u64 capabilities;
  19991. + u64 capabilities = x86_pmu.intel_cap.capabilities;
  19992. - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
  19993. - x86_pmu.intel_cap.capabilities = capabilities;
  19994. + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
  19995. + x86_pmu.intel_cap.capabilities = capabilities;
  19996. }
  19997. intel_ds_init();
  19998. diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
  19999. index 5ad35ad..e0a3960 100644
  20000. --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
  20001. +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
  20002. @@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
  20003. NULL,
  20004. };
  20005. -static struct attribute_group rapl_pmu_events_group = {
  20006. +static attribute_group_no_const rapl_pmu_events_group __read_only = {
  20007. .name = "events",
  20008. .attrs = NULL, /* patched at runtime */
  20009. };
  20010. diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
  20011. index 047f540..afdeba0 100644
  20012. --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
  20013. +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
  20014. @@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
  20015. static int __init uncore_type_init(struct intel_uncore_type *type)
  20016. {
  20017. struct intel_uncore_pmu *pmus;
  20018. - struct attribute_group *attr_group;
  20019. + attribute_group_no_const *attr_group;
  20020. struct attribute **attrs;
  20021. int i, j;
  20022. diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
  20023. index a80ab71..4089da5 100644
  20024. --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
  20025. +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
  20026. @@ -498,7 +498,7 @@ struct intel_uncore_box {
  20027. struct uncore_event_desc {
  20028. struct kobj_attribute attr;
  20029. const char *config;
  20030. -};
  20031. +} __do_const;
  20032. #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
  20033. { \
  20034. diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
  20035. index 7d9481c..99c7e4b 100644
  20036. --- a/arch/x86/kernel/cpuid.c
  20037. +++ b/arch/x86/kernel/cpuid.c
  20038. @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
  20039. return notifier_from_errno(err);
  20040. }
  20041. -static struct notifier_block __refdata cpuid_class_cpu_notifier =
  20042. +static struct notifier_block cpuid_class_cpu_notifier =
  20043. {
  20044. .notifier_call = cpuid_class_cpu_callback,
  20045. };
  20046. diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
  20047. index a57902e..ebaae2a 100644
  20048. --- a/arch/x86/kernel/crash.c
  20049. +++ b/arch/x86/kernel/crash.c
  20050. @@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
  20051. {
  20052. #ifdef CONFIG_X86_32
  20053. struct pt_regs fixed_regs;
  20054. -#endif
  20055. -#ifdef CONFIG_X86_32
  20056. - if (!user_mode_vm(regs)) {
  20057. + if (!user_mode(regs)) {
  20058. crash_fixup_ss_esp(&fixed_regs, regs);
  20059. regs = &fixed_regs;
  20060. }
  20061. diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
  20062. index afa64ad..dce67dd 100644
  20063. --- a/arch/x86/kernel/crash_dump_64.c
  20064. +++ b/arch/x86/kernel/crash_dump_64.c
  20065. @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
  20066. return -ENOMEM;
  20067. if (userbuf) {
  20068. - if (copy_to_user(buf, vaddr + offset, csize)) {
  20069. + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
  20070. iounmap(vaddr);
  20071. return -EFAULT;
  20072. }
  20073. diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
  20074. index f6dfd93..892ade4 100644
  20075. --- a/arch/x86/kernel/doublefault.c
  20076. +++ b/arch/x86/kernel/doublefault.c
  20077. @@ -12,7 +12,7 @@
  20078. #define DOUBLEFAULT_STACKSIZE (1024)
  20079. static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
  20080. -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
  20081. +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
  20082. #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
  20083. @@ -22,7 +22,7 @@ static void doublefault_fn(void)
  20084. unsigned long gdt, tss;
  20085. native_store_gdt(&gdt_desc);
  20086. - gdt = gdt_desc.address;
  20087. + gdt = (unsigned long)gdt_desc.address;
  20088. printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
  20089. @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
  20090. /* 0x2 bit is always set */
  20091. .flags = X86_EFLAGS_SF | 0x2,
  20092. .sp = STACK_START,
  20093. - .es = __USER_DS,
  20094. + .es = __KERNEL_DS,
  20095. .cs = __KERNEL_CS,
  20096. .ss = __KERNEL_DS,
  20097. - .ds = __USER_DS,
  20098. + .ds = __KERNEL_DS,
  20099. .fs = __KERNEL_PERCPU,
  20100. .__cr3 = __pa_nodebug(swapper_pg_dir),
  20101. diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
  20102. index d9c12d3..7858b62 100644
  20103. --- a/arch/x86/kernel/dumpstack.c
  20104. +++ b/arch/x86/kernel/dumpstack.c
  20105. @@ -2,6 +2,9 @@
  20106. * Copyright (C) 1991, 1992 Linus Torvalds
  20107. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  20108. */
  20109. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  20110. +#define __INCLUDED_BY_HIDESYM 1
  20111. +#endif
  20112. #include <linux/kallsyms.h>
  20113. #include <linux/kprobes.h>
  20114. #include <linux/uaccess.h>
  20115. @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
  20116. static void
  20117. print_ftrace_graph_addr(unsigned long addr, void *data,
  20118. const struct stacktrace_ops *ops,
  20119. - struct thread_info *tinfo, int *graph)
  20120. + struct task_struct *task, int *graph)
  20121. {
  20122. - struct task_struct *task;
  20123. unsigned long ret_addr;
  20124. int index;
  20125. if (addr != (unsigned long)return_to_handler)
  20126. return;
  20127. - task = tinfo->task;
  20128. index = task->curr_ret_stack;
  20129. if (!task->ret_stack || index < *graph)
  20130. @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
  20131. static inline void
  20132. print_ftrace_graph_addr(unsigned long addr, void *data,
  20133. const struct stacktrace_ops *ops,
  20134. - struct thread_info *tinfo, int *graph)
  20135. + struct task_struct *task, int *graph)
  20136. { }
  20137. #endif
  20138. @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
  20139. * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
  20140. */
  20141. -static inline int valid_stack_ptr(struct thread_info *tinfo,
  20142. - void *p, unsigned int size, void *end)
  20143. +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
  20144. {
  20145. - void *t = tinfo;
  20146. if (end) {
  20147. if (p < end && p >= (end-THREAD_SIZE))
  20148. return 1;
  20149. @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
  20150. }
  20151. unsigned long
  20152. -print_context_stack(struct thread_info *tinfo,
  20153. +print_context_stack(struct task_struct *task, void *stack_start,
  20154. unsigned long *stack, unsigned long bp,
  20155. const struct stacktrace_ops *ops, void *data,
  20156. unsigned long *end, int *graph)
  20157. {
  20158. struct stack_frame *frame = (struct stack_frame *)bp;
  20159. - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
  20160. + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
  20161. unsigned long addr;
  20162. addr = *stack;
  20163. @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
  20164. } else {
  20165. ops->address(data, addr, 0);
  20166. }
  20167. - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
  20168. + print_ftrace_graph_addr(addr, data, ops, task, graph);
  20169. }
  20170. stack++;
  20171. }
  20172. @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
  20173. EXPORT_SYMBOL_GPL(print_context_stack);
  20174. unsigned long
  20175. -print_context_stack_bp(struct thread_info *tinfo,
  20176. +print_context_stack_bp(struct task_struct *task, void *stack_start,
  20177. unsigned long *stack, unsigned long bp,
  20178. const struct stacktrace_ops *ops, void *data,
  20179. unsigned long *end, int *graph)
  20180. @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
  20181. struct stack_frame *frame = (struct stack_frame *)bp;
  20182. unsigned long *ret_addr = &frame->return_address;
  20183. - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
  20184. + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
  20185. unsigned long addr = *ret_addr;
  20186. if (!__kernel_text_address(addr))
  20187. @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
  20188. ops->address(data, addr, 1);
  20189. frame = frame->next_frame;
  20190. ret_addr = &frame->return_address;
  20191. - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
  20192. + print_ftrace_graph_addr(addr, data, ops, task, graph);
  20193. }
  20194. return (unsigned long)frame;
  20195. @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
  20196. static void print_trace_address(void *data, unsigned long addr, int reliable)
  20197. {
  20198. touch_nmi_watchdog();
  20199. - printk(data);
  20200. + printk("%s", (char *)data);
  20201. printk_stack_address(addr, reliable);
  20202. }
  20203. @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
  20204. }
  20205. EXPORT_SYMBOL_GPL(oops_begin);
  20206. +extern void gr_handle_kernel_exploit(void);
  20207. +
  20208. void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
  20209. {
  20210. if (regs && kexec_should_crash(current))
  20211. @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
  20212. panic("Fatal exception in interrupt");
  20213. if (panic_on_oops)
  20214. panic("Fatal exception");
  20215. - do_exit(signr);
  20216. +
  20217. + gr_handle_kernel_exploit();
  20218. +
  20219. + do_group_exit(signr);
  20220. }
  20221. int __kprobes __die(const char *str, struct pt_regs *regs, long err)
  20222. @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
  20223. print_modules();
  20224. show_regs(regs);
  20225. #ifdef CONFIG_X86_32
  20226. - if (user_mode_vm(regs)) {
  20227. + if (user_mode(regs)) {
  20228. sp = regs->sp;
  20229. ss = regs->ss & 0xffff;
  20230. } else {
  20231. @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
  20232. unsigned long flags = oops_begin();
  20233. int sig = SIGSEGV;
  20234. - if (!user_mode_vm(regs))
  20235. + if (!user_mode(regs))
  20236. report_bug(regs->ip, regs);
  20237. if (__die(str, regs, err))
  20238. diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
  20239. index f2a1770..10fa52d 100644
  20240. --- a/arch/x86/kernel/dumpstack_32.c
  20241. +++ b/arch/x86/kernel/dumpstack_32.c
  20242. @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20243. bp = stack_frame(task, regs);
  20244. for (;;) {
  20245. - struct thread_info *context;
  20246. + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
  20247. - context = (struct thread_info *)
  20248. - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
  20249. - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
  20250. + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
  20251. - stack = (unsigned long *)context->previous_esp;
  20252. - if (!stack)
  20253. + if (stack_start == task_stack_page(task))
  20254. break;
  20255. + stack = *(unsigned long **)stack_start;
  20256. if (ops->stack(data, "IRQ") < 0)
  20257. break;
  20258. touch_nmi_watchdog();
  20259. @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
  20260. int i;
  20261. show_regs_print_info(KERN_EMERG);
  20262. - __show_regs(regs, !user_mode_vm(regs));
  20263. + __show_regs(regs, !user_mode(regs));
  20264. /*
  20265. * When in-kernel, we also print out the stack and code at the
  20266. * time of the fault..
  20267. */
  20268. - if (!user_mode_vm(regs)) {
  20269. + if (!user_mode(regs)) {
  20270. unsigned int code_prologue = code_bytes * 43 / 64;
  20271. unsigned int code_len = code_bytes;
  20272. unsigned char c;
  20273. u8 *ip;
  20274. + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
  20275. pr_emerg("Stack:\n");
  20276. show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
  20277. pr_emerg("Code:");
  20278. - ip = (u8 *)regs->ip - code_prologue;
  20279. + ip = (u8 *)regs->ip - code_prologue + cs_base;
  20280. if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
  20281. /* try starting at IP */
  20282. - ip = (u8 *)regs->ip;
  20283. + ip = (u8 *)regs->ip + cs_base;
  20284. code_len = code_len - code_prologue + 1;
  20285. }
  20286. for (i = 0; i < code_len; i++, ip++) {
  20287. @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
  20288. pr_cont(" Bad EIP value.");
  20289. break;
  20290. }
  20291. - if (ip == (u8 *)regs->ip)
  20292. + if (ip == (u8 *)regs->ip + cs_base)
  20293. pr_cont(" <%02x>", c);
  20294. else
  20295. pr_cont(" %02x", c);
  20296. @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
  20297. {
  20298. unsigned short ud2;
  20299. + ip = ktla_ktva(ip);
  20300. if (ip < PAGE_OFFSET)
  20301. return 0;
  20302. if (probe_kernel_address((unsigned short *)ip, ud2))
  20303. @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
  20304. return ud2 == 0x0b0f;
  20305. }
  20306. +
  20307. +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
  20308. +void pax_check_alloca(unsigned long size)
  20309. +{
  20310. + unsigned long sp = (unsigned long)&sp, stack_left;
  20311. +
  20312. + /* all kernel stacks are of the same size */
  20313. + stack_left = sp & (THREAD_SIZE - 1);
  20314. + BUG_ON(stack_left < 256 || size >= stack_left - 256);
  20315. +}
  20316. +EXPORT_SYMBOL(pax_check_alloca);
  20317. +#endif
  20318. diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
  20319. index addb207..921706b 100644
  20320. --- a/arch/x86/kernel/dumpstack_64.c
  20321. +++ b/arch/x86/kernel/dumpstack_64.c
  20322. @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20323. unsigned long *irq_stack_end =
  20324. (unsigned long *)per_cpu(irq_stack_ptr, cpu);
  20325. unsigned used = 0;
  20326. - struct thread_info *tinfo;
  20327. int graph = 0;
  20328. unsigned long dummy;
  20329. + void *stack_start;
  20330. if (!task)
  20331. task = current;
  20332. @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20333. * current stack address. If the stacks consist of nested
  20334. * exceptions
  20335. */
  20336. - tinfo = task_thread_info(task);
  20337. for (;;) {
  20338. char *id;
  20339. unsigned long *estack_end;
  20340. +
  20341. estack_end = in_exception_stack(cpu, (unsigned long)stack,
  20342. &used, &id);
  20343. @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20344. if (ops->stack(data, id) < 0)
  20345. break;
  20346. - bp = ops->walk_stack(tinfo, stack, bp, ops,
  20347. + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
  20348. data, estack_end, &graph);
  20349. ops->stack(data, "<EOE>");
  20350. /*
  20351. @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20352. * second-to-last pointer (index -2 to end) in the
  20353. * exception stack:
  20354. */
  20355. + if ((u16)estack_end[-1] != __KERNEL_DS)
  20356. + goto out;
  20357. stack = (unsigned long *) estack_end[-2];
  20358. continue;
  20359. }
  20360. @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20361. if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
  20362. if (ops->stack(data, "IRQ") < 0)
  20363. break;
  20364. - bp = ops->walk_stack(tinfo, stack, bp,
  20365. + bp = ops->walk_stack(task, irq_stack, stack, bp,
  20366. ops, data, irq_stack_end, &graph);
  20367. /*
  20368. * We link to the next stack (which would be
  20369. @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
  20370. /*
  20371. * This handles the process stack:
  20372. */
  20373. - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
  20374. + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
  20375. + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
  20376. +out:
  20377. put_cpu();
  20378. }
  20379. EXPORT_SYMBOL(dump_trace);
  20380. @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
  20381. return ud2 == 0x0b0f;
  20382. }
  20383. +
  20384. +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
  20385. +void pax_check_alloca(unsigned long size)
  20386. +{
  20387. + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
  20388. + unsigned cpu, used;
  20389. + char *id;
  20390. +
  20391. + /* check the process stack first */
  20392. + stack_start = (unsigned long)task_stack_page(current);
  20393. + stack_end = stack_start + THREAD_SIZE;
  20394. + if (likely(stack_start <= sp && sp < stack_end)) {
  20395. + unsigned long stack_left = sp & (THREAD_SIZE - 1);
  20396. + BUG_ON(stack_left < 256 || size >= stack_left - 256);
  20397. + return;
  20398. + }
  20399. +
  20400. + cpu = get_cpu();
  20401. +
  20402. + /* check the irq stacks */
  20403. + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
  20404. + stack_start = stack_end - IRQ_STACK_SIZE;
  20405. + if (stack_start <= sp && sp < stack_end) {
  20406. + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
  20407. + put_cpu();
  20408. + BUG_ON(stack_left < 256 || size >= stack_left - 256);
  20409. + return;
  20410. + }
  20411. +
  20412. + /* check the exception stacks */
  20413. + used = 0;
  20414. + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
  20415. + stack_start = stack_end - EXCEPTION_STKSZ;
  20416. + if (stack_end && stack_start <= sp && sp < stack_end) {
  20417. + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
  20418. + put_cpu();
  20419. + BUG_ON(stack_left < 256 || size >= stack_left - 256);
  20420. + return;
  20421. + }
  20422. +
  20423. + put_cpu();
  20424. +
  20425. + /* unknown stack */
  20426. + BUG();
  20427. +}
  20428. +EXPORT_SYMBOL(pax_check_alloca);
  20429. +#endif
  20430. diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
  20431. index 988c00a..4f673b6 100644
  20432. --- a/arch/x86/kernel/e820.c
  20433. +++ b/arch/x86/kernel/e820.c
  20434. @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
  20435. static void early_panic(char *msg)
  20436. {
  20437. - early_printk(msg);
  20438. - panic(msg);
  20439. + early_printk("%s", msg);
  20440. + panic("%s", msg);
  20441. }
  20442. static int userdef __initdata;
  20443. diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
  20444. index 01d1c18..8073693 100644
  20445. --- a/arch/x86/kernel/early_printk.c
  20446. +++ b/arch/x86/kernel/early_printk.c
  20447. @@ -7,6 +7,7 @@
  20448. #include <linux/pci_regs.h>
  20449. #include <linux/pci_ids.h>
  20450. #include <linux/errno.h>
  20451. +#include <linux/sched.h>
  20452. #include <asm/io.h>
  20453. #include <asm/processor.h>
  20454. #include <asm/fcntl.h>
  20455. diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
  20456. index a2a4f46..6cab058 100644
  20457. --- a/arch/x86/kernel/entry_32.S
  20458. +++ b/arch/x86/kernel/entry_32.S
  20459. @@ -177,13 +177,153 @@
  20460. /*CFI_REL_OFFSET gs, PT_GS*/
  20461. .endm
  20462. .macro SET_KERNEL_GS reg
  20463. +
  20464. +#ifdef CONFIG_CC_STACKPROTECTOR
  20465. movl $(__KERNEL_STACK_CANARY), \reg
  20466. +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
  20467. + movl $(__USER_DS), \reg
  20468. +#else
  20469. + xorl \reg, \reg
  20470. +#endif
  20471. +
  20472. movl \reg, %gs
  20473. .endm
  20474. #endif /* CONFIG_X86_32_LAZY_GS */
  20475. -.macro SAVE_ALL
  20476. +.macro pax_enter_kernel
  20477. +#ifdef CONFIG_PAX_KERNEXEC
  20478. + call pax_enter_kernel
  20479. +#endif
  20480. +.endm
  20481. +
  20482. +.macro pax_exit_kernel
  20483. +#ifdef CONFIG_PAX_KERNEXEC
  20484. + call pax_exit_kernel
  20485. +#endif
  20486. +.endm
  20487. +
  20488. +#ifdef CONFIG_PAX_KERNEXEC
  20489. +ENTRY(pax_enter_kernel)
  20490. +#ifdef CONFIG_PARAVIRT
  20491. + pushl %eax
  20492. + pushl %ecx
  20493. + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
  20494. + mov %eax, %esi
  20495. +#else
  20496. + mov %cr0, %esi
  20497. +#endif
  20498. + bts $16, %esi
  20499. + jnc 1f
  20500. + mov %cs, %esi
  20501. + cmp $__KERNEL_CS, %esi
  20502. + jz 3f
  20503. + ljmp $__KERNEL_CS, $3f
  20504. +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
  20505. +2:
  20506. +#ifdef CONFIG_PARAVIRT
  20507. + mov %esi, %eax
  20508. + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
  20509. +#else
  20510. + mov %esi, %cr0
  20511. +#endif
  20512. +3:
  20513. +#ifdef CONFIG_PARAVIRT
  20514. + popl %ecx
  20515. + popl %eax
  20516. +#endif
  20517. + ret
  20518. +ENDPROC(pax_enter_kernel)
  20519. +
  20520. +ENTRY(pax_exit_kernel)
  20521. +#ifdef CONFIG_PARAVIRT
  20522. + pushl %eax
  20523. + pushl %ecx
  20524. +#endif
  20525. + mov %cs, %esi
  20526. + cmp $__KERNEXEC_KERNEL_CS, %esi
  20527. + jnz 2f
  20528. +#ifdef CONFIG_PARAVIRT
  20529. + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
  20530. + mov %eax, %esi
  20531. +#else
  20532. + mov %cr0, %esi
  20533. +#endif
  20534. + btr $16, %esi
  20535. + ljmp $__KERNEL_CS, $1f
  20536. +1:
  20537. +#ifdef CONFIG_PARAVIRT
  20538. + mov %esi, %eax
  20539. + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
  20540. +#else
  20541. + mov %esi, %cr0
  20542. +#endif
  20543. +2:
  20544. +#ifdef CONFIG_PARAVIRT
  20545. + popl %ecx
  20546. + popl %eax
  20547. +#endif
  20548. + ret
  20549. +ENDPROC(pax_exit_kernel)
  20550. +#endif
  20551. +
  20552. + .macro pax_erase_kstack
  20553. +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
  20554. + call pax_erase_kstack
  20555. +#endif
  20556. + .endm
  20557. +
  20558. +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
  20559. +/*
  20560. + * ebp: thread_info
  20561. + */
  20562. +ENTRY(pax_erase_kstack)
  20563. + pushl %edi
  20564. + pushl %ecx
  20565. + pushl %eax
  20566. +
  20567. + mov TI_lowest_stack(%ebp), %edi
  20568. + mov $-0xBEEF, %eax
  20569. + std
  20570. +
  20571. +1: mov %edi, %ecx
  20572. + and $THREAD_SIZE_asm - 1, %ecx
  20573. + shr $2, %ecx
  20574. + repne scasl
  20575. + jecxz 2f
  20576. +
  20577. + cmp $2*16, %ecx
  20578. + jc 2f
  20579. +
  20580. + mov $2*16, %ecx
  20581. + repe scasl
  20582. + jecxz 2f
  20583. + jne 1b
  20584. +
  20585. +2: cld
  20586. + mov %esp, %ecx
  20587. + sub %edi, %ecx
  20588. +
  20589. + cmp $THREAD_SIZE_asm, %ecx
  20590. + jb 3f
  20591. + ud2
  20592. +3:
  20593. +
  20594. + shr $2, %ecx
  20595. + rep stosl
  20596. +
  20597. + mov TI_task_thread_sp0(%ebp), %edi
  20598. + sub $128, %edi
  20599. + mov %edi, TI_lowest_stack(%ebp)
  20600. +
  20601. + popl %eax
  20602. + popl %ecx
  20603. + popl %edi
  20604. + ret
  20605. +ENDPROC(pax_erase_kstack)
  20606. +#endif
  20607. +
  20608. +.macro __SAVE_ALL _DS
  20609. cld
  20610. PUSH_GS
  20611. pushl_cfi %fs
  20612. @@ -206,7 +346,7 @@
  20613. CFI_REL_OFFSET ecx, 0
  20614. pushl_cfi %ebx
  20615. CFI_REL_OFFSET ebx, 0
  20616. - movl $(__USER_DS), %edx
  20617. + movl $\_DS, %edx
  20618. movl %edx, %ds
  20619. movl %edx, %es
  20620. movl $(__KERNEL_PERCPU), %edx
  20621. @@ -214,6 +354,15 @@
  20622. SET_KERNEL_GS %edx
  20623. .endm
  20624. +.macro SAVE_ALL
  20625. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  20626. + __SAVE_ALL __KERNEL_DS
  20627. + pax_enter_kernel
  20628. +#else
  20629. + __SAVE_ALL __USER_DS
  20630. +#endif
  20631. +.endm
  20632. +
  20633. .macro RESTORE_INT_REGS
  20634. popl_cfi %ebx
  20635. CFI_RESTORE ebx
  20636. @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
  20637. popfl_cfi
  20638. jmp syscall_exit
  20639. CFI_ENDPROC
  20640. -END(ret_from_fork)
  20641. +ENDPROC(ret_from_fork)
  20642. ENTRY(ret_from_kernel_thread)
  20643. CFI_STARTPROC
  20644. @@ -344,7 +493,15 @@ ret_from_intr:
  20645. andl $SEGMENT_RPL_MASK, %eax
  20646. #endif
  20647. cmpl $USER_RPL, %eax
  20648. +
  20649. +#ifdef CONFIG_PAX_KERNEXEC
  20650. + jae resume_userspace
  20651. +
  20652. + pax_exit_kernel
  20653. + jmp resume_kernel
  20654. +#else
  20655. jb resume_kernel # not returning to v8086 or userspace
  20656. +#endif
  20657. ENTRY(resume_userspace)
  20658. LOCKDEP_SYS_EXIT
  20659. @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
  20660. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  20661. # int/exception return?
  20662. jne work_pending
  20663. - jmp restore_all
  20664. -END(ret_from_exception)
  20665. + jmp restore_all_pax
  20666. +ENDPROC(ret_from_exception)
  20667. #ifdef CONFIG_PREEMPT
  20668. ENTRY(resume_kernel)
  20669. @@ -369,7 +526,7 @@ need_resched:
  20670. jz restore_all
  20671. call preempt_schedule_irq
  20672. jmp need_resched
  20673. -END(resume_kernel)
  20674. +ENDPROC(resume_kernel)
  20675. #endif
  20676. CFI_ENDPROC
  20677. /*
  20678. @@ -403,30 +560,45 @@ sysenter_past_esp:
  20679. /*CFI_REL_OFFSET cs, 0*/
  20680. /*
  20681. * Push current_thread_info()->sysenter_return to the stack.
  20682. - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  20683. - * pushed above; +8 corresponds to copy_thread's esp0 setting.
  20684. */
  20685. - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
  20686. + pushl_cfi $0
  20687. CFI_REL_OFFSET eip, 0
  20688. pushl_cfi %eax
  20689. SAVE_ALL
  20690. + GET_THREAD_INFO(%ebp)
  20691. + movl TI_sysenter_return(%ebp),%ebp
  20692. + movl %ebp,PT_EIP(%esp)
  20693. ENABLE_INTERRUPTS(CLBR_NONE)
  20694. /*
  20695. * Load the potential sixth argument from user stack.
  20696. * Careful about security.
  20697. */
  20698. + movl PT_OLDESP(%esp),%ebp
  20699. +
  20700. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  20701. + mov PT_OLDSS(%esp),%ds
  20702. +1: movl %ds:(%ebp),%ebp
  20703. + push %ss
  20704. + pop %ds
  20705. +#else
  20706. cmpl $__PAGE_OFFSET-3,%ebp
  20707. jae syscall_fault
  20708. ASM_STAC
  20709. 1: movl (%ebp),%ebp
  20710. ASM_CLAC
  20711. +#endif
  20712. +
  20713. movl %ebp,PT_EBP(%esp)
  20714. _ASM_EXTABLE(1b,syscall_fault)
  20715. GET_THREAD_INFO(%ebp)
  20716. +#ifdef CONFIG_PAX_RANDKSTACK
  20717. + pax_erase_kstack
  20718. +#endif
  20719. +
  20720. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  20721. jnz sysenter_audit
  20722. sysenter_do_call:
  20723. @@ -441,12 +613,24 @@ sysenter_do_call:
  20724. testl $_TIF_ALLWORK_MASK, %ecx
  20725. jne sysexit_audit
  20726. sysenter_exit:
  20727. +
  20728. +#ifdef CONFIG_PAX_RANDKSTACK
  20729. + pushl_cfi %eax
  20730. + movl %esp, %eax
  20731. + call pax_randomize_kstack
  20732. + popl_cfi %eax
  20733. +#endif
  20734. +
  20735. + pax_erase_kstack
  20736. +
  20737. /* if something modifies registers it must also disable sysexit */
  20738. movl PT_EIP(%esp), %edx
  20739. movl PT_OLDESP(%esp), %ecx
  20740. xorl %ebp,%ebp
  20741. TRACE_IRQS_ON
  20742. 1: mov PT_FS(%esp), %fs
  20743. +2: mov PT_DS(%esp), %ds
  20744. +3: mov PT_ES(%esp), %es
  20745. PTGS_TO_GS
  20746. ENABLE_INTERRUPTS_SYSEXIT
  20747. @@ -463,6 +647,9 @@ sysenter_audit:
  20748. movl %eax,%edx /* 2nd arg: syscall number */
  20749. movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
  20750. call __audit_syscall_entry
  20751. +
  20752. + pax_erase_kstack
  20753. +
  20754. pushl_cfi %ebx
  20755. movl PT_EAX(%esp),%eax /* reload syscall number */
  20756. jmp sysenter_do_call
  20757. @@ -488,10 +675,16 @@ sysexit_audit:
  20758. CFI_ENDPROC
  20759. .pushsection .fixup,"ax"
  20760. -2: movl $0,PT_FS(%esp)
  20761. +4: movl $0,PT_FS(%esp)
  20762. + jmp 1b
  20763. +5: movl $0,PT_DS(%esp)
  20764. + jmp 1b
  20765. +6: movl $0,PT_ES(%esp)
  20766. jmp 1b
  20767. .popsection
  20768. - _ASM_EXTABLE(1b,2b)
  20769. + _ASM_EXTABLE(1b,4b)
  20770. + _ASM_EXTABLE(2b,5b)
  20771. + _ASM_EXTABLE(3b,6b)
  20772. PTGS_TO_GS_EX
  20773. ENDPROC(ia32_sysenter_target)
  20774. @@ -506,6 +699,11 @@ ENTRY(system_call)
  20775. pushl_cfi %eax # save orig_eax
  20776. SAVE_ALL
  20777. GET_THREAD_INFO(%ebp)
  20778. +
  20779. +#ifdef CONFIG_PAX_RANDKSTACK
  20780. + pax_erase_kstack
  20781. +#endif
  20782. +
  20783. # system call tracing in operation / emulation
  20784. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  20785. jnz syscall_trace_entry
  20786. @@ -524,6 +722,15 @@ syscall_exit:
  20787. testl $_TIF_ALLWORK_MASK, %ecx # current->work
  20788. jne syscall_exit_work
  20789. +restore_all_pax:
  20790. +
  20791. +#ifdef CONFIG_PAX_RANDKSTACK
  20792. + movl %esp, %eax
  20793. + call pax_randomize_kstack
  20794. +#endif
  20795. +
  20796. + pax_erase_kstack
  20797. +
  20798. restore_all:
  20799. TRACE_IRQS_IRET
  20800. restore_all_notrace:
  20801. @@ -580,14 +787,34 @@ ldt_ss:
  20802. * compensating for the offset by changing to the ESPFIX segment with
  20803. * a base address that matches for the difference.
  20804. */
  20805. -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
  20806. +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
  20807. mov %esp, %edx /* load kernel esp */
  20808. mov PT_OLDESP(%esp), %eax /* load userspace esp */
  20809. mov %dx, %ax /* eax: new kernel esp */
  20810. sub %eax, %edx /* offset (low word is 0) */
  20811. +#ifdef CONFIG_SMP
  20812. + movl PER_CPU_VAR(cpu_number), %ebx
  20813. + shll $PAGE_SHIFT_asm, %ebx
  20814. + addl $cpu_gdt_table, %ebx
  20815. +#else
  20816. + movl $cpu_gdt_table, %ebx
  20817. +#endif
  20818. shr $16, %edx
  20819. - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
  20820. - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
  20821. +
  20822. +#ifdef CONFIG_PAX_KERNEXEC
  20823. + mov %cr0, %esi
  20824. + btr $16, %esi
  20825. + mov %esi, %cr0
  20826. +#endif
  20827. +
  20828. + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
  20829. + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
  20830. +
  20831. +#ifdef CONFIG_PAX_KERNEXEC
  20832. + bts $16, %esi
  20833. + mov %esi, %cr0
  20834. +#endif
  20835. +
  20836. pushl_cfi $__ESPFIX_SS
  20837. pushl_cfi %eax /* new kernel esp */
  20838. /* Disable interrupts, but do not irqtrace this section: we
  20839. @@ -616,20 +843,18 @@ work_resched:
  20840. movl TI_flags(%ebp), %ecx
  20841. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  20842. # than syscall tracing?
  20843. - jz restore_all
  20844. + jz restore_all_pax
  20845. testb $_TIF_NEED_RESCHED, %cl
  20846. jnz work_resched
  20847. work_notifysig: # deal with pending signals and
  20848. # notify-resume requests
  20849. + movl %esp, %eax
  20850. #ifdef CONFIG_VM86
  20851. testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
  20852. - movl %esp, %eax
  20853. jne work_notifysig_v86 # returning to kernel-space or
  20854. # vm86-space
  20855. 1:
  20856. -#else
  20857. - movl %esp, %eax
  20858. #endif
  20859. TRACE_IRQS_ON
  20860. ENABLE_INTERRUPTS(CLBR_NONE)
  20861. @@ -650,7 +875,7 @@ work_notifysig_v86:
  20862. movl %eax, %esp
  20863. jmp 1b
  20864. #endif
  20865. -END(work_pending)
  20866. +ENDPROC(work_pending)
  20867. # perform syscall exit tracing
  20868. ALIGN
  20869. @@ -658,11 +883,14 @@ syscall_trace_entry:
  20870. movl $-ENOSYS,PT_EAX(%esp)
  20871. movl %esp, %eax
  20872. call syscall_trace_enter
  20873. +
  20874. + pax_erase_kstack
  20875. +
  20876. /* What it returned is what we'll actually use. */
  20877. cmpl $(NR_syscalls), %eax
  20878. jnae syscall_call
  20879. jmp syscall_exit
  20880. -END(syscall_trace_entry)
  20881. +ENDPROC(syscall_trace_entry)
  20882. # perform syscall exit tracing
  20883. ALIGN
  20884. @@ -675,21 +903,25 @@ syscall_exit_work:
  20885. movl %esp, %eax
  20886. call syscall_trace_leave
  20887. jmp resume_userspace
  20888. -END(syscall_exit_work)
  20889. +ENDPROC(syscall_exit_work)
  20890. CFI_ENDPROC
  20891. RING0_INT_FRAME # can't unwind into user space anyway
  20892. syscall_fault:
  20893. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  20894. + push %ss
  20895. + pop %ds
  20896. +#endif
  20897. ASM_CLAC
  20898. GET_THREAD_INFO(%ebp)
  20899. movl $-EFAULT,PT_EAX(%esp)
  20900. jmp resume_userspace
  20901. -END(syscall_fault)
  20902. +ENDPROC(syscall_fault)
  20903. syscall_badsys:
  20904. movl $-ENOSYS,PT_EAX(%esp)
  20905. jmp resume_userspace
  20906. -END(syscall_badsys)
  20907. +ENDPROC(syscall_badsys)
  20908. CFI_ENDPROC
  20909. /*
  20910. * End of kprobes section
  20911. @@ -705,8 +937,15 @@ END(syscall_badsys)
  20912. * normal stack and adjusts ESP with the matching offset.
  20913. */
  20914. /* fixup the stack */
  20915. - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
  20916. - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
  20917. +#ifdef CONFIG_SMP
  20918. + movl PER_CPU_VAR(cpu_number), %ebx
  20919. + shll $PAGE_SHIFT_asm, %ebx
  20920. + addl $cpu_gdt_table, %ebx
  20921. +#else
  20922. + movl $cpu_gdt_table, %ebx
  20923. +#endif
  20924. + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
  20925. + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
  20926. shl $16, %eax
  20927. addl %esp, %eax /* the adjusted stack pointer */
  20928. pushl_cfi $__KERNEL_DS
  20929. @@ -759,7 +998,7 @@ vector=vector+1
  20930. .endr
  20931. 2: jmp common_interrupt
  20932. .endr
  20933. -END(irq_entries_start)
  20934. +ENDPROC(irq_entries_start)
  20935. .previous
  20936. END(interrupt)
  20937. @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
  20938. pushl_cfi $do_coprocessor_error
  20939. jmp error_code
  20940. CFI_ENDPROC
  20941. -END(coprocessor_error)
  20942. +ENDPROC(coprocessor_error)
  20943. ENTRY(simd_coprocessor_error)
  20944. RING0_INT_FRAME
  20945. @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
  20946. .section .altinstructions,"a"
  20947. altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
  20948. .previous
  20949. -.section .altinstr_replacement,"ax"
  20950. +.section .altinstr_replacement,"a"
  20951. 663: pushl $do_simd_coprocessor_error
  20952. 664:
  20953. .previous
  20954. @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
  20955. #endif
  20956. jmp error_code
  20957. CFI_ENDPROC
  20958. -END(simd_coprocessor_error)
  20959. +ENDPROC(simd_coprocessor_error)
  20960. ENTRY(device_not_available)
  20961. RING0_INT_FRAME
  20962. @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
  20963. pushl_cfi $do_device_not_available
  20964. jmp error_code
  20965. CFI_ENDPROC
  20966. -END(device_not_available)
  20967. +ENDPROC(device_not_available)
  20968. #ifdef CONFIG_PARAVIRT
  20969. ENTRY(native_iret)
  20970. iret
  20971. _ASM_EXTABLE(native_iret, iret_exc)
  20972. -END(native_iret)
  20973. +ENDPROC(native_iret)
  20974. ENTRY(native_irq_enable_sysexit)
  20975. sti
  20976. sysexit
  20977. -END(native_irq_enable_sysexit)
  20978. +ENDPROC(native_irq_enable_sysexit)
  20979. #endif
  20980. ENTRY(overflow)
  20981. @@ -872,7 +1111,7 @@ ENTRY(overflow)
  20982. pushl_cfi $do_overflow
  20983. jmp error_code
  20984. CFI_ENDPROC
  20985. -END(overflow)
  20986. +ENDPROC(overflow)
  20987. ENTRY(bounds)
  20988. RING0_INT_FRAME
  20989. @@ -881,7 +1120,7 @@ ENTRY(bounds)
  20990. pushl_cfi $do_bounds
  20991. jmp error_code
  20992. CFI_ENDPROC
  20993. -END(bounds)
  20994. +ENDPROC(bounds)
  20995. ENTRY(invalid_op)
  20996. RING0_INT_FRAME
  20997. @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
  20998. pushl_cfi $do_invalid_op
  20999. jmp error_code
  21000. CFI_ENDPROC
  21001. -END(invalid_op)
  21002. +ENDPROC(invalid_op)
  21003. ENTRY(coprocessor_segment_overrun)
  21004. RING0_INT_FRAME
  21005. @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
  21006. pushl_cfi $do_coprocessor_segment_overrun
  21007. jmp error_code
  21008. CFI_ENDPROC
  21009. -END(coprocessor_segment_overrun)
  21010. +ENDPROC(coprocessor_segment_overrun)
  21011. ENTRY(invalid_TSS)
  21012. RING0_EC_FRAME
  21013. @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
  21014. pushl_cfi $do_invalid_TSS
  21015. jmp error_code
  21016. CFI_ENDPROC
  21017. -END(invalid_TSS)
  21018. +ENDPROC(invalid_TSS)
  21019. ENTRY(segment_not_present)
  21020. RING0_EC_FRAME
  21021. @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
  21022. pushl_cfi $do_segment_not_present
  21023. jmp error_code
  21024. CFI_ENDPROC
  21025. -END(segment_not_present)
  21026. +ENDPROC(segment_not_present)
  21027. ENTRY(stack_segment)
  21028. RING0_EC_FRAME
  21029. @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
  21030. pushl_cfi $do_stack_segment
  21031. jmp error_code
  21032. CFI_ENDPROC
  21033. -END(stack_segment)
  21034. +ENDPROC(stack_segment)
  21035. ENTRY(alignment_check)
  21036. RING0_EC_FRAME
  21037. @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
  21038. pushl_cfi $do_alignment_check
  21039. jmp error_code
  21040. CFI_ENDPROC
  21041. -END(alignment_check)
  21042. +ENDPROC(alignment_check)
  21043. ENTRY(divide_error)
  21044. RING0_INT_FRAME
  21045. @@ -940,7 +1179,7 @@ ENTRY(divide_error)
  21046. pushl_cfi $do_divide_error
  21047. jmp error_code
  21048. CFI_ENDPROC
  21049. -END(divide_error)
  21050. +ENDPROC(divide_error)
  21051. #ifdef CONFIG_X86_MCE
  21052. ENTRY(machine_check)
  21053. @@ -950,7 +1189,7 @@ ENTRY(machine_check)
  21054. pushl_cfi machine_check_vector
  21055. jmp error_code
  21056. CFI_ENDPROC
  21057. -END(machine_check)
  21058. +ENDPROC(machine_check)
  21059. #endif
  21060. ENTRY(spurious_interrupt_bug)
  21061. @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
  21062. pushl_cfi $do_spurious_interrupt_bug
  21063. jmp error_code
  21064. CFI_ENDPROC
  21065. -END(spurious_interrupt_bug)
  21066. +ENDPROC(spurious_interrupt_bug)
  21067. /*
  21068. * End of kprobes section
  21069. */
  21070. @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
  21071. ENTRY(mcount)
  21072. ret
  21073. -END(mcount)
  21074. +ENDPROC(mcount)
  21075. ENTRY(ftrace_caller)
  21076. cmpl $0, function_trace_stop
  21077. @@ -1103,7 +1342,7 @@ ftrace_graph_call:
  21078. .globl ftrace_stub
  21079. ftrace_stub:
  21080. ret
  21081. -END(ftrace_caller)
  21082. +ENDPROC(ftrace_caller)
  21083. ENTRY(ftrace_regs_caller)
  21084. pushf /* push flags before compare (in cs location) */
  21085. @@ -1207,7 +1446,7 @@ trace:
  21086. popl %ecx
  21087. popl %eax
  21088. jmp ftrace_stub
  21089. -END(mcount)
  21090. +ENDPROC(mcount)
  21091. #endif /* CONFIG_DYNAMIC_FTRACE */
  21092. #endif /* CONFIG_FUNCTION_TRACER */
  21093. @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
  21094. popl %ecx
  21095. popl %eax
  21096. ret
  21097. -END(ftrace_graph_caller)
  21098. +ENDPROC(ftrace_graph_caller)
  21099. .globl return_to_handler
  21100. return_to_handler:
  21101. @@ -1291,15 +1530,18 @@ error_code:
  21102. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  21103. REG_TO_PTGS %ecx
  21104. SET_KERNEL_GS %ecx
  21105. - movl $(__USER_DS), %ecx
  21106. + movl $(__KERNEL_DS), %ecx
  21107. movl %ecx, %ds
  21108. movl %ecx, %es
  21109. +
  21110. + pax_enter_kernel
  21111. +
  21112. TRACE_IRQS_OFF
  21113. movl %esp,%eax # pt_regs pointer
  21114. call *%edi
  21115. jmp ret_from_exception
  21116. CFI_ENDPROC
  21117. -END(page_fault)
  21118. +ENDPROC(page_fault)
  21119. /*
  21120. * Debug traps and NMI can happen at the one SYSENTER instruction
  21121. @@ -1342,7 +1584,7 @@ debug_stack_correct:
  21122. call do_debug
  21123. jmp ret_from_exception
  21124. CFI_ENDPROC
  21125. -END(debug)
  21126. +ENDPROC(debug)
  21127. /*
  21128. * NMI is doubly nasty. It can happen _while_ we're handling
  21129. @@ -1380,6 +1622,9 @@ nmi_stack_correct:
  21130. xorl %edx,%edx # zero error code
  21131. movl %esp,%eax # pt_regs pointer
  21132. call do_nmi
  21133. +
  21134. + pax_exit_kernel
  21135. +
  21136. jmp restore_all_notrace
  21137. CFI_ENDPROC
  21138. @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
  21139. FIXUP_ESPFIX_STACK # %eax == %esp
  21140. xorl %edx,%edx # zero error code
  21141. call do_nmi
  21142. +
  21143. + pax_exit_kernel
  21144. +
  21145. RESTORE_REGS
  21146. lss 12+4(%esp), %esp # back to espfix stack
  21147. CFI_ADJUST_CFA_OFFSET -24
  21148. jmp irq_return
  21149. CFI_ENDPROC
  21150. -END(nmi)
  21151. +ENDPROC(nmi)
  21152. ENTRY(int3)
  21153. RING0_INT_FRAME
  21154. @@ -1434,14 +1682,14 @@ ENTRY(int3)
  21155. call do_int3
  21156. jmp ret_from_exception
  21157. CFI_ENDPROC
  21158. -END(int3)
  21159. +ENDPROC(int3)
  21160. ENTRY(general_protection)
  21161. RING0_EC_FRAME
  21162. pushl_cfi $do_general_protection
  21163. jmp error_code
  21164. CFI_ENDPROC
  21165. -END(general_protection)
  21166. +ENDPROC(general_protection)
  21167. #ifdef CONFIG_KVM_GUEST
  21168. ENTRY(async_page_fault)
  21169. @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
  21170. pushl_cfi $do_async_page_fault
  21171. jmp error_code
  21172. CFI_ENDPROC
  21173. -END(async_page_fault)
  21174. +ENDPROC(async_page_fault)
  21175. #endif
  21176. /*
  21177. diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
  21178. index 1e96c36..3ff710a 100644
  21179. --- a/arch/x86/kernel/entry_64.S
  21180. +++ b/arch/x86/kernel/entry_64.S
  21181. @@ -59,6 +59,8 @@
  21182. #include <asm/context_tracking.h>
  21183. #include <asm/smap.h>
  21184. #include <linux/err.h>
  21185. +#include <asm/pgtable.h>
  21186. +#include <asm/alternative-asm.h>
  21187. /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
  21188. #include <linux/elf-em.h>
  21189. @@ -80,8 +82,9 @@
  21190. #ifdef CONFIG_DYNAMIC_FTRACE
  21191. ENTRY(function_hook)
  21192. + pax_force_retaddr
  21193. retq
  21194. -END(function_hook)
  21195. +ENDPROC(function_hook)
  21196. /* skip is set if stack has been adjusted */
  21197. .macro ftrace_caller_setup skip=0
  21198. @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
  21199. #endif
  21200. GLOBAL(ftrace_stub)
  21201. + pax_force_retaddr
  21202. retq
  21203. -END(ftrace_caller)
  21204. +ENDPROC(ftrace_caller)
  21205. ENTRY(ftrace_regs_caller)
  21206. /* Save the current flags before compare (in SS location)*/
  21207. @@ -191,7 +195,7 @@ ftrace_restore_flags:
  21208. popfq
  21209. jmp ftrace_stub
  21210. -END(ftrace_regs_caller)
  21211. +ENDPROC(ftrace_regs_caller)
  21212. #else /* ! CONFIG_DYNAMIC_FTRACE */
  21213. @@ -212,6 +216,7 @@ ENTRY(function_hook)
  21214. #endif
  21215. GLOBAL(ftrace_stub)
  21216. + pax_force_retaddr
  21217. retq
  21218. trace:
  21219. @@ -225,12 +230,13 @@ trace:
  21220. #endif
  21221. subq $MCOUNT_INSN_SIZE, %rdi
  21222. + pax_force_fptr ftrace_trace_function
  21223. call *ftrace_trace_function
  21224. MCOUNT_RESTORE_FRAME
  21225. jmp ftrace_stub
  21226. -END(function_hook)
  21227. +ENDPROC(function_hook)
  21228. #endif /* CONFIG_DYNAMIC_FTRACE */
  21229. #endif /* CONFIG_FUNCTION_TRACER */
  21230. @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
  21231. MCOUNT_RESTORE_FRAME
  21232. + pax_force_retaddr
  21233. retq
  21234. -END(ftrace_graph_caller)
  21235. +ENDPROC(ftrace_graph_caller)
  21236. GLOBAL(return_to_handler)
  21237. subq $24, %rsp
  21238. @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
  21239. movq 8(%rsp), %rdx
  21240. movq (%rsp), %rax
  21241. addq $24, %rsp
  21242. + pax_force_fptr %rdi
  21243. jmp *%rdi
  21244. +ENDPROC(return_to_handler)
  21245. #endif
  21246. @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
  21247. ENDPROC(native_usergs_sysret64)
  21248. #endif /* CONFIG_PARAVIRT */
  21249. + .macro ljmpq sel, off
  21250. +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
  21251. + .byte 0x48; ljmp *1234f(%rip)
  21252. + .pushsection .rodata
  21253. + .align 16
  21254. + 1234: .quad \off; .word \sel
  21255. + .popsection
  21256. +#else
  21257. + pushq $\sel
  21258. + pushq $\off
  21259. + lretq
  21260. +#endif
  21261. + .endm
  21262. +
  21263. + .macro pax_enter_kernel
  21264. + pax_set_fptr_mask
  21265. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  21266. + call pax_enter_kernel
  21267. +#endif
  21268. + .endm
  21269. +
  21270. + .macro pax_exit_kernel
  21271. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  21272. + call pax_exit_kernel
  21273. +#endif
  21274. +
  21275. + .endm
  21276. +
  21277. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  21278. +ENTRY(pax_enter_kernel)
  21279. + pushq %rdi
  21280. +
  21281. +#ifdef CONFIG_PARAVIRT
  21282. + PV_SAVE_REGS(CLBR_RDI)
  21283. +#endif
  21284. +
  21285. +#ifdef CONFIG_PAX_KERNEXEC
  21286. + GET_CR0_INTO_RDI
  21287. + bts $16,%rdi
  21288. + jnc 3f
  21289. + mov %cs,%edi
  21290. + cmp $__KERNEL_CS,%edi
  21291. + jnz 2f
  21292. +1:
  21293. +#endif
  21294. +
  21295. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21296. + 661: jmp 111f
  21297. + .pushsection .altinstr_replacement, "a"
  21298. + 662: ASM_NOP2
  21299. + .popsection
  21300. + .pushsection .altinstructions, "a"
  21301. + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
  21302. + .popsection
  21303. + GET_CR3_INTO_RDI
  21304. + cmp $0,%dil
  21305. + jnz 112f
  21306. + mov $__KERNEL_DS,%edi
  21307. + mov %edi,%ss
  21308. + jmp 111f
  21309. +112: cmp $1,%dil
  21310. + jz 113f
  21311. + ud2
  21312. +113: sub $4097,%rdi
  21313. + bts $63,%rdi
  21314. + SET_RDI_INTO_CR3
  21315. + mov $__UDEREF_KERNEL_DS,%edi
  21316. + mov %edi,%ss
  21317. +111:
  21318. +#endif
  21319. +
  21320. +#ifdef CONFIG_PARAVIRT
  21321. + PV_RESTORE_REGS(CLBR_RDI)
  21322. +#endif
  21323. +
  21324. + popq %rdi
  21325. + pax_force_retaddr
  21326. + retq
  21327. +
  21328. +#ifdef CONFIG_PAX_KERNEXEC
  21329. +2: ljmpq __KERNEL_CS,1b
  21330. +3: ljmpq __KERNEXEC_KERNEL_CS,4f
  21331. +4: SET_RDI_INTO_CR0
  21332. + jmp 1b
  21333. +#endif
  21334. +ENDPROC(pax_enter_kernel)
  21335. +
  21336. +ENTRY(pax_exit_kernel)
  21337. + pushq %rdi
  21338. +
  21339. +#ifdef CONFIG_PARAVIRT
  21340. + PV_SAVE_REGS(CLBR_RDI)
  21341. +#endif
  21342. +
  21343. +#ifdef CONFIG_PAX_KERNEXEC
  21344. + mov %cs,%rdi
  21345. + cmp $__KERNEXEC_KERNEL_CS,%edi
  21346. + jz 2f
  21347. + GET_CR0_INTO_RDI
  21348. + bts $16,%rdi
  21349. + jnc 4f
  21350. +1:
  21351. +#endif
  21352. +
  21353. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21354. + 661: jmp 111f
  21355. + .pushsection .altinstr_replacement, "a"
  21356. + 662: ASM_NOP2
  21357. + .popsection
  21358. + .pushsection .altinstructions, "a"
  21359. + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
  21360. + .popsection
  21361. + mov %ss,%edi
  21362. + cmp $__UDEREF_KERNEL_DS,%edi
  21363. + jnz 111f
  21364. + GET_CR3_INTO_RDI
  21365. + cmp $0,%dil
  21366. + jz 112f
  21367. + ud2
  21368. +112: add $4097,%rdi
  21369. + bts $63,%rdi
  21370. + SET_RDI_INTO_CR3
  21371. + mov $__KERNEL_DS,%edi
  21372. + mov %edi,%ss
  21373. +111:
  21374. +#endif
  21375. +
  21376. +#ifdef CONFIG_PARAVIRT
  21377. + PV_RESTORE_REGS(CLBR_RDI);
  21378. +#endif
  21379. +
  21380. + popq %rdi
  21381. + pax_force_retaddr
  21382. + retq
  21383. +
  21384. +#ifdef CONFIG_PAX_KERNEXEC
  21385. +2: GET_CR0_INTO_RDI
  21386. + btr $16,%rdi
  21387. + jnc 4f
  21388. + ljmpq __KERNEL_CS,3f
  21389. +3: SET_RDI_INTO_CR0
  21390. + jmp 1b
  21391. +4: ud2
  21392. + jmp 4b
  21393. +#endif
  21394. +ENDPROC(pax_exit_kernel)
  21395. +#endif
  21396. +
  21397. + .macro pax_enter_kernel_user
  21398. + pax_set_fptr_mask
  21399. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21400. + call pax_enter_kernel_user
  21401. +#endif
  21402. + .endm
  21403. +
  21404. + .macro pax_exit_kernel_user
  21405. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21406. + call pax_exit_kernel_user
  21407. +#endif
  21408. +#ifdef CONFIG_PAX_RANDKSTACK
  21409. + pushq %rax
  21410. + pushq %r11
  21411. + call pax_randomize_kstack
  21412. + popq %r11
  21413. + popq %rax
  21414. +#endif
  21415. + .endm
  21416. +
  21417. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21418. +ENTRY(pax_enter_kernel_user)
  21419. + pushq %rdi
  21420. + pushq %rbx
  21421. +
  21422. +#ifdef CONFIG_PARAVIRT
  21423. + PV_SAVE_REGS(CLBR_RDI)
  21424. +#endif
  21425. +
  21426. + 661: jmp 111f
  21427. + .pushsection .altinstr_replacement, "a"
  21428. + 662: ASM_NOP2
  21429. + .popsection
  21430. + .pushsection .altinstructions, "a"
  21431. + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
  21432. + .popsection
  21433. + GET_CR3_INTO_RDI
  21434. + cmp $1,%dil
  21435. + jnz 4f
  21436. + sub $4097,%rdi
  21437. + bts $63,%rdi
  21438. + SET_RDI_INTO_CR3
  21439. + jmp 3f
  21440. +111:
  21441. +
  21442. + GET_CR3_INTO_RDI
  21443. + mov %rdi,%rbx
  21444. + add $__START_KERNEL_map,%rbx
  21445. + sub phys_base(%rip),%rbx
  21446. +
  21447. +#ifdef CONFIG_PARAVIRT
  21448. + cmpl $0, pv_info+PARAVIRT_enabled
  21449. + jz 1f
  21450. + pushq %rdi
  21451. + i = 0
  21452. + .rept USER_PGD_PTRS
  21453. + mov i*8(%rbx),%rsi
  21454. + mov $0,%sil
  21455. + lea i*8(%rbx),%rdi
  21456. + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
  21457. + i = i + 1
  21458. + .endr
  21459. + popq %rdi
  21460. + jmp 2f
  21461. +1:
  21462. +#endif
  21463. +
  21464. + i = 0
  21465. + .rept USER_PGD_PTRS
  21466. + movb $0,i*8(%rbx)
  21467. + i = i + 1
  21468. + .endr
  21469. +
  21470. +2: SET_RDI_INTO_CR3
  21471. +
  21472. +#ifdef CONFIG_PAX_KERNEXEC
  21473. + GET_CR0_INTO_RDI
  21474. + bts $16,%rdi
  21475. + SET_RDI_INTO_CR0
  21476. +#endif
  21477. +
  21478. +3:
  21479. +
  21480. +#ifdef CONFIG_PARAVIRT
  21481. + PV_RESTORE_REGS(CLBR_RDI)
  21482. +#endif
  21483. +
  21484. + popq %rbx
  21485. + popq %rdi
  21486. + pax_force_retaddr
  21487. + retq
  21488. +4: ud2
  21489. +ENDPROC(pax_enter_kernel_user)
  21490. +
  21491. +ENTRY(pax_exit_kernel_user)
  21492. + pushq %rdi
  21493. + pushq %rbx
  21494. +
  21495. +#ifdef CONFIG_PARAVIRT
  21496. + PV_SAVE_REGS(CLBR_RDI)
  21497. +#endif
  21498. +
  21499. + GET_CR3_INTO_RDI
  21500. + 661: jmp 1f
  21501. + .pushsection .altinstr_replacement, "a"
  21502. + 662: ASM_NOP2
  21503. + .popsection
  21504. + .pushsection .altinstructions, "a"
  21505. + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
  21506. + .popsection
  21507. + cmp $0,%dil
  21508. + jnz 3f
  21509. + add $4097,%rdi
  21510. + bts $63,%rdi
  21511. + SET_RDI_INTO_CR3
  21512. + jmp 2f
  21513. +1:
  21514. +
  21515. + mov %rdi,%rbx
  21516. +
  21517. +#ifdef CONFIG_PAX_KERNEXEC
  21518. + GET_CR0_INTO_RDI
  21519. + btr $16,%rdi
  21520. + jnc 3f
  21521. + SET_RDI_INTO_CR0
  21522. +#endif
  21523. +
  21524. + add $__START_KERNEL_map,%rbx
  21525. + sub phys_base(%rip),%rbx
  21526. +
  21527. +#ifdef CONFIG_PARAVIRT
  21528. + cmpl $0, pv_info+PARAVIRT_enabled
  21529. + jz 1f
  21530. + i = 0
  21531. + .rept USER_PGD_PTRS
  21532. + mov i*8(%rbx),%rsi
  21533. + mov $0x67,%sil
  21534. + lea i*8(%rbx),%rdi
  21535. + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
  21536. + i = i + 1
  21537. + .endr
  21538. + jmp 2f
  21539. +1:
  21540. +#endif
  21541. +
  21542. + i = 0
  21543. + .rept USER_PGD_PTRS
  21544. + movb $0x67,i*8(%rbx)
  21545. + i = i + 1
  21546. + .endr
  21547. +2:
  21548. +
  21549. +#ifdef CONFIG_PARAVIRT
  21550. + PV_RESTORE_REGS(CLBR_RDI)
  21551. +#endif
  21552. +
  21553. + popq %rbx
  21554. + popq %rdi
  21555. + pax_force_retaddr
  21556. + retq
  21557. +3: ud2
  21558. +ENDPROC(pax_exit_kernel_user)
  21559. +#endif
  21560. +
  21561. + .macro pax_enter_kernel_nmi
  21562. + pax_set_fptr_mask
  21563. +
  21564. +#ifdef CONFIG_PAX_KERNEXEC
  21565. + GET_CR0_INTO_RDI
  21566. + bts $16,%rdi
  21567. + jc 110f
  21568. + SET_RDI_INTO_CR0
  21569. + or $2,%ebx
  21570. +110:
  21571. +#endif
  21572. +
  21573. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21574. + 661: jmp 111f
  21575. + .pushsection .altinstr_replacement, "a"
  21576. + 662: ASM_NOP2
  21577. + .popsection
  21578. + .pushsection .altinstructions, "a"
  21579. + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
  21580. + .popsection
  21581. + GET_CR3_INTO_RDI
  21582. + cmp $0,%dil
  21583. + jz 111f
  21584. + sub $4097,%rdi
  21585. + or $4,%ebx
  21586. + bts $63,%rdi
  21587. + SET_RDI_INTO_CR3
  21588. + mov $__UDEREF_KERNEL_DS,%edi
  21589. + mov %edi,%ss
  21590. +111:
  21591. +#endif
  21592. + .endm
  21593. +
  21594. + .macro pax_exit_kernel_nmi
  21595. +#ifdef CONFIG_PAX_KERNEXEC
  21596. + btr $1,%ebx
  21597. + jnc 110f
  21598. + GET_CR0_INTO_RDI
  21599. + btr $16,%rdi
  21600. + SET_RDI_INTO_CR0
  21601. +110:
  21602. +#endif
  21603. +
  21604. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21605. + btr $2,%ebx
  21606. + jnc 111f
  21607. + GET_CR3_INTO_RDI
  21608. + add $4097,%rdi
  21609. + bts $63,%rdi
  21610. + SET_RDI_INTO_CR3
  21611. + mov $__KERNEL_DS,%edi
  21612. + mov %edi,%ss
  21613. +111:
  21614. +#endif
  21615. + .endm
  21616. +
  21617. + .macro pax_erase_kstack
  21618. +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
  21619. + call pax_erase_kstack
  21620. +#endif
  21621. + .endm
  21622. +
  21623. +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
  21624. +ENTRY(pax_erase_kstack)
  21625. + pushq %rdi
  21626. + pushq %rcx
  21627. + pushq %rax
  21628. + pushq %r11
  21629. +
  21630. + GET_THREAD_INFO(%r11)
  21631. + mov TI_lowest_stack(%r11), %rdi
  21632. + mov $-0xBEEF, %rax
  21633. + std
  21634. +
  21635. +1: mov %edi, %ecx
  21636. + and $THREAD_SIZE_asm - 1, %ecx
  21637. + shr $3, %ecx
  21638. + repne scasq
  21639. + jecxz 2f
  21640. +
  21641. + cmp $2*8, %ecx
  21642. + jc 2f
  21643. +
  21644. + mov $2*8, %ecx
  21645. + repe scasq
  21646. + jecxz 2f
  21647. + jne 1b
  21648. +
  21649. +2: cld
  21650. + mov %esp, %ecx
  21651. + sub %edi, %ecx
  21652. +
  21653. + cmp $THREAD_SIZE_asm, %rcx
  21654. + jb 3f
  21655. + ud2
  21656. +3:
  21657. +
  21658. + shr $3, %ecx
  21659. + rep stosq
  21660. +
  21661. + mov TI_task_thread_sp0(%r11), %rdi
  21662. + sub $256, %rdi
  21663. + mov %rdi, TI_lowest_stack(%r11)
  21664. +
  21665. + popq %r11
  21666. + popq %rax
  21667. + popq %rcx
  21668. + popq %rdi
  21669. + pax_force_retaddr
  21670. + ret
  21671. +ENDPROC(pax_erase_kstack)
  21672. +#endif
  21673. .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
  21674. #ifdef CONFIG_TRACE_IRQFLAGS
  21675. @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
  21676. .endm
  21677. .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
  21678. - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
  21679. + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
  21680. jnc 1f
  21681. TRACE_IRQS_ON_DEBUG
  21682. 1:
  21683. @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
  21684. movq \tmp,R11+\offset(%rsp)
  21685. .endm
  21686. - .macro FAKE_STACK_FRAME child_rip
  21687. - /* push in order ss, rsp, eflags, cs, rip */
  21688. - xorl %eax, %eax
  21689. - pushq_cfi $__KERNEL_DS /* ss */
  21690. - /*CFI_REL_OFFSET ss,0*/
  21691. - pushq_cfi %rax /* rsp */
  21692. - CFI_REL_OFFSET rsp,0
  21693. - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
  21694. - /*CFI_REL_OFFSET rflags,0*/
  21695. - pushq_cfi $__KERNEL_CS /* cs */
  21696. - /*CFI_REL_OFFSET cs,0*/
  21697. - pushq_cfi \child_rip /* rip */
  21698. - CFI_REL_OFFSET rip,0
  21699. - pushq_cfi %rax /* orig rax */
  21700. - .endm
  21701. -
  21702. - .macro UNFAKE_STACK_FRAME
  21703. - addq $8*6, %rsp
  21704. - CFI_ADJUST_CFA_OFFSET -(6*8)
  21705. - .endm
  21706. -
  21707. /*
  21708. * initial frame state for interrupts (and exceptions without error code)
  21709. */
  21710. @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
  21711. /* save partial stack frame */
  21712. .macro SAVE_ARGS_IRQ
  21713. cld
  21714. - /* start from rbp in pt_regs and jump over */
  21715. - movq_cfi rdi, (RDI-RBP)
  21716. - movq_cfi rsi, (RSI-RBP)
  21717. - movq_cfi rdx, (RDX-RBP)
  21718. - movq_cfi rcx, (RCX-RBP)
  21719. - movq_cfi rax, (RAX-RBP)
  21720. - movq_cfi r8, (R8-RBP)
  21721. - movq_cfi r9, (R9-RBP)
  21722. - movq_cfi r10, (R10-RBP)
  21723. - movq_cfi r11, (R11-RBP)
  21724. + /* start from r15 in pt_regs and jump over */
  21725. + movq_cfi rdi, RDI
  21726. + movq_cfi rsi, RSI
  21727. + movq_cfi rdx, RDX
  21728. + movq_cfi rcx, RCX
  21729. + movq_cfi rax, RAX
  21730. + movq_cfi r8, R8
  21731. + movq_cfi r9, R9
  21732. + movq_cfi r10, R10
  21733. + movq_cfi r11, R11
  21734. + movq_cfi r12, R12
  21735. /* Save rbp so that we can unwind from get_irq_regs() */
  21736. - movq_cfi rbp, 0
  21737. + movq_cfi rbp, RBP
  21738. /* Save previous stack value */
  21739. movq %rsp, %rsi
  21740. - leaq -RBP(%rsp),%rdi /* arg1 for handler */
  21741. - testl $3, CS-RBP(%rsi)
  21742. + movq %rsp,%rdi /* arg1 for handler */
  21743. + testb $3, CS(%rsi)
  21744. je 1f
  21745. SWAPGS
  21746. /*
  21747. @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
  21748. 0x06 /* DW_OP_deref */, \
  21749. 0x08 /* DW_OP_const1u */, SS+8-RBP, \
  21750. 0x22 /* DW_OP_plus */
  21751. +
  21752. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21753. + testb $3, CS(%rdi)
  21754. + jnz 1f
  21755. + pax_enter_kernel
  21756. + jmp 2f
  21757. +1: pax_enter_kernel_user
  21758. +2:
  21759. +#else
  21760. + pax_enter_kernel
  21761. +#endif
  21762. +
  21763. /* We entered an interrupt context - irqs are off: */
  21764. TRACE_IRQS_OFF
  21765. .endm
  21766. @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
  21767. js 1f /* negative -> in kernel */
  21768. SWAPGS
  21769. xorl %ebx,%ebx
  21770. -1: ret
  21771. +1:
  21772. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  21773. + testb $3, CS+8(%rsp)
  21774. + jnz 1f
  21775. + pax_enter_kernel
  21776. + jmp 2f
  21777. +1: pax_enter_kernel_user
  21778. +2:
  21779. +#else
  21780. + pax_enter_kernel
  21781. +#endif
  21782. + pax_force_retaddr
  21783. + ret
  21784. CFI_ENDPROC
  21785. -END(save_paranoid)
  21786. +ENDPROC(save_paranoid)
  21787. +
  21788. +ENTRY(save_paranoid_nmi)
  21789. + XCPT_FRAME 1 RDI+8
  21790. + cld
  21791. + movq_cfi rdi, RDI+8
  21792. + movq_cfi rsi, RSI+8
  21793. + movq_cfi rdx, RDX+8
  21794. + movq_cfi rcx, RCX+8
  21795. + movq_cfi rax, RAX+8
  21796. + movq_cfi r8, R8+8
  21797. + movq_cfi r9, R9+8
  21798. + movq_cfi r10, R10+8
  21799. + movq_cfi r11, R11+8
  21800. + movq_cfi rbx, RBX+8
  21801. + movq_cfi rbp, RBP+8
  21802. + movq_cfi r12, R12+8
  21803. + movq_cfi r13, R13+8
  21804. + movq_cfi r14, R14+8
  21805. + movq_cfi r15, R15+8
  21806. + movl $1,%ebx
  21807. + movl $MSR_GS_BASE,%ecx
  21808. + rdmsr
  21809. + testl %edx,%edx
  21810. + js 1f /* negative -> in kernel */
  21811. + SWAPGS
  21812. + xorl %ebx,%ebx
  21813. +1: pax_enter_kernel_nmi
  21814. + pax_force_retaddr
  21815. + ret
  21816. + CFI_ENDPROC
  21817. +ENDPROC(save_paranoid_nmi)
  21818. .popsection
  21819. /*
  21820. @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
  21821. RESTORE_REST
  21822. - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
  21823. + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
  21824. jz 1f
  21825. testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
  21826. @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
  21827. jmp ret_from_sys_call # go to the SYSRET fastpath
  21828. 1:
  21829. - subq $REST_SKIP, %rsp # leave space for volatiles
  21830. - CFI_ADJUST_CFA_OFFSET REST_SKIP
  21831. movq %rbp, %rdi
  21832. call *%rbx
  21833. movl $0, RAX(%rsp)
  21834. RESTORE_REST
  21835. jmp int_ret_from_sys_call
  21836. CFI_ENDPROC
  21837. -END(ret_from_fork)
  21838. +ENDPROC(ret_from_fork)
  21839. /*
  21840. * System call entry. Up to 6 arguments in registers are supported.
  21841. @@ -593,7 +1059,7 @@ END(ret_from_fork)
  21842. ENTRY(system_call)
  21843. CFI_STARTPROC simple
  21844. CFI_SIGNAL_FRAME
  21845. - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
  21846. + CFI_DEF_CFA rsp,0
  21847. CFI_REGISTER rip,rcx
  21848. /*CFI_REGISTER rflags,r11*/
  21849. SWAPGS_UNSAFE_STACK
  21850. @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
  21851. movq %rsp,PER_CPU_VAR(old_rsp)
  21852. movq PER_CPU_VAR(kernel_stack),%rsp
  21853. + SAVE_ARGS 8*6,0
  21854. + pax_enter_kernel_user
  21855. +
  21856. +#ifdef CONFIG_PAX_RANDKSTACK
  21857. + pax_erase_kstack
  21858. +#endif
  21859. +
  21860. /*
  21861. * No need to follow this irqs off/on section - it's straight
  21862. * and short:
  21863. */
  21864. ENABLE_INTERRUPTS(CLBR_NONE)
  21865. - SAVE_ARGS 8,0
  21866. movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
  21867. movq %rcx,RIP-ARGOFFSET(%rsp)
  21868. CFI_REL_OFFSET rip,RIP-ARGOFFSET
  21869. - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  21870. + GET_THREAD_INFO(%rcx)
  21871. + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
  21872. jnz tracesys
  21873. system_call_fastpath:
  21874. #if __SYSCALL_MASK == ~0
  21875. @@ -639,10 +1112,13 @@ sysret_check:
  21876. LOCKDEP_SYS_EXIT
  21877. DISABLE_INTERRUPTS(CLBR_NONE)
  21878. TRACE_IRQS_OFF
  21879. - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
  21880. + GET_THREAD_INFO(%rcx)
  21881. + movl TI_flags(%rcx),%edx
  21882. andl %edi,%edx
  21883. jnz sysret_careful
  21884. CFI_REMEMBER_STATE
  21885. + pax_exit_kernel_user
  21886. + pax_erase_kstack
  21887. /*
  21888. * sysretq will re-enable interrupts:
  21889. */
  21890. @@ -701,6 +1177,9 @@ auditsys:
  21891. movq %rax,%rsi /* 2nd arg: syscall number */
  21892. movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
  21893. call __audit_syscall_entry
  21894. +
  21895. + pax_erase_kstack
  21896. +
  21897. LOAD_ARGS 0 /* reload call-clobbered registers */
  21898. jmp system_call_fastpath
  21899. @@ -722,7 +1201,7 @@ sysret_audit:
  21900. /* Do syscall tracing */
  21901. tracesys:
  21902. #ifdef CONFIG_AUDITSYSCALL
  21903. - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
  21904. + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
  21905. jz auditsys
  21906. #endif
  21907. SAVE_REST
  21908. @@ -730,12 +1209,15 @@ tracesys:
  21909. FIXUP_TOP_OF_STACK %rdi
  21910. movq %rsp,%rdi
  21911. call syscall_trace_enter
  21912. +
  21913. + pax_erase_kstack
  21914. +
  21915. /*
  21916. * Reload arg registers from stack in case ptrace changed them.
  21917. * We don't reload %rax because syscall_trace_enter() returned
  21918. * the value it wants us to use in the table lookup.
  21919. */
  21920. - LOAD_ARGS ARGOFFSET, 1
  21921. + LOAD_ARGS 1
  21922. RESTORE_REST
  21923. #if __SYSCALL_MASK == ~0
  21924. cmpq $__NR_syscall_max,%rax
  21925. @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
  21926. andl %edi,%edx
  21927. jnz int_careful
  21928. andl $~TS_COMPAT,TI_status(%rcx)
  21929. - jmp retint_swapgs
  21930. + pax_exit_kernel_user
  21931. + pax_erase_kstack
  21932. + jmp retint_swapgs_pax
  21933. /* Either reschedule or signal or syscall exit tracking needed. */
  21934. /* First do a reschedule test. */
  21935. @@ -811,7 +1295,7 @@ int_restore_rest:
  21936. TRACE_IRQS_OFF
  21937. jmp int_with_check
  21938. CFI_ENDPROC
  21939. -END(system_call)
  21940. +ENDPROC(system_call)
  21941. .macro FORK_LIKE func
  21942. ENTRY(stub_\func)
  21943. @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
  21944. DEFAULT_FRAME 0 8 /* offset 8: return address */
  21945. call sys_\func
  21946. RESTORE_TOP_OF_STACK %r11, 8
  21947. - ret $REST_SKIP /* pop extended registers */
  21948. + pax_force_retaddr
  21949. + ret
  21950. CFI_ENDPROC
  21951. -END(stub_\func)
  21952. +ENDPROC(stub_\func)
  21953. .endm
  21954. .macro FIXED_FRAME label,func
  21955. @@ -836,9 +1321,10 @@ ENTRY(\label)
  21956. FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
  21957. call \func
  21958. RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
  21959. + pax_force_retaddr
  21960. ret
  21961. CFI_ENDPROC
  21962. -END(\label)
  21963. +ENDPROC(\label)
  21964. .endm
  21965. FORK_LIKE clone
  21966. @@ -846,19 +1332,6 @@ END(\label)
  21967. FORK_LIKE vfork
  21968. FIXED_FRAME stub_iopl, sys_iopl
  21969. -ENTRY(ptregscall_common)
  21970. - DEFAULT_FRAME 1 8 /* offset 8: return address */
  21971. - RESTORE_TOP_OF_STACK %r11, 8
  21972. - movq_cfi_restore R15+8, r15
  21973. - movq_cfi_restore R14+8, r14
  21974. - movq_cfi_restore R13+8, r13
  21975. - movq_cfi_restore R12+8, r12
  21976. - movq_cfi_restore RBP+8, rbp
  21977. - movq_cfi_restore RBX+8, rbx
  21978. - ret $REST_SKIP /* pop extended registers */
  21979. - CFI_ENDPROC
  21980. -END(ptregscall_common)
  21981. -
  21982. ENTRY(stub_execve)
  21983. CFI_STARTPROC
  21984. addq $8, %rsp
  21985. @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
  21986. RESTORE_REST
  21987. jmp int_ret_from_sys_call
  21988. CFI_ENDPROC
  21989. -END(stub_execve)
  21990. +ENDPROC(stub_execve)
  21991. /*
  21992. * sigreturn is special because it needs to restore all registers on return.
  21993. @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
  21994. RESTORE_REST
  21995. jmp int_ret_from_sys_call
  21996. CFI_ENDPROC
  21997. -END(stub_rt_sigreturn)
  21998. +ENDPROC(stub_rt_sigreturn)
  21999. #ifdef CONFIG_X86_X32_ABI
  22000. ENTRY(stub_x32_rt_sigreturn)
  22001. @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
  22002. RESTORE_REST
  22003. jmp int_ret_from_sys_call
  22004. CFI_ENDPROC
  22005. -END(stub_x32_rt_sigreturn)
  22006. +ENDPROC(stub_x32_rt_sigreturn)
  22007. ENTRY(stub_x32_execve)
  22008. CFI_STARTPROC
  22009. @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
  22010. RESTORE_REST
  22011. jmp int_ret_from_sys_call
  22012. CFI_ENDPROC
  22013. -END(stub_x32_execve)
  22014. +ENDPROC(stub_x32_execve)
  22015. #endif
  22016. @@ -952,7 +1425,7 @@ vector=vector+1
  22017. 2: jmp common_interrupt
  22018. .endr
  22019. CFI_ENDPROC
  22020. -END(irq_entries_start)
  22021. +ENDPROC(irq_entries_start)
  22022. .previous
  22023. END(interrupt)
  22024. @@ -969,8 +1442,8 @@ END(interrupt)
  22025. /* 0(%rsp): ~(interrupt number) */
  22026. .macro interrupt func
  22027. /* reserve pt_regs for scratch regs and rbp */
  22028. - subq $ORIG_RAX-RBP, %rsp
  22029. - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
  22030. + subq $ORIG_RAX, %rsp
  22031. + CFI_ADJUST_CFA_OFFSET ORIG_RAX
  22032. SAVE_ARGS_IRQ
  22033. call \func
  22034. .endm
  22035. @@ -997,14 +1470,14 @@ ret_from_intr:
  22036. /* Restore saved previous stack */
  22037. popq %rsi
  22038. - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
  22039. - leaq ARGOFFSET-RBP(%rsi), %rsp
  22040. + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
  22041. + movq %rsi, %rsp
  22042. CFI_DEF_CFA_REGISTER rsp
  22043. - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
  22044. + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
  22045. exit_intr:
  22046. GET_THREAD_INFO(%rcx)
  22047. - testl $3,CS-ARGOFFSET(%rsp)
  22048. + testb $3,CS-ARGOFFSET(%rsp)
  22049. je retint_kernel
  22050. /* Interrupt came from user space */
  22051. @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
  22052. * The iretq could re-enable interrupts:
  22053. */
  22054. DISABLE_INTERRUPTS(CLBR_ANY)
  22055. + pax_exit_kernel_user
  22056. +retint_swapgs_pax:
  22057. TRACE_IRQS_IRETQ
  22058. SWAPGS
  22059. jmp restore_args
  22060. retint_restore_args: /* return to kernel space */
  22061. DISABLE_INTERRUPTS(CLBR_ANY)
  22062. + pax_exit_kernel
  22063. + pax_force_retaddr (RIP-ARGOFFSET)
  22064. /*
  22065. * The iretq could re-enable interrupts:
  22066. */
  22067. @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
  22068. #endif
  22069. CFI_ENDPROC
  22070. -END(common_interrupt)
  22071. +ENDPROC(common_interrupt)
  22072. /*
  22073. * End of kprobes section
  22074. */
  22075. @@ -1130,7 +1607,7 @@ ENTRY(\sym)
  22076. interrupt \do_sym
  22077. jmp ret_from_intr
  22078. CFI_ENDPROC
  22079. -END(\sym)
  22080. +ENDPROC(\sym)
  22081. .endm
  22082. #ifdef CONFIG_TRACING
  22083. @@ -1218,7 +1695,7 @@ ENTRY(\sym)
  22084. call \do_sym
  22085. jmp error_exit /* %ebx: no swapgs flag */
  22086. CFI_ENDPROC
  22087. -END(\sym)
  22088. +ENDPROC(\sym)
  22089. .endm
  22090. .macro paranoidzeroentry sym do_sym
  22091. @@ -1236,10 +1713,10 @@ ENTRY(\sym)
  22092. call \do_sym
  22093. jmp paranoid_exit /* %ebx: no swapgs flag */
  22094. CFI_ENDPROC
  22095. -END(\sym)
  22096. +ENDPROC(\sym)
  22097. .endm
  22098. -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
  22099. +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
  22100. .macro paranoidzeroentry_ist sym do_sym ist
  22101. ENTRY(\sym)
  22102. INTR_FRAME
  22103. @@ -1252,12 +1729,18 @@ ENTRY(\sym)
  22104. TRACE_IRQS_OFF_DEBUG
  22105. movq %rsp,%rdi /* pt_regs pointer */
  22106. xorl %esi,%esi /* no error code */
  22107. +#ifdef CONFIG_SMP
  22108. + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
  22109. + lea init_tss(%r13), %r13
  22110. +#else
  22111. + lea init_tss(%rip), %r13
  22112. +#endif
  22113. subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
  22114. call \do_sym
  22115. addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
  22116. jmp paranoid_exit /* %ebx: no swapgs flag */
  22117. CFI_ENDPROC
  22118. -END(\sym)
  22119. +ENDPROC(\sym)
  22120. .endm
  22121. .macro errorentry sym do_sym
  22122. @@ -1275,7 +1758,7 @@ ENTRY(\sym)
  22123. call \do_sym
  22124. jmp error_exit /* %ebx: no swapgs flag */
  22125. CFI_ENDPROC
  22126. -END(\sym)
  22127. +ENDPROC(\sym)
  22128. .endm
  22129. #ifdef CONFIG_TRACING
  22130. @@ -1306,7 +1789,7 @@ ENTRY(\sym)
  22131. call \do_sym
  22132. jmp paranoid_exit /* %ebx: no swapgs flag */
  22133. CFI_ENDPROC
  22134. -END(\sym)
  22135. +ENDPROC(\sym)
  22136. .endm
  22137. zeroentry divide_error do_divide_error
  22138. @@ -1336,9 +1819,10 @@ gs_change:
  22139. 2: mfence /* workaround */
  22140. SWAPGS
  22141. popfq_cfi
  22142. + pax_force_retaddr
  22143. ret
  22144. CFI_ENDPROC
  22145. -END(native_load_gs_index)
  22146. +ENDPROC(native_load_gs_index)
  22147. _ASM_EXTABLE(gs_change,bad_gs)
  22148. .section .fixup,"ax"
  22149. @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
  22150. CFI_DEF_CFA_REGISTER rsp
  22151. CFI_ADJUST_CFA_OFFSET -8
  22152. decl PER_CPU_VAR(irq_count)
  22153. + pax_force_retaddr
  22154. ret
  22155. CFI_ENDPROC
  22156. -END(do_softirq_own_stack)
  22157. +ENDPROC(do_softirq_own_stack)
  22158. #ifdef CONFIG_XEN
  22159. zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
  22160. @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
  22161. decl PER_CPU_VAR(irq_count)
  22162. jmp error_exit
  22163. CFI_ENDPROC
  22164. -END(xen_do_hypervisor_callback)
  22165. +ENDPROC(xen_do_hypervisor_callback)
  22166. /*
  22167. * Hypervisor uses this for application faults while it executes.
  22168. @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
  22169. SAVE_ALL
  22170. jmp error_exit
  22171. CFI_ENDPROC
  22172. -END(xen_failsafe_callback)
  22173. +ENDPROC(xen_failsafe_callback)
  22174. apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
  22175. xen_hvm_callback_vector xen_evtchn_do_upcall
  22176. @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
  22177. DEFAULT_FRAME
  22178. DISABLE_INTERRUPTS(CLBR_NONE)
  22179. TRACE_IRQS_OFF_DEBUG
  22180. - testl %ebx,%ebx /* swapgs needed? */
  22181. + testl $1,%ebx /* swapgs needed? */
  22182. jnz paranoid_restore
  22183. - testl $3,CS(%rsp)
  22184. + testb $3,CS(%rsp)
  22185. jnz paranoid_userspace
  22186. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  22187. + pax_exit_kernel
  22188. + TRACE_IRQS_IRETQ 0
  22189. + SWAPGS_UNSAFE_STACK
  22190. + RESTORE_ALL 8
  22191. + pax_force_retaddr_bts
  22192. + jmp irq_return
  22193. +#endif
  22194. paranoid_swapgs:
  22195. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  22196. + pax_exit_kernel_user
  22197. +#else
  22198. + pax_exit_kernel
  22199. +#endif
  22200. TRACE_IRQS_IRETQ 0
  22201. SWAPGS_UNSAFE_STACK
  22202. RESTORE_ALL 8
  22203. jmp irq_return
  22204. paranoid_restore:
  22205. + pax_exit_kernel
  22206. TRACE_IRQS_IRETQ_DEBUG 0
  22207. RESTORE_ALL 8
  22208. + pax_force_retaddr_bts
  22209. jmp irq_return
  22210. paranoid_userspace:
  22211. GET_THREAD_INFO(%rcx)
  22212. @@ -1557,7 +2057,7 @@ paranoid_schedule:
  22213. TRACE_IRQS_OFF
  22214. jmp paranoid_userspace
  22215. CFI_ENDPROC
  22216. -END(paranoid_exit)
  22217. +ENDPROC(paranoid_exit)
  22218. /*
  22219. * Exception entry point. This expects an error code/orig_rax on the stack.
  22220. @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
  22221. movq_cfi r14, R14+8
  22222. movq_cfi r15, R15+8
  22223. xorl %ebx,%ebx
  22224. - testl $3,CS+8(%rsp)
  22225. + testb $3,CS+8(%rsp)
  22226. je error_kernelspace
  22227. error_swapgs:
  22228. SWAPGS
  22229. error_sti:
  22230. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  22231. + testb $3, CS+8(%rsp)
  22232. + jnz 1f
  22233. + pax_enter_kernel
  22234. + jmp 2f
  22235. +1: pax_enter_kernel_user
  22236. +2:
  22237. +#else
  22238. + pax_enter_kernel
  22239. +#endif
  22240. TRACE_IRQS_OFF
  22241. + pax_force_retaddr
  22242. ret
  22243. /*
  22244. @@ -1616,7 +2127,7 @@ bstep_iret:
  22245. movq %rcx,RIP+8(%rsp)
  22246. jmp error_swapgs
  22247. CFI_ENDPROC
  22248. -END(error_entry)
  22249. +ENDPROC(error_entry)
  22250. /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
  22251. @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
  22252. DISABLE_INTERRUPTS(CLBR_NONE)
  22253. TRACE_IRQS_OFF
  22254. GET_THREAD_INFO(%rcx)
  22255. - testl %eax,%eax
  22256. + testl $1,%eax
  22257. jne retint_kernel
  22258. LOCKDEP_SYS_EXIT_IRQ
  22259. movl TI_flags(%rcx),%edx
  22260. @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
  22261. jnz retint_careful
  22262. jmp retint_swapgs
  22263. CFI_ENDPROC
  22264. -END(error_exit)
  22265. +ENDPROC(error_exit)
  22266. /*
  22267. * Test if a given stack is an NMI stack or not.
  22268. @@ -1694,9 +2205,11 @@ ENTRY(nmi)
  22269. * If %cs was not the kernel segment, then the NMI triggered in user
  22270. * space, which means it is definitely not nested.
  22271. */
  22272. + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
  22273. + je 1f
  22274. cmpl $__KERNEL_CS, 16(%rsp)
  22275. jne first_nmi
  22276. -
  22277. +1:
  22278. /*
  22279. * Check the special variable on the stack to see if NMIs are
  22280. * executing.
  22281. @@ -1730,8 +2243,7 @@ nested_nmi:
  22282. 1:
  22283. /* Set up the interrupted NMIs stack to jump to repeat_nmi */
  22284. - leaq -1*8(%rsp), %rdx
  22285. - movq %rdx, %rsp
  22286. + subq $8, %rsp
  22287. CFI_ADJUST_CFA_OFFSET 1*8
  22288. leaq -10*8(%rsp), %rdx
  22289. pushq_cfi $__KERNEL_DS
  22290. @@ -1749,6 +2261,7 @@ nested_nmi_out:
  22291. CFI_RESTORE rdx
  22292. /* No need to check faults here */
  22293. +# pax_force_retaddr_bts
  22294. INTERRUPT_RETURN
  22295. CFI_RESTORE_STATE
  22296. @@ -1845,13 +2358,13 @@ end_repeat_nmi:
  22297. subq $ORIG_RAX-R15, %rsp
  22298. CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
  22299. /*
  22300. - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
  22301. + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
  22302. * as we should not be calling schedule in NMI context.
  22303. * Even with normal interrupts enabled. An NMI should not be
  22304. * setting NEED_RESCHED or anything that normal interrupts and
  22305. * exceptions might do.
  22306. */
  22307. - call save_paranoid
  22308. + call save_paranoid_nmi
  22309. DEFAULT_FRAME 0
  22310. /*
  22311. @@ -1861,9 +2374,9 @@ end_repeat_nmi:
  22312. * NMI itself takes a page fault, the page fault that was preempted
  22313. * will read the information from the NMI page fault and not the
  22314. * origin fault. Save it off and restore it if it changes.
  22315. - * Use the r12 callee-saved register.
  22316. + * Use the r13 callee-saved register.
  22317. */
  22318. - movq %cr2, %r12
  22319. + movq %cr2, %r13
  22320. /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
  22321. movq %rsp,%rdi
  22322. @@ -1872,31 +2385,36 @@ end_repeat_nmi:
  22323. /* Did the NMI take a page fault? Restore cr2 if it did */
  22324. movq %cr2, %rcx
  22325. - cmpq %rcx, %r12
  22326. + cmpq %rcx, %r13
  22327. je 1f
  22328. - movq %r12, %cr2
  22329. + movq %r13, %cr2
  22330. 1:
  22331. - testl %ebx,%ebx /* swapgs needed? */
  22332. + testl $1,%ebx /* swapgs needed? */
  22333. jnz nmi_restore
  22334. nmi_swapgs:
  22335. SWAPGS_UNSAFE_STACK
  22336. nmi_restore:
  22337. + pax_exit_kernel_nmi
  22338. /* Pop the extra iret frame at once */
  22339. RESTORE_ALL 6*8
  22340. + testb $3, 8(%rsp)
  22341. + jnz 1f
  22342. + pax_force_retaddr_bts
  22343. +1:
  22344. /* Clear the NMI executing stack variable */
  22345. movq $0, 5*8(%rsp)
  22346. jmp irq_return
  22347. CFI_ENDPROC
  22348. -END(nmi)
  22349. +ENDPROC(nmi)
  22350. ENTRY(ignore_sysret)
  22351. CFI_STARTPROC
  22352. mov $-ENOSYS,%eax
  22353. sysret
  22354. CFI_ENDPROC
  22355. -END(ignore_sysret)
  22356. +ENDPROC(ignore_sysret)
  22357. /*
  22358. * End of kprobes section
  22359. diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
  22360. index 1ffc32d..e52c745 100644
  22361. --- a/arch/x86/kernel/ftrace.c
  22362. +++ b/arch/x86/kernel/ftrace.c
  22363. @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
  22364. {
  22365. unsigned char replaced[MCOUNT_INSN_SIZE];
  22366. + ip = ktla_ktva(ip);
  22367. +
  22368. /*
  22369. * Note: Due to modules and __init, code can
  22370. * disappear and change, we need to protect against faulting
  22371. @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
  22372. unsigned char old[MCOUNT_INSN_SIZE];
  22373. int ret;
  22374. - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
  22375. + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
  22376. ftrace_update_func = ip;
  22377. /* Make sure the breakpoints see the ftrace_update_func update */
  22378. @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
  22379. * kernel identity mapping to modify code.
  22380. */
  22381. if (within(ip, (unsigned long)_text, (unsigned long)_etext))
  22382. - ip = (unsigned long)__va(__pa_symbol(ip));
  22383. + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
  22384. return probe_kernel_write((void *)ip, val, size);
  22385. }
  22386. @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
  22387. unsigned char replaced[MCOUNT_INSN_SIZE];
  22388. unsigned char brk = BREAKPOINT_INSTRUCTION;
  22389. - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
  22390. + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
  22391. return -EFAULT;
  22392. /* Make sure it is what we expect it to be */
  22393. @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
  22394. return ret;
  22395. fail_update:
  22396. - probe_kernel_write((void *)ip, &old_code[0], 1);
  22397. + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
  22398. goto out;
  22399. }
  22400. diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
  22401. index 85126cc..1bbce17 100644
  22402. --- a/arch/x86/kernel/head64.c
  22403. +++ b/arch/x86/kernel/head64.c
  22404. @@ -67,12 +67,12 @@ again:
  22405. pgd = *pgd_p;
  22406. /*
  22407. - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
  22408. - * critical -- __PAGE_OFFSET would point us back into the dynamic
  22409. + * The use of __early_va rather than __va here is critical:
  22410. + * __va would point us back into the dynamic
  22411. * range and we might end up looping forever...
  22412. */
  22413. if (pgd)
  22414. - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
  22415. + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
  22416. else {
  22417. if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
  22418. reset_early_page_tables();
  22419. @@ -82,13 +82,13 @@ again:
  22420. pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
  22421. for (i = 0; i < PTRS_PER_PUD; i++)
  22422. pud_p[i] = 0;
  22423. - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
  22424. + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
  22425. }
  22426. pud_p += pud_index(address);
  22427. pud = *pud_p;
  22428. if (pud)
  22429. - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
  22430. + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
  22431. else {
  22432. if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
  22433. reset_early_page_tables();
  22434. @@ -98,7 +98,7 @@ again:
  22435. pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
  22436. for (i = 0; i < PTRS_PER_PMD; i++)
  22437. pmd_p[i] = 0;
  22438. - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
  22439. + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
  22440. }
  22441. pmd = (physaddr & PMD_MASK) + early_pmd_flags;
  22442. pmd_p[pmd_index(address)] = pmd;
  22443. @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
  22444. if (console_loglevel == 10)
  22445. early_printk("Kernel alive\n");
  22446. - clear_page(init_level4_pgt);
  22447. /* set init_level4_pgt kernel high mapping*/
  22448. init_level4_pgt[511] = early_level4_pgt[511];
  22449. diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
  22450. index f36bd42..56ee1534 100644
  22451. --- a/arch/x86/kernel/head_32.S
  22452. +++ b/arch/x86/kernel/head_32.S
  22453. @@ -26,6 +26,12 @@
  22454. /* Physical address */
  22455. #define pa(X) ((X) - __PAGE_OFFSET)
  22456. +#ifdef CONFIG_PAX_KERNEXEC
  22457. +#define ta(X) (X)
  22458. +#else
  22459. +#define ta(X) ((X) - __PAGE_OFFSET)
  22460. +#endif
  22461. +
  22462. /*
  22463. * References to members of the new_cpu_data structure.
  22464. */
  22465. @@ -55,11 +61,7 @@
  22466. * and small than max_low_pfn, otherwise will waste some page table entries
  22467. */
  22468. -#if PTRS_PER_PMD > 1
  22469. -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
  22470. -#else
  22471. -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
  22472. -#endif
  22473. +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
  22474. /* Number of possible pages in the lowmem region */
  22475. LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
  22476. @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
  22477. RESERVE_BRK(pagetables, INIT_MAP_SIZE)
  22478. /*
  22479. + * Real beginning of normal "text" segment
  22480. + */
  22481. +ENTRY(stext)
  22482. +ENTRY(_stext)
  22483. +
  22484. +/*
  22485. * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
  22486. * %esi points to the real-mode code as a 32-bit pointer.
  22487. * CS and DS must be 4 GB flat segments, but we don't depend on
  22488. @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
  22489. * can.
  22490. */
  22491. __HEAD
  22492. +
  22493. +#ifdef CONFIG_PAX_KERNEXEC
  22494. + jmp startup_32
  22495. +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
  22496. +.fill PAGE_SIZE-5,1,0xcc
  22497. +#endif
  22498. +
  22499. ENTRY(startup_32)
  22500. movl pa(stack_start),%ecx
  22501. @@ -106,6 +121,59 @@ ENTRY(startup_32)
  22502. 2:
  22503. leal -__PAGE_OFFSET(%ecx),%esp
  22504. +#ifdef CONFIG_SMP
  22505. + movl $pa(cpu_gdt_table),%edi
  22506. + movl $__per_cpu_load,%eax
  22507. + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
  22508. + rorl $16,%eax
  22509. + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
  22510. + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
  22511. + movl $__per_cpu_end - 1,%eax
  22512. + subl $__per_cpu_start,%eax
  22513. + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
  22514. +#endif
  22515. +
  22516. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  22517. + movl $NR_CPUS,%ecx
  22518. + movl $pa(cpu_gdt_table),%edi
  22519. +1:
  22520. + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
  22521. + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
  22522. + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
  22523. + addl $PAGE_SIZE_asm,%edi
  22524. + loop 1b
  22525. +#endif
  22526. +
  22527. +#ifdef CONFIG_PAX_KERNEXEC
  22528. + movl $pa(boot_gdt),%edi
  22529. + movl $__LOAD_PHYSICAL_ADDR,%eax
  22530. + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
  22531. + rorl $16,%eax
  22532. + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
  22533. + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
  22534. + rorl $16,%eax
  22535. +
  22536. + ljmp $(__BOOT_CS),$1f
  22537. +1:
  22538. +
  22539. + movl $NR_CPUS,%ecx
  22540. + movl $pa(cpu_gdt_table),%edi
  22541. + addl $__PAGE_OFFSET,%eax
  22542. +1:
  22543. + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
  22544. + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
  22545. + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
  22546. + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
  22547. + rorl $16,%eax
  22548. + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
  22549. + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
  22550. + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
  22551. + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
  22552. + rorl $16,%eax
  22553. + addl $PAGE_SIZE_asm,%edi
  22554. + loop 1b
  22555. +#endif
  22556. +
  22557. /*
  22558. * Clear BSS first so that there are no surprises...
  22559. */
  22560. @@ -201,8 +269,11 @@ ENTRY(startup_32)
  22561. movl %eax, pa(max_pfn_mapped)
  22562. /* Do early initialization of the fixmap area */
  22563. - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
  22564. - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
  22565. +#ifdef CONFIG_COMPAT_VDSO
  22566. + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
  22567. +#else
  22568. + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
  22569. +#endif
  22570. #else /* Not PAE */
  22571. page_pde_offset = (__PAGE_OFFSET >> 20);
  22572. @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
  22573. movl %eax, pa(max_pfn_mapped)
  22574. /* Do early initialization of the fixmap area */
  22575. - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
  22576. - movl %eax,pa(initial_page_table+0xffc)
  22577. +#ifdef CONFIG_COMPAT_VDSO
  22578. + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
  22579. +#else
  22580. + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
  22581. +#endif
  22582. #endif
  22583. #ifdef CONFIG_PARAVIRT
  22584. @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
  22585. cmpl $num_subarch_entries, %eax
  22586. jae bad_subarch
  22587. - movl pa(subarch_entries)(,%eax,4), %eax
  22588. - subl $__PAGE_OFFSET, %eax
  22589. - jmp *%eax
  22590. + jmp *pa(subarch_entries)(,%eax,4)
  22591. bad_subarch:
  22592. WEAK(lguest_entry)
  22593. @@ -261,10 +333,10 @@ WEAK(xen_entry)
  22594. __INITDATA
  22595. subarch_entries:
  22596. - .long default_entry /* normal x86/PC */
  22597. - .long lguest_entry /* lguest hypervisor */
  22598. - .long xen_entry /* Xen hypervisor */
  22599. - .long default_entry /* Moorestown MID */
  22600. + .long ta(default_entry) /* normal x86/PC */
  22601. + .long ta(lguest_entry) /* lguest hypervisor */
  22602. + .long ta(xen_entry) /* Xen hypervisor */
  22603. + .long ta(default_entry) /* Moorestown MID */
  22604. num_subarch_entries = (. - subarch_entries) / 4
  22605. .previous
  22606. #else
  22607. @@ -354,6 +426,7 @@ default_entry:
  22608. movl pa(mmu_cr4_features),%eax
  22609. movl %eax,%cr4
  22610. +#ifdef CONFIG_X86_PAE
  22611. testb $X86_CR4_PAE, %al # check if PAE is enabled
  22612. jz enable_paging
  22613. @@ -382,6 +455,9 @@ default_entry:
  22614. /* Make changes effective */
  22615. wrmsr
  22616. + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
  22617. +#endif
  22618. +
  22619. enable_paging:
  22620. /*
  22621. @@ -449,14 +525,20 @@ is486:
  22622. 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
  22623. movl %eax,%ss # after changing gdt.
  22624. - movl $(__USER_DS),%eax # DS/ES contains default USER segment
  22625. +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
  22626. movl %eax,%ds
  22627. movl %eax,%es
  22628. movl $(__KERNEL_PERCPU), %eax
  22629. movl %eax,%fs # set this cpu's percpu
  22630. +#ifdef CONFIG_CC_STACKPROTECTOR
  22631. movl $(__KERNEL_STACK_CANARY),%eax
  22632. +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
  22633. + movl $(__USER_DS),%eax
  22634. +#else
  22635. + xorl %eax,%eax
  22636. +#endif
  22637. movl %eax,%gs
  22638. xorl %eax,%eax # Clear LDT
  22639. @@ -512,8 +594,11 @@ setup_once:
  22640. * relocation. Manually set base address in stack canary
  22641. * segment descriptor.
  22642. */
  22643. - movl $gdt_page,%eax
  22644. + movl $cpu_gdt_table,%eax
  22645. movl $stack_canary,%ecx
  22646. +#ifdef CONFIG_SMP
  22647. + addl $__per_cpu_load,%ecx
  22648. +#endif
  22649. movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
  22650. shrl $16, %ecx
  22651. movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
  22652. @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
  22653. cmpl $2,(%esp) # X86_TRAP_NMI
  22654. je is_nmi # Ignore NMI
  22655. - cmpl $2,%ss:early_recursion_flag
  22656. + cmpl $1,%ss:early_recursion_flag
  22657. je hlt_loop
  22658. incl %ss:early_recursion_flag
  22659. @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
  22660. pushl (20+6*4)(%esp) /* trapno */
  22661. pushl $fault_msg
  22662. call printk
  22663. -#endif
  22664. call dump_stack
  22665. +#endif
  22666. hlt_loop:
  22667. hlt
  22668. jmp hlt_loop
  22669. @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
  22670. /* This is the default interrupt "handler" :-) */
  22671. ALIGN
  22672. ignore_int:
  22673. - cld
  22674. #ifdef CONFIG_PRINTK
  22675. + cmpl $2,%ss:early_recursion_flag
  22676. + je hlt_loop
  22677. + incl %ss:early_recursion_flag
  22678. + cld
  22679. pushl %eax
  22680. pushl %ecx
  22681. pushl %edx
  22682. @@ -617,9 +705,6 @@ ignore_int:
  22683. movl $(__KERNEL_DS),%eax
  22684. movl %eax,%ds
  22685. movl %eax,%es
  22686. - cmpl $2,early_recursion_flag
  22687. - je hlt_loop
  22688. - incl early_recursion_flag
  22689. pushl 16(%esp)
  22690. pushl 24(%esp)
  22691. pushl 32(%esp)
  22692. @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
  22693. /*
  22694. * BSS section
  22695. */
  22696. -__PAGE_ALIGNED_BSS
  22697. - .align PAGE_SIZE
  22698. #ifdef CONFIG_X86_PAE
  22699. +.section .initial_pg_pmd,"a",@progbits
  22700. initial_pg_pmd:
  22701. .fill 1024*KPMDS,4,0
  22702. #else
  22703. +.section .initial_page_table,"a",@progbits
  22704. ENTRY(initial_page_table)
  22705. .fill 1024,4,0
  22706. #endif
  22707. +.section .initial_pg_fixmap,"a",@progbits
  22708. initial_pg_fixmap:
  22709. .fill 1024,4,0
  22710. +.section .empty_zero_page,"a",@progbits
  22711. ENTRY(empty_zero_page)
  22712. .fill 4096,1,0
  22713. +.section .swapper_pg_dir,"a",@progbits
  22714. ENTRY(swapper_pg_dir)
  22715. +#ifdef CONFIG_X86_PAE
  22716. + .fill 4,8,0
  22717. +#else
  22718. .fill 1024,4,0
  22719. +#endif
  22720. /*
  22721. * This starts the data section.
  22722. */
  22723. #ifdef CONFIG_X86_PAE
  22724. -__PAGE_ALIGNED_DATA
  22725. - /* Page-aligned for the benefit of paravirt? */
  22726. - .align PAGE_SIZE
  22727. +.section .initial_page_table,"a",@progbits
  22728. ENTRY(initial_page_table)
  22729. .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
  22730. # if KPMDS == 3
  22731. @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
  22732. # error "Kernel PMDs should be 1, 2 or 3"
  22733. # endif
  22734. .align PAGE_SIZE /* needs to be page-sized too */
  22735. +
  22736. +#ifdef CONFIG_PAX_PER_CPU_PGD
  22737. +ENTRY(cpu_pgd)
  22738. + .rept 2*NR_CPUS
  22739. + .fill 4,8,0
  22740. + .endr
  22741. +#endif
  22742. +
  22743. #endif
  22744. .data
  22745. .balign 4
  22746. ENTRY(stack_start)
  22747. - .long init_thread_union+THREAD_SIZE
  22748. + .long init_thread_union+THREAD_SIZE-8
  22749. __INITRODATA
  22750. int_msg:
  22751. @@ -727,7 +825,7 @@ fault_msg:
  22752. * segment size, and 32-bit linear address value:
  22753. */
  22754. - .data
  22755. +.section .rodata,"a",@progbits
  22756. .globl boot_gdt_descr
  22757. .globl idt_descr
  22758. @@ -736,7 +834,7 @@ fault_msg:
  22759. .word 0 # 32 bit align gdt_desc.address
  22760. boot_gdt_descr:
  22761. .word __BOOT_DS+7
  22762. - .long boot_gdt - __PAGE_OFFSET
  22763. + .long pa(boot_gdt)
  22764. .word 0 # 32-bit align idt_desc.address
  22765. idt_descr:
  22766. @@ -747,7 +845,7 @@ idt_descr:
  22767. .word 0 # 32 bit align gdt_desc.address
  22768. ENTRY(early_gdt_descr)
  22769. .word GDT_ENTRIES*8-1
  22770. - .long gdt_page /* Overwritten for secondary CPUs */
  22771. + .long cpu_gdt_table /* Overwritten for secondary CPUs */
  22772. /*
  22773. * The boot_gdt must mirror the equivalent in setup.S and is
  22774. @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
  22775. .align L1_CACHE_BYTES
  22776. ENTRY(boot_gdt)
  22777. .fill GDT_ENTRY_BOOT_CS,8,0
  22778. - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
  22779. - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
  22780. + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
  22781. + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
  22782. +
  22783. + .align PAGE_SIZE_asm
  22784. +ENTRY(cpu_gdt_table)
  22785. + .rept NR_CPUS
  22786. + .quad 0x0000000000000000 /* NULL descriptor */
  22787. + .quad 0x0000000000000000 /* 0x0b reserved */
  22788. + .quad 0x0000000000000000 /* 0x13 reserved */
  22789. + .quad 0x0000000000000000 /* 0x1b reserved */
  22790. +
  22791. +#ifdef CONFIG_PAX_KERNEXEC
  22792. + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
  22793. +#else
  22794. + .quad 0x0000000000000000 /* 0x20 unused */
  22795. +#endif
  22796. +
  22797. + .quad 0x0000000000000000 /* 0x28 unused */
  22798. + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
  22799. + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
  22800. + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
  22801. + .quad 0x0000000000000000 /* 0x4b reserved */
  22802. + .quad 0x0000000000000000 /* 0x53 reserved */
  22803. + .quad 0x0000000000000000 /* 0x5b reserved */
  22804. +
  22805. + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
  22806. + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
  22807. + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
  22808. + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
  22809. +
  22810. + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
  22811. + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
  22812. +
  22813. + /*
  22814. + * Segments used for calling PnP BIOS have byte granularity.
  22815. + * The code segments and data segments have fixed 64k limits,
  22816. + * the transfer segment sizes are set at run time.
  22817. + */
  22818. + .quad 0x00409b000000ffff /* 0x90 32-bit code */
  22819. + .quad 0x00009b000000ffff /* 0x98 16-bit code */
  22820. + .quad 0x000093000000ffff /* 0xa0 16-bit data */
  22821. + .quad 0x0000930000000000 /* 0xa8 16-bit data */
  22822. + .quad 0x0000930000000000 /* 0xb0 16-bit data */
  22823. +
  22824. + /*
  22825. + * The APM segments have byte granularity and their bases
  22826. + * are set at run time. All have 64k limits.
  22827. + */
  22828. + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
  22829. + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
  22830. + .quad 0x004093000000ffff /* 0xc8 APM DS data */
  22831. +
  22832. + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
  22833. + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
  22834. + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
  22835. + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
  22836. + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
  22837. + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
  22838. +
  22839. + /* Be sure this is zeroed to avoid false validations in Xen */
  22840. + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
  22841. + .endr
  22842. diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
  22843. index a468c0a..c7dec74 100644
  22844. --- a/arch/x86/kernel/head_64.S
  22845. +++ b/arch/x86/kernel/head_64.S
  22846. @@ -20,6 +20,8 @@
  22847. #include <asm/processor-flags.h>
  22848. #include <asm/percpu.h>
  22849. #include <asm/nops.h>
  22850. +#include <asm/cpufeature.h>
  22851. +#include <asm/alternative-asm.h>
  22852. #ifdef CONFIG_PARAVIRT
  22853. #include <asm/asm-offsets.h>
  22854. @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
  22855. L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
  22856. L4_START_KERNEL = pgd_index(__START_KERNEL_map)
  22857. L3_START_KERNEL = pud_index(__START_KERNEL_map)
  22858. +L4_VMALLOC_START = pgd_index(VMALLOC_START)
  22859. +L3_VMALLOC_START = pud_index(VMALLOC_START)
  22860. +L4_VMALLOC_END = pgd_index(VMALLOC_END)
  22861. +L3_VMALLOC_END = pud_index(VMALLOC_END)
  22862. +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
  22863. +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
  22864. .text
  22865. __HEAD
  22866. @@ -89,11 +97,24 @@ startup_64:
  22867. * Fixup the physical addresses in the page table
  22868. */
  22869. addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
  22870. + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
  22871. + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
  22872. + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
  22873. + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
  22874. + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
  22875. - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
  22876. - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
  22877. + addq %rbp, level3_ident_pgt + (0*8)(%rip)
  22878. +#ifndef CONFIG_XEN
  22879. + addq %rbp, level3_ident_pgt + (1*8)(%rip)
  22880. +#endif
  22881. +
  22882. + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
  22883. +
  22884. + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
  22885. + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
  22886. addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
  22887. + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
  22888. /*
  22889. * Set up the identity mapping for the switchover. These
  22890. @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
  22891. movq $(init_level4_pgt - __START_KERNEL_map), %rax
  22892. 1:
  22893. - /* Enable PAE mode and PGE */
  22894. - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
  22895. + /* Enable PAE mode and PSE/PGE */
  22896. + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
  22897. movq %rcx, %cr4
  22898. /* Setup early boot stage 4 level pagetables. */
  22899. @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
  22900. movl $MSR_EFER, %ecx
  22901. rdmsr
  22902. btsl $_EFER_SCE, %eax /* Enable System Call */
  22903. - btl $20,%edi /* No Execute supported? */
  22904. + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
  22905. jnc 1f
  22906. btsl $_EFER_NX, %eax
  22907. btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
  22908. +#ifndef CONFIG_EFI
  22909. + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
  22910. +#endif
  22911. + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
  22912. + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
  22913. + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
  22914. + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
  22915. + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
  22916. + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
  22917. 1: wrmsr /* Make changes effective */
  22918. /* Setup cr0 */
  22919. @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
  22920. * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
  22921. * address given in m16:64.
  22922. */
  22923. + pax_set_fptr_mask
  22924. movq initial_code(%rip),%rax
  22925. pushq $0 # fake return address to stop unwinder
  22926. pushq $__KERNEL_CS # set correct cs
  22927. @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
  22928. .quad INIT_PER_CPU_VAR(irq_stack_union)
  22929. GLOBAL(stack_start)
  22930. - .quad init_thread_union+THREAD_SIZE-8
  22931. + .quad init_thread_union+THREAD_SIZE-16
  22932. .word 0
  22933. __FINITDATA
  22934. @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
  22935. call dump_stack
  22936. #ifdef CONFIG_KALLSYMS
  22937. leaq early_idt_ripmsg(%rip),%rdi
  22938. - movq 40(%rsp),%rsi # %rip again
  22939. + movq 88(%rsp),%rsi # %rip again
  22940. call __print_symbol
  22941. #endif
  22942. #endif /* EARLY_PRINTK */
  22943. @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
  22944. early_recursion_flag:
  22945. .long 0
  22946. + .section .rodata,"a",@progbits
  22947. #ifdef CONFIG_EARLY_PRINTK
  22948. early_idt_msg:
  22949. .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
  22950. @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
  22951. NEXT_PAGE(early_dynamic_pgts)
  22952. .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
  22953. - .data
  22954. + .section .rodata,"a",@progbits
  22955. -#ifndef CONFIG_XEN
  22956. NEXT_PAGE(init_level4_pgt)
  22957. - .fill 512,8,0
  22958. -#else
  22959. -NEXT_PAGE(init_level4_pgt)
  22960. - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22961. .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
  22962. .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22963. + .org init_level4_pgt + L4_VMALLOC_START*8, 0
  22964. + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22965. + .org init_level4_pgt + L4_VMALLOC_END*8, 0
  22966. + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22967. + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
  22968. + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22969. .org init_level4_pgt + L4_START_KERNEL*8, 0
  22970. /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
  22971. .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
  22972. +#ifdef CONFIG_PAX_PER_CPU_PGD
  22973. +NEXT_PAGE(cpu_pgd)
  22974. + .rept 2*NR_CPUS
  22975. + .fill 512,8,0
  22976. + .endr
  22977. +#endif
  22978. +
  22979. NEXT_PAGE(level3_ident_pgt)
  22980. .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22981. +#ifdef CONFIG_XEN
  22982. .fill 511, 8, 0
  22983. +#else
  22984. + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
  22985. + .fill 510,8,0
  22986. +#endif
  22987. +
  22988. +NEXT_PAGE(level3_vmalloc_start_pgt)
  22989. + .fill 512,8,0
  22990. +
  22991. +NEXT_PAGE(level3_vmalloc_end_pgt)
  22992. + .fill 512,8,0
  22993. +
  22994. +NEXT_PAGE(level3_vmemmap_pgt)
  22995. + .fill L3_VMEMMAP_START,8,0
  22996. + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
  22997. +
  22998. NEXT_PAGE(level2_ident_pgt)
  22999. - /* Since I easily can, map the first 1G.
  23000. + /* Since I easily can, map the first 2G.
  23001. * Don't set NX because code runs from these pages.
  23002. */
  23003. - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
  23004. -#endif
  23005. + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
  23006. NEXT_PAGE(level3_kernel_pgt)
  23007. .fill L3_START_KERNEL,8,0
  23008. @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
  23009. .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
  23010. .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
  23011. +NEXT_PAGE(level2_vmemmap_pgt)
  23012. + .fill 512,8,0
  23013. +
  23014. NEXT_PAGE(level2_kernel_pgt)
  23015. /*
  23016. * 512 MB kernel mapping. We spend a full page on this pagetable
  23017. @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
  23018. NEXT_PAGE(level2_fixmap_pgt)
  23019. .fill 506,8,0
  23020. .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
  23021. - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
  23022. - .fill 5,8,0
  23023. + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
  23024. + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
  23025. + .fill 4,8,0
  23026. NEXT_PAGE(level1_fixmap_pgt)
  23027. .fill 512,8,0
  23028. +NEXT_PAGE(level1_vsyscall_pgt)
  23029. + .fill 512,8,0
  23030. +
  23031. #undef PMDS
  23032. - .data
  23033. + .align PAGE_SIZE
  23034. +ENTRY(cpu_gdt_table)
  23035. + .rept NR_CPUS
  23036. + .quad 0x0000000000000000 /* NULL descriptor */
  23037. + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
  23038. + .quad 0x00af9b000000ffff /* __KERNEL_CS */
  23039. + .quad 0x00cf93000000ffff /* __KERNEL_DS */
  23040. + .quad 0x00cffb000000ffff /* __USER32_CS */
  23041. + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
  23042. + .quad 0x00affb000000ffff /* __USER_CS */
  23043. +
  23044. +#ifdef CONFIG_PAX_KERNEXEC
  23045. + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
  23046. +#else
  23047. + .quad 0x0 /* unused */
  23048. +#endif
  23049. +
  23050. + .quad 0,0 /* TSS */
  23051. + .quad 0,0 /* LDT */
  23052. + .quad 0,0,0 /* three TLS descriptors */
  23053. + .quad 0x0000f40000000000 /* node/CPU stored in limit */
  23054. + /* asm/segment.h:GDT_ENTRIES must match this */
  23055. +
  23056. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  23057. + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
  23058. +#else
  23059. + .quad 0x0 /* unused */
  23060. +#endif
  23061. +
  23062. + /* zero the remaining page */
  23063. + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
  23064. + .endr
  23065. +
  23066. .align 16
  23067. .globl early_gdt_descr
  23068. early_gdt_descr:
  23069. .word GDT_ENTRIES*8-1
  23070. early_gdt_descr_base:
  23071. - .quad INIT_PER_CPU_VAR(gdt_page)
  23072. + .quad cpu_gdt_table
  23073. ENTRY(phys_base)
  23074. /* This must match the first entry in level2_kernel_pgt */
  23075. .quad 0x0000000000000000
  23076. #include "../../x86/xen/xen-head.S"
  23077. -
  23078. - __PAGE_ALIGNED_BSS
  23079. +
  23080. + .section .rodata,"a",@progbits
  23081. NEXT_PAGE(empty_zero_page)
  23082. .skip PAGE_SIZE
  23083. diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
  23084. index 05fd74f..c3548b1 100644
  23085. --- a/arch/x86/kernel/i386_ksyms_32.c
  23086. +++ b/arch/x86/kernel/i386_ksyms_32.c
  23087. @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
  23088. EXPORT_SYMBOL(cmpxchg8b_emu);
  23089. #endif
  23090. +EXPORT_SYMBOL_GPL(cpu_gdt_table);
  23091. +
  23092. /* Networking helper routines. */
  23093. EXPORT_SYMBOL(csum_partial_copy_generic);
  23094. +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
  23095. +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
  23096. EXPORT_SYMBOL(__get_user_1);
  23097. EXPORT_SYMBOL(__get_user_2);
  23098. @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
  23099. EXPORT_SYMBOL(___preempt_schedule_context);
  23100. #endif
  23101. #endif
  23102. +
  23103. +#ifdef CONFIG_PAX_KERNEXEC
  23104. +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
  23105. +#endif
  23106. +
  23107. +#ifdef CONFIG_PAX_PER_CPU_PGD
  23108. +EXPORT_SYMBOL(cpu_pgd);
  23109. +#endif
  23110. diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
  23111. index d5dd808..b6432cf 100644
  23112. --- a/arch/x86/kernel/i387.c
  23113. +++ b/arch/x86/kernel/i387.c
  23114. @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
  23115. static inline bool interrupted_user_mode(void)
  23116. {
  23117. struct pt_regs *regs = get_irq_regs();
  23118. - return regs && user_mode_vm(regs);
  23119. + return regs && user_mode(regs);
  23120. }
  23121. /*
  23122. diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
  23123. index 2e977b5..5f2c273 100644
  23124. --- a/arch/x86/kernel/i8259.c
  23125. +++ b/arch/x86/kernel/i8259.c
  23126. @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
  23127. static void make_8259A_irq(unsigned int irq)
  23128. {
  23129. disable_irq_nosync(irq);
  23130. - io_apic_irqs &= ~(1<<irq);
  23131. + io_apic_irqs &= ~(1UL<<irq);
  23132. irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
  23133. i8259A_chip.name);
  23134. enable_irq(irq);
  23135. @@ -209,7 +209,7 @@ spurious_8259A_irq:
  23136. "spurious 8259A interrupt: IRQ%d.\n", irq);
  23137. spurious_irq_mask |= irqmask;
  23138. }
  23139. - atomic_inc(&irq_err_count);
  23140. + atomic_inc_unchecked(&irq_err_count);
  23141. /*
  23142. * Theoretically we do not have to handle this IRQ,
  23143. * but in Linux this does not cause problems and is
  23144. @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
  23145. /* (slave's support for AEOI in flat mode is to be investigated) */
  23146. outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
  23147. + pax_open_kernel();
  23148. if (auto_eoi)
  23149. /*
  23150. * In AEOI mode we just have to mask the interrupt
  23151. * when acking.
  23152. */
  23153. - i8259A_chip.irq_mask_ack = disable_8259A_irq;
  23154. + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
  23155. else
  23156. - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
  23157. + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
  23158. + pax_close_kernel();
  23159. udelay(100); /* wait for 8259A to initialize */
  23160. diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
  23161. index a979b5b..1d6db75 100644
  23162. --- a/arch/x86/kernel/io_delay.c
  23163. +++ b/arch/x86/kernel/io_delay.c
  23164. @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
  23165. * Quirk table for systems that misbehave (lock up, etc.) if port
  23166. * 0x80 is used:
  23167. */
  23168. -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
  23169. +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
  23170. {
  23171. .callback = dmi_io_delay_0xed_port,
  23172. .ident = "Compaq Presario V6000",
  23173. diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
  23174. index 4ddaf66..49d5c18 100644
  23175. --- a/arch/x86/kernel/ioport.c
  23176. +++ b/arch/x86/kernel/ioport.c
  23177. @@ -6,6 +6,7 @@
  23178. #include <linux/sched.h>
  23179. #include <linux/kernel.h>
  23180. #include <linux/capability.h>
  23181. +#include <linux/security.h>
  23182. #include <linux/errno.h>
  23183. #include <linux/types.h>
  23184. #include <linux/ioport.h>
  23185. @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
  23186. return -EINVAL;
  23187. if (turn_on && !capable(CAP_SYS_RAWIO))
  23188. return -EPERM;
  23189. +#ifdef CONFIG_GRKERNSEC_IO
  23190. + if (turn_on && grsec_disable_privio) {
  23191. + gr_handle_ioperm();
  23192. + return -ENODEV;
  23193. + }
  23194. +#endif
  23195. /*
  23196. * If it's the first ioperm() call in this thread's lifetime, set the
  23197. @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
  23198. * because the ->io_bitmap_max value must match the bitmap
  23199. * contents:
  23200. */
  23201. - tss = &per_cpu(init_tss, get_cpu());
  23202. + tss = init_tss + get_cpu();
  23203. if (turn_on)
  23204. bitmap_clear(t->io_bitmap_ptr, from, num);
  23205. @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
  23206. if (level > old) {
  23207. if (!capable(CAP_SYS_RAWIO))
  23208. return -EPERM;
  23209. +#ifdef CONFIG_GRKERNSEC_IO
  23210. + if (grsec_disable_privio) {
  23211. + gr_handle_iopl();
  23212. + return -ENODEV;
  23213. + }
  23214. +#endif
  23215. }
  23216. regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
  23217. t->iopl = level << 12;
  23218. diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
  23219. index d99f31d..1c0f466 100644
  23220. --- a/arch/x86/kernel/irq.c
  23221. +++ b/arch/x86/kernel/irq.c
  23222. @@ -21,7 +21,7 @@
  23223. #define CREATE_TRACE_POINTS
  23224. #include <asm/trace/irq_vectors.h>
  23225. -atomic_t irq_err_count;
  23226. +atomic_unchecked_t irq_err_count;
  23227. /* Function pointer for generic interrupt vector handling */
  23228. void (*x86_platform_ipi_callback)(void) = NULL;
  23229. @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
  23230. seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
  23231. seq_printf(p, " Machine check polls\n");
  23232. #endif
  23233. - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  23234. + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
  23235. #if defined(CONFIG_X86_IO_APIC)
  23236. - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
  23237. + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
  23238. #endif
  23239. return 0;
  23240. }
  23241. @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
  23242. u64 arch_irq_stat(void)
  23243. {
  23244. - u64 sum = atomic_read(&irq_err_count);
  23245. + u64 sum = atomic_read_unchecked(&irq_err_count);
  23246. return sum;
  23247. }
  23248. diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
  23249. index d7fcbed..96e715a 100644
  23250. --- a/arch/x86/kernel/irq_32.c
  23251. +++ b/arch/x86/kernel/irq_32.c
  23252. @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
  23253. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  23254. +extern void gr_handle_kernel_exploit(void);
  23255. +
  23256. int sysctl_panic_on_stackoverflow __read_mostly;
  23257. /* Debugging check for stack overflow: is there less than 1KB free? */
  23258. @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
  23259. __asm__ __volatile__("andl %%esp,%0" :
  23260. "=r" (sp) : "0" (THREAD_SIZE - 1));
  23261. - return sp < (sizeof(struct thread_info) + STACK_WARN);
  23262. + return sp < STACK_WARN;
  23263. }
  23264. static void print_stack_overflow(void)
  23265. {
  23266. printk(KERN_WARNING "low stack detected by irq handler\n");
  23267. dump_stack();
  23268. + gr_handle_kernel_exploit();
  23269. if (sysctl_panic_on_stackoverflow)
  23270. panic("low stack detected by irq handler - check messages\n");
  23271. }
  23272. @@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
  23273. * per-CPU IRQ handling contexts (thread information and stack)
  23274. */
  23275. union irq_ctx {
  23276. - struct thread_info tinfo;
  23277. - u32 stack[THREAD_SIZE/sizeof(u32)];
  23278. + unsigned long previous_esp;
  23279. + u32 stack[THREAD_SIZE/sizeof(u32)];
  23280. } __attribute__((aligned(THREAD_SIZE)));
  23281. static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
  23282. @@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
  23283. static inline int
  23284. execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
  23285. {
  23286. - union irq_ctx *curctx, *irqctx;
  23287. + union irq_ctx *irqctx;
  23288. u32 *isp, arg1, arg2;
  23289. - curctx = (union irq_ctx *) current_thread_info();
  23290. irqctx = __this_cpu_read(hardirq_ctx);
  23291. /*
  23292. @@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
  23293. * handler) we can't do that and just have to keep using the
  23294. * current stack (which is the irq stack already after all)
  23295. */
  23296. - if (unlikely(curctx == irqctx))
  23297. + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
  23298. return 0;
  23299. /* build the stack frame on the IRQ stack */
  23300. - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
  23301. - irqctx->tinfo.task = curctx->tinfo.task;
  23302. - irqctx->tinfo.previous_esp = current_stack_pointer;
  23303. + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
  23304. + irqctx->previous_esp = current_stack_pointer;
  23305. +
  23306. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  23307. + __set_fs(MAKE_MM_SEG(0));
  23308. +#endif
  23309. if (unlikely(overflow))
  23310. call_on_stack(print_stack_overflow, isp);
  23311. @@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
  23312. : "0" (irq), "1" (desc), "2" (isp),
  23313. "D" (desc->handle_irq)
  23314. : "memory", "cc", "ecx");
  23315. +
  23316. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  23317. + __set_fs(current_thread_info()->addr_limit);
  23318. +#endif
  23319. +
  23320. return 1;
  23321. }
  23322. @@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
  23323. */
  23324. void irq_ctx_init(int cpu)
  23325. {
  23326. - union irq_ctx *irqctx;
  23327. -
  23328. if (per_cpu(hardirq_ctx, cpu))
  23329. return;
  23330. - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
  23331. - THREADINFO_GFP,
  23332. - THREAD_SIZE_ORDER));
  23333. - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
  23334. - irqctx->tinfo.cpu = cpu;
  23335. - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  23336. -
  23337. - per_cpu(hardirq_ctx, cpu) = irqctx;
  23338. -
  23339. - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
  23340. - THREADINFO_GFP,
  23341. - THREAD_SIZE_ORDER));
  23342. - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
  23343. - irqctx->tinfo.cpu = cpu;
  23344. - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  23345. -
  23346. - per_cpu(softirq_ctx, cpu) = irqctx;
  23347. -
  23348. - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
  23349. - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
  23350. + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
  23351. + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
  23352. }
  23353. void do_softirq_own_stack(void)
  23354. {
  23355. - struct thread_info *curctx;
  23356. union irq_ctx *irqctx;
  23357. u32 *isp;
  23358. - curctx = current_thread_info();
  23359. irqctx = __this_cpu_read(softirq_ctx);
  23360. - irqctx->tinfo.task = curctx->task;
  23361. - irqctx->tinfo.previous_esp = current_stack_pointer;
  23362. + irqctx->previous_esp = current_stack_pointer;
  23363. /* build the stack frame on the softirq stack */
  23364. - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
  23365. + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
  23366. +
  23367. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  23368. + __set_fs(MAKE_MM_SEG(0));
  23369. +#endif
  23370. call_on_stack(__do_softirq, isp);
  23371. +
  23372. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  23373. + __set_fs(current_thread_info()->addr_limit);
  23374. +#endif
  23375. +
  23376. }
  23377. bool handle_irq(unsigned irq, struct pt_regs *regs)
  23378. @@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
  23379. if (unlikely(!desc))
  23380. return false;
  23381. - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
  23382. + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
  23383. if (unlikely(overflow))
  23384. print_stack_overflow();
  23385. desc->handle_irq(irq, desc);
  23386. diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
  23387. index 4d1c746..55a22d6 100644
  23388. --- a/arch/x86/kernel/irq_64.c
  23389. +++ b/arch/x86/kernel/irq_64.c
  23390. @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
  23391. DEFINE_PER_CPU(struct pt_regs *, irq_regs);
  23392. EXPORT_PER_CPU_SYMBOL(irq_regs);
  23393. +extern void gr_handle_kernel_exploit(void);
  23394. +
  23395. int sysctl_panic_on_stackoverflow;
  23396. /*
  23397. @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
  23398. u64 estack_top, estack_bottom;
  23399. u64 curbase = (u64)task_stack_page(current);
  23400. - if (user_mode_vm(regs))
  23401. + if (user_mode(regs))
  23402. return;
  23403. if (regs->sp >= curbase + sizeof(struct thread_info) +
  23404. @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
  23405. irq_stack_top, irq_stack_bottom,
  23406. estack_top, estack_bottom);
  23407. + gr_handle_kernel_exploit();
  23408. +
  23409. if (sysctl_panic_on_stackoverflow)
  23410. panic("low stack detected by irq handler - check messages\n");
  23411. #endif
  23412. diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
  23413. index 26d5a55..a01160a 100644
  23414. --- a/arch/x86/kernel/jump_label.c
  23415. +++ b/arch/x86/kernel/jump_label.c
  23416. @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
  23417. * Jump label is enabled for the first time.
  23418. * So we expect a default_nop...
  23419. */
  23420. - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
  23421. + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
  23422. != 0))
  23423. bug_at((void *)entry->code, __LINE__);
  23424. } else {
  23425. @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
  23426. * ...otherwise expect an ideal_nop. Otherwise
  23427. * something went horribly wrong.
  23428. */
  23429. - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
  23430. + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
  23431. != 0))
  23432. bug_at((void *)entry->code, __LINE__);
  23433. }
  23434. @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
  23435. * are converting the default nop to the ideal nop.
  23436. */
  23437. if (init) {
  23438. - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
  23439. + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
  23440. bug_at((void *)entry->code, __LINE__);
  23441. } else {
  23442. code.jump = 0xe9;
  23443. code.offset = entry->target -
  23444. (entry->code + JUMP_LABEL_NOP_SIZE);
  23445. - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
  23446. + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
  23447. bug_at((void *)entry->code, __LINE__);
  23448. }
  23449. memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
  23450. diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
  23451. index 7ec1d5f..5a7d130 100644
  23452. --- a/arch/x86/kernel/kgdb.c
  23453. +++ b/arch/x86/kernel/kgdb.c
  23454. @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
  23455. #ifdef CONFIG_X86_32
  23456. switch (regno) {
  23457. case GDB_SS:
  23458. - if (!user_mode_vm(regs))
  23459. + if (!user_mode(regs))
  23460. *(unsigned long *)mem = __KERNEL_DS;
  23461. break;
  23462. case GDB_SP:
  23463. - if (!user_mode_vm(regs))
  23464. + if (!user_mode(regs))
  23465. *(unsigned long *)mem = kernel_stack_pointer(regs);
  23466. break;
  23467. case GDB_GS:
  23468. @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
  23469. bp->attr.bp_addr = breakinfo[breakno].addr;
  23470. bp->attr.bp_len = breakinfo[breakno].len;
  23471. bp->attr.bp_type = breakinfo[breakno].type;
  23472. - info->address = breakinfo[breakno].addr;
  23473. + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
  23474. + info->address = ktla_ktva(breakinfo[breakno].addr);
  23475. + else
  23476. + info->address = breakinfo[breakno].addr;
  23477. info->len = breakinfo[breakno].len;
  23478. info->type = breakinfo[breakno].type;
  23479. val = arch_install_hw_breakpoint(bp);
  23480. @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
  23481. case 'k':
  23482. /* clear the trace bit */
  23483. linux_regs->flags &= ~X86_EFLAGS_TF;
  23484. - atomic_set(&kgdb_cpu_doing_single_step, -1);
  23485. + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
  23486. /* set the trace bit if we're stepping */
  23487. if (remcomInBuffer[0] == 's') {
  23488. linux_regs->flags |= X86_EFLAGS_TF;
  23489. - atomic_set(&kgdb_cpu_doing_single_step,
  23490. + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
  23491. raw_smp_processor_id());
  23492. }
  23493. @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
  23494. switch (cmd) {
  23495. case DIE_DEBUG:
  23496. - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
  23497. + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
  23498. if (user_mode(regs))
  23499. return single_step_cont(regs, args);
  23500. break;
  23501. @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
  23502. #endif /* CONFIG_DEBUG_RODATA */
  23503. bpt->type = BP_BREAKPOINT;
  23504. - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
  23505. + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
  23506. BREAK_INSTR_SIZE);
  23507. if (err)
  23508. return err;
  23509. - err = probe_kernel_write((char *)bpt->bpt_addr,
  23510. + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
  23511. arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
  23512. #ifdef CONFIG_DEBUG_RODATA
  23513. if (!err)
  23514. @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
  23515. return -EBUSY;
  23516. text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
  23517. BREAK_INSTR_SIZE);
  23518. - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
  23519. + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
  23520. if (err)
  23521. return err;
  23522. if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
  23523. @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
  23524. if (mutex_is_locked(&text_mutex))
  23525. goto knl_write;
  23526. text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
  23527. - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
  23528. + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
  23529. if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
  23530. goto knl_write;
  23531. return err;
  23532. knl_write:
  23533. #endif /* CONFIG_DEBUG_RODATA */
  23534. - return probe_kernel_write((char *)bpt->bpt_addr,
  23535. + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
  23536. (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
  23537. }
  23538. diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
  23539. index 79a3f96..6ba030a 100644
  23540. --- a/arch/x86/kernel/kprobes/core.c
  23541. +++ b/arch/x86/kernel/kprobes/core.c
  23542. @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
  23543. s32 raddr;
  23544. } __packed *insn;
  23545. - insn = (struct __arch_relative_insn *)from;
  23546. + insn = (struct __arch_relative_insn *)ktla_ktva(from);
  23547. +
  23548. + pax_open_kernel();
  23549. insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
  23550. insn->op = op;
  23551. + pax_close_kernel();
  23552. }
  23553. /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
  23554. @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
  23555. kprobe_opcode_t opcode;
  23556. kprobe_opcode_t *orig_opcodes = opcodes;
  23557. - if (search_exception_tables((unsigned long)opcodes))
  23558. + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
  23559. return 0; /* Page fault may occur on this address. */
  23560. retry:
  23561. @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
  23562. * for the first byte, we can recover the original instruction
  23563. * from it and kp->opcode.
  23564. */
  23565. - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
  23566. + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
  23567. buf[0] = kp->opcode;
  23568. - return (unsigned long)buf;
  23569. + return ktva_ktla((unsigned long)buf);
  23570. }
  23571. /*
  23572. @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
  23573. /* Another subsystem puts a breakpoint, failed to recover */
  23574. if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
  23575. return 0;
  23576. + pax_open_kernel();
  23577. memcpy(dest, insn.kaddr, insn.length);
  23578. + pax_close_kernel();
  23579. #ifdef CONFIG_X86_64
  23580. if (insn_rip_relative(&insn)) {
  23581. @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
  23582. return 0;
  23583. }
  23584. disp = (u8 *) dest + insn_offset_displacement(&insn);
  23585. + pax_open_kernel();
  23586. *(s32 *) disp = (s32) newdisp;
  23587. + pax_close_kernel();
  23588. }
  23589. #endif
  23590. return insn.length;
  23591. @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
  23592. * nor set current_kprobe, because it doesn't use single
  23593. * stepping.
  23594. */
  23595. - regs->ip = (unsigned long)p->ainsn.insn;
  23596. + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
  23597. preempt_enable_no_resched();
  23598. return;
  23599. }
  23600. @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
  23601. regs->flags &= ~X86_EFLAGS_IF;
  23602. /* single step inline if the instruction is an int3 */
  23603. if (p->opcode == BREAKPOINT_INSTRUCTION)
  23604. - regs->ip = (unsigned long)p->addr;
  23605. + regs->ip = ktla_ktva((unsigned long)p->addr);
  23606. else
  23607. - regs->ip = (unsigned long)p->ainsn.insn;
  23608. + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
  23609. }
  23610. /*
  23611. @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
  23612. setup_singlestep(p, regs, kcb, 0);
  23613. return 1;
  23614. }
  23615. - } else if (*addr != BREAKPOINT_INSTRUCTION) {
  23616. + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
  23617. /*
  23618. * The breakpoint instruction was removed right
  23619. * after we hit it. Another cpu has removed
  23620. @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
  23621. " movq %rax, 152(%rsp)\n"
  23622. RESTORE_REGS_STRING
  23623. " popfq\n"
  23624. +#ifdef KERNEXEC_PLUGIN
  23625. + " btsq $63,(%rsp)\n"
  23626. +#endif
  23627. #else
  23628. " pushf\n"
  23629. SAVE_REGS_STRING
  23630. @@ -779,7 +789,7 @@ static void __kprobes
  23631. resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
  23632. {
  23633. unsigned long *tos = stack_addr(regs);
  23634. - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
  23635. + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
  23636. unsigned long orig_ip = (unsigned long)p->addr;
  23637. kprobe_opcode_t *insn = p->ainsn.insn;
  23638. @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
  23639. struct die_args *args = data;
  23640. int ret = NOTIFY_DONE;
  23641. - if (args->regs && user_mode_vm(args->regs))
  23642. + if (args->regs && user_mode(args->regs))
  23643. return ret;
  23644. switch (val) {
  23645. diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
  23646. index 898160b..758cde8 100644
  23647. --- a/arch/x86/kernel/kprobes/opt.c
  23648. +++ b/arch/x86/kernel/kprobes/opt.c
  23649. @@ -79,6 +79,7 @@ found:
  23650. /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
  23651. static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
  23652. {
  23653. + pax_open_kernel();
  23654. #ifdef CONFIG_X86_64
  23655. *addr++ = 0x48;
  23656. *addr++ = 0xbf;
  23657. @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
  23658. *addr++ = 0xb8;
  23659. #endif
  23660. *(unsigned long *)addr = val;
  23661. + pax_close_kernel();
  23662. }
  23663. asm (
  23664. @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
  23665. * Verify if the address gap is in 2GB range, because this uses
  23666. * a relative jump.
  23667. */
  23668. - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
  23669. + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
  23670. if (abs(rel) > 0x7fffffff)
  23671. return -ERANGE;
  23672. @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
  23673. op->optinsn.size = ret;
  23674. /* Copy arch-dep-instance from template */
  23675. - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
  23676. + pax_open_kernel();
  23677. + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
  23678. + pax_close_kernel();
  23679. /* Set probe information */
  23680. synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
  23681. /* Set probe function call */
  23682. - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
  23683. + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
  23684. /* Set returning jmp instruction at the tail of out-of-line buffer */
  23685. - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
  23686. + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
  23687. (u8 *)op->kp.addr + op->optinsn.size);
  23688. flush_icache_range((unsigned long) buf,
  23689. @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
  23690. WARN_ON(kprobe_disabled(&op->kp));
  23691. /* Backup instructions which will be replaced by jump address */
  23692. - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
  23693. + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
  23694. RELATIVE_ADDR_SIZE);
  23695. insn_buf[0] = RELATIVEJUMP_OPCODE;
  23696. @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
  23697. /* This kprobe is really able to run optimized path. */
  23698. op = container_of(p, struct optimized_kprobe, kp);
  23699. /* Detour through copied instructions */
  23700. - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
  23701. + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
  23702. if (!reenter)
  23703. reset_current_kprobe();
  23704. preempt_enable_no_resched();
  23705. diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
  23706. index c2bedae..25e7ab6 100644
  23707. --- a/arch/x86/kernel/ksysfs.c
  23708. +++ b/arch/x86/kernel/ksysfs.c
  23709. @@ -184,7 +184,7 @@ out:
  23710. static struct kobj_attribute type_attr = __ATTR_RO(type);
  23711. -static struct bin_attribute data_attr = {
  23712. +static bin_attribute_no_const data_attr __read_only = {
  23713. .attr = {
  23714. .name = "data",
  23715. .mode = S_IRUGO,
  23716. diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
  23717. index af1d14a..37b8776 100644
  23718. --- a/arch/x86/kernel/ldt.c
  23719. +++ b/arch/x86/kernel/ldt.c
  23720. @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
  23721. if (reload) {
  23722. #ifdef CONFIG_SMP
  23723. preempt_disable();
  23724. - load_LDT(pc);
  23725. + load_LDT_nolock(pc);
  23726. if (!cpumask_equal(mm_cpumask(current->mm),
  23727. cpumask_of(smp_processor_id())))
  23728. smp_call_function(flush_ldt, current->mm, 1);
  23729. preempt_enable();
  23730. #else
  23731. - load_LDT(pc);
  23732. + load_LDT_nolock(pc);
  23733. #endif
  23734. }
  23735. if (oldsize) {
  23736. @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
  23737. return err;
  23738. for (i = 0; i < old->size; i++)
  23739. - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
  23740. + write_ldt_entry(new->ldt, i, old->ldt + i);
  23741. return 0;
  23742. }
  23743. @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  23744. retval = copy_ldt(&mm->context, &old_mm->context);
  23745. mutex_unlock(&old_mm->context.lock);
  23746. }
  23747. +
  23748. + if (tsk == current) {
  23749. + mm->context.vdso = 0;
  23750. +
  23751. +#ifdef CONFIG_X86_32
  23752. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  23753. + mm->context.user_cs_base = 0UL;
  23754. + mm->context.user_cs_limit = ~0UL;
  23755. +
  23756. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
  23757. + cpus_clear(mm->context.cpu_user_cs_mask);
  23758. +#endif
  23759. +
  23760. +#endif
  23761. +#endif
  23762. +
  23763. + }
  23764. +
  23765. return retval;
  23766. }
  23767. @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
  23768. }
  23769. }
  23770. +#ifdef CONFIG_PAX_SEGMEXEC
  23771. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
  23772. + error = -EINVAL;
  23773. + goto out_unlock;
  23774. + }
  23775. +#endif
  23776. +
  23777. /*
  23778. * On x86-64 we do not support 16-bit segments due to
  23779. * IRET leaking the high bits of the kernel stack address.
  23780. diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
  23781. index 1667b1d..16492c5 100644
  23782. --- a/arch/x86/kernel/machine_kexec_32.c
  23783. +++ b/arch/x86/kernel/machine_kexec_32.c
  23784. @@ -25,7 +25,7 @@
  23785. #include <asm/cacheflush.h>
  23786. #include <asm/debugreg.h>
  23787. -static void set_idt(void *newidt, __u16 limit)
  23788. +static void set_idt(struct desc_struct *newidt, __u16 limit)
  23789. {
  23790. struct desc_ptr curidt;
  23791. @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
  23792. }
  23793. -static void set_gdt(void *newgdt, __u16 limit)
  23794. +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
  23795. {
  23796. struct desc_ptr curgdt;
  23797. @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
  23798. }
  23799. control_page = page_address(image->control_code_page);
  23800. - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
  23801. + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
  23802. relocate_kernel_ptr = control_page;
  23803. page_list[PA_CONTROL_PAGE] = __pa(control_page);
  23804. diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
  23805. index 18be189..4a9fe40 100644
  23806. --- a/arch/x86/kernel/module.c
  23807. +++ b/arch/x86/kernel/module.c
  23808. @@ -43,15 +43,60 @@ do { \
  23809. } while (0)
  23810. #endif
  23811. -void *module_alloc(unsigned long size)
  23812. +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
  23813. {
  23814. - if (PAGE_ALIGN(size) > MODULES_LEN)
  23815. + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
  23816. return NULL;
  23817. return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
  23818. - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
  23819. + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
  23820. NUMA_NO_NODE, __builtin_return_address(0));
  23821. }
  23822. +void *module_alloc(unsigned long size)
  23823. +{
  23824. +
  23825. +#ifdef CONFIG_PAX_KERNEXEC
  23826. + return __module_alloc(size, PAGE_KERNEL);
  23827. +#else
  23828. + return __module_alloc(size, PAGE_KERNEL_EXEC);
  23829. +#endif
  23830. +
  23831. +}
  23832. +
  23833. +#ifdef CONFIG_PAX_KERNEXEC
  23834. +#ifdef CONFIG_X86_32
  23835. +void *module_alloc_exec(unsigned long size)
  23836. +{
  23837. + struct vm_struct *area;
  23838. +
  23839. + if (size == 0)
  23840. + return NULL;
  23841. +
  23842. + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
  23843. + return area ? area->addr : NULL;
  23844. +}
  23845. +EXPORT_SYMBOL(module_alloc_exec);
  23846. +
  23847. +void module_free_exec(struct module *mod, void *module_region)
  23848. +{
  23849. + vunmap(module_region);
  23850. +}
  23851. +EXPORT_SYMBOL(module_free_exec);
  23852. +#else
  23853. +void module_free_exec(struct module *mod, void *module_region)
  23854. +{
  23855. + module_free(mod, module_region);
  23856. +}
  23857. +EXPORT_SYMBOL(module_free_exec);
  23858. +
  23859. +void *module_alloc_exec(unsigned long size)
  23860. +{
  23861. + return __module_alloc(size, PAGE_KERNEL_RX);
  23862. +}
  23863. +EXPORT_SYMBOL(module_alloc_exec);
  23864. +#endif
  23865. +#endif
  23866. +
  23867. #ifdef CONFIG_X86_32
  23868. int apply_relocate(Elf32_Shdr *sechdrs,
  23869. const char *strtab,
  23870. @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
  23871. unsigned int i;
  23872. Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
  23873. Elf32_Sym *sym;
  23874. - uint32_t *location;
  23875. + uint32_t *plocation, location;
  23876. DEBUGP("Applying relocate section %u to %u\n",
  23877. relsec, sechdrs[relsec].sh_info);
  23878. for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
  23879. /* This is where to make the change */
  23880. - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
  23881. - + rel[i].r_offset;
  23882. + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
  23883. + location = (uint32_t)plocation;
  23884. + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
  23885. + plocation = ktla_ktva((void *)plocation);
  23886. /* This is the symbol it is referring to. Note that all
  23887. undefined symbols have been resolved. */
  23888. sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
  23889. @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
  23890. switch (ELF32_R_TYPE(rel[i].r_info)) {
  23891. case R_386_32:
  23892. /* We add the value into the location given */
  23893. - *location += sym->st_value;
  23894. + pax_open_kernel();
  23895. + *plocation += sym->st_value;
  23896. + pax_close_kernel();
  23897. break;
  23898. case R_386_PC32:
  23899. /* Add the value, subtract its position */
  23900. - *location += sym->st_value - (uint32_t)location;
  23901. + pax_open_kernel();
  23902. + *plocation += sym->st_value - location;
  23903. + pax_close_kernel();
  23904. break;
  23905. default:
  23906. pr_err("%s: Unknown relocation: %u\n",
  23907. @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
  23908. case R_X86_64_NONE:
  23909. break;
  23910. case R_X86_64_64:
  23911. + pax_open_kernel();
  23912. *(u64 *)loc = val;
  23913. + pax_close_kernel();
  23914. break;
  23915. case R_X86_64_32:
  23916. + pax_open_kernel();
  23917. *(u32 *)loc = val;
  23918. + pax_close_kernel();
  23919. if (val != *(u32 *)loc)
  23920. goto overflow;
  23921. break;
  23922. case R_X86_64_32S:
  23923. + pax_open_kernel();
  23924. *(s32 *)loc = val;
  23925. + pax_close_kernel();
  23926. if ((s64)val != *(s32 *)loc)
  23927. goto overflow;
  23928. break;
  23929. case R_X86_64_PC32:
  23930. val -= (u64)loc;
  23931. + pax_open_kernel();
  23932. *(u32 *)loc = val;
  23933. + pax_close_kernel();
  23934. +
  23935. #if 0
  23936. if ((s64)val != *(s32 *)loc)
  23937. goto overflow;
  23938. diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
  23939. index 05266b5..3432443 100644
  23940. --- a/arch/x86/kernel/msr.c
  23941. +++ b/arch/x86/kernel/msr.c
  23942. @@ -37,6 +37,7 @@
  23943. #include <linux/notifier.h>
  23944. #include <linux/uaccess.h>
  23945. #include <linux/gfp.h>
  23946. +#include <linux/grsecurity.h>
  23947. #include <asm/processor.h>
  23948. #include <asm/msr.h>
  23949. @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
  23950. int err = 0;
  23951. ssize_t bytes = 0;
  23952. +#ifdef CONFIG_GRKERNSEC_KMEM
  23953. + gr_handle_msr_write();
  23954. + return -EPERM;
  23955. +#endif
  23956. +
  23957. if (count % 8)
  23958. return -EINVAL; /* Invalid chunk size */
  23959. @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
  23960. err = -EBADF;
  23961. break;
  23962. }
  23963. +#ifdef CONFIG_GRKERNSEC_KMEM
  23964. + gr_handle_msr_write();
  23965. + return -EPERM;
  23966. +#endif
  23967. if (copy_from_user(&regs, uregs, sizeof regs)) {
  23968. err = -EFAULT;
  23969. break;
  23970. @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
  23971. return notifier_from_errno(err);
  23972. }
  23973. -static struct notifier_block __refdata msr_class_cpu_notifier = {
  23974. +static struct notifier_block msr_class_cpu_notifier = {
  23975. .notifier_call = msr_class_cpu_callback,
  23976. };
  23977. diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
  23978. index 6fcb49c..5b3f4ff 100644
  23979. --- a/arch/x86/kernel/nmi.c
  23980. +++ b/arch/x86/kernel/nmi.c
  23981. @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
  23982. return handled;
  23983. }
  23984. -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
  23985. +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
  23986. {
  23987. struct nmi_desc *desc = nmi_to_desc(type);
  23988. unsigned long flags;
  23989. @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
  23990. * event confuses some handlers (kdump uses this flag)
  23991. */
  23992. if (action->flags & NMI_FLAG_FIRST)
  23993. - list_add_rcu(&action->list, &desc->head);
  23994. + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
  23995. else
  23996. - list_add_tail_rcu(&action->list, &desc->head);
  23997. + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
  23998. spin_unlock_irqrestore(&desc->lock, flags);
  23999. return 0;
  24000. @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
  24001. if (!strcmp(n->name, name)) {
  24002. WARN(in_nmi(),
  24003. "Trying to free NMI (%s) from NMI context!\n", n->name);
  24004. - list_del_rcu(&n->list);
  24005. + pax_list_del_rcu((struct list_head *)&n->list);
  24006. break;
  24007. }
  24008. }
  24009. @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
  24010. dotraplinkage notrace __kprobes void
  24011. do_nmi(struct pt_regs *regs, long error_code)
  24012. {
  24013. +
  24014. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  24015. + if (!user_mode(regs)) {
  24016. + unsigned long cs = regs->cs & 0xFFFF;
  24017. + unsigned long ip = ktva_ktla(regs->ip);
  24018. +
  24019. + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
  24020. + regs->ip = ip;
  24021. + }
  24022. +#endif
  24023. +
  24024. nmi_nesting_preprocess(regs);
  24025. nmi_enter();
  24026. diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
  24027. index 6d9582e..f746287 100644
  24028. --- a/arch/x86/kernel/nmi_selftest.c
  24029. +++ b/arch/x86/kernel/nmi_selftest.c
  24030. @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
  24031. {
  24032. /* trap all the unknown NMIs we may generate */
  24033. register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
  24034. - __initdata);
  24035. + __initconst);
  24036. }
  24037. static void __init cleanup_nmi_testsuite(void)
  24038. @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
  24039. unsigned long timeout;
  24040. if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
  24041. - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
  24042. + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
  24043. nmi_fail = FAILURE;
  24044. return;
  24045. }
  24046. diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
  24047. index bbb6c73..24a58ef 100644
  24048. --- a/arch/x86/kernel/paravirt-spinlocks.c
  24049. +++ b/arch/x86/kernel/paravirt-spinlocks.c
  24050. @@ -8,7 +8,7 @@
  24051. #include <asm/paravirt.h>
  24052. -struct pv_lock_ops pv_lock_ops = {
  24053. +struct pv_lock_ops pv_lock_ops __read_only = {
  24054. #ifdef CONFIG_SMP
  24055. .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
  24056. .unlock_kick = paravirt_nop,
  24057. diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
  24058. index 1b10af8..45bfbec 100644
  24059. --- a/arch/x86/kernel/paravirt.c
  24060. +++ b/arch/x86/kernel/paravirt.c
  24061. @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
  24062. {
  24063. return x;
  24064. }
  24065. +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
  24066. +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
  24067. +#endif
  24068. void __init default_banner(void)
  24069. {
  24070. @@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
  24071. if (opfunc == NULL)
  24072. /* If there's no function, patch it with a ud2a (BUG) */
  24073. - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
  24074. - else if (opfunc == _paravirt_nop)
  24075. + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
  24076. + else if (opfunc == (void *)_paravirt_nop)
  24077. /* If the operation is a nop, then nop the callsite */
  24078. ret = paravirt_patch_nop();
  24079. /* identity functions just return their single argument */
  24080. - else if (opfunc == _paravirt_ident_32)
  24081. + else if (opfunc == (void *)_paravirt_ident_32)
  24082. ret = paravirt_patch_ident_32(insnbuf, len);
  24083. - else if (opfunc == _paravirt_ident_64)
  24084. + else if (opfunc == (void *)_paravirt_ident_64)
  24085. ret = paravirt_patch_ident_64(insnbuf, len);
  24086. +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
  24087. + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
  24088. + ret = paravirt_patch_ident_64(insnbuf, len);
  24089. +#endif
  24090. else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
  24091. type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
  24092. @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
  24093. if (insn_len > len || start == NULL)
  24094. insn_len = len;
  24095. else
  24096. - memcpy(insnbuf, start, insn_len);
  24097. + memcpy(insnbuf, ktla_ktva(start), insn_len);
  24098. return insn_len;
  24099. }
  24100. @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
  24101. return this_cpu_read(paravirt_lazy_mode);
  24102. }
  24103. -struct pv_info pv_info = {
  24104. +struct pv_info pv_info __read_only = {
  24105. .name = "bare hardware",
  24106. .paravirt_enabled = 0,
  24107. .kernel_rpl = 0,
  24108. @@ -310,16 +317,16 @@ struct pv_info pv_info = {
  24109. #endif
  24110. };
  24111. -struct pv_init_ops pv_init_ops = {
  24112. +struct pv_init_ops pv_init_ops __read_only = {
  24113. .patch = native_patch,
  24114. };
  24115. -struct pv_time_ops pv_time_ops = {
  24116. +struct pv_time_ops pv_time_ops __read_only = {
  24117. .sched_clock = native_sched_clock,
  24118. .steal_clock = native_steal_clock,
  24119. };
  24120. -__visible struct pv_irq_ops pv_irq_ops = {
  24121. +__visible struct pv_irq_ops pv_irq_ops __read_only = {
  24122. .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
  24123. .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
  24124. .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
  24125. @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
  24126. #endif
  24127. };
  24128. -__visible struct pv_cpu_ops pv_cpu_ops = {
  24129. +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
  24130. .cpuid = native_cpuid,
  24131. .get_debugreg = native_get_debugreg,
  24132. .set_debugreg = native_set_debugreg,
  24133. @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
  24134. .end_context_switch = paravirt_nop,
  24135. };
  24136. -struct pv_apic_ops pv_apic_ops = {
  24137. +struct pv_apic_ops pv_apic_ops __read_only= {
  24138. #ifdef CONFIG_X86_LOCAL_APIC
  24139. .startup_ipi_hook = paravirt_nop,
  24140. #endif
  24141. };
  24142. -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
  24143. +#ifdef CONFIG_X86_32
  24144. +#ifdef CONFIG_X86_PAE
  24145. +/* 64-bit pagetable entries */
  24146. +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
  24147. +#else
  24148. /* 32-bit pagetable entries */
  24149. #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
  24150. +#endif
  24151. #else
  24152. /* 64-bit pagetable entries */
  24153. #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
  24154. #endif
  24155. -struct pv_mmu_ops pv_mmu_ops = {
  24156. +struct pv_mmu_ops pv_mmu_ops __read_only = {
  24157. .read_cr2 = native_read_cr2,
  24158. .write_cr2 = native_write_cr2,
  24159. @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
  24160. .make_pud = PTE_IDENT,
  24161. .set_pgd = native_set_pgd,
  24162. + .set_pgd_batched = native_set_pgd_batched,
  24163. #endif
  24164. #endif /* PAGETABLE_LEVELS >= 3 */
  24165. @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
  24166. },
  24167. .set_fixmap = native_set_fixmap,
  24168. +
  24169. +#ifdef CONFIG_PAX_KERNEXEC
  24170. + .pax_open_kernel = native_pax_open_kernel,
  24171. + .pax_close_kernel = native_pax_close_kernel,
  24172. +#endif
  24173. +
  24174. };
  24175. EXPORT_SYMBOL_GPL(pv_time_ops);
  24176. diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
  24177. index 299d493..2ccb0ee 100644
  24178. --- a/arch/x86/kernel/pci-calgary_64.c
  24179. +++ b/arch/x86/kernel/pci-calgary_64.c
  24180. @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
  24181. tce_space = be64_to_cpu(readq(target));
  24182. tce_space = tce_space & TAR_SW_BITS;
  24183. - tce_space = tce_space & (~specified_table_size);
  24184. + tce_space = tce_space & (~(unsigned long)specified_table_size);
  24185. info->tce_space = (u64 *)__va(tce_space);
  24186. }
  24187. }
  24188. diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
  24189. index 35ccf75..7a15747 100644
  24190. --- a/arch/x86/kernel/pci-iommu_table.c
  24191. +++ b/arch/x86/kernel/pci-iommu_table.c
  24192. @@ -2,7 +2,7 @@
  24193. #include <asm/iommu_table.h>
  24194. #include <linux/string.h>
  24195. #include <linux/kallsyms.h>
  24196. -
  24197. +#include <linux/sched.h>
  24198. #define DEBUG 1
  24199. diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
  24200. index 6c483ba..d10ce2f 100644
  24201. --- a/arch/x86/kernel/pci-swiotlb.c
  24202. +++ b/arch/x86/kernel/pci-swiotlb.c
  24203. @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
  24204. void *vaddr, dma_addr_t dma_addr,
  24205. struct dma_attrs *attrs)
  24206. {
  24207. - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
  24208. + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
  24209. }
  24210. static struct dma_map_ops swiotlb_dma_ops = {
  24211. diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
  24212. index ca7f0d5..8996469 100644
  24213. --- a/arch/x86/kernel/preempt.S
  24214. +++ b/arch/x86/kernel/preempt.S
  24215. @@ -3,12 +3,14 @@
  24216. #include <asm/dwarf2.h>
  24217. #include <asm/asm.h>
  24218. #include <asm/calling.h>
  24219. +#include <asm/alternative-asm.h>
  24220. ENTRY(___preempt_schedule)
  24221. CFI_STARTPROC
  24222. SAVE_ALL
  24223. call preempt_schedule
  24224. RESTORE_ALL
  24225. + pax_force_retaddr
  24226. ret
  24227. CFI_ENDPROC
  24228. @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
  24229. SAVE_ALL
  24230. call preempt_schedule_context
  24231. RESTORE_ALL
  24232. + pax_force_retaddr
  24233. ret
  24234. CFI_ENDPROC
  24235. diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
  24236. index 3fb8d95..254dc51 100644
  24237. --- a/arch/x86/kernel/process.c
  24238. +++ b/arch/x86/kernel/process.c
  24239. @@ -36,7 +36,8 @@
  24240. * section. Since TSS's are completely CPU-local, we want them
  24241. * on exact cacheline boundaries, to eliminate cacheline ping-pong.
  24242. */
  24243. -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
  24244. +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
  24245. +EXPORT_SYMBOL(init_tss);
  24246. #ifdef CONFIG_X86_64
  24247. static DEFINE_PER_CPU(unsigned char, is_idle);
  24248. @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
  24249. task_xstate_cachep =
  24250. kmem_cache_create("task_xstate", xstate_size,
  24251. __alignof__(union thread_xstate),
  24252. - SLAB_PANIC | SLAB_NOTRACK, NULL);
  24253. + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
  24254. }
  24255. /*
  24256. @@ -105,7 +106,7 @@ void exit_thread(void)
  24257. unsigned long *bp = t->io_bitmap_ptr;
  24258. if (bp) {
  24259. - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
  24260. + struct tss_struct *tss = init_tss + get_cpu();
  24261. t->io_bitmap_ptr = NULL;
  24262. clear_thread_flag(TIF_IO_BITMAP);
  24263. @@ -125,6 +126,9 @@ void flush_thread(void)
  24264. {
  24265. struct task_struct *tsk = current;
  24266. +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
  24267. + loadsegment(gs, 0);
  24268. +#endif
  24269. flush_ptrace_hw_breakpoint(tsk);
  24270. memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
  24271. drop_init_fpu(tsk);
  24272. @@ -271,7 +275,7 @@ static void __exit_idle(void)
  24273. void exit_idle(void)
  24274. {
  24275. /* idle loop has pid 0 */
  24276. - if (current->pid)
  24277. + if (task_pid_nr(current))
  24278. return;
  24279. __exit_idle();
  24280. }
  24281. @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
  24282. return ret;
  24283. }
  24284. #endif
  24285. -void stop_this_cpu(void *dummy)
  24286. +__noreturn void stop_this_cpu(void *dummy)
  24287. {
  24288. local_irq_disable();
  24289. /*
  24290. @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
  24291. }
  24292. early_param("idle", idle_setup);
  24293. -unsigned long arch_align_stack(unsigned long sp)
  24294. +#ifdef CONFIG_PAX_RANDKSTACK
  24295. +void pax_randomize_kstack(struct pt_regs *regs)
  24296. {
  24297. - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  24298. - sp -= get_random_int() % 8192;
  24299. - return sp & ~0xf;
  24300. -}
  24301. + struct thread_struct *thread = &current->thread;
  24302. + unsigned long time;
  24303. -unsigned long arch_randomize_brk(struct mm_struct *mm)
  24304. -{
  24305. - unsigned long range_end = mm->brk + 0x02000000;
  24306. - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
  24307. -}
  24308. + if (!randomize_va_space)
  24309. + return;
  24310. +
  24311. + if (v8086_mode(regs))
  24312. + return;
  24313. + rdtscl(time);
  24314. +
  24315. + /* P4 seems to return a 0 LSB, ignore it */
  24316. +#ifdef CONFIG_MPENTIUM4
  24317. + time &= 0x3EUL;
  24318. + time <<= 2;
  24319. +#elif defined(CONFIG_X86_64)
  24320. + time &= 0xFUL;
  24321. + time <<= 4;
  24322. +#else
  24323. + time &= 0x1FUL;
  24324. + time <<= 3;
  24325. +#endif
  24326. +
  24327. + thread->sp0 ^= time;
  24328. + load_sp0(init_tss + smp_processor_id(), thread);
  24329. +
  24330. +#ifdef CONFIG_X86_64
  24331. + this_cpu_write(kernel_stack, thread->sp0);
  24332. +#endif
  24333. +}
  24334. +#endif
  24335. diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
  24336. index 0de43e9..056b840 100644
  24337. --- a/arch/x86/kernel/process_32.c
  24338. +++ b/arch/x86/kernel/process_32.c
  24339. @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
  24340. unsigned long thread_saved_pc(struct task_struct *tsk)
  24341. {
  24342. return ((unsigned long *)tsk->thread.sp)[3];
  24343. +//XXX return tsk->thread.eip;
  24344. }
  24345. void __show_regs(struct pt_regs *regs, int all)
  24346. @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
  24347. unsigned long sp;
  24348. unsigned short ss, gs;
  24349. - if (user_mode_vm(regs)) {
  24350. + if (user_mode(regs)) {
  24351. sp = regs->sp;
  24352. ss = regs->ss & 0xffff;
  24353. - gs = get_user_gs(regs);
  24354. } else {
  24355. sp = kernel_stack_pointer(regs);
  24356. savesegment(ss, ss);
  24357. - savesegment(gs, gs);
  24358. }
  24359. + gs = get_user_gs(regs);
  24360. printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
  24361. (u16)regs->cs, regs->ip, regs->flags,
  24362. - smp_processor_id());
  24363. + raw_smp_processor_id());
  24364. print_symbol("EIP is at %s\n", regs->ip);
  24365. printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
  24366. @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
  24367. int copy_thread(unsigned long clone_flags, unsigned long sp,
  24368. unsigned long arg, struct task_struct *p)
  24369. {
  24370. - struct pt_regs *childregs = task_pt_regs(p);
  24371. + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
  24372. struct task_struct *tsk;
  24373. int err;
  24374. p->thread.sp = (unsigned long) childregs;
  24375. p->thread.sp0 = (unsigned long) (childregs+1);
  24376. + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
  24377. if (unlikely(p->flags & PF_KTHREAD)) {
  24378. /* kernel thread */
  24379. memset(childregs, 0, sizeof(struct pt_regs));
  24380. p->thread.ip = (unsigned long) ret_from_kernel_thread;
  24381. - task_user_gs(p) = __KERNEL_STACK_CANARY;
  24382. - childregs->ds = __USER_DS;
  24383. - childregs->es = __USER_DS;
  24384. + savesegment(gs, childregs->gs);
  24385. + childregs->ds = __KERNEL_DS;
  24386. + childregs->es = __KERNEL_DS;
  24387. childregs->fs = __KERNEL_PERCPU;
  24388. childregs->bx = sp; /* function */
  24389. childregs->bp = arg;
  24390. @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24391. struct thread_struct *prev = &prev_p->thread,
  24392. *next = &next_p->thread;
  24393. int cpu = smp_processor_id();
  24394. - struct tss_struct *tss = &per_cpu(init_tss, cpu);
  24395. + struct tss_struct *tss = init_tss + cpu;
  24396. fpu_switch_t fpu;
  24397. /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
  24398. @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24399. */
  24400. lazy_save_gs(prev->gs);
  24401. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  24402. + __set_fs(task_thread_info(next_p)->addr_limit);
  24403. +#endif
  24404. +
  24405. /*
  24406. * Load the per-thread Thread-Local Storage descriptor.
  24407. */
  24408. @@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24409. */
  24410. arch_end_context_switch(next_p);
  24411. + this_cpu_write(current_task, next_p);
  24412. + this_cpu_write(current_tinfo, &next_p->tinfo);
  24413. +
  24414. /*
  24415. * Restore %gs if needed (which is common)
  24416. */
  24417. @@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24418. switch_fpu_finish(next_p, fpu);
  24419. - this_cpu_write(current_task, next_p);
  24420. -
  24421. return prev_p;
  24422. }
  24423. @@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
  24424. } while (count++ < 16);
  24425. return 0;
  24426. }
  24427. -
  24428. diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
  24429. index 9c0280f..5bbb1c0 100644
  24430. --- a/arch/x86/kernel/process_64.c
  24431. +++ b/arch/x86/kernel/process_64.c
  24432. @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
  24433. struct pt_regs *childregs;
  24434. struct task_struct *me = current;
  24435. - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  24436. + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
  24437. childregs = task_pt_regs(p);
  24438. p->thread.sp = (unsigned long) childregs;
  24439. p->thread.usersp = me->thread.usersp;
  24440. + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
  24441. set_tsk_thread_flag(p, TIF_FORK);
  24442. p->thread.fpu_counter = 0;
  24443. p->thread.io_bitmap_ptr = NULL;
  24444. @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
  24445. p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
  24446. savesegment(es, p->thread.es);
  24447. savesegment(ds, p->thread.ds);
  24448. + savesegment(ss, p->thread.ss);
  24449. + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
  24450. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  24451. if (unlikely(p->flags & PF_KTHREAD)) {
  24452. @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24453. struct thread_struct *prev = &prev_p->thread;
  24454. struct thread_struct *next = &next_p->thread;
  24455. int cpu = smp_processor_id();
  24456. - struct tss_struct *tss = &per_cpu(init_tss, cpu);
  24457. + struct tss_struct *tss = init_tss + cpu;
  24458. unsigned fsindex, gsindex;
  24459. fpu_switch_t fpu;
  24460. @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24461. if (unlikely(next->ds | prev->ds))
  24462. loadsegment(ds, next->ds);
  24463. + savesegment(ss, prev->ss);
  24464. + if (unlikely(next->ss != prev->ss))
  24465. + loadsegment(ss, next->ss);
  24466. /* We must save %fs and %gs before load_TLS() because
  24467. * %fs and %gs may be cleared by load_TLS().
  24468. @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24469. prev->usersp = this_cpu_read(old_rsp);
  24470. this_cpu_write(old_rsp, next->usersp);
  24471. this_cpu_write(current_task, next_p);
  24472. + this_cpu_write(current_tinfo, &next_p->tinfo);
  24473. /*
  24474. * If it were not for PREEMPT_ACTIVE we could guarantee that the
  24475. @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  24476. task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
  24477. this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
  24478. - this_cpu_write(kernel_stack,
  24479. - (unsigned long)task_stack_page(next_p) +
  24480. - THREAD_SIZE - KERNEL_STACK_OFFSET);
  24481. + this_cpu_write(kernel_stack, next->sp0);
  24482. /*
  24483. * Now maybe reload the debug registers and handle I/O bitmaps
  24484. @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
  24485. if (!p || p == current || p->state == TASK_RUNNING)
  24486. return 0;
  24487. stack = (unsigned long)task_stack_page(p);
  24488. - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
  24489. + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
  24490. return 0;
  24491. fp = *(u64 *)(p->thread.sp);
  24492. do {
  24493. - if (fp < (unsigned long)stack ||
  24494. - fp >= (unsigned long)stack+THREAD_SIZE)
  24495. + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
  24496. return 0;
  24497. ip = *(u64 *)(fp+8);
  24498. if (!in_sched_functions(ip))
  24499. diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
  24500. index 7461f50..1334029 100644
  24501. --- a/arch/x86/kernel/ptrace.c
  24502. +++ b/arch/x86/kernel/ptrace.c
  24503. @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
  24504. {
  24505. unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
  24506. unsigned long sp = (unsigned long)&regs->sp;
  24507. - struct thread_info *tinfo;
  24508. - if (context == (sp & ~(THREAD_SIZE - 1)))
  24509. + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
  24510. return sp;
  24511. - tinfo = (struct thread_info *)context;
  24512. - if (tinfo->previous_esp)
  24513. - return tinfo->previous_esp;
  24514. + sp = *(unsigned long *)context;
  24515. + if (sp)
  24516. + return sp;
  24517. return (unsigned long)regs;
  24518. }
  24519. @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
  24520. static unsigned long ptrace_get_dr7(struct perf_event *bp[])
  24521. {
  24522. int i;
  24523. - int dr7 = 0;
  24524. + unsigned long dr7 = 0;
  24525. struct arch_hw_breakpoint *info;
  24526. for (i = 0; i < HBP_NUM; i++) {
  24527. @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
  24528. unsigned long addr, unsigned long data)
  24529. {
  24530. int ret;
  24531. - unsigned long __user *datap = (unsigned long __user *)data;
  24532. + unsigned long __user *datap = (__force unsigned long __user *)data;
  24533. switch (request) {
  24534. /* read the word at location addr in the USER area. */
  24535. @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
  24536. if ((int) addr < 0)
  24537. return -EIO;
  24538. ret = do_get_thread_area(child, addr,
  24539. - (struct user_desc __user *)data);
  24540. + (__force struct user_desc __user *) data);
  24541. break;
  24542. case PTRACE_SET_THREAD_AREA:
  24543. if ((int) addr < 0)
  24544. return -EIO;
  24545. ret = do_set_thread_area(child, addr,
  24546. - (struct user_desc __user *)data, 0);
  24547. + (__force struct user_desc __user *) data, 0);
  24548. break;
  24549. #endif
  24550. @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  24551. #ifdef CONFIG_X86_64
  24552. -static struct user_regset x86_64_regsets[] __read_mostly = {
  24553. +static user_regset_no_const x86_64_regsets[] __read_only = {
  24554. [REGSET_GENERAL] = {
  24555. .core_note_type = NT_PRSTATUS,
  24556. .n = sizeof(struct user_regs_struct) / sizeof(long),
  24557. @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
  24558. #endif /* CONFIG_X86_64 */
  24559. #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
  24560. -static struct user_regset x86_32_regsets[] __read_mostly = {
  24561. +static user_regset_no_const x86_32_regsets[] __read_only = {
  24562. [REGSET_GENERAL] = {
  24563. .core_note_type = NT_PRSTATUS,
  24564. .n = sizeof(struct user_regs_struct32) / sizeof(u32),
  24565. @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
  24566. */
  24567. u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
  24568. -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
  24569. +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
  24570. {
  24571. #ifdef CONFIG_X86_64
  24572. x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
  24573. @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
  24574. memset(info, 0, sizeof(*info));
  24575. info->si_signo = SIGTRAP;
  24576. info->si_code = si_code;
  24577. - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
  24578. + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
  24579. }
  24580. void user_single_step_siginfo(struct task_struct *tsk,
  24581. @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
  24582. # define IS_IA32 0
  24583. #endif
  24584. +#ifdef CONFIG_GRKERNSEC_SETXID
  24585. +extern void gr_delayed_cred_worker(void);
  24586. +#endif
  24587. +
  24588. /*
  24589. * We must return the syscall number to actually look up in the table.
  24590. * This can be -1L to skip running any syscall at all.
  24591. @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
  24592. user_exit();
  24593. +#ifdef CONFIG_GRKERNSEC_SETXID
  24594. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  24595. + gr_delayed_cred_worker();
  24596. +#endif
  24597. +
  24598. /*
  24599. * If we stepped into a sysenter/syscall insn, it trapped in
  24600. * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
  24601. @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
  24602. */
  24603. user_exit();
  24604. +#ifdef CONFIG_GRKERNSEC_SETXID
  24605. + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
  24606. + gr_delayed_cred_worker();
  24607. +#endif
  24608. +
  24609. audit_syscall_exit(regs);
  24610. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  24611. diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
  24612. index 2f355d2..e75ed0a 100644
  24613. --- a/arch/x86/kernel/pvclock.c
  24614. +++ b/arch/x86/kernel/pvclock.c
  24615. @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
  24616. reset_hung_task_detector();
  24617. }
  24618. -static atomic64_t last_value = ATOMIC64_INIT(0);
  24619. +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
  24620. void pvclock_resume(void)
  24621. {
  24622. - atomic64_set(&last_value, 0);
  24623. + atomic64_set_unchecked(&last_value, 0);
  24624. }
  24625. u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
  24626. @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
  24627. * updating at the same time, and one of them could be slightly behind,
  24628. * making the assumption that last_value always go forward fail to hold.
  24629. */
  24630. - last = atomic64_read(&last_value);
  24631. + last = atomic64_read_unchecked(&last_value);
  24632. do {
  24633. if (ret < last)
  24634. return last;
  24635. - last = atomic64_cmpxchg(&last_value, last, ret);
  24636. + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
  24637. } while (unlikely(last != ret));
  24638. return ret;
  24639. diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
  24640. index c752cb4..866c432 100644
  24641. --- a/arch/x86/kernel/reboot.c
  24642. +++ b/arch/x86/kernel/reboot.c
  24643. @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
  24644. void __noreturn machine_real_restart(unsigned int type)
  24645. {
  24646. +
  24647. +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
  24648. + struct desc_struct *gdt;
  24649. +#endif
  24650. +
  24651. local_irq_disable();
  24652. /*
  24653. @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
  24654. /* Jump to the identity-mapped low memory code */
  24655. #ifdef CONFIG_X86_32
  24656. - asm volatile("jmpl *%0" : :
  24657. +
  24658. +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
  24659. + gdt = get_cpu_gdt_table(smp_processor_id());
  24660. + pax_open_kernel();
  24661. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  24662. + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
  24663. + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
  24664. + loadsegment(ds, __KERNEL_DS);
  24665. + loadsegment(es, __KERNEL_DS);
  24666. + loadsegment(ss, __KERNEL_DS);
  24667. +#endif
  24668. +#ifdef CONFIG_PAX_KERNEXEC
  24669. + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
  24670. + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
  24671. + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
  24672. + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
  24673. + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
  24674. + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
  24675. +#endif
  24676. + pax_close_kernel();
  24677. +#endif
  24678. +
  24679. + asm volatile("ljmpl *%0" : :
  24680. "rm" (real_mode_header->machine_real_restart_asm),
  24681. "a" (type));
  24682. #else
  24683. @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
  24684. * try to force a triple fault and then cycle between hitting the keyboard
  24685. * controller and doing that
  24686. */
  24687. -static void native_machine_emergency_restart(void)
  24688. +static void __noreturn native_machine_emergency_restart(void)
  24689. {
  24690. int i;
  24691. int attempt = 0;
  24692. @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
  24693. #endif
  24694. }
  24695. -static void __machine_emergency_restart(int emergency)
  24696. +static void __noreturn __machine_emergency_restart(int emergency)
  24697. {
  24698. reboot_emergency = emergency;
  24699. machine_ops.emergency_restart();
  24700. }
  24701. -static void native_machine_restart(char *__unused)
  24702. +static void __noreturn native_machine_restart(char *__unused)
  24703. {
  24704. pr_notice("machine restart\n");
  24705. @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
  24706. __machine_emergency_restart(0);
  24707. }
  24708. -static void native_machine_halt(void)
  24709. +static void __noreturn native_machine_halt(void)
  24710. {
  24711. /* Stop other cpus and apics */
  24712. machine_shutdown();
  24713. @@ -618,7 +645,7 @@ static void native_machine_halt(void)
  24714. stop_this_cpu(NULL);
  24715. }
  24716. -static void native_machine_power_off(void)
  24717. +static void __noreturn native_machine_power_off(void)
  24718. {
  24719. if (pm_power_off) {
  24720. if (!reboot_force)
  24721. @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
  24722. }
  24723. /* A fallback in case there is no PM info available */
  24724. tboot_shutdown(TB_SHUTDOWN_HALT);
  24725. + unreachable();
  24726. }
  24727. -struct machine_ops machine_ops = {
  24728. +struct machine_ops machine_ops __read_only = {
  24729. .power_off = native_machine_power_off,
  24730. .shutdown = native_machine_shutdown,
  24731. .emergency_restart = native_machine_emergency_restart,
  24732. diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
  24733. index c8e41e9..64049ef 100644
  24734. --- a/arch/x86/kernel/reboot_fixups_32.c
  24735. +++ b/arch/x86/kernel/reboot_fixups_32.c
  24736. @@ -57,7 +57,7 @@ struct device_fixup {
  24737. unsigned int vendor;
  24738. unsigned int device;
  24739. void (*reboot_fixup)(struct pci_dev *);
  24740. -};
  24741. +} __do_const;
  24742. /*
  24743. * PCI ids solely used for fixups_table go here
  24744. diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
  24745. index 3fd2c69..a444264 100644
  24746. --- a/arch/x86/kernel/relocate_kernel_64.S
  24747. +++ b/arch/x86/kernel/relocate_kernel_64.S
  24748. @@ -96,8 +96,7 @@ relocate_kernel:
  24749. /* jump to identity mapped page */
  24750. addq $(identity_mapped - relocate_kernel), %r8
  24751. - pushq %r8
  24752. - ret
  24753. + jmp *%r8
  24754. identity_mapped:
  24755. /* set return address to 0 if not preserving context */
  24756. diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
  24757. index ce72964..be8aea7 100644
  24758. --- a/arch/x86/kernel/setup.c
  24759. +++ b/arch/x86/kernel/setup.c
  24760. @@ -110,6 +110,7 @@
  24761. #include <asm/mce.h>
  24762. #include <asm/alternative.h>
  24763. #include <asm/prom.h>
  24764. +#include <asm/boot.h>
  24765. /*
  24766. * max_low_pfn_mapped: highest direct mapped pfn under 4GB
  24767. @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
  24768. #endif
  24769. -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
  24770. -__visible unsigned long mmu_cr4_features;
  24771. +#ifdef CONFIG_X86_64
  24772. +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
  24773. +#elif defined(CONFIG_X86_PAE)
  24774. +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
  24775. #else
  24776. -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
  24777. +__visible unsigned long mmu_cr4_features __read_only;
  24778. #endif
  24779. +void set_in_cr4(unsigned long mask)
  24780. +{
  24781. + unsigned long cr4 = read_cr4();
  24782. +
  24783. + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
  24784. + return;
  24785. +
  24786. + pax_open_kernel();
  24787. + mmu_cr4_features |= mask;
  24788. + pax_close_kernel();
  24789. +
  24790. + if (trampoline_cr4_features)
  24791. + *trampoline_cr4_features = mmu_cr4_features;
  24792. + cr4 |= mask;
  24793. + write_cr4(cr4);
  24794. +}
  24795. +EXPORT_SYMBOL(set_in_cr4);
  24796. +
  24797. +void clear_in_cr4(unsigned long mask)
  24798. +{
  24799. + unsigned long cr4 = read_cr4();
  24800. +
  24801. + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
  24802. + return;
  24803. +
  24804. + pax_open_kernel();
  24805. + mmu_cr4_features &= ~mask;
  24806. + pax_close_kernel();
  24807. +
  24808. + if (trampoline_cr4_features)
  24809. + *trampoline_cr4_features = mmu_cr4_features;
  24810. + cr4 &= ~mask;
  24811. + write_cr4(cr4);
  24812. +}
  24813. +EXPORT_SYMBOL(clear_in_cr4);
  24814. +
  24815. /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
  24816. int bootloader_type, bootloader_version;
  24817. @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
  24818. * area (640->1Mb) as ram even though it is not.
  24819. * take them out.
  24820. */
  24821. - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
  24822. + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
  24823. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  24824. }
  24825. @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
  24826. /* called before trim_bios_range() to spare extra sanitize */
  24827. static void __init e820_add_kernel_range(void)
  24828. {
  24829. - u64 start = __pa_symbol(_text);
  24830. + u64 start = __pa_symbol(ktla_ktva(_text));
  24831. u64 size = __pa_symbol(_end) - start;
  24832. /*
  24833. @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
  24834. void __init setup_arch(char **cmdline_p)
  24835. {
  24836. +#ifdef CONFIG_X86_32
  24837. + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
  24838. +#else
  24839. memblock_reserve(__pa_symbol(_text),
  24840. (unsigned long)__bss_stop - (unsigned long)_text);
  24841. +#endif
  24842. early_reserve_initrd();
  24843. @@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
  24844. if (!boot_params.hdr.root_flags)
  24845. root_mountflags &= ~MS_RDONLY;
  24846. - init_mm.start_code = (unsigned long) _text;
  24847. - init_mm.end_code = (unsigned long) _etext;
  24848. + init_mm.start_code = ktla_ktva((unsigned long) _text);
  24849. + init_mm.end_code = ktla_ktva((unsigned long) _etext);
  24850. init_mm.end_data = (unsigned long) _edata;
  24851. init_mm.brk = _brk_end;
  24852. - code_resource.start = __pa_symbol(_text);
  24853. - code_resource.end = __pa_symbol(_etext)-1;
  24854. - data_resource.start = __pa_symbol(_etext);
  24855. + code_resource.start = __pa_symbol(ktla_ktva(_text));
  24856. + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
  24857. + data_resource.start = __pa_symbol(_sdata);
  24858. data_resource.end = __pa_symbol(_edata)-1;
  24859. bss_resource.start = __pa_symbol(__bss_start);
  24860. bss_resource.end = __pa_symbol(__bss_stop)-1;
  24861. diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
  24862. index 5cdff03..80fa283 100644
  24863. --- a/arch/x86/kernel/setup_percpu.c
  24864. +++ b/arch/x86/kernel/setup_percpu.c
  24865. @@ -21,19 +21,17 @@
  24866. #include <asm/cpu.h>
  24867. #include <asm/stackprotector.h>
  24868. -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
  24869. +#ifdef CONFIG_SMP
  24870. +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
  24871. EXPORT_PER_CPU_SYMBOL(cpu_number);
  24872. +#endif
  24873. -#ifdef CONFIG_X86_64
  24874. #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
  24875. -#else
  24876. -#define BOOT_PERCPU_OFFSET 0
  24877. -#endif
  24878. DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
  24879. EXPORT_PER_CPU_SYMBOL(this_cpu_off);
  24880. -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
  24881. +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
  24882. [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
  24883. };
  24884. EXPORT_SYMBOL(__per_cpu_offset);
  24885. @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
  24886. {
  24887. #ifdef CONFIG_NEED_MULTIPLE_NODES
  24888. pg_data_t *last = NULL;
  24889. - unsigned int cpu;
  24890. + int cpu;
  24891. for_each_possible_cpu(cpu) {
  24892. int node = early_cpu_to_node(cpu);
  24893. @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
  24894. {
  24895. #ifdef CONFIG_X86_32
  24896. struct desc_struct gdt;
  24897. + unsigned long base = per_cpu_offset(cpu);
  24898. - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
  24899. - 0x2 | DESCTYPE_S, 0x8);
  24900. - gdt.s = 1;
  24901. + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
  24902. + 0x83 | DESCTYPE_S, 0xC);
  24903. write_gdt_entry(get_cpu_gdt_table(cpu),
  24904. GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
  24905. #endif
  24906. @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
  24907. /* alrighty, percpu areas up and running */
  24908. delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
  24909. for_each_possible_cpu(cpu) {
  24910. +#ifdef CONFIG_CC_STACKPROTECTOR
  24911. +#ifdef CONFIG_X86_32
  24912. + unsigned long canary = per_cpu(stack_canary.canary, cpu);
  24913. +#endif
  24914. +#endif
  24915. per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
  24916. per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
  24917. per_cpu(cpu_number, cpu) = cpu;
  24918. @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
  24919. */
  24920. set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
  24921. #endif
  24922. +#ifdef CONFIG_CC_STACKPROTECTOR
  24923. +#ifdef CONFIG_X86_32
  24924. + if (!cpu)
  24925. + per_cpu(stack_canary.canary, cpu) = canary;
  24926. +#endif
  24927. +#endif
  24928. /*
  24929. * Up to this point, the boot CPU has been using .init.data
  24930. * area. Reload any changed state for the boot CPU.
  24931. diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
  24932. index 9e5de68..16c53cb 100644
  24933. --- a/arch/x86/kernel/signal.c
  24934. +++ b/arch/x86/kernel/signal.c
  24935. @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
  24936. * Align the stack pointer according to the i386 ABI,
  24937. * i.e. so that on function entry ((sp + 4) & 15) == 0.
  24938. */
  24939. - sp = ((sp + 4) & -16ul) - 4;
  24940. + sp = ((sp - 12) & -16ul) - 4;
  24941. #else /* !CONFIG_X86_32 */
  24942. sp = round_down(sp, 16) - 8;
  24943. #endif
  24944. @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
  24945. }
  24946. if (current->mm->context.vdso)
  24947. - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
  24948. + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
  24949. else
  24950. - restorer = &frame->retcode;
  24951. + restorer = (void __user *)&frame->retcode;
  24952. if (ksig->ka.sa.sa_flags & SA_RESTORER)
  24953. restorer = ksig->ka.sa.sa_restorer;
  24954. @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
  24955. * reasons and because gdb uses it as a signature to notice
  24956. * signal handler stack frames.
  24957. */
  24958. - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
  24959. + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
  24960. if (err)
  24961. return -EFAULT;
  24962. @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
  24963. save_altstack_ex(&frame->uc.uc_stack, regs->sp);
  24964. /* Set up to return from userspace. */
  24965. - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
  24966. + if (current->mm->context.vdso)
  24967. + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
  24968. + else
  24969. + restorer = (void __user *)&frame->retcode;
  24970. if (ksig->ka.sa.sa_flags & SA_RESTORER)
  24971. restorer = ksig->ka.sa.sa_restorer;
  24972. put_user_ex(restorer, &frame->pretcode);
  24973. @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
  24974. * reasons and because gdb uses it as a signature to notice
  24975. * signal handler stack frames.
  24976. */
  24977. - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
  24978. + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
  24979. } put_user_catch(err);
  24980. err |= copy_siginfo_to_user(&frame->info, &ksig->info);
  24981. @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
  24982. {
  24983. int usig = signr_convert(ksig->sig);
  24984. sigset_t *set = sigmask_to_save();
  24985. - compat_sigset_t *cset = (compat_sigset_t *) set;
  24986. + sigset_t sigcopy;
  24987. + compat_sigset_t *cset;
  24988. +
  24989. + sigcopy = *set;
  24990. +
  24991. + cset = (compat_sigset_t *) &sigcopy;
  24992. /* Set up the stack frame */
  24993. if (is_ia32_frame()) {
  24994. @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
  24995. } else if (is_x32_frame()) {
  24996. return x32_setup_rt_frame(ksig, cset, regs);
  24997. } else {
  24998. - return __setup_rt_frame(ksig->sig, ksig, set, regs);
  24999. + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
  25000. }
  25001. }
  25002. diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
  25003. index 7c3a5a6..f0a8961 100644
  25004. --- a/arch/x86/kernel/smp.c
  25005. +++ b/arch/x86/kernel/smp.c
  25006. @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
  25007. __setup("nonmi_ipi", nonmi_ipi_setup);
  25008. -struct smp_ops smp_ops = {
  25009. +struct smp_ops smp_ops __read_only = {
  25010. .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
  25011. .smp_prepare_cpus = native_smp_prepare_cpus,
  25012. .smp_cpus_done = native_smp_cpus_done,
  25013. diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
  25014. index a32da80..30c97f1 100644
  25015. --- a/arch/x86/kernel/smpboot.c
  25016. +++ b/arch/x86/kernel/smpboot.c
  25017. @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
  25018. enable_start_cpu0 = 0;
  25019. -#ifdef CONFIG_X86_32
  25020. - /* switch away from the initial page table */
  25021. - load_cr3(swapper_pg_dir);
  25022. - __flush_tlb_all();
  25023. -#endif
  25024. -
  25025. /* otherwise gcc will move up smp_processor_id before the cpu_init */
  25026. barrier();
  25027. +
  25028. + /* switch away from the initial page table */
  25029. +#ifdef CONFIG_PAX_PER_CPU_PGD
  25030. + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
  25031. + __flush_tlb_all();
  25032. +#elif defined(CONFIG_X86_32)
  25033. + load_cr3(swapper_pg_dir);
  25034. + __flush_tlb_all();
  25035. +#endif
  25036. +
  25037. /*
  25038. * Check TSC synchronization with the BP:
  25039. */
  25040. @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
  25041. alternatives_enable_smp();
  25042. idle->thread.sp = (unsigned long) (((struct pt_regs *)
  25043. - (THREAD_SIZE + task_stack_page(idle))) - 1);
  25044. + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
  25045. per_cpu(current_task, cpu) = idle;
  25046. + per_cpu(current_tinfo, cpu) = &idle->tinfo;
  25047. #ifdef CONFIG_X86_32
  25048. /* Stack for startup_32 can be just as for start_secondary onwards */
  25049. @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
  25050. #else
  25051. clear_tsk_thread_flag(idle, TIF_FORK);
  25052. initial_gs = per_cpu_offset(cpu);
  25053. - per_cpu(kernel_stack, cpu) =
  25054. - (unsigned long)task_stack_page(idle) -
  25055. - KERNEL_STACK_OFFSET + THREAD_SIZE;
  25056. + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
  25057. #endif
  25058. +
  25059. + pax_open_kernel();
  25060. early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
  25061. + pax_close_kernel();
  25062. +
  25063. initial_code = (unsigned long)start_secondary;
  25064. stack_start = idle->thread.sp;
  25065. @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
  25066. /* the FPU context is blank, nobody can own it */
  25067. __cpu_disable_lazy_restore(cpu);
  25068. +#ifdef CONFIG_PAX_PER_CPU_PGD
  25069. + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
  25070. + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  25071. + KERNEL_PGD_PTRS);
  25072. + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
  25073. + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  25074. + KERNEL_PGD_PTRS);
  25075. +#endif
  25076. +
  25077. err = do_boot_cpu(apicid, cpu, tidle);
  25078. if (err) {
  25079. pr_debug("do_boot_cpu failed %d\n", err);
  25080. diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
  25081. index 9b4d51d..5d28b58 100644
  25082. --- a/arch/x86/kernel/step.c
  25083. +++ b/arch/x86/kernel/step.c
  25084. @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
  25085. struct desc_struct *desc;
  25086. unsigned long base;
  25087. - seg &= ~7UL;
  25088. + seg >>= 3;
  25089. mutex_lock(&child->mm->context.lock);
  25090. - if (unlikely((seg >> 3) >= child->mm->context.size))
  25091. + if (unlikely(seg >= child->mm->context.size))
  25092. addr = -1L; /* bogus selector, access would fault */
  25093. else {
  25094. desc = child->mm->context.ldt + seg;
  25095. @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
  25096. addr += base;
  25097. }
  25098. mutex_unlock(&child->mm->context.lock);
  25099. - }
  25100. + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
  25101. + addr = ktla_ktva(addr);
  25102. return addr;
  25103. }
  25104. @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
  25105. unsigned char opcode[15];
  25106. unsigned long addr = convert_ip_to_linear(child, regs);
  25107. + if (addr == -EINVAL)
  25108. + return 0;
  25109. +
  25110. copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
  25111. for (i = 0; i < copied; i++) {
  25112. switch (opcode[i]) {
  25113. diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
  25114. new file mode 100644
  25115. index 0000000..5877189
  25116. --- /dev/null
  25117. +++ b/arch/x86/kernel/sys_i386_32.c
  25118. @@ -0,0 +1,189 @@
  25119. +/*
  25120. + * This file contains various random system calls that
  25121. + * have a non-standard calling sequence on the Linux/i386
  25122. + * platform.
  25123. + */
  25124. +
  25125. +#include <linux/errno.h>
  25126. +#include <linux/sched.h>
  25127. +#include <linux/mm.h>
  25128. +#include <linux/fs.h>
  25129. +#include <linux/smp.h>
  25130. +#include <linux/sem.h>
  25131. +#include <linux/msg.h>
  25132. +#include <linux/shm.h>
  25133. +#include <linux/stat.h>
  25134. +#include <linux/syscalls.h>
  25135. +#include <linux/mman.h>
  25136. +#include <linux/file.h>
  25137. +#include <linux/utsname.h>
  25138. +#include <linux/ipc.h>
  25139. +#include <linux/elf.h>
  25140. +
  25141. +#include <linux/uaccess.h>
  25142. +#include <linux/unistd.h>
  25143. +
  25144. +#include <asm/syscalls.h>
  25145. +
  25146. +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
  25147. +{
  25148. + unsigned long pax_task_size = TASK_SIZE;
  25149. +
  25150. +#ifdef CONFIG_PAX_SEGMEXEC
  25151. + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
  25152. + pax_task_size = SEGMEXEC_TASK_SIZE;
  25153. +#endif
  25154. +
  25155. + if (flags & MAP_FIXED)
  25156. + if (len > pax_task_size || addr > pax_task_size - len)
  25157. + return -EINVAL;
  25158. +
  25159. + return 0;
  25160. +}
  25161. +
  25162. +/*
  25163. + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
  25164. + */
  25165. +static unsigned long get_align_mask(void)
  25166. +{
  25167. + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
  25168. + return 0;
  25169. +
  25170. + if (!(current->flags & PF_RANDOMIZE))
  25171. + return 0;
  25172. +
  25173. + return va_align.mask;
  25174. +}
  25175. +
  25176. +unsigned long
  25177. +arch_get_unmapped_area(struct file *filp, unsigned long addr,
  25178. + unsigned long len, unsigned long pgoff, unsigned long flags)
  25179. +{
  25180. + struct mm_struct *mm = current->mm;
  25181. + struct vm_area_struct *vma;
  25182. + unsigned long pax_task_size = TASK_SIZE;
  25183. + struct vm_unmapped_area_info info;
  25184. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  25185. +
  25186. +#ifdef CONFIG_PAX_SEGMEXEC
  25187. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  25188. + pax_task_size = SEGMEXEC_TASK_SIZE;
  25189. +#endif
  25190. +
  25191. + pax_task_size -= PAGE_SIZE;
  25192. +
  25193. + if (len > pax_task_size)
  25194. + return -ENOMEM;
  25195. +
  25196. + if (flags & MAP_FIXED)
  25197. + return addr;
  25198. +
  25199. +#ifdef CONFIG_PAX_RANDMMAP
  25200. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  25201. +#endif
  25202. +
  25203. + if (addr) {
  25204. + addr = PAGE_ALIGN(addr);
  25205. + if (pax_task_size - len >= addr) {
  25206. + vma = find_vma(mm, addr);
  25207. + if (check_heap_stack_gap(vma, addr, len, offset))
  25208. + return addr;
  25209. + }
  25210. + }
  25211. +
  25212. + info.flags = 0;
  25213. + info.length = len;
  25214. + info.align_mask = filp ? get_align_mask() : 0;
  25215. + info.align_offset = pgoff << PAGE_SHIFT;
  25216. + info.threadstack_offset = offset;
  25217. +
  25218. +#ifdef CONFIG_PAX_PAGEEXEC
  25219. + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
  25220. + info.low_limit = 0x00110000UL;
  25221. + info.high_limit = mm->start_code;
  25222. +
  25223. +#ifdef CONFIG_PAX_RANDMMAP
  25224. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  25225. + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
  25226. +#endif
  25227. +
  25228. + if (info.low_limit < info.high_limit) {
  25229. + addr = vm_unmapped_area(&info);
  25230. + if (!IS_ERR_VALUE(addr))
  25231. + return addr;
  25232. + }
  25233. + } else
  25234. +#endif
  25235. +
  25236. + info.low_limit = mm->mmap_base;
  25237. + info.high_limit = pax_task_size;
  25238. +
  25239. + return vm_unmapped_area(&info);
  25240. +}
  25241. +
  25242. +unsigned long
  25243. +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  25244. + const unsigned long len, const unsigned long pgoff,
  25245. + const unsigned long flags)
  25246. +{
  25247. + struct vm_area_struct *vma;
  25248. + struct mm_struct *mm = current->mm;
  25249. + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
  25250. + struct vm_unmapped_area_info info;
  25251. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  25252. +
  25253. +#ifdef CONFIG_PAX_SEGMEXEC
  25254. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  25255. + pax_task_size = SEGMEXEC_TASK_SIZE;
  25256. +#endif
  25257. +
  25258. + pax_task_size -= PAGE_SIZE;
  25259. +
  25260. + /* requested length too big for entire address space */
  25261. + if (len > pax_task_size)
  25262. + return -ENOMEM;
  25263. +
  25264. + if (flags & MAP_FIXED)
  25265. + return addr;
  25266. +
  25267. +#ifdef CONFIG_PAX_PAGEEXEC
  25268. + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
  25269. + goto bottomup;
  25270. +#endif
  25271. +
  25272. +#ifdef CONFIG_PAX_RANDMMAP
  25273. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  25274. +#endif
  25275. +
  25276. + /* requesting a specific address */
  25277. + if (addr) {
  25278. + addr = PAGE_ALIGN(addr);
  25279. + if (pax_task_size - len >= addr) {
  25280. + vma = find_vma(mm, addr);
  25281. + if (check_heap_stack_gap(vma, addr, len, offset))
  25282. + return addr;
  25283. + }
  25284. + }
  25285. +
  25286. + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
  25287. + info.length = len;
  25288. + info.low_limit = PAGE_SIZE;
  25289. + info.high_limit = mm->mmap_base;
  25290. + info.align_mask = filp ? get_align_mask() : 0;
  25291. + info.align_offset = pgoff << PAGE_SHIFT;
  25292. + info.threadstack_offset = offset;
  25293. +
  25294. + addr = vm_unmapped_area(&info);
  25295. + if (!(addr & ~PAGE_MASK))
  25296. + return addr;
  25297. + VM_BUG_ON(addr != -ENOMEM);
  25298. +
  25299. +bottomup:
  25300. + /*
  25301. + * A failed mmap() very likely causes application failure,
  25302. + * so fall back to the bottom-up function here. This scenario
  25303. + * can happen with large stack limits and large mmap()
  25304. + * allocations.
  25305. + */
  25306. + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
  25307. +}
  25308. diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
  25309. index 30277e2..5664a29 100644
  25310. --- a/arch/x86/kernel/sys_x86_64.c
  25311. +++ b/arch/x86/kernel/sys_x86_64.c
  25312. @@ -81,8 +81,8 @@ out:
  25313. return error;
  25314. }
  25315. -static void find_start_end(unsigned long flags, unsigned long *begin,
  25316. - unsigned long *end)
  25317. +static void find_start_end(struct mm_struct *mm, unsigned long flags,
  25318. + unsigned long *begin, unsigned long *end)
  25319. {
  25320. if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
  25321. unsigned long new_begin;
  25322. @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
  25323. *begin = new_begin;
  25324. }
  25325. } else {
  25326. - *begin = current->mm->mmap_legacy_base;
  25327. + *begin = mm->mmap_legacy_base;
  25328. *end = TASK_SIZE;
  25329. }
  25330. }
  25331. @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  25332. struct vm_area_struct *vma;
  25333. struct vm_unmapped_area_info info;
  25334. unsigned long begin, end;
  25335. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  25336. if (flags & MAP_FIXED)
  25337. return addr;
  25338. - find_start_end(flags, &begin, &end);
  25339. + find_start_end(mm, flags, &begin, &end);
  25340. if (len > end)
  25341. return -ENOMEM;
  25342. +#ifdef CONFIG_PAX_RANDMMAP
  25343. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  25344. +#endif
  25345. +
  25346. if (addr) {
  25347. addr = PAGE_ALIGN(addr);
  25348. vma = find_vma(mm, addr);
  25349. - if (end - len >= addr &&
  25350. - (!vma || addr + len <= vma->vm_start))
  25351. + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  25352. return addr;
  25353. }
  25354. @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  25355. info.high_limit = end;
  25356. info.align_mask = filp ? get_align_mask() : 0;
  25357. info.align_offset = pgoff << PAGE_SHIFT;
  25358. + info.threadstack_offset = offset;
  25359. return vm_unmapped_area(&info);
  25360. }
  25361. @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  25362. struct mm_struct *mm = current->mm;
  25363. unsigned long addr = addr0;
  25364. struct vm_unmapped_area_info info;
  25365. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  25366. /* requested length too big for entire address space */
  25367. if (len > TASK_SIZE)
  25368. @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  25369. if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
  25370. goto bottomup;
  25371. +#ifdef CONFIG_PAX_RANDMMAP
  25372. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  25373. +#endif
  25374. +
  25375. /* requesting a specific address */
  25376. if (addr) {
  25377. addr = PAGE_ALIGN(addr);
  25378. vma = find_vma(mm, addr);
  25379. - if (TASK_SIZE - len >= addr &&
  25380. - (!vma || addr + len <= vma->vm_start))
  25381. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  25382. return addr;
  25383. }
  25384. @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  25385. info.high_limit = mm->mmap_base;
  25386. info.align_mask = filp ? get_align_mask() : 0;
  25387. info.align_offset = pgoff << PAGE_SHIFT;
  25388. + info.threadstack_offset = offset;
  25389. addr = vm_unmapped_area(&info);
  25390. if (!(addr & ~PAGE_MASK))
  25391. return addr;
  25392. diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
  25393. index 91a4496..bb87552 100644
  25394. --- a/arch/x86/kernel/tboot.c
  25395. +++ b/arch/x86/kernel/tboot.c
  25396. @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
  25397. void tboot_shutdown(u32 shutdown_type)
  25398. {
  25399. - void (*shutdown)(void);
  25400. + void (* __noreturn shutdown)(void);
  25401. if (!tboot_enabled())
  25402. return;
  25403. @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
  25404. switch_to_tboot_pt();
  25405. - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
  25406. + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
  25407. shutdown();
  25408. /* should not reach here */
  25409. @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
  25410. return -ENODEV;
  25411. }
  25412. -static atomic_t ap_wfs_count;
  25413. +static atomic_unchecked_t ap_wfs_count;
  25414. static int tboot_wait_for_aps(int num_aps)
  25415. {
  25416. @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
  25417. {
  25418. switch (action) {
  25419. case CPU_DYING:
  25420. - atomic_inc(&ap_wfs_count);
  25421. + atomic_inc_unchecked(&ap_wfs_count);
  25422. if (num_online_cpus() == 1)
  25423. - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
  25424. + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
  25425. return NOTIFY_BAD;
  25426. break;
  25427. }
  25428. @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
  25429. tboot_create_trampoline();
  25430. - atomic_set(&ap_wfs_count, 0);
  25431. + atomic_set_unchecked(&ap_wfs_count, 0);
  25432. register_hotcpu_notifier(&tboot_cpu_notifier);
  25433. #ifdef CONFIG_DEBUG_FS
  25434. diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
  25435. index 24d3c91..d06b473 100644
  25436. --- a/arch/x86/kernel/time.c
  25437. +++ b/arch/x86/kernel/time.c
  25438. @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
  25439. {
  25440. unsigned long pc = instruction_pointer(regs);
  25441. - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
  25442. + if (!user_mode(regs) && in_lock_functions(pc)) {
  25443. #ifdef CONFIG_FRAME_POINTER
  25444. - return *(unsigned long *)(regs->bp + sizeof(long));
  25445. + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
  25446. #else
  25447. unsigned long *sp =
  25448. (unsigned long *)kernel_stack_pointer(regs);
  25449. @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
  25450. * or above a saved flags. Eflags has bits 22-31 zero,
  25451. * kernel addresses don't.
  25452. */
  25453. +
  25454. +#ifdef CONFIG_PAX_KERNEXEC
  25455. + return ktla_ktva(sp[0]);
  25456. +#else
  25457. if (sp[0] >> 22)
  25458. return sp[0];
  25459. if (sp[1] >> 22)
  25460. return sp[1];
  25461. #endif
  25462. +
  25463. +#endif
  25464. }
  25465. return pc;
  25466. }
  25467. diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
  25468. index f7fec09..9991981 100644
  25469. --- a/arch/x86/kernel/tls.c
  25470. +++ b/arch/x86/kernel/tls.c
  25471. @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
  25472. if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
  25473. return -EINVAL;
  25474. +#ifdef CONFIG_PAX_SEGMEXEC
  25475. + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
  25476. + return -EINVAL;
  25477. +#endif
  25478. +
  25479. set_tls_desc(p, idx, &info, 1);
  25480. return 0;
  25481. @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
  25482. if (kbuf)
  25483. info = kbuf;
  25484. - else if (__copy_from_user(infobuf, ubuf, count))
  25485. + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
  25486. return -EFAULT;
  25487. else
  25488. info = infobuf;
  25489. diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
  25490. index 1c113db..287b42e 100644
  25491. --- a/arch/x86/kernel/tracepoint.c
  25492. +++ b/arch/x86/kernel/tracepoint.c
  25493. @@ -9,11 +9,11 @@
  25494. #include <linux/atomic.h>
  25495. atomic_t trace_idt_ctr = ATOMIC_INIT(0);
  25496. -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
  25497. +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
  25498. (unsigned long) trace_idt_table };
  25499. /* No need to be aligned, but done to keep all IDTs defined the same way. */
  25500. -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
  25501. +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
  25502. static int trace_irq_vector_refcount;
  25503. static DEFINE_MUTEX(irq_vector_mutex);
  25504. diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
  25505. index 57409f6..e2c17e1 100644
  25506. --- a/arch/x86/kernel/traps.c
  25507. +++ b/arch/x86/kernel/traps.c
  25508. @@ -66,7 +66,7 @@
  25509. #include <asm/proto.h>
  25510. /* No need to be aligned, but done to keep all IDTs defined the same way. */
  25511. -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
  25512. +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
  25513. #else
  25514. #include <asm/processor-flags.h>
  25515. #include <asm/setup.h>
  25516. @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
  25517. #endif
  25518. /* Must be page-aligned because the real IDT is used in a fixmap. */
  25519. -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
  25520. +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
  25521. DECLARE_BITMAP(used_vectors, NR_VECTORS);
  25522. EXPORT_SYMBOL_GPL(used_vectors);
  25523. @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
  25524. }
  25525. static int __kprobes
  25526. -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
  25527. +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
  25528. struct pt_regs *regs, long error_code)
  25529. {
  25530. #ifdef CONFIG_X86_32
  25531. - if (regs->flags & X86_VM_MASK) {
  25532. + if (v8086_mode(regs)) {
  25533. /*
  25534. * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
  25535. * On nmi (interrupt 2), do_trap should not be called.
  25536. @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
  25537. return -1;
  25538. }
  25539. #endif
  25540. - if (!user_mode(regs)) {
  25541. + if (!user_mode_novm(regs)) {
  25542. if (!fixup_exception(regs)) {
  25543. tsk->thread.error_code = error_code;
  25544. tsk->thread.trap_nr = trapnr;
  25545. +
  25546. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  25547. + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
  25548. + str = "PAX: suspicious stack segment fault";
  25549. +#endif
  25550. +
  25551. die(str, regs, error_code);
  25552. }
  25553. +
  25554. +#ifdef CONFIG_PAX_REFCOUNT
  25555. + if (trapnr == X86_TRAP_OF)
  25556. + pax_report_refcount_overflow(regs);
  25557. +#endif
  25558. +
  25559. return 0;
  25560. }
  25561. @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
  25562. }
  25563. static void __kprobes
  25564. -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
  25565. +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
  25566. long error_code, siginfo_t *info)
  25567. {
  25568. struct task_struct *tsk = current;
  25569. @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
  25570. if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
  25571. printk_ratelimit()) {
  25572. pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
  25573. - tsk->comm, tsk->pid, str,
  25574. + tsk->comm, task_pid_nr(tsk), str,
  25575. regs->ip, regs->sp, error_code);
  25576. print_vma_addr(" in ", regs->ip);
  25577. pr_cont("\n");
  25578. @@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
  25579. conditional_sti(regs);
  25580. #ifdef CONFIG_X86_32
  25581. - if (regs->flags & X86_VM_MASK) {
  25582. + if (v8086_mode(regs)) {
  25583. local_irq_enable();
  25584. handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
  25585. goto exit;
  25586. @@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
  25587. #endif
  25588. tsk = current;
  25589. - if (!user_mode(regs)) {
  25590. + if (!user_mode_novm(regs)) {
  25591. if (fixup_exception(regs))
  25592. goto exit;
  25593. tsk->thread.error_code = error_code;
  25594. tsk->thread.trap_nr = X86_TRAP_GP;
  25595. if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
  25596. - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
  25597. + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
  25598. +
  25599. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  25600. + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
  25601. + die("PAX: suspicious general protection fault", regs, error_code);
  25602. + else
  25603. +#endif
  25604. +
  25605. die("general protection fault", regs, error_code);
  25606. + }
  25607. goto exit;
  25608. }
  25609. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
  25610. + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
  25611. + struct mm_struct *mm = tsk->mm;
  25612. + unsigned long limit;
  25613. +
  25614. + down_write(&mm->mmap_sem);
  25615. + limit = mm->context.user_cs_limit;
  25616. + if (limit < TASK_SIZE) {
  25617. + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
  25618. + up_write(&mm->mmap_sem);
  25619. + return;
  25620. + }
  25621. + up_write(&mm->mmap_sem);
  25622. + }
  25623. +#endif
  25624. +
  25625. tsk->thread.error_code = error_code;
  25626. tsk->thread.trap_nr = X86_TRAP_GP;
  25627. @@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
  25628. /* It's safe to allow irq's after DR6 has been saved */
  25629. preempt_conditional_sti(regs);
  25630. - if (regs->flags & X86_VM_MASK) {
  25631. + if (v8086_mode(regs)) {
  25632. handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
  25633. X86_TRAP_DB);
  25634. preempt_conditional_cli(regs);
  25635. @@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
  25636. * We already checked v86 mode above, so we can check for kernel mode
  25637. * by just checking the CPL of CS.
  25638. */
  25639. - if ((dr6 & DR_STEP) && !user_mode(regs)) {
  25640. + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
  25641. tsk->thread.debugreg6 &= ~DR_STEP;
  25642. set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
  25643. regs->flags &= ~X86_EFLAGS_TF;
  25644. @@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
  25645. return;
  25646. conditional_sti(regs);
  25647. - if (!user_mode_vm(regs))
  25648. + if (!user_mode(regs))
  25649. {
  25650. if (!fixup_exception(regs)) {
  25651. task->thread.error_code = error_code;
  25652. diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
  25653. index cfbe99f..a6e8fa7 100644
  25654. --- a/arch/x86/kernel/tsc.c
  25655. +++ b/arch/x86/kernel/tsc.c
  25656. @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
  25657. */
  25658. smp_wmb();
  25659. - ACCESS_ONCE(c2n->head) = data;
  25660. + ACCESS_ONCE_RW(c2n->head) = data;
  25661. }
  25662. /*
  25663. diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
  25664. index 2ed8459..7cf329f 100644
  25665. --- a/arch/x86/kernel/uprobes.c
  25666. +++ b/arch/x86/kernel/uprobes.c
  25667. @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
  25668. int ret = NOTIFY_DONE;
  25669. /* We are only interested in userspace traps */
  25670. - if (regs && !user_mode_vm(regs))
  25671. + if (regs && !user_mode(regs))
  25672. return NOTIFY_DONE;
  25673. switch (val) {
  25674. @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
  25675. if (ncopied != rasize) {
  25676. pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
  25677. - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
  25678. + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
  25679. force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
  25680. }
  25681. diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
  25682. index b9242ba..50c5edd 100644
  25683. --- a/arch/x86/kernel/verify_cpu.S
  25684. +++ b/arch/x86/kernel/verify_cpu.S
  25685. @@ -20,6 +20,7 @@
  25686. * arch/x86/boot/compressed/head_64.S: Boot cpu verification
  25687. * arch/x86/kernel/trampoline_64.S: secondary processor verification
  25688. * arch/x86/kernel/head_32.S: processor startup
  25689. + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
  25690. *
  25691. * verify_cpu, returns the status of longmode and SSE in register %eax.
  25692. * 0: Success 1: Failure
  25693. diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
  25694. index e8edcf5..27f9344 100644
  25695. --- a/arch/x86/kernel/vm86_32.c
  25696. +++ b/arch/x86/kernel/vm86_32.c
  25697. @@ -44,6 +44,7 @@
  25698. #include <linux/ptrace.h>
  25699. #include <linux/audit.h>
  25700. #include <linux/stddef.h>
  25701. +#include <linux/grsecurity.h>
  25702. #include <asm/uaccess.h>
  25703. #include <asm/io.h>
  25704. @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
  25705. do_exit(SIGSEGV);
  25706. }
  25707. - tss = &per_cpu(init_tss, get_cpu());
  25708. + tss = init_tss + get_cpu();
  25709. current->thread.sp0 = current->thread.saved_sp0;
  25710. current->thread.sysenter_cs = __KERNEL_CS;
  25711. load_sp0(tss, &current->thread);
  25712. @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
  25713. if (tsk->thread.saved_sp0)
  25714. return -EPERM;
  25715. +
  25716. +#ifdef CONFIG_GRKERNSEC_VM86
  25717. + if (!capable(CAP_SYS_RAWIO)) {
  25718. + gr_handle_vm86();
  25719. + return -EPERM;
  25720. + }
  25721. +#endif
  25722. +
  25723. tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
  25724. offsetof(struct kernel_vm86_struct, vm86plus) -
  25725. sizeof(info.regs));
  25726. @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
  25727. int tmp;
  25728. struct vm86plus_struct __user *v86;
  25729. +#ifdef CONFIG_GRKERNSEC_VM86
  25730. + if (!capable(CAP_SYS_RAWIO)) {
  25731. + gr_handle_vm86();
  25732. + return -EPERM;
  25733. + }
  25734. +#endif
  25735. +
  25736. tsk = current;
  25737. switch (cmd) {
  25738. case VM86_REQUEST_IRQ:
  25739. @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
  25740. tsk->thread.saved_fs = info->regs32->fs;
  25741. tsk->thread.saved_gs = get_user_gs(info->regs32);
  25742. - tss = &per_cpu(init_tss, get_cpu());
  25743. + tss = init_tss + get_cpu();
  25744. tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
  25745. if (cpu_has_sep)
  25746. tsk->thread.sysenter_cs = 0;
  25747. @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
  25748. goto cannot_handle;
  25749. if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
  25750. goto cannot_handle;
  25751. - intr_ptr = (unsigned long __user *) (i << 2);
  25752. + intr_ptr = (__force unsigned long __user *) (i << 2);
  25753. if (get_user(segoffs, intr_ptr))
  25754. goto cannot_handle;
  25755. if ((segoffs >> 16) == BIOSSEG)
  25756. diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
  25757. index da6b35a..977e9cf 100644
  25758. --- a/arch/x86/kernel/vmlinux.lds.S
  25759. +++ b/arch/x86/kernel/vmlinux.lds.S
  25760. @@ -26,6 +26,13 @@
  25761. #include <asm/page_types.h>
  25762. #include <asm/cache.h>
  25763. #include <asm/boot.h>
  25764. +#include <asm/segment.h>
  25765. +
  25766. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  25767. +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
  25768. +#else
  25769. +#define __KERNEL_TEXT_OFFSET 0
  25770. +#endif
  25771. #undef i386 /* in case the preprocessor is a 32bit one */
  25772. @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
  25773. PHDRS {
  25774. text PT_LOAD FLAGS(5); /* R_E */
  25775. +#ifdef CONFIG_X86_32
  25776. + module PT_LOAD FLAGS(5); /* R_E */
  25777. +#endif
  25778. +#ifdef CONFIG_XEN
  25779. + rodata PT_LOAD FLAGS(5); /* R_E */
  25780. +#else
  25781. + rodata PT_LOAD FLAGS(4); /* R__ */
  25782. +#endif
  25783. data PT_LOAD FLAGS(6); /* RW_ */
  25784. -#ifdef CONFIG_X86_64
  25785. + init.begin PT_LOAD FLAGS(6); /* RW_ */
  25786. #ifdef CONFIG_SMP
  25787. percpu PT_LOAD FLAGS(6); /* RW_ */
  25788. #endif
  25789. + text.init PT_LOAD FLAGS(5); /* R_E */
  25790. + text.exit PT_LOAD FLAGS(5); /* R_E */
  25791. init PT_LOAD FLAGS(7); /* RWE */
  25792. -#endif
  25793. note PT_NOTE FLAGS(0); /* ___ */
  25794. }
  25795. SECTIONS
  25796. {
  25797. #ifdef CONFIG_X86_32
  25798. - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
  25799. - phys_startup_32 = startup_32 - LOAD_OFFSET;
  25800. + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
  25801. #else
  25802. - . = __START_KERNEL;
  25803. - phys_startup_64 = startup_64 - LOAD_OFFSET;
  25804. + . = __START_KERNEL;
  25805. #endif
  25806. /* Text and read-only data */
  25807. - .text : AT(ADDR(.text) - LOAD_OFFSET) {
  25808. - _text = .;
  25809. + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
  25810. /* bootstrapping code */
  25811. +#ifdef CONFIG_X86_32
  25812. + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
  25813. +#else
  25814. + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
  25815. +#endif
  25816. + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
  25817. + _text = .;
  25818. HEAD_TEXT
  25819. . = ALIGN(8);
  25820. _stext = .;
  25821. @@ -104,13 +124,47 @@ SECTIONS
  25822. IRQENTRY_TEXT
  25823. *(.fixup)
  25824. *(.gnu.warning)
  25825. - /* End of text section */
  25826. - _etext = .;
  25827. } :text = 0x9090
  25828. - NOTES :text :note
  25829. + . += __KERNEL_TEXT_OFFSET;
  25830. - EXCEPTION_TABLE(16) :text = 0x9090
  25831. +#ifdef CONFIG_X86_32
  25832. + . = ALIGN(PAGE_SIZE);
  25833. + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
  25834. +
  25835. +#ifdef CONFIG_PAX_KERNEXEC
  25836. + MODULES_EXEC_VADDR = .;
  25837. + BYTE(0)
  25838. + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
  25839. + . = ALIGN(HPAGE_SIZE) - 1;
  25840. + MODULES_EXEC_END = .;
  25841. +#endif
  25842. +
  25843. + } :module
  25844. +#endif
  25845. +
  25846. + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
  25847. + /* End of text section */
  25848. + BYTE(0)
  25849. + _etext = . - __KERNEL_TEXT_OFFSET;
  25850. + }
  25851. +
  25852. +#ifdef CONFIG_X86_32
  25853. + . = ALIGN(PAGE_SIZE);
  25854. + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
  25855. + . = ALIGN(PAGE_SIZE);
  25856. + *(.empty_zero_page)
  25857. + *(.initial_pg_fixmap)
  25858. + *(.initial_pg_pmd)
  25859. + *(.initial_page_table)
  25860. + *(.swapper_pg_dir)
  25861. + } :rodata
  25862. +#endif
  25863. +
  25864. + . = ALIGN(PAGE_SIZE);
  25865. + NOTES :rodata :note
  25866. +
  25867. + EXCEPTION_TABLE(16) :rodata
  25868. #if defined(CONFIG_DEBUG_RODATA)
  25869. /* .text should occupy whole number of pages */
  25870. @@ -122,16 +176,20 @@ SECTIONS
  25871. /* Data */
  25872. .data : AT(ADDR(.data) - LOAD_OFFSET) {
  25873. +
  25874. +#ifdef CONFIG_PAX_KERNEXEC
  25875. + . = ALIGN(HPAGE_SIZE);
  25876. +#else
  25877. + . = ALIGN(PAGE_SIZE);
  25878. +#endif
  25879. +
  25880. /* Start of data section */
  25881. _sdata = .;
  25882. /* init_task */
  25883. INIT_TASK_DATA(THREAD_SIZE)
  25884. -#ifdef CONFIG_X86_32
  25885. - /* 32 bit has nosave before _edata */
  25886. NOSAVE_DATA
  25887. -#endif
  25888. PAGE_ALIGNED_DATA(PAGE_SIZE)
  25889. @@ -172,12 +230,19 @@ SECTIONS
  25890. #endif /* CONFIG_X86_64 */
  25891. /* Init code and data - will be freed after init */
  25892. - . = ALIGN(PAGE_SIZE);
  25893. .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
  25894. + BYTE(0)
  25895. +
  25896. +#ifdef CONFIG_PAX_KERNEXEC
  25897. + . = ALIGN(HPAGE_SIZE);
  25898. +#else
  25899. + . = ALIGN(PAGE_SIZE);
  25900. +#endif
  25901. +
  25902. __init_begin = .; /* paired with __init_end */
  25903. - }
  25904. + } :init.begin
  25905. -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
  25906. +#ifdef CONFIG_SMP
  25907. /*
  25908. * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
  25909. * output PHDR, so the next output section - .init.text - should
  25910. @@ -186,12 +251,27 @@ SECTIONS
  25911. PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
  25912. #endif
  25913. - INIT_TEXT_SECTION(PAGE_SIZE)
  25914. -#ifdef CONFIG_X86_64
  25915. - :init
  25916. -#endif
  25917. + . = ALIGN(PAGE_SIZE);
  25918. + init_begin = .;
  25919. + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
  25920. + VMLINUX_SYMBOL(_sinittext) = .;
  25921. + INIT_TEXT
  25922. + VMLINUX_SYMBOL(_einittext) = .;
  25923. + . = ALIGN(PAGE_SIZE);
  25924. + } :text.init
  25925. - INIT_DATA_SECTION(16)
  25926. + /*
  25927. + * .exit.text is discard at runtime, not link time, to deal with
  25928. + * references from .altinstructions and .eh_frame
  25929. + */
  25930. + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
  25931. + EXIT_TEXT
  25932. + . = ALIGN(16);
  25933. + } :text.exit
  25934. + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
  25935. +
  25936. + . = ALIGN(PAGE_SIZE);
  25937. + INIT_DATA_SECTION(16) :init
  25938. .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
  25939. __x86_cpu_dev_start = .;
  25940. @@ -262,19 +342,12 @@ SECTIONS
  25941. }
  25942. . = ALIGN(8);
  25943. - /*
  25944. - * .exit.text is discard at runtime, not link time, to deal with
  25945. - * references from .altinstructions and .eh_frame
  25946. - */
  25947. - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
  25948. - EXIT_TEXT
  25949. - }
  25950. .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
  25951. EXIT_DATA
  25952. }
  25953. -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
  25954. +#ifndef CONFIG_SMP
  25955. PERCPU_SECTION(INTERNODE_CACHE_BYTES)
  25956. #endif
  25957. @@ -293,16 +366,10 @@ SECTIONS
  25958. .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
  25959. __smp_locks = .;
  25960. *(.smp_locks)
  25961. - . = ALIGN(PAGE_SIZE);
  25962. __smp_locks_end = .;
  25963. + . = ALIGN(PAGE_SIZE);
  25964. }
  25965. -#ifdef CONFIG_X86_64
  25966. - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
  25967. - NOSAVE_DATA
  25968. - }
  25969. -#endif
  25970. -
  25971. /* BSS */
  25972. . = ALIGN(PAGE_SIZE);
  25973. .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
  25974. @@ -318,6 +385,7 @@ SECTIONS
  25975. __brk_base = .;
  25976. . += 64 * 1024; /* 64k alignment slop space */
  25977. *(.brk_reservation) /* areas brk users have reserved */
  25978. + . = ALIGN(HPAGE_SIZE);
  25979. __brk_limit = .;
  25980. }
  25981. @@ -344,13 +412,12 @@ SECTIONS
  25982. * for the boot processor.
  25983. */
  25984. #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
  25985. -INIT_PER_CPU(gdt_page);
  25986. INIT_PER_CPU(irq_stack_union);
  25987. /*
  25988. * Build-time check on the image size:
  25989. */
  25990. -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
  25991. +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
  25992. "kernel image bigger than KERNEL_IMAGE_SIZE");
  25993. #ifdef CONFIG_SMP
  25994. diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
  25995. index 1f96f93..6f29be7 100644
  25996. --- a/arch/x86/kernel/vsyscall_64.c
  25997. +++ b/arch/x86/kernel/vsyscall_64.c
  25998. @@ -56,15 +56,13 @@
  25999. DEFINE_VVAR(int, vgetcpu_mode);
  26000. DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
  26001. -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
  26002. +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
  26003. static int __init vsyscall_setup(char *str)
  26004. {
  26005. if (str) {
  26006. if (!strcmp("emulate", str))
  26007. vsyscall_mode = EMULATE;
  26008. - else if (!strcmp("native", str))
  26009. - vsyscall_mode = NATIVE;
  26010. else if (!strcmp("none", str))
  26011. vsyscall_mode = NONE;
  26012. else
  26013. @@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
  26014. vdata->monotonic_time_sec = tk->xtime_sec
  26015. + tk->wall_to_monotonic.tv_sec;
  26016. vdata->monotonic_time_snsec = tk->xtime_nsec
  26017. - + (tk->wall_to_monotonic.tv_nsec
  26018. + + ((u64)tk->wall_to_monotonic.tv_nsec
  26019. << tk->shift);
  26020. while (vdata->monotonic_time_snsec >=
  26021. (((u64)NSEC_PER_SEC) << tk->shift)) {
  26022. @@ -323,8 +321,7 @@ do_ret:
  26023. return true;
  26024. sigsegv:
  26025. - force_sig(SIGSEGV, current);
  26026. - return true;
  26027. + do_group_exit(SIGKILL);
  26028. }
  26029. /*
  26030. @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
  26031. extern char __vvar_page;
  26032. unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
  26033. - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
  26034. - vsyscall_mode == NATIVE
  26035. - ? PAGE_KERNEL_VSYSCALL
  26036. - : PAGE_KERNEL_VVAR);
  26037. + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
  26038. BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
  26039. (unsigned long)VSYSCALL_START);
  26040. diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
  26041. index 04068192..4d75aa6 100644
  26042. --- a/arch/x86/kernel/x8664_ksyms_64.c
  26043. +++ b/arch/x86/kernel/x8664_ksyms_64.c
  26044. @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
  26045. EXPORT_SYMBOL(copy_user_generic_unrolled);
  26046. EXPORT_SYMBOL(copy_user_enhanced_fast_string);
  26047. EXPORT_SYMBOL(__copy_user_nocache);
  26048. -EXPORT_SYMBOL(_copy_from_user);
  26049. -EXPORT_SYMBOL(_copy_to_user);
  26050. EXPORT_SYMBOL(copy_page);
  26051. EXPORT_SYMBOL(clear_page);
  26052. @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
  26053. EXPORT_SYMBOL(___preempt_schedule_context);
  26054. #endif
  26055. #endif
  26056. +
  26057. +#ifdef CONFIG_PAX_PER_CPU_PGD
  26058. +EXPORT_SYMBOL(cpu_pgd);
  26059. +#endif
  26060. diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
  26061. index e48b674..a451dd9 100644
  26062. --- a/arch/x86/kernel/x86_init.c
  26063. +++ b/arch/x86/kernel/x86_init.c
  26064. @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
  26065. static void default_nmi_init(void) { };
  26066. static int default_i8042_detect(void) { return 1; };
  26067. -struct x86_platform_ops x86_platform = {
  26068. +struct x86_platform_ops x86_platform __read_only = {
  26069. .calibrate_tsc = native_calibrate_tsc,
  26070. .get_wallclock = mach_get_cmos_time,
  26071. .set_wallclock = mach_set_rtc_mmss,
  26072. @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
  26073. EXPORT_SYMBOL_GPL(x86_platform);
  26074. #if defined(CONFIG_PCI_MSI)
  26075. -struct x86_msi_ops x86_msi = {
  26076. +struct x86_msi_ops x86_msi __read_only = {
  26077. .setup_msi_irqs = native_setup_msi_irqs,
  26078. .compose_msi_msg = native_compose_msi_msg,
  26079. .teardown_msi_irq = native_teardown_msi_irq,
  26080. @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
  26081. }
  26082. #endif
  26083. -struct x86_io_apic_ops x86_io_apic_ops = {
  26084. +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
  26085. .init = native_io_apic_init_mappings,
  26086. .read = native_io_apic_read,
  26087. .write = native_io_apic_write,
  26088. diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
  26089. index a4b451c..8dfe1ad 100644
  26090. --- a/arch/x86/kernel/xsave.c
  26091. +++ b/arch/x86/kernel/xsave.c
  26092. @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
  26093. /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
  26094. sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
  26095. - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
  26096. + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
  26097. if (!use_xsave())
  26098. return err;
  26099. - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
  26100. + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
  26101. /*
  26102. * Read the xstate_bv which we copied (directly from the cpu or
  26103. * from the state in task struct) to the user buffers.
  26104. */
  26105. - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
  26106. + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
  26107. /*
  26108. * For legacy compatible, we always set FP/SSE bits in the bit
  26109. @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
  26110. */
  26111. xstate_bv |= XSTATE_FPSSE;
  26112. - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
  26113. + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
  26114. return err;
  26115. }
  26116. @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
  26117. {
  26118. int err;
  26119. + buf = (struct xsave_struct __user *)____m(buf);
  26120. if (use_xsave())
  26121. err = xsave_user(buf);
  26122. else if (use_fxsr())
  26123. @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
  26124. */
  26125. static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
  26126. {
  26127. + buf = (void __user *)____m(buf);
  26128. if (use_xsave()) {
  26129. if ((unsigned long)buf % 64 || fx_only) {
  26130. u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
  26131. diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
  26132. index c697625..a032162 100644
  26133. --- a/arch/x86/kvm/cpuid.c
  26134. +++ b/arch/x86/kvm/cpuid.c
  26135. @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
  26136. struct kvm_cpuid2 *cpuid,
  26137. struct kvm_cpuid_entry2 __user *entries)
  26138. {
  26139. - int r;
  26140. + int r, i;
  26141. r = -E2BIG;
  26142. if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
  26143. goto out;
  26144. r = -EFAULT;
  26145. - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
  26146. - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
  26147. + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
  26148. goto out;
  26149. + for (i = 0; i < cpuid->nent; ++i) {
  26150. + struct kvm_cpuid_entry2 cpuid_entry;
  26151. + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
  26152. + goto out;
  26153. + vcpu->arch.cpuid_entries[i] = cpuid_entry;
  26154. + }
  26155. vcpu->arch.cpuid_nent = cpuid->nent;
  26156. kvm_apic_set_version(vcpu);
  26157. kvm_x86_ops->cpuid_update(vcpu);
  26158. @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
  26159. struct kvm_cpuid2 *cpuid,
  26160. struct kvm_cpuid_entry2 __user *entries)
  26161. {
  26162. - int r;
  26163. + int r, i;
  26164. r = -E2BIG;
  26165. if (cpuid->nent < vcpu->arch.cpuid_nent)
  26166. goto out;
  26167. r = -EFAULT;
  26168. - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
  26169. - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
  26170. + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
  26171. goto out;
  26172. + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
  26173. + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
  26174. + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
  26175. + goto out;
  26176. + }
  26177. return 0;
  26178. out:
  26179. diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
  26180. index 9736529..ab4f54c 100644
  26181. --- a/arch/x86/kvm/lapic.c
  26182. +++ b/arch/x86/kvm/lapic.c
  26183. @@ -55,7 +55,7 @@
  26184. #define APIC_BUS_CYCLE_NS 1
  26185. /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
  26186. -#define apic_debug(fmt, arg...)
  26187. +#define apic_debug(fmt, arg...) do {} while (0)
  26188. #define APIC_LVT_NUM 6
  26189. /* 14 is the version for Xeon and Pentium 8.4.8*/
  26190. diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
  26191. index cba218a..1cc1bed 100644
  26192. --- a/arch/x86/kvm/paging_tmpl.h
  26193. +++ b/arch/x86/kvm/paging_tmpl.h
  26194. @@ -331,7 +331,7 @@ retry_walk:
  26195. if (unlikely(kvm_is_error_hva(host_addr)))
  26196. goto error;
  26197. - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
  26198. + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
  26199. if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
  26200. goto error;
  26201. walker->ptep_user[walker->level - 1] = ptep_user;
  26202. diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
  26203. index 2de1bc0..22251ee 100644
  26204. --- a/arch/x86/kvm/svm.c
  26205. +++ b/arch/x86/kvm/svm.c
  26206. @@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
  26207. int cpu = raw_smp_processor_id();
  26208. struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
  26209. +
  26210. + pax_open_kernel();
  26211. sd->tss_desc->type = 9; /* available 32/64-bit TSS */
  26212. + pax_close_kernel();
  26213. +
  26214. load_TR_desc();
  26215. }
  26216. @@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
  26217. #endif
  26218. #endif
  26219. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
  26220. + __set_fs(current_thread_info()->addr_limit);
  26221. +#endif
  26222. +
  26223. reload_tss(vcpu);
  26224. local_irq_disable();
  26225. diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
  26226. index 3927528..fc19971 100644
  26227. --- a/arch/x86/kvm/vmx.c
  26228. +++ b/arch/x86/kvm/vmx.c
  26229. @@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
  26230. #endif
  26231. }
  26232. -static void vmcs_clear_bits(unsigned long field, u32 mask)
  26233. +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
  26234. {
  26235. vmcs_writel(field, vmcs_readl(field) & ~mask);
  26236. }
  26237. -static void vmcs_set_bits(unsigned long field, u32 mask)
  26238. +static void vmcs_set_bits(unsigned long field, unsigned long mask)
  26239. {
  26240. vmcs_writel(field, vmcs_readl(field) | mask);
  26241. }
  26242. @@ -1585,7 +1585,11 @@ static void reload_tss(void)
  26243. struct desc_struct *descs;
  26244. descs = (void *)gdt->address;
  26245. +
  26246. + pax_open_kernel();
  26247. descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
  26248. + pax_close_kernel();
  26249. +
  26250. load_TR_desc();
  26251. }
  26252. @@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
  26253. vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
  26254. vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
  26255. +#ifdef CONFIG_PAX_PER_CPU_PGD
  26256. + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
  26257. +#endif
  26258. +
  26259. rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
  26260. vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
  26261. vmx->loaded_vmcs->cpu = cpu;
  26262. @@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
  26263. * reads and returns guest's timestamp counter "register"
  26264. * guest_tsc = host_tsc + tsc_offset -- 21.3
  26265. */
  26266. -static u64 guest_read_tsc(void)
  26267. +static u64 __intentional_overflow(-1) guest_read_tsc(void)
  26268. {
  26269. u64 host_tsc, tsc_offset;
  26270. @@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
  26271. if (!cpu_has_vmx_flexpriority())
  26272. flexpriority_enabled = 0;
  26273. - if (!cpu_has_vmx_tpr_shadow())
  26274. - kvm_x86_ops->update_cr8_intercept = NULL;
  26275. + if (!cpu_has_vmx_tpr_shadow()) {
  26276. + pax_open_kernel();
  26277. + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
  26278. + pax_close_kernel();
  26279. + }
  26280. if (enable_ept && !cpu_has_vmx_ept_2m_page())
  26281. kvm_disable_largepages();
  26282. @@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
  26283. if (!cpu_has_vmx_apicv())
  26284. enable_apicv = 0;
  26285. + pax_open_kernel();
  26286. if (enable_apicv)
  26287. - kvm_x86_ops->update_cr8_intercept = NULL;
  26288. + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
  26289. else {
  26290. - kvm_x86_ops->hwapic_irr_update = NULL;
  26291. - kvm_x86_ops->deliver_posted_interrupt = NULL;
  26292. - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
  26293. + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
  26294. + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
  26295. + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
  26296. }
  26297. + pax_close_kernel();
  26298. if (nested)
  26299. nested_vmx_setup_ctls_msrs();
  26300. @@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
  26301. vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
  26302. vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
  26303. +
  26304. +#ifndef CONFIG_PAX_PER_CPU_PGD
  26305. vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
  26306. +#endif
  26307. vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
  26308. #ifdef CONFIG_X86_64
  26309. @@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
  26310. vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
  26311. vmx->host_idt_base = dt.address;
  26312. - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
  26313. + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
  26314. rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
  26315. vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
  26316. @@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
  26317. "jmp 2f \n\t"
  26318. "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
  26319. "2: "
  26320. +
  26321. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  26322. + "ljmp %[cs],$3f\n\t"
  26323. + "3: "
  26324. +#endif
  26325. +
  26326. /* Save guest registers, load host registers, keep flags */
  26327. "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
  26328. "pop %0 \n\t"
  26329. @@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
  26330. #endif
  26331. [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
  26332. [wordsize]"i"(sizeof(ulong))
  26333. +
  26334. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  26335. + ,[cs]"i"(__KERNEL_CS)
  26336. +#endif
  26337. +
  26338. : "cc", "memory"
  26339. #ifdef CONFIG_X86_64
  26340. , "rax", "rbx", "rdi", "rsi"
  26341. @@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
  26342. if (debugctlmsr)
  26343. update_debugctlmsr(debugctlmsr);
  26344. -#ifndef CONFIG_X86_64
  26345. +#ifdef CONFIG_X86_32
  26346. /*
  26347. * The sysexit path does not restore ds/es, so we must set them to
  26348. * a reasonable value ourselves.
  26349. @@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
  26350. * may be executed in interrupt context, which saves and restore segments
  26351. * around it, nullifying its effect.
  26352. */
  26353. - loadsegment(ds, __USER_DS);
  26354. - loadsegment(es, __USER_DS);
  26355. + loadsegment(ds, __KERNEL_DS);
  26356. + loadsegment(es, __KERNEL_DS);
  26357. + loadsegment(ss, __KERNEL_DS);
  26358. +
  26359. +#ifdef CONFIG_PAX_KERNEXEC
  26360. + loadsegment(fs, __KERNEL_PERCPU);
  26361. +#endif
  26362. +
  26363. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  26364. + __set_fs(current_thread_info()->addr_limit);
  26365. +#endif
  26366. +
  26367. #endif
  26368. vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
  26369. diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
  26370. index 2b85784..ad70e19 100644
  26371. --- a/arch/x86/kvm/x86.c
  26372. +++ b/arch/x86/kvm/x86.c
  26373. @@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
  26374. {
  26375. struct kvm *kvm = vcpu->kvm;
  26376. int lm = is_long_mode(vcpu);
  26377. - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
  26378. - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
  26379. + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
  26380. + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
  26381. u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
  26382. : kvm->arch.xen_hvm_config.blob_size_32;
  26383. u32 page_num = data & ~PAGE_MASK;
  26384. @@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
  26385. if (n < msr_list.nmsrs)
  26386. goto out;
  26387. r = -EFAULT;
  26388. + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
  26389. + goto out;
  26390. if (copy_to_user(user_msr_list->indices, &msrs_to_save,
  26391. num_msrs_to_save * sizeof(u32)))
  26392. goto out;
  26393. @@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
  26394. };
  26395. #endif
  26396. -int kvm_arch_init(void *opaque)
  26397. +int kvm_arch_init(const void *opaque)
  26398. {
  26399. int r;
  26400. struct kvm_x86_ops *ops = opaque;
  26401. diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
  26402. index ad1fb5f..fe30b66 100644
  26403. --- a/arch/x86/lguest/boot.c
  26404. +++ b/arch/x86/lguest/boot.c
  26405. @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
  26406. * Rebooting also tells the Host we're finished, but the RESTART flag tells the
  26407. * Launcher to reboot us.
  26408. */
  26409. -static void lguest_restart(char *reason)
  26410. +static __noreturn void lguest_restart(char *reason)
  26411. {
  26412. hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
  26413. + BUG();
  26414. }
  26415. /*G:050
  26416. diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
  26417. index 00933d5..3a64af9 100644
  26418. --- a/arch/x86/lib/atomic64_386_32.S
  26419. +++ b/arch/x86/lib/atomic64_386_32.S
  26420. @@ -48,6 +48,10 @@ BEGIN(read)
  26421. movl (v), %eax
  26422. movl 4(v), %edx
  26423. RET_ENDP
  26424. +BEGIN(read_unchecked)
  26425. + movl (v), %eax
  26426. + movl 4(v), %edx
  26427. +RET_ENDP
  26428. #undef v
  26429. #define v %esi
  26430. @@ -55,6 +59,10 @@ BEGIN(set)
  26431. movl %ebx, (v)
  26432. movl %ecx, 4(v)
  26433. RET_ENDP
  26434. +BEGIN(set_unchecked)
  26435. + movl %ebx, (v)
  26436. + movl %ecx, 4(v)
  26437. +RET_ENDP
  26438. #undef v
  26439. #define v %esi
  26440. @@ -70,6 +78,20 @@ RET_ENDP
  26441. BEGIN(add)
  26442. addl %eax, (v)
  26443. adcl %edx, 4(v)
  26444. +
  26445. +#ifdef CONFIG_PAX_REFCOUNT
  26446. + jno 0f
  26447. + subl %eax, (v)
  26448. + sbbl %edx, 4(v)
  26449. + int $4
  26450. +0:
  26451. + _ASM_EXTABLE(0b, 0b)
  26452. +#endif
  26453. +
  26454. +RET_ENDP
  26455. +BEGIN(add_unchecked)
  26456. + addl %eax, (v)
  26457. + adcl %edx, 4(v)
  26458. RET_ENDP
  26459. #undef v
  26460. @@ -77,6 +99,24 @@ RET_ENDP
  26461. BEGIN(add_return)
  26462. addl (v), %eax
  26463. adcl 4(v), %edx
  26464. +
  26465. +#ifdef CONFIG_PAX_REFCOUNT
  26466. + into
  26467. +1234:
  26468. + _ASM_EXTABLE(1234b, 2f)
  26469. +#endif
  26470. +
  26471. + movl %eax, (v)
  26472. + movl %edx, 4(v)
  26473. +
  26474. +#ifdef CONFIG_PAX_REFCOUNT
  26475. +2:
  26476. +#endif
  26477. +
  26478. +RET_ENDP
  26479. +BEGIN(add_return_unchecked)
  26480. + addl (v), %eax
  26481. + adcl 4(v), %edx
  26482. movl %eax, (v)
  26483. movl %edx, 4(v)
  26484. RET_ENDP
  26485. @@ -86,6 +126,20 @@ RET_ENDP
  26486. BEGIN(sub)
  26487. subl %eax, (v)
  26488. sbbl %edx, 4(v)
  26489. +
  26490. +#ifdef CONFIG_PAX_REFCOUNT
  26491. + jno 0f
  26492. + addl %eax, (v)
  26493. + adcl %edx, 4(v)
  26494. + int $4
  26495. +0:
  26496. + _ASM_EXTABLE(0b, 0b)
  26497. +#endif
  26498. +
  26499. +RET_ENDP
  26500. +BEGIN(sub_unchecked)
  26501. + subl %eax, (v)
  26502. + sbbl %edx, 4(v)
  26503. RET_ENDP
  26504. #undef v
  26505. @@ -96,6 +150,27 @@ BEGIN(sub_return)
  26506. sbbl $0, %edx
  26507. addl (v), %eax
  26508. adcl 4(v), %edx
  26509. +
  26510. +#ifdef CONFIG_PAX_REFCOUNT
  26511. + into
  26512. +1234:
  26513. + _ASM_EXTABLE(1234b, 2f)
  26514. +#endif
  26515. +
  26516. + movl %eax, (v)
  26517. + movl %edx, 4(v)
  26518. +
  26519. +#ifdef CONFIG_PAX_REFCOUNT
  26520. +2:
  26521. +#endif
  26522. +
  26523. +RET_ENDP
  26524. +BEGIN(sub_return_unchecked)
  26525. + negl %edx
  26526. + negl %eax
  26527. + sbbl $0, %edx
  26528. + addl (v), %eax
  26529. + adcl 4(v), %edx
  26530. movl %eax, (v)
  26531. movl %edx, 4(v)
  26532. RET_ENDP
  26533. @@ -105,6 +180,20 @@ RET_ENDP
  26534. BEGIN(inc)
  26535. addl $1, (v)
  26536. adcl $0, 4(v)
  26537. +
  26538. +#ifdef CONFIG_PAX_REFCOUNT
  26539. + jno 0f
  26540. + subl $1, (v)
  26541. + sbbl $0, 4(v)
  26542. + int $4
  26543. +0:
  26544. + _ASM_EXTABLE(0b, 0b)
  26545. +#endif
  26546. +
  26547. +RET_ENDP
  26548. +BEGIN(inc_unchecked)
  26549. + addl $1, (v)
  26550. + adcl $0, 4(v)
  26551. RET_ENDP
  26552. #undef v
  26553. @@ -114,6 +203,26 @@ BEGIN(inc_return)
  26554. movl 4(v), %edx
  26555. addl $1, %eax
  26556. adcl $0, %edx
  26557. +
  26558. +#ifdef CONFIG_PAX_REFCOUNT
  26559. + into
  26560. +1234:
  26561. + _ASM_EXTABLE(1234b, 2f)
  26562. +#endif
  26563. +
  26564. + movl %eax, (v)
  26565. + movl %edx, 4(v)
  26566. +
  26567. +#ifdef CONFIG_PAX_REFCOUNT
  26568. +2:
  26569. +#endif
  26570. +
  26571. +RET_ENDP
  26572. +BEGIN(inc_return_unchecked)
  26573. + movl (v), %eax
  26574. + movl 4(v), %edx
  26575. + addl $1, %eax
  26576. + adcl $0, %edx
  26577. movl %eax, (v)
  26578. movl %edx, 4(v)
  26579. RET_ENDP
  26580. @@ -123,6 +232,20 @@ RET_ENDP
  26581. BEGIN(dec)
  26582. subl $1, (v)
  26583. sbbl $0, 4(v)
  26584. +
  26585. +#ifdef CONFIG_PAX_REFCOUNT
  26586. + jno 0f
  26587. + addl $1, (v)
  26588. + adcl $0, 4(v)
  26589. + int $4
  26590. +0:
  26591. + _ASM_EXTABLE(0b, 0b)
  26592. +#endif
  26593. +
  26594. +RET_ENDP
  26595. +BEGIN(dec_unchecked)
  26596. + subl $1, (v)
  26597. + sbbl $0, 4(v)
  26598. RET_ENDP
  26599. #undef v
  26600. @@ -132,6 +255,26 @@ BEGIN(dec_return)
  26601. movl 4(v), %edx
  26602. subl $1, %eax
  26603. sbbl $0, %edx
  26604. +
  26605. +#ifdef CONFIG_PAX_REFCOUNT
  26606. + into
  26607. +1234:
  26608. + _ASM_EXTABLE(1234b, 2f)
  26609. +#endif
  26610. +
  26611. + movl %eax, (v)
  26612. + movl %edx, 4(v)
  26613. +
  26614. +#ifdef CONFIG_PAX_REFCOUNT
  26615. +2:
  26616. +#endif
  26617. +
  26618. +RET_ENDP
  26619. +BEGIN(dec_return_unchecked)
  26620. + movl (v), %eax
  26621. + movl 4(v), %edx
  26622. + subl $1, %eax
  26623. + sbbl $0, %edx
  26624. movl %eax, (v)
  26625. movl %edx, 4(v)
  26626. RET_ENDP
  26627. @@ -143,6 +286,13 @@ BEGIN(add_unless)
  26628. adcl %edx, %edi
  26629. addl (v), %eax
  26630. adcl 4(v), %edx
  26631. +
  26632. +#ifdef CONFIG_PAX_REFCOUNT
  26633. + into
  26634. +1234:
  26635. + _ASM_EXTABLE(1234b, 2f)
  26636. +#endif
  26637. +
  26638. cmpl %eax, %ecx
  26639. je 3f
  26640. 1:
  26641. @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
  26642. 1:
  26643. addl $1, %eax
  26644. adcl $0, %edx
  26645. +
  26646. +#ifdef CONFIG_PAX_REFCOUNT
  26647. + into
  26648. +1234:
  26649. + _ASM_EXTABLE(1234b, 2f)
  26650. +#endif
  26651. +
  26652. movl %eax, (v)
  26653. movl %edx, 4(v)
  26654. movl $1, %eax
  26655. @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
  26656. movl 4(v), %edx
  26657. subl $1, %eax
  26658. sbbl $0, %edx
  26659. +
  26660. +#ifdef CONFIG_PAX_REFCOUNT
  26661. + into
  26662. +1234:
  26663. + _ASM_EXTABLE(1234b, 1f)
  26664. +#endif
  26665. +
  26666. js 1f
  26667. movl %eax, (v)
  26668. movl %edx, 4(v)
  26669. diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
  26670. index f5cc9eb..51fa319 100644
  26671. --- a/arch/x86/lib/atomic64_cx8_32.S
  26672. +++ b/arch/x86/lib/atomic64_cx8_32.S
  26673. @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
  26674. CFI_STARTPROC
  26675. read64 %ecx
  26676. + pax_force_retaddr
  26677. ret
  26678. CFI_ENDPROC
  26679. ENDPROC(atomic64_read_cx8)
  26680. +ENTRY(atomic64_read_unchecked_cx8)
  26681. + CFI_STARTPROC
  26682. +
  26683. + read64 %ecx
  26684. + pax_force_retaddr
  26685. + ret
  26686. + CFI_ENDPROC
  26687. +ENDPROC(atomic64_read_unchecked_cx8)
  26688. +
  26689. ENTRY(atomic64_set_cx8)
  26690. CFI_STARTPROC
  26691. @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
  26692. cmpxchg8b (%esi)
  26693. jne 1b
  26694. + pax_force_retaddr
  26695. ret
  26696. CFI_ENDPROC
  26697. ENDPROC(atomic64_set_cx8)
  26698. +ENTRY(atomic64_set_unchecked_cx8)
  26699. + CFI_STARTPROC
  26700. +
  26701. +1:
  26702. +/* we don't need LOCK_PREFIX since aligned 64-bit writes
  26703. + * are atomic on 586 and newer */
  26704. + cmpxchg8b (%esi)
  26705. + jne 1b
  26706. +
  26707. + pax_force_retaddr
  26708. + ret
  26709. + CFI_ENDPROC
  26710. +ENDPROC(atomic64_set_unchecked_cx8)
  26711. +
  26712. ENTRY(atomic64_xchg_cx8)
  26713. CFI_STARTPROC
  26714. @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
  26715. cmpxchg8b (%esi)
  26716. jne 1b
  26717. + pax_force_retaddr
  26718. ret
  26719. CFI_ENDPROC
  26720. ENDPROC(atomic64_xchg_cx8)
  26721. -.macro addsub_return func ins insc
  26722. -ENTRY(atomic64_\func\()_return_cx8)
  26723. +.macro addsub_return func ins insc unchecked=""
  26724. +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
  26725. CFI_STARTPROC
  26726. SAVE ebp
  26727. SAVE ebx
  26728. @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
  26729. movl %edx, %ecx
  26730. \ins\()l %esi, %ebx
  26731. \insc\()l %edi, %ecx
  26732. +
  26733. +.ifb \unchecked
  26734. +#ifdef CONFIG_PAX_REFCOUNT
  26735. + into
  26736. +2:
  26737. + _ASM_EXTABLE(2b, 3f)
  26738. +#endif
  26739. +.endif
  26740. +
  26741. LOCK_PREFIX
  26742. cmpxchg8b (%ebp)
  26743. jne 1b
  26744. -
  26745. -10:
  26746. movl %ebx, %eax
  26747. movl %ecx, %edx
  26748. +
  26749. +.ifb \unchecked
  26750. +#ifdef CONFIG_PAX_REFCOUNT
  26751. +3:
  26752. +#endif
  26753. +.endif
  26754. +
  26755. RESTORE edi
  26756. RESTORE esi
  26757. RESTORE ebx
  26758. RESTORE ebp
  26759. + pax_force_retaddr
  26760. ret
  26761. CFI_ENDPROC
  26762. -ENDPROC(atomic64_\func\()_return_cx8)
  26763. +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
  26764. .endm
  26765. addsub_return add add adc
  26766. addsub_return sub sub sbb
  26767. +addsub_return add add adc _unchecked
  26768. +addsub_return sub sub sbb _unchecked
  26769. -.macro incdec_return func ins insc
  26770. -ENTRY(atomic64_\func\()_return_cx8)
  26771. +.macro incdec_return func ins insc unchecked=""
  26772. +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
  26773. CFI_STARTPROC
  26774. SAVE ebx
  26775. @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
  26776. movl %edx, %ecx
  26777. \ins\()l $1, %ebx
  26778. \insc\()l $0, %ecx
  26779. +
  26780. +.ifb \unchecked
  26781. +#ifdef CONFIG_PAX_REFCOUNT
  26782. + into
  26783. +2:
  26784. + _ASM_EXTABLE(2b, 3f)
  26785. +#endif
  26786. +.endif
  26787. +
  26788. LOCK_PREFIX
  26789. cmpxchg8b (%esi)
  26790. jne 1b
  26791. -10:
  26792. movl %ebx, %eax
  26793. movl %ecx, %edx
  26794. +
  26795. +.ifb \unchecked
  26796. +#ifdef CONFIG_PAX_REFCOUNT
  26797. +3:
  26798. +#endif
  26799. +.endif
  26800. +
  26801. RESTORE ebx
  26802. + pax_force_retaddr
  26803. ret
  26804. CFI_ENDPROC
  26805. -ENDPROC(atomic64_\func\()_return_cx8)
  26806. +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
  26807. .endm
  26808. incdec_return inc add adc
  26809. incdec_return dec sub sbb
  26810. +incdec_return inc add adc _unchecked
  26811. +incdec_return dec sub sbb _unchecked
  26812. ENTRY(atomic64_dec_if_positive_cx8)
  26813. CFI_STARTPROC
  26814. @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
  26815. movl %edx, %ecx
  26816. subl $1, %ebx
  26817. sbb $0, %ecx
  26818. +
  26819. +#ifdef CONFIG_PAX_REFCOUNT
  26820. + into
  26821. +1234:
  26822. + _ASM_EXTABLE(1234b, 2f)
  26823. +#endif
  26824. +
  26825. js 2f
  26826. LOCK_PREFIX
  26827. cmpxchg8b (%esi)
  26828. @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
  26829. movl %ebx, %eax
  26830. movl %ecx, %edx
  26831. RESTORE ebx
  26832. + pax_force_retaddr
  26833. ret
  26834. CFI_ENDPROC
  26835. ENDPROC(atomic64_dec_if_positive_cx8)
  26836. @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
  26837. movl %edx, %ecx
  26838. addl %ebp, %ebx
  26839. adcl %edi, %ecx
  26840. +
  26841. +#ifdef CONFIG_PAX_REFCOUNT
  26842. + into
  26843. +1234:
  26844. + _ASM_EXTABLE(1234b, 3f)
  26845. +#endif
  26846. +
  26847. LOCK_PREFIX
  26848. cmpxchg8b (%esi)
  26849. jne 1b
  26850. @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
  26851. CFI_ADJUST_CFA_OFFSET -8
  26852. RESTORE ebx
  26853. RESTORE ebp
  26854. + pax_force_retaddr
  26855. ret
  26856. 4:
  26857. cmpl %edx, 4(%esp)
  26858. @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
  26859. xorl %ecx, %ecx
  26860. addl $1, %ebx
  26861. adcl %edx, %ecx
  26862. +
  26863. +#ifdef CONFIG_PAX_REFCOUNT
  26864. + into
  26865. +1234:
  26866. + _ASM_EXTABLE(1234b, 3f)
  26867. +#endif
  26868. +
  26869. LOCK_PREFIX
  26870. cmpxchg8b (%esi)
  26871. jne 1b
  26872. @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
  26873. movl $1, %eax
  26874. 3:
  26875. RESTORE ebx
  26876. + pax_force_retaddr
  26877. ret
  26878. CFI_ENDPROC
  26879. ENDPROC(atomic64_inc_not_zero_cx8)
  26880. diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
  26881. index e78b8ee..7e173a8 100644
  26882. --- a/arch/x86/lib/checksum_32.S
  26883. +++ b/arch/x86/lib/checksum_32.S
  26884. @@ -29,7 +29,8 @@
  26885. #include <asm/dwarf2.h>
  26886. #include <asm/errno.h>
  26887. #include <asm/asm.h>
  26888. -
  26889. +#include <asm/segment.h>
  26890. +
  26891. /*
  26892. * computes a partial checksum, e.g. for TCP/UDP fragments
  26893. */
  26894. @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
  26895. #define ARGBASE 16
  26896. #define FP 12
  26897. -
  26898. -ENTRY(csum_partial_copy_generic)
  26899. +
  26900. +ENTRY(csum_partial_copy_generic_to_user)
  26901. CFI_STARTPROC
  26902. +
  26903. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  26904. + pushl_cfi %gs
  26905. + popl_cfi %es
  26906. + jmp csum_partial_copy_generic
  26907. +#endif
  26908. +
  26909. +ENTRY(csum_partial_copy_generic_from_user)
  26910. +
  26911. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  26912. + pushl_cfi %gs
  26913. + popl_cfi %ds
  26914. +#endif
  26915. +
  26916. +ENTRY(csum_partial_copy_generic)
  26917. subl $4,%esp
  26918. CFI_ADJUST_CFA_OFFSET 4
  26919. pushl_cfi %edi
  26920. @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
  26921. jmp 4f
  26922. SRC(1: movw (%esi), %bx )
  26923. addl $2, %esi
  26924. -DST( movw %bx, (%edi) )
  26925. +DST( movw %bx, %es:(%edi) )
  26926. addl $2, %edi
  26927. addw %bx, %ax
  26928. adcl $0, %eax
  26929. @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
  26930. SRC(1: movl (%esi), %ebx )
  26931. SRC( movl 4(%esi), %edx )
  26932. adcl %ebx, %eax
  26933. -DST( movl %ebx, (%edi) )
  26934. +DST( movl %ebx, %es:(%edi) )
  26935. adcl %edx, %eax
  26936. -DST( movl %edx, 4(%edi) )
  26937. +DST( movl %edx, %es:4(%edi) )
  26938. SRC( movl 8(%esi), %ebx )
  26939. SRC( movl 12(%esi), %edx )
  26940. adcl %ebx, %eax
  26941. -DST( movl %ebx, 8(%edi) )
  26942. +DST( movl %ebx, %es:8(%edi) )
  26943. adcl %edx, %eax
  26944. -DST( movl %edx, 12(%edi) )
  26945. +DST( movl %edx, %es:12(%edi) )
  26946. SRC( movl 16(%esi), %ebx )
  26947. SRC( movl 20(%esi), %edx )
  26948. adcl %ebx, %eax
  26949. -DST( movl %ebx, 16(%edi) )
  26950. +DST( movl %ebx, %es:16(%edi) )
  26951. adcl %edx, %eax
  26952. -DST( movl %edx, 20(%edi) )
  26953. +DST( movl %edx, %es:20(%edi) )
  26954. SRC( movl 24(%esi), %ebx )
  26955. SRC( movl 28(%esi), %edx )
  26956. adcl %ebx, %eax
  26957. -DST( movl %ebx, 24(%edi) )
  26958. +DST( movl %ebx, %es:24(%edi) )
  26959. adcl %edx, %eax
  26960. -DST( movl %edx, 28(%edi) )
  26961. +DST( movl %edx, %es:28(%edi) )
  26962. lea 32(%esi), %esi
  26963. lea 32(%edi), %edi
  26964. @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
  26965. shrl $2, %edx # This clears CF
  26966. SRC(3: movl (%esi), %ebx )
  26967. adcl %ebx, %eax
  26968. -DST( movl %ebx, (%edi) )
  26969. +DST( movl %ebx, %es:(%edi) )
  26970. lea 4(%esi), %esi
  26971. lea 4(%edi), %edi
  26972. dec %edx
  26973. @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
  26974. jb 5f
  26975. SRC( movw (%esi), %cx )
  26976. leal 2(%esi), %esi
  26977. -DST( movw %cx, (%edi) )
  26978. +DST( movw %cx, %es:(%edi) )
  26979. leal 2(%edi), %edi
  26980. je 6f
  26981. shll $16,%ecx
  26982. SRC(5: movb (%esi), %cl )
  26983. -DST( movb %cl, (%edi) )
  26984. +DST( movb %cl, %es:(%edi) )
  26985. 6: addl %ecx, %eax
  26986. adcl $0, %eax
  26987. 7:
  26988. @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
  26989. 6001:
  26990. movl ARGBASE+20(%esp), %ebx # src_err_ptr
  26991. - movl $-EFAULT, (%ebx)
  26992. + movl $-EFAULT, %ss:(%ebx)
  26993. # zero the complete destination - computing the rest
  26994. # is too much work
  26995. @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
  26996. 6002:
  26997. movl ARGBASE+24(%esp), %ebx # dst_err_ptr
  26998. - movl $-EFAULT,(%ebx)
  26999. + movl $-EFAULT,%ss:(%ebx)
  27000. jmp 5000b
  27001. .previous
  27002. + pushl_cfi %ss
  27003. + popl_cfi %ds
  27004. + pushl_cfi %ss
  27005. + popl_cfi %es
  27006. popl_cfi %ebx
  27007. CFI_RESTORE ebx
  27008. popl_cfi %esi
  27009. @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
  27010. popl_cfi %ecx # equivalent to addl $4,%esp
  27011. ret
  27012. CFI_ENDPROC
  27013. -ENDPROC(csum_partial_copy_generic)
  27014. +ENDPROC(csum_partial_copy_generic_to_user)
  27015. #else
  27016. /* Version for PentiumII/PPro */
  27017. #define ROUND1(x) \
  27018. + nop; nop; nop; \
  27019. SRC(movl x(%esi), %ebx ) ; \
  27020. addl %ebx, %eax ; \
  27021. - DST(movl %ebx, x(%edi) ) ;
  27022. + DST(movl %ebx, %es:x(%edi)) ;
  27023. #define ROUND(x) \
  27024. + nop; nop; nop; \
  27025. SRC(movl x(%esi), %ebx ) ; \
  27026. adcl %ebx, %eax ; \
  27027. - DST(movl %ebx, x(%edi) ) ;
  27028. + DST(movl %ebx, %es:x(%edi)) ;
  27029. #define ARGBASE 12
  27030. -
  27031. -ENTRY(csum_partial_copy_generic)
  27032. +
  27033. +ENTRY(csum_partial_copy_generic_to_user)
  27034. CFI_STARTPROC
  27035. +
  27036. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  27037. + pushl_cfi %gs
  27038. + popl_cfi %es
  27039. + jmp csum_partial_copy_generic
  27040. +#endif
  27041. +
  27042. +ENTRY(csum_partial_copy_generic_from_user)
  27043. +
  27044. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  27045. + pushl_cfi %gs
  27046. + popl_cfi %ds
  27047. +#endif
  27048. +
  27049. +ENTRY(csum_partial_copy_generic)
  27050. pushl_cfi %ebx
  27051. CFI_REL_OFFSET ebx, 0
  27052. pushl_cfi %edi
  27053. @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
  27054. subl %ebx, %edi
  27055. lea -1(%esi),%edx
  27056. andl $-32,%edx
  27057. - lea 3f(%ebx,%ebx), %ebx
  27058. + lea 3f(%ebx,%ebx,2), %ebx
  27059. testl %esi, %esi
  27060. jmp *%ebx
  27061. 1: addl $64,%esi
  27062. @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
  27063. jb 5f
  27064. SRC( movw (%esi), %dx )
  27065. leal 2(%esi), %esi
  27066. -DST( movw %dx, (%edi) )
  27067. +DST( movw %dx, %es:(%edi) )
  27068. leal 2(%edi), %edi
  27069. je 6f
  27070. shll $16,%edx
  27071. 5:
  27072. SRC( movb (%esi), %dl )
  27073. -DST( movb %dl, (%edi) )
  27074. +DST( movb %dl, %es:(%edi) )
  27075. 6: addl %edx, %eax
  27076. adcl $0, %eax
  27077. 7:
  27078. .section .fixup, "ax"
  27079. 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
  27080. - movl $-EFAULT, (%ebx)
  27081. + movl $-EFAULT, %ss:(%ebx)
  27082. # zero the complete destination (computing the rest is too much work)
  27083. movl ARGBASE+8(%esp),%edi # dst
  27084. movl ARGBASE+12(%esp),%ecx # len
  27085. @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
  27086. rep; stosb
  27087. jmp 7b
  27088. 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
  27089. - movl $-EFAULT, (%ebx)
  27090. + movl $-EFAULT, %ss:(%ebx)
  27091. jmp 7b
  27092. .previous
  27093. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  27094. + pushl_cfi %ss
  27095. + popl_cfi %ds
  27096. + pushl_cfi %ss
  27097. + popl_cfi %es
  27098. +#endif
  27099. +
  27100. popl_cfi %esi
  27101. CFI_RESTORE esi
  27102. popl_cfi %edi
  27103. @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
  27104. CFI_RESTORE ebx
  27105. ret
  27106. CFI_ENDPROC
  27107. -ENDPROC(csum_partial_copy_generic)
  27108. +ENDPROC(csum_partial_copy_generic_to_user)
  27109. #undef ROUND
  27110. #undef ROUND1
  27111. diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
  27112. index f2145cf..cea889d 100644
  27113. --- a/arch/x86/lib/clear_page_64.S
  27114. +++ b/arch/x86/lib/clear_page_64.S
  27115. @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
  27116. movl $4096/8,%ecx
  27117. xorl %eax,%eax
  27118. rep stosq
  27119. + pax_force_retaddr
  27120. ret
  27121. CFI_ENDPROC
  27122. ENDPROC(clear_page_c)
  27123. @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
  27124. movl $4096,%ecx
  27125. xorl %eax,%eax
  27126. rep stosb
  27127. + pax_force_retaddr
  27128. ret
  27129. CFI_ENDPROC
  27130. ENDPROC(clear_page_c_e)
  27131. @@ -43,6 +45,7 @@ ENTRY(clear_page)
  27132. leaq 64(%rdi),%rdi
  27133. jnz .Lloop
  27134. nop
  27135. + pax_force_retaddr
  27136. ret
  27137. CFI_ENDPROC
  27138. .Lclear_page_end:
  27139. @@ -58,7 +61,7 @@ ENDPROC(clear_page)
  27140. #include <asm/cpufeature.h>
  27141. - .section .altinstr_replacement,"ax"
  27142. + .section .altinstr_replacement,"a"
  27143. 1: .byte 0xeb /* jmp <disp8> */
  27144. .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
  27145. 2: .byte 0xeb /* jmp <disp8> */
  27146. diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
  27147. index 1e572c5..2a162cd 100644
  27148. --- a/arch/x86/lib/cmpxchg16b_emu.S
  27149. +++ b/arch/x86/lib/cmpxchg16b_emu.S
  27150. @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
  27151. popf
  27152. mov $1, %al
  27153. + pax_force_retaddr
  27154. ret
  27155. not_same:
  27156. popf
  27157. xor %al,%al
  27158. + pax_force_retaddr
  27159. ret
  27160. CFI_ENDPROC
  27161. diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
  27162. index 176cca6..e0d658e 100644
  27163. --- a/arch/x86/lib/copy_page_64.S
  27164. +++ b/arch/x86/lib/copy_page_64.S
  27165. @@ -9,6 +9,7 @@ copy_page_rep:
  27166. CFI_STARTPROC
  27167. movl $4096/8, %ecx
  27168. rep movsq
  27169. + pax_force_retaddr
  27170. ret
  27171. CFI_ENDPROC
  27172. ENDPROC(copy_page_rep)
  27173. @@ -24,8 +25,8 @@ ENTRY(copy_page)
  27174. CFI_ADJUST_CFA_OFFSET 2*8
  27175. movq %rbx, (%rsp)
  27176. CFI_REL_OFFSET rbx, 0
  27177. - movq %r12, 1*8(%rsp)
  27178. - CFI_REL_OFFSET r12, 1*8
  27179. + movq %r13, 1*8(%rsp)
  27180. + CFI_REL_OFFSET r13, 1*8
  27181. movl $(4096/64)-5, %ecx
  27182. .p2align 4
  27183. @@ -38,7 +39,7 @@ ENTRY(copy_page)
  27184. movq 0x8*4(%rsi), %r9
  27185. movq 0x8*5(%rsi), %r10
  27186. movq 0x8*6(%rsi), %r11
  27187. - movq 0x8*7(%rsi), %r12
  27188. + movq 0x8*7(%rsi), %r13
  27189. prefetcht0 5*64(%rsi)
  27190. @@ -49,7 +50,7 @@ ENTRY(copy_page)
  27191. movq %r9, 0x8*4(%rdi)
  27192. movq %r10, 0x8*5(%rdi)
  27193. movq %r11, 0x8*6(%rdi)
  27194. - movq %r12, 0x8*7(%rdi)
  27195. + movq %r13, 0x8*7(%rdi)
  27196. leaq 64 (%rsi), %rsi
  27197. leaq 64 (%rdi), %rdi
  27198. @@ -68,7 +69,7 @@ ENTRY(copy_page)
  27199. movq 0x8*4(%rsi), %r9
  27200. movq 0x8*5(%rsi), %r10
  27201. movq 0x8*6(%rsi), %r11
  27202. - movq 0x8*7(%rsi), %r12
  27203. + movq 0x8*7(%rsi), %r13
  27204. movq %rax, 0x8*0(%rdi)
  27205. movq %rbx, 0x8*1(%rdi)
  27206. @@ -77,7 +78,7 @@ ENTRY(copy_page)
  27207. movq %r9, 0x8*4(%rdi)
  27208. movq %r10, 0x8*5(%rdi)
  27209. movq %r11, 0x8*6(%rdi)
  27210. - movq %r12, 0x8*7(%rdi)
  27211. + movq %r13, 0x8*7(%rdi)
  27212. leaq 64(%rdi), %rdi
  27213. leaq 64(%rsi), %rsi
  27214. @@ -85,10 +86,11 @@ ENTRY(copy_page)
  27215. movq (%rsp), %rbx
  27216. CFI_RESTORE rbx
  27217. - movq 1*8(%rsp), %r12
  27218. - CFI_RESTORE r12
  27219. + movq 1*8(%rsp), %r13
  27220. + CFI_RESTORE r13
  27221. addq $2*8, %rsp
  27222. CFI_ADJUST_CFA_OFFSET -2*8
  27223. + pax_force_retaddr
  27224. ret
  27225. .Lcopy_page_end:
  27226. CFI_ENDPROC
  27227. @@ -99,7 +101,7 @@ ENDPROC(copy_page)
  27228. #include <asm/cpufeature.h>
  27229. - .section .altinstr_replacement,"ax"
  27230. + .section .altinstr_replacement,"a"
  27231. 1: .byte 0xeb /* jmp <disp8> */
  27232. .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
  27233. 2:
  27234. diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
  27235. index dee945d..a84067b 100644
  27236. --- a/arch/x86/lib/copy_user_64.S
  27237. +++ b/arch/x86/lib/copy_user_64.S
  27238. @@ -18,31 +18,7 @@
  27239. #include <asm/alternative-asm.h>
  27240. #include <asm/asm.h>
  27241. #include <asm/smap.h>
  27242. -
  27243. -/*
  27244. - * By placing feature2 after feature1 in altinstructions section, we logically
  27245. - * implement:
  27246. - * If CPU has feature2, jmp to alt2 is used
  27247. - * else if CPU has feature1, jmp to alt1 is used
  27248. - * else jmp to orig is used.
  27249. - */
  27250. - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
  27251. -0:
  27252. - .byte 0xe9 /* 32bit jump */
  27253. - .long \orig-1f /* by default jump to orig */
  27254. -1:
  27255. - .section .altinstr_replacement,"ax"
  27256. -2: .byte 0xe9 /* near jump with 32bit immediate */
  27257. - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
  27258. -3: .byte 0xe9 /* near jump with 32bit immediate */
  27259. - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
  27260. - .previous
  27261. -
  27262. - .section .altinstructions,"a"
  27263. - altinstruction_entry 0b,2b,\feature1,5,5
  27264. - altinstruction_entry 0b,3b,\feature2,5,5
  27265. - .previous
  27266. - .endm
  27267. +#include <asm/pgtable.h>
  27268. .macro ALIGN_DESTINATION
  27269. #ifdef FIX_ALIGNMENT
  27270. @@ -70,52 +46,6 @@
  27271. #endif
  27272. .endm
  27273. -/* Standard copy_to_user with segment limit checking */
  27274. -ENTRY(_copy_to_user)
  27275. - CFI_STARTPROC
  27276. - GET_THREAD_INFO(%rax)
  27277. - movq %rdi,%rcx
  27278. - addq %rdx,%rcx
  27279. - jc bad_to_user
  27280. - cmpq TI_addr_limit(%rax),%rcx
  27281. - ja bad_to_user
  27282. - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
  27283. - copy_user_generic_unrolled,copy_user_generic_string, \
  27284. - copy_user_enhanced_fast_string
  27285. - CFI_ENDPROC
  27286. -ENDPROC(_copy_to_user)
  27287. -
  27288. -/* Standard copy_from_user with segment limit checking */
  27289. -ENTRY(_copy_from_user)
  27290. - CFI_STARTPROC
  27291. - GET_THREAD_INFO(%rax)
  27292. - movq %rsi,%rcx
  27293. - addq %rdx,%rcx
  27294. - jc bad_from_user
  27295. - cmpq TI_addr_limit(%rax),%rcx
  27296. - ja bad_from_user
  27297. - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
  27298. - copy_user_generic_unrolled,copy_user_generic_string, \
  27299. - copy_user_enhanced_fast_string
  27300. - CFI_ENDPROC
  27301. -ENDPROC(_copy_from_user)
  27302. -
  27303. - .section .fixup,"ax"
  27304. - /* must zero dest */
  27305. -ENTRY(bad_from_user)
  27306. -bad_from_user:
  27307. - CFI_STARTPROC
  27308. - movl %edx,%ecx
  27309. - xorl %eax,%eax
  27310. - rep
  27311. - stosb
  27312. -bad_to_user:
  27313. - movl %edx,%eax
  27314. - ret
  27315. - CFI_ENDPROC
  27316. -ENDPROC(bad_from_user)
  27317. - .previous
  27318. -
  27319. /*
  27320. * copy_user_generic_unrolled - memory copy with exception handling.
  27321. * This version is for CPUs like P4 that don't have efficient micro
  27322. @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
  27323. */
  27324. ENTRY(copy_user_generic_unrolled)
  27325. CFI_STARTPROC
  27326. + ASM_PAX_OPEN_USERLAND
  27327. ASM_STAC
  27328. cmpl $8,%edx
  27329. jb 20f /* less then 8 bytes, go to byte copy loop */
  27330. @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
  27331. jnz 21b
  27332. 23: xor %eax,%eax
  27333. ASM_CLAC
  27334. + ASM_PAX_CLOSE_USERLAND
  27335. + pax_force_retaddr
  27336. ret
  27337. .section .fixup,"ax"
  27338. @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
  27339. */
  27340. ENTRY(copy_user_generic_string)
  27341. CFI_STARTPROC
  27342. + ASM_PAX_OPEN_USERLAND
  27343. ASM_STAC
  27344. cmpl $8,%edx
  27345. jb 2f /* less than 8 bytes, go to byte copy loop */
  27346. @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
  27347. movsb
  27348. xorl %eax,%eax
  27349. ASM_CLAC
  27350. + ASM_PAX_CLOSE_USERLAND
  27351. + pax_force_retaddr
  27352. ret
  27353. .section .fixup,"ax"
  27354. @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
  27355. */
  27356. ENTRY(copy_user_enhanced_fast_string)
  27357. CFI_STARTPROC
  27358. + ASM_PAX_OPEN_USERLAND
  27359. ASM_STAC
  27360. movl %edx,%ecx
  27361. 1: rep
  27362. movsb
  27363. xorl %eax,%eax
  27364. ASM_CLAC
  27365. + ASM_PAX_CLOSE_USERLAND
  27366. + pax_force_retaddr
  27367. ret
  27368. .section .fixup,"ax"
  27369. diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
  27370. index 6a4f43c..c70fb52 100644
  27371. --- a/arch/x86/lib/copy_user_nocache_64.S
  27372. +++ b/arch/x86/lib/copy_user_nocache_64.S
  27373. @@ -8,6 +8,7 @@
  27374. #include <linux/linkage.h>
  27375. #include <asm/dwarf2.h>
  27376. +#include <asm/alternative-asm.h>
  27377. #define FIX_ALIGNMENT 1
  27378. @@ -16,6 +17,7 @@
  27379. #include <asm/thread_info.h>
  27380. #include <asm/asm.h>
  27381. #include <asm/smap.h>
  27382. +#include <asm/pgtable.h>
  27383. .macro ALIGN_DESTINATION
  27384. #ifdef FIX_ALIGNMENT
  27385. @@ -49,6 +51,16 @@
  27386. */
  27387. ENTRY(__copy_user_nocache)
  27388. CFI_STARTPROC
  27389. +
  27390. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  27391. + mov pax_user_shadow_base,%rcx
  27392. + cmp %rcx,%rsi
  27393. + jae 1f
  27394. + add %rcx,%rsi
  27395. +1:
  27396. +#endif
  27397. +
  27398. + ASM_PAX_OPEN_USERLAND
  27399. ASM_STAC
  27400. cmpl $8,%edx
  27401. jb 20f /* less then 8 bytes, go to byte copy loop */
  27402. @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
  27403. jnz 21b
  27404. 23: xorl %eax,%eax
  27405. ASM_CLAC
  27406. + ASM_PAX_CLOSE_USERLAND
  27407. sfence
  27408. + pax_force_retaddr
  27409. ret
  27410. .section .fixup,"ax"
  27411. diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
  27412. index 2419d5f..fe52d0e 100644
  27413. --- a/arch/x86/lib/csum-copy_64.S
  27414. +++ b/arch/x86/lib/csum-copy_64.S
  27415. @@ -9,6 +9,7 @@
  27416. #include <asm/dwarf2.h>
  27417. #include <asm/errno.h>
  27418. #include <asm/asm.h>
  27419. +#include <asm/alternative-asm.h>
  27420. /*
  27421. * Checksum copy with exception handling.
  27422. @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
  27423. CFI_ADJUST_CFA_OFFSET 7*8
  27424. movq %rbx, 2*8(%rsp)
  27425. CFI_REL_OFFSET rbx, 2*8
  27426. - movq %r12, 3*8(%rsp)
  27427. - CFI_REL_OFFSET r12, 3*8
  27428. + movq %r15, 3*8(%rsp)
  27429. + CFI_REL_OFFSET r15, 3*8
  27430. movq %r14, 4*8(%rsp)
  27431. CFI_REL_OFFSET r14, 4*8
  27432. movq %r13, 5*8(%rsp)
  27433. @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
  27434. movl %edx, %ecx
  27435. xorl %r9d, %r9d
  27436. - movq %rcx, %r12
  27437. + movq %rcx, %r15
  27438. - shrq $6, %r12
  27439. + shrq $6, %r15
  27440. jz .Lhandle_tail /* < 64 */
  27441. clc
  27442. /* main loop. clear in 64 byte blocks */
  27443. /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
  27444. - /* r11: temp3, rdx: temp4, r12 loopcnt */
  27445. + /* r11: temp3, rdx: temp4, r15 loopcnt */
  27446. /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
  27447. .p2align 4
  27448. .Lloop:
  27449. @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
  27450. adcq %r14, %rax
  27451. adcq %r13, %rax
  27452. - decl %r12d
  27453. + decl %r15d
  27454. dest
  27455. movq %rbx, (%rsi)
  27456. @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
  27457. .Lende:
  27458. movq 2*8(%rsp), %rbx
  27459. CFI_RESTORE rbx
  27460. - movq 3*8(%rsp), %r12
  27461. - CFI_RESTORE r12
  27462. + movq 3*8(%rsp), %r15
  27463. + CFI_RESTORE r15
  27464. movq 4*8(%rsp), %r14
  27465. CFI_RESTORE r14
  27466. movq 5*8(%rsp), %r13
  27467. @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
  27468. CFI_RESTORE rbp
  27469. addq $7*8, %rsp
  27470. CFI_ADJUST_CFA_OFFSET -7*8
  27471. + pax_force_retaddr
  27472. ret
  27473. CFI_RESTORE_STATE
  27474. diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
  27475. index 7609e0e..b449b98 100644
  27476. --- a/arch/x86/lib/csum-wrappers_64.c
  27477. +++ b/arch/x86/lib/csum-wrappers_64.c
  27478. @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
  27479. len -= 2;
  27480. }
  27481. }
  27482. + pax_open_userland();
  27483. stac();
  27484. - isum = csum_partial_copy_generic((__force const void *)src,
  27485. + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
  27486. dst, len, isum, errp, NULL);
  27487. clac();
  27488. + pax_close_userland();
  27489. if (unlikely(*errp))
  27490. goto out_err;
  27491. @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
  27492. }
  27493. *errp = 0;
  27494. + pax_open_userland();
  27495. stac();
  27496. - ret = csum_partial_copy_generic(src, (void __force *)dst,
  27497. + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
  27498. len, isum, NULL, errp);
  27499. clac();
  27500. + pax_close_userland();
  27501. return ret;
  27502. }
  27503. EXPORT_SYMBOL(csum_partial_copy_to_user);
  27504. diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
  27505. index a451235..1daa956 100644
  27506. --- a/arch/x86/lib/getuser.S
  27507. +++ b/arch/x86/lib/getuser.S
  27508. @@ -33,17 +33,40 @@
  27509. #include <asm/thread_info.h>
  27510. #include <asm/asm.h>
  27511. #include <asm/smap.h>
  27512. +#include <asm/segment.h>
  27513. +#include <asm/pgtable.h>
  27514. +#include <asm/alternative-asm.h>
  27515. +
  27516. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
  27517. +#define __copyuser_seg gs;
  27518. +#else
  27519. +#define __copyuser_seg
  27520. +#endif
  27521. .text
  27522. ENTRY(__get_user_1)
  27523. CFI_STARTPROC
  27524. +
  27525. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  27526. GET_THREAD_INFO(%_ASM_DX)
  27527. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  27528. jae bad_get_user
  27529. ASM_STAC
  27530. -1: movzbl (%_ASM_AX),%edx
  27531. +
  27532. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  27533. + mov pax_user_shadow_base,%_ASM_DX
  27534. + cmp %_ASM_DX,%_ASM_AX
  27535. + jae 1234f
  27536. + add %_ASM_DX,%_ASM_AX
  27537. +1234:
  27538. +#endif
  27539. +
  27540. +#endif
  27541. +
  27542. +1: __copyuser_seg movzbl (%_ASM_AX),%edx
  27543. xor %eax,%eax
  27544. ASM_CLAC
  27545. + pax_force_retaddr
  27546. ret
  27547. CFI_ENDPROC
  27548. ENDPROC(__get_user_1)
  27549. @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
  27550. ENTRY(__get_user_2)
  27551. CFI_STARTPROC
  27552. add $1,%_ASM_AX
  27553. +
  27554. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  27555. jc bad_get_user
  27556. GET_THREAD_INFO(%_ASM_DX)
  27557. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  27558. jae bad_get_user
  27559. ASM_STAC
  27560. -2: movzwl -1(%_ASM_AX),%edx
  27561. +
  27562. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  27563. + mov pax_user_shadow_base,%_ASM_DX
  27564. + cmp %_ASM_DX,%_ASM_AX
  27565. + jae 1234f
  27566. + add %_ASM_DX,%_ASM_AX
  27567. +1234:
  27568. +#endif
  27569. +
  27570. +#endif
  27571. +
  27572. +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
  27573. xor %eax,%eax
  27574. ASM_CLAC
  27575. + pax_force_retaddr
  27576. ret
  27577. CFI_ENDPROC
  27578. ENDPROC(__get_user_2)
  27579. @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
  27580. ENTRY(__get_user_4)
  27581. CFI_STARTPROC
  27582. add $3,%_ASM_AX
  27583. +
  27584. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  27585. jc bad_get_user
  27586. GET_THREAD_INFO(%_ASM_DX)
  27587. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  27588. jae bad_get_user
  27589. ASM_STAC
  27590. -3: movl -3(%_ASM_AX),%edx
  27591. +
  27592. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  27593. + mov pax_user_shadow_base,%_ASM_DX
  27594. + cmp %_ASM_DX,%_ASM_AX
  27595. + jae 1234f
  27596. + add %_ASM_DX,%_ASM_AX
  27597. +1234:
  27598. +#endif
  27599. +
  27600. +#endif
  27601. +
  27602. +3: __copyuser_seg movl -3(%_ASM_AX),%edx
  27603. xor %eax,%eax
  27604. ASM_CLAC
  27605. + pax_force_retaddr
  27606. ret
  27607. CFI_ENDPROC
  27608. ENDPROC(__get_user_4)
  27609. @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
  27610. GET_THREAD_INFO(%_ASM_DX)
  27611. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  27612. jae bad_get_user
  27613. +
  27614. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  27615. + mov pax_user_shadow_base,%_ASM_DX
  27616. + cmp %_ASM_DX,%_ASM_AX
  27617. + jae 1234f
  27618. + add %_ASM_DX,%_ASM_AX
  27619. +1234:
  27620. +#endif
  27621. +
  27622. ASM_STAC
  27623. 4: movq -7(%_ASM_AX),%rdx
  27624. xor %eax,%eax
  27625. ASM_CLAC
  27626. + pax_force_retaddr
  27627. ret
  27628. #else
  27629. add $7,%_ASM_AX
  27630. @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
  27631. cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
  27632. jae bad_get_user_8
  27633. ASM_STAC
  27634. -4: movl -7(%_ASM_AX),%edx
  27635. -5: movl -3(%_ASM_AX),%ecx
  27636. +4: __copyuser_seg movl -7(%_ASM_AX),%edx
  27637. +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
  27638. xor %eax,%eax
  27639. ASM_CLAC
  27640. + pax_force_retaddr
  27641. ret
  27642. #endif
  27643. CFI_ENDPROC
  27644. @@ -113,6 +175,7 @@ bad_get_user:
  27645. xor %edx,%edx
  27646. mov $(-EFAULT),%_ASM_AX
  27647. ASM_CLAC
  27648. + pax_force_retaddr
  27649. ret
  27650. CFI_ENDPROC
  27651. END(bad_get_user)
  27652. @@ -124,6 +187,7 @@ bad_get_user_8:
  27653. xor %ecx,%ecx
  27654. mov $(-EFAULT),%_ASM_AX
  27655. ASM_CLAC
  27656. + pax_force_retaddr
  27657. ret
  27658. CFI_ENDPROC
  27659. END(bad_get_user_8)
  27660. diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
  27661. index 54fcffe..7be149e 100644
  27662. --- a/arch/x86/lib/insn.c
  27663. +++ b/arch/x86/lib/insn.c
  27664. @@ -20,8 +20,10 @@
  27665. #ifdef __KERNEL__
  27666. #include <linux/string.h>
  27667. +#include <asm/pgtable_types.h>
  27668. #else
  27669. #include <string.h>
  27670. +#define ktla_ktva(addr) addr
  27671. #endif
  27672. #include <asm/inat.h>
  27673. #include <asm/insn.h>
  27674. @@ -53,8 +55,8 @@
  27675. void insn_init(struct insn *insn, const void *kaddr, int x86_64)
  27676. {
  27677. memset(insn, 0, sizeof(*insn));
  27678. - insn->kaddr = kaddr;
  27679. - insn->next_byte = kaddr;
  27680. + insn->kaddr = ktla_ktva(kaddr);
  27681. + insn->next_byte = ktla_ktva(kaddr);
  27682. insn->x86_64 = x86_64 ? 1 : 0;
  27683. insn->opnd_bytes = 4;
  27684. if (x86_64)
  27685. diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
  27686. index 05a95e7..326f2fa 100644
  27687. --- a/arch/x86/lib/iomap_copy_64.S
  27688. +++ b/arch/x86/lib/iomap_copy_64.S
  27689. @@ -17,6 +17,7 @@
  27690. #include <linux/linkage.h>
  27691. #include <asm/dwarf2.h>
  27692. +#include <asm/alternative-asm.h>
  27693. /*
  27694. * override generic version in lib/iomap_copy.c
  27695. @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
  27696. CFI_STARTPROC
  27697. movl %edx,%ecx
  27698. rep movsd
  27699. + pax_force_retaddr
  27700. ret
  27701. CFI_ENDPROC
  27702. ENDPROC(__iowrite32_copy)
  27703. diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
  27704. index 56313a3..0db417e 100644
  27705. --- a/arch/x86/lib/memcpy_64.S
  27706. +++ b/arch/x86/lib/memcpy_64.S
  27707. @@ -24,7 +24,7 @@
  27708. * This gets patched over the unrolled variant (below) via the
  27709. * alternative instructions framework:
  27710. */
  27711. - .section .altinstr_replacement, "ax", @progbits
  27712. + .section .altinstr_replacement, "a", @progbits
  27713. .Lmemcpy_c:
  27714. movq %rdi, %rax
  27715. movq %rdx, %rcx
  27716. @@ -33,6 +33,7 @@
  27717. rep movsq
  27718. movl %edx, %ecx
  27719. rep movsb
  27720. + pax_force_retaddr
  27721. ret
  27722. .Lmemcpy_e:
  27723. .previous
  27724. @@ -44,11 +45,12 @@
  27725. * This gets patched over the unrolled variant (below) via the
  27726. * alternative instructions framework:
  27727. */
  27728. - .section .altinstr_replacement, "ax", @progbits
  27729. + .section .altinstr_replacement, "a", @progbits
  27730. .Lmemcpy_c_e:
  27731. movq %rdi, %rax
  27732. movq %rdx, %rcx
  27733. rep movsb
  27734. + pax_force_retaddr
  27735. ret
  27736. .Lmemcpy_e_e:
  27737. .previous
  27738. @@ -136,6 +138,7 @@ ENTRY(memcpy)
  27739. movq %r9, 1*8(%rdi)
  27740. movq %r10, -2*8(%rdi, %rdx)
  27741. movq %r11, -1*8(%rdi, %rdx)
  27742. + pax_force_retaddr
  27743. retq
  27744. .p2align 4
  27745. .Lless_16bytes:
  27746. @@ -148,6 +151,7 @@ ENTRY(memcpy)
  27747. movq -1*8(%rsi, %rdx), %r9
  27748. movq %r8, 0*8(%rdi)
  27749. movq %r9, -1*8(%rdi, %rdx)
  27750. + pax_force_retaddr
  27751. retq
  27752. .p2align 4
  27753. .Lless_8bytes:
  27754. @@ -161,6 +165,7 @@ ENTRY(memcpy)
  27755. movl -4(%rsi, %rdx), %r8d
  27756. movl %ecx, (%rdi)
  27757. movl %r8d, -4(%rdi, %rdx)
  27758. + pax_force_retaddr
  27759. retq
  27760. .p2align 4
  27761. .Lless_3bytes:
  27762. @@ -179,6 +184,7 @@ ENTRY(memcpy)
  27763. movb %cl, (%rdi)
  27764. .Lend:
  27765. + pax_force_retaddr
  27766. retq
  27767. CFI_ENDPROC
  27768. ENDPROC(memcpy)
  27769. diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
  27770. index 65268a6..dd1de11 100644
  27771. --- a/arch/x86/lib/memmove_64.S
  27772. +++ b/arch/x86/lib/memmove_64.S
  27773. @@ -202,14 +202,16 @@ ENTRY(memmove)
  27774. movb (%rsi), %r11b
  27775. movb %r11b, (%rdi)
  27776. 13:
  27777. + pax_force_retaddr
  27778. retq
  27779. CFI_ENDPROC
  27780. - .section .altinstr_replacement,"ax"
  27781. + .section .altinstr_replacement,"a"
  27782. .Lmemmove_begin_forward_efs:
  27783. /* Forward moving data. */
  27784. movq %rdx, %rcx
  27785. rep movsb
  27786. + pax_force_retaddr
  27787. retq
  27788. .Lmemmove_end_forward_efs:
  27789. .previous
  27790. diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
  27791. index 2dcb380..2eb79fe 100644
  27792. --- a/arch/x86/lib/memset_64.S
  27793. +++ b/arch/x86/lib/memset_64.S
  27794. @@ -16,7 +16,7 @@
  27795. *
  27796. * rax original destination
  27797. */
  27798. - .section .altinstr_replacement, "ax", @progbits
  27799. + .section .altinstr_replacement, "a", @progbits
  27800. .Lmemset_c:
  27801. movq %rdi,%r9
  27802. movq %rdx,%rcx
  27803. @@ -30,6 +30,7 @@
  27804. movl %edx,%ecx
  27805. rep stosb
  27806. movq %r9,%rax
  27807. + pax_force_retaddr
  27808. ret
  27809. .Lmemset_e:
  27810. .previous
  27811. @@ -45,13 +46,14 @@
  27812. *
  27813. * rax original destination
  27814. */
  27815. - .section .altinstr_replacement, "ax", @progbits
  27816. + .section .altinstr_replacement, "a", @progbits
  27817. .Lmemset_c_e:
  27818. movq %rdi,%r9
  27819. movb %sil,%al
  27820. movq %rdx,%rcx
  27821. rep stosb
  27822. movq %r9,%rax
  27823. + pax_force_retaddr
  27824. ret
  27825. .Lmemset_e_e:
  27826. .previous
  27827. @@ -118,6 +120,7 @@ ENTRY(__memset)
  27828. .Lende:
  27829. movq %r10,%rax
  27830. + pax_force_retaddr
  27831. ret
  27832. CFI_RESTORE_STATE
  27833. diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
  27834. index c9f2d9b..e7fd2c0 100644
  27835. --- a/arch/x86/lib/mmx_32.c
  27836. +++ b/arch/x86/lib/mmx_32.c
  27837. @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
  27838. {
  27839. void *p;
  27840. int i;
  27841. + unsigned long cr0;
  27842. if (unlikely(in_interrupt()))
  27843. return __memcpy(to, from, len);
  27844. @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
  27845. kernel_fpu_begin();
  27846. __asm__ __volatile__ (
  27847. - "1: prefetch (%0)\n" /* This set is 28 bytes */
  27848. - " prefetch 64(%0)\n"
  27849. - " prefetch 128(%0)\n"
  27850. - " prefetch 192(%0)\n"
  27851. - " prefetch 256(%0)\n"
  27852. + "1: prefetch (%1)\n" /* This set is 28 bytes */
  27853. + " prefetch 64(%1)\n"
  27854. + " prefetch 128(%1)\n"
  27855. + " prefetch 192(%1)\n"
  27856. + " prefetch 256(%1)\n"
  27857. "2: \n"
  27858. ".section .fixup, \"ax\"\n"
  27859. - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
  27860. + "3: \n"
  27861. +
  27862. +#ifdef CONFIG_PAX_KERNEXEC
  27863. + " movl %%cr0, %0\n"
  27864. + " movl %0, %%eax\n"
  27865. + " andl $0xFFFEFFFF, %%eax\n"
  27866. + " movl %%eax, %%cr0\n"
  27867. +#endif
  27868. +
  27869. + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
  27870. +
  27871. +#ifdef CONFIG_PAX_KERNEXEC
  27872. + " movl %0, %%cr0\n"
  27873. +#endif
  27874. +
  27875. " jmp 2b\n"
  27876. ".previous\n"
  27877. _ASM_EXTABLE(1b, 3b)
  27878. - : : "r" (from));
  27879. + : "=&r" (cr0) : "r" (from) : "ax");
  27880. for ( ; i > 5; i--) {
  27881. __asm__ __volatile__ (
  27882. - "1: prefetch 320(%0)\n"
  27883. - "2: movq (%0), %%mm0\n"
  27884. - " movq 8(%0), %%mm1\n"
  27885. - " movq 16(%0), %%mm2\n"
  27886. - " movq 24(%0), %%mm3\n"
  27887. - " movq %%mm0, (%1)\n"
  27888. - " movq %%mm1, 8(%1)\n"
  27889. - " movq %%mm2, 16(%1)\n"
  27890. - " movq %%mm3, 24(%1)\n"
  27891. - " movq 32(%0), %%mm0\n"
  27892. - " movq 40(%0), %%mm1\n"
  27893. - " movq 48(%0), %%mm2\n"
  27894. - " movq 56(%0), %%mm3\n"
  27895. - " movq %%mm0, 32(%1)\n"
  27896. - " movq %%mm1, 40(%1)\n"
  27897. - " movq %%mm2, 48(%1)\n"
  27898. - " movq %%mm3, 56(%1)\n"
  27899. + "1: prefetch 320(%1)\n"
  27900. + "2: movq (%1), %%mm0\n"
  27901. + " movq 8(%1), %%mm1\n"
  27902. + " movq 16(%1), %%mm2\n"
  27903. + " movq 24(%1), %%mm3\n"
  27904. + " movq %%mm0, (%2)\n"
  27905. + " movq %%mm1, 8(%2)\n"
  27906. + " movq %%mm2, 16(%2)\n"
  27907. + " movq %%mm3, 24(%2)\n"
  27908. + " movq 32(%1), %%mm0\n"
  27909. + " movq 40(%1), %%mm1\n"
  27910. + " movq 48(%1), %%mm2\n"
  27911. + " movq 56(%1), %%mm3\n"
  27912. + " movq %%mm0, 32(%2)\n"
  27913. + " movq %%mm1, 40(%2)\n"
  27914. + " movq %%mm2, 48(%2)\n"
  27915. + " movq %%mm3, 56(%2)\n"
  27916. ".section .fixup, \"ax\"\n"
  27917. - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
  27918. + "3:\n"
  27919. +
  27920. +#ifdef CONFIG_PAX_KERNEXEC
  27921. + " movl %%cr0, %0\n"
  27922. + " movl %0, %%eax\n"
  27923. + " andl $0xFFFEFFFF, %%eax\n"
  27924. + " movl %%eax, %%cr0\n"
  27925. +#endif
  27926. +
  27927. + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
  27928. +
  27929. +#ifdef CONFIG_PAX_KERNEXEC
  27930. + " movl %0, %%cr0\n"
  27931. +#endif
  27932. +
  27933. " jmp 2b\n"
  27934. ".previous\n"
  27935. _ASM_EXTABLE(1b, 3b)
  27936. - : : "r" (from), "r" (to) : "memory");
  27937. + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
  27938. from += 64;
  27939. to += 64;
  27940. @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
  27941. static void fast_copy_page(void *to, void *from)
  27942. {
  27943. int i;
  27944. + unsigned long cr0;
  27945. kernel_fpu_begin();
  27946. @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
  27947. * but that is for later. -AV
  27948. */
  27949. __asm__ __volatile__(
  27950. - "1: prefetch (%0)\n"
  27951. - " prefetch 64(%0)\n"
  27952. - " prefetch 128(%0)\n"
  27953. - " prefetch 192(%0)\n"
  27954. - " prefetch 256(%0)\n"
  27955. + "1: prefetch (%1)\n"
  27956. + " prefetch 64(%1)\n"
  27957. + " prefetch 128(%1)\n"
  27958. + " prefetch 192(%1)\n"
  27959. + " prefetch 256(%1)\n"
  27960. "2: \n"
  27961. ".section .fixup, \"ax\"\n"
  27962. - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
  27963. + "3: \n"
  27964. +
  27965. +#ifdef CONFIG_PAX_KERNEXEC
  27966. + " movl %%cr0, %0\n"
  27967. + " movl %0, %%eax\n"
  27968. + " andl $0xFFFEFFFF, %%eax\n"
  27969. + " movl %%eax, %%cr0\n"
  27970. +#endif
  27971. +
  27972. + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
  27973. +
  27974. +#ifdef CONFIG_PAX_KERNEXEC
  27975. + " movl %0, %%cr0\n"
  27976. +#endif
  27977. +
  27978. " jmp 2b\n"
  27979. ".previous\n"
  27980. - _ASM_EXTABLE(1b, 3b) : : "r" (from));
  27981. + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
  27982. for (i = 0; i < (4096-320)/64; i++) {
  27983. __asm__ __volatile__ (
  27984. - "1: prefetch 320(%0)\n"
  27985. - "2: movq (%0), %%mm0\n"
  27986. - " movntq %%mm0, (%1)\n"
  27987. - " movq 8(%0), %%mm1\n"
  27988. - " movntq %%mm1, 8(%1)\n"
  27989. - " movq 16(%0), %%mm2\n"
  27990. - " movntq %%mm2, 16(%1)\n"
  27991. - " movq 24(%0), %%mm3\n"
  27992. - " movntq %%mm3, 24(%1)\n"
  27993. - " movq 32(%0), %%mm4\n"
  27994. - " movntq %%mm4, 32(%1)\n"
  27995. - " movq 40(%0), %%mm5\n"
  27996. - " movntq %%mm5, 40(%1)\n"
  27997. - " movq 48(%0), %%mm6\n"
  27998. - " movntq %%mm6, 48(%1)\n"
  27999. - " movq 56(%0), %%mm7\n"
  28000. - " movntq %%mm7, 56(%1)\n"
  28001. + "1: prefetch 320(%1)\n"
  28002. + "2: movq (%1), %%mm0\n"
  28003. + " movntq %%mm0, (%2)\n"
  28004. + " movq 8(%1), %%mm1\n"
  28005. + " movntq %%mm1, 8(%2)\n"
  28006. + " movq 16(%1), %%mm2\n"
  28007. + " movntq %%mm2, 16(%2)\n"
  28008. + " movq 24(%1), %%mm3\n"
  28009. + " movntq %%mm3, 24(%2)\n"
  28010. + " movq 32(%1), %%mm4\n"
  28011. + " movntq %%mm4, 32(%2)\n"
  28012. + " movq 40(%1), %%mm5\n"
  28013. + " movntq %%mm5, 40(%2)\n"
  28014. + " movq 48(%1), %%mm6\n"
  28015. + " movntq %%mm6, 48(%2)\n"
  28016. + " movq 56(%1), %%mm7\n"
  28017. + " movntq %%mm7, 56(%2)\n"
  28018. ".section .fixup, \"ax\"\n"
  28019. - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
  28020. + "3:\n"
  28021. +
  28022. +#ifdef CONFIG_PAX_KERNEXEC
  28023. + " movl %%cr0, %0\n"
  28024. + " movl %0, %%eax\n"
  28025. + " andl $0xFFFEFFFF, %%eax\n"
  28026. + " movl %%eax, %%cr0\n"
  28027. +#endif
  28028. +
  28029. + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
  28030. +
  28031. +#ifdef CONFIG_PAX_KERNEXEC
  28032. + " movl %0, %%cr0\n"
  28033. +#endif
  28034. +
  28035. " jmp 2b\n"
  28036. ".previous\n"
  28037. - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
  28038. + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
  28039. from += 64;
  28040. to += 64;
  28041. @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
  28042. static void fast_copy_page(void *to, void *from)
  28043. {
  28044. int i;
  28045. + unsigned long cr0;
  28046. kernel_fpu_begin();
  28047. __asm__ __volatile__ (
  28048. - "1: prefetch (%0)\n"
  28049. - " prefetch 64(%0)\n"
  28050. - " prefetch 128(%0)\n"
  28051. - " prefetch 192(%0)\n"
  28052. - " prefetch 256(%0)\n"
  28053. + "1: prefetch (%1)\n"
  28054. + " prefetch 64(%1)\n"
  28055. + " prefetch 128(%1)\n"
  28056. + " prefetch 192(%1)\n"
  28057. + " prefetch 256(%1)\n"
  28058. "2: \n"
  28059. ".section .fixup, \"ax\"\n"
  28060. - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
  28061. + "3: \n"
  28062. +
  28063. +#ifdef CONFIG_PAX_KERNEXEC
  28064. + " movl %%cr0, %0\n"
  28065. + " movl %0, %%eax\n"
  28066. + " andl $0xFFFEFFFF, %%eax\n"
  28067. + " movl %%eax, %%cr0\n"
  28068. +#endif
  28069. +
  28070. + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
  28071. +
  28072. +#ifdef CONFIG_PAX_KERNEXEC
  28073. + " movl %0, %%cr0\n"
  28074. +#endif
  28075. +
  28076. " jmp 2b\n"
  28077. ".previous\n"
  28078. - _ASM_EXTABLE(1b, 3b) : : "r" (from));
  28079. + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
  28080. for (i = 0; i < 4096/64; i++) {
  28081. __asm__ __volatile__ (
  28082. - "1: prefetch 320(%0)\n"
  28083. - "2: movq (%0), %%mm0\n"
  28084. - " movq 8(%0), %%mm1\n"
  28085. - " movq 16(%0), %%mm2\n"
  28086. - " movq 24(%0), %%mm3\n"
  28087. - " movq %%mm0, (%1)\n"
  28088. - " movq %%mm1, 8(%1)\n"
  28089. - " movq %%mm2, 16(%1)\n"
  28090. - " movq %%mm3, 24(%1)\n"
  28091. - " movq 32(%0), %%mm0\n"
  28092. - " movq 40(%0), %%mm1\n"
  28093. - " movq 48(%0), %%mm2\n"
  28094. - " movq 56(%0), %%mm3\n"
  28095. - " movq %%mm0, 32(%1)\n"
  28096. - " movq %%mm1, 40(%1)\n"
  28097. - " movq %%mm2, 48(%1)\n"
  28098. - " movq %%mm3, 56(%1)\n"
  28099. + "1: prefetch 320(%1)\n"
  28100. + "2: movq (%1), %%mm0\n"
  28101. + " movq 8(%1), %%mm1\n"
  28102. + " movq 16(%1), %%mm2\n"
  28103. + " movq 24(%1), %%mm3\n"
  28104. + " movq %%mm0, (%2)\n"
  28105. + " movq %%mm1, 8(%2)\n"
  28106. + " movq %%mm2, 16(%2)\n"
  28107. + " movq %%mm3, 24(%2)\n"
  28108. + " movq 32(%1), %%mm0\n"
  28109. + " movq 40(%1), %%mm1\n"
  28110. + " movq 48(%1), %%mm2\n"
  28111. + " movq 56(%1), %%mm3\n"
  28112. + " movq %%mm0, 32(%2)\n"
  28113. + " movq %%mm1, 40(%2)\n"
  28114. + " movq %%mm2, 48(%2)\n"
  28115. + " movq %%mm3, 56(%2)\n"
  28116. ".section .fixup, \"ax\"\n"
  28117. - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
  28118. + "3:\n"
  28119. +
  28120. +#ifdef CONFIG_PAX_KERNEXEC
  28121. + " movl %%cr0, %0\n"
  28122. + " movl %0, %%eax\n"
  28123. + " andl $0xFFFEFFFF, %%eax\n"
  28124. + " movl %%eax, %%cr0\n"
  28125. +#endif
  28126. +
  28127. + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
  28128. +
  28129. +#ifdef CONFIG_PAX_KERNEXEC
  28130. + " movl %0, %%cr0\n"
  28131. +#endif
  28132. +
  28133. " jmp 2b\n"
  28134. ".previous\n"
  28135. _ASM_EXTABLE(1b, 3b)
  28136. - : : "r" (from), "r" (to) : "memory");
  28137. + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
  28138. from += 64;
  28139. to += 64;
  28140. diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
  28141. index f6d13ee..d789440 100644
  28142. --- a/arch/x86/lib/msr-reg.S
  28143. +++ b/arch/x86/lib/msr-reg.S
  28144. @@ -3,6 +3,7 @@
  28145. #include <asm/dwarf2.h>
  28146. #include <asm/asm.h>
  28147. #include <asm/msr.h>
  28148. +#include <asm/alternative-asm.h>
  28149. #ifdef CONFIG_X86_64
  28150. /*
  28151. @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
  28152. movl %edi, 28(%r10)
  28153. popq_cfi %rbp
  28154. popq_cfi %rbx
  28155. + pax_force_retaddr
  28156. ret
  28157. 3:
  28158. CFI_RESTORE_STATE
  28159. diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
  28160. index fc6ba17..d4d989d 100644
  28161. --- a/arch/x86/lib/putuser.S
  28162. +++ b/arch/x86/lib/putuser.S
  28163. @@ -16,7 +16,9 @@
  28164. #include <asm/errno.h>
  28165. #include <asm/asm.h>
  28166. #include <asm/smap.h>
  28167. -
  28168. +#include <asm/segment.h>
  28169. +#include <asm/pgtable.h>
  28170. +#include <asm/alternative-asm.h>
  28171. /*
  28172. * __put_user_X
  28173. @@ -30,57 +32,125 @@
  28174. * as they get called from within inline assembly.
  28175. */
  28176. -#define ENTER CFI_STARTPROC ; \
  28177. - GET_THREAD_INFO(%_ASM_BX)
  28178. -#define EXIT ASM_CLAC ; \
  28179. - ret ; \
  28180. +#define ENTER CFI_STARTPROC
  28181. +#define EXIT ASM_CLAC ; \
  28182. + pax_force_retaddr ; \
  28183. + ret ; \
  28184. CFI_ENDPROC
  28185. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  28186. +#define _DEST %_ASM_CX,%_ASM_BX
  28187. +#else
  28188. +#define _DEST %_ASM_CX
  28189. +#endif
  28190. +
  28191. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
  28192. +#define __copyuser_seg gs;
  28193. +#else
  28194. +#define __copyuser_seg
  28195. +#endif
  28196. +
  28197. .text
  28198. ENTRY(__put_user_1)
  28199. ENTER
  28200. +
  28201. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  28202. + GET_THREAD_INFO(%_ASM_BX)
  28203. cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
  28204. jae bad_put_user
  28205. ASM_STAC
  28206. -1: movb %al,(%_ASM_CX)
  28207. +
  28208. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  28209. + mov pax_user_shadow_base,%_ASM_BX
  28210. + cmp %_ASM_BX,%_ASM_CX
  28211. + jb 1234f
  28212. + xor %ebx,%ebx
  28213. +1234:
  28214. +#endif
  28215. +
  28216. +#endif
  28217. +
  28218. +1: __copyuser_seg movb %al,(_DEST)
  28219. xor %eax,%eax
  28220. EXIT
  28221. ENDPROC(__put_user_1)
  28222. ENTRY(__put_user_2)
  28223. ENTER
  28224. +
  28225. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  28226. + GET_THREAD_INFO(%_ASM_BX)
  28227. mov TI_addr_limit(%_ASM_BX),%_ASM_BX
  28228. sub $1,%_ASM_BX
  28229. cmp %_ASM_BX,%_ASM_CX
  28230. jae bad_put_user
  28231. ASM_STAC
  28232. -2: movw %ax,(%_ASM_CX)
  28233. +
  28234. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  28235. + mov pax_user_shadow_base,%_ASM_BX
  28236. + cmp %_ASM_BX,%_ASM_CX
  28237. + jb 1234f
  28238. + xor %ebx,%ebx
  28239. +1234:
  28240. +#endif
  28241. +
  28242. +#endif
  28243. +
  28244. +2: __copyuser_seg movw %ax,(_DEST)
  28245. xor %eax,%eax
  28246. EXIT
  28247. ENDPROC(__put_user_2)
  28248. ENTRY(__put_user_4)
  28249. ENTER
  28250. +
  28251. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  28252. + GET_THREAD_INFO(%_ASM_BX)
  28253. mov TI_addr_limit(%_ASM_BX),%_ASM_BX
  28254. sub $3,%_ASM_BX
  28255. cmp %_ASM_BX,%_ASM_CX
  28256. jae bad_put_user
  28257. ASM_STAC
  28258. -3: movl %eax,(%_ASM_CX)
  28259. +
  28260. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  28261. + mov pax_user_shadow_base,%_ASM_BX
  28262. + cmp %_ASM_BX,%_ASM_CX
  28263. + jb 1234f
  28264. + xor %ebx,%ebx
  28265. +1234:
  28266. +#endif
  28267. +
  28268. +#endif
  28269. +
  28270. +3: __copyuser_seg movl %eax,(_DEST)
  28271. xor %eax,%eax
  28272. EXIT
  28273. ENDPROC(__put_user_4)
  28274. ENTRY(__put_user_8)
  28275. ENTER
  28276. +
  28277. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
  28278. + GET_THREAD_INFO(%_ASM_BX)
  28279. mov TI_addr_limit(%_ASM_BX),%_ASM_BX
  28280. sub $7,%_ASM_BX
  28281. cmp %_ASM_BX,%_ASM_CX
  28282. jae bad_put_user
  28283. ASM_STAC
  28284. -4: mov %_ASM_AX,(%_ASM_CX)
  28285. +
  28286. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  28287. + mov pax_user_shadow_base,%_ASM_BX
  28288. + cmp %_ASM_BX,%_ASM_CX
  28289. + jb 1234f
  28290. + xor %ebx,%ebx
  28291. +1234:
  28292. +#endif
  28293. +
  28294. +#endif
  28295. +
  28296. +4: __copyuser_seg mov %_ASM_AX,(_DEST)
  28297. #ifdef CONFIG_X86_32
  28298. -5: movl %edx,4(%_ASM_CX)
  28299. +5: __copyuser_seg movl %edx,4(_DEST)
  28300. #endif
  28301. xor %eax,%eax
  28302. EXIT
  28303. diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
  28304. index 1cad221..de671ee 100644
  28305. --- a/arch/x86/lib/rwlock.S
  28306. +++ b/arch/x86/lib/rwlock.S
  28307. @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
  28308. FRAME
  28309. 0: LOCK_PREFIX
  28310. WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
  28311. +
  28312. +#ifdef CONFIG_PAX_REFCOUNT
  28313. + jno 1234f
  28314. + LOCK_PREFIX
  28315. + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
  28316. + int $4
  28317. +1234:
  28318. + _ASM_EXTABLE(1234b, 1234b)
  28319. +#endif
  28320. +
  28321. 1: rep; nop
  28322. cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
  28323. jne 1b
  28324. LOCK_PREFIX
  28325. WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
  28326. +
  28327. +#ifdef CONFIG_PAX_REFCOUNT
  28328. + jno 1234f
  28329. + LOCK_PREFIX
  28330. + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
  28331. + int $4
  28332. +1234:
  28333. + _ASM_EXTABLE(1234b, 1234b)
  28334. +#endif
  28335. +
  28336. jnz 0b
  28337. ENDFRAME
  28338. + pax_force_retaddr
  28339. ret
  28340. CFI_ENDPROC
  28341. END(__write_lock_failed)
  28342. @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
  28343. FRAME
  28344. 0: LOCK_PREFIX
  28345. READ_LOCK_SIZE(inc) (%__lock_ptr)
  28346. +
  28347. +#ifdef CONFIG_PAX_REFCOUNT
  28348. + jno 1234f
  28349. + LOCK_PREFIX
  28350. + READ_LOCK_SIZE(dec) (%__lock_ptr)
  28351. + int $4
  28352. +1234:
  28353. + _ASM_EXTABLE(1234b, 1234b)
  28354. +#endif
  28355. +
  28356. 1: rep; nop
  28357. READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
  28358. js 1b
  28359. LOCK_PREFIX
  28360. READ_LOCK_SIZE(dec) (%__lock_ptr)
  28361. +
  28362. +#ifdef CONFIG_PAX_REFCOUNT
  28363. + jno 1234f
  28364. + LOCK_PREFIX
  28365. + READ_LOCK_SIZE(inc) (%__lock_ptr)
  28366. + int $4
  28367. +1234:
  28368. + _ASM_EXTABLE(1234b, 1234b)
  28369. +#endif
  28370. +
  28371. js 0b
  28372. ENDFRAME
  28373. + pax_force_retaddr
  28374. ret
  28375. CFI_ENDPROC
  28376. END(__read_lock_failed)
  28377. diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
  28378. index 5dff5f0..cadebf4 100644
  28379. --- a/arch/x86/lib/rwsem.S
  28380. +++ b/arch/x86/lib/rwsem.S
  28381. @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
  28382. __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
  28383. CFI_RESTORE __ASM_REG(dx)
  28384. restore_common_regs
  28385. + pax_force_retaddr
  28386. ret
  28387. CFI_ENDPROC
  28388. ENDPROC(call_rwsem_down_read_failed)
  28389. @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
  28390. movq %rax,%rdi
  28391. call rwsem_down_write_failed
  28392. restore_common_regs
  28393. + pax_force_retaddr
  28394. ret
  28395. CFI_ENDPROC
  28396. ENDPROC(call_rwsem_down_write_failed)
  28397. @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
  28398. movq %rax,%rdi
  28399. call rwsem_wake
  28400. restore_common_regs
  28401. -1: ret
  28402. +1: pax_force_retaddr
  28403. + ret
  28404. CFI_ENDPROC
  28405. ENDPROC(call_rwsem_wake)
  28406. @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
  28407. __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
  28408. CFI_RESTORE __ASM_REG(dx)
  28409. restore_common_regs
  28410. + pax_force_retaddr
  28411. ret
  28412. CFI_ENDPROC
  28413. ENDPROC(call_rwsem_downgrade_wake)
  28414. diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
  28415. index a63efd6..8149fbe 100644
  28416. --- a/arch/x86/lib/thunk_64.S
  28417. +++ b/arch/x86/lib/thunk_64.S
  28418. @@ -8,6 +8,7 @@
  28419. #include <linux/linkage.h>
  28420. #include <asm/dwarf2.h>
  28421. #include <asm/calling.h>
  28422. +#include <asm/alternative-asm.h>
  28423. /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
  28424. .macro THUNK name, func, put_ret_addr_in_rdi=0
  28425. @@ -15,11 +16,11 @@
  28426. \name:
  28427. CFI_STARTPROC
  28428. - /* this one pushes 9 elems, the next one would be %rIP */
  28429. - SAVE_ARGS
  28430. + /* this one pushes 15+1 elems, the next one would be %rIP */
  28431. + SAVE_ARGS 8
  28432. .if \put_ret_addr_in_rdi
  28433. - movq_cfi_restore 9*8, rdi
  28434. + movq_cfi_restore RIP, rdi
  28435. .endif
  28436. call \func
  28437. @@ -38,8 +39,9 @@
  28438. /* SAVE_ARGS below is used only for the .cfi directives it contains. */
  28439. CFI_STARTPROC
  28440. - SAVE_ARGS
  28441. + SAVE_ARGS 8
  28442. restore:
  28443. - RESTORE_ARGS
  28444. + RESTORE_ARGS 1,8
  28445. + pax_force_retaddr
  28446. ret
  28447. CFI_ENDPROC
  28448. diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
  28449. index e2f5e21..4b22130 100644
  28450. --- a/arch/x86/lib/usercopy_32.c
  28451. +++ b/arch/x86/lib/usercopy_32.c
  28452. @@ -42,11 +42,13 @@ do { \
  28453. int __d0; \
  28454. might_fault(); \
  28455. __asm__ __volatile__( \
  28456. + __COPYUSER_SET_ES \
  28457. ASM_STAC "\n" \
  28458. "0: rep; stosl\n" \
  28459. " movl %2,%0\n" \
  28460. "1: rep; stosb\n" \
  28461. "2: " ASM_CLAC "\n" \
  28462. + __COPYUSER_RESTORE_ES \
  28463. ".section .fixup,\"ax\"\n" \
  28464. "3: lea 0(%2,%0,4),%0\n" \
  28465. " jmp 2b\n" \
  28466. @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
  28467. #ifdef CONFIG_X86_INTEL_USERCOPY
  28468. static unsigned long
  28469. -__copy_user_intel(void __user *to, const void *from, unsigned long size)
  28470. +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
  28471. {
  28472. int d0, d1;
  28473. __asm__ __volatile__(
  28474. @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
  28475. " .align 2,0x90\n"
  28476. "3: movl 0(%4), %%eax\n"
  28477. "4: movl 4(%4), %%edx\n"
  28478. - "5: movl %%eax, 0(%3)\n"
  28479. - "6: movl %%edx, 4(%3)\n"
  28480. + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
  28481. + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
  28482. "7: movl 8(%4), %%eax\n"
  28483. "8: movl 12(%4),%%edx\n"
  28484. - "9: movl %%eax, 8(%3)\n"
  28485. - "10: movl %%edx, 12(%3)\n"
  28486. + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
  28487. + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
  28488. "11: movl 16(%4), %%eax\n"
  28489. "12: movl 20(%4), %%edx\n"
  28490. - "13: movl %%eax, 16(%3)\n"
  28491. - "14: movl %%edx, 20(%3)\n"
  28492. + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
  28493. + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
  28494. "15: movl 24(%4), %%eax\n"
  28495. "16: movl 28(%4), %%edx\n"
  28496. - "17: movl %%eax, 24(%3)\n"
  28497. - "18: movl %%edx, 28(%3)\n"
  28498. + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
  28499. + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
  28500. "19: movl 32(%4), %%eax\n"
  28501. "20: movl 36(%4), %%edx\n"
  28502. - "21: movl %%eax, 32(%3)\n"
  28503. - "22: movl %%edx, 36(%3)\n"
  28504. + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
  28505. + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
  28506. "23: movl 40(%4), %%eax\n"
  28507. "24: movl 44(%4), %%edx\n"
  28508. - "25: movl %%eax, 40(%3)\n"
  28509. - "26: movl %%edx, 44(%3)\n"
  28510. + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
  28511. + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
  28512. "27: movl 48(%4), %%eax\n"
  28513. "28: movl 52(%4), %%edx\n"
  28514. - "29: movl %%eax, 48(%3)\n"
  28515. - "30: movl %%edx, 52(%3)\n"
  28516. + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
  28517. + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
  28518. "31: movl 56(%4), %%eax\n"
  28519. "32: movl 60(%4), %%edx\n"
  28520. - "33: movl %%eax, 56(%3)\n"
  28521. - "34: movl %%edx, 60(%3)\n"
  28522. + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
  28523. + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
  28524. " addl $-64, %0\n"
  28525. " addl $64, %4\n"
  28526. " addl $64, %3\n"
  28527. @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
  28528. " shrl $2, %0\n"
  28529. " andl $3, %%eax\n"
  28530. " cld\n"
  28531. + __COPYUSER_SET_ES
  28532. "99: rep; movsl\n"
  28533. "36: movl %%eax, %0\n"
  28534. "37: rep; movsb\n"
  28535. "100:\n"
  28536. + __COPYUSER_RESTORE_ES
  28537. + ".section .fixup,\"ax\"\n"
  28538. + "101: lea 0(%%eax,%0,4),%0\n"
  28539. + " jmp 100b\n"
  28540. + ".previous\n"
  28541. + _ASM_EXTABLE(1b,100b)
  28542. + _ASM_EXTABLE(2b,100b)
  28543. + _ASM_EXTABLE(3b,100b)
  28544. + _ASM_EXTABLE(4b,100b)
  28545. + _ASM_EXTABLE(5b,100b)
  28546. + _ASM_EXTABLE(6b,100b)
  28547. + _ASM_EXTABLE(7b,100b)
  28548. + _ASM_EXTABLE(8b,100b)
  28549. + _ASM_EXTABLE(9b,100b)
  28550. + _ASM_EXTABLE(10b,100b)
  28551. + _ASM_EXTABLE(11b,100b)
  28552. + _ASM_EXTABLE(12b,100b)
  28553. + _ASM_EXTABLE(13b,100b)
  28554. + _ASM_EXTABLE(14b,100b)
  28555. + _ASM_EXTABLE(15b,100b)
  28556. + _ASM_EXTABLE(16b,100b)
  28557. + _ASM_EXTABLE(17b,100b)
  28558. + _ASM_EXTABLE(18b,100b)
  28559. + _ASM_EXTABLE(19b,100b)
  28560. + _ASM_EXTABLE(20b,100b)
  28561. + _ASM_EXTABLE(21b,100b)
  28562. + _ASM_EXTABLE(22b,100b)
  28563. + _ASM_EXTABLE(23b,100b)
  28564. + _ASM_EXTABLE(24b,100b)
  28565. + _ASM_EXTABLE(25b,100b)
  28566. + _ASM_EXTABLE(26b,100b)
  28567. + _ASM_EXTABLE(27b,100b)
  28568. + _ASM_EXTABLE(28b,100b)
  28569. + _ASM_EXTABLE(29b,100b)
  28570. + _ASM_EXTABLE(30b,100b)
  28571. + _ASM_EXTABLE(31b,100b)
  28572. + _ASM_EXTABLE(32b,100b)
  28573. + _ASM_EXTABLE(33b,100b)
  28574. + _ASM_EXTABLE(34b,100b)
  28575. + _ASM_EXTABLE(35b,100b)
  28576. + _ASM_EXTABLE(36b,100b)
  28577. + _ASM_EXTABLE(37b,100b)
  28578. + _ASM_EXTABLE(99b,101b)
  28579. + : "=&c"(size), "=&D" (d0), "=&S" (d1)
  28580. + : "1"(to), "2"(from), "0"(size)
  28581. + : "eax", "edx", "memory");
  28582. + return size;
  28583. +}
  28584. +
  28585. +static unsigned long
  28586. +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
  28587. +{
  28588. + int d0, d1;
  28589. + __asm__ __volatile__(
  28590. + " .align 2,0x90\n"
  28591. + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
  28592. + " cmpl $67, %0\n"
  28593. + " jbe 3f\n"
  28594. + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
  28595. + " .align 2,0x90\n"
  28596. + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
  28597. + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
  28598. + "5: movl %%eax, 0(%3)\n"
  28599. + "6: movl %%edx, 4(%3)\n"
  28600. + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
  28601. + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
  28602. + "9: movl %%eax, 8(%3)\n"
  28603. + "10: movl %%edx, 12(%3)\n"
  28604. + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
  28605. + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
  28606. + "13: movl %%eax, 16(%3)\n"
  28607. + "14: movl %%edx, 20(%3)\n"
  28608. + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
  28609. + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
  28610. + "17: movl %%eax, 24(%3)\n"
  28611. + "18: movl %%edx, 28(%3)\n"
  28612. + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
  28613. + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
  28614. + "21: movl %%eax, 32(%3)\n"
  28615. + "22: movl %%edx, 36(%3)\n"
  28616. + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
  28617. + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
  28618. + "25: movl %%eax, 40(%3)\n"
  28619. + "26: movl %%edx, 44(%3)\n"
  28620. + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
  28621. + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
  28622. + "29: movl %%eax, 48(%3)\n"
  28623. + "30: movl %%edx, 52(%3)\n"
  28624. + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
  28625. + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
  28626. + "33: movl %%eax, 56(%3)\n"
  28627. + "34: movl %%edx, 60(%3)\n"
  28628. + " addl $-64, %0\n"
  28629. + " addl $64, %4\n"
  28630. + " addl $64, %3\n"
  28631. + " cmpl $63, %0\n"
  28632. + " ja 1b\n"
  28633. + "35: movl %0, %%eax\n"
  28634. + " shrl $2, %0\n"
  28635. + " andl $3, %%eax\n"
  28636. + " cld\n"
  28637. + "99: rep; "__copyuser_seg" movsl\n"
  28638. + "36: movl %%eax, %0\n"
  28639. + "37: rep; "__copyuser_seg" movsb\n"
  28640. + "100:\n"
  28641. ".section .fixup,\"ax\"\n"
  28642. "101: lea 0(%%eax,%0,4),%0\n"
  28643. " jmp 100b\n"
  28644. @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
  28645. int d0, d1;
  28646. __asm__ __volatile__(
  28647. " .align 2,0x90\n"
  28648. - "0: movl 32(%4), %%eax\n"
  28649. + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
  28650. " cmpl $67, %0\n"
  28651. " jbe 2f\n"
  28652. - "1: movl 64(%4), %%eax\n"
  28653. + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
  28654. " .align 2,0x90\n"
  28655. - "2: movl 0(%4), %%eax\n"
  28656. - "21: movl 4(%4), %%edx\n"
  28657. + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
  28658. + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
  28659. " movl %%eax, 0(%3)\n"
  28660. " movl %%edx, 4(%3)\n"
  28661. - "3: movl 8(%4), %%eax\n"
  28662. - "31: movl 12(%4),%%edx\n"
  28663. + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
  28664. + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
  28665. " movl %%eax, 8(%3)\n"
  28666. " movl %%edx, 12(%3)\n"
  28667. - "4: movl 16(%4), %%eax\n"
  28668. - "41: movl 20(%4), %%edx\n"
  28669. + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
  28670. + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
  28671. " movl %%eax, 16(%3)\n"
  28672. " movl %%edx, 20(%3)\n"
  28673. - "10: movl 24(%4), %%eax\n"
  28674. - "51: movl 28(%4), %%edx\n"
  28675. + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
  28676. + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
  28677. " movl %%eax, 24(%3)\n"
  28678. " movl %%edx, 28(%3)\n"
  28679. - "11: movl 32(%4), %%eax\n"
  28680. - "61: movl 36(%4), %%edx\n"
  28681. + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
  28682. + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
  28683. " movl %%eax, 32(%3)\n"
  28684. " movl %%edx, 36(%3)\n"
  28685. - "12: movl 40(%4), %%eax\n"
  28686. - "71: movl 44(%4), %%edx\n"
  28687. + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
  28688. + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
  28689. " movl %%eax, 40(%3)\n"
  28690. " movl %%edx, 44(%3)\n"
  28691. - "13: movl 48(%4), %%eax\n"
  28692. - "81: movl 52(%4), %%edx\n"
  28693. + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
  28694. + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
  28695. " movl %%eax, 48(%3)\n"
  28696. " movl %%edx, 52(%3)\n"
  28697. - "14: movl 56(%4), %%eax\n"
  28698. - "91: movl 60(%4), %%edx\n"
  28699. + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
  28700. + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
  28701. " movl %%eax, 56(%3)\n"
  28702. " movl %%edx, 60(%3)\n"
  28703. " addl $-64, %0\n"
  28704. @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
  28705. " shrl $2, %0\n"
  28706. " andl $3, %%eax\n"
  28707. " cld\n"
  28708. - "6: rep; movsl\n"
  28709. + "6: rep; "__copyuser_seg" movsl\n"
  28710. " movl %%eax,%0\n"
  28711. - "7: rep; movsb\n"
  28712. + "7: rep; "__copyuser_seg" movsb\n"
  28713. "8:\n"
  28714. ".section .fixup,\"ax\"\n"
  28715. "9: lea 0(%%eax,%0,4),%0\n"
  28716. @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
  28717. __asm__ __volatile__(
  28718. " .align 2,0x90\n"
  28719. - "0: movl 32(%4), %%eax\n"
  28720. + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
  28721. " cmpl $67, %0\n"
  28722. " jbe 2f\n"
  28723. - "1: movl 64(%4), %%eax\n"
  28724. + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
  28725. " .align 2,0x90\n"
  28726. - "2: movl 0(%4), %%eax\n"
  28727. - "21: movl 4(%4), %%edx\n"
  28728. + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
  28729. + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
  28730. " movnti %%eax, 0(%3)\n"
  28731. " movnti %%edx, 4(%3)\n"
  28732. - "3: movl 8(%4), %%eax\n"
  28733. - "31: movl 12(%4),%%edx\n"
  28734. + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
  28735. + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
  28736. " movnti %%eax, 8(%3)\n"
  28737. " movnti %%edx, 12(%3)\n"
  28738. - "4: movl 16(%4), %%eax\n"
  28739. - "41: movl 20(%4), %%edx\n"
  28740. + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
  28741. + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
  28742. " movnti %%eax, 16(%3)\n"
  28743. " movnti %%edx, 20(%3)\n"
  28744. - "10: movl 24(%4), %%eax\n"
  28745. - "51: movl 28(%4), %%edx\n"
  28746. + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
  28747. + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
  28748. " movnti %%eax, 24(%3)\n"
  28749. " movnti %%edx, 28(%3)\n"
  28750. - "11: movl 32(%4), %%eax\n"
  28751. - "61: movl 36(%4), %%edx\n"
  28752. + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
  28753. + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
  28754. " movnti %%eax, 32(%3)\n"
  28755. " movnti %%edx, 36(%3)\n"
  28756. - "12: movl 40(%4), %%eax\n"
  28757. - "71: movl 44(%4), %%edx\n"
  28758. + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
  28759. + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
  28760. " movnti %%eax, 40(%3)\n"
  28761. " movnti %%edx, 44(%3)\n"
  28762. - "13: movl 48(%4), %%eax\n"
  28763. - "81: movl 52(%4), %%edx\n"
  28764. + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
  28765. + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
  28766. " movnti %%eax, 48(%3)\n"
  28767. " movnti %%edx, 52(%3)\n"
  28768. - "14: movl 56(%4), %%eax\n"
  28769. - "91: movl 60(%4), %%edx\n"
  28770. + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
  28771. + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
  28772. " movnti %%eax, 56(%3)\n"
  28773. " movnti %%edx, 60(%3)\n"
  28774. " addl $-64, %0\n"
  28775. @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
  28776. " shrl $2, %0\n"
  28777. " andl $3, %%eax\n"
  28778. " cld\n"
  28779. - "6: rep; movsl\n"
  28780. + "6: rep; "__copyuser_seg" movsl\n"
  28781. " movl %%eax,%0\n"
  28782. - "7: rep; movsb\n"
  28783. + "7: rep; "__copyuser_seg" movsb\n"
  28784. "8:\n"
  28785. ".section .fixup,\"ax\"\n"
  28786. "9: lea 0(%%eax,%0,4),%0\n"
  28787. @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
  28788. __asm__ __volatile__(
  28789. " .align 2,0x90\n"
  28790. - "0: movl 32(%4), %%eax\n"
  28791. + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
  28792. " cmpl $67, %0\n"
  28793. " jbe 2f\n"
  28794. - "1: movl 64(%4), %%eax\n"
  28795. + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
  28796. " .align 2,0x90\n"
  28797. - "2: movl 0(%4), %%eax\n"
  28798. - "21: movl 4(%4), %%edx\n"
  28799. + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
  28800. + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
  28801. " movnti %%eax, 0(%3)\n"
  28802. " movnti %%edx, 4(%3)\n"
  28803. - "3: movl 8(%4), %%eax\n"
  28804. - "31: movl 12(%4),%%edx\n"
  28805. + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
  28806. + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
  28807. " movnti %%eax, 8(%3)\n"
  28808. " movnti %%edx, 12(%3)\n"
  28809. - "4: movl 16(%4), %%eax\n"
  28810. - "41: movl 20(%4), %%edx\n"
  28811. + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
  28812. + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
  28813. " movnti %%eax, 16(%3)\n"
  28814. " movnti %%edx, 20(%3)\n"
  28815. - "10: movl 24(%4), %%eax\n"
  28816. - "51: movl 28(%4), %%edx\n"
  28817. + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
  28818. + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
  28819. " movnti %%eax, 24(%3)\n"
  28820. " movnti %%edx, 28(%3)\n"
  28821. - "11: movl 32(%4), %%eax\n"
  28822. - "61: movl 36(%4), %%edx\n"
  28823. + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
  28824. + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
  28825. " movnti %%eax, 32(%3)\n"
  28826. " movnti %%edx, 36(%3)\n"
  28827. - "12: movl 40(%4), %%eax\n"
  28828. - "71: movl 44(%4), %%edx\n"
  28829. + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
  28830. + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
  28831. " movnti %%eax, 40(%3)\n"
  28832. " movnti %%edx, 44(%3)\n"
  28833. - "13: movl 48(%4), %%eax\n"
  28834. - "81: movl 52(%4), %%edx\n"
  28835. + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
  28836. + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
  28837. " movnti %%eax, 48(%3)\n"
  28838. " movnti %%edx, 52(%3)\n"
  28839. - "14: movl 56(%4), %%eax\n"
  28840. - "91: movl 60(%4), %%edx\n"
  28841. + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
  28842. + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
  28843. " movnti %%eax, 56(%3)\n"
  28844. " movnti %%edx, 60(%3)\n"
  28845. " addl $-64, %0\n"
  28846. @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
  28847. " shrl $2, %0\n"
  28848. " andl $3, %%eax\n"
  28849. " cld\n"
  28850. - "6: rep; movsl\n"
  28851. + "6: rep; "__copyuser_seg" movsl\n"
  28852. " movl %%eax,%0\n"
  28853. - "7: rep; movsb\n"
  28854. + "7: rep; "__copyuser_seg" movsb\n"
  28855. "8:\n"
  28856. ".section .fixup,\"ax\"\n"
  28857. "9: lea 0(%%eax,%0,4),%0\n"
  28858. @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
  28859. */
  28860. unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
  28861. unsigned long size);
  28862. -unsigned long __copy_user_intel(void __user *to, const void *from,
  28863. +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
  28864. + unsigned long size);
  28865. +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
  28866. unsigned long size);
  28867. unsigned long __copy_user_zeroing_intel_nocache(void *to,
  28868. const void __user *from, unsigned long size);
  28869. #endif /* CONFIG_X86_INTEL_USERCOPY */
  28870. /* Generic arbitrary sized copy. */
  28871. -#define __copy_user(to, from, size) \
  28872. +#define __copy_user(to, from, size, prefix, set, restore) \
  28873. do { \
  28874. int __d0, __d1, __d2; \
  28875. __asm__ __volatile__( \
  28876. + set \
  28877. " cmp $7,%0\n" \
  28878. " jbe 1f\n" \
  28879. " movl %1,%0\n" \
  28880. " negl %0\n" \
  28881. " andl $7,%0\n" \
  28882. " subl %0,%3\n" \
  28883. - "4: rep; movsb\n" \
  28884. + "4: rep; "prefix"movsb\n" \
  28885. " movl %3,%0\n" \
  28886. " shrl $2,%0\n" \
  28887. " andl $3,%3\n" \
  28888. " .align 2,0x90\n" \
  28889. - "0: rep; movsl\n" \
  28890. + "0: rep; "prefix"movsl\n" \
  28891. " movl %3,%0\n" \
  28892. - "1: rep; movsb\n" \
  28893. + "1: rep; "prefix"movsb\n" \
  28894. "2:\n" \
  28895. + restore \
  28896. ".section .fixup,\"ax\"\n" \
  28897. "5: addl %3,%0\n" \
  28898. " jmp 2b\n" \
  28899. @@ -538,14 +650,14 @@ do { \
  28900. " negl %0\n" \
  28901. " andl $7,%0\n" \
  28902. " subl %0,%3\n" \
  28903. - "4: rep; movsb\n" \
  28904. + "4: rep; "__copyuser_seg"movsb\n" \
  28905. " movl %3,%0\n" \
  28906. " shrl $2,%0\n" \
  28907. " andl $3,%3\n" \
  28908. " .align 2,0x90\n" \
  28909. - "0: rep; movsl\n" \
  28910. + "0: rep; "__copyuser_seg"movsl\n" \
  28911. " movl %3,%0\n" \
  28912. - "1: rep; movsb\n" \
  28913. + "1: rep; "__copyuser_seg"movsb\n" \
  28914. "2:\n" \
  28915. ".section .fixup,\"ax\"\n" \
  28916. "5: addl %3,%0\n" \
  28917. @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
  28918. {
  28919. stac();
  28920. if (movsl_is_ok(to, from, n))
  28921. - __copy_user(to, from, n);
  28922. + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
  28923. else
  28924. - n = __copy_user_intel(to, from, n);
  28925. + n = __generic_copy_to_user_intel(to, from, n);
  28926. clac();
  28927. return n;
  28928. }
  28929. @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
  28930. {
  28931. stac();
  28932. if (movsl_is_ok(to, from, n))
  28933. - __copy_user(to, from, n);
  28934. + __copy_user(to, from, n, __copyuser_seg, "", "");
  28935. else
  28936. - n = __copy_user_intel((void __user *)to,
  28937. - (const void *)from, n);
  28938. + n = __generic_copy_from_user_intel(to, from, n);
  28939. clac();
  28940. return n;
  28941. }
  28942. @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
  28943. if (n > 64 && cpu_has_xmm2)
  28944. n = __copy_user_intel_nocache(to, from, n);
  28945. else
  28946. - __copy_user(to, from, n);
  28947. + __copy_user(to, from, n, __copyuser_seg, "", "");
  28948. #else
  28949. - __copy_user(to, from, n);
  28950. + __copy_user(to, from, n, __copyuser_seg, "", "");
  28951. #endif
  28952. clac();
  28953. return n;
  28954. }
  28955. EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
  28956. -/**
  28957. - * copy_to_user: - Copy a block of data into user space.
  28958. - * @to: Destination address, in user space.
  28959. - * @from: Source address, in kernel space.
  28960. - * @n: Number of bytes to copy.
  28961. - *
  28962. - * Context: User context only. This function may sleep.
  28963. - *
  28964. - * Copy data from kernel space to user space.
  28965. - *
  28966. - * Returns number of bytes that could not be copied.
  28967. - * On success, this will be zero.
  28968. - */
  28969. -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
  28970. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  28971. +void __set_fs(mm_segment_t x)
  28972. {
  28973. - if (access_ok(VERIFY_WRITE, to, n))
  28974. - n = __copy_to_user(to, from, n);
  28975. - return n;
  28976. + switch (x.seg) {
  28977. + case 0:
  28978. + loadsegment(gs, 0);
  28979. + break;
  28980. + case TASK_SIZE_MAX:
  28981. + loadsegment(gs, __USER_DS);
  28982. + break;
  28983. + case -1UL:
  28984. + loadsegment(gs, __KERNEL_DS);
  28985. + break;
  28986. + default:
  28987. + BUG();
  28988. + }
  28989. }
  28990. -EXPORT_SYMBOL(_copy_to_user);
  28991. +EXPORT_SYMBOL(__set_fs);
  28992. -/**
  28993. - * copy_from_user: - Copy a block of data from user space.
  28994. - * @to: Destination address, in kernel space.
  28995. - * @from: Source address, in user space.
  28996. - * @n: Number of bytes to copy.
  28997. - *
  28998. - * Context: User context only. This function may sleep.
  28999. - *
  29000. - * Copy data from user space to kernel space.
  29001. - *
  29002. - * Returns number of bytes that could not be copied.
  29003. - * On success, this will be zero.
  29004. - *
  29005. - * If some data could not be copied, this function will pad the copied
  29006. - * data to the requested size using zero bytes.
  29007. - */
  29008. -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
  29009. +void set_fs(mm_segment_t x)
  29010. {
  29011. - if (access_ok(VERIFY_READ, from, n))
  29012. - n = __copy_from_user(to, from, n);
  29013. - else
  29014. - memset(to, 0, n);
  29015. - return n;
  29016. + current_thread_info()->addr_limit = x;
  29017. + __set_fs(x);
  29018. }
  29019. -EXPORT_SYMBOL(_copy_from_user);
  29020. +EXPORT_SYMBOL(set_fs);
  29021. +#endif
  29022. diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
  29023. index c905e89..01ab928 100644
  29024. --- a/arch/x86/lib/usercopy_64.c
  29025. +++ b/arch/x86/lib/usercopy_64.c
  29026. @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
  29027. might_fault();
  29028. /* no memory constraint because it doesn't change any memory gcc knows
  29029. about */
  29030. + pax_open_userland();
  29031. stac();
  29032. asm volatile(
  29033. " testq %[size8],%[size8]\n"
  29034. @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
  29035. _ASM_EXTABLE(0b,3b)
  29036. _ASM_EXTABLE(1b,2b)
  29037. : [size8] "=&c"(size), [dst] "=&D" (__d0)
  29038. - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
  29039. + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
  29040. [zero] "r" (0UL), [eight] "r" (8UL));
  29041. clac();
  29042. + pax_close_userland();
  29043. return size;
  29044. }
  29045. EXPORT_SYMBOL(__clear_user);
  29046. @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
  29047. }
  29048. EXPORT_SYMBOL(clear_user);
  29049. -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
  29050. +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
  29051. {
  29052. - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
  29053. - return copy_user_generic((__force void *)to, (__force void *)from, len);
  29054. - }
  29055. - return len;
  29056. + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
  29057. + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
  29058. + return len;
  29059. }
  29060. EXPORT_SYMBOL(copy_in_user);
  29061. @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
  29062. * it is not necessary to optimize tail handling.
  29063. */
  29064. __visible unsigned long
  29065. -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
  29066. +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
  29067. {
  29068. char c;
  29069. unsigned zero_len;
  29070. + clac();
  29071. + pax_close_userland();
  29072. for (; len; --len, to++) {
  29073. if (__get_user_nocheck(c, from++, sizeof(char)))
  29074. break;
  29075. @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
  29076. for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
  29077. if (__put_user_nocheck(c, to++, sizeof(char)))
  29078. break;
  29079. - clac();
  29080. return len;
  29081. }
  29082. diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
  29083. index 6a19ad9..1c48f9a 100644
  29084. --- a/arch/x86/mm/Makefile
  29085. +++ b/arch/x86/mm/Makefile
  29086. @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
  29087. obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
  29088. obj-$(CONFIG_MEMTEST) += memtest.o
  29089. +
  29090. +quote:="
  29091. +obj-$(CONFIG_X86_64) += uderef_64.o
  29092. +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
  29093. diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
  29094. index 903ec1e..c4166b2 100644
  29095. --- a/arch/x86/mm/extable.c
  29096. +++ b/arch/x86/mm/extable.c
  29097. @@ -6,12 +6,24 @@
  29098. static inline unsigned long
  29099. ex_insn_addr(const struct exception_table_entry *x)
  29100. {
  29101. - return (unsigned long)&x->insn + x->insn;
  29102. + unsigned long reloc = 0;
  29103. +
  29104. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  29105. + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  29106. +#endif
  29107. +
  29108. + return (unsigned long)&x->insn + x->insn + reloc;
  29109. }
  29110. static inline unsigned long
  29111. ex_fixup_addr(const struct exception_table_entry *x)
  29112. {
  29113. - return (unsigned long)&x->fixup + x->fixup;
  29114. + unsigned long reloc = 0;
  29115. +
  29116. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  29117. + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  29118. +#endif
  29119. +
  29120. + return (unsigned long)&x->fixup + x->fixup + reloc;
  29121. }
  29122. int fixup_exception(struct pt_regs *regs)
  29123. @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
  29124. unsigned long new_ip;
  29125. #ifdef CONFIG_PNPBIOS
  29126. - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
  29127. + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
  29128. extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
  29129. extern u32 pnp_bios_is_utter_crap;
  29130. pnp_bios_is_utter_crap = 1;
  29131. @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
  29132. i += 4;
  29133. p->fixup -= i;
  29134. i += 4;
  29135. +
  29136. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  29137. + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
  29138. + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  29139. + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
  29140. +#endif
  29141. +
  29142. }
  29143. }
  29144. diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
  29145. index a10c8c7..35a5abb 100644
  29146. --- a/arch/x86/mm/fault.c
  29147. +++ b/arch/x86/mm/fault.c
  29148. @@ -14,11 +14,18 @@
  29149. #include <linux/hugetlb.h> /* hstate_index_to_shift */
  29150. #include <linux/prefetch.h> /* prefetchw */
  29151. #include <linux/context_tracking.h> /* exception_enter(), ... */
  29152. +#include <linux/unistd.h>
  29153. +#include <linux/compiler.h>
  29154. #include <asm/traps.h> /* dotraplinkage, ... */
  29155. #include <asm/pgalloc.h> /* pgd_*(), ... */
  29156. #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
  29157. #include <asm/fixmap.h> /* VSYSCALL_START */
  29158. +#include <asm/tlbflush.h>
  29159. +
  29160. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  29161. +#include <asm/stacktrace.h>
  29162. +#endif
  29163. #define CREATE_TRACE_POINTS
  29164. #include <asm/trace/exceptions.h>
  29165. @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
  29166. int ret = 0;
  29167. /* kprobe_running() needs smp_processor_id() */
  29168. - if (kprobes_built_in() && !user_mode_vm(regs)) {
  29169. + if (kprobes_built_in() && !user_mode(regs)) {
  29170. preempt_disable();
  29171. if (kprobe_running() && kprobe_fault_handler(regs, 14))
  29172. ret = 1;
  29173. @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
  29174. return !instr_lo || (instr_lo>>1) == 1;
  29175. case 0x00:
  29176. /* Prefetch instruction is 0x0F0D or 0x0F18 */
  29177. - if (probe_kernel_address(instr, opcode))
  29178. + if (user_mode(regs)) {
  29179. + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
  29180. + return 0;
  29181. + } else if (probe_kernel_address(instr, opcode))
  29182. return 0;
  29183. *prefetch = (instr_lo == 0xF) &&
  29184. @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
  29185. while (instr < max_instr) {
  29186. unsigned char opcode;
  29187. - if (probe_kernel_address(instr, opcode))
  29188. + if (user_mode(regs)) {
  29189. + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
  29190. + break;
  29191. + } else if (probe_kernel_address(instr, opcode))
  29192. break;
  29193. instr++;
  29194. @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
  29195. force_sig_info(si_signo, &info, tsk);
  29196. }
  29197. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  29198. +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
  29199. +#endif
  29200. +
  29201. +#ifdef CONFIG_PAX_EMUTRAMP
  29202. +static int pax_handle_fetch_fault(struct pt_regs *regs);
  29203. +#endif
  29204. +
  29205. +#ifdef CONFIG_PAX_PAGEEXEC
  29206. +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
  29207. +{
  29208. + pgd_t *pgd;
  29209. + pud_t *pud;
  29210. + pmd_t *pmd;
  29211. +
  29212. + pgd = pgd_offset(mm, address);
  29213. + if (!pgd_present(*pgd))
  29214. + return NULL;
  29215. + pud = pud_offset(pgd, address);
  29216. + if (!pud_present(*pud))
  29217. + return NULL;
  29218. + pmd = pmd_offset(pud, address);
  29219. + if (!pmd_present(*pmd))
  29220. + return NULL;
  29221. + return pmd;
  29222. +}
  29223. +#endif
  29224. +
  29225. DEFINE_SPINLOCK(pgd_lock);
  29226. LIST_HEAD(pgd_list);
  29227. @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
  29228. for (address = VMALLOC_START & PMD_MASK;
  29229. address >= TASK_SIZE && address < FIXADDR_TOP;
  29230. address += PMD_SIZE) {
  29231. +
  29232. +#ifdef CONFIG_PAX_PER_CPU_PGD
  29233. + unsigned long cpu;
  29234. +#else
  29235. struct page *page;
  29236. +#endif
  29237. spin_lock(&pgd_lock);
  29238. +
  29239. +#ifdef CONFIG_PAX_PER_CPU_PGD
  29240. + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
  29241. + pgd_t *pgd = get_cpu_pgd(cpu, user);
  29242. + pmd_t *ret;
  29243. +
  29244. + ret = vmalloc_sync_one(pgd, address);
  29245. + if (!ret)
  29246. + break;
  29247. + pgd = get_cpu_pgd(cpu, kernel);
  29248. +#else
  29249. list_for_each_entry(page, &pgd_list, lru) {
  29250. + pgd_t *pgd;
  29251. spinlock_t *pgt_lock;
  29252. pmd_t *ret;
  29253. @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
  29254. pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
  29255. spin_lock(pgt_lock);
  29256. - ret = vmalloc_sync_one(page_address(page), address);
  29257. + pgd = page_address(page);
  29258. +#endif
  29259. +
  29260. + ret = vmalloc_sync_one(pgd, address);
  29261. +
  29262. +#ifndef CONFIG_PAX_PER_CPU_PGD
  29263. spin_unlock(pgt_lock);
  29264. +#endif
  29265. if (!ret)
  29266. break;
  29267. @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
  29268. * an interrupt in the middle of a task switch..
  29269. */
  29270. pgd_paddr = read_cr3();
  29271. +
  29272. +#ifdef CONFIG_PAX_PER_CPU_PGD
  29273. + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
  29274. + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
  29275. +#endif
  29276. +
  29277. pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
  29278. if (!pmd_k)
  29279. return -1;
  29280. @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
  29281. * happen within a race in page table update. In the later
  29282. * case just flush:
  29283. */
  29284. - pgd = pgd_offset(current->active_mm, address);
  29285. +
  29286. pgd_ref = pgd_offset_k(address);
  29287. if (pgd_none(*pgd_ref))
  29288. return -1;
  29289. +#ifdef CONFIG_PAX_PER_CPU_PGD
  29290. + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
  29291. + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
  29292. + if (pgd_none(*pgd)) {
  29293. + set_pgd(pgd, *pgd_ref);
  29294. + arch_flush_lazy_mmu_mode();
  29295. + } else {
  29296. + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
  29297. + }
  29298. + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
  29299. +#else
  29300. + pgd = pgd_offset(current->active_mm, address);
  29301. +#endif
  29302. +
  29303. if (pgd_none(*pgd)) {
  29304. set_pgd(pgd, *pgd_ref);
  29305. arch_flush_lazy_mmu_mode();
  29306. @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
  29307. static int is_errata100(struct pt_regs *regs, unsigned long address)
  29308. {
  29309. #ifdef CONFIG_X86_64
  29310. - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
  29311. + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
  29312. return 1;
  29313. #endif
  29314. return 0;
  29315. @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
  29316. }
  29317. static const char nx_warning[] = KERN_CRIT
  29318. -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
  29319. +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
  29320. static void
  29321. show_fault_oops(struct pt_regs *regs, unsigned long error_code,
  29322. @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
  29323. if (!oops_may_print())
  29324. return;
  29325. - if (error_code & PF_INSTR) {
  29326. + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
  29327. unsigned int level;
  29328. pte_t *pte = lookup_address(address, &level);
  29329. if (pte && pte_present(*pte) && !pte_exec(*pte))
  29330. - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
  29331. + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
  29332. }
  29333. +#ifdef CONFIG_PAX_KERNEXEC
  29334. + if (init_mm.start_code <= address && address < init_mm.end_code) {
  29335. + if (current->signal->curr_ip)
  29336. + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
  29337. + &current->signal->curr_ip, current->comm, task_pid_nr(current),
  29338. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
  29339. + else
  29340. + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
  29341. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
  29342. + }
  29343. +#endif
  29344. +
  29345. printk(KERN_ALERT "BUG: unable to handle kernel ");
  29346. if (address < PAGE_SIZE)
  29347. printk(KERN_CONT "NULL pointer dereference");
  29348. @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
  29349. return;
  29350. }
  29351. #endif
  29352. +
  29353. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  29354. + if (pax_is_fetch_fault(regs, error_code, address)) {
  29355. +
  29356. +#ifdef CONFIG_PAX_EMUTRAMP
  29357. + switch (pax_handle_fetch_fault(regs)) {
  29358. + case 2:
  29359. + return;
  29360. + }
  29361. +#endif
  29362. +
  29363. + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
  29364. + do_group_exit(SIGKILL);
  29365. + }
  29366. +#endif
  29367. +
  29368. /* Kernel addresses are always protection faults: */
  29369. if (address >= TASK_SIZE)
  29370. error_code |= PF_PROT;
  29371. @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
  29372. if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
  29373. printk(KERN_ERR
  29374. "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
  29375. - tsk->comm, tsk->pid, address);
  29376. + tsk->comm, task_pid_nr(tsk), address);
  29377. code = BUS_MCEERR_AR;
  29378. }
  29379. #endif
  29380. @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
  29381. return 1;
  29382. }
  29383. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
  29384. +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
  29385. +{
  29386. + pte_t *pte;
  29387. + pmd_t *pmd;
  29388. + spinlock_t *ptl;
  29389. + unsigned char pte_mask;
  29390. +
  29391. + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
  29392. + !(mm->pax_flags & MF_PAX_PAGEEXEC))
  29393. + return 0;
  29394. +
  29395. + /* PaX: it's our fault, let's handle it if we can */
  29396. +
  29397. + /* PaX: take a look at read faults before acquiring any locks */
  29398. + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
  29399. + /* instruction fetch attempt from a protected page in user mode */
  29400. + up_read(&mm->mmap_sem);
  29401. +
  29402. +#ifdef CONFIG_PAX_EMUTRAMP
  29403. + switch (pax_handle_fetch_fault(regs)) {
  29404. + case 2:
  29405. + return 1;
  29406. + }
  29407. +#endif
  29408. +
  29409. + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
  29410. + do_group_exit(SIGKILL);
  29411. + }
  29412. +
  29413. + pmd = pax_get_pmd(mm, address);
  29414. + if (unlikely(!pmd))
  29415. + return 0;
  29416. +
  29417. + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
  29418. + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
  29419. + pte_unmap_unlock(pte, ptl);
  29420. + return 0;
  29421. + }
  29422. +
  29423. + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
  29424. + /* write attempt to a protected page in user mode */
  29425. + pte_unmap_unlock(pte, ptl);
  29426. + return 0;
  29427. + }
  29428. +
  29429. +#ifdef CONFIG_SMP
  29430. + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
  29431. +#else
  29432. + if (likely(address > get_limit(regs->cs)))
  29433. +#endif
  29434. + {
  29435. + set_pte(pte, pte_mkread(*pte));
  29436. + __flush_tlb_one(address);
  29437. + pte_unmap_unlock(pte, ptl);
  29438. + up_read(&mm->mmap_sem);
  29439. + return 1;
  29440. + }
  29441. +
  29442. + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
  29443. +
  29444. + /*
  29445. + * PaX: fill DTLB with user rights and retry
  29446. + */
  29447. + __asm__ __volatile__ (
  29448. + "orb %2,(%1)\n"
  29449. +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
  29450. +/*
  29451. + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
  29452. + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
  29453. + * page fault when examined during a TLB load attempt. this is true not only
  29454. + * for PTEs holding a non-present entry but also present entries that will
  29455. + * raise a page fault (such as those set up by PaX, or the copy-on-write
  29456. + * mechanism). in effect it means that we do *not* need to flush the TLBs
  29457. + * for our target pages since their PTEs are simply not in the TLBs at all.
  29458. +
  29459. + * the best thing in omitting it is that we gain around 15-20% speed in the
  29460. + * fast path of the page fault handler and can get rid of tracing since we
  29461. + * can no longer flush unintended entries.
  29462. + */
  29463. + "invlpg (%0)\n"
  29464. +#endif
  29465. + __copyuser_seg"testb $0,(%0)\n"
  29466. + "xorb %3,(%1)\n"
  29467. + :
  29468. + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
  29469. + : "memory", "cc");
  29470. + pte_unmap_unlock(pte, ptl);
  29471. + up_read(&mm->mmap_sem);
  29472. + return 1;
  29473. +}
  29474. +#endif
  29475. +
  29476. /*
  29477. * Handle a spurious fault caused by a stale TLB entry.
  29478. *
  29479. @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
  29480. static inline int
  29481. access_error(unsigned long error_code, struct vm_area_struct *vma)
  29482. {
  29483. + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
  29484. + return 1;
  29485. +
  29486. if (error_code & PF_WRITE) {
  29487. /* write, present and write, not present: */
  29488. if (unlikely(!(vma->vm_flags & VM_WRITE)))
  29489. @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
  29490. if (error_code & PF_USER)
  29491. return false;
  29492. - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
  29493. + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
  29494. return false;
  29495. return true;
  29496. @@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
  29497. tsk = current;
  29498. mm = tsk->mm;
  29499. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  29500. + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
  29501. + if (!search_exception_tables(regs->ip)) {
  29502. + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
  29503. + bad_area_nosemaphore(regs, error_code, address);
  29504. + return;
  29505. + }
  29506. + if (address < pax_user_shadow_base) {
  29507. + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
  29508. + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
  29509. + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
  29510. + } else
  29511. + address -= pax_user_shadow_base;
  29512. + }
  29513. +#endif
  29514. +
  29515. /*
  29516. * Detect and handle instructions that would cause a page fault for
  29517. * both a tracked kernel page and a userspace page.
  29518. @@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
  29519. * User-mode registers count as a user access even for any
  29520. * potential system fault or CPU buglet:
  29521. */
  29522. - if (user_mode_vm(regs)) {
  29523. + if (user_mode(regs)) {
  29524. local_irq_enable();
  29525. error_code |= PF_USER;
  29526. flags |= FAULT_FLAG_USER;
  29527. @@ -1162,6 +1386,11 @@ retry:
  29528. might_sleep();
  29529. }
  29530. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
  29531. + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
  29532. + return;
  29533. +#endif
  29534. +
  29535. vma = find_vma(mm, address);
  29536. if (unlikely(!vma)) {
  29537. bad_area(regs, error_code, address);
  29538. @@ -1173,18 +1402,24 @@ retry:
  29539. bad_area(regs, error_code, address);
  29540. return;
  29541. }
  29542. - if (error_code & PF_USER) {
  29543. - /*
  29544. - * Accessing the stack below %sp is always a bug.
  29545. - * The large cushion allows instructions like enter
  29546. - * and pusha to work. ("enter $65535, $31" pushes
  29547. - * 32 pointers and then decrements %sp by 65535.)
  29548. - */
  29549. - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
  29550. - bad_area(regs, error_code, address);
  29551. - return;
  29552. - }
  29553. + /*
  29554. + * Accessing the stack below %sp is always a bug.
  29555. + * The large cushion allows instructions like enter
  29556. + * and pusha to work. ("enter $65535, $31" pushes
  29557. + * 32 pointers and then decrements %sp by 65535.)
  29558. + */
  29559. + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
  29560. + bad_area(regs, error_code, address);
  29561. + return;
  29562. }
  29563. +
  29564. +#ifdef CONFIG_PAX_SEGMEXEC
  29565. + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
  29566. + bad_area(regs, error_code, address);
  29567. + return;
  29568. + }
  29569. +#endif
  29570. +
  29571. if (unlikely(expand_stack(vma, address))) {
  29572. bad_area(regs, error_code, address);
  29573. return;
  29574. @@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
  29575. exception_exit(prev_state);
  29576. }
  29577. #endif /* CONFIG_TRACING */
  29578. +
  29579. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  29580. +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
  29581. +{
  29582. + struct mm_struct *mm = current->mm;
  29583. + unsigned long ip = regs->ip;
  29584. +
  29585. + if (v8086_mode(regs))
  29586. + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
  29587. +
  29588. +#ifdef CONFIG_PAX_PAGEEXEC
  29589. + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
  29590. + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
  29591. + return true;
  29592. + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
  29593. + return true;
  29594. + return false;
  29595. + }
  29596. +#endif
  29597. +
  29598. +#ifdef CONFIG_PAX_SEGMEXEC
  29599. + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
  29600. + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
  29601. + return true;
  29602. + return false;
  29603. + }
  29604. +#endif
  29605. +
  29606. + return false;
  29607. +}
  29608. +#endif
  29609. +
  29610. +#ifdef CONFIG_PAX_EMUTRAMP
  29611. +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
  29612. +{
  29613. + int err;
  29614. +
  29615. + do { /* PaX: libffi trampoline emulation */
  29616. + unsigned char mov, jmp;
  29617. + unsigned int addr1, addr2;
  29618. +
  29619. +#ifdef CONFIG_X86_64
  29620. + if ((regs->ip + 9) >> 32)
  29621. + break;
  29622. +#endif
  29623. +
  29624. + err = get_user(mov, (unsigned char __user *)regs->ip);
  29625. + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
  29626. + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
  29627. + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
  29628. +
  29629. + if (err)
  29630. + break;
  29631. +
  29632. + if (mov == 0xB8 && jmp == 0xE9) {
  29633. + regs->ax = addr1;
  29634. + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
  29635. + return 2;
  29636. + }
  29637. + } while (0);
  29638. +
  29639. + do { /* PaX: gcc trampoline emulation #1 */
  29640. + unsigned char mov1, mov2;
  29641. + unsigned short jmp;
  29642. + unsigned int addr1, addr2;
  29643. +
  29644. +#ifdef CONFIG_X86_64
  29645. + if ((regs->ip + 11) >> 32)
  29646. + break;
  29647. +#endif
  29648. +
  29649. + err = get_user(mov1, (unsigned char __user *)regs->ip);
  29650. + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
  29651. + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
  29652. + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
  29653. + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
  29654. +
  29655. + if (err)
  29656. + break;
  29657. +
  29658. + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
  29659. + regs->cx = addr1;
  29660. + regs->ax = addr2;
  29661. + regs->ip = addr2;
  29662. + return 2;
  29663. + }
  29664. + } while (0);
  29665. +
  29666. + do { /* PaX: gcc trampoline emulation #2 */
  29667. + unsigned char mov, jmp;
  29668. + unsigned int addr1, addr2;
  29669. +
  29670. +#ifdef CONFIG_X86_64
  29671. + if ((regs->ip + 9) >> 32)
  29672. + break;
  29673. +#endif
  29674. +
  29675. + err = get_user(mov, (unsigned char __user *)regs->ip);
  29676. + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
  29677. + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
  29678. + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
  29679. +
  29680. + if (err)
  29681. + break;
  29682. +
  29683. + if (mov == 0xB9 && jmp == 0xE9) {
  29684. + regs->cx = addr1;
  29685. + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
  29686. + return 2;
  29687. + }
  29688. + } while (0);
  29689. +
  29690. + return 1; /* PaX in action */
  29691. +}
  29692. +
  29693. +#ifdef CONFIG_X86_64
  29694. +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
  29695. +{
  29696. + int err;
  29697. +
  29698. + do { /* PaX: libffi trampoline emulation */
  29699. + unsigned short mov1, mov2, jmp1;
  29700. + unsigned char stcclc, jmp2;
  29701. + unsigned long addr1, addr2;
  29702. +
  29703. + err = get_user(mov1, (unsigned short __user *)regs->ip);
  29704. + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
  29705. + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
  29706. + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
  29707. + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
  29708. + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
  29709. + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
  29710. +
  29711. + if (err)
  29712. + break;
  29713. +
  29714. + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
  29715. + regs->r11 = addr1;
  29716. + regs->r10 = addr2;
  29717. + if (stcclc == 0xF8)
  29718. + regs->flags &= ~X86_EFLAGS_CF;
  29719. + else
  29720. + regs->flags |= X86_EFLAGS_CF;
  29721. + regs->ip = addr1;
  29722. + return 2;
  29723. + }
  29724. + } while (0);
  29725. +
  29726. + do { /* PaX: gcc trampoline emulation #1 */
  29727. + unsigned short mov1, mov2, jmp1;
  29728. + unsigned char jmp2;
  29729. + unsigned int addr1;
  29730. + unsigned long addr2;
  29731. +
  29732. + err = get_user(mov1, (unsigned short __user *)regs->ip);
  29733. + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
  29734. + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
  29735. + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
  29736. + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
  29737. + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
  29738. +
  29739. + if (err)
  29740. + break;
  29741. +
  29742. + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
  29743. + regs->r11 = addr1;
  29744. + regs->r10 = addr2;
  29745. + regs->ip = addr1;
  29746. + return 2;
  29747. + }
  29748. + } while (0);
  29749. +
  29750. + do { /* PaX: gcc trampoline emulation #2 */
  29751. + unsigned short mov1, mov2, jmp1;
  29752. + unsigned char jmp2;
  29753. + unsigned long addr1, addr2;
  29754. +
  29755. + err = get_user(mov1, (unsigned short __user *)regs->ip);
  29756. + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
  29757. + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
  29758. + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
  29759. + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
  29760. + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
  29761. +
  29762. + if (err)
  29763. + break;
  29764. +
  29765. + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
  29766. + regs->r11 = addr1;
  29767. + regs->r10 = addr2;
  29768. + regs->ip = addr1;
  29769. + return 2;
  29770. + }
  29771. + } while (0);
  29772. +
  29773. + return 1; /* PaX in action */
  29774. +}
  29775. +#endif
  29776. +
  29777. +/*
  29778. + * PaX: decide what to do with offenders (regs->ip = fault address)
  29779. + *
  29780. + * returns 1 when task should be killed
  29781. + * 2 when gcc trampoline was detected
  29782. + */
  29783. +static int pax_handle_fetch_fault(struct pt_regs *regs)
  29784. +{
  29785. + if (v8086_mode(regs))
  29786. + return 1;
  29787. +
  29788. + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
  29789. + return 1;
  29790. +
  29791. +#ifdef CONFIG_X86_32
  29792. + return pax_handle_fetch_fault_32(regs);
  29793. +#else
  29794. + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
  29795. + return pax_handle_fetch_fault_32(regs);
  29796. + else
  29797. + return pax_handle_fetch_fault_64(regs);
  29798. +#endif
  29799. +}
  29800. +#endif
  29801. +
  29802. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  29803. +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
  29804. +{
  29805. + long i;
  29806. +
  29807. + printk(KERN_ERR "PAX: bytes at PC: ");
  29808. + for (i = 0; i < 20; i++) {
  29809. + unsigned char c;
  29810. + if (get_user(c, (unsigned char __force_user *)pc+i))
  29811. + printk(KERN_CONT "?? ");
  29812. + else
  29813. + printk(KERN_CONT "%02x ", c);
  29814. + }
  29815. + printk("\n");
  29816. +
  29817. + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
  29818. + for (i = -1; i < 80 / (long)sizeof(long); i++) {
  29819. + unsigned long c;
  29820. + if (get_user(c, (unsigned long __force_user *)sp+i)) {
  29821. +#ifdef CONFIG_X86_32
  29822. + printk(KERN_CONT "???????? ");
  29823. +#else
  29824. + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
  29825. + printk(KERN_CONT "???????? ???????? ");
  29826. + else
  29827. + printk(KERN_CONT "???????????????? ");
  29828. +#endif
  29829. + } else {
  29830. +#ifdef CONFIG_X86_64
  29831. + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
  29832. + printk(KERN_CONT "%08x ", (unsigned int)c);
  29833. + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
  29834. + } else
  29835. +#endif
  29836. + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
  29837. + }
  29838. + }
  29839. + printk("\n");
  29840. +}
  29841. +#endif
  29842. +
  29843. +/**
  29844. + * probe_kernel_write(): safely attempt to write to a location
  29845. + * @dst: address to write to
  29846. + * @src: pointer to the data that shall be written
  29847. + * @size: size of the data chunk
  29848. + *
  29849. + * Safely write to address @dst from the buffer at @src. If a kernel fault
  29850. + * happens, handle that and return -EFAULT.
  29851. + */
  29852. +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
  29853. +{
  29854. + long ret;
  29855. + mm_segment_t old_fs = get_fs();
  29856. +
  29857. + set_fs(KERNEL_DS);
  29858. + pagefault_disable();
  29859. + pax_open_kernel();
  29860. + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
  29861. + pax_close_kernel();
  29862. + pagefault_enable();
  29863. + set_fs(old_fs);
  29864. +
  29865. + return ret ? -EFAULT : 0;
  29866. +}
  29867. diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
  29868. index 207d9aef..69030980 100644
  29869. --- a/arch/x86/mm/gup.c
  29870. +++ b/arch/x86/mm/gup.c
  29871. @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
  29872. addr = start;
  29873. len = (unsigned long) nr_pages << PAGE_SHIFT;
  29874. end = start + len;
  29875. - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
  29876. + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
  29877. (void __user *)start, len)))
  29878. return 0;
  29879. @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
  29880. goto slow_irqon;
  29881. #endif
  29882. + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
  29883. + (void __user *)start, len)))
  29884. + return 0;
  29885. +
  29886. /*
  29887. * XXX: batch / limit 'nr', to avoid large irq off latency
  29888. * needs some instrumenting to determine the common sizes used by
  29889. diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
  29890. index 4500142..53a363c 100644
  29891. --- a/arch/x86/mm/highmem_32.c
  29892. +++ b/arch/x86/mm/highmem_32.c
  29893. @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  29894. idx = type + KM_TYPE_NR*smp_processor_id();
  29895. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  29896. BUG_ON(!pte_none(*(kmap_pte-idx)));
  29897. +
  29898. + pax_open_kernel();
  29899. set_pte(kmap_pte-idx, mk_pte(page, prot));
  29900. + pax_close_kernel();
  29901. +
  29902. arch_flush_lazy_mmu_mode();
  29903. return (void *)vaddr;
  29904. diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
  29905. index 8c9f647..57cb402 100644
  29906. --- a/arch/x86/mm/hugetlbpage.c
  29907. +++ b/arch/x86/mm/hugetlbpage.c
  29908. @@ -90,23 +90,24 @@ int pmd_huge_support(void)
  29909. #ifdef CONFIG_HUGETLB_PAGE
  29910. static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
  29911. unsigned long addr, unsigned long len,
  29912. - unsigned long pgoff, unsigned long flags)
  29913. + unsigned long pgoff, unsigned long flags, unsigned long offset)
  29914. {
  29915. struct hstate *h = hstate_file(file);
  29916. struct vm_unmapped_area_info info;
  29917. -
  29918. +
  29919. info.flags = 0;
  29920. info.length = len;
  29921. info.low_limit = current->mm->mmap_legacy_base;
  29922. info.high_limit = TASK_SIZE;
  29923. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  29924. info.align_offset = 0;
  29925. + info.threadstack_offset = offset;
  29926. return vm_unmapped_area(&info);
  29927. }
  29928. static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
  29929. unsigned long addr0, unsigned long len,
  29930. - unsigned long pgoff, unsigned long flags)
  29931. + unsigned long pgoff, unsigned long flags, unsigned long offset)
  29932. {
  29933. struct hstate *h = hstate_file(file);
  29934. struct vm_unmapped_area_info info;
  29935. @@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
  29936. info.high_limit = current->mm->mmap_base;
  29937. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  29938. info.align_offset = 0;
  29939. + info.threadstack_offset = offset;
  29940. addr = vm_unmapped_area(&info);
  29941. /*
  29942. @@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
  29943. VM_BUG_ON(addr != -ENOMEM);
  29944. info.flags = 0;
  29945. info.low_limit = TASK_UNMAPPED_BASE;
  29946. +
  29947. +#ifdef CONFIG_PAX_RANDMMAP
  29948. + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
  29949. + info.low_limit += current->mm->delta_mmap;
  29950. +#endif
  29951. +
  29952. info.high_limit = TASK_SIZE;
  29953. addr = vm_unmapped_area(&info);
  29954. }
  29955. @@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  29956. struct hstate *h = hstate_file(file);
  29957. struct mm_struct *mm = current->mm;
  29958. struct vm_area_struct *vma;
  29959. + unsigned long pax_task_size = TASK_SIZE;
  29960. + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
  29961. if (len & ~huge_page_mask(h))
  29962. return -EINVAL;
  29963. - if (len > TASK_SIZE)
  29964. +
  29965. +#ifdef CONFIG_PAX_SEGMEXEC
  29966. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  29967. + pax_task_size = SEGMEXEC_TASK_SIZE;
  29968. +#endif
  29969. +
  29970. + pax_task_size -= PAGE_SIZE;
  29971. +
  29972. + if (len > pax_task_size)
  29973. return -ENOMEM;
  29974. if (flags & MAP_FIXED) {
  29975. @@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  29976. return addr;
  29977. }
  29978. +#ifdef CONFIG_PAX_RANDMMAP
  29979. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  29980. +#endif
  29981. +
  29982. if (addr) {
  29983. addr = ALIGN(addr, huge_page_size(h));
  29984. vma = find_vma(mm, addr);
  29985. - if (TASK_SIZE - len >= addr &&
  29986. - (!vma || addr + len <= vma->vm_start))
  29987. + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  29988. return addr;
  29989. }
  29990. if (mm->get_unmapped_area == arch_get_unmapped_area)
  29991. return hugetlb_get_unmapped_area_bottomup(file, addr, len,
  29992. - pgoff, flags);
  29993. + pgoff, flags, offset);
  29994. else
  29995. return hugetlb_get_unmapped_area_topdown(file, addr, len,
  29996. - pgoff, flags);
  29997. + pgoff, flags, offset);
  29998. }
  29999. #endif /* CONFIG_HUGETLB_PAGE */
  30000. diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
  30001. index f971306..e83e0f6 100644
  30002. --- a/arch/x86/mm/init.c
  30003. +++ b/arch/x86/mm/init.c
  30004. @@ -4,6 +4,7 @@
  30005. #include <linux/swap.h>
  30006. #include <linux/memblock.h>
  30007. #include <linux/bootmem.h> /* for max_low_pfn */
  30008. +#include <linux/tboot.h>
  30009. #include <asm/cacheflush.h>
  30010. #include <asm/e820.h>
  30011. @@ -17,6 +18,8 @@
  30012. #include <asm/proto.h>
  30013. #include <asm/dma.h> /* for MAX_DMA_PFN */
  30014. #include <asm/microcode.h>
  30015. +#include <asm/desc.h>
  30016. +#include <asm/bios_ebda.h>
  30017. #include "mm_internal.h"
  30018. @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
  30019. early_ioremap_page_table_range_init();
  30020. #endif
  30021. +#ifdef CONFIG_PAX_PER_CPU_PGD
  30022. + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
  30023. + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  30024. + KERNEL_PGD_PTRS);
  30025. + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
  30026. + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
  30027. + KERNEL_PGD_PTRS);
  30028. + load_cr3(get_cpu_pgd(0, kernel));
  30029. +#else
  30030. load_cr3(swapper_pg_dir);
  30031. +#endif
  30032. +
  30033. __flush_tlb_all();
  30034. early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
  30035. @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
  30036. * Access has to be given to non-kernel-ram areas as well, these contain the PCI
  30037. * mmio resources as well as potential bios/acpi data regions.
  30038. */
  30039. +
  30040. +#ifdef CONFIG_GRKERNSEC_KMEM
  30041. +static unsigned int ebda_start __read_only;
  30042. +static unsigned int ebda_end __read_only;
  30043. +#endif
  30044. +
  30045. int devmem_is_allowed(unsigned long pagenr)
  30046. {
  30047. - if (pagenr < 256)
  30048. +#ifdef CONFIG_GRKERNSEC_KMEM
  30049. + /* allow BDA */
  30050. + if (!pagenr)
  30051. return 1;
  30052. + /* allow EBDA */
  30053. + if (pagenr >= ebda_start && pagenr < ebda_end)
  30054. + return 1;
  30055. + /* if tboot is in use, allow access to its hardcoded serial log range */
  30056. + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
  30057. + return 1;
  30058. +#else
  30059. + if (!pagenr)
  30060. + return 1;
  30061. +#ifdef CONFIG_VM86
  30062. + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
  30063. + return 1;
  30064. +#endif
  30065. +#endif
  30066. +
  30067. + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
  30068. + return 1;
  30069. +#ifdef CONFIG_GRKERNSEC_KMEM
  30070. + /* throw out everything else below 1MB */
  30071. + if (pagenr <= 256)
  30072. + return 0;
  30073. +#endif
  30074. if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
  30075. return 0;
  30076. if (!page_is_ram(pagenr))
  30077. @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
  30078. #endif
  30079. }
  30080. +#ifdef CONFIG_GRKERNSEC_KMEM
  30081. +static inline void gr_init_ebda(void)
  30082. +{
  30083. + unsigned int ebda_addr;
  30084. + unsigned int ebda_size = 0;
  30085. +
  30086. + ebda_addr = get_bios_ebda();
  30087. + if (ebda_addr) {
  30088. + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
  30089. + ebda_size <<= 10;
  30090. + }
  30091. + if (ebda_addr && ebda_size) {
  30092. + ebda_start = ebda_addr >> PAGE_SHIFT;
  30093. + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
  30094. + } else {
  30095. + ebda_start = 0x9f000 >> PAGE_SHIFT;
  30096. + ebda_end = 0xa0000 >> PAGE_SHIFT;
  30097. + }
  30098. +}
  30099. +#else
  30100. +static inline void gr_init_ebda(void) { }
  30101. +#endif
  30102. +
  30103. void free_initmem(void)
  30104. {
  30105. +#ifdef CONFIG_PAX_KERNEXEC
  30106. +#ifdef CONFIG_X86_32
  30107. + /* PaX: limit KERNEL_CS to actual size */
  30108. + unsigned long addr, limit;
  30109. + struct desc_struct d;
  30110. + int cpu;
  30111. +#else
  30112. + pgd_t *pgd;
  30113. + pud_t *pud;
  30114. + pmd_t *pmd;
  30115. + unsigned long addr, end;
  30116. +#endif
  30117. +#endif
  30118. +
  30119. + gr_init_ebda();
  30120. +
  30121. +#ifdef CONFIG_PAX_KERNEXEC
  30122. +#ifdef CONFIG_X86_32
  30123. + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
  30124. + limit = (limit - 1UL) >> PAGE_SHIFT;
  30125. +
  30126. + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
  30127. + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
  30128. + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
  30129. + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
  30130. + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
  30131. + }
  30132. +
  30133. + /* PaX: make KERNEL_CS read-only */
  30134. + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
  30135. + if (!paravirt_enabled())
  30136. + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
  30137. +/*
  30138. + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
  30139. + pgd = pgd_offset_k(addr);
  30140. + pud = pud_offset(pgd, addr);
  30141. + pmd = pmd_offset(pud, addr);
  30142. + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
  30143. + }
  30144. +*/
  30145. +#ifdef CONFIG_X86_PAE
  30146. + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
  30147. +/*
  30148. + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
  30149. + pgd = pgd_offset_k(addr);
  30150. + pud = pud_offset(pgd, addr);
  30151. + pmd = pmd_offset(pud, addr);
  30152. + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
  30153. + }
  30154. +*/
  30155. +#endif
  30156. +
  30157. +#ifdef CONFIG_MODULES
  30158. + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
  30159. +#endif
  30160. +
  30161. +#else
  30162. + /* PaX: make kernel code/rodata read-only, rest non-executable */
  30163. + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
  30164. + pgd = pgd_offset_k(addr);
  30165. + pud = pud_offset(pgd, addr);
  30166. + pmd = pmd_offset(pud, addr);
  30167. + if (!pmd_present(*pmd))
  30168. + continue;
  30169. + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
  30170. + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
  30171. + else
  30172. + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
  30173. + }
  30174. +
  30175. + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
  30176. + end = addr + KERNEL_IMAGE_SIZE;
  30177. + for (; addr < end; addr += PMD_SIZE) {
  30178. + pgd = pgd_offset_k(addr);
  30179. + pud = pud_offset(pgd, addr);
  30180. + pmd = pmd_offset(pud, addr);
  30181. + if (!pmd_present(*pmd))
  30182. + continue;
  30183. + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
  30184. + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
  30185. + }
  30186. +#endif
  30187. +
  30188. + flush_tlb_all();
  30189. +#endif
  30190. +
  30191. free_init_pages("unused kernel",
  30192. (unsigned long)(&__init_begin),
  30193. (unsigned long)(&__init_end));
  30194. diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
  30195. index e395048..cd38278 100644
  30196. --- a/arch/x86/mm/init_32.c
  30197. +++ b/arch/x86/mm/init_32.c
  30198. @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
  30199. bool __read_mostly __vmalloc_start_set = false;
  30200. /*
  30201. - * Creates a middle page table and puts a pointer to it in the
  30202. - * given global directory entry. This only returns the gd entry
  30203. - * in non-PAE compilation mode, since the middle layer is folded.
  30204. - */
  30205. -static pmd_t * __init one_md_table_init(pgd_t *pgd)
  30206. -{
  30207. - pud_t *pud;
  30208. - pmd_t *pmd_table;
  30209. -
  30210. -#ifdef CONFIG_X86_PAE
  30211. - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
  30212. - pmd_table = (pmd_t *)alloc_low_page();
  30213. - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
  30214. - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
  30215. - pud = pud_offset(pgd, 0);
  30216. - BUG_ON(pmd_table != pmd_offset(pud, 0));
  30217. -
  30218. - return pmd_table;
  30219. - }
  30220. -#endif
  30221. - pud = pud_offset(pgd, 0);
  30222. - pmd_table = pmd_offset(pud, 0);
  30223. -
  30224. - return pmd_table;
  30225. -}
  30226. -
  30227. -/*
  30228. * Create a page table and place a pointer to it in a middle page
  30229. * directory entry:
  30230. */
  30231. @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
  30232. pte_t *page_table = (pte_t *)alloc_low_page();
  30233. paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
  30234. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  30235. + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
  30236. +#else
  30237. set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
  30238. +#endif
  30239. BUG_ON(page_table != pte_offset_kernel(pmd, 0));
  30240. }
  30241. return pte_offset_kernel(pmd, 0);
  30242. }
  30243. +static pmd_t * __init one_md_table_init(pgd_t *pgd)
  30244. +{
  30245. + pud_t *pud;
  30246. + pmd_t *pmd_table;
  30247. +
  30248. + pud = pud_offset(pgd, 0);
  30249. + pmd_table = pmd_offset(pud, 0);
  30250. +
  30251. + return pmd_table;
  30252. +}
  30253. +
  30254. pmd_t * __init populate_extra_pmd(unsigned long vaddr)
  30255. {
  30256. int pgd_idx = pgd_index(vaddr);
  30257. @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
  30258. int pgd_idx, pmd_idx;
  30259. unsigned long vaddr;
  30260. pgd_t *pgd;
  30261. + pud_t *pud;
  30262. pmd_t *pmd;
  30263. pte_t *pte = NULL;
  30264. unsigned long count = page_table_range_init_count(start, end);
  30265. @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
  30266. pgd = pgd_base + pgd_idx;
  30267. for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
  30268. - pmd = one_md_table_init(pgd);
  30269. - pmd = pmd + pmd_index(vaddr);
  30270. + pud = pud_offset(pgd, vaddr);
  30271. + pmd = pmd_offset(pud, vaddr);
  30272. +
  30273. +#ifdef CONFIG_X86_PAE
  30274. + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
  30275. +#endif
  30276. +
  30277. for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
  30278. pmd++, pmd_idx++) {
  30279. pte = page_table_kmap_check(one_page_table_init(pmd),
  30280. @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
  30281. }
  30282. }
  30283. -static inline int is_kernel_text(unsigned long addr)
  30284. +static inline int is_kernel_text(unsigned long start, unsigned long end)
  30285. {
  30286. - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
  30287. - return 1;
  30288. - return 0;
  30289. + if ((start >= ktla_ktva((unsigned long)_etext) ||
  30290. + end <= ktla_ktva((unsigned long)_stext)) &&
  30291. + (start >= ktla_ktva((unsigned long)_einittext) ||
  30292. + end <= ktla_ktva((unsigned long)_sinittext)) &&
  30293. +
  30294. +#ifdef CONFIG_ACPI_SLEEP
  30295. + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
  30296. +#endif
  30297. +
  30298. + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
  30299. + return 0;
  30300. + return 1;
  30301. }
  30302. /*
  30303. @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
  30304. unsigned long last_map_addr = end;
  30305. unsigned long start_pfn, end_pfn;
  30306. pgd_t *pgd_base = swapper_pg_dir;
  30307. - int pgd_idx, pmd_idx, pte_ofs;
  30308. + unsigned int pgd_idx, pmd_idx, pte_ofs;
  30309. unsigned long pfn;
  30310. pgd_t *pgd;
  30311. + pud_t *pud;
  30312. pmd_t *pmd;
  30313. pte_t *pte;
  30314. unsigned pages_2m, pages_4k;
  30315. @@ -291,8 +295,13 @@ repeat:
  30316. pfn = start_pfn;
  30317. pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
  30318. pgd = pgd_base + pgd_idx;
  30319. - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
  30320. - pmd = one_md_table_init(pgd);
  30321. + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
  30322. + pud = pud_offset(pgd, 0);
  30323. + pmd = pmd_offset(pud, 0);
  30324. +
  30325. +#ifdef CONFIG_X86_PAE
  30326. + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
  30327. +#endif
  30328. if (pfn >= end_pfn)
  30329. continue;
  30330. @@ -304,14 +313,13 @@ repeat:
  30331. #endif
  30332. for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
  30333. pmd++, pmd_idx++) {
  30334. - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
  30335. + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
  30336. /*
  30337. * Map with big pages if possible, otherwise
  30338. * create normal page tables:
  30339. */
  30340. if (use_pse) {
  30341. - unsigned int addr2;
  30342. pgprot_t prot = PAGE_KERNEL_LARGE;
  30343. /*
  30344. * first pass will use the same initial
  30345. @@ -322,11 +330,7 @@ repeat:
  30346. _PAGE_PSE);
  30347. pfn &= PMD_MASK >> PAGE_SHIFT;
  30348. - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
  30349. - PAGE_OFFSET + PAGE_SIZE-1;
  30350. -
  30351. - if (is_kernel_text(addr) ||
  30352. - is_kernel_text(addr2))
  30353. + if (is_kernel_text(address, address + PMD_SIZE))
  30354. prot = PAGE_KERNEL_LARGE_EXEC;
  30355. pages_2m++;
  30356. @@ -343,7 +347,7 @@ repeat:
  30357. pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
  30358. pte += pte_ofs;
  30359. for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
  30360. - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
  30361. + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
  30362. pgprot_t prot = PAGE_KERNEL;
  30363. /*
  30364. * first pass will use the same initial
  30365. @@ -351,7 +355,7 @@ repeat:
  30366. */
  30367. pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
  30368. - if (is_kernel_text(addr))
  30369. + if (is_kernel_text(address, address + PAGE_SIZE))
  30370. prot = PAGE_KERNEL_EXEC;
  30371. pages_4k++;
  30372. @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
  30373. pud = pud_offset(pgd, va);
  30374. pmd = pmd_offset(pud, va);
  30375. - if (!pmd_present(*pmd))
  30376. + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
  30377. break;
  30378. /* should not be large page here */
  30379. @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
  30380. static void __init pagetable_init(void)
  30381. {
  30382. - pgd_t *pgd_base = swapper_pg_dir;
  30383. -
  30384. - permanent_kmaps_init(pgd_base);
  30385. + permanent_kmaps_init(swapper_pg_dir);
  30386. }
  30387. -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
  30388. +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
  30389. EXPORT_SYMBOL_GPL(__supported_pte_mask);
  30390. /* user-defined highmem size */
  30391. @@ -787,10 +789,10 @@ void __init mem_init(void)
  30392. ((unsigned long)&__init_end -
  30393. (unsigned long)&__init_begin) >> 10,
  30394. - (unsigned long)&_etext, (unsigned long)&_edata,
  30395. - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
  30396. + (unsigned long)&_sdata, (unsigned long)&_edata,
  30397. + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
  30398. - (unsigned long)&_text, (unsigned long)&_etext,
  30399. + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
  30400. ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
  30401. /*
  30402. @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
  30403. if (!kernel_set_to_readonly)
  30404. return;
  30405. + start = ktla_ktva(start);
  30406. pr_debug("Set kernel text: %lx - %lx for read write\n",
  30407. start, start+size);
  30408. @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
  30409. if (!kernel_set_to_readonly)
  30410. return;
  30411. + start = ktla_ktva(start);
  30412. pr_debug("Set kernel text: %lx - %lx for read only\n",
  30413. start, start+size);
  30414. @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
  30415. unsigned long start = PFN_ALIGN(_text);
  30416. unsigned long size = PFN_ALIGN(_etext) - start;
  30417. + start = ktla_ktva(start);
  30418. set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
  30419. printk(KERN_INFO "Write protecting the kernel text: %luk\n",
  30420. size >> 10);
  30421. diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
  30422. index f35c66c..84b95ef 100644
  30423. --- a/arch/x86/mm/init_64.c
  30424. +++ b/arch/x86/mm/init_64.c
  30425. @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
  30426. * around without checking the pgd every time.
  30427. */
  30428. -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
  30429. +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
  30430. EXPORT_SYMBOL_GPL(__supported_pte_mask);
  30431. int force_personality32;
  30432. @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
  30433. for (address = start; address <= end; address += PGDIR_SIZE) {
  30434. const pgd_t *pgd_ref = pgd_offset_k(address);
  30435. +
  30436. +#ifdef CONFIG_PAX_PER_CPU_PGD
  30437. + unsigned long cpu;
  30438. +#else
  30439. struct page *page;
  30440. +#endif
  30441. if (pgd_none(*pgd_ref))
  30442. continue;
  30443. spin_lock(&pgd_lock);
  30444. +
  30445. +#ifdef CONFIG_PAX_PER_CPU_PGD
  30446. + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
  30447. + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
  30448. +
  30449. + if (pgd_none(*pgd))
  30450. + set_pgd(pgd, *pgd_ref);
  30451. + else
  30452. + BUG_ON(pgd_page_vaddr(*pgd)
  30453. + != pgd_page_vaddr(*pgd_ref));
  30454. + pgd = pgd_offset_cpu(cpu, kernel, address);
  30455. +#else
  30456. list_for_each_entry(page, &pgd_list, lru) {
  30457. pgd_t *pgd;
  30458. spinlock_t *pgt_lock;
  30459. @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
  30460. /* the pgt_lock only for Xen */
  30461. pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
  30462. spin_lock(pgt_lock);
  30463. +#endif
  30464. if (pgd_none(*pgd))
  30465. set_pgd(pgd, *pgd_ref);
  30466. @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
  30467. BUG_ON(pgd_page_vaddr(*pgd)
  30468. != pgd_page_vaddr(*pgd_ref));
  30469. +#ifndef CONFIG_PAX_PER_CPU_PGD
  30470. spin_unlock(pgt_lock);
  30471. +#endif
  30472. +
  30473. }
  30474. spin_unlock(&pgd_lock);
  30475. }
  30476. @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
  30477. {
  30478. if (pgd_none(*pgd)) {
  30479. pud_t *pud = (pud_t *)spp_getpage();
  30480. - pgd_populate(&init_mm, pgd, pud);
  30481. + pgd_populate_kernel(&init_mm, pgd, pud);
  30482. if (pud != pud_offset(pgd, 0))
  30483. printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
  30484. pud, pud_offset(pgd, 0));
  30485. @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
  30486. {
  30487. if (pud_none(*pud)) {
  30488. pmd_t *pmd = (pmd_t *) spp_getpage();
  30489. - pud_populate(&init_mm, pud, pmd);
  30490. + pud_populate_kernel(&init_mm, pud, pmd);
  30491. if (pmd != pmd_offset(pud, 0))
  30492. printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
  30493. pmd, pmd_offset(pud, 0));
  30494. @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
  30495. pmd = fill_pmd(pud, vaddr);
  30496. pte = fill_pte(pmd, vaddr);
  30497. + pax_open_kernel();
  30498. set_pte(pte, new_pte);
  30499. + pax_close_kernel();
  30500. /*
  30501. * It's enough to flush this one mapping.
  30502. @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
  30503. pgd = pgd_offset_k((unsigned long)__va(phys));
  30504. if (pgd_none(*pgd)) {
  30505. pud = (pud_t *) spp_getpage();
  30506. - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
  30507. - _PAGE_USER));
  30508. + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
  30509. }
  30510. pud = pud_offset(pgd, (unsigned long)__va(phys));
  30511. if (pud_none(*pud)) {
  30512. pmd = (pmd_t *) spp_getpage();
  30513. - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
  30514. - _PAGE_USER));
  30515. + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
  30516. }
  30517. pmd = pmd_offset(pud, phys);
  30518. BUG_ON(!pmd_none(*pmd));
  30519. @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
  30520. prot);
  30521. spin_lock(&init_mm.page_table_lock);
  30522. - pud_populate(&init_mm, pud, pmd);
  30523. + pud_populate_kernel(&init_mm, pud, pmd);
  30524. spin_unlock(&init_mm.page_table_lock);
  30525. }
  30526. __flush_tlb_all();
  30527. @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
  30528. page_size_mask);
  30529. spin_lock(&init_mm.page_table_lock);
  30530. - pgd_populate(&init_mm, pgd, pud);
  30531. + pgd_populate_kernel(&init_mm, pgd, pud);
  30532. spin_unlock(&init_mm.page_table_lock);
  30533. pgd_changed = true;
  30534. }
  30535. @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
  30536. static struct vm_area_struct gate_vma = {
  30537. .vm_start = VSYSCALL_START,
  30538. .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
  30539. - .vm_page_prot = PAGE_READONLY_EXEC,
  30540. - .vm_flags = VM_READ | VM_EXEC
  30541. + .vm_page_prot = PAGE_READONLY,
  30542. + .vm_flags = VM_READ
  30543. };
  30544. struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  30545. @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
  30546. const char *arch_vma_name(struct vm_area_struct *vma)
  30547. {
  30548. - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  30549. + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
  30550. return "[vdso]";
  30551. if (vma == &gate_vma)
  30552. return "[vsyscall]";
  30553. diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
  30554. index 7b179b4..6bd17777 100644
  30555. --- a/arch/x86/mm/iomap_32.c
  30556. +++ b/arch/x86/mm/iomap_32.c
  30557. @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
  30558. type = kmap_atomic_idx_push();
  30559. idx = type + KM_TYPE_NR * smp_processor_id();
  30560. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  30561. +
  30562. + pax_open_kernel();
  30563. set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
  30564. + pax_close_kernel();
  30565. +
  30566. arch_flush_lazy_mmu_mode();
  30567. return (void *)vaddr;
  30568. diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
  30569. index 799580c..72f9fe0 100644
  30570. --- a/arch/x86/mm/ioremap.c
  30571. +++ b/arch/x86/mm/ioremap.c
  30572. @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
  30573. for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
  30574. int is_ram = page_is_ram(pfn);
  30575. - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
  30576. + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
  30577. return NULL;
  30578. WARN_ON_ONCE(is_ram);
  30579. }
  30580. @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
  30581. *
  30582. * Caller must ensure there is only one unmapping for the same pointer.
  30583. */
  30584. -void iounmap(volatile void __iomem *addr)
  30585. +void iounmap(const volatile void __iomem *addr)
  30586. {
  30587. struct vm_struct *p, *o;
  30588. @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
  30589. /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
  30590. if (page_is_ram(start >> PAGE_SHIFT))
  30591. +#ifdef CONFIG_HIGHMEM
  30592. + if ((start >> PAGE_SHIFT) < max_low_pfn)
  30593. +#endif
  30594. return __va(phys);
  30595. addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
  30596. @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
  30597. void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
  30598. {
  30599. if (page_is_ram(phys >> PAGE_SHIFT))
  30600. +#ifdef CONFIG_HIGHMEM
  30601. + if ((phys >> PAGE_SHIFT) < max_low_pfn)
  30602. +#endif
  30603. return;
  30604. iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
  30605. @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
  30606. early_param("early_ioremap_debug", early_ioremap_debug_setup);
  30607. static __initdata int after_paging_init;
  30608. -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
  30609. +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
  30610. static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
  30611. {
  30612. @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
  30613. slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
  30614. pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
  30615. - memset(bm_pte, 0, sizeof(bm_pte));
  30616. - pmd_populate_kernel(&init_mm, pmd, bm_pte);
  30617. + pmd_populate_user(&init_mm, pmd, bm_pte);
  30618. /*
  30619. * The boot-ioremap range spans multiple pmds, for which
  30620. diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
  30621. index d87dd6d..bf3fa66 100644
  30622. --- a/arch/x86/mm/kmemcheck/kmemcheck.c
  30623. +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
  30624. @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
  30625. * memory (e.g. tracked pages)? For now, we need this to avoid
  30626. * invoking kmemcheck for PnP BIOS calls.
  30627. */
  30628. - if (regs->flags & X86_VM_MASK)
  30629. + if (v8086_mode(regs))
  30630. return false;
  30631. - if (regs->cs != __KERNEL_CS)
  30632. + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
  30633. return false;
  30634. pte = kmemcheck_pte_lookup(address);
  30635. diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
  30636. index 25e7e13..1964579 100644
  30637. --- a/arch/x86/mm/mmap.c
  30638. +++ b/arch/x86/mm/mmap.c
  30639. @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
  30640. * Leave an at least ~128 MB hole with possible stack randomization.
  30641. */
  30642. #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
  30643. -#define MAX_GAP (TASK_SIZE/6*5)
  30644. +#define MAX_GAP (pax_task_size/6*5)
  30645. static int mmap_is_legacy(void)
  30646. {
  30647. @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
  30648. return rnd << PAGE_SHIFT;
  30649. }
  30650. -static unsigned long mmap_base(void)
  30651. +static unsigned long mmap_base(struct mm_struct *mm)
  30652. {
  30653. unsigned long gap = rlimit(RLIMIT_STACK);
  30654. + unsigned long pax_task_size = TASK_SIZE;
  30655. +
  30656. +#ifdef CONFIG_PAX_SEGMEXEC
  30657. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  30658. + pax_task_size = SEGMEXEC_TASK_SIZE;
  30659. +#endif
  30660. if (gap < MIN_GAP)
  30661. gap = MIN_GAP;
  30662. else if (gap > MAX_GAP)
  30663. gap = MAX_GAP;
  30664. - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
  30665. + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
  30666. }
  30667. /*
  30668. * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
  30669. * does, but not when emulating X86_32
  30670. */
  30671. -static unsigned long mmap_legacy_base(void)
  30672. +static unsigned long mmap_legacy_base(struct mm_struct *mm)
  30673. {
  30674. - if (mmap_is_ia32())
  30675. + if (mmap_is_ia32()) {
  30676. +
  30677. +#ifdef CONFIG_PAX_SEGMEXEC
  30678. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  30679. + return SEGMEXEC_TASK_UNMAPPED_BASE;
  30680. + else
  30681. +#endif
  30682. +
  30683. return TASK_UNMAPPED_BASE;
  30684. - else
  30685. + } else
  30686. return TASK_UNMAPPED_BASE + mmap_rnd();
  30687. }
  30688. @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
  30689. */
  30690. void arch_pick_mmap_layout(struct mm_struct *mm)
  30691. {
  30692. - mm->mmap_legacy_base = mmap_legacy_base();
  30693. - mm->mmap_base = mmap_base();
  30694. + mm->mmap_legacy_base = mmap_legacy_base(mm);
  30695. + mm->mmap_base = mmap_base(mm);
  30696. +
  30697. +#ifdef CONFIG_PAX_RANDMMAP
  30698. + if (mm->pax_flags & MF_PAX_RANDMMAP) {
  30699. + mm->mmap_legacy_base += mm->delta_mmap;
  30700. + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
  30701. + }
  30702. +#endif
  30703. if (mmap_is_legacy()) {
  30704. mm->mmap_base = mm->mmap_legacy_base;
  30705. diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
  30706. index 0057a7a..95c7edd 100644
  30707. --- a/arch/x86/mm/mmio-mod.c
  30708. +++ b/arch/x86/mm/mmio-mod.c
  30709. @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
  30710. break;
  30711. default:
  30712. {
  30713. - unsigned char *ip = (unsigned char *)instptr;
  30714. + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
  30715. my_trace->opcode = MMIO_UNKNOWN_OP;
  30716. my_trace->width = 0;
  30717. my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
  30718. @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
  30719. static void ioremap_trace_core(resource_size_t offset, unsigned long size,
  30720. void __iomem *addr)
  30721. {
  30722. - static atomic_t next_id;
  30723. + static atomic_unchecked_t next_id;
  30724. struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
  30725. /* These are page-unaligned. */
  30726. struct mmiotrace_map map = {
  30727. @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
  30728. .private = trace
  30729. },
  30730. .phys = offset,
  30731. - .id = atomic_inc_return(&next_id)
  30732. + .id = atomic_inc_return_unchecked(&next_id)
  30733. };
  30734. map.map_id = trace->id;
  30735. @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
  30736. ioremap_trace_core(offset, size, addr);
  30737. }
  30738. -static void iounmap_trace_core(volatile void __iomem *addr)
  30739. +static void iounmap_trace_core(const volatile void __iomem *addr)
  30740. {
  30741. struct mmiotrace_map map = {
  30742. .phys = 0,
  30743. @@ -328,7 +328,7 @@ not_enabled:
  30744. }
  30745. }
  30746. -void mmiotrace_iounmap(volatile void __iomem *addr)
  30747. +void mmiotrace_iounmap(const volatile void __iomem *addr)
  30748. {
  30749. might_sleep();
  30750. if (is_enabled()) /* recheck and proper locking in *_core() */
  30751. diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
  30752. index 27aa0455..0eb1406 100644
  30753. --- a/arch/x86/mm/numa.c
  30754. +++ b/arch/x86/mm/numa.c
  30755. @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
  30756. return true;
  30757. }
  30758. -static int __init numa_register_memblks(struct numa_meminfo *mi)
  30759. +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
  30760. {
  30761. unsigned long uninitialized_var(pfn_align);
  30762. int i, nid;
  30763. diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
  30764. index 461bc82..4e091a3 100644
  30765. --- a/arch/x86/mm/pageattr-test.c
  30766. +++ b/arch/x86/mm/pageattr-test.c
  30767. @@ -35,7 +35,7 @@ enum {
  30768. static int pte_testbit(pte_t pte)
  30769. {
  30770. - return pte_flags(pte) & _PAGE_UNUSED1;
  30771. + return pte_flags(pte) & _PAGE_CPA_TEST;
  30772. }
  30773. struct split_state {
  30774. diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
  30775. index a348868..3c64310 100644
  30776. --- a/arch/x86/mm/pageattr.c
  30777. +++ b/arch/x86/mm/pageattr.c
  30778. @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
  30779. */
  30780. #ifdef CONFIG_PCI_BIOS
  30781. if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
  30782. - pgprot_val(forbidden) |= _PAGE_NX;
  30783. + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
  30784. #endif
  30785. /*
  30786. @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
  30787. * Does not cover __inittext since that is gone later on. On
  30788. * 64bit we do not enforce !NX on the low mapping
  30789. */
  30790. - if (within(address, (unsigned long)_text, (unsigned long)_etext))
  30791. - pgprot_val(forbidden) |= _PAGE_NX;
  30792. + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
  30793. + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
  30794. +#ifdef CONFIG_DEBUG_RODATA
  30795. /*
  30796. * The .rodata section needs to be read-only. Using the pfn
  30797. * catches all aliases.
  30798. @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
  30799. if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
  30800. __pa_symbol(__end_rodata) >> PAGE_SHIFT))
  30801. pgprot_val(forbidden) |= _PAGE_RW;
  30802. +#endif
  30803. #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
  30804. /*
  30805. @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
  30806. }
  30807. #endif
  30808. +#ifdef CONFIG_PAX_KERNEXEC
  30809. + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
  30810. + pgprot_val(forbidden) |= _PAGE_RW;
  30811. + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
  30812. + }
  30813. +#endif
  30814. +
  30815. prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
  30816. return prot;
  30817. @@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
  30818. static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
  30819. {
  30820. /* change init_mm */
  30821. + pax_open_kernel();
  30822. set_pte_atomic(kpte, pte);
  30823. +
  30824. #ifdef CONFIG_X86_32
  30825. if (!SHARED_KERNEL_PMD) {
  30826. +
  30827. +#ifdef CONFIG_PAX_PER_CPU_PGD
  30828. + unsigned long cpu;
  30829. +#else
  30830. struct page *page;
  30831. +#endif
  30832. +#ifdef CONFIG_PAX_PER_CPU_PGD
  30833. + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
  30834. + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
  30835. +#else
  30836. list_for_each_entry(page, &pgd_list, lru) {
  30837. - pgd_t *pgd;
  30838. + pgd_t *pgd = (pgd_t *)page_address(page);
  30839. +#endif
  30840. +
  30841. pud_t *pud;
  30842. pmd_t *pmd;
  30843. - pgd = (pgd_t *)page_address(page) + pgd_index(address);
  30844. + pgd += pgd_index(address);
  30845. pud = pud_offset(pgd, address);
  30846. pmd = pmd_offset(pud, address);
  30847. set_pte_atomic((pte_t *)pmd, pte);
  30848. }
  30849. }
  30850. #endif
  30851. + pax_close_kernel();
  30852. }
  30853. static int
  30854. diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
  30855. index 6574388..87e9bef 100644
  30856. --- a/arch/x86/mm/pat.c
  30857. +++ b/arch/x86/mm/pat.c
  30858. @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
  30859. if (!entry) {
  30860. printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
  30861. - current->comm, current->pid, start, end - 1);
  30862. + current->comm, task_pid_nr(current), start, end - 1);
  30863. return -EINVAL;
  30864. }
  30865. @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
  30866. while (cursor < to) {
  30867. if (!devmem_is_allowed(pfn)) {
  30868. - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
  30869. - current->comm, from, to - 1);
  30870. + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
  30871. + current->comm, from, to - 1, cursor);
  30872. return 0;
  30873. }
  30874. cursor += PAGE_SIZE;
  30875. @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
  30876. if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
  30877. printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
  30878. "for [mem %#010Lx-%#010Lx]\n",
  30879. - current->comm, current->pid,
  30880. + current->comm, task_pid_nr(current),
  30881. cattr_name(flags),
  30882. base, (unsigned long long)(base + size-1));
  30883. return -EINVAL;
  30884. @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
  30885. flags = lookup_memtype(paddr);
  30886. if (want_flags != flags) {
  30887. printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
  30888. - current->comm, current->pid,
  30889. + current->comm, task_pid_nr(current),
  30890. cattr_name(want_flags),
  30891. (unsigned long long)paddr,
  30892. (unsigned long long)(paddr + size - 1),
  30893. @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
  30894. free_memtype(paddr, paddr + size);
  30895. printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
  30896. " for [mem %#010Lx-%#010Lx], got %s\n",
  30897. - current->comm, current->pid,
  30898. + current->comm, task_pid_nr(current),
  30899. cattr_name(want_flags),
  30900. (unsigned long long)paddr,
  30901. (unsigned long long)(paddr + size - 1),
  30902. diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
  30903. index 415f6c4..d319983 100644
  30904. --- a/arch/x86/mm/pat_rbtree.c
  30905. +++ b/arch/x86/mm/pat_rbtree.c
  30906. @@ -160,7 +160,7 @@ success:
  30907. failure:
  30908. printk(KERN_INFO "%s:%d conflicting memory types "
  30909. - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
  30910. + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
  30911. end, cattr_name(found_type), cattr_name(match->type));
  30912. return -EBUSY;
  30913. }
  30914. diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
  30915. index 9f0614d..92ae64a 100644
  30916. --- a/arch/x86/mm/pf_in.c
  30917. +++ b/arch/x86/mm/pf_in.c
  30918. @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
  30919. int i;
  30920. enum reason_type rv = OTHERS;
  30921. - p = (unsigned char *)ins_addr;
  30922. + p = (unsigned char *)ktla_ktva(ins_addr);
  30923. p += skip_prefix(p, &prf);
  30924. p += get_opcode(p, &opcode);
  30925. @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
  30926. struct prefix_bits prf;
  30927. int i;
  30928. - p = (unsigned char *)ins_addr;
  30929. + p = (unsigned char *)ktla_ktva(ins_addr);
  30930. p += skip_prefix(p, &prf);
  30931. p += get_opcode(p, &opcode);
  30932. @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
  30933. struct prefix_bits prf;
  30934. int i;
  30935. - p = (unsigned char *)ins_addr;
  30936. + p = (unsigned char *)ktla_ktva(ins_addr);
  30937. p += skip_prefix(p, &prf);
  30938. p += get_opcode(p, &opcode);
  30939. @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
  30940. struct prefix_bits prf;
  30941. int i;
  30942. - p = (unsigned char *)ins_addr;
  30943. + p = (unsigned char *)ktla_ktva(ins_addr);
  30944. p += skip_prefix(p, &prf);
  30945. p += get_opcode(p, &opcode);
  30946. for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
  30947. @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
  30948. struct prefix_bits prf;
  30949. int i;
  30950. - p = (unsigned char *)ins_addr;
  30951. + p = (unsigned char *)ktla_ktva(ins_addr);
  30952. p += skip_prefix(p, &prf);
  30953. p += get_opcode(p, &opcode);
  30954. for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
  30955. diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
  30956. index c96314a..433b127 100644
  30957. --- a/arch/x86/mm/pgtable.c
  30958. +++ b/arch/x86/mm/pgtable.c
  30959. @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
  30960. list_del(&page->lru);
  30961. }
  30962. -#define UNSHARED_PTRS_PER_PGD \
  30963. - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
  30964. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  30965. +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
  30966. +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
  30967. +{
  30968. + unsigned int count = USER_PGD_PTRS;
  30969. + if (!pax_user_shadow_base)
  30970. + return;
  30971. +
  30972. + while (count--)
  30973. + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
  30974. +}
  30975. +#endif
  30976. +
  30977. +#ifdef CONFIG_PAX_PER_CPU_PGD
  30978. +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
  30979. +{
  30980. + unsigned int count = USER_PGD_PTRS;
  30981. +
  30982. + while (count--) {
  30983. + pgd_t pgd;
  30984. +
  30985. +#ifdef CONFIG_X86_64
  30986. + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
  30987. +#else
  30988. + pgd = *src++;
  30989. +#endif
  30990. +
  30991. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  30992. + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
  30993. +#endif
  30994. +
  30995. + *dst++ = pgd;
  30996. + }
  30997. +
  30998. +}
  30999. +#endif
  31000. +
  31001. +#ifdef CONFIG_X86_64
  31002. +#define pxd_t pud_t
  31003. +#define pyd_t pgd_t
  31004. +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
  31005. +#define pgtable_pxd_page_ctor(page) true
  31006. +#define pgtable_pxd_page_dtor(page)
  31007. +#define pxd_free(mm, pud) pud_free((mm), (pud))
  31008. +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
  31009. +#define pyd_offset(mm, address) pgd_offset((mm), (address))
  31010. +#define PYD_SIZE PGDIR_SIZE
  31011. +#else
  31012. +#define pxd_t pmd_t
  31013. +#define pyd_t pud_t
  31014. +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
  31015. +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
  31016. +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
  31017. +#define pxd_free(mm, pud) pmd_free((mm), (pud))
  31018. +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
  31019. +#define pyd_offset(mm, address) pud_offset((mm), (address))
  31020. +#define PYD_SIZE PUD_SIZE
  31021. +#endif
  31022. +
  31023. +#ifdef CONFIG_PAX_PER_CPU_PGD
  31024. +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
  31025. +static inline void pgd_dtor(pgd_t *pgd) {}
  31026. +#else
  31027. static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
  31028. {
  31029. BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
  31030. @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
  31031. pgd_list_del(pgd);
  31032. spin_unlock(&pgd_lock);
  31033. }
  31034. +#endif
  31035. /*
  31036. * List of all pgd's needed for non-PAE so it can invalidate entries
  31037. @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
  31038. * -- nyc
  31039. */
  31040. -#ifdef CONFIG_X86_PAE
  31041. +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
  31042. /*
  31043. * In PAE mode, we need to do a cr3 reload (=tlb flush) when
  31044. * updating the top-level pagetable entries to guarantee the
  31045. @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
  31046. * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
  31047. * and initialize the kernel pmds here.
  31048. */
  31049. -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
  31050. +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
  31051. void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
  31052. {
  31053. @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
  31054. */
  31055. flush_tlb_mm(mm);
  31056. }
  31057. +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
  31058. +#define PREALLOCATED_PXDS USER_PGD_PTRS
  31059. #else /* !CONFIG_X86_PAE */
  31060. /* No need to prepopulate any pagetable entries in non-PAE modes. */
  31061. -#define PREALLOCATED_PMDS 0
  31062. +#define PREALLOCATED_PXDS 0
  31063. #endif /* CONFIG_X86_PAE */
  31064. -static void free_pmds(pmd_t *pmds[])
  31065. +static void free_pxds(pxd_t *pxds[])
  31066. {
  31067. int i;
  31068. - for(i = 0; i < PREALLOCATED_PMDS; i++)
  31069. - if (pmds[i]) {
  31070. - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
  31071. - free_page((unsigned long)pmds[i]);
  31072. + for(i = 0; i < PREALLOCATED_PXDS; i++)
  31073. + if (pxds[i]) {
  31074. + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
  31075. + free_page((unsigned long)pxds[i]);
  31076. }
  31077. }
  31078. -static int preallocate_pmds(pmd_t *pmds[])
  31079. +static int preallocate_pxds(pxd_t *pxds[])
  31080. {
  31081. int i;
  31082. bool failed = false;
  31083. - for(i = 0; i < PREALLOCATED_PMDS; i++) {
  31084. - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
  31085. - if (!pmd)
  31086. + for(i = 0; i < PREALLOCATED_PXDS; i++) {
  31087. + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
  31088. + if (!pxd)
  31089. failed = true;
  31090. - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
  31091. - free_page((unsigned long)pmd);
  31092. - pmd = NULL;
  31093. + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
  31094. + free_page((unsigned long)pxd);
  31095. + pxd = NULL;
  31096. failed = true;
  31097. }
  31098. - pmds[i] = pmd;
  31099. + pxds[i] = pxd;
  31100. }
  31101. if (failed) {
  31102. - free_pmds(pmds);
  31103. + free_pxds(pxds);
  31104. return -ENOMEM;
  31105. }
  31106. @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
  31107. * preallocate which never got a corresponding vma will need to be
  31108. * freed manually.
  31109. */
  31110. -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
  31111. +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
  31112. {
  31113. int i;
  31114. - for(i = 0; i < PREALLOCATED_PMDS; i++) {
  31115. + for(i = 0; i < PREALLOCATED_PXDS; i++) {
  31116. pgd_t pgd = pgdp[i];
  31117. if (pgd_val(pgd) != 0) {
  31118. - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
  31119. + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
  31120. - pgdp[i] = native_make_pgd(0);
  31121. + set_pgd(pgdp + i, native_make_pgd(0));
  31122. - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
  31123. - pmd_free(mm, pmd);
  31124. + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
  31125. + pxd_free(mm, pxd);
  31126. }
  31127. }
  31128. }
  31129. -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
  31130. +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
  31131. {
  31132. - pud_t *pud;
  31133. + pyd_t *pyd;
  31134. int i;
  31135. - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
  31136. + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
  31137. return;
  31138. - pud = pud_offset(pgd, 0);
  31139. -
  31140. - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
  31141. - pmd_t *pmd = pmds[i];
  31142. +#ifdef CONFIG_X86_64
  31143. + pyd = pyd_offset(mm, 0L);
  31144. +#else
  31145. + pyd = pyd_offset(pgd, 0L);
  31146. +#endif
  31147. + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
  31148. + pxd_t *pxd = pxds[i];
  31149. if (i >= KERNEL_PGD_BOUNDARY)
  31150. - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
  31151. - sizeof(pmd_t) * PTRS_PER_PMD);
  31152. + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
  31153. + sizeof(pxd_t) * PTRS_PER_PMD);
  31154. - pud_populate(mm, pud, pmd);
  31155. + pyd_populate(mm, pyd, pxd);
  31156. }
  31157. }
  31158. pgd_t *pgd_alloc(struct mm_struct *mm)
  31159. {
  31160. pgd_t *pgd;
  31161. - pmd_t *pmds[PREALLOCATED_PMDS];
  31162. + pxd_t *pxds[PREALLOCATED_PXDS];
  31163. pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
  31164. @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
  31165. mm->pgd = pgd;
  31166. - if (preallocate_pmds(pmds) != 0)
  31167. + if (preallocate_pxds(pxds) != 0)
  31168. goto out_free_pgd;
  31169. if (paravirt_pgd_alloc(mm) != 0)
  31170. - goto out_free_pmds;
  31171. + goto out_free_pxds;
  31172. /*
  31173. * Make sure that pre-populating the pmds is atomic with
  31174. @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
  31175. spin_lock(&pgd_lock);
  31176. pgd_ctor(mm, pgd);
  31177. - pgd_prepopulate_pmd(mm, pgd, pmds);
  31178. + pgd_prepopulate_pxd(mm, pgd, pxds);
  31179. spin_unlock(&pgd_lock);
  31180. return pgd;
  31181. -out_free_pmds:
  31182. - free_pmds(pmds);
  31183. +out_free_pxds:
  31184. + free_pxds(pxds);
  31185. out_free_pgd:
  31186. free_page((unsigned long)pgd);
  31187. out:
  31188. @@ -313,7 +380,7 @@ out:
  31189. void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  31190. {
  31191. - pgd_mop_up_pmds(mm, pgd);
  31192. + pgd_mop_up_pxds(mm, pgd);
  31193. pgd_dtor(pgd);
  31194. paravirt_pgd_free(mm, pgd);
  31195. free_page((unsigned long)pgd);
  31196. diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
  31197. index a69bcb8..19068ab 100644
  31198. --- a/arch/x86/mm/pgtable_32.c
  31199. +++ b/arch/x86/mm/pgtable_32.c
  31200. @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
  31201. return;
  31202. }
  31203. pte = pte_offset_kernel(pmd, vaddr);
  31204. +
  31205. + pax_open_kernel();
  31206. if (pte_val(pteval))
  31207. set_pte_at(&init_mm, vaddr, pte, pteval);
  31208. else
  31209. pte_clear(&init_mm, vaddr, pte);
  31210. + pax_close_kernel();
  31211. /*
  31212. * It's enough to flush this one mapping.
  31213. diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
  31214. index e666cbb..61788c45 100644
  31215. --- a/arch/x86/mm/physaddr.c
  31216. +++ b/arch/x86/mm/physaddr.c
  31217. @@ -10,7 +10,7 @@
  31218. #ifdef CONFIG_X86_64
  31219. #ifdef CONFIG_DEBUG_VIRTUAL
  31220. -unsigned long __phys_addr(unsigned long x)
  31221. +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
  31222. {
  31223. unsigned long y = x - __START_KERNEL_map;
  31224. @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
  31225. #else
  31226. #ifdef CONFIG_DEBUG_VIRTUAL
  31227. -unsigned long __phys_addr(unsigned long x)
  31228. +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
  31229. {
  31230. unsigned long phys_addr = x - PAGE_OFFSET;
  31231. /* VMALLOC_* aren't constants */
  31232. diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
  31233. index 90555bf..f5f1828 100644
  31234. --- a/arch/x86/mm/setup_nx.c
  31235. +++ b/arch/x86/mm/setup_nx.c
  31236. @@ -5,8 +5,10 @@
  31237. #include <asm/pgtable.h>
  31238. #include <asm/proto.h>
  31239. +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  31240. static int disable_nx;
  31241. +#ifndef CONFIG_PAX_PAGEEXEC
  31242. /*
  31243. * noexec = on|off
  31244. *
  31245. @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
  31246. return 0;
  31247. }
  31248. early_param("noexec", noexec_setup);
  31249. +#endif
  31250. +
  31251. +#endif
  31252. void x86_configure_nx(void)
  31253. {
  31254. +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  31255. if (cpu_has_nx && !disable_nx)
  31256. __supported_pte_mask |= _PAGE_NX;
  31257. else
  31258. +#endif
  31259. __supported_pte_mask &= ~_PAGE_NX;
  31260. }
  31261. diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
  31262. index dd8dda1..9e9b0f6 100644
  31263. --- a/arch/x86/mm/tlb.c
  31264. +++ b/arch/x86/mm/tlb.c
  31265. @@ -48,7 +48,11 @@ void leave_mm(int cpu)
  31266. BUG();
  31267. if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
  31268. cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
  31269. +
  31270. +#ifndef CONFIG_PAX_PER_CPU_PGD
  31271. load_cr3(swapper_pg_dir);
  31272. +#endif
  31273. +
  31274. }
  31275. }
  31276. EXPORT_SYMBOL_GPL(leave_mm);
  31277. diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
  31278. new file mode 100644
  31279. index 0000000..dace51c
  31280. --- /dev/null
  31281. +++ b/arch/x86/mm/uderef_64.c
  31282. @@ -0,0 +1,37 @@
  31283. +#include <linux/mm.h>
  31284. +#include <asm/pgtable.h>
  31285. +#include <asm/uaccess.h>
  31286. +
  31287. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  31288. +/* PaX: due to the special call convention these functions must
  31289. + * - remain leaf functions under all configurations,
  31290. + * - never be called directly, only dereferenced from the wrappers.
  31291. + */
  31292. +void __pax_open_userland(void)
  31293. +{
  31294. + unsigned int cpu;
  31295. +
  31296. + if (unlikely(!segment_eq(get_fs(), USER_DS)))
  31297. + return;
  31298. +
  31299. + cpu = raw_get_cpu();
  31300. + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
  31301. + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
  31302. + raw_put_cpu_no_resched();
  31303. +}
  31304. +EXPORT_SYMBOL(__pax_open_userland);
  31305. +
  31306. +void __pax_close_userland(void)
  31307. +{
  31308. + unsigned int cpu;
  31309. +
  31310. + if (unlikely(!segment_eq(get_fs(), USER_DS)))
  31311. + return;
  31312. +
  31313. + cpu = raw_get_cpu();
  31314. + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
  31315. + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
  31316. + raw_put_cpu_no_resched();
  31317. +}
  31318. +EXPORT_SYMBOL(__pax_close_userland);
  31319. +#endif
  31320. diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
  31321. index 0149575..f746de8 100644
  31322. --- a/arch/x86/net/bpf_jit.S
  31323. +++ b/arch/x86/net/bpf_jit.S
  31324. @@ -9,6 +9,7 @@
  31325. */
  31326. #include <linux/linkage.h>
  31327. #include <asm/dwarf2.h>
  31328. +#include <asm/alternative-asm.h>
  31329. /*
  31330. * Calling convention :
  31331. @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
  31332. jle bpf_slow_path_word
  31333. mov (SKBDATA,%rsi),%eax
  31334. bswap %eax /* ntohl() */
  31335. + pax_force_retaddr
  31336. ret
  31337. sk_load_half:
  31338. @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
  31339. jle bpf_slow_path_half
  31340. movzwl (SKBDATA,%rsi),%eax
  31341. rol $8,%ax # ntohs()
  31342. + pax_force_retaddr
  31343. ret
  31344. sk_load_byte:
  31345. @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
  31346. cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
  31347. jle bpf_slow_path_byte
  31348. movzbl (SKBDATA,%rsi),%eax
  31349. + pax_force_retaddr
  31350. ret
  31351. /**
  31352. @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
  31353. movzbl (SKBDATA,%rsi),%ebx
  31354. and $15,%bl
  31355. shl $2,%bl
  31356. + pax_force_retaddr
  31357. ret
  31358. /* rsi contains offset and can be scratched */
  31359. @@ -109,6 +114,7 @@ bpf_slow_path_word:
  31360. js bpf_error
  31361. mov -12(%rbp),%eax
  31362. bswap %eax
  31363. + pax_force_retaddr
  31364. ret
  31365. bpf_slow_path_half:
  31366. @@ -117,12 +123,14 @@ bpf_slow_path_half:
  31367. mov -12(%rbp),%ax
  31368. rol $8,%ax
  31369. movzwl %ax,%eax
  31370. + pax_force_retaddr
  31371. ret
  31372. bpf_slow_path_byte:
  31373. bpf_slow_path_common(1)
  31374. js bpf_error
  31375. movzbl -12(%rbp),%eax
  31376. + pax_force_retaddr
  31377. ret
  31378. bpf_slow_path_byte_msh:
  31379. @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
  31380. and $15,%al
  31381. shl $2,%al
  31382. xchg %eax,%ebx
  31383. + pax_force_retaddr
  31384. ret
  31385. #define sk_negative_common(SIZE) \
  31386. @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
  31387. sk_negative_common(4)
  31388. mov (%rax), %eax
  31389. bswap %eax
  31390. + pax_force_retaddr
  31391. ret
  31392. bpf_slow_path_half_neg:
  31393. @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
  31394. mov (%rax),%ax
  31395. rol $8,%ax
  31396. movzwl %ax,%eax
  31397. + pax_force_retaddr
  31398. ret
  31399. bpf_slow_path_byte_neg:
  31400. @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
  31401. .globl sk_load_byte_negative_offset
  31402. sk_negative_common(1)
  31403. movzbl (%rax), %eax
  31404. + pax_force_retaddr
  31405. ret
  31406. bpf_slow_path_byte_msh_neg:
  31407. @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
  31408. and $15,%al
  31409. shl $2,%al
  31410. xchg %eax,%ebx
  31411. + pax_force_retaddr
  31412. ret
  31413. bpf_error:
  31414. @@ -197,4 +210,5 @@ bpf_error:
  31415. xor %eax,%eax
  31416. mov -8(%rbp),%rbx
  31417. leaveq
  31418. + pax_force_retaddr
  31419. ret
  31420. diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
  31421. index 4ed75dd..3cf24f0b 100644
  31422. --- a/arch/x86/net/bpf_jit_comp.c
  31423. +++ b/arch/x86/net/bpf_jit_comp.c
  31424. @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
  31425. return ptr + len;
  31426. }
  31427. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31428. +#define MAX_INSTR_CODE_SIZE 96
  31429. +#else
  31430. +#define MAX_INSTR_CODE_SIZE 64
  31431. +#endif
  31432. +
  31433. #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
  31434. #define EMIT1(b1) EMIT(b1, 1)
  31435. #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
  31436. #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
  31437. #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
  31438. +
  31439. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31440. +/* original constant will appear in ecx */
  31441. +#define DILUTE_CONST_SEQUENCE(_off, _key) \
  31442. +do { \
  31443. + /* mov ecx, randkey */ \
  31444. + EMIT1(0xb9); \
  31445. + EMIT(_key, 4); \
  31446. + /* xor ecx, randkey ^ off */ \
  31447. + EMIT2(0x81, 0xf1); \
  31448. + EMIT((_key) ^ (_off), 4); \
  31449. +} while (0)
  31450. +
  31451. +#define EMIT1_off32(b1, _off) \
  31452. +do { \
  31453. + switch (b1) { \
  31454. + case 0x05: /* add eax, imm32 */ \
  31455. + case 0x2d: /* sub eax, imm32 */ \
  31456. + case 0x25: /* and eax, imm32 */ \
  31457. + case 0x0d: /* or eax, imm32 */ \
  31458. + case 0xb8: /* mov eax, imm32 */ \
  31459. + case 0x35: /* xor eax, imm32 */ \
  31460. + case 0x3d: /* cmp eax, imm32 */ \
  31461. + case 0xa9: /* test eax, imm32 */ \
  31462. + DILUTE_CONST_SEQUENCE(_off, randkey); \
  31463. + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
  31464. + break; \
  31465. + case 0xbb: /* mov ebx, imm32 */ \
  31466. + DILUTE_CONST_SEQUENCE(_off, randkey); \
  31467. + /* mov ebx, ecx */ \
  31468. + EMIT2(0x89, 0xcb); \
  31469. + break; \
  31470. + case 0xbe: /* mov esi, imm32 */ \
  31471. + DILUTE_CONST_SEQUENCE(_off, randkey); \
  31472. + /* mov esi, ecx */ \
  31473. + EMIT2(0x89, 0xce); \
  31474. + break; \
  31475. + case 0xe8: /* call rel imm32, always to known funcs */ \
  31476. + EMIT1(b1); \
  31477. + EMIT(_off, 4); \
  31478. + break; \
  31479. + case 0xe9: /* jmp rel imm32 */ \
  31480. + EMIT1(b1); \
  31481. + EMIT(_off, 4); \
  31482. + /* prevent fall-through, we're not called if off = 0 */ \
  31483. + EMIT(0xcccccccc, 4); \
  31484. + EMIT(0xcccccccc, 4); \
  31485. + break; \
  31486. + default: \
  31487. + BUILD_BUG(); \
  31488. + } \
  31489. +} while (0)
  31490. +
  31491. +#define EMIT2_off32(b1, b2, _off) \
  31492. +do { \
  31493. + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
  31494. + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
  31495. + EMIT(randkey, 4); \
  31496. + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
  31497. + EMIT((_off) - randkey, 4); \
  31498. + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
  31499. + DILUTE_CONST_SEQUENCE(_off, randkey); \
  31500. + /* imul eax, ecx */ \
  31501. + EMIT3(0x0f, 0xaf, 0xc1); \
  31502. + } else { \
  31503. + BUILD_BUG(); \
  31504. + } \
  31505. +} while (0)
  31506. +#else
  31507. #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
  31508. +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
  31509. +#endif
  31510. #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
  31511. #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
  31512. @@ -91,6 +168,24 @@ do { \
  31513. #define X86_JBE 0x76
  31514. #define X86_JA 0x77
  31515. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31516. +#define APPEND_FLOW_VERIFY() \
  31517. +do { \
  31518. + /* mov ecx, randkey */ \
  31519. + EMIT1(0xb9); \
  31520. + EMIT(randkey, 4); \
  31521. + /* cmp ecx, randkey */ \
  31522. + EMIT2(0x81, 0xf9); \
  31523. + EMIT(randkey, 4); \
  31524. + /* jz after 8 int 3s */ \
  31525. + EMIT2(0x74, 0x08); \
  31526. + EMIT(0xcccccccc, 4); \
  31527. + EMIT(0xcccccccc, 4); \
  31528. +} while (0)
  31529. +#else
  31530. +#define APPEND_FLOW_VERIFY() do { } while (0)
  31531. +#endif
  31532. +
  31533. #define EMIT_COND_JMP(op, offset) \
  31534. do { \
  31535. if (is_near(offset)) \
  31536. @@ -98,6 +193,7 @@ do { \
  31537. else { \
  31538. EMIT2(0x0f, op + 0x10); \
  31539. EMIT(offset, 4); /* jxx .+off32 */ \
  31540. + APPEND_FLOW_VERIFY(); \
  31541. } \
  31542. } while (0)
  31543. @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
  31544. return -1;
  31545. }
  31546. -struct bpf_binary_header {
  31547. - unsigned int pages;
  31548. - /* Note : for security reasons, bpf code will follow a randomly
  31549. - * sized amount of int3 instructions
  31550. - */
  31551. - u8 image[];
  31552. -};
  31553. -
  31554. -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
  31555. +/* Note : for security reasons, bpf code will follow a randomly
  31556. + * sized amount of int3 instructions
  31557. + */
  31558. +static u8 *bpf_alloc_binary(unsigned int proglen,
  31559. u8 **image_ptr)
  31560. {
  31561. unsigned int sz, hole;
  31562. - struct bpf_binary_header *header;
  31563. + u8 *header;
  31564. /* Most of BPF filters are really small,
  31565. * but if some of them fill a page, allow at least
  31566. * 128 extra bytes to insert a random section of int3
  31567. */
  31568. - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
  31569. - header = module_alloc(sz);
  31570. + sz = round_up(proglen + 128, PAGE_SIZE);
  31571. + header = module_alloc_exec(sz);
  31572. if (!header)
  31573. return NULL;
  31574. + pax_open_kernel();
  31575. memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
  31576. + pax_close_kernel();
  31577. - header->pages = sz / PAGE_SIZE;
  31578. - hole = sz - (proglen + sizeof(*header));
  31579. + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
  31580. /* insert a random number of int3 instructions before BPF code */
  31581. - *image_ptr = &header->image[prandom_u32() % hole];
  31582. + *image_ptr = &header[prandom_u32() % hole];
  31583. return header;
  31584. }
  31585. void bpf_jit_compile(struct sk_filter *fp)
  31586. {
  31587. - u8 temp[64];
  31588. + u8 temp[MAX_INSTR_CODE_SIZE];
  31589. u8 *prog;
  31590. unsigned int proglen, oldproglen = 0;
  31591. int ilen, i;
  31592. int t_offset, f_offset;
  31593. u8 t_op, f_op, seen = 0, pass;
  31594. u8 *image = NULL;
  31595. - struct bpf_binary_header *header = NULL;
  31596. + u8 *header = NULL;
  31597. u8 *func;
  31598. int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
  31599. unsigned int cleanup_addr; /* epilogue code offset */
  31600. unsigned int *addrs;
  31601. const struct sock_filter *filter = fp->insns;
  31602. int flen = fp->len;
  31603. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31604. + unsigned int randkey;
  31605. +#endif
  31606. if (!bpf_jit_enable)
  31607. return;
  31608. @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
  31609. return;
  31610. /* Before first pass, make a rough estimation of addrs[]
  31611. - * each bpf instruction is translated to less than 64 bytes
  31612. + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
  31613. */
  31614. for (proglen = 0, i = 0; i < flen; i++) {
  31615. - proglen += 64;
  31616. + proglen += MAX_INSTR_CODE_SIZE;
  31617. addrs[i] = proglen;
  31618. }
  31619. cleanup_addr = proglen; /* epilogue address */
  31620. @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
  31621. for (i = 0; i < flen; i++) {
  31622. unsigned int K = filter[i].k;
  31623. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31624. + randkey = prandom_u32();
  31625. +#endif
  31626. +
  31627. switch (filter[i].code) {
  31628. case BPF_S_ALU_ADD_X: /* A += X; */
  31629. seen |= SEEN_XREG;
  31630. @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
  31631. case BPF_S_ALU_MUL_K: /* A *= K */
  31632. if (is_imm8(K))
  31633. EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
  31634. - else {
  31635. - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
  31636. - EMIT(K, 4);
  31637. - }
  31638. + else
  31639. + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
  31640. break;
  31641. case BPF_S_ALU_DIV_X: /* A /= X; */
  31642. seen |= SEEN_XREG;
  31643. @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
  31644. break;
  31645. }
  31646. EMIT2(0x31, 0xd2); /* xor %edx,%edx */
  31647. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31648. + DILUTE_CONST_SEQUENCE(K, randkey);
  31649. +#else
  31650. EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
  31651. +#endif
  31652. EMIT2(0xf7, 0xf1); /* div %ecx */
  31653. EMIT2(0x89, 0xd0); /* mov %edx,%eax */
  31654. break;
  31655. @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
  31656. if (K == 1)
  31657. break;
  31658. EMIT2(0x31, 0xd2); /* xor %edx,%edx */
  31659. +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
  31660. + DILUTE_CONST_SEQUENCE(K, randkey);
  31661. +#else
  31662. EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
  31663. +#endif
  31664. EMIT2(0xf7, 0xf1); /* div %ecx */
  31665. break;
  31666. case BPF_S_ALU_AND_X:
  31667. @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
  31668. if (is_imm8(K)) {
  31669. EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
  31670. } else {
  31671. - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
  31672. - EMIT(K, 4);
  31673. + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
  31674. }
  31675. } else {
  31676. EMIT2(0x89,0xde); /* mov %ebx,%esi */
  31677. @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
  31678. if (unlikely(proglen + ilen > oldproglen)) {
  31679. pr_err("bpb_jit_compile fatal error\n");
  31680. kfree(addrs);
  31681. - module_free(NULL, header);
  31682. + module_free_exec(NULL, image);
  31683. return;
  31684. }
  31685. + pax_open_kernel();
  31686. memcpy(image + proglen, temp, ilen);
  31687. + pax_close_kernel();
  31688. }
  31689. proglen += ilen;
  31690. addrs[i] = proglen;
  31691. @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
  31692. if (image) {
  31693. bpf_flush_icache(header, image + proglen);
  31694. - set_memory_ro((unsigned long)header, header->pages);
  31695. fp->bpf_func = (void *)image;
  31696. }
  31697. out:
  31698. @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
  31699. {
  31700. struct sk_filter *fp = container_of(work, struct sk_filter, work);
  31701. unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
  31702. - struct bpf_binary_header *header = (void *)addr;
  31703. - set_memory_rw(addr, header->pages);
  31704. - module_free(NULL, header);
  31705. + set_memory_rw(addr, 1);
  31706. + module_free_exec(NULL, (void *)addr);
  31707. kfree(fp);
  31708. }
  31709. diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
  31710. index 5d04be5..2beeaa2 100644
  31711. --- a/arch/x86/oprofile/backtrace.c
  31712. +++ b/arch/x86/oprofile/backtrace.c
  31713. @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
  31714. struct stack_frame_ia32 *fp;
  31715. unsigned long bytes;
  31716. - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
  31717. + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
  31718. if (bytes != 0)
  31719. return NULL;
  31720. - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
  31721. + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
  31722. oprofile_add_trace(bufhead[0].return_address);
  31723. @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
  31724. struct stack_frame bufhead[2];
  31725. unsigned long bytes;
  31726. - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
  31727. + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
  31728. if (bytes != 0)
  31729. return NULL;
  31730. @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
  31731. {
  31732. struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
  31733. - if (!user_mode_vm(regs)) {
  31734. + if (!user_mode(regs)) {
  31735. unsigned long stack = kernel_stack_pointer(regs);
  31736. if (depth)
  31737. dump_trace(NULL, regs, (unsigned long *)stack, 0,
  31738. diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
  31739. index 6890d84..1dad1f1 100644
  31740. --- a/arch/x86/oprofile/nmi_int.c
  31741. +++ b/arch/x86/oprofile/nmi_int.c
  31742. @@ -23,6 +23,7 @@
  31743. #include <asm/nmi.h>
  31744. #include <asm/msr.h>
  31745. #include <asm/apic.h>
  31746. +#include <asm/pgtable.h>
  31747. #include "op_counter.h"
  31748. #include "op_x86_model.h"
  31749. @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
  31750. if (ret)
  31751. return ret;
  31752. - if (!model->num_virt_counters)
  31753. - model->num_virt_counters = model->num_counters;
  31754. + if (!model->num_virt_counters) {
  31755. + pax_open_kernel();
  31756. + *(unsigned int *)&model->num_virt_counters = model->num_counters;
  31757. + pax_close_kernel();
  31758. + }
  31759. mux_init(ops);
  31760. diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
  31761. index 50d86c0..7985318 100644
  31762. --- a/arch/x86/oprofile/op_model_amd.c
  31763. +++ b/arch/x86/oprofile/op_model_amd.c
  31764. @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
  31765. num_counters = AMD64_NUM_COUNTERS;
  31766. }
  31767. - op_amd_spec.num_counters = num_counters;
  31768. - op_amd_spec.num_controls = num_counters;
  31769. - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
  31770. + pax_open_kernel();
  31771. + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
  31772. + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
  31773. + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
  31774. + pax_close_kernel();
  31775. return 0;
  31776. }
  31777. diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
  31778. index d90528e..0127e2b 100644
  31779. --- a/arch/x86/oprofile/op_model_ppro.c
  31780. +++ b/arch/x86/oprofile/op_model_ppro.c
  31781. @@ -19,6 +19,7 @@
  31782. #include <asm/msr.h>
  31783. #include <asm/apic.h>
  31784. #include <asm/nmi.h>
  31785. +#include <asm/pgtable.h>
  31786. #include "op_x86_model.h"
  31787. #include "op_counter.h"
  31788. @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
  31789. num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
  31790. - op_arch_perfmon_spec.num_counters = num_counters;
  31791. - op_arch_perfmon_spec.num_controls = num_counters;
  31792. + pax_open_kernel();
  31793. + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
  31794. + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
  31795. + pax_close_kernel();
  31796. }
  31797. static int arch_perfmon_init(struct oprofile_operations *ignore)
  31798. diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
  31799. index 71e8a67..6a313bb 100644
  31800. --- a/arch/x86/oprofile/op_x86_model.h
  31801. +++ b/arch/x86/oprofile/op_x86_model.h
  31802. @@ -52,7 +52,7 @@ struct op_x86_model_spec {
  31803. void (*switch_ctrl)(struct op_x86_model_spec const *model,
  31804. struct op_msrs const * const msrs);
  31805. #endif
  31806. -};
  31807. +} __do_const;
  31808. struct op_counter_config;
  31809. diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
  31810. index 84b9d67..260e5ff 100644
  31811. --- a/arch/x86/pci/intel_mid_pci.c
  31812. +++ b/arch/x86/pci/intel_mid_pci.c
  31813. @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
  31814. pr_info("Intel MID platform detected, using MID PCI ops\n");
  31815. pci_mmcfg_late_init();
  31816. pcibios_enable_irq = intel_mid_pci_irq_enable;
  31817. - pci_root_ops = intel_mid_pci_ops;
  31818. + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
  31819. pci_soc_mode = 1;
  31820. /* Continue with standard init */
  31821. return 1;
  31822. diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
  31823. index 372e9b8..e775a6c 100644
  31824. --- a/arch/x86/pci/irq.c
  31825. +++ b/arch/x86/pci/irq.c
  31826. @@ -50,7 +50,7 @@ struct irq_router {
  31827. struct irq_router_handler {
  31828. u16 vendor;
  31829. int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
  31830. -};
  31831. +} __do_const;
  31832. int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
  31833. void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
  31834. @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
  31835. return 0;
  31836. }
  31837. -static __initdata struct irq_router_handler pirq_routers[] = {
  31838. +static __initconst const struct irq_router_handler pirq_routers[] = {
  31839. { PCI_VENDOR_ID_INTEL, intel_router_probe },
  31840. { PCI_VENDOR_ID_AL, ali_router_probe },
  31841. { PCI_VENDOR_ID_ITE, ite_router_probe },
  31842. @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
  31843. static void __init pirq_find_router(struct irq_router *r)
  31844. {
  31845. struct irq_routing_table *rt = pirq_table;
  31846. - struct irq_router_handler *h;
  31847. + const struct irq_router_handler *h;
  31848. #ifdef CONFIG_PCI_BIOS
  31849. if (!rt->signature) {
  31850. @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
  31851. return 0;
  31852. }
  31853. -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
  31854. +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
  31855. {
  31856. .callback = fix_broken_hp_bios_irq9,
  31857. .ident = "HP Pavilion N5400 Series Laptop",
  31858. diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
  31859. index c77b24a..c979855 100644
  31860. --- a/arch/x86/pci/pcbios.c
  31861. +++ b/arch/x86/pci/pcbios.c
  31862. @@ -79,7 +79,7 @@ union bios32 {
  31863. static struct {
  31864. unsigned long address;
  31865. unsigned short segment;
  31866. -} bios32_indirect = { 0, __KERNEL_CS };
  31867. +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
  31868. /*
  31869. * Returns the entry point for the given service, NULL on error
  31870. @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
  31871. unsigned long length; /* %ecx */
  31872. unsigned long entry; /* %edx */
  31873. unsigned long flags;
  31874. + struct desc_struct d, *gdt;
  31875. local_irq_save(flags);
  31876. - __asm__("lcall *(%%edi); cld"
  31877. +
  31878. + gdt = get_cpu_gdt_table(smp_processor_id());
  31879. +
  31880. + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
  31881. + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
  31882. + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
  31883. + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
  31884. +
  31885. + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
  31886. : "=a" (return_code),
  31887. "=b" (address),
  31888. "=c" (length),
  31889. "=d" (entry)
  31890. : "0" (service),
  31891. "1" (0),
  31892. - "D" (&bios32_indirect));
  31893. + "D" (&bios32_indirect),
  31894. + "r"(__PCIBIOS_DS)
  31895. + : "memory");
  31896. +
  31897. + pax_open_kernel();
  31898. + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
  31899. + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
  31900. + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
  31901. + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
  31902. + pax_close_kernel();
  31903. +
  31904. local_irq_restore(flags);
  31905. switch (return_code) {
  31906. - case 0:
  31907. - return address + entry;
  31908. - case 0x80: /* Not present */
  31909. - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
  31910. - return 0;
  31911. - default: /* Shouldn't happen */
  31912. - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
  31913. - service, return_code);
  31914. + case 0: {
  31915. + int cpu;
  31916. + unsigned char flags;
  31917. +
  31918. + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
  31919. + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
  31920. + printk(KERN_WARNING "bios32_service: not valid\n");
  31921. return 0;
  31922. + }
  31923. + address = address + PAGE_OFFSET;
  31924. + length += 16UL; /* some BIOSs underreport this... */
  31925. + flags = 4;
  31926. + if (length >= 64*1024*1024) {
  31927. + length >>= PAGE_SHIFT;
  31928. + flags |= 8;
  31929. + }
  31930. +
  31931. + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
  31932. + gdt = get_cpu_gdt_table(cpu);
  31933. + pack_descriptor(&d, address, length, 0x9b, flags);
  31934. + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
  31935. + pack_descriptor(&d, address, length, 0x93, flags);
  31936. + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
  31937. + }
  31938. + return entry;
  31939. + }
  31940. + case 0x80: /* Not present */
  31941. + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
  31942. + return 0;
  31943. + default: /* Shouldn't happen */
  31944. + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
  31945. + service, return_code);
  31946. + return 0;
  31947. }
  31948. }
  31949. static struct {
  31950. unsigned long address;
  31951. unsigned short segment;
  31952. -} pci_indirect = { 0, __KERNEL_CS };
  31953. +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
  31954. -static int pci_bios_present;
  31955. +static int pci_bios_present __read_only;
  31956. static int check_pcibios(void)
  31957. {
  31958. @@ -131,11 +174,13 @@ static int check_pcibios(void)
  31959. unsigned long flags, pcibios_entry;
  31960. if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
  31961. - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
  31962. + pci_indirect.address = pcibios_entry;
  31963. local_irq_save(flags);
  31964. - __asm__(
  31965. - "lcall *(%%edi); cld\n\t"
  31966. + __asm__("movw %w6, %%ds\n\t"
  31967. + "lcall *%%ss:(%%edi); cld\n\t"
  31968. + "push %%ss\n\t"
  31969. + "pop %%ds\n\t"
  31970. "jc 1f\n\t"
  31971. "xor %%ah, %%ah\n"
  31972. "1:"
  31973. @@ -144,7 +189,8 @@ static int check_pcibios(void)
  31974. "=b" (ebx),
  31975. "=c" (ecx)
  31976. : "1" (PCIBIOS_PCI_BIOS_PRESENT),
  31977. - "D" (&pci_indirect)
  31978. + "D" (&pci_indirect),
  31979. + "r" (__PCIBIOS_DS)
  31980. : "memory");
  31981. local_irq_restore(flags);
  31982. @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
  31983. switch (len) {
  31984. case 1:
  31985. - __asm__("lcall *(%%esi); cld\n\t"
  31986. + __asm__("movw %w6, %%ds\n\t"
  31987. + "lcall *%%ss:(%%esi); cld\n\t"
  31988. + "push %%ss\n\t"
  31989. + "pop %%ds\n\t"
  31990. "jc 1f\n\t"
  31991. "xor %%ah, %%ah\n"
  31992. "1:"
  31993. @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
  31994. : "1" (PCIBIOS_READ_CONFIG_BYTE),
  31995. "b" (bx),
  31996. "D" ((long)reg),
  31997. - "S" (&pci_indirect));
  31998. + "S" (&pci_indirect),
  31999. + "r" (__PCIBIOS_DS));
  32000. /*
  32001. * Zero-extend the result beyond 8 bits, do not trust the
  32002. * BIOS having done it:
  32003. @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
  32004. *value &= 0xff;
  32005. break;
  32006. case 2:
  32007. - __asm__("lcall *(%%esi); cld\n\t"
  32008. + __asm__("movw %w6, %%ds\n\t"
  32009. + "lcall *%%ss:(%%esi); cld\n\t"
  32010. + "push %%ss\n\t"
  32011. + "pop %%ds\n\t"
  32012. "jc 1f\n\t"
  32013. "xor %%ah, %%ah\n"
  32014. "1:"
  32015. @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
  32016. : "1" (PCIBIOS_READ_CONFIG_WORD),
  32017. "b" (bx),
  32018. "D" ((long)reg),
  32019. - "S" (&pci_indirect));
  32020. + "S" (&pci_indirect),
  32021. + "r" (__PCIBIOS_DS));
  32022. /*
  32023. * Zero-extend the result beyond 16 bits, do not trust the
  32024. * BIOS having done it:
  32025. @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
  32026. *value &= 0xffff;
  32027. break;
  32028. case 4:
  32029. - __asm__("lcall *(%%esi); cld\n\t"
  32030. + __asm__("movw %w6, %%ds\n\t"
  32031. + "lcall *%%ss:(%%esi); cld\n\t"
  32032. + "push %%ss\n\t"
  32033. + "pop %%ds\n\t"
  32034. "jc 1f\n\t"
  32035. "xor %%ah, %%ah\n"
  32036. "1:"
  32037. @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
  32038. : "1" (PCIBIOS_READ_CONFIG_DWORD),
  32039. "b" (bx),
  32040. "D" ((long)reg),
  32041. - "S" (&pci_indirect));
  32042. + "S" (&pci_indirect),
  32043. + "r" (__PCIBIOS_DS));
  32044. break;
  32045. }
  32046. @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
  32047. switch (len) {
  32048. case 1:
  32049. - __asm__("lcall *(%%esi); cld\n\t"
  32050. + __asm__("movw %w6, %%ds\n\t"
  32051. + "lcall *%%ss:(%%esi); cld\n\t"
  32052. + "push %%ss\n\t"
  32053. + "pop %%ds\n\t"
  32054. "jc 1f\n\t"
  32055. "xor %%ah, %%ah\n"
  32056. "1:"
  32057. @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
  32058. "c" (value),
  32059. "b" (bx),
  32060. "D" ((long)reg),
  32061. - "S" (&pci_indirect));
  32062. + "S" (&pci_indirect),
  32063. + "r" (__PCIBIOS_DS));
  32064. break;
  32065. case 2:
  32066. - __asm__("lcall *(%%esi); cld\n\t"
  32067. + __asm__("movw %w6, %%ds\n\t"
  32068. + "lcall *%%ss:(%%esi); cld\n\t"
  32069. + "push %%ss\n\t"
  32070. + "pop %%ds\n\t"
  32071. "jc 1f\n\t"
  32072. "xor %%ah, %%ah\n"
  32073. "1:"
  32074. @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
  32075. "c" (value),
  32076. "b" (bx),
  32077. "D" ((long)reg),
  32078. - "S" (&pci_indirect));
  32079. + "S" (&pci_indirect),
  32080. + "r" (__PCIBIOS_DS));
  32081. break;
  32082. case 4:
  32083. - __asm__("lcall *(%%esi); cld\n\t"
  32084. + __asm__("movw %w6, %%ds\n\t"
  32085. + "lcall *%%ss:(%%esi); cld\n\t"
  32086. + "push %%ss\n\t"
  32087. + "pop %%ds\n\t"
  32088. "jc 1f\n\t"
  32089. "xor %%ah, %%ah\n"
  32090. "1:"
  32091. @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
  32092. "c" (value),
  32093. "b" (bx),
  32094. "D" ((long)reg),
  32095. - "S" (&pci_indirect));
  32096. + "S" (&pci_indirect),
  32097. + "r" (__PCIBIOS_DS));
  32098. break;
  32099. }
  32100. @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
  32101. DBG("PCI: Fetching IRQ routing table... ");
  32102. __asm__("push %%es\n\t"
  32103. + "movw %w8, %%ds\n\t"
  32104. "push %%ds\n\t"
  32105. "pop %%es\n\t"
  32106. - "lcall *(%%esi); cld\n\t"
  32107. + "lcall *%%ss:(%%esi); cld\n\t"
  32108. "pop %%es\n\t"
  32109. + "push %%ss\n\t"
  32110. + "pop %%ds\n"
  32111. "jc 1f\n\t"
  32112. "xor %%ah, %%ah\n"
  32113. "1:"
  32114. @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
  32115. "1" (0),
  32116. "D" ((long) &opt),
  32117. "S" (&pci_indirect),
  32118. - "m" (opt)
  32119. + "m" (opt),
  32120. + "r" (__PCIBIOS_DS)
  32121. : "memory");
  32122. DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
  32123. if (ret & 0xff00)
  32124. @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
  32125. {
  32126. int ret;
  32127. - __asm__("lcall *(%%esi); cld\n\t"
  32128. + __asm__("movw %w5, %%ds\n\t"
  32129. + "lcall *%%ss:(%%esi); cld\n\t"
  32130. + "push %%ss\n\t"
  32131. + "pop %%ds\n"
  32132. "jc 1f\n\t"
  32133. "xor %%ah, %%ah\n"
  32134. "1:"
  32135. @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
  32136. : "0" (PCIBIOS_SET_PCI_HW_INT),
  32137. "b" ((dev->bus->number << 8) | dev->devfn),
  32138. "c" ((irq << 8) | (pin + 10)),
  32139. - "S" (&pci_indirect));
  32140. + "S" (&pci_indirect),
  32141. + "r" (__PCIBIOS_DS));
  32142. return !(ret & 0xff00);
  32143. }
  32144. EXPORT_SYMBOL(pcibios_set_irq_routing);
  32145. diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
  32146. index 9ee3491..872192f 100644
  32147. --- a/arch/x86/platform/efi/efi_32.c
  32148. +++ b/arch/x86/platform/efi/efi_32.c
  32149. @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
  32150. {
  32151. struct desc_ptr gdt_descr;
  32152. +#ifdef CONFIG_PAX_KERNEXEC
  32153. + struct desc_struct d;
  32154. +#endif
  32155. +
  32156. local_irq_save(efi_rt_eflags);
  32157. load_cr3(initial_page_table);
  32158. __flush_tlb_all();
  32159. +#ifdef CONFIG_PAX_KERNEXEC
  32160. + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
  32161. + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
  32162. + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
  32163. + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
  32164. +#endif
  32165. +
  32166. gdt_descr.address = __pa(get_cpu_gdt_table(0));
  32167. gdt_descr.size = GDT_SIZE - 1;
  32168. load_gdt(&gdt_descr);
  32169. @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
  32170. {
  32171. struct desc_ptr gdt_descr;
  32172. +#ifdef CONFIG_PAX_KERNEXEC
  32173. + struct desc_struct d;
  32174. +
  32175. + memset(&d, 0, sizeof d);
  32176. + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
  32177. + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
  32178. +#endif
  32179. +
  32180. gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
  32181. gdt_descr.size = GDT_SIZE - 1;
  32182. load_gdt(&gdt_descr);
  32183. +#ifdef CONFIG_PAX_PER_CPU_PGD
  32184. + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
  32185. +#else
  32186. load_cr3(swapper_pg_dir);
  32187. +#endif
  32188. +
  32189. __flush_tlb_all();
  32190. local_irq_restore(efi_rt_eflags);
  32191. diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
  32192. index 666b74a..673d88f 100644
  32193. --- a/arch/x86/platform/efi/efi_64.c
  32194. +++ b/arch/x86/platform/efi/efi_64.c
  32195. @@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
  32196. vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
  32197. set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
  32198. }
  32199. +
  32200. +#ifdef CONFIG_PAX_PER_CPU_PGD
  32201. + load_cr3(swapper_pg_dir);
  32202. +#endif
  32203. +
  32204. __flush_tlb_all();
  32205. }
  32206. @@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
  32207. for (pgd = 0; pgd < n_pgds; pgd++)
  32208. set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
  32209. kfree(save_pgd);
  32210. +
  32211. +#ifdef CONFIG_PAX_PER_CPU_PGD
  32212. + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
  32213. +#endif
  32214. +
  32215. __flush_tlb_all();
  32216. local_irq_restore(efi_flags);
  32217. early_code_mapping_set_exec(0);
  32218. diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
  32219. index fbe66e6..eae5e38 100644
  32220. --- a/arch/x86/platform/efi/efi_stub_32.S
  32221. +++ b/arch/x86/platform/efi/efi_stub_32.S
  32222. @@ -6,7 +6,9 @@
  32223. */
  32224. #include <linux/linkage.h>
  32225. +#include <linux/init.h>
  32226. #include <asm/page_types.h>
  32227. +#include <asm/segment.h>
  32228. /*
  32229. * efi_call_phys(void *, ...) is a function with variable parameters.
  32230. @@ -20,7 +22,7 @@
  32231. * service functions will comply with gcc calling convention, too.
  32232. */
  32233. -.text
  32234. +__INIT
  32235. ENTRY(efi_call_phys)
  32236. /*
  32237. * 0. The function can only be called in Linux kernel. So CS has been
  32238. @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
  32239. * The mapping of lower virtual memory has been created in prelog and
  32240. * epilog.
  32241. */
  32242. - movl $1f, %edx
  32243. - subl $__PAGE_OFFSET, %edx
  32244. - jmp *%edx
  32245. +#ifdef CONFIG_PAX_KERNEXEC
  32246. + movl $(__KERNEXEC_EFI_DS), %edx
  32247. + mov %edx, %ds
  32248. + mov %edx, %es
  32249. + mov %edx, %ss
  32250. + addl $2f,(1f)
  32251. + ljmp *(1f)
  32252. +
  32253. +__INITDATA
  32254. +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
  32255. +.previous
  32256. +
  32257. +2:
  32258. + subl $2b,(1b)
  32259. +#else
  32260. + jmp 1f-__PAGE_OFFSET
  32261. 1:
  32262. +#endif
  32263. /*
  32264. * 2. Now on the top of stack is the return
  32265. @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
  32266. * parameter 2, ..., param n. To make things easy, we save the return
  32267. * address of efi_call_phys in a global variable.
  32268. */
  32269. - popl %edx
  32270. - movl %edx, saved_return_addr
  32271. - /* get the function pointer into ECX*/
  32272. - popl %ecx
  32273. - movl %ecx, efi_rt_function_ptr
  32274. - movl $2f, %edx
  32275. - subl $__PAGE_OFFSET, %edx
  32276. - pushl %edx
  32277. + popl (saved_return_addr)
  32278. + popl (efi_rt_function_ptr)
  32279. /*
  32280. * 3. Clear PG bit in %CR0.
  32281. @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
  32282. /*
  32283. * 5. Call the physical function.
  32284. */
  32285. - jmp *%ecx
  32286. + call *(efi_rt_function_ptr-__PAGE_OFFSET)
  32287. -2:
  32288. /*
  32289. * 6. After EFI runtime service returns, control will return to
  32290. * following instruction. We'd better readjust stack pointer first.
  32291. @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
  32292. movl %cr0, %edx
  32293. orl $0x80000000, %edx
  32294. movl %edx, %cr0
  32295. - jmp 1f
  32296. -1:
  32297. +
  32298. /*
  32299. * 8. Now restore the virtual mode from flat mode by
  32300. * adding EIP with PAGE_OFFSET.
  32301. */
  32302. - movl $1f, %edx
  32303. - jmp *%edx
  32304. +#ifdef CONFIG_PAX_KERNEXEC
  32305. + movl $(__KERNEL_DS), %edx
  32306. + mov %edx, %ds
  32307. + mov %edx, %es
  32308. + mov %edx, %ss
  32309. + ljmp $(__KERNEL_CS),$1f
  32310. +#else
  32311. + jmp 1f+__PAGE_OFFSET
  32312. +#endif
  32313. 1:
  32314. /*
  32315. * 9. Balance the stack. And because EAX contain the return value,
  32316. * we'd better not clobber it.
  32317. */
  32318. - leal efi_rt_function_ptr, %edx
  32319. - movl (%edx), %ecx
  32320. - pushl %ecx
  32321. + pushl (efi_rt_function_ptr)
  32322. /*
  32323. - * 10. Push the saved return address onto the stack and return.
  32324. + * 10. Return to the saved return address.
  32325. */
  32326. - leal saved_return_addr, %edx
  32327. - movl (%edx), %ecx
  32328. - pushl %ecx
  32329. - ret
  32330. + jmpl *(saved_return_addr)
  32331. ENDPROC(efi_call_phys)
  32332. .previous
  32333. -.data
  32334. +__INITDATA
  32335. saved_return_addr:
  32336. .long 0
  32337. efi_rt_function_ptr:
  32338. diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
  32339. index 88073b1..1cc2f53 100644
  32340. --- a/arch/x86/platform/efi/efi_stub_64.S
  32341. +++ b/arch/x86/platform/efi/efi_stub_64.S
  32342. @@ -7,6 +7,7 @@
  32343. */
  32344. #include <linux/linkage.h>
  32345. +#include <asm/alternative-asm.h>
  32346. #define SAVE_XMM \
  32347. mov %rsp, %rax; \
  32348. @@ -77,6 +78,7 @@ ENTRY(efi_call0)
  32349. RESTORE_PGT
  32350. addq $32, %rsp
  32351. RESTORE_XMM
  32352. + pax_force_retaddr 0, 1
  32353. ret
  32354. ENDPROC(efi_call0)
  32355. @@ -89,6 +91,7 @@ ENTRY(efi_call1)
  32356. RESTORE_PGT
  32357. addq $32, %rsp
  32358. RESTORE_XMM
  32359. + pax_force_retaddr 0, 1
  32360. ret
  32361. ENDPROC(efi_call1)
  32362. @@ -101,6 +104,7 @@ ENTRY(efi_call2)
  32363. RESTORE_PGT
  32364. addq $32, %rsp
  32365. RESTORE_XMM
  32366. + pax_force_retaddr 0, 1
  32367. ret
  32368. ENDPROC(efi_call2)
  32369. @@ -114,6 +118,7 @@ ENTRY(efi_call3)
  32370. RESTORE_PGT
  32371. addq $32, %rsp
  32372. RESTORE_XMM
  32373. + pax_force_retaddr 0, 1
  32374. ret
  32375. ENDPROC(efi_call3)
  32376. @@ -128,6 +133,7 @@ ENTRY(efi_call4)
  32377. RESTORE_PGT
  32378. addq $32, %rsp
  32379. RESTORE_XMM
  32380. + pax_force_retaddr 0, 1
  32381. ret
  32382. ENDPROC(efi_call4)
  32383. @@ -143,6 +149,7 @@ ENTRY(efi_call5)
  32384. RESTORE_PGT
  32385. addq $48, %rsp
  32386. RESTORE_XMM
  32387. + pax_force_retaddr 0, 1
  32388. ret
  32389. ENDPROC(efi_call5)
  32390. @@ -161,6 +168,7 @@ ENTRY(efi_call6)
  32391. RESTORE_PGT
  32392. addq $48, %rsp
  32393. RESTORE_XMM
  32394. + pax_force_retaddr 0, 1
  32395. ret
  32396. ENDPROC(efi_call6)
  32397. diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
  32398. index 1bbedc4..eb795b5 100644
  32399. --- a/arch/x86/platform/intel-mid/intel-mid.c
  32400. +++ b/arch/x86/platform/intel-mid/intel-mid.c
  32401. @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
  32402. {
  32403. };
  32404. -static void intel_mid_reboot(void)
  32405. +static void __noreturn intel_mid_reboot(void)
  32406. {
  32407. intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
  32408. + BUG();
  32409. }
  32410. static unsigned long __init intel_mid_calibrate_tsc(void)
  32411. diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
  32412. index d6ee929..3637cb5 100644
  32413. --- a/arch/x86/platform/olpc/olpc_dt.c
  32414. +++ b/arch/x86/platform/olpc/olpc_dt.c
  32415. @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
  32416. return res;
  32417. }
  32418. -static struct of_pdt_ops prom_olpc_ops __initdata = {
  32419. +static struct of_pdt_ops prom_olpc_ops __initconst = {
  32420. .nextprop = olpc_dt_nextprop,
  32421. .getproplen = olpc_dt_getproplen,
  32422. .getproperty = olpc_dt_getproperty,
  32423. diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
  32424. index 424f4c9..f2a2988 100644
  32425. --- a/arch/x86/power/cpu.c
  32426. +++ b/arch/x86/power/cpu.c
  32427. @@ -137,11 +137,8 @@ static void do_fpu_end(void)
  32428. static void fix_processor_context(void)
  32429. {
  32430. int cpu = smp_processor_id();
  32431. - struct tss_struct *t = &per_cpu(init_tss, cpu);
  32432. -#ifdef CONFIG_X86_64
  32433. - struct desc_struct *desc = get_cpu_gdt_table(cpu);
  32434. - tss_desc tss;
  32435. -#endif
  32436. + struct tss_struct *t = init_tss + cpu;
  32437. +
  32438. set_tss_desc(cpu, t); /*
  32439. * This just modifies memory; should not be
  32440. * necessary. But... This is necessary, because
  32441. @@ -150,10 +147,6 @@ static void fix_processor_context(void)
  32442. */
  32443. #ifdef CONFIG_X86_64
  32444. - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
  32445. - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
  32446. - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
  32447. -
  32448. syscall_init(); /* This sets MSR_*STAR and related */
  32449. #endif
  32450. load_TR_desc(); /* This does ltr */
  32451. diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
  32452. index bad628a..a102610 100644
  32453. --- a/arch/x86/realmode/init.c
  32454. +++ b/arch/x86/realmode/init.c
  32455. @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
  32456. __va(real_mode_header->trampoline_header);
  32457. #ifdef CONFIG_X86_32
  32458. - trampoline_header->start = __pa_symbol(startup_32_smp);
  32459. + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
  32460. +
  32461. +#ifdef CONFIG_PAX_KERNEXEC
  32462. + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
  32463. +#endif
  32464. +
  32465. + trampoline_header->boot_cs = __BOOT_CS;
  32466. trampoline_header->gdt_limit = __BOOT_DS + 7;
  32467. trampoline_header->gdt_base = __pa_symbol(boot_gdt);
  32468. #else
  32469. @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
  32470. *trampoline_cr4_features = read_cr4();
  32471. trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
  32472. - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
  32473. + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
  32474. trampoline_pgd[511] = init_level4_pgt[511].pgd;
  32475. #endif
  32476. }
  32477. diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
  32478. index 3497f14..cc73b92 100644
  32479. --- a/arch/x86/realmode/rm/Makefile
  32480. +++ b/arch/x86/realmode/rm/Makefile
  32481. @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
  32482. KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
  32483. -I$(srctree)/arch/x86/boot
  32484. +ifdef CONSTIFY_PLUGIN
  32485. +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
  32486. +endif
  32487. KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
  32488. GCOV_PROFILE := n
  32489. diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
  32490. index a28221d..93c40f1 100644
  32491. --- a/arch/x86/realmode/rm/header.S
  32492. +++ b/arch/x86/realmode/rm/header.S
  32493. @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
  32494. #endif
  32495. /* APM/BIOS reboot */
  32496. .long pa_machine_real_restart_asm
  32497. -#ifdef CONFIG_X86_64
  32498. +#ifdef CONFIG_X86_32
  32499. + .long __KERNEL_CS
  32500. +#else
  32501. .long __KERNEL32_CS
  32502. #endif
  32503. END(real_mode_header)
  32504. diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
  32505. index 48ddd76..c26749f 100644
  32506. --- a/arch/x86/realmode/rm/trampoline_32.S
  32507. +++ b/arch/x86/realmode/rm/trampoline_32.S
  32508. @@ -24,6 +24,12 @@
  32509. #include <asm/page_types.h>
  32510. #include "realmode.h"
  32511. +#ifdef CONFIG_PAX_KERNEXEC
  32512. +#define ta(X) (X)
  32513. +#else
  32514. +#define ta(X) (pa_ ## X)
  32515. +#endif
  32516. +
  32517. .text
  32518. .code16
  32519. @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
  32520. cli # We should be safe anyway
  32521. - movl tr_start, %eax # where we need to go
  32522. -
  32523. movl $0xA5A5A5A5, trampoline_status
  32524. # write marker for master knows we're running
  32525. @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
  32526. movw $1, %dx # protected mode (PE) bit
  32527. lmsw %dx # into protected mode
  32528. - ljmpl $__BOOT_CS, $pa_startup_32
  32529. + ljmpl *(trampoline_header)
  32530. .section ".text32","ax"
  32531. .code32
  32532. @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
  32533. .balign 8
  32534. GLOBAL(trampoline_header)
  32535. tr_start: .space 4
  32536. - tr_gdt_pad: .space 2
  32537. + tr_boot_cs: .space 2
  32538. tr_gdt: .space 6
  32539. END(trampoline_header)
  32540. diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
  32541. index dac7b20..72dbaca 100644
  32542. --- a/arch/x86/realmode/rm/trampoline_64.S
  32543. +++ b/arch/x86/realmode/rm/trampoline_64.S
  32544. @@ -93,6 +93,7 @@ ENTRY(startup_32)
  32545. movl %edx, %gs
  32546. movl pa_tr_cr4, %eax
  32547. + andl $~X86_CR4_PCIDE, %eax
  32548. movl %eax, %cr4 # Enable PAE mode
  32549. # Setup trampoline 4 level pagetables
  32550. @@ -106,7 +107,7 @@ ENTRY(startup_32)
  32551. wrmsr
  32552. # Enable paging and in turn activate Long Mode
  32553. - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
  32554. + movl $(X86_CR0_PG | X86_CR0_PE), %eax
  32555. movl %eax, %cr0
  32556. /*
  32557. diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
  32558. index 9e7e147..25a4158 100644
  32559. --- a/arch/x86/realmode/rm/wakeup_asm.S
  32560. +++ b/arch/x86/realmode/rm/wakeup_asm.S
  32561. @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
  32562. lgdtl pmode_gdt
  32563. /* This really couldn't... */
  32564. - movl pmode_entry, %eax
  32565. movl pmode_cr0, %ecx
  32566. movl %ecx, %cr0
  32567. - ljmpl $__KERNEL_CS, $pa_startup_32
  32568. - /* -> jmp *%eax in trampoline_32.S */
  32569. +
  32570. + ljmpl *pmode_entry
  32571. #else
  32572. jmp trampoline_start
  32573. #endif
  32574. diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
  32575. index e812034..c747134 100644
  32576. --- a/arch/x86/tools/Makefile
  32577. +++ b/arch/x86/tools/Makefile
  32578. @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
  32579. $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
  32580. -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
  32581. +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
  32582. hostprogs-y += relocs
  32583. relocs-objs := relocs_32.o relocs_64.o relocs_common.o
  32584. relocs: $(obj)/relocs
  32585. diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
  32586. index cfbdbdb..1aa763c 100644
  32587. --- a/arch/x86/tools/relocs.c
  32588. +++ b/arch/x86/tools/relocs.c
  32589. @@ -11,6 +13,7 @@
  32590. #define Elf_Sym ElfW(Sym)
  32591. static Elf_Ehdr ehdr;
  32592. +static Elf_Phdr *phdr;
  32593. struct relocs {
  32594. uint32_t *offset;
  32595. @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
  32596. }
  32597. }
  32598. +static void read_phdrs(FILE *fp)
  32599. +{
  32600. + unsigned int i;
  32601. +
  32602. + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
  32603. + if (!phdr) {
  32604. + die("Unable to allocate %d program headers\n",
  32605. + ehdr.e_phnum);
  32606. + }
  32607. + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
  32608. + die("Seek to %d failed: %s\n",
  32609. + ehdr.e_phoff, strerror(errno));
  32610. + }
  32611. + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
  32612. + die("Cannot read ELF program headers: %s\n",
  32613. + strerror(errno));
  32614. + }
  32615. + for(i = 0; i < ehdr.e_phnum; i++) {
  32616. + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
  32617. + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
  32618. + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
  32619. + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
  32620. + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
  32621. + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
  32622. + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
  32623. + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
  32624. + }
  32625. +
  32626. +}
  32627. +
  32628. static void read_shdrs(FILE *fp)
  32629. {
  32630. - int i;
  32631. + unsigned int i;
  32632. Elf_Shdr shdr;
  32633. secs = calloc(ehdr.e_shnum, sizeof(struct section));
  32634. @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
  32635. static void read_strtabs(FILE *fp)
  32636. {
  32637. - int i;
  32638. + unsigned int i;
  32639. for (i = 0; i < ehdr.e_shnum; i++) {
  32640. struct section *sec = &secs[i];
  32641. if (sec->shdr.sh_type != SHT_STRTAB) {
  32642. @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
  32643. static void read_symtabs(FILE *fp)
  32644. {
  32645. - int i,j;
  32646. + unsigned int i,j;
  32647. for (i = 0; i < ehdr.e_shnum; i++) {
  32648. struct section *sec = &secs[i];
  32649. if (sec->shdr.sh_type != SHT_SYMTAB) {
  32650. @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
  32651. }
  32652. -static void read_relocs(FILE *fp)
  32653. +static void read_relocs(FILE *fp, int use_real_mode)
  32654. {
  32655. - int i,j;
  32656. + unsigned int i,j;
  32657. + uint32_t base;
  32658. +
  32659. for (i = 0; i < ehdr.e_shnum; i++) {
  32660. struct section *sec = &secs[i];
  32661. if (sec->shdr.sh_type != SHT_REL_TYPE) {
  32662. @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
  32663. die("Cannot read symbol table: %s\n",
  32664. strerror(errno));
  32665. }
  32666. + base = 0;
  32667. +
  32668. +#ifdef CONFIG_X86_32
  32669. + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
  32670. + if (phdr[j].p_type != PT_LOAD )
  32671. + continue;
  32672. + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
  32673. + continue;
  32674. + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
  32675. + break;
  32676. + }
  32677. +#endif
  32678. +
  32679. for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
  32680. Elf_Rel *rel = &sec->reltab[j];
  32681. - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
  32682. + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
  32683. rel->r_info = elf_xword_to_cpu(rel->r_info);
  32684. #if (SHT_REL_TYPE == SHT_RELA)
  32685. rel->r_addend = elf_xword_to_cpu(rel->r_addend);
  32686. @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
  32687. static void print_absolute_symbols(void)
  32688. {
  32689. - int i;
  32690. + unsigned int i;
  32691. const char *format;
  32692. if (ELF_BITS == 64)
  32693. @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
  32694. for (i = 0; i < ehdr.e_shnum; i++) {
  32695. struct section *sec = &secs[i];
  32696. char *sym_strtab;
  32697. - int j;
  32698. + unsigned int j;
  32699. if (sec->shdr.sh_type != SHT_SYMTAB) {
  32700. continue;
  32701. @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
  32702. static void print_absolute_relocs(void)
  32703. {
  32704. - int i, printed = 0;
  32705. + unsigned int i, printed = 0;
  32706. const char *format;
  32707. if (ELF_BITS == 64)
  32708. @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
  32709. struct section *sec_applies, *sec_symtab;
  32710. char *sym_strtab;
  32711. Elf_Sym *sh_symtab;
  32712. - int j;
  32713. + unsigned int j;
  32714. if (sec->shdr.sh_type != SHT_REL_TYPE) {
  32715. continue;
  32716. }
  32717. @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
  32718. static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
  32719. Elf_Sym *sym, const char *symname))
  32720. {
  32721. - int i;
  32722. + unsigned int i;
  32723. /* Walk through the relocations */
  32724. for (i = 0; i < ehdr.e_shnum; i++) {
  32725. char *sym_strtab;
  32726. Elf_Sym *sh_symtab;
  32727. struct section *sec_applies, *sec_symtab;
  32728. - int j;
  32729. + unsigned int j;
  32730. struct section *sec = &secs[i];
  32731. if (sec->shdr.sh_type != SHT_REL_TYPE) {
  32732. @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
  32733. {
  32734. unsigned r_type = ELF32_R_TYPE(rel->r_info);
  32735. int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
  32736. + char *sym_strtab = sec->link->link->strtab;
  32737. +
  32738. + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
  32739. + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
  32740. + return 0;
  32741. +
  32742. +#ifdef CONFIG_PAX_KERNEXEC
  32743. + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
  32744. + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
  32745. + return 0;
  32746. + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
  32747. + return 0;
  32748. + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
  32749. + return 0;
  32750. + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
  32751. + return 0;
  32752. +#endif
  32753. switch (r_type) {
  32754. case R_386_NONE:
  32755. @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
  32756. static void emit_relocs(int as_text, int use_real_mode)
  32757. {
  32758. - int i;
  32759. + unsigned int i;
  32760. int (*write_reloc)(uint32_t, FILE *) = write32;
  32761. int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
  32762. const char *symname);
  32763. @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
  32764. {
  32765. regex_init(use_real_mode);
  32766. read_ehdr(fp);
  32767. + read_phdrs(fp);
  32768. read_shdrs(fp);
  32769. read_strtabs(fp);
  32770. read_symtabs(fp);
  32771. - read_relocs(fp);
  32772. + read_relocs(fp, use_real_mode);
  32773. if (ELF_BITS == 64)
  32774. percpu_init();
  32775. if (show_absolute_syms) {
  32776. diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
  32777. index 80ffa5b..a33bd15 100644
  32778. --- a/arch/x86/um/tls_32.c
  32779. +++ b/arch/x86/um/tls_32.c
  32780. @@ -260,7 +260,7 @@ out:
  32781. if (unlikely(task == current &&
  32782. !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
  32783. printk(KERN_ERR "get_tls_entry: task with pid %d got here "
  32784. - "without flushed TLS.", current->pid);
  32785. + "without flushed TLS.", task_pid_nr(current));
  32786. }
  32787. return 0;
  32788. diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
  32789. index fd14be1..e3c79c0 100644
  32790. --- a/arch/x86/vdso/Makefile
  32791. +++ b/arch/x86/vdso/Makefile
  32792. @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
  32793. -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
  32794. sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
  32795. -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  32796. +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  32797. GCOV_PROFILE := n
  32798. #
  32799. diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
  32800. index d6bfb87..876ee18 100644
  32801. --- a/arch/x86/vdso/vdso32-setup.c
  32802. +++ b/arch/x86/vdso/vdso32-setup.c
  32803. @@ -25,6 +25,7 @@
  32804. #include <asm/tlbflush.h>
  32805. #include <asm/vdso.h>
  32806. #include <asm/proto.h>
  32807. +#include <asm/mman.h>
  32808. enum {
  32809. VDSO_DISABLED = 0,
  32810. @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
  32811. void enable_sep_cpu(void)
  32812. {
  32813. int cpu = get_cpu();
  32814. - struct tss_struct *tss = &per_cpu(init_tss, cpu);
  32815. + struct tss_struct *tss = init_tss + cpu;
  32816. if (!boot_cpu_has(X86_FEATURE_SEP)) {
  32817. put_cpu();
  32818. @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
  32819. gate_vma.vm_start = FIXADDR_USER_START;
  32820. gate_vma.vm_end = FIXADDR_USER_END;
  32821. gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
  32822. - gate_vma.vm_page_prot = __P101;
  32823. + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
  32824. return 0;
  32825. }
  32826. @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  32827. if (compat)
  32828. addr = VDSO_HIGH_BASE;
  32829. else {
  32830. - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  32831. + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
  32832. if (IS_ERR_VALUE(addr)) {
  32833. ret = addr;
  32834. goto up_fail;
  32835. }
  32836. }
  32837. - current->mm->context.vdso = (void *)addr;
  32838. + current->mm->context.vdso = addr;
  32839. if (compat_uses_vma || !compat) {
  32840. /*
  32841. @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  32842. }
  32843. current_thread_info()->sysenter_return =
  32844. - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
  32845. + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
  32846. up_fail:
  32847. if (ret)
  32848. - current->mm->context.vdso = NULL;
  32849. + current->mm->context.vdso = 0;
  32850. up_write(&mm->mmap_sem);
  32851. @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
  32852. const char *arch_vma_name(struct vm_area_struct *vma)
  32853. {
  32854. - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  32855. + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
  32856. return "[vdso]";
  32857. +
  32858. +#ifdef CONFIG_PAX_SEGMEXEC
  32859. + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
  32860. + return "[vdso]";
  32861. +#endif
  32862. +
  32863. return NULL;
  32864. }
  32865. @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  32866. * Check to see if the corresponding task was created in compat vdso
  32867. * mode.
  32868. */
  32869. - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
  32870. + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
  32871. return &gate_vma;
  32872. return NULL;
  32873. }
  32874. diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
  32875. index 431e875..cbb23f3 100644
  32876. --- a/arch/x86/vdso/vma.c
  32877. +++ b/arch/x86/vdso/vma.c
  32878. @@ -16,8 +16,6 @@
  32879. #include <asm/vdso.h>
  32880. #include <asm/page.h>
  32881. -unsigned int __read_mostly vdso_enabled = 1;
  32882. -
  32883. extern char vdso_start[], vdso_end[];
  32884. extern unsigned short vdso_sync_cpuid;
  32885. @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
  32886. * unaligned here as a result of stack start randomization.
  32887. */
  32888. addr = PAGE_ALIGN(addr);
  32889. - addr = align_vdso_addr(addr);
  32890. return addr;
  32891. }
  32892. @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
  32893. unsigned size)
  32894. {
  32895. struct mm_struct *mm = current->mm;
  32896. - unsigned long addr;
  32897. + unsigned long addr = 0;
  32898. int ret;
  32899. - if (!vdso_enabled)
  32900. - return 0;
  32901. -
  32902. down_write(&mm->mmap_sem);
  32903. +
  32904. +#ifdef CONFIG_PAX_RANDMMAP
  32905. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  32906. +#endif
  32907. +
  32908. addr = vdso_addr(mm->start_stack, size);
  32909. + addr = align_vdso_addr(addr);
  32910. addr = get_unmapped_area(NULL, addr, size, 0, 0);
  32911. if (IS_ERR_VALUE(addr)) {
  32912. ret = addr;
  32913. goto up_fail;
  32914. }
  32915. - current->mm->context.vdso = (void *)addr;
  32916. + mm->context.vdso = addr;
  32917. ret = install_special_mapping(mm, addr, size,
  32918. VM_READ|VM_EXEC|
  32919. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
  32920. pages);
  32921. - if (ret) {
  32922. - current->mm->context.vdso = NULL;
  32923. - goto up_fail;
  32924. - }
  32925. + if (ret)
  32926. + mm->context.vdso = 0;
  32927. up_fail:
  32928. up_write(&mm->mmap_sem);
  32929. @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
  32930. vdsox32_size);
  32931. }
  32932. #endif
  32933. -
  32934. -static __init int vdso_setup(char *s)
  32935. -{
  32936. - vdso_enabled = simple_strtoul(s, NULL, 0);
  32937. - return 0;
  32938. -}
  32939. -__setup("vdso=", vdso_setup);
  32940. diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
  32941. index 01b9026..1e476df 100644
  32942. --- a/arch/x86/xen/Kconfig
  32943. +++ b/arch/x86/xen/Kconfig
  32944. @@ -9,6 +9,7 @@ config XEN
  32945. select XEN_HAVE_PVMMU
  32946. depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
  32947. depends on X86_TSC
  32948. + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
  32949. help
  32950. This is the Linux Xen port. Enabling this will allow the
  32951. kernel to boot in a paravirtualized environment under the
  32952. diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
  32953. index 201d09a..e4723e5 100644
  32954. --- a/arch/x86/xen/enlighten.c
  32955. +++ b/arch/x86/xen/enlighten.c
  32956. @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
  32957. struct shared_info xen_dummy_shared_info;
  32958. -void *xen_initial_gdt;
  32959. -
  32960. RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
  32961. __read_mostly int xen_have_vector_callback;
  32962. EXPORT_SYMBOL_GPL(xen_have_vector_callback);
  32963. @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
  32964. {
  32965. unsigned long va = dtr->address;
  32966. unsigned int size = dtr->size + 1;
  32967. - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
  32968. - unsigned long frames[pages];
  32969. + unsigned long frames[65536 / PAGE_SIZE];
  32970. int f;
  32971. /*
  32972. @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
  32973. {
  32974. unsigned long va = dtr->address;
  32975. unsigned int size = dtr->size + 1;
  32976. - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
  32977. - unsigned long frames[pages];
  32978. + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
  32979. int f;
  32980. /*
  32981. @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
  32982. * 8-byte entries, or 16 4k pages..
  32983. */
  32984. - BUG_ON(size > 65536);
  32985. + BUG_ON(size > GDT_SIZE);
  32986. BUG_ON(va & ~PAGE_MASK);
  32987. for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
  32988. @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
  32989. return 0;
  32990. }
  32991. -static void set_xen_basic_apic_ops(void)
  32992. +static void __init set_xen_basic_apic_ops(void)
  32993. {
  32994. apic->read = xen_apic_read;
  32995. apic->write = xen_apic_write;
  32996. @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
  32997. #endif
  32998. };
  32999. -static void xen_reboot(int reason)
  33000. +static __noreturn void xen_reboot(int reason)
  33001. {
  33002. struct sched_shutdown r = { .reason = reason };
  33003. - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
  33004. - BUG();
  33005. + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
  33006. + BUG();
  33007. }
  33008. -static void xen_restart(char *msg)
  33009. +static __noreturn void xen_restart(char *msg)
  33010. {
  33011. xen_reboot(SHUTDOWN_reboot);
  33012. }
  33013. -static void xen_emergency_restart(void)
  33014. +static __noreturn void xen_emergency_restart(void)
  33015. {
  33016. xen_reboot(SHUTDOWN_reboot);
  33017. }
  33018. -static void xen_machine_halt(void)
  33019. +static __noreturn void xen_machine_halt(void)
  33020. {
  33021. xen_reboot(SHUTDOWN_poweroff);
  33022. }
  33023. -static void xen_machine_power_off(void)
  33024. +static __noreturn void xen_machine_power_off(void)
  33025. {
  33026. if (pm_power_off)
  33027. pm_power_off();
  33028. @@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
  33029. __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
  33030. /* Work out if we support NX */
  33031. - x86_configure_nx();
  33032. +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  33033. + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
  33034. + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
  33035. + unsigned l, h;
  33036. +
  33037. + __supported_pte_mask |= _PAGE_NX;
  33038. + rdmsr(MSR_EFER, l, h);
  33039. + l |= EFER_NX;
  33040. + wrmsr(MSR_EFER, l, h);
  33041. + }
  33042. +#endif
  33043. /* Get mfn list */
  33044. xen_build_dynamic_phys_to_machine();
  33045. @@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
  33046. machine_ops = xen_machine_ops;
  33047. - /*
  33048. - * The only reliable way to retain the initial address of the
  33049. - * percpu gdt_page is to remember it here, so we can go and
  33050. - * mark it RW later, when the initial percpu area is freed.
  33051. - */
  33052. - xen_initial_gdt = &per_cpu(gdt_page, 0);
  33053. -
  33054. xen_smp_init();
  33055. #ifdef CONFIG_ACPI_NUMA
  33056. diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
  33057. index 2423ef0..4f6fb5b 100644
  33058. --- a/arch/x86/xen/mmu.c
  33059. +++ b/arch/x86/xen/mmu.c
  33060. @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
  33061. return val;
  33062. }
  33063. -static pteval_t pte_pfn_to_mfn(pteval_t val)
  33064. +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
  33065. {
  33066. if (val & _PAGE_PRESENT) {
  33067. unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
  33068. @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
  33069. /* L3_k[510] -> level2_kernel_pgt
  33070. * L3_i[511] -> level2_fixmap_pgt */
  33071. convert_pfn_mfn(level3_kernel_pgt);
  33072. + convert_pfn_mfn(level3_vmalloc_start_pgt);
  33073. + convert_pfn_mfn(level3_vmalloc_end_pgt);
  33074. + convert_pfn_mfn(level3_vmemmap_pgt);
  33075. }
  33076. /* We get [511][511] and have Xen's version of level2_kernel_pgt */
  33077. l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
  33078. @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
  33079. set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
  33080. set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
  33081. set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
  33082. + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
  33083. + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
  33084. + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
  33085. set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
  33086. set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
  33087. + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
  33088. set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
  33089. set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
  33090. @@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
  33091. pv_mmu_ops.set_pud = xen_set_pud;
  33092. #if PAGETABLE_LEVELS == 4
  33093. pv_mmu_ops.set_pgd = xen_set_pgd;
  33094. + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
  33095. #endif
  33096. /* This will work as long as patching hasn't happened yet
  33097. @@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
  33098. .pud_val = PV_CALLEE_SAVE(xen_pud_val),
  33099. .make_pud = PV_CALLEE_SAVE(xen_make_pud),
  33100. .set_pgd = xen_set_pgd_hyper,
  33101. + .set_pgd_batched = xen_set_pgd_hyper,
  33102. .alloc_pud = xen_alloc_pmd_init,
  33103. .release_pud = xen_release_pmd_init,
  33104. diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
  33105. index a18eadd..2e2f10e 100644
  33106. --- a/arch/x86/xen/smp.c
  33107. +++ b/arch/x86/xen/smp.c
  33108. @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
  33109. if (xen_pv_domain()) {
  33110. if (!xen_feature(XENFEAT_writable_page_tables))
  33111. - /* We've switched to the "real" per-cpu gdt, so make
  33112. - * sure the old memory can be recycled. */
  33113. - make_lowmem_page_readwrite(xen_initial_gdt);
  33114. -
  33115. #ifdef CONFIG_X86_32
  33116. /*
  33117. * Xen starts us with XEN_FLAT_RING1_DS, but linux code
  33118. * expects __USER_DS
  33119. */
  33120. - loadsegment(ds, __USER_DS);
  33121. - loadsegment(es, __USER_DS);
  33122. + loadsegment(ds, __KERNEL_DS);
  33123. + loadsegment(es, __KERNEL_DS);
  33124. #endif
  33125. xen_filter_cpu_maps();
  33126. @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
  33127. #ifdef CONFIG_X86_32
  33128. /* Note: PVH is not yet supported on x86_32. */
  33129. ctxt->user_regs.fs = __KERNEL_PERCPU;
  33130. - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
  33131. + savesegment(gs, ctxt->user_regs.gs);
  33132. #endif
  33133. ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
  33134. @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
  33135. if (!xen_feature(XENFEAT_auto_translated_physmap)) {
  33136. ctxt->flags = VGCF_IN_KERNEL;
  33137. ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
  33138. - ctxt->user_regs.ds = __USER_DS;
  33139. - ctxt->user_regs.es = __USER_DS;
  33140. + ctxt->user_regs.ds = __KERNEL_DS;
  33141. + ctxt->user_regs.es = __KERNEL_DS;
  33142. ctxt->user_regs.ss = __KERNEL_DS;
  33143. xen_copy_trap_info(ctxt->trap_ctxt);
  33144. @@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
  33145. int rc;
  33146. per_cpu(current_task, cpu) = idle;
  33147. + per_cpu(current_tinfo, cpu) = &idle->tinfo;
  33148. #ifdef CONFIG_X86_32
  33149. irq_ctx_init(cpu);
  33150. #else
  33151. clear_tsk_thread_flag(idle, TIF_FORK);
  33152. - per_cpu(kernel_stack, cpu) =
  33153. - (unsigned long)task_stack_page(idle) -
  33154. - KERNEL_STACK_OFFSET + THREAD_SIZE;
  33155. + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
  33156. #endif
  33157. xen_setup_runstate_info(cpu);
  33158. xen_setup_timer(cpu);
  33159. @@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
  33160. void __init xen_smp_init(void)
  33161. {
  33162. - smp_ops = xen_smp_ops;
  33163. + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
  33164. xen_fill_possible_map();
  33165. }
  33166. diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
  33167. index 33ca6e4..0ded929 100644
  33168. --- a/arch/x86/xen/xen-asm_32.S
  33169. +++ b/arch/x86/xen/xen-asm_32.S
  33170. @@ -84,14 +84,14 @@ ENTRY(xen_iret)
  33171. ESP_OFFSET=4 # bytes pushed onto stack
  33172. /*
  33173. - * Store vcpu_info pointer for easy access. Do it this way to
  33174. - * avoid having to reload %fs
  33175. + * Store vcpu_info pointer for easy access.
  33176. */
  33177. #ifdef CONFIG_SMP
  33178. - GET_THREAD_INFO(%eax)
  33179. - movl %ss:TI_cpu(%eax), %eax
  33180. - movl %ss:__per_cpu_offset(,%eax,4), %eax
  33181. - mov %ss:xen_vcpu(%eax), %eax
  33182. + push %fs
  33183. + mov $(__KERNEL_PERCPU), %eax
  33184. + mov %eax, %fs
  33185. + mov PER_CPU_VAR(xen_vcpu), %eax
  33186. + pop %fs
  33187. #else
  33188. movl %ss:xen_vcpu, %eax
  33189. #endif
  33190. diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
  33191. index 485b695..fda3e7c 100644
  33192. --- a/arch/x86/xen/xen-head.S
  33193. +++ b/arch/x86/xen/xen-head.S
  33194. @@ -39,6 +39,17 @@ ENTRY(startup_xen)
  33195. #ifdef CONFIG_X86_32
  33196. mov %esi,xen_start_info
  33197. mov $init_thread_union+THREAD_SIZE,%esp
  33198. +#ifdef CONFIG_SMP
  33199. + movl $cpu_gdt_table,%edi
  33200. + movl $__per_cpu_load,%eax
  33201. + movw %ax,__KERNEL_PERCPU + 2(%edi)
  33202. + rorl $16,%eax
  33203. + movb %al,__KERNEL_PERCPU + 4(%edi)
  33204. + movb %ah,__KERNEL_PERCPU + 7(%edi)
  33205. + movl $__per_cpu_end - 1,%eax
  33206. + subl $__per_cpu_start,%eax
  33207. + movw %ax,__KERNEL_PERCPU + 0(%edi)
  33208. +#endif
  33209. #else
  33210. mov %rsi,xen_start_info
  33211. mov $init_thread_union+THREAD_SIZE,%rsp
  33212. diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
  33213. index 1cb6f4c..9981524 100644
  33214. --- a/arch/x86/xen/xen-ops.h
  33215. +++ b/arch/x86/xen/xen-ops.h
  33216. @@ -10,8 +10,6 @@
  33217. extern const char xen_hypervisor_callback[];
  33218. extern const char xen_failsafe_callback[];
  33219. -extern void *xen_initial_gdt;
  33220. -
  33221. struct trap_info;
  33222. void xen_copy_trap_info(struct trap_info *traps);
  33223. diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
  33224. index 525bd3d..ef888b1 100644
  33225. --- a/arch/xtensa/variants/dc232b/include/variant/core.h
  33226. +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
  33227. @@ -119,9 +119,9 @@
  33228. ----------------------------------------------------------------------*/
  33229. #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
  33230. -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
  33231. #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
  33232. #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
  33233. +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
  33234. #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
  33235. #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
  33236. diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
  33237. index 2f33760..835e50a 100644
  33238. --- a/arch/xtensa/variants/fsf/include/variant/core.h
  33239. +++ b/arch/xtensa/variants/fsf/include/variant/core.h
  33240. @@ -11,6 +11,7 @@
  33241. #ifndef _XTENSA_CORE_H
  33242. #define _XTENSA_CORE_H
  33243. +#include <linux/const.h>
  33244. /****************************************************************************
  33245. Parameters Useful for Any Code, USER or PRIVILEGED
  33246. @@ -112,9 +113,9 @@
  33247. ----------------------------------------------------------------------*/
  33248. #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
  33249. -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
  33250. #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
  33251. #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
  33252. +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
  33253. #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
  33254. #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
  33255. diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
  33256. index af00795..2bb8105 100644
  33257. --- a/arch/xtensa/variants/s6000/include/variant/core.h
  33258. +++ b/arch/xtensa/variants/s6000/include/variant/core.h
  33259. @@ -11,6 +11,7 @@
  33260. #ifndef _XTENSA_CORE_CONFIGURATION_H
  33261. #define _XTENSA_CORE_CONFIGURATION_H
  33262. +#include <linux/const.h>
  33263. /****************************************************************************
  33264. Parameters Useful for Any Code, USER or PRIVILEGED
  33265. @@ -118,9 +119,9 @@
  33266. ----------------------------------------------------------------------*/
  33267. #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
  33268. -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
  33269. #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
  33270. #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
  33271. +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
  33272. #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
  33273. #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
  33274. diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
  33275. index 4e491d9..c8e18e4 100644
  33276. --- a/block/blk-cgroup.c
  33277. +++ b/block/blk-cgroup.c
  33278. @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
  33279. static struct cgroup_subsys_state *
  33280. blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
  33281. {
  33282. - static atomic64_t id_seq = ATOMIC64_INIT(0);
  33283. + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
  33284. struct blkcg *blkcg;
  33285. if (!parent_css) {
  33286. @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
  33287. blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
  33288. blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
  33289. - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
  33290. + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
  33291. done:
  33292. spin_lock_init(&blkcg->lock);
  33293. INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
  33294. diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
  33295. index 1855bf5..af12b06 100644
  33296. --- a/block/blk-iopoll.c
  33297. +++ b/block/blk-iopoll.c
  33298. @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
  33299. }
  33300. EXPORT_SYMBOL(blk_iopoll_complete);
  33301. -static void blk_iopoll_softirq(struct softirq_action *h)
  33302. +static __latent_entropy void blk_iopoll_softirq(void)
  33303. {
  33304. struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
  33305. int rearm = 0, budget = blk_iopoll_budget;
  33306. diff --git a/block/blk-map.c b/block/blk-map.c
  33307. index ae4ae10..c470b8d 100644
  33308. --- a/block/blk-map.c
  33309. +++ b/block/blk-map.c
  33310. @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
  33311. if (!len || !kbuf)
  33312. return -EINVAL;
  33313. - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
  33314. + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
  33315. if (do_copy)
  33316. bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
  33317. else
  33318. diff --git a/block/blk-softirq.c b/block/blk-softirq.c
  33319. index 57790c1..5e988dd 100644
  33320. --- a/block/blk-softirq.c
  33321. +++ b/block/blk-softirq.c
  33322. @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
  33323. * Softirq action handler - move entries to local list and loop over them
  33324. * while passing them to the queue registered handler.
  33325. */
  33326. -static void blk_done_softirq(struct softirq_action *h)
  33327. +static __latent_entropy void blk_done_softirq(void)
  33328. {
  33329. struct list_head *cpu_list, local_list;
  33330. diff --git a/block/bsg.c b/block/bsg.c
  33331. index 420a5a9..23834aa 100644
  33332. --- a/block/bsg.c
  33333. +++ b/block/bsg.c
  33334. @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
  33335. struct sg_io_v4 *hdr, struct bsg_device *bd,
  33336. fmode_t has_write_perm)
  33337. {
  33338. + unsigned char tmpcmd[sizeof(rq->__cmd)];
  33339. + unsigned char *cmdptr;
  33340. +
  33341. if (hdr->request_len > BLK_MAX_CDB) {
  33342. rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
  33343. if (!rq->cmd)
  33344. return -ENOMEM;
  33345. - }
  33346. + cmdptr = rq->cmd;
  33347. + } else
  33348. + cmdptr = tmpcmd;
  33349. - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
  33350. + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
  33351. hdr->request_len))
  33352. return -EFAULT;
  33353. + if (cmdptr != rq->cmd)
  33354. + memcpy(rq->cmd, cmdptr, hdr->request_len);
  33355. +
  33356. if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
  33357. if (blk_verify_command(rq->cmd, has_write_perm))
  33358. return -EPERM;
  33359. diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
  33360. index fbd5a67..f24fd95 100644
  33361. --- a/block/compat_ioctl.c
  33362. +++ b/block/compat_ioctl.c
  33363. @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
  33364. cgc = compat_alloc_user_space(sizeof(*cgc));
  33365. cgc32 = compat_ptr(arg);
  33366. - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
  33367. + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
  33368. get_user(data, &cgc32->buffer) ||
  33369. put_user(compat_ptr(data), &cgc->buffer) ||
  33370. copy_in_user(&cgc->buflen, &cgc32->buflen,
  33371. @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
  33372. err |= __get_user(f->spec1, &uf->spec1);
  33373. err |= __get_user(f->fmt_gap, &uf->fmt_gap);
  33374. err |= __get_user(name, &uf->name);
  33375. - f->name = compat_ptr(name);
  33376. + f->name = (void __force_kernel *)compat_ptr(name);
  33377. if (err) {
  33378. err = -EFAULT;
  33379. goto out;
  33380. diff --git a/block/genhd.c b/block/genhd.c
  33381. index 791f419..89f21c4 100644
  33382. --- a/block/genhd.c
  33383. +++ b/block/genhd.c
  33384. @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
  33385. /*
  33386. * Register device numbers dev..(dev+range-1)
  33387. - * range must be nonzero
  33388. + * Noop if @range is zero.
  33389. * The hash chain is sorted on range, so that subranges can override.
  33390. */
  33391. void blk_register_region(dev_t devt, unsigned long range, struct module *module,
  33392. struct kobject *(*probe)(dev_t, int *, void *),
  33393. int (*lock)(dev_t, void *), void *data)
  33394. {
  33395. - kobj_map(bdev_map, devt, range, module, probe, lock, data);
  33396. + if (range)
  33397. + kobj_map(bdev_map, devt, range, module, probe, lock, data);
  33398. }
  33399. EXPORT_SYMBOL(blk_register_region);
  33400. +/* undo blk_register_region(), noop if @range is zero */
  33401. void blk_unregister_region(dev_t devt, unsigned long range)
  33402. {
  33403. - kobj_unmap(bdev_map, devt, range);
  33404. + if (range)
  33405. + kobj_unmap(bdev_map, devt, range);
  33406. }
  33407. EXPORT_SYMBOL(blk_unregister_region);
  33408. diff --git a/block/partitions/efi.c b/block/partitions/efi.c
  33409. index dc51f46..d5446a8 100644
  33410. --- a/block/partitions/efi.c
  33411. +++ b/block/partitions/efi.c
  33412. @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
  33413. if (!gpt)
  33414. return NULL;
  33415. + if (!le32_to_cpu(gpt->num_partition_entries))
  33416. + return NULL;
  33417. + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
  33418. + if (!pte)
  33419. + return NULL;
  33420. +
  33421. count = le32_to_cpu(gpt->num_partition_entries) *
  33422. le32_to_cpu(gpt->sizeof_partition_entry);
  33423. - if (!count)
  33424. - return NULL;
  33425. - pte = kmalloc(count, GFP_KERNEL);
  33426. - if (!pte)
  33427. - return NULL;
  33428. -
  33429. if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
  33430. (u8 *) pte, count) < count) {
  33431. kfree(pte);
  33432. diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
  33433. index 2648797..92ed21f 100644
  33434. --- a/block/scsi_ioctl.c
  33435. +++ b/block/scsi_ioctl.c
  33436. @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
  33437. return put_user(0, p);
  33438. }
  33439. -static int sg_get_timeout(struct request_queue *q)
  33440. +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
  33441. {
  33442. return jiffies_to_clock_t(q->sg_timeout);
  33443. }
  33444. @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
  33445. static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
  33446. struct sg_io_hdr *hdr, fmode_t mode)
  33447. {
  33448. - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
  33449. + unsigned char tmpcmd[sizeof(rq->__cmd)];
  33450. + unsigned char *cmdptr;
  33451. +
  33452. + if (rq->cmd != rq->__cmd)
  33453. + cmdptr = rq->cmd;
  33454. + else
  33455. + cmdptr = tmpcmd;
  33456. +
  33457. + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
  33458. return -EFAULT;
  33459. +
  33460. + if (cmdptr != rq->cmd)
  33461. + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
  33462. +
  33463. if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
  33464. return -EPERM;
  33465. @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
  33466. int err;
  33467. unsigned int in_len, out_len, bytes, opcode, cmdlen;
  33468. char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
  33469. + unsigned char tmpcmd[sizeof(rq->__cmd)];
  33470. + unsigned char *cmdptr;
  33471. if (!sic)
  33472. return -EINVAL;
  33473. @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
  33474. */
  33475. err = -EFAULT;
  33476. rq->cmd_len = cmdlen;
  33477. - if (copy_from_user(rq->cmd, sic->data, cmdlen))
  33478. +
  33479. + if (rq->cmd != rq->__cmd)
  33480. + cmdptr = rq->cmd;
  33481. + else
  33482. + cmdptr = tmpcmd;
  33483. +
  33484. + if (copy_from_user(cmdptr, sic->data, cmdlen))
  33485. goto error;
  33486. + if (rq->cmd != cmdptr)
  33487. + memcpy(rq->cmd, cmdptr, cmdlen);
  33488. +
  33489. if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
  33490. goto error;
  33491. diff --git a/crypto/cryptd.c b/crypto/cryptd.c
  33492. index 7bdd61b..afec999 100644
  33493. --- a/crypto/cryptd.c
  33494. +++ b/crypto/cryptd.c
  33495. @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
  33496. struct cryptd_blkcipher_request_ctx {
  33497. crypto_completion_t complete;
  33498. -};
  33499. +} __no_const;
  33500. struct cryptd_hash_ctx {
  33501. struct crypto_shash *child;
  33502. @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
  33503. struct cryptd_aead_request_ctx {
  33504. crypto_completion_t complete;
  33505. -};
  33506. +} __no_const;
  33507. static void cryptd_queue_worker(struct work_struct *work);
  33508. diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
  33509. index 309d345..1632720 100644
  33510. --- a/crypto/pcrypt.c
  33511. +++ b/crypto/pcrypt.c
  33512. @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
  33513. int ret;
  33514. pinst->kobj.kset = pcrypt_kset;
  33515. - ret = kobject_add(&pinst->kobj, NULL, name);
  33516. + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
  33517. if (!ret)
  33518. kobject_uevent(&pinst->kobj, KOBJ_ADD);
  33519. diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
  33520. index 15dddc1..b61cf0c 100644
  33521. --- a/drivers/acpi/acpica/hwxfsleep.c
  33522. +++ b/drivers/acpi/acpica/hwxfsleep.c
  33523. @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
  33524. /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
  33525. static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
  33526. - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
  33527. - acpi_hw_extended_sleep},
  33528. - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
  33529. - acpi_hw_extended_wake_prep},
  33530. - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
  33531. + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
  33532. + .extended_function = acpi_hw_extended_sleep},
  33533. + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
  33534. + .extended_function = acpi_hw_extended_wake_prep},
  33535. + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
  33536. + .extended_function = acpi_hw_extended_wake}
  33537. };
  33538. /*
  33539. diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
  33540. index e5bcd91..74f050d 100644
  33541. --- a/drivers/acpi/apei/apei-internal.h
  33542. +++ b/drivers/acpi/apei/apei-internal.h
  33543. @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
  33544. struct apei_exec_ins_type {
  33545. u32 flags;
  33546. apei_exec_ins_func_t run;
  33547. -};
  33548. +} __do_const;
  33549. struct apei_exec_context {
  33550. u32 ip;
  33551. diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
  33552. index dab7cb7..f0d2994 100644
  33553. --- a/drivers/acpi/apei/ghes.c
  33554. +++ b/drivers/acpi/apei/ghes.c
  33555. @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
  33556. const struct acpi_hest_generic *generic,
  33557. const struct acpi_generic_status *estatus)
  33558. {
  33559. - static atomic_t seqno;
  33560. + static atomic_unchecked_t seqno;
  33561. unsigned int curr_seqno;
  33562. char pfx_seq[64];
  33563. @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
  33564. else
  33565. pfx = KERN_ERR;
  33566. }
  33567. - curr_seqno = atomic_inc_return(&seqno);
  33568. + curr_seqno = atomic_inc_return_unchecked(&seqno);
  33569. snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
  33570. printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
  33571. pfx_seq, generic->header.source_id);
  33572. diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
  33573. index a83e3c6..c3d617f 100644
  33574. --- a/drivers/acpi/bgrt.c
  33575. +++ b/drivers/acpi/bgrt.c
  33576. @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
  33577. if (!bgrt_image)
  33578. return -ENODEV;
  33579. - bin_attr_image.private = bgrt_image;
  33580. - bin_attr_image.size = bgrt_image_size;
  33581. + pax_open_kernel();
  33582. + *(void **)&bin_attr_image.private = bgrt_image;
  33583. + *(size_t *)&bin_attr_image.size = bgrt_image_size;
  33584. + pax_close_kernel();
  33585. bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
  33586. if (!bgrt_kobj)
  33587. diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
  33588. index afec452..c5d8b96 100644
  33589. --- a/drivers/acpi/blacklist.c
  33590. +++ b/drivers/acpi/blacklist.c
  33591. @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
  33592. u32 is_critical_error;
  33593. };
  33594. -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
  33595. +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
  33596. /*
  33597. * POLICY: If *anything* doesn't work, put it on the blacklist.
  33598. @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
  33599. return 0;
  33600. }
  33601. -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
  33602. +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
  33603. {
  33604. .callback = dmi_disable_osi_vista,
  33605. .ident = "Fujitsu Siemens",
  33606. diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
  33607. index c68e724..e863008 100644
  33608. --- a/drivers/acpi/custom_method.c
  33609. +++ b/drivers/acpi/custom_method.c
  33610. @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
  33611. struct acpi_table_header table;
  33612. acpi_status status;
  33613. +#ifdef CONFIG_GRKERNSEC_KMEM
  33614. + return -EPERM;
  33615. +#endif
  33616. +
  33617. if (!(*ppos)) {
  33618. /* parse the table header to get the table length */
  33619. if (count <= sizeof(struct acpi_table_header))
  33620. diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
  33621. index 3dca36d..abaf070 100644
  33622. --- a/drivers/acpi/processor_idle.c
  33623. +++ b/drivers/acpi/processor_idle.c
  33624. @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
  33625. {
  33626. int i, count = CPUIDLE_DRIVER_STATE_START;
  33627. struct acpi_processor_cx *cx;
  33628. - struct cpuidle_state *state;
  33629. + cpuidle_state_no_const *state;
  33630. struct cpuidle_driver *drv = &acpi_idle_driver;
  33631. if (!pr->flags.power_setup_done)
  33632. diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
  33633. index 91a32ce..d77fcaf 100644
  33634. --- a/drivers/acpi/sysfs.c
  33635. +++ b/drivers/acpi/sysfs.c
  33636. @@ -425,11 +425,11 @@ static u32 num_counters;
  33637. static struct attribute **all_attrs;
  33638. static u32 acpi_gpe_count;
  33639. -static struct attribute_group interrupt_stats_attr_group = {
  33640. +static attribute_group_no_const interrupt_stats_attr_group = {
  33641. .name = "interrupts",
  33642. };
  33643. -static struct kobj_attribute *counter_attrs;
  33644. +static kobj_attribute_no_const *counter_attrs;
  33645. static void delete_gpe_attr_array(void)
  33646. {
  33647. diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
  33648. index 36605ab..6ef6d4b 100644
  33649. --- a/drivers/ata/libahci.c
  33650. +++ b/drivers/ata/libahci.c
  33651. @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
  33652. }
  33653. EXPORT_SYMBOL_GPL(ahci_kick_engine);
  33654. -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
  33655. +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
  33656. struct ata_taskfile *tf, int is_cmd, u16 flags,
  33657. unsigned long timeout_msec)
  33658. {
  33659. diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
  33660. index 0a79c54..c1b92ed 100644
  33661. --- a/drivers/ata/libata-core.c
  33662. +++ b/drivers/ata/libata-core.c
  33663. @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
  33664. static void ata_dev_xfermask(struct ata_device *dev);
  33665. static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
  33666. -atomic_t ata_print_id = ATOMIC_INIT(0);
  33667. +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
  33668. struct ata_force_param {
  33669. const char *name;
  33670. @@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
  33671. struct ata_port *ap;
  33672. unsigned int tag;
  33673. - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  33674. + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  33675. ap = qc->ap;
  33676. qc->flags = 0;
  33677. @@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
  33678. struct ata_port *ap;
  33679. struct ata_link *link;
  33680. - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  33681. + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  33682. WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
  33683. ap = qc->ap;
  33684. link = qc->dev->link;
  33685. @@ -5993,6 +5993,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
  33686. return;
  33687. spin_lock(&lock);
  33688. + pax_open_kernel();
  33689. for (cur = ops->inherits; cur; cur = cur->inherits) {
  33690. void **inherit = (void **)cur;
  33691. @@ -6006,8 +6007,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
  33692. if (IS_ERR(*pp))
  33693. *pp = NULL;
  33694. - ops->inherits = NULL;
  33695. + *(struct ata_port_operations **)&ops->inherits = NULL;
  33696. + pax_close_kernel();
  33697. spin_unlock(&lock);
  33698. }
  33699. @@ -6200,7 +6202,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
  33700. /* give ports names and add SCSI hosts */
  33701. for (i = 0; i < host->n_ports; i++) {
  33702. - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
  33703. + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
  33704. host->ports[i]->local_port_no = i + 1;
  33705. }
  33706. diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
  33707. index ef8567d..8bdbd03 100644
  33708. --- a/drivers/ata/libata-scsi.c
  33709. +++ b/drivers/ata/libata-scsi.c
  33710. @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
  33711. if (rc)
  33712. return rc;
  33713. - ap->print_id = atomic_inc_return(&ata_print_id);
  33714. + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
  33715. return 0;
  33716. }
  33717. EXPORT_SYMBOL_GPL(ata_sas_port_init);
  33718. diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
  33719. index 45b5ab3..98446b8 100644
  33720. --- a/drivers/ata/libata.h
  33721. +++ b/drivers/ata/libata.h
  33722. @@ -53,7 +53,7 @@ enum {
  33723. ATA_DNXFER_QUIET = (1 << 31),
  33724. };
  33725. -extern atomic_t ata_print_id;
  33726. +extern atomic_unchecked_t ata_print_id;
  33727. extern int atapi_passthru16;
  33728. extern int libata_fua;
  33729. extern int libata_noacpi;
  33730. diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
  33731. index 73492dd..ca2bff5 100644
  33732. --- a/drivers/ata/pata_arasan_cf.c
  33733. +++ b/drivers/ata/pata_arasan_cf.c
  33734. @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
  33735. /* Handle platform specific quirks */
  33736. if (quirk) {
  33737. if (quirk & CF_BROKEN_PIO) {
  33738. - ap->ops->set_piomode = NULL;
  33739. + pax_open_kernel();
  33740. + *(void **)&ap->ops->set_piomode = NULL;
  33741. + pax_close_kernel();
  33742. ap->pio_mask = 0;
  33743. }
  33744. if (quirk & CF_BROKEN_MWDMA)
  33745. diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
  33746. index f9b983a..887b9d8 100644
  33747. --- a/drivers/atm/adummy.c
  33748. +++ b/drivers/atm/adummy.c
  33749. @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
  33750. vcc->pop(vcc, skb);
  33751. else
  33752. dev_kfree_skb_any(skb);
  33753. - atomic_inc(&vcc->stats->tx);
  33754. + atomic_inc_unchecked(&vcc->stats->tx);
  33755. return 0;
  33756. }
  33757. diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
  33758. index 62a7607..cc4be104 100644
  33759. --- a/drivers/atm/ambassador.c
  33760. +++ b/drivers/atm/ambassador.c
  33761. @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
  33762. PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
  33763. // VC layer stats
  33764. - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
  33765. + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
  33766. // free the descriptor
  33767. kfree (tx_descr);
  33768. @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
  33769. dump_skb ("<<<", vc, skb);
  33770. // VC layer stats
  33771. - atomic_inc(&atm_vcc->stats->rx);
  33772. + atomic_inc_unchecked(&atm_vcc->stats->rx);
  33773. __net_timestamp(skb);
  33774. // end of our responsibility
  33775. atm_vcc->push (atm_vcc, skb);
  33776. @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
  33777. } else {
  33778. PRINTK (KERN_INFO, "dropped over-size frame");
  33779. // should we count this?
  33780. - atomic_inc(&atm_vcc->stats->rx_drop);
  33781. + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
  33782. }
  33783. } else {
  33784. @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
  33785. }
  33786. if (check_area (skb->data, skb->len)) {
  33787. - atomic_inc(&atm_vcc->stats->tx_err);
  33788. + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
  33789. return -ENOMEM; // ?
  33790. }
  33791. diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
  33792. index 0e3f8f9..765a7a5 100644
  33793. --- a/drivers/atm/atmtcp.c
  33794. +++ b/drivers/atm/atmtcp.c
  33795. @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
  33796. if (vcc->pop) vcc->pop(vcc,skb);
  33797. else dev_kfree_skb(skb);
  33798. if (dev_data) return 0;
  33799. - atomic_inc(&vcc->stats->tx_err);
  33800. + atomic_inc_unchecked(&vcc->stats->tx_err);
  33801. return -ENOLINK;
  33802. }
  33803. size = skb->len+sizeof(struct atmtcp_hdr);
  33804. @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
  33805. if (!new_skb) {
  33806. if (vcc->pop) vcc->pop(vcc,skb);
  33807. else dev_kfree_skb(skb);
  33808. - atomic_inc(&vcc->stats->tx_err);
  33809. + atomic_inc_unchecked(&vcc->stats->tx_err);
  33810. return -ENOBUFS;
  33811. }
  33812. hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
  33813. @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
  33814. if (vcc->pop) vcc->pop(vcc,skb);
  33815. else dev_kfree_skb(skb);
  33816. out_vcc->push(out_vcc,new_skb);
  33817. - atomic_inc(&vcc->stats->tx);
  33818. - atomic_inc(&out_vcc->stats->rx);
  33819. + atomic_inc_unchecked(&vcc->stats->tx);
  33820. + atomic_inc_unchecked(&out_vcc->stats->rx);
  33821. return 0;
  33822. }
  33823. @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
  33824. out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
  33825. read_unlock(&vcc_sklist_lock);
  33826. if (!out_vcc) {
  33827. - atomic_inc(&vcc->stats->tx_err);
  33828. + atomic_inc_unchecked(&vcc->stats->tx_err);
  33829. goto done;
  33830. }
  33831. skb_pull(skb,sizeof(struct atmtcp_hdr));
  33832. @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
  33833. __net_timestamp(new_skb);
  33834. skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
  33835. out_vcc->push(out_vcc,new_skb);
  33836. - atomic_inc(&vcc->stats->tx);
  33837. - atomic_inc(&out_vcc->stats->rx);
  33838. + atomic_inc_unchecked(&vcc->stats->tx);
  33839. + atomic_inc_unchecked(&out_vcc->stats->rx);
  33840. done:
  33841. if (vcc->pop) vcc->pop(vcc,skb);
  33842. else dev_kfree_skb(skb);
  33843. diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
  33844. index b1955ba..b179940 100644
  33845. --- a/drivers/atm/eni.c
  33846. +++ b/drivers/atm/eni.c
  33847. @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
  33848. DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
  33849. vcc->dev->number);
  33850. length = 0;
  33851. - atomic_inc(&vcc->stats->rx_err);
  33852. + atomic_inc_unchecked(&vcc->stats->rx_err);
  33853. }
  33854. else {
  33855. length = ATM_CELL_SIZE-1; /* no HEC */
  33856. @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
  33857. size);
  33858. }
  33859. eff = length = 0;
  33860. - atomic_inc(&vcc->stats->rx_err);
  33861. + atomic_inc_unchecked(&vcc->stats->rx_err);
  33862. }
  33863. else {
  33864. size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
  33865. @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
  33866. "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
  33867. vcc->dev->number,vcc->vci,length,size << 2,descr);
  33868. length = eff = 0;
  33869. - atomic_inc(&vcc->stats->rx_err);
  33870. + atomic_inc_unchecked(&vcc->stats->rx_err);
  33871. }
  33872. }
  33873. skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
  33874. @@ -767,7 +767,7 @@ rx_dequeued++;
  33875. vcc->push(vcc,skb);
  33876. pushed++;
  33877. }
  33878. - atomic_inc(&vcc->stats->rx);
  33879. + atomic_inc_unchecked(&vcc->stats->rx);
  33880. }
  33881. wake_up(&eni_dev->rx_wait);
  33882. }
  33883. @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
  33884. PCI_DMA_TODEVICE);
  33885. if (vcc->pop) vcc->pop(vcc,skb);
  33886. else dev_kfree_skb_irq(skb);
  33887. - atomic_inc(&vcc->stats->tx);
  33888. + atomic_inc_unchecked(&vcc->stats->tx);
  33889. wake_up(&eni_dev->tx_wait);
  33890. dma_complete++;
  33891. }
  33892. diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
  33893. index b41c948..a002b17 100644
  33894. --- a/drivers/atm/firestream.c
  33895. +++ b/drivers/atm/firestream.c
  33896. @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
  33897. }
  33898. }
  33899. - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
  33900. + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
  33901. fs_dprintk (FS_DEBUG_TXMEM, "i");
  33902. fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
  33903. @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
  33904. #endif
  33905. skb_put (skb, qe->p1 & 0xffff);
  33906. ATM_SKB(skb)->vcc = atm_vcc;
  33907. - atomic_inc(&atm_vcc->stats->rx);
  33908. + atomic_inc_unchecked(&atm_vcc->stats->rx);
  33909. __net_timestamp(skb);
  33910. fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
  33911. atm_vcc->push (atm_vcc, skb);
  33912. @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
  33913. kfree (pe);
  33914. }
  33915. if (atm_vcc)
  33916. - atomic_inc(&atm_vcc->stats->rx_drop);
  33917. + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
  33918. break;
  33919. case 0x1f: /* Reassembly abort: no buffers. */
  33920. /* Silently increment error counter. */
  33921. if (atm_vcc)
  33922. - atomic_inc(&atm_vcc->stats->rx_drop);
  33923. + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
  33924. break;
  33925. default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
  33926. printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
  33927. diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
  33928. index 204814e..cede831 100644
  33929. --- a/drivers/atm/fore200e.c
  33930. +++ b/drivers/atm/fore200e.c
  33931. @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
  33932. #endif
  33933. /* check error condition */
  33934. if (*entry->status & STATUS_ERROR)
  33935. - atomic_inc(&vcc->stats->tx_err);
  33936. + atomic_inc_unchecked(&vcc->stats->tx_err);
  33937. else
  33938. - atomic_inc(&vcc->stats->tx);
  33939. + atomic_inc_unchecked(&vcc->stats->tx);
  33940. }
  33941. }
  33942. @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
  33943. if (skb == NULL) {
  33944. DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
  33945. - atomic_inc(&vcc->stats->rx_drop);
  33946. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  33947. return -ENOMEM;
  33948. }
  33949. @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
  33950. dev_kfree_skb_any(skb);
  33951. - atomic_inc(&vcc->stats->rx_drop);
  33952. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  33953. return -ENOMEM;
  33954. }
  33955. ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
  33956. vcc->push(vcc, skb);
  33957. - atomic_inc(&vcc->stats->rx);
  33958. + atomic_inc_unchecked(&vcc->stats->rx);
  33959. ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
  33960. @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
  33961. DPRINTK(2, "damaged PDU on %d.%d.%d\n",
  33962. fore200e->atm_dev->number,
  33963. entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
  33964. - atomic_inc(&vcc->stats->rx_err);
  33965. + atomic_inc_unchecked(&vcc->stats->rx_err);
  33966. }
  33967. }
  33968. @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
  33969. goto retry_here;
  33970. }
  33971. - atomic_inc(&vcc->stats->tx_err);
  33972. + atomic_inc_unchecked(&vcc->stats->tx_err);
  33973. fore200e->tx_sat++;
  33974. DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
  33975. diff --git a/drivers/atm/he.c b/drivers/atm/he.c
  33976. index aa6be26..f70a785 100644
  33977. --- a/drivers/atm/he.c
  33978. +++ b/drivers/atm/he.c
  33979. @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
  33980. if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
  33981. hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
  33982. - atomic_inc(&vcc->stats->rx_drop);
  33983. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  33984. goto return_host_buffers;
  33985. }
  33986. @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
  33987. RBRQ_LEN_ERR(he_dev->rbrq_head)
  33988. ? "LEN_ERR" : "",
  33989. vcc->vpi, vcc->vci);
  33990. - atomic_inc(&vcc->stats->rx_err);
  33991. + atomic_inc_unchecked(&vcc->stats->rx_err);
  33992. goto return_host_buffers;
  33993. }
  33994. @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
  33995. vcc->push(vcc, skb);
  33996. spin_lock(&he_dev->global_lock);
  33997. - atomic_inc(&vcc->stats->rx);
  33998. + atomic_inc_unchecked(&vcc->stats->rx);
  33999. return_host_buffers:
  34000. ++pdus_assembled;
  34001. @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
  34002. tpd->vcc->pop(tpd->vcc, tpd->skb);
  34003. else
  34004. dev_kfree_skb_any(tpd->skb);
  34005. - atomic_inc(&tpd->vcc->stats->tx_err);
  34006. + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
  34007. }
  34008. pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
  34009. return;
  34010. @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34011. vcc->pop(vcc, skb);
  34012. else
  34013. dev_kfree_skb_any(skb);
  34014. - atomic_inc(&vcc->stats->tx_err);
  34015. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34016. return -EINVAL;
  34017. }
  34018. @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34019. vcc->pop(vcc, skb);
  34020. else
  34021. dev_kfree_skb_any(skb);
  34022. - atomic_inc(&vcc->stats->tx_err);
  34023. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34024. return -EINVAL;
  34025. }
  34026. #endif
  34027. @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34028. vcc->pop(vcc, skb);
  34029. else
  34030. dev_kfree_skb_any(skb);
  34031. - atomic_inc(&vcc->stats->tx_err);
  34032. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34033. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  34034. return -ENOMEM;
  34035. }
  34036. @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34037. vcc->pop(vcc, skb);
  34038. else
  34039. dev_kfree_skb_any(skb);
  34040. - atomic_inc(&vcc->stats->tx_err);
  34041. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34042. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  34043. return -ENOMEM;
  34044. }
  34045. @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34046. __enqueue_tpd(he_dev, tpd, cid);
  34047. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  34048. - atomic_inc(&vcc->stats->tx);
  34049. + atomic_inc_unchecked(&vcc->stats->tx);
  34050. return 0;
  34051. }
  34052. diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
  34053. index 1dc0519..1aadaf7 100644
  34054. --- a/drivers/atm/horizon.c
  34055. +++ b/drivers/atm/horizon.c
  34056. @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
  34057. {
  34058. struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
  34059. // VC layer stats
  34060. - atomic_inc(&vcc->stats->rx);
  34061. + atomic_inc_unchecked(&vcc->stats->rx);
  34062. __net_timestamp(skb);
  34063. // end of our responsibility
  34064. vcc->push (vcc, skb);
  34065. @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
  34066. dev->tx_iovec = NULL;
  34067. // VC layer stats
  34068. - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
  34069. + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
  34070. // free the skb
  34071. hrz_kfree_skb (skb);
  34072. diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
  34073. index 1bdf104..9dc44b1 100644
  34074. --- a/drivers/atm/idt77252.c
  34075. +++ b/drivers/atm/idt77252.c
  34076. @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
  34077. else
  34078. dev_kfree_skb(skb);
  34079. - atomic_inc(&vcc->stats->tx);
  34080. + atomic_inc_unchecked(&vcc->stats->tx);
  34081. }
  34082. atomic_dec(&scq->used);
  34083. @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  34084. if ((sb = dev_alloc_skb(64)) == NULL) {
  34085. printk("%s: Can't allocate buffers for aal0.\n",
  34086. card->name);
  34087. - atomic_add(i, &vcc->stats->rx_drop);
  34088. + atomic_add_unchecked(i, &vcc->stats->rx_drop);
  34089. break;
  34090. }
  34091. if (!atm_charge(vcc, sb->truesize)) {
  34092. RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
  34093. card->name);
  34094. - atomic_add(i - 1, &vcc->stats->rx_drop);
  34095. + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
  34096. dev_kfree_skb(sb);
  34097. break;
  34098. }
  34099. @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  34100. ATM_SKB(sb)->vcc = vcc;
  34101. __net_timestamp(sb);
  34102. vcc->push(vcc, sb);
  34103. - atomic_inc(&vcc->stats->rx);
  34104. + atomic_inc_unchecked(&vcc->stats->rx);
  34105. cell += ATM_CELL_PAYLOAD;
  34106. }
  34107. @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  34108. "(CDC: %08x)\n",
  34109. card->name, len, rpp->len, readl(SAR_REG_CDC));
  34110. recycle_rx_pool_skb(card, rpp);
  34111. - atomic_inc(&vcc->stats->rx_err);
  34112. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34113. return;
  34114. }
  34115. if (stat & SAR_RSQE_CRC) {
  34116. RXPRINTK("%s: AAL5 CRC error.\n", card->name);
  34117. recycle_rx_pool_skb(card, rpp);
  34118. - atomic_inc(&vcc->stats->rx_err);
  34119. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34120. return;
  34121. }
  34122. if (skb_queue_len(&rpp->queue) > 1) {
  34123. @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  34124. RXPRINTK("%s: Can't alloc RX skb.\n",
  34125. card->name);
  34126. recycle_rx_pool_skb(card, rpp);
  34127. - atomic_inc(&vcc->stats->rx_err);
  34128. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34129. return;
  34130. }
  34131. if (!atm_charge(vcc, skb->truesize)) {
  34132. @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  34133. __net_timestamp(skb);
  34134. vcc->push(vcc, skb);
  34135. - atomic_inc(&vcc->stats->rx);
  34136. + atomic_inc_unchecked(&vcc->stats->rx);
  34137. return;
  34138. }
  34139. @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  34140. __net_timestamp(skb);
  34141. vcc->push(vcc, skb);
  34142. - atomic_inc(&vcc->stats->rx);
  34143. + atomic_inc_unchecked(&vcc->stats->rx);
  34144. if (skb->truesize > SAR_FB_SIZE_3)
  34145. add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
  34146. @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
  34147. if (vcc->qos.aal != ATM_AAL0) {
  34148. RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
  34149. card->name, vpi, vci);
  34150. - atomic_inc(&vcc->stats->rx_drop);
  34151. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34152. goto drop;
  34153. }
  34154. if ((sb = dev_alloc_skb(64)) == NULL) {
  34155. printk("%s: Can't allocate buffers for AAL0.\n",
  34156. card->name);
  34157. - atomic_inc(&vcc->stats->rx_err);
  34158. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34159. goto drop;
  34160. }
  34161. @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
  34162. ATM_SKB(sb)->vcc = vcc;
  34163. __net_timestamp(sb);
  34164. vcc->push(vcc, sb);
  34165. - atomic_inc(&vcc->stats->rx);
  34166. + atomic_inc_unchecked(&vcc->stats->rx);
  34167. drop:
  34168. skb_pull(queue, 64);
  34169. @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
  34170. if (vc == NULL) {
  34171. printk("%s: NULL connection in send().\n", card->name);
  34172. - atomic_inc(&vcc->stats->tx_err);
  34173. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34174. dev_kfree_skb(skb);
  34175. return -EINVAL;
  34176. }
  34177. if (!test_bit(VCF_TX, &vc->flags)) {
  34178. printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
  34179. - atomic_inc(&vcc->stats->tx_err);
  34180. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34181. dev_kfree_skb(skb);
  34182. return -EINVAL;
  34183. }
  34184. @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
  34185. break;
  34186. default:
  34187. printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
  34188. - atomic_inc(&vcc->stats->tx_err);
  34189. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34190. dev_kfree_skb(skb);
  34191. return -EINVAL;
  34192. }
  34193. if (skb_shinfo(skb)->nr_frags != 0) {
  34194. printk("%s: No scatter-gather yet.\n", card->name);
  34195. - atomic_inc(&vcc->stats->tx_err);
  34196. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34197. dev_kfree_skb(skb);
  34198. return -EINVAL;
  34199. }
  34200. @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
  34201. err = queue_skb(card, vc, skb, oam);
  34202. if (err) {
  34203. - atomic_inc(&vcc->stats->tx_err);
  34204. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34205. dev_kfree_skb(skb);
  34206. return err;
  34207. }
  34208. @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
  34209. skb = dev_alloc_skb(64);
  34210. if (!skb) {
  34211. printk("%s: Out of memory in send_oam().\n", card->name);
  34212. - atomic_inc(&vcc->stats->tx_err);
  34213. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34214. return -ENOMEM;
  34215. }
  34216. atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  34217. diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
  34218. index 4217f29..88f547a 100644
  34219. --- a/drivers/atm/iphase.c
  34220. +++ b/drivers/atm/iphase.c
  34221. @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
  34222. status = (u_short) (buf_desc_ptr->desc_mode);
  34223. if (status & (RX_CER | RX_PTE | RX_OFL))
  34224. {
  34225. - atomic_inc(&vcc->stats->rx_err);
  34226. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34227. IF_ERR(printk("IA: bad packet, dropping it");)
  34228. if (status & RX_CER) {
  34229. IF_ERR(printk(" cause: packet CRC error\n");)
  34230. @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
  34231. len = dma_addr - buf_addr;
  34232. if (len > iadev->rx_buf_sz) {
  34233. printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
  34234. - atomic_inc(&vcc->stats->rx_err);
  34235. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34236. goto out_free_desc;
  34237. }
  34238. @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
  34239. ia_vcc = INPH_IA_VCC(vcc);
  34240. if (ia_vcc == NULL)
  34241. {
  34242. - atomic_inc(&vcc->stats->rx_err);
  34243. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34244. atm_return(vcc, skb->truesize);
  34245. dev_kfree_skb_any(skb);
  34246. goto INCR_DLE;
  34247. @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
  34248. if ((length > iadev->rx_buf_sz) || (length >
  34249. (skb->len - sizeof(struct cpcs_trailer))))
  34250. {
  34251. - atomic_inc(&vcc->stats->rx_err);
  34252. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34253. IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
  34254. length, skb->len);)
  34255. atm_return(vcc, skb->truesize);
  34256. @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
  34257. IF_RX(printk("rx_dle_intr: skb push");)
  34258. vcc->push(vcc,skb);
  34259. - atomic_inc(&vcc->stats->rx);
  34260. + atomic_inc_unchecked(&vcc->stats->rx);
  34261. iadev->rx_pkt_cnt++;
  34262. }
  34263. INCR_DLE:
  34264. @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
  34265. {
  34266. struct k_sonet_stats *stats;
  34267. stats = &PRIV(_ia_dev[board])->sonet_stats;
  34268. - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
  34269. - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
  34270. - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
  34271. - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
  34272. - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
  34273. - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
  34274. - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
  34275. - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
  34276. - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
  34277. + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
  34278. + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
  34279. + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
  34280. + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
  34281. + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
  34282. + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
  34283. + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
  34284. + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
  34285. + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
  34286. }
  34287. ia_cmds.status = 0;
  34288. break;
  34289. @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
  34290. if ((desc == 0) || (desc > iadev->num_tx_desc))
  34291. {
  34292. IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
  34293. - atomic_inc(&vcc->stats->tx);
  34294. + atomic_inc_unchecked(&vcc->stats->tx);
  34295. if (vcc->pop)
  34296. vcc->pop(vcc, skb);
  34297. else
  34298. @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
  34299. ATM_DESC(skb) = vcc->vci;
  34300. skb_queue_tail(&iadev->tx_dma_q, skb);
  34301. - atomic_inc(&vcc->stats->tx);
  34302. + atomic_inc_unchecked(&vcc->stats->tx);
  34303. iadev->tx_pkt_cnt++;
  34304. /* Increment transaction counter */
  34305. writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
  34306. #if 0
  34307. /* add flow control logic */
  34308. - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
  34309. + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
  34310. if (iavcc->vc_desc_cnt > 10) {
  34311. vcc->tx_quota = vcc->tx_quota * 3 / 4;
  34312. printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
  34313. diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
  34314. index fa7d701..1e404c7 100644
  34315. --- a/drivers/atm/lanai.c
  34316. +++ b/drivers/atm/lanai.c
  34317. @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
  34318. vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
  34319. lanai_endtx(lanai, lvcc);
  34320. lanai_free_skb(lvcc->tx.atmvcc, skb);
  34321. - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
  34322. + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
  34323. }
  34324. /* Try to fill the buffer - don't call unless there is backlog */
  34325. @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
  34326. ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
  34327. __net_timestamp(skb);
  34328. lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
  34329. - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
  34330. + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
  34331. out:
  34332. lvcc->rx.buf.ptr = end;
  34333. cardvcc_write(lvcc, endptr, vcc_rxreadptr);
  34334. @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
  34335. DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
  34336. "vcc %d\n", lanai->number, (unsigned int) s, vci);
  34337. lanai->stats.service_rxnotaal5++;
  34338. - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  34339. + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
  34340. return 0;
  34341. }
  34342. if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
  34343. @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
  34344. int bytes;
  34345. read_unlock(&vcc_sklist_lock);
  34346. DPRINTK("got trashed rx pdu on vci %d\n", vci);
  34347. - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  34348. + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
  34349. lvcc->stats.x.aal5.service_trash++;
  34350. bytes = (SERVICE_GET_END(s) * 16) -
  34351. (((unsigned long) lvcc->rx.buf.ptr) -
  34352. @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
  34353. }
  34354. if (s & SERVICE_STREAM) {
  34355. read_unlock(&vcc_sklist_lock);
  34356. - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  34357. + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
  34358. lvcc->stats.x.aal5.service_stream++;
  34359. printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
  34360. "PDU on VCI %d!\n", lanai->number, vci);
  34361. @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
  34362. return 0;
  34363. }
  34364. DPRINTK("got rx crc error on vci %d\n", vci);
  34365. - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  34366. + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
  34367. lvcc->stats.x.aal5.service_rxcrc++;
  34368. lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
  34369. cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
  34370. diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
  34371. index 9587e95..b45c5cb 100644
  34372. --- a/drivers/atm/nicstar.c
  34373. +++ b/drivers/atm/nicstar.c
  34374. @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34375. if ((vc = (vc_map *) vcc->dev_data) == NULL) {
  34376. printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
  34377. card->index);
  34378. - atomic_inc(&vcc->stats->tx_err);
  34379. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34380. dev_kfree_skb_any(skb);
  34381. return -EINVAL;
  34382. }
  34383. @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34384. if (!vc->tx) {
  34385. printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
  34386. card->index);
  34387. - atomic_inc(&vcc->stats->tx_err);
  34388. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34389. dev_kfree_skb_any(skb);
  34390. return -EINVAL;
  34391. }
  34392. @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34393. if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
  34394. printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
  34395. card->index);
  34396. - atomic_inc(&vcc->stats->tx_err);
  34397. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34398. dev_kfree_skb_any(skb);
  34399. return -EINVAL;
  34400. }
  34401. if (skb_shinfo(skb)->nr_frags != 0) {
  34402. printk("nicstar%d: No scatter-gather yet.\n", card->index);
  34403. - atomic_inc(&vcc->stats->tx_err);
  34404. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34405. dev_kfree_skb_any(skb);
  34406. return -EINVAL;
  34407. }
  34408. @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
  34409. }
  34410. if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
  34411. - atomic_inc(&vcc->stats->tx_err);
  34412. + atomic_inc_unchecked(&vcc->stats->tx_err);
  34413. dev_kfree_skb_any(skb);
  34414. return -EIO;
  34415. }
  34416. - atomic_inc(&vcc->stats->tx);
  34417. + atomic_inc_unchecked(&vcc->stats->tx);
  34418. return 0;
  34419. }
  34420. @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34421. printk
  34422. ("nicstar%d: Can't allocate buffers for aal0.\n",
  34423. card->index);
  34424. - atomic_add(i, &vcc->stats->rx_drop);
  34425. + atomic_add_unchecked(i, &vcc->stats->rx_drop);
  34426. break;
  34427. }
  34428. if (!atm_charge(vcc, sb->truesize)) {
  34429. RXPRINTK
  34430. ("nicstar%d: atm_charge() dropped aal0 packets.\n",
  34431. card->index);
  34432. - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
  34433. + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
  34434. dev_kfree_skb_any(sb);
  34435. break;
  34436. }
  34437. @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34438. ATM_SKB(sb)->vcc = vcc;
  34439. __net_timestamp(sb);
  34440. vcc->push(vcc, sb);
  34441. - atomic_inc(&vcc->stats->rx);
  34442. + atomic_inc_unchecked(&vcc->stats->rx);
  34443. cell += ATM_CELL_PAYLOAD;
  34444. }
  34445. @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34446. if (iovb == NULL) {
  34447. printk("nicstar%d: Out of iovec buffers.\n",
  34448. card->index);
  34449. - atomic_inc(&vcc->stats->rx_drop);
  34450. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34451. recycle_rx_buf(card, skb);
  34452. return;
  34453. }
  34454. @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34455. small or large buffer itself. */
  34456. } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
  34457. printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
  34458. - atomic_inc(&vcc->stats->rx_err);
  34459. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34460. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  34461. NS_MAX_IOVECS);
  34462. NS_PRV_IOVCNT(iovb) = 0;
  34463. @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34464. ("nicstar%d: Expected a small buffer, and this is not one.\n",
  34465. card->index);
  34466. which_list(card, skb);
  34467. - atomic_inc(&vcc->stats->rx_err);
  34468. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34469. recycle_rx_buf(card, skb);
  34470. vc->rx_iov = NULL;
  34471. recycle_iov_buf(card, iovb);
  34472. @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34473. ("nicstar%d: Expected a large buffer, and this is not one.\n",
  34474. card->index);
  34475. which_list(card, skb);
  34476. - atomic_inc(&vcc->stats->rx_err);
  34477. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34478. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  34479. NS_PRV_IOVCNT(iovb));
  34480. vc->rx_iov = NULL;
  34481. @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34482. printk(" - PDU size mismatch.\n");
  34483. else
  34484. printk(".\n");
  34485. - atomic_inc(&vcc->stats->rx_err);
  34486. + atomic_inc_unchecked(&vcc->stats->rx_err);
  34487. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  34488. NS_PRV_IOVCNT(iovb));
  34489. vc->rx_iov = NULL;
  34490. @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34491. /* skb points to a small buffer */
  34492. if (!atm_charge(vcc, skb->truesize)) {
  34493. push_rxbufs(card, skb);
  34494. - atomic_inc(&vcc->stats->rx_drop);
  34495. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34496. } else {
  34497. skb_put(skb, len);
  34498. dequeue_sm_buf(card, skb);
  34499. @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34500. ATM_SKB(skb)->vcc = vcc;
  34501. __net_timestamp(skb);
  34502. vcc->push(vcc, skb);
  34503. - atomic_inc(&vcc->stats->rx);
  34504. + atomic_inc_unchecked(&vcc->stats->rx);
  34505. }
  34506. } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
  34507. struct sk_buff *sb;
  34508. @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34509. if (len <= NS_SMBUFSIZE) {
  34510. if (!atm_charge(vcc, sb->truesize)) {
  34511. push_rxbufs(card, sb);
  34512. - atomic_inc(&vcc->stats->rx_drop);
  34513. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34514. } else {
  34515. skb_put(sb, len);
  34516. dequeue_sm_buf(card, sb);
  34517. @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34518. ATM_SKB(sb)->vcc = vcc;
  34519. __net_timestamp(sb);
  34520. vcc->push(vcc, sb);
  34521. - atomic_inc(&vcc->stats->rx);
  34522. + atomic_inc_unchecked(&vcc->stats->rx);
  34523. }
  34524. push_rxbufs(card, skb);
  34525. @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34526. if (!atm_charge(vcc, skb->truesize)) {
  34527. push_rxbufs(card, skb);
  34528. - atomic_inc(&vcc->stats->rx_drop);
  34529. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34530. } else {
  34531. dequeue_lg_buf(card, skb);
  34532. #ifdef NS_USE_DESTRUCTORS
  34533. @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34534. ATM_SKB(skb)->vcc = vcc;
  34535. __net_timestamp(skb);
  34536. vcc->push(vcc, skb);
  34537. - atomic_inc(&vcc->stats->rx);
  34538. + atomic_inc_unchecked(&vcc->stats->rx);
  34539. }
  34540. push_rxbufs(card, sb);
  34541. @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34542. printk
  34543. ("nicstar%d: Out of huge buffers.\n",
  34544. card->index);
  34545. - atomic_inc(&vcc->stats->rx_drop);
  34546. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34547. recycle_iovec_rx_bufs(card,
  34548. (struct iovec *)
  34549. iovb->data,
  34550. @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34551. card->hbpool.count++;
  34552. } else
  34553. dev_kfree_skb_any(hb);
  34554. - atomic_inc(&vcc->stats->rx_drop);
  34555. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  34556. } else {
  34557. /* Copy the small buffer to the huge buffer */
  34558. sb = (struct sk_buff *)iov->iov_base;
  34559. @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  34560. #endif /* NS_USE_DESTRUCTORS */
  34561. __net_timestamp(hb);
  34562. vcc->push(vcc, hb);
  34563. - atomic_inc(&vcc->stats->rx);
  34564. + atomic_inc_unchecked(&vcc->stats->rx);
  34565. }
  34566. }
  34567. diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
  34568. index e3fb496..d9646bf 100644
  34569. --- a/drivers/atm/solos-pci.c
  34570. +++ b/drivers/atm/solos-pci.c
  34571. @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
  34572. }
  34573. atm_charge(vcc, skb->truesize);
  34574. vcc->push(vcc, skb);
  34575. - atomic_inc(&vcc->stats->rx);
  34576. + atomic_inc_unchecked(&vcc->stats->rx);
  34577. break;
  34578. case PKT_STATUS:
  34579. @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
  34580. vcc = SKB_CB(oldskb)->vcc;
  34581. if (vcc) {
  34582. - atomic_inc(&vcc->stats->tx);
  34583. + atomic_inc_unchecked(&vcc->stats->tx);
  34584. solos_pop(vcc, oldskb);
  34585. } else {
  34586. dev_kfree_skb_irq(oldskb);
  34587. diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
  34588. index 0215934..ce9f5b1 100644
  34589. --- a/drivers/atm/suni.c
  34590. +++ b/drivers/atm/suni.c
  34591. @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
  34592. #define ADD_LIMITED(s,v) \
  34593. - atomic_add((v),&stats->s); \
  34594. - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
  34595. + atomic_add_unchecked((v),&stats->s); \
  34596. + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
  34597. static void suni_hz(unsigned long from_timer)
  34598. diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
  34599. index 5120a96..e2572bd 100644
  34600. --- a/drivers/atm/uPD98402.c
  34601. +++ b/drivers/atm/uPD98402.c
  34602. @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
  34603. struct sonet_stats tmp;
  34604. int error = 0;
  34605. - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
  34606. + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
  34607. sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
  34608. if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
  34609. if (zero && !error) {
  34610. @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
  34611. #define ADD_LIMITED(s,v) \
  34612. - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
  34613. - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
  34614. - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
  34615. + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
  34616. + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
  34617. + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
  34618. static void stat_event(struct atm_dev *dev)
  34619. @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
  34620. if (reason & uPD98402_INT_PFM) stat_event(dev);
  34621. if (reason & uPD98402_INT_PCO) {
  34622. (void) GET(PCOCR); /* clear interrupt cause */
  34623. - atomic_add(GET(HECCT),
  34624. + atomic_add_unchecked(GET(HECCT),
  34625. &PRIV(dev)->sonet_stats.uncorr_hcs);
  34626. }
  34627. if ((reason & uPD98402_INT_RFO) &&
  34628. @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
  34629. PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
  34630. uPD98402_INT_LOS),PIMR); /* enable them */
  34631. (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
  34632. - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
  34633. - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
  34634. - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
  34635. + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
  34636. + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
  34637. + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
  34638. return 0;
  34639. }
  34640. diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
  34641. index 969c3c2..9b72956 100644
  34642. --- a/drivers/atm/zatm.c
  34643. +++ b/drivers/atm/zatm.c
  34644. @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
  34645. }
  34646. if (!size) {
  34647. dev_kfree_skb_irq(skb);
  34648. - if (vcc) atomic_inc(&vcc->stats->rx_err);
  34649. + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
  34650. continue;
  34651. }
  34652. if (!atm_charge(vcc,skb->truesize)) {
  34653. @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
  34654. skb->len = size;
  34655. ATM_SKB(skb)->vcc = vcc;
  34656. vcc->push(vcc,skb);
  34657. - atomic_inc(&vcc->stats->rx);
  34658. + atomic_inc_unchecked(&vcc->stats->rx);
  34659. }
  34660. zout(pos & 0xffff,MTA(mbx));
  34661. #if 0 /* probably a stupid idea */
  34662. @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
  34663. skb_queue_head(&zatm_vcc->backlog,skb);
  34664. break;
  34665. }
  34666. - atomic_inc(&vcc->stats->tx);
  34667. + atomic_inc_unchecked(&vcc->stats->tx);
  34668. wake_up(&zatm_vcc->tx_wait);
  34669. }
  34670. diff --git a/drivers/base/bus.c b/drivers/base/bus.c
  34671. index 59dc808..f10c74e 100644
  34672. --- a/drivers/base/bus.c
  34673. +++ b/drivers/base/bus.c
  34674. @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
  34675. return -EINVAL;
  34676. mutex_lock(&subsys->p->mutex);
  34677. - list_add_tail(&sif->node, &subsys->p->interfaces);
  34678. + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
  34679. if (sif->add_dev) {
  34680. subsys_dev_iter_init(&iter, subsys, NULL, NULL);
  34681. while ((dev = subsys_dev_iter_next(&iter)))
  34682. @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
  34683. subsys = sif->subsys;
  34684. mutex_lock(&subsys->p->mutex);
  34685. - list_del_init(&sif->node);
  34686. + pax_list_del_init((struct list_head *)&sif->node);
  34687. if (sif->remove_dev) {
  34688. subsys_dev_iter_init(&iter, subsys, NULL, NULL);
  34689. while ((dev = subsys_dev_iter_next(&iter)))
  34690. diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
  34691. index 25798db..15f130e 100644
  34692. --- a/drivers/base/devtmpfs.c
  34693. +++ b/drivers/base/devtmpfs.c
  34694. @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
  34695. if (!thread)
  34696. return 0;
  34697. - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
  34698. + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
  34699. if (err)
  34700. printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
  34701. else
  34702. @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
  34703. *err = sys_unshare(CLONE_NEWNS);
  34704. if (*err)
  34705. goto out;
  34706. - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
  34707. + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
  34708. if (*err)
  34709. goto out;
  34710. - sys_chdir("/.."); /* will traverse into overmounted root */
  34711. - sys_chroot(".");
  34712. + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
  34713. + sys_chroot((char __force_user *)".");
  34714. complete(&setup_done);
  34715. while (1) {
  34716. spin_lock(&req_lock);
  34717. diff --git a/drivers/base/node.c b/drivers/base/node.c
  34718. index bc9f43b..29703b8 100644
  34719. --- a/drivers/base/node.c
  34720. +++ b/drivers/base/node.c
  34721. @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
  34722. struct node_attr {
  34723. struct device_attribute attr;
  34724. enum node_states state;
  34725. -};
  34726. +} __do_const;
  34727. static ssize_t show_node_state(struct device *dev,
  34728. struct device_attribute *attr, char *buf)
  34729. diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
  34730. index bfb8955..4ebff34 100644
  34731. --- a/drivers/base/power/domain.c
  34732. +++ b/drivers/base/power/domain.c
  34733. @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
  34734. if (dev->power.subsys_data->domain_data) {
  34735. gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
  34736. - gpd_data->ops = (struct gpd_dev_ops){ NULL };
  34737. + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
  34738. if (clear_td)
  34739. - gpd_data->td = (struct gpd_timing_data){ 0 };
  34740. + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
  34741. if (--gpd_data->refcount == 0) {
  34742. dev->power.subsys_data->domain_data = NULL;
  34743. @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
  34744. {
  34745. struct cpuidle_driver *cpuidle_drv;
  34746. struct gpd_cpu_data *cpu_data;
  34747. - struct cpuidle_state *idle_state;
  34748. + cpuidle_state_no_const *idle_state;
  34749. int ret = 0;
  34750. if (IS_ERR_OR_NULL(genpd) || state < 0)
  34751. @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
  34752. int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
  34753. {
  34754. struct gpd_cpu_data *cpu_data;
  34755. - struct cpuidle_state *idle_state;
  34756. + cpuidle_state_no_const *idle_state;
  34757. int ret = 0;
  34758. if (IS_ERR_OR_NULL(genpd))
  34759. diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
  34760. index 03e089a..0e9560c 100644
  34761. --- a/drivers/base/power/sysfs.c
  34762. +++ b/drivers/base/power/sysfs.c
  34763. @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
  34764. return -EIO;
  34765. }
  34766. }
  34767. - return sprintf(buf, p);
  34768. + return sprintf(buf, "%s", p);
  34769. }
  34770. static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
  34771. diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
  34772. index 2d56f41..8830f19 100644
  34773. --- a/drivers/base/power/wakeup.c
  34774. +++ b/drivers/base/power/wakeup.c
  34775. @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
  34776. * They need to be modified together atomically, so it's better to use one
  34777. * atomic variable to hold them both.
  34778. */
  34779. -static atomic_t combined_event_count = ATOMIC_INIT(0);
  34780. +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
  34781. #define IN_PROGRESS_BITS (sizeof(int) * 4)
  34782. #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
  34783. static void split_counters(unsigned int *cnt, unsigned int *inpr)
  34784. {
  34785. - unsigned int comb = atomic_read(&combined_event_count);
  34786. + unsigned int comb = atomic_read_unchecked(&combined_event_count);
  34787. *cnt = (comb >> IN_PROGRESS_BITS);
  34788. *inpr = comb & MAX_IN_PROGRESS;
  34789. @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
  34790. ws->start_prevent_time = ws->last_time;
  34791. /* Increment the counter of events in progress. */
  34792. - cec = atomic_inc_return(&combined_event_count);
  34793. + cec = atomic_inc_return_unchecked(&combined_event_count);
  34794. trace_wakeup_source_activate(ws->name, cec);
  34795. }
  34796. @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
  34797. * Increment the counter of registered wakeup events and decrement the
  34798. * couter of wakeup events in progress simultaneously.
  34799. */
  34800. - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
  34801. + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
  34802. trace_wakeup_source_deactivate(ws->name, cec);
  34803. split_counters(&cnt, &inpr);
  34804. diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
  34805. index e8d11b6..7b1b36f 100644
  34806. --- a/drivers/base/syscore.c
  34807. +++ b/drivers/base/syscore.c
  34808. @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
  34809. void register_syscore_ops(struct syscore_ops *ops)
  34810. {
  34811. mutex_lock(&syscore_ops_lock);
  34812. - list_add_tail(&ops->node, &syscore_ops_list);
  34813. + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
  34814. mutex_unlock(&syscore_ops_lock);
  34815. }
  34816. EXPORT_SYMBOL_GPL(register_syscore_ops);
  34817. @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
  34818. void unregister_syscore_ops(struct syscore_ops *ops)
  34819. {
  34820. mutex_lock(&syscore_ops_lock);
  34821. - list_del(&ops->node);
  34822. + pax_list_del((struct list_head *)&ops->node);
  34823. mutex_unlock(&syscore_ops_lock);
  34824. }
  34825. EXPORT_SYMBOL_GPL(unregister_syscore_ops);
  34826. diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
  34827. index 036e8ab..6221dec 100644
  34828. --- a/drivers/block/cciss.c
  34829. +++ b/drivers/block/cciss.c
  34830. @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
  34831. while (!list_empty(&h->reqQ)) {
  34832. c = list_entry(h->reqQ.next, CommandList_struct, list);
  34833. /* can't do anything if fifo is full */
  34834. - if ((h->access.fifo_full(h))) {
  34835. + if ((h->access->fifo_full(h))) {
  34836. dev_warn(&h->pdev->dev, "fifo full\n");
  34837. break;
  34838. }
  34839. @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
  34840. h->Qdepth--;
  34841. /* Tell the controller execute command */
  34842. - h->access.submit_command(h, c);
  34843. + h->access->submit_command(h, c);
  34844. /* Put job onto the completed Q */
  34845. addQ(&h->cmpQ, c);
  34846. @@ -3447,17 +3447,17 @@ startio:
  34847. static inline unsigned long get_next_completion(ctlr_info_t *h)
  34848. {
  34849. - return h->access.command_completed(h);
  34850. + return h->access->command_completed(h);
  34851. }
  34852. static inline int interrupt_pending(ctlr_info_t *h)
  34853. {
  34854. - return h->access.intr_pending(h);
  34855. + return h->access->intr_pending(h);
  34856. }
  34857. static inline long interrupt_not_for_us(ctlr_info_t *h)
  34858. {
  34859. - return ((h->access.intr_pending(h) == 0) ||
  34860. + return ((h->access->intr_pending(h) == 0) ||
  34861. (h->interrupts_enabled == 0));
  34862. }
  34863. @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
  34864. u32 a;
  34865. if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
  34866. - return h->access.command_completed(h);
  34867. + return h->access->command_completed(h);
  34868. if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
  34869. a = *(h->reply_pool_head); /* Next cmd in ring buffer */
  34870. @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
  34871. trans_support & CFGTBL_Trans_use_short_tags);
  34872. /* Change the access methods to the performant access methods */
  34873. - h->access = SA5_performant_access;
  34874. + h->access = &SA5_performant_access;
  34875. h->transMethod = CFGTBL_Trans_Performant;
  34876. return;
  34877. @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
  34878. if (prod_index < 0)
  34879. return -ENODEV;
  34880. h->product_name = products[prod_index].product_name;
  34881. - h->access = *(products[prod_index].access);
  34882. + h->access = products[prod_index].access;
  34883. if (cciss_board_disabled(h)) {
  34884. dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
  34885. @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
  34886. }
  34887. /* make sure the board interrupts are off */
  34888. - h->access.set_intr_mask(h, CCISS_INTR_OFF);
  34889. + h->access->set_intr_mask(h, CCISS_INTR_OFF);
  34890. rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
  34891. if (rc)
  34892. goto clean2;
  34893. @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
  34894. * fake ones to scoop up any residual completions.
  34895. */
  34896. spin_lock_irqsave(&h->lock, flags);
  34897. - h->access.set_intr_mask(h, CCISS_INTR_OFF);
  34898. + h->access->set_intr_mask(h, CCISS_INTR_OFF);
  34899. spin_unlock_irqrestore(&h->lock, flags);
  34900. free_irq(h->intr[h->intr_mode], h);
  34901. rc = cciss_request_irq(h, cciss_msix_discard_completions,
  34902. @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
  34903. dev_info(&h->pdev->dev, "Board READY.\n");
  34904. dev_info(&h->pdev->dev,
  34905. "Waiting for stale completions to drain.\n");
  34906. - h->access.set_intr_mask(h, CCISS_INTR_ON);
  34907. + h->access->set_intr_mask(h, CCISS_INTR_ON);
  34908. msleep(10000);
  34909. - h->access.set_intr_mask(h, CCISS_INTR_OFF);
  34910. + h->access->set_intr_mask(h, CCISS_INTR_OFF);
  34911. rc = controller_reset_failed(h->cfgtable);
  34912. if (rc)
  34913. @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
  34914. cciss_scsi_setup(h);
  34915. /* Turn the interrupts on so we can service requests */
  34916. - h->access.set_intr_mask(h, CCISS_INTR_ON);
  34917. + h->access->set_intr_mask(h, CCISS_INTR_ON);
  34918. /* Get the firmware version */
  34919. inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
  34920. @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
  34921. kfree(flush_buf);
  34922. if (return_code != IO_OK)
  34923. dev_warn(&h->pdev->dev, "Error flushing cache\n");
  34924. - h->access.set_intr_mask(h, CCISS_INTR_OFF);
  34925. + h->access->set_intr_mask(h, CCISS_INTR_OFF);
  34926. free_irq(h->intr[h->intr_mode], h);
  34927. }
  34928. diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
  34929. index 7fda30e..2f27946 100644
  34930. --- a/drivers/block/cciss.h
  34931. +++ b/drivers/block/cciss.h
  34932. @@ -101,7 +101,7 @@ struct ctlr_info
  34933. /* information about each logical volume */
  34934. drive_info_struct *drv[CISS_MAX_LUN];
  34935. - struct access_method access;
  34936. + struct access_method *access;
  34937. /* queue and queue Info */
  34938. struct list_head reqQ;
  34939. @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
  34940. }
  34941. static struct access_method SA5_access = {
  34942. - SA5_submit_command,
  34943. - SA5_intr_mask,
  34944. - SA5_fifo_full,
  34945. - SA5_intr_pending,
  34946. - SA5_completed,
  34947. + .submit_command = SA5_submit_command,
  34948. + .set_intr_mask = SA5_intr_mask,
  34949. + .fifo_full = SA5_fifo_full,
  34950. + .intr_pending = SA5_intr_pending,
  34951. + .command_completed = SA5_completed,
  34952. };
  34953. static struct access_method SA5B_access = {
  34954. - SA5_submit_command,
  34955. - SA5B_intr_mask,
  34956. - SA5_fifo_full,
  34957. - SA5B_intr_pending,
  34958. - SA5_completed,
  34959. + .submit_command = SA5_submit_command,
  34960. + .set_intr_mask = SA5B_intr_mask,
  34961. + .fifo_full = SA5_fifo_full,
  34962. + .intr_pending = SA5B_intr_pending,
  34963. + .command_completed = SA5_completed,
  34964. };
  34965. static struct access_method SA5_performant_access = {
  34966. - SA5_submit_command,
  34967. - SA5_performant_intr_mask,
  34968. - SA5_fifo_full,
  34969. - SA5_performant_intr_pending,
  34970. - SA5_performant_completed,
  34971. + .submit_command = SA5_submit_command,
  34972. + .set_intr_mask = SA5_performant_intr_mask,
  34973. + .fifo_full = SA5_fifo_full,
  34974. + .intr_pending = SA5_performant_intr_pending,
  34975. + .command_completed = SA5_performant_completed,
  34976. };
  34977. struct board_type {
  34978. diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
  34979. index 2b94403..fd6ad1f 100644
  34980. --- a/drivers/block/cpqarray.c
  34981. +++ b/drivers/block/cpqarray.c
  34982. @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
  34983. if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
  34984. goto Enomem4;
  34985. }
  34986. - hba[i]->access.set_intr_mask(hba[i], 0);
  34987. + hba[i]->access->set_intr_mask(hba[i], 0);
  34988. if (request_irq(hba[i]->intr, do_ida_intr,
  34989. IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
  34990. {
  34991. @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
  34992. add_timer(&hba[i]->timer);
  34993. /* Enable IRQ now that spinlock and rate limit timer are set up */
  34994. - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
  34995. + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
  34996. for(j=0; j<NWD; j++) {
  34997. struct gendisk *disk = ida_gendisk[i][j];
  34998. @@ -694,7 +694,7 @@ DBGINFO(
  34999. for(i=0; i<NR_PRODUCTS; i++) {
  35000. if (board_id == products[i].board_id) {
  35001. c->product_name = products[i].product_name;
  35002. - c->access = *(products[i].access);
  35003. + c->access = products[i].access;
  35004. break;
  35005. }
  35006. }
  35007. @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
  35008. hba[ctlr]->intr = intr;
  35009. sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
  35010. hba[ctlr]->product_name = products[j].product_name;
  35011. - hba[ctlr]->access = *(products[j].access);
  35012. + hba[ctlr]->access = products[j].access;
  35013. hba[ctlr]->ctlr = ctlr;
  35014. hba[ctlr]->board_id = board_id;
  35015. hba[ctlr]->pci_dev = NULL; /* not PCI */
  35016. @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
  35017. while((c = h->reqQ) != NULL) {
  35018. /* Can't do anything if we're busy */
  35019. - if (h->access.fifo_full(h) == 0)
  35020. + if (h->access->fifo_full(h) == 0)
  35021. return;
  35022. /* Get the first entry from the request Q */
  35023. @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
  35024. h->Qdepth--;
  35025. /* Tell the controller to do our bidding */
  35026. - h->access.submit_command(h, c);
  35027. + h->access->submit_command(h, c);
  35028. /* Get onto the completion Q */
  35029. addQ(&h->cmpQ, c);
  35030. @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
  35031. unsigned long flags;
  35032. __u32 a,a1;
  35033. - istat = h->access.intr_pending(h);
  35034. + istat = h->access->intr_pending(h);
  35035. /* Is this interrupt for us? */
  35036. if (istat == 0)
  35037. return IRQ_NONE;
  35038. @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
  35039. */
  35040. spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
  35041. if (istat & FIFO_NOT_EMPTY) {
  35042. - while((a = h->access.command_completed(h))) {
  35043. + while((a = h->access->command_completed(h))) {
  35044. a1 = a; a &= ~3;
  35045. if ((c = h->cmpQ) == NULL)
  35046. {
  35047. @@ -1448,11 +1448,11 @@ static int sendcmd(
  35048. /*
  35049. * Disable interrupt
  35050. */
  35051. - info_p->access.set_intr_mask(info_p, 0);
  35052. + info_p->access->set_intr_mask(info_p, 0);
  35053. /* Make sure there is room in the command FIFO */
  35054. /* Actually it should be completely empty at this time. */
  35055. for (i = 200000; i > 0; i--) {
  35056. - temp = info_p->access.fifo_full(info_p);
  35057. + temp = info_p->access->fifo_full(info_p);
  35058. if (temp != 0) {
  35059. break;
  35060. }
  35061. @@ -1465,7 +1465,7 @@ DBG(
  35062. /*
  35063. * Send the cmd
  35064. */
  35065. - info_p->access.submit_command(info_p, c);
  35066. + info_p->access->submit_command(info_p, c);
  35067. complete = pollcomplete(ctlr);
  35068. pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
  35069. @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
  35070. * we check the new geometry. Then turn interrupts back on when
  35071. * we're done.
  35072. */
  35073. - host->access.set_intr_mask(host, 0);
  35074. + host->access->set_intr_mask(host, 0);
  35075. getgeometry(ctlr);
  35076. - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
  35077. + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
  35078. for(i=0; i<NWD; i++) {
  35079. struct gendisk *disk = ida_gendisk[ctlr][i];
  35080. @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
  35081. /* Wait (up to 2 seconds) for a command to complete */
  35082. for (i = 200000; i > 0; i--) {
  35083. - done = hba[ctlr]->access.command_completed(hba[ctlr]);
  35084. + done = hba[ctlr]->access->command_completed(hba[ctlr]);
  35085. if (done == 0) {
  35086. udelay(10); /* a short fixed delay */
  35087. } else
  35088. diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
  35089. index be73e9d..7fbf140 100644
  35090. --- a/drivers/block/cpqarray.h
  35091. +++ b/drivers/block/cpqarray.h
  35092. @@ -99,7 +99,7 @@ struct ctlr_info {
  35093. drv_info_t drv[NWD];
  35094. struct proc_dir_entry *proc;
  35095. - struct access_method access;
  35096. + struct access_method *access;
  35097. cmdlist_t *reqQ;
  35098. cmdlist_t *cmpQ;
  35099. diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
  35100. index 0e06f0c..c47b81d 100644
  35101. --- a/drivers/block/drbd/drbd_int.h
  35102. +++ b/drivers/block/drbd/drbd_int.h
  35103. @@ -582,7 +582,7 @@ struct drbd_epoch {
  35104. struct drbd_tconn *tconn;
  35105. struct list_head list;
  35106. unsigned int barrier_nr;
  35107. - atomic_t epoch_size; /* increased on every request added. */
  35108. + atomic_unchecked_t epoch_size; /* increased on every request added. */
  35109. atomic_t active; /* increased on every req. added, and dec on every finished. */
  35110. unsigned long flags;
  35111. };
  35112. @@ -1022,7 +1022,7 @@ struct drbd_conf {
  35113. unsigned int al_tr_number;
  35114. int al_tr_cycle;
  35115. wait_queue_head_t seq_wait;
  35116. - atomic_t packet_seq;
  35117. + atomic_unchecked_t packet_seq;
  35118. unsigned int peer_seq;
  35119. spinlock_t peer_seq_lock;
  35120. unsigned int minor;
  35121. @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
  35122. char __user *uoptval;
  35123. int err;
  35124. - uoptval = (char __user __force *)optval;
  35125. + uoptval = (char __force_user *)optval;
  35126. set_fs(KERNEL_DS);
  35127. if (level == SOL_SOCKET)
  35128. diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
  35129. index 89c497c..9c736ae 100644
  35130. --- a/drivers/block/drbd/drbd_interval.c
  35131. +++ b/drivers/block/drbd/drbd_interval.c
  35132. @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
  35133. }
  35134. static const struct rb_augment_callbacks augment_callbacks = {
  35135. - augment_propagate,
  35136. - augment_copy,
  35137. - augment_rotate,
  35138. + .propagate = augment_propagate,
  35139. + .copy = augment_copy,
  35140. + .rotate = augment_rotate,
  35141. };
  35142. /**
  35143. diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
  35144. index 929468e..7d934eb 100644
  35145. --- a/drivers/block/drbd/drbd_main.c
  35146. +++ b/drivers/block/drbd/drbd_main.c
  35147. @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
  35148. p->sector = sector;
  35149. p->block_id = block_id;
  35150. p->blksize = blksize;
  35151. - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
  35152. + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
  35153. return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
  35154. }
  35155. @@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
  35156. return -EIO;
  35157. p->sector = cpu_to_be64(req->i.sector);
  35158. p->block_id = (unsigned long)req;
  35159. - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
  35160. + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
  35161. dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
  35162. if (mdev->state.conn >= C_SYNC_SOURCE &&
  35163. mdev->state.conn <= C_PAUSED_SYNC_T)
  35164. @@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
  35165. {
  35166. struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
  35167. - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
  35168. - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
  35169. + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
  35170. + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
  35171. kfree(tconn->current_epoch);
  35172. idr_destroy(&tconn->volumes);
  35173. diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
  35174. index c706d50..5e1b472 100644
  35175. --- a/drivers/block/drbd/drbd_nl.c
  35176. +++ b/drivers/block/drbd/drbd_nl.c
  35177. @@ -3440,7 +3440,7 @@ out:
  35178. void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
  35179. {
  35180. - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
  35181. + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
  35182. struct sk_buff *msg;
  35183. struct drbd_genlmsghdr *d_out;
  35184. unsigned seq;
  35185. @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
  35186. return;
  35187. }
  35188. - seq = atomic_inc_return(&drbd_genl_seq);
  35189. + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
  35190. msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
  35191. if (!msg)
  35192. goto failed;
  35193. diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
  35194. index d073305..4998fea 100644
  35195. --- a/drivers/block/drbd/drbd_receiver.c
  35196. +++ b/drivers/block/drbd/drbd_receiver.c
  35197. @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
  35198. {
  35199. int err;
  35200. - atomic_set(&mdev->packet_seq, 0);
  35201. + atomic_set_unchecked(&mdev->packet_seq, 0);
  35202. mdev->peer_seq = 0;
  35203. mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
  35204. @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
  35205. do {
  35206. next_epoch = NULL;
  35207. - epoch_size = atomic_read(&epoch->epoch_size);
  35208. + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
  35209. switch (ev & ~EV_CLEANUP) {
  35210. case EV_PUT:
  35211. @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
  35212. rv = FE_DESTROYED;
  35213. } else {
  35214. epoch->flags = 0;
  35215. - atomic_set(&epoch->epoch_size, 0);
  35216. + atomic_set_unchecked(&epoch->epoch_size, 0);
  35217. /* atomic_set(&epoch->active, 0); is already zero */
  35218. if (rv == FE_STILL_LIVE)
  35219. rv = FE_RECYCLED;
  35220. @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
  35221. conn_wait_active_ee_empty(tconn);
  35222. drbd_flush(tconn);
  35223. - if (atomic_read(&tconn->current_epoch->epoch_size)) {
  35224. + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
  35225. epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
  35226. if (epoch)
  35227. break;
  35228. @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
  35229. }
  35230. epoch->flags = 0;
  35231. - atomic_set(&epoch->epoch_size, 0);
  35232. + atomic_set_unchecked(&epoch->epoch_size, 0);
  35233. atomic_set(&epoch->active, 0);
  35234. spin_lock(&tconn->epoch_lock);
  35235. - if (atomic_read(&tconn->current_epoch->epoch_size)) {
  35236. + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
  35237. list_add(&epoch->list, &tconn->current_epoch->list);
  35238. tconn->current_epoch = epoch;
  35239. tconn->epochs++;
  35240. @@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
  35241. err = wait_for_and_update_peer_seq(mdev, peer_seq);
  35242. drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
  35243. - atomic_inc(&tconn->current_epoch->epoch_size);
  35244. + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
  35245. err2 = drbd_drain_block(mdev, pi->size);
  35246. if (!err)
  35247. err = err2;
  35248. @@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
  35249. spin_lock(&tconn->epoch_lock);
  35250. peer_req->epoch = tconn->current_epoch;
  35251. - atomic_inc(&peer_req->epoch->epoch_size);
  35252. + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
  35253. atomic_inc(&peer_req->epoch->active);
  35254. spin_unlock(&tconn->epoch_lock);
  35255. @@ -4345,7 +4345,7 @@ struct data_cmd {
  35256. int expect_payload;
  35257. size_t pkt_size;
  35258. int (*fn)(struct drbd_tconn *, struct packet_info *);
  35259. -};
  35260. +} __do_const;
  35261. static struct data_cmd drbd_cmd_handler[] = {
  35262. [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
  35263. @@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
  35264. if (!list_empty(&tconn->current_epoch->list))
  35265. conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
  35266. /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
  35267. - atomic_set(&tconn->current_epoch->epoch_size, 0);
  35268. + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
  35269. tconn->send.seen_any_write_yet = false;
  35270. conn_info(tconn, "Connection closed\n");
  35271. @@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
  35272. struct asender_cmd {
  35273. size_t pkt_size;
  35274. int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
  35275. -};
  35276. +} __do_const;
  35277. static struct asender_cmd asender_tbl[] = {
  35278. [P_PING] = { 0, got_Ping },
  35279. diff --git a/drivers/block/loop.c b/drivers/block/loop.c
  35280. index 66e8c3b..9b68dd9 100644
  35281. --- a/drivers/block/loop.c
  35282. +++ b/drivers/block/loop.c
  35283. @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
  35284. file_start_write(file);
  35285. set_fs(get_ds());
  35286. - bw = file->f_op->write(file, buf, len, &pos);
  35287. + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
  35288. set_fs(old_fs);
  35289. file_end_write(file);
  35290. if (likely(bw == len))
  35291. diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
  35292. index 091b9ea..f5428f8 100644
  35293. --- a/drivers/block/null_blk.c
  35294. +++ b/drivers/block/null_blk.c
  35295. @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
  35296. return 0;
  35297. }
  35298. -static struct blk_mq_ops null_mq_ops = {
  35299. - .queue_rq = null_queue_rq,
  35300. - .map_queue = blk_mq_map_queue,
  35301. +static struct blk_mq_ops null_mq_single_ops = {
  35302. + .queue_rq = null_queue_rq,
  35303. + .map_queue = blk_mq_map_queue,
  35304. .init_hctx = null_init_hctx,
  35305. .complete = null_softirq_done_fn,
  35306. + .alloc_hctx = blk_mq_alloc_single_hw_queue,
  35307. + .free_hctx = blk_mq_free_single_hw_queue,
  35308. +};
  35309. +
  35310. +static struct blk_mq_ops null_mq_per_node_ops = {
  35311. + .queue_rq = null_queue_rq,
  35312. + .map_queue = blk_mq_map_queue,
  35313. + .init_hctx = null_init_hctx,
  35314. + .alloc_hctx = null_alloc_hctx,
  35315. + .free_hctx = null_free_hctx,
  35316. };
  35317. static struct blk_mq_reg null_mq_reg = {
  35318. - .ops = &null_mq_ops,
  35319. + .ops = &null_mq_single_ops,
  35320. .queue_depth = 64,
  35321. .cmd_size = sizeof(struct nullb_cmd),
  35322. .flags = BLK_MQ_F_SHOULD_MERGE,
  35323. @@ -521,13 +531,8 @@ static int null_add_dev(void)
  35324. null_mq_reg.queue_depth = hw_queue_depth;
  35325. null_mq_reg.nr_hw_queues = submit_queues;
  35326. - if (use_per_node_hctx) {
  35327. - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
  35328. - null_mq_reg.ops->free_hctx = null_free_hctx;
  35329. - } else {
  35330. - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
  35331. - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
  35332. - }
  35333. + if (use_per_node_hctx)
  35334. + null_mq_reg.ops = &null_mq_per_node_ops;
  35335. nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
  35336. } else if (queue_mode == NULL_Q_BIO) {
  35337. diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
  35338. index a2af73d..c0b8f61 100644
  35339. --- a/drivers/block/pktcdvd.c
  35340. +++ b/drivers/block/pktcdvd.c
  35341. @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
  35342. static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
  35343. {
  35344. - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
  35345. + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
  35346. }
  35347. /*
  35348. @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
  35349. return -EROFS;
  35350. }
  35351. pd->settings.fp = ti.fp;
  35352. - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
  35353. + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
  35354. if (ti.nwa_v) {
  35355. pd->nwa = be32_to_cpu(ti.next_writable);
  35356. diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
  35357. index e5565fb..71be10b4 100644
  35358. --- a/drivers/block/smart1,2.h
  35359. +++ b/drivers/block/smart1,2.h
  35360. @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
  35361. }
  35362. static struct access_method smart4_access = {
  35363. - smart4_submit_command,
  35364. - smart4_intr_mask,
  35365. - smart4_fifo_full,
  35366. - smart4_intr_pending,
  35367. - smart4_completed,
  35368. + .submit_command = smart4_submit_command,
  35369. + .set_intr_mask = smart4_intr_mask,
  35370. + .fifo_full = smart4_fifo_full,
  35371. + .intr_pending = smart4_intr_pending,
  35372. + .command_completed = smart4_completed,
  35373. };
  35374. /*
  35375. @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
  35376. }
  35377. static struct access_method smart2_access = {
  35378. - smart2_submit_command,
  35379. - smart2_intr_mask,
  35380. - smart2_fifo_full,
  35381. - smart2_intr_pending,
  35382. - smart2_completed,
  35383. + .submit_command = smart2_submit_command,
  35384. + .set_intr_mask = smart2_intr_mask,
  35385. + .fifo_full = smart2_fifo_full,
  35386. + .intr_pending = smart2_intr_pending,
  35387. + .command_completed = smart2_completed,
  35388. };
  35389. /*
  35390. @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
  35391. }
  35392. static struct access_method smart2e_access = {
  35393. - smart2e_submit_command,
  35394. - smart2e_intr_mask,
  35395. - smart2e_fifo_full,
  35396. - smart2e_intr_pending,
  35397. - smart2e_completed,
  35398. + .submit_command = smart2e_submit_command,
  35399. + .set_intr_mask = smart2e_intr_mask,
  35400. + .fifo_full = smart2e_fifo_full,
  35401. + .intr_pending = smart2e_intr_pending,
  35402. + .command_completed = smart2e_completed,
  35403. };
  35404. /*
  35405. @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
  35406. }
  35407. static struct access_method smart1_access = {
  35408. - smart1_submit_command,
  35409. - smart1_intr_mask,
  35410. - smart1_fifo_full,
  35411. - smart1_intr_pending,
  35412. - smart1_completed,
  35413. + .submit_command = smart1_submit_command,
  35414. + .set_intr_mask = smart1_intr_mask,
  35415. + .fifo_full = smart1_fifo_full,
  35416. + .intr_pending = smart1_intr_pending,
  35417. + .command_completed = smart1_completed,
  35418. };
  35419. diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
  35420. index f038dba..bb74c08 100644
  35421. --- a/drivers/bluetooth/btwilink.c
  35422. +++ b/drivers/bluetooth/btwilink.c
  35423. @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
  35424. static int bt_ti_probe(struct platform_device *pdev)
  35425. {
  35426. - static struct ti_st *hst;
  35427. + struct ti_st *hst;
  35428. struct hci_dev *hdev;
  35429. int err;
  35430. diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
  35431. index 8a3aff7..d7538c2 100644
  35432. --- a/drivers/cdrom/cdrom.c
  35433. +++ b/drivers/cdrom/cdrom.c
  35434. @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
  35435. ENSURE(reset, CDC_RESET);
  35436. ENSURE(generic_packet, CDC_GENERIC_PACKET);
  35437. cdi->mc_flags = 0;
  35438. - cdo->n_minors = 0;
  35439. cdi->options = CDO_USE_FFLAGS;
  35440. if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
  35441. @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
  35442. else
  35443. cdi->cdda_method = CDDA_OLD;
  35444. - if (!cdo->generic_packet)
  35445. - cdo->generic_packet = cdrom_dummy_generic_packet;
  35446. + if (!cdo->generic_packet) {
  35447. + pax_open_kernel();
  35448. + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
  35449. + pax_close_kernel();
  35450. + }
  35451. cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
  35452. mutex_lock(&cdrom_mutex);
  35453. @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
  35454. if (cdi->exit)
  35455. cdi->exit(cdi);
  35456. - cdi->ops->n_minors--;
  35457. cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
  35458. }
  35459. @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
  35460. */
  35461. nr = nframes;
  35462. do {
  35463. - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
  35464. + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
  35465. if (cgc.buffer)
  35466. break;
  35467. @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
  35468. struct cdrom_device_info *cdi;
  35469. int ret;
  35470. - ret = scnprintf(info + *pos, max_size - *pos, header);
  35471. + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
  35472. if (!ret)
  35473. return 1;
  35474. diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
  35475. index 51e75ad..39c4c76 100644
  35476. --- a/drivers/cdrom/gdrom.c
  35477. +++ b/drivers/cdrom/gdrom.c
  35478. @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
  35479. .audio_ioctl = gdrom_audio_ioctl,
  35480. .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
  35481. CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
  35482. - .n_minors = 1,
  35483. };
  35484. static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
  35485. diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
  35486. index 1386749..5430258 100644
  35487. --- a/drivers/char/Kconfig
  35488. +++ b/drivers/char/Kconfig
  35489. @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
  35490. config DEVKMEM
  35491. bool "/dev/kmem virtual device support"
  35492. - default y
  35493. + default n
  35494. + depends on !GRKERNSEC_KMEM
  35495. help
  35496. Say Y here if you want to support the /dev/kmem device. The
  35497. /dev/kmem device is rarely used, but can be used for certain
  35498. @@ -577,6 +578,7 @@ config DEVPORT
  35499. bool
  35500. depends on !M68K
  35501. depends on ISA || PCI
  35502. + depends on !GRKERNSEC_KMEM
  35503. default y
  35504. source "drivers/s390/char/Kconfig"
  35505. diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
  35506. index a48e05b..6bac831 100644
  35507. --- a/drivers/char/agp/compat_ioctl.c
  35508. +++ b/drivers/char/agp/compat_ioctl.c
  35509. @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
  35510. return -ENOMEM;
  35511. }
  35512. - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
  35513. + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
  35514. sizeof(*usegment) * ureserve.seg_count)) {
  35515. kfree(usegment);
  35516. kfree(ksegment);
  35517. diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
  35518. index 1b19239..963967b 100644
  35519. --- a/drivers/char/agp/frontend.c
  35520. +++ b/drivers/char/agp/frontend.c
  35521. @@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
  35522. agp_copy_info(agp_bridge, &kerninfo);
  35523. + memset(&userinfo, 0, sizeof(userinfo));
  35524. userinfo.version.major = kerninfo.version.major;
  35525. userinfo.version.minor = kerninfo.version.minor;
  35526. userinfo.bridge_id = kerninfo.device->vendor |
  35527. @@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
  35528. if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
  35529. return -EFAULT;
  35530. - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
  35531. + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
  35532. return -EFAULT;
  35533. client = agp_find_client_by_pid(reserve.pid);
  35534. @@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
  35535. if (segment == NULL)
  35536. return -ENOMEM;
  35537. - if (copy_from_user(segment, (void __user *) reserve.seg_list,
  35538. + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
  35539. sizeof(struct agp_segment) * reserve.seg_count)) {
  35540. kfree(segment);
  35541. return -EFAULT;
  35542. diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
  35543. index 4f94375..413694e 100644
  35544. --- a/drivers/char/genrtc.c
  35545. +++ b/drivers/char/genrtc.c
  35546. @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
  35547. switch (cmd) {
  35548. case RTC_PLL_GET:
  35549. + memset(&pll, 0, sizeof(pll));
  35550. if (get_rtc_pll(&pll))
  35551. return -EINVAL;
  35552. else
  35553. diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
  35554. index d5d4cd8..22d561d 100644
  35555. --- a/drivers/char/hpet.c
  35556. +++ b/drivers/char/hpet.c
  35557. @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
  35558. }
  35559. static int
  35560. -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
  35561. +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
  35562. struct hpet_info *info)
  35563. {
  35564. struct hpet_timer __iomem *timer;
  35565. diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
  35566. index 86fe45c..c0ea948 100644
  35567. --- a/drivers/char/hw_random/intel-rng.c
  35568. +++ b/drivers/char/hw_random/intel-rng.c
  35569. @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
  35570. if (no_fwh_detect)
  35571. return -ENODEV;
  35572. - printk(warning);
  35573. + printk("%s", warning);
  35574. return -EBUSY;
  35575. }
  35576. diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
  35577. index ec4e10f..f2a763b 100644
  35578. --- a/drivers/char/ipmi/ipmi_msghandler.c
  35579. +++ b/drivers/char/ipmi/ipmi_msghandler.c
  35580. @@ -420,7 +420,7 @@ struct ipmi_smi {
  35581. struct proc_dir_entry *proc_dir;
  35582. char proc_dir_name[10];
  35583. - atomic_t stats[IPMI_NUM_STATS];
  35584. + atomic_unchecked_t stats[IPMI_NUM_STATS];
  35585. /*
  35586. * run_to_completion duplicate of smb_info, smi_info
  35587. @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
  35588. #define ipmi_inc_stat(intf, stat) \
  35589. - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
  35590. + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
  35591. #define ipmi_get_stat(intf, stat) \
  35592. - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
  35593. + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
  35594. static int is_lan_addr(struct ipmi_addr *addr)
  35595. {
  35596. @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
  35597. INIT_LIST_HEAD(&intf->cmd_rcvrs);
  35598. init_waitqueue_head(&intf->waitq);
  35599. for (i = 0; i < IPMI_NUM_STATS; i++)
  35600. - atomic_set(&intf->stats[i], 0);
  35601. + atomic_set_unchecked(&intf->stats[i], 0);
  35602. intf->proc_dir = NULL;
  35603. diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
  35604. index 03f4189..e79f5e0 100644
  35605. --- a/drivers/char/ipmi/ipmi_si_intf.c
  35606. +++ b/drivers/char/ipmi/ipmi_si_intf.c
  35607. @@ -280,7 +280,7 @@ struct smi_info {
  35608. unsigned char slave_addr;
  35609. /* Counters and things for the proc filesystem. */
  35610. - atomic_t stats[SI_NUM_STATS];
  35611. + atomic_unchecked_t stats[SI_NUM_STATS];
  35612. struct task_struct *thread;
  35613. @@ -289,9 +289,9 @@ struct smi_info {
  35614. };
  35615. #define smi_inc_stat(smi, stat) \
  35616. - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
  35617. + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
  35618. #define smi_get_stat(smi, stat) \
  35619. - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
  35620. + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
  35621. #define SI_MAX_PARMS 4
  35622. @@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
  35623. atomic_set(&new_smi->req_events, 0);
  35624. new_smi->run_to_completion = 0;
  35625. for (i = 0; i < SI_NUM_STATS; i++)
  35626. - atomic_set(&new_smi->stats[i], 0);
  35627. + atomic_set_unchecked(&new_smi->stats[i], 0);
  35628. new_smi->interrupt_disabled = 1;
  35629. atomic_set(&new_smi->stop_operation, 0);
  35630. diff --git a/drivers/char/mem.c b/drivers/char/mem.c
  35631. index 92c5937..1be4e4d 100644
  35632. --- a/drivers/char/mem.c
  35633. +++ b/drivers/char/mem.c
  35634. @@ -18,6 +18,7 @@
  35635. #include <linux/raw.h>
  35636. #include <linux/tty.h>
  35637. #include <linux/capability.h>
  35638. +#include <linux/security.h>
  35639. #include <linux/ptrace.h>
  35640. #include <linux/device.h>
  35641. #include <linux/highmem.h>
  35642. @@ -36,6 +37,10 @@
  35643. #define DEVPORT_MINOR 4
  35644. +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
  35645. +extern const struct file_operations grsec_fops;
  35646. +#endif
  35647. +
  35648. static inline unsigned long size_inside_page(unsigned long start,
  35649. unsigned long size)
  35650. {
  35651. @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
  35652. while (cursor < to) {
  35653. if (!devmem_is_allowed(pfn)) {
  35654. +#ifdef CONFIG_GRKERNSEC_KMEM
  35655. + gr_handle_mem_readwrite(from, to);
  35656. +#else
  35657. printk(KERN_INFO
  35658. "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
  35659. current->comm, from, to);
  35660. +#endif
  35661. return 0;
  35662. }
  35663. cursor += PAGE_SIZE;
  35664. @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
  35665. }
  35666. return 1;
  35667. }
  35668. +#elif defined(CONFIG_GRKERNSEC_KMEM)
  35669. +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
  35670. +{
  35671. + return 0;
  35672. +}
  35673. #else
  35674. static inline int range_is_allowed(unsigned long pfn, unsigned long size)
  35675. {
  35676. @@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
  35677. while (count > 0) {
  35678. unsigned long remaining;
  35679. + char *temp;
  35680. sz = size_inside_page(p, count);
  35681. @@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
  35682. if (!ptr)
  35683. return -EFAULT;
  35684. - remaining = copy_to_user(buf, ptr, sz);
  35685. +#ifdef CONFIG_PAX_USERCOPY
  35686. + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
  35687. + if (!temp) {
  35688. + unxlate_dev_mem_ptr(p, ptr);
  35689. + return -ENOMEM;
  35690. + }
  35691. + memcpy(temp, ptr, sz);
  35692. +#else
  35693. + temp = ptr;
  35694. +#endif
  35695. +
  35696. + remaining = copy_to_user(buf, temp, sz);
  35697. +
  35698. +#ifdef CONFIG_PAX_USERCOPY
  35699. + kfree(temp);
  35700. +#endif
  35701. +
  35702. unxlate_dev_mem_ptr(p, ptr);
  35703. if (remaining)
  35704. return -EFAULT;
  35705. @@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
  35706. size_t count, loff_t *ppos)
  35707. {
  35708. unsigned long p = *ppos;
  35709. - ssize_t low_count, read, sz;
  35710. + ssize_t low_count, read, sz, err = 0;
  35711. char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
  35712. - int err = 0;
  35713. read = 0;
  35714. if (p < (unsigned long) high_memory) {
  35715. @@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
  35716. }
  35717. #endif
  35718. while (low_count > 0) {
  35719. + char *temp;
  35720. +
  35721. sz = size_inside_page(p, low_count);
  35722. /*
  35723. @@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
  35724. */
  35725. kbuf = xlate_dev_kmem_ptr((char *)p);
  35726. - if (copy_to_user(buf, kbuf, sz))
  35727. +#ifdef CONFIG_PAX_USERCOPY
  35728. + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
  35729. + if (!temp)
  35730. + return -ENOMEM;
  35731. + memcpy(temp, kbuf, sz);
  35732. +#else
  35733. + temp = kbuf;
  35734. +#endif
  35735. +
  35736. + err = copy_to_user(buf, temp, sz);
  35737. +
  35738. +#ifdef CONFIG_PAX_USERCOPY
  35739. + kfree(temp);
  35740. +#endif
  35741. +
  35742. + if (err)
  35743. return -EFAULT;
  35744. buf += sz;
  35745. p += sz;
  35746. @@ -821,6 +868,9 @@ static const struct memdev {
  35747. #ifdef CONFIG_PRINTK
  35748. [11] = { "kmsg", 0644, &kmsg_fops, NULL },
  35749. #endif
  35750. +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
  35751. + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
  35752. +#endif
  35753. };
  35754. static int memory_open(struct inode *inode, struct file *filp)
  35755. @@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
  35756. continue;
  35757. device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
  35758. - NULL, devlist[minor].name);
  35759. + NULL, "%s", devlist[minor].name);
  35760. }
  35761. return tty_init();
  35762. diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
  35763. index 9df78e2..01ba9ae 100644
  35764. --- a/drivers/char/nvram.c
  35765. +++ b/drivers/char/nvram.c
  35766. @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
  35767. spin_unlock_irq(&rtc_lock);
  35768. - if (copy_to_user(buf, contents, tmp - contents))
  35769. + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
  35770. return -EFAULT;
  35771. *ppos = i;
  35772. diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
  35773. index 8320abd..ec48108 100644
  35774. --- a/drivers/char/pcmcia/synclink_cs.c
  35775. +++ b/drivers/char/pcmcia/synclink_cs.c
  35776. @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
  35777. if (debug_level >= DEBUG_LEVEL_INFO)
  35778. printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
  35779. - __FILE__, __LINE__, info->device_name, port->count);
  35780. + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
  35781. - WARN_ON(!port->count);
  35782. + WARN_ON(!atomic_read(&port->count));
  35783. if (tty_port_close_start(port, tty, filp) == 0)
  35784. goto cleanup;
  35785. @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
  35786. cleanup:
  35787. if (debug_level >= DEBUG_LEVEL_INFO)
  35788. printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
  35789. - tty->driver->name, port->count);
  35790. + tty->driver->name, atomic_read(&port->count));
  35791. }
  35792. /* Wait until the transmitter is empty.
  35793. @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
  35794. if (debug_level >= DEBUG_LEVEL_INFO)
  35795. printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
  35796. - __FILE__, __LINE__, tty->driver->name, port->count);
  35797. + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
  35798. /* If port is closing, signal caller to try again */
  35799. if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
  35800. @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
  35801. goto cleanup;
  35802. }
  35803. spin_lock(&port->lock);
  35804. - port->count++;
  35805. + atomic_inc(&port->count);
  35806. spin_unlock(&port->lock);
  35807. spin_unlock_irqrestore(&info->netlock, flags);
  35808. - if (port->count == 1) {
  35809. + if (atomic_read(&port->count) == 1) {
  35810. /* 1st open on this device, init hardware */
  35811. retval = startup(info, tty);
  35812. if (retval < 0)
  35813. @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  35814. unsigned short new_crctype;
  35815. /* return error if TTY interface open */
  35816. - if (info->port.count)
  35817. + if (atomic_read(&info->port.count))
  35818. return -EBUSY;
  35819. switch (encoding)
  35820. @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
  35821. /* arbitrate between network and tty opens */
  35822. spin_lock_irqsave(&info->netlock, flags);
  35823. - if (info->port.count != 0 || info->netcount != 0) {
  35824. + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
  35825. printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
  35826. spin_unlock_irqrestore(&info->netlock, flags);
  35827. return -EBUSY;
  35828. @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  35829. printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
  35830. /* return error if TTY interface open */
  35831. - if (info->port.count)
  35832. + if (atomic_read(&info->port.count))
  35833. return -EBUSY;
  35834. if (cmd != SIOCWANDEV)
  35835. diff --git a/drivers/char/random.c b/drivers/char/random.c
  35836. index 429b75b..a7f4145 100644
  35837. --- a/drivers/char/random.c
  35838. +++ b/drivers/char/random.c
  35839. @@ -270,10 +270,17 @@
  35840. /*
  35841. * Configuration information
  35842. */
  35843. +#ifdef CONFIG_GRKERNSEC_RANDNET
  35844. +#define INPUT_POOL_SHIFT 14
  35845. +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
  35846. +#define OUTPUT_POOL_SHIFT 12
  35847. +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
  35848. +#else
  35849. #define INPUT_POOL_SHIFT 12
  35850. #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
  35851. #define OUTPUT_POOL_SHIFT 10
  35852. #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
  35853. +#endif
  35854. #define SEC_XFER_SIZE 512
  35855. #define EXTRACT_SIZE 10
  35856. @@ -284,9 +291,6 @@
  35857. /*
  35858. * To allow fractional bits to be tracked, the entropy_count field is
  35859. * denominated in units of 1/8th bits.
  35860. - *
  35861. - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
  35862. - * credit_entropy_bits() needs to be 64 bits wide.
  35863. */
  35864. #define ENTROPY_SHIFT 3
  35865. #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
  35866. @@ -361,12 +365,19 @@ static struct poolinfo {
  35867. #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
  35868. int tap1, tap2, tap3, tap4, tap5;
  35869. } poolinfo_table[] = {
  35870. +#ifdef CONFIG_GRKERNSEC_RANDNET
  35871. + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
  35872. + { S(512), 411, 308, 208, 104, 1 },
  35873. + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
  35874. + { S(128), 104, 76, 51, 25, 1 },
  35875. +#else
  35876. /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
  35877. /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
  35878. { S(128), 104, 76, 51, 25, 1 },
  35879. /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
  35880. /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
  35881. { S(32), 26, 19, 14, 7, 1 },
  35882. +#endif
  35883. #if 0
  35884. /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
  35885. { S(2048), 1638, 1231, 819, 411, 1 },
  35886. @@ -433,9 +444,9 @@ struct entropy_store {
  35887. };
  35888. static void push_to_pool(struct work_struct *work);
  35889. -static __u32 input_pool_data[INPUT_POOL_WORDS];
  35890. -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
  35891. -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
  35892. +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
  35893. +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
  35894. +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
  35895. static struct entropy_store input_pool = {
  35896. .poolinfo = &poolinfo_table[0],
  35897. @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
  35898. input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
  35899. }
  35900. - ACCESS_ONCE(r->input_rotate) = input_rotate;
  35901. - ACCESS_ONCE(r->add_ptr) = i;
  35902. + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
  35903. + ACCESS_ONCE_RW(r->add_ptr) = i;
  35904. smp_wmb();
  35905. if (out)
  35906. @@ -632,7 +643,7 @@ retry:
  35907. /* The +2 corresponds to the /4 in the denominator */
  35908. do {
  35909. - unsigned int anfrac = min(pnfrac, pool_size/2);
  35910. + u64 anfrac = min(pnfrac, pool_size/2);
  35911. unsigned int add =
  35912. ((pool_size - entropy_count)*anfrac*3) >> s;
  35913. @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
  35914. extract_buf(r, tmp);
  35915. i = min_t(int, nbytes, EXTRACT_SIZE);
  35916. - if (copy_to_user(buf, tmp, i)) {
  35917. + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
  35918. ret = -EFAULT;
  35919. break;
  35920. }
  35921. @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
  35922. #include <linux/sysctl.h>
  35923. static int min_read_thresh = 8, min_write_thresh;
  35924. -static int max_read_thresh = INPUT_POOL_WORDS * 32;
  35925. +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
  35926. static int max_write_thresh = INPUT_POOL_WORDS * 32;
  35927. static char sysctl_bootid[16];
  35928. @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
  35929. static int proc_do_uuid(struct ctl_table *table, int write,
  35930. void __user *buffer, size_t *lenp, loff_t *ppos)
  35931. {
  35932. - struct ctl_table fake_table;
  35933. + ctl_table_no_const fake_table;
  35934. unsigned char buf[64], tmp_uuid[16], *uuid;
  35935. uuid = table->data;
  35936. @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
  35937. static int proc_do_entropy(ctl_table *table, int write,
  35938. void __user *buffer, size_t *lenp, loff_t *ppos)
  35939. {
  35940. - ctl_table fake_table;
  35941. + ctl_table_no_const fake_table;
  35942. int entropy_count;
  35943. entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
  35944. diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
  35945. index 7cc1fe22..b602d6b 100644
  35946. --- a/drivers/char/sonypi.c
  35947. +++ b/drivers/char/sonypi.c
  35948. @@ -54,6 +54,7 @@
  35949. #include <asm/uaccess.h>
  35950. #include <asm/io.h>
  35951. +#include <asm/local.h>
  35952. #include <linux/sonypi.h>
  35953. @@ -490,7 +491,7 @@ static struct sonypi_device {
  35954. spinlock_t fifo_lock;
  35955. wait_queue_head_t fifo_proc_list;
  35956. struct fasync_struct *fifo_async;
  35957. - int open_count;
  35958. + local_t open_count;
  35959. int model;
  35960. struct input_dev *input_jog_dev;
  35961. struct input_dev *input_key_dev;
  35962. @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
  35963. static int sonypi_misc_release(struct inode *inode, struct file *file)
  35964. {
  35965. mutex_lock(&sonypi_device.lock);
  35966. - sonypi_device.open_count--;
  35967. + local_dec(&sonypi_device.open_count);
  35968. mutex_unlock(&sonypi_device.lock);
  35969. return 0;
  35970. }
  35971. @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
  35972. {
  35973. mutex_lock(&sonypi_device.lock);
  35974. /* Flush input queue on first open */
  35975. - if (!sonypi_device.open_count)
  35976. + if (!local_read(&sonypi_device.open_count))
  35977. kfifo_reset(&sonypi_device.fifo);
  35978. - sonypi_device.open_count++;
  35979. + local_inc(&sonypi_device.open_count);
  35980. mutex_unlock(&sonypi_device.lock);
  35981. return 0;
  35982. diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
  35983. index b9a57fa..5bb9e38 100644
  35984. --- a/drivers/char/tpm/tpm_acpi.c
  35985. +++ b/drivers/char/tpm/tpm_acpi.c
  35986. @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
  35987. virt = acpi_os_map_memory(start, len);
  35988. if (!virt) {
  35989. kfree(log->bios_event_log);
  35990. + log->bios_event_log = NULL;
  35991. printk("%s: ERROR - Unable to map memory\n", __func__);
  35992. return -EIO;
  35993. }
  35994. - memcpy_fromio(log->bios_event_log, virt, len);
  35995. + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
  35996. acpi_os_unmap_memory(virt, len);
  35997. return 0;
  35998. diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
  35999. index 59f7cb2..bac8b6d 100644
  36000. --- a/drivers/char/tpm/tpm_eventlog.c
  36001. +++ b/drivers/char/tpm/tpm_eventlog.c
  36002. @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
  36003. event = addr;
  36004. if ((event->event_type == 0 && event->event_size == 0) ||
  36005. - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
  36006. + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
  36007. return NULL;
  36008. return addr;
  36009. @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
  36010. return NULL;
  36011. if ((event->event_type == 0 && event->event_size == 0) ||
  36012. - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
  36013. + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
  36014. return NULL;
  36015. (*pos)++;
  36016. @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
  36017. int i;
  36018. for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
  36019. - seq_putc(m, data[i]);
  36020. + if (!seq_putc(m, data[i]))
  36021. + return -EFAULT;
  36022. return 0;
  36023. }
  36024. diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
  36025. index 6928d09..ff6abe8 100644
  36026. --- a/drivers/char/virtio_console.c
  36027. +++ b/drivers/char/virtio_console.c
  36028. @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
  36029. if (to_user) {
  36030. ssize_t ret;
  36031. - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
  36032. + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
  36033. if (ret)
  36034. return -EFAULT;
  36035. } else {
  36036. @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
  36037. if (!port_has_data(port) && !port->host_connected)
  36038. return 0;
  36039. - return fill_readbuf(port, ubuf, count, true);
  36040. + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
  36041. }
  36042. static int wait_port_writable(struct port *port, bool nonblock)
  36043. diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
  36044. index 57a078e..c17cde8 100644
  36045. --- a/drivers/clk/clk-composite.c
  36046. +++ b/drivers/clk/clk-composite.c
  36047. @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
  36048. struct clk *clk;
  36049. struct clk_init_data init;
  36050. struct clk_composite *composite;
  36051. - struct clk_ops *clk_composite_ops;
  36052. + clk_ops_no_const *clk_composite_ops;
  36053. composite = kzalloc(sizeof(*composite), GFP_KERNEL);
  36054. if (!composite) {
  36055. diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
  36056. index 5983a26..65d5f46 100644
  36057. --- a/drivers/clk/socfpga/clk.c
  36058. +++ b/drivers/clk/socfpga/clk.c
  36059. @@ -22,6 +22,7 @@
  36060. #include <linux/clk-provider.h>
  36061. #include <linux/io.h>
  36062. #include <linux/of.h>
  36063. +#include <asm/pgtable.h>
  36064. /* Clock Manager offsets */
  36065. #define CLKMGR_CTRL 0x0
  36066. @@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
  36067. streq(clk_name, "periph_pll") ||
  36068. streq(clk_name, "sdram_pll")) {
  36069. socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
  36070. - clk_pll_ops.enable = clk_gate_ops.enable;
  36071. - clk_pll_ops.disable = clk_gate_ops.disable;
  36072. + pax_open_kernel();
  36073. + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
  36074. + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
  36075. + pax_close_kernel();
  36076. }
  36077. clk = clk_register(NULL, &socfpga_clk->hw.hw);
  36078. @@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
  36079. return parent_rate / div;
  36080. }
  36081. -static struct clk_ops gateclk_ops = {
  36082. +static clk_ops_no_const gateclk_ops __read_only = {
  36083. .recalc_rate = socfpga_clk_recalc_rate,
  36084. .get_parent = socfpga_clk_get_parent,
  36085. .set_parent = socfpga_clk_set_parent,
  36086. diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
  36087. index 18448a7..d5fad43 100644
  36088. --- a/drivers/cpufreq/acpi-cpufreq.c
  36089. +++ b/drivers/cpufreq/acpi-cpufreq.c
  36090. @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
  36091. data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
  36092. per_cpu(acfreq_data, cpu) = data;
  36093. - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
  36094. - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
  36095. + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
  36096. + pax_open_kernel();
  36097. + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
  36098. + pax_close_kernel();
  36099. + }
  36100. result = acpi_processor_register_performance(data->acpi_data, cpu);
  36101. if (result)
  36102. @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
  36103. policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
  36104. break;
  36105. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  36106. - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
  36107. + pax_open_kernel();
  36108. + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
  36109. + pax_close_kernel();
  36110. break;
  36111. default:
  36112. break;
  36113. @@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
  36114. if (!msrs)
  36115. return;
  36116. - acpi_cpufreq_driver.boost_supported = true;
  36117. - acpi_cpufreq_driver.boost_enabled = boost_state(0);
  36118. + pax_open_kernel();
  36119. + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
  36120. + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
  36121. + pax_close_kernel();
  36122. get_online_cpus();
  36123. /* Force all MSRs to the same value */
  36124. diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
  36125. index 199b52b..e3503bb 100644
  36126. --- a/drivers/cpufreq/cpufreq.c
  36127. +++ b/drivers/cpufreq/cpufreq.c
  36128. @@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
  36129. #endif
  36130. mutex_lock(&cpufreq_governor_mutex);
  36131. - list_del(&governor->governor_list);
  36132. + pax_list_del(&governor->governor_list);
  36133. mutex_unlock(&cpufreq_governor_mutex);
  36134. return;
  36135. }
  36136. @@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
  36137. return NOTIFY_OK;
  36138. }
  36139. -static struct notifier_block __refdata cpufreq_cpu_notifier = {
  36140. +static struct notifier_block cpufreq_cpu_notifier = {
  36141. .notifier_call = cpufreq_cpu_callback,
  36142. };
  36143. @@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
  36144. return 0;
  36145. write_lock_irqsave(&cpufreq_driver_lock, flags);
  36146. - cpufreq_driver->boost_enabled = state;
  36147. + pax_open_kernel();
  36148. + *(bool *)&cpufreq_driver->boost_enabled = state;
  36149. + pax_close_kernel();
  36150. write_unlock_irqrestore(&cpufreq_driver_lock, flags);
  36151. ret = cpufreq_driver->set_boost(state);
  36152. if (ret) {
  36153. write_lock_irqsave(&cpufreq_driver_lock, flags);
  36154. - cpufreq_driver->boost_enabled = !state;
  36155. + pax_open_kernel();
  36156. + *(bool *)&cpufreq_driver->boost_enabled = !state;
  36157. + pax_close_kernel();
  36158. write_unlock_irqrestore(&cpufreq_driver_lock, flags);
  36159. pr_err("%s: Cannot %s BOOST\n", __func__,
  36160. @@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
  36161. pr_debug("trying to register driver %s\n", driver_data->name);
  36162. - if (driver_data->setpolicy)
  36163. - driver_data->flags |= CPUFREQ_CONST_LOOPS;
  36164. + if (driver_data->setpolicy) {
  36165. + pax_open_kernel();
  36166. + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
  36167. + pax_close_kernel();
  36168. + }
  36169. write_lock_irqsave(&cpufreq_driver_lock, flags);
  36170. if (cpufreq_driver) {
  36171. @@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
  36172. * Check if driver provides function to enable boost -
  36173. * if not, use cpufreq_boost_set_sw as default
  36174. */
  36175. - if (!cpufreq_driver->set_boost)
  36176. - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
  36177. + if (!cpufreq_driver->set_boost) {
  36178. + pax_open_kernel();
  36179. + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
  36180. + pax_close_kernel();
  36181. + }
  36182. ret = cpufreq_sysfs_create_file(&boost.attr);
  36183. if (ret) {
  36184. diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
  36185. index ba43991..23858ffb 100644
  36186. --- a/drivers/cpufreq/cpufreq_governor.c
  36187. +++ b/drivers/cpufreq/cpufreq_governor.c
  36188. @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
  36189. struct dbs_data *dbs_data;
  36190. struct od_cpu_dbs_info_s *od_dbs_info = NULL;
  36191. struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
  36192. - struct od_ops *od_ops = NULL;
  36193. + const struct od_ops *od_ops = NULL;
  36194. struct od_dbs_tuners *od_tuners = NULL;
  36195. struct cs_dbs_tuners *cs_tuners = NULL;
  36196. struct cpu_dbs_common_info *cpu_cdbs;
  36197. @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
  36198. if ((cdata->governor == GOV_CONSERVATIVE) &&
  36199. (!policy->governor->initialized)) {
  36200. - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
  36201. + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
  36202. cpufreq_register_notifier(cs_ops->notifier_block,
  36203. CPUFREQ_TRANSITION_NOTIFIER);
  36204. @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
  36205. if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
  36206. (policy->governor->initialized == 1)) {
  36207. - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
  36208. + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
  36209. cpufreq_unregister_notifier(cs_ops->notifier_block,
  36210. CPUFREQ_TRANSITION_NOTIFIER);
  36211. diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
  36212. index bfb9ae1..e1d3a7e 100644
  36213. --- a/drivers/cpufreq/cpufreq_governor.h
  36214. +++ b/drivers/cpufreq/cpufreq_governor.h
  36215. @@ -205,7 +205,7 @@ struct common_dbs_data {
  36216. void (*exit)(struct dbs_data *dbs_data);
  36217. /* Governor specific ops, see below */
  36218. - void *gov_ops;
  36219. + const void *gov_ops;
  36220. };
  36221. /* Governor Per policy data */
  36222. @@ -225,7 +225,7 @@ struct od_ops {
  36223. unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
  36224. unsigned int freq_next, unsigned int relation);
  36225. void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
  36226. -};
  36227. +} __no_const;
  36228. struct cs_ops {
  36229. struct notifier_block *notifier_block;
  36230. diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
  36231. index 18d4091..434be15 100644
  36232. --- a/drivers/cpufreq/cpufreq_ondemand.c
  36233. +++ b/drivers/cpufreq/cpufreq_ondemand.c
  36234. @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
  36235. define_get_cpu_dbs_routines(od_cpu_dbs_info);
  36236. -static struct od_ops od_ops = {
  36237. +static struct od_ops od_ops __read_only = {
  36238. .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
  36239. .powersave_bias_target = generic_powersave_bias_target,
  36240. .freq_increase = dbs_freq_increase,
  36241. @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
  36242. (struct cpufreq_policy *, unsigned int, unsigned int),
  36243. unsigned int powersave_bias)
  36244. {
  36245. - od_ops.powersave_bias_target = f;
  36246. + pax_open_kernel();
  36247. + *(void **)&od_ops.powersave_bias_target = f;
  36248. + pax_close_kernel();
  36249. od_set_powersave_bias(powersave_bias);
  36250. }
  36251. EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
  36252. void od_unregister_powersave_bias_handler(void)
  36253. {
  36254. - od_ops.powersave_bias_target = generic_powersave_bias_target;
  36255. + pax_open_kernel();
  36256. + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
  36257. + pax_close_kernel();
  36258. od_set_powersave_bias(0);
  36259. }
  36260. EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
  36261. diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
  36262. index 2cd36b9..8f07fae 100644
  36263. --- a/drivers/cpufreq/intel_pstate.c
  36264. +++ b/drivers/cpufreq/intel_pstate.c
  36265. @@ -124,10 +124,10 @@ struct pstate_funcs {
  36266. struct cpu_defaults {
  36267. struct pstate_adjust_policy pid_policy;
  36268. struct pstate_funcs funcs;
  36269. -};
  36270. +} __do_const;
  36271. static struct pstate_adjust_policy pid_params;
  36272. -static struct pstate_funcs pstate_funcs;
  36273. +static struct pstate_funcs *pstate_funcs;
  36274. struct perf_limits {
  36275. int no_turbo;
  36276. @@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
  36277. cpu->pstate.current_pstate = pstate;
  36278. - pstate_funcs.set(cpu, pstate);
  36279. + pstate_funcs->set(cpu, pstate);
  36280. }
  36281. static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
  36282. @@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
  36283. {
  36284. sprintf(cpu->name, "Intel 2nd generation core");
  36285. - cpu->pstate.min_pstate = pstate_funcs.get_min();
  36286. - cpu->pstate.max_pstate = pstate_funcs.get_max();
  36287. - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
  36288. + cpu->pstate.min_pstate = pstate_funcs->get_min();
  36289. + cpu->pstate.max_pstate = pstate_funcs->get_max();
  36290. + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
  36291. - if (pstate_funcs.get_vid)
  36292. - pstate_funcs.get_vid(cpu);
  36293. + if (pstate_funcs->get_vid)
  36294. + pstate_funcs->get_vid(cpu);
  36295. /*
  36296. * goto max pstate so we don't slow up boot if we are built-in if we are
  36297. @@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
  36298. rdmsrl(MSR_IA32_APERF, aperf);
  36299. rdmsrl(MSR_IA32_MPERF, mperf);
  36300. - if (!pstate_funcs.get_max() ||
  36301. - !pstate_funcs.get_min() ||
  36302. - !pstate_funcs.get_turbo())
  36303. + if (!pstate_funcs->get_max() ||
  36304. + !pstate_funcs->get_min() ||
  36305. + !pstate_funcs->get_turbo())
  36306. return -ENODEV;
  36307. rdmsrl(MSR_IA32_APERF, tmp);
  36308. @@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
  36309. return 0;
  36310. }
  36311. -static void copy_pid_params(struct pstate_adjust_policy *policy)
  36312. +static void copy_pid_params(const struct pstate_adjust_policy *policy)
  36313. {
  36314. pid_params.sample_rate_ms = policy->sample_rate_ms;
  36315. pid_params.p_gain_pct = policy->p_gain_pct;
  36316. @@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
  36317. static void copy_cpu_funcs(struct pstate_funcs *funcs)
  36318. {
  36319. - pstate_funcs.get_max = funcs->get_max;
  36320. - pstate_funcs.get_min = funcs->get_min;
  36321. - pstate_funcs.get_turbo = funcs->get_turbo;
  36322. - pstate_funcs.set = funcs->set;
  36323. - pstate_funcs.get_vid = funcs->get_vid;
  36324. + pstate_funcs = funcs;
  36325. }
  36326. #if IS_ENABLED(CONFIG_ACPI)
  36327. diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
  36328. index 3d1cba9..0ab21d2 100644
  36329. --- a/drivers/cpufreq/p4-clockmod.c
  36330. +++ b/drivers/cpufreq/p4-clockmod.c
  36331. @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
  36332. case 0x0F: /* Core Duo */
  36333. case 0x16: /* Celeron Core */
  36334. case 0x1C: /* Atom */
  36335. - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
  36336. + pax_open_kernel();
  36337. + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
  36338. + pax_close_kernel();
  36339. return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
  36340. case 0x0D: /* Pentium M (Dothan) */
  36341. - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
  36342. + pax_open_kernel();
  36343. + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
  36344. + pax_close_kernel();
  36345. /* fall through */
  36346. case 0x09: /* Pentium M (Banias) */
  36347. return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
  36348. @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
  36349. /* on P-4s, the TSC runs with constant frequency independent whether
  36350. * throttling is active or not. */
  36351. - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
  36352. + pax_open_kernel();
  36353. + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
  36354. + pax_close_kernel();
  36355. if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
  36356. printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
  36357. diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
  36358. index 724ffbd..f06aaaa 100644
  36359. --- a/drivers/cpufreq/sparc-us3-cpufreq.c
  36360. +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
  36361. @@ -18,14 +18,12 @@
  36362. #include <asm/head.h>
  36363. #include <asm/timer.h>
  36364. -static struct cpufreq_driver *cpufreq_us3_driver;
  36365. -
  36366. struct us3_freq_percpu_info {
  36367. struct cpufreq_frequency_table table[4];
  36368. };
  36369. /* Indexed by cpu number. */
  36370. -static struct us3_freq_percpu_info *us3_freq_table;
  36371. +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
  36372. /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
  36373. * in the Safari config register.
  36374. @@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
  36375. static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
  36376. {
  36377. - if (cpufreq_us3_driver) {
  36378. - cpufreq_frequency_table_put_attr(policy->cpu);
  36379. - us3_freq_target(policy, 0);
  36380. - }
  36381. + cpufreq_frequency_table_put_attr(policy->cpu);
  36382. + us3_freq_target(policy, 0);
  36383. return 0;
  36384. }
  36385. +static int __init us3_freq_init(void);
  36386. +static void __exit us3_freq_exit(void);
  36387. +
  36388. +static struct cpufreq_driver cpufreq_us3_driver = {
  36389. + .init = us3_freq_cpu_init,
  36390. + .verify = cpufreq_generic_frequency_table_verify,
  36391. + .target_index = us3_freq_target,
  36392. + .get = us3_freq_get,
  36393. + .exit = us3_freq_cpu_exit,
  36394. + .name = "UltraSPARC-III",
  36395. +
  36396. +};
  36397. +
  36398. static int __init us3_freq_init(void)
  36399. {
  36400. unsigned long manuf, impl, ver;
  36401. - int ret;
  36402. if (tlb_type != cheetah && tlb_type != cheetah_plus)
  36403. return -ENODEV;
  36404. @@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
  36405. (impl == CHEETAH_IMPL ||
  36406. impl == CHEETAH_PLUS_IMPL ||
  36407. impl == JAGUAR_IMPL ||
  36408. - impl == PANTHER_IMPL)) {
  36409. - struct cpufreq_driver *driver;
  36410. -
  36411. - ret = -ENOMEM;
  36412. - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
  36413. - if (!driver)
  36414. - goto err_out;
  36415. -
  36416. - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
  36417. - GFP_KERNEL);
  36418. - if (!us3_freq_table)
  36419. - goto err_out;
  36420. -
  36421. - driver->init = us3_freq_cpu_init;
  36422. - driver->verify = cpufreq_generic_frequency_table_verify;
  36423. - driver->target_index = us3_freq_target;
  36424. - driver->get = us3_freq_get;
  36425. - driver->exit = us3_freq_cpu_exit;
  36426. - strcpy(driver->name, "UltraSPARC-III");
  36427. -
  36428. - cpufreq_us3_driver = driver;
  36429. - ret = cpufreq_register_driver(driver);
  36430. - if (ret)
  36431. - goto err_out;
  36432. -
  36433. - return 0;
  36434. -
  36435. -err_out:
  36436. - if (driver) {
  36437. - kfree(driver);
  36438. - cpufreq_us3_driver = NULL;
  36439. - }
  36440. - kfree(us3_freq_table);
  36441. - us3_freq_table = NULL;
  36442. - return ret;
  36443. - }
  36444. + impl == PANTHER_IMPL))
  36445. + return cpufreq_register_driver(&cpufreq_us3_driver);
  36446. return -ENODEV;
  36447. }
  36448. static void __exit us3_freq_exit(void)
  36449. {
  36450. - if (cpufreq_us3_driver) {
  36451. - cpufreq_unregister_driver(cpufreq_us3_driver);
  36452. - kfree(cpufreq_us3_driver);
  36453. - cpufreq_us3_driver = NULL;
  36454. - kfree(us3_freq_table);
  36455. - us3_freq_table = NULL;
  36456. - }
  36457. + cpufreq_unregister_driver(&cpufreq_us3_driver);
  36458. }
  36459. MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
  36460. diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
  36461. index 4e1daca..e707b61 100644
  36462. --- a/drivers/cpufreq/speedstep-centrino.c
  36463. +++ b/drivers/cpufreq/speedstep-centrino.c
  36464. @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
  36465. !cpu_has(cpu, X86_FEATURE_EST))
  36466. return -ENODEV;
  36467. - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
  36468. - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
  36469. + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
  36470. + pax_open_kernel();
  36471. + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
  36472. + pax_close_kernel();
  36473. + }
  36474. if (policy->cpu != 0)
  36475. return -ENODEV;
  36476. diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
  36477. index 06dbe7c..c2c8671 100644
  36478. --- a/drivers/cpuidle/driver.c
  36479. +++ b/drivers/cpuidle/driver.c
  36480. @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
  36481. static void poll_idle_init(struct cpuidle_driver *drv)
  36482. {
  36483. - struct cpuidle_state *state = &drv->states[0];
  36484. + cpuidle_state_no_const *state = &drv->states[0];
  36485. snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
  36486. snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
  36487. diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
  36488. index ca89412..a7b9c49 100644
  36489. --- a/drivers/cpuidle/governor.c
  36490. +++ b/drivers/cpuidle/governor.c
  36491. @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
  36492. mutex_lock(&cpuidle_lock);
  36493. if (__cpuidle_find_governor(gov->name) == NULL) {
  36494. ret = 0;
  36495. - list_add_tail(&gov->governor_list, &cpuidle_governors);
  36496. + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
  36497. if (!cpuidle_curr_governor ||
  36498. cpuidle_curr_governor->rating < gov->rating)
  36499. cpuidle_switch_governor(gov);
  36500. diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
  36501. index e918b6d..f87ea80 100644
  36502. --- a/drivers/cpuidle/sysfs.c
  36503. +++ b/drivers/cpuidle/sysfs.c
  36504. @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
  36505. NULL
  36506. };
  36507. -static struct attribute_group cpuidle_attr_group = {
  36508. +static attribute_group_no_const cpuidle_attr_group = {
  36509. .attrs = cpuidle_default_attrs,
  36510. .name = "cpuidle",
  36511. };
  36512. diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
  36513. index 12fea3e..1e28f47 100644
  36514. --- a/drivers/crypto/hifn_795x.c
  36515. +++ b/drivers/crypto/hifn_795x.c
  36516. @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
  36517. MODULE_PARM_DESC(hifn_pll_ref,
  36518. "PLL reference clock (pci[freq] or ext[freq], default ext)");
  36519. -static atomic_t hifn_dev_number;
  36520. +static atomic_unchecked_t hifn_dev_number;
  36521. #define ACRYPTO_OP_DECRYPT 0
  36522. #define ACRYPTO_OP_ENCRYPT 1
  36523. @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  36524. goto err_out_disable_pci_device;
  36525. snprintf(name, sizeof(name), "hifn%d",
  36526. - atomic_inc_return(&hifn_dev_number)-1);
  36527. + atomic_inc_return_unchecked(&hifn_dev_number)-1);
  36528. err = pci_request_regions(pdev, name);
  36529. if (err)
  36530. diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
  36531. index a0b2f7e..1b6f028 100644
  36532. --- a/drivers/devfreq/devfreq.c
  36533. +++ b/drivers/devfreq/devfreq.c
  36534. @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
  36535. goto err_out;
  36536. }
  36537. - list_add(&governor->node, &devfreq_governor_list);
  36538. + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
  36539. list_for_each_entry(devfreq, &devfreq_list, node) {
  36540. int ret = 0;
  36541. @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
  36542. }
  36543. }
  36544. - list_del(&governor->node);
  36545. + pax_list_del((struct list_head *)&governor->node);
  36546. err_out:
  36547. mutex_unlock(&devfreq_list_lock);
  36548. diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
  36549. index 2e7b394..1371a64 100644
  36550. --- a/drivers/dma/sh/shdma-base.c
  36551. +++ b/drivers/dma/sh/shdma-base.c
  36552. @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
  36553. schan->slave_id = -EINVAL;
  36554. }
  36555. - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
  36556. - sdev->desc_size, GFP_KERNEL);
  36557. + schan->desc = kcalloc(sdev->desc_size,
  36558. + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
  36559. if (!schan->desc) {
  36560. ret = -ENOMEM;
  36561. goto edescalloc;
  36562. diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
  36563. index 0d765c0..60b7480 100644
  36564. --- a/drivers/dma/sh/shdmac.c
  36565. +++ b/drivers/dma/sh/shdmac.c
  36566. @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
  36567. return ret;
  36568. }
  36569. -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
  36570. +static struct notifier_block sh_dmae_nmi_notifier = {
  36571. .notifier_call = sh_dmae_nmi_handler,
  36572. /* Run before NMI debug handler and KGDB */
  36573. diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
  36574. index 592af5f..bb1d583 100644
  36575. --- a/drivers/edac/edac_device.c
  36576. +++ b/drivers/edac/edac_device.c
  36577. @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
  36578. */
  36579. int edac_device_alloc_index(void)
  36580. {
  36581. - static atomic_t device_indexes = ATOMIC_INIT(0);
  36582. + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
  36583. - return atomic_inc_return(&device_indexes) - 1;
  36584. + return atomic_inc_return_unchecked(&device_indexes) - 1;
  36585. }
  36586. EXPORT_SYMBOL_GPL(edac_device_alloc_index);
  36587. diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
  36588. index b335c6a..db65b44 100644
  36589. --- a/drivers/edac/edac_mc_sysfs.c
  36590. +++ b/drivers/edac/edac_mc_sysfs.c
  36591. @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
  36592. struct dev_ch_attribute {
  36593. struct device_attribute attr;
  36594. int channel;
  36595. -};
  36596. +} __do_const;
  36597. #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
  36598. struct dev_ch_attribute dev_attr_legacy_##_name = \
  36599. @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
  36600. }
  36601. if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
  36602. + pax_open_kernel();
  36603. if (mci->get_sdram_scrub_rate) {
  36604. - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
  36605. - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
  36606. + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
  36607. + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
  36608. }
  36609. if (mci->set_sdram_scrub_rate) {
  36610. - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
  36611. - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
  36612. + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
  36613. + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
  36614. }
  36615. + pax_close_kernel();
  36616. err = device_create_file(&mci->dev,
  36617. &dev_attr_sdram_scrub_rate);
  36618. if (err) {
  36619. diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
  36620. index 2cf44b4d..6dd2dc7 100644
  36621. --- a/drivers/edac/edac_pci.c
  36622. +++ b/drivers/edac/edac_pci.c
  36623. @@ -29,7 +29,7 @@
  36624. static DEFINE_MUTEX(edac_pci_ctls_mutex);
  36625. static LIST_HEAD(edac_pci_list);
  36626. -static atomic_t pci_indexes = ATOMIC_INIT(0);
  36627. +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
  36628. /*
  36629. * edac_pci_alloc_ctl_info
  36630. @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
  36631. */
  36632. int edac_pci_alloc_index(void)
  36633. {
  36634. - return atomic_inc_return(&pci_indexes) - 1;
  36635. + return atomic_inc_return_unchecked(&pci_indexes) - 1;
  36636. }
  36637. EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
  36638. diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
  36639. index e8658e4..22746d6 100644
  36640. --- a/drivers/edac/edac_pci_sysfs.c
  36641. +++ b/drivers/edac/edac_pci_sysfs.c
  36642. @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
  36643. static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
  36644. static int edac_pci_poll_msec = 1000; /* one second workq period */
  36645. -static atomic_t pci_parity_count = ATOMIC_INIT(0);
  36646. -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
  36647. +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
  36648. +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
  36649. static struct kobject *edac_pci_top_main_kobj;
  36650. static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
  36651. @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
  36652. void *value;
  36653. ssize_t(*show) (void *, char *);
  36654. ssize_t(*store) (void *, const char *, size_t);
  36655. -};
  36656. +} __do_const;
  36657. /* Set of show/store abstract level functions for PCI Parity object */
  36658. static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
  36659. @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
  36660. edac_printk(KERN_CRIT, EDAC_PCI,
  36661. "Signaled System Error on %s\n",
  36662. pci_name(dev));
  36663. - atomic_inc(&pci_nonparity_count);
  36664. + atomic_inc_unchecked(&pci_nonparity_count);
  36665. }
  36666. if (status & (PCI_STATUS_PARITY)) {
  36667. @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
  36668. "Master Data Parity Error on %s\n",
  36669. pci_name(dev));
  36670. - atomic_inc(&pci_parity_count);
  36671. + atomic_inc_unchecked(&pci_parity_count);
  36672. }
  36673. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  36674. @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
  36675. "Detected Parity Error on %s\n",
  36676. pci_name(dev));
  36677. - atomic_inc(&pci_parity_count);
  36678. + atomic_inc_unchecked(&pci_parity_count);
  36679. }
  36680. }
  36681. @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
  36682. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  36683. "Signaled System Error on %s\n",
  36684. pci_name(dev));
  36685. - atomic_inc(&pci_nonparity_count);
  36686. + atomic_inc_unchecked(&pci_nonparity_count);
  36687. }
  36688. if (status & (PCI_STATUS_PARITY)) {
  36689. @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
  36690. "Master Data Parity Error on "
  36691. "%s\n", pci_name(dev));
  36692. - atomic_inc(&pci_parity_count);
  36693. + atomic_inc_unchecked(&pci_parity_count);
  36694. }
  36695. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  36696. @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
  36697. "Detected Parity Error on %s\n",
  36698. pci_name(dev));
  36699. - atomic_inc(&pci_parity_count);
  36700. + atomic_inc_unchecked(&pci_parity_count);
  36701. }
  36702. }
  36703. }
  36704. @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
  36705. if (!check_pci_errors)
  36706. return;
  36707. - before_count = atomic_read(&pci_parity_count);
  36708. + before_count = atomic_read_unchecked(&pci_parity_count);
  36709. /* scan all PCI devices looking for a Parity Error on devices and
  36710. * bridges.
  36711. @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
  36712. /* Only if operator has selected panic on PCI Error */
  36713. if (edac_pci_get_panic_on_pe()) {
  36714. /* If the count is different 'after' from 'before' */
  36715. - if (before_count != atomic_read(&pci_parity_count))
  36716. + if (before_count != atomic_read_unchecked(&pci_parity_count))
  36717. panic("EDAC: PCI Parity Error");
  36718. }
  36719. }
  36720. diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
  36721. index 51b7e3a..aa8a3e8 100644
  36722. --- a/drivers/edac/mce_amd.h
  36723. +++ b/drivers/edac/mce_amd.h
  36724. @@ -77,7 +77,7 @@ struct amd_decoder_ops {
  36725. bool (*mc0_mce)(u16, u8);
  36726. bool (*mc1_mce)(u16, u8);
  36727. bool (*mc2_mce)(u16, u8);
  36728. -};
  36729. +} __no_const;
  36730. void amd_report_gart_errors(bool);
  36731. void amd_register_ecc_decoder(void (*f)(int, struct mce *));
  36732. diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
  36733. index 57ea7f4..af06b76 100644
  36734. --- a/drivers/firewire/core-card.c
  36735. +++ b/drivers/firewire/core-card.c
  36736. @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
  36737. const struct fw_card_driver *driver,
  36738. struct device *device)
  36739. {
  36740. - static atomic_t index = ATOMIC_INIT(-1);
  36741. + static atomic_unchecked_t index = ATOMIC_INIT(-1);
  36742. - card->index = atomic_inc_return(&index);
  36743. + card->index = atomic_inc_return_unchecked(&index);
  36744. card->driver = driver;
  36745. card->device = device;
  36746. card->current_tlabel = 0;
  36747. @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
  36748. void fw_core_remove_card(struct fw_card *card)
  36749. {
  36750. - struct fw_card_driver dummy_driver = dummy_driver_template;
  36751. + fw_card_driver_no_const dummy_driver = dummy_driver_template;
  36752. card->driver->update_phy_reg(card, 4,
  36753. PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
  36754. diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
  36755. index 2c6d5e1..a2cca6b 100644
  36756. --- a/drivers/firewire/core-device.c
  36757. +++ b/drivers/firewire/core-device.c
  36758. @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
  36759. struct config_rom_attribute {
  36760. struct device_attribute attr;
  36761. u32 key;
  36762. -};
  36763. +} __do_const;
  36764. static ssize_t show_immediate(struct device *dev,
  36765. struct device_attribute *dattr, char *buf)
  36766. diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
  36767. index eb6935c..3cc2bfa 100644
  36768. --- a/drivers/firewire/core-transaction.c
  36769. +++ b/drivers/firewire/core-transaction.c
  36770. @@ -38,6 +38,7 @@
  36771. #include <linux/timer.h>
  36772. #include <linux/types.h>
  36773. #include <linux/workqueue.h>
  36774. +#include <linux/sched.h>
  36775. #include <asm/byteorder.h>
  36776. diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
  36777. index c98764a..551b520 100644
  36778. --- a/drivers/firewire/core.h
  36779. +++ b/drivers/firewire/core.h
  36780. @@ -111,6 +111,7 @@ struct fw_card_driver {
  36781. int (*stop_iso)(struct fw_iso_context *ctx);
  36782. };
  36783. +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
  36784. void fw_card_initialize(struct fw_card *card,
  36785. const struct fw_card_driver *driver, struct device *device);
  36786. diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
  36787. index 8db6632..9bbc8ca 100644
  36788. --- a/drivers/firewire/ohci.c
  36789. +++ b/drivers/firewire/ohci.c
  36790. @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
  36791. be32_to_cpu(ohci->next_header));
  36792. }
  36793. +#ifndef CONFIG_GRKERNSEC
  36794. if (param_remote_dma) {
  36795. reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
  36796. reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
  36797. }
  36798. +#endif
  36799. spin_unlock_irq(&ohci->lock);
  36800. @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
  36801. unsigned long flags;
  36802. int n, ret = 0;
  36803. +#ifndef CONFIG_GRKERNSEC
  36804. if (param_remote_dma)
  36805. return 0;
  36806. +#endif
  36807. /*
  36808. * FIXME: Make sure this bitmask is cleared when we clear the busReset
  36809. diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
  36810. index 94a58a0..f5eba42 100644
  36811. --- a/drivers/firmware/dmi-id.c
  36812. +++ b/drivers/firmware/dmi-id.c
  36813. @@ -16,7 +16,7 @@
  36814. struct dmi_device_attribute{
  36815. struct device_attribute dev_attr;
  36816. int field;
  36817. -};
  36818. +} __do_const;
  36819. #define to_dmi_dev_attr(_dev_attr) \
  36820. container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
  36821. diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
  36822. index 17afc51..0ef90cd 100644
  36823. --- a/drivers/firmware/dmi_scan.c
  36824. +++ b/drivers/firmware/dmi_scan.c
  36825. @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
  36826. if (buf == NULL)
  36827. return -1;
  36828. - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
  36829. + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
  36830. dmi_unmap(buf);
  36831. return 0;
  36832. diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
  36833. index 1491dd4..aa910db 100644
  36834. --- a/drivers/firmware/efi/cper.c
  36835. +++ b/drivers/firmware/efi/cper.c
  36836. @@ -41,12 +41,12 @@
  36837. */
  36838. u64 cper_next_record_id(void)
  36839. {
  36840. - static atomic64_t seq;
  36841. + static atomic64_unchecked_t seq;
  36842. - if (!atomic64_read(&seq))
  36843. - atomic64_set(&seq, ((u64)get_seconds()) << 32);
  36844. + if (!atomic64_read_unchecked(&seq))
  36845. + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
  36846. - return atomic64_inc_return(&seq);
  36847. + return atomic64_inc_return_unchecked(&seq);
  36848. }
  36849. EXPORT_SYMBOL_GPL(cper_next_record_id);
  36850. diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
  36851. index 4753bac..02861a2 100644
  36852. --- a/drivers/firmware/efi/efi.c
  36853. +++ b/drivers/firmware/efi/efi.c
  36854. @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
  36855. };
  36856. static struct efivars generic_efivars;
  36857. -static struct efivar_operations generic_ops;
  36858. +static efivar_operations_no_const generic_ops __read_only;
  36859. static int generic_ops_register(void)
  36860. {
  36861. - generic_ops.get_variable = efi.get_variable;
  36862. - generic_ops.set_variable = efi.set_variable;
  36863. - generic_ops.get_next_variable = efi.get_next_variable;
  36864. - generic_ops.query_variable_store = efi_query_variable_store;
  36865. + pax_open_kernel();
  36866. + *(void **)&generic_ops.get_variable = efi.get_variable;
  36867. + *(void **)&generic_ops.set_variable = efi.set_variable;
  36868. + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
  36869. + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
  36870. + pax_close_kernel();
  36871. return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
  36872. }
  36873. diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
  36874. index 3dc2482..7bd2f61 100644
  36875. --- a/drivers/firmware/efi/efivars.c
  36876. +++ b/drivers/firmware/efi/efivars.c
  36877. @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
  36878. static int
  36879. create_efivars_bin_attributes(void)
  36880. {
  36881. - struct bin_attribute *attr;
  36882. + bin_attribute_no_const *attr;
  36883. int error;
  36884. /* new_var */
  36885. diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
  36886. index 2a90ba6..07f3733 100644
  36887. --- a/drivers/firmware/google/memconsole.c
  36888. +++ b/drivers/firmware/google/memconsole.c
  36889. @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
  36890. if (!found_memconsole())
  36891. return -ENODEV;
  36892. - memconsole_bin_attr.size = memconsole_length;
  36893. + pax_open_kernel();
  36894. + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
  36895. + pax_close_kernel();
  36896. ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
  36897. diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
  36898. index 1e98a98..b444372 100644
  36899. --- a/drivers/gpio/gpio-em.c
  36900. +++ b/drivers/gpio/gpio-em.c
  36901. @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
  36902. struct em_gio_priv *p;
  36903. struct resource *io[2], *irq[2];
  36904. struct gpio_chip *gpio_chip;
  36905. - struct irq_chip *irq_chip;
  36906. + irq_chip_no_const *irq_chip;
  36907. const char *name = dev_name(&pdev->dev);
  36908. int ret;
  36909. diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
  36910. index f5bf3c3..7baaa59 100644
  36911. --- a/drivers/gpio/gpio-ich.c
  36912. +++ b/drivers/gpio/gpio-ich.c
  36913. @@ -71,7 +71,7 @@ struct ichx_desc {
  36914. /* Some chipsets have quirks, let these use their own request/get */
  36915. int (*request)(struct gpio_chip *chip, unsigned offset);
  36916. int (*get)(struct gpio_chip *chip, unsigned offset);
  36917. -};
  36918. +} __do_const;
  36919. static struct {
  36920. spinlock_t lock;
  36921. diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
  36922. index ca76ce7..68b384b 100644
  36923. --- a/drivers/gpio/gpio-rcar.c
  36924. +++ b/drivers/gpio/gpio-rcar.c
  36925. @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
  36926. struct gpio_rcar_priv *p;
  36927. struct resource *io, *irq;
  36928. struct gpio_chip *gpio_chip;
  36929. - struct irq_chip *irq_chip;
  36930. + irq_chip_no_const *irq_chip;
  36931. const char *name = dev_name(&pdev->dev);
  36932. int ret;
  36933. diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
  36934. index 9902732..64b62dd 100644
  36935. --- a/drivers/gpio/gpio-vr41xx.c
  36936. +++ b/drivers/gpio/gpio-vr41xx.c
  36937. @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
  36938. printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
  36939. maskl, pendl, maskh, pendh);
  36940. - atomic_inc(&irq_err_count);
  36941. + atomic_inc_unchecked(&irq_err_count);
  36942. return -EINVAL;
  36943. }
  36944. diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
  36945. index 3b7d32d..05c2f74 100644
  36946. --- a/drivers/gpu/drm/drm_crtc.c
  36947. +++ b/drivers/gpu/drm/drm_crtc.c
  36948. @@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
  36949. goto done;
  36950. }
  36951. - if (copy_to_user(&enum_ptr[copied].name,
  36952. + if (copy_to_user(enum_ptr[copied].name,
  36953. &prop_enum->name, DRM_PROP_NAME_LEN)) {
  36954. ret = -EFAULT;
  36955. goto done;
  36956. diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
  36957. index 345be03..158368d 100644
  36958. --- a/drivers/gpu/drm/drm_drv.c
  36959. +++ b/drivers/gpu/drm/drm_drv.c
  36960. @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
  36961. /**
  36962. * Copy and IOCTL return string to user space
  36963. */
  36964. -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
  36965. +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
  36966. {
  36967. int len;
  36968. @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
  36969. struct drm_file *file_priv = filp->private_data;
  36970. struct drm_device *dev;
  36971. const struct drm_ioctl_desc *ioctl = NULL;
  36972. - drm_ioctl_t *func;
  36973. + drm_ioctl_no_const_t func;
  36974. unsigned int nr = DRM_IOCTL_NR(cmd);
  36975. int retcode = -EINVAL;
  36976. char stack_kdata[128];
  36977. diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
  36978. index 7f2af9a..1561914 100644
  36979. --- a/drivers/gpu/drm/drm_fops.c
  36980. +++ b/drivers/gpu/drm/drm_fops.c
  36981. @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
  36982. if (drm_device_is_unplugged(dev))
  36983. return -ENODEV;
  36984. - if (!dev->open_count++)
  36985. + if (local_inc_return(&dev->open_count) == 1)
  36986. need_setup = 1;
  36987. mutex_lock(&dev->struct_mutex);
  36988. old_imapping = inode->i_mapping;
  36989. @@ -127,7 +127,7 @@ err_undo:
  36990. iput(container_of(dev->dev_mapping, struct inode, i_data));
  36991. dev->dev_mapping = old_mapping;
  36992. mutex_unlock(&dev->struct_mutex);
  36993. - dev->open_count--;
  36994. + local_dec(&dev->open_count);
  36995. return retcode;
  36996. }
  36997. EXPORT_SYMBOL(drm_open);
  36998. @@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
  36999. mutex_lock(&drm_global_mutex);
  37000. - DRM_DEBUG("open_count = %d\n", dev->open_count);
  37001. + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
  37002. if (dev->driver->preclose)
  37003. dev->driver->preclose(dev, file_priv);
  37004. @@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
  37005. * Begin inline drm_release
  37006. */
  37007. - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
  37008. + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
  37009. task_pid_nr(current),
  37010. (long)old_encode_dev(file_priv->minor->device),
  37011. - dev->open_count);
  37012. + local_read(&dev->open_count));
  37013. /* Release any auth tokens that might point to this file_priv,
  37014. (do that under the drm_global_mutex) */
  37015. @@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
  37016. * End inline drm_release
  37017. */
  37018. - if (!--dev->open_count) {
  37019. + if (local_dec_and_test(&dev->open_count)) {
  37020. retcode = drm_lastclose(dev);
  37021. if (drm_device_is_unplugged(dev))
  37022. drm_put_dev(dev);
  37023. diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
  37024. index 3d2e91c..d31c4c9 100644
  37025. --- a/drivers/gpu/drm/drm_global.c
  37026. +++ b/drivers/gpu/drm/drm_global.c
  37027. @@ -36,7 +36,7 @@
  37028. struct drm_global_item {
  37029. struct mutex mutex;
  37030. void *object;
  37031. - int refcount;
  37032. + atomic_t refcount;
  37033. };
  37034. static struct drm_global_item glob[DRM_GLOBAL_NUM];
  37035. @@ -49,7 +49,7 @@ void drm_global_init(void)
  37036. struct drm_global_item *item = &glob[i];
  37037. mutex_init(&item->mutex);
  37038. item->object = NULL;
  37039. - item->refcount = 0;
  37040. + atomic_set(&item->refcount, 0);
  37041. }
  37042. }
  37043. @@ -59,7 +59,7 @@ void drm_global_release(void)
  37044. for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
  37045. struct drm_global_item *item = &glob[i];
  37046. BUG_ON(item->object != NULL);
  37047. - BUG_ON(item->refcount != 0);
  37048. + BUG_ON(atomic_read(&item->refcount) != 0);
  37049. }
  37050. }
  37051. @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
  37052. struct drm_global_item *item = &glob[ref->global_type];
  37053. mutex_lock(&item->mutex);
  37054. - if (item->refcount == 0) {
  37055. + if (atomic_read(&item->refcount) == 0) {
  37056. item->object = kzalloc(ref->size, GFP_KERNEL);
  37057. if (unlikely(item->object == NULL)) {
  37058. ret = -ENOMEM;
  37059. @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
  37060. goto out_err;
  37061. }
  37062. - ++item->refcount;
  37063. + atomic_inc(&item->refcount);
  37064. ref->object = item->object;
  37065. mutex_unlock(&item->mutex);
  37066. return 0;
  37067. @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
  37068. struct drm_global_item *item = &glob[ref->global_type];
  37069. mutex_lock(&item->mutex);
  37070. - BUG_ON(item->refcount == 0);
  37071. + BUG_ON(atomic_read(&item->refcount) == 0);
  37072. BUG_ON(ref->object != item->object);
  37073. - if (--item->refcount == 0) {
  37074. + if (atomic_dec_and_test(&item->refcount)) {
  37075. ref->release(ref);
  37076. item->object = NULL;
  37077. }
  37078. diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
  37079. index 7473035..a48b9c5 100644
  37080. --- a/drivers/gpu/drm/drm_info.c
  37081. +++ b/drivers/gpu/drm/drm_info.c
  37082. @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
  37083. struct drm_local_map *map;
  37084. struct drm_map_list *r_list;
  37085. - /* Hardcoded from _DRM_FRAME_BUFFER,
  37086. - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
  37087. - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
  37088. - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
  37089. + static const char * const types[] = {
  37090. + [_DRM_FRAME_BUFFER] = "FB",
  37091. + [_DRM_REGISTERS] = "REG",
  37092. + [_DRM_SHM] = "SHM",
  37093. + [_DRM_AGP] = "AGP",
  37094. + [_DRM_SCATTER_GATHER] = "SG",
  37095. + [_DRM_CONSISTENT] = "PCI"};
  37096. const char *type;
  37097. int i;
  37098. @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
  37099. map = r_list->map;
  37100. if (!map)
  37101. continue;
  37102. - if (map->type < 0 || map->type > 5)
  37103. + if (map->type >= ARRAY_SIZE(types))
  37104. type = "??";
  37105. else
  37106. type = types[map->type];
  37107. @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
  37108. vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
  37109. vma->vm_flags & VM_LOCKED ? 'l' : '-',
  37110. vma->vm_flags & VM_IO ? 'i' : '-',
  37111. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  37112. + 0);
  37113. +#else
  37114. vma->vm_pgoff);
  37115. +#endif
  37116. #if defined(__i386__)
  37117. pgprot = pgprot_val(vma->vm_page_prot);
  37118. diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
  37119. index 2f4c4343..dd12cd2 100644
  37120. --- a/drivers/gpu/drm/drm_ioc32.c
  37121. +++ b/drivers/gpu/drm/drm_ioc32.c
  37122. @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
  37123. request = compat_alloc_user_space(nbytes);
  37124. if (!access_ok(VERIFY_WRITE, request, nbytes))
  37125. return -EFAULT;
  37126. - list = (struct drm_buf_desc *) (request + 1);
  37127. + list = (struct drm_buf_desc __user *) (request + 1);
  37128. if (__put_user(count, &request->count)
  37129. || __put_user(list, &request->list))
  37130. @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
  37131. request = compat_alloc_user_space(nbytes);
  37132. if (!access_ok(VERIFY_WRITE, request, nbytes))
  37133. return -EFAULT;
  37134. - list = (struct drm_buf_pub *) (request + 1);
  37135. + list = (struct drm_buf_pub __user *) (request + 1);
  37136. if (__put_user(count, &request->count)
  37137. || __put_user(list, &request->list))
  37138. @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
  37139. return 0;
  37140. }
  37141. -drm_ioctl_compat_t *drm_compat_ioctls[] = {
  37142. +drm_ioctl_compat_t drm_compat_ioctls[] = {
  37143. [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
  37144. [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
  37145. [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
  37146. @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
  37147. long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  37148. {
  37149. unsigned int nr = DRM_IOCTL_NR(cmd);
  37150. - drm_ioctl_compat_t *fn;
  37151. int ret;
  37152. /* Assume that ioctls without an explicit compat routine will just
  37153. @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  37154. if (nr >= ARRAY_SIZE(drm_compat_ioctls))
  37155. return drm_ioctl(filp, cmd, arg);
  37156. - fn = drm_compat_ioctls[nr];
  37157. -
  37158. - if (fn != NULL)
  37159. - ret = (*fn) (filp, cmd, arg);
  37160. + if (drm_compat_ioctls[nr] != NULL)
  37161. + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
  37162. else
  37163. ret = drm_ioctl(filp, cmd, arg);
  37164. diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
  37165. index 98a33c580..8fd1c2b 100644
  37166. --- a/drivers/gpu/drm/drm_stub.c
  37167. +++ b/drivers/gpu/drm/drm_stub.c
  37168. @@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
  37169. drm_device_set_unplugged(dev);
  37170. - if (dev->open_count == 0) {
  37171. + if (local_read(&dev->open_count) == 0) {
  37172. drm_put_dev(dev);
  37173. }
  37174. mutex_unlock(&drm_global_mutex);
  37175. diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
  37176. index c22c309..ae758c3 100644
  37177. --- a/drivers/gpu/drm/drm_sysfs.c
  37178. +++ b/drivers/gpu/drm/drm_sysfs.c
  37179. @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
  37180. */
  37181. int drm_sysfs_device_add(struct drm_minor *minor)
  37182. {
  37183. - char *minor_str;
  37184. + const char *minor_str;
  37185. int r;
  37186. if (minor->type == DRM_MINOR_CONTROL)
  37187. diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
  37188. index d4d16ed..8fb0b51 100644
  37189. --- a/drivers/gpu/drm/i810/i810_drv.h
  37190. +++ b/drivers/gpu/drm/i810/i810_drv.h
  37191. @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
  37192. int page_flipping;
  37193. wait_queue_head_t irq_queue;
  37194. - atomic_t irq_received;
  37195. - atomic_t irq_emitted;
  37196. + atomic_unchecked_t irq_received;
  37197. + atomic_unchecked_t irq_emitted;
  37198. int front_offset;
  37199. } drm_i810_private_t;
  37200. diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
  37201. index b2b46c5..feb9fe7 100644
  37202. --- a/drivers/gpu/drm/i915/i915_debugfs.c
  37203. +++ b/drivers/gpu/drm/i915/i915_debugfs.c
  37204. @@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
  37205. I915_READ(GTIMR));
  37206. }
  37207. seq_printf(m, "Interrupts received: %d\n",
  37208. - atomic_read(&dev_priv->irq_received));
  37209. + atomic_read_unchecked(&dev_priv->irq_received));
  37210. for_each_ring(ring, dev_priv, i) {
  37211. if (INTEL_INFO(dev)->gen >= 6) {
  37212. seq_printf(m,
  37213. diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
  37214. index 15a74f9..4278889 100644
  37215. --- a/drivers/gpu/drm/i915/i915_dma.c
  37216. +++ b/drivers/gpu/drm/i915/i915_dma.c
  37217. @@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
  37218. bool can_switch;
  37219. spin_lock(&dev->count_lock);
  37220. - can_switch = (dev->open_count == 0);
  37221. + can_switch = (local_read(&dev->open_count) == 0);
  37222. spin_unlock(&dev->count_lock);
  37223. return can_switch;
  37224. }
  37225. diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
  37226. index df77e20..d3fda9f 100644
  37227. --- a/drivers/gpu/drm/i915/i915_drv.h
  37228. +++ b/drivers/gpu/drm/i915/i915_drv.h
  37229. @@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
  37230. drm_dma_handle_t *status_page_dmah;
  37231. struct resource mch_res;
  37232. - atomic_t irq_received;
  37233. + atomic_unchecked_t irq_received;
  37234. /* protects the irq masks */
  37235. spinlock_t irq_lock;
  37236. diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  37237. index d269ecf..6d857bc 100644
  37238. --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  37239. +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  37240. @@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
  37241. static int
  37242. validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
  37243. - int count)
  37244. + unsigned int count)
  37245. {
  37246. - int i;
  37247. + unsigned int i;
  37248. unsigned relocs_total = 0;
  37249. unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
  37250. diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
  37251. index 3c59584..500f2e9 100644
  37252. --- a/drivers/gpu/drm/i915/i915_ioc32.c
  37253. +++ b/drivers/gpu/drm/i915/i915_ioc32.c
  37254. @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
  37255. (unsigned long)request);
  37256. }
  37257. -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
  37258. +static drm_ioctl_compat_t i915_compat_ioctls[] = {
  37259. [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
  37260. [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
  37261. [DRM_I915_GETPARAM] = compat_i915_getparam,
  37262. @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
  37263. long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  37264. {
  37265. unsigned int nr = DRM_IOCTL_NR(cmd);
  37266. - drm_ioctl_compat_t *fn = NULL;
  37267. int ret;
  37268. if (nr < DRM_COMMAND_BASE)
  37269. return drm_compat_ioctl(filp, cmd, arg);
  37270. - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
  37271. - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
  37272. -
  37273. - if (fn != NULL)
  37274. + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
  37275. + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
  37276. ret = (*fn) (filp, cmd, arg);
  37277. - else
  37278. + } else
  37279. ret = drm_ioctl(filp, cmd, arg);
  37280. return ret;
  37281. diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
  37282. index d554169..f4426bb 100644
  37283. --- a/drivers/gpu/drm/i915/i915_irq.c
  37284. +++ b/drivers/gpu/drm/i915/i915_irq.c
  37285. @@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  37286. int pipe;
  37287. u32 pipe_stats[I915_MAX_PIPES];
  37288. - atomic_inc(&dev_priv->irq_received);
  37289. + atomic_inc_unchecked(&dev_priv->irq_received);
  37290. while (true) {
  37291. iir = I915_READ(VLV_IIR);
  37292. @@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  37293. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  37294. irqreturn_t ret = IRQ_NONE;
  37295. - atomic_inc(&dev_priv->irq_received);
  37296. + atomic_inc_unchecked(&dev_priv->irq_received);
  37297. /* We get interrupts on unclaimed registers, so check for this before we
  37298. * do any I915_{READ,WRITE}. */
  37299. @@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
  37300. uint32_t tmp = 0;
  37301. enum pipe pipe;
  37302. - atomic_inc(&dev_priv->irq_received);
  37303. + atomic_inc_unchecked(&dev_priv->irq_received);
  37304. master_ctl = I915_READ(GEN8_MASTER_IRQ);
  37305. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  37306. @@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
  37307. {
  37308. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  37309. - atomic_set(&dev_priv->irq_received, 0);
  37310. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37311. I915_WRITE(HWSTAM, 0xeffe);
  37312. @@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
  37313. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  37314. int pipe;
  37315. - atomic_set(&dev_priv->irq_received, 0);
  37316. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37317. /* VLV magic */
  37318. I915_WRITE(VLV_IMR, 0);
  37319. @@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
  37320. struct drm_i915_private *dev_priv = dev->dev_private;
  37321. int pipe;
  37322. - atomic_set(&dev_priv->irq_received, 0);
  37323. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37324. I915_WRITE(GEN8_MASTER_IRQ, 0);
  37325. POSTING_READ(GEN8_MASTER_IRQ);
  37326. @@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
  37327. if (!dev_priv)
  37328. return;
  37329. - atomic_set(&dev_priv->irq_received, 0);
  37330. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37331. I915_WRITE(GEN8_MASTER_IRQ, 0);
  37332. @@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
  37333. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  37334. int pipe;
  37335. - atomic_set(&dev_priv->irq_received, 0);
  37336. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37337. for_each_pipe(pipe)
  37338. I915_WRITE(PIPESTAT(pipe), 0);
  37339. @@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  37340. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  37341. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  37342. - atomic_inc(&dev_priv->irq_received);
  37343. + atomic_inc_unchecked(&dev_priv->irq_received);
  37344. iir = I915_READ16(IIR);
  37345. if (iir == 0)
  37346. @@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
  37347. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  37348. int pipe;
  37349. - atomic_set(&dev_priv->irq_received, 0);
  37350. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37351. if (I915_HAS_HOTPLUG(dev)) {
  37352. I915_WRITE(PORT_HOTPLUG_EN, 0);
  37353. @@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
  37354. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  37355. int pipe, ret = IRQ_NONE;
  37356. - atomic_inc(&dev_priv->irq_received);
  37357. + atomic_inc_unchecked(&dev_priv->irq_received);
  37358. iir = I915_READ(IIR);
  37359. do {
  37360. @@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
  37361. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  37362. int pipe;
  37363. - atomic_set(&dev_priv->irq_received, 0);
  37364. + atomic_set_unchecked(&dev_priv->irq_received, 0);
  37365. I915_WRITE(PORT_HOTPLUG_EN, 0);
  37366. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  37367. @@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
  37368. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  37369. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  37370. - atomic_inc(&dev_priv->irq_received);
  37371. + atomic_inc_unchecked(&dev_priv->irq_received);
  37372. iir = I915_READ(IIR);
  37373. diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
  37374. index 9b8a7c7..60f6003 100644
  37375. --- a/drivers/gpu/drm/i915/intel_display.c
  37376. +++ b/drivers/gpu/drm/i915/intel_display.c
  37377. @@ -10776,13 +10776,13 @@ struct intel_quirk {
  37378. int subsystem_vendor;
  37379. int subsystem_device;
  37380. void (*hook)(struct drm_device *dev);
  37381. -};
  37382. +} __do_const;
  37383. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  37384. struct intel_dmi_quirk {
  37385. void (*hook)(struct drm_device *dev);
  37386. const struct dmi_system_id (*dmi_id_list)[];
  37387. -};
  37388. +} __do_const;
  37389. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  37390. {
  37391. @@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  37392. return 1;
  37393. }
  37394. -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  37395. +static const struct dmi_system_id intel_dmi_quirks_table[] = {
  37396. {
  37397. - .dmi_id_list = &(const struct dmi_system_id[]) {
  37398. - {
  37399. - .callback = intel_dmi_reverse_brightness,
  37400. - .ident = "NCR Corporation",
  37401. - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  37402. - DMI_MATCH(DMI_PRODUCT_NAME, ""),
  37403. - },
  37404. - },
  37405. - { } /* terminating entry */
  37406. + .callback = intel_dmi_reverse_brightness,
  37407. + .ident = "NCR Corporation",
  37408. + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  37409. + DMI_MATCH(DMI_PRODUCT_NAME, ""),
  37410. },
  37411. + },
  37412. + { } /* terminating entry */
  37413. +};
  37414. +
  37415. +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  37416. + {
  37417. + .dmi_id_list = &intel_dmi_quirks_table,
  37418. .hook = quirk_invert_brightness,
  37419. },
  37420. };
  37421. diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
  37422. index fe45321..836fdca 100644
  37423. --- a/drivers/gpu/drm/mga/mga_drv.h
  37424. +++ b/drivers/gpu/drm/mga/mga_drv.h
  37425. @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
  37426. u32 clear_cmd;
  37427. u32 maccess;
  37428. - atomic_t vbl_received; /**< Number of vblanks received. */
  37429. + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
  37430. wait_queue_head_t fence_queue;
  37431. - atomic_t last_fence_retired;
  37432. + atomic_unchecked_t last_fence_retired;
  37433. u32 next_fence_to_post;
  37434. unsigned int fb_cpp;
  37435. diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
  37436. index 86b4bb8..ae237ad 100644
  37437. --- a/drivers/gpu/drm/mga/mga_ioc32.c
  37438. +++ b/drivers/gpu/drm/mga/mga_ioc32.c
  37439. @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
  37440. return 0;
  37441. }
  37442. -drm_ioctl_compat_t *mga_compat_ioctls[] = {
  37443. +drm_ioctl_compat_t mga_compat_ioctls[] = {
  37444. [DRM_MGA_INIT] = compat_mga_init,
  37445. [DRM_MGA_GETPARAM] = compat_mga_getparam,
  37446. [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
  37447. @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
  37448. long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  37449. {
  37450. unsigned int nr = DRM_IOCTL_NR(cmd);
  37451. - drm_ioctl_compat_t *fn = NULL;
  37452. int ret;
  37453. if (nr < DRM_COMMAND_BASE)
  37454. return drm_compat_ioctl(filp, cmd, arg);
  37455. - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
  37456. - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
  37457. -
  37458. - if (fn != NULL)
  37459. + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
  37460. + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
  37461. ret = (*fn) (filp, cmd, arg);
  37462. - else
  37463. + } else
  37464. ret = drm_ioctl(filp, cmd, arg);
  37465. return ret;
  37466. diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
  37467. index 1b071b8..de8601a 100644
  37468. --- a/drivers/gpu/drm/mga/mga_irq.c
  37469. +++ b/drivers/gpu/drm/mga/mga_irq.c
  37470. @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
  37471. if (crtc != 0)
  37472. return 0;
  37473. - return atomic_read(&dev_priv->vbl_received);
  37474. + return atomic_read_unchecked(&dev_priv->vbl_received);
  37475. }
  37476. @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
  37477. /* VBLANK interrupt */
  37478. if (status & MGA_VLINEPEN) {
  37479. MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
  37480. - atomic_inc(&dev_priv->vbl_received);
  37481. + atomic_inc_unchecked(&dev_priv->vbl_received);
  37482. drm_handle_vblank(dev, 0);
  37483. handled = 1;
  37484. }
  37485. @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
  37486. if ((prim_start & ~0x03) != (prim_end & ~0x03))
  37487. MGA_WRITE(MGA_PRIMEND, prim_end);
  37488. - atomic_inc(&dev_priv->last_fence_retired);
  37489. + atomic_inc_unchecked(&dev_priv->last_fence_retired);
  37490. wake_up(&dev_priv->fence_queue);
  37491. handled = 1;
  37492. }
  37493. @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
  37494. * using fences.
  37495. */
  37496. DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
  37497. - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
  37498. + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
  37499. - *sequence) <= (1 << 23)));
  37500. *sequence = cur_fence;
  37501. diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
  37502. index 4c3feaa..26391ce 100644
  37503. --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
  37504. +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
  37505. @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
  37506. struct bit_table {
  37507. const char id;
  37508. int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
  37509. -};
  37510. +} __no_const;
  37511. #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
  37512. diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
  37513. index 23ca7a5..b6c955d 100644
  37514. --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
  37515. +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
  37516. @@ -97,7 +97,6 @@ struct nouveau_drm {
  37517. struct drm_global_reference mem_global_ref;
  37518. struct ttm_bo_global_ref bo_global_ref;
  37519. struct ttm_bo_device bdev;
  37520. - atomic_t validate_sequence;
  37521. int (*move)(struct nouveau_channel *,
  37522. struct ttm_buffer_object *,
  37523. struct ttm_mem_reg *, struct ttm_mem_reg *);
  37524. diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
  37525. index c1a7e5a..38b8539 100644
  37526. --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
  37527. +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
  37528. @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
  37529. unsigned long arg)
  37530. {
  37531. unsigned int nr = DRM_IOCTL_NR(cmd);
  37532. - drm_ioctl_compat_t *fn = NULL;
  37533. + drm_ioctl_compat_t fn = NULL;
  37534. int ret;
  37535. if (nr < DRM_COMMAND_BASE)
  37536. diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
  37537. index d45d50d..72a5dd2 100644
  37538. --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
  37539. +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
  37540. @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
  37541. }
  37542. const struct ttm_mem_type_manager_func nouveau_vram_manager = {
  37543. - nouveau_vram_manager_init,
  37544. - nouveau_vram_manager_fini,
  37545. - nouveau_vram_manager_new,
  37546. - nouveau_vram_manager_del,
  37547. - nouveau_vram_manager_debug
  37548. + .init = nouveau_vram_manager_init,
  37549. + .takedown = nouveau_vram_manager_fini,
  37550. + .get_node = nouveau_vram_manager_new,
  37551. + .put_node = nouveau_vram_manager_del,
  37552. + .debug = nouveau_vram_manager_debug
  37553. };
  37554. static int
  37555. @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
  37556. }
  37557. const struct ttm_mem_type_manager_func nouveau_gart_manager = {
  37558. - nouveau_gart_manager_init,
  37559. - nouveau_gart_manager_fini,
  37560. - nouveau_gart_manager_new,
  37561. - nouveau_gart_manager_del,
  37562. - nouveau_gart_manager_debug
  37563. + .init = nouveau_gart_manager_init,
  37564. + .takedown = nouveau_gart_manager_fini,
  37565. + .get_node = nouveau_gart_manager_new,
  37566. + .put_node = nouveau_gart_manager_del,
  37567. + .debug = nouveau_gart_manager_debug
  37568. };
  37569. #include <core/subdev/vm/nv04.h>
  37570. @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
  37571. }
  37572. const struct ttm_mem_type_manager_func nv04_gart_manager = {
  37573. - nv04_gart_manager_init,
  37574. - nv04_gart_manager_fini,
  37575. - nv04_gart_manager_new,
  37576. - nv04_gart_manager_del,
  37577. - nv04_gart_manager_debug
  37578. + .init = nv04_gart_manager_init,
  37579. + .takedown = nv04_gart_manager_fini,
  37580. + .get_node = nv04_gart_manager_new,
  37581. + .put_node = nv04_gart_manager_del,
  37582. + .debug = nv04_gart_manager_debug
  37583. };
  37584. int
  37585. diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
  37586. index 471347e..5adc6b9 100644
  37587. --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
  37588. +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
  37589. @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
  37590. bool can_switch;
  37591. spin_lock(&dev->count_lock);
  37592. - can_switch = (dev->open_count == 0);
  37593. + can_switch = (local_read(&dev->open_count) == 0);
  37594. spin_unlock(&dev->count_lock);
  37595. return can_switch;
  37596. }
  37597. diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
  37598. index eb89653..613cf71 100644
  37599. --- a/drivers/gpu/drm/qxl/qxl_cmd.c
  37600. +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
  37601. @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
  37602. int ret;
  37603. mutex_lock(&qdev->async_io_mutex);
  37604. - irq_num = atomic_read(&qdev->irq_received_io_cmd);
  37605. + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
  37606. if (qdev->last_sent_io_cmd > irq_num) {
  37607. if (intr)
  37608. ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
  37609. - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37610. + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37611. else
  37612. ret = wait_event_timeout(qdev->io_cmd_event,
  37613. - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37614. + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37615. /* 0 is timeout, just bail the "hw" has gone away */
  37616. if (ret <= 0)
  37617. goto out;
  37618. - irq_num = atomic_read(&qdev->irq_received_io_cmd);
  37619. + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
  37620. }
  37621. outb(val, addr);
  37622. qdev->last_sent_io_cmd = irq_num + 1;
  37623. if (intr)
  37624. ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
  37625. - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37626. + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37627. else
  37628. ret = wait_event_timeout(qdev->io_cmd_event,
  37629. - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37630. + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
  37631. out:
  37632. if (ret > 0)
  37633. ret = 0;
  37634. diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
  37635. index c3c2bbd..bc3c0fb 100644
  37636. --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
  37637. +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
  37638. @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
  37639. struct drm_info_node *node = (struct drm_info_node *) m->private;
  37640. struct qxl_device *qdev = node->minor->dev->dev_private;
  37641. - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
  37642. - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
  37643. - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
  37644. - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
  37645. + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
  37646. + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
  37647. + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
  37648. + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
  37649. seq_printf(m, "%d\n", qdev->irq_received_error);
  37650. return 0;
  37651. }
  37652. diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
  37653. index 36ed40b..0397633 100644
  37654. --- a/drivers/gpu/drm/qxl/qxl_drv.h
  37655. +++ b/drivers/gpu/drm/qxl/qxl_drv.h
  37656. @@ -290,10 +290,10 @@ struct qxl_device {
  37657. unsigned int last_sent_io_cmd;
  37658. /* interrupt handling */
  37659. - atomic_t irq_received;
  37660. - atomic_t irq_received_display;
  37661. - atomic_t irq_received_cursor;
  37662. - atomic_t irq_received_io_cmd;
  37663. + atomic_unchecked_t irq_received;
  37664. + atomic_unchecked_t irq_received_display;
  37665. + atomic_unchecked_t irq_received_cursor;
  37666. + atomic_unchecked_t irq_received_io_cmd;
  37667. unsigned irq_received_error;
  37668. wait_queue_head_t display_event;
  37669. wait_queue_head_t cursor_event;
  37670. diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
  37671. index 0bb86e6..d41416d 100644
  37672. --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
  37673. +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
  37674. @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
  37675. /* TODO copy slow path code from i915 */
  37676. fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
  37677. - unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
  37678. + unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
  37679. {
  37680. struct qxl_drawable *draw = fb_cmd;
  37681. @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
  37682. struct drm_qxl_reloc reloc;
  37683. if (copy_from_user(&reloc,
  37684. - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
  37685. + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
  37686. sizeof(reloc))) {
  37687. ret = -EFAULT;
  37688. goto out_free_bos;
  37689. @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
  37690. for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
  37691. - struct drm_qxl_command *commands =
  37692. - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
  37693. + struct drm_qxl_command __user *commands =
  37694. + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
  37695. - if (copy_from_user(&user_cmd, &commands[cmd_num],
  37696. + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
  37697. sizeof(user_cmd)))
  37698. return -EFAULT;
  37699. diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
  37700. index 28f84b4..fb3e224 100644
  37701. --- a/drivers/gpu/drm/qxl/qxl_irq.c
  37702. +++ b/drivers/gpu/drm/qxl/qxl_irq.c
  37703. @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
  37704. pending = xchg(&qdev->ram_header->int_pending, 0);
  37705. - atomic_inc(&qdev->irq_received);
  37706. + atomic_inc_unchecked(&qdev->irq_received);
  37707. if (pending & QXL_INTERRUPT_DISPLAY) {
  37708. - atomic_inc(&qdev->irq_received_display);
  37709. + atomic_inc_unchecked(&qdev->irq_received_display);
  37710. wake_up_all(&qdev->display_event);
  37711. qxl_queue_garbage_collect(qdev, false);
  37712. }
  37713. if (pending & QXL_INTERRUPT_CURSOR) {
  37714. - atomic_inc(&qdev->irq_received_cursor);
  37715. + atomic_inc_unchecked(&qdev->irq_received_cursor);
  37716. wake_up_all(&qdev->cursor_event);
  37717. }
  37718. if (pending & QXL_INTERRUPT_IO_CMD) {
  37719. - atomic_inc(&qdev->irq_received_io_cmd);
  37720. + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
  37721. wake_up_all(&qdev->io_cmd_event);
  37722. }
  37723. if (pending & QXL_INTERRUPT_ERROR) {
  37724. @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
  37725. init_waitqueue_head(&qdev->io_cmd_event);
  37726. INIT_WORK(&qdev->client_monitors_config_work,
  37727. qxl_client_monitors_config_work_func);
  37728. - atomic_set(&qdev->irq_received, 0);
  37729. - atomic_set(&qdev->irq_received_display, 0);
  37730. - atomic_set(&qdev->irq_received_cursor, 0);
  37731. - atomic_set(&qdev->irq_received_io_cmd, 0);
  37732. + atomic_set_unchecked(&qdev->irq_received, 0);
  37733. + atomic_set_unchecked(&qdev->irq_received_display, 0);
  37734. + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
  37735. + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
  37736. qdev->irq_received_error = 0;
  37737. ret = drm_irq_install(qdev->ddev);
  37738. qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
  37739. diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
  37740. index c7e7e65..7dddd4d 100644
  37741. --- a/drivers/gpu/drm/qxl/qxl_ttm.c
  37742. +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
  37743. @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
  37744. }
  37745. }
  37746. -static struct vm_operations_struct qxl_ttm_vm_ops;
  37747. +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
  37748. static const struct vm_operations_struct *ttm_vm_ops;
  37749. static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  37750. @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
  37751. return r;
  37752. if (unlikely(ttm_vm_ops == NULL)) {
  37753. ttm_vm_ops = vma->vm_ops;
  37754. + pax_open_kernel();
  37755. qxl_ttm_vm_ops = *ttm_vm_ops;
  37756. qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
  37757. + pax_close_kernel();
  37758. }
  37759. vma->vm_ops = &qxl_ttm_vm_ops;
  37760. return 0;
  37761. @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
  37762. static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
  37763. {
  37764. #if defined(CONFIG_DEBUG_FS)
  37765. - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
  37766. - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
  37767. - unsigned i;
  37768. + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
  37769. + {
  37770. + .name = "qxl_mem_mm",
  37771. + .show = &qxl_mm_dump_table,
  37772. + },
  37773. + {
  37774. + .name = "qxl_surf_mm",
  37775. + .show = &qxl_mm_dump_table,
  37776. + }
  37777. + };
  37778. - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
  37779. - if (i == 0)
  37780. - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
  37781. - else
  37782. - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
  37783. - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
  37784. - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
  37785. - qxl_mem_types_list[i].driver_features = 0;
  37786. - if (i == 0)
  37787. - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
  37788. - else
  37789. - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
  37790. + pax_open_kernel();
  37791. + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
  37792. + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
  37793. + pax_close_kernel();
  37794. - }
  37795. - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
  37796. + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
  37797. #else
  37798. return 0;
  37799. #endif
  37800. diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
  37801. index 59459fe..be26b31 100644
  37802. --- a/drivers/gpu/drm/r128/r128_cce.c
  37803. +++ b/drivers/gpu/drm/r128/r128_cce.c
  37804. @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
  37805. /* GH: Simple idle check.
  37806. */
  37807. - atomic_set(&dev_priv->idle_count, 0);
  37808. + atomic_set_unchecked(&dev_priv->idle_count, 0);
  37809. /* We don't support anything other than bus-mastering ring mode,
  37810. * but the ring can be in either AGP or PCI space for the ring
  37811. diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
  37812. index 5bf3f5f..7000661 100644
  37813. --- a/drivers/gpu/drm/r128/r128_drv.h
  37814. +++ b/drivers/gpu/drm/r128/r128_drv.h
  37815. @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
  37816. int is_pci;
  37817. unsigned long cce_buffers_offset;
  37818. - atomic_t idle_count;
  37819. + atomic_unchecked_t idle_count;
  37820. int page_flipping;
  37821. int current_page;
  37822. u32 crtc_offset;
  37823. u32 crtc_offset_cntl;
  37824. - atomic_t vbl_received;
  37825. + atomic_unchecked_t vbl_received;
  37826. u32 color_fmt;
  37827. unsigned int front_offset;
  37828. diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
  37829. index b0d0fd3..a6fbbe4 100644
  37830. --- a/drivers/gpu/drm/r128/r128_ioc32.c
  37831. +++ b/drivers/gpu/drm/r128/r128_ioc32.c
  37832. @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
  37833. return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
  37834. }
  37835. -drm_ioctl_compat_t *r128_compat_ioctls[] = {
  37836. +drm_ioctl_compat_t r128_compat_ioctls[] = {
  37837. [DRM_R128_INIT] = compat_r128_init,
  37838. [DRM_R128_DEPTH] = compat_r128_depth,
  37839. [DRM_R128_STIPPLE] = compat_r128_stipple,
  37840. @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
  37841. long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  37842. {
  37843. unsigned int nr = DRM_IOCTL_NR(cmd);
  37844. - drm_ioctl_compat_t *fn = NULL;
  37845. int ret;
  37846. if (nr < DRM_COMMAND_BASE)
  37847. return drm_compat_ioctl(filp, cmd, arg);
  37848. - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
  37849. - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
  37850. -
  37851. - if (fn != NULL)
  37852. + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
  37853. + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
  37854. ret = (*fn) (filp, cmd, arg);
  37855. - else
  37856. + } else
  37857. ret = drm_ioctl(filp, cmd, arg);
  37858. return ret;
  37859. diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
  37860. index c2ae496..30b5993 100644
  37861. --- a/drivers/gpu/drm/r128/r128_irq.c
  37862. +++ b/drivers/gpu/drm/r128/r128_irq.c
  37863. @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
  37864. if (crtc != 0)
  37865. return 0;
  37866. - return atomic_read(&dev_priv->vbl_received);
  37867. + return atomic_read_unchecked(&dev_priv->vbl_received);
  37868. }
  37869. irqreturn_t r128_driver_irq_handler(int irq, void *arg)
  37870. @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
  37871. /* VBLANK interrupt */
  37872. if (status & R128_CRTC_VBLANK_INT) {
  37873. R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
  37874. - atomic_inc(&dev_priv->vbl_received);
  37875. + atomic_inc_unchecked(&dev_priv->vbl_received);
  37876. drm_handle_vblank(dev, 0);
  37877. return IRQ_HANDLED;
  37878. }
  37879. diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
  37880. index e806dac..f81d32f 100644
  37881. --- a/drivers/gpu/drm/r128/r128_state.c
  37882. +++ b/drivers/gpu/drm/r128/r128_state.c
  37883. @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
  37884. static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
  37885. {
  37886. - if (atomic_read(&dev_priv->idle_count) == 0)
  37887. + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
  37888. r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
  37889. else
  37890. - atomic_set(&dev_priv->idle_count, 0);
  37891. + atomic_set_unchecked(&dev_priv->idle_count, 0);
  37892. }
  37893. #endif
  37894. diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
  37895. index 4a85bb6..aaea819 100644
  37896. --- a/drivers/gpu/drm/radeon/mkregtable.c
  37897. +++ b/drivers/gpu/drm/radeon/mkregtable.c
  37898. @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
  37899. regex_t mask_rex;
  37900. regmatch_t match[4];
  37901. char buf[1024];
  37902. - size_t end;
  37903. + long end;
  37904. int len;
  37905. int done = 0;
  37906. int r;
  37907. unsigned o;
  37908. struct offset *offset;
  37909. char last_reg_s[10];
  37910. - int last_reg;
  37911. + unsigned long last_reg;
  37912. if (regcomp
  37913. (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
  37914. diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
  37915. index 044bc98..50ced9b 100644
  37916. --- a/drivers/gpu/drm/radeon/radeon_device.c
  37917. +++ b/drivers/gpu/drm/radeon/radeon_device.c
  37918. @@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
  37919. bool can_switch;
  37920. spin_lock(&dev->count_lock);
  37921. - can_switch = (dev->open_count == 0);
  37922. + can_switch = (local_read(&dev->open_count) == 0);
  37923. spin_unlock(&dev->count_lock);
  37924. return can_switch;
  37925. }
  37926. diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
  37927. index dafd812..1bf20c7 100644
  37928. --- a/drivers/gpu/drm/radeon/radeon_drv.h
  37929. +++ b/drivers/gpu/drm/radeon/radeon_drv.h
  37930. @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
  37931. /* SW interrupt */
  37932. wait_queue_head_t swi_queue;
  37933. - atomic_t swi_emitted;
  37934. + atomic_unchecked_t swi_emitted;
  37935. int vblank_crtc;
  37936. uint32_t irq_enable_reg;
  37937. uint32_t r500_disp_irq_reg;
  37938. diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
  37939. index bdb0f93..5ff558f 100644
  37940. --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
  37941. +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
  37942. @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
  37943. request = compat_alloc_user_space(sizeof(*request));
  37944. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  37945. || __put_user(req32.param, &request->param)
  37946. - || __put_user((void __user *)(unsigned long)req32.value,
  37947. + || __put_user((unsigned long)req32.value,
  37948. &request->value))
  37949. return -EFAULT;
  37950. @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
  37951. #define compat_radeon_cp_setparam NULL
  37952. #endif /* X86_64 || IA64 */
  37953. -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
  37954. +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
  37955. [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
  37956. [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
  37957. [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
  37958. @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
  37959. long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  37960. {
  37961. unsigned int nr = DRM_IOCTL_NR(cmd);
  37962. - drm_ioctl_compat_t *fn = NULL;
  37963. int ret;
  37964. if (nr < DRM_COMMAND_BASE)
  37965. return drm_compat_ioctl(filp, cmd, arg);
  37966. - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
  37967. - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
  37968. -
  37969. - if (fn != NULL)
  37970. + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
  37971. + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
  37972. ret = (*fn) (filp, cmd, arg);
  37973. - else
  37974. + } else
  37975. ret = drm_ioctl(filp, cmd, arg);
  37976. return ret;
  37977. diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
  37978. index 244b19b..c19226d 100644
  37979. --- a/drivers/gpu/drm/radeon/radeon_irq.c
  37980. +++ b/drivers/gpu/drm/radeon/radeon_irq.c
  37981. @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
  37982. unsigned int ret;
  37983. RING_LOCALS;
  37984. - atomic_inc(&dev_priv->swi_emitted);
  37985. - ret = atomic_read(&dev_priv->swi_emitted);
  37986. + atomic_inc_unchecked(&dev_priv->swi_emitted);
  37987. + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
  37988. BEGIN_RING(4);
  37989. OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
  37990. @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
  37991. drm_radeon_private_t *dev_priv =
  37992. (drm_radeon_private_t *) dev->dev_private;
  37993. - atomic_set(&dev_priv->swi_emitted, 0);
  37994. + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
  37995. init_waitqueue_head(&dev_priv->swi_queue);
  37996. dev->max_vblank_count = 0x001fffff;
  37997. diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
  37998. index 956ab7f..fbd36d8 100644
  37999. --- a/drivers/gpu/drm/radeon/radeon_state.c
  38000. +++ b/drivers/gpu/drm/radeon/radeon_state.c
  38001. @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
  38002. if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
  38003. sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
  38004. - if (copy_from_user(&depth_boxes, clear->depth_boxes,
  38005. + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
  38006. sarea_priv->nbox * sizeof(depth_boxes[0])))
  38007. return -EFAULT;
  38008. @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
  38009. {
  38010. drm_radeon_private_t *dev_priv = dev->dev_private;
  38011. drm_radeon_getparam_t *param = data;
  38012. - int value;
  38013. + int value = 0;
  38014. DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
  38015. diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
  38016. index 040a2a1..eae4e54 100644
  38017. --- a/drivers/gpu/drm/radeon/radeon_ttm.c
  38018. +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
  38019. @@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
  38020. man->size = size >> PAGE_SHIFT;
  38021. }
  38022. -static struct vm_operations_struct radeon_ttm_vm_ops;
  38023. +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
  38024. static const struct vm_operations_struct *ttm_vm_ops = NULL;
  38025. static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  38026. @@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
  38027. }
  38028. if (unlikely(ttm_vm_ops == NULL)) {
  38029. ttm_vm_ops = vma->vm_ops;
  38030. + pax_open_kernel();
  38031. radeon_ttm_vm_ops = *ttm_vm_ops;
  38032. radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
  38033. + pax_close_kernel();
  38034. }
  38035. vma->vm_ops = &radeon_ttm_vm_ops;
  38036. return 0;
  38037. diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
  38038. index 9336006..ce78aa7 100644
  38039. --- a/drivers/gpu/drm/tegra/dc.c
  38040. +++ b/drivers/gpu/drm/tegra/dc.c
  38041. @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
  38042. }
  38043. for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
  38044. - dc->debugfs_files[i].data = dc;
  38045. + *(void **)&dc->debugfs_files[i].data = dc;
  38046. err = drm_debugfs_create_files(dc->debugfs_files,
  38047. ARRAY_SIZE(debugfs_files),
  38048. diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
  38049. index d452faab..f8cbc6a 100644
  38050. --- a/drivers/gpu/drm/tegra/dsi.c
  38051. +++ b/drivers/gpu/drm/tegra/dsi.c
  38052. @@ -53,7 +53,7 @@ struct tegra_dsi {
  38053. struct clk *clk_lp;
  38054. struct clk *clk;
  38055. - struct drm_info_list *debugfs_files;
  38056. + drm_info_list_no_const *debugfs_files;
  38057. struct drm_minor *minor;
  38058. struct dentry *debugfs;
  38059. diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
  38060. index 6928015..c9853e7 100644
  38061. --- a/drivers/gpu/drm/tegra/hdmi.c
  38062. +++ b/drivers/gpu/drm/tegra/hdmi.c
  38063. @@ -59,7 +59,7 @@ struct tegra_hdmi {
  38064. bool stereo;
  38065. bool dvi;
  38066. - struct drm_info_list *debugfs_files;
  38067. + drm_info_list_no_const *debugfs_files;
  38068. struct drm_minor *minor;
  38069. struct dentry *debugfs;
  38070. };
  38071. diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
  38072. index c58eba33..83c2728 100644
  38073. --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
  38074. +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
  38075. @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
  38076. }
  38077. const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
  38078. - ttm_bo_man_init,
  38079. - ttm_bo_man_takedown,
  38080. - ttm_bo_man_get_node,
  38081. - ttm_bo_man_put_node,
  38082. - ttm_bo_man_debug
  38083. + .init = ttm_bo_man_init,
  38084. + .takedown = ttm_bo_man_takedown,
  38085. + .get_node = ttm_bo_man_get_node,
  38086. + .put_node = ttm_bo_man_put_node,
  38087. + .debug = ttm_bo_man_debug
  38088. };
  38089. EXPORT_SYMBOL(ttm_bo_manager_func);
  38090. diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
  38091. index dbc2def..0a9f710 100644
  38092. --- a/drivers/gpu/drm/ttm/ttm_memory.c
  38093. +++ b/drivers/gpu/drm/ttm/ttm_memory.c
  38094. @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
  38095. zone->glob = glob;
  38096. glob->zone_kernel = zone;
  38097. ret = kobject_init_and_add(
  38098. - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
  38099. + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
  38100. if (unlikely(ret != 0)) {
  38101. kobject_put(&zone->kobj);
  38102. return ret;
  38103. @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
  38104. zone->glob = glob;
  38105. glob->zone_dma32 = zone;
  38106. ret = kobject_init_and_add(
  38107. - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
  38108. + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
  38109. if (unlikely(ret != 0)) {
  38110. kobject_put(&zone->kobj);
  38111. return ret;
  38112. diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
  38113. index 863bef9..cba15cf 100644
  38114. --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
  38115. +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
  38116. @@ -391,9 +391,9 @@ out:
  38117. static unsigned long
  38118. ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
  38119. {
  38120. - static atomic_t start_pool = ATOMIC_INIT(0);
  38121. + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
  38122. unsigned i;
  38123. - unsigned pool_offset = atomic_add_return(1, &start_pool);
  38124. + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
  38125. struct ttm_page_pool *pool;
  38126. int shrink_pages = sc->nr_to_scan;
  38127. unsigned long freed = 0;
  38128. diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
  38129. index dbadd49..1b7457b 100644
  38130. --- a/drivers/gpu/drm/udl/udl_fb.c
  38131. +++ b/drivers/gpu/drm/udl/udl_fb.c
  38132. @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
  38133. fb_deferred_io_cleanup(info);
  38134. kfree(info->fbdefio);
  38135. info->fbdefio = NULL;
  38136. - info->fbops->fb_mmap = udl_fb_mmap;
  38137. }
  38138. pr_warn("released /dev/fb%d user=%d count=%d\n",
  38139. diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
  38140. index ad02732..144f5ed 100644
  38141. --- a/drivers/gpu/drm/via/via_drv.h
  38142. +++ b/drivers/gpu/drm/via/via_drv.h
  38143. @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
  38144. typedef uint32_t maskarray_t[5];
  38145. typedef struct drm_via_irq {
  38146. - atomic_t irq_received;
  38147. + atomic_unchecked_t irq_received;
  38148. uint32_t pending_mask;
  38149. uint32_t enable_mask;
  38150. wait_queue_head_t irq_queue;
  38151. @@ -75,7 +75,7 @@ typedef struct drm_via_private {
  38152. struct timeval last_vblank;
  38153. int last_vblank_valid;
  38154. unsigned usec_per_vblank;
  38155. - atomic_t vbl_received;
  38156. + atomic_unchecked_t vbl_received;
  38157. drm_via_state_t hc_state;
  38158. char pci_buf[VIA_PCI_BUF_SIZE];
  38159. const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
  38160. diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
  38161. index 1319433..a993b0c 100644
  38162. --- a/drivers/gpu/drm/via/via_irq.c
  38163. +++ b/drivers/gpu/drm/via/via_irq.c
  38164. @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
  38165. if (crtc != 0)
  38166. return 0;
  38167. - return atomic_read(&dev_priv->vbl_received);
  38168. + return atomic_read_unchecked(&dev_priv->vbl_received);
  38169. }
  38170. irqreturn_t via_driver_irq_handler(int irq, void *arg)
  38171. @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
  38172. status = VIA_READ(VIA_REG_INTERRUPT);
  38173. if (status & VIA_IRQ_VBLANK_PENDING) {
  38174. - atomic_inc(&dev_priv->vbl_received);
  38175. - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
  38176. + atomic_inc_unchecked(&dev_priv->vbl_received);
  38177. + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
  38178. do_gettimeofday(&cur_vblank);
  38179. if (dev_priv->last_vblank_valid) {
  38180. dev_priv->usec_per_vblank =
  38181. @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
  38182. dev_priv->last_vblank = cur_vblank;
  38183. dev_priv->last_vblank_valid = 1;
  38184. }
  38185. - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
  38186. + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
  38187. DRM_DEBUG("US per vblank is: %u\n",
  38188. dev_priv->usec_per_vblank);
  38189. }
  38190. @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
  38191. for (i = 0; i < dev_priv->num_irqs; ++i) {
  38192. if (status & cur_irq->pending_mask) {
  38193. - atomic_inc(&cur_irq->irq_received);
  38194. + atomic_inc_unchecked(&cur_irq->irq_received);
  38195. wake_up(&cur_irq->irq_queue);
  38196. handled = 1;
  38197. if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
  38198. @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
  38199. DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
  38200. ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
  38201. masks[irq][4]));
  38202. - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
  38203. + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
  38204. } else {
  38205. DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
  38206. (((cur_irq_sequence =
  38207. - atomic_read(&cur_irq->irq_received)) -
  38208. + atomic_read_unchecked(&cur_irq->irq_received)) -
  38209. *sequence) <= (1 << 23)));
  38210. }
  38211. *sequence = cur_irq_sequence;
  38212. @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
  38213. }
  38214. for (i = 0; i < dev_priv->num_irqs; ++i) {
  38215. - atomic_set(&cur_irq->irq_received, 0);
  38216. + atomic_set_unchecked(&cur_irq->irq_received, 0);
  38217. cur_irq->enable_mask = dev_priv->irq_masks[i][0];
  38218. cur_irq->pending_mask = dev_priv->irq_masks[i][1];
  38219. init_waitqueue_head(&cur_irq->irq_queue);
  38220. @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
  38221. switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
  38222. case VIA_IRQ_RELATIVE:
  38223. irqwait->request.sequence +=
  38224. - atomic_read(&cur_irq->irq_received);
  38225. + atomic_read_unchecked(&cur_irq->irq_received);
  38226. irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
  38227. case VIA_IRQ_ABSOLUTE:
  38228. break;
  38229. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
  38230. index 0783155..b29e18e 100644
  38231. --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
  38232. +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
  38233. @@ -437,7 +437,7 @@ struct vmw_private {
  38234. * Fencing and IRQs.
  38235. */
  38236. - atomic_t marker_seq;
  38237. + atomic_unchecked_t marker_seq;
  38238. wait_queue_head_t fence_queue;
  38239. wait_queue_head_t fifo_queue;
  38240. int fence_queue_waiters; /* Protected by hw_mutex */
  38241. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
  38242. index 6ccd993..618d592 100644
  38243. --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
  38244. +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
  38245. @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
  38246. (unsigned int) min,
  38247. (unsigned int) fifo->capabilities);
  38248. - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
  38249. + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
  38250. iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
  38251. vmw_marker_queue_init(&fifo->marker_queue);
  38252. return vmw_fifo_send_fence(dev_priv, &dummy);
  38253. @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
  38254. if (reserveable)
  38255. iowrite32(bytes, fifo_mem +
  38256. SVGA_FIFO_RESERVED);
  38257. - return fifo_mem + (next_cmd >> 2);
  38258. + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
  38259. } else {
  38260. need_bounce = true;
  38261. }
  38262. @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
  38263. fm = vmw_fifo_reserve(dev_priv, bytes);
  38264. if (unlikely(fm == NULL)) {
  38265. - *seqno = atomic_read(&dev_priv->marker_seq);
  38266. + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
  38267. ret = -ENOMEM;
  38268. (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
  38269. false, 3*HZ);
  38270. @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
  38271. }
  38272. do {
  38273. - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
  38274. + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
  38275. } while (*seqno == 0);
  38276. if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
  38277. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
  38278. index b1273e8..9c274fd 100644
  38279. --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
  38280. +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
  38281. @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
  38282. }
  38283. const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
  38284. - vmw_gmrid_man_init,
  38285. - vmw_gmrid_man_takedown,
  38286. - vmw_gmrid_man_get_node,
  38287. - vmw_gmrid_man_put_node,
  38288. - vmw_gmrid_man_debug
  38289. + .init = vmw_gmrid_man_init,
  38290. + .takedown = vmw_gmrid_man_takedown,
  38291. + .get_node = vmw_gmrid_man_get_node,
  38292. + .put_node = vmw_gmrid_man_put_node,
  38293. + .debug = vmw_gmrid_man_debug
  38294. };
  38295. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
  38296. index 47b7094..698ba09 100644
  38297. --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
  38298. +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
  38299. @@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
  38300. int ret;
  38301. num_clips = arg->num_clips;
  38302. - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
  38303. + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
  38304. if (unlikely(num_clips == 0))
  38305. return 0;
  38306. @@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  38307. int ret;
  38308. num_clips = arg->num_clips;
  38309. - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
  38310. + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
  38311. if (unlikely(num_clips == 0))
  38312. return 0;
  38313. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
  38314. index 0c42376..6febe77 100644
  38315. --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
  38316. +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
  38317. @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
  38318. * emitted. Then the fence is stale and signaled.
  38319. */
  38320. - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
  38321. + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
  38322. > VMW_FENCE_WRAP);
  38323. return ret;
  38324. @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
  38325. if (fifo_idle)
  38326. down_read(&fifo_state->rwsem);
  38327. - signal_seq = atomic_read(&dev_priv->marker_seq);
  38328. + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
  38329. ret = 0;
  38330. for (;;) {
  38331. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
  38332. index 8a8725c2..afed796 100644
  38333. --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
  38334. +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
  38335. @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
  38336. while (!vmw_lag_lt(queue, us)) {
  38337. spin_lock(&queue->lock);
  38338. if (list_empty(&queue->head))
  38339. - seqno = atomic_read(&dev_priv->marker_seq);
  38340. + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
  38341. else {
  38342. marker = list_first_entry(&queue->head,
  38343. struct vmw_marker, head);
  38344. diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
  38345. index ec0ae2d..dc0780b 100644
  38346. --- a/drivers/gpu/vga/vga_switcheroo.c
  38347. +++ b/drivers/gpu/vga/vga_switcheroo.c
  38348. @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
  38349. /* this version is for the case where the power switch is separate
  38350. to the device being powered down. */
  38351. -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
  38352. +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
  38353. {
  38354. /* copy over all the bus versions */
  38355. if (dev->bus && dev->bus->pm) {
  38356. @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
  38357. return ret;
  38358. }
  38359. -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
  38360. +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
  38361. {
  38362. /* copy over all the bus versions */
  38363. if (dev->bus && dev->bus->pm) {
  38364. diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
  38365. index cc32a6f..02a4b1c 100644
  38366. --- a/drivers/hid/hid-core.c
  38367. +++ b/drivers/hid/hid-core.c
  38368. @@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
  38369. int hid_add_device(struct hid_device *hdev)
  38370. {
  38371. - static atomic_t id = ATOMIC_INIT(0);
  38372. + static atomic_unchecked_t id = ATOMIC_INIT(0);
  38373. int ret;
  38374. if (WARN_ON(hdev->status & HID_STAT_ADDED))
  38375. @@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
  38376. /* XXX hack, any other cleaner solution after the driver core
  38377. * is converted to allow more than 20 bytes as the device name? */
  38378. dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
  38379. - hdev->vendor, hdev->product, atomic_inc_return(&id));
  38380. + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
  38381. hid_debug_register(hdev, dev_name(&hdev->dev));
  38382. ret = device_add(&hdev->dev);
  38383. diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
  38384. index c13fb5b..55a3802 100644
  38385. --- a/drivers/hid/hid-wiimote-debug.c
  38386. +++ b/drivers/hid/hid-wiimote-debug.c
  38387. @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
  38388. else if (size == 0)
  38389. return -EIO;
  38390. - if (copy_to_user(u, buf, size))
  38391. + if (size > sizeof(buf) || copy_to_user(u, buf, size))
  38392. return -EFAULT;
  38393. *off += size;
  38394. diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
  38395. index cedc6da..2c3da2a 100644
  38396. --- a/drivers/hid/uhid.c
  38397. +++ b/drivers/hid/uhid.c
  38398. @@ -47,7 +47,7 @@ struct uhid_device {
  38399. struct mutex report_lock;
  38400. wait_queue_head_t report_wait;
  38401. atomic_t report_done;
  38402. - atomic_t report_id;
  38403. + atomic_unchecked_t report_id;
  38404. struct uhid_event report_buf;
  38405. };
  38406. @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
  38407. spin_lock_irqsave(&uhid->qlock, flags);
  38408. ev->type = UHID_FEATURE;
  38409. - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
  38410. + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
  38411. ev->u.feature.rnum = rnum;
  38412. ev->u.feature.rtype = report_type;
  38413. @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
  38414. spin_lock_irqsave(&uhid->qlock, flags);
  38415. /* id for old report; drop it silently */
  38416. - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
  38417. + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
  38418. goto unlock;
  38419. if (atomic_read(&uhid->report_done))
  38420. goto unlock;
  38421. diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
  38422. index 69ea36f..8dbf4bb 100644
  38423. --- a/drivers/hv/channel.c
  38424. +++ b/drivers/hv/channel.c
  38425. @@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
  38426. int ret = 0;
  38427. int t;
  38428. - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
  38429. - atomic_inc(&vmbus_connection.next_gpadl_handle);
  38430. + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
  38431. + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
  38432. ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
  38433. if (ret)
  38434. diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
  38435. index bcb4950..61dba6c 100644
  38436. --- a/drivers/hv/hv.c
  38437. +++ b/drivers/hv/hv.c
  38438. @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
  38439. u64 output_address = (output) ? virt_to_phys(output) : 0;
  38440. u32 output_address_hi = output_address >> 32;
  38441. u32 output_address_lo = output_address & 0xFFFFFFFF;
  38442. - void *hypercall_page = hv_context.hypercall_page;
  38443. + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
  38444. __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
  38445. "=a"(hv_status_lo) : "d" (control_hi),
  38446. @@ -154,7 +154,7 @@ int hv_init(void)
  38447. /* See if the hypercall page is already set */
  38448. rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
  38449. - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
  38450. + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
  38451. if (!virtaddr)
  38452. goto cleanup;
  38453. diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
  38454. index 7e17a54..a50a33d 100644
  38455. --- a/drivers/hv/hv_balloon.c
  38456. +++ b/drivers/hv/hv_balloon.c
  38457. @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
  38458. module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
  38459. MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
  38460. -static atomic_t trans_id = ATOMIC_INIT(0);
  38461. +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
  38462. static int dm_ring_size = (5 * PAGE_SIZE);
  38463. @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
  38464. pr_info("Memory hot add failed\n");
  38465. dm->state = DM_INITIALIZED;
  38466. - resp.hdr.trans_id = atomic_inc_return(&trans_id);
  38467. + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38468. vmbus_sendpacket(dm->dev->channel, &resp,
  38469. sizeof(struct dm_hot_add_response),
  38470. (unsigned long)NULL,
  38471. @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
  38472. memset(&status, 0, sizeof(struct dm_status));
  38473. status.hdr.type = DM_STATUS_REPORT;
  38474. status.hdr.size = sizeof(struct dm_status);
  38475. - status.hdr.trans_id = atomic_inc_return(&trans_id);
  38476. + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38477. /*
  38478. * The host expects the guest to report free memory.
  38479. @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
  38480. * send the status. This can happen if we were interrupted
  38481. * after we picked our transaction ID.
  38482. */
  38483. - if (status.hdr.trans_id != atomic_read(&trans_id))
  38484. + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
  38485. return;
  38486. vmbus_sendpacket(dm->dev->channel, &status,
  38487. @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
  38488. */
  38489. do {
  38490. - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
  38491. + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38492. ret = vmbus_sendpacket(dm_device.dev->channel,
  38493. bl_resp,
  38494. bl_resp->hdr.size,
  38495. @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
  38496. memset(&resp, 0, sizeof(struct dm_unballoon_response));
  38497. resp.hdr.type = DM_UNBALLOON_RESPONSE;
  38498. - resp.hdr.trans_id = atomic_inc_return(&trans_id);
  38499. + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38500. resp.hdr.size = sizeof(struct dm_unballoon_response);
  38501. vmbus_sendpacket(dm_device.dev->channel, &resp,
  38502. @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
  38503. memset(&version_req, 0, sizeof(struct dm_version_request));
  38504. version_req.hdr.type = DM_VERSION_REQUEST;
  38505. version_req.hdr.size = sizeof(struct dm_version_request);
  38506. - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
  38507. + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38508. version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
  38509. version_req.is_last_attempt = 1;
  38510. @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
  38511. memset(&version_req, 0, sizeof(struct dm_version_request));
  38512. version_req.hdr.type = DM_VERSION_REQUEST;
  38513. version_req.hdr.size = sizeof(struct dm_version_request);
  38514. - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
  38515. + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38516. version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
  38517. version_req.is_last_attempt = 0;
  38518. @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
  38519. memset(&cap_msg, 0, sizeof(struct dm_capabilities));
  38520. cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
  38521. cap_msg.hdr.size = sizeof(struct dm_capabilities);
  38522. - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
  38523. + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
  38524. cap_msg.caps.cap_bits.balloon = 1;
  38525. cap_msg.caps.cap_bits.hot_add = 1;
  38526. diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
  38527. index e055176..c22ff1f 100644
  38528. --- a/drivers/hv/hyperv_vmbus.h
  38529. +++ b/drivers/hv/hyperv_vmbus.h
  38530. @@ -602,7 +602,7 @@ enum vmbus_connect_state {
  38531. struct vmbus_connection {
  38532. enum vmbus_connect_state conn_state;
  38533. - atomic_t next_gpadl_handle;
  38534. + atomic_unchecked_t next_gpadl_handle;
  38535. /*
  38536. * Represents channel interrupts. Each bit position represents a
  38537. diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
  38538. index 077bb1b..d433d74 100644
  38539. --- a/drivers/hv/vmbus_drv.c
  38540. +++ b/drivers/hv/vmbus_drv.c
  38541. @@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
  38542. {
  38543. int ret = 0;
  38544. - static atomic_t device_num = ATOMIC_INIT(0);
  38545. + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
  38546. dev_set_name(&child_device_obj->device, "vmbus_0_%d",
  38547. - atomic_inc_return(&device_num));
  38548. + atomic_inc_return_unchecked(&device_num));
  38549. child_device_obj->device.bus = &hv_bus;
  38550. child_device_obj->device.parent = &hv_acpi_dev->dev;
  38551. diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
  38552. index 579bdf9..75118b5 100644
  38553. --- a/drivers/hwmon/acpi_power_meter.c
  38554. +++ b/drivers/hwmon/acpi_power_meter.c
  38555. @@ -116,7 +116,7 @@ struct sensor_template {
  38556. struct device_attribute *devattr,
  38557. const char *buf, size_t count);
  38558. int index;
  38559. -};
  38560. +} __do_const;
  38561. /* Averaging interval */
  38562. static int update_avg_interval(struct acpi_power_meter_resource *resource)
  38563. @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
  38564. struct sensor_template *attrs)
  38565. {
  38566. struct device *dev = &resource->acpi_dev->dev;
  38567. - struct sensor_device_attribute *sensors =
  38568. + sensor_device_attribute_no_const *sensors =
  38569. &resource->sensors[resource->num_sensors];
  38570. int res = 0;
  38571. diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
  38572. index 3288f13..71cfb4e 100644
  38573. --- a/drivers/hwmon/applesmc.c
  38574. +++ b/drivers/hwmon/applesmc.c
  38575. @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
  38576. {
  38577. struct applesmc_node_group *grp;
  38578. struct applesmc_dev_attr *node;
  38579. - struct attribute *attr;
  38580. + attribute_no_const *attr;
  38581. int ret, i;
  38582. for (grp = groups; grp->format; grp++) {
  38583. diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
  38584. index ae208f6..48b6c5b 100644
  38585. --- a/drivers/hwmon/asus_atk0110.c
  38586. +++ b/drivers/hwmon/asus_atk0110.c
  38587. @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
  38588. struct atk_sensor_data {
  38589. struct list_head list;
  38590. struct atk_data *data;
  38591. - struct device_attribute label_attr;
  38592. - struct device_attribute input_attr;
  38593. - struct device_attribute limit1_attr;
  38594. - struct device_attribute limit2_attr;
  38595. + device_attribute_no_const label_attr;
  38596. + device_attribute_no_const input_attr;
  38597. + device_attribute_no_const limit1_attr;
  38598. + device_attribute_no_const limit2_attr;
  38599. char label_attr_name[ATTR_NAME_SIZE];
  38600. char input_attr_name[ATTR_NAME_SIZE];
  38601. char limit1_attr_name[ATTR_NAME_SIZE];
  38602. @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
  38603. static struct device_attribute atk_name_attr =
  38604. __ATTR(name, 0444, atk_name_show, NULL);
  38605. -static void atk_init_attribute(struct device_attribute *attr, char *name,
  38606. +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
  38607. sysfs_show_func show)
  38608. {
  38609. sysfs_attr_init(&attr->attr);
  38610. diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
  38611. index bbb0b0d..9fe1332 100644
  38612. --- a/drivers/hwmon/coretemp.c
  38613. +++ b/drivers/hwmon/coretemp.c
  38614. @@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
  38615. return NOTIFY_OK;
  38616. }
  38617. -static struct notifier_block coretemp_cpu_notifier __refdata = {
  38618. +static struct notifier_block coretemp_cpu_notifier = {
  38619. .notifier_call = coretemp_cpu_callback,
  38620. };
  38621. diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
  38622. index 632f1dc..57e6a58 100644
  38623. --- a/drivers/hwmon/ibmaem.c
  38624. +++ b/drivers/hwmon/ibmaem.c
  38625. @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
  38626. struct aem_rw_sensor_template *rw)
  38627. {
  38628. struct device *dev = &data->pdev->dev;
  38629. - struct sensor_device_attribute *sensors = data->sensors;
  38630. + sensor_device_attribute_no_const *sensors = data->sensors;
  38631. int err;
  38632. /* Set up read-only sensors */
  38633. diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
  38634. index 708081b..fe2d4ab 100644
  38635. --- a/drivers/hwmon/iio_hwmon.c
  38636. +++ b/drivers/hwmon/iio_hwmon.c
  38637. @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
  38638. {
  38639. struct device *dev = &pdev->dev;
  38640. struct iio_hwmon_state *st;
  38641. - struct sensor_device_attribute *a;
  38642. + sensor_device_attribute_no_const *a;
  38643. int ret, i;
  38644. int in_i = 1, temp_i = 1, curr_i = 1;
  38645. enum iio_chan_type type;
  38646. diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
  38647. index 38d5a63..cf2c2ea 100644
  38648. --- a/drivers/hwmon/nct6775.c
  38649. +++ b/drivers/hwmon/nct6775.c
  38650. @@ -944,10 +944,10 @@ static struct attribute_group *
  38651. nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
  38652. int repeat)
  38653. {
  38654. - struct attribute_group *group;
  38655. + attribute_group_no_const *group;
  38656. struct sensor_device_attr_u *su;
  38657. - struct sensor_device_attribute *a;
  38658. - struct sensor_device_attribute_2 *a2;
  38659. + sensor_device_attribute_no_const *a;
  38660. + sensor_device_attribute_2_no_const *a2;
  38661. struct attribute **attrs;
  38662. struct sensor_device_template **t;
  38663. int i, count;
  38664. diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
  38665. index 291d11f..3f0dbbd 100644
  38666. --- a/drivers/hwmon/pmbus/pmbus_core.c
  38667. +++ b/drivers/hwmon/pmbus/pmbus_core.c
  38668. @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
  38669. return 0;
  38670. }
  38671. -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
  38672. +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
  38673. const char *name,
  38674. umode_t mode,
  38675. ssize_t (*show)(struct device *dev,
  38676. @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
  38677. dev_attr->store = store;
  38678. }
  38679. -static void pmbus_attr_init(struct sensor_device_attribute *a,
  38680. +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
  38681. const char *name,
  38682. umode_t mode,
  38683. ssize_t (*show)(struct device *dev,
  38684. @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
  38685. u16 reg, u8 mask)
  38686. {
  38687. struct pmbus_boolean *boolean;
  38688. - struct sensor_device_attribute *a;
  38689. + sensor_device_attribute_no_const *a;
  38690. boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
  38691. if (!boolean)
  38692. @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
  38693. bool update, bool readonly)
  38694. {
  38695. struct pmbus_sensor *sensor;
  38696. - struct device_attribute *a;
  38697. + device_attribute_no_const *a;
  38698. sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
  38699. if (!sensor)
  38700. @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
  38701. const char *lstring, int index)
  38702. {
  38703. struct pmbus_label *label;
  38704. - struct device_attribute *a;
  38705. + device_attribute_no_const *a;
  38706. label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
  38707. if (!label)
  38708. diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
  38709. index 97cd45a..ac54d8b 100644
  38710. --- a/drivers/hwmon/sht15.c
  38711. +++ b/drivers/hwmon/sht15.c
  38712. @@ -169,7 +169,7 @@ struct sht15_data {
  38713. int supply_uv;
  38714. bool supply_uv_valid;
  38715. struct work_struct update_supply_work;
  38716. - atomic_t interrupt_handled;
  38717. + atomic_unchecked_t interrupt_handled;
  38718. };
  38719. /**
  38720. @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
  38721. ret = gpio_direction_input(data->pdata->gpio_data);
  38722. if (ret)
  38723. return ret;
  38724. - atomic_set(&data->interrupt_handled, 0);
  38725. + atomic_set_unchecked(&data->interrupt_handled, 0);
  38726. enable_irq(gpio_to_irq(data->pdata->gpio_data));
  38727. if (gpio_get_value(data->pdata->gpio_data) == 0) {
  38728. disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
  38729. /* Only relevant if the interrupt hasn't occurred. */
  38730. - if (!atomic_read(&data->interrupt_handled))
  38731. + if (!atomic_read_unchecked(&data->interrupt_handled))
  38732. schedule_work(&data->read_work);
  38733. }
  38734. ret = wait_event_timeout(data->wait_queue,
  38735. @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
  38736. /* First disable the interrupt */
  38737. disable_irq_nosync(irq);
  38738. - atomic_inc(&data->interrupt_handled);
  38739. + atomic_inc_unchecked(&data->interrupt_handled);
  38740. /* Then schedule a reading work struct */
  38741. if (data->state != SHT15_READING_NOTHING)
  38742. schedule_work(&data->read_work);
  38743. @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
  38744. * If not, then start the interrupt again - care here as could
  38745. * have gone low in meantime so verify it hasn't!
  38746. */
  38747. - atomic_set(&data->interrupt_handled, 0);
  38748. + atomic_set_unchecked(&data->interrupt_handled, 0);
  38749. enable_irq(gpio_to_irq(data->pdata->gpio_data));
  38750. /* If still not occurred or another handler was scheduled */
  38751. if (gpio_get_value(data->pdata->gpio_data)
  38752. - || atomic_read(&data->interrupt_handled))
  38753. + || atomic_read_unchecked(&data->interrupt_handled))
  38754. return;
  38755. }
  38756. diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
  38757. index 38944e9..ae9e5ed 100644
  38758. --- a/drivers/hwmon/via-cputemp.c
  38759. +++ b/drivers/hwmon/via-cputemp.c
  38760. @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
  38761. return NOTIFY_OK;
  38762. }
  38763. -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
  38764. +static struct notifier_block via_cputemp_cpu_notifier = {
  38765. .notifier_call = via_cputemp_cpu_callback,
  38766. };
  38767. diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
  38768. index 41fc683..a39cfea 100644
  38769. --- a/drivers/i2c/busses/i2c-amd756-s4882.c
  38770. +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
  38771. @@ -43,7 +43,7 @@
  38772. extern struct i2c_adapter amd756_smbus;
  38773. static struct i2c_adapter *s4882_adapter;
  38774. -static struct i2c_algorithm *s4882_algo;
  38775. +static i2c_algorithm_no_const *s4882_algo;
  38776. /* Wrapper access functions for multiplexed SMBus */
  38777. static DEFINE_MUTEX(amd756_lock);
  38778. diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
  38779. index 721f7eb..0fd2a09 100644
  38780. --- a/drivers/i2c/busses/i2c-diolan-u2c.c
  38781. +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
  38782. @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
  38783. /* usb layer */
  38784. /* Send command to device, and get response. */
  38785. -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
  38786. +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
  38787. {
  38788. int ret = 0;
  38789. int actual;
  38790. diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
  38791. index b170bdf..3c76427 100644
  38792. --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
  38793. +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
  38794. @@ -41,7 +41,7 @@
  38795. extern struct i2c_adapter *nforce2_smbus;
  38796. static struct i2c_adapter *s4985_adapter;
  38797. -static struct i2c_algorithm *s4985_algo;
  38798. +static i2c_algorithm_no_const *s4985_algo;
  38799. /* Wrapper access functions for multiplexed SMBus */
  38800. static DEFINE_MUTEX(nforce2_lock);
  38801. diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
  38802. index 80b47e8..1a6040d9 100644
  38803. --- a/drivers/i2c/i2c-dev.c
  38804. +++ b/drivers/i2c/i2c-dev.c
  38805. @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
  38806. break;
  38807. }
  38808. - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
  38809. + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
  38810. rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
  38811. if (IS_ERR(rdwr_pa[i].buf)) {
  38812. res = PTR_ERR(rdwr_pa[i].buf);
  38813. diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
  38814. index 0b510ba..4fbb5085 100644
  38815. --- a/drivers/ide/ide-cd.c
  38816. +++ b/drivers/ide/ide-cd.c
  38817. @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
  38818. alignment = queue_dma_alignment(q) | q->dma_pad_mask;
  38819. if ((unsigned long)buf & alignment
  38820. || blk_rq_bytes(rq) & q->dma_pad_mask
  38821. - || object_is_on_stack(buf))
  38822. + || object_starts_on_stack(buf))
  38823. drive->dma = 0;
  38824. }
  38825. }
  38826. diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
  38827. index acc911a..8700c3c 100644
  38828. --- a/drivers/iio/industrialio-core.c
  38829. +++ b/drivers/iio/industrialio-core.c
  38830. @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
  38831. }
  38832. static
  38833. -int __iio_device_attr_init(struct device_attribute *dev_attr,
  38834. +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
  38835. const char *postfix,
  38836. struct iio_chan_spec const *chan,
  38837. ssize_t (*readfunc)(struct device *dev,
  38838. diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
  38839. index c323917..6ddea8b 100644
  38840. --- a/drivers/infiniband/core/cm.c
  38841. +++ b/drivers/infiniband/core/cm.c
  38842. @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
  38843. struct cm_counter_group {
  38844. struct kobject obj;
  38845. - atomic_long_t counter[CM_ATTR_COUNT];
  38846. + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
  38847. };
  38848. struct cm_counter_attribute {
  38849. @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
  38850. struct ib_mad_send_buf *msg = NULL;
  38851. int ret;
  38852. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38853. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38854. counter[CM_REQ_COUNTER]);
  38855. /* Quick state check to discard duplicate REQs. */
  38856. @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
  38857. if (!cm_id_priv)
  38858. return;
  38859. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38860. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38861. counter[CM_REP_COUNTER]);
  38862. ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
  38863. if (ret)
  38864. @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
  38865. if (cm_id_priv->id.state != IB_CM_REP_SENT &&
  38866. cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
  38867. spin_unlock_irq(&cm_id_priv->lock);
  38868. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38869. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38870. counter[CM_RTU_COUNTER]);
  38871. goto out;
  38872. }
  38873. @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
  38874. cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
  38875. dreq_msg->local_comm_id);
  38876. if (!cm_id_priv) {
  38877. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38878. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38879. counter[CM_DREQ_COUNTER]);
  38880. cm_issue_drep(work->port, work->mad_recv_wc);
  38881. return -EINVAL;
  38882. @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
  38883. case IB_CM_MRA_REP_RCVD:
  38884. break;
  38885. case IB_CM_TIMEWAIT:
  38886. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38887. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38888. counter[CM_DREQ_COUNTER]);
  38889. if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
  38890. goto unlock;
  38891. @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
  38892. cm_free_msg(msg);
  38893. goto deref;
  38894. case IB_CM_DREQ_RCVD:
  38895. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38896. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38897. counter[CM_DREQ_COUNTER]);
  38898. goto unlock;
  38899. default:
  38900. @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
  38901. ib_modify_mad(cm_id_priv->av.port->mad_agent,
  38902. cm_id_priv->msg, timeout)) {
  38903. if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
  38904. - atomic_long_inc(&work->port->
  38905. + atomic_long_inc_unchecked(&work->port->
  38906. counter_group[CM_RECV_DUPLICATES].
  38907. counter[CM_MRA_COUNTER]);
  38908. goto out;
  38909. @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
  38910. break;
  38911. case IB_CM_MRA_REQ_RCVD:
  38912. case IB_CM_MRA_REP_RCVD:
  38913. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38914. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38915. counter[CM_MRA_COUNTER]);
  38916. /* fall through */
  38917. default:
  38918. @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
  38919. case IB_CM_LAP_IDLE:
  38920. break;
  38921. case IB_CM_MRA_LAP_SENT:
  38922. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38923. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38924. counter[CM_LAP_COUNTER]);
  38925. if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
  38926. goto unlock;
  38927. @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
  38928. cm_free_msg(msg);
  38929. goto deref;
  38930. case IB_CM_LAP_RCVD:
  38931. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38932. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38933. counter[CM_LAP_COUNTER]);
  38934. goto unlock;
  38935. default:
  38936. @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
  38937. cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
  38938. if (cur_cm_id_priv) {
  38939. spin_unlock_irq(&cm.lock);
  38940. - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
  38941. + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
  38942. counter[CM_SIDR_REQ_COUNTER]);
  38943. goto out; /* Duplicate message. */
  38944. }
  38945. @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
  38946. if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
  38947. msg->retries = 1;
  38948. - atomic_long_add(1 + msg->retries,
  38949. + atomic_long_add_unchecked(1 + msg->retries,
  38950. &port->counter_group[CM_XMIT].counter[attr_index]);
  38951. if (msg->retries)
  38952. - atomic_long_add(msg->retries,
  38953. + atomic_long_add_unchecked(msg->retries,
  38954. &port->counter_group[CM_XMIT_RETRIES].
  38955. counter[attr_index]);
  38956. @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
  38957. }
  38958. attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
  38959. - atomic_long_inc(&port->counter_group[CM_RECV].
  38960. + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
  38961. counter[attr_id - CM_ATTR_ID_OFFSET]);
  38962. work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
  38963. @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
  38964. cm_attr = container_of(attr, struct cm_counter_attribute, attr);
  38965. return sprintf(buf, "%ld\n",
  38966. - atomic_long_read(&group->counter[cm_attr->index]));
  38967. + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
  38968. }
  38969. static const struct sysfs_ops cm_counter_ops = {
  38970. diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
  38971. index 9f5ad7c..588cd84 100644
  38972. --- a/drivers/infiniband/core/fmr_pool.c
  38973. +++ b/drivers/infiniband/core/fmr_pool.c
  38974. @@ -98,8 +98,8 @@ struct ib_fmr_pool {
  38975. struct task_struct *thread;
  38976. - atomic_t req_ser;
  38977. - atomic_t flush_ser;
  38978. + atomic_unchecked_t req_ser;
  38979. + atomic_unchecked_t flush_ser;
  38980. wait_queue_head_t force_wait;
  38981. };
  38982. @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
  38983. struct ib_fmr_pool *pool = pool_ptr;
  38984. do {
  38985. - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
  38986. + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
  38987. ib_fmr_batch_release(pool);
  38988. - atomic_inc(&pool->flush_ser);
  38989. + atomic_inc_unchecked(&pool->flush_ser);
  38990. wake_up_interruptible(&pool->force_wait);
  38991. if (pool->flush_function)
  38992. @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
  38993. }
  38994. set_current_state(TASK_INTERRUPTIBLE);
  38995. - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
  38996. + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
  38997. !kthread_should_stop())
  38998. schedule();
  38999. __set_current_state(TASK_RUNNING);
  39000. @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
  39001. pool->dirty_watermark = params->dirty_watermark;
  39002. pool->dirty_len = 0;
  39003. spin_lock_init(&pool->pool_lock);
  39004. - atomic_set(&pool->req_ser, 0);
  39005. - atomic_set(&pool->flush_ser, 0);
  39006. + atomic_set_unchecked(&pool->req_ser, 0);
  39007. + atomic_set_unchecked(&pool->flush_ser, 0);
  39008. init_waitqueue_head(&pool->force_wait);
  39009. pool->thread = kthread_run(ib_fmr_cleanup_thread,
  39010. @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
  39011. }
  39012. spin_unlock_irq(&pool->pool_lock);
  39013. - serial = atomic_inc_return(&pool->req_ser);
  39014. + serial = atomic_inc_return_unchecked(&pool->req_ser);
  39015. wake_up_process(pool->thread);
  39016. if (wait_event_interruptible(pool->force_wait,
  39017. - atomic_read(&pool->flush_ser) - serial >= 0))
  39018. + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
  39019. return -EINTR;
  39020. return 0;
  39021. @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
  39022. } else {
  39023. list_add_tail(&fmr->list, &pool->dirty_list);
  39024. if (++pool->dirty_len >= pool->dirty_watermark) {
  39025. - atomic_inc(&pool->req_ser);
  39026. + atomic_inc_unchecked(&pool->req_ser);
  39027. wake_up_process(pool->thread);
  39028. }
  39029. }
  39030. diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
  39031. index 41b1195..27971a0 100644
  39032. --- a/drivers/infiniband/hw/cxgb4/mem.c
  39033. +++ b/drivers/infiniband/hw/cxgb4/mem.c
  39034. @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
  39035. int err;
  39036. struct fw_ri_tpte tpt;
  39037. u32 stag_idx;
  39038. - static atomic_t key;
  39039. + static atomic_unchecked_t key;
  39040. if (c4iw_fatal_error(rdev))
  39041. return -EIO;
  39042. @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
  39043. if (rdev->stats.stag.cur > rdev->stats.stag.max)
  39044. rdev->stats.stag.max = rdev->stats.stag.cur;
  39045. mutex_unlock(&rdev->stats.lock);
  39046. - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
  39047. + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
  39048. }
  39049. PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
  39050. __func__, stag_state, type, pdid, stag_idx);
  39051. diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
  39052. index 644c2c7..ecf0879 100644
  39053. --- a/drivers/infiniband/hw/ipath/ipath_dma.c
  39054. +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
  39055. @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
  39056. }
  39057. struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
  39058. - ipath_mapping_error,
  39059. - ipath_dma_map_single,
  39060. - ipath_dma_unmap_single,
  39061. - ipath_dma_map_page,
  39062. - ipath_dma_unmap_page,
  39063. - ipath_map_sg,
  39064. - ipath_unmap_sg,
  39065. - ipath_sg_dma_address,
  39066. - ipath_sg_dma_len,
  39067. - ipath_sync_single_for_cpu,
  39068. - ipath_sync_single_for_device,
  39069. - ipath_dma_alloc_coherent,
  39070. - ipath_dma_free_coherent
  39071. + .mapping_error = ipath_mapping_error,
  39072. + .map_single = ipath_dma_map_single,
  39073. + .unmap_single = ipath_dma_unmap_single,
  39074. + .map_page = ipath_dma_map_page,
  39075. + .unmap_page = ipath_dma_unmap_page,
  39076. + .map_sg = ipath_map_sg,
  39077. + .unmap_sg = ipath_unmap_sg,
  39078. + .dma_address = ipath_sg_dma_address,
  39079. + .dma_len = ipath_sg_dma_len,
  39080. + .sync_single_for_cpu = ipath_sync_single_for_cpu,
  39081. + .sync_single_for_device = ipath_sync_single_for_device,
  39082. + .alloc_coherent = ipath_dma_alloc_coherent,
  39083. + .free_coherent = ipath_dma_free_coherent
  39084. };
  39085. diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
  39086. index 79b3dbc..96e5fcc 100644
  39087. --- a/drivers/infiniband/hw/ipath/ipath_rc.c
  39088. +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
  39089. @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
  39090. struct ib_atomic_eth *ateth;
  39091. struct ipath_ack_entry *e;
  39092. u64 vaddr;
  39093. - atomic64_t *maddr;
  39094. + atomic64_unchecked_t *maddr;
  39095. u64 sdata;
  39096. u32 rkey;
  39097. u8 next;
  39098. @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
  39099. IB_ACCESS_REMOTE_ATOMIC)))
  39100. goto nack_acc_unlck;
  39101. /* Perform atomic OP and save result. */
  39102. - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
  39103. + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
  39104. sdata = be64_to_cpu(ateth->swap_data);
  39105. e = &qp->s_ack_queue[qp->r_head_ack_queue];
  39106. e->atomic_data = (opcode == OP(FETCH_ADD)) ?
  39107. - (u64) atomic64_add_return(sdata, maddr) - sdata :
  39108. + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
  39109. (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
  39110. be64_to_cpu(ateth->compare_data),
  39111. sdata);
  39112. diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
  39113. index 1f95bba..9530f87 100644
  39114. --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
  39115. +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
  39116. @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
  39117. unsigned long flags;
  39118. struct ib_wc wc;
  39119. u64 sdata;
  39120. - atomic64_t *maddr;
  39121. + atomic64_unchecked_t *maddr;
  39122. enum ib_wc_status send_status;
  39123. /*
  39124. @@ -382,11 +382,11 @@ again:
  39125. IB_ACCESS_REMOTE_ATOMIC)))
  39126. goto acc_err;
  39127. /* Perform atomic OP and save result. */
  39128. - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
  39129. + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
  39130. sdata = wqe->wr.wr.atomic.compare_add;
  39131. *(u64 *) sqp->s_sge.sge.vaddr =
  39132. (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
  39133. - (u64) atomic64_add_return(sdata, maddr) - sdata :
  39134. + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
  39135. (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
  39136. sdata, wqe->wr.wr.atomic.swap);
  39137. goto send_comp;
  39138. diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
  39139. index f2a3f48..673ec79 100644
  39140. --- a/drivers/infiniband/hw/mlx4/mad.c
  39141. +++ b/drivers/infiniband/hw/mlx4/mad.c
  39142. @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
  39143. __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
  39144. {
  39145. - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
  39146. + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
  39147. cpu_to_be64(0xff00000000000000LL);
  39148. }
  39149. diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
  39150. index 25b2cdf..099ff97 100644
  39151. --- a/drivers/infiniband/hw/mlx4/mcg.c
  39152. +++ b/drivers/infiniband/hw/mlx4/mcg.c
  39153. @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
  39154. {
  39155. char name[20];
  39156. - atomic_set(&ctx->tid, 0);
  39157. + atomic_set_unchecked(&ctx->tid, 0);
  39158. sprintf(name, "mlx4_ib_mcg%d", ctx->port);
  39159. ctx->mcg_wq = create_singlethread_workqueue(name);
  39160. if (!ctx->mcg_wq)
  39161. diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
  39162. index a230683..3723f2d 100644
  39163. --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
  39164. +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
  39165. @@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
  39166. struct list_head mcg_mgid0_list;
  39167. struct workqueue_struct *mcg_wq;
  39168. struct mlx4_ib_demux_pv_ctx **tun;
  39169. - atomic_t tid;
  39170. + atomic_unchecked_t tid;
  39171. int flushing; /* flushing the work queue */
  39172. };
  39173. diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
  39174. index 9d3e5c1..6f166df 100644
  39175. --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
  39176. +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
  39177. @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
  39178. mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
  39179. }
  39180. -int mthca_QUERY_FW(struct mthca_dev *dev)
  39181. +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
  39182. {
  39183. struct mthca_mailbox *mailbox;
  39184. u32 *outbox;
  39185. @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  39186. CMD_TIME_CLASS_B);
  39187. }
  39188. -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  39189. +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  39190. int num_mtt)
  39191. {
  39192. return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
  39193. @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
  39194. 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
  39195. }
  39196. -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  39197. +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  39198. int eq_num)
  39199. {
  39200. return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
  39201. @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
  39202. CMD_TIME_CLASS_B);
  39203. }
  39204. -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
  39205. +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
  39206. int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
  39207. void *in_mad, void *response_mad)
  39208. {
  39209. diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
  39210. index 87897b9..7e79542 100644
  39211. --- a/drivers/infiniband/hw/mthca/mthca_main.c
  39212. +++ b/drivers/infiniband/hw/mthca/mthca_main.c
  39213. @@ -692,7 +692,7 @@ err_close:
  39214. return err;
  39215. }
  39216. -static int mthca_setup_hca(struct mthca_dev *dev)
  39217. +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
  39218. {
  39219. int err;
  39220. diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
  39221. index ed9a989..6aa5dc2 100644
  39222. --- a/drivers/infiniband/hw/mthca/mthca_mr.c
  39223. +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
  39224. @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
  39225. * through the bitmaps)
  39226. */
  39227. -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
  39228. +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
  39229. {
  39230. int o;
  39231. int m;
  39232. @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
  39233. return key;
  39234. }
  39235. -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
  39236. +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
  39237. u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
  39238. {
  39239. struct mthca_mailbox *mailbox;
  39240. @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
  39241. return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
  39242. }
  39243. -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
  39244. +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
  39245. u64 *buffer_list, int buffer_size_shift,
  39246. int list_len, u64 iova, u64 total_size,
  39247. u32 access, struct mthca_mr *mr)
  39248. diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
  39249. index 42dde06..1257310 100644
  39250. --- a/drivers/infiniband/hw/mthca/mthca_provider.c
  39251. +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
  39252. @@ -764,7 +764,7 @@ unlock:
  39253. return 0;
  39254. }
  39255. -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
  39256. +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
  39257. {
  39258. struct mthca_dev *dev = to_mdev(ibcq->device);
  39259. struct mthca_cq *cq = to_mcq(ibcq);
  39260. diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
  39261. index 353c7b0..c6ce921 100644
  39262. --- a/drivers/infiniband/hw/nes/nes.c
  39263. +++ b/drivers/infiniband/hw/nes/nes.c
  39264. @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
  39265. LIST_HEAD(nes_adapter_list);
  39266. static LIST_HEAD(nes_dev_list);
  39267. -atomic_t qps_destroyed;
  39268. +atomic_unchecked_t qps_destroyed;
  39269. static unsigned int ee_flsh_adapter;
  39270. static unsigned int sysfs_nonidx_addr;
  39271. @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
  39272. struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
  39273. struct nes_adapter *nesadapter = nesdev->nesadapter;
  39274. - atomic_inc(&qps_destroyed);
  39275. + atomic_inc_unchecked(&qps_destroyed);
  39276. /* Free the control structures */
  39277. diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
  39278. index 33cc589..3bd6538 100644
  39279. --- a/drivers/infiniband/hw/nes/nes.h
  39280. +++ b/drivers/infiniband/hw/nes/nes.h
  39281. @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
  39282. extern unsigned int wqm_quanta;
  39283. extern struct list_head nes_adapter_list;
  39284. -extern atomic_t cm_connects;
  39285. -extern atomic_t cm_accepts;
  39286. -extern atomic_t cm_disconnects;
  39287. -extern atomic_t cm_closes;
  39288. -extern atomic_t cm_connecteds;
  39289. -extern atomic_t cm_connect_reqs;
  39290. -extern atomic_t cm_rejects;
  39291. -extern atomic_t mod_qp_timouts;
  39292. -extern atomic_t qps_created;
  39293. -extern atomic_t qps_destroyed;
  39294. -extern atomic_t sw_qps_destroyed;
  39295. +extern atomic_unchecked_t cm_connects;
  39296. +extern atomic_unchecked_t cm_accepts;
  39297. +extern atomic_unchecked_t cm_disconnects;
  39298. +extern atomic_unchecked_t cm_closes;
  39299. +extern atomic_unchecked_t cm_connecteds;
  39300. +extern atomic_unchecked_t cm_connect_reqs;
  39301. +extern atomic_unchecked_t cm_rejects;
  39302. +extern atomic_unchecked_t mod_qp_timouts;
  39303. +extern atomic_unchecked_t qps_created;
  39304. +extern atomic_unchecked_t qps_destroyed;
  39305. +extern atomic_unchecked_t sw_qps_destroyed;
  39306. extern u32 mh_detected;
  39307. extern u32 mh_pauses_sent;
  39308. extern u32 cm_packets_sent;
  39309. @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
  39310. extern u32 cm_packets_received;
  39311. extern u32 cm_packets_dropped;
  39312. extern u32 cm_packets_retrans;
  39313. -extern atomic_t cm_listens_created;
  39314. -extern atomic_t cm_listens_destroyed;
  39315. +extern atomic_unchecked_t cm_listens_created;
  39316. +extern atomic_unchecked_t cm_listens_destroyed;
  39317. extern u32 cm_backlog_drops;
  39318. -extern atomic_t cm_loopbacks;
  39319. -extern atomic_t cm_nodes_created;
  39320. -extern atomic_t cm_nodes_destroyed;
  39321. -extern atomic_t cm_accel_dropped_pkts;
  39322. -extern atomic_t cm_resets_recvd;
  39323. -extern atomic_t pau_qps_created;
  39324. -extern atomic_t pau_qps_destroyed;
  39325. +extern atomic_unchecked_t cm_loopbacks;
  39326. +extern atomic_unchecked_t cm_nodes_created;
  39327. +extern atomic_unchecked_t cm_nodes_destroyed;
  39328. +extern atomic_unchecked_t cm_accel_dropped_pkts;
  39329. +extern atomic_unchecked_t cm_resets_recvd;
  39330. +extern atomic_unchecked_t pau_qps_created;
  39331. +extern atomic_unchecked_t pau_qps_destroyed;
  39332. extern u32 int_mod_timer_init;
  39333. extern u32 int_mod_cq_depth_256;
  39334. diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
  39335. index 9c9f2f5..2559190 100644
  39336. --- a/drivers/infiniband/hw/nes/nes_cm.c
  39337. +++ b/drivers/infiniband/hw/nes/nes_cm.c
  39338. @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
  39339. u32 cm_packets_retrans;
  39340. u32 cm_packets_created;
  39341. u32 cm_packets_received;
  39342. -atomic_t cm_listens_created;
  39343. -atomic_t cm_listens_destroyed;
  39344. +atomic_unchecked_t cm_listens_created;
  39345. +atomic_unchecked_t cm_listens_destroyed;
  39346. u32 cm_backlog_drops;
  39347. -atomic_t cm_loopbacks;
  39348. -atomic_t cm_nodes_created;
  39349. -atomic_t cm_nodes_destroyed;
  39350. -atomic_t cm_accel_dropped_pkts;
  39351. -atomic_t cm_resets_recvd;
  39352. +atomic_unchecked_t cm_loopbacks;
  39353. +atomic_unchecked_t cm_nodes_created;
  39354. +atomic_unchecked_t cm_nodes_destroyed;
  39355. +atomic_unchecked_t cm_accel_dropped_pkts;
  39356. +atomic_unchecked_t cm_resets_recvd;
  39357. static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
  39358. static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
  39359. @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
  39360. /* instance of function pointers for client API */
  39361. /* set address of this instance to cm_core->cm_ops at cm_core alloc */
  39362. static struct nes_cm_ops nes_cm_api = {
  39363. - mini_cm_accelerated,
  39364. - mini_cm_listen,
  39365. - mini_cm_del_listen,
  39366. - mini_cm_connect,
  39367. - mini_cm_close,
  39368. - mini_cm_accept,
  39369. - mini_cm_reject,
  39370. - mini_cm_recv_pkt,
  39371. - mini_cm_dealloc_core,
  39372. - mini_cm_get,
  39373. - mini_cm_set
  39374. + .accelerated = mini_cm_accelerated,
  39375. + .listen = mini_cm_listen,
  39376. + .stop_listener = mini_cm_del_listen,
  39377. + .connect = mini_cm_connect,
  39378. + .close = mini_cm_close,
  39379. + .accept = mini_cm_accept,
  39380. + .reject = mini_cm_reject,
  39381. + .recv_pkt = mini_cm_recv_pkt,
  39382. + .destroy_cm_core = mini_cm_dealloc_core,
  39383. + .get = mini_cm_get,
  39384. + .set = mini_cm_set
  39385. };
  39386. static struct nes_cm_core *g_cm_core;
  39387. -atomic_t cm_connects;
  39388. -atomic_t cm_accepts;
  39389. -atomic_t cm_disconnects;
  39390. -atomic_t cm_closes;
  39391. -atomic_t cm_connecteds;
  39392. -atomic_t cm_connect_reqs;
  39393. -atomic_t cm_rejects;
  39394. +atomic_unchecked_t cm_connects;
  39395. +atomic_unchecked_t cm_accepts;
  39396. +atomic_unchecked_t cm_disconnects;
  39397. +atomic_unchecked_t cm_closes;
  39398. +atomic_unchecked_t cm_connecteds;
  39399. +atomic_unchecked_t cm_connect_reqs;
  39400. +atomic_unchecked_t cm_rejects;
  39401. int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
  39402. {
  39403. @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
  39404. kfree(listener);
  39405. listener = NULL;
  39406. ret = 0;
  39407. - atomic_inc(&cm_listens_destroyed);
  39408. + atomic_inc_unchecked(&cm_listens_destroyed);
  39409. } else {
  39410. spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
  39411. }
  39412. @@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
  39413. cm_node->rem_mac);
  39414. add_hte_node(cm_core, cm_node);
  39415. - atomic_inc(&cm_nodes_created);
  39416. + atomic_inc_unchecked(&cm_nodes_created);
  39417. return cm_node;
  39418. }
  39419. @@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
  39420. }
  39421. atomic_dec(&cm_core->node_cnt);
  39422. - atomic_inc(&cm_nodes_destroyed);
  39423. + atomic_inc_unchecked(&cm_nodes_destroyed);
  39424. nesqp = cm_node->nesqp;
  39425. if (nesqp) {
  39426. nesqp->cm_node = NULL;
  39427. @@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
  39428. static void drop_packet(struct sk_buff *skb)
  39429. {
  39430. - atomic_inc(&cm_accel_dropped_pkts);
  39431. + atomic_inc_unchecked(&cm_accel_dropped_pkts);
  39432. dev_kfree_skb_any(skb);
  39433. }
  39434. @@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
  39435. {
  39436. int reset = 0; /* whether to send reset in case of err.. */
  39437. - atomic_inc(&cm_resets_recvd);
  39438. + atomic_inc_unchecked(&cm_resets_recvd);
  39439. nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
  39440. " refcnt=%d\n", cm_node, cm_node->state,
  39441. atomic_read(&cm_node->ref_count));
  39442. @@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
  39443. rem_ref_cm_node(cm_node->cm_core, cm_node);
  39444. return NULL;
  39445. }
  39446. - atomic_inc(&cm_loopbacks);
  39447. + atomic_inc_unchecked(&cm_loopbacks);
  39448. loopbackremotenode->loopbackpartner = cm_node;
  39449. loopbackremotenode->tcp_cntxt.rcv_wscale =
  39450. NES_CM_DEFAULT_RCV_WND_SCALE;
  39451. @@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
  39452. nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
  39453. else {
  39454. rem_ref_cm_node(cm_core, cm_node);
  39455. - atomic_inc(&cm_accel_dropped_pkts);
  39456. + atomic_inc_unchecked(&cm_accel_dropped_pkts);
  39457. dev_kfree_skb_any(skb);
  39458. }
  39459. break;
  39460. @@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
  39461. if ((cm_id) && (cm_id->event_handler)) {
  39462. if (issue_disconn) {
  39463. - atomic_inc(&cm_disconnects);
  39464. + atomic_inc_unchecked(&cm_disconnects);
  39465. cm_event.event = IW_CM_EVENT_DISCONNECT;
  39466. cm_event.status = disconn_status;
  39467. cm_event.local_addr = cm_id->local_addr;
  39468. @@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
  39469. }
  39470. if (issue_close) {
  39471. - atomic_inc(&cm_closes);
  39472. + atomic_inc_unchecked(&cm_closes);
  39473. nes_disconnect(nesqp, 1);
  39474. cm_id->provider_data = nesqp;
  39475. @@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  39476. nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
  39477. nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
  39478. - atomic_inc(&cm_accepts);
  39479. + atomic_inc_unchecked(&cm_accepts);
  39480. nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
  39481. netdev_refcnt_read(nesvnic->netdev));
  39482. @@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  39483. struct nes_cm_core *cm_core;
  39484. u8 *start_buff;
  39485. - atomic_inc(&cm_rejects);
  39486. + atomic_inc_unchecked(&cm_rejects);
  39487. cm_node = (struct nes_cm_node *)cm_id->provider_data;
  39488. loopback = cm_node->loopbackpartner;
  39489. cm_core = cm_node->cm_core;
  39490. @@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  39491. ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
  39492. ntohs(laddr->sin_port));
  39493. - atomic_inc(&cm_connects);
  39494. + atomic_inc_unchecked(&cm_connects);
  39495. nesqp->active_conn = 1;
  39496. /* cache the cm_id in the qp */
  39497. @@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
  39498. g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
  39499. return err;
  39500. }
  39501. - atomic_inc(&cm_listens_created);
  39502. + atomic_inc_unchecked(&cm_listens_created);
  39503. }
  39504. cm_id->add_ref(cm_id);
  39505. @@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
  39506. if (nesqp->destroyed)
  39507. return;
  39508. - atomic_inc(&cm_connecteds);
  39509. + atomic_inc_unchecked(&cm_connecteds);
  39510. nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
  39511. " local port 0x%04X. jiffies = %lu.\n",
  39512. nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
  39513. @@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
  39514. cm_id->add_ref(cm_id);
  39515. ret = cm_id->event_handler(cm_id, &cm_event);
  39516. - atomic_inc(&cm_closes);
  39517. + atomic_inc_unchecked(&cm_closes);
  39518. cm_event.event = IW_CM_EVENT_CLOSE;
  39519. cm_event.status = 0;
  39520. cm_event.provider_data = cm_id->provider_data;
  39521. @@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
  39522. return;
  39523. cm_id = cm_node->cm_id;
  39524. - atomic_inc(&cm_connect_reqs);
  39525. + atomic_inc_unchecked(&cm_connect_reqs);
  39526. nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
  39527. cm_node, cm_id, jiffies);
  39528. @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
  39529. return;
  39530. cm_id = cm_node->cm_id;
  39531. - atomic_inc(&cm_connect_reqs);
  39532. + atomic_inc_unchecked(&cm_connect_reqs);
  39533. nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
  39534. cm_node, cm_id, jiffies);
  39535. diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
  39536. index 4166452..fc952c3 100644
  39537. --- a/drivers/infiniband/hw/nes/nes_mgt.c
  39538. +++ b/drivers/infiniband/hw/nes/nes_mgt.c
  39539. @@ -40,8 +40,8 @@
  39540. #include "nes.h"
  39541. #include "nes_mgt.h"
  39542. -atomic_t pau_qps_created;
  39543. -atomic_t pau_qps_destroyed;
  39544. +atomic_unchecked_t pau_qps_created;
  39545. +atomic_unchecked_t pau_qps_destroyed;
  39546. static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
  39547. {
  39548. @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
  39549. {
  39550. struct sk_buff *skb;
  39551. unsigned long flags;
  39552. - atomic_inc(&pau_qps_destroyed);
  39553. + atomic_inc_unchecked(&pau_qps_destroyed);
  39554. /* Free packets that have not yet been forwarded */
  39555. /* Lock is acquired by skb_dequeue when removing the skb */
  39556. @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
  39557. cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
  39558. skb_queue_head_init(&nesqp->pau_list);
  39559. spin_lock_init(&nesqp->pau_lock);
  39560. - atomic_inc(&pau_qps_created);
  39561. + atomic_inc_unchecked(&pau_qps_created);
  39562. nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
  39563. }
  39564. diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
  39565. index 49eb511..a774366 100644
  39566. --- a/drivers/infiniband/hw/nes/nes_nic.c
  39567. +++ b/drivers/infiniband/hw/nes/nes_nic.c
  39568. @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
  39569. target_stat_values[++index] = mh_detected;
  39570. target_stat_values[++index] = mh_pauses_sent;
  39571. target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
  39572. - target_stat_values[++index] = atomic_read(&cm_connects);
  39573. - target_stat_values[++index] = atomic_read(&cm_accepts);
  39574. - target_stat_values[++index] = atomic_read(&cm_disconnects);
  39575. - target_stat_values[++index] = atomic_read(&cm_connecteds);
  39576. - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
  39577. - target_stat_values[++index] = atomic_read(&cm_rejects);
  39578. - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
  39579. - target_stat_values[++index] = atomic_read(&qps_created);
  39580. - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
  39581. - target_stat_values[++index] = atomic_read(&qps_destroyed);
  39582. - target_stat_values[++index] = atomic_read(&cm_closes);
  39583. + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
  39584. + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
  39585. + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
  39586. + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
  39587. + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
  39588. + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
  39589. + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
  39590. + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
  39591. + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
  39592. + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
  39593. + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
  39594. target_stat_values[++index] = cm_packets_sent;
  39595. target_stat_values[++index] = cm_packets_bounced;
  39596. target_stat_values[++index] = cm_packets_created;
  39597. target_stat_values[++index] = cm_packets_received;
  39598. target_stat_values[++index] = cm_packets_dropped;
  39599. target_stat_values[++index] = cm_packets_retrans;
  39600. - target_stat_values[++index] = atomic_read(&cm_listens_created);
  39601. - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
  39602. + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
  39603. + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
  39604. target_stat_values[++index] = cm_backlog_drops;
  39605. - target_stat_values[++index] = atomic_read(&cm_loopbacks);
  39606. - target_stat_values[++index] = atomic_read(&cm_nodes_created);
  39607. - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
  39608. - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
  39609. - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
  39610. + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
  39611. + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
  39612. + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
  39613. + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
  39614. + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
  39615. target_stat_values[++index] = nesadapter->free_4kpbl;
  39616. target_stat_values[++index] = nesadapter->free_256pbl;
  39617. target_stat_values[++index] = int_mod_timer_init;
  39618. target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
  39619. target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
  39620. target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
  39621. - target_stat_values[++index] = atomic_read(&pau_qps_created);
  39622. - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
  39623. + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
  39624. + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
  39625. }
  39626. /**
  39627. diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
  39628. index eb62461..2b7fc71 100644
  39629. --- a/drivers/infiniband/hw/nes/nes_verbs.c
  39630. +++ b/drivers/infiniband/hw/nes/nes_verbs.c
  39631. @@ -46,9 +46,9 @@
  39632. #include <rdma/ib_umem.h>
  39633. -atomic_t mod_qp_timouts;
  39634. -atomic_t qps_created;
  39635. -atomic_t sw_qps_destroyed;
  39636. +atomic_unchecked_t mod_qp_timouts;
  39637. +atomic_unchecked_t qps_created;
  39638. +atomic_unchecked_t sw_qps_destroyed;
  39639. static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
  39640. @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
  39641. if (init_attr->create_flags)
  39642. return ERR_PTR(-EINVAL);
  39643. - atomic_inc(&qps_created);
  39644. + atomic_inc_unchecked(&qps_created);
  39645. switch (init_attr->qp_type) {
  39646. case IB_QPT_RC:
  39647. if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
  39648. @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
  39649. struct iw_cm_event cm_event;
  39650. int ret = 0;
  39651. - atomic_inc(&sw_qps_destroyed);
  39652. + atomic_inc_unchecked(&sw_qps_destroyed);
  39653. nesqp->destroyed = 1;
  39654. /* Blow away the connection if it exists. */
  39655. diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
  39656. index 1946101..09766d2 100644
  39657. --- a/drivers/infiniband/hw/qib/qib.h
  39658. +++ b/drivers/infiniband/hw/qib/qib.h
  39659. @@ -52,6 +52,7 @@
  39660. #include <linux/kref.h>
  39661. #include <linux/sched.h>
  39662. #include <linux/kthread.h>
  39663. +#include <linux/slab.h>
  39664. #include "qib_common.h"
  39665. #include "qib_verbs.h"
  39666. diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
  39667. index 24c41ba..102d71f 100644
  39668. --- a/drivers/input/gameport/gameport.c
  39669. +++ b/drivers/input/gameport/gameport.c
  39670. @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
  39671. */
  39672. static void gameport_init_port(struct gameport *gameport)
  39673. {
  39674. - static atomic_t gameport_no = ATOMIC_INIT(0);
  39675. + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
  39676. __module_get(THIS_MODULE);
  39677. mutex_init(&gameport->drv_mutex);
  39678. device_initialize(&gameport->dev);
  39679. dev_set_name(&gameport->dev, "gameport%lu",
  39680. - (unsigned long)atomic_inc_return(&gameport_no) - 1);
  39681. + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
  39682. gameport->dev.bus = &gameport_bus;
  39683. gameport->dev.release = gameport_release_port;
  39684. if (gameport->parent)
  39685. diff --git a/drivers/input/input.c b/drivers/input/input.c
  39686. index 1c4c0db..6f7abe3 100644
  39687. --- a/drivers/input/input.c
  39688. +++ b/drivers/input/input.c
  39689. @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
  39690. */
  39691. struct input_dev *input_allocate_device(void)
  39692. {
  39693. - static atomic_t input_no = ATOMIC_INIT(0);
  39694. + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
  39695. struct input_dev *dev;
  39696. dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
  39697. @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
  39698. INIT_LIST_HEAD(&dev->node);
  39699. dev_set_name(&dev->dev, "input%ld",
  39700. - (unsigned long) atomic_inc_return(&input_no) - 1);
  39701. + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
  39702. __module_get(THIS_MODULE);
  39703. }
  39704. diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
  39705. index 4a95b22..874c182 100644
  39706. --- a/drivers/input/joystick/sidewinder.c
  39707. +++ b/drivers/input/joystick/sidewinder.c
  39708. @@ -30,6 +30,7 @@
  39709. #include <linux/kernel.h>
  39710. #include <linux/module.h>
  39711. #include <linux/slab.h>
  39712. +#include <linux/sched.h>
  39713. #include <linux/input.h>
  39714. #include <linux/gameport.h>
  39715. #include <linux/jiffies.h>
  39716. diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
  39717. index 603fe0d..f63decc 100644
  39718. --- a/drivers/input/joystick/xpad.c
  39719. +++ b/drivers/input/joystick/xpad.c
  39720. @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
  39721. static int xpad_led_probe(struct usb_xpad *xpad)
  39722. {
  39723. - static atomic_t led_seq = ATOMIC_INIT(0);
  39724. + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
  39725. long led_no;
  39726. struct xpad_led *led;
  39727. struct led_classdev *led_cdev;
  39728. @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
  39729. if (!led)
  39730. return -ENOMEM;
  39731. - led_no = (long)atomic_inc_return(&led_seq) - 1;
  39732. + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
  39733. snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
  39734. led->xpad = xpad;
  39735. diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
  39736. index e204f26..8459f15 100644
  39737. --- a/drivers/input/misc/ims-pcu.c
  39738. +++ b/drivers/input/misc/ims-pcu.c
  39739. @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
  39740. static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
  39741. {
  39742. - static atomic_t device_no = ATOMIC_INIT(0);
  39743. + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
  39744. const struct ims_pcu_device_info *info;
  39745. u8 device_id;
  39746. @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
  39747. }
  39748. /* Device appears to be operable, complete initialization */
  39749. - pcu->device_no = atomic_inc_return(&device_no) - 1;
  39750. + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
  39751. error = ims_pcu_setup_backlight(pcu);
  39752. if (error)
  39753. diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
  39754. index 2f0b39d..7370f13 100644
  39755. --- a/drivers/input/mouse/psmouse.h
  39756. +++ b/drivers/input/mouse/psmouse.h
  39757. @@ -116,7 +116,7 @@ struct psmouse_attribute {
  39758. ssize_t (*set)(struct psmouse *psmouse, void *data,
  39759. const char *buf, size_t count);
  39760. bool protect;
  39761. -};
  39762. +} __do_const;
  39763. #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
  39764. ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
  39765. diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
  39766. index b604564..3f14ae4 100644
  39767. --- a/drivers/input/mousedev.c
  39768. +++ b/drivers/input/mousedev.c
  39769. @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
  39770. spin_unlock_irq(&client->packet_lock);
  39771. - if (copy_to_user(buffer, data, count))
  39772. + if (count > sizeof(data) || copy_to_user(buffer, data, count))
  39773. return -EFAULT;
  39774. return count;
  39775. diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
  39776. index 8f4c4ab..5fc8a45 100644
  39777. --- a/drivers/input/serio/serio.c
  39778. +++ b/drivers/input/serio/serio.c
  39779. @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
  39780. */
  39781. static void serio_init_port(struct serio *serio)
  39782. {
  39783. - static atomic_t serio_no = ATOMIC_INIT(0);
  39784. + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
  39785. __module_get(THIS_MODULE);
  39786. @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
  39787. mutex_init(&serio->drv_mutex);
  39788. device_initialize(&serio->dev);
  39789. dev_set_name(&serio->dev, "serio%ld",
  39790. - (long)atomic_inc_return(&serio_no) - 1);
  39791. + (long)atomic_inc_return_unchecked(&serio_no) - 1);
  39792. serio->dev.bus = &serio_bus;
  39793. serio->dev.release = serio_release_port;
  39794. serio->dev.groups = serio_device_attr_groups;
  39795. diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
  39796. index c9a02fe..0debc75 100644
  39797. --- a/drivers/input/serio/serio_raw.c
  39798. +++ b/drivers/input/serio/serio_raw.c
  39799. @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
  39800. static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
  39801. {
  39802. - static atomic_t serio_raw_no = ATOMIC_INIT(0);
  39803. + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
  39804. struct serio_raw *serio_raw;
  39805. int err;
  39806. @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
  39807. }
  39808. snprintf(serio_raw->name, sizeof(serio_raw->name),
  39809. - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
  39810. + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
  39811. kref_init(&serio_raw->kref);
  39812. INIT_LIST_HEAD(&serio_raw->client_list);
  39813. init_waitqueue_head(&serio_raw->wait);
  39814. diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
  39815. index e5555fc..937986d 100644
  39816. --- a/drivers/iommu/iommu.c
  39817. +++ b/drivers/iommu/iommu.c
  39818. @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
  39819. static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
  39820. {
  39821. bus_register_notifier(bus, &iommu_bus_nb);
  39822. - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
  39823. + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
  39824. }
  39825. /**
  39826. diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
  39827. index 228632c9..edfe331 100644
  39828. --- a/drivers/iommu/irq_remapping.c
  39829. +++ b/drivers/iommu/irq_remapping.c
  39830. @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
  39831. void panic_if_irq_remap(const char *msg)
  39832. {
  39833. if (irq_remapping_enabled)
  39834. - panic(msg);
  39835. + panic("%s", msg);
  39836. }
  39837. static void ir_ack_apic_edge(struct irq_data *data)
  39838. @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
  39839. void irq_remap_modify_chip_defaults(struct irq_chip *chip)
  39840. {
  39841. - chip->irq_print_chip = ir_print_prefix;
  39842. - chip->irq_ack = ir_ack_apic_edge;
  39843. - chip->irq_eoi = ir_ack_apic_level;
  39844. - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
  39845. + pax_open_kernel();
  39846. + *(void **)&chip->irq_print_chip = ir_print_prefix;
  39847. + *(void **)&chip->irq_ack = ir_ack_apic_edge;
  39848. + *(void **)&chip->irq_eoi = ir_ack_apic_level;
  39849. + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
  39850. + pax_close_kernel();
  39851. }
  39852. bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
  39853. diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
  39854. index 341c601..e5f407e 100644
  39855. --- a/drivers/irqchip/irq-gic.c
  39856. +++ b/drivers/irqchip/irq-gic.c
  39857. @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
  39858. * Supported arch specific GIC irq extension.
  39859. * Default make them NULL.
  39860. */
  39861. -struct irq_chip gic_arch_extn = {
  39862. +irq_chip_no_const gic_arch_extn = {
  39863. .irq_eoi = NULL,
  39864. .irq_mask = NULL,
  39865. .irq_unmask = NULL,
  39866. @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
  39867. chained_irq_exit(chip, desc);
  39868. }
  39869. -static struct irq_chip gic_chip = {
  39870. +static irq_chip_no_const gic_chip __read_only = {
  39871. .name = "GIC",
  39872. .irq_mask = gic_mask_irq,
  39873. .irq_unmask = gic_unmask_irq,
  39874. diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
  39875. index 8777065..a4a9967 100644
  39876. --- a/drivers/irqchip/irq-renesas-irqc.c
  39877. +++ b/drivers/irqchip/irq-renesas-irqc.c
  39878. @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
  39879. struct irqc_priv *p;
  39880. struct resource *io;
  39881. struct resource *irq;
  39882. - struct irq_chip *irq_chip;
  39883. + irq_chip_no_const *irq_chip;
  39884. const char *name = dev_name(&pdev->dev);
  39885. int ret;
  39886. int k;
  39887. diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
  39888. index ac6f72b..81150f2 100644
  39889. --- a/drivers/isdn/capi/capi.c
  39890. +++ b/drivers/isdn/capi/capi.c
  39891. @@ -81,8 +81,8 @@ struct capiminor {
  39892. struct capi20_appl *ap;
  39893. u32 ncci;
  39894. - atomic_t datahandle;
  39895. - atomic_t msgid;
  39896. + atomic_unchecked_t datahandle;
  39897. + atomic_unchecked_t msgid;
  39898. struct tty_port port;
  39899. int ttyinstop;
  39900. @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
  39901. capimsg_setu16(s, 2, mp->ap->applid);
  39902. capimsg_setu8 (s, 4, CAPI_DATA_B3);
  39903. capimsg_setu8 (s, 5, CAPI_RESP);
  39904. - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
  39905. + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
  39906. capimsg_setu32(s, 8, mp->ncci);
  39907. capimsg_setu16(s, 12, datahandle);
  39908. }
  39909. @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
  39910. mp->outbytes -= len;
  39911. spin_unlock_bh(&mp->outlock);
  39912. - datahandle = atomic_inc_return(&mp->datahandle);
  39913. + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
  39914. skb_push(skb, CAPI_DATA_B3_REQ_LEN);
  39915. memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
  39916. capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
  39917. capimsg_setu16(skb->data, 2, mp->ap->applid);
  39918. capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
  39919. capimsg_setu8 (skb->data, 5, CAPI_REQ);
  39920. - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
  39921. + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
  39922. capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
  39923. capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
  39924. capimsg_setu16(skb->data, 16, len); /* Data length */
  39925. diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
  39926. index c44950d..10ac276 100644
  39927. --- a/drivers/isdn/gigaset/bas-gigaset.c
  39928. +++ b/drivers/isdn/gigaset/bas-gigaset.c
  39929. @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
  39930. static const struct gigaset_ops gigops = {
  39931. - gigaset_write_cmd,
  39932. - gigaset_write_room,
  39933. - gigaset_chars_in_buffer,
  39934. - gigaset_brkchars,
  39935. - gigaset_init_bchannel,
  39936. - gigaset_close_bchannel,
  39937. - gigaset_initbcshw,
  39938. - gigaset_freebcshw,
  39939. - gigaset_reinitbcshw,
  39940. - gigaset_initcshw,
  39941. - gigaset_freecshw,
  39942. - gigaset_set_modem_ctrl,
  39943. - gigaset_baud_rate,
  39944. - gigaset_set_line_ctrl,
  39945. - gigaset_isoc_send_skb,
  39946. - gigaset_isoc_input,
  39947. + .write_cmd = gigaset_write_cmd,
  39948. + .write_room = gigaset_write_room,
  39949. + .chars_in_buffer = gigaset_chars_in_buffer,
  39950. + .brkchars = gigaset_brkchars,
  39951. + .init_bchannel = gigaset_init_bchannel,
  39952. + .close_bchannel = gigaset_close_bchannel,
  39953. + .initbcshw = gigaset_initbcshw,
  39954. + .freebcshw = gigaset_freebcshw,
  39955. + .reinitbcshw = gigaset_reinitbcshw,
  39956. + .initcshw = gigaset_initcshw,
  39957. + .freecshw = gigaset_freecshw,
  39958. + .set_modem_ctrl = gigaset_set_modem_ctrl,
  39959. + .baud_rate = gigaset_baud_rate,
  39960. + .set_line_ctrl = gigaset_set_line_ctrl,
  39961. + .send_skb = gigaset_isoc_send_skb,
  39962. + .handle_input = gigaset_isoc_input,
  39963. };
  39964. /* bas_gigaset_init
  39965. diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
  39966. index 600c79b..3752bab 100644
  39967. --- a/drivers/isdn/gigaset/interface.c
  39968. +++ b/drivers/isdn/gigaset/interface.c
  39969. @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
  39970. }
  39971. tty->driver_data = cs;
  39972. - ++cs->port.count;
  39973. + atomic_inc(&cs->port.count);
  39974. - if (cs->port.count == 1) {
  39975. + if (atomic_read(&cs->port.count) == 1) {
  39976. tty_port_tty_set(&cs->port, tty);
  39977. cs->port.low_latency = 1;
  39978. }
  39979. @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
  39980. if (!cs->connected)
  39981. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  39982. - else if (!cs->port.count)
  39983. + else if (!atomic_read(&cs->port.count))
  39984. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  39985. - else if (!--cs->port.count)
  39986. + else if (!atomic_dec_return(&cs->port.count))
  39987. tty_port_tty_set(&cs->port, NULL);
  39988. mutex_unlock(&cs->mutex);
  39989. diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
  39990. index 8c91fd5..14f13ce 100644
  39991. --- a/drivers/isdn/gigaset/ser-gigaset.c
  39992. +++ b/drivers/isdn/gigaset/ser-gigaset.c
  39993. @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
  39994. }
  39995. static const struct gigaset_ops ops = {
  39996. - gigaset_write_cmd,
  39997. - gigaset_write_room,
  39998. - gigaset_chars_in_buffer,
  39999. - gigaset_brkchars,
  40000. - gigaset_init_bchannel,
  40001. - gigaset_close_bchannel,
  40002. - gigaset_initbcshw,
  40003. - gigaset_freebcshw,
  40004. - gigaset_reinitbcshw,
  40005. - gigaset_initcshw,
  40006. - gigaset_freecshw,
  40007. - gigaset_set_modem_ctrl,
  40008. - gigaset_baud_rate,
  40009. - gigaset_set_line_ctrl,
  40010. - gigaset_m10x_send_skb, /* asyncdata.c */
  40011. - gigaset_m10x_input, /* asyncdata.c */
  40012. + .write_cmd = gigaset_write_cmd,
  40013. + .write_room = gigaset_write_room,
  40014. + .chars_in_buffer = gigaset_chars_in_buffer,
  40015. + .brkchars = gigaset_brkchars,
  40016. + .init_bchannel = gigaset_init_bchannel,
  40017. + .close_bchannel = gigaset_close_bchannel,
  40018. + .initbcshw = gigaset_initbcshw,
  40019. + .freebcshw = gigaset_freebcshw,
  40020. + .reinitbcshw = gigaset_reinitbcshw,
  40021. + .initcshw = gigaset_initcshw,
  40022. + .freecshw = gigaset_freecshw,
  40023. + .set_modem_ctrl = gigaset_set_modem_ctrl,
  40024. + .baud_rate = gigaset_baud_rate,
  40025. + .set_line_ctrl = gigaset_set_line_ctrl,
  40026. + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
  40027. + .handle_input = gigaset_m10x_input, /* asyncdata.c */
  40028. };
  40029. diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
  40030. index d0a41cb..b953e50 100644
  40031. --- a/drivers/isdn/gigaset/usb-gigaset.c
  40032. +++ b/drivers/isdn/gigaset/usb-gigaset.c
  40033. @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
  40034. gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
  40035. memcpy(cs->hw.usb->bchars, buf, 6);
  40036. return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
  40037. - 0, 0, &buf, 6, 2000);
  40038. + 0, 0, buf, 6, 2000);
  40039. }
  40040. static void gigaset_freebcshw(struct bc_state *bcs)
  40041. @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
  40042. }
  40043. static const struct gigaset_ops ops = {
  40044. - gigaset_write_cmd,
  40045. - gigaset_write_room,
  40046. - gigaset_chars_in_buffer,
  40047. - gigaset_brkchars,
  40048. - gigaset_init_bchannel,
  40049. - gigaset_close_bchannel,
  40050. - gigaset_initbcshw,
  40051. - gigaset_freebcshw,
  40052. - gigaset_reinitbcshw,
  40053. - gigaset_initcshw,
  40054. - gigaset_freecshw,
  40055. - gigaset_set_modem_ctrl,
  40056. - gigaset_baud_rate,
  40057. - gigaset_set_line_ctrl,
  40058. - gigaset_m10x_send_skb,
  40059. - gigaset_m10x_input,
  40060. + .write_cmd = gigaset_write_cmd,
  40061. + .write_room = gigaset_write_room,
  40062. + .chars_in_buffer = gigaset_chars_in_buffer,
  40063. + .brkchars = gigaset_brkchars,
  40064. + .init_bchannel = gigaset_init_bchannel,
  40065. + .close_bchannel = gigaset_close_bchannel,
  40066. + .initbcshw = gigaset_initbcshw,
  40067. + .freebcshw = gigaset_freebcshw,
  40068. + .reinitbcshw = gigaset_reinitbcshw,
  40069. + .initcshw = gigaset_initcshw,
  40070. + .freecshw = gigaset_freecshw,
  40071. + .set_modem_ctrl = gigaset_set_modem_ctrl,
  40072. + .baud_rate = gigaset_baud_rate,
  40073. + .set_line_ctrl = gigaset_set_line_ctrl,
  40074. + .send_skb = gigaset_m10x_send_skb,
  40075. + .handle_input = gigaset_m10x_input,
  40076. };
  40077. /*
  40078. diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
  40079. index 4d9b195..455075c 100644
  40080. --- a/drivers/isdn/hardware/avm/b1.c
  40081. +++ b/drivers/isdn/hardware/avm/b1.c
  40082. @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
  40083. }
  40084. if (left) {
  40085. if (t4file->user) {
  40086. - if (copy_from_user(buf, dp, left))
  40087. + if (left > sizeof buf || copy_from_user(buf, dp, left))
  40088. return -EFAULT;
  40089. } else {
  40090. memcpy(buf, dp, left);
  40091. @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
  40092. }
  40093. if (left) {
  40094. if (config->user) {
  40095. - if (copy_from_user(buf, dp, left))
  40096. + if (left > sizeof buf || copy_from_user(buf, dp, left))
  40097. return -EFAULT;
  40098. } else {
  40099. memcpy(buf, dp, left);
  40100. diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
  40101. index 9bb12ba..d4262f7 100644
  40102. --- a/drivers/isdn/i4l/isdn_common.c
  40103. +++ b/drivers/isdn/i4l/isdn_common.c
  40104. @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
  40105. } else
  40106. return -EINVAL;
  40107. case IIOCDBGVAR:
  40108. + if (!capable(CAP_SYS_RAWIO))
  40109. + return -EPERM;
  40110. if (arg) {
  40111. if (copy_to_user(argp, &dev, sizeof(ulong)))
  40112. return -EFAULT;
  40113. diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
  40114. index 91d5730..336523e 100644
  40115. --- a/drivers/isdn/i4l/isdn_concap.c
  40116. +++ b/drivers/isdn/i4l/isdn_concap.c
  40117. @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
  40118. }
  40119. struct concap_device_ops isdn_concap_reliable_dl_dops = {
  40120. - &isdn_concap_dl_data_req,
  40121. - &isdn_concap_dl_connect_req,
  40122. - &isdn_concap_dl_disconn_req
  40123. + .data_req = &isdn_concap_dl_data_req,
  40124. + .connect_req = &isdn_concap_dl_connect_req,
  40125. + .disconn_req = &isdn_concap_dl_disconn_req
  40126. };
  40127. /* The following should better go into a dedicated source file such that
  40128. diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
  40129. index 3c5f249..5fac4d0 100644
  40130. --- a/drivers/isdn/i4l/isdn_tty.c
  40131. +++ b/drivers/isdn/i4l/isdn_tty.c
  40132. @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
  40133. #ifdef ISDN_DEBUG_MODEM_OPEN
  40134. printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
  40135. - port->count);
  40136. + atomic_read(&port->count));
  40137. #endif
  40138. - port->count++;
  40139. + atomic_inc(&port->count);
  40140. port->tty = tty;
  40141. /*
  40142. * Start up serial port
  40143. @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
  40144. #endif
  40145. return;
  40146. }
  40147. - if ((tty->count == 1) && (port->count != 1)) {
  40148. + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
  40149. /*
  40150. * Uh, oh. tty->count is 1, which means that the tty
  40151. * structure will be freed. Info->count should always
  40152. @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
  40153. * serial port won't be shutdown.
  40154. */
  40155. printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
  40156. - "info->count is %d\n", port->count);
  40157. - port->count = 1;
  40158. + "info->count is %d\n", atomic_read(&port->count));
  40159. + atomic_set(&port->count, 1);
  40160. }
  40161. - if (--port->count < 0) {
  40162. + if (atomic_dec_return(&port->count) < 0) {
  40163. printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
  40164. - info->line, port->count);
  40165. - port->count = 0;
  40166. + info->line, atomic_read(&port->count));
  40167. + atomic_set(&port->count, 0);
  40168. }
  40169. - if (port->count) {
  40170. + if (atomic_read(&port->count)) {
  40171. #ifdef ISDN_DEBUG_MODEM_OPEN
  40172. printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
  40173. #endif
  40174. @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
  40175. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
  40176. return;
  40177. isdn_tty_shutdown(info);
  40178. - port->count = 0;
  40179. + atomic_set(&port->count, 0);
  40180. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  40181. port->tty = NULL;
  40182. wake_up_interruptible(&port->open_wait);
  40183. @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
  40184. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  40185. modem_info *info = &dev->mdm.info[i];
  40186. - if (info->port.count == 0)
  40187. + if (atomic_read(&info->port.count) == 0)
  40188. continue;
  40189. if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
  40190. (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
  40191. diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
  40192. index e2d4e58..40cd045 100644
  40193. --- a/drivers/isdn/i4l/isdn_x25iface.c
  40194. +++ b/drivers/isdn/i4l/isdn_x25iface.c
  40195. @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
  40196. static struct concap_proto_ops ix25_pops = {
  40197. - &isdn_x25iface_proto_new,
  40198. - &isdn_x25iface_proto_del,
  40199. - &isdn_x25iface_proto_restart,
  40200. - &isdn_x25iface_proto_close,
  40201. - &isdn_x25iface_xmit,
  40202. - &isdn_x25iface_receive,
  40203. - &isdn_x25iface_connect_ind,
  40204. - &isdn_x25iface_disconn_ind
  40205. + .proto_new = &isdn_x25iface_proto_new,
  40206. + .proto_del = &isdn_x25iface_proto_del,
  40207. + .restart = &isdn_x25iface_proto_restart,
  40208. + .close = &isdn_x25iface_proto_close,
  40209. + .encap_and_xmit = &isdn_x25iface_xmit,
  40210. + .data_ind = &isdn_x25iface_receive,
  40211. + .connect_ind = &isdn_x25iface_connect_ind,
  40212. + .disconn_ind = &isdn_x25iface_disconn_ind
  40213. };
  40214. /* error message helper function */
  40215. diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
  40216. index 53d487f..cae33fe 100644
  40217. --- a/drivers/isdn/icn/icn.c
  40218. +++ b/drivers/isdn/icn/icn.c
  40219. @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
  40220. if (count > len)
  40221. count = len;
  40222. if (user) {
  40223. - if (copy_from_user(msg, buf, count))
  40224. + if (count > sizeof msg || copy_from_user(msg, buf, count))
  40225. return -EFAULT;
  40226. } else
  40227. memcpy(msg, buf, count);
  40228. @@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
  40229. ulong a;
  40230. ulong flags;
  40231. int i;
  40232. - char cbuf[60];
  40233. + char cbuf[80];
  40234. isdn_ctrl cmd;
  40235. icn_cdef cdef;
  40236. char __user *arg;
  40237. @@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
  40238. break;
  40239. if ((c->arg & 255) < ICN_BCH) {
  40240. char *p;
  40241. - char dial[50];
  40242. char dcode[4];
  40243. a = c->arg;
  40244. @@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
  40245. } else
  40246. /* Normal Dial */
  40247. strcpy(dcode, "CAL");
  40248. - strcpy(dial, p);
  40249. - sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
  40250. - dcode, dial, c->parm.setup.si1,
  40251. - c->parm.setup.si2, c->parm.setup.eazmsn);
  40252. + snprintf(cbuf, sizeof(cbuf),
  40253. + "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
  40254. + dcode, p, c->parm.setup.si1,
  40255. + c->parm.setup.si2, c->parm.setup.eazmsn);
  40256. i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
  40257. }
  40258. break;
  40259. diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
  40260. index a4f05c5..1433bc5 100644
  40261. --- a/drivers/isdn/mISDN/dsp_cmx.c
  40262. +++ b/drivers/isdn/mISDN/dsp_cmx.c
  40263. @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
  40264. static u16 dsp_count; /* last sample count */
  40265. static int dsp_count_valid; /* if we have last sample count */
  40266. -void
  40267. +void __intentional_overflow(-1)
  40268. dsp_cmx_send(void *arg)
  40269. {
  40270. struct dsp_conf *conf;
  40271. diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
  40272. index d93e245..e7ece6b 100644
  40273. --- a/drivers/leds/leds-clevo-mail.c
  40274. +++ b/drivers/leds/leds-clevo-mail.c
  40275. @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
  40276. * detected as working, but in reality it is not) as low as
  40277. * possible.
  40278. */
  40279. -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
  40280. +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
  40281. {
  40282. .callback = clevo_mail_led_dmi_callback,
  40283. .ident = "Clevo D410J",
  40284. diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
  40285. index 5b8f938..b73d657 100644
  40286. --- a/drivers/leds/leds-ss4200.c
  40287. +++ b/drivers/leds/leds-ss4200.c
  40288. @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
  40289. * detected as working, but in reality it is not) as low as
  40290. * possible.
  40291. */
  40292. -static struct dmi_system_id nas_led_whitelist[] __initdata = {
  40293. +static struct dmi_system_id nas_led_whitelist[] __initconst = {
  40294. {
  40295. .callback = ss4200_led_dmi_callback,
  40296. .ident = "Intel SS4200-E",
  40297. diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
  40298. index 0bf1e4e..b4bf44e 100644
  40299. --- a/drivers/lguest/core.c
  40300. +++ b/drivers/lguest/core.c
  40301. @@ -97,9 +97,17 @@ static __init int map_switcher(void)
  40302. * The end address needs +1 because __get_vm_area allocates an
  40303. * extra guard page, so we need space for that.
  40304. */
  40305. +
  40306. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  40307. + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
  40308. + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
  40309. + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
  40310. +#else
  40311. switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
  40312. VM_ALLOC, switcher_addr, switcher_addr
  40313. + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
  40314. +#endif
  40315. +
  40316. if (!switcher_vma) {
  40317. err = -ENOMEM;
  40318. printk("lguest: could not map switcher pages high\n");
  40319. @@ -124,7 +132,7 @@ static __init int map_switcher(void)
  40320. * Now the Switcher is mapped at the right address, we can't fail!
  40321. * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
  40322. */
  40323. - memcpy(switcher_vma->addr, start_switcher_text,
  40324. + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
  40325. end_switcher_text - start_switcher_text);
  40326. printk(KERN_INFO "lguest: mapped switcher at %p\n",
  40327. diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
  40328. index bfb39bb..08a603b 100644
  40329. --- a/drivers/lguest/page_tables.c
  40330. +++ b/drivers/lguest/page_tables.c
  40331. @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
  40332. /*:*/
  40333. #ifdef CONFIG_X86_PAE
  40334. -static void release_pmd(pmd_t *spmd)
  40335. +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
  40336. {
  40337. /* If the entry's not present, there's nothing to release. */
  40338. if (pmd_flags(*spmd) & _PAGE_PRESENT) {
  40339. diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
  40340. index 922a1ac..9dd0c2a 100644
  40341. --- a/drivers/lguest/x86/core.c
  40342. +++ b/drivers/lguest/x86/core.c
  40343. @@ -59,7 +59,7 @@ static struct {
  40344. /* Offset from where switcher.S was compiled to where we've copied it */
  40345. static unsigned long switcher_offset(void)
  40346. {
  40347. - return switcher_addr - (unsigned long)start_switcher_text;
  40348. + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
  40349. }
  40350. /* This cpu's struct lguest_pages (after the Switcher text page) */
  40351. @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
  40352. * These copies are pretty cheap, so we do them unconditionally: */
  40353. /* Save the current Host top-level page directory.
  40354. */
  40355. +
  40356. +#ifdef CONFIG_PAX_PER_CPU_PGD
  40357. + pages->state.host_cr3 = read_cr3();
  40358. +#else
  40359. pages->state.host_cr3 = __pa(current->mm->pgd);
  40360. +#endif
  40361. +
  40362. /*
  40363. * Set up the Guest's page tables to see this CPU's pages (and no
  40364. * other CPU's pages).
  40365. @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
  40366. * compiled-in switcher code and the high-mapped copy we just made.
  40367. */
  40368. for (i = 0; i < IDT_ENTRIES; i++)
  40369. - default_idt_entries[i] += switcher_offset();
  40370. + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
  40371. /*
  40372. * Set up the Switcher's per-cpu areas.
  40373. @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
  40374. * it will be undisturbed when we switch. To change %cs and jump we
  40375. * need this structure to feed to Intel's "lcall" instruction.
  40376. */
  40377. - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
  40378. + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
  40379. lguest_entry.segment = LGUEST_CS;
  40380. /*
  40381. diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
  40382. index 40634b0..4f5855e 100644
  40383. --- a/drivers/lguest/x86/switcher_32.S
  40384. +++ b/drivers/lguest/x86/switcher_32.S
  40385. @@ -87,6 +87,7 @@
  40386. #include <asm/page.h>
  40387. #include <asm/segment.h>
  40388. #include <asm/lguest.h>
  40389. +#include <asm/processor-flags.h>
  40390. // We mark the start of the code to copy
  40391. // It's placed in .text tho it's never run here
  40392. @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
  40393. // Changes type when we load it: damn Intel!
  40394. // For after we switch over our page tables
  40395. // That entry will be read-only: we'd crash.
  40396. +
  40397. +#ifdef CONFIG_PAX_KERNEXEC
  40398. + mov %cr0, %edx
  40399. + xor $X86_CR0_WP, %edx
  40400. + mov %edx, %cr0
  40401. +#endif
  40402. +
  40403. movl $(GDT_ENTRY_TSS*8), %edx
  40404. ltr %dx
  40405. @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
  40406. // Let's clear it again for our return.
  40407. // The GDT descriptor of the Host
  40408. // Points to the table after two "size" bytes
  40409. - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
  40410. + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
  40411. // Clear "used" from type field (byte 5, bit 2)
  40412. - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
  40413. + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
  40414. +
  40415. +#ifdef CONFIG_PAX_KERNEXEC
  40416. + mov %cr0, %eax
  40417. + xor $X86_CR0_WP, %eax
  40418. + mov %eax, %cr0
  40419. +#endif
  40420. // Once our page table's switched, the Guest is live!
  40421. // The Host fades as we run this final step.
  40422. @@ -295,13 +309,12 @@ deliver_to_host:
  40423. // I consulted gcc, and it gave
  40424. // These instructions, which I gladly credit:
  40425. leal (%edx,%ebx,8), %eax
  40426. - movzwl (%eax),%edx
  40427. - movl 4(%eax), %eax
  40428. - xorw %ax, %ax
  40429. - orl %eax, %edx
  40430. + movl 4(%eax), %edx
  40431. + movw (%eax), %dx
  40432. // Now the address of the handler's in %edx
  40433. // We call it now: its "iret" drops us home.
  40434. - jmp *%edx
  40435. + ljmp $__KERNEL_CS, $1f
  40436. +1: jmp *%edx
  40437. // Every interrupt can come to us here
  40438. // But we must truly tell each apart.
  40439. diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
  40440. index 7ef7461..5a09dac 100644
  40441. --- a/drivers/md/bcache/closure.h
  40442. +++ b/drivers/md/bcache/closure.h
  40443. @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
  40444. static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
  40445. struct workqueue_struct *wq)
  40446. {
  40447. - BUG_ON(object_is_on_stack(cl));
  40448. + BUG_ON(object_starts_on_stack(cl));
  40449. closure_set_ip(cl);
  40450. cl->fn = fn;
  40451. cl->wq = wq;
  40452. diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
  40453. index 4195a01..42527ac 100644
  40454. --- a/drivers/md/bitmap.c
  40455. +++ b/drivers/md/bitmap.c
  40456. @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
  40457. chunk_kb ? "KB" : "B");
  40458. if (bitmap->storage.file) {
  40459. seq_printf(seq, ", file: ");
  40460. - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
  40461. + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
  40462. }
  40463. seq_printf(seq, "\n");
  40464. diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
  40465. index 5152142..623d141 100644
  40466. --- a/drivers/md/dm-ioctl.c
  40467. +++ b/drivers/md/dm-ioctl.c
  40468. @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
  40469. cmd == DM_LIST_VERSIONS_CMD)
  40470. return 0;
  40471. - if ((cmd == DM_DEV_CREATE_CMD)) {
  40472. + if (cmd == DM_DEV_CREATE_CMD) {
  40473. if (!*param->name) {
  40474. DMWARN("name not supplied when creating device");
  40475. return -EINVAL;
  40476. diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
  40477. index 7dfdb5c..4caada6 100644
  40478. --- a/drivers/md/dm-raid1.c
  40479. +++ b/drivers/md/dm-raid1.c
  40480. @@ -40,7 +40,7 @@ enum dm_raid1_error {
  40481. struct mirror {
  40482. struct mirror_set *ms;
  40483. - atomic_t error_count;
  40484. + atomic_unchecked_t error_count;
  40485. unsigned long error_type;
  40486. struct dm_dev *dev;
  40487. sector_t offset;
  40488. @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
  40489. struct mirror *m;
  40490. for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
  40491. - if (!atomic_read(&m->error_count))
  40492. + if (!atomic_read_unchecked(&m->error_count))
  40493. return m;
  40494. return NULL;
  40495. @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
  40496. * simple way to tell if a device has encountered
  40497. * errors.
  40498. */
  40499. - atomic_inc(&m->error_count);
  40500. + atomic_inc_unchecked(&m->error_count);
  40501. if (test_and_set_bit(error_type, &m->error_type))
  40502. return;
  40503. @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
  40504. struct mirror *m = get_default_mirror(ms);
  40505. do {
  40506. - if (likely(!atomic_read(&m->error_count)))
  40507. + if (likely(!atomic_read_unchecked(&m->error_count)))
  40508. return m;
  40509. if (m-- == ms->mirror)
  40510. @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
  40511. {
  40512. struct mirror *default_mirror = get_default_mirror(m->ms);
  40513. - return !atomic_read(&default_mirror->error_count);
  40514. + return !atomic_read_unchecked(&default_mirror->error_count);
  40515. }
  40516. static int mirror_available(struct mirror_set *ms, struct bio *bio)
  40517. @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
  40518. */
  40519. if (likely(region_in_sync(ms, region, 1)))
  40520. m = choose_mirror(ms, bio->bi_iter.bi_sector);
  40521. - else if (m && atomic_read(&m->error_count))
  40522. + else if (m && atomic_read_unchecked(&m->error_count))
  40523. m = NULL;
  40524. if (likely(m))
  40525. @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
  40526. }
  40527. ms->mirror[mirror].ms = ms;
  40528. - atomic_set(&(ms->mirror[mirror].error_count), 0);
  40529. + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
  40530. ms->mirror[mirror].error_type = 0;
  40531. ms->mirror[mirror].offset = offset;
  40532. @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
  40533. */
  40534. static char device_status_char(struct mirror *m)
  40535. {
  40536. - if (!atomic_read(&(m->error_count)))
  40537. + if (!atomic_read_unchecked(&(m->error_count)))
  40538. return 'A';
  40539. return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
  40540. diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
  40541. index 28a9012..9c0f6a5 100644
  40542. --- a/drivers/md/dm-stats.c
  40543. +++ b/drivers/md/dm-stats.c
  40544. @@ -382,7 +382,7 @@ do_sync_free:
  40545. synchronize_rcu_expedited();
  40546. dm_stat_free(&s->rcu_head);
  40547. } else {
  40548. - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
  40549. + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
  40550. call_rcu(&s->rcu_head, dm_stat_free);
  40551. }
  40552. return 0;
  40553. @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
  40554. ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
  40555. (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
  40556. ));
  40557. - ACCESS_ONCE(last->last_sector) = end_sector;
  40558. - ACCESS_ONCE(last->last_rw) = bi_rw;
  40559. + ACCESS_ONCE_RW(last->last_sector) = end_sector;
  40560. + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
  40561. }
  40562. rcu_read_lock();
  40563. diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
  40564. index d1600d2..4c3af3a 100644
  40565. --- a/drivers/md/dm-stripe.c
  40566. +++ b/drivers/md/dm-stripe.c
  40567. @@ -21,7 +21,7 @@ struct stripe {
  40568. struct dm_dev *dev;
  40569. sector_t physical_start;
  40570. - atomic_t error_count;
  40571. + atomic_unchecked_t error_count;
  40572. };
  40573. struct stripe_c {
  40574. @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
  40575. kfree(sc);
  40576. return r;
  40577. }
  40578. - atomic_set(&(sc->stripe[i].error_count), 0);
  40579. + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
  40580. }
  40581. ti->private = sc;
  40582. @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
  40583. DMEMIT("%d ", sc->stripes);
  40584. for (i = 0; i < sc->stripes; i++) {
  40585. DMEMIT("%s ", sc->stripe[i].dev->name);
  40586. - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
  40587. + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
  40588. 'D' : 'A';
  40589. }
  40590. buffer[i] = '\0';
  40591. @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
  40592. */
  40593. for (i = 0; i < sc->stripes; i++)
  40594. if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
  40595. - atomic_inc(&(sc->stripe[i].error_count));
  40596. - if (atomic_read(&(sc->stripe[i].error_count)) <
  40597. + atomic_inc_unchecked(&(sc->stripe[i].error_count));
  40598. + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
  40599. DM_IO_ERROR_THRESHOLD)
  40600. schedule_work(&sc->trigger_event);
  40601. }
  40602. diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
  40603. index 6a7f2b8..fea0bde 100644
  40604. --- a/drivers/md/dm-table.c
  40605. +++ b/drivers/md/dm-table.c
  40606. @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
  40607. static int open_dev(struct dm_dev_internal *d, dev_t dev,
  40608. struct mapped_device *md)
  40609. {
  40610. - static char *_claim_ptr = "I belong to device-mapper";
  40611. + static char _claim_ptr[] = "I belong to device-mapper";
  40612. struct block_device *bdev;
  40613. int r;
  40614. @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
  40615. if (!dev_size)
  40616. return 0;
  40617. - if ((start >= dev_size) || (start + len > dev_size)) {
  40618. + if ((start >= dev_size) || (len > dev_size - start)) {
  40619. DMWARN("%s: %s too small for target: "
  40620. "start=%llu, len=%llu, dev_size=%llu",
  40621. dm_device_name(ti->table->md), bdevname(bdev, b),
  40622. diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
  40623. index b086a94..74cb67e 100644
  40624. --- a/drivers/md/dm-thin-metadata.c
  40625. +++ b/drivers/md/dm-thin-metadata.c
  40626. @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
  40627. {
  40628. pmd->info.tm = pmd->tm;
  40629. pmd->info.levels = 2;
  40630. - pmd->info.value_type.context = pmd->data_sm;
  40631. + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
  40632. pmd->info.value_type.size = sizeof(__le64);
  40633. pmd->info.value_type.inc = data_block_inc;
  40634. pmd->info.value_type.dec = data_block_dec;
  40635. @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
  40636. pmd->bl_info.tm = pmd->tm;
  40637. pmd->bl_info.levels = 1;
  40638. - pmd->bl_info.value_type.context = pmd->data_sm;
  40639. + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
  40640. pmd->bl_info.value_type.size = sizeof(__le64);
  40641. pmd->bl_info.value_type.inc = data_block_inc;
  40642. pmd->bl_info.value_type.dec = data_block_dec;
  40643. diff --git a/drivers/md/dm.c b/drivers/md/dm.c
  40644. index 8c53b09..f1fb2b0 100644
  40645. --- a/drivers/md/dm.c
  40646. +++ b/drivers/md/dm.c
  40647. @@ -185,9 +185,9 @@ struct mapped_device {
  40648. /*
  40649. * Event handling.
  40650. */
  40651. - atomic_t event_nr;
  40652. + atomic_unchecked_t event_nr;
  40653. wait_queue_head_t eventq;
  40654. - atomic_t uevent_seq;
  40655. + atomic_unchecked_t uevent_seq;
  40656. struct list_head uevent_list;
  40657. spinlock_t uevent_lock; /* Protect access to uevent_list */
  40658. @@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
  40659. spin_lock_init(&md->deferred_lock);
  40660. atomic_set(&md->holders, 1);
  40661. atomic_set(&md->open_count, 0);
  40662. - atomic_set(&md->event_nr, 0);
  40663. - atomic_set(&md->uevent_seq, 0);
  40664. + atomic_set_unchecked(&md->event_nr, 0);
  40665. + atomic_set_unchecked(&md->uevent_seq, 0);
  40666. INIT_LIST_HEAD(&md->uevent_list);
  40667. spin_lock_init(&md->uevent_lock);
  40668. @@ -2043,7 +2043,7 @@ static void event_callback(void *context)
  40669. dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
  40670. - atomic_inc(&md->event_nr);
  40671. + atomic_inc_unchecked(&md->event_nr);
  40672. wake_up(&md->eventq);
  40673. }
  40674. @@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
  40675. uint32_t dm_next_uevent_seq(struct mapped_device *md)
  40676. {
  40677. - return atomic_add_return(1, &md->uevent_seq);
  40678. + return atomic_add_return_unchecked(1, &md->uevent_seq);
  40679. }
  40680. uint32_t dm_get_event_nr(struct mapped_device *md)
  40681. {
  40682. - return atomic_read(&md->event_nr);
  40683. + return atomic_read_unchecked(&md->event_nr);
  40684. }
  40685. int dm_wait_event(struct mapped_device *md, int event_nr)
  40686. {
  40687. return wait_event_interruptible(md->eventq,
  40688. - (event_nr != atomic_read(&md->event_nr)));
  40689. + (event_nr != atomic_read_unchecked(&md->event_nr)));
  40690. }
  40691. void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
  40692. diff --git a/drivers/md/md.c b/drivers/md/md.c
  40693. index 4ad5cc4..0f19664 100644
  40694. --- a/drivers/md/md.c
  40695. +++ b/drivers/md/md.c
  40696. @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
  40697. * start build, activate spare
  40698. */
  40699. static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
  40700. -static atomic_t md_event_count;
  40701. +static atomic_unchecked_t md_event_count;
  40702. void md_new_event(struct mddev *mddev)
  40703. {
  40704. - atomic_inc(&md_event_count);
  40705. + atomic_inc_unchecked(&md_event_count);
  40706. wake_up(&md_event_waiters);
  40707. }
  40708. EXPORT_SYMBOL_GPL(md_new_event);
  40709. @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
  40710. */
  40711. static void md_new_event_inintr(struct mddev *mddev)
  40712. {
  40713. - atomic_inc(&md_event_count);
  40714. + atomic_inc_unchecked(&md_event_count);
  40715. wake_up(&md_event_waiters);
  40716. }
  40717. @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
  40718. if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
  40719. (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
  40720. rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
  40721. - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
  40722. + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
  40723. rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
  40724. bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
  40725. @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
  40726. else
  40727. sb->resync_offset = cpu_to_le64(0);
  40728. - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
  40729. + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
  40730. sb->raid_disks = cpu_to_le32(mddev->raid_disks);
  40731. sb->size = cpu_to_le64(mddev->dev_sectors);
  40732. @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
  40733. static ssize_t
  40734. errors_show(struct md_rdev *rdev, char *page)
  40735. {
  40736. - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
  40737. + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
  40738. }
  40739. static ssize_t
  40740. @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
  40741. char *e;
  40742. unsigned long n = simple_strtoul(buf, &e, 10);
  40743. if (*buf && (*e == 0 || *e == '\n')) {
  40744. - atomic_set(&rdev->corrected_errors, n);
  40745. + atomic_set_unchecked(&rdev->corrected_errors, n);
  40746. return len;
  40747. }
  40748. return -EINVAL;
  40749. @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
  40750. rdev->sb_loaded = 0;
  40751. rdev->bb_page = NULL;
  40752. atomic_set(&rdev->nr_pending, 0);
  40753. - atomic_set(&rdev->read_errors, 0);
  40754. - atomic_set(&rdev->corrected_errors, 0);
  40755. + atomic_set_unchecked(&rdev->read_errors, 0);
  40756. + atomic_set_unchecked(&rdev->corrected_errors, 0);
  40757. INIT_LIST_HEAD(&rdev->same_set);
  40758. init_waitqueue_head(&rdev->blocked_wait);
  40759. @@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
  40760. spin_unlock(&pers_lock);
  40761. seq_printf(seq, "\n");
  40762. - seq->poll_event = atomic_read(&md_event_count);
  40763. + seq->poll_event = atomic_read_unchecked(&md_event_count);
  40764. return 0;
  40765. }
  40766. if (v == (void*)2) {
  40767. @@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
  40768. return error;
  40769. seq = file->private_data;
  40770. - seq->poll_event = atomic_read(&md_event_count);
  40771. + seq->poll_event = atomic_read_unchecked(&md_event_count);
  40772. return error;
  40773. }
  40774. @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
  40775. /* always allow read */
  40776. mask = POLLIN | POLLRDNORM;
  40777. - if (seq->poll_event != atomic_read(&md_event_count))
  40778. + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
  40779. mask |= POLLERR | POLLPRI;
  40780. return mask;
  40781. }
  40782. @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
  40783. struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
  40784. curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
  40785. (int)part_stat_read(&disk->part0, sectors[1]) -
  40786. - atomic_read(&disk->sync_io);
  40787. + atomic_read_unchecked(&disk->sync_io);
  40788. /* sync IO will cause sync_io to increase before the disk_stats
  40789. * as sync_io is counted when a request starts, and
  40790. * disk_stats is counted when it completes.
  40791. diff --git a/drivers/md/md.h b/drivers/md/md.h
  40792. index 07bba96..2d6788c 100644
  40793. --- a/drivers/md/md.h
  40794. +++ b/drivers/md/md.h
  40795. @@ -94,13 +94,13 @@ struct md_rdev {
  40796. * only maintained for arrays that
  40797. * support hot removal
  40798. */
  40799. - atomic_t read_errors; /* number of consecutive read errors that
  40800. + atomic_unchecked_t read_errors; /* number of consecutive read errors that
  40801. * we have tried to ignore.
  40802. */
  40803. struct timespec last_read_error; /* monotonic time since our
  40804. * last read error
  40805. */
  40806. - atomic_t corrected_errors; /* number of corrected read errors,
  40807. + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
  40808. * for reporting to userspace and storing
  40809. * in superblock.
  40810. */
  40811. @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
  40812. static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
  40813. {
  40814. - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
  40815. + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
  40816. }
  40817. struct md_personality
  40818. diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
  40819. index 786b689..ea8c956 100644
  40820. --- a/drivers/md/persistent-data/dm-space-map-metadata.c
  40821. +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
  40822. @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
  40823. * Flick into a mode where all blocks get allocated in the new area.
  40824. */
  40825. smm->begin = old_len;
  40826. - memcpy(sm, &bootstrap_ops, sizeof(*sm));
  40827. + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
  40828. /*
  40829. * Extend.
  40830. @@ -710,7 +710,7 @@ out:
  40831. /*
  40832. * Switch back to normal behaviour.
  40833. */
  40834. - memcpy(sm, &ops, sizeof(*sm));
  40835. + memcpy((void *)sm, &ops, sizeof(*sm));
  40836. return r;
  40837. }
  40838. diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
  40839. index 3e6d115..ffecdeb 100644
  40840. --- a/drivers/md/persistent-data/dm-space-map.h
  40841. +++ b/drivers/md/persistent-data/dm-space-map.h
  40842. @@ -71,6 +71,7 @@ struct dm_space_map {
  40843. dm_sm_threshold_fn fn,
  40844. void *context);
  40845. };
  40846. +typedef struct dm_space_map __no_const dm_space_map_no_const;
  40847. /*----------------------------------------------------------------*/
  40848. diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
  40849. index 4a6ca1c..e952750 100644
  40850. --- a/drivers/md/raid1.c
  40851. +++ b/drivers/md/raid1.c
  40852. @@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
  40853. if (r1_sync_page_io(rdev, sect, s,
  40854. bio->bi_io_vec[idx].bv_page,
  40855. READ) != 0)
  40856. - atomic_add(s, &rdev->corrected_errors);
  40857. + atomic_add_unchecked(s, &rdev->corrected_errors);
  40858. }
  40859. sectors -= s;
  40860. sect += s;
  40861. @@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
  40862. test_bit(In_sync, &rdev->flags)) {
  40863. if (r1_sync_page_io(rdev, sect, s,
  40864. conf->tmppage, READ)) {
  40865. - atomic_add(s, &rdev->corrected_errors);
  40866. + atomic_add_unchecked(s, &rdev->corrected_errors);
  40867. printk(KERN_INFO
  40868. "md/raid1:%s: read error corrected "
  40869. "(%d sectors at %llu on %s)\n",
  40870. diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
  40871. index 33fc408..fc61709 100644
  40872. --- a/drivers/md/raid10.c
  40873. +++ b/drivers/md/raid10.c
  40874. @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
  40875. /* The write handler will notice the lack of
  40876. * R10BIO_Uptodate and record any errors etc
  40877. */
  40878. - atomic_add(r10_bio->sectors,
  40879. + atomic_add_unchecked(r10_bio->sectors,
  40880. &conf->mirrors[d].rdev->corrected_errors);
  40881. /* for reconstruct, we always reschedule after a read.
  40882. @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
  40883. {
  40884. struct timespec cur_time_mon;
  40885. unsigned long hours_since_last;
  40886. - unsigned int read_errors = atomic_read(&rdev->read_errors);
  40887. + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
  40888. ktime_get_ts(&cur_time_mon);
  40889. @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
  40890. * overflowing the shift of read_errors by hours_since_last.
  40891. */
  40892. if (hours_since_last >= 8 * sizeof(read_errors))
  40893. - atomic_set(&rdev->read_errors, 0);
  40894. + atomic_set_unchecked(&rdev->read_errors, 0);
  40895. else
  40896. - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
  40897. + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
  40898. }
  40899. static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
  40900. @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
  40901. return;
  40902. check_decay_read_errors(mddev, rdev);
  40903. - atomic_inc(&rdev->read_errors);
  40904. - if (atomic_read(&rdev->read_errors) > max_read_errors) {
  40905. + atomic_inc_unchecked(&rdev->read_errors);
  40906. + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
  40907. char b[BDEVNAME_SIZE];
  40908. bdevname(rdev->bdev, b);
  40909. @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
  40910. "md/raid10:%s: %s: Raid device exceeded "
  40911. "read_error threshold [cur %d:max %d]\n",
  40912. mdname(mddev), b,
  40913. - atomic_read(&rdev->read_errors), max_read_errors);
  40914. + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
  40915. printk(KERN_NOTICE
  40916. "md/raid10:%s: %s: Failing raid device\n",
  40917. mdname(mddev), b);
  40918. @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
  40919. sect +
  40920. choose_data_offset(r10_bio, rdev)),
  40921. bdevname(rdev->bdev, b));
  40922. - atomic_add(s, &rdev->corrected_errors);
  40923. + atomic_add_unchecked(s, &rdev->corrected_errors);
  40924. }
  40925. rdev_dec_pending(rdev, mddev);
  40926. diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
  40927. index 16f5c21..4df20dc 100644
  40928. --- a/drivers/md/raid5.c
  40929. +++ b/drivers/md/raid5.c
  40930. @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
  40931. mdname(conf->mddev), STRIPE_SECTORS,
  40932. (unsigned long long)s,
  40933. bdevname(rdev->bdev, b));
  40934. - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
  40935. + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
  40936. clear_bit(R5_ReadError, &sh->dev[i].flags);
  40937. clear_bit(R5_ReWrite, &sh->dev[i].flags);
  40938. } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
  40939. clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
  40940. - if (atomic_read(&rdev->read_errors))
  40941. - atomic_set(&rdev->read_errors, 0);
  40942. + if (atomic_read_unchecked(&rdev->read_errors))
  40943. + atomic_set_unchecked(&rdev->read_errors, 0);
  40944. } else {
  40945. const char *bdn = bdevname(rdev->bdev, b);
  40946. int retry = 0;
  40947. int set_bad = 0;
  40948. clear_bit(R5_UPTODATE, &sh->dev[i].flags);
  40949. - atomic_inc(&rdev->read_errors);
  40950. + atomic_inc_unchecked(&rdev->read_errors);
  40951. if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
  40952. printk_ratelimited(
  40953. KERN_WARNING
  40954. @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
  40955. mdname(conf->mddev),
  40956. (unsigned long long)s,
  40957. bdn);
  40958. - } else if (atomic_read(&rdev->read_errors)
  40959. + } else if (atomic_read_unchecked(&rdev->read_errors)
  40960. > conf->max_nr_stripes)
  40961. printk(KERN_WARNING
  40962. "md/raid:%s: Too many read errors, failing device %s.\n",
  40963. diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
  40964. index 983db75..ef9248c 100644
  40965. --- a/drivers/media/dvb-core/dvbdev.c
  40966. +++ b/drivers/media/dvb-core/dvbdev.c
  40967. @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
  40968. const struct dvb_device *template, void *priv, int type)
  40969. {
  40970. struct dvb_device *dvbdev;
  40971. - struct file_operations *dvbdevfops;
  40972. + file_operations_no_const *dvbdevfops;
  40973. struct device *clsdev;
  40974. int minor;
  40975. int id;
  40976. diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
  40977. index 9b6c3bb..baeb5c7 100644
  40978. --- a/drivers/media/dvb-frontends/dib3000.h
  40979. +++ b/drivers/media/dvb-frontends/dib3000.h
  40980. @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
  40981. int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
  40982. int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
  40983. int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
  40984. -};
  40985. +} __no_const;
  40986. #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
  40987. extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
  40988. diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
  40989. index d5a7a13..703560f 100644
  40990. --- a/drivers/media/media-device.c
  40991. +++ b/drivers/media/media-device.c
  40992. @@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
  40993. struct media_entity *ent;
  40994. struct media_entity_desc u_ent;
  40995. + memset(&u_ent, 0, sizeof(u_ent));
  40996. if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
  40997. return -EFAULT;
  40998. diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
  40999. index ed8cb90..5ef7f79 100644
  41000. --- a/drivers/media/pci/cx88/cx88-video.c
  41001. +++ b/drivers/media/pci/cx88/cx88-video.c
  41002. @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
  41003. /* ------------------------------------------------------------------ */
  41004. -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
  41005. -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
  41006. -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
  41007. +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
  41008. +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
  41009. +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
  41010. module_param_array(video_nr, int, NULL, 0444);
  41011. module_param_array(vbi_nr, int, NULL, 0444);
  41012. diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
  41013. index 802642d..5534900 100644
  41014. --- a/drivers/media/pci/ivtv/ivtv-driver.c
  41015. +++ b/drivers/media/pci/ivtv/ivtv-driver.c
  41016. @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
  41017. MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
  41018. /* ivtv instance counter */
  41019. -static atomic_t ivtv_instance = ATOMIC_INIT(0);
  41020. +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
  41021. /* Parameter declarations */
  41022. static int cardtype[IVTV_MAX_CARDS];
  41023. diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
  41024. index dfd0a21..6bbb465 100644
  41025. --- a/drivers/media/platform/omap/omap_vout.c
  41026. +++ b/drivers/media/platform/omap/omap_vout.c
  41027. @@ -63,7 +63,6 @@ enum omap_vout_channels {
  41028. OMAP_VIDEO2,
  41029. };
  41030. -static struct videobuf_queue_ops video_vbq_ops;
  41031. /* Variables configurable through module params*/
  41032. static u32 video1_numbuffers = 3;
  41033. static u32 video2_numbuffers = 3;
  41034. @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
  41035. {
  41036. struct videobuf_queue *q;
  41037. struct omap_vout_device *vout = NULL;
  41038. + static struct videobuf_queue_ops video_vbq_ops = {
  41039. + .buf_setup = omap_vout_buffer_setup,
  41040. + .buf_prepare = omap_vout_buffer_prepare,
  41041. + .buf_release = omap_vout_buffer_release,
  41042. + .buf_queue = omap_vout_buffer_queue,
  41043. + };
  41044. vout = video_drvdata(file);
  41045. v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
  41046. @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
  41047. vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  41048. q = &vout->vbq;
  41049. - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
  41050. - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
  41051. - video_vbq_ops.buf_release = omap_vout_buffer_release;
  41052. - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
  41053. spin_lock_init(&vout->vbq_lock);
  41054. videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
  41055. diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
  41056. index fb2acc5..a2fcbdc4 100644
  41057. --- a/drivers/media/platform/s5p-tv/mixer.h
  41058. +++ b/drivers/media/platform/s5p-tv/mixer.h
  41059. @@ -156,7 +156,7 @@ struct mxr_layer {
  41060. /** layer index (unique identifier) */
  41061. int idx;
  41062. /** callbacks for layer methods */
  41063. - struct mxr_layer_ops ops;
  41064. + struct mxr_layer_ops *ops;
  41065. /** format array */
  41066. const struct mxr_format **fmt_array;
  41067. /** size of format array */
  41068. diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
  41069. index 74344c7..a39e70e 100644
  41070. --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
  41071. +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
  41072. @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
  41073. {
  41074. struct mxr_layer *layer;
  41075. int ret;
  41076. - struct mxr_layer_ops ops = {
  41077. + static struct mxr_layer_ops ops = {
  41078. .release = mxr_graph_layer_release,
  41079. .buffer_set = mxr_graph_buffer_set,
  41080. .stream_set = mxr_graph_stream_set,
  41081. diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
  41082. index b713403..53cb5ad 100644
  41083. --- a/drivers/media/platform/s5p-tv/mixer_reg.c
  41084. +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
  41085. @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
  41086. layer->update_buf = next;
  41087. }
  41088. - layer->ops.buffer_set(layer, layer->update_buf);
  41089. + layer->ops->buffer_set(layer, layer->update_buf);
  41090. if (done && done != layer->shadow_buf)
  41091. vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
  41092. diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
  41093. index c5059ba..2649f28 100644
  41094. --- a/drivers/media/platform/s5p-tv/mixer_video.c
  41095. +++ b/drivers/media/platform/s5p-tv/mixer_video.c
  41096. @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
  41097. layer->geo.src.height = layer->geo.src.full_height;
  41098. mxr_geometry_dump(mdev, &layer->geo);
  41099. - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
  41100. + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
  41101. mxr_geometry_dump(mdev, &layer->geo);
  41102. }
  41103. @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
  41104. layer->geo.dst.full_width = mbus_fmt.width;
  41105. layer->geo.dst.full_height = mbus_fmt.height;
  41106. layer->geo.dst.field = mbus_fmt.field;
  41107. - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
  41108. + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
  41109. mxr_geometry_dump(mdev, &layer->geo);
  41110. }
  41111. @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
  41112. /* set source size to highest accepted value */
  41113. geo->src.full_width = max(geo->dst.full_width, pix->width);
  41114. geo->src.full_height = max(geo->dst.full_height, pix->height);
  41115. - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
  41116. + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
  41117. mxr_geometry_dump(mdev, &layer->geo);
  41118. /* set cropping to total visible screen */
  41119. geo->src.width = pix->width;
  41120. @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
  41121. geo->src.x_offset = 0;
  41122. geo->src.y_offset = 0;
  41123. /* assure consistency of geometry */
  41124. - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
  41125. + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
  41126. mxr_geometry_dump(mdev, &layer->geo);
  41127. /* set full size to lowest possible value */
  41128. geo->src.full_width = 0;
  41129. geo->src.full_height = 0;
  41130. - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
  41131. + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
  41132. mxr_geometry_dump(mdev, &layer->geo);
  41133. /* returning results */
  41134. @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
  41135. target->width = s->r.width;
  41136. target->height = s->r.height;
  41137. - layer->ops.fix_geometry(layer, stage, s->flags);
  41138. + layer->ops->fix_geometry(layer, stage, s->flags);
  41139. /* retrieve update selection rectangle */
  41140. res.left = target->x_offset;
  41141. @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
  41142. mxr_output_get(mdev);
  41143. mxr_layer_update_output(layer);
  41144. - layer->ops.format_set(layer);
  41145. + layer->ops->format_set(layer);
  41146. /* enabling layer in hardware */
  41147. spin_lock_irqsave(&layer->enq_slock, flags);
  41148. layer->state = MXR_LAYER_STREAMING;
  41149. spin_unlock_irqrestore(&layer->enq_slock, flags);
  41150. - layer->ops.stream_set(layer, MXR_ENABLE);
  41151. + layer->ops->stream_set(layer, MXR_ENABLE);
  41152. mxr_streamer_get(mdev);
  41153. return 0;
  41154. @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
  41155. spin_unlock_irqrestore(&layer->enq_slock, flags);
  41156. /* disabling layer in hardware */
  41157. - layer->ops.stream_set(layer, MXR_DISABLE);
  41158. + layer->ops->stream_set(layer, MXR_DISABLE);
  41159. /* remove one streamer */
  41160. mxr_streamer_put(mdev);
  41161. /* allow changes in output configuration */
  41162. @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
  41163. void mxr_layer_release(struct mxr_layer *layer)
  41164. {
  41165. - if (layer->ops.release)
  41166. - layer->ops.release(layer);
  41167. + if (layer->ops->release)
  41168. + layer->ops->release(layer);
  41169. }
  41170. void mxr_base_layer_release(struct mxr_layer *layer)
  41171. @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
  41172. layer->mdev = mdev;
  41173. layer->idx = idx;
  41174. - layer->ops = *ops;
  41175. + layer->ops = ops;
  41176. spin_lock_init(&layer->enq_slock);
  41177. INIT_LIST_HEAD(&layer->enq_list);
  41178. diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
  41179. index c9388c4..ce71ece 100644
  41180. --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
  41181. +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
  41182. @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
  41183. {
  41184. struct mxr_layer *layer;
  41185. int ret;
  41186. - struct mxr_layer_ops ops = {
  41187. + static struct mxr_layer_ops ops = {
  41188. .release = mxr_vp_layer_release,
  41189. .buffer_set = mxr_vp_buffer_set,
  41190. .stream_set = mxr_vp_stream_set,
  41191. diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
  41192. index 2d4e73b..8b4d5b6 100644
  41193. --- a/drivers/media/platform/vivi.c
  41194. +++ b/drivers/media/platform/vivi.c
  41195. @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
  41196. MODULE_LICENSE("Dual BSD/GPL");
  41197. MODULE_VERSION(VIVI_VERSION);
  41198. -static unsigned video_nr = -1;
  41199. -module_param(video_nr, uint, 0644);
  41200. +static int video_nr = -1;
  41201. +module_param(video_nr, int, 0644);
  41202. MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
  41203. static unsigned n_devs = 1;
  41204. diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
  41205. index 545c04c..a14bded 100644
  41206. --- a/drivers/media/radio/radio-cadet.c
  41207. +++ b/drivers/media/radio/radio-cadet.c
  41208. @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
  41209. unsigned char readbuf[RDS_BUFFER];
  41210. int i = 0;
  41211. + if (count > RDS_BUFFER)
  41212. + return -EFAULT;
  41213. mutex_lock(&dev->lock);
  41214. if (dev->rdsstat == 0)
  41215. cadet_start_rds(dev);
  41216. @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
  41217. while (i < count && dev->rdsin != dev->rdsout)
  41218. readbuf[i++] = dev->rdsbuf[dev->rdsout++];
  41219. - if (i && copy_to_user(data, readbuf, i))
  41220. + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
  41221. i = -EFAULT;
  41222. unlock:
  41223. mutex_unlock(&dev->lock);
  41224. diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
  41225. index 5236035..c622c74 100644
  41226. --- a/drivers/media/radio/radio-maxiradio.c
  41227. +++ b/drivers/media/radio/radio-maxiradio.c
  41228. @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
  41229. /* TEA5757 pin mappings */
  41230. static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
  41231. -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
  41232. +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
  41233. #define PCI_VENDOR_ID_GUILLEMOT 0x5046
  41234. #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
  41235. diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
  41236. index 050b3bb..79f62b9 100644
  41237. --- a/drivers/media/radio/radio-shark.c
  41238. +++ b/drivers/media/radio/radio-shark.c
  41239. @@ -79,7 +79,7 @@ struct shark_device {
  41240. u32 last_val;
  41241. };
  41242. -static atomic_t shark_instance = ATOMIC_INIT(0);
  41243. +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
  41244. static void shark_write_val(struct snd_tea575x *tea, u32 val)
  41245. {
  41246. diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
  41247. index 8654e0d..0608a64 100644
  41248. --- a/drivers/media/radio/radio-shark2.c
  41249. +++ b/drivers/media/radio/radio-shark2.c
  41250. @@ -74,7 +74,7 @@ struct shark_device {
  41251. u8 *transfer_buffer;
  41252. };
  41253. -static atomic_t shark_instance = ATOMIC_INIT(0);
  41254. +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
  41255. static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
  41256. {
  41257. diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
  41258. index 2fd9009..278cc1e 100644
  41259. --- a/drivers/media/radio/radio-si476x.c
  41260. +++ b/drivers/media/radio/radio-si476x.c
  41261. @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
  41262. struct si476x_radio *radio;
  41263. struct v4l2_ctrl *ctrl;
  41264. - static atomic_t instance = ATOMIC_INIT(0);
  41265. + static atomic_unchecked_t instance = ATOMIC_INIT(0);
  41266. radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
  41267. if (!radio)
  41268. diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
  41269. index a1c641e..3007da9 100644
  41270. --- a/drivers/media/usb/dvb-usb/cxusb.c
  41271. +++ b/drivers/media/usb/dvb-usb/cxusb.c
  41272. @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
  41273. struct dib0700_adapter_state {
  41274. int (*set_param_save) (struct dvb_frontend *);
  41275. -};
  41276. +} __no_const;
  41277. static int dib7070_set_param_override(struct dvb_frontend *fe)
  41278. {
  41279. diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
  41280. index ae0f56a..ec71784 100644
  41281. --- a/drivers/media/usb/dvb-usb/dw2102.c
  41282. +++ b/drivers/media/usb/dvb-usb/dw2102.c
  41283. @@ -118,7 +118,7 @@ struct su3000_state {
  41284. struct s6x0_state {
  41285. int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
  41286. -};
  41287. +} __no_const;
  41288. /* debug */
  41289. static int dvb_usb_dw2102_debug;
  41290. diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
  41291. index b63a5e5..b16a062 100644
  41292. --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
  41293. +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
  41294. @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
  41295. __u32 reserved;
  41296. };
  41297. -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
  41298. +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
  41299. enum v4l2_memory memory)
  41300. {
  41301. void __user *up_pln;
  41302. @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
  41303. return 0;
  41304. }
  41305. -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
  41306. +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
  41307. enum v4l2_memory memory)
  41308. {
  41309. if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
  41310. @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
  41311. * by passing a very big num_planes value */
  41312. uplane = compat_alloc_user_space(num_planes *
  41313. sizeof(struct v4l2_plane));
  41314. - kp->m.planes = uplane;
  41315. + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
  41316. while (--num_planes >= 0) {
  41317. ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
  41318. @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
  41319. if (num_planes == 0)
  41320. return 0;
  41321. - uplane = kp->m.planes;
  41322. + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
  41323. if (get_user(p, &up->m.planes))
  41324. return -EFAULT;
  41325. uplane32 = compat_ptr(p);
  41326. @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
  41327. get_user(kp->capability, &up->capability) ||
  41328. get_user(kp->flags, &up->flags))
  41329. return -EFAULT;
  41330. - kp->base = compat_ptr(tmp);
  41331. + kp->base = (void __force_kernel *)compat_ptr(tmp);
  41332. get_v4l2_pix_format(&kp->fmt, &up->fmt);
  41333. return 0;
  41334. }
  41335. @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
  41336. n * sizeof(struct v4l2_ext_control32)))
  41337. return -EFAULT;
  41338. kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
  41339. - kp->controls = kcontrols;
  41340. + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
  41341. while (--n >= 0) {
  41342. if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
  41343. return -EFAULT;
  41344. @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
  41345. static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
  41346. {
  41347. struct v4l2_ext_control32 __user *ucontrols;
  41348. - struct v4l2_ext_control __user *kcontrols = kp->controls;
  41349. + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
  41350. int n = kp->count;
  41351. compat_caddr_t p;
  41352. @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
  41353. put_user(kp->start_block, &up->start_block) ||
  41354. put_user(kp->blocks, &up->blocks) ||
  41355. put_user(tmp, &up->edid) ||
  41356. - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
  41357. + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
  41358. return -EFAULT;
  41359. return 0;
  41360. }
  41361. diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
  41362. index 6ff002b..6b9316b 100644
  41363. --- a/drivers/media/v4l2-core/v4l2-ctrls.c
  41364. +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
  41365. @@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
  41366. return 0;
  41367. case V4L2_CTRL_TYPE_STRING:
  41368. - len = strlen(c->string);
  41369. - if (len < ctrl->minimum)
  41370. + len = strlen_user(c->string);
  41371. + if (!len || len < ctrl->minimum)
  41372. return -ERANGE;
  41373. if ((len - ctrl->minimum) % ctrl->step)
  41374. return -ERANGE;
  41375. diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
  41376. index 02d1b63..5fd6b16 100644
  41377. --- a/drivers/media/v4l2-core/v4l2-device.c
  41378. +++ b/drivers/media/v4l2-core/v4l2-device.c
  41379. @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
  41380. EXPORT_SYMBOL_GPL(v4l2_device_put);
  41381. int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
  41382. - atomic_t *instance)
  41383. + atomic_unchecked_t *instance)
  41384. {
  41385. - int num = atomic_inc_return(instance) - 1;
  41386. + int num = atomic_inc_return_unchecked(instance) - 1;
  41387. int len = strlen(basename);
  41388. if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
  41389. diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
  41390. index 707aef7..93b8ac0 100644
  41391. --- a/drivers/media/v4l2-core/v4l2-ioctl.c
  41392. +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
  41393. @@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
  41394. struct file *file, void *fh, void *p);
  41395. } u;
  41396. void (*debug)(const void *arg, bool write_only);
  41397. -};
  41398. +} __do_const;
  41399. +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
  41400. /* This control needs a priority check */
  41401. #define INFO_FL_PRIO (1 << 0)
  41402. @@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
  41403. struct video_device *vfd = video_devdata(file);
  41404. const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
  41405. bool write_only = false;
  41406. - struct v4l2_ioctl_info default_info;
  41407. + v4l2_ioctl_info_no_const default_info;
  41408. const struct v4l2_ioctl_info *info;
  41409. void *fh = file->private_data;
  41410. struct v4l2_fh *vfh = NULL;
  41411. @@ -2197,7 +2198,7 @@ done:
  41412. }
  41413. static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
  41414. - void * __user *user_ptr, void ***kernel_ptr)
  41415. + void __user **user_ptr, void ***kernel_ptr)
  41416. {
  41417. int ret = 0;
  41418. @@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
  41419. ret = -EINVAL;
  41420. break;
  41421. }
  41422. - *user_ptr = (void __user *)buf->m.planes;
  41423. + *user_ptr = (void __force_user *)buf->m.planes;
  41424. *kernel_ptr = (void *)&buf->m.planes;
  41425. *array_size = sizeof(struct v4l2_plane) * buf->length;
  41426. ret = 1;
  41427. @@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
  41428. ret = -EINVAL;
  41429. break;
  41430. }
  41431. - *user_ptr = (void __user *)ctrls->controls;
  41432. + *user_ptr = (void __force_user *)ctrls->controls;
  41433. *kernel_ptr = (void *)&ctrls->controls;
  41434. *array_size = sizeof(struct v4l2_ext_control)
  41435. * ctrls->count;
  41436. @@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
  41437. }
  41438. if (has_array_args) {
  41439. - *kernel_ptr = user_ptr;
  41440. + *kernel_ptr = (void __force_kernel *)user_ptr;
  41441. if (copy_to_user(user_ptr, mbuf, array_size))
  41442. err = -EFAULT;
  41443. goto out_array_args;
  41444. diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
  41445. index 570b18a..f880314 100644
  41446. --- a/drivers/message/fusion/mptbase.c
  41447. +++ b/drivers/message/fusion/mptbase.c
  41448. @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
  41449. seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  41450. seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  41451. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  41452. + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
  41453. +#else
  41454. seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  41455. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  41456. +#endif
  41457. +
  41458. /*
  41459. * Rounding UP to nearest 4-kB boundary here...
  41460. */
  41461. @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
  41462. ioc->facts.GlobalCredits);
  41463. seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
  41464. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  41465. + NULL, NULL);
  41466. +#else
  41467. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  41468. +#endif
  41469. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  41470. seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  41471. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  41472. diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
  41473. index 00d339c..2ea899d 100644
  41474. --- a/drivers/message/fusion/mptsas.c
  41475. +++ b/drivers/message/fusion/mptsas.c
  41476. @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
  41477. return 0;
  41478. }
  41479. +static inline void
  41480. +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
  41481. +{
  41482. + if (phy_info->port_details) {
  41483. + phy_info->port_details->rphy = rphy;
  41484. + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
  41485. + ioc->name, rphy));
  41486. + }
  41487. +
  41488. + if (rphy) {
  41489. + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  41490. + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
  41491. + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
  41492. + ioc->name, rphy, rphy->dev.release));
  41493. + }
  41494. +}
  41495. +
  41496. /* no mutex */
  41497. static void
  41498. mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
  41499. @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
  41500. return NULL;
  41501. }
  41502. -static inline void
  41503. -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
  41504. -{
  41505. - if (phy_info->port_details) {
  41506. - phy_info->port_details->rphy = rphy;
  41507. - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
  41508. - ioc->name, rphy));
  41509. - }
  41510. -
  41511. - if (rphy) {
  41512. - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  41513. - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
  41514. - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
  41515. - ioc->name, rphy, rphy->dev.release));
  41516. - }
  41517. -}
  41518. -
  41519. static inline struct sas_port *
  41520. mptsas_get_port(struct mptsas_phyinfo *phy_info)
  41521. {
  41522. diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
  41523. index 727819c..ad74694 100644
  41524. --- a/drivers/message/fusion/mptscsih.c
  41525. +++ b/drivers/message/fusion/mptscsih.c
  41526. @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
  41527. h = shost_priv(SChost);
  41528. - if (h) {
  41529. - if (h->info_kbuf == NULL)
  41530. - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  41531. - return h->info_kbuf;
  41532. - h->info_kbuf[0] = '\0';
  41533. + if (!h)
  41534. + return NULL;
  41535. - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  41536. - h->info_kbuf[size-1] = '\0';
  41537. - }
  41538. + if (h->info_kbuf == NULL)
  41539. + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  41540. + return h->info_kbuf;
  41541. + h->info_kbuf[0] = '\0';
  41542. +
  41543. + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  41544. + h->info_kbuf[size-1] = '\0';
  41545. return h->info_kbuf;
  41546. }
  41547. diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
  41548. index b7d87cd..3fb36da 100644
  41549. --- a/drivers/message/i2o/i2o_proc.c
  41550. +++ b/drivers/message/i2o/i2o_proc.c
  41551. @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
  41552. "Array Controller Device"
  41553. };
  41554. -static char *chtostr(char *tmp, u8 *chars, int n)
  41555. -{
  41556. - tmp[0] = 0;
  41557. - return strncat(tmp, (char *)chars, n);
  41558. -}
  41559. -
  41560. static int i2o_report_query_status(struct seq_file *seq, int block_status,
  41561. char *group)
  41562. {
  41563. @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
  41564. static int i2o_seq_show_hw(struct seq_file *seq, void *v)
  41565. {
  41566. struct i2o_controller *c = (struct i2o_controller *)seq->private;
  41567. - static u32 work32[5];
  41568. - static u8 *work8 = (u8 *) work32;
  41569. - static u16 *work16 = (u16 *) work32;
  41570. + u32 work32[5];
  41571. + u8 *work8 = (u8 *) work32;
  41572. + u16 *work16 = (u16 *) work32;
  41573. int token;
  41574. u32 hwcap;
  41575. @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
  41576. } *result;
  41577. i2o_exec_execute_ddm_table ddm_table;
  41578. - char tmp[28 + 1];
  41579. result = kmalloc(sizeof(*result), GFP_KERNEL);
  41580. if (!result)
  41581. @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
  41582. seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
  41583. seq_printf(seq, "%-#8x", ddm_table.module_id);
  41584. - seq_printf(seq, "%-29s",
  41585. - chtostr(tmp, ddm_table.module_name_version, 28));
  41586. + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
  41587. seq_printf(seq, "%9d ", ddm_table.data_size);
  41588. seq_printf(seq, "%8d", ddm_table.code_size);
  41589. @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
  41590. i2o_driver_result_table *result;
  41591. i2o_driver_store_table *dst;
  41592. - char tmp[28 + 1];
  41593. result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
  41594. if (result == NULL)
  41595. @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
  41596. seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
  41597. seq_printf(seq, "%-#8x", dst->module_id);
  41598. - seq_printf(seq, "%-29s",
  41599. - chtostr(tmp, dst->module_name_version, 28));
  41600. - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
  41601. + seq_printf(seq, "%-.28s", dst->module_name_version);
  41602. + seq_printf(seq, "%-.8s", dst->date);
  41603. seq_printf(seq, "%8d ", dst->module_size);
  41604. seq_printf(seq, "%8d ", dst->mpb_size);
  41605. seq_printf(seq, "0x%04x", dst->module_flags);
  41606. @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
  41607. static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
  41608. {
  41609. struct i2o_device *d = (struct i2o_device *)seq->private;
  41610. - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
  41611. + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
  41612. // == (allow) 512d bytes (max)
  41613. - static u16 *work16 = (u16 *) work32;
  41614. + u16 *work16 = (u16 *) work32;
  41615. int token;
  41616. - char tmp[16 + 1];
  41617. token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
  41618. @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
  41619. seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
  41620. seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
  41621. seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
  41622. - seq_printf(seq, "Vendor info : %s\n",
  41623. - chtostr(tmp, (u8 *) (work32 + 2), 16));
  41624. - seq_printf(seq, "Product info : %s\n",
  41625. - chtostr(tmp, (u8 *) (work32 + 6), 16));
  41626. - seq_printf(seq, "Description : %s\n",
  41627. - chtostr(tmp, (u8 *) (work32 + 10), 16));
  41628. - seq_printf(seq, "Product rev. : %s\n",
  41629. - chtostr(tmp, (u8 *) (work32 + 14), 8));
  41630. + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
  41631. + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
  41632. + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
  41633. + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
  41634. seq_printf(seq, "Serial number : ");
  41635. print_serial_number(seq, (u8 *) (work32 + 16),
  41636. @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
  41637. u8 pad[256]; // allow up to 256 byte (max) serial number
  41638. } result;
  41639. - char tmp[24 + 1];
  41640. -
  41641. token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
  41642. if (token < 0) {
  41643. @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
  41644. }
  41645. seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
  41646. - seq_printf(seq, "Module name : %s\n",
  41647. - chtostr(tmp, result.module_name, 24));
  41648. - seq_printf(seq, "Module revision : %s\n",
  41649. - chtostr(tmp, result.module_rev, 8));
  41650. + seq_printf(seq, "Module name : %.24s\n", result.module_name);
  41651. + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
  41652. seq_printf(seq, "Serial number : ");
  41653. print_serial_number(seq, result.serial_number, sizeof(result) - 36);
  41654. @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
  41655. u8 instance_number[4];
  41656. } result;
  41657. - char tmp[64 + 1];
  41658. -
  41659. token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
  41660. if (token < 0) {
  41661. @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
  41662. return 0;
  41663. }
  41664. - seq_printf(seq, "Device name : %s\n",
  41665. - chtostr(tmp, result.device_name, 64));
  41666. - seq_printf(seq, "Service name : %s\n",
  41667. - chtostr(tmp, result.service_name, 64));
  41668. - seq_printf(seq, "Physical name : %s\n",
  41669. - chtostr(tmp, result.physical_location, 64));
  41670. - seq_printf(seq, "Instance number : %s\n",
  41671. - chtostr(tmp, result.instance_number, 4));
  41672. + seq_printf(seq, "Device name : %.64s\n", result.device_name);
  41673. + seq_printf(seq, "Service name : %.64s\n", result.service_name);
  41674. + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
  41675. + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
  41676. return 0;
  41677. }
  41678. @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
  41679. static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
  41680. {
  41681. struct i2o_device *d = (struct i2o_device *)seq->private;
  41682. - static u32 work32[12];
  41683. - static u16 *work16 = (u16 *) work32;
  41684. - static u8 *work8 = (u8 *) work32;
  41685. + u32 work32[12];
  41686. + u16 *work16 = (u16 *) work32;
  41687. + u8 *work8 = (u8 *) work32;
  41688. int token;
  41689. token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
  41690. diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
  41691. index a8c08f3..155fe3d 100644
  41692. --- a/drivers/message/i2o/iop.c
  41693. +++ b/drivers/message/i2o/iop.c
  41694. @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
  41695. spin_lock_irqsave(&c->context_list_lock, flags);
  41696. - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
  41697. - atomic_inc(&c->context_list_counter);
  41698. + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
  41699. + atomic_inc_unchecked(&c->context_list_counter);
  41700. - entry->context = atomic_read(&c->context_list_counter);
  41701. + entry->context = atomic_read_unchecked(&c->context_list_counter);
  41702. list_add(&entry->list, &c->context_list);
  41703. @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
  41704. #if BITS_PER_LONG == 64
  41705. spin_lock_init(&c->context_list_lock);
  41706. - atomic_set(&c->context_list_counter, 0);
  41707. + atomic_set_unchecked(&c->context_list_counter, 0);
  41708. INIT_LIST_HEAD(&c->context_list);
  41709. #endif
  41710. diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
  41711. index d1a22aa..d0f7bf7 100644
  41712. --- a/drivers/mfd/ab8500-debugfs.c
  41713. +++ b/drivers/mfd/ab8500-debugfs.c
  41714. @@ -100,7 +100,7 @@ static int irq_last;
  41715. static u32 *irq_count;
  41716. static int num_irqs;
  41717. -static struct device_attribute **dev_attr;
  41718. +static device_attribute_no_const **dev_attr;
  41719. static char **event_name;
  41720. static u8 avg_sample = SAMPLE_16;
  41721. diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
  41722. index 81b7d88..95ae998 100644
  41723. --- a/drivers/mfd/janz-cmodio.c
  41724. +++ b/drivers/mfd/janz-cmodio.c
  41725. @@ -13,6 +13,7 @@
  41726. #include <linux/kernel.h>
  41727. #include <linux/module.h>
  41728. +#include <linux/slab.h>
  41729. #include <linux/init.h>
  41730. #include <linux/pci.h>
  41731. #include <linux/interrupt.h>
  41732. diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
  41733. index a83eed5..62a58a9 100644
  41734. --- a/drivers/mfd/max8925-i2c.c
  41735. +++ b/drivers/mfd/max8925-i2c.c
  41736. @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
  41737. const struct i2c_device_id *id)
  41738. {
  41739. struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
  41740. - static struct max8925_chip *chip;
  41741. + struct max8925_chip *chip;
  41742. struct device_node *node = client->dev.of_node;
  41743. if (node && !pdata) {
  41744. diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
  41745. index d657331..0d9a80f 100644
  41746. --- a/drivers/mfd/tps65910.c
  41747. +++ b/drivers/mfd/tps65910.c
  41748. @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
  41749. struct tps65910_platform_data *pdata)
  41750. {
  41751. int ret = 0;
  41752. - static struct regmap_irq_chip *tps6591x_irqs_chip;
  41753. + struct regmap_irq_chip *tps6591x_irqs_chip;
  41754. if (!irq) {
  41755. dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
  41756. diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
  41757. index 9aa6d1e..1631bfc 100644
  41758. --- a/drivers/mfd/twl4030-irq.c
  41759. +++ b/drivers/mfd/twl4030-irq.c
  41760. @@ -35,6 +35,7 @@
  41761. #include <linux/of.h>
  41762. #include <linux/irqdomain.h>
  41763. #include <linux/i2c/twl.h>
  41764. +#include <asm/pgtable.h>
  41765. #include "twl-core.h"
  41766. @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
  41767. * Install an irq handler for each of the SIH modules;
  41768. * clone dummy irq_chip since PIH can't *do* anything
  41769. */
  41770. - twl4030_irq_chip = dummy_irq_chip;
  41771. - twl4030_irq_chip.name = "twl4030";
  41772. + pax_open_kernel();
  41773. + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
  41774. + *(const char **)&twl4030_irq_chip.name = "twl4030";
  41775. - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
  41776. + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
  41777. + pax_close_kernel();
  41778. for (i = irq_base; i < irq_end; i++) {
  41779. irq_set_chip_and_handler(i, &twl4030_irq_chip,
  41780. diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
  41781. index 464419b..64bae8d 100644
  41782. --- a/drivers/misc/c2port/core.c
  41783. +++ b/drivers/misc/c2port/core.c
  41784. @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
  41785. goto error_idr_alloc;
  41786. c2dev->id = ret;
  41787. - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
  41788. + pax_open_kernel();
  41789. + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
  41790. + pax_close_kernel();
  41791. c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
  41792. "c2port%d", c2dev->id);
  41793. diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
  41794. index 9c34e57..b981cda 100644
  41795. --- a/drivers/misc/eeprom/sunxi_sid.c
  41796. +++ b/drivers/misc/eeprom/sunxi_sid.c
  41797. @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
  41798. platform_set_drvdata(pdev, sid_data);
  41799. - sid_bin_attr.size = sid_data->keysize;
  41800. + pax_open_kernel();
  41801. + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
  41802. + pax_close_kernel();
  41803. if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
  41804. return -ENODEV;
  41805. diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
  41806. index 36f5d52..32311c3 100644
  41807. --- a/drivers/misc/kgdbts.c
  41808. +++ b/drivers/misc/kgdbts.c
  41809. @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
  41810. char before[BREAK_INSTR_SIZE];
  41811. char after[BREAK_INSTR_SIZE];
  41812. - probe_kernel_read(before, (char *)kgdbts_break_test,
  41813. + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
  41814. BREAK_INSTR_SIZE);
  41815. init_simple_test();
  41816. ts.tst = plant_and_detach_test;
  41817. @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
  41818. /* Activate test with initial breakpoint */
  41819. if (!is_early)
  41820. kgdb_breakpoint();
  41821. - probe_kernel_read(after, (char *)kgdbts_break_test,
  41822. + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
  41823. BREAK_INSTR_SIZE);
  41824. if (memcmp(before, after, BREAK_INSTR_SIZE)) {
  41825. printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
  41826. diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
  41827. index 036effe..b3a6336 100644
  41828. --- a/drivers/misc/lis3lv02d/lis3lv02d.c
  41829. +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
  41830. @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
  41831. * the lid is closed. This leads to interrupts as soon as a little move
  41832. * is done.
  41833. */
  41834. - atomic_inc(&lis3->count);
  41835. + atomic_inc_unchecked(&lis3->count);
  41836. wake_up_interruptible(&lis3->misc_wait);
  41837. kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
  41838. @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
  41839. if (lis3->pm_dev)
  41840. pm_runtime_get_sync(lis3->pm_dev);
  41841. - atomic_set(&lis3->count, 0);
  41842. + atomic_set_unchecked(&lis3->count, 0);
  41843. return 0;
  41844. }
  41845. @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
  41846. add_wait_queue(&lis3->misc_wait, &wait);
  41847. while (true) {
  41848. set_current_state(TASK_INTERRUPTIBLE);
  41849. - data = atomic_xchg(&lis3->count, 0);
  41850. + data = atomic_xchg_unchecked(&lis3->count, 0);
  41851. if (data)
  41852. break;
  41853. @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
  41854. struct lis3lv02d, miscdev);
  41855. poll_wait(file, &lis3->misc_wait, wait);
  41856. - if (atomic_read(&lis3->count))
  41857. + if (atomic_read_unchecked(&lis3->count))
  41858. return POLLIN | POLLRDNORM;
  41859. return 0;
  41860. }
  41861. diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
  41862. index c439c82..1f20f57 100644
  41863. --- a/drivers/misc/lis3lv02d/lis3lv02d.h
  41864. +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
  41865. @@ -297,7 +297,7 @@ struct lis3lv02d {
  41866. struct input_polled_dev *idev; /* input device */
  41867. struct platform_device *pdev; /* platform device */
  41868. struct regulator_bulk_data regulators[2];
  41869. - atomic_t count; /* interrupt count after last read */
  41870. + atomic_unchecked_t count; /* interrupt count after last read */
  41871. union axis_conversion ac; /* hw -> logical axis */
  41872. int mapped_btns[3];
  41873. diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
  41874. index 2f30bad..c4c13d0 100644
  41875. --- a/drivers/misc/sgi-gru/gruhandles.c
  41876. +++ b/drivers/misc/sgi-gru/gruhandles.c
  41877. @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
  41878. unsigned long nsec;
  41879. nsec = CLKS2NSEC(clks);
  41880. - atomic_long_inc(&mcs_op_statistics[op].count);
  41881. - atomic_long_add(nsec, &mcs_op_statistics[op].total);
  41882. + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
  41883. + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
  41884. if (mcs_op_statistics[op].max < nsec)
  41885. mcs_op_statistics[op].max = nsec;
  41886. }
  41887. diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
  41888. index 4f76359..cdfcb2e 100644
  41889. --- a/drivers/misc/sgi-gru/gruprocfs.c
  41890. +++ b/drivers/misc/sgi-gru/gruprocfs.c
  41891. @@ -32,9 +32,9 @@
  41892. #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
  41893. -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
  41894. +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
  41895. {
  41896. - unsigned long val = atomic_long_read(v);
  41897. + unsigned long val = atomic_long_read_unchecked(v);
  41898. seq_printf(s, "%16lu %s\n", val, id);
  41899. }
  41900. @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
  41901. seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
  41902. for (op = 0; op < mcsop_last; op++) {
  41903. - count = atomic_long_read(&mcs_op_statistics[op].count);
  41904. - total = atomic_long_read(&mcs_op_statistics[op].total);
  41905. + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
  41906. + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
  41907. max = mcs_op_statistics[op].max;
  41908. seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
  41909. count ? total / count : 0, max);
  41910. diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
  41911. index 5c3ce24..4915ccb 100644
  41912. --- a/drivers/misc/sgi-gru/grutables.h
  41913. +++ b/drivers/misc/sgi-gru/grutables.h
  41914. @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
  41915. * GRU statistics.
  41916. */
  41917. struct gru_stats_s {
  41918. - atomic_long_t vdata_alloc;
  41919. - atomic_long_t vdata_free;
  41920. - atomic_long_t gts_alloc;
  41921. - atomic_long_t gts_free;
  41922. - atomic_long_t gms_alloc;
  41923. - atomic_long_t gms_free;
  41924. - atomic_long_t gts_double_allocate;
  41925. - atomic_long_t assign_context;
  41926. - atomic_long_t assign_context_failed;
  41927. - atomic_long_t free_context;
  41928. - atomic_long_t load_user_context;
  41929. - atomic_long_t load_kernel_context;
  41930. - atomic_long_t lock_kernel_context;
  41931. - atomic_long_t unlock_kernel_context;
  41932. - atomic_long_t steal_user_context;
  41933. - atomic_long_t steal_kernel_context;
  41934. - atomic_long_t steal_context_failed;
  41935. - atomic_long_t nopfn;
  41936. - atomic_long_t asid_new;
  41937. - atomic_long_t asid_next;
  41938. - atomic_long_t asid_wrap;
  41939. - atomic_long_t asid_reuse;
  41940. - atomic_long_t intr;
  41941. - atomic_long_t intr_cbr;
  41942. - atomic_long_t intr_tfh;
  41943. - atomic_long_t intr_spurious;
  41944. - atomic_long_t intr_mm_lock_failed;
  41945. - atomic_long_t call_os;
  41946. - atomic_long_t call_os_wait_queue;
  41947. - atomic_long_t user_flush_tlb;
  41948. - atomic_long_t user_unload_context;
  41949. - atomic_long_t user_exception;
  41950. - atomic_long_t set_context_option;
  41951. - atomic_long_t check_context_retarget_intr;
  41952. - atomic_long_t check_context_unload;
  41953. - atomic_long_t tlb_dropin;
  41954. - atomic_long_t tlb_preload_page;
  41955. - atomic_long_t tlb_dropin_fail_no_asid;
  41956. - atomic_long_t tlb_dropin_fail_upm;
  41957. - atomic_long_t tlb_dropin_fail_invalid;
  41958. - atomic_long_t tlb_dropin_fail_range_active;
  41959. - atomic_long_t tlb_dropin_fail_idle;
  41960. - atomic_long_t tlb_dropin_fail_fmm;
  41961. - atomic_long_t tlb_dropin_fail_no_exception;
  41962. - atomic_long_t tfh_stale_on_fault;
  41963. - atomic_long_t mmu_invalidate_range;
  41964. - atomic_long_t mmu_invalidate_page;
  41965. - atomic_long_t flush_tlb;
  41966. - atomic_long_t flush_tlb_gru;
  41967. - atomic_long_t flush_tlb_gru_tgh;
  41968. - atomic_long_t flush_tlb_gru_zero_asid;
  41969. + atomic_long_unchecked_t vdata_alloc;
  41970. + atomic_long_unchecked_t vdata_free;
  41971. + atomic_long_unchecked_t gts_alloc;
  41972. + atomic_long_unchecked_t gts_free;
  41973. + atomic_long_unchecked_t gms_alloc;
  41974. + atomic_long_unchecked_t gms_free;
  41975. + atomic_long_unchecked_t gts_double_allocate;
  41976. + atomic_long_unchecked_t assign_context;
  41977. + atomic_long_unchecked_t assign_context_failed;
  41978. + atomic_long_unchecked_t free_context;
  41979. + atomic_long_unchecked_t load_user_context;
  41980. + atomic_long_unchecked_t load_kernel_context;
  41981. + atomic_long_unchecked_t lock_kernel_context;
  41982. + atomic_long_unchecked_t unlock_kernel_context;
  41983. + atomic_long_unchecked_t steal_user_context;
  41984. + atomic_long_unchecked_t steal_kernel_context;
  41985. + atomic_long_unchecked_t steal_context_failed;
  41986. + atomic_long_unchecked_t nopfn;
  41987. + atomic_long_unchecked_t asid_new;
  41988. + atomic_long_unchecked_t asid_next;
  41989. + atomic_long_unchecked_t asid_wrap;
  41990. + atomic_long_unchecked_t asid_reuse;
  41991. + atomic_long_unchecked_t intr;
  41992. + atomic_long_unchecked_t intr_cbr;
  41993. + atomic_long_unchecked_t intr_tfh;
  41994. + atomic_long_unchecked_t intr_spurious;
  41995. + atomic_long_unchecked_t intr_mm_lock_failed;
  41996. + atomic_long_unchecked_t call_os;
  41997. + atomic_long_unchecked_t call_os_wait_queue;
  41998. + atomic_long_unchecked_t user_flush_tlb;
  41999. + atomic_long_unchecked_t user_unload_context;
  42000. + atomic_long_unchecked_t user_exception;
  42001. + atomic_long_unchecked_t set_context_option;
  42002. + atomic_long_unchecked_t check_context_retarget_intr;
  42003. + atomic_long_unchecked_t check_context_unload;
  42004. + atomic_long_unchecked_t tlb_dropin;
  42005. + atomic_long_unchecked_t tlb_preload_page;
  42006. + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
  42007. + atomic_long_unchecked_t tlb_dropin_fail_upm;
  42008. + atomic_long_unchecked_t tlb_dropin_fail_invalid;
  42009. + atomic_long_unchecked_t tlb_dropin_fail_range_active;
  42010. + atomic_long_unchecked_t tlb_dropin_fail_idle;
  42011. + atomic_long_unchecked_t tlb_dropin_fail_fmm;
  42012. + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
  42013. + atomic_long_unchecked_t tfh_stale_on_fault;
  42014. + atomic_long_unchecked_t mmu_invalidate_range;
  42015. + atomic_long_unchecked_t mmu_invalidate_page;
  42016. + atomic_long_unchecked_t flush_tlb;
  42017. + atomic_long_unchecked_t flush_tlb_gru;
  42018. + atomic_long_unchecked_t flush_tlb_gru_tgh;
  42019. + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
  42020. - atomic_long_t copy_gpa;
  42021. - atomic_long_t read_gpa;
  42022. + atomic_long_unchecked_t copy_gpa;
  42023. + atomic_long_unchecked_t read_gpa;
  42024. - atomic_long_t mesq_receive;
  42025. - atomic_long_t mesq_receive_none;
  42026. - atomic_long_t mesq_send;
  42027. - atomic_long_t mesq_send_failed;
  42028. - atomic_long_t mesq_noop;
  42029. - atomic_long_t mesq_send_unexpected_error;
  42030. - atomic_long_t mesq_send_lb_overflow;
  42031. - atomic_long_t mesq_send_qlimit_reached;
  42032. - atomic_long_t mesq_send_amo_nacked;
  42033. - atomic_long_t mesq_send_put_nacked;
  42034. - atomic_long_t mesq_page_overflow;
  42035. - atomic_long_t mesq_qf_locked;
  42036. - atomic_long_t mesq_qf_noop_not_full;
  42037. - atomic_long_t mesq_qf_switch_head_failed;
  42038. - atomic_long_t mesq_qf_unexpected_error;
  42039. - atomic_long_t mesq_noop_unexpected_error;
  42040. - atomic_long_t mesq_noop_lb_overflow;
  42041. - atomic_long_t mesq_noop_qlimit_reached;
  42042. - atomic_long_t mesq_noop_amo_nacked;
  42043. - atomic_long_t mesq_noop_put_nacked;
  42044. - atomic_long_t mesq_noop_page_overflow;
  42045. + atomic_long_unchecked_t mesq_receive;
  42046. + atomic_long_unchecked_t mesq_receive_none;
  42047. + atomic_long_unchecked_t mesq_send;
  42048. + atomic_long_unchecked_t mesq_send_failed;
  42049. + atomic_long_unchecked_t mesq_noop;
  42050. + atomic_long_unchecked_t mesq_send_unexpected_error;
  42051. + atomic_long_unchecked_t mesq_send_lb_overflow;
  42052. + atomic_long_unchecked_t mesq_send_qlimit_reached;
  42053. + atomic_long_unchecked_t mesq_send_amo_nacked;
  42054. + atomic_long_unchecked_t mesq_send_put_nacked;
  42055. + atomic_long_unchecked_t mesq_page_overflow;
  42056. + atomic_long_unchecked_t mesq_qf_locked;
  42057. + atomic_long_unchecked_t mesq_qf_noop_not_full;
  42058. + atomic_long_unchecked_t mesq_qf_switch_head_failed;
  42059. + atomic_long_unchecked_t mesq_qf_unexpected_error;
  42060. + atomic_long_unchecked_t mesq_noop_unexpected_error;
  42061. + atomic_long_unchecked_t mesq_noop_lb_overflow;
  42062. + atomic_long_unchecked_t mesq_noop_qlimit_reached;
  42063. + atomic_long_unchecked_t mesq_noop_amo_nacked;
  42064. + atomic_long_unchecked_t mesq_noop_put_nacked;
  42065. + atomic_long_unchecked_t mesq_noop_page_overflow;
  42066. };
  42067. @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
  42068. tghop_invalidate, mcsop_last};
  42069. struct mcs_op_statistic {
  42070. - atomic_long_t count;
  42071. - atomic_long_t total;
  42072. + atomic_long_unchecked_t count;
  42073. + atomic_long_unchecked_t total;
  42074. unsigned long max;
  42075. };
  42076. @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
  42077. #define STAT(id) do { \
  42078. if (gru_options & OPT_STATS) \
  42079. - atomic_long_inc(&gru_stats.id); \
  42080. + atomic_long_inc_unchecked(&gru_stats.id); \
  42081. } while (0)
  42082. #ifdef CONFIG_SGI_GRU_DEBUG
  42083. diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
  42084. index c862cd4..0d176fe 100644
  42085. --- a/drivers/misc/sgi-xp/xp.h
  42086. +++ b/drivers/misc/sgi-xp/xp.h
  42087. @@ -288,7 +288,7 @@ struct xpc_interface {
  42088. xpc_notify_func, void *);
  42089. void (*received) (short, int, void *);
  42090. enum xp_retval (*partid_to_nasids) (short, void *);
  42091. -};
  42092. +} __no_const;
  42093. extern struct xpc_interface xpc_interface;
  42094. diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
  42095. index 01be66d..e3a0c7e 100644
  42096. --- a/drivers/misc/sgi-xp/xp_main.c
  42097. +++ b/drivers/misc/sgi-xp/xp_main.c
  42098. @@ -78,13 +78,13 @@ xpc_notloaded(void)
  42099. }
  42100. struct xpc_interface xpc_interface = {
  42101. - (void (*)(int))xpc_notloaded,
  42102. - (void (*)(int))xpc_notloaded,
  42103. - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
  42104. - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
  42105. + .connect = (void (*)(int))xpc_notloaded,
  42106. + .disconnect = (void (*)(int))xpc_notloaded,
  42107. + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
  42108. + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
  42109. void *))xpc_notloaded,
  42110. - (void (*)(short, int, void *))xpc_notloaded,
  42111. - (enum xp_retval(*)(short, void *))xpc_notloaded
  42112. + .received = (void (*)(short, int, void *))xpc_notloaded,
  42113. + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
  42114. };
  42115. EXPORT_SYMBOL_GPL(xpc_interface);
  42116. diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
  42117. index b94d5f7..7f494c5 100644
  42118. --- a/drivers/misc/sgi-xp/xpc.h
  42119. +++ b/drivers/misc/sgi-xp/xpc.h
  42120. @@ -835,6 +835,7 @@ struct xpc_arch_operations {
  42121. void (*received_payload) (struct xpc_channel *, void *);
  42122. void (*notify_senders_of_disconnect) (struct xpc_channel *);
  42123. };
  42124. +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
  42125. /* struct xpc_partition act_state values (for XPC HB) */
  42126. @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
  42127. /* found in xpc_main.c */
  42128. extern struct device *xpc_part;
  42129. extern struct device *xpc_chan;
  42130. -extern struct xpc_arch_operations xpc_arch_ops;
  42131. +extern xpc_arch_operations_no_const xpc_arch_ops;
  42132. extern int xpc_disengage_timelimit;
  42133. extern int xpc_disengage_timedout;
  42134. extern int xpc_activate_IRQ_rcvd;
  42135. diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
  42136. index 82dc574..8539ab2 100644
  42137. --- a/drivers/misc/sgi-xp/xpc_main.c
  42138. +++ b/drivers/misc/sgi-xp/xpc_main.c
  42139. @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
  42140. .notifier_call = xpc_system_die,
  42141. };
  42142. -struct xpc_arch_operations xpc_arch_ops;
  42143. +xpc_arch_operations_no_const xpc_arch_ops;
  42144. /*
  42145. * Timer function to enforce the timelimit on the partition disengage.
  42146. @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
  42147. if (((die_args->trapnr == X86_TRAP_MF) ||
  42148. (die_args->trapnr == X86_TRAP_XF)) &&
  42149. - !user_mode_vm(die_args->regs))
  42150. + !user_mode(die_args->regs))
  42151. xpc_die_deactivate();
  42152. break;
  42153. diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
  42154. index 7b5424f..ed1d6ac 100644
  42155. --- a/drivers/mmc/card/block.c
  42156. +++ b/drivers/mmc/card/block.c
  42157. @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
  42158. if (idata->ic.postsleep_min_us)
  42159. usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
  42160. - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
  42161. + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
  42162. err = -EFAULT;
  42163. goto cmd_rel_host;
  42164. }
  42165. diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
  42166. index e5b5eeb..7bf2212 100644
  42167. --- a/drivers/mmc/core/mmc_ops.c
  42168. +++ b/drivers/mmc/core/mmc_ops.c
  42169. @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
  42170. void *data_buf;
  42171. int is_on_stack;
  42172. - is_on_stack = object_is_on_stack(buf);
  42173. + is_on_stack = object_starts_on_stack(buf);
  42174. if (is_on_stack) {
  42175. /*
  42176. * dma onto stack is unsafe/nonportable, but callers to this
  42177. diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
  42178. index 6bf24ab..13d0293b 100644
  42179. --- a/drivers/mmc/host/dw_mmc.h
  42180. +++ b/drivers/mmc/host/dw_mmc.h
  42181. @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
  42182. int (*parse_dt)(struct dw_mci *host);
  42183. int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
  42184. struct dw_mci_tuning_data *tuning_data);
  42185. -};
  42186. +} __do_const;
  42187. #endif /* _DW_MMC_H_ */
  42188. diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
  42189. index b931226..df6a085 100644
  42190. --- a/drivers/mmc/host/mmci.c
  42191. +++ b/drivers/mmc/host/mmci.c
  42192. @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
  42193. }
  42194. if (variant->busy_detect) {
  42195. - mmci_ops.card_busy = mmci_card_busy;
  42196. + pax_open_kernel();
  42197. + *(void **)&mmci_ops.card_busy = mmci_card_busy;
  42198. + pax_close_kernel();
  42199. mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
  42200. }
  42201. diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
  42202. index b841bb7..d82712f5 100644
  42203. --- a/drivers/mmc/host/sdhci-esdhc-imx.c
  42204. +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
  42205. @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
  42206. host->mmc->caps |= MMC_CAP_1_8V_DDR;
  42207. }
  42208. - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
  42209. - sdhci_esdhc_ops.platform_execute_tuning =
  42210. + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
  42211. + pax_open_kernel();
  42212. + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
  42213. esdhc_executing_tuning;
  42214. + pax_close_kernel();
  42215. + }
  42216. if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
  42217. writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
  42218. diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
  42219. index 6debda9..2ba7427 100644
  42220. --- a/drivers/mmc/host/sdhci-s3c.c
  42221. +++ b/drivers/mmc/host/sdhci-s3c.c
  42222. @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
  42223. * we can use overriding functions instead of default.
  42224. */
  42225. if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
  42226. - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
  42227. - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
  42228. - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
  42229. + pax_open_kernel();
  42230. + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
  42231. + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
  42232. + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
  42233. + pax_close_kernel();
  42234. }
  42235. /* It supports additional host capabilities if needed */
  42236. diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
  42237. index 096993f..f02c23b 100644
  42238. --- a/drivers/mtd/chips/cfi_cmdset_0020.c
  42239. +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
  42240. @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
  42241. size_t totlen = 0, thislen;
  42242. int ret = 0;
  42243. size_t buflen = 0;
  42244. - static char *buffer;
  42245. + char *buffer;
  42246. if (!ECCBUF_SIZE) {
  42247. /* We should fall back to a general writev implementation.
  42248. diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
  42249. index c07cd57..61c4fbd 100644
  42250. --- a/drivers/mtd/nand/denali.c
  42251. +++ b/drivers/mtd/nand/denali.c
  42252. @@ -24,6 +24,7 @@
  42253. #include <linux/slab.h>
  42254. #include <linux/mtd/mtd.h>
  42255. #include <linux/module.h>
  42256. +#include <linux/slab.h>
  42257. #include "denali.h"
  42258. diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
  42259. index ca6369f..0ce9fed 100644
  42260. --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
  42261. +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
  42262. @@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
  42263. /* first try to map the upper buffer directly */
  42264. if (virt_addr_valid(this->upper_buf) &&
  42265. - !object_is_on_stack(this->upper_buf)) {
  42266. + !object_starts_on_stack(this->upper_buf)) {
  42267. sg_init_one(sgl, this->upper_buf, this->upper_len);
  42268. ret = dma_map_sg(this->dev, sgl, 1, dr);
  42269. if (ret == 0)
  42270. diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
  42271. index 51b9d6a..52af9a7 100644
  42272. --- a/drivers/mtd/nftlmount.c
  42273. +++ b/drivers/mtd/nftlmount.c
  42274. @@ -24,6 +24,7 @@
  42275. #include <asm/errno.h>
  42276. #include <linux/delay.h>
  42277. #include <linux/slab.h>
  42278. +#include <linux/sched.h>
  42279. #include <linux/mtd/mtd.h>
  42280. #include <linux/mtd/nand.h>
  42281. #include <linux/mtd/nftl.h>
  42282. diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
  42283. index cf49c22..971b133 100644
  42284. --- a/drivers/mtd/sm_ftl.c
  42285. +++ b/drivers/mtd/sm_ftl.c
  42286. @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
  42287. #define SM_CIS_VENDOR_OFFSET 0x59
  42288. static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
  42289. {
  42290. - struct attribute_group *attr_group;
  42291. + attribute_group_no_const *attr_group;
  42292. struct attribute **attributes;
  42293. struct sm_sysfs_attribute *vendor_attribute;
  42294. char *vendor;
  42295. diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
  42296. index e5628fc..ffe54d1 100644
  42297. --- a/drivers/net/bonding/bond_main.c
  42298. +++ b/drivers/net/bonding/bond_main.c
  42299. @@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
  42300. bond_netlink_fini();
  42301. unregister_pernet_subsys(&bond_net_ops);
  42302. + rtnl_link_unregister(&bond_link_ops);
  42303. #ifdef CONFIG_NET_POLL_CONTROLLER
  42304. /*
  42305. diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
  42306. index 70651f8..7eb1bdf 100644
  42307. --- a/drivers/net/bonding/bond_netlink.c
  42308. +++ b/drivers/net/bonding/bond_netlink.c
  42309. @@ -542,7 +542,7 @@ nla_put_failure:
  42310. return -EMSGSIZE;
  42311. }
  42312. -struct rtnl_link_ops bond_link_ops __read_mostly = {
  42313. +struct rtnl_link_ops bond_link_ops = {
  42314. .kind = "bond",
  42315. .priv_size = sizeof(struct bonding),
  42316. .setup = bond_setup,
  42317. diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
  42318. index 9e7d95d..d447b88 100644
  42319. --- a/drivers/net/can/Kconfig
  42320. +++ b/drivers/net/can/Kconfig
  42321. @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
  42322. config CAN_FLEXCAN
  42323. tristate "Support for Freescale FLEXCAN based chips"
  42324. - depends on ARM || PPC
  42325. + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
  42326. ---help---
  42327. Say Y here if you want to support for Freescale FlexCAN.
  42328. diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
  42329. index 455d4c3..3353ee7 100644
  42330. --- a/drivers/net/ethernet/8390/ax88796.c
  42331. +++ b/drivers/net/ethernet/8390/ax88796.c
  42332. @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
  42333. if (ax->plat->reg_offsets)
  42334. ei_local->reg_offset = ax->plat->reg_offsets;
  42335. else {
  42336. + resource_size_t _mem_size = mem_size;
  42337. + do_div(_mem_size, 0x18);
  42338. ei_local->reg_offset = ax->reg_offsets;
  42339. for (ret = 0; ret < 0x18; ret++)
  42340. - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
  42341. + ax->reg_offsets[ret] = _mem_size * ret;
  42342. }
  42343. if (!request_mem_region(mem->start, mem_size, pdev->name)) {
  42344. diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
  42345. index a89a40f..5a8a2ac 100644
  42346. --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
  42347. +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
  42348. @@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
  42349. static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
  42350. {
  42351. /* RX_MODE controlling object */
  42352. - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
  42353. + bnx2x_init_rx_mode_obj(bp);
  42354. /* multicast configuration controlling object */
  42355. bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
  42356. diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
  42357. index 0fb6ff2..78fd55c 100644
  42358. --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
  42359. +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
  42360. @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
  42361. return rc;
  42362. }
  42363. -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
  42364. - struct bnx2x_rx_mode_obj *o)
  42365. +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
  42366. {
  42367. if (CHIP_IS_E1x(bp)) {
  42368. - o->wait_comp = bnx2x_empty_rx_mode_wait;
  42369. - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
  42370. + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
  42371. + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
  42372. } else {
  42373. - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
  42374. - o->config_rx_mode = bnx2x_set_rx_mode_e2;
  42375. + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
  42376. + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
  42377. }
  42378. }
  42379. diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
  42380. index 00d7f21..2cddec4 100644
  42381. --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
  42382. +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
  42383. @@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
  42384. /********************* RX MODE ****************/
  42385. -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
  42386. - struct bnx2x_rx_mode_obj *o);
  42387. +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
  42388. /**
  42389. * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
  42390. diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
  42391. index 04321e5..b51cdc4 100644
  42392. --- a/drivers/net/ethernet/broadcom/tg3.h
  42393. +++ b/drivers/net/ethernet/broadcom/tg3.h
  42394. @@ -150,6 +150,7 @@
  42395. #define CHIPREV_ID_5750_A0 0x4000
  42396. #define CHIPREV_ID_5750_A1 0x4001
  42397. #define CHIPREV_ID_5750_A3 0x4003
  42398. +#define CHIPREV_ID_5750_C1 0x4201
  42399. #define CHIPREV_ID_5750_C2 0x4202
  42400. #define CHIPREV_ID_5752_A0_HW 0x5000
  42401. #define CHIPREV_ID_5752_A0 0x6000
  42402. diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
  42403. index 13f9636..228040f 100644
  42404. --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
  42405. +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
  42406. @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
  42407. }
  42408. static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
  42409. - bna_cb_ioceth_enable,
  42410. - bna_cb_ioceth_disable,
  42411. - bna_cb_ioceth_hbfail,
  42412. - bna_cb_ioceth_reset
  42413. + .enable_cbfn = bna_cb_ioceth_enable,
  42414. + .disable_cbfn = bna_cb_ioceth_disable,
  42415. + .hbfail_cbfn = bna_cb_ioceth_hbfail,
  42416. + .reset_cbfn = bna_cb_ioceth_reset
  42417. };
  42418. static void bna_attr_init(struct bna_ioceth *ioceth)
  42419. diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
  42420. index 8cffcdf..aadf043 100644
  42421. --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
  42422. +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
  42423. @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
  42424. */
  42425. struct l2t_skb_cb {
  42426. arp_failure_handler_func arp_failure_handler;
  42427. -};
  42428. +} __no_const;
  42429. #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
  42430. diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
  42431. index 34e2488..07e2079 100644
  42432. --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
  42433. +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
  42434. @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
  42435. int i;
  42436. struct adapter *ap = netdev2adap(dev);
  42437. - static const unsigned int *reg_ranges;
  42438. + const unsigned int *reg_ranges;
  42439. int arr_size = 0, buf_size = 0;
  42440. if (is_t4(ap->params.chip)) {
  42441. diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
  42442. index c05b66d..ed69872 100644
  42443. --- a/drivers/net/ethernet/dec/tulip/de4x5.c
  42444. +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
  42445. @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  42446. for (i=0; i<ETH_ALEN; i++) {
  42447. tmp.addr[i] = dev->dev_addr[i];
  42448. }
  42449. - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
  42450. + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
  42451. break;
  42452. case DE4X5_SET_HWADDR: /* Set the hardware address */
  42453. @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  42454. spin_lock_irqsave(&lp->lock, flags);
  42455. memcpy(&statbuf, &lp->pktStats, ioc->len);
  42456. spin_unlock_irqrestore(&lp->lock, flags);
  42457. - if (copy_to_user(ioc->data, &statbuf, ioc->len))
  42458. + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
  42459. return -EFAULT;
  42460. break;
  42461. }
  42462. diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
  42463. index 36c8061..ca5e1e0 100644
  42464. --- a/drivers/net/ethernet/emulex/benet/be_main.c
  42465. +++ b/drivers/net/ethernet/emulex/benet/be_main.c
  42466. @@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
  42467. if (wrapped)
  42468. newacc += 65536;
  42469. - ACCESS_ONCE(*acc) = newacc;
  42470. + ACCESS_ONCE_RW(*acc) = newacc;
  42471. }
  42472. static void populate_erx_stats(struct be_adapter *adapter,
  42473. diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
  42474. index c11ecbc..13bb299 100644
  42475. --- a/drivers/net/ethernet/faraday/ftgmac100.c
  42476. +++ b/drivers/net/ethernet/faraday/ftgmac100.c
  42477. @@ -30,6 +30,8 @@
  42478. #include <linux/netdevice.h>
  42479. #include <linux/phy.h>
  42480. #include <linux/platform_device.h>
  42481. +#include <linux/interrupt.h>
  42482. +#include <linux/irqreturn.h>
  42483. #include <net/ip.h>
  42484. #include "ftgmac100.h"
  42485. diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
  42486. index 8be5b40..081bc1b 100644
  42487. --- a/drivers/net/ethernet/faraday/ftmac100.c
  42488. +++ b/drivers/net/ethernet/faraday/ftmac100.c
  42489. @@ -31,6 +31,8 @@
  42490. #include <linux/module.h>
  42491. #include <linux/netdevice.h>
  42492. #include <linux/platform_device.h>
  42493. +#include <linux/interrupt.h>
  42494. +#include <linux/irqreturn.h>
  42495. #include "ftmac100.h"
  42496. diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
  42497. index e33ec6c..f54cfe7 100644
  42498. --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
  42499. +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
  42500. @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
  42501. wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
  42502. /* Update the base adjustement value. */
  42503. - ACCESS_ONCE(pf->ptp_base_adj) = incval;
  42504. + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
  42505. smp_mb(); /* Force the above update. */
  42506. }
  42507. diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
  42508. index 5184e2a..acb28c3 100644
  42509. --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
  42510. +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
  42511. @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
  42512. }
  42513. /* update the base incval used to calculate frequency adjustment */
  42514. - ACCESS_ONCE(adapter->base_incval) = incval;
  42515. + ACCESS_ONCE_RW(adapter->base_incval) = incval;
  42516. smp_mb();
  42517. /* need lock to prevent incorrect read while modifying cyclecounter */
  42518. diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
  42519. index 089b713..28d87ae 100644
  42520. --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
  42521. +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
  42522. @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
  42523. struct __vxge_hw_fifo *fifo;
  42524. struct vxge_hw_fifo_config *config;
  42525. u32 txdl_size, txdl_per_memblock;
  42526. - struct vxge_hw_mempool_cbs fifo_mp_callback;
  42527. + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
  42528. + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
  42529. + };
  42530. +
  42531. struct __vxge_hw_virtualpath *vpath;
  42532. if ((vp == NULL) || (attr == NULL)) {
  42533. @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
  42534. goto exit;
  42535. }
  42536. - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
  42537. -
  42538. fifo->mempool =
  42539. __vxge_hw_mempool_create(vpath->hldev,
  42540. fifo->config->memblock_size,
  42541. diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
  42542. index 90a2dda..47e620e 100644
  42543. --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
  42544. +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
  42545. @@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
  42546. adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
  42547. } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
  42548. ahw->nic_mode = QLCNIC_DEFAULT_MODE;
  42549. - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
  42550. + pax_open_kernel();
  42551. + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
  42552. + pax_close_kernel();
  42553. ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
  42554. adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
  42555. adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
  42556. diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
  42557. index be7d7a6..a8983f8 100644
  42558. --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
  42559. +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
  42560. @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
  42561. case QLCNIC_NON_PRIV_FUNC:
  42562. ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
  42563. ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
  42564. - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
  42565. + pax_open_kernel();
  42566. + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
  42567. + pax_close_kernel();
  42568. break;
  42569. case QLCNIC_PRIV_FUNC:
  42570. ahw->op_mode = QLCNIC_PRIV_FUNC;
  42571. ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
  42572. - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
  42573. + pax_open_kernel();
  42574. + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
  42575. + pax_close_kernel();
  42576. break;
  42577. case QLCNIC_MGMT_FUNC:
  42578. ahw->op_mode = QLCNIC_MGMT_FUNC;
  42579. ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
  42580. - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
  42581. + pax_open_kernel();
  42582. + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
  42583. + pax_close_kernel();
  42584. break;
  42585. default:
  42586. dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
  42587. diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
  42588. index 7763962..c3499a7 100644
  42589. --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
  42590. +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
  42591. @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
  42592. struct qlcnic_dump_entry *entry;
  42593. struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
  42594. struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
  42595. - static const struct qlcnic_dump_operations *fw_dump_ops;
  42596. + const struct qlcnic_dump_operations *fw_dump_ops;
  42597. struct device *dev = &adapter->pdev->dev;
  42598. struct qlcnic_hardware_context *ahw;
  42599. void *temp_buffer;
  42600. diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
  42601. index 3ff7bc3..366091b 100644
  42602. --- a/drivers/net/ethernet/realtek/r8169.c
  42603. +++ b/drivers/net/ethernet/realtek/r8169.c
  42604. @@ -758,22 +758,22 @@ struct rtl8169_private {
  42605. struct mdio_ops {
  42606. void (*write)(struct rtl8169_private *, int, int);
  42607. int (*read)(struct rtl8169_private *, int);
  42608. - } mdio_ops;
  42609. + } __no_const mdio_ops;
  42610. struct pll_power_ops {
  42611. void (*down)(struct rtl8169_private *);
  42612. void (*up)(struct rtl8169_private *);
  42613. - } pll_power_ops;
  42614. + } __no_const pll_power_ops;
  42615. struct jumbo_ops {
  42616. void (*enable)(struct rtl8169_private *);
  42617. void (*disable)(struct rtl8169_private *);
  42618. - } jumbo_ops;
  42619. + } __no_const jumbo_ops;
  42620. struct csi_ops {
  42621. void (*write)(struct rtl8169_private *, int, int);
  42622. u32 (*read)(struct rtl8169_private *, int);
  42623. - } csi_ops;
  42624. + } __no_const csi_ops;
  42625. int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
  42626. int (*get_settings)(struct net_device *, struct ethtool_cmd *);
  42627. diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
  42628. index d7a3682..9ce272a 100644
  42629. --- a/drivers/net/ethernet/sfc/ptp.c
  42630. +++ b/drivers/net/ethernet/sfc/ptp.c
  42631. @@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
  42632. ptp->start.dma_addr);
  42633. /* Clear flag that signals MC ready */
  42634. - ACCESS_ONCE(*start) = 0;
  42635. + ACCESS_ONCE_RW(*start) = 0;
  42636. rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
  42637. MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
  42638. EFX_BUG_ON_PARANOID(rc);
  42639. diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
  42640. index 50617c5..b13724c 100644
  42641. --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
  42642. +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
  42643. @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
  42644. writel(value, ioaddr + MMC_CNTRL);
  42645. - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
  42646. - MMC_CNTRL, value);
  42647. +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
  42648. +// MMC_CNTRL, value);
  42649. }
  42650. /* To mask all all interrupts.*/
  42651. diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
  42652. index 7b594ce..1f6c5708 100644
  42653. --- a/drivers/net/hyperv/hyperv_net.h
  42654. +++ b/drivers/net/hyperv/hyperv_net.h
  42655. @@ -100,7 +100,7 @@ struct rndis_device {
  42656. enum rndis_device_state state;
  42657. bool link_state;
  42658. - atomic_t new_req_id;
  42659. + atomic_unchecked_t new_req_id;
  42660. spinlock_t request_lock;
  42661. struct list_head req_list;
  42662. diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
  42663. index b54fd25..9bd2bae 100644
  42664. --- a/drivers/net/hyperv/rndis_filter.c
  42665. +++ b/drivers/net/hyperv/rndis_filter.c
  42666. @@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
  42667. * template
  42668. */
  42669. set = &rndis_msg->msg.set_req;
  42670. - set->req_id = atomic_inc_return(&dev->new_req_id);
  42671. + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
  42672. /* Add to the request list */
  42673. spin_lock_irqsave(&dev->request_lock, flags);
  42674. @@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
  42675. /* Setup the rndis set */
  42676. halt = &request->request_msg.msg.halt_req;
  42677. - halt->req_id = atomic_inc_return(&dev->new_req_id);
  42678. + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
  42679. /* Ignore return since this msg is optional. */
  42680. rndis_filter_send_request(dev, request);
  42681. diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
  42682. index bf0d55e..82bcfbd1 100644
  42683. --- a/drivers/net/ieee802154/fakehard.c
  42684. +++ b/drivers/net/ieee802154/fakehard.c
  42685. @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
  42686. phy->transmit_power = 0xbf;
  42687. dev->netdev_ops = &fake_ops;
  42688. - dev->ml_priv = &fake_mlme;
  42689. + dev->ml_priv = (void *)&fake_mlme;
  42690. priv = netdev_priv(dev);
  42691. priv->phy = phy;
  42692. diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
  42693. index 1831fb7..9c24bca 100644
  42694. --- a/drivers/net/macvlan.c
  42695. +++ b/drivers/net/macvlan.c
  42696. @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
  42697. int macvlan_link_register(struct rtnl_link_ops *ops)
  42698. {
  42699. /* common fields */
  42700. - ops->priv_size = sizeof(struct macvlan_dev);
  42701. - ops->validate = macvlan_validate;
  42702. - ops->maxtype = IFLA_MACVLAN_MAX;
  42703. - ops->policy = macvlan_policy;
  42704. - ops->changelink = macvlan_changelink;
  42705. - ops->get_size = macvlan_get_size;
  42706. - ops->fill_info = macvlan_fill_info;
  42707. + pax_open_kernel();
  42708. + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
  42709. + *(void **)&ops->validate = macvlan_validate;
  42710. + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
  42711. + *(const void **)&ops->policy = macvlan_policy;
  42712. + *(void **)&ops->changelink = macvlan_changelink;
  42713. + *(void **)&ops->get_size = macvlan_get_size;
  42714. + *(void **)&ops->fill_info = macvlan_fill_info;
  42715. + pax_close_kernel();
  42716. return rtnl_link_register(ops);
  42717. };
  42718. @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
  42719. return NOTIFY_DONE;
  42720. }
  42721. -static struct notifier_block macvlan_notifier_block __read_mostly = {
  42722. +static struct notifier_block macvlan_notifier_block = {
  42723. .notifier_call = macvlan_device_event,
  42724. };
  42725. diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
  42726. index ff111a8..c4c3ac4 100644
  42727. --- a/drivers/net/macvtap.c
  42728. +++ b/drivers/net/macvtap.c
  42729. @@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
  42730. }
  42731. ret = 0;
  42732. - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
  42733. + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
  42734. put_user(q->flags, &ifr->ifr_flags))
  42735. ret = -EFAULT;
  42736. macvtap_put_vlan(vlan);
  42737. @@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
  42738. return NOTIFY_DONE;
  42739. }
  42740. -static struct notifier_block macvtap_notifier_block __read_mostly = {
  42741. +static struct notifier_block macvtap_notifier_block = {
  42742. .notifier_call = macvtap_device_event,
  42743. };
  42744. diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
  42745. index daec9b0..6428fcb 100644
  42746. --- a/drivers/net/phy/mdio-bitbang.c
  42747. +++ b/drivers/net/phy/mdio-bitbang.c
  42748. @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
  42749. struct mdiobb_ctrl *ctrl = bus->priv;
  42750. module_put(ctrl->ops->owner);
  42751. + mdiobus_unregister(bus);
  42752. mdiobus_free(bus);
  42753. }
  42754. EXPORT_SYMBOL(free_mdio_bitbang);
  42755. diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
  42756. index 72ff14b..11d442d 100644
  42757. --- a/drivers/net/ppp/ppp_generic.c
  42758. +++ b/drivers/net/ppp/ppp_generic.c
  42759. @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  42760. void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
  42761. struct ppp_stats stats;
  42762. struct ppp_comp_stats cstats;
  42763. - char *vers;
  42764. switch (cmd) {
  42765. case SIOCGPPPSTATS:
  42766. @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  42767. break;
  42768. case SIOCGPPPVER:
  42769. - vers = PPP_VERSION;
  42770. - if (copy_to_user(addr, vers, strlen(vers) + 1))
  42771. + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
  42772. break;
  42773. err = 0;
  42774. break;
  42775. diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
  42776. index 1252d9c..80e660b 100644
  42777. --- a/drivers/net/slip/slhc.c
  42778. +++ b/drivers/net/slip/slhc.c
  42779. @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
  42780. register struct tcphdr *thp;
  42781. register struct iphdr *ip;
  42782. register struct cstate *cs;
  42783. - int len, hdrlen;
  42784. + long len, hdrlen;
  42785. unsigned char *cp = icp;
  42786. /* We've got a compressed packet; read the change byte */
  42787. diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
  42788. index c8624a8..f0a4f6a 100644
  42789. --- a/drivers/net/team/team.c
  42790. +++ b/drivers/net/team/team.c
  42791. @@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
  42792. return NOTIFY_DONE;
  42793. }
  42794. -static struct notifier_block team_notifier_block __read_mostly = {
  42795. +static struct notifier_block team_notifier_block = {
  42796. .notifier_call = team_device_event,
  42797. };
  42798. diff --git a/drivers/net/tun.c b/drivers/net/tun.c
  42799. index 26f8635..c237839 100644
  42800. --- a/drivers/net/tun.c
  42801. +++ b/drivers/net/tun.c
  42802. @@ -1876,7 +1876,7 @@ unlock:
  42803. }
  42804. static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
  42805. - unsigned long arg, int ifreq_len)
  42806. + unsigned long arg, size_t ifreq_len)
  42807. {
  42808. struct tun_file *tfile = file->private_data;
  42809. struct tun_struct *tun;
  42810. @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
  42811. unsigned int ifindex;
  42812. int ret;
  42813. + if (ifreq_len > sizeof ifr)
  42814. + return -EFAULT;
  42815. +
  42816. if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
  42817. if (copy_from_user(&ifr, argp, ifreq_len))
  42818. return -EFAULT;
  42819. diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
  42820. index d350d27..75d7d9d 100644
  42821. --- a/drivers/net/usb/cdc_ncm.c
  42822. +++ b/drivers/net/usb/cdc_ncm.c
  42823. @@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
  42824. skb_out->len > CDC_NCM_MIN_TX_PKT)
  42825. memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
  42826. ctx->tx_max - skb_out->len);
  42827. - else if ((skb_out->len % dev->maxpacket) == 0)
  42828. + else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
  42829. *skb_put(skb_out, 1) = 0; /* force short packet */
  42830. /* set final frame length */
  42831. diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
  42832. index 660bd5e..ac59452 100644
  42833. --- a/drivers/net/usb/hso.c
  42834. +++ b/drivers/net/usb/hso.c
  42835. @@ -71,7 +71,7 @@
  42836. #include <asm/byteorder.h>
  42837. #include <linux/serial_core.h>
  42838. #include <linux/serial.h>
  42839. -
  42840. +#include <asm/local.h>
  42841. #define MOD_AUTHOR "Option Wireless"
  42842. #define MOD_DESCRIPTION "USB High Speed Option driver"
  42843. @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
  42844. struct urb *urb;
  42845. urb = serial->rx_urb[0];
  42846. - if (serial->port.count > 0) {
  42847. + if (atomic_read(&serial->port.count) > 0) {
  42848. count = put_rxbuf_data(urb, serial);
  42849. if (count == -1)
  42850. return;
  42851. @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
  42852. DUMP1(urb->transfer_buffer, urb->actual_length);
  42853. /* Anyone listening? */
  42854. - if (serial->port.count == 0)
  42855. + if (atomic_read(&serial->port.count) == 0)
  42856. return;
  42857. if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
  42858. @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
  42859. tty_port_tty_set(&serial->port, tty);
  42860. /* check for port already opened, if not set the termios */
  42861. - serial->port.count++;
  42862. - if (serial->port.count == 1) {
  42863. + if (atomic_inc_return(&serial->port.count) == 1) {
  42864. serial->rx_state = RX_IDLE;
  42865. /* Force default termio settings */
  42866. _hso_serial_set_termios(tty, NULL);
  42867. @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
  42868. result = hso_start_serial_device(serial->parent, GFP_KERNEL);
  42869. if (result) {
  42870. hso_stop_serial_device(serial->parent);
  42871. - serial->port.count--;
  42872. + atomic_dec(&serial->port.count);
  42873. kref_put(&serial->parent->ref, hso_serial_ref_free);
  42874. }
  42875. } else {
  42876. @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
  42877. /* reset the rts and dtr */
  42878. /* do the actual close */
  42879. - serial->port.count--;
  42880. + atomic_dec(&serial->port.count);
  42881. - if (serial->port.count <= 0) {
  42882. - serial->port.count = 0;
  42883. + if (atomic_read(&serial->port.count) <= 0) {
  42884. + atomic_set(&serial->port.count, 0);
  42885. tty_port_tty_set(&serial->port, NULL);
  42886. if (!usb_gone)
  42887. hso_stop_serial_device(serial->parent);
  42888. @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
  42889. /* the actual setup */
  42890. spin_lock_irqsave(&serial->serial_lock, flags);
  42891. - if (serial->port.count)
  42892. + if (atomic_read(&serial->port.count))
  42893. _hso_serial_set_termios(tty, old);
  42894. else
  42895. tty->termios = *old;
  42896. @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
  42897. D1("Pending read interrupt on port %d\n", i);
  42898. spin_lock(&serial->serial_lock);
  42899. if (serial->rx_state == RX_IDLE &&
  42900. - serial->port.count > 0) {
  42901. + atomic_read(&serial->port.count) > 0) {
  42902. /* Setup and send a ctrl req read on
  42903. * port i */
  42904. if (!serial->rx_urb_filled[0]) {
  42905. @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
  42906. /* Start all serial ports */
  42907. for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
  42908. if (serial_table[i] && (serial_table[i]->interface == iface)) {
  42909. - if (dev2ser(serial_table[i])->port.count) {
  42910. + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
  42911. result =
  42912. hso_start_serial_device(serial_table[i], GFP_NOIO);
  42913. hso_kick_transmit(dev2ser(serial_table[i]));
  42914. diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
  42915. index adb12f3..48005ab 100644
  42916. --- a/drivers/net/usb/r8152.c
  42917. +++ b/drivers/net/usb/r8152.c
  42918. @@ -513,7 +513,7 @@ struct r8152 {
  42919. void (*disable)(struct r8152 *);
  42920. void (*down)(struct r8152 *);
  42921. void (*unload)(struct r8152 *);
  42922. - } rtl_ops;
  42923. + } __no_const rtl_ops;
  42924. int intr_interval;
  42925. u32 msg_enable;
  42926. diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
  42927. index a2515887..6d13233 100644
  42928. --- a/drivers/net/usb/sierra_net.c
  42929. +++ b/drivers/net/usb/sierra_net.c
  42930. @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
  42931. /* atomic counter partially included in MAC address to make sure 2 devices
  42932. * do not end up with the same MAC - concept breaks in case of > 255 ifaces
  42933. */
  42934. -static atomic_t iface_counter = ATOMIC_INIT(0);
  42935. +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
  42936. /*
  42937. * SYNC Timer Delay definition used to set the expiry time
  42938. @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
  42939. dev->net->netdev_ops = &sierra_net_device_ops;
  42940. /* change MAC addr to include, ifacenum, and to be unique */
  42941. - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
  42942. + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
  42943. dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
  42944. /* we will have to manufacture ethernet headers, prepare template */
  42945. diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
  42946. index d091e52..568bb179 100644
  42947. --- a/drivers/net/vxlan.c
  42948. +++ b/drivers/net/vxlan.c
  42949. @@ -2847,7 +2847,7 @@ nla_put_failure:
  42950. return -EMSGSIZE;
  42951. }
  42952. -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
  42953. +static struct rtnl_link_ops vxlan_link_ops = {
  42954. .kind = "vxlan",
  42955. .maxtype = IFLA_VXLAN_MAX,
  42956. .policy = vxlan_policy,
  42957. @@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
  42958. return NOTIFY_DONE;
  42959. }
  42960. -static struct notifier_block vxlan_notifier_block __read_mostly = {
  42961. +static struct notifier_block vxlan_notifier_block = {
  42962. .notifier_call = vxlan_lowerdev_event,
  42963. };
  42964. diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
  42965. index 5920c99..ff2e4a5 100644
  42966. --- a/drivers/net/wan/lmc/lmc_media.c
  42967. +++ b/drivers/net/wan/lmc/lmc_media.c
  42968. @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
  42969. static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
  42970. lmc_media_t lmc_ds3_media = {
  42971. - lmc_ds3_init, /* special media init stuff */
  42972. - lmc_ds3_default, /* reset to default state */
  42973. - lmc_ds3_set_status, /* reset status to state provided */
  42974. - lmc_dummy_set_1, /* set clock source */
  42975. - lmc_dummy_set2_1, /* set line speed */
  42976. - lmc_ds3_set_100ft, /* set cable length */
  42977. - lmc_ds3_set_scram, /* set scrambler */
  42978. - lmc_ds3_get_link_status, /* get link status */
  42979. - lmc_dummy_set_1, /* set link status */
  42980. - lmc_ds3_set_crc_length, /* set CRC length */
  42981. - lmc_dummy_set_1, /* set T1 or E1 circuit type */
  42982. - lmc_ds3_watchdog
  42983. + .init = lmc_ds3_init, /* special media init stuff */
  42984. + .defaults = lmc_ds3_default, /* reset to default state */
  42985. + .set_status = lmc_ds3_set_status, /* reset status to state provided */
  42986. + .set_clock_source = lmc_dummy_set_1, /* set clock source */
  42987. + .set_speed = lmc_dummy_set2_1, /* set line speed */
  42988. + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
  42989. + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
  42990. + .get_link_status = lmc_ds3_get_link_status, /* get link status */
  42991. + .set_link_status = lmc_dummy_set_1, /* set link status */
  42992. + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
  42993. + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
  42994. + .watchdog = lmc_ds3_watchdog
  42995. };
  42996. lmc_media_t lmc_hssi_media = {
  42997. - lmc_hssi_init, /* special media init stuff */
  42998. - lmc_hssi_default, /* reset to default state */
  42999. - lmc_hssi_set_status, /* reset status to state provided */
  43000. - lmc_hssi_set_clock, /* set clock source */
  43001. - lmc_dummy_set2_1, /* set line speed */
  43002. - lmc_dummy_set_1, /* set cable length */
  43003. - lmc_dummy_set_1, /* set scrambler */
  43004. - lmc_hssi_get_link_status, /* get link status */
  43005. - lmc_hssi_set_link_status, /* set link status */
  43006. - lmc_hssi_set_crc_length, /* set CRC length */
  43007. - lmc_dummy_set_1, /* set T1 or E1 circuit type */
  43008. - lmc_hssi_watchdog
  43009. + .init = lmc_hssi_init, /* special media init stuff */
  43010. + .defaults = lmc_hssi_default, /* reset to default state */
  43011. + .set_status = lmc_hssi_set_status, /* reset status to state provided */
  43012. + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
  43013. + .set_speed = lmc_dummy_set2_1, /* set line speed */
  43014. + .set_cable_length = lmc_dummy_set_1, /* set cable length */
  43015. + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
  43016. + .get_link_status = lmc_hssi_get_link_status, /* get link status */
  43017. + .set_link_status = lmc_hssi_set_link_status, /* set link status */
  43018. + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
  43019. + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
  43020. + .watchdog = lmc_hssi_watchdog
  43021. };
  43022. -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
  43023. - lmc_ssi_default, /* reset to default state */
  43024. - lmc_ssi_set_status, /* reset status to state provided */
  43025. - lmc_ssi_set_clock, /* set clock source */
  43026. - lmc_ssi_set_speed, /* set line speed */
  43027. - lmc_dummy_set_1, /* set cable length */
  43028. - lmc_dummy_set_1, /* set scrambler */
  43029. - lmc_ssi_get_link_status, /* get link status */
  43030. - lmc_ssi_set_link_status, /* set link status */
  43031. - lmc_ssi_set_crc_length, /* set CRC length */
  43032. - lmc_dummy_set_1, /* set T1 or E1 circuit type */
  43033. - lmc_ssi_watchdog
  43034. +lmc_media_t lmc_ssi_media = {
  43035. + .init = lmc_ssi_init, /* special media init stuff */
  43036. + .defaults = lmc_ssi_default, /* reset to default state */
  43037. + .set_status = lmc_ssi_set_status, /* reset status to state provided */
  43038. + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
  43039. + .set_speed = lmc_ssi_set_speed, /* set line speed */
  43040. + .set_cable_length = lmc_dummy_set_1, /* set cable length */
  43041. + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
  43042. + .get_link_status = lmc_ssi_get_link_status, /* get link status */
  43043. + .set_link_status = lmc_ssi_set_link_status, /* set link status */
  43044. + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
  43045. + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
  43046. + .watchdog = lmc_ssi_watchdog
  43047. };
  43048. lmc_media_t lmc_t1_media = {
  43049. - lmc_t1_init, /* special media init stuff */
  43050. - lmc_t1_default, /* reset to default state */
  43051. - lmc_t1_set_status, /* reset status to state provided */
  43052. - lmc_t1_set_clock, /* set clock source */
  43053. - lmc_dummy_set2_1, /* set line speed */
  43054. - lmc_dummy_set_1, /* set cable length */
  43055. - lmc_dummy_set_1, /* set scrambler */
  43056. - lmc_t1_get_link_status, /* get link status */
  43057. - lmc_dummy_set_1, /* set link status */
  43058. - lmc_t1_set_crc_length, /* set CRC length */
  43059. - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
  43060. - lmc_t1_watchdog
  43061. + .init = lmc_t1_init, /* special media init stuff */
  43062. + .defaults = lmc_t1_default, /* reset to default state */
  43063. + .set_status = lmc_t1_set_status, /* reset status to state provided */
  43064. + .set_clock_source = lmc_t1_set_clock, /* set clock source */
  43065. + .set_speed = lmc_dummy_set2_1, /* set line speed */
  43066. + .set_cable_length = lmc_dummy_set_1, /* set cable length */
  43067. + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
  43068. + .get_link_status = lmc_t1_get_link_status, /* get link status */
  43069. + .set_link_status = lmc_dummy_set_1, /* set link status */
  43070. + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
  43071. + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
  43072. + .watchdog = lmc_t1_watchdog
  43073. };
  43074. static void
  43075. diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
  43076. index feacc3b..5bac0de 100644
  43077. --- a/drivers/net/wan/z85230.c
  43078. +++ b/drivers/net/wan/z85230.c
  43079. @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
  43080. struct z8530_irqhandler z8530_sync =
  43081. {
  43082. - z8530_rx,
  43083. - z8530_tx,
  43084. - z8530_status
  43085. + .rx = z8530_rx,
  43086. + .tx = z8530_tx,
  43087. + .status = z8530_status
  43088. };
  43089. EXPORT_SYMBOL(z8530_sync);
  43090. @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
  43091. }
  43092. static struct z8530_irqhandler z8530_dma_sync = {
  43093. - z8530_dma_rx,
  43094. - z8530_dma_tx,
  43095. - z8530_dma_status
  43096. + .rx = z8530_dma_rx,
  43097. + .tx = z8530_dma_tx,
  43098. + .status = z8530_dma_status
  43099. };
  43100. static struct z8530_irqhandler z8530_txdma_sync = {
  43101. - z8530_rx,
  43102. - z8530_dma_tx,
  43103. - z8530_dma_status
  43104. + .rx = z8530_rx,
  43105. + .tx = z8530_dma_tx,
  43106. + .status = z8530_dma_status
  43107. };
  43108. /**
  43109. @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
  43110. struct z8530_irqhandler z8530_nop=
  43111. {
  43112. - z8530_rx_clear,
  43113. - z8530_tx_clear,
  43114. - z8530_status_clear
  43115. + .rx = z8530_rx_clear,
  43116. + .tx = z8530_tx_clear,
  43117. + .status = z8530_status_clear
  43118. };
  43119. diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
  43120. index 0b60295..b8bfa5b 100644
  43121. --- a/drivers/net/wimax/i2400m/rx.c
  43122. +++ b/drivers/net/wimax/i2400m/rx.c
  43123. @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
  43124. if (i2400m->rx_roq == NULL)
  43125. goto error_roq_alloc;
  43126. - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
  43127. + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
  43128. GFP_KERNEL);
  43129. if (rd == NULL) {
  43130. result = -ENOMEM;
  43131. diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
  43132. index edf4b57..68b51c0 100644
  43133. --- a/drivers/net/wireless/airo.c
  43134. +++ b/drivers/net/wireless/airo.c
  43135. @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
  43136. struct airo_info *ai = dev->ml_priv;
  43137. int ridcode;
  43138. int enabled;
  43139. - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
  43140. + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
  43141. unsigned char *iobuf;
  43142. /* Only super-user can write RIDs */
  43143. diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
  43144. index 99b3bfa..9559372 100644
  43145. --- a/drivers/net/wireless/at76c50x-usb.c
  43146. +++ b/drivers/net/wireless/at76c50x-usb.c
  43147. @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
  43148. }
  43149. /* Convert timeout from the DFU status to jiffies */
  43150. -static inline unsigned long at76_get_timeout(struct dfu_status *s)
  43151. +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
  43152. {
  43153. return msecs_to_jiffies((s->poll_timeout[2] << 16)
  43154. | (s->poll_timeout[1] << 8)
  43155. diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
  43156. index edc57ab..ff49e0a 100644
  43157. --- a/drivers/net/wireless/ath/ath10k/htc.c
  43158. +++ b/drivers/net/wireless/ath/ath10k/htc.c
  43159. @@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
  43160. /* registered target arrival callback from the HIF layer */
  43161. int ath10k_htc_init(struct ath10k *ar)
  43162. {
  43163. - struct ath10k_hif_cb htc_callbacks;
  43164. + static struct ath10k_hif_cb htc_callbacks = {
  43165. + .rx_completion = ath10k_htc_rx_completion_handler,
  43166. + .tx_completion = ath10k_htc_tx_completion_handler,
  43167. + };
  43168. struct ath10k_htc_ep *ep = NULL;
  43169. struct ath10k_htc *htc = &ar->htc;
  43170. @@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
  43171. ath10k_htc_reset_endpoint_states(htc);
  43172. /* setup HIF layer callbacks */
  43173. - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
  43174. - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
  43175. htc->ar = ar;
  43176. /* Get HIF default pipe for HTC message exchange */
  43177. diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
  43178. index 4716d33..a688310 100644
  43179. --- a/drivers/net/wireless/ath/ath10k/htc.h
  43180. +++ b/drivers/net/wireless/ath/ath10k/htc.h
  43181. @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
  43182. struct ath10k_htc_ops {
  43183. void (*target_send_suspend_complete)(struct ath10k *ar);
  43184. -};
  43185. +} __no_const;
  43186. struct ath10k_htc_ep_ops {
  43187. void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
  43188. void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
  43189. void (*ep_tx_credits)(struct ath10k *);
  43190. -};
  43191. +} __no_const;
  43192. /* service connection information */
  43193. struct ath10k_htc_svc_conn_req {
  43194. diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
  43195. index 741b38d..b7ae41b 100644
  43196. --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
  43197. +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
  43198. @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43199. ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
  43200. ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
  43201. - ACCESS_ONCE(ads->ds_link) = i->link;
  43202. - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
  43203. + ACCESS_ONCE_RW(ads->ds_link) = i->link;
  43204. + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
  43205. ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
  43206. ctl6 = SM(i->keytype, AR_EncrType);
  43207. @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43208. if ((i->is_first || i->is_last) &&
  43209. i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
  43210. - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
  43211. + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
  43212. | set11nTries(i->rates, 1)
  43213. | set11nTries(i->rates, 2)
  43214. | set11nTries(i->rates, 3)
  43215. | (i->dur_update ? AR_DurUpdateEna : 0)
  43216. | SM(0, AR_BurstDur);
  43217. - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
  43218. + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
  43219. | set11nRate(i->rates, 1)
  43220. | set11nRate(i->rates, 2)
  43221. | set11nRate(i->rates, 3);
  43222. } else {
  43223. - ACCESS_ONCE(ads->ds_ctl2) = 0;
  43224. - ACCESS_ONCE(ads->ds_ctl3) = 0;
  43225. + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
  43226. + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
  43227. }
  43228. if (!i->is_first) {
  43229. - ACCESS_ONCE(ads->ds_ctl0) = 0;
  43230. - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
  43231. - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
  43232. + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
  43233. + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
  43234. + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
  43235. return;
  43236. }
  43237. @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43238. break;
  43239. }
  43240. - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
  43241. + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
  43242. | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  43243. | SM(i->txpower, AR_XmitPower)
  43244. | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  43245. @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43246. | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
  43247. (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
  43248. - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
  43249. - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
  43250. + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
  43251. + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
  43252. if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
  43253. return;
  43254. - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
  43255. + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
  43256. | set11nPktDurRTSCTS(i->rates, 1);
  43257. - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
  43258. + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
  43259. | set11nPktDurRTSCTS(i->rates, 3);
  43260. - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
  43261. + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
  43262. | set11nRateFlags(i->rates, 1)
  43263. | set11nRateFlags(i->rates, 2)
  43264. | set11nRateFlags(i->rates, 3)
  43265. diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
  43266. index 729ffbf..49f50e3 100644
  43267. --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
  43268. +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
  43269. @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43270. (i->qcu << AR_TxQcuNum_S) | desc_len;
  43271. checksum += val;
  43272. - ACCESS_ONCE(ads->info) = val;
  43273. + ACCESS_ONCE_RW(ads->info) = val;
  43274. checksum += i->link;
  43275. - ACCESS_ONCE(ads->link) = i->link;
  43276. + ACCESS_ONCE_RW(ads->link) = i->link;
  43277. checksum += i->buf_addr[0];
  43278. - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
  43279. + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
  43280. checksum += i->buf_addr[1];
  43281. - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
  43282. + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
  43283. checksum += i->buf_addr[2];
  43284. - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
  43285. + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
  43286. checksum += i->buf_addr[3];
  43287. - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
  43288. + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
  43289. checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
  43290. - ACCESS_ONCE(ads->ctl3) = val;
  43291. + ACCESS_ONCE_RW(ads->ctl3) = val;
  43292. checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
  43293. - ACCESS_ONCE(ads->ctl5) = val;
  43294. + ACCESS_ONCE_RW(ads->ctl5) = val;
  43295. checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
  43296. - ACCESS_ONCE(ads->ctl7) = val;
  43297. + ACCESS_ONCE_RW(ads->ctl7) = val;
  43298. checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
  43299. - ACCESS_ONCE(ads->ctl9) = val;
  43300. + ACCESS_ONCE_RW(ads->ctl9) = val;
  43301. checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
  43302. - ACCESS_ONCE(ads->ctl10) = checksum;
  43303. + ACCESS_ONCE_RW(ads->ctl10) = checksum;
  43304. if (i->is_first || i->is_last) {
  43305. - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
  43306. + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
  43307. | set11nTries(i->rates, 1)
  43308. | set11nTries(i->rates, 2)
  43309. | set11nTries(i->rates, 3)
  43310. | (i->dur_update ? AR_DurUpdateEna : 0)
  43311. | SM(0, AR_BurstDur);
  43312. - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
  43313. + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
  43314. | set11nRate(i->rates, 1)
  43315. | set11nRate(i->rates, 2)
  43316. | set11nRate(i->rates, 3);
  43317. } else {
  43318. - ACCESS_ONCE(ads->ctl13) = 0;
  43319. - ACCESS_ONCE(ads->ctl14) = 0;
  43320. + ACCESS_ONCE_RW(ads->ctl13) = 0;
  43321. + ACCESS_ONCE_RW(ads->ctl14) = 0;
  43322. }
  43323. ads->ctl20 = 0;
  43324. @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43325. ctl17 = SM(i->keytype, AR_EncrType);
  43326. if (!i->is_first) {
  43327. - ACCESS_ONCE(ads->ctl11) = 0;
  43328. - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
  43329. - ACCESS_ONCE(ads->ctl15) = 0;
  43330. - ACCESS_ONCE(ads->ctl16) = 0;
  43331. - ACCESS_ONCE(ads->ctl17) = ctl17;
  43332. - ACCESS_ONCE(ads->ctl18) = 0;
  43333. - ACCESS_ONCE(ads->ctl19) = 0;
  43334. + ACCESS_ONCE_RW(ads->ctl11) = 0;
  43335. + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
  43336. + ACCESS_ONCE_RW(ads->ctl15) = 0;
  43337. + ACCESS_ONCE_RW(ads->ctl16) = 0;
  43338. + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
  43339. + ACCESS_ONCE_RW(ads->ctl18) = 0;
  43340. + ACCESS_ONCE_RW(ads->ctl19) = 0;
  43341. return;
  43342. }
  43343. - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
  43344. + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
  43345. | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
  43346. | SM(i->txpower, AR_XmitPower)
  43347. | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
  43348. @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
  43349. val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
  43350. ctl12 |= SM(val, AR_PAPRDChainMask);
  43351. - ACCESS_ONCE(ads->ctl12) = ctl12;
  43352. - ACCESS_ONCE(ads->ctl17) = ctl17;
  43353. + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
  43354. + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
  43355. - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
  43356. + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
  43357. | set11nPktDurRTSCTS(i->rates, 1);
  43358. - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
  43359. + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
  43360. | set11nPktDurRTSCTS(i->rates, 3);
  43361. - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
  43362. + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
  43363. | set11nRateFlags(i->rates, 1)
  43364. | set11nRateFlags(i->rates, 2)
  43365. | set11nRateFlags(i->rates, 3)
  43366. | SM(i->rtscts_rate, AR_RTSCTSRate);
  43367. - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
  43368. + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
  43369. }
  43370. static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
  43371. diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
  43372. index 0acd4b5..0591c91 100644
  43373. --- a/drivers/net/wireless/ath/ath9k/hw.h
  43374. +++ b/drivers/net/wireless/ath/ath9k/hw.h
  43375. @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
  43376. /* ANI */
  43377. void (*ani_cache_ini_regs)(struct ath_hw *ah);
  43378. -};
  43379. +} __no_const;
  43380. /**
  43381. * struct ath_spec_scan - parameters for Atheros spectral scan
  43382. @@ -706,7 +706,7 @@ struct ath_hw_ops {
  43383. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  43384. void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
  43385. #endif
  43386. -};
  43387. +} __no_const;
  43388. struct ath_nf_limits {
  43389. s16 max;
  43390. diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
  43391. index 92190da..f3a4c4c 100644
  43392. --- a/drivers/net/wireless/b43/phy_lp.c
  43393. +++ b/drivers/net/wireless/b43/phy_lp.c
  43394. @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
  43395. {
  43396. struct ssb_bus *bus = dev->dev->sdev->bus;
  43397. - static const struct b206x_channel *chandata = NULL;
  43398. + const struct b206x_channel *chandata = NULL;
  43399. u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
  43400. u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
  43401. u16 old_comm15, scale;
  43402. diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
  43403. index 0487461..fd9e84a 100644
  43404. --- a/drivers/net/wireless/iwlegacy/3945-mac.c
  43405. +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
  43406. @@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  43407. */
  43408. if (il3945_mod_params.disable_hw_scan) {
  43409. D_INFO("Disabling hw_scan\n");
  43410. - il3945_mac_ops.hw_scan = NULL;
  43411. + pax_open_kernel();
  43412. + *(void **)&il3945_mac_ops.hw_scan = NULL;
  43413. + pax_close_kernel();
  43414. }
  43415. D_INFO("*** LOAD DRIVER ***\n");
  43416. diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
  43417. index d2fe259..0c4c682 100644
  43418. --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
  43419. +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
  43420. @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
  43421. {
  43422. struct iwl_priv *priv = file->private_data;
  43423. char buf[64];
  43424. - int buf_size;
  43425. + size_t buf_size;
  43426. u32 offset, len;
  43427. memset(buf, 0, sizeof(buf));
  43428. @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
  43429. struct iwl_priv *priv = file->private_data;
  43430. char buf[8];
  43431. - int buf_size;
  43432. + size_t buf_size;
  43433. u32 reset_flag;
  43434. memset(buf, 0, sizeof(buf));
  43435. @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  43436. {
  43437. struct iwl_priv *priv = file->private_data;
  43438. char buf[8];
  43439. - int buf_size;
  43440. + size_t buf_size;
  43441. int ht40;
  43442. memset(buf, 0, sizeof(buf));
  43443. @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  43444. {
  43445. struct iwl_priv *priv = file->private_data;
  43446. char buf[8];
  43447. - int buf_size;
  43448. + size_t buf_size;
  43449. int value;
  43450. memset(buf, 0, sizeof(buf));
  43451. @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
  43452. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  43453. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  43454. -static const char *fmt_value = " %-30s %10u\n";
  43455. -static const char *fmt_hex = " %-30s 0x%02X\n";
  43456. -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
  43457. -static const char *fmt_header =
  43458. +static const char fmt_value[] = " %-30s %10u\n";
  43459. +static const char fmt_hex[] = " %-30s 0x%02X\n";
  43460. +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
  43461. +static const char fmt_header[] =
  43462. "%-32s current cumulative delta max\n";
  43463. static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
  43464. @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  43465. {
  43466. struct iwl_priv *priv = file->private_data;
  43467. char buf[8];
  43468. - int buf_size;
  43469. + size_t buf_size;
  43470. int clear;
  43471. memset(buf, 0, sizeof(buf));
  43472. @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  43473. {
  43474. struct iwl_priv *priv = file->private_data;
  43475. char buf[8];
  43476. - int buf_size;
  43477. + size_t buf_size;
  43478. int trace;
  43479. memset(buf, 0, sizeof(buf));
  43480. @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
  43481. {
  43482. struct iwl_priv *priv = file->private_data;
  43483. char buf[8];
  43484. - int buf_size;
  43485. + size_t buf_size;
  43486. int missed;
  43487. memset(buf, 0, sizeof(buf));
  43488. @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
  43489. struct iwl_priv *priv = file->private_data;
  43490. char buf[8];
  43491. - int buf_size;
  43492. + size_t buf_size;
  43493. int plcp;
  43494. memset(buf, 0, sizeof(buf));
  43495. @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
  43496. struct iwl_priv *priv = file->private_data;
  43497. char buf[8];
  43498. - int buf_size;
  43499. + size_t buf_size;
  43500. int flush;
  43501. memset(buf, 0, sizeof(buf));
  43502. @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
  43503. struct iwl_priv *priv = file->private_data;
  43504. char buf[8];
  43505. - int buf_size;
  43506. + size_t buf_size;
  43507. int rts;
  43508. if (!priv->cfg->ht_params)
  43509. @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
  43510. {
  43511. struct iwl_priv *priv = file->private_data;
  43512. char buf[8];
  43513. - int buf_size;
  43514. + size_t buf_size;
  43515. memset(buf, 0, sizeof(buf));
  43516. buf_size = min(count, sizeof(buf) - 1);
  43517. @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  43518. struct iwl_priv *priv = file->private_data;
  43519. u32 event_log_flag;
  43520. char buf[8];
  43521. - int buf_size;
  43522. + size_t buf_size;
  43523. /* check that the interface is up */
  43524. if (!iwl_is_ready(priv))
  43525. @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
  43526. struct iwl_priv *priv = file->private_data;
  43527. char buf[8];
  43528. u32 calib_disabled;
  43529. - int buf_size;
  43530. + size_t buf_size;
  43531. memset(buf, 0, sizeof(buf));
  43532. buf_size = min(count, sizeof(buf) - 1);
  43533. diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
  43534. index ea7e70c..bc0c45f 100644
  43535. --- a/drivers/net/wireless/iwlwifi/dvm/main.c
  43536. +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
  43537. @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
  43538. static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
  43539. {
  43540. struct iwl_nvm_data *data = priv->nvm_data;
  43541. - char *debug_msg;
  43542. + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
  43543. if (data->sku_cap_11n_enable &&
  43544. !priv->cfg->ht_params) {
  43545. @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
  43546. return -EINVAL;
  43547. }
  43548. - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
  43549. IWL_DEBUG_INFO(priv, debug_msg,
  43550. data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
  43551. data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
  43552. diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
  43553. index f950780..be9df93 100644
  43554. --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
  43555. +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
  43556. @@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  43557. struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
  43558. char buf[8];
  43559. - int buf_size;
  43560. + size_t buf_size;
  43561. u32 reset_flag;
  43562. memset(buf, 0, sizeof(buf));
  43563. @@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
  43564. {
  43565. struct iwl_trans *trans = file->private_data;
  43566. char buf[8];
  43567. - int buf_size;
  43568. + size_t buf_size;
  43569. int csr;
  43570. memset(buf, 0, sizeof(buf));
  43571. diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
  43572. index 69d4c31..bd0b316 100644
  43573. --- a/drivers/net/wireless/mac80211_hwsim.c
  43574. +++ b/drivers/net/wireless/mac80211_hwsim.c
  43575. @@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
  43576. if (channels < 1)
  43577. return -EINVAL;
  43578. - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
  43579. - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
  43580. - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
  43581. - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
  43582. - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
  43583. - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
  43584. - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
  43585. - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
  43586. - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
  43587. - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
  43588. - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
  43589. - mac80211_hwsim_assign_vif_chanctx;
  43590. - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
  43591. - mac80211_hwsim_unassign_vif_chanctx;
  43592. + pax_open_kernel();
  43593. + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
  43594. + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
  43595. + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
  43596. + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
  43597. + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
  43598. + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
  43599. + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
  43600. + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
  43601. + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
  43602. + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
  43603. + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
  43604. + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
  43605. + pax_close_kernel();
  43606. spin_lock_init(&hwsim_radio_lock);
  43607. INIT_LIST_HEAD(&hwsim_radios);
  43608. diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
  43609. index 5028557..91cf394 100644
  43610. --- a/drivers/net/wireless/rndis_wlan.c
  43611. +++ b/drivers/net/wireless/rndis_wlan.c
  43612. @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
  43613. netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
  43614. - if (rts_threshold < 0 || rts_threshold > 2347)
  43615. + if (rts_threshold > 2347)
  43616. rts_threshold = 2347;
  43617. tmp = cpu_to_le32(rts_threshold);
  43618. diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
  43619. index e3b885d..7a7de2f 100644
  43620. --- a/drivers/net/wireless/rt2x00/rt2x00.h
  43621. +++ b/drivers/net/wireless/rt2x00/rt2x00.h
  43622. @@ -375,7 +375,7 @@ struct rt2x00_intf {
  43623. * for hardware which doesn't support hardware
  43624. * sequence counting.
  43625. */
  43626. - atomic_t seqno;
  43627. + atomic_unchecked_t seqno;
  43628. };
  43629. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  43630. diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
  43631. index 5642ccc..01f03eb 100644
  43632. --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
  43633. +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
  43634. @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
  43635. * sequence counter given by mac80211.
  43636. */
  43637. if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
  43638. - seqno = atomic_add_return(0x10, &intf->seqno);
  43639. + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
  43640. else
  43641. - seqno = atomic_read(&intf->seqno);
  43642. + seqno = atomic_read_unchecked(&intf->seqno);
  43643. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  43644. hdr->seq_ctrl |= cpu_to_le16(seqno);
  43645. diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
  43646. index e2b3d9c..67a5184 100644
  43647. --- a/drivers/net/wireless/ti/wl1251/sdio.c
  43648. +++ b/drivers/net/wireless/ti/wl1251/sdio.c
  43649. @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
  43650. irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  43651. - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
  43652. - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
  43653. + pax_open_kernel();
  43654. + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
  43655. + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
  43656. + pax_close_kernel();
  43657. wl1251_info("using dedicated interrupt line");
  43658. } else {
  43659. - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
  43660. - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
  43661. + pax_open_kernel();
  43662. + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
  43663. + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
  43664. + pax_close_kernel();
  43665. wl1251_info("using SDIO interrupt");
  43666. }
  43667. diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
  43668. index be7129b..4161356 100644
  43669. --- a/drivers/net/wireless/ti/wl12xx/main.c
  43670. +++ b/drivers/net/wireless/ti/wl12xx/main.c
  43671. @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
  43672. sizeof(wl->conf.mem));
  43673. /* read data preparation is only needed by wl127x */
  43674. - wl->ops->prepare_read = wl127x_prepare_read;
  43675. + pax_open_kernel();
  43676. + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
  43677. + pax_close_kernel();
  43678. wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
  43679. WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
  43680. @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
  43681. sizeof(wl->conf.mem));
  43682. /* read data preparation is only needed by wl127x */
  43683. - wl->ops->prepare_read = wl127x_prepare_read;
  43684. + pax_open_kernel();
  43685. + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
  43686. + pax_close_kernel();
  43687. wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
  43688. WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
  43689. diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
  43690. index ec37b16..7e34d66 100644
  43691. --- a/drivers/net/wireless/ti/wl18xx/main.c
  43692. +++ b/drivers/net/wireless/ti/wl18xx/main.c
  43693. @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
  43694. }
  43695. if (!checksum_param) {
  43696. - wl18xx_ops.set_rx_csum = NULL;
  43697. - wl18xx_ops.init_vif = NULL;
  43698. + pax_open_kernel();
  43699. + *(void **)&wl18xx_ops.set_rx_csum = NULL;
  43700. + *(void **)&wl18xx_ops.init_vif = NULL;
  43701. + pax_close_kernel();
  43702. }
  43703. /* Enable 11a Band only if we have 5G antennas */
  43704. diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
  43705. index a912dc0..a8225ba 100644
  43706. --- a/drivers/net/wireless/zd1211rw/zd_usb.c
  43707. +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
  43708. @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
  43709. {
  43710. struct zd_usb *usb = urb->context;
  43711. struct zd_usb_interrupt *intr = &usb->intr;
  43712. - int len;
  43713. + unsigned int len;
  43714. u16 int_num;
  43715. ZD_ASSERT(in_interrupt());
  43716. diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
  43717. index 683671a..4519fc2 100644
  43718. --- a/drivers/nfc/nfcwilink.c
  43719. +++ b/drivers/nfc/nfcwilink.c
  43720. @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
  43721. static int nfcwilink_probe(struct platform_device *pdev)
  43722. {
  43723. - static struct nfcwilink *drv;
  43724. + struct nfcwilink *drv;
  43725. int rc;
  43726. __u32 protocols;
  43727. diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
  43728. index d93b2b6..ae50401 100644
  43729. --- a/drivers/oprofile/buffer_sync.c
  43730. +++ b/drivers/oprofile/buffer_sync.c
  43731. @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
  43732. if (cookie == NO_COOKIE)
  43733. offset = pc;
  43734. if (cookie == INVALID_COOKIE) {
  43735. - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
  43736. + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
  43737. offset = pc;
  43738. }
  43739. if (cookie != last_cookie) {
  43740. @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
  43741. /* add userspace sample */
  43742. if (!mm) {
  43743. - atomic_inc(&oprofile_stats.sample_lost_no_mm);
  43744. + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
  43745. return 0;
  43746. }
  43747. cookie = lookup_dcookie(mm, s->eip, &offset);
  43748. if (cookie == INVALID_COOKIE) {
  43749. - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
  43750. + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
  43751. return 0;
  43752. }
  43753. @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
  43754. /* ignore backtraces if failed to add a sample */
  43755. if (state == sb_bt_start) {
  43756. state = sb_bt_ignore;
  43757. - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
  43758. + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
  43759. }
  43760. }
  43761. release_mm(mm);
  43762. diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
  43763. index c0cc4e7..44d4e54 100644
  43764. --- a/drivers/oprofile/event_buffer.c
  43765. +++ b/drivers/oprofile/event_buffer.c
  43766. @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
  43767. }
  43768. if (buffer_pos == buffer_size) {
  43769. - atomic_inc(&oprofile_stats.event_lost_overflow);
  43770. + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
  43771. return;
  43772. }
  43773. diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
  43774. index ed2c3ec..deda85a 100644
  43775. --- a/drivers/oprofile/oprof.c
  43776. +++ b/drivers/oprofile/oprof.c
  43777. @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
  43778. if (oprofile_ops.switch_events())
  43779. return;
  43780. - atomic_inc(&oprofile_stats.multiplex_counter);
  43781. + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
  43782. start_switch_worker();
  43783. }
  43784. diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
  43785. index ee2cfce..7f8f699 100644
  43786. --- a/drivers/oprofile/oprofile_files.c
  43787. +++ b/drivers/oprofile/oprofile_files.c
  43788. @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
  43789. #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
  43790. -static ssize_t timeout_read(struct file *file, char __user *buf,
  43791. +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
  43792. size_t count, loff_t *offset)
  43793. {
  43794. return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
  43795. diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
  43796. index 59659ce..6c860a0 100644
  43797. --- a/drivers/oprofile/oprofile_stats.c
  43798. +++ b/drivers/oprofile/oprofile_stats.c
  43799. @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
  43800. cpu_buf->sample_invalid_eip = 0;
  43801. }
  43802. - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
  43803. - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
  43804. - atomic_set(&oprofile_stats.event_lost_overflow, 0);
  43805. - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
  43806. - atomic_set(&oprofile_stats.multiplex_counter, 0);
  43807. + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
  43808. + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
  43809. + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
  43810. + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
  43811. + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
  43812. }
  43813. diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
  43814. index 1fc622b..8c48fc3 100644
  43815. --- a/drivers/oprofile/oprofile_stats.h
  43816. +++ b/drivers/oprofile/oprofile_stats.h
  43817. @@ -13,11 +13,11 @@
  43818. #include <linux/atomic.h>
  43819. struct oprofile_stat_struct {
  43820. - atomic_t sample_lost_no_mm;
  43821. - atomic_t sample_lost_no_mapping;
  43822. - atomic_t bt_lost_no_mapping;
  43823. - atomic_t event_lost_overflow;
  43824. - atomic_t multiplex_counter;
  43825. + atomic_unchecked_t sample_lost_no_mm;
  43826. + atomic_unchecked_t sample_lost_no_mapping;
  43827. + atomic_unchecked_t bt_lost_no_mapping;
  43828. + atomic_unchecked_t event_lost_overflow;
  43829. + atomic_unchecked_t multiplex_counter;
  43830. };
  43831. extern struct oprofile_stat_struct oprofile_stats;
  43832. diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
  43833. index 3f49345..c750d0b 100644
  43834. --- a/drivers/oprofile/oprofilefs.c
  43835. +++ b/drivers/oprofile/oprofilefs.c
  43836. @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
  43837. static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
  43838. {
  43839. - atomic_t *val = file->private_data;
  43840. - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
  43841. + atomic_unchecked_t *val = file->private_data;
  43842. + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
  43843. }
  43844. @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
  43845. int oprofilefs_create_ro_atomic(struct dentry *root,
  43846. - char const *name, atomic_t *val)
  43847. + char const *name, atomic_unchecked_t *val)
  43848. {
  43849. return __oprofilefs_create_file(root, name,
  43850. &atomic_ro_fops, 0444, val);
  43851. diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
  43852. index 61be1d9..dec05d7 100644
  43853. --- a/drivers/oprofile/timer_int.c
  43854. +++ b/drivers/oprofile/timer_int.c
  43855. @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
  43856. return NOTIFY_OK;
  43857. }
  43858. -static struct notifier_block __refdata oprofile_cpu_notifier = {
  43859. +static struct notifier_block oprofile_cpu_notifier = {
  43860. .notifier_call = oprofile_cpu_notify,
  43861. };
  43862. diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
  43863. index 92ed045..62d39bd7 100644
  43864. --- a/drivers/parport/procfs.c
  43865. +++ b/drivers/parport/procfs.c
  43866. @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
  43867. *ppos += len;
  43868. - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
  43869. + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
  43870. }
  43871. #ifdef CONFIG_PARPORT_1284
  43872. @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
  43873. *ppos += len;
  43874. - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
  43875. + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
  43876. }
  43877. #endif /* IEEE1284.3 support. */
  43878. diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
  43879. index 8dcccff..35d701d 100644
  43880. --- a/drivers/pci/hotplug/acpiphp_ibm.c
  43881. +++ b/drivers/pci/hotplug/acpiphp_ibm.c
  43882. @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
  43883. goto init_cleanup;
  43884. }
  43885. - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
  43886. + pax_open_kernel();
  43887. + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
  43888. + pax_close_kernel();
  43889. retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
  43890. return retval;
  43891. diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
  43892. index 7536eef..52dc8fa 100644
  43893. --- a/drivers/pci/hotplug/cpcihp_generic.c
  43894. +++ b/drivers/pci/hotplug/cpcihp_generic.c
  43895. @@ -73,7 +73,6 @@ static u16 port;
  43896. static unsigned int enum_bit;
  43897. static u8 enum_mask;
  43898. -static struct cpci_hp_controller_ops generic_hpc_ops;
  43899. static struct cpci_hp_controller generic_hpc;
  43900. static int __init validate_parameters(void)
  43901. @@ -139,6 +138,10 @@ static int query_enum(void)
  43902. return ((value & enum_mask) == enum_mask);
  43903. }
  43904. +static struct cpci_hp_controller_ops generic_hpc_ops = {
  43905. + .query_enum = query_enum,
  43906. +};
  43907. +
  43908. static int __init cpcihp_generic_init(void)
  43909. {
  43910. int status;
  43911. @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
  43912. pci_dev_put(dev);
  43913. memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
  43914. - generic_hpc_ops.query_enum = query_enum;
  43915. generic_hpc.ops = &generic_hpc_ops;
  43916. status = cpci_hp_register_controller(&generic_hpc);
  43917. diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
  43918. index e8c4a7c..7046f5c 100644
  43919. --- a/drivers/pci/hotplug/cpcihp_zt5550.c
  43920. +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
  43921. @@ -59,7 +59,6 @@
  43922. /* local variables */
  43923. static bool debug;
  43924. static bool poll;
  43925. -static struct cpci_hp_controller_ops zt5550_hpc_ops;
  43926. static struct cpci_hp_controller zt5550_hpc;
  43927. /* Primary cPCI bus bridge device */
  43928. @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
  43929. return 0;
  43930. }
  43931. +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
  43932. + .query_enum = zt5550_hc_query_enum,
  43933. +};
  43934. +
  43935. static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  43936. {
  43937. int status;
  43938. @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
  43939. dbg("returned from zt5550_hc_config");
  43940. memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
  43941. - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
  43942. zt5550_hpc.ops = &zt5550_hpc_ops;
  43943. if(!poll) {
  43944. zt5550_hpc.irq = hc_dev->irq;
  43945. zt5550_hpc.irq_flags = IRQF_SHARED;
  43946. zt5550_hpc.dev_id = hc_dev;
  43947. - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
  43948. - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
  43949. - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
  43950. + pax_open_kernel();
  43951. + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
  43952. + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
  43953. + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
  43954. + pax_open_kernel();
  43955. } else {
  43956. info("using ENUM# polling mode");
  43957. }
  43958. diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
  43959. index 76ba8a1..20ca857 100644
  43960. --- a/drivers/pci/hotplug/cpqphp_nvram.c
  43961. +++ b/drivers/pci/hotplug/cpqphp_nvram.c
  43962. @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
  43963. void compaq_nvram_init (void __iomem *rom_start)
  43964. {
  43965. +
  43966. +#ifndef CONFIG_PAX_KERNEXEC
  43967. if (rom_start) {
  43968. compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
  43969. }
  43970. +#endif
  43971. +
  43972. dbg("int15 entry = %p\n", compaq_int15_entry_point);
  43973. /* initialize our int15 lock */
  43974. diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
  43975. index cfa92a9..29539c5 100644
  43976. --- a/drivers/pci/hotplug/pci_hotplug_core.c
  43977. +++ b/drivers/pci/hotplug/pci_hotplug_core.c
  43978. @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
  43979. return -EINVAL;
  43980. }
  43981. - slot->ops->owner = owner;
  43982. - slot->ops->mod_name = mod_name;
  43983. + pax_open_kernel();
  43984. + *(struct module **)&slot->ops->owner = owner;
  43985. + *(const char **)&slot->ops->mod_name = mod_name;
  43986. + pax_close_kernel();
  43987. mutex_lock(&pci_hp_mutex);
  43988. /*
  43989. diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
  43990. index 53b58de..4479896 100644
  43991. --- a/drivers/pci/hotplug/pciehp_core.c
  43992. +++ b/drivers/pci/hotplug/pciehp_core.c
  43993. @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
  43994. struct slot *slot = ctrl->slot;
  43995. struct hotplug_slot *hotplug = NULL;
  43996. struct hotplug_slot_info *info = NULL;
  43997. - struct hotplug_slot_ops *ops = NULL;
  43998. + hotplug_slot_ops_no_const *ops = NULL;
  43999. char name[SLOT_NAME_SIZE];
  44000. int retval = -ENOMEM;
  44001. diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
  44002. index 955ab79..d1df9c7 100644
  44003. --- a/drivers/pci/msi.c
  44004. +++ b/drivers/pci/msi.c
  44005. @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
  44006. {
  44007. struct attribute **msi_attrs;
  44008. struct attribute *msi_attr;
  44009. - struct device_attribute *msi_dev_attr;
  44010. - struct attribute_group *msi_irq_group;
  44011. + device_attribute_no_const *msi_dev_attr;
  44012. + attribute_group_no_const *msi_irq_group;
  44013. const struct attribute_group **msi_irq_groups;
  44014. struct msi_desc *entry;
  44015. int ret = -ENOMEM;
  44016. @@ -589,7 +589,7 @@ error_attrs:
  44017. count = 0;
  44018. msi_attr = msi_attrs[count];
  44019. while (msi_attr) {
  44020. - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
  44021. + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
  44022. kfree(msi_attr->name);
  44023. kfree(msi_dev_attr);
  44024. ++count;
  44025. diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
  44026. index 276ef9c..1d33a36 100644
  44027. --- a/drivers/pci/pci-sysfs.c
  44028. +++ b/drivers/pci/pci-sysfs.c
  44029. @@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
  44030. {
  44031. /* allocate attribute structure, piggyback attribute name */
  44032. int name_len = write_combine ? 13 : 10;
  44033. - struct bin_attribute *res_attr;
  44034. + bin_attribute_no_const *res_attr;
  44035. int retval;
  44036. res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
  44037. @@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
  44038. static int pci_create_capabilities_sysfs(struct pci_dev *dev)
  44039. {
  44040. int retval;
  44041. - struct bin_attribute *attr;
  44042. + bin_attribute_no_const *attr;
  44043. /* If the device has VPD, try to expose it in sysfs. */
  44044. if (dev->vpd) {
  44045. @@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
  44046. {
  44047. int retval;
  44048. int rom_size = 0;
  44049. - struct bin_attribute *attr;
  44050. + bin_attribute_no_const *attr;
  44051. if (!sysfs_initialized)
  44052. return -EACCES;
  44053. diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
  44054. index 4df38df..b6bb7fe 100644
  44055. --- a/drivers/pci/pci.h
  44056. +++ b/drivers/pci/pci.h
  44057. @@ -93,7 +93,7 @@ struct pci_vpd_ops {
  44058. struct pci_vpd {
  44059. unsigned int len;
  44060. const struct pci_vpd_ops *ops;
  44061. - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
  44062. + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
  44063. };
  44064. int pci_vpd_pci22_init(struct pci_dev *dev);
  44065. diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
  44066. index e1e7026..d28dd33 100644
  44067. --- a/drivers/pci/pcie/aspm.c
  44068. +++ b/drivers/pci/pcie/aspm.c
  44069. @@ -27,9 +27,9 @@
  44070. #define MODULE_PARAM_PREFIX "pcie_aspm."
  44071. /* Note: those are not register definitions */
  44072. -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
  44073. -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
  44074. -#define ASPM_STATE_L1 (4) /* L1 state */
  44075. +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
  44076. +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
  44077. +#define ASPM_STATE_L1 (4U) /* L1 state */
  44078. #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
  44079. #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
  44080. diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
  44081. index 6e34498..9911975 100644
  44082. --- a/drivers/pci/probe.c
  44083. +++ b/drivers/pci/probe.c
  44084. @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
  44085. struct pci_bus_region region, inverted_region;
  44086. bool bar_too_big = false, bar_disabled = false;
  44087. - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
  44088. + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
  44089. /* No printks while decoding is disabled! */
  44090. if (!dev->mmio_always_on) {
  44091. diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
  44092. index 46d1378..30e452b 100644
  44093. --- a/drivers/pci/proc.c
  44094. +++ b/drivers/pci/proc.c
  44095. @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
  44096. static int __init pci_proc_init(void)
  44097. {
  44098. struct pci_dev *dev = NULL;
  44099. +
  44100. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  44101. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  44102. + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
  44103. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  44104. + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
  44105. +#endif
  44106. +#else
  44107. proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
  44108. +#endif
  44109. proc_create("devices", 0, proc_bus_pci_dir,
  44110. &proc_bus_pci_dev_operations);
  44111. proc_initialized = 1;
  44112. diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
  44113. index 7f3aad0..7d604bb 100644
  44114. --- a/drivers/platform/chrome/chromeos_laptop.c
  44115. +++ b/drivers/platform/chrome/chromeos_laptop.c
  44116. @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
  44117. .callback = chromeos_laptop_dmi_matched, \
  44118. .driver_data = (void *)&board_
  44119. -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
  44120. +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
  44121. {
  44122. .ident = "Samsung Series 5 550",
  44123. .matches = {
  44124. diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
  44125. index c5e082f..d6307a0 100644
  44126. --- a/drivers/platform/x86/asus-wmi.c
  44127. +++ b/drivers/platform/x86/asus-wmi.c
  44128. @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
  44129. int err;
  44130. u32 retval = -1;
  44131. +#ifdef CONFIG_GRKERNSEC_KMEM
  44132. + return -EPERM;
  44133. +#endif
  44134. +
  44135. err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
  44136. if (err < 0)
  44137. @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
  44138. int err;
  44139. u32 retval = -1;
  44140. +#ifdef CONFIG_GRKERNSEC_KMEM
  44141. + return -EPERM;
  44142. +#endif
  44143. +
  44144. err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
  44145. &retval);
  44146. @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
  44147. union acpi_object *obj;
  44148. acpi_status status;
  44149. +#ifdef CONFIG_GRKERNSEC_KMEM
  44150. + return -EPERM;
  44151. +#endif
  44152. +
  44153. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
  44154. 1, asus->debug.method_id,
  44155. &input, &output);
  44156. diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
  44157. index 62f8030..c7f2a45 100644
  44158. --- a/drivers/platform/x86/msi-laptop.c
  44159. +++ b/drivers/platform/x86/msi-laptop.c
  44160. @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
  44161. if (!quirks->ec_read_only) {
  44162. /* allow userland write sysfs file */
  44163. - dev_attr_bluetooth.store = store_bluetooth;
  44164. - dev_attr_wlan.store = store_wlan;
  44165. - dev_attr_threeg.store = store_threeg;
  44166. - dev_attr_bluetooth.attr.mode |= S_IWUSR;
  44167. - dev_attr_wlan.attr.mode |= S_IWUSR;
  44168. - dev_attr_threeg.attr.mode |= S_IWUSR;
  44169. + pax_open_kernel();
  44170. + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
  44171. + *(void **)&dev_attr_wlan.store = store_wlan;
  44172. + *(void **)&dev_attr_threeg.store = store_threeg;
  44173. + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
  44174. + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
  44175. + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
  44176. + pax_close_kernel();
  44177. }
  44178. /* disable hardware control by fn key */
  44179. diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
  44180. index 70222f2..8c8ce66 100644
  44181. --- a/drivers/platform/x86/msi-wmi.c
  44182. +++ b/drivers/platform/x86/msi-wmi.c
  44183. @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
  44184. static void msi_wmi_notify(u32 value, void *context)
  44185. {
  44186. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  44187. - static struct key_entry *key;
  44188. + struct key_entry *key;
  44189. union acpi_object *obj;
  44190. acpi_status status;
  44191. diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
  44192. index 8f8551a..3ace3ca 100644
  44193. --- a/drivers/platform/x86/sony-laptop.c
  44194. +++ b/drivers/platform/x86/sony-laptop.c
  44195. @@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
  44196. }
  44197. /* High speed charging function */
  44198. -static struct device_attribute *hsc_handle;
  44199. +static device_attribute_no_const *hsc_handle;
  44200. static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
  44201. struct device_attribute *attr,
  44202. diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
  44203. index e2a91c8..986cc9f 100644
  44204. --- a/drivers/platform/x86/thinkpad_acpi.c
  44205. +++ b/drivers/platform/x86/thinkpad_acpi.c
  44206. @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
  44207. return 0;
  44208. }
  44209. -void static hotkey_mask_warn_incomplete_mask(void)
  44210. +static void hotkey_mask_warn_incomplete_mask(void)
  44211. {
  44212. /* log only what the user can fix... */
  44213. const u32 wantedmask = hotkey_driver_mask &
  44214. @@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
  44215. }
  44216. }
  44217. -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44218. - struct tp_nvram_state *newn,
  44219. - const u32 event_mask)
  44220. -{
  44221. -
  44222. #define TPACPI_COMPARE_KEY(__scancode, __member) \
  44223. do { \
  44224. if ((event_mask & (1 << __scancode)) && \
  44225. @@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44226. tpacpi_hotkey_send_key(__scancode); \
  44227. } while (0)
  44228. - void issue_volchange(const unsigned int oldvol,
  44229. - const unsigned int newvol)
  44230. - {
  44231. - unsigned int i = oldvol;
  44232. +static void issue_volchange(const unsigned int oldvol,
  44233. + const unsigned int newvol,
  44234. + const u32 event_mask)
  44235. +{
  44236. + unsigned int i = oldvol;
  44237. - while (i > newvol) {
  44238. - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
  44239. - i--;
  44240. - }
  44241. - while (i < newvol) {
  44242. - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
  44243. - i++;
  44244. - }
  44245. + while (i > newvol) {
  44246. + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
  44247. + i--;
  44248. }
  44249. + while (i < newvol) {
  44250. + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
  44251. + i++;
  44252. + }
  44253. +}
  44254. - void issue_brightnesschange(const unsigned int oldbrt,
  44255. - const unsigned int newbrt)
  44256. - {
  44257. - unsigned int i = oldbrt;
  44258. +static void issue_brightnesschange(const unsigned int oldbrt,
  44259. + const unsigned int newbrt,
  44260. + const u32 event_mask)
  44261. +{
  44262. + unsigned int i = oldbrt;
  44263. - while (i > newbrt) {
  44264. - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
  44265. - i--;
  44266. - }
  44267. - while (i < newbrt) {
  44268. - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
  44269. - i++;
  44270. - }
  44271. + while (i > newbrt) {
  44272. + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
  44273. + i--;
  44274. + }
  44275. + while (i < newbrt) {
  44276. + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
  44277. + i++;
  44278. }
  44279. +}
  44280. +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44281. + struct tp_nvram_state *newn,
  44282. + const u32 event_mask)
  44283. +{
  44284. TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
  44285. TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
  44286. TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
  44287. @@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44288. oldn->volume_level != newn->volume_level) {
  44289. /* recently muted, or repeated mute keypress, or
  44290. * multiple presses ending in mute */
  44291. - issue_volchange(oldn->volume_level, newn->volume_level);
  44292. + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
  44293. TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
  44294. }
  44295. } else {
  44296. @@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44297. TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
  44298. }
  44299. if (oldn->volume_level != newn->volume_level) {
  44300. - issue_volchange(oldn->volume_level, newn->volume_level);
  44301. + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
  44302. } else if (oldn->volume_toggle != newn->volume_toggle) {
  44303. /* repeated vol up/down keypress at end of scale ? */
  44304. if (newn->volume_level == 0)
  44305. @@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44306. /* handle brightness */
  44307. if (oldn->brightness_level != newn->brightness_level) {
  44308. issue_brightnesschange(oldn->brightness_level,
  44309. - newn->brightness_level);
  44310. + newn->brightness_level,
  44311. + event_mask);
  44312. } else if (oldn->brightness_toggle != newn->brightness_toggle) {
  44313. /* repeated key presses that didn't change state */
  44314. if (newn->brightness_level == 0)
  44315. @@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
  44316. && !tp_features.bright_unkfw)
  44317. TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
  44318. }
  44319. +}
  44320. #undef TPACPI_COMPARE_KEY
  44321. #undef TPACPI_MAY_SEND_KEY
  44322. -}
  44323. /*
  44324. * Polling driver
  44325. diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
  44326. index 769d265..a3a05ca 100644
  44327. --- a/drivers/pnp/pnpbios/bioscalls.c
  44328. +++ b/drivers/pnp/pnpbios/bioscalls.c
  44329. @@ -58,7 +58,7 @@ do { \
  44330. set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
  44331. } while(0)
  44332. -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
  44333. +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
  44334. (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
  44335. /*
  44336. @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
  44337. cpu = get_cpu();
  44338. save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
  44339. +
  44340. + pax_open_kernel();
  44341. get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
  44342. + pax_close_kernel();
  44343. /* On some boxes IRQ's during PnP BIOS calls are deadly. */
  44344. spin_lock_irqsave(&pnp_bios_lock, flags);
  44345. @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
  44346. :"memory");
  44347. spin_unlock_irqrestore(&pnp_bios_lock, flags);
  44348. + pax_open_kernel();
  44349. get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
  44350. + pax_close_kernel();
  44351. +
  44352. put_cpu();
  44353. /* If we get here and this is set then the PnP BIOS faulted on us. */
  44354. @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
  44355. return status;
  44356. }
  44357. -void pnpbios_calls_init(union pnp_bios_install_struct *header)
  44358. +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
  44359. {
  44360. int i;
  44361. @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
  44362. pnp_bios_callpoint.offset = header->fields.pm16offset;
  44363. pnp_bios_callpoint.segment = PNP_CS16;
  44364. + pax_open_kernel();
  44365. +
  44366. for_each_possible_cpu(i) {
  44367. struct desc_struct *gdt = get_cpu_gdt_table(i);
  44368. if (!gdt)
  44369. @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
  44370. set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
  44371. (unsigned long)__va(header->fields.pm16dseg));
  44372. }
  44373. +
  44374. + pax_close_kernel();
  44375. }
  44376. diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
  44377. index bacddd1..65ea100 100644
  44378. --- a/drivers/pnp/resource.c
  44379. +++ b/drivers/pnp/resource.c
  44380. @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
  44381. return 1;
  44382. /* check if the resource is valid */
  44383. - if (*irq < 0 || *irq > 15)
  44384. + if (*irq > 15)
  44385. return 0;
  44386. /* check if the resource is reserved */
  44387. @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
  44388. return 1;
  44389. /* check if the resource is valid */
  44390. - if (*dma < 0 || *dma == 4 || *dma > 7)
  44391. + if (*dma == 4 || *dma > 7)
  44392. return 0;
  44393. /* check if the resource is reserved */
  44394. diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
  44395. index 0c52e2a..3421ab7 100644
  44396. --- a/drivers/power/pda_power.c
  44397. +++ b/drivers/power/pda_power.c
  44398. @@ -37,7 +37,11 @@ static int polling;
  44399. #if IS_ENABLED(CONFIG_USB_PHY)
  44400. static struct usb_phy *transceiver;
  44401. -static struct notifier_block otg_nb;
  44402. +static int otg_handle_notification(struct notifier_block *nb,
  44403. + unsigned long event, void *unused);
  44404. +static struct notifier_block otg_nb = {
  44405. + .notifier_call = otg_handle_notification
  44406. +};
  44407. #endif
  44408. static struct regulator *ac_draw;
  44409. @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
  44410. #if IS_ENABLED(CONFIG_USB_PHY)
  44411. if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
  44412. - otg_nb.notifier_call = otg_handle_notification;
  44413. ret = usb_register_notifier(transceiver, &otg_nb);
  44414. if (ret) {
  44415. dev_err(dev, "failure to register otg notifier\n");
  44416. diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
  44417. index cc439fd..8fa30df 100644
  44418. --- a/drivers/power/power_supply.h
  44419. +++ b/drivers/power/power_supply.h
  44420. @@ -16,12 +16,12 @@ struct power_supply;
  44421. #ifdef CONFIG_SYSFS
  44422. -extern void power_supply_init_attrs(struct device_type *dev_type);
  44423. +extern void power_supply_init_attrs(void);
  44424. extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
  44425. #else
  44426. -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
  44427. +static inline void power_supply_init_attrs(void) {}
  44428. #define power_supply_uevent NULL
  44429. #endif /* CONFIG_SYSFS */
  44430. diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
  44431. index 2660664..75fcb04 100644
  44432. --- a/drivers/power/power_supply_core.c
  44433. +++ b/drivers/power/power_supply_core.c
  44434. @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
  44435. ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
  44436. EXPORT_SYMBOL_GPL(power_supply_notifier);
  44437. -static struct device_type power_supply_dev_type;
  44438. +extern const struct attribute_group *power_supply_attr_groups[];
  44439. +static struct device_type power_supply_dev_type = {
  44440. + .groups = power_supply_attr_groups,
  44441. +};
  44442. static bool __power_supply_is_supplied_by(struct power_supply *supplier,
  44443. struct power_supply *supply)
  44444. @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
  44445. return PTR_ERR(power_supply_class);
  44446. power_supply_class->dev_uevent = power_supply_uevent;
  44447. - power_supply_init_attrs(&power_supply_dev_type);
  44448. + power_supply_init_attrs();
  44449. return 0;
  44450. }
  44451. diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
  44452. index 44420d1..967126e 100644
  44453. --- a/drivers/power/power_supply_sysfs.c
  44454. +++ b/drivers/power/power_supply_sysfs.c
  44455. @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
  44456. .is_visible = power_supply_attr_is_visible,
  44457. };
  44458. -static const struct attribute_group *power_supply_attr_groups[] = {
  44459. +const struct attribute_group *power_supply_attr_groups[] = {
  44460. &power_supply_attr_group,
  44461. NULL,
  44462. };
  44463. -void power_supply_init_attrs(struct device_type *dev_type)
  44464. +void power_supply_init_attrs(void)
  44465. {
  44466. int i;
  44467. - dev_type->groups = power_supply_attr_groups;
  44468. -
  44469. for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
  44470. __power_supply_attrs[i] = &power_supply_attrs[i].attr;
  44471. }
  44472. diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
  44473. index 84419af..268ede8 100644
  44474. --- a/drivers/powercap/powercap_sys.c
  44475. +++ b/drivers/powercap/powercap_sys.c
  44476. @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
  44477. struct device_attribute name_attr;
  44478. };
  44479. +static ssize_t show_constraint_name(struct device *dev,
  44480. + struct device_attribute *dev_attr,
  44481. + char *buf);
  44482. +
  44483. static struct powercap_constraint_attr
  44484. - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
  44485. + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
  44486. + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
  44487. + .power_limit_attr = {
  44488. + .attr = {
  44489. + .name = NULL,
  44490. + .mode = S_IWUSR | S_IRUGO
  44491. + },
  44492. + .show = show_constraint_power_limit_uw,
  44493. + .store = store_constraint_power_limit_uw
  44494. + },
  44495. +
  44496. + .time_window_attr = {
  44497. + .attr = {
  44498. + .name = NULL,
  44499. + .mode = S_IWUSR | S_IRUGO
  44500. + },
  44501. + .show = show_constraint_time_window_us,
  44502. + .store = store_constraint_time_window_us
  44503. + },
  44504. +
  44505. + .max_power_attr = {
  44506. + .attr = {
  44507. + .name = NULL,
  44508. + .mode = S_IRUGO
  44509. + },
  44510. + .show = show_constraint_max_power_uw,
  44511. + .store = NULL
  44512. + },
  44513. +
  44514. + .min_power_attr = {
  44515. + .attr = {
  44516. + .name = NULL,
  44517. + .mode = S_IRUGO
  44518. + },
  44519. + .show = show_constraint_min_power_uw,
  44520. + .store = NULL
  44521. + },
  44522. +
  44523. + .max_time_window_attr = {
  44524. + .attr = {
  44525. + .name = NULL,
  44526. + .mode = S_IRUGO
  44527. + },
  44528. + .show = show_constraint_max_time_window_us,
  44529. + .store = NULL
  44530. + },
  44531. +
  44532. + .min_time_window_attr = {
  44533. + .attr = {
  44534. + .name = NULL,
  44535. + .mode = S_IRUGO
  44536. + },
  44537. + .show = show_constraint_min_time_window_us,
  44538. + .store = NULL
  44539. + },
  44540. +
  44541. + .name_attr = {
  44542. + .attr = {
  44543. + .name = NULL,
  44544. + .mode = S_IRUGO
  44545. + },
  44546. + .show = show_constraint_name,
  44547. + .store = NULL
  44548. + }
  44549. + }
  44550. +};
  44551. /* A list of powercap control_types */
  44552. static LIST_HEAD(powercap_cntrl_list);
  44553. @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
  44554. }
  44555. static int create_constraint_attribute(int id, const char *name,
  44556. - int mode,
  44557. - struct device_attribute *dev_attr,
  44558. - ssize_t (*show)(struct device *,
  44559. - struct device_attribute *, char *),
  44560. - ssize_t (*store)(struct device *,
  44561. - struct device_attribute *,
  44562. - const char *, size_t)
  44563. - )
  44564. + struct device_attribute *dev_attr)
  44565. {
  44566. + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
  44567. - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
  44568. - id, name);
  44569. - if (!dev_attr->attr.name)
  44570. + if (!name)
  44571. return -ENOMEM;
  44572. - dev_attr->attr.mode = mode;
  44573. - dev_attr->show = show;
  44574. - dev_attr->store = store;
  44575. +
  44576. + pax_open_kernel();
  44577. + *(const char **)&dev_attr->attr.name = name;
  44578. + pax_close_kernel();
  44579. return 0;
  44580. }
  44581. @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
  44582. for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
  44583. ret = create_constraint_attribute(i, "power_limit_uw",
  44584. - S_IWUSR | S_IRUGO,
  44585. - &constraint_attrs[i].power_limit_attr,
  44586. - show_constraint_power_limit_uw,
  44587. - store_constraint_power_limit_uw);
  44588. + &constraint_attrs[i].power_limit_attr);
  44589. if (ret)
  44590. goto err_alloc;
  44591. ret = create_constraint_attribute(i, "time_window_us",
  44592. - S_IWUSR | S_IRUGO,
  44593. - &constraint_attrs[i].time_window_attr,
  44594. - show_constraint_time_window_us,
  44595. - store_constraint_time_window_us);
  44596. + &constraint_attrs[i].time_window_attr);
  44597. if (ret)
  44598. goto err_alloc;
  44599. - ret = create_constraint_attribute(i, "name", S_IRUGO,
  44600. - &constraint_attrs[i].name_attr,
  44601. - show_constraint_name,
  44602. - NULL);
  44603. + ret = create_constraint_attribute(i, "name",
  44604. + &constraint_attrs[i].name_attr);
  44605. if (ret)
  44606. goto err_alloc;
  44607. - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
  44608. - &constraint_attrs[i].max_power_attr,
  44609. - show_constraint_max_power_uw,
  44610. - NULL);
  44611. + ret = create_constraint_attribute(i, "max_power_uw",
  44612. + &constraint_attrs[i].max_power_attr);
  44613. if (ret)
  44614. goto err_alloc;
  44615. - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
  44616. - &constraint_attrs[i].min_power_attr,
  44617. - show_constraint_min_power_uw,
  44618. - NULL);
  44619. + ret = create_constraint_attribute(i, "min_power_uw",
  44620. + &constraint_attrs[i].min_power_attr);
  44621. if (ret)
  44622. goto err_alloc;
  44623. ret = create_constraint_attribute(i, "max_time_window_us",
  44624. - S_IRUGO,
  44625. - &constraint_attrs[i].max_time_window_attr,
  44626. - show_constraint_max_time_window_us,
  44627. - NULL);
  44628. + &constraint_attrs[i].max_time_window_attr);
  44629. if (ret)
  44630. goto err_alloc;
  44631. ret = create_constraint_attribute(i, "min_time_window_us",
  44632. - S_IRUGO,
  44633. - &constraint_attrs[i].min_time_window_attr,
  44634. - show_constraint_min_time_window_us,
  44635. - NULL);
  44636. + &constraint_attrs[i].min_time_window_attr);
  44637. if (ret)
  44638. goto err_alloc;
  44639. @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
  44640. power_zone->zone_dev_attrs[count++] =
  44641. &dev_attr_max_energy_range_uj.attr;
  44642. if (power_zone->ops->get_energy_uj) {
  44643. + pax_open_kernel();
  44644. if (power_zone->ops->reset_energy_uj)
  44645. - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
  44646. + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
  44647. else
  44648. - dev_attr_energy_uj.attr.mode = S_IRUGO;
  44649. + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
  44650. + pax_close_kernel();
  44651. power_zone->zone_dev_attrs[count++] =
  44652. &dev_attr_energy_uj.attr;
  44653. }
  44654. diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
  44655. index afca1bc..86840b8 100644
  44656. --- a/drivers/regulator/core.c
  44657. +++ b/drivers/regulator/core.c
  44658. @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
  44659. {
  44660. const struct regulation_constraints *constraints = NULL;
  44661. const struct regulator_init_data *init_data;
  44662. - static atomic_t regulator_no = ATOMIC_INIT(0);
  44663. + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
  44664. struct regulator_dev *rdev;
  44665. struct device *dev;
  44666. int ret, i;
  44667. @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
  44668. rdev->dev.of_node = config->of_node;
  44669. rdev->dev.parent = dev;
  44670. dev_set_name(&rdev->dev, "regulator.%d",
  44671. - atomic_inc_return(&regulator_no) - 1);
  44672. + atomic_inc_return_unchecked(&regulator_no) - 1);
  44673. ret = device_register(&rdev->dev);
  44674. if (ret != 0) {
  44675. put_device(&rdev->dev);
  44676. diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
  44677. index 8d94d3d..653b623 100644
  44678. --- a/drivers/regulator/max8660.c
  44679. +++ b/drivers/regulator/max8660.c
  44680. @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
  44681. max8660->shadow_regs[MAX8660_OVER1] = 5;
  44682. } else {
  44683. /* Otherwise devices can be toggled via software */
  44684. - max8660_dcdc_ops.enable = max8660_dcdc_enable;
  44685. - max8660_dcdc_ops.disable = max8660_dcdc_disable;
  44686. + pax_open_kernel();
  44687. + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
  44688. + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
  44689. + pax_close_kernel();
  44690. }
  44691. /*
  44692. diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
  44693. index 892aa1e..ebd1b9c 100644
  44694. --- a/drivers/regulator/max8973-regulator.c
  44695. +++ b/drivers/regulator/max8973-regulator.c
  44696. @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
  44697. if (!pdata || !pdata->enable_ext_control) {
  44698. max->desc.enable_reg = MAX8973_VOUT;
  44699. max->desc.enable_mask = MAX8973_VOUT_ENABLE;
  44700. - max->ops.enable = regulator_enable_regmap;
  44701. - max->ops.disable = regulator_disable_regmap;
  44702. - max->ops.is_enabled = regulator_is_enabled_regmap;
  44703. + pax_open_kernel();
  44704. + *(void **)&max->ops.enable = regulator_enable_regmap;
  44705. + *(void **)&max->ops.disable = regulator_disable_regmap;
  44706. + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
  44707. + pax_close_kernel();
  44708. }
  44709. if (pdata) {
  44710. diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
  44711. index f374fa5..26f0683 100644
  44712. --- a/drivers/regulator/mc13892-regulator.c
  44713. +++ b/drivers/regulator/mc13892-regulator.c
  44714. @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
  44715. }
  44716. mc13xxx_unlock(mc13892);
  44717. - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
  44718. + pax_open_kernel();
  44719. + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
  44720. = mc13892_vcam_set_mode;
  44721. - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
  44722. + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
  44723. = mc13892_vcam_get_mode;
  44724. + pax_close_kernel();
  44725. mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
  44726. ARRAY_SIZE(mc13892_regulators));
  44727. diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
  44728. index cae212f..58a3980 100644
  44729. --- a/drivers/rtc/rtc-cmos.c
  44730. +++ b/drivers/rtc/rtc-cmos.c
  44731. @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
  44732. hpet_rtc_timer_init();
  44733. /* export at least the first block of NVRAM */
  44734. - nvram.size = address_space - NVRAM_OFFSET;
  44735. + pax_open_kernel();
  44736. + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
  44737. + pax_close_kernel();
  44738. retval = sysfs_create_bin_file(&dev->kobj, &nvram);
  44739. if (retval < 0) {
  44740. dev_dbg(dev, "can't create nvram file? %d\n", retval);
  44741. diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
  44742. index d049393..bb20be0 100644
  44743. --- a/drivers/rtc/rtc-dev.c
  44744. +++ b/drivers/rtc/rtc-dev.c
  44745. @@ -16,6 +16,7 @@
  44746. #include <linux/module.h>
  44747. #include <linux/rtc.h>
  44748. #include <linux/sched.h>
  44749. +#include <linux/grsecurity.h>
  44750. #include "rtc-core.h"
  44751. static dev_t rtc_devt;
  44752. @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
  44753. if (copy_from_user(&tm, uarg, sizeof(tm)))
  44754. return -EFAULT;
  44755. + gr_log_timechange();
  44756. +
  44757. return rtc_set_time(rtc, &tm);
  44758. case RTC_PIE_ON:
  44759. diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
  44760. index 4e75345..09f8663 100644
  44761. --- a/drivers/rtc/rtc-ds1307.c
  44762. +++ b/drivers/rtc/rtc-ds1307.c
  44763. @@ -107,7 +107,7 @@ struct ds1307 {
  44764. u8 offset; /* register's offset */
  44765. u8 regs[11];
  44766. u16 nvram_offset;
  44767. - struct bin_attribute *nvram;
  44768. + bin_attribute_no_const *nvram;
  44769. enum ds_type type;
  44770. unsigned long flags;
  44771. #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
  44772. diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
  44773. index 11880c1..b823aa4 100644
  44774. --- a/drivers/rtc/rtc-m48t59.c
  44775. +++ b/drivers/rtc/rtc-m48t59.c
  44776. @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
  44777. if (IS_ERR(m48t59->rtc))
  44778. return PTR_ERR(m48t59->rtc);
  44779. - m48t59_nvram_attr.size = pdata->offset;
  44780. + pax_open_kernel();
  44781. + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
  44782. + pax_close_kernel();
  44783. ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
  44784. if (ret)
  44785. diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
  44786. index 14b5f8d..cc9bd26 100644
  44787. --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
  44788. +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
  44789. @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
  44790. for (bit = 0; bit < 8; bit++) {
  44791. if ((pci_status[i] & (0x1 << bit)) != 0) {
  44792. - static const char *s;
  44793. + const char *s;
  44794. s = pci_status_strings[bit];
  44795. if (i == 7/*TARG*/ && bit == 3)
  44796. @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
  44797. for (bit = 0; bit < 8; bit++) {
  44798. - if ((split_status[i] & (0x1 << bit)) != 0) {
  44799. - static const char *s;
  44800. -
  44801. - s = split_status_strings[bit];
  44802. - printk(s, ahd_name(ahd),
  44803. + if ((split_status[i] & (0x1 << bit)) != 0)
  44804. + printk(split_status_strings[bit], ahd_name(ahd),
  44805. split_status_source[i]);
  44806. - }
  44807. if (i > 1)
  44808. continue;
  44809. - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
  44810. - static const char *s;
  44811. -
  44812. - s = split_status_strings[bit];
  44813. - printk(s, ahd_name(ahd), "SG");
  44814. - }
  44815. + if ((sg_split_status[i] & (0x1 << bit)) != 0)
  44816. + printk(split_status_strings[bit], ahd_name(ahd), "SG");
  44817. }
  44818. }
  44819. /*
  44820. diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
  44821. index e693af6..2e525b6 100644
  44822. --- a/drivers/scsi/bfa/bfa_fcpim.h
  44823. +++ b/drivers/scsi/bfa/bfa_fcpim.h
  44824. @@ -36,7 +36,7 @@ struct bfa_iotag_s {
  44825. struct bfa_itn_s {
  44826. bfa_isr_func_t isr;
  44827. -};
  44828. +} __no_const;
  44829. void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
  44830. void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
  44831. diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
  44832. index a3ab5cc..8143622 100644
  44833. --- a/drivers/scsi/bfa/bfa_fcs.c
  44834. +++ b/drivers/scsi/bfa/bfa_fcs.c
  44835. @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
  44836. #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
  44837. static struct bfa_fcs_mod_s fcs_modules[] = {
  44838. - { bfa_fcs_port_attach, NULL, NULL },
  44839. - { bfa_fcs_uf_attach, NULL, NULL },
  44840. - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
  44841. - bfa_fcs_fabric_modexit },
  44842. + {
  44843. + .attach = bfa_fcs_port_attach,
  44844. + .modinit = NULL,
  44845. + .modexit = NULL
  44846. + },
  44847. + {
  44848. + .attach = bfa_fcs_uf_attach,
  44849. + .modinit = NULL,
  44850. + .modexit = NULL
  44851. + },
  44852. + {
  44853. + .attach = bfa_fcs_fabric_attach,
  44854. + .modinit = bfa_fcs_fabric_modinit,
  44855. + .modexit = bfa_fcs_fabric_modexit
  44856. + },
  44857. };
  44858. /*
  44859. diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
  44860. index ff75ef8..2dfe00a 100644
  44861. --- a/drivers/scsi/bfa/bfa_fcs_lport.c
  44862. +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
  44863. @@ -89,15 +89,26 @@ static struct {
  44864. void (*offline) (struct bfa_fcs_lport_s *port);
  44865. } __port_action[] = {
  44866. {
  44867. - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
  44868. - bfa_fcs_lport_unknown_offline}, {
  44869. - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
  44870. - bfa_fcs_lport_fab_offline}, {
  44871. - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
  44872. - bfa_fcs_lport_n2n_offline}, {
  44873. - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
  44874. - bfa_fcs_lport_loop_offline},
  44875. - };
  44876. + .init = bfa_fcs_lport_unknown_init,
  44877. + .online = bfa_fcs_lport_unknown_online,
  44878. + .offline = bfa_fcs_lport_unknown_offline
  44879. + },
  44880. + {
  44881. + .init = bfa_fcs_lport_fab_init,
  44882. + .online = bfa_fcs_lport_fab_online,
  44883. + .offline = bfa_fcs_lport_fab_offline
  44884. + },
  44885. + {
  44886. + .init = bfa_fcs_lport_n2n_init,
  44887. + .online = bfa_fcs_lport_n2n_online,
  44888. + .offline = bfa_fcs_lport_n2n_offline
  44889. + },
  44890. + {
  44891. + .init = bfa_fcs_lport_loop_init,
  44892. + .online = bfa_fcs_lport_loop_online,
  44893. + .offline = bfa_fcs_lport_loop_offline
  44894. + },
  44895. +};
  44896. /*
  44897. * fcs_port_sm FCS logical port state machine
  44898. diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
  44899. index 2e28392..9d865b6 100644
  44900. --- a/drivers/scsi/bfa/bfa_ioc.h
  44901. +++ b/drivers/scsi/bfa/bfa_ioc.h
  44902. @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
  44903. bfa_ioc_disable_cbfn_t disable_cbfn;
  44904. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  44905. bfa_ioc_reset_cbfn_t reset_cbfn;
  44906. -};
  44907. +} __no_const;
  44908. /*
  44909. * IOC event notification mechanism.
  44910. @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
  44911. void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
  44912. enum bfi_ioc_state fwstate);
  44913. enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
  44914. -};
  44915. +} __no_const;
  44916. /*
  44917. * Queue element to wait for room in request queue. FIFO order is
  44918. diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
  44919. index a14c784..6de6790 100644
  44920. --- a/drivers/scsi/bfa/bfa_modules.h
  44921. +++ b/drivers/scsi/bfa/bfa_modules.h
  44922. @@ -78,12 +78,12 @@ enum {
  44923. \
  44924. extern struct bfa_module_s hal_mod_ ## __mod; \
  44925. struct bfa_module_s hal_mod_ ## __mod = { \
  44926. - bfa_ ## __mod ## _meminfo, \
  44927. - bfa_ ## __mod ## _attach, \
  44928. - bfa_ ## __mod ## _detach, \
  44929. - bfa_ ## __mod ## _start, \
  44930. - bfa_ ## __mod ## _stop, \
  44931. - bfa_ ## __mod ## _iocdisable, \
  44932. + .meminfo = bfa_ ## __mod ## _meminfo, \
  44933. + .attach = bfa_ ## __mod ## _attach, \
  44934. + .detach = bfa_ ## __mod ## _detach, \
  44935. + .start = bfa_ ## __mod ## _start, \
  44936. + .stop = bfa_ ## __mod ## _stop, \
  44937. + .iocdisable = bfa_ ## __mod ## _iocdisable, \
  44938. }
  44939. #define BFA_CACHELINE_SZ (256)
  44940. diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
  44941. index 045c4e1..13de803 100644
  44942. --- a/drivers/scsi/fcoe/fcoe_sysfs.c
  44943. +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
  44944. @@ -33,8 +33,8 @@
  44945. */
  44946. #include "libfcoe.h"
  44947. -static atomic_t ctlr_num;
  44948. -static atomic_t fcf_num;
  44949. +static atomic_unchecked_t ctlr_num;
  44950. +static atomic_unchecked_t fcf_num;
  44951. /*
  44952. * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
  44953. @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
  44954. if (!ctlr)
  44955. goto out;
  44956. - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
  44957. + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
  44958. ctlr->f = f;
  44959. ctlr->mode = FIP_CONN_TYPE_FABRIC;
  44960. INIT_LIST_HEAD(&ctlr->fcfs);
  44961. @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
  44962. fcf->dev.parent = &ctlr->dev;
  44963. fcf->dev.bus = &fcoe_bus_type;
  44964. fcf->dev.type = &fcoe_fcf_device_type;
  44965. - fcf->id = atomic_inc_return(&fcf_num) - 1;
  44966. + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
  44967. fcf->state = FCOE_FCF_STATE_UNKNOWN;
  44968. fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
  44969. @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
  44970. {
  44971. int error;
  44972. - atomic_set(&ctlr_num, 0);
  44973. - atomic_set(&fcf_num, 0);
  44974. + atomic_set_unchecked(&ctlr_num, 0);
  44975. + atomic_set_unchecked(&fcf_num, 0);
  44976. error = bus_register(&fcoe_bus_type);
  44977. if (error)
  44978. diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
  44979. index f28ea07..34b16d3 100644
  44980. --- a/drivers/scsi/hosts.c
  44981. +++ b/drivers/scsi/hosts.c
  44982. @@ -42,7 +42,7 @@
  44983. #include "scsi_logging.h"
  44984. -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
  44985. +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
  44986. static void scsi_host_cls_release(struct device *dev)
  44987. @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
  44988. * subtract one because we increment first then return, but we need to
  44989. * know what the next host number was before increment
  44990. */
  44991. - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
  44992. + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
  44993. shost->dma_channel = 0xff;
  44994. /* These three are default values which can be overridden */
  44995. diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
  44996. index 868318a..e07ef3b 100644
  44997. --- a/drivers/scsi/hpsa.c
  44998. +++ b/drivers/scsi/hpsa.c
  44999. @@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
  45000. unsigned long flags;
  45001. if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
  45002. - return h->access.command_completed(h, q);
  45003. + return h->access->command_completed(h, q);
  45004. if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
  45005. a = rq->head[rq->current_entry];
  45006. @@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
  45007. while (!list_empty(&h->reqQ)) {
  45008. c = list_entry(h->reqQ.next, struct CommandList, list);
  45009. /* can't do anything if fifo is full */
  45010. - if ((h->access.fifo_full(h))) {
  45011. + if ((h->access->fifo_full(h))) {
  45012. h->fifo_recently_full = 1;
  45013. dev_warn(&h->pdev->dev, "fifo full\n");
  45014. break;
  45015. @@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
  45016. /* Tell the controller execute command */
  45017. spin_unlock_irqrestore(&h->lock, flags);
  45018. - h->access.submit_command(h, c);
  45019. + h->access->submit_command(h, c);
  45020. spin_lock_irqsave(&h->lock, flags);
  45021. }
  45022. spin_unlock_irqrestore(&h->lock, flags);
  45023. @@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
  45024. static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
  45025. {
  45026. - return h->access.command_completed(h, q);
  45027. + return h->access->command_completed(h, q);
  45028. }
  45029. static inline bool interrupt_pending(struct ctlr_info *h)
  45030. {
  45031. - return h->access.intr_pending(h);
  45032. + return h->access->intr_pending(h);
  45033. }
  45034. static inline long interrupt_not_for_us(struct ctlr_info *h)
  45035. {
  45036. - return (h->access.intr_pending(h) == 0) ||
  45037. + return (h->access->intr_pending(h) == 0) ||
  45038. (h->interrupts_enabled == 0);
  45039. }
  45040. @@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
  45041. if (prod_index < 0)
  45042. return -ENODEV;
  45043. h->product_name = products[prod_index].product_name;
  45044. - h->access = *(products[prod_index].access);
  45045. + h->access = products[prod_index].access;
  45046. pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
  45047. PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
  45048. @@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
  45049. {
  45050. unsigned long flags;
  45051. - h->access.set_intr_mask(h, HPSA_INTR_OFF);
  45052. + h->access->set_intr_mask(h, HPSA_INTR_OFF);
  45053. spin_lock_irqsave(&h->lock, flags);
  45054. h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
  45055. spin_unlock_irqrestore(&h->lock, flags);
  45056. @@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
  45057. }
  45058. /* make sure the board interrupts are off */
  45059. - h->access.set_intr_mask(h, HPSA_INTR_OFF);
  45060. + h->access->set_intr_mask(h, HPSA_INTR_OFF);
  45061. if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
  45062. goto clean2;
  45063. @@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
  45064. * fake ones to scoop up any residual completions.
  45065. */
  45066. spin_lock_irqsave(&h->lock, flags);
  45067. - h->access.set_intr_mask(h, HPSA_INTR_OFF);
  45068. + h->access->set_intr_mask(h, HPSA_INTR_OFF);
  45069. spin_unlock_irqrestore(&h->lock, flags);
  45070. free_irqs(h);
  45071. rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
  45072. @@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
  45073. dev_info(&h->pdev->dev, "Board READY.\n");
  45074. dev_info(&h->pdev->dev,
  45075. "Waiting for stale completions to drain.\n");
  45076. - h->access.set_intr_mask(h, HPSA_INTR_ON);
  45077. + h->access->set_intr_mask(h, HPSA_INTR_ON);
  45078. msleep(10000);
  45079. - h->access.set_intr_mask(h, HPSA_INTR_OFF);
  45080. + h->access->set_intr_mask(h, HPSA_INTR_OFF);
  45081. rc = controller_reset_failed(h->cfgtable);
  45082. if (rc)
  45083. @@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
  45084. }
  45085. /* Turn the interrupts on so we can service requests */
  45086. - h->access.set_intr_mask(h, HPSA_INTR_ON);
  45087. + h->access->set_intr_mask(h, HPSA_INTR_ON);
  45088. hpsa_hba_inquiry(h);
  45089. hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
  45090. @@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
  45091. * To write all data in the battery backed cache to disks
  45092. */
  45093. hpsa_flush_cache(h);
  45094. - h->access.set_intr_mask(h, HPSA_INTR_OFF);
  45095. + h->access->set_intr_mask(h, HPSA_INTR_OFF);
  45096. hpsa_free_irqs_and_disable_msix(h);
  45097. }
  45098. @@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
  45099. return;
  45100. }
  45101. /* Change the access methods to the performant access methods */
  45102. - h->access = SA5_performant_access;
  45103. + h->access = &SA5_performant_access;
  45104. h->transMethod = CFGTBL_Trans_Performant;
  45105. }
  45106. diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
  45107. index 01c3283..4655219 100644
  45108. --- a/drivers/scsi/hpsa.h
  45109. +++ b/drivers/scsi/hpsa.h
  45110. @@ -79,7 +79,7 @@ struct ctlr_info {
  45111. unsigned int msix_vector;
  45112. unsigned int msi_vector;
  45113. int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
  45114. - struct access_method access;
  45115. + struct access_method *access;
  45116. /* queue and queue Info */
  45117. struct list_head reqQ;
  45118. @@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
  45119. }
  45120. static struct access_method SA5_access = {
  45121. - SA5_submit_command,
  45122. - SA5_intr_mask,
  45123. - SA5_fifo_full,
  45124. - SA5_intr_pending,
  45125. - SA5_completed,
  45126. + .submit_command = SA5_submit_command,
  45127. + .set_intr_mask = SA5_intr_mask,
  45128. + .fifo_full = SA5_fifo_full,
  45129. + .intr_pending = SA5_intr_pending,
  45130. + .command_completed = SA5_completed,
  45131. };
  45132. static struct access_method SA5_performant_access = {
  45133. - SA5_submit_command,
  45134. - SA5_performant_intr_mask,
  45135. - SA5_fifo_full,
  45136. - SA5_performant_intr_pending,
  45137. - SA5_performant_completed,
  45138. + .submit_command = SA5_submit_command,
  45139. + .set_intr_mask = SA5_performant_intr_mask,
  45140. + .fifo_full = SA5_fifo_full,
  45141. + .intr_pending = SA5_performant_intr_pending,
  45142. + .command_completed = SA5_performant_completed,
  45143. };
  45144. struct board_type {
  45145. diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
  45146. index 1b3a094..068e683 100644
  45147. --- a/drivers/scsi/libfc/fc_exch.c
  45148. +++ b/drivers/scsi/libfc/fc_exch.c
  45149. @@ -101,12 +101,12 @@ struct fc_exch_mgr {
  45150. u16 pool_max_index;
  45151. struct {
  45152. - atomic_t no_free_exch;
  45153. - atomic_t no_free_exch_xid;
  45154. - atomic_t xid_not_found;
  45155. - atomic_t xid_busy;
  45156. - atomic_t seq_not_found;
  45157. - atomic_t non_bls_resp;
  45158. + atomic_unchecked_t no_free_exch;
  45159. + atomic_unchecked_t no_free_exch_xid;
  45160. + atomic_unchecked_t xid_not_found;
  45161. + atomic_unchecked_t xid_busy;
  45162. + atomic_unchecked_t seq_not_found;
  45163. + atomic_unchecked_t non_bls_resp;
  45164. } stats;
  45165. };
  45166. @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
  45167. /* allocate memory for exchange */
  45168. ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
  45169. if (!ep) {
  45170. - atomic_inc(&mp->stats.no_free_exch);
  45171. + atomic_inc_unchecked(&mp->stats.no_free_exch);
  45172. goto out;
  45173. }
  45174. memset(ep, 0, sizeof(*ep));
  45175. @@ -874,7 +874,7 @@ out:
  45176. return ep;
  45177. err:
  45178. spin_unlock_bh(&pool->lock);
  45179. - atomic_inc(&mp->stats.no_free_exch_xid);
  45180. + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
  45181. mempool_free(ep, mp->ep_pool);
  45182. return NULL;
  45183. }
  45184. @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
  45185. xid = ntohs(fh->fh_ox_id); /* we originated exch */
  45186. ep = fc_exch_find(mp, xid);
  45187. if (!ep) {
  45188. - atomic_inc(&mp->stats.xid_not_found);
  45189. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45190. reject = FC_RJT_OX_ID;
  45191. goto out;
  45192. }
  45193. @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
  45194. ep = fc_exch_find(mp, xid);
  45195. if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
  45196. if (ep) {
  45197. - atomic_inc(&mp->stats.xid_busy);
  45198. + atomic_inc_unchecked(&mp->stats.xid_busy);
  45199. reject = FC_RJT_RX_ID;
  45200. goto rel;
  45201. }
  45202. @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
  45203. }
  45204. xid = ep->xid; /* get our XID */
  45205. } else if (!ep) {
  45206. - atomic_inc(&mp->stats.xid_not_found);
  45207. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45208. reject = FC_RJT_RX_ID; /* XID not found */
  45209. goto out;
  45210. }
  45211. @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
  45212. } else {
  45213. sp = &ep->seq;
  45214. if (sp->id != fh->fh_seq_id) {
  45215. - atomic_inc(&mp->stats.seq_not_found);
  45216. + atomic_inc_unchecked(&mp->stats.seq_not_found);
  45217. if (f_ctl & FC_FC_END_SEQ) {
  45218. /*
  45219. * Update sequence_id based on incoming last
  45220. @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
  45221. ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
  45222. if (!ep) {
  45223. - atomic_inc(&mp->stats.xid_not_found);
  45224. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45225. goto out;
  45226. }
  45227. if (ep->esb_stat & ESB_ST_COMPLETE) {
  45228. - atomic_inc(&mp->stats.xid_not_found);
  45229. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45230. goto rel;
  45231. }
  45232. if (ep->rxid == FC_XID_UNKNOWN)
  45233. ep->rxid = ntohs(fh->fh_rx_id);
  45234. if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
  45235. - atomic_inc(&mp->stats.xid_not_found);
  45236. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45237. goto rel;
  45238. }
  45239. if (ep->did != ntoh24(fh->fh_s_id) &&
  45240. ep->did != FC_FID_FLOGI) {
  45241. - atomic_inc(&mp->stats.xid_not_found);
  45242. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45243. goto rel;
  45244. }
  45245. sof = fr_sof(fp);
  45246. @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
  45247. sp->ssb_stat |= SSB_ST_RESP;
  45248. sp->id = fh->fh_seq_id;
  45249. } else if (sp->id != fh->fh_seq_id) {
  45250. - atomic_inc(&mp->stats.seq_not_found);
  45251. + atomic_inc_unchecked(&mp->stats.seq_not_found);
  45252. goto rel;
  45253. }
  45254. @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
  45255. sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
  45256. if (!sp)
  45257. - atomic_inc(&mp->stats.xid_not_found);
  45258. + atomic_inc_unchecked(&mp->stats.xid_not_found);
  45259. else
  45260. - atomic_inc(&mp->stats.non_bls_resp);
  45261. + atomic_inc_unchecked(&mp->stats.non_bls_resp);
  45262. fc_frame_free(fp);
  45263. }
  45264. @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
  45265. list_for_each_entry(ema, &lport->ema_list, ema_list) {
  45266. mp = ema->mp;
  45267. - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
  45268. + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
  45269. st->fc_no_free_exch_xid +=
  45270. - atomic_read(&mp->stats.no_free_exch_xid);
  45271. - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
  45272. - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
  45273. - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
  45274. - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
  45275. + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
  45276. + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
  45277. + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
  45278. + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
  45279. + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
  45280. }
  45281. }
  45282. EXPORT_SYMBOL(fc_exch_update_stats);
  45283. diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
  45284. index d289583..b745eec 100644
  45285. --- a/drivers/scsi/libsas/sas_ata.c
  45286. +++ b/drivers/scsi/libsas/sas_ata.c
  45287. @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
  45288. .postreset = ata_std_postreset,
  45289. .error_handler = ata_std_error_handler,
  45290. .post_internal_cmd = sas_ata_post_internal,
  45291. - .qc_defer = ata_std_qc_defer,
  45292. + .qc_defer = ata_std_qc_defer,
  45293. .qc_prep = ata_noop_qc_prep,
  45294. .qc_issue = sas_ata_qc_issue,
  45295. .qc_fill_rtf = sas_ata_qc_fill_rtf,
  45296. diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
  45297. index 4e1b75c..0bbdfa9 100644
  45298. --- a/drivers/scsi/lpfc/lpfc.h
  45299. +++ b/drivers/scsi/lpfc/lpfc.h
  45300. @@ -432,7 +432,7 @@ struct lpfc_vport {
  45301. struct dentry *debug_nodelist;
  45302. struct dentry *vport_debugfs_root;
  45303. struct lpfc_debugfs_trc *disc_trc;
  45304. - atomic_t disc_trc_cnt;
  45305. + atomic_unchecked_t disc_trc_cnt;
  45306. #endif
  45307. uint8_t stat_data_enabled;
  45308. uint8_t stat_data_blocked;
  45309. @@ -865,8 +865,8 @@ struct lpfc_hba {
  45310. struct timer_list fabric_block_timer;
  45311. unsigned long bit_flags;
  45312. #define FABRIC_COMANDS_BLOCKED 0
  45313. - atomic_t num_rsrc_err;
  45314. - atomic_t num_cmd_success;
  45315. + atomic_unchecked_t num_rsrc_err;
  45316. + atomic_unchecked_t num_cmd_success;
  45317. unsigned long last_rsrc_error_time;
  45318. unsigned long last_ramp_down_time;
  45319. unsigned long last_ramp_up_time;
  45320. @@ -902,7 +902,7 @@ struct lpfc_hba {
  45321. struct dentry *debug_slow_ring_trc;
  45322. struct lpfc_debugfs_trc *slow_ring_trc;
  45323. - atomic_t slow_ring_trc_cnt;
  45324. + atomic_unchecked_t slow_ring_trc_cnt;
  45325. /* iDiag debugfs sub-directory */
  45326. struct dentry *idiag_root;
  45327. struct dentry *idiag_pci_cfg;
  45328. diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
  45329. index b800cc9..16b6a91 100644
  45330. --- a/drivers/scsi/lpfc/lpfc_debugfs.c
  45331. +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
  45332. @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  45333. #include <linux/debugfs.h>
  45334. -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  45335. +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  45336. static unsigned long lpfc_debugfs_start_time = 0L;
  45337. /* iDiag */
  45338. @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  45339. lpfc_debugfs_enable = 0;
  45340. len = 0;
  45341. - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  45342. + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
  45343. (lpfc_debugfs_max_disc_trc - 1);
  45344. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  45345. dtp = vport->disc_trc + i;
  45346. @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  45347. lpfc_debugfs_enable = 0;
  45348. len = 0;
  45349. - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  45350. + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
  45351. (lpfc_debugfs_max_slow_ring_trc - 1);
  45352. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  45353. dtp = phba->slow_ring_trc + i;
  45354. @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  45355. !vport || !vport->disc_trc)
  45356. return;
  45357. - index = atomic_inc_return(&vport->disc_trc_cnt) &
  45358. + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
  45359. (lpfc_debugfs_max_disc_trc - 1);
  45360. dtp = vport->disc_trc + index;
  45361. dtp->fmt = fmt;
  45362. dtp->data1 = data1;
  45363. dtp->data2 = data2;
  45364. dtp->data3 = data3;
  45365. - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  45366. + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
  45367. dtp->jif = jiffies;
  45368. #endif
  45369. return;
  45370. @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  45371. !phba || !phba->slow_ring_trc)
  45372. return;
  45373. - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  45374. + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
  45375. (lpfc_debugfs_max_slow_ring_trc - 1);
  45376. dtp = phba->slow_ring_trc + index;
  45377. dtp->fmt = fmt;
  45378. dtp->data1 = data1;
  45379. dtp->data2 = data2;
  45380. dtp->data3 = data3;
  45381. - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  45382. + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
  45383. dtp->jif = jiffies;
  45384. #endif
  45385. return;
  45386. @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
  45387. "slow_ring buffer\n");
  45388. goto debug_failed;
  45389. }
  45390. - atomic_set(&phba->slow_ring_trc_cnt, 0);
  45391. + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
  45392. memset(phba->slow_ring_trc, 0,
  45393. (sizeof(struct lpfc_debugfs_trc) *
  45394. lpfc_debugfs_max_slow_ring_trc));
  45395. @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
  45396. "buffer\n");
  45397. goto debug_failed;
  45398. }
  45399. - atomic_set(&vport->disc_trc_cnt, 0);
  45400. + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
  45401. snprintf(name, sizeof(name), "discovery_trace");
  45402. vport->debug_disc_trc =
  45403. diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
  45404. index 68c94cc..8c27be5 100644
  45405. --- a/drivers/scsi/lpfc/lpfc_init.c
  45406. +++ b/drivers/scsi/lpfc/lpfc_init.c
  45407. @@ -10949,8 +10949,10 @@ lpfc_init(void)
  45408. "misc_register returned with status %d", error);
  45409. if (lpfc_enable_npiv) {
  45410. - lpfc_transport_functions.vport_create = lpfc_vport_create;
  45411. - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  45412. + pax_open_kernel();
  45413. + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
  45414. + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  45415. + pax_close_kernel();
  45416. }
  45417. lpfc_transport_template =
  45418. fc_attach_transport(&lpfc_transport_functions);
  45419. diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
  45420. index b2ede05..aaf482ca 100644
  45421. --- a/drivers/scsi/lpfc/lpfc_scsi.c
  45422. +++ b/drivers/scsi/lpfc/lpfc_scsi.c
  45423. @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
  45424. uint32_t evt_posted;
  45425. spin_lock_irqsave(&phba->hbalock, flags);
  45426. - atomic_inc(&phba->num_rsrc_err);
  45427. + atomic_inc_unchecked(&phba->num_rsrc_err);
  45428. phba->last_rsrc_error_time = jiffies;
  45429. if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
  45430. @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
  45431. unsigned long flags;
  45432. struct lpfc_hba *phba = vport->phba;
  45433. uint32_t evt_posted;
  45434. - atomic_inc(&phba->num_cmd_success);
  45435. + atomic_inc_unchecked(&phba->num_cmd_success);
  45436. if (vport->cfg_lun_queue_depth <= queue_depth)
  45437. return;
  45438. @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
  45439. unsigned long num_rsrc_err, num_cmd_success;
  45440. int i;
  45441. - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
  45442. - num_cmd_success = atomic_read(&phba->num_cmd_success);
  45443. + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
  45444. + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
  45445. /*
  45446. * The error and success command counters are global per
  45447. @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
  45448. }
  45449. }
  45450. lpfc_destroy_vport_work_array(phba, vports);
  45451. - atomic_set(&phba->num_rsrc_err, 0);
  45452. - atomic_set(&phba->num_cmd_success, 0);
  45453. + atomic_set_unchecked(&phba->num_rsrc_err, 0);
  45454. + atomic_set_unchecked(&phba->num_cmd_success, 0);
  45455. }
  45456. /**
  45457. @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
  45458. }
  45459. }
  45460. lpfc_destroy_vport_work_array(phba, vports);
  45461. - atomic_set(&phba->num_rsrc_err, 0);
  45462. - atomic_set(&phba->num_cmd_success, 0);
  45463. + atomic_set_unchecked(&phba->num_rsrc_err, 0);
  45464. + atomic_set_unchecked(&phba->num_cmd_success, 0);
  45465. }
  45466. /**
  45467. diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
  45468. index 6fd7d40..b444223 100644
  45469. --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
  45470. +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
  45471. @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
  45472. {
  45473. struct scsi_device *sdev = to_scsi_device(dev);
  45474. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  45475. - static struct _raid_device *raid_device;
  45476. + struct _raid_device *raid_device;
  45477. unsigned long flags;
  45478. Mpi2RaidVolPage0_t vol_pg0;
  45479. Mpi2ConfigReply_t mpi_reply;
  45480. @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
  45481. {
  45482. struct scsi_device *sdev = to_scsi_device(dev);
  45483. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  45484. - static struct _raid_device *raid_device;
  45485. + struct _raid_device *raid_device;
  45486. unsigned long flags;
  45487. Mpi2RaidVolPage0_t vol_pg0;
  45488. Mpi2ConfigReply_t mpi_reply;
  45489. @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
  45490. struct fw_event_work *fw_event)
  45491. {
  45492. Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
  45493. - static struct _raid_device *raid_device;
  45494. + struct _raid_device *raid_device;
  45495. unsigned long flags;
  45496. u16 handle;
  45497. @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
  45498. u64 sas_address;
  45499. struct _sas_device *sas_device;
  45500. struct _sas_node *expander_device;
  45501. - static struct _raid_device *raid_device;
  45502. + struct _raid_device *raid_device;
  45503. u8 retry_count;
  45504. unsigned long flags;
  45505. diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
  45506. index be8ce54..94ed33a 100644
  45507. --- a/drivers/scsi/pmcraid.c
  45508. +++ b/drivers/scsi/pmcraid.c
  45509. @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
  45510. res->scsi_dev = scsi_dev;
  45511. scsi_dev->hostdata = res;
  45512. res->change_detected = 0;
  45513. - atomic_set(&res->read_failures, 0);
  45514. - atomic_set(&res->write_failures, 0);
  45515. + atomic_set_unchecked(&res->read_failures, 0);
  45516. + atomic_set_unchecked(&res->write_failures, 0);
  45517. rc = 0;
  45518. }
  45519. spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
  45520. @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
  45521. /* If this was a SCSI read/write command keep count of errors */
  45522. if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
  45523. - atomic_inc(&res->read_failures);
  45524. + atomic_inc_unchecked(&res->read_failures);
  45525. else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
  45526. - atomic_inc(&res->write_failures);
  45527. + atomic_inc_unchecked(&res->write_failures);
  45528. if (!RES_IS_GSCSI(res->cfg_entry) &&
  45529. masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
  45530. @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
  45531. * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
  45532. * hrrq_id assigned here in queuecommand
  45533. */
  45534. - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
  45535. + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
  45536. pinstance->num_hrrq;
  45537. cmd->cmd_done = pmcraid_io_done;
  45538. @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
  45539. * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
  45540. * hrrq_id assigned here in queuecommand
  45541. */
  45542. - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
  45543. + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
  45544. pinstance->num_hrrq;
  45545. if (request_size) {
  45546. @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
  45547. pinstance = container_of(workp, struct pmcraid_instance, worker_q);
  45548. /* add resources only after host is added into system */
  45549. - if (!atomic_read(&pinstance->expose_resources))
  45550. + if (!atomic_read_unchecked(&pinstance->expose_resources))
  45551. return;
  45552. fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
  45553. @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
  45554. init_waitqueue_head(&pinstance->reset_wait_q);
  45555. atomic_set(&pinstance->outstanding_cmds, 0);
  45556. - atomic_set(&pinstance->last_message_id, 0);
  45557. - atomic_set(&pinstance->expose_resources, 0);
  45558. + atomic_set_unchecked(&pinstance->last_message_id, 0);
  45559. + atomic_set_unchecked(&pinstance->expose_resources, 0);
  45560. INIT_LIST_HEAD(&pinstance->free_res_q);
  45561. INIT_LIST_HEAD(&pinstance->used_res_q);
  45562. @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
  45563. /* Schedule worker thread to handle CCN and take care of adding and
  45564. * removing devices to OS
  45565. */
  45566. - atomic_set(&pinstance->expose_resources, 1);
  45567. + atomic_set_unchecked(&pinstance->expose_resources, 1);
  45568. schedule_work(&pinstance->worker_q);
  45569. return rc;
  45570. diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
  45571. index e1d150f..6c6df44 100644
  45572. --- a/drivers/scsi/pmcraid.h
  45573. +++ b/drivers/scsi/pmcraid.h
  45574. @@ -748,7 +748,7 @@ struct pmcraid_instance {
  45575. struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
  45576. /* Message id as filled in last fired IOARCB, used to identify HRRQ */
  45577. - atomic_t last_message_id;
  45578. + atomic_unchecked_t last_message_id;
  45579. /* configuration table */
  45580. struct pmcraid_config_table *cfg_table;
  45581. @@ -777,7 +777,7 @@ struct pmcraid_instance {
  45582. atomic_t outstanding_cmds;
  45583. /* should add/delete resources to mid-layer now ?*/
  45584. - atomic_t expose_resources;
  45585. + atomic_unchecked_t expose_resources;
  45586. @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
  45587. struct pmcraid_config_table_entry_ext cfg_entry_ext;
  45588. };
  45589. struct scsi_device *scsi_dev; /* Link scsi_device structure */
  45590. - atomic_t read_failures; /* count of failed READ commands */
  45591. - atomic_t write_failures; /* count of failed WRITE commands */
  45592. + atomic_unchecked_t read_failures; /* count of failed READ commands */
  45593. + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
  45594. /* To indicate add/delete/modify during CCN */
  45595. u8 change_detected;
  45596. diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
  45597. index 4a0d7c9..3d658d7 100644
  45598. --- a/drivers/scsi/qla2xxx/qla_attr.c
  45599. +++ b/drivers/scsi/qla2xxx/qla_attr.c
  45600. @@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  45601. return 0;
  45602. }
  45603. -struct fc_function_template qla2xxx_transport_functions = {
  45604. +fc_function_template_no_const qla2xxx_transport_functions = {
  45605. .show_host_node_name = 1,
  45606. .show_host_port_name = 1,
  45607. @@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
  45608. .bsg_timeout = qla24xx_bsg_timeout,
  45609. };
  45610. -struct fc_function_template qla2xxx_transport_vport_functions = {
  45611. +fc_function_template_no_const qla2xxx_transport_vport_functions = {
  45612. .show_host_node_name = 1,
  45613. .show_host_port_name = 1,
  45614. diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
  45615. index 1f42662..bf9836c 100644
  45616. --- a/drivers/scsi/qla2xxx/qla_gbl.h
  45617. +++ b/drivers/scsi/qla2xxx/qla_gbl.h
  45618. @@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
  45619. struct device_attribute;
  45620. extern struct device_attribute *qla2x00_host_attrs[];
  45621. struct fc_function_template;
  45622. -extern struct fc_function_template qla2xxx_transport_functions;
  45623. -extern struct fc_function_template qla2xxx_transport_vport_functions;
  45624. +extern fc_function_template_no_const qla2xxx_transport_functions;
  45625. +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
  45626. extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
  45627. extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
  45628. extern void qla2x00_init_host_attr(scsi_qla_host_t *);
  45629. diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
  45630. index 83cb612..9b7b08c 100644
  45631. --- a/drivers/scsi/qla2xxx/qla_os.c
  45632. +++ b/drivers/scsi/qla2xxx/qla_os.c
  45633. @@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  45634. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  45635. /* Ok, a 64bit DMA mask is applicable. */
  45636. ha->flags.enable_64bit_addressing = 1;
  45637. - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  45638. - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  45639. + pax_open_kernel();
  45640. + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  45641. + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  45642. + pax_close_kernel();
  45643. return;
  45644. }
  45645. }
  45646. diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
  45647. index aa67bb9..06d0e2a 100644
  45648. --- a/drivers/scsi/qla4xxx/ql4_def.h
  45649. +++ b/drivers/scsi/qla4xxx/ql4_def.h
  45650. @@ -303,7 +303,7 @@ struct ddb_entry {
  45651. * (4000 only) */
  45652. atomic_t relogin_timer; /* Max Time to wait for
  45653. * relogin to complete */
  45654. - atomic_t relogin_retry_count; /* Num of times relogin has been
  45655. + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
  45656. * retried */
  45657. uint32_t default_time2wait; /* Default Min time between
  45658. * relogins (+aens) */
  45659. diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
  45660. index c21adc3..1b4155f 100644
  45661. --- a/drivers/scsi/qla4xxx/ql4_os.c
  45662. +++ b/drivers/scsi/qla4xxx/ql4_os.c
  45663. @@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  45664. */
  45665. if (!iscsi_is_session_online(cls_sess)) {
  45666. /* Reset retry relogin timer */
  45667. - atomic_inc(&ddb_entry->relogin_retry_count);
  45668. + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
  45669. DEBUG2(ql4_printk(KERN_INFO, ha,
  45670. "%s: index[%d] relogin timed out-retrying"
  45671. " relogin (%d), retry (%d)\n", __func__,
  45672. ddb_entry->fw_ddb_index,
  45673. - atomic_read(&ddb_entry->relogin_retry_count),
  45674. + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
  45675. ddb_entry->default_time2wait + 4));
  45676. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  45677. atomic_set(&ddb_entry->retry_relogin_timer,
  45678. @@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  45679. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  45680. atomic_set(&ddb_entry->relogin_timer, 0);
  45681. - atomic_set(&ddb_entry->relogin_retry_count, 0);
  45682. + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
  45683. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  45684. ddb_entry->default_relogin_timeout =
  45685. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  45686. diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
  45687. index d8afec8..3ec7152 100644
  45688. --- a/drivers/scsi/scsi.c
  45689. +++ b/drivers/scsi/scsi.c
  45690. @@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
  45691. struct Scsi_Host *host = cmd->device->host;
  45692. int rtn = 0;
  45693. - atomic_inc(&cmd->device->iorequest_cnt);
  45694. + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
  45695. /* check if the device is still usable */
  45696. if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
  45697. diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
  45698. index 62ec84b..93159d8 100644
  45699. --- a/drivers/scsi/scsi_lib.c
  45700. +++ b/drivers/scsi/scsi_lib.c
  45701. @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
  45702. shost = sdev->host;
  45703. scsi_init_cmd_errh(cmd);
  45704. cmd->result = DID_NO_CONNECT << 16;
  45705. - atomic_inc(&cmd->device->iorequest_cnt);
  45706. + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
  45707. /*
  45708. * SCSI request completion path will do scsi_device_unbusy(),
  45709. @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
  45710. INIT_LIST_HEAD(&cmd->eh_entry);
  45711. - atomic_inc(&cmd->device->iodone_cnt);
  45712. + atomic_inc_unchecked(&cmd->device->iodone_cnt);
  45713. if (cmd->result)
  45714. - atomic_inc(&cmd->device->ioerr_cnt);
  45715. + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
  45716. disposition = scsi_decide_disposition(cmd);
  45717. if (disposition != SUCCESS &&
  45718. diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
  45719. index 9117d0b..d289a7a 100644
  45720. --- a/drivers/scsi/scsi_sysfs.c
  45721. +++ b/drivers/scsi/scsi_sysfs.c
  45722. @@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
  45723. char *buf) \
  45724. { \
  45725. struct scsi_device *sdev = to_scsi_device(dev); \
  45726. - unsigned long long count = atomic_read(&sdev->field); \
  45727. + unsigned long long count = atomic_read_unchecked(&sdev->field); \
  45728. return snprintf(buf, 20, "0x%llx\n", count); \
  45729. } \
  45730. static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
  45731. diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
  45732. index 84a1fdf..693b0d6 100644
  45733. --- a/drivers/scsi/scsi_tgt_lib.c
  45734. +++ b/drivers/scsi/scsi_tgt_lib.c
  45735. @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
  45736. int err;
  45737. dprintk("%lx %u\n", uaddr, len);
  45738. - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
  45739. + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
  45740. if (err) {
  45741. /*
  45742. * TODO: need to fixup sg_tablesize, max_segment_size,
  45743. diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
  45744. index 4628fd5..a94a1c2 100644
  45745. --- a/drivers/scsi/scsi_transport_fc.c
  45746. +++ b/drivers/scsi/scsi_transport_fc.c
  45747. @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
  45748. * Netlink Infrastructure
  45749. */
  45750. -static atomic_t fc_event_seq;
  45751. +static atomic_unchecked_t fc_event_seq;
  45752. /**
  45753. * fc_get_event_number - Obtain the next sequential FC event number
  45754. @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
  45755. u32
  45756. fc_get_event_number(void)
  45757. {
  45758. - return atomic_add_return(1, &fc_event_seq);
  45759. + return atomic_add_return_unchecked(1, &fc_event_seq);
  45760. }
  45761. EXPORT_SYMBOL(fc_get_event_number);
  45762. @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
  45763. {
  45764. int error;
  45765. - atomic_set(&fc_event_seq, 0);
  45766. + atomic_set_unchecked(&fc_event_seq, 0);
  45767. error = transport_class_register(&fc_host_class);
  45768. if (error)
  45769. @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
  45770. char *cp;
  45771. *val = simple_strtoul(buf, &cp, 0);
  45772. - if ((*cp && (*cp != '\n')) || (*val < 0))
  45773. + if (*cp && (*cp != '\n'))
  45774. return -EINVAL;
  45775. /*
  45776. * Check for overflow; dev_loss_tmo is u32
  45777. diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
  45778. index fd8ffe6..fd0bebf 100644
  45779. --- a/drivers/scsi/scsi_transport_iscsi.c
  45780. +++ b/drivers/scsi/scsi_transport_iscsi.c
  45781. @@ -79,7 +79,7 @@ struct iscsi_internal {
  45782. struct transport_container session_cont;
  45783. };
  45784. -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
  45785. +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
  45786. static struct workqueue_struct *iscsi_eh_timer_workq;
  45787. static DEFINE_IDA(iscsi_sess_ida);
  45788. @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
  45789. int err;
  45790. ihost = shost->shost_data;
  45791. - session->sid = atomic_add_return(1, &iscsi_session_nr);
  45792. + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
  45793. if (target_id == ISCSI_MAX_TARGET) {
  45794. id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
  45795. @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
  45796. printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
  45797. ISCSI_TRANSPORT_VERSION);
  45798. - atomic_set(&iscsi_session_nr, 0);
  45799. + atomic_set_unchecked(&iscsi_session_nr, 0);
  45800. err = class_register(&iscsi_transport_class);
  45801. if (err)
  45802. diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
  45803. index d47ffc8..30f46a9 100644
  45804. --- a/drivers/scsi/scsi_transport_srp.c
  45805. +++ b/drivers/scsi/scsi_transport_srp.c
  45806. @@ -36,7 +36,7 @@
  45807. #include "scsi_transport_srp_internal.h"
  45808. struct srp_host_attrs {
  45809. - atomic_t next_port_id;
  45810. + atomic_unchecked_t next_port_id;
  45811. };
  45812. #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
  45813. @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
  45814. struct Scsi_Host *shost = dev_to_shost(dev);
  45815. struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
  45816. - atomic_set(&srp_host->next_port_id, 0);
  45817. + atomic_set_unchecked(&srp_host->next_port_id, 0);
  45818. return 0;
  45819. }
  45820. @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
  45821. rport_fast_io_fail_timedout);
  45822. INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
  45823. - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
  45824. + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
  45825. dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
  45826. transport_setup_device(&rport->dev);
  45827. diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
  45828. index 36d1a23..3f33303 100644
  45829. --- a/drivers/scsi/sd.c
  45830. +++ b/drivers/scsi/sd.c
  45831. @@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
  45832. sdkp->disk = gd;
  45833. sdkp->index = index;
  45834. atomic_set(&sdkp->openers, 0);
  45835. - atomic_set(&sdkp->device->ioerr_cnt, 0);
  45836. + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
  45837. if (!sdp->request_queue->rq_timeout) {
  45838. if (sdp->type != TYPE_MOD)
  45839. diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
  45840. index df5e961..df6b97f 100644
  45841. --- a/drivers/scsi/sg.c
  45842. +++ b/drivers/scsi/sg.c
  45843. @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
  45844. sdp->disk->disk_name,
  45845. MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
  45846. NULL,
  45847. - (char *)arg);
  45848. + (char __user *)arg);
  45849. case BLKTRACESTART:
  45850. return blk_trace_startstop(sdp->device->request_queue, 1);
  45851. case BLKTRACESTOP:
  45852. diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
  45853. index d0b28bb..a263613 100644
  45854. --- a/drivers/spi/spi.c
  45855. +++ b/drivers/spi/spi.c
  45856. @@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
  45857. EXPORT_SYMBOL_GPL(spi_bus_unlock);
  45858. /* portable code must never pass more than 32 bytes */
  45859. -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
  45860. +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
  45861. static u8 *buf;
  45862. diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
  45863. index 2c61783..4d49e4e 100644
  45864. --- a/drivers/staging/android/timed_output.c
  45865. +++ b/drivers/staging/android/timed_output.c
  45866. @@ -25,7 +25,7 @@
  45867. #include "timed_output.h"
  45868. static struct class *timed_output_class;
  45869. -static atomic_t device_count;
  45870. +static atomic_unchecked_t device_count;
  45871. static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
  45872. char *buf)
  45873. @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
  45874. timed_output_class = class_create(THIS_MODULE, "timed_output");
  45875. if (IS_ERR(timed_output_class))
  45876. return PTR_ERR(timed_output_class);
  45877. - atomic_set(&device_count, 0);
  45878. + atomic_set_unchecked(&device_count, 0);
  45879. timed_output_class->dev_groups = timed_output_groups;
  45880. }
  45881. @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
  45882. if (ret < 0)
  45883. return ret;
  45884. - tdev->index = atomic_inc_return(&device_count);
  45885. + tdev->index = atomic_inc_return_unchecked(&device_count);
  45886. tdev->dev = device_create(timed_output_class, NULL,
  45887. MKDEV(0, tdev->index), NULL, "%s", tdev->name);
  45888. if (IS_ERR(tdev->dev))
  45889. diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
  45890. index fe47cd3..19a1bd1 100644
  45891. --- a/drivers/staging/gdm724x/gdm_tty.c
  45892. +++ b/drivers/staging/gdm724x/gdm_tty.c
  45893. @@ -44,7 +44,7 @@
  45894. #define gdm_tty_send_control(n, r, v, d, l) (\
  45895. n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
  45896. -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
  45897. +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
  45898. static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
  45899. static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
  45900. diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
  45901. index 236ed66..dd9cd74 100644
  45902. --- a/drivers/staging/imx-drm/imx-drm-core.c
  45903. +++ b/drivers/staging/imx-drm/imx-drm-core.c
  45904. @@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
  45905. goto err_busy;
  45906. }
  45907. - if (imxdrm->drm->open_count) {
  45908. + if (local_read(&imxdrm->drm->open_count)) {
  45909. ret = -EBUSY;
  45910. goto err_busy;
  45911. }
  45912. @@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
  45913. mutex_lock(&imxdrm->mutex);
  45914. - if (imxdrm->drm->open_count) {
  45915. + if (local_read(&imxdrm->drm->open_count)) {
  45916. ret = -EBUSY;
  45917. goto err_busy;
  45918. }
  45919. @@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
  45920. mutex_lock(&imxdrm->mutex);
  45921. - if (imxdrm->drm->open_count) {
  45922. + if (local_read(&imxdrm->drm->open_count)) {
  45923. ret = -EBUSY;
  45924. goto err_busy;
  45925. }
  45926. diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
  45927. index 3f8020c..649fded 100644
  45928. --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
  45929. +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
  45930. @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
  45931. return 0;
  45932. }
  45933. -sfw_test_client_ops_t brw_test_client;
  45934. -void brw_init_test_client(void)
  45935. -{
  45936. - brw_test_client.tso_init = brw_client_init;
  45937. - brw_test_client.tso_fini = brw_client_fini;
  45938. - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
  45939. - brw_test_client.tso_done_rpc = brw_client_done_rpc;
  45940. +sfw_test_client_ops_t brw_test_client = {
  45941. + .tso_init = brw_client_init,
  45942. + .tso_fini = brw_client_fini,
  45943. + .tso_prep_rpc = brw_client_prep_rpc,
  45944. + .tso_done_rpc = brw_client_done_rpc,
  45945. };
  45946. srpc_service_t brw_test_service;
  45947. diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
  45948. index 050723a..fa6fdf1 100644
  45949. --- a/drivers/staging/lustre/lnet/selftest/framework.c
  45950. +++ b/drivers/staging/lustre/lnet/selftest/framework.c
  45951. @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
  45952. extern sfw_test_client_ops_t ping_test_client;
  45953. extern srpc_service_t ping_test_service;
  45954. -extern void ping_init_test_client(void);
  45955. extern void ping_init_test_service(void);
  45956. extern sfw_test_client_ops_t brw_test_client;
  45957. extern srpc_service_t brw_test_service;
  45958. -extern void brw_init_test_client(void);
  45959. extern void brw_init_test_service(void);
  45960. @@ -1684,12 +1682,10 @@ sfw_startup (void)
  45961. INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
  45962. INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
  45963. - brw_init_test_client();
  45964. brw_init_test_service();
  45965. rc = sfw_register_test(&brw_test_service, &brw_test_client);
  45966. LASSERT (rc == 0);
  45967. - ping_init_test_client();
  45968. ping_init_test_service();
  45969. rc = sfw_register_test(&ping_test_service, &ping_test_client);
  45970. LASSERT (rc == 0);
  45971. diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
  45972. index 750cac4..e4d751f 100644
  45973. --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
  45974. +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
  45975. @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
  45976. return 0;
  45977. }
  45978. -sfw_test_client_ops_t ping_test_client;
  45979. -void ping_init_test_client(void)
  45980. -{
  45981. - ping_test_client.tso_init = ping_client_init;
  45982. - ping_test_client.tso_fini = ping_client_fini;
  45983. - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
  45984. - ping_test_client.tso_done_rpc = ping_client_done_rpc;
  45985. -}
  45986. +sfw_test_client_ops_t ping_test_client = {
  45987. + .tso_init = ping_client_init,
  45988. + .tso_fini = ping_client_fini,
  45989. + .tso_prep_rpc = ping_client_prep_rpc,
  45990. + .tso_done_rpc = ping_client_done_rpc,
  45991. +};
  45992. srpc_service_t ping_test_service;
  45993. void ping_init_test_service(void)
  45994. diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
  45995. index ec4bb5e..740c6dd 100644
  45996. --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
  45997. +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
  45998. @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
  45999. ldlm_completion_callback lcs_completion;
  46000. ldlm_blocking_callback lcs_blocking;
  46001. ldlm_glimpse_callback lcs_glimpse;
  46002. -};
  46003. +} __no_const;
  46004. /* ldlm_lockd.c */
  46005. int ldlm_del_waiting_lock(struct ldlm_lock *lock);
  46006. diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
  46007. index c3470ce..2bef527 100644
  46008. --- a/drivers/staging/lustre/lustre/include/obd.h
  46009. +++ b/drivers/staging/lustre/lustre/include/obd.h
  46010. @@ -1426,7 +1426,7 @@ struct md_ops {
  46011. * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
  46012. * wrapper function in include/linux/obd_class.h.
  46013. */
  46014. -};
  46015. +} __no_const;
  46016. struct lsm_operations {
  46017. void (*lsm_free)(struct lov_stripe_md *);
  46018. diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
  46019. index c9aae13..60ea292 100644
  46020. --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
  46021. +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
  46022. @@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
  46023. int added = (mode == LCK_NL);
  46024. int overlaps = 0;
  46025. int splitted = 0;
  46026. - const struct ldlm_callback_suite null_cbs = { NULL };
  46027. + const struct ldlm_callback_suite null_cbs = { };
  46028. CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
  46029. LPU64" end "LPU64"\n", *flags,
  46030. diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
  46031. index e947b91..f408990 100644
  46032. --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
  46033. +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
  46034. @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
  46035. int LL_PROC_PROTO(proc_console_max_delay_cs)
  46036. {
  46037. int rc, max_delay_cs;
  46038. - ctl_table_t dummy = *table;
  46039. + ctl_table_no_const dummy = *table;
  46040. cfs_duration_t d;
  46041. dummy.data = &max_delay_cs;
  46042. @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
  46043. int LL_PROC_PROTO(proc_console_min_delay_cs)
  46044. {
  46045. int rc, min_delay_cs;
  46046. - ctl_table_t dummy = *table;
  46047. + ctl_table_no_const dummy = *table;
  46048. cfs_duration_t d;
  46049. dummy.data = &min_delay_cs;
  46050. @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
  46051. int LL_PROC_PROTO(proc_console_backoff)
  46052. {
  46053. int rc, backoff;
  46054. - ctl_table_t dummy = *table;
  46055. + ctl_table_no_const dummy = *table;
  46056. dummy.data = &backoff;
  46057. dummy.proc_handler = &proc_dointvec;
  46058. diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
  46059. index 24ae26d..9d09cab 100644
  46060. --- a/drivers/staging/lustre/lustre/libcfs/module.c
  46061. +++ b/drivers/staging/lustre/lustre/libcfs/module.c
  46062. @@ -313,11 +313,11 @@ out:
  46063. struct cfs_psdev_ops libcfs_psdev_ops = {
  46064. - libcfs_psdev_open,
  46065. - libcfs_psdev_release,
  46066. - NULL,
  46067. - NULL,
  46068. - libcfs_ioctl
  46069. + .p_open = libcfs_psdev_open,
  46070. + .p_close = libcfs_psdev_release,
  46071. + .p_read = NULL,
  46072. + .p_write = NULL,
  46073. + .p_ioctl = libcfs_ioctl
  46074. };
  46075. extern int insert_proc(void);
  46076. diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
  46077. index 52b7731..d604da0 100644
  46078. --- a/drivers/staging/lustre/lustre/llite/dir.c
  46079. +++ b/drivers/staging/lustre/lustre/llite/dir.c
  46080. @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
  46081. int mode;
  46082. int err;
  46083. - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
  46084. + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
  46085. op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
  46086. strlen(filename), mode, LUSTRE_OPC_MKDIR,
  46087. lump);
  46088. diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
  46089. index 480b7c4..6846324 100644
  46090. --- a/drivers/staging/media/solo6x10/solo6x10-core.c
  46091. +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
  46092. @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
  46093. static int solo_sysfs_init(struct solo_dev *solo_dev)
  46094. {
  46095. - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
  46096. + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
  46097. struct device *dev = &solo_dev->dev;
  46098. const char *driver;
  46099. int i;
  46100. diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
  46101. index 1db18c7..35e6afc 100644
  46102. --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
  46103. +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
  46104. @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
  46105. int solo_g723_init(struct solo_dev *solo_dev)
  46106. {
  46107. - static struct snd_device_ops ops = { NULL };
  46108. + static struct snd_device_ops ops = { };
  46109. struct snd_card *card;
  46110. struct snd_kcontrol_new kctl;
  46111. char name[32];
  46112. diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
  46113. index 7f2f247..d999137 100644
  46114. --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
  46115. +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
  46116. @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
  46117. /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
  46118. if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
  46119. - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
  46120. + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
  46121. if (p2m_id < 0)
  46122. p2m_id = -p2m_id;
  46123. }
  46124. diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
  46125. index 8964f8b..36eb087 100644
  46126. --- a/drivers/staging/media/solo6x10/solo6x10.h
  46127. +++ b/drivers/staging/media/solo6x10/solo6x10.h
  46128. @@ -237,7 +237,7 @@ struct solo_dev {
  46129. /* P2M DMA Engine */
  46130. struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
  46131. - atomic_t p2m_count;
  46132. + atomic_unchecked_t p2m_count;
  46133. int p2m_jiffies;
  46134. unsigned int p2m_timeouts;
  46135. diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
  46136. index a0f4868..139f1fb 100644
  46137. --- a/drivers/staging/octeon/ethernet-rx.c
  46138. +++ b/drivers/staging/octeon/ethernet-rx.c
  46139. @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
  46140. /* Increment RX stats for virtual ports */
  46141. if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
  46142. #ifdef CONFIG_64BIT
  46143. - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
  46144. - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
  46145. + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
  46146. + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
  46147. #else
  46148. - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
  46149. - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
  46150. + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
  46151. + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
  46152. #endif
  46153. }
  46154. netif_receive_skb(skb);
  46155. @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
  46156. dev->name);
  46157. */
  46158. #ifdef CONFIG_64BIT
  46159. - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
  46160. + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
  46161. #else
  46162. - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
  46163. + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
  46164. #endif
  46165. dev_kfree_skb_irq(skb);
  46166. }
  46167. diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
  46168. index 089dc4b..c9a687e 100644
  46169. --- a/drivers/staging/octeon/ethernet.c
  46170. +++ b/drivers/staging/octeon/ethernet.c
  46171. @@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
  46172. * since the RX tasklet also increments it.
  46173. */
  46174. #ifdef CONFIG_64BIT
  46175. - atomic64_add(rx_status.dropped_packets,
  46176. - (atomic64_t *)&priv->stats.rx_dropped);
  46177. + atomic64_add_unchecked(rx_status.dropped_packets,
  46178. + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
  46179. #else
  46180. - atomic_add(rx_status.dropped_packets,
  46181. - (atomic_t *)&priv->stats.rx_dropped);
  46182. + atomic_add_unchecked(rx_status.dropped_packets,
  46183. + (atomic_unchecked_t *)&priv->stats.rx_dropped);
  46184. #endif
  46185. }
  46186. diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
  46187. index c274b34..f84de76 100644
  46188. --- a/drivers/staging/rtl8188eu/include/hal_intf.h
  46189. +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
  46190. @@ -271,7 +271,7 @@ struct hal_ops {
  46191. s32 (*c2h_handler)(struct adapter *padapter,
  46192. struct c2h_evt_hdr *c2h_evt);
  46193. c2h_id_filter c2h_id_filter_ccx;
  46194. -};
  46195. +} __no_const;
  46196. enum rt_eeprom_type {
  46197. EEPROM_93C46,
  46198. diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
  46199. index 3d1dfcc..ff5620a 100644
  46200. --- a/drivers/staging/rtl8188eu/include/rtw_io.h
  46201. +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
  46202. @@ -126,7 +126,7 @@ struct _io_ops {
  46203. u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
  46204. void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
  46205. void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
  46206. -};
  46207. +} __no_const;
  46208. struct io_req {
  46209. struct list_head list;
  46210. diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
  46211. index dc23395..cf7e9b1 100644
  46212. --- a/drivers/staging/rtl8712/rtl871x_io.h
  46213. +++ b/drivers/staging/rtl8712/rtl871x_io.h
  46214. @@ -108,7 +108,7 @@ struct _io_ops {
  46215. u8 *pmem);
  46216. u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
  46217. u8 *pmem);
  46218. -};
  46219. +} __no_const;
  46220. struct io_req {
  46221. struct list_head list;
  46222. diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
  46223. index 1f5088b..0e59820 100644
  46224. --- a/drivers/staging/sbe-2t3e3/netdev.c
  46225. +++ b/drivers/staging/sbe-2t3e3/netdev.c
  46226. @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  46227. t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
  46228. if (rlen)
  46229. - if (copy_to_user(data, &resp, rlen))
  46230. + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
  46231. return -EFAULT;
  46232. return 0;
  46233. diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
  46234. index a863a98..d272795 100644
  46235. --- a/drivers/staging/usbip/vhci.h
  46236. +++ b/drivers/staging/usbip/vhci.h
  46237. @@ -83,7 +83,7 @@ struct vhci_hcd {
  46238. unsigned resuming:1;
  46239. unsigned long re_timeout;
  46240. - atomic_t seqnum;
  46241. + atomic_unchecked_t seqnum;
  46242. /*
  46243. * NOTE:
  46244. diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
  46245. index 72391ef..7c6717a 100644
  46246. --- a/drivers/staging/usbip/vhci_hcd.c
  46247. +++ b/drivers/staging/usbip/vhci_hcd.c
  46248. @@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
  46249. spin_lock(&vdev->priv_lock);
  46250. - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
  46251. + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
  46252. if (priv->seqnum == 0xffff)
  46253. dev_info(&urb->dev->dev, "seqnum max\n");
  46254. @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  46255. return -ENOMEM;
  46256. }
  46257. - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
  46258. + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
  46259. if (unlink->seqnum == 0xffff)
  46260. pr_info("seqnum max\n");
  46261. @@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
  46262. vdev->rhport = rhport;
  46263. }
  46264. - atomic_set(&vhci->seqnum, 0);
  46265. + atomic_set_unchecked(&vhci->seqnum, 0);
  46266. spin_lock_init(&vhci->lock);
  46267. hcd->power_budget = 0; /* no limit */
  46268. diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
  46269. index d07fcb5..358e1e1 100644
  46270. --- a/drivers/staging/usbip/vhci_rx.c
  46271. +++ b/drivers/staging/usbip/vhci_rx.c
  46272. @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
  46273. if (!urb) {
  46274. pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
  46275. pr_info("max seqnum %d\n",
  46276. - atomic_read(&the_controller->seqnum));
  46277. + atomic_read_unchecked(&the_controller->seqnum));
  46278. usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
  46279. return;
  46280. }
  46281. diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
  46282. index 6eecd53..29317c6 100644
  46283. --- a/drivers/staging/vt6655/hostap.c
  46284. +++ b/drivers/staging/vt6655/hostap.c
  46285. @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
  46286. *
  46287. */
  46288. +static net_device_ops_no_const apdev_netdev_ops;
  46289. +
  46290. static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
  46291. {
  46292. PSDevice apdev_priv;
  46293. struct net_device *dev = pDevice->dev;
  46294. int ret;
  46295. - const struct net_device_ops apdev_netdev_ops = {
  46296. - .ndo_start_xmit = pDevice->tx_80211,
  46297. - };
  46298. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
  46299. @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
  46300. *apdev_priv = *pDevice;
  46301. eth_hw_addr_inherit(pDevice->apdev, dev);
  46302. + /* only half broken now */
  46303. + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
  46304. pDevice->apdev->netdev_ops = &apdev_netdev_ops;
  46305. pDevice->apdev->type = ARPHRD_IEEE80211;
  46306. diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
  46307. index 67ba48b..24e602f 100644
  46308. --- a/drivers/staging/vt6656/hostap.c
  46309. +++ b/drivers/staging/vt6656/hostap.c
  46310. @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
  46311. *
  46312. */
  46313. +static net_device_ops_no_const apdev_netdev_ops;
  46314. +
  46315. static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
  46316. {
  46317. struct vnt_private *apdev_priv;
  46318. struct net_device *dev = pDevice->dev;
  46319. int ret;
  46320. - const struct net_device_ops apdev_netdev_ops = {
  46321. - .ndo_start_xmit = pDevice->tx_80211,
  46322. - };
  46323. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
  46324. @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
  46325. *apdev_priv = *pDevice;
  46326. memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
  46327. + /* only half broken now */
  46328. + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
  46329. pDevice->apdev->netdev_ops = &apdev_netdev_ops;
  46330. pDevice->apdev->type = ARPHRD_IEEE80211;
  46331. diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
  46332. index 24884ca..26c8220 100644
  46333. --- a/drivers/target/sbp/sbp_target.c
  46334. +++ b/drivers/target/sbp/sbp_target.c
  46335. @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
  46336. #define SESSION_MAINTENANCE_INTERVAL HZ
  46337. -static atomic_t login_id = ATOMIC_INIT(0);
  46338. +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
  46339. static void session_maintenance_work(struct work_struct *);
  46340. static int sbp_run_transaction(struct fw_card *, int, int, int, int,
  46341. @@ -444,7 +444,7 @@ static void sbp_management_request_login(
  46342. login->lun = se_lun;
  46343. login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
  46344. login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
  46345. - login->login_id = atomic_inc_return(&login_id);
  46346. + login->login_id = atomic_inc_return_unchecked(&login_id);
  46347. login->tgt_agt = sbp_target_agent_register(login);
  46348. if (IS_ERR(login->tgt_agt)) {
  46349. diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
  46350. index 65001e1..2ebfbb9 100644
  46351. --- a/drivers/target/target_core_device.c
  46352. +++ b/drivers/target/target_core_device.c
  46353. @@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
  46354. spin_lock_init(&dev->se_tmr_lock);
  46355. spin_lock_init(&dev->qf_cmd_lock);
  46356. sema_init(&dev->caw_sem, 1);
  46357. - atomic_set(&dev->dev_ordered_id, 0);
  46358. + atomic_set_unchecked(&dev->dev_ordered_id, 0);
  46359. INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
  46360. spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
  46361. INIT_LIST_HEAD(&dev->t10_pr.registration_list);
  46362. diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
  46363. index 2956250..b10f722 100644
  46364. --- a/drivers/target/target_core_transport.c
  46365. +++ b/drivers/target/target_core_transport.c
  46366. @@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
  46367. * Used to determine when ORDERED commands should go from
  46368. * Dormant to Active status.
  46369. */
  46370. - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
  46371. + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
  46372. smp_mb__after_atomic_inc();
  46373. pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
  46374. cmd->se_ordered_id, cmd->sam_task_attr,
  46375. diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
  46376. index 04b1be7..5eff86d 100644
  46377. --- a/drivers/thermal/of-thermal.c
  46378. +++ b/drivers/thermal/of-thermal.c
  46379. @@ -30,6 +30,7 @@
  46380. #include <linux/err.h>
  46381. #include <linux/export.h>
  46382. #include <linux/string.h>
  46383. +#include <linux/mm.h>
  46384. #include "thermal_core.h"
  46385. @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
  46386. tz->get_trend = get_trend;
  46387. tz->sensor_data = data;
  46388. - tzd->ops->get_temp = of_thermal_get_temp;
  46389. - tzd->ops->get_trend = of_thermal_get_trend;
  46390. + pax_open_kernel();
  46391. + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
  46392. + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
  46393. + pax_close_kernel();
  46394. mutex_unlock(&tzd->lock);
  46395. return tzd;
  46396. @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
  46397. return;
  46398. mutex_lock(&tzd->lock);
  46399. - tzd->ops->get_temp = NULL;
  46400. - tzd->ops->get_trend = NULL;
  46401. + pax_open_kernel();
  46402. + *(void **)&tzd->ops->get_temp = NULL;
  46403. + *(void **)&tzd->ops->get_trend = NULL;
  46404. + pax_close_kernel();
  46405. tz->get_temp = NULL;
  46406. tz->get_trend = NULL;
  46407. diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
  46408. index a57bb5a..1f727d33 100644
  46409. --- a/drivers/tty/cyclades.c
  46410. +++ b/drivers/tty/cyclades.c
  46411. @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
  46412. printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
  46413. info->port.count);
  46414. #endif
  46415. - info->port.count++;
  46416. + atomic_inc(&info->port.count);
  46417. #ifdef CY_DEBUG_COUNT
  46418. printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
  46419. - current->pid, info->port.count);
  46420. + current->pid, atomic_read(&info->port.count));
  46421. #endif
  46422. /*
  46423. @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
  46424. for (j = 0; j < cy_card[i].nports; j++) {
  46425. info = &cy_card[i].ports[j];
  46426. - if (info->port.count) {
  46427. + if (atomic_read(&info->port.count)) {
  46428. /* XXX is the ldisc num worth this? */
  46429. struct tty_struct *tty;
  46430. struct tty_ldisc *ld;
  46431. diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
  46432. index 0ff7fda..dbc7d52 100644
  46433. --- a/drivers/tty/hvc/hvc_console.c
  46434. +++ b/drivers/tty/hvc/hvc_console.c
  46435. @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
  46436. spin_lock_irqsave(&hp->port.lock, flags);
  46437. /* Check and then increment for fast path open. */
  46438. - if (hp->port.count++ > 0) {
  46439. + if (atomic_inc_return(&hp->port.count) > 1) {
  46440. spin_unlock_irqrestore(&hp->port.lock, flags);
  46441. hvc_kick();
  46442. return 0;
  46443. @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
  46444. spin_lock_irqsave(&hp->port.lock, flags);
  46445. - if (--hp->port.count == 0) {
  46446. + if (atomic_dec_return(&hp->port.count) == 0) {
  46447. spin_unlock_irqrestore(&hp->port.lock, flags);
  46448. /* We are done with the tty pointer now. */
  46449. tty_port_tty_set(&hp->port, NULL);
  46450. @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
  46451. */
  46452. tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
  46453. } else {
  46454. - if (hp->port.count < 0)
  46455. + if (atomic_read(&hp->port.count) < 0)
  46456. printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
  46457. - hp->vtermno, hp->port.count);
  46458. + hp->vtermno, atomic_read(&hp->port.count));
  46459. spin_unlock_irqrestore(&hp->port.lock, flags);
  46460. }
  46461. }
  46462. @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
  46463. * open->hangup case this can be called after the final close so prevent
  46464. * that from happening for now.
  46465. */
  46466. - if (hp->port.count <= 0) {
  46467. + if (atomic_read(&hp->port.count) <= 0) {
  46468. spin_unlock_irqrestore(&hp->port.lock, flags);
  46469. return;
  46470. }
  46471. - hp->port.count = 0;
  46472. + atomic_set(&hp->port.count, 0);
  46473. spin_unlock_irqrestore(&hp->port.lock, flags);
  46474. tty_port_tty_set(&hp->port, NULL);
  46475. @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
  46476. return -EPIPE;
  46477. /* FIXME what's this (unprotected) check for? */
  46478. - if (hp->port.count <= 0)
  46479. + if (atomic_read(&hp->port.count) <= 0)
  46480. return -EIO;
  46481. spin_lock_irqsave(&hp->lock, flags);
  46482. diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
  46483. index 81e939e..95ead10 100644
  46484. --- a/drivers/tty/hvc/hvcs.c
  46485. +++ b/drivers/tty/hvc/hvcs.c
  46486. @@ -83,6 +83,7 @@
  46487. #include <asm/hvcserver.h>
  46488. #include <asm/uaccess.h>
  46489. #include <asm/vio.h>
  46490. +#include <asm/local.h>
  46491. /*
  46492. * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
  46493. @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
  46494. spin_lock_irqsave(&hvcsd->lock, flags);
  46495. - if (hvcsd->port.count > 0) {
  46496. + if (atomic_read(&hvcsd->port.count) > 0) {
  46497. spin_unlock_irqrestore(&hvcsd->lock, flags);
  46498. printk(KERN_INFO "HVCS: vterm state unchanged. "
  46499. "The hvcs device node is still in use.\n");
  46500. @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
  46501. }
  46502. }
  46503. - hvcsd->port.count = 0;
  46504. + atomic_set(&hvcsd->port.count, 0);
  46505. hvcsd->port.tty = tty;
  46506. tty->driver_data = hvcsd;
  46507. @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
  46508. unsigned long flags;
  46509. spin_lock_irqsave(&hvcsd->lock, flags);
  46510. - hvcsd->port.count++;
  46511. + atomic_inc(&hvcsd->port.count);
  46512. hvcsd->todo_mask |= HVCS_SCHED_READ;
  46513. spin_unlock_irqrestore(&hvcsd->lock, flags);
  46514. @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
  46515. hvcsd = tty->driver_data;
  46516. spin_lock_irqsave(&hvcsd->lock, flags);
  46517. - if (--hvcsd->port.count == 0) {
  46518. + if (atomic_dec_and_test(&hvcsd->port.count)) {
  46519. vio_disable_interrupts(hvcsd->vdev);
  46520. @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
  46521. free_irq(irq, hvcsd);
  46522. return;
  46523. - } else if (hvcsd->port.count < 0) {
  46524. + } else if (atomic_read(&hvcsd->port.count) < 0) {
  46525. printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
  46526. " is missmanaged.\n",
  46527. - hvcsd->vdev->unit_address, hvcsd->port.count);
  46528. + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
  46529. }
  46530. spin_unlock_irqrestore(&hvcsd->lock, flags);
  46531. @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
  46532. spin_lock_irqsave(&hvcsd->lock, flags);
  46533. /* Preserve this so that we know how many kref refs to put */
  46534. - temp_open_count = hvcsd->port.count;
  46535. + temp_open_count = atomic_read(&hvcsd->port.count);
  46536. /*
  46537. * Don't kref put inside the spinlock because the destruction
  46538. @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
  46539. tty->driver_data = NULL;
  46540. hvcsd->port.tty = NULL;
  46541. - hvcsd->port.count = 0;
  46542. + atomic_set(&hvcsd->port.count, 0);
  46543. /* This will drop any buffered data on the floor which is OK in a hangup
  46544. * scenario. */
  46545. @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
  46546. * the middle of a write operation? This is a crummy place to do this
  46547. * but we want to keep it all in the spinlock.
  46548. */
  46549. - if (hvcsd->port.count <= 0) {
  46550. + if (atomic_read(&hvcsd->port.count) <= 0) {
  46551. spin_unlock_irqrestore(&hvcsd->lock, flags);
  46552. return -ENODEV;
  46553. }
  46554. @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
  46555. {
  46556. struct hvcs_struct *hvcsd = tty->driver_data;
  46557. - if (!hvcsd || hvcsd->port.count <= 0)
  46558. + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
  46559. return 0;
  46560. return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
  46561. diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
  46562. index 4190199..06d5bfa 100644
  46563. --- a/drivers/tty/hvc/hvsi.c
  46564. +++ b/drivers/tty/hvc/hvsi.c
  46565. @@ -85,7 +85,7 @@ struct hvsi_struct {
  46566. int n_outbuf;
  46567. uint32_t vtermno;
  46568. uint32_t virq;
  46569. - atomic_t seqno; /* HVSI packet sequence number */
  46570. + atomic_unchecked_t seqno; /* HVSI packet sequence number */
  46571. uint16_t mctrl;
  46572. uint8_t state; /* HVSI protocol state */
  46573. uint8_t flags;
  46574. @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
  46575. packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
  46576. packet.hdr.len = sizeof(struct hvsi_query_response);
  46577. - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
  46578. + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
  46579. packet.verb = VSV_SEND_VERSION_NUMBER;
  46580. packet.u.version = HVSI_VERSION;
  46581. packet.query_seqno = query_seqno+1;
  46582. @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
  46583. packet.hdr.type = VS_QUERY_PACKET_HEADER;
  46584. packet.hdr.len = sizeof(struct hvsi_query);
  46585. - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
  46586. + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
  46587. packet.verb = verb;
  46588. pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
  46589. @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
  46590. int wrote;
  46591. packet.hdr.type = VS_CONTROL_PACKET_HEADER,
  46592. - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
  46593. + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
  46594. packet.hdr.len = sizeof(struct hvsi_control);
  46595. packet.verb = VSV_SET_MODEM_CTL;
  46596. packet.mask = HVSI_TSDTR;
  46597. @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
  46598. BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
  46599. packet.hdr.type = VS_DATA_PACKET_HEADER;
  46600. - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
  46601. + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
  46602. packet.hdr.len = count + sizeof(struct hvsi_header);
  46603. memcpy(&packet.data, buf, count);
  46604. @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
  46605. struct hvsi_control packet __ALIGNED__;
  46606. packet.hdr.type = VS_CONTROL_PACKET_HEADER;
  46607. - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
  46608. + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
  46609. packet.hdr.len = 6;
  46610. packet.verb = VSV_CLOSE_PROTOCOL;
  46611. @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
  46612. tty_port_tty_set(&hp->port, tty);
  46613. spin_lock_irqsave(&hp->lock, flags);
  46614. - hp->port.count++;
  46615. + atomic_inc(&hp->port.count);
  46616. atomic_set(&hp->seqno, 0);
  46617. h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
  46618. spin_unlock_irqrestore(&hp->lock, flags);
  46619. @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
  46620. spin_lock_irqsave(&hp->lock, flags);
  46621. - if (--hp->port.count == 0) {
  46622. + if (atomic_dec_return(&hp->port.count) == 0) {
  46623. tty_port_tty_set(&hp->port, NULL);
  46624. hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
  46625. @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
  46626. spin_lock_irqsave(&hp->lock, flags);
  46627. }
  46628. - } else if (hp->port.count < 0)
  46629. + } else if (atomic_read(&hp->port.count) < 0)
  46630. printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
  46631. - hp - hvsi_ports, hp->port.count);
  46632. + hp - hvsi_ports, atomic_read(&hp->port.count));
  46633. spin_unlock_irqrestore(&hp->lock, flags);
  46634. }
  46635. @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
  46636. tty_port_tty_set(&hp->port, NULL);
  46637. spin_lock_irqsave(&hp->lock, flags);
  46638. - hp->port.count = 0;
  46639. + atomic_set(&hp->port.count, 0);
  46640. hp->n_outbuf = 0;
  46641. spin_unlock_irqrestore(&hp->lock, flags);
  46642. }
  46643. diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
  46644. index 7ae6c29..05c6dba 100644
  46645. --- a/drivers/tty/hvc/hvsi_lib.c
  46646. +++ b/drivers/tty/hvc/hvsi_lib.c
  46647. @@ -8,7 +8,7 @@
  46648. static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
  46649. {
  46650. - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
  46651. + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
  46652. /* Assumes that always succeeds, works in practice */
  46653. return pv->put_chars(pv->termno, (char *)packet, packet->len);
  46654. @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
  46655. /* Reset state */
  46656. pv->established = 0;
  46657. - atomic_set(&pv->seqno, 0);
  46658. + atomic_set_unchecked(&pv->seqno, 0);
  46659. pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
  46660. diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
  46661. index 17ee3bf..8d2520d 100644
  46662. --- a/drivers/tty/ipwireless/tty.c
  46663. +++ b/drivers/tty/ipwireless/tty.c
  46664. @@ -28,6 +28,7 @@
  46665. #include <linux/tty_driver.h>
  46666. #include <linux/tty_flip.h>
  46667. #include <linux/uaccess.h>
  46668. +#include <asm/local.h>
  46669. #include "tty.h"
  46670. #include "network.h"
  46671. @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
  46672. mutex_unlock(&tty->ipw_tty_mutex);
  46673. return -ENODEV;
  46674. }
  46675. - if (tty->port.count == 0)
  46676. + if (atomic_read(&tty->port.count) == 0)
  46677. tty->tx_bytes_queued = 0;
  46678. - tty->port.count++;
  46679. + atomic_inc(&tty->port.count);
  46680. tty->port.tty = linux_tty;
  46681. linux_tty->driver_data = tty;
  46682. @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
  46683. static void do_ipw_close(struct ipw_tty *tty)
  46684. {
  46685. - tty->port.count--;
  46686. -
  46687. - if (tty->port.count == 0) {
  46688. + if (atomic_dec_return(&tty->port.count) == 0) {
  46689. struct tty_struct *linux_tty = tty->port.tty;
  46690. if (linux_tty != NULL) {
  46691. @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
  46692. return;
  46693. mutex_lock(&tty->ipw_tty_mutex);
  46694. - if (tty->port.count == 0) {
  46695. + if (atomic_read(&tty->port.count) == 0) {
  46696. mutex_unlock(&tty->ipw_tty_mutex);
  46697. return;
  46698. }
  46699. @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
  46700. mutex_lock(&tty->ipw_tty_mutex);
  46701. - if (!tty->port.count) {
  46702. + if (!atomic_read(&tty->port.count)) {
  46703. mutex_unlock(&tty->ipw_tty_mutex);
  46704. return;
  46705. }
  46706. @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
  46707. return -ENODEV;
  46708. mutex_lock(&tty->ipw_tty_mutex);
  46709. - if (!tty->port.count) {
  46710. + if (!atomic_read(&tty->port.count)) {
  46711. mutex_unlock(&tty->ipw_tty_mutex);
  46712. return -EINVAL;
  46713. }
  46714. @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
  46715. if (!tty)
  46716. return -ENODEV;
  46717. - if (!tty->port.count)
  46718. + if (!atomic_read(&tty->port.count))
  46719. return -EINVAL;
  46720. room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
  46721. @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
  46722. if (!tty)
  46723. return 0;
  46724. - if (!tty->port.count)
  46725. + if (!atomic_read(&tty->port.count))
  46726. return 0;
  46727. return tty->tx_bytes_queued;
  46728. @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
  46729. if (!tty)
  46730. return -ENODEV;
  46731. - if (!tty->port.count)
  46732. + if (!atomic_read(&tty->port.count))
  46733. return -EINVAL;
  46734. return get_control_lines(tty);
  46735. @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
  46736. if (!tty)
  46737. return -ENODEV;
  46738. - if (!tty->port.count)
  46739. + if (!atomic_read(&tty->port.count))
  46740. return -EINVAL;
  46741. return set_control_lines(tty, set, clear);
  46742. @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
  46743. if (!tty)
  46744. return -ENODEV;
  46745. - if (!tty->port.count)
  46746. + if (!atomic_read(&tty->port.count))
  46747. return -EINVAL;
  46748. /* FIXME: Exactly how is the tty object locked here .. */
  46749. @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
  46750. * are gone */
  46751. mutex_lock(&ttyj->ipw_tty_mutex);
  46752. }
  46753. - while (ttyj->port.count)
  46754. + while (atomic_read(&ttyj->port.count))
  46755. do_ipw_close(ttyj);
  46756. ipwireless_disassociate_network_ttys(network,
  46757. ttyj->channel_idx);
  46758. diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
  46759. index 1deaca4..c8582d4 100644
  46760. --- a/drivers/tty/moxa.c
  46761. +++ b/drivers/tty/moxa.c
  46762. @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
  46763. }
  46764. ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
  46765. - ch->port.count++;
  46766. + atomic_inc(&ch->port.count);
  46767. tty->driver_data = ch;
  46768. tty_port_tty_set(&ch->port, tty);
  46769. mutex_lock(&ch->port.mutex);
  46770. diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
  46771. index 2ebe47b..3205833 100644
  46772. --- a/drivers/tty/n_gsm.c
  46773. +++ b/drivers/tty/n_gsm.c
  46774. @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
  46775. spin_lock_init(&dlci->lock);
  46776. mutex_init(&dlci->mutex);
  46777. dlci->fifo = &dlci->_fifo;
  46778. - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
  46779. + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
  46780. kfree(dlci);
  46781. return NULL;
  46782. }
  46783. @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
  46784. struct gsm_dlci *dlci = tty->driver_data;
  46785. struct tty_port *port = &dlci->port;
  46786. - port->count++;
  46787. + atomic_inc(&port->count);
  46788. tty_port_tty_set(port, tty);
  46789. dlci->modem_rx = 0;
  46790. diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
  46791. index e36d1f5..9938e3e 100644
  46792. --- a/drivers/tty/n_tty.c
  46793. +++ b/drivers/tty/n_tty.c
  46794. @@ -115,7 +115,7 @@ struct n_tty_data {
  46795. int minimum_to_wake;
  46796. /* consumer-published */
  46797. - size_t read_tail;
  46798. + size_t read_tail __intentional_overflow(-1);
  46799. size_t line_start;
  46800. /* protected by output lock */
  46801. @@ -2519,6 +2519,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
  46802. {
  46803. *ops = tty_ldisc_N_TTY;
  46804. ops->owner = NULL;
  46805. - ops->refcount = ops->flags = 0;
  46806. + atomic_set(&ops->refcount, 0);
  46807. + ops->flags = 0;
  46808. }
  46809. EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
  46810. diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
  46811. index 25c9bc7..24077b7 100644
  46812. --- a/drivers/tty/pty.c
  46813. +++ b/drivers/tty/pty.c
  46814. @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
  46815. panic("Couldn't register Unix98 pts driver");
  46816. /* Now create the /dev/ptmx special device */
  46817. + pax_open_kernel();
  46818. tty_default_fops(&ptmx_fops);
  46819. - ptmx_fops.open = ptmx_open;
  46820. + *(void **)&ptmx_fops.open = ptmx_open;
  46821. + pax_close_kernel();
  46822. cdev_init(&ptmx_cdev, &ptmx_fops);
  46823. if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
  46824. diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
  46825. index 383c4c7..d408e21 100644
  46826. --- a/drivers/tty/rocket.c
  46827. +++ b/drivers/tty/rocket.c
  46828. @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
  46829. tty->driver_data = info;
  46830. tty_port_tty_set(port, tty);
  46831. - if (port->count++ == 0) {
  46832. + if (atomic_inc_return(&port->count) == 1) {
  46833. atomic_inc(&rp_num_ports_open);
  46834. #ifdef ROCKET_DEBUG_OPEN
  46835. @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
  46836. #endif
  46837. }
  46838. #ifdef ROCKET_DEBUG_OPEN
  46839. - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
  46840. + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
  46841. #endif
  46842. /*
  46843. @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
  46844. spin_unlock_irqrestore(&info->port.lock, flags);
  46845. return;
  46846. }
  46847. - if (info->port.count)
  46848. + if (atomic_read(&info->port.count))
  46849. atomic_dec(&rp_num_ports_open);
  46850. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  46851. spin_unlock_irqrestore(&info->port.lock, flags);
  46852. diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
  46853. index 1274499..f541382 100644
  46854. --- a/drivers/tty/serial/ioc4_serial.c
  46855. +++ b/drivers/tty/serial/ioc4_serial.c
  46856. @@ -437,7 +437,7 @@ struct ioc4_soft {
  46857. } is_intr_info[MAX_IOC4_INTR_ENTS];
  46858. /* Number of entries active in the above array */
  46859. - atomic_t is_num_intrs;
  46860. + atomic_unchecked_t is_num_intrs;
  46861. } is_intr_type[IOC4_NUM_INTR_TYPES];
  46862. /* is_ir_lock must be held while
  46863. @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
  46864. BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
  46865. || (type == IOC4_OTHER_INTR_TYPE)));
  46866. - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
  46867. + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
  46868. BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
  46869. /* Save off the lower level interrupt handler */
  46870. @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
  46871. soft = arg;
  46872. for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
  46873. - num_intrs = (int)atomic_read(
  46874. + num_intrs = (int)atomic_read_unchecked(
  46875. &soft->is_intr_type[intr_type].is_num_intrs);
  46876. this_mir = this_ir = pending_intrs(soft, intr_type);
  46877. diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
  46878. index a260cde..6b2b5ce 100644
  46879. --- a/drivers/tty/serial/kgdboc.c
  46880. +++ b/drivers/tty/serial/kgdboc.c
  46881. @@ -24,8 +24,9 @@
  46882. #define MAX_CONFIG_LEN 40
  46883. static struct kgdb_io kgdboc_io_ops;
  46884. +static struct kgdb_io kgdboc_io_ops_console;
  46885. -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
  46886. +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
  46887. static int configured = -1;
  46888. static char config[MAX_CONFIG_LEN];
  46889. @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
  46890. kgdboc_unregister_kbd();
  46891. if (configured == 1)
  46892. kgdb_unregister_io_module(&kgdboc_io_ops);
  46893. + else if (configured == 2)
  46894. + kgdb_unregister_io_module(&kgdboc_io_ops_console);
  46895. }
  46896. static int configure_kgdboc(void)
  46897. @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
  46898. int err;
  46899. char *cptr = config;
  46900. struct console *cons;
  46901. + int is_console = 0;
  46902. err = kgdboc_option_setup(config);
  46903. if (err || !strlen(config) || isspace(config[0]))
  46904. goto noconfig;
  46905. err = -ENODEV;
  46906. - kgdboc_io_ops.is_console = 0;
  46907. kgdb_tty_driver = NULL;
  46908. kgdboc_use_kms = 0;
  46909. @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
  46910. int idx;
  46911. if (cons->device && cons->device(cons, &idx) == p &&
  46912. idx == tty_line) {
  46913. - kgdboc_io_ops.is_console = 1;
  46914. + is_console = 1;
  46915. break;
  46916. }
  46917. cons = cons->next;
  46918. @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
  46919. kgdb_tty_line = tty_line;
  46920. do_register:
  46921. - err = kgdb_register_io_module(&kgdboc_io_ops);
  46922. + if (is_console) {
  46923. + err = kgdb_register_io_module(&kgdboc_io_ops_console);
  46924. + configured = 2;
  46925. + } else {
  46926. + err = kgdb_register_io_module(&kgdboc_io_ops);
  46927. + configured = 1;
  46928. + }
  46929. if (err)
  46930. goto noconfig;
  46931. @@ -205,8 +214,6 @@ do_register:
  46932. if (err)
  46933. goto nmi_con_failed;
  46934. - configured = 1;
  46935. -
  46936. return 0;
  46937. nmi_con_failed:
  46938. @@ -223,7 +230,7 @@ noconfig:
  46939. static int __init init_kgdboc(void)
  46940. {
  46941. /* Already configured? */
  46942. - if (configured == 1)
  46943. + if (configured >= 1)
  46944. return 0;
  46945. return configure_kgdboc();
  46946. @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
  46947. if (config[len - 1] == '\n')
  46948. config[len - 1] = '\0';
  46949. - if (configured == 1)
  46950. + if (configured >= 1)
  46951. cleanup_kgdboc();
  46952. /* Go and configure with the new params. */
  46953. @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
  46954. .post_exception = kgdboc_post_exp_handler,
  46955. };
  46956. +static struct kgdb_io kgdboc_io_ops_console = {
  46957. + .name = "kgdboc",
  46958. + .read_char = kgdboc_get_char,
  46959. + .write_char = kgdboc_put_char,
  46960. + .pre_exception = kgdboc_pre_exp_handler,
  46961. + .post_exception = kgdboc_post_exp_handler,
  46962. + .is_console = 1
  46963. +};
  46964. +
  46965. #ifdef CONFIG_KGDB_SERIAL_CONSOLE
  46966. /* This is only available if kgdboc is a built in for early debugging */
  46967. static int __init kgdboc_early_init(char *opt)
  46968. diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
  46969. index b5d779c..3622cfe 100644
  46970. --- a/drivers/tty/serial/msm_serial.c
  46971. +++ b/drivers/tty/serial/msm_serial.c
  46972. @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
  46973. .cons = MSM_CONSOLE,
  46974. };
  46975. -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
  46976. +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
  46977. static const struct of_device_id msm_uartdm_table[] = {
  46978. { .compatible = "qcom,msm-uartdm" },
  46979. @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
  46980. int irq;
  46981. if (pdev->id == -1)
  46982. - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
  46983. + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
  46984. if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
  46985. return -ENXIO;
  46986. diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
  46987. index 9cd706d..6ff2de7 100644
  46988. --- a/drivers/tty/serial/samsung.c
  46989. +++ b/drivers/tty/serial/samsung.c
  46990. @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
  46991. }
  46992. }
  46993. +static int s3c64xx_serial_startup(struct uart_port *port);
  46994. static int s3c24xx_serial_startup(struct uart_port *port)
  46995. {
  46996. struct s3c24xx_uart_port *ourport = to_ourport(port);
  46997. int ret;
  46998. + /* Startup sequence is different for s3c64xx and higher SoC's */
  46999. + if (s3c24xx_serial_has_interrupt_mask(port))
  47000. + return s3c64xx_serial_startup(port);
  47001. +
  47002. dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
  47003. port->mapbase, port->membase);
  47004. @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
  47005. /* setup info for port */
  47006. port->dev = &platdev->dev;
  47007. - /* Startup sequence is different for s3c64xx and higher SoC's */
  47008. - if (s3c24xx_serial_has_interrupt_mask(port))
  47009. - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
  47010. -
  47011. port->uartclk = 1;
  47012. if (cfg->uart_flags & UPF_CONS_FLOW) {
  47013. diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
  47014. index ece2049..fba2524 100644
  47015. --- a/drivers/tty/serial/serial_core.c
  47016. +++ b/drivers/tty/serial/serial_core.c
  47017. @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
  47018. uart_flush_buffer(tty);
  47019. uart_shutdown(tty, state);
  47020. spin_lock_irqsave(&port->lock, flags);
  47021. - port->count = 0;
  47022. + atomic_set(&port->count, 0);
  47023. clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
  47024. spin_unlock_irqrestore(&port->lock, flags);
  47025. tty_port_tty_set(port, NULL);
  47026. @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
  47027. goto end;
  47028. }
  47029. - port->count++;
  47030. + atomic_inc(&port->count);
  47031. if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
  47032. retval = -ENXIO;
  47033. goto err_dec_count;
  47034. @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
  47035. /*
  47036. * Make sure the device is in D0 state.
  47037. */
  47038. - if (port->count == 1)
  47039. + if (atomic_read(&port->count) == 1)
  47040. uart_change_pm(state, UART_PM_STATE_ON);
  47041. /*
  47042. @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
  47043. end:
  47044. return retval;
  47045. err_dec_count:
  47046. - port->count--;
  47047. + atomic_inc(&port->count);
  47048. mutex_unlock(&port->mutex);
  47049. goto end;
  47050. }
  47051. diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
  47052. index 5ae14b4..2c1288f 100644
  47053. --- a/drivers/tty/synclink.c
  47054. +++ b/drivers/tty/synclink.c
  47055. @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
  47056. if (debug_level >= DEBUG_LEVEL_INFO)
  47057. printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
  47058. - __FILE__,__LINE__, info->device_name, info->port.count);
  47059. + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
  47060. if (tty_port_close_start(&info->port, tty, filp) == 0)
  47061. goto cleanup;
  47062. @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
  47063. cleanup:
  47064. if (debug_level >= DEBUG_LEVEL_INFO)
  47065. printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
  47066. - tty->driver->name, info->port.count);
  47067. + tty->driver->name, atomic_read(&info->port.count));
  47068. } /* end of mgsl_close() */
  47069. @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
  47070. mgsl_flush_buffer(tty);
  47071. shutdown(info);
  47072. -
  47073. - info->port.count = 0;
  47074. +
  47075. + atomic_set(&info->port.count, 0);
  47076. info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
  47077. info->port.tty = NULL;
  47078. @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
  47079. if (debug_level >= DEBUG_LEVEL_INFO)
  47080. printk("%s(%d):block_til_ready before block on %s count=%d\n",
  47081. - __FILE__,__LINE__, tty->driver->name, port->count );
  47082. + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
  47083. spin_lock_irqsave(&info->irq_spinlock, flags);
  47084. if (!tty_hung_up_p(filp)) {
  47085. extra_count = true;
  47086. - port->count--;
  47087. + atomic_dec(&port->count);
  47088. }
  47089. spin_unlock_irqrestore(&info->irq_spinlock, flags);
  47090. port->blocked_open++;
  47091. @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
  47092. if (debug_level >= DEBUG_LEVEL_INFO)
  47093. printk("%s(%d):block_til_ready blocking on %s count=%d\n",
  47094. - __FILE__,__LINE__, tty->driver->name, port->count );
  47095. + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
  47096. tty_unlock(tty);
  47097. schedule();
  47098. @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
  47099. /* FIXME: Racy on hangup during close wait */
  47100. if (extra_count)
  47101. - port->count++;
  47102. + atomic_inc(&port->count);
  47103. port->blocked_open--;
  47104. if (debug_level >= DEBUG_LEVEL_INFO)
  47105. printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
  47106. - __FILE__,__LINE__, tty->driver->name, port->count );
  47107. + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
  47108. if (!retval)
  47109. port->flags |= ASYNC_NORMAL_ACTIVE;
  47110. @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
  47111. if (debug_level >= DEBUG_LEVEL_INFO)
  47112. printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
  47113. - __FILE__,__LINE__,tty->driver->name, info->port.count);
  47114. + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
  47115. /* If port is closing, signal caller to try again */
  47116. if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
  47117. @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
  47118. spin_unlock_irqrestore(&info->netlock, flags);
  47119. goto cleanup;
  47120. }
  47121. - info->port.count++;
  47122. + atomic_inc(&info->port.count);
  47123. spin_unlock_irqrestore(&info->netlock, flags);
  47124. - if (info->port.count == 1) {
  47125. + if (atomic_read(&info->port.count) == 1) {
  47126. /* 1st open on this device, init hardware */
  47127. retval = startup(info);
  47128. if (retval < 0)
  47129. @@ -3446,8 +3446,8 @@ cleanup:
  47130. if (retval) {
  47131. if (tty->count == 1)
  47132. info->port.tty = NULL; /* tty layer will release tty struct */
  47133. - if(info->port.count)
  47134. - info->port.count--;
  47135. + if (atomic_read(&info->port.count))
  47136. + atomic_dec(&info->port.count);
  47137. }
  47138. return retval;
  47139. @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  47140. unsigned short new_crctype;
  47141. /* return error if TTY interface open */
  47142. - if (info->port.count)
  47143. + if (atomic_read(&info->port.count))
  47144. return -EBUSY;
  47145. switch (encoding)
  47146. @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
  47147. /* arbitrate between network and tty opens */
  47148. spin_lock_irqsave(&info->netlock, flags);
  47149. - if (info->port.count != 0 || info->netcount != 0) {
  47150. + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
  47151. printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
  47152. spin_unlock_irqrestore(&info->netlock, flags);
  47153. return -EBUSY;
  47154. @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  47155. printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
  47156. /* return error if TTY interface open */
  47157. - if (info->port.count)
  47158. + if (atomic_read(&info->port.count))
  47159. return -EBUSY;
  47160. if (cmd != SIOCWANDEV)
  47161. diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
  47162. index c359a91..959fc26 100644
  47163. --- a/drivers/tty/synclink_gt.c
  47164. +++ b/drivers/tty/synclink_gt.c
  47165. @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
  47166. tty->driver_data = info;
  47167. info->port.tty = tty;
  47168. - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
  47169. + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
  47170. /* If port is closing, signal caller to try again */
  47171. if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
  47172. @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
  47173. mutex_unlock(&info->port.mutex);
  47174. goto cleanup;
  47175. }
  47176. - info->port.count++;
  47177. + atomic_inc(&info->port.count);
  47178. spin_unlock_irqrestore(&info->netlock, flags);
  47179. - if (info->port.count == 1) {
  47180. + if (atomic_read(&info->port.count) == 1) {
  47181. /* 1st open on this device, init hardware */
  47182. retval = startup(info);
  47183. if (retval < 0) {
  47184. @@ -715,8 +715,8 @@ cleanup:
  47185. if (retval) {
  47186. if (tty->count == 1)
  47187. info->port.tty = NULL; /* tty layer will release tty struct */
  47188. - if(info->port.count)
  47189. - info->port.count--;
  47190. + if(atomic_read(&info->port.count))
  47191. + atomic_dec(&info->port.count);
  47192. }
  47193. DBGINFO(("%s open rc=%d\n", info->device_name, retval));
  47194. @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
  47195. if (sanity_check(info, tty->name, "close"))
  47196. return;
  47197. - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
  47198. + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
  47199. if (tty_port_close_start(&info->port, tty, filp) == 0)
  47200. goto cleanup;
  47201. @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
  47202. tty_port_close_end(&info->port, tty);
  47203. info->port.tty = NULL;
  47204. cleanup:
  47205. - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
  47206. + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
  47207. }
  47208. static void hangup(struct tty_struct *tty)
  47209. @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
  47210. shutdown(info);
  47211. spin_lock_irqsave(&info->port.lock, flags);
  47212. - info->port.count = 0;
  47213. + atomic_set(&info->port.count, 0);
  47214. info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
  47215. info->port.tty = NULL;
  47216. spin_unlock_irqrestore(&info->port.lock, flags);
  47217. @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  47218. unsigned short new_crctype;
  47219. /* return error if TTY interface open */
  47220. - if (info->port.count)
  47221. + if (atomic_read(&info->port.count))
  47222. return -EBUSY;
  47223. DBGINFO(("%s hdlcdev_attach\n", info->device_name));
  47224. @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
  47225. /* arbitrate between network and tty opens */
  47226. spin_lock_irqsave(&info->netlock, flags);
  47227. - if (info->port.count != 0 || info->netcount != 0) {
  47228. + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
  47229. DBGINFO(("%s hdlc_open busy\n", dev->name));
  47230. spin_unlock_irqrestore(&info->netlock, flags);
  47231. return -EBUSY;
  47232. @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  47233. DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
  47234. /* return error if TTY interface open */
  47235. - if (info->port.count)
  47236. + if (atomic_read(&info->port.count))
  47237. return -EBUSY;
  47238. if (cmd != SIOCWANDEV)
  47239. @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
  47240. if (port == NULL)
  47241. continue;
  47242. spin_lock(&port->lock);
  47243. - if ((port->port.count || port->netcount) &&
  47244. + if ((atomic_read(&port->port.count) || port->netcount) &&
  47245. port->pending_bh && !port->bh_running &&
  47246. !port->bh_requested) {
  47247. DBGISR(("%s bh queued\n", port->device_name));
  47248. @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
  47249. spin_lock_irqsave(&info->lock, flags);
  47250. if (!tty_hung_up_p(filp)) {
  47251. extra_count = true;
  47252. - port->count--;
  47253. + atomic_dec(&port->count);
  47254. }
  47255. spin_unlock_irqrestore(&info->lock, flags);
  47256. port->blocked_open++;
  47257. @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
  47258. remove_wait_queue(&port->open_wait, &wait);
  47259. if (extra_count)
  47260. - port->count++;
  47261. + atomic_inc(&port->count);
  47262. port->blocked_open--;
  47263. if (!retval)
  47264. diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
  47265. index 144202e..4ccb07d 100644
  47266. --- a/drivers/tty/synclinkmp.c
  47267. +++ b/drivers/tty/synclinkmp.c
  47268. @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
  47269. if (debug_level >= DEBUG_LEVEL_INFO)
  47270. printk("%s(%d):%s open(), old ref count = %d\n",
  47271. - __FILE__,__LINE__,tty->driver->name, info->port.count);
  47272. + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
  47273. /* If port is closing, signal caller to try again */
  47274. if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
  47275. @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
  47276. spin_unlock_irqrestore(&info->netlock, flags);
  47277. goto cleanup;
  47278. }
  47279. - info->port.count++;
  47280. + atomic_inc(&info->port.count);
  47281. spin_unlock_irqrestore(&info->netlock, flags);
  47282. - if (info->port.count == 1) {
  47283. + if (atomic_read(&info->port.count) == 1) {
  47284. /* 1st open on this device, init hardware */
  47285. retval = startup(info);
  47286. if (retval < 0)
  47287. @@ -796,8 +796,8 @@ cleanup:
  47288. if (retval) {
  47289. if (tty->count == 1)
  47290. info->port.tty = NULL; /* tty layer will release tty struct */
  47291. - if(info->port.count)
  47292. - info->port.count--;
  47293. + if(atomic_read(&info->port.count))
  47294. + atomic_dec(&info->port.count);
  47295. }
  47296. return retval;
  47297. @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
  47298. if (debug_level >= DEBUG_LEVEL_INFO)
  47299. printk("%s(%d):%s close() entry, count=%d\n",
  47300. - __FILE__,__LINE__, info->device_name, info->port.count);
  47301. + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
  47302. if (tty_port_close_start(&info->port, tty, filp) == 0)
  47303. goto cleanup;
  47304. @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
  47305. cleanup:
  47306. if (debug_level >= DEBUG_LEVEL_INFO)
  47307. printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
  47308. - tty->driver->name, info->port.count);
  47309. + tty->driver->name, atomic_read(&info->port.count));
  47310. }
  47311. /* Called by tty_hangup() when a hangup is signaled.
  47312. @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
  47313. shutdown(info);
  47314. spin_lock_irqsave(&info->port.lock, flags);
  47315. - info->port.count = 0;
  47316. + atomic_set(&info->port.count, 0);
  47317. info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
  47318. info->port.tty = NULL;
  47319. spin_unlock_irqrestore(&info->port.lock, flags);
  47320. @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  47321. unsigned short new_crctype;
  47322. /* return error if TTY interface open */
  47323. - if (info->port.count)
  47324. + if (atomic_read(&info->port.count))
  47325. return -EBUSY;
  47326. switch (encoding)
  47327. @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
  47328. /* arbitrate between network and tty opens */
  47329. spin_lock_irqsave(&info->netlock, flags);
  47330. - if (info->port.count != 0 || info->netcount != 0) {
  47331. + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
  47332. printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
  47333. spin_unlock_irqrestore(&info->netlock, flags);
  47334. return -EBUSY;
  47335. @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  47336. printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
  47337. /* return error if TTY interface open */
  47338. - if (info->port.count)
  47339. + if (atomic_read(&info->port.count))
  47340. return -EBUSY;
  47341. if (cmd != SIOCWANDEV)
  47342. @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
  47343. * do not request bottom half processing if the
  47344. * device is not open in a normal mode.
  47345. */
  47346. - if ( port && (port->port.count || port->netcount) &&
  47347. + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
  47348. port->pending_bh && !port->bh_running &&
  47349. !port->bh_requested ) {
  47350. if ( debug_level >= DEBUG_LEVEL_ISR )
  47351. @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
  47352. if (debug_level >= DEBUG_LEVEL_INFO)
  47353. printk("%s(%d):%s block_til_ready() before block, count=%d\n",
  47354. - __FILE__,__LINE__, tty->driver->name, port->count );
  47355. + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
  47356. spin_lock_irqsave(&info->lock, flags);
  47357. if (!tty_hung_up_p(filp)) {
  47358. extra_count = true;
  47359. - port->count--;
  47360. + atomic_dec(&port->count);
  47361. }
  47362. spin_unlock_irqrestore(&info->lock, flags);
  47363. port->blocked_open++;
  47364. @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
  47365. if (debug_level >= DEBUG_LEVEL_INFO)
  47366. printk("%s(%d):%s block_til_ready() count=%d\n",
  47367. - __FILE__,__LINE__, tty->driver->name, port->count );
  47368. + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
  47369. tty_unlock(tty);
  47370. schedule();
  47371. @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
  47372. remove_wait_queue(&port->open_wait, &wait);
  47373. if (extra_count)
  47374. - port->count++;
  47375. + atomic_inc(&port->count);
  47376. port->blocked_open--;
  47377. if (debug_level >= DEBUG_LEVEL_INFO)
  47378. printk("%s(%d):%s block_til_ready() after, count=%d\n",
  47379. - __FILE__,__LINE__, tty->driver->name, port->count );
  47380. + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
  47381. if (!retval)
  47382. port->flags |= ASYNC_NORMAL_ACTIVE;
  47383. diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
  47384. index ce396ec..04a37be 100644
  47385. --- a/drivers/tty/sysrq.c
  47386. +++ b/drivers/tty/sysrq.c
  47387. @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
  47388. static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
  47389. size_t count, loff_t *ppos)
  47390. {
  47391. - if (count) {
  47392. + if (count && capable(CAP_SYS_ADMIN)) {
  47393. char c;
  47394. if (get_user(c, buf))
  47395. diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
  47396. index d3448a9..28e8db0 100644
  47397. --- a/drivers/tty/tty_io.c
  47398. +++ b/drivers/tty/tty_io.c
  47399. @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
  47400. void tty_default_fops(struct file_operations *fops)
  47401. {
  47402. - *fops = tty_fops;
  47403. + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
  47404. }
  47405. /*
  47406. diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
  47407. index 2d822aa..a566234 100644
  47408. --- a/drivers/tty/tty_ldisc.c
  47409. +++ b/drivers/tty/tty_ldisc.c
  47410. @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
  47411. raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
  47412. tty_ldiscs[disc] = new_ldisc;
  47413. new_ldisc->num = disc;
  47414. - new_ldisc->refcount = 0;
  47415. + atomic_set(&new_ldisc->refcount, 0);
  47416. raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
  47417. return ret;
  47418. @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
  47419. return -EINVAL;
  47420. raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
  47421. - if (tty_ldiscs[disc]->refcount)
  47422. + if (atomic_read(&tty_ldiscs[disc]->refcount))
  47423. ret = -EBUSY;
  47424. else
  47425. tty_ldiscs[disc] = NULL;
  47426. @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
  47427. if (ldops) {
  47428. ret = ERR_PTR(-EAGAIN);
  47429. if (try_module_get(ldops->owner)) {
  47430. - ldops->refcount++;
  47431. + atomic_inc(&ldops->refcount);
  47432. ret = ldops;
  47433. }
  47434. }
  47435. @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
  47436. unsigned long flags;
  47437. raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
  47438. - ldops->refcount--;
  47439. + atomic_dec(&ldops->refcount);
  47440. module_put(ldops->owner);
  47441. raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
  47442. }
  47443. diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
  47444. index 3f746c8..2f2fcaa 100644
  47445. --- a/drivers/tty/tty_port.c
  47446. +++ b/drivers/tty/tty_port.c
  47447. @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
  47448. unsigned long flags;
  47449. spin_lock_irqsave(&port->lock, flags);
  47450. - port->count = 0;
  47451. + atomic_set(&port->count, 0);
  47452. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  47453. tty = port->tty;
  47454. if (tty)
  47455. @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
  47456. /* The port lock protects the port counts */
  47457. spin_lock_irqsave(&port->lock, flags);
  47458. if (!tty_hung_up_p(filp))
  47459. - port->count--;
  47460. + atomic_dec(&port->count);
  47461. port->blocked_open++;
  47462. spin_unlock_irqrestore(&port->lock, flags);
  47463. @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
  47464. we must not mess that up further */
  47465. spin_lock_irqsave(&port->lock, flags);
  47466. if (!tty_hung_up_p(filp))
  47467. - port->count++;
  47468. + atomic_inc(&port->count);
  47469. port->blocked_open--;
  47470. if (retval == 0)
  47471. port->flags |= ASYNC_NORMAL_ACTIVE;
  47472. @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
  47473. return 0;
  47474. }
  47475. - if (tty->count == 1 && port->count != 1) {
  47476. + if (tty->count == 1 && atomic_read(&port->count) != 1) {
  47477. printk(KERN_WARNING
  47478. "tty_port_close_start: tty->count = 1 port count = %d.\n",
  47479. - port->count);
  47480. - port->count = 1;
  47481. + atomic_read(&port->count));
  47482. + atomic_set(&port->count, 1);
  47483. }
  47484. - if (--port->count < 0) {
  47485. + if (atomic_dec_return(&port->count) < 0) {
  47486. printk(KERN_WARNING "tty_port_close_start: count = %d\n",
  47487. - port->count);
  47488. - port->count = 0;
  47489. + atomic_read(&port->count));
  47490. + atomic_set(&port->count, 0);
  47491. }
  47492. - if (port->count) {
  47493. + if (atomic_read(&port->count)) {
  47494. spin_unlock_irqrestore(&port->lock, flags);
  47495. return 0;
  47496. }
  47497. @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
  47498. {
  47499. spin_lock_irq(&port->lock);
  47500. if (!tty_hung_up_p(filp))
  47501. - ++port->count;
  47502. + atomic_inc(&port->count);
  47503. spin_unlock_irq(&port->lock);
  47504. tty_port_tty_set(port, tty);
  47505. diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
  47506. index d0e3a44..5f8b754 100644
  47507. --- a/drivers/tty/vt/keyboard.c
  47508. +++ b/drivers/tty/vt/keyboard.c
  47509. @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
  47510. kbd->kbdmode == VC_OFF) &&
  47511. value != KVAL(K_SAK))
  47512. return; /* SAK is allowed even in raw mode */
  47513. +
  47514. +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
  47515. + {
  47516. + void *func = fn_handler[value];
  47517. + if (func == fn_show_state || func == fn_show_ptregs ||
  47518. + func == fn_show_mem)
  47519. + return;
  47520. + }
  47521. +#endif
  47522. +
  47523. fn_handler[value](vc);
  47524. }
  47525. @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
  47526. if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
  47527. return -EFAULT;
  47528. - if (!capable(CAP_SYS_TTY_CONFIG))
  47529. - perm = 0;
  47530. -
  47531. switch (cmd) {
  47532. case KDGKBENT:
  47533. /* Ensure another thread doesn't free it under us */
  47534. @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
  47535. spin_unlock_irqrestore(&kbd_event_lock, flags);
  47536. return put_user(val, &user_kbe->kb_value);
  47537. case KDSKBENT:
  47538. + if (!capable(CAP_SYS_TTY_CONFIG))
  47539. + perm = 0;
  47540. +
  47541. if (!perm)
  47542. return -EPERM;
  47543. if (!i && v == K_NOSUCHMAP) {
  47544. @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
  47545. int i, j, k;
  47546. int ret;
  47547. - if (!capable(CAP_SYS_TTY_CONFIG))
  47548. - perm = 0;
  47549. -
  47550. kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
  47551. if (!kbs) {
  47552. ret = -ENOMEM;
  47553. @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
  47554. kfree(kbs);
  47555. return ((p && *p) ? -EOVERFLOW : 0);
  47556. case KDSKBSENT:
  47557. + if (!capable(CAP_SYS_TTY_CONFIG))
  47558. + perm = 0;
  47559. +
  47560. if (!perm) {
  47561. ret = -EPERM;
  47562. goto reterr;
  47563. diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
  47564. index a673e5b..36e5d32 100644
  47565. --- a/drivers/uio/uio.c
  47566. +++ b/drivers/uio/uio.c
  47567. @@ -25,6 +25,7 @@
  47568. #include <linux/kobject.h>
  47569. #include <linux/cdev.h>
  47570. #include <linux/uio_driver.h>
  47571. +#include <asm/local.h>
  47572. #define UIO_MAX_DEVICES (1U << MINORBITS)
  47573. @@ -32,7 +33,7 @@ struct uio_device {
  47574. struct module *owner;
  47575. struct device *dev;
  47576. int minor;
  47577. - atomic_t event;
  47578. + atomic_unchecked_t event;
  47579. struct fasync_struct *async_queue;
  47580. wait_queue_head_t wait;
  47581. struct uio_info *info;
  47582. @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
  47583. struct device_attribute *attr, char *buf)
  47584. {
  47585. struct uio_device *idev = dev_get_drvdata(dev);
  47586. - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
  47587. + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
  47588. }
  47589. static DEVICE_ATTR_RO(event);
  47590. @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
  47591. {
  47592. struct uio_device *idev = info->uio_dev;
  47593. - atomic_inc(&idev->event);
  47594. + atomic_inc_unchecked(&idev->event);
  47595. wake_up_interruptible(&idev->wait);
  47596. kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
  47597. }
  47598. @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
  47599. }
  47600. listener->dev = idev;
  47601. - listener->event_count = atomic_read(&idev->event);
  47602. + listener->event_count = atomic_read_unchecked(&idev->event);
  47603. filep->private_data = listener;
  47604. if (idev->info->open) {
  47605. @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
  47606. return -EIO;
  47607. poll_wait(filep, &idev->wait, wait);
  47608. - if (listener->event_count != atomic_read(&idev->event))
  47609. + if (listener->event_count != atomic_read_unchecked(&idev->event))
  47610. return POLLIN | POLLRDNORM;
  47611. return 0;
  47612. }
  47613. @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
  47614. do {
  47615. set_current_state(TASK_INTERRUPTIBLE);
  47616. - event_count = atomic_read(&idev->event);
  47617. + event_count = atomic_read_unchecked(&idev->event);
  47618. if (event_count != listener->event_count) {
  47619. if (copy_to_user(buf, &event_count, count))
  47620. retval = -EFAULT;
  47621. @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
  47622. static int uio_find_mem_index(struct vm_area_struct *vma)
  47623. {
  47624. struct uio_device *idev = vma->vm_private_data;
  47625. + unsigned long size;
  47626. if (vma->vm_pgoff < MAX_UIO_MAPS) {
  47627. - if (idev->info->mem[vma->vm_pgoff].size == 0)
  47628. + size = idev->info->mem[vma->vm_pgoff].size;
  47629. + if (size == 0)
  47630. + return -1;
  47631. + if (vma->vm_end - vma->vm_start > size)
  47632. return -1;
  47633. return (int)vma->vm_pgoff;
  47634. }
  47635. @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
  47636. idev->owner = owner;
  47637. idev->info = info;
  47638. init_waitqueue_head(&idev->wait);
  47639. - atomic_set(&idev->event, 0);
  47640. + atomic_set_unchecked(&idev->event, 0);
  47641. ret = uio_get_minor(idev);
  47642. if (ret)
  47643. diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
  47644. index 813d4d3..a71934f 100644
  47645. --- a/drivers/usb/atm/cxacru.c
  47646. +++ b/drivers/usb/atm/cxacru.c
  47647. @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
  47648. ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
  47649. if (ret < 2)
  47650. return -EINVAL;
  47651. - if (index < 0 || index > 0x7f)
  47652. + if (index > 0x7f)
  47653. return -EINVAL;
  47654. pos += tmp;
  47655. diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
  47656. index dada014..1d0d517 100644
  47657. --- a/drivers/usb/atm/usbatm.c
  47658. +++ b/drivers/usb/atm/usbatm.c
  47659. @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
  47660. if (printk_ratelimit())
  47661. atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
  47662. __func__, vpi, vci);
  47663. - atomic_inc(&vcc->stats->rx_err);
  47664. + atomic_inc_unchecked(&vcc->stats->rx_err);
  47665. return;
  47666. }
  47667. @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
  47668. if (length > ATM_MAX_AAL5_PDU) {
  47669. atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
  47670. __func__, length, vcc);
  47671. - atomic_inc(&vcc->stats->rx_err);
  47672. + atomic_inc_unchecked(&vcc->stats->rx_err);
  47673. goto out;
  47674. }
  47675. @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
  47676. if (sarb->len < pdu_length) {
  47677. atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
  47678. __func__, pdu_length, sarb->len, vcc);
  47679. - atomic_inc(&vcc->stats->rx_err);
  47680. + atomic_inc_unchecked(&vcc->stats->rx_err);
  47681. goto out;
  47682. }
  47683. if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
  47684. atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
  47685. __func__, vcc);
  47686. - atomic_inc(&vcc->stats->rx_err);
  47687. + atomic_inc_unchecked(&vcc->stats->rx_err);
  47688. goto out;
  47689. }
  47690. @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
  47691. if (printk_ratelimit())
  47692. atm_err(instance, "%s: no memory for skb (length: %u)!\n",
  47693. __func__, length);
  47694. - atomic_inc(&vcc->stats->rx_drop);
  47695. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  47696. goto out;
  47697. }
  47698. @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
  47699. vcc->push(vcc, skb);
  47700. - atomic_inc(&vcc->stats->rx);
  47701. + atomic_inc_unchecked(&vcc->stats->rx);
  47702. out:
  47703. skb_trim(sarb, 0);
  47704. }
  47705. @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
  47706. struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
  47707. usbatm_pop(vcc, skb);
  47708. - atomic_inc(&vcc->stats->tx);
  47709. + atomic_inc_unchecked(&vcc->stats->tx);
  47710. skb = skb_dequeue(&instance->sndqueue);
  47711. }
  47712. @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
  47713. if (!left--)
  47714. return sprintf(page,
  47715. "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
  47716. - atomic_read(&atm_dev->stats.aal5.tx),
  47717. - atomic_read(&atm_dev->stats.aal5.tx_err),
  47718. - atomic_read(&atm_dev->stats.aal5.rx),
  47719. - atomic_read(&atm_dev->stats.aal5.rx_err),
  47720. - atomic_read(&atm_dev->stats.aal5.rx_drop));
  47721. + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
  47722. + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
  47723. + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
  47724. + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
  47725. + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
  47726. if (!left--) {
  47727. if (instance->disconnected)
  47728. diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
  47729. index 2a3bbdf..91d72cf 100644
  47730. --- a/drivers/usb/core/devices.c
  47731. +++ b/drivers/usb/core/devices.c
  47732. @@ -126,7 +126,7 @@ static const char format_endpt[] =
  47733. * time it gets called.
  47734. */
  47735. static struct device_connect_event {
  47736. - atomic_t count;
  47737. + atomic_unchecked_t count;
  47738. wait_queue_head_t wait;
  47739. } device_event = {
  47740. .count = ATOMIC_INIT(1),
  47741. @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
  47742. void usbfs_conn_disc_event(void)
  47743. {
  47744. - atomic_add(2, &device_event.count);
  47745. + atomic_add_unchecked(2, &device_event.count);
  47746. wake_up(&device_event.wait);
  47747. }
  47748. @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
  47749. poll_wait(file, &device_event.wait, wait);
  47750. - event_count = atomic_read(&device_event.count);
  47751. + event_count = atomic_read_unchecked(&device_event.count);
  47752. if (file->f_version != event_count) {
  47753. file->f_version = event_count;
  47754. return POLLIN | POLLRDNORM;
  47755. diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
  47756. index 90e18f6..5eeda46 100644
  47757. --- a/drivers/usb/core/devio.c
  47758. +++ b/drivers/usb/core/devio.c
  47759. @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
  47760. struct dev_state *ps = file->private_data;
  47761. struct usb_device *dev = ps->dev;
  47762. ssize_t ret = 0;
  47763. - unsigned len;
  47764. + size_t len;
  47765. loff_t pos;
  47766. int i;
  47767. @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
  47768. for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
  47769. struct usb_config_descriptor *config =
  47770. (struct usb_config_descriptor *)dev->rawdescriptors[i];
  47771. - unsigned int length = le16_to_cpu(config->wTotalLength);
  47772. + size_t length = le16_to_cpu(config->wTotalLength);
  47773. if (*ppos < pos + length) {
  47774. /* The descriptor may claim to be longer than it
  47775. * really is. Here is the actual allocated length. */
  47776. - unsigned alloclen =
  47777. + size_t alloclen =
  47778. le16_to_cpu(dev->config[i].desc.wTotalLength);
  47779. - len = length - (*ppos - pos);
  47780. + len = length + pos - *ppos;
  47781. if (len > nbytes)
  47782. len = nbytes;
  47783. /* Simply don't write (skip over) unallocated parts */
  47784. if (alloclen > (*ppos - pos)) {
  47785. - alloclen -= (*ppos - pos);
  47786. + alloclen = alloclen + pos - *ppos;
  47787. if (copy_to_user(buf,
  47788. dev->rawdescriptors[i] + (*ppos - pos),
  47789. min(len, alloclen))) {
  47790. diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
  47791. index 2518c32..1c201bb 100644
  47792. --- a/drivers/usb/core/hcd.c
  47793. +++ b/drivers/usb/core/hcd.c
  47794. @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
  47795. */
  47796. usb_get_urb(urb);
  47797. atomic_inc(&urb->use_count);
  47798. - atomic_inc(&urb->dev->urbnum);
  47799. + atomic_inc_unchecked(&urb->dev->urbnum);
  47800. usbmon_urb_submit(&hcd->self, urb);
  47801. /* NOTE requirements on root-hub callers (usbfs and the hub
  47802. @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
  47803. urb->hcpriv = NULL;
  47804. INIT_LIST_HEAD(&urb->urb_list);
  47805. atomic_dec(&urb->use_count);
  47806. - atomic_dec(&urb->dev->urbnum);
  47807. + atomic_dec_unchecked(&urb->dev->urbnum);
  47808. if (atomic_read(&urb->reject))
  47809. wake_up(&usb_kill_urb_queue);
  47810. usb_put_urb(urb);
  47811. diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
  47812. index d498d03..e26f959 100644
  47813. --- a/drivers/usb/core/hub.c
  47814. +++ b/drivers/usb/core/hub.c
  47815. @@ -27,6 +27,7 @@
  47816. #include <linux/freezer.h>
  47817. #include <linux/random.h>
  47818. #include <linux/pm_qos.h>
  47819. +#include <linux/grsecurity.h>
  47820. #include <asm/uaccess.h>
  47821. #include <asm/byteorder.h>
  47822. @@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
  47823. goto done;
  47824. return;
  47825. }
  47826. +
  47827. + if (gr_handle_new_usb())
  47828. + goto done;
  47829. +
  47830. if (hub_is_superspeed(hub->hdev))
  47831. unit_load = 150;
  47832. else
  47833. diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
  47834. index f829a1a..e6c334a 100644
  47835. --- a/drivers/usb/core/message.c
  47836. +++ b/drivers/usb/core/message.c
  47837. @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
  47838. * Return: If successful, the number of bytes transferred. Otherwise, a negative
  47839. * error number.
  47840. */
  47841. -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
  47842. +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
  47843. __u8 requesttype, __u16 value, __u16 index, void *data,
  47844. __u16 size, int timeout)
  47845. {
  47846. @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
  47847. * If successful, 0. Otherwise a negative error number. The number of actual
  47848. * bytes transferred will be stored in the @actual_length paramater.
  47849. */
  47850. -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
  47851. +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
  47852. void *data, int len, int *actual_length, int timeout)
  47853. {
  47854. return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
  47855. @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
  47856. * bytes transferred will be stored in the @actual_length parameter.
  47857. *
  47858. */
  47859. -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
  47860. +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
  47861. void *data, int len, int *actual_length, int timeout)
  47862. {
  47863. struct urb *urb;
  47864. diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
  47865. index 1236c60..d47a51c 100644
  47866. --- a/drivers/usb/core/sysfs.c
  47867. +++ b/drivers/usb/core/sysfs.c
  47868. @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
  47869. struct usb_device *udev;
  47870. udev = to_usb_device(dev);
  47871. - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
  47872. + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
  47873. }
  47874. static DEVICE_ATTR_RO(urbnum);
  47875. diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
  47876. index 4d11449..f4ccabf 100644
  47877. --- a/drivers/usb/core/usb.c
  47878. +++ b/drivers/usb/core/usb.c
  47879. @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
  47880. set_dev_node(&dev->dev, dev_to_node(bus->controller));
  47881. dev->state = USB_STATE_ATTACHED;
  47882. dev->lpm_disable_count = 1;
  47883. - atomic_set(&dev->urbnum, 0);
  47884. + atomic_set_unchecked(&dev->urbnum, 0);
  47885. INIT_LIST_HEAD(&dev->ep0.urb_list);
  47886. dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
  47887. diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
  47888. index 2da0a5a..4870e09 100644
  47889. --- a/drivers/usb/dwc3/gadget.c
  47890. +++ b/drivers/usb/dwc3/gadget.c
  47891. @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
  47892. if (!usb_endpoint_xfer_isoc(desc))
  47893. return 0;
  47894. - memset(&trb_link, 0, sizeof(trb_link));
  47895. -
  47896. /* Link TRB for ISOC. The HWO bit is never reset */
  47897. trb_st_hw = &dep->trb_pool[0];
  47898. diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
  47899. index 8cfc319..4868255 100644
  47900. --- a/drivers/usb/early/ehci-dbgp.c
  47901. +++ b/drivers/usb/early/ehci-dbgp.c
  47902. @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
  47903. #ifdef CONFIG_KGDB
  47904. static struct kgdb_io kgdbdbgp_io_ops;
  47905. -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
  47906. +static struct kgdb_io kgdbdbgp_io_ops_console;
  47907. +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
  47908. #else
  47909. #define dbgp_kgdb_mode (0)
  47910. #endif
  47911. @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
  47912. .write_char = kgdbdbgp_write_char,
  47913. };
  47914. +static struct kgdb_io kgdbdbgp_io_ops_console = {
  47915. + .name = "kgdbdbgp",
  47916. + .read_char = kgdbdbgp_read_char,
  47917. + .write_char = kgdbdbgp_write_char,
  47918. + .is_console = 1
  47919. +};
  47920. +
  47921. static int kgdbdbgp_wait_time;
  47922. static int __init kgdbdbgp_parse_config(char *str)
  47923. @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
  47924. ptr++;
  47925. kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
  47926. }
  47927. - kgdb_register_io_module(&kgdbdbgp_io_ops);
  47928. - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
  47929. + if (early_dbgp_console.index != -1)
  47930. + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
  47931. + else
  47932. + kgdb_register_io_module(&kgdbdbgp_io_ops);
  47933. return 0;
  47934. }
  47935. diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
  47936. index 2b4c82d..06a8ee6 100644
  47937. --- a/drivers/usb/gadget/f_uac1.c
  47938. +++ b/drivers/usb/gadget/f_uac1.c
  47939. @@ -13,6 +13,7 @@
  47940. #include <linux/kernel.h>
  47941. #include <linux/device.h>
  47942. #include <linux/atomic.h>
  47943. +#include <linux/module.h>
  47944. #include "u_uac1.h"
  47945. diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
  47946. index ad0aca8..8ff84865 100644
  47947. --- a/drivers/usb/gadget/u_serial.c
  47948. +++ b/drivers/usb/gadget/u_serial.c
  47949. @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
  47950. spin_lock_irq(&port->port_lock);
  47951. /* already open? Great. */
  47952. - if (port->port.count) {
  47953. + if (atomic_read(&port->port.count)) {
  47954. status = 0;
  47955. - port->port.count++;
  47956. + atomic_inc(&port->port.count);
  47957. /* currently opening/closing? wait ... */
  47958. } else if (port->openclose) {
  47959. @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
  47960. tty->driver_data = port;
  47961. port->port.tty = tty;
  47962. - port->port.count = 1;
  47963. + atomic_set(&port->port.count, 1);
  47964. port->openclose = false;
  47965. /* if connected, start the I/O stream */
  47966. @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
  47967. spin_lock_irq(&port->port_lock);
  47968. - if (port->port.count != 1) {
  47969. - if (port->port.count == 0)
  47970. + if (atomic_read(&port->port.count) != 1) {
  47971. + if (atomic_read(&port->port.count) == 0)
  47972. WARN_ON(1);
  47973. else
  47974. - --port->port.count;
  47975. + atomic_dec(&port->port.count);
  47976. goto exit;
  47977. }
  47978. @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
  47979. * and sleep if necessary
  47980. */
  47981. port->openclose = true;
  47982. - port->port.count = 0;
  47983. + atomic_set(&port->port.count, 0);
  47984. gser = port->port_usb;
  47985. if (gser && gser->disconnect)
  47986. @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
  47987. int cond;
  47988. spin_lock_irq(&port->port_lock);
  47989. - cond = (port->port.count == 0) && !port->openclose;
  47990. + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
  47991. spin_unlock_irq(&port->port_lock);
  47992. return cond;
  47993. }
  47994. @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
  47995. /* if it's already open, start I/O ... and notify the serial
  47996. * protocol about open/close status (connect/disconnect).
  47997. */
  47998. - if (port->port.count) {
  47999. + if (atomic_read(&port->port.count)) {
  48000. pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
  48001. gs_start_io(port);
  48002. if (gser->connect)
  48003. @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
  48004. port->port_usb = NULL;
  48005. gser->ioport = NULL;
  48006. - if (port->port.count > 0 || port->openclose) {
  48007. + if (atomic_read(&port->port.count) > 0 || port->openclose) {
  48008. wake_up_interruptible(&port->drain_wait);
  48009. if (port->port.tty)
  48010. tty_hangup(port->port.tty);
  48011. @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
  48012. /* finally, free any unused/unusable I/O buffers */
  48013. spin_lock_irqsave(&port->port_lock, flags);
  48014. - if (port->port.count == 0 && !port->openclose)
  48015. + if (atomic_read(&port->port.count) == 0 && !port->openclose)
  48016. gs_buf_free(&port->port_write_buf);
  48017. gs_free_requests(gser->out, &port->read_pool, NULL);
  48018. gs_free_requests(gser->out, &port->read_queue, NULL);
  48019. diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
  48020. index 7a55fea..cc0ed4f 100644
  48021. --- a/drivers/usb/gadget/u_uac1.c
  48022. +++ b/drivers/usb/gadget/u_uac1.c
  48023. @@ -16,6 +16,7 @@
  48024. #include <linux/ctype.h>
  48025. #include <linux/random.h>
  48026. #include <linux/syscalls.h>
  48027. +#include <linux/module.h>
  48028. #include "u_uac1.h"
  48029. diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
  48030. index 7ae0c4d..35521b7 100644
  48031. --- a/drivers/usb/host/ehci-hub.c
  48032. +++ b/drivers/usb/host/ehci-hub.c
  48033. @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
  48034. urb->transfer_flags = URB_DIR_IN;
  48035. usb_get_urb(urb);
  48036. atomic_inc(&urb->use_count);
  48037. - atomic_inc(&urb->dev->urbnum);
  48038. + atomic_inc_unchecked(&urb->dev->urbnum);
  48039. urb->setup_dma = dma_map_single(
  48040. hcd->self.controller,
  48041. urb->setup_packet,
  48042. @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
  48043. urb->status = -EINPROGRESS;
  48044. usb_get_urb(urb);
  48045. atomic_inc(&urb->use_count);
  48046. - atomic_inc(&urb->dev->urbnum);
  48047. + atomic_inc_unchecked(&urb->dev->urbnum);
  48048. retval = submit_single_step_set_feature(hcd, urb, 0);
  48049. if (!retval && !wait_for_completion_timeout(&done,
  48050. msecs_to_jiffies(2000))) {
  48051. diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
  48052. index ba6a5d6..f88f7f3 100644
  48053. --- a/drivers/usb/misc/appledisplay.c
  48054. +++ b/drivers/usb/misc/appledisplay.c
  48055. @@ -83,7 +83,7 @@ struct appledisplay {
  48056. spinlock_t lock;
  48057. };
  48058. -static atomic_t count_displays = ATOMIC_INIT(0);
  48059. +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
  48060. static struct workqueue_struct *wq;
  48061. static void appledisplay_complete(struct urb *urb)
  48062. @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
  48063. /* Register backlight device */
  48064. snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
  48065. - atomic_inc_return(&count_displays) - 1);
  48066. + atomic_inc_return_unchecked(&count_displays) - 1);
  48067. memset(&props, 0, sizeof(struct backlight_properties));
  48068. props.type = BACKLIGHT_RAW;
  48069. props.max_brightness = 0xff;
  48070. diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
  48071. index 8d7fc48..01c4986 100644
  48072. --- a/drivers/usb/serial/console.c
  48073. +++ b/drivers/usb/serial/console.c
  48074. @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
  48075. info->port = port;
  48076. - ++port->port.count;
  48077. + atomic_inc(&port->port.count);
  48078. if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
  48079. if (serial->type->set_termios) {
  48080. /*
  48081. @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
  48082. }
  48083. /* Now that any required fake tty operations are completed restore
  48084. * the tty port count */
  48085. - --port->port.count;
  48086. + atomic_dec(&port->port.count);
  48087. /* The console is special in terms of closing the device so
  48088. * indicate this port is now acting as a system console. */
  48089. port->port.console = 1;
  48090. @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
  48091. free_tty:
  48092. kfree(tty);
  48093. reset_open_count:
  48094. - port->port.count = 0;
  48095. + atomic_set(&port->port.count, 0);
  48096. usb_autopm_put_interface(serial->interface);
  48097. error_get_interface:
  48098. usb_serial_put(serial);
  48099. @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
  48100. static void usb_console_write(struct console *co,
  48101. const char *buf, unsigned count)
  48102. {
  48103. - static struct usbcons_info *info = &usbcons_info;
  48104. + struct usbcons_info *info = &usbcons_info;
  48105. struct usb_serial_port *port = info->port;
  48106. struct usb_serial *serial;
  48107. int retval = -ENODEV;
  48108. diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
  48109. index 75f70f0..d467e1a 100644
  48110. --- a/drivers/usb/storage/usb.h
  48111. +++ b/drivers/usb/storage/usb.h
  48112. @@ -63,7 +63,7 @@ struct us_unusual_dev {
  48113. __u8 useProtocol;
  48114. __u8 useTransport;
  48115. int (*initFunction)(struct us_data *);
  48116. -};
  48117. +} __do_const;
  48118. /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
  48119. diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
  48120. index a2ef84b..aa7c2b8 100644
  48121. --- a/drivers/usb/wusbcore/wa-hc.h
  48122. +++ b/drivers/usb/wusbcore/wa-hc.h
  48123. @@ -225,7 +225,7 @@ struct wahc {
  48124. spinlock_t xfer_list_lock;
  48125. struct work_struct xfer_enqueue_work;
  48126. struct work_struct xfer_error_work;
  48127. - atomic_t xfer_id_count;
  48128. + atomic_unchecked_t xfer_id_count;
  48129. kernel_ulong_t quirks;
  48130. };
  48131. @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
  48132. INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
  48133. INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
  48134. wa->dto_in_use = 0;
  48135. - atomic_set(&wa->xfer_id_count, 1);
  48136. + atomic_set_unchecked(&wa->xfer_id_count, 1);
  48137. }
  48138. /**
  48139. diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
  48140. index 3cd96e9..bd7c58d 100644
  48141. --- a/drivers/usb/wusbcore/wa-xfer.c
  48142. +++ b/drivers/usb/wusbcore/wa-xfer.c
  48143. @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
  48144. */
  48145. static void wa_xfer_id_init(struct wa_xfer *xfer)
  48146. {
  48147. - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
  48148. + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
  48149. }
  48150. /* Return the xfer's ID. */
  48151. diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
  48152. index 21271d8..45b55a0 100644
  48153. --- a/drivers/vfio/vfio.c
  48154. +++ b/drivers/vfio/vfio.c
  48155. @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
  48156. return 0;
  48157. /* TODO Prevent device auto probing */
  48158. - WARN("Device %s added to live group %d!\n", dev_name(dev),
  48159. + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
  48160. iommu_group_id(group->iommu_group));
  48161. return 0;
  48162. diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
  48163. index 5174eba..451e6bc 100644
  48164. --- a/drivers/vhost/vringh.c
  48165. +++ b/drivers/vhost/vringh.c
  48166. @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
  48167. /* Userspace access helpers: in this case, addresses are really userspace. */
  48168. static inline int getu16_user(u16 *val, const u16 *p)
  48169. {
  48170. - return get_user(*val, (__force u16 __user *)p);
  48171. + return get_user(*val, (u16 __force_user *)p);
  48172. }
  48173. static inline int putu16_user(u16 *p, u16 val)
  48174. {
  48175. - return put_user(val, (__force u16 __user *)p);
  48176. + return put_user(val, (u16 __force_user *)p);
  48177. }
  48178. static inline int copydesc_user(void *dst, const void *src, size_t len)
  48179. {
  48180. - return copy_from_user(dst, (__force void __user *)src, len) ?
  48181. + return copy_from_user(dst, (void __force_user *)src, len) ?
  48182. -EFAULT : 0;
  48183. }
  48184. @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
  48185. const struct vring_used_elem *src,
  48186. unsigned int num)
  48187. {
  48188. - return copy_to_user((__force void __user *)dst, src,
  48189. + return copy_to_user((void __force_user *)dst, src,
  48190. sizeof(*dst) * num) ? -EFAULT : 0;
  48191. }
  48192. static inline int xfer_from_user(void *src, void *dst, size_t len)
  48193. {
  48194. - return copy_from_user(dst, (__force void __user *)src, len) ?
  48195. + return copy_from_user(dst, (void __force_user *)src, len) ?
  48196. -EFAULT : 0;
  48197. }
  48198. static inline int xfer_to_user(void *dst, void *src, size_t len)
  48199. {
  48200. - return copy_to_user((__force void __user *)dst, src, len) ?
  48201. + return copy_to_user((void __force_user *)dst, src, len) ?
  48202. -EFAULT : 0;
  48203. }
  48204. @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
  48205. vrh->last_used_idx = 0;
  48206. vrh->vring.num = num;
  48207. /* vring expects kernel addresses, but only used via accessors. */
  48208. - vrh->vring.desc = (__force struct vring_desc *)desc;
  48209. - vrh->vring.avail = (__force struct vring_avail *)avail;
  48210. - vrh->vring.used = (__force struct vring_used *)used;
  48211. + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
  48212. + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
  48213. + vrh->vring.used = (__force_kernel struct vring_used *)used;
  48214. return 0;
  48215. }
  48216. EXPORT_SYMBOL(vringh_init_user);
  48217. @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
  48218. static inline int putu16_kern(u16 *p, u16 val)
  48219. {
  48220. - ACCESS_ONCE(*p) = val;
  48221. + ACCESS_ONCE_RW(*p) = val;
  48222. return 0;
  48223. }
  48224. diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
  48225. index 1b0b233..6f34c2c 100644
  48226. --- a/drivers/video/arcfb.c
  48227. +++ b/drivers/video/arcfb.c
  48228. @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
  48229. return -ENOSPC;
  48230. err = 0;
  48231. - if ((count + p) > fbmemlength) {
  48232. + if (count > (fbmemlength - p)) {
  48233. count = fbmemlength - p;
  48234. err = -ENOSPC;
  48235. }
  48236. diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
  48237. index 52108be..c7c110d 100644
  48238. --- a/drivers/video/aty/aty128fb.c
  48239. +++ b/drivers/video/aty/aty128fb.c
  48240. @@ -149,7 +149,7 @@ enum {
  48241. };
  48242. /* Must match above enum */
  48243. -static char * const r128_family[] = {
  48244. +static const char * const r128_family[] = {
  48245. "AGP",
  48246. "PCI",
  48247. "PRO AGP",
  48248. diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
  48249. index 28fafbf..ae91651 100644
  48250. --- a/drivers/video/aty/atyfb_base.c
  48251. +++ b/drivers/video/aty/atyfb_base.c
  48252. @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
  48253. par->accel_flags = var->accel_flags; /* hack */
  48254. if (var->accel_flags) {
  48255. - info->fbops->fb_sync = atyfb_sync;
  48256. + pax_open_kernel();
  48257. + *(void **)&info->fbops->fb_sync = atyfb_sync;
  48258. + pax_close_kernel();
  48259. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  48260. } else {
  48261. - info->fbops->fb_sync = NULL;
  48262. + pax_open_kernel();
  48263. + *(void **)&info->fbops->fb_sync = NULL;
  48264. + pax_close_kernel();
  48265. info->flags |= FBINFO_HWACCEL_DISABLED;
  48266. }
  48267. diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
  48268. index 0fe02e2..ab01b26 100644
  48269. --- a/drivers/video/aty/mach64_cursor.c
  48270. +++ b/drivers/video/aty/mach64_cursor.c
  48271. @@ -8,6 +8,7 @@
  48272. #include "../fb_draw.h"
  48273. #include <asm/io.h>
  48274. +#include <asm/pgtable.h>
  48275. #ifdef __sparc__
  48276. #include <asm/fbio.h>
  48277. @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
  48278. info->sprite.buf_align = 16; /* and 64 lines tall. */
  48279. info->sprite.flags = FB_PIXMAP_IO;
  48280. - info->fbops->fb_cursor = atyfb_cursor;
  48281. + pax_open_kernel();
  48282. + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
  48283. + pax_close_kernel();
  48284. return 0;
  48285. }
  48286. diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
  48287. index 84a110a..96312c3 100644
  48288. --- a/drivers/video/backlight/kb3886_bl.c
  48289. +++ b/drivers/video/backlight/kb3886_bl.c
  48290. @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
  48291. static unsigned long kb3886bl_flags;
  48292. #define KB3886BL_SUSPENDED 0x01
  48293. -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
  48294. +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
  48295. {
  48296. .ident = "Sahara Touch-iT",
  48297. .matches = {
  48298. diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
  48299. index 900aa4e..6d49418 100644
  48300. --- a/drivers/video/fb_defio.c
  48301. +++ b/drivers/video/fb_defio.c
  48302. @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
  48303. BUG_ON(!fbdefio);
  48304. mutex_init(&fbdefio->lock);
  48305. - info->fbops->fb_mmap = fb_deferred_io_mmap;
  48306. + pax_open_kernel();
  48307. + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
  48308. + pax_close_kernel();
  48309. INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
  48310. INIT_LIST_HEAD(&fbdefio->pagelist);
  48311. if (fbdefio->delay == 0) /* set a default of 1 s */
  48312. @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
  48313. page->mapping = NULL;
  48314. }
  48315. - info->fbops->fb_mmap = NULL;
  48316. + *(void **)&info->fbops->fb_mmap = NULL;
  48317. mutex_destroy(&fbdefio->lock);
  48318. }
  48319. EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
  48320. diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
  48321. index 7309ac7..be3c49c 100644
  48322. --- a/drivers/video/fbmem.c
  48323. +++ b/drivers/video/fbmem.c
  48324. @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
  48325. image->dx += image->width + 8;
  48326. }
  48327. } else if (rotate == FB_ROTATE_UD) {
  48328. - for (x = 0; x < num && image->dx >= 0; x++) {
  48329. + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
  48330. info->fbops->fb_imageblit(info, image);
  48331. image->dx -= image->width + 8;
  48332. }
  48333. @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
  48334. image->dy += image->height + 8;
  48335. }
  48336. } else if (rotate == FB_ROTATE_CCW) {
  48337. - for (x = 0; x < num && image->dy >= 0; x++) {
  48338. + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
  48339. info->fbops->fb_imageblit(info, image);
  48340. image->dy -= image->height + 8;
  48341. }
  48342. @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  48343. return -EFAULT;
  48344. if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
  48345. return -EINVAL;
  48346. - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
  48347. + if (con2fb.framebuffer >= FB_MAX)
  48348. return -EINVAL;
  48349. if (!registered_fb[con2fb.framebuffer])
  48350. request_module("fb%d", con2fb.framebuffer);
  48351. @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
  48352. __u32 data;
  48353. int err;
  48354. - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
  48355. + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
  48356. data = (__u32) (unsigned long) fix->smem_start;
  48357. err |= put_user(data, &fix32->smem_start);
  48358. diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
  48359. index 130708f..cdac1a9 100644
  48360. --- a/drivers/video/hyperv_fb.c
  48361. +++ b/drivers/video/hyperv_fb.c
  48362. @@ -233,7 +233,7 @@ static uint screen_fb_size;
  48363. static inline int synthvid_send(struct hv_device *hdev,
  48364. struct synthvid_msg *msg)
  48365. {
  48366. - static atomic64_t request_id = ATOMIC64_INIT(0);
  48367. + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
  48368. int ret;
  48369. msg->pipe_hdr.type = PIPE_MSG_DATA;
  48370. @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
  48371. ret = vmbus_sendpacket(hdev->channel, msg,
  48372. msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
  48373. - atomic64_inc_return(&request_id),
  48374. + atomic64_inc_return_unchecked(&request_id),
  48375. VM_PKT_DATA_INBAND, 0);
  48376. if (ret)
  48377. diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
  48378. index 7672d2e..b56437f 100644
  48379. --- a/drivers/video/i810/i810_accel.c
  48380. +++ b/drivers/video/i810/i810_accel.c
  48381. @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
  48382. }
  48383. }
  48384. printk("ringbuffer lockup!!!\n");
  48385. + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
  48386. i810_report_error(mmio);
  48387. par->dev_flags |= LOCKUP;
  48388. info->pixmap.scan_align = 1;
  48389. diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
  48390. index 3c14e43..2630570 100644
  48391. --- a/drivers/video/logo/logo_linux_clut224.ppm
  48392. +++ b/drivers/video/logo/logo_linux_clut224.ppm
  48393. @@ -2,1603 +2,1123 @@ P3
  48394. # Standard 224-color Linux logo
  48395. 80 80
  48396. 255
  48397. - 0 0 0 0 0 0 0 0 0 0 0 0
  48398. - 0 0 0 0 0 0 0 0 0 0 0 0
  48399. - 0 0 0 0 0 0 0 0 0 0 0 0
  48400. - 0 0 0 0 0 0 0 0 0 0 0 0
  48401. - 0 0 0 0 0 0 0 0 0 0 0 0
  48402. - 0 0 0 0 0 0 0 0 0 0 0 0
  48403. - 0 0 0 0 0 0 0 0 0 0 0 0
  48404. - 0 0 0 0 0 0 0 0 0 0 0 0
  48405. - 0 0 0 0 0 0 0 0 0 0 0 0
  48406. - 6 6 6 6 6 6 10 10 10 10 10 10
  48407. - 10 10 10 6 6 6 6 6 6 6 6 6
  48408. - 0 0 0 0 0 0 0 0 0 0 0 0
  48409. - 0 0 0 0 0 0 0 0 0 0 0 0
  48410. - 0 0 0 0 0 0 0 0 0 0 0 0
  48411. - 0 0 0 0 0 0 0 0 0 0 0 0
  48412. - 0 0 0 0 0 0 0 0 0 0 0 0
  48413. - 0 0 0 0 0 0 0 0 0 0 0 0
  48414. - 0 0 0 0 0 0 0 0 0 0 0 0
  48415. - 0 0 0 0 0 0 0 0 0 0 0 0
  48416. - 0 0 0 0 0 0 0 0 0 0 0 0
  48417. - 0 0 0 0 0 0 0 0 0 0 0 0
  48418. - 0 0 0 0 0 0 0 0 0 0 0 0
  48419. - 0 0 0 0 0 0 0 0 0 0 0 0
  48420. - 0 0 0 0 0 0 0 0 0 0 0 0
  48421. - 0 0 0 0 0 0 0 0 0 0 0 0
  48422. - 0 0 0 0 0 0 0 0 0 0 0 0
  48423. - 0 0 0 0 0 0 0 0 0 0 0 0
  48424. - 0 0 0 0 0 0 0 0 0 0 0 0
  48425. - 0 0 0 6 6 6 10 10 10 14 14 14
  48426. - 22 22 22 26 26 26 30 30 30 34 34 34
  48427. - 30 30 30 30 30 30 26 26 26 18 18 18
  48428. - 14 14 14 10 10 10 6 6 6 0 0 0
  48429. - 0 0 0 0 0 0 0 0 0 0 0 0
  48430. - 0 0 0 0 0 0 0 0 0 0 0 0
  48431. - 0 0 0 0 0 0 0 0 0 0 0 0
  48432. - 0 0 0 0 0 0 0 0 0 0 0 0
  48433. - 0 0 0 0 0 0 0 0 0 0 0 0
  48434. - 0 0 0 0 0 0 0 0 0 0 0 0
  48435. - 0 0 0 0 0 0 0 0 0 0 0 0
  48436. - 0 0 0 0 0 0 0 0 0 0 0 0
  48437. - 0 0 0 0 0 0 0 0 0 0 0 0
  48438. - 0 0 0 0 0 1 0 0 1 0 0 0
  48439. - 0 0 0 0 0 0 0 0 0 0 0 0
  48440. - 0 0 0 0 0 0 0 0 0 0 0 0
  48441. - 0 0 0 0 0 0 0 0 0 0 0 0
  48442. - 0 0 0 0 0 0 0 0 0 0 0 0
  48443. - 0 0 0 0 0 0 0 0 0 0 0 0
  48444. - 0 0 0 0 0 0 0 0 0 0 0 0
  48445. - 6 6 6 14 14 14 26 26 26 42 42 42
  48446. - 54 54 54 66 66 66 78 78 78 78 78 78
  48447. - 78 78 78 74 74 74 66 66 66 54 54 54
  48448. - 42 42 42 26 26 26 18 18 18 10 10 10
  48449. - 6 6 6 0 0 0 0 0 0 0 0 0
  48450. - 0 0 0 0 0 0 0 0 0 0 0 0
  48451. - 0 0 0 0 0 0 0 0 0 0 0 0
  48452. - 0 0 0 0 0 0 0 0 0 0 0 0
  48453. - 0 0 0 0 0 0 0 0 0 0 0 0
  48454. - 0 0 0 0 0 0 0 0 0 0 0 0
  48455. - 0 0 0 0 0 0 0 0 0 0 0 0
  48456. - 0 0 0 0 0 0 0 0 0 0 0 0
  48457. - 0 0 0 0 0 0 0 0 0 0 0 0
  48458. - 0 0 1 0 0 0 0 0 0 0 0 0
  48459. - 0 0 0 0 0 0 0 0 0 0 0 0
  48460. - 0 0 0 0 0 0 0 0 0 0 0 0
  48461. - 0 0 0 0 0 0 0 0 0 0 0 0
  48462. - 0 0 0 0 0 0 0 0 0 0 0 0
  48463. - 0 0 0 0 0 0 0 0 0 0 0 0
  48464. - 0 0 0 0 0 0 0 0 0 10 10 10
  48465. - 22 22 22 42 42 42 66 66 66 86 86 86
  48466. - 66 66 66 38 38 38 38 38 38 22 22 22
  48467. - 26 26 26 34 34 34 54 54 54 66 66 66
  48468. - 86 86 86 70 70 70 46 46 46 26 26 26
  48469. - 14 14 14 6 6 6 0 0 0 0 0 0
  48470. - 0 0 0 0 0 0 0 0 0 0 0 0
  48471. - 0 0 0 0 0 0 0 0 0 0 0 0
  48472. - 0 0 0 0 0 0 0 0 0 0 0 0
  48473. - 0 0 0 0 0 0 0 0 0 0 0 0
  48474. - 0 0 0 0 0 0 0 0 0 0 0 0
  48475. - 0 0 0 0 0 0 0 0 0 0 0 0
  48476. - 0 0 0 0 0 0 0 0 0 0 0 0
  48477. - 0 0 0 0 0 0 0 0 0 0 0 0
  48478. - 0 0 1 0 0 1 0 0 1 0 0 0
  48479. - 0 0 0 0 0 0 0 0 0 0 0 0
  48480. - 0 0 0 0 0 0 0 0 0 0 0 0
  48481. - 0 0 0 0 0 0 0 0 0 0 0 0
  48482. - 0 0 0 0 0 0 0 0 0 0 0 0
  48483. - 0 0 0 0 0 0 0 0 0 0 0 0
  48484. - 0 0 0 0 0 0 10 10 10 26 26 26
  48485. - 50 50 50 82 82 82 58 58 58 6 6 6
  48486. - 2 2 6 2 2 6 2 2 6 2 2 6
  48487. - 2 2 6 2 2 6 2 2 6 2 2 6
  48488. - 6 6 6 54 54 54 86 86 86 66 66 66
  48489. - 38 38 38 18 18 18 6 6 6 0 0 0
  48490. - 0 0 0 0 0 0 0 0 0 0 0 0
  48491. - 0 0 0 0 0 0 0 0 0 0 0 0
  48492. - 0 0 0 0 0 0 0 0 0 0 0 0
  48493. - 0 0 0 0 0 0 0 0 0 0 0 0
  48494. - 0 0 0 0 0 0 0 0 0 0 0 0
  48495. - 0 0 0 0 0 0 0 0 0 0 0 0
  48496. - 0 0 0 0 0 0 0 0 0 0 0 0
  48497. - 0 0 0 0 0 0 0 0 0 0 0 0
  48498. - 0 0 0 0 0 0 0 0 0 0 0 0
  48499. - 0 0 0 0 0 0 0 0 0 0 0 0
  48500. - 0 0 0 0 0 0 0 0 0 0 0 0
  48501. - 0 0 0 0 0 0 0 0 0 0 0 0
  48502. - 0 0 0 0 0 0 0 0 0 0 0 0
  48503. - 0 0 0 0 0 0 0 0 0 0 0 0
  48504. - 0 0 0 6 6 6 22 22 22 50 50 50
  48505. - 78 78 78 34 34 34 2 2 6 2 2 6
  48506. - 2 2 6 2 2 6 2 2 6 2 2 6
  48507. - 2 2 6 2 2 6 2 2 6 2 2 6
  48508. - 2 2 6 2 2 6 6 6 6 70 70 70
  48509. - 78 78 78 46 46 46 22 22 22 6 6 6
  48510. - 0 0 0 0 0 0 0 0 0 0 0 0
  48511. - 0 0 0 0 0 0 0 0 0 0 0 0
  48512. - 0 0 0 0 0 0 0 0 0 0 0 0
  48513. - 0 0 0 0 0 0 0 0 0 0 0 0
  48514. - 0 0 0 0 0 0 0 0 0 0 0 0
  48515. - 0 0 0 0 0 0 0 0 0 0 0 0
  48516. - 0 0 0 0 0 0 0 0 0 0 0 0
  48517. - 0 0 0 0 0 0 0 0 0 0 0 0
  48518. - 0 0 1 0 0 1 0 0 1 0 0 0
  48519. - 0 0 0 0 0 0 0 0 0 0 0 0
  48520. - 0 0 0 0 0 0 0 0 0 0 0 0
  48521. - 0 0 0 0 0 0 0 0 0 0 0 0
  48522. - 0 0 0 0 0 0 0 0 0 0 0 0
  48523. - 0 0 0 0 0 0 0 0 0 0 0 0
  48524. - 6 6 6 18 18 18 42 42 42 82 82 82
  48525. - 26 26 26 2 2 6 2 2 6 2 2 6
  48526. - 2 2 6 2 2 6 2 2 6 2 2 6
  48527. - 2 2 6 2 2 6 2 2 6 14 14 14
  48528. - 46 46 46 34 34 34 6 6 6 2 2 6
  48529. - 42 42 42 78 78 78 42 42 42 18 18 18
  48530. - 6 6 6 0 0 0 0 0 0 0 0 0
  48531. - 0 0 0 0 0 0 0 0 0 0 0 0
  48532. - 0 0 0 0 0 0 0 0 0 0 0 0
  48533. - 0 0 0 0 0 0 0 0 0 0 0 0
  48534. - 0 0 0 0 0 0 0 0 0 0 0 0
  48535. - 0 0 0 0 0 0 0 0 0 0 0 0
  48536. - 0 0 0 0 0 0 0 0 0 0 0 0
  48537. - 0 0 0 0 0 0 0 0 0 0 0 0
  48538. - 0 0 1 0 0 0 0 0 1 0 0 0
  48539. - 0 0 0 0 0 0 0 0 0 0 0 0
  48540. - 0 0 0 0 0 0 0 0 0 0 0 0
  48541. - 0 0 0 0 0 0 0 0 0 0 0 0
  48542. - 0 0 0 0 0 0 0 0 0 0 0 0
  48543. - 0 0 0 0 0 0 0 0 0 0 0 0
  48544. - 10 10 10 30 30 30 66 66 66 58 58 58
  48545. - 2 2 6 2 2 6 2 2 6 2 2 6
  48546. - 2 2 6 2 2 6 2 2 6 2 2 6
  48547. - 2 2 6 2 2 6 2 2 6 26 26 26
  48548. - 86 86 86 101 101 101 46 46 46 10 10 10
  48549. - 2 2 6 58 58 58 70 70 70 34 34 34
  48550. - 10 10 10 0 0 0 0 0 0 0 0 0
  48551. - 0 0 0 0 0 0 0 0 0 0 0 0
  48552. - 0 0 0 0 0 0 0 0 0 0 0 0
  48553. - 0 0 0 0 0 0 0 0 0 0 0 0
  48554. - 0 0 0 0 0 0 0 0 0 0 0 0
  48555. - 0 0 0 0 0 0 0 0 0 0 0 0
  48556. - 0 0 0 0 0 0 0 0 0 0 0 0
  48557. - 0 0 0 0 0 0 0 0 0 0 0 0
  48558. - 0 0 1 0 0 1 0 0 1 0 0 0
  48559. - 0 0 0 0 0 0 0 0 0 0 0 0
  48560. - 0 0 0 0 0 0 0 0 0 0 0 0
  48561. - 0 0 0 0 0 0 0 0 0 0 0 0
  48562. - 0 0 0 0 0 0 0 0 0 0 0 0
  48563. - 0 0 0 0 0 0 0 0 0 0 0 0
  48564. - 14 14 14 42 42 42 86 86 86 10 10 10
  48565. - 2 2 6 2 2 6 2 2 6 2 2 6
  48566. - 2 2 6 2 2 6 2 2 6 2 2 6
  48567. - 2 2 6 2 2 6 2 2 6 30 30 30
  48568. - 94 94 94 94 94 94 58 58 58 26 26 26
  48569. - 2 2 6 6 6 6 78 78 78 54 54 54
  48570. - 22 22 22 6 6 6 0 0 0 0 0 0
  48571. - 0 0 0 0 0 0 0 0 0 0 0 0
  48572. - 0 0 0 0 0 0 0 0 0 0 0 0
  48573. - 0 0 0 0 0 0 0 0 0 0 0 0
  48574. - 0 0 0 0 0 0 0 0 0 0 0 0
  48575. - 0 0 0 0 0 0 0 0 0 0 0 0
  48576. - 0 0 0 0 0 0 0 0 0 0 0 0
  48577. - 0 0 0 0 0 0 0 0 0 0 0 0
  48578. - 0 0 0 0 0 0 0 0 0 0 0 0
  48579. - 0 0 0 0 0 0 0 0 0 0 0 0
  48580. - 0 0 0 0 0 0 0 0 0 0 0 0
  48581. - 0 0 0 0 0 0 0 0 0 0 0 0
  48582. - 0 0 0 0 0 0 0 0 0 0 0 0
  48583. - 0 0 0 0 0 0 0 0 0 6 6 6
  48584. - 22 22 22 62 62 62 62 62 62 2 2 6
  48585. - 2 2 6 2 2 6 2 2 6 2 2 6
  48586. - 2 2 6 2 2 6 2 2 6 2 2 6
  48587. - 2 2 6 2 2 6 2 2 6 26 26 26
  48588. - 54 54 54 38 38 38 18 18 18 10 10 10
  48589. - 2 2 6 2 2 6 34 34 34 82 82 82
  48590. - 38 38 38 14 14 14 0 0 0 0 0 0
  48591. - 0 0 0 0 0 0 0 0 0 0 0 0
  48592. - 0 0 0 0 0 0 0 0 0 0 0 0
  48593. - 0 0 0 0 0 0 0 0 0 0 0 0
  48594. - 0 0 0 0 0 0 0 0 0 0 0 0
  48595. - 0 0 0 0 0 0 0 0 0 0 0 0
  48596. - 0 0 0 0 0 0 0 0 0 0 0 0
  48597. - 0 0 0 0 0 0 0 0 0 0 0 0
  48598. - 0 0 0 0 0 1 0 0 1 0 0 0
  48599. - 0 0 0 0 0 0 0 0 0 0 0 0
  48600. - 0 0 0 0 0 0 0 0 0 0 0 0
  48601. - 0 0 0 0 0 0 0 0 0 0 0 0
  48602. - 0 0 0 0 0 0 0 0 0 0 0 0
  48603. - 0 0 0 0 0 0 0 0 0 6 6 6
  48604. - 30 30 30 78 78 78 30 30 30 2 2 6
  48605. - 2 2 6 2 2 6 2 2 6 2 2 6
  48606. - 2 2 6 2 2 6 2 2 6 2 2 6
  48607. - 2 2 6 2 2 6 2 2 6 10 10 10
  48608. - 10 10 10 2 2 6 2 2 6 2 2 6
  48609. - 2 2 6 2 2 6 2 2 6 78 78 78
  48610. - 50 50 50 18 18 18 6 6 6 0 0 0
  48611. - 0 0 0 0 0 0 0 0 0 0 0 0
  48612. - 0 0 0 0 0 0 0 0 0 0 0 0
  48613. - 0 0 0 0 0 0 0 0 0 0 0 0
  48614. - 0 0 0 0 0 0 0 0 0 0 0 0
  48615. - 0 0 0 0 0 0 0 0 0 0 0 0
  48616. - 0 0 0 0 0 0 0 0 0 0 0 0
  48617. - 0 0 0 0 0 0 0 0 0 0 0 0
  48618. - 0 0 1 0 0 0 0 0 0 0 0 0
  48619. - 0 0 0 0 0 0 0 0 0 0 0 0
  48620. - 0 0 0 0 0 0 0 0 0 0 0 0
  48621. - 0 0 0 0 0 0 0 0 0 0 0 0
  48622. - 0 0 0 0 0 0 0 0 0 0 0 0
  48623. - 0 0 0 0 0 0 0 0 0 10 10 10
  48624. - 38 38 38 86 86 86 14 14 14 2 2 6
  48625. - 2 2 6 2 2 6 2 2 6 2 2 6
  48626. - 2 2 6 2 2 6 2 2 6 2 2 6
  48627. - 2 2 6 2 2 6 2 2 6 2 2 6
  48628. - 2 2 6 2 2 6 2 2 6 2 2 6
  48629. - 2 2 6 2 2 6 2 2 6 54 54 54
  48630. - 66 66 66 26 26 26 6 6 6 0 0 0
  48631. - 0 0 0 0 0 0 0 0 0 0 0 0
  48632. - 0 0 0 0 0 0 0 0 0 0 0 0
  48633. - 0 0 0 0 0 0 0 0 0 0 0 0
  48634. - 0 0 0 0 0 0 0 0 0 0 0 0
  48635. - 0 0 0 0 0 0 0 0 0 0 0 0
  48636. - 0 0 0 0 0 0 0 0 0 0 0 0
  48637. - 0 0 0 0 0 0 0 0 0 0 0 0
  48638. - 0 0 0 0 0 1 0 0 1 0 0 0
  48639. - 0 0 0 0 0 0 0 0 0 0 0 0
  48640. - 0 0 0 0 0 0 0 0 0 0 0 0
  48641. - 0 0 0 0 0 0 0 0 0 0 0 0
  48642. - 0 0 0 0 0 0 0 0 0 0 0 0
  48643. - 0 0 0 0 0 0 0 0 0 14 14 14
  48644. - 42 42 42 82 82 82 2 2 6 2 2 6
  48645. - 2 2 6 6 6 6 10 10 10 2 2 6
  48646. - 2 2 6 2 2 6 2 2 6 2 2 6
  48647. - 2 2 6 2 2 6 2 2 6 6 6 6
  48648. - 14 14 14 10 10 10 2 2 6 2 2 6
  48649. - 2 2 6 2 2 6 2 2 6 18 18 18
  48650. - 82 82 82 34 34 34 10 10 10 0 0 0
  48651. - 0 0 0 0 0 0 0 0 0 0 0 0
  48652. - 0 0 0 0 0 0 0 0 0 0 0 0
  48653. - 0 0 0 0 0 0 0 0 0 0 0 0
  48654. - 0 0 0 0 0 0 0 0 0 0 0 0
  48655. - 0 0 0 0 0 0 0 0 0 0 0 0
  48656. - 0 0 0 0 0 0 0 0 0 0 0 0
  48657. - 0 0 0 0 0 0 0 0 0 0 0 0
  48658. - 0 0 1 0 0 0 0 0 0 0 0 0
  48659. - 0 0 0 0 0 0 0 0 0 0 0 0
  48660. - 0 0 0 0 0 0 0 0 0 0 0 0
  48661. - 0 0 0 0 0 0 0 0 0 0 0 0
  48662. - 0 0 0 0 0 0 0 0 0 0 0 0
  48663. - 0 0 0 0 0 0 0 0 0 14 14 14
  48664. - 46 46 46 86 86 86 2 2 6 2 2 6
  48665. - 6 6 6 6 6 6 22 22 22 34 34 34
  48666. - 6 6 6 2 2 6 2 2 6 2 2 6
  48667. - 2 2 6 2 2 6 18 18 18 34 34 34
  48668. - 10 10 10 50 50 50 22 22 22 2 2 6
  48669. - 2 2 6 2 2 6 2 2 6 10 10 10
  48670. - 86 86 86 42 42 42 14 14 14 0 0 0
  48671. - 0 0 0 0 0 0 0 0 0 0 0 0
  48672. - 0 0 0 0 0 0 0 0 0 0 0 0
  48673. - 0 0 0 0 0 0 0 0 0 0 0 0
  48674. - 0 0 0 0 0 0 0 0 0 0 0 0
  48675. - 0 0 0 0 0 0 0 0 0 0 0 0
  48676. - 0 0 0 0 0 0 0 0 0 0 0 0
  48677. - 0 0 0 0 0 0 0 0 0 0 0 0
  48678. - 0 0 1 0 0 1 0 0 1 0 0 0
  48679. - 0 0 0 0 0 0 0 0 0 0 0 0
  48680. - 0 0 0 0 0 0 0 0 0 0 0 0
  48681. - 0 0 0 0 0 0 0 0 0 0 0 0
  48682. - 0 0 0 0 0 0 0 0 0 0 0 0
  48683. - 0 0 0 0 0 0 0 0 0 14 14 14
  48684. - 46 46 46 86 86 86 2 2 6 2 2 6
  48685. - 38 38 38 116 116 116 94 94 94 22 22 22
  48686. - 22 22 22 2 2 6 2 2 6 2 2 6
  48687. - 14 14 14 86 86 86 138 138 138 162 162 162
  48688. -154 154 154 38 38 38 26 26 26 6 6 6
  48689. - 2 2 6 2 2 6 2 2 6 2 2 6
  48690. - 86 86 86 46 46 46 14 14 14 0 0 0
  48691. - 0 0 0 0 0 0 0 0 0 0 0 0
  48692. - 0 0 0 0 0 0 0 0 0 0 0 0
  48693. - 0 0 0 0 0 0 0 0 0 0 0 0
  48694. - 0 0 0 0 0 0 0 0 0 0 0 0
  48695. - 0 0 0 0 0 0 0 0 0 0 0 0
  48696. - 0 0 0 0 0 0 0 0 0 0 0 0
  48697. - 0 0 0 0 0 0 0 0 0 0 0 0
  48698. - 0 0 0 0 0 0 0 0 0 0 0 0
  48699. - 0 0 0 0 0 0 0 0 0 0 0 0
  48700. - 0 0 0 0 0 0 0 0 0 0 0 0
  48701. - 0 0 0 0 0 0 0 0 0 0 0 0
  48702. - 0 0 0 0 0 0 0 0 0 0 0 0
  48703. - 0 0 0 0 0 0 0 0 0 14 14 14
  48704. - 46 46 46 86 86 86 2 2 6 14 14 14
  48705. -134 134 134 198 198 198 195 195 195 116 116 116
  48706. - 10 10 10 2 2 6 2 2 6 6 6 6
  48707. -101 98 89 187 187 187 210 210 210 218 218 218
  48708. -214 214 214 134 134 134 14 14 14 6 6 6
  48709. - 2 2 6 2 2 6 2 2 6 2 2 6
  48710. - 86 86 86 50 50 50 18 18 18 6 6 6
  48711. - 0 0 0 0 0 0 0 0 0 0 0 0
  48712. - 0 0 0 0 0 0 0 0 0 0 0 0
  48713. - 0 0 0 0 0 0 0 0 0 0 0 0
  48714. - 0 0 0 0 0 0 0 0 0 0 0 0
  48715. - 0 0 0 0 0 0 0 0 0 0 0 0
  48716. - 0 0 0 0 0 0 0 0 0 0 0 0
  48717. - 0 0 0 0 0 0 0 0 1 0 0 0
  48718. - 0 0 1 0 0 1 0 0 1 0 0 0
  48719. - 0 0 0 0 0 0 0 0 0 0 0 0
  48720. - 0 0 0 0 0 0 0 0 0 0 0 0
  48721. - 0 0 0 0 0 0 0 0 0 0 0 0
  48722. - 0 0 0 0 0 0 0 0 0 0 0 0
  48723. - 0 0 0 0 0 0 0 0 0 14 14 14
  48724. - 46 46 46 86 86 86 2 2 6 54 54 54
  48725. -218 218 218 195 195 195 226 226 226 246 246 246
  48726. - 58 58 58 2 2 6 2 2 6 30 30 30
  48727. -210 210 210 253 253 253 174 174 174 123 123 123
  48728. -221 221 221 234 234 234 74 74 74 2 2 6
  48729. - 2 2 6 2 2 6 2 2 6 2 2 6
  48730. - 70 70 70 58 58 58 22 22 22 6 6 6
  48731. - 0 0 0 0 0 0 0 0 0 0 0 0
  48732. - 0 0 0 0 0 0 0 0 0 0 0 0
  48733. - 0 0 0 0 0 0 0 0 0 0 0 0
  48734. - 0 0 0 0 0 0 0 0 0 0 0 0
  48735. - 0 0 0 0 0 0 0 0 0 0 0 0
  48736. - 0 0 0 0 0 0 0 0 0 0 0 0
  48737. - 0 0 0 0 0 0 0 0 0 0 0 0
  48738. - 0 0 0 0 0 0 0 0 0 0 0 0
  48739. - 0 0 0 0 0 0 0 0 0 0 0 0
  48740. - 0 0 0 0 0 0 0 0 0 0 0 0
  48741. - 0 0 0 0 0 0 0 0 0 0 0 0
  48742. - 0 0 0 0 0 0 0 0 0 0 0 0
  48743. - 0 0 0 0 0 0 0 0 0 14 14 14
  48744. - 46 46 46 82 82 82 2 2 6 106 106 106
  48745. -170 170 170 26 26 26 86 86 86 226 226 226
  48746. -123 123 123 10 10 10 14 14 14 46 46 46
  48747. -231 231 231 190 190 190 6 6 6 70 70 70
  48748. - 90 90 90 238 238 238 158 158 158 2 2 6
  48749. - 2 2 6 2 2 6 2 2 6 2 2 6
  48750. - 70 70 70 58 58 58 22 22 22 6 6 6
  48751. - 0 0 0 0 0 0 0 0 0 0 0 0
  48752. - 0 0 0 0 0 0 0 0 0 0 0 0
  48753. - 0 0 0 0 0 0 0 0 0 0 0 0
  48754. - 0 0 0 0 0 0 0 0 0 0 0 0
  48755. - 0 0 0 0 0 0 0 0 0 0 0 0
  48756. - 0 0 0 0 0 0 0 0 0 0 0 0
  48757. - 0 0 0 0 0 0 0 0 1 0 0 0
  48758. - 0 0 1 0 0 1 0 0 1 0 0 0
  48759. - 0 0 0 0 0 0 0 0 0 0 0 0
  48760. - 0 0 0 0 0 0 0 0 0 0 0 0
  48761. - 0 0 0 0 0 0 0 0 0 0 0 0
  48762. - 0 0 0 0 0 0 0 0 0 0 0 0
  48763. - 0 0 0 0 0 0 0 0 0 14 14 14
  48764. - 42 42 42 86 86 86 6 6 6 116 116 116
  48765. -106 106 106 6 6 6 70 70 70 149 149 149
  48766. -128 128 128 18 18 18 38 38 38 54 54 54
  48767. -221 221 221 106 106 106 2 2 6 14 14 14
  48768. - 46 46 46 190 190 190 198 198 198 2 2 6
  48769. - 2 2 6 2 2 6 2 2 6 2 2 6
  48770. - 74 74 74 62 62 62 22 22 22 6 6 6
  48771. - 0 0 0 0 0 0 0 0 0 0 0 0
  48772. - 0 0 0 0 0 0 0 0 0 0 0 0
  48773. - 0 0 0 0 0 0 0 0 0 0 0 0
  48774. - 0 0 0 0 0 0 0 0 0 0 0 0
  48775. - 0 0 0 0 0 0 0 0 0 0 0 0
  48776. - 0 0 0 0 0 0 0 0 0 0 0 0
  48777. - 0 0 0 0 0 0 0 0 1 0 0 0
  48778. - 0 0 1 0 0 0 0 0 1 0 0 0
  48779. - 0 0 0 0 0 0 0 0 0 0 0 0
  48780. - 0 0 0 0 0 0 0 0 0 0 0 0
  48781. - 0 0 0 0 0 0 0 0 0 0 0 0
  48782. - 0 0 0 0 0 0 0 0 0 0 0 0
  48783. - 0 0 0 0 0 0 0 0 0 14 14 14
  48784. - 42 42 42 94 94 94 14 14 14 101 101 101
  48785. -128 128 128 2 2 6 18 18 18 116 116 116
  48786. -118 98 46 121 92 8 121 92 8 98 78 10
  48787. -162 162 162 106 106 106 2 2 6 2 2 6
  48788. - 2 2 6 195 195 195 195 195 195 6 6 6
  48789. - 2 2 6 2 2 6 2 2 6 2 2 6
  48790. - 74 74 74 62 62 62 22 22 22 6 6 6
  48791. - 0 0 0 0 0 0 0 0 0 0 0 0
  48792. - 0 0 0 0 0 0 0 0 0 0 0 0
  48793. - 0 0 0 0 0 0 0 0 0 0 0 0
  48794. - 0 0 0 0 0 0 0 0 0 0 0 0
  48795. - 0 0 0 0 0 0 0 0 0 0 0 0
  48796. - 0 0 0 0 0 0 0 0 0 0 0 0
  48797. - 0 0 0 0 0 0 0 0 1 0 0 1
  48798. - 0 0 1 0 0 0 0 0 1 0 0 0
  48799. - 0 0 0 0 0 0 0 0 0 0 0 0
  48800. - 0 0 0 0 0 0 0 0 0 0 0 0
  48801. - 0 0 0 0 0 0 0 0 0 0 0 0
  48802. - 0 0 0 0 0 0 0 0 0 0 0 0
  48803. - 0 0 0 0 0 0 0 0 0 10 10 10
  48804. - 38 38 38 90 90 90 14 14 14 58 58 58
  48805. -210 210 210 26 26 26 54 38 6 154 114 10
  48806. -226 170 11 236 186 11 225 175 15 184 144 12
  48807. -215 174 15 175 146 61 37 26 9 2 2 6
  48808. - 70 70 70 246 246 246 138 138 138 2 2 6
  48809. - 2 2 6 2 2 6 2 2 6 2 2 6
  48810. - 70 70 70 66 66 66 26 26 26 6 6 6
  48811. - 0 0 0 0 0 0 0 0 0 0 0 0
  48812. - 0 0 0 0 0 0 0 0 0 0 0 0
  48813. - 0 0 0 0 0 0 0 0 0 0 0 0
  48814. - 0 0 0 0 0 0 0 0 0 0 0 0
  48815. - 0 0 0 0 0 0 0 0 0 0 0 0
  48816. - 0 0 0 0 0 0 0 0 0 0 0 0
  48817. - 0 0 0 0 0 0 0 0 0 0 0 0
  48818. - 0 0 0 0 0 0 0 0 0 0 0 0
  48819. - 0 0 0 0 0 0 0 0 0 0 0 0
  48820. - 0 0 0 0 0 0 0 0 0 0 0 0
  48821. - 0 0 0 0 0 0 0 0 0 0 0 0
  48822. - 0 0 0 0 0 0 0 0 0 0 0 0
  48823. - 0 0 0 0 0 0 0 0 0 10 10 10
  48824. - 38 38 38 86 86 86 14 14 14 10 10 10
  48825. -195 195 195 188 164 115 192 133 9 225 175 15
  48826. -239 182 13 234 190 10 232 195 16 232 200 30
  48827. -245 207 45 241 208 19 232 195 16 184 144 12
  48828. -218 194 134 211 206 186 42 42 42 2 2 6
  48829. - 2 2 6 2 2 6 2 2 6 2 2 6
  48830. - 50 50 50 74 74 74 30 30 30 6 6 6
  48831. - 0 0 0 0 0 0 0 0 0 0 0 0
  48832. - 0 0 0 0 0 0 0 0 0 0 0 0
  48833. - 0 0 0 0 0 0 0 0 0 0 0 0
  48834. - 0 0 0 0 0 0 0 0 0 0 0 0
  48835. - 0 0 0 0 0 0 0 0 0 0 0 0
  48836. - 0 0 0 0 0 0 0 0 0 0 0 0
  48837. - 0 0 0 0 0 0 0 0 0 0 0 0
  48838. - 0 0 0 0 0 0 0 0 0 0 0 0
  48839. - 0 0 0 0 0 0 0 0 0 0 0 0
  48840. - 0 0 0 0 0 0 0 0 0 0 0 0
  48841. - 0 0 0 0 0 0 0 0 0 0 0 0
  48842. - 0 0 0 0 0 0 0 0 0 0 0 0
  48843. - 0 0 0 0 0 0 0 0 0 10 10 10
  48844. - 34 34 34 86 86 86 14 14 14 2 2 6
  48845. -121 87 25 192 133 9 219 162 10 239 182 13
  48846. -236 186 11 232 195 16 241 208 19 244 214 54
  48847. -246 218 60 246 218 38 246 215 20 241 208 19
  48848. -241 208 19 226 184 13 121 87 25 2 2 6
  48849. - 2 2 6 2 2 6 2 2 6 2 2 6
  48850. - 50 50 50 82 82 82 34 34 34 10 10 10
  48851. - 0 0 0 0 0 0 0 0 0 0 0 0
  48852. - 0 0 0 0 0 0 0 0 0 0 0 0
  48853. - 0 0 0 0 0 0 0 0 0 0 0 0
  48854. - 0 0 0 0 0 0 0 0 0 0 0 0
  48855. - 0 0 0 0 0 0 0 0 0 0 0 0
  48856. - 0 0 0 0 0 0 0 0 0 0 0 0
  48857. - 0 0 0 0 0 0 0 0 0 0 0 0
  48858. - 0 0 0 0 0 0 0 0 0 0 0 0
  48859. - 0 0 0 0 0 0 0 0 0 0 0 0
  48860. - 0 0 0 0 0 0 0 0 0 0 0 0
  48861. - 0 0 0 0 0 0 0 0 0 0 0 0
  48862. - 0 0 0 0 0 0 0 0 0 0 0 0
  48863. - 0 0 0 0 0 0 0 0 0 10 10 10
  48864. - 34 34 34 82 82 82 30 30 30 61 42 6
  48865. -180 123 7 206 145 10 230 174 11 239 182 13
  48866. -234 190 10 238 202 15 241 208 19 246 218 74
  48867. -246 218 38 246 215 20 246 215 20 246 215 20
  48868. -226 184 13 215 174 15 184 144 12 6 6 6
  48869. - 2 2 6 2 2 6 2 2 6 2 2 6
  48870. - 26 26 26 94 94 94 42 42 42 14 14 14
  48871. - 0 0 0 0 0 0 0 0 0 0 0 0
  48872. - 0 0 0 0 0 0 0 0 0 0 0 0
  48873. - 0 0 0 0 0 0 0 0 0 0 0 0
  48874. - 0 0 0 0 0 0 0 0 0 0 0 0
  48875. - 0 0 0 0 0 0 0 0 0 0 0 0
  48876. - 0 0 0 0 0 0 0 0 0 0 0 0
  48877. - 0 0 0 0 0 0 0 0 0 0 0 0
  48878. - 0 0 0 0 0 0 0 0 0 0 0 0
  48879. - 0 0 0 0 0 0 0 0 0 0 0 0
  48880. - 0 0 0 0 0 0 0 0 0 0 0 0
  48881. - 0 0 0 0 0 0 0 0 0 0 0 0
  48882. - 0 0 0 0 0 0 0 0 0 0 0 0
  48883. - 0 0 0 0 0 0 0 0 0 10 10 10
  48884. - 30 30 30 78 78 78 50 50 50 104 69 6
  48885. -192 133 9 216 158 10 236 178 12 236 186 11
  48886. -232 195 16 241 208 19 244 214 54 245 215 43
  48887. -246 215 20 246 215 20 241 208 19 198 155 10
  48888. -200 144 11 216 158 10 156 118 10 2 2 6
  48889. - 2 2 6 2 2 6 2 2 6 2 2 6
  48890. - 6 6 6 90 90 90 54 54 54 18 18 18
  48891. - 6 6 6 0 0 0 0 0 0 0 0 0
  48892. - 0 0 0 0 0 0 0 0 0 0 0 0
  48893. - 0 0 0 0 0 0 0 0 0 0 0 0
  48894. - 0 0 0 0 0 0 0 0 0 0 0 0
  48895. - 0 0 0 0 0 0 0 0 0 0 0 0
  48896. - 0 0 0 0 0 0 0 0 0 0 0 0
  48897. - 0 0 0 0 0 0 0 0 0 0 0 0
  48898. - 0 0 0 0 0 0 0 0 0 0 0 0
  48899. - 0 0 0 0 0 0 0 0 0 0 0 0
  48900. - 0 0 0 0 0 0 0 0 0 0 0 0
  48901. - 0 0 0 0 0 0 0 0 0 0 0 0
  48902. - 0 0 0 0 0 0 0 0 0 0 0 0
  48903. - 0 0 0 0 0 0 0 0 0 10 10 10
  48904. - 30 30 30 78 78 78 46 46 46 22 22 22
  48905. -137 92 6 210 162 10 239 182 13 238 190 10
  48906. -238 202 15 241 208 19 246 215 20 246 215 20
  48907. -241 208 19 203 166 17 185 133 11 210 150 10
  48908. -216 158 10 210 150 10 102 78 10 2 2 6
  48909. - 6 6 6 54 54 54 14 14 14 2 2 6
  48910. - 2 2 6 62 62 62 74 74 74 30 30 30
  48911. - 10 10 10 0 0 0 0 0 0 0 0 0
  48912. - 0 0 0 0 0 0 0 0 0 0 0 0
  48913. - 0 0 0 0 0 0 0 0 0 0 0 0
  48914. - 0 0 0 0 0 0 0 0 0 0 0 0
  48915. - 0 0 0 0 0 0 0 0 0 0 0 0
  48916. - 0 0 0 0 0 0 0 0 0 0 0 0
  48917. - 0 0 0 0 0 0 0 0 0 0 0 0
  48918. - 0 0 0 0 0 0 0 0 0 0 0 0
  48919. - 0 0 0 0 0 0 0 0 0 0 0 0
  48920. - 0 0 0 0 0 0 0 0 0 0 0 0
  48921. - 0 0 0 0 0 0 0 0 0 0 0 0
  48922. - 0 0 0 0 0 0 0 0 0 0 0 0
  48923. - 0 0 0 0 0 0 0 0 0 10 10 10
  48924. - 34 34 34 78 78 78 50 50 50 6 6 6
  48925. - 94 70 30 139 102 15 190 146 13 226 184 13
  48926. -232 200 30 232 195 16 215 174 15 190 146 13
  48927. -168 122 10 192 133 9 210 150 10 213 154 11
  48928. -202 150 34 182 157 106 101 98 89 2 2 6
  48929. - 2 2 6 78 78 78 116 116 116 58 58 58
  48930. - 2 2 6 22 22 22 90 90 90 46 46 46
  48931. - 18 18 18 6 6 6 0 0 0 0 0 0
  48932. - 0 0 0 0 0 0 0 0 0 0 0 0
  48933. - 0 0 0 0 0 0 0 0 0 0 0 0
  48934. - 0 0 0 0 0 0 0 0 0 0 0 0
  48935. - 0 0 0 0 0 0 0 0 0 0 0 0
  48936. - 0 0 0 0 0 0 0 0 0 0 0 0
  48937. - 0 0 0 0 0 0 0 0 0 0 0 0
  48938. - 0 0 0 0 0 0 0 0 0 0 0 0
  48939. - 0 0 0 0 0 0 0 0 0 0 0 0
  48940. - 0 0 0 0 0 0 0 0 0 0 0 0
  48941. - 0 0 0 0 0 0 0 0 0 0 0 0
  48942. - 0 0 0 0 0 0 0 0 0 0 0 0
  48943. - 0 0 0 0 0 0 0 0 0 10 10 10
  48944. - 38 38 38 86 86 86 50 50 50 6 6 6
  48945. -128 128 128 174 154 114 156 107 11 168 122 10
  48946. -198 155 10 184 144 12 197 138 11 200 144 11
  48947. -206 145 10 206 145 10 197 138 11 188 164 115
  48948. -195 195 195 198 198 198 174 174 174 14 14 14
  48949. - 2 2 6 22 22 22 116 116 116 116 116 116
  48950. - 22 22 22 2 2 6 74 74 74 70 70 70
  48951. - 30 30 30 10 10 10 0 0 0 0 0 0
  48952. - 0 0 0 0 0 0 0 0 0 0 0 0
  48953. - 0 0 0 0 0 0 0 0 0 0 0 0
  48954. - 0 0 0 0 0 0 0 0 0 0 0 0
  48955. - 0 0 0 0 0 0 0 0 0 0 0 0
  48956. - 0 0 0 0 0 0 0 0 0 0 0 0
  48957. - 0 0 0 0 0 0 0 0 0 0 0 0
  48958. - 0 0 0 0 0 0 0 0 0 0 0 0
  48959. - 0 0 0 0 0 0 0 0 0 0 0 0
  48960. - 0 0 0 0 0 0 0 0 0 0 0 0
  48961. - 0 0 0 0 0 0 0 0 0 0 0 0
  48962. - 0 0 0 0 0 0 0 0 0 0 0 0
  48963. - 0 0 0 0 0 0 6 6 6 18 18 18
  48964. - 50 50 50 101 101 101 26 26 26 10 10 10
  48965. -138 138 138 190 190 190 174 154 114 156 107 11
  48966. -197 138 11 200 144 11 197 138 11 192 133 9
  48967. -180 123 7 190 142 34 190 178 144 187 187 187
  48968. -202 202 202 221 221 221 214 214 214 66 66 66
  48969. - 2 2 6 2 2 6 50 50 50 62 62 62
  48970. - 6 6 6 2 2 6 10 10 10 90 90 90
  48971. - 50 50 50 18 18 18 6 6 6 0 0 0
  48972. - 0 0 0 0 0 0 0 0 0 0 0 0
  48973. - 0 0 0 0 0 0 0 0 0 0 0 0
  48974. - 0 0 0 0 0 0 0 0 0 0 0 0
  48975. - 0 0 0 0 0 0 0 0 0 0 0 0
  48976. - 0 0 0 0 0 0 0 0 0 0 0 0
  48977. - 0 0 0 0 0 0 0 0 0 0 0 0
  48978. - 0 0 0 0 0 0 0 0 0 0 0 0
  48979. - 0 0 0 0 0 0 0 0 0 0 0 0
  48980. - 0 0 0 0 0 0 0 0 0 0 0 0
  48981. - 0 0 0 0 0 0 0 0 0 0 0 0
  48982. - 0 0 0 0 0 0 0 0 0 0 0 0
  48983. - 0 0 0 0 0 0 10 10 10 34 34 34
  48984. - 74 74 74 74 74 74 2 2 6 6 6 6
  48985. -144 144 144 198 198 198 190 190 190 178 166 146
  48986. -154 121 60 156 107 11 156 107 11 168 124 44
  48987. -174 154 114 187 187 187 190 190 190 210 210 210
  48988. -246 246 246 253 253 253 253 253 253 182 182 182
  48989. - 6 6 6 2 2 6 2 2 6 2 2 6
  48990. - 2 2 6 2 2 6 2 2 6 62 62 62
  48991. - 74 74 74 34 34 34 14 14 14 0 0 0
  48992. - 0 0 0 0 0 0 0 0 0 0 0 0
  48993. - 0 0 0 0 0 0 0 0 0 0 0 0
  48994. - 0 0 0 0 0 0 0 0 0 0 0 0
  48995. - 0 0 0 0 0 0 0 0 0 0 0 0
  48996. - 0 0 0 0 0 0 0 0 0 0 0 0
  48997. - 0 0 0 0 0 0 0 0 0 0 0 0
  48998. - 0 0 0 0 0 0 0 0 0 0 0 0
  48999. - 0 0 0 0 0 0 0 0 0 0 0 0
  49000. - 0 0 0 0 0 0 0 0 0 0 0 0
  49001. - 0 0 0 0 0 0 0 0 0 0 0 0
  49002. - 0 0 0 0 0 0 0 0 0 0 0 0
  49003. - 0 0 0 10 10 10 22 22 22 54 54 54
  49004. - 94 94 94 18 18 18 2 2 6 46 46 46
  49005. -234 234 234 221 221 221 190 190 190 190 190 190
  49006. -190 190 190 187 187 187 187 187 187 190 190 190
  49007. -190 190 190 195 195 195 214 214 214 242 242 242
  49008. -253 253 253 253 253 253 253 253 253 253 253 253
  49009. - 82 82 82 2 2 6 2 2 6 2 2 6
  49010. - 2 2 6 2 2 6 2 2 6 14 14 14
  49011. - 86 86 86 54 54 54 22 22 22 6 6 6
  49012. - 0 0 0 0 0 0 0 0 0 0 0 0
  49013. - 0 0 0 0 0 0 0 0 0 0 0 0
  49014. - 0 0 0 0 0 0 0 0 0 0 0 0
  49015. - 0 0 0 0 0 0 0 0 0 0 0 0
  49016. - 0 0 0 0 0 0 0 0 0 0 0 0
  49017. - 0 0 0 0 0 0 0 0 0 0 0 0
  49018. - 0 0 0 0 0 0 0 0 0 0 0 0
  49019. - 0 0 0 0 0 0 0 0 0 0 0 0
  49020. - 0 0 0 0 0 0 0 0 0 0 0 0
  49021. - 0 0 0 0 0 0 0 0 0 0 0 0
  49022. - 0 0 0 0 0 0 0 0 0 0 0 0
  49023. - 6 6 6 18 18 18 46 46 46 90 90 90
  49024. - 46 46 46 18 18 18 6 6 6 182 182 182
  49025. -253 253 253 246 246 246 206 206 206 190 190 190
  49026. -190 190 190 190 190 190 190 190 190 190 190 190
  49027. -206 206 206 231 231 231 250 250 250 253 253 253
  49028. -253 253 253 253 253 253 253 253 253 253 253 253
  49029. -202 202 202 14 14 14 2 2 6 2 2 6
  49030. - 2 2 6 2 2 6 2 2 6 2 2 6
  49031. - 42 42 42 86 86 86 42 42 42 18 18 18
  49032. - 6 6 6 0 0 0 0 0 0 0 0 0
  49033. - 0 0 0 0 0 0 0 0 0 0 0 0
  49034. - 0 0 0 0 0 0 0 0 0 0 0 0
  49035. - 0 0 0 0 0 0 0 0 0 0 0 0
  49036. - 0 0 0 0 0 0 0 0 0 0 0 0
  49037. - 0 0 0 0 0 0 0 0 0 0 0 0
  49038. - 0 0 0 0 0 0 0 0 0 0 0 0
  49039. - 0 0 0 0 0 0 0 0 0 0 0 0
  49040. - 0 0 0 0 0 0 0 0 0 0 0 0
  49041. - 0 0 0 0 0 0 0 0 0 0 0 0
  49042. - 0 0 0 0 0 0 0 0 0 6 6 6
  49043. - 14 14 14 38 38 38 74 74 74 66 66 66
  49044. - 2 2 6 6 6 6 90 90 90 250 250 250
  49045. -253 253 253 253 253 253 238 238 238 198 198 198
  49046. -190 190 190 190 190 190 195 195 195 221 221 221
  49047. -246 246 246 253 253 253 253 253 253 253 253 253
  49048. -253 253 253 253 253 253 253 253 253 253 253 253
  49049. -253 253 253 82 82 82 2 2 6 2 2 6
  49050. - 2 2 6 2 2 6 2 2 6 2 2 6
  49051. - 2 2 6 78 78 78 70 70 70 34 34 34
  49052. - 14 14 14 6 6 6 0 0 0 0 0 0
  49053. - 0 0 0 0 0 0 0 0 0 0 0 0
  49054. - 0 0 0 0 0 0 0 0 0 0 0 0
  49055. - 0 0 0 0 0 0 0 0 0 0 0 0
  49056. - 0 0 0 0 0 0 0 0 0 0 0 0
  49057. - 0 0 0 0 0 0 0 0 0 0 0 0
  49058. - 0 0 0 0 0 0 0 0 0 0 0 0
  49059. - 0 0 0 0 0 0 0 0 0 0 0 0
  49060. - 0 0 0 0 0 0 0 0 0 0 0 0
  49061. - 0 0 0 0 0 0 0 0 0 0 0 0
  49062. - 0 0 0 0 0 0 0 0 0 14 14 14
  49063. - 34 34 34 66 66 66 78 78 78 6 6 6
  49064. - 2 2 6 18 18 18 218 218 218 253 253 253
  49065. -253 253 253 253 253 253 253 253 253 246 246 246
  49066. -226 226 226 231 231 231 246 246 246 253 253 253
  49067. -253 253 253 253 253 253 253 253 253 253 253 253
  49068. -253 253 253 253 253 253 253 253 253 253 253 253
  49069. -253 253 253 178 178 178 2 2 6 2 2 6
  49070. - 2 2 6 2 2 6 2 2 6 2 2 6
  49071. - 2 2 6 18 18 18 90 90 90 62 62 62
  49072. - 30 30 30 10 10 10 0 0 0 0 0 0
  49073. - 0 0 0 0 0 0 0 0 0 0 0 0
  49074. - 0 0 0 0 0 0 0 0 0 0 0 0
  49075. - 0 0 0 0 0 0 0 0 0 0 0 0
  49076. - 0 0 0 0 0 0 0 0 0 0 0 0
  49077. - 0 0 0 0 0 0 0 0 0 0 0 0
  49078. - 0 0 0 0 0 0 0 0 0 0 0 0
  49079. - 0 0 0 0 0 0 0 0 0 0 0 0
  49080. - 0 0 0 0 0 0 0 0 0 0 0 0
  49081. - 0 0 0 0 0 0 0 0 0 0 0 0
  49082. - 0 0 0 0 0 0 10 10 10 26 26 26
  49083. - 58 58 58 90 90 90 18 18 18 2 2 6
  49084. - 2 2 6 110 110 110 253 253 253 253 253 253
  49085. -253 253 253 253 253 253 253 253 253 253 253 253
  49086. -250 250 250 253 253 253 253 253 253 253 253 253
  49087. -253 253 253 253 253 253 253 253 253 253 253 253
  49088. -253 253 253 253 253 253 253 253 253 253 253 253
  49089. -253 253 253 231 231 231 18 18 18 2 2 6
  49090. - 2 2 6 2 2 6 2 2 6 2 2 6
  49091. - 2 2 6 2 2 6 18 18 18 94 94 94
  49092. - 54 54 54 26 26 26 10 10 10 0 0 0
  49093. - 0 0 0 0 0 0 0 0 0 0 0 0
  49094. - 0 0 0 0 0 0 0 0 0 0 0 0
  49095. - 0 0 0 0 0 0 0 0 0 0 0 0
  49096. - 0 0 0 0 0 0 0 0 0 0 0 0
  49097. - 0 0 0 0 0 0 0 0 0 0 0 0
  49098. - 0 0 0 0 0 0 0 0 0 0 0 0
  49099. - 0 0 0 0 0 0 0 0 0 0 0 0
  49100. - 0 0 0 0 0 0 0 0 0 0 0 0
  49101. - 0 0 0 0 0 0 0 0 0 0 0 0
  49102. - 0 0 0 6 6 6 22 22 22 50 50 50
  49103. - 90 90 90 26 26 26 2 2 6 2 2 6
  49104. - 14 14 14 195 195 195 250 250 250 253 253 253
  49105. -253 253 253 253 253 253 253 253 253 253 253 253
  49106. -253 253 253 253 253 253 253 253 253 253 253 253
  49107. -253 253 253 253 253 253 253 253 253 253 253 253
  49108. -253 253 253 253 253 253 253 253 253 253 253 253
  49109. -250 250 250 242 242 242 54 54 54 2 2 6
  49110. - 2 2 6 2 2 6 2 2 6 2 2 6
  49111. - 2 2 6 2 2 6 2 2 6 38 38 38
  49112. - 86 86 86 50 50 50 22 22 22 6 6 6
  49113. - 0 0 0 0 0 0 0 0 0 0 0 0
  49114. - 0 0 0 0 0 0 0 0 0 0 0 0
  49115. - 0 0 0 0 0 0 0 0 0 0 0 0
  49116. - 0 0 0 0 0 0 0 0 0 0 0 0
  49117. - 0 0 0 0 0 0 0 0 0 0 0 0
  49118. - 0 0 0 0 0 0 0 0 0 0 0 0
  49119. - 0 0 0 0 0 0 0 0 0 0 0 0
  49120. - 0 0 0 0 0 0 0 0 0 0 0 0
  49121. - 0 0 0 0 0 0 0 0 0 0 0 0
  49122. - 6 6 6 14 14 14 38 38 38 82 82 82
  49123. - 34 34 34 2 2 6 2 2 6 2 2 6
  49124. - 42 42 42 195 195 195 246 246 246 253 253 253
  49125. -253 253 253 253 253 253 253 253 253 250 250 250
  49126. -242 242 242 242 242 242 250 250 250 253 253 253
  49127. -253 253 253 253 253 253 253 253 253 253 253 253
  49128. -253 253 253 250 250 250 246 246 246 238 238 238
  49129. -226 226 226 231 231 231 101 101 101 6 6 6
  49130. - 2 2 6 2 2 6 2 2 6 2 2 6
  49131. - 2 2 6 2 2 6 2 2 6 2 2 6
  49132. - 38 38 38 82 82 82 42 42 42 14 14 14
  49133. - 6 6 6 0 0 0 0 0 0 0 0 0
  49134. - 0 0 0 0 0 0 0 0 0 0 0 0
  49135. - 0 0 0 0 0 0 0 0 0 0 0 0
  49136. - 0 0 0 0 0 0 0 0 0 0 0 0
  49137. - 0 0 0 0 0 0 0 0 0 0 0 0
  49138. - 0 0 0 0 0 0 0 0 0 0 0 0
  49139. - 0 0 0 0 0 0 0 0 0 0 0 0
  49140. - 0 0 0 0 0 0 0 0 0 0 0 0
  49141. - 0 0 0 0 0 0 0 0 0 0 0 0
  49142. - 10 10 10 26 26 26 62 62 62 66 66 66
  49143. - 2 2 6 2 2 6 2 2 6 6 6 6
  49144. - 70 70 70 170 170 170 206 206 206 234 234 234
  49145. -246 246 246 250 250 250 250 250 250 238 238 238
  49146. -226 226 226 231 231 231 238 238 238 250 250 250
  49147. -250 250 250 250 250 250 246 246 246 231 231 231
  49148. -214 214 214 206 206 206 202 202 202 202 202 202
  49149. -198 198 198 202 202 202 182 182 182 18 18 18
  49150. - 2 2 6 2 2 6 2 2 6 2 2 6
  49151. - 2 2 6 2 2 6 2 2 6 2 2 6
  49152. - 2 2 6 62 62 62 66 66 66 30 30 30
  49153. - 10 10 10 0 0 0 0 0 0 0 0 0
  49154. - 0 0 0 0 0 0 0 0 0 0 0 0
  49155. - 0 0 0 0 0 0 0 0 0 0 0 0
  49156. - 0 0 0 0 0 0 0 0 0 0 0 0
  49157. - 0 0 0 0 0 0 0 0 0 0 0 0
  49158. - 0 0 0 0 0 0 0 0 0 0 0 0
  49159. - 0 0 0 0 0 0 0 0 0 0 0 0
  49160. - 0 0 0 0 0 0 0 0 0 0 0 0
  49161. - 0 0 0 0 0 0 0 0 0 0 0 0
  49162. - 14 14 14 42 42 42 82 82 82 18 18 18
  49163. - 2 2 6 2 2 6 2 2 6 10 10 10
  49164. - 94 94 94 182 182 182 218 218 218 242 242 242
  49165. -250 250 250 253 253 253 253 253 253 250 250 250
  49166. -234 234 234 253 253 253 253 253 253 253 253 253
  49167. -253 253 253 253 253 253 253 253 253 246 246 246
  49168. -238 238 238 226 226 226 210 210 210 202 202 202
  49169. -195 195 195 195 195 195 210 210 210 158 158 158
  49170. - 6 6 6 14 14 14 50 50 50 14 14 14
  49171. - 2 2 6 2 2 6 2 2 6 2 2 6
  49172. - 2 2 6 6 6 6 86 86 86 46 46 46
  49173. - 18 18 18 6 6 6 0 0 0 0 0 0
  49174. - 0 0 0 0 0 0 0 0 0 0 0 0
  49175. - 0 0 0 0 0 0 0 0 0 0 0 0
  49176. - 0 0 0 0 0 0 0 0 0 0 0 0
  49177. - 0 0 0 0 0 0 0 0 0 0 0 0
  49178. - 0 0 0 0 0 0 0 0 0 0 0 0
  49179. - 0 0 0 0 0 0 0 0 0 0 0 0
  49180. - 0 0 0 0 0 0 0 0 0 0 0 0
  49181. - 0 0 0 0 0 0 0 0 0 6 6 6
  49182. - 22 22 22 54 54 54 70 70 70 2 2 6
  49183. - 2 2 6 10 10 10 2 2 6 22 22 22
  49184. -166 166 166 231 231 231 250 250 250 253 253 253
  49185. -253 253 253 253 253 253 253 253 253 250 250 250
  49186. -242 242 242 253 253 253 253 253 253 253 253 253
  49187. -253 253 253 253 253 253 253 253 253 253 253 253
  49188. -253 253 253 253 253 253 253 253 253 246 246 246
  49189. -231 231 231 206 206 206 198 198 198 226 226 226
  49190. - 94 94 94 2 2 6 6 6 6 38 38 38
  49191. - 30 30 30 2 2 6 2 2 6 2 2 6
  49192. - 2 2 6 2 2 6 62 62 62 66 66 66
  49193. - 26 26 26 10 10 10 0 0 0 0 0 0
  49194. - 0 0 0 0 0 0 0 0 0 0 0 0
  49195. - 0 0 0 0 0 0 0 0 0 0 0 0
  49196. - 0 0 0 0 0 0 0 0 0 0 0 0
  49197. - 0 0 0 0 0 0 0 0 0 0 0 0
  49198. - 0 0 0 0 0 0 0 0 0 0 0 0
  49199. - 0 0 0 0 0 0 0 0 0 0 0 0
  49200. - 0 0 0 0 0 0 0 0 0 0 0 0
  49201. - 0 0 0 0 0 0 0 0 0 10 10 10
  49202. - 30 30 30 74 74 74 50 50 50 2 2 6
  49203. - 26 26 26 26 26 26 2 2 6 106 106 106
  49204. -238 238 238 253 253 253 253 253 253 253 253 253
  49205. -253 253 253 253 253 253 253 253 253 253 253 253
  49206. -253 253 253 253 253 253 253 253 253 253 253 253
  49207. -253 253 253 253 253 253 253 253 253 253 253 253
  49208. -253 253 253 253 253 253 253 253 253 253 253 253
  49209. -253 253 253 246 246 246 218 218 218 202 202 202
  49210. -210 210 210 14 14 14 2 2 6 2 2 6
  49211. - 30 30 30 22 22 22 2 2 6 2 2 6
  49212. - 2 2 6 2 2 6 18 18 18 86 86 86
  49213. - 42 42 42 14 14 14 0 0 0 0 0 0
  49214. - 0 0 0 0 0 0 0 0 0 0 0 0
  49215. - 0 0 0 0 0 0 0 0 0 0 0 0
  49216. - 0 0 0 0 0 0 0 0 0 0 0 0
  49217. - 0 0 0 0 0 0 0 0 0 0 0 0
  49218. - 0 0 0 0 0 0 0 0 0 0 0 0
  49219. - 0 0 0 0 0 0 0 0 0 0 0 0
  49220. - 0 0 0 0 0 0 0 0 0 0 0 0
  49221. - 0 0 0 0 0 0 0 0 0 14 14 14
  49222. - 42 42 42 90 90 90 22 22 22 2 2 6
  49223. - 42 42 42 2 2 6 18 18 18 218 218 218
  49224. -253 253 253 253 253 253 253 253 253 253 253 253
  49225. -253 253 253 253 253 253 253 253 253 253 253 253
  49226. -253 253 253 253 253 253 253 253 253 253 253 253
  49227. -253 253 253 253 253 253 253 253 253 253 253 253
  49228. -253 253 253 253 253 253 253 253 253 253 253 253
  49229. -253 253 253 253 253 253 250 250 250 221 221 221
  49230. -218 218 218 101 101 101 2 2 6 14 14 14
  49231. - 18 18 18 38 38 38 10 10 10 2 2 6
  49232. - 2 2 6 2 2 6 2 2 6 78 78 78
  49233. - 58 58 58 22 22 22 6 6 6 0 0 0
  49234. - 0 0 0 0 0 0 0 0 0 0 0 0
  49235. - 0 0 0 0 0 0 0 0 0 0 0 0
  49236. - 0 0 0 0 0 0 0 0 0 0 0 0
  49237. - 0 0 0 0 0 0 0 0 0 0 0 0
  49238. - 0 0 0 0 0 0 0 0 0 0 0 0
  49239. - 0 0 0 0 0 0 0 0 0 0 0 0
  49240. - 0 0 0 0 0 0 0 0 0 0 0 0
  49241. - 0 0 0 0 0 0 6 6 6 18 18 18
  49242. - 54 54 54 82 82 82 2 2 6 26 26 26
  49243. - 22 22 22 2 2 6 123 123 123 253 253 253
  49244. -253 253 253 253 253 253 253 253 253 253 253 253
  49245. -253 253 253 253 253 253 253 253 253 253 253 253
  49246. -253 253 253 253 253 253 253 253 253 253 253 253
  49247. -253 253 253 253 253 253 253 253 253 253 253 253
  49248. -253 253 253 253 253 253 253 253 253 253 253 253
  49249. -253 253 253 253 253 253 253 253 253 250 250 250
  49250. -238 238 238 198 198 198 6 6 6 38 38 38
  49251. - 58 58 58 26 26 26 38 38 38 2 2 6
  49252. - 2 2 6 2 2 6 2 2 6 46 46 46
  49253. - 78 78 78 30 30 30 10 10 10 0 0 0
  49254. - 0 0 0 0 0 0 0 0 0 0 0 0
  49255. - 0 0 0 0 0 0 0 0 0 0 0 0
  49256. - 0 0 0 0 0 0 0 0 0 0 0 0
  49257. - 0 0 0 0 0 0 0 0 0 0 0 0
  49258. - 0 0 0 0 0 0 0 0 0 0 0 0
  49259. - 0 0 0 0 0 0 0 0 0 0 0 0
  49260. - 0 0 0 0 0 0 0 0 0 0 0 0
  49261. - 0 0 0 0 0 0 10 10 10 30 30 30
  49262. - 74 74 74 58 58 58 2 2 6 42 42 42
  49263. - 2 2 6 22 22 22 231 231 231 253 253 253
  49264. -253 253 253 253 253 253 253 253 253 253 253 253
  49265. -253 253 253 253 253 253 253 253 253 250 250 250
  49266. -253 253 253 253 253 253 253 253 253 253 253 253
  49267. -253 253 253 253 253 253 253 253 253 253 253 253
  49268. -253 253 253 253 253 253 253 253 253 253 253 253
  49269. -253 253 253 253 253 253 253 253 253 253 253 253
  49270. -253 253 253 246 246 246 46 46 46 38 38 38
  49271. - 42 42 42 14 14 14 38 38 38 14 14 14
  49272. - 2 2 6 2 2 6 2 2 6 6 6 6
  49273. - 86 86 86 46 46 46 14 14 14 0 0 0
  49274. - 0 0 0 0 0 0 0 0 0 0 0 0
  49275. - 0 0 0 0 0 0 0 0 0 0 0 0
  49276. - 0 0 0 0 0 0 0 0 0 0 0 0
  49277. - 0 0 0 0 0 0 0 0 0 0 0 0
  49278. - 0 0 0 0 0 0 0 0 0 0 0 0
  49279. - 0 0 0 0 0 0 0 0 0 0 0 0
  49280. - 0 0 0 0 0 0 0 0 0 0 0 0
  49281. - 0 0 0 6 6 6 14 14 14 42 42 42
  49282. - 90 90 90 18 18 18 18 18 18 26 26 26
  49283. - 2 2 6 116 116 116 253 253 253 253 253 253
  49284. -253 253 253 253 253 253 253 253 253 253 253 253
  49285. -253 253 253 253 253 253 250 250 250 238 238 238
  49286. -253 253 253 253 253 253 253 253 253 253 253 253
  49287. -253 253 253 253 253 253 253 253 253 253 253 253
  49288. -253 253 253 253 253 253 253 253 253 253 253 253
  49289. -253 253 253 253 253 253 253 253 253 253 253 253
  49290. -253 253 253 253 253 253 94 94 94 6 6 6
  49291. - 2 2 6 2 2 6 10 10 10 34 34 34
  49292. - 2 2 6 2 2 6 2 2 6 2 2 6
  49293. - 74 74 74 58 58 58 22 22 22 6 6 6
  49294. - 0 0 0 0 0 0 0 0 0 0 0 0
  49295. - 0 0 0 0 0 0 0 0 0 0 0 0
  49296. - 0 0 0 0 0 0 0 0 0 0 0 0
  49297. - 0 0 0 0 0 0 0 0 0 0 0 0
  49298. - 0 0 0 0 0 0 0 0 0 0 0 0
  49299. - 0 0 0 0 0 0 0 0 0 0 0 0
  49300. - 0 0 0 0 0 0 0 0 0 0 0 0
  49301. - 0 0 0 10 10 10 26 26 26 66 66 66
  49302. - 82 82 82 2 2 6 38 38 38 6 6 6
  49303. - 14 14 14 210 210 210 253 253 253 253 253 253
  49304. -253 253 253 253 253 253 253 253 253 253 253 253
  49305. -253 253 253 253 253 253 246 246 246 242 242 242
  49306. -253 253 253 253 253 253 253 253 253 253 253 253
  49307. -253 253 253 253 253 253 253 253 253 253 253 253
  49308. -253 253 253 253 253 253 253 253 253 253 253 253
  49309. -253 253 253 253 253 253 253 253 253 253 253 253
  49310. -253 253 253 253 253 253 144 144 144 2 2 6
  49311. - 2 2 6 2 2 6 2 2 6 46 46 46
  49312. - 2 2 6 2 2 6 2 2 6 2 2 6
  49313. - 42 42 42 74 74 74 30 30 30 10 10 10
  49314. - 0 0 0 0 0 0 0 0 0 0 0 0
  49315. - 0 0 0 0 0 0 0 0 0 0 0 0
  49316. - 0 0 0 0 0 0 0 0 0 0 0 0
  49317. - 0 0 0 0 0 0 0 0 0 0 0 0
  49318. - 0 0 0 0 0 0 0 0 0 0 0 0
  49319. - 0 0 0 0 0 0 0 0 0 0 0 0
  49320. - 0 0 0 0 0 0 0 0 0 0 0 0
  49321. - 6 6 6 14 14 14 42 42 42 90 90 90
  49322. - 26 26 26 6 6 6 42 42 42 2 2 6
  49323. - 74 74 74 250 250 250 253 253 253 253 253 253
  49324. -253 253 253 253 253 253 253 253 253 253 253 253
  49325. -253 253 253 253 253 253 242 242 242 242 242 242
  49326. -253 253 253 253 253 253 253 253 253 253 253 253
  49327. -253 253 253 253 253 253 253 253 253 253 253 253
  49328. -253 253 253 253 253 253 253 253 253 253 253 253
  49329. -253 253 253 253 253 253 253 253 253 253 253 253
  49330. -253 253 253 253 253 253 182 182 182 2 2 6
  49331. - 2 2 6 2 2 6 2 2 6 46 46 46
  49332. - 2 2 6 2 2 6 2 2 6 2 2 6
  49333. - 10 10 10 86 86 86 38 38 38 10 10 10
  49334. - 0 0 0 0 0 0 0 0 0 0 0 0
  49335. - 0 0 0 0 0 0 0 0 0 0 0 0
  49336. - 0 0 0 0 0 0 0 0 0 0 0 0
  49337. - 0 0 0 0 0 0 0 0 0 0 0 0
  49338. - 0 0 0 0 0 0 0 0 0 0 0 0
  49339. - 0 0 0 0 0 0 0 0 0 0 0 0
  49340. - 0 0 0 0 0 0 0 0 0 0 0 0
  49341. - 10 10 10 26 26 26 66 66 66 82 82 82
  49342. - 2 2 6 22 22 22 18 18 18 2 2 6
  49343. -149 149 149 253 253 253 253 253 253 253 253 253
  49344. -253 253 253 253 253 253 253 253 253 253 253 253
  49345. -253 253 253 253 253 253 234 234 234 242 242 242
  49346. -253 253 253 253 253 253 253 253 253 253 253 253
  49347. -253 253 253 253 253 253 253 253 253 253 253 253
  49348. -253 253 253 253 253 253 253 253 253 253 253 253
  49349. -253 253 253 253 253 253 253 253 253 253 253 253
  49350. -253 253 253 253 253 253 206 206 206 2 2 6
  49351. - 2 2 6 2 2 6 2 2 6 38 38 38
  49352. - 2 2 6 2 2 6 2 2 6 2 2 6
  49353. - 6 6 6 86 86 86 46 46 46 14 14 14
  49354. - 0 0 0 0 0 0 0 0 0 0 0 0
  49355. - 0 0 0 0 0 0 0 0 0 0 0 0
  49356. - 0 0 0 0 0 0 0 0 0 0 0 0
  49357. - 0 0 0 0 0 0 0 0 0 0 0 0
  49358. - 0 0 0 0 0 0 0 0 0 0 0 0
  49359. - 0 0 0 0 0 0 0 0 0 0 0 0
  49360. - 0 0 0 0 0 0 0 0 0 6 6 6
  49361. - 18 18 18 46 46 46 86 86 86 18 18 18
  49362. - 2 2 6 34 34 34 10 10 10 6 6 6
  49363. -210 210 210 253 253 253 253 253 253 253 253 253
  49364. -253 253 253 253 253 253 253 253 253 253 253 253
  49365. -253 253 253 253 253 253 234 234 234 242 242 242
  49366. -253 253 253 253 253 253 253 253 253 253 253 253
  49367. -253 253 253 253 253 253 253 253 253 253 253 253
  49368. -253 253 253 253 253 253 253 253 253 253 253 253
  49369. -253 253 253 253 253 253 253 253 253 253 253 253
  49370. -253 253 253 253 253 253 221 221 221 6 6 6
  49371. - 2 2 6 2 2 6 6 6 6 30 30 30
  49372. - 2 2 6 2 2 6 2 2 6 2 2 6
  49373. - 2 2 6 82 82 82 54 54 54 18 18 18
  49374. - 6 6 6 0 0 0 0 0 0 0 0 0
  49375. - 0 0 0 0 0 0 0 0 0 0 0 0
  49376. - 0 0 0 0 0 0 0 0 0 0 0 0
  49377. - 0 0 0 0 0 0 0 0 0 0 0 0
  49378. - 0 0 0 0 0 0 0 0 0 0 0 0
  49379. - 0 0 0 0 0 0 0 0 0 0 0 0
  49380. - 0 0 0 0 0 0 0 0 0 10 10 10
  49381. - 26 26 26 66 66 66 62 62 62 2 2 6
  49382. - 2 2 6 38 38 38 10 10 10 26 26 26
  49383. -238 238 238 253 253 253 253 253 253 253 253 253
  49384. -253 253 253 253 253 253 253 253 253 253 253 253
  49385. -253 253 253 253 253 253 231 231 231 238 238 238
  49386. -253 253 253 253 253 253 253 253 253 253 253 253
  49387. -253 253 253 253 253 253 253 253 253 253 253 253
  49388. -253 253 253 253 253 253 253 253 253 253 253 253
  49389. -253 253 253 253 253 253 253 253 253 253 253 253
  49390. -253 253 253 253 253 253 231 231 231 6 6 6
  49391. - 2 2 6 2 2 6 10 10 10 30 30 30
  49392. - 2 2 6 2 2 6 2 2 6 2 2 6
  49393. - 2 2 6 66 66 66 58 58 58 22 22 22
  49394. - 6 6 6 0 0 0 0 0 0 0 0 0
  49395. - 0 0 0 0 0 0 0 0 0 0 0 0
  49396. - 0 0 0 0 0 0 0 0 0 0 0 0
  49397. - 0 0 0 0 0 0 0 0 0 0 0 0
  49398. - 0 0 0 0 0 0 0 0 0 0 0 0
  49399. - 0 0 0 0 0 0 0 0 0 0 0 0
  49400. - 0 0 0 0 0 0 0 0 0 10 10 10
  49401. - 38 38 38 78 78 78 6 6 6 2 2 6
  49402. - 2 2 6 46 46 46 14 14 14 42 42 42
  49403. -246 246 246 253 253 253 253 253 253 253 253 253
  49404. -253 253 253 253 253 253 253 253 253 253 253 253
  49405. -253 253 253 253 253 253 231 231 231 242 242 242
  49406. -253 253 253 253 253 253 253 253 253 253 253 253
  49407. -253 253 253 253 253 253 253 253 253 253 253 253
  49408. -253 253 253 253 253 253 253 253 253 253 253 253
  49409. -253 253 253 253 253 253 253 253 253 253 253 253
  49410. -253 253 253 253 253 253 234 234 234 10 10 10
  49411. - 2 2 6 2 2 6 22 22 22 14 14 14
  49412. - 2 2 6 2 2 6 2 2 6 2 2 6
  49413. - 2 2 6 66 66 66 62 62 62 22 22 22
  49414. - 6 6 6 0 0 0 0 0 0 0 0 0
  49415. - 0 0 0 0 0 0 0 0 0 0 0 0
  49416. - 0 0 0 0 0 0 0 0 0 0 0 0
  49417. - 0 0 0 0 0 0 0 0 0 0 0 0
  49418. - 0 0 0 0 0 0 0 0 0 0 0 0
  49419. - 0 0 0 0 0 0 0 0 0 0 0 0
  49420. - 0 0 0 0 0 0 6 6 6 18 18 18
  49421. - 50 50 50 74 74 74 2 2 6 2 2 6
  49422. - 14 14 14 70 70 70 34 34 34 62 62 62
  49423. -250 250 250 253 253 253 253 253 253 253 253 253
  49424. -253 253 253 253 253 253 253 253 253 253 253 253
  49425. -253 253 253 253 253 253 231 231 231 246 246 246
  49426. -253 253 253 253 253 253 253 253 253 253 253 253
  49427. -253 253 253 253 253 253 253 253 253 253 253 253
  49428. -253 253 253 253 253 253 253 253 253 253 253 253
  49429. -253 253 253 253 253 253 253 253 253 253 253 253
  49430. -253 253 253 253 253 253 234 234 234 14 14 14
  49431. - 2 2 6 2 2 6 30 30 30 2 2 6
  49432. - 2 2 6 2 2 6 2 2 6 2 2 6
  49433. - 2 2 6 66 66 66 62 62 62 22 22 22
  49434. - 6 6 6 0 0 0 0 0 0 0 0 0
  49435. - 0 0 0 0 0 0 0 0 0 0 0 0
  49436. - 0 0 0 0 0 0 0 0 0 0 0 0
  49437. - 0 0 0 0 0 0 0 0 0 0 0 0
  49438. - 0 0 0 0 0 0 0 0 0 0 0 0
  49439. - 0 0 0 0 0 0 0 0 0 0 0 0
  49440. - 0 0 0 0 0 0 6 6 6 18 18 18
  49441. - 54 54 54 62 62 62 2 2 6 2 2 6
  49442. - 2 2 6 30 30 30 46 46 46 70 70 70
  49443. -250 250 250 253 253 253 253 253 253 253 253 253
  49444. -253 253 253 253 253 253 253 253 253 253 253 253
  49445. -253 253 253 253 253 253 231 231 231 246 246 246
  49446. -253 253 253 253 253 253 253 253 253 253 253 253
  49447. -253 253 253 253 253 253 253 253 253 253 253 253
  49448. -253 253 253 253 253 253 253 253 253 253 253 253
  49449. -253 253 253 253 253 253 253 253 253 253 253 253
  49450. -253 253 253 253 253 253 226 226 226 10 10 10
  49451. - 2 2 6 6 6 6 30 30 30 2 2 6
  49452. - 2 2 6 2 2 6 2 2 6 2 2 6
  49453. - 2 2 6 66 66 66 58 58 58 22 22 22
  49454. - 6 6 6 0 0 0 0 0 0 0 0 0
  49455. - 0 0 0 0 0 0 0 0 0 0 0 0
  49456. - 0 0 0 0 0 0 0 0 0 0 0 0
  49457. - 0 0 0 0 0 0 0 0 0 0 0 0
  49458. - 0 0 0 0 0 0 0 0 0 0 0 0
  49459. - 0 0 0 0 0 0 0 0 0 0 0 0
  49460. - 0 0 0 0 0 0 6 6 6 22 22 22
  49461. - 58 58 58 62 62 62 2 2 6 2 2 6
  49462. - 2 2 6 2 2 6 30 30 30 78 78 78
  49463. -250 250 250 253 253 253 253 253 253 253 253 253
  49464. -253 253 253 253 253 253 253 253 253 253 253 253
  49465. -253 253 253 253 253 253 231 231 231 246 246 246
  49466. -253 253 253 253 253 253 253 253 253 253 253 253
  49467. -253 253 253 253 253 253 253 253 253 253 253 253
  49468. -253 253 253 253 253 253 253 253 253 253 253 253
  49469. -253 253 253 253 253 253 253 253 253 253 253 253
  49470. -253 253 253 253 253 253 206 206 206 2 2 6
  49471. - 22 22 22 34 34 34 18 14 6 22 22 22
  49472. - 26 26 26 18 18 18 6 6 6 2 2 6
  49473. - 2 2 6 82 82 82 54 54 54 18 18 18
  49474. - 6 6 6 0 0 0 0 0 0 0 0 0
  49475. - 0 0 0 0 0 0 0 0 0 0 0 0
  49476. - 0 0 0 0 0 0 0 0 0 0 0 0
  49477. - 0 0 0 0 0 0 0 0 0 0 0 0
  49478. - 0 0 0 0 0 0 0 0 0 0 0 0
  49479. - 0 0 0 0 0 0 0 0 0 0 0 0
  49480. - 0 0 0 0 0 0 6 6 6 26 26 26
  49481. - 62 62 62 106 106 106 74 54 14 185 133 11
  49482. -210 162 10 121 92 8 6 6 6 62 62 62
  49483. -238 238 238 253 253 253 253 253 253 253 253 253
  49484. -253 253 253 253 253 253 253 253 253 253 253 253
  49485. -253 253 253 253 253 253 231 231 231 246 246 246
  49486. -253 253 253 253 253 253 253 253 253 253 253 253
  49487. -253 253 253 253 253 253 253 253 253 253 253 253
  49488. -253 253 253 253 253 253 253 253 253 253 253 253
  49489. -253 253 253 253 253 253 253 253 253 253 253 253
  49490. -253 253 253 253 253 253 158 158 158 18 18 18
  49491. - 14 14 14 2 2 6 2 2 6 2 2 6
  49492. - 6 6 6 18 18 18 66 66 66 38 38 38
  49493. - 6 6 6 94 94 94 50 50 50 18 18 18
  49494. - 6 6 6 0 0 0 0 0 0 0 0 0
  49495. - 0 0 0 0 0 0 0 0 0 0 0 0
  49496. - 0 0 0 0 0 0 0 0 0 0 0 0
  49497. - 0 0 0 0 0 0 0 0 0 0 0 0
  49498. - 0 0 0 0 0 0 0 0 0 0 0 0
  49499. - 0 0 0 0 0 0 0 0 0 6 6 6
  49500. - 10 10 10 10 10 10 18 18 18 38 38 38
  49501. - 78 78 78 142 134 106 216 158 10 242 186 14
  49502. -246 190 14 246 190 14 156 118 10 10 10 10
  49503. - 90 90 90 238 238 238 253 253 253 253 253 253
  49504. -253 253 253 253 253 253 253 253 253 253 253 253
  49505. -253 253 253 253 253 253 231 231 231 250 250 250
  49506. -253 253 253 253 253 253 253 253 253 253 253 253
  49507. -253 253 253 253 253 253 253 253 253 253 253 253
  49508. -253 253 253 253 253 253 253 253 253 253 253 253
  49509. -253 253 253 253 253 253 253 253 253 246 230 190
  49510. -238 204 91 238 204 91 181 142 44 37 26 9
  49511. - 2 2 6 2 2 6 2 2 6 2 2 6
  49512. - 2 2 6 2 2 6 38 38 38 46 46 46
  49513. - 26 26 26 106 106 106 54 54 54 18 18 18
  49514. - 6 6 6 0 0 0 0 0 0 0 0 0
  49515. - 0 0 0 0 0 0 0 0 0 0 0 0
  49516. - 0 0 0 0 0 0 0 0 0 0 0 0
  49517. - 0 0 0 0 0 0 0 0 0 0 0 0
  49518. - 0 0 0 0 0 0 0 0 0 0 0 0
  49519. - 0 0 0 6 6 6 14 14 14 22 22 22
  49520. - 30 30 30 38 38 38 50 50 50 70 70 70
  49521. -106 106 106 190 142 34 226 170 11 242 186 14
  49522. -246 190 14 246 190 14 246 190 14 154 114 10
  49523. - 6 6 6 74 74 74 226 226 226 253 253 253
  49524. -253 253 253 253 253 253 253 253 253 253 253 253
  49525. -253 253 253 253 253 253 231 231 231 250 250 250
  49526. -253 253 253 253 253 253 253 253 253 253 253 253
  49527. -253 253 253 253 253 253 253 253 253 253 253 253
  49528. -253 253 253 253 253 253 253 253 253 253 253 253
  49529. -253 253 253 253 253 253 253 253 253 228 184 62
  49530. -241 196 14 241 208 19 232 195 16 38 30 10
  49531. - 2 2 6 2 2 6 2 2 6 2 2 6
  49532. - 2 2 6 6 6 6 30 30 30 26 26 26
  49533. -203 166 17 154 142 90 66 66 66 26 26 26
  49534. - 6 6 6 0 0 0 0 0 0 0 0 0
  49535. - 0 0 0 0 0 0 0 0 0 0 0 0
  49536. - 0 0 0 0 0 0 0 0 0 0 0 0
  49537. - 0 0 0 0 0 0 0 0 0 0 0 0
  49538. - 0 0 0 0 0 0 0 0 0 0 0 0
  49539. - 6 6 6 18 18 18 38 38 38 58 58 58
  49540. - 78 78 78 86 86 86 101 101 101 123 123 123
  49541. -175 146 61 210 150 10 234 174 13 246 186 14
  49542. -246 190 14 246 190 14 246 190 14 238 190 10
  49543. -102 78 10 2 2 6 46 46 46 198 198 198
  49544. -253 253 253 253 253 253 253 253 253 253 253 253
  49545. -253 253 253 253 253 253 234 234 234 242 242 242
  49546. -253 253 253 253 253 253 253 253 253 253 253 253
  49547. -253 253 253 253 253 253 253 253 253 253 253 253
  49548. -253 253 253 253 253 253 253 253 253 253 253 253
  49549. -253 253 253 253 253 253 253 253 253 224 178 62
  49550. -242 186 14 241 196 14 210 166 10 22 18 6
  49551. - 2 2 6 2 2 6 2 2 6 2 2 6
  49552. - 2 2 6 2 2 6 6 6 6 121 92 8
  49553. -238 202 15 232 195 16 82 82 82 34 34 34
  49554. - 10 10 10 0 0 0 0 0 0 0 0 0
  49555. - 0 0 0 0 0 0 0 0 0 0 0 0
  49556. - 0 0 0 0 0 0 0 0 0 0 0 0
  49557. - 0 0 0 0 0 0 0 0 0 0 0 0
  49558. - 0 0 0 0 0 0 0 0 0 0 0 0
  49559. - 14 14 14 38 38 38 70 70 70 154 122 46
  49560. -190 142 34 200 144 11 197 138 11 197 138 11
  49561. -213 154 11 226 170 11 242 186 14 246 190 14
  49562. -246 190 14 246 190 14 246 190 14 246 190 14
  49563. -225 175 15 46 32 6 2 2 6 22 22 22
  49564. -158 158 158 250 250 250 253 253 253 253 253 253
  49565. -253 253 253 253 253 253 253 253 253 253 253 253
  49566. -253 253 253 253 253 253 253 253 253 253 253 253
  49567. -253 253 253 253 253 253 253 253 253 253 253 253
  49568. -253 253 253 253 253 253 253 253 253 253 253 253
  49569. -253 253 253 250 250 250 242 242 242 224 178 62
  49570. -239 182 13 236 186 11 213 154 11 46 32 6
  49571. - 2 2 6 2 2 6 2 2 6 2 2 6
  49572. - 2 2 6 2 2 6 61 42 6 225 175 15
  49573. -238 190 10 236 186 11 112 100 78 42 42 42
  49574. - 14 14 14 0 0 0 0 0 0 0 0 0
  49575. - 0 0 0 0 0 0 0 0 0 0 0 0
  49576. - 0 0 0 0 0 0 0 0 0 0 0 0
  49577. - 0 0 0 0 0 0 0 0 0 0 0 0
  49578. - 0 0 0 0 0 0 0 0 0 6 6 6
  49579. - 22 22 22 54 54 54 154 122 46 213 154 11
  49580. -226 170 11 230 174 11 226 170 11 226 170 11
  49581. -236 178 12 242 186 14 246 190 14 246 190 14
  49582. -246 190 14 246 190 14 246 190 14 246 190 14
  49583. -241 196 14 184 144 12 10 10 10 2 2 6
  49584. - 6 6 6 116 116 116 242 242 242 253 253 253
  49585. -253 253 253 253 253 253 253 253 253 253 253 253
  49586. -253 253 253 253 253 253 253 253 253 253 253 253
  49587. -253 253 253 253 253 253 253 253 253 253 253 253
  49588. -253 253 253 253 253 253 253 253 253 253 253 253
  49589. -253 253 253 231 231 231 198 198 198 214 170 54
  49590. -236 178 12 236 178 12 210 150 10 137 92 6
  49591. - 18 14 6 2 2 6 2 2 6 2 2 6
  49592. - 6 6 6 70 47 6 200 144 11 236 178 12
  49593. -239 182 13 239 182 13 124 112 88 58 58 58
  49594. - 22 22 22 6 6 6 0 0 0 0 0 0
  49595. - 0 0 0 0 0 0 0 0 0 0 0 0
  49596. - 0 0 0 0 0 0 0 0 0 0 0 0
  49597. - 0 0 0 0 0 0 0 0 0 0 0 0
  49598. - 0 0 0 0 0 0 0 0 0 10 10 10
  49599. - 30 30 30 70 70 70 180 133 36 226 170 11
  49600. -239 182 13 242 186 14 242 186 14 246 186 14
  49601. -246 190 14 246 190 14 246 190 14 246 190 14
  49602. -246 190 14 246 190 14 246 190 14 246 190 14
  49603. -246 190 14 232 195 16 98 70 6 2 2 6
  49604. - 2 2 6 2 2 6 66 66 66 221 221 221
  49605. -253 253 253 253 253 253 253 253 253 253 253 253
  49606. -253 253 253 253 253 253 253 253 253 253 253 253
  49607. -253 253 253 253 253 253 253 253 253 253 253 253
  49608. -253 253 253 253 253 253 253 253 253 253 253 253
  49609. -253 253 253 206 206 206 198 198 198 214 166 58
  49610. -230 174 11 230 174 11 216 158 10 192 133 9
  49611. -163 110 8 116 81 8 102 78 10 116 81 8
  49612. -167 114 7 197 138 11 226 170 11 239 182 13
  49613. -242 186 14 242 186 14 162 146 94 78 78 78
  49614. - 34 34 34 14 14 14 6 6 6 0 0 0
  49615. - 0 0 0 0 0 0 0 0 0 0 0 0
  49616. - 0 0 0 0 0 0 0 0 0 0 0 0
  49617. - 0 0 0 0 0 0 0 0 0 0 0 0
  49618. - 0 0 0 0 0 0 0 0 0 6 6 6
  49619. - 30 30 30 78 78 78 190 142 34 226 170 11
  49620. -239 182 13 246 190 14 246 190 14 246 190 14
  49621. -246 190 14 246 190 14 246 190 14 246 190 14
  49622. -246 190 14 246 190 14 246 190 14 246 190 14
  49623. -246 190 14 241 196 14 203 166 17 22 18 6
  49624. - 2 2 6 2 2 6 2 2 6 38 38 38
  49625. -218 218 218 253 253 253 253 253 253 253 253 253
  49626. -253 253 253 253 253 253 253 253 253 253 253 253
  49627. -253 253 253 253 253 253 253 253 253 253 253 253
  49628. -253 253 253 253 253 253 253 253 253 253 253 253
  49629. -250 250 250 206 206 206 198 198 198 202 162 69
  49630. -226 170 11 236 178 12 224 166 10 210 150 10
  49631. -200 144 11 197 138 11 192 133 9 197 138 11
  49632. -210 150 10 226 170 11 242 186 14 246 190 14
  49633. -246 190 14 246 186 14 225 175 15 124 112 88
  49634. - 62 62 62 30 30 30 14 14 14 6 6 6
  49635. - 0 0 0 0 0 0 0 0 0 0 0 0
  49636. - 0 0 0 0 0 0 0 0 0 0 0 0
  49637. - 0 0 0 0 0 0 0 0 0 0 0 0
  49638. - 0 0 0 0 0 0 0 0 0 10 10 10
  49639. - 30 30 30 78 78 78 174 135 50 224 166 10
  49640. -239 182 13 246 190 14 246 190 14 246 190 14
  49641. -246 190 14 246 190 14 246 190 14 246 190 14
  49642. -246 190 14 246 190 14 246 190 14 246 190 14
  49643. -246 190 14 246 190 14 241 196 14 139 102 15
  49644. - 2 2 6 2 2 6 2 2 6 2 2 6
  49645. - 78 78 78 250 250 250 253 253 253 253 253 253
  49646. -253 253 253 253 253 253 253 253 253 253 253 253
  49647. -253 253 253 253 253 253 253 253 253 253 253 253
  49648. -253 253 253 253 253 253 253 253 253 253 253 253
  49649. -250 250 250 214 214 214 198 198 198 190 150 46
  49650. -219 162 10 236 178 12 234 174 13 224 166 10
  49651. -216 158 10 213 154 11 213 154 11 216 158 10
  49652. -226 170 11 239 182 13 246 190 14 246 190 14
  49653. -246 190 14 246 190 14 242 186 14 206 162 42
  49654. -101 101 101 58 58 58 30 30 30 14 14 14
  49655. - 6 6 6 0 0 0 0 0 0 0 0 0
  49656. - 0 0 0 0 0 0 0 0 0 0 0 0
  49657. - 0 0 0 0 0 0 0 0 0 0 0 0
  49658. - 0 0 0 0 0 0 0 0 0 10 10 10
  49659. - 30 30 30 74 74 74 174 135 50 216 158 10
  49660. -236 178 12 246 190 14 246 190 14 246 190 14
  49661. -246 190 14 246 190 14 246 190 14 246 190 14
  49662. -246 190 14 246 190 14 246 190 14 246 190 14
  49663. -246 190 14 246 190 14 241 196 14 226 184 13
  49664. - 61 42 6 2 2 6 2 2 6 2 2 6
  49665. - 22 22 22 238 238 238 253 253 253 253 253 253
  49666. -253 253 253 253 253 253 253 253 253 253 253 253
  49667. -253 253 253 253 253 253 253 253 253 253 253 253
  49668. -253 253 253 253 253 253 253 253 253 253 253 253
  49669. -253 253 253 226 226 226 187 187 187 180 133 36
  49670. -216 158 10 236 178 12 239 182 13 236 178 12
  49671. -230 174 11 226 170 11 226 170 11 230 174 11
  49672. -236 178 12 242 186 14 246 190 14 246 190 14
  49673. -246 190 14 246 190 14 246 186 14 239 182 13
  49674. -206 162 42 106 106 106 66 66 66 34 34 34
  49675. - 14 14 14 6 6 6 0 0 0 0 0 0
  49676. - 0 0 0 0 0 0 0 0 0 0 0 0
  49677. - 0 0 0 0 0 0 0 0 0 0 0 0
  49678. - 0 0 0 0 0 0 0 0 0 6 6 6
  49679. - 26 26 26 70 70 70 163 133 67 213 154 11
  49680. -236 178 12 246 190 14 246 190 14 246 190 14
  49681. -246 190 14 246 190 14 246 190 14 246 190 14
  49682. -246 190 14 246 190 14 246 190 14 246 190 14
  49683. -246 190 14 246 190 14 246 190 14 241 196 14
  49684. -190 146 13 18 14 6 2 2 6 2 2 6
  49685. - 46 46 46 246 246 246 253 253 253 253 253 253
  49686. -253 253 253 253 253 253 253 253 253 253 253 253
  49687. -253 253 253 253 253 253 253 253 253 253 253 253
  49688. -253 253 253 253 253 253 253 253 253 253 253 253
  49689. -253 253 253 221 221 221 86 86 86 156 107 11
  49690. -216 158 10 236 178 12 242 186 14 246 186 14
  49691. -242 186 14 239 182 13 239 182 13 242 186 14
  49692. -242 186 14 246 186 14 246 190 14 246 190 14
  49693. -246 190 14 246 190 14 246 190 14 246 190 14
  49694. -242 186 14 225 175 15 142 122 72 66 66 66
  49695. - 30 30 30 10 10 10 0 0 0 0 0 0
  49696. - 0 0 0 0 0 0 0 0 0 0 0 0
  49697. - 0 0 0 0 0 0 0 0 0 0 0 0
  49698. - 0 0 0 0 0 0 0 0 0 6 6 6
  49699. - 26 26 26 70 70 70 163 133 67 210 150 10
  49700. -236 178 12 246 190 14 246 190 14 246 190 14
  49701. -246 190 14 246 190 14 246 190 14 246 190 14
  49702. -246 190 14 246 190 14 246 190 14 246 190 14
  49703. -246 190 14 246 190 14 246 190 14 246 190 14
  49704. -232 195 16 121 92 8 34 34 34 106 106 106
  49705. -221 221 221 253 253 253 253 253 253 253 253 253
  49706. -253 253 253 253 253 253 253 253 253 253 253 253
  49707. -253 253 253 253 253 253 253 253 253 253 253 253
  49708. -253 253 253 253 253 253 253 253 253 253 253 253
  49709. -242 242 242 82 82 82 18 14 6 163 110 8
  49710. -216 158 10 236 178 12 242 186 14 246 190 14
  49711. -246 190 14 246 190 14 246 190 14 246 190 14
  49712. -246 190 14 246 190 14 246 190 14 246 190 14
  49713. -246 190 14 246 190 14 246 190 14 246 190 14
  49714. -246 190 14 246 190 14 242 186 14 163 133 67
  49715. - 46 46 46 18 18 18 6 6 6 0 0 0
  49716. - 0 0 0 0 0 0 0 0 0 0 0 0
  49717. - 0 0 0 0 0 0 0 0 0 0 0 0
  49718. - 0 0 0 0 0 0 0 0 0 10 10 10
  49719. - 30 30 30 78 78 78 163 133 67 210 150 10
  49720. -236 178 12 246 186 14 246 190 14 246 190 14
  49721. -246 190 14 246 190 14 246 190 14 246 190 14
  49722. -246 190 14 246 190 14 246 190 14 246 190 14
  49723. -246 190 14 246 190 14 246 190 14 246 190 14
  49724. -241 196 14 215 174 15 190 178 144 253 253 253
  49725. -253 253 253 253 253 253 253 253 253 253 253 253
  49726. -253 253 253 253 253 253 253 253 253 253 253 253
  49727. -253 253 253 253 253 253 253 253 253 253 253 253
  49728. -253 253 253 253 253 253 253 253 253 218 218 218
  49729. - 58 58 58 2 2 6 22 18 6 167 114 7
  49730. -216 158 10 236 178 12 246 186 14 246 190 14
  49731. -246 190 14 246 190 14 246 190 14 246 190 14
  49732. -246 190 14 246 190 14 246 190 14 246 190 14
  49733. -246 190 14 246 190 14 246 190 14 246 190 14
  49734. -246 190 14 246 186 14 242 186 14 190 150 46
  49735. - 54 54 54 22 22 22 6 6 6 0 0 0
  49736. - 0 0 0 0 0 0 0 0 0 0 0 0
  49737. - 0 0 0 0 0 0 0 0 0 0 0 0
  49738. - 0 0 0 0 0 0 0 0 0 14 14 14
  49739. - 38 38 38 86 86 86 180 133 36 213 154 11
  49740. -236 178 12 246 186 14 246 190 14 246 190 14
  49741. -246 190 14 246 190 14 246 190 14 246 190 14
  49742. -246 190 14 246 190 14 246 190 14 246 190 14
  49743. -246 190 14 246 190 14 246 190 14 246 190 14
  49744. -246 190 14 232 195 16 190 146 13 214 214 214
  49745. -253 253 253 253 253 253 253 253 253 253 253 253
  49746. -253 253 253 253 253 253 253 253 253 253 253 253
  49747. -253 253 253 253 253 253 253 253 253 253 253 253
  49748. -253 253 253 250 250 250 170 170 170 26 26 26
  49749. - 2 2 6 2 2 6 37 26 9 163 110 8
  49750. -219 162 10 239 182 13 246 186 14 246 190 14
  49751. -246 190 14 246 190 14 246 190 14 246 190 14
  49752. -246 190 14 246 190 14 246 190 14 246 190 14
  49753. -246 190 14 246 190 14 246 190 14 246 190 14
  49754. -246 186 14 236 178 12 224 166 10 142 122 72
  49755. - 46 46 46 18 18 18 6 6 6 0 0 0
  49756. - 0 0 0 0 0 0 0 0 0 0 0 0
  49757. - 0 0 0 0 0 0 0 0 0 0 0 0
  49758. - 0 0 0 0 0 0 6 6 6 18 18 18
  49759. - 50 50 50 109 106 95 192 133 9 224 166 10
  49760. -242 186 14 246 190 14 246 190 14 246 190 14
  49761. -246 190 14 246 190 14 246 190 14 246 190 14
  49762. -246 190 14 246 190 14 246 190 14 246 190 14
  49763. -246 190 14 246 190 14 246 190 14 246 190 14
  49764. -242 186 14 226 184 13 210 162 10 142 110 46
  49765. -226 226 226 253 253 253 253 253 253 253 253 253
  49766. -253 253 253 253 253 253 253 253 253 253 253 253
  49767. -253 253 253 253 253 253 253 253 253 253 253 253
  49768. -198 198 198 66 66 66 2 2 6 2 2 6
  49769. - 2 2 6 2 2 6 50 34 6 156 107 11
  49770. -219 162 10 239 182 13 246 186 14 246 190 14
  49771. -246 190 14 246 190 14 246 190 14 246 190 14
  49772. -246 190 14 246 190 14 246 190 14 246 190 14
  49773. -246 190 14 246 190 14 246 190 14 242 186 14
  49774. -234 174 13 213 154 11 154 122 46 66 66 66
  49775. - 30 30 30 10 10 10 0 0 0 0 0 0
  49776. - 0 0 0 0 0 0 0 0 0 0 0 0
  49777. - 0 0 0 0 0 0 0 0 0 0 0 0
  49778. - 0 0 0 0 0 0 6 6 6 22 22 22
  49779. - 58 58 58 154 121 60 206 145 10 234 174 13
  49780. -242 186 14 246 186 14 246 190 14 246 190 14
  49781. -246 190 14 246 190 14 246 190 14 246 190 14
  49782. -246 190 14 246 190 14 246 190 14 246 190 14
  49783. -246 190 14 246 190 14 246 190 14 246 190 14
  49784. -246 186 14 236 178 12 210 162 10 163 110 8
  49785. - 61 42 6 138 138 138 218 218 218 250 250 250
  49786. -253 253 253 253 253 253 253 253 253 250 250 250
  49787. -242 242 242 210 210 210 144 144 144 66 66 66
  49788. - 6 6 6 2 2 6 2 2 6 2 2 6
  49789. - 2 2 6 2 2 6 61 42 6 163 110 8
  49790. -216 158 10 236 178 12 246 190 14 246 190 14
  49791. -246 190 14 246 190 14 246 190 14 246 190 14
  49792. -246 190 14 246 190 14 246 190 14 246 190 14
  49793. -246 190 14 239 182 13 230 174 11 216 158 10
  49794. -190 142 34 124 112 88 70 70 70 38 38 38
  49795. - 18 18 18 6 6 6 0 0 0 0 0 0
  49796. - 0 0 0 0 0 0 0 0 0 0 0 0
  49797. - 0 0 0 0 0 0 0 0 0 0 0 0
  49798. - 0 0 0 0 0 0 6 6 6 22 22 22
  49799. - 62 62 62 168 124 44 206 145 10 224 166 10
  49800. -236 178 12 239 182 13 242 186 14 242 186 14
  49801. -246 186 14 246 190 14 246 190 14 246 190 14
  49802. -246 190 14 246 190 14 246 190 14 246 190 14
  49803. -246 190 14 246 190 14 246 190 14 246 190 14
  49804. -246 190 14 236 178 12 216 158 10 175 118 6
  49805. - 80 54 7 2 2 6 6 6 6 30 30 30
  49806. - 54 54 54 62 62 62 50 50 50 38 38 38
  49807. - 14 14 14 2 2 6 2 2 6 2 2 6
  49808. - 2 2 6 2 2 6 2 2 6 2 2 6
  49809. - 2 2 6 6 6 6 80 54 7 167 114 7
  49810. -213 154 11 236 178 12 246 190 14 246 190 14
  49811. -246 190 14 246 190 14 246 190 14 246 190 14
  49812. -246 190 14 242 186 14 239 182 13 239 182 13
  49813. -230 174 11 210 150 10 174 135 50 124 112 88
  49814. - 82 82 82 54 54 54 34 34 34 18 18 18
  49815. - 6 6 6 0 0 0 0 0 0 0 0 0
  49816. - 0 0 0 0 0 0 0 0 0 0 0 0
  49817. - 0 0 0 0 0 0 0 0 0 0 0 0
  49818. - 0 0 0 0 0 0 6 6 6 18 18 18
  49819. - 50 50 50 158 118 36 192 133 9 200 144 11
  49820. -216 158 10 219 162 10 224 166 10 226 170 11
  49821. -230 174 11 236 178 12 239 182 13 239 182 13
  49822. -242 186 14 246 186 14 246 190 14 246 190 14
  49823. -246 190 14 246 190 14 246 190 14 246 190 14
  49824. -246 186 14 230 174 11 210 150 10 163 110 8
  49825. -104 69 6 10 10 10 2 2 6 2 2 6
  49826. - 2 2 6 2 2 6 2 2 6 2 2 6
  49827. - 2 2 6 2 2 6 2 2 6 2 2 6
  49828. - 2 2 6 2 2 6 2 2 6 2 2 6
  49829. - 2 2 6 6 6 6 91 60 6 167 114 7
  49830. -206 145 10 230 174 11 242 186 14 246 190 14
  49831. -246 190 14 246 190 14 246 186 14 242 186 14
  49832. -239 182 13 230 174 11 224 166 10 213 154 11
  49833. -180 133 36 124 112 88 86 86 86 58 58 58
  49834. - 38 38 38 22 22 22 10 10 10 6 6 6
  49835. - 0 0 0 0 0 0 0 0 0 0 0 0
  49836. - 0 0 0 0 0 0 0 0 0 0 0 0
  49837. - 0 0 0 0 0 0 0 0 0 0 0 0
  49838. - 0 0 0 0 0 0 0 0 0 14 14 14
  49839. - 34 34 34 70 70 70 138 110 50 158 118 36
  49840. -167 114 7 180 123 7 192 133 9 197 138 11
  49841. -200 144 11 206 145 10 213 154 11 219 162 10
  49842. -224 166 10 230 174 11 239 182 13 242 186 14
  49843. -246 186 14 246 186 14 246 186 14 246 186 14
  49844. -239 182 13 216 158 10 185 133 11 152 99 6
  49845. -104 69 6 18 14 6 2 2 6 2 2 6
  49846. - 2 2 6 2 2 6 2 2 6 2 2 6
  49847. - 2 2 6 2 2 6 2 2 6 2 2 6
  49848. - 2 2 6 2 2 6 2 2 6 2 2 6
  49849. - 2 2 6 6 6 6 80 54 7 152 99 6
  49850. -192 133 9 219 162 10 236 178 12 239 182 13
  49851. -246 186 14 242 186 14 239 182 13 236 178 12
  49852. -224 166 10 206 145 10 192 133 9 154 121 60
  49853. - 94 94 94 62 62 62 42 42 42 22 22 22
  49854. - 14 14 14 6 6 6 0 0 0 0 0 0
  49855. - 0 0 0 0 0 0 0 0 0 0 0 0
  49856. - 0 0 0 0 0 0 0 0 0 0 0 0
  49857. - 0 0 0 0 0 0 0 0 0 0 0 0
  49858. - 0 0 0 0 0 0 0 0 0 6 6 6
  49859. - 18 18 18 34 34 34 58 58 58 78 78 78
  49860. -101 98 89 124 112 88 142 110 46 156 107 11
  49861. -163 110 8 167 114 7 175 118 6 180 123 7
  49862. -185 133 11 197 138 11 210 150 10 219 162 10
  49863. -226 170 11 236 178 12 236 178 12 234 174 13
  49864. -219 162 10 197 138 11 163 110 8 130 83 6
  49865. - 91 60 6 10 10 10 2 2 6 2 2 6
  49866. - 18 18 18 38 38 38 38 38 38 38 38 38
  49867. - 38 38 38 38 38 38 38 38 38 38 38 38
  49868. - 38 38 38 38 38 38 26 26 26 2 2 6
  49869. - 2 2 6 6 6 6 70 47 6 137 92 6
  49870. -175 118 6 200 144 11 219 162 10 230 174 11
  49871. -234 174 13 230 174 11 219 162 10 210 150 10
  49872. -192 133 9 163 110 8 124 112 88 82 82 82
  49873. - 50 50 50 30 30 30 14 14 14 6 6 6
  49874. - 0 0 0 0 0 0 0 0 0 0 0 0
  49875. - 0 0 0 0 0 0 0 0 0 0 0 0
  49876. - 0 0 0 0 0 0 0 0 0 0 0 0
  49877. - 0 0 0 0 0 0 0 0 0 0 0 0
  49878. - 0 0 0 0 0 0 0 0 0 0 0 0
  49879. - 6 6 6 14 14 14 22 22 22 34 34 34
  49880. - 42 42 42 58 58 58 74 74 74 86 86 86
  49881. -101 98 89 122 102 70 130 98 46 121 87 25
  49882. -137 92 6 152 99 6 163 110 8 180 123 7
  49883. -185 133 11 197 138 11 206 145 10 200 144 11
  49884. -180 123 7 156 107 11 130 83 6 104 69 6
  49885. - 50 34 6 54 54 54 110 110 110 101 98 89
  49886. - 86 86 86 82 82 82 78 78 78 78 78 78
  49887. - 78 78 78 78 78 78 78 78 78 78 78 78
  49888. - 78 78 78 82 82 82 86 86 86 94 94 94
  49889. -106 106 106 101 101 101 86 66 34 124 80 6
  49890. -156 107 11 180 123 7 192 133 9 200 144 11
  49891. -206 145 10 200 144 11 192 133 9 175 118 6
  49892. -139 102 15 109 106 95 70 70 70 42 42 42
  49893. - 22 22 22 10 10 10 0 0 0 0 0 0
  49894. - 0 0 0 0 0 0 0 0 0 0 0 0
  49895. - 0 0 0 0 0 0 0 0 0 0 0 0
  49896. - 0 0 0 0 0 0 0 0 0 0 0 0
  49897. - 0 0 0 0 0 0 0 0 0 0 0 0
  49898. - 0 0 0 0 0 0 0 0 0 0 0 0
  49899. - 0 0 0 0 0 0 6 6 6 10 10 10
  49900. - 14 14 14 22 22 22 30 30 30 38 38 38
  49901. - 50 50 50 62 62 62 74 74 74 90 90 90
  49902. -101 98 89 112 100 78 121 87 25 124 80 6
  49903. -137 92 6 152 99 6 152 99 6 152 99 6
  49904. -138 86 6 124 80 6 98 70 6 86 66 30
  49905. -101 98 89 82 82 82 58 58 58 46 46 46
  49906. - 38 38 38 34 34 34 34 34 34 34 34 34
  49907. - 34 34 34 34 34 34 34 34 34 34 34 34
  49908. - 34 34 34 34 34 34 38 38 38 42 42 42
  49909. - 54 54 54 82 82 82 94 86 76 91 60 6
  49910. -134 86 6 156 107 11 167 114 7 175 118 6
  49911. -175 118 6 167 114 7 152 99 6 121 87 25
  49912. -101 98 89 62 62 62 34 34 34 18 18 18
  49913. - 6 6 6 0 0 0 0 0 0 0 0 0
  49914. - 0 0 0 0 0 0 0 0 0 0 0 0
  49915. - 0 0 0 0 0 0 0 0 0 0 0 0
  49916. - 0 0 0 0 0 0 0 0 0 0 0 0
  49917. - 0 0 0 0 0 0 0 0 0 0 0 0
  49918. - 0 0 0 0 0 0 0 0 0 0 0 0
  49919. - 0 0 0 0 0 0 0 0 0 0 0 0
  49920. - 0 0 0 6 6 6 6 6 6 10 10 10
  49921. - 18 18 18 22 22 22 30 30 30 42 42 42
  49922. - 50 50 50 66 66 66 86 86 86 101 98 89
  49923. -106 86 58 98 70 6 104 69 6 104 69 6
  49924. -104 69 6 91 60 6 82 62 34 90 90 90
  49925. - 62 62 62 38 38 38 22 22 22 14 14 14
  49926. - 10 10 10 10 10 10 10 10 10 10 10 10
  49927. - 10 10 10 10 10 10 6 6 6 10 10 10
  49928. - 10 10 10 10 10 10 10 10 10 14 14 14
  49929. - 22 22 22 42 42 42 70 70 70 89 81 66
  49930. - 80 54 7 104 69 6 124 80 6 137 92 6
  49931. -134 86 6 116 81 8 100 82 52 86 86 86
  49932. - 58 58 58 30 30 30 14 14 14 6 6 6
  49933. - 0 0 0 0 0 0 0 0 0 0 0 0
  49934. - 0 0 0 0 0 0 0 0 0 0 0 0
  49935. - 0 0 0 0 0 0 0 0 0 0 0 0
  49936. - 0 0 0 0 0 0 0 0 0 0 0 0
  49937. - 0 0 0 0 0 0 0 0 0 0 0 0
  49938. - 0 0 0 0 0 0 0 0 0 0 0 0
  49939. - 0 0 0 0 0 0 0 0 0 0 0 0
  49940. - 0 0 0 0 0 0 0 0 0 0 0 0
  49941. - 0 0 0 6 6 6 10 10 10 14 14 14
  49942. - 18 18 18 26 26 26 38 38 38 54 54 54
  49943. - 70 70 70 86 86 86 94 86 76 89 81 66
  49944. - 89 81 66 86 86 86 74 74 74 50 50 50
  49945. - 30 30 30 14 14 14 6 6 6 0 0 0
  49946. - 0 0 0 0 0 0 0 0 0 0 0 0
  49947. - 0 0 0 0 0 0 0 0 0 0 0 0
  49948. - 0 0 0 0 0 0 0 0 0 0 0 0
  49949. - 6 6 6 18 18 18 34 34 34 58 58 58
  49950. - 82 82 82 89 81 66 89 81 66 89 81 66
  49951. - 94 86 66 94 86 76 74 74 74 50 50 50
  49952. - 26 26 26 14 14 14 6 6 6 0 0 0
  49953. - 0 0 0 0 0 0 0 0 0 0 0 0
  49954. - 0 0 0 0 0 0 0 0 0 0 0 0
  49955. - 0 0 0 0 0 0 0 0 0 0 0 0
  49956. - 0 0 0 0 0 0 0 0 0 0 0 0
  49957. - 0 0 0 0 0 0 0 0 0 0 0 0
  49958. - 0 0 0 0 0 0 0 0 0 0 0 0
  49959. - 0 0 0 0 0 0 0 0 0 0 0 0
  49960. - 0 0 0 0 0 0 0 0 0 0 0 0
  49961. - 0 0 0 0 0 0 0 0 0 0 0 0
  49962. - 6 6 6 6 6 6 14 14 14 18 18 18
  49963. - 30 30 30 38 38 38 46 46 46 54 54 54
  49964. - 50 50 50 42 42 42 30 30 30 18 18 18
  49965. - 10 10 10 0 0 0 0 0 0 0 0 0
  49966. - 0 0 0 0 0 0 0 0 0 0 0 0
  49967. - 0 0 0 0 0 0 0 0 0 0 0 0
  49968. - 0 0 0 0 0 0 0 0 0 0 0 0
  49969. - 0 0 0 6 6 6 14 14 14 26 26 26
  49970. - 38 38 38 50 50 50 58 58 58 58 58 58
  49971. - 54 54 54 42 42 42 30 30 30 18 18 18
  49972. - 10 10 10 0 0 0 0 0 0 0 0 0
  49973. - 0 0 0 0 0 0 0 0 0 0 0 0
  49974. - 0 0 0 0 0 0 0 0 0 0 0 0
  49975. - 0 0 0 0 0 0 0 0 0 0 0 0
  49976. - 0 0 0 0 0 0 0 0 0 0 0 0
  49977. - 0 0 0 0 0 0 0 0 0 0 0 0
  49978. - 0 0 0 0 0 0 0 0 0 0 0 0
  49979. - 0 0 0 0 0 0 0 0 0 0 0 0
  49980. - 0 0 0 0 0 0 0 0 0 0 0 0
  49981. - 0 0 0 0 0 0 0 0 0 0 0 0
  49982. - 0 0 0 0 0 0 0 0 0 6 6 6
  49983. - 6 6 6 10 10 10 14 14 14 18 18 18
  49984. - 18 18 18 14 14 14 10 10 10 6 6 6
  49985. - 0 0 0 0 0 0 0 0 0 0 0 0
  49986. - 0 0 0 0 0 0 0 0 0 0 0 0
  49987. - 0 0 0 0 0 0 0 0 0 0 0 0
  49988. - 0 0 0 0 0 0 0 0 0 0 0 0
  49989. - 0 0 0 0 0 0 0 0 0 6 6 6
  49990. - 14 14 14 18 18 18 22 22 22 22 22 22
  49991. - 18 18 18 14 14 14 10 10 10 6 6 6
  49992. - 0 0 0 0 0 0 0 0 0 0 0 0
  49993. - 0 0 0 0 0 0 0 0 0 0 0 0
  49994. - 0 0 0 0 0 0 0 0 0 0 0 0
  49995. - 0 0 0 0 0 0 0 0 0 0 0 0
  49996. - 0 0 0 0 0 0 0 0 0 0 0 0
  49997. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  49998. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  49999. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50000. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50001. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50002. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50003. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50004. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50005. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50006. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50007. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50008. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50009. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50010. +4 4 4 4 4 4
  50011. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50012. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50013. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50014. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50015. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50016. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50017. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50018. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50019. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50020. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50021. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50022. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50023. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50024. +4 4 4 4 4 4
  50025. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50026. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50027. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50028. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50029. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50030. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50031. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50032. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50033. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50034. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50035. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50036. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50037. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50038. +4 4 4 4 4 4
  50039. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50040. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50041. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50042. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50043. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50044. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50045. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50046. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50047. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50048. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50049. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50050. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50051. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50052. +4 4 4 4 4 4
  50053. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50054. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50055. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50056. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50057. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50058. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50059. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50060. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50061. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50062. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50063. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50064. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50065. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50066. +4 4 4 4 4 4
  50067. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50068. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50069. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50070. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50071. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50072. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50073. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50074. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50075. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50076. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50077. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50078. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50079. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50080. +4 4 4 4 4 4
  50081. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50082. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50083. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50084. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50085. +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
  50086. +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
  50087. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50088. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50089. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50090. +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
  50091. +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
  50092. +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
  50093. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50094. +4 4 4 4 4 4
  50095. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50096. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50097. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50098. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50099. +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
  50100. +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
  50101. +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50102. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50103. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50104. +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
  50105. +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
  50106. +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
  50107. +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50108. +4 4 4 4 4 4
  50109. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50110. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50111. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50112. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50113. +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
  50114. +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
  50115. +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
  50116. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50117. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50118. +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
  50119. +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
  50120. +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
  50121. +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
  50122. +4 4 4 4 4 4
  50123. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50124. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50125. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50126. +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
  50127. +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
  50128. +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
  50129. +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
  50130. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50131. +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
  50132. +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
  50133. +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
  50134. +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
  50135. +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
  50136. +4 4 4 4 4 4
  50137. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50138. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50139. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50140. +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
  50141. +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
  50142. +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
  50143. +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
  50144. +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
  50145. +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
  50146. +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
  50147. +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
  50148. +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
  50149. +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
  50150. +4 4 4 4 4 4
  50151. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50152. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50153. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
  50154. +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
  50155. +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
  50156. +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
  50157. +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
  50158. +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
  50159. +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
  50160. +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
  50161. +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
  50162. +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
  50163. +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
  50164. +4 4 4 4 4 4
  50165. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50166. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50167. +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
  50168. +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
  50169. +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
  50170. +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
  50171. +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
  50172. +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
  50173. +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
  50174. +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
  50175. +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
  50176. +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
  50177. +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
  50178. +4 4 4 4 4 4
  50179. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50180. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50181. +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
  50182. +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
  50183. +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
  50184. +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
  50185. +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
  50186. +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
  50187. +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
  50188. +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
  50189. +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
  50190. +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
  50191. +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
  50192. +4 4 4 4 4 4
  50193. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50194. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50195. +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
  50196. +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
  50197. +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
  50198. +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
  50199. +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
  50200. +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
  50201. +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
  50202. +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
  50203. +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
  50204. +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
  50205. +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
  50206. +4 4 4 4 4 4
  50207. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50208. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50209. +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
  50210. +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
  50211. +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
  50212. +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
  50213. +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
  50214. +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
  50215. +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
  50216. +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
  50217. +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
  50218. +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
  50219. +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
  50220. +4 4 4 4 4 4
  50221. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50222. +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
  50223. +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
  50224. +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
  50225. +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
  50226. +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
  50227. +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
  50228. +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
  50229. +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
  50230. +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
  50231. +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
  50232. +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
  50233. +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
  50234. +4 4 4 4 4 4
  50235. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50236. +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
  50237. +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
  50238. +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
  50239. +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
  50240. +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
  50241. +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
  50242. +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
  50243. +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
  50244. +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
  50245. +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
  50246. +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
  50247. +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
  50248. +0 0 0 4 4 4
  50249. +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
  50250. +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
  50251. +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
  50252. +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
  50253. +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
  50254. +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
  50255. +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
  50256. +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
  50257. +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
  50258. +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
  50259. +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
  50260. +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
  50261. +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
  50262. +2 0 0 0 0 0
  50263. +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
  50264. +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
  50265. +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
  50266. +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
  50267. +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
  50268. +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
  50269. +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
  50270. +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
  50271. +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
  50272. +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
  50273. +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
  50274. +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
  50275. +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
  50276. +37 38 37 0 0 0
  50277. +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
  50278. +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
  50279. +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
  50280. +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
  50281. +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
  50282. +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
  50283. +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
  50284. +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
  50285. +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
  50286. +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
  50287. +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
  50288. +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
  50289. +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
  50290. +85 115 134 4 0 0
  50291. +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
  50292. +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
  50293. +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
  50294. +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
  50295. +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
  50296. +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
  50297. +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
  50298. +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
  50299. +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
  50300. +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
  50301. +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
  50302. +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
  50303. +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
  50304. +60 73 81 4 0 0
  50305. +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
  50306. +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
  50307. +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
  50308. +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
  50309. +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
  50310. +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
  50311. +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
  50312. +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
  50313. +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
  50314. +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
  50315. +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
  50316. +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
  50317. +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
  50318. +16 19 21 4 0 0
  50319. +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
  50320. +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
  50321. +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
  50322. +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
  50323. +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
  50324. +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
  50325. +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
  50326. +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
  50327. +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
  50328. +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
  50329. +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
  50330. +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
  50331. +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
  50332. +4 0 0 4 3 3
  50333. +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
  50334. +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
  50335. +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
  50336. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
  50337. +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
  50338. +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
  50339. +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
  50340. +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
  50341. +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
  50342. +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
  50343. +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
  50344. +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
  50345. +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
  50346. +3 2 2 4 4 4
  50347. +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
  50348. +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
  50349. +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
  50350. +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
  50351. +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
  50352. +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
  50353. +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  50354. +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
  50355. +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
  50356. +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
  50357. +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
  50358. +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
  50359. +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
  50360. +4 4 4 4 4 4
  50361. +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
  50362. +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
  50363. +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
  50364. +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
  50365. +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
  50366. +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
  50367. +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
  50368. +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
  50369. +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
  50370. +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
  50371. +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
  50372. +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
  50373. +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
  50374. +4 4 4 4 4 4
  50375. +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
  50376. +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
  50377. +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
  50378. +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
  50379. +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
  50380. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
  50381. +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
  50382. +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
  50383. +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
  50384. +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
  50385. +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
  50386. +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
  50387. +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
  50388. +5 5 5 5 5 5
  50389. +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
  50390. +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
  50391. +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
  50392. +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
  50393. +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
  50394. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
  50395. +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
  50396. +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
  50397. +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
  50398. +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
  50399. +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
  50400. +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
  50401. +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
  50402. +5 5 5 4 4 4
  50403. +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
  50404. +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
  50405. +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
  50406. +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
  50407. +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
  50408. +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
  50409. +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
  50410. +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
  50411. +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
  50412. +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
  50413. +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
  50414. +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
  50415. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50416. +4 4 4 4 4 4
  50417. +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
  50418. +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
  50419. +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
  50420. +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
  50421. +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
  50422. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
  50423. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
  50424. +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
  50425. +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
  50426. +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
  50427. +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
  50428. +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
  50429. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50430. +4 4 4 4 4 4
  50431. +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
  50432. +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
  50433. +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
  50434. +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
  50435. +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
  50436. +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
  50437. +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
  50438. +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
  50439. +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
  50440. +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
  50441. +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
  50442. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50443. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50444. +4 4 4 4 4 4
  50445. +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
  50446. +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
  50447. +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
  50448. +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
  50449. +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
  50450. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
  50451. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
  50452. +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
  50453. +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
  50454. +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
  50455. +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
  50456. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50457. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50458. +4 4 4 4 4 4
  50459. +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
  50460. +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
  50461. +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
  50462. +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
  50463. +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
  50464. +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
  50465. +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
  50466. +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
  50467. +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
  50468. +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
  50469. +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50470. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50471. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50472. +4 4 4 4 4 4
  50473. +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
  50474. +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
  50475. +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
  50476. +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
  50477. +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
  50478. +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
  50479. +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
  50480. +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
  50481. +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
  50482. +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
  50483. +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
  50484. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50485. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50486. +4 4 4 4 4 4
  50487. +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
  50488. +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
  50489. +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
  50490. +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
  50491. +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
  50492. +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
  50493. +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
  50494. +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
  50495. +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
  50496. +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
  50497. +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
  50498. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50499. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50500. +4 4 4 4 4 4
  50501. +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
  50502. +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
  50503. +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
  50504. +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
  50505. +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
  50506. +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
  50507. +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
  50508. +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
  50509. +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
  50510. +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
  50511. +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50512. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50513. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50514. +4 4 4 4 4 4
  50515. +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
  50516. +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
  50517. +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
  50518. +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
  50519. +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
  50520. +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
  50521. +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
  50522. +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
  50523. +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
  50524. +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
  50525. +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50526. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50527. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50528. +4 4 4 4 4 4
  50529. +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
  50530. +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
  50531. +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
  50532. +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
  50533. +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
  50534. +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
  50535. +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
  50536. +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
  50537. +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
  50538. +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
  50539. +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50540. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50541. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50542. +4 4 4 4 4 4
  50543. +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
  50544. +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
  50545. +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
  50546. +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
  50547. +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
  50548. +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
  50549. +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
  50550. +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
  50551. +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
  50552. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50553. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50554. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50555. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50556. +4 4 4 4 4 4
  50557. +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
  50558. +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
  50559. +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
  50560. +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
  50561. +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
  50562. +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
  50563. +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
  50564. +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
  50565. +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
  50566. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50567. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50568. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50569. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50570. +4 4 4 4 4 4
  50571. +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
  50572. +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
  50573. +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
  50574. +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
  50575. +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
  50576. +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
  50577. +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
  50578. +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
  50579. +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
  50580. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50581. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50582. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50583. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50584. +4 4 4 4 4 4
  50585. +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
  50586. +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
  50587. +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
  50588. +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
  50589. +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
  50590. +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
  50591. +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
  50592. +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
  50593. +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
  50594. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50595. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50596. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50597. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50598. +4 4 4 4 4 4
  50599. +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
  50600. +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
  50601. +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
  50602. +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
  50603. +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
  50604. +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
  50605. +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
  50606. +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
  50607. +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
  50608. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50609. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50610. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50611. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50612. +4 4 4 4 4 4
  50613. +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
  50614. +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
  50615. +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
  50616. +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
  50617. +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
  50618. +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
  50619. +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
  50620. +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
  50621. +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
  50622. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50623. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50624. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50625. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50626. +4 4 4 4 4 4
  50627. +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
  50628. +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
  50629. +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
  50630. +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
  50631. +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
  50632. +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
  50633. +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
  50634. +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
  50635. +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
  50636. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50637. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50638. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50639. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50640. +4 4 4 4 4 4
  50641. +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
  50642. +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
  50643. +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
  50644. +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
  50645. +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
  50646. +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
  50647. +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
  50648. +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
  50649. +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
  50650. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50651. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50652. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50653. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50654. +4 4 4 4 4 4
  50655. +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
  50656. +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
  50657. +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
  50658. +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
  50659. +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
  50660. +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
  50661. +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
  50662. +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
  50663. +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
  50664. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50665. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50666. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50667. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50668. +4 4 4 4 4 4
  50669. +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
  50670. +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
  50671. +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
  50672. +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
  50673. +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
  50674. +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
  50675. +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
  50676. +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
  50677. +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
  50678. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50679. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50680. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50681. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50682. +4 4 4 4 4 4
  50683. +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
  50684. +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
  50685. +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
  50686. +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
  50687. +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
  50688. +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
  50689. +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
  50690. +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
  50691. +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
  50692. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50693. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50694. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50695. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50696. +4 4 4 4 4 4
  50697. +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
  50698. +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
  50699. +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
  50700. +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
  50701. +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
  50702. +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
  50703. +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
  50704. +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
  50705. +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
  50706. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50707. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50708. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50709. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50710. +4 4 4 4 4 4
  50711. +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
  50712. +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
  50713. +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
  50714. +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
  50715. +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
  50716. +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
  50717. +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
  50718. +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
  50719. +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
  50720. +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50721. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50722. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50723. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50724. +4 4 4 4 4 4
  50725. +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
  50726. +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
  50727. +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
  50728. +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
  50729. +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
  50730. +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
  50731. +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
  50732. +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
  50733. +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
  50734. +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50735. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50736. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50737. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50738. +4 4 4 4 4 4
  50739. +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
  50740. +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
  50741. +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
  50742. +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
  50743. +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
  50744. +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
  50745. +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
  50746. +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
  50747. +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
  50748. +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
  50749. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50750. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50751. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50752. +4 4 4 4 4 4
  50753. +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
  50754. +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
  50755. +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
  50756. +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
  50757. +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
  50758. +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
  50759. +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
  50760. +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
  50761. +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
  50762. +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
  50763. +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  50764. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50765. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50766. +4 4 4 4 4 4
  50767. +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
  50768. +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
  50769. +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
  50770. +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
  50771. +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
  50772. +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
  50773. +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
  50774. +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
  50775. +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
  50776. +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
  50777. +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50778. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50779. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50780. +4 4 4 4 4 4
  50781. +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
  50782. +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
  50783. +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
  50784. +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
  50785. +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
  50786. +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
  50787. +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50788. +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
  50789. +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
  50790. +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
  50791. +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
  50792. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50793. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50794. +4 4 4 4 4 4
  50795. +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
  50796. +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
  50797. +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
  50798. +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
  50799. +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
  50800. +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
  50801. +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
  50802. +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
  50803. +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
  50804. +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
  50805. +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50806. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50807. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50808. +4 4 4 4 4 4
  50809. +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
  50810. +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
  50811. +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
  50812. +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
  50813. +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
  50814. +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
  50815. +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
  50816. +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
  50817. +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
  50818. +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
  50819. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50820. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50821. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50822. +4 4 4 4 4 4
  50823. +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
  50824. +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
  50825. +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
  50826. +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
  50827. +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
  50828. +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
  50829. +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
  50830. +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
  50831. +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
  50832. +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
  50833. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50834. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50835. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50836. +4 4 4 4 4 4
  50837. +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
  50838. +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
  50839. +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
  50840. +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
  50841. +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
  50842. +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
  50843. +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
  50844. +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
  50845. +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
  50846. +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
  50847. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50848. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50849. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50850. +4 4 4 4 4 4
  50851. +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
  50852. +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
  50853. +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
  50854. +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
  50855. +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
  50856. +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
  50857. +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
  50858. +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
  50859. +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
  50860. +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
  50861. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50862. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50863. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50864. +4 4 4 4 4 4
  50865. +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
  50866. +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
  50867. +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
  50868. +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
  50869. +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
  50870. +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
  50871. +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
  50872. +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
  50873. +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
  50874. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50875. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50876. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50877. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50878. +4 4 4 4 4 4
  50879. +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
  50880. +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
  50881. +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
  50882. +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
  50883. +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
  50884. +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
  50885. +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
  50886. +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
  50887. +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
  50888. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50889. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50890. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50891. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50892. +4 4 4 4 4 4
  50893. +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
  50894. +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
  50895. +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
  50896. +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
  50897. +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
  50898. +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
  50899. +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
  50900. +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
  50901. +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50902. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50903. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50904. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50905. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50906. +4 4 4 4 4 4
  50907. +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
  50908. +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
  50909. +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
  50910. +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
  50911. +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
  50912. +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
  50913. +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
  50914. +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
  50915. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50916. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50917. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50918. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50919. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50920. +4 4 4 4 4 4
  50921. +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
  50922. +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
  50923. +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
  50924. +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
  50925. +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
  50926. +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
  50927. +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
  50928. +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
  50929. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50930. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50931. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50932. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50933. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50934. +4 4 4 4 4 4
  50935. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
  50936. +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
  50937. +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
  50938. +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
  50939. +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
  50940. +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
  50941. +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
  50942. +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
  50943. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50944. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50945. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50946. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50947. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50948. +4 4 4 4 4 4
  50949. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50950. +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
  50951. +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
  50952. +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
  50953. +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
  50954. +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
  50955. +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
  50956. +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
  50957. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50958. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50959. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50960. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50961. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50962. +4 4 4 4 4 4
  50963. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50964. +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
  50965. +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
  50966. +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
  50967. +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
  50968. +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
  50969. +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
  50970. +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
  50971. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50972. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50973. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50974. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50975. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50976. +4 4 4 4 4 4
  50977. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50978. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50979. +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
  50980. +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
  50981. +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
  50982. +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
  50983. +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
  50984. +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
  50985. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50986. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50987. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50988. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50989. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50990. +4 4 4 4 4 4
  50991. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50992. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50993. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
  50994. +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
  50995. +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
  50996. +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
  50997. +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
  50998. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  50999. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51000. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51001. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51002. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51003. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51004. +4 4 4 4 4 4
  51005. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51006. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51007. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51008. +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
  51009. +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
  51010. +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
  51011. +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
  51012. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51013. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51014. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51015. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51016. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51017. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51018. +4 4 4 4 4 4
  51019. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51020. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51021. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51022. +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
  51023. +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
  51024. +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
  51025. +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
  51026. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51027. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51028. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51029. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51030. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51031. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51032. +4 4 4 4 4 4
  51033. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51034. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51035. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51036. +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
  51037. +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
  51038. +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
  51039. +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
  51040. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51041. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51042. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51043. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51044. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51045. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51046. +4 4 4 4 4 4
  51047. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51048. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51049. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51050. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
  51051. +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
  51052. +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
  51053. +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
  51054. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51055. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51056. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51057. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51058. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51059. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51060. +4 4 4 4 4 4
  51061. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51062. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51063. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51064. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51065. +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
  51066. +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
  51067. +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
  51068. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51069. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51070. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51071. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51072. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51073. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51074. +4 4 4 4 4 4
  51075. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51076. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51077. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51078. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51079. +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
  51080. +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
  51081. +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51082. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51083. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51084. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51085. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51086. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51087. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51088. +4 4 4 4 4 4
  51089. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51090. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51091. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51092. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51093. +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
  51094. +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
  51095. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51096. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51097. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51098. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51099. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51100. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51101. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51102. +4 4 4 4 4 4
  51103. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51104. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51105. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51106. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51107. +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
  51108. +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
  51109. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51110. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51111. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51112. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51113. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51114. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51115. +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  51116. +4 4 4 4 4 4
  51117. diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
  51118. index a01147f..5d896f8 100644
  51119. --- a/drivers/video/matrox/matroxfb_DAC1064.c
  51120. +++ b/drivers/video/matrox/matroxfb_DAC1064.c
  51121. @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
  51122. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  51123. struct matrox_switch matrox_mystique = {
  51124. - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
  51125. + .preinit = MGA1064_preinit,
  51126. + .reset = MGA1064_reset,
  51127. + .init = MGA1064_init,
  51128. + .restore = MGA1064_restore,
  51129. };
  51130. EXPORT_SYMBOL(matrox_mystique);
  51131. #endif
  51132. #ifdef CONFIG_FB_MATROX_G
  51133. struct matrox_switch matrox_G100 = {
  51134. - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
  51135. + .preinit = MGAG100_preinit,
  51136. + .reset = MGAG100_reset,
  51137. + .init = MGAG100_init,
  51138. + .restore = MGAG100_restore,
  51139. };
  51140. EXPORT_SYMBOL(matrox_G100);
  51141. #endif
  51142. diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
  51143. index 195ad7c..09743fc 100644
  51144. --- a/drivers/video/matrox/matroxfb_Ti3026.c
  51145. +++ b/drivers/video/matrox/matroxfb_Ti3026.c
  51146. @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
  51147. }
  51148. struct matrox_switch matrox_millennium = {
  51149. - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
  51150. + .preinit = Ti3026_preinit,
  51151. + .reset = Ti3026_reset,
  51152. + .init = Ti3026_init,
  51153. + .restore = Ti3026_restore
  51154. };
  51155. EXPORT_SYMBOL(matrox_millennium);
  51156. #endif
  51157. diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
  51158. index fe92eed..106e085 100644
  51159. --- a/drivers/video/mb862xx/mb862xxfb_accel.c
  51160. +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
  51161. @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
  51162. struct mb862xxfb_par *par = info->par;
  51163. if (info->var.bits_per_pixel == 32) {
  51164. - info->fbops->fb_fillrect = cfb_fillrect;
  51165. - info->fbops->fb_copyarea = cfb_copyarea;
  51166. - info->fbops->fb_imageblit = cfb_imageblit;
  51167. + pax_open_kernel();
  51168. + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
  51169. + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
  51170. + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
  51171. + pax_close_kernel();
  51172. } else {
  51173. outreg(disp, GC_L0EM, 3);
  51174. - info->fbops->fb_fillrect = mb86290fb_fillrect;
  51175. - info->fbops->fb_copyarea = mb86290fb_copyarea;
  51176. - info->fbops->fb_imageblit = mb86290fb_imageblit;
  51177. + pax_open_kernel();
  51178. + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
  51179. + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
  51180. + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
  51181. + pax_close_kernel();
  51182. }
  51183. outreg(draw, GDC_REG_DRAW_BASE, 0);
  51184. outreg(draw, GDC_REG_MODE_MISC, 0x8000);
  51185. diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
  51186. index def0412..fed6529 100644
  51187. --- a/drivers/video/nvidia/nvidia.c
  51188. +++ b/drivers/video/nvidia/nvidia.c
  51189. @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
  51190. info->fix.line_length = (info->var.xres_virtual *
  51191. info->var.bits_per_pixel) >> 3;
  51192. if (info->var.accel_flags) {
  51193. - info->fbops->fb_imageblit = nvidiafb_imageblit;
  51194. - info->fbops->fb_fillrect = nvidiafb_fillrect;
  51195. - info->fbops->fb_copyarea = nvidiafb_copyarea;
  51196. - info->fbops->fb_sync = nvidiafb_sync;
  51197. + pax_open_kernel();
  51198. + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
  51199. + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
  51200. + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
  51201. + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
  51202. + pax_close_kernel();
  51203. info->pixmap.scan_align = 4;
  51204. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  51205. info->flags |= FBINFO_READS_FAST;
  51206. NVResetGraphics(info);
  51207. } else {
  51208. - info->fbops->fb_imageblit = cfb_imageblit;
  51209. - info->fbops->fb_fillrect = cfb_fillrect;
  51210. - info->fbops->fb_copyarea = cfb_copyarea;
  51211. - info->fbops->fb_sync = NULL;
  51212. + pax_open_kernel();
  51213. + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
  51214. + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
  51215. + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
  51216. + *(void **)&info->fbops->fb_sync = NULL;
  51217. + pax_close_kernel();
  51218. info->pixmap.scan_align = 1;
  51219. info->flags |= FBINFO_HWACCEL_DISABLED;
  51220. info->flags &= ~FBINFO_READS_FAST;
  51221. @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
  51222. info->pixmap.size = 8 * 1024;
  51223. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  51224. - if (!hwcur)
  51225. - info->fbops->fb_cursor = NULL;
  51226. + if (!hwcur) {
  51227. + pax_open_kernel();
  51228. + *(void **)&info->fbops->fb_cursor = NULL;
  51229. + pax_close_kernel();
  51230. + }
  51231. info->var.accel_flags = (!noaccel);
  51232. diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
  51233. index 669a81f..e216d76 100644
  51234. --- a/drivers/video/omap2/dss/display.c
  51235. +++ b/drivers/video/omap2/dss/display.c
  51236. @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
  51237. snprintf(dssdev->alias, sizeof(dssdev->alias),
  51238. "display%d", disp_num_counter++);
  51239. + pax_open_kernel();
  51240. if (drv && drv->get_resolution == NULL)
  51241. - drv->get_resolution = omapdss_default_get_resolution;
  51242. + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
  51243. if (drv && drv->get_recommended_bpp == NULL)
  51244. - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
  51245. + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
  51246. if (drv && drv->get_timings == NULL)
  51247. - drv->get_timings = omapdss_default_get_timings;
  51248. + *(void **)&drv->get_timings = omapdss_default_get_timings;
  51249. + pax_close_kernel();
  51250. mutex_lock(&panel_list_mutex);
  51251. list_add_tail(&dssdev->panel_list, &panel_list);
  51252. diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
  51253. index 83433cb..71e9b98 100644
  51254. --- a/drivers/video/s1d13xxxfb.c
  51255. +++ b/drivers/video/s1d13xxxfb.c
  51256. @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
  51257. switch(prod_id) {
  51258. case S1D13506_PROD_ID: /* activate acceleration */
  51259. - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
  51260. - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
  51261. + pax_open_kernel();
  51262. + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
  51263. + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
  51264. + pax_close_kernel();
  51265. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
  51266. FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
  51267. break;
  51268. diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
  51269. index 2bcc84a..29dd1ea 100644
  51270. --- a/drivers/video/sh_mobile_lcdcfb.c
  51271. +++ b/drivers/video/sh_mobile_lcdcfb.c
  51272. @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
  51273. }
  51274. static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
  51275. - lcdc_sys_write_index,
  51276. - lcdc_sys_write_data,
  51277. - lcdc_sys_read_data,
  51278. + .write_index = lcdc_sys_write_index,
  51279. + .write_data = lcdc_sys_write_data,
  51280. + .read_data = lcdc_sys_read_data,
  51281. };
  51282. static int sh_mobile_lcdc_sginit(struct fb_info *info,
  51283. diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
  51284. index d513ed6..90b0de9 100644
  51285. --- a/drivers/video/smscufx.c
  51286. +++ b/drivers/video/smscufx.c
  51287. @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
  51288. fb_deferred_io_cleanup(info);
  51289. kfree(info->fbdefio);
  51290. info->fbdefio = NULL;
  51291. - info->fbops->fb_mmap = ufx_ops_mmap;
  51292. + pax_open_kernel();
  51293. + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
  51294. + pax_close_kernel();
  51295. }
  51296. pr_debug("released /dev/fb%d user=%d count=%d",
  51297. diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
  51298. index 77b890e..458e666 100644
  51299. --- a/drivers/video/udlfb.c
  51300. +++ b/drivers/video/udlfb.c
  51301. @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
  51302. dlfb_urb_completion(urb);
  51303. error:
  51304. - atomic_add(bytes_sent, &dev->bytes_sent);
  51305. - atomic_add(bytes_identical, &dev->bytes_identical);
  51306. - atomic_add(width*height*2, &dev->bytes_rendered);
  51307. + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
  51308. + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
  51309. + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
  51310. end_cycles = get_cycles();
  51311. - atomic_add(((unsigned int) ((end_cycles - start_cycles)
  51312. + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
  51313. >> 10)), /* Kcycles */
  51314. &dev->cpu_kcycles_used);
  51315. @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
  51316. dlfb_urb_completion(urb);
  51317. error:
  51318. - atomic_add(bytes_sent, &dev->bytes_sent);
  51319. - atomic_add(bytes_identical, &dev->bytes_identical);
  51320. - atomic_add(bytes_rendered, &dev->bytes_rendered);
  51321. + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
  51322. + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
  51323. + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
  51324. end_cycles = get_cycles();
  51325. - atomic_add(((unsigned int) ((end_cycles - start_cycles)
  51326. + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
  51327. >> 10)), /* Kcycles */
  51328. &dev->cpu_kcycles_used);
  51329. }
  51330. @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
  51331. fb_deferred_io_cleanup(info);
  51332. kfree(info->fbdefio);
  51333. info->fbdefio = NULL;
  51334. - info->fbops->fb_mmap = dlfb_ops_mmap;
  51335. + pax_open_kernel();
  51336. + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
  51337. + pax_close_kernel();
  51338. }
  51339. pr_warn("released /dev/fb%d user=%d count=%d\n",
  51340. @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
  51341. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  51342. struct dlfb_data *dev = fb_info->par;
  51343. return snprintf(buf, PAGE_SIZE, "%u\n",
  51344. - atomic_read(&dev->bytes_rendered));
  51345. + atomic_read_unchecked(&dev->bytes_rendered));
  51346. }
  51347. static ssize_t metrics_bytes_identical_show(struct device *fbdev,
  51348. @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
  51349. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  51350. struct dlfb_data *dev = fb_info->par;
  51351. return snprintf(buf, PAGE_SIZE, "%u\n",
  51352. - atomic_read(&dev->bytes_identical));
  51353. + atomic_read_unchecked(&dev->bytes_identical));
  51354. }
  51355. static ssize_t metrics_bytes_sent_show(struct device *fbdev,
  51356. @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
  51357. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  51358. struct dlfb_data *dev = fb_info->par;
  51359. return snprintf(buf, PAGE_SIZE, "%u\n",
  51360. - atomic_read(&dev->bytes_sent));
  51361. + atomic_read_unchecked(&dev->bytes_sent));
  51362. }
  51363. static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
  51364. @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
  51365. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  51366. struct dlfb_data *dev = fb_info->par;
  51367. return snprintf(buf, PAGE_SIZE, "%u\n",
  51368. - atomic_read(&dev->cpu_kcycles_used));
  51369. + atomic_read_unchecked(&dev->cpu_kcycles_used));
  51370. }
  51371. static ssize_t edid_show(
  51372. @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
  51373. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  51374. struct dlfb_data *dev = fb_info->par;
  51375. - atomic_set(&dev->bytes_rendered, 0);
  51376. - atomic_set(&dev->bytes_identical, 0);
  51377. - atomic_set(&dev->bytes_sent, 0);
  51378. - atomic_set(&dev->cpu_kcycles_used, 0);
  51379. + atomic_set_unchecked(&dev->bytes_rendered, 0);
  51380. + atomic_set_unchecked(&dev->bytes_identical, 0);
  51381. + atomic_set_unchecked(&dev->bytes_sent, 0);
  51382. + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
  51383. return count;
  51384. }
  51385. diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
  51386. index 256fba7..6e75516 100644
  51387. --- a/drivers/video/uvesafb.c
  51388. +++ b/drivers/video/uvesafb.c
  51389. @@ -19,6 +19,7 @@
  51390. #include <linux/io.h>
  51391. #include <linux/mutex.h>
  51392. #include <linux/slab.h>
  51393. +#include <linux/moduleloader.h>
  51394. #include <video/edid.h>
  51395. #include <video/uvesafb.h>
  51396. #ifdef CONFIG_X86
  51397. @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
  51398. if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
  51399. par->pmi_setpal = par->ypan = 0;
  51400. } else {
  51401. +
  51402. +#ifdef CONFIG_PAX_KERNEXEC
  51403. +#ifdef CONFIG_MODULES
  51404. + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
  51405. +#endif
  51406. + if (!par->pmi_code) {
  51407. + par->pmi_setpal = par->ypan = 0;
  51408. + return 0;
  51409. + }
  51410. +#endif
  51411. +
  51412. par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
  51413. + task->t.regs.edi);
  51414. +
  51415. +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51416. + pax_open_kernel();
  51417. + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
  51418. + pax_close_kernel();
  51419. +
  51420. + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
  51421. + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
  51422. +#else
  51423. par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
  51424. par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
  51425. +#endif
  51426. +
  51427. printk(KERN_INFO "uvesafb: protected mode interface info at "
  51428. "%04x:%04x\n",
  51429. (u16)task->t.regs.es, (u16)task->t.regs.edi);
  51430. @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
  51431. par->ypan = ypan;
  51432. if (par->pmi_setpal || par->ypan) {
  51433. +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
  51434. if (__supported_pte_mask & _PAGE_NX) {
  51435. par->pmi_setpal = par->ypan = 0;
  51436. printk(KERN_WARNING "uvesafb: NX protection is active, "
  51437. "better not use the PMI.\n");
  51438. - } else {
  51439. + } else
  51440. +#endif
  51441. uvesafb_vbe_getpmi(task, par);
  51442. - }
  51443. }
  51444. #else
  51445. /* The protected mode interface is not available on non-x86. */
  51446. @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
  51447. info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
  51448. /* Disable blanking if the user requested so. */
  51449. - if (!blank)
  51450. - info->fbops->fb_blank = NULL;
  51451. + if (!blank) {
  51452. + pax_open_kernel();
  51453. + *(void **)&info->fbops->fb_blank = NULL;
  51454. + pax_close_kernel();
  51455. + }
  51456. /*
  51457. * Find out how much IO memory is required for the mode with
  51458. @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
  51459. info->flags = FBINFO_FLAG_DEFAULT |
  51460. (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
  51461. - if (!par->ypan)
  51462. - info->fbops->fb_pan_display = NULL;
  51463. + if (!par->ypan) {
  51464. + pax_open_kernel();
  51465. + *(void **)&info->fbops->fb_pan_display = NULL;
  51466. + pax_close_kernel();
  51467. + }
  51468. }
  51469. static void uvesafb_init_mtrr(struct fb_info *info)
  51470. @@ -1792,6 +1822,11 @@ out_mode:
  51471. out:
  51472. kfree(par->vbe_modes);
  51473. +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51474. + if (par->pmi_code)
  51475. + module_free_exec(NULL, par->pmi_code);
  51476. +#endif
  51477. +
  51478. framebuffer_release(info);
  51479. return err;
  51480. }
  51481. @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
  51482. kfree(par->vbe_modes);
  51483. kfree(par->vbe_state_orig);
  51484. kfree(par->vbe_state_saved);
  51485. +
  51486. +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51487. + if (par->pmi_code)
  51488. + module_free_exec(NULL, par->pmi_code);
  51489. +#endif
  51490. +
  51491. }
  51492. framebuffer_release(info);
  51493. diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
  51494. index 1c7da3b..56ea0bd 100644
  51495. --- a/drivers/video/vesafb.c
  51496. +++ b/drivers/video/vesafb.c
  51497. @@ -9,6 +9,7 @@
  51498. */
  51499. #include <linux/module.h>
  51500. +#include <linux/moduleloader.h>
  51501. #include <linux/kernel.h>
  51502. #include <linux/errno.h>
  51503. #include <linux/string.h>
  51504. @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
  51505. static int vram_total; /* Set total amount of memory */
  51506. static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
  51507. static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
  51508. -static void (*pmi_start)(void) __read_mostly;
  51509. -static void (*pmi_pal) (void) __read_mostly;
  51510. +static void (*pmi_start)(void) __read_only;
  51511. +static void (*pmi_pal) (void) __read_only;
  51512. static int depth __read_mostly;
  51513. static int vga_compat __read_mostly;
  51514. /* --------------------------------------------------------------------- */
  51515. @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
  51516. unsigned int size_remap;
  51517. unsigned int size_total;
  51518. char *option = NULL;
  51519. + void *pmi_code = NULL;
  51520. /* ignore error return of fb_get_options */
  51521. fb_get_options("vesafb", &option);
  51522. @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
  51523. size_remap = size_total;
  51524. vesafb_fix.smem_len = size_remap;
  51525. -#ifndef __i386__
  51526. - screen_info.vesapm_seg = 0;
  51527. -#endif
  51528. -
  51529. if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
  51530. printk(KERN_WARNING
  51531. "vesafb: cannot reserve video memory at 0x%lx\n",
  51532. @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
  51533. printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
  51534. vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
  51535. +#ifdef __i386__
  51536. +
  51537. +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51538. + pmi_code = module_alloc_exec(screen_info.vesapm_size);
  51539. + if (!pmi_code)
  51540. +#elif !defined(CONFIG_PAX_KERNEXEC)
  51541. + if (0)
  51542. +#endif
  51543. +
  51544. +#endif
  51545. + screen_info.vesapm_seg = 0;
  51546. +
  51547. if (screen_info.vesapm_seg) {
  51548. - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
  51549. - screen_info.vesapm_seg,screen_info.vesapm_off);
  51550. + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
  51551. + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
  51552. }
  51553. if (screen_info.vesapm_seg < 0xc000)
  51554. @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
  51555. if (ypan || pmi_setpal) {
  51556. unsigned short *pmi_base;
  51557. +
  51558. pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
  51559. - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
  51560. - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
  51561. +
  51562. +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51563. + pax_open_kernel();
  51564. + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
  51565. +#else
  51566. + pmi_code = pmi_base;
  51567. +#endif
  51568. +
  51569. + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
  51570. + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
  51571. +
  51572. +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51573. + pmi_start = ktva_ktla(pmi_start);
  51574. + pmi_pal = ktva_ktla(pmi_pal);
  51575. + pax_close_kernel();
  51576. +#endif
  51577. +
  51578. printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
  51579. if (pmi_base[3]) {
  51580. printk(KERN_INFO "vesafb: pmi: ports = ");
  51581. @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
  51582. info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
  51583. (ypan ? FBINFO_HWACCEL_YPAN : 0);
  51584. - if (!ypan)
  51585. - info->fbops->fb_pan_display = NULL;
  51586. + if (!ypan) {
  51587. + pax_open_kernel();
  51588. + *(void **)&info->fbops->fb_pan_display = NULL;
  51589. + pax_close_kernel();
  51590. + }
  51591. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  51592. err = -ENOMEM;
  51593. @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
  51594. fb_info(info, "%s frame buffer device\n", info->fix.id);
  51595. return 0;
  51596. err:
  51597. +
  51598. +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
  51599. + module_free_exec(NULL, pmi_code);
  51600. +#endif
  51601. +
  51602. if (info->screen_base)
  51603. iounmap(info->screen_base);
  51604. framebuffer_release(info);
  51605. diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
  51606. index 88714ae..16c2e11 100644
  51607. --- a/drivers/video/via/via_clock.h
  51608. +++ b/drivers/video/via/via_clock.h
  51609. @@ -56,7 +56,7 @@ struct via_clock {
  51610. void (*set_engine_pll_state)(u8 state);
  51611. void (*set_engine_pll)(struct via_pll_config config);
  51612. -};
  51613. +} __no_const;
  51614. static inline u32 get_pll_internal_frequency(u32 ref_freq,
  51615. diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
  51616. index fef20db..d28b1ab 100644
  51617. --- a/drivers/xen/xenfs/xenstored.c
  51618. +++ b/drivers/xen/xenfs/xenstored.c
  51619. @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
  51620. static int xsd_kva_open(struct inode *inode, struct file *file)
  51621. {
  51622. file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
  51623. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  51624. + NULL);
  51625. +#else
  51626. xen_store_interface);
  51627. +#endif
  51628. +
  51629. if (!file->private_data)
  51630. return -ENOMEM;
  51631. return 0;
  51632. diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
  51633. index c71e886..61d3d44b 100644
  51634. --- a/fs/9p/vfs_addr.c
  51635. +++ b/fs/9p/vfs_addr.c
  51636. @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
  51637. retval = v9fs_file_write_internal(inode,
  51638. v9inode->writeback_fid,
  51639. - (__force const char __user *)buffer,
  51640. + (const char __force_user *)buffer,
  51641. len, &offset, 0);
  51642. if (retval > 0)
  51643. retval = 0;
  51644. diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
  51645. index bb7991c..481e21a 100644
  51646. --- a/fs/9p/vfs_inode.c
  51647. +++ b/fs/9p/vfs_inode.c
  51648. @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  51649. void
  51650. v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
  51651. {
  51652. - char *s = nd_get_link(nd);
  51653. + const char *s = nd_get_link(nd);
  51654. p9_debug(P9_DEBUG_VFS, " %s %s\n",
  51655. dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
  51656. diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
  51657. index 370b24c..ff0be7b 100644
  51658. --- a/fs/Kconfig.binfmt
  51659. +++ b/fs/Kconfig.binfmt
  51660. @@ -103,7 +103,7 @@ config HAVE_AOUT
  51661. config BINFMT_AOUT
  51662. tristate "Kernel support for a.out and ECOFF binaries"
  51663. - depends on HAVE_AOUT
  51664. + depends on HAVE_AOUT && BROKEN
  51665. ---help---
  51666. A.out (Assembler.OUTput) is a set of formats for libraries and
  51667. executables used in the earliest versions of UNIX. Linux used
  51668. diff --git a/fs/affs/super.c b/fs/affs/super.c
  51669. index d098731..9a5b19d 100644
  51670. --- a/fs/affs/super.c
  51671. +++ b/fs/affs/super.c
  51672. @@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
  51673. &blocksize,&sbi->s_prefix,
  51674. sbi->s_volume, &mount_flags)) {
  51675. printk(KERN_ERR "AFFS: Error parsing options\n");
  51676. - kfree(sbi->s_prefix);
  51677. - kfree(sbi);
  51678. return -EINVAL;
  51679. }
  51680. /* N.B. after this point s_prefix must be released */
  51681. diff --git a/fs/afs/inode.c b/fs/afs/inode.c
  51682. index ce25d75..dc09eeb 100644
  51683. --- a/fs/afs/inode.c
  51684. +++ b/fs/afs/inode.c
  51685. @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
  51686. struct afs_vnode *vnode;
  51687. struct super_block *sb;
  51688. struct inode *inode;
  51689. - static atomic_t afs_autocell_ino;
  51690. + static atomic_unchecked_t afs_autocell_ino;
  51691. _enter("{%x:%u},%*.*s,",
  51692. AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
  51693. @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
  51694. data.fid.unique = 0;
  51695. data.fid.vnode = 0;
  51696. - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
  51697. + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
  51698. afs_iget5_autocell_test, afs_iget5_set,
  51699. &data);
  51700. if (!inode) {
  51701. diff --git a/fs/aio.c b/fs/aio.c
  51702. index 12a3de0e..25949c1 100644
  51703. --- a/fs/aio.c
  51704. +++ b/fs/aio.c
  51705. @@ -375,7 +375,7 @@ static int aio_setup_ring(struct kioctx *ctx)
  51706. size += sizeof(struct io_event) * nr_events;
  51707. nr_pages = PFN_UP(size);
  51708. - if (nr_pages < 0)
  51709. + if (nr_pages <= 0)
  51710. return -EINVAL;
  51711. file = aio_private_file(ctx, nr_pages);
  51712. @@ -1299,10 +1299,8 @@ rw_common:
  51713. &iovec, compat)
  51714. : aio_setup_single_vector(req, rw, buf, &nr_segs,
  51715. iovec);
  51716. - if (ret)
  51717. - return ret;
  51718. -
  51719. - ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
  51720. + if (!ret)
  51721. + ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
  51722. if (ret < 0) {
  51723. if (iovec != &inline_vec)
  51724. kfree(iovec);
  51725. diff --git a/fs/attr.c b/fs/attr.c
  51726. index 5d4e59d..fd02418 100644
  51727. --- a/fs/attr.c
  51728. +++ b/fs/attr.c
  51729. @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
  51730. unsigned long limit;
  51731. limit = rlimit(RLIMIT_FSIZE);
  51732. + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
  51733. if (limit != RLIM_INFINITY && offset > limit)
  51734. goto out_sig;
  51735. if (offset > inode->i_sb->s_maxbytes)
  51736. diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
  51737. index 116fd38..c04182da 100644
  51738. --- a/fs/autofs4/waitq.c
  51739. +++ b/fs/autofs4/waitq.c
  51740. @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
  51741. {
  51742. unsigned long sigpipe, flags;
  51743. mm_segment_t fs;
  51744. - const char *data = (const char *)addr;
  51745. + const char __user *data = (const char __force_user *)addr;
  51746. ssize_t wr = 0;
  51747. sigpipe = sigismember(&current->pending.signal, SIGPIPE);
  51748. @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
  51749. return 1;
  51750. }
  51751. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  51752. +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
  51753. +#endif
  51754. +
  51755. int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
  51756. enum autofs_notify notify)
  51757. {
  51758. @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
  51759. /* If this is a direct mount request create a dummy name */
  51760. if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
  51761. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  51762. + /* this name does get written to userland via autofs4_write() */
  51763. + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
  51764. +#else
  51765. qstr.len = sprintf(name, "%p", dentry);
  51766. +#endif
  51767. else {
  51768. qstr.len = autofs4_getpath(sbi, dentry, &name);
  51769. if (!qstr.len) {
  51770. diff --git a/fs/befs/endian.h b/fs/befs/endian.h
  51771. index 2722387..56059b5 100644
  51772. --- a/fs/befs/endian.h
  51773. +++ b/fs/befs/endian.h
  51774. @@ -11,7 +11,7 @@
  51775. #include <asm/byteorder.h>
  51776. -static inline u64
  51777. +static inline u64 __intentional_overflow(-1)
  51778. fs64_to_cpu(const struct super_block *sb, fs64 n)
  51779. {
  51780. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  51781. @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
  51782. return (__force fs64)cpu_to_be64(n);
  51783. }
  51784. -static inline u32
  51785. +static inline u32 __intentional_overflow(-1)
  51786. fs32_to_cpu(const struct super_block *sb, fs32 n)
  51787. {
  51788. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  51789. @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
  51790. return (__force fs32)cpu_to_be32(n);
  51791. }
  51792. -static inline u16
  51793. +static inline u16 __intentional_overflow(-1)
  51794. fs16_to_cpu(const struct super_block *sb, fs16 n)
  51795. {
  51796. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  51797. diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
  51798. index ca0ba15..0fa3257 100644
  51799. --- a/fs/binfmt_aout.c
  51800. +++ b/fs/binfmt_aout.c
  51801. @@ -16,6 +16,7 @@
  51802. #include <linux/string.h>
  51803. #include <linux/fs.h>
  51804. #include <linux/file.h>
  51805. +#include <linux/security.h>
  51806. #include <linux/stat.h>
  51807. #include <linux/fcntl.h>
  51808. #include <linux/ptrace.h>
  51809. @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
  51810. #endif
  51811. # define START_STACK(u) ((void __user *)u.start_stack)
  51812. + memset(&dump, 0, sizeof(dump));
  51813. +
  51814. fs = get_fs();
  51815. set_fs(KERNEL_DS);
  51816. has_dumped = 1;
  51817. @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
  51818. /* If the size of the dump file exceeds the rlimit, then see what would happen
  51819. if we wrote the stack, but not the data area. */
  51820. + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
  51821. if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
  51822. dump.u_dsize = 0;
  51823. /* Make sure we have enough room to write the stack and data areas. */
  51824. + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
  51825. if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
  51826. dump.u_ssize = 0;
  51827. @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
  51828. rlim = rlimit(RLIMIT_DATA);
  51829. if (rlim >= RLIM_INFINITY)
  51830. rlim = ~0;
  51831. +
  51832. + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
  51833. if (ex.a_data + ex.a_bss > rlim)
  51834. return -ENOMEM;
  51835. @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
  51836. install_exec_creds(bprm);
  51837. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  51838. + current->mm->pax_flags = 0UL;
  51839. +#endif
  51840. +
  51841. +#ifdef CONFIG_PAX_PAGEEXEC
  51842. + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
  51843. + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
  51844. +
  51845. +#ifdef CONFIG_PAX_EMUTRAMP
  51846. + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
  51847. + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
  51848. +#endif
  51849. +
  51850. +#ifdef CONFIG_PAX_MPROTECT
  51851. + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
  51852. + current->mm->pax_flags |= MF_PAX_MPROTECT;
  51853. +#endif
  51854. +
  51855. + }
  51856. +#endif
  51857. +
  51858. if (N_MAGIC(ex) == OMAGIC) {
  51859. unsigned long text_addr, map_size;
  51860. loff_t pos;
  51861. @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
  51862. }
  51863. error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
  51864. - PROT_READ | PROT_WRITE | PROT_EXEC,
  51865. + PROT_READ | PROT_WRITE,
  51866. MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
  51867. fd_offset + ex.a_text);
  51868. if (error != N_DATADDR(ex)) {
  51869. diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
  51870. index 67be295..83e2f86 100644
  51871. --- a/fs/binfmt_elf.c
  51872. +++ b/fs/binfmt_elf.c
  51873. @@ -34,6 +34,7 @@
  51874. #include <linux/utsname.h>
  51875. #include <linux/coredump.h>
  51876. #include <linux/sched.h>
  51877. +#include <linux/xattr.h>
  51878. #include <asm/uaccess.h>
  51879. #include <asm/param.h>
  51880. #include <asm/page.h>
  51881. @@ -48,7 +49,7 @@
  51882. static int load_elf_binary(struct linux_binprm *bprm);
  51883. static int load_elf_library(struct file *);
  51884. static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
  51885. - int, int, unsigned long);
  51886. + int, int, unsigned long) __intentional_overflow(-1);
  51887. /*
  51888. * If we don't support core dumping, then supply a NULL so we
  51889. @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
  51890. #define elf_core_dump NULL
  51891. #endif
  51892. +#ifdef CONFIG_PAX_MPROTECT
  51893. +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
  51894. +#endif
  51895. +
  51896. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  51897. +static void elf_handle_mmap(struct file *file);
  51898. +#endif
  51899. +
  51900. #if ELF_EXEC_PAGESIZE > PAGE_SIZE
  51901. #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
  51902. #else
  51903. @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
  51904. .load_binary = load_elf_binary,
  51905. .load_shlib = load_elf_library,
  51906. .core_dump = elf_core_dump,
  51907. +
  51908. +#ifdef CONFIG_PAX_MPROTECT
  51909. + .handle_mprotect= elf_handle_mprotect,
  51910. +#endif
  51911. +
  51912. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  51913. + .handle_mmap = elf_handle_mmap,
  51914. +#endif
  51915. +
  51916. .min_coredump = ELF_EXEC_PAGESIZE,
  51917. };
  51918. @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
  51919. static int set_brk(unsigned long start, unsigned long end)
  51920. {
  51921. + unsigned long e = end;
  51922. +
  51923. start = ELF_PAGEALIGN(start);
  51924. end = ELF_PAGEALIGN(end);
  51925. if (end > start) {
  51926. @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
  51927. if (BAD_ADDR(addr))
  51928. return addr;
  51929. }
  51930. - current->mm->start_brk = current->mm->brk = end;
  51931. + current->mm->start_brk = current->mm->brk = e;
  51932. return 0;
  51933. }
  51934. @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
  51935. elf_addr_t __user *u_rand_bytes;
  51936. const char *k_platform = ELF_PLATFORM;
  51937. const char *k_base_platform = ELF_BASE_PLATFORM;
  51938. - unsigned char k_rand_bytes[16];
  51939. + u32 k_rand_bytes[4];
  51940. int items;
  51941. elf_addr_t *elf_info;
  51942. int ei_index = 0;
  51943. const struct cred *cred = current_cred();
  51944. struct vm_area_struct *vma;
  51945. + unsigned long saved_auxv[AT_VECTOR_SIZE];
  51946. /*
  51947. * In some cases (e.g. Hyper-Threading), we want to avoid L1
  51948. @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
  51949. * Generate 16 random bytes for userspace PRNG seeding.
  51950. */
  51951. get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
  51952. - u_rand_bytes = (elf_addr_t __user *)
  51953. - STACK_ALLOC(p, sizeof(k_rand_bytes));
  51954. + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
  51955. + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
  51956. + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
  51957. + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
  51958. + p = STACK_ROUND(p, sizeof(k_rand_bytes));
  51959. + u_rand_bytes = (elf_addr_t __user *) p;
  51960. if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
  51961. return -EFAULT;
  51962. @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
  51963. return -EFAULT;
  51964. current->mm->env_end = p;
  51965. + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
  51966. +
  51967. /* Put the elf_info on the stack in the right place. */
  51968. sp = (elf_addr_t __user *)envp + 1;
  51969. - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
  51970. + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
  51971. return -EFAULT;
  51972. return 0;
  51973. }
  51974. @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
  51975. an ELF header */
  51976. static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
  51977. - struct file *interpreter, unsigned long *interp_map_addr,
  51978. - unsigned long no_base)
  51979. + struct file *interpreter, unsigned long no_base)
  51980. {
  51981. struct elf_phdr *elf_phdata;
  51982. struct elf_phdr *eppnt;
  51983. - unsigned long load_addr = 0;
  51984. + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
  51985. int load_addr_set = 0;
  51986. unsigned long last_bss = 0, elf_bss = 0;
  51987. - unsigned long error = ~0UL;
  51988. + unsigned long error = -EINVAL;
  51989. unsigned long total_size;
  51990. int retval, i, size;
  51991. @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
  51992. goto out_close;
  51993. }
  51994. +#ifdef CONFIG_PAX_SEGMEXEC
  51995. + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
  51996. + pax_task_size = SEGMEXEC_TASK_SIZE;
  51997. +#endif
  51998. +
  51999. eppnt = elf_phdata;
  52000. for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
  52001. if (eppnt->p_type == PT_LOAD) {
  52002. @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
  52003. map_addr = elf_map(interpreter, load_addr + vaddr,
  52004. eppnt, elf_prot, elf_type, total_size);
  52005. total_size = 0;
  52006. - if (!*interp_map_addr)
  52007. - *interp_map_addr = map_addr;
  52008. error = map_addr;
  52009. if (BAD_ADDR(map_addr))
  52010. goto out_close;
  52011. @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
  52012. k = load_addr + eppnt->p_vaddr;
  52013. if (BAD_ADDR(k) ||
  52014. eppnt->p_filesz > eppnt->p_memsz ||
  52015. - eppnt->p_memsz > TASK_SIZE ||
  52016. - TASK_SIZE - eppnt->p_memsz < k) {
  52017. + eppnt->p_memsz > pax_task_size ||
  52018. + pax_task_size - eppnt->p_memsz < k) {
  52019. error = -ENOMEM;
  52020. goto out_close;
  52021. }
  52022. @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
  52023. elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
  52024. /* Map the last of the bss segment */
  52025. - error = vm_brk(elf_bss, last_bss - elf_bss);
  52026. - if (BAD_ADDR(error))
  52027. - goto out_close;
  52028. + if (last_bss > elf_bss) {
  52029. + error = vm_brk(elf_bss, last_bss - elf_bss);
  52030. + if (BAD_ADDR(error))
  52031. + goto out_close;
  52032. + }
  52033. }
  52034. error = load_addr;
  52035. @@ -538,6 +569,336 @@ out:
  52036. return error;
  52037. }
  52038. +#ifdef CONFIG_PAX_PT_PAX_FLAGS
  52039. +#ifdef CONFIG_PAX_SOFTMODE
  52040. +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
  52041. +{
  52042. + unsigned long pax_flags = 0UL;
  52043. +
  52044. +#ifdef CONFIG_PAX_PAGEEXEC
  52045. + if (elf_phdata->p_flags & PF_PAGEEXEC)
  52046. + pax_flags |= MF_PAX_PAGEEXEC;
  52047. +#endif
  52048. +
  52049. +#ifdef CONFIG_PAX_SEGMEXEC
  52050. + if (elf_phdata->p_flags & PF_SEGMEXEC)
  52051. + pax_flags |= MF_PAX_SEGMEXEC;
  52052. +#endif
  52053. +
  52054. +#ifdef CONFIG_PAX_EMUTRAMP
  52055. + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
  52056. + pax_flags |= MF_PAX_EMUTRAMP;
  52057. +#endif
  52058. +
  52059. +#ifdef CONFIG_PAX_MPROTECT
  52060. + if (elf_phdata->p_flags & PF_MPROTECT)
  52061. + pax_flags |= MF_PAX_MPROTECT;
  52062. +#endif
  52063. +
  52064. +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
  52065. + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
  52066. + pax_flags |= MF_PAX_RANDMMAP;
  52067. +#endif
  52068. +
  52069. + return pax_flags;
  52070. +}
  52071. +#endif
  52072. +
  52073. +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
  52074. +{
  52075. + unsigned long pax_flags = 0UL;
  52076. +
  52077. +#ifdef CONFIG_PAX_PAGEEXEC
  52078. + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
  52079. + pax_flags |= MF_PAX_PAGEEXEC;
  52080. +#endif
  52081. +
  52082. +#ifdef CONFIG_PAX_SEGMEXEC
  52083. + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
  52084. + pax_flags |= MF_PAX_SEGMEXEC;
  52085. +#endif
  52086. +
  52087. +#ifdef CONFIG_PAX_EMUTRAMP
  52088. + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
  52089. + pax_flags |= MF_PAX_EMUTRAMP;
  52090. +#endif
  52091. +
  52092. +#ifdef CONFIG_PAX_MPROTECT
  52093. + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
  52094. + pax_flags |= MF_PAX_MPROTECT;
  52095. +#endif
  52096. +
  52097. +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
  52098. + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
  52099. + pax_flags |= MF_PAX_RANDMMAP;
  52100. +#endif
  52101. +
  52102. + return pax_flags;
  52103. +}
  52104. +#endif
  52105. +
  52106. +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
  52107. +#ifdef CONFIG_PAX_SOFTMODE
  52108. +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
  52109. +{
  52110. + unsigned long pax_flags = 0UL;
  52111. +
  52112. +#ifdef CONFIG_PAX_PAGEEXEC
  52113. + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
  52114. + pax_flags |= MF_PAX_PAGEEXEC;
  52115. +#endif
  52116. +
  52117. +#ifdef CONFIG_PAX_SEGMEXEC
  52118. + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
  52119. + pax_flags |= MF_PAX_SEGMEXEC;
  52120. +#endif
  52121. +
  52122. +#ifdef CONFIG_PAX_EMUTRAMP
  52123. + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
  52124. + pax_flags |= MF_PAX_EMUTRAMP;
  52125. +#endif
  52126. +
  52127. +#ifdef CONFIG_PAX_MPROTECT
  52128. + if (pax_flags_softmode & MF_PAX_MPROTECT)
  52129. + pax_flags |= MF_PAX_MPROTECT;
  52130. +#endif
  52131. +
  52132. +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
  52133. + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
  52134. + pax_flags |= MF_PAX_RANDMMAP;
  52135. +#endif
  52136. +
  52137. + return pax_flags;
  52138. +}
  52139. +#endif
  52140. +
  52141. +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
  52142. +{
  52143. + unsigned long pax_flags = 0UL;
  52144. +
  52145. +#ifdef CONFIG_PAX_PAGEEXEC
  52146. + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
  52147. + pax_flags |= MF_PAX_PAGEEXEC;
  52148. +#endif
  52149. +
  52150. +#ifdef CONFIG_PAX_SEGMEXEC
  52151. + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
  52152. + pax_flags |= MF_PAX_SEGMEXEC;
  52153. +#endif
  52154. +
  52155. +#ifdef CONFIG_PAX_EMUTRAMP
  52156. + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
  52157. + pax_flags |= MF_PAX_EMUTRAMP;
  52158. +#endif
  52159. +
  52160. +#ifdef CONFIG_PAX_MPROTECT
  52161. + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
  52162. + pax_flags |= MF_PAX_MPROTECT;
  52163. +#endif
  52164. +
  52165. +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
  52166. + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
  52167. + pax_flags |= MF_PAX_RANDMMAP;
  52168. +#endif
  52169. +
  52170. + return pax_flags;
  52171. +}
  52172. +#endif
  52173. +
  52174. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  52175. +static unsigned long pax_parse_defaults(void)
  52176. +{
  52177. + unsigned long pax_flags = 0UL;
  52178. +
  52179. +#ifdef CONFIG_PAX_SOFTMODE
  52180. + if (pax_softmode)
  52181. + return pax_flags;
  52182. +#endif
  52183. +
  52184. +#ifdef CONFIG_PAX_PAGEEXEC
  52185. + pax_flags |= MF_PAX_PAGEEXEC;
  52186. +#endif
  52187. +
  52188. +#ifdef CONFIG_PAX_SEGMEXEC
  52189. + pax_flags |= MF_PAX_SEGMEXEC;
  52190. +#endif
  52191. +
  52192. +#ifdef CONFIG_PAX_MPROTECT
  52193. + pax_flags |= MF_PAX_MPROTECT;
  52194. +#endif
  52195. +
  52196. +#ifdef CONFIG_PAX_RANDMMAP
  52197. + if (randomize_va_space)
  52198. + pax_flags |= MF_PAX_RANDMMAP;
  52199. +#endif
  52200. +
  52201. + return pax_flags;
  52202. +}
  52203. +
  52204. +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
  52205. +{
  52206. + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
  52207. +
  52208. +#ifdef CONFIG_PAX_EI_PAX
  52209. +
  52210. +#ifdef CONFIG_PAX_SOFTMODE
  52211. + if (pax_softmode)
  52212. + return pax_flags;
  52213. +#endif
  52214. +
  52215. + pax_flags = 0UL;
  52216. +
  52217. +#ifdef CONFIG_PAX_PAGEEXEC
  52218. + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
  52219. + pax_flags |= MF_PAX_PAGEEXEC;
  52220. +#endif
  52221. +
  52222. +#ifdef CONFIG_PAX_SEGMEXEC
  52223. + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
  52224. + pax_flags |= MF_PAX_SEGMEXEC;
  52225. +#endif
  52226. +
  52227. +#ifdef CONFIG_PAX_EMUTRAMP
  52228. + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
  52229. + pax_flags |= MF_PAX_EMUTRAMP;
  52230. +#endif
  52231. +
  52232. +#ifdef CONFIG_PAX_MPROTECT
  52233. + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
  52234. + pax_flags |= MF_PAX_MPROTECT;
  52235. +#endif
  52236. +
  52237. +#ifdef CONFIG_PAX_ASLR
  52238. + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
  52239. + pax_flags |= MF_PAX_RANDMMAP;
  52240. +#endif
  52241. +
  52242. +#endif
  52243. +
  52244. + return pax_flags;
  52245. +
  52246. +}
  52247. +
  52248. +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
  52249. +{
  52250. +
  52251. +#ifdef CONFIG_PAX_PT_PAX_FLAGS
  52252. + unsigned long i;
  52253. +
  52254. + for (i = 0UL; i < elf_ex->e_phnum; i++)
  52255. + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
  52256. + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
  52257. + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
  52258. + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
  52259. + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
  52260. + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
  52261. + return PAX_PARSE_FLAGS_FALLBACK;
  52262. +
  52263. +#ifdef CONFIG_PAX_SOFTMODE
  52264. + if (pax_softmode)
  52265. + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
  52266. + else
  52267. +#endif
  52268. +
  52269. + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
  52270. + break;
  52271. + }
  52272. +#endif
  52273. +
  52274. + return PAX_PARSE_FLAGS_FALLBACK;
  52275. +}
  52276. +
  52277. +static unsigned long pax_parse_xattr_pax(struct file * const file)
  52278. +{
  52279. +
  52280. +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
  52281. + ssize_t xattr_size, i;
  52282. + unsigned char xattr_value[sizeof("pemrs") - 1];
  52283. + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
  52284. +
  52285. + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
  52286. + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
  52287. + return PAX_PARSE_FLAGS_FALLBACK;
  52288. +
  52289. + for (i = 0; i < xattr_size; i++)
  52290. + switch (xattr_value[i]) {
  52291. + default:
  52292. + return PAX_PARSE_FLAGS_FALLBACK;
  52293. +
  52294. +#define parse_flag(option1, option2, flag) \
  52295. + case option1: \
  52296. + if (pax_flags_hardmode & MF_PAX_##flag) \
  52297. + return PAX_PARSE_FLAGS_FALLBACK;\
  52298. + pax_flags_hardmode |= MF_PAX_##flag; \
  52299. + break; \
  52300. + case option2: \
  52301. + if (pax_flags_softmode & MF_PAX_##flag) \
  52302. + return PAX_PARSE_FLAGS_FALLBACK;\
  52303. + pax_flags_softmode |= MF_PAX_##flag; \
  52304. + break;
  52305. +
  52306. + parse_flag('p', 'P', PAGEEXEC);
  52307. + parse_flag('e', 'E', EMUTRAMP);
  52308. + parse_flag('m', 'M', MPROTECT);
  52309. + parse_flag('r', 'R', RANDMMAP);
  52310. + parse_flag('s', 'S', SEGMEXEC);
  52311. +
  52312. +#undef parse_flag
  52313. + }
  52314. +
  52315. + if (pax_flags_hardmode & pax_flags_softmode)
  52316. + return PAX_PARSE_FLAGS_FALLBACK;
  52317. +
  52318. +#ifdef CONFIG_PAX_SOFTMODE
  52319. + if (pax_softmode)
  52320. + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
  52321. + else
  52322. +#endif
  52323. +
  52324. + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
  52325. +#else
  52326. + return PAX_PARSE_FLAGS_FALLBACK;
  52327. +#endif
  52328. +
  52329. +}
  52330. +
  52331. +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
  52332. +{
  52333. + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
  52334. +
  52335. + pax_flags = pax_parse_defaults();
  52336. + ei_pax_flags = pax_parse_ei_pax(elf_ex);
  52337. + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
  52338. + xattr_pax_flags = pax_parse_xattr_pax(file);
  52339. +
  52340. + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
  52341. + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
  52342. + pt_pax_flags != xattr_pax_flags)
  52343. + return -EINVAL;
  52344. + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
  52345. + pax_flags = xattr_pax_flags;
  52346. + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
  52347. + pax_flags = pt_pax_flags;
  52348. + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
  52349. + pax_flags = ei_pax_flags;
  52350. +
  52351. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
  52352. + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
  52353. + if ((__supported_pte_mask & _PAGE_NX))
  52354. + pax_flags &= ~MF_PAX_SEGMEXEC;
  52355. + else
  52356. + pax_flags &= ~MF_PAX_PAGEEXEC;
  52357. + }
  52358. +#endif
  52359. +
  52360. + if (0 > pax_check_flags(&pax_flags))
  52361. + return -EINVAL;
  52362. +
  52363. + current->mm->pax_flags = pax_flags;
  52364. + return 0;
  52365. +}
  52366. +#endif
  52367. +
  52368. /*
  52369. * These are the functions used to load ELF style executables and shared
  52370. * libraries. There is no binary dependent code anywhere else.
  52371. @@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
  52372. {
  52373. unsigned int random_variable = 0;
  52374. +#ifdef CONFIG_PAX_RANDUSTACK
  52375. + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
  52376. + return stack_top - current->mm->delta_stack;
  52377. +#endif
  52378. +
  52379. if ((current->flags & PF_RANDOMIZE) &&
  52380. !(current->personality & ADDR_NO_RANDOMIZE)) {
  52381. random_variable = get_random_int() & STACK_RND_MASK;
  52382. @@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
  52383. unsigned long load_addr = 0, load_bias = 0;
  52384. int load_addr_set = 0;
  52385. char * elf_interpreter = NULL;
  52386. - unsigned long error;
  52387. + unsigned long error = 0;
  52388. struct elf_phdr *elf_ppnt, *elf_phdata;
  52389. unsigned long elf_bss, elf_brk;
  52390. int retval, i;
  52391. @@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
  52392. unsigned long start_code, end_code, start_data, end_data;
  52393. unsigned long reloc_func_desc __maybe_unused = 0;
  52394. int executable_stack = EXSTACK_DEFAULT;
  52395. - unsigned long def_flags = 0;
  52396. struct pt_regs *regs = current_pt_regs();
  52397. struct {
  52398. struct elfhdr elf_ex;
  52399. struct elfhdr interp_elf_ex;
  52400. } *loc;
  52401. + unsigned long pax_task_size;
  52402. loc = kmalloc(sizeof(*loc), GFP_KERNEL);
  52403. if (!loc) {
  52404. @@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
  52405. goto out_free_dentry;
  52406. /* OK, This is the point of no return */
  52407. - current->mm->def_flags = def_flags;
  52408. + current->mm->def_flags = 0;
  52409. /* Do this immediately, since STACK_TOP as used in setup_arg_pages
  52410. may depend on the personality. */
  52411. SET_PERSONALITY(loc->elf_ex);
  52412. +
  52413. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  52414. + current->mm->pax_flags = 0UL;
  52415. +#endif
  52416. +
  52417. +#ifdef CONFIG_PAX_DLRESOLVE
  52418. + current->mm->call_dl_resolve = 0UL;
  52419. +#endif
  52420. +
  52421. +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
  52422. + current->mm->call_syscall = 0UL;
  52423. +#endif
  52424. +
  52425. +#ifdef CONFIG_PAX_ASLR
  52426. + current->mm->delta_mmap = 0UL;
  52427. + current->mm->delta_stack = 0UL;
  52428. +#endif
  52429. +
  52430. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  52431. + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
  52432. + send_sig(SIGKILL, current, 0);
  52433. + goto out_free_dentry;
  52434. + }
  52435. +#endif
  52436. +
  52437. +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
  52438. + pax_set_initial_flags(bprm);
  52439. +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
  52440. + if (pax_set_initial_flags_func)
  52441. + (pax_set_initial_flags_func)(bprm);
  52442. +#endif
  52443. +
  52444. +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
  52445. + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
  52446. + current->mm->context.user_cs_limit = PAGE_SIZE;
  52447. + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
  52448. + }
  52449. +#endif
  52450. +
  52451. +#ifdef CONFIG_PAX_SEGMEXEC
  52452. + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
  52453. + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
  52454. + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
  52455. + pax_task_size = SEGMEXEC_TASK_SIZE;
  52456. + current->mm->def_flags |= VM_NOHUGEPAGE;
  52457. + } else
  52458. +#endif
  52459. +
  52460. + pax_task_size = TASK_SIZE;
  52461. +
  52462. +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
  52463. + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
  52464. + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
  52465. + put_cpu();
  52466. + }
  52467. +#endif
  52468. +
  52469. +#ifdef CONFIG_PAX_ASLR
  52470. + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
  52471. + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
  52472. + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
  52473. + }
  52474. +#endif
  52475. +
  52476. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  52477. + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
  52478. + executable_stack = EXSTACK_DISABLE_X;
  52479. + current->personality &= ~READ_IMPLIES_EXEC;
  52480. + } else
  52481. +#endif
  52482. +
  52483. if (elf_read_implies_exec(loc->elf_ex, executable_stack))
  52484. current->personality |= READ_IMPLIES_EXEC;
  52485. @@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
  52486. #else
  52487. load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
  52488. #endif
  52489. +
  52490. +#ifdef CONFIG_PAX_RANDMMAP
  52491. + /* PaX: randomize base address at the default exe base if requested */
  52492. + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
  52493. +#ifdef CONFIG_SPARC64
  52494. + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
  52495. +#else
  52496. + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
  52497. +#endif
  52498. + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
  52499. + elf_flags |= MAP_FIXED;
  52500. + }
  52501. +#endif
  52502. +
  52503. }
  52504. error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
  52505. @@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
  52506. * allowed task size. Note that p_filesz must always be
  52507. * <= p_memsz so it is only necessary to check p_memsz.
  52508. */
  52509. - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
  52510. - elf_ppnt->p_memsz > TASK_SIZE ||
  52511. - TASK_SIZE - elf_ppnt->p_memsz < k) {
  52512. + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
  52513. + elf_ppnt->p_memsz > pax_task_size ||
  52514. + pax_task_size - elf_ppnt->p_memsz < k) {
  52515. /* set_brk can never work. Avoid overflows. */
  52516. send_sig(SIGKILL, current, 0);
  52517. retval = -EINVAL;
  52518. @@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
  52519. goto out_free_dentry;
  52520. }
  52521. if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
  52522. - send_sig(SIGSEGV, current, 0);
  52523. - retval = -EFAULT; /* Nobody gets to see this, but.. */
  52524. - goto out_free_dentry;
  52525. + /*
  52526. + * This bss-zeroing can fail if the ELF
  52527. + * file specifies odd protections. So
  52528. + * we don't check the return value
  52529. + */
  52530. }
  52531. +#ifdef CONFIG_PAX_RANDMMAP
  52532. + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
  52533. + unsigned long start, size, flags;
  52534. + vm_flags_t vm_flags;
  52535. +
  52536. + start = ELF_PAGEALIGN(elf_brk);
  52537. + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
  52538. + flags = MAP_FIXED | MAP_PRIVATE;
  52539. + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
  52540. +
  52541. + down_write(&current->mm->mmap_sem);
  52542. + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
  52543. + retval = -ENOMEM;
  52544. + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
  52545. +// if (current->personality & ADDR_NO_RANDOMIZE)
  52546. +// vm_flags |= VM_READ | VM_MAYREAD;
  52547. + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
  52548. + retval = IS_ERR_VALUE(start) ? start : 0;
  52549. + }
  52550. + up_write(&current->mm->mmap_sem);
  52551. + if (retval == 0)
  52552. + retval = set_brk(start + size, start + size + PAGE_SIZE);
  52553. + if (retval < 0) {
  52554. + send_sig(SIGKILL, current, 0);
  52555. + goto out_free_dentry;
  52556. + }
  52557. + }
  52558. +#endif
  52559. +
  52560. if (elf_interpreter) {
  52561. - unsigned long interp_map_addr = 0;
  52562. -
  52563. elf_entry = load_elf_interp(&loc->interp_elf_ex,
  52564. interpreter,
  52565. - &interp_map_addr,
  52566. load_bias);
  52567. if (!IS_ERR((void *)elf_entry)) {
  52568. /*
  52569. @@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
  52570. * Decide what to dump of a segment, part, all or none.
  52571. */
  52572. static unsigned long vma_dump_size(struct vm_area_struct *vma,
  52573. - unsigned long mm_flags)
  52574. + unsigned long mm_flags, long signr)
  52575. {
  52576. #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
  52577. @@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
  52578. if (vma->vm_file == NULL)
  52579. return 0;
  52580. - if (FILTER(MAPPED_PRIVATE))
  52581. + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
  52582. goto whole;
  52583. /*
  52584. @@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
  52585. {
  52586. elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
  52587. int i = 0;
  52588. - do
  52589. + do {
  52590. i += 2;
  52591. - while (auxv[i - 2] != AT_NULL);
  52592. + } while (auxv[i - 2] != AT_NULL);
  52593. fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
  52594. }
  52595. @@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
  52596. {
  52597. mm_segment_t old_fs = get_fs();
  52598. set_fs(KERNEL_DS);
  52599. - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
  52600. + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
  52601. set_fs(old_fs);
  52602. fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
  52603. }
  52604. @@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
  52605. }
  52606. static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
  52607. - unsigned long mm_flags)
  52608. + struct coredump_params *cprm)
  52609. {
  52610. struct vm_area_struct *vma;
  52611. size_t size = 0;
  52612. for (vma = first_vma(current, gate_vma); vma != NULL;
  52613. vma = next_vma(vma, gate_vma))
  52614. - size += vma_dump_size(vma, mm_flags);
  52615. + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
  52616. return size;
  52617. }
  52618. @@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
  52619. dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
  52620. - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
  52621. + offset += elf_core_vma_data_size(gate_vma, cprm);
  52622. offset += elf_core_extra_data_size();
  52623. e_shoff = offset;
  52624. @@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
  52625. phdr.p_offset = offset;
  52626. phdr.p_vaddr = vma->vm_start;
  52627. phdr.p_paddr = 0;
  52628. - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
  52629. + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
  52630. phdr.p_memsz = vma->vm_end - vma->vm_start;
  52631. offset += phdr.p_filesz;
  52632. phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
  52633. @@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
  52634. unsigned long addr;
  52635. unsigned long end;
  52636. - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
  52637. + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
  52638. for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
  52639. struct page *page;
  52640. @@ -2199,6 +2678,167 @@ out:
  52641. #endif /* CONFIG_ELF_CORE */
  52642. +#ifdef CONFIG_PAX_MPROTECT
  52643. +/* PaX: non-PIC ELF libraries need relocations on their executable segments
  52644. + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
  52645. + * we'll remove VM_MAYWRITE for good on RELRO segments.
  52646. + *
  52647. + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
  52648. + * basis because we want to allow the common case and not the special ones.
  52649. + */
  52650. +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
  52651. +{
  52652. + struct elfhdr elf_h;
  52653. + struct elf_phdr elf_p;
  52654. + unsigned long i;
  52655. + unsigned long oldflags;
  52656. + bool is_textrel_rw, is_textrel_rx, is_relro;
  52657. +
  52658. + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
  52659. + return;
  52660. +
  52661. + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
  52662. + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
  52663. +
  52664. +#ifdef CONFIG_PAX_ELFRELOCS
  52665. + /* possible TEXTREL */
  52666. + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
  52667. + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
  52668. +#else
  52669. + is_textrel_rw = false;
  52670. + is_textrel_rx = false;
  52671. +#endif
  52672. +
  52673. + /* possible RELRO */
  52674. + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
  52675. +
  52676. + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
  52677. + return;
  52678. +
  52679. + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
  52680. + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
  52681. +
  52682. +#ifdef CONFIG_PAX_ETEXECRELOCS
  52683. + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
  52684. +#else
  52685. + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
  52686. +#endif
  52687. +
  52688. + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
  52689. + !elf_check_arch(&elf_h) ||
  52690. + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
  52691. + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
  52692. + return;
  52693. +
  52694. + for (i = 0UL; i < elf_h.e_phnum; i++) {
  52695. + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
  52696. + return;
  52697. + switch (elf_p.p_type) {
  52698. + case PT_DYNAMIC:
  52699. + if (!is_textrel_rw && !is_textrel_rx)
  52700. + continue;
  52701. + i = 0UL;
  52702. + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
  52703. + elf_dyn dyn;
  52704. +
  52705. + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
  52706. + break;
  52707. + if (dyn.d_tag == DT_NULL)
  52708. + break;
  52709. + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
  52710. + gr_log_textrel(vma);
  52711. + if (is_textrel_rw)
  52712. + vma->vm_flags |= VM_MAYWRITE;
  52713. + else
  52714. + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
  52715. + vma->vm_flags &= ~VM_MAYWRITE;
  52716. + break;
  52717. + }
  52718. + i++;
  52719. + }
  52720. + is_textrel_rw = false;
  52721. + is_textrel_rx = false;
  52722. + continue;
  52723. +
  52724. + case PT_GNU_RELRO:
  52725. + if (!is_relro)
  52726. + continue;
  52727. + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
  52728. + vma->vm_flags &= ~VM_MAYWRITE;
  52729. + is_relro = false;
  52730. + continue;
  52731. +
  52732. +#ifdef CONFIG_PAX_PT_PAX_FLAGS
  52733. + case PT_PAX_FLAGS: {
  52734. + const char *msg_mprotect = "", *msg_emutramp = "";
  52735. + char *buffer_lib, *buffer_exe;
  52736. +
  52737. + if (elf_p.p_flags & PF_NOMPROTECT)
  52738. + msg_mprotect = "MPROTECT disabled";
  52739. +
  52740. +#ifdef CONFIG_PAX_EMUTRAMP
  52741. + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
  52742. + msg_emutramp = "EMUTRAMP enabled";
  52743. +#endif
  52744. +
  52745. + if (!msg_mprotect[0] && !msg_emutramp[0])
  52746. + continue;
  52747. +
  52748. + if (!printk_ratelimit())
  52749. + continue;
  52750. +
  52751. + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
  52752. + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
  52753. + if (buffer_lib && buffer_exe) {
  52754. + char *path_lib, *path_exe;
  52755. +
  52756. + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
  52757. + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
  52758. +
  52759. + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
  52760. + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
  52761. +
  52762. + }
  52763. + free_page((unsigned long)buffer_exe);
  52764. + free_page((unsigned long)buffer_lib);
  52765. + continue;
  52766. + }
  52767. +#endif
  52768. +
  52769. + }
  52770. + }
  52771. +}
  52772. +#endif
  52773. +
  52774. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  52775. +
  52776. +extern int grsec_enable_log_rwxmaps;
  52777. +
  52778. +static void elf_handle_mmap(struct file *file)
  52779. +{
  52780. + struct elfhdr elf_h;
  52781. + struct elf_phdr elf_p;
  52782. + unsigned long i;
  52783. +
  52784. + if (!grsec_enable_log_rwxmaps)
  52785. + return;
  52786. +
  52787. + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
  52788. + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
  52789. + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
  52790. + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
  52791. + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
  52792. + return;
  52793. +
  52794. + for (i = 0UL; i < elf_h.e_phnum; i++) {
  52795. + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
  52796. + return;
  52797. + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
  52798. + gr_log_ptgnustack(file);
  52799. + }
  52800. +}
  52801. +#endif
  52802. +
  52803. static int __init init_elf_binfmt(void)
  52804. {
  52805. register_binfmt(&elf_format);
  52806. diff --git a/fs/bio.c b/fs/bio.c
  52807. index 8754e7b..0669094 100644
  52808. --- a/fs/bio.c
  52809. +++ b/fs/bio.c
  52810. @@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
  52811. /*
  52812. * Overflow, abort
  52813. */
  52814. - if (end < start)
  52815. + if (end < start || end - start > INT_MAX - nr_pages)
  52816. return ERR_PTR(-EINVAL);
  52817. nr_pages += end - start;
  52818. @@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
  52819. /*
  52820. * Overflow, abort
  52821. */
  52822. - if (end < start)
  52823. + if (end < start || end - start > INT_MAX - nr_pages)
  52824. return ERR_PTR(-EINVAL);
  52825. nr_pages += end - start;
  52826. @@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
  52827. const int read = bio_data_dir(bio) == READ;
  52828. struct bio_map_data *bmd = bio->bi_private;
  52829. int i;
  52830. - char *p = bmd->sgvecs[0].iov_base;
  52831. + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
  52832. bio_for_each_segment_all(bvec, bio, i) {
  52833. char *addr = page_address(bvec->bv_page);
  52834. diff --git a/fs/block_dev.c b/fs/block_dev.c
  52835. index 1e86823..8e34695 100644
  52836. --- a/fs/block_dev.c
  52837. +++ b/fs/block_dev.c
  52838. @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
  52839. else if (bdev->bd_contains == bdev)
  52840. return true; /* is a whole device which isn't held */
  52841. - else if (whole->bd_holder == bd_may_claim)
  52842. + else if (whole->bd_holder == (void *)bd_may_claim)
  52843. return true; /* is a partition of a device that is being partitioned */
  52844. else if (whole->bd_holder != NULL)
  52845. return false; /* is a partition of a held device */
  52846. diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
  52847. index cbd3a7d..c6a2881 100644
  52848. --- a/fs/btrfs/ctree.c
  52849. +++ b/fs/btrfs/ctree.c
  52850. @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
  52851. free_extent_buffer(buf);
  52852. add_root_to_dirty_list(root);
  52853. } else {
  52854. - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
  52855. - parent_start = parent->start;
  52856. - else
  52857. + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
  52858. + if (parent)
  52859. + parent_start = parent->start;
  52860. + else
  52861. + parent_start = 0;
  52862. + } else
  52863. parent_start = 0;
  52864. WARN_ON(trans->transid != btrfs_header_generation(parent));
  52865. diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
  52866. index 451b00c..a2cccee 100644
  52867. --- a/fs/btrfs/delayed-inode.c
  52868. +++ b/fs/btrfs/delayed-inode.c
  52869. @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
  52870. static void finish_one_item(struct btrfs_delayed_root *delayed_root)
  52871. {
  52872. - int seq = atomic_inc_return(&delayed_root->items_seq);
  52873. + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
  52874. if ((atomic_dec_return(&delayed_root->items) <
  52875. BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
  52876. waitqueue_active(&delayed_root->wait))
  52877. @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
  52878. static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
  52879. {
  52880. - int val = atomic_read(&delayed_root->items_seq);
  52881. + int val = atomic_read_unchecked(&delayed_root->items_seq);
  52882. if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
  52883. return 1;
  52884. @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
  52885. int seq;
  52886. int ret;
  52887. - seq = atomic_read(&delayed_root->items_seq);
  52888. + seq = atomic_read_unchecked(&delayed_root->items_seq);
  52889. ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
  52890. if (ret)
  52891. diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
  52892. index f70119f..ab5894d 100644
  52893. --- a/fs/btrfs/delayed-inode.h
  52894. +++ b/fs/btrfs/delayed-inode.h
  52895. @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
  52896. */
  52897. struct list_head prepare_list;
  52898. atomic_t items; /* for delayed items */
  52899. - atomic_t items_seq; /* for delayed items */
  52900. + atomic_unchecked_t items_seq; /* for delayed items */
  52901. int nodes; /* for delayed nodes */
  52902. wait_queue_head_t wait;
  52903. };
  52904. @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
  52905. struct btrfs_delayed_root *delayed_root)
  52906. {
  52907. atomic_set(&delayed_root->items, 0);
  52908. - atomic_set(&delayed_root->items_seq, 0);
  52909. + atomic_set_unchecked(&delayed_root->items_seq, 0);
  52910. delayed_root->nodes = 0;
  52911. spin_lock_init(&delayed_root->lock);
  52912. init_waitqueue_head(&delayed_root->wait);
  52913. diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
  52914. index a6d8efa..2f062cf 100644
  52915. --- a/fs/btrfs/ioctl.c
  52916. +++ b/fs/btrfs/ioctl.c
  52917. @@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
  52918. for (i = 0; i < num_types; i++) {
  52919. struct btrfs_space_info *tmp;
  52920. + /* Don't copy in more than we allocated */
  52921. if (!slot_count)
  52922. break;
  52923. + slot_count--;
  52924. +
  52925. info = NULL;
  52926. rcu_read_lock();
  52927. list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
  52928. @@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
  52929. memcpy(dest, &space, sizeof(space));
  52930. dest++;
  52931. space_args.total_spaces++;
  52932. - slot_count--;
  52933. }
  52934. - if (!slot_count)
  52935. - break;
  52936. }
  52937. up_read(&info->groups_sem);
  52938. }
  52939. diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
  52940. index d04db81..96e54f1 100644
  52941. --- a/fs/btrfs/super.c
  52942. +++ b/fs/btrfs/super.c
  52943. @@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
  52944. function, line, errstr);
  52945. return;
  52946. }
  52947. - ACCESS_ONCE(trans->transaction->aborted) = errno;
  52948. + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
  52949. /* Wake up anybody who may be waiting on this transaction */
  52950. wake_up(&root->fs_info->transaction_wait);
  52951. wake_up(&root->fs_info->transaction_blocked_wait);
  52952. diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
  52953. index 865f4cf..f321e86 100644
  52954. --- a/fs/btrfs/sysfs.c
  52955. +++ b/fs/btrfs/sysfs.c
  52956. @@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
  52957. for (set = 0; set < FEAT_MAX; set++) {
  52958. int i;
  52959. struct attribute *attrs[2];
  52960. - struct attribute_group agroup = {
  52961. + attribute_group_no_const agroup = {
  52962. .name = "features",
  52963. .attrs = attrs,
  52964. };
  52965. diff --git a/fs/buffer.c b/fs/buffer.c
  52966. index 27265a8..289f488 100644
  52967. --- a/fs/buffer.c
  52968. +++ b/fs/buffer.c
  52969. @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
  52970. bh_cachep = kmem_cache_create("buffer_head",
  52971. sizeof(struct buffer_head), 0,
  52972. (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
  52973. - SLAB_MEM_SPREAD),
  52974. + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
  52975. NULL);
  52976. /*
  52977. diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
  52978. index 622f469..e8d2d55 100644
  52979. --- a/fs/cachefiles/bind.c
  52980. +++ b/fs/cachefiles/bind.c
  52981. @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
  52982. args);
  52983. /* start by checking things over */
  52984. - ASSERT(cache->fstop_percent >= 0 &&
  52985. - cache->fstop_percent < cache->fcull_percent &&
  52986. + ASSERT(cache->fstop_percent < cache->fcull_percent &&
  52987. cache->fcull_percent < cache->frun_percent &&
  52988. cache->frun_percent < 100);
  52989. - ASSERT(cache->bstop_percent >= 0 &&
  52990. - cache->bstop_percent < cache->bcull_percent &&
  52991. + ASSERT(cache->bstop_percent < cache->bcull_percent &&
  52992. cache->bcull_percent < cache->brun_percent &&
  52993. cache->brun_percent < 100);
  52994. diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
  52995. index 0a1467b..6a53245 100644
  52996. --- a/fs/cachefiles/daemon.c
  52997. +++ b/fs/cachefiles/daemon.c
  52998. @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
  52999. if (n > buflen)
  53000. return -EMSGSIZE;
  53001. - if (copy_to_user(_buffer, buffer, n) != 0)
  53002. + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
  53003. return -EFAULT;
  53004. return n;
  53005. @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
  53006. if (test_bit(CACHEFILES_DEAD, &cache->flags))
  53007. return -EIO;
  53008. - if (datalen < 0 || datalen > PAGE_SIZE - 1)
  53009. + if (datalen > PAGE_SIZE - 1)
  53010. return -EOPNOTSUPP;
  53011. /* drag the command string into the kernel so we can parse it */
  53012. @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
  53013. if (args[0] != '%' || args[1] != '\0')
  53014. return -EINVAL;
  53015. - if (fstop < 0 || fstop >= cache->fcull_percent)
  53016. + if (fstop >= cache->fcull_percent)
  53017. return cachefiles_daemon_range_error(cache, args);
  53018. cache->fstop_percent = fstop;
  53019. @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
  53020. if (args[0] != '%' || args[1] != '\0')
  53021. return -EINVAL;
  53022. - if (bstop < 0 || bstop >= cache->bcull_percent)
  53023. + if (bstop >= cache->bcull_percent)
  53024. return cachefiles_daemon_range_error(cache, args);
  53025. cache->bstop_percent = bstop;
  53026. diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
  53027. index 5349473..d6c0b93 100644
  53028. --- a/fs/cachefiles/internal.h
  53029. +++ b/fs/cachefiles/internal.h
  53030. @@ -59,7 +59,7 @@ struct cachefiles_cache {
  53031. wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
  53032. struct rb_root active_nodes; /* active nodes (can't be culled) */
  53033. rwlock_t active_lock; /* lock for active_nodes */
  53034. - atomic_t gravecounter; /* graveyard uniquifier */
  53035. + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
  53036. unsigned frun_percent; /* when to stop culling (% files) */
  53037. unsigned fcull_percent; /* when to start culling (% files) */
  53038. unsigned fstop_percent; /* when to stop allocating (% files) */
  53039. @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
  53040. * proc.c
  53041. */
  53042. #ifdef CONFIG_CACHEFILES_HISTOGRAM
  53043. -extern atomic_t cachefiles_lookup_histogram[HZ];
  53044. -extern atomic_t cachefiles_mkdir_histogram[HZ];
  53045. -extern atomic_t cachefiles_create_histogram[HZ];
  53046. +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
  53047. +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
  53048. +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
  53049. extern int __init cachefiles_proc_init(void);
  53050. extern void cachefiles_proc_cleanup(void);
  53051. static inline
  53052. -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
  53053. +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
  53054. {
  53055. unsigned long jif = jiffies - start_jif;
  53056. if (jif >= HZ)
  53057. jif = HZ - 1;
  53058. - atomic_inc(&histogram[jif]);
  53059. + atomic_inc_unchecked(&histogram[jif]);
  53060. }
  53061. #else
  53062. diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
  53063. index ca65f39..48921e3 100644
  53064. --- a/fs/cachefiles/namei.c
  53065. +++ b/fs/cachefiles/namei.c
  53066. @@ -317,7 +317,7 @@ try_again:
  53067. /* first step is to make up a grave dentry in the graveyard */
  53068. sprintf(nbuffer, "%08x%08x",
  53069. (uint32_t) get_seconds(),
  53070. - (uint32_t) atomic_inc_return(&cache->gravecounter));
  53071. + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
  53072. /* do the multiway lock magic */
  53073. trap = lock_rename(cache->graveyard, dir);
  53074. diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
  53075. index eccd339..4c1d995 100644
  53076. --- a/fs/cachefiles/proc.c
  53077. +++ b/fs/cachefiles/proc.c
  53078. @@ -14,9 +14,9 @@
  53079. #include <linux/seq_file.h>
  53080. #include "internal.h"
  53081. -atomic_t cachefiles_lookup_histogram[HZ];
  53082. -atomic_t cachefiles_mkdir_histogram[HZ];
  53083. -atomic_t cachefiles_create_histogram[HZ];
  53084. +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
  53085. +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
  53086. +atomic_unchecked_t cachefiles_create_histogram[HZ];
  53087. /*
  53088. * display the latency histogram
  53089. @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
  53090. return 0;
  53091. default:
  53092. index = (unsigned long) v - 3;
  53093. - x = atomic_read(&cachefiles_lookup_histogram[index]);
  53094. - y = atomic_read(&cachefiles_mkdir_histogram[index]);
  53095. - z = atomic_read(&cachefiles_create_histogram[index]);
  53096. + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
  53097. + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
  53098. + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
  53099. if (x == 0 && y == 0 && z == 0)
  53100. return 0;
  53101. diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
  53102. index ebaff36..7e3ea26 100644
  53103. --- a/fs/cachefiles/rdwr.c
  53104. +++ b/fs/cachefiles/rdwr.c
  53105. @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
  53106. old_fs = get_fs();
  53107. set_fs(KERNEL_DS);
  53108. ret = file->f_op->write(
  53109. - file, (const void __user *) data, len, &pos);
  53110. + file, (const void __force_user *) data, len, &pos);
  53111. set_fs(old_fs);
  53112. kunmap(page);
  53113. file_end_write(file);
  53114. diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
  53115. index 45eda6d..9126f7f 100644
  53116. --- a/fs/ceph/dir.c
  53117. +++ b/fs/ceph/dir.c
  53118. @@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
  53119. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  53120. struct ceph_mds_client *mdsc = fsc->mdsc;
  53121. unsigned frag = fpos_frag(ctx->pos);
  53122. - int off = fpos_off(ctx->pos);
  53123. + unsigned int off = fpos_off(ctx->pos);
  53124. int err;
  53125. u32 ftype;
  53126. struct ceph_mds_reply_info_parsed *rinfo;
  53127. diff --git a/fs/ceph/super.c b/fs/ceph/super.c
  53128. index 10a4ccb..92dbc5e 100644
  53129. --- a/fs/ceph/super.c
  53130. +++ b/fs/ceph/super.c
  53131. @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
  53132. /*
  53133. * construct our own bdi so we can control readahead, etc.
  53134. */
  53135. -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
  53136. +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
  53137. static int ceph_register_bdi(struct super_block *sb,
  53138. struct ceph_fs_client *fsc)
  53139. @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
  53140. default_backing_dev_info.ra_pages;
  53141. err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
  53142. - atomic_long_inc_return(&bdi_seq));
  53143. + atomic_long_inc_return_unchecked(&bdi_seq));
  53144. if (!err)
  53145. sb->s_bdi = &fsc->backing_dev_info;
  53146. return err;
  53147. diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
  53148. index f3ac415..3d2420c 100644
  53149. --- a/fs/cifs/cifs_debug.c
  53150. +++ b/fs/cifs/cifs_debug.c
  53151. @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
  53152. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  53153. #ifdef CONFIG_CIFS_STATS2
  53154. - atomic_set(&totBufAllocCount, 0);
  53155. - atomic_set(&totSmBufAllocCount, 0);
  53156. + atomic_set_unchecked(&totBufAllocCount, 0);
  53157. + atomic_set_unchecked(&totSmBufAllocCount, 0);
  53158. #endif /* CONFIG_CIFS_STATS2 */
  53159. spin_lock(&cifs_tcp_ses_lock);
  53160. list_for_each(tmp1, &cifs_tcp_ses_list) {
  53161. @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
  53162. tcon = list_entry(tmp3,
  53163. struct cifs_tcon,
  53164. tcon_list);
  53165. - atomic_set(&tcon->num_smbs_sent, 0);
  53166. + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
  53167. if (server->ops->clear_stats)
  53168. server->ops->clear_stats(tcon);
  53169. }
  53170. @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
  53171. smBufAllocCount.counter, cifs_min_small);
  53172. #ifdef CONFIG_CIFS_STATS2
  53173. seq_printf(m, "Total Large %d Small %d Allocations\n",
  53174. - atomic_read(&totBufAllocCount),
  53175. - atomic_read(&totSmBufAllocCount));
  53176. + atomic_read_unchecked(&totBufAllocCount),
  53177. + atomic_read_unchecked(&totSmBufAllocCount));
  53178. #endif /* CONFIG_CIFS_STATS2 */
  53179. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  53180. @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
  53181. if (tcon->need_reconnect)
  53182. seq_puts(m, "\tDISCONNECTED ");
  53183. seq_printf(m, "\nSMBs: %d",
  53184. - atomic_read(&tcon->num_smbs_sent));
  53185. + atomic_read_unchecked(&tcon->num_smbs_sent));
  53186. if (server->ops->print_stats)
  53187. server->ops->print_stats(m, tcon);
  53188. }
  53189. diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
  53190. index 849f613..eae6dec 100644
  53191. --- a/fs/cifs/cifsfs.c
  53192. +++ b/fs/cifs/cifsfs.c
  53193. @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
  53194. */
  53195. cifs_req_cachep = kmem_cache_create("cifs_request",
  53196. CIFSMaxBufSize + max_hdr_size, 0,
  53197. - SLAB_HWCACHE_ALIGN, NULL);
  53198. + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
  53199. if (cifs_req_cachep == NULL)
  53200. return -ENOMEM;
  53201. @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
  53202. efficient to alloc 1 per page off the slab compared to 17K (5page)
  53203. alloc of large cifs buffers even when page debugging is on */
  53204. cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
  53205. - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
  53206. + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
  53207. NULL);
  53208. if (cifs_sm_req_cachep == NULL) {
  53209. mempool_destroy(cifs_req_poolp);
  53210. @@ -1168,8 +1168,8 @@ init_cifs(void)
  53211. atomic_set(&bufAllocCount, 0);
  53212. atomic_set(&smBufAllocCount, 0);
  53213. #ifdef CONFIG_CIFS_STATS2
  53214. - atomic_set(&totBufAllocCount, 0);
  53215. - atomic_set(&totSmBufAllocCount, 0);
  53216. + atomic_set_unchecked(&totBufAllocCount, 0);
  53217. + atomic_set_unchecked(&totSmBufAllocCount, 0);
  53218. #endif /* CONFIG_CIFS_STATS2 */
  53219. atomic_set(&midCount, 0);
  53220. diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
  53221. index c0f3718..6afed7d 100644
  53222. --- a/fs/cifs/cifsglob.h
  53223. +++ b/fs/cifs/cifsglob.h
  53224. @@ -804,35 +804,35 @@ struct cifs_tcon {
  53225. __u16 Flags; /* optional support bits */
  53226. enum statusEnum tidStatus;
  53227. #ifdef CONFIG_CIFS_STATS
  53228. - atomic_t num_smbs_sent;
  53229. + atomic_unchecked_t num_smbs_sent;
  53230. union {
  53231. struct {
  53232. - atomic_t num_writes;
  53233. - atomic_t num_reads;
  53234. - atomic_t num_flushes;
  53235. - atomic_t num_oplock_brks;
  53236. - atomic_t num_opens;
  53237. - atomic_t num_closes;
  53238. - atomic_t num_deletes;
  53239. - atomic_t num_mkdirs;
  53240. - atomic_t num_posixopens;
  53241. - atomic_t num_posixmkdirs;
  53242. - atomic_t num_rmdirs;
  53243. - atomic_t num_renames;
  53244. - atomic_t num_t2renames;
  53245. - atomic_t num_ffirst;
  53246. - atomic_t num_fnext;
  53247. - atomic_t num_fclose;
  53248. - atomic_t num_hardlinks;
  53249. - atomic_t num_symlinks;
  53250. - atomic_t num_locks;
  53251. - atomic_t num_acl_get;
  53252. - atomic_t num_acl_set;
  53253. + atomic_unchecked_t num_writes;
  53254. + atomic_unchecked_t num_reads;
  53255. + atomic_unchecked_t num_flushes;
  53256. + atomic_unchecked_t num_oplock_brks;
  53257. + atomic_unchecked_t num_opens;
  53258. + atomic_unchecked_t num_closes;
  53259. + atomic_unchecked_t num_deletes;
  53260. + atomic_unchecked_t num_mkdirs;
  53261. + atomic_unchecked_t num_posixopens;
  53262. + atomic_unchecked_t num_posixmkdirs;
  53263. + atomic_unchecked_t num_rmdirs;
  53264. + atomic_unchecked_t num_renames;
  53265. + atomic_unchecked_t num_t2renames;
  53266. + atomic_unchecked_t num_ffirst;
  53267. + atomic_unchecked_t num_fnext;
  53268. + atomic_unchecked_t num_fclose;
  53269. + atomic_unchecked_t num_hardlinks;
  53270. + atomic_unchecked_t num_symlinks;
  53271. + atomic_unchecked_t num_locks;
  53272. + atomic_unchecked_t num_acl_get;
  53273. + atomic_unchecked_t num_acl_set;
  53274. } cifs_stats;
  53275. #ifdef CONFIG_CIFS_SMB2
  53276. struct {
  53277. - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
  53278. - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
  53279. + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
  53280. + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
  53281. } smb2_stats;
  53282. #endif /* CONFIG_CIFS_SMB2 */
  53283. } stats;
  53284. @@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
  53285. }
  53286. #ifdef CONFIG_CIFS_STATS
  53287. -#define cifs_stats_inc atomic_inc
  53288. +#define cifs_stats_inc atomic_inc_unchecked
  53289. static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
  53290. unsigned int bytes)
  53291. @@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
  53292. /* Various Debug counters */
  53293. GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
  53294. #ifdef CONFIG_CIFS_STATS2
  53295. -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
  53296. -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
  53297. +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
  53298. +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
  53299. #endif
  53300. GLOBAL_EXTERN atomic_t smBufAllocCount;
  53301. GLOBAL_EXTERN atomic_t midCount;
  53302. diff --git a/fs/cifs/file.c b/fs/cifs/file.c
  53303. index 834fce7..8a314b5 100644
  53304. --- a/fs/cifs/file.c
  53305. +++ b/fs/cifs/file.c
  53306. @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
  53307. index = mapping->writeback_index; /* Start from prev offset */
  53308. end = -1;
  53309. } else {
  53310. - index = wbc->range_start >> PAGE_CACHE_SHIFT;
  53311. - end = wbc->range_end >> PAGE_CACHE_SHIFT;
  53312. - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
  53313. + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
  53314. range_whole = true;
  53315. + index = 0;
  53316. + end = ULONG_MAX;
  53317. + } else {
  53318. + index = wbc->range_start >> PAGE_CACHE_SHIFT;
  53319. + end = wbc->range_end >> PAGE_CACHE_SHIFT;
  53320. + }
  53321. scanned = true;
  53322. }
  53323. retry:
  53324. diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
  53325. index 2f9f379..43f8025 100644
  53326. --- a/fs/cifs/misc.c
  53327. +++ b/fs/cifs/misc.c
  53328. @@ -170,7 +170,7 @@ cifs_buf_get(void)
  53329. memset(ret_buf, 0, buf_size + 3);
  53330. atomic_inc(&bufAllocCount);
  53331. #ifdef CONFIG_CIFS_STATS2
  53332. - atomic_inc(&totBufAllocCount);
  53333. + atomic_inc_unchecked(&totBufAllocCount);
  53334. #endif /* CONFIG_CIFS_STATS2 */
  53335. }
  53336. @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
  53337. /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
  53338. atomic_inc(&smBufAllocCount);
  53339. #ifdef CONFIG_CIFS_STATS2
  53340. - atomic_inc(&totSmBufAllocCount);
  53341. + atomic_inc_unchecked(&totSmBufAllocCount);
  53342. #endif /* CONFIG_CIFS_STATS2 */
  53343. }
  53344. diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
  53345. index 526fb89..ecdbf5a 100644
  53346. --- a/fs/cifs/smb1ops.c
  53347. +++ b/fs/cifs/smb1ops.c
  53348. @@ -616,27 +616,27 @@ static void
  53349. cifs_clear_stats(struct cifs_tcon *tcon)
  53350. {
  53351. #ifdef CONFIG_CIFS_STATS
  53352. - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
  53353. - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
  53354. - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
  53355. - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
  53356. - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
  53357. - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
  53358. - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
  53359. - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
  53360. - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
  53361. - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
  53362. - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
  53363. - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
  53364. - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
  53365. - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
  53366. - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
  53367. - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
  53368. - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
  53369. - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
  53370. - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
  53371. - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
  53372. - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
  53373. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
  53374. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
  53375. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
  53376. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
  53377. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
  53378. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
  53379. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
  53380. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
  53381. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
  53382. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
  53383. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
  53384. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
  53385. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
  53386. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
  53387. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
  53388. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
  53389. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
  53390. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
  53391. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
  53392. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
  53393. + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
  53394. #endif
  53395. }
  53396. @@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  53397. {
  53398. #ifdef CONFIG_CIFS_STATS
  53399. seq_printf(m, " Oplocks breaks: %d",
  53400. - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
  53401. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
  53402. seq_printf(m, "\nReads: %d Bytes: %llu",
  53403. - atomic_read(&tcon->stats.cifs_stats.num_reads),
  53404. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
  53405. (long long)(tcon->bytes_read));
  53406. seq_printf(m, "\nWrites: %d Bytes: %llu",
  53407. - atomic_read(&tcon->stats.cifs_stats.num_writes),
  53408. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
  53409. (long long)(tcon->bytes_written));
  53410. seq_printf(m, "\nFlushes: %d",
  53411. - atomic_read(&tcon->stats.cifs_stats.num_flushes));
  53412. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
  53413. seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
  53414. - atomic_read(&tcon->stats.cifs_stats.num_locks),
  53415. - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
  53416. - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
  53417. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
  53418. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
  53419. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
  53420. seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
  53421. - atomic_read(&tcon->stats.cifs_stats.num_opens),
  53422. - atomic_read(&tcon->stats.cifs_stats.num_closes),
  53423. - atomic_read(&tcon->stats.cifs_stats.num_deletes));
  53424. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
  53425. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
  53426. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
  53427. seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
  53428. - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
  53429. - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
  53430. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
  53431. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
  53432. seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
  53433. - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
  53434. - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
  53435. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
  53436. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
  53437. seq_printf(m, "\nRenames: %d T2 Renames %d",
  53438. - atomic_read(&tcon->stats.cifs_stats.num_renames),
  53439. - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
  53440. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
  53441. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
  53442. seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
  53443. - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
  53444. - atomic_read(&tcon->stats.cifs_stats.num_fnext),
  53445. - atomic_read(&tcon->stats.cifs_stats.num_fclose));
  53446. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
  53447. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
  53448. + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
  53449. #endif
  53450. }
  53451. diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
  53452. index 192f51a..539307e 100644
  53453. --- a/fs/cifs/smb2ops.c
  53454. +++ b/fs/cifs/smb2ops.c
  53455. @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
  53456. #ifdef CONFIG_CIFS_STATS
  53457. int i;
  53458. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  53459. - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  53460. - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  53461. + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  53462. + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  53463. }
  53464. #endif
  53465. }
  53466. @@ -405,65 +405,65 @@ static void
  53467. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  53468. {
  53469. #ifdef CONFIG_CIFS_STATS
  53470. - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  53471. - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  53472. + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  53473. + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  53474. seq_printf(m, "\nNegotiates: %d sent %d failed",
  53475. - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  53476. - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  53477. + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
  53478. + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
  53479. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  53480. - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  53481. - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  53482. + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
  53483. + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
  53484. seq_printf(m, "\nLogoffs: %d sent %d failed",
  53485. - atomic_read(&sent[SMB2_LOGOFF_HE]),
  53486. - atomic_read(&failed[SMB2_LOGOFF_HE]));
  53487. + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
  53488. + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
  53489. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  53490. - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  53491. - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  53492. + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
  53493. + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
  53494. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  53495. - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  53496. - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  53497. + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
  53498. + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
  53499. seq_printf(m, "\nCreates: %d sent %d failed",
  53500. - atomic_read(&sent[SMB2_CREATE_HE]),
  53501. - atomic_read(&failed[SMB2_CREATE_HE]));
  53502. + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
  53503. + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
  53504. seq_printf(m, "\nCloses: %d sent %d failed",
  53505. - atomic_read(&sent[SMB2_CLOSE_HE]),
  53506. - atomic_read(&failed[SMB2_CLOSE_HE]));
  53507. + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
  53508. + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
  53509. seq_printf(m, "\nFlushes: %d sent %d failed",
  53510. - atomic_read(&sent[SMB2_FLUSH_HE]),
  53511. - atomic_read(&failed[SMB2_FLUSH_HE]));
  53512. + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
  53513. + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
  53514. seq_printf(m, "\nReads: %d sent %d failed",
  53515. - atomic_read(&sent[SMB2_READ_HE]),
  53516. - atomic_read(&failed[SMB2_READ_HE]));
  53517. + atomic_read_unchecked(&sent[SMB2_READ_HE]),
  53518. + atomic_read_unchecked(&failed[SMB2_READ_HE]));
  53519. seq_printf(m, "\nWrites: %d sent %d failed",
  53520. - atomic_read(&sent[SMB2_WRITE_HE]),
  53521. - atomic_read(&failed[SMB2_WRITE_HE]));
  53522. + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
  53523. + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
  53524. seq_printf(m, "\nLocks: %d sent %d failed",
  53525. - atomic_read(&sent[SMB2_LOCK_HE]),
  53526. - atomic_read(&failed[SMB2_LOCK_HE]));
  53527. + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
  53528. + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
  53529. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  53530. - atomic_read(&sent[SMB2_IOCTL_HE]),
  53531. - atomic_read(&failed[SMB2_IOCTL_HE]));
  53532. + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
  53533. + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
  53534. seq_printf(m, "\nCancels: %d sent %d failed",
  53535. - atomic_read(&sent[SMB2_CANCEL_HE]),
  53536. - atomic_read(&failed[SMB2_CANCEL_HE]));
  53537. + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
  53538. + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
  53539. seq_printf(m, "\nEchos: %d sent %d failed",
  53540. - atomic_read(&sent[SMB2_ECHO_HE]),
  53541. - atomic_read(&failed[SMB2_ECHO_HE]));
  53542. + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
  53543. + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
  53544. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  53545. - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  53546. - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  53547. + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
  53548. + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
  53549. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  53550. - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  53551. - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  53552. + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
  53553. + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
  53554. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  53555. - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  53556. - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  53557. + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
  53558. + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
  53559. seq_printf(m, "\nSetInfos: %d sent %d failed",
  53560. - atomic_read(&sent[SMB2_SET_INFO_HE]),
  53561. - atomic_read(&failed[SMB2_SET_INFO_HE]));
  53562. + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
  53563. + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
  53564. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  53565. - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  53566. - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  53567. + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
  53568. + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
  53569. #endif
  53570. }
  53571. diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
  53572. index 8603447..f9caeee 100644
  53573. --- a/fs/cifs/smb2pdu.c
  53574. +++ b/fs/cifs/smb2pdu.c
  53575. @@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
  53576. default:
  53577. cifs_dbg(VFS, "info level %u isn't supported\n",
  53578. srch_inf->info_level);
  53579. - rc = -EINVAL;
  53580. - goto qdir_exit;
  53581. + return -EINVAL;
  53582. }
  53583. req->FileIndex = cpu_to_le32(index);
  53584. diff --git a/fs/coda/cache.c b/fs/coda/cache.c
  53585. index 1da168c..8bc7ff6 100644
  53586. --- a/fs/coda/cache.c
  53587. +++ b/fs/coda/cache.c
  53588. @@ -24,7 +24,7 @@
  53589. #include "coda_linux.h"
  53590. #include "coda_cache.h"
  53591. -static atomic_t permission_epoch = ATOMIC_INIT(0);
  53592. +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
  53593. /* replace or extend an acl cache hit */
  53594. void coda_cache_enter(struct inode *inode, int mask)
  53595. @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
  53596. struct coda_inode_info *cii = ITOC(inode);
  53597. spin_lock(&cii->c_lock);
  53598. - cii->c_cached_epoch = atomic_read(&permission_epoch);
  53599. + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
  53600. if (!uid_eq(cii->c_uid, current_fsuid())) {
  53601. cii->c_uid = current_fsuid();
  53602. cii->c_cached_perm = mask;
  53603. @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
  53604. {
  53605. struct coda_inode_info *cii = ITOC(inode);
  53606. spin_lock(&cii->c_lock);
  53607. - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
  53608. + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
  53609. spin_unlock(&cii->c_lock);
  53610. }
  53611. /* remove all acl caches */
  53612. void coda_cache_clear_all(struct super_block *sb)
  53613. {
  53614. - atomic_inc(&permission_epoch);
  53615. + atomic_inc_unchecked(&permission_epoch);
  53616. }
  53617. @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
  53618. spin_lock(&cii->c_lock);
  53619. hit = (mask & cii->c_cached_perm) == mask &&
  53620. uid_eq(cii->c_uid, current_fsuid()) &&
  53621. - cii->c_cached_epoch == atomic_read(&permission_epoch);
  53622. + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
  53623. spin_unlock(&cii->c_lock);
  53624. return hit;
  53625. diff --git a/fs/compat.c b/fs/compat.c
  53626. index 6af20de..fec3fbb 100644
  53627. --- a/fs/compat.c
  53628. +++ b/fs/compat.c
  53629. @@ -54,7 +54,7 @@
  53630. #include <asm/ioctls.h>
  53631. #include "internal.h"
  53632. -int compat_log = 1;
  53633. +int compat_log = 0;
  53634. int compat_printk(const char *fmt, ...)
  53635. {
  53636. @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
  53637. set_fs(KERNEL_DS);
  53638. /* The __user pointer cast is valid because of the set_fs() */
  53639. - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
  53640. + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
  53641. set_fs(oldfs);
  53642. /* truncating is ok because it's a user address */
  53643. if (!ret)
  53644. @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
  53645. goto out;
  53646. ret = -EINVAL;
  53647. - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
  53648. + if (nr_segs > UIO_MAXIOV)
  53649. goto out;
  53650. if (nr_segs > fast_segs) {
  53651. ret = -ENOMEM;
  53652. @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
  53653. struct compat_readdir_callback {
  53654. struct dir_context ctx;
  53655. struct compat_old_linux_dirent __user *dirent;
  53656. + struct file * file;
  53657. int result;
  53658. };
  53659. @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
  53660. buf->result = -EOVERFLOW;
  53661. return -EOVERFLOW;
  53662. }
  53663. +
  53664. + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
  53665. + return 0;
  53666. +
  53667. buf->result++;
  53668. dirent = buf->dirent;
  53669. if (!access_ok(VERIFY_WRITE, dirent,
  53670. @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
  53671. if (!f.file)
  53672. return -EBADF;
  53673. + buf.file = f.file;
  53674. error = iterate_dir(f.file, &buf.ctx);
  53675. if (buf.result)
  53676. error = buf.result;
  53677. @@ -901,6 +907,7 @@ struct compat_getdents_callback {
  53678. struct dir_context ctx;
  53679. struct compat_linux_dirent __user *current_dir;
  53680. struct compat_linux_dirent __user *previous;
  53681. + struct file * file;
  53682. int count;
  53683. int error;
  53684. };
  53685. @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
  53686. buf->error = -EOVERFLOW;
  53687. return -EOVERFLOW;
  53688. }
  53689. +
  53690. + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
  53691. + return 0;
  53692. +
  53693. dirent = buf->previous;
  53694. if (dirent) {
  53695. if (__put_user(offset, &dirent->d_off))
  53696. @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
  53697. if (!f.file)
  53698. return -EBADF;
  53699. + buf.file = f.file;
  53700. error = iterate_dir(f.file, &buf.ctx);
  53701. if (error >= 0)
  53702. error = buf.error;
  53703. @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
  53704. struct dir_context ctx;
  53705. struct linux_dirent64 __user *current_dir;
  53706. struct linux_dirent64 __user *previous;
  53707. + struct file * file;
  53708. int count;
  53709. int error;
  53710. };
  53711. @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
  53712. buf->error = -EINVAL; /* only used if we fail.. */
  53713. if (reclen > buf->count)
  53714. return -EINVAL;
  53715. +
  53716. + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
  53717. + return 0;
  53718. +
  53719. dirent = buf->previous;
  53720. if (dirent) {
  53721. @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
  53722. if (!f.file)
  53723. return -EBADF;
  53724. + buf.file = f.file;
  53725. error = iterate_dir(f.file, &buf.ctx);
  53726. if (error >= 0)
  53727. error = buf.error;
  53728. diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
  53729. index a81147e..20bf2b5 100644
  53730. --- a/fs/compat_binfmt_elf.c
  53731. +++ b/fs/compat_binfmt_elf.c
  53732. @@ -30,11 +30,13 @@
  53733. #undef elf_phdr
  53734. #undef elf_shdr
  53735. #undef elf_note
  53736. +#undef elf_dyn
  53737. #undef elf_addr_t
  53738. #define elfhdr elf32_hdr
  53739. #define elf_phdr elf32_phdr
  53740. #define elf_shdr elf32_shdr
  53741. #define elf_note elf32_note
  53742. +#define elf_dyn Elf32_Dyn
  53743. #define elf_addr_t Elf32_Addr
  53744. /*
  53745. diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
  53746. index 3881610..ab3df0b 100644
  53747. --- a/fs/compat_ioctl.c
  53748. +++ b/fs/compat_ioctl.c
  53749. @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
  53750. return -EFAULT;
  53751. if (__get_user(udata, &ss32->iomem_base))
  53752. return -EFAULT;
  53753. - ss.iomem_base = compat_ptr(udata);
  53754. + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
  53755. if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
  53756. __get_user(ss.port_high, &ss32->port_high))
  53757. return -EFAULT;
  53758. @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
  53759. for (i = 0; i < nmsgs; i++) {
  53760. if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
  53761. return -EFAULT;
  53762. - if (get_user(datap, &umsgs[i].buf) ||
  53763. - put_user(compat_ptr(datap), &tmsgs[i].buf))
  53764. + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
  53765. + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
  53766. return -EFAULT;
  53767. }
  53768. return sys_ioctl(fd, cmd, (unsigned long)tdata);
  53769. @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
  53770. copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
  53771. copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
  53772. copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
  53773. - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
  53774. + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
  53775. return -EFAULT;
  53776. return ioctl_preallocate(file, p);
  53777. @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
  53778. static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
  53779. {
  53780. unsigned int a, b;
  53781. - a = *(unsigned int *)p;
  53782. - b = *(unsigned int *)q;
  53783. + a = *(const unsigned int *)p;
  53784. + b = *(const unsigned int *)q;
  53785. if (a > b)
  53786. return 1;
  53787. if (a < b)
  53788. diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
  53789. index e081acb..911df21 100644
  53790. --- a/fs/configfs/dir.c
  53791. +++ b/fs/configfs/dir.c
  53792. @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
  53793. }
  53794. for (p = q->next; p != &parent_sd->s_children; p = p->next) {
  53795. struct configfs_dirent *next;
  53796. - const char *name;
  53797. + const unsigned char * name;
  53798. + char d_name[sizeof(next->s_dentry->d_iname)];
  53799. int len;
  53800. struct inode *inode = NULL;
  53801. @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
  53802. continue;
  53803. name = configfs_get_name(next);
  53804. - len = strlen(name);
  53805. + if (next->s_dentry && name == next->s_dentry->d_iname) {
  53806. + len = next->s_dentry->d_name.len;
  53807. + memcpy(d_name, name, len);
  53808. + name = d_name;
  53809. + } else
  53810. + len = strlen(name);
  53811. /*
  53812. * We'll have a dentry and an inode for
  53813. diff --git a/fs/coredump.c b/fs/coredump.c
  53814. index e3ad709..836c55f 100644
  53815. --- a/fs/coredump.c
  53816. +++ b/fs/coredump.c
  53817. @@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
  53818. static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
  53819. {
  53820. int free, need;
  53821. + va_list arg_copy;
  53822. again:
  53823. free = cn->size - cn->used;
  53824. - need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
  53825. +
  53826. + va_copy(arg_copy, arg);
  53827. + need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
  53828. + va_end(arg_copy);
  53829. +
  53830. if (need < free) {
  53831. cn->used += need;
  53832. return 0;
  53833. @@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
  53834. struct pipe_inode_info *pipe = file->private_data;
  53835. pipe_lock(pipe);
  53836. - pipe->readers++;
  53837. - pipe->writers--;
  53838. + atomic_inc(&pipe->readers);
  53839. + atomic_dec(&pipe->writers);
  53840. wake_up_interruptible_sync(&pipe->wait);
  53841. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  53842. pipe_unlock(pipe);
  53843. @@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
  53844. * We actually want wait_event_freezable() but then we need
  53845. * to clear TIF_SIGPENDING and improve dump_interrupted().
  53846. */
  53847. - wait_event_interruptible(pipe->wait, pipe->readers == 1);
  53848. + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
  53849. pipe_lock(pipe);
  53850. - pipe->readers--;
  53851. - pipe->writers++;
  53852. + atomic_dec(&pipe->readers);
  53853. + atomic_inc(&pipe->writers);
  53854. pipe_unlock(pipe);
  53855. }
  53856. @@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
  53857. struct files_struct *displaced;
  53858. bool need_nonrelative = false;
  53859. bool core_dumped = false;
  53860. - static atomic_t core_dump_count = ATOMIC_INIT(0);
  53861. + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
  53862. + long signr = siginfo->si_signo;
  53863. + int dumpable;
  53864. struct coredump_params cprm = {
  53865. .siginfo = siginfo,
  53866. .regs = signal_pt_regs(),
  53867. @@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
  53868. .mm_flags = mm->flags,
  53869. };
  53870. - audit_core_dumps(siginfo->si_signo);
  53871. + audit_core_dumps(signr);
  53872. +
  53873. + dumpable = __get_dumpable(cprm.mm_flags);
  53874. +
  53875. + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
  53876. + gr_handle_brute_attach(dumpable);
  53877. binfmt = mm->binfmt;
  53878. if (!binfmt || !binfmt->core_dump)
  53879. goto fail;
  53880. - if (!__get_dumpable(cprm.mm_flags))
  53881. + if (!dumpable)
  53882. goto fail;
  53883. cred = prepare_creds();
  53884. @@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
  53885. need_nonrelative = true;
  53886. }
  53887. - retval = coredump_wait(siginfo->si_signo, &core_state);
  53888. + retval = coredump_wait(signr, &core_state);
  53889. if (retval < 0)
  53890. goto fail_creds;
  53891. @@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
  53892. }
  53893. cprm.limit = RLIM_INFINITY;
  53894. - dump_count = atomic_inc_return(&core_dump_count);
  53895. + dump_count = atomic_inc_return_unchecked(&core_dump_count);
  53896. if (core_pipe_limit && (core_pipe_limit < dump_count)) {
  53897. printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
  53898. task_tgid_vnr(current), current->comm);
  53899. @@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
  53900. } else {
  53901. struct inode *inode;
  53902. + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
  53903. +
  53904. if (cprm.limit < binfmt->min_coredump)
  53905. goto fail_unlock;
  53906. @@ -668,7 +682,7 @@ close_fail:
  53907. filp_close(cprm.file, NULL);
  53908. fail_dropcount:
  53909. if (ispipe)
  53910. - atomic_dec(&core_dump_count);
  53911. + atomic_dec_unchecked(&core_dump_count);
  53912. fail_unlock:
  53913. kfree(cn.corename);
  53914. coredump_finish(mm, core_dumped);
  53915. @@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
  53916. struct file *file = cprm->file;
  53917. loff_t pos = file->f_pos;
  53918. ssize_t n;
  53919. +
  53920. + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
  53921. if (cprm->written + nr > cprm->limit)
  53922. return 0;
  53923. while (nr) {
  53924. diff --git a/fs/dcache.c b/fs/dcache.c
  53925. index ca02c13..7e2b581 100644
  53926. --- a/fs/dcache.c
  53927. +++ b/fs/dcache.c
  53928. @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
  53929. */
  53930. dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
  53931. if (name->len > DNAME_INLINE_LEN-1) {
  53932. - dname = kmalloc(name->len + 1, GFP_KERNEL);
  53933. + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
  53934. if (!dname) {
  53935. kmem_cache_free(dentry_cache, dentry);
  53936. return NULL;
  53937. @@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
  53938. mempages -= reserve;
  53939. names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
  53940. - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
  53941. + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
  53942. + SLAB_NO_SANITIZE, NULL);
  53943. dcache_init();
  53944. inode_init();
  53945. diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
  53946. index 9c0444c..628490c 100644
  53947. --- a/fs/debugfs/inode.c
  53948. +++ b/fs/debugfs/inode.c
  53949. @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
  53950. */
  53951. struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
  53952. {
  53953. +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
  53954. + return __create_file(name, S_IFDIR | S_IRWXU,
  53955. +#else
  53956. return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
  53957. +#endif
  53958. parent, NULL, NULL);
  53959. }
  53960. EXPORT_SYMBOL_GPL(debugfs_create_dir);
  53961. diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
  53962. index b167ca4..a224e19 100644
  53963. --- a/fs/ecryptfs/inode.c
  53964. +++ b/fs/ecryptfs/inode.c
  53965. @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
  53966. old_fs = get_fs();
  53967. set_fs(get_ds());
  53968. rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
  53969. - (char __user *)lower_buf,
  53970. + (char __force_user *)lower_buf,
  53971. PATH_MAX);
  53972. set_fs(old_fs);
  53973. if (rc < 0)
  53974. diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
  53975. index e4141f2..d8263e8 100644
  53976. --- a/fs/ecryptfs/miscdev.c
  53977. +++ b/fs/ecryptfs/miscdev.c
  53978. @@ -304,7 +304,7 @@ check_list:
  53979. goto out_unlock_msg_ctx;
  53980. i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
  53981. if (msg_ctx->msg) {
  53982. - if (copy_to_user(&buf[i], packet_length, packet_length_size))
  53983. + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
  53984. goto out_unlock_msg_ctx;
  53985. i += packet_length_size;
  53986. if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
  53987. diff --git a/fs/exec.c b/fs/exec.c
  53988. index 3d78fcc..460e2a0 100644
  53989. --- a/fs/exec.c
  53990. +++ b/fs/exec.c
  53991. @@ -55,8 +55,20 @@
  53992. #include <linux/pipe_fs_i.h>
  53993. #include <linux/oom.h>
  53994. #include <linux/compat.h>
  53995. +#include <linux/random.h>
  53996. +#include <linux/seq_file.h>
  53997. +#include <linux/coredump.h>
  53998. +#include <linux/mman.h>
  53999. +
  54000. +#ifdef CONFIG_PAX_REFCOUNT
  54001. +#include <linux/kallsyms.h>
  54002. +#include <linux/kdebug.h>
  54003. +#endif
  54004. +
  54005. +#include <trace/events/fs.h>
  54006. #include <asm/uaccess.h>
  54007. +#include <asm/sections.h>
  54008. #include <asm/mmu_context.h>
  54009. #include <asm/tlb.h>
  54010. @@ -65,19 +77,34 @@
  54011. #include <trace/events/sched.h>
  54012. +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
  54013. +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
  54014. +{
  54015. + pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
  54016. +}
  54017. +#endif
  54018. +
  54019. +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
  54020. +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
  54021. +EXPORT_SYMBOL(pax_set_initial_flags_func);
  54022. +#endif
  54023. +
  54024. int suid_dumpable = 0;
  54025. static LIST_HEAD(formats);
  54026. static DEFINE_RWLOCK(binfmt_lock);
  54027. +extern int gr_process_kernel_exec_ban(void);
  54028. +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
  54029. +
  54030. void __register_binfmt(struct linux_binfmt * fmt, int insert)
  54031. {
  54032. BUG_ON(!fmt);
  54033. if (WARN_ON(!fmt->load_binary))
  54034. return;
  54035. write_lock(&binfmt_lock);
  54036. - insert ? list_add(&fmt->lh, &formats) :
  54037. - list_add_tail(&fmt->lh, &formats);
  54038. + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
  54039. + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
  54040. write_unlock(&binfmt_lock);
  54041. }
  54042. @@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
  54043. void unregister_binfmt(struct linux_binfmt * fmt)
  54044. {
  54045. write_lock(&binfmt_lock);
  54046. - list_del(&fmt->lh);
  54047. + pax_list_del((struct list_head *)&fmt->lh);
  54048. write_unlock(&binfmt_lock);
  54049. }
  54050. @@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
  54051. int write)
  54052. {
  54053. struct page *page;
  54054. - int ret;
  54055. -#ifdef CONFIG_STACK_GROWSUP
  54056. - if (write) {
  54057. - ret = expand_downwards(bprm->vma, pos);
  54058. - if (ret < 0)
  54059. - return NULL;
  54060. - }
  54061. -#endif
  54062. - ret = get_user_pages(current, bprm->mm, pos,
  54063. - 1, write, 1, &page, NULL);
  54064. - if (ret <= 0)
  54065. + if (0 > expand_downwards(bprm->vma, pos))
  54066. + return NULL;
  54067. + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
  54068. return NULL;
  54069. if (write) {
  54070. @@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
  54071. if (size <= ARG_MAX)
  54072. return page;
  54073. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  54074. + // only allow 512KB for argv+env on suid/sgid binaries
  54075. + // to prevent easy ASLR exhaustion
  54076. + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
  54077. + (!gid_eq(bprm->cred->egid, current_egid()))) &&
  54078. + (size > (512 * 1024))) {
  54079. + put_page(page);
  54080. + return NULL;
  54081. + }
  54082. +#endif
  54083. +
  54084. /*
  54085. * Limit to 1/4-th the stack size for the argv+env strings.
  54086. * This ensures that:
  54087. @@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
  54088. vma->vm_end = STACK_TOP_MAX;
  54089. vma->vm_start = vma->vm_end - PAGE_SIZE;
  54090. vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
  54091. +
  54092. +#ifdef CONFIG_PAX_SEGMEXEC
  54093. + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
  54094. +#endif
  54095. +
  54096. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  54097. INIT_LIST_HEAD(&vma->anon_vma_chain);
  54098. @@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
  54099. mm->stack_vm = mm->total_vm = 1;
  54100. up_write(&mm->mmap_sem);
  54101. bprm->p = vma->vm_end - sizeof(void *);
  54102. +
  54103. +#ifdef CONFIG_PAX_RANDUSTACK
  54104. + if (randomize_va_space)
  54105. + bprm->p ^= prandom_u32() & ~PAGE_MASK;
  54106. +#endif
  54107. +
  54108. return 0;
  54109. err:
  54110. up_write(&mm->mmap_sem);
  54111. @@ -396,7 +437,7 @@ struct user_arg_ptr {
  54112. } ptr;
  54113. };
  54114. -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
  54115. +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
  54116. {
  54117. const char __user *native;
  54118. @@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
  54119. compat_uptr_t compat;
  54120. if (get_user(compat, argv.ptr.compat + nr))
  54121. - return ERR_PTR(-EFAULT);
  54122. + return (const char __force_user *)ERR_PTR(-EFAULT);
  54123. return compat_ptr(compat);
  54124. }
  54125. #endif
  54126. if (get_user(native, argv.ptr.native + nr))
  54127. - return ERR_PTR(-EFAULT);
  54128. + return (const char __force_user *)ERR_PTR(-EFAULT);
  54129. return native;
  54130. }
  54131. @@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
  54132. if (!p)
  54133. break;
  54134. - if (IS_ERR(p))
  54135. + if (IS_ERR((const char __force_kernel *)p))
  54136. return -EFAULT;
  54137. if (i >= max)
  54138. @@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
  54139. ret = -EFAULT;
  54140. str = get_user_arg_ptr(argv, argc);
  54141. - if (IS_ERR(str))
  54142. + if (IS_ERR((const char __force_kernel *)str))
  54143. goto out;
  54144. len = strnlen_user(str, MAX_ARG_STRLEN);
  54145. @@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
  54146. int r;
  54147. mm_segment_t oldfs = get_fs();
  54148. struct user_arg_ptr argv = {
  54149. - .ptr.native = (const char __user *const __user *)__argv,
  54150. + .ptr.native = (const char __user * const __force_user *)__argv,
  54151. };
  54152. set_fs(KERNEL_DS);
  54153. @@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
  54154. unsigned long new_end = old_end - shift;
  54155. struct mmu_gather tlb;
  54156. - BUG_ON(new_start > new_end);
  54157. + if (new_start >= new_end || new_start < mmap_min_addr)
  54158. + return -ENOMEM;
  54159. /*
  54160. * ensure there are no vmas between where we want to go
  54161. @@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
  54162. if (vma != find_vma(mm, new_start))
  54163. return -EFAULT;
  54164. +#ifdef CONFIG_PAX_SEGMEXEC
  54165. + BUG_ON(pax_find_mirror_vma(vma));
  54166. +#endif
  54167. +
  54168. /*
  54169. * cover the whole range: [new_start, old_end)
  54170. */
  54171. @@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
  54172. stack_top = arch_align_stack(stack_top);
  54173. stack_top = PAGE_ALIGN(stack_top);
  54174. - if (unlikely(stack_top < mmap_min_addr) ||
  54175. - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
  54176. - return -ENOMEM;
  54177. -
  54178. stack_shift = vma->vm_end - stack_top;
  54179. bprm->p -= stack_shift;
  54180. @@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
  54181. bprm->exec -= stack_shift;
  54182. down_write(&mm->mmap_sem);
  54183. +
  54184. + /* Move stack pages down in memory. */
  54185. + if (stack_shift) {
  54186. + ret = shift_arg_pages(vma, stack_shift);
  54187. + if (ret)
  54188. + goto out_unlock;
  54189. + }
  54190. +
  54191. vm_flags = VM_STACK_FLAGS;
  54192. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  54193. + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
  54194. + vm_flags &= ~VM_EXEC;
  54195. +
  54196. +#ifdef CONFIG_PAX_MPROTECT
  54197. + if (mm->pax_flags & MF_PAX_MPROTECT)
  54198. + vm_flags &= ~VM_MAYEXEC;
  54199. +#endif
  54200. +
  54201. + }
  54202. +#endif
  54203. +
  54204. /*
  54205. * Adjust stack execute permissions; explicitly enable for
  54206. * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
  54207. @@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
  54208. goto out_unlock;
  54209. BUG_ON(prev != vma);
  54210. - /* Move stack pages down in memory. */
  54211. - if (stack_shift) {
  54212. - ret = shift_arg_pages(vma, stack_shift);
  54213. - if (ret)
  54214. - goto out_unlock;
  54215. - }
  54216. -
  54217. /* mprotect_fixup is overkill to remove the temporary stack flags */
  54218. vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
  54219. @@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
  54220. #endif
  54221. current->mm->start_stack = bprm->p;
  54222. ret = expand_stack(vma, stack_base);
  54223. +
  54224. +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
  54225. + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
  54226. + unsigned long size;
  54227. + vm_flags_t vm_flags;
  54228. +
  54229. + size = STACK_TOP - vma->vm_end;
  54230. + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
  54231. +
  54232. + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
  54233. +
  54234. +#ifdef CONFIG_X86
  54235. + if (!ret) {
  54236. + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
  54237. + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
  54238. + }
  54239. +#endif
  54240. +
  54241. + }
  54242. +#endif
  54243. +
  54244. if (ret)
  54245. ret = -EFAULT;
  54246. @@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
  54247. fsnotify_open(file);
  54248. + trace_open_exec(name->name);
  54249. +
  54250. err = deny_write_access(file);
  54251. if (err)
  54252. goto exit;
  54253. @@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
  54254. old_fs = get_fs();
  54255. set_fs(get_ds());
  54256. /* The cast to a user pointer is valid due to the set_fs() */
  54257. - result = vfs_read(file, (void __user *)addr, count, &pos);
  54258. + result = vfs_read(file, (void __force_user *)addr, count, &pos);
  54259. set_fs(old_fs);
  54260. return result;
  54261. }
  54262. @@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
  54263. }
  54264. rcu_read_unlock();
  54265. - if (p->fs->users > n_fs)
  54266. + if (atomic_read(&p->fs->users) > n_fs)
  54267. bprm->unsafe |= LSM_UNSAFE_SHARE;
  54268. else
  54269. p->fs->in_exec = 1;
  54270. @@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
  54271. return ret;
  54272. }
  54273. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  54274. +static DEFINE_PER_CPU(u64, exec_counter);
  54275. +static int __init init_exec_counters(void)
  54276. +{
  54277. + unsigned int cpu;
  54278. +
  54279. + for_each_possible_cpu(cpu) {
  54280. + per_cpu(exec_counter, cpu) = (u64)cpu;
  54281. + }
  54282. +
  54283. + return 0;
  54284. +}
  54285. +early_initcall(init_exec_counters);
  54286. +static inline void increment_exec_counter(void)
  54287. +{
  54288. + BUILD_BUG_ON(NR_CPUS > (1 << 16));
  54289. + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
  54290. +}
  54291. +#else
  54292. +static inline void increment_exec_counter(void) {}
  54293. +#endif
  54294. +
  54295. +extern void gr_handle_exec_args(struct linux_binprm *bprm,
  54296. + struct user_arg_ptr argv);
  54297. +
  54298. /*
  54299. * sys_execve() executes a new program.
  54300. */
  54301. @@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
  54302. struct user_arg_ptr argv,
  54303. struct user_arg_ptr envp)
  54304. {
  54305. +#ifdef CONFIG_GRKERNSEC
  54306. + struct file *old_exec_file;
  54307. + struct acl_subject_label *old_acl;
  54308. + struct rlimit old_rlim[RLIM_NLIMITS];
  54309. +#endif
  54310. struct linux_binprm *bprm;
  54311. struct file *file;
  54312. struct files_struct *displaced;
  54313. @@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
  54314. if (IS_ERR(filename))
  54315. return PTR_ERR(filename);
  54316. + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
  54317. +
  54318. /*
  54319. * We move the actual failure in case of RLIMIT_NPROC excess from
  54320. * set*uid() to execve() because too many poorly written programs
  54321. @@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
  54322. if (IS_ERR(file))
  54323. goto out_unmark;
  54324. + if (gr_ptrace_readexec(file, bprm->unsafe)) {
  54325. + retval = -EPERM;
  54326. + goto out_unmark;
  54327. + }
  54328. +
  54329. sched_exec();
  54330. bprm->file = file;
  54331. bprm->filename = bprm->interp = filename->name;
  54332. + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
  54333. + retval = -EACCES;
  54334. + goto out_unmark;
  54335. + }
  54336. +
  54337. retval = bprm_mm_init(bprm);
  54338. if (retval)
  54339. goto out_unmark;
  54340. @@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
  54341. if (retval < 0)
  54342. goto out;
  54343. +#ifdef CONFIG_GRKERNSEC
  54344. + old_acl = current->acl;
  54345. + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
  54346. + old_exec_file = current->exec_file;
  54347. + get_file(file);
  54348. + current->exec_file = file;
  54349. +#endif
  54350. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  54351. + /* limit suid stack to 8MB
  54352. + * we saved the old limits above and will restore them if this exec fails
  54353. + */
  54354. + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
  54355. + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
  54356. + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
  54357. +#endif
  54358. +
  54359. + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
  54360. + retval = -EPERM;
  54361. + goto out_fail;
  54362. + }
  54363. +
  54364. + if (!gr_tpe_allow(file)) {
  54365. + retval = -EACCES;
  54366. + goto out_fail;
  54367. + }
  54368. +
  54369. + if (gr_check_crash_exec(file)) {
  54370. + retval = -EACCES;
  54371. + goto out_fail;
  54372. + }
  54373. +
  54374. + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
  54375. + bprm->unsafe);
  54376. + if (retval < 0)
  54377. + goto out_fail;
  54378. +
  54379. retval = copy_strings_kernel(1, &bprm->filename, bprm);
  54380. if (retval < 0)
  54381. - goto out;
  54382. + goto out_fail;
  54383. bprm->exec = bprm->p;
  54384. retval = copy_strings(bprm->envc, envp, bprm);
  54385. if (retval < 0)
  54386. - goto out;
  54387. + goto out_fail;
  54388. retval = copy_strings(bprm->argc, argv, bprm);
  54389. if (retval < 0)
  54390. - goto out;
  54391. + goto out_fail;
  54392. +
  54393. + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
  54394. +
  54395. + gr_handle_exec_args(bprm, argv);
  54396. retval = exec_binprm(bprm);
  54397. if (retval < 0)
  54398. - goto out;
  54399. + goto out_fail;
  54400. +#ifdef CONFIG_GRKERNSEC
  54401. + if (old_exec_file)
  54402. + fput(old_exec_file);
  54403. +#endif
  54404. /* execve succeeded */
  54405. +
  54406. + increment_exec_counter();
  54407. current->fs->in_exec = 0;
  54408. current->in_execve = 0;
  54409. acct_update_integrals(current);
  54410. @@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
  54411. put_files_struct(displaced);
  54412. return retval;
  54413. +out_fail:
  54414. +#ifdef CONFIG_GRKERNSEC
  54415. + current->acl = old_acl;
  54416. + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
  54417. + fput(current->exec_file);
  54418. + current->exec_file = old_exec_file;
  54419. +#endif
  54420. +
  54421. out:
  54422. if (bprm->mm) {
  54423. acct_arg_size(bprm, 0);
  54424. @@ -1626,3 +1800,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
  54425. return compat_do_execve(getname(filename), argv, envp);
  54426. }
  54427. #endif
  54428. +
  54429. +int pax_check_flags(unsigned long *flags)
  54430. +{
  54431. + int retval = 0;
  54432. +
  54433. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
  54434. + if (*flags & MF_PAX_SEGMEXEC)
  54435. + {
  54436. + *flags &= ~MF_PAX_SEGMEXEC;
  54437. + retval = -EINVAL;
  54438. + }
  54439. +#endif
  54440. +
  54441. + if ((*flags & MF_PAX_PAGEEXEC)
  54442. +
  54443. +#ifdef CONFIG_PAX_PAGEEXEC
  54444. + && (*flags & MF_PAX_SEGMEXEC)
  54445. +#endif
  54446. +
  54447. + )
  54448. + {
  54449. + *flags &= ~MF_PAX_PAGEEXEC;
  54450. + retval = -EINVAL;
  54451. + }
  54452. +
  54453. + if ((*flags & MF_PAX_MPROTECT)
  54454. +
  54455. +#ifdef CONFIG_PAX_MPROTECT
  54456. + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
  54457. +#endif
  54458. +
  54459. + )
  54460. + {
  54461. + *flags &= ~MF_PAX_MPROTECT;
  54462. + retval = -EINVAL;
  54463. + }
  54464. +
  54465. + if ((*flags & MF_PAX_EMUTRAMP)
  54466. +
  54467. +#ifdef CONFIG_PAX_EMUTRAMP
  54468. + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
  54469. +#endif
  54470. +
  54471. + )
  54472. + {
  54473. + *flags &= ~MF_PAX_EMUTRAMP;
  54474. + retval = -EINVAL;
  54475. + }
  54476. +
  54477. + return retval;
  54478. +}
  54479. +
  54480. +EXPORT_SYMBOL(pax_check_flags);
  54481. +
  54482. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  54483. +char *pax_get_path(const struct path *path, char *buf, int buflen)
  54484. +{
  54485. + char *pathname = d_path(path, buf, buflen);
  54486. +
  54487. + if (IS_ERR(pathname))
  54488. + goto toolong;
  54489. +
  54490. + pathname = mangle_path(buf, pathname, "\t\n\\");
  54491. + if (!pathname)
  54492. + goto toolong;
  54493. +
  54494. + *pathname = 0;
  54495. + return buf;
  54496. +
  54497. +toolong:
  54498. + return "<path too long>";
  54499. +}
  54500. +EXPORT_SYMBOL(pax_get_path);
  54501. +
  54502. +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
  54503. +{
  54504. + struct task_struct *tsk = current;
  54505. + struct mm_struct *mm = current->mm;
  54506. + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
  54507. + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
  54508. + char *path_exec = NULL;
  54509. + char *path_fault = NULL;
  54510. + unsigned long start = 0UL, end = 0UL, offset = 0UL;
  54511. + siginfo_t info = { };
  54512. +
  54513. + if (buffer_exec && buffer_fault) {
  54514. + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
  54515. +
  54516. + down_read(&mm->mmap_sem);
  54517. + vma = mm->mmap;
  54518. + while (vma && (!vma_exec || !vma_fault)) {
  54519. + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
  54520. + vma_exec = vma;
  54521. + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
  54522. + vma_fault = vma;
  54523. + vma = vma->vm_next;
  54524. + }
  54525. + if (vma_exec)
  54526. + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
  54527. + if (vma_fault) {
  54528. + start = vma_fault->vm_start;
  54529. + end = vma_fault->vm_end;
  54530. + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
  54531. + if (vma_fault->vm_file)
  54532. + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
  54533. + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
  54534. + path_fault = "<heap>";
  54535. + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
  54536. + path_fault = "<stack>";
  54537. + else
  54538. + path_fault = "<anonymous mapping>";
  54539. + }
  54540. + up_read(&mm->mmap_sem);
  54541. + }
  54542. + if (tsk->signal->curr_ip)
  54543. + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
  54544. + else
  54545. + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
  54546. + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
  54547. + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
  54548. + free_page((unsigned long)buffer_exec);
  54549. + free_page((unsigned long)buffer_fault);
  54550. + pax_report_insns(regs, pc, sp);
  54551. + info.si_signo = SIGKILL;
  54552. + info.si_errno = 0;
  54553. + info.si_code = SI_KERNEL;
  54554. + info.si_pid = 0;
  54555. + info.si_uid = 0;
  54556. + do_coredump(&info);
  54557. +}
  54558. +#endif
  54559. +
  54560. +#ifdef CONFIG_PAX_REFCOUNT
  54561. +void pax_report_refcount_overflow(struct pt_regs *regs)
  54562. +{
  54563. + if (current->signal->curr_ip)
  54564. + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
  54565. + &current->signal->curr_ip, current->comm, task_pid_nr(current),
  54566. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
  54567. + else
  54568. + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
  54569. + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
  54570. + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
  54571. + preempt_disable();
  54572. + show_regs(regs);
  54573. + preempt_enable();
  54574. + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
  54575. +}
  54576. +#endif
  54577. +
  54578. +#ifdef CONFIG_PAX_USERCOPY
  54579. +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
  54580. +static noinline int check_stack_object(const void *obj, unsigned long len)
  54581. +{
  54582. + const void * const stack = task_stack_page(current);
  54583. + const void * const stackend = stack + THREAD_SIZE;
  54584. +
  54585. +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
  54586. + const void *frame = NULL;
  54587. + const void *oldframe;
  54588. +#endif
  54589. +
  54590. + if (obj + len < obj)
  54591. + return -1;
  54592. +
  54593. + if (obj + len <= stack || stackend <= obj)
  54594. + return 0;
  54595. +
  54596. + if (obj < stack || stackend < obj + len)
  54597. + return -1;
  54598. +
  54599. +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
  54600. + oldframe = __builtin_frame_address(1);
  54601. + if (oldframe)
  54602. + frame = __builtin_frame_address(2);
  54603. + /*
  54604. + low ----------------------------------------------> high
  54605. + [saved bp][saved ip][args][local vars][saved bp][saved ip]
  54606. + ^----------------^
  54607. + allow copies only within here
  54608. + */
  54609. + while (stack <= frame && frame < stackend) {
  54610. + /* if obj + len extends past the last frame, this
  54611. + check won't pass and the next frame will be 0,
  54612. + causing us to bail out and correctly report
  54613. + the copy as invalid
  54614. + */
  54615. + if (obj + len <= frame)
  54616. + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
  54617. + oldframe = frame;
  54618. + frame = *(const void * const *)frame;
  54619. + }
  54620. + return -1;
  54621. +#else
  54622. + return 1;
  54623. +#endif
  54624. +}
  54625. +
  54626. +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
  54627. +{
  54628. + if (current->signal->curr_ip)
  54629. + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
  54630. + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
  54631. + else
  54632. + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
  54633. + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
  54634. + dump_stack();
  54635. + gr_handle_kernel_exploit();
  54636. + do_group_exit(SIGKILL);
  54637. +}
  54638. +#endif
  54639. +
  54640. +#ifdef CONFIG_PAX_USERCOPY
  54641. +
  54642. +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
  54643. +{
  54644. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  54645. + unsigned long textlow = ktla_ktva((unsigned long)_stext);
  54646. +#ifdef CONFIG_MODULES
  54647. + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
  54648. +#else
  54649. + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
  54650. +#endif
  54651. +
  54652. +#else
  54653. + unsigned long textlow = (unsigned long)_stext;
  54654. + unsigned long texthigh = (unsigned long)_etext;
  54655. +
  54656. +#ifdef CONFIG_X86_64
  54657. + /* check against linear mapping as well */
  54658. + if (high > (unsigned long)__va(__pa(textlow)) &&
  54659. + low < (unsigned long)__va(__pa(texthigh)))
  54660. + return true;
  54661. +#endif
  54662. +
  54663. +#endif
  54664. +
  54665. + if (high <= textlow || low >= texthigh)
  54666. + return false;
  54667. + else
  54668. + return true;
  54669. +}
  54670. +#endif
  54671. +
  54672. +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
  54673. +{
  54674. +
  54675. +#ifdef CONFIG_PAX_USERCOPY
  54676. + const char *type;
  54677. +
  54678. + if (!n)
  54679. + return;
  54680. +
  54681. + type = check_heap_object(ptr, n);
  54682. + if (!type) {
  54683. + int ret = check_stack_object(ptr, n);
  54684. + if (ret == 1 || ret == 2)
  54685. + return;
  54686. + if (ret == 0) {
  54687. + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
  54688. + type = "<kernel text>";
  54689. + else
  54690. + return;
  54691. + } else
  54692. + type = "<process stack>";
  54693. + }
  54694. +
  54695. + pax_report_usercopy(ptr, n, to_user, type);
  54696. +#endif
  54697. +
  54698. +}
  54699. +EXPORT_SYMBOL(__check_object_size);
  54700. +
  54701. +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
  54702. +void pax_track_stack(void)
  54703. +{
  54704. + unsigned long sp = (unsigned long)&sp;
  54705. + if (sp < current_thread_info()->lowest_stack &&
  54706. + sp > (unsigned long)task_stack_page(current))
  54707. + current_thread_info()->lowest_stack = sp;
  54708. +}
  54709. +EXPORT_SYMBOL(pax_track_stack);
  54710. +#endif
  54711. +
  54712. +#ifdef CONFIG_PAX_SIZE_OVERFLOW
  54713. +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
  54714. +{
  54715. + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
  54716. + dump_stack();
  54717. + do_group_exit(SIGKILL);
  54718. +}
  54719. +EXPORT_SYMBOL(report_size_overflow);
  54720. +#endif
  54721. diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
  54722. index 9f9992b..8b59411 100644
  54723. --- a/fs/ext2/balloc.c
  54724. +++ b/fs/ext2/balloc.c
  54725. @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
  54726. free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
  54727. root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
  54728. - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
  54729. + if (free_blocks < root_blocks + 1 &&
  54730. !uid_eq(sbi->s_resuid, current_fsuid()) &&
  54731. (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
  54732. - !in_group_p (sbi->s_resgid))) {
  54733. + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
  54734. return 0;
  54735. }
  54736. return 1;
  54737. diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
  54738. index 9142614..97484fa 100644
  54739. --- a/fs/ext2/xattr.c
  54740. +++ b/fs/ext2/xattr.c
  54741. @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
  54742. struct buffer_head *bh = NULL;
  54743. struct ext2_xattr_entry *entry;
  54744. char *end;
  54745. - size_t rest = buffer_size;
  54746. + size_t rest = buffer_size, total_size = 0;
  54747. int error;
  54748. ea_idebug(inode, "buffer=%p, buffer_size=%ld",
  54749. @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
  54750. buffer += size;
  54751. }
  54752. rest -= size;
  54753. + total_size += size;
  54754. }
  54755. }
  54756. - error = buffer_size - rest; /* total size */
  54757. + error = total_size;
  54758. cleanup:
  54759. brelse(bh);
  54760. diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
  54761. index 22548f5..41521d8 100644
  54762. --- a/fs/ext3/balloc.c
  54763. +++ b/fs/ext3/balloc.c
  54764. @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
  54765. free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
  54766. root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
  54767. - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
  54768. + if (free_blocks < root_blocks + 1 &&
  54769. !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
  54770. (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
  54771. - !in_group_p (sbi->s_resgid))) {
  54772. + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
  54773. return 0;
  54774. }
  54775. return 1;
  54776. diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
  54777. index c6874be..f8a6ae8 100644
  54778. --- a/fs/ext3/xattr.c
  54779. +++ b/fs/ext3/xattr.c
  54780. @@ -330,7 +330,7 @@ static int
  54781. ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
  54782. char *buffer, size_t buffer_size)
  54783. {
  54784. - size_t rest = buffer_size;
  54785. + size_t rest = buffer_size, total_size = 0;
  54786. for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
  54787. const struct xattr_handler *handler =
  54788. @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
  54789. buffer += size;
  54790. }
  54791. rest -= size;
  54792. + total_size += size;
  54793. }
  54794. }
  54795. - return buffer_size - rest;
  54796. + return total_size;
  54797. }
  54798. static int
  54799. diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
  54800. index 6ea7b14..8fa16d9 100644
  54801. --- a/fs/ext4/balloc.c
  54802. +++ b/fs/ext4/balloc.c
  54803. @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
  54804. /* Hm, nope. Are (enough) root reserved clusters available? */
  54805. if (uid_eq(sbi->s_resuid, current_fsuid()) ||
  54806. (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
  54807. - capable(CAP_SYS_RESOURCE) ||
  54808. - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
  54809. + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
  54810. + capable_nolog(CAP_SYS_RESOURCE)) {
  54811. if (free_clusters >= (nclusters + dirty_clusters +
  54812. resv_clusters))
  54813. diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
  54814. index 3a603a8..9b868ba 100644
  54815. --- a/fs/ext4/ext4.h
  54816. +++ b/fs/ext4/ext4.h
  54817. @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
  54818. unsigned long s_mb_last_start;
  54819. /* stats for buddy allocator */
  54820. - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
  54821. - atomic_t s_bal_success; /* we found long enough chunks */
  54822. - atomic_t s_bal_allocated; /* in blocks */
  54823. - atomic_t s_bal_ex_scanned; /* total extents scanned */
  54824. - atomic_t s_bal_goals; /* goal hits */
  54825. - atomic_t s_bal_breaks; /* too long searches */
  54826. - atomic_t s_bal_2orders; /* 2^order hits */
  54827. + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
  54828. + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
  54829. + atomic_unchecked_t s_bal_allocated; /* in blocks */
  54830. + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
  54831. + atomic_unchecked_t s_bal_goals; /* goal hits */
  54832. + atomic_unchecked_t s_bal_breaks; /* too long searches */
  54833. + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
  54834. spinlock_t s_bal_lock;
  54835. unsigned long s_mb_buddies_generated;
  54836. unsigned long long s_mb_generation_time;
  54837. - atomic_t s_mb_lost_chunks;
  54838. - atomic_t s_mb_preallocated;
  54839. - atomic_t s_mb_discarded;
  54840. + atomic_unchecked_t s_mb_lost_chunks;
  54841. + atomic_unchecked_t s_mb_preallocated;
  54842. + atomic_unchecked_t s_mb_discarded;
  54843. atomic_t s_lock_busy;
  54844. /* locality groups */
  54845. diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
  54846. index 04a5c75..09894fa 100644
  54847. --- a/fs/ext4/mballoc.c
  54848. +++ b/fs/ext4/mballoc.c
  54849. @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
  54850. BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
  54851. if (EXT4_SB(sb)->s_mb_stats)
  54852. - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
  54853. + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
  54854. break;
  54855. }
  54856. @@ -2189,7 +2189,7 @@ repeat:
  54857. ac->ac_status = AC_STATUS_CONTINUE;
  54858. ac->ac_flags |= EXT4_MB_HINT_FIRST;
  54859. cr = 3;
  54860. - atomic_inc(&sbi->s_mb_lost_chunks);
  54861. + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
  54862. goto repeat;
  54863. }
  54864. }
  54865. @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
  54866. if (sbi->s_mb_stats) {
  54867. ext4_msg(sb, KERN_INFO,
  54868. "mballoc: %u blocks %u reqs (%u success)",
  54869. - atomic_read(&sbi->s_bal_allocated),
  54870. - atomic_read(&sbi->s_bal_reqs),
  54871. - atomic_read(&sbi->s_bal_success));
  54872. + atomic_read_unchecked(&sbi->s_bal_allocated),
  54873. + atomic_read_unchecked(&sbi->s_bal_reqs),
  54874. + atomic_read_unchecked(&sbi->s_bal_success));
  54875. ext4_msg(sb, KERN_INFO,
  54876. "mballoc: %u extents scanned, %u goal hits, "
  54877. "%u 2^N hits, %u breaks, %u lost",
  54878. - atomic_read(&sbi->s_bal_ex_scanned),
  54879. - atomic_read(&sbi->s_bal_goals),
  54880. - atomic_read(&sbi->s_bal_2orders),
  54881. - atomic_read(&sbi->s_bal_breaks),
  54882. - atomic_read(&sbi->s_mb_lost_chunks));
  54883. + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
  54884. + atomic_read_unchecked(&sbi->s_bal_goals),
  54885. + atomic_read_unchecked(&sbi->s_bal_2orders),
  54886. + atomic_read_unchecked(&sbi->s_bal_breaks),
  54887. + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
  54888. ext4_msg(sb, KERN_INFO,
  54889. "mballoc: %lu generated and it took %Lu",
  54890. sbi->s_mb_buddies_generated,
  54891. sbi->s_mb_generation_time);
  54892. ext4_msg(sb, KERN_INFO,
  54893. "mballoc: %u preallocated, %u discarded",
  54894. - atomic_read(&sbi->s_mb_preallocated),
  54895. - atomic_read(&sbi->s_mb_discarded));
  54896. + atomic_read_unchecked(&sbi->s_mb_preallocated),
  54897. + atomic_read_unchecked(&sbi->s_mb_discarded));
  54898. }
  54899. free_percpu(sbi->s_locality_groups);
  54900. @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
  54901. struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
  54902. if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
  54903. - atomic_inc(&sbi->s_bal_reqs);
  54904. - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
  54905. + atomic_inc_unchecked(&sbi->s_bal_reqs);
  54906. + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
  54907. if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
  54908. - atomic_inc(&sbi->s_bal_success);
  54909. - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
  54910. + atomic_inc_unchecked(&sbi->s_bal_success);
  54911. + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
  54912. if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
  54913. ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
  54914. - atomic_inc(&sbi->s_bal_goals);
  54915. + atomic_inc_unchecked(&sbi->s_bal_goals);
  54916. if (ac->ac_found > sbi->s_mb_max_to_scan)
  54917. - atomic_inc(&sbi->s_bal_breaks);
  54918. + atomic_inc_unchecked(&sbi->s_bal_breaks);
  54919. }
  54920. if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
  54921. @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
  54922. trace_ext4_mb_new_inode_pa(ac, pa);
  54923. ext4_mb_use_inode_pa(ac, pa);
  54924. - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
  54925. + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
  54926. ei = EXT4_I(ac->ac_inode);
  54927. grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
  54928. @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
  54929. trace_ext4_mb_new_group_pa(ac, pa);
  54930. ext4_mb_use_group_pa(ac, pa);
  54931. - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
  54932. + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
  54933. grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
  54934. lg = ac->ac_lg;
  54935. @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
  54936. * from the bitmap and continue.
  54937. */
  54938. }
  54939. - atomic_add(free, &sbi->s_mb_discarded);
  54940. + atomic_add_unchecked(free, &sbi->s_mb_discarded);
  54941. return err;
  54942. }
  54943. @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
  54944. ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
  54945. BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
  54946. mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
  54947. - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
  54948. + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
  54949. trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
  54950. return 0;
  54951. diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
  54952. index 04434ad..6404663 100644
  54953. --- a/fs/ext4/mmp.c
  54954. +++ b/fs/ext4/mmp.c
  54955. @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
  54956. void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
  54957. const char *function, unsigned int line, const char *msg)
  54958. {
  54959. - __ext4_warning(sb, function, line, msg);
  54960. + __ext4_warning(sb, function, line, "%s", msg);
  54961. __ext4_warning(sb, function, line,
  54962. "MMP failure info: last update time: %llu, last update "
  54963. "node: %s, last update device: %s\n",
  54964. diff --git a/fs/ext4/super.c b/fs/ext4/super.c
  54965. index 710fed2..a82e4e8 100644
  54966. --- a/fs/ext4/super.c
  54967. +++ b/fs/ext4/super.c
  54968. @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
  54969. }
  54970. #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
  54971. -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
  54972. +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
  54973. "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
  54974. #ifdef CONFIG_QUOTA
  54975. @@ -2450,7 +2450,7 @@ struct ext4_attr {
  54976. int offset;
  54977. int deprecated_val;
  54978. } u;
  54979. -};
  54980. +} __do_const;
  54981. static int parse_strtoull(const char *buf,
  54982. unsigned long long max, unsigned long long *value)
  54983. diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
  54984. index 55e611c..cfad16d 100644
  54985. --- a/fs/ext4/xattr.c
  54986. +++ b/fs/ext4/xattr.c
  54987. @@ -381,7 +381,7 @@ static int
  54988. ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
  54989. char *buffer, size_t buffer_size)
  54990. {
  54991. - size_t rest = buffer_size;
  54992. + size_t rest = buffer_size, total_size = 0;
  54993. for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
  54994. const struct xattr_handler *handler =
  54995. @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
  54996. buffer += size;
  54997. }
  54998. rest -= size;
  54999. + total_size += size;
  55000. }
  55001. }
  55002. - return buffer_size - rest;
  55003. + return total_size;
  55004. }
  55005. static int
  55006. diff --git a/fs/fcntl.c b/fs/fcntl.c
  55007. index ef68665..5deacdc 100644
  55008. --- a/fs/fcntl.c
  55009. +++ b/fs/fcntl.c
  55010. @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
  55011. if (err)
  55012. return err;
  55013. + if (gr_handle_chroot_fowner(pid, type))
  55014. + return -ENOENT;
  55015. + if (gr_check_protected_task_fowner(pid, type))
  55016. + return -EACCES;
  55017. +
  55018. f_modown(filp, pid, type, force);
  55019. return 0;
  55020. }
  55021. diff --git a/fs/fhandle.c b/fs/fhandle.c
  55022. index 999ff5c..41f4109 100644
  55023. --- a/fs/fhandle.c
  55024. +++ b/fs/fhandle.c
  55025. @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
  55026. } else
  55027. retval = 0;
  55028. /* copy the mount id */
  55029. - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
  55030. - sizeof(*mnt_id)) ||
  55031. + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
  55032. copy_to_user(ufh, handle,
  55033. sizeof(struct file_handle) + handle_bytes))
  55034. retval = -EFAULT;
  55035. diff --git a/fs/file.c b/fs/file.c
  55036. index eb56a13..ccee850 100644
  55037. --- a/fs/file.c
  55038. +++ b/fs/file.c
  55039. @@ -16,6 +16,7 @@
  55040. #include <linux/slab.h>
  55041. #include <linux/vmalloc.h>
  55042. #include <linux/file.h>
  55043. +#include <linux/security.h>
  55044. #include <linux/fdtable.h>
  55045. #include <linux/bitops.h>
  55046. #include <linux/interrupt.h>
  55047. @@ -141,7 +142,7 @@ out:
  55048. * Return <0 error code on error; 1 on successful completion.
  55049. * The files->file_lock should be held on entry, and will be held on exit.
  55050. */
  55051. -static int expand_fdtable(struct files_struct *files, int nr)
  55052. +static int expand_fdtable(struct files_struct *files, unsigned int nr)
  55053. __releases(files->file_lock)
  55054. __acquires(files->file_lock)
  55055. {
  55056. @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
  55057. * expanded and execution may have blocked.
  55058. * The files->file_lock should be held on entry, and will be held on exit.
  55059. */
  55060. -static int expand_files(struct files_struct *files, int nr)
  55061. +static int expand_files(struct files_struct *files, unsigned int nr)
  55062. {
  55063. struct fdtable *fdt;
  55064. @@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
  55065. if (!file)
  55066. return __close_fd(files, fd);
  55067. + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
  55068. if (fd >= rlimit(RLIMIT_NOFILE))
  55069. return -EBADF;
  55070. @@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
  55071. if (unlikely(oldfd == newfd))
  55072. return -EINVAL;
  55073. + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
  55074. if (newfd >= rlimit(RLIMIT_NOFILE))
  55075. return -EBADF;
  55076. @@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
  55077. int f_dupfd(unsigned int from, struct file *file, unsigned flags)
  55078. {
  55079. int err;
  55080. + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
  55081. if (from >= rlimit(RLIMIT_NOFILE))
  55082. return -EINVAL;
  55083. err = alloc_fd(from, flags);
  55084. diff --git a/fs/filesystems.c b/fs/filesystems.c
  55085. index 92567d9..fcd8cbf 100644
  55086. --- a/fs/filesystems.c
  55087. +++ b/fs/filesystems.c
  55088. @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
  55089. int len = dot ? dot - name : strlen(name);
  55090. fs = __get_fs_type(name, len);
  55091. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  55092. + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
  55093. +#else
  55094. if (!fs && (request_module("fs-%.*s", len, name) == 0))
  55095. +#endif
  55096. fs = __get_fs_type(name, len);
  55097. if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
  55098. diff --git a/fs/fs_struct.c b/fs/fs_struct.c
  55099. index 7dca743..543d620 100644
  55100. --- a/fs/fs_struct.c
  55101. +++ b/fs/fs_struct.c
  55102. @@ -4,6 +4,7 @@
  55103. #include <linux/path.h>
  55104. #include <linux/slab.h>
  55105. #include <linux/fs_struct.h>
  55106. +#include <linux/grsecurity.h>
  55107. #include "internal.h"
  55108. /*
  55109. @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
  55110. write_seqcount_begin(&fs->seq);
  55111. old_root = fs->root;
  55112. fs->root = *path;
  55113. + gr_set_chroot_entries(current, path);
  55114. write_seqcount_end(&fs->seq);
  55115. spin_unlock(&fs->lock);
  55116. if (old_root.dentry)
  55117. @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
  55118. int hits = 0;
  55119. spin_lock(&fs->lock);
  55120. write_seqcount_begin(&fs->seq);
  55121. + /* this root replacement is only done by pivot_root,
  55122. + leave grsec's chroot tagging alone for this task
  55123. + so that a pivoted root isn't treated as a chroot
  55124. + */
  55125. hits += replace_path(&fs->root, old_root, new_root);
  55126. hits += replace_path(&fs->pwd, old_root, new_root);
  55127. write_seqcount_end(&fs->seq);
  55128. @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
  55129. task_lock(tsk);
  55130. spin_lock(&fs->lock);
  55131. tsk->fs = NULL;
  55132. - kill = !--fs->users;
  55133. + gr_clear_chroot_entries(tsk);
  55134. + kill = !atomic_dec_return(&fs->users);
  55135. spin_unlock(&fs->lock);
  55136. task_unlock(tsk);
  55137. if (kill)
  55138. @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
  55139. struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
  55140. /* We don't need to lock fs - think why ;-) */
  55141. if (fs) {
  55142. - fs->users = 1;
  55143. + atomic_set(&fs->users, 1);
  55144. fs->in_exec = 0;
  55145. spin_lock_init(&fs->lock);
  55146. seqcount_init(&fs->seq);
  55147. @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
  55148. spin_lock(&old->lock);
  55149. fs->root = old->root;
  55150. path_get(&fs->root);
  55151. + /* instead of calling gr_set_chroot_entries here,
  55152. + we call it from every caller of this function
  55153. + */
  55154. fs->pwd = old->pwd;
  55155. path_get(&fs->pwd);
  55156. spin_unlock(&old->lock);
  55157. @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
  55158. task_lock(current);
  55159. spin_lock(&fs->lock);
  55160. - kill = !--fs->users;
  55161. + kill = !atomic_dec_return(&fs->users);
  55162. current->fs = new_fs;
  55163. + gr_set_chroot_entries(current, &new_fs->root);
  55164. spin_unlock(&fs->lock);
  55165. task_unlock(current);
  55166. @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
  55167. int current_umask(void)
  55168. {
  55169. - return current->fs->umask;
  55170. + return current->fs->umask | gr_acl_umask();
  55171. }
  55172. EXPORT_SYMBOL(current_umask);
  55173. /* to be mentioned only in INIT_TASK */
  55174. struct fs_struct init_fs = {
  55175. - .users = 1,
  55176. + .users = ATOMIC_INIT(1),
  55177. .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
  55178. .seq = SEQCNT_ZERO(init_fs.seq),
  55179. .umask = 0022,
  55180. diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
  55181. index 29d7feb..303644d 100644
  55182. --- a/fs/fscache/cookie.c
  55183. +++ b/fs/fscache/cookie.c
  55184. @@ -19,7 +19,7 @@
  55185. struct kmem_cache *fscache_cookie_jar;
  55186. -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
  55187. +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
  55188. static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
  55189. static int fscache_alloc_object(struct fscache_cache *cache,
  55190. @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
  55191. parent ? (char *) parent->def->name : "<no-parent>",
  55192. def->name, netfs_data, enable);
  55193. - fscache_stat(&fscache_n_acquires);
  55194. + fscache_stat_unchecked(&fscache_n_acquires);
  55195. /* if there's no parent cookie, then we don't create one here either */
  55196. if (!parent) {
  55197. - fscache_stat(&fscache_n_acquires_null);
  55198. + fscache_stat_unchecked(&fscache_n_acquires_null);
  55199. _leave(" [no parent]");
  55200. return NULL;
  55201. }
  55202. @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
  55203. /* allocate and initialise a cookie */
  55204. cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
  55205. if (!cookie) {
  55206. - fscache_stat(&fscache_n_acquires_oom);
  55207. + fscache_stat_unchecked(&fscache_n_acquires_oom);
  55208. _leave(" [ENOMEM]");
  55209. return NULL;
  55210. }
  55211. @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
  55212. switch (cookie->def->type) {
  55213. case FSCACHE_COOKIE_TYPE_INDEX:
  55214. - fscache_stat(&fscache_n_cookie_index);
  55215. + fscache_stat_unchecked(&fscache_n_cookie_index);
  55216. break;
  55217. case FSCACHE_COOKIE_TYPE_DATAFILE:
  55218. - fscache_stat(&fscache_n_cookie_data);
  55219. + fscache_stat_unchecked(&fscache_n_cookie_data);
  55220. break;
  55221. default:
  55222. - fscache_stat(&fscache_n_cookie_special);
  55223. + fscache_stat_unchecked(&fscache_n_cookie_special);
  55224. break;
  55225. }
  55226. @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
  55227. } else {
  55228. atomic_dec(&parent->n_children);
  55229. __fscache_cookie_put(cookie);
  55230. - fscache_stat(&fscache_n_acquires_nobufs);
  55231. + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
  55232. _leave(" = NULL");
  55233. return NULL;
  55234. }
  55235. @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
  55236. }
  55237. }
  55238. - fscache_stat(&fscache_n_acquires_ok);
  55239. + fscache_stat_unchecked(&fscache_n_acquires_ok);
  55240. _leave(" = %p", cookie);
  55241. return cookie;
  55242. }
  55243. @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
  55244. cache = fscache_select_cache_for_object(cookie->parent);
  55245. if (!cache) {
  55246. up_read(&fscache_addremove_sem);
  55247. - fscache_stat(&fscache_n_acquires_no_cache);
  55248. + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
  55249. _leave(" = -ENOMEDIUM [no cache]");
  55250. return -ENOMEDIUM;
  55251. }
  55252. @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
  55253. object = cache->ops->alloc_object(cache, cookie);
  55254. fscache_stat_d(&fscache_n_cop_alloc_object);
  55255. if (IS_ERR(object)) {
  55256. - fscache_stat(&fscache_n_object_no_alloc);
  55257. + fscache_stat_unchecked(&fscache_n_object_no_alloc);
  55258. ret = PTR_ERR(object);
  55259. goto error;
  55260. }
  55261. - fscache_stat(&fscache_n_object_alloc);
  55262. + fscache_stat_unchecked(&fscache_n_object_alloc);
  55263. - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
  55264. + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
  55265. _debug("ALLOC OBJ%x: %s {%lx}",
  55266. object->debug_id, cookie->def->name, object->events);
  55267. @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
  55268. _enter("{%s}", cookie->def->name);
  55269. - fscache_stat(&fscache_n_invalidates);
  55270. + fscache_stat_unchecked(&fscache_n_invalidates);
  55271. /* Only permit invalidation of data files. Invalidating an index will
  55272. * require the caller to release all its attachments to the tree rooted
  55273. @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
  55274. {
  55275. struct fscache_object *object;
  55276. - fscache_stat(&fscache_n_updates);
  55277. + fscache_stat_unchecked(&fscache_n_updates);
  55278. if (!cookie) {
  55279. - fscache_stat(&fscache_n_updates_null);
  55280. + fscache_stat_unchecked(&fscache_n_updates_null);
  55281. _leave(" [no cookie]");
  55282. return;
  55283. }
  55284. @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
  55285. */
  55286. void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
  55287. {
  55288. - fscache_stat(&fscache_n_relinquishes);
  55289. + fscache_stat_unchecked(&fscache_n_relinquishes);
  55290. if (retire)
  55291. - fscache_stat(&fscache_n_relinquishes_retire);
  55292. + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
  55293. if (!cookie) {
  55294. - fscache_stat(&fscache_n_relinquishes_null);
  55295. + fscache_stat_unchecked(&fscache_n_relinquishes_null);
  55296. _leave(" [no cookie]");
  55297. return;
  55298. }
  55299. @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
  55300. if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
  55301. goto inconsistent;
  55302. - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
  55303. + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
  55304. __fscache_use_cookie(cookie);
  55305. if (fscache_submit_op(object, op) < 0)
  55306. diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
  55307. index 4226f66..0fb3f45 100644
  55308. --- a/fs/fscache/internal.h
  55309. +++ b/fs/fscache/internal.h
  55310. @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
  55311. extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
  55312. extern int fscache_wait_for_operation_activation(struct fscache_object *,
  55313. struct fscache_operation *,
  55314. - atomic_t *,
  55315. - atomic_t *,
  55316. + atomic_unchecked_t *,
  55317. + atomic_unchecked_t *,
  55318. void (*)(struct fscache_operation *));
  55319. extern void fscache_invalidate_writes(struct fscache_cookie *);
  55320. @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
  55321. * stats.c
  55322. */
  55323. #ifdef CONFIG_FSCACHE_STATS
  55324. -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
  55325. -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
  55326. +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
  55327. +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
  55328. -extern atomic_t fscache_n_op_pend;
  55329. -extern atomic_t fscache_n_op_run;
  55330. -extern atomic_t fscache_n_op_enqueue;
  55331. -extern atomic_t fscache_n_op_deferred_release;
  55332. -extern atomic_t fscache_n_op_release;
  55333. -extern atomic_t fscache_n_op_gc;
  55334. -extern atomic_t fscache_n_op_cancelled;
  55335. -extern atomic_t fscache_n_op_rejected;
  55336. +extern atomic_unchecked_t fscache_n_op_pend;
  55337. +extern atomic_unchecked_t fscache_n_op_run;
  55338. +extern atomic_unchecked_t fscache_n_op_enqueue;
  55339. +extern atomic_unchecked_t fscache_n_op_deferred_release;
  55340. +extern atomic_unchecked_t fscache_n_op_release;
  55341. +extern atomic_unchecked_t fscache_n_op_gc;
  55342. +extern atomic_unchecked_t fscache_n_op_cancelled;
  55343. +extern atomic_unchecked_t fscache_n_op_rejected;
  55344. -extern atomic_t fscache_n_attr_changed;
  55345. -extern atomic_t fscache_n_attr_changed_ok;
  55346. -extern atomic_t fscache_n_attr_changed_nobufs;
  55347. -extern atomic_t fscache_n_attr_changed_nomem;
  55348. -extern atomic_t fscache_n_attr_changed_calls;
  55349. +extern atomic_unchecked_t fscache_n_attr_changed;
  55350. +extern atomic_unchecked_t fscache_n_attr_changed_ok;
  55351. +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
  55352. +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
  55353. +extern atomic_unchecked_t fscache_n_attr_changed_calls;
  55354. -extern atomic_t fscache_n_allocs;
  55355. -extern atomic_t fscache_n_allocs_ok;
  55356. -extern atomic_t fscache_n_allocs_wait;
  55357. -extern atomic_t fscache_n_allocs_nobufs;
  55358. -extern atomic_t fscache_n_allocs_intr;
  55359. -extern atomic_t fscache_n_allocs_object_dead;
  55360. -extern atomic_t fscache_n_alloc_ops;
  55361. -extern atomic_t fscache_n_alloc_op_waits;
  55362. +extern atomic_unchecked_t fscache_n_allocs;
  55363. +extern atomic_unchecked_t fscache_n_allocs_ok;
  55364. +extern atomic_unchecked_t fscache_n_allocs_wait;
  55365. +extern atomic_unchecked_t fscache_n_allocs_nobufs;
  55366. +extern atomic_unchecked_t fscache_n_allocs_intr;
  55367. +extern atomic_unchecked_t fscache_n_allocs_object_dead;
  55368. +extern atomic_unchecked_t fscache_n_alloc_ops;
  55369. +extern atomic_unchecked_t fscache_n_alloc_op_waits;
  55370. -extern atomic_t fscache_n_retrievals;
  55371. -extern atomic_t fscache_n_retrievals_ok;
  55372. -extern atomic_t fscache_n_retrievals_wait;
  55373. -extern atomic_t fscache_n_retrievals_nodata;
  55374. -extern atomic_t fscache_n_retrievals_nobufs;
  55375. -extern atomic_t fscache_n_retrievals_intr;
  55376. -extern atomic_t fscache_n_retrievals_nomem;
  55377. -extern atomic_t fscache_n_retrievals_object_dead;
  55378. -extern atomic_t fscache_n_retrieval_ops;
  55379. -extern atomic_t fscache_n_retrieval_op_waits;
  55380. +extern atomic_unchecked_t fscache_n_retrievals;
  55381. +extern atomic_unchecked_t fscache_n_retrievals_ok;
  55382. +extern atomic_unchecked_t fscache_n_retrievals_wait;
  55383. +extern atomic_unchecked_t fscache_n_retrievals_nodata;
  55384. +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
  55385. +extern atomic_unchecked_t fscache_n_retrievals_intr;
  55386. +extern atomic_unchecked_t fscache_n_retrievals_nomem;
  55387. +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
  55388. +extern atomic_unchecked_t fscache_n_retrieval_ops;
  55389. +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
  55390. -extern atomic_t fscache_n_stores;
  55391. -extern atomic_t fscache_n_stores_ok;
  55392. -extern atomic_t fscache_n_stores_again;
  55393. -extern atomic_t fscache_n_stores_nobufs;
  55394. -extern atomic_t fscache_n_stores_oom;
  55395. -extern atomic_t fscache_n_store_ops;
  55396. -extern atomic_t fscache_n_store_calls;
  55397. -extern atomic_t fscache_n_store_pages;
  55398. -extern atomic_t fscache_n_store_radix_deletes;
  55399. -extern atomic_t fscache_n_store_pages_over_limit;
  55400. +extern atomic_unchecked_t fscache_n_stores;
  55401. +extern atomic_unchecked_t fscache_n_stores_ok;
  55402. +extern atomic_unchecked_t fscache_n_stores_again;
  55403. +extern atomic_unchecked_t fscache_n_stores_nobufs;
  55404. +extern atomic_unchecked_t fscache_n_stores_oom;
  55405. +extern atomic_unchecked_t fscache_n_store_ops;
  55406. +extern atomic_unchecked_t fscache_n_store_calls;
  55407. +extern atomic_unchecked_t fscache_n_store_pages;
  55408. +extern atomic_unchecked_t fscache_n_store_radix_deletes;
  55409. +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
  55410. -extern atomic_t fscache_n_store_vmscan_not_storing;
  55411. -extern atomic_t fscache_n_store_vmscan_gone;
  55412. -extern atomic_t fscache_n_store_vmscan_busy;
  55413. -extern atomic_t fscache_n_store_vmscan_cancelled;
  55414. -extern atomic_t fscache_n_store_vmscan_wait;
  55415. +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
  55416. +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
  55417. +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
  55418. +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
  55419. +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
  55420. -extern atomic_t fscache_n_marks;
  55421. -extern atomic_t fscache_n_uncaches;
  55422. +extern atomic_unchecked_t fscache_n_marks;
  55423. +extern atomic_unchecked_t fscache_n_uncaches;
  55424. -extern atomic_t fscache_n_acquires;
  55425. -extern atomic_t fscache_n_acquires_null;
  55426. -extern atomic_t fscache_n_acquires_no_cache;
  55427. -extern atomic_t fscache_n_acquires_ok;
  55428. -extern atomic_t fscache_n_acquires_nobufs;
  55429. -extern atomic_t fscache_n_acquires_oom;
  55430. +extern atomic_unchecked_t fscache_n_acquires;
  55431. +extern atomic_unchecked_t fscache_n_acquires_null;
  55432. +extern atomic_unchecked_t fscache_n_acquires_no_cache;
  55433. +extern atomic_unchecked_t fscache_n_acquires_ok;
  55434. +extern atomic_unchecked_t fscache_n_acquires_nobufs;
  55435. +extern atomic_unchecked_t fscache_n_acquires_oom;
  55436. -extern atomic_t fscache_n_invalidates;
  55437. -extern atomic_t fscache_n_invalidates_run;
  55438. +extern atomic_unchecked_t fscache_n_invalidates;
  55439. +extern atomic_unchecked_t fscache_n_invalidates_run;
  55440. -extern atomic_t fscache_n_updates;
  55441. -extern atomic_t fscache_n_updates_null;
  55442. -extern atomic_t fscache_n_updates_run;
  55443. +extern atomic_unchecked_t fscache_n_updates;
  55444. +extern atomic_unchecked_t fscache_n_updates_null;
  55445. +extern atomic_unchecked_t fscache_n_updates_run;
  55446. -extern atomic_t fscache_n_relinquishes;
  55447. -extern atomic_t fscache_n_relinquishes_null;
  55448. -extern atomic_t fscache_n_relinquishes_waitcrt;
  55449. -extern atomic_t fscache_n_relinquishes_retire;
  55450. +extern atomic_unchecked_t fscache_n_relinquishes;
  55451. +extern atomic_unchecked_t fscache_n_relinquishes_null;
  55452. +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
  55453. +extern atomic_unchecked_t fscache_n_relinquishes_retire;
  55454. -extern atomic_t fscache_n_cookie_index;
  55455. -extern atomic_t fscache_n_cookie_data;
  55456. -extern atomic_t fscache_n_cookie_special;
  55457. +extern atomic_unchecked_t fscache_n_cookie_index;
  55458. +extern atomic_unchecked_t fscache_n_cookie_data;
  55459. +extern atomic_unchecked_t fscache_n_cookie_special;
  55460. -extern atomic_t fscache_n_object_alloc;
  55461. -extern atomic_t fscache_n_object_no_alloc;
  55462. -extern atomic_t fscache_n_object_lookups;
  55463. -extern atomic_t fscache_n_object_lookups_negative;
  55464. -extern atomic_t fscache_n_object_lookups_positive;
  55465. -extern atomic_t fscache_n_object_lookups_timed_out;
  55466. -extern atomic_t fscache_n_object_created;
  55467. -extern atomic_t fscache_n_object_avail;
  55468. -extern atomic_t fscache_n_object_dead;
  55469. +extern atomic_unchecked_t fscache_n_object_alloc;
  55470. +extern atomic_unchecked_t fscache_n_object_no_alloc;
  55471. +extern atomic_unchecked_t fscache_n_object_lookups;
  55472. +extern atomic_unchecked_t fscache_n_object_lookups_negative;
  55473. +extern atomic_unchecked_t fscache_n_object_lookups_positive;
  55474. +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
  55475. +extern atomic_unchecked_t fscache_n_object_created;
  55476. +extern atomic_unchecked_t fscache_n_object_avail;
  55477. +extern atomic_unchecked_t fscache_n_object_dead;
  55478. -extern atomic_t fscache_n_checkaux_none;
  55479. -extern atomic_t fscache_n_checkaux_okay;
  55480. -extern atomic_t fscache_n_checkaux_update;
  55481. -extern atomic_t fscache_n_checkaux_obsolete;
  55482. +extern atomic_unchecked_t fscache_n_checkaux_none;
  55483. +extern atomic_unchecked_t fscache_n_checkaux_okay;
  55484. +extern atomic_unchecked_t fscache_n_checkaux_update;
  55485. +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
  55486. extern atomic_t fscache_n_cop_alloc_object;
  55487. extern atomic_t fscache_n_cop_lookup_object;
  55488. @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
  55489. atomic_inc(stat);
  55490. }
  55491. +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
  55492. +{
  55493. + atomic_inc_unchecked(stat);
  55494. +}
  55495. +
  55496. static inline void fscache_stat_d(atomic_t *stat)
  55497. {
  55498. atomic_dec(stat);
  55499. @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
  55500. #define __fscache_stat(stat) (NULL)
  55501. #define fscache_stat(stat) do {} while (0)
  55502. +#define fscache_stat_unchecked(stat) do {} while (0)
  55503. #define fscache_stat_d(stat) do {} while (0)
  55504. #endif
  55505. diff --git a/fs/fscache/object.c b/fs/fscache/object.c
  55506. index d3b4539..ed0c659 100644
  55507. --- a/fs/fscache/object.c
  55508. +++ b/fs/fscache/object.c
  55509. @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
  55510. _debug("LOOKUP \"%s\" in \"%s\"",
  55511. cookie->def->name, object->cache->tag->name);
  55512. - fscache_stat(&fscache_n_object_lookups);
  55513. + fscache_stat_unchecked(&fscache_n_object_lookups);
  55514. fscache_stat(&fscache_n_cop_lookup_object);
  55515. ret = object->cache->ops->lookup_object(object);
  55516. fscache_stat_d(&fscache_n_cop_lookup_object);
  55517. @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
  55518. if (ret == -ETIMEDOUT) {
  55519. /* probably stuck behind another object, so move this one to
  55520. * the back of the queue */
  55521. - fscache_stat(&fscache_n_object_lookups_timed_out);
  55522. + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
  55523. _leave(" [timeout]");
  55524. return NO_TRANSIT;
  55525. }
  55526. @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
  55527. _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
  55528. if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
  55529. - fscache_stat(&fscache_n_object_lookups_negative);
  55530. + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
  55531. /* Allow write requests to begin stacking up and read requests to begin
  55532. * returning ENODATA.
  55533. @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
  55534. /* if we were still looking up, then we must have a positive lookup
  55535. * result, in which case there may be data available */
  55536. if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
  55537. - fscache_stat(&fscache_n_object_lookups_positive);
  55538. + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
  55539. /* We do (presumably) have data */
  55540. clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
  55541. @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
  55542. clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
  55543. wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
  55544. } else {
  55545. - fscache_stat(&fscache_n_object_created);
  55546. + fscache_stat_unchecked(&fscache_n_object_created);
  55547. }
  55548. set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
  55549. @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
  55550. fscache_stat_d(&fscache_n_cop_lookup_complete);
  55551. fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
  55552. - fscache_stat(&fscache_n_object_avail);
  55553. + fscache_stat_unchecked(&fscache_n_object_avail);
  55554. _leave("");
  55555. return transit_to(JUMPSTART_DEPS);
  55556. @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
  55557. /* this just shifts the object release to the work processor */
  55558. fscache_put_object(object);
  55559. - fscache_stat(&fscache_n_object_dead);
  55560. + fscache_stat_unchecked(&fscache_n_object_dead);
  55561. _leave("");
  55562. return transit_to(OBJECT_DEAD);
  55563. @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
  55564. enum fscache_checkaux result;
  55565. if (!object->cookie->def->check_aux) {
  55566. - fscache_stat(&fscache_n_checkaux_none);
  55567. + fscache_stat_unchecked(&fscache_n_checkaux_none);
  55568. return FSCACHE_CHECKAUX_OKAY;
  55569. }
  55570. @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
  55571. switch (result) {
  55572. /* entry okay as is */
  55573. case FSCACHE_CHECKAUX_OKAY:
  55574. - fscache_stat(&fscache_n_checkaux_okay);
  55575. + fscache_stat_unchecked(&fscache_n_checkaux_okay);
  55576. break;
  55577. /* entry requires update */
  55578. case FSCACHE_CHECKAUX_NEEDS_UPDATE:
  55579. - fscache_stat(&fscache_n_checkaux_update);
  55580. + fscache_stat_unchecked(&fscache_n_checkaux_update);
  55581. break;
  55582. /* entry requires deletion */
  55583. case FSCACHE_CHECKAUX_OBSOLETE:
  55584. - fscache_stat(&fscache_n_checkaux_obsolete);
  55585. + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
  55586. break;
  55587. default:
  55588. @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
  55589. {
  55590. const struct fscache_state *s;
  55591. - fscache_stat(&fscache_n_invalidates_run);
  55592. + fscache_stat_unchecked(&fscache_n_invalidates_run);
  55593. fscache_stat(&fscache_n_cop_invalidate_object);
  55594. s = _fscache_invalidate_object(object, event);
  55595. fscache_stat_d(&fscache_n_cop_invalidate_object);
  55596. @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
  55597. {
  55598. _enter("{OBJ%x},%d", object->debug_id, event);
  55599. - fscache_stat(&fscache_n_updates_run);
  55600. + fscache_stat_unchecked(&fscache_n_updates_run);
  55601. fscache_stat(&fscache_n_cop_update_object);
  55602. object->cache->ops->update_object(object);
  55603. fscache_stat_d(&fscache_n_cop_update_object);
  55604. diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
  55605. index 318071a..379938b 100644
  55606. --- a/fs/fscache/operation.c
  55607. +++ b/fs/fscache/operation.c
  55608. @@ -17,7 +17,7 @@
  55609. #include <linux/slab.h>
  55610. #include "internal.h"
  55611. -atomic_t fscache_op_debug_id;
  55612. +atomic_unchecked_t fscache_op_debug_id;
  55613. EXPORT_SYMBOL(fscache_op_debug_id);
  55614. /**
  55615. @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
  55616. ASSERTCMP(atomic_read(&op->usage), >, 0);
  55617. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
  55618. - fscache_stat(&fscache_n_op_enqueue);
  55619. + fscache_stat_unchecked(&fscache_n_op_enqueue);
  55620. switch (op->flags & FSCACHE_OP_TYPE) {
  55621. case FSCACHE_OP_ASYNC:
  55622. _debug("queue async");
  55623. @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
  55624. wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
  55625. if (op->processor)
  55626. fscache_enqueue_operation(op);
  55627. - fscache_stat(&fscache_n_op_run);
  55628. + fscache_stat_unchecked(&fscache_n_op_run);
  55629. }
  55630. /*
  55631. @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
  55632. if (object->n_in_progress > 0) {
  55633. atomic_inc(&op->usage);
  55634. list_add_tail(&op->pend_link, &object->pending_ops);
  55635. - fscache_stat(&fscache_n_op_pend);
  55636. + fscache_stat_unchecked(&fscache_n_op_pend);
  55637. } else if (!list_empty(&object->pending_ops)) {
  55638. atomic_inc(&op->usage);
  55639. list_add_tail(&op->pend_link, &object->pending_ops);
  55640. - fscache_stat(&fscache_n_op_pend);
  55641. + fscache_stat_unchecked(&fscache_n_op_pend);
  55642. fscache_start_operations(object);
  55643. } else {
  55644. ASSERTCMP(object->n_in_progress, ==, 0);
  55645. @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
  55646. object->n_exclusive++; /* reads and writes must wait */
  55647. atomic_inc(&op->usage);
  55648. list_add_tail(&op->pend_link, &object->pending_ops);
  55649. - fscache_stat(&fscache_n_op_pend);
  55650. + fscache_stat_unchecked(&fscache_n_op_pend);
  55651. ret = 0;
  55652. } else {
  55653. /* If we're in any other state, there must have been an I/O
  55654. @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
  55655. if (object->n_exclusive > 0) {
  55656. atomic_inc(&op->usage);
  55657. list_add_tail(&op->pend_link, &object->pending_ops);
  55658. - fscache_stat(&fscache_n_op_pend);
  55659. + fscache_stat_unchecked(&fscache_n_op_pend);
  55660. } else if (!list_empty(&object->pending_ops)) {
  55661. atomic_inc(&op->usage);
  55662. list_add_tail(&op->pend_link, &object->pending_ops);
  55663. - fscache_stat(&fscache_n_op_pend);
  55664. + fscache_stat_unchecked(&fscache_n_op_pend);
  55665. fscache_start_operations(object);
  55666. } else {
  55667. ASSERTCMP(object->n_exclusive, ==, 0);
  55668. @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
  55669. object->n_ops++;
  55670. atomic_inc(&op->usage);
  55671. list_add_tail(&op->pend_link, &object->pending_ops);
  55672. - fscache_stat(&fscache_n_op_pend);
  55673. + fscache_stat_unchecked(&fscache_n_op_pend);
  55674. ret = 0;
  55675. } else if (fscache_object_is_dying(object)) {
  55676. - fscache_stat(&fscache_n_op_rejected);
  55677. + fscache_stat_unchecked(&fscache_n_op_rejected);
  55678. op->state = FSCACHE_OP_ST_CANCELLED;
  55679. ret = -ENOBUFS;
  55680. } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
  55681. @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
  55682. ret = -EBUSY;
  55683. if (op->state == FSCACHE_OP_ST_PENDING) {
  55684. ASSERT(!list_empty(&op->pend_link));
  55685. - fscache_stat(&fscache_n_op_cancelled);
  55686. + fscache_stat_unchecked(&fscache_n_op_cancelled);
  55687. list_del_init(&op->pend_link);
  55688. if (do_cancel)
  55689. do_cancel(op);
  55690. @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
  55691. while (!list_empty(&object->pending_ops)) {
  55692. op = list_entry(object->pending_ops.next,
  55693. struct fscache_operation, pend_link);
  55694. - fscache_stat(&fscache_n_op_cancelled);
  55695. + fscache_stat_unchecked(&fscache_n_op_cancelled);
  55696. list_del_init(&op->pend_link);
  55697. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
  55698. @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
  55699. op->state, ==, FSCACHE_OP_ST_CANCELLED);
  55700. op->state = FSCACHE_OP_ST_DEAD;
  55701. - fscache_stat(&fscache_n_op_release);
  55702. + fscache_stat_unchecked(&fscache_n_op_release);
  55703. if (op->release) {
  55704. op->release(op);
  55705. @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
  55706. * lock, and defer it otherwise */
  55707. if (!spin_trylock(&object->lock)) {
  55708. _debug("defer put");
  55709. - fscache_stat(&fscache_n_op_deferred_release);
  55710. + fscache_stat_unchecked(&fscache_n_op_deferred_release);
  55711. cache = object->cache;
  55712. spin_lock(&cache->op_gc_list_lock);
  55713. @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
  55714. _debug("GC DEFERRED REL OBJ%x OP%x",
  55715. object->debug_id, op->debug_id);
  55716. - fscache_stat(&fscache_n_op_gc);
  55717. + fscache_stat_unchecked(&fscache_n_op_gc);
  55718. ASSERTCMP(atomic_read(&op->usage), ==, 0);
  55719. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
  55720. diff --git a/fs/fscache/page.c b/fs/fscache/page.c
  55721. index 7f5c658..6c1e164 100644
  55722. --- a/fs/fscache/page.c
  55723. +++ b/fs/fscache/page.c
  55724. @@ -61,7 +61,7 @@ try_again:
  55725. val = radix_tree_lookup(&cookie->stores, page->index);
  55726. if (!val) {
  55727. rcu_read_unlock();
  55728. - fscache_stat(&fscache_n_store_vmscan_not_storing);
  55729. + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
  55730. __fscache_uncache_page(cookie, page);
  55731. return true;
  55732. }
  55733. @@ -91,11 +91,11 @@ try_again:
  55734. spin_unlock(&cookie->stores_lock);
  55735. if (xpage) {
  55736. - fscache_stat(&fscache_n_store_vmscan_cancelled);
  55737. - fscache_stat(&fscache_n_store_radix_deletes);
  55738. + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
  55739. + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
  55740. ASSERTCMP(xpage, ==, page);
  55741. } else {
  55742. - fscache_stat(&fscache_n_store_vmscan_gone);
  55743. + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
  55744. }
  55745. wake_up_bit(&cookie->flags, 0);
  55746. @@ -110,11 +110,11 @@ page_busy:
  55747. * sleeping on memory allocation, so we may need to impose a timeout
  55748. * too. */
  55749. if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
  55750. - fscache_stat(&fscache_n_store_vmscan_busy);
  55751. + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
  55752. return false;
  55753. }
  55754. - fscache_stat(&fscache_n_store_vmscan_wait);
  55755. + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
  55756. __fscache_wait_on_page_write(cookie, page);
  55757. gfp &= ~__GFP_WAIT;
  55758. goto try_again;
  55759. @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
  55760. FSCACHE_COOKIE_STORING_TAG);
  55761. if (!radix_tree_tag_get(&cookie->stores, page->index,
  55762. FSCACHE_COOKIE_PENDING_TAG)) {
  55763. - fscache_stat(&fscache_n_store_radix_deletes);
  55764. + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
  55765. xpage = radix_tree_delete(&cookie->stores, page->index);
  55766. }
  55767. spin_unlock(&cookie->stores_lock);
  55768. @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
  55769. _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
  55770. - fscache_stat(&fscache_n_attr_changed_calls);
  55771. + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
  55772. if (fscache_object_is_active(object)) {
  55773. fscache_stat(&fscache_n_cop_attr_changed);
  55774. @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
  55775. ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
  55776. - fscache_stat(&fscache_n_attr_changed);
  55777. + fscache_stat_unchecked(&fscache_n_attr_changed);
  55778. op = kzalloc(sizeof(*op), GFP_KERNEL);
  55779. if (!op) {
  55780. - fscache_stat(&fscache_n_attr_changed_nomem);
  55781. + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
  55782. _leave(" = -ENOMEM");
  55783. return -ENOMEM;
  55784. }
  55785. @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
  55786. if (fscache_submit_exclusive_op(object, op) < 0)
  55787. goto nobufs;
  55788. spin_unlock(&cookie->lock);
  55789. - fscache_stat(&fscache_n_attr_changed_ok);
  55790. + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
  55791. fscache_put_operation(op);
  55792. _leave(" = 0");
  55793. return 0;
  55794. @@ -225,7 +225,7 @@ nobufs:
  55795. kfree(op);
  55796. if (wake_cookie)
  55797. __fscache_wake_unused_cookie(cookie);
  55798. - fscache_stat(&fscache_n_attr_changed_nobufs);
  55799. + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
  55800. _leave(" = %d", -ENOBUFS);
  55801. return -ENOBUFS;
  55802. }
  55803. @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
  55804. /* allocate a retrieval operation and attempt to submit it */
  55805. op = kzalloc(sizeof(*op), GFP_NOIO);
  55806. if (!op) {
  55807. - fscache_stat(&fscache_n_retrievals_nomem);
  55808. + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
  55809. return NULL;
  55810. }
  55811. @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
  55812. return 0;
  55813. }
  55814. - fscache_stat(&fscache_n_retrievals_wait);
  55815. + fscache_stat_unchecked(&fscache_n_retrievals_wait);
  55816. jif = jiffies;
  55817. if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
  55818. fscache_wait_bit_interruptible,
  55819. TASK_INTERRUPTIBLE) != 0) {
  55820. - fscache_stat(&fscache_n_retrievals_intr);
  55821. + fscache_stat_unchecked(&fscache_n_retrievals_intr);
  55822. _leave(" = -ERESTARTSYS");
  55823. return -ERESTARTSYS;
  55824. }
  55825. @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
  55826. */
  55827. int fscache_wait_for_operation_activation(struct fscache_object *object,
  55828. struct fscache_operation *op,
  55829. - atomic_t *stat_op_waits,
  55830. - atomic_t *stat_object_dead,
  55831. + atomic_unchecked_t *stat_op_waits,
  55832. + atomic_unchecked_t *stat_object_dead,
  55833. void (*do_cancel)(struct fscache_operation *))
  55834. {
  55835. int ret;
  55836. @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
  55837. _debug(">>> WT");
  55838. if (stat_op_waits)
  55839. - fscache_stat(stat_op_waits);
  55840. + fscache_stat_unchecked(stat_op_waits);
  55841. if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
  55842. fscache_wait_bit_interruptible,
  55843. TASK_INTERRUPTIBLE) != 0) {
  55844. @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
  55845. check_if_dead:
  55846. if (op->state == FSCACHE_OP_ST_CANCELLED) {
  55847. if (stat_object_dead)
  55848. - fscache_stat(stat_object_dead);
  55849. + fscache_stat_unchecked(stat_object_dead);
  55850. _leave(" = -ENOBUFS [cancelled]");
  55851. return -ENOBUFS;
  55852. }
  55853. @@ -366,7 +366,7 @@ check_if_dead:
  55854. pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
  55855. fscache_cancel_op(op, do_cancel);
  55856. if (stat_object_dead)
  55857. - fscache_stat(stat_object_dead);
  55858. + fscache_stat_unchecked(stat_object_dead);
  55859. return -ENOBUFS;
  55860. }
  55861. return 0;
  55862. @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
  55863. _enter("%p,%p,,,", cookie, page);
  55864. - fscache_stat(&fscache_n_retrievals);
  55865. + fscache_stat_unchecked(&fscache_n_retrievals);
  55866. if (hlist_empty(&cookie->backing_objects))
  55867. goto nobufs;
  55868. @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
  55869. goto nobufs_unlock_dec;
  55870. spin_unlock(&cookie->lock);
  55871. - fscache_stat(&fscache_n_retrieval_ops);
  55872. + fscache_stat_unchecked(&fscache_n_retrieval_ops);
  55873. /* pin the netfs read context in case we need to do the actual netfs
  55874. * read because we've encountered a cache read failure */
  55875. @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
  55876. error:
  55877. if (ret == -ENOMEM)
  55878. - fscache_stat(&fscache_n_retrievals_nomem);
  55879. + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
  55880. else if (ret == -ERESTARTSYS)
  55881. - fscache_stat(&fscache_n_retrievals_intr);
  55882. + fscache_stat_unchecked(&fscache_n_retrievals_intr);
  55883. else if (ret == -ENODATA)
  55884. - fscache_stat(&fscache_n_retrievals_nodata);
  55885. + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
  55886. else if (ret < 0)
  55887. - fscache_stat(&fscache_n_retrievals_nobufs);
  55888. + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
  55889. else
  55890. - fscache_stat(&fscache_n_retrievals_ok);
  55891. + fscache_stat_unchecked(&fscache_n_retrievals_ok);
  55892. fscache_put_retrieval(op);
  55893. _leave(" = %d", ret);
  55894. @@ -490,7 +490,7 @@ nobufs_unlock:
  55895. __fscache_wake_unused_cookie(cookie);
  55896. kfree(op);
  55897. nobufs:
  55898. - fscache_stat(&fscache_n_retrievals_nobufs);
  55899. + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
  55900. _leave(" = -ENOBUFS");
  55901. return -ENOBUFS;
  55902. }
  55903. @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
  55904. _enter("%p,,%d,,,", cookie, *nr_pages);
  55905. - fscache_stat(&fscache_n_retrievals);
  55906. + fscache_stat_unchecked(&fscache_n_retrievals);
  55907. if (hlist_empty(&cookie->backing_objects))
  55908. goto nobufs;
  55909. @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
  55910. goto nobufs_unlock_dec;
  55911. spin_unlock(&cookie->lock);
  55912. - fscache_stat(&fscache_n_retrieval_ops);
  55913. + fscache_stat_unchecked(&fscache_n_retrieval_ops);
  55914. /* pin the netfs read context in case we need to do the actual netfs
  55915. * read because we've encountered a cache read failure */
  55916. @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
  55917. error:
  55918. if (ret == -ENOMEM)
  55919. - fscache_stat(&fscache_n_retrievals_nomem);
  55920. + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
  55921. else if (ret == -ERESTARTSYS)
  55922. - fscache_stat(&fscache_n_retrievals_intr);
  55923. + fscache_stat_unchecked(&fscache_n_retrievals_intr);
  55924. else if (ret == -ENODATA)
  55925. - fscache_stat(&fscache_n_retrievals_nodata);
  55926. + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
  55927. else if (ret < 0)
  55928. - fscache_stat(&fscache_n_retrievals_nobufs);
  55929. + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
  55930. else
  55931. - fscache_stat(&fscache_n_retrievals_ok);
  55932. + fscache_stat_unchecked(&fscache_n_retrievals_ok);
  55933. fscache_put_retrieval(op);
  55934. _leave(" = %d", ret);
  55935. @@ -621,7 +621,7 @@ nobufs_unlock:
  55936. if (wake_cookie)
  55937. __fscache_wake_unused_cookie(cookie);
  55938. nobufs:
  55939. - fscache_stat(&fscache_n_retrievals_nobufs);
  55940. + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
  55941. _leave(" = -ENOBUFS");
  55942. return -ENOBUFS;
  55943. }
  55944. @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
  55945. _enter("%p,%p,,,", cookie, page);
  55946. - fscache_stat(&fscache_n_allocs);
  55947. + fscache_stat_unchecked(&fscache_n_allocs);
  55948. if (hlist_empty(&cookie->backing_objects))
  55949. goto nobufs;
  55950. @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
  55951. goto nobufs_unlock_dec;
  55952. spin_unlock(&cookie->lock);
  55953. - fscache_stat(&fscache_n_alloc_ops);
  55954. + fscache_stat_unchecked(&fscache_n_alloc_ops);
  55955. ret = fscache_wait_for_operation_activation(
  55956. object, &op->op,
  55957. @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
  55958. error:
  55959. if (ret == -ERESTARTSYS)
  55960. - fscache_stat(&fscache_n_allocs_intr);
  55961. + fscache_stat_unchecked(&fscache_n_allocs_intr);
  55962. else if (ret < 0)
  55963. - fscache_stat(&fscache_n_allocs_nobufs);
  55964. + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
  55965. else
  55966. - fscache_stat(&fscache_n_allocs_ok);
  55967. + fscache_stat_unchecked(&fscache_n_allocs_ok);
  55968. fscache_put_retrieval(op);
  55969. _leave(" = %d", ret);
  55970. @@ -715,7 +715,7 @@ nobufs_unlock:
  55971. if (wake_cookie)
  55972. __fscache_wake_unused_cookie(cookie);
  55973. nobufs:
  55974. - fscache_stat(&fscache_n_allocs_nobufs);
  55975. + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
  55976. _leave(" = -ENOBUFS");
  55977. return -ENOBUFS;
  55978. }
  55979. @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
  55980. spin_lock(&cookie->stores_lock);
  55981. - fscache_stat(&fscache_n_store_calls);
  55982. + fscache_stat_unchecked(&fscache_n_store_calls);
  55983. /* find a page to store */
  55984. page = NULL;
  55985. @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
  55986. page = results[0];
  55987. _debug("gang %d [%lx]", n, page->index);
  55988. if (page->index > op->store_limit) {
  55989. - fscache_stat(&fscache_n_store_pages_over_limit);
  55990. + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
  55991. goto superseded;
  55992. }
  55993. @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
  55994. spin_unlock(&cookie->stores_lock);
  55995. spin_unlock(&object->lock);
  55996. - fscache_stat(&fscache_n_store_pages);
  55997. + fscache_stat_unchecked(&fscache_n_store_pages);
  55998. fscache_stat(&fscache_n_cop_write_page);
  55999. ret = object->cache->ops->write_page(op, page);
  56000. fscache_stat_d(&fscache_n_cop_write_page);
  56001. @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
  56002. ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
  56003. ASSERT(PageFsCache(page));
  56004. - fscache_stat(&fscache_n_stores);
  56005. + fscache_stat_unchecked(&fscache_n_stores);
  56006. if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
  56007. _leave(" = -ENOBUFS [invalidating]");
  56008. @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
  56009. spin_unlock(&cookie->stores_lock);
  56010. spin_unlock(&object->lock);
  56011. - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
  56012. + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
  56013. op->store_limit = object->store_limit;
  56014. __fscache_use_cookie(cookie);
  56015. @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
  56016. spin_unlock(&cookie->lock);
  56017. radix_tree_preload_end();
  56018. - fscache_stat(&fscache_n_store_ops);
  56019. - fscache_stat(&fscache_n_stores_ok);
  56020. + fscache_stat_unchecked(&fscache_n_store_ops);
  56021. + fscache_stat_unchecked(&fscache_n_stores_ok);
  56022. /* the work queue now carries its own ref on the object */
  56023. fscache_put_operation(&op->op);
  56024. @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
  56025. return 0;
  56026. already_queued:
  56027. - fscache_stat(&fscache_n_stores_again);
  56028. + fscache_stat_unchecked(&fscache_n_stores_again);
  56029. already_pending:
  56030. spin_unlock(&cookie->stores_lock);
  56031. spin_unlock(&object->lock);
  56032. spin_unlock(&cookie->lock);
  56033. radix_tree_preload_end();
  56034. kfree(op);
  56035. - fscache_stat(&fscache_n_stores_ok);
  56036. + fscache_stat_unchecked(&fscache_n_stores_ok);
  56037. _leave(" = 0");
  56038. return 0;
  56039. @@ -1024,14 +1024,14 @@ nobufs:
  56040. kfree(op);
  56041. if (wake_cookie)
  56042. __fscache_wake_unused_cookie(cookie);
  56043. - fscache_stat(&fscache_n_stores_nobufs);
  56044. + fscache_stat_unchecked(&fscache_n_stores_nobufs);
  56045. _leave(" = -ENOBUFS");
  56046. return -ENOBUFS;
  56047. nomem_free:
  56048. kfree(op);
  56049. nomem:
  56050. - fscache_stat(&fscache_n_stores_oom);
  56051. + fscache_stat_unchecked(&fscache_n_stores_oom);
  56052. _leave(" = -ENOMEM");
  56053. return -ENOMEM;
  56054. }
  56055. @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
  56056. ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
  56057. ASSERTCMP(page, !=, NULL);
  56058. - fscache_stat(&fscache_n_uncaches);
  56059. + fscache_stat_unchecked(&fscache_n_uncaches);
  56060. /* cache withdrawal may beat us to it */
  56061. if (!PageFsCache(page))
  56062. @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
  56063. struct fscache_cookie *cookie = op->op.object->cookie;
  56064. #ifdef CONFIG_FSCACHE_STATS
  56065. - atomic_inc(&fscache_n_marks);
  56066. + atomic_inc_unchecked(&fscache_n_marks);
  56067. #endif
  56068. _debug("- mark %p{%lx}", page, page->index);
  56069. diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
  56070. index 40d13c7..ddf52b9 100644
  56071. --- a/fs/fscache/stats.c
  56072. +++ b/fs/fscache/stats.c
  56073. @@ -18,99 +18,99 @@
  56074. /*
  56075. * operation counters
  56076. */
  56077. -atomic_t fscache_n_op_pend;
  56078. -atomic_t fscache_n_op_run;
  56079. -atomic_t fscache_n_op_enqueue;
  56080. -atomic_t fscache_n_op_requeue;
  56081. -atomic_t fscache_n_op_deferred_release;
  56082. -atomic_t fscache_n_op_release;
  56083. -atomic_t fscache_n_op_gc;
  56084. -atomic_t fscache_n_op_cancelled;
  56085. -atomic_t fscache_n_op_rejected;
  56086. +atomic_unchecked_t fscache_n_op_pend;
  56087. +atomic_unchecked_t fscache_n_op_run;
  56088. +atomic_unchecked_t fscache_n_op_enqueue;
  56089. +atomic_unchecked_t fscache_n_op_requeue;
  56090. +atomic_unchecked_t fscache_n_op_deferred_release;
  56091. +atomic_unchecked_t fscache_n_op_release;
  56092. +atomic_unchecked_t fscache_n_op_gc;
  56093. +atomic_unchecked_t fscache_n_op_cancelled;
  56094. +atomic_unchecked_t fscache_n_op_rejected;
  56095. -atomic_t fscache_n_attr_changed;
  56096. -atomic_t fscache_n_attr_changed_ok;
  56097. -atomic_t fscache_n_attr_changed_nobufs;
  56098. -atomic_t fscache_n_attr_changed_nomem;
  56099. -atomic_t fscache_n_attr_changed_calls;
  56100. +atomic_unchecked_t fscache_n_attr_changed;
  56101. +atomic_unchecked_t fscache_n_attr_changed_ok;
  56102. +atomic_unchecked_t fscache_n_attr_changed_nobufs;
  56103. +atomic_unchecked_t fscache_n_attr_changed_nomem;
  56104. +atomic_unchecked_t fscache_n_attr_changed_calls;
  56105. -atomic_t fscache_n_allocs;
  56106. -atomic_t fscache_n_allocs_ok;
  56107. -atomic_t fscache_n_allocs_wait;
  56108. -atomic_t fscache_n_allocs_nobufs;
  56109. -atomic_t fscache_n_allocs_intr;
  56110. -atomic_t fscache_n_allocs_object_dead;
  56111. -atomic_t fscache_n_alloc_ops;
  56112. -atomic_t fscache_n_alloc_op_waits;
  56113. +atomic_unchecked_t fscache_n_allocs;
  56114. +atomic_unchecked_t fscache_n_allocs_ok;
  56115. +atomic_unchecked_t fscache_n_allocs_wait;
  56116. +atomic_unchecked_t fscache_n_allocs_nobufs;
  56117. +atomic_unchecked_t fscache_n_allocs_intr;
  56118. +atomic_unchecked_t fscache_n_allocs_object_dead;
  56119. +atomic_unchecked_t fscache_n_alloc_ops;
  56120. +atomic_unchecked_t fscache_n_alloc_op_waits;
  56121. -atomic_t fscache_n_retrievals;
  56122. -atomic_t fscache_n_retrievals_ok;
  56123. -atomic_t fscache_n_retrievals_wait;
  56124. -atomic_t fscache_n_retrievals_nodata;
  56125. -atomic_t fscache_n_retrievals_nobufs;
  56126. -atomic_t fscache_n_retrievals_intr;
  56127. -atomic_t fscache_n_retrievals_nomem;
  56128. -atomic_t fscache_n_retrievals_object_dead;
  56129. -atomic_t fscache_n_retrieval_ops;
  56130. -atomic_t fscache_n_retrieval_op_waits;
  56131. +atomic_unchecked_t fscache_n_retrievals;
  56132. +atomic_unchecked_t fscache_n_retrievals_ok;
  56133. +atomic_unchecked_t fscache_n_retrievals_wait;
  56134. +atomic_unchecked_t fscache_n_retrievals_nodata;
  56135. +atomic_unchecked_t fscache_n_retrievals_nobufs;
  56136. +atomic_unchecked_t fscache_n_retrievals_intr;
  56137. +atomic_unchecked_t fscache_n_retrievals_nomem;
  56138. +atomic_unchecked_t fscache_n_retrievals_object_dead;
  56139. +atomic_unchecked_t fscache_n_retrieval_ops;
  56140. +atomic_unchecked_t fscache_n_retrieval_op_waits;
  56141. -atomic_t fscache_n_stores;
  56142. -atomic_t fscache_n_stores_ok;
  56143. -atomic_t fscache_n_stores_again;
  56144. -atomic_t fscache_n_stores_nobufs;
  56145. -atomic_t fscache_n_stores_oom;
  56146. -atomic_t fscache_n_store_ops;
  56147. -atomic_t fscache_n_store_calls;
  56148. -atomic_t fscache_n_store_pages;
  56149. -atomic_t fscache_n_store_radix_deletes;
  56150. -atomic_t fscache_n_store_pages_over_limit;
  56151. +atomic_unchecked_t fscache_n_stores;
  56152. +atomic_unchecked_t fscache_n_stores_ok;
  56153. +atomic_unchecked_t fscache_n_stores_again;
  56154. +atomic_unchecked_t fscache_n_stores_nobufs;
  56155. +atomic_unchecked_t fscache_n_stores_oom;
  56156. +atomic_unchecked_t fscache_n_store_ops;
  56157. +atomic_unchecked_t fscache_n_store_calls;
  56158. +atomic_unchecked_t fscache_n_store_pages;
  56159. +atomic_unchecked_t fscache_n_store_radix_deletes;
  56160. +atomic_unchecked_t fscache_n_store_pages_over_limit;
  56161. -atomic_t fscache_n_store_vmscan_not_storing;
  56162. -atomic_t fscache_n_store_vmscan_gone;
  56163. -atomic_t fscache_n_store_vmscan_busy;
  56164. -atomic_t fscache_n_store_vmscan_cancelled;
  56165. -atomic_t fscache_n_store_vmscan_wait;
  56166. +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
  56167. +atomic_unchecked_t fscache_n_store_vmscan_gone;
  56168. +atomic_unchecked_t fscache_n_store_vmscan_busy;
  56169. +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
  56170. +atomic_unchecked_t fscache_n_store_vmscan_wait;
  56171. -atomic_t fscache_n_marks;
  56172. -atomic_t fscache_n_uncaches;
  56173. +atomic_unchecked_t fscache_n_marks;
  56174. +atomic_unchecked_t fscache_n_uncaches;
  56175. -atomic_t fscache_n_acquires;
  56176. -atomic_t fscache_n_acquires_null;
  56177. -atomic_t fscache_n_acquires_no_cache;
  56178. -atomic_t fscache_n_acquires_ok;
  56179. -atomic_t fscache_n_acquires_nobufs;
  56180. -atomic_t fscache_n_acquires_oom;
  56181. +atomic_unchecked_t fscache_n_acquires;
  56182. +atomic_unchecked_t fscache_n_acquires_null;
  56183. +atomic_unchecked_t fscache_n_acquires_no_cache;
  56184. +atomic_unchecked_t fscache_n_acquires_ok;
  56185. +atomic_unchecked_t fscache_n_acquires_nobufs;
  56186. +atomic_unchecked_t fscache_n_acquires_oom;
  56187. -atomic_t fscache_n_invalidates;
  56188. -atomic_t fscache_n_invalidates_run;
  56189. +atomic_unchecked_t fscache_n_invalidates;
  56190. +atomic_unchecked_t fscache_n_invalidates_run;
  56191. -atomic_t fscache_n_updates;
  56192. -atomic_t fscache_n_updates_null;
  56193. -atomic_t fscache_n_updates_run;
  56194. +atomic_unchecked_t fscache_n_updates;
  56195. +atomic_unchecked_t fscache_n_updates_null;
  56196. +atomic_unchecked_t fscache_n_updates_run;
  56197. -atomic_t fscache_n_relinquishes;
  56198. -atomic_t fscache_n_relinquishes_null;
  56199. -atomic_t fscache_n_relinquishes_waitcrt;
  56200. -atomic_t fscache_n_relinquishes_retire;
  56201. +atomic_unchecked_t fscache_n_relinquishes;
  56202. +atomic_unchecked_t fscache_n_relinquishes_null;
  56203. +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
  56204. +atomic_unchecked_t fscache_n_relinquishes_retire;
  56205. -atomic_t fscache_n_cookie_index;
  56206. -atomic_t fscache_n_cookie_data;
  56207. -atomic_t fscache_n_cookie_special;
  56208. +atomic_unchecked_t fscache_n_cookie_index;
  56209. +atomic_unchecked_t fscache_n_cookie_data;
  56210. +atomic_unchecked_t fscache_n_cookie_special;
  56211. -atomic_t fscache_n_object_alloc;
  56212. -atomic_t fscache_n_object_no_alloc;
  56213. -atomic_t fscache_n_object_lookups;
  56214. -atomic_t fscache_n_object_lookups_negative;
  56215. -atomic_t fscache_n_object_lookups_positive;
  56216. -atomic_t fscache_n_object_lookups_timed_out;
  56217. -atomic_t fscache_n_object_created;
  56218. -atomic_t fscache_n_object_avail;
  56219. -atomic_t fscache_n_object_dead;
  56220. +atomic_unchecked_t fscache_n_object_alloc;
  56221. +atomic_unchecked_t fscache_n_object_no_alloc;
  56222. +atomic_unchecked_t fscache_n_object_lookups;
  56223. +atomic_unchecked_t fscache_n_object_lookups_negative;
  56224. +atomic_unchecked_t fscache_n_object_lookups_positive;
  56225. +atomic_unchecked_t fscache_n_object_lookups_timed_out;
  56226. +atomic_unchecked_t fscache_n_object_created;
  56227. +atomic_unchecked_t fscache_n_object_avail;
  56228. +atomic_unchecked_t fscache_n_object_dead;
  56229. -atomic_t fscache_n_checkaux_none;
  56230. -atomic_t fscache_n_checkaux_okay;
  56231. -atomic_t fscache_n_checkaux_update;
  56232. -atomic_t fscache_n_checkaux_obsolete;
  56233. +atomic_unchecked_t fscache_n_checkaux_none;
  56234. +atomic_unchecked_t fscache_n_checkaux_okay;
  56235. +atomic_unchecked_t fscache_n_checkaux_update;
  56236. +atomic_unchecked_t fscache_n_checkaux_obsolete;
  56237. atomic_t fscache_n_cop_alloc_object;
  56238. atomic_t fscache_n_cop_lookup_object;
  56239. @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
  56240. seq_puts(m, "FS-Cache statistics\n");
  56241. seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
  56242. - atomic_read(&fscache_n_cookie_index),
  56243. - atomic_read(&fscache_n_cookie_data),
  56244. - atomic_read(&fscache_n_cookie_special));
  56245. + atomic_read_unchecked(&fscache_n_cookie_index),
  56246. + atomic_read_unchecked(&fscache_n_cookie_data),
  56247. + atomic_read_unchecked(&fscache_n_cookie_special));
  56248. seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
  56249. - atomic_read(&fscache_n_object_alloc),
  56250. - atomic_read(&fscache_n_object_no_alloc),
  56251. - atomic_read(&fscache_n_object_avail),
  56252. - atomic_read(&fscache_n_object_dead));
  56253. + atomic_read_unchecked(&fscache_n_object_alloc),
  56254. + atomic_read_unchecked(&fscache_n_object_no_alloc),
  56255. + atomic_read_unchecked(&fscache_n_object_avail),
  56256. + atomic_read_unchecked(&fscache_n_object_dead));
  56257. seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
  56258. - atomic_read(&fscache_n_checkaux_none),
  56259. - atomic_read(&fscache_n_checkaux_okay),
  56260. - atomic_read(&fscache_n_checkaux_update),
  56261. - atomic_read(&fscache_n_checkaux_obsolete));
  56262. + atomic_read_unchecked(&fscache_n_checkaux_none),
  56263. + atomic_read_unchecked(&fscache_n_checkaux_okay),
  56264. + atomic_read_unchecked(&fscache_n_checkaux_update),
  56265. + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
  56266. seq_printf(m, "Pages : mrk=%u unc=%u\n",
  56267. - atomic_read(&fscache_n_marks),
  56268. - atomic_read(&fscache_n_uncaches));
  56269. + atomic_read_unchecked(&fscache_n_marks),
  56270. + atomic_read_unchecked(&fscache_n_uncaches));
  56271. seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
  56272. " oom=%u\n",
  56273. - atomic_read(&fscache_n_acquires),
  56274. - atomic_read(&fscache_n_acquires_null),
  56275. - atomic_read(&fscache_n_acquires_no_cache),
  56276. - atomic_read(&fscache_n_acquires_ok),
  56277. - atomic_read(&fscache_n_acquires_nobufs),
  56278. - atomic_read(&fscache_n_acquires_oom));
  56279. + atomic_read_unchecked(&fscache_n_acquires),
  56280. + atomic_read_unchecked(&fscache_n_acquires_null),
  56281. + atomic_read_unchecked(&fscache_n_acquires_no_cache),
  56282. + atomic_read_unchecked(&fscache_n_acquires_ok),
  56283. + atomic_read_unchecked(&fscache_n_acquires_nobufs),
  56284. + atomic_read_unchecked(&fscache_n_acquires_oom));
  56285. seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
  56286. - atomic_read(&fscache_n_object_lookups),
  56287. - atomic_read(&fscache_n_object_lookups_negative),
  56288. - atomic_read(&fscache_n_object_lookups_positive),
  56289. - atomic_read(&fscache_n_object_created),
  56290. - atomic_read(&fscache_n_object_lookups_timed_out));
  56291. + atomic_read_unchecked(&fscache_n_object_lookups),
  56292. + atomic_read_unchecked(&fscache_n_object_lookups_negative),
  56293. + atomic_read_unchecked(&fscache_n_object_lookups_positive),
  56294. + atomic_read_unchecked(&fscache_n_object_created),
  56295. + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
  56296. seq_printf(m, "Invals : n=%u run=%u\n",
  56297. - atomic_read(&fscache_n_invalidates),
  56298. - atomic_read(&fscache_n_invalidates_run));
  56299. + atomic_read_unchecked(&fscache_n_invalidates),
  56300. + atomic_read_unchecked(&fscache_n_invalidates_run));
  56301. seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
  56302. - atomic_read(&fscache_n_updates),
  56303. - atomic_read(&fscache_n_updates_null),
  56304. - atomic_read(&fscache_n_updates_run));
  56305. + atomic_read_unchecked(&fscache_n_updates),
  56306. + atomic_read_unchecked(&fscache_n_updates_null),
  56307. + atomic_read_unchecked(&fscache_n_updates_run));
  56308. seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
  56309. - atomic_read(&fscache_n_relinquishes),
  56310. - atomic_read(&fscache_n_relinquishes_null),
  56311. - atomic_read(&fscache_n_relinquishes_waitcrt),
  56312. - atomic_read(&fscache_n_relinquishes_retire));
  56313. + atomic_read_unchecked(&fscache_n_relinquishes),
  56314. + atomic_read_unchecked(&fscache_n_relinquishes_null),
  56315. + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
  56316. + atomic_read_unchecked(&fscache_n_relinquishes_retire));
  56317. seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
  56318. - atomic_read(&fscache_n_attr_changed),
  56319. - atomic_read(&fscache_n_attr_changed_ok),
  56320. - atomic_read(&fscache_n_attr_changed_nobufs),
  56321. - atomic_read(&fscache_n_attr_changed_nomem),
  56322. - atomic_read(&fscache_n_attr_changed_calls));
  56323. + atomic_read_unchecked(&fscache_n_attr_changed),
  56324. + atomic_read_unchecked(&fscache_n_attr_changed_ok),
  56325. + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
  56326. + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
  56327. + atomic_read_unchecked(&fscache_n_attr_changed_calls));
  56328. seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
  56329. - atomic_read(&fscache_n_allocs),
  56330. - atomic_read(&fscache_n_allocs_ok),
  56331. - atomic_read(&fscache_n_allocs_wait),
  56332. - atomic_read(&fscache_n_allocs_nobufs),
  56333. - atomic_read(&fscache_n_allocs_intr));
  56334. + atomic_read_unchecked(&fscache_n_allocs),
  56335. + atomic_read_unchecked(&fscache_n_allocs_ok),
  56336. + atomic_read_unchecked(&fscache_n_allocs_wait),
  56337. + atomic_read_unchecked(&fscache_n_allocs_nobufs),
  56338. + atomic_read_unchecked(&fscache_n_allocs_intr));
  56339. seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
  56340. - atomic_read(&fscache_n_alloc_ops),
  56341. - atomic_read(&fscache_n_alloc_op_waits),
  56342. - atomic_read(&fscache_n_allocs_object_dead));
  56343. + atomic_read_unchecked(&fscache_n_alloc_ops),
  56344. + atomic_read_unchecked(&fscache_n_alloc_op_waits),
  56345. + atomic_read_unchecked(&fscache_n_allocs_object_dead));
  56346. seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
  56347. " int=%u oom=%u\n",
  56348. - atomic_read(&fscache_n_retrievals),
  56349. - atomic_read(&fscache_n_retrievals_ok),
  56350. - atomic_read(&fscache_n_retrievals_wait),
  56351. - atomic_read(&fscache_n_retrievals_nodata),
  56352. - atomic_read(&fscache_n_retrievals_nobufs),
  56353. - atomic_read(&fscache_n_retrievals_intr),
  56354. - atomic_read(&fscache_n_retrievals_nomem));
  56355. + atomic_read_unchecked(&fscache_n_retrievals),
  56356. + atomic_read_unchecked(&fscache_n_retrievals_ok),
  56357. + atomic_read_unchecked(&fscache_n_retrievals_wait),
  56358. + atomic_read_unchecked(&fscache_n_retrievals_nodata),
  56359. + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
  56360. + atomic_read_unchecked(&fscache_n_retrievals_intr),
  56361. + atomic_read_unchecked(&fscache_n_retrievals_nomem));
  56362. seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
  56363. - atomic_read(&fscache_n_retrieval_ops),
  56364. - atomic_read(&fscache_n_retrieval_op_waits),
  56365. - atomic_read(&fscache_n_retrievals_object_dead));
  56366. + atomic_read_unchecked(&fscache_n_retrieval_ops),
  56367. + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
  56368. + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
  56369. seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
  56370. - atomic_read(&fscache_n_stores),
  56371. - atomic_read(&fscache_n_stores_ok),
  56372. - atomic_read(&fscache_n_stores_again),
  56373. - atomic_read(&fscache_n_stores_nobufs),
  56374. - atomic_read(&fscache_n_stores_oom));
  56375. + atomic_read_unchecked(&fscache_n_stores),
  56376. + atomic_read_unchecked(&fscache_n_stores_ok),
  56377. + atomic_read_unchecked(&fscache_n_stores_again),
  56378. + atomic_read_unchecked(&fscache_n_stores_nobufs),
  56379. + atomic_read_unchecked(&fscache_n_stores_oom));
  56380. seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
  56381. - atomic_read(&fscache_n_store_ops),
  56382. - atomic_read(&fscache_n_store_calls),
  56383. - atomic_read(&fscache_n_store_pages),
  56384. - atomic_read(&fscache_n_store_radix_deletes),
  56385. - atomic_read(&fscache_n_store_pages_over_limit));
  56386. + atomic_read_unchecked(&fscache_n_store_ops),
  56387. + atomic_read_unchecked(&fscache_n_store_calls),
  56388. + atomic_read_unchecked(&fscache_n_store_pages),
  56389. + atomic_read_unchecked(&fscache_n_store_radix_deletes),
  56390. + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
  56391. seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
  56392. - atomic_read(&fscache_n_store_vmscan_not_storing),
  56393. - atomic_read(&fscache_n_store_vmscan_gone),
  56394. - atomic_read(&fscache_n_store_vmscan_busy),
  56395. - atomic_read(&fscache_n_store_vmscan_cancelled),
  56396. - atomic_read(&fscache_n_store_vmscan_wait));
  56397. + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
  56398. + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
  56399. + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
  56400. + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
  56401. + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
  56402. seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
  56403. - atomic_read(&fscache_n_op_pend),
  56404. - atomic_read(&fscache_n_op_run),
  56405. - atomic_read(&fscache_n_op_enqueue),
  56406. - atomic_read(&fscache_n_op_cancelled),
  56407. - atomic_read(&fscache_n_op_rejected));
  56408. + atomic_read_unchecked(&fscache_n_op_pend),
  56409. + atomic_read_unchecked(&fscache_n_op_run),
  56410. + atomic_read_unchecked(&fscache_n_op_enqueue),
  56411. + atomic_read_unchecked(&fscache_n_op_cancelled),
  56412. + atomic_read_unchecked(&fscache_n_op_rejected));
  56413. seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
  56414. - atomic_read(&fscache_n_op_deferred_release),
  56415. - atomic_read(&fscache_n_op_release),
  56416. - atomic_read(&fscache_n_op_gc));
  56417. + atomic_read_unchecked(&fscache_n_op_deferred_release),
  56418. + atomic_read_unchecked(&fscache_n_op_release),
  56419. + atomic_read_unchecked(&fscache_n_op_gc));
  56420. seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
  56421. atomic_read(&fscache_n_cop_alloc_object),
  56422. diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
  56423. index b96a49b..9bfdc47 100644
  56424. --- a/fs/fuse/cuse.c
  56425. +++ b/fs/fuse/cuse.c
  56426. @@ -606,10 +606,12 @@ static int __init cuse_init(void)
  56427. INIT_LIST_HEAD(&cuse_conntbl[i]);
  56428. /* inherit and extend fuse_dev_operations */
  56429. - cuse_channel_fops = fuse_dev_operations;
  56430. - cuse_channel_fops.owner = THIS_MODULE;
  56431. - cuse_channel_fops.open = cuse_channel_open;
  56432. - cuse_channel_fops.release = cuse_channel_release;
  56433. + pax_open_kernel();
  56434. + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
  56435. + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
  56436. + *(void **)&cuse_channel_fops.open = cuse_channel_open;
  56437. + *(void **)&cuse_channel_fops.release = cuse_channel_release;
  56438. + pax_close_kernel();
  56439. cuse_class = class_create(THIS_MODULE, "cuse");
  56440. if (IS_ERR(cuse_class))
  56441. diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
  56442. index 0a648bb..8d463f1 100644
  56443. --- a/fs/fuse/dev.c
  56444. +++ b/fs/fuse/dev.c
  56445. @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
  56446. ret = 0;
  56447. pipe_lock(pipe);
  56448. - if (!pipe->readers) {
  56449. + if (!atomic_read(&pipe->readers)) {
  56450. send_sig(SIGPIPE, current, 0);
  56451. if (!ret)
  56452. ret = -EPIPE;
  56453. @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
  56454. page_nr++;
  56455. ret += buf->len;
  56456. - if (pipe->files)
  56457. + if (atomic_read(&pipe->files))
  56458. do_wakeup = 1;
  56459. }
  56460. diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
  56461. index 1d1292c..bba17ea 100644
  56462. --- a/fs/fuse/dir.c
  56463. +++ b/fs/fuse/dir.c
  56464. @@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
  56465. return link;
  56466. }
  56467. -static void free_link(char *link)
  56468. +static void free_link(const char *link)
  56469. {
  56470. if (!IS_ERR(link))
  56471. free_page((unsigned long) link);
  56472. diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
  56473. index fe649d3..c679164 100644
  56474. --- a/fs/hostfs/hostfs_kern.c
  56475. +++ b/fs/hostfs/hostfs_kern.c
  56476. @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  56477. static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
  56478. {
  56479. - char *s = nd_get_link(nd);
  56480. + const char *s = nd_get_link(nd);
  56481. if (!IS_ERR(s))
  56482. __putname(s);
  56483. }
  56484. diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
  56485. index d19b30a..ef89c36 100644
  56486. --- a/fs/hugetlbfs/inode.c
  56487. +++ b/fs/hugetlbfs/inode.c
  56488. @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  56489. struct mm_struct *mm = current->mm;
  56490. struct vm_area_struct *vma;
  56491. struct hstate *h = hstate_file(file);
  56492. + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
  56493. struct vm_unmapped_area_info info;
  56494. if (len & ~huge_page_mask(h))
  56495. @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  56496. return addr;
  56497. }
  56498. +#ifdef CONFIG_PAX_RANDMMAP
  56499. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  56500. +#endif
  56501. +
  56502. if (addr) {
  56503. addr = ALIGN(addr, huge_page_size(h));
  56504. vma = find_vma(mm, addr);
  56505. - if (TASK_SIZE - len >= addr &&
  56506. - (!vma || addr + len <= vma->vm_start))
  56507. + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
  56508. return addr;
  56509. }
  56510. info.flags = 0;
  56511. info.length = len;
  56512. info.low_limit = TASK_UNMAPPED_BASE;
  56513. +
  56514. +#ifdef CONFIG_PAX_RANDMMAP
  56515. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  56516. + info.low_limit += mm->delta_mmap;
  56517. +#endif
  56518. +
  56519. info.high_limit = TASK_SIZE;
  56520. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  56521. info.align_offset = 0;
  56522. @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
  56523. };
  56524. MODULE_ALIAS_FS("hugetlbfs");
  56525. -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
  56526. +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
  56527. static int can_do_hugetlb_shm(void)
  56528. {
  56529. diff --git a/fs/inode.c b/fs/inode.c
  56530. index 4bcdad3..1883822 100644
  56531. --- a/fs/inode.c
  56532. +++ b/fs/inode.c
  56533. @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
  56534. #ifdef CONFIG_SMP
  56535. if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
  56536. - static atomic_t shared_last_ino;
  56537. - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
  56538. + static atomic_unchecked_t shared_last_ino;
  56539. + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
  56540. res = next - LAST_INO_BATCH;
  56541. }
  56542. diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
  56543. index 4a6cf28..d3a29d3 100644
  56544. --- a/fs/jffs2/erase.c
  56545. +++ b/fs/jffs2/erase.c
  56546. @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
  56547. struct jffs2_unknown_node marker = {
  56548. .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
  56549. .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
  56550. - .totlen = cpu_to_je32(c->cleanmarker_size)
  56551. + .totlen = cpu_to_je32(c->cleanmarker_size),
  56552. + .hdr_crc = cpu_to_je32(0)
  56553. };
  56554. jffs2_prealloc_raw_node_refs(c, jeb, 1);
  56555. diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
  56556. index a6597d6..41b30ec 100644
  56557. --- a/fs/jffs2/wbuf.c
  56558. +++ b/fs/jffs2/wbuf.c
  56559. @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
  56560. {
  56561. .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
  56562. .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
  56563. - .totlen = constant_cpu_to_je32(8)
  56564. + .totlen = constant_cpu_to_je32(8),
  56565. + .hdr_crc = constant_cpu_to_je32(0)
  56566. };
  56567. /*
  56568. diff --git a/fs/jfs/super.c b/fs/jfs/super.c
  56569. index e2b7483..855bca3 100644
  56570. --- a/fs/jfs/super.c
  56571. +++ b/fs/jfs/super.c
  56572. @@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
  56573. jfs_inode_cachep =
  56574. kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
  56575. - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
  56576. + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
  56577. init_once);
  56578. if (jfs_inode_cachep == NULL)
  56579. return -ENOMEM;
  56580. diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
  56581. index 39c0143..d54fad4 100644
  56582. --- a/fs/kernfs/dir.c
  56583. +++ b/fs/kernfs/dir.c
  56584. @@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
  56585. *
  56586. * Returns 31 bit hash of ns + name (so it fits in an off_t )
  56587. */
  56588. -static unsigned int kernfs_name_hash(const char *name, const void *ns)
  56589. +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
  56590. {
  56591. unsigned long hash = init_name_hash();
  56592. unsigned int len = strlen(name);
  56593. diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
  56594. index dbf397b..d624b48 100644
  56595. --- a/fs/kernfs/file.c
  56596. +++ b/fs/kernfs/file.c
  56597. @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
  56598. struct kernfs_open_node {
  56599. atomic_t refcnt;
  56600. - atomic_t event;
  56601. + atomic_unchecked_t event;
  56602. wait_queue_head_t poll;
  56603. struct list_head files; /* goes through kernfs_open_file.list */
  56604. };
  56605. @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
  56606. {
  56607. struct kernfs_open_file *of = sf->private;
  56608. - of->event = atomic_read(&of->kn->attr.open->event);
  56609. + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
  56610. return of->kn->attr.ops->seq_show(sf, v);
  56611. }
  56612. @@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
  56613. return ret;
  56614. }
  56615. -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
  56616. - void *buf, int len, int write)
  56617. +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
  56618. + void *buf, size_t len, int write)
  56619. {
  56620. struct file *file = vma->vm_file;
  56621. struct kernfs_open_file *of = kernfs_of(file);
  56622. - int ret;
  56623. + ssize_t ret;
  56624. if (!of->vm_ops)
  56625. return -EINVAL;
  56626. @@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
  56627. return -ENOMEM;
  56628. atomic_set(&new_on->refcnt, 0);
  56629. - atomic_set(&new_on->event, 1);
  56630. + atomic_set_unchecked(&new_on->event, 1);
  56631. init_waitqueue_head(&new_on->poll);
  56632. INIT_LIST_HEAD(&new_on->files);
  56633. goto retry;
  56634. @@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
  56635. kernfs_put_active(kn);
  56636. - if (of->event != atomic_read(&on->event))
  56637. + if (of->event != atomic_read_unchecked(&on->event))
  56638. goto trigger;
  56639. return DEFAULT_POLLMASK;
  56640. @@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
  56641. if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
  56642. on = kn->attr.open;
  56643. if (on) {
  56644. - atomic_inc(&on->event);
  56645. + atomic_inc_unchecked(&on->event);
  56646. wake_up_interruptible(&on->poll);
  56647. }
  56648. }
  56649. diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
  56650. index 4d45705..b35e0bd 100644
  56651. --- a/fs/kernfs/symlink.c
  56652. +++ b/fs/kernfs/symlink.c
  56653. @@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
  56654. static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
  56655. void *cookie)
  56656. {
  56657. - char *page = nd_get_link(nd);
  56658. + const char *page = nd_get_link(nd);
  56659. if (!IS_ERR(page))
  56660. free_page((unsigned long)page);
  56661. }
  56662. diff --git a/fs/libfs.c b/fs/libfs.c
  56663. index a184424..944ddce 100644
  56664. --- a/fs/libfs.c
  56665. +++ b/fs/libfs.c
  56666. @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
  56667. for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
  56668. struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
  56669. + char d_name[sizeof(next->d_iname)];
  56670. + const unsigned char *name;
  56671. +
  56672. spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
  56673. if (!simple_positive(next)) {
  56674. spin_unlock(&next->d_lock);
  56675. @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
  56676. spin_unlock(&next->d_lock);
  56677. spin_unlock(&dentry->d_lock);
  56678. - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
  56679. + name = next->d_name.name;
  56680. + if (name == next->d_iname) {
  56681. + memcpy(d_name, name, next->d_name.len);
  56682. + name = d_name;
  56683. + }
  56684. + if (!dir_emit(ctx, name, next->d_name.len,
  56685. next->d_inode->i_ino, dt_type(next->d_inode)))
  56686. return 0;
  56687. spin_lock(&dentry->d_lock);
  56688. @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
  56689. void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
  56690. void *cookie)
  56691. {
  56692. - char *s = nd_get_link(nd);
  56693. + const char *s = nd_get_link(nd);
  56694. if (!IS_ERR(s))
  56695. kfree(s);
  56696. }
  56697. diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
  56698. index acd3947..1f896e2 100644
  56699. --- a/fs/lockd/clntproc.c
  56700. +++ b/fs/lockd/clntproc.c
  56701. @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
  56702. /*
  56703. * Cookie counter for NLM requests
  56704. */
  56705. -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
  56706. +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
  56707. void nlmclnt_next_cookie(struct nlm_cookie *c)
  56708. {
  56709. - u32 cookie = atomic_inc_return(&nlm_cookie);
  56710. + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
  56711. memcpy(c->data, &cookie, 4);
  56712. c->len=4;
  56713. diff --git a/fs/locks.c b/fs/locks.c
  56714. index 4dd39b9..12d6aaf 100644
  56715. --- a/fs/locks.c
  56716. +++ b/fs/locks.c
  56717. @@ -2218,16 +2218,16 @@ void locks_remove_flock(struct file *filp)
  56718. return;
  56719. if (filp->f_op->flock) {
  56720. - struct file_lock fl = {
  56721. + struct file_lock flock = {
  56722. .fl_pid = current->tgid,
  56723. .fl_file = filp,
  56724. .fl_flags = FL_FLOCK,
  56725. .fl_type = F_UNLCK,
  56726. .fl_end = OFFSET_MAX,
  56727. };
  56728. - filp->f_op->flock(filp, F_SETLKW, &fl);
  56729. - if (fl.fl_ops && fl.fl_ops->fl_release_private)
  56730. - fl.fl_ops->fl_release_private(&fl);
  56731. + filp->f_op->flock(filp, F_SETLKW, &flock);
  56732. + if (flock.fl_ops && flock.fl_ops->fl_release_private)
  56733. + flock.fl_ops->fl_release_private(&flock);
  56734. }
  56735. spin_lock(&inode->i_lock);
  56736. diff --git a/fs/mount.h b/fs/mount.h
  56737. index b29e42f..5ea7fdf 100644
  56738. --- a/fs/mount.h
  56739. +++ b/fs/mount.h
  56740. @@ -11,7 +11,7 @@ struct mnt_namespace {
  56741. u64 seq; /* Sequence number to prevent loops */
  56742. wait_queue_head_t poll;
  56743. int event;
  56744. -};
  56745. +} __randomize_layout;
  56746. struct mnt_pcp {
  56747. int mnt_count;
  56748. @@ -57,7 +57,7 @@ struct mount {
  56749. int mnt_expiry_mark; /* true if marked for expiry */
  56750. int mnt_pinned;
  56751. struct path mnt_ex_mountpoint;
  56752. -};
  56753. +} __randomize_layout;
  56754. #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
  56755. diff --git a/fs/namei.c b/fs/namei.c
  56756. index 4b491b4..a0166f9 100644
  56757. --- a/fs/namei.c
  56758. +++ b/fs/namei.c
  56759. @@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
  56760. if (ret != -EACCES)
  56761. return ret;
  56762. +#ifdef CONFIG_GRKERNSEC
  56763. + /* we'll block if we have to log due to a denied capability use */
  56764. + if (mask & MAY_NOT_BLOCK)
  56765. + return -ECHILD;
  56766. +#endif
  56767. +
  56768. if (S_ISDIR(inode->i_mode)) {
  56769. /* DACs are overridable for directories */
  56770. - if (inode_capable(inode, CAP_DAC_OVERRIDE))
  56771. - return 0;
  56772. if (!(mask & MAY_WRITE))
  56773. - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
  56774. + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
  56775. + inode_capable(inode, CAP_DAC_READ_SEARCH))
  56776. return 0;
  56777. + if (inode_capable(inode, CAP_DAC_OVERRIDE))
  56778. + return 0;
  56779. return -EACCES;
  56780. }
  56781. /*
  56782. + * Searching includes executable on directories, else just read.
  56783. + */
  56784. + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
  56785. + if (mask == MAY_READ)
  56786. + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
  56787. + inode_capable(inode, CAP_DAC_READ_SEARCH))
  56788. + return 0;
  56789. +
  56790. + /*
  56791. * Read/write DACs are always overridable.
  56792. * Executable DACs are overridable when there is
  56793. * at least one exec bit set.
  56794. @@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
  56795. if (inode_capable(inode, CAP_DAC_OVERRIDE))
  56796. return 0;
  56797. - /*
  56798. - * Searching includes executable on directories, else just read.
  56799. - */
  56800. - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
  56801. - if (mask == MAY_READ)
  56802. - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
  56803. - return 0;
  56804. -
  56805. return -EACCES;
  56806. }
  56807. @@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
  56808. {
  56809. struct dentry *dentry = link->dentry;
  56810. int error;
  56811. - char *s;
  56812. + const char *s;
  56813. BUG_ON(nd->flags & LOOKUP_RCU);
  56814. @@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
  56815. if (error)
  56816. goto out_put_nd_path;
  56817. + if (gr_handle_follow_link(dentry->d_parent->d_inode,
  56818. + dentry->d_inode, dentry, nd->path.mnt)) {
  56819. + error = -EACCES;
  56820. + goto out_put_nd_path;
  56821. + }
  56822. +
  56823. nd->last_type = LAST_BIND;
  56824. *p = dentry->d_inode->i_op->follow_link(dentry, nd);
  56825. error = PTR_ERR(*p);
  56826. @@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
  56827. if (res)
  56828. break;
  56829. res = walk_component(nd, path, LOOKUP_FOLLOW);
  56830. + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
  56831. + res = -EACCES;
  56832. put_link(nd, &link, cookie);
  56833. } while (res > 0);
  56834. @@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
  56835. static inline unsigned long hash_name(const char *name, unsigned int *hashp)
  56836. {
  56837. unsigned long a, b, adata, bdata, mask, hash, len;
  56838. - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  56839. + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  56840. hash = a = 0;
  56841. len = -sizeof(unsigned long);
  56842. @@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
  56843. if (err)
  56844. break;
  56845. err = lookup_last(nd, &path);
  56846. + if (!err && gr_handle_symlink_owner(&link, nd->inode))
  56847. + err = -EACCES;
  56848. put_link(nd, &link, cookie);
  56849. }
  56850. }
  56851. @@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
  56852. if (!err)
  56853. err = complete_walk(nd);
  56854. + if (!err && !(nd->flags & LOOKUP_PARENT)) {
  56855. + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
  56856. + path_put(&nd->path);
  56857. + err = -ENOENT;
  56858. + }
  56859. + }
  56860. +
  56861. if (!err && nd->flags & LOOKUP_DIRECTORY) {
  56862. if (!d_is_directory(nd->path.dentry)) {
  56863. path_put(&nd->path);
  56864. @@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
  56865. retval = path_lookupat(dfd, name->name,
  56866. flags | LOOKUP_REVAL, nd);
  56867. - if (likely(!retval))
  56868. + if (likely(!retval)) {
  56869. audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
  56870. + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
  56871. + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
  56872. + path_put(&nd->path);
  56873. + return -ENOENT;
  56874. + }
  56875. + }
  56876. + }
  56877. return retval;
  56878. }
  56879. @@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
  56880. if (flag & O_NOATIME && !inode_owner_or_capable(inode))
  56881. return -EPERM;
  56882. + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
  56883. + return -EPERM;
  56884. + if (gr_handle_rawio(inode))
  56885. + return -EPERM;
  56886. + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
  56887. + return -EACCES;
  56888. +
  56889. return 0;
  56890. }
  56891. @@ -2787,7 +2826,7 @@ looked_up:
  56892. * cleared otherwise prior to returning.
  56893. */
  56894. static int lookup_open(struct nameidata *nd, struct path *path,
  56895. - struct file *file,
  56896. + struct path *link, struct file *file,
  56897. const struct open_flags *op,
  56898. bool got_write, int *opened)
  56899. {
  56900. @@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
  56901. /* Negative dentry, just create the file */
  56902. if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
  56903. umode_t mode = op->mode;
  56904. +
  56905. + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
  56906. + error = -EACCES;
  56907. + goto out_dput;
  56908. + }
  56909. +
  56910. + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
  56911. + error = -EACCES;
  56912. + goto out_dput;
  56913. + }
  56914. +
  56915. if (!IS_POSIXACL(dir->d_inode))
  56916. mode &= ~current_umask();
  56917. /*
  56918. @@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
  56919. nd->flags & LOOKUP_EXCL);
  56920. if (error)
  56921. goto out_dput;
  56922. + else
  56923. + gr_handle_create(dentry, nd->path.mnt);
  56924. }
  56925. out_no_open:
  56926. path->dentry = dentry;
  56927. @@ -2857,7 +2909,7 @@ out_dput:
  56928. /*
  56929. * Handle the last step of open()
  56930. */
  56931. -static int do_last(struct nameidata *nd, struct path *path,
  56932. +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
  56933. struct file *file, const struct open_flags *op,
  56934. int *opened, struct filename *name)
  56935. {
  56936. @@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
  56937. if (error)
  56938. return error;
  56939. + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
  56940. + error = -ENOENT;
  56941. + goto out;
  56942. + }
  56943. + if (link && gr_handle_symlink_owner(link, nd->inode)) {
  56944. + error = -EACCES;
  56945. + goto out;
  56946. + }
  56947. +
  56948. audit_inode(name, dir, LOOKUP_PARENT);
  56949. error = -EISDIR;
  56950. /* trailing slashes? */
  56951. @@ -2926,7 +2987,7 @@ retry_lookup:
  56952. */
  56953. }
  56954. mutex_lock(&dir->d_inode->i_mutex);
  56955. - error = lookup_open(nd, path, file, op, got_write, opened);
  56956. + error = lookup_open(nd, path, link, file, op, got_write, opened);
  56957. mutex_unlock(&dir->d_inode->i_mutex);
  56958. if (error <= 0) {
  56959. @@ -2950,11 +3011,28 @@ retry_lookup:
  56960. goto finish_open_created;
  56961. }
  56962. + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
  56963. + error = -ENOENT;
  56964. + goto exit_dput;
  56965. + }
  56966. + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
  56967. + error = -EACCES;
  56968. + goto exit_dput;
  56969. + }
  56970. +
  56971. /*
  56972. * create/update audit record if it already exists.
  56973. */
  56974. - if (d_is_positive(path->dentry))
  56975. + if (d_is_positive(path->dentry)) {
  56976. + /* only check if O_CREAT is specified, all other checks need to go
  56977. + into may_open */
  56978. + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
  56979. + error = -EACCES;
  56980. + goto exit_dput;
  56981. + }
  56982. +
  56983. audit_inode(name, path->dentry, 0);
  56984. + }
  56985. /*
  56986. * If atomic_open() acquired write access it is dropped now due to
  56987. @@ -2995,6 +3073,11 @@ finish_lookup:
  56988. }
  56989. }
  56990. BUG_ON(inode != path->dentry->d_inode);
  56991. + /* if we're resolving a symlink to another symlink */
  56992. + if (link && gr_handle_symlink_owner(link, inode)) {
  56993. + error = -EACCES;
  56994. + goto out;
  56995. + }
  56996. return 1;
  56997. }
  56998. @@ -3004,7 +3087,6 @@ finish_lookup:
  56999. save_parent.dentry = nd->path.dentry;
  57000. save_parent.mnt = mntget(path->mnt);
  57001. nd->path.dentry = path->dentry;
  57002. -
  57003. }
  57004. nd->inode = inode;
  57005. /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
  57006. @@ -3014,7 +3096,18 @@ finish_open:
  57007. path_put(&save_parent);
  57008. return error;
  57009. }
  57010. +
  57011. + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
  57012. + error = -ENOENT;
  57013. + goto out;
  57014. + }
  57015. + if (link && gr_handle_symlink_owner(link, nd->inode)) {
  57016. + error = -EACCES;
  57017. + goto out;
  57018. + }
  57019. +
  57020. audit_inode(name, nd->path.dentry, 0);
  57021. +
  57022. error = -EISDIR;
  57023. if ((open_flag & O_CREAT) &&
  57024. (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
  57025. @@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
  57026. if (unlikely(error))
  57027. goto out;
  57028. - error = do_last(nd, &path, file, op, &opened, pathname);
  57029. + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
  57030. while (unlikely(error > 0)) { /* trailing symlink */
  57031. struct path link = path;
  57032. void *cookie;
  57033. @@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
  57034. error = follow_link(&link, nd, &cookie);
  57035. if (unlikely(error))
  57036. break;
  57037. - error = do_last(nd, &path, file, op, &opened, pathname);
  57038. + error = do_last(nd, &path, &link, file, op, &opened, pathname);
  57039. put_link(nd, &link, cookie);
  57040. }
  57041. out:
  57042. @@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
  57043. goto unlock;
  57044. error = -EEXIST;
  57045. - if (d_is_positive(dentry))
  57046. + if (d_is_positive(dentry)) {
  57047. + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
  57048. + error = -ENOENT;
  57049. goto fail;
  57050. -
  57051. + }
  57052. /*
  57053. * Special case - lookup gave negative, but... we had foo/bar/
  57054. * From the vfs_mknod() POV we just have a negative dentry -
  57055. @@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
  57056. }
  57057. EXPORT_SYMBOL(user_path_create);
  57058. +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
  57059. +{
  57060. + struct filename *tmp = getname(pathname);
  57061. + struct dentry *res;
  57062. + if (IS_ERR(tmp))
  57063. + return ERR_CAST(tmp);
  57064. + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
  57065. + if (IS_ERR(res))
  57066. + putname(tmp);
  57067. + else
  57068. + *to = tmp;
  57069. + return res;
  57070. +}
  57071. +
  57072. int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
  57073. {
  57074. int error = may_create(dir, dentry);
  57075. @@ -3412,6 +3521,17 @@ retry:
  57076. if (!IS_POSIXACL(path.dentry->d_inode))
  57077. mode &= ~current_umask();
  57078. +
  57079. + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
  57080. + error = -EPERM;
  57081. + goto out;
  57082. + }
  57083. +
  57084. + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
  57085. + error = -EACCES;
  57086. + goto out;
  57087. + }
  57088. +
  57089. error = security_path_mknod(&path, dentry, mode, dev);
  57090. if (error)
  57091. goto out;
  57092. @@ -3428,6 +3548,8 @@ retry:
  57093. break;
  57094. }
  57095. out:
  57096. + if (!error)
  57097. + gr_handle_create(dentry, path.mnt);
  57098. done_path_create(&path, dentry);
  57099. if (retry_estale(error, lookup_flags)) {
  57100. lookup_flags |= LOOKUP_REVAL;
  57101. @@ -3480,9 +3602,16 @@ retry:
  57102. if (!IS_POSIXACL(path.dentry->d_inode))
  57103. mode &= ~current_umask();
  57104. + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
  57105. + error = -EACCES;
  57106. + goto out;
  57107. + }
  57108. error = security_path_mkdir(&path, dentry, mode);
  57109. if (!error)
  57110. error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
  57111. + if (!error)
  57112. + gr_handle_create(dentry, path.mnt);
  57113. +out:
  57114. done_path_create(&path, dentry);
  57115. if (retry_estale(error, lookup_flags)) {
  57116. lookup_flags |= LOOKUP_REVAL;
  57117. @@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
  57118. struct filename *name;
  57119. struct dentry *dentry;
  57120. struct nameidata nd;
  57121. + ino_t saved_ino = 0;
  57122. + dev_t saved_dev = 0;
  57123. unsigned int lookup_flags = 0;
  57124. retry:
  57125. name = user_path_parent(dfd, pathname, &nd, lookup_flags);
  57126. @@ -3595,10 +3726,21 @@ retry:
  57127. error = -ENOENT;
  57128. goto exit3;
  57129. }
  57130. +
  57131. + saved_ino = dentry->d_inode->i_ino;
  57132. + saved_dev = gr_get_dev_from_dentry(dentry);
  57133. +
  57134. + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
  57135. + error = -EACCES;
  57136. + goto exit3;
  57137. + }
  57138. +
  57139. error = security_path_rmdir(&nd.path, dentry);
  57140. if (error)
  57141. goto exit3;
  57142. error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
  57143. + if (!error && (saved_dev || saved_ino))
  57144. + gr_handle_delete(saved_ino, saved_dev);
  57145. exit3:
  57146. dput(dentry);
  57147. exit2:
  57148. @@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
  57149. struct nameidata nd;
  57150. struct inode *inode = NULL;
  57151. struct inode *delegated_inode = NULL;
  57152. + ino_t saved_ino = 0;
  57153. + dev_t saved_dev = 0;
  57154. unsigned int lookup_flags = 0;
  57155. retry:
  57156. name = user_path_parent(dfd, pathname, &nd, lookup_flags);
  57157. @@ -3714,10 +3858,22 @@ retry_deleg:
  57158. if (d_is_negative(dentry))
  57159. goto slashes;
  57160. ihold(inode);
  57161. +
  57162. + if (inode->i_nlink <= 1) {
  57163. + saved_ino = inode->i_ino;
  57164. + saved_dev = gr_get_dev_from_dentry(dentry);
  57165. + }
  57166. + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
  57167. + error = -EACCES;
  57168. + goto exit2;
  57169. + }
  57170. +
  57171. error = security_path_unlink(&nd.path, dentry);
  57172. if (error)
  57173. goto exit2;
  57174. error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
  57175. + if (!error && (saved_ino || saved_dev))
  57176. + gr_handle_delete(saved_ino, saved_dev);
  57177. exit2:
  57178. dput(dentry);
  57179. }
  57180. @@ -3805,9 +3961,17 @@ retry:
  57181. if (IS_ERR(dentry))
  57182. goto out_putname;
  57183. + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
  57184. + error = -EACCES;
  57185. + goto out;
  57186. + }
  57187. +
  57188. error = security_path_symlink(&path, dentry, from->name);
  57189. if (!error)
  57190. error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
  57191. + if (!error)
  57192. + gr_handle_create(dentry, path.mnt);
  57193. +out:
  57194. done_path_create(&path, dentry);
  57195. if (retry_estale(error, lookup_flags)) {
  57196. lookup_flags |= LOOKUP_REVAL;
  57197. @@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
  57198. struct dentry *new_dentry;
  57199. struct path old_path, new_path;
  57200. struct inode *delegated_inode = NULL;
  57201. + struct filename *to = NULL;
  57202. int how = 0;
  57203. int error;
  57204. @@ -3933,7 +4098,7 @@ retry:
  57205. if (error)
  57206. return error;
  57207. - new_dentry = user_path_create(newdfd, newname, &new_path,
  57208. + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
  57209. (how & LOOKUP_REVAL));
  57210. error = PTR_ERR(new_dentry);
  57211. if (IS_ERR(new_dentry))
  57212. @@ -3945,11 +4110,28 @@ retry:
  57213. error = may_linkat(&old_path);
  57214. if (unlikely(error))
  57215. goto out_dput;
  57216. +
  57217. + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
  57218. + old_path.dentry->d_inode,
  57219. + old_path.dentry->d_inode->i_mode, to)) {
  57220. + error = -EACCES;
  57221. + goto out_dput;
  57222. + }
  57223. +
  57224. + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
  57225. + old_path.dentry, old_path.mnt, to)) {
  57226. + error = -EACCES;
  57227. + goto out_dput;
  57228. + }
  57229. +
  57230. error = security_path_link(old_path.dentry, &new_path, new_dentry);
  57231. if (error)
  57232. goto out_dput;
  57233. error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
  57234. + if (!error)
  57235. + gr_handle_create(new_dentry, new_path.mnt);
  57236. out_dput:
  57237. + putname(to);
  57238. done_path_create(&new_path, new_dentry);
  57239. if (delegated_inode) {
  57240. error = break_deleg_wait(&delegated_inode);
  57241. @@ -4236,6 +4418,12 @@ retry_deleg:
  57242. if (new_dentry == trap)
  57243. goto exit5;
  57244. + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
  57245. + old_dentry, old_dir->d_inode, oldnd.path.mnt,
  57246. + to);
  57247. + if (error)
  57248. + goto exit5;
  57249. +
  57250. error = security_path_rename(&oldnd.path, old_dentry,
  57251. &newnd.path, new_dentry);
  57252. if (error)
  57253. @@ -4243,6 +4431,9 @@ retry_deleg:
  57254. error = vfs_rename(old_dir->d_inode, old_dentry,
  57255. new_dir->d_inode, new_dentry,
  57256. &delegated_inode);
  57257. + if (!error)
  57258. + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
  57259. + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
  57260. exit5:
  57261. dput(new_dentry);
  57262. exit4:
  57263. @@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
  57264. int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
  57265. {
  57266. + char tmpbuf[64];
  57267. + const char *newlink;
  57268. int len;
  57269. len = PTR_ERR(link);
  57270. @@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
  57271. len = strlen(link);
  57272. if (len > (unsigned) buflen)
  57273. len = buflen;
  57274. - if (copy_to_user(buffer, link, len))
  57275. +
  57276. + if (len < sizeof(tmpbuf)) {
  57277. + memcpy(tmpbuf, link, len);
  57278. + newlink = tmpbuf;
  57279. + } else
  57280. + newlink = link;
  57281. +
  57282. + if (copy_to_user(buffer, newlink, len))
  57283. len = -EFAULT;
  57284. out:
  57285. return len;
  57286. diff --git a/fs/namespace.c b/fs/namespace.c
  57287. index 65233a5..82ac953 100644
  57288. --- a/fs/namespace.c
  57289. +++ b/fs/namespace.c
  57290. @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
  57291. if (!(sb->s_flags & MS_RDONLY))
  57292. retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
  57293. up_write(&sb->s_umount);
  57294. +
  57295. + gr_log_remount(mnt->mnt_devname, retval);
  57296. +
  57297. return retval;
  57298. }
  57299. @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
  57300. }
  57301. unlock_mount_hash();
  57302. namespace_unlock();
  57303. +
  57304. + gr_log_unmount(mnt->mnt_devname, retval);
  57305. +
  57306. return retval;
  57307. }
  57308. @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
  57309. * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
  57310. */
  57311. -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
  57312. +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
  57313. {
  57314. struct path path;
  57315. struct mount *mnt;
  57316. @@ -1422,7 +1428,7 @@ out:
  57317. /*
  57318. * The 2.0 compatible umount. No flags.
  57319. */
  57320. -SYSCALL_DEFINE1(oldumount, char __user *, name)
  57321. +SYSCALL_DEFINE1(oldumount, const char __user *, name)
  57322. {
  57323. return sys_umount(name, 0);
  57324. }
  57325. @@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
  57326. MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
  57327. MS_STRICTATIME);
  57328. + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
  57329. + retval = -EPERM;
  57330. + goto dput_out;
  57331. + }
  57332. +
  57333. + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
  57334. + retval = -EPERM;
  57335. + goto dput_out;
  57336. + }
  57337. +
  57338. if (flags & MS_REMOUNT)
  57339. retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
  57340. data_page);
  57341. @@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
  57342. dev_name, data_page);
  57343. dput_out:
  57344. path_put(&path);
  57345. +
  57346. + gr_log_mount(dev_name, dir_name, retval);
  57347. +
  57348. return retval;
  57349. }
  57350. @@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
  57351. * number incrementing at 10Ghz will take 12,427 years to wrap which
  57352. * is effectively never, so we can ignore the possibility.
  57353. */
  57354. -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
  57355. +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
  57356. static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
  57357. {
  57358. @@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
  57359. kfree(new_ns);
  57360. return ERR_PTR(ret);
  57361. }
  57362. - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
  57363. + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
  57364. atomic_set(&new_ns->count, 1);
  57365. new_ns->root = NULL;
  57366. INIT_LIST_HEAD(&new_ns->list);
  57367. @@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
  57368. return new_ns;
  57369. }
  57370. -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
  57371. +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
  57372. struct user_namespace *user_ns, struct fs_struct *new_fs)
  57373. {
  57374. struct mnt_namespace *new_ns;
  57375. @@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
  57376. }
  57377. EXPORT_SYMBOL(mount_subtree);
  57378. -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
  57379. - char __user *, type, unsigned long, flags, void __user *, data)
  57380. +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
  57381. + const char __user *, type, unsigned long, flags, void __user *, data)
  57382. {
  57383. int ret;
  57384. char *kernel_type;
  57385. @@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
  57386. if (error)
  57387. goto out2;
  57388. + if (gr_handle_chroot_pivot()) {
  57389. + error = -EPERM;
  57390. + goto out2;
  57391. + }
  57392. +
  57393. get_fs_root(current->fs, &root);
  57394. old_mp = lock_mount(&old);
  57395. error = PTR_ERR(old_mp);
  57396. @@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
  57397. !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
  57398. return -EPERM;
  57399. - if (fs->users != 1)
  57400. + if (atomic_read(&fs->users) != 1)
  57401. return -EINVAL;
  57402. get_mnt_ns(mnt_ns);
  57403. diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
  57404. index f4ccfe6..a5cf064 100644
  57405. --- a/fs/nfs/callback_xdr.c
  57406. +++ b/fs/nfs/callback_xdr.c
  57407. @@ -51,7 +51,7 @@ struct callback_op {
  57408. callback_decode_arg_t decode_args;
  57409. callback_encode_res_t encode_res;
  57410. long res_maxsize;
  57411. -};
  57412. +} __do_const;
  57413. static struct callback_op callback_ops[];
  57414. diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
  57415. index 360114a..ac6e265 100644
  57416. --- a/fs/nfs/inode.c
  57417. +++ b/fs/nfs/inode.c
  57418. @@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
  57419. return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
  57420. }
  57421. -static atomic_long_t nfs_attr_generation_counter;
  57422. +static atomic_long_unchecked_t nfs_attr_generation_counter;
  57423. static unsigned long nfs_read_attr_generation_counter(void)
  57424. {
  57425. - return atomic_long_read(&nfs_attr_generation_counter);
  57426. + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
  57427. }
  57428. unsigned long nfs_inc_attr_generation_counter(void)
  57429. {
  57430. - return atomic_long_inc_return(&nfs_attr_generation_counter);
  57431. + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
  57432. }
  57433. void nfs_fattr_init(struct nfs_fattr *fattr)
  57434. diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
  57435. index 9a914e8..e89c0ea 100644
  57436. --- a/fs/nfsd/nfs4proc.c
  57437. +++ b/fs/nfsd/nfs4proc.c
  57438. @@ -1178,7 +1178,7 @@ struct nfsd4_operation {
  57439. nfsd4op_rsize op_rsize_bop;
  57440. stateid_getter op_get_currentstateid;
  57441. stateid_setter op_set_currentstateid;
  57442. -};
  57443. +} __do_const;
  57444. static struct nfsd4_operation nfsd4_ops[];
  57445. diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
  57446. index 16e8fa7..b0803f6 100644
  57447. --- a/fs/nfsd/nfs4xdr.c
  57448. +++ b/fs/nfsd/nfs4xdr.c
  57449. @@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
  57450. typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
  57451. -static nfsd4_dec nfsd4_dec_ops[] = {
  57452. +static const nfsd4_dec nfsd4_dec_ops[] = {
  57453. [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
  57454. [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
  57455. [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
  57456. diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
  57457. index f8f060f..c4ba09a 100644
  57458. --- a/fs/nfsd/nfscache.c
  57459. +++ b/fs/nfsd/nfscache.c
  57460. @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
  57461. {
  57462. struct svc_cacherep *rp = rqstp->rq_cacherep;
  57463. struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
  57464. - int len;
  57465. + long len;
  57466. size_t bufsize = 0;
  57467. if (!rp)
  57468. return;
  57469. - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
  57470. - len >>= 2;
  57471. + if (statp) {
  57472. + len = (char*)statp - (char*)resv->iov_base;
  57473. + len = resv->iov_len - len;
  57474. + len >>= 2;
  57475. + }
  57476. /* Don't cache excessive amounts of data and XDR failures */
  57477. if (!statp || len > (256 >> 2)) {
  57478. diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
  57479. index eea5ad1..5a84ac7 100644
  57480. --- a/fs/nfsd/vfs.c
  57481. +++ b/fs/nfsd/vfs.c
  57482. @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
  57483. } else {
  57484. oldfs = get_fs();
  57485. set_fs(KERNEL_DS);
  57486. - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
  57487. + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
  57488. set_fs(oldfs);
  57489. }
  57490. @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
  57491. /* Write the data. */
  57492. oldfs = get_fs(); set_fs(KERNEL_DS);
  57493. - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
  57494. + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
  57495. set_fs(oldfs);
  57496. if (host_err < 0)
  57497. goto out_nfserr;
  57498. @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
  57499. */
  57500. oldfs = get_fs(); set_fs(KERNEL_DS);
  57501. - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
  57502. + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
  57503. set_fs(oldfs);
  57504. if (host_err < 0)
  57505. diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
  57506. index 52ccd34..43a53b1 100644
  57507. --- a/fs/nls/nls_base.c
  57508. +++ b/fs/nls/nls_base.c
  57509. @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
  57510. int __register_nls(struct nls_table *nls, struct module *owner)
  57511. {
  57512. - struct nls_table ** tmp = &tables;
  57513. + struct nls_table *tmp = tables;
  57514. if (nls->next)
  57515. return -EBUSY;
  57516. - nls->owner = owner;
  57517. + pax_open_kernel();
  57518. + *(void **)&nls->owner = owner;
  57519. + pax_close_kernel();
  57520. spin_lock(&nls_lock);
  57521. - while (*tmp) {
  57522. - if (nls == *tmp) {
  57523. + while (tmp) {
  57524. + if (nls == tmp) {
  57525. spin_unlock(&nls_lock);
  57526. return -EBUSY;
  57527. }
  57528. - tmp = &(*tmp)->next;
  57529. + tmp = tmp->next;
  57530. }
  57531. - nls->next = tables;
  57532. + pax_open_kernel();
  57533. + *(struct nls_table **)&nls->next = tables;
  57534. + pax_close_kernel();
  57535. tables = nls;
  57536. spin_unlock(&nls_lock);
  57537. return 0;
  57538. @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
  57539. int unregister_nls(struct nls_table * nls)
  57540. {
  57541. - struct nls_table ** tmp = &tables;
  57542. + struct nls_table * const * tmp = &tables;
  57543. spin_lock(&nls_lock);
  57544. while (*tmp) {
  57545. if (nls == *tmp) {
  57546. - *tmp = nls->next;
  57547. + pax_open_kernel();
  57548. + *(struct nls_table **)tmp = nls->next;
  57549. + pax_close_kernel();
  57550. spin_unlock(&nls_lock);
  57551. return 0;
  57552. }
  57553. diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
  57554. index 162b3f1..6076a7c 100644
  57555. --- a/fs/nls/nls_euc-jp.c
  57556. +++ b/fs/nls/nls_euc-jp.c
  57557. @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
  57558. p_nls = load_nls("cp932");
  57559. if (p_nls) {
  57560. - table.charset2upper = p_nls->charset2upper;
  57561. - table.charset2lower = p_nls->charset2lower;
  57562. + pax_open_kernel();
  57563. + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
  57564. + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
  57565. + pax_close_kernel();
  57566. return register_nls(&table);
  57567. }
  57568. diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
  57569. index a80a741..7b96e1b 100644
  57570. --- a/fs/nls/nls_koi8-ru.c
  57571. +++ b/fs/nls/nls_koi8-ru.c
  57572. @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
  57573. p_nls = load_nls("koi8-u");
  57574. if (p_nls) {
  57575. - table.charset2upper = p_nls->charset2upper;
  57576. - table.charset2lower = p_nls->charset2lower;
  57577. + pax_open_kernel();
  57578. + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
  57579. + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
  57580. + pax_close_kernel();
  57581. return register_nls(&table);
  57582. }
  57583. diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
  57584. index 287a22c..4e56e4e 100644
  57585. --- a/fs/notify/fanotify/fanotify_user.c
  57586. +++ b/fs/notify/fanotify/fanotify_user.c
  57587. @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
  57588. fd = fanotify_event_metadata.fd;
  57589. ret = -EFAULT;
  57590. - if (copy_to_user(buf, &fanotify_event_metadata,
  57591. - fanotify_event_metadata.event_len))
  57592. + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
  57593. + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
  57594. goto out_close_fd;
  57595. ret = prepare_for_access_response(group, event, fd);
  57596. @@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
  57597. oevent->path.mnt = NULL;
  57598. oevent->path.dentry = NULL;
  57599. + if (force_o_largefile())
  57600. + event_f_flags |= O_LARGEFILE;
  57601. group->fanotify_data.f_flags = event_f_flags;
  57602. #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
  57603. oevent->response = 0;
  57604. diff --git a/fs/notify/notification.c b/fs/notify/notification.c
  57605. index 1e58402..bb2d6f4 100644
  57606. --- a/fs/notify/notification.c
  57607. +++ b/fs/notify/notification.c
  57608. @@ -48,7 +48,7 @@
  57609. #include <linux/fsnotify_backend.h>
  57610. #include "fsnotify.h"
  57611. -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
  57612. +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
  57613. /**
  57614. * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
  57615. @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
  57616. */
  57617. u32 fsnotify_get_cookie(void)
  57618. {
  57619. - return atomic_inc_return(&fsnotify_sync_cookie);
  57620. + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
  57621. }
  57622. EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
  57623. diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
  57624. index 9e38daf..5727cae 100644
  57625. --- a/fs/ntfs/dir.c
  57626. +++ b/fs/ntfs/dir.c
  57627. @@ -1310,7 +1310,7 @@ find_next_index_buffer:
  57628. ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
  57629. ~(s64)(ndir->itype.index.block_size - 1)));
  57630. /* Bounds checks. */
  57631. - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
  57632. + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
  57633. ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
  57634. "inode 0x%lx or driver bug.", vdir->i_ino);
  57635. goto err_out;
  57636. diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
  57637. index db9bd8a..8338fb6 100644
  57638. --- a/fs/ntfs/file.c
  57639. +++ b/fs/ntfs/file.c
  57640. @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
  57641. char *addr;
  57642. size_t total = 0;
  57643. unsigned len;
  57644. - int left;
  57645. + unsigned left;
  57646. do {
  57647. len = PAGE_CACHE_SIZE - ofs;
  57648. diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
  57649. index 82650d5..db37dcf 100644
  57650. --- a/fs/ntfs/super.c
  57651. +++ b/fs/ntfs/super.c
  57652. @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
  57653. if (!silent)
  57654. ntfs_error(sb, "Primary boot sector is invalid.");
  57655. } else if (!silent)
  57656. - ntfs_error(sb, read_err_str, "primary");
  57657. + ntfs_error(sb, read_err_str, "%s", "primary");
  57658. if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
  57659. if (bh_primary)
  57660. brelse(bh_primary);
  57661. @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
  57662. goto hotfix_primary_boot_sector;
  57663. brelse(bh_backup);
  57664. } else if (!silent)
  57665. - ntfs_error(sb, read_err_str, "backup");
  57666. + ntfs_error(sb, read_err_str, "%s", "backup");
  57667. /* Try to read NT3.51- backup boot sector. */
  57668. if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
  57669. if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
  57670. @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
  57671. "sector.");
  57672. brelse(bh_backup);
  57673. } else if (!silent)
  57674. - ntfs_error(sb, read_err_str, "backup");
  57675. + ntfs_error(sb, read_err_str, "%s", "backup");
  57676. /* We failed. Cleanup and return. */
  57677. if (bh_primary)
  57678. brelse(bh_primary);
  57679. diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
  57680. index 0440134..d52c93a 100644
  57681. --- a/fs/ocfs2/localalloc.c
  57682. +++ b/fs/ocfs2/localalloc.c
  57683. @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
  57684. goto bail;
  57685. }
  57686. - atomic_inc(&osb->alloc_stats.moves);
  57687. + atomic_inc_unchecked(&osb->alloc_stats.moves);
  57688. bail:
  57689. if (handle)
  57690. diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
  57691. index 553f53c..aaf5133 100644
  57692. --- a/fs/ocfs2/ocfs2.h
  57693. +++ b/fs/ocfs2/ocfs2.h
  57694. @@ -235,11 +235,11 @@ enum ocfs2_vol_state
  57695. struct ocfs2_alloc_stats
  57696. {
  57697. - atomic_t moves;
  57698. - atomic_t local_data;
  57699. - atomic_t bitmap_data;
  57700. - atomic_t bg_allocs;
  57701. - atomic_t bg_extends;
  57702. + atomic_unchecked_t moves;
  57703. + atomic_unchecked_t local_data;
  57704. + atomic_unchecked_t bitmap_data;
  57705. + atomic_unchecked_t bg_allocs;
  57706. + atomic_unchecked_t bg_extends;
  57707. };
  57708. enum ocfs2_local_alloc_state
  57709. diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
  57710. index 47ae266..6e8b793 100644
  57711. --- a/fs/ocfs2/suballoc.c
  57712. +++ b/fs/ocfs2/suballoc.c
  57713. @@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
  57714. mlog_errno(status);
  57715. goto bail;
  57716. }
  57717. - atomic_inc(&osb->alloc_stats.bg_extends);
  57718. + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
  57719. /* You should never ask for this much metadata */
  57720. BUG_ON(bits_wanted >
  57721. @@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
  57722. mlog_errno(status);
  57723. goto bail;
  57724. }
  57725. - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
  57726. + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
  57727. *suballoc_loc = res.sr_bg_blkno;
  57728. *suballoc_bit_start = res.sr_bit_offset;
  57729. @@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
  57730. trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
  57731. res->sr_bits);
  57732. - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
  57733. + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
  57734. BUG_ON(res->sr_bits != 1);
  57735. @@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
  57736. mlog_errno(status);
  57737. goto bail;
  57738. }
  57739. - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
  57740. + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
  57741. BUG_ON(res.sr_bits != 1);
  57742. @@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
  57743. cluster_start,
  57744. num_clusters);
  57745. if (!status)
  57746. - atomic_inc(&osb->alloc_stats.local_data);
  57747. + atomic_inc_unchecked(&osb->alloc_stats.local_data);
  57748. } else {
  57749. if (min_clusters > (osb->bitmap_cpg - 1)) {
  57750. /* The only paths asking for contiguousness
  57751. @@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
  57752. ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
  57753. res.sr_bg_blkno,
  57754. res.sr_bit_offset);
  57755. - atomic_inc(&osb->alloc_stats.bitmap_data);
  57756. + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
  57757. *num_clusters = res.sr_bits;
  57758. }
  57759. }
  57760. diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
  57761. index 49d84f8..4807e0b 100644
  57762. --- a/fs/ocfs2/super.c
  57763. +++ b/fs/ocfs2/super.c
  57764. @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  57765. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  57766. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  57767. "Stats",
  57768. - atomic_read(&osb->alloc_stats.bitmap_data),
  57769. - atomic_read(&osb->alloc_stats.local_data),
  57770. - atomic_read(&osb->alloc_stats.bg_allocs),
  57771. - atomic_read(&osb->alloc_stats.moves),
  57772. - atomic_read(&osb->alloc_stats.bg_extends));
  57773. + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
  57774. + atomic_read_unchecked(&osb->alloc_stats.local_data),
  57775. + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
  57776. + atomic_read_unchecked(&osb->alloc_stats.moves),
  57777. + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
  57778. out += snprintf(buf + out, len - out,
  57779. "%10s => State: %u Descriptor: %llu Size: %u bits "
  57780. @@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
  57781. spin_lock_init(&osb->osb_xattr_lock);
  57782. ocfs2_init_steal_slots(osb);
  57783. - atomic_set(&osb->alloc_stats.moves, 0);
  57784. - atomic_set(&osb->alloc_stats.local_data, 0);
  57785. - atomic_set(&osb->alloc_stats.bitmap_data, 0);
  57786. - atomic_set(&osb->alloc_stats.bg_allocs, 0);
  57787. - atomic_set(&osb->alloc_stats.bg_extends, 0);
  57788. + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
  57789. + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
  57790. + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
  57791. + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
  57792. + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
  57793. /* Copy the blockcheck stats from the superblock probe */
  57794. osb->osb_ecc_stats = *stats;
  57795. diff --git a/fs/open.c b/fs/open.c
  57796. index b9ed8b2..0d5c7a0 100644
  57797. --- a/fs/open.c
  57798. +++ b/fs/open.c
  57799. @@ -32,6 +32,8 @@
  57800. #include <linux/dnotify.h>
  57801. #include <linux/compat.h>
  57802. +#define CREATE_TRACE_POINTS
  57803. +#include <trace/events/fs.h>
  57804. #include "internal.h"
  57805. int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
  57806. @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
  57807. error = locks_verify_truncate(inode, NULL, length);
  57808. if (!error)
  57809. error = security_path_truncate(path);
  57810. + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
  57811. + error = -EACCES;
  57812. if (!error)
  57813. error = do_truncate(path->dentry, length, 0, NULL);
  57814. @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
  57815. error = locks_verify_truncate(inode, f.file, length);
  57816. if (!error)
  57817. error = security_path_truncate(&f.file->f_path);
  57818. + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
  57819. + error = -EACCES;
  57820. if (!error)
  57821. error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
  57822. sb_end_write(inode->i_sb);
  57823. @@ -361,6 +367,9 @@ retry:
  57824. if (__mnt_is_readonly(path.mnt))
  57825. res = -EROFS;
  57826. + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
  57827. + res = -EACCES;
  57828. +
  57829. out_path_release:
  57830. path_put(&path);
  57831. if (retry_estale(res, lookup_flags)) {
  57832. @@ -392,6 +401,8 @@ retry:
  57833. if (error)
  57834. goto dput_and_out;
  57835. + gr_log_chdir(path.dentry, path.mnt);
  57836. +
  57837. set_fs_pwd(current->fs, &path);
  57838. dput_and_out:
  57839. @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
  57840. goto out_putf;
  57841. error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
  57842. +
  57843. + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
  57844. + error = -EPERM;
  57845. +
  57846. + if (!error)
  57847. + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
  57848. +
  57849. if (!error)
  57850. set_fs_pwd(current->fs, &f.file->f_path);
  57851. out_putf:
  57852. @@ -450,7 +468,13 @@ retry:
  57853. if (error)
  57854. goto dput_and_out;
  57855. + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
  57856. + goto dput_and_out;
  57857. +
  57858. set_fs_root(current->fs, &path);
  57859. +
  57860. + gr_handle_chroot_chdir(&path);
  57861. +
  57862. error = 0;
  57863. dput_and_out:
  57864. path_put(&path);
  57865. @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
  57866. return error;
  57867. retry_deleg:
  57868. mutex_lock(&inode->i_mutex);
  57869. +
  57870. + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
  57871. + error = -EACCES;
  57872. + goto out_unlock;
  57873. + }
  57874. + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
  57875. + error = -EACCES;
  57876. + goto out_unlock;
  57877. + }
  57878. +
  57879. error = security_path_chmod(path, mode);
  57880. if (error)
  57881. goto out_unlock;
  57882. @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
  57883. uid = make_kuid(current_user_ns(), user);
  57884. gid = make_kgid(current_user_ns(), group);
  57885. + if (!gr_acl_handle_chown(path->dentry, path->mnt))
  57886. + return -EACCES;
  57887. +
  57888. newattrs.ia_valid = ATTR_CTIME;
  57889. if (user != (uid_t) -1) {
  57890. if (!uid_valid(uid))
  57891. @@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
  57892. } else {
  57893. fsnotify_open(f);
  57894. fd_install(fd, f);
  57895. + trace_do_sys_open(tmp->name, flags, mode);
  57896. }
  57897. }
  57898. putname(tmp);
  57899. diff --git a/fs/pipe.c b/fs/pipe.c
  57900. index 78fd0d0..f71fc09 100644
  57901. --- a/fs/pipe.c
  57902. +++ b/fs/pipe.c
  57903. @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
  57904. static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
  57905. {
  57906. - if (pipe->files)
  57907. + if (atomic_read(&pipe->files))
  57908. mutex_lock_nested(&pipe->mutex, subclass);
  57909. }
  57910. @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
  57911. void pipe_unlock(struct pipe_inode_info *pipe)
  57912. {
  57913. - if (pipe->files)
  57914. + if (atomic_read(&pipe->files))
  57915. mutex_unlock(&pipe->mutex);
  57916. }
  57917. EXPORT_SYMBOL(pipe_unlock);
  57918. @@ -449,9 +449,9 @@ redo:
  57919. }
  57920. if (bufs) /* More to do? */
  57921. continue;
  57922. - if (!pipe->writers)
  57923. + if (!atomic_read(&pipe->writers))
  57924. break;
  57925. - if (!pipe->waiting_writers) {
  57926. + if (!atomic_read(&pipe->waiting_writers)) {
  57927. /* syscall merging: Usually we must not sleep
  57928. * if O_NONBLOCK is set, or if we got some data.
  57929. * But if a writer sleeps in kernel space, then
  57930. @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
  57931. ret = 0;
  57932. __pipe_lock(pipe);
  57933. - if (!pipe->readers) {
  57934. + if (!atomic_read(&pipe->readers)) {
  57935. send_sig(SIGPIPE, current, 0);
  57936. ret = -EPIPE;
  57937. goto out;
  57938. @@ -562,7 +562,7 @@ redo1:
  57939. for (;;) {
  57940. int bufs;
  57941. - if (!pipe->readers) {
  57942. + if (!atomic_read(&pipe->readers)) {
  57943. send_sig(SIGPIPE, current, 0);
  57944. if (!ret)
  57945. ret = -EPIPE;
  57946. @@ -653,9 +653,9 @@ redo2:
  57947. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  57948. do_wakeup = 0;
  57949. }
  57950. - pipe->waiting_writers++;
  57951. + atomic_inc(&pipe->waiting_writers);
  57952. pipe_wait(pipe);
  57953. - pipe->waiting_writers--;
  57954. + atomic_dec(&pipe->waiting_writers);
  57955. }
  57956. out:
  57957. __pipe_unlock(pipe);
  57958. @@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
  57959. mask = 0;
  57960. if (filp->f_mode & FMODE_READ) {
  57961. mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
  57962. - if (!pipe->writers && filp->f_version != pipe->w_counter)
  57963. + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
  57964. mask |= POLLHUP;
  57965. }
  57966. @@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
  57967. * Most Unices do not set POLLERR for FIFOs but on Linux they
  57968. * behave exactly like pipes for poll().
  57969. */
  57970. - if (!pipe->readers)
  57971. + if (!atomic_read(&pipe->readers))
  57972. mask |= POLLERR;
  57973. }
  57974. @@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
  57975. int kill = 0;
  57976. spin_lock(&inode->i_lock);
  57977. - if (!--pipe->files) {
  57978. + if (atomic_dec_and_test(&pipe->files)) {
  57979. inode->i_pipe = NULL;
  57980. kill = 1;
  57981. }
  57982. @@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
  57983. __pipe_lock(pipe);
  57984. if (file->f_mode & FMODE_READ)
  57985. - pipe->readers--;
  57986. + atomic_dec(&pipe->readers);
  57987. if (file->f_mode & FMODE_WRITE)
  57988. - pipe->writers--;
  57989. + atomic_dec(&pipe->writers);
  57990. - if (pipe->readers || pipe->writers) {
  57991. + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
  57992. wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
  57993. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  57994. kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
  57995. @@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
  57996. kfree(pipe);
  57997. }
  57998. -static struct vfsmount *pipe_mnt __read_mostly;
  57999. +struct vfsmount *pipe_mnt __read_mostly;
  58000. /*
  58001. * pipefs_dname() is called from d_path().
  58002. @@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
  58003. goto fail_iput;
  58004. inode->i_pipe = pipe;
  58005. - pipe->files = 2;
  58006. - pipe->readers = pipe->writers = 1;
  58007. + atomic_set(&pipe->files, 2);
  58008. + atomic_set(&pipe->readers, 1);
  58009. + atomic_set(&pipe->writers, 1);
  58010. inode->i_fop = &pipefifo_fops;
  58011. /*
  58012. @@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
  58013. spin_lock(&inode->i_lock);
  58014. if (inode->i_pipe) {
  58015. pipe = inode->i_pipe;
  58016. - pipe->files++;
  58017. + atomic_inc(&pipe->files);
  58018. spin_unlock(&inode->i_lock);
  58019. } else {
  58020. spin_unlock(&inode->i_lock);
  58021. pipe = alloc_pipe_info();
  58022. if (!pipe)
  58023. return -ENOMEM;
  58024. - pipe->files = 1;
  58025. + atomic_set(&pipe->files, 1);
  58026. spin_lock(&inode->i_lock);
  58027. if (unlikely(inode->i_pipe)) {
  58028. - inode->i_pipe->files++;
  58029. + atomic_inc(&inode->i_pipe->files);
  58030. spin_unlock(&inode->i_lock);
  58031. free_pipe_info(pipe);
  58032. pipe = inode->i_pipe;
  58033. @@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
  58034. * opened, even when there is no process writing the FIFO.
  58035. */
  58036. pipe->r_counter++;
  58037. - if (pipe->readers++ == 0)
  58038. + if (atomic_inc_return(&pipe->readers) == 1)
  58039. wake_up_partner(pipe);
  58040. - if (!is_pipe && !pipe->writers) {
  58041. + if (!is_pipe && !atomic_read(&pipe->writers)) {
  58042. if ((filp->f_flags & O_NONBLOCK)) {
  58043. /* suppress POLLHUP until we have
  58044. * seen a writer */
  58045. @@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
  58046. * errno=ENXIO when there is no process reading the FIFO.
  58047. */
  58048. ret = -ENXIO;
  58049. - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
  58050. + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
  58051. goto err;
  58052. pipe->w_counter++;
  58053. - if (!pipe->writers++)
  58054. + if (atomic_inc_return(&pipe->writers) == 1)
  58055. wake_up_partner(pipe);
  58056. - if (!is_pipe && !pipe->readers) {
  58057. + if (!is_pipe && !atomic_read(&pipe->readers)) {
  58058. if (wait_for_partner(pipe, &pipe->r_counter))
  58059. goto err_wr;
  58060. }
  58061. @@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
  58062. * the process can at least talk to itself.
  58063. */
  58064. - pipe->readers++;
  58065. - pipe->writers++;
  58066. + atomic_inc(&pipe->readers);
  58067. + atomic_inc(&pipe->writers);
  58068. pipe->r_counter++;
  58069. pipe->w_counter++;
  58070. - if (pipe->readers == 1 || pipe->writers == 1)
  58071. + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
  58072. wake_up_partner(pipe);
  58073. break;
  58074. @@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
  58075. return 0;
  58076. err_rd:
  58077. - if (!--pipe->readers)
  58078. + if (atomic_dec_and_test(&pipe->readers))
  58079. wake_up_interruptible(&pipe->wait);
  58080. ret = -ERESTARTSYS;
  58081. goto err;
  58082. err_wr:
  58083. - if (!--pipe->writers)
  58084. + if (atomic_dec_and_test(&pipe->writers))
  58085. wake_up_interruptible(&pipe->wait);
  58086. ret = -ERESTARTSYS;
  58087. goto err;
  58088. diff --git a/fs/posix_acl.c b/fs/posix_acl.c
  58089. index 9e363e4..d936d15 100644
  58090. --- a/fs/posix_acl.c
  58091. +++ b/fs/posix_acl.c
  58092. @@ -20,6 +20,7 @@
  58093. #include <linux/xattr.h>
  58094. #include <linux/export.h>
  58095. #include <linux/user_namespace.h>
  58096. +#include <linux/grsecurity.h>
  58097. struct posix_acl **acl_by_type(struct inode *inode, int type)
  58098. {
  58099. @@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
  58100. }
  58101. }
  58102. if (mode_p)
  58103. - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
  58104. + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
  58105. return not_equiv;
  58106. }
  58107. EXPORT_SYMBOL(posix_acl_equiv_mode);
  58108. @@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
  58109. mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
  58110. }
  58111. - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
  58112. + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
  58113. return not_equiv;
  58114. }
  58115. @@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
  58116. struct posix_acl *clone = posix_acl_clone(*acl, gfp);
  58117. int err = -ENOMEM;
  58118. if (clone) {
  58119. + *mode_p &= ~gr_acl_umask();
  58120. +
  58121. err = posix_acl_create_masq(clone, mode_p);
  58122. if (err < 0) {
  58123. posix_acl_release(clone);
  58124. @@ -653,11 +656,12 @@ struct posix_acl *
  58125. posix_acl_from_xattr(struct user_namespace *user_ns,
  58126. const void *value, size_t size)
  58127. {
  58128. - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
  58129. - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
  58130. + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
  58131. + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
  58132. int count;
  58133. struct posix_acl *acl;
  58134. struct posix_acl_entry *acl_e;
  58135. + umode_t umask = gr_acl_umask();
  58136. if (!value)
  58137. return NULL;
  58138. @@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
  58139. switch(acl_e->e_tag) {
  58140. case ACL_USER_OBJ:
  58141. + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
  58142. + break;
  58143. case ACL_GROUP_OBJ:
  58144. case ACL_MASK:
  58145. + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
  58146. + break;
  58147. case ACL_OTHER:
  58148. + acl_e->e_perm &= ~(umask & S_IRWXO);
  58149. break;
  58150. case ACL_USER:
  58151. + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
  58152. acl_e->e_uid =
  58153. make_kuid(user_ns,
  58154. le32_to_cpu(entry->e_id));
  58155. @@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
  58156. goto fail;
  58157. break;
  58158. case ACL_GROUP:
  58159. + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
  58160. acl_e->e_gid =
  58161. make_kgid(user_ns,
  58162. le32_to_cpu(entry->e_id));
  58163. diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
  58164. index 2183fcf..3c32a98 100644
  58165. --- a/fs/proc/Kconfig
  58166. +++ b/fs/proc/Kconfig
  58167. @@ -30,7 +30,7 @@ config PROC_FS
  58168. config PROC_KCORE
  58169. bool "/proc/kcore support" if !ARM
  58170. - depends on PROC_FS && MMU
  58171. + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
  58172. help
  58173. Provides a virtual ELF core file of the live kernel. This can
  58174. be read with gdb and other ELF tools. No modifications can be
  58175. @@ -38,8 +38,8 @@ config PROC_KCORE
  58176. config PROC_VMCORE
  58177. bool "/proc/vmcore support"
  58178. - depends on PROC_FS && CRASH_DUMP
  58179. - default y
  58180. + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
  58181. + default n
  58182. help
  58183. Exports the dump image of crashed kernel in ELF format.
  58184. @@ -63,8 +63,8 @@ config PROC_SYSCTL
  58185. limited in memory.
  58186. config PROC_PAGE_MONITOR
  58187. - default y
  58188. - depends on PROC_FS && MMU
  58189. + default n
  58190. + depends on PROC_FS && MMU && !GRKERNSEC
  58191. bool "Enable /proc page monitoring" if EXPERT
  58192. help
  58193. Various /proc files exist to monitor process memory utilization:
  58194. diff --git a/fs/proc/array.c b/fs/proc/array.c
  58195. index 656e401..b5b86b9 100644
  58196. --- a/fs/proc/array.c
  58197. +++ b/fs/proc/array.c
  58198. @@ -60,6 +60,7 @@
  58199. #include <linux/tty.h>
  58200. #include <linux/string.h>
  58201. #include <linux/mman.h>
  58202. +#include <linux/grsecurity.h>
  58203. #include <linux/proc_fs.h>
  58204. #include <linux/ioport.h>
  58205. #include <linux/uaccess.h>
  58206. @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
  58207. seq_putc(m, '\n');
  58208. }
  58209. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  58210. +static inline void task_pax(struct seq_file *m, struct task_struct *p)
  58211. +{
  58212. + if (p->mm)
  58213. + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
  58214. + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
  58215. + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
  58216. + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
  58217. + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
  58218. + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
  58219. + else
  58220. + seq_printf(m, "PaX:\t-----\n");
  58221. +}
  58222. +#endif
  58223. +
  58224. int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
  58225. struct pid *pid, struct task_struct *task)
  58226. {
  58227. @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
  58228. task_cpus_allowed(m, task);
  58229. cpuset_task_status_allowed(m, task);
  58230. task_context_switch_counts(m, task);
  58231. +
  58232. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  58233. + task_pax(m, task);
  58234. +#endif
  58235. +
  58236. +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
  58237. + task_grsec_rbac(m, task);
  58238. +#endif
  58239. +
  58240. return 0;
  58241. }
  58242. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58243. +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
  58244. + (_mm->pax_flags & MF_PAX_RANDMMAP || \
  58245. + _mm->pax_flags & MF_PAX_SEGMEXEC))
  58246. +#endif
  58247. +
  58248. static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
  58249. struct pid *pid, struct task_struct *task, int whole)
  58250. {
  58251. @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
  58252. char tcomm[sizeof(task->comm)];
  58253. unsigned long flags;
  58254. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58255. + if (current->exec_id != m->exec_id) {
  58256. + gr_log_badprocpid("stat");
  58257. + return 0;
  58258. + }
  58259. +#endif
  58260. +
  58261. state = *get_task_state(task);
  58262. vsize = eip = esp = 0;
  58263. permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
  58264. @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
  58265. gtime = task_gtime(task);
  58266. }
  58267. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58268. + if (PAX_RAND_FLAGS(mm)) {
  58269. + eip = 0;
  58270. + esp = 0;
  58271. + wchan = 0;
  58272. + }
  58273. +#endif
  58274. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  58275. + wchan = 0;
  58276. + eip =0;
  58277. + esp =0;
  58278. +#endif
  58279. +
  58280. /* scale priority and nice values from timeslices to -20..20 */
  58281. /* to make it look like a "normal" Unix priority/nice value */
  58282. priority = task_prio(task);
  58283. @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
  58284. seq_put_decimal_ull(m, ' ', vsize);
  58285. seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
  58286. seq_put_decimal_ull(m, ' ', rsslim);
  58287. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58288. + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
  58289. + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
  58290. + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
  58291. +#else
  58292. seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
  58293. seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
  58294. seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
  58295. +#endif
  58296. seq_put_decimal_ull(m, ' ', esp);
  58297. seq_put_decimal_ull(m, ' ', eip);
  58298. /* The signal information here is obsolete.
  58299. @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
  58300. seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
  58301. seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
  58302. - if (mm && permitted) {
  58303. + if (mm && permitted
  58304. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58305. + && !PAX_RAND_FLAGS(mm)
  58306. +#endif
  58307. + ) {
  58308. seq_put_decimal_ull(m, ' ', mm->start_data);
  58309. seq_put_decimal_ull(m, ' ', mm->end_data);
  58310. seq_put_decimal_ull(m, ' ', mm->start_brk);
  58311. @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
  58312. struct pid *pid, struct task_struct *task)
  58313. {
  58314. unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
  58315. - struct mm_struct *mm = get_task_mm(task);
  58316. + struct mm_struct *mm;
  58317. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58318. + if (current->exec_id != m->exec_id) {
  58319. + gr_log_badprocpid("statm");
  58320. + return 0;
  58321. + }
  58322. +#endif
  58323. + mm = get_task_mm(task);
  58324. if (mm) {
  58325. size = task_statm(mm, &shared, &text, &data, &resident);
  58326. mmput(mm);
  58327. @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
  58328. return 0;
  58329. }
  58330. +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
  58331. +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
  58332. +{
  58333. + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
  58334. +}
  58335. +#endif
  58336. +
  58337. #ifdef CONFIG_CHECKPOINT_RESTORE
  58338. static struct pid *
  58339. get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
  58340. diff --git a/fs/proc/base.c b/fs/proc/base.c
  58341. index b976062..584d0bc 100644
  58342. --- a/fs/proc/base.c
  58343. +++ b/fs/proc/base.c
  58344. @@ -113,6 +113,14 @@ struct pid_entry {
  58345. union proc_op op;
  58346. };
  58347. +struct getdents_callback {
  58348. + struct linux_dirent __user * current_dir;
  58349. + struct linux_dirent __user * previous;
  58350. + struct file * file;
  58351. + int count;
  58352. + int error;
  58353. +};
  58354. +
  58355. #define NOD(NAME, MODE, IOP, FOP, OP) { \
  58356. .name = (NAME), \
  58357. .len = sizeof(NAME) - 1, \
  58358. @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
  58359. if (!mm->arg_end)
  58360. goto out_mm; /* Shh! No looking before we're done */
  58361. + if (gr_acl_handle_procpidmem(task))
  58362. + goto out_mm;
  58363. +
  58364. len = mm->arg_end - mm->arg_start;
  58365. if (len > PAGE_SIZE)
  58366. @@ -237,12 +248,28 @@ out:
  58367. return res;
  58368. }
  58369. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58370. +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
  58371. + (_mm->pax_flags & MF_PAX_RANDMMAP || \
  58372. + _mm->pax_flags & MF_PAX_SEGMEXEC))
  58373. +#endif
  58374. +
  58375. static int proc_pid_auxv(struct task_struct *task, char *buffer)
  58376. {
  58377. struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
  58378. int res = PTR_ERR(mm);
  58379. if (mm && !IS_ERR(mm)) {
  58380. unsigned int nwords = 0;
  58381. +
  58382. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58383. + /* allow if we're currently ptracing this task */
  58384. + if (PAX_RAND_FLAGS(mm) &&
  58385. + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
  58386. + mmput(mm);
  58387. + return 0;
  58388. + }
  58389. +#endif
  58390. +
  58391. do {
  58392. nwords += 2;
  58393. } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
  58394. @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
  58395. }
  58396. -#ifdef CONFIG_KALLSYMS
  58397. +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  58398. /*
  58399. * Provides a wchan file via kallsyms in a proper one-value-per-file format.
  58400. * Returns the resolved symbol. If that fails, simply return the address.
  58401. @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
  58402. mutex_unlock(&task->signal->cred_guard_mutex);
  58403. }
  58404. -#ifdef CONFIG_STACKTRACE
  58405. +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  58406. #define MAX_STACK_TRACE_DEPTH 64
  58407. @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
  58408. return count;
  58409. }
  58410. -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
  58411. +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
  58412. static int proc_pid_syscall(struct task_struct *task, char *buffer)
  58413. {
  58414. long nr;
  58415. @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
  58416. /************************************************************************/
  58417. /* permission checks */
  58418. -static int proc_fd_access_allowed(struct inode *inode)
  58419. +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
  58420. {
  58421. struct task_struct *task;
  58422. int allowed = 0;
  58423. @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
  58424. */
  58425. task = get_proc_task(inode);
  58426. if (task) {
  58427. - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
  58428. + if (log)
  58429. + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
  58430. + else
  58431. + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
  58432. put_task_struct(task);
  58433. }
  58434. return allowed;
  58435. @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
  58436. struct task_struct *task,
  58437. int hide_pid_min)
  58438. {
  58439. + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
  58440. + return false;
  58441. +
  58442. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  58443. + rcu_read_lock();
  58444. + {
  58445. + const struct cred *tmpcred = current_cred();
  58446. + const struct cred *cred = __task_cred(task);
  58447. +
  58448. + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
  58449. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  58450. + || in_group_p(grsec_proc_gid)
  58451. +#endif
  58452. + ) {
  58453. + rcu_read_unlock();
  58454. + return true;
  58455. + }
  58456. + }
  58457. + rcu_read_unlock();
  58458. +
  58459. + if (!pid->hide_pid)
  58460. + return false;
  58461. +#endif
  58462. +
  58463. if (pid->hide_pid < hide_pid_min)
  58464. return true;
  58465. if (in_group_p(pid->pid_gid))
  58466. return true;
  58467. +
  58468. return ptrace_may_access(task, PTRACE_MODE_READ);
  58469. }
  58470. @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
  58471. put_task_struct(task);
  58472. if (!has_perms) {
  58473. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  58474. + {
  58475. +#else
  58476. if (pid->hide_pid == 2) {
  58477. +#endif
  58478. /*
  58479. * Let's make getdents(), stat(), and open()
  58480. * consistent with each other. If a process
  58481. @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
  58482. if (!task)
  58483. return -ESRCH;
  58484. + if (gr_acl_handle_procpidmem(task)) {
  58485. + put_task_struct(task);
  58486. + return -EPERM;
  58487. + }
  58488. +
  58489. mm = mm_access(task, mode);
  58490. put_task_struct(task);
  58491. @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
  58492. file->private_data = mm;
  58493. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58494. + file->f_version = current->exec_id;
  58495. +#endif
  58496. +
  58497. return 0;
  58498. }
  58499. @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
  58500. ssize_t copied;
  58501. char *page;
  58502. +#ifdef CONFIG_GRKERNSEC
  58503. + if (write)
  58504. + return -EPERM;
  58505. +#endif
  58506. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58507. + if (file->f_version != current->exec_id) {
  58508. + gr_log_badprocpid("mem");
  58509. + return 0;
  58510. + }
  58511. +#endif
  58512. +
  58513. if (!mm)
  58514. return 0;
  58515. @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
  58516. goto free;
  58517. while (count > 0) {
  58518. - int this_len = min_t(int, count, PAGE_SIZE);
  58519. + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
  58520. if (write && copy_from_user(page, buf, this_len)) {
  58521. copied = -EFAULT;
  58522. @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
  58523. if (!mm)
  58524. return 0;
  58525. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  58526. + if (file->f_version != current->exec_id) {
  58527. + gr_log_badprocpid("environ");
  58528. + return 0;
  58529. + }
  58530. +#endif
  58531. +
  58532. page = (char *)__get_free_page(GFP_TEMPORARY);
  58533. if (!page)
  58534. return -ENOMEM;
  58535. @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
  58536. goto free;
  58537. while (count > 0) {
  58538. size_t this_len, max_len;
  58539. - int retval;
  58540. + ssize_t retval;
  58541. if (src >= (mm->env_end - mm->env_start))
  58542. break;
  58543. @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
  58544. int error = -EACCES;
  58545. /* Are we allowed to snoop on the tasks file descriptors? */
  58546. - if (!proc_fd_access_allowed(inode))
  58547. + if (!proc_fd_access_allowed(inode, 0))
  58548. goto out;
  58549. error = PROC_I(inode)->op.proc_get_link(dentry, &path);
  58550. @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
  58551. struct path path;
  58552. /* Are we allowed to snoop on the tasks file descriptors? */
  58553. - if (!proc_fd_access_allowed(inode))
  58554. - goto out;
  58555. + /* logging this is needed for learning on chromium to work properly,
  58556. + but we don't want to flood the logs from 'ps' which does a readlink
  58557. + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
  58558. + CAP_SYS_PTRACE as it's not necessary for its basic functionality
  58559. + */
  58560. + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
  58561. + if (!proc_fd_access_allowed(inode,0))
  58562. + goto out;
  58563. + } else {
  58564. + if (!proc_fd_access_allowed(inode,1))
  58565. + goto out;
  58566. + }
  58567. error = PROC_I(inode)->op.proc_get_link(dentry, &path);
  58568. if (error)
  58569. @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
  58570. rcu_read_lock();
  58571. cred = __task_cred(task);
  58572. inode->i_uid = cred->euid;
  58573. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  58574. + inode->i_gid = grsec_proc_gid;
  58575. +#else
  58576. inode->i_gid = cred->egid;
  58577. +#endif
  58578. rcu_read_unlock();
  58579. }
  58580. security_task_to_inode(task, inode);
  58581. @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
  58582. return -ENOENT;
  58583. }
  58584. if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
  58585. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  58586. + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
  58587. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  58588. + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
  58589. +#endif
  58590. task_dumpable(task)) {
  58591. cred = __task_cred(task);
  58592. stat->uid = cred->euid;
  58593. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  58594. + stat->gid = grsec_proc_gid;
  58595. +#else
  58596. stat->gid = cred->egid;
  58597. +#endif
  58598. }
  58599. }
  58600. rcu_read_unlock();
  58601. @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
  58602. if (task) {
  58603. if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
  58604. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  58605. + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
  58606. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  58607. + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
  58608. +#endif
  58609. task_dumpable(task)) {
  58610. rcu_read_lock();
  58611. cred = __task_cred(task);
  58612. inode->i_uid = cred->euid;
  58613. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  58614. + inode->i_gid = grsec_proc_gid;
  58615. +#else
  58616. inode->i_gid = cred->egid;
  58617. +#endif
  58618. rcu_read_unlock();
  58619. } else {
  58620. inode->i_uid = GLOBAL_ROOT_UID;
  58621. @@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
  58622. if (!task)
  58623. goto out_no_task;
  58624. + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
  58625. + goto out;
  58626. +
  58627. /*
  58628. * Yes, it does not scale. And it should not. Don't add
  58629. * new entries into /proc/<tgid>/ without very good reasons.
  58630. @@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
  58631. if (!task)
  58632. return -ENOENT;
  58633. + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
  58634. + goto out;
  58635. +
  58636. if (!dir_emit_dots(file, ctx))
  58637. goto out;
  58638. @@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
  58639. REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
  58640. #endif
  58641. REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
  58642. -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
  58643. +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
  58644. INF("syscall", S_IRUGO, proc_pid_syscall),
  58645. #endif
  58646. INF("cmdline", S_IRUGO, proc_pid_cmdline),
  58647. @@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
  58648. #ifdef CONFIG_SECURITY
  58649. DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
  58650. #endif
  58651. -#ifdef CONFIG_KALLSYMS
  58652. +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  58653. INF("wchan", S_IRUGO, proc_pid_wchan),
  58654. #endif
  58655. -#ifdef CONFIG_STACKTRACE
  58656. +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  58657. ONE("stack", S_IRUGO, proc_pid_stack),
  58658. #endif
  58659. #ifdef CONFIG_SCHEDSTATS
  58660. @@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
  58661. #ifdef CONFIG_HARDWALL
  58662. INF("hardwall", S_IRUGO, proc_pid_hardwall),
  58663. #endif
  58664. +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
  58665. + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
  58666. +#endif
  58667. #ifdef CONFIG_USER_NS
  58668. REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
  58669. REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
  58670. @@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
  58671. if (!inode)
  58672. goto out;
  58673. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  58674. + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
  58675. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  58676. + inode->i_gid = grsec_proc_gid;
  58677. + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
  58678. +#else
  58679. inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
  58680. +#endif
  58681. inode->i_op = &proc_tgid_base_inode_operations;
  58682. inode->i_fop = &proc_tgid_base_operations;
  58683. inode->i_flags|=S_IMMUTABLE;
  58684. @@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
  58685. if (!task)
  58686. goto out;
  58687. + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
  58688. + goto out_put_task;
  58689. +
  58690. result = proc_pid_instantiate(dir, dentry, task, NULL);
  58691. +out_put_task:
  58692. put_task_struct(task);
  58693. out:
  58694. return ERR_PTR(result);
  58695. @@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
  58696. REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
  58697. #endif
  58698. REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
  58699. -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
  58700. +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
  58701. INF("syscall", S_IRUGO, proc_pid_syscall),
  58702. #endif
  58703. INF("cmdline", S_IRUGO, proc_pid_cmdline),
  58704. @@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
  58705. #ifdef CONFIG_SECURITY
  58706. DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
  58707. #endif
  58708. -#ifdef CONFIG_KALLSYMS
  58709. +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  58710. INF("wchan", S_IRUGO, proc_pid_wchan),
  58711. #endif
  58712. -#ifdef CONFIG_STACKTRACE
  58713. +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  58714. ONE("stack", S_IRUGO, proc_pid_stack),
  58715. #endif
  58716. #ifdef CONFIG_SCHEDSTATS
  58717. diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
  58718. index cbd82df..c0407d2 100644
  58719. --- a/fs/proc/cmdline.c
  58720. +++ b/fs/proc/cmdline.c
  58721. @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
  58722. static int __init proc_cmdline_init(void)
  58723. {
  58724. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  58725. + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
  58726. +#else
  58727. proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
  58728. +#endif
  58729. return 0;
  58730. }
  58731. fs_initcall(proc_cmdline_init);
  58732. diff --git a/fs/proc/devices.c b/fs/proc/devices.c
  58733. index 50493ed..248166b 100644
  58734. --- a/fs/proc/devices.c
  58735. +++ b/fs/proc/devices.c
  58736. @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
  58737. static int __init proc_devices_init(void)
  58738. {
  58739. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  58740. + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
  58741. +#else
  58742. proc_create("devices", 0, NULL, &proc_devinfo_operations);
  58743. +#endif
  58744. return 0;
  58745. }
  58746. fs_initcall(proc_devices_init);
  58747. diff --git a/fs/proc/fd.c b/fs/proc/fd.c
  58748. index 985ea88..d118a0a 100644
  58749. --- a/fs/proc/fd.c
  58750. +++ b/fs/proc/fd.c
  58751. @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
  58752. if (!task)
  58753. return -ENOENT;
  58754. - files = get_files_struct(task);
  58755. + if (!gr_acl_handle_procpidmem(task))
  58756. + files = get_files_struct(task);
  58757. put_task_struct(task);
  58758. if (files) {
  58759. @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
  58760. */
  58761. int proc_fd_permission(struct inode *inode, int mask)
  58762. {
  58763. + struct task_struct *task;
  58764. int rv = generic_permission(inode, mask);
  58765. - if (rv == 0)
  58766. - return 0;
  58767. +
  58768. if (task_tgid(current) == proc_pid(inode))
  58769. rv = 0;
  58770. +
  58771. + task = get_proc_task(inode);
  58772. + if (task == NULL)
  58773. + return rv;
  58774. +
  58775. + if (gr_acl_handle_procpidmem(task))
  58776. + rv = -EACCES;
  58777. +
  58778. + put_task_struct(task);
  58779. +
  58780. return rv;
  58781. }
  58782. diff --git a/fs/proc/generic.c b/fs/proc/generic.c
  58783. index b7f268e..3bea6b7 100644
  58784. --- a/fs/proc/generic.c
  58785. +++ b/fs/proc/generic.c
  58786. @@ -23,6 +23,7 @@
  58787. #include <linux/bitops.h>
  58788. #include <linux/spinlock.h>
  58789. #include <linux/completion.h>
  58790. +#include <linux/grsecurity.h>
  58791. #include <asm/uaccess.h>
  58792. #include "internal.h"
  58793. @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
  58794. return proc_lookup_de(PDE(dir), dir, dentry);
  58795. }
  58796. +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
  58797. + unsigned int flags)
  58798. +{
  58799. + if (gr_proc_is_restricted())
  58800. + return ERR_PTR(-EACCES);
  58801. +
  58802. + return proc_lookup_de(PDE(dir), dir, dentry);
  58803. +}
  58804. +
  58805. /*
  58806. * This returns non-zero if at EOF, so that the /proc
  58807. * root directory can use this and check if it should
  58808. @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
  58809. return proc_readdir_de(PDE(inode), file, ctx);
  58810. }
  58811. +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
  58812. +{
  58813. + struct inode *inode = file_inode(file);
  58814. +
  58815. + if (gr_proc_is_restricted())
  58816. + return -EACCES;
  58817. +
  58818. + return proc_readdir_de(PDE(inode), file, ctx);
  58819. +}
  58820. +
  58821. /*
  58822. * These are the generic /proc directory operations. They
  58823. * use the in-memory "struct proc_dir_entry" tree to parse
  58824. @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
  58825. .iterate = proc_readdir,
  58826. };
  58827. +static const struct file_operations proc_dir_restricted_operations = {
  58828. + .llseek = generic_file_llseek,
  58829. + .read = generic_read_dir,
  58830. + .iterate = proc_readdir_restrict,
  58831. +};
  58832. +
  58833. /*
  58834. * proc directories can do almost nothing..
  58835. */
  58836. @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
  58837. .setattr = proc_notify_change,
  58838. };
  58839. +static const struct inode_operations proc_dir_restricted_inode_operations = {
  58840. + .lookup = proc_lookup_restrict,
  58841. + .getattr = proc_getattr,
  58842. + .setattr = proc_notify_change,
  58843. +};
  58844. +
  58845. static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
  58846. {
  58847. struct proc_dir_entry *tmp;
  58848. @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
  58849. return ret;
  58850. if (S_ISDIR(dp->mode)) {
  58851. - dp->proc_fops = &proc_dir_operations;
  58852. - dp->proc_iops = &proc_dir_inode_operations;
  58853. + if (dp->restricted) {
  58854. + dp->proc_fops = &proc_dir_restricted_operations;
  58855. + dp->proc_iops = &proc_dir_restricted_inode_operations;
  58856. + } else {
  58857. + dp->proc_fops = &proc_dir_operations;
  58858. + dp->proc_iops = &proc_dir_inode_operations;
  58859. + }
  58860. dir->nlink++;
  58861. } else if (S_ISLNK(dp->mode)) {
  58862. dp->proc_iops = &proc_link_inode_operations;
  58863. @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
  58864. }
  58865. EXPORT_SYMBOL_GPL(proc_mkdir_data);
  58866. +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
  58867. + struct proc_dir_entry *parent, void *data)
  58868. +{
  58869. + struct proc_dir_entry *ent;
  58870. +
  58871. + if (mode == 0)
  58872. + mode = S_IRUGO | S_IXUGO;
  58873. +
  58874. + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
  58875. + if (ent) {
  58876. + ent->data = data;
  58877. + ent->restricted = 1;
  58878. + if (proc_register(parent, ent) < 0) {
  58879. + kfree(ent);
  58880. + ent = NULL;
  58881. + }
  58882. + }
  58883. + return ent;
  58884. +}
  58885. +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
  58886. +
  58887. struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
  58888. struct proc_dir_entry *parent)
  58889. {
  58890. @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
  58891. }
  58892. EXPORT_SYMBOL(proc_mkdir);
  58893. +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
  58894. + struct proc_dir_entry *parent)
  58895. +{
  58896. + return proc_mkdir_data_restrict(name, 0, parent, NULL);
  58897. +}
  58898. +EXPORT_SYMBOL(proc_mkdir_restrict);
  58899. +
  58900. struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
  58901. struct proc_dir_entry *parent,
  58902. const struct file_operations *proc_fops,
  58903. diff --git a/fs/proc/inode.c b/fs/proc/inode.c
  58904. index 124fc43..8afbb02 100644
  58905. --- a/fs/proc/inode.c
  58906. +++ b/fs/proc/inode.c
  58907. @@ -23,11 +23,17 @@
  58908. #include <linux/slab.h>
  58909. #include <linux/mount.h>
  58910. #include <linux/magic.h>
  58911. +#include <linux/grsecurity.h>
  58912. #include <asm/uaccess.h>
  58913. #include "internal.h"
  58914. +#ifdef CONFIG_PROC_SYSCTL
  58915. +extern const struct inode_operations proc_sys_inode_operations;
  58916. +extern const struct inode_operations proc_sys_dir_operations;
  58917. +#endif
  58918. +
  58919. static void proc_evict_inode(struct inode *inode)
  58920. {
  58921. struct proc_dir_entry *de;
  58922. @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
  58923. ns = PROC_I(inode)->ns.ns;
  58924. if (ns_ops && ns)
  58925. ns_ops->put(ns);
  58926. +
  58927. +#ifdef CONFIG_PROC_SYSCTL
  58928. + if (inode->i_op == &proc_sys_inode_operations ||
  58929. + inode->i_op == &proc_sys_dir_operations)
  58930. + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
  58931. +#endif
  58932. +
  58933. }
  58934. static struct kmem_cache * proc_inode_cachep;
  58935. @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
  58936. if (de->mode) {
  58937. inode->i_mode = de->mode;
  58938. inode->i_uid = de->uid;
  58939. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  58940. + inode->i_gid = grsec_proc_gid;
  58941. +#else
  58942. inode->i_gid = de->gid;
  58943. +#endif
  58944. }
  58945. if (de->size)
  58946. inode->i_size = de->size;
  58947. diff --git a/fs/proc/internal.h b/fs/proc/internal.h
  58948. index 651d09a..6a4b495 100644
  58949. --- a/fs/proc/internal.h
  58950. +++ b/fs/proc/internal.h
  58951. @@ -46,9 +46,10 @@ struct proc_dir_entry {
  58952. struct completion *pde_unload_completion;
  58953. struct list_head pde_openers; /* who did ->open, but not ->release */
  58954. spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  58955. + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
  58956. u8 namelen;
  58957. char name[];
  58958. -};
  58959. +} __randomize_layout;
  58960. union proc_op {
  58961. int (*proc_get_link)(struct dentry *, struct path *);
  58962. @@ -67,7 +68,7 @@ struct proc_inode {
  58963. struct ctl_table *sysctl_entry;
  58964. struct proc_ns ns;
  58965. struct inode vfs_inode;
  58966. -};
  58967. +} __randomize_layout;
  58968. /*
  58969. * General functions
  58970. @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
  58971. struct pid *, struct task_struct *);
  58972. extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
  58973. struct pid *, struct task_struct *);
  58974. +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
  58975. +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
  58976. +#endif
  58977. /*
  58978. * base.c
  58979. @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
  58980. extern spinlock_t proc_subdir_lock;
  58981. extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
  58982. +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
  58983. extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
  58984. struct dentry *);
  58985. extern int proc_readdir(struct file *, struct dir_context *);
  58986. +extern int proc_readdir_restrict(struct file *, struct dir_context *);
  58987. extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
  58988. static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
  58989. diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
  58990. index a352d57..cb94a5c 100644
  58991. --- a/fs/proc/interrupts.c
  58992. +++ b/fs/proc/interrupts.c
  58993. @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
  58994. static int __init proc_interrupts_init(void)
  58995. {
  58996. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  58997. + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
  58998. +#else
  58999. proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
  59000. +#endif
  59001. return 0;
  59002. }
  59003. fs_initcall(proc_interrupts_init);
  59004. diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
  59005. index 39e6ef3..2f9cb5e 100644
  59006. --- a/fs/proc/kcore.c
  59007. +++ b/fs/proc/kcore.c
  59008. @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
  59009. * the addresses in the elf_phdr on our list.
  59010. */
  59011. start = kc_offset_to_vaddr(*fpos - elf_buflen);
  59012. - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
  59013. + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
  59014. + if (tsz > buflen)
  59015. tsz = buflen;
  59016. -
  59017. +
  59018. while (buflen) {
  59019. struct kcore_list *m;
  59020. @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
  59021. kfree(elf_buf);
  59022. } else {
  59023. if (kern_addr_valid(start)) {
  59024. - unsigned long n;
  59025. + char *elf_buf;
  59026. + mm_segment_t oldfs;
  59027. - n = copy_to_user(buffer, (char *)start, tsz);
  59028. - /*
  59029. - * We cannot distinguish between fault on source
  59030. - * and fault on destination. When this happens
  59031. - * we clear too and hope it will trigger the
  59032. - * EFAULT again.
  59033. - */
  59034. - if (n) {
  59035. - if (clear_user(buffer + tsz - n,
  59036. - n))
  59037. + elf_buf = kmalloc(tsz, GFP_KERNEL);
  59038. + if (!elf_buf)
  59039. + return -ENOMEM;
  59040. + oldfs = get_fs();
  59041. + set_fs(KERNEL_DS);
  59042. + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
  59043. + set_fs(oldfs);
  59044. + if (copy_to_user(buffer, elf_buf, tsz)) {
  59045. + kfree(elf_buf);
  59046. return -EFAULT;
  59047. + }
  59048. }
  59049. + set_fs(oldfs);
  59050. + kfree(elf_buf);
  59051. } else {
  59052. if (clear_user(buffer, tsz))
  59053. return -EFAULT;
  59054. @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
  59055. static int open_kcore(struct inode *inode, struct file *filp)
  59056. {
  59057. +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
  59058. + return -EPERM;
  59059. +#endif
  59060. if (!capable(CAP_SYS_RAWIO))
  59061. return -EPERM;
  59062. if (kcore_need_update)
  59063. diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
  59064. index 136e548..1f88922 100644
  59065. --- a/fs/proc/meminfo.c
  59066. +++ b/fs/proc/meminfo.c
  59067. @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
  59068. vmi.used >> 10,
  59069. vmi.largest_chunk >> 10
  59070. #ifdef CONFIG_MEMORY_FAILURE
  59071. - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
  59072. + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
  59073. #endif
  59074. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  59075. ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
  59076. diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
  59077. index d4a3574..b421ce9 100644
  59078. --- a/fs/proc/nommu.c
  59079. +++ b/fs/proc/nommu.c
  59080. @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
  59081. if (file) {
  59082. seq_pad(m, ' ');
  59083. - seq_path(m, &file->f_path, "");
  59084. + seq_path(m, &file->f_path, "\n\\");
  59085. }
  59086. seq_putc(m, '\n');
  59087. diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
  59088. index 4677bb7..94067cd 100644
  59089. --- a/fs/proc/proc_net.c
  59090. +++ b/fs/proc/proc_net.c
  59091. @@ -23,6 +23,7 @@
  59092. #include <linux/nsproxy.h>
  59093. #include <net/net_namespace.h>
  59094. #include <linux/seq_file.h>
  59095. +#include <linux/grsecurity.h>
  59096. #include "internal.h"
  59097. @@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
  59098. return maybe_get_net(PDE_NET(PDE(inode)));
  59099. }
  59100. +extern const struct seq_operations dev_seq_ops;
  59101. +
  59102. int seq_open_net(struct inode *ino, struct file *f,
  59103. const struct seq_operations *ops, int size)
  59104. {
  59105. @@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
  59106. BUG_ON(size < sizeof(*p));
  59107. + /* only permit access to /proc/net/dev */
  59108. + if (ops != &dev_seq_ops && gr_proc_is_restricted())
  59109. + return -EACCES;
  59110. +
  59111. net = get_proc_net(ino);
  59112. if (net == NULL)
  59113. return -ENXIO;
  59114. @@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
  59115. int err;
  59116. struct net *net;
  59117. + if (gr_proc_is_restricted())
  59118. + return -EACCES;
  59119. +
  59120. err = -ENXIO;
  59121. net = get_proc_net(inode);
  59122. if (net == NULL)
  59123. diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
  59124. index 7129046..6914844 100644
  59125. --- a/fs/proc/proc_sysctl.c
  59126. +++ b/fs/proc/proc_sysctl.c
  59127. @@ -11,13 +11,21 @@
  59128. #include <linux/namei.h>
  59129. #include <linux/mm.h>
  59130. #include <linux/module.h>
  59131. +#include <linux/nsproxy.h>
  59132. +#ifdef CONFIG_GRKERNSEC
  59133. +#include <net/net_namespace.h>
  59134. +#endif
  59135. #include "internal.h"
  59136. +extern int gr_handle_chroot_sysctl(const int op);
  59137. +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
  59138. + const int op);
  59139. +
  59140. static const struct dentry_operations proc_sys_dentry_operations;
  59141. static const struct file_operations proc_sys_file_operations;
  59142. -static const struct inode_operations proc_sys_inode_operations;
  59143. +const struct inode_operations proc_sys_inode_operations;
  59144. static const struct file_operations proc_sys_dir_file_operations;
  59145. -static const struct inode_operations proc_sys_dir_operations;
  59146. +const struct inode_operations proc_sys_dir_operations;
  59147. void proc_sys_poll_notify(struct ctl_table_poll *poll)
  59148. {
  59149. @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
  59150. err = NULL;
  59151. d_set_d_op(dentry, &proc_sys_dentry_operations);
  59152. +
  59153. + gr_handle_proc_create(dentry, inode);
  59154. +
  59155. d_add(dentry, inode);
  59156. out:
  59157. @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
  59158. struct inode *inode = file_inode(filp);
  59159. struct ctl_table_header *head = grab_header(inode);
  59160. struct ctl_table *table = PROC_I(inode)->sysctl_entry;
  59161. + int op = write ? MAY_WRITE : MAY_READ;
  59162. ssize_t error;
  59163. size_t res;
  59164. @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
  59165. * and won't be until we finish.
  59166. */
  59167. error = -EPERM;
  59168. - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
  59169. + if (sysctl_perm(head, table, op))
  59170. goto out;
  59171. /* if that can happen at all, it should be -EINVAL, not -EISDIR */
  59172. @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
  59173. if (!table->proc_handler)
  59174. goto out;
  59175. +#ifdef CONFIG_GRKERNSEC
  59176. + error = -EPERM;
  59177. + if (gr_handle_chroot_sysctl(op))
  59178. + goto out;
  59179. + dget(filp->f_path.dentry);
  59180. + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
  59181. + dput(filp->f_path.dentry);
  59182. + goto out;
  59183. + }
  59184. + dput(filp->f_path.dentry);
  59185. + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
  59186. + goto out;
  59187. + if (write) {
  59188. + if (current->nsproxy->net_ns != table->extra2) {
  59189. + if (!capable(CAP_SYS_ADMIN))
  59190. + goto out;
  59191. + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
  59192. + goto out;
  59193. + }
  59194. +#endif
  59195. +
  59196. /* careful: calling conventions are nasty here */
  59197. res = count;
  59198. error = table->proc_handler(table, write, buf, &res, ppos);
  59199. @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
  59200. return false;
  59201. } else {
  59202. d_set_d_op(child, &proc_sys_dentry_operations);
  59203. +
  59204. + gr_handle_proc_create(child, inode);
  59205. +
  59206. d_add(child, inode);
  59207. }
  59208. } else {
  59209. @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
  59210. if ((*pos)++ < ctx->pos)
  59211. return true;
  59212. + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
  59213. + return 0;
  59214. +
  59215. if (unlikely(S_ISLNK(table->mode)))
  59216. res = proc_sys_link_fill_cache(file, ctx, head, table);
  59217. else
  59218. @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
  59219. if (IS_ERR(head))
  59220. return PTR_ERR(head);
  59221. + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
  59222. + return -ENOENT;
  59223. +
  59224. generic_fillattr(inode, stat);
  59225. if (table)
  59226. stat->mode = (stat->mode & S_IFMT) | table->mode;
  59227. @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
  59228. .llseek = generic_file_llseek,
  59229. };
  59230. -static const struct inode_operations proc_sys_inode_operations = {
  59231. +const struct inode_operations proc_sys_inode_operations = {
  59232. .permission = proc_sys_permission,
  59233. .setattr = proc_sys_setattr,
  59234. .getattr = proc_sys_getattr,
  59235. };
  59236. -static const struct inode_operations proc_sys_dir_operations = {
  59237. +const struct inode_operations proc_sys_dir_operations = {
  59238. .lookup = proc_sys_lookup,
  59239. .permission = proc_sys_permission,
  59240. .setattr = proc_sys_setattr,
  59241. @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
  59242. static struct ctl_dir *new_dir(struct ctl_table_set *set,
  59243. const char *name, int namelen)
  59244. {
  59245. - struct ctl_table *table;
  59246. + ctl_table_no_const *table;
  59247. struct ctl_dir *new;
  59248. struct ctl_node *node;
  59249. char *new_name;
  59250. @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
  59251. return NULL;
  59252. node = (struct ctl_node *)(new + 1);
  59253. - table = (struct ctl_table *)(node + 1);
  59254. + table = (ctl_table_no_const *)(node + 1);
  59255. new_name = (char *)(table + 2);
  59256. memcpy(new_name, name, namelen);
  59257. new_name[namelen] = '\0';
  59258. @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
  59259. static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
  59260. struct ctl_table_root *link_root)
  59261. {
  59262. - struct ctl_table *link_table, *entry, *link;
  59263. + ctl_table_no_const *link_table, *link;
  59264. + struct ctl_table *entry;
  59265. struct ctl_table_header *links;
  59266. struct ctl_node *node;
  59267. char *link_name;
  59268. @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
  59269. return NULL;
  59270. node = (struct ctl_node *)(links + 1);
  59271. - link_table = (struct ctl_table *)(node + nr_entries);
  59272. + link_table = (ctl_table_no_const *)(node + nr_entries);
  59273. link_name = (char *)&link_table[nr_entries + 1];
  59274. for (link = link_table, entry = table; entry->procname; link++, entry++) {
  59275. @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
  59276. struct ctl_table_header ***subheader, struct ctl_table_set *set,
  59277. struct ctl_table *table)
  59278. {
  59279. - struct ctl_table *ctl_table_arg = NULL;
  59280. - struct ctl_table *entry, *files;
  59281. + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
  59282. + struct ctl_table *entry;
  59283. int nr_files = 0;
  59284. int nr_dirs = 0;
  59285. int err = -ENOMEM;
  59286. @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
  59287. nr_files++;
  59288. }
  59289. - files = table;
  59290. /* If there are mixed files and directories we need a new table */
  59291. if (nr_dirs && nr_files) {
  59292. - struct ctl_table *new;
  59293. + ctl_table_no_const *new;
  59294. files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
  59295. GFP_KERNEL);
  59296. if (!files)
  59297. @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
  59298. /* Register everything except a directory full of subdirectories */
  59299. if (nr_files || !nr_dirs) {
  59300. struct ctl_table_header *header;
  59301. - header = __register_sysctl_table(set, path, files);
  59302. + header = __register_sysctl_table(set, path, files ? files : table);
  59303. if (!header) {
  59304. kfree(ctl_table_arg);
  59305. goto out;
  59306. diff --git a/fs/proc/root.c b/fs/proc/root.c
  59307. index 87dbcbe..55e1b4d 100644
  59308. --- a/fs/proc/root.c
  59309. +++ b/fs/proc/root.c
  59310. @@ -186,7 +186,15 @@ void __init proc_root_init(void)
  59311. #ifdef CONFIG_PROC_DEVICETREE
  59312. proc_device_tree_init();
  59313. #endif
  59314. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  59315. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  59316. + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
  59317. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  59318. + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
  59319. +#endif
  59320. +#else
  59321. proc_mkdir("bus", NULL);
  59322. +#endif
  59323. proc_sys_init();
  59324. }
  59325. diff --git a/fs/proc/stat.c b/fs/proc/stat.c
  59326. index 6f599c6..bd00271 100644
  59327. --- a/fs/proc/stat.c
  59328. +++ b/fs/proc/stat.c
  59329. @@ -11,6 +11,7 @@
  59330. #include <linux/irqnr.h>
  59331. #include <asm/cputime.h>
  59332. #include <linux/tick.h>
  59333. +#include <linux/grsecurity.h>
  59334. #ifndef arch_irq_stat_cpu
  59335. #define arch_irq_stat_cpu(cpu) 0
  59336. @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
  59337. u64 sum_softirq = 0;
  59338. unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
  59339. struct timespec boottime;
  59340. + int unrestricted = 1;
  59341. +
  59342. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  59343. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  59344. + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
  59345. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  59346. + && !in_group_p(grsec_proc_gid)
  59347. +#endif
  59348. + )
  59349. + unrestricted = 0;
  59350. +#endif
  59351. +#endif
  59352. user = nice = system = idle = iowait =
  59353. irq = softirq = steal = 0;
  59354. @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
  59355. nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
  59356. system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
  59357. idle += get_idle_time(i);
  59358. - iowait += get_iowait_time(i);
  59359. - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
  59360. - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
  59361. - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
  59362. - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
  59363. - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
  59364. - sum += kstat_cpu_irqs_sum(i);
  59365. - sum += arch_irq_stat_cpu(i);
  59366. + if (unrestricted) {
  59367. + iowait += get_iowait_time(i);
  59368. + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
  59369. + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
  59370. + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
  59371. + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
  59372. + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
  59373. + sum += kstat_cpu_irqs_sum(i);
  59374. + sum += arch_irq_stat_cpu(i);
  59375. + for (j = 0; j < NR_SOFTIRQS; j++) {
  59376. + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
  59377. - for (j = 0; j < NR_SOFTIRQS; j++) {
  59378. - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
  59379. -
  59380. - per_softirq_sums[j] += softirq_stat;
  59381. - sum_softirq += softirq_stat;
  59382. + per_softirq_sums[j] += softirq_stat;
  59383. + sum_softirq += softirq_stat;
  59384. + }
  59385. }
  59386. }
  59387. - sum += arch_irq_stat();
  59388. + if (unrestricted)
  59389. + sum += arch_irq_stat();
  59390. seq_puts(p, "cpu ");
  59391. seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
  59392. @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
  59393. nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
  59394. system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
  59395. idle = get_idle_time(i);
  59396. - iowait = get_iowait_time(i);
  59397. - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
  59398. - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
  59399. - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
  59400. - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
  59401. - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
  59402. + if (unrestricted) {
  59403. + iowait = get_iowait_time(i);
  59404. + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
  59405. + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
  59406. + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
  59407. + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
  59408. + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
  59409. + }
  59410. seq_printf(p, "cpu%d", i);
  59411. seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
  59412. seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
  59413. @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
  59414. /* sum again ? it could be updated? */
  59415. for_each_irq_nr(j)
  59416. - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
  59417. + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
  59418. seq_printf(p,
  59419. "\nctxt %llu\n"
  59420. @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
  59421. "processes %lu\n"
  59422. "procs_running %lu\n"
  59423. "procs_blocked %lu\n",
  59424. - nr_context_switches(),
  59425. + unrestricted ? nr_context_switches() : 0ULL,
  59426. (unsigned long)jif,
  59427. - total_forks,
  59428. - nr_running(),
  59429. - nr_iowait());
  59430. + unrestricted ? total_forks : 0UL,
  59431. + unrestricted ? nr_running() : 0UL,
  59432. + unrestricted ? nr_iowait() : 0UL);
  59433. seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
  59434. diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
  59435. index fb52b54..5fc7c14 100644
  59436. --- a/fs/proc/task_mmu.c
  59437. +++ b/fs/proc/task_mmu.c
  59438. @@ -12,12 +12,19 @@
  59439. #include <linux/swap.h>
  59440. #include <linux/swapops.h>
  59441. #include <linux/mmu_notifier.h>
  59442. +#include <linux/grsecurity.h>
  59443. #include <asm/elf.h>
  59444. #include <asm/uaccess.h>
  59445. #include <asm/tlbflush.h>
  59446. #include "internal.h"
  59447. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59448. +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
  59449. + (_mm->pax_flags & MF_PAX_RANDMMAP || \
  59450. + _mm->pax_flags & MF_PAX_SEGMEXEC))
  59451. +#endif
  59452. +
  59453. void task_mem(struct seq_file *m, struct mm_struct *mm)
  59454. {
  59455. unsigned long data, text, lib, swap;
  59456. @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
  59457. "VmExe:\t%8lu kB\n"
  59458. "VmLib:\t%8lu kB\n"
  59459. "VmPTE:\t%8lu kB\n"
  59460. - "VmSwap:\t%8lu kB\n",
  59461. - hiwater_vm << (PAGE_SHIFT-10),
  59462. + "VmSwap:\t%8lu kB\n"
  59463. +
  59464. +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
  59465. + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
  59466. +#endif
  59467. +
  59468. + ,hiwater_vm << (PAGE_SHIFT-10),
  59469. total_vm << (PAGE_SHIFT-10),
  59470. mm->locked_vm << (PAGE_SHIFT-10),
  59471. mm->pinned_vm << (PAGE_SHIFT-10),
  59472. @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
  59473. mm->stack_vm << (PAGE_SHIFT-10), text, lib,
  59474. (PTRS_PER_PTE * sizeof(pte_t) *
  59475. atomic_long_read(&mm->nr_ptes)) >> 10,
  59476. - swap << (PAGE_SHIFT-10));
  59477. + swap << (PAGE_SHIFT-10)
  59478. +
  59479. +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
  59480. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59481. + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
  59482. + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
  59483. +#else
  59484. + , mm->context.user_cs_base
  59485. + , mm->context.user_cs_limit
  59486. +#endif
  59487. +#endif
  59488. +
  59489. + );
  59490. }
  59491. unsigned long task_vsize(struct mm_struct *mm)
  59492. @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
  59493. pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
  59494. }
  59495. - /* We don't show the stack guard page in /proc/maps */
  59496. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59497. + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
  59498. + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
  59499. +#else
  59500. start = vma->vm_start;
  59501. - if (stack_guard_page_start(vma, start))
  59502. - start += PAGE_SIZE;
  59503. end = vma->vm_end;
  59504. - if (stack_guard_page_end(vma, end))
  59505. - end -= PAGE_SIZE;
  59506. +#endif
  59507. seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
  59508. seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
  59509. @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
  59510. flags & VM_WRITE ? 'w' : '-',
  59511. flags & VM_EXEC ? 'x' : '-',
  59512. flags & VM_MAYSHARE ? 's' : 'p',
  59513. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59514. + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
  59515. +#else
  59516. pgoff,
  59517. +#endif
  59518. MAJOR(dev), MINOR(dev), ino);
  59519. /*
  59520. @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
  59521. */
  59522. if (file) {
  59523. seq_pad(m, ' ');
  59524. - seq_path(m, &file->f_path, "\n");
  59525. + seq_path(m, &file->f_path, "\n\\");
  59526. goto done;
  59527. }
  59528. @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
  59529. * Thread stack in /proc/PID/task/TID/maps or
  59530. * the main process stack.
  59531. */
  59532. - if (!is_pid || (vma->vm_start <= mm->start_stack &&
  59533. - vma->vm_end >= mm->start_stack)) {
  59534. + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
  59535. + (vma->vm_start <= mm->start_stack &&
  59536. + vma->vm_end >= mm->start_stack)) {
  59537. name = "[stack]";
  59538. } else {
  59539. /* Thread stack in /proc/PID/maps */
  59540. @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
  59541. struct proc_maps_private *priv = m->private;
  59542. struct task_struct *task = priv->task;
  59543. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59544. + if (current->exec_id != m->exec_id) {
  59545. + gr_log_badprocpid("maps");
  59546. + return 0;
  59547. + }
  59548. +#endif
  59549. +
  59550. show_map_vma(m, vma, is_pid);
  59551. if (m->count < m->size) /* vma is copied successfully */
  59552. @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
  59553. .private = &mss,
  59554. };
  59555. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59556. + if (current->exec_id != m->exec_id) {
  59557. + gr_log_badprocpid("smaps");
  59558. + return 0;
  59559. + }
  59560. +#endif
  59561. memset(&mss, 0, sizeof mss);
  59562. - mss.vma = vma;
  59563. - /* mmap_sem is held in m_start */
  59564. - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
  59565. - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
  59566. -
  59567. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59568. + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
  59569. +#endif
  59570. + mss.vma = vma;
  59571. + /* mmap_sem is held in m_start */
  59572. + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
  59573. + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
  59574. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59575. + }
  59576. +#endif
  59577. show_map_vma(m, vma, is_pid);
  59578. seq_printf(m,
  59579. @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
  59580. "KernelPageSize: %8lu kB\n"
  59581. "MMUPageSize: %8lu kB\n"
  59582. "Locked: %8lu kB\n",
  59583. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59584. + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
  59585. +#else
  59586. (vma->vm_end - vma->vm_start) >> 10,
  59587. +#endif
  59588. mss.resident >> 10,
  59589. (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
  59590. mss.shared_clean >> 10,
  59591. @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
  59592. char buffer[64];
  59593. int nid;
  59594. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59595. + if (current->exec_id != m->exec_id) {
  59596. + gr_log_badprocpid("numa_maps");
  59597. + return 0;
  59598. + }
  59599. +#endif
  59600. +
  59601. if (!mm)
  59602. return 0;
  59603. @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
  59604. mpol_to_str(buffer, sizeof(buffer), pol);
  59605. mpol_cond_put(pol);
  59606. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59607. + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
  59608. +#else
  59609. seq_printf(m, "%08lx %s", vma->vm_start, buffer);
  59610. +#endif
  59611. if (file) {
  59612. seq_printf(m, " file=");
  59613. - seq_path(m, &file->f_path, "\n\t= ");
  59614. + seq_path(m, &file->f_path, "\n\t\\= ");
  59615. } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
  59616. seq_printf(m, " heap");
  59617. } else {
  59618. diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
  59619. index 678455d..ebd3245 100644
  59620. --- a/fs/proc/task_nommu.c
  59621. +++ b/fs/proc/task_nommu.c
  59622. @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
  59623. else
  59624. bytes += kobjsize(mm);
  59625. - if (current->fs && current->fs->users > 1)
  59626. + if (current->fs && atomic_read(&current->fs->users) > 1)
  59627. sbytes += kobjsize(current->fs);
  59628. else
  59629. bytes += kobjsize(current->fs);
  59630. @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
  59631. if (file) {
  59632. seq_pad(m, ' ');
  59633. - seq_path(m, &file->f_path, "");
  59634. + seq_path(m, &file->f_path, "\n\\");
  59635. } else if (mm) {
  59636. pid_t tid = vm_is_stack(priv->task, vma, is_pid);
  59637. diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
  59638. index 88d4585..c10bfeb 100644
  59639. --- a/fs/proc/vmcore.c
  59640. +++ b/fs/proc/vmcore.c
  59641. @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
  59642. nr_bytes = count;
  59643. /* If pfn is not ram, return zeros for sparse dump files */
  59644. - if (pfn_is_ram(pfn) == 0)
  59645. - memset(buf, 0, nr_bytes);
  59646. - else {
  59647. + if (pfn_is_ram(pfn) == 0) {
  59648. + if (userbuf) {
  59649. + if (clear_user((char __force_user *)buf, nr_bytes))
  59650. + return -EFAULT;
  59651. + } else
  59652. + memset(buf, 0, nr_bytes);
  59653. + } else {
  59654. tmp = copy_oldmem_page(pfn, buf, nr_bytes,
  59655. offset, userbuf);
  59656. if (tmp < 0)
  59657. @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
  59658. static int copy_to(void *target, void *src, size_t size, int userbuf)
  59659. {
  59660. if (userbuf) {
  59661. - if (copy_to_user((char __user *) target, src, size))
  59662. + if (copy_to_user((char __force_user *) target, src, size))
  59663. return -EFAULT;
  59664. } else {
  59665. memcpy(target, src, size);
  59666. @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
  59667. if (*fpos < m->offset + m->size) {
  59668. tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
  59669. start = m->paddr + *fpos - m->offset;
  59670. - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
  59671. + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
  59672. if (tmp < 0)
  59673. return tmp;
  59674. buflen -= tsz;
  59675. @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
  59676. static ssize_t read_vmcore(struct file *file, char __user *buffer,
  59677. size_t buflen, loff_t *fpos)
  59678. {
  59679. - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
  59680. + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
  59681. }
  59682. /*
  59683. diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
  59684. index b00fcc9..e0c6381 100644
  59685. --- a/fs/qnx6/qnx6.h
  59686. +++ b/fs/qnx6/qnx6.h
  59687. @@ -74,7 +74,7 @@ enum {
  59688. BYTESEX_BE,
  59689. };
  59690. -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
  59691. +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
  59692. {
  59693. if (sbi->s_bytesex == BYTESEX_LE)
  59694. return le64_to_cpu((__force __le64)n);
  59695. @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
  59696. return (__force __fs64)cpu_to_be64(n);
  59697. }
  59698. -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
  59699. +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
  59700. {
  59701. if (sbi->s_bytesex == BYTESEX_LE)
  59702. return le32_to_cpu((__force __le32)n);
  59703. diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
  59704. index 72d2917..c917c12 100644
  59705. --- a/fs/quota/netlink.c
  59706. +++ b/fs/quota/netlink.c
  59707. @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
  59708. void quota_send_warning(struct kqid qid, dev_t dev,
  59709. const char warntype)
  59710. {
  59711. - static atomic_t seq;
  59712. + static atomic_unchecked_t seq;
  59713. struct sk_buff *skb;
  59714. void *msg_head;
  59715. int ret;
  59716. @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
  59717. "VFS: Not enough memory to send quota warning.\n");
  59718. return;
  59719. }
  59720. - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
  59721. + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
  59722. &quota_genl_family, 0, QUOTA_NL_C_WARNING);
  59723. if (!msg_head) {
  59724. printk(KERN_ERR
  59725. diff --git a/fs/read_write.c b/fs/read_write.c
  59726. index 28cc9c8..208e4fb 100644
  59727. --- a/fs/read_write.c
  59728. +++ b/fs/read_write.c
  59729. @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
  59730. old_fs = get_fs();
  59731. set_fs(get_ds());
  59732. - p = (__force const char __user *)buf;
  59733. + p = (const char __force_user *)buf;
  59734. if (count > MAX_RW_COUNT)
  59735. count = MAX_RW_COUNT;
  59736. if (file->f_op->write)
  59737. diff --git a/fs/readdir.c b/fs/readdir.c
  59738. index 5b53d99..a6c3049 100644
  59739. --- a/fs/readdir.c
  59740. +++ b/fs/readdir.c
  59741. @@ -17,6 +17,7 @@
  59742. #include <linux/security.h>
  59743. #include <linux/syscalls.h>
  59744. #include <linux/unistd.h>
  59745. +#include <linux/namei.h>
  59746. #include <asm/uaccess.h>
  59747. @@ -69,6 +70,7 @@ struct old_linux_dirent {
  59748. struct readdir_callback {
  59749. struct dir_context ctx;
  59750. struct old_linux_dirent __user * dirent;
  59751. + struct file * file;
  59752. int result;
  59753. };
  59754. @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
  59755. buf->result = -EOVERFLOW;
  59756. return -EOVERFLOW;
  59757. }
  59758. +
  59759. + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
  59760. + return 0;
  59761. +
  59762. buf->result++;
  59763. dirent = buf->dirent;
  59764. if (!access_ok(VERIFY_WRITE, dirent,
  59765. @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
  59766. if (!f.file)
  59767. return -EBADF;
  59768. + buf.file = f.file;
  59769. error = iterate_dir(f.file, &buf.ctx);
  59770. if (buf.result)
  59771. error = buf.result;
  59772. @@ -142,6 +149,7 @@ struct getdents_callback {
  59773. struct dir_context ctx;
  59774. struct linux_dirent __user * current_dir;
  59775. struct linux_dirent __user * previous;
  59776. + struct file * file;
  59777. int count;
  59778. int error;
  59779. };
  59780. @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
  59781. buf->error = -EOVERFLOW;
  59782. return -EOVERFLOW;
  59783. }
  59784. +
  59785. + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
  59786. + return 0;
  59787. +
  59788. dirent = buf->previous;
  59789. if (dirent) {
  59790. if (__put_user(offset, &dirent->d_off))
  59791. @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
  59792. if (!f.file)
  59793. return -EBADF;
  59794. + buf.file = f.file;
  59795. error = iterate_dir(f.file, &buf.ctx);
  59796. if (error >= 0)
  59797. error = buf.error;
  59798. @@ -226,6 +239,7 @@ struct getdents_callback64 {
  59799. struct dir_context ctx;
  59800. struct linux_dirent64 __user * current_dir;
  59801. struct linux_dirent64 __user * previous;
  59802. + struct file *file;
  59803. int count;
  59804. int error;
  59805. };
  59806. @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
  59807. buf->error = -EINVAL; /* only used if we fail.. */
  59808. if (reclen > buf->count)
  59809. return -EINVAL;
  59810. +
  59811. + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
  59812. + return 0;
  59813. +
  59814. dirent = buf->previous;
  59815. if (dirent) {
  59816. if (__put_user(offset, &dirent->d_off))
  59817. @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
  59818. if (!f.file)
  59819. return -EBADF;
  59820. + buf.file = f.file;
  59821. error = iterate_dir(f.file, &buf.ctx);
  59822. if (error >= 0)
  59823. error = buf.error;
  59824. diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
  59825. index 9a3c68c..767933e 100644
  59826. --- a/fs/reiserfs/do_balan.c
  59827. +++ b/fs/reiserfs/do_balan.c
  59828. @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
  59829. return;
  59830. }
  59831. - atomic_inc(&(fs_generation(tb->tb_sb)));
  59832. + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
  59833. do_balance_starts(tb);
  59834. /* balance leaf returns 0 except if combining L R and S into
  59835. diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
  59836. index ee382ef..f4eb6eb5 100644
  59837. --- a/fs/reiserfs/item_ops.c
  59838. +++ b/fs/reiserfs/item_ops.c
  59839. @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
  59840. }
  59841. static struct item_operations errcatch_ops = {
  59842. - errcatch_bytes_number,
  59843. - errcatch_decrement_key,
  59844. - errcatch_is_left_mergeable,
  59845. - errcatch_print_item,
  59846. - errcatch_check_item,
  59847. + .bytes_number = errcatch_bytes_number,
  59848. + .decrement_key = errcatch_decrement_key,
  59849. + .is_left_mergeable = errcatch_is_left_mergeable,
  59850. + .print_item = errcatch_print_item,
  59851. + .check_item = errcatch_check_item,
  59852. - errcatch_create_vi,
  59853. - errcatch_check_left,
  59854. - errcatch_check_right,
  59855. - errcatch_part_size,
  59856. - errcatch_unit_num,
  59857. - errcatch_print_vi
  59858. + .create_vi = errcatch_create_vi,
  59859. + .check_left = errcatch_check_left,
  59860. + .check_right = errcatch_check_right,
  59861. + .part_size = errcatch_part_size,
  59862. + .unit_num = errcatch_unit_num,
  59863. + .print_vi = errcatch_print_vi
  59864. };
  59865. //////////////////////////////////////////////////////////////////////////////
  59866. diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
  59867. index 02b0b7d..c85018b 100644
  59868. --- a/fs/reiserfs/procfs.c
  59869. +++ b/fs/reiserfs/procfs.c
  59870. @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
  59871. "SMALL_TAILS " : "NO_TAILS ",
  59872. replay_only(sb) ? "REPLAY_ONLY " : "",
  59873. convert_reiserfs(sb) ? "CONV " : "",
  59874. - atomic_read(&r->s_generation_counter),
  59875. + atomic_read_unchecked(&r->s_generation_counter),
  59876. SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
  59877. SF(s_do_balance), SF(s_unneeded_left_neighbor),
  59878. SF(s_good_search_by_key_reada), SF(s_bmaps),
  59879. diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
  59880. index 8d06adf..7e1c9f8 100644
  59881. --- a/fs/reiserfs/reiserfs.h
  59882. +++ b/fs/reiserfs/reiserfs.h
  59883. @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
  59884. /* Comment? -Hans */
  59885. wait_queue_head_t s_wait;
  59886. /* To be obsoleted soon by per buffer seals.. -Hans */
  59887. - atomic_t s_generation_counter; // increased by one every time the
  59888. + atomic_unchecked_t s_generation_counter; // increased by one every time the
  59889. // tree gets re-balanced
  59890. unsigned long s_properties; /* File system properties. Currently holds
  59891. on-disk FS format */
  59892. @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
  59893. #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
  59894. #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
  59895. -#define get_generation(s) atomic_read (&fs_generation(s))
  59896. +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
  59897. #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
  59898. #define __fs_changed(gen,s) (gen != get_generation (s))
  59899. #define fs_changed(gen,s) \
  59900. diff --git a/fs/select.c b/fs/select.c
  59901. index 467bb1c..cf9d65a 100644
  59902. --- a/fs/select.c
  59903. +++ b/fs/select.c
  59904. @@ -20,6 +20,7 @@
  59905. #include <linux/export.h>
  59906. #include <linux/slab.h>
  59907. #include <linux/poll.h>
  59908. +#include <linux/security.h>
  59909. #include <linux/personality.h> /* for STICKY_TIMEOUTS */
  59910. #include <linux/file.h>
  59911. #include <linux/fdtable.h>
  59912. @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
  59913. struct poll_list *walk = head;
  59914. unsigned long todo = nfds;
  59915. + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
  59916. if (nfds > rlimit(RLIMIT_NOFILE))
  59917. return -EINVAL;
  59918. diff --git a/fs/seq_file.c b/fs/seq_file.c
  59919. index 1d641bb..c2f4743 100644
  59920. --- a/fs/seq_file.c
  59921. +++ b/fs/seq_file.c
  59922. @@ -10,6 +10,8 @@
  59923. #include <linux/seq_file.h>
  59924. #include <linux/slab.h>
  59925. #include <linux/cred.h>
  59926. +#include <linux/sched.h>
  59927. +#include <linux/grsecurity.h>
  59928. #include <asm/uaccess.h>
  59929. #include <asm/page.h>
  59930. @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
  59931. #ifdef CONFIG_USER_NS
  59932. p->user_ns = file->f_cred->user_ns;
  59933. #endif
  59934. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  59935. + p->exec_id = current->exec_id;
  59936. +#endif
  59937. /*
  59938. * Wrappers around seq_open(e.g. swaps_open) need to be
  59939. @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
  59940. }
  59941. EXPORT_SYMBOL(seq_open);
  59942. +
  59943. +int seq_open_restrict(struct file *file, const struct seq_operations *op)
  59944. +{
  59945. + if (gr_proc_is_restricted())
  59946. + return -EACCES;
  59947. +
  59948. + return seq_open(file, op);
  59949. +}
  59950. +EXPORT_SYMBOL(seq_open_restrict);
  59951. +
  59952. static int traverse(struct seq_file *m, loff_t offset)
  59953. {
  59954. loff_t pos = 0, index;
  59955. @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
  59956. return 0;
  59957. }
  59958. if (!m->buf) {
  59959. - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
  59960. + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
  59961. if (!m->buf)
  59962. return -ENOMEM;
  59963. }
  59964. @@ -137,7 +152,7 @@ Eoverflow:
  59965. m->op->stop(m, p);
  59966. kfree(m->buf);
  59967. m->count = 0;
  59968. - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
  59969. + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
  59970. return !m->buf ? -ENOMEM : -EAGAIN;
  59971. }
  59972. @@ -153,7 +168,7 @@ Eoverflow:
  59973. ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
  59974. {
  59975. struct seq_file *m = file->private_data;
  59976. - size_t copied = 0;
  59977. + ssize_t copied = 0;
  59978. loff_t pos;
  59979. size_t n;
  59980. void *p;
  59981. @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
  59982. /* grab buffer if we didn't have one */
  59983. if (!m->buf) {
  59984. - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
  59985. + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
  59986. if (!m->buf)
  59987. goto Enomem;
  59988. }
  59989. @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
  59990. m->op->stop(m, p);
  59991. kfree(m->buf);
  59992. m->count = 0;
  59993. - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
  59994. + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
  59995. if (!m->buf)
  59996. goto Enomem;
  59997. m->version = 0;
  59998. @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
  59999. int single_open(struct file *file, int (*show)(struct seq_file *, void *),
  60000. void *data)
  60001. {
  60002. - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
  60003. + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
  60004. int res = -ENOMEM;
  60005. if (op) {
  60006. @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
  60007. }
  60008. EXPORT_SYMBOL(single_open_size);
  60009. +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
  60010. + void *data)
  60011. +{
  60012. + if (gr_proc_is_restricted())
  60013. + return -EACCES;
  60014. +
  60015. + return single_open(file, show, data);
  60016. +}
  60017. +EXPORT_SYMBOL(single_open_restrict);
  60018. +
  60019. +
  60020. int single_release(struct inode *inode, struct file *file)
  60021. {
  60022. const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
  60023. diff --git a/fs/splice.c b/fs/splice.c
  60024. index 12028fa..a6f2619 100644
  60025. --- a/fs/splice.c
  60026. +++ b/fs/splice.c
  60027. @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
  60028. pipe_lock(pipe);
  60029. for (;;) {
  60030. - if (!pipe->readers) {
  60031. + if (!atomic_read(&pipe->readers)) {
  60032. send_sig(SIGPIPE, current, 0);
  60033. if (!ret)
  60034. ret = -EPIPE;
  60035. @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
  60036. page_nr++;
  60037. ret += buf->len;
  60038. - if (pipe->files)
  60039. + if (atomic_read(&pipe->files))
  60040. do_wakeup = 1;
  60041. if (!--spd->nr_pages)
  60042. @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
  60043. do_wakeup = 0;
  60044. }
  60045. - pipe->waiting_writers++;
  60046. + atomic_inc(&pipe->waiting_writers);
  60047. pipe_wait(pipe);
  60048. - pipe->waiting_writers--;
  60049. + atomic_dec(&pipe->waiting_writers);
  60050. }
  60051. pipe_unlock(pipe);
  60052. @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
  60053. old_fs = get_fs();
  60054. set_fs(get_ds());
  60055. /* The cast to a user pointer is valid due to the set_fs() */
  60056. - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
  60057. + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
  60058. set_fs(old_fs);
  60059. return res;
  60060. @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
  60061. old_fs = get_fs();
  60062. set_fs(get_ds());
  60063. /* The cast to a user pointer is valid due to the set_fs() */
  60064. - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
  60065. + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
  60066. set_fs(old_fs);
  60067. return res;
  60068. @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
  60069. goto err;
  60070. this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
  60071. - vec[i].iov_base = (void __user *) page_address(page);
  60072. + vec[i].iov_base = (void __force_user *) page_address(page);
  60073. vec[i].iov_len = this_len;
  60074. spd.pages[i] = page;
  60075. spd.nr_pages++;
  60076. @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
  60077. ops->release(pipe, buf);
  60078. pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
  60079. pipe->nrbufs--;
  60080. - if (pipe->files)
  60081. + if (atomic_read(&pipe->files))
  60082. sd->need_wakeup = true;
  60083. }
  60084. @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
  60085. int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
  60086. {
  60087. while (!pipe->nrbufs) {
  60088. - if (!pipe->writers)
  60089. + if (!atomic_read(&pipe->writers))
  60090. return 0;
  60091. - if (!pipe->waiting_writers && sd->num_spliced)
  60092. + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
  60093. return 0;
  60094. if (sd->flags & SPLICE_F_NONBLOCK)
  60095. @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
  60096. * out of the pipe right after the splice_to_pipe(). So set
  60097. * PIPE_READERS appropriately.
  60098. */
  60099. - pipe->readers = 1;
  60100. + atomic_set(&pipe->readers, 1);
  60101. current->splice_pipe = pipe;
  60102. }
  60103. @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
  60104. partial[buffers].offset = off;
  60105. partial[buffers].len = plen;
  60106. + partial[buffers].private = 0;
  60107. off = 0;
  60108. len -= plen;
  60109. @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
  60110. ret = -ERESTARTSYS;
  60111. break;
  60112. }
  60113. - if (!pipe->writers)
  60114. + if (!atomic_read(&pipe->writers))
  60115. break;
  60116. - if (!pipe->waiting_writers) {
  60117. + if (!atomic_read(&pipe->waiting_writers)) {
  60118. if (flags & SPLICE_F_NONBLOCK) {
  60119. ret = -EAGAIN;
  60120. break;
  60121. @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
  60122. pipe_lock(pipe);
  60123. while (pipe->nrbufs >= pipe->buffers) {
  60124. - if (!pipe->readers) {
  60125. + if (!atomic_read(&pipe->readers)) {
  60126. send_sig(SIGPIPE, current, 0);
  60127. ret = -EPIPE;
  60128. break;
  60129. @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
  60130. ret = -ERESTARTSYS;
  60131. break;
  60132. }
  60133. - pipe->waiting_writers++;
  60134. + atomic_inc(&pipe->waiting_writers);
  60135. pipe_wait(pipe);
  60136. - pipe->waiting_writers--;
  60137. + atomic_dec(&pipe->waiting_writers);
  60138. }
  60139. pipe_unlock(pipe);
  60140. @@ -1880,14 +1881,14 @@ retry:
  60141. pipe_double_lock(ipipe, opipe);
  60142. do {
  60143. - if (!opipe->readers) {
  60144. + if (!atomic_read(&opipe->readers)) {
  60145. send_sig(SIGPIPE, current, 0);
  60146. if (!ret)
  60147. ret = -EPIPE;
  60148. break;
  60149. }
  60150. - if (!ipipe->nrbufs && !ipipe->writers)
  60151. + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
  60152. break;
  60153. /*
  60154. @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
  60155. pipe_double_lock(ipipe, opipe);
  60156. do {
  60157. - if (!opipe->readers) {
  60158. + if (!atomic_read(&opipe->readers)) {
  60159. send_sig(SIGPIPE, current, 0);
  60160. if (!ret)
  60161. ret = -EPIPE;
  60162. @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
  60163. * return EAGAIN if we have the potential of some data in the
  60164. * future, otherwise just return 0
  60165. */
  60166. - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
  60167. + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
  60168. ret = -EAGAIN;
  60169. pipe_unlock(ipipe);
  60170. diff --git a/fs/stat.c b/fs/stat.c
  60171. index ae0c3ce..9ee641c 100644
  60172. --- a/fs/stat.c
  60173. +++ b/fs/stat.c
  60174. @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
  60175. stat->gid = inode->i_gid;
  60176. stat->rdev = inode->i_rdev;
  60177. stat->size = i_size_read(inode);
  60178. - stat->atime = inode->i_atime;
  60179. - stat->mtime = inode->i_mtime;
  60180. + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
  60181. + stat->atime = inode->i_ctime;
  60182. + stat->mtime = inode->i_ctime;
  60183. + } else {
  60184. + stat->atime = inode->i_atime;
  60185. + stat->mtime = inode->i_mtime;
  60186. + }
  60187. stat->ctime = inode->i_ctime;
  60188. stat->blksize = (1 << inode->i_blkbits);
  60189. stat->blocks = inode->i_blocks;
  60190. @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
  60191. int vfs_getattr_nosec(struct path *path, struct kstat *stat)
  60192. {
  60193. struct inode *inode = path->dentry->d_inode;
  60194. + int retval;
  60195. - if (inode->i_op->getattr)
  60196. - return inode->i_op->getattr(path->mnt, path->dentry, stat);
  60197. + if (inode->i_op->getattr) {
  60198. + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
  60199. + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
  60200. + stat->atime = stat->ctime;
  60201. + stat->mtime = stat->ctime;
  60202. + }
  60203. + return retval;
  60204. + }
  60205. generic_fillattr(inode, stat);
  60206. return 0;
  60207. diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
  60208. index ee0d761..b346c58 100644
  60209. --- a/fs/sysfs/dir.c
  60210. +++ b/fs/sysfs/dir.c
  60211. @@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
  60212. int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
  60213. {
  60214. struct kernfs_node *parent, *kn;
  60215. + const char *name;
  60216. + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
  60217. +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
  60218. + const char *parent_name;
  60219. +#endif
  60220. BUG_ON(!kobj);
  60221. + name = kobject_name(kobj);
  60222. +
  60223. if (kobj->parent)
  60224. parent = kobj->parent->sd;
  60225. else
  60226. @@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
  60227. if (!parent)
  60228. return -ENOENT;
  60229. - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
  60230. - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
  60231. +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
  60232. + parent_name = parent->name;
  60233. + mode = S_IRWXU;
  60234. +
  60235. + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
  60236. + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
  60237. + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
  60238. + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
  60239. + mode = S_IRWXU | S_IRUGO | S_IXUGO;
  60240. +#endif
  60241. +
  60242. + kn = kernfs_create_dir_ns(parent, name,
  60243. + mode, kobj, ns);
  60244. if (IS_ERR(kn)) {
  60245. if (PTR_ERR(kn) == -EEXIST)
  60246. - sysfs_warn_dup(parent, kobject_name(kobj));
  60247. + sysfs_warn_dup(parent, name);
  60248. return PTR_ERR(kn);
  60249. }
  60250. diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
  60251. index 69d4889..a810bd4 100644
  60252. --- a/fs/sysv/sysv.h
  60253. +++ b/fs/sysv/sysv.h
  60254. @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
  60255. #endif
  60256. }
  60257. -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
  60258. +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
  60259. {
  60260. if (sbi->s_bytesex == BYTESEX_PDP)
  60261. return PDP_swab((__force __u32)n);
  60262. diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
  60263. index e18b988..f1d4ad0f 100644
  60264. --- a/fs/ubifs/io.c
  60265. +++ b/fs/ubifs/io.c
  60266. @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
  60267. return err;
  60268. }
  60269. -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
  60270. +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
  60271. {
  60272. int err;
  60273. diff --git a/fs/udf/misc.c b/fs/udf/misc.c
  60274. index c175b4d..8f36a16 100644
  60275. --- a/fs/udf/misc.c
  60276. +++ b/fs/udf/misc.c
  60277. @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
  60278. u8 udf_tag_checksum(const struct tag *t)
  60279. {
  60280. - u8 *data = (u8 *)t;
  60281. + const u8 *data = (const u8 *)t;
  60282. u8 checksum = 0;
  60283. int i;
  60284. for (i = 0; i < sizeof(struct tag); ++i)
  60285. diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
  60286. index 8d974c4..b82f6ec 100644
  60287. --- a/fs/ufs/swab.h
  60288. +++ b/fs/ufs/swab.h
  60289. @@ -22,7 +22,7 @@ enum {
  60290. BYTESEX_BE
  60291. };
  60292. -static inline u64
  60293. +static inline u64 __intentional_overflow(-1)
  60294. fs64_to_cpu(struct super_block *sbp, __fs64 n)
  60295. {
  60296. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  60297. @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
  60298. return (__force __fs64)cpu_to_be64(n);
  60299. }
  60300. -static inline u32
  60301. +static inline u32 __intentional_overflow(-1)
  60302. fs32_to_cpu(struct super_block *sbp, __fs32 n)
  60303. {
  60304. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  60305. diff --git a/fs/utimes.c b/fs/utimes.c
  60306. index aa138d6..5f3a811 100644
  60307. --- a/fs/utimes.c
  60308. +++ b/fs/utimes.c
  60309. @@ -1,6 +1,7 @@
  60310. #include <linux/compiler.h>
  60311. #include <linux/file.h>
  60312. #include <linux/fs.h>
  60313. +#include <linux/security.h>
  60314. #include <linux/linkage.h>
  60315. #include <linux/mount.h>
  60316. #include <linux/namei.h>
  60317. @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
  60318. }
  60319. }
  60320. retry_deleg:
  60321. +
  60322. + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
  60323. + error = -EACCES;
  60324. + goto mnt_drop_write_and_out;
  60325. + }
  60326. +
  60327. mutex_lock(&inode->i_mutex);
  60328. error = notify_change(path->dentry, &newattrs, &delegated_inode);
  60329. mutex_unlock(&inode->i_mutex);
  60330. diff --git a/fs/xattr.c b/fs/xattr.c
  60331. index 3377dff..f394815 100644
  60332. --- a/fs/xattr.c
  60333. +++ b/fs/xattr.c
  60334. @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
  60335. return rc;
  60336. }
  60337. +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
  60338. +ssize_t
  60339. +pax_getxattr(struct dentry *dentry, void *value, size_t size)
  60340. +{
  60341. + struct inode *inode = dentry->d_inode;
  60342. + ssize_t error;
  60343. +
  60344. + error = inode_permission(inode, MAY_EXEC);
  60345. + if (error)
  60346. + return error;
  60347. +
  60348. + if (inode->i_op->getxattr)
  60349. + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
  60350. + else
  60351. + error = -EOPNOTSUPP;
  60352. +
  60353. + return error;
  60354. +}
  60355. +EXPORT_SYMBOL(pax_getxattr);
  60356. +#endif
  60357. +
  60358. ssize_t
  60359. vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
  60360. {
  60361. @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
  60362. * Extended attribute SET operations
  60363. */
  60364. static long
  60365. -setxattr(struct dentry *d, const char __user *name, const void __user *value,
  60366. +setxattr(struct path *path, const char __user *name, const void __user *value,
  60367. size_t size, int flags)
  60368. {
  60369. int error;
  60370. @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
  60371. posix_acl_fix_xattr_from_user(kvalue, size);
  60372. }
  60373. - error = vfs_setxattr(d, kname, kvalue, size, flags);
  60374. + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
  60375. + error = -EACCES;
  60376. + goto out;
  60377. + }
  60378. +
  60379. + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
  60380. out:
  60381. if (vvalue)
  60382. vfree(vvalue);
  60383. @@ -377,7 +403,7 @@ retry:
  60384. return error;
  60385. error = mnt_want_write(path.mnt);
  60386. if (!error) {
  60387. - error = setxattr(path.dentry, name, value, size, flags);
  60388. + error = setxattr(&path, name, value, size, flags);
  60389. mnt_drop_write(path.mnt);
  60390. }
  60391. path_put(&path);
  60392. @@ -401,7 +427,7 @@ retry:
  60393. return error;
  60394. error = mnt_want_write(path.mnt);
  60395. if (!error) {
  60396. - error = setxattr(path.dentry, name, value, size, flags);
  60397. + error = setxattr(&path, name, value, size, flags);
  60398. mnt_drop_write(path.mnt);
  60399. }
  60400. path_put(&path);
  60401. @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
  60402. const void __user *,value, size_t, size, int, flags)
  60403. {
  60404. struct fd f = fdget(fd);
  60405. - struct dentry *dentry;
  60406. int error = -EBADF;
  60407. if (!f.file)
  60408. return error;
  60409. - dentry = f.file->f_path.dentry;
  60410. - audit_inode(NULL, dentry, 0);
  60411. + audit_inode(NULL, f.file->f_path.dentry, 0);
  60412. error = mnt_want_write_file(f.file);
  60413. if (!error) {
  60414. - error = setxattr(dentry, name, value, size, flags);
  60415. + error = setxattr(&f.file->f_path, name, value, size, flags);
  60416. mnt_drop_write_file(f.file);
  60417. }
  60418. fdput(f);
  60419. @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
  60420. * Extended attribute REMOVE operations
  60421. */
  60422. static long
  60423. -removexattr(struct dentry *d, const char __user *name)
  60424. +removexattr(struct path *path, const char __user *name)
  60425. {
  60426. int error;
  60427. char kname[XATTR_NAME_MAX + 1];
  60428. @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
  60429. if (error < 0)
  60430. return error;
  60431. - return vfs_removexattr(d, kname);
  60432. + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
  60433. + return -EACCES;
  60434. +
  60435. + return vfs_removexattr(path->dentry, kname);
  60436. }
  60437. SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
  60438. @@ -652,7 +679,7 @@ retry:
  60439. return error;
  60440. error = mnt_want_write(path.mnt);
  60441. if (!error) {
  60442. - error = removexattr(path.dentry, name);
  60443. + error = removexattr(&path, name);
  60444. mnt_drop_write(path.mnt);
  60445. }
  60446. path_put(&path);
  60447. @@ -675,7 +702,7 @@ retry:
  60448. return error;
  60449. error = mnt_want_write(path.mnt);
  60450. if (!error) {
  60451. - error = removexattr(path.dentry, name);
  60452. + error = removexattr(&path, name);
  60453. mnt_drop_write(path.mnt);
  60454. }
  60455. path_put(&path);
  60456. @@ -689,16 +716,16 @@ retry:
  60457. SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
  60458. {
  60459. struct fd f = fdget(fd);
  60460. - struct dentry *dentry;
  60461. + struct path *path;
  60462. int error = -EBADF;
  60463. if (!f.file)
  60464. return error;
  60465. - dentry = f.file->f_path.dentry;
  60466. - audit_inode(NULL, dentry, 0);
  60467. + path = &f.file->f_path;
  60468. + audit_inode(NULL, path->dentry, 0);
  60469. error = mnt_want_write_file(f.file);
  60470. if (!error) {
  60471. - error = removexattr(dentry, name);
  60472. + error = removexattr(path, name);
  60473. mnt_drop_write_file(f.file);
  60474. }
  60475. fdput(f);
  60476. diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
  60477. index 152543c..d80c361 100644
  60478. --- a/fs/xfs/xfs_bmap.c
  60479. +++ b/fs/xfs/xfs_bmap.c
  60480. @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
  60481. #else
  60482. #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
  60483. -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
  60484. +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
  60485. #endif /* DEBUG */
  60486. /*
  60487. diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
  60488. index aead369..0dfecfd 100644
  60489. --- a/fs/xfs/xfs_dir2_readdir.c
  60490. +++ b/fs/xfs/xfs_dir2_readdir.c
  60491. @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
  60492. ino = dp->d_ops->sf_get_ino(sfp, sfep);
  60493. filetype = dp->d_ops->sf_get_ftype(sfep);
  60494. ctx->pos = off & 0x7fffffff;
  60495. - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
  60496. + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
  60497. + char name[sfep->namelen];
  60498. + memcpy(name, sfep->name, sfep->namelen);
  60499. + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
  60500. + return 0;
  60501. + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
  60502. xfs_dir3_get_dtype(mp, filetype)))
  60503. return 0;
  60504. sfep = dp->d_ops->sf_nextentry(sfp, sfep);
  60505. diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
  60506. index bcfe612..aa399c0 100644
  60507. --- a/fs/xfs/xfs_ioctl.c
  60508. +++ b/fs/xfs/xfs_ioctl.c
  60509. @@ -122,7 +122,7 @@ xfs_find_handle(
  60510. }
  60511. error = -EFAULT;
  60512. - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
  60513. + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
  60514. copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
  60515. goto out_put;
  60516. diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
  60517. new file mode 100644
  60518. index 0000000..3abaf02
  60519. --- /dev/null
  60520. +++ b/grsecurity/Kconfig
  60521. @@ -0,0 +1,1161 @@
  60522. +#
  60523. +# grecurity configuration
  60524. +#
  60525. +menu "Memory Protections"
  60526. +depends on GRKERNSEC
  60527. +
  60528. +config GRKERNSEC_KMEM
  60529. + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
  60530. + default y if GRKERNSEC_CONFIG_AUTO
  60531. + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
  60532. + help
  60533. + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
  60534. + be written to or read from to modify or leak the contents of the running
  60535. + kernel. /dev/port will also not be allowed to be opened, writing to
  60536. + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
  60537. + If you have module support disabled, enabling this will close up several
  60538. + ways that are currently used to insert malicious code into the running
  60539. + kernel.
  60540. +
  60541. + Even with this feature enabled, we still highly recommend that
  60542. + you use the RBAC system, as it is still possible for an attacker to
  60543. + modify the running kernel through other more obscure methods.
  60544. +
  60545. + It is highly recommended that you say Y here if you meet all the
  60546. + conditions above.
  60547. +
  60548. +config GRKERNSEC_VM86
  60549. + bool "Restrict VM86 mode"
  60550. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
  60551. + depends on X86_32
  60552. +
  60553. + help
  60554. + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
  60555. + make use of a special execution mode on 32bit x86 processors called
  60556. + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
  60557. + video cards and will still work with this option enabled. The purpose
  60558. + of the option is to prevent exploitation of emulation errors in
  60559. + virtualization of vm86 mode like the one discovered in VMWare in 2009.
  60560. + Nearly all users should be able to enable this option.
  60561. +
  60562. +config GRKERNSEC_IO
  60563. + bool "Disable privileged I/O"
  60564. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
  60565. + depends on X86
  60566. + select RTC_CLASS
  60567. + select RTC_INTF_DEV
  60568. + select RTC_DRV_CMOS
  60569. +
  60570. + help
  60571. + If you say Y here, all ioperm and iopl calls will return an error.
  60572. + Ioperm and iopl can be used to modify the running kernel.
  60573. + Unfortunately, some programs need this access to operate properly,
  60574. + the most notable of which are XFree86 and hwclock. hwclock can be
  60575. + remedied by having RTC support in the kernel, so real-time
  60576. + clock support is enabled if this option is enabled, to ensure
  60577. + that hwclock operates correctly. If hwclock still does not work,
  60578. + either update udev or symlink /dev/rtc to /dev/rtc0.
  60579. +
  60580. + If you're using XFree86 or a version of Xorg from 2012 or earlier,
  60581. + you may not be able to boot into a graphical environment with this
  60582. + option enabled. In this case, you should use the RBAC system instead.
  60583. +
  60584. +config GRKERNSEC_JIT_HARDEN
  60585. + bool "Harden BPF JIT against spray attacks"
  60586. + default y if GRKERNSEC_CONFIG_AUTO
  60587. + depends on BPF_JIT && X86
  60588. + help
  60589. + If you say Y here, the native code generated by the kernel's Berkeley
  60590. + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
  60591. + attacks that attempt to fit attacker-beneficial instructions in
  60592. + 32bit immediate fields of JIT-generated native instructions. The
  60593. + attacker will generally aim to cause an unintended instruction sequence
  60594. + of JIT-generated native code to execute by jumping into the middle of
  60595. + a generated instruction. This feature effectively randomizes the 32bit
  60596. + immediate constants present in the generated code to thwart such attacks.
  60597. +
  60598. + If you're using KERNEXEC, it's recommended that you enable this option
  60599. + to supplement the hardening of the kernel.
  60600. +
  60601. +config GRKERNSEC_PERF_HARDEN
  60602. + bool "Disable unprivileged PERF_EVENTS usage by default"
  60603. + default y if GRKERNSEC_CONFIG_AUTO
  60604. + depends on PERF_EVENTS
  60605. + help
  60606. + If you say Y here, the range of acceptable values for the
  60607. + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
  60608. + default to a new value: 3. When the sysctl is set to this value, no
  60609. + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
  60610. +
  60611. + Though PERF_EVENTS can be used legitimately for performance monitoring
  60612. + and low-level application profiling, it is forced on regardless of
  60613. + configuration, has been at fault for several vulnerabilities, and
  60614. + creates new opportunities for side channels and other information leaks.
  60615. +
  60616. + This feature puts PERF_EVENTS into a secure default state and permits
  60617. + the administrator to change out of it temporarily if unprivileged
  60618. + application profiling is needed.
  60619. +
  60620. +config GRKERNSEC_RAND_THREADSTACK
  60621. + bool "Insert random gaps between thread stacks"
  60622. + default y if GRKERNSEC_CONFIG_AUTO
  60623. + depends on PAX_RANDMMAP && !PPC
  60624. + help
  60625. + If you say Y here, a random-sized gap will be enforced between allocated
  60626. + thread stacks. Glibc's NPTL and other threading libraries that
  60627. + pass MAP_STACK to the kernel for thread stack allocation are supported.
  60628. + The implementation currently provides 8 bits of entropy for the gap.
  60629. +
  60630. + Many distributions do not compile threaded remote services with the
  60631. + -fstack-check argument to GCC, causing the variable-sized stack-based
  60632. + allocator, alloca(), to not probe the stack on allocation. This
  60633. + permits an unbounded alloca() to skip over any guard page and potentially
  60634. + modify another thread's stack reliably. An enforced random gap
  60635. + reduces the reliability of such an attack and increases the chance
  60636. + that such a read/write to another thread's stack instead lands in
  60637. + an unmapped area, causing a crash and triggering grsecurity's
  60638. + anti-bruteforcing logic.
  60639. +
  60640. +config GRKERNSEC_PROC_MEMMAP
  60641. + bool "Harden ASLR against information leaks and entropy reduction"
  60642. + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
  60643. + depends on PAX_NOEXEC || PAX_ASLR
  60644. + help
  60645. + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
  60646. + give no information about the addresses of its mappings if
  60647. + PaX features that rely on random addresses are enabled on the task.
  60648. + In addition to sanitizing this information and disabling other
  60649. + dangerous sources of information, this option causes reads of sensitive
  60650. + /proc/<pid> entries where the file descriptor was opened in a different
  60651. + task than the one performing the read. Such attempts are logged.
  60652. + This option also limits argv/env strings for suid/sgid binaries
  60653. + to 512KB to prevent a complete exhaustion of the stack entropy provided
  60654. + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
  60655. + binaries to prevent alternative mmap layouts from being abused.
  60656. +
  60657. + If you use PaX it is essential that you say Y here as it closes up
  60658. + several holes that make full ASLR useless locally.
  60659. +
  60660. +config GRKERNSEC_BRUTE
  60661. + bool "Deter exploit bruteforcing"
  60662. + default y if GRKERNSEC_CONFIG_AUTO
  60663. + help
  60664. + If you say Y here, attempts to bruteforce exploits against forking
  60665. + daemons such as apache or sshd, as well as against suid/sgid binaries
  60666. + will be deterred. When a child of a forking daemon is killed by PaX
  60667. + or crashes due to an illegal instruction or other suspicious signal,
  60668. + the parent process will be delayed 30 seconds upon every subsequent
  60669. + fork until the administrator is able to assess the situation and
  60670. + restart the daemon.
  60671. + In the suid/sgid case, the attempt is logged, the user has all their
  60672. + existing instances of the suid/sgid binary terminated and will
  60673. + be unable to execute any suid/sgid binaries for 15 minutes.
  60674. +
  60675. + It is recommended that you also enable signal logging in the auditing
  60676. + section so that logs are generated when a process triggers a suspicious
  60677. + signal.
  60678. + If the sysctl option is enabled, a sysctl option with name
  60679. + "deter_bruteforce" is created.
  60680. +
  60681. +config GRKERNSEC_MODHARDEN
  60682. + bool "Harden module auto-loading"
  60683. + default y if GRKERNSEC_CONFIG_AUTO
  60684. + depends on MODULES
  60685. + help
  60686. + If you say Y here, module auto-loading in response to use of some
  60687. + feature implemented by an unloaded module will be restricted to
  60688. + root users. Enabling this option helps defend against attacks
  60689. + by unprivileged users who abuse the auto-loading behavior to
  60690. + cause a vulnerable module to load that is then exploited.
  60691. +
  60692. + If this option prevents a legitimate use of auto-loading for a
  60693. + non-root user, the administrator can execute modprobe manually
  60694. + with the exact name of the module mentioned in the alert log.
  60695. + Alternatively, the administrator can add the module to the list
  60696. + of modules loaded at boot by modifying init scripts.
  60697. +
  60698. + Modification of init scripts will most likely be needed on
  60699. + Ubuntu servers with encrypted home directory support enabled,
  60700. + as the first non-root user logging in will cause the ecb(aes),
  60701. + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
  60702. +
  60703. +config GRKERNSEC_HIDESYM
  60704. + bool "Hide kernel symbols"
  60705. + default y if GRKERNSEC_CONFIG_AUTO
  60706. + select PAX_USERCOPY_SLABS
  60707. + help
  60708. + If you say Y here, getting information on loaded modules, and
  60709. + displaying all kernel symbols through a syscall will be restricted
  60710. + to users with CAP_SYS_MODULE. For software compatibility reasons,
  60711. + /proc/kallsyms will be restricted to the root user. The RBAC
  60712. + system can hide that entry even from root.
  60713. +
  60714. + This option also prevents leaking of kernel addresses through
  60715. + several /proc entries.
  60716. +
  60717. + Note that this option is only effective provided the following
  60718. + conditions are met:
  60719. + 1) The kernel using grsecurity is not precompiled by some distribution
  60720. + 2) You have also enabled GRKERNSEC_DMESG
  60721. + 3) You are using the RBAC system and hiding other files such as your
  60722. + kernel image and System.map. Alternatively, enabling this option
  60723. + causes the permissions on /boot, /lib/modules, and the kernel
  60724. + source directory to change at compile time to prevent
  60725. + reading by non-root users.
  60726. + If the above conditions are met, this option will aid in providing a
  60727. + useful protection against local kernel exploitation of overflows
  60728. + and arbitrary read/write vulnerabilities.
  60729. +
  60730. + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
  60731. + in addition to this feature.
  60732. +
  60733. +config GRKERNSEC_RANDSTRUCT
  60734. + bool "Randomize layout of sensitive kernel structures"
  60735. + default y if GRKERNSEC_CONFIG_AUTO
  60736. + select GRKERNSEC_HIDESYM
  60737. + select MODVERSIONS if MODULES
  60738. + help
  60739. + If you say Y here, the layouts of a number of sensitive kernel
  60740. + structures (task, fs, cred, etc) and all structures composed entirely
  60741. + of function pointers (aka "ops" structs) will be randomized at compile-time.
  60742. + This can introduce the requirement of an additional infoleak
  60743. + vulnerability for exploits targeting these structure types.
  60744. +
  60745. + Enabling this feature will introduce some performance impact, slightly
  60746. + increase memory usage, and prevent the use of forensic tools like
  60747. + Volatility against the system (unless the kernel source tree isn't
  60748. + cleaned after kernel installation).
  60749. +
  60750. + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
  60751. + It remains after a make clean to allow for external modules to be compiled
  60752. + with the existing seed and will be removed by a make mrproper or
  60753. + make distclean.
  60754. +
  60755. + Note that the implementation requires gcc 4.6.4. or newer. You may need
  60756. + to install the supporting headers explicitly in addition to the normal
  60757. + gcc package.
  60758. +
  60759. +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
  60760. + bool "Use cacheline-aware structure randomization"
  60761. + depends on GRKERNSEC_RANDSTRUCT
  60762. + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
  60763. + help
  60764. + If you say Y here, the RANDSTRUCT randomization will make a best effort
  60765. + at restricting randomization to cacheline-sized groups of elements. It
  60766. + will further not randomize bitfields in structures. This reduces the
  60767. + performance hit of RANDSTRUCT at the cost of weakened randomization.
  60768. +
  60769. +config GRKERNSEC_KERN_LOCKOUT
  60770. + bool "Active kernel exploit response"
  60771. + default y if GRKERNSEC_CONFIG_AUTO
  60772. + depends on X86 || ARM || PPC || SPARC
  60773. + help
  60774. + If you say Y here, when a PaX alert is triggered due to suspicious
  60775. + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
  60776. + or an OOPS occurs due to bad memory accesses, instead of just
  60777. + terminating the offending process (and potentially allowing
  60778. + a subsequent exploit from the same user), we will take one of two
  60779. + actions:
  60780. + If the user was root, we will panic the system
  60781. + If the user was non-root, we will log the attempt, terminate
  60782. + all processes owned by the user, then prevent them from creating
  60783. + any new processes until the system is restarted
  60784. + This deters repeated kernel exploitation/bruteforcing attempts
  60785. + and is useful for later forensics.
  60786. +
  60787. +config GRKERNSEC_OLD_ARM_USERLAND
  60788. + bool "Old ARM userland compatibility"
  60789. + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
  60790. + help
  60791. + If you say Y here, stubs of executable code to perform such operations
  60792. + as "compare-exchange" will be placed at fixed locations in the ARM vector
  60793. + table. This is unfortunately needed for old ARM userland meant to run
  60794. + across a wide range of processors. Without this option enabled,
  60795. + the get_tls and data memory barrier stubs will be emulated by the kernel,
  60796. + which is enough for Linaro userlands or other userlands designed for v6
  60797. + and newer ARM CPUs. It's recommended that you try without this option enabled
  60798. + first, and only enable it if your userland does not boot (it will likely fail
  60799. + at init time).
  60800. +
  60801. +endmenu
  60802. +menu "Role Based Access Control Options"
  60803. +depends on GRKERNSEC
  60804. +
  60805. +config GRKERNSEC_RBAC_DEBUG
  60806. + bool
  60807. +
  60808. +config GRKERNSEC_NO_RBAC
  60809. + bool "Disable RBAC system"
  60810. + help
  60811. + If you say Y here, the /dev/grsec device will be removed from the kernel,
  60812. + preventing the RBAC system from being enabled. You should only say Y
  60813. + here if you have no intention of using the RBAC system, so as to prevent
  60814. + an attacker with root access from misusing the RBAC system to hide files
  60815. + and processes when loadable module support and /dev/[k]mem have been
  60816. + locked down.
  60817. +
  60818. +config GRKERNSEC_ACL_HIDEKERN
  60819. + bool "Hide kernel processes"
  60820. + help
  60821. + If you say Y here, all kernel threads will be hidden to all
  60822. + processes but those whose subject has the "view hidden processes"
  60823. + flag.
  60824. +
  60825. +config GRKERNSEC_ACL_MAXTRIES
  60826. + int "Maximum tries before password lockout"
  60827. + default 3
  60828. + help
  60829. + This option enforces the maximum number of times a user can attempt
  60830. + to authorize themselves with the grsecurity RBAC system before being
  60831. + denied the ability to attempt authorization again for a specified time.
  60832. + The lower the number, the harder it will be to brute-force a password.
  60833. +
  60834. +config GRKERNSEC_ACL_TIMEOUT
  60835. + int "Time to wait after max password tries, in seconds"
  60836. + default 30
  60837. + help
  60838. + This option specifies the time the user must wait after attempting to
  60839. + authorize to the RBAC system with the maximum number of invalid
  60840. + passwords. The higher the number, the harder it will be to brute-force
  60841. + a password.
  60842. +
  60843. +endmenu
  60844. +menu "Filesystem Protections"
  60845. +depends on GRKERNSEC
  60846. +
  60847. +config GRKERNSEC_PROC
  60848. + bool "Proc restrictions"
  60849. + default y if GRKERNSEC_CONFIG_AUTO
  60850. + help
  60851. + If you say Y here, the permissions of the /proc filesystem
  60852. + will be altered to enhance system security and privacy. You MUST
  60853. + choose either a user only restriction or a user and group restriction.
  60854. + Depending upon the option you choose, you can either restrict users to
  60855. + see only the processes they themselves run, or choose a group that can
  60856. + view all processes and files normally restricted to root if you choose
  60857. + the "restrict to user only" option. NOTE: If you're running identd or
  60858. + ntpd as a non-root user, you will have to run it as the group you
  60859. + specify here.
  60860. +
  60861. +config GRKERNSEC_PROC_USER
  60862. + bool "Restrict /proc to user only"
  60863. + depends on GRKERNSEC_PROC
  60864. + help
  60865. + If you say Y here, non-root users will only be able to view their own
  60866. + processes, and restricts them from viewing network-related information,
  60867. + and viewing kernel symbol and module information.
  60868. +
  60869. +config GRKERNSEC_PROC_USERGROUP
  60870. + bool "Allow special group"
  60871. + default y if GRKERNSEC_CONFIG_AUTO
  60872. + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
  60873. + help
  60874. + If you say Y here, you will be able to select a group that will be
  60875. + able to view all processes and network-related information. If you've
  60876. + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
  60877. + remain hidden. This option is useful if you want to run identd as
  60878. + a non-root user. The group you select may also be chosen at boot time
  60879. + via "grsec_proc_gid=" on the kernel commandline.
  60880. +
  60881. +config GRKERNSEC_PROC_GID
  60882. + int "GID for special group"
  60883. + depends on GRKERNSEC_PROC_USERGROUP
  60884. + default 1001
  60885. +
  60886. +config GRKERNSEC_PROC_ADD
  60887. + bool "Additional restrictions"
  60888. + default y if GRKERNSEC_CONFIG_AUTO
  60889. + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
  60890. + help
  60891. + If you say Y here, additional restrictions will be placed on
  60892. + /proc that keep normal users from viewing device information and
  60893. + slabinfo information that could be useful for exploits.
  60894. +
  60895. +config GRKERNSEC_LINK
  60896. + bool "Linking restrictions"
  60897. + default y if GRKERNSEC_CONFIG_AUTO
  60898. + help
  60899. + If you say Y here, /tmp race exploits will be prevented, since users
  60900. + will no longer be able to follow symlinks owned by other users in
  60901. + world-writable +t directories (e.g. /tmp), unless the owner of the
  60902. + symlink is the owner of the directory. users will also not be
  60903. + able to hardlink to files they do not own. If the sysctl option is
  60904. + enabled, a sysctl option with name "linking_restrictions" is created.
  60905. +
  60906. +config GRKERNSEC_SYMLINKOWN
  60907. + bool "Kernel-enforced SymlinksIfOwnerMatch"
  60908. + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
  60909. + help
  60910. + Apache's SymlinksIfOwnerMatch option has an inherent race condition
  60911. + that prevents it from being used as a security feature. As Apache
  60912. + verifies the symlink by performing a stat() against the target of
  60913. + the symlink before it is followed, an attacker can setup a symlink
  60914. + to point to a same-owned file, then replace the symlink with one
  60915. + that targets another user's file just after Apache "validates" the
  60916. + symlink -- a classic TOCTOU race. If you say Y here, a complete,
  60917. + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
  60918. + will be in place for the group you specify. If the sysctl option
  60919. + is enabled, a sysctl option with name "enforce_symlinksifowner" is
  60920. + created.
  60921. +
  60922. +config GRKERNSEC_SYMLINKOWN_GID
  60923. + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
  60924. + depends on GRKERNSEC_SYMLINKOWN
  60925. + default 1006
  60926. + help
  60927. + Setting this GID determines what group kernel-enforced
  60928. + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
  60929. + is enabled, a sysctl option with name "symlinkown_gid" is created.
  60930. +
  60931. +config GRKERNSEC_FIFO
  60932. + bool "FIFO restrictions"
  60933. + default y if GRKERNSEC_CONFIG_AUTO
  60934. + help
  60935. + If you say Y here, users will not be able to write to FIFOs they don't
  60936. + own in world-writable +t directories (e.g. /tmp), unless the owner of
  60937. + the FIFO is the same owner of the directory it's held in. If the sysctl
  60938. + option is enabled, a sysctl option with name "fifo_restrictions" is
  60939. + created.
  60940. +
  60941. +config GRKERNSEC_SYSFS_RESTRICT
  60942. + bool "Sysfs/debugfs restriction"
  60943. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
  60944. + depends on SYSFS
  60945. + help
  60946. + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
  60947. + any filesystem normally mounted under it (e.g. debugfs) will be
  60948. + mostly accessible only by root. These filesystems generally provide access
  60949. + to hardware and debug information that isn't appropriate for unprivileged
  60950. + users of the system. Sysfs and debugfs have also become a large source
  60951. + of new vulnerabilities, ranging from infoleaks to local compromise.
  60952. + There has been very little oversight with an eye toward security involved
  60953. + in adding new exporters of information to these filesystems, so their
  60954. + use is discouraged.
  60955. + For reasons of compatibility, a few directories have been whitelisted
  60956. + for access by non-root users:
  60957. + /sys/fs/selinux
  60958. + /sys/fs/fuse
  60959. + /sys/devices/system/cpu
  60960. +
  60961. +config GRKERNSEC_ROFS
  60962. + bool "Runtime read-only mount protection"
  60963. + depends on SYSCTL
  60964. + help
  60965. + If you say Y here, a sysctl option with name "romount_protect" will
  60966. + be created. By setting this option to 1 at runtime, filesystems
  60967. + will be protected in the following ways:
  60968. + * No new writable mounts will be allowed
  60969. + * Existing read-only mounts won't be able to be remounted read/write
  60970. + * Write operations will be denied on all block devices
  60971. + This option acts independently of grsec_lock: once it is set to 1,
  60972. + it cannot be turned off. Therefore, please be mindful of the resulting
  60973. + behavior if this option is enabled in an init script on a read-only
  60974. + filesystem.
  60975. + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
  60976. + and GRKERNSEC_IO should be enabled and module loading disabled via
  60977. + config or at runtime.
  60978. + This feature is mainly intended for secure embedded systems.
  60979. +
  60980. +
  60981. +config GRKERNSEC_DEVICE_SIDECHANNEL
  60982. + bool "Eliminate stat/notify-based device sidechannels"
  60983. + default y if GRKERNSEC_CONFIG_AUTO
  60984. + help
  60985. + If you say Y here, timing analyses on block or character
  60986. + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
  60987. + will be thwarted for unprivileged users. If a process without
  60988. + CAP_MKNOD stats such a device, the last access and last modify times
  60989. + will match the device's create time. No access or modify events
  60990. + will be triggered through inotify/dnotify/fanotify for such devices.
  60991. + This feature will prevent attacks that may at a minimum
  60992. + allow an attacker to determine the administrator's password length.
  60993. +
  60994. +config GRKERNSEC_CHROOT
  60995. + bool "Chroot jail restrictions"
  60996. + default y if GRKERNSEC_CONFIG_AUTO
  60997. + help
  60998. + If you say Y here, you will be able to choose several options that will
  60999. + make breaking out of a chrooted jail much more difficult. If you
  61000. + encounter no software incompatibilities with the following options, it
  61001. + is recommended that you enable each one.
  61002. +
  61003. + Note that the chroot restrictions are not intended to apply to "chroots"
  61004. + to directories that are simple bind mounts of the global root filesystem.
  61005. + For several other reasons, a user shouldn't expect any significant
  61006. + security by performing such a chroot.
  61007. +
  61008. +config GRKERNSEC_CHROOT_MOUNT
  61009. + bool "Deny mounts"
  61010. + default y if GRKERNSEC_CONFIG_AUTO
  61011. + depends on GRKERNSEC_CHROOT
  61012. + help
  61013. + If you say Y here, processes inside a chroot will not be able to
  61014. + mount or remount filesystems. If the sysctl option is enabled, a
  61015. + sysctl option with name "chroot_deny_mount" is created.
  61016. +
  61017. +config GRKERNSEC_CHROOT_DOUBLE
  61018. + bool "Deny double-chroots"
  61019. + default y if GRKERNSEC_CONFIG_AUTO
  61020. + depends on GRKERNSEC_CHROOT
  61021. + help
  61022. + If you say Y here, processes inside a chroot will not be able to chroot
  61023. + again outside the chroot. This is a widely used method of breaking
  61024. + out of a chroot jail and should not be allowed. If the sysctl
  61025. + option is enabled, a sysctl option with name
  61026. + "chroot_deny_chroot" is created.
  61027. +
  61028. +config GRKERNSEC_CHROOT_PIVOT
  61029. + bool "Deny pivot_root in chroot"
  61030. + default y if GRKERNSEC_CONFIG_AUTO
  61031. + depends on GRKERNSEC_CHROOT
  61032. + help
  61033. + If you say Y here, processes inside a chroot will not be able to use
  61034. + a function called pivot_root() that was introduced in Linux 2.3.41. It
  61035. + works similar to chroot in that it changes the root filesystem. This
  61036. + function could be misused in a chrooted process to attempt to break out
  61037. + of the chroot, and therefore should not be allowed. If the sysctl
  61038. + option is enabled, a sysctl option with name "chroot_deny_pivot" is
  61039. + created.
  61040. +
  61041. +config GRKERNSEC_CHROOT_CHDIR
  61042. + bool "Enforce chdir(\"/\") on all chroots"
  61043. + default y if GRKERNSEC_CONFIG_AUTO
  61044. + depends on GRKERNSEC_CHROOT
  61045. + help
  61046. + If you say Y here, the current working directory of all newly-chrooted
  61047. + applications will be set to the the root directory of the chroot.
  61048. + The man page on chroot(2) states:
  61049. + Note that this call does not change the current working
  61050. + directory, so that `.' can be outside the tree rooted at
  61051. + `/'. In particular, the super-user can escape from a
  61052. + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
  61053. +
  61054. + It is recommended that you say Y here, since it's not known to break
  61055. + any software. If the sysctl option is enabled, a sysctl option with
  61056. + name "chroot_enforce_chdir" is created.
  61057. +
  61058. +config GRKERNSEC_CHROOT_CHMOD
  61059. + bool "Deny (f)chmod +s"
  61060. + default y if GRKERNSEC_CONFIG_AUTO
  61061. + depends on GRKERNSEC_CHROOT
  61062. + help
  61063. + If you say Y here, processes inside a chroot will not be able to chmod
  61064. + or fchmod files to make them have suid or sgid bits. This protects
  61065. + against another published method of breaking a chroot. If the sysctl
  61066. + option is enabled, a sysctl option with name "chroot_deny_chmod" is
  61067. + created.
  61068. +
  61069. +config GRKERNSEC_CHROOT_FCHDIR
  61070. + bool "Deny fchdir out of chroot"
  61071. + default y if GRKERNSEC_CONFIG_AUTO
  61072. + depends on GRKERNSEC_CHROOT
  61073. + help
  61074. + If you say Y here, a well-known method of breaking chroots by fchdir'ing
  61075. + to a file descriptor of the chrooting process that points to a directory
  61076. + outside the filesystem will be stopped. If the sysctl option
  61077. + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
  61078. +
  61079. +config GRKERNSEC_CHROOT_MKNOD
  61080. + bool "Deny mknod"
  61081. + default y if GRKERNSEC_CONFIG_AUTO
  61082. + depends on GRKERNSEC_CHROOT
  61083. + help
  61084. + If you say Y here, processes inside a chroot will not be allowed to
  61085. + mknod. The problem with using mknod inside a chroot is that it
  61086. + would allow an attacker to create a device entry that is the same
  61087. + as one on the physical root of your system, which could range from
  61088. + anything from the console device to a device for your harddrive (which
  61089. + they could then use to wipe the drive or steal data). It is recommended
  61090. + that you say Y here, unless you run into software incompatibilities.
  61091. + If the sysctl option is enabled, a sysctl option with name
  61092. + "chroot_deny_mknod" is created.
  61093. +
  61094. +config GRKERNSEC_CHROOT_SHMAT
  61095. + bool "Deny shmat() out of chroot"
  61096. + default y if GRKERNSEC_CONFIG_AUTO
  61097. + depends on GRKERNSEC_CHROOT
  61098. + help
  61099. + If you say Y here, processes inside a chroot will not be able to attach
  61100. + to shared memory segments that were created outside of the chroot jail.
  61101. + It is recommended that you say Y here. If the sysctl option is enabled,
  61102. + a sysctl option with name "chroot_deny_shmat" is created.
  61103. +
  61104. +config GRKERNSEC_CHROOT_UNIX
  61105. + bool "Deny access to abstract AF_UNIX sockets out of chroot"
  61106. + default y if GRKERNSEC_CONFIG_AUTO
  61107. + depends on GRKERNSEC_CHROOT
  61108. + help
  61109. + If you say Y here, processes inside a chroot will not be able to
  61110. + connect to abstract (meaning not belonging to a filesystem) Unix
  61111. + domain sockets that were bound outside of a chroot. It is recommended
  61112. + that you say Y here. If the sysctl option is enabled, a sysctl option
  61113. + with name "chroot_deny_unix" is created.
  61114. +
  61115. +config GRKERNSEC_CHROOT_FINDTASK
  61116. + bool "Protect outside processes"
  61117. + default y if GRKERNSEC_CONFIG_AUTO
  61118. + depends on GRKERNSEC_CHROOT
  61119. + help
  61120. + If you say Y here, processes inside a chroot will not be able to
  61121. + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
  61122. + getsid, or view any process outside of the chroot. If the sysctl
  61123. + option is enabled, a sysctl option with name "chroot_findtask" is
  61124. + created.
  61125. +
  61126. +config GRKERNSEC_CHROOT_NICE
  61127. + bool "Restrict priority changes"
  61128. + default y if GRKERNSEC_CONFIG_AUTO
  61129. + depends on GRKERNSEC_CHROOT
  61130. + help
  61131. + If you say Y here, processes inside a chroot will not be able to raise
  61132. + the priority of processes in the chroot, or alter the priority of
  61133. + processes outside the chroot. This provides more security than simply
  61134. + removing CAP_SYS_NICE from the process' capability set. If the
  61135. + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
  61136. + is created.
  61137. +
  61138. +config GRKERNSEC_CHROOT_SYSCTL
  61139. + bool "Deny sysctl writes"
  61140. + default y if GRKERNSEC_CONFIG_AUTO
  61141. + depends on GRKERNSEC_CHROOT
  61142. + help
  61143. + If you say Y here, an attacker in a chroot will not be able to
  61144. + write to sysctl entries, either by sysctl(2) or through a /proc
  61145. + interface. It is strongly recommended that you say Y here. If the
  61146. + sysctl option is enabled, a sysctl option with name
  61147. + "chroot_deny_sysctl" is created.
  61148. +
  61149. +config GRKERNSEC_CHROOT_CAPS
  61150. + bool "Capability restrictions"
  61151. + default y if GRKERNSEC_CONFIG_AUTO
  61152. + depends on GRKERNSEC_CHROOT
  61153. + help
  61154. + If you say Y here, the capabilities on all processes within a
  61155. + chroot jail will be lowered to stop module insertion, raw i/o,
  61156. + system and net admin tasks, rebooting the system, modifying immutable
  61157. + files, modifying IPC owned by another, and changing the system time.
  61158. + This is left an option because it can break some apps. Disable this
  61159. + if your chrooted apps are having problems performing those kinds of
  61160. + tasks. If the sysctl option is enabled, a sysctl option with
  61161. + name "chroot_caps" is created.
  61162. +
  61163. +config GRKERNSEC_CHROOT_INITRD
  61164. + bool "Exempt initrd tasks from restrictions"
  61165. + default y if GRKERNSEC_CONFIG_AUTO
  61166. + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
  61167. + help
  61168. + If you say Y here, tasks started prior to init will be exempted from
  61169. + grsecurity's chroot restrictions. This option is mainly meant to
  61170. + resolve Plymouth's performing privileged operations unnecessarily
  61171. + in a chroot.
  61172. +
  61173. +endmenu
  61174. +menu "Kernel Auditing"
  61175. +depends on GRKERNSEC
  61176. +
  61177. +config GRKERNSEC_AUDIT_GROUP
  61178. + bool "Single group for auditing"
  61179. + help
  61180. + If you say Y here, the exec and chdir logging features will only operate
  61181. + on a group you specify. This option is recommended if you only want to
  61182. + watch certain users instead of having a large amount of logs from the
  61183. + entire system. If the sysctl option is enabled, a sysctl option with
  61184. + name "audit_group" is created.
  61185. +
  61186. +config GRKERNSEC_AUDIT_GID
  61187. + int "GID for auditing"
  61188. + depends on GRKERNSEC_AUDIT_GROUP
  61189. + default 1007
  61190. +
  61191. +config GRKERNSEC_EXECLOG
  61192. + bool "Exec logging"
  61193. + help
  61194. + If you say Y here, all execve() calls will be logged (since the
  61195. + other exec*() calls are frontends to execve(), all execution
  61196. + will be logged). Useful for shell-servers that like to keep track
  61197. + of their users. If the sysctl option is enabled, a sysctl option with
  61198. + name "exec_logging" is created.
  61199. + WARNING: This option when enabled will produce a LOT of logs, especially
  61200. + on an active system.
  61201. +
  61202. +config GRKERNSEC_RESLOG
  61203. + bool "Resource logging"
  61204. + default y if GRKERNSEC_CONFIG_AUTO
  61205. + help
  61206. + If you say Y here, all attempts to overstep resource limits will
  61207. + be logged with the resource name, the requested size, and the current
  61208. + limit. It is highly recommended that you say Y here. If the sysctl
  61209. + option is enabled, a sysctl option with name "resource_logging" is
  61210. + created. If the RBAC system is enabled, the sysctl value is ignored.
  61211. +
  61212. +config GRKERNSEC_CHROOT_EXECLOG
  61213. + bool "Log execs within chroot"
  61214. + help
  61215. + If you say Y here, all executions inside a chroot jail will be logged
  61216. + to syslog. This can cause a large amount of logs if certain
  61217. + applications (eg. djb's daemontools) are installed on the system, and
  61218. + is therefore left as an option. If the sysctl option is enabled, a
  61219. + sysctl option with name "chroot_execlog" is created.
  61220. +
  61221. +config GRKERNSEC_AUDIT_PTRACE
  61222. + bool "Ptrace logging"
  61223. + help
  61224. + If you say Y here, all attempts to attach to a process via ptrace
  61225. + will be logged. If the sysctl option is enabled, a sysctl option
  61226. + with name "audit_ptrace" is created.
  61227. +
  61228. +config GRKERNSEC_AUDIT_CHDIR
  61229. + bool "Chdir logging"
  61230. + help
  61231. + If you say Y here, all chdir() calls will be logged. If the sysctl
  61232. + option is enabled, a sysctl option with name "audit_chdir" is created.
  61233. +
  61234. +config GRKERNSEC_AUDIT_MOUNT
  61235. + bool "(Un)Mount logging"
  61236. + help
  61237. + If you say Y here, all mounts and unmounts will be logged. If the
  61238. + sysctl option is enabled, a sysctl option with name "audit_mount" is
  61239. + created.
  61240. +
  61241. +config GRKERNSEC_SIGNAL
  61242. + bool "Signal logging"
  61243. + default y if GRKERNSEC_CONFIG_AUTO
  61244. + help
  61245. + If you say Y here, certain important signals will be logged, such as
  61246. + SIGSEGV, which will as a result inform you of when a error in a program
  61247. + occurred, which in some cases could mean a possible exploit attempt.
  61248. + If the sysctl option is enabled, a sysctl option with name
  61249. + "signal_logging" is created.
  61250. +
  61251. +config GRKERNSEC_FORKFAIL
  61252. + bool "Fork failure logging"
  61253. + help
  61254. + If you say Y here, all failed fork() attempts will be logged.
  61255. + This could suggest a fork bomb, or someone attempting to overstep
  61256. + their process limit. If the sysctl option is enabled, a sysctl option
  61257. + with name "forkfail_logging" is created.
  61258. +
  61259. +config GRKERNSEC_TIME
  61260. + bool "Time change logging"
  61261. + default y if GRKERNSEC_CONFIG_AUTO
  61262. + help
  61263. + If you say Y here, any changes of the system clock will be logged.
  61264. + If the sysctl option is enabled, a sysctl option with name
  61265. + "timechange_logging" is created.
  61266. +
  61267. +config GRKERNSEC_PROC_IPADDR
  61268. + bool "/proc/<pid>/ipaddr support"
  61269. + default y if GRKERNSEC_CONFIG_AUTO
  61270. + help
  61271. + If you say Y here, a new entry will be added to each /proc/<pid>
  61272. + directory that contains the IP address of the person using the task.
  61273. + The IP is carried across local TCP and AF_UNIX stream sockets.
  61274. + This information can be useful for IDS/IPSes to perform remote response
  61275. + to a local attack. The entry is readable by only the owner of the
  61276. + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
  61277. + the RBAC system), and thus does not create privacy concerns.
  61278. +
  61279. +config GRKERNSEC_RWXMAP_LOG
  61280. + bool 'Denied RWX mmap/mprotect logging'
  61281. + default y if GRKERNSEC_CONFIG_AUTO
  61282. + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
  61283. + help
  61284. + If you say Y here, calls to mmap() and mprotect() with explicit
  61285. + usage of PROT_WRITE and PROT_EXEC together will be logged when
  61286. + denied by the PAX_MPROTECT feature. This feature will also
  61287. + log other problematic scenarios that can occur when PAX_MPROTECT
  61288. + is enabled on a binary, like textrels and PT_GNU_STACK. If the
  61289. + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
  61290. + is created.
  61291. +
  61292. +endmenu
  61293. +
  61294. +menu "Executable Protections"
  61295. +depends on GRKERNSEC
  61296. +
  61297. +config GRKERNSEC_DMESG
  61298. + bool "Dmesg(8) restriction"
  61299. + default y if GRKERNSEC_CONFIG_AUTO
  61300. + help
  61301. + If you say Y here, non-root users will not be able to use dmesg(8)
  61302. + to view the contents of the kernel's circular log buffer.
  61303. + The kernel's log buffer often contains kernel addresses and other
  61304. + identifying information useful to an attacker in fingerprinting a
  61305. + system for a targeted exploit.
  61306. + If the sysctl option is enabled, a sysctl option with name "dmesg" is
  61307. + created.
  61308. +
  61309. +config GRKERNSEC_HARDEN_PTRACE
  61310. + bool "Deter ptrace-based process snooping"
  61311. + default y if GRKERNSEC_CONFIG_AUTO
  61312. + help
  61313. + If you say Y here, TTY sniffers and other malicious monitoring
  61314. + programs implemented through ptrace will be defeated. If you
  61315. + have been using the RBAC system, this option has already been
  61316. + enabled for several years for all users, with the ability to make
  61317. + fine-grained exceptions.
  61318. +
  61319. + This option only affects the ability of non-root users to ptrace
  61320. + processes that are not a descendent of the ptracing process.
  61321. + This means that strace ./binary and gdb ./binary will still work,
  61322. + but attaching to arbitrary processes will not. If the sysctl
  61323. + option is enabled, a sysctl option with name "harden_ptrace" is
  61324. + created.
  61325. +
  61326. +config GRKERNSEC_PTRACE_READEXEC
  61327. + bool "Require read access to ptrace sensitive binaries"
  61328. + default y if GRKERNSEC_CONFIG_AUTO
  61329. + help
  61330. + If you say Y here, unprivileged users will not be able to ptrace unreadable
  61331. + binaries. This option is useful in environments that
  61332. + remove the read bits (e.g. file mode 4711) from suid binaries to
  61333. + prevent infoleaking of their contents. This option adds
  61334. + consistency to the use of that file mode, as the binary could normally
  61335. + be read out when run without privileges while ptracing.
  61336. +
  61337. + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
  61338. + is created.
  61339. +
  61340. +config GRKERNSEC_SETXID
  61341. + bool "Enforce consistent multithreaded privileges"
  61342. + default y if GRKERNSEC_CONFIG_AUTO
  61343. + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
  61344. + help
  61345. + If you say Y here, a change from a root uid to a non-root uid
  61346. + in a multithreaded application will cause the resulting uids,
  61347. + gids, supplementary groups, and capabilities in that thread
  61348. + to be propagated to the other threads of the process. In most
  61349. + cases this is unnecessary, as glibc will emulate this behavior
  61350. + on behalf of the application. Other libcs do not act in the
  61351. + same way, allowing the other threads of the process to continue
  61352. + running with root privileges. If the sysctl option is enabled,
  61353. + a sysctl option with name "consistent_setxid" is created.
  61354. +
  61355. +config GRKERNSEC_HARDEN_IPC
  61356. + bool "Disallow access to overly-permissive IPC objects"
  61357. + default y if GRKERNSEC_CONFIG_AUTO
  61358. + depends on SYSVIPC
  61359. + help
  61360. + If you say Y here, access to overly-permissive IPC objects (shared
  61361. + memory, message queues, and semaphores) will be denied for processes
  61362. + given the following criteria beyond normal permission checks:
  61363. + 1) If the IPC object is world-accessible and the euid doesn't match
  61364. + that of the creator or current uid for the IPC object
  61365. + 2) If the IPC object is group-accessible and the egid doesn't
  61366. + match that of the creator or current gid for the IPC object
  61367. + It's a common error to grant too much permission to these objects,
  61368. + with impact ranging from denial of service and information leaking to
  61369. + privilege escalation. This feature was developed in response to
  61370. + research by Tim Brown:
  61371. + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
  61372. + who found hundreds of such insecure usages. Processes with
  61373. + CAP_IPC_OWNER are still permitted to access these IPC objects.
  61374. + If the sysctl option is enabled, a sysctl option with name
  61375. + "harden_ipc" is created.
  61376. +
  61377. +config GRKERNSEC_TPE
  61378. + bool "Trusted Path Execution (TPE)"
  61379. + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
  61380. + help
  61381. + If you say Y here, you will be able to choose a gid to add to the
  61382. + supplementary groups of users you want to mark as "untrusted."
  61383. + These users will not be able to execute any files that are not in
  61384. + root-owned directories writable only by root. If the sysctl option
  61385. + is enabled, a sysctl option with name "tpe" is created.
  61386. +
  61387. +config GRKERNSEC_TPE_ALL
  61388. + bool "Partially restrict all non-root users"
  61389. + depends on GRKERNSEC_TPE
  61390. + help
  61391. + If you say Y here, all non-root users will be covered under
  61392. + a weaker TPE restriction. This is separate from, and in addition to,
  61393. + the main TPE options that you have selected elsewhere. Thus, if a
  61394. + "trusted" GID is chosen, this restriction applies to even that GID.
  61395. + Under this restriction, all non-root users will only be allowed to
  61396. + execute files in directories they own that are not group or
  61397. + world-writable, or in directories owned by root and writable only by
  61398. + root. If the sysctl option is enabled, a sysctl option with name
  61399. + "tpe_restrict_all" is created.
  61400. +
  61401. +config GRKERNSEC_TPE_INVERT
  61402. + bool "Invert GID option"
  61403. + depends on GRKERNSEC_TPE
  61404. + help
  61405. + If you say Y here, the group you specify in the TPE configuration will
  61406. + decide what group TPE restrictions will be *disabled* for. This
  61407. + option is useful if you want TPE restrictions to be applied to most
  61408. + users on the system. If the sysctl option is enabled, a sysctl option
  61409. + with name "tpe_invert" is created. Unlike other sysctl options, this
  61410. + entry will default to on for backward-compatibility.
  61411. +
  61412. +config GRKERNSEC_TPE_GID
  61413. + int
  61414. + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
  61415. + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
  61416. +
  61417. +config GRKERNSEC_TPE_UNTRUSTED_GID
  61418. + int "GID for TPE-untrusted users"
  61419. + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
  61420. + default 1005
  61421. + help
  61422. + Setting this GID determines what group TPE restrictions will be
  61423. + *enabled* for. If the sysctl option is enabled, a sysctl option
  61424. + with name "tpe_gid" is created.
  61425. +
  61426. +config GRKERNSEC_TPE_TRUSTED_GID
  61427. + int "GID for TPE-trusted users"
  61428. + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
  61429. + default 1005
  61430. + help
  61431. + Setting this GID determines what group TPE restrictions will be
  61432. + *disabled* for. If the sysctl option is enabled, a sysctl option
  61433. + with name "tpe_gid" is created.
  61434. +
  61435. +endmenu
  61436. +menu "Network Protections"
  61437. +depends on GRKERNSEC
  61438. +
  61439. +config GRKERNSEC_RANDNET
  61440. + bool "Larger entropy pools"
  61441. + default y if GRKERNSEC_CONFIG_AUTO
  61442. + help
  61443. + If you say Y here, the entropy pools used for many features of Linux
  61444. + and grsecurity will be doubled in size. Since several grsecurity
  61445. + features use additional randomness, it is recommended that you say Y
  61446. + here. Saying Y here has a similar effect as modifying
  61447. + /proc/sys/kernel/random/poolsize.
  61448. +
  61449. +config GRKERNSEC_BLACKHOLE
  61450. + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
  61451. + default y if GRKERNSEC_CONFIG_AUTO
  61452. + depends on NET
  61453. + help
  61454. + If you say Y here, neither TCP resets nor ICMP
  61455. + destination-unreachable packets will be sent in response to packets
  61456. + sent to ports for which no associated listening process exists.
  61457. + This feature supports both IPV4 and IPV6 and exempts the
  61458. + loopback interface from blackholing. Enabling this feature
  61459. + makes a host more resilient to DoS attacks and reduces network
  61460. + visibility against scanners.
  61461. +
  61462. + The blackhole feature as-implemented is equivalent to the FreeBSD
  61463. + blackhole feature, as it prevents RST responses to all packets, not
  61464. + just SYNs. Under most application behavior this causes no
  61465. + problems, but applications (like haproxy) may not close certain
  61466. + connections in a way that cleanly terminates them on the remote
  61467. + end, leaving the remote host in LAST_ACK state. Because of this
  61468. + side-effect and to prevent intentional LAST_ACK DoSes, this
  61469. + feature also adds automatic mitigation against such attacks.
  61470. + The mitigation drastically reduces the amount of time a socket
  61471. + can spend in LAST_ACK state. If you're using haproxy and not
  61472. + all servers it connects to have this option enabled, consider
  61473. + disabling this feature on the haproxy host.
  61474. +
  61475. + If the sysctl option is enabled, two sysctl options with names
  61476. + "ip_blackhole" and "lastack_retries" will be created.
  61477. + While "ip_blackhole" takes the standard zero/non-zero on/off
  61478. + toggle, "lastack_retries" uses the same kinds of values as
  61479. + "tcp_retries1" and "tcp_retries2". The default value of 4
  61480. + prevents a socket from lasting more than 45 seconds in LAST_ACK
  61481. + state.
  61482. +
  61483. +config GRKERNSEC_NO_SIMULT_CONNECT
  61484. + bool "Disable TCP Simultaneous Connect"
  61485. + default y if GRKERNSEC_CONFIG_AUTO
  61486. + depends on NET
  61487. + help
  61488. + If you say Y here, a feature by Willy Tarreau will be enabled that
  61489. + removes a weakness in Linux's strict implementation of TCP that
  61490. + allows two clients to connect to each other without either entering
  61491. + a listening state. The weakness allows an attacker to easily prevent
  61492. + a client from connecting to a known server provided the source port
  61493. + for the connection is guessed correctly.
  61494. +
  61495. + As the weakness could be used to prevent an antivirus or IPS from
  61496. + fetching updates, or prevent an SSL gateway from fetching a CRL,
  61497. + it should be eliminated by enabling this option. Though Linux is
  61498. + one of few operating systems supporting simultaneous connect, it
  61499. + has no legitimate use in practice and is rarely supported by firewalls.
  61500. +
  61501. +config GRKERNSEC_SOCKET
  61502. + bool "Socket restrictions"
  61503. + depends on NET
  61504. + help
  61505. + If you say Y here, you will be able to choose from several options.
  61506. + If you assign a GID on your system and add it to the supplementary
  61507. + groups of users you want to restrict socket access to, this patch
  61508. + will perform up to three things, based on the option(s) you choose.
  61509. +
  61510. +config GRKERNSEC_SOCKET_ALL
  61511. + bool "Deny any sockets to group"
  61512. + depends on GRKERNSEC_SOCKET
  61513. + help
  61514. + If you say Y here, you will be able to choose a GID of whose users will
  61515. + be unable to connect to other hosts from your machine or run server
  61516. + applications from your machine. If the sysctl option is enabled, a
  61517. + sysctl option with name "socket_all" is created.
  61518. +
  61519. +config GRKERNSEC_SOCKET_ALL_GID
  61520. + int "GID to deny all sockets for"
  61521. + depends on GRKERNSEC_SOCKET_ALL
  61522. + default 1004
  61523. + help
  61524. + Here you can choose the GID to disable socket access for. Remember to
  61525. + add the users you want socket access disabled for to the GID
  61526. + specified here. If the sysctl option is enabled, a sysctl option
  61527. + with name "socket_all_gid" is created.
  61528. +
  61529. +config GRKERNSEC_SOCKET_CLIENT
  61530. + bool "Deny client sockets to group"
  61531. + depends on GRKERNSEC_SOCKET
  61532. + help
  61533. + If you say Y here, you will be able to choose a GID of whose users will
  61534. + be unable to connect to other hosts from your machine, but will be
  61535. + able to run servers. If this option is enabled, all users in the group
  61536. + you specify will have to use passive mode when initiating ftp transfers
  61537. + from the shell on your machine. If the sysctl option is enabled, a
  61538. + sysctl option with name "socket_client" is created.
  61539. +
  61540. +config GRKERNSEC_SOCKET_CLIENT_GID
  61541. + int "GID to deny client sockets for"
  61542. + depends on GRKERNSEC_SOCKET_CLIENT
  61543. + default 1003
  61544. + help
  61545. + Here you can choose the GID to disable client socket access for.
  61546. + Remember to add the users you want client socket access disabled for to
  61547. + the GID specified here. If the sysctl option is enabled, a sysctl
  61548. + option with name "socket_client_gid" is created.
  61549. +
  61550. +config GRKERNSEC_SOCKET_SERVER
  61551. + bool "Deny server sockets to group"
  61552. + depends on GRKERNSEC_SOCKET
  61553. + help
  61554. + If you say Y here, you will be able to choose a GID of whose users will
  61555. + be unable to run server applications from your machine. If the sysctl
  61556. + option is enabled, a sysctl option with name "socket_server" is created.
  61557. +
  61558. +config GRKERNSEC_SOCKET_SERVER_GID
  61559. + int "GID to deny server sockets for"
  61560. + depends on GRKERNSEC_SOCKET_SERVER
  61561. + default 1002
  61562. + help
  61563. + Here you can choose the GID to disable server socket access for.
  61564. + Remember to add the users you want server socket access disabled for to
  61565. + the GID specified here. If the sysctl option is enabled, a sysctl
  61566. + option with name "socket_server_gid" is created.
  61567. +
  61568. +endmenu
  61569. +
  61570. +menu "Physical Protections"
  61571. +depends on GRKERNSEC
  61572. +
  61573. +config GRKERNSEC_DENYUSB
  61574. + bool "Deny new USB connections after toggle"
  61575. + default y if GRKERNSEC_CONFIG_AUTO
  61576. + depends on SYSCTL && USB_SUPPORT
  61577. + help
  61578. + If you say Y here, a new sysctl option with name "deny_new_usb"
  61579. + will be created. Setting its value to 1 will prevent any new
  61580. + USB devices from being recognized by the OS. Any attempted USB
  61581. + device insertion will be logged. This option is intended to be
  61582. + used against custom USB devices designed to exploit vulnerabilities
  61583. + in various USB device drivers.
  61584. +
  61585. + For greatest effectiveness, this sysctl should be set after any
  61586. + relevant init scripts. This option is safe to enable in distros
  61587. + as each user can choose whether or not to toggle the sysctl.
  61588. +
  61589. +config GRKERNSEC_DENYUSB_FORCE
  61590. + bool "Reject all USB devices not connected at boot"
  61591. + select USB
  61592. + depends on GRKERNSEC_DENYUSB
  61593. + help
  61594. + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
  61595. + that doesn't involve a sysctl entry. This option should only be
  61596. + enabled if you're sure you want to deny all new USB connections
  61597. + at runtime and don't want to modify init scripts. This should not
  61598. + be enabled by distros. It forces the core USB code to be built
  61599. + into the kernel image so that all devices connected at boot time
  61600. + can be recognized and new USB device connections can be prevented
  61601. + prior to init running.
  61602. +
  61603. +endmenu
  61604. +
  61605. +menu "Sysctl Support"
  61606. +depends on GRKERNSEC && SYSCTL
  61607. +
  61608. +config GRKERNSEC_SYSCTL
  61609. + bool "Sysctl support"
  61610. + default y if GRKERNSEC_CONFIG_AUTO
  61611. + help
  61612. + If you say Y here, you will be able to change the options that
  61613. + grsecurity runs with at bootup, without having to recompile your
  61614. + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
  61615. + to enable (1) or disable (0) various features. All the sysctl entries
  61616. + are mutable until the "grsec_lock" entry is set to a non-zero value.
  61617. + All features enabled in the kernel configuration are disabled at boot
  61618. + if you do not say Y to the "Turn on features by default" option.
  61619. + All options should be set at startup, and the grsec_lock entry should
  61620. + be set to a non-zero value after all the options are set.
  61621. + *THIS IS EXTREMELY IMPORTANT*
  61622. +
  61623. +config GRKERNSEC_SYSCTL_DISTRO
  61624. + bool "Extra sysctl support for distro makers (READ HELP)"
  61625. + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
  61626. + help
  61627. + If you say Y here, additional sysctl options will be created
  61628. + for features that affect processes running as root. Therefore,
  61629. + it is critical when using this option that the grsec_lock entry be
  61630. + enabled after boot. Only distros with prebuilt kernel packages
  61631. + with this option enabled that can ensure grsec_lock is enabled
  61632. + after boot should use this option.
  61633. + *Failure to set grsec_lock after boot makes all grsec features
  61634. + this option covers useless*
  61635. +
  61636. + Currently this option creates the following sysctl entries:
  61637. + "Disable Privileged I/O": "disable_priv_io"
  61638. +
  61639. +config GRKERNSEC_SYSCTL_ON
  61640. + bool "Turn on features by default"
  61641. + default y if GRKERNSEC_CONFIG_AUTO
  61642. + depends on GRKERNSEC_SYSCTL
  61643. + help
  61644. + If you say Y here, instead of having all features enabled in the
  61645. + kernel configuration disabled at boot time, the features will be
  61646. + enabled at boot time. It is recommended you say Y here unless
  61647. + there is some reason you would want all sysctl-tunable features to
  61648. + be disabled by default. As mentioned elsewhere, it is important
  61649. + to enable the grsec_lock entry once you have finished modifying
  61650. + the sysctl entries.
  61651. +
  61652. +endmenu
  61653. +menu "Logging Options"
  61654. +depends on GRKERNSEC
  61655. +
  61656. +config GRKERNSEC_FLOODTIME
  61657. + int "Seconds in between log messages (minimum)"
  61658. + default 10
  61659. + help
  61660. + This option allows you to enforce the number of seconds between
  61661. + grsecurity log messages. The default should be suitable for most
  61662. + people, however, if you choose to change it, choose a value small enough
  61663. + to allow informative logs to be produced, but large enough to
  61664. + prevent flooding.
  61665. +
  61666. + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
  61667. + any rate limiting on grsecurity log messages.
  61668. +
  61669. +config GRKERNSEC_FLOODBURST
  61670. + int "Number of messages in a burst (maximum)"
  61671. + default 6
  61672. + help
  61673. + This option allows you to choose the maximum number of messages allowed
  61674. + within the flood time interval you chose in a separate option. The
  61675. + default should be suitable for most people, however if you find that
  61676. + many of your logs are being interpreted as flooding, you may want to
  61677. + raise this value.
  61678. +
  61679. + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
  61680. + any rate limiting on grsecurity log messages.
  61681. +
  61682. +endmenu
  61683. diff --git a/grsecurity/Makefile b/grsecurity/Makefile
  61684. new file mode 100644
  61685. index 0000000..30ababb
  61686. --- /dev/null
  61687. +++ b/grsecurity/Makefile
  61688. @@ -0,0 +1,54 @@
  61689. +# grsecurity – access control and security hardening for Linux
  61690. +# All code in this directory and various hooks located throughout the Linux kernel are
  61691. +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
  61692. +# http://www.grsecurity.net spender@grsecurity.net
  61693. +#
  61694. +# This program is free software; you can redistribute it and/or
  61695. +# modify it under the terms of the GNU General Public License version 2
  61696. +# as published by the Free Software Foundation.
  61697. +#
  61698. +# This program is distributed in the hope that it will be useful,
  61699. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  61700. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  61701. +# GNU General Public License for more details.
  61702. +#
  61703. +# You should have received a copy of the GNU General Public License
  61704. +# along with this program; if not, write to the Free Software
  61705. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  61706. +
  61707. +KBUILD_CFLAGS += -Werror
  61708. +
  61709. +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
  61710. + grsec_mount.o grsec_sig.o grsec_sysctl.o \
  61711. + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
  61712. + grsec_usb.o grsec_ipc.o grsec_proc.o
  61713. +
  61714. +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
  61715. + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
  61716. + gracl_learn.o grsec_log.o gracl_policy.o
  61717. +ifdef CONFIG_COMPAT
  61718. +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
  61719. +endif
  61720. +
  61721. +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
  61722. +
  61723. +ifdef CONFIG_NET
  61724. +obj-y += grsec_sock.o
  61725. +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
  61726. +endif
  61727. +
  61728. +ifndef CONFIG_GRKERNSEC
  61729. +obj-y += grsec_disabled.o
  61730. +endif
  61731. +
  61732. +ifdef CONFIG_GRKERNSEC_HIDESYM
  61733. +extra-y := grsec_hidesym.o
  61734. +$(obj)/grsec_hidesym.o:
  61735. + @-chmod -f 500 /boot
  61736. + @-chmod -f 500 /lib/modules
  61737. + @-chmod -f 500 /lib64/modules
  61738. + @-chmod -f 500 /lib32/modules
  61739. + @-chmod -f 700 .
  61740. + @-chmod -f 700 $(objtree)
  61741. + @echo ' grsec: protected kernel image paths'
  61742. +endif
  61743. diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
  61744. new file mode 100644
  61745. index 0000000..e56396f
  61746. --- /dev/null
  61747. +++ b/grsecurity/gracl.c
  61748. @@ -0,0 +1,2679 @@
  61749. +#include <linux/kernel.h>
  61750. +#include <linux/module.h>
  61751. +#include <linux/sched.h>
  61752. +#include <linux/mm.h>
  61753. +#include <linux/file.h>
  61754. +#include <linux/fs.h>
  61755. +#include <linux/namei.h>
  61756. +#include <linux/mount.h>
  61757. +#include <linux/tty.h>
  61758. +#include <linux/proc_fs.h>
  61759. +#include <linux/lglock.h>
  61760. +#include <linux/slab.h>
  61761. +#include <linux/vmalloc.h>
  61762. +#include <linux/types.h>
  61763. +#include <linux/sysctl.h>
  61764. +#include <linux/netdevice.h>
  61765. +#include <linux/ptrace.h>
  61766. +#include <linux/gracl.h>
  61767. +#include <linux/gralloc.h>
  61768. +#include <linux/security.h>
  61769. +#include <linux/grinternal.h>
  61770. +#include <linux/pid_namespace.h>
  61771. +#include <linux/stop_machine.h>
  61772. +#include <linux/fdtable.h>
  61773. +#include <linux/percpu.h>
  61774. +#include <linux/lglock.h>
  61775. +#include <linux/hugetlb.h>
  61776. +#include <linux/posix-timers.h>
  61777. +#include <linux/prefetch.h>
  61778. +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
  61779. +#include <linux/magic.h>
  61780. +#include <linux/pagemap.h>
  61781. +#include "../fs/btrfs/async-thread.h"
  61782. +#include "../fs/btrfs/ctree.h"
  61783. +#include "../fs/btrfs/btrfs_inode.h"
  61784. +#endif
  61785. +#include "../fs/mount.h"
  61786. +
  61787. +#include <asm/uaccess.h>
  61788. +#include <asm/errno.h>
  61789. +#include <asm/mman.h>
  61790. +
  61791. +#define FOR_EACH_ROLE_START(role) \
  61792. + role = running_polstate.role_list; \
  61793. + while (role) {
  61794. +
  61795. +#define FOR_EACH_ROLE_END(role) \
  61796. + role = role->prev; \
  61797. + }
  61798. +
  61799. +extern struct path gr_real_root;
  61800. +
  61801. +static struct gr_policy_state running_polstate;
  61802. +struct gr_policy_state *polstate = &running_polstate;
  61803. +extern struct gr_alloc_state *current_alloc_state;
  61804. +
  61805. +extern char *gr_shared_page[4];
  61806. +DEFINE_RWLOCK(gr_inode_lock);
  61807. +
  61808. +static unsigned int gr_status __read_only = GR_STATUS_INIT;
  61809. +
  61810. +#ifdef CONFIG_NET
  61811. +extern struct vfsmount *sock_mnt;
  61812. +#endif
  61813. +
  61814. +extern struct vfsmount *pipe_mnt;
  61815. +extern struct vfsmount *shm_mnt;
  61816. +
  61817. +#ifdef CONFIG_HUGETLBFS
  61818. +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
  61819. +#endif
  61820. +
  61821. +extern u16 acl_sp_role_value;
  61822. +extern struct acl_object_label *fakefs_obj_rw;
  61823. +extern struct acl_object_label *fakefs_obj_rwx;
  61824. +
  61825. +int gr_acl_is_enabled(void)
  61826. +{
  61827. + return (gr_status & GR_READY);
  61828. +}
  61829. +
  61830. +void gr_enable_rbac_system(void)
  61831. +{
  61832. + pax_open_kernel();
  61833. + gr_status |= GR_READY;
  61834. + pax_close_kernel();
  61835. +}
  61836. +
  61837. +int gr_rbac_disable(void *unused)
  61838. +{
  61839. + pax_open_kernel();
  61840. + gr_status &= ~GR_READY;
  61841. + pax_close_kernel();
  61842. +
  61843. + return 0;
  61844. +}
  61845. +
  61846. +static inline dev_t __get_dev(const struct dentry *dentry)
  61847. +{
  61848. +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
  61849. + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
  61850. + return BTRFS_I(dentry->d_inode)->root->anon_dev;
  61851. + else
  61852. +#endif
  61853. + return dentry->d_sb->s_dev;
  61854. +}
  61855. +
  61856. +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
  61857. +{
  61858. + return __get_dev(dentry);
  61859. +}
  61860. +
  61861. +static char gr_task_roletype_to_char(struct task_struct *task)
  61862. +{
  61863. + switch (task->role->roletype &
  61864. + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
  61865. + GR_ROLE_SPECIAL)) {
  61866. + case GR_ROLE_DEFAULT:
  61867. + return 'D';
  61868. + case GR_ROLE_USER:
  61869. + return 'U';
  61870. + case GR_ROLE_GROUP:
  61871. + return 'G';
  61872. + case GR_ROLE_SPECIAL:
  61873. + return 'S';
  61874. + }
  61875. +
  61876. + return 'X';
  61877. +}
  61878. +
  61879. +char gr_roletype_to_char(void)
  61880. +{
  61881. + return gr_task_roletype_to_char(current);
  61882. +}
  61883. +
  61884. +__inline__ int
  61885. +gr_acl_tpe_check(void)
  61886. +{
  61887. + if (unlikely(!(gr_status & GR_READY)))
  61888. + return 0;
  61889. + if (current->role->roletype & GR_ROLE_TPE)
  61890. + return 1;
  61891. + else
  61892. + return 0;
  61893. +}
  61894. +
  61895. +int
  61896. +gr_handle_rawio(const struct inode *inode)
  61897. +{
  61898. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  61899. + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
  61900. + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
  61901. + !capable(CAP_SYS_RAWIO))
  61902. + return 1;
  61903. +#endif
  61904. + return 0;
  61905. +}
  61906. +
  61907. +int
  61908. +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
  61909. +{
  61910. + if (likely(lena != lenb))
  61911. + return 0;
  61912. +
  61913. + return !memcmp(a, b, lena);
  61914. +}
  61915. +
  61916. +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
  61917. +{
  61918. + *buflen -= namelen;
  61919. + if (*buflen < 0)
  61920. + return -ENAMETOOLONG;
  61921. + *buffer -= namelen;
  61922. + memcpy(*buffer, str, namelen);
  61923. + return 0;
  61924. +}
  61925. +
  61926. +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
  61927. +{
  61928. + return prepend(buffer, buflen, name->name, name->len);
  61929. +}
  61930. +
  61931. +static int prepend_path(const struct path *path, struct path *root,
  61932. + char **buffer, int *buflen)
  61933. +{
  61934. + struct dentry *dentry = path->dentry;
  61935. + struct vfsmount *vfsmnt = path->mnt;
  61936. + struct mount *mnt = real_mount(vfsmnt);
  61937. + bool slash = false;
  61938. + int error = 0;
  61939. +
  61940. + while (dentry != root->dentry || vfsmnt != root->mnt) {
  61941. + struct dentry * parent;
  61942. +
  61943. + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
  61944. + /* Global root? */
  61945. + if (!mnt_has_parent(mnt)) {
  61946. + goto out;
  61947. + }
  61948. + dentry = mnt->mnt_mountpoint;
  61949. + mnt = mnt->mnt_parent;
  61950. + vfsmnt = &mnt->mnt;
  61951. + continue;
  61952. + }
  61953. + parent = dentry->d_parent;
  61954. + prefetch(parent);
  61955. + spin_lock(&dentry->d_lock);
  61956. + error = prepend_name(buffer, buflen, &dentry->d_name);
  61957. + spin_unlock(&dentry->d_lock);
  61958. + if (!error)
  61959. + error = prepend(buffer, buflen, "/", 1);
  61960. + if (error)
  61961. + break;
  61962. +
  61963. + slash = true;
  61964. + dentry = parent;
  61965. + }
  61966. +
  61967. +out:
  61968. + if (!error && !slash)
  61969. + error = prepend(buffer, buflen, "/", 1);
  61970. +
  61971. + return error;
  61972. +}
  61973. +
  61974. +/* this must be called with mount_lock and rename_lock held */
  61975. +
  61976. +static char *__our_d_path(const struct path *path, struct path *root,
  61977. + char *buf, int buflen)
  61978. +{
  61979. + char *res = buf + buflen;
  61980. + int error;
  61981. +
  61982. + prepend(&res, &buflen, "\0", 1);
  61983. + error = prepend_path(path, root, &res, &buflen);
  61984. + if (error)
  61985. + return ERR_PTR(error);
  61986. +
  61987. + return res;
  61988. +}
  61989. +
  61990. +static char *
  61991. +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
  61992. +{
  61993. + char *retval;
  61994. +
  61995. + retval = __our_d_path(path, root, buf, buflen);
  61996. + if (unlikely(IS_ERR(retval)))
  61997. + retval = strcpy(buf, "<path too long>");
  61998. + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
  61999. + retval[1] = '\0';
  62000. +
  62001. + return retval;
  62002. +}
  62003. +
  62004. +static char *
  62005. +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
  62006. + char *buf, int buflen)
  62007. +{
  62008. + struct path path;
  62009. + char *res;
  62010. +
  62011. + path.dentry = (struct dentry *)dentry;
  62012. + path.mnt = (struct vfsmount *)vfsmnt;
  62013. +
  62014. + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
  62015. + by the RBAC system */
  62016. + res = gen_full_path(&path, &gr_real_root, buf, buflen);
  62017. +
  62018. + return res;
  62019. +}
  62020. +
  62021. +static char *
  62022. +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
  62023. + char *buf, int buflen)
  62024. +{
  62025. + char *res;
  62026. + struct path path;
  62027. + struct path root;
  62028. + struct task_struct *reaper = init_pid_ns.child_reaper;
  62029. +
  62030. + path.dentry = (struct dentry *)dentry;
  62031. + path.mnt = (struct vfsmount *)vfsmnt;
  62032. +
  62033. + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
  62034. + get_fs_root(reaper->fs, &root);
  62035. +
  62036. + read_seqlock_excl(&mount_lock);
  62037. + write_seqlock(&rename_lock);
  62038. + res = gen_full_path(&path, &root, buf, buflen);
  62039. + write_sequnlock(&rename_lock);
  62040. + read_sequnlock_excl(&mount_lock);
  62041. +
  62042. + path_put(&root);
  62043. + return res;
  62044. +}
  62045. +
  62046. +char *
  62047. +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
  62048. +{
  62049. + char *ret;
  62050. + read_seqlock_excl(&mount_lock);
  62051. + write_seqlock(&rename_lock);
  62052. + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
  62053. + PAGE_SIZE);
  62054. + write_sequnlock(&rename_lock);
  62055. + read_sequnlock_excl(&mount_lock);
  62056. + return ret;
  62057. +}
  62058. +
  62059. +static char *
  62060. +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
  62061. +{
  62062. + char *ret;
  62063. + char *buf;
  62064. + int buflen;
  62065. +
  62066. + read_seqlock_excl(&mount_lock);
  62067. + write_seqlock(&rename_lock);
  62068. + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
  62069. + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
  62070. + buflen = (int)(ret - buf);
  62071. + if (buflen >= 5)
  62072. + prepend(&ret, &buflen, "/proc", 5);
  62073. + else
  62074. + ret = strcpy(buf, "<path too long>");
  62075. + write_sequnlock(&rename_lock);
  62076. + read_sequnlock_excl(&mount_lock);
  62077. + return ret;
  62078. +}
  62079. +
  62080. +char *
  62081. +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
  62082. +{
  62083. + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
  62084. + PAGE_SIZE);
  62085. +}
  62086. +
  62087. +char *
  62088. +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
  62089. +{
  62090. + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
  62091. + PAGE_SIZE);
  62092. +}
  62093. +
  62094. +char *
  62095. +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
  62096. +{
  62097. + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
  62098. + PAGE_SIZE);
  62099. +}
  62100. +
  62101. +char *
  62102. +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
  62103. +{
  62104. + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
  62105. + PAGE_SIZE);
  62106. +}
  62107. +
  62108. +char *
  62109. +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
  62110. +{
  62111. + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
  62112. + PAGE_SIZE);
  62113. +}
  62114. +
  62115. +__inline__ __u32
  62116. +to_gr_audit(const __u32 reqmode)
  62117. +{
  62118. + /* masks off auditable permission flags, then shifts them to create
  62119. + auditing flags, and adds the special case of append auditing if
  62120. + we're requesting write */
  62121. + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
  62122. +}
  62123. +
  62124. +struct acl_role_label *
  62125. +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
  62126. + const gid_t gid)
  62127. +{
  62128. + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
  62129. + struct acl_role_label *match;
  62130. + struct role_allowed_ip *ipp;
  62131. + unsigned int x;
  62132. + u32 curr_ip = task->signal->saved_ip;
  62133. +
  62134. + match = state->acl_role_set.r_hash[index];
  62135. +
  62136. + while (match) {
  62137. + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
  62138. + for (x = 0; x < match->domain_child_num; x++) {
  62139. + if (match->domain_children[x] == uid)
  62140. + goto found;
  62141. + }
  62142. + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
  62143. + break;
  62144. + match = match->next;
  62145. + }
  62146. +found:
  62147. + if (match == NULL) {
  62148. + try_group:
  62149. + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
  62150. + match = state->acl_role_set.r_hash[index];
  62151. +
  62152. + while (match) {
  62153. + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
  62154. + for (x = 0; x < match->domain_child_num; x++) {
  62155. + if (match->domain_children[x] == gid)
  62156. + goto found2;
  62157. + }
  62158. + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
  62159. + break;
  62160. + match = match->next;
  62161. + }
  62162. +found2:
  62163. + if (match == NULL)
  62164. + match = state->default_role;
  62165. + if (match->allowed_ips == NULL)
  62166. + return match;
  62167. + else {
  62168. + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
  62169. + if (likely
  62170. + ((ntohl(curr_ip) & ipp->netmask) ==
  62171. + (ntohl(ipp->addr) & ipp->netmask)))
  62172. + return match;
  62173. + }
  62174. + match = state->default_role;
  62175. + }
  62176. + } else if (match->allowed_ips == NULL) {
  62177. + return match;
  62178. + } else {
  62179. + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
  62180. + if (likely
  62181. + ((ntohl(curr_ip) & ipp->netmask) ==
  62182. + (ntohl(ipp->addr) & ipp->netmask)))
  62183. + return match;
  62184. + }
  62185. + goto try_group;
  62186. + }
  62187. +
  62188. + return match;
  62189. +}
  62190. +
  62191. +static struct acl_role_label *
  62192. +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
  62193. + const gid_t gid)
  62194. +{
  62195. + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
  62196. +}
  62197. +
  62198. +struct acl_subject_label *
  62199. +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
  62200. + const struct acl_role_label *role)
  62201. +{
  62202. + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
  62203. + struct acl_subject_label *match;
  62204. +
  62205. + match = role->subj_hash[index];
  62206. +
  62207. + while (match && (match->inode != ino || match->device != dev ||
  62208. + (match->mode & GR_DELETED))) {
  62209. + match = match->next;
  62210. + }
  62211. +
  62212. + if (match && !(match->mode & GR_DELETED))
  62213. + return match;
  62214. + else
  62215. + return NULL;
  62216. +}
  62217. +
  62218. +struct acl_subject_label *
  62219. +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
  62220. + const struct acl_role_label *role)
  62221. +{
  62222. + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
  62223. + struct acl_subject_label *match;
  62224. +
  62225. + match = role->subj_hash[index];
  62226. +
  62227. + while (match && (match->inode != ino || match->device != dev ||
  62228. + !(match->mode & GR_DELETED))) {
  62229. + match = match->next;
  62230. + }
  62231. +
  62232. + if (match && (match->mode & GR_DELETED))
  62233. + return match;
  62234. + else
  62235. + return NULL;
  62236. +}
  62237. +
  62238. +static struct acl_object_label *
  62239. +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
  62240. + const struct acl_subject_label *subj)
  62241. +{
  62242. + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
  62243. + struct acl_object_label *match;
  62244. +
  62245. + match = subj->obj_hash[index];
  62246. +
  62247. + while (match && (match->inode != ino || match->device != dev ||
  62248. + (match->mode & GR_DELETED))) {
  62249. + match = match->next;
  62250. + }
  62251. +
  62252. + if (match && !(match->mode & GR_DELETED))
  62253. + return match;
  62254. + else
  62255. + return NULL;
  62256. +}
  62257. +
  62258. +static struct acl_object_label *
  62259. +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
  62260. + const struct acl_subject_label *subj)
  62261. +{
  62262. + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
  62263. + struct acl_object_label *match;
  62264. +
  62265. + match = subj->obj_hash[index];
  62266. +
  62267. + while (match && (match->inode != ino || match->device != dev ||
  62268. + !(match->mode & GR_DELETED))) {
  62269. + match = match->next;
  62270. + }
  62271. +
  62272. + if (match && (match->mode & GR_DELETED))
  62273. + return match;
  62274. +
  62275. + match = subj->obj_hash[index];
  62276. +
  62277. + while (match && (match->inode != ino || match->device != dev ||
  62278. + (match->mode & GR_DELETED))) {
  62279. + match = match->next;
  62280. + }
  62281. +
  62282. + if (match && !(match->mode & GR_DELETED))
  62283. + return match;
  62284. + else
  62285. + return NULL;
  62286. +}
  62287. +
  62288. +struct name_entry *
  62289. +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
  62290. +{
  62291. + unsigned int len = strlen(name);
  62292. + unsigned int key = full_name_hash(name, len);
  62293. + unsigned int index = key % state->name_set.n_size;
  62294. + struct name_entry *match;
  62295. +
  62296. + match = state->name_set.n_hash[index];
  62297. +
  62298. + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
  62299. + match = match->next;
  62300. +
  62301. + return match;
  62302. +}
  62303. +
  62304. +static struct name_entry *
  62305. +lookup_name_entry(const char *name)
  62306. +{
  62307. + return __lookup_name_entry(&running_polstate, name);
  62308. +}
  62309. +
  62310. +static struct name_entry *
  62311. +lookup_name_entry_create(const char *name)
  62312. +{
  62313. + unsigned int len = strlen(name);
  62314. + unsigned int key = full_name_hash(name, len);
  62315. + unsigned int index = key % running_polstate.name_set.n_size;
  62316. + struct name_entry *match;
  62317. +
  62318. + match = running_polstate.name_set.n_hash[index];
  62319. +
  62320. + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
  62321. + !match->deleted))
  62322. + match = match->next;
  62323. +
  62324. + if (match && match->deleted)
  62325. + return match;
  62326. +
  62327. + match = running_polstate.name_set.n_hash[index];
  62328. +
  62329. + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
  62330. + match->deleted))
  62331. + match = match->next;
  62332. +
  62333. + if (match && !match->deleted)
  62334. + return match;
  62335. + else
  62336. + return NULL;
  62337. +}
  62338. +
  62339. +static struct inodev_entry *
  62340. +lookup_inodev_entry(const ino_t ino, const dev_t dev)
  62341. +{
  62342. + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
  62343. + struct inodev_entry *match;
  62344. +
  62345. + match = running_polstate.inodev_set.i_hash[index];
  62346. +
  62347. + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
  62348. + match = match->next;
  62349. +
  62350. + return match;
  62351. +}
  62352. +
  62353. +void
  62354. +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
  62355. +{
  62356. + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
  62357. + state->inodev_set.i_size);
  62358. + struct inodev_entry **curr;
  62359. +
  62360. + entry->prev = NULL;
  62361. +
  62362. + curr = &state->inodev_set.i_hash[index];
  62363. + if (*curr != NULL)
  62364. + (*curr)->prev = entry;
  62365. +
  62366. + entry->next = *curr;
  62367. + *curr = entry;
  62368. +
  62369. + return;
  62370. +}
  62371. +
  62372. +static void
  62373. +insert_inodev_entry(struct inodev_entry *entry)
  62374. +{
  62375. + __insert_inodev_entry(&running_polstate, entry);
  62376. +}
  62377. +
  62378. +void
  62379. +insert_acl_obj_label(struct acl_object_label *obj,
  62380. + struct acl_subject_label *subj)
  62381. +{
  62382. + unsigned int index =
  62383. + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
  62384. + struct acl_object_label **curr;
  62385. +
  62386. + obj->prev = NULL;
  62387. +
  62388. + curr = &subj->obj_hash[index];
  62389. + if (*curr != NULL)
  62390. + (*curr)->prev = obj;
  62391. +
  62392. + obj->next = *curr;
  62393. + *curr = obj;
  62394. +
  62395. + return;
  62396. +}
  62397. +
  62398. +void
  62399. +insert_acl_subj_label(struct acl_subject_label *obj,
  62400. + struct acl_role_label *role)
  62401. +{
  62402. + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
  62403. + struct acl_subject_label **curr;
  62404. +
  62405. + obj->prev = NULL;
  62406. +
  62407. + curr = &role->subj_hash[index];
  62408. + if (*curr != NULL)
  62409. + (*curr)->prev = obj;
  62410. +
  62411. + obj->next = *curr;
  62412. + *curr = obj;
  62413. +
  62414. + return;
  62415. +}
  62416. +
  62417. +/* derived from glibc fnmatch() 0: match, 1: no match*/
  62418. +
  62419. +static int
  62420. +glob_match(const char *p, const char *n)
  62421. +{
  62422. + char c;
  62423. +
  62424. + while ((c = *p++) != '\0') {
  62425. + switch (c) {
  62426. + case '?':
  62427. + if (*n == '\0')
  62428. + return 1;
  62429. + else if (*n == '/')
  62430. + return 1;
  62431. + break;
  62432. + case '\\':
  62433. + if (*n != c)
  62434. + return 1;
  62435. + break;
  62436. + case '*':
  62437. + for (c = *p++; c == '?' || c == '*'; c = *p++) {
  62438. + if (*n == '/')
  62439. + return 1;
  62440. + else if (c == '?') {
  62441. + if (*n == '\0')
  62442. + return 1;
  62443. + else
  62444. + ++n;
  62445. + }
  62446. + }
  62447. + if (c == '\0') {
  62448. + return 0;
  62449. + } else {
  62450. + const char *endp;
  62451. +
  62452. + if ((endp = strchr(n, '/')) == NULL)
  62453. + endp = n + strlen(n);
  62454. +
  62455. + if (c == '[') {
  62456. + for (--p; n < endp; ++n)
  62457. + if (!glob_match(p, n))
  62458. + return 0;
  62459. + } else if (c == '/') {
  62460. + while (*n != '\0' && *n != '/')
  62461. + ++n;
  62462. + if (*n == '/' && !glob_match(p, n + 1))
  62463. + return 0;
  62464. + } else {
  62465. + for (--p; n < endp; ++n)
  62466. + if (*n == c && !glob_match(p, n))
  62467. + return 0;
  62468. + }
  62469. +
  62470. + return 1;
  62471. + }
  62472. + case '[':
  62473. + {
  62474. + int not;
  62475. + char cold;
  62476. +
  62477. + if (*n == '\0' || *n == '/')
  62478. + return 1;
  62479. +
  62480. + not = (*p == '!' || *p == '^');
  62481. + if (not)
  62482. + ++p;
  62483. +
  62484. + c = *p++;
  62485. + for (;;) {
  62486. + unsigned char fn = (unsigned char)*n;
  62487. +
  62488. + if (c == '\0')
  62489. + return 1;
  62490. + else {
  62491. + if (c == fn)
  62492. + goto matched;
  62493. + cold = c;
  62494. + c = *p++;
  62495. +
  62496. + if (c == '-' && *p != ']') {
  62497. + unsigned char cend = *p++;
  62498. +
  62499. + if (cend == '\0')
  62500. + return 1;
  62501. +
  62502. + if (cold <= fn && fn <= cend)
  62503. + goto matched;
  62504. +
  62505. + c = *p++;
  62506. + }
  62507. + }
  62508. +
  62509. + if (c == ']')
  62510. + break;
  62511. + }
  62512. + if (!not)
  62513. + return 1;
  62514. + break;
  62515. + matched:
  62516. + while (c != ']') {
  62517. + if (c == '\0')
  62518. + return 1;
  62519. +
  62520. + c = *p++;
  62521. + }
  62522. + if (not)
  62523. + return 1;
  62524. + }
  62525. + break;
  62526. + default:
  62527. + if (c != *n)
  62528. + return 1;
  62529. + }
  62530. +
  62531. + ++n;
  62532. + }
  62533. +
  62534. + if (*n == '\0')
  62535. + return 0;
  62536. +
  62537. + if (*n == '/')
  62538. + return 0;
  62539. +
  62540. + return 1;
  62541. +}
  62542. +
  62543. +static struct acl_object_label *
  62544. +chk_glob_label(struct acl_object_label *globbed,
  62545. + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
  62546. +{
  62547. + struct acl_object_label *tmp;
  62548. +
  62549. + if (*path == NULL)
  62550. + *path = gr_to_filename_nolock(dentry, mnt);
  62551. +
  62552. + tmp = globbed;
  62553. +
  62554. + while (tmp) {
  62555. + if (!glob_match(tmp->filename, *path))
  62556. + return tmp;
  62557. + tmp = tmp->next;
  62558. + }
  62559. +
  62560. + return NULL;
  62561. +}
  62562. +
  62563. +static struct acl_object_label *
  62564. +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
  62565. + const ino_t curr_ino, const dev_t curr_dev,
  62566. + const struct acl_subject_label *subj, char **path, const int checkglob)
  62567. +{
  62568. + struct acl_subject_label *tmpsubj;
  62569. + struct acl_object_label *retval;
  62570. + struct acl_object_label *retval2;
  62571. +
  62572. + tmpsubj = (struct acl_subject_label *) subj;
  62573. + read_lock(&gr_inode_lock);
  62574. + do {
  62575. + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
  62576. + if (retval) {
  62577. + if (checkglob && retval->globbed) {
  62578. + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
  62579. + if (retval2)
  62580. + retval = retval2;
  62581. + }
  62582. + break;
  62583. + }
  62584. + } while ((tmpsubj = tmpsubj->parent_subject));
  62585. + read_unlock(&gr_inode_lock);
  62586. +
  62587. + return retval;
  62588. +}
  62589. +
  62590. +static __inline__ struct acl_object_label *
  62591. +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
  62592. + struct dentry *curr_dentry,
  62593. + const struct acl_subject_label *subj, char **path, const int checkglob)
  62594. +{
  62595. + int newglob = checkglob;
  62596. + ino_t inode;
  62597. + dev_t device;
  62598. +
  62599. + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
  62600. + as we don't want a / * rule to match instead of the / object
  62601. + don't do this for create lookups that call this function though, since they're looking up
  62602. + on the parent and thus need globbing checks on all paths
  62603. + */
  62604. + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
  62605. + newglob = GR_NO_GLOB;
  62606. +
  62607. + spin_lock(&curr_dentry->d_lock);
  62608. + inode = curr_dentry->d_inode->i_ino;
  62609. + device = __get_dev(curr_dentry);
  62610. + spin_unlock(&curr_dentry->d_lock);
  62611. +
  62612. + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
  62613. +}
  62614. +
  62615. +#ifdef CONFIG_HUGETLBFS
  62616. +static inline bool
  62617. +is_hugetlbfs_mnt(const struct vfsmount *mnt)
  62618. +{
  62619. + int i;
  62620. + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
  62621. + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
  62622. + return true;
  62623. + }
  62624. +
  62625. + return false;
  62626. +}
  62627. +#endif
  62628. +
  62629. +static struct acl_object_label *
  62630. +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
  62631. + const struct acl_subject_label *subj, char *path, const int checkglob)
  62632. +{
  62633. + struct dentry *dentry = (struct dentry *) l_dentry;
  62634. + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
  62635. + struct mount *real_mnt = real_mount(mnt);
  62636. + struct acl_object_label *retval;
  62637. + struct dentry *parent;
  62638. +
  62639. + read_seqlock_excl(&mount_lock);
  62640. + write_seqlock(&rename_lock);
  62641. +
  62642. + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
  62643. +#ifdef CONFIG_NET
  62644. + mnt == sock_mnt ||
  62645. +#endif
  62646. +#ifdef CONFIG_HUGETLBFS
  62647. + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
  62648. +#endif
  62649. + /* ignore Eric Biederman */
  62650. + IS_PRIVATE(l_dentry->d_inode))) {
  62651. + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
  62652. + goto out;
  62653. + }
  62654. +
  62655. + for (;;) {
  62656. + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
  62657. + break;
  62658. +
  62659. + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
  62660. + if (!mnt_has_parent(real_mnt))
  62661. + break;
  62662. +
  62663. + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
  62664. + if (retval != NULL)
  62665. + goto out;
  62666. +
  62667. + dentry = real_mnt->mnt_mountpoint;
  62668. + real_mnt = real_mnt->mnt_parent;
  62669. + mnt = &real_mnt->mnt;
  62670. + continue;
  62671. + }
  62672. +
  62673. + parent = dentry->d_parent;
  62674. + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
  62675. + if (retval != NULL)
  62676. + goto out;
  62677. +
  62678. + dentry = parent;
  62679. + }
  62680. +
  62681. + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
  62682. +
  62683. + /* gr_real_root is pinned so we don't have to hold a reference */
  62684. + if (retval == NULL)
  62685. + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
  62686. +out:
  62687. + write_sequnlock(&rename_lock);
  62688. + read_sequnlock_excl(&mount_lock);
  62689. +
  62690. + BUG_ON(retval == NULL);
  62691. +
  62692. + return retval;
  62693. +}
  62694. +
  62695. +static __inline__ struct acl_object_label *
  62696. +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
  62697. + const struct acl_subject_label *subj)
  62698. +{
  62699. + char *path = NULL;
  62700. + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
  62701. +}
  62702. +
  62703. +static __inline__ struct acl_object_label *
  62704. +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
  62705. + const struct acl_subject_label *subj)
  62706. +{
  62707. + char *path = NULL;
  62708. + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
  62709. +}
  62710. +
  62711. +static __inline__ struct acl_object_label *
  62712. +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
  62713. + const struct acl_subject_label *subj, char *path)
  62714. +{
  62715. + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
  62716. +}
  62717. +
  62718. +struct acl_subject_label *
  62719. +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
  62720. + const struct acl_role_label *role)
  62721. +{
  62722. + struct dentry *dentry = (struct dentry *) l_dentry;
  62723. + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
  62724. + struct mount *real_mnt = real_mount(mnt);
  62725. + struct acl_subject_label *retval;
  62726. + struct dentry *parent;
  62727. +
  62728. + read_seqlock_excl(&mount_lock);
  62729. + write_seqlock(&rename_lock);
  62730. +
  62731. + for (;;) {
  62732. + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
  62733. + break;
  62734. + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
  62735. + if (!mnt_has_parent(real_mnt))
  62736. + break;
  62737. +
  62738. + spin_lock(&dentry->d_lock);
  62739. + read_lock(&gr_inode_lock);
  62740. + retval =
  62741. + lookup_acl_subj_label(dentry->d_inode->i_ino,
  62742. + __get_dev(dentry), role);
  62743. + read_unlock(&gr_inode_lock);
  62744. + spin_unlock(&dentry->d_lock);
  62745. + if (retval != NULL)
  62746. + goto out;
  62747. +
  62748. + dentry = real_mnt->mnt_mountpoint;
  62749. + real_mnt = real_mnt->mnt_parent;
  62750. + mnt = &real_mnt->mnt;
  62751. + continue;
  62752. + }
  62753. +
  62754. + spin_lock(&dentry->d_lock);
  62755. + read_lock(&gr_inode_lock);
  62756. + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
  62757. + __get_dev(dentry), role);
  62758. + read_unlock(&gr_inode_lock);
  62759. + parent = dentry->d_parent;
  62760. + spin_unlock(&dentry->d_lock);
  62761. +
  62762. + if (retval != NULL)
  62763. + goto out;
  62764. +
  62765. + dentry = parent;
  62766. + }
  62767. +
  62768. + spin_lock(&dentry->d_lock);
  62769. + read_lock(&gr_inode_lock);
  62770. + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
  62771. + __get_dev(dentry), role);
  62772. + read_unlock(&gr_inode_lock);
  62773. + spin_unlock(&dentry->d_lock);
  62774. +
  62775. + if (unlikely(retval == NULL)) {
  62776. + /* gr_real_root is pinned, we don't need to hold a reference */
  62777. + read_lock(&gr_inode_lock);
  62778. + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
  62779. + __get_dev(gr_real_root.dentry), role);
  62780. + read_unlock(&gr_inode_lock);
  62781. + }
  62782. +out:
  62783. + write_sequnlock(&rename_lock);
  62784. + read_sequnlock_excl(&mount_lock);
  62785. +
  62786. + BUG_ON(retval == NULL);
  62787. +
  62788. + return retval;
  62789. +}
  62790. +
  62791. +void
  62792. +assign_special_role(const char *rolename)
  62793. +{
  62794. + struct acl_object_label *obj;
  62795. + struct acl_role_label *r;
  62796. + struct acl_role_label *assigned = NULL;
  62797. + struct task_struct *tsk;
  62798. + struct file *filp;
  62799. +
  62800. + FOR_EACH_ROLE_START(r)
  62801. + if (!strcmp(rolename, r->rolename) &&
  62802. + (r->roletype & GR_ROLE_SPECIAL)) {
  62803. + assigned = r;
  62804. + break;
  62805. + }
  62806. + FOR_EACH_ROLE_END(r)
  62807. +
  62808. + if (!assigned)
  62809. + return;
  62810. +
  62811. + read_lock(&tasklist_lock);
  62812. + read_lock(&grsec_exec_file_lock);
  62813. +
  62814. + tsk = current->real_parent;
  62815. + if (tsk == NULL)
  62816. + goto out_unlock;
  62817. +
  62818. + filp = tsk->exec_file;
  62819. + if (filp == NULL)
  62820. + goto out_unlock;
  62821. +
  62822. + tsk->is_writable = 0;
  62823. + tsk->inherited = 0;
  62824. +
  62825. + tsk->acl_sp_role = 1;
  62826. + tsk->acl_role_id = ++acl_sp_role_value;
  62827. + tsk->role = assigned;
  62828. + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
  62829. +
  62830. + /* ignore additional mmap checks for processes that are writable
  62831. + by the default ACL */
  62832. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
  62833. + if (unlikely(obj->mode & GR_WRITE))
  62834. + tsk->is_writable = 1;
  62835. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
  62836. + if (unlikely(obj->mode & GR_WRITE))
  62837. + tsk->is_writable = 1;
  62838. +
  62839. +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
  62840. + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
  62841. + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
  62842. +#endif
  62843. +
  62844. +out_unlock:
  62845. + read_unlock(&grsec_exec_file_lock);
  62846. + read_unlock(&tasklist_lock);
  62847. + return;
  62848. +}
  62849. +
  62850. +
  62851. +static void
  62852. +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
  62853. +{
  62854. + struct task_struct *task = current;
  62855. + const struct cred *cred = current_cred();
  62856. +
  62857. + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
  62858. + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
  62859. + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
  62860. + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
  62861. +
  62862. + return;
  62863. +}
  62864. +
  62865. +static void
  62866. +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
  62867. +{
  62868. + struct task_struct *task = current;
  62869. + const struct cred *cred = current_cred();
  62870. +
  62871. + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
  62872. + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
  62873. + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
  62874. + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
  62875. +
  62876. + return;
  62877. +}
  62878. +
  62879. +static void
  62880. +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
  62881. +{
  62882. + struct task_struct *task = current;
  62883. + const struct cred *cred = current_cred();
  62884. +
  62885. + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
  62886. + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
  62887. + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
  62888. + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
  62889. +
  62890. + return;
  62891. +}
  62892. +
  62893. +static void
  62894. +gr_set_proc_res(struct task_struct *task)
  62895. +{
  62896. + struct acl_subject_label *proc;
  62897. + unsigned short i;
  62898. +
  62899. + proc = task->acl;
  62900. +
  62901. + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
  62902. + return;
  62903. +
  62904. + for (i = 0; i < RLIM_NLIMITS; i++) {
  62905. + if (!(proc->resmask & (1U << i)))
  62906. + continue;
  62907. +
  62908. + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
  62909. + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
  62910. +
  62911. + if (i == RLIMIT_CPU)
  62912. + update_rlimit_cpu(task, proc->res[i].rlim_cur);
  62913. + }
  62914. +
  62915. + return;
  62916. +}
  62917. +
  62918. +/* both of the below must be called with
  62919. + rcu_read_lock();
  62920. + read_lock(&tasklist_lock);
  62921. + read_lock(&grsec_exec_file_lock);
  62922. +*/
  62923. +
  62924. +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
  62925. +{
  62926. + char *tmpname;
  62927. + struct acl_subject_label *tmpsubj;
  62928. + struct file *filp;
  62929. + struct name_entry *nmatch;
  62930. +
  62931. + filp = task->exec_file;
  62932. + if (filp == NULL)
  62933. + return NULL;
  62934. +
  62935. + /* the following is to apply the correct subject
  62936. + on binaries running when the RBAC system
  62937. + is enabled, when the binaries have been
  62938. + replaced or deleted since their execution
  62939. + -----
  62940. + when the RBAC system starts, the inode/dev
  62941. + from exec_file will be one the RBAC system
  62942. + is unaware of. It only knows the inode/dev
  62943. + of the present file on disk, or the absence
  62944. + of it.
  62945. + */
  62946. +
  62947. + if (filename)
  62948. + nmatch = __lookup_name_entry(state, filename);
  62949. + else {
  62950. + preempt_disable();
  62951. + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
  62952. +
  62953. + nmatch = __lookup_name_entry(state, tmpname);
  62954. + preempt_enable();
  62955. + }
  62956. + tmpsubj = NULL;
  62957. + if (nmatch) {
  62958. + if (nmatch->deleted)
  62959. + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
  62960. + else
  62961. + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
  62962. + }
  62963. + /* this also works for the reload case -- if we don't match a potentially inherited subject
  62964. + then we fall back to a normal lookup based on the binary's ino/dev
  62965. + */
  62966. + if (tmpsubj == NULL)
  62967. + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
  62968. +
  62969. + return tmpsubj;
  62970. +}
  62971. +
  62972. +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
  62973. +{
  62974. + return __gr_get_subject_for_task(&running_polstate, task, filename);
  62975. +}
  62976. +
  62977. +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
  62978. +{
  62979. + struct acl_object_label *obj;
  62980. + struct file *filp;
  62981. +
  62982. + filp = task->exec_file;
  62983. +
  62984. + task->acl = subj;
  62985. + task->is_writable = 0;
  62986. + /* ignore additional mmap checks for processes that are writable
  62987. + by the default ACL */
  62988. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
  62989. + if (unlikely(obj->mode & GR_WRITE))
  62990. + task->is_writable = 1;
  62991. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
  62992. + if (unlikely(obj->mode & GR_WRITE))
  62993. + task->is_writable = 1;
  62994. +
  62995. + gr_set_proc_res(task);
  62996. +
  62997. +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
  62998. + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
  62999. +#endif
  63000. +}
  63001. +
  63002. +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
  63003. +{
  63004. + __gr_apply_subject_to_task(&running_polstate, task, subj);
  63005. +}
  63006. +
  63007. +__u32
  63008. +gr_search_file(const struct dentry * dentry, const __u32 mode,
  63009. + const struct vfsmount * mnt)
  63010. +{
  63011. + __u32 retval = mode;
  63012. + struct acl_subject_label *curracl;
  63013. + struct acl_object_label *currobj;
  63014. +
  63015. + if (unlikely(!(gr_status & GR_READY)))
  63016. + return (mode & ~GR_AUDITS);
  63017. +
  63018. + curracl = current->acl;
  63019. +
  63020. + currobj = chk_obj_label(dentry, mnt, curracl);
  63021. + retval = currobj->mode & mode;
  63022. +
  63023. + /* if we're opening a specified transfer file for writing
  63024. + (e.g. /dev/initctl), then transfer our role to init
  63025. + */
  63026. + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
  63027. + current->role->roletype & GR_ROLE_PERSIST)) {
  63028. + struct task_struct *task = init_pid_ns.child_reaper;
  63029. +
  63030. + if (task->role != current->role) {
  63031. + struct acl_subject_label *subj;
  63032. +
  63033. + task->acl_sp_role = 0;
  63034. + task->acl_role_id = current->acl_role_id;
  63035. + task->role = current->role;
  63036. + rcu_read_lock();
  63037. + read_lock(&grsec_exec_file_lock);
  63038. + subj = gr_get_subject_for_task(task, NULL);
  63039. + gr_apply_subject_to_task(task, subj);
  63040. + read_unlock(&grsec_exec_file_lock);
  63041. + rcu_read_unlock();
  63042. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
  63043. + }
  63044. + }
  63045. +
  63046. + if (unlikely
  63047. + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
  63048. + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
  63049. + __u32 new_mode = mode;
  63050. +
  63051. + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
  63052. +
  63053. + retval = new_mode;
  63054. +
  63055. + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
  63056. + new_mode |= GR_INHERIT;
  63057. +
  63058. + if (!(mode & GR_NOLEARN))
  63059. + gr_log_learn(dentry, mnt, new_mode);
  63060. + }
  63061. +
  63062. + return retval;
  63063. +}
  63064. +
  63065. +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
  63066. + const struct dentry *parent,
  63067. + const struct vfsmount *mnt)
  63068. +{
  63069. + struct name_entry *match;
  63070. + struct acl_object_label *matchpo;
  63071. + struct acl_subject_label *curracl;
  63072. + char *path;
  63073. +
  63074. + if (unlikely(!(gr_status & GR_READY)))
  63075. + return NULL;
  63076. +
  63077. + preempt_disable();
  63078. + path = gr_to_filename_rbac(new_dentry, mnt);
  63079. + match = lookup_name_entry_create(path);
  63080. +
  63081. + curracl = current->acl;
  63082. +
  63083. + if (match) {
  63084. + read_lock(&gr_inode_lock);
  63085. + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
  63086. + read_unlock(&gr_inode_lock);
  63087. +
  63088. + if (matchpo) {
  63089. + preempt_enable();
  63090. + return matchpo;
  63091. + }
  63092. + }
  63093. +
  63094. + // lookup parent
  63095. +
  63096. + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
  63097. +
  63098. + preempt_enable();
  63099. + return matchpo;
  63100. +}
  63101. +
  63102. +__u32
  63103. +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
  63104. + const struct vfsmount * mnt, const __u32 mode)
  63105. +{
  63106. + struct acl_object_label *matchpo;
  63107. + __u32 retval;
  63108. +
  63109. + if (unlikely(!(gr_status & GR_READY)))
  63110. + return (mode & ~GR_AUDITS);
  63111. +
  63112. + matchpo = gr_get_create_object(new_dentry, parent, mnt);
  63113. +
  63114. + retval = matchpo->mode & mode;
  63115. +
  63116. + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
  63117. + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
  63118. + __u32 new_mode = mode;
  63119. +
  63120. + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
  63121. +
  63122. + gr_log_learn(new_dentry, mnt, new_mode);
  63123. + return new_mode;
  63124. + }
  63125. +
  63126. + return retval;
  63127. +}
  63128. +
  63129. +__u32
  63130. +gr_check_link(const struct dentry * new_dentry,
  63131. + const struct dentry * parent_dentry,
  63132. + const struct vfsmount * parent_mnt,
  63133. + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
  63134. +{
  63135. + struct acl_object_label *obj;
  63136. + __u32 oldmode, newmode;
  63137. + __u32 needmode;
  63138. + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
  63139. + GR_DELETE | GR_INHERIT;
  63140. +
  63141. + if (unlikely(!(gr_status & GR_READY)))
  63142. + return (GR_CREATE | GR_LINK);
  63143. +
  63144. + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
  63145. + oldmode = obj->mode;
  63146. +
  63147. + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
  63148. + newmode = obj->mode;
  63149. +
  63150. + needmode = newmode & checkmodes;
  63151. +
  63152. + // old name for hardlink must have at least the permissions of the new name
  63153. + if ((oldmode & needmode) != needmode)
  63154. + goto bad;
  63155. +
  63156. + // if old name had restrictions/auditing, make sure the new name does as well
  63157. + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
  63158. +
  63159. + // don't allow hardlinking of suid/sgid/fcapped files without permission
  63160. + if (is_privileged_binary(old_dentry))
  63161. + needmode |= GR_SETID;
  63162. +
  63163. + if ((newmode & needmode) != needmode)
  63164. + goto bad;
  63165. +
  63166. + // enforce minimum permissions
  63167. + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
  63168. + return newmode;
  63169. +bad:
  63170. + needmode = oldmode;
  63171. + if (is_privileged_binary(old_dentry))
  63172. + needmode |= GR_SETID;
  63173. +
  63174. + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
  63175. + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
  63176. + return (GR_CREATE | GR_LINK);
  63177. + } else if (newmode & GR_SUPPRESS)
  63178. + return GR_SUPPRESS;
  63179. + else
  63180. + return 0;
  63181. +}
  63182. +
  63183. +int
  63184. +gr_check_hidden_task(const struct task_struct *task)
  63185. +{
  63186. + if (unlikely(!(gr_status & GR_READY)))
  63187. + return 0;
  63188. +
  63189. + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
  63190. + return 1;
  63191. +
  63192. + return 0;
  63193. +}
  63194. +
  63195. +int
  63196. +gr_check_protected_task(const struct task_struct *task)
  63197. +{
  63198. + if (unlikely(!(gr_status & GR_READY) || !task))
  63199. + return 0;
  63200. +
  63201. + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
  63202. + task->acl != current->acl)
  63203. + return 1;
  63204. +
  63205. + return 0;
  63206. +}
  63207. +
  63208. +int
  63209. +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
  63210. +{
  63211. + struct task_struct *p;
  63212. + int ret = 0;
  63213. +
  63214. + if (unlikely(!(gr_status & GR_READY) || !pid))
  63215. + return ret;
  63216. +
  63217. + read_lock(&tasklist_lock);
  63218. + do_each_pid_task(pid, type, p) {
  63219. + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
  63220. + p->acl != current->acl) {
  63221. + ret = 1;
  63222. + goto out;
  63223. + }
  63224. + } while_each_pid_task(pid, type, p);
  63225. +out:
  63226. + read_unlock(&tasklist_lock);
  63227. +
  63228. + return ret;
  63229. +}
  63230. +
  63231. +void
  63232. +gr_copy_label(struct task_struct *tsk)
  63233. +{
  63234. + struct task_struct *p = current;
  63235. +
  63236. + tsk->inherited = p->inherited;
  63237. + tsk->acl_sp_role = 0;
  63238. + tsk->acl_role_id = p->acl_role_id;
  63239. + tsk->acl = p->acl;
  63240. + tsk->role = p->role;
  63241. + tsk->signal->used_accept = 0;
  63242. + tsk->signal->curr_ip = p->signal->curr_ip;
  63243. + tsk->signal->saved_ip = p->signal->saved_ip;
  63244. + if (p->exec_file)
  63245. + get_file(p->exec_file);
  63246. + tsk->exec_file = p->exec_file;
  63247. + tsk->is_writable = p->is_writable;
  63248. + if (unlikely(p->signal->used_accept)) {
  63249. + p->signal->curr_ip = 0;
  63250. + p->signal->saved_ip = 0;
  63251. + }
  63252. +
  63253. + return;
  63254. +}
  63255. +
  63256. +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
  63257. +
  63258. +int
  63259. +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
  63260. +{
  63261. + unsigned int i;
  63262. + __u16 num;
  63263. + uid_t *uidlist;
  63264. + uid_t curuid;
  63265. + int realok = 0;
  63266. + int effectiveok = 0;
  63267. + int fsok = 0;
  63268. + uid_t globalreal, globaleffective, globalfs;
  63269. +
  63270. +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
  63271. + struct user_struct *user;
  63272. +
  63273. + if (!uid_valid(real))
  63274. + goto skipit;
  63275. +
  63276. + /* find user based on global namespace */
  63277. +
  63278. + globalreal = GR_GLOBAL_UID(real);
  63279. +
  63280. + user = find_user(make_kuid(&init_user_ns, globalreal));
  63281. + if (user == NULL)
  63282. + goto skipit;
  63283. +
  63284. + if (gr_process_kernel_setuid_ban(user)) {
  63285. + /* for find_user */
  63286. + free_uid(user);
  63287. + return 1;
  63288. + }
  63289. +
  63290. + /* for find_user */
  63291. + free_uid(user);
  63292. +
  63293. +skipit:
  63294. +#endif
  63295. +
  63296. + if (unlikely(!(gr_status & GR_READY)))
  63297. + return 0;
  63298. +
  63299. + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
  63300. + gr_log_learn_uid_change(real, effective, fs);
  63301. +
  63302. + num = current->acl->user_trans_num;
  63303. + uidlist = current->acl->user_transitions;
  63304. +
  63305. + if (uidlist == NULL)
  63306. + return 0;
  63307. +
  63308. + if (!uid_valid(real)) {
  63309. + realok = 1;
  63310. + globalreal = (uid_t)-1;
  63311. + } else {
  63312. + globalreal = GR_GLOBAL_UID(real);
  63313. + }
  63314. + if (!uid_valid(effective)) {
  63315. + effectiveok = 1;
  63316. + globaleffective = (uid_t)-1;
  63317. + } else {
  63318. + globaleffective = GR_GLOBAL_UID(effective);
  63319. + }
  63320. + if (!uid_valid(fs)) {
  63321. + fsok = 1;
  63322. + globalfs = (uid_t)-1;
  63323. + } else {
  63324. + globalfs = GR_GLOBAL_UID(fs);
  63325. + }
  63326. +
  63327. + if (current->acl->user_trans_type & GR_ID_ALLOW) {
  63328. + for (i = 0; i < num; i++) {
  63329. + curuid = uidlist[i];
  63330. + if (globalreal == curuid)
  63331. + realok = 1;
  63332. + if (globaleffective == curuid)
  63333. + effectiveok = 1;
  63334. + if (globalfs == curuid)
  63335. + fsok = 1;
  63336. + }
  63337. + } else if (current->acl->user_trans_type & GR_ID_DENY) {
  63338. + for (i = 0; i < num; i++) {
  63339. + curuid = uidlist[i];
  63340. + if (globalreal == curuid)
  63341. + break;
  63342. + if (globaleffective == curuid)
  63343. + break;
  63344. + if (globalfs == curuid)
  63345. + break;
  63346. + }
  63347. + /* not in deny list */
  63348. + if (i == num) {
  63349. + realok = 1;
  63350. + effectiveok = 1;
  63351. + fsok = 1;
  63352. + }
  63353. + }
  63354. +
  63355. + if (realok && effectiveok && fsok)
  63356. + return 0;
  63357. + else {
  63358. + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
  63359. + return 1;
  63360. + }
  63361. +}
  63362. +
  63363. +int
  63364. +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
  63365. +{
  63366. + unsigned int i;
  63367. + __u16 num;
  63368. + gid_t *gidlist;
  63369. + gid_t curgid;
  63370. + int realok = 0;
  63371. + int effectiveok = 0;
  63372. + int fsok = 0;
  63373. + gid_t globalreal, globaleffective, globalfs;
  63374. +
  63375. + if (unlikely(!(gr_status & GR_READY)))
  63376. + return 0;
  63377. +
  63378. + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
  63379. + gr_log_learn_gid_change(real, effective, fs);
  63380. +
  63381. + num = current->acl->group_trans_num;
  63382. + gidlist = current->acl->group_transitions;
  63383. +
  63384. + if (gidlist == NULL)
  63385. + return 0;
  63386. +
  63387. + if (!gid_valid(real)) {
  63388. + realok = 1;
  63389. + globalreal = (gid_t)-1;
  63390. + } else {
  63391. + globalreal = GR_GLOBAL_GID(real);
  63392. + }
  63393. + if (!gid_valid(effective)) {
  63394. + effectiveok = 1;
  63395. + globaleffective = (gid_t)-1;
  63396. + } else {
  63397. + globaleffective = GR_GLOBAL_GID(effective);
  63398. + }
  63399. + if (!gid_valid(fs)) {
  63400. + fsok = 1;
  63401. + globalfs = (gid_t)-1;
  63402. + } else {
  63403. + globalfs = GR_GLOBAL_GID(fs);
  63404. + }
  63405. +
  63406. + if (current->acl->group_trans_type & GR_ID_ALLOW) {
  63407. + for (i = 0; i < num; i++) {
  63408. + curgid = gidlist[i];
  63409. + if (globalreal == curgid)
  63410. + realok = 1;
  63411. + if (globaleffective == curgid)
  63412. + effectiveok = 1;
  63413. + if (globalfs == curgid)
  63414. + fsok = 1;
  63415. + }
  63416. + } else if (current->acl->group_trans_type & GR_ID_DENY) {
  63417. + for (i = 0; i < num; i++) {
  63418. + curgid = gidlist[i];
  63419. + if (globalreal == curgid)
  63420. + break;
  63421. + if (globaleffective == curgid)
  63422. + break;
  63423. + if (globalfs == curgid)
  63424. + break;
  63425. + }
  63426. + /* not in deny list */
  63427. + if (i == num) {
  63428. + realok = 1;
  63429. + effectiveok = 1;
  63430. + fsok = 1;
  63431. + }
  63432. + }
  63433. +
  63434. + if (realok && effectiveok && fsok)
  63435. + return 0;
  63436. + else {
  63437. + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
  63438. + return 1;
  63439. + }
  63440. +}
  63441. +
  63442. +extern int gr_acl_is_capable(const int cap);
  63443. +
  63444. +void
  63445. +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
  63446. +{
  63447. + struct acl_role_label *role = task->role;
  63448. + struct acl_subject_label *subj = NULL;
  63449. + struct acl_object_label *obj;
  63450. + struct file *filp;
  63451. + uid_t uid;
  63452. + gid_t gid;
  63453. +
  63454. + if (unlikely(!(gr_status & GR_READY)))
  63455. + return;
  63456. +
  63457. + uid = GR_GLOBAL_UID(kuid);
  63458. + gid = GR_GLOBAL_GID(kgid);
  63459. +
  63460. + filp = task->exec_file;
  63461. +
  63462. + /* kernel process, we'll give them the kernel role */
  63463. + if (unlikely(!filp)) {
  63464. + task->role = running_polstate.kernel_role;
  63465. + task->acl = running_polstate.kernel_role->root_label;
  63466. + return;
  63467. + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
  63468. + /* save the current ip at time of role lookup so that the proper
  63469. + IP will be learned for role_allowed_ip */
  63470. + task->signal->saved_ip = task->signal->curr_ip;
  63471. + role = lookup_acl_role_label(task, uid, gid);
  63472. + }
  63473. +
  63474. + /* don't change the role if we're not a privileged process */
  63475. + if (role && task->role != role &&
  63476. + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
  63477. + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
  63478. + return;
  63479. +
  63480. + /* perform subject lookup in possibly new role
  63481. + we can use this result below in the case where role == task->role
  63482. + */
  63483. + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
  63484. +
  63485. + /* if we changed uid/gid, but result in the same role
  63486. + and are using inheritance, don't lose the inherited subject
  63487. + if current subject is other than what normal lookup
  63488. + would result in, we arrived via inheritance, don't
  63489. + lose subject
  63490. + */
  63491. + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
  63492. + (subj == task->acl)))
  63493. + task->acl = subj;
  63494. +
  63495. + /* leave task->inherited unaffected */
  63496. +
  63497. + task->role = role;
  63498. +
  63499. + task->is_writable = 0;
  63500. +
  63501. + /* ignore additional mmap checks for processes that are writable
  63502. + by the default ACL */
  63503. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
  63504. + if (unlikely(obj->mode & GR_WRITE))
  63505. + task->is_writable = 1;
  63506. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
  63507. + if (unlikely(obj->mode & GR_WRITE))
  63508. + task->is_writable = 1;
  63509. +
  63510. +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
  63511. + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
  63512. +#endif
  63513. +
  63514. + gr_set_proc_res(task);
  63515. +
  63516. + return;
  63517. +}
  63518. +
  63519. +int
  63520. +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
  63521. + const int unsafe_flags)
  63522. +{
  63523. + struct task_struct *task = current;
  63524. + struct acl_subject_label *newacl;
  63525. + struct acl_object_label *obj;
  63526. + __u32 retmode;
  63527. +
  63528. + if (unlikely(!(gr_status & GR_READY)))
  63529. + return 0;
  63530. +
  63531. + newacl = chk_subj_label(dentry, mnt, task->role);
  63532. +
  63533. + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
  63534. + did an exec
  63535. + */
  63536. + rcu_read_lock();
  63537. + read_lock(&tasklist_lock);
  63538. + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
  63539. + (task->parent->acl->mode & GR_POVERRIDE))) {
  63540. + read_unlock(&tasklist_lock);
  63541. + rcu_read_unlock();
  63542. + goto skip_check;
  63543. + }
  63544. + read_unlock(&tasklist_lock);
  63545. + rcu_read_unlock();
  63546. +
  63547. + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
  63548. + !(task->role->roletype & GR_ROLE_GOD) &&
  63549. + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
  63550. + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
  63551. + if (unsafe_flags & LSM_UNSAFE_SHARE)
  63552. + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
  63553. + else
  63554. + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
  63555. + return -EACCES;
  63556. + }
  63557. +
  63558. +skip_check:
  63559. +
  63560. + obj = chk_obj_label(dentry, mnt, task->acl);
  63561. + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
  63562. +
  63563. + if (!(task->acl->mode & GR_INHERITLEARN) &&
  63564. + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
  63565. + if (obj->nested)
  63566. + task->acl = obj->nested;
  63567. + else
  63568. + task->acl = newacl;
  63569. + task->inherited = 0;
  63570. + } else {
  63571. + task->inherited = 1;
  63572. + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
  63573. + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
  63574. + }
  63575. +
  63576. + task->is_writable = 0;
  63577. +
  63578. + /* ignore additional mmap checks for processes that are writable
  63579. + by the default ACL */
  63580. + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
  63581. + if (unlikely(obj->mode & GR_WRITE))
  63582. + task->is_writable = 1;
  63583. + obj = chk_obj_label(dentry, mnt, task->role->root_label);
  63584. + if (unlikely(obj->mode & GR_WRITE))
  63585. + task->is_writable = 1;
  63586. +
  63587. + gr_set_proc_res(task);
  63588. +
  63589. +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
  63590. + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
  63591. +#endif
  63592. + return 0;
  63593. +}
  63594. +
  63595. +/* always called with valid inodev ptr */
  63596. +static void
  63597. +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
  63598. +{
  63599. + struct acl_object_label *matchpo;
  63600. + struct acl_subject_label *matchps;
  63601. + struct acl_subject_label *subj;
  63602. + struct acl_role_label *role;
  63603. + unsigned int x;
  63604. +
  63605. + FOR_EACH_ROLE_START(role)
  63606. + FOR_EACH_SUBJECT_START(role, subj, x)
  63607. + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
  63608. + matchpo->mode |= GR_DELETED;
  63609. + FOR_EACH_SUBJECT_END(subj,x)
  63610. + FOR_EACH_NESTED_SUBJECT_START(role, subj)
  63611. + /* nested subjects aren't in the role's subj_hash table */
  63612. + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
  63613. + matchpo->mode |= GR_DELETED;
  63614. + FOR_EACH_NESTED_SUBJECT_END(subj)
  63615. + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
  63616. + matchps->mode |= GR_DELETED;
  63617. + FOR_EACH_ROLE_END(role)
  63618. +
  63619. + inodev->nentry->deleted = 1;
  63620. +
  63621. + return;
  63622. +}
  63623. +
  63624. +void
  63625. +gr_handle_delete(const ino_t ino, const dev_t dev)
  63626. +{
  63627. + struct inodev_entry *inodev;
  63628. +
  63629. + if (unlikely(!(gr_status & GR_READY)))
  63630. + return;
  63631. +
  63632. + write_lock(&gr_inode_lock);
  63633. + inodev = lookup_inodev_entry(ino, dev);
  63634. + if (inodev != NULL)
  63635. + do_handle_delete(inodev, ino, dev);
  63636. + write_unlock(&gr_inode_lock);
  63637. +
  63638. + return;
  63639. +}
  63640. +
  63641. +static void
  63642. +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
  63643. + const ino_t newinode, const dev_t newdevice,
  63644. + struct acl_subject_label *subj)
  63645. +{
  63646. + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
  63647. + struct acl_object_label *match;
  63648. +
  63649. + match = subj->obj_hash[index];
  63650. +
  63651. + while (match && (match->inode != oldinode ||
  63652. + match->device != olddevice ||
  63653. + !(match->mode & GR_DELETED)))
  63654. + match = match->next;
  63655. +
  63656. + if (match && (match->inode == oldinode)
  63657. + && (match->device == olddevice)
  63658. + && (match->mode & GR_DELETED)) {
  63659. + if (match->prev == NULL) {
  63660. + subj->obj_hash[index] = match->next;
  63661. + if (match->next != NULL)
  63662. + match->next->prev = NULL;
  63663. + } else {
  63664. + match->prev->next = match->next;
  63665. + if (match->next != NULL)
  63666. + match->next->prev = match->prev;
  63667. + }
  63668. + match->prev = NULL;
  63669. + match->next = NULL;
  63670. + match->inode = newinode;
  63671. + match->device = newdevice;
  63672. + match->mode &= ~GR_DELETED;
  63673. +
  63674. + insert_acl_obj_label(match, subj);
  63675. + }
  63676. +
  63677. + return;
  63678. +}
  63679. +
  63680. +static void
  63681. +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
  63682. + const ino_t newinode, const dev_t newdevice,
  63683. + struct acl_role_label *role)
  63684. +{
  63685. + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
  63686. + struct acl_subject_label *match;
  63687. +
  63688. + match = role->subj_hash[index];
  63689. +
  63690. + while (match && (match->inode != oldinode ||
  63691. + match->device != olddevice ||
  63692. + !(match->mode & GR_DELETED)))
  63693. + match = match->next;
  63694. +
  63695. + if (match && (match->inode == oldinode)
  63696. + && (match->device == olddevice)
  63697. + && (match->mode & GR_DELETED)) {
  63698. + if (match->prev == NULL) {
  63699. + role->subj_hash[index] = match->next;
  63700. + if (match->next != NULL)
  63701. + match->next->prev = NULL;
  63702. + } else {
  63703. + match->prev->next = match->next;
  63704. + if (match->next != NULL)
  63705. + match->next->prev = match->prev;
  63706. + }
  63707. + match->prev = NULL;
  63708. + match->next = NULL;
  63709. + match->inode = newinode;
  63710. + match->device = newdevice;
  63711. + match->mode &= ~GR_DELETED;
  63712. +
  63713. + insert_acl_subj_label(match, role);
  63714. + }
  63715. +
  63716. + return;
  63717. +}
  63718. +
  63719. +static void
  63720. +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
  63721. + const ino_t newinode, const dev_t newdevice)
  63722. +{
  63723. + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
  63724. + struct inodev_entry *match;
  63725. +
  63726. + match = running_polstate.inodev_set.i_hash[index];
  63727. +
  63728. + while (match && (match->nentry->inode != oldinode ||
  63729. + match->nentry->device != olddevice || !match->nentry->deleted))
  63730. + match = match->next;
  63731. +
  63732. + if (match && (match->nentry->inode == oldinode)
  63733. + && (match->nentry->device == olddevice) &&
  63734. + match->nentry->deleted) {
  63735. + if (match->prev == NULL) {
  63736. + running_polstate.inodev_set.i_hash[index] = match->next;
  63737. + if (match->next != NULL)
  63738. + match->next->prev = NULL;
  63739. + } else {
  63740. + match->prev->next = match->next;
  63741. + if (match->next != NULL)
  63742. + match->next->prev = match->prev;
  63743. + }
  63744. + match->prev = NULL;
  63745. + match->next = NULL;
  63746. + match->nentry->inode = newinode;
  63747. + match->nentry->device = newdevice;
  63748. + match->nentry->deleted = 0;
  63749. +
  63750. + insert_inodev_entry(match);
  63751. + }
  63752. +
  63753. + return;
  63754. +}
  63755. +
  63756. +static void
  63757. +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
  63758. +{
  63759. + struct acl_subject_label *subj;
  63760. + struct acl_role_label *role;
  63761. + unsigned int x;
  63762. +
  63763. + FOR_EACH_ROLE_START(role)
  63764. + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
  63765. +
  63766. + FOR_EACH_NESTED_SUBJECT_START(role, subj)
  63767. + if ((subj->inode == ino) && (subj->device == dev)) {
  63768. + subj->inode = ino;
  63769. + subj->device = dev;
  63770. + }
  63771. + /* nested subjects aren't in the role's subj_hash table */
  63772. + update_acl_obj_label(matchn->inode, matchn->device,
  63773. + ino, dev, subj);
  63774. + FOR_EACH_NESTED_SUBJECT_END(subj)
  63775. + FOR_EACH_SUBJECT_START(role, subj, x)
  63776. + update_acl_obj_label(matchn->inode, matchn->device,
  63777. + ino, dev, subj);
  63778. + FOR_EACH_SUBJECT_END(subj,x)
  63779. + FOR_EACH_ROLE_END(role)
  63780. +
  63781. + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
  63782. +
  63783. + return;
  63784. +}
  63785. +
  63786. +static void
  63787. +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
  63788. + const struct vfsmount *mnt)
  63789. +{
  63790. + ino_t ino = dentry->d_inode->i_ino;
  63791. + dev_t dev = __get_dev(dentry);
  63792. +
  63793. + __do_handle_create(matchn, ino, dev);
  63794. +
  63795. + return;
  63796. +}
  63797. +
  63798. +void
  63799. +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
  63800. +{
  63801. + struct name_entry *matchn;
  63802. +
  63803. + if (unlikely(!(gr_status & GR_READY)))
  63804. + return;
  63805. +
  63806. + preempt_disable();
  63807. + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
  63808. +
  63809. + if (unlikely((unsigned long)matchn)) {
  63810. + write_lock(&gr_inode_lock);
  63811. + do_handle_create(matchn, dentry, mnt);
  63812. + write_unlock(&gr_inode_lock);
  63813. + }
  63814. + preempt_enable();
  63815. +
  63816. + return;
  63817. +}
  63818. +
  63819. +void
  63820. +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
  63821. +{
  63822. + struct name_entry *matchn;
  63823. +
  63824. + if (unlikely(!(gr_status & GR_READY)))
  63825. + return;
  63826. +
  63827. + preempt_disable();
  63828. + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
  63829. +
  63830. + if (unlikely((unsigned long)matchn)) {
  63831. + write_lock(&gr_inode_lock);
  63832. + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
  63833. + write_unlock(&gr_inode_lock);
  63834. + }
  63835. + preempt_enable();
  63836. +
  63837. + return;
  63838. +}
  63839. +
  63840. +void
  63841. +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
  63842. + struct dentry *old_dentry,
  63843. + struct dentry *new_dentry,
  63844. + struct vfsmount *mnt, const __u8 replace)
  63845. +{
  63846. + struct name_entry *matchn;
  63847. + struct inodev_entry *inodev;
  63848. + struct inode *inode = new_dentry->d_inode;
  63849. + ino_t old_ino = old_dentry->d_inode->i_ino;
  63850. + dev_t old_dev = __get_dev(old_dentry);
  63851. +
  63852. + /* vfs_rename swaps the name and parent link for old_dentry and
  63853. + new_dentry
  63854. + at this point, old_dentry has the new name, parent link, and inode
  63855. + for the renamed file
  63856. + if a file is being replaced by a rename, new_dentry has the inode
  63857. + and name for the replaced file
  63858. + */
  63859. +
  63860. + if (unlikely(!(gr_status & GR_READY)))
  63861. + return;
  63862. +
  63863. + preempt_disable();
  63864. + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
  63865. +
  63866. + /* we wouldn't have to check d_inode if it weren't for
  63867. + NFS silly-renaming
  63868. + */
  63869. +
  63870. + write_lock(&gr_inode_lock);
  63871. + if (unlikely(replace && inode)) {
  63872. + ino_t new_ino = inode->i_ino;
  63873. + dev_t new_dev = __get_dev(new_dentry);
  63874. +
  63875. + inodev = lookup_inodev_entry(new_ino, new_dev);
  63876. + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
  63877. + do_handle_delete(inodev, new_ino, new_dev);
  63878. + }
  63879. +
  63880. + inodev = lookup_inodev_entry(old_ino, old_dev);
  63881. + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
  63882. + do_handle_delete(inodev, old_ino, old_dev);
  63883. +
  63884. + if (unlikely((unsigned long)matchn))
  63885. + do_handle_create(matchn, old_dentry, mnt);
  63886. +
  63887. + write_unlock(&gr_inode_lock);
  63888. + preempt_enable();
  63889. +
  63890. + return;
  63891. +}
  63892. +
  63893. +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
  63894. +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
  63895. + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
  63896. + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
  63897. + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
  63898. + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
  63899. + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
  63900. + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
  63901. + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
  63902. + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
  63903. + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
  63904. + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
  63905. + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
  63906. + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
  63907. + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
  63908. + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
  63909. + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
  63910. + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
  63911. +};
  63912. +
  63913. +void
  63914. +gr_learn_resource(const struct task_struct *task,
  63915. + const int res, const unsigned long wanted, const int gt)
  63916. +{
  63917. + struct acl_subject_label *acl;
  63918. + const struct cred *cred;
  63919. +
  63920. + if (unlikely((gr_status & GR_READY) &&
  63921. + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
  63922. + goto skip_reslog;
  63923. +
  63924. + gr_log_resource(task, res, wanted, gt);
  63925. +skip_reslog:
  63926. +
  63927. + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
  63928. + return;
  63929. +
  63930. + acl = task->acl;
  63931. +
  63932. + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
  63933. + !(acl->resmask & (1U << (unsigned short) res))))
  63934. + return;
  63935. +
  63936. + if (wanted >= acl->res[res].rlim_cur) {
  63937. + unsigned long res_add;
  63938. +
  63939. + res_add = wanted + res_learn_bumps[res];
  63940. +
  63941. + acl->res[res].rlim_cur = res_add;
  63942. +
  63943. + if (wanted > acl->res[res].rlim_max)
  63944. + acl->res[res].rlim_max = res_add;
  63945. +
  63946. + /* only log the subject filename, since resource logging is supported for
  63947. + single-subject learning only */
  63948. + rcu_read_lock();
  63949. + cred = __task_cred(task);
  63950. + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
  63951. + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
  63952. + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
  63953. + "", (unsigned long) res, &task->signal->saved_ip);
  63954. + rcu_read_unlock();
  63955. + }
  63956. +
  63957. + return;
  63958. +}
  63959. +EXPORT_SYMBOL_GPL(gr_learn_resource);
  63960. +#endif
  63961. +
  63962. +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
  63963. +void
  63964. +pax_set_initial_flags(struct linux_binprm *bprm)
  63965. +{
  63966. + struct task_struct *task = current;
  63967. + struct acl_subject_label *proc;
  63968. + unsigned long flags;
  63969. +
  63970. + if (unlikely(!(gr_status & GR_READY)))
  63971. + return;
  63972. +
  63973. + flags = pax_get_flags(task);
  63974. +
  63975. + proc = task->acl;
  63976. +
  63977. + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
  63978. + flags &= ~MF_PAX_PAGEEXEC;
  63979. + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
  63980. + flags &= ~MF_PAX_SEGMEXEC;
  63981. + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
  63982. + flags &= ~MF_PAX_RANDMMAP;
  63983. + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
  63984. + flags &= ~MF_PAX_EMUTRAMP;
  63985. + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
  63986. + flags &= ~MF_PAX_MPROTECT;
  63987. +
  63988. + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
  63989. + flags |= MF_PAX_PAGEEXEC;
  63990. + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
  63991. + flags |= MF_PAX_SEGMEXEC;
  63992. + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
  63993. + flags |= MF_PAX_RANDMMAP;
  63994. + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
  63995. + flags |= MF_PAX_EMUTRAMP;
  63996. + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
  63997. + flags |= MF_PAX_MPROTECT;
  63998. +
  63999. + pax_set_flags(task, flags);
  64000. +
  64001. + return;
  64002. +}
  64003. +#endif
  64004. +
  64005. +int
  64006. +gr_handle_proc_ptrace(struct task_struct *task)
  64007. +{
  64008. + struct file *filp;
  64009. + struct task_struct *tmp = task;
  64010. + struct task_struct *curtemp = current;
  64011. + __u32 retmode;
  64012. +
  64013. +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
  64014. + if (unlikely(!(gr_status & GR_READY)))
  64015. + return 0;
  64016. +#endif
  64017. +
  64018. + read_lock(&tasklist_lock);
  64019. + read_lock(&grsec_exec_file_lock);
  64020. + filp = task->exec_file;
  64021. +
  64022. + while (task_pid_nr(tmp) > 0) {
  64023. + if (tmp == curtemp)
  64024. + break;
  64025. + tmp = tmp->real_parent;
  64026. + }
  64027. +
  64028. + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
  64029. + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
  64030. + read_unlock(&grsec_exec_file_lock);
  64031. + read_unlock(&tasklist_lock);
  64032. + return 1;
  64033. + }
  64034. +
  64035. +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
  64036. + if (!(gr_status & GR_READY)) {
  64037. + read_unlock(&grsec_exec_file_lock);
  64038. + read_unlock(&tasklist_lock);
  64039. + return 0;
  64040. + }
  64041. +#endif
  64042. +
  64043. + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
  64044. + read_unlock(&grsec_exec_file_lock);
  64045. + read_unlock(&tasklist_lock);
  64046. +
  64047. + if (retmode & GR_NOPTRACE)
  64048. + return 1;
  64049. +
  64050. + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
  64051. + && (current->acl != task->acl || (current->acl != current->role->root_label
  64052. + && task_pid_nr(current) != task_pid_nr(task))))
  64053. + return 1;
  64054. +
  64055. + return 0;
  64056. +}
  64057. +
  64058. +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
  64059. +{
  64060. + if (unlikely(!(gr_status & GR_READY)))
  64061. + return;
  64062. +
  64063. + if (!(current->role->roletype & GR_ROLE_GOD))
  64064. + return;
  64065. +
  64066. + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
  64067. + p->role->rolename, gr_task_roletype_to_char(p),
  64068. + p->acl->filename);
  64069. +}
  64070. +
  64071. +int
  64072. +gr_handle_ptrace(struct task_struct *task, const long request)
  64073. +{
  64074. + struct task_struct *tmp = task;
  64075. + struct task_struct *curtemp = current;
  64076. + __u32 retmode;
  64077. +
  64078. +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
  64079. + if (unlikely(!(gr_status & GR_READY)))
  64080. + return 0;
  64081. +#endif
  64082. + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
  64083. + read_lock(&tasklist_lock);
  64084. + while (task_pid_nr(tmp) > 0) {
  64085. + if (tmp == curtemp)
  64086. + break;
  64087. + tmp = tmp->real_parent;
  64088. + }
  64089. +
  64090. + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
  64091. + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
  64092. + read_unlock(&tasklist_lock);
  64093. + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
  64094. + return 1;
  64095. + }
  64096. + read_unlock(&tasklist_lock);
  64097. + }
  64098. +
  64099. +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
  64100. + if (!(gr_status & GR_READY))
  64101. + return 0;
  64102. +#endif
  64103. +
  64104. + read_lock(&grsec_exec_file_lock);
  64105. + if (unlikely(!task->exec_file)) {
  64106. + read_unlock(&grsec_exec_file_lock);
  64107. + return 0;
  64108. + }
  64109. +
  64110. + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
  64111. + read_unlock(&grsec_exec_file_lock);
  64112. +
  64113. + if (retmode & GR_NOPTRACE) {
  64114. + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
  64115. + return 1;
  64116. + }
  64117. +
  64118. + if (retmode & GR_PTRACERD) {
  64119. + switch (request) {
  64120. + case PTRACE_SEIZE:
  64121. + case PTRACE_POKETEXT:
  64122. + case PTRACE_POKEDATA:
  64123. + case PTRACE_POKEUSR:
  64124. +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
  64125. + case PTRACE_SETREGS:
  64126. + case PTRACE_SETFPREGS:
  64127. +#endif
  64128. +#ifdef CONFIG_X86
  64129. + case PTRACE_SETFPXREGS:
  64130. +#endif
  64131. +#ifdef CONFIG_ALTIVEC
  64132. + case PTRACE_SETVRREGS:
  64133. +#endif
  64134. + return 1;
  64135. + default:
  64136. + return 0;
  64137. + }
  64138. + } else if (!(current->acl->mode & GR_POVERRIDE) &&
  64139. + !(current->role->roletype & GR_ROLE_GOD) &&
  64140. + (current->acl != task->acl)) {
  64141. + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
  64142. + return 1;
  64143. + }
  64144. +
  64145. + return 0;
  64146. +}
  64147. +
  64148. +static int is_writable_mmap(const struct file *filp)
  64149. +{
  64150. + struct task_struct *task = current;
  64151. + struct acl_object_label *obj, *obj2;
  64152. +
  64153. + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
  64154. + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && (filp->f_path.mnt != shm_mnt || (filp->f_path.dentry->d_inode->i_nlink > 0))) {
  64155. + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
  64156. + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
  64157. + task->role->root_label);
  64158. + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
  64159. + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
  64160. + return 1;
  64161. + }
  64162. + }
  64163. + return 0;
  64164. +}
  64165. +
  64166. +int
  64167. +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
  64168. +{
  64169. + __u32 mode;
  64170. +
  64171. + if (unlikely(!file || !(prot & PROT_EXEC)))
  64172. + return 1;
  64173. +
  64174. + if (is_writable_mmap(file))
  64175. + return 0;
  64176. +
  64177. + mode =
  64178. + gr_search_file(file->f_path.dentry,
  64179. + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
  64180. + file->f_path.mnt);
  64181. +
  64182. + if (!gr_tpe_allow(file))
  64183. + return 0;
  64184. +
  64185. + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
  64186. + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
  64187. + return 0;
  64188. + } else if (unlikely(!(mode & GR_EXEC))) {
  64189. + return 0;
  64190. + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
  64191. + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
  64192. + return 1;
  64193. + }
  64194. +
  64195. + return 1;
  64196. +}
  64197. +
  64198. +int
  64199. +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
  64200. +{
  64201. + __u32 mode;
  64202. +
  64203. + if (unlikely(!file || !(prot & PROT_EXEC)))
  64204. + return 1;
  64205. +
  64206. + if (is_writable_mmap(file))
  64207. + return 0;
  64208. +
  64209. + mode =
  64210. + gr_search_file(file->f_path.dentry,
  64211. + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
  64212. + file->f_path.mnt);
  64213. +
  64214. + if (!gr_tpe_allow(file))
  64215. + return 0;
  64216. +
  64217. + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
  64218. + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
  64219. + return 0;
  64220. + } else if (unlikely(!(mode & GR_EXEC))) {
  64221. + return 0;
  64222. + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
  64223. + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
  64224. + return 1;
  64225. + }
  64226. +
  64227. + return 1;
  64228. +}
  64229. +
  64230. +void
  64231. +gr_acl_handle_psacct(struct task_struct *task, const long code)
  64232. +{
  64233. + unsigned long runtime, cputime;
  64234. + cputime_t utime, stime;
  64235. + unsigned int wday, cday;
  64236. + __u8 whr, chr;
  64237. + __u8 wmin, cmin;
  64238. + __u8 wsec, csec;
  64239. + struct timespec timeval;
  64240. +
  64241. + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
  64242. + !(task->acl->mode & GR_PROCACCT)))
  64243. + return;
  64244. +
  64245. + do_posix_clock_monotonic_gettime(&timeval);
  64246. + runtime = timeval.tv_sec - task->start_time.tv_sec;
  64247. + wday = runtime / (60 * 60 * 24);
  64248. + runtime -= wday * (60 * 60 * 24);
  64249. + whr = runtime / (60 * 60);
  64250. + runtime -= whr * (60 * 60);
  64251. + wmin = runtime / 60;
  64252. + runtime -= wmin * 60;
  64253. + wsec = runtime;
  64254. +
  64255. + task_cputime(task, &utime, &stime);
  64256. + cputime = cputime_to_secs(utime + stime);
  64257. + cday = cputime / (60 * 60 * 24);
  64258. + cputime -= cday * (60 * 60 * 24);
  64259. + chr = cputime / (60 * 60);
  64260. + cputime -= chr * (60 * 60);
  64261. + cmin = cputime / 60;
  64262. + cputime -= cmin * 60;
  64263. + csec = cputime;
  64264. +
  64265. + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
  64266. +
  64267. + return;
  64268. +}
  64269. +
  64270. +#ifdef CONFIG_TASKSTATS
  64271. +int gr_is_taskstats_denied(int pid)
  64272. +{
  64273. + struct task_struct *task;
  64274. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  64275. + const struct cred *cred;
  64276. +#endif
  64277. + int ret = 0;
  64278. +
  64279. + /* restrict taskstats viewing to un-chrooted root users
  64280. + who have the 'view' subject flag if the RBAC system is enabled
  64281. + */
  64282. +
  64283. + rcu_read_lock();
  64284. + read_lock(&tasklist_lock);
  64285. + task = find_task_by_vpid(pid);
  64286. + if (task) {
  64287. +#ifdef CONFIG_GRKERNSEC_CHROOT
  64288. + if (proc_is_chrooted(task))
  64289. + ret = -EACCES;
  64290. +#endif
  64291. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  64292. + cred = __task_cred(task);
  64293. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  64294. + if (gr_is_global_nonroot(cred->uid))
  64295. + ret = -EACCES;
  64296. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  64297. + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
  64298. + ret = -EACCES;
  64299. +#endif
  64300. +#endif
  64301. + if (gr_status & GR_READY) {
  64302. + if (!(task->acl->mode & GR_VIEW))
  64303. + ret = -EACCES;
  64304. + }
  64305. + } else
  64306. + ret = -ENOENT;
  64307. +
  64308. + read_unlock(&tasklist_lock);
  64309. + rcu_read_unlock();
  64310. +
  64311. + return ret;
  64312. +}
  64313. +#endif
  64314. +
  64315. +/* AUXV entries are filled via a descendant of search_binary_handler
  64316. + after we've already applied the subject for the target
  64317. +*/
  64318. +int gr_acl_enable_at_secure(void)
  64319. +{
  64320. + if (unlikely(!(gr_status & GR_READY)))
  64321. + return 0;
  64322. +
  64323. + if (current->acl->mode & GR_ATSECURE)
  64324. + return 1;
  64325. +
  64326. + return 0;
  64327. +}
  64328. +
  64329. +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
  64330. +{
  64331. + struct task_struct *task = current;
  64332. + struct dentry *dentry = file->f_path.dentry;
  64333. + struct vfsmount *mnt = file->f_path.mnt;
  64334. + struct acl_object_label *obj, *tmp;
  64335. + struct acl_subject_label *subj;
  64336. + unsigned int bufsize;
  64337. + int is_not_root;
  64338. + char *path;
  64339. + dev_t dev = __get_dev(dentry);
  64340. +
  64341. + if (unlikely(!(gr_status & GR_READY)))
  64342. + return 1;
  64343. +
  64344. + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
  64345. + return 1;
  64346. +
  64347. + /* ignore Eric Biederman */
  64348. + if (IS_PRIVATE(dentry->d_inode))
  64349. + return 1;
  64350. +
  64351. + subj = task->acl;
  64352. + read_lock(&gr_inode_lock);
  64353. + do {
  64354. + obj = lookup_acl_obj_label(ino, dev, subj);
  64355. + if (obj != NULL) {
  64356. + read_unlock(&gr_inode_lock);
  64357. + return (obj->mode & GR_FIND) ? 1 : 0;
  64358. + }
  64359. + } while ((subj = subj->parent_subject));
  64360. + read_unlock(&gr_inode_lock);
  64361. +
  64362. + /* this is purely an optimization since we're looking for an object
  64363. + for the directory we're doing a readdir on
  64364. + if it's possible for any globbed object to match the entry we're
  64365. + filling into the directory, then the object we find here will be
  64366. + an anchor point with attached globbed objects
  64367. + */
  64368. + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
  64369. + if (obj->globbed == NULL)
  64370. + return (obj->mode & GR_FIND) ? 1 : 0;
  64371. +
  64372. + is_not_root = ((obj->filename[0] == '/') &&
  64373. + (obj->filename[1] == '\0')) ? 0 : 1;
  64374. + bufsize = PAGE_SIZE - namelen - is_not_root;
  64375. +
  64376. + /* check bufsize > PAGE_SIZE || bufsize == 0 */
  64377. + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
  64378. + return 1;
  64379. +
  64380. + preempt_disable();
  64381. + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
  64382. + bufsize);
  64383. +
  64384. + bufsize = strlen(path);
  64385. +
  64386. + /* if base is "/", don't append an additional slash */
  64387. + if (is_not_root)
  64388. + *(path + bufsize) = '/';
  64389. + memcpy(path + bufsize + is_not_root, name, namelen);
  64390. + *(path + bufsize + namelen + is_not_root) = '\0';
  64391. +
  64392. + tmp = obj->globbed;
  64393. + while (tmp) {
  64394. + if (!glob_match(tmp->filename, path)) {
  64395. + preempt_enable();
  64396. + return (tmp->mode & GR_FIND) ? 1 : 0;
  64397. + }
  64398. + tmp = tmp->next;
  64399. + }
  64400. + preempt_enable();
  64401. + return (obj->mode & GR_FIND) ? 1 : 0;
  64402. +}
  64403. +
  64404. +void gr_put_exec_file(struct task_struct *task)
  64405. +{
  64406. + struct file *filp;
  64407. +
  64408. + write_lock(&grsec_exec_file_lock);
  64409. + filp = task->exec_file;
  64410. + task->exec_file = NULL;
  64411. + write_unlock(&grsec_exec_file_lock);
  64412. +
  64413. + if (filp)
  64414. + fput(filp);
  64415. +
  64416. + return;
  64417. +}
  64418. +
  64419. +
  64420. +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
  64421. +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
  64422. +#endif
  64423. +#ifdef CONFIG_SECURITY
  64424. +EXPORT_SYMBOL_GPL(gr_check_user_change);
  64425. +EXPORT_SYMBOL_GPL(gr_check_group_change);
  64426. +#endif
  64427. +
  64428. diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
  64429. new file mode 100644
  64430. index 0000000..18ffbbd
  64431. --- /dev/null
  64432. +++ b/grsecurity/gracl_alloc.c
  64433. @@ -0,0 +1,105 @@
  64434. +#include <linux/kernel.h>
  64435. +#include <linux/mm.h>
  64436. +#include <linux/slab.h>
  64437. +#include <linux/vmalloc.h>
  64438. +#include <linux/gracl.h>
  64439. +#include <linux/grsecurity.h>
  64440. +
  64441. +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
  64442. +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
  64443. +
  64444. +static __inline__ int
  64445. +alloc_pop(void)
  64446. +{
  64447. + if (current_alloc_state->alloc_stack_next == 1)
  64448. + return 0;
  64449. +
  64450. + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
  64451. +
  64452. + current_alloc_state->alloc_stack_next--;
  64453. +
  64454. + return 1;
  64455. +}
  64456. +
  64457. +static __inline__ int
  64458. +alloc_push(void *buf)
  64459. +{
  64460. + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
  64461. + return 1;
  64462. +
  64463. + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
  64464. +
  64465. + current_alloc_state->alloc_stack_next++;
  64466. +
  64467. + return 0;
  64468. +}
  64469. +
  64470. +void *
  64471. +acl_alloc(unsigned long len)
  64472. +{
  64473. + void *ret = NULL;
  64474. +
  64475. + if (!len || len > PAGE_SIZE)
  64476. + goto out;
  64477. +
  64478. + ret = kmalloc(len, GFP_KERNEL);
  64479. +
  64480. + if (ret) {
  64481. + if (alloc_push(ret)) {
  64482. + kfree(ret);
  64483. + ret = NULL;
  64484. + }
  64485. + }
  64486. +
  64487. +out:
  64488. + return ret;
  64489. +}
  64490. +
  64491. +void *
  64492. +acl_alloc_num(unsigned long num, unsigned long len)
  64493. +{
  64494. + if (!len || (num > (PAGE_SIZE / len)))
  64495. + return NULL;
  64496. +
  64497. + return acl_alloc(num * len);
  64498. +}
  64499. +
  64500. +void
  64501. +acl_free_all(void)
  64502. +{
  64503. + if (!current_alloc_state->alloc_stack)
  64504. + return;
  64505. +
  64506. + while (alloc_pop()) ;
  64507. +
  64508. + if (current_alloc_state->alloc_stack) {
  64509. + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
  64510. + kfree(current_alloc_state->alloc_stack);
  64511. + else
  64512. + vfree(current_alloc_state->alloc_stack);
  64513. + }
  64514. +
  64515. + current_alloc_state->alloc_stack = NULL;
  64516. + current_alloc_state->alloc_stack_size = 1;
  64517. + current_alloc_state->alloc_stack_next = 1;
  64518. +
  64519. + return;
  64520. +}
  64521. +
  64522. +int
  64523. +acl_alloc_stack_init(unsigned long size)
  64524. +{
  64525. + if ((size * sizeof (void *)) <= PAGE_SIZE)
  64526. + current_alloc_state->alloc_stack =
  64527. + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
  64528. + else
  64529. + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
  64530. +
  64531. + current_alloc_state->alloc_stack_size = size;
  64532. + current_alloc_state->alloc_stack_next = 1;
  64533. +
  64534. + if (!current_alloc_state->alloc_stack)
  64535. + return 0;
  64536. + else
  64537. + return 1;
  64538. +}
  64539. diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
  64540. new file mode 100644
  64541. index 0000000..bdd51ea
  64542. --- /dev/null
  64543. +++ b/grsecurity/gracl_cap.c
  64544. @@ -0,0 +1,110 @@
  64545. +#include <linux/kernel.h>
  64546. +#include <linux/module.h>
  64547. +#include <linux/sched.h>
  64548. +#include <linux/gracl.h>
  64549. +#include <linux/grsecurity.h>
  64550. +#include <linux/grinternal.h>
  64551. +
  64552. +extern const char *captab_log[];
  64553. +extern int captab_log_entries;
  64554. +
  64555. +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
  64556. +{
  64557. + struct acl_subject_label *curracl;
  64558. + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
  64559. + kernel_cap_t cap_audit = __cap_empty_set;
  64560. +
  64561. + if (!gr_acl_is_enabled())
  64562. + return 1;
  64563. +
  64564. + curracl = task->acl;
  64565. +
  64566. + cap_drop = curracl->cap_lower;
  64567. + cap_mask = curracl->cap_mask;
  64568. + cap_audit = curracl->cap_invert_audit;
  64569. +
  64570. + while ((curracl = curracl->parent_subject)) {
  64571. + /* if the cap isn't specified in the current computed mask but is specified in the
  64572. + current level subject, and is lowered in the current level subject, then add
  64573. + it to the set of dropped capabilities
  64574. + otherwise, add the current level subject's mask to the current computed mask
  64575. + */
  64576. + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
  64577. + cap_raise(cap_mask, cap);
  64578. + if (cap_raised(curracl->cap_lower, cap))
  64579. + cap_raise(cap_drop, cap);
  64580. + if (cap_raised(curracl->cap_invert_audit, cap))
  64581. + cap_raise(cap_audit, cap);
  64582. + }
  64583. + }
  64584. +
  64585. + if (!cap_raised(cap_drop, cap)) {
  64586. + if (cap_raised(cap_audit, cap))
  64587. + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
  64588. + return 1;
  64589. + }
  64590. +
  64591. + curracl = task->acl;
  64592. +
  64593. + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
  64594. + && cap_raised(cred->cap_effective, cap)) {
  64595. + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
  64596. + task->role->roletype, GR_GLOBAL_UID(cred->uid),
  64597. + GR_GLOBAL_GID(cred->gid), task->exec_file ?
  64598. + gr_to_filename(task->exec_file->f_path.dentry,
  64599. + task->exec_file->f_path.mnt) : curracl->filename,
  64600. + curracl->filename, 0UL,
  64601. + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
  64602. + return 1;
  64603. + }
  64604. +
  64605. + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
  64606. + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
  64607. +
  64608. + return 0;
  64609. +}
  64610. +
  64611. +int
  64612. +gr_acl_is_capable(const int cap)
  64613. +{
  64614. + return gr_task_acl_is_capable(current, current_cred(), cap);
  64615. +}
  64616. +
  64617. +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
  64618. +{
  64619. + struct acl_subject_label *curracl;
  64620. + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
  64621. +
  64622. + if (!gr_acl_is_enabled())
  64623. + return 1;
  64624. +
  64625. + curracl = task->acl;
  64626. +
  64627. + cap_drop = curracl->cap_lower;
  64628. + cap_mask = curracl->cap_mask;
  64629. +
  64630. + while ((curracl = curracl->parent_subject)) {
  64631. + /* if the cap isn't specified in the current computed mask but is specified in the
  64632. + current level subject, and is lowered in the current level subject, then add
  64633. + it to the set of dropped capabilities
  64634. + otherwise, add the current level subject's mask to the current computed mask
  64635. + */
  64636. + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
  64637. + cap_raise(cap_mask, cap);
  64638. + if (cap_raised(curracl->cap_lower, cap))
  64639. + cap_raise(cap_drop, cap);
  64640. + }
  64641. + }
  64642. +
  64643. + if (!cap_raised(cap_drop, cap))
  64644. + return 1;
  64645. +
  64646. + return 0;
  64647. +}
  64648. +
  64649. +int
  64650. +gr_acl_is_capable_nolog(const int cap)
  64651. +{
  64652. + return gr_task_acl_is_capable_nolog(current, cap);
  64653. +}
  64654. +
  64655. diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
  64656. new file mode 100644
  64657. index 0000000..ca25605
  64658. --- /dev/null
  64659. +++ b/grsecurity/gracl_compat.c
  64660. @@ -0,0 +1,270 @@
  64661. +#include <linux/kernel.h>
  64662. +#include <linux/gracl.h>
  64663. +#include <linux/compat.h>
  64664. +#include <linux/gracl_compat.h>
  64665. +
  64666. +#include <asm/uaccess.h>
  64667. +
  64668. +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
  64669. +{
  64670. + struct gr_arg_wrapper_compat uwrapcompat;
  64671. +
  64672. + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
  64673. + return -EFAULT;
  64674. +
  64675. + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
  64676. + (uwrapcompat.version != 0x2901)) ||
  64677. + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
  64678. + return -EINVAL;
  64679. +
  64680. + uwrap->arg = compat_ptr(uwrapcompat.arg);
  64681. + uwrap->version = uwrapcompat.version;
  64682. + uwrap->size = sizeof(struct gr_arg);
  64683. +
  64684. + return 0;
  64685. +}
  64686. +
  64687. +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
  64688. +{
  64689. + struct gr_arg_compat argcompat;
  64690. +
  64691. + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
  64692. + return -EFAULT;
  64693. +
  64694. + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
  64695. + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
  64696. + arg->role_db.num_roles = argcompat.role_db.num_roles;
  64697. + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
  64698. + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
  64699. + arg->role_db.num_objects = argcompat.role_db.num_objects;
  64700. +
  64701. + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
  64702. + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
  64703. + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
  64704. + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
  64705. + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
  64706. + arg->segv_device = argcompat.segv_device;
  64707. + arg->segv_inode = argcompat.segv_inode;
  64708. + arg->segv_uid = argcompat.segv_uid;
  64709. + arg->num_sprole_pws = argcompat.num_sprole_pws;
  64710. + arg->mode = argcompat.mode;
  64711. +
  64712. + return 0;
  64713. +}
  64714. +
  64715. +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
  64716. +{
  64717. + struct acl_object_label_compat objcompat;
  64718. +
  64719. + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
  64720. + return -EFAULT;
  64721. +
  64722. + obj->filename = compat_ptr(objcompat.filename);
  64723. + obj->inode = objcompat.inode;
  64724. + obj->device = objcompat.device;
  64725. + obj->mode = objcompat.mode;
  64726. +
  64727. + obj->nested = compat_ptr(objcompat.nested);
  64728. + obj->globbed = compat_ptr(objcompat.globbed);
  64729. +
  64730. + obj->prev = compat_ptr(objcompat.prev);
  64731. + obj->next = compat_ptr(objcompat.next);
  64732. +
  64733. + return 0;
  64734. +}
  64735. +
  64736. +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
  64737. +{
  64738. + unsigned int i;
  64739. + struct acl_subject_label_compat subjcompat;
  64740. +
  64741. + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
  64742. + return -EFAULT;
  64743. +
  64744. + subj->filename = compat_ptr(subjcompat.filename);
  64745. + subj->inode = subjcompat.inode;
  64746. + subj->device = subjcompat.device;
  64747. + subj->mode = subjcompat.mode;
  64748. + subj->cap_mask = subjcompat.cap_mask;
  64749. + subj->cap_lower = subjcompat.cap_lower;
  64750. + subj->cap_invert_audit = subjcompat.cap_invert_audit;
  64751. +
  64752. + for (i = 0; i < GR_NLIMITS; i++) {
  64753. + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
  64754. + subj->res[i].rlim_cur = RLIM_INFINITY;
  64755. + else
  64756. + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
  64757. + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
  64758. + subj->res[i].rlim_max = RLIM_INFINITY;
  64759. + else
  64760. + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
  64761. + }
  64762. + subj->resmask = subjcompat.resmask;
  64763. +
  64764. + subj->user_trans_type = subjcompat.user_trans_type;
  64765. + subj->group_trans_type = subjcompat.group_trans_type;
  64766. + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
  64767. + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
  64768. + subj->user_trans_num = subjcompat.user_trans_num;
  64769. + subj->group_trans_num = subjcompat.group_trans_num;
  64770. +
  64771. + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
  64772. + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
  64773. + subj->ip_type = subjcompat.ip_type;
  64774. + subj->ips = compat_ptr(subjcompat.ips);
  64775. + subj->ip_num = subjcompat.ip_num;
  64776. + subj->inaddr_any_override = subjcompat.inaddr_any_override;
  64777. +
  64778. + subj->crashes = subjcompat.crashes;
  64779. + subj->expires = subjcompat.expires;
  64780. +
  64781. + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
  64782. + subj->hash = compat_ptr(subjcompat.hash);
  64783. + subj->prev = compat_ptr(subjcompat.prev);
  64784. + subj->next = compat_ptr(subjcompat.next);
  64785. +
  64786. + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
  64787. + subj->obj_hash_size = subjcompat.obj_hash_size;
  64788. + subj->pax_flags = subjcompat.pax_flags;
  64789. +
  64790. + return 0;
  64791. +}
  64792. +
  64793. +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
  64794. +{
  64795. + struct acl_role_label_compat rolecompat;
  64796. +
  64797. + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
  64798. + return -EFAULT;
  64799. +
  64800. + role->rolename = compat_ptr(rolecompat.rolename);
  64801. + role->uidgid = rolecompat.uidgid;
  64802. + role->roletype = rolecompat.roletype;
  64803. +
  64804. + role->auth_attempts = rolecompat.auth_attempts;
  64805. + role->expires = rolecompat.expires;
  64806. +
  64807. + role->root_label = compat_ptr(rolecompat.root_label);
  64808. + role->hash = compat_ptr(rolecompat.hash);
  64809. +
  64810. + role->prev = compat_ptr(rolecompat.prev);
  64811. + role->next = compat_ptr(rolecompat.next);
  64812. +
  64813. + role->transitions = compat_ptr(rolecompat.transitions);
  64814. + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
  64815. + role->domain_children = compat_ptr(rolecompat.domain_children);
  64816. + role->domain_child_num = rolecompat.domain_child_num;
  64817. +
  64818. + role->umask = rolecompat.umask;
  64819. +
  64820. + role->subj_hash = compat_ptr(rolecompat.subj_hash);
  64821. + role->subj_hash_size = rolecompat.subj_hash_size;
  64822. +
  64823. + return 0;
  64824. +}
  64825. +
  64826. +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
  64827. +{
  64828. + struct role_allowed_ip_compat roleip_compat;
  64829. +
  64830. + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
  64831. + return -EFAULT;
  64832. +
  64833. + roleip->addr = roleip_compat.addr;
  64834. + roleip->netmask = roleip_compat.netmask;
  64835. +
  64836. + roleip->prev = compat_ptr(roleip_compat.prev);
  64837. + roleip->next = compat_ptr(roleip_compat.next);
  64838. +
  64839. + return 0;
  64840. +}
  64841. +
  64842. +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
  64843. +{
  64844. + struct role_transition_compat trans_compat;
  64845. +
  64846. + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
  64847. + return -EFAULT;
  64848. +
  64849. + trans->rolename = compat_ptr(trans_compat.rolename);
  64850. +
  64851. + trans->prev = compat_ptr(trans_compat.prev);
  64852. + trans->next = compat_ptr(trans_compat.next);
  64853. +
  64854. + return 0;
  64855. +
  64856. +}
  64857. +
  64858. +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
  64859. +{
  64860. + struct gr_hash_struct_compat hash_compat;
  64861. +
  64862. + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
  64863. + return -EFAULT;
  64864. +
  64865. + hash->table = compat_ptr(hash_compat.table);
  64866. + hash->nametable = compat_ptr(hash_compat.nametable);
  64867. + hash->first = compat_ptr(hash_compat.first);
  64868. +
  64869. + hash->table_size = hash_compat.table_size;
  64870. + hash->used_size = hash_compat.used_size;
  64871. +
  64872. + hash->type = hash_compat.type;
  64873. +
  64874. + return 0;
  64875. +}
  64876. +
  64877. +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
  64878. +{
  64879. + compat_uptr_t ptrcompat;
  64880. +
  64881. + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
  64882. + return -EFAULT;
  64883. +
  64884. + *(void **)ptr = compat_ptr(ptrcompat);
  64885. +
  64886. + return 0;
  64887. +}
  64888. +
  64889. +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
  64890. +{
  64891. + struct acl_ip_label_compat ip_compat;
  64892. +
  64893. + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
  64894. + return -EFAULT;
  64895. +
  64896. + ip->iface = compat_ptr(ip_compat.iface);
  64897. + ip->addr = ip_compat.addr;
  64898. + ip->netmask = ip_compat.netmask;
  64899. + ip->low = ip_compat.low;
  64900. + ip->high = ip_compat.high;
  64901. + ip->mode = ip_compat.mode;
  64902. + ip->type = ip_compat.type;
  64903. +
  64904. + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
  64905. +
  64906. + ip->prev = compat_ptr(ip_compat.prev);
  64907. + ip->next = compat_ptr(ip_compat.next);
  64908. +
  64909. + return 0;
  64910. +}
  64911. +
  64912. +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
  64913. +{
  64914. + struct sprole_pw_compat pw_compat;
  64915. +
  64916. + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
  64917. + return -EFAULT;
  64918. +
  64919. + pw->rolename = compat_ptr(pw_compat.rolename);
  64920. + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
  64921. + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
  64922. +
  64923. + return 0;
  64924. +}
  64925. +
  64926. +size_t get_gr_arg_wrapper_size_compat(void)
  64927. +{
  64928. + return sizeof(struct gr_arg_wrapper_compat);
  64929. +}
  64930. +
  64931. diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
  64932. new file mode 100644
  64933. index 0000000..a89b1f4
  64934. --- /dev/null
  64935. +++ b/grsecurity/gracl_fs.c
  64936. @@ -0,0 +1,437 @@
  64937. +#include <linux/kernel.h>
  64938. +#include <linux/sched.h>
  64939. +#include <linux/types.h>
  64940. +#include <linux/fs.h>
  64941. +#include <linux/file.h>
  64942. +#include <linux/stat.h>
  64943. +#include <linux/grsecurity.h>
  64944. +#include <linux/grinternal.h>
  64945. +#include <linux/gracl.h>
  64946. +
  64947. +umode_t
  64948. +gr_acl_umask(void)
  64949. +{
  64950. + if (unlikely(!gr_acl_is_enabled()))
  64951. + return 0;
  64952. +
  64953. + return current->role->umask;
  64954. +}
  64955. +
  64956. +__u32
  64957. +gr_acl_handle_hidden_file(const struct dentry * dentry,
  64958. + const struct vfsmount * mnt)
  64959. +{
  64960. + __u32 mode;
  64961. +
  64962. + if (unlikely(d_is_negative(dentry)))
  64963. + return GR_FIND;
  64964. +
  64965. + mode =
  64966. + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
  64967. +
  64968. + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
  64969. + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
  64970. + return mode;
  64971. + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
  64972. + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
  64973. + return 0;
  64974. + } else if (unlikely(!(mode & GR_FIND)))
  64975. + return 0;
  64976. +
  64977. + return GR_FIND;
  64978. +}
  64979. +
  64980. +__u32
  64981. +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
  64982. + int acc_mode)
  64983. +{
  64984. + __u32 reqmode = GR_FIND;
  64985. + __u32 mode;
  64986. +
  64987. + if (unlikely(d_is_negative(dentry)))
  64988. + return reqmode;
  64989. +
  64990. + if (acc_mode & MAY_APPEND)
  64991. + reqmode |= GR_APPEND;
  64992. + else if (acc_mode & MAY_WRITE)
  64993. + reqmode |= GR_WRITE;
  64994. + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
  64995. + reqmode |= GR_READ;
  64996. +
  64997. + mode =
  64998. + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
  64999. + mnt);
  65000. +
  65001. + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
  65002. + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
  65003. + reqmode & GR_READ ? " reading" : "",
  65004. + reqmode & GR_WRITE ? " writing" : reqmode &
  65005. + GR_APPEND ? " appending" : "");
  65006. + return reqmode;
  65007. + } else
  65008. + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
  65009. + {
  65010. + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
  65011. + reqmode & GR_READ ? " reading" : "",
  65012. + reqmode & GR_WRITE ? " writing" : reqmode &
  65013. + GR_APPEND ? " appending" : "");
  65014. + return 0;
  65015. + } else if (unlikely((mode & reqmode) != reqmode))
  65016. + return 0;
  65017. +
  65018. + return reqmode;
  65019. +}
  65020. +
  65021. +__u32
  65022. +gr_acl_handle_creat(const struct dentry * dentry,
  65023. + const struct dentry * p_dentry,
  65024. + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
  65025. + const int imode)
  65026. +{
  65027. + __u32 reqmode = GR_WRITE | GR_CREATE;
  65028. + __u32 mode;
  65029. +
  65030. + if (acc_mode & MAY_APPEND)
  65031. + reqmode |= GR_APPEND;
  65032. + // if a directory was required or the directory already exists, then
  65033. + // don't count this open as a read
  65034. + if ((acc_mode & MAY_READ) &&
  65035. + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
  65036. + reqmode |= GR_READ;
  65037. + if ((open_flags & O_CREAT) &&
  65038. + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
  65039. + reqmode |= GR_SETID;
  65040. +
  65041. + mode =
  65042. + gr_check_create(dentry, p_dentry, p_mnt,
  65043. + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
  65044. +
  65045. + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
  65046. + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
  65047. + reqmode & GR_READ ? " reading" : "",
  65048. + reqmode & GR_WRITE ? " writing" : reqmode &
  65049. + GR_APPEND ? " appending" : "");
  65050. + return reqmode;
  65051. + } else
  65052. + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
  65053. + {
  65054. + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
  65055. + reqmode & GR_READ ? " reading" : "",
  65056. + reqmode & GR_WRITE ? " writing" : reqmode &
  65057. + GR_APPEND ? " appending" : "");
  65058. + return 0;
  65059. + } else if (unlikely((mode & reqmode) != reqmode))
  65060. + return 0;
  65061. +
  65062. + return reqmode;
  65063. +}
  65064. +
  65065. +__u32
  65066. +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
  65067. + const int fmode)
  65068. +{
  65069. + __u32 mode, reqmode = GR_FIND;
  65070. +
  65071. + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
  65072. + reqmode |= GR_EXEC;
  65073. + if (fmode & S_IWOTH)
  65074. + reqmode |= GR_WRITE;
  65075. + if (fmode & S_IROTH)
  65076. + reqmode |= GR_READ;
  65077. +
  65078. + mode =
  65079. + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
  65080. + mnt);
  65081. +
  65082. + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
  65083. + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
  65084. + reqmode & GR_READ ? " reading" : "",
  65085. + reqmode & GR_WRITE ? " writing" : "",
  65086. + reqmode & GR_EXEC ? " executing" : "");
  65087. + return reqmode;
  65088. + } else
  65089. + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
  65090. + {
  65091. + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
  65092. + reqmode & GR_READ ? " reading" : "",
  65093. + reqmode & GR_WRITE ? " writing" : "",
  65094. + reqmode & GR_EXEC ? " executing" : "");
  65095. + return 0;
  65096. + } else if (unlikely((mode & reqmode) != reqmode))
  65097. + return 0;
  65098. +
  65099. + return reqmode;
  65100. +}
  65101. +
  65102. +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
  65103. +{
  65104. + __u32 mode;
  65105. +
  65106. + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
  65107. +
  65108. + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
  65109. + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
  65110. + return mode;
  65111. + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
  65112. + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
  65113. + return 0;
  65114. + } else if (unlikely((mode & (reqmode)) != (reqmode)))
  65115. + return 0;
  65116. +
  65117. + return (reqmode);
  65118. +}
  65119. +
  65120. +__u32
  65121. +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
  65122. +{
  65123. + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
  65124. +}
  65125. +
  65126. +__u32
  65127. +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
  65128. +{
  65129. + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
  65130. +}
  65131. +
  65132. +__u32
  65133. +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
  65134. +{
  65135. + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
  65136. +}
  65137. +
  65138. +__u32
  65139. +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
  65140. +{
  65141. + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
  65142. +}
  65143. +
  65144. +__u32
  65145. +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
  65146. + umode_t *modeptr)
  65147. +{
  65148. + umode_t mode;
  65149. +
  65150. + *modeptr &= ~gr_acl_umask();
  65151. + mode = *modeptr;
  65152. +
  65153. + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
  65154. + return 1;
  65155. +
  65156. + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
  65157. + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
  65158. + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
  65159. + GR_CHMOD_ACL_MSG);
  65160. + } else {
  65161. + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
  65162. + }
  65163. +}
  65164. +
  65165. +__u32
  65166. +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
  65167. +{
  65168. + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
  65169. +}
  65170. +
  65171. +__u32
  65172. +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
  65173. +{
  65174. + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
  65175. +}
  65176. +
  65177. +__u32
  65178. +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
  65179. +{
  65180. + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
  65181. +}
  65182. +
  65183. +__u32
  65184. +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
  65185. +{
  65186. + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
  65187. +}
  65188. +
  65189. +__u32
  65190. +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
  65191. +{
  65192. + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
  65193. + GR_UNIXCONNECT_ACL_MSG);
  65194. +}
  65195. +
  65196. +/* hardlinks require at minimum create and link permission,
  65197. + any additional privilege required is based on the
  65198. + privilege of the file being linked to
  65199. +*/
  65200. +__u32
  65201. +gr_acl_handle_link(const struct dentry * new_dentry,
  65202. + const struct dentry * parent_dentry,
  65203. + const struct vfsmount * parent_mnt,
  65204. + const struct dentry * old_dentry,
  65205. + const struct vfsmount * old_mnt, const struct filename *to)
  65206. +{
  65207. + __u32 mode;
  65208. + __u32 needmode = GR_CREATE | GR_LINK;
  65209. + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
  65210. +
  65211. + mode =
  65212. + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
  65213. + old_mnt);
  65214. +
  65215. + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
  65216. + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
  65217. + return mode;
  65218. + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
  65219. + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
  65220. + return 0;
  65221. + } else if (unlikely((mode & needmode) != needmode))
  65222. + return 0;
  65223. +
  65224. + return 1;
  65225. +}
  65226. +
  65227. +__u32
  65228. +gr_acl_handle_symlink(const struct dentry * new_dentry,
  65229. + const struct dentry * parent_dentry,
  65230. + const struct vfsmount * parent_mnt, const struct filename *from)
  65231. +{
  65232. + __u32 needmode = GR_WRITE | GR_CREATE;
  65233. + __u32 mode;
  65234. +
  65235. + mode =
  65236. + gr_check_create(new_dentry, parent_dentry, parent_mnt,
  65237. + GR_CREATE | GR_AUDIT_CREATE |
  65238. + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
  65239. +
  65240. + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
  65241. + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
  65242. + return mode;
  65243. + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
  65244. + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
  65245. + return 0;
  65246. + } else if (unlikely((mode & needmode) != needmode))
  65247. + return 0;
  65248. +
  65249. + return (GR_WRITE | GR_CREATE);
  65250. +}
  65251. +
  65252. +static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt)
  65253. +{
  65254. + __u32 mode;
  65255. +
  65256. + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
  65257. +
  65258. + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
  65259. + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
  65260. + return mode;
  65261. + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
  65262. + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
  65263. + return 0;
  65264. + } else if (unlikely((mode & (reqmode)) != (reqmode)))
  65265. + return 0;
  65266. +
  65267. + return (reqmode);
  65268. +}
  65269. +
  65270. +__u32
  65271. +gr_acl_handle_mknod(const struct dentry * new_dentry,
  65272. + const struct dentry * parent_dentry,
  65273. + const struct vfsmount * parent_mnt,
  65274. + const int mode)
  65275. +{
  65276. + __u32 reqmode = GR_WRITE | GR_CREATE;
  65277. + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
  65278. + reqmode |= GR_SETID;
  65279. +
  65280. + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
  65281. + reqmode, GR_MKNOD_ACL_MSG);
  65282. +}
  65283. +
  65284. +__u32
  65285. +gr_acl_handle_mkdir(const struct dentry *new_dentry,
  65286. + const struct dentry *parent_dentry,
  65287. + const struct vfsmount *parent_mnt)
  65288. +{
  65289. + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
  65290. + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
  65291. +}
  65292. +
  65293. +#define RENAME_CHECK_SUCCESS(old, new) \
  65294. + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
  65295. + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
  65296. +
  65297. +int
  65298. +gr_acl_handle_rename(struct dentry *new_dentry,
  65299. + struct dentry *parent_dentry,
  65300. + const struct vfsmount *parent_mnt,
  65301. + struct dentry *old_dentry,
  65302. + struct inode *old_parent_inode,
  65303. + struct vfsmount *old_mnt, const struct filename *newname)
  65304. +{
  65305. + __u32 comp1, comp2;
  65306. + int error = 0;
  65307. +
  65308. + if (unlikely(!gr_acl_is_enabled()))
  65309. + return 0;
  65310. +
  65311. + if (d_is_negative(new_dentry)) {
  65312. + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
  65313. + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
  65314. + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
  65315. + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
  65316. + GR_DELETE | GR_AUDIT_DELETE |
  65317. + GR_AUDIT_READ | GR_AUDIT_WRITE |
  65318. + GR_SUPPRESS, old_mnt);
  65319. + } else {
  65320. + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
  65321. + GR_CREATE | GR_DELETE |
  65322. + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
  65323. + GR_AUDIT_READ | GR_AUDIT_WRITE |
  65324. + GR_SUPPRESS, parent_mnt);
  65325. + comp2 =
  65326. + gr_search_file(old_dentry,
  65327. + GR_READ | GR_WRITE | GR_AUDIT_READ |
  65328. + GR_DELETE | GR_AUDIT_DELETE |
  65329. + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
  65330. + }
  65331. +
  65332. + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
  65333. + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
  65334. + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
  65335. + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
  65336. + && !(comp2 & GR_SUPPRESS)) {
  65337. + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
  65338. + error = -EACCES;
  65339. + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
  65340. + error = -EACCES;
  65341. +
  65342. + return error;
  65343. +}
  65344. +
  65345. +void
  65346. +gr_acl_handle_exit(void)
  65347. +{
  65348. + u16 id;
  65349. + char *rolename;
  65350. +
  65351. + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
  65352. + !(current->role->roletype & GR_ROLE_PERSIST))) {
  65353. + id = current->acl_role_id;
  65354. + rolename = current->role->rolename;
  65355. + gr_set_acls(1);
  65356. + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
  65357. + }
  65358. +
  65359. + gr_put_exec_file(current);
  65360. + return;
  65361. +}
  65362. +
  65363. +int
  65364. +gr_acl_handle_procpidmem(const struct task_struct *task)
  65365. +{
  65366. + if (unlikely(!gr_acl_is_enabled()))
  65367. + return 0;
  65368. +
  65369. + if (task != current && task->acl->mode & GR_PROTPROCFD)
  65370. + return -EACCES;
  65371. +
  65372. + return 0;
  65373. +}
  65374. diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
  65375. new file mode 100644
  65376. index 0000000..f056b81
  65377. --- /dev/null
  65378. +++ b/grsecurity/gracl_ip.c
  65379. @@ -0,0 +1,386 @@
  65380. +#include <linux/kernel.h>
  65381. +#include <asm/uaccess.h>
  65382. +#include <asm/errno.h>
  65383. +#include <net/sock.h>
  65384. +#include <linux/file.h>
  65385. +#include <linux/fs.h>
  65386. +#include <linux/net.h>
  65387. +#include <linux/in.h>
  65388. +#include <linux/skbuff.h>
  65389. +#include <linux/ip.h>
  65390. +#include <linux/udp.h>
  65391. +#include <linux/types.h>
  65392. +#include <linux/sched.h>
  65393. +#include <linux/netdevice.h>
  65394. +#include <linux/inetdevice.h>
  65395. +#include <linux/gracl.h>
  65396. +#include <linux/grsecurity.h>
  65397. +#include <linux/grinternal.h>
  65398. +
  65399. +#define GR_BIND 0x01
  65400. +#define GR_CONNECT 0x02
  65401. +#define GR_INVERT 0x04
  65402. +#define GR_BINDOVERRIDE 0x08
  65403. +#define GR_CONNECTOVERRIDE 0x10
  65404. +#define GR_SOCK_FAMILY 0x20
  65405. +
  65406. +static const char * gr_protocols[IPPROTO_MAX] = {
  65407. + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
  65408. + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
  65409. + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
  65410. + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
  65411. + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
  65412. + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
  65413. + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
  65414. + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
  65415. + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
  65416. + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
  65417. + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
  65418. + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
  65419. + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
  65420. + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
  65421. + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
  65422. + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
  65423. + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
  65424. + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
  65425. + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
  65426. + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
  65427. + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
  65428. + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
  65429. + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
  65430. + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
  65431. + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
  65432. + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
  65433. + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
  65434. + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
  65435. + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
  65436. + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
  65437. + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
  65438. + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
  65439. + };
  65440. +
  65441. +static const char * gr_socktypes[SOCK_MAX] = {
  65442. + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
  65443. + "unknown:7", "unknown:8", "unknown:9", "packet"
  65444. + };
  65445. +
  65446. +static const char * gr_sockfamilies[AF_MAX+1] = {
  65447. + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
  65448. + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
  65449. + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
  65450. + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
  65451. + };
  65452. +
  65453. +const char *
  65454. +gr_proto_to_name(unsigned char proto)
  65455. +{
  65456. + return gr_protocols[proto];
  65457. +}
  65458. +
  65459. +const char *
  65460. +gr_socktype_to_name(unsigned char type)
  65461. +{
  65462. + return gr_socktypes[type];
  65463. +}
  65464. +
  65465. +const char *
  65466. +gr_sockfamily_to_name(unsigned char family)
  65467. +{
  65468. + return gr_sockfamilies[family];
  65469. +}
  65470. +
  65471. +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
  65472. +
  65473. +int
  65474. +gr_search_socket(const int domain, const int type, const int protocol)
  65475. +{
  65476. + struct acl_subject_label *curr;
  65477. + const struct cred *cred = current_cred();
  65478. +
  65479. + if (unlikely(!gr_acl_is_enabled()))
  65480. + goto exit;
  65481. +
  65482. + if ((domain < 0) || (type < 0) || (protocol < 0) ||
  65483. + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
  65484. + goto exit; // let the kernel handle it
  65485. +
  65486. + curr = current->acl;
  65487. +
  65488. + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
  65489. + /* the family is allowed, if this is PF_INET allow it only if
  65490. + the extra sock type/protocol checks pass */
  65491. + if (domain == PF_INET)
  65492. + goto inet_check;
  65493. + goto exit;
  65494. + } else {
  65495. + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
  65496. + __u32 fakeip = 0;
  65497. + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
  65498. + current->role->roletype, GR_GLOBAL_UID(cred->uid),
  65499. + GR_GLOBAL_GID(cred->gid), current->exec_file ?
  65500. + gr_to_filename(current->exec_file->f_path.dentry,
  65501. + current->exec_file->f_path.mnt) :
  65502. + curr->filename, curr->filename,
  65503. + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
  65504. + &current->signal->saved_ip);
  65505. + goto exit;
  65506. + }
  65507. + goto exit_fail;
  65508. + }
  65509. +
  65510. +inet_check:
  65511. + /* the rest of this checking is for IPv4 only */
  65512. + if (!curr->ips)
  65513. + goto exit;
  65514. +
  65515. + if ((curr->ip_type & (1U << type)) &&
  65516. + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
  65517. + goto exit;
  65518. +
  65519. + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
  65520. + /* we don't place acls on raw sockets , and sometimes
  65521. + dgram/ip sockets are opened for ioctl and not
  65522. + bind/connect, so we'll fake a bind learn log */
  65523. + if (type == SOCK_RAW || type == SOCK_PACKET) {
  65524. + __u32 fakeip = 0;
  65525. + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
  65526. + current->role->roletype, GR_GLOBAL_UID(cred->uid),
  65527. + GR_GLOBAL_GID(cred->gid), current->exec_file ?
  65528. + gr_to_filename(current->exec_file->f_path.dentry,
  65529. + current->exec_file->f_path.mnt) :
  65530. + curr->filename, curr->filename,
  65531. + &fakeip, 0, type,
  65532. + protocol, GR_CONNECT, &current->signal->saved_ip);
  65533. + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
  65534. + __u32 fakeip = 0;
  65535. + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
  65536. + current->role->roletype, GR_GLOBAL_UID(cred->uid),
  65537. + GR_GLOBAL_GID(cred->gid), current->exec_file ?
  65538. + gr_to_filename(current->exec_file->f_path.dentry,
  65539. + current->exec_file->f_path.mnt) :
  65540. + curr->filename, curr->filename,
  65541. + &fakeip, 0, type,
  65542. + protocol, GR_BIND, &current->signal->saved_ip);
  65543. + }
  65544. + /* we'll log when they use connect or bind */
  65545. + goto exit;
  65546. + }
  65547. +
  65548. +exit_fail:
  65549. + if (domain == PF_INET)
  65550. + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
  65551. + gr_socktype_to_name(type), gr_proto_to_name(protocol));
  65552. + else if (rcu_access_pointer(net_families[domain]) != NULL)
  65553. + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
  65554. + gr_socktype_to_name(type), protocol);
  65555. +
  65556. + return 0;
  65557. +exit:
  65558. + return 1;
  65559. +}
  65560. +
  65561. +int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask)
  65562. +{
  65563. + if ((ip->mode & mode) &&
  65564. + (ip_port >= ip->low) &&
  65565. + (ip_port <= ip->high) &&
  65566. + ((ntohl(ip_addr) & our_netmask) ==
  65567. + (ntohl(our_addr) & our_netmask))
  65568. + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
  65569. + && (ip->type & (1U << type))) {
  65570. + if (ip->mode & GR_INVERT)
  65571. + return 2; // specifically denied
  65572. + else
  65573. + return 1; // allowed
  65574. + }
  65575. +
  65576. + return 0; // not specifically allowed, may continue parsing
  65577. +}
  65578. +
  65579. +static int
  65580. +gr_search_connectbind(const int full_mode, struct sock *sk,
  65581. + struct sockaddr_in *addr, const int type)
  65582. +{
  65583. + char iface[IFNAMSIZ] = {0};
  65584. + struct acl_subject_label *curr;
  65585. + struct acl_ip_label *ip;
  65586. + struct inet_sock *isk;
  65587. + struct net_device *dev;
  65588. + struct in_device *idev;
  65589. + unsigned long i;
  65590. + int ret;
  65591. + int mode = full_mode & (GR_BIND | GR_CONNECT);
  65592. + __u32 ip_addr = 0;
  65593. + __u32 our_addr;
  65594. + __u32 our_netmask;
  65595. + char *p;
  65596. + __u16 ip_port = 0;
  65597. + const struct cred *cred = current_cred();
  65598. +
  65599. + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
  65600. + return 0;
  65601. +
  65602. + curr = current->acl;
  65603. + isk = inet_sk(sk);
  65604. +
  65605. + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
  65606. + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
  65607. + addr->sin_addr.s_addr = curr->inaddr_any_override;
  65608. + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
  65609. + struct sockaddr_in saddr;
  65610. + int err;
  65611. +
  65612. + saddr.sin_family = AF_INET;
  65613. + saddr.sin_addr.s_addr = curr->inaddr_any_override;
  65614. + saddr.sin_port = isk->inet_sport;
  65615. +
  65616. + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
  65617. + if (err)
  65618. + return err;
  65619. +
  65620. + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
  65621. + if (err)
  65622. + return err;
  65623. + }
  65624. +
  65625. + if (!curr->ips)
  65626. + return 0;
  65627. +
  65628. + ip_addr = addr->sin_addr.s_addr;
  65629. + ip_port = ntohs(addr->sin_port);
  65630. +
  65631. + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
  65632. + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
  65633. + current->role->roletype, GR_GLOBAL_UID(cred->uid),
  65634. + GR_GLOBAL_GID(cred->gid), current->exec_file ?
  65635. + gr_to_filename(current->exec_file->f_path.dentry,
  65636. + current->exec_file->f_path.mnt) :
  65637. + curr->filename, curr->filename,
  65638. + &ip_addr, ip_port, type,
  65639. + sk->sk_protocol, mode, &current->signal->saved_ip);
  65640. + return 0;
  65641. + }
  65642. +
  65643. + for (i = 0; i < curr->ip_num; i++) {
  65644. + ip = *(curr->ips + i);
  65645. + if (ip->iface != NULL) {
  65646. + strncpy(iface, ip->iface, IFNAMSIZ - 1);
  65647. + p = strchr(iface, ':');
  65648. + if (p != NULL)
  65649. + *p = '\0';
  65650. + dev = dev_get_by_name(sock_net(sk), iface);
  65651. + if (dev == NULL)
  65652. + continue;
  65653. + idev = in_dev_get(dev);
  65654. + if (idev == NULL) {
  65655. + dev_put(dev);
  65656. + continue;
  65657. + }
  65658. + rcu_read_lock();
  65659. + for_ifa(idev) {
  65660. + if (!strcmp(ip->iface, ifa->ifa_label)) {
  65661. + our_addr = ifa->ifa_address;
  65662. + our_netmask = 0xffffffff;
  65663. + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
  65664. + if (ret == 1) {
  65665. + rcu_read_unlock();
  65666. + in_dev_put(idev);
  65667. + dev_put(dev);
  65668. + return 0;
  65669. + } else if (ret == 2) {
  65670. + rcu_read_unlock();
  65671. + in_dev_put(idev);
  65672. + dev_put(dev);
  65673. + goto denied;
  65674. + }
  65675. + }
  65676. + } endfor_ifa(idev);
  65677. + rcu_read_unlock();
  65678. + in_dev_put(idev);
  65679. + dev_put(dev);
  65680. + } else {
  65681. + our_addr = ip->addr;
  65682. + our_netmask = ip->netmask;
  65683. + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
  65684. + if (ret == 1)
  65685. + return 0;
  65686. + else if (ret == 2)
  65687. + goto denied;
  65688. + }
  65689. + }
  65690. +
  65691. +denied:
  65692. + if (mode == GR_BIND)
  65693. + gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
  65694. + else if (mode == GR_CONNECT)
  65695. + gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
  65696. +
  65697. + return -EACCES;
  65698. +}
  65699. +
  65700. +int
  65701. +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
  65702. +{
  65703. + /* always allow disconnection of dgram sockets with connect */
  65704. + if (addr->sin_family == AF_UNSPEC)
  65705. + return 0;
  65706. + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
  65707. +}
  65708. +
  65709. +int
  65710. +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
  65711. +{
  65712. + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
  65713. +}
  65714. +
  65715. +int gr_search_listen(struct socket *sock)
  65716. +{
  65717. + struct sock *sk = sock->sk;
  65718. + struct sockaddr_in addr;
  65719. +
  65720. + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
  65721. + addr.sin_port = inet_sk(sk)->inet_sport;
  65722. +
  65723. + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
  65724. +}
  65725. +
  65726. +int gr_search_accept(struct socket *sock)
  65727. +{
  65728. + struct sock *sk = sock->sk;
  65729. + struct sockaddr_in addr;
  65730. +
  65731. + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
  65732. + addr.sin_port = inet_sk(sk)->inet_sport;
  65733. +
  65734. + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
  65735. +}
  65736. +
  65737. +int
  65738. +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
  65739. +{
  65740. + if (addr)
  65741. + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
  65742. + else {
  65743. + struct sockaddr_in sin;
  65744. + const struct inet_sock *inet = inet_sk(sk);
  65745. +
  65746. + sin.sin_addr.s_addr = inet->inet_daddr;
  65747. + sin.sin_port = inet->inet_dport;
  65748. +
  65749. + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
  65750. + }
  65751. +}
  65752. +
  65753. +int
  65754. +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
  65755. +{
  65756. + struct sockaddr_in sin;
  65757. +
  65758. + if (unlikely(skb->len < sizeof (struct udphdr)))
  65759. + return 0; // skip this packet
  65760. +
  65761. + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
  65762. + sin.sin_port = udp_hdr(skb)->source;
  65763. +
  65764. + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
  65765. +}
  65766. diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
  65767. new file mode 100644
  65768. index 0000000..25f54ef
  65769. --- /dev/null
  65770. +++ b/grsecurity/gracl_learn.c
  65771. @@ -0,0 +1,207 @@
  65772. +#include <linux/kernel.h>
  65773. +#include <linux/mm.h>
  65774. +#include <linux/sched.h>
  65775. +#include <linux/poll.h>
  65776. +#include <linux/string.h>
  65777. +#include <linux/file.h>
  65778. +#include <linux/types.h>
  65779. +#include <linux/vmalloc.h>
  65780. +#include <linux/grinternal.h>
  65781. +
  65782. +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
  65783. + size_t count, loff_t *ppos);
  65784. +extern int gr_acl_is_enabled(void);
  65785. +
  65786. +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
  65787. +static int gr_learn_attached;
  65788. +
  65789. +/* use a 512k buffer */
  65790. +#define LEARN_BUFFER_SIZE (512 * 1024)
  65791. +
  65792. +static DEFINE_SPINLOCK(gr_learn_lock);
  65793. +static DEFINE_MUTEX(gr_learn_user_mutex);
  65794. +
  65795. +/* we need to maintain two buffers, so that the kernel context of grlearn
  65796. + uses a semaphore around the userspace copying, and the other kernel contexts
  65797. + use a spinlock when copying into the buffer, since they cannot sleep
  65798. +*/
  65799. +static char *learn_buffer;
  65800. +static char *learn_buffer_user;
  65801. +static int learn_buffer_len;
  65802. +static int learn_buffer_user_len;
  65803. +
  65804. +static ssize_t
  65805. +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
  65806. +{
  65807. + DECLARE_WAITQUEUE(wait, current);
  65808. + ssize_t retval = 0;
  65809. +
  65810. + add_wait_queue(&learn_wait, &wait);
  65811. + set_current_state(TASK_INTERRUPTIBLE);
  65812. + do {
  65813. + mutex_lock(&gr_learn_user_mutex);
  65814. + spin_lock(&gr_learn_lock);
  65815. + if (learn_buffer_len)
  65816. + break;
  65817. + spin_unlock(&gr_learn_lock);
  65818. + mutex_unlock(&gr_learn_user_mutex);
  65819. + if (file->f_flags & O_NONBLOCK) {
  65820. + retval = -EAGAIN;
  65821. + goto out;
  65822. + }
  65823. + if (signal_pending(current)) {
  65824. + retval = -ERESTARTSYS;
  65825. + goto out;
  65826. + }
  65827. +
  65828. + schedule();
  65829. + } while (1);
  65830. +
  65831. + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
  65832. + learn_buffer_user_len = learn_buffer_len;
  65833. + retval = learn_buffer_len;
  65834. + learn_buffer_len = 0;
  65835. +
  65836. + spin_unlock(&gr_learn_lock);
  65837. +
  65838. + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
  65839. + retval = -EFAULT;
  65840. +
  65841. + mutex_unlock(&gr_learn_user_mutex);
  65842. +out:
  65843. + set_current_state(TASK_RUNNING);
  65844. + remove_wait_queue(&learn_wait, &wait);
  65845. + return retval;
  65846. +}
  65847. +
  65848. +static unsigned int
  65849. +poll_learn(struct file * file, poll_table * wait)
  65850. +{
  65851. + poll_wait(file, &learn_wait, wait);
  65852. +
  65853. + if (learn_buffer_len)
  65854. + return (POLLIN | POLLRDNORM);
  65855. +
  65856. + return 0;
  65857. +}
  65858. +
  65859. +void
  65860. +gr_clear_learn_entries(void)
  65861. +{
  65862. + char *tmp;
  65863. +
  65864. + mutex_lock(&gr_learn_user_mutex);
  65865. + spin_lock(&gr_learn_lock);
  65866. + tmp = learn_buffer;
  65867. + learn_buffer = NULL;
  65868. + spin_unlock(&gr_learn_lock);
  65869. + if (tmp)
  65870. + vfree(tmp);
  65871. + if (learn_buffer_user != NULL) {
  65872. + vfree(learn_buffer_user);
  65873. + learn_buffer_user = NULL;
  65874. + }
  65875. + learn_buffer_len = 0;
  65876. + mutex_unlock(&gr_learn_user_mutex);
  65877. +
  65878. + return;
  65879. +}
  65880. +
  65881. +void
  65882. +gr_add_learn_entry(const char *fmt, ...)
  65883. +{
  65884. + va_list args;
  65885. + unsigned int len;
  65886. +
  65887. + if (!gr_learn_attached)
  65888. + return;
  65889. +
  65890. + spin_lock(&gr_learn_lock);
  65891. +
  65892. + /* leave a gap at the end so we know when it's "full" but don't have to
  65893. + compute the exact length of the string we're trying to append
  65894. + */
  65895. + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
  65896. + spin_unlock(&gr_learn_lock);
  65897. + wake_up_interruptible(&learn_wait);
  65898. + return;
  65899. + }
  65900. + if (learn_buffer == NULL) {
  65901. + spin_unlock(&gr_learn_lock);
  65902. + return;
  65903. + }
  65904. +
  65905. + va_start(args, fmt);
  65906. + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
  65907. + va_end(args);
  65908. +
  65909. + learn_buffer_len += len + 1;
  65910. +
  65911. + spin_unlock(&gr_learn_lock);
  65912. + wake_up_interruptible(&learn_wait);
  65913. +
  65914. + return;
  65915. +}
  65916. +
  65917. +static int
  65918. +open_learn(struct inode *inode, struct file *file)
  65919. +{
  65920. + if (file->f_mode & FMODE_READ && gr_learn_attached)
  65921. + return -EBUSY;
  65922. + if (file->f_mode & FMODE_READ) {
  65923. + int retval = 0;
  65924. + mutex_lock(&gr_learn_user_mutex);
  65925. + if (learn_buffer == NULL)
  65926. + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
  65927. + if (learn_buffer_user == NULL)
  65928. + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
  65929. + if (learn_buffer == NULL) {
  65930. + retval = -ENOMEM;
  65931. + goto out_error;
  65932. + }
  65933. + if (learn_buffer_user == NULL) {
  65934. + retval = -ENOMEM;
  65935. + goto out_error;
  65936. + }
  65937. + learn_buffer_len = 0;
  65938. + learn_buffer_user_len = 0;
  65939. + gr_learn_attached = 1;
  65940. +out_error:
  65941. + mutex_unlock(&gr_learn_user_mutex);
  65942. + return retval;
  65943. + }
  65944. + return 0;
  65945. +}
  65946. +
  65947. +static int
  65948. +close_learn(struct inode *inode, struct file *file)
  65949. +{
  65950. + if (file->f_mode & FMODE_READ) {
  65951. + char *tmp = NULL;
  65952. + mutex_lock(&gr_learn_user_mutex);
  65953. + spin_lock(&gr_learn_lock);
  65954. + tmp = learn_buffer;
  65955. + learn_buffer = NULL;
  65956. + spin_unlock(&gr_learn_lock);
  65957. + if (tmp)
  65958. + vfree(tmp);
  65959. + if (learn_buffer_user != NULL) {
  65960. + vfree(learn_buffer_user);
  65961. + learn_buffer_user = NULL;
  65962. + }
  65963. + learn_buffer_len = 0;
  65964. + learn_buffer_user_len = 0;
  65965. + gr_learn_attached = 0;
  65966. + mutex_unlock(&gr_learn_user_mutex);
  65967. + }
  65968. +
  65969. + return 0;
  65970. +}
  65971. +
  65972. +const struct file_operations grsec_fops = {
  65973. + .read = read_learn,
  65974. + .write = write_grsec_handler,
  65975. + .open = open_learn,
  65976. + .release = close_learn,
  65977. + .poll = poll_learn,
  65978. +};
  65979. diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
  65980. new file mode 100644
  65981. index 0000000..361a099
  65982. --- /dev/null
  65983. +++ b/grsecurity/gracl_policy.c
  65984. @@ -0,0 +1,1782 @@
  65985. +#include <linux/kernel.h>
  65986. +#include <linux/module.h>
  65987. +#include <linux/sched.h>
  65988. +#include <linux/mm.h>
  65989. +#include <linux/file.h>
  65990. +#include <linux/fs.h>
  65991. +#include <linux/namei.h>
  65992. +#include <linux/mount.h>
  65993. +#include <linux/tty.h>
  65994. +#include <linux/proc_fs.h>
  65995. +#include <linux/lglock.h>
  65996. +#include <linux/slab.h>
  65997. +#include <linux/vmalloc.h>
  65998. +#include <linux/types.h>
  65999. +#include <linux/sysctl.h>
  66000. +#include <linux/netdevice.h>
  66001. +#include <linux/ptrace.h>
  66002. +#include <linux/gracl.h>
  66003. +#include <linux/gralloc.h>
  66004. +#include <linux/security.h>
  66005. +#include <linux/grinternal.h>
  66006. +#include <linux/pid_namespace.h>
  66007. +#include <linux/stop_machine.h>
  66008. +#include <linux/fdtable.h>
  66009. +#include <linux/percpu.h>
  66010. +#include <linux/lglock.h>
  66011. +#include <linux/hugetlb.h>
  66012. +#include <linux/posix-timers.h>
  66013. +#include "../fs/mount.h"
  66014. +
  66015. +#include <asm/uaccess.h>
  66016. +#include <asm/errno.h>
  66017. +#include <asm/mman.h>
  66018. +
  66019. +extern struct gr_policy_state *polstate;
  66020. +
  66021. +#define FOR_EACH_ROLE_START(role) \
  66022. + role = polstate->role_list; \
  66023. + while (role) {
  66024. +
  66025. +#define FOR_EACH_ROLE_END(role) \
  66026. + role = role->prev; \
  66027. + }
  66028. +
  66029. +struct path gr_real_root;
  66030. +
  66031. +extern struct gr_alloc_state *current_alloc_state;
  66032. +
  66033. +u16 acl_sp_role_value;
  66034. +
  66035. +static DEFINE_MUTEX(gr_dev_mutex);
  66036. +
  66037. +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
  66038. +extern void gr_clear_learn_entries(void);
  66039. +
  66040. +static struct gr_arg gr_usermode;
  66041. +static unsigned char gr_system_salt[GR_SALT_LEN];
  66042. +static unsigned char gr_system_sum[GR_SHA_LEN];
  66043. +
  66044. +static unsigned int gr_auth_attempts = 0;
  66045. +static unsigned long gr_auth_expires = 0UL;
  66046. +
  66047. +struct acl_object_label *fakefs_obj_rw;
  66048. +struct acl_object_label *fakefs_obj_rwx;
  66049. +
  66050. +extern int gr_init_uidset(void);
  66051. +extern void gr_free_uidset(void);
  66052. +extern void gr_remove_uid(uid_t uid);
  66053. +extern int gr_find_uid(uid_t uid);
  66054. +
  66055. +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
  66056. +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
  66057. +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
  66058. +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
  66059. +extern struct acl_role_label *__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid, const gid_t gid);
  66060. +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
  66061. +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
  66062. +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
  66063. +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
  66064. +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
  66065. +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
  66066. +extern void assign_special_role(const char *rolename);
  66067. +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
  66068. +extern int gr_rbac_disable(void *unused);
  66069. +extern void gr_enable_rbac_system(void);
  66070. +
  66071. +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
  66072. +{
  66073. + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
  66074. + return -EFAULT;
  66075. +
  66076. + return 0;
  66077. +}
  66078. +
  66079. +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
  66080. +{
  66081. + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
  66082. + return -EFAULT;
  66083. +
  66084. + return 0;
  66085. +}
  66086. +
  66087. +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
  66088. +{
  66089. + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
  66090. + return -EFAULT;
  66091. +
  66092. + return 0;
  66093. +}
  66094. +
  66095. +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
  66096. +{
  66097. + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
  66098. + return -EFAULT;
  66099. +
  66100. + return 0;
  66101. +}
  66102. +
  66103. +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
  66104. +{
  66105. + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
  66106. + return -EFAULT;
  66107. +
  66108. + return 0;
  66109. +}
  66110. +
  66111. +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
  66112. +{
  66113. + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
  66114. + return -EFAULT;
  66115. +
  66116. + return 0;
  66117. +}
  66118. +
  66119. +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
  66120. +{
  66121. + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
  66122. + return -EFAULT;
  66123. +
  66124. + return 0;
  66125. +}
  66126. +
  66127. +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
  66128. +{
  66129. + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
  66130. + return -EFAULT;
  66131. +
  66132. + return 0;
  66133. +}
  66134. +
  66135. +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
  66136. +{
  66137. + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
  66138. + return -EFAULT;
  66139. +
  66140. + return 0;
  66141. +}
  66142. +
  66143. +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
  66144. +{
  66145. + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
  66146. + return -EFAULT;
  66147. +
  66148. + if (((uwrap->version != GRSECURITY_VERSION) &&
  66149. + (uwrap->version != 0x2901)) ||
  66150. + (uwrap->size != sizeof(struct gr_arg)))
  66151. + return -EINVAL;
  66152. +
  66153. + return 0;
  66154. +}
  66155. +
  66156. +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
  66157. +{
  66158. + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
  66159. + return -EFAULT;
  66160. +
  66161. + return 0;
  66162. +}
  66163. +
  66164. +static size_t get_gr_arg_wrapper_size_normal(void)
  66165. +{
  66166. + return sizeof(struct gr_arg_wrapper);
  66167. +}
  66168. +
  66169. +#ifdef CONFIG_COMPAT
  66170. +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
  66171. +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
  66172. +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
  66173. +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
  66174. +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
  66175. +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
  66176. +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
  66177. +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
  66178. +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
  66179. +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
  66180. +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
  66181. +extern size_t get_gr_arg_wrapper_size_compat(void);
  66182. +
  66183. +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
  66184. +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
  66185. +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
  66186. +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
  66187. +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
  66188. +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
  66189. +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
  66190. +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
  66191. +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
  66192. +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
  66193. +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
  66194. +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
  66195. +
  66196. +#else
  66197. +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
  66198. +#define copy_gr_arg copy_gr_arg_normal
  66199. +#define copy_gr_hash_struct copy_gr_hash_struct_normal
  66200. +#define copy_acl_object_label copy_acl_object_label_normal
  66201. +#define copy_acl_subject_label copy_acl_subject_label_normal
  66202. +#define copy_acl_role_label copy_acl_role_label_normal
  66203. +#define copy_acl_ip_label copy_acl_ip_label_normal
  66204. +#define copy_pointer_from_array copy_pointer_from_array_normal
  66205. +#define copy_sprole_pw copy_sprole_pw_normal
  66206. +#define copy_role_transition copy_role_transition_normal
  66207. +#define copy_role_allowed_ip copy_role_allowed_ip_normal
  66208. +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
  66209. +#endif
  66210. +
  66211. +static struct acl_subject_label *
  66212. +lookup_subject_map(const struct acl_subject_label *userp)
  66213. +{
  66214. + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
  66215. + struct subject_map *match;
  66216. +
  66217. + match = polstate->subj_map_set.s_hash[index];
  66218. +
  66219. + while (match && match->user != userp)
  66220. + match = match->next;
  66221. +
  66222. + if (match != NULL)
  66223. + return match->kernel;
  66224. + else
  66225. + return NULL;
  66226. +}
  66227. +
  66228. +static void
  66229. +insert_subj_map_entry(struct subject_map *subjmap)
  66230. +{
  66231. + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
  66232. + struct subject_map **curr;
  66233. +
  66234. + subjmap->prev = NULL;
  66235. +
  66236. + curr = &polstate->subj_map_set.s_hash[index];
  66237. + if (*curr != NULL)
  66238. + (*curr)->prev = subjmap;
  66239. +
  66240. + subjmap->next = *curr;
  66241. + *curr = subjmap;
  66242. +
  66243. + return;
  66244. +}
  66245. +
  66246. +static void
  66247. +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
  66248. +{
  66249. + unsigned int index =
  66250. + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
  66251. + struct acl_role_label **curr;
  66252. + struct acl_role_label *tmp, *tmp2;
  66253. +
  66254. + curr = &polstate->acl_role_set.r_hash[index];
  66255. +
  66256. + /* simple case, slot is empty, just set it to our role */
  66257. + if (*curr == NULL) {
  66258. + *curr = role;
  66259. + } else {
  66260. + /* example:
  66261. + 1 -> 2 -> 3 (adding 2 -> 3 to here)
  66262. + 2 -> 3
  66263. + */
  66264. + /* first check to see if we can already be reached via this slot */
  66265. + tmp = *curr;
  66266. + while (tmp && tmp != role)
  66267. + tmp = tmp->next;
  66268. + if (tmp == role) {
  66269. + /* we don't need to add ourselves to this slot's chain */
  66270. + return;
  66271. + }
  66272. + /* we need to add ourselves to this chain, two cases */
  66273. + if (role->next == NULL) {
  66274. + /* simple case, append the current chain to our role */
  66275. + role->next = *curr;
  66276. + *curr = role;
  66277. + } else {
  66278. + /* 1 -> 2 -> 3 -> 4
  66279. + 2 -> 3 -> 4
  66280. + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
  66281. + */
  66282. + /* trickier case: walk our role's chain until we find
  66283. + the role for the start of the current slot's chain */
  66284. + tmp = role;
  66285. + tmp2 = *curr;
  66286. + while (tmp->next && tmp->next != tmp2)
  66287. + tmp = tmp->next;
  66288. + if (tmp->next == tmp2) {
  66289. + /* from example above, we found 3, so just
  66290. + replace this slot's chain with ours */
  66291. + *curr = role;
  66292. + } else {
  66293. + /* we didn't find a subset of our role's chain
  66294. + in the current slot's chain, so append their
  66295. + chain to ours, and set us as the first role in
  66296. + the slot's chain
  66297. +
  66298. + we could fold this case with the case above,
  66299. + but making it explicit for clarity
  66300. + */
  66301. + tmp->next = tmp2;
  66302. + *curr = role;
  66303. + }
  66304. + }
  66305. + }
  66306. +
  66307. + return;
  66308. +}
  66309. +
  66310. +static void
  66311. +insert_acl_role_label(struct acl_role_label *role)
  66312. +{
  66313. + int i;
  66314. +
  66315. + if (polstate->role_list == NULL) {
  66316. + polstate->role_list = role;
  66317. + role->prev = NULL;
  66318. + } else {
  66319. + role->prev = polstate->role_list;
  66320. + polstate->role_list = role;
  66321. + }
  66322. +
  66323. + /* used for hash chains */
  66324. + role->next = NULL;
  66325. +
  66326. + if (role->roletype & GR_ROLE_DOMAIN) {
  66327. + for (i = 0; i < role->domain_child_num; i++)
  66328. + __insert_acl_role_label(role, role->domain_children[i]);
  66329. + } else
  66330. + __insert_acl_role_label(role, role->uidgid);
  66331. +}
  66332. +
  66333. +static int
  66334. +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
  66335. +{
  66336. + struct name_entry **curr, *nentry;
  66337. + struct inodev_entry *ientry;
  66338. + unsigned int len = strlen(name);
  66339. + unsigned int key = full_name_hash(name, len);
  66340. + unsigned int index = key % polstate->name_set.n_size;
  66341. +
  66342. + curr = &polstate->name_set.n_hash[index];
  66343. +
  66344. + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
  66345. + curr = &((*curr)->next);
  66346. +
  66347. + if (*curr != NULL)
  66348. + return 1;
  66349. +
  66350. + nentry = acl_alloc(sizeof (struct name_entry));
  66351. + if (nentry == NULL)
  66352. + return 0;
  66353. + ientry = acl_alloc(sizeof (struct inodev_entry));
  66354. + if (ientry == NULL)
  66355. + return 0;
  66356. + ientry->nentry = nentry;
  66357. +
  66358. + nentry->key = key;
  66359. + nentry->name = name;
  66360. + nentry->inode = inode;
  66361. + nentry->device = device;
  66362. + nentry->len = len;
  66363. + nentry->deleted = deleted;
  66364. +
  66365. + nentry->prev = NULL;
  66366. + curr = &polstate->name_set.n_hash[index];
  66367. + if (*curr != NULL)
  66368. + (*curr)->prev = nentry;
  66369. + nentry->next = *curr;
  66370. + *curr = nentry;
  66371. +
  66372. + /* insert us into the table searchable by inode/dev */
  66373. + __insert_inodev_entry(polstate, ientry);
  66374. +
  66375. + return 1;
  66376. +}
  66377. +
  66378. +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
  66379. +
  66380. +static void *
  66381. +create_table(__u32 * len, int elementsize)
  66382. +{
  66383. + unsigned int table_sizes[] = {
  66384. + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
  66385. + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
  66386. + 4194301, 8388593, 16777213, 33554393, 67108859
  66387. + };
  66388. + void *newtable = NULL;
  66389. + unsigned int pwr = 0;
  66390. +
  66391. + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
  66392. + table_sizes[pwr] <= *len)
  66393. + pwr++;
  66394. +
  66395. + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
  66396. + return newtable;
  66397. +
  66398. + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
  66399. + newtable =
  66400. + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
  66401. + else
  66402. + newtable = vmalloc(table_sizes[pwr] * elementsize);
  66403. +
  66404. + *len = table_sizes[pwr];
  66405. +
  66406. + return newtable;
  66407. +}
  66408. +
  66409. +static int
  66410. +init_variables(const struct gr_arg *arg, bool reload)
  66411. +{
  66412. + struct task_struct *reaper = init_pid_ns.child_reaper;
  66413. + unsigned int stacksize;
  66414. +
  66415. + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
  66416. + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
  66417. + polstate->name_set.n_size = arg->role_db.num_objects;
  66418. + polstate->inodev_set.i_size = arg->role_db.num_objects;
  66419. +
  66420. + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
  66421. + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
  66422. + return 1;
  66423. +
  66424. + if (!reload) {
  66425. + if (!gr_init_uidset())
  66426. + return 1;
  66427. + }
  66428. +
  66429. + /* set up the stack that holds allocation info */
  66430. +
  66431. + stacksize = arg->role_db.num_pointers + 5;
  66432. +
  66433. + if (!acl_alloc_stack_init(stacksize))
  66434. + return 1;
  66435. +
  66436. + if (!reload) {
  66437. + /* grab reference for the real root dentry and vfsmount */
  66438. + get_fs_root(reaper->fs, &gr_real_root);
  66439. +
  66440. +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
  66441. + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(gr_real_root.dentry), gr_real_root.dentry->d_inode->i_ino);
  66442. +#endif
  66443. +
  66444. + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
  66445. + if (fakefs_obj_rw == NULL)
  66446. + return 1;
  66447. + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
  66448. +
  66449. + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
  66450. + if (fakefs_obj_rwx == NULL)
  66451. + return 1;
  66452. + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
  66453. + }
  66454. +
  66455. + polstate->subj_map_set.s_hash =
  66456. + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
  66457. + polstate->acl_role_set.r_hash =
  66458. + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
  66459. + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
  66460. + polstate->inodev_set.i_hash =
  66461. + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
  66462. +
  66463. + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
  66464. + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
  66465. + return 1;
  66466. +
  66467. + memset(polstate->subj_map_set.s_hash, 0,
  66468. + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
  66469. + memset(polstate->acl_role_set.r_hash, 0,
  66470. + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
  66471. + memset(polstate->name_set.n_hash, 0,
  66472. + sizeof (struct name_entry *) * polstate->name_set.n_size);
  66473. + memset(polstate->inodev_set.i_hash, 0,
  66474. + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
  66475. +
  66476. + return 0;
  66477. +}
  66478. +
  66479. +/* free information not needed after startup
  66480. + currently contains user->kernel pointer mappings for subjects
  66481. +*/
  66482. +
  66483. +static void
  66484. +free_init_variables(void)
  66485. +{
  66486. + __u32 i;
  66487. +
  66488. + if (polstate->subj_map_set.s_hash) {
  66489. + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
  66490. + if (polstate->subj_map_set.s_hash[i]) {
  66491. + kfree(polstate->subj_map_set.s_hash[i]);
  66492. + polstate->subj_map_set.s_hash[i] = NULL;
  66493. + }
  66494. + }
  66495. +
  66496. + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
  66497. + PAGE_SIZE)
  66498. + kfree(polstate->subj_map_set.s_hash);
  66499. + else
  66500. + vfree(polstate->subj_map_set.s_hash);
  66501. + }
  66502. +
  66503. + return;
  66504. +}
  66505. +
  66506. +static void
  66507. +free_variables(bool reload)
  66508. +{
  66509. + struct acl_subject_label *s;
  66510. + struct acl_role_label *r;
  66511. + struct task_struct *task, *task2;
  66512. + unsigned int x;
  66513. +
  66514. + if (!reload) {
  66515. + gr_clear_learn_entries();
  66516. +
  66517. + read_lock(&tasklist_lock);
  66518. + do_each_thread(task2, task) {
  66519. + task->acl_sp_role = 0;
  66520. + task->acl_role_id = 0;
  66521. + task->inherited = 0;
  66522. + task->acl = NULL;
  66523. + task->role = NULL;
  66524. + } while_each_thread(task2, task);
  66525. + read_unlock(&tasklist_lock);
  66526. +
  66527. + kfree(fakefs_obj_rw);
  66528. + fakefs_obj_rw = NULL;
  66529. + kfree(fakefs_obj_rwx);
  66530. + fakefs_obj_rwx = NULL;
  66531. +
  66532. + /* release the reference to the real root dentry and vfsmount */
  66533. + path_put(&gr_real_root);
  66534. + memset(&gr_real_root, 0, sizeof(gr_real_root));
  66535. + }
  66536. +
  66537. + /* free all object hash tables */
  66538. +
  66539. + FOR_EACH_ROLE_START(r)
  66540. + if (r->subj_hash == NULL)
  66541. + goto next_role;
  66542. + FOR_EACH_SUBJECT_START(r, s, x)
  66543. + if (s->obj_hash == NULL)
  66544. + break;
  66545. + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
  66546. + kfree(s->obj_hash);
  66547. + else
  66548. + vfree(s->obj_hash);
  66549. + FOR_EACH_SUBJECT_END(s, x)
  66550. + FOR_EACH_NESTED_SUBJECT_START(r, s)
  66551. + if (s->obj_hash == NULL)
  66552. + break;
  66553. + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
  66554. + kfree(s->obj_hash);
  66555. + else
  66556. + vfree(s->obj_hash);
  66557. + FOR_EACH_NESTED_SUBJECT_END(s)
  66558. + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
  66559. + kfree(r->subj_hash);
  66560. + else
  66561. + vfree(r->subj_hash);
  66562. + r->subj_hash = NULL;
  66563. +next_role:
  66564. + FOR_EACH_ROLE_END(r)
  66565. +
  66566. + acl_free_all();
  66567. +
  66568. + if (polstate->acl_role_set.r_hash) {
  66569. + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
  66570. + PAGE_SIZE)
  66571. + kfree(polstate->acl_role_set.r_hash);
  66572. + else
  66573. + vfree(polstate->acl_role_set.r_hash);
  66574. + }
  66575. + if (polstate->name_set.n_hash) {
  66576. + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
  66577. + PAGE_SIZE)
  66578. + kfree(polstate->name_set.n_hash);
  66579. + else
  66580. + vfree(polstate->name_set.n_hash);
  66581. + }
  66582. +
  66583. + if (polstate->inodev_set.i_hash) {
  66584. + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
  66585. + PAGE_SIZE)
  66586. + kfree(polstate->inodev_set.i_hash);
  66587. + else
  66588. + vfree(polstate->inodev_set.i_hash);
  66589. + }
  66590. +
  66591. + if (!reload)
  66592. + gr_free_uidset();
  66593. +
  66594. + memset(&polstate->name_set, 0, sizeof (struct name_db));
  66595. + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
  66596. + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
  66597. + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
  66598. +
  66599. + polstate->default_role = NULL;
  66600. + polstate->kernel_role = NULL;
  66601. + polstate->role_list = NULL;
  66602. +
  66603. + return;
  66604. +}
  66605. +
  66606. +static struct acl_subject_label *
  66607. +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
  66608. +
  66609. +static int alloc_and_copy_string(char **name, unsigned int maxlen)
  66610. +{
  66611. + unsigned int len = strnlen_user(*name, maxlen);
  66612. + char *tmp;
  66613. +
  66614. + if (!len || len >= maxlen)
  66615. + return -EINVAL;
  66616. +
  66617. + if ((tmp = (char *) acl_alloc(len)) == NULL)
  66618. + return -ENOMEM;
  66619. +
  66620. + if (copy_from_user(tmp, *name, len))
  66621. + return -EFAULT;
  66622. +
  66623. + tmp[len-1] = '\0';
  66624. + *name = tmp;
  66625. +
  66626. + return 0;
  66627. +}
  66628. +
  66629. +static int
  66630. +copy_user_glob(struct acl_object_label *obj)
  66631. +{
  66632. + struct acl_object_label *g_tmp, **guser;
  66633. + int error;
  66634. +
  66635. + if (obj->globbed == NULL)
  66636. + return 0;
  66637. +
  66638. + guser = &obj->globbed;
  66639. + while (*guser) {
  66640. + g_tmp = (struct acl_object_label *)
  66641. + acl_alloc(sizeof (struct acl_object_label));
  66642. + if (g_tmp == NULL)
  66643. + return -ENOMEM;
  66644. +
  66645. + if (copy_acl_object_label(g_tmp, *guser))
  66646. + return -EFAULT;
  66647. +
  66648. + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
  66649. + if (error)
  66650. + return error;
  66651. +
  66652. + *guser = g_tmp;
  66653. + guser = &(g_tmp->next);
  66654. + }
  66655. +
  66656. + return 0;
  66657. +}
  66658. +
  66659. +static int
  66660. +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
  66661. + struct acl_role_label *role)
  66662. +{
  66663. + struct acl_object_label *o_tmp;
  66664. + int ret;
  66665. +
  66666. + while (userp) {
  66667. + if ((o_tmp = (struct acl_object_label *)
  66668. + acl_alloc(sizeof (struct acl_object_label))) == NULL)
  66669. + return -ENOMEM;
  66670. +
  66671. + if (copy_acl_object_label(o_tmp, userp))
  66672. + return -EFAULT;
  66673. +
  66674. + userp = o_tmp->prev;
  66675. +
  66676. + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
  66677. + if (ret)
  66678. + return ret;
  66679. +
  66680. + insert_acl_obj_label(o_tmp, subj);
  66681. + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
  66682. + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
  66683. + return -ENOMEM;
  66684. +
  66685. + ret = copy_user_glob(o_tmp);
  66686. + if (ret)
  66687. + return ret;
  66688. +
  66689. + if (o_tmp->nested) {
  66690. + int already_copied;
  66691. +
  66692. + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
  66693. + if (IS_ERR(o_tmp->nested))
  66694. + return PTR_ERR(o_tmp->nested);
  66695. +
  66696. + /* insert into nested subject list if we haven't copied this one yet
  66697. + to prevent duplicate entries */
  66698. + if (!already_copied) {
  66699. + o_tmp->nested->next = role->hash->first;
  66700. + role->hash->first = o_tmp->nested;
  66701. + }
  66702. + }
  66703. + }
  66704. +
  66705. + return 0;
  66706. +}
  66707. +
  66708. +static __u32
  66709. +count_user_subjs(struct acl_subject_label *userp)
  66710. +{
  66711. + struct acl_subject_label s_tmp;
  66712. + __u32 num = 0;
  66713. +
  66714. + while (userp) {
  66715. + if (copy_acl_subject_label(&s_tmp, userp))
  66716. + break;
  66717. +
  66718. + userp = s_tmp.prev;
  66719. + }
  66720. +
  66721. + return num;
  66722. +}
  66723. +
  66724. +static int
  66725. +copy_user_allowedips(struct acl_role_label *rolep)
  66726. +{
  66727. + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
  66728. +
  66729. + ruserip = rolep->allowed_ips;
  66730. +
  66731. + while (ruserip) {
  66732. + rlast = rtmp;
  66733. +
  66734. + if ((rtmp = (struct role_allowed_ip *)
  66735. + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
  66736. + return -ENOMEM;
  66737. +
  66738. + if (copy_role_allowed_ip(rtmp, ruserip))
  66739. + return -EFAULT;
  66740. +
  66741. + ruserip = rtmp->prev;
  66742. +
  66743. + if (!rlast) {
  66744. + rtmp->prev = NULL;
  66745. + rolep->allowed_ips = rtmp;
  66746. + } else {
  66747. + rlast->next = rtmp;
  66748. + rtmp->prev = rlast;
  66749. + }
  66750. +
  66751. + if (!ruserip)
  66752. + rtmp->next = NULL;
  66753. + }
  66754. +
  66755. + return 0;
  66756. +}
  66757. +
  66758. +static int
  66759. +copy_user_transitions(struct acl_role_label *rolep)
  66760. +{
  66761. + struct role_transition *rusertp, *rtmp = NULL, *rlast;
  66762. + int error;
  66763. +
  66764. + rusertp = rolep->transitions;
  66765. +
  66766. + while (rusertp) {
  66767. + rlast = rtmp;
  66768. +
  66769. + if ((rtmp = (struct role_transition *)
  66770. + acl_alloc(sizeof (struct role_transition))) == NULL)
  66771. + return -ENOMEM;
  66772. +
  66773. + if (copy_role_transition(rtmp, rusertp))
  66774. + return -EFAULT;
  66775. +
  66776. + rusertp = rtmp->prev;
  66777. +
  66778. + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
  66779. + if (error)
  66780. + return error;
  66781. +
  66782. + if (!rlast) {
  66783. + rtmp->prev = NULL;
  66784. + rolep->transitions = rtmp;
  66785. + } else {
  66786. + rlast->next = rtmp;
  66787. + rtmp->prev = rlast;
  66788. + }
  66789. +
  66790. + if (!rusertp)
  66791. + rtmp->next = NULL;
  66792. + }
  66793. +
  66794. + return 0;
  66795. +}
  66796. +
  66797. +static __u32 count_user_objs(const struct acl_object_label __user *userp)
  66798. +{
  66799. + struct acl_object_label o_tmp;
  66800. + __u32 num = 0;
  66801. +
  66802. + while (userp) {
  66803. + if (copy_acl_object_label(&o_tmp, userp))
  66804. + break;
  66805. +
  66806. + userp = o_tmp.prev;
  66807. + num++;
  66808. + }
  66809. +
  66810. + return num;
  66811. +}
  66812. +
  66813. +static struct acl_subject_label *
  66814. +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
  66815. +{
  66816. + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
  66817. + __u32 num_objs;
  66818. + struct acl_ip_label **i_tmp, *i_utmp2;
  66819. + struct gr_hash_struct ghash;
  66820. + struct subject_map *subjmap;
  66821. + unsigned int i_num;
  66822. + int err;
  66823. +
  66824. + if (already_copied != NULL)
  66825. + *already_copied = 0;
  66826. +
  66827. + s_tmp = lookup_subject_map(userp);
  66828. +
  66829. + /* we've already copied this subject into the kernel, just return
  66830. + the reference to it, and don't copy it over again
  66831. + */
  66832. + if (s_tmp) {
  66833. + if (already_copied != NULL)
  66834. + *already_copied = 1;
  66835. + return(s_tmp);
  66836. + }
  66837. +
  66838. + if ((s_tmp = (struct acl_subject_label *)
  66839. + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
  66840. + return ERR_PTR(-ENOMEM);
  66841. +
  66842. + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
  66843. + if (subjmap == NULL)
  66844. + return ERR_PTR(-ENOMEM);
  66845. +
  66846. + subjmap->user = userp;
  66847. + subjmap->kernel = s_tmp;
  66848. + insert_subj_map_entry(subjmap);
  66849. +
  66850. + if (copy_acl_subject_label(s_tmp, userp))
  66851. + return ERR_PTR(-EFAULT);
  66852. +
  66853. + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
  66854. + if (err)
  66855. + return ERR_PTR(err);
  66856. +
  66857. + if (!strcmp(s_tmp->filename, "/"))
  66858. + role->root_label = s_tmp;
  66859. +
  66860. + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
  66861. + return ERR_PTR(-EFAULT);
  66862. +
  66863. + /* copy user and group transition tables */
  66864. +
  66865. + if (s_tmp->user_trans_num) {
  66866. + uid_t *uidlist;
  66867. +
  66868. + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
  66869. + if (uidlist == NULL)
  66870. + return ERR_PTR(-ENOMEM);
  66871. + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
  66872. + return ERR_PTR(-EFAULT);
  66873. +
  66874. + s_tmp->user_transitions = uidlist;
  66875. + }
  66876. +
  66877. + if (s_tmp->group_trans_num) {
  66878. + gid_t *gidlist;
  66879. +
  66880. + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
  66881. + if (gidlist == NULL)
  66882. + return ERR_PTR(-ENOMEM);
  66883. + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
  66884. + return ERR_PTR(-EFAULT);
  66885. +
  66886. + s_tmp->group_transitions = gidlist;
  66887. + }
  66888. +
  66889. + /* set up object hash table */
  66890. + num_objs = count_user_objs(ghash.first);
  66891. +
  66892. + s_tmp->obj_hash_size = num_objs;
  66893. + s_tmp->obj_hash =
  66894. + (struct acl_object_label **)
  66895. + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
  66896. +
  66897. + if (!s_tmp->obj_hash)
  66898. + return ERR_PTR(-ENOMEM);
  66899. +
  66900. + memset(s_tmp->obj_hash, 0,
  66901. + s_tmp->obj_hash_size *
  66902. + sizeof (struct acl_object_label *));
  66903. +
  66904. + /* add in objects */
  66905. + err = copy_user_objs(ghash.first, s_tmp, role);
  66906. +
  66907. + if (err)
  66908. + return ERR_PTR(err);
  66909. +
  66910. + /* set pointer for parent subject */
  66911. + if (s_tmp->parent_subject) {
  66912. + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
  66913. +
  66914. + if (IS_ERR(s_tmp2))
  66915. + return s_tmp2;
  66916. +
  66917. + s_tmp->parent_subject = s_tmp2;
  66918. + }
  66919. +
  66920. + /* add in ip acls */
  66921. +
  66922. + if (!s_tmp->ip_num) {
  66923. + s_tmp->ips = NULL;
  66924. + goto insert;
  66925. + }
  66926. +
  66927. + i_tmp =
  66928. + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
  66929. + sizeof (struct acl_ip_label *));
  66930. +
  66931. + if (!i_tmp)
  66932. + return ERR_PTR(-ENOMEM);
  66933. +
  66934. + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
  66935. + *(i_tmp + i_num) =
  66936. + (struct acl_ip_label *)
  66937. + acl_alloc(sizeof (struct acl_ip_label));
  66938. + if (!*(i_tmp + i_num))
  66939. + return ERR_PTR(-ENOMEM);
  66940. +
  66941. + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
  66942. + return ERR_PTR(-EFAULT);
  66943. +
  66944. + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
  66945. + return ERR_PTR(-EFAULT);
  66946. +
  66947. + if ((*(i_tmp + i_num))->iface == NULL)
  66948. + continue;
  66949. +
  66950. + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
  66951. + if (err)
  66952. + return ERR_PTR(err);
  66953. + }
  66954. +
  66955. + s_tmp->ips = i_tmp;
  66956. +
  66957. +insert:
  66958. + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
  66959. + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
  66960. + return ERR_PTR(-ENOMEM);
  66961. +
  66962. + return s_tmp;
  66963. +}
  66964. +
  66965. +static int
  66966. +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
  66967. +{
  66968. + struct acl_subject_label s_pre;
  66969. + struct acl_subject_label * ret;
  66970. + int err;
  66971. +
  66972. + while (userp) {
  66973. + if (copy_acl_subject_label(&s_pre, userp))
  66974. + return -EFAULT;
  66975. +
  66976. + ret = do_copy_user_subj(userp, role, NULL);
  66977. +
  66978. + err = PTR_ERR(ret);
  66979. + if (IS_ERR(ret))
  66980. + return err;
  66981. +
  66982. + insert_acl_subj_label(ret, role);
  66983. +
  66984. + userp = s_pre.prev;
  66985. + }
  66986. +
  66987. + return 0;
  66988. +}
  66989. +
  66990. +static int
  66991. +copy_user_acl(struct gr_arg *arg)
  66992. +{
  66993. + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
  66994. + struct acl_subject_label *subj_list;
  66995. + struct sprole_pw *sptmp;
  66996. + struct gr_hash_struct *ghash;
  66997. + uid_t *domainlist;
  66998. + unsigned int r_num;
  66999. + int err = 0;
  67000. + __u16 i;
  67001. + __u32 num_subjs;
  67002. +
  67003. + /* we need a default and kernel role */
  67004. + if (arg->role_db.num_roles < 2)
  67005. + return -EINVAL;
  67006. +
  67007. + /* copy special role authentication info from userspace */
  67008. +
  67009. + polstate->num_sprole_pws = arg->num_sprole_pws;
  67010. + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
  67011. +
  67012. + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
  67013. + return -ENOMEM;
  67014. +
  67015. + for (i = 0; i < polstate->num_sprole_pws; i++) {
  67016. + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
  67017. + if (!sptmp)
  67018. + return -ENOMEM;
  67019. + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
  67020. + return -EFAULT;
  67021. +
  67022. + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
  67023. + if (err)
  67024. + return err;
  67025. +
  67026. +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
  67027. + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
  67028. +#endif
  67029. +
  67030. + polstate->acl_special_roles[i] = sptmp;
  67031. + }
  67032. +
  67033. + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
  67034. +
  67035. + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
  67036. + r_tmp = acl_alloc(sizeof (struct acl_role_label));
  67037. +
  67038. + if (!r_tmp)
  67039. + return -ENOMEM;
  67040. +
  67041. + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
  67042. + return -EFAULT;
  67043. +
  67044. + if (copy_acl_role_label(r_tmp, r_utmp2))
  67045. + return -EFAULT;
  67046. +
  67047. + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
  67048. + if (err)
  67049. + return err;
  67050. +
  67051. + if (!strcmp(r_tmp->rolename, "default")
  67052. + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
  67053. + polstate->default_role = r_tmp;
  67054. + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
  67055. + polstate->kernel_role = r_tmp;
  67056. + }
  67057. +
  67058. + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
  67059. + return -ENOMEM;
  67060. +
  67061. + if (copy_gr_hash_struct(ghash, r_tmp->hash))
  67062. + return -EFAULT;
  67063. +
  67064. + r_tmp->hash = ghash;
  67065. +
  67066. + num_subjs = count_user_subjs(r_tmp->hash->first);
  67067. +
  67068. + r_tmp->subj_hash_size = num_subjs;
  67069. + r_tmp->subj_hash =
  67070. + (struct acl_subject_label **)
  67071. + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
  67072. +
  67073. + if (!r_tmp->subj_hash)
  67074. + return -ENOMEM;
  67075. +
  67076. + err = copy_user_allowedips(r_tmp);
  67077. + if (err)
  67078. + return err;
  67079. +
  67080. + /* copy domain info */
  67081. + if (r_tmp->domain_children != NULL) {
  67082. + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
  67083. + if (domainlist == NULL)
  67084. + return -ENOMEM;
  67085. +
  67086. + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
  67087. + return -EFAULT;
  67088. +
  67089. + r_tmp->domain_children = domainlist;
  67090. + }
  67091. +
  67092. + err = copy_user_transitions(r_tmp);
  67093. + if (err)
  67094. + return err;
  67095. +
  67096. + memset(r_tmp->subj_hash, 0,
  67097. + r_tmp->subj_hash_size *
  67098. + sizeof (struct acl_subject_label *));
  67099. +
  67100. + /* acquire the list of subjects, then NULL out
  67101. + the list prior to parsing the subjects for this role,
  67102. + as during this parsing the list is replaced with a list
  67103. + of *nested* subjects for the role
  67104. + */
  67105. + subj_list = r_tmp->hash->first;
  67106. +
  67107. + /* set nested subject list to null */
  67108. + r_tmp->hash->first = NULL;
  67109. +
  67110. + err = copy_user_subjs(subj_list, r_tmp);
  67111. +
  67112. + if (err)
  67113. + return err;
  67114. +
  67115. + insert_acl_role_label(r_tmp);
  67116. + }
  67117. +
  67118. + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
  67119. + return -EINVAL;
  67120. +
  67121. + return err;
  67122. +}
  67123. +
  67124. +static int gracl_reload_apply_policies(void *reload)
  67125. +{
  67126. + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
  67127. + struct task_struct *task, *task2;
  67128. + struct acl_role_label *role, *rtmp;
  67129. + struct acl_subject_label *subj;
  67130. + const struct cred *cred;
  67131. + int role_applied;
  67132. + int ret = 0;
  67133. +
  67134. + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
  67135. + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
  67136. +
  67137. + /* first make sure we'll be able to apply the new policy cleanly */
  67138. + do_each_thread(task2, task) {
  67139. + if (task->exec_file == NULL)
  67140. + continue;
  67141. + role_applied = 0;
  67142. + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
  67143. + /* preserve special roles */
  67144. + FOR_EACH_ROLE_START(role)
  67145. + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
  67146. + rtmp = task->role;
  67147. + task->role = role;
  67148. + role_applied = 1;
  67149. + break;
  67150. + }
  67151. + FOR_EACH_ROLE_END(role)
  67152. + }
  67153. + if (!role_applied) {
  67154. + cred = __task_cred(task);
  67155. + rtmp = task->role;
  67156. + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
  67157. + }
  67158. + /* this handles non-nested inherited subjects, nested subjects will still
  67159. + be dropped currently */
  67160. + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
  67161. + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
  67162. + /* change the role back so that we've made no modifications to the policy */
  67163. + task->role = rtmp;
  67164. +
  67165. + if (subj == NULL || task->tmpacl == NULL) {
  67166. + ret = -EINVAL;
  67167. + goto out;
  67168. + }
  67169. + } while_each_thread(task2, task);
  67170. +
  67171. + /* now actually apply the policy */
  67172. +
  67173. + do_each_thread(task2, task) {
  67174. + if (task->exec_file) {
  67175. + role_applied = 0;
  67176. + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
  67177. + /* preserve special roles */
  67178. + FOR_EACH_ROLE_START(role)
  67179. + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
  67180. + task->role = role;
  67181. + role_applied = 1;
  67182. + break;
  67183. + }
  67184. + FOR_EACH_ROLE_END(role)
  67185. + }
  67186. + if (!role_applied) {
  67187. + cred = __task_cred(task);
  67188. + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
  67189. + }
  67190. + /* this handles non-nested inherited subjects, nested subjects will still
  67191. + be dropped currently */
  67192. + if (!reload_state->oldmode && task->inherited)
  67193. + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
  67194. + else {
  67195. + /* looked up and tagged to the task previously */
  67196. + subj = task->tmpacl;
  67197. + }
  67198. + /* subj will be non-null */
  67199. + __gr_apply_subject_to_task(polstate, task, subj);
  67200. + if (reload_state->oldmode) {
  67201. + task->acl_role_id = 0;
  67202. + task->acl_sp_role = 0;
  67203. + task->inherited = 0;
  67204. + }
  67205. + } else {
  67206. + // it's a kernel process
  67207. + task->role = polstate->kernel_role;
  67208. + task->acl = polstate->kernel_role->root_label;
  67209. +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
  67210. + task->acl->mode &= ~GR_PROCFIND;
  67211. +#endif
  67212. + }
  67213. + } while_each_thread(task2, task);
  67214. +
  67215. + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
  67216. + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
  67217. +
  67218. +out:
  67219. +
  67220. + return ret;
  67221. +}
  67222. +
  67223. +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
  67224. +{
  67225. + struct gr_reload_state new_reload_state = { };
  67226. + int err;
  67227. +
  67228. + new_reload_state.oldpolicy_ptr = polstate;
  67229. + new_reload_state.oldalloc_ptr = current_alloc_state;
  67230. + new_reload_state.oldmode = oldmode;
  67231. +
  67232. + current_alloc_state = &new_reload_state.newalloc;
  67233. + polstate = &new_reload_state.newpolicy;
  67234. +
  67235. + /* everything relevant is now saved off, copy in the new policy */
  67236. + if (init_variables(args, true)) {
  67237. + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
  67238. + err = -ENOMEM;
  67239. + goto error;
  67240. + }
  67241. +
  67242. + err = copy_user_acl(args);
  67243. + free_init_variables();
  67244. + if (err)
  67245. + goto error;
  67246. + /* the new policy is copied in, with the old policy available via saved_state
  67247. + first go through applying roles, making sure to preserve special roles
  67248. + then apply new subjects, making sure to preserve inherited and nested subjects,
  67249. + though currently only inherited subjects will be preserved
  67250. + */
  67251. + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
  67252. + if (err)
  67253. + goto error;
  67254. +
  67255. + /* we've now applied the new policy, so restore the old policy state to free it */
  67256. + polstate = &new_reload_state.oldpolicy;
  67257. + current_alloc_state = &new_reload_state.oldalloc;
  67258. + free_variables(true);
  67259. +
  67260. + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
  67261. + to running_polstate/current_alloc_state inside stop_machine
  67262. + */
  67263. + err = 0;
  67264. + goto out;
  67265. +error:
  67266. + /* on error of loading the new policy, we'll just keep the previous
  67267. + policy set around
  67268. + */
  67269. + free_variables(true);
  67270. +
  67271. + /* doesn't affect runtime, but maintains consistent state */
  67272. +out:
  67273. + polstate = new_reload_state.oldpolicy_ptr;
  67274. + current_alloc_state = new_reload_state.oldalloc_ptr;
  67275. +
  67276. + return err;
  67277. +}
  67278. +
  67279. +static int
  67280. +gracl_init(struct gr_arg *args)
  67281. +{
  67282. + int error = 0;
  67283. +
  67284. + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
  67285. + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
  67286. +
  67287. + if (init_variables(args, false)) {
  67288. + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
  67289. + error = -ENOMEM;
  67290. + goto out;
  67291. + }
  67292. +
  67293. + error = copy_user_acl(args);
  67294. + free_init_variables();
  67295. + if (error)
  67296. + goto out;
  67297. +
  67298. + error = gr_set_acls(0);
  67299. + if (error)
  67300. + goto out;
  67301. +
  67302. + gr_enable_rbac_system();
  67303. +
  67304. + return 0;
  67305. +
  67306. +out:
  67307. + free_variables(false);
  67308. + return error;
  67309. +}
  67310. +
  67311. +static int
  67312. +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
  67313. + unsigned char **sum)
  67314. +{
  67315. + struct acl_role_label *r;
  67316. + struct role_allowed_ip *ipp;
  67317. + struct role_transition *trans;
  67318. + unsigned int i;
  67319. + int found = 0;
  67320. + u32 curr_ip = current->signal->curr_ip;
  67321. +
  67322. + current->signal->saved_ip = curr_ip;
  67323. +
  67324. + /* check transition table */
  67325. +
  67326. + for (trans = current->role->transitions; trans; trans = trans->next) {
  67327. + if (!strcmp(rolename, trans->rolename)) {
  67328. + found = 1;
  67329. + break;
  67330. + }
  67331. + }
  67332. +
  67333. + if (!found)
  67334. + return 0;
  67335. +
  67336. + /* handle special roles that do not require authentication
  67337. + and check ip */
  67338. +
  67339. + FOR_EACH_ROLE_START(r)
  67340. + if (!strcmp(rolename, r->rolename) &&
  67341. + (r->roletype & GR_ROLE_SPECIAL)) {
  67342. + found = 0;
  67343. + if (r->allowed_ips != NULL) {
  67344. + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
  67345. + if ((ntohl(curr_ip) & ipp->netmask) ==
  67346. + (ntohl(ipp->addr) & ipp->netmask))
  67347. + found = 1;
  67348. + }
  67349. + } else
  67350. + found = 2;
  67351. + if (!found)
  67352. + return 0;
  67353. +
  67354. + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
  67355. + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
  67356. + *salt = NULL;
  67357. + *sum = NULL;
  67358. + return 1;
  67359. + }
  67360. + }
  67361. + FOR_EACH_ROLE_END(r)
  67362. +
  67363. + for (i = 0; i < polstate->num_sprole_pws; i++) {
  67364. + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
  67365. + *salt = polstate->acl_special_roles[i]->salt;
  67366. + *sum = polstate->acl_special_roles[i]->sum;
  67367. + return 1;
  67368. + }
  67369. + }
  67370. +
  67371. + return 0;
  67372. +}
  67373. +
  67374. +int gr_check_secure_terminal(struct task_struct *task)
  67375. +{
  67376. + struct task_struct *p, *p2, *p3;
  67377. + struct files_struct *files;
  67378. + struct fdtable *fdt;
  67379. + struct file *our_file = NULL, *file;
  67380. + int i;
  67381. +
  67382. + if (task->signal->tty == NULL)
  67383. + return 1;
  67384. +
  67385. + files = get_files_struct(task);
  67386. + if (files != NULL) {
  67387. + rcu_read_lock();
  67388. + fdt = files_fdtable(files);
  67389. + for (i=0; i < fdt->max_fds; i++) {
  67390. + file = fcheck_files(files, i);
  67391. + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
  67392. + get_file(file);
  67393. + our_file = file;
  67394. + }
  67395. + }
  67396. + rcu_read_unlock();
  67397. + put_files_struct(files);
  67398. + }
  67399. +
  67400. + if (our_file == NULL)
  67401. + return 1;
  67402. +
  67403. + read_lock(&tasklist_lock);
  67404. + do_each_thread(p2, p) {
  67405. + files = get_files_struct(p);
  67406. + if (files == NULL ||
  67407. + (p->signal && p->signal->tty == task->signal->tty)) {
  67408. + if (files != NULL)
  67409. + put_files_struct(files);
  67410. + continue;
  67411. + }
  67412. + rcu_read_lock();
  67413. + fdt = files_fdtable(files);
  67414. + for (i=0; i < fdt->max_fds; i++) {
  67415. + file = fcheck_files(files, i);
  67416. + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
  67417. + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
  67418. + p3 = task;
  67419. + while (task_pid_nr(p3) > 0) {
  67420. + if (p3 == p)
  67421. + break;
  67422. + p3 = p3->real_parent;
  67423. + }
  67424. + if (p3 == p)
  67425. + break;
  67426. + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
  67427. + gr_handle_alertkill(p);
  67428. + rcu_read_unlock();
  67429. + put_files_struct(files);
  67430. + read_unlock(&tasklist_lock);
  67431. + fput(our_file);
  67432. + return 0;
  67433. + }
  67434. + }
  67435. + rcu_read_unlock();
  67436. + put_files_struct(files);
  67437. + } while_each_thread(p2, p);
  67438. + read_unlock(&tasklist_lock);
  67439. +
  67440. + fput(our_file);
  67441. + return 1;
  67442. +}
  67443. +
  67444. +ssize_t
  67445. +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
  67446. +{
  67447. + struct gr_arg_wrapper uwrap;
  67448. + unsigned char *sprole_salt = NULL;
  67449. + unsigned char *sprole_sum = NULL;
  67450. + int error = 0;
  67451. + int error2 = 0;
  67452. + size_t req_count = 0;
  67453. + unsigned char oldmode = 0;
  67454. +
  67455. + mutex_lock(&gr_dev_mutex);
  67456. +
  67457. + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
  67458. + error = -EPERM;
  67459. + goto out;
  67460. + }
  67461. +
  67462. +#ifdef CONFIG_COMPAT
  67463. + pax_open_kernel();
  67464. + if (is_compat_task()) {
  67465. + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
  67466. + copy_gr_arg = &copy_gr_arg_compat;
  67467. + copy_acl_object_label = &copy_acl_object_label_compat;
  67468. + copy_acl_subject_label = &copy_acl_subject_label_compat;
  67469. + copy_acl_role_label = &copy_acl_role_label_compat;
  67470. + copy_acl_ip_label = &copy_acl_ip_label_compat;
  67471. + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
  67472. + copy_role_transition = &copy_role_transition_compat;
  67473. + copy_sprole_pw = &copy_sprole_pw_compat;
  67474. + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
  67475. + copy_pointer_from_array = &copy_pointer_from_array_compat;
  67476. + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
  67477. + } else {
  67478. + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
  67479. + copy_gr_arg = &copy_gr_arg_normal;
  67480. + copy_acl_object_label = &copy_acl_object_label_normal;
  67481. + copy_acl_subject_label = &copy_acl_subject_label_normal;
  67482. + copy_acl_role_label = &copy_acl_role_label_normal;
  67483. + copy_acl_ip_label = &copy_acl_ip_label_normal;
  67484. + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
  67485. + copy_role_transition = &copy_role_transition_normal;
  67486. + copy_sprole_pw = &copy_sprole_pw_normal;
  67487. + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
  67488. + copy_pointer_from_array = &copy_pointer_from_array_normal;
  67489. + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
  67490. + }
  67491. + pax_close_kernel();
  67492. +#endif
  67493. +
  67494. + req_count = get_gr_arg_wrapper_size();
  67495. +
  67496. + if (count != req_count) {
  67497. + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
  67498. + error = -EINVAL;
  67499. + goto out;
  67500. + }
  67501. +
  67502. +
  67503. + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
  67504. + gr_auth_expires = 0;
  67505. + gr_auth_attempts = 0;
  67506. + }
  67507. +
  67508. + error = copy_gr_arg_wrapper(buf, &uwrap);
  67509. + if (error)
  67510. + goto out;
  67511. +
  67512. + error = copy_gr_arg(uwrap.arg, &gr_usermode);
  67513. + if (error)
  67514. + goto out;
  67515. +
  67516. + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
  67517. + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
  67518. + time_after(gr_auth_expires, get_seconds())) {
  67519. + error = -EBUSY;
  67520. + goto out;
  67521. + }
  67522. +
  67523. + /* if non-root trying to do anything other than use a special role,
  67524. + do not attempt authentication, do not count towards authentication
  67525. + locking
  67526. + */
  67527. +
  67528. + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
  67529. + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
  67530. + gr_is_global_nonroot(current_uid())) {
  67531. + error = -EPERM;
  67532. + goto out;
  67533. + }
  67534. +
  67535. + /* ensure pw and special role name are null terminated */
  67536. +
  67537. + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
  67538. + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
  67539. +
  67540. + /* Okay.
  67541. + * We have our enough of the argument structure..(we have yet
  67542. + * to copy_from_user the tables themselves) . Copy the tables
  67543. + * only if we need them, i.e. for loading operations. */
  67544. +
  67545. + switch (gr_usermode.mode) {
  67546. + case GR_STATUS:
  67547. + if (gr_acl_is_enabled()) {
  67548. + error = 1;
  67549. + if (!gr_check_secure_terminal(current))
  67550. + error = 3;
  67551. + } else
  67552. + error = 2;
  67553. + goto out;
  67554. + case GR_SHUTDOWN:
  67555. + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
  67556. + stop_machine(gr_rbac_disable, NULL, NULL);
  67557. + free_variables(false);
  67558. + memset(&gr_usermode, 0, sizeof(gr_usermode));
  67559. + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
  67560. + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
  67561. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
  67562. + } else if (gr_acl_is_enabled()) {
  67563. + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
  67564. + error = -EPERM;
  67565. + } else {
  67566. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
  67567. + error = -EAGAIN;
  67568. + }
  67569. + break;
  67570. + case GR_ENABLE:
  67571. + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
  67572. + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
  67573. + else {
  67574. + if (gr_acl_is_enabled())
  67575. + error = -EAGAIN;
  67576. + else
  67577. + error = error2;
  67578. + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
  67579. + }
  67580. + break;
  67581. + case GR_OLDRELOAD:
  67582. + oldmode = 1;
  67583. + case GR_RELOAD:
  67584. + if (!gr_acl_is_enabled()) {
  67585. + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
  67586. + error = -EAGAIN;
  67587. + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
  67588. + error2 = gracl_reload(&gr_usermode, oldmode);
  67589. + if (!error2)
  67590. + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
  67591. + else {
  67592. + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
  67593. + error = error2;
  67594. + }
  67595. + } else {
  67596. + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
  67597. + error = -EPERM;
  67598. + }
  67599. + break;
  67600. + case GR_SEGVMOD:
  67601. + if (unlikely(!gr_acl_is_enabled())) {
  67602. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
  67603. + error = -EAGAIN;
  67604. + break;
  67605. + }
  67606. +
  67607. + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
  67608. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
  67609. + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
  67610. + struct acl_subject_label *segvacl;
  67611. + segvacl =
  67612. + lookup_acl_subj_label(gr_usermode.segv_inode,
  67613. + gr_usermode.segv_device,
  67614. + current->role);
  67615. + if (segvacl) {
  67616. + segvacl->crashes = 0;
  67617. + segvacl->expires = 0;
  67618. + }
  67619. + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
  67620. + gr_remove_uid(gr_usermode.segv_uid);
  67621. + }
  67622. + } else {
  67623. + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
  67624. + error = -EPERM;
  67625. + }
  67626. + break;
  67627. + case GR_SPROLE:
  67628. + case GR_SPROLEPAM:
  67629. + if (unlikely(!gr_acl_is_enabled())) {
  67630. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
  67631. + error = -EAGAIN;
  67632. + break;
  67633. + }
  67634. +
  67635. + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
  67636. + current->role->expires = 0;
  67637. + current->role->auth_attempts = 0;
  67638. + }
  67639. +
  67640. + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
  67641. + time_after(current->role->expires, get_seconds())) {
  67642. + error = -EBUSY;
  67643. + goto out;
  67644. + }
  67645. +
  67646. + if (lookup_special_role_auth
  67647. + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
  67648. + && ((!sprole_salt && !sprole_sum)
  67649. + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
  67650. + char *p = "";
  67651. + assign_special_role(gr_usermode.sp_role);
  67652. + read_lock(&tasklist_lock);
  67653. + if (current->real_parent)
  67654. + p = current->real_parent->role->rolename;
  67655. + read_unlock(&tasklist_lock);
  67656. + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
  67657. + p, acl_sp_role_value);
  67658. + } else {
  67659. + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
  67660. + error = -EPERM;
  67661. + if(!(current->role->auth_attempts++))
  67662. + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
  67663. +
  67664. + goto out;
  67665. + }
  67666. + break;
  67667. + case GR_UNSPROLE:
  67668. + if (unlikely(!gr_acl_is_enabled())) {
  67669. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
  67670. + error = -EAGAIN;
  67671. + break;
  67672. + }
  67673. +
  67674. + if (current->role->roletype & GR_ROLE_SPECIAL) {
  67675. + char *p = "";
  67676. + int i = 0;
  67677. +
  67678. + read_lock(&tasklist_lock);
  67679. + if (current->real_parent) {
  67680. + p = current->real_parent->role->rolename;
  67681. + i = current->real_parent->acl_role_id;
  67682. + }
  67683. + read_unlock(&tasklist_lock);
  67684. +
  67685. + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
  67686. + gr_set_acls(1);
  67687. + } else {
  67688. + error = -EPERM;
  67689. + goto out;
  67690. + }
  67691. + break;
  67692. + default:
  67693. + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
  67694. + error = -EINVAL;
  67695. + break;
  67696. + }
  67697. +
  67698. + if (error != -EPERM)
  67699. + goto out;
  67700. +
  67701. + if(!(gr_auth_attempts++))
  67702. + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
  67703. +
  67704. + out:
  67705. + mutex_unlock(&gr_dev_mutex);
  67706. +
  67707. + if (!error)
  67708. + error = req_count;
  67709. +
  67710. + return error;
  67711. +}
  67712. +
  67713. +int
  67714. +gr_set_acls(const int type)
  67715. +{
  67716. + struct task_struct *task, *task2;
  67717. + struct acl_role_label *role = current->role;
  67718. + struct acl_subject_label *subj;
  67719. + __u16 acl_role_id = current->acl_role_id;
  67720. + const struct cred *cred;
  67721. + int ret;
  67722. +
  67723. + rcu_read_lock();
  67724. + read_lock(&tasklist_lock);
  67725. + read_lock(&grsec_exec_file_lock);
  67726. + do_each_thread(task2, task) {
  67727. + /* check to see if we're called from the exit handler,
  67728. + if so, only replace ACLs that have inherited the admin
  67729. + ACL */
  67730. +
  67731. + if (type && (task->role != role ||
  67732. + task->acl_role_id != acl_role_id))
  67733. + continue;
  67734. +
  67735. + task->acl_role_id = 0;
  67736. + task->acl_sp_role = 0;
  67737. + task->inherited = 0;
  67738. +
  67739. + if (task->exec_file) {
  67740. + cred = __task_cred(task);
  67741. + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
  67742. + subj = __gr_get_subject_for_task(polstate, task, NULL);
  67743. + if (subj == NULL) {
  67744. + ret = -EINVAL;
  67745. + read_unlock(&grsec_exec_file_lock);
  67746. + read_unlock(&tasklist_lock);
  67747. + rcu_read_unlock();
  67748. + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
  67749. + return ret;
  67750. + }
  67751. + __gr_apply_subject_to_task(polstate, task, subj);
  67752. + } else {
  67753. + // it's a kernel process
  67754. + task->role = polstate->kernel_role;
  67755. + task->acl = polstate->kernel_role->root_label;
  67756. +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
  67757. + task->acl->mode &= ~GR_PROCFIND;
  67758. +#endif
  67759. + }
  67760. + } while_each_thread(task2, task);
  67761. + read_unlock(&grsec_exec_file_lock);
  67762. + read_unlock(&tasklist_lock);
  67763. + rcu_read_unlock();
  67764. +
  67765. + return 0;
  67766. +}
  67767. diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
  67768. new file mode 100644
  67769. index 0000000..39645c9
  67770. --- /dev/null
  67771. +++ b/grsecurity/gracl_res.c
  67772. @@ -0,0 +1,68 @@
  67773. +#include <linux/kernel.h>
  67774. +#include <linux/sched.h>
  67775. +#include <linux/gracl.h>
  67776. +#include <linux/grinternal.h>
  67777. +
  67778. +static const char *restab_log[] = {
  67779. + [RLIMIT_CPU] = "RLIMIT_CPU",
  67780. + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
  67781. + [RLIMIT_DATA] = "RLIMIT_DATA",
  67782. + [RLIMIT_STACK] = "RLIMIT_STACK",
  67783. + [RLIMIT_CORE] = "RLIMIT_CORE",
  67784. + [RLIMIT_RSS] = "RLIMIT_RSS",
  67785. + [RLIMIT_NPROC] = "RLIMIT_NPROC",
  67786. + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
  67787. + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
  67788. + [RLIMIT_AS] = "RLIMIT_AS",
  67789. + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
  67790. + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
  67791. + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
  67792. + [RLIMIT_NICE] = "RLIMIT_NICE",
  67793. + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
  67794. + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
  67795. + [GR_CRASH_RES] = "RLIMIT_CRASH"
  67796. +};
  67797. +
  67798. +void
  67799. +gr_log_resource(const struct task_struct *task,
  67800. + const int res, const unsigned long wanted, const int gt)
  67801. +{
  67802. + const struct cred *cred;
  67803. + unsigned long rlim;
  67804. +
  67805. + if (!gr_acl_is_enabled() && !grsec_resource_logging)
  67806. + return;
  67807. +
  67808. + // not yet supported resource
  67809. + if (unlikely(!restab_log[res]))
  67810. + return;
  67811. +
  67812. + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
  67813. + rlim = task_rlimit_max(task, res);
  67814. + else
  67815. + rlim = task_rlimit(task, res);
  67816. +
  67817. + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
  67818. + return;
  67819. +
  67820. + rcu_read_lock();
  67821. + cred = __task_cred(task);
  67822. +
  67823. + if (res == RLIMIT_NPROC &&
  67824. + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
  67825. + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
  67826. + goto out_rcu_unlock;
  67827. + else if (res == RLIMIT_MEMLOCK &&
  67828. + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
  67829. + goto out_rcu_unlock;
  67830. + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
  67831. + goto out_rcu_unlock;
  67832. + rcu_read_unlock();
  67833. +
  67834. + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
  67835. +
  67836. + return;
  67837. +out_rcu_unlock:
  67838. + rcu_read_unlock();
  67839. + return;
  67840. +}
  67841. diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
  67842. new file mode 100644
  67843. index 0000000..2040e61
  67844. --- /dev/null
  67845. +++ b/grsecurity/gracl_segv.c
  67846. @@ -0,0 +1,313 @@
  67847. +#include <linux/kernel.h>
  67848. +#include <linux/mm.h>
  67849. +#include <asm/uaccess.h>
  67850. +#include <asm/errno.h>
  67851. +#include <asm/mman.h>
  67852. +#include <net/sock.h>
  67853. +#include <linux/file.h>
  67854. +#include <linux/fs.h>
  67855. +#include <linux/net.h>
  67856. +#include <linux/in.h>
  67857. +#include <linux/slab.h>
  67858. +#include <linux/types.h>
  67859. +#include <linux/sched.h>
  67860. +#include <linux/timer.h>
  67861. +#include <linux/gracl.h>
  67862. +#include <linux/grsecurity.h>
  67863. +#include <linux/grinternal.h>
  67864. +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
  67865. +#include <linux/magic.h>
  67866. +#include <linux/pagemap.h>
  67867. +#include "../fs/btrfs/async-thread.h"
  67868. +#include "../fs/btrfs/ctree.h"
  67869. +#include "../fs/btrfs/btrfs_inode.h"
  67870. +#endif
  67871. +
  67872. +static struct crash_uid *uid_set;
  67873. +static unsigned short uid_used;
  67874. +static DEFINE_SPINLOCK(gr_uid_lock);
  67875. +extern rwlock_t gr_inode_lock;
  67876. +extern struct acl_subject_label *
  67877. + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
  67878. + struct acl_role_label *role);
  67879. +
  67880. +static inline dev_t __get_dev(const struct dentry *dentry)
  67881. +{
  67882. +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
  67883. + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
  67884. + return BTRFS_I(dentry->d_inode)->root->anon_dev;
  67885. + else
  67886. +#endif
  67887. + return dentry->d_sb->s_dev;
  67888. +}
  67889. +
  67890. +int
  67891. +gr_init_uidset(void)
  67892. +{
  67893. + uid_set =
  67894. + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
  67895. + uid_used = 0;
  67896. +
  67897. + return uid_set ? 1 : 0;
  67898. +}
  67899. +
  67900. +void
  67901. +gr_free_uidset(void)
  67902. +{
  67903. + if (uid_set) {
  67904. + struct crash_uid *tmpset;
  67905. + spin_lock(&gr_uid_lock);
  67906. + tmpset = uid_set;
  67907. + uid_set = NULL;
  67908. + uid_used = 0;
  67909. + spin_unlock(&gr_uid_lock);
  67910. + if (tmpset)
  67911. + kfree(tmpset);
  67912. + }
  67913. +
  67914. + return;
  67915. +}
  67916. +
  67917. +int
  67918. +gr_find_uid(const uid_t uid)
  67919. +{
  67920. + struct crash_uid *tmp = uid_set;
  67921. + uid_t buid;
  67922. + int low = 0, high = uid_used - 1, mid;
  67923. +
  67924. + while (high >= low) {
  67925. + mid = (low + high) >> 1;
  67926. + buid = tmp[mid].uid;
  67927. + if (buid == uid)
  67928. + return mid;
  67929. + if (buid > uid)
  67930. + high = mid - 1;
  67931. + if (buid < uid)
  67932. + low = mid + 1;
  67933. + }
  67934. +
  67935. + return -1;
  67936. +}
  67937. +
  67938. +static __inline__ void
  67939. +gr_insertsort(void)
  67940. +{
  67941. + unsigned short i, j;
  67942. + struct crash_uid index;
  67943. +
  67944. + for (i = 1; i < uid_used; i++) {
  67945. + index = uid_set[i];
  67946. + j = i;
  67947. + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
  67948. + uid_set[j] = uid_set[j - 1];
  67949. + j--;
  67950. + }
  67951. + uid_set[j] = index;
  67952. + }
  67953. +
  67954. + return;
  67955. +}
  67956. +
  67957. +static __inline__ void
  67958. +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
  67959. +{
  67960. + int loc;
  67961. + uid_t uid = GR_GLOBAL_UID(kuid);
  67962. +
  67963. + if (uid_used == GR_UIDTABLE_MAX)
  67964. + return;
  67965. +
  67966. + loc = gr_find_uid(uid);
  67967. +
  67968. + if (loc >= 0) {
  67969. + uid_set[loc].expires = expires;
  67970. + return;
  67971. + }
  67972. +
  67973. + uid_set[uid_used].uid = uid;
  67974. + uid_set[uid_used].expires = expires;
  67975. + uid_used++;
  67976. +
  67977. + gr_insertsort();
  67978. +
  67979. + return;
  67980. +}
  67981. +
  67982. +void
  67983. +gr_remove_uid(const unsigned short loc)
  67984. +{
  67985. + unsigned short i;
  67986. +
  67987. + for (i = loc + 1; i < uid_used; i++)
  67988. + uid_set[i - 1] = uid_set[i];
  67989. +
  67990. + uid_used--;
  67991. +
  67992. + return;
  67993. +}
  67994. +
  67995. +int
  67996. +gr_check_crash_uid(const kuid_t kuid)
  67997. +{
  67998. + int loc;
  67999. + int ret = 0;
  68000. + uid_t uid;
  68001. +
  68002. + if (unlikely(!gr_acl_is_enabled()))
  68003. + return 0;
  68004. +
  68005. + uid = GR_GLOBAL_UID(kuid);
  68006. +
  68007. + spin_lock(&gr_uid_lock);
  68008. + loc = gr_find_uid(uid);
  68009. +
  68010. + if (loc < 0)
  68011. + goto out_unlock;
  68012. +
  68013. + if (time_before_eq(uid_set[loc].expires, get_seconds()))
  68014. + gr_remove_uid(loc);
  68015. + else
  68016. + ret = 1;
  68017. +
  68018. +out_unlock:
  68019. + spin_unlock(&gr_uid_lock);
  68020. + return ret;
  68021. +}
  68022. +
  68023. +static __inline__ int
  68024. +proc_is_setxid(const struct cred *cred)
  68025. +{
  68026. + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
  68027. + !uid_eq(cred->uid, cred->fsuid))
  68028. + return 1;
  68029. + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
  68030. + !gid_eq(cred->gid, cred->fsgid))
  68031. + return 1;
  68032. +
  68033. + return 0;
  68034. +}
  68035. +
  68036. +extern int gr_fake_force_sig(int sig, struct task_struct *t);
  68037. +
  68038. +void
  68039. +gr_handle_crash(struct task_struct *task, const int sig)
  68040. +{
  68041. + struct acl_subject_label *curr;
  68042. + struct task_struct *tsk, *tsk2;
  68043. + const struct cred *cred;
  68044. + const struct cred *cred2;
  68045. +
  68046. + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
  68047. + return;
  68048. +
  68049. + if (unlikely(!gr_acl_is_enabled()))
  68050. + return;
  68051. +
  68052. + curr = task->acl;
  68053. +
  68054. + if (!(curr->resmask & (1U << GR_CRASH_RES)))
  68055. + return;
  68056. +
  68057. + if (time_before_eq(curr->expires, get_seconds())) {
  68058. + curr->expires = 0;
  68059. + curr->crashes = 0;
  68060. + }
  68061. +
  68062. + curr->crashes++;
  68063. +
  68064. + if (!curr->expires)
  68065. + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
  68066. +
  68067. + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
  68068. + time_after(curr->expires, get_seconds())) {
  68069. + rcu_read_lock();
  68070. + cred = __task_cred(task);
  68071. + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
  68072. + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
  68073. + spin_lock(&gr_uid_lock);
  68074. + gr_insert_uid(cred->uid, curr->expires);
  68075. + spin_unlock(&gr_uid_lock);
  68076. + curr->expires = 0;
  68077. + curr->crashes = 0;
  68078. + read_lock(&tasklist_lock);
  68079. + do_each_thread(tsk2, tsk) {
  68080. + cred2 = __task_cred(tsk);
  68081. + if (tsk != task && uid_eq(cred2->uid, cred->uid))
  68082. + gr_fake_force_sig(SIGKILL, tsk);
  68083. + } while_each_thread(tsk2, tsk);
  68084. + read_unlock(&tasklist_lock);
  68085. + } else {
  68086. + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
  68087. + read_lock(&tasklist_lock);
  68088. + read_lock(&grsec_exec_file_lock);
  68089. + do_each_thread(tsk2, tsk) {
  68090. + if (likely(tsk != task)) {
  68091. + // if this thread has the same subject as the one that triggered
  68092. + // RES_CRASH and it's the same binary, kill it
  68093. + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
  68094. + gr_fake_force_sig(SIGKILL, tsk);
  68095. + }
  68096. + } while_each_thread(tsk2, tsk);
  68097. + read_unlock(&grsec_exec_file_lock);
  68098. + read_unlock(&tasklist_lock);
  68099. + }
  68100. + rcu_read_unlock();
  68101. + }
  68102. +
  68103. + return;
  68104. +}
  68105. +
  68106. +int
  68107. +gr_check_crash_exec(const struct file *filp)
  68108. +{
  68109. + struct acl_subject_label *curr;
  68110. +
  68111. + if (unlikely(!gr_acl_is_enabled()))
  68112. + return 0;
  68113. +
  68114. + read_lock(&gr_inode_lock);
  68115. + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
  68116. + __get_dev(filp->f_path.dentry),
  68117. + current->role);
  68118. + read_unlock(&gr_inode_lock);
  68119. +
  68120. + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
  68121. + (!curr->crashes && !curr->expires))
  68122. + return 0;
  68123. +
  68124. + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
  68125. + time_after(curr->expires, get_seconds()))
  68126. + return 1;
  68127. + else if (time_before_eq(curr->expires, get_seconds())) {
  68128. + curr->crashes = 0;
  68129. + curr->expires = 0;
  68130. + }
  68131. +
  68132. + return 0;
  68133. +}
  68134. +
  68135. +void
  68136. +gr_handle_alertkill(struct task_struct *task)
  68137. +{
  68138. + struct acl_subject_label *curracl;
  68139. + __u32 curr_ip;
  68140. + struct task_struct *p, *p2;
  68141. +
  68142. + if (unlikely(!gr_acl_is_enabled()))
  68143. + return;
  68144. +
  68145. + curracl = task->acl;
  68146. + curr_ip = task->signal->curr_ip;
  68147. +
  68148. + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
  68149. + read_lock(&tasklist_lock);
  68150. + do_each_thread(p2, p) {
  68151. + if (p->signal->curr_ip == curr_ip)
  68152. + gr_fake_force_sig(SIGKILL, p);
  68153. + } while_each_thread(p2, p);
  68154. + read_unlock(&tasklist_lock);
  68155. + } else if (curracl->mode & GR_KILLPROC)
  68156. + gr_fake_force_sig(SIGKILL, task);
  68157. +
  68158. + return;
  68159. +}
  68160. diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
  68161. new file mode 100644
  68162. index 0000000..98011b0
  68163. --- /dev/null
  68164. +++ b/grsecurity/gracl_shm.c
  68165. @@ -0,0 +1,40 @@
  68166. +#include <linux/kernel.h>
  68167. +#include <linux/mm.h>
  68168. +#include <linux/sched.h>
  68169. +#include <linux/file.h>
  68170. +#include <linux/ipc.h>
  68171. +#include <linux/gracl.h>
  68172. +#include <linux/grsecurity.h>
  68173. +#include <linux/grinternal.h>
  68174. +
  68175. +int
  68176. +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
  68177. + const time_t shm_createtime, const kuid_t cuid, const int shmid)
  68178. +{
  68179. + struct task_struct *task;
  68180. +
  68181. + if (!gr_acl_is_enabled())
  68182. + return 1;
  68183. +
  68184. + rcu_read_lock();
  68185. + read_lock(&tasklist_lock);
  68186. +
  68187. + task = find_task_by_vpid(shm_cprid);
  68188. +
  68189. + if (unlikely(!task))
  68190. + task = find_task_by_vpid(shm_lapid);
  68191. +
  68192. + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
  68193. + (task_pid_nr(task) == shm_lapid)) &&
  68194. + (task->acl->mode & GR_PROTSHM) &&
  68195. + (task->acl != current->acl))) {
  68196. + read_unlock(&tasklist_lock);
  68197. + rcu_read_unlock();
  68198. + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
  68199. + return 0;
  68200. + }
  68201. + read_unlock(&tasklist_lock);
  68202. + rcu_read_unlock();
  68203. +
  68204. + return 1;
  68205. +}
  68206. diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
  68207. new file mode 100644
  68208. index 0000000..bc0be01
  68209. --- /dev/null
  68210. +++ b/grsecurity/grsec_chdir.c
  68211. @@ -0,0 +1,19 @@
  68212. +#include <linux/kernel.h>
  68213. +#include <linux/sched.h>
  68214. +#include <linux/fs.h>
  68215. +#include <linux/file.h>
  68216. +#include <linux/grsecurity.h>
  68217. +#include <linux/grinternal.h>
  68218. +
  68219. +void
  68220. +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
  68221. +{
  68222. +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
  68223. + if ((grsec_enable_chdir && grsec_enable_group &&
  68224. + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
  68225. + !grsec_enable_group)) {
  68226. + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
  68227. + }
  68228. +#endif
  68229. + return;
  68230. +}
  68231. diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
  68232. new file mode 100644
  68233. index 0000000..651d6c2
  68234. --- /dev/null
  68235. +++ b/grsecurity/grsec_chroot.c
  68236. @@ -0,0 +1,370 @@
  68237. +#include <linux/kernel.h>
  68238. +#include <linux/module.h>
  68239. +#include <linux/sched.h>
  68240. +#include <linux/file.h>
  68241. +#include <linux/fs.h>
  68242. +#include <linux/mount.h>
  68243. +#include <linux/types.h>
  68244. +#include "../fs/mount.h"
  68245. +#include <linux/grsecurity.h>
  68246. +#include <linux/grinternal.h>
  68247. +
  68248. +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
  68249. +int gr_init_ran;
  68250. +#endif
  68251. +
  68252. +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
  68253. +{
  68254. +#ifdef CONFIG_GRKERNSEC
  68255. + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
  68256. + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
  68257. +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
  68258. + && gr_init_ran
  68259. +#endif
  68260. + )
  68261. + task->gr_is_chrooted = 1;
  68262. + else {
  68263. +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
  68264. + if (task_pid_nr(task) == 1 && !gr_init_ran)
  68265. + gr_init_ran = 1;
  68266. +#endif
  68267. + task->gr_is_chrooted = 0;
  68268. + }
  68269. +
  68270. + task->gr_chroot_dentry = path->dentry;
  68271. +#endif
  68272. + return;
  68273. +}
  68274. +
  68275. +void gr_clear_chroot_entries(struct task_struct *task)
  68276. +{
  68277. +#ifdef CONFIG_GRKERNSEC
  68278. + task->gr_is_chrooted = 0;
  68279. + task->gr_chroot_dentry = NULL;
  68280. +#endif
  68281. + return;
  68282. +}
  68283. +
  68284. +int
  68285. +gr_handle_chroot_unix(const pid_t pid)
  68286. +{
  68287. +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
  68288. + struct task_struct *p;
  68289. +
  68290. + if (unlikely(!grsec_enable_chroot_unix))
  68291. + return 1;
  68292. +
  68293. + if (likely(!proc_is_chrooted(current)))
  68294. + return 1;
  68295. +
  68296. + rcu_read_lock();
  68297. + read_lock(&tasklist_lock);
  68298. + p = find_task_by_vpid_unrestricted(pid);
  68299. + if (unlikely(p && !have_same_root(current, p))) {
  68300. + read_unlock(&tasklist_lock);
  68301. + rcu_read_unlock();
  68302. + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
  68303. + return 0;
  68304. + }
  68305. + read_unlock(&tasklist_lock);
  68306. + rcu_read_unlock();
  68307. +#endif
  68308. + return 1;
  68309. +}
  68310. +
  68311. +int
  68312. +gr_handle_chroot_nice(void)
  68313. +{
  68314. +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
  68315. + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
  68316. + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
  68317. + return -EPERM;
  68318. + }
  68319. +#endif
  68320. + return 0;
  68321. +}
  68322. +
  68323. +int
  68324. +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
  68325. +{
  68326. +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
  68327. + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
  68328. + && proc_is_chrooted(current)) {
  68329. + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
  68330. + return -EACCES;
  68331. + }
  68332. +#endif
  68333. + return 0;
  68334. +}
  68335. +
  68336. +int
  68337. +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
  68338. +{
  68339. +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
  68340. + struct task_struct *p;
  68341. + int ret = 0;
  68342. + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
  68343. + return ret;
  68344. +
  68345. + read_lock(&tasklist_lock);
  68346. + do_each_pid_task(pid, type, p) {
  68347. + if (!have_same_root(current, p)) {
  68348. + ret = 1;
  68349. + goto out;
  68350. + }
  68351. + } while_each_pid_task(pid, type, p);
  68352. +out:
  68353. + read_unlock(&tasklist_lock);
  68354. + return ret;
  68355. +#endif
  68356. + return 0;
  68357. +}
  68358. +
  68359. +int
  68360. +gr_pid_is_chrooted(struct task_struct *p)
  68361. +{
  68362. +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
  68363. + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
  68364. + return 0;
  68365. +
  68366. + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
  68367. + !have_same_root(current, p)) {
  68368. + return 1;
  68369. + }
  68370. +#endif
  68371. + return 0;
  68372. +}
  68373. +
  68374. +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
  68375. +
  68376. +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
  68377. +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
  68378. +{
  68379. + struct path path, currentroot;
  68380. + int ret = 0;
  68381. +
  68382. + path.dentry = (struct dentry *)u_dentry;
  68383. + path.mnt = (struct vfsmount *)u_mnt;
  68384. + get_fs_root(current->fs, &currentroot);
  68385. + if (path_is_under(&path, &currentroot))
  68386. + ret = 1;
  68387. + path_put(&currentroot);
  68388. +
  68389. + return ret;
  68390. +}
  68391. +#endif
  68392. +
  68393. +int
  68394. +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
  68395. +{
  68396. +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
  68397. + if (!grsec_enable_chroot_fchdir)
  68398. + return 1;
  68399. +
  68400. + if (!proc_is_chrooted(current))
  68401. + return 1;
  68402. + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
  68403. + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
  68404. + return 0;
  68405. + }
  68406. +#endif
  68407. + return 1;
  68408. +}
  68409. +
  68410. +int
  68411. +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
  68412. + const time_t shm_createtime)
  68413. +{
  68414. +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
  68415. + struct task_struct *p;
  68416. + time_t starttime;
  68417. +
  68418. + if (unlikely(!grsec_enable_chroot_shmat))
  68419. + return 1;
  68420. +
  68421. + if (likely(!proc_is_chrooted(current)))
  68422. + return 1;
  68423. +
  68424. + rcu_read_lock();
  68425. + read_lock(&tasklist_lock);
  68426. +
  68427. + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
  68428. + starttime = p->start_time.tv_sec;
  68429. + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
  68430. + if (have_same_root(current, p)) {
  68431. + goto allow;
  68432. + } else {
  68433. + read_unlock(&tasklist_lock);
  68434. + rcu_read_unlock();
  68435. + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
  68436. + return 0;
  68437. + }
  68438. + }
  68439. + /* creator exited, pid reuse, fall through to next check */
  68440. + }
  68441. + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
  68442. + if (unlikely(!have_same_root(current, p))) {
  68443. + read_unlock(&tasklist_lock);
  68444. + rcu_read_unlock();
  68445. + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
  68446. + return 0;
  68447. + }
  68448. + }
  68449. +
  68450. +allow:
  68451. + read_unlock(&tasklist_lock);
  68452. + rcu_read_unlock();
  68453. +#endif
  68454. + return 1;
  68455. +}
  68456. +
  68457. +void
  68458. +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
  68459. +{
  68460. +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
  68461. + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
  68462. + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
  68463. +#endif
  68464. + return;
  68465. +}
  68466. +
  68467. +int
  68468. +gr_handle_chroot_mknod(const struct dentry *dentry,
  68469. + const struct vfsmount *mnt, const int mode)
  68470. +{
  68471. +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
  68472. + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
  68473. + proc_is_chrooted(current)) {
  68474. + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
  68475. + return -EPERM;
  68476. + }
  68477. +#endif
  68478. + return 0;
  68479. +}
  68480. +
  68481. +int
  68482. +gr_handle_chroot_mount(const struct dentry *dentry,
  68483. + const struct vfsmount *mnt, const char *dev_name)
  68484. +{
  68485. +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
  68486. + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
  68487. + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
  68488. + return -EPERM;
  68489. + }
  68490. +#endif
  68491. + return 0;
  68492. +}
  68493. +
  68494. +int
  68495. +gr_handle_chroot_pivot(void)
  68496. +{
  68497. +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
  68498. + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
  68499. + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
  68500. + return -EPERM;
  68501. + }
  68502. +#endif
  68503. + return 0;
  68504. +}
  68505. +
  68506. +int
  68507. +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
  68508. +{
  68509. +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
  68510. + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
  68511. + !gr_is_outside_chroot(dentry, mnt)) {
  68512. + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
  68513. + return -EPERM;
  68514. + }
  68515. +#endif
  68516. + return 0;
  68517. +}
  68518. +
  68519. +extern const char *captab_log[];
  68520. +extern int captab_log_entries;
  68521. +
  68522. +int
  68523. +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
  68524. +{
  68525. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  68526. + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
  68527. + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
  68528. + if (cap_raised(chroot_caps, cap)) {
  68529. + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
  68530. + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
  68531. + }
  68532. + return 0;
  68533. + }
  68534. + }
  68535. +#endif
  68536. + return 1;
  68537. +}
  68538. +
  68539. +int
  68540. +gr_chroot_is_capable(const int cap)
  68541. +{
  68542. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  68543. + return gr_task_chroot_is_capable(current, current_cred(), cap);
  68544. +#endif
  68545. + return 1;
  68546. +}
  68547. +
  68548. +int
  68549. +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
  68550. +{
  68551. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  68552. + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
  68553. + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
  68554. + if (cap_raised(chroot_caps, cap)) {
  68555. + return 0;
  68556. + }
  68557. + }
  68558. +#endif
  68559. + return 1;
  68560. +}
  68561. +
  68562. +int
  68563. +gr_chroot_is_capable_nolog(const int cap)
  68564. +{
  68565. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  68566. + return gr_task_chroot_is_capable_nolog(current, cap);
  68567. +#endif
  68568. + return 1;
  68569. +}
  68570. +
  68571. +int
  68572. +gr_handle_chroot_sysctl(const int op)
  68573. +{
  68574. +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
  68575. + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
  68576. + proc_is_chrooted(current))
  68577. + return -EACCES;
  68578. +#endif
  68579. + return 0;
  68580. +}
  68581. +
  68582. +void
  68583. +gr_handle_chroot_chdir(const struct path *path)
  68584. +{
  68585. +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
  68586. + if (grsec_enable_chroot_chdir)
  68587. + set_fs_pwd(current->fs, path);
  68588. +#endif
  68589. + return;
  68590. +}
  68591. +
  68592. +int
  68593. +gr_handle_chroot_chmod(const struct dentry *dentry,
  68594. + const struct vfsmount *mnt, const int mode)
  68595. +{
  68596. +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
  68597. + /* allow chmod +s on directories, but not files */
  68598. + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
  68599. + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
  68600. + proc_is_chrooted(current)) {
  68601. + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
  68602. + return -EPERM;
  68603. + }
  68604. +#endif
  68605. + return 0;
  68606. +}
  68607. diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
  68608. new file mode 100644
  68609. index 0000000..4d6fce8
  68610. --- /dev/null
  68611. +++ b/grsecurity/grsec_disabled.c
  68612. @@ -0,0 +1,433 @@
  68613. +#include <linux/kernel.h>
  68614. +#include <linux/module.h>
  68615. +#include <linux/sched.h>
  68616. +#include <linux/file.h>
  68617. +#include <linux/fs.h>
  68618. +#include <linux/kdev_t.h>
  68619. +#include <linux/net.h>
  68620. +#include <linux/in.h>
  68621. +#include <linux/ip.h>
  68622. +#include <linux/skbuff.h>
  68623. +#include <linux/sysctl.h>
  68624. +
  68625. +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
  68626. +void
  68627. +pax_set_initial_flags(struct linux_binprm *bprm)
  68628. +{
  68629. + return;
  68630. +}
  68631. +#endif
  68632. +
  68633. +#ifdef CONFIG_SYSCTL
  68634. +__u32
  68635. +gr_handle_sysctl(const struct ctl_table * table, const int op)
  68636. +{
  68637. + return 0;
  68638. +}
  68639. +#endif
  68640. +
  68641. +#ifdef CONFIG_TASKSTATS
  68642. +int gr_is_taskstats_denied(int pid)
  68643. +{
  68644. + return 0;
  68645. +}
  68646. +#endif
  68647. +
  68648. +int
  68649. +gr_acl_is_enabled(void)
  68650. +{
  68651. + return 0;
  68652. +}
  68653. +
  68654. +void
  68655. +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
  68656. +{
  68657. + return;
  68658. +}
  68659. +
  68660. +int
  68661. +gr_handle_rawio(const struct inode *inode)
  68662. +{
  68663. + return 0;
  68664. +}
  68665. +
  68666. +void
  68667. +gr_acl_handle_psacct(struct task_struct *task, const long code)
  68668. +{
  68669. + return;
  68670. +}
  68671. +
  68672. +int
  68673. +gr_handle_ptrace(struct task_struct *task, const long request)
  68674. +{
  68675. + return 0;
  68676. +}
  68677. +
  68678. +int
  68679. +gr_handle_proc_ptrace(struct task_struct *task)
  68680. +{
  68681. + return 0;
  68682. +}
  68683. +
  68684. +int
  68685. +gr_set_acls(const int type)
  68686. +{
  68687. + return 0;
  68688. +}
  68689. +
  68690. +int
  68691. +gr_check_hidden_task(const struct task_struct *tsk)
  68692. +{
  68693. + return 0;
  68694. +}
  68695. +
  68696. +int
  68697. +gr_check_protected_task(const struct task_struct *task)
  68698. +{
  68699. + return 0;
  68700. +}
  68701. +
  68702. +int
  68703. +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
  68704. +{
  68705. + return 0;
  68706. +}
  68707. +
  68708. +void
  68709. +gr_copy_label(struct task_struct *tsk)
  68710. +{
  68711. + return;
  68712. +}
  68713. +
  68714. +void
  68715. +gr_set_pax_flags(struct task_struct *task)
  68716. +{
  68717. + return;
  68718. +}
  68719. +
  68720. +int
  68721. +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
  68722. + const int unsafe_share)
  68723. +{
  68724. + return 0;
  68725. +}
  68726. +
  68727. +void
  68728. +gr_handle_delete(const ino_t ino, const dev_t dev)
  68729. +{
  68730. + return;
  68731. +}
  68732. +
  68733. +void
  68734. +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
  68735. +{
  68736. + return;
  68737. +}
  68738. +
  68739. +void
  68740. +gr_handle_crash(struct task_struct *task, const int sig)
  68741. +{
  68742. + return;
  68743. +}
  68744. +
  68745. +int
  68746. +gr_check_crash_exec(const struct file *filp)
  68747. +{
  68748. + return 0;
  68749. +}
  68750. +
  68751. +int
  68752. +gr_check_crash_uid(const kuid_t uid)
  68753. +{
  68754. + return 0;
  68755. +}
  68756. +
  68757. +void
  68758. +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
  68759. + struct dentry *old_dentry,
  68760. + struct dentry *new_dentry,
  68761. + struct vfsmount *mnt, const __u8 replace)
  68762. +{
  68763. + return;
  68764. +}
  68765. +
  68766. +int
  68767. +gr_search_socket(const int family, const int type, const int protocol)
  68768. +{
  68769. + return 1;
  68770. +}
  68771. +
  68772. +int
  68773. +gr_search_connectbind(const int mode, const struct socket *sock,
  68774. + const struct sockaddr_in *addr)
  68775. +{
  68776. + return 0;
  68777. +}
  68778. +
  68779. +void
  68780. +gr_handle_alertkill(struct task_struct *task)
  68781. +{
  68782. + return;
  68783. +}
  68784. +
  68785. +__u32
  68786. +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
  68787. +{
  68788. + return 1;
  68789. +}
  68790. +
  68791. +__u32
  68792. +gr_acl_handle_hidden_file(const struct dentry * dentry,
  68793. + const struct vfsmount * mnt)
  68794. +{
  68795. + return 1;
  68796. +}
  68797. +
  68798. +__u32
  68799. +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
  68800. + int acc_mode)
  68801. +{
  68802. + return 1;
  68803. +}
  68804. +
  68805. +__u32
  68806. +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
  68807. +{
  68808. + return 1;
  68809. +}
  68810. +
  68811. +__u32
  68812. +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
  68813. +{
  68814. + return 1;
  68815. +}
  68816. +
  68817. +int
  68818. +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
  68819. + unsigned int *vm_flags)
  68820. +{
  68821. + return 1;
  68822. +}
  68823. +
  68824. +__u32
  68825. +gr_acl_handle_truncate(const struct dentry * dentry,
  68826. + const struct vfsmount * mnt)
  68827. +{
  68828. + return 1;
  68829. +}
  68830. +
  68831. +__u32
  68832. +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
  68833. +{
  68834. + return 1;
  68835. +}
  68836. +
  68837. +__u32
  68838. +gr_acl_handle_access(const struct dentry * dentry,
  68839. + const struct vfsmount * mnt, const int fmode)
  68840. +{
  68841. + return 1;
  68842. +}
  68843. +
  68844. +__u32
  68845. +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
  68846. + umode_t *mode)
  68847. +{
  68848. + return 1;
  68849. +}
  68850. +
  68851. +__u32
  68852. +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
  68853. +{
  68854. + return 1;
  68855. +}
  68856. +
  68857. +__u32
  68858. +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
  68859. +{
  68860. + return 1;
  68861. +}
  68862. +
  68863. +__u32
  68864. +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
  68865. +{
  68866. + return 1;
  68867. +}
  68868. +
  68869. +void
  68870. +grsecurity_init(void)
  68871. +{
  68872. + return;
  68873. +}
  68874. +
  68875. +umode_t gr_acl_umask(void)
  68876. +{
  68877. + return 0;
  68878. +}
  68879. +
  68880. +__u32
  68881. +gr_acl_handle_mknod(const struct dentry * new_dentry,
  68882. + const struct dentry * parent_dentry,
  68883. + const struct vfsmount * parent_mnt,
  68884. + const int mode)
  68885. +{
  68886. + return 1;
  68887. +}
  68888. +
  68889. +__u32
  68890. +gr_acl_handle_mkdir(const struct dentry * new_dentry,
  68891. + const struct dentry * parent_dentry,
  68892. + const struct vfsmount * parent_mnt)
  68893. +{
  68894. + return 1;
  68895. +}
  68896. +
  68897. +__u32
  68898. +gr_acl_handle_symlink(const struct dentry * new_dentry,
  68899. + const struct dentry * parent_dentry,
  68900. + const struct vfsmount * parent_mnt, const struct filename *from)
  68901. +{
  68902. + return 1;
  68903. +}
  68904. +
  68905. +__u32
  68906. +gr_acl_handle_link(const struct dentry * new_dentry,
  68907. + const struct dentry * parent_dentry,
  68908. + const struct vfsmount * parent_mnt,
  68909. + const struct dentry * old_dentry,
  68910. + const struct vfsmount * old_mnt, const struct filename *to)
  68911. +{
  68912. + return 1;
  68913. +}
  68914. +
  68915. +int
  68916. +gr_acl_handle_rename(const struct dentry *new_dentry,
  68917. + const struct dentry *parent_dentry,
  68918. + const struct vfsmount *parent_mnt,
  68919. + const struct dentry *old_dentry,
  68920. + const struct inode *old_parent_inode,
  68921. + const struct vfsmount *old_mnt, const struct filename *newname)
  68922. +{
  68923. + return 0;
  68924. +}
  68925. +
  68926. +int
  68927. +gr_acl_handle_filldir(const struct file *file, const char *name,
  68928. + const int namelen, const ino_t ino)
  68929. +{
  68930. + return 1;
  68931. +}
  68932. +
  68933. +int
  68934. +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
  68935. + const time_t shm_createtime, const kuid_t cuid, const int shmid)
  68936. +{
  68937. + return 1;
  68938. +}
  68939. +
  68940. +int
  68941. +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
  68942. +{
  68943. + return 0;
  68944. +}
  68945. +
  68946. +int
  68947. +gr_search_accept(const struct socket *sock)
  68948. +{
  68949. + return 0;
  68950. +}
  68951. +
  68952. +int
  68953. +gr_search_listen(const struct socket *sock)
  68954. +{
  68955. + return 0;
  68956. +}
  68957. +
  68958. +int
  68959. +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
  68960. +{
  68961. + return 0;
  68962. +}
  68963. +
  68964. +__u32
  68965. +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
  68966. +{
  68967. + return 1;
  68968. +}
  68969. +
  68970. +__u32
  68971. +gr_acl_handle_creat(const struct dentry * dentry,
  68972. + const struct dentry * p_dentry,
  68973. + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
  68974. + const int imode)
  68975. +{
  68976. + return 1;
  68977. +}
  68978. +
  68979. +void
  68980. +gr_acl_handle_exit(void)
  68981. +{
  68982. + return;
  68983. +}
  68984. +
  68985. +int
  68986. +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
  68987. +{
  68988. + return 1;
  68989. +}
  68990. +
  68991. +void
  68992. +gr_set_role_label(const kuid_t uid, const kgid_t gid)
  68993. +{
  68994. + return;
  68995. +}
  68996. +
  68997. +int
  68998. +gr_acl_handle_procpidmem(const struct task_struct *task)
  68999. +{
  69000. + return 0;
  69001. +}
  69002. +
  69003. +int
  69004. +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
  69005. +{
  69006. + return 0;
  69007. +}
  69008. +
  69009. +int
  69010. +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
  69011. +{
  69012. + return 0;
  69013. +}
  69014. +
  69015. +int
  69016. +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
  69017. +{
  69018. + return 0;
  69019. +}
  69020. +
  69021. +int
  69022. +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
  69023. +{
  69024. + return 0;
  69025. +}
  69026. +
  69027. +int gr_acl_enable_at_secure(void)
  69028. +{
  69029. + return 0;
  69030. +}
  69031. +
  69032. +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
  69033. +{
  69034. + return dentry->d_sb->s_dev;
  69035. +}
  69036. +
  69037. +void gr_put_exec_file(struct task_struct *task)
  69038. +{
  69039. + return;
  69040. +}
  69041. +
  69042. +#ifdef CONFIG_SECURITY
  69043. +EXPORT_SYMBOL_GPL(gr_check_user_change);
  69044. +EXPORT_SYMBOL_GPL(gr_check_group_change);
  69045. +#endif
  69046. diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
  69047. new file mode 100644
  69048. index 0000000..f35f454
  69049. --- /dev/null
  69050. +++ b/grsecurity/grsec_exec.c
  69051. @@ -0,0 +1,187 @@
  69052. +#include <linux/kernel.h>
  69053. +#include <linux/sched.h>
  69054. +#include <linux/file.h>
  69055. +#include <linux/binfmts.h>
  69056. +#include <linux/fs.h>
  69057. +#include <linux/types.h>
  69058. +#include <linux/grdefs.h>
  69059. +#include <linux/grsecurity.h>
  69060. +#include <linux/grinternal.h>
  69061. +#include <linux/capability.h>
  69062. +#include <linux/module.h>
  69063. +#include <linux/compat.h>
  69064. +
  69065. +#include <asm/uaccess.h>
  69066. +
  69067. +#ifdef CONFIG_GRKERNSEC_EXECLOG
  69068. +static char gr_exec_arg_buf[132];
  69069. +static DEFINE_MUTEX(gr_exec_arg_mutex);
  69070. +#endif
  69071. +
  69072. +struct user_arg_ptr {
  69073. +#ifdef CONFIG_COMPAT
  69074. + bool is_compat;
  69075. +#endif
  69076. + union {
  69077. + const char __user *const __user *native;
  69078. +#ifdef CONFIG_COMPAT
  69079. + const compat_uptr_t __user *compat;
  69080. +#endif
  69081. + } ptr;
  69082. +};
  69083. +
  69084. +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
  69085. +
  69086. +void
  69087. +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
  69088. +{
  69089. +#ifdef CONFIG_GRKERNSEC_EXECLOG
  69090. + char *grarg = gr_exec_arg_buf;
  69091. + unsigned int i, x, execlen = 0;
  69092. + char c;
  69093. +
  69094. + if (!((grsec_enable_execlog && grsec_enable_group &&
  69095. + in_group_p(grsec_audit_gid))
  69096. + || (grsec_enable_execlog && !grsec_enable_group)))
  69097. + return;
  69098. +
  69099. + mutex_lock(&gr_exec_arg_mutex);
  69100. + memset(grarg, 0, sizeof(gr_exec_arg_buf));
  69101. +
  69102. + for (i = 0; i < bprm->argc && execlen < 128; i++) {
  69103. + const char __user *p;
  69104. + unsigned int len;
  69105. +
  69106. + p = get_user_arg_ptr(argv, i);
  69107. + if (IS_ERR(p))
  69108. + goto log;
  69109. +
  69110. + len = strnlen_user(p, 128 - execlen);
  69111. + if (len > 128 - execlen)
  69112. + len = 128 - execlen;
  69113. + else if (len > 0)
  69114. + len--;
  69115. + if (copy_from_user(grarg + execlen, p, len))
  69116. + goto log;
  69117. +
  69118. + /* rewrite unprintable characters */
  69119. + for (x = 0; x < len; x++) {
  69120. + c = *(grarg + execlen + x);
  69121. + if (c < 32 || c > 126)
  69122. + *(grarg + execlen + x) = ' ';
  69123. + }
  69124. +
  69125. + execlen += len;
  69126. + *(grarg + execlen) = ' ';
  69127. + *(grarg + execlen + 1) = '\0';
  69128. + execlen++;
  69129. + }
  69130. +
  69131. + log:
  69132. + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
  69133. + bprm->file->f_path.mnt, grarg);
  69134. + mutex_unlock(&gr_exec_arg_mutex);
  69135. +#endif
  69136. + return;
  69137. +}
  69138. +
  69139. +#ifdef CONFIG_GRKERNSEC
  69140. +extern int gr_acl_is_capable(const int cap);
  69141. +extern int gr_acl_is_capable_nolog(const int cap);
  69142. +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
  69143. +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
  69144. +extern int gr_chroot_is_capable(const int cap);
  69145. +extern int gr_chroot_is_capable_nolog(const int cap);
  69146. +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
  69147. +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
  69148. +#endif
  69149. +
  69150. +const char *captab_log[] = {
  69151. + "CAP_CHOWN",
  69152. + "CAP_DAC_OVERRIDE",
  69153. + "CAP_DAC_READ_SEARCH",
  69154. + "CAP_FOWNER",
  69155. + "CAP_FSETID",
  69156. + "CAP_KILL",
  69157. + "CAP_SETGID",
  69158. + "CAP_SETUID",
  69159. + "CAP_SETPCAP",
  69160. + "CAP_LINUX_IMMUTABLE",
  69161. + "CAP_NET_BIND_SERVICE",
  69162. + "CAP_NET_BROADCAST",
  69163. + "CAP_NET_ADMIN",
  69164. + "CAP_NET_RAW",
  69165. + "CAP_IPC_LOCK",
  69166. + "CAP_IPC_OWNER",
  69167. + "CAP_SYS_MODULE",
  69168. + "CAP_SYS_RAWIO",
  69169. + "CAP_SYS_CHROOT",
  69170. + "CAP_SYS_PTRACE",
  69171. + "CAP_SYS_PACCT",
  69172. + "CAP_SYS_ADMIN",
  69173. + "CAP_SYS_BOOT",
  69174. + "CAP_SYS_NICE",
  69175. + "CAP_SYS_RESOURCE",
  69176. + "CAP_SYS_TIME",
  69177. + "CAP_SYS_TTY_CONFIG",
  69178. + "CAP_MKNOD",
  69179. + "CAP_LEASE",
  69180. + "CAP_AUDIT_WRITE",
  69181. + "CAP_AUDIT_CONTROL",
  69182. + "CAP_SETFCAP",
  69183. + "CAP_MAC_OVERRIDE",
  69184. + "CAP_MAC_ADMIN",
  69185. + "CAP_SYSLOG",
  69186. + "CAP_WAKE_ALARM"
  69187. +};
  69188. +
  69189. +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
  69190. +
  69191. +int gr_is_capable(const int cap)
  69192. +{
  69193. +#ifdef CONFIG_GRKERNSEC
  69194. + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
  69195. + return 1;
  69196. + return 0;
  69197. +#else
  69198. + return 1;
  69199. +#endif
  69200. +}
  69201. +
  69202. +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
  69203. +{
  69204. +#ifdef CONFIG_GRKERNSEC
  69205. + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
  69206. + return 1;
  69207. + return 0;
  69208. +#else
  69209. + return 1;
  69210. +#endif
  69211. +}
  69212. +
  69213. +int gr_is_capable_nolog(const int cap)
  69214. +{
  69215. +#ifdef CONFIG_GRKERNSEC
  69216. + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
  69217. + return 1;
  69218. + return 0;
  69219. +#else
  69220. + return 1;
  69221. +#endif
  69222. +}
  69223. +
  69224. +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
  69225. +{
  69226. +#ifdef CONFIG_GRKERNSEC
  69227. + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
  69228. + return 1;
  69229. + return 0;
  69230. +#else
  69231. + return 1;
  69232. +#endif
  69233. +}
  69234. +
  69235. +EXPORT_SYMBOL_GPL(gr_is_capable);
  69236. +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
  69237. +EXPORT_SYMBOL_GPL(gr_task_is_capable);
  69238. +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
  69239. diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
  69240. new file mode 100644
  69241. index 0000000..06cc6ea
  69242. --- /dev/null
  69243. +++ b/grsecurity/grsec_fifo.c
  69244. @@ -0,0 +1,24 @@
  69245. +#include <linux/kernel.h>
  69246. +#include <linux/sched.h>
  69247. +#include <linux/fs.h>
  69248. +#include <linux/file.h>
  69249. +#include <linux/grinternal.h>
  69250. +
  69251. +int
  69252. +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
  69253. + const struct dentry *dir, const int flag, const int acc_mode)
  69254. +{
  69255. +#ifdef CONFIG_GRKERNSEC_FIFO
  69256. + const struct cred *cred = current_cred();
  69257. +
  69258. + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
  69259. + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
  69260. + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
  69261. + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
  69262. + if (!inode_permission(dentry->d_inode, acc_mode))
  69263. + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
  69264. + return -EACCES;
  69265. + }
  69266. +#endif
  69267. + return 0;
  69268. +}
  69269. diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
  69270. new file mode 100644
  69271. index 0000000..8ca18bf
  69272. --- /dev/null
  69273. +++ b/grsecurity/grsec_fork.c
  69274. @@ -0,0 +1,23 @@
  69275. +#include <linux/kernel.h>
  69276. +#include <linux/sched.h>
  69277. +#include <linux/grsecurity.h>
  69278. +#include <linux/grinternal.h>
  69279. +#include <linux/errno.h>
  69280. +
  69281. +void
  69282. +gr_log_forkfail(const int retval)
  69283. +{
  69284. +#ifdef CONFIG_GRKERNSEC_FORKFAIL
  69285. + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
  69286. + switch (retval) {
  69287. + case -EAGAIN:
  69288. + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
  69289. + break;
  69290. + case -ENOMEM:
  69291. + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
  69292. + break;
  69293. + }
  69294. + }
  69295. +#endif
  69296. + return;
  69297. +}
  69298. diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
  69299. new file mode 100644
  69300. index 0000000..ae6c028
  69301. --- /dev/null
  69302. +++ b/grsecurity/grsec_init.c
  69303. @@ -0,0 +1,272 @@
  69304. +#include <linux/kernel.h>
  69305. +#include <linux/sched.h>
  69306. +#include <linux/mm.h>
  69307. +#include <linux/gracl.h>
  69308. +#include <linux/slab.h>
  69309. +#include <linux/vmalloc.h>
  69310. +#include <linux/percpu.h>
  69311. +#include <linux/module.h>
  69312. +
  69313. +int grsec_enable_ptrace_readexec;
  69314. +int grsec_enable_setxid;
  69315. +int grsec_enable_symlinkown;
  69316. +kgid_t grsec_symlinkown_gid;
  69317. +int grsec_enable_brute;
  69318. +int grsec_enable_link;
  69319. +int grsec_enable_dmesg;
  69320. +int grsec_enable_harden_ptrace;
  69321. +int grsec_enable_harden_ipc;
  69322. +int grsec_enable_fifo;
  69323. +int grsec_enable_execlog;
  69324. +int grsec_enable_signal;
  69325. +int grsec_enable_forkfail;
  69326. +int grsec_enable_audit_ptrace;
  69327. +int grsec_enable_time;
  69328. +int grsec_enable_group;
  69329. +kgid_t grsec_audit_gid;
  69330. +int grsec_enable_chdir;
  69331. +int grsec_enable_mount;
  69332. +int grsec_enable_rofs;
  69333. +int grsec_deny_new_usb;
  69334. +int grsec_enable_chroot_findtask;
  69335. +int grsec_enable_chroot_mount;
  69336. +int grsec_enable_chroot_shmat;
  69337. +int grsec_enable_chroot_fchdir;
  69338. +int grsec_enable_chroot_double;
  69339. +int grsec_enable_chroot_pivot;
  69340. +int grsec_enable_chroot_chdir;
  69341. +int grsec_enable_chroot_chmod;
  69342. +int grsec_enable_chroot_mknod;
  69343. +int grsec_enable_chroot_nice;
  69344. +int grsec_enable_chroot_execlog;
  69345. +int grsec_enable_chroot_caps;
  69346. +int grsec_enable_chroot_sysctl;
  69347. +int grsec_enable_chroot_unix;
  69348. +int grsec_enable_tpe;
  69349. +kgid_t grsec_tpe_gid;
  69350. +int grsec_enable_blackhole;
  69351. +#ifdef CONFIG_IPV6_MODULE
  69352. +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
  69353. +#endif
  69354. +int grsec_lastack_retries;
  69355. +int grsec_enable_tpe_all;
  69356. +int grsec_enable_tpe_invert;
  69357. +int grsec_enable_socket_all;
  69358. +kgid_t grsec_socket_all_gid;
  69359. +int grsec_enable_socket_client;
  69360. +kgid_t grsec_socket_client_gid;
  69361. +int grsec_enable_socket_server;
  69362. +kgid_t grsec_socket_server_gid;
  69363. +int grsec_resource_logging;
  69364. +int grsec_disable_privio;
  69365. +int grsec_enable_log_rwxmaps;
  69366. +int grsec_lock;
  69367. +
  69368. +DEFINE_SPINLOCK(grsec_alert_lock);
  69369. +unsigned long grsec_alert_wtime = 0;
  69370. +unsigned long grsec_alert_fyet = 0;
  69371. +
  69372. +DEFINE_SPINLOCK(grsec_audit_lock);
  69373. +
  69374. +DEFINE_RWLOCK(grsec_exec_file_lock);
  69375. +
  69376. +char *gr_shared_page[4];
  69377. +
  69378. +char *gr_alert_log_fmt;
  69379. +char *gr_audit_log_fmt;
  69380. +char *gr_alert_log_buf;
  69381. +char *gr_audit_log_buf;
  69382. +
  69383. +void __init
  69384. +grsecurity_init(void)
  69385. +{
  69386. + int j;
  69387. + /* create the per-cpu shared pages */
  69388. +
  69389. +#ifdef CONFIG_X86
  69390. + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
  69391. +#endif
  69392. +
  69393. + for (j = 0; j < 4; j++) {
  69394. + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
  69395. + if (gr_shared_page[j] == NULL) {
  69396. + panic("Unable to allocate grsecurity shared page");
  69397. + return;
  69398. + }
  69399. + }
  69400. +
  69401. + /* allocate log buffers */
  69402. + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
  69403. + if (!gr_alert_log_fmt) {
  69404. + panic("Unable to allocate grsecurity alert log format buffer");
  69405. + return;
  69406. + }
  69407. + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
  69408. + if (!gr_audit_log_fmt) {
  69409. + panic("Unable to allocate grsecurity audit log format buffer");
  69410. + return;
  69411. + }
  69412. + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
  69413. + if (!gr_alert_log_buf) {
  69414. + panic("Unable to allocate grsecurity alert log buffer");
  69415. + return;
  69416. + }
  69417. + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
  69418. + if (!gr_audit_log_buf) {
  69419. + panic("Unable to allocate grsecurity audit log buffer");
  69420. + return;
  69421. + }
  69422. +
  69423. +#ifdef CONFIG_GRKERNSEC_IO
  69424. +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
  69425. + grsec_disable_privio = 1;
  69426. +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
  69427. + grsec_disable_privio = 1;
  69428. +#else
  69429. + grsec_disable_privio = 0;
  69430. +#endif
  69431. +#endif
  69432. +
  69433. +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
  69434. + /* for backward compatibility, tpe_invert always defaults to on if
  69435. + enabled in the kernel
  69436. + */
  69437. + grsec_enable_tpe_invert = 1;
  69438. +#endif
  69439. +
  69440. +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
  69441. +#ifndef CONFIG_GRKERNSEC_SYSCTL
  69442. + grsec_lock = 1;
  69443. +#endif
  69444. +
  69445. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  69446. + grsec_enable_log_rwxmaps = 1;
  69447. +#endif
  69448. +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
  69449. + grsec_enable_group = 1;
  69450. + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
  69451. +#endif
  69452. +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
  69453. + grsec_enable_ptrace_readexec = 1;
  69454. +#endif
  69455. +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
  69456. + grsec_enable_chdir = 1;
  69457. +#endif
  69458. +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
  69459. + grsec_enable_harden_ptrace = 1;
  69460. +#endif
  69461. +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
  69462. + grsec_enable_harden_ipc = 1;
  69463. +#endif
  69464. +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
  69465. + grsec_enable_mount = 1;
  69466. +#endif
  69467. +#ifdef CONFIG_GRKERNSEC_LINK
  69468. + grsec_enable_link = 1;
  69469. +#endif
  69470. +#ifdef CONFIG_GRKERNSEC_BRUTE
  69471. + grsec_enable_brute = 1;
  69472. +#endif
  69473. +#ifdef CONFIG_GRKERNSEC_DMESG
  69474. + grsec_enable_dmesg = 1;
  69475. +#endif
  69476. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  69477. + grsec_enable_blackhole = 1;
  69478. + grsec_lastack_retries = 4;
  69479. +#endif
  69480. +#ifdef CONFIG_GRKERNSEC_FIFO
  69481. + grsec_enable_fifo = 1;
  69482. +#endif
  69483. +#ifdef CONFIG_GRKERNSEC_EXECLOG
  69484. + grsec_enable_execlog = 1;
  69485. +#endif
  69486. +#ifdef CONFIG_GRKERNSEC_SETXID
  69487. + grsec_enable_setxid = 1;
  69488. +#endif
  69489. +#ifdef CONFIG_GRKERNSEC_SIGNAL
  69490. + grsec_enable_signal = 1;
  69491. +#endif
  69492. +#ifdef CONFIG_GRKERNSEC_FORKFAIL
  69493. + grsec_enable_forkfail = 1;
  69494. +#endif
  69495. +#ifdef CONFIG_GRKERNSEC_TIME
  69496. + grsec_enable_time = 1;
  69497. +#endif
  69498. +#ifdef CONFIG_GRKERNSEC_RESLOG
  69499. + grsec_resource_logging = 1;
  69500. +#endif
  69501. +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
  69502. + grsec_enable_chroot_findtask = 1;
  69503. +#endif
  69504. +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
  69505. + grsec_enable_chroot_unix = 1;
  69506. +#endif
  69507. +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
  69508. + grsec_enable_chroot_mount = 1;
  69509. +#endif
  69510. +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
  69511. + grsec_enable_chroot_fchdir = 1;
  69512. +#endif
  69513. +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
  69514. + grsec_enable_chroot_shmat = 1;
  69515. +#endif
  69516. +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
  69517. + grsec_enable_audit_ptrace = 1;
  69518. +#endif
  69519. +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
  69520. + grsec_enable_chroot_double = 1;
  69521. +#endif
  69522. +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
  69523. + grsec_enable_chroot_pivot = 1;
  69524. +#endif
  69525. +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
  69526. + grsec_enable_chroot_chdir = 1;
  69527. +#endif
  69528. +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
  69529. + grsec_enable_chroot_chmod = 1;
  69530. +#endif
  69531. +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
  69532. + grsec_enable_chroot_mknod = 1;
  69533. +#endif
  69534. +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
  69535. + grsec_enable_chroot_nice = 1;
  69536. +#endif
  69537. +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
  69538. + grsec_enable_chroot_execlog = 1;
  69539. +#endif
  69540. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  69541. + grsec_enable_chroot_caps = 1;
  69542. +#endif
  69543. +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
  69544. + grsec_enable_chroot_sysctl = 1;
  69545. +#endif
  69546. +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
  69547. + grsec_enable_symlinkown = 1;
  69548. + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
  69549. +#endif
  69550. +#ifdef CONFIG_GRKERNSEC_TPE
  69551. + grsec_enable_tpe = 1;
  69552. + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
  69553. +#ifdef CONFIG_GRKERNSEC_TPE_ALL
  69554. + grsec_enable_tpe_all = 1;
  69555. +#endif
  69556. +#endif
  69557. +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
  69558. + grsec_enable_socket_all = 1;
  69559. + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
  69560. +#endif
  69561. +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
  69562. + grsec_enable_socket_client = 1;
  69563. + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
  69564. +#endif
  69565. +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
  69566. + grsec_enable_socket_server = 1;
  69567. + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
  69568. +#endif
  69569. +#endif
  69570. +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
  69571. + grsec_deny_new_usb = 1;
  69572. +#endif
  69573. +
  69574. + return;
  69575. +}
  69576. diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
  69577. new file mode 100644
  69578. index 0000000..1773300
  69579. --- /dev/null
  69580. +++ b/grsecurity/grsec_ipc.c
  69581. @@ -0,0 +1,48 @@
  69582. +#include <linux/kernel.h>
  69583. +#include <linux/mm.h>
  69584. +#include <linux/sched.h>
  69585. +#include <linux/file.h>
  69586. +#include <linux/ipc.h>
  69587. +#include <linux/ipc_namespace.h>
  69588. +#include <linux/grsecurity.h>
  69589. +#include <linux/grinternal.h>
  69590. +
  69591. +int
  69592. +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
  69593. +{
  69594. +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
  69595. + int write;
  69596. + int orig_granted_mode;
  69597. + kuid_t euid;
  69598. + kgid_t egid;
  69599. +
  69600. + if (!grsec_enable_harden_ipc)
  69601. + return 1;
  69602. +
  69603. + euid = current_euid();
  69604. + egid = current_egid();
  69605. +
  69606. + write = requested_mode & 00002;
  69607. + orig_granted_mode = ipcp->mode;
  69608. +
  69609. + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
  69610. + orig_granted_mode >>= 6;
  69611. + else {
  69612. + /* if likely wrong permissions, lock to user */
  69613. + if (orig_granted_mode & 0007)
  69614. + orig_granted_mode = 0;
  69615. + /* otherwise do a egid-only check */
  69616. + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
  69617. + orig_granted_mode >>= 3;
  69618. + /* otherwise, no access */
  69619. + else
  69620. + orig_granted_mode = 0;
  69621. + }
  69622. + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
  69623. + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
  69624. + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
  69625. + return 0;
  69626. + }
  69627. +#endif
  69628. + return 1;
  69629. +}
  69630. diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
  69631. new file mode 100644
  69632. index 0000000..5e05e20
  69633. --- /dev/null
  69634. +++ b/grsecurity/grsec_link.c
  69635. @@ -0,0 +1,58 @@
  69636. +#include <linux/kernel.h>
  69637. +#include <linux/sched.h>
  69638. +#include <linux/fs.h>
  69639. +#include <linux/file.h>
  69640. +#include <linux/grinternal.h>
  69641. +
  69642. +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
  69643. +{
  69644. +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
  69645. + const struct inode *link_inode = link->dentry->d_inode;
  69646. +
  69647. + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
  69648. + /* ignore root-owned links, e.g. /proc/self */
  69649. + gr_is_global_nonroot(link_inode->i_uid) && target &&
  69650. + !uid_eq(link_inode->i_uid, target->i_uid)) {
  69651. + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
  69652. + return 1;
  69653. + }
  69654. +#endif
  69655. + return 0;
  69656. +}
  69657. +
  69658. +int
  69659. +gr_handle_follow_link(const struct inode *parent,
  69660. + const struct inode *inode,
  69661. + const struct dentry *dentry, const struct vfsmount *mnt)
  69662. +{
  69663. +#ifdef CONFIG_GRKERNSEC_LINK
  69664. + const struct cred *cred = current_cred();
  69665. +
  69666. + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
  69667. + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
  69668. + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
  69669. + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
  69670. + return -EACCES;
  69671. + }
  69672. +#endif
  69673. + return 0;
  69674. +}
  69675. +
  69676. +int
  69677. +gr_handle_hardlink(const struct dentry *dentry,
  69678. + const struct vfsmount *mnt,
  69679. + struct inode *inode, const int mode, const struct filename *to)
  69680. +{
  69681. +#ifdef CONFIG_GRKERNSEC_LINK
  69682. + const struct cred *cred = current_cred();
  69683. +
  69684. + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
  69685. + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
  69686. + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
  69687. + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
  69688. + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
  69689. + return -EPERM;
  69690. + }
  69691. +#endif
  69692. + return 0;
  69693. +}
  69694. diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
  69695. new file mode 100644
  69696. index 0000000..dbe0a6b
  69697. --- /dev/null
  69698. +++ b/grsecurity/grsec_log.c
  69699. @@ -0,0 +1,341 @@
  69700. +#include <linux/kernel.h>
  69701. +#include <linux/sched.h>
  69702. +#include <linux/file.h>
  69703. +#include <linux/tty.h>
  69704. +#include <linux/fs.h>
  69705. +#include <linux/mm.h>
  69706. +#include <linux/grinternal.h>
  69707. +
  69708. +#ifdef CONFIG_TREE_PREEMPT_RCU
  69709. +#define DISABLE_PREEMPT() preempt_disable()
  69710. +#define ENABLE_PREEMPT() preempt_enable()
  69711. +#else
  69712. +#define DISABLE_PREEMPT()
  69713. +#define ENABLE_PREEMPT()
  69714. +#endif
  69715. +
  69716. +#define BEGIN_LOCKS(x) \
  69717. + DISABLE_PREEMPT(); \
  69718. + rcu_read_lock(); \
  69719. + read_lock(&tasklist_lock); \
  69720. + read_lock(&grsec_exec_file_lock); \
  69721. + if (x != GR_DO_AUDIT) \
  69722. + spin_lock(&grsec_alert_lock); \
  69723. + else \
  69724. + spin_lock(&grsec_audit_lock)
  69725. +
  69726. +#define END_LOCKS(x) \
  69727. + if (x != GR_DO_AUDIT) \
  69728. + spin_unlock(&grsec_alert_lock); \
  69729. + else \
  69730. + spin_unlock(&grsec_audit_lock); \
  69731. + read_unlock(&grsec_exec_file_lock); \
  69732. + read_unlock(&tasklist_lock); \
  69733. + rcu_read_unlock(); \
  69734. + ENABLE_PREEMPT(); \
  69735. + if (x == GR_DONT_AUDIT) \
  69736. + gr_handle_alertkill(current)
  69737. +
  69738. +enum {
  69739. + FLOODING,
  69740. + NO_FLOODING
  69741. +};
  69742. +
  69743. +extern char *gr_alert_log_fmt;
  69744. +extern char *gr_audit_log_fmt;
  69745. +extern char *gr_alert_log_buf;
  69746. +extern char *gr_audit_log_buf;
  69747. +
  69748. +static int gr_log_start(int audit)
  69749. +{
  69750. + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
  69751. + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
  69752. + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
  69753. +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
  69754. + unsigned long curr_secs = get_seconds();
  69755. +
  69756. + if (audit == GR_DO_AUDIT)
  69757. + goto set_fmt;
  69758. +
  69759. + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
  69760. + grsec_alert_wtime = curr_secs;
  69761. + grsec_alert_fyet = 0;
  69762. + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
  69763. + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
  69764. + grsec_alert_fyet++;
  69765. + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
  69766. + grsec_alert_wtime = curr_secs;
  69767. + grsec_alert_fyet++;
  69768. + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
  69769. + return FLOODING;
  69770. + }
  69771. + else return FLOODING;
  69772. +
  69773. +set_fmt:
  69774. +#endif
  69775. + memset(buf, 0, PAGE_SIZE);
  69776. + if (current->signal->curr_ip && gr_acl_is_enabled()) {
  69777. + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
  69778. + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
  69779. + } else if (current->signal->curr_ip) {
  69780. + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
  69781. + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
  69782. + } else if (gr_acl_is_enabled()) {
  69783. + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
  69784. + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
  69785. + } else {
  69786. + sprintf(fmt, "%s%s", loglevel, "grsec: ");
  69787. + strcpy(buf, fmt);
  69788. + }
  69789. +
  69790. + return NO_FLOODING;
  69791. +}
  69792. +
  69793. +static void gr_log_middle(int audit, const char *msg, va_list ap)
  69794. + __attribute__ ((format (printf, 2, 0)));
  69795. +
  69796. +static void gr_log_middle(int audit, const char *msg, va_list ap)
  69797. +{
  69798. + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
  69799. + unsigned int len = strlen(buf);
  69800. +
  69801. + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
  69802. +
  69803. + return;
  69804. +}
  69805. +
  69806. +static void gr_log_middle_varargs(int audit, const char *msg, ...)
  69807. + __attribute__ ((format (printf, 2, 3)));
  69808. +
  69809. +static void gr_log_middle_varargs(int audit, const char *msg, ...)
  69810. +{
  69811. + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
  69812. + unsigned int len = strlen(buf);
  69813. + va_list ap;
  69814. +
  69815. + va_start(ap, msg);
  69816. + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
  69817. + va_end(ap);
  69818. +
  69819. + return;
  69820. +}
  69821. +
  69822. +static void gr_log_end(int audit, int append_default)
  69823. +{
  69824. + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
  69825. + if (append_default) {
  69826. + struct task_struct *task = current;
  69827. + struct task_struct *parent = task->real_parent;
  69828. + const struct cred *cred = __task_cred(task);
  69829. + const struct cred *pcred = __task_cred(parent);
  69830. + unsigned int len = strlen(buf);
  69831. +
  69832. + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
  69833. + }
  69834. +
  69835. + printk("%s\n", buf);
  69836. +
  69837. + return;
  69838. +}
  69839. +
  69840. +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
  69841. +{
  69842. + int logtype;
  69843. + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
  69844. + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
  69845. + void *voidptr = NULL;
  69846. + int num1 = 0, num2 = 0;
  69847. + unsigned long ulong1 = 0, ulong2 = 0;
  69848. + struct dentry *dentry = NULL;
  69849. + struct vfsmount *mnt = NULL;
  69850. + struct file *file = NULL;
  69851. + struct task_struct *task = NULL;
  69852. + struct vm_area_struct *vma = NULL;
  69853. + const struct cred *cred, *pcred;
  69854. + va_list ap;
  69855. +
  69856. + BEGIN_LOCKS(audit);
  69857. + logtype = gr_log_start(audit);
  69858. + if (logtype == FLOODING) {
  69859. + END_LOCKS(audit);
  69860. + return;
  69861. + }
  69862. + va_start(ap, argtypes);
  69863. + switch (argtypes) {
  69864. + case GR_TTYSNIFF:
  69865. + task = va_arg(ap, struct task_struct *);
  69866. + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
  69867. + break;
  69868. + case GR_SYSCTL_HIDDEN:
  69869. + str1 = va_arg(ap, char *);
  69870. + gr_log_middle_varargs(audit, msg, result, str1);
  69871. + break;
  69872. + case GR_RBAC:
  69873. + dentry = va_arg(ap, struct dentry *);
  69874. + mnt = va_arg(ap, struct vfsmount *);
  69875. + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
  69876. + break;
  69877. + case GR_RBAC_STR:
  69878. + dentry = va_arg(ap, struct dentry *);
  69879. + mnt = va_arg(ap, struct vfsmount *);
  69880. + str1 = va_arg(ap, char *);
  69881. + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
  69882. + break;
  69883. + case GR_STR_RBAC:
  69884. + str1 = va_arg(ap, char *);
  69885. + dentry = va_arg(ap, struct dentry *);
  69886. + mnt = va_arg(ap, struct vfsmount *);
  69887. + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
  69888. + break;
  69889. + case GR_RBAC_MODE2:
  69890. + dentry = va_arg(ap, struct dentry *);
  69891. + mnt = va_arg(ap, struct vfsmount *);
  69892. + str1 = va_arg(ap, char *);
  69893. + str2 = va_arg(ap, char *);
  69894. + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
  69895. + break;
  69896. + case GR_RBAC_MODE3:
  69897. + dentry = va_arg(ap, struct dentry *);
  69898. + mnt = va_arg(ap, struct vfsmount *);
  69899. + str1 = va_arg(ap, char *);
  69900. + str2 = va_arg(ap, char *);
  69901. + str3 = va_arg(ap, char *);
  69902. + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
  69903. + break;
  69904. + case GR_FILENAME:
  69905. + dentry = va_arg(ap, struct dentry *);
  69906. + mnt = va_arg(ap, struct vfsmount *);
  69907. + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
  69908. + break;
  69909. + case GR_STR_FILENAME:
  69910. + str1 = va_arg(ap, char *);
  69911. + dentry = va_arg(ap, struct dentry *);
  69912. + mnt = va_arg(ap, struct vfsmount *);
  69913. + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
  69914. + break;
  69915. + case GR_FILENAME_STR:
  69916. + dentry = va_arg(ap, struct dentry *);
  69917. + mnt = va_arg(ap, struct vfsmount *);
  69918. + str1 = va_arg(ap, char *);
  69919. + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
  69920. + break;
  69921. + case GR_FILENAME_TWO_INT:
  69922. + dentry = va_arg(ap, struct dentry *);
  69923. + mnt = va_arg(ap, struct vfsmount *);
  69924. + num1 = va_arg(ap, int);
  69925. + num2 = va_arg(ap, int);
  69926. + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
  69927. + break;
  69928. + case GR_FILENAME_TWO_INT_STR:
  69929. + dentry = va_arg(ap, struct dentry *);
  69930. + mnt = va_arg(ap, struct vfsmount *);
  69931. + num1 = va_arg(ap, int);
  69932. + num2 = va_arg(ap, int);
  69933. + str1 = va_arg(ap, char *);
  69934. + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
  69935. + break;
  69936. + case GR_TEXTREL:
  69937. + file = va_arg(ap, struct file *);
  69938. + ulong1 = va_arg(ap, unsigned long);
  69939. + ulong2 = va_arg(ap, unsigned long);
  69940. + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
  69941. + break;
  69942. + case GR_PTRACE:
  69943. + task = va_arg(ap, struct task_struct *);
  69944. + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
  69945. + break;
  69946. + case GR_RESOURCE:
  69947. + task = va_arg(ap, struct task_struct *);
  69948. + cred = __task_cred(task);
  69949. + pcred = __task_cred(task->real_parent);
  69950. + ulong1 = va_arg(ap, unsigned long);
  69951. + str1 = va_arg(ap, char *);
  69952. + ulong2 = va_arg(ap, unsigned long);
  69953. + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
  69954. + break;
  69955. + case GR_CAP:
  69956. + task = va_arg(ap, struct task_struct *);
  69957. + cred = __task_cred(task);
  69958. + pcred = __task_cred(task->real_parent);
  69959. + str1 = va_arg(ap, char *);
  69960. + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
  69961. + break;
  69962. + case GR_SIG:
  69963. + str1 = va_arg(ap, char *);
  69964. + voidptr = va_arg(ap, void *);
  69965. + gr_log_middle_varargs(audit, msg, str1, voidptr);
  69966. + break;
  69967. + case GR_SIG2:
  69968. + task = va_arg(ap, struct task_struct *);
  69969. + cred = __task_cred(task);
  69970. + pcred = __task_cred(task->real_parent);
  69971. + num1 = va_arg(ap, int);
  69972. + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
  69973. + break;
  69974. + case GR_CRASH1:
  69975. + task = va_arg(ap, struct task_struct *);
  69976. + cred = __task_cred(task);
  69977. + pcred = __task_cred(task->real_parent);
  69978. + ulong1 = va_arg(ap, unsigned long);
  69979. + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
  69980. + break;
  69981. + case GR_CRASH2:
  69982. + task = va_arg(ap, struct task_struct *);
  69983. + cred = __task_cred(task);
  69984. + pcred = __task_cred(task->real_parent);
  69985. + ulong1 = va_arg(ap, unsigned long);
  69986. + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
  69987. + break;
  69988. + case GR_RWXMAP:
  69989. + file = va_arg(ap, struct file *);
  69990. + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
  69991. + break;
  69992. + case GR_RWXMAPVMA:
  69993. + vma = va_arg(ap, struct vm_area_struct *);
  69994. + if (vma->vm_file)
  69995. + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
  69996. + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
  69997. + str1 = "<stack>";
  69998. + else if (vma->vm_start <= current->mm->brk &&
  69999. + vma->vm_end >= current->mm->start_brk)
  70000. + str1 = "<heap>";
  70001. + else
  70002. + str1 = "<anonymous mapping>";
  70003. + gr_log_middle_varargs(audit, msg, str1);
  70004. + break;
  70005. + case GR_PSACCT:
  70006. + {
  70007. + unsigned int wday, cday;
  70008. + __u8 whr, chr;
  70009. + __u8 wmin, cmin;
  70010. + __u8 wsec, csec;
  70011. + char cur_tty[64] = { 0 };
  70012. + char parent_tty[64] = { 0 };
  70013. +
  70014. + task = va_arg(ap, struct task_struct *);
  70015. + wday = va_arg(ap, unsigned int);
  70016. + cday = va_arg(ap, unsigned int);
  70017. + whr = va_arg(ap, int);
  70018. + chr = va_arg(ap, int);
  70019. + wmin = va_arg(ap, int);
  70020. + cmin = va_arg(ap, int);
  70021. + wsec = va_arg(ap, int);
  70022. + csec = va_arg(ap, int);
  70023. + ulong1 = va_arg(ap, unsigned long);
  70024. + cred = __task_cred(task);
  70025. + pcred = __task_cred(task->real_parent);
  70026. +
  70027. + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
  70028. + }
  70029. + break;
  70030. + default:
  70031. + gr_log_middle(audit, msg, ap);
  70032. + }
  70033. + va_end(ap);
  70034. + // these don't need DEFAULTSECARGS printed on the end
  70035. + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
  70036. + gr_log_end(audit, 0);
  70037. + else
  70038. + gr_log_end(audit, 1);
  70039. + END_LOCKS(audit);
  70040. +}
  70041. diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
  70042. new file mode 100644
  70043. index 0000000..0e39d8c
  70044. --- /dev/null
  70045. +++ b/grsecurity/grsec_mem.c
  70046. @@ -0,0 +1,48 @@
  70047. +#include <linux/kernel.h>
  70048. +#include <linux/sched.h>
  70049. +#include <linux/mm.h>
  70050. +#include <linux/mman.h>
  70051. +#include <linux/module.h>
  70052. +#include <linux/grinternal.h>
  70053. +
  70054. +void gr_handle_msr_write(void)
  70055. +{
  70056. + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
  70057. + return;
  70058. +}
  70059. +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
  70060. +
  70061. +void
  70062. +gr_handle_ioperm(void)
  70063. +{
  70064. + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
  70065. + return;
  70066. +}
  70067. +
  70068. +void
  70069. +gr_handle_iopl(void)
  70070. +{
  70071. + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
  70072. + return;
  70073. +}
  70074. +
  70075. +void
  70076. +gr_handle_mem_readwrite(u64 from, u64 to)
  70077. +{
  70078. + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
  70079. + return;
  70080. +}
  70081. +
  70082. +void
  70083. +gr_handle_vm86(void)
  70084. +{
  70085. + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
  70086. + return;
  70087. +}
  70088. +
  70089. +void
  70090. +gr_log_badprocpid(const char *entry)
  70091. +{
  70092. + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
  70093. + return;
  70094. +}
  70095. diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
  70096. new file mode 100644
  70097. index 0000000..cd9e124
  70098. --- /dev/null
  70099. +++ b/grsecurity/grsec_mount.c
  70100. @@ -0,0 +1,65 @@
  70101. +#include <linux/kernel.h>
  70102. +#include <linux/sched.h>
  70103. +#include <linux/mount.h>
  70104. +#include <linux/major.h>
  70105. +#include <linux/grsecurity.h>
  70106. +#include <linux/grinternal.h>
  70107. +
  70108. +void
  70109. +gr_log_remount(const char *devname, const int retval)
  70110. +{
  70111. +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
  70112. + if (grsec_enable_mount && (retval >= 0))
  70113. + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
  70114. +#endif
  70115. + return;
  70116. +}
  70117. +
  70118. +void
  70119. +gr_log_unmount(const char *devname, const int retval)
  70120. +{
  70121. +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
  70122. + if (grsec_enable_mount && (retval >= 0))
  70123. + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
  70124. +#endif
  70125. + return;
  70126. +}
  70127. +
  70128. +void
  70129. +gr_log_mount(const char *from, const char *to, const int retval)
  70130. +{
  70131. +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
  70132. + if (grsec_enable_mount && (retval >= 0))
  70133. + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
  70134. +#endif
  70135. + return;
  70136. +}
  70137. +
  70138. +int
  70139. +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
  70140. +{
  70141. +#ifdef CONFIG_GRKERNSEC_ROFS
  70142. + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
  70143. + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
  70144. + return -EPERM;
  70145. + } else
  70146. + return 0;
  70147. +#endif
  70148. + return 0;
  70149. +}
  70150. +
  70151. +int
  70152. +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
  70153. +{
  70154. +#ifdef CONFIG_GRKERNSEC_ROFS
  70155. + struct inode *inode = dentry->d_inode;
  70156. +
  70157. + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
  70158. + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
  70159. + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
  70160. + return -EPERM;
  70161. + } else
  70162. + return 0;
  70163. +#endif
  70164. + return 0;
  70165. +}
  70166. diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
  70167. new file mode 100644
  70168. index 0000000..6ee9d50
  70169. --- /dev/null
  70170. +++ b/grsecurity/grsec_pax.c
  70171. @@ -0,0 +1,45 @@
  70172. +#include <linux/kernel.h>
  70173. +#include <linux/sched.h>
  70174. +#include <linux/mm.h>
  70175. +#include <linux/file.h>
  70176. +#include <linux/grinternal.h>
  70177. +#include <linux/grsecurity.h>
  70178. +
  70179. +void
  70180. +gr_log_textrel(struct vm_area_struct * vma)
  70181. +{
  70182. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  70183. + if (grsec_enable_log_rwxmaps)
  70184. + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
  70185. +#endif
  70186. + return;
  70187. +}
  70188. +
  70189. +void gr_log_ptgnustack(struct file *file)
  70190. +{
  70191. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  70192. + if (grsec_enable_log_rwxmaps)
  70193. + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
  70194. +#endif
  70195. + return;
  70196. +}
  70197. +
  70198. +void
  70199. +gr_log_rwxmmap(struct file *file)
  70200. +{
  70201. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  70202. + if (grsec_enable_log_rwxmaps)
  70203. + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
  70204. +#endif
  70205. + return;
  70206. +}
  70207. +
  70208. +void
  70209. +gr_log_rwxmprotect(struct vm_area_struct *vma)
  70210. +{
  70211. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  70212. + if (grsec_enable_log_rwxmaps)
  70213. + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
  70214. +#endif
  70215. + return;
  70216. +}
  70217. diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
  70218. new file mode 100644
  70219. index 0000000..2005a3a
  70220. --- /dev/null
  70221. +++ b/grsecurity/grsec_proc.c
  70222. @@ -0,0 +1,20 @@
  70223. +#include <linux/kernel.h>
  70224. +#include <linux/sched.h>
  70225. +#include <linux/grsecurity.h>
  70226. +#include <linux/grinternal.h>
  70227. +
  70228. +int gr_proc_is_restricted(void)
  70229. +{
  70230. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  70231. + const struct cred *cred = current_cred();
  70232. +#endif
  70233. +
  70234. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  70235. + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
  70236. + return -EACCES;
  70237. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  70238. + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
  70239. + return -EACCES;
  70240. +#endif
  70241. + return 0;
  70242. +}
  70243. diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
  70244. new file mode 100644
  70245. index 0000000..f7f29aa
  70246. --- /dev/null
  70247. +++ b/grsecurity/grsec_ptrace.c
  70248. @@ -0,0 +1,30 @@
  70249. +#include <linux/kernel.h>
  70250. +#include <linux/sched.h>
  70251. +#include <linux/grinternal.h>
  70252. +#include <linux/security.h>
  70253. +
  70254. +void
  70255. +gr_audit_ptrace(struct task_struct *task)
  70256. +{
  70257. +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
  70258. + if (grsec_enable_audit_ptrace)
  70259. + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
  70260. +#endif
  70261. + return;
  70262. +}
  70263. +
  70264. +int
  70265. +gr_ptrace_readexec(struct file *file, int unsafe_flags)
  70266. +{
  70267. +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
  70268. + const struct dentry *dentry = file->f_path.dentry;
  70269. + const struct vfsmount *mnt = file->f_path.mnt;
  70270. +
  70271. + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
  70272. + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
  70273. + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
  70274. + return -EACCES;
  70275. + }
  70276. +#endif
  70277. + return 0;
  70278. +}
  70279. diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
  70280. new file mode 100644
  70281. index 0000000..3860c7e
  70282. --- /dev/null
  70283. +++ b/grsecurity/grsec_sig.c
  70284. @@ -0,0 +1,236 @@
  70285. +#include <linux/kernel.h>
  70286. +#include <linux/sched.h>
  70287. +#include <linux/fs.h>
  70288. +#include <linux/delay.h>
  70289. +#include <linux/grsecurity.h>
  70290. +#include <linux/grinternal.h>
  70291. +#include <linux/hardirq.h>
  70292. +
  70293. +char *signames[] = {
  70294. + [SIGSEGV] = "Segmentation fault",
  70295. + [SIGILL] = "Illegal instruction",
  70296. + [SIGABRT] = "Abort",
  70297. + [SIGBUS] = "Invalid alignment/Bus error"
  70298. +};
  70299. +
  70300. +void
  70301. +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
  70302. +{
  70303. +#ifdef CONFIG_GRKERNSEC_SIGNAL
  70304. + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
  70305. + (sig == SIGABRT) || (sig == SIGBUS))) {
  70306. + if (task_pid_nr(t) == task_pid_nr(current)) {
  70307. + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
  70308. + } else {
  70309. + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
  70310. + }
  70311. + }
  70312. +#endif
  70313. + return;
  70314. +}
  70315. +
  70316. +int
  70317. +gr_handle_signal(const struct task_struct *p, const int sig)
  70318. +{
  70319. +#ifdef CONFIG_GRKERNSEC
  70320. + /* ignore the 0 signal for protected task checks */
  70321. + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
  70322. + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
  70323. + return -EPERM;
  70324. + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
  70325. + return -EPERM;
  70326. + }
  70327. +#endif
  70328. + return 0;
  70329. +}
  70330. +
  70331. +#ifdef CONFIG_GRKERNSEC
  70332. +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
  70333. +
  70334. +int gr_fake_force_sig(int sig, struct task_struct *t)
  70335. +{
  70336. + unsigned long int flags;
  70337. + int ret, blocked, ignored;
  70338. + struct k_sigaction *action;
  70339. +
  70340. + spin_lock_irqsave(&t->sighand->siglock, flags);
  70341. + action = &t->sighand->action[sig-1];
  70342. + ignored = action->sa.sa_handler == SIG_IGN;
  70343. + blocked = sigismember(&t->blocked, sig);
  70344. + if (blocked || ignored) {
  70345. + action->sa.sa_handler = SIG_DFL;
  70346. + if (blocked) {
  70347. + sigdelset(&t->blocked, sig);
  70348. + recalc_sigpending_and_wake(t);
  70349. + }
  70350. + }
  70351. + if (action->sa.sa_handler == SIG_DFL)
  70352. + t->signal->flags &= ~SIGNAL_UNKILLABLE;
  70353. + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
  70354. +
  70355. + spin_unlock_irqrestore(&t->sighand->siglock, flags);
  70356. +
  70357. + return ret;
  70358. +}
  70359. +#endif
  70360. +
  70361. +#define GR_USER_BAN_TIME (15 * 60)
  70362. +#define GR_DAEMON_BRUTE_TIME (30 * 60)
  70363. +
  70364. +void gr_handle_brute_attach(int dumpable)
  70365. +{
  70366. +#ifdef CONFIG_GRKERNSEC_BRUTE
  70367. + struct task_struct *p = current;
  70368. + kuid_t uid = GLOBAL_ROOT_UID;
  70369. + int daemon = 0;
  70370. +
  70371. + if (!grsec_enable_brute)
  70372. + return;
  70373. +
  70374. + rcu_read_lock();
  70375. + read_lock(&tasklist_lock);
  70376. + read_lock(&grsec_exec_file_lock);
  70377. + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
  70378. + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
  70379. + p->real_parent->brute = 1;
  70380. + daemon = 1;
  70381. + } else {
  70382. + const struct cred *cred = __task_cred(p), *cred2;
  70383. + struct task_struct *tsk, *tsk2;
  70384. +
  70385. + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
  70386. + struct user_struct *user;
  70387. +
  70388. + uid = cred->uid;
  70389. +
  70390. + /* this is put upon execution past expiration */
  70391. + user = find_user(uid);
  70392. + if (user == NULL)
  70393. + goto unlock;
  70394. + user->suid_banned = 1;
  70395. + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
  70396. + if (user->suid_ban_expires == ~0UL)
  70397. + user->suid_ban_expires--;
  70398. +
  70399. + /* only kill other threads of the same binary, from the same user */
  70400. + do_each_thread(tsk2, tsk) {
  70401. + cred2 = __task_cred(tsk);
  70402. + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
  70403. + gr_fake_force_sig(SIGKILL, tsk);
  70404. + } while_each_thread(tsk2, tsk);
  70405. + }
  70406. + }
  70407. +unlock:
  70408. + read_unlock(&grsec_exec_file_lock);
  70409. + read_unlock(&tasklist_lock);
  70410. + rcu_read_unlock();
  70411. +
  70412. + if (gr_is_global_nonroot(uid))
  70413. + gr_log_fs_int2(GR_DONT_AUDIT, GR_BRUTE_SUID_MSG, p->exec_file->f_path.dentry, p->exec_file->f_path.mnt, GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
  70414. + else if (daemon)
  70415. + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
  70416. +
  70417. +#endif
  70418. + return;
  70419. +}
  70420. +
  70421. +void gr_handle_brute_check(void)
  70422. +{
  70423. +#ifdef CONFIG_GRKERNSEC_BRUTE
  70424. + struct task_struct *p = current;
  70425. +
  70426. + if (unlikely(p->brute)) {
  70427. + if (!grsec_enable_brute)
  70428. + p->brute = 0;
  70429. + else if (time_before(get_seconds(), p->brute_expires))
  70430. + msleep(30 * 1000);
  70431. + }
  70432. +#endif
  70433. + return;
  70434. +}
  70435. +
  70436. +void gr_handle_kernel_exploit(void)
  70437. +{
  70438. +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
  70439. + const struct cred *cred;
  70440. + struct task_struct *tsk, *tsk2;
  70441. + struct user_struct *user;
  70442. + kuid_t uid;
  70443. +
  70444. + if (in_irq() || in_serving_softirq() || in_nmi())
  70445. + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
  70446. +
  70447. + uid = current_uid();
  70448. +
  70449. + if (gr_is_global_root(uid))
  70450. + panic("grsec: halting the system due to suspicious kernel crash caused by root");
  70451. + else {
  70452. + /* kill all the processes of this user, hold a reference
  70453. + to their creds struct, and prevent them from creating
  70454. + another process until system reset
  70455. + */
  70456. + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
  70457. + GR_GLOBAL_UID(uid));
  70458. + /* we intentionally leak this ref */
  70459. + user = get_uid(current->cred->user);
  70460. + if (user)
  70461. + user->kernel_banned = 1;
  70462. +
  70463. + /* kill all processes of this user */
  70464. + read_lock(&tasklist_lock);
  70465. + do_each_thread(tsk2, tsk) {
  70466. + cred = __task_cred(tsk);
  70467. + if (uid_eq(cred->uid, uid))
  70468. + gr_fake_force_sig(SIGKILL, tsk);
  70469. + } while_each_thread(tsk2, tsk);
  70470. + read_unlock(&tasklist_lock);
  70471. + }
  70472. +#endif
  70473. +}
  70474. +
  70475. +#ifdef CONFIG_GRKERNSEC_BRUTE
  70476. +static bool suid_ban_expired(struct user_struct *user)
  70477. +{
  70478. + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
  70479. + user->suid_banned = 0;
  70480. + user->suid_ban_expires = 0;
  70481. + free_uid(user);
  70482. + return true;
  70483. + }
  70484. +
  70485. + return false;
  70486. +}
  70487. +#endif
  70488. +
  70489. +int gr_process_kernel_exec_ban(void)
  70490. +{
  70491. +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
  70492. + if (unlikely(current->cred->user->kernel_banned))
  70493. + return -EPERM;
  70494. +#endif
  70495. + return 0;
  70496. +}
  70497. +
  70498. +int gr_process_kernel_setuid_ban(struct user_struct *user)
  70499. +{
  70500. +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
  70501. + if (unlikely(user->kernel_banned))
  70502. + gr_fake_force_sig(SIGKILL, current);
  70503. +#endif
  70504. + return 0;
  70505. +}
  70506. +
  70507. +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
  70508. +{
  70509. +#ifdef CONFIG_GRKERNSEC_BRUTE
  70510. + struct user_struct *user = current->cred->user;
  70511. + if (unlikely(user->suid_banned)) {
  70512. + if (suid_ban_expired(user))
  70513. + return 0;
  70514. + /* disallow execution of suid binaries only */
  70515. + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
  70516. + return -EPERM;
  70517. + }
  70518. +#endif
  70519. + return 0;
  70520. +}
  70521. diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
  70522. new file mode 100644
  70523. index 0000000..c0aef3a
  70524. --- /dev/null
  70525. +++ b/grsecurity/grsec_sock.c
  70526. @@ -0,0 +1,244 @@
  70527. +#include <linux/kernel.h>
  70528. +#include <linux/module.h>
  70529. +#include <linux/sched.h>
  70530. +#include <linux/file.h>
  70531. +#include <linux/net.h>
  70532. +#include <linux/in.h>
  70533. +#include <linux/ip.h>
  70534. +#include <net/sock.h>
  70535. +#include <net/inet_sock.h>
  70536. +#include <linux/grsecurity.h>
  70537. +#include <linux/grinternal.h>
  70538. +#include <linux/gracl.h>
  70539. +
  70540. +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
  70541. +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
  70542. +
  70543. +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
  70544. +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
  70545. +
  70546. +#ifdef CONFIG_UNIX_MODULE
  70547. +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
  70548. +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
  70549. +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
  70550. +EXPORT_SYMBOL_GPL(gr_handle_create);
  70551. +#endif
  70552. +
  70553. +#ifdef CONFIG_GRKERNSEC
  70554. +#define gr_conn_table_size 32749
  70555. +struct conn_table_entry {
  70556. + struct conn_table_entry *next;
  70557. + struct signal_struct *sig;
  70558. +};
  70559. +
  70560. +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
  70561. +DEFINE_SPINLOCK(gr_conn_table_lock);
  70562. +
  70563. +extern const char * gr_socktype_to_name(unsigned char type);
  70564. +extern const char * gr_proto_to_name(unsigned char proto);
  70565. +extern const char * gr_sockfamily_to_name(unsigned char family);
  70566. +
  70567. +static __inline__ int
  70568. +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
  70569. +{
  70570. + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
  70571. +}
  70572. +
  70573. +static __inline__ int
  70574. +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
  70575. + __u16 sport, __u16 dport)
  70576. +{
  70577. + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
  70578. + sig->gr_sport == sport && sig->gr_dport == dport))
  70579. + return 1;
  70580. + else
  70581. + return 0;
  70582. +}
  70583. +
  70584. +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
  70585. +{
  70586. + struct conn_table_entry **match;
  70587. + unsigned int index;
  70588. +
  70589. + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
  70590. + sig->gr_sport, sig->gr_dport,
  70591. + gr_conn_table_size);
  70592. +
  70593. + newent->sig = sig;
  70594. +
  70595. + match = &gr_conn_table[index];
  70596. + newent->next = *match;
  70597. + *match = newent;
  70598. +
  70599. + return;
  70600. +}
  70601. +
  70602. +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
  70603. +{
  70604. + struct conn_table_entry *match, *last = NULL;
  70605. + unsigned int index;
  70606. +
  70607. + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
  70608. + sig->gr_sport, sig->gr_dport,
  70609. + gr_conn_table_size);
  70610. +
  70611. + match = gr_conn_table[index];
  70612. + while (match && !conn_match(match->sig,
  70613. + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
  70614. + sig->gr_dport)) {
  70615. + last = match;
  70616. + match = match->next;
  70617. + }
  70618. +
  70619. + if (match) {
  70620. + if (last)
  70621. + last->next = match->next;
  70622. + else
  70623. + gr_conn_table[index] = NULL;
  70624. + kfree(match);
  70625. + }
  70626. +
  70627. + return;
  70628. +}
  70629. +
  70630. +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
  70631. + __u16 sport, __u16 dport)
  70632. +{
  70633. + struct conn_table_entry *match;
  70634. + unsigned int index;
  70635. +
  70636. + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
  70637. +
  70638. + match = gr_conn_table[index];
  70639. + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
  70640. + match = match->next;
  70641. +
  70642. + if (match)
  70643. + return match->sig;
  70644. + else
  70645. + return NULL;
  70646. +}
  70647. +
  70648. +#endif
  70649. +
  70650. +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
  70651. +{
  70652. +#ifdef CONFIG_GRKERNSEC
  70653. + struct signal_struct *sig = task->signal;
  70654. + struct conn_table_entry *newent;
  70655. +
  70656. + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
  70657. + if (newent == NULL)
  70658. + return;
  70659. + /* no bh lock needed since we are called with bh disabled */
  70660. + spin_lock(&gr_conn_table_lock);
  70661. + gr_del_task_from_ip_table_nolock(sig);
  70662. + sig->gr_saddr = inet->inet_rcv_saddr;
  70663. + sig->gr_daddr = inet->inet_daddr;
  70664. + sig->gr_sport = inet->inet_sport;
  70665. + sig->gr_dport = inet->inet_dport;
  70666. + gr_add_to_task_ip_table_nolock(sig, newent);
  70667. + spin_unlock(&gr_conn_table_lock);
  70668. +#endif
  70669. + return;
  70670. +}
  70671. +
  70672. +void gr_del_task_from_ip_table(struct task_struct *task)
  70673. +{
  70674. +#ifdef CONFIG_GRKERNSEC
  70675. + spin_lock_bh(&gr_conn_table_lock);
  70676. + gr_del_task_from_ip_table_nolock(task->signal);
  70677. + spin_unlock_bh(&gr_conn_table_lock);
  70678. +#endif
  70679. + return;
  70680. +}
  70681. +
  70682. +void
  70683. +gr_attach_curr_ip(const struct sock *sk)
  70684. +{
  70685. +#ifdef CONFIG_GRKERNSEC
  70686. + struct signal_struct *p, *set;
  70687. + const struct inet_sock *inet = inet_sk(sk);
  70688. +
  70689. + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
  70690. + return;
  70691. +
  70692. + set = current->signal;
  70693. +
  70694. + spin_lock_bh(&gr_conn_table_lock);
  70695. + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
  70696. + inet->inet_dport, inet->inet_sport);
  70697. + if (unlikely(p != NULL)) {
  70698. + set->curr_ip = p->curr_ip;
  70699. + set->used_accept = 1;
  70700. + gr_del_task_from_ip_table_nolock(p);
  70701. + spin_unlock_bh(&gr_conn_table_lock);
  70702. + return;
  70703. + }
  70704. + spin_unlock_bh(&gr_conn_table_lock);
  70705. +
  70706. + set->curr_ip = inet->inet_daddr;
  70707. + set->used_accept = 1;
  70708. +#endif
  70709. + return;
  70710. +}
  70711. +
  70712. +int
  70713. +gr_handle_sock_all(const int family, const int type, const int protocol)
  70714. +{
  70715. +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
  70716. + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
  70717. + (family != AF_UNIX)) {
  70718. + if (family == AF_INET)
  70719. + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
  70720. + else
  70721. + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
  70722. + return -EACCES;
  70723. + }
  70724. +#endif
  70725. + return 0;
  70726. +}
  70727. +
  70728. +int
  70729. +gr_handle_sock_server(const struct sockaddr *sck)
  70730. +{
  70731. +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
  70732. + if (grsec_enable_socket_server &&
  70733. + in_group_p(grsec_socket_server_gid) &&
  70734. + sck && (sck->sa_family != AF_UNIX) &&
  70735. + (sck->sa_family != AF_LOCAL)) {
  70736. + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
  70737. + return -EACCES;
  70738. + }
  70739. +#endif
  70740. + return 0;
  70741. +}
  70742. +
  70743. +int
  70744. +gr_handle_sock_server_other(const struct sock *sck)
  70745. +{
  70746. +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
  70747. + if (grsec_enable_socket_server &&
  70748. + in_group_p(grsec_socket_server_gid) &&
  70749. + sck && (sck->sk_family != AF_UNIX) &&
  70750. + (sck->sk_family != AF_LOCAL)) {
  70751. + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
  70752. + return -EACCES;
  70753. + }
  70754. +#endif
  70755. + return 0;
  70756. +}
  70757. +
  70758. +int
  70759. +gr_handle_sock_client(const struct sockaddr *sck)
  70760. +{
  70761. +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
  70762. + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
  70763. + sck && (sck->sa_family != AF_UNIX) &&
  70764. + (sck->sa_family != AF_LOCAL)) {
  70765. + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
  70766. + return -EACCES;
  70767. + }
  70768. +#endif
  70769. + return 0;
  70770. +}
  70771. diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
  70772. new file mode 100644
  70773. index 0000000..8159888
  70774. --- /dev/null
  70775. +++ b/grsecurity/grsec_sysctl.c
  70776. @@ -0,0 +1,479 @@
  70777. +#include <linux/kernel.h>
  70778. +#include <linux/sched.h>
  70779. +#include <linux/sysctl.h>
  70780. +#include <linux/grsecurity.h>
  70781. +#include <linux/grinternal.h>
  70782. +
  70783. +int
  70784. +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
  70785. +{
  70786. +#ifdef CONFIG_GRKERNSEC_SYSCTL
  70787. + if (dirname == NULL || name == NULL)
  70788. + return 0;
  70789. + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
  70790. + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
  70791. + return -EACCES;
  70792. + }
  70793. +#endif
  70794. + return 0;
  70795. +}
  70796. +
  70797. +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
  70798. +static int __maybe_unused __read_only one = 1;
  70799. +#endif
  70800. +
  70801. +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
  70802. + defined(CONFIG_GRKERNSEC_DENYUSB)
  70803. +struct ctl_table grsecurity_table[] = {
  70804. +#ifdef CONFIG_GRKERNSEC_SYSCTL
  70805. +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
  70806. +#ifdef CONFIG_GRKERNSEC_IO
  70807. + {
  70808. + .procname = "disable_priv_io",
  70809. + .data = &grsec_disable_privio,
  70810. + .maxlen = sizeof(int),
  70811. + .mode = 0600,
  70812. + .proc_handler = &proc_dointvec,
  70813. + },
  70814. +#endif
  70815. +#endif
  70816. +#ifdef CONFIG_GRKERNSEC_LINK
  70817. + {
  70818. + .procname = "linking_restrictions",
  70819. + .data = &grsec_enable_link,
  70820. + .maxlen = sizeof(int),
  70821. + .mode = 0600,
  70822. + .proc_handler = &proc_dointvec,
  70823. + },
  70824. +#endif
  70825. +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
  70826. + {
  70827. + .procname = "enforce_symlinksifowner",
  70828. + .data = &grsec_enable_symlinkown,
  70829. + .maxlen = sizeof(int),
  70830. + .mode = 0600,
  70831. + .proc_handler = &proc_dointvec,
  70832. + },
  70833. + {
  70834. + .procname = "symlinkown_gid",
  70835. + .data = &grsec_symlinkown_gid,
  70836. + .maxlen = sizeof(int),
  70837. + .mode = 0600,
  70838. + .proc_handler = &proc_dointvec,
  70839. + },
  70840. +#endif
  70841. +#ifdef CONFIG_GRKERNSEC_BRUTE
  70842. + {
  70843. + .procname = "deter_bruteforce",
  70844. + .data = &grsec_enable_brute,
  70845. + .maxlen = sizeof(int),
  70846. + .mode = 0600,
  70847. + .proc_handler = &proc_dointvec,
  70848. + },
  70849. +#endif
  70850. +#ifdef CONFIG_GRKERNSEC_FIFO
  70851. + {
  70852. + .procname = "fifo_restrictions",
  70853. + .data = &grsec_enable_fifo,
  70854. + .maxlen = sizeof(int),
  70855. + .mode = 0600,
  70856. + .proc_handler = &proc_dointvec,
  70857. + },
  70858. +#endif
  70859. +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
  70860. + {
  70861. + .procname = "ptrace_readexec",
  70862. + .data = &grsec_enable_ptrace_readexec,
  70863. + .maxlen = sizeof(int),
  70864. + .mode = 0600,
  70865. + .proc_handler = &proc_dointvec,
  70866. + },
  70867. +#endif
  70868. +#ifdef CONFIG_GRKERNSEC_SETXID
  70869. + {
  70870. + .procname = "consistent_setxid",
  70871. + .data = &grsec_enable_setxid,
  70872. + .maxlen = sizeof(int),
  70873. + .mode = 0600,
  70874. + .proc_handler = &proc_dointvec,
  70875. + },
  70876. +#endif
  70877. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  70878. + {
  70879. + .procname = "ip_blackhole",
  70880. + .data = &grsec_enable_blackhole,
  70881. + .maxlen = sizeof(int),
  70882. + .mode = 0600,
  70883. + .proc_handler = &proc_dointvec,
  70884. + },
  70885. + {
  70886. + .procname = "lastack_retries",
  70887. + .data = &grsec_lastack_retries,
  70888. + .maxlen = sizeof(int),
  70889. + .mode = 0600,
  70890. + .proc_handler = &proc_dointvec,
  70891. + },
  70892. +#endif
  70893. +#ifdef CONFIG_GRKERNSEC_EXECLOG
  70894. + {
  70895. + .procname = "exec_logging",
  70896. + .data = &grsec_enable_execlog,
  70897. + .maxlen = sizeof(int),
  70898. + .mode = 0600,
  70899. + .proc_handler = &proc_dointvec,
  70900. + },
  70901. +#endif
  70902. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  70903. + {
  70904. + .procname = "rwxmap_logging",
  70905. + .data = &grsec_enable_log_rwxmaps,
  70906. + .maxlen = sizeof(int),
  70907. + .mode = 0600,
  70908. + .proc_handler = &proc_dointvec,
  70909. + },
  70910. +#endif
  70911. +#ifdef CONFIG_GRKERNSEC_SIGNAL
  70912. + {
  70913. + .procname = "signal_logging",
  70914. + .data = &grsec_enable_signal,
  70915. + .maxlen = sizeof(int),
  70916. + .mode = 0600,
  70917. + .proc_handler = &proc_dointvec,
  70918. + },
  70919. +#endif
  70920. +#ifdef CONFIG_GRKERNSEC_FORKFAIL
  70921. + {
  70922. + .procname = "forkfail_logging",
  70923. + .data = &grsec_enable_forkfail,
  70924. + .maxlen = sizeof(int),
  70925. + .mode = 0600,
  70926. + .proc_handler = &proc_dointvec,
  70927. + },
  70928. +#endif
  70929. +#ifdef CONFIG_GRKERNSEC_TIME
  70930. + {
  70931. + .procname = "timechange_logging",
  70932. + .data = &grsec_enable_time,
  70933. + .maxlen = sizeof(int),
  70934. + .mode = 0600,
  70935. + .proc_handler = &proc_dointvec,
  70936. + },
  70937. +#endif
  70938. +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
  70939. + {
  70940. + .procname = "chroot_deny_shmat",
  70941. + .data = &grsec_enable_chroot_shmat,
  70942. + .maxlen = sizeof(int),
  70943. + .mode = 0600,
  70944. + .proc_handler = &proc_dointvec,
  70945. + },
  70946. +#endif
  70947. +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
  70948. + {
  70949. + .procname = "chroot_deny_unix",
  70950. + .data = &grsec_enable_chroot_unix,
  70951. + .maxlen = sizeof(int),
  70952. + .mode = 0600,
  70953. + .proc_handler = &proc_dointvec,
  70954. + },
  70955. +#endif
  70956. +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
  70957. + {
  70958. + .procname = "chroot_deny_mount",
  70959. + .data = &grsec_enable_chroot_mount,
  70960. + .maxlen = sizeof(int),
  70961. + .mode = 0600,
  70962. + .proc_handler = &proc_dointvec,
  70963. + },
  70964. +#endif
  70965. +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
  70966. + {
  70967. + .procname = "chroot_deny_fchdir",
  70968. + .data = &grsec_enable_chroot_fchdir,
  70969. + .maxlen = sizeof(int),
  70970. + .mode = 0600,
  70971. + .proc_handler = &proc_dointvec,
  70972. + },
  70973. +#endif
  70974. +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
  70975. + {
  70976. + .procname = "chroot_deny_chroot",
  70977. + .data = &grsec_enable_chroot_double,
  70978. + .maxlen = sizeof(int),
  70979. + .mode = 0600,
  70980. + .proc_handler = &proc_dointvec,
  70981. + },
  70982. +#endif
  70983. +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
  70984. + {
  70985. + .procname = "chroot_deny_pivot",
  70986. + .data = &grsec_enable_chroot_pivot,
  70987. + .maxlen = sizeof(int),
  70988. + .mode = 0600,
  70989. + .proc_handler = &proc_dointvec,
  70990. + },
  70991. +#endif
  70992. +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
  70993. + {
  70994. + .procname = "chroot_enforce_chdir",
  70995. + .data = &grsec_enable_chroot_chdir,
  70996. + .maxlen = sizeof(int),
  70997. + .mode = 0600,
  70998. + .proc_handler = &proc_dointvec,
  70999. + },
  71000. +#endif
  71001. +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
  71002. + {
  71003. + .procname = "chroot_deny_chmod",
  71004. + .data = &grsec_enable_chroot_chmod,
  71005. + .maxlen = sizeof(int),
  71006. + .mode = 0600,
  71007. + .proc_handler = &proc_dointvec,
  71008. + },
  71009. +#endif
  71010. +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
  71011. + {
  71012. + .procname = "chroot_deny_mknod",
  71013. + .data = &grsec_enable_chroot_mknod,
  71014. + .maxlen = sizeof(int),
  71015. + .mode = 0600,
  71016. + .proc_handler = &proc_dointvec,
  71017. + },
  71018. +#endif
  71019. +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
  71020. + {
  71021. + .procname = "chroot_restrict_nice",
  71022. + .data = &grsec_enable_chroot_nice,
  71023. + .maxlen = sizeof(int),
  71024. + .mode = 0600,
  71025. + .proc_handler = &proc_dointvec,
  71026. + },
  71027. +#endif
  71028. +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
  71029. + {
  71030. + .procname = "chroot_execlog",
  71031. + .data = &grsec_enable_chroot_execlog,
  71032. + .maxlen = sizeof(int),
  71033. + .mode = 0600,
  71034. + .proc_handler = &proc_dointvec,
  71035. + },
  71036. +#endif
  71037. +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
  71038. + {
  71039. + .procname = "chroot_caps",
  71040. + .data = &grsec_enable_chroot_caps,
  71041. + .maxlen = sizeof(int),
  71042. + .mode = 0600,
  71043. + .proc_handler = &proc_dointvec,
  71044. + },
  71045. +#endif
  71046. +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
  71047. + {
  71048. + .procname = "chroot_deny_sysctl",
  71049. + .data = &grsec_enable_chroot_sysctl,
  71050. + .maxlen = sizeof(int),
  71051. + .mode = 0600,
  71052. + .proc_handler = &proc_dointvec,
  71053. + },
  71054. +#endif
  71055. +#ifdef CONFIG_GRKERNSEC_TPE
  71056. + {
  71057. + .procname = "tpe",
  71058. + .data = &grsec_enable_tpe,
  71059. + .maxlen = sizeof(int),
  71060. + .mode = 0600,
  71061. + .proc_handler = &proc_dointvec,
  71062. + },
  71063. + {
  71064. + .procname = "tpe_gid",
  71065. + .data = &grsec_tpe_gid,
  71066. + .maxlen = sizeof(int),
  71067. + .mode = 0600,
  71068. + .proc_handler = &proc_dointvec,
  71069. + },
  71070. +#endif
  71071. +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
  71072. + {
  71073. + .procname = "tpe_invert",
  71074. + .data = &grsec_enable_tpe_invert,
  71075. + .maxlen = sizeof(int),
  71076. + .mode = 0600,
  71077. + .proc_handler = &proc_dointvec,
  71078. + },
  71079. +#endif
  71080. +#ifdef CONFIG_GRKERNSEC_TPE_ALL
  71081. + {
  71082. + .procname = "tpe_restrict_all",
  71083. + .data = &grsec_enable_tpe_all,
  71084. + .maxlen = sizeof(int),
  71085. + .mode = 0600,
  71086. + .proc_handler = &proc_dointvec,
  71087. + },
  71088. +#endif
  71089. +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
  71090. + {
  71091. + .procname = "socket_all",
  71092. + .data = &grsec_enable_socket_all,
  71093. + .maxlen = sizeof(int),
  71094. + .mode = 0600,
  71095. + .proc_handler = &proc_dointvec,
  71096. + },
  71097. + {
  71098. + .procname = "socket_all_gid",
  71099. + .data = &grsec_socket_all_gid,
  71100. + .maxlen = sizeof(int),
  71101. + .mode = 0600,
  71102. + .proc_handler = &proc_dointvec,
  71103. + },
  71104. +#endif
  71105. +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
  71106. + {
  71107. + .procname = "socket_client",
  71108. + .data = &grsec_enable_socket_client,
  71109. + .maxlen = sizeof(int),
  71110. + .mode = 0600,
  71111. + .proc_handler = &proc_dointvec,
  71112. + },
  71113. + {
  71114. + .procname = "socket_client_gid",
  71115. + .data = &grsec_socket_client_gid,
  71116. + .maxlen = sizeof(int),
  71117. + .mode = 0600,
  71118. + .proc_handler = &proc_dointvec,
  71119. + },
  71120. +#endif
  71121. +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
  71122. + {
  71123. + .procname = "socket_server",
  71124. + .data = &grsec_enable_socket_server,
  71125. + .maxlen = sizeof(int),
  71126. + .mode = 0600,
  71127. + .proc_handler = &proc_dointvec,
  71128. + },
  71129. + {
  71130. + .procname = "socket_server_gid",
  71131. + .data = &grsec_socket_server_gid,
  71132. + .maxlen = sizeof(int),
  71133. + .mode = 0600,
  71134. + .proc_handler = &proc_dointvec,
  71135. + },
  71136. +#endif
  71137. +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
  71138. + {
  71139. + .procname = "audit_group",
  71140. + .data = &grsec_enable_group,
  71141. + .maxlen = sizeof(int),
  71142. + .mode = 0600,
  71143. + .proc_handler = &proc_dointvec,
  71144. + },
  71145. + {
  71146. + .procname = "audit_gid",
  71147. + .data = &grsec_audit_gid,
  71148. + .maxlen = sizeof(int),
  71149. + .mode = 0600,
  71150. + .proc_handler = &proc_dointvec,
  71151. + },
  71152. +#endif
  71153. +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
  71154. + {
  71155. + .procname = "audit_chdir",
  71156. + .data = &grsec_enable_chdir,
  71157. + .maxlen = sizeof(int),
  71158. + .mode = 0600,
  71159. + .proc_handler = &proc_dointvec,
  71160. + },
  71161. +#endif
  71162. +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
  71163. + {
  71164. + .procname = "audit_mount",
  71165. + .data = &grsec_enable_mount,
  71166. + .maxlen = sizeof(int),
  71167. + .mode = 0600,
  71168. + .proc_handler = &proc_dointvec,
  71169. + },
  71170. +#endif
  71171. +#ifdef CONFIG_GRKERNSEC_DMESG
  71172. + {
  71173. + .procname = "dmesg",
  71174. + .data = &grsec_enable_dmesg,
  71175. + .maxlen = sizeof(int),
  71176. + .mode = 0600,
  71177. + .proc_handler = &proc_dointvec,
  71178. + },
  71179. +#endif
  71180. +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
  71181. + {
  71182. + .procname = "chroot_findtask",
  71183. + .data = &grsec_enable_chroot_findtask,
  71184. + .maxlen = sizeof(int),
  71185. + .mode = 0600,
  71186. + .proc_handler = &proc_dointvec,
  71187. + },
  71188. +#endif
  71189. +#ifdef CONFIG_GRKERNSEC_RESLOG
  71190. + {
  71191. + .procname = "resource_logging",
  71192. + .data = &grsec_resource_logging,
  71193. + .maxlen = sizeof(int),
  71194. + .mode = 0600,
  71195. + .proc_handler = &proc_dointvec,
  71196. + },
  71197. +#endif
  71198. +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
  71199. + {
  71200. + .procname = "audit_ptrace",
  71201. + .data = &grsec_enable_audit_ptrace,
  71202. + .maxlen = sizeof(int),
  71203. + .mode = 0600,
  71204. + .proc_handler = &proc_dointvec,
  71205. + },
  71206. +#endif
  71207. +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
  71208. + {
  71209. + .procname = "harden_ptrace",
  71210. + .data = &grsec_enable_harden_ptrace,
  71211. + .maxlen = sizeof(int),
  71212. + .mode = 0600,
  71213. + .proc_handler = &proc_dointvec,
  71214. + },
  71215. +#endif
  71216. +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
  71217. + {
  71218. + .procname = "harden_ipc",
  71219. + .data = &grsec_enable_harden_ipc,
  71220. + .maxlen = sizeof(int),
  71221. + .mode = 0600,
  71222. + .proc_handler = &proc_dointvec,
  71223. + },
  71224. +#endif
  71225. + {
  71226. + .procname = "grsec_lock",
  71227. + .data = &grsec_lock,
  71228. + .maxlen = sizeof(int),
  71229. + .mode = 0600,
  71230. + .proc_handler = &proc_dointvec,
  71231. + },
  71232. +#endif
  71233. +#ifdef CONFIG_GRKERNSEC_ROFS
  71234. + {
  71235. + .procname = "romount_protect",
  71236. + .data = &grsec_enable_rofs,
  71237. + .maxlen = sizeof(int),
  71238. + .mode = 0600,
  71239. + .proc_handler = &proc_dointvec_minmax,
  71240. + .extra1 = &one,
  71241. + .extra2 = &one,
  71242. + },
  71243. +#endif
  71244. +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
  71245. + {
  71246. + .procname = "deny_new_usb",
  71247. + .data = &grsec_deny_new_usb,
  71248. + .maxlen = sizeof(int),
  71249. + .mode = 0600,
  71250. + .proc_handler = &proc_dointvec,
  71251. + },
  71252. +#endif
  71253. + { }
  71254. +};
  71255. +#endif
  71256. diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
  71257. new file mode 100644
  71258. index 0000000..61b514e
  71259. --- /dev/null
  71260. +++ b/grsecurity/grsec_time.c
  71261. @@ -0,0 +1,16 @@
  71262. +#include <linux/kernel.h>
  71263. +#include <linux/sched.h>
  71264. +#include <linux/grinternal.h>
  71265. +#include <linux/module.h>
  71266. +
  71267. +void
  71268. +gr_log_timechange(void)
  71269. +{
  71270. +#ifdef CONFIG_GRKERNSEC_TIME
  71271. + if (grsec_enable_time)
  71272. + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
  71273. +#endif
  71274. + return;
  71275. +}
  71276. +
  71277. +EXPORT_SYMBOL_GPL(gr_log_timechange);
  71278. diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
  71279. new file mode 100644
  71280. index 0000000..ee57dcf
  71281. --- /dev/null
  71282. +++ b/grsecurity/grsec_tpe.c
  71283. @@ -0,0 +1,73 @@
  71284. +#include <linux/kernel.h>
  71285. +#include <linux/sched.h>
  71286. +#include <linux/file.h>
  71287. +#include <linux/fs.h>
  71288. +#include <linux/grinternal.h>
  71289. +
  71290. +extern int gr_acl_tpe_check(void);
  71291. +
  71292. +int
  71293. +gr_tpe_allow(const struct file *file)
  71294. +{
  71295. +#ifdef CONFIG_GRKERNSEC
  71296. + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
  71297. + const struct cred *cred = current_cred();
  71298. + char *msg = NULL;
  71299. + char *msg2 = NULL;
  71300. +
  71301. + // never restrict root
  71302. + if (gr_is_global_root(cred->uid))
  71303. + return 1;
  71304. +
  71305. + if (grsec_enable_tpe) {
  71306. +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
  71307. + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
  71308. + msg = "not being in trusted group";
  71309. + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
  71310. + msg = "being in untrusted group";
  71311. +#else
  71312. + if (in_group_p(grsec_tpe_gid))
  71313. + msg = "being in untrusted group";
  71314. +#endif
  71315. + }
  71316. + if (!msg && gr_acl_tpe_check())
  71317. + msg = "being in untrusted role";
  71318. +
  71319. + // not in any affected group/role
  71320. + if (!msg)
  71321. + goto next_check;
  71322. +
  71323. + if (gr_is_global_nonroot(inode->i_uid))
  71324. + msg2 = "file in non-root-owned directory";
  71325. + else if (inode->i_mode & S_IWOTH)
  71326. + msg2 = "file in world-writable directory";
  71327. + else if (inode->i_mode & S_IWGRP)
  71328. + msg2 = "file in group-writable directory";
  71329. +
  71330. + if (msg && msg2) {
  71331. + char fullmsg[70] = {0};
  71332. + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
  71333. + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
  71334. + return 0;
  71335. + }
  71336. + msg = NULL;
  71337. +next_check:
  71338. +#ifdef CONFIG_GRKERNSEC_TPE_ALL
  71339. + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
  71340. + return 1;
  71341. +
  71342. + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
  71343. + msg = "directory not owned by user";
  71344. + else if (inode->i_mode & S_IWOTH)
  71345. + msg = "file in world-writable directory";
  71346. + else if (inode->i_mode & S_IWGRP)
  71347. + msg = "file in group-writable directory";
  71348. +
  71349. + if (msg) {
  71350. + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
  71351. + return 0;
  71352. + }
  71353. +#endif
  71354. +#endif
  71355. + return 1;
  71356. +}
  71357. diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
  71358. new file mode 100644
  71359. index 0000000..ae02d8e
  71360. --- /dev/null
  71361. +++ b/grsecurity/grsec_usb.c
  71362. @@ -0,0 +1,15 @@
  71363. +#include <linux/kernel.h>
  71364. +#include <linux/grinternal.h>
  71365. +#include <linux/module.h>
  71366. +
  71367. +int gr_handle_new_usb(void)
  71368. +{
  71369. +#ifdef CONFIG_GRKERNSEC_DENYUSB
  71370. + if (grsec_deny_new_usb) {
  71371. + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
  71372. + return 1;
  71373. + }
  71374. +#endif
  71375. + return 0;
  71376. +}
  71377. +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
  71378. diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
  71379. new file mode 100644
  71380. index 0000000..9f7b1ac
  71381. --- /dev/null
  71382. +++ b/grsecurity/grsum.c
  71383. @@ -0,0 +1,61 @@
  71384. +#include <linux/err.h>
  71385. +#include <linux/kernel.h>
  71386. +#include <linux/sched.h>
  71387. +#include <linux/mm.h>
  71388. +#include <linux/scatterlist.h>
  71389. +#include <linux/crypto.h>
  71390. +#include <linux/gracl.h>
  71391. +
  71392. +
  71393. +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
  71394. +#error "crypto and sha256 must be built into the kernel"
  71395. +#endif
  71396. +
  71397. +int
  71398. +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
  71399. +{
  71400. + char *p;
  71401. + struct crypto_hash *tfm;
  71402. + struct hash_desc desc;
  71403. + struct scatterlist sg;
  71404. + unsigned char temp_sum[GR_SHA_LEN];
  71405. + volatile int retval = 0;
  71406. + volatile int dummy = 0;
  71407. + unsigned int i;
  71408. +
  71409. + sg_init_table(&sg, 1);
  71410. +
  71411. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  71412. + if (IS_ERR(tfm)) {
  71413. + /* should never happen, since sha256 should be built in */
  71414. + return 1;
  71415. + }
  71416. +
  71417. + desc.tfm = tfm;
  71418. + desc.flags = 0;
  71419. +
  71420. + crypto_hash_init(&desc);
  71421. +
  71422. + p = salt;
  71423. + sg_set_buf(&sg, p, GR_SALT_LEN);
  71424. + crypto_hash_update(&desc, &sg, sg.length);
  71425. +
  71426. + p = entry->pw;
  71427. + sg_set_buf(&sg, p, strlen(p));
  71428. +
  71429. + crypto_hash_update(&desc, &sg, sg.length);
  71430. +
  71431. + crypto_hash_final(&desc, temp_sum);
  71432. +
  71433. + memset(entry->pw, 0, GR_PW_LEN);
  71434. +
  71435. + for (i = 0; i < GR_SHA_LEN; i++)
  71436. + if (sum[i] != temp_sum[i])
  71437. + retval = 1;
  71438. + else
  71439. + dummy = 1; // waste a cycle
  71440. +
  71441. + crypto_free_hash(tfm);
  71442. +
  71443. + return retval;
  71444. +}
  71445. diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
  71446. index 77ff547..181834f 100644
  71447. --- a/include/asm-generic/4level-fixup.h
  71448. +++ b/include/asm-generic/4level-fixup.h
  71449. @@ -13,8 +13,10 @@
  71450. #define pmd_alloc(mm, pud, address) \
  71451. ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
  71452. NULL: pmd_offset(pud, address))
  71453. +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
  71454. #define pud_alloc(mm, pgd, address) (pgd)
  71455. +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
  71456. #define pud_offset(pgd, start) (pgd)
  71457. #define pud_none(pud) 0
  71458. #define pud_bad(pud) 0
  71459. diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
  71460. index b7babf0..97f4c4f 100644
  71461. --- a/include/asm-generic/atomic-long.h
  71462. +++ b/include/asm-generic/atomic-long.h
  71463. @@ -22,6 +22,12 @@
  71464. typedef atomic64_t atomic_long_t;
  71465. +#ifdef CONFIG_PAX_REFCOUNT
  71466. +typedef atomic64_unchecked_t atomic_long_unchecked_t;
  71467. +#else
  71468. +typedef atomic64_t atomic_long_unchecked_t;
  71469. +#endif
  71470. +
  71471. #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
  71472. static inline long atomic_long_read(atomic_long_t *l)
  71473. @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
  71474. return (long)atomic64_read(v);
  71475. }
  71476. +#ifdef CONFIG_PAX_REFCOUNT
  71477. +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
  71478. +{
  71479. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71480. +
  71481. + return (long)atomic64_read_unchecked(v);
  71482. +}
  71483. +#endif
  71484. +
  71485. static inline void atomic_long_set(atomic_long_t *l, long i)
  71486. {
  71487. atomic64_t *v = (atomic64_t *)l;
  71488. @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
  71489. atomic64_set(v, i);
  71490. }
  71491. +#ifdef CONFIG_PAX_REFCOUNT
  71492. +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
  71493. +{
  71494. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71495. +
  71496. + atomic64_set_unchecked(v, i);
  71497. +}
  71498. +#endif
  71499. +
  71500. static inline void atomic_long_inc(atomic_long_t *l)
  71501. {
  71502. atomic64_t *v = (atomic64_t *)l;
  71503. @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
  71504. atomic64_inc(v);
  71505. }
  71506. +#ifdef CONFIG_PAX_REFCOUNT
  71507. +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
  71508. +{
  71509. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71510. +
  71511. + atomic64_inc_unchecked(v);
  71512. +}
  71513. +#endif
  71514. +
  71515. static inline void atomic_long_dec(atomic_long_t *l)
  71516. {
  71517. atomic64_t *v = (atomic64_t *)l;
  71518. @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
  71519. atomic64_dec(v);
  71520. }
  71521. +#ifdef CONFIG_PAX_REFCOUNT
  71522. +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
  71523. +{
  71524. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71525. +
  71526. + atomic64_dec_unchecked(v);
  71527. +}
  71528. +#endif
  71529. +
  71530. static inline void atomic_long_add(long i, atomic_long_t *l)
  71531. {
  71532. atomic64_t *v = (atomic64_t *)l;
  71533. @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
  71534. atomic64_add(i, v);
  71535. }
  71536. +#ifdef CONFIG_PAX_REFCOUNT
  71537. +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
  71538. +{
  71539. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71540. +
  71541. + atomic64_add_unchecked(i, v);
  71542. +}
  71543. +#endif
  71544. +
  71545. static inline void atomic_long_sub(long i, atomic_long_t *l)
  71546. {
  71547. atomic64_t *v = (atomic64_t *)l;
  71548. @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
  71549. atomic64_sub(i, v);
  71550. }
  71551. +#ifdef CONFIG_PAX_REFCOUNT
  71552. +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
  71553. +{
  71554. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71555. +
  71556. + atomic64_sub_unchecked(i, v);
  71557. +}
  71558. +#endif
  71559. +
  71560. static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
  71561. {
  71562. atomic64_t *v = (atomic64_t *)l;
  71563. @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
  71564. return atomic64_add_negative(i, v);
  71565. }
  71566. -static inline long atomic_long_add_return(long i, atomic_long_t *l)
  71567. +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
  71568. {
  71569. atomic64_t *v = (atomic64_t *)l;
  71570. return (long)atomic64_add_return(i, v);
  71571. }
  71572. +#ifdef CONFIG_PAX_REFCOUNT
  71573. +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
  71574. +{
  71575. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71576. +
  71577. + return (long)atomic64_add_return_unchecked(i, v);
  71578. +}
  71579. +#endif
  71580. +
  71581. static inline long atomic_long_sub_return(long i, atomic_long_t *l)
  71582. {
  71583. atomic64_t *v = (atomic64_t *)l;
  71584. @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
  71585. return (long)atomic64_inc_return(v);
  71586. }
  71587. +#ifdef CONFIG_PAX_REFCOUNT
  71588. +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
  71589. +{
  71590. + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
  71591. +
  71592. + return (long)atomic64_inc_return_unchecked(v);
  71593. +}
  71594. +#endif
  71595. +
  71596. static inline long atomic_long_dec_return(atomic_long_t *l)
  71597. {
  71598. atomic64_t *v = (atomic64_t *)l;
  71599. @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
  71600. typedef atomic_t atomic_long_t;
  71601. +#ifdef CONFIG_PAX_REFCOUNT
  71602. +typedef atomic_unchecked_t atomic_long_unchecked_t;
  71603. +#else
  71604. +typedef atomic_t atomic_long_unchecked_t;
  71605. +#endif
  71606. +
  71607. #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
  71608. static inline long atomic_long_read(atomic_long_t *l)
  71609. {
  71610. @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
  71611. return (long)atomic_read(v);
  71612. }
  71613. +#ifdef CONFIG_PAX_REFCOUNT
  71614. +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
  71615. +{
  71616. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71617. +
  71618. + return (long)atomic_read_unchecked(v);
  71619. +}
  71620. +#endif
  71621. +
  71622. static inline void atomic_long_set(atomic_long_t *l, long i)
  71623. {
  71624. atomic_t *v = (atomic_t *)l;
  71625. @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
  71626. atomic_set(v, i);
  71627. }
  71628. +#ifdef CONFIG_PAX_REFCOUNT
  71629. +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
  71630. +{
  71631. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71632. +
  71633. + atomic_set_unchecked(v, i);
  71634. +}
  71635. +#endif
  71636. +
  71637. static inline void atomic_long_inc(atomic_long_t *l)
  71638. {
  71639. atomic_t *v = (atomic_t *)l;
  71640. @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
  71641. atomic_inc(v);
  71642. }
  71643. +#ifdef CONFIG_PAX_REFCOUNT
  71644. +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
  71645. +{
  71646. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71647. +
  71648. + atomic_inc_unchecked(v);
  71649. +}
  71650. +#endif
  71651. +
  71652. static inline void atomic_long_dec(atomic_long_t *l)
  71653. {
  71654. atomic_t *v = (atomic_t *)l;
  71655. @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
  71656. atomic_dec(v);
  71657. }
  71658. +#ifdef CONFIG_PAX_REFCOUNT
  71659. +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
  71660. +{
  71661. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71662. +
  71663. + atomic_dec_unchecked(v);
  71664. +}
  71665. +#endif
  71666. +
  71667. static inline void atomic_long_add(long i, atomic_long_t *l)
  71668. {
  71669. atomic_t *v = (atomic_t *)l;
  71670. @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
  71671. atomic_add(i, v);
  71672. }
  71673. +#ifdef CONFIG_PAX_REFCOUNT
  71674. +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
  71675. +{
  71676. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71677. +
  71678. + atomic_add_unchecked(i, v);
  71679. +}
  71680. +#endif
  71681. +
  71682. static inline void atomic_long_sub(long i, atomic_long_t *l)
  71683. {
  71684. atomic_t *v = (atomic_t *)l;
  71685. @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
  71686. atomic_sub(i, v);
  71687. }
  71688. +#ifdef CONFIG_PAX_REFCOUNT
  71689. +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
  71690. +{
  71691. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71692. +
  71693. + atomic_sub_unchecked(i, v);
  71694. +}
  71695. +#endif
  71696. +
  71697. static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
  71698. {
  71699. atomic_t *v = (atomic_t *)l;
  71700. @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
  71701. return (long)atomic_add_return(i, v);
  71702. }
  71703. +#ifdef CONFIG_PAX_REFCOUNT
  71704. +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
  71705. +{
  71706. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71707. +
  71708. + return (long)atomic_add_return_unchecked(i, v);
  71709. +}
  71710. +
  71711. +#endif
  71712. +
  71713. static inline long atomic_long_sub_return(long i, atomic_long_t *l)
  71714. {
  71715. atomic_t *v = (atomic_t *)l;
  71716. @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
  71717. return (long)atomic_inc_return(v);
  71718. }
  71719. +#ifdef CONFIG_PAX_REFCOUNT
  71720. +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
  71721. +{
  71722. + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
  71723. +
  71724. + return (long)atomic_inc_return_unchecked(v);
  71725. +}
  71726. +#endif
  71727. +
  71728. static inline long atomic_long_dec_return(atomic_long_t *l)
  71729. {
  71730. atomic_t *v = (atomic_t *)l;
  71731. @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
  71732. #endif /* BITS_PER_LONG == 64 */
  71733. +#ifdef CONFIG_PAX_REFCOUNT
  71734. +static inline void pax_refcount_needs_these_functions(void)
  71735. +{
  71736. + atomic_read_unchecked((atomic_unchecked_t *)NULL);
  71737. + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
  71738. + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
  71739. + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
  71740. + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
  71741. + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
  71742. + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
  71743. + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
  71744. + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
  71745. + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
  71746. + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
  71747. +#ifdef CONFIG_X86
  71748. + atomic_clear_mask_unchecked(0, NULL);
  71749. + atomic_set_mask_unchecked(0, NULL);
  71750. +#endif
  71751. +
  71752. + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
  71753. + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
  71754. + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
  71755. + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
  71756. + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
  71757. + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
  71758. + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
  71759. + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
  71760. +}
  71761. +#else
  71762. +#define atomic_read_unchecked(v) atomic_read(v)
  71763. +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
  71764. +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
  71765. +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
  71766. +#define atomic_inc_unchecked(v) atomic_inc(v)
  71767. +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
  71768. +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
  71769. +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
  71770. +#define atomic_dec_unchecked(v) atomic_dec(v)
  71771. +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
  71772. +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
  71773. +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
  71774. +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
  71775. +
  71776. +#define atomic_long_read_unchecked(v) atomic_long_read(v)
  71777. +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
  71778. +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
  71779. +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
  71780. +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
  71781. +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
  71782. +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
  71783. +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
  71784. +#endif
  71785. +
  71786. #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
  71787. diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
  71788. index 33bd2de..f31bff97 100644
  71789. --- a/include/asm-generic/atomic.h
  71790. +++ b/include/asm-generic/atomic.h
  71791. @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  71792. * Atomically clears the bits set in @mask from @v
  71793. */
  71794. #ifndef atomic_clear_mask
  71795. -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
  71796. +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
  71797. {
  71798. unsigned long flags;
  71799. diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
  71800. index b18ce4f..2ee2843 100644
  71801. --- a/include/asm-generic/atomic64.h
  71802. +++ b/include/asm-generic/atomic64.h
  71803. @@ -16,6 +16,8 @@ typedef struct {
  71804. long long counter;
  71805. } atomic64_t;
  71806. +typedef atomic64_t atomic64_unchecked_t;
  71807. +
  71808. #define ATOMIC64_INIT(i) { (i) }
  71809. extern long long atomic64_read(const atomic64_t *v);
  71810. @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
  71811. #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
  71812. #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
  71813. +#define atomic64_read_unchecked(v) atomic64_read(v)
  71814. +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
  71815. +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
  71816. +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
  71817. +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
  71818. +#define atomic64_inc_unchecked(v) atomic64_inc(v)
  71819. +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
  71820. +#define atomic64_dec_unchecked(v) atomic64_dec(v)
  71821. +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
  71822. +
  71823. #endif /* _ASM_GENERIC_ATOMIC64_H */
  71824. diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
  71825. index a60a7cc..0fe12f2 100644
  71826. --- a/include/asm-generic/bitops/__fls.h
  71827. +++ b/include/asm-generic/bitops/__fls.h
  71828. @@ -9,7 +9,7 @@
  71829. *
  71830. * Undefined if no set bit exists, so code should check against 0 first.
  71831. */
  71832. -static __always_inline unsigned long __fls(unsigned long word)
  71833. +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
  71834. {
  71835. int num = BITS_PER_LONG - 1;
  71836. diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
  71837. index 0576d1f..dad6c71 100644
  71838. --- a/include/asm-generic/bitops/fls.h
  71839. +++ b/include/asm-generic/bitops/fls.h
  71840. @@ -9,7 +9,7 @@
  71841. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  71842. */
  71843. -static __always_inline int fls(int x)
  71844. +static __always_inline int __intentional_overflow(-1) fls(int x)
  71845. {
  71846. int r = 32;
  71847. diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
  71848. index b097cf8..3d40e14 100644
  71849. --- a/include/asm-generic/bitops/fls64.h
  71850. +++ b/include/asm-generic/bitops/fls64.h
  71851. @@ -15,7 +15,7 @@
  71852. * at position 64.
  71853. */
  71854. #if BITS_PER_LONG == 32
  71855. -static __always_inline int fls64(__u64 x)
  71856. +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
  71857. {
  71858. __u32 h = x >> 32;
  71859. if (h)
  71860. @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
  71861. return fls(x);
  71862. }
  71863. #elif BITS_PER_LONG == 64
  71864. -static __always_inline int fls64(__u64 x)
  71865. +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
  71866. {
  71867. if (x == 0)
  71868. return 0;
  71869. diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
  71870. index 1bfcfe5..e04c5c9 100644
  71871. --- a/include/asm-generic/cache.h
  71872. +++ b/include/asm-generic/cache.h
  71873. @@ -6,7 +6,7 @@
  71874. * cache lines need to provide their own cache.h.
  71875. */
  71876. -#define L1_CACHE_SHIFT 5
  71877. -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  71878. +#define L1_CACHE_SHIFT 5UL
  71879. +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
  71880. #endif /* __ASM_GENERIC_CACHE_H */
  71881. diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
  71882. index 0d68a1e..b74a761 100644
  71883. --- a/include/asm-generic/emergency-restart.h
  71884. +++ b/include/asm-generic/emergency-restart.h
  71885. @@ -1,7 +1,7 @@
  71886. #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
  71887. #define _ASM_GENERIC_EMERGENCY_RESTART_H
  71888. -static inline void machine_emergency_restart(void)
  71889. +static inline __noreturn void machine_emergency_restart(void)
  71890. {
  71891. machine_restart(NULL);
  71892. }
  71893. diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
  71894. index 90f99c7..00ce236 100644
  71895. --- a/include/asm-generic/kmap_types.h
  71896. +++ b/include/asm-generic/kmap_types.h
  71897. @@ -2,9 +2,9 @@
  71898. #define _ASM_GENERIC_KMAP_TYPES_H
  71899. #ifdef __WITH_KM_FENCE
  71900. -# define KM_TYPE_NR 41
  71901. +# define KM_TYPE_NR 42
  71902. #else
  71903. -# define KM_TYPE_NR 20
  71904. +# define KM_TYPE_NR 21
  71905. #endif
  71906. #endif
  71907. diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
  71908. index 9ceb03b..62b0b8f 100644
  71909. --- a/include/asm-generic/local.h
  71910. +++ b/include/asm-generic/local.h
  71911. @@ -23,24 +23,37 @@ typedef struct
  71912. atomic_long_t a;
  71913. } local_t;
  71914. +typedef struct {
  71915. + atomic_long_unchecked_t a;
  71916. +} local_unchecked_t;
  71917. +
  71918. #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
  71919. #define local_read(l) atomic_long_read(&(l)->a)
  71920. +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
  71921. #define local_set(l,i) atomic_long_set((&(l)->a),(i))
  71922. +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
  71923. #define local_inc(l) atomic_long_inc(&(l)->a)
  71924. +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
  71925. #define local_dec(l) atomic_long_dec(&(l)->a)
  71926. +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
  71927. #define local_add(i,l) atomic_long_add((i),(&(l)->a))
  71928. +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
  71929. #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
  71930. +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
  71931. #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
  71932. #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
  71933. #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
  71934. #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
  71935. #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
  71936. +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
  71937. #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
  71938. #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
  71939. +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
  71940. #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
  71941. +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
  71942. #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
  71943. #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
  71944. #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
  71945. diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
  71946. index 725612b..9cc513a 100644
  71947. --- a/include/asm-generic/pgtable-nopmd.h
  71948. +++ b/include/asm-generic/pgtable-nopmd.h
  71949. @@ -1,14 +1,19 @@
  71950. #ifndef _PGTABLE_NOPMD_H
  71951. #define _PGTABLE_NOPMD_H
  71952. -#ifndef __ASSEMBLY__
  71953. -
  71954. #include <asm-generic/pgtable-nopud.h>
  71955. -struct mm_struct;
  71956. -
  71957. #define __PAGETABLE_PMD_FOLDED
  71958. +#define PMD_SHIFT PUD_SHIFT
  71959. +#define PTRS_PER_PMD 1
  71960. +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
  71961. +#define PMD_MASK (~(PMD_SIZE-1))
  71962. +
  71963. +#ifndef __ASSEMBLY__
  71964. +
  71965. +struct mm_struct;
  71966. +
  71967. /*
  71968. * Having the pmd type consist of a pud gets the size right, and allows
  71969. * us to conceptually access the pud entry that this pmd is folded into
  71970. @@ -16,11 +21,6 @@ struct mm_struct;
  71971. */
  71972. typedef struct { pud_t pud; } pmd_t;
  71973. -#define PMD_SHIFT PUD_SHIFT
  71974. -#define PTRS_PER_PMD 1
  71975. -#define PMD_SIZE (1UL << PMD_SHIFT)
  71976. -#define PMD_MASK (~(PMD_SIZE-1))
  71977. -
  71978. /*
  71979. * The "pud_xxx()" functions here are trivial for a folded two-level
  71980. * setup: the pmd is never bad, and a pmd always exists (as it's folded
  71981. diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
  71982. index 810431d..0ec4804f 100644
  71983. --- a/include/asm-generic/pgtable-nopud.h
  71984. +++ b/include/asm-generic/pgtable-nopud.h
  71985. @@ -1,10 +1,15 @@
  71986. #ifndef _PGTABLE_NOPUD_H
  71987. #define _PGTABLE_NOPUD_H
  71988. -#ifndef __ASSEMBLY__
  71989. -
  71990. #define __PAGETABLE_PUD_FOLDED
  71991. +#define PUD_SHIFT PGDIR_SHIFT
  71992. +#define PTRS_PER_PUD 1
  71993. +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
  71994. +#define PUD_MASK (~(PUD_SIZE-1))
  71995. +
  71996. +#ifndef __ASSEMBLY__
  71997. +
  71998. /*
  71999. * Having the pud type consist of a pgd gets the size right, and allows
  72000. * us to conceptually access the pgd entry that this pud is folded into
  72001. @@ -12,11 +17,6 @@
  72002. */
  72003. typedef struct { pgd_t pgd; } pud_t;
  72004. -#define PUD_SHIFT PGDIR_SHIFT
  72005. -#define PTRS_PER_PUD 1
  72006. -#define PUD_SIZE (1UL << PUD_SHIFT)
  72007. -#define PUD_MASK (~(PUD_SIZE-1))
  72008. -
  72009. /*
  72010. * The "pgd_xxx()" functions here are trivial for a folded two-level
  72011. * setup: the pud is never bad, and a pud always exists (as it's folded
  72012. @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
  72013. #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
  72014. #define pgd_populate(mm, pgd, pud) do { } while (0)
  72015. +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
  72016. /*
  72017. * (puds are folded into pgds so this doesn't get actually called,
  72018. * but the define is needed for a generic inline function.)
  72019. diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
  72020. index 34c7bdc..38d4f3b 100644
  72021. --- a/include/asm-generic/pgtable.h
  72022. +++ b/include/asm-generic/pgtable.h
  72023. @@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
  72024. }
  72025. #endif /* CONFIG_NUMA_BALANCING */
  72026. +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
  72027. +#ifdef CONFIG_PAX_KERNEXEC
  72028. +#error KERNEXEC requires pax_open_kernel
  72029. +#else
  72030. +static inline unsigned long pax_open_kernel(void) { return 0; }
  72031. +#endif
  72032. +#endif
  72033. +
  72034. +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
  72035. +#ifdef CONFIG_PAX_KERNEXEC
  72036. +#error KERNEXEC requires pax_close_kernel
  72037. +#else
  72038. +static inline unsigned long pax_close_kernel(void) { return 0; }
  72039. +#endif
  72040. +#endif
  72041. +
  72042. #endif /* CONFIG_MMU */
  72043. #endif /* !__ASSEMBLY__ */
  72044. diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
  72045. index 72d8803..cb9749c 100644
  72046. --- a/include/asm-generic/uaccess.h
  72047. +++ b/include/asm-generic/uaccess.h
  72048. @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
  72049. return __clear_user(to, n);
  72050. }
  72051. +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
  72052. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  72053. +#error UDEREF requires pax_open_userland
  72054. +#else
  72055. +static inline unsigned long pax_open_userland(void) { return 0; }
  72056. +#endif
  72057. +#endif
  72058. +
  72059. +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
  72060. +#ifdef CONFIG_PAX_MEMORY_UDEREF
  72061. +#error UDEREF requires pax_close_userland
  72062. +#else
  72063. +static inline unsigned long pax_close_userland(void) { return 0; }
  72064. +#endif
  72065. +#endif
  72066. +
  72067. #endif /* __ASM_GENERIC_UACCESS_H */
  72068. diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
  72069. index bc2121f..2f41f9a 100644
  72070. --- a/include/asm-generic/vmlinux.lds.h
  72071. +++ b/include/asm-generic/vmlinux.lds.h
  72072. @@ -232,6 +232,7 @@
  72073. .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
  72074. VMLINUX_SYMBOL(__start_rodata) = .; \
  72075. *(.rodata) *(.rodata.*) \
  72076. + *(.data..read_only) \
  72077. *(__vermagic) /* Kernel version magic */ \
  72078. . = ALIGN(8); \
  72079. VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
  72080. @@ -716,17 +717,18 @@
  72081. * section in the linker script will go there too. @phdr should have
  72082. * a leading colon.
  72083. *
  72084. - * Note that this macros defines __per_cpu_load as an absolute symbol.
  72085. + * Note that this macros defines per_cpu_load as an absolute symbol.
  72086. * If there is no need to put the percpu section at a predetermined
  72087. * address, use PERCPU_SECTION.
  72088. */
  72089. #define PERCPU_VADDR(cacheline, vaddr, phdr) \
  72090. - VMLINUX_SYMBOL(__per_cpu_load) = .; \
  72091. - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
  72092. + per_cpu_load = .; \
  72093. + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
  72094. - LOAD_OFFSET) { \
  72095. + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
  72096. PERCPU_INPUT(cacheline) \
  72097. } phdr \
  72098. - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
  72099. + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
  72100. /**
  72101. * PERCPU_SECTION - define output section for percpu area, simple version
  72102. diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
  72103. index e73c19e..5b89e00 100644
  72104. --- a/include/crypto/algapi.h
  72105. +++ b/include/crypto/algapi.h
  72106. @@ -34,7 +34,7 @@ struct crypto_type {
  72107. unsigned int maskclear;
  72108. unsigned int maskset;
  72109. unsigned int tfmsize;
  72110. -};
  72111. +} __do_const;
  72112. struct crypto_instance {
  72113. struct crypto_alg alg;
  72114. diff --git a/include/drm/drmP.h b/include/drm/drmP.h
  72115. index 04a7f31..668d424 100644
  72116. --- a/include/drm/drmP.h
  72117. +++ b/include/drm/drmP.h
  72118. @@ -67,6 +67,7 @@
  72119. #include <linux/workqueue.h>
  72120. #include <linux/poll.h>
  72121. #include <asm/pgalloc.h>
  72122. +#include <asm/local.h>
  72123. #include <drm/drm.h>
  72124. #include <drm/drm_sarea.h>
  72125. #include <drm/drm_vma_manager.h>
  72126. @@ -297,10 +298,12 @@ do { \
  72127. * \param cmd command.
  72128. * \param arg argument.
  72129. */
  72130. -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  72131. +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
  72132. + struct drm_file *file_priv);
  72133. +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
  72134. struct drm_file *file_priv);
  72135. -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  72136. +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
  72137. unsigned long arg);
  72138. #define DRM_IOCTL_NR(n) _IOC_NR(n)
  72139. @@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  72140. struct drm_ioctl_desc {
  72141. unsigned int cmd;
  72142. int flags;
  72143. - drm_ioctl_t *func;
  72144. + drm_ioctl_t func;
  72145. unsigned int cmd_drv;
  72146. const char *name;
  72147. -};
  72148. +} __do_const;
  72149. /**
  72150. * Creates a driver or general drm_ioctl_desc array entry for the given
  72151. @@ -1022,7 +1025,8 @@ struct drm_info_list {
  72152. int (*show)(struct seq_file*, void*); /** show callback */
  72153. u32 driver_features; /**< Required driver features for this entry */
  72154. void *data;
  72155. -};
  72156. +} __do_const;
  72157. +typedef struct drm_info_list __no_const drm_info_list_no_const;
  72158. /**
  72159. * debugfs node structure. This structure represents a debugfs file.
  72160. @@ -1106,7 +1110,7 @@ struct drm_device {
  72161. /** \name Usage Counters */
  72162. /*@{ */
  72163. - int open_count; /**< Outstanding files open */
  72164. + local_t open_count; /**< Outstanding files open */
  72165. int buf_use; /**< Buffers in use -- cannot alloc */
  72166. atomic_t buf_alloc; /**< Buffer allocation in progress */
  72167. /*@} */
  72168. diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
  72169. index b1388b5..e1d1163 100644
  72170. --- a/include/drm/drm_crtc_helper.h
  72171. +++ b/include/drm/drm_crtc_helper.h
  72172. @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
  72173. struct drm_connector *connector);
  72174. /* disable encoder when not in use - more explicit than dpms off */
  72175. void (*disable)(struct drm_encoder *encoder);
  72176. -};
  72177. +} __no_const;
  72178. /**
  72179. * drm_connector_helper_funcs - helper operations for connectors
  72180. diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
  72181. index 940ece4..8cb727f 100644
  72182. --- a/include/drm/i915_pciids.h
  72183. +++ b/include/drm/i915_pciids.h
  72184. @@ -37,7 +37,7 @@
  72185. */
  72186. #define INTEL_VGA_DEVICE(id, info) { \
  72187. 0x8086, id, \
  72188. - ~0, ~0, \
  72189. + PCI_ANY_ID, PCI_ANY_ID, \
  72190. 0x030000, 0xff0000, \
  72191. (unsigned long) info }
  72192. diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
  72193. index 72dcbe8..8db58d7 100644
  72194. --- a/include/drm/ttm/ttm_memory.h
  72195. +++ b/include/drm/ttm/ttm_memory.h
  72196. @@ -48,7 +48,7 @@
  72197. struct ttm_mem_shrink {
  72198. int (*do_shrink) (struct ttm_mem_shrink *);
  72199. -};
  72200. +} __no_const;
  72201. /**
  72202. * struct ttm_mem_global - Global memory accounting structure.
  72203. diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
  72204. index 49a8284..9643967 100644
  72205. --- a/include/drm/ttm/ttm_page_alloc.h
  72206. +++ b/include/drm/ttm/ttm_page_alloc.h
  72207. @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
  72208. */
  72209. extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
  72210. +struct device;
  72211. extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
  72212. extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
  72213. diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
  72214. index 4b840e8..155d235 100644
  72215. --- a/include/keys/asymmetric-subtype.h
  72216. +++ b/include/keys/asymmetric-subtype.h
  72217. @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
  72218. /* Verify the signature on a key of this subtype (optional) */
  72219. int (*verify_signature)(const struct key *key,
  72220. const struct public_key_signature *sig);
  72221. -};
  72222. +} __do_const;
  72223. /**
  72224. * asymmetric_key_subtype - Get the subtype from an asymmetric key
  72225. diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
  72226. index c1da539..1dcec55 100644
  72227. --- a/include/linux/atmdev.h
  72228. +++ b/include/linux/atmdev.h
  72229. @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
  72230. #endif
  72231. struct k_atm_aal_stats {
  72232. -#define __HANDLE_ITEM(i) atomic_t i
  72233. +#define __HANDLE_ITEM(i) atomic_unchecked_t i
  72234. __AAL_STAT_ITEMS
  72235. #undef __HANDLE_ITEM
  72236. };
  72237. @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
  72238. int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
  72239. int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
  72240. struct module *owner;
  72241. -};
  72242. +} __do_const ;
  72243. struct atmphy_ops {
  72244. int (*start)(struct atm_dev *dev);
  72245. diff --git a/include/linux/audit.h b/include/linux/audit.h
  72246. index ec1464d..833274b 100644
  72247. --- a/include/linux/audit.h
  72248. +++ b/include/linux/audit.h
  72249. @@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
  72250. extern unsigned int audit_serial(void);
  72251. extern int auditsc_get_stamp(struct audit_context *ctx,
  72252. struct timespec *t, unsigned int *serial);
  72253. -extern int audit_set_loginuid(kuid_t loginuid);
  72254. +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
  72255. static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
  72256. {
  72257. diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
  72258. index b4a745d..e3c0942 100644
  72259. --- a/include/linux/binfmts.h
  72260. +++ b/include/linux/binfmts.h
  72261. @@ -45,7 +45,7 @@ struct linux_binprm {
  72262. unsigned interp_data;
  72263. unsigned long loader, exec;
  72264. char tcomm[TASK_COMM_LEN];
  72265. -};
  72266. +} __randomize_layout;
  72267. #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
  72268. #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
  72269. @@ -74,8 +74,10 @@ struct linux_binfmt {
  72270. int (*load_binary)(struct linux_binprm *);
  72271. int (*load_shlib)(struct file *);
  72272. int (*core_dump)(struct coredump_params *cprm);
  72273. + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
  72274. + void (*handle_mmap)(struct file *);
  72275. unsigned long min_coredump; /* minimal dump size */
  72276. -};
  72277. +} __do_const __randomize_layout;
  72278. extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
  72279. diff --git a/include/linux/bitops.h b/include/linux/bitops.h
  72280. index be5fd38..d71192a 100644
  72281. --- a/include/linux/bitops.h
  72282. +++ b/include/linux/bitops.h
  72283. @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
  72284. * @word: value to rotate
  72285. * @shift: bits to roll
  72286. */
  72287. -static inline __u32 rol32(__u32 word, unsigned int shift)
  72288. +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
  72289. {
  72290. return (word << shift) | (word >> (32 - shift));
  72291. }
  72292. @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
  72293. * @word: value to rotate
  72294. * @shift: bits to roll
  72295. */
  72296. -static inline __u32 ror32(__u32 word, unsigned int shift)
  72297. +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
  72298. {
  72299. return (word >> shift) | (word << (32 - shift));
  72300. }
  72301. @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
  72302. return (__s32)(value << shift) >> shift;
  72303. }
  72304. -static inline unsigned fls_long(unsigned long l)
  72305. +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
  72306. {
  72307. if (sizeof(l) == 4)
  72308. return fls(l);
  72309. diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
  72310. index 4afa4f8..1ed7824 100644
  72311. --- a/include/linux/blkdev.h
  72312. +++ b/include/linux/blkdev.h
  72313. @@ -1572,7 +1572,7 @@ struct block_device_operations {
  72314. /* this callback is with swap_lock and sometimes page table lock held */
  72315. void (*swap_slot_free_notify) (struct block_device *, unsigned long);
  72316. struct module *owner;
  72317. -};
  72318. +} __do_const;
  72319. extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
  72320. unsigned long);
  72321. diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
  72322. index afc1343..9735539 100644
  72323. --- a/include/linux/blktrace_api.h
  72324. +++ b/include/linux/blktrace_api.h
  72325. @@ -25,7 +25,7 @@ struct blk_trace {
  72326. struct dentry *dropped_file;
  72327. struct dentry *msg_file;
  72328. struct list_head running_list;
  72329. - atomic_t dropped;
  72330. + atomic_unchecked_t dropped;
  72331. };
  72332. extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
  72333. diff --git a/include/linux/cache.h b/include/linux/cache.h
  72334. index 17e7e82..1d7da26 100644
  72335. --- a/include/linux/cache.h
  72336. +++ b/include/linux/cache.h
  72337. @@ -16,6 +16,14 @@
  72338. #define __read_mostly
  72339. #endif
  72340. +#ifndef __read_only
  72341. +#ifdef CONFIG_PAX_KERNEXEC
  72342. +#error KERNEXEC requires __read_only
  72343. +#else
  72344. +#define __read_only __read_mostly
  72345. +#endif
  72346. +#endif
  72347. +
  72348. #ifndef ____cacheline_aligned
  72349. #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
  72350. #endif
  72351. diff --git a/include/linux/capability.h b/include/linux/capability.h
  72352. index a6ee1f9..e1ca49d 100644
  72353. --- a/include/linux/capability.h
  72354. +++ b/include/linux/capability.h
  72355. @@ -212,8 +212,13 @@ extern bool capable(int cap);
  72356. extern bool ns_capable(struct user_namespace *ns, int cap);
  72357. extern bool inode_capable(const struct inode *inode, int cap);
  72358. extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
  72359. +extern bool capable_nolog(int cap);
  72360. +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
  72361. +extern bool inode_capable_nolog(const struct inode *inode, int cap);
  72362. /* audit system wants to get cap info from files as well */
  72363. extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
  72364. +extern int is_privileged_binary(const struct dentry *dentry);
  72365. +
  72366. #endif /* !_LINUX_CAPABILITY_H */
  72367. diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
  72368. index 8609d57..86e4d79 100644
  72369. --- a/include/linux/cdrom.h
  72370. +++ b/include/linux/cdrom.h
  72371. @@ -87,7 +87,6 @@ struct cdrom_device_ops {
  72372. /* driver specifications */
  72373. const int capability; /* capability flags */
  72374. - int n_minors; /* number of active minor devices */
  72375. /* handle uniform packets for scsi type devices (scsi,atapi) */
  72376. int (*generic_packet) (struct cdrom_device_info *,
  72377. struct packet_command *);
  72378. diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
  72379. index 4ce9056..86caac6 100644
  72380. --- a/include/linux/cleancache.h
  72381. +++ b/include/linux/cleancache.h
  72382. @@ -31,7 +31,7 @@ struct cleancache_ops {
  72383. void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
  72384. void (*invalidate_inode)(int, struct cleancache_filekey);
  72385. void (*invalidate_fs)(int);
  72386. -};
  72387. +} __no_const;
  72388. extern struct cleancache_ops *
  72389. cleancache_register_ops(struct cleancache_ops *ops);
  72390. diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
  72391. index 939533d..cf0a57c 100644
  72392. --- a/include/linux/clk-provider.h
  72393. +++ b/include/linux/clk-provider.h
  72394. @@ -166,6 +166,7 @@ struct clk_ops {
  72395. unsigned long parent_accuracy);
  72396. void (*init)(struct clk_hw *hw);
  72397. };
  72398. +typedef struct clk_ops __no_const clk_ops_no_const;
  72399. /**
  72400. * struct clk_init_data - holds init data that's common to all clocks and is
  72401. diff --git a/include/linux/compat.h b/include/linux/compat.h
  72402. index 3f448c6..df3ce1d 100644
  72403. --- a/include/linux/compat.h
  72404. +++ b/include/linux/compat.h
  72405. @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
  72406. compat_size_t __user *len_ptr);
  72407. asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
  72408. -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
  72409. +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
  72410. asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
  72411. asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
  72412. compat_ssize_t msgsz, int msgflg);
  72413. @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
  72414. extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  72415. compat_ulong_t addr, compat_ulong_t data);
  72416. asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  72417. - compat_long_t addr, compat_long_t data);
  72418. + compat_ulong_t addr, compat_ulong_t data);
  72419. asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
  72420. /*
  72421. diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
  72422. index 2507fd2..55203f8 100644
  72423. --- a/include/linux/compiler-gcc4.h
  72424. +++ b/include/linux/compiler-gcc4.h
  72425. @@ -39,9 +39,34 @@
  72426. # define __compiletime_warning(message) __attribute__((warning(message)))
  72427. # define __compiletime_error(message) __attribute__((error(message)))
  72428. #endif /* __CHECKER__ */
  72429. +
  72430. +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
  72431. +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
  72432. +#define __bos0(ptr) __bos((ptr), 0)
  72433. +#define __bos1(ptr) __bos((ptr), 1)
  72434. #endif /* GCC_VERSION >= 40300 */
  72435. #if GCC_VERSION >= 40500
  72436. +
  72437. +#ifdef RANDSTRUCT_PLUGIN
  72438. +#define __randomize_layout __attribute__((randomize_layout))
  72439. +#define __no_randomize_layout __attribute__((no_randomize_layout))
  72440. +#endif
  72441. +
  72442. +#ifdef CONSTIFY_PLUGIN
  72443. +#define __no_const __attribute__((no_const))
  72444. +#define __do_const __attribute__((do_const))
  72445. +#endif
  72446. +
  72447. +#ifdef SIZE_OVERFLOW_PLUGIN
  72448. +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
  72449. +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
  72450. +#endif
  72451. +
  72452. +#ifdef LATENT_ENTROPY_PLUGIN
  72453. +#define __latent_entropy __attribute__((latent_entropy))
  72454. +#endif
  72455. +
  72456. /*
  72457. * Mark a position in code as unreachable. This can be used to
  72458. * suppress control flow warnings after asm blocks that transfer
  72459. diff --git a/include/linux/compiler.h b/include/linux/compiler.h
  72460. index 2472740..4857634 100644
  72461. --- a/include/linux/compiler.h
  72462. +++ b/include/linux/compiler.h
  72463. @@ -5,11 +5,14 @@
  72464. #ifdef __CHECKER__
  72465. # define __user __attribute__((noderef, address_space(1)))
  72466. +# define __force_user __force __user
  72467. # define __kernel __attribute__((address_space(0)))
  72468. +# define __force_kernel __force __kernel
  72469. # define __safe __attribute__((safe))
  72470. # define __force __attribute__((force))
  72471. # define __nocast __attribute__((nocast))
  72472. # define __iomem __attribute__((noderef, address_space(2)))
  72473. +# define __force_iomem __force __iomem
  72474. # define __must_hold(x) __attribute__((context(x,1,1)))
  72475. # define __acquires(x) __attribute__((context(x,0,1)))
  72476. # define __releases(x) __attribute__((context(x,1,0)))
  72477. @@ -17,20 +20,37 @@
  72478. # define __release(x) __context__(x,-1)
  72479. # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
  72480. # define __percpu __attribute__((noderef, address_space(3)))
  72481. +# define __force_percpu __force __percpu
  72482. #ifdef CONFIG_SPARSE_RCU_POINTER
  72483. # define __rcu __attribute__((noderef, address_space(4)))
  72484. +# define __force_rcu __force __rcu
  72485. #else
  72486. # define __rcu
  72487. +# define __force_rcu
  72488. #endif
  72489. extern void __chk_user_ptr(const volatile void __user *);
  72490. extern void __chk_io_ptr(const volatile void __iomem *);
  72491. #else
  72492. -# define __user
  72493. -# define __kernel
  72494. +# ifdef CHECKER_PLUGIN
  72495. +//# define __user
  72496. +//# define __force_user
  72497. +//# define __kernel
  72498. +//# define __force_kernel
  72499. +# else
  72500. +# ifdef STRUCTLEAK_PLUGIN
  72501. +# define __user __attribute__((user))
  72502. +# else
  72503. +# define __user
  72504. +# endif
  72505. +# define __force_user
  72506. +# define __kernel
  72507. +# define __force_kernel
  72508. +# endif
  72509. # define __safe
  72510. # define __force
  72511. # define __nocast
  72512. # define __iomem
  72513. +# define __force_iomem
  72514. # define __chk_user_ptr(x) (void)0
  72515. # define __chk_io_ptr(x) (void)0
  72516. # define __builtin_warning(x, y...) (1)
  72517. @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
  72518. # define __release(x) (void)0
  72519. # define __cond_lock(x,c) (c)
  72520. # define __percpu
  72521. +# define __force_percpu
  72522. # define __rcu
  72523. +# define __force_rcu
  72524. #endif
  72525. /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
  72526. @@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
  72527. # define __attribute_const__ /* unimplemented */
  72528. #endif
  72529. +#ifndef __randomize_layout
  72530. +# define __randomize_layout
  72531. +#endif
  72532. +
  72533. +#ifndef __no_randomize_layout
  72534. +# define __no_randomize_layout
  72535. +#endif
  72536. +
  72537. +#ifndef __no_const
  72538. +# define __no_const
  72539. +#endif
  72540. +
  72541. +#ifndef __do_const
  72542. +# define __do_const
  72543. +#endif
  72544. +
  72545. +#ifndef __size_overflow
  72546. +# define __size_overflow(...)
  72547. +#endif
  72548. +
  72549. +#ifndef __intentional_overflow
  72550. +# define __intentional_overflow(...)
  72551. +#endif
  72552. +
  72553. +#ifndef __latent_entropy
  72554. +# define __latent_entropy
  72555. +#endif
  72556. +
  72557. /*
  72558. * Tell gcc if a function is cold. The compiler will assume any path
  72559. * directly leading to the call is unlikely.
  72560. @@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
  72561. #define __cold
  72562. #endif
  72563. +#ifndef __alloc_size
  72564. +#define __alloc_size(...)
  72565. +#endif
  72566. +
  72567. +#ifndef __bos
  72568. +#define __bos(ptr, arg)
  72569. +#endif
  72570. +
  72571. +#ifndef __bos0
  72572. +#define __bos0(ptr)
  72573. +#endif
  72574. +
  72575. +#ifndef __bos1
  72576. +#define __bos1(ptr)
  72577. +#endif
  72578. +
  72579. /* Simple shorthand for a section definition */
  72580. #ifndef __section
  72581. # define __section(S) __attribute__ ((__section__(#S)))
  72582. @@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
  72583. * use is to mediate communication between process-level code and irq/NMI
  72584. * handlers, all running on the same CPU.
  72585. */
  72586. -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
  72587. +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
  72588. +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
  72589. /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
  72590. #ifdef CONFIG_KPROBES
  72591. diff --git a/include/linux/completion.h b/include/linux/completion.h
  72592. index 5d5aaae..0ea9b84 100644
  72593. --- a/include/linux/completion.h
  72594. +++ b/include/linux/completion.h
  72595. @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
  72596. extern void wait_for_completion(struct completion *);
  72597. extern void wait_for_completion_io(struct completion *);
  72598. -extern int wait_for_completion_interruptible(struct completion *x);
  72599. -extern int wait_for_completion_killable(struct completion *x);
  72600. +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
  72601. +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
  72602. extern unsigned long wait_for_completion_timeout(struct completion *x,
  72603. - unsigned long timeout);
  72604. + unsigned long timeout) __intentional_overflow(-1);
  72605. extern unsigned long wait_for_completion_io_timeout(struct completion *x,
  72606. - unsigned long timeout);
  72607. + unsigned long timeout) __intentional_overflow(-1);
  72608. extern long wait_for_completion_interruptible_timeout(
  72609. - struct completion *x, unsigned long timeout);
  72610. + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
  72611. extern long wait_for_completion_killable_timeout(
  72612. - struct completion *x, unsigned long timeout);
  72613. + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
  72614. extern bool try_wait_for_completion(struct completion *x);
  72615. extern bool completion_done(struct completion *x);
  72616. diff --git a/include/linux/configfs.h b/include/linux/configfs.h
  72617. index 34025df..d94bbbc 100644
  72618. --- a/include/linux/configfs.h
  72619. +++ b/include/linux/configfs.h
  72620. @@ -125,7 +125,7 @@ struct configfs_attribute {
  72621. const char *ca_name;
  72622. struct module *ca_owner;
  72623. umode_t ca_mode;
  72624. -};
  72625. +} __do_const;
  72626. /*
  72627. * Users often need to create attribute structures for their configurable
  72628. diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
  72629. index 4d89e0e..5281847 100644
  72630. --- a/include/linux/cpufreq.h
  72631. +++ b/include/linux/cpufreq.h
  72632. @@ -191,6 +191,7 @@ struct global_attr {
  72633. ssize_t (*store)(struct kobject *a, struct attribute *b,
  72634. const char *c, size_t count);
  72635. };
  72636. +typedef struct global_attr __no_const global_attr_no_const;
  72637. #define define_one_global_ro(_name) \
  72638. static struct global_attr _name = \
  72639. @@ -232,7 +233,7 @@ struct cpufreq_driver {
  72640. bool boost_supported;
  72641. bool boost_enabled;
  72642. int (*set_boost) (int state);
  72643. -};
  72644. +} __do_const;
  72645. /* flags */
  72646. #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
  72647. diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
  72648. index 50fcbb0..9d2dbd9 100644
  72649. --- a/include/linux/cpuidle.h
  72650. +++ b/include/linux/cpuidle.h
  72651. @@ -50,7 +50,8 @@ struct cpuidle_state {
  72652. int index);
  72653. int (*enter_dead) (struct cpuidle_device *dev, int index);
  72654. -};
  72655. +} __do_const;
  72656. +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
  72657. /* Idle State Flags */
  72658. #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
  72659. @@ -192,7 +193,7 @@ struct cpuidle_governor {
  72660. void (*reflect) (struct cpuidle_device *dev, int index);
  72661. struct module *owner;
  72662. -};
  72663. +} __do_const;
  72664. #ifdef CONFIG_CPU_IDLE
  72665. extern int cpuidle_register_governor(struct cpuidle_governor *gov);
  72666. diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
  72667. index d08e4d2..95fad61 100644
  72668. --- a/include/linux/cpumask.h
  72669. +++ b/include/linux/cpumask.h
  72670. @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
  72671. }
  72672. /* Valid inputs for n are -1 and 0. */
  72673. -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
  72674. +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
  72675. {
  72676. return n+1;
  72677. }
  72678. -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
  72679. +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
  72680. {
  72681. return n+1;
  72682. }
  72683. -static inline unsigned int cpumask_next_and(int n,
  72684. +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
  72685. const struct cpumask *srcp,
  72686. const struct cpumask *andp)
  72687. {
  72688. @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
  72689. *
  72690. * Returns >= nr_cpu_ids if no further cpus set.
  72691. */
  72692. -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
  72693. +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
  72694. {
  72695. /* -1 is a legal arg here. */
  72696. if (n != -1)
  72697. @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
  72698. *
  72699. * Returns >= nr_cpu_ids if no further cpus unset.
  72700. */
  72701. -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
  72702. +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
  72703. {
  72704. /* -1 is a legal arg here. */
  72705. if (n != -1)
  72706. @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
  72707. return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
  72708. }
  72709. -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
  72710. +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
  72711. int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
  72712. /**
  72713. diff --git a/include/linux/cred.h b/include/linux/cred.h
  72714. index 04421e8..117e17a 100644
  72715. --- a/include/linux/cred.h
  72716. +++ b/include/linux/cred.h
  72717. @@ -35,7 +35,7 @@ struct group_info {
  72718. int nblocks;
  72719. kgid_t small_block[NGROUPS_SMALL];
  72720. kgid_t *blocks[0];
  72721. -};
  72722. +} __randomize_layout;
  72723. /**
  72724. * get_group_info - Get a reference to a group info structure
  72725. @@ -136,7 +136,7 @@ struct cred {
  72726. struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
  72727. struct group_info *group_info; /* supplementary groups for euid/fsgid */
  72728. struct rcu_head rcu; /* RCU deletion hook */
  72729. -};
  72730. +} __randomize_layout;
  72731. extern void __put_cred(struct cred *);
  72732. extern void exit_creds(struct task_struct *);
  72733. @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
  72734. static inline void validate_process_creds(void)
  72735. {
  72736. }
  72737. +static inline void validate_task_creds(struct task_struct *task)
  72738. +{
  72739. +}
  72740. #endif
  72741. /**
  72742. diff --git a/include/linux/crypto.h b/include/linux/crypto.h
  72743. index b92eadf..b4ecdc1 100644
  72744. --- a/include/linux/crypto.h
  72745. +++ b/include/linux/crypto.h
  72746. @@ -373,7 +373,7 @@ struct cipher_tfm {
  72747. const u8 *key, unsigned int keylen);
  72748. void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  72749. void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  72750. -};
  72751. +} __no_const;
  72752. struct hash_tfm {
  72753. int (*init)(struct hash_desc *desc);
  72754. @@ -394,13 +394,13 @@ struct compress_tfm {
  72755. int (*cot_decompress)(struct crypto_tfm *tfm,
  72756. const u8 *src, unsigned int slen,
  72757. u8 *dst, unsigned int *dlen);
  72758. -};
  72759. +} __no_const;
  72760. struct rng_tfm {
  72761. int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
  72762. unsigned int dlen);
  72763. int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
  72764. -};
  72765. +} __no_const;
  72766. #define crt_ablkcipher crt_u.ablkcipher
  72767. #define crt_aead crt_u.aead
  72768. diff --git a/include/linux/ctype.h b/include/linux/ctype.h
  72769. index 653589e..4ef254a 100644
  72770. --- a/include/linux/ctype.h
  72771. +++ b/include/linux/ctype.h
  72772. @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
  72773. * Fast implementation of tolower() for internal usage. Do not use in your
  72774. * code.
  72775. */
  72776. -static inline char _tolower(const char c)
  72777. +static inline unsigned char _tolower(const unsigned char c)
  72778. {
  72779. return c | 0x20;
  72780. }
  72781. diff --git a/include/linux/dcache.h b/include/linux/dcache.h
  72782. index bf72e9a..4ca7927 100644
  72783. --- a/include/linux/dcache.h
  72784. +++ b/include/linux/dcache.h
  72785. @@ -133,7 +133,7 @@ struct dentry {
  72786. } d_u;
  72787. struct list_head d_subdirs; /* our children */
  72788. struct hlist_node d_alias; /* inode alias list */
  72789. -};
  72790. +} __randomize_layout;
  72791. /*
  72792. * dentry->d_lock spinlock nesting subclasses:
  72793. diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
  72794. index 7925bf0..d5143d2 100644
  72795. --- a/include/linux/decompress/mm.h
  72796. +++ b/include/linux/decompress/mm.h
  72797. @@ -77,7 +77,7 @@ static void free(void *where)
  72798. * warnings when not needed (indeed large_malloc / large_free are not
  72799. * needed by inflate */
  72800. -#define malloc(a) kmalloc(a, GFP_KERNEL)
  72801. +#define malloc(a) kmalloc((a), GFP_KERNEL)
  72802. #define free(a) kfree(a)
  72803. #define large_malloc(a) vmalloc(a)
  72804. diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
  72805. index d48dc00..211ee54 100644
  72806. --- a/include/linux/devfreq.h
  72807. +++ b/include/linux/devfreq.h
  72808. @@ -114,7 +114,7 @@ struct devfreq_governor {
  72809. int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
  72810. int (*event_handler)(struct devfreq *devfreq,
  72811. unsigned int event, void *data);
  72812. -};
  72813. +} __do_const;
  72814. /**
  72815. * struct devfreq - Device devfreq structure
  72816. diff --git a/include/linux/device.h b/include/linux/device.h
  72817. index 952b010..d5b7691 100644
  72818. --- a/include/linux/device.h
  72819. +++ b/include/linux/device.h
  72820. @@ -310,7 +310,7 @@ struct subsys_interface {
  72821. struct list_head node;
  72822. int (*add_dev)(struct device *dev, struct subsys_interface *sif);
  72823. int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
  72824. -};
  72825. +} __do_const;
  72826. int subsys_interface_register(struct subsys_interface *sif);
  72827. void subsys_interface_unregister(struct subsys_interface *sif);
  72828. @@ -506,7 +506,7 @@ struct device_type {
  72829. void (*release)(struct device *dev);
  72830. const struct dev_pm_ops *pm;
  72831. -};
  72832. +} __do_const;
  72833. /* interface for exporting device attributes */
  72834. struct device_attribute {
  72835. @@ -516,11 +516,12 @@ struct device_attribute {
  72836. ssize_t (*store)(struct device *dev, struct device_attribute *attr,
  72837. const char *buf, size_t count);
  72838. };
  72839. +typedef struct device_attribute __no_const device_attribute_no_const;
  72840. struct dev_ext_attribute {
  72841. struct device_attribute attr;
  72842. void *var;
  72843. -};
  72844. +} __do_const;
  72845. ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
  72846. char *buf);
  72847. diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
  72848. index fd4aee2..1f28db9 100644
  72849. --- a/include/linux/dma-mapping.h
  72850. +++ b/include/linux/dma-mapping.h
  72851. @@ -54,7 +54,7 @@ struct dma_map_ops {
  72852. u64 (*get_required_mask)(struct device *dev);
  72853. #endif
  72854. int is_phys;
  72855. -};
  72856. +} __do_const;
  72857. #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
  72858. diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
  72859. index c5c92d5..6a5c2b2 100644
  72860. --- a/include/linux/dmaengine.h
  72861. +++ b/include/linux/dmaengine.h
  72862. @@ -1150,9 +1150,9 @@ struct dma_pinned_list {
  72863. struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
  72864. void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
  72865. -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
  72866. +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
  72867. struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
  72868. -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
  72869. +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
  72870. struct dma_pinned_list *pinned_list, struct page *page,
  72871. unsigned int offset, size_t len);
  72872. diff --git a/include/linux/efi.h b/include/linux/efi.h
  72873. index 0a819e7..8ed47f1 100644
  72874. --- a/include/linux/efi.h
  72875. +++ b/include/linux/efi.h
  72876. @@ -768,6 +768,7 @@ struct efivar_operations {
  72877. efi_set_variable_t *set_variable;
  72878. efi_query_variable_store_t *query_variable_store;
  72879. };
  72880. +typedef struct efivar_operations __no_const efivar_operations_no_const;
  72881. struct efivars {
  72882. /*
  72883. diff --git a/include/linux/elf.h b/include/linux/elf.h
  72884. index 67a5fa7..b817372 100644
  72885. --- a/include/linux/elf.h
  72886. +++ b/include/linux/elf.h
  72887. @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
  72888. #define elf_note elf32_note
  72889. #define elf_addr_t Elf32_Off
  72890. #define Elf_Half Elf32_Half
  72891. +#define elf_dyn Elf32_Dyn
  72892. #else
  72893. @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
  72894. #define elf_note elf64_note
  72895. #define elf_addr_t Elf64_Off
  72896. #define Elf_Half Elf64_Half
  72897. +#define elf_dyn Elf64_Dyn
  72898. #endif
  72899. diff --git a/include/linux/err.h b/include/linux/err.h
  72900. index 15f92e0..e825a8e 100644
  72901. --- a/include/linux/err.h
  72902. +++ b/include/linux/err.h
  72903. @@ -19,12 +19,12 @@
  72904. #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
  72905. -static inline void * __must_check ERR_PTR(long error)
  72906. +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
  72907. {
  72908. return (void *) error;
  72909. }
  72910. -static inline long __must_check PTR_ERR(__force const void *ptr)
  72911. +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
  72912. {
  72913. return (long) ptr;
  72914. }
  72915. diff --git a/include/linux/extcon.h b/include/linux/extcon.h
  72916. index 21c59af..6057a03 100644
  72917. --- a/include/linux/extcon.h
  72918. +++ b/include/linux/extcon.h
  72919. @@ -135,7 +135,7 @@ struct extcon_dev {
  72920. /* /sys/class/extcon/.../mutually_exclusive/... */
  72921. struct attribute_group attr_g_muex;
  72922. struct attribute **attrs_muex;
  72923. - struct device_attribute *d_attrs_muex;
  72924. + device_attribute_no_const *d_attrs_muex;
  72925. };
  72926. /**
  72927. diff --git a/include/linux/fb.h b/include/linux/fb.h
  72928. index fe6ac95..898d41d 100644
  72929. --- a/include/linux/fb.h
  72930. +++ b/include/linux/fb.h
  72931. @@ -304,7 +304,7 @@ struct fb_ops {
  72932. /* called at KDB enter and leave time to prepare the console */
  72933. int (*fb_debug_enter)(struct fb_info *info);
  72934. int (*fb_debug_leave)(struct fb_info *info);
  72935. -};
  72936. +} __do_const;
  72937. #ifdef CONFIG_FB_TILEBLITTING
  72938. #define FB_TILE_CURSOR_NONE 0
  72939. diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
  72940. index 70e8e21..1939916 100644
  72941. --- a/include/linux/fdtable.h
  72942. +++ b/include/linux/fdtable.h
  72943. @@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
  72944. void put_files_struct(struct files_struct *fs);
  72945. void reset_files_struct(struct files_struct *);
  72946. int unshare_files(struct files_struct **);
  72947. -struct files_struct *dup_fd(struct files_struct *, int *);
  72948. +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
  72949. void do_close_on_exec(struct files_struct *);
  72950. int iterate_fd(struct files_struct *, unsigned,
  72951. int (*)(const void *, struct file *, unsigned),
  72952. diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
  72953. index 8293262..2b3b8bd 100644
  72954. --- a/include/linux/frontswap.h
  72955. +++ b/include/linux/frontswap.h
  72956. @@ -11,7 +11,7 @@ struct frontswap_ops {
  72957. int (*load)(unsigned, pgoff_t, struct page *);
  72958. void (*invalidate_page)(unsigned, pgoff_t);
  72959. void (*invalidate_area)(unsigned);
  72960. -};
  72961. +} __no_const;
  72962. extern bool frontswap_enabled;
  72963. extern struct frontswap_ops *
  72964. diff --git a/include/linux/fs.h b/include/linux/fs.h
  72965. index 23b2a35..8764ab7 100644
  72966. --- a/include/linux/fs.h
  72967. +++ b/include/linux/fs.h
  72968. @@ -426,7 +426,7 @@ struct address_space {
  72969. spinlock_t private_lock; /* for use by the address_space */
  72970. struct list_head private_list; /* ditto */
  72971. void *private_data; /* ditto */
  72972. -} __attribute__((aligned(sizeof(long))));
  72973. +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
  72974. /*
  72975. * On most architectures that alignment is already the case; but
  72976. * must be enforced here for CRIS, to let the least significant bit
  72977. @@ -469,7 +469,7 @@ struct block_device {
  72978. int bd_fsfreeze_count;
  72979. /* Mutex for freeze */
  72980. struct mutex bd_fsfreeze_mutex;
  72981. -};
  72982. +} __randomize_layout;
  72983. /*
  72984. * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
  72985. @@ -613,7 +613,7 @@ struct inode {
  72986. atomic_t i_readcount; /* struct files open RO */
  72987. #endif
  72988. void *i_private; /* fs or device private pointer */
  72989. -};
  72990. +} __randomize_layout;
  72991. static inline int inode_unhashed(struct inode *inode)
  72992. {
  72993. @@ -812,7 +812,7 @@ struct file {
  72994. #ifdef CONFIG_DEBUG_WRITECOUNT
  72995. unsigned long f_mnt_write_state;
  72996. #endif
  72997. -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
  72998. +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
  72999. struct file_handle {
  73000. __u32 handle_bytes;
  73001. @@ -982,7 +982,7 @@ struct file_lock {
  73002. int state; /* state of grant or error if -ve */
  73003. } afs;
  73004. } fl_u;
  73005. -};
  73006. +} __randomize_layout;
  73007. /* The following constant reflects the upper bound of the file/locking space */
  73008. #ifndef OFFSET_MAX
  73009. @@ -1329,7 +1329,7 @@ struct super_block {
  73010. struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
  73011. struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
  73012. struct rcu_head rcu;
  73013. -};
  73014. +} __randomize_layout;
  73015. extern struct timespec current_fs_time(struct super_block *sb);
  73016. @@ -1551,7 +1551,8 @@ struct file_operations {
  73017. long (*fallocate)(struct file *file, int mode, loff_t offset,
  73018. loff_t len);
  73019. int (*show_fdinfo)(struct seq_file *m, struct file *f);
  73020. -};
  73021. +} __do_const __randomize_layout;
  73022. +typedef struct file_operations __no_const file_operations_no_const;
  73023. struct inode_operations {
  73024. struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
  73025. @@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
  73026. return !IS_DEADDIR(inode);
  73027. }
  73028. +static inline bool is_sidechannel_device(const struct inode *inode)
  73029. +{
  73030. +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
  73031. + umode_t mode = inode->i_mode;
  73032. + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
  73033. +#else
  73034. + return false;
  73035. +#endif
  73036. +}
  73037. +
  73038. #endif /* _LINUX_FS_H */
  73039. diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
  73040. index 0efc3e6..fd23610 100644
  73041. --- a/include/linux/fs_struct.h
  73042. +++ b/include/linux/fs_struct.h
  73043. @@ -6,13 +6,13 @@
  73044. #include <linux/seqlock.h>
  73045. struct fs_struct {
  73046. - int users;
  73047. + atomic_t users;
  73048. spinlock_t lock;
  73049. seqcount_t seq;
  73050. int umask;
  73051. int in_exec;
  73052. struct path root, pwd;
  73053. -};
  73054. +} __randomize_layout;
  73055. extern struct kmem_cache *fs_cachep;
  73056. diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
  73057. index 7714849..a4a5c7a 100644
  73058. --- a/include/linux/fscache-cache.h
  73059. +++ b/include/linux/fscache-cache.h
  73060. @@ -113,7 +113,7 @@ struct fscache_operation {
  73061. fscache_operation_release_t release;
  73062. };
  73063. -extern atomic_t fscache_op_debug_id;
  73064. +extern atomic_unchecked_t fscache_op_debug_id;
  73065. extern void fscache_op_work_func(struct work_struct *work);
  73066. extern void fscache_enqueue_operation(struct fscache_operation *);
  73067. @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
  73068. INIT_WORK(&op->work, fscache_op_work_func);
  73069. atomic_set(&op->usage, 1);
  73070. op->state = FSCACHE_OP_ST_INITIALISED;
  73071. - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
  73072. + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
  73073. op->processor = processor;
  73074. op->release = release;
  73075. INIT_LIST_HEAD(&op->pend_link);
  73076. diff --git a/include/linux/fscache.h b/include/linux/fscache.h
  73077. index 115bb81..e7b812b 100644
  73078. --- a/include/linux/fscache.h
  73079. +++ b/include/linux/fscache.h
  73080. @@ -152,7 +152,7 @@ struct fscache_cookie_def {
  73081. * - this is mandatory for any object that may have data
  73082. */
  73083. void (*now_uncached)(void *cookie_netfs_data);
  73084. -};
  73085. +} __do_const;
  73086. /*
  73087. * fscache cached network filesystem type
  73088. diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
  73089. index 1c804b0..1432c2b 100644
  73090. --- a/include/linux/fsnotify.h
  73091. +++ b/include/linux/fsnotify.h
  73092. @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
  73093. struct inode *inode = file_inode(file);
  73094. __u32 mask = FS_ACCESS;
  73095. + if (is_sidechannel_device(inode))
  73096. + return;
  73097. +
  73098. if (S_ISDIR(inode->i_mode))
  73099. mask |= FS_ISDIR;
  73100. @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
  73101. struct inode *inode = file_inode(file);
  73102. __u32 mask = FS_MODIFY;
  73103. + if (is_sidechannel_device(inode))
  73104. + return;
  73105. +
  73106. if (S_ISDIR(inode->i_mode))
  73107. mask |= FS_ISDIR;
  73108. @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
  73109. */
  73110. static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
  73111. {
  73112. - return kstrdup(name, GFP_KERNEL);
  73113. + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
  73114. }
  73115. /*
  73116. diff --git a/include/linux/genhd.h b/include/linux/genhd.h
  73117. index 9f3c275..8bdff5d 100644
  73118. --- a/include/linux/genhd.h
  73119. +++ b/include/linux/genhd.h
  73120. @@ -194,7 +194,7 @@ struct gendisk {
  73121. struct kobject *slave_dir;
  73122. struct timer_rand_state *random;
  73123. - atomic_t sync_io; /* RAID */
  73124. + atomic_unchecked_t sync_io; /* RAID */
  73125. struct disk_events *ev;
  73126. #ifdef CONFIG_BLK_DEV_INTEGRITY
  73127. struct blk_integrity *integrity;
  73128. @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
  73129. extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
  73130. /* drivers/char/random.c */
  73131. -extern void add_disk_randomness(struct gendisk *disk);
  73132. +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
  73133. extern void rand_initialize_disk(struct gendisk *disk);
  73134. static inline sector_t get_start_sect(struct block_device *bdev)
  73135. diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
  73136. index c0894dd..2fbf10c 100644
  73137. --- a/include/linux/genl_magic_func.h
  73138. +++ b/include/linux/genl_magic_func.h
  73139. @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
  73140. },
  73141. #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
  73142. -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
  73143. +static struct genl_ops ZZZ_genl_ops[] = {
  73144. #include GENL_MAGIC_INCLUDE_FILE
  73145. };
  73146. diff --git a/include/linux/gfp.h b/include/linux/gfp.h
  73147. index 39b81dc..819dc51 100644
  73148. --- a/include/linux/gfp.h
  73149. +++ b/include/linux/gfp.h
  73150. @@ -36,6 +36,13 @@ struct vm_area_struct;
  73151. #define ___GFP_NO_KSWAPD 0x400000u
  73152. #define ___GFP_OTHER_NODE 0x800000u
  73153. #define ___GFP_WRITE 0x1000000u
  73154. +
  73155. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  73156. +#define ___GFP_USERCOPY 0x2000000u
  73157. +#else
  73158. +#define ___GFP_USERCOPY 0
  73159. +#endif
  73160. +
  73161. /* If the above are modified, __GFP_BITS_SHIFT may need updating */
  73162. /*
  73163. @@ -93,6 +100,7 @@ struct vm_area_struct;
  73164. #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
  73165. #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
  73166. #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
  73167. +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
  73168. /*
  73169. * This may seem redundant, but it's a way of annotating false positives vs.
  73170. @@ -100,7 +108,7 @@ struct vm_area_struct;
  73171. */
  73172. #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
  73173. -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
  73174. +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
  73175. #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
  73176. /* This equals 0, but use constants in case they ever change */
  73177. @@ -158,6 +166,8 @@ struct vm_area_struct;
  73178. /* 4GB DMA on some platforms */
  73179. #define GFP_DMA32 __GFP_DMA32
  73180. +#define GFP_USERCOPY __GFP_USERCOPY
  73181. +
  73182. /* Convert GFP flags to their corresponding migrate type */
  73183. static inline int allocflags_to_migratetype(gfp_t gfp_flags)
  73184. {
  73185. diff --git a/include/linux/gracl.h b/include/linux/gracl.h
  73186. new file mode 100644
  73187. index 0000000..edb2cb6
  73188. --- /dev/null
  73189. +++ b/include/linux/gracl.h
  73190. @@ -0,0 +1,340 @@
  73191. +#ifndef GR_ACL_H
  73192. +#define GR_ACL_H
  73193. +
  73194. +#include <linux/grdefs.h>
  73195. +#include <linux/resource.h>
  73196. +#include <linux/capability.h>
  73197. +#include <linux/dcache.h>
  73198. +#include <asm/resource.h>
  73199. +
  73200. +/* Major status information */
  73201. +
  73202. +#define GR_VERSION "grsecurity 3.0"
  73203. +#define GRSECURITY_VERSION 0x3000
  73204. +
  73205. +enum {
  73206. + GR_SHUTDOWN = 0,
  73207. + GR_ENABLE = 1,
  73208. + GR_SPROLE = 2,
  73209. + GR_OLDRELOAD = 3,
  73210. + GR_SEGVMOD = 4,
  73211. + GR_STATUS = 5,
  73212. + GR_UNSPROLE = 6,
  73213. + GR_PASSSET = 7,
  73214. + GR_SPROLEPAM = 8,
  73215. + GR_RELOAD = 9,
  73216. +};
  73217. +
  73218. +/* Password setup definitions
  73219. + * kernel/grhash.c */
  73220. +enum {
  73221. + GR_PW_LEN = 128,
  73222. + GR_SALT_LEN = 16,
  73223. + GR_SHA_LEN = 32,
  73224. +};
  73225. +
  73226. +enum {
  73227. + GR_SPROLE_LEN = 64,
  73228. +};
  73229. +
  73230. +enum {
  73231. + GR_NO_GLOB = 0,
  73232. + GR_REG_GLOB,
  73233. + GR_CREATE_GLOB
  73234. +};
  73235. +
  73236. +#define GR_NLIMITS 32
  73237. +
  73238. +/* Begin Data Structures */
  73239. +
  73240. +struct sprole_pw {
  73241. + unsigned char *rolename;
  73242. + unsigned char salt[GR_SALT_LEN];
  73243. + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
  73244. +};
  73245. +
  73246. +struct name_entry {
  73247. + __u32 key;
  73248. + ino_t inode;
  73249. + dev_t device;
  73250. + char *name;
  73251. + __u16 len;
  73252. + __u8 deleted;
  73253. + struct name_entry *prev;
  73254. + struct name_entry *next;
  73255. +};
  73256. +
  73257. +struct inodev_entry {
  73258. + struct name_entry *nentry;
  73259. + struct inodev_entry *prev;
  73260. + struct inodev_entry *next;
  73261. +};
  73262. +
  73263. +struct acl_role_db {
  73264. + struct acl_role_label **r_hash;
  73265. + __u32 r_size;
  73266. +};
  73267. +
  73268. +struct inodev_db {
  73269. + struct inodev_entry **i_hash;
  73270. + __u32 i_size;
  73271. +};
  73272. +
  73273. +struct name_db {
  73274. + struct name_entry **n_hash;
  73275. + __u32 n_size;
  73276. +};
  73277. +
  73278. +struct crash_uid {
  73279. + uid_t uid;
  73280. + unsigned long expires;
  73281. +};
  73282. +
  73283. +struct gr_hash_struct {
  73284. + void **table;
  73285. + void **nametable;
  73286. + void *first;
  73287. + __u32 table_size;
  73288. + __u32 used_size;
  73289. + int type;
  73290. +};
  73291. +
  73292. +/* Userspace Grsecurity ACL data structures */
  73293. +
  73294. +struct acl_subject_label {
  73295. + char *filename;
  73296. + ino_t inode;
  73297. + dev_t device;
  73298. + __u32 mode;
  73299. + kernel_cap_t cap_mask;
  73300. + kernel_cap_t cap_lower;
  73301. + kernel_cap_t cap_invert_audit;
  73302. +
  73303. + struct rlimit res[GR_NLIMITS];
  73304. + __u32 resmask;
  73305. +
  73306. + __u8 user_trans_type;
  73307. + __u8 group_trans_type;
  73308. + uid_t *user_transitions;
  73309. + gid_t *group_transitions;
  73310. + __u16 user_trans_num;
  73311. + __u16 group_trans_num;
  73312. +
  73313. + __u32 sock_families[2];
  73314. + __u32 ip_proto[8];
  73315. + __u32 ip_type;
  73316. + struct acl_ip_label **ips;
  73317. + __u32 ip_num;
  73318. + __u32 inaddr_any_override;
  73319. +
  73320. + __u32 crashes;
  73321. + unsigned long expires;
  73322. +
  73323. + struct acl_subject_label *parent_subject;
  73324. + struct gr_hash_struct *hash;
  73325. + struct acl_subject_label *prev;
  73326. + struct acl_subject_label *next;
  73327. +
  73328. + struct acl_object_label **obj_hash;
  73329. + __u32 obj_hash_size;
  73330. + __u16 pax_flags;
  73331. +};
  73332. +
  73333. +struct role_allowed_ip {
  73334. + __u32 addr;
  73335. + __u32 netmask;
  73336. +
  73337. + struct role_allowed_ip *prev;
  73338. + struct role_allowed_ip *next;
  73339. +};
  73340. +
  73341. +struct role_transition {
  73342. + char *rolename;
  73343. +
  73344. + struct role_transition *prev;
  73345. + struct role_transition *next;
  73346. +};
  73347. +
  73348. +struct acl_role_label {
  73349. + char *rolename;
  73350. + uid_t uidgid;
  73351. + __u16 roletype;
  73352. +
  73353. + __u16 auth_attempts;
  73354. + unsigned long expires;
  73355. +
  73356. + struct acl_subject_label *root_label;
  73357. + struct gr_hash_struct *hash;
  73358. +
  73359. + struct acl_role_label *prev;
  73360. + struct acl_role_label *next;
  73361. +
  73362. + struct role_transition *transitions;
  73363. + struct role_allowed_ip *allowed_ips;
  73364. + uid_t *domain_children;
  73365. + __u16 domain_child_num;
  73366. +
  73367. + umode_t umask;
  73368. +
  73369. + struct acl_subject_label **subj_hash;
  73370. + __u32 subj_hash_size;
  73371. +};
  73372. +
  73373. +struct user_acl_role_db {
  73374. + struct acl_role_label **r_table;
  73375. + __u32 num_pointers; /* Number of allocations to track */
  73376. + __u32 num_roles; /* Number of roles */
  73377. + __u32 num_domain_children; /* Number of domain children */
  73378. + __u32 num_subjects; /* Number of subjects */
  73379. + __u32 num_objects; /* Number of objects */
  73380. +};
  73381. +
  73382. +struct acl_object_label {
  73383. + char *filename;
  73384. + ino_t inode;
  73385. + dev_t device;
  73386. + __u32 mode;
  73387. +
  73388. + struct acl_subject_label *nested;
  73389. + struct acl_object_label *globbed;
  73390. +
  73391. + /* next two structures not used */
  73392. +
  73393. + struct acl_object_label *prev;
  73394. + struct acl_object_label *next;
  73395. +};
  73396. +
  73397. +struct acl_ip_label {
  73398. + char *iface;
  73399. + __u32 addr;
  73400. + __u32 netmask;
  73401. + __u16 low, high;
  73402. + __u8 mode;
  73403. + __u32 type;
  73404. + __u32 proto[8];
  73405. +
  73406. + /* next two structures not used */
  73407. +
  73408. + struct acl_ip_label *prev;
  73409. + struct acl_ip_label *next;
  73410. +};
  73411. +
  73412. +struct gr_arg {
  73413. + struct user_acl_role_db role_db;
  73414. + unsigned char pw[GR_PW_LEN];
  73415. + unsigned char salt[GR_SALT_LEN];
  73416. + unsigned char sum[GR_SHA_LEN];
  73417. + unsigned char sp_role[GR_SPROLE_LEN];
  73418. + struct sprole_pw *sprole_pws;
  73419. + dev_t segv_device;
  73420. + ino_t segv_inode;
  73421. + uid_t segv_uid;
  73422. + __u16 num_sprole_pws;
  73423. + __u16 mode;
  73424. +};
  73425. +
  73426. +struct gr_arg_wrapper {
  73427. + struct gr_arg *arg;
  73428. + __u32 version;
  73429. + __u32 size;
  73430. +};
  73431. +
  73432. +struct subject_map {
  73433. + struct acl_subject_label *user;
  73434. + struct acl_subject_label *kernel;
  73435. + struct subject_map *prev;
  73436. + struct subject_map *next;
  73437. +};
  73438. +
  73439. +struct acl_subj_map_db {
  73440. + struct subject_map **s_hash;
  73441. + __u32 s_size;
  73442. +};
  73443. +
  73444. +struct gr_policy_state {
  73445. + struct sprole_pw **acl_special_roles;
  73446. + __u16 num_sprole_pws;
  73447. + struct acl_role_label *kernel_role;
  73448. + struct acl_role_label *role_list;
  73449. + struct acl_role_label *default_role;
  73450. + struct acl_role_db acl_role_set;
  73451. + struct acl_subj_map_db subj_map_set;
  73452. + struct name_db name_set;
  73453. + struct inodev_db inodev_set;
  73454. +};
  73455. +
  73456. +struct gr_alloc_state {
  73457. + unsigned long alloc_stack_next;
  73458. + unsigned long alloc_stack_size;
  73459. + void **alloc_stack;
  73460. +};
  73461. +
  73462. +struct gr_reload_state {
  73463. + struct gr_policy_state oldpolicy;
  73464. + struct gr_alloc_state oldalloc;
  73465. + struct gr_policy_state newpolicy;
  73466. + struct gr_alloc_state newalloc;
  73467. + struct gr_policy_state *oldpolicy_ptr;
  73468. + struct gr_alloc_state *oldalloc_ptr;
  73469. + unsigned char oldmode;
  73470. +};
  73471. +
  73472. +/* End Data Structures Section */
  73473. +
  73474. +/* Hash functions generated by empirical testing by Brad Spengler
  73475. + Makes good use of the low bits of the inode. Generally 0-1 times
  73476. + in loop for successful match. 0-3 for unsuccessful match.
  73477. + Shift/add algorithm with modulus of table size and an XOR*/
  73478. +
  73479. +static __inline__ unsigned int
  73480. +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
  73481. +{
  73482. + return ((((uid + type) << (16 + type)) ^ uid) % sz);
  73483. +}
  73484. +
  73485. + static __inline__ unsigned int
  73486. +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
  73487. +{
  73488. + return ((const unsigned long)userp % sz);
  73489. +}
  73490. +
  73491. +static __inline__ unsigned int
  73492. +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
  73493. +{
  73494. + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
  73495. +}
  73496. +
  73497. +static __inline__ unsigned int
  73498. +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
  73499. +{
  73500. + return full_name_hash((const unsigned char *)name, len) % sz;
  73501. +}
  73502. +
  73503. +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
  73504. + subj = NULL; \
  73505. + iter = 0; \
  73506. + while (iter < role->subj_hash_size) { \
  73507. + if (subj == NULL) \
  73508. + subj = role->subj_hash[iter]; \
  73509. + if (subj == NULL) { \
  73510. + iter++; \
  73511. + continue; \
  73512. + }
  73513. +
  73514. +#define FOR_EACH_SUBJECT_END(subj,iter) \
  73515. + subj = subj->next; \
  73516. + if (subj == NULL) \
  73517. + iter++; \
  73518. + }
  73519. +
  73520. +
  73521. +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
  73522. + subj = role->hash->first; \
  73523. + while (subj != NULL) {
  73524. +
  73525. +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
  73526. + subj = subj->next; \
  73527. + }
  73528. +
  73529. +#endif
  73530. +
  73531. diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
  73532. new file mode 100644
  73533. index 0000000..33ebd1f
  73534. --- /dev/null
  73535. +++ b/include/linux/gracl_compat.h
  73536. @@ -0,0 +1,156 @@
  73537. +#ifndef GR_ACL_COMPAT_H
  73538. +#define GR_ACL_COMPAT_H
  73539. +
  73540. +#include <linux/resource.h>
  73541. +#include <asm/resource.h>
  73542. +
  73543. +struct sprole_pw_compat {
  73544. + compat_uptr_t rolename;
  73545. + unsigned char salt[GR_SALT_LEN];
  73546. + unsigned char sum[GR_SHA_LEN];
  73547. +};
  73548. +
  73549. +struct gr_hash_struct_compat {
  73550. + compat_uptr_t table;
  73551. + compat_uptr_t nametable;
  73552. + compat_uptr_t first;
  73553. + __u32 table_size;
  73554. + __u32 used_size;
  73555. + int type;
  73556. +};
  73557. +
  73558. +struct acl_subject_label_compat {
  73559. + compat_uptr_t filename;
  73560. + compat_ino_t inode;
  73561. + __u32 device;
  73562. + __u32 mode;
  73563. + kernel_cap_t cap_mask;
  73564. + kernel_cap_t cap_lower;
  73565. + kernel_cap_t cap_invert_audit;
  73566. +
  73567. + struct compat_rlimit res[GR_NLIMITS];
  73568. + __u32 resmask;
  73569. +
  73570. + __u8 user_trans_type;
  73571. + __u8 group_trans_type;
  73572. + compat_uptr_t user_transitions;
  73573. + compat_uptr_t group_transitions;
  73574. + __u16 user_trans_num;
  73575. + __u16 group_trans_num;
  73576. +
  73577. + __u32 sock_families[2];
  73578. + __u32 ip_proto[8];
  73579. + __u32 ip_type;
  73580. + compat_uptr_t ips;
  73581. + __u32 ip_num;
  73582. + __u32 inaddr_any_override;
  73583. +
  73584. + __u32 crashes;
  73585. + compat_ulong_t expires;
  73586. +
  73587. + compat_uptr_t parent_subject;
  73588. + compat_uptr_t hash;
  73589. + compat_uptr_t prev;
  73590. + compat_uptr_t next;
  73591. +
  73592. + compat_uptr_t obj_hash;
  73593. + __u32 obj_hash_size;
  73594. + __u16 pax_flags;
  73595. +};
  73596. +
  73597. +struct role_allowed_ip_compat {
  73598. + __u32 addr;
  73599. + __u32 netmask;
  73600. +
  73601. + compat_uptr_t prev;
  73602. + compat_uptr_t next;
  73603. +};
  73604. +
  73605. +struct role_transition_compat {
  73606. + compat_uptr_t rolename;
  73607. +
  73608. + compat_uptr_t prev;
  73609. + compat_uptr_t next;
  73610. +};
  73611. +
  73612. +struct acl_role_label_compat {
  73613. + compat_uptr_t rolename;
  73614. + uid_t uidgid;
  73615. + __u16 roletype;
  73616. +
  73617. + __u16 auth_attempts;
  73618. + compat_ulong_t expires;
  73619. +
  73620. + compat_uptr_t root_label;
  73621. + compat_uptr_t hash;
  73622. +
  73623. + compat_uptr_t prev;
  73624. + compat_uptr_t next;
  73625. +
  73626. + compat_uptr_t transitions;
  73627. + compat_uptr_t allowed_ips;
  73628. + compat_uptr_t domain_children;
  73629. + __u16 domain_child_num;
  73630. +
  73631. + umode_t umask;
  73632. +
  73633. + compat_uptr_t subj_hash;
  73634. + __u32 subj_hash_size;
  73635. +};
  73636. +
  73637. +struct user_acl_role_db_compat {
  73638. + compat_uptr_t r_table;
  73639. + __u32 num_pointers;
  73640. + __u32 num_roles;
  73641. + __u32 num_domain_children;
  73642. + __u32 num_subjects;
  73643. + __u32 num_objects;
  73644. +};
  73645. +
  73646. +struct acl_object_label_compat {
  73647. + compat_uptr_t filename;
  73648. + compat_ino_t inode;
  73649. + __u32 device;
  73650. + __u32 mode;
  73651. +
  73652. + compat_uptr_t nested;
  73653. + compat_uptr_t globbed;
  73654. +
  73655. + compat_uptr_t prev;
  73656. + compat_uptr_t next;
  73657. +};
  73658. +
  73659. +struct acl_ip_label_compat {
  73660. + compat_uptr_t iface;
  73661. + __u32 addr;
  73662. + __u32 netmask;
  73663. + __u16 low, high;
  73664. + __u8 mode;
  73665. + __u32 type;
  73666. + __u32 proto[8];
  73667. +
  73668. + compat_uptr_t prev;
  73669. + compat_uptr_t next;
  73670. +};
  73671. +
  73672. +struct gr_arg_compat {
  73673. + struct user_acl_role_db_compat role_db;
  73674. + unsigned char pw[GR_PW_LEN];
  73675. + unsigned char salt[GR_SALT_LEN];
  73676. + unsigned char sum[GR_SHA_LEN];
  73677. + unsigned char sp_role[GR_SPROLE_LEN];
  73678. + compat_uptr_t sprole_pws;
  73679. + __u32 segv_device;
  73680. + compat_ino_t segv_inode;
  73681. + uid_t segv_uid;
  73682. + __u16 num_sprole_pws;
  73683. + __u16 mode;
  73684. +};
  73685. +
  73686. +struct gr_arg_wrapper_compat {
  73687. + compat_uptr_t arg;
  73688. + __u32 version;
  73689. + __u32 size;
  73690. +};
  73691. +
  73692. +#endif
  73693. diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
  73694. new file mode 100644
  73695. index 0000000..323ecf2
  73696. --- /dev/null
  73697. +++ b/include/linux/gralloc.h
  73698. @@ -0,0 +1,9 @@
  73699. +#ifndef __GRALLOC_H
  73700. +#define __GRALLOC_H
  73701. +
  73702. +void acl_free_all(void);
  73703. +int acl_alloc_stack_init(unsigned long size);
  73704. +void *acl_alloc(unsigned long len);
  73705. +void *acl_alloc_num(unsigned long num, unsigned long len);
  73706. +
  73707. +#endif
  73708. diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
  73709. new file mode 100644
  73710. index 0000000..be66033
  73711. --- /dev/null
  73712. +++ b/include/linux/grdefs.h
  73713. @@ -0,0 +1,140 @@
  73714. +#ifndef GRDEFS_H
  73715. +#define GRDEFS_H
  73716. +
  73717. +/* Begin grsecurity status declarations */
  73718. +
  73719. +enum {
  73720. + GR_READY = 0x01,
  73721. + GR_STATUS_INIT = 0x00 // disabled state
  73722. +};
  73723. +
  73724. +/* Begin ACL declarations */
  73725. +
  73726. +/* Role flags */
  73727. +
  73728. +enum {
  73729. + GR_ROLE_USER = 0x0001,
  73730. + GR_ROLE_GROUP = 0x0002,
  73731. + GR_ROLE_DEFAULT = 0x0004,
  73732. + GR_ROLE_SPECIAL = 0x0008,
  73733. + GR_ROLE_AUTH = 0x0010,
  73734. + GR_ROLE_NOPW = 0x0020,
  73735. + GR_ROLE_GOD = 0x0040,
  73736. + GR_ROLE_LEARN = 0x0080,
  73737. + GR_ROLE_TPE = 0x0100,
  73738. + GR_ROLE_DOMAIN = 0x0200,
  73739. + GR_ROLE_PAM = 0x0400,
  73740. + GR_ROLE_PERSIST = 0x0800
  73741. +};
  73742. +
  73743. +/* ACL Subject and Object mode flags */
  73744. +enum {
  73745. + GR_DELETED = 0x80000000
  73746. +};
  73747. +
  73748. +/* ACL Object-only mode flags */
  73749. +enum {
  73750. + GR_READ = 0x00000001,
  73751. + GR_APPEND = 0x00000002,
  73752. + GR_WRITE = 0x00000004,
  73753. + GR_EXEC = 0x00000008,
  73754. + GR_FIND = 0x00000010,
  73755. + GR_INHERIT = 0x00000020,
  73756. + GR_SETID = 0x00000040,
  73757. + GR_CREATE = 0x00000080,
  73758. + GR_DELETE = 0x00000100,
  73759. + GR_LINK = 0x00000200,
  73760. + GR_AUDIT_READ = 0x00000400,
  73761. + GR_AUDIT_APPEND = 0x00000800,
  73762. + GR_AUDIT_WRITE = 0x00001000,
  73763. + GR_AUDIT_EXEC = 0x00002000,
  73764. + GR_AUDIT_FIND = 0x00004000,
  73765. + GR_AUDIT_INHERIT= 0x00008000,
  73766. + GR_AUDIT_SETID = 0x00010000,
  73767. + GR_AUDIT_CREATE = 0x00020000,
  73768. + GR_AUDIT_DELETE = 0x00040000,
  73769. + GR_AUDIT_LINK = 0x00080000,
  73770. + GR_PTRACERD = 0x00100000,
  73771. + GR_NOPTRACE = 0x00200000,
  73772. + GR_SUPPRESS = 0x00400000,
  73773. + GR_NOLEARN = 0x00800000,
  73774. + GR_INIT_TRANSFER= 0x01000000
  73775. +};
  73776. +
  73777. +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
  73778. + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
  73779. + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
  73780. +
  73781. +/* ACL subject-only mode flags */
  73782. +enum {
  73783. + GR_KILL = 0x00000001,
  73784. + GR_VIEW = 0x00000002,
  73785. + GR_PROTECTED = 0x00000004,
  73786. + GR_LEARN = 0x00000008,
  73787. + GR_OVERRIDE = 0x00000010,
  73788. + /* just a placeholder, this mode is only used in userspace */
  73789. + GR_DUMMY = 0x00000020,
  73790. + GR_PROTSHM = 0x00000040,
  73791. + GR_KILLPROC = 0x00000080,
  73792. + GR_KILLIPPROC = 0x00000100,
  73793. + /* just a placeholder, this mode is only used in userspace */
  73794. + GR_NOTROJAN = 0x00000200,
  73795. + GR_PROTPROCFD = 0x00000400,
  73796. + GR_PROCACCT = 0x00000800,
  73797. + GR_RELAXPTRACE = 0x00001000,
  73798. + //GR_NESTED = 0x00002000,
  73799. + GR_INHERITLEARN = 0x00004000,
  73800. + GR_PROCFIND = 0x00008000,
  73801. + GR_POVERRIDE = 0x00010000,
  73802. + GR_KERNELAUTH = 0x00020000,
  73803. + GR_ATSECURE = 0x00040000,
  73804. + GR_SHMEXEC = 0x00080000
  73805. +};
  73806. +
  73807. +enum {
  73808. + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
  73809. + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
  73810. + GR_PAX_ENABLE_MPROTECT = 0x0004,
  73811. + GR_PAX_ENABLE_RANDMMAP = 0x0008,
  73812. + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
  73813. + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
  73814. + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
  73815. + GR_PAX_DISABLE_MPROTECT = 0x0400,
  73816. + GR_PAX_DISABLE_RANDMMAP = 0x0800,
  73817. + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
  73818. +};
  73819. +
  73820. +enum {
  73821. + GR_ID_USER = 0x01,
  73822. + GR_ID_GROUP = 0x02,
  73823. +};
  73824. +
  73825. +enum {
  73826. + GR_ID_ALLOW = 0x01,
  73827. + GR_ID_DENY = 0x02,
  73828. +};
  73829. +
  73830. +#define GR_CRASH_RES 31
  73831. +#define GR_UIDTABLE_MAX 500
  73832. +
  73833. +/* begin resource learning section */
  73834. +enum {
  73835. + GR_RLIM_CPU_BUMP = 60,
  73836. + GR_RLIM_FSIZE_BUMP = 50000,
  73837. + GR_RLIM_DATA_BUMP = 10000,
  73838. + GR_RLIM_STACK_BUMP = 1000,
  73839. + GR_RLIM_CORE_BUMP = 10000,
  73840. + GR_RLIM_RSS_BUMP = 500000,
  73841. + GR_RLIM_NPROC_BUMP = 1,
  73842. + GR_RLIM_NOFILE_BUMP = 5,
  73843. + GR_RLIM_MEMLOCK_BUMP = 50000,
  73844. + GR_RLIM_AS_BUMP = 500000,
  73845. + GR_RLIM_LOCKS_BUMP = 2,
  73846. + GR_RLIM_SIGPENDING_BUMP = 5,
  73847. + GR_RLIM_MSGQUEUE_BUMP = 10000,
  73848. + GR_RLIM_NICE_BUMP = 1,
  73849. + GR_RLIM_RTPRIO_BUMP = 1,
  73850. + GR_RLIM_RTTIME_BUMP = 1000000
  73851. +};
  73852. +
  73853. +#endif
  73854. diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
  73855. new file mode 100644
  73856. index 0000000..d25522e
  73857. --- /dev/null
  73858. +++ b/include/linux/grinternal.h
  73859. @@ -0,0 +1,229 @@
  73860. +#ifndef __GRINTERNAL_H
  73861. +#define __GRINTERNAL_H
  73862. +
  73863. +#ifdef CONFIG_GRKERNSEC
  73864. +
  73865. +#include <linux/fs.h>
  73866. +#include <linux/mnt_namespace.h>
  73867. +#include <linux/nsproxy.h>
  73868. +#include <linux/gracl.h>
  73869. +#include <linux/grdefs.h>
  73870. +#include <linux/grmsg.h>
  73871. +
  73872. +void gr_add_learn_entry(const char *fmt, ...)
  73873. + __attribute__ ((format (printf, 1, 2)));
  73874. +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
  73875. + const struct vfsmount *mnt);
  73876. +__u32 gr_check_create(const struct dentry *new_dentry,
  73877. + const struct dentry *parent,
  73878. + const struct vfsmount *mnt, const __u32 mode);
  73879. +int gr_check_protected_task(const struct task_struct *task);
  73880. +__u32 to_gr_audit(const __u32 reqmode);
  73881. +int gr_set_acls(const int type);
  73882. +int gr_acl_is_enabled(void);
  73883. +char gr_roletype_to_char(void);
  73884. +
  73885. +void gr_handle_alertkill(struct task_struct *task);
  73886. +char *gr_to_filename(const struct dentry *dentry,
  73887. + const struct vfsmount *mnt);
  73888. +char *gr_to_filename1(const struct dentry *dentry,
  73889. + const struct vfsmount *mnt);
  73890. +char *gr_to_filename2(const struct dentry *dentry,
  73891. + const struct vfsmount *mnt);
  73892. +char *gr_to_filename3(const struct dentry *dentry,
  73893. + const struct vfsmount *mnt);
  73894. +
  73895. +extern int grsec_enable_ptrace_readexec;
  73896. +extern int grsec_enable_harden_ptrace;
  73897. +extern int grsec_enable_link;
  73898. +extern int grsec_enable_fifo;
  73899. +extern int grsec_enable_execve;
  73900. +extern int grsec_enable_shm;
  73901. +extern int grsec_enable_execlog;
  73902. +extern int grsec_enable_signal;
  73903. +extern int grsec_enable_audit_ptrace;
  73904. +extern int grsec_enable_forkfail;
  73905. +extern int grsec_enable_time;
  73906. +extern int grsec_enable_rofs;
  73907. +extern int grsec_deny_new_usb;
  73908. +extern int grsec_enable_chroot_shmat;
  73909. +extern int grsec_enable_chroot_mount;
  73910. +extern int grsec_enable_chroot_double;
  73911. +extern int grsec_enable_chroot_pivot;
  73912. +extern int grsec_enable_chroot_chdir;
  73913. +extern int grsec_enable_chroot_chmod;
  73914. +extern int grsec_enable_chroot_mknod;
  73915. +extern int grsec_enable_chroot_fchdir;
  73916. +extern int grsec_enable_chroot_nice;
  73917. +extern int grsec_enable_chroot_execlog;
  73918. +extern int grsec_enable_chroot_caps;
  73919. +extern int grsec_enable_chroot_sysctl;
  73920. +extern int grsec_enable_chroot_unix;
  73921. +extern int grsec_enable_symlinkown;
  73922. +extern kgid_t grsec_symlinkown_gid;
  73923. +extern int grsec_enable_tpe;
  73924. +extern kgid_t grsec_tpe_gid;
  73925. +extern int grsec_enable_tpe_all;
  73926. +extern int grsec_enable_tpe_invert;
  73927. +extern int grsec_enable_socket_all;
  73928. +extern kgid_t grsec_socket_all_gid;
  73929. +extern int grsec_enable_socket_client;
  73930. +extern kgid_t grsec_socket_client_gid;
  73931. +extern int grsec_enable_socket_server;
  73932. +extern kgid_t grsec_socket_server_gid;
  73933. +extern kgid_t grsec_audit_gid;
  73934. +extern int grsec_enable_group;
  73935. +extern int grsec_enable_log_rwxmaps;
  73936. +extern int grsec_enable_mount;
  73937. +extern int grsec_enable_chdir;
  73938. +extern int grsec_resource_logging;
  73939. +extern int grsec_enable_blackhole;
  73940. +extern int grsec_lastack_retries;
  73941. +extern int grsec_enable_brute;
  73942. +extern int grsec_enable_harden_ipc;
  73943. +extern int grsec_lock;
  73944. +
  73945. +extern spinlock_t grsec_alert_lock;
  73946. +extern unsigned long grsec_alert_wtime;
  73947. +extern unsigned long grsec_alert_fyet;
  73948. +
  73949. +extern spinlock_t grsec_audit_lock;
  73950. +
  73951. +extern rwlock_t grsec_exec_file_lock;
  73952. +
  73953. +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
  73954. + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
  73955. + (tsk)->exec_file->f_path.mnt) : "/")
  73956. +
  73957. +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
  73958. + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
  73959. + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
  73960. +
  73961. +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
  73962. + gr_to_filename((tsk)->exec_file->f_path.dentry, \
  73963. + (tsk)->exec_file->f_path.mnt) : "/")
  73964. +
  73965. +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
  73966. + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
  73967. + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
  73968. +
  73969. +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
  73970. +
  73971. +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
  73972. +
  73973. +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
  73974. +{
  73975. + if (file1 && file2) {
  73976. + const struct inode *inode1 = file1->f_path.dentry->d_inode;
  73977. + const struct inode *inode2 = file2->f_path.dentry->d_inode;
  73978. + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
  73979. + return true;
  73980. + }
  73981. +
  73982. + return false;
  73983. +}
  73984. +
  73985. +#define GR_CHROOT_CAPS {{ \
  73986. + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
  73987. + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
  73988. + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
  73989. + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
  73990. + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
  73991. + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
  73992. + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
  73993. +
  73994. +#define security_learn(normal_msg,args...) \
  73995. +({ \
  73996. + read_lock(&grsec_exec_file_lock); \
  73997. + gr_add_learn_entry(normal_msg "\n", ## args); \
  73998. + read_unlock(&grsec_exec_file_lock); \
  73999. +})
  74000. +
  74001. +enum {
  74002. + GR_DO_AUDIT,
  74003. + GR_DONT_AUDIT,
  74004. + /* used for non-audit messages that we shouldn't kill the task on */
  74005. + GR_DONT_AUDIT_GOOD
  74006. +};
  74007. +
  74008. +enum {
  74009. + GR_TTYSNIFF,
  74010. + GR_RBAC,
  74011. + GR_RBAC_STR,
  74012. + GR_STR_RBAC,
  74013. + GR_RBAC_MODE2,
  74014. + GR_RBAC_MODE3,
  74015. + GR_FILENAME,
  74016. + GR_SYSCTL_HIDDEN,
  74017. + GR_NOARGS,
  74018. + GR_ONE_INT,
  74019. + GR_ONE_INT_TWO_STR,
  74020. + GR_ONE_STR,
  74021. + GR_STR_INT,
  74022. + GR_TWO_STR_INT,
  74023. + GR_TWO_INT,
  74024. + GR_TWO_U64,
  74025. + GR_THREE_INT,
  74026. + GR_FIVE_INT_TWO_STR,
  74027. + GR_TWO_STR,
  74028. + GR_THREE_STR,
  74029. + GR_FOUR_STR,
  74030. + GR_STR_FILENAME,
  74031. + GR_FILENAME_STR,
  74032. + GR_FILENAME_TWO_INT,
  74033. + GR_FILENAME_TWO_INT_STR,
  74034. + GR_TEXTREL,
  74035. + GR_PTRACE,
  74036. + GR_RESOURCE,
  74037. + GR_CAP,
  74038. + GR_SIG,
  74039. + GR_SIG2,
  74040. + GR_CRASH1,
  74041. + GR_CRASH2,
  74042. + GR_PSACCT,
  74043. + GR_RWXMAP,
  74044. + GR_RWXMAPVMA
  74045. +};
  74046. +
  74047. +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
  74048. +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
  74049. +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
  74050. +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
  74051. +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
  74052. +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
  74053. +#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
  74054. +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
  74055. +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
  74056. +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
  74057. +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
  74058. +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
  74059. +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
  74060. +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
  74061. +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
  74062. +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
  74063. +#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
  74064. +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
  74065. +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
  74066. +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
  74067. +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
  74068. +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
  74069. +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
  74070. +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
  74071. +#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
  74072. +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
  74073. +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
  74074. +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
  74075. +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
  74076. +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
  74077. +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
  74078. +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
  74079. +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
  74080. +#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
  74081. +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
  74082. +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
  74083. +
  74084. +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
  74085. +
  74086. +#endif
  74087. +
  74088. +#endif
  74089. diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
  74090. new file mode 100644
  74091. index 0000000..ba93581
  74092. --- /dev/null
  74093. +++ b/include/linux/grmsg.h
  74094. @@ -0,0 +1,116 @@
  74095. +#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
  74096. +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
  74097. +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
  74098. +#define GR_STOPMOD_MSG "denied modification of module state by "
  74099. +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
  74100. +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
  74101. +#define GR_IOPERM_MSG "denied use of ioperm() by "
  74102. +#define GR_IOPL_MSG "denied use of iopl() by "
  74103. +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
  74104. +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
  74105. +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
  74106. +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
  74107. +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
  74108. +#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%pI4"
  74109. +#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%pI4"
  74110. +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
  74111. +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
  74112. +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
  74113. +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
  74114. +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
  74115. +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
  74116. +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
  74117. +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
  74118. +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
  74119. +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
  74120. +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
  74121. +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
  74122. +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
  74123. +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
  74124. +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
  74125. +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
  74126. +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
  74127. +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
  74128. +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
  74129. +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
  74130. +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
  74131. +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
  74132. +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
  74133. +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
  74134. +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
  74135. +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
  74136. +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
  74137. +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
  74138. +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
  74139. +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
  74140. +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
  74141. +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
  74142. +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
  74143. +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
  74144. +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
  74145. +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
  74146. +#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
  74147. +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
  74148. +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
  74149. +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
  74150. +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
  74151. +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
  74152. +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
  74153. +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
  74154. +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
  74155. +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
  74156. +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
  74157. +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
  74158. +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
  74159. +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
  74160. +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
  74161. +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
  74162. +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
  74163. +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
  74164. +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
  74165. +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
  74166. +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
  74167. +#define GR_FAILFORK_MSG "failed fork with errno %s by "
  74168. +#define GR_NICE_CHROOT_MSG "denied priority change by "
  74169. +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
  74170. +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
  74171. +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
  74172. +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
  74173. +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
  74174. +#define GR_TIME_MSG "time set by "
  74175. +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
  74176. +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
  74177. +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
  74178. +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
  74179. +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
  74180. +#define GR_BIND_MSG "denied bind() by "
  74181. +#define GR_CONNECT_MSG "denied connect() by "
  74182. +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
  74183. +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
  74184. +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
  74185. +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
  74186. +#define GR_CAP_ACL_MSG "use of %s denied for "
  74187. +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
  74188. +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
  74189. +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
  74190. +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
  74191. +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
  74192. +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
  74193. +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
  74194. +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
  74195. +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
  74196. +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
  74197. +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
  74198. +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
  74199. +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
  74200. +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
  74201. +#define GR_VM86_MSG "denied use of vm86 by "
  74202. +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
  74203. +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
  74204. +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
  74205. +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
  74206. +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
  74207. +#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
  74208. +#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
  74209. +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
  74210. +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
  74211. diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
  74212. new file mode 100644
  74213. index 0000000..f2d8c6c
  74214. --- /dev/null
  74215. +++ b/include/linux/grsecurity.h
  74216. @@ -0,0 +1,248 @@
  74217. +#ifndef GR_SECURITY_H
  74218. +#define GR_SECURITY_H
  74219. +#include <linux/fs.h>
  74220. +#include <linux/fs_struct.h>
  74221. +#include <linux/binfmts.h>
  74222. +#include <linux/gracl.h>
  74223. +
  74224. +/* notify of brain-dead configs */
  74225. +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  74226. +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
  74227. +#endif
  74228. +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
  74229. +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
  74230. +#endif
  74231. +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
  74232. +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
  74233. +#endif
  74234. +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
  74235. +#error "CONFIG_PAX enabled, but no PaX options are enabled."
  74236. +#endif
  74237. +
  74238. +int gr_handle_new_usb(void);
  74239. +
  74240. +void gr_handle_brute_attach(int dumpable);
  74241. +void gr_handle_brute_check(void);
  74242. +void gr_handle_kernel_exploit(void);
  74243. +
  74244. +char gr_roletype_to_char(void);
  74245. +
  74246. +int gr_proc_is_restricted(void);
  74247. +
  74248. +int gr_acl_enable_at_secure(void);
  74249. +
  74250. +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
  74251. +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
  74252. +
  74253. +void gr_del_task_from_ip_table(struct task_struct *p);
  74254. +
  74255. +int gr_pid_is_chrooted(struct task_struct *p);
  74256. +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
  74257. +int gr_handle_chroot_nice(void);
  74258. +int gr_handle_chroot_sysctl(const int op);
  74259. +int gr_handle_chroot_setpriority(struct task_struct *p,
  74260. + const int niceval);
  74261. +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
  74262. +int gr_handle_chroot_chroot(const struct dentry *dentry,
  74263. + const struct vfsmount *mnt);
  74264. +void gr_handle_chroot_chdir(const struct path *path);
  74265. +int gr_handle_chroot_chmod(const struct dentry *dentry,
  74266. + const struct vfsmount *mnt, const int mode);
  74267. +int gr_handle_chroot_mknod(const struct dentry *dentry,
  74268. + const struct vfsmount *mnt, const int mode);
  74269. +int gr_handle_chroot_mount(const struct dentry *dentry,
  74270. + const struct vfsmount *mnt,
  74271. + const char *dev_name);
  74272. +int gr_handle_chroot_pivot(void);
  74273. +int gr_handle_chroot_unix(const pid_t pid);
  74274. +
  74275. +int gr_handle_rawio(const struct inode *inode);
  74276. +
  74277. +void gr_handle_ioperm(void);
  74278. +void gr_handle_iopl(void);
  74279. +void gr_handle_msr_write(void);
  74280. +
  74281. +umode_t gr_acl_umask(void);
  74282. +
  74283. +int gr_tpe_allow(const struct file *file);
  74284. +
  74285. +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
  74286. +void gr_clear_chroot_entries(struct task_struct *task);
  74287. +
  74288. +void gr_log_forkfail(const int retval);
  74289. +void gr_log_timechange(void);
  74290. +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
  74291. +void gr_log_chdir(const struct dentry *dentry,
  74292. + const struct vfsmount *mnt);
  74293. +void gr_log_chroot_exec(const struct dentry *dentry,
  74294. + const struct vfsmount *mnt);
  74295. +void gr_log_remount(const char *devname, const int retval);
  74296. +void gr_log_unmount(const char *devname, const int retval);
  74297. +void gr_log_mount(const char *from, const char *to, const int retval);
  74298. +void gr_log_textrel(struct vm_area_struct *vma);
  74299. +void gr_log_ptgnustack(struct file *file);
  74300. +void gr_log_rwxmmap(struct file *file);
  74301. +void gr_log_rwxmprotect(struct vm_area_struct *vma);
  74302. +
  74303. +int gr_handle_follow_link(const struct inode *parent,
  74304. + const struct inode *inode,
  74305. + const struct dentry *dentry,
  74306. + const struct vfsmount *mnt);
  74307. +int gr_handle_fifo(const struct dentry *dentry,
  74308. + const struct vfsmount *mnt,
  74309. + const struct dentry *dir, const int flag,
  74310. + const int acc_mode);
  74311. +int gr_handle_hardlink(const struct dentry *dentry,
  74312. + const struct vfsmount *mnt,
  74313. + struct inode *inode,
  74314. + const int mode, const struct filename *to);
  74315. +
  74316. +int gr_is_capable(const int cap);
  74317. +int gr_is_capable_nolog(const int cap);
  74318. +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
  74319. +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
  74320. +
  74321. +void gr_copy_label(struct task_struct *tsk);
  74322. +void gr_handle_crash(struct task_struct *task, const int sig);
  74323. +int gr_handle_signal(const struct task_struct *p, const int sig);
  74324. +int gr_check_crash_uid(const kuid_t uid);
  74325. +int gr_check_protected_task(const struct task_struct *task);
  74326. +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
  74327. +int gr_acl_handle_mmap(const struct file *file,
  74328. + const unsigned long prot);
  74329. +int gr_acl_handle_mprotect(const struct file *file,
  74330. + const unsigned long prot);
  74331. +int gr_check_hidden_task(const struct task_struct *tsk);
  74332. +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
  74333. + const struct vfsmount *mnt);
  74334. +__u32 gr_acl_handle_utime(const struct dentry *dentry,
  74335. + const struct vfsmount *mnt);
  74336. +__u32 gr_acl_handle_access(const struct dentry *dentry,
  74337. + const struct vfsmount *mnt, const int fmode);
  74338. +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
  74339. + const struct vfsmount *mnt, umode_t *mode);
  74340. +__u32 gr_acl_handle_chown(const struct dentry *dentry,
  74341. + const struct vfsmount *mnt);
  74342. +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
  74343. + const struct vfsmount *mnt);
  74344. +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
  74345. + const struct vfsmount *mnt);
  74346. +int gr_handle_ptrace(struct task_struct *task, const long request);
  74347. +int gr_handle_proc_ptrace(struct task_struct *task);
  74348. +__u32 gr_acl_handle_execve(const struct dentry *dentry,
  74349. + const struct vfsmount *mnt);
  74350. +int gr_check_crash_exec(const struct file *filp);
  74351. +int gr_acl_is_enabled(void);
  74352. +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
  74353. + const kgid_t gid);
  74354. +int gr_set_proc_label(const struct dentry *dentry,
  74355. + const struct vfsmount *mnt,
  74356. + const int unsafe_flags);
  74357. +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
  74358. + const struct vfsmount *mnt);
  74359. +__u32 gr_acl_handle_open(const struct dentry *dentry,
  74360. + const struct vfsmount *mnt, int acc_mode);
  74361. +__u32 gr_acl_handle_creat(const struct dentry *dentry,
  74362. + const struct dentry *p_dentry,
  74363. + const struct vfsmount *p_mnt,
  74364. + int open_flags, int acc_mode, const int imode);
  74365. +void gr_handle_create(const struct dentry *dentry,
  74366. + const struct vfsmount *mnt);
  74367. +void gr_handle_proc_create(const struct dentry *dentry,
  74368. + const struct inode *inode);
  74369. +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
  74370. + const struct dentry *parent_dentry,
  74371. + const struct vfsmount *parent_mnt,
  74372. + const int mode);
  74373. +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
  74374. + const struct dentry *parent_dentry,
  74375. + const struct vfsmount *parent_mnt);
  74376. +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
  74377. + const struct vfsmount *mnt);
  74378. +void gr_handle_delete(const ino_t ino, const dev_t dev);
  74379. +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
  74380. + const struct vfsmount *mnt);
  74381. +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
  74382. + const struct dentry *parent_dentry,
  74383. + const struct vfsmount *parent_mnt,
  74384. + const struct filename *from);
  74385. +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
  74386. + const struct dentry *parent_dentry,
  74387. + const struct vfsmount *parent_mnt,
  74388. + const struct dentry *old_dentry,
  74389. + const struct vfsmount *old_mnt, const struct filename *to);
  74390. +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
  74391. +int gr_acl_handle_rename(struct dentry *new_dentry,
  74392. + struct dentry *parent_dentry,
  74393. + const struct vfsmount *parent_mnt,
  74394. + struct dentry *old_dentry,
  74395. + struct inode *old_parent_inode,
  74396. + struct vfsmount *old_mnt, const struct filename *newname);
  74397. +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
  74398. + struct dentry *old_dentry,
  74399. + struct dentry *new_dentry,
  74400. + struct vfsmount *mnt, const __u8 replace);
  74401. +__u32 gr_check_link(const struct dentry *new_dentry,
  74402. + const struct dentry *parent_dentry,
  74403. + const struct vfsmount *parent_mnt,
  74404. + const struct dentry *old_dentry,
  74405. + const struct vfsmount *old_mnt);
  74406. +int gr_acl_handle_filldir(const struct file *file, const char *name,
  74407. + const unsigned int namelen, const ino_t ino);
  74408. +
  74409. +__u32 gr_acl_handle_unix(const struct dentry *dentry,
  74410. + const struct vfsmount *mnt);
  74411. +void gr_acl_handle_exit(void);
  74412. +void gr_acl_handle_psacct(struct task_struct *task, const long code);
  74413. +int gr_acl_handle_procpidmem(const struct task_struct *task);
  74414. +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
  74415. +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
  74416. +void gr_audit_ptrace(struct task_struct *task);
  74417. +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
  74418. +void gr_put_exec_file(struct task_struct *task);
  74419. +
  74420. +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
  74421. +
  74422. +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
  74423. +extern void gr_learn_resource(const struct task_struct *task, const int res,
  74424. + const unsigned long wanted, const int gt);
  74425. +#else
  74426. +static inline void gr_learn_resource(const struct task_struct *task, const int res,
  74427. + const unsigned long wanted, const int gt)
  74428. +{
  74429. +}
  74430. +#endif
  74431. +
  74432. +#ifdef CONFIG_GRKERNSEC_RESLOG
  74433. +extern void gr_log_resource(const struct task_struct *task, const int res,
  74434. + const unsigned long wanted, const int gt);
  74435. +#else
  74436. +static inline void gr_log_resource(const struct task_struct *task, const int res,
  74437. + const unsigned long wanted, const int gt)
  74438. +{
  74439. +}
  74440. +#endif
  74441. +
  74442. +#ifdef CONFIG_GRKERNSEC
  74443. +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
  74444. +void gr_handle_vm86(void);
  74445. +void gr_handle_mem_readwrite(u64 from, u64 to);
  74446. +
  74447. +void gr_log_badprocpid(const char *entry);
  74448. +
  74449. +extern int grsec_enable_dmesg;
  74450. +extern int grsec_disable_privio;
  74451. +
  74452. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  74453. +extern kgid_t grsec_proc_gid;
  74454. +#endif
  74455. +
  74456. +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
  74457. +extern int grsec_enable_chroot_findtask;
  74458. +#endif
  74459. +#ifdef CONFIG_GRKERNSEC_SETXID
  74460. +extern int grsec_enable_setxid;
  74461. +#endif
  74462. +#endif
  74463. +
  74464. +#endif
  74465. diff --git a/include/linux/grsock.h b/include/linux/grsock.h
  74466. new file mode 100644
  74467. index 0000000..e7ffaaf
  74468. --- /dev/null
  74469. +++ b/include/linux/grsock.h
  74470. @@ -0,0 +1,19 @@
  74471. +#ifndef __GRSOCK_H
  74472. +#define __GRSOCK_H
  74473. +
  74474. +extern void gr_attach_curr_ip(const struct sock *sk);
  74475. +extern int gr_handle_sock_all(const int family, const int type,
  74476. + const int protocol);
  74477. +extern int gr_handle_sock_server(const struct sockaddr *sck);
  74478. +extern int gr_handle_sock_server_other(const struct sock *sck);
  74479. +extern int gr_handle_sock_client(const struct sockaddr *sck);
  74480. +extern int gr_search_connect(struct socket * sock,
  74481. + struct sockaddr_in * addr);
  74482. +extern int gr_search_bind(struct socket * sock,
  74483. + struct sockaddr_in * addr);
  74484. +extern int gr_search_listen(struct socket * sock);
  74485. +extern int gr_search_accept(struct socket * sock);
  74486. +extern int gr_search_socket(const int domain, const int type,
  74487. + const int protocol);
  74488. +
  74489. +#endif
  74490. diff --git a/include/linux/hash.h b/include/linux/hash.h
  74491. index bd1754c..8240892 100644
  74492. --- a/include/linux/hash.h
  74493. +++ b/include/linux/hash.h
  74494. @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
  74495. struct fast_hash_ops {
  74496. u32 (*hash)(const void *data, u32 len, u32 seed);
  74497. u32 (*hash2)(const u32 *data, u32 len, u32 seed);
  74498. -};
  74499. +} __no_const;
  74500. /**
  74501. * arch_fast_hash - Caclulates a hash over a given buffer that can have
  74502. diff --git a/include/linux/highmem.h b/include/linux/highmem.h
  74503. index 7fb31da..08b5114 100644
  74504. --- a/include/linux/highmem.h
  74505. +++ b/include/linux/highmem.h
  74506. @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
  74507. kunmap_atomic(kaddr);
  74508. }
  74509. +static inline void sanitize_highpage(struct page *page)
  74510. +{
  74511. + void *kaddr;
  74512. + unsigned long flags;
  74513. +
  74514. + local_irq_save(flags);
  74515. + kaddr = kmap_atomic(page);
  74516. + clear_page(kaddr);
  74517. + kunmap_atomic(kaddr);
  74518. + local_irq_restore(flags);
  74519. +}
  74520. +
  74521. static inline void zero_user_segments(struct page *page,
  74522. unsigned start1, unsigned end1,
  74523. unsigned start2, unsigned end2)
  74524. diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
  74525. index 1c7b89a..7dda400 100644
  74526. --- a/include/linux/hwmon-sysfs.h
  74527. +++ b/include/linux/hwmon-sysfs.h
  74528. @@ -25,7 +25,8 @@
  74529. struct sensor_device_attribute{
  74530. struct device_attribute dev_attr;
  74531. int index;
  74532. -};
  74533. +} __do_const;
  74534. +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
  74535. #define to_sensor_dev_attr(_dev_attr) \
  74536. container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
  74537. @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
  74538. struct device_attribute dev_attr;
  74539. u8 index;
  74540. u8 nr;
  74541. -};
  74542. +} __do_const;
  74543. +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
  74544. #define to_sensor_dev_attr_2(_dev_attr) \
  74545. container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
  74546. diff --git a/include/linux/i2c.h b/include/linux/i2c.h
  74547. index deddeb8..bcaf62d 100644
  74548. --- a/include/linux/i2c.h
  74549. +++ b/include/linux/i2c.h
  74550. @@ -378,6 +378,7 @@ struct i2c_algorithm {
  74551. /* To determine what the adapter supports */
  74552. u32 (*functionality) (struct i2c_adapter *);
  74553. };
  74554. +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
  74555. /**
  74556. * struct i2c_bus_recovery_info - I2C bus recovery information
  74557. diff --git a/include/linux/i2o.h b/include/linux/i2o.h
  74558. index d23c3c2..eb63c81 100644
  74559. --- a/include/linux/i2o.h
  74560. +++ b/include/linux/i2o.h
  74561. @@ -565,7 +565,7 @@ struct i2o_controller {
  74562. struct i2o_device *exec; /* Executive */
  74563. #if BITS_PER_LONG == 64
  74564. spinlock_t context_list_lock; /* lock for context_list */
  74565. - atomic_t context_list_counter; /* needed for unique contexts */
  74566. + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
  74567. struct list_head context_list; /* list of context id's
  74568. and pointers */
  74569. #endif
  74570. diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
  74571. index aff7ad8..3942bbd 100644
  74572. --- a/include/linux/if_pppox.h
  74573. +++ b/include/linux/if_pppox.h
  74574. @@ -76,7 +76,7 @@ struct pppox_proto {
  74575. int (*ioctl)(struct socket *sock, unsigned int cmd,
  74576. unsigned long arg);
  74577. struct module *owner;
  74578. -};
  74579. +} __do_const;
  74580. extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
  74581. extern void unregister_pppox_proto(int proto_num);
  74582. diff --git a/include/linux/init.h b/include/linux/init.h
  74583. index e168880..d9b489d 100644
  74584. --- a/include/linux/init.h
  74585. +++ b/include/linux/init.h
  74586. @@ -37,9 +37,17 @@
  74587. * section.
  74588. */
  74589. +#define add_init_latent_entropy __latent_entropy
  74590. +
  74591. +#ifdef CONFIG_MEMORY_HOTPLUG
  74592. +#define add_meminit_latent_entropy
  74593. +#else
  74594. +#define add_meminit_latent_entropy __latent_entropy
  74595. +#endif
  74596. +
  74597. /* These are for everybody (although not all archs will actually
  74598. discard it in modules) */
  74599. -#define __init __section(.init.text) __cold notrace
  74600. +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
  74601. #define __initdata __section(.init.data)
  74602. #define __initconst __constsection(.init.rodata)
  74603. #define __exitdata __section(.exit.data)
  74604. @@ -100,7 +108,7 @@
  74605. #define __cpuexitconst
  74606. /* Used for MEMORY_HOTPLUG */
  74607. -#define __meminit __section(.meminit.text) __cold notrace
  74608. +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
  74609. #define __meminitdata __section(.meminit.data)
  74610. #define __meminitconst __constsection(.meminit.rodata)
  74611. #define __memexit __section(.memexit.text) __exitused __cold notrace
  74612. diff --git a/include/linux/init_task.h b/include/linux/init_task.h
  74613. index 6df7f9f..d0bf699 100644
  74614. --- a/include/linux/init_task.h
  74615. +++ b/include/linux/init_task.h
  74616. @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
  74617. #define INIT_TASK_COMM "swapper"
  74618. +#ifdef CONFIG_X86
  74619. +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
  74620. +#else
  74621. +#define INIT_TASK_THREAD_INFO
  74622. +#endif
  74623. +
  74624. #ifdef CONFIG_RT_MUTEXES
  74625. # define INIT_RT_MUTEXES(tsk) \
  74626. .pi_waiters = RB_ROOT, \
  74627. @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
  74628. RCU_POINTER_INITIALIZER(cred, &init_cred), \
  74629. .comm = INIT_TASK_COMM, \
  74630. .thread = INIT_THREAD, \
  74631. + INIT_TASK_THREAD_INFO \
  74632. .fs = &init_fs, \
  74633. .files = &init_files, \
  74634. .signal = &init_signals, \
  74635. diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
  74636. index a2678d3..e411b1b 100644
  74637. --- a/include/linux/interrupt.h
  74638. +++ b/include/linux/interrupt.h
  74639. @@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
  74640. struct softirq_action
  74641. {
  74642. - void (*action)(struct softirq_action *);
  74643. -};
  74644. + void (*action)(void);
  74645. +} __no_const;
  74646. asmlinkage void do_softirq(void);
  74647. asmlinkage void __do_softirq(void);
  74648. @@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
  74649. }
  74650. #endif
  74651. -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  74652. +extern void open_softirq(int nr, void (*action)(void));
  74653. extern void softirq_init(void);
  74654. extern void __raise_softirq_irqoff(unsigned int nr);
  74655. diff --git a/include/linux/iommu.h b/include/linux/iommu.h
  74656. index b96a5b2..2732d1c 100644
  74657. --- a/include/linux/iommu.h
  74658. +++ b/include/linux/iommu.h
  74659. @@ -131,7 +131,7 @@ struct iommu_ops {
  74660. u32 (*domain_get_windows)(struct iommu_domain *domain);
  74661. unsigned long pgsize_bitmap;
  74662. -};
  74663. +} __do_const;
  74664. #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
  74665. #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
  74666. diff --git a/include/linux/ioport.h b/include/linux/ioport.h
  74667. index 89b7c24..382af74 100644
  74668. --- a/include/linux/ioport.h
  74669. +++ b/include/linux/ioport.h
  74670. @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
  74671. int adjust_resource(struct resource *res, resource_size_t start,
  74672. resource_size_t size);
  74673. resource_size_t resource_alignment(struct resource *res);
  74674. -static inline resource_size_t resource_size(const struct resource *res)
  74675. +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
  74676. {
  74677. return res->end - res->start + 1;
  74678. }
  74679. diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
  74680. index 35e7eca..6afb7ad 100644
  74681. --- a/include/linux/ipc_namespace.h
  74682. +++ b/include/linux/ipc_namespace.h
  74683. @@ -69,7 +69,7 @@ struct ipc_namespace {
  74684. struct user_namespace *user_ns;
  74685. unsigned int proc_inum;
  74686. -};
  74687. +} __randomize_layout;
  74688. extern struct ipc_namespace init_ipc_ns;
  74689. extern atomic_t nr_ipc_ns;
  74690. diff --git a/include/linux/irq.h b/include/linux/irq.h
  74691. index 7dc1003..407327b 100644
  74692. --- a/include/linux/irq.h
  74693. +++ b/include/linux/irq.h
  74694. @@ -338,7 +338,8 @@ struct irq_chip {
  74695. void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
  74696. unsigned long flags;
  74697. -};
  74698. +} __do_const;
  74699. +typedef struct irq_chip __no_const irq_chip_no_const;
  74700. /*
  74701. * irq_chip specific flags
  74702. diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
  74703. index 0ceb389..eed3fb8 100644
  74704. --- a/include/linux/irqchip/arm-gic.h
  74705. +++ b/include/linux/irqchip/arm-gic.h
  74706. @@ -73,9 +73,11 @@
  74707. #ifndef __ASSEMBLY__
  74708. +#include <linux/irq.h>
  74709. +
  74710. struct device_node;
  74711. -extern struct irq_chip gic_arch_extn;
  74712. +extern irq_chip_no_const gic_arch_extn;
  74713. void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
  74714. u32 offset, struct device_node *);
  74715. diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
  74716. index 1f44466..b481806 100644
  74717. --- a/include/linux/jiffies.h
  74718. +++ b/include/linux/jiffies.h
  74719. @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
  74720. /*
  74721. * Convert various time units to each other:
  74722. */
  74723. -extern unsigned int jiffies_to_msecs(const unsigned long j);
  74724. -extern unsigned int jiffies_to_usecs(const unsigned long j);
  74725. +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
  74726. +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
  74727. -static inline u64 jiffies_to_nsecs(const unsigned long j)
  74728. +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
  74729. {
  74730. return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
  74731. }
  74732. -extern unsigned long msecs_to_jiffies(const unsigned int m);
  74733. -extern unsigned long usecs_to_jiffies(const unsigned int u);
  74734. +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
  74735. +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
  74736. extern unsigned long timespec_to_jiffies(const struct timespec *value);
  74737. extern void jiffies_to_timespec(const unsigned long jiffies,
  74738. - struct timespec *value);
  74739. -extern unsigned long timeval_to_jiffies(const struct timeval *value);
  74740. + struct timespec *value) __intentional_overflow(-1);
  74741. +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
  74742. extern void jiffies_to_timeval(const unsigned long jiffies,
  74743. struct timeval *value);
  74744. diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
  74745. index 6883e19..e854fcb 100644
  74746. --- a/include/linux/kallsyms.h
  74747. +++ b/include/linux/kallsyms.h
  74748. @@ -15,7 +15,8 @@
  74749. struct module;
  74750. -#ifdef CONFIG_KALLSYMS
  74751. +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
  74752. +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  74753. /* Lookup the address for a symbol. Returns 0 if not found. */
  74754. unsigned long kallsyms_lookup_name(const char *name);
  74755. @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
  74756. /* Stupid that this does nothing, but I didn't create this mess. */
  74757. #define __print_symbol(fmt, addr)
  74758. #endif /*CONFIG_KALLSYMS*/
  74759. +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
  74760. + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
  74761. +extern unsigned long kallsyms_lookup_name(const char *name);
  74762. +extern void __print_symbol(const char *fmt, unsigned long address);
  74763. +extern int sprint_backtrace(char *buffer, unsigned long address);
  74764. +extern int sprint_symbol(char *buffer, unsigned long address);
  74765. +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
  74766. +const char *kallsyms_lookup(unsigned long addr,
  74767. + unsigned long *symbolsize,
  74768. + unsigned long *offset,
  74769. + char **modname, char *namebuf);
  74770. +extern int kallsyms_lookup_size_offset(unsigned long addr,
  74771. + unsigned long *symbolsize,
  74772. + unsigned long *offset);
  74773. +#endif
  74774. /* This macro allows us to keep printk typechecking */
  74775. static __printf(1, 2)
  74776. diff --git a/include/linux/key-type.h b/include/linux/key-type.h
  74777. index a74c3a8..28d3f21 100644
  74778. --- a/include/linux/key-type.h
  74779. +++ b/include/linux/key-type.h
  74780. @@ -131,7 +131,7 @@ struct key_type {
  74781. /* internal fields */
  74782. struct list_head link; /* link in types list */
  74783. struct lock_class_key lock_class; /* key->sem lock class */
  74784. -};
  74785. +} __do_const;
  74786. extern struct key_type key_type_keyring;
  74787. diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
  74788. index 6b06d37..c134867 100644
  74789. --- a/include/linux/kgdb.h
  74790. +++ b/include/linux/kgdb.h
  74791. @@ -52,7 +52,7 @@ extern int kgdb_connected;
  74792. extern int kgdb_io_module_registered;
  74793. extern atomic_t kgdb_setting_breakpoint;
  74794. -extern atomic_t kgdb_cpu_doing_single_step;
  74795. +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
  74796. extern struct task_struct *kgdb_usethread;
  74797. extern struct task_struct *kgdb_contthread;
  74798. @@ -254,7 +254,7 @@ struct kgdb_arch {
  74799. void (*correct_hw_break)(void);
  74800. void (*enable_nmi)(bool on);
  74801. -};
  74802. +} __do_const;
  74803. /**
  74804. * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
  74805. @@ -279,7 +279,7 @@ struct kgdb_io {
  74806. void (*pre_exception) (void);
  74807. void (*post_exception) (void);
  74808. int is_console;
  74809. -};
  74810. +} __do_const;
  74811. extern struct kgdb_arch arch_kgdb_ops;
  74812. diff --git a/include/linux/kmod.h b/include/linux/kmod.h
  74813. index 0555cc6..40116ce 100644
  74814. --- a/include/linux/kmod.h
  74815. +++ b/include/linux/kmod.h
  74816. @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
  74817. * usually useless though. */
  74818. extern __printf(2, 3)
  74819. int __request_module(bool wait, const char *name, ...);
  74820. +extern __printf(3, 4)
  74821. +int ___request_module(bool wait, char *param_name, const char *name, ...);
  74822. #define request_module(mod...) __request_module(true, mod)
  74823. #define request_module_nowait(mod...) __request_module(false, mod)
  74824. #define try_then_request_module(x, mod...) \
  74825. @@ -57,6 +59,9 @@ struct subprocess_info {
  74826. struct work_struct work;
  74827. struct completion *complete;
  74828. char *path;
  74829. +#ifdef CONFIG_GRKERNSEC
  74830. + char *origpath;
  74831. +#endif
  74832. char **argv;
  74833. char **envp;
  74834. int wait;
  74835. diff --git a/include/linux/kobject.h b/include/linux/kobject.h
  74836. index 926afb6..58dd6e5 100644
  74837. --- a/include/linux/kobject.h
  74838. +++ b/include/linux/kobject.h
  74839. @@ -116,7 +116,7 @@ struct kobj_type {
  74840. struct attribute **default_attrs;
  74841. const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
  74842. const void *(*namespace)(struct kobject *kobj);
  74843. -};
  74844. +} __do_const;
  74845. struct kobj_uevent_env {
  74846. char *envp[UEVENT_NUM_ENVP];
  74847. @@ -139,6 +139,7 @@ struct kobj_attribute {
  74848. ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
  74849. const char *buf, size_t count);
  74850. };
  74851. +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
  74852. extern const struct sysfs_ops kobj_sysfs_ops;
  74853. @@ -166,7 +167,7 @@ struct kset {
  74854. spinlock_t list_lock;
  74855. struct kobject kobj;
  74856. const struct kset_uevent_ops *uevent_ops;
  74857. -};
  74858. +} __randomize_layout;
  74859. extern void kset_init(struct kset *kset);
  74860. extern int __must_check kset_register(struct kset *kset);
  74861. diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
  74862. index df32d25..fb52e27 100644
  74863. --- a/include/linux/kobject_ns.h
  74864. +++ b/include/linux/kobject_ns.h
  74865. @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
  74866. const void *(*netlink_ns)(struct sock *sk);
  74867. const void *(*initial_ns)(void);
  74868. void (*drop_ns)(void *);
  74869. -};
  74870. +} __do_const;
  74871. int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
  74872. int kobj_ns_type_registered(enum kobj_ns_type type);
  74873. diff --git a/include/linux/kref.h b/include/linux/kref.h
  74874. index 484604d..0f6c5b6 100644
  74875. --- a/include/linux/kref.h
  74876. +++ b/include/linux/kref.h
  74877. @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
  74878. static inline int kref_sub(struct kref *kref, unsigned int count,
  74879. void (*release)(struct kref *kref))
  74880. {
  74881. - WARN_ON(release == NULL);
  74882. + BUG_ON(release == NULL);
  74883. if (atomic_sub_and_test((int) count, &kref->refcount)) {
  74884. release(kref);
  74885. diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
  74886. index b8e9a43..632678d 100644
  74887. --- a/include/linux/kvm_host.h
  74888. +++ b/include/linux/kvm_host.h
  74889. @@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
  74890. {
  74891. }
  74892. #endif
  74893. -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  74894. +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  74895. struct module *module);
  74896. void kvm_exit(void);
  74897. @@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
  74898. struct kvm_guest_debug *dbg);
  74899. int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
  74900. -int kvm_arch_init(void *opaque);
  74901. +int kvm_arch_init(const void *opaque);
  74902. void kvm_arch_exit(void);
  74903. int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
  74904. diff --git a/include/linux/libata.h b/include/linux/libata.h
  74905. index 3fee55e..42565b7 100644
  74906. --- a/include/linux/libata.h
  74907. +++ b/include/linux/libata.h
  74908. @@ -976,7 +976,7 @@ struct ata_port_operations {
  74909. * fields must be pointers.
  74910. */
  74911. const struct ata_port_operations *inherits;
  74912. -};
  74913. +} __do_const;
  74914. struct ata_port_info {
  74915. unsigned long flags;
  74916. diff --git a/include/linux/linkage.h b/include/linux/linkage.h
  74917. index a6a42dd..6c5ebce 100644
  74918. --- a/include/linux/linkage.h
  74919. +++ b/include/linux/linkage.h
  74920. @@ -36,6 +36,7 @@
  74921. #endif
  74922. #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
  74923. +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
  74924. #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
  74925. /*
  74926. diff --git a/include/linux/list.h b/include/linux/list.h
  74927. index ef95941..82db65a 100644
  74928. --- a/include/linux/list.h
  74929. +++ b/include/linux/list.h
  74930. @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
  74931. extern void list_del(struct list_head *entry);
  74932. #endif
  74933. +extern void __pax_list_add(struct list_head *new,
  74934. + struct list_head *prev,
  74935. + struct list_head *next);
  74936. +static inline void pax_list_add(struct list_head *new, struct list_head *head)
  74937. +{
  74938. + __pax_list_add(new, head, head->next);
  74939. +}
  74940. +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
  74941. +{
  74942. + __pax_list_add(new, head->prev, head);
  74943. +}
  74944. +extern void pax_list_del(struct list_head *entry);
  74945. +
  74946. /**
  74947. * list_replace - replace old entry by new one
  74948. * @old : the element to be replaced
  74949. @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
  74950. INIT_LIST_HEAD(entry);
  74951. }
  74952. +extern void pax_list_del_init(struct list_head *entry);
  74953. +
  74954. /**
  74955. * list_move - delete from one list and add as another's head
  74956. * @list: the entry to move
  74957. diff --git a/include/linux/math64.h b/include/linux/math64.h
  74958. index c45c089..298841c 100644
  74959. --- a/include/linux/math64.h
  74960. +++ b/include/linux/math64.h
  74961. @@ -15,7 +15,7 @@
  74962. * This is commonly provided by 32bit archs to provide an optimized 64bit
  74963. * divide.
  74964. */
  74965. -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  74966. +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  74967. {
  74968. *remainder = dividend % divisor;
  74969. return dividend / divisor;
  74970. @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
  74971. /**
  74972. * div64_u64 - unsigned 64bit divide with 64bit divisor
  74973. */
  74974. -static inline u64 div64_u64(u64 dividend, u64 divisor)
  74975. +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
  74976. {
  74977. return dividend / divisor;
  74978. }
  74979. @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
  74980. #define div64_ul(x, y) div_u64((x), (y))
  74981. #ifndef div_u64_rem
  74982. -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  74983. +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  74984. {
  74985. *remainder = do_div(dividend, divisor);
  74986. return dividend;
  74987. @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
  74988. #endif
  74989. #ifndef div64_u64
  74990. -extern u64 div64_u64(u64 dividend, u64 divisor);
  74991. +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
  74992. #endif
  74993. #ifndef div64_s64
  74994. @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
  74995. * divide.
  74996. */
  74997. #ifndef div_u64
  74998. -static inline u64 div_u64(u64 dividend, u32 divisor)
  74999. +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
  75000. {
  75001. u32 remainder;
  75002. return div_u64_rem(dividend, divisor, &remainder);
  75003. diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
  75004. index 5f1ea75..5125ac5 100644
  75005. --- a/include/linux/mempolicy.h
  75006. +++ b/include/linux/mempolicy.h
  75007. @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
  75008. }
  75009. #define vma_policy(vma) ((vma)->vm_policy)
  75010. +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
  75011. +{
  75012. + vma->vm_policy = pol;
  75013. +}
  75014. static inline void mpol_get(struct mempolicy *pol)
  75015. {
  75016. @@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
  75017. }
  75018. #define vma_policy(vma) NULL
  75019. +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
  75020. +{
  75021. +}
  75022. static inline int
  75023. vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
  75024. diff --git a/include/linux/mm.h b/include/linux/mm.h
  75025. index c1b7414..5ea2ad8 100644
  75026. --- a/include/linux/mm.h
  75027. +++ b/include/linux/mm.h
  75028. @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
  75029. #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
  75030. #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
  75031. #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
  75032. +
  75033. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
  75034. +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
  75035. +#endif
  75036. +
  75037. #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
  75038. #ifdef CONFIG_MEM_SOFT_DIRTY
  75039. @@ -229,8 +234,8 @@ struct vm_operations_struct {
  75040. /* called by access_process_vm when get_user_pages() fails, typically
  75041. * for use by special VMAs that can switch between memory and hardware
  75042. */
  75043. - int (*access)(struct vm_area_struct *vma, unsigned long addr,
  75044. - void *buf, int len, int write);
  75045. + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
  75046. + void *buf, size_t len, int write);
  75047. #ifdef CONFIG_NUMA
  75048. /*
  75049. * set_policy() op must add a reference to any non-NULL @new mempolicy
  75050. @@ -260,6 +265,7 @@ struct vm_operations_struct {
  75051. int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
  75052. unsigned long size, pgoff_t pgoff);
  75053. };
  75054. +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
  75055. struct mmu_gather;
  75056. struct inode;
  75057. @@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
  75058. unsigned long *pfn);
  75059. int follow_phys(struct vm_area_struct *vma, unsigned long address,
  75060. unsigned int flags, unsigned long *prot, resource_size_t *phys);
  75061. -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
  75062. - void *buf, int len, int write);
  75063. +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
  75064. + void *buf, size_t len, int write);
  75065. static inline void unmap_shared_mapping_range(struct address_space *mapping,
  75066. loff_t const holebegin, loff_t const holelen)
  75067. @@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
  75068. }
  75069. #endif
  75070. -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
  75071. -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
  75072. - void *buf, int len, int write);
  75073. +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
  75074. +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
  75075. + void *buf, size_t len, int write);
  75076. long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  75077. unsigned long start, unsigned long nr_pages,
  75078. @@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
  75079. int set_page_dirty_lock(struct page *page);
  75080. int clear_page_dirty_for_io(struct page *page);
  75081. -/* Is the vma a continuation of the stack vma above it? */
  75082. -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
  75083. -{
  75084. - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
  75085. -}
  75086. -
  75087. -static inline int stack_guard_page_start(struct vm_area_struct *vma,
  75088. - unsigned long addr)
  75089. -{
  75090. - return (vma->vm_flags & VM_GROWSDOWN) &&
  75091. - (vma->vm_start == addr) &&
  75092. - !vma_growsdown(vma->vm_prev, addr);
  75093. -}
  75094. -
  75095. -/* Is the vma a continuation of the stack vma below it? */
  75096. -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
  75097. -{
  75098. - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
  75099. -}
  75100. -
  75101. -static inline int stack_guard_page_end(struct vm_area_struct *vma,
  75102. - unsigned long addr)
  75103. -{
  75104. - return (vma->vm_flags & VM_GROWSUP) &&
  75105. - (vma->vm_end == addr) &&
  75106. - !vma_growsup(vma->vm_next, addr);
  75107. -}
  75108. -
  75109. extern pid_t
  75110. vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
  75111. @@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
  75112. }
  75113. #endif
  75114. +#ifdef CONFIG_MMU
  75115. +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
  75116. +#else
  75117. +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
  75118. +{
  75119. + return __pgprot(0);
  75120. +}
  75121. +#endif
  75122. +
  75123. int vma_wants_writenotify(struct vm_area_struct *vma);
  75124. extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
  75125. @@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
  75126. {
  75127. return 0;
  75128. }
  75129. +
  75130. +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
  75131. + unsigned long address)
  75132. +{
  75133. + return 0;
  75134. +}
  75135. #else
  75136. int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
  75137. +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
  75138. #endif
  75139. #ifdef __PAGETABLE_PMD_FOLDED
  75140. @@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
  75141. {
  75142. return 0;
  75143. }
  75144. +
  75145. +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
  75146. + unsigned long address)
  75147. +{
  75148. + return 0;
  75149. +}
  75150. #else
  75151. int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
  75152. +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
  75153. #endif
  75154. int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
  75155. @@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
  75156. NULL: pud_offset(pgd, address);
  75157. }
  75158. +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
  75159. +{
  75160. + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
  75161. + NULL: pud_offset(pgd, address);
  75162. +}
  75163. +
  75164. static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
  75165. {
  75166. return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
  75167. NULL: pmd_offset(pud, address);
  75168. }
  75169. +
  75170. +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
  75171. +{
  75172. + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
  75173. + NULL: pmd_offset(pud, address);
  75174. +}
  75175. #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
  75176. #if USE_SPLIT_PTE_PTLOCKS
  75177. @@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
  75178. unsigned long addr, unsigned long len,
  75179. unsigned long flags, struct page **pages);
  75180. -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  75181. +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
  75182. extern unsigned long mmap_region(struct file *file, unsigned long addr,
  75183. unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
  75184. @@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  75185. unsigned long len, unsigned long prot, unsigned long flags,
  75186. unsigned long pgoff, unsigned long *populate);
  75187. extern int do_munmap(struct mm_struct *, unsigned long, size_t);
  75188. +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
  75189. #ifdef CONFIG_MMU
  75190. extern int __mm_populate(unsigned long addr, unsigned long len,
  75191. @@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
  75192. unsigned long high_limit;
  75193. unsigned long align_mask;
  75194. unsigned long align_offset;
  75195. + unsigned long threadstack_offset;
  75196. };
  75197. -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
  75198. -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
  75199. +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
  75200. +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
  75201. /*
  75202. * Search for an unmapped address range.
  75203. @@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
  75204. * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
  75205. */
  75206. static inline unsigned long
  75207. -vm_unmapped_area(struct vm_unmapped_area_info *info)
  75208. +vm_unmapped_area(const struct vm_unmapped_area_info *info)
  75209. {
  75210. if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
  75211. return unmapped_area(info);
  75212. @@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
  75213. extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
  75214. struct vm_area_struct **pprev);
  75215. +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
  75216. +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
  75217. +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
  75218. +
  75219. /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
  75220. NULL if none. Assume start_addr < end_addr. */
  75221. static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
  75222. @@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
  75223. return vma;
  75224. }
  75225. -#ifdef CONFIG_MMU
  75226. -pgprot_t vm_get_page_prot(unsigned long vm_flags);
  75227. -#else
  75228. -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
  75229. -{
  75230. - return __pgprot(0);
  75231. -}
  75232. -#endif
  75233. -
  75234. #ifdef CONFIG_NUMA_BALANCING
  75235. unsigned long change_prot_numa(struct vm_area_struct *vma,
  75236. unsigned long start, unsigned long end);
  75237. @@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
  75238. static inline void vm_stat_account(struct mm_struct *mm,
  75239. unsigned long flags, struct file *file, long pages)
  75240. {
  75241. +
  75242. +#ifdef CONFIG_PAX_RANDMMAP
  75243. + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
  75244. +#endif
  75245. +
  75246. mm->total_vm += pages;
  75247. }
  75248. #endif /* CONFIG_PROC_FS */
  75249. @@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
  75250. extern int sysctl_memory_failure_early_kill;
  75251. extern int sysctl_memory_failure_recovery;
  75252. extern void shake_page(struct page *p, int access);
  75253. -extern atomic_long_t num_poisoned_pages;
  75254. +extern atomic_long_unchecked_t num_poisoned_pages;
  75255. extern int soft_offline_page(struct page *page, int flags);
  75256. #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
  75257. @@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
  75258. static inline void setup_nr_node_ids(void) {}
  75259. #endif
  75260. +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
  75261. +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
  75262. +#else
  75263. +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
  75264. +#endif
  75265. +
  75266. #endif /* __KERNEL__ */
  75267. #endif /* _LINUX_MM_H */
  75268. diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
  75269. index 290901a..e99b01c 100644
  75270. --- a/include/linux/mm_types.h
  75271. +++ b/include/linux/mm_types.h
  75272. @@ -307,7 +307,9 @@ struct vm_area_struct {
  75273. #ifdef CONFIG_NUMA
  75274. struct mempolicy *vm_policy; /* NUMA policy for the VMA */
  75275. #endif
  75276. -};
  75277. +
  75278. + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
  75279. +} __randomize_layout;
  75280. struct core_thread {
  75281. struct task_struct *task;
  75282. @@ -453,7 +455,25 @@ struct mm_struct {
  75283. bool tlb_flush_pending;
  75284. #endif
  75285. struct uprobes_state uprobes_state;
  75286. -};
  75287. +
  75288. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  75289. + unsigned long pax_flags;
  75290. +#endif
  75291. +
  75292. +#ifdef CONFIG_PAX_DLRESOLVE
  75293. + unsigned long call_dl_resolve;
  75294. +#endif
  75295. +
  75296. +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
  75297. + unsigned long call_syscall;
  75298. +#endif
  75299. +
  75300. +#ifdef CONFIG_PAX_ASLR
  75301. + unsigned long delta_mmap; /* randomized offset */
  75302. + unsigned long delta_stack; /* randomized offset */
  75303. +#endif
  75304. +
  75305. +} __randomize_layout;
  75306. static inline void mm_init_cpumask(struct mm_struct *mm)
  75307. {
  75308. diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
  75309. index c5d5278..f0b68c8 100644
  75310. --- a/include/linux/mmiotrace.h
  75311. +++ b/include/linux/mmiotrace.h
  75312. @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
  75313. /* Called from ioremap.c */
  75314. extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
  75315. void __iomem *addr);
  75316. -extern void mmiotrace_iounmap(volatile void __iomem *addr);
  75317. +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
  75318. /* For anyone to insert markers. Remember trailing newline. */
  75319. extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
  75320. @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
  75321. {
  75322. }
  75323. -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
  75324. +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
  75325. {
  75326. }
  75327. diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
  75328. index 9b61b9b..52147d6b 100644
  75329. --- a/include/linux/mmzone.h
  75330. +++ b/include/linux/mmzone.h
  75331. @@ -396,7 +396,7 @@ struct zone {
  75332. unsigned long flags; /* zone flags, see below */
  75333. /* Zone statistics */
  75334. - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  75335. + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  75336. /*
  75337. * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
  75338. diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
  75339. index 45e9214..a7227d6 100644
  75340. --- a/include/linux/mod_devicetable.h
  75341. +++ b/include/linux/mod_devicetable.h
  75342. @@ -13,7 +13,7 @@
  75343. typedef unsigned long kernel_ulong_t;
  75344. #endif
  75345. -#define PCI_ANY_ID (~0)
  75346. +#define PCI_ANY_ID ((__u16)~0)
  75347. struct pci_device_id {
  75348. __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
  75349. @@ -139,7 +139,7 @@ struct usb_device_id {
  75350. #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
  75351. #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
  75352. -#define HID_ANY_ID (~0)
  75353. +#define HID_ANY_ID (~0U)
  75354. #define HID_BUS_ANY 0xffff
  75355. #define HID_GROUP_ANY 0x0000
  75356. @@ -467,7 +467,7 @@ struct dmi_system_id {
  75357. const char *ident;
  75358. struct dmi_strmatch matches[4];
  75359. void *driver_data;
  75360. -};
  75361. +} __do_const;
  75362. /*
  75363. * struct dmi_device_id appears during expansion of
  75364. * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
  75365. diff --git a/include/linux/module.h b/include/linux/module.h
  75366. index eaf60ff..641979a 100644
  75367. --- a/include/linux/module.h
  75368. +++ b/include/linux/module.h
  75369. @@ -17,9 +17,11 @@
  75370. #include <linux/moduleparam.h>
  75371. #include <linux/tracepoint.h>
  75372. #include <linux/export.h>
  75373. +#include <linux/fs.h>
  75374. #include <linux/percpu.h>
  75375. #include <asm/module.h>
  75376. +#include <asm/pgtable.h>
  75377. /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
  75378. #define MODULE_SIG_STRING "~Module signature appended~\n"
  75379. @@ -42,7 +44,7 @@ struct module_kobject {
  75380. struct kobject *drivers_dir;
  75381. struct module_param_attrs *mp;
  75382. struct completion *kobj_completion;
  75383. -};
  75384. +} __randomize_layout;
  75385. struct module_attribute {
  75386. struct attribute attr;
  75387. @@ -54,12 +56,13 @@ struct module_attribute {
  75388. int (*test)(struct module *);
  75389. void (*free)(struct module *);
  75390. };
  75391. +typedef struct module_attribute __no_const module_attribute_no_const;
  75392. struct module_version_attribute {
  75393. struct module_attribute mattr;
  75394. const char *module_name;
  75395. const char *version;
  75396. -} __attribute__ ((__aligned__(sizeof(void *))));
  75397. +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
  75398. extern ssize_t __modver_version_show(struct module_attribute *,
  75399. struct module_kobject *, char *);
  75400. @@ -238,7 +241,7 @@ struct module {
  75401. /* Sysfs stuff. */
  75402. struct module_kobject mkobj;
  75403. - struct module_attribute *modinfo_attrs;
  75404. + module_attribute_no_const *modinfo_attrs;
  75405. const char *version;
  75406. const char *srcversion;
  75407. struct kobject *holders_dir;
  75408. @@ -287,19 +290,16 @@ struct module {
  75409. int (*init)(void);
  75410. /* If this is non-NULL, vfree after init() returns */
  75411. - void *module_init;
  75412. + void *module_init_rx, *module_init_rw;
  75413. /* Here is the actual code + data, vfree'd on unload. */
  75414. - void *module_core;
  75415. + void *module_core_rx, *module_core_rw;
  75416. /* Here are the sizes of the init and core sections */
  75417. - unsigned int init_size, core_size;
  75418. + unsigned int init_size_rw, core_size_rw;
  75419. /* The size of the executable code in each section. */
  75420. - unsigned int init_text_size, core_text_size;
  75421. -
  75422. - /* Size of RO sections of the module (text+rodata) */
  75423. - unsigned int init_ro_size, core_ro_size;
  75424. + unsigned int init_size_rx, core_size_rx;
  75425. /* Arch-specific module values */
  75426. struct mod_arch_specific arch;
  75427. @@ -355,6 +355,10 @@ struct module {
  75428. #ifdef CONFIG_EVENT_TRACING
  75429. struct ftrace_event_call **trace_events;
  75430. unsigned int num_trace_events;
  75431. + struct file_operations trace_id;
  75432. + struct file_operations trace_enable;
  75433. + struct file_operations trace_format;
  75434. + struct file_operations trace_filter;
  75435. #endif
  75436. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  75437. unsigned int num_ftrace_callsites;
  75438. @@ -378,7 +382,7 @@ struct module {
  75439. ctor_fn_t *ctors;
  75440. unsigned int num_ctors;
  75441. #endif
  75442. -};
  75443. +} __randomize_layout;
  75444. #ifndef MODULE_ARCH_INIT
  75445. #define MODULE_ARCH_INIT {}
  75446. #endif
  75447. @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
  75448. bool is_module_percpu_address(unsigned long addr);
  75449. bool is_module_text_address(unsigned long addr);
  75450. +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
  75451. +{
  75452. +
  75453. +#ifdef CONFIG_PAX_KERNEXEC
  75454. + if (ktla_ktva(addr) >= (unsigned long)start &&
  75455. + ktla_ktva(addr) < (unsigned long)start + size)
  75456. + return 1;
  75457. +#endif
  75458. +
  75459. + return ((void *)addr >= start && (void *)addr < start + size);
  75460. +}
  75461. +
  75462. +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
  75463. +{
  75464. + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
  75465. +}
  75466. +
  75467. +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
  75468. +{
  75469. + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
  75470. +}
  75471. +
  75472. +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
  75473. +{
  75474. + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
  75475. +}
  75476. +
  75477. +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
  75478. +{
  75479. + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
  75480. +}
  75481. +
  75482. static inline int within_module_core(unsigned long addr, const struct module *mod)
  75483. {
  75484. - return (unsigned long)mod->module_core <= addr &&
  75485. - addr < (unsigned long)mod->module_core + mod->core_size;
  75486. + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
  75487. }
  75488. static inline int within_module_init(unsigned long addr, const struct module *mod)
  75489. {
  75490. - return (unsigned long)mod->module_init <= addr &&
  75491. - addr < (unsigned long)mod->module_init + mod->init_size;
  75492. + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
  75493. }
  75494. /* Search for module by name: must hold module_mutex. */
  75495. diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
  75496. index 560ca53..ef621ef 100644
  75497. --- a/include/linux/moduleloader.h
  75498. +++ b/include/linux/moduleloader.h
  75499. @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
  75500. sections. Returns NULL on failure. */
  75501. void *module_alloc(unsigned long size);
  75502. +#ifdef CONFIG_PAX_KERNEXEC
  75503. +void *module_alloc_exec(unsigned long size);
  75504. +#else
  75505. +#define module_alloc_exec(x) module_alloc(x)
  75506. +#endif
  75507. +
  75508. /* Free memory returned from module_alloc. */
  75509. void module_free(struct module *mod, void *module_region);
  75510. +#ifdef CONFIG_PAX_KERNEXEC
  75511. +void module_free_exec(struct module *mod, void *module_region);
  75512. +#else
  75513. +#define module_free_exec(x, y) module_free((x), (y))
  75514. +#endif
  75515. +
  75516. /*
  75517. * Apply the given relocation to the (simplified) ELF. Return -error
  75518. * or 0.
  75519. @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
  75520. unsigned int relsec,
  75521. struct module *me)
  75522. {
  75523. +#ifdef CONFIG_MODULES
  75524. printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
  75525. +#endif
  75526. return -ENOEXEC;
  75527. }
  75528. #endif
  75529. @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
  75530. unsigned int relsec,
  75531. struct module *me)
  75532. {
  75533. +#ifdef CONFIG_MODULES
  75534. printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
  75535. +#endif
  75536. return -ENOEXEC;
  75537. }
  75538. #endif
  75539. diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
  75540. index c3eb102..073c4a6 100644
  75541. --- a/include/linux/moduleparam.h
  75542. +++ b/include/linux/moduleparam.h
  75543. @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
  75544. * @len is usually just sizeof(string).
  75545. */
  75546. #define module_param_string(name, string, len, perm) \
  75547. - static const struct kparam_string __param_string_##name \
  75548. + static const struct kparam_string __param_string_##name __used \
  75549. = { len, string }; \
  75550. __module_param_call(MODULE_PARAM_PREFIX, name, \
  75551. &param_ops_string, \
  75552. @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
  75553. */
  75554. #define module_param_array_named(name, array, type, nump, perm) \
  75555. param_check_##type(name, &(array)[0]); \
  75556. - static const struct kparam_array __param_arr_##name \
  75557. + static const struct kparam_array __param_arr_##name __used \
  75558. = { .max = ARRAY_SIZE(array), .num = nump, \
  75559. .ops = &param_ops_##type, \
  75560. .elemsize = sizeof(array[0]), .elem = array }; \
  75561. diff --git a/include/linux/mount.h b/include/linux/mount.h
  75562. index 839bac2..a96b37c 100644
  75563. --- a/include/linux/mount.h
  75564. +++ b/include/linux/mount.h
  75565. @@ -59,7 +59,7 @@ struct vfsmount {
  75566. struct dentry *mnt_root; /* root of the mounted tree */
  75567. struct super_block *mnt_sb; /* pointer to superblock */
  75568. int mnt_flags;
  75569. -};
  75570. +} __randomize_layout;
  75571. struct file; /* forward dec */
  75572. diff --git a/include/linux/namei.h b/include/linux/namei.h
  75573. index 492de72..1bddcd4 100644
  75574. --- a/include/linux/namei.h
  75575. +++ b/include/linux/namei.h
  75576. @@ -19,7 +19,7 @@ struct nameidata {
  75577. unsigned seq, m_seq;
  75578. int last_type;
  75579. unsigned depth;
  75580. - char *saved_names[MAX_NESTED_LINKS + 1];
  75581. + const char *saved_names[MAX_NESTED_LINKS + 1];
  75582. };
  75583. /*
  75584. @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
  75585. extern void nd_jump_link(struct nameidata *nd, struct path *path);
  75586. -static inline void nd_set_link(struct nameidata *nd, char *path)
  75587. +static inline void nd_set_link(struct nameidata *nd, const char *path)
  75588. {
  75589. nd->saved_names[nd->depth] = path;
  75590. }
  75591. -static inline char *nd_get_link(struct nameidata *nd)
  75592. +static inline const char *nd_get_link(const struct nameidata *nd)
  75593. {
  75594. return nd->saved_names[nd->depth];
  75595. }
  75596. diff --git a/include/linux/net.h b/include/linux/net.h
  75597. index 94734a6..d8d6931 100644
  75598. --- a/include/linux/net.h
  75599. +++ b/include/linux/net.h
  75600. @@ -192,7 +192,7 @@ struct net_proto_family {
  75601. int (*create)(struct net *net, struct socket *sock,
  75602. int protocol, int kern);
  75603. struct module *owner;
  75604. -};
  75605. +} __do_const;
  75606. struct iovec;
  75607. struct kvec;
  75608. diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
  75609. index daafd95..74c5d1e 100644
  75610. --- a/include/linux/netdevice.h
  75611. +++ b/include/linux/netdevice.h
  75612. @@ -1146,6 +1146,7 @@ struct net_device_ops {
  75613. struct net_device *dev,
  75614. void *priv);
  75615. };
  75616. +typedef struct net_device_ops __no_const net_device_ops_no_const;
  75617. /*
  75618. * The DEVICE structure.
  75619. @@ -1228,7 +1229,7 @@ struct net_device {
  75620. int iflink;
  75621. struct net_device_stats stats;
  75622. - atomic_long_t rx_dropped; /* dropped packets by core network
  75623. + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
  75624. * Do not use this in drivers.
  75625. */
  75626. diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
  75627. index 2077489..a15e561 100644
  75628. --- a/include/linux/netfilter.h
  75629. +++ b/include/linux/netfilter.h
  75630. @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
  75631. #endif
  75632. /* Use the module struct to lock set/get code in place */
  75633. struct module *owner;
  75634. -};
  75635. +} __do_const;
  75636. /* Function to register/unregister hook points. */
  75637. int nf_register_hook(struct nf_hook_ops *reg);
  75638. diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
  75639. index 28c7436..2d6156a 100644
  75640. --- a/include/linux/netfilter/nfnetlink.h
  75641. +++ b/include/linux/netfilter/nfnetlink.h
  75642. @@ -19,7 +19,7 @@ struct nfnl_callback {
  75643. const struct nlattr * const cda[]);
  75644. const struct nla_policy *policy; /* netlink attribute policy */
  75645. const u_int16_t attr_count; /* number of nlattr's */
  75646. -};
  75647. +} __do_const;
  75648. struct nfnetlink_subsystem {
  75649. const char *name;
  75650. diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
  75651. new file mode 100644
  75652. index 0000000..33f4af8
  75653. --- /dev/null
  75654. +++ b/include/linux/netfilter/xt_gradm.h
  75655. @@ -0,0 +1,9 @@
  75656. +#ifndef _LINUX_NETFILTER_XT_GRADM_H
  75657. +#define _LINUX_NETFILTER_XT_GRADM_H 1
  75658. +
  75659. +struct xt_gradm_mtinfo {
  75660. + __u16 flags;
  75661. + __u16 invflags;
  75662. +};
  75663. +
  75664. +#endif
  75665. diff --git a/include/linux/nls.h b/include/linux/nls.h
  75666. index 520681b..1d67ed2 100644
  75667. --- a/include/linux/nls.h
  75668. +++ b/include/linux/nls.h
  75669. @@ -31,7 +31,7 @@ struct nls_table {
  75670. const unsigned char *charset2upper;
  75671. struct module *owner;
  75672. struct nls_table *next;
  75673. -};
  75674. +} __do_const;
  75675. /* this value hold the maximum octet of charset */
  75676. #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
  75677. diff --git a/include/linux/notifier.h b/include/linux/notifier.h
  75678. index d14a4c3..a078786 100644
  75679. --- a/include/linux/notifier.h
  75680. +++ b/include/linux/notifier.h
  75681. @@ -54,7 +54,8 @@ struct notifier_block {
  75682. notifier_fn_t notifier_call;
  75683. struct notifier_block __rcu *next;
  75684. int priority;
  75685. -};
  75686. +} __do_const;
  75687. +typedef struct notifier_block __no_const notifier_block_no_const;
  75688. struct atomic_notifier_head {
  75689. spinlock_t lock;
  75690. diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
  75691. index b2a0f15..4d7da32 100644
  75692. --- a/include/linux/oprofile.h
  75693. +++ b/include/linux/oprofile.h
  75694. @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
  75695. int oprofilefs_create_ro_ulong(struct dentry * root,
  75696. char const * name, ulong * val);
  75697. -/** Create a file for read-only access to an atomic_t. */
  75698. +/** Create a file for read-only access to an atomic_unchecked_t. */
  75699. int oprofilefs_create_ro_atomic(struct dentry * root,
  75700. - char const * name, atomic_t * val);
  75701. + char const * name, atomic_unchecked_t * val);
  75702. /** create a directory */
  75703. struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
  75704. diff --git a/include/linux/padata.h b/include/linux/padata.h
  75705. index 4386946..f50c615 100644
  75706. --- a/include/linux/padata.h
  75707. +++ b/include/linux/padata.h
  75708. @@ -129,7 +129,7 @@ struct parallel_data {
  75709. struct padata_serial_queue __percpu *squeue;
  75710. atomic_t reorder_objects;
  75711. atomic_t refcnt;
  75712. - atomic_t seq_nr;
  75713. + atomic_unchecked_t seq_nr;
  75714. struct padata_cpumask cpumask;
  75715. spinlock_t lock ____cacheline_aligned;
  75716. unsigned int processed;
  75717. diff --git a/include/linux/path.h b/include/linux/path.h
  75718. index d137218..be0c176 100644
  75719. --- a/include/linux/path.h
  75720. +++ b/include/linux/path.h
  75721. @@ -1,13 +1,15 @@
  75722. #ifndef _LINUX_PATH_H
  75723. #define _LINUX_PATH_H
  75724. +#include <linux/compiler.h>
  75725. +
  75726. struct dentry;
  75727. struct vfsmount;
  75728. struct path {
  75729. struct vfsmount *mnt;
  75730. struct dentry *dentry;
  75731. -};
  75732. +} __randomize_layout;
  75733. extern void path_get(const struct path *);
  75734. extern void path_put(const struct path *);
  75735. diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
  75736. index 5f2e559..7d59314 100644
  75737. --- a/include/linux/pci_hotplug.h
  75738. +++ b/include/linux/pci_hotplug.h
  75739. @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
  75740. int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
  75741. int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
  75742. int (*reset_slot) (struct hotplug_slot *slot, int probe);
  75743. -};
  75744. +} __do_const;
  75745. +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
  75746. /**
  75747. * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
  75748. diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
  75749. index e56b07f..aef789b 100644
  75750. --- a/include/linux/perf_event.h
  75751. +++ b/include/linux/perf_event.h
  75752. @@ -328,8 +328,8 @@ struct perf_event {
  75753. enum perf_event_active_state state;
  75754. unsigned int attach_state;
  75755. - local64_t count;
  75756. - atomic64_t child_count;
  75757. + local64_t count; /* PaX: fix it one day */
  75758. + atomic64_unchecked_t child_count;
  75759. /*
  75760. * These are the total time in nanoseconds that the event
  75761. @@ -380,8 +380,8 @@ struct perf_event {
  75762. * These accumulate total time (in nanoseconds) that children
  75763. * events have been enabled and running, respectively.
  75764. */
  75765. - atomic64_t child_total_time_enabled;
  75766. - atomic64_t child_total_time_running;
  75767. + atomic64_unchecked_t child_total_time_enabled;
  75768. + atomic64_unchecked_t child_total_time_running;
  75769. /*
  75770. * Protect attach/detach and child_list:
  75771. @@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
  75772. entry->ip[entry->nr++] = ip;
  75773. }
  75774. -extern int sysctl_perf_event_paranoid;
  75775. +extern int sysctl_perf_event_legitimately_concerned;
  75776. extern int sysctl_perf_event_mlock;
  75777. extern int sysctl_perf_event_sample_rate;
  75778. extern int sysctl_perf_cpu_time_max_percent;
  75779. @@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
  75780. loff_t *ppos);
  75781. +static inline bool perf_paranoid_any(void)
  75782. +{
  75783. + return sysctl_perf_event_legitimately_concerned > 2;
  75784. +}
  75785. +
  75786. static inline bool perf_paranoid_tracepoint_raw(void)
  75787. {
  75788. - return sysctl_perf_event_paranoid > -1;
  75789. + return sysctl_perf_event_legitimately_concerned > -1;
  75790. }
  75791. static inline bool perf_paranoid_cpu(void)
  75792. {
  75793. - return sysctl_perf_event_paranoid > 0;
  75794. + return sysctl_perf_event_legitimately_concerned > 0;
  75795. }
  75796. static inline bool perf_paranoid_kernel(void)
  75797. {
  75798. - return sysctl_perf_event_paranoid > 1;
  75799. + return sysctl_perf_event_legitimately_concerned > 1;
  75800. }
  75801. extern void perf_event_init(void);
  75802. @@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
  75803. struct device_attribute attr;
  75804. u64 id;
  75805. const char *event_str;
  75806. -};
  75807. +} __do_const;
  75808. #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
  75809. static struct perf_pmu_events_attr _var = { \
  75810. diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
  75811. index 7246ef3..1539ea4 100644
  75812. --- a/include/linux/pid_namespace.h
  75813. +++ b/include/linux/pid_namespace.h
  75814. @@ -43,7 +43,7 @@ struct pid_namespace {
  75815. int hide_pid;
  75816. int reboot; /* group exit code if this pidns was rebooted */
  75817. unsigned int proc_inum;
  75818. -};
  75819. +} __randomize_layout;
  75820. extern struct pid_namespace init_pid_ns;
  75821. diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
  75822. index ab57526..94598804 100644
  75823. --- a/include/linux/pipe_fs_i.h
  75824. +++ b/include/linux/pipe_fs_i.h
  75825. @@ -47,10 +47,10 @@ struct pipe_inode_info {
  75826. struct mutex mutex;
  75827. wait_queue_head_t wait;
  75828. unsigned int nrbufs, curbuf, buffers;
  75829. - unsigned int readers;
  75830. - unsigned int writers;
  75831. - unsigned int files;
  75832. - unsigned int waiting_writers;
  75833. + atomic_t readers;
  75834. + atomic_t writers;
  75835. + atomic_t files;
  75836. + atomic_t waiting_writers;
  75837. unsigned int r_counter;
  75838. unsigned int w_counter;
  75839. struct page *tmp_page;
  75840. diff --git a/include/linux/pm.h b/include/linux/pm.h
  75841. index 8c6583a..febb84c 100644
  75842. --- a/include/linux/pm.h
  75843. +++ b/include/linux/pm.h
  75844. @@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
  75845. struct dev_pm_domain {
  75846. struct dev_pm_ops ops;
  75847. };
  75848. +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
  75849. /*
  75850. * The PM_EVENT_ messages are also used by drivers implementing the legacy
  75851. diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
  75852. index 7c1d252..0e7061d 100644
  75853. --- a/include/linux/pm_domain.h
  75854. +++ b/include/linux/pm_domain.h
  75855. @@ -44,11 +44,11 @@ struct gpd_dev_ops {
  75856. int (*thaw_early)(struct device *dev);
  75857. int (*thaw)(struct device *dev);
  75858. bool (*active_wakeup)(struct device *dev);
  75859. -};
  75860. +} __no_const;
  75861. struct gpd_cpu_data {
  75862. unsigned int saved_exit_latency;
  75863. - struct cpuidle_state *idle_state;
  75864. + cpuidle_state_no_const *idle_state;
  75865. };
  75866. struct generic_pm_domain {
  75867. diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
  75868. index 16c9a62..f9f0838 100644
  75869. --- a/include/linux/pm_runtime.h
  75870. +++ b/include/linux/pm_runtime.h
  75871. @@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
  75872. static inline void pm_runtime_mark_last_busy(struct device *dev)
  75873. {
  75874. - ACCESS_ONCE(dev->power.last_busy) = jiffies;
  75875. + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
  75876. }
  75877. #else /* !CONFIG_PM_RUNTIME */
  75878. diff --git a/include/linux/pnp.h b/include/linux/pnp.h
  75879. index 195aafc..49a7bc2 100644
  75880. --- a/include/linux/pnp.h
  75881. +++ b/include/linux/pnp.h
  75882. @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
  75883. struct pnp_fixup {
  75884. char id[7];
  75885. void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
  75886. -};
  75887. +} __do_const;
  75888. /* config parameters */
  75889. #define PNP_CONFIG_NORMAL 0x0001
  75890. diff --git a/include/linux/poison.h b/include/linux/poison.h
  75891. index 2110a81..13a11bb 100644
  75892. --- a/include/linux/poison.h
  75893. +++ b/include/linux/poison.h
  75894. @@ -19,8 +19,8 @@
  75895. * under normal circumstances, used to verify that nobody uses
  75896. * non-initialized list entries.
  75897. */
  75898. -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
  75899. -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
  75900. +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
  75901. +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
  75902. /********** include/linux/timer.h **********/
  75903. /*
  75904. diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
  75905. index d8b187c3..9a9257a 100644
  75906. --- a/include/linux/power/smartreflex.h
  75907. +++ b/include/linux/power/smartreflex.h
  75908. @@ -238,7 +238,7 @@ struct omap_sr_class_data {
  75909. int (*notify)(struct omap_sr *sr, u32 status);
  75910. u8 notify_flags;
  75911. u8 class_type;
  75912. -};
  75913. +} __do_const;
  75914. /**
  75915. * struct omap_sr_nvalue_table - Smartreflex n-target value info
  75916. diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
  75917. index 4ea1d37..80f4b33 100644
  75918. --- a/include/linux/ppp-comp.h
  75919. +++ b/include/linux/ppp-comp.h
  75920. @@ -84,7 +84,7 @@ struct compressor {
  75921. struct module *owner;
  75922. /* Extra skb space needed by the compressor algorithm */
  75923. unsigned int comp_extra;
  75924. -};
  75925. +} __do_const;
  75926. /*
  75927. * The return value from decompress routine is the length of the
  75928. diff --git a/include/linux/preempt.h b/include/linux/preempt.h
  75929. index de83b4e..c4b997d 100644
  75930. --- a/include/linux/preempt.h
  75931. +++ b/include/linux/preempt.h
  75932. @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
  75933. #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
  75934. #endif
  75935. +#define raw_preempt_count_add(val) __preempt_count_add(val)
  75936. +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
  75937. +
  75938. #define __preempt_count_inc() __preempt_count_add(1)
  75939. #define __preempt_count_dec() __preempt_count_sub(1)
  75940. #define preempt_count_inc() preempt_count_add(1)
  75941. +#define raw_preempt_count_inc() raw_preempt_count_add(1)
  75942. #define preempt_count_dec() preempt_count_sub(1)
  75943. +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
  75944. #ifdef CONFIG_PREEMPT_COUNT
  75945. @@ -41,6 +46,12 @@ do { \
  75946. barrier(); \
  75947. } while (0)
  75948. +#define raw_preempt_disable() \
  75949. +do { \
  75950. + raw_preempt_count_inc(); \
  75951. + barrier(); \
  75952. +} while (0)
  75953. +
  75954. #define sched_preempt_enable_no_resched() \
  75955. do { \
  75956. barrier(); \
  75957. @@ -49,6 +60,12 @@ do { \
  75958. #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  75959. +#define raw_preempt_enable_no_resched() \
  75960. +do { \
  75961. + barrier(); \
  75962. + raw_preempt_count_dec(); \
  75963. +} while (0)
  75964. +
  75965. #ifdef CONFIG_PREEMPT
  75966. #define preempt_enable() \
  75967. do { \
  75968. @@ -113,8 +130,10 @@ do { \
  75969. * region.
  75970. */
  75971. #define preempt_disable() barrier()
  75972. +#define raw_preempt_disable() barrier()
  75973. #define sched_preempt_enable_no_resched() barrier()
  75974. #define preempt_enable_no_resched() barrier()
  75975. +#define raw_preempt_enable_no_resched() barrier()
  75976. #define preempt_enable() barrier()
  75977. #define preempt_check_resched() do { } while (0)
  75978. @@ -128,11 +147,13 @@ do { \
  75979. /*
  75980. * Modules have no business playing preemption tricks.
  75981. */
  75982. +#ifndef CONFIG_PAX_KERNEXEC
  75983. #undef sched_preempt_enable_no_resched
  75984. #undef preempt_enable_no_resched
  75985. #undef preempt_enable_no_resched_notrace
  75986. #undef preempt_check_resched
  75987. #endif
  75988. +#endif
  75989. #define preempt_set_need_resched() \
  75990. do { \
  75991. diff --git a/include/linux/printk.h b/include/linux/printk.h
  75992. index fa47e27..c08e034 100644
  75993. --- a/include/linux/printk.h
  75994. +++ b/include/linux/printk.h
  75995. @@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
  75996. void early_printk(const char *s, ...) { }
  75997. #endif
  75998. +extern int kptr_restrict;
  75999. +
  76000. #ifdef CONFIG_PRINTK
  76001. asmlinkage __printf(5, 0)
  76002. int vprintk_emit(int facility, int level,
  76003. @@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  76004. extern int printk_delay_msec;
  76005. extern int dmesg_restrict;
  76006. -extern int kptr_restrict;
  76007. extern void wake_up_klogd(void);
  76008. diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
  76009. index 608e60a..bbcb1a0 100644
  76010. --- a/include/linux/proc_fs.h
  76011. +++ b/include/linux/proc_fs.h
  76012. @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
  76013. extern struct proc_dir_entry *proc_symlink(const char *,
  76014. struct proc_dir_entry *, const char *);
  76015. extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
  76016. +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
  76017. extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
  76018. struct proc_dir_entry *, void *);
  76019. +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
  76020. + struct proc_dir_entry *, void *);
  76021. extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
  76022. struct proc_dir_entry *);
  76023. @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
  76024. return proc_create_data(name, mode, parent, proc_fops, NULL);
  76025. }
  76026. +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
  76027. + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
  76028. +{
  76029. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  76030. + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
  76031. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  76032. + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
  76033. +#else
  76034. + return proc_create_data(name, mode, parent, proc_fops, NULL);
  76035. +#endif
  76036. +}
  76037. +
  76038. +
  76039. extern void proc_set_size(struct proc_dir_entry *, loff_t);
  76040. extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
  76041. extern void *PDE_DATA(const struct inode *);
  76042. @@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
  76043. static inline struct proc_dir_entry *proc_net_mkdir(
  76044. struct net *net, const char *name, struct proc_dir_entry *parent)
  76045. {
  76046. - return proc_mkdir_data(name, 0, parent, net);
  76047. + return proc_mkdir_data_restrict(name, 0, parent, net);
  76048. }
  76049. #endif /* _LINUX_PROC_FS_H */
  76050. diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
  76051. index 34a1e10..70f6bde 100644
  76052. --- a/include/linux/proc_ns.h
  76053. +++ b/include/linux/proc_ns.h
  76054. @@ -14,7 +14,7 @@ struct proc_ns_operations {
  76055. void (*put)(void *ns);
  76056. int (*install)(struct nsproxy *nsproxy, void *ns);
  76057. unsigned int (*inum)(void *ns);
  76058. -};
  76059. +} __do_const __randomize_layout;
  76060. struct proc_ns {
  76061. void *ns;
  76062. diff --git a/include/linux/quota.h b/include/linux/quota.h
  76063. index cc7494a..1e27036 100644
  76064. --- a/include/linux/quota.h
  76065. +++ b/include/linux/quota.h
  76066. @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
  76067. extern bool qid_eq(struct kqid left, struct kqid right);
  76068. extern bool qid_lt(struct kqid left, struct kqid right);
  76069. -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
  76070. +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
  76071. extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
  76072. extern bool qid_valid(struct kqid qid);
  76073. diff --git a/include/linux/random.h b/include/linux/random.h
  76074. index 1cfce0e..b0b9235 100644
  76075. --- a/include/linux/random.h
  76076. +++ b/include/linux/random.h
  76077. @@ -9,9 +9,19 @@
  76078. #include <uapi/linux/random.h>
  76079. extern void add_device_randomness(const void *, unsigned int);
  76080. +
  76081. +static inline void add_latent_entropy(void)
  76082. +{
  76083. +
  76084. +#ifdef LATENT_ENTROPY_PLUGIN
  76085. + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
  76086. +#endif
  76087. +
  76088. +}
  76089. +
  76090. extern void add_input_randomness(unsigned int type, unsigned int code,
  76091. - unsigned int value);
  76092. -extern void add_interrupt_randomness(int irq, int irq_flags);
  76093. + unsigned int value) __latent_entropy;
  76094. +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
  76095. extern void get_random_bytes(void *buf, int nbytes);
  76096. extern void get_random_bytes_arch(void *buf, int nbytes);
  76097. @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
  76098. extern const struct file_operations random_fops, urandom_fops;
  76099. #endif
  76100. -unsigned int get_random_int(void);
  76101. +unsigned int __intentional_overflow(-1) get_random_int(void);
  76102. unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
  76103. -u32 prandom_u32(void);
  76104. +u32 prandom_u32(void) __intentional_overflow(-1);
  76105. void prandom_bytes(void *buf, int nbytes);
  76106. void prandom_seed(u32 seed);
  76107. void prandom_reseed_late(void);
  76108. @@ -37,6 +47,11 @@ struct rnd_state {
  76109. u32 prandom_u32_state(struct rnd_state *state);
  76110. void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
  76111. +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
  76112. +{
  76113. + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
  76114. +}
  76115. +
  76116. /**
  76117. * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
  76118. * @ep_ro: right open interval endpoint
  76119. diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
  76120. index fea49b5..2ac22bb 100644
  76121. --- a/include/linux/rbtree_augmented.h
  76122. +++ b/include/linux/rbtree_augmented.h
  76123. @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
  76124. old->rbaugmented = rbcompute(old); \
  76125. } \
  76126. rbstatic const struct rb_augment_callbacks rbname = { \
  76127. - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
  76128. + .propagate = rbname ## _propagate, \
  76129. + .copy = rbname ## _copy, \
  76130. + .rotate = rbname ## _rotate \
  76131. };
  76132. diff --git a/include/linux/rculist.h b/include/linux/rculist.h
  76133. index dbaf990..52e07b8 100644
  76134. --- a/include/linux/rculist.h
  76135. +++ b/include/linux/rculist.h
  76136. @@ -29,8 +29,8 @@
  76137. */
  76138. static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
  76139. {
  76140. - ACCESS_ONCE(list->next) = list;
  76141. - ACCESS_ONCE(list->prev) = list;
  76142. + ACCESS_ONCE_RW(list->next) = list;
  76143. + ACCESS_ONCE_RW(list->prev) = list;
  76144. }
  76145. /*
  76146. @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
  76147. struct list_head *prev, struct list_head *next);
  76148. #endif
  76149. +void __pax_list_add_rcu(struct list_head *new,
  76150. + struct list_head *prev, struct list_head *next);
  76151. +
  76152. /**
  76153. * list_add_rcu - add a new entry to rcu-protected list
  76154. * @new: new entry to be added
  76155. @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
  76156. __list_add_rcu(new, head, head->next);
  76157. }
  76158. +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
  76159. +{
  76160. + __pax_list_add_rcu(new, head, head->next);
  76161. +}
  76162. +
  76163. /**
  76164. * list_add_tail_rcu - add a new entry to rcu-protected list
  76165. * @new: new entry to be added
  76166. @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
  76167. __list_add_rcu(new, head->prev, head);
  76168. }
  76169. +static inline void pax_list_add_tail_rcu(struct list_head *new,
  76170. + struct list_head *head)
  76171. +{
  76172. + __pax_list_add_rcu(new, head->prev, head);
  76173. +}
  76174. +
  76175. /**
  76176. * list_del_rcu - deletes entry from list without re-initialization
  76177. * @entry: the element to delete from the list.
  76178. @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
  76179. entry->prev = LIST_POISON2;
  76180. }
  76181. +extern void pax_list_del_rcu(struct list_head *entry);
  76182. +
  76183. /**
  76184. * hlist_del_init_rcu - deletes entry from hash list with re-initialization
  76185. * @n: the element to delete from the hash list.
  76186. diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
  76187. index 72bf3a0..853347f 100644
  76188. --- a/include/linux/rcupdate.h
  76189. +++ b/include/linux/rcupdate.h
  76190. @@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
  76191. #define rcu_assign_pointer(p, v) \
  76192. do { \
  76193. smp_wmb(); \
  76194. - ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
  76195. + ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
  76196. } while (0)
  76197. diff --git a/include/linux/reboot.h b/include/linux/reboot.h
  76198. index 9e7db9e..7d4fd72 100644
  76199. --- a/include/linux/reboot.h
  76200. +++ b/include/linux/reboot.h
  76201. @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
  76202. */
  76203. extern void migrate_to_reboot_cpu(void);
  76204. -extern void machine_restart(char *cmd);
  76205. -extern void machine_halt(void);
  76206. -extern void machine_power_off(void);
  76207. +extern void machine_restart(char *cmd) __noreturn;
  76208. +extern void machine_halt(void) __noreturn;
  76209. +extern void machine_power_off(void) __noreturn;
  76210. extern void machine_shutdown(void);
  76211. struct pt_regs;
  76212. @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
  76213. */
  76214. extern void kernel_restart_prepare(char *cmd);
  76215. -extern void kernel_restart(char *cmd);
  76216. -extern void kernel_halt(void);
  76217. -extern void kernel_power_off(void);
  76218. +extern void kernel_restart(char *cmd) __noreturn;
  76219. +extern void kernel_halt(void) __noreturn;
  76220. +extern void kernel_power_off(void) __noreturn;
  76221. extern int C_A_D; /* for sysctl */
  76222. void ctrl_alt_del(void);
  76223. @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
  76224. * Emergency restart, callable from an interrupt handler.
  76225. */
  76226. -extern void emergency_restart(void);
  76227. +extern void emergency_restart(void) __noreturn;
  76228. #include <asm/emergency-restart.h>
  76229. #endif /* _LINUX_REBOOT_H */
  76230. diff --git a/include/linux/regset.h b/include/linux/regset.h
  76231. index 8e0c9fe..ac4d221 100644
  76232. --- a/include/linux/regset.h
  76233. +++ b/include/linux/regset.h
  76234. @@ -161,7 +161,8 @@ struct user_regset {
  76235. unsigned int align;
  76236. unsigned int bias;
  76237. unsigned int core_note_type;
  76238. -};
  76239. +} __do_const;
  76240. +typedef struct user_regset __no_const user_regset_no_const;
  76241. /**
  76242. * struct user_regset_view - available regsets
  76243. diff --git a/include/linux/relay.h b/include/linux/relay.h
  76244. index d7c8359..818daf5 100644
  76245. --- a/include/linux/relay.h
  76246. +++ b/include/linux/relay.h
  76247. @@ -157,7 +157,7 @@ struct rchan_callbacks
  76248. * The callback should return 0 if successful, negative if not.
  76249. */
  76250. int (*remove_buf_file)(struct dentry *dentry);
  76251. -};
  76252. +} __no_const;
  76253. /*
  76254. * CONFIG_RELAY kernel API, kernel/relay.c
  76255. diff --git a/include/linux/rio.h b/include/linux/rio.h
  76256. index b71d573..2f940bd 100644
  76257. --- a/include/linux/rio.h
  76258. +++ b/include/linux/rio.h
  76259. @@ -355,7 +355,7 @@ struct rio_ops {
  76260. int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
  76261. u64 rstart, u32 size, u32 flags);
  76262. void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
  76263. -};
  76264. +} __no_const;
  76265. #define RIO_RESOURCE_MEM 0x00000100
  76266. #define RIO_RESOURCE_DOORBELL 0x00000200
  76267. diff --git a/include/linux/rmap.h b/include/linux/rmap.h
  76268. index b66c211..13d2915 100644
  76269. --- a/include/linux/rmap.h
  76270. +++ b/include/linux/rmap.h
  76271. @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
  76272. void anon_vma_init(void); /* create anon_vma_cachep */
  76273. int anon_vma_prepare(struct vm_area_struct *);
  76274. void unlink_anon_vmas(struct vm_area_struct *);
  76275. -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
  76276. -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
  76277. +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
  76278. +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
  76279. static inline void anon_vma_merge(struct vm_area_struct *vma,
  76280. struct vm_area_struct *next)
  76281. diff --git a/include/linux/sched.h b/include/linux/sched.h
  76282. index a781dec..be1d2a3 100644
  76283. --- a/include/linux/sched.h
  76284. +++ b/include/linux/sched.h
  76285. @@ -129,6 +129,7 @@ struct fs_struct;
  76286. struct perf_event_context;
  76287. struct blk_plug;
  76288. struct filename;
  76289. +struct linux_binprm;
  76290. /*
  76291. * List of flags we want to share for kernel threads,
  76292. @@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
  76293. extern int in_sched_functions(unsigned long addr);
  76294. #define MAX_SCHEDULE_TIMEOUT LONG_MAX
  76295. -extern signed long schedule_timeout(signed long timeout);
  76296. +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
  76297. extern signed long schedule_timeout_interruptible(signed long timeout);
  76298. extern signed long schedule_timeout_killable(signed long timeout);
  76299. extern signed long schedule_timeout_uninterruptible(signed long timeout);
  76300. @@ -380,6 +381,19 @@ struct nsproxy;
  76301. struct user_namespace;
  76302. #ifdef CONFIG_MMU
  76303. +
  76304. +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
  76305. +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
  76306. +#else
  76307. +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
  76308. +{
  76309. + return 0;
  76310. +}
  76311. +#endif
  76312. +
  76313. +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
  76314. +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
  76315. +
  76316. extern void arch_pick_mmap_layout(struct mm_struct *mm);
  76317. extern unsigned long
  76318. arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
  76319. @@ -677,6 +691,17 @@ struct signal_struct {
  76320. #ifdef CONFIG_TASKSTATS
  76321. struct taskstats *stats;
  76322. #endif
  76323. +
  76324. +#ifdef CONFIG_GRKERNSEC
  76325. + u32 curr_ip;
  76326. + u32 saved_ip;
  76327. + u32 gr_saddr;
  76328. + u32 gr_daddr;
  76329. + u16 gr_sport;
  76330. + u16 gr_dport;
  76331. + u8 used_accept:1;
  76332. +#endif
  76333. +
  76334. #ifdef CONFIG_AUDIT
  76335. unsigned audit_tty;
  76336. unsigned audit_tty_log_passwd;
  76337. @@ -703,7 +728,7 @@ struct signal_struct {
  76338. struct mutex cred_guard_mutex; /* guard against foreign influences on
  76339. * credential calculations
  76340. * (notably. ptrace) */
  76341. -};
  76342. +} __randomize_layout;
  76343. /*
  76344. * Bits in flags field of signal_struct.
  76345. @@ -757,6 +782,14 @@ struct user_struct {
  76346. struct key *session_keyring; /* UID's default session keyring */
  76347. #endif
  76348. +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
  76349. + unsigned char kernel_banned;
  76350. +#endif
  76351. +#ifdef CONFIG_GRKERNSEC_BRUTE
  76352. + unsigned char suid_banned;
  76353. + unsigned long suid_ban_expires;
  76354. +#endif
  76355. +
  76356. /* Hash table maintenance information */
  76357. struct hlist_node uidhash_node;
  76358. kuid_t uid;
  76359. @@ -764,7 +797,7 @@ struct user_struct {
  76360. #ifdef CONFIG_PERF_EVENTS
  76361. atomic_long_t locked_vm;
  76362. #endif
  76363. -};
  76364. +} __randomize_layout;
  76365. extern int uids_sysfs_init(void);
  76366. @@ -1286,8 +1319,8 @@ struct task_struct {
  76367. struct list_head thread_node;
  76368. struct completion *vfork_done; /* for vfork() */
  76369. - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
  76370. - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
  76371. + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
  76372. + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
  76373. cputime_t utime, stime, utimescaled, stimescaled;
  76374. cputime_t gtime;
  76375. @@ -1312,11 +1345,6 @@ struct task_struct {
  76376. struct task_cputime cputime_expires;
  76377. struct list_head cpu_timers[3];
  76378. -/* process credentials */
  76379. - const struct cred __rcu *real_cred; /* objective and real subjective task
  76380. - * credentials (COW) */
  76381. - const struct cred __rcu *cred; /* effective (overridable) subjective task
  76382. - * credentials (COW) */
  76383. char comm[TASK_COMM_LEN]; /* executable name excluding path
  76384. - access with [gs]et_task_comm (which lock
  76385. it with task_lock())
  76386. @@ -1333,6 +1361,10 @@ struct task_struct {
  76387. #endif
  76388. /* CPU-specific state of this task */
  76389. struct thread_struct thread;
  76390. +/* thread_info moved to task_struct */
  76391. +#ifdef CONFIG_X86
  76392. + struct thread_info tinfo;
  76393. +#endif
  76394. /* filesystem information */
  76395. struct fs_struct *fs;
  76396. /* open file information */
  76397. @@ -1409,6 +1441,10 @@ struct task_struct {
  76398. gfp_t lockdep_reclaim_gfp;
  76399. #endif
  76400. +/* process credentials */
  76401. + const struct cred __rcu *real_cred; /* objective and real subjective task
  76402. + * credentials (COW) */
  76403. +
  76404. /* journalling filesystem info */
  76405. void *journal_info;
  76406. @@ -1447,6 +1483,10 @@ struct task_struct {
  76407. /* cg_list protected by css_set_lock and tsk->alloc_lock */
  76408. struct list_head cg_list;
  76409. #endif
  76410. +
  76411. + const struct cred __rcu *cred; /* effective (overridable) subjective task
  76412. + * credentials (COW) */
  76413. +
  76414. #ifdef CONFIG_FUTEX
  76415. struct robust_list_head __user *robust_list;
  76416. #ifdef CONFIG_COMPAT
  76417. @@ -1581,7 +1621,78 @@ struct task_struct {
  76418. unsigned int sequential_io;
  76419. unsigned int sequential_io_avg;
  76420. #endif
  76421. -};
  76422. +
  76423. +#ifdef CONFIG_GRKERNSEC
  76424. + /* grsecurity */
  76425. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  76426. + u64 exec_id;
  76427. +#endif
  76428. +#ifdef CONFIG_GRKERNSEC_SETXID
  76429. + const struct cred *delayed_cred;
  76430. +#endif
  76431. + struct dentry *gr_chroot_dentry;
  76432. + struct acl_subject_label *acl;
  76433. + struct acl_subject_label *tmpacl;
  76434. + struct acl_role_label *role;
  76435. + struct file *exec_file;
  76436. + unsigned long brute_expires;
  76437. + u16 acl_role_id;
  76438. + u8 inherited;
  76439. + /* is this the task that authenticated to the special role */
  76440. + u8 acl_sp_role;
  76441. + u8 is_writable;
  76442. + u8 brute;
  76443. + u8 gr_is_chrooted;
  76444. +#endif
  76445. +
  76446. +} __randomize_layout;
  76447. +
  76448. +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
  76449. +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
  76450. +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
  76451. +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
  76452. +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
  76453. +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
  76454. +
  76455. +#ifdef CONFIG_PAX_SOFTMODE
  76456. +extern int pax_softmode;
  76457. +#endif
  76458. +
  76459. +extern int pax_check_flags(unsigned long *);
  76460. +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
  76461. +
  76462. +/* if tsk != current then task_lock must be held on it */
  76463. +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
  76464. +static inline unsigned long pax_get_flags(struct task_struct *tsk)
  76465. +{
  76466. + if (likely(tsk->mm))
  76467. + return tsk->mm->pax_flags;
  76468. + else
  76469. + return 0UL;
  76470. +}
  76471. +
  76472. +/* if tsk != current then task_lock must be held on it */
  76473. +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
  76474. +{
  76475. + if (likely(tsk->mm)) {
  76476. + tsk->mm->pax_flags = flags;
  76477. + return 0;
  76478. + }
  76479. + return -EINVAL;
  76480. +}
  76481. +#endif
  76482. +
  76483. +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
  76484. +extern void pax_set_initial_flags(struct linux_binprm *bprm);
  76485. +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
  76486. +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
  76487. +#endif
  76488. +
  76489. +struct path;
  76490. +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
  76491. +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
  76492. +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
  76493. +extern void pax_report_refcount_overflow(struct pt_regs *regs);
  76494. /* Future-safe accessor for struct task_struct's cpus_allowed. */
  76495. #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
  76496. @@ -1658,7 +1769,7 @@ struct pid_namespace;
  76497. pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
  76498. struct pid_namespace *ns);
  76499. -static inline pid_t task_pid_nr(struct task_struct *tsk)
  76500. +static inline pid_t task_pid_nr(const struct task_struct *tsk)
  76501. {
  76502. return tsk->pid;
  76503. }
  76504. @@ -2112,7 +2223,9 @@ void yield(void);
  76505. extern struct exec_domain default_exec_domain;
  76506. union thread_union {
  76507. +#ifndef CONFIG_X86
  76508. struct thread_info thread_info;
  76509. +#endif
  76510. unsigned long stack[THREAD_SIZE/sizeof(long)];
  76511. };
  76512. @@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
  76513. */
  76514. extern struct task_struct *find_task_by_vpid(pid_t nr);
  76515. +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
  76516. extern struct task_struct *find_task_by_pid_ns(pid_t nr,
  76517. struct pid_namespace *ns);
  76518. @@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
  76519. extern void exit_itimers(struct signal_struct *);
  76520. extern void flush_itimer_signals(void);
  76521. -extern void do_group_exit(int);
  76522. +extern __noreturn void do_group_exit(int);
  76523. extern int allow_signal(int);
  76524. extern int disallow_signal(int);
  76525. @@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
  76526. #endif
  76527. -static inline int object_is_on_stack(void *obj)
  76528. +static inline int object_starts_on_stack(void *obj)
  76529. {
  76530. - void *stack = task_stack_page(current);
  76531. + const void *stack = task_stack_page(current);
  76532. return (obj >= stack) && (obj < (stack + THREAD_SIZE));
  76533. }
  76534. diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
  76535. index 8045a55..c959cd5 100644
  76536. --- a/include/linux/sched/sysctl.h
  76537. +++ b/include/linux/sched/sysctl.h
  76538. @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
  76539. #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
  76540. extern int sysctl_max_map_count;
  76541. +extern unsigned long sysctl_heap_stack_gap;
  76542. extern unsigned int sysctl_sched_latency;
  76543. extern unsigned int sysctl_sched_min_granularity;
  76544. diff --git a/include/linux/security.h b/include/linux/security.h
  76545. index 2fc42d1..4d802f2 100644
  76546. --- a/include/linux/security.h
  76547. +++ b/include/linux/security.h
  76548. @@ -27,6 +27,7 @@
  76549. #include <linux/slab.h>
  76550. #include <linux/err.h>
  76551. #include <linux/string.h>
  76552. +#include <linux/grsecurity.h>
  76553. struct linux_binprm;
  76554. struct cred;
  76555. @@ -116,8 +117,6 @@ struct seq_file;
  76556. extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
  76557. -void reset_security_ops(void);
  76558. -
  76559. #ifdef CONFIG_MMU
  76560. extern unsigned long mmap_min_addr;
  76561. extern unsigned long dac_mmap_min_addr;
  76562. @@ -1719,7 +1718,7 @@ struct security_operations {
  76563. struct audit_context *actx);
  76564. void (*audit_rule_free) (void *lsmrule);
  76565. #endif /* CONFIG_AUDIT */
  76566. -};
  76567. +} __randomize_layout;
  76568. /* prototypes */
  76569. extern int security_init(void);
  76570. diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
  76571. index dc368b8..e895209 100644
  76572. --- a/include/linux/semaphore.h
  76573. +++ b/include/linux/semaphore.h
  76574. @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
  76575. }
  76576. extern void down(struct semaphore *sem);
  76577. -extern int __must_check down_interruptible(struct semaphore *sem);
  76578. +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
  76579. extern int __must_check down_killable(struct semaphore *sem);
  76580. extern int __must_check down_trylock(struct semaphore *sem);
  76581. extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
  76582. diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
  76583. index 52e0097..383f21d 100644
  76584. --- a/include/linux/seq_file.h
  76585. +++ b/include/linux/seq_file.h
  76586. @@ -27,6 +27,9 @@ struct seq_file {
  76587. struct mutex lock;
  76588. const struct seq_operations *op;
  76589. int poll_event;
  76590. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  76591. + u64 exec_id;
  76592. +#endif
  76593. #ifdef CONFIG_USER_NS
  76594. struct user_namespace *user_ns;
  76595. #endif
  76596. @@ -39,6 +42,7 @@ struct seq_operations {
  76597. void * (*next) (struct seq_file *m, void *v, loff_t *pos);
  76598. int (*show) (struct seq_file *m, void *v);
  76599. };
  76600. +typedef struct seq_operations __no_const seq_operations_no_const;
  76601. #define SEQ_SKIP 1
  76602. @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
  76603. char *mangle_path(char *s, const char *p, const char *esc);
  76604. int seq_open(struct file *, const struct seq_operations *);
  76605. +int seq_open_restrict(struct file *, const struct seq_operations *);
  76606. ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
  76607. loff_t seq_lseek(struct file *, loff_t, int);
  76608. int seq_release(struct inode *, struct file *);
  76609. @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
  76610. }
  76611. int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
  76612. +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
  76613. int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
  76614. int single_release(struct inode *, struct file *);
  76615. void *__seq_open_private(struct file *, const struct seq_operations *, int);
  76616. diff --git a/include/linux/shm.h b/include/linux/shm.h
  76617. index 1e2cd2e..0288750 100644
  76618. --- a/include/linux/shm.h
  76619. +++ b/include/linux/shm.h
  76620. @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
  76621. /* The task created the shm object. NULL if the task is dead. */
  76622. struct task_struct *shm_creator;
  76623. +#ifdef CONFIG_GRKERNSEC
  76624. + time_t shm_createtime;
  76625. + pid_t shm_lapid;
  76626. +#endif
  76627. };
  76628. /* shm_mode upper byte flags */
  76629. diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
  76630. index 15ede6a..80161c3 100644
  76631. --- a/include/linux/skbuff.h
  76632. +++ b/include/linux/skbuff.h
  76633. @@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
  76634. struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
  76635. int node);
  76636. struct sk_buff *build_skb(void *data, unsigned int frag_size);
  76637. -static inline struct sk_buff *alloc_skb(unsigned int size,
  76638. +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
  76639. gfp_t priority)
  76640. {
  76641. return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
  76642. @@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
  76643. return skb->inner_transport_header - skb->inner_network_header;
  76644. }
  76645. -static inline int skb_network_offset(const struct sk_buff *skb)
  76646. +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
  76647. {
  76648. return skb_network_header(skb) - skb->data;
  76649. }
  76650. @@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
  76651. * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
  76652. */
  76653. #ifndef NET_SKB_PAD
  76654. -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
  76655. +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
  76656. #endif
  76657. int ___pskb_trim(struct sk_buff *skb, unsigned int len);
  76658. @@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
  76659. int *err);
  76660. unsigned int datagram_poll(struct file *file, struct socket *sock,
  76661. struct poll_table_struct *wait);
  76662. -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
  76663. +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
  76664. struct iovec *to, int size);
  76665. int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
  76666. struct iovec *iov);
  76667. @@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
  76668. nf_bridge_put(skb->nf_bridge);
  76669. skb->nf_bridge = NULL;
  76670. #endif
  76671. +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
  76672. + skb->nf_trace = 0;
  76673. +#endif
  76674. }
  76675. static inline void nf_reset_trace(struct sk_buff *skb)
  76676. diff --git a/include/linux/slab.h b/include/linux/slab.h
  76677. index b5b2df6..69f5734 100644
  76678. --- a/include/linux/slab.h
  76679. +++ b/include/linux/slab.h
  76680. @@ -14,15 +14,29 @@
  76681. #include <linux/gfp.h>
  76682. #include <linux/types.h>
  76683. #include <linux/workqueue.h>
  76684. -
  76685. +#include <linux/err.h>
  76686. /*
  76687. * Flags to pass to kmem_cache_create().
  76688. * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
  76689. */
  76690. #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
  76691. +
  76692. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  76693. +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
  76694. +#else
  76695. +#define SLAB_USERCOPY 0x00000000UL
  76696. +#endif
  76697. +
  76698. #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
  76699. #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
  76700. +
  76701. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  76702. +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
  76703. +#else
  76704. +#define SLAB_NO_SANITIZE 0x00000000UL
  76705. +#endif
  76706. +
  76707. #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
  76708. #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
  76709. #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
  76710. @@ -98,10 +112,13 @@
  76711. * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
  76712. * Both make kfree a no-op.
  76713. */
  76714. -#define ZERO_SIZE_PTR ((void *)16)
  76715. +#define ZERO_SIZE_PTR \
  76716. +({ \
  76717. + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
  76718. + (void *)(-MAX_ERRNO-1L); \
  76719. +})
  76720. -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
  76721. - (unsigned long)ZERO_SIZE_PTR)
  76722. +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
  76723. #include <linux/kmemleak.h>
  76724. @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
  76725. void kfree(const void *);
  76726. void kzfree(const void *);
  76727. size_t ksize(const void *);
  76728. +const char *check_heap_object(const void *ptr, unsigned long n);
  76729. +bool is_usercopy_object(const void *ptr);
  76730. /*
  76731. * Some archs want to perform DMA into kmalloc caches and need a guaranteed
  76732. @@ -174,7 +193,7 @@ struct kmem_cache {
  76733. unsigned int align; /* Alignment as calculated */
  76734. unsigned long flags; /* Active flags on the slab */
  76735. const char *name; /* Slab name for sysfs */
  76736. - int refcount; /* Use counter */
  76737. + atomic_t refcount; /* Use counter */
  76738. void (*ctor)(void *); /* Called on object slot creation */
  76739. struct list_head list; /* List of all slab caches on the system */
  76740. };
  76741. @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
  76742. extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
  76743. #endif
  76744. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  76745. +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
  76746. +#endif
  76747. +
  76748. /*
  76749. * Figure out which kmalloc slab an allocation of a certain size
  76750. * belongs to.
  76751. @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
  76752. * 2 = 120 .. 192 bytes
  76753. * n = 2^(n-1) .. 2^n -1
  76754. */
  76755. -static __always_inline int kmalloc_index(size_t size)
  76756. +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
  76757. {
  76758. if (!size)
  76759. return 0;
  76760. @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
  76761. }
  76762. #endif /* !CONFIG_SLOB */
  76763. -void *__kmalloc(size_t size, gfp_t flags);
  76764. +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
  76765. void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
  76766. #ifdef CONFIG_NUMA
  76767. -void *__kmalloc_node(size_t size, gfp_t flags, int node);
  76768. +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
  76769. void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
  76770. #else
  76771. static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
  76772. diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
  76773. index 8235dfb..47ce586 100644
  76774. --- a/include/linux/slab_def.h
  76775. +++ b/include/linux/slab_def.h
  76776. @@ -38,7 +38,7 @@ struct kmem_cache {
  76777. /* 4) cache creation/removal */
  76778. const char *name;
  76779. struct list_head list;
  76780. - int refcount;
  76781. + atomic_t refcount;
  76782. int object_size;
  76783. int align;
  76784. @@ -54,10 +54,14 @@ struct kmem_cache {
  76785. unsigned long node_allocs;
  76786. unsigned long node_frees;
  76787. unsigned long node_overflow;
  76788. - atomic_t allochit;
  76789. - atomic_t allocmiss;
  76790. - atomic_t freehit;
  76791. - atomic_t freemiss;
  76792. + atomic_unchecked_t allochit;
  76793. + atomic_unchecked_t allocmiss;
  76794. + atomic_unchecked_t freehit;
  76795. + atomic_unchecked_t freemiss;
  76796. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  76797. + atomic_unchecked_t sanitized;
  76798. + atomic_unchecked_t not_sanitized;
  76799. +#endif
  76800. /*
  76801. * If debugging is enabled, then the allocator can add additional
  76802. diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
  76803. index f56bfa9..8378a26 100644
  76804. --- a/include/linux/slub_def.h
  76805. +++ b/include/linux/slub_def.h
  76806. @@ -74,7 +74,7 @@ struct kmem_cache {
  76807. struct kmem_cache_order_objects max;
  76808. struct kmem_cache_order_objects min;
  76809. gfp_t allocflags; /* gfp flags to use on each alloc */
  76810. - int refcount; /* Refcount for slab cache destroy */
  76811. + atomic_t refcount; /* Refcount for slab cache destroy */
  76812. void (*ctor)(void *);
  76813. int inuse; /* Offset to metadata */
  76814. int align; /* Alignment */
  76815. diff --git a/include/linux/smp.h b/include/linux/smp.h
  76816. index 6ae004e..2743532 100644
  76817. --- a/include/linux/smp.h
  76818. +++ b/include/linux/smp.h
  76819. @@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
  76820. #endif
  76821. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  76822. +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
  76823. #define put_cpu() preempt_enable()
  76824. +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
  76825. /*
  76826. * Callback to arch code if there's nosmp or maxcpus=0 on the
  76827. diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
  76828. index 54f91d3..be2c379 100644
  76829. --- a/include/linux/sock_diag.h
  76830. +++ b/include/linux/sock_diag.h
  76831. @@ -11,7 +11,7 @@ struct sock;
  76832. struct sock_diag_handler {
  76833. __u8 family;
  76834. int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
  76835. -};
  76836. +} __do_const;
  76837. int sock_diag_register(const struct sock_diag_handler *h);
  76838. void sock_diag_unregister(const struct sock_diag_handler *h);
  76839. diff --git a/include/linux/sonet.h b/include/linux/sonet.h
  76840. index 680f9a3..f13aeb0 100644
  76841. --- a/include/linux/sonet.h
  76842. +++ b/include/linux/sonet.h
  76843. @@ -7,7 +7,7 @@
  76844. #include <uapi/linux/sonet.h>
  76845. struct k_sonet_stats {
  76846. -#define __HANDLE_ITEM(i) atomic_t i
  76847. +#define __HANDLE_ITEM(i) atomic_unchecked_t i
  76848. __SONET_ITEMS
  76849. #undef __HANDLE_ITEM
  76850. };
  76851. diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
  76852. index 07d8e53..dc934c9 100644
  76853. --- a/include/linux/sunrpc/addr.h
  76854. +++ b/include/linux/sunrpc/addr.h
  76855. @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
  76856. {
  76857. switch (sap->sa_family) {
  76858. case AF_INET:
  76859. - return ntohs(((struct sockaddr_in *)sap)->sin_port);
  76860. + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
  76861. case AF_INET6:
  76862. - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
  76863. + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
  76864. }
  76865. return 0;
  76866. }
  76867. @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
  76868. static inline bool __rpc_copy_addr4(struct sockaddr *dst,
  76869. const struct sockaddr *src)
  76870. {
  76871. - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
  76872. + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
  76873. struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
  76874. dsin->sin_family = ssin->sin_family;
  76875. @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
  76876. if (sa->sa_family != AF_INET6)
  76877. return 0;
  76878. - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
  76879. + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
  76880. }
  76881. #endif /* _LINUX_SUNRPC_ADDR_H */
  76882. diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
  76883. index 8af2804..c7414ef 100644
  76884. --- a/include/linux/sunrpc/clnt.h
  76885. +++ b/include/linux/sunrpc/clnt.h
  76886. @@ -97,7 +97,7 @@ struct rpc_procinfo {
  76887. unsigned int p_timer; /* Which RTT timer to use */
  76888. u32 p_statidx; /* Which procedure to account */
  76889. const char * p_name; /* name of procedure */
  76890. -};
  76891. +} __do_const;
  76892. #ifdef __KERNEL__
  76893. diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
  76894. index 04e7632..2e2a8a3 100644
  76895. --- a/include/linux/sunrpc/svc.h
  76896. +++ b/include/linux/sunrpc/svc.h
  76897. @@ -412,7 +412,7 @@ struct svc_procedure {
  76898. unsigned int pc_count; /* call count */
  76899. unsigned int pc_cachetype; /* cache info (NFS) */
  76900. unsigned int pc_xdrressize; /* maximum size of XDR reply */
  76901. -};
  76902. +} __do_const;
  76903. /*
  76904. * Function prototypes.
  76905. diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
  76906. index 0b8e3e6..33e0a01 100644
  76907. --- a/include/linux/sunrpc/svc_rdma.h
  76908. +++ b/include/linux/sunrpc/svc_rdma.h
  76909. @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
  76910. extern unsigned int svcrdma_max_requests;
  76911. extern unsigned int svcrdma_max_req_size;
  76912. -extern atomic_t rdma_stat_recv;
  76913. -extern atomic_t rdma_stat_read;
  76914. -extern atomic_t rdma_stat_write;
  76915. -extern atomic_t rdma_stat_sq_starve;
  76916. -extern atomic_t rdma_stat_rq_starve;
  76917. -extern atomic_t rdma_stat_rq_poll;
  76918. -extern atomic_t rdma_stat_rq_prod;
  76919. -extern atomic_t rdma_stat_sq_poll;
  76920. -extern atomic_t rdma_stat_sq_prod;
  76921. +extern atomic_unchecked_t rdma_stat_recv;
  76922. +extern atomic_unchecked_t rdma_stat_read;
  76923. +extern atomic_unchecked_t rdma_stat_write;
  76924. +extern atomic_unchecked_t rdma_stat_sq_starve;
  76925. +extern atomic_unchecked_t rdma_stat_rq_starve;
  76926. +extern atomic_unchecked_t rdma_stat_rq_poll;
  76927. +extern atomic_unchecked_t rdma_stat_rq_prod;
  76928. +extern atomic_unchecked_t rdma_stat_sq_poll;
  76929. +extern atomic_unchecked_t rdma_stat_sq_prod;
  76930. #define RPCRDMA_VERSION 1
  76931. diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
  76932. index 8d71d65..f79586e 100644
  76933. --- a/include/linux/sunrpc/svcauth.h
  76934. +++ b/include/linux/sunrpc/svcauth.h
  76935. @@ -120,7 +120,7 @@ struct auth_ops {
  76936. int (*release)(struct svc_rqst *rq);
  76937. void (*domain_release)(struct auth_domain *);
  76938. int (*set_client)(struct svc_rqst *rq);
  76939. -};
  76940. +} __do_const;
  76941. #define SVC_GARBAGE 1
  76942. #define SVC_SYSERR 2
  76943. diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
  76944. index a5ffd32..0935dea 100644
  76945. --- a/include/linux/swiotlb.h
  76946. +++ b/include/linux/swiotlb.h
  76947. @@ -60,7 +60,8 @@ extern void
  76948. extern void
  76949. swiotlb_free_coherent(struct device *hwdev, size_t size,
  76950. - void *vaddr, dma_addr_t dma_handle);
  76951. + void *vaddr, dma_addr_t dma_handle,
  76952. + struct dma_attrs *attrs);
  76953. extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
  76954. unsigned long offset, size_t size,
  76955. diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
  76956. index a747a77..9e14df7 100644
  76957. --- a/include/linux/syscalls.h
  76958. +++ b/include/linux/syscalls.h
  76959. @@ -98,8 +98,14 @@ struct sigaltstack;
  76960. #define __MAP(n,...) __MAP##n(__VA_ARGS__)
  76961. #define __SC_DECL(t, a) t a
  76962. +#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
  76963. #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
  76964. -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
  76965. +#define __SC_LONG(t, a) __typeof( \
  76966. + __builtin_choose_expr( \
  76967. + sizeof(t) > sizeof(int), \
  76968. + (t) 0, \
  76969. + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
  76970. + )) a
  76971. #define __SC_CAST(t, a) (t) a
  76972. #define __SC_ARGS(t, a) a
  76973. #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
  76974. @@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
  76975. asmlinkage long sys_fsync(unsigned int fd);
  76976. asmlinkage long sys_fdatasync(unsigned int fd);
  76977. asmlinkage long sys_bdflush(int func, long data);
  76978. -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
  76979. - char __user *type, unsigned long flags,
  76980. +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
  76981. + const char __user *type, unsigned long flags,
  76982. void __user *data);
  76983. -asmlinkage long sys_umount(char __user *name, int flags);
  76984. -asmlinkage long sys_oldumount(char __user *name);
  76985. +asmlinkage long sys_umount(const char __user *name, int flags);
  76986. +asmlinkage long sys_oldumount(const char __user *name);
  76987. asmlinkage long sys_truncate(const char __user *path, long length);
  76988. asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
  76989. asmlinkage long sys_stat(const char __user *filename,
  76990. @@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
  76991. asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
  76992. asmlinkage long sys_send(int, void __user *, size_t, unsigned);
  76993. asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
  76994. - struct sockaddr __user *, int);
  76995. + struct sockaddr __user *, int) __intentional_overflow(0);
  76996. asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
  76997. asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
  76998. unsigned int vlen, unsigned flags);
  76999. diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
  77000. index 27b3b0b..e093dd9 100644
  77001. --- a/include/linux/syscore_ops.h
  77002. +++ b/include/linux/syscore_ops.h
  77003. @@ -16,7 +16,7 @@ struct syscore_ops {
  77004. int (*suspend)(void);
  77005. void (*resume)(void);
  77006. void (*shutdown)(void);
  77007. -};
  77008. +} __do_const;
  77009. extern void register_syscore_ops(struct syscore_ops *ops);
  77010. extern void unregister_syscore_ops(struct syscore_ops *ops);
  77011. diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
  77012. index 14a8ff2..fa95f3a 100644
  77013. --- a/include/linux/sysctl.h
  77014. +++ b/include/linux/sysctl.h
  77015. @@ -34,13 +34,13 @@ struct ctl_table_root;
  77016. struct ctl_table_header;
  77017. struct ctl_dir;
  77018. -typedef struct ctl_table ctl_table;
  77019. -
  77020. typedef int proc_handler (struct ctl_table *ctl, int write,
  77021. void __user *buffer, size_t *lenp, loff_t *ppos);
  77022. extern int proc_dostring(struct ctl_table *, int,
  77023. void __user *, size_t *, loff_t *);
  77024. +extern int proc_dostring_modpriv(struct ctl_table *, int,
  77025. + void __user *, size_t *, loff_t *);
  77026. extern int proc_dointvec(struct ctl_table *, int,
  77027. void __user *, size_t *, loff_t *);
  77028. extern int proc_dointvec_minmax(struct ctl_table *, int,
  77029. @@ -115,7 +115,9 @@ struct ctl_table
  77030. struct ctl_table_poll *poll;
  77031. void *extra1;
  77032. void *extra2;
  77033. -};
  77034. +} __do_const __randomize_layout;
  77035. +typedef struct ctl_table __no_const ctl_table_no_const;
  77036. +typedef struct ctl_table ctl_table;
  77037. struct ctl_node {
  77038. struct rb_node node;
  77039. diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
  77040. index 30b2ebe..37412ef 100644
  77041. --- a/include/linux/sysfs.h
  77042. +++ b/include/linux/sysfs.h
  77043. @@ -34,7 +34,8 @@ struct attribute {
  77044. struct lock_class_key *key;
  77045. struct lock_class_key skey;
  77046. #endif
  77047. -};
  77048. +} __do_const;
  77049. +typedef struct attribute __no_const attribute_no_const;
  77050. /**
  77051. * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
  77052. @@ -63,7 +64,8 @@ struct attribute_group {
  77053. struct attribute *, int);
  77054. struct attribute **attrs;
  77055. struct bin_attribute **bin_attrs;
  77056. -};
  77057. +} __do_const;
  77058. +typedef struct attribute_group __no_const attribute_group_no_const;
  77059. /**
  77060. * Use these macros to make defining attributes easier. See include/linux/device.h
  77061. @@ -127,7 +129,8 @@ struct bin_attribute {
  77062. char *, loff_t, size_t);
  77063. int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
  77064. struct vm_area_struct *vma);
  77065. -};
  77066. +} __do_const;
  77067. +typedef struct bin_attribute __no_const bin_attribute_no_const;
  77068. /**
  77069. * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
  77070. diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
  77071. index 387fa7d..3fcde6b 100644
  77072. --- a/include/linux/sysrq.h
  77073. +++ b/include/linux/sysrq.h
  77074. @@ -16,6 +16,7 @@
  77075. #include <linux/errno.h>
  77076. #include <linux/types.h>
  77077. +#include <linux/compiler.h>
  77078. /* Possible values of bitmask for enabling sysrq functions */
  77079. /* 0x0001 is reserved for enable everything */
  77080. @@ -33,7 +34,7 @@ struct sysrq_key_op {
  77081. char *help_msg;
  77082. char *action_msg;
  77083. int enable_mask;
  77084. -};
  77085. +} __do_const;
  77086. #ifdef CONFIG_MAGIC_SYSRQ
  77087. diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
  77088. index fddbe20..e4cce53 100644
  77089. --- a/include/linux/thread_info.h
  77090. +++ b/include/linux/thread_info.h
  77091. @@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
  77092. #error "no set_restore_sigmask() provided and default one won't work"
  77093. #endif
  77094. +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
  77095. +
  77096. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
  77097. +extern void pax_check_alloca(unsigned long size);
  77098. +#endif
  77099. +
  77100. +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
  77101. +{
  77102. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
  77103. + /* always check if we've overflowed the stack in a copy*user */
  77104. + pax_check_alloca(sizeof(unsigned long));
  77105. +#endif
  77106. +
  77107. +#ifndef CONFIG_PAX_USERCOPY_DEBUG
  77108. + if (!__builtin_constant_p(n))
  77109. +#endif
  77110. + __check_object_size(ptr, n, to_user);
  77111. +}
  77112. +
  77113. #endif /* __KERNEL__ */
  77114. #endif /* _LINUX_THREAD_INFO_H */
  77115. diff --git a/include/linux/tty.h b/include/linux/tty.h
  77116. index b90b5c2..e23a512 100644
  77117. --- a/include/linux/tty.h
  77118. +++ b/include/linux/tty.h
  77119. @@ -202,7 +202,7 @@ struct tty_port {
  77120. const struct tty_port_operations *ops; /* Port operations */
  77121. spinlock_t lock; /* Lock protecting tty field */
  77122. int blocked_open; /* Waiting to open */
  77123. - int count; /* Usage count */
  77124. + atomic_t count; /* Usage count */
  77125. wait_queue_head_t open_wait; /* Open waiters */
  77126. wait_queue_head_t close_wait; /* Close waiters */
  77127. wait_queue_head_t delta_msr_wait; /* Modem status change */
  77128. @@ -284,7 +284,7 @@ struct tty_struct {
  77129. /* If the tty has a pending do_SAK, queue it here - akpm */
  77130. struct work_struct SAK_work;
  77131. struct tty_port *port;
  77132. -};
  77133. +} __randomize_layout;
  77134. /* Each of a tty's open files has private_data pointing to tty_file_private */
  77135. struct tty_file_private {
  77136. @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
  77137. struct tty_struct *tty, struct file *filp);
  77138. static inline int tty_port_users(struct tty_port *port)
  77139. {
  77140. - return port->count + port->blocked_open;
  77141. + return atomic_read(&port->count) + port->blocked_open;
  77142. }
  77143. extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
  77144. diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
  77145. index 756a609..89db85e 100644
  77146. --- a/include/linux/tty_driver.h
  77147. +++ b/include/linux/tty_driver.h
  77148. @@ -285,7 +285,7 @@ struct tty_operations {
  77149. void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
  77150. #endif
  77151. const struct file_operations *proc_fops;
  77152. -};
  77153. +} __do_const __randomize_layout;
  77154. struct tty_driver {
  77155. int magic; /* magic number for this structure */
  77156. @@ -319,7 +319,7 @@ struct tty_driver {
  77157. const struct tty_operations *ops;
  77158. struct list_head tty_drivers;
  77159. -};
  77160. +} __randomize_layout;
  77161. extern struct list_head tty_drivers;
  77162. diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
  77163. index b8347c2..85d8b0f 100644
  77164. --- a/include/linux/tty_ldisc.h
  77165. +++ b/include/linux/tty_ldisc.h
  77166. @@ -213,7 +213,7 @@ struct tty_ldisc_ops {
  77167. struct module *owner;
  77168. - int refcount;
  77169. + atomic_t refcount;
  77170. };
  77171. struct tty_ldisc {
  77172. diff --git a/include/linux/types.h b/include/linux/types.h
  77173. index 4d118ba..c3ee9bf 100644
  77174. --- a/include/linux/types.h
  77175. +++ b/include/linux/types.h
  77176. @@ -176,10 +176,26 @@ typedef struct {
  77177. int counter;
  77178. } atomic_t;
  77179. +#ifdef CONFIG_PAX_REFCOUNT
  77180. +typedef struct {
  77181. + int counter;
  77182. +} atomic_unchecked_t;
  77183. +#else
  77184. +typedef atomic_t atomic_unchecked_t;
  77185. +#endif
  77186. +
  77187. #ifdef CONFIG_64BIT
  77188. typedef struct {
  77189. long counter;
  77190. } atomic64_t;
  77191. +
  77192. +#ifdef CONFIG_PAX_REFCOUNT
  77193. +typedef struct {
  77194. + long counter;
  77195. +} atomic64_unchecked_t;
  77196. +#else
  77197. +typedef atomic64_t atomic64_unchecked_t;
  77198. +#endif
  77199. #endif
  77200. struct list_head {
  77201. diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
  77202. index ecd3319..8a36ded 100644
  77203. --- a/include/linux/uaccess.h
  77204. +++ b/include/linux/uaccess.h
  77205. @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
  77206. long ret; \
  77207. mm_segment_t old_fs = get_fs(); \
  77208. \
  77209. - set_fs(KERNEL_DS); \
  77210. pagefault_disable(); \
  77211. - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
  77212. - pagefault_enable(); \
  77213. + set_fs(KERNEL_DS); \
  77214. + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
  77215. set_fs(old_fs); \
  77216. + pagefault_enable(); \
  77217. ret; \
  77218. })
  77219. diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
  77220. index 2d1f9b6..d7a9fce 100644
  77221. --- a/include/linux/uidgid.h
  77222. +++ b/include/linux/uidgid.h
  77223. @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
  77224. #endif /* CONFIG_USER_NS */
  77225. +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
  77226. +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
  77227. +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
  77228. +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
  77229. +
  77230. #endif /* _LINUX_UIDGID_H */
  77231. diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
  77232. index 99c1b4d..562e6f3 100644
  77233. --- a/include/linux/unaligned/access_ok.h
  77234. +++ b/include/linux/unaligned/access_ok.h
  77235. @@ -4,34 +4,34 @@
  77236. #include <linux/kernel.h>
  77237. #include <asm/byteorder.h>
  77238. -static inline u16 get_unaligned_le16(const void *p)
  77239. +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
  77240. {
  77241. - return le16_to_cpup((__le16 *)p);
  77242. + return le16_to_cpup((const __le16 *)p);
  77243. }
  77244. -static inline u32 get_unaligned_le32(const void *p)
  77245. +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
  77246. {
  77247. - return le32_to_cpup((__le32 *)p);
  77248. + return le32_to_cpup((const __le32 *)p);
  77249. }
  77250. -static inline u64 get_unaligned_le64(const void *p)
  77251. +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
  77252. {
  77253. - return le64_to_cpup((__le64 *)p);
  77254. + return le64_to_cpup((const __le64 *)p);
  77255. }
  77256. -static inline u16 get_unaligned_be16(const void *p)
  77257. +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
  77258. {
  77259. - return be16_to_cpup((__be16 *)p);
  77260. + return be16_to_cpup((const __be16 *)p);
  77261. }
  77262. -static inline u32 get_unaligned_be32(const void *p)
  77263. +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
  77264. {
  77265. - return be32_to_cpup((__be32 *)p);
  77266. + return be32_to_cpup((const __be32 *)p);
  77267. }
  77268. -static inline u64 get_unaligned_be64(const void *p)
  77269. +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
  77270. {
  77271. - return be64_to_cpup((__be64 *)p);
  77272. + return be64_to_cpup((const __be64 *)p);
  77273. }
  77274. static inline void put_unaligned_le16(u16 val, void *p)
  77275. diff --git a/include/linux/usb.h b/include/linux/usb.h
  77276. index 7f6eb85..656e806 100644
  77277. --- a/include/linux/usb.h
  77278. +++ b/include/linux/usb.h
  77279. @@ -563,7 +563,7 @@ struct usb_device {
  77280. int maxchild;
  77281. u32 quirks;
  77282. - atomic_t urbnum;
  77283. + atomic_unchecked_t urbnum;
  77284. unsigned long active_duration;
  77285. @@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
  77286. extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
  77287. __u8 request, __u8 requesttype, __u16 value, __u16 index,
  77288. - void *data, __u16 size, int timeout);
  77289. + void *data, __u16 size, int timeout) __intentional_overflow(-1);
  77290. extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
  77291. void *data, int len, int *actual_length, int timeout);
  77292. extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
  77293. diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
  77294. index e452ba6..78f8e80 100644
  77295. --- a/include/linux/usb/renesas_usbhs.h
  77296. +++ b/include/linux/usb/renesas_usbhs.h
  77297. @@ -39,7 +39,7 @@ enum {
  77298. */
  77299. struct renesas_usbhs_driver_callback {
  77300. int (*notify_hotplug)(struct platform_device *pdev);
  77301. -};
  77302. +} __no_const;
  77303. /*
  77304. * callback functions for platform
  77305. diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
  77306. index 4836ba3..603f6ee 100644
  77307. --- a/include/linux/user_namespace.h
  77308. +++ b/include/linux/user_namespace.h
  77309. @@ -33,7 +33,7 @@ struct user_namespace {
  77310. struct key *persistent_keyring_register;
  77311. struct rw_semaphore persistent_keyring_register_sem;
  77312. #endif
  77313. -};
  77314. +} __randomize_layout;
  77315. extern struct user_namespace init_user_ns;
  77316. diff --git a/include/linux/utsname.h b/include/linux/utsname.h
  77317. index 239e277..22a5cf5 100644
  77318. --- a/include/linux/utsname.h
  77319. +++ b/include/linux/utsname.h
  77320. @@ -24,7 +24,7 @@ struct uts_namespace {
  77321. struct new_utsname name;
  77322. struct user_namespace *user_ns;
  77323. unsigned int proc_inum;
  77324. -};
  77325. +} __randomize_layout;
  77326. extern struct uts_namespace init_uts_ns;
  77327. #ifdef CONFIG_UTS_NS
  77328. diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
  77329. index 6f8fbcf..4efc177 100644
  77330. --- a/include/linux/vermagic.h
  77331. +++ b/include/linux/vermagic.h
  77332. @@ -25,9 +25,42 @@
  77333. #define MODULE_ARCH_VERMAGIC ""
  77334. #endif
  77335. +#ifdef CONFIG_PAX_REFCOUNT
  77336. +#define MODULE_PAX_REFCOUNT "REFCOUNT "
  77337. +#else
  77338. +#define MODULE_PAX_REFCOUNT ""
  77339. +#endif
  77340. +
  77341. +#ifdef CONSTIFY_PLUGIN
  77342. +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
  77343. +#else
  77344. +#define MODULE_CONSTIFY_PLUGIN ""
  77345. +#endif
  77346. +
  77347. +#ifdef STACKLEAK_PLUGIN
  77348. +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
  77349. +#else
  77350. +#define MODULE_STACKLEAK_PLUGIN ""
  77351. +#endif
  77352. +
  77353. +#ifdef RANDSTRUCT_PLUGIN
  77354. +#include <generated/randomize_layout_hash.h>
  77355. +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
  77356. +#else
  77357. +#define MODULE_RANDSTRUCT_PLUGIN
  77358. +#endif
  77359. +
  77360. +#ifdef CONFIG_GRKERNSEC
  77361. +#define MODULE_GRSEC "GRSEC "
  77362. +#else
  77363. +#define MODULE_GRSEC ""
  77364. +#endif
  77365. +
  77366. #define VERMAGIC_STRING \
  77367. UTS_RELEASE " " \
  77368. MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
  77369. MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
  77370. - MODULE_ARCH_VERMAGIC
  77371. + MODULE_ARCH_VERMAGIC \
  77372. + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
  77373. + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
  77374. diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
  77375. index 502073a..a7de024 100644
  77376. --- a/include/linux/vga_switcheroo.h
  77377. +++ b/include/linux/vga_switcheroo.h
  77378. @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
  77379. void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
  77380. -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
  77381. -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
  77382. +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
  77383. +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
  77384. #else
  77385. static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
  77386. @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
  77387. static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
  77388. -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
  77389. -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
  77390. +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
  77391. +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
  77392. #endif
  77393. #endif /* _LINUX_VGA_SWITCHEROO_H_ */
  77394. diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
  77395. index 4b8a891..cb8df6e 100644
  77396. --- a/include/linux/vmalloc.h
  77397. +++ b/include/linux/vmalloc.h
  77398. @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
  77399. #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
  77400. #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
  77401. #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
  77402. +
  77403. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
  77404. +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
  77405. +#endif
  77406. +
  77407. /* bits [20..32] reserved for arch specific ioremap internals */
  77408. /*
  77409. @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
  77410. /* for /dev/kmem */
  77411. extern long vread(char *buf, char *addr, unsigned long count);
  77412. -extern long vwrite(char *buf, char *addr, unsigned long count);
  77413. +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
  77414. /*
  77415. * Internals. Dont't use..
  77416. diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
  77417. index 67ce70c..d540954 100644
  77418. --- a/include/linux/vmstat.h
  77419. +++ b/include/linux/vmstat.h
  77420. @@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
  77421. /*
  77422. * Zone based page accounting with per cpu differentials.
  77423. */
  77424. -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  77425. +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  77426. static inline void zone_page_state_add(long x, struct zone *zone,
  77427. enum zone_stat_item item)
  77428. {
  77429. - atomic_long_add(x, &zone->vm_stat[item]);
  77430. - atomic_long_add(x, &vm_stat[item]);
  77431. + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
  77432. + atomic_long_add_unchecked(x, &vm_stat[item]);
  77433. }
  77434. -static inline unsigned long global_page_state(enum zone_stat_item item)
  77435. +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
  77436. {
  77437. - long x = atomic_long_read(&vm_stat[item]);
  77438. + long x = atomic_long_read_unchecked(&vm_stat[item]);
  77439. #ifdef CONFIG_SMP
  77440. if (x < 0)
  77441. x = 0;
  77442. @@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
  77443. return x;
  77444. }
  77445. -static inline unsigned long zone_page_state(struct zone *zone,
  77446. +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
  77447. enum zone_stat_item item)
  77448. {
  77449. - long x = atomic_long_read(&zone->vm_stat[item]);
  77450. + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
  77451. #ifdef CONFIG_SMP
  77452. if (x < 0)
  77453. x = 0;
  77454. @@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
  77455. static inline unsigned long zone_page_state_snapshot(struct zone *zone,
  77456. enum zone_stat_item item)
  77457. {
  77458. - long x = atomic_long_read(&zone->vm_stat[item]);
  77459. + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
  77460. #ifdef CONFIG_SMP
  77461. int cpu;
  77462. @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
  77463. static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
  77464. {
  77465. - atomic_long_inc(&zone->vm_stat[item]);
  77466. - atomic_long_inc(&vm_stat[item]);
  77467. + atomic_long_inc_unchecked(&zone->vm_stat[item]);
  77468. + atomic_long_inc_unchecked(&vm_stat[item]);
  77469. }
  77470. static inline void __inc_zone_page_state(struct page *page,
  77471. @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
  77472. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  77473. {
  77474. - atomic_long_dec(&zone->vm_stat[item]);
  77475. - atomic_long_dec(&vm_stat[item]);
  77476. + atomic_long_dec_unchecked(&zone->vm_stat[item]);
  77477. + atomic_long_dec_unchecked(&vm_stat[item]);
  77478. }
  77479. static inline void __dec_zone_page_state(struct page *page,
  77480. diff --git a/include/linux/xattr.h b/include/linux/xattr.h
  77481. index 91b0a68..0e9adf6 100644
  77482. --- a/include/linux/xattr.h
  77483. +++ b/include/linux/xattr.h
  77484. @@ -28,7 +28,7 @@ struct xattr_handler {
  77485. size_t size, int handler_flags);
  77486. int (*set)(struct dentry *dentry, const char *name, const void *buffer,
  77487. size_t size, int flags, int handler_flags);
  77488. -};
  77489. +} __do_const;
  77490. struct xattr {
  77491. const char *name;
  77492. @@ -37,6 +37,9 @@ struct xattr {
  77493. };
  77494. ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
  77495. +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
  77496. +ssize_t pax_getxattr(struct dentry *, void *, size_t);
  77497. +#endif
  77498. ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
  77499. ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
  77500. int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
  77501. diff --git a/include/linux/zlib.h b/include/linux/zlib.h
  77502. index 9c5a6b4..09c9438 100644
  77503. --- a/include/linux/zlib.h
  77504. +++ b/include/linux/zlib.h
  77505. @@ -31,6 +31,7 @@
  77506. #define _ZLIB_H
  77507. #include <linux/zconf.h>
  77508. +#include <linux/compiler.h>
  77509. /* zlib deflate based on ZLIB_VERSION "1.1.3" */
  77510. /* zlib inflate based on ZLIB_VERSION "1.2.3" */
  77511. @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
  77512. /* basic functions */
  77513. -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
  77514. +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
  77515. /*
  77516. Returns the number of bytes that needs to be allocated for a per-
  77517. stream workspace with the specified parameters. A pointer to this
  77518. diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
  77519. index c768c9f..bdcaa5a 100644
  77520. --- a/include/media/v4l2-dev.h
  77521. +++ b/include/media/v4l2-dev.h
  77522. @@ -76,7 +76,7 @@ struct v4l2_file_operations {
  77523. int (*mmap) (struct file *, struct vm_area_struct *);
  77524. int (*open) (struct file *);
  77525. int (*release) (struct file *);
  77526. -};
  77527. +} __do_const;
  77528. /*
  77529. * Newer version of video_device, handled by videodev2.c
  77530. diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
  77531. index c9b1593..a572459 100644
  77532. --- a/include/media/v4l2-device.h
  77533. +++ b/include/media/v4l2-device.h
  77534. @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
  77535. this function returns 0. If the name ends with a digit (e.g. cx18),
  77536. then the name will be set to cx18-0 since cx180 looks really odd. */
  77537. int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
  77538. - atomic_t *instance);
  77539. + atomic_unchecked_t *instance);
  77540. /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
  77541. Since the parent disappears this ensures that v4l2_dev doesn't have an
  77542. diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
  77543. index 9a36d92..0aafe2a 100644
  77544. --- a/include/net/9p/transport.h
  77545. +++ b/include/net/9p/transport.h
  77546. @@ -60,7 +60,7 @@ struct p9_trans_module {
  77547. int (*cancel) (struct p9_client *, struct p9_req_t *req);
  77548. int (*zc_request)(struct p9_client *, struct p9_req_t *,
  77549. char *, char *, int , int, int, int);
  77550. -};
  77551. +} __do_const;
  77552. void v9fs_register_trans(struct p9_trans_module *m);
  77553. void v9fs_unregister_trans(struct p9_trans_module *m);
  77554. diff --git a/include/net/af_unix.h b/include/net/af_unix.h
  77555. index a175ba4..196eb82 100644
  77556. --- a/include/net/af_unix.h
  77557. +++ b/include/net/af_unix.h
  77558. @@ -36,7 +36,7 @@ struct unix_skb_parms {
  77559. u32 secid; /* Security ID */
  77560. #endif
  77561. u32 consumed;
  77562. -};
  77563. +} __randomize_layout;
  77564. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  77565. #define UNIXSID(skb) (&UNIXCB((skb)).secid)
  77566. diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
  77567. index dbc4a89..4a59b5d 100644
  77568. --- a/include/net/bluetooth/l2cap.h
  77569. +++ b/include/net/bluetooth/l2cap.h
  77570. @@ -600,7 +600,7 @@ struct l2cap_ops {
  77571. long (*get_sndtimeo) (struct l2cap_chan *chan);
  77572. struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
  77573. unsigned long len, int nb);
  77574. -};
  77575. +} __do_const;
  77576. struct l2cap_conn {
  77577. struct hci_conn *hcon;
  77578. diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
  77579. index f2ae33d..c457cf0 100644
  77580. --- a/include/net/caif/cfctrl.h
  77581. +++ b/include/net/caif/cfctrl.h
  77582. @@ -52,7 +52,7 @@ struct cfctrl_rsp {
  77583. void (*radioset_rsp)(void);
  77584. void (*reject_rsp)(struct cflayer *layer, u8 linkid,
  77585. struct cflayer *client_layer);
  77586. -};
  77587. +} __no_const;
  77588. /* Link Setup Parameters for CAIF-Links. */
  77589. struct cfctrl_link_param {
  77590. @@ -101,8 +101,8 @@ struct cfctrl_request_info {
  77591. struct cfctrl {
  77592. struct cfsrvl serv;
  77593. struct cfctrl_rsp res;
  77594. - atomic_t req_seq_no;
  77595. - atomic_t rsp_seq_no;
  77596. + atomic_unchecked_t req_seq_no;
  77597. + atomic_unchecked_t rsp_seq_no;
  77598. struct list_head list;
  77599. /* Protects from simultaneous access to first_req list */
  77600. spinlock_t info_list_lock;
  77601. diff --git a/include/net/flow.h b/include/net/flow.h
  77602. index d23e7fa..e188307 100644
  77603. --- a/include/net/flow.h
  77604. +++ b/include/net/flow.h
  77605. @@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
  77606. void flow_cache_flush(void);
  77607. void flow_cache_flush_deferred(void);
  77608. -extern atomic_t flow_cache_genid;
  77609. +extern atomic_unchecked_t flow_cache_genid;
  77610. #endif
  77611. diff --git a/include/net/genetlink.h b/include/net/genetlink.h
  77612. index 93695f0..766d71c 100644
  77613. --- a/include/net/genetlink.h
  77614. +++ b/include/net/genetlink.h
  77615. @@ -120,7 +120,7 @@ struct genl_ops {
  77616. u8 cmd;
  77617. u8 internal_flags;
  77618. u8 flags;
  77619. -};
  77620. +} __do_const;
  77621. int __genl_register_family(struct genl_family *family);
  77622. diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
  77623. index 734d9b5..48a9a4b 100644
  77624. --- a/include/net/gro_cells.h
  77625. +++ b/include/net/gro_cells.h
  77626. @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
  77627. cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
  77628. if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
  77629. - atomic_long_inc(&dev->rx_dropped);
  77630. + atomic_long_inc_unchecked(&dev->rx_dropped);
  77631. kfree_skb(skb);
  77632. return;
  77633. }
  77634. diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
  77635. index c55aeed..b3393f4 100644
  77636. --- a/include/net/inet_connection_sock.h
  77637. +++ b/include/net/inet_connection_sock.h
  77638. @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
  77639. void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
  77640. int (*bind_conflict)(const struct sock *sk,
  77641. const struct inet_bind_bucket *tb, bool relax);
  77642. -};
  77643. +} __do_const;
  77644. /** inet_connection_sock - INET connection oriented sock
  77645. *
  77646. diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
  77647. index 6efe73c..fa94270 100644
  77648. --- a/include/net/inetpeer.h
  77649. +++ b/include/net/inetpeer.h
  77650. @@ -47,8 +47,8 @@ struct inet_peer {
  77651. */
  77652. union {
  77653. struct {
  77654. - atomic_t rid; /* Frag reception counter */
  77655. - atomic_t ip_id_count; /* IP ID for the next packet */
  77656. + atomic_unchecked_t rid; /* Frag reception counter */
  77657. + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
  77658. };
  77659. struct rcu_head rcu;
  77660. struct inet_peer *gc_next;
  77661. @@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
  77662. /* can be called with or without local BH being disabled */
  77663. static inline int inet_getid(struct inet_peer *p, int more)
  77664. {
  77665. - int old, new;
  77666. + int id;
  77667. more++;
  77668. inet_peer_refcheck(p);
  77669. - do {
  77670. - old = atomic_read(&p->ip_id_count);
  77671. - new = old + more;
  77672. - if (!new)
  77673. - new = 1;
  77674. - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
  77675. - return new;
  77676. + id = atomic_add_return_unchecked(more, &p->ip_id_count);
  77677. + if (!id)
  77678. + id = atomic_inc_return_unchecked(&p->ip_id_count);
  77679. + return id;
  77680. }
  77681. #endif /* _NET_INETPEER_H */
  77682. diff --git a/include/net/ip.h b/include/net/ip.h
  77683. index 23be0fd..0cb3e2c 100644
  77684. --- a/include/net/ip.h
  77685. +++ b/include/net/ip.h
  77686. @@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
  77687. void inet_get_local_port_range(struct net *net, int *low, int *high);
  77688. -extern unsigned long *sysctl_local_reserved_ports;
  77689. +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
  77690. static inline int inet_is_reserved_local_port(int port)
  77691. {
  77692. return test_bit(port, sysctl_local_reserved_ports);
  77693. diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
  77694. index 9922093..a1755d6 100644
  77695. --- a/include/net/ip_fib.h
  77696. +++ b/include/net/ip_fib.h
  77697. @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
  77698. #define FIB_RES_SADDR(net, res) \
  77699. ((FIB_RES_NH(res).nh_saddr_genid == \
  77700. - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
  77701. + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
  77702. FIB_RES_NH(res).nh_saddr : \
  77703. fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
  77704. #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
  77705. diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
  77706. index 5679d92..2e7a690 100644
  77707. --- a/include/net/ip_vs.h
  77708. +++ b/include/net/ip_vs.h
  77709. @@ -558,7 +558,7 @@ struct ip_vs_conn {
  77710. struct ip_vs_conn *control; /* Master control connection */
  77711. atomic_t n_control; /* Number of controlled ones */
  77712. struct ip_vs_dest *dest; /* real server */
  77713. - atomic_t in_pkts; /* incoming packet counter */
  77714. + atomic_unchecked_t in_pkts; /* incoming packet counter */
  77715. /* packet transmitter for different forwarding methods. If it
  77716. mangles the packet, it must return NF_DROP or better NF_STOLEN,
  77717. @@ -705,7 +705,7 @@ struct ip_vs_dest {
  77718. __be16 port; /* port number of the server */
  77719. union nf_inet_addr addr; /* IP address of the server */
  77720. volatile unsigned int flags; /* dest status flags */
  77721. - atomic_t conn_flags; /* flags to copy to conn */
  77722. + atomic_unchecked_t conn_flags; /* flags to copy to conn */
  77723. atomic_t weight; /* server weight */
  77724. atomic_t refcnt; /* reference counter */
  77725. @@ -960,11 +960,11 @@ struct netns_ipvs {
  77726. /* ip_vs_lblc */
  77727. int sysctl_lblc_expiration;
  77728. struct ctl_table_header *lblc_ctl_header;
  77729. - struct ctl_table *lblc_ctl_table;
  77730. + ctl_table_no_const *lblc_ctl_table;
  77731. /* ip_vs_lblcr */
  77732. int sysctl_lblcr_expiration;
  77733. struct ctl_table_header *lblcr_ctl_header;
  77734. - struct ctl_table *lblcr_ctl_table;
  77735. + ctl_table_no_const *lblcr_ctl_table;
  77736. /* ip_vs_est */
  77737. struct list_head est_list; /* estimator list */
  77738. spinlock_t est_lock;
  77739. diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
  77740. index 8d4f588..2e37ad2 100644
  77741. --- a/include/net/irda/ircomm_tty.h
  77742. +++ b/include/net/irda/ircomm_tty.h
  77743. @@ -33,6 +33,7 @@
  77744. #include <linux/termios.h>
  77745. #include <linux/timer.h>
  77746. #include <linux/tty.h> /* struct tty_struct */
  77747. +#include <asm/local.h>
  77748. #include <net/irda/irias_object.h>
  77749. #include <net/irda/ircomm_core.h>
  77750. diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
  77751. index 714cc9a..ea05f3e 100644
  77752. --- a/include/net/iucv/af_iucv.h
  77753. +++ b/include/net/iucv/af_iucv.h
  77754. @@ -149,7 +149,7 @@ struct iucv_skb_cb {
  77755. struct iucv_sock_list {
  77756. struct hlist_head head;
  77757. rwlock_t lock;
  77758. - atomic_t autobind_name;
  77759. + atomic_unchecked_t autobind_name;
  77760. };
  77761. unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
  77762. diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
  77763. index f3be818..bf46196 100644
  77764. --- a/include/net/llc_c_ac.h
  77765. +++ b/include/net/llc_c_ac.h
  77766. @@ -87,7 +87,7 @@
  77767. #define LLC_CONN_AC_STOP_SENDACK_TMR 70
  77768. #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
  77769. -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
  77770. +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
  77771. int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
  77772. int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
  77773. diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
  77774. index 3948cf1..83b28c4 100644
  77775. --- a/include/net/llc_c_ev.h
  77776. +++ b/include/net/llc_c_ev.h
  77777. @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
  77778. return (struct llc_conn_state_ev *)skb->cb;
  77779. }
  77780. -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
  77781. -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
  77782. +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
  77783. +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
  77784. int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
  77785. int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
  77786. diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
  77787. index 0e79cfb..f46db31 100644
  77788. --- a/include/net/llc_c_st.h
  77789. +++ b/include/net/llc_c_st.h
  77790. @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
  77791. u8 next_state;
  77792. llc_conn_ev_qfyr_t *ev_qualifiers;
  77793. llc_conn_action_t *ev_actions;
  77794. -};
  77795. +} __do_const;
  77796. struct llc_conn_state {
  77797. u8 current_state;
  77798. diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
  77799. index a61b98c..aade1eb 100644
  77800. --- a/include/net/llc_s_ac.h
  77801. +++ b/include/net/llc_s_ac.h
  77802. @@ -23,7 +23,7 @@
  77803. #define SAP_ACT_TEST_IND 9
  77804. /* All action functions must look like this */
  77805. -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
  77806. +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
  77807. int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
  77808. int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
  77809. diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
  77810. index 567c681..cd73ac0 100644
  77811. --- a/include/net/llc_s_st.h
  77812. +++ b/include/net/llc_s_st.h
  77813. @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
  77814. llc_sap_ev_t ev;
  77815. u8 next_state;
  77816. llc_sap_action_t *ev_actions;
  77817. -};
  77818. +} __do_const;
  77819. struct llc_sap_state {
  77820. u8 curr_state;
  77821. diff --git a/include/net/mac80211.h b/include/net/mac80211.h
  77822. index f4ab2fb..71a85ba 100644
  77823. --- a/include/net/mac80211.h
  77824. +++ b/include/net/mac80211.h
  77825. @@ -4476,7 +4476,7 @@ struct rate_control_ops {
  77826. void (*add_sta_debugfs)(void *priv, void *priv_sta,
  77827. struct dentry *dir);
  77828. void (*remove_sta_debugfs)(void *priv, void *priv_sta);
  77829. -};
  77830. +} __do_const;
  77831. static inline int rate_supported(struct ieee80211_sta *sta,
  77832. enum ieee80211_band band,
  77833. diff --git a/include/net/neighbour.h b/include/net/neighbour.h
  77834. index 7277caf..fd095bc 100644
  77835. --- a/include/net/neighbour.h
  77836. +++ b/include/net/neighbour.h
  77837. @@ -163,7 +163,7 @@ struct neigh_ops {
  77838. void (*error_report)(struct neighbour *, struct sk_buff *);
  77839. int (*output)(struct neighbour *, struct sk_buff *);
  77840. int (*connected_output)(struct neighbour *, struct sk_buff *);
  77841. -};
  77842. +} __do_const;
  77843. struct pneigh_entry {
  77844. struct pneigh_entry *next;
  77845. @@ -203,7 +203,6 @@ struct neigh_table {
  77846. void (*proxy_redo)(struct sk_buff *skb);
  77847. char *id;
  77848. struct neigh_parms parms;
  77849. - /* HACK. gc_* should follow parms without a gap! */
  77850. int gc_interval;
  77851. int gc_thresh1;
  77852. int gc_thresh2;
  77853. @@ -218,7 +217,7 @@ struct neigh_table {
  77854. struct neigh_statistics __percpu *stats;
  77855. struct neigh_hash_table __rcu *nht;
  77856. struct pneigh_entry **phash_buckets;
  77857. -};
  77858. +} __randomize_layout;
  77859. static inline int neigh_parms_family(struct neigh_parms *p)
  77860. {
  77861. diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
  77862. index 991dcd9..ab58d00 100644
  77863. --- a/include/net/net_namespace.h
  77864. +++ b/include/net/net_namespace.h
  77865. @@ -124,8 +124,8 @@ struct net {
  77866. struct netns_ipvs *ipvs;
  77867. #endif
  77868. struct sock *diag_nlsk;
  77869. - atomic_t fnhe_genid;
  77870. -};
  77871. + atomic_unchecked_t fnhe_genid;
  77872. +} __randomize_layout;
  77873. /*
  77874. * ifindex generation is per-net namespace, and loopback is
  77875. @@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
  77876. #define __net_init __init
  77877. #define __net_exit __exit_refok
  77878. #define __net_initdata __initdata
  77879. +#ifdef CONSTIFY_PLUGIN
  77880. #define __net_initconst __initconst
  77881. +#else
  77882. +#define __net_initconst __initdata
  77883. +#endif
  77884. #endif
  77885. struct pernet_operations {
  77886. @@ -299,7 +303,7 @@ struct pernet_operations {
  77887. void (*exit_batch)(struct list_head *net_exit_list);
  77888. int *id;
  77889. size_t size;
  77890. -};
  77891. +} __do_const;
  77892. /*
  77893. * Use these carefully. If you implement a network device and it
  77894. @@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
  77895. static inline int rt_genid_ipv4(struct net *net)
  77896. {
  77897. - return atomic_read(&net->ipv4.rt_genid);
  77898. + return atomic_read_unchecked(&net->ipv4.rt_genid);
  77899. }
  77900. static inline void rt_genid_bump_ipv4(struct net *net)
  77901. {
  77902. - atomic_inc(&net->ipv4.rt_genid);
  77903. + atomic_inc_unchecked(&net->ipv4.rt_genid);
  77904. }
  77905. #if IS_ENABLED(CONFIG_IPV6)
  77906. static inline int rt_genid_ipv6(struct net *net)
  77907. {
  77908. - return atomic_read(&net->ipv6.rt_genid);
  77909. + return atomic_read_unchecked(&net->ipv6.rt_genid);
  77910. }
  77911. static inline void rt_genid_bump_ipv6(struct net *net)
  77912. {
  77913. - atomic_inc(&net->ipv6.rt_genid);
  77914. + atomic_inc_unchecked(&net->ipv6.rt_genid);
  77915. }
  77916. #else
  77917. static inline int rt_genid_ipv6(struct net *net)
  77918. @@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
  77919. static inline int fnhe_genid(struct net *net)
  77920. {
  77921. - return atomic_read(&net->fnhe_genid);
  77922. + return atomic_read_unchecked(&net->fnhe_genid);
  77923. }
  77924. static inline void fnhe_genid_bump(struct net *net)
  77925. {
  77926. - atomic_inc(&net->fnhe_genid);
  77927. + atomic_inc_unchecked(&net->fnhe_genid);
  77928. }
  77929. #endif /* __NET_NET_NAMESPACE_H */
  77930. diff --git a/include/net/netdma.h b/include/net/netdma.h
  77931. index 8ba8ce2..99b7fff 100644
  77932. --- a/include/net/netdma.h
  77933. +++ b/include/net/netdma.h
  77934. @@ -24,7 +24,7 @@
  77935. #include <linux/dmaengine.h>
  77936. #include <linux/skbuff.h>
  77937. -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
  77938. +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
  77939. struct sk_buff *skb, int offset, struct iovec *to,
  77940. size_t len, struct dma_pinned_list *pinned_list);
  77941. diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
  77942. index 956b175..55d1504 100644
  77943. --- a/include/net/netfilter/nf_conntrack_extend.h
  77944. +++ b/include/net/netfilter/nf_conntrack_extend.h
  77945. @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
  77946. /* Extensions: optional stuff which isn't permanently in struct. */
  77947. struct nf_ct_ext {
  77948. struct rcu_head rcu;
  77949. - u8 offset[NF_CT_EXT_NUM];
  77950. - u8 len;
  77951. + u16 offset[NF_CT_EXT_NUM];
  77952. + u16 len;
  77953. char data[0];
  77954. };
  77955. diff --git a/include/net/netlink.h b/include/net/netlink.h
  77956. index 2b47eaa..6d5bcc2 100644
  77957. --- a/include/net/netlink.h
  77958. +++ b/include/net/netlink.h
  77959. @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
  77960. static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
  77961. {
  77962. if (mark)
  77963. - skb_trim(skb, (unsigned char *) mark - skb->data);
  77964. + skb_trim(skb, (const unsigned char *) mark - skb->data);
  77965. }
  77966. /**
  77967. diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
  77968. index fbcc7fa..03c7e51 100644
  77969. --- a/include/net/netns/conntrack.h
  77970. +++ b/include/net/netns/conntrack.h
  77971. @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
  77972. struct nf_proto_net {
  77973. #ifdef CONFIG_SYSCTL
  77974. struct ctl_table_header *ctl_table_header;
  77975. - struct ctl_table *ctl_table;
  77976. + ctl_table_no_const *ctl_table;
  77977. #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
  77978. struct ctl_table_header *ctl_compat_header;
  77979. - struct ctl_table *ctl_compat_table;
  77980. + ctl_table_no_const *ctl_compat_table;
  77981. #endif
  77982. #endif
  77983. unsigned int users;
  77984. @@ -58,7 +58,7 @@ struct nf_ip_net {
  77985. struct nf_icmp_net icmpv6;
  77986. #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
  77987. struct ctl_table_header *ctl_table_header;
  77988. - struct ctl_table *ctl_table;
  77989. + ctl_table_no_const *ctl_table;
  77990. #endif
  77991. };
  77992. diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
  77993. index 80f500a..f0c23c2 100644
  77994. --- a/include/net/netns/ipv4.h
  77995. +++ b/include/net/netns/ipv4.h
  77996. @@ -74,7 +74,7 @@ struct netns_ipv4 {
  77997. kgid_t sysctl_ping_group_range[2];
  77998. - atomic_t dev_addr_genid;
  77999. + atomic_unchecked_t dev_addr_genid;
  78000. #ifdef CONFIG_IP_MROUTE
  78001. #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
  78002. @@ -84,6 +84,6 @@ struct netns_ipv4 {
  78003. struct fib_rules_ops *mr_rules_ops;
  78004. #endif
  78005. #endif
  78006. - atomic_t rt_genid;
  78007. + atomic_unchecked_t rt_genid;
  78008. };
  78009. #endif
  78010. diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
  78011. index 21edaf1..4c5faae 100644
  78012. --- a/include/net/netns/ipv6.h
  78013. +++ b/include/net/netns/ipv6.h
  78014. @@ -73,8 +73,8 @@ struct netns_ipv6 {
  78015. struct fib_rules_ops *mr6_rules_ops;
  78016. #endif
  78017. #endif
  78018. - atomic_t dev_addr_genid;
  78019. - atomic_t rt_genid;
  78020. + atomic_unchecked_t dev_addr_genid;
  78021. + atomic_unchecked_t rt_genid;
  78022. };
  78023. #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
  78024. diff --git a/include/net/ping.h b/include/net/ping.h
  78025. index 026479b..d9b2829 100644
  78026. --- a/include/net/ping.h
  78027. +++ b/include/net/ping.h
  78028. @@ -54,7 +54,7 @@ struct ping_iter_state {
  78029. extern struct proto ping_prot;
  78030. #if IS_ENABLED(CONFIG_IPV6)
  78031. -extern struct pingv6_ops pingv6_ops;
  78032. +extern struct pingv6_ops *pingv6_ops;
  78033. #endif
  78034. struct pingfakehdr {
  78035. diff --git a/include/net/protocol.h b/include/net/protocol.h
  78036. index a7e986b..dc67bce 100644
  78037. --- a/include/net/protocol.h
  78038. +++ b/include/net/protocol.h
  78039. @@ -49,7 +49,7 @@ struct net_protocol {
  78040. * socket lookup?
  78041. */
  78042. icmp_strict_tag_validation:1;
  78043. -};
  78044. +} __do_const;
  78045. #if IS_ENABLED(CONFIG_IPV6)
  78046. struct inet6_protocol {
  78047. @@ -62,7 +62,7 @@ struct inet6_protocol {
  78048. u8 type, u8 code, int offset,
  78049. __be32 info);
  78050. unsigned int flags; /* INET6_PROTO_xxx */
  78051. -};
  78052. +} __do_const;
  78053. #define INET6_PROTO_NOPOLICY 0x1
  78054. #define INET6_PROTO_FINAL 0x2
  78055. diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
  78056. index 661e45d..54c39df 100644
  78057. --- a/include/net/rtnetlink.h
  78058. +++ b/include/net/rtnetlink.h
  78059. @@ -93,7 +93,7 @@ struct rtnl_link_ops {
  78060. int (*fill_slave_info)(struct sk_buff *skb,
  78061. const struct net_device *dev,
  78062. const struct net_device *slave_dev);
  78063. -};
  78064. +} __do_const;
  78065. int __rtnl_link_register(struct rtnl_link_ops *ops);
  78066. void __rtnl_link_unregister(struct rtnl_link_ops *ops);
  78067. diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
  78068. index 4a5b9a3..ca27d73 100644
  78069. --- a/include/net/sctp/checksum.h
  78070. +++ b/include/net/sctp/checksum.h
  78071. @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
  78072. unsigned int offset)
  78073. {
  78074. struct sctphdr *sh = sctp_hdr(skb);
  78075. - __le32 ret, old = sh->checksum;
  78076. - const struct skb_checksum_ops ops = {
  78077. + __le32 ret, old = sh->checksum;
  78078. + static const struct skb_checksum_ops ops = {
  78079. .update = sctp_csum_update,
  78080. .combine = sctp_csum_combine,
  78081. };
  78082. diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
  78083. index 7f4eeb3..37e8fe1 100644
  78084. --- a/include/net/sctp/sm.h
  78085. +++ b/include/net/sctp/sm.h
  78086. @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
  78087. typedef struct {
  78088. sctp_state_fn_t *fn;
  78089. const char *name;
  78090. -} sctp_sm_table_entry_t;
  78091. +} __do_const sctp_sm_table_entry_t;
  78092. /* A naming convention of "sctp_sf_xxx" applies to all the state functions
  78093. * currently in use.
  78094. @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
  78095. __u32 sctp_generate_tsn(const struct sctp_endpoint *);
  78096. /* Extern declarations for major data structures. */
  78097. -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
  78098. +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
  78099. /* Get the size of a DATA chunk payload. */
  78100. diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
  78101. index 6ee76c8..45f2609 100644
  78102. --- a/include/net/sctp/structs.h
  78103. +++ b/include/net/sctp/structs.h
  78104. @@ -507,7 +507,7 @@ struct sctp_pf {
  78105. struct sctp_association *asoc);
  78106. void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
  78107. struct sctp_af *af;
  78108. -};
  78109. +} __do_const;
  78110. /* Structure to track chunk fragments that have been acked, but peer
  78111. diff --git a/include/net/sock.h b/include/net/sock.h
  78112. index b9586a1..b2948c0 100644
  78113. --- a/include/net/sock.h
  78114. +++ b/include/net/sock.h
  78115. @@ -348,7 +348,7 @@ struct sock {
  78116. unsigned int sk_napi_id;
  78117. unsigned int sk_ll_usec;
  78118. #endif
  78119. - atomic_t sk_drops;
  78120. + atomic_unchecked_t sk_drops;
  78121. int sk_rcvbuf;
  78122. struct sk_filter __rcu *sk_filter;
  78123. @@ -1036,7 +1036,7 @@ struct proto {
  78124. void (*destroy_cgroup)(struct mem_cgroup *memcg);
  78125. struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
  78126. #endif
  78127. -};
  78128. +} __randomize_layout;
  78129. /*
  78130. * Bits in struct cg_proto.flags
  78131. @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
  78132. return ret >> PAGE_SHIFT;
  78133. }
  78134. -static inline long
  78135. +static inline long __intentional_overflow(-1)
  78136. sk_memory_allocated(const struct sock *sk)
  78137. {
  78138. struct proto *prot = sk->sk_prot;
  78139. @@ -1368,7 +1368,7 @@ struct sock_iocb {
  78140. struct scm_cookie *scm;
  78141. struct msghdr *msg, async_msg;
  78142. struct kiocb *kiocb;
  78143. -};
  78144. +} __randomize_layout;
  78145. static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
  78146. {
  78147. @@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
  78148. }
  78149. static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
  78150. - char __user *from, char *to,
  78151. + char __user *from, unsigned char *to,
  78152. int copy, int offset)
  78153. {
  78154. if (skb->ip_summed == CHECKSUM_NONE) {
  78155. @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
  78156. }
  78157. }
  78158. -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
  78159. +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
  78160. /**
  78161. * sk_page_frag - return an appropriate page_frag
  78162. diff --git a/include/net/tcp.h b/include/net/tcp.h
  78163. index 743acce..44a58b0 100644
  78164. --- a/include/net/tcp.h
  78165. +++ b/include/net/tcp.h
  78166. @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
  78167. void tcp_xmit_retransmit_queue(struct sock *);
  78168. void tcp_simple_retransmit(struct sock *);
  78169. int tcp_trim_head(struct sock *, struct sk_buff *, u32);
  78170. -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
  78171. +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
  78172. void tcp_send_probe0(struct sock *);
  78173. void tcp_send_partial(struct sock *);
  78174. @@ -710,8 +710,8 @@ struct tcp_skb_cb {
  78175. struct inet6_skb_parm h6;
  78176. #endif
  78177. } header; /* For incoming frames */
  78178. - __u32 seq; /* Starting sequence number */
  78179. - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
  78180. + __u32 seq __intentional_overflow(0); /* Starting sequence number */
  78181. + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
  78182. __u32 when; /* used to compute rtt's */
  78183. __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
  78184. @@ -725,7 +725,7 @@ struct tcp_skb_cb {
  78185. __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
  78186. /* 1 byte hole */
  78187. - __u32 ack_seq; /* Sequence number ACK'd */
  78188. + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
  78189. };
  78190. #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
  78191. diff --git a/include/net/xfrm.h b/include/net/xfrm.h
  78192. index fb5654a..4457522 100644
  78193. --- a/include/net/xfrm.h
  78194. +++ b/include/net/xfrm.h
  78195. @@ -286,7 +286,6 @@ struct xfrm_dst;
  78196. struct xfrm_policy_afinfo {
  78197. unsigned short family;
  78198. struct dst_ops *dst_ops;
  78199. - void (*garbage_collect)(struct net *net);
  78200. struct dst_entry *(*dst_lookup)(struct net *net, int tos,
  78201. const xfrm_address_t *saddr,
  78202. const xfrm_address_t *daddr);
  78203. @@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
  78204. struct net_device *dev,
  78205. const struct flowi *fl);
  78206. struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
  78207. -};
  78208. +} __do_const;
  78209. int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
  78210. int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
  78211. @@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
  78212. int (*transport_finish)(struct sk_buff *skb,
  78213. int async);
  78214. void (*local_error)(struct sk_buff *skb, u32 mtu);
  78215. -};
  78216. +} __do_const;
  78217. int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
  78218. int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
  78219. @@ -428,7 +427,7 @@ struct xfrm_mode {
  78220. struct module *owner;
  78221. unsigned int encap;
  78222. int flags;
  78223. -};
  78224. +} __do_const;
  78225. /* Flags for xfrm_mode. */
  78226. enum {
  78227. @@ -525,7 +524,7 @@ struct xfrm_policy {
  78228. struct timer_list timer;
  78229. struct flow_cache_object flo;
  78230. - atomic_t genid;
  78231. + atomic_unchecked_t genid;
  78232. u32 priority;
  78233. u32 index;
  78234. struct xfrm_mark mark;
  78235. @@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
  78236. }
  78237. void xfrm_garbage_collect(struct net *net);
  78238. +void xfrm_garbage_collect_deferred(struct net *net);
  78239. #else
  78240. @@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
  78241. static inline void xfrm_garbage_collect(struct net *net)
  78242. {
  78243. }
  78244. +static inline void xfrm_garbage_collect_deferred(struct net *net)
  78245. +{
  78246. +}
  78247. #endif
  78248. static __inline__
  78249. diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
  78250. index 1017e0b..227aa4d 100644
  78251. --- a/include/rdma/iw_cm.h
  78252. +++ b/include/rdma/iw_cm.h
  78253. @@ -122,7 +122,7 @@ struct iw_cm_verbs {
  78254. int backlog);
  78255. int (*destroy_listen)(struct iw_cm_id *cm_id);
  78256. -};
  78257. +} __no_const;
  78258. /**
  78259. * iw_create_cm_id - Create an IW CM identifier.
  78260. diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
  78261. index 52beadf..598734c 100644
  78262. --- a/include/scsi/libfc.h
  78263. +++ b/include/scsi/libfc.h
  78264. @@ -771,6 +771,7 @@ struct libfc_function_template {
  78265. */
  78266. void (*disc_stop_final) (struct fc_lport *);
  78267. };
  78268. +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
  78269. /**
  78270. * struct fc_disc - Discovery context
  78271. @@ -875,7 +876,7 @@ struct fc_lport {
  78272. struct fc_vport *vport;
  78273. /* Operational Information */
  78274. - struct libfc_function_template tt;
  78275. + libfc_function_template_no_const tt;
  78276. u8 link_up;
  78277. u8 qfull;
  78278. enum fc_lport_state state;
  78279. diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
  78280. index d65fbec..f80fef2 100644
  78281. --- a/include/scsi/scsi_device.h
  78282. +++ b/include/scsi/scsi_device.h
  78283. @@ -180,9 +180,9 @@ struct scsi_device {
  78284. unsigned int max_device_blocked; /* what device_blocked counts down from */
  78285. #define SCSI_DEFAULT_DEVICE_BLOCKED 3
  78286. - atomic_t iorequest_cnt;
  78287. - atomic_t iodone_cnt;
  78288. - atomic_t ioerr_cnt;
  78289. + atomic_unchecked_t iorequest_cnt;
  78290. + atomic_unchecked_t iodone_cnt;
  78291. + atomic_unchecked_t ioerr_cnt;
  78292. struct device sdev_gendev,
  78293. sdev_dev;
  78294. diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
  78295. index b797e8f..8e2c3aa 100644
  78296. --- a/include/scsi/scsi_transport_fc.h
  78297. +++ b/include/scsi/scsi_transport_fc.h
  78298. @@ -751,7 +751,8 @@ struct fc_function_template {
  78299. unsigned long show_host_system_hostname:1;
  78300. unsigned long disable_target_scan:1;
  78301. -};
  78302. +} __do_const;
  78303. +typedef struct fc_function_template __no_const fc_function_template_no_const;
  78304. /**
  78305. diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
  78306. index ae6c3b8..fd748ac 100644
  78307. --- a/include/sound/compress_driver.h
  78308. +++ b/include/sound/compress_driver.h
  78309. @@ -128,7 +128,7 @@ struct snd_compr_ops {
  78310. struct snd_compr_caps *caps);
  78311. int (*get_codec_caps) (struct snd_compr_stream *stream,
  78312. struct snd_compr_codec_caps *codec);
  78313. -};
  78314. +} __no_const;
  78315. /**
  78316. * struct snd_compr: Compressed device
  78317. diff --git a/include/sound/soc.h b/include/sound/soc.h
  78318. index 9a00147..d814573 100644
  78319. --- a/include/sound/soc.h
  78320. +++ b/include/sound/soc.h
  78321. @@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
  78322. /* probe ordering - for components with runtime dependencies */
  78323. int probe_order;
  78324. int remove_order;
  78325. -};
  78326. +} __do_const;
  78327. /* SoC platform interface */
  78328. struct snd_soc_platform_driver {
  78329. @@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
  78330. unsigned int (*read)(struct snd_soc_platform *, unsigned int);
  78331. int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
  78332. int (*bespoke_trigger)(struct snd_pcm_substream *, int);
  78333. -};
  78334. +} __do_const;
  78335. struct snd_soc_platform {
  78336. const char *name;
  78337. diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
  78338. index 1772fad..282e3e2 100644
  78339. --- a/include/target/target_core_base.h
  78340. +++ b/include/target/target_core_base.h
  78341. @@ -754,7 +754,7 @@ struct se_device {
  78342. atomic_long_t write_bytes;
  78343. /* Active commands on this virtual SE device */
  78344. atomic_t simple_cmds;
  78345. - atomic_t dev_ordered_id;
  78346. + atomic_unchecked_t dev_ordered_id;
  78347. atomic_t dev_ordered_sync;
  78348. atomic_t dev_qf_count;
  78349. int export_count;
  78350. diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
  78351. new file mode 100644
  78352. index 0000000..fb634b7
  78353. --- /dev/null
  78354. +++ b/include/trace/events/fs.h
  78355. @@ -0,0 +1,53 @@
  78356. +#undef TRACE_SYSTEM
  78357. +#define TRACE_SYSTEM fs
  78358. +
  78359. +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
  78360. +#define _TRACE_FS_H
  78361. +
  78362. +#include <linux/fs.h>
  78363. +#include <linux/tracepoint.h>
  78364. +
  78365. +TRACE_EVENT(do_sys_open,
  78366. +
  78367. + TP_PROTO(const char *filename, int flags, int mode),
  78368. +
  78369. + TP_ARGS(filename, flags, mode),
  78370. +
  78371. + TP_STRUCT__entry(
  78372. + __string( filename, filename )
  78373. + __field( int, flags )
  78374. + __field( int, mode )
  78375. + ),
  78376. +
  78377. + TP_fast_assign(
  78378. + __assign_str(filename, filename);
  78379. + __entry->flags = flags;
  78380. + __entry->mode = mode;
  78381. + ),
  78382. +
  78383. + TP_printk("\"%s\" %x %o",
  78384. + __get_str(filename), __entry->flags, __entry->mode)
  78385. +);
  78386. +
  78387. +TRACE_EVENT(open_exec,
  78388. +
  78389. + TP_PROTO(const char *filename),
  78390. +
  78391. + TP_ARGS(filename),
  78392. +
  78393. + TP_STRUCT__entry(
  78394. + __string( filename, filename )
  78395. + ),
  78396. +
  78397. + TP_fast_assign(
  78398. + __assign_str(filename, filename);
  78399. + ),
  78400. +
  78401. + TP_printk("\"%s\"",
  78402. + __get_str(filename))
  78403. +);
  78404. +
  78405. +#endif /* _TRACE_FS_H */
  78406. +
  78407. +/* This part must be outside protection */
  78408. +#include <trace/define_trace.h>
  78409. diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
  78410. index 1c09820..7f5ec79 100644
  78411. --- a/include/trace/events/irq.h
  78412. +++ b/include/trace/events/irq.h
  78413. @@ -36,7 +36,7 @@ struct softirq_action;
  78414. */
  78415. TRACE_EVENT(irq_handler_entry,
  78416. - TP_PROTO(int irq, struct irqaction *action),
  78417. + TP_PROTO(int irq, const struct irqaction *action),
  78418. TP_ARGS(irq, action),
  78419. @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
  78420. */
  78421. TRACE_EVENT(irq_handler_exit,
  78422. - TP_PROTO(int irq, struct irqaction *action, int ret),
  78423. + TP_PROTO(int irq, const struct irqaction *action, int ret),
  78424. TP_ARGS(irq, action, ret),
  78425. diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
  78426. index 7caf44c..23c6f27 100644
  78427. --- a/include/uapi/linux/a.out.h
  78428. +++ b/include/uapi/linux/a.out.h
  78429. @@ -39,6 +39,14 @@ enum machine_type {
  78430. M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
  78431. };
  78432. +/* Constants for the N_FLAGS field */
  78433. +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
  78434. +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
  78435. +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
  78436. +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
  78437. +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
  78438. +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
  78439. +
  78440. #if !defined (N_MAGIC)
  78441. #define N_MAGIC(exec) ((exec).a_info & 0xffff)
  78442. #endif
  78443. diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
  78444. index 22b6ad3..aeba37e 100644
  78445. --- a/include/uapi/linux/bcache.h
  78446. +++ b/include/uapi/linux/bcache.h
  78447. @@ -5,6 +5,7 @@
  78448. * Bcache on disk data structures
  78449. */
  78450. +#include <linux/compiler.h>
  78451. #include <asm/types.h>
  78452. #define BITMASK(name, type, field, offset, size) \
  78453. @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
  78454. /* Btree keys - all units are in sectors */
  78455. struct bkey {
  78456. - __u64 high;
  78457. - __u64 low;
  78458. + __u64 high __intentional_overflow(-1);
  78459. + __u64 low __intentional_overflow(-1);
  78460. __u64 ptr[];
  78461. };
  78462. diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
  78463. index d876736..ccce5c0 100644
  78464. --- a/include/uapi/linux/byteorder/little_endian.h
  78465. +++ b/include/uapi/linux/byteorder/little_endian.h
  78466. @@ -42,51 +42,51 @@
  78467. static inline __le64 __cpu_to_le64p(const __u64 *p)
  78468. {
  78469. - return (__force __le64)*p;
  78470. + return (__force const __le64)*p;
  78471. }
  78472. -static inline __u64 __le64_to_cpup(const __le64 *p)
  78473. +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
  78474. {
  78475. - return (__force __u64)*p;
  78476. + return (__force const __u64)*p;
  78477. }
  78478. static inline __le32 __cpu_to_le32p(const __u32 *p)
  78479. {
  78480. - return (__force __le32)*p;
  78481. + return (__force const __le32)*p;
  78482. }
  78483. static inline __u32 __le32_to_cpup(const __le32 *p)
  78484. {
  78485. - return (__force __u32)*p;
  78486. + return (__force const __u32)*p;
  78487. }
  78488. static inline __le16 __cpu_to_le16p(const __u16 *p)
  78489. {
  78490. - return (__force __le16)*p;
  78491. + return (__force const __le16)*p;
  78492. }
  78493. static inline __u16 __le16_to_cpup(const __le16 *p)
  78494. {
  78495. - return (__force __u16)*p;
  78496. + return (__force const __u16)*p;
  78497. }
  78498. static inline __be64 __cpu_to_be64p(const __u64 *p)
  78499. {
  78500. - return (__force __be64)__swab64p(p);
  78501. + return (__force const __be64)__swab64p(p);
  78502. }
  78503. static inline __u64 __be64_to_cpup(const __be64 *p)
  78504. {
  78505. - return __swab64p((__u64 *)p);
  78506. + return __swab64p((const __u64 *)p);
  78507. }
  78508. static inline __be32 __cpu_to_be32p(const __u32 *p)
  78509. {
  78510. - return (__force __be32)__swab32p(p);
  78511. + return (__force const __be32)__swab32p(p);
  78512. }
  78513. -static inline __u32 __be32_to_cpup(const __be32 *p)
  78514. +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
  78515. {
  78516. - return __swab32p((__u32 *)p);
  78517. + return __swab32p((const __u32 *)p);
  78518. }
  78519. static inline __be16 __cpu_to_be16p(const __u16 *p)
  78520. {
  78521. - return (__force __be16)__swab16p(p);
  78522. + return (__force const __be16)__swab16p(p);
  78523. }
  78524. static inline __u16 __be16_to_cpup(const __be16 *p)
  78525. {
  78526. - return __swab16p((__u16 *)p);
  78527. + return __swab16p((const __u16 *)p);
  78528. }
  78529. #define __cpu_to_le64s(x) do { (void)(x); } while (0)
  78530. #define __le64_to_cpus(x) do { (void)(x); } while (0)
  78531. diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
  78532. index ef6103b..d4e65dd 100644
  78533. --- a/include/uapi/linux/elf.h
  78534. +++ b/include/uapi/linux/elf.h
  78535. @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
  78536. #define PT_GNU_EH_FRAME 0x6474e550
  78537. #define PT_GNU_STACK (PT_LOOS + 0x474e551)
  78538. +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
  78539. +
  78540. +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
  78541. +
  78542. +/* Constants for the e_flags field */
  78543. +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
  78544. +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
  78545. +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
  78546. +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
  78547. +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
  78548. +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
  78549. /*
  78550. * Extended Numbering
  78551. @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
  78552. #define DT_DEBUG 21
  78553. #define DT_TEXTREL 22
  78554. #define DT_JMPREL 23
  78555. +#define DT_FLAGS 30
  78556. + #define DF_TEXTREL 0x00000004
  78557. #define DT_ENCODING 32
  78558. #define OLD_DT_LOOS 0x60000000
  78559. #define DT_LOOS 0x6000000d
  78560. @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
  78561. #define PF_W 0x2
  78562. #define PF_X 0x1
  78563. +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
  78564. +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
  78565. +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
  78566. +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
  78567. +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
  78568. +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
  78569. +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
  78570. +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
  78571. +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
  78572. +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
  78573. +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
  78574. +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
  78575. +
  78576. typedef struct elf32_phdr{
  78577. Elf32_Word p_type;
  78578. Elf32_Off p_offset;
  78579. @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
  78580. #define EI_OSABI 7
  78581. #define EI_PAD 8
  78582. +#define EI_PAX 14
  78583. +
  78584. #define ELFMAG0 0x7f /* EI_MAG */
  78585. #define ELFMAG1 'E'
  78586. #define ELFMAG2 'L'
  78587. diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
  78588. index aa169c4..6a2771d 100644
  78589. --- a/include/uapi/linux/personality.h
  78590. +++ b/include/uapi/linux/personality.h
  78591. @@ -30,6 +30,7 @@ enum {
  78592. #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
  78593. ADDR_NO_RANDOMIZE | \
  78594. ADDR_COMPAT_LAYOUT | \
  78595. + ADDR_LIMIT_3GB | \
  78596. MMAP_PAGE_ZERO)
  78597. /*
  78598. diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
  78599. index 7530e74..e714828 100644
  78600. --- a/include/uapi/linux/screen_info.h
  78601. +++ b/include/uapi/linux/screen_info.h
  78602. @@ -43,7 +43,8 @@ struct screen_info {
  78603. __u16 pages; /* 0x32 */
  78604. __u16 vesa_attributes; /* 0x34 */
  78605. __u32 capabilities; /* 0x36 */
  78606. - __u8 _reserved[6]; /* 0x3a */
  78607. + __u16 vesapm_size; /* 0x3a */
  78608. + __u8 _reserved[4]; /* 0x3c */
  78609. } __attribute__((packed));
  78610. #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
  78611. diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
  78612. index 0e011eb..82681b1 100644
  78613. --- a/include/uapi/linux/swab.h
  78614. +++ b/include/uapi/linux/swab.h
  78615. @@ -43,7 +43,7 @@
  78616. * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
  78617. */
  78618. -static inline __attribute_const__ __u16 __fswab16(__u16 val)
  78619. +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
  78620. {
  78621. #ifdef __HAVE_BUILTIN_BSWAP16__
  78622. return __builtin_bswap16(val);
  78623. @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
  78624. #endif
  78625. }
  78626. -static inline __attribute_const__ __u32 __fswab32(__u32 val)
  78627. +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
  78628. {
  78629. #ifdef __HAVE_BUILTIN_BSWAP32__
  78630. return __builtin_bswap32(val);
  78631. @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
  78632. #endif
  78633. }
  78634. -static inline __attribute_const__ __u64 __fswab64(__u64 val)
  78635. +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
  78636. {
  78637. #ifdef __HAVE_BUILTIN_BSWAP64__
  78638. return __builtin_bswap64(val);
  78639. diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
  78640. index 6d67213..552fdd9 100644
  78641. --- a/include/uapi/linux/sysctl.h
  78642. +++ b/include/uapi/linux/sysctl.h
  78643. @@ -155,8 +155,6 @@ enum
  78644. KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
  78645. };
  78646. -
  78647. -
  78648. /* CTL_VM names: */
  78649. enum
  78650. {
  78651. diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
  78652. index fe94bb9..c9e51c2 100644
  78653. --- a/include/uapi/linux/videodev2.h
  78654. +++ b/include/uapi/linux/videodev2.h
  78655. @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
  78656. union {
  78657. __s32 value;
  78658. __s64 value64;
  78659. - char *string;
  78660. + char __user *string;
  78661. };
  78662. } __attribute__ ((packed));
  78663. diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
  78664. index c38355c..17a57bc 100644
  78665. --- a/include/uapi/linux/xattr.h
  78666. +++ b/include/uapi/linux/xattr.h
  78667. @@ -73,5 +73,9 @@
  78668. #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
  78669. #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
  78670. +/* User namespace */
  78671. +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
  78672. +#define XATTR_PAX_FLAGS_SUFFIX "flags"
  78673. +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
  78674. #endif /* _UAPI_LINUX_XATTR_H */
  78675. diff --git a/include/video/udlfb.h b/include/video/udlfb.h
  78676. index f9466fa..f4e2b81 100644
  78677. --- a/include/video/udlfb.h
  78678. +++ b/include/video/udlfb.h
  78679. @@ -53,10 +53,10 @@ struct dlfb_data {
  78680. u32 pseudo_palette[256];
  78681. int blank_mode; /*one of FB_BLANK_ */
  78682. /* blit-only rendering path metrics, exposed through sysfs */
  78683. - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
  78684. - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
  78685. - atomic_t bytes_sent; /* to usb, after compression including overhead */
  78686. - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
  78687. + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
  78688. + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
  78689. + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
  78690. + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
  78691. };
  78692. #define NR_USB_REQUEST_I2C_SUB_IO 0x02
  78693. diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
  78694. index 30f5362..8ed8ac9 100644
  78695. --- a/include/video/uvesafb.h
  78696. +++ b/include/video/uvesafb.h
  78697. @@ -122,6 +122,7 @@ struct uvesafb_par {
  78698. u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
  78699. u8 pmi_setpal; /* PMI for palette changes */
  78700. u16 *pmi_base; /* protected mode interface location */
  78701. + u8 *pmi_code; /* protected mode code location */
  78702. void *pmi_start;
  78703. void *pmi_pal;
  78704. u8 *vbe_state_orig; /*
  78705. diff --git a/init/Kconfig b/init/Kconfig
  78706. index d56cb03..7e6d5dc 100644
  78707. --- a/init/Kconfig
  78708. +++ b/init/Kconfig
  78709. @@ -1079,6 +1079,7 @@ endif # CGROUPS
  78710. config CHECKPOINT_RESTORE
  78711. bool "Checkpoint/restore support" if EXPERT
  78712. + depends on !GRKERNSEC
  78713. default n
  78714. help
  78715. Enables additional kernel features in a sake of checkpoint/restore.
  78716. @@ -1545,7 +1546,7 @@ config SLUB_DEBUG
  78717. config COMPAT_BRK
  78718. bool "Disable heap randomization"
  78719. - default y
  78720. + default n
  78721. help
  78722. Randomizing heap placement makes heap exploits harder, but it
  78723. also breaks ancient binaries (including anything libc5 based).
  78724. @@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
  78725. config STOP_MACHINE
  78726. bool
  78727. default y
  78728. - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
  78729. + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
  78730. help
  78731. Need stop_machine() primitive.
  78732. diff --git a/init/Makefile b/init/Makefile
  78733. index 7bc47ee..6da2dc7 100644
  78734. --- a/init/Makefile
  78735. +++ b/init/Makefile
  78736. @@ -2,6 +2,9 @@
  78737. # Makefile for the linux kernel.
  78738. #
  78739. +ccflags-y := $(GCC_PLUGINS_CFLAGS)
  78740. +asflags-y := $(GCC_PLUGINS_AFLAGS)
  78741. +
  78742. obj-y := main.o version.o mounts.o
  78743. ifneq ($(CONFIG_BLK_DEV_INITRD),y)
  78744. obj-y += noinitramfs.o
  78745. diff --git a/init/do_mounts.c b/init/do_mounts.c
  78746. index 8e5addc..c96ea61 100644
  78747. --- a/init/do_mounts.c
  78748. +++ b/init/do_mounts.c
  78749. @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
  78750. static int __init do_mount_root(char *name, char *fs, int flags, void *data)
  78751. {
  78752. struct super_block *s;
  78753. - int err = sys_mount(name, "/root", fs, flags, data);
  78754. + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
  78755. if (err)
  78756. return err;
  78757. - sys_chdir("/root");
  78758. + sys_chdir((const char __force_user *)"/root");
  78759. s = current->fs->pwd.dentry->d_sb;
  78760. ROOT_DEV = s->s_dev;
  78761. printk(KERN_INFO
  78762. @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
  78763. va_start(args, fmt);
  78764. vsprintf(buf, fmt, args);
  78765. va_end(args);
  78766. - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
  78767. + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
  78768. if (fd >= 0) {
  78769. sys_ioctl(fd, FDEJECT, 0);
  78770. sys_close(fd);
  78771. }
  78772. printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
  78773. - fd = sys_open("/dev/console", O_RDWR, 0);
  78774. + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
  78775. if (fd >= 0) {
  78776. sys_ioctl(fd, TCGETS, (long)&termios);
  78777. termios.c_lflag &= ~ICANON;
  78778. sys_ioctl(fd, TCSETSF, (long)&termios);
  78779. - sys_read(fd, &c, 1);
  78780. + sys_read(fd, (char __user *)&c, 1);
  78781. termios.c_lflag |= ICANON;
  78782. sys_ioctl(fd, TCSETSF, (long)&termios);
  78783. sys_close(fd);
  78784. @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
  78785. mount_root();
  78786. out:
  78787. devtmpfs_mount("dev");
  78788. - sys_mount(".", "/", NULL, MS_MOVE, NULL);
  78789. - sys_chroot(".");
  78790. + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
  78791. + sys_chroot((const char __force_user *)".");
  78792. }
  78793. static bool is_tmpfs;
  78794. diff --git a/init/do_mounts.h b/init/do_mounts.h
  78795. index f5b978a..69dbfe8 100644
  78796. --- a/init/do_mounts.h
  78797. +++ b/init/do_mounts.h
  78798. @@ -15,15 +15,15 @@ extern int root_mountflags;
  78799. static inline int create_dev(char *name, dev_t dev)
  78800. {
  78801. - sys_unlink(name);
  78802. - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
  78803. + sys_unlink((char __force_user *)name);
  78804. + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
  78805. }
  78806. #if BITS_PER_LONG == 32
  78807. static inline u32 bstat(char *name)
  78808. {
  78809. struct stat64 stat;
  78810. - if (sys_stat64(name, &stat) != 0)
  78811. + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
  78812. return 0;
  78813. if (!S_ISBLK(stat.st_mode))
  78814. return 0;
  78815. @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
  78816. static inline u32 bstat(char *name)
  78817. {
  78818. struct stat stat;
  78819. - if (sys_newstat(name, &stat) != 0)
  78820. + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
  78821. return 0;
  78822. if (!S_ISBLK(stat.st_mode))
  78823. return 0;
  78824. diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
  78825. index 3e0878e..8a9d7a0 100644
  78826. --- a/init/do_mounts_initrd.c
  78827. +++ b/init/do_mounts_initrd.c
  78828. @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
  78829. {
  78830. sys_unshare(CLONE_FS | CLONE_FILES);
  78831. /* stdin/stdout/stderr for /linuxrc */
  78832. - sys_open("/dev/console", O_RDWR, 0);
  78833. + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
  78834. sys_dup(0);
  78835. sys_dup(0);
  78836. /* move initrd over / and chdir/chroot in initrd root */
  78837. - sys_chdir("/root");
  78838. - sys_mount(".", "/", NULL, MS_MOVE, NULL);
  78839. - sys_chroot(".");
  78840. + sys_chdir((const char __force_user *)"/root");
  78841. + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
  78842. + sys_chroot((const char __force_user *)".");
  78843. sys_setsid();
  78844. return 0;
  78845. }
  78846. @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
  78847. create_dev("/dev/root.old", Root_RAM0);
  78848. /* mount initrd on rootfs' /root */
  78849. mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
  78850. - sys_mkdir("/old", 0700);
  78851. - sys_chdir("/old");
  78852. + sys_mkdir((const char __force_user *)"/old", 0700);
  78853. + sys_chdir((const char __force_user *)"/old");
  78854. /* try loading default modules from initrd */
  78855. load_default_modules();
  78856. @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
  78857. current->flags &= ~PF_FREEZER_SKIP;
  78858. /* move initrd to rootfs' /old */
  78859. - sys_mount("..", ".", NULL, MS_MOVE, NULL);
  78860. + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
  78861. /* switch root and cwd back to / of rootfs */
  78862. - sys_chroot("..");
  78863. + sys_chroot((const char __force_user *)"..");
  78864. if (new_decode_dev(real_root_dev) == Root_RAM0) {
  78865. - sys_chdir("/old");
  78866. + sys_chdir((const char __force_user *)"/old");
  78867. return;
  78868. }
  78869. - sys_chdir("/");
  78870. + sys_chdir((const char __force_user *)"/");
  78871. ROOT_DEV = new_decode_dev(real_root_dev);
  78872. mount_root();
  78873. printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
  78874. - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
  78875. + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
  78876. if (!error)
  78877. printk("okay\n");
  78878. else {
  78879. - int fd = sys_open("/dev/root.old", O_RDWR, 0);
  78880. + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
  78881. if (error == -ENOENT)
  78882. printk("/initrd does not exist. Ignored.\n");
  78883. else
  78884. printk("failed\n");
  78885. printk(KERN_NOTICE "Unmounting old root\n");
  78886. - sys_umount("/old", MNT_DETACH);
  78887. + sys_umount((char __force_user *)"/old", MNT_DETACH);
  78888. printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
  78889. if (fd < 0) {
  78890. error = fd;
  78891. @@ -127,11 +127,11 @@ int __init initrd_load(void)
  78892. * mounted in the normal path.
  78893. */
  78894. if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
  78895. - sys_unlink("/initrd.image");
  78896. + sys_unlink((const char __force_user *)"/initrd.image");
  78897. handle_initrd();
  78898. return 1;
  78899. }
  78900. }
  78901. - sys_unlink("/initrd.image");
  78902. + sys_unlink((const char __force_user *)"/initrd.image");
  78903. return 0;
  78904. }
  78905. diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
  78906. index 8cb6db5..d729f50 100644
  78907. --- a/init/do_mounts_md.c
  78908. +++ b/init/do_mounts_md.c
  78909. @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
  78910. partitioned ? "_d" : "", minor,
  78911. md_setup_args[ent].device_names);
  78912. - fd = sys_open(name, 0, 0);
  78913. + fd = sys_open((char __force_user *)name, 0, 0);
  78914. if (fd < 0) {
  78915. printk(KERN_ERR "md: open failed - cannot start "
  78916. "array %s\n", name);
  78917. @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
  78918. * array without it
  78919. */
  78920. sys_close(fd);
  78921. - fd = sys_open(name, 0, 0);
  78922. + fd = sys_open((char __force_user *)name, 0, 0);
  78923. sys_ioctl(fd, BLKRRPART, 0);
  78924. }
  78925. sys_close(fd);
  78926. @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
  78927. wait_for_device_probe();
  78928. - fd = sys_open("/dev/md0", 0, 0);
  78929. + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
  78930. if (fd >= 0) {
  78931. sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
  78932. sys_close(fd);
  78933. diff --git a/init/init_task.c b/init/init_task.c
  78934. index ba0a7f36..2bcf1d5 100644
  78935. --- a/init/init_task.c
  78936. +++ b/init/init_task.c
  78937. @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
  78938. * Initial thread structure. Alignment of this is handled by a special
  78939. * linker map entry.
  78940. */
  78941. +#ifdef CONFIG_X86
  78942. +union thread_union init_thread_union __init_task_data;
  78943. +#else
  78944. union thread_union init_thread_union __init_task_data =
  78945. { INIT_THREAD_INFO(init_task) };
  78946. +#endif
  78947. diff --git a/init/initramfs.c b/init/initramfs.c
  78948. index 93b6139..8d628b7 100644
  78949. --- a/init/initramfs.c
  78950. +++ b/init/initramfs.c
  78951. @@ -84,7 +84,7 @@ static void __init free_hash(void)
  78952. }
  78953. }
  78954. -static long __init do_utime(char *filename, time_t mtime)
  78955. +static long __init do_utime(char __force_user *filename, time_t mtime)
  78956. {
  78957. struct timespec t[2];
  78958. @@ -119,7 +119,7 @@ static void __init dir_utime(void)
  78959. struct dir_entry *de, *tmp;
  78960. list_for_each_entry_safe(de, tmp, &dir_list, list) {
  78961. list_del(&de->list);
  78962. - do_utime(de->name, de->mtime);
  78963. + do_utime((char __force_user *)de->name, de->mtime);
  78964. kfree(de->name);
  78965. kfree(de);
  78966. }
  78967. @@ -281,7 +281,7 @@ static int __init maybe_link(void)
  78968. if (nlink >= 2) {
  78969. char *old = find_link(major, minor, ino, mode, collected);
  78970. if (old)
  78971. - return (sys_link(old, collected) < 0) ? -1 : 1;
  78972. + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
  78973. }
  78974. return 0;
  78975. }
  78976. @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
  78977. {
  78978. struct stat st;
  78979. - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
  78980. + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
  78981. if (S_ISDIR(st.st_mode))
  78982. - sys_rmdir(path);
  78983. + sys_rmdir((char __force_user *)path);
  78984. else
  78985. - sys_unlink(path);
  78986. + sys_unlink((char __force_user *)path);
  78987. }
  78988. }
  78989. @@ -315,7 +315,7 @@ static int __init do_name(void)
  78990. int openflags = O_WRONLY|O_CREAT;
  78991. if (ml != 1)
  78992. openflags |= O_TRUNC;
  78993. - wfd = sys_open(collected, openflags, mode);
  78994. + wfd = sys_open((char __force_user *)collected, openflags, mode);
  78995. if (wfd >= 0) {
  78996. sys_fchown(wfd, uid, gid);
  78997. @@ -327,17 +327,17 @@ static int __init do_name(void)
  78998. }
  78999. }
  79000. } else if (S_ISDIR(mode)) {
  79001. - sys_mkdir(collected, mode);
  79002. - sys_chown(collected, uid, gid);
  79003. - sys_chmod(collected, mode);
  79004. + sys_mkdir((char __force_user *)collected, mode);
  79005. + sys_chown((char __force_user *)collected, uid, gid);
  79006. + sys_chmod((char __force_user *)collected, mode);
  79007. dir_add(collected, mtime);
  79008. } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
  79009. S_ISFIFO(mode) || S_ISSOCK(mode)) {
  79010. if (maybe_link() == 0) {
  79011. - sys_mknod(collected, mode, rdev);
  79012. - sys_chown(collected, uid, gid);
  79013. - sys_chmod(collected, mode);
  79014. - do_utime(collected, mtime);
  79015. + sys_mknod((char __force_user *)collected, mode, rdev);
  79016. + sys_chown((char __force_user *)collected, uid, gid);
  79017. + sys_chmod((char __force_user *)collected, mode);
  79018. + do_utime((char __force_user *)collected, mtime);
  79019. }
  79020. }
  79021. return 0;
  79022. @@ -346,15 +346,15 @@ static int __init do_name(void)
  79023. static int __init do_copy(void)
  79024. {
  79025. if (count >= body_len) {
  79026. - sys_write(wfd, victim, body_len);
  79027. + sys_write(wfd, (char __force_user *)victim, body_len);
  79028. sys_close(wfd);
  79029. - do_utime(vcollected, mtime);
  79030. + do_utime((char __force_user *)vcollected, mtime);
  79031. kfree(vcollected);
  79032. eat(body_len);
  79033. state = SkipIt;
  79034. return 0;
  79035. } else {
  79036. - sys_write(wfd, victim, count);
  79037. + sys_write(wfd, (char __force_user *)victim, count);
  79038. body_len -= count;
  79039. eat(count);
  79040. return 1;
  79041. @@ -365,9 +365,9 @@ static int __init do_symlink(void)
  79042. {
  79043. collected[N_ALIGN(name_len) + body_len] = '\0';
  79044. clean_path(collected, 0);
  79045. - sys_symlink(collected + N_ALIGN(name_len), collected);
  79046. - sys_lchown(collected, uid, gid);
  79047. - do_utime(collected, mtime);
  79048. + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
  79049. + sys_lchown((char __force_user *)collected, uid, gid);
  79050. + do_utime((char __force_user *)collected, mtime);
  79051. state = SkipIt;
  79052. next_state = Reset;
  79053. return 0;
  79054. diff --git a/init/main.c b/init/main.c
  79055. index 9c7fd4c..650b4f1 100644
  79056. --- a/init/main.c
  79057. +++ b/init/main.c
  79058. @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
  79059. static inline void mark_rodata_ro(void) { }
  79060. #endif
  79061. +extern void grsecurity_init(void);
  79062. +
  79063. /*
  79064. * Debug helper: via this flag we know that we are in 'early bootup code'
  79065. * where only the boot processor is running with IRQ disabled. This means
  79066. @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
  79067. __setup("reset_devices", set_reset_devices);
  79068. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  79069. +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
  79070. +static int __init setup_grsec_proc_gid(char *str)
  79071. +{
  79072. + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
  79073. + return 1;
  79074. +}
  79075. +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
  79076. +#endif
  79077. +
  79078. +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
  79079. +unsigned long pax_user_shadow_base __read_only;
  79080. +EXPORT_SYMBOL(pax_user_shadow_base);
  79081. +extern char pax_enter_kernel_user[];
  79082. +extern char pax_exit_kernel_user[];
  79083. +#endif
  79084. +
  79085. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
  79086. +static int __init setup_pax_nouderef(char *str)
  79087. +{
  79088. +#ifdef CONFIG_X86_32
  79089. + unsigned int cpu;
  79090. + struct desc_struct *gdt;
  79091. +
  79092. + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
  79093. + gdt = get_cpu_gdt_table(cpu);
  79094. + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
  79095. + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
  79096. + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
  79097. + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
  79098. + }
  79099. + loadsegment(ds, __KERNEL_DS);
  79100. + loadsegment(es, __KERNEL_DS);
  79101. + loadsegment(ss, __KERNEL_DS);
  79102. +#else
  79103. + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
  79104. + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
  79105. + clone_pgd_mask = ~(pgdval_t)0UL;
  79106. + pax_user_shadow_base = 0UL;
  79107. + setup_clear_cpu_cap(X86_FEATURE_PCID);
  79108. + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
  79109. +#endif
  79110. +
  79111. + return 0;
  79112. +}
  79113. +early_param("pax_nouderef", setup_pax_nouderef);
  79114. +
  79115. +#ifdef CONFIG_X86_64
  79116. +static int __init setup_pax_weakuderef(char *str)
  79117. +{
  79118. + if (clone_pgd_mask != ~(pgdval_t)0UL)
  79119. + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
  79120. + return 1;
  79121. +}
  79122. +__setup("pax_weakuderef", setup_pax_weakuderef);
  79123. +#endif
  79124. +#endif
  79125. +
  79126. +#ifdef CONFIG_PAX_SOFTMODE
  79127. +int pax_softmode;
  79128. +
  79129. +static int __init setup_pax_softmode(char *str)
  79130. +{
  79131. + get_option(&str, &pax_softmode);
  79132. + return 1;
  79133. +}
  79134. +__setup("pax_softmode=", setup_pax_softmode);
  79135. +#endif
  79136. +
  79137. static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
  79138. const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
  79139. static const char *panic_later, *panic_param;
  79140. @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
  79141. {
  79142. int count = preempt_count();
  79143. int ret;
  79144. - char msgbuf[64];
  79145. + const char *msg1 = "", *msg2 = "";
  79146. if (initcall_debug)
  79147. ret = do_one_initcall_debug(fn);
  79148. else
  79149. ret = fn();
  79150. - msgbuf[0] = 0;
  79151. -
  79152. if (preempt_count() != count) {
  79153. - sprintf(msgbuf, "preemption imbalance ");
  79154. + msg1 = " preemption imbalance";
  79155. preempt_count_set(count);
  79156. }
  79157. if (irqs_disabled()) {
  79158. - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
  79159. + msg2 = " disabled interrupts";
  79160. local_irq_enable();
  79161. }
  79162. - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
  79163. + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
  79164. + add_latent_entropy();
  79165. return ret;
  79166. }
  79167. @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
  79168. {
  79169. argv_init[0] = init_filename;
  79170. return do_execve(getname_kernel(init_filename),
  79171. - (const char __user *const __user *)argv_init,
  79172. - (const char __user *const __user *)envp_init);
  79173. + (const char __user *const __force_user *)argv_init,
  79174. + (const char __user *const __force_user *)envp_init);
  79175. }
  79176. static int try_to_run_init_process(const char *init_filename)
  79177. @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
  79178. return ret;
  79179. }
  79180. +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
  79181. +extern int gr_init_ran;
  79182. +#endif
  79183. +
  79184. static noinline void __init kernel_init_freeable(void);
  79185. static int __ref kernel_init(void *unused)
  79186. @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
  79187. ramdisk_execute_command, ret);
  79188. }
  79189. +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
  79190. + /* if no initrd was used, be extra sure we enforce chroot restrictions */
  79191. + gr_init_ran = 1;
  79192. +#endif
  79193. +
  79194. /*
  79195. * We try each of these until one succeeds.
  79196. *
  79197. @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
  79198. do_basic_setup();
  79199. /* Open the /dev/console on the rootfs, this should never fail */
  79200. - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
  79201. + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
  79202. pr_err("Warning: unable to open an initial console.\n");
  79203. (void) sys_dup(0);
  79204. @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
  79205. if (!ramdisk_execute_command)
  79206. ramdisk_execute_command = "/init";
  79207. - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
  79208. + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
  79209. ramdisk_execute_command = NULL;
  79210. prepare_namespace();
  79211. }
  79212. + grsecurity_init();
  79213. +
  79214. /*
  79215. * Ok, we have completed the initial bootup, and
  79216. * we're essentially up and running. Get rid of the
  79217. diff --git a/ipc/compat.c b/ipc/compat.c
  79218. index f486b00..442867f 100644
  79219. --- a/ipc/compat.c
  79220. +++ b/ipc/compat.c
  79221. @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
  79222. COMPAT_SHMLBA);
  79223. if (err < 0)
  79224. return err;
  79225. - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
  79226. + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
  79227. }
  79228. case SHMDT:
  79229. return sys_shmdt(compat_ptr(ptr));
  79230. diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
  79231. index 1702864..797fa84 100644
  79232. --- a/ipc/ipc_sysctl.c
  79233. +++ b/ipc/ipc_sysctl.c
  79234. @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
  79235. static int proc_ipc_dointvec(ctl_table *table, int write,
  79236. void __user *buffer, size_t *lenp, loff_t *ppos)
  79237. {
  79238. - struct ctl_table ipc_table;
  79239. + ctl_table_no_const ipc_table;
  79240. memcpy(&ipc_table, table, sizeof(ipc_table));
  79241. ipc_table.data = get_ipc(table);
  79242. @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
  79243. static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
  79244. void __user *buffer, size_t *lenp, loff_t *ppos)
  79245. {
  79246. - struct ctl_table ipc_table;
  79247. + ctl_table_no_const ipc_table;
  79248. memcpy(&ipc_table, table, sizeof(ipc_table));
  79249. ipc_table.data = get_ipc(table);
  79250. @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
  79251. static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
  79252. void __user *buffer, size_t *lenp, loff_t *ppos)
  79253. {
  79254. - struct ctl_table ipc_table;
  79255. + ctl_table_no_const ipc_table;
  79256. size_t lenp_bef = *lenp;
  79257. int rc;
  79258. @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
  79259. static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
  79260. void __user *buffer, size_t *lenp, loff_t *ppos)
  79261. {
  79262. - struct ctl_table ipc_table;
  79263. + ctl_table_no_const ipc_table;
  79264. memcpy(&ipc_table, table, sizeof(ipc_table));
  79265. ipc_table.data = get_ipc(table);
  79266. @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
  79267. static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
  79268. void __user *buffer, size_t *lenp, loff_t *ppos)
  79269. {
  79270. - struct ctl_table ipc_table;
  79271. + ctl_table_no_const ipc_table;
  79272. size_t lenp_bef = *lenp;
  79273. int oldval;
  79274. int rc;
  79275. diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
  79276. index 5bb8bfe..a38ec05 100644
  79277. --- a/ipc/mq_sysctl.c
  79278. +++ b/ipc/mq_sysctl.c
  79279. @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
  79280. static int proc_mq_dointvec(ctl_table *table, int write,
  79281. void __user *buffer, size_t *lenp, loff_t *ppos)
  79282. {
  79283. - struct ctl_table mq_table;
  79284. + ctl_table_no_const mq_table;
  79285. memcpy(&mq_table, table, sizeof(mq_table));
  79286. mq_table.data = get_mq(table);
  79287. @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
  79288. static int proc_mq_dointvec_minmax(ctl_table *table, int write,
  79289. void __user *buffer, size_t *lenp, loff_t *ppos)
  79290. {
  79291. - struct ctl_table mq_table;
  79292. + ctl_table_no_const mq_table;
  79293. memcpy(&mq_table, table, sizeof(mq_table));
  79294. mq_table.data = get_mq(table);
  79295. diff --git a/ipc/mqueue.c b/ipc/mqueue.c
  79296. index c3b3117..1efa933 100644
  79297. --- a/ipc/mqueue.c
  79298. +++ b/ipc/mqueue.c
  79299. @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
  79300. mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
  79301. info->attr.mq_msgsize);
  79302. + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
  79303. spin_lock(&mq_lock);
  79304. if (u->mq_bytes + mq_bytes < u->mq_bytes ||
  79305. u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
  79306. diff --git a/ipc/msg.c b/ipc/msg.c
  79307. index 6498531..b0ff3c8 100644
  79308. --- a/ipc/msg.c
  79309. +++ b/ipc/msg.c
  79310. @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
  79311. return security_msg_queue_associate(msq, msgflg);
  79312. }
  79313. +static struct ipc_ops msg_ops = {
  79314. + .getnew = newque,
  79315. + .associate = msg_security,
  79316. + .more_checks = NULL
  79317. +};
  79318. +
  79319. SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
  79320. {
  79321. struct ipc_namespace *ns;
  79322. - struct ipc_ops msg_ops;
  79323. struct ipc_params msg_params;
  79324. ns = current->nsproxy->ipc_ns;
  79325. - msg_ops.getnew = newque;
  79326. - msg_ops.associate = msg_security;
  79327. - msg_ops.more_checks = NULL;
  79328. -
  79329. msg_params.key = key;
  79330. msg_params.flg = msgflg;
  79331. diff --git a/ipc/sem.c b/ipc/sem.c
  79332. index bee5554..e9af81dd 100644
  79333. --- a/ipc/sem.c
  79334. +++ b/ipc/sem.c
  79335. @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
  79336. return 0;
  79337. }
  79338. +static struct ipc_ops sem_ops = {
  79339. + .getnew = newary,
  79340. + .associate = sem_security,
  79341. + .more_checks = sem_more_checks
  79342. +};
  79343. +
  79344. SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
  79345. {
  79346. struct ipc_namespace *ns;
  79347. - struct ipc_ops sem_ops;
  79348. struct ipc_params sem_params;
  79349. ns = current->nsproxy->ipc_ns;
  79350. @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
  79351. if (nsems < 0 || nsems > ns->sc_semmsl)
  79352. return -EINVAL;
  79353. - sem_ops.getnew = newary;
  79354. - sem_ops.associate = sem_security;
  79355. - sem_ops.more_checks = sem_more_checks;
  79356. -
  79357. sem_params.key = key;
  79358. sem_params.flg = semflg;
  79359. sem_params.u.nsems = nsems;
  79360. diff --git a/ipc/shm.c b/ipc/shm.c
  79361. index 7645961..afc7f02 100644
  79362. --- a/ipc/shm.c
  79363. +++ b/ipc/shm.c
  79364. @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
  79365. static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
  79366. #endif
  79367. +#ifdef CONFIG_GRKERNSEC
  79368. +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
  79369. + const time_t shm_createtime, const kuid_t cuid,
  79370. + const int shmid);
  79371. +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
  79372. + const time_t shm_createtime);
  79373. +#endif
  79374. +
  79375. void shm_init_ns(struct ipc_namespace *ns)
  79376. {
  79377. ns->shm_ctlmax = SHMMAX;
  79378. @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
  79379. shp->shm_lprid = 0;
  79380. shp->shm_atim = shp->shm_dtim = 0;
  79381. shp->shm_ctim = get_seconds();
  79382. +#ifdef CONFIG_GRKERNSEC
  79383. + {
  79384. + struct timespec timeval;
  79385. + do_posix_clock_monotonic_gettime(&timeval);
  79386. +
  79387. + shp->shm_createtime = timeval.tv_sec;
  79388. + }
  79389. +#endif
  79390. shp->shm_segsz = size;
  79391. shp->shm_nattch = 0;
  79392. shp->shm_file = file;
  79393. @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
  79394. return 0;
  79395. }
  79396. +static struct ipc_ops shm_ops = {
  79397. + .getnew = newseg,
  79398. + .associate = shm_security,
  79399. + .more_checks = shm_more_checks
  79400. +};
  79401. +
  79402. SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
  79403. {
  79404. struct ipc_namespace *ns;
  79405. - struct ipc_ops shm_ops;
  79406. struct ipc_params shm_params;
  79407. ns = current->nsproxy->ipc_ns;
  79408. - shm_ops.getnew = newseg;
  79409. - shm_ops.associate = shm_security;
  79410. - shm_ops.more_checks = shm_more_checks;
  79411. -
  79412. shm_params.key = key;
  79413. shm_params.flg = shmflg;
  79414. shm_params.u.size = size;
  79415. @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
  79416. f_mode = FMODE_READ | FMODE_WRITE;
  79417. }
  79418. if (shmflg & SHM_EXEC) {
  79419. +
  79420. +#ifdef CONFIG_PAX_MPROTECT
  79421. + if (current->mm->pax_flags & MF_PAX_MPROTECT)
  79422. + goto out;
  79423. +#endif
  79424. +
  79425. prot |= PROT_EXEC;
  79426. acc_mode |= S_IXUGO;
  79427. }
  79428. @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
  79429. if (err)
  79430. goto out_unlock;
  79431. +#ifdef CONFIG_GRKERNSEC
  79432. + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
  79433. + shp->shm_perm.cuid, shmid) ||
  79434. + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
  79435. + err = -EACCES;
  79436. + goto out_unlock;
  79437. + }
  79438. +#endif
  79439. +
  79440. ipc_lock_object(&shp->shm_perm);
  79441. /* check if shm_destroy() is tearing down shp */
  79442. @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
  79443. path = shp->shm_file->f_path;
  79444. path_get(&path);
  79445. shp->shm_nattch++;
  79446. +#ifdef CONFIG_GRKERNSEC
  79447. + shp->shm_lapid = current->pid;
  79448. +#endif
  79449. size = i_size_read(path.dentry->d_inode);
  79450. ipc_unlock_object(&shp->shm_perm);
  79451. rcu_read_unlock();
  79452. diff --git a/ipc/util.c b/ipc/util.c
  79453. index e1b4c6d..8174204 100644
  79454. --- a/ipc/util.c
  79455. +++ b/ipc/util.c
  79456. @@ -71,6 +71,8 @@ struct ipc_proc_iface {
  79457. int (*show)(struct seq_file *, void *);
  79458. };
  79459. +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
  79460. +
  79461. static void ipc_memory_notifier(struct work_struct *work)
  79462. {
  79463. ipcns_notify(IPCNS_MEMCHANGED);
  79464. @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
  79465. granted_mode >>= 6;
  79466. else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  79467. granted_mode >>= 3;
  79468. +
  79469. + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
  79470. + return -1;
  79471. +
  79472. /* is there some bit set in requested_mode but not in granted_mode? */
  79473. if ((requested_mode & ~granted_mode & 0007) &&
  79474. !ns_capable(ns->user_ns, CAP_IPC_OWNER))
  79475. diff --git a/kernel/acct.c b/kernel/acct.c
  79476. index 8d6e145..33e0b1e 100644
  79477. --- a/kernel/acct.c
  79478. +++ b/kernel/acct.c
  79479. @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
  79480. */
  79481. flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
  79482. current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
  79483. - file->f_op->write(file, (char *)&ac,
  79484. + file->f_op->write(file, (char __force_user *)&ac,
  79485. sizeof(acct_t), &file->f_pos);
  79486. current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
  79487. set_fs(fs);
  79488. diff --git a/kernel/audit.c b/kernel/audit.c
  79489. index 95a20f3..e1cb300 100644
  79490. --- a/kernel/audit.c
  79491. +++ b/kernel/audit.c
  79492. @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
  79493. 3) suppressed due to audit_rate_limit
  79494. 4) suppressed due to audit_backlog_limit
  79495. */
  79496. -static atomic_t audit_lost = ATOMIC_INIT(0);
  79497. +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
  79498. /* The netlink socket. */
  79499. static struct sock *audit_sock;
  79500. @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
  79501. unsigned long now;
  79502. int print;
  79503. - atomic_inc(&audit_lost);
  79504. + atomic_inc_unchecked(&audit_lost);
  79505. print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
  79506. @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
  79507. if (print) {
  79508. if (printk_ratelimit())
  79509. pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
  79510. - atomic_read(&audit_lost),
  79511. + atomic_read_unchecked(&audit_lost),
  79512. audit_rate_limit,
  79513. audit_backlog_limit);
  79514. audit_panic(message);
  79515. @@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
  79516. s.pid = audit_pid;
  79517. s.rate_limit = audit_rate_limit;
  79518. s.backlog_limit = audit_backlog_limit;
  79519. - s.lost = atomic_read(&audit_lost);
  79520. + s.lost = atomic_read_unchecked(&audit_lost);
  79521. s.backlog = skb_queue_len(&audit_skb_queue);
  79522. s.version = AUDIT_VERSION_LATEST;
  79523. s.backlog_wait_time = audit_backlog_wait_time;
  79524. diff --git a/kernel/auditsc.c b/kernel/auditsc.c
  79525. index 7aef2f4..db6ced2 100644
  79526. --- a/kernel/auditsc.c
  79527. +++ b/kernel/auditsc.c
  79528. @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
  79529. }
  79530. /* global counter which is incremented every time something logs in */
  79531. -static atomic_t session_id = ATOMIC_INIT(0);
  79532. +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
  79533. static int audit_set_loginuid_perm(kuid_t loginuid)
  79534. {
  79535. @@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
  79536. /* are we setting or clearing? */
  79537. if (uid_valid(loginuid))
  79538. - sessionid = (unsigned int)atomic_inc_return(&session_id);
  79539. + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
  79540. task->sessionid = sessionid;
  79541. task->loginuid = loginuid;
  79542. diff --git a/kernel/capability.c b/kernel/capability.c
  79543. index 34019c5..363f279 100644
  79544. --- a/kernel/capability.c
  79545. +++ b/kernel/capability.c
  79546. @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
  79547. * before modification is attempted and the application
  79548. * fails.
  79549. */
  79550. + if (tocopy > ARRAY_SIZE(kdata))
  79551. + return -EFAULT;
  79552. +
  79553. if (copy_to_user(dataptr, kdata, tocopy
  79554. * sizeof(struct __user_cap_data_struct))) {
  79555. return -EFAULT;
  79556. @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
  79557. int ret;
  79558. rcu_read_lock();
  79559. - ret = security_capable(__task_cred(t), ns, cap);
  79560. + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
  79561. + gr_task_is_capable(t, __task_cred(t), cap);
  79562. rcu_read_unlock();
  79563. - return (ret == 0);
  79564. + return ret;
  79565. }
  79566. /**
  79567. @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
  79568. int ret;
  79569. rcu_read_lock();
  79570. - ret = security_capable_noaudit(__task_cred(t), ns, cap);
  79571. + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
  79572. rcu_read_unlock();
  79573. - return (ret == 0);
  79574. + return ret;
  79575. }
  79576. /**
  79577. @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
  79578. BUG();
  79579. }
  79580. - if (security_capable(current_cred(), ns, cap) == 0) {
  79581. + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
  79582. current->flags |= PF_SUPERPRIV;
  79583. return true;
  79584. }
  79585. @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
  79586. }
  79587. EXPORT_SYMBOL(ns_capable);
  79588. +bool ns_capable_nolog(struct user_namespace *ns, int cap)
  79589. +{
  79590. + if (unlikely(!cap_valid(cap))) {
  79591. + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
  79592. + BUG();
  79593. + }
  79594. +
  79595. + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
  79596. + current->flags |= PF_SUPERPRIV;
  79597. + return true;
  79598. + }
  79599. + return false;
  79600. +}
  79601. +EXPORT_SYMBOL(ns_capable_nolog);
  79602. +
  79603. /**
  79604. * file_ns_capable - Determine if the file's opener had a capability in effect
  79605. * @file: The file we want to check
  79606. @@ -432,6 +451,12 @@ bool capable(int cap)
  79607. }
  79608. EXPORT_SYMBOL(capable);
  79609. +bool capable_nolog(int cap)
  79610. +{
  79611. + return ns_capable_nolog(&init_user_ns, cap);
  79612. +}
  79613. +EXPORT_SYMBOL(capable_nolog);
  79614. +
  79615. /**
  79616. * inode_capable - Check superior capability over inode
  79617. * @inode: The inode in question
  79618. @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
  79619. return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
  79620. }
  79621. EXPORT_SYMBOL(inode_capable);
  79622. +
  79623. +bool inode_capable_nolog(const struct inode *inode, int cap)
  79624. +{
  79625. + struct user_namespace *ns = current_user_ns();
  79626. +
  79627. + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
  79628. +}
  79629. +EXPORT_SYMBOL(inode_capable_nolog);
  79630. diff --git a/kernel/cgroup.c b/kernel/cgroup.c
  79631. index 0c753dd..dd7d3d6 100644
  79632. --- a/kernel/cgroup.c
  79633. +++ b/kernel/cgroup.c
  79634. @@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
  79635. struct css_set *cset = link->cset;
  79636. struct task_struct *task;
  79637. int count = 0;
  79638. - seq_printf(seq, "css_set %p\n", cset);
  79639. + seq_printf(seq, "css_set %pK\n", cset);
  79640. list_for_each_entry(task, &cset->tasks, cg_list) {
  79641. if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
  79642. seq_puts(seq, " ...\n");
  79643. diff --git a/kernel/compat.c b/kernel/compat.c
  79644. index 0a09e48..b46b3d78 100644
  79645. --- a/kernel/compat.c
  79646. +++ b/kernel/compat.c
  79647. @@ -13,6 +13,7 @@
  79648. #include <linux/linkage.h>
  79649. #include <linux/compat.h>
  79650. +#include <linux/module.h>
  79651. #include <linux/errno.h>
  79652. #include <linux/time.h>
  79653. #include <linux/signal.h>
  79654. @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
  79655. mm_segment_t oldfs;
  79656. long ret;
  79657. - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
  79658. + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
  79659. oldfs = get_fs();
  79660. set_fs(KERNEL_DS);
  79661. ret = hrtimer_nanosleep_restart(restart);
  79662. @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
  79663. oldfs = get_fs();
  79664. set_fs(KERNEL_DS);
  79665. ret = hrtimer_nanosleep(&tu,
  79666. - rmtp ? (struct timespec __user *)&rmt : NULL,
  79667. + rmtp ? (struct timespec __force_user *)&rmt : NULL,
  79668. HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  79669. set_fs(oldfs);
  79670. @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
  79671. mm_segment_t old_fs = get_fs();
  79672. set_fs(KERNEL_DS);
  79673. - ret = sys_sigpending((old_sigset_t __user *) &s);
  79674. + ret = sys_sigpending((old_sigset_t __force_user *) &s);
  79675. set_fs(old_fs);
  79676. if (ret == 0)
  79677. ret = put_user(s, set);
  79678. @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
  79679. mm_segment_t old_fs = get_fs();
  79680. set_fs(KERNEL_DS);
  79681. - ret = sys_old_getrlimit(resource, &r);
  79682. + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
  79683. set_fs(old_fs);
  79684. if (!ret) {
  79685. @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
  79686. set_fs (KERNEL_DS);
  79687. ret = sys_wait4(pid,
  79688. (stat_addr ?
  79689. - (unsigned int __user *) &status : NULL),
  79690. - options, (struct rusage __user *) &r);
  79691. + (unsigned int __force_user *) &status : NULL),
  79692. + options, (struct rusage __force_user *) &r);
  79693. set_fs (old_fs);
  79694. if (ret > 0) {
  79695. @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
  79696. memset(&info, 0, sizeof(info));
  79697. set_fs(KERNEL_DS);
  79698. - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
  79699. - uru ? (struct rusage __user *)&ru : NULL);
  79700. + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
  79701. + uru ? (struct rusage __force_user *)&ru : NULL);
  79702. set_fs(old_fs);
  79703. if ((ret < 0) || (info.si_signo == 0))
  79704. @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
  79705. oldfs = get_fs();
  79706. set_fs(KERNEL_DS);
  79707. err = sys_timer_settime(timer_id, flags,
  79708. - (struct itimerspec __user *) &newts,
  79709. - (struct itimerspec __user *) &oldts);
  79710. + (struct itimerspec __force_user *) &newts,
  79711. + (struct itimerspec __force_user *) &oldts);
  79712. set_fs(oldfs);
  79713. if (!err && old && put_compat_itimerspec(old, &oldts))
  79714. return -EFAULT;
  79715. @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
  79716. oldfs = get_fs();
  79717. set_fs(KERNEL_DS);
  79718. err = sys_timer_gettime(timer_id,
  79719. - (struct itimerspec __user *) &ts);
  79720. + (struct itimerspec __force_user *) &ts);
  79721. set_fs(oldfs);
  79722. if (!err && put_compat_itimerspec(setting, &ts))
  79723. return -EFAULT;
  79724. @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
  79725. oldfs = get_fs();
  79726. set_fs(KERNEL_DS);
  79727. err = sys_clock_settime(which_clock,
  79728. - (struct timespec __user *) &ts);
  79729. + (struct timespec __force_user *) &ts);
  79730. set_fs(oldfs);
  79731. return err;
  79732. }
  79733. @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
  79734. oldfs = get_fs();
  79735. set_fs(KERNEL_DS);
  79736. err = sys_clock_gettime(which_clock,
  79737. - (struct timespec __user *) &ts);
  79738. + (struct timespec __force_user *) &ts);
  79739. set_fs(oldfs);
  79740. if (!err && put_compat_timespec(&ts, tp))
  79741. return -EFAULT;
  79742. @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
  79743. oldfs = get_fs();
  79744. set_fs(KERNEL_DS);
  79745. - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
  79746. + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
  79747. set_fs(oldfs);
  79748. err = compat_put_timex(utp, &txc);
  79749. @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
  79750. oldfs = get_fs();
  79751. set_fs(KERNEL_DS);
  79752. err = sys_clock_getres(which_clock,
  79753. - (struct timespec __user *) &ts);
  79754. + (struct timespec __force_user *) &ts);
  79755. set_fs(oldfs);
  79756. if (!err && tp && put_compat_timespec(&ts, tp))
  79757. return -EFAULT;
  79758. @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
  79759. long err;
  79760. mm_segment_t oldfs;
  79761. struct timespec tu;
  79762. - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
  79763. + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
  79764. - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
  79765. + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
  79766. oldfs = get_fs();
  79767. set_fs(KERNEL_DS);
  79768. err = clock_nanosleep_restart(restart);
  79769. @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
  79770. oldfs = get_fs();
  79771. set_fs(KERNEL_DS);
  79772. err = sys_clock_nanosleep(which_clock, flags,
  79773. - (struct timespec __user *) &in,
  79774. - (struct timespec __user *) &out);
  79775. + (struct timespec __force_user *) &in,
  79776. + (struct timespec __force_user *) &out);
  79777. set_fs(oldfs);
  79778. if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
  79779. @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
  79780. mm_segment_t old_fs = get_fs();
  79781. set_fs(KERNEL_DS);
  79782. - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
  79783. + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
  79784. set_fs(old_fs);
  79785. if (put_compat_timespec(&t, interval))
  79786. return -EFAULT;
  79787. diff --git a/kernel/configs.c b/kernel/configs.c
  79788. index c18b1f1..b9a0132 100644
  79789. --- a/kernel/configs.c
  79790. +++ b/kernel/configs.c
  79791. @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
  79792. struct proc_dir_entry *entry;
  79793. /* create the current config file */
  79794. +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
  79795. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
  79796. + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
  79797. + &ikconfig_file_ops);
  79798. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  79799. + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
  79800. + &ikconfig_file_ops);
  79801. +#endif
  79802. +#else
  79803. entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
  79804. &ikconfig_file_ops);
  79805. +#endif
  79806. +
  79807. if (!entry)
  79808. return -ENOMEM;
  79809. diff --git a/kernel/cred.c b/kernel/cred.c
  79810. index e0573a4..3874e41 100644
  79811. --- a/kernel/cred.c
  79812. +++ b/kernel/cred.c
  79813. @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
  79814. validate_creds(cred);
  79815. alter_cred_subscribers(cred, -1);
  79816. put_cred(cred);
  79817. +
  79818. +#ifdef CONFIG_GRKERNSEC_SETXID
  79819. + cred = (struct cred *) tsk->delayed_cred;
  79820. + if (cred != NULL) {
  79821. + tsk->delayed_cred = NULL;
  79822. + validate_creds(cred);
  79823. + alter_cred_subscribers(cred, -1);
  79824. + put_cred(cred);
  79825. + }
  79826. +#endif
  79827. }
  79828. /**
  79829. @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
  79830. * Always returns 0 thus allowing this function to be tail-called at the end
  79831. * of, say, sys_setgid().
  79832. */
  79833. -int commit_creds(struct cred *new)
  79834. +static int __commit_creds(struct cred *new)
  79835. {
  79836. struct task_struct *task = current;
  79837. const struct cred *old = task->real_cred;
  79838. @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
  79839. get_cred(new); /* we will require a ref for the subj creds too */
  79840. + gr_set_role_label(task, new->uid, new->gid);
  79841. +
  79842. /* dumpability changes */
  79843. if (!uid_eq(old->euid, new->euid) ||
  79844. !gid_eq(old->egid, new->egid) ||
  79845. @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
  79846. put_cred(old);
  79847. return 0;
  79848. }
  79849. +#ifdef CONFIG_GRKERNSEC_SETXID
  79850. +extern int set_user(struct cred *new);
  79851. +
  79852. +void gr_delayed_cred_worker(void)
  79853. +{
  79854. + const struct cred *new = current->delayed_cred;
  79855. + struct cred *ncred;
  79856. +
  79857. + current->delayed_cred = NULL;
  79858. +
  79859. + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
  79860. + // from doing get_cred on it when queueing this
  79861. + put_cred(new);
  79862. + return;
  79863. + } else if (new == NULL)
  79864. + return;
  79865. +
  79866. + ncred = prepare_creds();
  79867. + if (!ncred)
  79868. + goto die;
  79869. + // uids
  79870. + ncred->uid = new->uid;
  79871. + ncred->euid = new->euid;
  79872. + ncred->suid = new->suid;
  79873. + ncred->fsuid = new->fsuid;
  79874. + // gids
  79875. + ncred->gid = new->gid;
  79876. + ncred->egid = new->egid;
  79877. + ncred->sgid = new->sgid;
  79878. + ncred->fsgid = new->fsgid;
  79879. + // groups
  79880. + if (set_groups(ncred, new->group_info) < 0) {
  79881. + abort_creds(ncred);
  79882. + goto die;
  79883. + }
  79884. + // caps
  79885. + ncred->securebits = new->securebits;
  79886. + ncred->cap_inheritable = new->cap_inheritable;
  79887. + ncred->cap_permitted = new->cap_permitted;
  79888. + ncred->cap_effective = new->cap_effective;
  79889. + ncred->cap_bset = new->cap_bset;
  79890. +
  79891. + if (set_user(ncred)) {
  79892. + abort_creds(ncred);
  79893. + goto die;
  79894. + }
  79895. +
  79896. + // from doing get_cred on it when queueing this
  79897. + put_cred(new);
  79898. +
  79899. + __commit_creds(ncred);
  79900. + return;
  79901. +die:
  79902. + // from doing get_cred on it when queueing this
  79903. + put_cred(new);
  79904. + do_group_exit(SIGKILL);
  79905. +}
  79906. +#endif
  79907. +
  79908. +int commit_creds(struct cred *new)
  79909. +{
  79910. +#ifdef CONFIG_GRKERNSEC_SETXID
  79911. + int ret;
  79912. + int schedule_it = 0;
  79913. + struct task_struct *t;
  79914. +
  79915. + /* we won't get called with tasklist_lock held for writing
  79916. + and interrupts disabled as the cred struct in that case is
  79917. + init_cred
  79918. + */
  79919. + if (grsec_enable_setxid && !current_is_single_threaded() &&
  79920. + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
  79921. + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
  79922. + schedule_it = 1;
  79923. + }
  79924. + ret = __commit_creds(new);
  79925. + if (schedule_it) {
  79926. + rcu_read_lock();
  79927. + read_lock(&tasklist_lock);
  79928. + for (t = next_thread(current); t != current;
  79929. + t = next_thread(t)) {
  79930. + if (t->delayed_cred == NULL) {
  79931. + t->delayed_cred = get_cred(new);
  79932. + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
  79933. + set_tsk_need_resched(t);
  79934. + }
  79935. + }
  79936. + read_unlock(&tasklist_lock);
  79937. + rcu_read_unlock();
  79938. + }
  79939. + return ret;
  79940. +#else
  79941. + return __commit_creds(new);
  79942. +#endif
  79943. +}
  79944. +
  79945. EXPORT_SYMBOL(commit_creds);
  79946. /**
  79947. diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
  79948. index 334b398..9145fb1 100644
  79949. --- a/kernel/debug/debug_core.c
  79950. +++ b/kernel/debug/debug_core.c
  79951. @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
  79952. */
  79953. static atomic_t masters_in_kgdb;
  79954. static atomic_t slaves_in_kgdb;
  79955. -static atomic_t kgdb_break_tasklet_var;
  79956. +static atomic_unchecked_t kgdb_break_tasklet_var;
  79957. atomic_t kgdb_setting_breakpoint;
  79958. struct task_struct *kgdb_usethread;
  79959. @@ -133,7 +133,7 @@ int kgdb_single_step;
  79960. static pid_t kgdb_sstep_pid;
  79961. /* to keep track of the CPU which is doing the single stepping*/
  79962. -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
  79963. +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
  79964. /*
  79965. * If you are debugging a problem where roundup (the collection of
  79966. @@ -541,7 +541,7 @@ return_normal:
  79967. * kernel will only try for the value of sstep_tries before
  79968. * giving up and continuing on.
  79969. */
  79970. - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
  79971. + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
  79972. (kgdb_info[cpu].task &&
  79973. kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
  79974. atomic_set(&kgdb_active, -1);
  79975. @@ -639,8 +639,8 @@ cpu_master_loop:
  79976. }
  79977. kgdb_restore:
  79978. - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
  79979. - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
  79980. + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
  79981. + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
  79982. if (kgdb_info[sstep_cpu].task)
  79983. kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
  79984. else
  79985. @@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
  79986. static void kgdb_tasklet_bpt(unsigned long ing)
  79987. {
  79988. kgdb_breakpoint();
  79989. - atomic_set(&kgdb_break_tasklet_var, 0);
  79990. + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
  79991. }
  79992. static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
  79993. void kgdb_schedule_breakpoint(void)
  79994. {
  79995. - if (atomic_read(&kgdb_break_tasklet_var) ||
  79996. + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
  79997. atomic_read(&kgdb_active) != -1 ||
  79998. atomic_read(&kgdb_setting_breakpoint))
  79999. return;
  80000. - atomic_inc(&kgdb_break_tasklet_var);
  80001. + atomic_inc_unchecked(&kgdb_break_tasklet_var);
  80002. tasklet_schedule(&kgdb_tasklet_breakpoint);
  80003. }
  80004. EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
  80005. diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
  80006. index 0b097c8..11dd5c5 100644
  80007. --- a/kernel/debug/kdb/kdb_main.c
  80008. +++ b/kernel/debug/kdb/kdb_main.c
  80009. @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
  80010. continue;
  80011. kdb_printf("%-20s%8u 0x%p ", mod->name,
  80012. - mod->core_size, (void *)mod);
  80013. + mod->core_size_rx + mod->core_size_rw, (void *)mod);
  80014. #ifdef CONFIG_MODULE_UNLOAD
  80015. kdb_printf("%4ld ", module_refcount(mod));
  80016. #endif
  80017. @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
  80018. kdb_printf(" (Loading)");
  80019. else
  80020. kdb_printf(" (Live)");
  80021. - kdb_printf(" 0x%p", mod->module_core);
  80022. + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
  80023. #ifdef CONFIG_MODULE_UNLOAD
  80024. {
  80025. diff --git a/kernel/events/core.c b/kernel/events/core.c
  80026. index fa0b2d4..67a1c7a 100644
  80027. --- a/kernel/events/core.c
  80028. +++ b/kernel/events/core.c
  80029. @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
  80030. * 0 - disallow raw tracepoint access for unpriv
  80031. * 1 - disallow cpu events for unpriv
  80032. * 2 - disallow kernel profiling for unpriv
  80033. + * 3 - disallow all unpriv perf event use
  80034. */
  80035. -int sysctl_perf_event_paranoid __read_mostly = 1;
  80036. +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
  80037. +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
  80038. +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
  80039. +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
  80040. +#else
  80041. +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
  80042. +#endif
  80043. /* Minimum for 512 kiB + 1 user control page */
  80044. int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
  80045. @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
  80046. tmp *= sysctl_perf_cpu_time_max_percent;
  80047. do_div(tmp, 100);
  80048. - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
  80049. + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
  80050. }
  80051. static int perf_rotate_context(struct perf_cpu_context *cpuctx);
  80052. @@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
  80053. update_perf_cpu_limits();
  80054. }
  80055. -static atomic64_t perf_event_id;
  80056. +static atomic64_unchecked_t perf_event_id;
  80057. static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
  80058. enum event_type_t event_type);
  80059. @@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
  80060. static inline u64 perf_event_count(struct perf_event *event)
  80061. {
  80062. - return local64_read(&event->count) + atomic64_read(&event->child_count);
  80063. + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
  80064. }
  80065. static u64 perf_event_read(struct perf_event *event)
  80066. @@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
  80067. mutex_lock(&event->child_mutex);
  80068. total += perf_event_read(event);
  80069. *enabled += event->total_time_enabled +
  80070. - atomic64_read(&event->child_total_time_enabled);
  80071. + atomic64_read_unchecked(&event->child_total_time_enabled);
  80072. *running += event->total_time_running +
  80073. - atomic64_read(&event->child_total_time_running);
  80074. + atomic64_read_unchecked(&event->child_total_time_running);
  80075. list_for_each_entry(child, &event->child_list, child_list) {
  80076. total += perf_event_read(child);
  80077. @@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
  80078. userpg->offset -= local64_read(&event->hw.prev_count);
  80079. userpg->time_enabled = enabled +
  80080. - atomic64_read(&event->child_total_time_enabled);
  80081. + atomic64_read_unchecked(&event->child_total_time_enabled);
  80082. userpg->time_running = running +
  80083. - atomic64_read(&event->child_total_time_running);
  80084. + atomic64_read_unchecked(&event->child_total_time_running);
  80085. arch_perf_update_userpage(userpg, now);
  80086. @@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
  80087. /* Data. */
  80088. sp = perf_user_stack_pointer(regs);
  80089. - rem = __output_copy_user(handle, (void *) sp, dump_size);
  80090. + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
  80091. dyn_size = dump_size - rem;
  80092. perf_output_skip(handle, rem);
  80093. @@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
  80094. values[n++] = perf_event_count(event);
  80095. if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
  80096. values[n++] = enabled +
  80097. - atomic64_read(&event->child_total_time_enabled);
  80098. + atomic64_read_unchecked(&event->child_total_time_enabled);
  80099. }
  80100. if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
  80101. values[n++] = running +
  80102. - atomic64_read(&event->child_total_time_running);
  80103. + atomic64_read_unchecked(&event->child_total_time_running);
  80104. }
  80105. if (read_format & PERF_FORMAT_ID)
  80106. values[n++] = primary_event_id(event);
  80107. @@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
  80108. event->parent = parent_event;
  80109. event->ns = get_pid_ns(task_active_pid_ns(current));
  80110. - event->id = atomic64_inc_return(&perf_event_id);
  80111. + event->id = atomic64_inc_return_unchecked(&perf_event_id);
  80112. event->state = PERF_EVENT_STATE_INACTIVE;
  80113. @@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
  80114. if (flags & ~PERF_FLAG_ALL)
  80115. return -EINVAL;
  80116. +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
  80117. + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
  80118. + return -EACCES;
  80119. +#endif
  80120. +
  80121. err = perf_copy_attr(attr_uptr, &attr);
  80122. if (err)
  80123. return err;
  80124. @@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
  80125. /*
  80126. * Add back the child's count to the parent's count:
  80127. */
  80128. - atomic64_add(child_val, &parent_event->child_count);
  80129. - atomic64_add(child_event->total_time_enabled,
  80130. + atomic64_add_unchecked(child_val, &parent_event->child_count);
  80131. + atomic64_add_unchecked(child_event->total_time_enabled,
  80132. &parent_event->child_total_time_enabled);
  80133. - atomic64_add(child_event->total_time_running,
  80134. + atomic64_add_unchecked(child_event->total_time_running,
  80135. &parent_event->child_total_time_running);
  80136. /*
  80137. diff --git a/kernel/events/internal.h b/kernel/events/internal.h
  80138. index 569b2187..19940d9 100644
  80139. --- a/kernel/events/internal.h
  80140. +++ b/kernel/events/internal.h
  80141. @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
  80142. return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
  80143. }
  80144. -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
  80145. +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
  80146. static inline unsigned long \
  80147. func_name(struct perf_output_handle *handle, \
  80148. - const void *buf, unsigned long len) \
  80149. + const void user *buf, unsigned long len) \
  80150. { \
  80151. unsigned long size, written; \
  80152. \
  80153. @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
  80154. return 0;
  80155. }
  80156. -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
  80157. +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
  80158. static inline unsigned long
  80159. memcpy_skip(void *dst, const void *src, unsigned long n)
  80160. @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
  80161. return 0;
  80162. }
  80163. -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
  80164. +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
  80165. #ifndef arch_perf_out_copy_user
  80166. #define arch_perf_out_copy_user arch_perf_out_copy_user
  80167. @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
  80168. }
  80169. #endif
  80170. -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
  80171. +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
  80172. /* Callchain handling */
  80173. extern struct perf_callchain_entry *
  80174. diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
  80175. index 307d87c..6466cbe 100644
  80176. --- a/kernel/events/uprobes.c
  80177. +++ b/kernel/events/uprobes.c
  80178. @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
  80179. {
  80180. struct page *page;
  80181. uprobe_opcode_t opcode;
  80182. - int result;
  80183. + long result;
  80184. pagefault_disable();
  80185. result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
  80186. diff --git a/kernel/exit.c b/kernel/exit.c
  80187. index 81b3d67..ef189a4 100644
  80188. --- a/kernel/exit.c
  80189. +++ b/kernel/exit.c
  80190. @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
  80191. struct task_struct *leader;
  80192. int zap_leader;
  80193. repeat:
  80194. +#ifdef CONFIG_NET
  80195. + gr_del_task_from_ip_table(p);
  80196. +#endif
  80197. +
  80198. /* don't need to get the RCU readlock here - the process is dead and
  80199. * can't be modifying its own credentials. But shut RCU-lockdep up */
  80200. rcu_read_lock();
  80201. @@ -330,7 +334,7 @@ int allow_signal(int sig)
  80202. * know it'll be handled, so that they don't get converted to
  80203. * SIGKILL or just silently dropped.
  80204. */
  80205. - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
  80206. + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
  80207. recalc_sigpending();
  80208. spin_unlock_irq(&current->sighand->siglock);
  80209. return 0;
  80210. @@ -706,6 +710,8 @@ void do_exit(long code)
  80211. struct task_struct *tsk = current;
  80212. int group_dead;
  80213. + set_fs(USER_DS);
  80214. +
  80215. profile_task_exit(tsk);
  80216. WARN_ON(blk_needs_flush_plug(tsk));
  80217. @@ -722,7 +728,6 @@ void do_exit(long code)
  80218. * mm_release()->clear_child_tid() from writing to a user-controlled
  80219. * kernel address.
  80220. */
  80221. - set_fs(USER_DS);
  80222. ptrace_event(PTRACE_EVENT_EXIT, code);
  80223. @@ -781,6 +786,9 @@ void do_exit(long code)
  80224. tsk->exit_code = code;
  80225. taskstats_exit(tsk, group_dead);
  80226. + gr_acl_handle_psacct(tsk, code);
  80227. + gr_acl_handle_exit();
  80228. +
  80229. exit_mm(tsk);
  80230. if (group_dead)
  80231. @@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
  80232. * Take down every thread in the group. This is called by fatal signals
  80233. * as well as by sys_exit_group (below).
  80234. */
  80235. -void
  80236. +__noreturn void
  80237. do_group_exit(int exit_code)
  80238. {
  80239. struct signal_struct *sig = current->signal;
  80240. diff --git a/kernel/fork.c b/kernel/fork.c
  80241. index a17621c..b77fef8 100644
  80242. --- a/kernel/fork.c
  80243. +++ b/kernel/fork.c
  80244. @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
  80245. *stackend = STACK_END_MAGIC; /* for overflow detection */
  80246. #ifdef CONFIG_CC_STACKPROTECTOR
  80247. - tsk->stack_canary = get_random_int();
  80248. + tsk->stack_canary = pax_get_random_long();
  80249. #endif
  80250. /*
  80251. @@ -345,12 +345,80 @@ free_tsk:
  80252. }
  80253. #ifdef CONFIG_MMU
  80254. -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
  80255. +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
  80256. +{
  80257. + struct vm_area_struct *tmp;
  80258. + unsigned long charge;
  80259. + struct file *file;
  80260. + int retval;
  80261. +
  80262. + charge = 0;
  80263. + if (mpnt->vm_flags & VM_ACCOUNT) {
  80264. + unsigned long len = vma_pages(mpnt);
  80265. +
  80266. + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
  80267. + goto fail_nomem;
  80268. + charge = len;
  80269. + }
  80270. + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
  80271. + if (!tmp)
  80272. + goto fail_nomem;
  80273. + *tmp = *mpnt;
  80274. + tmp->vm_mm = mm;
  80275. + INIT_LIST_HEAD(&tmp->anon_vma_chain);
  80276. + retval = vma_dup_policy(mpnt, tmp);
  80277. + if (retval)
  80278. + goto fail_nomem_policy;
  80279. + if (anon_vma_fork(tmp, mpnt))
  80280. + goto fail_nomem_anon_vma_fork;
  80281. + tmp->vm_flags &= ~VM_LOCKED;
  80282. + tmp->vm_next = tmp->vm_prev = NULL;
  80283. + tmp->vm_mirror = NULL;
  80284. + file = tmp->vm_file;
  80285. + if (file) {
  80286. + struct inode *inode = file_inode(file);
  80287. + struct address_space *mapping = file->f_mapping;
  80288. +
  80289. + get_file(file);
  80290. + if (tmp->vm_flags & VM_DENYWRITE)
  80291. + atomic_dec(&inode->i_writecount);
  80292. + mutex_lock(&mapping->i_mmap_mutex);
  80293. + if (tmp->vm_flags & VM_SHARED)
  80294. + mapping->i_mmap_writable++;
  80295. + flush_dcache_mmap_lock(mapping);
  80296. + /* insert tmp into the share list, just after mpnt */
  80297. + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
  80298. + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
  80299. + else
  80300. + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
  80301. + flush_dcache_mmap_unlock(mapping);
  80302. + mutex_unlock(&mapping->i_mmap_mutex);
  80303. + }
  80304. +
  80305. + /*
  80306. + * Clear hugetlb-related page reserves for children. This only
  80307. + * affects MAP_PRIVATE mappings. Faults generated by the child
  80308. + * are not guaranteed to succeed, even if read-only
  80309. + */
  80310. + if (is_vm_hugetlb_page(tmp))
  80311. + reset_vma_resv_huge_pages(tmp);
  80312. +
  80313. + return tmp;
  80314. +
  80315. +fail_nomem_anon_vma_fork:
  80316. + mpol_put(vma_policy(tmp));
  80317. +fail_nomem_policy:
  80318. + kmem_cache_free(vm_area_cachep, tmp);
  80319. +fail_nomem:
  80320. + vm_unacct_memory(charge);
  80321. + return NULL;
  80322. +}
  80323. +
  80324. +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
  80325. {
  80326. struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
  80327. struct rb_node **rb_link, *rb_parent;
  80328. int retval;
  80329. - unsigned long charge;
  80330. uprobe_start_dup_mmap();
  80331. down_write(&oldmm->mmap_sem);
  80332. @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
  80333. prev = NULL;
  80334. for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
  80335. - struct file *file;
  80336. -
  80337. if (mpnt->vm_flags & VM_DONTCOPY) {
  80338. vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
  80339. -vma_pages(mpnt));
  80340. continue;
  80341. }
  80342. - charge = 0;
  80343. - if (mpnt->vm_flags & VM_ACCOUNT) {
  80344. - unsigned long len = vma_pages(mpnt);
  80345. -
  80346. - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
  80347. - goto fail_nomem;
  80348. - charge = len;
  80349. - }
  80350. - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
  80351. - if (!tmp)
  80352. - goto fail_nomem;
  80353. - *tmp = *mpnt;
  80354. - INIT_LIST_HEAD(&tmp->anon_vma_chain);
  80355. - retval = vma_dup_policy(mpnt, tmp);
  80356. - if (retval)
  80357. - goto fail_nomem_policy;
  80358. - tmp->vm_mm = mm;
  80359. - if (anon_vma_fork(tmp, mpnt))
  80360. - goto fail_nomem_anon_vma_fork;
  80361. - tmp->vm_flags &= ~VM_LOCKED;
  80362. - tmp->vm_next = tmp->vm_prev = NULL;
  80363. - file = tmp->vm_file;
  80364. - if (file) {
  80365. - struct inode *inode = file_inode(file);
  80366. - struct address_space *mapping = file->f_mapping;
  80367. -
  80368. - get_file(file);
  80369. - if (tmp->vm_flags & VM_DENYWRITE)
  80370. - atomic_dec(&inode->i_writecount);
  80371. - mutex_lock(&mapping->i_mmap_mutex);
  80372. - if (tmp->vm_flags & VM_SHARED)
  80373. - mapping->i_mmap_writable++;
  80374. - flush_dcache_mmap_lock(mapping);
  80375. - /* insert tmp into the share list, just after mpnt */
  80376. - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
  80377. - vma_nonlinear_insert(tmp,
  80378. - &mapping->i_mmap_nonlinear);
  80379. - else
  80380. - vma_interval_tree_insert_after(tmp, mpnt,
  80381. - &mapping->i_mmap);
  80382. - flush_dcache_mmap_unlock(mapping);
  80383. - mutex_unlock(&mapping->i_mmap_mutex);
  80384. + tmp = dup_vma(mm, oldmm, mpnt);
  80385. + if (!tmp) {
  80386. + retval = -ENOMEM;
  80387. + goto out;
  80388. }
  80389. /*
  80390. @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
  80391. if (retval)
  80392. goto out;
  80393. }
  80394. +
  80395. +#ifdef CONFIG_PAX_SEGMEXEC
  80396. + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
  80397. + struct vm_area_struct *mpnt_m;
  80398. +
  80399. + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
  80400. + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
  80401. +
  80402. + if (!mpnt->vm_mirror)
  80403. + continue;
  80404. +
  80405. + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
  80406. + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
  80407. + mpnt->vm_mirror = mpnt_m;
  80408. + } else {
  80409. + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
  80410. + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
  80411. + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
  80412. + mpnt->vm_mirror->vm_mirror = mpnt;
  80413. + }
  80414. + }
  80415. + BUG_ON(mpnt_m);
  80416. + }
  80417. +#endif
  80418. +
  80419. /* a new mm has just been created */
  80420. arch_dup_mmap(oldmm, mm);
  80421. retval = 0;
  80422. @@ -468,14 +521,6 @@ out:
  80423. up_write(&oldmm->mmap_sem);
  80424. uprobe_end_dup_mmap();
  80425. return retval;
  80426. -fail_nomem_anon_vma_fork:
  80427. - mpol_put(vma_policy(tmp));
  80428. -fail_nomem_policy:
  80429. - kmem_cache_free(vm_area_cachep, tmp);
  80430. -fail_nomem:
  80431. - retval = -ENOMEM;
  80432. - vm_unacct_memory(charge);
  80433. - goto out;
  80434. }
  80435. static inline int mm_alloc_pgd(struct mm_struct *mm)
  80436. @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
  80437. return ERR_PTR(err);
  80438. mm = get_task_mm(task);
  80439. - if (mm && mm != current->mm &&
  80440. - !ptrace_may_access(task, mode)) {
  80441. + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
  80442. + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
  80443. mmput(mm);
  80444. mm = ERR_PTR(-EACCES);
  80445. }
  80446. @@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
  80447. spin_unlock(&fs->lock);
  80448. return -EAGAIN;
  80449. }
  80450. - fs->users++;
  80451. + atomic_inc(&fs->users);
  80452. spin_unlock(&fs->lock);
  80453. return 0;
  80454. }
  80455. tsk->fs = copy_fs_struct(fs);
  80456. if (!tsk->fs)
  80457. return -ENOMEM;
  80458. + /* Carry through gr_chroot_dentry and is_chrooted instead
  80459. + of recomputing it here. Already copied when the task struct
  80460. + is duplicated. This allows pivot_root to not be treated as
  80461. + a chroot
  80462. + */
  80463. + //gr_set_chroot_entries(tsk, &tsk->fs->root);
  80464. +
  80465. return 0;
  80466. }
  80467. @@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
  80468. * parts of the process environment (as per the clone
  80469. * flags). The actual kick-off is left to the caller.
  80470. */
  80471. -static struct task_struct *copy_process(unsigned long clone_flags,
  80472. +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
  80473. unsigned long stack_start,
  80474. unsigned long stack_size,
  80475. int __user *child_tidptr,
  80476. @@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
  80477. DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
  80478. #endif
  80479. retval = -EAGAIN;
  80480. +
  80481. + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
  80482. +
  80483. if (atomic_read(&p->real_cred->user->processes) >=
  80484. task_rlimit(p, RLIMIT_NPROC)) {
  80485. if (p->real_cred->user != INIT_USER &&
  80486. @@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
  80487. goto bad_fork_free_pid;
  80488. }
  80489. + /* synchronizes with gr_set_acls()
  80490. + we need to call this past the point of no return for fork()
  80491. + */
  80492. + gr_copy_label(p);
  80493. +
  80494. if (likely(p->pid)) {
  80495. ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
  80496. @@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
  80497. bad_fork_free:
  80498. free_task(p);
  80499. fork_out:
  80500. + gr_log_forkfail(retval);
  80501. +
  80502. return ERR_PTR(retval);
  80503. }
  80504. @@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
  80505. p = copy_process(clone_flags, stack_start, stack_size,
  80506. child_tidptr, NULL, trace);
  80507. + add_latent_entropy();
  80508. /*
  80509. * Do this prior waking up the new thread - the thread pointer
  80510. * might get invalid after that point, if the thread exits quickly.
  80511. @@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
  80512. if (clone_flags & CLONE_PARENT_SETTID)
  80513. put_user(nr, parent_tidptr);
  80514. + gr_handle_brute_check();
  80515. +
  80516. if (clone_flags & CLONE_VFORK) {
  80517. p->vfork_done = &vfork;
  80518. init_completion(&vfork);
  80519. @@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
  80520. mm_cachep = kmem_cache_create("mm_struct",
  80521. sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
  80522. SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
  80523. - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
  80524. + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
  80525. mmap_init();
  80526. nsproxy_cache_init();
  80527. }
  80528. @@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
  80529. return 0;
  80530. /* don't need lock here; in the worst case we'll do useless copy */
  80531. - if (fs->users == 1)
  80532. + if (atomic_read(&fs->users) == 1)
  80533. return 0;
  80534. *new_fsp = copy_fs_struct(fs);
  80535. @@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
  80536. fs = current->fs;
  80537. spin_lock(&fs->lock);
  80538. current->fs = new_fs;
  80539. - if (--fs->users)
  80540. + gr_set_chroot_entries(current, &current->fs->root);
  80541. + if (atomic_dec_return(&fs->users))
  80542. new_fs = NULL;
  80543. else
  80544. new_fs = fs;
  80545. diff --git a/kernel/futex.c b/kernel/futex.c
  80546. index 6801b37..bb6becca 100644
  80547. --- a/kernel/futex.c
  80548. +++ b/kernel/futex.c
  80549. @@ -54,6 +54,7 @@
  80550. #include <linux/mount.h>
  80551. #include <linux/pagemap.h>
  80552. #include <linux/syscalls.h>
  80553. +#include <linux/ptrace.h>
  80554. #include <linux/signal.h>
  80555. #include <linux/export.h>
  80556. #include <linux/magic.h>
  80557. @@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
  80558. struct page *page, *page_head;
  80559. int err, ro = 0;
  80560. +#ifdef CONFIG_PAX_SEGMEXEC
  80561. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
  80562. + return -EFAULT;
  80563. +#endif
  80564. +
  80565. /*
  80566. * The futex address must be "naturally" aligned.
  80567. */
  80568. @@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
  80569. static int get_futex_value_locked(u32 *dest, u32 __user *from)
  80570. {
  80571. - int ret;
  80572. + unsigned long ret;
  80573. pagefault_disable();
  80574. ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
  80575. @@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
  80576. {
  80577. #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
  80578. u32 curval;
  80579. + mm_segment_t oldfs;
  80580. /*
  80581. * This will fail and we want it. Some arch implementations do
  80582. @@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
  80583. * implementation, the non-functional ones will return
  80584. * -ENOSYS.
  80585. */
  80586. + oldfs = get_fs();
  80587. + set_fs(USER_DS);
  80588. if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
  80589. futex_cmpxchg_enabled = 1;
  80590. + set_fs(oldfs);
  80591. #endif
  80592. }
  80593. diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
  80594. index f9f44fd..29885e4 100644
  80595. --- a/kernel/futex_compat.c
  80596. +++ b/kernel/futex_compat.c
  80597. @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
  80598. return 0;
  80599. }
  80600. -static void __user *futex_uaddr(struct robust_list __user *entry,
  80601. +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
  80602. compat_long_t futex_offset)
  80603. {
  80604. compat_uptr_t base = ptr_to_compat(entry);
  80605. diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
  80606. index f45b75b..bfac6d5 100644
  80607. --- a/kernel/gcov/base.c
  80608. +++ b/kernel/gcov/base.c
  80609. @@ -108,11 +108,6 @@ void gcov_enable_events(void)
  80610. }
  80611. #ifdef CONFIG_MODULES
  80612. -static inline int within(void *addr, void *start, unsigned long size)
  80613. -{
  80614. - return ((addr >= start) && (addr < start + size));
  80615. -}
  80616. -
  80617. /* Update list and generate events when modules are unloaded. */
  80618. static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
  80619. void *data)
  80620. @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
  80621. /* Remove entries located in module from linked list. */
  80622. while ((info = gcov_info_next(info))) {
  80623. - if (within(info, mod->module_core, mod->core_size)) {
  80624. + if (within_module_core_rw((unsigned long)info, mod)) {
  80625. gcov_info_unlink(prev, info);
  80626. if (gcov_events_enabled)
  80627. gcov_event(GCOV_REMOVE, info);
  80628. diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
  80629. index 0909436..6037d22 100644
  80630. --- a/kernel/hrtimer.c
  80631. +++ b/kernel/hrtimer.c
  80632. @@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
  80633. local_irq_restore(flags);
  80634. }
  80635. -static void run_hrtimer_softirq(struct softirq_action *h)
  80636. +static __latent_entropy void run_hrtimer_softirq(void)
  80637. {
  80638. hrtimer_peek_ahead_timers();
  80639. }
  80640. diff --git a/kernel/irq_work.c b/kernel/irq_work.c
  80641. index 55fcce6..0e4cf34 100644
  80642. --- a/kernel/irq_work.c
  80643. +++ b/kernel/irq_work.c
  80644. @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
  80645. return NOTIFY_OK;
  80646. }
  80647. -static struct notifier_block cpu_notify;
  80648. +static struct notifier_block cpu_notify = {
  80649. + .notifier_call = irq_work_cpu_notify,
  80650. + .priority = 0,
  80651. +};
  80652. static __init int irq_work_init_cpu_notifier(void)
  80653. {
  80654. - cpu_notify.notifier_call = irq_work_cpu_notify;
  80655. - cpu_notify.priority = 0;
  80656. register_cpu_notifier(&cpu_notify);
  80657. return 0;
  80658. }
  80659. diff --git a/kernel/jump_label.c b/kernel/jump_label.c
  80660. index 9019f15..9a3c42e 100644
  80661. --- a/kernel/jump_label.c
  80662. +++ b/kernel/jump_label.c
  80663. @@ -14,6 +14,7 @@
  80664. #include <linux/err.h>
  80665. #include <linux/static_key.h>
  80666. #include <linux/jump_label_ratelimit.h>
  80667. +#include <linux/mm.h>
  80668. #ifdef HAVE_JUMP_LABEL
  80669. @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
  80670. size = (((unsigned long)stop - (unsigned long)start)
  80671. / sizeof(struct jump_entry));
  80672. + pax_open_kernel();
  80673. sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
  80674. + pax_close_kernel();
  80675. }
  80676. static void jump_label_update(struct static_key *key, int enable);
  80677. @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
  80678. struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
  80679. struct jump_entry *iter;
  80680. + pax_open_kernel();
  80681. for (iter = iter_start; iter < iter_stop; iter++) {
  80682. if (within_module_init(iter->code, mod))
  80683. iter->code = 0;
  80684. }
  80685. + pax_close_kernel();
  80686. }
  80687. static int
  80688. diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
  80689. index 3127ad5..159d880 100644
  80690. --- a/kernel/kallsyms.c
  80691. +++ b/kernel/kallsyms.c
  80692. @@ -11,6 +11,9 @@
  80693. * Changed the compression method from stem compression to "table lookup"
  80694. * compression (see scripts/kallsyms.c for a more complete description)
  80695. */
  80696. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  80697. +#define __INCLUDED_BY_HIDESYM 1
  80698. +#endif
  80699. #include <linux/kallsyms.h>
  80700. #include <linux/module.h>
  80701. #include <linux/init.h>
  80702. @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
  80703. static inline int is_kernel_inittext(unsigned long addr)
  80704. {
  80705. + if (system_state != SYSTEM_BOOTING)
  80706. + return 0;
  80707. +
  80708. if (addr >= (unsigned long)_sinittext
  80709. && addr <= (unsigned long)_einittext)
  80710. return 1;
  80711. return 0;
  80712. }
  80713. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  80714. +#ifdef CONFIG_MODULES
  80715. +static inline int is_module_text(unsigned long addr)
  80716. +{
  80717. + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
  80718. + return 1;
  80719. +
  80720. + addr = ktla_ktva(addr);
  80721. + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
  80722. +}
  80723. +#else
  80724. +static inline int is_module_text(unsigned long addr)
  80725. +{
  80726. + return 0;
  80727. +}
  80728. +#endif
  80729. +#endif
  80730. +
  80731. static inline int is_kernel_text(unsigned long addr)
  80732. {
  80733. if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
  80734. @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
  80735. static inline int is_kernel(unsigned long addr)
  80736. {
  80737. +
  80738. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  80739. + if (is_kernel_text(addr) || is_kernel_inittext(addr))
  80740. + return 1;
  80741. +
  80742. + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
  80743. +#else
  80744. if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
  80745. +#endif
  80746. +
  80747. return 1;
  80748. return in_gate_area_no_mm(addr);
  80749. }
  80750. static int is_ksym_addr(unsigned long addr)
  80751. {
  80752. +
  80753. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  80754. + if (is_module_text(addr))
  80755. + return 0;
  80756. +#endif
  80757. +
  80758. if (all_var)
  80759. return is_kernel(addr);
  80760. @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
  80761. static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
  80762. {
  80763. - iter->name[0] = '\0';
  80764. iter->nameoff = get_symbol_offset(new_pos);
  80765. iter->pos = new_pos;
  80766. }
  80767. @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
  80768. {
  80769. struct kallsym_iter *iter = m->private;
  80770. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  80771. + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
  80772. + return 0;
  80773. +#endif
  80774. +
  80775. /* Some debugging symbols have no name. Ignore them. */
  80776. if (!iter->name[0])
  80777. return 0;
  80778. @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
  80779. */
  80780. type = iter->exported ? toupper(iter->type) :
  80781. tolower(iter->type);
  80782. +
  80783. seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
  80784. type, iter->name, iter->module_name);
  80785. } else
  80786. @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
  80787. struct kallsym_iter *iter;
  80788. int ret;
  80789. - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
  80790. + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  80791. if (!iter)
  80792. return -ENOMEM;
  80793. reset_iter(iter, 0);
  80794. diff --git a/kernel/kcmp.c b/kernel/kcmp.c
  80795. index e30ac0f..3528cac 100644
  80796. --- a/kernel/kcmp.c
  80797. +++ b/kernel/kcmp.c
  80798. @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
  80799. struct task_struct *task1, *task2;
  80800. int ret;
  80801. +#ifdef CONFIG_GRKERNSEC
  80802. + return -ENOSYS;
  80803. +#endif
  80804. +
  80805. rcu_read_lock();
  80806. /*
  80807. diff --git a/kernel/kexec.c b/kernel/kexec.c
  80808. index 60bafbe..a120f4f 100644
  80809. --- a/kernel/kexec.c
  80810. +++ b/kernel/kexec.c
  80811. @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
  80812. unsigned long flags)
  80813. {
  80814. struct compat_kexec_segment in;
  80815. - struct kexec_segment out, __user *ksegments;
  80816. + struct kexec_segment out;
  80817. + struct kexec_segment __user *ksegments;
  80818. unsigned long i, result;
  80819. /* Don't allow clients that don't understand the native
  80820. diff --git a/kernel/kmod.c b/kernel/kmod.c
  80821. index 6b375af..eaff670 100644
  80822. --- a/kernel/kmod.c
  80823. +++ b/kernel/kmod.c
  80824. @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
  80825. kfree(info->argv);
  80826. }
  80827. -static int call_modprobe(char *module_name, int wait)
  80828. +static int call_modprobe(char *module_name, char *module_param, int wait)
  80829. {
  80830. struct subprocess_info *info;
  80831. static char *envp[] = {
  80832. @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
  80833. NULL
  80834. };
  80835. - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
  80836. + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
  80837. if (!argv)
  80838. goto out;
  80839. @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
  80840. argv[1] = "-q";
  80841. argv[2] = "--";
  80842. argv[3] = module_name; /* check free_modprobe_argv() */
  80843. - argv[4] = NULL;
  80844. + argv[4] = module_param;
  80845. + argv[5] = NULL;
  80846. info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
  80847. NULL, free_modprobe_argv, NULL);
  80848. @@ -129,9 +130,8 @@ out:
  80849. * If module auto-loading support is disabled then this function
  80850. * becomes a no-operation.
  80851. */
  80852. -int __request_module(bool wait, const char *fmt, ...)
  80853. +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
  80854. {
  80855. - va_list args;
  80856. char module_name[MODULE_NAME_LEN];
  80857. unsigned int max_modprobes;
  80858. int ret;
  80859. @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
  80860. if (!modprobe_path[0])
  80861. return 0;
  80862. - va_start(args, fmt);
  80863. - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
  80864. - va_end(args);
  80865. + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
  80866. if (ret >= MODULE_NAME_LEN)
  80867. return -ENAMETOOLONG;
  80868. @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
  80869. if (ret)
  80870. return ret;
  80871. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  80872. + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
  80873. + /* hack to workaround consolekit/udisks stupidity */
  80874. + read_lock(&tasklist_lock);
  80875. + if (!strcmp(current->comm, "mount") &&
  80876. + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
  80877. + read_unlock(&tasklist_lock);
  80878. + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
  80879. + return -EPERM;
  80880. + }
  80881. + read_unlock(&tasklist_lock);
  80882. + }
  80883. +#endif
  80884. +
  80885. /* If modprobe needs a service that is in a module, we get a recursive
  80886. * loop. Limit the number of running kmod threads to max_threads/2 or
  80887. * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
  80888. @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
  80889. trace_module_request(module_name, wait, _RET_IP_);
  80890. - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
  80891. + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
  80892. atomic_dec(&kmod_concurrent);
  80893. return ret;
  80894. }
  80895. +
  80896. +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
  80897. +{
  80898. + va_list args;
  80899. + int ret;
  80900. +
  80901. + va_start(args, fmt);
  80902. + ret = ____request_module(wait, module_param, fmt, args);
  80903. + va_end(args);
  80904. +
  80905. + return ret;
  80906. +}
  80907. +
  80908. +int __request_module(bool wait, const char *fmt, ...)
  80909. +{
  80910. + va_list args;
  80911. + int ret;
  80912. +
  80913. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  80914. + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
  80915. + char module_param[MODULE_NAME_LEN];
  80916. +
  80917. + memset(module_param, 0, sizeof(module_param));
  80918. +
  80919. + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
  80920. +
  80921. + va_start(args, fmt);
  80922. + ret = ____request_module(wait, module_param, fmt, args);
  80923. + va_end(args);
  80924. +
  80925. + return ret;
  80926. + }
  80927. +#endif
  80928. +
  80929. + va_start(args, fmt);
  80930. + ret = ____request_module(wait, NULL, fmt, args);
  80931. + va_end(args);
  80932. +
  80933. + return ret;
  80934. +}
  80935. +
  80936. EXPORT_SYMBOL(__request_module);
  80937. #endif /* CONFIG_MODULES */
  80938. @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
  80939. */
  80940. set_user_nice(current, 0);
  80941. +#ifdef CONFIG_GRKERNSEC
  80942. + /* this is race-free as far as userland is concerned as we copied
  80943. + out the path to be used prior to this point and are now operating
  80944. + on that copy
  80945. + */
  80946. + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
  80947. + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
  80948. + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
  80949. + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
  80950. + retval = -EPERM;
  80951. + goto fail;
  80952. + }
  80953. +#endif
  80954. +
  80955. retval = -ENOMEM;
  80956. new = prepare_kernel_cred(current);
  80957. if (!new)
  80958. @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
  80959. commit_creds(new);
  80960. retval = do_execve(getname_kernel(sub_info->path),
  80961. - (const char __user *const __user *)sub_info->argv,
  80962. - (const char __user *const __user *)sub_info->envp);
  80963. + (const char __user *const __force_user *)sub_info->argv,
  80964. + (const char __user *const __force_user *)sub_info->envp);
  80965. if (!retval)
  80966. return 0;
  80967. @@ -260,6 +327,10 @@ static int call_helper(void *data)
  80968. static void call_usermodehelper_freeinfo(struct subprocess_info *info)
  80969. {
  80970. +#ifdef CONFIG_GRKERNSEC
  80971. + kfree(info->path);
  80972. + info->path = info->origpath;
  80973. +#endif
  80974. if (info->cleanup)
  80975. (*info->cleanup)(info);
  80976. kfree(info);
  80977. @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
  80978. *
  80979. * Thus the __user pointer cast is valid here.
  80980. */
  80981. - sys_wait4(pid, (int __user *)&ret, 0, NULL);
  80982. + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
  80983. /*
  80984. * If ret is 0, either ____call_usermodehelper failed and the
  80985. @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
  80986. goto out;
  80987. INIT_WORK(&sub_info->work, __call_usermodehelper);
  80988. +#ifdef CONFIG_GRKERNSEC
  80989. + sub_info->origpath = path;
  80990. + sub_info->path = kstrdup(path, gfp_mask);
  80991. +#else
  80992. sub_info->path = path;
  80993. +#endif
  80994. sub_info->argv = argv;
  80995. sub_info->envp = envp;
  80996. @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
  80997. static int proc_cap_handler(struct ctl_table *table, int write,
  80998. void __user *buffer, size_t *lenp, loff_t *ppos)
  80999. {
  81000. - struct ctl_table t;
  81001. + ctl_table_no_const t;
  81002. unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
  81003. kernel_cap_t new_cap;
  81004. int err, i;
  81005. diff --git a/kernel/kprobes.c b/kernel/kprobes.c
  81006. index ceeadfc..11c18b6 100644
  81007. --- a/kernel/kprobes.c
  81008. +++ b/kernel/kprobes.c
  81009. @@ -31,6 +31,9 @@
  81010. * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
  81011. * <prasanna@in.ibm.com> added function-return probes.
  81012. */
  81013. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  81014. +#define __INCLUDED_BY_HIDESYM 1
  81015. +#endif
  81016. #include <linux/kprobes.h>
  81017. #include <linux/hash.h>
  81018. #include <linux/init.h>
  81019. @@ -135,12 +138,12 @@ enum kprobe_slot_state {
  81020. static void *alloc_insn_page(void)
  81021. {
  81022. - return module_alloc(PAGE_SIZE);
  81023. + return module_alloc_exec(PAGE_SIZE);
  81024. }
  81025. static void free_insn_page(void *page)
  81026. {
  81027. - module_free(NULL, page);
  81028. + module_free_exec(NULL, page);
  81029. }
  81030. struct kprobe_insn_cache kprobe_insn_slots = {
  81031. @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
  81032. kprobe_type = "k";
  81033. if (sym)
  81034. - seq_printf(pi, "%p %s %s+0x%x %s ",
  81035. + seq_printf(pi, "%pK %s %s+0x%x %s ",
  81036. p->addr, kprobe_type, sym, offset,
  81037. (modname ? modname : " "));
  81038. else
  81039. - seq_printf(pi, "%p %s %p ",
  81040. + seq_printf(pi, "%pK %s %pK ",
  81041. p->addr, kprobe_type, p->addr);
  81042. if (!pp)
  81043. diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
  81044. index d945a94..0b7f45f 100644
  81045. --- a/kernel/ksysfs.c
  81046. +++ b/kernel/ksysfs.c
  81047. @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
  81048. {
  81049. if (count+1 > UEVENT_HELPER_PATH_LEN)
  81050. return -ENOENT;
  81051. + if (!capable(CAP_SYS_ADMIN))
  81052. + return -EPERM;
  81053. memcpy(uevent_helper, buf, count);
  81054. uevent_helper[count] = '\0';
  81055. if (count && uevent_helper[count-1] == '\n')
  81056. @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
  81057. return count;
  81058. }
  81059. -static struct bin_attribute notes_attr = {
  81060. +static bin_attribute_no_const notes_attr __read_only = {
  81061. .attr = {
  81062. .name = "notes",
  81063. .mode = S_IRUGO,
  81064. diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
  81065. index eb8a547..321d8e1 100644
  81066. --- a/kernel/locking/lockdep.c
  81067. +++ b/kernel/locking/lockdep.c
  81068. @@ -597,6 +597,10 @@ static int static_obj(void *obj)
  81069. end = (unsigned long) &_end,
  81070. addr = (unsigned long) obj;
  81071. +#ifdef CONFIG_PAX_KERNEXEC
  81072. + start = ktla_ktva(start);
  81073. +#endif
  81074. +
  81075. /*
  81076. * static variable?
  81077. */
  81078. @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
  81079. if (!static_obj(lock->key)) {
  81080. debug_locks_off();
  81081. printk("INFO: trying to register non-static key.\n");
  81082. + printk("lock:%pS key:%pS.\n", lock, lock->key);
  81083. printk("the code is fine but needs lockdep annotation.\n");
  81084. printk("turning off the locking correctness validator.\n");
  81085. dump_stack();
  81086. @@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
  81087. if (!class)
  81088. return 0;
  81089. }
  81090. - atomic_inc((atomic_t *)&class->ops);
  81091. + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
  81092. if (very_verbose(class)) {
  81093. printk("\nacquire class [%p] %s", class->key, class->name);
  81094. if (class->name_version > 1)
  81095. diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
  81096. index ef43ac4..2720dfa 100644
  81097. --- a/kernel/locking/lockdep_proc.c
  81098. +++ b/kernel/locking/lockdep_proc.c
  81099. @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
  81100. return 0;
  81101. }
  81102. - seq_printf(m, "%p", class->key);
  81103. + seq_printf(m, "%pK", class->key);
  81104. #ifdef CONFIG_DEBUG_LOCKDEP
  81105. seq_printf(m, " OPS:%8ld", class->ops);
  81106. #endif
  81107. @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
  81108. list_for_each_entry(entry, &class->locks_after, entry) {
  81109. if (entry->distance == 1) {
  81110. - seq_printf(m, " -> [%p] ", entry->class->key);
  81111. + seq_printf(m, " -> [%pK] ", entry->class->key);
  81112. print_name(m, entry->class);
  81113. seq_puts(m, "\n");
  81114. }
  81115. @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
  81116. if (!class->key)
  81117. continue;
  81118. - seq_printf(m, "[%p] ", class->key);
  81119. + seq_printf(m, "[%pK] ", class->key);
  81120. print_name(m, class);
  81121. seq_puts(m, "\n");
  81122. }
  81123. @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
  81124. if (!i)
  81125. seq_line(m, '-', 40-namelen, namelen);
  81126. - snprintf(ip, sizeof(ip), "[<%p>]",
  81127. + snprintf(ip, sizeof(ip), "[<%pK>]",
  81128. (void *)class->contention_point[i]);
  81129. seq_printf(m, "%40s %14lu %29s %pS\n",
  81130. name, stats->contention_point[i],
  81131. @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
  81132. if (!i)
  81133. seq_line(m, '-', 40-namelen, namelen);
  81134. - snprintf(ip, sizeof(ip), "[<%p>]",
  81135. + snprintf(ip, sizeof(ip), "[<%pK>]",
  81136. (void *)class->contending_point[i]);
  81137. seq_printf(m, "%40s %14lu %29s %pS\n",
  81138. name, stats->contending_point[i],
  81139. diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
  81140. index faf6f5b..dc9070a 100644
  81141. --- a/kernel/locking/mutex-debug.c
  81142. +++ b/kernel/locking/mutex-debug.c
  81143. @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
  81144. }
  81145. void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
  81146. - struct thread_info *ti)
  81147. + struct task_struct *task)
  81148. {
  81149. SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
  81150. /* Mark the current thread as blocked on the lock: */
  81151. - ti->task->blocked_on = waiter;
  81152. + task->blocked_on = waiter;
  81153. }
  81154. void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
  81155. - struct thread_info *ti)
  81156. + struct task_struct *task)
  81157. {
  81158. DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
  81159. - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
  81160. - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
  81161. - ti->task->blocked_on = NULL;
  81162. + DEBUG_LOCKS_WARN_ON(waiter->task != task);
  81163. + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
  81164. + task->blocked_on = NULL;
  81165. list_del_init(&waiter->list);
  81166. waiter->task = NULL;
  81167. diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
  81168. index 0799fd3..d06ae3b 100644
  81169. --- a/kernel/locking/mutex-debug.h
  81170. +++ b/kernel/locking/mutex-debug.h
  81171. @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
  81172. extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
  81173. extern void debug_mutex_add_waiter(struct mutex *lock,
  81174. struct mutex_waiter *waiter,
  81175. - struct thread_info *ti);
  81176. + struct task_struct *task);
  81177. extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
  81178. - struct thread_info *ti);
  81179. + struct task_struct *task);
  81180. extern void debug_mutex_unlock(struct mutex *lock);
  81181. extern void debug_mutex_init(struct mutex *lock, const char *name,
  81182. struct lock_class_key *key);
  81183. diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
  81184. index 4dd6e4c..df52693 100644
  81185. --- a/kernel/locking/mutex.c
  81186. +++ b/kernel/locking/mutex.c
  81187. @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
  81188. node->locked = 1;
  81189. return;
  81190. }
  81191. - ACCESS_ONCE(prev->next) = node;
  81192. + ACCESS_ONCE_RW(prev->next) = node;
  81193. smp_wmb();
  81194. /* Wait until the lock holder passes the lock down */
  81195. while (!ACCESS_ONCE(node->locked))
  81196. @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
  81197. while (!(next = ACCESS_ONCE(node->next)))
  81198. arch_mutex_cpu_relax();
  81199. }
  81200. - ACCESS_ONCE(next->locked) = 1;
  81201. + ACCESS_ONCE_RW(next->locked) = 1;
  81202. smp_wmb();
  81203. }
  81204. @@ -520,7 +520,7 @@ slowpath:
  81205. goto skip_wait;
  81206. debug_mutex_lock_common(lock, &waiter);
  81207. - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
  81208. + debug_mutex_add_waiter(lock, &waiter, task);
  81209. /* add waiting tasks to the end of the waitqueue (FIFO): */
  81210. list_add_tail(&waiter.list, &lock->wait_list);
  81211. @@ -564,7 +564,7 @@ slowpath:
  81212. schedule_preempt_disabled();
  81213. spin_lock_mutex(&lock->wait_lock, flags);
  81214. }
  81215. - mutex_remove_waiter(lock, &waiter, current_thread_info());
  81216. + mutex_remove_waiter(lock, &waiter, task);
  81217. /* set it to 0 if there are no waiters left: */
  81218. if (likely(list_empty(&lock->wait_list)))
  81219. atomic_set(&lock->count, 0);
  81220. @@ -601,7 +601,7 @@ skip_wait:
  81221. return 0;
  81222. err:
  81223. - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
  81224. + mutex_remove_waiter(lock, &waiter, task);
  81225. spin_unlock_mutex(&lock->wait_lock, flags);
  81226. debug_mutex_free_waiter(&waiter);
  81227. mutex_release(&lock->dep_map, 1, ip);
  81228. diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
  81229. index 1d96dd0..994ff19 100644
  81230. --- a/kernel/locking/rtmutex-tester.c
  81231. +++ b/kernel/locking/rtmutex-tester.c
  81232. @@ -22,7 +22,7 @@
  81233. #define MAX_RT_TEST_MUTEXES 8
  81234. static spinlock_t rttest_lock;
  81235. -static atomic_t rttest_event;
  81236. +static atomic_unchecked_t rttest_event;
  81237. struct test_thread_data {
  81238. int opcode;
  81239. @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
  81240. case RTTEST_LOCKCONT:
  81241. td->mutexes[td->opdata] = 1;
  81242. - td->event = atomic_add_return(1, &rttest_event);
  81243. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81244. return 0;
  81245. case RTTEST_RESET:
  81246. @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
  81247. return 0;
  81248. case RTTEST_RESETEVENT:
  81249. - atomic_set(&rttest_event, 0);
  81250. + atomic_set_unchecked(&rttest_event, 0);
  81251. return 0;
  81252. default:
  81253. @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
  81254. return ret;
  81255. td->mutexes[id] = 1;
  81256. - td->event = atomic_add_return(1, &rttest_event);
  81257. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81258. rt_mutex_lock(&mutexes[id]);
  81259. - td->event = atomic_add_return(1, &rttest_event);
  81260. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81261. td->mutexes[id] = 4;
  81262. return 0;
  81263. @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
  81264. return ret;
  81265. td->mutexes[id] = 1;
  81266. - td->event = atomic_add_return(1, &rttest_event);
  81267. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81268. ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
  81269. - td->event = atomic_add_return(1, &rttest_event);
  81270. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81271. td->mutexes[id] = ret ? 0 : 4;
  81272. return ret ? -EINTR : 0;
  81273. @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
  81274. if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
  81275. return ret;
  81276. - td->event = atomic_add_return(1, &rttest_event);
  81277. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81278. rt_mutex_unlock(&mutexes[id]);
  81279. - td->event = atomic_add_return(1, &rttest_event);
  81280. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81281. td->mutexes[id] = 0;
  81282. return 0;
  81283. @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
  81284. break;
  81285. td->mutexes[dat] = 2;
  81286. - td->event = atomic_add_return(1, &rttest_event);
  81287. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81288. break;
  81289. default:
  81290. @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
  81291. return;
  81292. td->mutexes[dat] = 3;
  81293. - td->event = atomic_add_return(1, &rttest_event);
  81294. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81295. break;
  81296. case RTTEST_LOCKNOWAIT:
  81297. @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
  81298. return;
  81299. td->mutexes[dat] = 1;
  81300. - td->event = atomic_add_return(1, &rttest_event);
  81301. + td->event = atomic_add_return_unchecked(1, &rttest_event);
  81302. return;
  81303. default:
  81304. diff --git a/kernel/module.c b/kernel/module.c
  81305. index d24fcf2..2af3fd9 100644
  81306. --- a/kernel/module.c
  81307. +++ b/kernel/module.c
  81308. @@ -61,6 +61,7 @@
  81309. #include <linux/pfn.h>
  81310. #include <linux/bsearch.h>
  81311. #include <linux/fips.h>
  81312. +#include <linux/grsecurity.h>
  81313. #include <uapi/linux/module.h>
  81314. #include "module-internal.h"
  81315. @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
  81316. /* Bounds of module allocation, for speeding __module_address.
  81317. * Protected by module_mutex. */
  81318. -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
  81319. +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
  81320. +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
  81321. int register_module_notifier(struct notifier_block * nb)
  81322. {
  81323. @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
  81324. return true;
  81325. list_for_each_entry_rcu(mod, &modules, list) {
  81326. - struct symsearch arr[] = {
  81327. + struct symsearch modarr[] = {
  81328. { mod->syms, mod->syms + mod->num_syms, mod->crcs,
  81329. NOT_GPL_ONLY, false },
  81330. { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
  81331. @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
  81332. if (mod->state == MODULE_STATE_UNFORMED)
  81333. continue;
  81334. - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
  81335. + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
  81336. return true;
  81337. }
  81338. return false;
  81339. @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
  81340. if (!pcpusec->sh_size)
  81341. return 0;
  81342. - if (align > PAGE_SIZE) {
  81343. + if (align-1 >= PAGE_SIZE) {
  81344. pr_warn("%s: per-cpu alignment %li > %li\n",
  81345. mod->name, align, PAGE_SIZE);
  81346. align = PAGE_SIZE;
  81347. @@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
  81348. static ssize_t show_coresize(struct module_attribute *mattr,
  81349. struct module_kobject *mk, char *buffer)
  81350. {
  81351. - return sprintf(buffer, "%u\n", mk->mod->core_size);
  81352. + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
  81353. }
  81354. static struct module_attribute modinfo_coresize =
  81355. @@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
  81356. static ssize_t show_initsize(struct module_attribute *mattr,
  81357. struct module_kobject *mk, char *buffer)
  81358. {
  81359. - return sprintf(buffer, "%u\n", mk->mod->init_size);
  81360. + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
  81361. }
  81362. static struct module_attribute modinfo_initsize =
  81363. @@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
  81364. goto bad_version;
  81365. }
  81366. +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
  81367. + /*
  81368. + * avoid potentially printing jibberish on attempted load
  81369. + * of a module randomized with a different seed
  81370. + */
  81371. + pr_warn("no symbol version for %s\n", symname);
  81372. +#else
  81373. pr_warn("%s: no symbol version for %s\n", mod->name, symname);
  81374. +#endif
  81375. return 0;
  81376. bad_version:
  81377. +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
  81378. + /*
  81379. + * avoid potentially printing jibberish on attempted load
  81380. + * of a module randomized with a different seed
  81381. + */
  81382. + printk("attempted module disagrees about version of symbol %s\n",
  81383. + symname);
  81384. +#else
  81385. printk("%s: disagrees about version of symbol %s\n",
  81386. mod->name, symname);
  81387. +#endif
  81388. return 0;
  81389. }
  81390. @@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
  81391. */
  81392. #ifdef CONFIG_SYSFS
  81393. -#ifdef CONFIG_KALLSYMS
  81394. +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
  81395. static inline bool sect_empty(const Elf_Shdr *sect)
  81396. {
  81397. return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
  81398. @@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
  81399. {
  81400. unsigned int notes, loaded, i;
  81401. struct module_notes_attrs *notes_attrs;
  81402. - struct bin_attribute *nattr;
  81403. + bin_attribute_no_const *nattr;
  81404. /* failed to create section attributes, so can't create notes */
  81405. if (!mod->sect_attrs)
  81406. @@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
  81407. static int module_add_modinfo_attrs(struct module *mod)
  81408. {
  81409. struct module_attribute *attr;
  81410. - struct module_attribute *temp_attr;
  81411. + module_attribute_no_const *temp_attr;
  81412. int error = 0;
  81413. int i;
  81414. @@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
  81415. static void unset_module_core_ro_nx(struct module *mod)
  81416. {
  81417. - set_page_attributes(mod->module_core + mod->core_text_size,
  81418. - mod->module_core + mod->core_size,
  81419. + set_page_attributes(mod->module_core_rw,
  81420. + mod->module_core_rw + mod->core_size_rw,
  81421. set_memory_x);
  81422. - set_page_attributes(mod->module_core,
  81423. - mod->module_core + mod->core_ro_size,
  81424. + set_page_attributes(mod->module_core_rx,
  81425. + mod->module_core_rx + mod->core_size_rx,
  81426. set_memory_rw);
  81427. }
  81428. static void unset_module_init_ro_nx(struct module *mod)
  81429. {
  81430. - set_page_attributes(mod->module_init + mod->init_text_size,
  81431. - mod->module_init + mod->init_size,
  81432. + set_page_attributes(mod->module_init_rw,
  81433. + mod->module_init_rw + mod->init_size_rw,
  81434. set_memory_x);
  81435. - set_page_attributes(mod->module_init,
  81436. - mod->module_init + mod->init_ro_size,
  81437. + set_page_attributes(mod->module_init_rx,
  81438. + mod->module_init_rx + mod->init_size_rx,
  81439. set_memory_rw);
  81440. }
  81441. @@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
  81442. list_for_each_entry_rcu(mod, &modules, list) {
  81443. if (mod->state == MODULE_STATE_UNFORMED)
  81444. continue;
  81445. - if ((mod->module_core) && (mod->core_text_size)) {
  81446. - set_page_attributes(mod->module_core,
  81447. - mod->module_core + mod->core_text_size,
  81448. + if ((mod->module_core_rx) && (mod->core_size_rx)) {
  81449. + set_page_attributes(mod->module_core_rx,
  81450. + mod->module_core_rx + mod->core_size_rx,
  81451. set_memory_rw);
  81452. }
  81453. - if ((mod->module_init) && (mod->init_text_size)) {
  81454. - set_page_attributes(mod->module_init,
  81455. - mod->module_init + mod->init_text_size,
  81456. + if ((mod->module_init_rx) && (mod->init_size_rx)) {
  81457. + set_page_attributes(mod->module_init_rx,
  81458. + mod->module_init_rx + mod->init_size_rx,
  81459. set_memory_rw);
  81460. }
  81461. }
  81462. @@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
  81463. list_for_each_entry_rcu(mod, &modules, list) {
  81464. if (mod->state == MODULE_STATE_UNFORMED)
  81465. continue;
  81466. - if ((mod->module_core) && (mod->core_text_size)) {
  81467. - set_page_attributes(mod->module_core,
  81468. - mod->module_core + mod->core_text_size,
  81469. + if ((mod->module_core_rx) && (mod->core_size_rx)) {
  81470. + set_page_attributes(mod->module_core_rx,
  81471. + mod->module_core_rx + mod->core_size_rx,
  81472. set_memory_ro);
  81473. }
  81474. - if ((mod->module_init) && (mod->init_text_size)) {
  81475. - set_page_attributes(mod->module_init,
  81476. - mod->module_init + mod->init_text_size,
  81477. + if ((mod->module_init_rx) && (mod->init_size_rx)) {
  81478. + set_page_attributes(mod->module_init_rx,
  81479. + mod->module_init_rx + mod->init_size_rx,
  81480. set_memory_ro);
  81481. }
  81482. }
  81483. @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
  81484. /* This may be NULL, but that's OK */
  81485. unset_module_init_ro_nx(mod);
  81486. - module_free(mod, mod->module_init);
  81487. + module_free(mod, mod->module_init_rw);
  81488. + module_free_exec(mod, mod->module_init_rx);
  81489. kfree(mod->args);
  81490. percpu_modfree(mod);
  81491. /* Free lock-classes: */
  81492. - lockdep_free_key_range(mod->module_core, mod->core_size);
  81493. + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
  81494. + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
  81495. /* Finally, free the core (containing the module structure) */
  81496. unset_module_core_ro_nx(mod);
  81497. - module_free(mod, mod->module_core);
  81498. + module_free_exec(mod, mod->module_core_rx);
  81499. + module_free(mod, mod->module_core_rw);
  81500. #ifdef CONFIG_MPU
  81501. update_protections(current->mm);
  81502. @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
  81503. int ret = 0;
  81504. const struct kernel_symbol *ksym;
  81505. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  81506. + int is_fs_load = 0;
  81507. + int register_filesystem_found = 0;
  81508. + char *p;
  81509. +
  81510. + p = strstr(mod->args, "grsec_modharden_fs");
  81511. + if (p) {
  81512. + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
  81513. + /* copy \0 as well */
  81514. + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
  81515. + is_fs_load = 1;
  81516. + }
  81517. +#endif
  81518. +
  81519. for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
  81520. const char *name = info->strtab + sym[i].st_name;
  81521. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  81522. + /* it's a real shame this will never get ripped and copied
  81523. + upstream! ;(
  81524. + */
  81525. + if (is_fs_load && !strcmp(name, "register_filesystem"))
  81526. + register_filesystem_found = 1;
  81527. +#endif
  81528. +
  81529. switch (sym[i].st_shndx) {
  81530. case SHN_COMMON:
  81531. /* We compiled with -fno-common. These are not
  81532. @@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
  81533. ksym = resolve_symbol_wait(mod, info, name);
  81534. /* Ok if resolved. */
  81535. if (ksym && !IS_ERR(ksym)) {
  81536. + pax_open_kernel();
  81537. sym[i].st_value = ksym->value;
  81538. + pax_close_kernel();
  81539. break;
  81540. }
  81541. @@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
  81542. secbase = (unsigned long)mod_percpu(mod);
  81543. else
  81544. secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
  81545. + pax_open_kernel();
  81546. sym[i].st_value += secbase;
  81547. + pax_close_kernel();
  81548. break;
  81549. }
  81550. }
  81551. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  81552. + if (is_fs_load && !register_filesystem_found) {
  81553. + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
  81554. + ret = -EPERM;
  81555. + }
  81556. +#endif
  81557. +
  81558. return ret;
  81559. }
  81560. @@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
  81561. || s->sh_entsize != ~0UL
  81562. || strstarts(sname, ".init"))
  81563. continue;
  81564. - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
  81565. + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
  81566. + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
  81567. + else
  81568. + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
  81569. pr_debug("\t%s\n", sname);
  81570. }
  81571. - switch (m) {
  81572. - case 0: /* executable */
  81573. - mod->core_size = debug_align(mod->core_size);
  81574. - mod->core_text_size = mod->core_size;
  81575. - break;
  81576. - case 1: /* RO: text and ro-data */
  81577. - mod->core_size = debug_align(mod->core_size);
  81578. - mod->core_ro_size = mod->core_size;
  81579. - break;
  81580. - case 3: /* whole core */
  81581. - mod->core_size = debug_align(mod->core_size);
  81582. - break;
  81583. - }
  81584. }
  81585. pr_debug("Init section allocation order:\n");
  81586. @@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
  81587. || s->sh_entsize != ~0UL
  81588. || !strstarts(sname, ".init"))
  81589. continue;
  81590. - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
  81591. - | INIT_OFFSET_MASK);
  81592. + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
  81593. + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
  81594. + else
  81595. + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
  81596. + s->sh_entsize |= INIT_OFFSET_MASK;
  81597. pr_debug("\t%s\n", sname);
  81598. }
  81599. - switch (m) {
  81600. - case 0: /* executable */
  81601. - mod->init_size = debug_align(mod->init_size);
  81602. - mod->init_text_size = mod->init_size;
  81603. - break;
  81604. - case 1: /* RO: text and ro-data */
  81605. - mod->init_size = debug_align(mod->init_size);
  81606. - mod->init_ro_size = mod->init_size;
  81607. - break;
  81608. - case 3: /* whole init */
  81609. - mod->init_size = debug_align(mod->init_size);
  81610. - break;
  81611. - }
  81612. }
  81613. }
  81614. @@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
  81615. /* Put symbol section at end of init part of module. */
  81616. symsect->sh_flags |= SHF_ALLOC;
  81617. - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
  81618. + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
  81619. info->index.sym) | INIT_OFFSET_MASK;
  81620. pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
  81621. @@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
  81622. }
  81623. /* Append room for core symbols at end of core part. */
  81624. - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
  81625. - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
  81626. - mod->core_size += strtab_size;
  81627. + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
  81628. + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
  81629. + mod->core_size_rx += strtab_size;
  81630. /* Put string table section at end of init part of module. */
  81631. strsect->sh_flags |= SHF_ALLOC;
  81632. - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
  81633. + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
  81634. info->index.str) | INIT_OFFSET_MASK;
  81635. pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
  81636. }
  81637. @@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
  81638. /* Make sure we get permanent strtab: don't use info->strtab. */
  81639. mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
  81640. + pax_open_kernel();
  81641. +
  81642. /* Set types up while we still have access to sections. */
  81643. for (i = 0; i < mod->num_symtab; i++)
  81644. mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
  81645. - mod->core_symtab = dst = mod->module_core + info->symoffs;
  81646. - mod->core_strtab = s = mod->module_core + info->stroffs;
  81647. + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
  81648. + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
  81649. src = mod->symtab;
  81650. for (ndst = i = 0; i < mod->num_symtab; i++) {
  81651. if (i == 0 ||
  81652. @@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
  81653. }
  81654. }
  81655. mod->core_num_syms = ndst;
  81656. +
  81657. + pax_close_kernel();
  81658. }
  81659. #else
  81660. static inline void layout_symtab(struct module *mod, struct load_info *info)
  81661. @@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
  81662. return vmalloc_exec(size);
  81663. }
  81664. -static void *module_alloc_update_bounds(unsigned long size)
  81665. +static void *module_alloc_update_bounds_rw(unsigned long size)
  81666. {
  81667. void *ret = module_alloc(size);
  81668. if (ret) {
  81669. mutex_lock(&module_mutex);
  81670. /* Update module bounds. */
  81671. - if ((unsigned long)ret < module_addr_min)
  81672. - module_addr_min = (unsigned long)ret;
  81673. - if ((unsigned long)ret + size > module_addr_max)
  81674. - module_addr_max = (unsigned long)ret + size;
  81675. + if ((unsigned long)ret < module_addr_min_rw)
  81676. + module_addr_min_rw = (unsigned long)ret;
  81677. + if ((unsigned long)ret + size > module_addr_max_rw)
  81678. + module_addr_max_rw = (unsigned long)ret + size;
  81679. + mutex_unlock(&module_mutex);
  81680. + }
  81681. + return ret;
  81682. +}
  81683. +
  81684. +static void *module_alloc_update_bounds_rx(unsigned long size)
  81685. +{
  81686. + void *ret = module_alloc_exec(size);
  81687. +
  81688. + if (ret) {
  81689. + mutex_lock(&module_mutex);
  81690. + /* Update module bounds. */
  81691. + if ((unsigned long)ret < module_addr_min_rx)
  81692. + module_addr_min_rx = (unsigned long)ret;
  81693. + if ((unsigned long)ret + size > module_addr_max_rx)
  81694. + module_addr_max_rx = (unsigned long)ret + size;
  81695. mutex_unlock(&module_mutex);
  81696. }
  81697. return ret;
  81698. @@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
  81699. mod = (void *)info->sechdrs[info->index.mod].sh_addr;
  81700. if (info->index.sym == 0) {
  81701. +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
  81702. + /*
  81703. + * avoid potentially printing jibberish on attempted load
  81704. + * of a module randomized with a different seed
  81705. + */
  81706. + pr_warn("module has no symbols (stripped?)\n");
  81707. +#else
  81708. pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
  81709. +#endif
  81710. return ERR_PTR(-ENOEXEC);
  81711. }
  81712. @@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
  81713. static int check_modinfo(struct module *mod, struct load_info *info, int flags)
  81714. {
  81715. const char *modmagic = get_modinfo(info, "vermagic");
  81716. + const char *license = get_modinfo(info, "license");
  81717. int err;
  81718. +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
  81719. + if (!license || !license_is_gpl_compatible(license))
  81720. + return -ENOEXEC;
  81721. +#endif
  81722. +
  81723. if (flags & MODULE_INIT_IGNORE_VERMAGIC)
  81724. modmagic = NULL;
  81725. @@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
  81726. }
  81727. /* Set up license info based on the info section */
  81728. - set_license(mod, get_modinfo(info, "license"));
  81729. + set_license(mod, license);
  81730. return 0;
  81731. }
  81732. @@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
  81733. void *ptr;
  81734. /* Do the allocs. */
  81735. - ptr = module_alloc_update_bounds(mod->core_size);
  81736. + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
  81737. /*
  81738. * The pointer to this block is stored in the module structure
  81739. * which is inside the block. Just mark it as not being a
  81740. @@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
  81741. if (!ptr)
  81742. return -ENOMEM;
  81743. - memset(ptr, 0, mod->core_size);
  81744. - mod->module_core = ptr;
  81745. + memset(ptr, 0, mod->core_size_rw);
  81746. + mod->module_core_rw = ptr;
  81747. - if (mod->init_size) {
  81748. - ptr = module_alloc_update_bounds(mod->init_size);
  81749. + if (mod->init_size_rw) {
  81750. + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
  81751. /*
  81752. * The pointer to this block is stored in the module structure
  81753. * which is inside the block. This block doesn't need to be
  81754. @@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
  81755. */
  81756. kmemleak_ignore(ptr);
  81757. if (!ptr) {
  81758. - module_free(mod, mod->module_core);
  81759. + module_free(mod, mod->module_core_rw);
  81760. return -ENOMEM;
  81761. }
  81762. - memset(ptr, 0, mod->init_size);
  81763. - mod->module_init = ptr;
  81764. + memset(ptr, 0, mod->init_size_rw);
  81765. + mod->module_init_rw = ptr;
  81766. } else
  81767. - mod->module_init = NULL;
  81768. + mod->module_init_rw = NULL;
  81769. +
  81770. + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
  81771. + kmemleak_not_leak(ptr);
  81772. + if (!ptr) {
  81773. + if (mod->module_init_rw)
  81774. + module_free(mod, mod->module_init_rw);
  81775. + module_free(mod, mod->module_core_rw);
  81776. + return -ENOMEM;
  81777. + }
  81778. +
  81779. + pax_open_kernel();
  81780. + memset(ptr, 0, mod->core_size_rx);
  81781. + pax_close_kernel();
  81782. + mod->module_core_rx = ptr;
  81783. +
  81784. + if (mod->init_size_rx) {
  81785. + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
  81786. + kmemleak_ignore(ptr);
  81787. + if (!ptr && mod->init_size_rx) {
  81788. + module_free_exec(mod, mod->module_core_rx);
  81789. + if (mod->module_init_rw)
  81790. + module_free(mod, mod->module_init_rw);
  81791. + module_free(mod, mod->module_core_rw);
  81792. + return -ENOMEM;
  81793. + }
  81794. +
  81795. + pax_open_kernel();
  81796. + memset(ptr, 0, mod->init_size_rx);
  81797. + pax_close_kernel();
  81798. + mod->module_init_rx = ptr;
  81799. + } else
  81800. + mod->module_init_rx = NULL;
  81801. /* Transfer each section which specifies SHF_ALLOC */
  81802. pr_debug("final section addresses:\n");
  81803. @@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
  81804. if (!(shdr->sh_flags & SHF_ALLOC))
  81805. continue;
  81806. - if (shdr->sh_entsize & INIT_OFFSET_MASK)
  81807. - dest = mod->module_init
  81808. - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
  81809. - else
  81810. - dest = mod->module_core + shdr->sh_entsize;
  81811. + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
  81812. + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
  81813. + dest = mod->module_init_rw
  81814. + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
  81815. + else
  81816. + dest = mod->module_init_rx
  81817. + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
  81818. + } else {
  81819. + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
  81820. + dest = mod->module_core_rw + shdr->sh_entsize;
  81821. + else
  81822. + dest = mod->module_core_rx + shdr->sh_entsize;
  81823. + }
  81824. +
  81825. + if (shdr->sh_type != SHT_NOBITS) {
  81826. +
  81827. +#ifdef CONFIG_PAX_KERNEXEC
  81828. +#ifdef CONFIG_X86_64
  81829. + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
  81830. + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
  81831. +#endif
  81832. + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
  81833. + pax_open_kernel();
  81834. + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
  81835. + pax_close_kernel();
  81836. + } else
  81837. +#endif
  81838. - if (shdr->sh_type != SHT_NOBITS)
  81839. memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
  81840. + }
  81841. /* Update sh_addr to point to copy in image. */
  81842. - shdr->sh_addr = (unsigned long)dest;
  81843. +
  81844. +#ifdef CONFIG_PAX_KERNEXEC
  81845. + if (shdr->sh_flags & SHF_EXECINSTR)
  81846. + shdr->sh_addr = ktva_ktla((unsigned long)dest);
  81847. + else
  81848. +#endif
  81849. +
  81850. + shdr->sh_addr = (unsigned long)dest;
  81851. pr_debug("\t0x%lx %s\n",
  81852. (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
  81853. }
  81854. @@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
  81855. * Do it before processing of module parameters, so the module
  81856. * can provide parameter accessor functions of its own.
  81857. */
  81858. - if (mod->module_init)
  81859. - flush_icache_range((unsigned long)mod->module_init,
  81860. - (unsigned long)mod->module_init
  81861. - + mod->init_size);
  81862. - flush_icache_range((unsigned long)mod->module_core,
  81863. - (unsigned long)mod->module_core + mod->core_size);
  81864. + if (mod->module_init_rx)
  81865. + flush_icache_range((unsigned long)mod->module_init_rx,
  81866. + (unsigned long)mod->module_init_rx
  81867. + + mod->init_size_rx);
  81868. + flush_icache_range((unsigned long)mod->module_core_rx,
  81869. + (unsigned long)mod->module_core_rx + mod->core_size_rx);
  81870. set_fs(old_fs);
  81871. }
  81872. @@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
  81873. static void module_deallocate(struct module *mod, struct load_info *info)
  81874. {
  81875. percpu_modfree(mod);
  81876. - module_free(mod, mod->module_init);
  81877. - module_free(mod, mod->module_core);
  81878. + module_free_exec(mod, mod->module_init_rx);
  81879. + module_free_exec(mod, mod->module_core_rx);
  81880. + module_free(mod, mod->module_init_rw);
  81881. + module_free(mod, mod->module_core_rw);
  81882. }
  81883. int __weak module_finalize(const Elf_Ehdr *hdr,
  81884. @@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
  81885. static int post_relocation(struct module *mod, const struct load_info *info)
  81886. {
  81887. /* Sort exception table now relocations are done. */
  81888. + pax_open_kernel();
  81889. sort_extable(mod->extable, mod->extable + mod->num_exentries);
  81890. + pax_close_kernel();
  81891. /* Copy relocated percpu area over. */
  81892. percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
  81893. @@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
  81894. MODULE_STATE_COMING, mod);
  81895. /* Set RO and NX regions for core */
  81896. - set_section_ro_nx(mod->module_core,
  81897. - mod->core_text_size,
  81898. - mod->core_ro_size,
  81899. - mod->core_size);
  81900. + set_section_ro_nx(mod->module_core_rx,
  81901. + mod->core_size_rx,
  81902. + mod->core_size_rx,
  81903. + mod->core_size_rx);
  81904. /* Set RO and NX regions for init */
  81905. - set_section_ro_nx(mod->module_init,
  81906. - mod->init_text_size,
  81907. - mod->init_ro_size,
  81908. - mod->init_size);
  81909. + set_section_ro_nx(mod->module_init_rx,
  81910. + mod->init_size_rx,
  81911. + mod->init_size_rx,
  81912. + mod->init_size_rx);
  81913. do_mod_ctors(mod);
  81914. /* Start the module */
  81915. @@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
  81916. mod->strtab = mod->core_strtab;
  81917. #endif
  81918. unset_module_init_ro_nx(mod);
  81919. - module_free(mod, mod->module_init);
  81920. - mod->module_init = NULL;
  81921. - mod->init_size = 0;
  81922. - mod->init_ro_size = 0;
  81923. - mod->init_text_size = 0;
  81924. + module_free(mod, mod->module_init_rw);
  81925. + module_free_exec(mod, mod->module_init_rx);
  81926. + mod->module_init_rw = NULL;
  81927. + mod->module_init_rx = NULL;
  81928. + mod->init_size_rw = 0;
  81929. + mod->init_size_rx = 0;
  81930. mutex_unlock(&module_mutex);
  81931. wake_up_all(&module_wq);
  81932. @@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
  81933. if (err)
  81934. goto free_unload;
  81935. + /* Now copy in args */
  81936. + mod->args = strndup_user(uargs, ~0UL >> 1);
  81937. + if (IS_ERR(mod->args)) {
  81938. + err = PTR_ERR(mod->args);
  81939. + goto free_unload;
  81940. + }
  81941. +
  81942. /* Set up MODINFO_ATTR fields */
  81943. setup_modinfo(mod, info);
  81944. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  81945. + {
  81946. + char *p, *p2;
  81947. +
  81948. + if (strstr(mod->args, "grsec_modharden_netdev")) {
  81949. + printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
  81950. + err = -EPERM;
  81951. + goto free_modinfo;
  81952. + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
  81953. + p += sizeof("grsec_modharden_normal") - 1;
  81954. + p2 = strstr(p, "_");
  81955. + if (p2) {
  81956. + *p2 = '\0';
  81957. + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
  81958. + *p2 = '_';
  81959. + }
  81960. + err = -EPERM;
  81961. + goto free_modinfo;
  81962. + }
  81963. + }
  81964. +#endif
  81965. +
  81966. /* Fix up syms, so that st_value is a pointer to location. */
  81967. err = simplify_symbols(mod, info);
  81968. if (err < 0)
  81969. @@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
  81970. flush_module_icache(mod);
  81971. - /* Now copy in args */
  81972. - mod->args = strndup_user(uargs, ~0UL >> 1);
  81973. - if (IS_ERR(mod->args)) {
  81974. - err = PTR_ERR(mod->args);
  81975. - goto free_arch_cleanup;
  81976. - }
  81977. -
  81978. dynamic_debug_setup(info->debug, info->num_debug);
  81979. /* Finally it's fully formed, ready to start executing. */
  81980. @@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
  81981. ddebug_cleanup:
  81982. dynamic_debug_remove(info->debug);
  81983. synchronize_sched();
  81984. - kfree(mod->args);
  81985. - free_arch_cleanup:
  81986. module_arch_cleanup(mod);
  81987. free_modinfo:
  81988. free_modinfo(mod);
  81989. + kfree(mod->args);
  81990. free_unload:
  81991. module_unload_free(mod);
  81992. unlink_mod:
  81993. @@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
  81994. unsigned long nextval;
  81995. /* At worse, next value is at end of module */
  81996. - if (within_module_init(addr, mod))
  81997. - nextval = (unsigned long)mod->module_init+mod->init_text_size;
  81998. + if (within_module_init_rx(addr, mod))
  81999. + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
  82000. + else if (within_module_init_rw(addr, mod))
  82001. + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
  82002. + else if (within_module_core_rx(addr, mod))
  82003. + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
  82004. + else if (within_module_core_rw(addr, mod))
  82005. + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
  82006. else
  82007. - nextval = (unsigned long)mod->module_core+mod->core_text_size;
  82008. + return NULL;
  82009. /* Scan for closest preceding symbol, and next symbol. (ELF
  82010. starts real symbols at 1). */
  82011. @@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
  82012. return 0;
  82013. seq_printf(m, "%s %u",
  82014. - mod->name, mod->init_size + mod->core_size);
  82015. + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
  82016. print_unload_info(m, mod);
  82017. /* Informative for users. */
  82018. @@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
  82019. mod->state == MODULE_STATE_COMING ? "Loading":
  82020. "Live");
  82021. /* Used by oprofile and other similar tools. */
  82022. - seq_printf(m, " 0x%pK", mod->module_core);
  82023. + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
  82024. /* Taints info */
  82025. if (mod->taints)
  82026. @@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
  82027. static int __init proc_modules_init(void)
  82028. {
  82029. +#ifndef CONFIG_GRKERNSEC_HIDESYM
  82030. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  82031. + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
  82032. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  82033. + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
  82034. +#else
  82035. proc_create("modules", 0, NULL, &proc_modules_operations);
  82036. +#endif
  82037. +#else
  82038. + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
  82039. +#endif
  82040. return 0;
  82041. }
  82042. module_init(proc_modules_init);
  82043. @@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
  82044. {
  82045. struct module *mod;
  82046. - if (addr < module_addr_min || addr > module_addr_max)
  82047. + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
  82048. + (addr < module_addr_min_rw || addr > module_addr_max_rw))
  82049. return NULL;
  82050. list_for_each_entry_rcu(mod, &modules, list) {
  82051. if (mod->state == MODULE_STATE_UNFORMED)
  82052. continue;
  82053. - if (within_module_core(addr, mod)
  82054. - || within_module_init(addr, mod))
  82055. + if (within_module_init(addr, mod) || within_module_core(addr, mod))
  82056. return mod;
  82057. }
  82058. return NULL;
  82059. @@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
  82060. */
  82061. struct module *__module_text_address(unsigned long addr)
  82062. {
  82063. - struct module *mod = __module_address(addr);
  82064. + struct module *mod;
  82065. +
  82066. +#ifdef CONFIG_X86_32
  82067. + addr = ktla_ktva(addr);
  82068. +#endif
  82069. +
  82070. + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
  82071. + return NULL;
  82072. +
  82073. + mod = __module_address(addr);
  82074. +
  82075. if (mod) {
  82076. /* Make sure it's within the text section. */
  82077. - if (!within(addr, mod->module_init, mod->init_text_size)
  82078. - && !within(addr, mod->module_core, mod->core_text_size))
  82079. + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
  82080. mod = NULL;
  82081. }
  82082. return mod;
  82083. diff --git a/kernel/notifier.c b/kernel/notifier.c
  82084. index 2d5cc4c..d9ea600 100644
  82085. --- a/kernel/notifier.c
  82086. +++ b/kernel/notifier.c
  82087. @@ -5,6 +5,7 @@
  82088. #include <linux/rcupdate.h>
  82089. #include <linux/vmalloc.h>
  82090. #include <linux/reboot.h>
  82091. +#include <linux/mm.h>
  82092. /*
  82093. * Notifier list for kernel code which wants to be called
  82094. @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
  82095. while ((*nl) != NULL) {
  82096. if (n->priority > (*nl)->priority)
  82097. break;
  82098. - nl = &((*nl)->next);
  82099. + nl = (struct notifier_block **)&((*nl)->next);
  82100. }
  82101. - n->next = *nl;
  82102. + pax_open_kernel();
  82103. + *(const void **)&n->next = *nl;
  82104. rcu_assign_pointer(*nl, n);
  82105. + pax_close_kernel();
  82106. return 0;
  82107. }
  82108. @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
  82109. return 0;
  82110. if (n->priority > (*nl)->priority)
  82111. break;
  82112. - nl = &((*nl)->next);
  82113. + nl = (struct notifier_block **)&((*nl)->next);
  82114. }
  82115. - n->next = *nl;
  82116. + pax_open_kernel();
  82117. + *(const void **)&n->next = *nl;
  82118. rcu_assign_pointer(*nl, n);
  82119. + pax_close_kernel();
  82120. return 0;
  82121. }
  82122. @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
  82123. {
  82124. while ((*nl) != NULL) {
  82125. if ((*nl) == n) {
  82126. + pax_open_kernel();
  82127. rcu_assign_pointer(*nl, n->next);
  82128. + pax_close_kernel();
  82129. return 0;
  82130. }
  82131. - nl = &((*nl)->next);
  82132. + nl = (struct notifier_block **)&((*nl)->next);
  82133. }
  82134. return -ENOENT;
  82135. }
  82136. diff --git a/kernel/padata.c b/kernel/padata.c
  82137. index 161402f..598814c 100644
  82138. --- a/kernel/padata.c
  82139. +++ b/kernel/padata.c
  82140. @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
  82141. * seq_nr mod. number of cpus in use.
  82142. */
  82143. - seq_nr = atomic_inc_return(&pd->seq_nr);
  82144. + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
  82145. cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
  82146. return padata_index_to_cpu(pd, cpu_index);
  82147. @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
  82148. padata_init_pqueues(pd);
  82149. padata_init_squeues(pd);
  82150. setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
  82151. - atomic_set(&pd->seq_nr, -1);
  82152. + atomic_set_unchecked(&pd->seq_nr, -1);
  82153. atomic_set(&pd->reorder_objects, 0);
  82154. atomic_set(&pd->refcnt, 0);
  82155. pd->pinst = pinst;
  82156. diff --git a/kernel/panic.c b/kernel/panic.c
  82157. index 6d63003..486a109 100644
  82158. --- a/kernel/panic.c
  82159. +++ b/kernel/panic.c
  82160. @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
  82161. /*
  82162. * Stop ourself in panic -- architecture code may override this
  82163. */
  82164. -void __weak panic_smp_self_stop(void)
  82165. +void __weak __noreturn panic_smp_self_stop(void)
  82166. {
  82167. while (1)
  82168. cpu_relax();
  82169. @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
  82170. disable_trace_on_warning();
  82171. pr_warn("------------[ cut here ]------------\n");
  82172. - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
  82173. + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
  82174. raw_smp_processor_id(), current->pid, file, line, caller);
  82175. if (args)
  82176. @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
  82177. */
  82178. void __stack_chk_fail(void)
  82179. {
  82180. - panic("stack-protector: Kernel stack is corrupted in: %p\n",
  82181. + dump_stack();
  82182. + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
  82183. __builtin_return_address(0));
  82184. }
  82185. EXPORT_SYMBOL(__stack_chk_fail);
  82186. diff --git a/kernel/pid.c b/kernel/pid.c
  82187. index 9b9a266..c20ef80 100644
  82188. --- a/kernel/pid.c
  82189. +++ b/kernel/pid.c
  82190. @@ -33,6 +33,7 @@
  82191. #include <linux/rculist.h>
  82192. #include <linux/bootmem.h>
  82193. #include <linux/hash.h>
  82194. +#include <linux/security.h>
  82195. #include <linux/pid_namespace.h>
  82196. #include <linux/init_task.h>
  82197. #include <linux/syscalls.h>
  82198. @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
  82199. int pid_max = PID_MAX_DEFAULT;
  82200. -#define RESERVED_PIDS 300
  82201. +#define RESERVED_PIDS 500
  82202. int pid_max_min = RESERVED_PIDS + 1;
  82203. int pid_max_max = PID_MAX_LIMIT;
  82204. @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
  82205. */
  82206. struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
  82207. {
  82208. + struct task_struct *task;
  82209. +
  82210. rcu_lockdep_assert(rcu_read_lock_held(),
  82211. "find_task_by_pid_ns() needs rcu_read_lock()"
  82212. " protection");
  82213. - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
  82214. +
  82215. + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
  82216. +
  82217. + if (gr_pid_is_chrooted(task))
  82218. + return NULL;
  82219. +
  82220. + return task;
  82221. }
  82222. struct task_struct *find_task_by_vpid(pid_t vnr)
  82223. @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
  82224. return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
  82225. }
  82226. +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
  82227. +{
  82228. + rcu_lockdep_assert(rcu_read_lock_held(),
  82229. + "find_task_by_pid_ns() needs rcu_read_lock()"
  82230. + " protection");
  82231. + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
  82232. +}
  82233. +
  82234. struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
  82235. {
  82236. struct pid *pid;
  82237. diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
  82238. index db95d8e..a0ca23f 100644
  82239. --- a/kernel/pid_namespace.c
  82240. +++ b/kernel/pid_namespace.c
  82241. @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
  82242. void __user *buffer, size_t *lenp, loff_t *ppos)
  82243. {
  82244. struct pid_namespace *pid_ns = task_active_pid_ns(current);
  82245. - struct ctl_table tmp = *table;
  82246. + ctl_table_no_const tmp = *table;
  82247. if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
  82248. return -EPERM;
  82249. diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
  82250. index 3b89464..5e38379 100644
  82251. --- a/kernel/posix-cpu-timers.c
  82252. +++ b/kernel/posix-cpu-timers.c
  82253. @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
  82254. static __init int init_posix_cpu_timers(void)
  82255. {
  82256. - struct k_clock process = {
  82257. + static struct k_clock process = {
  82258. .clock_getres = process_cpu_clock_getres,
  82259. .clock_get = process_cpu_clock_get,
  82260. .timer_create = process_cpu_timer_create,
  82261. .nsleep = process_cpu_nsleep,
  82262. .nsleep_restart = process_cpu_nsleep_restart,
  82263. };
  82264. - struct k_clock thread = {
  82265. + static struct k_clock thread = {
  82266. .clock_getres = thread_cpu_clock_getres,
  82267. .clock_get = thread_cpu_clock_get,
  82268. .timer_create = thread_cpu_timer_create,
  82269. diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
  82270. index 424c2d4..679242f 100644
  82271. --- a/kernel/posix-timers.c
  82272. +++ b/kernel/posix-timers.c
  82273. @@ -43,6 +43,7 @@
  82274. #include <linux/hash.h>
  82275. #include <linux/posix-clock.h>
  82276. #include <linux/posix-timers.h>
  82277. +#include <linux/grsecurity.h>
  82278. #include <linux/syscalls.h>
  82279. #include <linux/wait.h>
  82280. #include <linux/workqueue.h>
  82281. @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
  82282. * which we beg off on and pass to do_sys_settimeofday().
  82283. */
  82284. -static struct k_clock posix_clocks[MAX_CLOCKS];
  82285. +static struct k_clock *posix_clocks[MAX_CLOCKS];
  82286. /*
  82287. * These ones are defined below.
  82288. @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
  82289. */
  82290. static __init int init_posix_timers(void)
  82291. {
  82292. - struct k_clock clock_realtime = {
  82293. + static struct k_clock clock_realtime = {
  82294. .clock_getres = hrtimer_get_res,
  82295. .clock_get = posix_clock_realtime_get,
  82296. .clock_set = posix_clock_realtime_set,
  82297. @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
  82298. .timer_get = common_timer_get,
  82299. .timer_del = common_timer_del,
  82300. };
  82301. - struct k_clock clock_monotonic = {
  82302. + static struct k_clock clock_monotonic = {
  82303. .clock_getres = hrtimer_get_res,
  82304. .clock_get = posix_ktime_get_ts,
  82305. .nsleep = common_nsleep,
  82306. @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
  82307. .timer_get = common_timer_get,
  82308. .timer_del = common_timer_del,
  82309. };
  82310. - struct k_clock clock_monotonic_raw = {
  82311. + static struct k_clock clock_monotonic_raw = {
  82312. .clock_getres = hrtimer_get_res,
  82313. .clock_get = posix_get_monotonic_raw,
  82314. };
  82315. - struct k_clock clock_realtime_coarse = {
  82316. + static struct k_clock clock_realtime_coarse = {
  82317. .clock_getres = posix_get_coarse_res,
  82318. .clock_get = posix_get_realtime_coarse,
  82319. };
  82320. - struct k_clock clock_monotonic_coarse = {
  82321. + static struct k_clock clock_monotonic_coarse = {
  82322. .clock_getres = posix_get_coarse_res,
  82323. .clock_get = posix_get_monotonic_coarse,
  82324. };
  82325. - struct k_clock clock_tai = {
  82326. + static struct k_clock clock_tai = {
  82327. .clock_getres = hrtimer_get_res,
  82328. .clock_get = posix_get_tai,
  82329. .nsleep = common_nsleep,
  82330. @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
  82331. .timer_get = common_timer_get,
  82332. .timer_del = common_timer_del,
  82333. };
  82334. - struct k_clock clock_boottime = {
  82335. + static struct k_clock clock_boottime = {
  82336. .clock_getres = hrtimer_get_res,
  82337. .clock_get = posix_get_boottime,
  82338. .nsleep = common_nsleep,
  82339. @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
  82340. return;
  82341. }
  82342. - posix_clocks[clock_id] = *new_clock;
  82343. + posix_clocks[clock_id] = new_clock;
  82344. }
  82345. EXPORT_SYMBOL_GPL(posix_timers_register_clock);
  82346. @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
  82347. return (id & CLOCKFD_MASK) == CLOCKFD ?
  82348. &clock_posix_dynamic : &clock_posix_cpu;
  82349. - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
  82350. + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
  82351. return NULL;
  82352. - return &posix_clocks[id];
  82353. + return posix_clocks[id];
  82354. }
  82355. static int common_timer_create(struct k_itimer *new_timer)
  82356. @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
  82357. struct k_clock *kc = clockid_to_kclock(which_clock);
  82358. struct k_itimer *new_timer;
  82359. int error, new_timer_id;
  82360. - sigevent_t event;
  82361. + sigevent_t event = { };
  82362. int it_id_set = IT_ID_NOT_SET;
  82363. if (!kc)
  82364. @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
  82365. if (copy_from_user(&new_tp, tp, sizeof (*tp)))
  82366. return -EFAULT;
  82367. + /* only the CLOCK_REALTIME clock can be set, all other clocks
  82368. + have their clock_set fptr set to a nosettime dummy function
  82369. + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
  82370. + call common_clock_set, which calls do_sys_settimeofday, which
  82371. + we hook
  82372. + */
  82373. +
  82374. return kc->clock_set(which_clock, &new_tp);
  82375. }
  82376. diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
  82377. index 2fac9cc..56fef29 100644
  82378. --- a/kernel/power/Kconfig
  82379. +++ b/kernel/power/Kconfig
  82380. @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
  82381. config HIBERNATION
  82382. bool "Hibernation (aka 'suspend to disk')"
  82383. depends on SWAP && ARCH_HIBERNATION_POSSIBLE
  82384. + depends on !GRKERNSEC_KMEM
  82385. + depends on !PAX_MEMORY_SANITIZE
  82386. select HIBERNATE_CALLBACKS
  82387. select LZO_COMPRESS
  82388. select LZO_DECOMPRESS
  82389. diff --git a/kernel/power/process.c b/kernel/power/process.c
  82390. index 06ec886..9dba35e 100644
  82391. --- a/kernel/power/process.c
  82392. +++ b/kernel/power/process.c
  82393. @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
  82394. unsigned int elapsed_msecs;
  82395. bool wakeup = false;
  82396. int sleep_usecs = USEC_PER_MSEC;
  82397. + bool timedout = false;
  82398. do_gettimeofday(&start);
  82399. @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
  82400. while (true) {
  82401. todo = 0;
  82402. + if (time_after(jiffies, end_time))
  82403. + timedout = true;
  82404. read_lock(&tasklist_lock);
  82405. do_each_thread(g, p) {
  82406. if (p == current || !freeze_task(p))
  82407. continue;
  82408. - if (!freezer_should_skip(p))
  82409. + if (!freezer_should_skip(p)) {
  82410. todo++;
  82411. + if (timedout) {
  82412. + printk(KERN_ERR "Task refusing to freeze:\n");
  82413. + sched_show_task(p);
  82414. + }
  82415. + }
  82416. } while_each_thread(g, p);
  82417. read_unlock(&tasklist_lock);
  82418. @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
  82419. todo += wq_busy;
  82420. }
  82421. - if (!todo || time_after(jiffies, end_time))
  82422. + if (!todo || timedout)
  82423. break;
  82424. if (pm_wakeup_pending()) {
  82425. diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
  82426. index 4dae9cb..039ffbb 100644
  82427. --- a/kernel/printk/printk.c
  82428. +++ b/kernel/printk/printk.c
  82429. @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
  82430. if (from_file && type != SYSLOG_ACTION_OPEN)
  82431. return 0;
  82432. +#ifdef CONFIG_GRKERNSEC_DMESG
  82433. + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
  82434. + return -EPERM;
  82435. +#endif
  82436. +
  82437. if (syslog_action_restricted(type)) {
  82438. if (capable(CAP_SYSLOG))
  82439. return 0;
  82440. diff --git a/kernel/profile.c b/kernel/profile.c
  82441. index ebdd9c1..612ee05 100644
  82442. --- a/kernel/profile.c
  82443. +++ b/kernel/profile.c
  82444. @@ -37,7 +37,7 @@ struct profile_hit {
  82445. #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
  82446. #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
  82447. -static atomic_t *prof_buffer;
  82448. +static atomic_unchecked_t *prof_buffer;
  82449. static unsigned long prof_len, prof_shift;
  82450. int prof_on __read_mostly;
  82451. @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
  82452. hits[i].pc = 0;
  82453. continue;
  82454. }
  82455. - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
  82456. + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
  82457. hits[i].hits = hits[i].pc = 0;
  82458. }
  82459. }
  82460. @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
  82461. * Add the current hit(s) and flush the write-queue out
  82462. * to the global buffer:
  82463. */
  82464. - atomic_add(nr_hits, &prof_buffer[pc]);
  82465. + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
  82466. for (i = 0; i < NR_PROFILE_HIT; ++i) {
  82467. - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
  82468. + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
  82469. hits[i].pc = hits[i].hits = 0;
  82470. }
  82471. out:
  82472. @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
  82473. {
  82474. unsigned long pc;
  82475. pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
  82476. - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
  82477. + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
  82478. }
  82479. #endif /* !CONFIG_SMP */
  82480. @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  82481. return -EFAULT;
  82482. buf++; p++; count--; read++;
  82483. }
  82484. - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
  82485. + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
  82486. if (copy_to_user(buf, (void *)pnt, count))
  82487. return -EFAULT;
  82488. read += count;
  82489. @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
  82490. }
  82491. #endif
  82492. profile_discard_flip_buffers();
  82493. - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
  82494. + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
  82495. return count;
  82496. }
  82497. diff --git a/kernel/ptrace.c b/kernel/ptrace.c
  82498. index 1f4bcb3..99cf7ab 100644
  82499. --- a/kernel/ptrace.c
  82500. +++ b/kernel/ptrace.c
  82501. @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
  82502. if (seize)
  82503. flags |= PT_SEIZED;
  82504. rcu_read_lock();
  82505. - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
  82506. + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
  82507. flags |= PT_PTRACE_CAP;
  82508. rcu_read_unlock();
  82509. task->ptrace = flags;
  82510. @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
  82511. break;
  82512. return -EIO;
  82513. }
  82514. - if (copy_to_user(dst, buf, retval))
  82515. + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
  82516. return -EFAULT;
  82517. copied += retval;
  82518. src += retval;
  82519. @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
  82520. bool seized = child->ptrace & PT_SEIZED;
  82521. int ret = -EIO;
  82522. siginfo_t siginfo, *si;
  82523. - void __user *datavp = (void __user *) data;
  82524. + void __user *datavp = (__force void __user *) data;
  82525. unsigned long __user *datalp = datavp;
  82526. unsigned long flags;
  82527. @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
  82528. goto out;
  82529. }
  82530. + if (gr_handle_ptrace(child, request)) {
  82531. + ret = -EPERM;
  82532. + goto out_put_task_struct;
  82533. + }
  82534. +
  82535. if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
  82536. ret = ptrace_attach(child, request, addr, data);
  82537. /*
  82538. * Some architectures need to do book-keeping after
  82539. * a ptrace attach.
  82540. */
  82541. - if (!ret)
  82542. + if (!ret) {
  82543. arch_ptrace_attach(child);
  82544. + gr_audit_ptrace(child);
  82545. + }
  82546. goto out_put_task_struct;
  82547. }
  82548. @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
  82549. copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
  82550. if (copied != sizeof(tmp))
  82551. return -EIO;
  82552. - return put_user(tmp, (unsigned long __user *)data);
  82553. + return put_user(tmp, (__force unsigned long __user *)data);
  82554. }
  82555. int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
  82556. @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
  82557. }
  82558. asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  82559. - compat_long_t addr, compat_long_t data)
  82560. + compat_ulong_t addr, compat_ulong_t data)
  82561. {
  82562. struct task_struct *child;
  82563. long ret;
  82564. @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  82565. goto out;
  82566. }
  82567. + if (gr_handle_ptrace(child, request)) {
  82568. + ret = -EPERM;
  82569. + goto out_put_task_struct;
  82570. + }
  82571. +
  82572. if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
  82573. ret = ptrace_attach(child, request, addr, data);
  82574. /*
  82575. * Some architectures need to do book-keeping after
  82576. * a ptrace attach.
  82577. */
  82578. - if (!ret)
  82579. + if (!ret) {
  82580. arch_ptrace_attach(child);
  82581. + gr_audit_ptrace(child);
  82582. + }
  82583. goto out_put_task_struct;
  82584. }
  82585. diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
  82586. index 3318d82..1a5b2d1 100644
  82587. --- a/kernel/rcu/srcu.c
  82588. +++ b/kernel/rcu/srcu.c
  82589. @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
  82590. idx = ACCESS_ONCE(sp->completed) & 0x1;
  82591. preempt_disable();
  82592. - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
  82593. + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
  82594. smp_mb(); /* B */ /* Avoid leaking the critical section. */
  82595. - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
  82596. + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
  82597. preempt_enable();
  82598. return idx;
  82599. }
  82600. diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
  82601. index 1254f31..16258dc 100644
  82602. --- a/kernel/rcu/tiny.c
  82603. +++ b/kernel/rcu/tiny.c
  82604. @@ -46,7 +46,7 @@
  82605. /* Forward declarations for tiny_plugin.h. */
  82606. struct rcu_ctrlblk;
  82607. static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
  82608. -static void rcu_process_callbacks(struct softirq_action *unused);
  82609. +static void rcu_process_callbacks(void);
  82610. static void __call_rcu(struct rcu_head *head,
  82611. void (*func)(struct rcu_head *rcu),
  82612. struct rcu_ctrlblk *rcp);
  82613. @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
  82614. false));
  82615. }
  82616. -static void rcu_process_callbacks(struct softirq_action *unused)
  82617. +static __latent_entropy void rcu_process_callbacks(void)
  82618. {
  82619. __rcu_process_callbacks(&rcu_sched_ctrlblk);
  82620. __rcu_process_callbacks(&rcu_bh_ctrlblk);
  82621. diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
  82622. index 732f8ae..42c1919 100644
  82623. --- a/kernel/rcu/torture.c
  82624. +++ b/kernel/rcu/torture.c
  82625. @@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
  82626. { 0 };
  82627. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
  82628. { 0 };
  82629. -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  82630. -static atomic_t n_rcu_torture_alloc;
  82631. -static atomic_t n_rcu_torture_alloc_fail;
  82632. -static atomic_t n_rcu_torture_free;
  82633. -static atomic_t n_rcu_torture_mberror;
  82634. -static atomic_t n_rcu_torture_error;
  82635. +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  82636. +static atomic_unchecked_t n_rcu_torture_alloc;
  82637. +static atomic_unchecked_t n_rcu_torture_alloc_fail;
  82638. +static atomic_unchecked_t n_rcu_torture_free;
  82639. +static atomic_unchecked_t n_rcu_torture_mberror;
  82640. +static atomic_unchecked_t n_rcu_torture_error;
  82641. static long n_rcu_torture_barrier_error;
  82642. static long n_rcu_torture_boost_ktrerror;
  82643. static long n_rcu_torture_boost_rterror;
  82644. @@ -297,11 +297,11 @@ rcu_torture_alloc(void)
  82645. spin_lock_bh(&rcu_torture_lock);
  82646. if (list_empty(&rcu_torture_freelist)) {
  82647. - atomic_inc(&n_rcu_torture_alloc_fail);
  82648. + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
  82649. spin_unlock_bh(&rcu_torture_lock);
  82650. return NULL;
  82651. }
  82652. - atomic_inc(&n_rcu_torture_alloc);
  82653. + atomic_inc_unchecked(&n_rcu_torture_alloc);
  82654. p = rcu_torture_freelist.next;
  82655. list_del_init(p);
  82656. spin_unlock_bh(&rcu_torture_lock);
  82657. @@ -314,7 +314,7 @@ rcu_torture_alloc(void)
  82658. static void
  82659. rcu_torture_free(struct rcu_torture *p)
  82660. {
  82661. - atomic_inc(&n_rcu_torture_free);
  82662. + atomic_inc_unchecked(&n_rcu_torture_free);
  82663. spin_lock_bh(&rcu_torture_lock);
  82664. list_add_tail(&p->rtort_free, &rcu_torture_freelist);
  82665. spin_unlock_bh(&rcu_torture_lock);
  82666. @@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
  82667. i = rp->rtort_pipe_count;
  82668. if (i > RCU_TORTURE_PIPE_LEN)
  82669. i = RCU_TORTURE_PIPE_LEN;
  82670. - atomic_inc(&rcu_torture_wcount[i]);
  82671. + atomic_inc_unchecked(&rcu_torture_wcount[i]);
  82672. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  82673. rp->rtort_mbtest = 0;
  82674. rcu_torture_free(rp);
  82675. @@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
  82676. i = old_rp->rtort_pipe_count;
  82677. if (i > RCU_TORTURE_PIPE_LEN)
  82678. i = RCU_TORTURE_PIPE_LEN;
  82679. - atomic_inc(&rcu_torture_wcount[i]);
  82680. + atomic_inc_unchecked(&rcu_torture_wcount[i]);
  82681. old_rp->rtort_pipe_count++;
  82682. if (gp_normal == gp_exp)
  82683. exp = !!(rcu_random(&rand) & 0x80);
  82684. @@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
  82685. i = rp->rtort_pipe_count;
  82686. if (i > RCU_TORTURE_PIPE_LEN)
  82687. i = RCU_TORTURE_PIPE_LEN;
  82688. - atomic_inc(&rcu_torture_wcount[i]);
  82689. + atomic_inc_unchecked(&rcu_torture_wcount[i]);
  82690. if (++rp->rtort_pipe_count >=
  82691. RCU_TORTURE_PIPE_LEN) {
  82692. rp->rtort_mbtest = 0;
  82693. @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
  82694. return;
  82695. }
  82696. if (p->rtort_mbtest == 0)
  82697. - atomic_inc(&n_rcu_torture_mberror);
  82698. + atomic_inc_unchecked(&n_rcu_torture_mberror);
  82699. spin_lock(&rand_lock);
  82700. cur_ops->read_delay(&rand);
  82701. n_rcu_torture_timers++;
  82702. @@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
  82703. continue;
  82704. }
  82705. if (p->rtort_mbtest == 0)
  82706. - atomic_inc(&n_rcu_torture_mberror);
  82707. + atomic_inc_unchecked(&n_rcu_torture_mberror);
  82708. cur_ops->read_delay(&rand);
  82709. preempt_disable();
  82710. pipe_count = p->rtort_pipe_count;
  82711. @@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
  82712. }
  82713. page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
  82714. page += sprintf(page,
  82715. - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
  82716. + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
  82717. rcu_torture_current,
  82718. rcu_torture_current_version,
  82719. list_empty(&rcu_torture_freelist),
  82720. - atomic_read(&n_rcu_torture_alloc),
  82721. - atomic_read(&n_rcu_torture_alloc_fail),
  82722. - atomic_read(&n_rcu_torture_free));
  82723. + atomic_read_unchecked(&n_rcu_torture_alloc),
  82724. + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
  82725. + atomic_read_unchecked(&n_rcu_torture_free));
  82726. page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
  82727. - atomic_read(&n_rcu_torture_mberror),
  82728. + atomic_read_unchecked(&n_rcu_torture_mberror),
  82729. n_rcu_torture_boost_ktrerror,
  82730. n_rcu_torture_boost_rterror);
  82731. page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
  82732. @@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
  82733. n_barrier_attempts,
  82734. n_rcu_torture_barrier_error);
  82735. page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
  82736. - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
  82737. + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
  82738. n_rcu_torture_barrier_error != 0 ||
  82739. n_rcu_torture_boost_ktrerror != 0 ||
  82740. n_rcu_torture_boost_rterror != 0 ||
  82741. n_rcu_torture_boost_failure != 0 ||
  82742. i > 1) {
  82743. page += sprintf(page, "!!! ");
  82744. - atomic_inc(&n_rcu_torture_error);
  82745. + atomic_inc_unchecked(&n_rcu_torture_error);
  82746. WARN_ON_ONCE(1);
  82747. }
  82748. page += sprintf(page, "Reader Pipe: ");
  82749. @@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
  82750. page += sprintf(page, "Free-Block Circulation: ");
  82751. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  82752. page += sprintf(page, " %d",
  82753. - atomic_read(&rcu_torture_wcount[i]));
  82754. + atomic_read_unchecked(&rcu_torture_wcount[i]));
  82755. }
  82756. page += sprintf(page, "\n");
  82757. if (cur_ops->stats)
  82758. @@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
  82759. rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
  82760. - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
  82761. + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
  82762. rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
  82763. else if (n_online_successes != n_online_attempts ||
  82764. n_offline_successes != n_offline_attempts)
  82765. @@ -1961,18 +1961,18 @@ rcu_torture_init(void)
  82766. rcu_torture_current = NULL;
  82767. rcu_torture_current_version = 0;
  82768. - atomic_set(&n_rcu_torture_alloc, 0);
  82769. - atomic_set(&n_rcu_torture_alloc_fail, 0);
  82770. - atomic_set(&n_rcu_torture_free, 0);
  82771. - atomic_set(&n_rcu_torture_mberror, 0);
  82772. - atomic_set(&n_rcu_torture_error, 0);
  82773. + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
  82774. + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
  82775. + atomic_set_unchecked(&n_rcu_torture_free, 0);
  82776. + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
  82777. + atomic_set_unchecked(&n_rcu_torture_error, 0);
  82778. n_rcu_torture_barrier_error = 0;
  82779. n_rcu_torture_boost_ktrerror = 0;
  82780. n_rcu_torture_boost_rterror = 0;
  82781. n_rcu_torture_boost_failure = 0;
  82782. n_rcu_torture_boosts = 0;
  82783. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  82784. - atomic_set(&rcu_torture_wcount[i], 0);
  82785. + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
  82786. for_each_possible_cpu(cpu) {
  82787. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  82788. per_cpu(rcu_torture_count, cpu)[i] = 0;
  82789. diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
  82790. index b3d116c..ebf6598 100644
  82791. --- a/kernel/rcu/tree.c
  82792. +++ b/kernel/rcu/tree.c
  82793. @@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
  82794. rcu_prepare_for_idle(smp_processor_id());
  82795. /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
  82796. smp_mb__before_atomic_inc(); /* See above. */
  82797. - atomic_inc(&rdtp->dynticks);
  82798. + atomic_inc_unchecked(&rdtp->dynticks);
  82799. smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
  82800. - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
  82801. + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
  82802. /*
  82803. * It is illegal to enter an extended quiescent state while
  82804. @@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
  82805. int user)
  82806. {
  82807. smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
  82808. - atomic_inc(&rdtp->dynticks);
  82809. + atomic_inc_unchecked(&rdtp->dynticks);
  82810. /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
  82811. smp_mb__after_atomic_inc(); /* See above. */
  82812. - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
  82813. + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
  82814. rcu_cleanup_after_idle(smp_processor_id());
  82815. trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
  82816. if (!user && !is_idle_task(current)) {
  82817. @@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
  82818. struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
  82819. if (rdtp->dynticks_nmi_nesting == 0 &&
  82820. - (atomic_read(&rdtp->dynticks) & 0x1))
  82821. + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
  82822. return;
  82823. rdtp->dynticks_nmi_nesting++;
  82824. smp_mb__before_atomic_inc(); /* Force delay from prior write. */
  82825. - atomic_inc(&rdtp->dynticks);
  82826. + atomic_inc_unchecked(&rdtp->dynticks);
  82827. /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
  82828. smp_mb__after_atomic_inc(); /* See above. */
  82829. - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
  82830. + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
  82831. }
  82832. /**
  82833. @@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
  82834. return;
  82835. /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
  82836. smp_mb__before_atomic_inc(); /* See above. */
  82837. - atomic_inc(&rdtp->dynticks);
  82838. + atomic_inc_unchecked(&rdtp->dynticks);
  82839. smp_mb__after_atomic_inc(); /* Force delay to next write. */
  82840. - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
  82841. + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
  82842. }
  82843. /**
  82844. @@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
  82845. */
  82846. bool notrace __rcu_is_watching(void)
  82847. {
  82848. - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
  82849. + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
  82850. }
  82851. /**
  82852. @@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
  82853. static int dyntick_save_progress_counter(struct rcu_data *rdp,
  82854. bool *isidle, unsigned long *maxj)
  82855. {
  82856. - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
  82857. + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
  82858. rcu_sysidle_check_cpu(rdp, isidle, maxj);
  82859. return (rdp->dynticks_snap & 0x1) == 0;
  82860. }
  82861. @@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
  82862. unsigned int curr;
  82863. unsigned int snap;
  82864. - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
  82865. + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
  82866. snap = (unsigned int)rdp->dynticks_snap;
  82867. /*
  82868. @@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
  82869. rdp = this_cpu_ptr(rsp->rda);
  82870. rcu_preempt_check_blocked_tasks(rnp);
  82871. rnp->qsmask = rnp->qsmaskinit;
  82872. - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
  82873. + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
  82874. WARN_ON_ONCE(rnp->completed != rsp->completed);
  82875. - ACCESS_ONCE(rnp->completed) = rsp->completed;
  82876. + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
  82877. if (rnp == rdp->mynode)
  82878. __note_gp_changes(rsp, rnp, rdp);
  82879. rcu_preempt_boost_start_gp(rnp);
  82880. @@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
  82881. rcu_for_each_node_breadth_first(rsp, rnp) {
  82882. raw_spin_lock_irq(&rnp->lock);
  82883. smp_mb__after_unlock_lock();
  82884. - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
  82885. + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
  82886. rdp = this_cpu_ptr(rsp->rda);
  82887. if (rnp == rdp->mynode)
  82888. __note_gp_changes(rsp, rnp, rdp);
  82889. @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
  82890. rsp->qlen += rdp->qlen;
  82891. rdp->n_cbs_orphaned += rdp->qlen;
  82892. rdp->qlen_lazy = 0;
  82893. - ACCESS_ONCE(rdp->qlen) = 0;
  82894. + ACCESS_ONCE_RW(rdp->qlen) = 0;
  82895. }
  82896. /*
  82897. @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
  82898. }
  82899. smp_mb(); /* List handling before counting for rcu_barrier(). */
  82900. rdp->qlen_lazy -= count_lazy;
  82901. - ACCESS_ONCE(rdp->qlen) -= count;
  82902. + ACCESS_ONCE_RW(rdp->qlen) -= count;
  82903. rdp->n_cbs_invoked += count;
  82904. /* Reinstate batch limit if we have worked down the excess. */
  82905. @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
  82906. /*
  82907. * Do RCU core processing for the current CPU.
  82908. */
  82909. -static void rcu_process_callbacks(struct softirq_action *unused)
  82910. +static void rcu_process_callbacks(void)
  82911. {
  82912. struct rcu_state *rsp;
  82913. @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
  82914. WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
  82915. if (debug_rcu_head_queue(head)) {
  82916. /* Probable double call_rcu(), so leak the callback. */
  82917. - ACCESS_ONCE(head->func) = rcu_leak_callback;
  82918. + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
  82919. WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
  82920. return;
  82921. }
  82922. @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
  82923. local_irq_restore(flags);
  82924. return;
  82925. }
  82926. - ACCESS_ONCE(rdp->qlen)++;
  82927. + ACCESS_ONCE_RW(rdp->qlen)++;
  82928. if (lazy)
  82929. rdp->qlen_lazy++;
  82930. else
  82931. @@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
  82932. * counter wrap on a 32-bit system. Quite a few more CPUs would of
  82933. * course be required on a 64-bit system.
  82934. */
  82935. - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
  82936. + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
  82937. (ulong)atomic_long_read(&rsp->expedited_done) +
  82938. ULONG_MAX / 8)) {
  82939. synchronize_sched();
  82940. - atomic_long_inc(&rsp->expedited_wrap);
  82941. + atomic_long_inc_unchecked(&rsp->expedited_wrap);
  82942. return;
  82943. }
  82944. @@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
  82945. * Take a ticket. Note that atomic_inc_return() implies a
  82946. * full memory barrier.
  82947. */
  82948. - snap = atomic_long_inc_return(&rsp->expedited_start);
  82949. + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
  82950. firstsnap = snap;
  82951. get_online_cpus();
  82952. WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
  82953. @@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
  82954. synchronize_sched_expedited_cpu_stop,
  82955. NULL) == -EAGAIN) {
  82956. put_online_cpus();
  82957. - atomic_long_inc(&rsp->expedited_tryfail);
  82958. + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
  82959. /* Check to see if someone else did our work for us. */
  82960. s = atomic_long_read(&rsp->expedited_done);
  82961. if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
  82962. /* ensure test happens before caller kfree */
  82963. smp_mb__before_atomic_inc(); /* ^^^ */
  82964. - atomic_long_inc(&rsp->expedited_workdone1);
  82965. + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
  82966. return;
  82967. }
  82968. @@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
  82969. udelay(trycount * num_online_cpus());
  82970. } else {
  82971. wait_rcu_gp(call_rcu_sched);
  82972. - atomic_long_inc(&rsp->expedited_normal);
  82973. + atomic_long_inc_unchecked(&rsp->expedited_normal);
  82974. return;
  82975. }
  82976. @@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
  82977. if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
  82978. /* ensure test happens before caller kfree */
  82979. smp_mb__before_atomic_inc(); /* ^^^ */
  82980. - atomic_long_inc(&rsp->expedited_workdone2);
  82981. + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
  82982. return;
  82983. }
  82984. @@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
  82985. * period works for us.
  82986. */
  82987. get_online_cpus();
  82988. - snap = atomic_long_read(&rsp->expedited_start);
  82989. + snap = atomic_long_read_unchecked(&rsp->expedited_start);
  82990. smp_mb(); /* ensure read is before try_stop_cpus(). */
  82991. }
  82992. - atomic_long_inc(&rsp->expedited_stoppedcpus);
  82993. + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
  82994. /*
  82995. * Everyone up to our most recent fetch is covered by our grace
  82996. @@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
  82997. * than we did already did their update.
  82998. */
  82999. do {
  83000. - atomic_long_inc(&rsp->expedited_done_tries);
  83001. + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
  83002. s = atomic_long_read(&rsp->expedited_done);
  83003. if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
  83004. /* ensure test happens before caller kfree */
  83005. smp_mb__before_atomic_inc(); /* ^^^ */
  83006. - atomic_long_inc(&rsp->expedited_done_lost);
  83007. + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
  83008. break;
  83009. }
  83010. } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
  83011. - atomic_long_inc(&rsp->expedited_done_exit);
  83012. + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
  83013. put_online_cpus();
  83014. }
  83015. @@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
  83016. * ACCESS_ONCE() to prevent the compiler from speculating
  83017. * the increment to precede the early-exit check.
  83018. */
  83019. - ACCESS_ONCE(rsp->n_barrier_done)++;
  83020. + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
  83021. WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
  83022. _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
  83023. smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
  83024. @@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
  83025. /* Increment ->n_barrier_done to prevent duplicate work. */
  83026. smp_mb(); /* Keep increment after above mechanism. */
  83027. - ACCESS_ONCE(rsp->n_barrier_done)++;
  83028. + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
  83029. WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
  83030. _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
  83031. smp_mb(); /* Keep increment before caller's subsequent code. */
  83032. @@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
  83033. rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
  83034. init_callback_list(rdp);
  83035. rdp->qlen_lazy = 0;
  83036. - ACCESS_ONCE(rdp->qlen) = 0;
  83037. + ACCESS_ONCE_RW(rdp->qlen) = 0;
  83038. rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
  83039. WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
  83040. - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
  83041. + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
  83042. rdp->cpu = cpu;
  83043. rdp->rsp = rsp;
  83044. rcu_boot_init_nocb_percpu_data(rdp);
  83045. @@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
  83046. init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
  83047. rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
  83048. rcu_sysidle_init_percpu_data(rdp->dynticks);
  83049. - atomic_set(&rdp->dynticks->dynticks,
  83050. - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
  83051. + atomic_set_unchecked(&rdp->dynticks->dynticks,
  83052. + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
  83053. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  83054. /* Add CPU to rcu_node bitmasks. */
  83055. diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
  83056. index 8c19873..bf83c57 100644
  83057. --- a/kernel/rcu/tree.h
  83058. +++ b/kernel/rcu/tree.h
  83059. @@ -87,11 +87,11 @@ struct rcu_dynticks {
  83060. long long dynticks_nesting; /* Track irq/process nesting level. */
  83061. /* Process level is worth LLONG_MAX/2. */
  83062. int dynticks_nmi_nesting; /* Track NMI nesting level. */
  83063. - atomic_t dynticks; /* Even value for idle, else odd. */
  83064. + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
  83065. #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
  83066. long long dynticks_idle_nesting;
  83067. /* irq/process nesting level from idle. */
  83068. - atomic_t dynticks_idle; /* Even value for idle, else odd. */
  83069. + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
  83070. /* "Idle" excludes userspace execution. */
  83071. unsigned long dynticks_idle_jiffies;
  83072. /* End of last non-NMI non-idle period. */
  83073. @@ -431,17 +431,17 @@ struct rcu_state {
  83074. /* _rcu_barrier(). */
  83075. /* End of fields guarded by barrier_mutex. */
  83076. - atomic_long_t expedited_start; /* Starting ticket. */
  83077. - atomic_long_t expedited_done; /* Done ticket. */
  83078. - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
  83079. - atomic_long_t expedited_tryfail; /* # acquisition failures. */
  83080. - atomic_long_t expedited_workdone1; /* # done by others #1. */
  83081. - atomic_long_t expedited_workdone2; /* # done by others #2. */
  83082. - atomic_long_t expedited_normal; /* # fallbacks to normal. */
  83083. - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
  83084. - atomic_long_t expedited_done_tries; /* # tries to update _done. */
  83085. - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
  83086. - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
  83087. + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
  83088. + atomic_long_t expedited_done; /* Done ticket. */
  83089. + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
  83090. + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
  83091. + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
  83092. + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
  83093. + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
  83094. + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
  83095. + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
  83096. + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
  83097. + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
  83098. unsigned long jiffies_force_qs; /* Time at which to invoke */
  83099. /* force_quiescent_state(). */
  83100. diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
  83101. index 6e2ef4b..c15df94 100644
  83102. --- a/kernel/rcu/tree_plugin.h
  83103. +++ b/kernel/rcu/tree_plugin.h
  83104. @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
  83105. static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
  83106. {
  83107. return !rcu_preempted_readers_exp(rnp) &&
  83108. - ACCESS_ONCE(rnp->expmask) == 0;
  83109. + ACCESS_ONCE_RW(rnp->expmask) == 0;
  83110. }
  83111. /*
  83112. @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
  83113. /* Clean up and exit. */
  83114. smp_mb(); /* ensure expedited GP seen before counter increment. */
  83115. - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
  83116. + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
  83117. unlock_mb_ret:
  83118. mutex_unlock(&sync_rcu_preempt_exp_mutex);
  83119. mb_ret:
  83120. @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
  83121. free_cpumask_var(cm);
  83122. }
  83123. -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  83124. +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
  83125. .store = &rcu_cpu_kthread_task,
  83126. .thread_should_run = rcu_cpu_kthread_should_run,
  83127. .thread_fn = rcu_cpu_kthread,
  83128. @@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
  83129. print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
  83130. pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
  83131. cpu, ticks_value, ticks_title,
  83132. - atomic_read(&rdtp->dynticks) & 0xfff,
  83133. + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
  83134. rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
  83135. rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
  83136. fast_no_hz);
  83137. @@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
  83138. /* Enqueue the callback on the nocb list and update counts. */
  83139. old_rhpp = xchg(&rdp->nocb_tail, rhtp);
  83140. - ACCESS_ONCE(*old_rhpp) = rhp;
  83141. + ACCESS_ONCE_RW(*old_rhpp) = rhp;
  83142. atomic_long_add(rhcount, &rdp->nocb_q_count);
  83143. atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
  83144. @@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
  83145. * Extract queued callbacks, update counts, and wait
  83146. * for a grace period to elapse.
  83147. */
  83148. - ACCESS_ONCE(rdp->nocb_head) = NULL;
  83149. + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
  83150. tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
  83151. c = atomic_long_xchg(&rdp->nocb_q_count, 0);
  83152. cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
  83153. - ACCESS_ONCE(rdp->nocb_p_count) += c;
  83154. - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
  83155. + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
  83156. + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
  83157. rcu_nocb_wait_gp(rdp);
  83158. /* Each pass through the following loop invokes a callback. */
  83159. @@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
  83160. list = next;
  83161. }
  83162. trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
  83163. - ACCESS_ONCE(rdp->nocb_p_count) -= c;
  83164. - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
  83165. + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
  83166. + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
  83167. rdp->n_nocbs_invoked += c;
  83168. }
  83169. return 0;
  83170. @@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
  83171. {
  83172. if (!rcu_nocb_need_deferred_wakeup(rdp))
  83173. return;
  83174. - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
  83175. + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
  83176. wake_up(&rdp->nocb_wq);
  83177. trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
  83178. }
  83179. @@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
  83180. t = kthread_run(rcu_nocb_kthread, rdp,
  83181. "rcuo%c/%d", rsp->abbr, cpu);
  83182. BUG_ON(IS_ERR(t));
  83183. - ACCESS_ONCE(rdp->nocb_kthread) = t;
  83184. + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
  83185. }
  83186. }
  83187. @@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
  83188. /* Record start of fully idle period. */
  83189. j = jiffies;
  83190. - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
  83191. + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
  83192. smp_mb__before_atomic_inc();
  83193. - atomic_inc(&rdtp->dynticks_idle);
  83194. + atomic_inc_unchecked(&rdtp->dynticks_idle);
  83195. smp_mb__after_atomic_inc();
  83196. - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
  83197. + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
  83198. }
  83199. /*
  83200. @@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
  83201. /* Record end of idle period. */
  83202. smp_mb__before_atomic_inc();
  83203. - atomic_inc(&rdtp->dynticks_idle);
  83204. + atomic_inc_unchecked(&rdtp->dynticks_idle);
  83205. smp_mb__after_atomic_inc();
  83206. - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
  83207. + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
  83208. /*
  83209. * If we are the timekeeping CPU, we are permitted to be non-idle
  83210. @@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
  83211. WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
  83212. /* Pick up current idle and NMI-nesting counter and check. */
  83213. - cur = atomic_read(&rdtp->dynticks_idle);
  83214. + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
  83215. if (cur & 0x1) {
  83216. *isidle = false; /* We are not idle! */
  83217. return;
  83218. @@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
  83219. case RCU_SYSIDLE_NOT:
  83220. /* First time all are idle, so note a short idle period. */
  83221. - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
  83222. + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
  83223. break;
  83224. case RCU_SYSIDLE_SHORT:
  83225. @@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
  83226. static void rcu_sysidle_cancel(void)
  83227. {
  83228. smp_mb();
  83229. - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
  83230. + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
  83231. }
  83232. /*
  83233. @@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
  83234. smp_mb(); /* grace period precedes setting inuse. */
  83235. rshp = container_of(rhp, struct rcu_sysidle_head, rh);
  83236. - ACCESS_ONCE(rshp->inuse) = 0;
  83237. + ACCESS_ONCE_RW(rshp->inuse) = 0;
  83238. }
  83239. /*
  83240. diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
  83241. index 4def475..8ffddde 100644
  83242. --- a/kernel/rcu/tree_trace.c
  83243. +++ b/kernel/rcu/tree_trace.c
  83244. @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
  83245. ulong2long(rdp->completed), ulong2long(rdp->gpnum),
  83246. rdp->passed_quiesce, rdp->qs_pending);
  83247. seq_printf(m, " dt=%d/%llx/%d df=%lu",
  83248. - atomic_read(&rdp->dynticks->dynticks),
  83249. + atomic_read_unchecked(&rdp->dynticks->dynticks),
  83250. rdp->dynticks->dynticks_nesting,
  83251. rdp->dynticks->dynticks_nmi_nesting,
  83252. rdp->dynticks_fqs);
  83253. @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
  83254. struct rcu_state *rsp = (struct rcu_state *)m->private;
  83255. seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
  83256. - atomic_long_read(&rsp->expedited_start),
  83257. + atomic_long_read_unchecked(&rsp->expedited_start),
  83258. atomic_long_read(&rsp->expedited_done),
  83259. - atomic_long_read(&rsp->expedited_wrap),
  83260. - atomic_long_read(&rsp->expedited_tryfail),
  83261. - atomic_long_read(&rsp->expedited_workdone1),
  83262. - atomic_long_read(&rsp->expedited_workdone2),
  83263. - atomic_long_read(&rsp->expedited_normal),
  83264. - atomic_long_read(&rsp->expedited_stoppedcpus),
  83265. - atomic_long_read(&rsp->expedited_done_tries),
  83266. - atomic_long_read(&rsp->expedited_done_lost),
  83267. - atomic_long_read(&rsp->expedited_done_exit));
  83268. + atomic_long_read_unchecked(&rsp->expedited_wrap),
  83269. + atomic_long_read_unchecked(&rsp->expedited_tryfail),
  83270. + atomic_long_read_unchecked(&rsp->expedited_workdone1),
  83271. + atomic_long_read_unchecked(&rsp->expedited_workdone2),
  83272. + atomic_long_read_unchecked(&rsp->expedited_normal),
  83273. + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
  83274. + atomic_long_read_unchecked(&rsp->expedited_done_tries),
  83275. + atomic_long_read_unchecked(&rsp->expedited_done_lost),
  83276. + atomic_long_read_unchecked(&rsp->expedited_done_exit));
  83277. return 0;
  83278. }
  83279. diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
  83280. index c54609f..2e8829c 100644
  83281. --- a/kernel/rcu/update.c
  83282. +++ b/kernel/rcu/update.c
  83283. @@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
  83284. * for CONFIG_RCU_CPU_STALL_TIMEOUT.
  83285. */
  83286. if (till_stall_check < 3) {
  83287. - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
  83288. + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
  83289. till_stall_check = 3;
  83290. } else if (till_stall_check > 300) {
  83291. - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
  83292. + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
  83293. till_stall_check = 300;
  83294. }
  83295. return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
  83296. diff --git a/kernel/resource.c b/kernel/resource.c
  83297. index 3f285dc..5755f62 100644
  83298. --- a/kernel/resource.c
  83299. +++ b/kernel/resource.c
  83300. @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
  83301. static int __init ioresources_init(void)
  83302. {
  83303. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  83304. +#ifdef CONFIG_GRKERNSEC_PROC_USER
  83305. + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
  83306. + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
  83307. +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  83308. + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
  83309. + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
  83310. +#endif
  83311. +#else
  83312. proc_create("ioports", 0, NULL, &proc_ioports_operations);
  83313. proc_create("iomem", 0, NULL, &proc_iomem_operations);
  83314. +#endif
  83315. return 0;
  83316. }
  83317. __initcall(ioresources_init);
  83318. diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
  83319. index 4a07353..66b5291 100644
  83320. --- a/kernel/sched/auto_group.c
  83321. +++ b/kernel/sched/auto_group.c
  83322. @@ -11,7 +11,7 @@
  83323. unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
  83324. static struct autogroup autogroup_default;
  83325. -static atomic_t autogroup_seq_nr;
  83326. +static atomic_unchecked_t autogroup_seq_nr;
  83327. void __init autogroup_init(struct task_struct *init_task)
  83328. {
  83329. @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
  83330. kref_init(&ag->kref);
  83331. init_rwsem(&ag->lock);
  83332. - ag->id = atomic_inc_return(&autogroup_seq_nr);
  83333. + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
  83334. ag->tg = tg;
  83335. #ifdef CONFIG_RT_GROUP_SCHED
  83336. /*
  83337. diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
  83338. index a63f4dc..349bbb0 100644
  83339. --- a/kernel/sched/completion.c
  83340. +++ b/kernel/sched/completion.c
  83341. @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
  83342. * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
  83343. * or number of jiffies left till timeout) if completed.
  83344. */
  83345. -long __sched
  83346. +long __sched __intentional_overflow(-1)
  83347. wait_for_completion_interruptible_timeout(struct completion *x,
  83348. unsigned long timeout)
  83349. {
  83350. @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
  83351. *
  83352. * Return: -ERESTARTSYS if interrupted, 0 if completed.
  83353. */
  83354. -int __sched wait_for_completion_killable(struct completion *x)
  83355. +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
  83356. {
  83357. long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
  83358. if (t == -ERESTARTSYS)
  83359. @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
  83360. * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
  83361. * or number of jiffies left till timeout) if completed.
  83362. */
  83363. -long __sched
  83364. +long __sched __intentional_overflow(-1)
  83365. wait_for_completion_killable_timeout(struct completion *x,
  83366. unsigned long timeout)
  83367. {
  83368. diff --git a/kernel/sched/core.c b/kernel/sched/core.c
  83369. index f5c6635..ab9f223 100644
  83370. --- a/kernel/sched/core.c
  83371. +++ b/kernel/sched/core.c
  83372. @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
  83373. int sysctl_numa_balancing(struct ctl_table *table, int write,
  83374. void __user *buffer, size_t *lenp, loff_t *ppos)
  83375. {
  83376. - struct ctl_table t;
  83377. + ctl_table_no_const t;
  83378. int err;
  83379. int state = numabalancing_enabled;
  83380. @@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
  83381. /* convert nice value [19,-20] to rlimit style value [1,40] */
  83382. int nice_rlim = 20 - nice;
  83383. + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
  83384. +
  83385. return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
  83386. capable(CAP_SYS_NICE));
  83387. }
  83388. @@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
  83389. if (nice > 19)
  83390. nice = 19;
  83391. - if (increment < 0 && !can_nice(current, nice))
  83392. + if (increment < 0 && (!can_nice(current, nice) ||
  83393. + gr_handle_chroot_nice()))
  83394. return -EPERM;
  83395. retval = security_task_setnice(current, nice);
  83396. @@ -3332,6 +3335,7 @@ recheck:
  83397. if (policy != p->policy && !rlim_rtprio)
  83398. return -EPERM;
  83399. + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
  83400. /* can't increase priority */
  83401. if (attr->sched_priority > p->rt_priority &&
  83402. attr->sched_priority > rlim_rtprio)
  83403. @@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
  83404. #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
  83405. -static struct ctl_table sd_ctl_dir[] = {
  83406. +static ctl_table_no_const sd_ctl_dir[] __read_only = {
  83407. {
  83408. .procname = "sched_domain",
  83409. .mode = 0555,
  83410. @@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
  83411. {}
  83412. };
  83413. -static struct ctl_table *sd_alloc_ctl_entry(int n)
  83414. +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
  83415. {
  83416. - struct ctl_table *entry =
  83417. + ctl_table_no_const *entry =
  83418. kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
  83419. return entry;
  83420. }
  83421. -static void sd_free_ctl_entry(struct ctl_table **tablep)
  83422. +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
  83423. {
  83424. - struct ctl_table *entry;
  83425. + ctl_table_no_const *entry;
  83426. /*
  83427. * In the intermediate directories, both the child directory and
  83428. @@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
  83429. * will always be set. In the lowest directory the names are
  83430. * static strings and all have proc handlers.
  83431. */
  83432. - for (entry = *tablep; entry->mode; entry++) {
  83433. - if (entry->child)
  83434. - sd_free_ctl_entry(&entry->child);
  83435. + for (entry = tablep; entry->mode; entry++) {
  83436. + if (entry->child) {
  83437. + sd_free_ctl_entry(entry->child);
  83438. + pax_open_kernel();
  83439. + entry->child = NULL;
  83440. + pax_close_kernel();
  83441. + }
  83442. if (entry->proc_handler == NULL)
  83443. kfree(entry->procname);
  83444. }
  83445. - kfree(*tablep);
  83446. - *tablep = NULL;
  83447. + kfree(tablep);
  83448. }
  83449. static int min_load_idx = 0;
  83450. static int max_load_idx = CPU_LOAD_IDX_MAX-1;
  83451. static void
  83452. -set_table_entry(struct ctl_table *entry,
  83453. +set_table_entry(ctl_table_no_const *entry,
  83454. const char *procname, void *data, int maxlen,
  83455. umode_t mode, proc_handler *proc_handler,
  83456. bool load_idx)
  83457. @@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
  83458. static struct ctl_table *
  83459. sd_alloc_ctl_domain_table(struct sched_domain *sd)
  83460. {
  83461. - struct ctl_table *table = sd_alloc_ctl_entry(13);
  83462. + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
  83463. if (table == NULL)
  83464. return NULL;
  83465. @@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
  83466. return table;
  83467. }
  83468. -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
  83469. +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
  83470. {
  83471. - struct ctl_table *entry, *table;
  83472. + ctl_table_no_const *entry, *table;
  83473. struct sched_domain *sd;
  83474. int domain_num = 0, i;
  83475. char buf[32];
  83476. @@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
  83477. static void register_sched_domain_sysctl(void)
  83478. {
  83479. int i, cpu_num = num_possible_cpus();
  83480. - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
  83481. + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
  83482. char buf[32];
  83483. WARN_ON(sd_ctl_dir[0].child);
  83484. + pax_open_kernel();
  83485. sd_ctl_dir[0].child = entry;
  83486. + pax_close_kernel();
  83487. if (entry == NULL)
  83488. return;
  83489. @@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
  83490. if (sd_sysctl_header)
  83491. unregister_sysctl_table(sd_sysctl_header);
  83492. sd_sysctl_header = NULL;
  83493. - if (sd_ctl_dir[0].child)
  83494. - sd_free_ctl_entry(&sd_ctl_dir[0].child);
  83495. + if (sd_ctl_dir[0].child) {
  83496. + sd_free_ctl_entry(sd_ctl_dir[0].child);
  83497. + pax_open_kernel();
  83498. + sd_ctl_dir[0].child = NULL;
  83499. + pax_close_kernel();
  83500. + }
  83501. }
  83502. #else
  83503. static void register_sched_domain_sysctl(void)
  83504. diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
  83505. index 9b4c4f3..665489b 100644
  83506. --- a/kernel/sched/fair.c
  83507. +++ b/kernel/sched/fair.c
  83508. @@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
  83509. static void reset_ptenuma_scan(struct task_struct *p)
  83510. {
  83511. - ACCESS_ONCE(p->mm->numa_scan_seq)++;
  83512. + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
  83513. p->mm->numa_scan_offset = 0;
  83514. }
  83515. @@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
  83516. * run_rebalance_domains is triggered when needed from the scheduler tick.
  83517. * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
  83518. */
  83519. -static void run_rebalance_domains(struct softirq_action *h)
  83520. +static __latent_entropy void run_rebalance_domains(void)
  83521. {
  83522. struct rq *this_rq = this_rq();
  83523. enum cpu_idle_type idle = this_rq->idle_balance ?
  83524. diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
  83525. index f964add..dcd823d 100644
  83526. --- a/kernel/sched/sched.h
  83527. +++ b/kernel/sched/sched.h
  83528. @@ -1157,7 +1157,7 @@ struct sched_class {
  83529. #ifdef CONFIG_FAIR_GROUP_SCHED
  83530. void (*task_move_group) (struct task_struct *p, int on_rq);
  83531. #endif
  83532. -};
  83533. +} __do_const;
  83534. #define sched_class_highest (&stop_sched_class)
  83535. #define for_each_class(class) \
  83536. diff --git a/kernel/signal.c b/kernel/signal.c
  83537. index 52f881d..1e9f941 100644
  83538. --- a/kernel/signal.c
  83539. +++ b/kernel/signal.c
  83540. @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
  83541. int print_fatal_signals __read_mostly;
  83542. -static void __user *sig_handler(struct task_struct *t, int sig)
  83543. +static __sighandler_t sig_handler(struct task_struct *t, int sig)
  83544. {
  83545. return t->sighand->action[sig - 1].sa.sa_handler;
  83546. }
  83547. -static int sig_handler_ignored(void __user *handler, int sig)
  83548. +static int sig_handler_ignored(__sighandler_t handler, int sig)
  83549. {
  83550. /* Is it explicitly or implicitly ignored? */
  83551. return handler == SIG_IGN ||
  83552. @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
  83553. static int sig_task_ignored(struct task_struct *t, int sig, bool force)
  83554. {
  83555. - void __user *handler;
  83556. + __sighandler_t handler;
  83557. handler = sig_handler(t, sig);
  83558. @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
  83559. atomic_inc(&user->sigpending);
  83560. rcu_read_unlock();
  83561. + if (!override_rlimit)
  83562. + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
  83563. +
  83564. if (override_rlimit ||
  83565. atomic_read(&user->sigpending) <=
  83566. task_rlimit(t, RLIMIT_SIGPENDING)) {
  83567. @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
  83568. int unhandled_signal(struct task_struct *tsk, int sig)
  83569. {
  83570. - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
  83571. + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
  83572. if (is_global_init(tsk))
  83573. return 1;
  83574. if (handler != SIG_IGN && handler != SIG_DFL)
  83575. @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
  83576. }
  83577. }
  83578. + /* allow glibc communication via tgkill to other threads in our
  83579. + thread group */
  83580. + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
  83581. + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
  83582. + && gr_handle_signal(t, sig))
  83583. + return -EPERM;
  83584. +
  83585. return security_task_kill(t, info, sig, 0);
  83586. }
  83587. @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  83588. return send_signal(sig, info, p, 1);
  83589. }
  83590. -static int
  83591. +int
  83592. specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  83593. {
  83594. return send_signal(sig, info, t, 0);
  83595. @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  83596. unsigned long int flags;
  83597. int ret, blocked, ignored;
  83598. struct k_sigaction *action;
  83599. + int is_unhandled = 0;
  83600. spin_lock_irqsave(&t->sighand->siglock, flags);
  83601. action = &t->sighand->action[sig-1];
  83602. @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  83603. }
  83604. if (action->sa.sa_handler == SIG_DFL)
  83605. t->signal->flags &= ~SIGNAL_UNKILLABLE;
  83606. + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
  83607. + is_unhandled = 1;
  83608. ret = specific_send_sig_info(sig, info, t);
  83609. spin_unlock_irqrestore(&t->sighand->siglock, flags);
  83610. + /* only deal with unhandled signals, java etc trigger SIGSEGV during
  83611. + normal operation */
  83612. + if (is_unhandled) {
  83613. + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
  83614. + gr_handle_crash(t, sig);
  83615. + }
  83616. +
  83617. return ret;
  83618. }
  83619. @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  83620. ret = check_kill_permission(sig, info, p);
  83621. rcu_read_unlock();
  83622. - if (!ret && sig)
  83623. + if (!ret && sig) {
  83624. ret = do_send_sig_info(sig, info, p, true);
  83625. + if (!ret)
  83626. + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
  83627. + }
  83628. return ret;
  83629. }
  83630. @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
  83631. int error = -ESRCH;
  83632. rcu_read_lock();
  83633. - p = find_task_by_vpid(pid);
  83634. +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
  83635. + /* allow glibc communication via tgkill to other threads in our
  83636. + thread group */
  83637. + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
  83638. + sig == (SIGRTMIN+1) && tgid == info->si_pid)
  83639. + p = find_task_by_vpid_unrestricted(pid);
  83640. + else
  83641. +#endif
  83642. + p = find_task_by_vpid(pid);
  83643. if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
  83644. error = check_kill_permission(sig, info, p);
  83645. /*
  83646. @@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
  83647. }
  83648. seg = get_fs();
  83649. set_fs(KERNEL_DS);
  83650. - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
  83651. - (stack_t __force __user *) &uoss,
  83652. + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
  83653. + (stack_t __force_user *) &uoss,
  83654. compat_user_stack_pointer());
  83655. set_fs(seg);
  83656. if (ret >= 0 && uoss_ptr) {
  83657. diff --git a/kernel/smpboot.c b/kernel/smpboot.c
  83658. index eb89e18..a4e6792 100644
  83659. --- a/kernel/smpboot.c
  83660. +++ b/kernel/smpboot.c
  83661. @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
  83662. }
  83663. smpboot_unpark_thread(plug_thread, cpu);
  83664. }
  83665. - list_add(&plug_thread->list, &hotplug_threads);
  83666. + pax_list_add(&plug_thread->list, &hotplug_threads);
  83667. out:
  83668. mutex_unlock(&smpboot_threads_lock);
  83669. return ret;
  83670. @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
  83671. {
  83672. get_online_cpus();
  83673. mutex_lock(&smpboot_threads_lock);
  83674. - list_del(&plug_thread->list);
  83675. + pax_list_del(&plug_thread->list);
  83676. smpboot_destroy_threads(plug_thread);
  83677. mutex_unlock(&smpboot_threads_lock);
  83678. put_online_cpus();
  83679. diff --git a/kernel/softirq.c b/kernel/softirq.c
  83680. index 490fcbb..1e502c6 100644
  83681. --- a/kernel/softirq.c
  83682. +++ b/kernel/softirq.c
  83683. @@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
  83684. EXPORT_SYMBOL(irq_stat);
  83685. #endif
  83686. -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
  83687. +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
  83688. DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
  83689. @@ -267,7 +267,7 @@ restart:
  83690. kstat_incr_softirqs_this_cpu(vec_nr);
  83691. trace_softirq_entry(vec_nr);
  83692. - h->action(h);
  83693. + h->action();
  83694. trace_softirq_exit(vec_nr);
  83695. if (unlikely(prev_count != preempt_count())) {
  83696. pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  83697. @@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
  83698. or_softirq_pending(1UL << nr);
  83699. }
  83700. -void open_softirq(int nr, void (*action)(struct softirq_action *))
  83701. +void __init open_softirq(int nr, void (*action)(void))
  83702. {
  83703. softirq_vec[nr].action = action;
  83704. }
  83705. @@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
  83706. }
  83707. EXPORT_SYMBOL(__tasklet_hi_schedule_first);
  83708. -static void tasklet_action(struct softirq_action *a)
  83709. +static void tasklet_action(void)
  83710. {
  83711. struct tasklet_struct *list;
  83712. @@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
  83713. }
  83714. }
  83715. -static void tasklet_hi_action(struct softirq_action *a)
  83716. +static __latent_entropy void tasklet_hi_action(void)
  83717. {
  83718. struct tasklet_struct *list;
  83719. @@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
  83720. .notifier_call = cpu_callback
  83721. };
  83722. -static struct smp_hotplug_thread softirq_threads = {
  83723. +static struct smp_hotplug_thread softirq_threads __read_only = {
  83724. .store = &ksoftirqd,
  83725. .thread_should_run = ksoftirqd_should_run,
  83726. .thread_fn = run_ksoftirqd,
  83727. diff --git a/kernel/sys.c b/kernel/sys.c
  83728. index c0a58be..784c618 100644
  83729. --- a/kernel/sys.c
  83730. +++ b/kernel/sys.c
  83731. @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
  83732. error = -EACCES;
  83733. goto out;
  83734. }
  83735. +
  83736. + if (gr_handle_chroot_setpriority(p, niceval)) {
  83737. + error = -EACCES;
  83738. + goto out;
  83739. + }
  83740. +
  83741. no_nice = security_task_setnice(p, niceval);
  83742. if (no_nice) {
  83743. error = no_nice;
  83744. @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
  83745. goto error;
  83746. }
  83747. + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
  83748. + goto error;
  83749. +
  83750. if (rgid != (gid_t) -1 ||
  83751. (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
  83752. new->sgid = new->egid;
  83753. @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
  83754. old = current_cred();
  83755. retval = -EPERM;
  83756. +
  83757. + if (gr_check_group_change(kgid, kgid, kgid))
  83758. + goto error;
  83759. +
  83760. if (ns_capable(old->user_ns, CAP_SETGID))
  83761. new->gid = new->egid = new->sgid = new->fsgid = kgid;
  83762. else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
  83763. @@ -403,7 +416,7 @@ error:
  83764. /*
  83765. * change the user struct in a credentials set to match the new UID
  83766. */
  83767. -static int set_user(struct cred *new)
  83768. +int set_user(struct cred *new)
  83769. {
  83770. struct user_struct *new_user;
  83771. @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
  83772. goto error;
  83773. }
  83774. + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
  83775. + goto error;
  83776. +
  83777. if (!uid_eq(new->uid, old->uid)) {
  83778. retval = set_user(new);
  83779. if (retval < 0)
  83780. @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
  83781. old = current_cred();
  83782. retval = -EPERM;
  83783. +
  83784. + if (gr_check_crash_uid(kuid))
  83785. + goto error;
  83786. + if (gr_check_user_change(kuid, kuid, kuid))
  83787. + goto error;
  83788. +
  83789. if (ns_capable(old->user_ns, CAP_SETUID)) {
  83790. new->suid = new->uid = kuid;
  83791. if (!uid_eq(kuid, old->uid)) {
  83792. @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
  83793. goto error;
  83794. }
  83795. + if (gr_check_user_change(kruid, keuid, INVALID_UID))
  83796. + goto error;
  83797. +
  83798. if (ruid != (uid_t) -1) {
  83799. new->uid = kruid;
  83800. if (!uid_eq(kruid, old->uid)) {
  83801. @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
  83802. goto error;
  83803. }
  83804. + if (gr_check_group_change(krgid, kegid, INVALID_GID))
  83805. + goto error;
  83806. +
  83807. if (rgid != (gid_t) -1)
  83808. new->gid = krgid;
  83809. if (egid != (gid_t) -1)
  83810. @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
  83811. uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
  83812. ns_capable(old->user_ns, CAP_SETUID)) {
  83813. if (!uid_eq(kuid, old->fsuid)) {
  83814. + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
  83815. + goto error;
  83816. +
  83817. new->fsuid = kuid;
  83818. if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
  83819. goto change_okay;
  83820. }
  83821. }
  83822. +error:
  83823. abort_creds(new);
  83824. return old_fsuid;
  83825. @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
  83826. if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
  83827. gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
  83828. ns_capable(old->user_ns, CAP_SETGID)) {
  83829. + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
  83830. + goto error;
  83831. +
  83832. if (!gid_eq(kgid, old->fsgid)) {
  83833. new->fsgid = kgid;
  83834. goto change_okay;
  83835. }
  83836. }
  83837. +error:
  83838. abort_creds(new);
  83839. return old_fsgid;
  83840. @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
  83841. return -EFAULT;
  83842. down_read(&uts_sem);
  83843. - error = __copy_to_user(&name->sysname, &utsname()->sysname,
  83844. + error = __copy_to_user(name->sysname, &utsname()->sysname,
  83845. __OLD_UTS_LEN);
  83846. error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
  83847. - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
  83848. + error |= __copy_to_user(name->nodename, &utsname()->nodename,
  83849. __OLD_UTS_LEN);
  83850. error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
  83851. - error |= __copy_to_user(&name->release, &utsname()->release,
  83852. + error |= __copy_to_user(name->release, &utsname()->release,
  83853. __OLD_UTS_LEN);
  83854. error |= __put_user(0, name->release + __OLD_UTS_LEN);
  83855. - error |= __copy_to_user(&name->version, &utsname()->version,
  83856. + error |= __copy_to_user(name->version, &utsname()->version,
  83857. __OLD_UTS_LEN);
  83858. error |= __put_user(0, name->version + __OLD_UTS_LEN);
  83859. - error |= __copy_to_user(&name->machine, &utsname()->machine,
  83860. + error |= __copy_to_user(name->machine, &utsname()->machine,
  83861. __OLD_UTS_LEN);
  83862. error |= __put_user(0, name->machine + __OLD_UTS_LEN);
  83863. up_read(&uts_sem);
  83864. @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
  83865. */
  83866. new_rlim->rlim_cur = 1;
  83867. }
  83868. + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
  83869. + is changed to a lower value. Since tasks can be created by the same
  83870. + user in between this limit change and an execve by this task, force
  83871. + a recheck only for this task by setting PF_NPROC_EXCEEDED
  83872. + */
  83873. + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
  83874. + tsk->flags |= PF_NPROC_EXCEEDED;
  83875. }
  83876. if (!retval) {
  83877. if (old_rlim)
  83878. diff --git a/kernel/sysctl.c b/kernel/sysctl.c
  83879. index aae21e8..58d8c9a 100644
  83880. --- a/kernel/sysctl.c
  83881. +++ b/kernel/sysctl.c
  83882. @@ -94,7 +94,6 @@
  83883. #if defined(CONFIG_SYSCTL)
  83884. -
  83885. /* External variables not in a header file. */
  83886. extern int max_threads;
  83887. extern int suid_dumpable;
  83888. @@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
  83889. /* Constants used for minimum and maximum */
  83890. #ifdef CONFIG_LOCKUP_DETECTOR
  83891. -static int sixty = 60;
  83892. +static int sixty __read_only = 60;
  83893. #endif
  83894. -static int __maybe_unused neg_one = -1;
  83895. -
  83896. -static int zero;
  83897. -static int __maybe_unused one = 1;
  83898. -static int __maybe_unused two = 2;
  83899. -static int __maybe_unused three = 3;
  83900. -static unsigned long one_ul = 1;
  83901. -static int one_hundred = 100;
  83902. +static int __maybe_unused neg_one __read_only = -1;
  83903. +static int zero __read_only = 0;
  83904. +static int __maybe_unused one __read_only = 1;
  83905. +static int __maybe_unused two __read_only = 2;
  83906. +static int __maybe_unused three __read_only = 3;
  83907. +static unsigned long one_ul __read_only = 1;
  83908. +static int one_hundred __read_only = 100;
  83909. #ifdef CONFIG_PRINTK
  83910. -static int ten_thousand = 10000;
  83911. +static int ten_thousand __read_only = 10000;
  83912. #endif
  83913. /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
  83914. @@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
  83915. void __user *buffer, size_t *lenp, loff_t *ppos);
  83916. #endif
  83917. -#ifdef CONFIG_PRINTK
  83918. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  83919. void __user *buffer, size_t *lenp, loff_t *ppos);
  83920. -#endif
  83921. static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
  83922. void __user *buffer, size_t *lenp, loff_t *ppos);
  83923. @@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
  83924. #endif
  83925. +extern struct ctl_table grsecurity_table[];
  83926. +
  83927. static struct ctl_table kern_table[];
  83928. static struct ctl_table vm_table[];
  83929. static struct ctl_table fs_table[];
  83930. @@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
  83931. int sysctl_legacy_va_layout;
  83932. #endif
  83933. +#ifdef CONFIG_PAX_SOFTMODE
  83934. +static ctl_table pax_table[] = {
  83935. + {
  83936. + .procname = "softmode",
  83937. + .data = &pax_softmode,
  83938. + .maxlen = sizeof(unsigned int),
  83939. + .mode = 0600,
  83940. + .proc_handler = &proc_dointvec,
  83941. + },
  83942. +
  83943. + { }
  83944. +};
  83945. +#endif
  83946. +
  83947. /* The default sysctl tables: */
  83948. static struct ctl_table sysctl_base_table[] = {
  83949. @@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
  83950. #endif
  83951. static struct ctl_table kern_table[] = {
  83952. +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
  83953. + {
  83954. + .procname = "grsecurity",
  83955. + .mode = 0500,
  83956. + .child = grsecurity_table,
  83957. + },
  83958. +#endif
  83959. +
  83960. +#ifdef CONFIG_PAX_SOFTMODE
  83961. + {
  83962. + .procname = "pax",
  83963. + .mode = 0500,
  83964. + .child = pax_table,
  83965. + },
  83966. +#endif
  83967. +
  83968. {
  83969. .procname = "sched_child_runs_first",
  83970. .data = &sysctl_sched_child_runs_first,
  83971. @@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
  83972. .data = &modprobe_path,
  83973. .maxlen = KMOD_PATH_LEN,
  83974. .mode = 0644,
  83975. - .proc_handler = proc_dostring,
  83976. + .proc_handler = proc_dostring_modpriv,
  83977. },
  83978. {
  83979. .procname = "modules_disabled",
  83980. @@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
  83981. .extra1 = &zero,
  83982. .extra2 = &one,
  83983. },
  83984. +#endif
  83985. {
  83986. .procname = "kptr_restrict",
  83987. .data = &kptr_restrict,
  83988. .maxlen = sizeof(int),
  83989. .mode = 0644,
  83990. .proc_handler = proc_dointvec_minmax_sysadmin,
  83991. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  83992. + .extra1 = &two,
  83993. +#else
  83994. .extra1 = &zero,
  83995. +#endif
  83996. .extra2 = &two,
  83997. },
  83998. -#endif
  83999. {
  84000. .procname = "ngroups_max",
  84001. .data = &ngroups_max,
  84002. @@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
  84003. */
  84004. {
  84005. .procname = "perf_event_paranoid",
  84006. - .data = &sysctl_perf_event_paranoid,
  84007. - .maxlen = sizeof(sysctl_perf_event_paranoid),
  84008. + .data = &sysctl_perf_event_legitimately_concerned,
  84009. + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
  84010. .mode = 0644,
  84011. - .proc_handler = proc_dointvec,
  84012. + /* go ahead, be a hero */
  84013. + .proc_handler = proc_dointvec_minmax_sysadmin,
  84014. + .extra1 = &neg_one,
  84015. +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
  84016. + .extra2 = &three,
  84017. +#else
  84018. + .extra2 = &two,
  84019. +#endif
  84020. },
  84021. {
  84022. .procname = "perf_event_mlock_kb",
  84023. @@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
  84024. .proc_handler = proc_dointvec_minmax,
  84025. .extra1 = &zero,
  84026. },
  84027. + {
  84028. + .procname = "heap_stack_gap",
  84029. + .data = &sysctl_heap_stack_gap,
  84030. + .maxlen = sizeof(sysctl_heap_stack_gap),
  84031. + .mode = 0644,
  84032. + .proc_handler = proc_doulongvec_minmax,
  84033. + },
  84034. #else
  84035. {
  84036. .procname = "nr_trim_pages",
  84037. @@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
  84038. buffer, lenp, ppos);
  84039. }
  84040. +int proc_dostring_modpriv(struct ctl_table *table, int write,
  84041. + void __user *buffer, size_t *lenp, loff_t *ppos)
  84042. +{
  84043. + if (write && !capable(CAP_SYS_MODULE))
  84044. + return -EPERM;
  84045. +
  84046. + return _proc_do_string(table->data, table->maxlen, write,
  84047. + buffer, lenp, ppos);
  84048. +}
  84049. +
  84050. static size_t proc_skip_spaces(char **buf)
  84051. {
  84052. size_t ret;
  84053. @@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
  84054. len = strlen(tmp);
  84055. if (len > *size)
  84056. len = *size;
  84057. + if (len > sizeof(tmp))
  84058. + len = sizeof(tmp);
  84059. if (copy_to_user(*buf, tmp, len))
  84060. return -EFAULT;
  84061. *size -= len;
  84062. @@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
  84063. static int proc_taint(struct ctl_table *table, int write,
  84064. void __user *buffer, size_t *lenp, loff_t *ppos)
  84065. {
  84066. - struct ctl_table t;
  84067. + ctl_table_no_const t;
  84068. unsigned long tmptaint = get_taint();
  84069. int err;
  84070. @@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
  84071. return err;
  84072. }
  84073. -#ifdef CONFIG_PRINTK
  84074. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  84075. void __user *buffer, size_t *lenp, loff_t *ppos)
  84076. {
  84077. @@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  84078. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  84079. }
  84080. -#endif
  84081. struct do_proc_dointvec_minmax_conv_param {
  84082. int *min;
  84083. @@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
  84084. return -ENOSYS;
  84085. }
  84086. +int proc_dostring_modpriv(struct ctl_table *table, int write,
  84087. + void __user *buffer, size_t *lenp, loff_t *ppos)
  84088. +{
  84089. + return -ENOSYS;
  84090. +}
  84091. +
  84092. int proc_dointvec(struct ctl_table *table, int write,
  84093. void __user *buffer, size_t *lenp, loff_t *ppos)
  84094. {
  84095. @@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
  84096. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  84097. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  84098. EXPORT_SYMBOL(proc_dostring);
  84099. +EXPORT_SYMBOL(proc_dostring_modpriv);
  84100. EXPORT_SYMBOL(proc_doulongvec_minmax);
  84101. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  84102. diff --git a/kernel/taskstats.c b/kernel/taskstats.c
  84103. index 13d2f7c..c93d0b0 100644
  84104. --- a/kernel/taskstats.c
  84105. +++ b/kernel/taskstats.c
  84106. @@ -28,9 +28,12 @@
  84107. #include <linux/fs.h>
  84108. #include <linux/file.h>
  84109. #include <linux/pid_namespace.h>
  84110. +#include <linux/grsecurity.h>
  84111. #include <net/genetlink.h>
  84112. #include <linux/atomic.h>
  84113. +extern int gr_is_taskstats_denied(int pid);
  84114. +
  84115. /*
  84116. * Maximum length of a cpumask that can be specified in
  84117. * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
  84118. @@ -576,6 +579,9 @@ err:
  84119. static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
  84120. {
  84121. + if (gr_is_taskstats_denied(current->pid))
  84122. + return -EACCES;
  84123. +
  84124. if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
  84125. return cmd_attr_register_cpumask(info);
  84126. else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
  84127. diff --git a/kernel/time.c b/kernel/time.c
  84128. index 7c7964c..2a0d412 100644
  84129. --- a/kernel/time.c
  84130. +++ b/kernel/time.c
  84131. @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
  84132. return error;
  84133. if (tz) {
  84134. + /* we log in do_settimeofday called below, so don't log twice
  84135. + */
  84136. + if (!tv)
  84137. + gr_log_timechange();
  84138. +
  84139. sys_tz = *tz;
  84140. update_vsyscall_tz();
  84141. if (firsttime) {
  84142. diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
  84143. index 88c9c65..7497ebc 100644
  84144. --- a/kernel/time/alarmtimer.c
  84145. +++ b/kernel/time/alarmtimer.c
  84146. @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
  84147. struct platform_device *pdev;
  84148. int error = 0;
  84149. int i;
  84150. - struct k_clock alarm_clock = {
  84151. + static struct k_clock alarm_clock = {
  84152. .clock_getres = alarm_clock_getres,
  84153. .clock_get = alarm_clock_get,
  84154. .timer_create = alarm_timer_create,
  84155. diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
  84156. index 5b40279..81e58db 100644
  84157. --- a/kernel/time/timekeeping.c
  84158. +++ b/kernel/time/timekeeping.c
  84159. @@ -15,6 +15,7 @@
  84160. #include <linux/init.h>
  84161. #include <linux/mm.h>
  84162. #include <linux/sched.h>
  84163. +#include <linux/grsecurity.h>
  84164. #include <linux/syscore_ops.h>
  84165. #include <linux/clocksource.h>
  84166. #include <linux/jiffies.h>
  84167. @@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
  84168. if (!timespec_valid_strict(tv))
  84169. return -EINVAL;
  84170. + gr_log_timechange();
  84171. +
  84172. raw_spin_lock_irqsave(&timekeeper_lock, flags);
  84173. write_seqcount_begin(&timekeeper_seq);
  84174. diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
  84175. index 61ed862..3b52c65 100644
  84176. --- a/kernel/time/timer_list.c
  84177. +++ b/kernel/time/timer_list.c
  84178. @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
  84179. static void print_name_offset(struct seq_file *m, void *sym)
  84180. {
  84181. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  84182. + SEQ_printf(m, "<%p>", NULL);
  84183. +#else
  84184. char symname[KSYM_NAME_LEN];
  84185. if (lookup_symbol_name((unsigned long)sym, symname) < 0)
  84186. SEQ_printf(m, "<%pK>", sym);
  84187. else
  84188. SEQ_printf(m, "%s", symname);
  84189. +#endif
  84190. }
  84191. static void
  84192. @@ -119,7 +123,11 @@ next_one:
  84193. static void
  84194. print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
  84195. {
  84196. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  84197. + SEQ_printf(m, " .base: %p\n", NULL);
  84198. +#else
  84199. SEQ_printf(m, " .base: %pK\n", base);
  84200. +#endif
  84201. SEQ_printf(m, " .index: %d\n",
  84202. base->index);
  84203. SEQ_printf(m, " .resolution: %Lu nsecs\n",
  84204. @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
  84205. {
  84206. struct proc_dir_entry *pe;
  84207. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  84208. + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
  84209. +#else
  84210. pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
  84211. +#endif
  84212. if (!pe)
  84213. return -ENOMEM;
  84214. return 0;
  84215. diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
  84216. index 1fb08f2..ca4bb1e 100644
  84217. --- a/kernel/time/timer_stats.c
  84218. +++ b/kernel/time/timer_stats.c
  84219. @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
  84220. static unsigned long nr_entries;
  84221. static struct entry entries[MAX_ENTRIES];
  84222. -static atomic_t overflow_count;
  84223. +static atomic_unchecked_t overflow_count;
  84224. /*
  84225. * The entries are in a hash-table, for fast lookup:
  84226. @@ -140,7 +140,7 @@ static void reset_entries(void)
  84227. nr_entries = 0;
  84228. memset(entries, 0, sizeof(entries));
  84229. memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
  84230. - atomic_set(&overflow_count, 0);
  84231. + atomic_set_unchecked(&overflow_count, 0);
  84232. }
  84233. static struct entry *alloc_entry(void)
  84234. @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
  84235. if (likely(entry))
  84236. entry->count++;
  84237. else
  84238. - atomic_inc(&overflow_count);
  84239. + atomic_inc_unchecked(&overflow_count);
  84240. out_unlock:
  84241. raw_spin_unlock_irqrestore(lock, flags);
  84242. @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
  84243. static void print_name_offset(struct seq_file *m, unsigned long addr)
  84244. {
  84245. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  84246. + seq_printf(m, "<%p>", NULL);
  84247. +#else
  84248. char symname[KSYM_NAME_LEN];
  84249. if (lookup_symbol_name(addr, symname) < 0)
  84250. - seq_printf(m, "<%p>", (void *)addr);
  84251. + seq_printf(m, "<%pK>", (void *)addr);
  84252. else
  84253. seq_printf(m, "%s", symname);
  84254. +#endif
  84255. }
  84256. static int tstats_show(struct seq_file *m, void *v)
  84257. @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
  84258. seq_puts(m, "Timer Stats Version: v0.3\n");
  84259. seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
  84260. - if (atomic_read(&overflow_count))
  84261. - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
  84262. + if (atomic_read_unchecked(&overflow_count))
  84263. + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
  84264. seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
  84265. for (i = 0; i < nr_entries; i++) {
  84266. @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
  84267. {
  84268. struct proc_dir_entry *pe;
  84269. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  84270. + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
  84271. +#else
  84272. pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
  84273. +#endif
  84274. if (!pe)
  84275. return -ENOMEM;
  84276. return 0;
  84277. diff --git a/kernel/timer.c b/kernel/timer.c
  84278. index accfd24..e00f0c0 100644
  84279. --- a/kernel/timer.c
  84280. +++ b/kernel/timer.c
  84281. @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
  84282. /*
  84283. * This function runs timers and the timer-tq in bottom half context.
  84284. */
  84285. -static void run_timer_softirq(struct softirq_action *h)
  84286. +static __latent_entropy void run_timer_softirq(void)
  84287. {
  84288. struct tvec_base *base = __this_cpu_read(tvec_bases);
  84289. @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
  84290. *
  84291. * In all cases the return value is guaranteed to be non-negative.
  84292. */
  84293. -signed long __sched schedule_timeout(signed long timeout)
  84294. +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
  84295. {
  84296. struct timer_list timer;
  84297. unsigned long expire;
  84298. diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
  84299. index b418cb0..f879a3d 100644
  84300. --- a/kernel/trace/blktrace.c
  84301. +++ b/kernel/trace/blktrace.c
  84302. @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
  84303. struct blk_trace *bt = filp->private_data;
  84304. char buf[16];
  84305. - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
  84306. + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
  84307. return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
  84308. }
  84309. @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
  84310. return 1;
  84311. bt = buf->chan->private_data;
  84312. - atomic_inc(&bt->dropped);
  84313. + atomic_inc_unchecked(&bt->dropped);
  84314. return 0;
  84315. }
  84316. @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
  84317. bt->dir = dir;
  84318. bt->dev = dev;
  84319. - atomic_set(&bt->dropped, 0);
  84320. + atomic_set_unchecked(&bt->dropped, 0);
  84321. INIT_LIST_HEAD(&bt->running_list);
  84322. ret = -EIO;
  84323. diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
  84324. index cd7f76d..553c805 100644
  84325. --- a/kernel/trace/ftrace.c
  84326. +++ b/kernel/trace/ftrace.c
  84327. @@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
  84328. if (unlikely(ftrace_disabled))
  84329. return 0;
  84330. + ret = ftrace_arch_code_modify_prepare();
  84331. + FTRACE_WARN_ON(ret);
  84332. + if (ret)
  84333. + return 0;
  84334. +
  84335. ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
  84336. + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
  84337. if (ret) {
  84338. ftrace_bug(ret, ip);
  84339. - return 0;
  84340. }
  84341. - return 1;
  84342. + return ret ? 0 : 1;
  84343. }
  84344. /*
  84345. @@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
  84346. if (!count)
  84347. return 0;
  84348. + pax_open_kernel();
  84349. sort(start, count, sizeof(*start),
  84350. ftrace_cmp_ips, ftrace_swap_ips);
  84351. + pax_close_kernel();
  84352. start_pg = ftrace_allocate_pages(count);
  84353. if (!start_pg)
  84354. @@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
  84355. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  84356. static int ftrace_graph_active;
  84357. -static struct notifier_block ftrace_suspend_notifier;
  84358. -
  84359. int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
  84360. {
  84361. return 0;
  84362. @@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
  84363. ftrace_graph_entry = ftrace_graph_entry_test;
  84364. }
  84365. +static struct notifier_block ftrace_suspend_notifier = {
  84366. + .notifier_call = ftrace_suspend_notifier_call
  84367. +};
  84368. +
  84369. int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  84370. trace_func_graph_ent_t entryfunc)
  84371. {
  84372. @@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  84373. goto out;
  84374. }
  84375. - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
  84376. register_pm_notifier(&ftrace_suspend_notifier);
  84377. ftrace_graph_active++;
  84378. diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
  84379. index fc4da2d..f3e800b 100644
  84380. --- a/kernel/trace/ring_buffer.c
  84381. +++ b/kernel/trace/ring_buffer.c
  84382. @@ -352,9 +352,9 @@ struct buffer_data_page {
  84383. */
  84384. struct buffer_page {
  84385. struct list_head list; /* list of buffer pages */
  84386. - local_t write; /* index for next write */
  84387. + local_unchecked_t write; /* index for next write */
  84388. unsigned read; /* index for next read */
  84389. - local_t entries; /* entries on this page */
  84390. + local_unchecked_t entries; /* entries on this page */
  84391. unsigned long real_end; /* real end of data */
  84392. struct buffer_data_page *page; /* Actual data page */
  84393. };
  84394. @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
  84395. unsigned long last_overrun;
  84396. local_t entries_bytes;
  84397. local_t entries;
  84398. - local_t overrun;
  84399. - local_t commit_overrun;
  84400. + local_unchecked_t overrun;
  84401. + local_unchecked_t commit_overrun;
  84402. local_t dropped_events;
  84403. local_t committing;
  84404. local_t commits;
  84405. @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
  84406. *
  84407. * We add a counter to the write field to denote this.
  84408. */
  84409. - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
  84410. - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
  84411. + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
  84412. + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
  84413. /*
  84414. * Just make sure we have seen our old_write and synchronize
  84415. @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
  84416. * cmpxchg to only update if an interrupt did not already
  84417. * do it for us. If the cmpxchg fails, we don't care.
  84418. */
  84419. - (void)local_cmpxchg(&next_page->write, old_write, val);
  84420. - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
  84421. + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
  84422. + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
  84423. /*
  84424. * No need to worry about races with clearing out the commit.
  84425. @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
  84426. static inline unsigned long rb_page_entries(struct buffer_page *bpage)
  84427. {
  84428. - return local_read(&bpage->entries) & RB_WRITE_MASK;
  84429. + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
  84430. }
  84431. static inline unsigned long rb_page_write(struct buffer_page *bpage)
  84432. {
  84433. - return local_read(&bpage->write) & RB_WRITE_MASK;
  84434. + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
  84435. }
  84436. static int
  84437. @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
  84438. * bytes consumed in ring buffer from here.
  84439. * Increment overrun to account for the lost events.
  84440. */
  84441. - local_add(page_entries, &cpu_buffer->overrun);
  84442. + local_add_unchecked(page_entries, &cpu_buffer->overrun);
  84443. local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
  84444. }
  84445. @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
  84446. * it is our responsibility to update
  84447. * the counters.
  84448. */
  84449. - local_add(entries, &cpu_buffer->overrun);
  84450. + local_add_unchecked(entries, &cpu_buffer->overrun);
  84451. local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
  84452. /*
  84453. @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
  84454. if (tail == BUF_PAGE_SIZE)
  84455. tail_page->real_end = 0;
  84456. - local_sub(length, &tail_page->write);
  84457. + local_sub_unchecked(length, &tail_page->write);
  84458. return;
  84459. }
  84460. @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
  84461. rb_event_set_padding(event);
  84462. /* Set the write back to the previous setting */
  84463. - local_sub(length, &tail_page->write);
  84464. + local_sub_unchecked(length, &tail_page->write);
  84465. return;
  84466. }
  84467. @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
  84468. /* Set write to end of buffer */
  84469. length = (tail + length) - BUF_PAGE_SIZE;
  84470. - local_sub(length, &tail_page->write);
  84471. + local_sub_unchecked(length, &tail_page->write);
  84472. }
  84473. /*
  84474. @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
  84475. * about it.
  84476. */
  84477. if (unlikely(next_page == commit_page)) {
  84478. - local_inc(&cpu_buffer->commit_overrun);
  84479. + local_inc_unchecked(&cpu_buffer->commit_overrun);
  84480. goto out_reset;
  84481. }
  84482. @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
  84483. cpu_buffer->tail_page) &&
  84484. (cpu_buffer->commit_page ==
  84485. cpu_buffer->reader_page))) {
  84486. - local_inc(&cpu_buffer->commit_overrun);
  84487. + local_inc_unchecked(&cpu_buffer->commit_overrun);
  84488. goto out_reset;
  84489. }
  84490. }
  84491. @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
  84492. length += RB_LEN_TIME_EXTEND;
  84493. tail_page = cpu_buffer->tail_page;
  84494. - write = local_add_return(length, &tail_page->write);
  84495. + write = local_add_return_unchecked(length, &tail_page->write);
  84496. /* set write to only the index of the write */
  84497. write &= RB_WRITE_MASK;
  84498. @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
  84499. kmemcheck_annotate_bitfield(event, bitfield);
  84500. rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
  84501. - local_inc(&tail_page->entries);
  84502. + local_inc_unchecked(&tail_page->entries);
  84503. /*
  84504. * If this is the first commit on the page, then update
  84505. @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
  84506. if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
  84507. unsigned long write_mask =
  84508. - local_read(&bpage->write) & ~RB_WRITE_MASK;
  84509. + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
  84510. unsigned long event_length = rb_event_length(event);
  84511. /*
  84512. * This is on the tail page. It is possible that
  84513. @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
  84514. */
  84515. old_index += write_mask;
  84516. new_index += write_mask;
  84517. - index = local_cmpxchg(&bpage->write, old_index, new_index);
  84518. + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
  84519. if (index == old_index) {
  84520. /* update counters */
  84521. local_sub(event_length, &cpu_buffer->entries_bytes);
  84522. @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
  84523. /* Do the likely case first */
  84524. if (likely(bpage->page == (void *)addr)) {
  84525. - local_dec(&bpage->entries);
  84526. + local_dec_unchecked(&bpage->entries);
  84527. return;
  84528. }
  84529. @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
  84530. start = bpage;
  84531. do {
  84532. if (bpage->page == (void *)addr) {
  84533. - local_dec(&bpage->entries);
  84534. + local_dec_unchecked(&bpage->entries);
  84535. return;
  84536. }
  84537. rb_inc_page(cpu_buffer, &bpage);
  84538. @@ -3146,7 +3146,7 @@ static inline unsigned long
  84539. rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
  84540. {
  84541. return local_read(&cpu_buffer->entries) -
  84542. - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
  84543. + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
  84544. }
  84545. /**
  84546. @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
  84547. return 0;
  84548. cpu_buffer = buffer->buffers[cpu];
  84549. - ret = local_read(&cpu_buffer->overrun);
  84550. + ret = local_read_unchecked(&cpu_buffer->overrun);
  84551. return ret;
  84552. }
  84553. @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
  84554. return 0;
  84555. cpu_buffer = buffer->buffers[cpu];
  84556. - ret = local_read(&cpu_buffer->commit_overrun);
  84557. + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
  84558. return ret;
  84559. }
  84560. @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
  84561. /* if you care about this being correct, lock the buffer */
  84562. for_each_buffer_cpu(buffer, cpu) {
  84563. cpu_buffer = buffer->buffers[cpu];
  84564. - overruns += local_read(&cpu_buffer->overrun);
  84565. + overruns += local_read_unchecked(&cpu_buffer->overrun);
  84566. }
  84567. return overruns;
  84568. @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
  84569. /*
  84570. * Reset the reader page to size zero.
  84571. */
  84572. - local_set(&cpu_buffer->reader_page->write, 0);
  84573. - local_set(&cpu_buffer->reader_page->entries, 0);
  84574. + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
  84575. + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
  84576. local_set(&cpu_buffer->reader_page->page->commit, 0);
  84577. cpu_buffer->reader_page->real_end = 0;
  84578. @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
  84579. * want to compare with the last_overrun.
  84580. */
  84581. smp_mb();
  84582. - overwrite = local_read(&(cpu_buffer->overrun));
  84583. + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
  84584. /*
  84585. * Here's the tricky part.
  84586. @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
  84587. cpu_buffer->head_page
  84588. = list_entry(cpu_buffer->pages, struct buffer_page, list);
  84589. - local_set(&cpu_buffer->head_page->write, 0);
  84590. - local_set(&cpu_buffer->head_page->entries, 0);
  84591. + local_set_unchecked(&cpu_buffer->head_page->write, 0);
  84592. + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
  84593. local_set(&cpu_buffer->head_page->page->commit, 0);
  84594. cpu_buffer->head_page->read = 0;
  84595. @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
  84596. INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
  84597. INIT_LIST_HEAD(&cpu_buffer->new_pages);
  84598. - local_set(&cpu_buffer->reader_page->write, 0);
  84599. - local_set(&cpu_buffer->reader_page->entries, 0);
  84600. + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
  84601. + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
  84602. local_set(&cpu_buffer->reader_page->page->commit, 0);
  84603. cpu_buffer->reader_page->read = 0;
  84604. local_set(&cpu_buffer->entries_bytes, 0);
  84605. - local_set(&cpu_buffer->overrun, 0);
  84606. - local_set(&cpu_buffer->commit_overrun, 0);
  84607. + local_set_unchecked(&cpu_buffer->overrun, 0);
  84608. + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
  84609. local_set(&cpu_buffer->dropped_events, 0);
  84610. local_set(&cpu_buffer->entries, 0);
  84611. local_set(&cpu_buffer->committing, 0);
  84612. @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
  84613. rb_init_page(bpage);
  84614. bpage = reader->page;
  84615. reader->page = *data_page;
  84616. - local_set(&reader->write, 0);
  84617. - local_set(&reader->entries, 0);
  84618. + local_set_unchecked(&reader->write, 0);
  84619. + local_set_unchecked(&reader->entries, 0);
  84620. reader->read = 0;
  84621. *data_page = bpage;
  84622. diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
  84623. index 24c1f23..781fd73f 100644
  84624. --- a/kernel/trace/trace.c
  84625. +++ b/kernel/trace/trace.c
  84626. @@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
  84627. return 0;
  84628. }
  84629. -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
  84630. +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
  84631. {
  84632. /* do nothing if flag is already set */
  84633. if (!!(trace_flags & mask) == !!enabled)
  84634. diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
  84635. index 02b592f..f971546 100644
  84636. --- a/kernel/trace/trace.h
  84637. +++ b/kernel/trace/trace.h
  84638. @@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
  84639. void trace_printk_init_buffers(void);
  84640. void trace_printk_start_comm(void);
  84641. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  84642. -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  84643. +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
  84644. /*
  84645. * Normal trace_printk() and friends allocates special buffers
  84646. diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
  84647. index 26dc348..8708ca7 100644
  84648. --- a/kernel/trace/trace_clock.c
  84649. +++ b/kernel/trace/trace_clock.c
  84650. @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
  84651. return now;
  84652. }
  84653. -static atomic64_t trace_counter;
  84654. +static atomic64_unchecked_t trace_counter;
  84655. /*
  84656. * trace_clock_counter(): simply an atomic counter.
  84657. @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
  84658. */
  84659. u64 notrace trace_clock_counter(void)
  84660. {
  84661. - return atomic64_add_return(1, &trace_counter);
  84662. + return atomic64_inc_return_unchecked(&trace_counter);
  84663. }
  84664. diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
  84665. index 7b16d40..1b2875d 100644
  84666. --- a/kernel/trace/trace_events.c
  84667. +++ b/kernel/trace/trace_events.c
  84668. @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
  84669. return 0;
  84670. }
  84671. -struct ftrace_module_file_ops;
  84672. static void __add_event_to_tracers(struct ftrace_event_call *call);
  84673. /* Add an additional event_call dynamically */
  84674. diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
  84675. index 0abd9b8..6a663a2 100644
  84676. --- a/kernel/trace/trace_mmiotrace.c
  84677. +++ b/kernel/trace/trace_mmiotrace.c
  84678. @@ -24,7 +24,7 @@ struct header_iter {
  84679. static struct trace_array *mmio_trace_array;
  84680. static bool overrun_detected;
  84681. static unsigned long prev_overruns;
  84682. -static atomic_t dropped_count;
  84683. +static atomic_unchecked_t dropped_count;
  84684. static void mmio_reset_data(struct trace_array *tr)
  84685. {
  84686. @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
  84687. static unsigned long count_overruns(struct trace_iterator *iter)
  84688. {
  84689. - unsigned long cnt = atomic_xchg(&dropped_count, 0);
  84690. + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
  84691. unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
  84692. if (over > prev_overruns)
  84693. @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
  84694. event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
  84695. sizeof(*entry), 0, pc);
  84696. if (!event) {
  84697. - atomic_inc(&dropped_count);
  84698. + atomic_inc_unchecked(&dropped_count);
  84699. return;
  84700. }
  84701. entry = ring_buffer_event_data(event);
  84702. @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
  84703. event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
  84704. sizeof(*entry), 0, pc);
  84705. if (!event) {
  84706. - atomic_inc(&dropped_count);
  84707. + atomic_inc_unchecked(&dropped_count);
  84708. return;
  84709. }
  84710. entry = ring_buffer_event_data(event);
  84711. diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
  84712. index ed32284..884d6c3 100644
  84713. --- a/kernel/trace/trace_output.c
  84714. +++ b/kernel/trace/trace_output.c
  84715. @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
  84716. p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
  84717. if (!IS_ERR(p)) {
  84718. - p = mangle_path(s->buffer + s->len, p, "\n");
  84719. + p = mangle_path(s->buffer + s->len, p, "\n\\");
  84720. if (p) {
  84721. s->len = p - s->buffer;
  84722. return 1;
  84723. @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
  84724. goto out;
  84725. }
  84726. + pax_open_kernel();
  84727. if (event->funcs->trace == NULL)
  84728. - event->funcs->trace = trace_nop_print;
  84729. + *(void **)&event->funcs->trace = trace_nop_print;
  84730. if (event->funcs->raw == NULL)
  84731. - event->funcs->raw = trace_nop_print;
  84732. + *(void **)&event->funcs->raw = trace_nop_print;
  84733. if (event->funcs->hex == NULL)
  84734. - event->funcs->hex = trace_nop_print;
  84735. + *(void **)&event->funcs->hex = trace_nop_print;
  84736. if (event->funcs->binary == NULL)
  84737. - event->funcs->binary = trace_nop_print;
  84738. + *(void **)&event->funcs->binary = trace_nop_print;
  84739. + pax_close_kernel();
  84740. key = event->type & (EVENT_HASHSIZE - 1);
  84741. diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
  84742. index e6be585..d73ae5e 100644
  84743. --- a/kernel/trace/trace_stack.c
  84744. +++ b/kernel/trace/trace_stack.c
  84745. @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
  84746. return;
  84747. /* we do not handle interrupt stacks yet */
  84748. - if (!object_is_on_stack(stack))
  84749. + if (!object_starts_on_stack(stack))
  84750. return;
  84751. local_irq_save(flags);
  84752. diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
  84753. index 80a57af..7f5a7ff 100644
  84754. --- a/kernel/user_namespace.c
  84755. +++ b/kernel/user_namespace.c
  84756. @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
  84757. !kgid_has_mapping(parent_ns, group))
  84758. return -EPERM;
  84759. +#ifdef CONFIG_GRKERNSEC
  84760. + /*
  84761. + * This doesn't really inspire confidence:
  84762. + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
  84763. + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
  84764. + * Increases kernel attack surface in areas developers
  84765. + * previously cared little about ("low importance due
  84766. + * to requiring "root" capability")
  84767. + * To be removed when this code receives *proper* review
  84768. + */
  84769. + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
  84770. + !capable(CAP_SETGID))
  84771. + return -EPERM;
  84772. +#endif
  84773. +
  84774. ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
  84775. if (!ns)
  84776. return -ENOMEM;
  84777. @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
  84778. if (atomic_read(&current->mm->mm_users) > 1)
  84779. return -EINVAL;
  84780. - if (current->fs->users != 1)
  84781. + if (atomic_read(&current->fs->users) != 1)
  84782. return -EINVAL;
  84783. if (!ns_capable(user_ns, CAP_SYS_ADMIN))
  84784. diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
  84785. index 4f69f9a..7c6f8f8 100644
  84786. --- a/kernel/utsname_sysctl.c
  84787. +++ b/kernel/utsname_sysctl.c
  84788. @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
  84789. static int proc_do_uts_string(ctl_table *table, int write,
  84790. void __user *buffer, size_t *lenp, loff_t *ppos)
  84791. {
  84792. - struct ctl_table uts_table;
  84793. + ctl_table_no_const uts_table;
  84794. int r;
  84795. memcpy(&uts_table, table, sizeof(uts_table));
  84796. uts_table.data = get_uts(table, write);
  84797. diff --git a/kernel/watchdog.c b/kernel/watchdog.c
  84798. index 4431610..4265616 100644
  84799. --- a/kernel/watchdog.c
  84800. +++ b/kernel/watchdog.c
  84801. @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
  84802. static void watchdog_nmi_disable(unsigned int cpu) { return; }
  84803. #endif /* CONFIG_HARDLOCKUP_DETECTOR */
  84804. -static struct smp_hotplug_thread watchdog_threads = {
  84805. +static struct smp_hotplug_thread watchdog_threads __read_only = {
  84806. .store = &softlockup_watchdog,
  84807. .thread_should_run = watchdog_should_run,
  84808. .thread_fn = watchdog,
  84809. diff --git a/kernel/workqueue.c b/kernel/workqueue.c
  84810. index 193e977..26dd63f 100644
  84811. --- a/kernel/workqueue.c
  84812. +++ b/kernel/workqueue.c
  84813. @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
  84814. WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
  84815. worker_flags |= WORKER_REBOUND;
  84816. worker_flags &= ~WORKER_UNBOUND;
  84817. - ACCESS_ONCE(worker->flags) = worker_flags;
  84818. + ACCESS_ONCE_RW(worker->flags) = worker_flags;
  84819. }
  84820. spin_unlock_irq(&pool->lock);
  84821. diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
  84822. index a48abea..e108def 100644
  84823. --- a/lib/Kconfig.debug
  84824. +++ b/lib/Kconfig.debug
  84825. @@ -854,7 +854,7 @@ config DEBUG_MUTEXES
  84826. config DEBUG_WW_MUTEX_SLOWPATH
  84827. bool "Wait/wound mutex debugging: Slowpath testing"
  84828. - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
  84829. + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
  84830. select DEBUG_LOCK_ALLOC
  84831. select DEBUG_SPINLOCK
  84832. select DEBUG_MUTEXES
  84833. @@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
  84834. config DEBUG_LOCK_ALLOC
  84835. bool "Lock debugging: detect incorrect freeing of live locks"
  84836. - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
  84837. + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
  84838. select DEBUG_SPINLOCK
  84839. select DEBUG_MUTEXES
  84840. select LOCKDEP
  84841. @@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
  84842. config PROVE_LOCKING
  84843. bool "Lock debugging: prove locking correctness"
  84844. - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
  84845. + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
  84846. select LOCKDEP
  84847. select DEBUG_SPINLOCK
  84848. select DEBUG_MUTEXES
  84849. @@ -932,7 +932,7 @@ config LOCKDEP
  84850. config LOCK_STAT
  84851. bool "Lock usage statistics"
  84852. - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
  84853. + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
  84854. select LOCKDEP
  84855. select DEBUG_SPINLOCK
  84856. select DEBUG_MUTEXES
  84857. @@ -1394,6 +1394,7 @@ config LATENCYTOP
  84858. depends on DEBUG_KERNEL
  84859. depends on STACKTRACE_SUPPORT
  84860. depends on PROC_FS
  84861. + depends on !GRKERNSEC_HIDESYM
  84862. select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
  84863. select KALLSYMS
  84864. select KALLSYMS_ALL
  84865. @@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
  84866. config DEBUG_STRICT_USER_COPY_CHECKS
  84867. bool "Strict user copy size checks"
  84868. depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
  84869. - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
  84870. + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
  84871. help
  84872. Enabling this option turns a certain set of sanity checks for user
  84873. copy operations into compile time failures.
  84874. @@ -1529,7 +1530,7 @@ endmenu # runtime tests
  84875. config PROVIDE_OHCI1394_DMA_INIT
  84876. bool "Remote debugging over FireWire early on boot"
  84877. - depends on PCI && X86
  84878. + depends on PCI && X86 && !GRKERNSEC
  84879. help
  84880. If you want to debug problems which hang or crash the kernel early
  84881. on boot and the crashing machine has a FireWire port, you can use
  84882. diff --git a/lib/Makefile b/lib/Makefile
  84883. index 48140e3..de854e5 100644
  84884. --- a/lib/Makefile
  84885. +++ b/lib/Makefile
  84886. @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
  84887. obj-$(CONFIG_BTREE) += btree.o
  84888. obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
  84889. obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
  84890. -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
  84891. +obj-y += list_debug.o
  84892. obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
  84893. ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
  84894. diff --git a/lib/average.c b/lib/average.c
  84895. index 114d1be..ab0350c 100644
  84896. --- a/lib/average.c
  84897. +++ b/lib/average.c
  84898. @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
  84899. {
  84900. unsigned long internal = ACCESS_ONCE(avg->internal);
  84901. - ACCESS_ONCE(avg->internal) = internal ?
  84902. + ACCESS_ONCE_RW(avg->internal) = internal ?
  84903. (((internal << avg->weight) - internal) +
  84904. (val << avg->factor)) >> avg->weight :
  84905. (val << avg->factor);
  84906. diff --git a/lib/bitmap.c b/lib/bitmap.c
  84907. index 06f7e4f..f3cf2b0 100644
  84908. --- a/lib/bitmap.c
  84909. +++ b/lib/bitmap.c
  84910. @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
  84911. {
  84912. int c, old_c, totaldigits, ndigits, nchunks, nbits;
  84913. u32 chunk;
  84914. - const char __user __force *ubuf = (const char __user __force *)buf;
  84915. + const char __user *ubuf = (const char __force_user *)buf;
  84916. bitmap_zero(maskp, nmaskbits);
  84917. @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
  84918. {
  84919. if (!access_ok(VERIFY_READ, ubuf, ulen))
  84920. return -EFAULT;
  84921. - return __bitmap_parse((const char __force *)ubuf,
  84922. + return __bitmap_parse((const char __force_kernel *)ubuf,
  84923. ulen, 1, maskp, nmaskbits);
  84924. }
  84925. @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
  84926. {
  84927. unsigned a, b;
  84928. int c, old_c, totaldigits;
  84929. - const char __user __force *ubuf = (const char __user __force *)buf;
  84930. + const char __user *ubuf = (const char __force_user *)buf;
  84931. int exp_digit, in_range;
  84932. totaldigits = c = 0;
  84933. @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
  84934. {
  84935. if (!access_ok(VERIFY_READ, ubuf, ulen))
  84936. return -EFAULT;
  84937. - return __bitmap_parselist((const char __force *)ubuf,
  84938. + return __bitmap_parselist((const char __force_kernel *)ubuf,
  84939. ulen, 1, maskp, nmaskbits);
  84940. }
  84941. EXPORT_SYMBOL(bitmap_parselist_user);
  84942. diff --git a/lib/bug.c b/lib/bug.c
  84943. index 1686034..a9c00c8 100644
  84944. --- a/lib/bug.c
  84945. +++ b/lib/bug.c
  84946. @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
  84947. return BUG_TRAP_TYPE_NONE;
  84948. bug = find_bug(bugaddr);
  84949. + if (!bug)
  84950. + return BUG_TRAP_TYPE_NONE;
  84951. file = NULL;
  84952. line = 0;
  84953. diff --git a/lib/debugobjects.c b/lib/debugobjects.c
  84954. index e0731c3..ad66444 100644
  84955. --- a/lib/debugobjects.c
  84956. +++ b/lib/debugobjects.c
  84957. @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
  84958. if (limit > 4)
  84959. return;
  84960. - is_on_stack = object_is_on_stack(addr);
  84961. + is_on_stack = object_starts_on_stack(addr);
  84962. if (is_on_stack == onstack)
  84963. return;
  84964. diff --git a/lib/devres.c b/lib/devres.c
  84965. index 8235331..5881053 100644
  84966. --- a/lib/devres.c
  84967. +++ b/lib/devres.c
  84968. @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
  84969. void devm_iounmap(struct device *dev, void __iomem *addr)
  84970. {
  84971. WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
  84972. - (void *)addr));
  84973. + (void __force *)addr));
  84974. iounmap(addr);
  84975. }
  84976. EXPORT_SYMBOL(devm_iounmap);
  84977. @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
  84978. {
  84979. ioport_unmap(addr);
  84980. WARN_ON(devres_destroy(dev, devm_ioport_map_release,
  84981. - devm_ioport_map_match, (void *)addr));
  84982. + devm_ioport_map_match, (void __force *)addr));
  84983. }
  84984. EXPORT_SYMBOL(devm_ioport_unmap);
  84985. #endif /* CONFIG_HAS_IOPORT */
  84986. diff --git a/lib/div64.c b/lib/div64.c
  84987. index 4382ad7..08aa558 100644
  84988. --- a/lib/div64.c
  84989. +++ b/lib/div64.c
  84990. @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
  84991. EXPORT_SYMBOL(__div64_32);
  84992. #ifndef div_s64_rem
  84993. -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
  84994. +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
  84995. {
  84996. u64 quotient;
  84997. @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
  84998. * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
  84999. */
  85000. #ifndef div64_u64
  85001. -u64 div64_u64(u64 dividend, u64 divisor)
  85002. +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
  85003. {
  85004. u32 high = divisor >> 32;
  85005. u64 quot;
  85006. diff --git a/lib/dma-debug.c b/lib/dma-debug.c
  85007. index 98f2d7e..899da5c 100644
  85008. --- a/lib/dma-debug.c
  85009. +++ b/lib/dma-debug.c
  85010. @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
  85011. void dma_debug_add_bus(struct bus_type *bus)
  85012. {
  85013. - struct notifier_block *nb;
  85014. + notifier_block_no_const *nb;
  85015. if (global_disable)
  85016. return;
  85017. @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
  85018. static void check_for_stack(struct device *dev, void *addr)
  85019. {
  85020. - if (object_is_on_stack(addr))
  85021. + if (object_starts_on_stack(addr))
  85022. err_printk(dev, NULL, "DMA-API: device driver maps memory from"
  85023. "stack [addr=%p]\n", addr);
  85024. }
  85025. diff --git a/lib/hash.c b/lib/hash.c
  85026. index fea973f..386626f 100644
  85027. --- a/lib/hash.c
  85028. +++ b/lib/hash.c
  85029. @@ -14,7 +14,7 @@
  85030. #include <linux/hash.h>
  85031. #include <linux/cache.h>
  85032. -static struct fast_hash_ops arch_hash_ops __read_mostly = {
  85033. +static struct fast_hash_ops arch_hash_ops __read_only = {
  85034. .hash = jhash,
  85035. .hash2 = jhash2,
  85036. };
  85037. diff --git a/lib/inflate.c b/lib/inflate.c
  85038. index 013a761..c28f3fc 100644
  85039. --- a/lib/inflate.c
  85040. +++ b/lib/inflate.c
  85041. @@ -269,7 +269,7 @@ static void free(void *where)
  85042. malloc_ptr = free_mem_ptr;
  85043. }
  85044. #else
  85045. -#define malloc(a) kmalloc(a, GFP_KERNEL)
  85046. +#define malloc(a) kmalloc((a), GFP_KERNEL)
  85047. #define free(a) kfree(a)
  85048. #endif
  85049. diff --git a/lib/ioremap.c b/lib/ioremap.c
  85050. index 0c9216c..863bd89 100644
  85051. --- a/lib/ioremap.c
  85052. +++ b/lib/ioremap.c
  85053. @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
  85054. unsigned long next;
  85055. phys_addr -= addr;
  85056. - pmd = pmd_alloc(&init_mm, pud, addr);
  85057. + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
  85058. if (!pmd)
  85059. return -ENOMEM;
  85060. do {
  85061. @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
  85062. unsigned long next;
  85063. phys_addr -= addr;
  85064. - pud = pud_alloc(&init_mm, pgd, addr);
  85065. + pud = pud_alloc_kernel(&init_mm, pgd, addr);
  85066. if (!pud)
  85067. return -ENOMEM;
  85068. do {
  85069. diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
  85070. index bd2bea9..6b3c95e 100644
  85071. --- a/lib/is_single_threaded.c
  85072. +++ b/lib/is_single_threaded.c
  85073. @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
  85074. struct task_struct *p, *t;
  85075. bool ret;
  85076. + if (!mm)
  85077. + return true;
  85078. +
  85079. if (atomic_read(&task->signal->live) != 1)
  85080. return false;
  85081. diff --git a/lib/kobject.c b/lib/kobject.c
  85082. index cb14aea..8c53cdb 100644
  85083. --- a/lib/kobject.c
  85084. +++ b/lib/kobject.c
  85085. @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
  85086. static DEFINE_SPINLOCK(kobj_ns_type_lock);
  85087. -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
  85088. +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
  85089. -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
  85090. +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
  85091. {
  85092. enum kobj_ns_type type = ops->type;
  85093. int error;
  85094. diff --git a/lib/list_debug.c b/lib/list_debug.c
  85095. index c24c2f7..f0296f4 100644
  85096. --- a/lib/list_debug.c
  85097. +++ b/lib/list_debug.c
  85098. @@ -11,7 +11,9 @@
  85099. #include <linux/bug.h>
  85100. #include <linux/kernel.h>
  85101. #include <linux/rculist.h>
  85102. +#include <linux/mm.h>
  85103. +#ifdef CONFIG_DEBUG_LIST
  85104. /*
  85105. * Insert a new entry between two known consecutive entries.
  85106. *
  85107. @@ -19,21 +21,40 @@
  85108. * the prev/next entries already!
  85109. */
  85110. +static bool __list_add_debug(struct list_head *new,
  85111. + struct list_head *prev,
  85112. + struct list_head *next)
  85113. +{
  85114. + if (unlikely(next->prev != prev)) {
  85115. + printk(KERN_ERR "list_add corruption. next->prev should be "
  85116. + "prev (%p), but was %p. (next=%p).\n",
  85117. + prev, next->prev, next);
  85118. + BUG();
  85119. + return false;
  85120. + }
  85121. + if (unlikely(prev->next != next)) {
  85122. + printk(KERN_ERR "list_add corruption. prev->next should be "
  85123. + "next (%p), but was %p. (prev=%p).\n",
  85124. + next, prev->next, prev);
  85125. + BUG();
  85126. + return false;
  85127. + }
  85128. + if (unlikely(new == prev || new == next)) {
  85129. + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
  85130. + new, prev, next);
  85131. + BUG();
  85132. + return false;
  85133. + }
  85134. + return true;
  85135. +}
  85136. +
  85137. void __list_add(struct list_head *new,
  85138. - struct list_head *prev,
  85139. - struct list_head *next)
  85140. + struct list_head *prev,
  85141. + struct list_head *next)
  85142. {
  85143. - WARN(next->prev != prev,
  85144. - "list_add corruption. next->prev should be "
  85145. - "prev (%p), but was %p. (next=%p).\n",
  85146. - prev, next->prev, next);
  85147. - WARN(prev->next != next,
  85148. - "list_add corruption. prev->next should be "
  85149. - "next (%p), but was %p. (prev=%p).\n",
  85150. - next, prev->next, prev);
  85151. - WARN(new == prev || new == next,
  85152. - "list_add double add: new=%p, prev=%p, next=%p.\n",
  85153. - new, prev, next);
  85154. + if (!__list_add_debug(new, prev, next))
  85155. + return;
  85156. +
  85157. next->prev = new;
  85158. new->next = next;
  85159. new->prev = prev;
  85160. @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
  85161. }
  85162. EXPORT_SYMBOL(__list_add);
  85163. -void __list_del_entry(struct list_head *entry)
  85164. +static bool __list_del_entry_debug(struct list_head *entry)
  85165. {
  85166. struct list_head *prev, *next;
  85167. prev = entry->prev;
  85168. next = entry->next;
  85169. - if (WARN(next == LIST_POISON1,
  85170. - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
  85171. - entry, LIST_POISON1) ||
  85172. - WARN(prev == LIST_POISON2,
  85173. - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
  85174. - entry, LIST_POISON2) ||
  85175. - WARN(prev->next != entry,
  85176. - "list_del corruption. prev->next should be %p, "
  85177. - "but was %p\n", entry, prev->next) ||
  85178. - WARN(next->prev != entry,
  85179. - "list_del corruption. next->prev should be %p, "
  85180. - "but was %p\n", entry, next->prev))
  85181. + if (unlikely(next == LIST_POISON1)) {
  85182. + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
  85183. + entry, LIST_POISON1);
  85184. + BUG();
  85185. + return false;
  85186. + }
  85187. + if (unlikely(prev == LIST_POISON2)) {
  85188. + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
  85189. + entry, LIST_POISON2);
  85190. + BUG();
  85191. + return false;
  85192. + }
  85193. + if (unlikely(entry->prev->next != entry)) {
  85194. + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
  85195. + "but was %p\n", entry, prev->next);
  85196. + BUG();
  85197. + return false;
  85198. + }
  85199. + if (unlikely(entry->next->prev != entry)) {
  85200. + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
  85201. + "but was %p\n", entry, next->prev);
  85202. + BUG();
  85203. + return false;
  85204. + }
  85205. + return true;
  85206. +}
  85207. +
  85208. +void __list_del_entry(struct list_head *entry)
  85209. +{
  85210. + if (!__list_del_entry_debug(entry))
  85211. return;
  85212. - __list_del(prev, next);
  85213. + __list_del(entry->prev, entry->next);
  85214. }
  85215. EXPORT_SYMBOL(__list_del_entry);
  85216. @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
  85217. void __list_add_rcu(struct list_head *new,
  85218. struct list_head *prev, struct list_head *next)
  85219. {
  85220. - WARN(next->prev != prev,
  85221. - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
  85222. - prev, next->prev, next);
  85223. - WARN(prev->next != next,
  85224. - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
  85225. - next, prev->next, prev);
  85226. + if (!__list_add_debug(new, prev, next))
  85227. + return;
  85228. +
  85229. new->next = next;
  85230. new->prev = prev;
  85231. rcu_assign_pointer(list_next_rcu(prev), new);
  85232. next->prev = new;
  85233. }
  85234. EXPORT_SYMBOL(__list_add_rcu);
  85235. +#endif
  85236. +
  85237. +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
  85238. +{
  85239. +#ifdef CONFIG_DEBUG_LIST
  85240. + if (!__list_add_debug(new, prev, next))
  85241. + return;
  85242. +#endif
  85243. +
  85244. + pax_open_kernel();
  85245. + next->prev = new;
  85246. + new->next = next;
  85247. + new->prev = prev;
  85248. + prev->next = new;
  85249. + pax_close_kernel();
  85250. +}
  85251. +EXPORT_SYMBOL(__pax_list_add);
  85252. +
  85253. +void pax_list_del(struct list_head *entry)
  85254. +{
  85255. +#ifdef CONFIG_DEBUG_LIST
  85256. + if (!__list_del_entry_debug(entry))
  85257. + return;
  85258. +#endif
  85259. +
  85260. + pax_open_kernel();
  85261. + __list_del(entry->prev, entry->next);
  85262. + entry->next = LIST_POISON1;
  85263. + entry->prev = LIST_POISON2;
  85264. + pax_close_kernel();
  85265. +}
  85266. +EXPORT_SYMBOL(pax_list_del);
  85267. +
  85268. +void pax_list_del_init(struct list_head *entry)
  85269. +{
  85270. + pax_open_kernel();
  85271. + __list_del(entry->prev, entry->next);
  85272. + INIT_LIST_HEAD(entry);
  85273. + pax_close_kernel();
  85274. +}
  85275. +EXPORT_SYMBOL(pax_list_del_init);
  85276. +
  85277. +void __pax_list_add_rcu(struct list_head *new,
  85278. + struct list_head *prev, struct list_head *next)
  85279. +{
  85280. +#ifdef CONFIG_DEBUG_LIST
  85281. + if (!__list_add_debug(new, prev, next))
  85282. + return;
  85283. +#endif
  85284. +
  85285. + pax_open_kernel();
  85286. + new->next = next;
  85287. + new->prev = prev;
  85288. + rcu_assign_pointer(list_next_rcu(prev), new);
  85289. + next->prev = new;
  85290. + pax_close_kernel();
  85291. +}
  85292. +EXPORT_SYMBOL(__pax_list_add_rcu);
  85293. +
  85294. +void pax_list_del_rcu(struct list_head *entry)
  85295. +{
  85296. +#ifdef CONFIG_DEBUG_LIST
  85297. + if (!__list_del_entry_debug(entry))
  85298. + return;
  85299. +#endif
  85300. +
  85301. + pax_open_kernel();
  85302. + __list_del(entry->prev, entry->next);
  85303. + entry->next = LIST_POISON1;
  85304. + entry->prev = LIST_POISON2;
  85305. + pax_close_kernel();
  85306. +}
  85307. +EXPORT_SYMBOL(pax_list_del_rcu);
  85308. diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
  85309. index 963b703..438bc51 100644
  85310. --- a/lib/percpu-refcount.c
  85311. +++ b/lib/percpu-refcount.c
  85312. @@ -29,7 +29,7 @@
  85313. * can't hit 0 before we've added up all the percpu refs.
  85314. */
  85315. -#define PCPU_COUNT_BIAS (1U << 31)
  85316. +#define PCPU_COUNT_BIAS (1U << 30)
  85317. /**
  85318. * percpu_ref_init - initialize a percpu refcount
  85319. diff --git a/lib/radix-tree.c b/lib/radix-tree.c
  85320. index bd4a8df..9e4804f 100644
  85321. --- a/lib/radix-tree.c
  85322. +++ b/lib/radix-tree.c
  85323. @@ -93,7 +93,7 @@ struct radix_tree_preload {
  85324. int nr;
  85325. struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
  85326. };
  85327. -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
  85328. +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
  85329. static inline void *ptr_to_indirect(void *ptr)
  85330. {
  85331. diff --git a/lib/random32.c b/lib/random32.c
  85332. index 6148967..009bfe8 100644
  85333. --- a/lib/random32.c
  85334. +++ b/lib/random32.c
  85335. @@ -44,7 +44,7 @@
  85336. static void __init prandom_state_selftest(void);
  85337. #endif
  85338. -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
  85339. +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
  85340. /**
  85341. * prandom_u32_state - seeded pseudo-random number generator.
  85342. diff --git a/lib/rbtree.c b/lib/rbtree.c
  85343. index 65f4eff..2cfa167 100644
  85344. --- a/lib/rbtree.c
  85345. +++ b/lib/rbtree.c
  85346. @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
  85347. static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
  85348. static const struct rb_augment_callbacks dummy_callbacks = {
  85349. - dummy_propagate, dummy_copy, dummy_rotate
  85350. + .propagate = dummy_propagate,
  85351. + .copy = dummy_copy,
  85352. + .rotate = dummy_rotate
  85353. };
  85354. void rb_insert_color(struct rb_node *node, struct rb_root *root)
  85355. diff --git a/lib/show_mem.c b/lib/show_mem.c
  85356. index 0922579..9d7adb9 100644
  85357. --- a/lib/show_mem.c
  85358. +++ b/lib/show_mem.c
  85359. @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
  85360. quicklist_total_size());
  85361. #endif
  85362. #ifdef CONFIG_MEMORY_FAILURE
  85363. - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
  85364. + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
  85365. #endif
  85366. }
  85367. diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
  85368. index bb2b201..46abaf9 100644
  85369. --- a/lib/strncpy_from_user.c
  85370. +++ b/lib/strncpy_from_user.c
  85371. @@ -21,7 +21,7 @@
  85372. */
  85373. static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
  85374. {
  85375. - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  85376. + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  85377. long res = 0;
  85378. /*
  85379. diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
  85380. index a28df52..3d55877 100644
  85381. --- a/lib/strnlen_user.c
  85382. +++ b/lib/strnlen_user.c
  85383. @@ -26,7 +26,7 @@
  85384. */
  85385. static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
  85386. {
  85387. - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  85388. + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  85389. long align, res = 0;
  85390. unsigned long c;
  85391. diff --git a/lib/swiotlb.c b/lib/swiotlb.c
  85392. index b604b83..c0547f6 100644
  85393. --- a/lib/swiotlb.c
  85394. +++ b/lib/swiotlb.c
  85395. @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
  85396. void
  85397. swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
  85398. - dma_addr_t dev_addr)
  85399. + dma_addr_t dev_addr, struct dma_attrs *attrs)
  85400. {
  85401. phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
  85402. diff --git a/lib/usercopy.c b/lib/usercopy.c
  85403. index 4f5b1dd..7cab418 100644
  85404. --- a/lib/usercopy.c
  85405. +++ b/lib/usercopy.c
  85406. @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
  85407. WARN(1, "Buffer overflow detected!\n");
  85408. }
  85409. EXPORT_SYMBOL(copy_from_user_overflow);
  85410. +
  85411. +void copy_to_user_overflow(void)
  85412. +{
  85413. + WARN(1, "Buffer overflow detected!\n");
  85414. +}
  85415. +EXPORT_SYMBOL(copy_to_user_overflow);
  85416. diff --git a/lib/vsprintf.c b/lib/vsprintf.c
  85417. index 185b6d3..823c48c 100644
  85418. --- a/lib/vsprintf.c
  85419. +++ b/lib/vsprintf.c
  85420. @@ -16,6 +16,9 @@
  85421. * - scnprintf and vscnprintf
  85422. */
  85423. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  85424. +#define __INCLUDED_BY_HIDESYM 1
  85425. +#endif
  85426. #include <stdarg.h>
  85427. #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
  85428. #include <linux/types.h>
  85429. @@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
  85430. return number(buf, end, num, spec);
  85431. }
  85432. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  85433. +int kptr_restrict __read_mostly = 2;
  85434. +#else
  85435. int kptr_restrict __read_mostly;
  85436. +#endif
  85437. /*
  85438. * Show a '%p' thing. A kernel extension is that the '%p' is followed
  85439. @@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
  85440. * - 'f' For simple symbolic function names without offset
  85441. * - 'S' For symbolic direct pointers with offset
  85442. * - 's' For symbolic direct pointers without offset
  85443. + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
  85444. * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
  85445. * - 'B' For backtraced symbolic direct pointers with offset
  85446. * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
  85447. @@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
  85448. if (!ptr && *fmt != 'K') {
  85449. /*
  85450. - * Print (null) with the same width as a pointer so it makes
  85451. + * Print (nil) with the same width as a pointer so it makes
  85452. * tabular output look nice.
  85453. */
  85454. if (spec.field_width == -1)
  85455. spec.field_width = default_width;
  85456. - return string(buf, end, "(null)", spec);
  85457. + return string(buf, end, "(nil)", spec);
  85458. }
  85459. switch (*fmt) {
  85460. @@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
  85461. /* Fallthrough */
  85462. case 'S':
  85463. case 's':
  85464. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  85465. + break;
  85466. +#else
  85467. + return symbol_string(buf, end, ptr, spec, fmt);
  85468. +#endif
  85469. + case 'A':
  85470. case 'B':
  85471. return symbol_string(buf, end, ptr, spec, fmt);
  85472. case 'R':
  85473. @@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
  85474. va_end(va);
  85475. return buf;
  85476. }
  85477. + case 'P':
  85478. + break;
  85479. case 'K':
  85480. /*
  85481. * %pK cannot be used in IRQ context because its test
  85482. @@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
  85483. ((const struct file *)ptr)->f_path.dentry,
  85484. spec, fmt);
  85485. }
  85486. +
  85487. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  85488. + /* 'P' = approved pointers to copy to userland,
  85489. + as in the /proc/kallsyms case, as we make it display nothing
  85490. + for non-root users, and the real contents for root users
  85491. + Also ignore 'K' pointers, since we force their NULLing for non-root users
  85492. + above
  85493. + */
  85494. + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
  85495. + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
  85496. + dump_stack();
  85497. + ptr = NULL;
  85498. + }
  85499. +#endif
  85500. +
  85501. spec.flags |= SMALL;
  85502. if (spec.field_width == -1) {
  85503. spec.field_width = default_width;
  85504. @@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
  85505. typeof(type) value; \
  85506. if (sizeof(type) == 8) { \
  85507. args = PTR_ALIGN(args, sizeof(u32)); \
  85508. - *(u32 *)&value = *(u32 *)args; \
  85509. - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
  85510. + *(u32 *)&value = *(const u32 *)args; \
  85511. + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
  85512. } else { \
  85513. args = PTR_ALIGN(args, sizeof(type)); \
  85514. - value = *(typeof(type) *)args; \
  85515. + value = *(const typeof(type) *)args; \
  85516. } \
  85517. args += sizeof(type); \
  85518. value; \
  85519. @@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
  85520. case FORMAT_TYPE_STR: {
  85521. const char *str_arg = args;
  85522. args += strlen(str_arg) + 1;
  85523. - str = string(str, end, (char *)str_arg, spec);
  85524. + str = string(str, end, str_arg, spec);
  85525. break;
  85526. }
  85527. diff --git a/localversion-grsec b/localversion-grsec
  85528. new file mode 100644
  85529. index 0000000..7cd6065
  85530. --- /dev/null
  85531. +++ b/localversion-grsec
  85532. @@ -0,0 +1 @@
  85533. +-grsec
  85534. diff --git a/mm/Kconfig b/mm/Kconfig
  85535. index 2888024..c15a810 100644
  85536. --- a/mm/Kconfig
  85537. +++ b/mm/Kconfig
  85538. @@ -326,10 +326,11 @@ config KSM
  85539. root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
  85540. config DEFAULT_MMAP_MIN_ADDR
  85541. - int "Low address space to protect from user allocation"
  85542. + int "Low address space to protect from user allocation"
  85543. depends on MMU
  85544. - default 4096
  85545. - help
  85546. + default 32768 if ALPHA || ARM || PARISC || SPARC32
  85547. + default 65536
  85548. + help
  85549. This is the portion of low virtual memory which should be protected
  85550. from userspace allocation. Keeping a user from writing to low pages
  85551. can help reduce the impact of kernel NULL pointer bugs.
  85552. @@ -360,7 +361,7 @@ config MEMORY_FAILURE
  85553. config HWPOISON_INJECT
  85554. tristate "HWPoison pages injector"
  85555. - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
  85556. + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
  85557. select PROC_PAGE_MONITOR
  85558. config NOMMU_INITIAL_TRIM_EXCESS
  85559. diff --git a/mm/backing-dev.c b/mm/backing-dev.c
  85560. index 09d9591..165bb75 100644
  85561. --- a/mm/backing-dev.c
  85562. +++ b/mm/backing-dev.c
  85563. @@ -12,7 +12,7 @@
  85564. #include <linux/device.h>
  85565. #include <trace/events/writeback.h>
  85566. -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
  85567. +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
  85568. struct backing_dev_info default_backing_dev_info = {
  85569. .name = "default",
  85570. @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
  85571. return err;
  85572. err = bdi_register(bdi, NULL, "%.28s-%ld", name,
  85573. - atomic_long_inc_return(&bdi_seq));
  85574. + atomic_long_inc_return_unchecked(&bdi_seq));
  85575. if (err) {
  85576. bdi_destroy(bdi);
  85577. return err;
  85578. diff --git a/mm/filemap.c b/mm/filemap.c
  85579. index 7a13f6a..e52e841 100644
  85580. --- a/mm/filemap.c
  85581. +++ b/mm/filemap.c
  85582. @@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
  85583. struct address_space *mapping = file->f_mapping;
  85584. if (!mapping->a_ops->readpage)
  85585. - return -ENOEXEC;
  85586. + return -ENODEV;
  85587. file_accessed(file);
  85588. vma->vm_ops = &generic_file_vm_ops;
  85589. return 0;
  85590. @@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
  85591. while (bytes) {
  85592. char __user *buf = iov->iov_base + base;
  85593. - int copy = min(bytes, iov->iov_len - base);
  85594. + size_t copy = min(bytes, iov->iov_len - base);
  85595. base = 0;
  85596. left = __copy_from_user_inatomic(vaddr, buf, copy);
  85597. @@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
  85598. BUG_ON(!in_atomic());
  85599. kaddr = kmap_atomic(page);
  85600. if (likely(i->nr_segs == 1)) {
  85601. - int left;
  85602. + size_t left;
  85603. char __user *buf = i->iov->iov_base + i->iov_offset;
  85604. left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
  85605. copied = bytes - left;
  85606. @@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
  85607. kaddr = kmap(page);
  85608. if (likely(i->nr_segs == 1)) {
  85609. - int left;
  85610. + size_t left;
  85611. char __user *buf = i->iov->iov_base + i->iov_offset;
  85612. left = __copy_from_user(kaddr + offset, buf, bytes);
  85613. copied = bytes - left;
  85614. @@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
  85615. * zero-length segments (without overruning the iovec).
  85616. */
  85617. while (bytes || unlikely(i->count && !iov->iov_len)) {
  85618. - int copy;
  85619. + size_t copy;
  85620. copy = min(bytes, iov->iov_len - base);
  85621. BUG_ON(!i->count || i->count < copy);
  85622. @@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
  85623. *pos = i_size_read(inode);
  85624. if (limit != RLIM_INFINITY) {
  85625. + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
  85626. if (*pos >= limit) {
  85627. send_sig(SIGXFSZ, current, 0);
  85628. return -EFBIG;
  85629. diff --git a/mm/fremap.c b/mm/fremap.c
  85630. index 34feba6..315fe78 100644
  85631. --- a/mm/fremap.c
  85632. +++ b/mm/fremap.c
  85633. @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
  85634. retry:
  85635. vma = find_vma(mm, start);
  85636. +#ifdef CONFIG_PAX_SEGMEXEC
  85637. + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
  85638. + goto out;
  85639. +#endif
  85640. +
  85641. /*
  85642. * Make sure the vma is shared, that it supports prefaulting,
  85643. * and that the remapped range is valid and fully within
  85644. diff --git a/mm/highmem.c b/mm/highmem.c
  85645. index b32b70c..e512eb0 100644
  85646. --- a/mm/highmem.c
  85647. +++ b/mm/highmem.c
  85648. @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
  85649. * So no dangers, even with speculative execution.
  85650. */
  85651. page = pte_page(pkmap_page_table[i]);
  85652. + pax_open_kernel();
  85653. pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
  85654. -
  85655. + pax_close_kernel();
  85656. set_page_address(page, NULL);
  85657. need_flush = 1;
  85658. }
  85659. @@ -198,9 +199,11 @@ start:
  85660. }
  85661. }
  85662. vaddr = PKMAP_ADDR(last_pkmap_nr);
  85663. +
  85664. + pax_open_kernel();
  85665. set_pte_at(&init_mm, vaddr,
  85666. &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
  85667. -
  85668. + pax_close_kernel();
  85669. pkmap_count[last_pkmap_nr] = 1;
  85670. set_page_address(page, (void *)vaddr);
  85671. diff --git a/mm/hugetlb.c b/mm/hugetlb.c
  85672. index 2de3c84..4ecaf1b 100644
  85673. --- a/mm/hugetlb.c
  85674. +++ b/mm/hugetlb.c
  85675. @@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
  85676. struct hstate *h = &default_hstate;
  85677. unsigned long tmp;
  85678. int ret;
  85679. + ctl_table_no_const hugetlb_table;
  85680. tmp = h->max_huge_pages;
  85681. if (write && h->order >= MAX_ORDER)
  85682. return -EINVAL;
  85683. - table->data = &tmp;
  85684. - table->maxlen = sizeof(unsigned long);
  85685. - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
  85686. + hugetlb_table = *table;
  85687. + hugetlb_table.data = &tmp;
  85688. + hugetlb_table.maxlen = sizeof(unsigned long);
  85689. + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
  85690. if (ret)
  85691. goto out;
  85692. @@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
  85693. struct hstate *h = &default_hstate;
  85694. unsigned long tmp;
  85695. int ret;
  85696. + ctl_table_no_const hugetlb_table;
  85697. tmp = h->nr_overcommit_huge_pages;
  85698. if (write && h->order >= MAX_ORDER)
  85699. return -EINVAL;
  85700. - table->data = &tmp;
  85701. - table->maxlen = sizeof(unsigned long);
  85702. - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
  85703. + hugetlb_table = *table;
  85704. + hugetlb_table.data = &tmp;
  85705. + hugetlb_table.maxlen = sizeof(unsigned long);
  85706. + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
  85707. if (ret)
  85708. goto out;
  85709. @@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
  85710. return 1;
  85711. }
  85712. +#ifdef CONFIG_PAX_SEGMEXEC
  85713. +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
  85714. +{
  85715. + struct mm_struct *mm = vma->vm_mm;
  85716. + struct vm_area_struct *vma_m;
  85717. + unsigned long address_m;
  85718. + pte_t *ptep_m;
  85719. +
  85720. + vma_m = pax_find_mirror_vma(vma);
  85721. + if (!vma_m)
  85722. + return;
  85723. +
  85724. + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
  85725. + address_m = address + SEGMEXEC_TASK_SIZE;
  85726. + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
  85727. + get_page(page_m);
  85728. + hugepage_add_anon_rmap(page_m, vma_m, address_m);
  85729. + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
  85730. +}
  85731. +#endif
  85732. +
  85733. /*
  85734. * Hugetlb_cow() should be called with page lock of the original hugepage held.
  85735. * Called with hugetlb_instantiation_mutex held and pte_page locked so we
  85736. @@ -2715,6 +2740,11 @@ retry_avoidcopy:
  85737. make_huge_pte(vma, new_page, 1));
  85738. page_remove_rmap(old_page);
  85739. hugepage_add_new_anon_rmap(new_page, vma, address);
  85740. +
  85741. +#ifdef CONFIG_PAX_SEGMEXEC
  85742. + pax_mirror_huge_pte(vma, address, new_page);
  85743. +#endif
  85744. +
  85745. /* Make the old page be freed below */
  85746. new_page = old_page;
  85747. }
  85748. @@ -2879,6 +2909,10 @@ retry:
  85749. && (vma->vm_flags & VM_SHARED)));
  85750. set_huge_pte_at(mm, address, ptep, new_pte);
  85751. +#ifdef CONFIG_PAX_SEGMEXEC
  85752. + pax_mirror_huge_pte(vma, address, page);
  85753. +#endif
  85754. +
  85755. if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
  85756. /* Optimization, do the COW without a second fault */
  85757. ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
  85758. @@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  85759. static DEFINE_MUTEX(hugetlb_instantiation_mutex);
  85760. struct hstate *h = hstate_vma(vma);
  85761. +#ifdef CONFIG_PAX_SEGMEXEC
  85762. + struct vm_area_struct *vma_m;
  85763. +#endif
  85764. +
  85765. address &= huge_page_mask(h);
  85766. ptep = huge_pte_offset(mm, address);
  85767. @@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  85768. VM_FAULT_SET_HINDEX(hstate_index(h));
  85769. }
  85770. +#ifdef CONFIG_PAX_SEGMEXEC
  85771. + vma_m = pax_find_mirror_vma(vma);
  85772. + if (vma_m) {
  85773. + unsigned long address_m;
  85774. +
  85775. + if (vma->vm_start > vma_m->vm_start) {
  85776. + address_m = address;
  85777. + address -= SEGMEXEC_TASK_SIZE;
  85778. + vma = vma_m;
  85779. + h = hstate_vma(vma);
  85780. + } else
  85781. + address_m = address + SEGMEXEC_TASK_SIZE;
  85782. +
  85783. + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
  85784. + return VM_FAULT_OOM;
  85785. + address_m &= HPAGE_MASK;
  85786. + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
  85787. + }
  85788. +#endif
  85789. +
  85790. ptep = huge_pte_alloc(mm, address, huge_page_size(h));
  85791. if (!ptep)
  85792. return VM_FAULT_OOM;
  85793. diff --git a/mm/internal.h b/mm/internal.h
  85794. index 3e91000..4741a60 100644
  85795. --- a/mm/internal.h
  85796. +++ b/mm/internal.h
  85797. @@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
  85798. * in mm/page_alloc.c
  85799. */
  85800. extern void __free_pages_bootmem(struct page *page, unsigned int order);
  85801. +extern void free_compound_page(struct page *page);
  85802. extern void prep_compound_page(struct page *page, unsigned long order);
  85803. #ifdef CONFIG_MEMORY_FAILURE
  85804. extern bool is_free_buddy_page(struct page *page);
  85805. @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
  85806. extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
  85807. unsigned long, unsigned long,
  85808. - unsigned long, unsigned long);
  85809. + unsigned long, unsigned long) __intentional_overflow(-1);
  85810. extern void set_pageblock_order(void);
  85811. unsigned long reclaim_clean_pages_from_list(struct zone *zone,
  85812. diff --git a/mm/kmemleak.c b/mm/kmemleak.c
  85813. index 31f01c5..7015178 100644
  85814. --- a/mm/kmemleak.c
  85815. +++ b/mm/kmemleak.c
  85816. @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
  85817. for (i = 0; i < object->trace_len; i++) {
  85818. void *ptr = (void *)object->trace[i];
  85819. - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
  85820. + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
  85821. }
  85822. }
  85823. @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
  85824. return -ENOMEM;
  85825. }
  85826. - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
  85827. + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
  85828. &kmemleak_fops);
  85829. if (!dentry)
  85830. pr_warning("Failed to create the debugfs kmemleak file\n");
  85831. diff --git a/mm/maccess.c b/mm/maccess.c
  85832. index d53adf9..03a24bf 100644
  85833. --- a/mm/maccess.c
  85834. +++ b/mm/maccess.c
  85835. @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
  85836. set_fs(KERNEL_DS);
  85837. pagefault_disable();
  85838. ret = __copy_from_user_inatomic(dst,
  85839. - (__force const void __user *)src, size);
  85840. + (const void __force_user *)src, size);
  85841. pagefault_enable();
  85842. set_fs(old_fs);
  85843. @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
  85844. set_fs(KERNEL_DS);
  85845. pagefault_disable();
  85846. - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
  85847. + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
  85848. pagefault_enable();
  85849. set_fs(old_fs);
  85850. diff --git a/mm/madvise.c b/mm/madvise.c
  85851. index 539eeb9..e24a987 100644
  85852. --- a/mm/madvise.c
  85853. +++ b/mm/madvise.c
  85854. @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
  85855. pgoff_t pgoff;
  85856. unsigned long new_flags = vma->vm_flags;
  85857. +#ifdef CONFIG_PAX_SEGMEXEC
  85858. + struct vm_area_struct *vma_m;
  85859. +#endif
  85860. +
  85861. switch (behavior) {
  85862. case MADV_NORMAL:
  85863. new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
  85864. @@ -126,6 +130,13 @@ success:
  85865. /*
  85866. * vm_flags is protected by the mmap_sem held in write mode.
  85867. */
  85868. +
  85869. +#ifdef CONFIG_PAX_SEGMEXEC
  85870. + vma_m = pax_find_mirror_vma(vma);
  85871. + if (vma_m)
  85872. + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
  85873. +#endif
  85874. +
  85875. vma->vm_flags = new_flags;
  85876. out:
  85877. @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
  85878. struct vm_area_struct **prev,
  85879. unsigned long start, unsigned long end)
  85880. {
  85881. +
  85882. +#ifdef CONFIG_PAX_SEGMEXEC
  85883. + struct vm_area_struct *vma_m;
  85884. +#endif
  85885. +
  85886. *prev = vma;
  85887. if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
  85888. return -EINVAL;
  85889. @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
  85890. zap_page_range(vma, start, end - start, &details);
  85891. } else
  85892. zap_page_range(vma, start, end - start, NULL);
  85893. +
  85894. +#ifdef CONFIG_PAX_SEGMEXEC
  85895. + vma_m = pax_find_mirror_vma(vma);
  85896. + if (vma_m) {
  85897. + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
  85898. + struct zap_details details = {
  85899. + .nonlinear_vma = vma_m,
  85900. + .last_index = ULONG_MAX,
  85901. + };
  85902. + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
  85903. + } else
  85904. + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
  85905. + }
  85906. +#endif
  85907. +
  85908. return 0;
  85909. }
  85910. @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
  85911. if (end < start)
  85912. return error;
  85913. +#ifdef CONFIG_PAX_SEGMEXEC
  85914. + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
  85915. + if (end > SEGMEXEC_TASK_SIZE)
  85916. + return error;
  85917. + } else
  85918. +#endif
  85919. +
  85920. + if (end > TASK_SIZE)
  85921. + return error;
  85922. +
  85923. error = 0;
  85924. if (end == start)
  85925. return error;
  85926. diff --git a/mm/memory-failure.c b/mm/memory-failure.c
  85927. index 90002ea..db1452d 100644
  85928. --- a/mm/memory-failure.c
  85929. +++ b/mm/memory-failure.c
  85930. @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
  85931. int sysctl_memory_failure_recovery __read_mostly = 1;
  85932. -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
  85933. +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
  85934. #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
  85935. @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
  85936. pfn, t->comm, t->pid);
  85937. si.si_signo = SIGBUS;
  85938. si.si_errno = 0;
  85939. - si.si_addr = (void *)addr;
  85940. + si.si_addr = (void __user *)addr;
  85941. #ifdef __ARCH_SI_TRAPNO
  85942. si.si_trapno = trapno;
  85943. #endif
  85944. @@ -762,7 +762,7 @@ static struct page_state {
  85945. unsigned long res;
  85946. char *msg;
  85947. int (*action)(struct page *p, unsigned long pfn);
  85948. -} error_states[] = {
  85949. +} __do_const error_states[] = {
  85950. { reserved, reserved, "reserved kernel", me_kernel },
  85951. /*
  85952. * free pages are specially detected outside this table:
  85953. @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
  85954. nr_pages = 1 << compound_order(hpage);
  85955. else /* normal page or thp */
  85956. nr_pages = 1;
  85957. - atomic_long_add(nr_pages, &num_poisoned_pages);
  85958. + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
  85959. /*
  85960. * We need/can do nothing about count=0 pages.
  85961. @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
  85962. if (!PageHWPoison(hpage)
  85963. || (hwpoison_filter(p) && TestClearPageHWPoison(p))
  85964. || (p != hpage && TestSetPageHWPoison(hpage))) {
  85965. - atomic_long_sub(nr_pages, &num_poisoned_pages);
  85966. + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
  85967. return 0;
  85968. }
  85969. set_page_hwpoison_huge_page(hpage);
  85970. @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
  85971. }
  85972. if (hwpoison_filter(p)) {
  85973. if (TestClearPageHWPoison(p))
  85974. - atomic_long_sub(nr_pages, &num_poisoned_pages);
  85975. + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
  85976. unlock_page(hpage);
  85977. put_page(hpage);
  85978. return 0;
  85979. @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
  85980. return 0;
  85981. }
  85982. if (TestClearPageHWPoison(p))
  85983. - atomic_long_dec(&num_poisoned_pages);
  85984. + atomic_long_dec_unchecked(&num_poisoned_pages);
  85985. pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
  85986. return 0;
  85987. }
  85988. @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
  85989. */
  85990. if (TestClearPageHWPoison(page)) {
  85991. pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
  85992. - atomic_long_sub(nr_pages, &num_poisoned_pages);
  85993. + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
  85994. freeit = 1;
  85995. if (PageHuge(page))
  85996. clear_page_hwpoison_huge_page(page);
  85997. @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
  85998. if (PageHuge(page)) {
  85999. set_page_hwpoison_huge_page(hpage);
  86000. dequeue_hwpoisoned_huge_page(hpage);
  86001. - atomic_long_add(1 << compound_order(hpage),
  86002. + atomic_long_add_unchecked(1 << compound_order(hpage),
  86003. &num_poisoned_pages);
  86004. } else {
  86005. SetPageHWPoison(page);
  86006. - atomic_long_inc(&num_poisoned_pages);
  86007. + atomic_long_inc_unchecked(&num_poisoned_pages);
  86008. }
  86009. }
  86010. return ret;
  86011. @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
  86012. put_page(page);
  86013. pr_info("soft_offline: %#lx: invalidated\n", pfn);
  86014. SetPageHWPoison(page);
  86015. - atomic_long_inc(&num_poisoned_pages);
  86016. + atomic_long_inc_unchecked(&num_poisoned_pages);
  86017. return 0;
  86018. }
  86019. @@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
  86020. if (!is_free_buddy_page(page))
  86021. pr_info("soft offline: %#lx: page leaked\n",
  86022. pfn);
  86023. - atomic_long_inc(&num_poisoned_pages);
  86024. + atomic_long_inc_unchecked(&num_poisoned_pages);
  86025. }
  86026. } else {
  86027. pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
  86028. @@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
  86029. if (PageHuge(page)) {
  86030. set_page_hwpoison_huge_page(hpage);
  86031. dequeue_hwpoisoned_huge_page(hpage);
  86032. - atomic_long_add(1 << compound_order(hpage),
  86033. + atomic_long_add_unchecked(1 << compound_order(hpage),
  86034. &num_poisoned_pages);
  86035. } else {
  86036. SetPageHWPoison(page);
  86037. - atomic_long_inc(&num_poisoned_pages);
  86038. + atomic_long_inc_unchecked(&num_poisoned_pages);
  86039. }
  86040. }
  86041. unset_migratetype_isolate(page, MIGRATE_MOVABLE);
  86042. diff --git a/mm/memory.c b/mm/memory.c
  86043. index 22dfa61..90d7ec5 100644
  86044. --- a/mm/memory.c
  86045. +++ b/mm/memory.c
  86046. @@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
  86047. free_pte_range(tlb, pmd, addr);
  86048. } while (pmd++, addr = next, addr != end);
  86049. +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
  86050. start &= PUD_MASK;
  86051. if (start < floor)
  86052. return;
  86053. @@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
  86054. pmd = pmd_offset(pud, start);
  86055. pud_clear(pud);
  86056. pmd_free_tlb(tlb, pmd, start);
  86057. +#endif
  86058. +
  86059. }
  86060. static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
  86061. @@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
  86062. free_pmd_range(tlb, pud, addr, next, floor, ceiling);
  86063. } while (pud++, addr = next, addr != end);
  86064. +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
  86065. start &= PGDIR_MASK;
  86066. if (start < floor)
  86067. return;
  86068. @@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
  86069. pud = pud_offset(pgd, start);
  86070. pgd_clear(pgd);
  86071. pud_free_tlb(tlb, pud, start);
  86072. +#endif
  86073. +
  86074. }
  86075. /*
  86076. @@ -1636,12 +1642,6 @@ no_page_table:
  86077. return page;
  86078. }
  86079. -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
  86080. -{
  86081. - return stack_guard_page_start(vma, addr) ||
  86082. - stack_guard_page_end(vma, addr+PAGE_SIZE);
  86083. -}
  86084. -
  86085. /**
  86086. * __get_user_pages() - pin user pages in memory
  86087. * @tsk: task_struct of target task
  86088. @@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  86089. i = 0;
  86090. - do {
  86091. + while (nr_pages) {
  86092. struct vm_area_struct *vma;
  86093. - vma = find_extend_vma(mm, start);
  86094. + vma = find_vma(mm, start);
  86095. if (!vma && in_gate_area(mm, start)) {
  86096. unsigned long pg = start & PAGE_MASK;
  86097. pgd_t *pgd;
  86098. @@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  86099. goto next_page;
  86100. }
  86101. - if (!vma ||
  86102. + if (!vma || start < vma->vm_start ||
  86103. (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
  86104. !(vm_flags & vma->vm_flags))
  86105. return i ? : -EFAULT;
  86106. @@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  86107. int ret;
  86108. unsigned int fault_flags = 0;
  86109. - /* For mlock, just skip the stack guard page. */
  86110. - if (foll_flags & FOLL_MLOCK) {
  86111. - if (stack_guard_page(vma, start))
  86112. - goto next_page;
  86113. - }
  86114. if (foll_flags & FOLL_WRITE)
  86115. fault_flags |= FAULT_FLAG_WRITE;
  86116. if (nonblocking)
  86117. @@ -1893,7 +1888,7 @@ next_page:
  86118. start += page_increm * PAGE_SIZE;
  86119. nr_pages -= page_increm;
  86120. } while (nr_pages && start < vma->vm_end);
  86121. - } while (nr_pages);
  86122. + }
  86123. return i;
  86124. }
  86125. EXPORT_SYMBOL(__get_user_pages);
  86126. @@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
  86127. unsigned long address, unsigned int fault_flags)
  86128. {
  86129. struct vm_area_struct *vma;
  86130. + vm_flags_t vm_flags;
  86131. int ret;
  86132. vma = find_extend_vma(mm, address);
  86133. if (!vma || address < vma->vm_start)
  86134. return -EFAULT;
  86135. + vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
  86136. + if (!(vm_flags & vma->vm_flags))
  86137. + return -EFAULT;
  86138. +
  86139. ret = handle_mm_fault(mm, vma, address, fault_flags);
  86140. if (ret & VM_FAULT_ERROR) {
  86141. if (ret & VM_FAULT_OOM)
  86142. @@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
  86143. page_add_file_rmap(page);
  86144. set_pte_at(mm, addr, pte, mk_pte(page, prot));
  86145. +#ifdef CONFIG_PAX_SEGMEXEC
  86146. + pax_mirror_file_pte(vma, addr, page, ptl);
  86147. +#endif
  86148. +
  86149. retval = 0;
  86150. pte_unmap_unlock(pte, ptl);
  86151. return retval;
  86152. @@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
  86153. if (!page_count(page))
  86154. return -EINVAL;
  86155. if (!(vma->vm_flags & VM_MIXEDMAP)) {
  86156. +
  86157. +#ifdef CONFIG_PAX_SEGMEXEC
  86158. + struct vm_area_struct *vma_m;
  86159. +#endif
  86160. +
  86161. BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
  86162. BUG_ON(vma->vm_flags & VM_PFNMAP);
  86163. vma->vm_flags |= VM_MIXEDMAP;
  86164. +
  86165. +#ifdef CONFIG_PAX_SEGMEXEC
  86166. + vma_m = pax_find_mirror_vma(vma);
  86167. + if (vma_m)
  86168. + vma_m->vm_flags |= VM_MIXEDMAP;
  86169. +#endif
  86170. +
  86171. }
  86172. return insert_page(vma, addr, page, vma->vm_page_prot);
  86173. }
  86174. @@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
  86175. unsigned long pfn)
  86176. {
  86177. BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
  86178. + BUG_ON(vma->vm_mirror);
  86179. if (addr < vma->vm_start || addr >= vma->vm_end)
  86180. return -EFAULT;
  86181. @@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
  86182. BUG_ON(pud_huge(*pud));
  86183. - pmd = pmd_alloc(mm, pud, addr);
  86184. + pmd = (mm == &init_mm) ?
  86185. + pmd_alloc_kernel(mm, pud, addr) :
  86186. + pmd_alloc(mm, pud, addr);
  86187. if (!pmd)
  86188. return -ENOMEM;
  86189. do {
  86190. @@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
  86191. unsigned long next;
  86192. int err;
  86193. - pud = pud_alloc(mm, pgd, addr);
  86194. + pud = (mm == &init_mm) ?
  86195. + pud_alloc_kernel(mm, pgd, addr) :
  86196. + pud_alloc(mm, pgd, addr);
  86197. if (!pud)
  86198. return -ENOMEM;
  86199. do {
  86200. @@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
  86201. copy_user_highpage(dst, src, va, vma);
  86202. }
  86203. +#ifdef CONFIG_PAX_SEGMEXEC
  86204. +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
  86205. +{
  86206. + struct mm_struct *mm = vma->vm_mm;
  86207. + spinlock_t *ptl;
  86208. + pte_t *pte, entry;
  86209. +
  86210. + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
  86211. + entry = *pte;
  86212. + if (!pte_present(entry)) {
  86213. + if (!pte_none(entry)) {
  86214. + BUG_ON(pte_file(entry));
  86215. + free_swap_and_cache(pte_to_swp_entry(entry));
  86216. + pte_clear_not_present_full(mm, address, pte, 0);
  86217. + }
  86218. + } else {
  86219. + struct page *page;
  86220. +
  86221. + flush_cache_page(vma, address, pte_pfn(entry));
  86222. + entry = ptep_clear_flush(vma, address, pte);
  86223. + BUG_ON(pte_dirty(entry));
  86224. + page = vm_normal_page(vma, address, entry);
  86225. + if (page) {
  86226. + update_hiwater_rss(mm);
  86227. + if (PageAnon(page))
  86228. + dec_mm_counter_fast(mm, MM_ANONPAGES);
  86229. + else
  86230. + dec_mm_counter_fast(mm, MM_FILEPAGES);
  86231. + page_remove_rmap(page);
  86232. + page_cache_release(page);
  86233. + }
  86234. + }
  86235. + pte_unmap_unlock(pte, ptl);
  86236. +}
  86237. +
  86238. +/* PaX: if vma is mirrored, synchronize the mirror's PTE
  86239. + *
  86240. + * the ptl of the lower mapped page is held on entry and is not released on exit
  86241. + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
  86242. + */
  86243. +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
  86244. +{
  86245. + struct mm_struct *mm = vma->vm_mm;
  86246. + unsigned long address_m;
  86247. + spinlock_t *ptl_m;
  86248. + struct vm_area_struct *vma_m;
  86249. + pmd_t *pmd_m;
  86250. + pte_t *pte_m, entry_m;
  86251. +
  86252. + BUG_ON(!page_m || !PageAnon(page_m));
  86253. +
  86254. + vma_m = pax_find_mirror_vma(vma);
  86255. + if (!vma_m)
  86256. + return;
  86257. +
  86258. + BUG_ON(!PageLocked(page_m));
  86259. + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
  86260. + address_m = address + SEGMEXEC_TASK_SIZE;
  86261. + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
  86262. + pte_m = pte_offset_map(pmd_m, address_m);
  86263. + ptl_m = pte_lockptr(mm, pmd_m);
  86264. + if (ptl != ptl_m) {
  86265. + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
  86266. + if (!pte_none(*pte_m))
  86267. + goto out;
  86268. + }
  86269. +
  86270. + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
  86271. + page_cache_get(page_m);
  86272. + page_add_anon_rmap(page_m, vma_m, address_m);
  86273. + inc_mm_counter_fast(mm, MM_ANONPAGES);
  86274. + set_pte_at(mm, address_m, pte_m, entry_m);
  86275. + update_mmu_cache(vma_m, address_m, pte_m);
  86276. +out:
  86277. + if (ptl != ptl_m)
  86278. + spin_unlock(ptl_m);
  86279. + pte_unmap(pte_m);
  86280. + unlock_page(page_m);
  86281. +}
  86282. +
  86283. +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
  86284. +{
  86285. + struct mm_struct *mm = vma->vm_mm;
  86286. + unsigned long address_m;
  86287. + spinlock_t *ptl_m;
  86288. + struct vm_area_struct *vma_m;
  86289. + pmd_t *pmd_m;
  86290. + pte_t *pte_m, entry_m;
  86291. +
  86292. + BUG_ON(!page_m || PageAnon(page_m));
  86293. +
  86294. + vma_m = pax_find_mirror_vma(vma);
  86295. + if (!vma_m)
  86296. + return;
  86297. +
  86298. + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
  86299. + address_m = address + SEGMEXEC_TASK_SIZE;
  86300. + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
  86301. + pte_m = pte_offset_map(pmd_m, address_m);
  86302. + ptl_m = pte_lockptr(mm, pmd_m);
  86303. + if (ptl != ptl_m) {
  86304. + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
  86305. + if (!pte_none(*pte_m))
  86306. + goto out;
  86307. + }
  86308. +
  86309. + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
  86310. + page_cache_get(page_m);
  86311. + page_add_file_rmap(page_m);
  86312. + inc_mm_counter_fast(mm, MM_FILEPAGES);
  86313. + set_pte_at(mm, address_m, pte_m, entry_m);
  86314. + update_mmu_cache(vma_m, address_m, pte_m);
  86315. +out:
  86316. + if (ptl != ptl_m)
  86317. + spin_unlock(ptl_m);
  86318. + pte_unmap(pte_m);
  86319. +}
  86320. +
  86321. +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
  86322. +{
  86323. + struct mm_struct *mm = vma->vm_mm;
  86324. + unsigned long address_m;
  86325. + spinlock_t *ptl_m;
  86326. + struct vm_area_struct *vma_m;
  86327. + pmd_t *pmd_m;
  86328. + pte_t *pte_m, entry_m;
  86329. +
  86330. + vma_m = pax_find_mirror_vma(vma);
  86331. + if (!vma_m)
  86332. + return;
  86333. +
  86334. + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
  86335. + address_m = address + SEGMEXEC_TASK_SIZE;
  86336. + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
  86337. + pte_m = pte_offset_map(pmd_m, address_m);
  86338. + ptl_m = pte_lockptr(mm, pmd_m);
  86339. + if (ptl != ptl_m) {
  86340. + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
  86341. + if (!pte_none(*pte_m))
  86342. + goto out;
  86343. + }
  86344. +
  86345. + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
  86346. + set_pte_at(mm, address_m, pte_m, entry_m);
  86347. +out:
  86348. + if (ptl != ptl_m)
  86349. + spin_unlock(ptl_m);
  86350. + pte_unmap(pte_m);
  86351. +}
  86352. +
  86353. +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
  86354. +{
  86355. + struct page *page_m;
  86356. + pte_t entry;
  86357. +
  86358. + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
  86359. + goto out;
  86360. +
  86361. + entry = *pte;
  86362. + page_m = vm_normal_page(vma, address, entry);
  86363. + if (!page_m)
  86364. + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
  86365. + else if (PageAnon(page_m)) {
  86366. + if (pax_find_mirror_vma(vma)) {
  86367. + pte_unmap_unlock(pte, ptl);
  86368. + lock_page(page_m);
  86369. + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
  86370. + if (pte_same(entry, *pte))
  86371. + pax_mirror_anon_pte(vma, address, page_m, ptl);
  86372. + else
  86373. + unlock_page(page_m);
  86374. + }
  86375. + } else
  86376. + pax_mirror_file_pte(vma, address, page_m, ptl);
  86377. +
  86378. +out:
  86379. + pte_unmap_unlock(pte, ptl);
  86380. +}
  86381. +#endif
  86382. +
  86383. /*
  86384. * This routine handles present pages, when users try to write
  86385. * to a shared page. It is done by copying the page to a new address
  86386. @@ -2810,6 +3011,12 @@ gotten:
  86387. */
  86388. page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
  86389. if (likely(pte_same(*page_table, orig_pte))) {
  86390. +
  86391. +#ifdef CONFIG_PAX_SEGMEXEC
  86392. + if (pax_find_mirror_vma(vma))
  86393. + BUG_ON(!trylock_page(new_page));
  86394. +#endif
  86395. +
  86396. if (old_page) {
  86397. if (!PageAnon(old_page)) {
  86398. dec_mm_counter_fast(mm, MM_FILEPAGES);
  86399. @@ -2861,6 +3068,10 @@ gotten:
  86400. page_remove_rmap(old_page);
  86401. }
  86402. +#ifdef CONFIG_PAX_SEGMEXEC
  86403. + pax_mirror_anon_pte(vma, address, new_page, ptl);
  86404. +#endif
  86405. +
  86406. /* Free the old page.. */
  86407. new_page = old_page;
  86408. ret |= VM_FAULT_WRITE;
  86409. @@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
  86410. swap_free(entry);
  86411. if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
  86412. try_to_free_swap(page);
  86413. +
  86414. +#ifdef CONFIG_PAX_SEGMEXEC
  86415. + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
  86416. +#endif
  86417. +
  86418. unlock_page(page);
  86419. if (page != swapcache) {
  86420. /*
  86421. @@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
  86422. /* No need to invalidate - it was non-present before */
  86423. update_mmu_cache(vma, address, page_table);
  86424. +
  86425. +#ifdef CONFIG_PAX_SEGMEXEC
  86426. + pax_mirror_anon_pte(vma, address, page, ptl);
  86427. +#endif
  86428. +
  86429. unlock:
  86430. pte_unmap_unlock(page_table, ptl);
  86431. out:
  86432. @@ -3180,40 +3401,6 @@ out_release:
  86433. }
  86434. /*
  86435. - * This is like a special single-page "expand_{down|up}wards()",
  86436. - * except we must first make sure that 'address{-|+}PAGE_SIZE'
  86437. - * doesn't hit another vma.
  86438. - */
  86439. -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
  86440. -{
  86441. - address &= PAGE_MASK;
  86442. - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
  86443. - struct vm_area_struct *prev = vma->vm_prev;
  86444. -
  86445. - /*
  86446. - * Is there a mapping abutting this one below?
  86447. - *
  86448. - * That's only ok if it's the same stack mapping
  86449. - * that has gotten split..
  86450. - */
  86451. - if (prev && prev->vm_end == address)
  86452. - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
  86453. -
  86454. - expand_downwards(vma, address - PAGE_SIZE);
  86455. - }
  86456. - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
  86457. - struct vm_area_struct *next = vma->vm_next;
  86458. -
  86459. - /* As VM_GROWSDOWN but s/below/above/ */
  86460. - if (next && next->vm_start == address + PAGE_SIZE)
  86461. - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
  86462. -
  86463. - expand_upwards(vma, address + PAGE_SIZE);
  86464. - }
  86465. - return 0;
  86466. -}
  86467. -
  86468. -/*
  86469. * We enter with non-exclusive mmap_sem (to exclude vma changes,
  86470. * but allow concurrent faults), and pte mapped but not yet locked.
  86471. * We return with mmap_sem still held, but pte unmapped and unlocked.
  86472. @@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
  86473. unsigned long address, pte_t *page_table, pmd_t *pmd,
  86474. unsigned int flags)
  86475. {
  86476. - struct page *page;
  86477. + struct page *page = NULL;
  86478. spinlock_t *ptl;
  86479. pte_t entry;
  86480. - pte_unmap(page_table);
  86481. -
  86482. - /* Check if we need to add a guard page to the stack */
  86483. - if (check_stack_guard_page(vma, address) < 0)
  86484. - return VM_FAULT_SIGBUS;
  86485. -
  86486. - /* Use the zero-page for reads */
  86487. if (!(flags & FAULT_FLAG_WRITE)) {
  86488. entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
  86489. vma->vm_page_prot));
  86490. - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
  86491. + ptl = pte_lockptr(mm, pmd);
  86492. + spin_lock(ptl);
  86493. if (!pte_none(*page_table))
  86494. goto unlock;
  86495. goto setpte;
  86496. }
  86497. /* Allocate our own private page. */
  86498. + pte_unmap(page_table);
  86499. +
  86500. if (unlikely(anon_vma_prepare(vma)))
  86501. goto oom;
  86502. page = alloc_zeroed_user_highpage_movable(vma, address);
  86503. @@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
  86504. if (!pte_none(*page_table))
  86505. goto release;
  86506. +#ifdef CONFIG_PAX_SEGMEXEC
  86507. + if (pax_find_mirror_vma(vma))
  86508. + BUG_ON(!trylock_page(page));
  86509. +#endif
  86510. +
  86511. inc_mm_counter_fast(mm, MM_ANONPAGES);
  86512. page_add_new_anon_rmap(page, vma, address);
  86513. setpte:
  86514. @@ -3273,6 +3461,12 @@ setpte:
  86515. /* No need to invalidate - it was non-present before */
  86516. update_mmu_cache(vma, address, page_table);
  86517. +
  86518. +#ifdef CONFIG_PAX_SEGMEXEC
  86519. + if (page)
  86520. + pax_mirror_anon_pte(vma, address, page, ptl);
  86521. +#endif
  86522. +
  86523. unlock:
  86524. pte_unmap_unlock(page_table, ptl);
  86525. return 0;
  86526. @@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  86527. */
  86528. /* Only go through if we didn't race with anybody else... */
  86529. if (likely(pte_same(*page_table, orig_pte))) {
  86530. +
  86531. +#ifdef CONFIG_PAX_SEGMEXEC
  86532. + if (anon && pax_find_mirror_vma(vma))
  86533. + BUG_ON(!trylock_page(page));
  86534. +#endif
  86535. +
  86536. flush_icache_page(vma, page);
  86537. entry = mk_pte(page, vma->vm_page_prot);
  86538. if (flags & FAULT_FLAG_WRITE)
  86539. @@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  86540. /* no need to invalidate: a not-present page won't be cached */
  86541. update_mmu_cache(vma, address, page_table);
  86542. +
  86543. +#ifdef CONFIG_PAX_SEGMEXEC
  86544. + if (anon)
  86545. + pax_mirror_anon_pte(vma, address, page, ptl);
  86546. + else
  86547. + pax_mirror_file_pte(vma, address, page, ptl);
  86548. +#endif
  86549. +
  86550. } else {
  86551. if (cow_page)
  86552. mem_cgroup_uncharge_page(cow_page);
  86553. @@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
  86554. if (flags & FAULT_FLAG_WRITE)
  86555. flush_tlb_fix_spurious_fault(vma, address);
  86556. }
  86557. +
  86558. +#ifdef CONFIG_PAX_SEGMEXEC
  86559. + pax_mirror_pte(vma, address, pte, pmd, ptl);
  86560. + return 0;
  86561. +#endif
  86562. +
  86563. unlock:
  86564. pte_unmap_unlock(pte, ptl);
  86565. return 0;
  86566. @@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  86567. pmd_t *pmd;
  86568. pte_t *pte;
  86569. +#ifdef CONFIG_PAX_SEGMEXEC
  86570. + struct vm_area_struct *vma_m;
  86571. +#endif
  86572. +
  86573. if (unlikely(is_vm_hugetlb_page(vma)))
  86574. return hugetlb_fault(mm, vma, address, flags);
  86575. +#ifdef CONFIG_PAX_SEGMEXEC
  86576. + vma_m = pax_find_mirror_vma(vma);
  86577. + if (vma_m) {
  86578. + unsigned long address_m;
  86579. + pgd_t *pgd_m;
  86580. + pud_t *pud_m;
  86581. + pmd_t *pmd_m;
  86582. +
  86583. + if (vma->vm_start > vma_m->vm_start) {
  86584. + address_m = address;
  86585. + address -= SEGMEXEC_TASK_SIZE;
  86586. + vma = vma_m;
  86587. + } else
  86588. + address_m = address + SEGMEXEC_TASK_SIZE;
  86589. +
  86590. + pgd_m = pgd_offset(mm, address_m);
  86591. + pud_m = pud_alloc(mm, pgd_m, address_m);
  86592. + if (!pud_m)
  86593. + return VM_FAULT_OOM;
  86594. + pmd_m = pmd_alloc(mm, pud_m, address_m);
  86595. + if (!pmd_m)
  86596. + return VM_FAULT_OOM;
  86597. + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
  86598. + return VM_FAULT_OOM;
  86599. + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
  86600. + }
  86601. +#endif
  86602. +
  86603. pgd = pgd_offset(mm, address);
  86604. pud = pud_alloc(mm, pgd, address);
  86605. if (!pud)
  86606. @@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
  86607. spin_unlock(&mm->page_table_lock);
  86608. return 0;
  86609. }
  86610. +
  86611. +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
  86612. +{
  86613. + pud_t *new = pud_alloc_one(mm, address);
  86614. + if (!new)
  86615. + return -ENOMEM;
  86616. +
  86617. + smp_wmb(); /* See comment in __pte_alloc */
  86618. +
  86619. + spin_lock(&mm->page_table_lock);
  86620. + if (pgd_present(*pgd)) /* Another has populated it */
  86621. + pud_free(mm, new);
  86622. + else
  86623. + pgd_populate_kernel(mm, pgd, new);
  86624. + spin_unlock(&mm->page_table_lock);
  86625. + return 0;
  86626. +}
  86627. #endif /* __PAGETABLE_PUD_FOLDED */
  86628. #ifndef __PAGETABLE_PMD_FOLDED
  86629. @@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
  86630. spin_unlock(&mm->page_table_lock);
  86631. return 0;
  86632. }
  86633. +
  86634. +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
  86635. +{
  86636. + pmd_t *new = pmd_alloc_one(mm, address);
  86637. + if (!new)
  86638. + return -ENOMEM;
  86639. +
  86640. + smp_wmb(); /* See comment in __pte_alloc */
  86641. +
  86642. + spin_lock(&mm->page_table_lock);
  86643. +#ifndef __ARCH_HAS_4LEVEL_HACK
  86644. + if (pud_present(*pud)) /* Another has populated it */
  86645. + pmd_free(mm, new);
  86646. + else
  86647. + pud_populate_kernel(mm, pud, new);
  86648. +#else
  86649. + if (pgd_present(*pud)) /* Another has populated it */
  86650. + pmd_free(mm, new);
  86651. + else
  86652. + pgd_populate_kernel(mm, pud, new);
  86653. +#endif /* __ARCH_HAS_4LEVEL_HACK */
  86654. + spin_unlock(&mm->page_table_lock);
  86655. + return 0;
  86656. +}
  86657. #endif /* __PAGETABLE_PMD_FOLDED */
  86658. #if !defined(__HAVE_ARCH_GATE_AREA)
  86659. @@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
  86660. gate_vma.vm_start = FIXADDR_USER_START;
  86661. gate_vma.vm_end = FIXADDR_USER_END;
  86662. gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
  86663. - gate_vma.vm_page_prot = __P101;
  86664. + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
  86665. return 0;
  86666. }
  86667. @@ -4011,8 +4298,8 @@ out:
  86668. return ret;
  86669. }
  86670. -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
  86671. - void *buf, int len, int write)
  86672. +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
  86673. + void *buf, size_t len, int write)
  86674. {
  86675. resource_size_t phys_addr;
  86676. unsigned long prot = 0;
  86677. @@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
  86678. * Access another process' address space as given in mm. If non-NULL, use the
  86679. * given task for page fault accounting.
  86680. */
  86681. -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  86682. - unsigned long addr, void *buf, int len, int write)
  86683. +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  86684. + unsigned long addr, void *buf, size_t len, int write)
  86685. {
  86686. struct vm_area_struct *vma;
  86687. void *old_buf = buf;
  86688. @@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  86689. down_read(&mm->mmap_sem);
  86690. /* ignore errors, just check how much was successfully transferred */
  86691. while (len) {
  86692. - int bytes, ret, offset;
  86693. + ssize_t bytes, ret, offset;
  86694. void *maddr;
  86695. struct page *page = NULL;
  86696. @@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  86697. *
  86698. * The caller must hold a reference on @mm.
  86699. */
  86700. -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
  86701. - void *buf, int len, int write)
  86702. +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
  86703. + void *buf, size_t len, int write)
  86704. {
  86705. return __access_remote_vm(NULL, mm, addr, buf, len, write);
  86706. }
  86707. @@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
  86708. * Source/target buffer must be kernel space,
  86709. * Do not walk the page table directly, use get_user_pages
  86710. */
  86711. -int access_process_vm(struct task_struct *tsk, unsigned long addr,
  86712. - void *buf, int len, int write)
  86713. +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
  86714. + void *buf, size_t len, int write)
  86715. {
  86716. struct mm_struct *mm;
  86717. - int ret;
  86718. + ssize_t ret;
  86719. mm = get_task_mm(tsk);
  86720. if (!mm)
  86721. diff --git a/mm/mempolicy.c b/mm/mempolicy.c
  86722. index ae3c8f3..fa4ee8e 100644
  86723. --- a/mm/mempolicy.c
  86724. +++ b/mm/mempolicy.c
  86725. @@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
  86726. unsigned long vmstart;
  86727. unsigned long vmend;
  86728. +#ifdef CONFIG_PAX_SEGMEXEC
  86729. + struct vm_area_struct *vma_m;
  86730. +#endif
  86731. +
  86732. vma = find_vma(mm, start);
  86733. if (!vma || vma->vm_start > start)
  86734. return -EFAULT;
  86735. @@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
  86736. err = vma_replace_policy(vma, new_pol);
  86737. if (err)
  86738. goto out;
  86739. +
  86740. +#ifdef CONFIG_PAX_SEGMEXEC
  86741. + vma_m = pax_find_mirror_vma(vma);
  86742. + if (vma_m) {
  86743. + err = vma_replace_policy(vma_m, new_pol);
  86744. + if (err)
  86745. + goto out;
  86746. + }
  86747. +#endif
  86748. +
  86749. }
  86750. out:
  86751. @@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
  86752. if (end < start)
  86753. return -EINVAL;
  86754. +
  86755. +#ifdef CONFIG_PAX_SEGMEXEC
  86756. + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
  86757. + if (end > SEGMEXEC_TASK_SIZE)
  86758. + return -EINVAL;
  86759. + } else
  86760. +#endif
  86761. +
  86762. + if (end > TASK_SIZE)
  86763. + return -EINVAL;
  86764. +
  86765. if (end == start)
  86766. return 0;
  86767. @@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
  86768. */
  86769. tcred = __task_cred(task);
  86770. if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
  86771. - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
  86772. - !capable(CAP_SYS_NICE)) {
  86773. + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
  86774. rcu_read_unlock();
  86775. err = -EPERM;
  86776. goto out_put;
  86777. @@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
  86778. goto out;
  86779. }
  86780. +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
  86781. + if (mm != current->mm &&
  86782. + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
  86783. + mmput(mm);
  86784. + err = -EPERM;
  86785. + goto out;
  86786. + }
  86787. +#endif
  86788. +
  86789. err = do_migrate_pages(mm, old, new,
  86790. capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
  86791. diff --git a/mm/migrate.c b/mm/migrate.c
  86792. index bed4880..a493f67 100644
  86793. --- a/mm/migrate.c
  86794. +++ b/mm/migrate.c
  86795. @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
  86796. */
  86797. tcred = __task_cred(task);
  86798. if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
  86799. - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
  86800. - !capable(CAP_SYS_NICE)) {
  86801. + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
  86802. rcu_read_unlock();
  86803. err = -EPERM;
  86804. goto out;
  86805. diff --git a/mm/mlock.c b/mm/mlock.c
  86806. index b1eb536..091d154 100644
  86807. --- a/mm/mlock.c
  86808. +++ b/mm/mlock.c
  86809. @@ -14,6 +14,7 @@
  86810. #include <linux/pagevec.h>
  86811. #include <linux/mempolicy.h>
  86812. #include <linux/syscalls.h>
  86813. +#include <linux/security.h>
  86814. #include <linux/sched.h>
  86815. #include <linux/export.h>
  86816. #include <linux/rmap.h>
  86817. @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
  86818. {
  86819. unsigned long nstart, end, tmp;
  86820. struct vm_area_struct * vma, * prev;
  86821. - int error;
  86822. + int error = 0;
  86823. VM_BUG_ON(start & ~PAGE_MASK);
  86824. VM_BUG_ON(len != PAGE_ALIGN(len));
  86825. @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
  86826. return -EINVAL;
  86827. if (end == start)
  86828. return 0;
  86829. + if (end > TASK_SIZE)
  86830. + return -EINVAL;
  86831. +
  86832. vma = find_vma(current->mm, start);
  86833. if (!vma || vma->vm_start > start)
  86834. return -ENOMEM;
  86835. @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
  86836. for (nstart = start ; ; ) {
  86837. vm_flags_t newflags;
  86838. +#ifdef CONFIG_PAX_SEGMEXEC
  86839. + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
  86840. + break;
  86841. +#endif
  86842. +
  86843. /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
  86844. newflags = vma->vm_flags & ~VM_LOCKED;
  86845. @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
  86846. locked += current->mm->locked_vm;
  86847. /* check against resource limits */
  86848. + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
  86849. if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
  86850. error = do_mlock(start, len, 1);
  86851. @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
  86852. for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
  86853. vm_flags_t newflags;
  86854. +#ifdef CONFIG_PAX_SEGMEXEC
  86855. + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
  86856. + break;
  86857. +#endif
  86858. +
  86859. newflags = vma->vm_flags & ~VM_LOCKED;
  86860. if (flags & MCL_CURRENT)
  86861. newflags |= VM_LOCKED;
  86862. @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
  86863. lock_limit >>= PAGE_SHIFT;
  86864. ret = -ENOMEM;
  86865. +
  86866. + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
  86867. +
  86868. down_write(&current->mm->mmap_sem);
  86869. -
  86870. if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
  86871. capable(CAP_IPC_LOCK))
  86872. ret = do_mlockall(flags);
  86873. diff --git a/mm/mmap.c b/mm/mmap.c
  86874. index 20ff0c3..a9eda98 100644
  86875. --- a/mm/mmap.c
  86876. +++ b/mm/mmap.c
  86877. @@ -36,6 +36,7 @@
  86878. #include <linux/sched/sysctl.h>
  86879. #include <linux/notifier.h>
  86880. #include <linux/memory.h>
  86881. +#include <linux/random.h>
  86882. #include <asm/uaccess.h>
  86883. #include <asm/cacheflush.h>
  86884. @@ -52,6 +53,16 @@
  86885. #define arch_rebalance_pgtables(addr, len) (addr)
  86886. #endif
  86887. +static inline void verify_mm_writelocked(struct mm_struct *mm)
  86888. +{
  86889. +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
  86890. + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
  86891. + up_read(&mm->mmap_sem);
  86892. + BUG();
  86893. + }
  86894. +#endif
  86895. +}
  86896. +
  86897. static void unmap_region(struct mm_struct *mm,
  86898. struct vm_area_struct *vma, struct vm_area_struct *prev,
  86899. unsigned long start, unsigned long end);
  86900. @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
  86901. * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
  86902. *
  86903. */
  86904. -pgprot_t protection_map[16] = {
  86905. +pgprot_t protection_map[16] __read_only = {
  86906. __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
  86907. __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
  86908. };
  86909. -pgprot_t vm_get_page_prot(unsigned long vm_flags)
  86910. +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
  86911. {
  86912. - return __pgprot(pgprot_val(protection_map[vm_flags &
  86913. + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
  86914. (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
  86915. pgprot_val(arch_vm_get_page_prot(vm_flags)));
  86916. +
  86917. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
  86918. + if (!(__supported_pte_mask & _PAGE_NX) &&
  86919. + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
  86920. + (vm_flags & (VM_READ | VM_WRITE)))
  86921. + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
  86922. +#endif
  86923. +
  86924. + return prot;
  86925. }
  86926. EXPORT_SYMBOL(vm_get_page_prot);
  86927. @@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
  86928. int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
  86929. unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
  86930. unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
  86931. +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
  86932. /*
  86933. * Make sure vm_committed_as in one cacheline and not cacheline shared with
  86934. * other variables. It can be updated by several CPUs frequently.
  86935. @@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
  86936. struct vm_area_struct *next = vma->vm_next;
  86937. might_sleep();
  86938. + BUG_ON(vma->vm_mirror);
  86939. if (vma->vm_ops && vma->vm_ops->close)
  86940. vma->vm_ops->close(vma);
  86941. if (vma->vm_file)
  86942. @@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
  86943. * not page aligned -Ram Gupta
  86944. */
  86945. rlim = rlimit(RLIMIT_DATA);
  86946. + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
  86947. if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
  86948. (mm->end_data - mm->start_data) > rlim)
  86949. goto out;
  86950. @@ -940,6 +963,12 @@ static int
  86951. can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
  86952. struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
  86953. {
  86954. +
  86955. +#ifdef CONFIG_PAX_SEGMEXEC
  86956. + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
  86957. + return 0;
  86958. +#endif
  86959. +
  86960. if (is_mergeable_vma(vma, file, vm_flags) &&
  86961. is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
  86962. if (vma->vm_pgoff == vm_pgoff)
  86963. @@ -959,6 +988,12 @@ static int
  86964. can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
  86965. struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
  86966. {
  86967. +
  86968. +#ifdef CONFIG_PAX_SEGMEXEC
  86969. + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
  86970. + return 0;
  86971. +#endif
  86972. +
  86973. if (is_mergeable_vma(vma, file, vm_flags) &&
  86974. is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
  86975. pgoff_t vm_pglen;
  86976. @@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
  86977. struct vm_area_struct *vma_merge(struct mm_struct *mm,
  86978. struct vm_area_struct *prev, unsigned long addr,
  86979. unsigned long end, unsigned long vm_flags,
  86980. - struct anon_vma *anon_vma, struct file *file,
  86981. + struct anon_vma *anon_vma, struct file *file,
  86982. pgoff_t pgoff, struct mempolicy *policy)
  86983. {
  86984. pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
  86985. struct vm_area_struct *area, *next;
  86986. int err;
  86987. +#ifdef CONFIG_PAX_SEGMEXEC
  86988. + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
  86989. + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
  86990. +
  86991. + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
  86992. +#endif
  86993. +
  86994. /*
  86995. * We later require that vma->vm_flags == vm_flags,
  86996. * so this tests vma->vm_flags & VM_SPECIAL, too.
  86997. @@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
  86998. if (next && next->vm_end == end) /* cases 6, 7, 8 */
  86999. next = next->vm_next;
  87000. +#ifdef CONFIG_PAX_SEGMEXEC
  87001. + if (prev)
  87002. + prev_m = pax_find_mirror_vma(prev);
  87003. + if (area)
  87004. + area_m = pax_find_mirror_vma(area);
  87005. + if (next)
  87006. + next_m = pax_find_mirror_vma(next);
  87007. +#endif
  87008. +
  87009. /*
  87010. * Can it merge with the predecessor?
  87011. */
  87012. @@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
  87013. /* cases 1, 6 */
  87014. err = vma_adjust(prev, prev->vm_start,
  87015. next->vm_end, prev->vm_pgoff, NULL);
  87016. - } else /* cases 2, 5, 7 */
  87017. +
  87018. +#ifdef CONFIG_PAX_SEGMEXEC
  87019. + if (!err && prev_m)
  87020. + err = vma_adjust(prev_m, prev_m->vm_start,
  87021. + next_m->vm_end, prev_m->vm_pgoff, NULL);
  87022. +#endif
  87023. +
  87024. + } else { /* cases 2, 5, 7 */
  87025. err = vma_adjust(prev, prev->vm_start,
  87026. end, prev->vm_pgoff, NULL);
  87027. +
  87028. +#ifdef CONFIG_PAX_SEGMEXEC
  87029. + if (!err && prev_m)
  87030. + err = vma_adjust(prev_m, prev_m->vm_start,
  87031. + end_m, prev_m->vm_pgoff, NULL);
  87032. +#endif
  87033. +
  87034. + }
  87035. if (err)
  87036. return NULL;
  87037. khugepaged_enter_vma_merge(prev);
  87038. @@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
  87039. mpol_equal(policy, vma_policy(next)) &&
  87040. can_vma_merge_before(next, vm_flags,
  87041. anon_vma, file, pgoff+pglen)) {
  87042. - if (prev && addr < prev->vm_end) /* case 4 */
  87043. + if (prev && addr < prev->vm_end) { /* case 4 */
  87044. err = vma_adjust(prev, prev->vm_start,
  87045. addr, prev->vm_pgoff, NULL);
  87046. - else /* cases 3, 8 */
  87047. +
  87048. +#ifdef CONFIG_PAX_SEGMEXEC
  87049. + if (!err && prev_m)
  87050. + err = vma_adjust(prev_m, prev_m->vm_start,
  87051. + addr_m, prev_m->vm_pgoff, NULL);
  87052. +#endif
  87053. +
  87054. + } else { /* cases 3, 8 */
  87055. err = vma_adjust(area, addr, next->vm_end,
  87056. next->vm_pgoff - pglen, NULL);
  87057. +
  87058. +#ifdef CONFIG_PAX_SEGMEXEC
  87059. + if (!err && area_m)
  87060. + err = vma_adjust(area_m, addr_m, next_m->vm_end,
  87061. + next_m->vm_pgoff - pglen, NULL);
  87062. +#endif
  87063. +
  87064. + }
  87065. if (err)
  87066. return NULL;
  87067. khugepaged_enter_vma_merge(area);
  87068. @@ -1172,8 +1253,10 @@ none:
  87069. void vm_stat_account(struct mm_struct *mm, unsigned long flags,
  87070. struct file *file, long pages)
  87071. {
  87072. - const unsigned long stack_flags
  87073. - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
  87074. +
  87075. +#ifdef CONFIG_PAX_RANDMMAP
  87076. + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
  87077. +#endif
  87078. mm->total_vm += pages;
  87079. @@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
  87080. mm->shared_vm += pages;
  87081. if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
  87082. mm->exec_vm += pages;
  87083. - } else if (flags & stack_flags)
  87084. + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
  87085. mm->stack_vm += pages;
  87086. }
  87087. #endif /* CONFIG_PROC_FS */
  87088. @@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
  87089. locked += mm->locked_vm;
  87090. lock_limit = rlimit(RLIMIT_MEMLOCK);
  87091. lock_limit >>= PAGE_SHIFT;
  87092. + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
  87093. if (locked > lock_limit && !capable(CAP_IPC_LOCK))
  87094. return -EAGAIN;
  87095. }
  87096. @@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  87097. * (the exception is when the underlying filesystem is noexec
  87098. * mounted, in which case we dont add PROT_EXEC.)
  87099. */
  87100. - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
  87101. + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
  87102. if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
  87103. prot |= PROT_EXEC;
  87104. @@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  87105. /* Obtain the address to map to. we verify (or select) it and ensure
  87106. * that it represents a valid section of the address space.
  87107. */
  87108. - addr = get_unmapped_area(file, addr, len, pgoff, flags);
  87109. + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
  87110. if (addr & ~PAGE_MASK)
  87111. return addr;
  87112. @@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  87113. vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
  87114. mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
  87115. +#ifdef CONFIG_PAX_MPROTECT
  87116. + if (mm->pax_flags & MF_PAX_MPROTECT) {
  87117. +
  87118. +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
  87119. + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
  87120. + mm->binfmt->handle_mmap)
  87121. + mm->binfmt->handle_mmap(file);
  87122. +#endif
  87123. +
  87124. +#ifndef CONFIG_PAX_MPROTECT_COMPAT
  87125. + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
  87126. + gr_log_rwxmmap(file);
  87127. +
  87128. +#ifdef CONFIG_PAX_EMUPLT
  87129. + vm_flags &= ~VM_EXEC;
  87130. +#else
  87131. + return -EPERM;
  87132. +#endif
  87133. +
  87134. + }
  87135. +
  87136. + if (!(vm_flags & VM_EXEC))
  87137. + vm_flags &= ~VM_MAYEXEC;
  87138. +#else
  87139. + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
  87140. + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
  87141. +#endif
  87142. + else
  87143. + vm_flags &= ~VM_MAYWRITE;
  87144. + }
  87145. +#endif
  87146. +
  87147. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
  87148. + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
  87149. + vm_flags &= ~VM_PAGEEXEC;
  87150. +#endif
  87151. +
  87152. if (flags & MAP_LOCKED)
  87153. if (!can_do_mlock())
  87154. return -EPERM;
  87155. @@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  87156. vm_flags |= VM_NORESERVE;
  87157. }
  87158. + if (!gr_acl_handle_mmap(file, prot))
  87159. + return -EACCES;
  87160. +
  87161. addr = mmap_region(file, addr, len, vm_flags, pgoff);
  87162. if (!IS_ERR_VALUE(addr) &&
  87163. ((vm_flags & VM_LOCKED) ||
  87164. @@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
  87165. vm_flags_t vm_flags = vma->vm_flags;
  87166. /* If it was private or non-writable, the write bit is already clear */
  87167. - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
  87168. + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
  87169. return 0;
  87170. /* The backer wishes to know when pages are first written to? */
  87171. @@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
  87172. struct rb_node **rb_link, *rb_parent;
  87173. unsigned long charged = 0;
  87174. +#ifdef CONFIG_PAX_SEGMEXEC
  87175. + struct vm_area_struct *vma_m = NULL;
  87176. +#endif
  87177. +
  87178. + /*
  87179. + * mm->mmap_sem is required to protect against another thread
  87180. + * changing the mappings in case we sleep.
  87181. + */
  87182. + verify_mm_writelocked(mm);
  87183. +
  87184. /* Check against address space limit. */
  87185. +
  87186. +#ifdef CONFIG_PAX_RANDMMAP
  87187. + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
  87188. +#endif
  87189. +
  87190. if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
  87191. unsigned long nr_pages;
  87192. @@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
  87193. /* Clear old maps */
  87194. error = -ENOMEM;
  87195. -munmap_back:
  87196. if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
  87197. if (do_munmap(mm, addr, len))
  87198. return -ENOMEM;
  87199. - goto munmap_back;
  87200. + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
  87201. }
  87202. /*
  87203. @@ -1554,6 +1692,16 @@ munmap_back:
  87204. goto unacct_error;
  87205. }
  87206. +#ifdef CONFIG_PAX_SEGMEXEC
  87207. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
  87208. + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  87209. + if (!vma_m) {
  87210. + error = -ENOMEM;
  87211. + goto free_vma;
  87212. + }
  87213. + }
  87214. +#endif
  87215. +
  87216. vma->vm_mm = mm;
  87217. vma->vm_start = addr;
  87218. vma->vm_end = addr + len;
  87219. @@ -1573,6 +1721,13 @@ munmap_back:
  87220. if (error)
  87221. goto unmap_and_free_vma;
  87222. +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
  87223. + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
  87224. + vma->vm_flags |= VM_PAGEEXEC;
  87225. + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  87226. + }
  87227. +#endif
  87228. +
  87229. /* Can addr have changed??
  87230. *
  87231. * Answer: Yes, several device drivers can do it in their
  87232. @@ -1606,6 +1761,12 @@ munmap_back:
  87233. }
  87234. vma_link(mm, vma, prev, rb_link, rb_parent);
  87235. +
  87236. +#ifdef CONFIG_PAX_SEGMEXEC
  87237. + if (vma_m)
  87238. + BUG_ON(pax_mirror_vma(vma_m, vma));
  87239. +#endif
  87240. +
  87241. /* Once vma denies write, undo our temporary denial count */
  87242. if (vm_flags & VM_DENYWRITE)
  87243. allow_write_access(file);
  87244. @@ -1614,6 +1775,7 @@ out:
  87245. perf_event_mmap(vma);
  87246. vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
  87247. + track_exec_limit(mm, addr, addr + len, vm_flags);
  87248. if (vm_flags & VM_LOCKED) {
  87249. if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
  87250. vma == get_gate_vma(current->mm)))
  87251. @@ -1646,6 +1808,12 @@ unmap_and_free_vma:
  87252. unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
  87253. charged = 0;
  87254. free_vma:
  87255. +
  87256. +#ifdef CONFIG_PAX_SEGMEXEC
  87257. + if (vma_m)
  87258. + kmem_cache_free(vm_area_cachep, vma_m);
  87259. +#endif
  87260. +
  87261. kmem_cache_free(vm_area_cachep, vma);
  87262. unacct_error:
  87263. if (charged)
  87264. @@ -1653,7 +1821,63 @@ unacct_error:
  87265. return error;
  87266. }
  87267. -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
  87268. +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
  87269. +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
  87270. +{
  87271. + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
  87272. + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
  87273. +
  87274. + return 0;
  87275. +}
  87276. +#endif
  87277. +
  87278. +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
  87279. +{
  87280. + if (!vma) {
  87281. +#ifdef CONFIG_STACK_GROWSUP
  87282. + if (addr > sysctl_heap_stack_gap)
  87283. + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
  87284. + else
  87285. + vma = find_vma(current->mm, 0);
  87286. + if (vma && (vma->vm_flags & VM_GROWSUP))
  87287. + return false;
  87288. +#endif
  87289. + return true;
  87290. + }
  87291. +
  87292. + if (addr + len > vma->vm_start)
  87293. + return false;
  87294. +
  87295. + if (vma->vm_flags & VM_GROWSDOWN)
  87296. + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
  87297. +#ifdef CONFIG_STACK_GROWSUP
  87298. + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
  87299. + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
  87300. +#endif
  87301. + else if (offset)
  87302. + return offset <= vma->vm_start - addr - len;
  87303. +
  87304. + return true;
  87305. +}
  87306. +
  87307. +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
  87308. +{
  87309. + if (vma->vm_start < len)
  87310. + return -ENOMEM;
  87311. +
  87312. + if (!(vma->vm_flags & VM_GROWSDOWN)) {
  87313. + if (offset <= vma->vm_start - len)
  87314. + return vma->vm_start - len - offset;
  87315. + else
  87316. + return -ENOMEM;
  87317. + }
  87318. +
  87319. + if (sysctl_heap_stack_gap <= vma->vm_start - len)
  87320. + return vma->vm_start - len - sysctl_heap_stack_gap;
  87321. + return -ENOMEM;
  87322. +}
  87323. +
  87324. +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
  87325. {
  87326. /*
  87327. * We implement the search by looking for an rbtree node that
  87328. @@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
  87329. }
  87330. }
  87331. - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
  87332. + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
  87333. check_current:
  87334. /* Check if current node has a suitable gap */
  87335. if (gap_start > high_limit)
  87336. return -ENOMEM;
  87337. +
  87338. + if (gap_end - gap_start > info->threadstack_offset)
  87339. + gap_start += info->threadstack_offset;
  87340. + else
  87341. + gap_start = gap_end;
  87342. +
  87343. + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
  87344. + if (gap_end - gap_start > sysctl_heap_stack_gap)
  87345. + gap_start += sysctl_heap_stack_gap;
  87346. + else
  87347. + gap_start = gap_end;
  87348. + }
  87349. + if (vma->vm_flags & VM_GROWSDOWN) {
  87350. + if (gap_end - gap_start > sysctl_heap_stack_gap)
  87351. + gap_end -= sysctl_heap_stack_gap;
  87352. + else
  87353. + gap_end = gap_start;
  87354. + }
  87355. if (gap_end >= low_limit && gap_end - gap_start >= length)
  87356. goto found;
  87357. @@ -1755,7 +1997,7 @@ found:
  87358. return gap_start;
  87359. }
  87360. -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
  87361. +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
  87362. {
  87363. struct mm_struct *mm = current->mm;
  87364. struct vm_area_struct *vma;
  87365. @@ -1809,6 +2051,24 @@ check_current:
  87366. gap_end = vma->vm_start;
  87367. if (gap_end < low_limit)
  87368. return -ENOMEM;
  87369. +
  87370. + if (gap_end - gap_start > info->threadstack_offset)
  87371. + gap_end -= info->threadstack_offset;
  87372. + else
  87373. + gap_end = gap_start;
  87374. +
  87375. + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
  87376. + if (gap_end - gap_start > sysctl_heap_stack_gap)
  87377. + gap_start += sysctl_heap_stack_gap;
  87378. + else
  87379. + gap_start = gap_end;
  87380. + }
  87381. + if (vma->vm_flags & VM_GROWSDOWN) {
  87382. + if (gap_end - gap_start > sysctl_heap_stack_gap)
  87383. + gap_end -= sysctl_heap_stack_gap;
  87384. + else
  87385. + gap_end = gap_start;
  87386. + }
  87387. if (gap_start <= high_limit && gap_end - gap_start >= length)
  87388. goto found;
  87389. @@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  87390. struct mm_struct *mm = current->mm;
  87391. struct vm_area_struct *vma;
  87392. struct vm_unmapped_area_info info;
  87393. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  87394. if (len > TASK_SIZE - mmap_min_addr)
  87395. return -ENOMEM;
  87396. @@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  87397. if (flags & MAP_FIXED)
  87398. return addr;
  87399. +#ifdef CONFIG_PAX_RANDMMAP
  87400. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  87401. +#endif
  87402. +
  87403. if (addr) {
  87404. addr = PAGE_ALIGN(addr);
  87405. vma = find_vma(mm, addr);
  87406. if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
  87407. - (!vma || addr + len <= vma->vm_start))
  87408. + check_heap_stack_gap(vma, addr, len, offset))
  87409. return addr;
  87410. }
  87411. @@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
  87412. info.low_limit = mm->mmap_base;
  87413. info.high_limit = TASK_SIZE;
  87414. info.align_mask = 0;
  87415. + info.threadstack_offset = offset;
  87416. return vm_unmapped_area(&info);
  87417. }
  87418. #endif
  87419. @@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  87420. struct mm_struct *mm = current->mm;
  87421. unsigned long addr = addr0;
  87422. struct vm_unmapped_area_info info;
  87423. + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
  87424. /* requested length too big for entire address space */
  87425. if (len > TASK_SIZE - mmap_min_addr)
  87426. @@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  87427. if (flags & MAP_FIXED)
  87428. return addr;
  87429. +#ifdef CONFIG_PAX_RANDMMAP
  87430. + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
  87431. +#endif
  87432. +
  87433. /* requesting a specific address */
  87434. if (addr) {
  87435. addr = PAGE_ALIGN(addr);
  87436. vma = find_vma(mm, addr);
  87437. if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
  87438. - (!vma || addr + len <= vma->vm_start))
  87439. + check_heap_stack_gap(vma, addr, len, offset))
  87440. return addr;
  87441. }
  87442. @@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  87443. info.low_limit = max(PAGE_SIZE, mmap_min_addr);
  87444. info.high_limit = mm->mmap_base;
  87445. info.align_mask = 0;
  87446. + info.threadstack_offset = offset;
  87447. addr = vm_unmapped_area(&info);
  87448. /*
  87449. @@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  87450. VM_BUG_ON(addr != -ENOMEM);
  87451. info.flags = 0;
  87452. info.low_limit = TASK_UNMAPPED_BASE;
  87453. +
  87454. +#ifdef CONFIG_PAX_RANDMMAP
  87455. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  87456. + info.low_limit += mm->delta_mmap;
  87457. +#endif
  87458. +
  87459. info.high_limit = TASK_SIZE;
  87460. addr = vm_unmapped_area(&info);
  87461. }
  87462. @@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
  87463. return vma;
  87464. }
  87465. +#ifdef CONFIG_PAX_SEGMEXEC
  87466. +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
  87467. +{
  87468. + struct vm_area_struct *vma_m;
  87469. +
  87470. + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
  87471. + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
  87472. + BUG_ON(vma->vm_mirror);
  87473. + return NULL;
  87474. + }
  87475. + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
  87476. + vma_m = vma->vm_mirror;
  87477. + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
  87478. + BUG_ON(vma->vm_file != vma_m->vm_file);
  87479. + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
  87480. + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
  87481. + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
  87482. + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
  87483. + return vma_m;
  87484. +}
  87485. +#endif
  87486. +
  87487. /*
  87488. * Verify that the stack growth is acceptable and
  87489. * update accounting. This is shared with both the
  87490. @@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
  87491. return -ENOMEM;
  87492. /* Stack limit test */
  87493. + gr_learn_resource(current, RLIMIT_STACK, size, 1);
  87494. if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
  87495. return -ENOMEM;
  87496. @@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
  87497. locked = mm->locked_vm + grow;
  87498. limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
  87499. limit >>= PAGE_SHIFT;
  87500. + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
  87501. if (locked > limit && !capable(CAP_IPC_LOCK))
  87502. return -ENOMEM;
  87503. }
  87504. @@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
  87505. * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
  87506. * vma is the last one with address > vma->vm_end. Have to extend vma.
  87507. */
  87508. +#ifndef CONFIG_IA64
  87509. +static
  87510. +#endif
  87511. int expand_upwards(struct vm_area_struct *vma, unsigned long address)
  87512. {
  87513. int error;
  87514. + bool locknext;
  87515. if (!(vma->vm_flags & VM_GROWSUP))
  87516. return -EFAULT;
  87517. + /* Also guard against wrapping around to address 0. */
  87518. + if (address < PAGE_ALIGN(address+1))
  87519. + address = PAGE_ALIGN(address+1);
  87520. + else
  87521. + return -ENOMEM;
  87522. +
  87523. /*
  87524. * We must make sure the anon_vma is allocated
  87525. * so that the anon_vma locking is not a noop.
  87526. */
  87527. if (unlikely(anon_vma_prepare(vma)))
  87528. return -ENOMEM;
  87529. + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
  87530. + if (locknext && anon_vma_prepare(vma->vm_next))
  87531. + return -ENOMEM;
  87532. vma_lock_anon_vma(vma);
  87533. + if (locknext)
  87534. + vma_lock_anon_vma(vma->vm_next);
  87535. /*
  87536. * vma->vm_start/vm_end cannot change under us because the caller
  87537. * is required to hold the mmap_sem in read mode. We need the
  87538. - * anon_vma lock to serialize against concurrent expand_stacks.
  87539. - * Also guard against wrapping around to address 0.
  87540. + * anon_vma locks to serialize against concurrent expand_stacks
  87541. + * and expand_upwards.
  87542. */
  87543. - if (address < PAGE_ALIGN(address+4))
  87544. - address = PAGE_ALIGN(address+4);
  87545. - else {
  87546. - vma_unlock_anon_vma(vma);
  87547. - return -ENOMEM;
  87548. - }
  87549. error = 0;
  87550. /* Somebody else might have raced and expanded it already */
  87551. - if (address > vma->vm_end) {
  87552. + if (vma->vm_next && (vma->vm_next->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && vma->vm_next->vm_start - address < sysctl_heap_stack_gap)
  87553. + error = -ENOMEM;
  87554. + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
  87555. unsigned long size, grow;
  87556. size = address - vma->vm_start;
  87557. @@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
  87558. }
  87559. }
  87560. }
  87561. + if (locknext)
  87562. + vma_unlock_anon_vma(vma->vm_next);
  87563. vma_unlock_anon_vma(vma);
  87564. khugepaged_enter_vma_merge(vma);
  87565. validate_mm(vma->vm_mm);
  87566. @@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
  87567. unsigned long address)
  87568. {
  87569. int error;
  87570. + bool lockprev = false;
  87571. + struct vm_area_struct *prev;
  87572. /*
  87573. * We must make sure the anon_vma is allocated
  87574. @@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
  87575. if (error)
  87576. return error;
  87577. + prev = vma->vm_prev;
  87578. +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
  87579. + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
  87580. +#endif
  87581. + if (lockprev && anon_vma_prepare(prev))
  87582. + return -ENOMEM;
  87583. + if (lockprev)
  87584. + vma_lock_anon_vma(prev);
  87585. +
  87586. vma_lock_anon_vma(vma);
  87587. /*
  87588. @@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
  87589. */
  87590. /* Somebody else might have raced and expanded it already */
  87591. - if (address < vma->vm_start) {
  87592. + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
  87593. + error = -ENOMEM;
  87594. + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
  87595. unsigned long size, grow;
  87596. +#ifdef CONFIG_PAX_SEGMEXEC
  87597. + struct vm_area_struct *vma_m;
  87598. +
  87599. + vma_m = pax_find_mirror_vma(vma);
  87600. +#endif
  87601. +
  87602. size = vma->vm_end - address;
  87603. grow = (vma->vm_start - address) >> PAGE_SHIFT;
  87604. @@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
  87605. vma->vm_pgoff -= grow;
  87606. anon_vma_interval_tree_post_update_vma(vma);
  87607. vma_gap_update(vma);
  87608. +
  87609. +#ifdef CONFIG_PAX_SEGMEXEC
  87610. + if (vma_m) {
  87611. + anon_vma_interval_tree_pre_update_vma(vma_m);
  87612. + vma_m->vm_start -= grow << PAGE_SHIFT;
  87613. + vma_m->vm_pgoff -= grow;
  87614. + anon_vma_interval_tree_post_update_vma(vma_m);
  87615. + vma_gap_update(vma_m);
  87616. + }
  87617. +#endif
  87618. +
  87619. spin_unlock(&vma->vm_mm->page_table_lock);
  87620. + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
  87621. perf_event_mmap(vma);
  87622. }
  87623. }
  87624. }
  87625. vma_unlock_anon_vma(vma);
  87626. + if (lockprev)
  87627. + vma_unlock_anon_vma(prev);
  87628. khugepaged_enter_vma_merge(vma);
  87629. validate_mm(vma->vm_mm);
  87630. return error;
  87631. @@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
  87632. do {
  87633. long nrpages = vma_pages(vma);
  87634. +#ifdef CONFIG_PAX_SEGMEXEC
  87635. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
  87636. + vma = remove_vma(vma);
  87637. + continue;
  87638. + }
  87639. +#endif
  87640. +
  87641. if (vma->vm_flags & VM_ACCOUNT)
  87642. nr_accounted += nrpages;
  87643. vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
  87644. @@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
  87645. insertion_point = (prev ? &prev->vm_next : &mm->mmap);
  87646. vma->vm_prev = NULL;
  87647. do {
  87648. +
  87649. +#ifdef CONFIG_PAX_SEGMEXEC
  87650. + if (vma->vm_mirror) {
  87651. + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
  87652. + vma->vm_mirror->vm_mirror = NULL;
  87653. + vma->vm_mirror->vm_flags &= ~VM_EXEC;
  87654. + vma->vm_mirror = NULL;
  87655. + }
  87656. +#endif
  87657. +
  87658. vma_rb_erase(vma, &mm->mm_rb);
  87659. mm->map_count--;
  87660. tail_vma = vma;
  87661. @@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
  87662. struct vm_area_struct *new;
  87663. int err = -ENOMEM;
  87664. +#ifdef CONFIG_PAX_SEGMEXEC
  87665. + struct vm_area_struct *vma_m, *new_m = NULL;
  87666. + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
  87667. +#endif
  87668. +
  87669. if (is_vm_hugetlb_page(vma) && (addr &
  87670. ~(huge_page_mask(hstate_vma(vma)))))
  87671. return -EINVAL;
  87672. +#ifdef CONFIG_PAX_SEGMEXEC
  87673. + vma_m = pax_find_mirror_vma(vma);
  87674. +#endif
  87675. +
  87676. new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
  87677. if (!new)
  87678. goto out_err;
  87679. +#ifdef CONFIG_PAX_SEGMEXEC
  87680. + if (vma_m) {
  87681. + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
  87682. + if (!new_m) {
  87683. + kmem_cache_free(vm_area_cachep, new);
  87684. + goto out_err;
  87685. + }
  87686. + }
  87687. +#endif
  87688. +
  87689. /* most fields are the same, copy all, and then fixup */
  87690. *new = *vma;
  87691. @@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
  87692. new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
  87693. }
  87694. +#ifdef CONFIG_PAX_SEGMEXEC
  87695. + if (vma_m) {
  87696. + *new_m = *vma_m;
  87697. + INIT_LIST_HEAD(&new_m->anon_vma_chain);
  87698. + new_m->vm_mirror = new;
  87699. + new->vm_mirror = new_m;
  87700. +
  87701. + if (new_below)
  87702. + new_m->vm_end = addr_m;
  87703. + else {
  87704. + new_m->vm_start = addr_m;
  87705. + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
  87706. + }
  87707. + }
  87708. +#endif
  87709. +
  87710. err = vma_dup_policy(vma, new);
  87711. if (err)
  87712. goto out_free_vma;
  87713. @@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
  87714. else
  87715. err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
  87716. +#ifdef CONFIG_PAX_SEGMEXEC
  87717. + if (!err && vma_m) {
  87718. + struct mempolicy *pol = vma_policy(new);
  87719. +
  87720. + if (anon_vma_clone(new_m, vma_m))
  87721. + goto out_free_mpol;
  87722. +
  87723. + mpol_get(pol);
  87724. + set_vma_policy(new_m, pol);
  87725. +
  87726. + if (new_m->vm_file)
  87727. + get_file(new_m->vm_file);
  87728. +
  87729. + if (new_m->vm_ops && new_m->vm_ops->open)
  87730. + new_m->vm_ops->open(new_m);
  87731. +
  87732. + if (new_below)
  87733. + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
  87734. + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
  87735. + else
  87736. + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
  87737. +
  87738. + if (err) {
  87739. + if (new_m->vm_ops && new_m->vm_ops->close)
  87740. + new_m->vm_ops->close(new_m);
  87741. + if (new_m->vm_file)
  87742. + fput(new_m->vm_file);
  87743. + mpol_put(pol);
  87744. + }
  87745. + }
  87746. +#endif
  87747. +
  87748. /* Success. */
  87749. if (!err)
  87750. return 0;
  87751. @@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
  87752. new->vm_ops->close(new);
  87753. if (new->vm_file)
  87754. fput(new->vm_file);
  87755. - unlink_anon_vmas(new);
  87756. out_free_mpol:
  87757. mpol_put(vma_policy(new));
  87758. out_free_vma:
  87759. +
  87760. +#ifdef CONFIG_PAX_SEGMEXEC
  87761. + if (new_m) {
  87762. + unlink_anon_vmas(new_m);
  87763. + kmem_cache_free(vm_area_cachep, new_m);
  87764. + }
  87765. +#endif
  87766. +
  87767. + unlink_anon_vmas(new);
  87768. kmem_cache_free(vm_area_cachep, new);
  87769. out_err:
  87770. return err;
  87771. @@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
  87772. int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
  87773. unsigned long addr, int new_below)
  87774. {
  87775. +
  87776. +#ifdef CONFIG_PAX_SEGMEXEC
  87777. + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
  87778. + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
  87779. + if (mm->map_count >= sysctl_max_map_count-1)
  87780. + return -ENOMEM;
  87781. + } else
  87782. +#endif
  87783. +
  87784. if (mm->map_count >= sysctl_max_map_count)
  87785. return -ENOMEM;
  87786. @@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
  87787. * work. This now handles partial unmappings.
  87788. * Jeremy Fitzhardinge <jeremy@goop.org>
  87789. */
  87790. +#ifdef CONFIG_PAX_SEGMEXEC
  87791. int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
  87792. {
  87793. + int ret = __do_munmap(mm, start, len);
  87794. + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
  87795. + return ret;
  87796. +
  87797. + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
  87798. +}
  87799. +
  87800. +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
  87801. +#else
  87802. +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
  87803. +#endif
  87804. +{
  87805. unsigned long end;
  87806. struct vm_area_struct *vma, *prev, *last;
  87807. + /*
  87808. + * mm->mmap_sem is required to protect against another thread
  87809. + * changing the mappings in case we sleep.
  87810. + */
  87811. + verify_mm_writelocked(mm);
  87812. +
  87813. if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
  87814. return -EINVAL;
  87815. @@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
  87816. /* Fix up all other VM information */
  87817. remove_vma_list(mm, vma);
  87818. + track_exec_limit(mm, start, end, 0UL);
  87819. +
  87820. return 0;
  87821. }
  87822. @@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
  87823. int ret;
  87824. struct mm_struct *mm = current->mm;
  87825. +
  87826. +#ifdef CONFIG_PAX_SEGMEXEC
  87827. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
  87828. + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
  87829. + return -EINVAL;
  87830. +#endif
  87831. +
  87832. down_write(&mm->mmap_sem);
  87833. ret = do_munmap(mm, start, len);
  87834. up_write(&mm->mmap_sem);
  87835. @@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
  87836. return vm_munmap(addr, len);
  87837. }
  87838. -static inline void verify_mm_writelocked(struct mm_struct *mm)
  87839. -{
  87840. -#ifdef CONFIG_DEBUG_VM
  87841. - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
  87842. - WARN_ON(1);
  87843. - up_read(&mm->mmap_sem);
  87844. - }
  87845. -#endif
  87846. -}
  87847. -
  87848. /*
  87849. * this is really a simplified "do_mmap". it only handles
  87850. * anonymous maps. eventually we may be able to do some
  87851. @@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
  87852. struct rb_node ** rb_link, * rb_parent;
  87853. pgoff_t pgoff = addr >> PAGE_SHIFT;
  87854. int error;
  87855. + unsigned long charged;
  87856. len = PAGE_ALIGN(len);
  87857. if (!len)
  87858. @@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
  87859. flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
  87860. +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
  87861. + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
  87862. + flags &= ~VM_EXEC;
  87863. +
  87864. +#ifdef CONFIG_PAX_MPROTECT
  87865. + if (mm->pax_flags & MF_PAX_MPROTECT)
  87866. + flags &= ~VM_MAYEXEC;
  87867. +#endif
  87868. +
  87869. + }
  87870. +#endif
  87871. +
  87872. error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
  87873. if (error & ~PAGE_MASK)
  87874. return error;
  87875. + charged = len >> PAGE_SHIFT;
  87876. +
  87877. error = mlock_future_check(mm, mm->def_flags, len);
  87878. if (error)
  87879. return error;
  87880. @@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
  87881. /*
  87882. * Clear old maps. this also does some error checking for us
  87883. */
  87884. - munmap_back:
  87885. if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
  87886. if (do_munmap(mm, addr, len))
  87887. return -ENOMEM;
  87888. - goto munmap_back;
  87889. + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
  87890. }
  87891. /* Check against address space limits *after* clearing old maps... */
  87892. - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
  87893. + if (!may_expand_vm(mm, charged))
  87894. return -ENOMEM;
  87895. if (mm->map_count > sysctl_max_map_count)
  87896. return -ENOMEM;
  87897. - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
  87898. + if (security_vm_enough_memory_mm(mm, charged))
  87899. return -ENOMEM;
  87900. /* Can we just expand an old private anonymous mapping? */
  87901. @@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
  87902. */
  87903. vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  87904. if (!vma) {
  87905. - vm_unacct_memory(len >> PAGE_SHIFT);
  87906. + vm_unacct_memory(charged);
  87907. return -ENOMEM;
  87908. }
  87909. @@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
  87910. vma_link(mm, vma, prev, rb_link, rb_parent);
  87911. out:
  87912. perf_event_mmap(vma);
  87913. - mm->total_vm += len >> PAGE_SHIFT;
  87914. + mm->total_vm += charged;
  87915. if (flags & VM_LOCKED)
  87916. - mm->locked_vm += (len >> PAGE_SHIFT);
  87917. + mm->locked_vm += charged;
  87918. vma->vm_flags |= VM_SOFTDIRTY;
  87919. + track_exec_limit(mm, addr, addr + len, flags);
  87920. return addr;
  87921. }
  87922. @@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
  87923. while (vma) {
  87924. if (vma->vm_flags & VM_ACCOUNT)
  87925. nr_accounted += vma_pages(vma);
  87926. + vma->vm_mirror = NULL;
  87927. vma = remove_vma(vma);
  87928. }
  87929. vm_unacct_memory(nr_accounted);
  87930. @@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
  87931. struct vm_area_struct *prev;
  87932. struct rb_node **rb_link, *rb_parent;
  87933. +#ifdef CONFIG_PAX_SEGMEXEC
  87934. + struct vm_area_struct *vma_m = NULL;
  87935. +#endif
  87936. +
  87937. + if (security_mmap_addr(vma->vm_start))
  87938. + return -EPERM;
  87939. +
  87940. /*
  87941. * The vm_pgoff of a purely anonymous vma should be irrelevant
  87942. * until its first write fault, when page's anon_vma and index
  87943. @@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
  87944. security_vm_enough_memory_mm(mm, vma_pages(vma)))
  87945. return -ENOMEM;
  87946. +#ifdef CONFIG_PAX_SEGMEXEC
  87947. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
  87948. + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  87949. + if (!vma_m)
  87950. + return -ENOMEM;
  87951. + }
  87952. +#endif
  87953. +
  87954. vma_link(mm, vma, prev, rb_link, rb_parent);
  87955. +
  87956. +#ifdef CONFIG_PAX_SEGMEXEC
  87957. + if (vma_m)
  87958. + BUG_ON(pax_mirror_vma(vma_m, vma));
  87959. +#endif
  87960. +
  87961. return 0;
  87962. }
  87963. @@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
  87964. struct rb_node **rb_link, *rb_parent;
  87965. bool faulted_in_anon_vma = true;
  87966. + BUG_ON(vma->vm_mirror);
  87967. +
  87968. /*
  87969. * If anonymous vma has not yet been faulted, update new pgoff
  87970. * to match new location, to increase its chance of merging.
  87971. @@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
  87972. return NULL;
  87973. }
  87974. +#ifdef CONFIG_PAX_SEGMEXEC
  87975. +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
  87976. +{
  87977. + struct vm_area_struct *prev_m;
  87978. + struct rb_node **rb_link_m, *rb_parent_m;
  87979. + struct mempolicy *pol_m;
  87980. +
  87981. + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
  87982. + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
  87983. + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
  87984. + *vma_m = *vma;
  87985. + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
  87986. + if (anon_vma_clone(vma_m, vma))
  87987. + return -ENOMEM;
  87988. + pol_m = vma_policy(vma_m);
  87989. + mpol_get(pol_m);
  87990. + set_vma_policy(vma_m, pol_m);
  87991. + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
  87992. + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
  87993. + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
  87994. + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
  87995. + if (vma_m->vm_file)
  87996. + get_file(vma_m->vm_file);
  87997. + if (vma_m->vm_ops && vma_m->vm_ops->open)
  87998. + vma_m->vm_ops->open(vma_m);
  87999. + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
  88000. + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
  88001. + vma_m->vm_mirror = vma;
  88002. + vma->vm_mirror = vma_m;
  88003. + return 0;
  88004. +}
  88005. +#endif
  88006. +
  88007. /*
  88008. * Return true if the calling process may expand its vm space by the passed
  88009. * number of pages
  88010. @@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
  88011. lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
  88012. + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
  88013. if (cur + npages > lim)
  88014. return 0;
  88015. return 1;
  88016. @@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
  88017. vma->vm_start = addr;
  88018. vma->vm_end = addr + len;
  88019. +#ifdef CONFIG_PAX_MPROTECT
  88020. + if (mm->pax_flags & MF_PAX_MPROTECT) {
  88021. +#ifndef CONFIG_PAX_MPROTECT_COMPAT
  88022. + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
  88023. + return -EPERM;
  88024. + if (!(vm_flags & VM_EXEC))
  88025. + vm_flags &= ~VM_MAYEXEC;
  88026. +#else
  88027. + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
  88028. + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
  88029. +#endif
  88030. + else
  88031. + vm_flags &= ~VM_MAYWRITE;
  88032. + }
  88033. +#endif
  88034. +
  88035. vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
  88036. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  88037. diff --git a/mm/mprotect.c b/mm/mprotect.c
  88038. index 769a67a..414d24f 100644
  88039. --- a/mm/mprotect.c
  88040. +++ b/mm/mprotect.c
  88041. @@ -24,10 +24,18 @@
  88042. #include <linux/migrate.h>
  88043. #include <linux/perf_event.h>
  88044. #include <linux/ksm.h>
  88045. +#include <linux/sched/sysctl.h>
  88046. +
  88047. +#ifdef CONFIG_PAX_MPROTECT
  88048. +#include <linux/elf.h>
  88049. +#include <linux/binfmts.h>
  88050. +#endif
  88051. +
  88052. #include <asm/uaccess.h>
  88053. #include <asm/pgtable.h>
  88054. #include <asm/cacheflush.h>
  88055. #include <asm/tlbflush.h>
  88056. +#include <asm/mmu_context.h>
  88057. #ifndef pgprot_modify
  88058. static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
  88059. @@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
  88060. return pages;
  88061. }
  88062. +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
  88063. +/* called while holding the mmap semaphor for writing except stack expansion */
  88064. +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
  88065. +{
  88066. + unsigned long oldlimit, newlimit = 0UL;
  88067. +
  88068. + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
  88069. + return;
  88070. +
  88071. + spin_lock(&mm->page_table_lock);
  88072. + oldlimit = mm->context.user_cs_limit;
  88073. + if ((prot & VM_EXEC) && oldlimit < end)
  88074. + /* USER_CS limit moved up */
  88075. + newlimit = end;
  88076. + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
  88077. + /* USER_CS limit moved down */
  88078. + newlimit = start;
  88079. +
  88080. + if (newlimit) {
  88081. + mm->context.user_cs_limit = newlimit;
  88082. +
  88083. +#ifdef CONFIG_SMP
  88084. + wmb();
  88085. + cpus_clear(mm->context.cpu_user_cs_mask);
  88086. + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
  88087. +#endif
  88088. +
  88089. + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
  88090. + }
  88091. + spin_unlock(&mm->page_table_lock);
  88092. + if (newlimit == end) {
  88093. + struct vm_area_struct *vma = find_vma(mm, oldlimit);
  88094. +
  88095. + for (; vma && vma->vm_start < end; vma = vma->vm_next)
  88096. + if (is_vm_hugetlb_page(vma))
  88097. + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
  88098. + else
  88099. + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
  88100. + }
  88101. +}
  88102. +#endif
  88103. +
  88104. int
  88105. mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
  88106. unsigned long start, unsigned long end, unsigned long newflags)
  88107. @@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
  88108. int error;
  88109. int dirty_accountable = 0;
  88110. +#ifdef CONFIG_PAX_SEGMEXEC
  88111. + struct vm_area_struct *vma_m = NULL;
  88112. + unsigned long start_m, end_m;
  88113. +
  88114. + start_m = start + SEGMEXEC_TASK_SIZE;
  88115. + end_m = end + SEGMEXEC_TASK_SIZE;
  88116. +#endif
  88117. +
  88118. if (newflags == oldflags) {
  88119. *pprev = vma;
  88120. return 0;
  88121. }
  88122. + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
  88123. + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
  88124. +
  88125. + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
  88126. + return -ENOMEM;
  88127. +
  88128. + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
  88129. + return -ENOMEM;
  88130. + }
  88131. +
  88132. /*
  88133. * If we make a private mapping writable we increase our commit;
  88134. * but (without finer accounting) cannot reduce our commit if we
  88135. @@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
  88136. }
  88137. }
  88138. +#ifdef CONFIG_PAX_SEGMEXEC
  88139. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
  88140. + if (start != vma->vm_start) {
  88141. + error = split_vma(mm, vma, start, 1);
  88142. + if (error)
  88143. + goto fail;
  88144. + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
  88145. + *pprev = (*pprev)->vm_next;
  88146. + }
  88147. +
  88148. + if (end != vma->vm_end) {
  88149. + error = split_vma(mm, vma, end, 0);
  88150. + if (error)
  88151. + goto fail;
  88152. + }
  88153. +
  88154. + if (pax_find_mirror_vma(vma)) {
  88155. + error = __do_munmap(mm, start_m, end_m - start_m);
  88156. + if (error)
  88157. + goto fail;
  88158. + } else {
  88159. + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  88160. + if (!vma_m) {
  88161. + error = -ENOMEM;
  88162. + goto fail;
  88163. + }
  88164. + vma->vm_flags = newflags;
  88165. + error = pax_mirror_vma(vma_m, vma);
  88166. + if (error) {
  88167. + vma->vm_flags = oldflags;
  88168. + goto fail;
  88169. + }
  88170. + }
  88171. + }
  88172. +#endif
  88173. +
  88174. /*
  88175. * First try to merge with previous and/or next vma.
  88176. */
  88177. @@ -277,9 +381,21 @@ success:
  88178. * vm_flags and vm_page_prot are protected by the mmap_sem
  88179. * held in write mode.
  88180. */
  88181. +
  88182. +#ifdef CONFIG_PAX_SEGMEXEC
  88183. + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
  88184. + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
  88185. +#endif
  88186. +
  88187. vma->vm_flags = newflags;
  88188. +
  88189. +#ifdef CONFIG_PAX_MPROTECT
  88190. + if (mm->binfmt && mm->binfmt->handle_mprotect)
  88191. + mm->binfmt->handle_mprotect(vma, newflags);
  88192. +#endif
  88193. +
  88194. vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
  88195. - vm_get_page_prot(newflags));
  88196. + vm_get_page_prot(vma->vm_flags));
  88197. if (vma_wants_writenotify(vma)) {
  88198. vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
  88199. @@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
  88200. end = start + len;
  88201. if (end <= start)
  88202. return -ENOMEM;
  88203. +
  88204. +#ifdef CONFIG_PAX_SEGMEXEC
  88205. + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
  88206. + if (end > SEGMEXEC_TASK_SIZE)
  88207. + return -EINVAL;
  88208. + } else
  88209. +#endif
  88210. +
  88211. + if (end > TASK_SIZE)
  88212. + return -EINVAL;
  88213. +
  88214. if (!arch_validate_prot(prot))
  88215. return -EINVAL;
  88216. @@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
  88217. /*
  88218. * Does the application expect PROT_READ to imply PROT_EXEC:
  88219. */
  88220. - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
  88221. + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
  88222. prot |= PROT_EXEC;
  88223. vm_flags = calc_vm_prot_bits(prot);
  88224. @@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
  88225. if (start > vma->vm_start)
  88226. prev = vma;
  88227. +#ifdef CONFIG_PAX_MPROTECT
  88228. + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
  88229. + current->mm->binfmt->handle_mprotect(vma, vm_flags);
  88230. +#endif
  88231. +
  88232. for (nstart = start ; ; ) {
  88233. unsigned long newflags;
  88234. @@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
  88235. /* newflags >> 4 shift VM_MAY% in place of VM_% */
  88236. if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
  88237. + if (prot & (PROT_WRITE | PROT_EXEC))
  88238. + gr_log_rwxmprotect(vma);
  88239. +
  88240. + error = -EACCES;
  88241. + goto out;
  88242. + }
  88243. +
  88244. + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
  88245. error = -EACCES;
  88246. goto out;
  88247. }
  88248. @@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
  88249. error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
  88250. if (error)
  88251. goto out;
  88252. +
  88253. + track_exec_limit(current->mm, nstart, tmp, vm_flags);
  88254. +
  88255. nstart = tmp;
  88256. if (nstart < prev->vm_end)
  88257. diff --git a/mm/mremap.c b/mm/mremap.c
  88258. index 0843feb..c3cde48 100644
  88259. --- a/mm/mremap.c
  88260. +++ b/mm/mremap.c
  88261. @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
  88262. continue;
  88263. pte = ptep_get_and_clear(mm, old_addr, old_pte);
  88264. pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
  88265. +
  88266. +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
  88267. + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
  88268. + pte = pte_exprotect(pte);
  88269. +#endif
  88270. +
  88271. pte = move_soft_dirty_pte(pte);
  88272. set_pte_at(mm, new_addr, new_pte, pte);
  88273. }
  88274. @@ -194,10 +200,17 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
  88275. break;
  88276. if (pmd_trans_huge(*old_pmd)) {
  88277. int err = 0;
  88278. - if (extent == HPAGE_PMD_SIZE)
  88279. + if (extent == HPAGE_PMD_SIZE) {
  88280. + VM_BUG_ON(vma->vm_file || !vma->anon_vma);
  88281. + /* See comment in move_ptes() */
  88282. + if (need_rmap_locks)
  88283. + anon_vma_lock_write(vma->anon_vma);
  88284. err = move_huge_pmd(vma, new_vma, old_addr,
  88285. new_addr, old_end,
  88286. old_pmd, new_pmd);
  88287. + if (need_rmap_locks)
  88288. + anon_vma_unlock_write(vma->anon_vma);
  88289. + }
  88290. if (err > 0) {
  88291. need_flush = true;
  88292. continue;
  88293. @@ -337,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
  88294. if (is_vm_hugetlb_page(vma))
  88295. goto Einval;
  88296. +#ifdef CONFIG_PAX_SEGMEXEC
  88297. + if (pax_find_mirror_vma(vma))
  88298. + goto Einval;
  88299. +#endif
  88300. +
  88301. /* We can't remap across vm area boundaries */
  88302. if (old_len > vma->vm_end - addr)
  88303. goto Efault;
  88304. @@ -392,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
  88305. unsigned long ret = -EINVAL;
  88306. unsigned long charged = 0;
  88307. unsigned long map_flags;
  88308. + unsigned long pax_task_size = TASK_SIZE;
  88309. if (new_addr & ~PAGE_MASK)
  88310. goto out;
  88311. - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
  88312. +#ifdef CONFIG_PAX_SEGMEXEC
  88313. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  88314. + pax_task_size = SEGMEXEC_TASK_SIZE;
  88315. +#endif
  88316. +
  88317. + pax_task_size -= PAGE_SIZE;
  88318. +
  88319. + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
  88320. goto out;
  88321. /* Check if the location we're moving into overlaps the
  88322. * old location at all, and fail if it does.
  88323. */
  88324. - if ((new_addr <= addr) && (new_addr+new_len) > addr)
  88325. - goto out;
  88326. -
  88327. - if ((addr <= new_addr) && (addr+old_len) > new_addr)
  88328. + if (addr + old_len > new_addr && new_addr + new_len > addr)
  88329. goto out;
  88330. ret = do_munmap(mm, new_addr, new_len);
  88331. @@ -474,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
  88332. unsigned long ret = -EINVAL;
  88333. unsigned long charged = 0;
  88334. bool locked = false;
  88335. + unsigned long pax_task_size = TASK_SIZE;
  88336. if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
  88337. return ret;
  88338. @@ -495,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
  88339. if (!new_len)
  88340. return ret;
  88341. +#ifdef CONFIG_PAX_SEGMEXEC
  88342. + if (mm->pax_flags & MF_PAX_SEGMEXEC)
  88343. + pax_task_size = SEGMEXEC_TASK_SIZE;
  88344. +#endif
  88345. +
  88346. + pax_task_size -= PAGE_SIZE;
  88347. +
  88348. + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
  88349. + old_len > pax_task_size || addr > pax_task_size-old_len)
  88350. + return ret;
  88351. +
  88352. down_write(&current->mm->mmap_sem);
  88353. if (flags & MREMAP_FIXED) {
  88354. @@ -545,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
  88355. new_addr = addr;
  88356. }
  88357. ret = addr;
  88358. + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
  88359. goto out;
  88360. }
  88361. }
  88362. @@ -568,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
  88363. goto out;
  88364. }
  88365. + map_flags = vma->vm_flags;
  88366. ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
  88367. + if (!(ret & ~PAGE_MASK)) {
  88368. + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
  88369. + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
  88370. + }
  88371. }
  88372. out:
  88373. if (ret & ~PAGE_MASK)
  88374. diff --git a/mm/nommu.c b/mm/nommu.c
  88375. index 8740213..f87e25b 100644
  88376. --- a/mm/nommu.c
  88377. +++ b/mm/nommu.c
  88378. @@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
  88379. int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
  88380. unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
  88381. unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
  88382. -int heap_stack_gap = 0;
  88383. atomic_long_t mmap_pages_allocated;
  88384. @@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
  88385. EXPORT_SYMBOL(find_vma);
  88386. /*
  88387. - * find a VMA
  88388. - * - we don't extend stack VMAs under NOMMU conditions
  88389. - */
  88390. -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
  88391. -{
  88392. - return find_vma(mm, addr);
  88393. -}
  88394. -
  88395. -/*
  88396. * expand a stack to a given address
  88397. * - not supported under NOMMU conditions
  88398. */
  88399. @@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
  88400. /* most fields are the same, copy all, and then fixup */
  88401. *new = *vma;
  88402. + INIT_LIST_HEAD(&new->anon_vma_chain);
  88403. *region = *vma->vm_region;
  88404. new->vm_region = region;
  88405. @@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
  88406. }
  88407. EXPORT_SYMBOL(generic_file_remap_pages);
  88408. -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  88409. - unsigned long addr, void *buf, int len, int write)
  88410. +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  88411. + unsigned long addr, void *buf, size_t len, int write)
  88412. {
  88413. struct vm_area_struct *vma;
  88414. @@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  88415. *
  88416. * The caller must hold a reference on @mm.
  88417. */
  88418. -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
  88419. - void *buf, int len, int write)
  88420. +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
  88421. + void *buf, size_t len, int write)
  88422. {
  88423. return __access_remote_vm(NULL, mm, addr, buf, len, write);
  88424. }
  88425. @@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
  88426. * Access another process' address space.
  88427. * - source/target buffer must be kernel space
  88428. */
  88429. -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
  88430. +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
  88431. {
  88432. struct mm_struct *mm;
  88433. diff --git a/mm/page-writeback.c b/mm/page-writeback.c
  88434. index 7106cb1..0805f48 100644
  88435. --- a/mm/page-writeback.c
  88436. +++ b/mm/page-writeback.c
  88437. @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
  88438. * card's bdi_dirty may rush to many times higher than bdi_setpoint.
  88439. * - the bdi dirty thresh drops quickly due to change of JBOD workload
  88440. */
  88441. -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
  88442. +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
  88443. unsigned long thresh,
  88444. unsigned long bg_thresh,
  88445. unsigned long dirty,
  88446. diff --git a/mm/page_alloc.c b/mm/page_alloc.c
  88447. index 7387a67..67105e4 100644
  88448. --- a/mm/page_alloc.c
  88449. +++ b/mm/page_alloc.c
  88450. @@ -61,6 +61,7 @@
  88451. #include <linux/page-debug-flags.h>
  88452. #include <linux/hugetlb.h>
  88453. #include <linux/sched/rt.h>
  88454. +#include <linux/random.h>
  88455. #include <asm/sections.h>
  88456. #include <asm/tlbflush.h>
  88457. @@ -354,7 +355,7 @@ out:
  88458. * This usage means that zero-order pages may not be compound.
  88459. */
  88460. -static void free_compound_page(struct page *page)
  88461. +void free_compound_page(struct page *page)
  88462. {
  88463. __free_pages_ok(page, compound_order(page));
  88464. }
  88465. @@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
  88466. int i;
  88467. int bad = 0;
  88468. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  88469. + unsigned long index = 1UL << order;
  88470. +#endif
  88471. +
  88472. trace_mm_page_free(page, order);
  88473. kmemcheck_free_shadow(page, order);
  88474. @@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
  88475. debug_check_no_obj_freed(page_address(page),
  88476. PAGE_SIZE << order);
  88477. }
  88478. +
  88479. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  88480. + for (; index; --index)
  88481. + sanitize_highpage(page + index - 1);
  88482. +#endif
  88483. +
  88484. arch_free_page(page, order);
  88485. kernel_map_pages(page, 1 << order, 0);
  88486. @@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
  88487. local_irq_restore(flags);
  88488. }
  88489. +#ifdef CONFIG_PAX_LATENT_ENTROPY
  88490. +bool __meminitdata extra_latent_entropy;
  88491. +
  88492. +static int __init setup_pax_extra_latent_entropy(char *str)
  88493. +{
  88494. + extra_latent_entropy = true;
  88495. + return 0;
  88496. +}
  88497. +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
  88498. +
  88499. +volatile u64 latent_entropy __latent_entropy;
  88500. +EXPORT_SYMBOL(latent_entropy);
  88501. +#endif
  88502. +
  88503. void __init __free_pages_bootmem(struct page *page, unsigned int order)
  88504. {
  88505. unsigned int nr_pages = 1 << order;
  88506. @@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
  88507. __ClearPageReserved(p);
  88508. set_page_count(p, 0);
  88509. +#ifdef CONFIG_PAX_LATENT_ENTROPY
  88510. + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
  88511. + u64 hash = 0;
  88512. + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
  88513. + const u64 *data = lowmem_page_address(page);
  88514. +
  88515. + for (index = 0; index < end; index++)
  88516. + hash ^= hash + data[index];
  88517. + latent_entropy ^= hash;
  88518. + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
  88519. + }
  88520. +#endif
  88521. +
  88522. page_zone(page)->managed_pages += nr_pages;
  88523. set_page_refcounted(page);
  88524. __free_pages(page, order);
  88525. @@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
  88526. arch_alloc_page(page, order);
  88527. kernel_map_pages(page, 1 << order, 1);
  88528. +#ifndef CONFIG_PAX_MEMORY_SANITIZE
  88529. if (gfp_flags & __GFP_ZERO)
  88530. prep_zero_page(page, order, gfp_flags);
  88531. +#endif
  88532. if (order && (gfp_flags & __GFP_COMP))
  88533. prep_compound_page(page, order);
  88534. @@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
  88535. continue;
  88536. mod_zone_page_state(zone, NR_ALLOC_BATCH,
  88537. high_wmark_pages(zone) - low_wmark_pages(zone) -
  88538. - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
  88539. + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
  88540. }
  88541. }
  88542. @@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
  88543. {
  88544. dump_page_badflags(page, reason, 0);
  88545. }
  88546. -EXPORT_SYMBOL_GPL(dump_page);
  88547. +EXPORT_SYMBOL(dump_page);
  88548. diff --git a/mm/page_io.c b/mm/page_io.c
  88549. index 7c59ef6..1358905 100644
  88550. --- a/mm/page_io.c
  88551. +++ b/mm/page_io.c
  88552. @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
  88553. struct file *swap_file = sis->swap_file;
  88554. struct address_space *mapping = swap_file->f_mapping;
  88555. struct iovec iov = {
  88556. - .iov_base = kmap(page),
  88557. + .iov_base = (void __force_user *)kmap(page),
  88558. .iov_len = PAGE_SIZE,
  88559. };
  88560. diff --git a/mm/percpu.c b/mm/percpu.c
  88561. index 036cfe0..980d0fa 100644
  88562. --- a/mm/percpu.c
  88563. +++ b/mm/percpu.c
  88564. @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
  88565. static unsigned int pcpu_high_unit_cpu __read_mostly;
  88566. /* the address of the first chunk which starts with the kernel static area */
  88567. -void *pcpu_base_addr __read_mostly;
  88568. +void *pcpu_base_addr __read_only;
  88569. EXPORT_SYMBOL_GPL(pcpu_base_addr);
  88570. static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
  88571. diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
  88572. index fd26d04..0cea1b0 100644
  88573. --- a/mm/process_vm_access.c
  88574. +++ b/mm/process_vm_access.c
  88575. @@ -13,6 +13,7 @@
  88576. #include <linux/uio.h>
  88577. #include <linux/sched.h>
  88578. #include <linux/highmem.h>
  88579. +#include <linux/security.h>
  88580. #include <linux/ptrace.h>
  88581. #include <linux/slab.h>
  88582. #include <linux/syscalls.h>
  88583. @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
  88584. size_t iov_l_curr_offset = 0;
  88585. ssize_t iov_len;
  88586. + return -ENOSYS; // PaX: until properly audited
  88587. +
  88588. /*
  88589. * Work out how many pages of struct pages we're going to need
  88590. * when eventually calling get_user_pages
  88591. */
  88592. for (i = 0; i < riovcnt; i++) {
  88593. iov_len = rvec[i].iov_len;
  88594. - if (iov_len > 0) {
  88595. - nr_pages_iov = ((unsigned long)rvec[i].iov_base
  88596. - + iov_len)
  88597. - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
  88598. - / PAGE_SIZE + 1;
  88599. - nr_pages = max(nr_pages, nr_pages_iov);
  88600. - }
  88601. + if (iov_len <= 0)
  88602. + continue;
  88603. + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
  88604. + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
  88605. + nr_pages = max(nr_pages, nr_pages_iov);
  88606. }
  88607. if (nr_pages == 0)
  88608. @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
  88609. goto free_proc_pages;
  88610. }
  88611. + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
  88612. + rc = -EPERM;
  88613. + goto put_task_struct;
  88614. + }
  88615. +
  88616. mm = mm_access(task, PTRACE_MODE_ATTACH);
  88617. if (!mm || IS_ERR(mm)) {
  88618. rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
  88619. diff --git a/mm/rmap.c b/mm/rmap.c
  88620. index d3cbac5..0788da4 100644
  88621. --- a/mm/rmap.c
  88622. +++ b/mm/rmap.c
  88623. @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
  88624. struct anon_vma *anon_vma = vma->anon_vma;
  88625. struct anon_vma_chain *avc;
  88626. +#ifdef CONFIG_PAX_SEGMEXEC
  88627. + struct anon_vma_chain *avc_m = NULL;
  88628. +#endif
  88629. +
  88630. might_sleep();
  88631. if (unlikely(!anon_vma)) {
  88632. struct mm_struct *mm = vma->vm_mm;
  88633. @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
  88634. if (!avc)
  88635. goto out_enomem;
  88636. +#ifdef CONFIG_PAX_SEGMEXEC
  88637. + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
  88638. + if (!avc_m)
  88639. + goto out_enomem_free_avc;
  88640. +#endif
  88641. +
  88642. anon_vma = find_mergeable_anon_vma(vma);
  88643. allocated = NULL;
  88644. if (!anon_vma) {
  88645. @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
  88646. /* page_table_lock to protect against threads */
  88647. spin_lock(&mm->page_table_lock);
  88648. if (likely(!vma->anon_vma)) {
  88649. +
  88650. +#ifdef CONFIG_PAX_SEGMEXEC
  88651. + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
  88652. +
  88653. + if (vma_m) {
  88654. + BUG_ON(vma_m->anon_vma);
  88655. + vma_m->anon_vma = anon_vma;
  88656. + anon_vma_chain_link(vma_m, avc_m, anon_vma);
  88657. + avc_m = NULL;
  88658. + }
  88659. +#endif
  88660. +
  88661. vma->anon_vma = anon_vma;
  88662. anon_vma_chain_link(vma, avc, anon_vma);
  88663. allocated = NULL;
  88664. @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
  88665. if (unlikely(allocated))
  88666. put_anon_vma(allocated);
  88667. +
  88668. +#ifdef CONFIG_PAX_SEGMEXEC
  88669. + if (unlikely(avc_m))
  88670. + anon_vma_chain_free(avc_m);
  88671. +#endif
  88672. +
  88673. if (unlikely(avc))
  88674. anon_vma_chain_free(avc);
  88675. }
  88676. return 0;
  88677. out_enomem_free_avc:
  88678. +
  88679. +#ifdef CONFIG_PAX_SEGMEXEC
  88680. + if (avc_m)
  88681. + anon_vma_chain_free(avc_m);
  88682. +#endif
  88683. +
  88684. anon_vma_chain_free(avc);
  88685. out_enomem:
  88686. return -ENOMEM;
  88687. @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
  88688. * Attach the anon_vmas from src to dst.
  88689. * Returns 0 on success, -ENOMEM on failure.
  88690. */
  88691. -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
  88692. +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
  88693. {
  88694. struct anon_vma_chain *avc, *pavc;
  88695. struct anon_vma *root = NULL;
  88696. @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
  88697. * the corresponding VMA in the parent process is attached to.
  88698. * Returns 0 on success, non-zero on failure.
  88699. */
  88700. -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
  88701. +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
  88702. {
  88703. struct anon_vma_chain *avc;
  88704. struct anon_vma *anon_vma;
  88705. @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
  88706. void __init anon_vma_init(void)
  88707. {
  88708. anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
  88709. - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
  88710. - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
  88711. + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
  88712. + anon_vma_ctor);
  88713. + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
  88714. + SLAB_PANIC|SLAB_NO_SANITIZE);
  88715. }
  88716. /*
  88717. diff --git a/mm/shmem.c b/mm/shmem.c
  88718. index 1f18c9d..3e03d33 100644
  88719. --- a/mm/shmem.c
  88720. +++ b/mm/shmem.c
  88721. @@ -33,7 +33,7 @@
  88722. #include <linux/swap.h>
  88723. #include <linux/aio.h>
  88724. -static struct vfsmount *shm_mnt;
  88725. +struct vfsmount *shm_mnt;
  88726. #ifdef CONFIG_SHMEM
  88727. /*
  88728. @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
  88729. #define BOGO_DIRENT_SIZE 20
  88730. /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
  88731. -#define SHORT_SYMLINK_LEN 128
  88732. +#define SHORT_SYMLINK_LEN 64
  88733. /*
  88734. * shmem_fallocate and shmem_writepage communicate via inode->i_private
  88735. @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
  88736. static int shmem_xattr_validate(const char *name)
  88737. {
  88738. struct { const char *prefix; size_t len; } arr[] = {
  88739. +
  88740. +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
  88741. + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
  88742. +#endif
  88743. +
  88744. { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
  88745. { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
  88746. };
  88747. @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
  88748. if (err)
  88749. return err;
  88750. +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
  88751. + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
  88752. + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
  88753. + return -EOPNOTSUPP;
  88754. + if (size > 8)
  88755. + return -EINVAL;
  88756. + }
  88757. +#endif
  88758. +
  88759. return simple_xattr_set(&info->xattrs, name, value, size, flags);
  88760. }
  88761. @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
  88762. int err = -ENOMEM;
  88763. /* Round up to L1_CACHE_BYTES to resist false sharing */
  88764. - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
  88765. - L1_CACHE_BYTES), GFP_KERNEL);
  88766. + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
  88767. if (!sbinfo)
  88768. return -ENOMEM;
  88769. diff --git a/mm/slab.c b/mm/slab.c
  88770. index b264214..83872cd 100644
  88771. --- a/mm/slab.c
  88772. +++ b/mm/slab.c
  88773. @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
  88774. if ((x)->max_freeable < i) \
  88775. (x)->max_freeable = i; \
  88776. } while (0)
  88777. -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
  88778. -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
  88779. -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
  88780. -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
  88781. +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
  88782. +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
  88783. +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
  88784. +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
  88785. +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
  88786. +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
  88787. #else
  88788. #define STATS_INC_ACTIVE(x) do { } while (0)
  88789. #define STATS_DEC_ACTIVE(x) do { } while (0)
  88790. @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
  88791. #define STATS_INC_ALLOCMISS(x) do { } while (0)
  88792. #define STATS_INC_FREEHIT(x) do { } while (0)
  88793. #define STATS_INC_FREEMISS(x) do { } while (0)
  88794. +#define STATS_INC_SANITIZED(x) do { } while (0)
  88795. +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
  88796. #endif
  88797. #if DEBUG
  88798. @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
  88799. * reciprocal_divide(offset, cache->reciprocal_buffer_size)
  88800. */
  88801. static inline unsigned int obj_to_index(const struct kmem_cache *cache,
  88802. - const struct page *page, void *obj)
  88803. + const struct page *page, const void *obj)
  88804. {
  88805. u32 offset = (obj - page->s_mem);
  88806. return reciprocal_divide(offset, cache->reciprocal_buffer_size);
  88807. @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
  88808. */
  88809. kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
  88810. - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
  88811. + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
  88812. if (INDEX_AC != INDEX_NODE)
  88813. kmalloc_caches[INDEX_NODE] =
  88814. create_kmalloc_cache("kmalloc-node",
  88815. - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
  88816. + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
  88817. slab_early_init = 0;
  88818. @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
  88819. struct array_cache *ac = cpu_cache_get(cachep);
  88820. check_irq_off();
  88821. +
  88822. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  88823. + if (pax_sanitize_slab) {
  88824. + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
  88825. + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
  88826. +
  88827. + if (cachep->ctor)
  88828. + cachep->ctor(objp);
  88829. +
  88830. + STATS_INC_SANITIZED(cachep);
  88831. + } else
  88832. + STATS_INC_NOT_SANITIZED(cachep);
  88833. + }
  88834. +#endif
  88835. +
  88836. kmemleak_free_recursive(objp, cachep->flags);
  88837. objp = cache_free_debugcheck(cachep, objp, caller);
  88838. @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
  88839. if (unlikely(ZERO_OR_NULL_PTR(objp)))
  88840. return;
  88841. + VM_BUG_ON(!virt_addr_valid(objp));
  88842. local_irq_save(flags);
  88843. kfree_debugcheck(objp);
  88844. c = virt_to_cache(objp);
  88845. @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
  88846. }
  88847. /* cpu stats */
  88848. {
  88849. - unsigned long allochit = atomic_read(&cachep->allochit);
  88850. - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
  88851. - unsigned long freehit = atomic_read(&cachep->freehit);
  88852. - unsigned long freemiss = atomic_read(&cachep->freemiss);
  88853. + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
  88854. + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
  88855. + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
  88856. + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
  88857. seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
  88858. allochit, allocmiss, freehit, freemiss);
  88859. }
  88860. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  88861. + {
  88862. + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
  88863. + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
  88864. +
  88865. + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
  88866. + }
  88867. +#endif
  88868. #endif
  88869. }
  88870. @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
  88871. static int __init slab_proc_init(void)
  88872. {
  88873. #ifdef CONFIG_DEBUG_SLAB_LEAK
  88874. - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
  88875. + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
  88876. #endif
  88877. return 0;
  88878. }
  88879. module_init(slab_proc_init);
  88880. #endif
  88881. +bool is_usercopy_object(const void *ptr)
  88882. +{
  88883. + struct page *page;
  88884. + struct kmem_cache *cachep;
  88885. +
  88886. + if (ZERO_OR_NULL_PTR(ptr))
  88887. + return false;
  88888. +
  88889. + if (!slab_is_available())
  88890. + return false;
  88891. +
  88892. + if (!virt_addr_valid(ptr))
  88893. + return false;
  88894. +
  88895. + page = virt_to_head_page(ptr);
  88896. +
  88897. + if (!PageSlab(page))
  88898. + return false;
  88899. +
  88900. + cachep = page->slab_cache;
  88901. + return cachep->flags & SLAB_USERCOPY;
  88902. +}
  88903. +
  88904. +#ifdef CONFIG_PAX_USERCOPY
  88905. +const char *check_heap_object(const void *ptr, unsigned long n)
  88906. +{
  88907. + struct page *page;
  88908. + struct kmem_cache *cachep;
  88909. + unsigned int objnr;
  88910. + unsigned long offset;
  88911. +
  88912. + if (ZERO_OR_NULL_PTR(ptr))
  88913. + return "<null>";
  88914. +
  88915. + if (!virt_addr_valid(ptr))
  88916. + return NULL;
  88917. +
  88918. + page = virt_to_head_page(ptr);
  88919. +
  88920. + if (!PageSlab(page))
  88921. + return NULL;
  88922. +
  88923. + cachep = page->slab_cache;
  88924. + if (!(cachep->flags & SLAB_USERCOPY))
  88925. + return cachep->name;
  88926. +
  88927. + objnr = obj_to_index(cachep, page, ptr);
  88928. + BUG_ON(objnr >= cachep->num);
  88929. + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
  88930. + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
  88931. + return NULL;
  88932. +
  88933. + return cachep->name;
  88934. +}
  88935. +#endif
  88936. +
  88937. /**
  88938. * ksize - get the actual amount of memory allocated for a given object
  88939. * @objp: Pointer to the object
  88940. diff --git a/mm/slab.h b/mm/slab.h
  88941. index 8184a7c..ab27737 100644
  88942. --- a/mm/slab.h
  88943. +++ b/mm/slab.h
  88944. @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
  88945. /* The slab cache that manages slab cache information */
  88946. extern struct kmem_cache *kmem_cache;
  88947. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  88948. +#ifdef CONFIG_X86_64
  88949. +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
  88950. +#else
  88951. +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
  88952. +#endif
  88953. +extern bool pax_sanitize_slab;
  88954. +#endif
  88955. +
  88956. unsigned long calculate_alignment(unsigned long flags,
  88957. unsigned long align, unsigned long size);
  88958. @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
  88959. /* Legal flag mask for kmem_cache_create(), for various configurations */
  88960. #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
  88961. - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
  88962. + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
  88963. + SLAB_USERCOPY | SLAB_NO_SANITIZE)
  88964. #if defined(CONFIG_DEBUG_SLAB)
  88965. #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
  88966. @@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
  88967. return s;
  88968. page = virt_to_head_page(x);
  88969. +
  88970. + BUG_ON(!PageSlab(page));
  88971. +
  88972. cachep = page->slab_cache;
  88973. if (slab_equal_or_root(cachep, s))
  88974. return cachep;
  88975. diff --git a/mm/slab_common.c b/mm/slab_common.c
  88976. index 1ec3c61..2067c11 100644
  88977. --- a/mm/slab_common.c
  88978. +++ b/mm/slab_common.c
  88979. @@ -23,11 +23,22 @@
  88980. #include "slab.h"
  88981. -enum slab_state slab_state;
  88982. +enum slab_state slab_state __read_only;
  88983. LIST_HEAD(slab_caches);
  88984. DEFINE_MUTEX(slab_mutex);
  88985. struct kmem_cache *kmem_cache;
  88986. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  88987. +bool pax_sanitize_slab __read_only = true;
  88988. +static int __init pax_sanitize_slab_setup(char *str)
  88989. +{
  88990. + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
  88991. + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
  88992. + return 1;
  88993. +}
  88994. +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
  88995. +#endif
  88996. +
  88997. #ifdef CONFIG_DEBUG_VM
  88998. static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
  88999. size_t size)
  89000. @@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
  89001. if (err)
  89002. goto out_free_cache;
  89003. - s->refcount = 1;
  89004. + atomic_set(&s->refcount, 1);
  89005. list_add(&s->list, &slab_caches);
  89006. memcg_register_cache(s);
  89007. @@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
  89008. get_online_cpus();
  89009. mutex_lock(&slab_mutex);
  89010. - s->refcount--;
  89011. - if (!s->refcount) {
  89012. + if (atomic_dec_and_test(&s->refcount)) {
  89013. list_del(&s->list);
  89014. if (!__kmem_cache_shutdown(s)) {
  89015. @@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
  89016. panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
  89017. name, size, err);
  89018. - s->refcount = -1; /* Exempt from merging for now */
  89019. + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
  89020. }
  89021. struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
  89022. @@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
  89023. create_boot_cache(s, name, size, flags);
  89024. list_add(&s->list, &slab_caches);
  89025. - s->refcount = 1;
  89026. + atomic_set(&s->refcount, 1);
  89027. return s;
  89028. }
  89029. @@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
  89030. EXPORT_SYMBOL(kmalloc_dma_caches);
  89031. #endif
  89032. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89033. +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
  89034. +EXPORT_SYMBOL(kmalloc_usercopy_caches);
  89035. +#endif
  89036. +
  89037. /*
  89038. * Conversion table for small slabs sizes / 8 to the index in the
  89039. * kmalloc array. This is necessary for slabs < 192 since we have non power
  89040. @@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
  89041. return kmalloc_dma_caches[index];
  89042. #endif
  89043. +
  89044. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89045. + if (unlikely((flags & GFP_USERCOPY)))
  89046. + return kmalloc_usercopy_caches[index];
  89047. +
  89048. +#endif
  89049. +
  89050. return kmalloc_caches[index];
  89051. }
  89052. @@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
  89053. for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
  89054. if (!kmalloc_caches[i]) {
  89055. kmalloc_caches[i] = create_kmalloc_cache(NULL,
  89056. - 1 << i, flags);
  89057. + 1 << i, SLAB_USERCOPY | flags);
  89058. }
  89059. /*
  89060. @@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
  89061. * earlier power of two caches
  89062. */
  89063. if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
  89064. - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
  89065. + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
  89066. if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
  89067. - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
  89068. + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
  89069. }
  89070. /* Kmalloc array is now usable */
  89071. @@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
  89072. }
  89073. }
  89074. #endif
  89075. +
  89076. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89077. + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
  89078. + struct kmem_cache *s = kmalloc_caches[i];
  89079. +
  89080. + if (s) {
  89081. + int size = kmalloc_size(i);
  89082. + char *n = kasprintf(GFP_NOWAIT,
  89083. + "usercopy-kmalloc-%d", size);
  89084. +
  89085. + BUG_ON(!n);
  89086. + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
  89087. + size, SLAB_USERCOPY | flags);
  89088. + }
  89089. + }
  89090. +#endif
  89091. +
  89092. }
  89093. #endif /* !CONFIG_SLOB */
  89094. @@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
  89095. seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
  89096. "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
  89097. seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
  89098. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  89099. + seq_puts(m, " : pax <sanitized> <not_sanitized>");
  89100. +#endif
  89101. #endif
  89102. seq_putc(m, '\n');
  89103. }
  89104. diff --git a/mm/slob.c b/mm/slob.c
  89105. index 4bf8809..98a6914 100644
  89106. --- a/mm/slob.c
  89107. +++ b/mm/slob.c
  89108. @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
  89109. /*
  89110. * Return the size of a slob block.
  89111. */
  89112. -static slobidx_t slob_units(slob_t *s)
  89113. +static slobidx_t slob_units(const slob_t *s)
  89114. {
  89115. if (s->units > 0)
  89116. return s->units;
  89117. @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
  89118. /*
  89119. * Return the next free slob block pointer after this one.
  89120. */
  89121. -static slob_t *slob_next(slob_t *s)
  89122. +static slob_t *slob_next(const slob_t *s)
  89123. {
  89124. slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
  89125. slobidx_t next;
  89126. @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
  89127. /*
  89128. * Returns true if s is the last free block in its page.
  89129. */
  89130. -static int slob_last(slob_t *s)
  89131. +static int slob_last(const slob_t *s)
  89132. {
  89133. return !((unsigned long)slob_next(s) & ~PAGE_MASK);
  89134. }
  89135. -static void *slob_new_pages(gfp_t gfp, int order, int node)
  89136. +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
  89137. {
  89138. - void *page;
  89139. + struct page *page;
  89140. #ifdef CONFIG_NUMA
  89141. if (node != NUMA_NO_NODE)
  89142. @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
  89143. if (!page)
  89144. return NULL;
  89145. - return page_address(page);
  89146. + __SetPageSlab(page);
  89147. + return page;
  89148. }
  89149. -static void slob_free_pages(void *b, int order)
  89150. +static void slob_free_pages(struct page *sp, int order)
  89151. {
  89152. if (current->reclaim_state)
  89153. current->reclaim_state->reclaimed_slab += 1 << order;
  89154. - free_pages((unsigned long)b, order);
  89155. + __ClearPageSlab(sp);
  89156. + page_mapcount_reset(sp);
  89157. + sp->private = 0;
  89158. + __free_pages(sp, order);
  89159. }
  89160. /*
  89161. @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
  89162. /* Not enough space: must allocate a new page */
  89163. if (!b) {
  89164. - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
  89165. - if (!b)
  89166. + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
  89167. + if (!sp)
  89168. return NULL;
  89169. - sp = virt_to_page(b);
  89170. - __SetPageSlab(sp);
  89171. + b = page_address(sp);
  89172. spin_lock_irqsave(&slob_lock, flags);
  89173. sp->units = SLOB_UNITS(PAGE_SIZE);
  89174. sp->freelist = b;
  89175. + sp->private = 0;
  89176. INIT_LIST_HEAD(&sp->list);
  89177. set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
  89178. set_slob_page_free(sp, slob_list);
  89179. @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
  89180. if (slob_page_free(sp))
  89181. clear_slob_page_free(sp);
  89182. spin_unlock_irqrestore(&slob_lock, flags);
  89183. - __ClearPageSlab(sp);
  89184. - page_mapcount_reset(sp);
  89185. - slob_free_pages(b, 0);
  89186. + slob_free_pages(sp, 0);
  89187. return;
  89188. }
  89189. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  89190. + if (pax_sanitize_slab)
  89191. + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
  89192. +#endif
  89193. +
  89194. if (!slob_page_free(sp)) {
  89195. /* This slob page is about to become partially free. Easy! */
  89196. sp->units = units;
  89197. @@ -424,11 +431,10 @@ out:
  89198. */
  89199. static __always_inline void *
  89200. -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
  89201. +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
  89202. {
  89203. - unsigned int *m;
  89204. - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
  89205. - void *ret;
  89206. + slob_t *m;
  89207. + void *ret = NULL;
  89208. gfp &= gfp_allowed_mask;
  89209. @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
  89210. if (!m)
  89211. return NULL;
  89212. - *m = size;
  89213. + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
  89214. + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
  89215. + m[0].units = size;
  89216. + m[1].units = align;
  89217. ret = (void *)m + align;
  89218. trace_kmalloc_node(caller, ret,
  89219. size, size + align, gfp, node);
  89220. } else {
  89221. unsigned int order = get_order(size);
  89222. + struct page *page;
  89223. if (likely(order))
  89224. gfp |= __GFP_COMP;
  89225. - ret = slob_new_pages(gfp, order, node);
  89226. + page = slob_new_pages(gfp, order, node);
  89227. + if (page) {
  89228. + ret = page_address(page);
  89229. + page->private = size;
  89230. + }
  89231. trace_kmalloc_node(caller, ret,
  89232. size, PAGE_SIZE << order, gfp, node);
  89233. }
  89234. - kmemleak_alloc(ret, size, 1, gfp);
  89235. + return ret;
  89236. +}
  89237. +
  89238. +static __always_inline void *
  89239. +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
  89240. +{
  89241. + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
  89242. + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
  89243. +
  89244. + if (!ZERO_OR_NULL_PTR(ret))
  89245. + kmemleak_alloc(ret, size, 1, gfp);
  89246. return ret;
  89247. }
  89248. @@ -493,34 +517,112 @@ void kfree(const void *block)
  89249. return;
  89250. kmemleak_free(block);
  89251. + VM_BUG_ON(!virt_addr_valid(block));
  89252. sp = virt_to_page(block);
  89253. - if (PageSlab(sp)) {
  89254. + VM_BUG_ON(!PageSlab(sp));
  89255. + if (!sp->private) {
  89256. int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
  89257. - unsigned int *m = (unsigned int *)(block - align);
  89258. - slob_free(m, *m + align);
  89259. - } else
  89260. + slob_t *m = (slob_t *)(block - align);
  89261. + slob_free(m, m[0].units + align);
  89262. + } else {
  89263. + __ClearPageSlab(sp);
  89264. + page_mapcount_reset(sp);
  89265. + sp->private = 0;
  89266. __free_pages(sp, compound_order(sp));
  89267. + }
  89268. }
  89269. EXPORT_SYMBOL(kfree);
  89270. +bool is_usercopy_object(const void *ptr)
  89271. +{
  89272. + if (!slab_is_available())
  89273. + return false;
  89274. +
  89275. + // PAX: TODO
  89276. +
  89277. + return false;
  89278. +}
  89279. +
  89280. +#ifdef CONFIG_PAX_USERCOPY
  89281. +const char *check_heap_object(const void *ptr, unsigned long n)
  89282. +{
  89283. + struct page *page;
  89284. + const slob_t *free;
  89285. + const void *base;
  89286. + unsigned long flags;
  89287. +
  89288. + if (ZERO_OR_NULL_PTR(ptr))
  89289. + return "<null>";
  89290. +
  89291. + if (!virt_addr_valid(ptr))
  89292. + return NULL;
  89293. +
  89294. + page = virt_to_head_page(ptr);
  89295. + if (!PageSlab(page))
  89296. + return NULL;
  89297. +
  89298. + if (page->private) {
  89299. + base = page;
  89300. + if (base <= ptr && n <= page->private - (ptr - base))
  89301. + return NULL;
  89302. + return "<slob>";
  89303. + }
  89304. +
  89305. + /* some tricky double walking to find the chunk */
  89306. + spin_lock_irqsave(&slob_lock, flags);
  89307. + base = (void *)((unsigned long)ptr & PAGE_MASK);
  89308. + free = page->freelist;
  89309. +
  89310. + while (!slob_last(free) && (void *)free <= ptr) {
  89311. + base = free + slob_units(free);
  89312. + free = slob_next(free);
  89313. + }
  89314. +
  89315. + while (base < (void *)free) {
  89316. + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
  89317. + int size = SLOB_UNIT * SLOB_UNITS(m + align);
  89318. + int offset;
  89319. +
  89320. + if (ptr < base + align)
  89321. + break;
  89322. +
  89323. + offset = ptr - base - align;
  89324. + if (offset >= m) {
  89325. + base += size;
  89326. + continue;
  89327. + }
  89328. +
  89329. + if (n > m - offset)
  89330. + break;
  89331. +
  89332. + spin_unlock_irqrestore(&slob_lock, flags);
  89333. + return NULL;
  89334. + }
  89335. +
  89336. + spin_unlock_irqrestore(&slob_lock, flags);
  89337. + return "<slob>";
  89338. +}
  89339. +#endif
  89340. +
  89341. /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
  89342. size_t ksize(const void *block)
  89343. {
  89344. struct page *sp;
  89345. int align;
  89346. - unsigned int *m;
  89347. + slob_t *m;
  89348. BUG_ON(!block);
  89349. if (unlikely(block == ZERO_SIZE_PTR))
  89350. return 0;
  89351. sp = virt_to_page(block);
  89352. - if (unlikely(!PageSlab(sp)))
  89353. - return PAGE_SIZE << compound_order(sp);
  89354. + VM_BUG_ON(!PageSlab(sp));
  89355. + if (sp->private)
  89356. + return sp->private;
  89357. align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
  89358. - m = (unsigned int *)(block - align);
  89359. - return SLOB_UNITS(*m) * SLOB_UNIT;
  89360. + m = (slob_t *)(block - align);
  89361. + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
  89362. }
  89363. EXPORT_SYMBOL(ksize);
  89364. @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
  89365. void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
  89366. {
  89367. - void *b;
  89368. + void *b = NULL;
  89369. flags &= gfp_allowed_mask;
  89370. lockdep_trace_alloc(flags);
  89371. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89372. + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
  89373. +#else
  89374. if (c->size < PAGE_SIZE) {
  89375. b = slob_alloc(c->size, flags, c->align, node);
  89376. trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
  89377. SLOB_UNITS(c->size) * SLOB_UNIT,
  89378. flags, node);
  89379. } else {
  89380. - b = slob_new_pages(flags, get_order(c->size), node);
  89381. + struct page *sp;
  89382. +
  89383. + sp = slob_new_pages(flags, get_order(c->size), node);
  89384. + if (sp) {
  89385. + b = page_address(sp);
  89386. + sp->private = c->size;
  89387. + }
  89388. trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
  89389. PAGE_SIZE << get_order(c->size),
  89390. flags, node);
  89391. }
  89392. +#endif
  89393. if (b && c->ctor)
  89394. c->ctor(b);
  89395. @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
  89396. static void __kmem_cache_free(void *b, int size)
  89397. {
  89398. - if (size < PAGE_SIZE)
  89399. + struct page *sp;
  89400. +
  89401. + sp = virt_to_page(b);
  89402. + BUG_ON(!PageSlab(sp));
  89403. + if (!sp->private)
  89404. slob_free(b, size);
  89405. else
  89406. - slob_free_pages(b, get_order(size));
  89407. + slob_free_pages(sp, get_order(size));
  89408. }
  89409. static void kmem_rcu_free(struct rcu_head *head)
  89410. @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
  89411. void kmem_cache_free(struct kmem_cache *c, void *b)
  89412. {
  89413. + int size = c->size;
  89414. +
  89415. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89416. + if (size + c->align < PAGE_SIZE) {
  89417. + size += c->align;
  89418. + b -= c->align;
  89419. + }
  89420. +#endif
  89421. +
  89422. kmemleak_free_recursive(b, c->flags);
  89423. if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
  89424. struct slob_rcu *slob_rcu;
  89425. - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
  89426. - slob_rcu->size = c->size;
  89427. + slob_rcu = b + (size - sizeof(struct slob_rcu));
  89428. + slob_rcu->size = size;
  89429. call_rcu(&slob_rcu->head, kmem_rcu_free);
  89430. } else {
  89431. - __kmem_cache_free(b, c->size);
  89432. + __kmem_cache_free(b, size);
  89433. }
  89434. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89435. + trace_kfree(_RET_IP_, b);
  89436. +#else
  89437. trace_kmem_cache_free(_RET_IP_, b);
  89438. +#endif
  89439. +
  89440. }
  89441. EXPORT_SYMBOL(kmem_cache_free);
  89442. diff --git a/mm/slub.c b/mm/slub.c
  89443. index 25f14ad..ff4d0b7 100644
  89444. --- a/mm/slub.c
  89445. +++ b/mm/slub.c
  89446. @@ -207,7 +207,7 @@ struct track {
  89447. enum track_item { TRACK_ALLOC, TRACK_FREE };
  89448. -#ifdef CONFIG_SYSFS
  89449. +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
  89450. static int sysfs_slab_add(struct kmem_cache *);
  89451. static int sysfs_slab_alias(struct kmem_cache *, const char *);
  89452. static void sysfs_slab_remove(struct kmem_cache *);
  89453. @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
  89454. if (!t->addr)
  89455. return;
  89456. - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
  89457. + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
  89458. s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
  89459. #ifdef CONFIG_STACKTRACE
  89460. {
  89461. @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
  89462. slab_free_hook(s, x);
  89463. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  89464. + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
  89465. + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
  89466. + if (s->ctor)
  89467. + s->ctor(x);
  89468. + }
  89469. +#endif
  89470. +
  89471. redo:
  89472. /*
  89473. * Determine the currently cpus per cpu slab.
  89474. @@ -2733,7 +2741,7 @@ static int slub_min_objects;
  89475. * Merge control. If this is set then no merging of slab caches will occur.
  89476. * (Could be removed. This was introduced to pacify the merge skeptics.)
  89477. */
  89478. -static int slub_nomerge;
  89479. +static int slub_nomerge = 1;
  89480. /*
  89481. * Calculate the order of allocation given an slab object size.
  89482. @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
  89483. s->inuse = size;
  89484. if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
  89485. +#ifdef CONFIG_PAX_MEMORY_SANITIZE
  89486. + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
  89487. +#endif
  89488. s->ctor)) {
  89489. /*
  89490. * Relocate free pointer after the object if it is not
  89491. @@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
  89492. EXPORT_SYMBOL(__kmalloc_node);
  89493. #endif
  89494. +bool is_usercopy_object(const void *ptr)
  89495. +{
  89496. + struct page *page;
  89497. + struct kmem_cache *s;
  89498. +
  89499. + if (ZERO_OR_NULL_PTR(ptr))
  89500. + return false;
  89501. +
  89502. + if (!slab_is_available())
  89503. + return false;
  89504. +
  89505. + if (!virt_addr_valid(ptr))
  89506. + return false;
  89507. +
  89508. + page = virt_to_head_page(ptr);
  89509. +
  89510. + if (!PageSlab(page))
  89511. + return false;
  89512. +
  89513. + s = page->slab_cache;
  89514. + return s->flags & SLAB_USERCOPY;
  89515. +}
  89516. +
  89517. +#ifdef CONFIG_PAX_USERCOPY
  89518. +const char *check_heap_object(const void *ptr, unsigned long n)
  89519. +{
  89520. + struct page *page;
  89521. + struct kmem_cache *s;
  89522. + unsigned long offset;
  89523. +
  89524. + if (ZERO_OR_NULL_PTR(ptr))
  89525. + return "<null>";
  89526. +
  89527. + if (!virt_addr_valid(ptr))
  89528. + return NULL;
  89529. +
  89530. + page = virt_to_head_page(ptr);
  89531. +
  89532. + if (!PageSlab(page))
  89533. + return NULL;
  89534. +
  89535. + s = page->slab_cache;
  89536. + if (!(s->flags & SLAB_USERCOPY))
  89537. + return s->name;
  89538. +
  89539. + offset = (ptr - page_address(page)) % s->size;
  89540. + if (offset <= s->object_size && n <= s->object_size - offset)
  89541. + return NULL;
  89542. +
  89543. + return s->name;
  89544. +}
  89545. +#endif
  89546. +
  89547. size_t ksize(const void *object)
  89548. {
  89549. struct page *page;
  89550. @@ -3387,6 +3451,7 @@ void kfree(const void *x)
  89551. if (unlikely(ZERO_OR_NULL_PTR(x)))
  89552. return;
  89553. + VM_BUG_ON(!virt_addr_valid(x));
  89554. page = virt_to_head_page(x);
  89555. if (unlikely(!PageSlab(page))) {
  89556. BUG_ON(!PageCompound(page));
  89557. @@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
  89558. /*
  89559. * We may have set a slab to be unmergeable during bootstrap.
  89560. */
  89561. - if (s->refcount < 0)
  89562. + if (atomic_read(&s->refcount) < 0)
  89563. return 1;
  89564. return 0;
  89565. @@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
  89566. s = find_mergeable(memcg, size, align, flags, name, ctor);
  89567. if (s) {
  89568. - s->refcount++;
  89569. + atomic_inc(&s->refcount);
  89570. /*
  89571. * Adjust the object sizes so that we clear
  89572. * the complete object on kzalloc.
  89573. @@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
  89574. s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
  89575. if (sysfs_slab_alias(s, name)) {
  89576. - s->refcount--;
  89577. + atomic_dec(&s->refcount);
  89578. s = NULL;
  89579. }
  89580. }
  89581. @@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
  89582. }
  89583. #endif
  89584. -#ifdef CONFIG_SYSFS
  89585. +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
  89586. static int count_inuse(struct page *page)
  89587. {
  89588. return page->inuse;
  89589. @@ -4268,12 +4333,12 @@ static void resiliency_test(void)
  89590. validate_slab_cache(kmalloc_caches[9]);
  89591. }
  89592. #else
  89593. -#ifdef CONFIG_SYSFS
  89594. +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
  89595. static void resiliency_test(void) {};
  89596. #endif
  89597. #endif
  89598. -#ifdef CONFIG_SYSFS
  89599. +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
  89600. enum slab_stat_type {
  89601. SL_ALL, /* All slabs */
  89602. SL_PARTIAL, /* Only partially allocated slabs */
  89603. @@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
  89604. static ssize_t aliases_show(struct kmem_cache *s, char *buf)
  89605. {
  89606. - return sprintf(buf, "%d\n", s->refcount - 1);
  89607. + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
  89608. }
  89609. SLAB_ATTR_RO(aliases);
  89610. @@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
  89611. SLAB_ATTR_RO(cache_dma);
  89612. #endif
  89613. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89614. +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
  89615. +{
  89616. + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
  89617. +}
  89618. +SLAB_ATTR_RO(usercopy);
  89619. +#endif
  89620. +
  89621. static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
  89622. {
  89623. return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
  89624. @@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
  89625. #ifdef CONFIG_ZONE_DMA
  89626. &cache_dma_attr.attr,
  89627. #endif
  89628. +#ifdef CONFIG_PAX_USERCOPY_SLABS
  89629. + &usercopy_attr.attr,
  89630. +#endif
  89631. #ifdef CONFIG_NUMA
  89632. &remote_node_defrag_ratio_attr.attr,
  89633. #endif
  89634. @@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
  89635. return name;
  89636. }
  89637. +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
  89638. static int sysfs_slab_add(struct kmem_cache *s)
  89639. {
  89640. int err;
  89641. @@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
  89642. kobject_del(&s->kobj);
  89643. kobject_put(&s->kobj);
  89644. }
  89645. +#endif
  89646. /*
  89647. * Need to buffer aliases during bootup until sysfs becomes
  89648. @@ -5243,6 +5321,7 @@ struct saved_alias {
  89649. static struct saved_alias *alias_list;
  89650. +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
  89651. static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
  89652. {
  89653. struct saved_alias *al;
  89654. @@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
  89655. alias_list = al;
  89656. return 0;
  89657. }
  89658. +#endif
  89659. static int __init slab_sysfs_init(void)
  89660. {
  89661. diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
  89662. index 4cba9c2..b4f9fcc 100644
  89663. --- a/mm/sparse-vmemmap.c
  89664. +++ b/mm/sparse-vmemmap.c
  89665. @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
  89666. void *p = vmemmap_alloc_block(PAGE_SIZE, node);
  89667. if (!p)
  89668. return NULL;
  89669. - pud_populate(&init_mm, pud, p);
  89670. + pud_populate_kernel(&init_mm, pud, p);
  89671. }
  89672. return pud;
  89673. }
  89674. @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
  89675. void *p = vmemmap_alloc_block(PAGE_SIZE, node);
  89676. if (!p)
  89677. return NULL;
  89678. - pgd_populate(&init_mm, pgd, p);
  89679. + pgd_populate_kernel(&init_mm, pgd, p);
  89680. }
  89681. return pgd;
  89682. }
  89683. diff --git a/mm/sparse.c b/mm/sparse.c
  89684. index 63c3ea5..95c0858 100644
  89685. --- a/mm/sparse.c
  89686. +++ b/mm/sparse.c
  89687. @@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
  89688. for (i = 0; i < PAGES_PER_SECTION; i++) {
  89689. if (PageHWPoison(&memmap[i])) {
  89690. - atomic_long_sub(1, &num_poisoned_pages);
  89691. + atomic_long_sub_unchecked(1, &num_poisoned_pages);
  89692. ClearPageHWPoison(&memmap[i]);
  89693. }
  89694. }
  89695. diff --git a/mm/swap.c b/mm/swap.c
  89696. index 0092097..33361ff 100644
  89697. --- a/mm/swap.c
  89698. +++ b/mm/swap.c
  89699. @@ -31,6 +31,7 @@
  89700. #include <linux/memcontrol.h>
  89701. #include <linux/gfp.h>
  89702. #include <linux/uio.h>
  89703. +#include <linux/hugetlb.h>
  89704. #include "internal.h"
  89705. @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
  89706. __page_cache_release(page);
  89707. dtor = get_compound_page_dtor(page);
  89708. + if (!PageHuge(page))
  89709. + BUG_ON(dtor != free_compound_page);
  89710. (*dtor)(page);
  89711. }
  89712. diff --git a/mm/swapfile.c b/mm/swapfile.c
  89713. index 4a7f7e6..22cddf5 100644
  89714. --- a/mm/swapfile.c
  89715. +++ b/mm/swapfile.c
  89716. @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
  89717. static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
  89718. /* Activity counter to indicate that a swapon or swapoff has occurred */
  89719. -static atomic_t proc_poll_event = ATOMIC_INIT(0);
  89720. +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
  89721. static inline unsigned char swap_count(unsigned char ent)
  89722. {
  89723. @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
  89724. spin_unlock(&swap_lock);
  89725. err = 0;
  89726. - atomic_inc(&proc_poll_event);
  89727. + atomic_inc_unchecked(&proc_poll_event);
  89728. wake_up_interruptible(&proc_poll_wait);
  89729. out_dput:
  89730. @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
  89731. poll_wait(file, &proc_poll_wait, wait);
  89732. - if (seq->poll_event != atomic_read(&proc_poll_event)) {
  89733. - seq->poll_event = atomic_read(&proc_poll_event);
  89734. + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
  89735. + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
  89736. return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
  89737. }
  89738. @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
  89739. return ret;
  89740. seq = file->private_data;
  89741. - seq->poll_event = atomic_read(&proc_poll_event);
  89742. + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
  89743. return 0;
  89744. }
  89745. @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
  89746. (frontswap_map) ? "FS" : "");
  89747. mutex_unlock(&swapon_mutex);
  89748. - atomic_inc(&proc_poll_event);
  89749. + atomic_inc_unchecked(&proc_poll_event);
  89750. wake_up_interruptible(&proc_poll_wait);
  89751. if (S_ISREG(inode->i_mode))
  89752. diff --git a/mm/util.c b/mm/util.c
  89753. index a24aa22..a0d41ae 100644
  89754. --- a/mm/util.c
  89755. +++ b/mm/util.c
  89756. @@ -297,6 +297,12 @@ done:
  89757. void arch_pick_mmap_layout(struct mm_struct *mm)
  89758. {
  89759. mm->mmap_base = TASK_UNMAPPED_BASE;
  89760. +
  89761. +#ifdef CONFIG_PAX_RANDMMAP
  89762. + if (mm->pax_flags & MF_PAX_RANDMMAP)
  89763. + mm->mmap_base += mm->delta_mmap;
  89764. +#endif
  89765. +
  89766. mm->get_unmapped_area = arch_get_unmapped_area;
  89767. }
  89768. #endif
  89769. diff --git a/mm/vmalloc.c b/mm/vmalloc.c
  89770. index 0fdf968..d6686e8 100644
  89771. --- a/mm/vmalloc.c
  89772. +++ b/mm/vmalloc.c
  89773. @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
  89774. pte = pte_offset_kernel(pmd, addr);
  89775. do {
  89776. - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
  89777. - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
  89778. +
  89779. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  89780. + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
  89781. + BUG_ON(!pte_exec(*pte));
  89782. + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
  89783. + continue;
  89784. + }
  89785. +#endif
  89786. +
  89787. + {
  89788. + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
  89789. + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
  89790. + }
  89791. } while (pte++, addr += PAGE_SIZE, addr != end);
  89792. }
  89793. @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
  89794. pte = pte_alloc_kernel(pmd, addr);
  89795. if (!pte)
  89796. return -ENOMEM;
  89797. +
  89798. + pax_open_kernel();
  89799. do {
  89800. struct page *page = pages[*nr];
  89801. - if (WARN_ON(!pte_none(*pte)))
  89802. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  89803. + if (pgprot_val(prot) & _PAGE_NX)
  89804. +#endif
  89805. +
  89806. + if (!pte_none(*pte)) {
  89807. + pax_close_kernel();
  89808. + WARN_ON(1);
  89809. return -EBUSY;
  89810. - if (WARN_ON(!page))
  89811. + }
  89812. + if (!page) {
  89813. + pax_close_kernel();
  89814. + WARN_ON(1);
  89815. return -ENOMEM;
  89816. + }
  89817. set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
  89818. (*nr)++;
  89819. } while (pte++, addr += PAGE_SIZE, addr != end);
  89820. + pax_close_kernel();
  89821. return 0;
  89822. }
  89823. @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
  89824. pmd_t *pmd;
  89825. unsigned long next;
  89826. - pmd = pmd_alloc(&init_mm, pud, addr);
  89827. + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
  89828. if (!pmd)
  89829. return -ENOMEM;
  89830. do {
  89831. @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
  89832. pud_t *pud;
  89833. unsigned long next;
  89834. - pud = pud_alloc(&init_mm, pgd, addr);
  89835. + pud = pud_alloc_kernel(&init_mm, pgd, addr);
  89836. if (!pud)
  89837. return -ENOMEM;
  89838. do {
  89839. @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
  89840. if (addr >= MODULES_VADDR && addr < MODULES_END)
  89841. return 1;
  89842. #endif
  89843. +
  89844. +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
  89845. + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
  89846. + return 1;
  89847. +#endif
  89848. +
  89849. return is_vmalloc_addr(x);
  89850. }
  89851. @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
  89852. if (!pgd_none(*pgd)) {
  89853. pud_t *pud = pud_offset(pgd, addr);
  89854. +#ifdef CONFIG_X86
  89855. + if (!pud_large(*pud))
  89856. +#endif
  89857. if (!pud_none(*pud)) {
  89858. pmd_t *pmd = pmd_offset(pud, addr);
  89859. +#ifdef CONFIG_X86
  89860. + if (!pmd_large(*pmd))
  89861. +#endif
  89862. if (!pmd_none(*pmd)) {
  89863. pte_t *ptep, pte;
  89864. @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
  89865. struct vm_struct *area;
  89866. BUG_ON(in_interrupt());
  89867. +
  89868. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
  89869. + if (flags & VM_KERNEXEC) {
  89870. + if (start != VMALLOC_START || end != VMALLOC_END)
  89871. + return NULL;
  89872. + start = (unsigned long)MODULES_EXEC_VADDR;
  89873. + end = (unsigned long)MODULES_EXEC_END;
  89874. + }
  89875. +#endif
  89876. +
  89877. if (flags & VM_IOREMAP)
  89878. align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
  89879. @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
  89880. if (count > totalram_pages)
  89881. return NULL;
  89882. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
  89883. + if (!(pgprot_val(prot) & _PAGE_NX))
  89884. + flags |= VM_KERNEXEC;
  89885. +#endif
  89886. +
  89887. area = get_vm_area_caller((count << PAGE_SHIFT), flags,
  89888. __builtin_return_address(0));
  89889. if (!area)
  89890. @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
  89891. if (!size || (size >> PAGE_SHIFT) > totalram_pages)
  89892. goto fail;
  89893. +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
  89894. + if (!(pgprot_val(prot) & _PAGE_NX))
  89895. + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
  89896. + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
  89897. + else
  89898. +#endif
  89899. +
  89900. area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
  89901. start, end, node, gfp_mask, caller);
  89902. if (!area)
  89903. @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
  89904. * For tight control over page level allocator and protection flags
  89905. * use __vmalloc() instead.
  89906. */
  89907. -
  89908. void *vmalloc_exec(unsigned long size)
  89909. {
  89910. - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
  89911. + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
  89912. NUMA_NO_NODE, __builtin_return_address(0));
  89913. }
  89914. @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
  89915. {
  89916. struct vm_struct *area;
  89917. + BUG_ON(vma->vm_mirror);
  89918. +
  89919. size = PAGE_ALIGN(size);
  89920. if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
  89921. @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
  89922. v->addr, v->addr + v->size, v->size);
  89923. if (v->caller)
  89924. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  89925. + seq_printf(m, " %pK", v->caller);
  89926. +#else
  89927. seq_printf(m, " %pS", v->caller);
  89928. +#endif
  89929. if (v->nr_pages)
  89930. seq_printf(m, " pages=%d", v->nr_pages);
  89931. diff --git a/mm/vmstat.c b/mm/vmstat.c
  89932. index def5dd2..4ce55cec 100644
  89933. --- a/mm/vmstat.c
  89934. +++ b/mm/vmstat.c
  89935. @@ -20,6 +20,7 @@
  89936. #include <linux/writeback.h>
  89937. #include <linux/compaction.h>
  89938. #include <linux/mm_inline.h>
  89939. +#include <linux/grsecurity.h>
  89940. #include "internal.h"
  89941. @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
  89942. *
  89943. * vm_stat contains the global counters
  89944. */
  89945. -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
  89946. +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
  89947. EXPORT_SYMBOL(vm_stat);
  89948. #ifdef CONFIG_SMP
  89949. @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
  89950. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  89951. if (diff[i])
  89952. - atomic_long_add(diff[i], &vm_stat[i]);
  89953. + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
  89954. }
  89955. /*
  89956. @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
  89957. v = this_cpu_xchg(p->vm_stat_diff[i], 0);
  89958. if (v) {
  89959. - atomic_long_add(v, &zone->vm_stat[i]);
  89960. + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
  89961. global_diff[i] += v;
  89962. #ifdef CONFIG_NUMA
  89963. /* 3 seconds idle till flush */
  89964. @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
  89965. v = p->vm_stat_diff[i];
  89966. p->vm_stat_diff[i] = 0;
  89967. - atomic_long_add(v, &zone->vm_stat[i]);
  89968. + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
  89969. global_diff[i] += v;
  89970. }
  89971. }
  89972. @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
  89973. if (pset->vm_stat_diff[i]) {
  89974. int v = pset->vm_stat_diff[i];
  89975. pset->vm_stat_diff[i] = 0;
  89976. - atomic_long_add(v, &zone->vm_stat[i]);
  89977. - atomic_long_add(v, &vm_stat[i]);
  89978. + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
  89979. + atomic_long_add_unchecked(v, &vm_stat[i]);
  89980. }
  89981. }
  89982. #endif
  89983. @@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
  89984. stat_items_size += sizeof(struct vm_event_state);
  89985. #endif
  89986. - v = kmalloc(stat_items_size, GFP_KERNEL);
  89987. + v = kzalloc(stat_items_size, GFP_KERNEL);
  89988. m->private = v;
  89989. if (!v)
  89990. return ERR_PTR(-ENOMEM);
  89991. +
  89992. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  89993. +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
  89994. + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
  89995. +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
  89996. + && !in_group_p(grsec_proc_gid)
  89997. +#endif
  89998. + )
  89999. + return (unsigned long *)m->private + *pos;
  90000. +#endif
  90001. +#endif
  90002. +
  90003. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  90004. v[i] = global_page_state(i);
  90005. v += NR_VM_ZONE_STAT_ITEMS;
  90006. @@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
  90007. put_online_cpus();
  90008. #endif
  90009. #ifdef CONFIG_PROC_FS
  90010. - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
  90011. - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
  90012. - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  90013. - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
  90014. + {
  90015. + mode_t gr_mode = S_IRUGO;
  90016. +#ifdef CONFIG_GRKERNSEC_PROC_ADD
  90017. + gr_mode = S_IRUSR;
  90018. +#endif
  90019. + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
  90020. + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
  90021. + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  90022. + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
  90023. + }
  90024. #endif
  90025. return 0;
  90026. }
  90027. diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
  90028. index 175273f..1c63e05 100644
  90029. --- a/net/8021q/vlan.c
  90030. +++ b/net/8021q/vlan.c
  90031. @@ -474,7 +474,7 @@ out:
  90032. return NOTIFY_DONE;
  90033. }
  90034. -static struct notifier_block vlan_notifier_block __read_mostly = {
  90035. +static struct notifier_block vlan_notifier_block = {
  90036. .notifier_call = vlan_device_event,
  90037. };
  90038. @@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
  90039. err = -EPERM;
  90040. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  90041. break;
  90042. - if ((args.u.name_type >= 0) &&
  90043. - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
  90044. + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
  90045. struct vlan_net *vn;
  90046. vn = net_generic(net, vlan_net_id);
  90047. diff --git a/net/9p/client.c b/net/9p/client.c
  90048. index 9186550..e604a2f 100644
  90049. --- a/net/9p/client.c
  90050. +++ b/net/9p/client.c
  90051. @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
  90052. len - inline_len);
  90053. } else {
  90054. err = copy_from_user(ename + inline_len,
  90055. - uidata, len - inline_len);
  90056. + (char __force_user *)uidata, len - inline_len);
  90057. if (err) {
  90058. err = -EFAULT;
  90059. goto out_err;
  90060. @@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
  90061. kernel_buf = 1;
  90062. indata = data;
  90063. } else
  90064. - indata = (__force char *)udata;
  90065. + indata = (__force_kernel char *)udata;
  90066. /*
  90067. * response header len is 11
  90068. * PDU Header(7) + IO Size (4)
  90069. @@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
  90070. kernel_buf = 1;
  90071. odata = data;
  90072. } else
  90073. - odata = (char *)udata;
  90074. + odata = (char __force_kernel *)udata;
  90075. req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
  90076. P9_ZC_HDR_SZ, kernel_buf, "dqd",
  90077. fid->fid, offset, rsize);
  90078. diff --git a/net/9p/mod.c b/net/9p/mod.c
  90079. index 6ab36ae..6f1841b 100644
  90080. --- a/net/9p/mod.c
  90081. +++ b/net/9p/mod.c
  90082. @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
  90083. void v9fs_register_trans(struct p9_trans_module *m)
  90084. {
  90085. spin_lock(&v9fs_trans_lock);
  90086. - list_add_tail(&m->list, &v9fs_trans_list);
  90087. + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
  90088. spin_unlock(&v9fs_trans_lock);
  90089. }
  90090. EXPORT_SYMBOL(v9fs_register_trans);
  90091. @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
  90092. void v9fs_unregister_trans(struct p9_trans_module *m)
  90093. {
  90094. spin_lock(&v9fs_trans_lock);
  90095. - list_del_init(&m->list);
  90096. + pax_list_del_init((struct list_head *)&m->list);
  90097. spin_unlock(&v9fs_trans_lock);
  90098. }
  90099. EXPORT_SYMBOL(v9fs_unregister_trans);
  90100. diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
  90101. index b7bd7f2..2498bf7 100644
  90102. --- a/net/9p/trans_fd.c
  90103. +++ b/net/9p/trans_fd.c
  90104. @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
  90105. oldfs = get_fs();
  90106. set_fs(get_ds());
  90107. /* The cast to a user pointer is valid due to the set_fs() */
  90108. - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
  90109. + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
  90110. set_fs(oldfs);
  90111. if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
  90112. diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
  90113. index af46bc4..f9adfcd 100644
  90114. --- a/net/appletalk/atalk_proc.c
  90115. +++ b/net/appletalk/atalk_proc.c
  90116. @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
  90117. struct proc_dir_entry *p;
  90118. int rc = -ENOMEM;
  90119. - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
  90120. + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
  90121. if (!atalk_proc_dir)
  90122. goto out;
  90123. diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
  90124. index 876fbe8..8bbea9f 100644
  90125. --- a/net/atm/atm_misc.c
  90126. +++ b/net/atm/atm_misc.c
  90127. @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
  90128. if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
  90129. return 1;
  90130. atm_return(vcc, truesize);
  90131. - atomic_inc(&vcc->stats->rx_drop);
  90132. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  90133. return 0;
  90134. }
  90135. EXPORT_SYMBOL(atm_charge);
  90136. @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
  90137. }
  90138. }
  90139. atm_return(vcc, guess);
  90140. - atomic_inc(&vcc->stats->rx_drop);
  90141. + atomic_inc_unchecked(&vcc->stats->rx_drop);
  90142. return NULL;
  90143. }
  90144. EXPORT_SYMBOL(atm_alloc_charge);
  90145. @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
  90146. void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
  90147. {
  90148. -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
  90149. +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
  90150. __SONET_ITEMS
  90151. #undef __HANDLE_ITEM
  90152. }
  90153. @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
  90154. void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
  90155. {
  90156. -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
  90157. +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
  90158. __SONET_ITEMS
  90159. #undef __HANDLE_ITEM
  90160. }
  90161. diff --git a/net/atm/lec.c b/net/atm/lec.c
  90162. index 5a2f602..9396143 100644
  90163. --- a/net/atm/lec.c
  90164. +++ b/net/atm/lec.c
  90165. @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
  90166. }
  90167. static struct lane2_ops lane2_ops = {
  90168. - lane2_resolve, /* resolve, spec 3.1.3 */
  90169. - lane2_associate_req, /* associate_req, spec 3.1.4 */
  90170. - NULL /* associate indicator, spec 3.1.5 */
  90171. + .resolve = lane2_resolve,
  90172. + .associate_req = lane2_associate_req,
  90173. + .associate_indicator = NULL
  90174. };
  90175. static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  90176. diff --git a/net/atm/lec.h b/net/atm/lec.h
  90177. index 4149db1..f2ab682 100644
  90178. --- a/net/atm/lec.h
  90179. +++ b/net/atm/lec.h
  90180. @@ -48,7 +48,7 @@ struct lane2_ops {
  90181. const u8 *tlvs, u32 sizeoftlvs);
  90182. void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
  90183. const u8 *tlvs, u32 sizeoftlvs);
  90184. -};
  90185. +} __no_const;
  90186. /*
  90187. * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
  90188. diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
  90189. index d1b2d9a..d549f7f 100644
  90190. --- a/net/atm/mpoa_caches.c
  90191. +++ b/net/atm/mpoa_caches.c
  90192. @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
  90193. static struct in_cache_ops ingress_ops = {
  90194. - in_cache_add_entry, /* add_entry */
  90195. - in_cache_get, /* get */
  90196. - in_cache_get_with_mask, /* get_with_mask */
  90197. - in_cache_get_by_vcc, /* get_by_vcc */
  90198. - in_cache_put, /* put */
  90199. - in_cache_remove_entry, /* remove_entry */
  90200. - cache_hit, /* cache_hit */
  90201. - clear_count_and_expired, /* clear_count */
  90202. - check_resolving_entries, /* check_resolving */
  90203. - refresh_entries, /* refresh */
  90204. - in_destroy_cache /* destroy_cache */
  90205. + .add_entry = in_cache_add_entry,
  90206. + .get = in_cache_get,
  90207. + .get_with_mask = in_cache_get_with_mask,
  90208. + .get_by_vcc = in_cache_get_by_vcc,
  90209. + .put = in_cache_put,
  90210. + .remove_entry = in_cache_remove_entry,
  90211. + .cache_hit = cache_hit,
  90212. + .clear_count = clear_count_and_expired,
  90213. + .check_resolving = check_resolving_entries,
  90214. + .refresh = refresh_entries,
  90215. + .destroy_cache = in_destroy_cache
  90216. };
  90217. static struct eg_cache_ops egress_ops = {
  90218. - eg_cache_add_entry, /* add_entry */
  90219. - eg_cache_get_by_cache_id, /* get_by_cache_id */
  90220. - eg_cache_get_by_tag, /* get_by_tag */
  90221. - eg_cache_get_by_vcc, /* get_by_vcc */
  90222. - eg_cache_get_by_src_ip, /* get_by_src_ip */
  90223. - eg_cache_put, /* put */
  90224. - eg_cache_remove_entry, /* remove_entry */
  90225. - update_eg_cache_entry, /* update */
  90226. - clear_expired, /* clear_expired */
  90227. - eg_destroy_cache /* destroy_cache */
  90228. + .add_entry = eg_cache_add_entry,
  90229. + .get_by_cache_id = eg_cache_get_by_cache_id,
  90230. + .get_by_tag = eg_cache_get_by_tag,
  90231. + .get_by_vcc = eg_cache_get_by_vcc,
  90232. + .get_by_src_ip = eg_cache_get_by_src_ip,
  90233. + .put = eg_cache_put,
  90234. + .remove_entry = eg_cache_remove_entry,
  90235. + .update = update_eg_cache_entry,
  90236. + .clear_expired = clear_expired,
  90237. + .destroy_cache = eg_destroy_cache
  90238. };
  90239. diff --git a/net/atm/proc.c b/net/atm/proc.c
  90240. index bbb6461..cf04016 100644
  90241. --- a/net/atm/proc.c
  90242. +++ b/net/atm/proc.c
  90243. @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
  90244. const struct k_atm_aal_stats *stats)
  90245. {
  90246. seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
  90247. - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
  90248. - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
  90249. - atomic_read(&stats->rx_drop));
  90250. + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
  90251. + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
  90252. + atomic_read_unchecked(&stats->rx_drop));
  90253. }
  90254. static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
  90255. diff --git a/net/atm/resources.c b/net/atm/resources.c
  90256. index 0447d5d..3cf4728 100644
  90257. --- a/net/atm/resources.c
  90258. +++ b/net/atm/resources.c
  90259. @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
  90260. static void copy_aal_stats(struct k_atm_aal_stats *from,
  90261. struct atm_aal_stats *to)
  90262. {
  90263. -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
  90264. +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
  90265. __AAL_STAT_ITEMS
  90266. #undef __HANDLE_ITEM
  90267. }
  90268. @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
  90269. static void subtract_aal_stats(struct k_atm_aal_stats *from,
  90270. struct atm_aal_stats *to)
  90271. {
  90272. -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
  90273. +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
  90274. __AAL_STAT_ITEMS
  90275. #undef __HANDLE_ITEM
  90276. }
  90277. diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
  90278. index 919a5ce..cc6b444 100644
  90279. --- a/net/ax25/sysctl_net_ax25.c
  90280. +++ b/net/ax25/sysctl_net_ax25.c
  90281. @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
  90282. {
  90283. char path[sizeof("net/ax25/") + IFNAMSIZ];
  90284. int k;
  90285. - struct ctl_table *table;
  90286. + ctl_table_no_const *table;
  90287. table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
  90288. if (!table)
  90289. diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
  90290. index 8323bce..a03130d 100644
  90291. --- a/net/batman-adv/bat_iv_ogm.c
  90292. +++ b/net/batman-adv/bat_iv_ogm.c
  90293. @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
  90294. /* randomize initial seqno to avoid collision */
  90295. get_random_bytes(&random_seqno, sizeof(random_seqno));
  90296. - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
  90297. + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
  90298. hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
  90299. ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
  90300. @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
  90301. batadv_ogm_packet->tvlv_len = htons(tvlv_len);
  90302. /* change sequence number to network order */
  90303. - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
  90304. + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
  90305. batadv_ogm_packet->seqno = htonl(seqno);
  90306. - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
  90307. + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
  90308. batadv_iv_ogm_slide_own_bcast_window(hard_iface);
  90309. @@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
  90310. return;
  90311. /* could be changed by schedule_own_packet() */
  90312. - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
  90313. + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
  90314. if (ogm_packet->flags & BATADV_DIRECTLINK)
  90315. has_directlink_flag = true;
  90316. diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
  90317. index 88df9b1..69cf7c0 100644
  90318. --- a/net/batman-adv/fragmentation.c
  90319. +++ b/net/batman-adv/fragmentation.c
  90320. @@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
  90321. frag_header.packet_type = BATADV_UNICAST_FRAG;
  90322. frag_header.version = BATADV_COMPAT_VERSION;
  90323. frag_header.ttl = BATADV_TTL;
  90324. - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
  90325. + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
  90326. frag_header.reserved = 0;
  90327. frag_header.no = 0;
  90328. frag_header.total_size = htons(skb->len);
  90329. diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
  90330. index f82c267..0e56d32 100644
  90331. --- a/net/batman-adv/soft-interface.c
  90332. +++ b/net/batman-adv/soft-interface.c
  90333. @@ -283,7 +283,7 @@ send:
  90334. primary_if->net_dev->dev_addr, ETH_ALEN);
  90335. /* set broadcast sequence number */
  90336. - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
  90337. + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
  90338. bcast_packet->seqno = htonl(seqno);
  90339. batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
  90340. @@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
  90341. atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
  90342. atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
  90343. - atomic_set(&bat_priv->bcast_seqno, 1);
  90344. + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
  90345. atomic_set(&bat_priv->tt.vn, 0);
  90346. atomic_set(&bat_priv->tt.local_changes, 0);
  90347. atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
  90348. @@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
  90349. /* randomize initial seqno to avoid collision */
  90350. get_random_bytes(&random_seqno, sizeof(random_seqno));
  90351. - atomic_set(&bat_priv->frag_seqno, random_seqno);
  90352. + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
  90353. bat_priv->primary_if = NULL;
  90354. bat_priv->num_ifaces = 0;
  90355. diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
  90356. index 78370ab..1cb3614 100644
  90357. --- a/net/batman-adv/types.h
  90358. +++ b/net/batman-adv/types.h
  90359. @@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
  90360. struct batadv_hard_iface_bat_iv {
  90361. unsigned char *ogm_buff;
  90362. int ogm_buff_len;
  90363. - atomic_t ogm_seqno;
  90364. + atomic_unchecked_t ogm_seqno;
  90365. };
  90366. /**
  90367. @@ -714,7 +714,7 @@ struct batadv_priv {
  90368. atomic_t bonding;
  90369. atomic_t fragmentation;
  90370. atomic_t packet_size_max;
  90371. - atomic_t frag_seqno;
  90372. + atomic_unchecked_t frag_seqno;
  90373. #ifdef CONFIG_BATMAN_ADV_BLA
  90374. atomic_t bridge_loop_avoidance;
  90375. #endif
  90376. @@ -730,7 +730,7 @@ struct batadv_priv {
  90377. #endif
  90378. uint32_t isolation_mark;
  90379. uint32_t isolation_mark_mask;
  90380. - atomic_t bcast_seqno;
  90381. + atomic_unchecked_t bcast_seqno;
  90382. atomic_t bcast_queue_left;
  90383. atomic_t batman_queue_left;
  90384. char num_ifaces;
  90385. diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
  90386. index 7552f9e..074ce29 100644
  90387. --- a/net/bluetooth/hci_sock.c
  90388. +++ b/net/bluetooth/hci_sock.c
  90389. @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
  90390. uf.event_mask[1] = *((u32 *) f->event_mask + 1);
  90391. }
  90392. - len = min_t(unsigned int, len, sizeof(uf));
  90393. + len = min((size_t)len, sizeof(uf));
  90394. if (copy_from_user(&uf, optval, len)) {
  90395. err = -EFAULT;
  90396. break;
  90397. diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
  90398. index b0ad2c7..96f6a5e 100644
  90399. --- a/net/bluetooth/l2cap_core.c
  90400. +++ b/net/bluetooth/l2cap_core.c
  90401. @@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
  90402. break;
  90403. case L2CAP_CONF_RFC:
  90404. - if (olen == sizeof(rfc))
  90405. - memcpy(&rfc, (void *)val, olen);
  90406. + if (olen != sizeof(rfc))
  90407. + break;
  90408. +
  90409. + memcpy(&rfc, (void *)val, olen);
  90410. if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
  90411. rfc.mode != chan->mode)
  90412. diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
  90413. index d58f76b..b69600a 100644
  90414. --- a/net/bluetooth/l2cap_sock.c
  90415. +++ b/net/bluetooth/l2cap_sock.c
  90416. @@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
  90417. struct sock *sk = sock->sk;
  90418. struct l2cap_chan *chan = l2cap_pi(sk)->chan;
  90419. struct l2cap_options opts;
  90420. - int len, err = 0;
  90421. + int err = 0;
  90422. + size_t len = optlen;
  90423. u32 opt;
  90424. BT_DBG("sk %p", sk);
  90425. @@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
  90426. opts.max_tx = chan->max_tx;
  90427. opts.txwin_size = chan->tx_win;
  90428. - len = min_t(unsigned int, sizeof(opts), optlen);
  90429. + len = min(sizeof(opts), len);
  90430. if (copy_from_user((char *) &opts, optval, len)) {
  90431. err = -EFAULT;
  90432. break;
  90433. @@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
  90434. struct bt_security sec;
  90435. struct bt_power pwr;
  90436. struct l2cap_conn *conn;
  90437. - int len, err = 0;
  90438. + int err = 0;
  90439. + size_t len = optlen;
  90440. u32 opt;
  90441. BT_DBG("sk %p", sk);
  90442. @@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
  90443. sec.level = BT_SECURITY_LOW;
  90444. - len = min_t(unsigned int, sizeof(sec), optlen);
  90445. + len = min(sizeof(sec), len);
  90446. if (copy_from_user((char *) &sec, optval, len)) {
  90447. err = -EFAULT;
  90448. break;
  90449. @@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
  90450. pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
  90451. - len = min_t(unsigned int, sizeof(pwr), optlen);
  90452. + len = min(sizeof(pwr), len);
  90453. if (copy_from_user((char *) &pwr, optval, len)) {
  90454. err = -EFAULT;
  90455. break;
  90456. diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
  90457. index 3c2d3e4..884855a 100644
  90458. --- a/net/bluetooth/rfcomm/sock.c
  90459. +++ b/net/bluetooth/rfcomm/sock.c
  90460. @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
  90461. struct sock *sk = sock->sk;
  90462. struct bt_security sec;
  90463. int err = 0;
  90464. - size_t len;
  90465. + size_t len = optlen;
  90466. u32 opt;
  90467. BT_DBG("sk %p", sk);
  90468. @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
  90469. sec.level = BT_SECURITY_LOW;
  90470. - len = min_t(unsigned int, sizeof(sec), optlen);
  90471. + len = min(sizeof(sec), len);
  90472. if (copy_from_user((char *) &sec, optval, len)) {
  90473. err = -EFAULT;
  90474. break;
  90475. diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
  90476. index f9c0980a..fcbbfeb 100644
  90477. --- a/net/bluetooth/rfcomm/tty.c
  90478. +++ b/net/bluetooth/rfcomm/tty.c
  90479. @@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
  90480. BT_DBG("tty %p id %d", tty, tty->index);
  90481. BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
  90482. - dev->channel, dev->port.count);
  90483. + dev->channel, atomic_read(&dev->port.count));
  90484. err = tty_port_open(&dev->port, tty, filp);
  90485. if (err)
  90486. @@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
  90487. struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
  90488. BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
  90489. - dev->port.count);
  90490. + atomic_read(&dev->port.count));
  90491. tty_port_close(&dev->port, tty, filp);
  90492. }
  90493. diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
  90494. index 0e474b1..fb7109c 100644
  90495. --- a/net/bridge/netfilter/ebtables.c
  90496. +++ b/net/bridge/netfilter/ebtables.c
  90497. @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
  90498. tmp.valid_hooks = t->table->valid_hooks;
  90499. }
  90500. mutex_unlock(&ebt_mutex);
  90501. - if (copy_to_user(user, &tmp, *len) != 0) {
  90502. + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
  90503. BUGPRINT("c2u Didn't work\n");
  90504. ret = -EFAULT;
  90505. break;
  90506. @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
  90507. goto out;
  90508. tmp.valid_hooks = t->valid_hooks;
  90509. - if (copy_to_user(user, &tmp, *len) != 0) {
  90510. + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
  90511. ret = -EFAULT;
  90512. break;
  90513. }
  90514. @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
  90515. tmp.entries_size = t->table->entries_size;
  90516. tmp.valid_hooks = t->table->valid_hooks;
  90517. - if (copy_to_user(user, &tmp, *len) != 0) {
  90518. + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
  90519. ret = -EFAULT;
  90520. break;
  90521. }
  90522. diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
  90523. index 0f45522..dab651f 100644
  90524. --- a/net/caif/cfctrl.c
  90525. +++ b/net/caif/cfctrl.c
  90526. @@ -10,6 +10,7 @@
  90527. #include <linux/spinlock.h>
  90528. #include <linux/slab.h>
  90529. #include <linux/pkt_sched.h>
  90530. +#include <linux/sched.h>
  90531. #include <net/caif/caif_layer.h>
  90532. #include <net/caif/cfpkt.h>
  90533. #include <net/caif/cfctrl.h>
  90534. @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
  90535. memset(&dev_info, 0, sizeof(dev_info));
  90536. dev_info.id = 0xff;
  90537. cfsrvl_init(&this->serv, 0, &dev_info, false);
  90538. - atomic_set(&this->req_seq_no, 1);
  90539. - atomic_set(&this->rsp_seq_no, 1);
  90540. + atomic_set_unchecked(&this->req_seq_no, 1);
  90541. + atomic_set_unchecked(&this->rsp_seq_no, 1);
  90542. this->serv.layer.receive = cfctrl_recv;
  90543. sprintf(this->serv.layer.name, "ctrl");
  90544. this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
  90545. @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
  90546. struct cfctrl_request_info *req)
  90547. {
  90548. spin_lock_bh(&ctrl->info_list_lock);
  90549. - atomic_inc(&ctrl->req_seq_no);
  90550. - req->sequence_no = atomic_read(&ctrl->req_seq_no);
  90551. + atomic_inc_unchecked(&ctrl->req_seq_no);
  90552. + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
  90553. list_add_tail(&req->list, &ctrl->list);
  90554. spin_unlock_bh(&ctrl->info_list_lock);
  90555. }
  90556. @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
  90557. if (p != first)
  90558. pr_warn("Requests are not received in order\n");
  90559. - atomic_set(&ctrl->rsp_seq_no,
  90560. + atomic_set_unchecked(&ctrl->rsp_seq_no,
  90561. p->sequence_no);
  90562. list_del(&p->list);
  90563. goto out;
  90564. diff --git a/net/can/af_can.c b/net/can/af_can.c
  90565. index a27f8aa..67174a3 100644
  90566. --- a/net/can/af_can.c
  90567. +++ b/net/can/af_can.c
  90568. @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
  90569. };
  90570. /* notifier block for netdevice event */
  90571. -static struct notifier_block can_netdev_notifier __read_mostly = {
  90572. +static struct notifier_block can_netdev_notifier = {
  90573. .notifier_call = can_notifier,
  90574. };
  90575. diff --git a/net/can/bcm.c b/net/can/bcm.c
  90576. index dcb75c0..24b1b43 100644
  90577. --- a/net/can/bcm.c
  90578. +++ b/net/can/bcm.c
  90579. @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
  90580. }
  90581. /* create /proc/net/can-bcm directory */
  90582. - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
  90583. + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
  90584. return 0;
  90585. }
  90586. diff --git a/net/can/gw.c b/net/can/gw.c
  90587. index ac31891..4799c17 100644
  90588. --- a/net/can/gw.c
  90589. +++ b/net/can/gw.c
  90590. @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
  90591. "default: " __stringify(CGW_DEFAULT_HOPS) ")");
  90592. static HLIST_HEAD(cgw_list);
  90593. -static struct notifier_block notifier;
  90594. static struct kmem_cache *cgw_cache __read_mostly;
  90595. @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
  90596. return err;
  90597. }
  90598. +static struct notifier_block notifier = {
  90599. + .notifier_call = cgw_notifier
  90600. +};
  90601. +
  90602. static __init int cgw_module_init(void)
  90603. {
  90604. /* sanitize given module parameter */
  90605. @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
  90606. return -ENOMEM;
  90607. /* set notifier */
  90608. - notifier.notifier_call = cgw_notifier;
  90609. register_netdevice_notifier(&notifier);
  90610. if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
  90611. diff --git a/net/can/proc.c b/net/can/proc.c
  90612. index b543470..d2ddae2 100644
  90613. --- a/net/can/proc.c
  90614. +++ b/net/can/proc.c
  90615. @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
  90616. void can_init_proc(void)
  90617. {
  90618. /* create /proc/net/can directory */
  90619. - can_dir = proc_mkdir("can", init_net.proc_net);
  90620. + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
  90621. if (!can_dir) {
  90622. printk(KERN_INFO "can: failed to create /proc/net/can . "
  90623. diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
  90624. index 30efc5c..cfa1bbc 100644
  90625. --- a/net/ceph/messenger.c
  90626. +++ b/net/ceph/messenger.c
  90627. @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
  90628. #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
  90629. static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
  90630. -static atomic_t addr_str_seq = ATOMIC_INIT(0);
  90631. +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
  90632. static struct page *zero_page; /* used in certain error cases */
  90633. @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
  90634. struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
  90635. struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
  90636. - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
  90637. + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
  90638. s = addr_str[i];
  90639. switch (ss->ss_family) {
  90640. diff --git a/net/compat.c b/net/compat.c
  90641. index f50161f..94fa415 100644
  90642. --- a/net/compat.c
  90643. +++ b/net/compat.c
  90644. @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
  90645. return -EFAULT;
  90646. if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
  90647. kmsg->msg_namelen = sizeof(struct sockaddr_storage);
  90648. - kmsg->msg_name = compat_ptr(tmp1);
  90649. - kmsg->msg_iov = compat_ptr(tmp2);
  90650. - kmsg->msg_control = compat_ptr(tmp3);
  90651. + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
  90652. + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
  90653. + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
  90654. return 0;
  90655. }
  90656. @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
  90657. if (kern_msg->msg_namelen) {
  90658. if (mode == VERIFY_READ) {
  90659. - int err = move_addr_to_kernel(kern_msg->msg_name,
  90660. + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
  90661. kern_msg->msg_namelen,
  90662. kern_address);
  90663. if (err < 0)
  90664. @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
  90665. kern_msg->msg_name = NULL;
  90666. tot_len = iov_from_user_compat_to_kern(kern_iov,
  90667. - (struct compat_iovec __user *)kern_msg->msg_iov,
  90668. + (struct compat_iovec __force_user *)kern_msg->msg_iov,
  90669. kern_msg->msg_iovlen);
  90670. if (tot_len >= 0)
  90671. kern_msg->msg_iov = kern_iov;
  90672. @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
  90673. #define CMSG_COMPAT_FIRSTHDR(msg) \
  90674. (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
  90675. - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
  90676. + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
  90677. (struct compat_cmsghdr __user *)NULL)
  90678. #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
  90679. ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
  90680. (ucmlen) <= (unsigned long) \
  90681. ((mhdr)->msg_controllen - \
  90682. - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
  90683. + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
  90684. static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
  90685. struct compat_cmsghdr __user *cmsg, int cmsg_len)
  90686. {
  90687. char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
  90688. - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
  90689. + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
  90690. msg->msg_controllen)
  90691. return NULL;
  90692. return (struct compat_cmsghdr __user *)ptr;
  90693. @@ -222,7 +222,7 @@ Efault:
  90694. int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
  90695. {
  90696. - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
  90697. + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
  90698. struct compat_cmsghdr cmhdr;
  90699. struct compat_timeval ctv;
  90700. struct compat_timespec cts[3];
  90701. @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
  90702. void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
  90703. {
  90704. - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
  90705. + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
  90706. int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
  90707. int fdnum = scm->fp->count;
  90708. struct file **fp = scm->fp->fp;
  90709. @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
  90710. return -EFAULT;
  90711. old_fs = get_fs();
  90712. set_fs(KERNEL_DS);
  90713. - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
  90714. + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
  90715. set_fs(old_fs);
  90716. return err;
  90717. @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
  90718. len = sizeof(ktime);
  90719. old_fs = get_fs();
  90720. set_fs(KERNEL_DS);
  90721. - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
  90722. + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
  90723. set_fs(old_fs);
  90724. if (!err) {
  90725. @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
  90726. case MCAST_JOIN_GROUP:
  90727. case MCAST_LEAVE_GROUP:
  90728. {
  90729. - struct compat_group_req __user *gr32 = (void *)optval;
  90730. + struct compat_group_req __user *gr32 = (void __user *)optval;
  90731. struct group_req __user *kgr =
  90732. compat_alloc_user_space(sizeof(struct group_req));
  90733. u32 interface;
  90734. @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
  90735. case MCAST_BLOCK_SOURCE:
  90736. case MCAST_UNBLOCK_SOURCE:
  90737. {
  90738. - struct compat_group_source_req __user *gsr32 = (void *)optval;
  90739. + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
  90740. struct group_source_req __user *kgsr = compat_alloc_user_space(
  90741. sizeof(struct group_source_req));
  90742. u32 interface;
  90743. @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
  90744. }
  90745. case MCAST_MSFILTER:
  90746. {
  90747. - struct compat_group_filter __user *gf32 = (void *)optval;
  90748. + struct compat_group_filter __user *gf32 = (void __user *)optval;
  90749. struct group_filter __user *kgf;
  90750. u32 interface, fmode, numsrc;
  90751. @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
  90752. char __user *optval, int __user *optlen,
  90753. int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
  90754. {
  90755. - struct compat_group_filter __user *gf32 = (void *)optval;
  90756. + struct compat_group_filter __user *gf32 = (void __user *)optval;
  90757. struct group_filter __user *kgf;
  90758. int __user *koptlen;
  90759. u32 interface, fmode, numsrc;
  90760. @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
  90761. if (call < SYS_SOCKET || call > SYS_SENDMMSG)
  90762. return -EINVAL;
  90763. - if (copy_from_user(a, args, nas[call]))
  90764. + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
  90765. return -EFAULT;
  90766. a0 = a[0];
  90767. a1 = a[1];
  90768. diff --git a/net/core/datagram.c b/net/core/datagram.c
  90769. index a16ed7b..eb44d17 100644
  90770. --- a/net/core/datagram.c
  90771. +++ b/net/core/datagram.c
  90772. @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
  90773. }
  90774. kfree_skb(skb);
  90775. - atomic_inc(&sk->sk_drops);
  90776. + atomic_inc_unchecked(&sk->sk_drops);
  90777. sk_mem_reclaim_partial(sk);
  90778. return err;
  90779. diff --git a/net/core/dev.c b/net/core/dev.c
  90780. index 45fa2f1..f3e28ec 100644
  90781. --- a/net/core/dev.c
  90782. +++ b/net/core/dev.c
  90783. @@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
  90784. {
  90785. if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
  90786. if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
  90787. - atomic_long_inc(&dev->rx_dropped);
  90788. + atomic_long_inc_unchecked(&dev->rx_dropped);
  90789. kfree_skb(skb);
  90790. return NET_RX_DROP;
  90791. }
  90792. }
  90793. if (unlikely(!is_skb_forwardable(dev, skb))) {
  90794. - atomic_long_inc(&dev->rx_dropped);
  90795. + atomic_long_inc_unchecked(&dev->rx_dropped);
  90796. kfree_skb(skb);
  90797. return NET_RX_DROP;
  90798. }
  90799. @@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
  90800. struct dev_gso_cb {
  90801. void (*destructor)(struct sk_buff *skb);
  90802. -};
  90803. +} __no_const;
  90804. #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
  90805. @@ -3227,7 +3227,7 @@ enqueue:
  90806. local_irq_restore(flags);
  90807. - atomic_long_inc(&skb->dev->rx_dropped);
  90808. + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
  90809. kfree_skb(skb);
  90810. return NET_RX_DROP;
  90811. }
  90812. @@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
  90813. }
  90814. EXPORT_SYMBOL(netif_rx_ni);
  90815. -static void net_tx_action(struct softirq_action *h)
  90816. +static __latent_entropy void net_tx_action(void)
  90817. {
  90818. struct softnet_data *sd = &__get_cpu_var(softnet_data);
  90819. @@ -3645,7 +3645,7 @@ ncls:
  90820. ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
  90821. } else {
  90822. drop:
  90823. - atomic_long_inc(&skb->dev->rx_dropped);
  90824. + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
  90825. kfree_skb(skb);
  90826. /* Jamal, now you will not able to escape explaining
  90827. * me how you were going to use this. :-)
  90828. @@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
  90829. }
  90830. EXPORT_SYMBOL(netif_napi_del);
  90831. -static void net_rx_action(struct softirq_action *h)
  90832. +static __latent_entropy void net_rx_action(void)
  90833. {
  90834. struct softnet_data *sd = &__get_cpu_var(softnet_data);
  90835. unsigned long time_limit = jiffies + 2;
  90836. @@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
  90837. } else {
  90838. netdev_stats_to_stats64(storage, &dev->stats);
  90839. }
  90840. - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
  90841. + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
  90842. return storage;
  90843. }
  90844. EXPORT_SYMBOL(dev_get_stats);
  90845. diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
  90846. index cf999e0..c59a975 100644
  90847. --- a/net/core/dev_ioctl.c
  90848. +++ b/net/core/dev_ioctl.c
  90849. @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
  90850. if (no_module && capable(CAP_NET_ADMIN))
  90851. no_module = request_module("netdev-%s", name);
  90852. if (no_module && capable(CAP_SYS_MODULE)) {
  90853. +#ifdef CONFIG_GRKERNSEC_MODHARDEN
  90854. + ___request_module(true, "grsec_modharden_netdev", "%s", name);
  90855. +#else
  90856. if (!request_module("%s", name))
  90857. pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
  90858. name);
  90859. +#endif
  90860. }
  90861. }
  90862. EXPORT_SYMBOL(dev_load);
  90863. diff --git a/net/core/filter.c b/net/core/filter.c
  90864. index ad30d62..21c0743 100644
  90865. --- a/net/core/filter.c
  90866. +++ b/net/core/filter.c
  90867. @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
  90868. void *ptr;
  90869. u32 A = 0; /* Accumulator */
  90870. u32 X = 0; /* Index Register */
  90871. - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
  90872. + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
  90873. u32 tmp;
  90874. int k;
  90875. @@ -292,10 +292,10 @@ load_b:
  90876. X = K;
  90877. continue;
  90878. case BPF_S_LD_MEM:
  90879. - A = mem[K];
  90880. + A = mem[K&15];
  90881. continue;
  90882. case BPF_S_LDX_MEM:
  90883. - X = mem[K];
  90884. + X = mem[K&15];
  90885. continue;
  90886. case BPF_S_MISC_TAX:
  90887. X = A;
  90888. @@ -308,10 +308,10 @@ load_b:
  90889. case BPF_S_RET_A:
  90890. return A;
  90891. case BPF_S_ST:
  90892. - mem[K] = A;
  90893. + mem[K&15] = A;
  90894. continue;
  90895. case BPF_S_STX:
  90896. - mem[K] = X;
  90897. + mem[K&15] = X;
  90898. continue;
  90899. case BPF_S_ANC_PROTOCOL:
  90900. A = ntohs(skb->protocol);
  90901. @@ -355,6 +355,10 @@ load_b:
  90902. if (skb_is_nonlinear(skb))
  90903. return 0;
  90904. +
  90905. + if (skb->len < sizeof(struct nlattr))
  90906. + return 0;
  90907. +
  90908. if (A > skb->len - sizeof(struct nlattr))
  90909. return 0;
  90910. @@ -371,11 +375,15 @@ load_b:
  90911. if (skb_is_nonlinear(skb))
  90912. return 0;
  90913. +
  90914. + if (skb->len < sizeof(struct nlattr))
  90915. + return 0;
  90916. +
  90917. if (A > skb->len - sizeof(struct nlattr))
  90918. return 0;
  90919. nla = (struct nlattr *)&skb->data[A];
  90920. - if (nla->nla_len > A - skb->len)
  90921. + if (nla->nla_len > skb->len - A)
  90922. return 0;
  90923. nla = nla_find_nested(nla, X);
  90924. @@ -391,9 +399,10 @@ load_b:
  90925. continue;
  90926. #endif
  90927. default:
  90928. - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
  90929. + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
  90930. fentry->code, fentry->jt,
  90931. fentry->jf, fentry->k);
  90932. + BUG();
  90933. return 0;
  90934. }
  90935. }
  90936. @@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
  90937. u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
  90938. int pc, ret = 0;
  90939. - BUILD_BUG_ON(BPF_MEMWORDS > 16);
  90940. + BUILD_BUG_ON(BPF_MEMWORDS != 16);
  90941. masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
  90942. if (!masks)
  90943. return -ENOMEM;
  90944. @@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
  90945. fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
  90946. if (!fp)
  90947. return -ENOMEM;
  90948. - memcpy(fp->insns, fprog->filter, fsize);
  90949. + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
  90950. atomic_set(&fp->refcnt, 1);
  90951. fp->len = fprog->len;
  90952. diff --git a/net/core/flow.c b/net/core/flow.c
  90953. index dfa602c..3103d88 100644
  90954. --- a/net/core/flow.c
  90955. +++ b/net/core/flow.c
  90956. @@ -61,7 +61,7 @@ struct flow_cache {
  90957. struct timer_list rnd_timer;
  90958. };
  90959. -atomic_t flow_cache_genid = ATOMIC_INIT(0);
  90960. +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
  90961. EXPORT_SYMBOL(flow_cache_genid);
  90962. static struct flow_cache flow_cache_global;
  90963. static struct kmem_cache *flow_cachep __read_mostly;
  90964. @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
  90965. static int flow_entry_valid(struct flow_cache_entry *fle)
  90966. {
  90967. - if (atomic_read(&flow_cache_genid) != fle->genid)
  90968. + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
  90969. return 0;
  90970. if (fle->object && !fle->object->ops->check(fle->object))
  90971. return 0;
  90972. @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
  90973. hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
  90974. fcp->hash_count++;
  90975. }
  90976. - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
  90977. + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
  90978. flo = fle->object;
  90979. if (!flo)
  90980. goto ret_object;
  90981. @@ -279,7 +279,7 @@ nocache:
  90982. }
  90983. flo = resolver(net, key, family, dir, flo, ctx);
  90984. if (fle) {
  90985. - fle->genid = atomic_read(&flow_cache_genid);
  90986. + fle->genid = atomic_read_unchecked(&flow_cache_genid);
  90987. if (!IS_ERR(flo))
  90988. fle->object = flo;
  90989. else
  90990. diff --git a/net/core/iovec.c b/net/core/iovec.c
  90991. index b618694..192bbba 100644
  90992. --- a/net/core/iovec.c
  90993. +++ b/net/core/iovec.c
  90994. @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
  90995. if (m->msg_namelen) {
  90996. if (mode == VERIFY_READ) {
  90997. void __user *namep;
  90998. - namep = (void __user __force *) m->msg_name;
  90999. + namep = (void __force_user *) m->msg_name;
  91000. err = move_addr_to_kernel(namep, m->msg_namelen,
  91001. address);
  91002. if (err < 0)
  91003. @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
  91004. }
  91005. size = m->msg_iovlen * sizeof(struct iovec);
  91006. - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
  91007. + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
  91008. return -EFAULT;
  91009. m->msg_iov = iov;
  91010. diff --git a/net/core/neighbour.c b/net/core/neighbour.c
  91011. index e161290..8149aea 100644
  91012. --- a/net/core/neighbour.c
  91013. +++ b/net/core/neighbour.c
  91014. @@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
  91015. void __user *buffer, size_t *lenp, loff_t *ppos)
  91016. {
  91017. int size, ret;
  91018. - struct ctl_table tmp = *ctl;
  91019. + ctl_table_no_const tmp = *ctl;
  91020. tmp.extra1 = &zero;
  91021. tmp.extra2 = &unres_qlen_max;
  91022. @@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
  91023. void __user *buffer,
  91024. size_t *lenp, loff_t *ppos)
  91025. {
  91026. - struct ctl_table tmp = *ctl;
  91027. + ctl_table_no_const tmp = *ctl;
  91028. int ret;
  91029. tmp.extra1 = &zero;
  91030. @@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
  91031. memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
  91032. sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
  91033. } else {
  91034. + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
  91035. dev_name_source = "default";
  91036. - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
  91037. - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
  91038. - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
  91039. - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
  91040. + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
  91041. + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
  91042. + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
  91043. + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
  91044. }
  91045. if (handler) {
  91046. diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
  91047. index 2bf8329..2eb1423 100644
  91048. --- a/net/core/net-procfs.c
  91049. +++ b/net/core/net-procfs.c
  91050. @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
  91051. struct rtnl_link_stats64 temp;
  91052. const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
  91053. - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
  91054. + if (gr_proc_is_restricted())
  91055. + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
  91056. + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
  91057. + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
  91058. + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
  91059. + else
  91060. + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
  91061. "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
  91062. dev->name, stats->rx_bytes, stats->rx_packets,
  91063. stats->rx_errors,
  91064. @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
  91065. return 0;
  91066. }
  91067. -static const struct seq_operations dev_seq_ops = {
  91068. +const struct seq_operations dev_seq_ops = {
  91069. .start = dev_seq_start,
  91070. .next = dev_seq_next,
  91071. .stop = dev_seq_stop,
  91072. @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
  91073. static int softnet_seq_open(struct inode *inode, struct file *file)
  91074. {
  91075. - return seq_open(file, &softnet_seq_ops);
  91076. + return seq_open_restrict(file, &softnet_seq_ops);
  91077. }
  91078. static const struct file_operations softnet_seq_fops = {
  91079. @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
  91080. else
  91081. seq_printf(seq, "%04x", ntohs(pt->type));
  91082. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  91083. + seq_printf(seq, " %-8s %pf\n",
  91084. + pt->dev ? pt->dev->name : "", NULL);
  91085. +#else
  91086. seq_printf(seq, " %-8s %pf\n",
  91087. pt->dev ? pt->dev->name : "", pt->func);
  91088. +#endif
  91089. }
  91090. return 0;
  91091. diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
  91092. index 81d3a9a..a0bd7a8 100644
  91093. --- a/net/core/net_namespace.c
  91094. +++ b/net/core/net_namespace.c
  91095. @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
  91096. int error;
  91097. LIST_HEAD(net_exit_list);
  91098. - list_add_tail(&ops->list, list);
  91099. + pax_list_add_tail((struct list_head *)&ops->list, list);
  91100. if (ops->init || (ops->id && ops->size)) {
  91101. for_each_net(net) {
  91102. error = ops_init(ops, net);
  91103. @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
  91104. out_undo:
  91105. /* If I have an error cleanup all namespaces I initialized */
  91106. - list_del(&ops->list);
  91107. + pax_list_del((struct list_head *)&ops->list);
  91108. ops_exit_list(ops, &net_exit_list);
  91109. ops_free_list(ops, &net_exit_list);
  91110. return error;
  91111. @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
  91112. struct net *net;
  91113. LIST_HEAD(net_exit_list);
  91114. - list_del(&ops->list);
  91115. + pax_list_del((struct list_head *)&ops->list);
  91116. for_each_net(net)
  91117. list_add_tail(&net->exit_list, &net_exit_list);
  91118. ops_exit_list(ops, &net_exit_list);
  91119. @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
  91120. mutex_lock(&net_mutex);
  91121. error = register_pernet_operations(&pernet_list, ops);
  91122. if (!error && (first_device == &pernet_list))
  91123. - first_device = &ops->list;
  91124. + first_device = (struct list_head *)&ops->list;
  91125. mutex_unlock(&net_mutex);
  91126. return error;
  91127. }
  91128. diff --git a/net/core/netpoll.c b/net/core/netpoll.c
  91129. index df9e6b1..6e68e4e 100644
  91130. --- a/net/core/netpoll.c
  91131. +++ b/net/core/netpoll.c
  91132. @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
  91133. struct udphdr *udph;
  91134. struct iphdr *iph;
  91135. struct ethhdr *eth;
  91136. - static atomic_t ip_ident;
  91137. + static atomic_unchecked_t ip_ident;
  91138. struct ipv6hdr *ip6h;
  91139. udp_len = len + sizeof(*udph);
  91140. @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
  91141. put_unaligned(0x45, (unsigned char *)iph);
  91142. iph->tos = 0;
  91143. put_unaligned(htons(ip_len), &(iph->tot_len));
  91144. - iph->id = htons(atomic_inc_return(&ip_ident));
  91145. + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
  91146. iph->frag_off = 0;
  91147. iph->ttl = 64;
  91148. iph->protocol = IPPROTO_UDP;
  91149. diff --git a/net/core/pktgen.c b/net/core/pktgen.c
  91150. index fdac61c..e5e5b46 100644
  91151. --- a/net/core/pktgen.c
  91152. +++ b/net/core/pktgen.c
  91153. @@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
  91154. pn->net = net;
  91155. INIT_LIST_HEAD(&pn->pktgen_threads);
  91156. pn->pktgen_exiting = false;
  91157. - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
  91158. + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
  91159. if (!pn->proc_dir) {
  91160. pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
  91161. return -ENODEV;
  91162. diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
  91163. index 120eecc..cd1ec44 100644
  91164. --- a/net/core/rtnetlink.c
  91165. +++ b/net/core/rtnetlink.c
  91166. @@ -58,7 +58,7 @@ struct rtnl_link {
  91167. rtnl_doit_func doit;
  91168. rtnl_dumpit_func dumpit;
  91169. rtnl_calcit_func calcit;
  91170. -};
  91171. +} __no_const;
  91172. static DEFINE_MUTEX(rtnl_mutex);
  91173. @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
  91174. if (rtnl_link_ops_get(ops->kind))
  91175. return -EEXIST;
  91176. - if (!ops->dellink)
  91177. - ops->dellink = unregister_netdevice_queue;
  91178. + if (!ops->dellink) {
  91179. + pax_open_kernel();
  91180. + *(void **)&ops->dellink = unregister_netdevice_queue;
  91181. + pax_close_kernel();
  91182. + }
  91183. - list_add_tail(&ops->list, &link_ops);
  91184. + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
  91185. return 0;
  91186. }
  91187. EXPORT_SYMBOL_GPL(__rtnl_link_register);
  91188. @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
  91189. for_each_net(net) {
  91190. __rtnl_kill_links(net, ops);
  91191. }
  91192. - list_del(&ops->list);
  91193. + pax_list_del((struct list_head *)&ops->list);
  91194. }
  91195. EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
  91196. diff --git a/net/core/scm.c b/net/core/scm.c
  91197. index b442e7e..6f5b5a2 100644
  91198. --- a/net/core/scm.c
  91199. +++ b/net/core/scm.c
  91200. @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
  91201. int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
  91202. {
  91203. struct cmsghdr __user *cm
  91204. - = (__force struct cmsghdr __user *)msg->msg_control;
  91205. + = (struct cmsghdr __force_user *)msg->msg_control;
  91206. struct cmsghdr cmhdr;
  91207. int cmlen = CMSG_LEN(len);
  91208. int err;
  91209. @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
  91210. err = -EFAULT;
  91211. if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
  91212. goto out;
  91213. - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
  91214. + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
  91215. goto out;
  91216. cmlen = CMSG_SPACE(len);
  91217. if (msg->msg_controllen < cmlen)
  91218. @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
  91219. void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
  91220. {
  91221. struct cmsghdr __user *cm
  91222. - = (__force struct cmsghdr __user*)msg->msg_control;
  91223. + = (struct cmsghdr __force_user *)msg->msg_control;
  91224. int fdmax = 0;
  91225. int fdnum = scm->fp->count;
  91226. @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
  91227. if (fdnum < fdmax)
  91228. fdmax = fdnum;
  91229. - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
  91230. + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
  91231. i++, cmfptr++)
  91232. {
  91233. struct socket *sock;
  91234. diff --git a/net/core/skbuff.c b/net/core/skbuff.c
  91235. index 90b96a1..cd18f16d 100644
  91236. --- a/net/core/skbuff.c
  91237. +++ b/net/core/skbuff.c
  91238. @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
  91239. __wsum skb_checksum(const struct sk_buff *skb, int offset,
  91240. int len, __wsum csum)
  91241. {
  91242. - const struct skb_checksum_ops ops = {
  91243. + static const struct skb_checksum_ops ops = {
  91244. .update = csum_partial_ext,
  91245. .combine = csum_block_add_ext,
  91246. };
  91247. @@ -3220,13 +3220,15 @@ void __init skb_init(void)
  91248. skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
  91249. sizeof(struct sk_buff),
  91250. 0,
  91251. - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  91252. + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
  91253. + SLAB_NO_SANITIZE,
  91254. NULL);
  91255. skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
  91256. (2*sizeof(struct sk_buff)) +
  91257. sizeof(atomic_t),
  91258. 0,
  91259. - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  91260. + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
  91261. + SLAB_NO_SANITIZE,
  91262. NULL);
  91263. }
  91264. diff --git a/net/core/sock.c b/net/core/sock.c
  91265. index c0fc6bd..51d8326 100644
  91266. --- a/net/core/sock.c
  91267. +++ b/net/core/sock.c
  91268. @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
  91269. struct sk_buff_head *list = &sk->sk_receive_queue;
  91270. if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
  91271. - atomic_inc(&sk->sk_drops);
  91272. + atomic_inc_unchecked(&sk->sk_drops);
  91273. trace_sock_rcvqueue_full(sk, skb);
  91274. return -ENOMEM;
  91275. }
  91276. @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
  91277. return err;
  91278. if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
  91279. - atomic_inc(&sk->sk_drops);
  91280. + atomic_inc_unchecked(&sk->sk_drops);
  91281. return -ENOBUFS;
  91282. }
  91283. @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
  91284. skb_dst_force(skb);
  91285. spin_lock_irqsave(&list->lock, flags);
  91286. - skb->dropcount = atomic_read(&sk->sk_drops);
  91287. + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
  91288. __skb_queue_tail(list, skb);
  91289. spin_unlock_irqrestore(&list->lock, flags);
  91290. @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
  91291. skb->dev = NULL;
  91292. if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
  91293. - atomic_inc(&sk->sk_drops);
  91294. + atomic_inc_unchecked(&sk->sk_drops);
  91295. goto discard_and_relse;
  91296. }
  91297. if (nested)
  91298. @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
  91299. mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
  91300. } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
  91301. bh_unlock_sock(sk);
  91302. - atomic_inc(&sk->sk_drops);
  91303. + atomic_inc_unchecked(&sk->sk_drops);
  91304. goto discard_and_relse;
  91305. }
  91306. @@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
  91307. struct timeval tm;
  91308. } v;
  91309. - int lv = sizeof(int);
  91310. - int len;
  91311. + unsigned int lv = sizeof(int);
  91312. + unsigned int len;
  91313. if (get_user(len, optlen))
  91314. return -EFAULT;
  91315. - if (len < 0)
  91316. + if (len > INT_MAX)
  91317. return -EINVAL;
  91318. memset(&v, 0, sizeof(v));
  91319. @@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
  91320. case SO_PEERNAME:
  91321. {
  91322. - char address[128];
  91323. + char address[_K_SS_MAXSIZE];
  91324. if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
  91325. return -ENOTCONN;
  91326. - if (lv < len)
  91327. + if (lv < len || sizeof address < len)
  91328. return -EINVAL;
  91329. if (copy_to_user(optval, address, len))
  91330. return -EFAULT;
  91331. @@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
  91332. if (len > lv)
  91333. len = lv;
  91334. - if (copy_to_user(optval, &v, len))
  91335. + if (len > sizeof(v) || copy_to_user(optval, &v, len))
  91336. return -EFAULT;
  91337. lenout:
  91338. if (put_user(len, optlen))
  91339. @@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
  91340. */
  91341. smp_wmb();
  91342. atomic_set(&sk->sk_refcnt, 1);
  91343. - atomic_set(&sk->sk_drops, 0);
  91344. + atomic_set_unchecked(&sk->sk_drops, 0);
  91345. }
  91346. EXPORT_SYMBOL(sock_init_data);
  91347. @@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
  91348. int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
  91349. int level, int type)
  91350. {
  91351. + struct sock_extended_err ee;
  91352. struct sock_exterr_skb *serr;
  91353. struct sk_buff *skb, *skb2;
  91354. int copied, err;
  91355. @@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
  91356. sock_recv_timestamp(msg, sk, skb);
  91357. serr = SKB_EXT_ERR(skb);
  91358. - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
  91359. + ee = serr->ee;
  91360. + put_cmsg(msg, level, type, sizeof ee, &ee);
  91361. msg->msg_flags |= MSG_ERRQUEUE;
  91362. err = copied;
  91363. diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
  91364. index a0e9cf6..ef7f9ed 100644
  91365. --- a/net/core/sock_diag.c
  91366. +++ b/net/core/sock_diag.c
  91367. @@ -9,26 +9,33 @@
  91368. #include <linux/inet_diag.h>
  91369. #include <linux/sock_diag.h>
  91370. -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
  91371. +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
  91372. static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
  91373. static DEFINE_MUTEX(sock_diag_table_mutex);
  91374. int sock_diag_check_cookie(void *sk, __u32 *cookie)
  91375. {
  91376. +#ifndef CONFIG_GRKERNSEC_HIDESYM
  91377. if ((cookie[0] != INET_DIAG_NOCOOKIE ||
  91378. cookie[1] != INET_DIAG_NOCOOKIE) &&
  91379. ((u32)(unsigned long)sk != cookie[0] ||
  91380. (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
  91381. return -ESTALE;
  91382. else
  91383. +#endif
  91384. return 0;
  91385. }
  91386. EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
  91387. void sock_diag_save_cookie(void *sk, __u32 *cookie)
  91388. {
  91389. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  91390. + cookie[0] = 0;
  91391. + cookie[1] = 0;
  91392. +#else
  91393. cookie[0] = (u32)(unsigned long)sk;
  91394. cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
  91395. +#endif
  91396. }
  91397. EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
  91398. @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
  91399. mutex_lock(&sock_diag_table_mutex);
  91400. if (sock_diag_handlers[hndl->family])
  91401. err = -EBUSY;
  91402. - else
  91403. + else {
  91404. + pax_open_kernel();
  91405. sock_diag_handlers[hndl->family] = hndl;
  91406. + pax_close_kernel();
  91407. + }
  91408. mutex_unlock(&sock_diag_table_mutex);
  91409. return err;
  91410. @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
  91411. mutex_lock(&sock_diag_table_mutex);
  91412. BUG_ON(sock_diag_handlers[family] != hnld);
  91413. + pax_open_kernel();
  91414. sock_diag_handlers[family] = NULL;
  91415. + pax_close_kernel();
  91416. mutex_unlock(&sock_diag_table_mutex);
  91417. }
  91418. EXPORT_SYMBOL_GPL(sock_diag_unregister);
  91419. diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
  91420. index cf9cd13..8b56af3 100644
  91421. --- a/net/core/sysctl_net_core.c
  91422. +++ b/net/core/sysctl_net_core.c
  91423. @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
  91424. {
  91425. unsigned int orig_size, size;
  91426. int ret, i;
  91427. - struct ctl_table tmp = {
  91428. + ctl_table_no_const tmp = {
  91429. .data = &size,
  91430. .maxlen = sizeof(size),
  91431. .mode = table->mode
  91432. @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
  91433. void __user *buffer, size_t *lenp, loff_t *ppos)
  91434. {
  91435. char id[IFNAMSIZ];
  91436. - struct ctl_table tbl = {
  91437. + ctl_table_no_const tbl = {
  91438. .data = id,
  91439. .maxlen = IFNAMSIZ,
  91440. };
  91441. @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
  91442. static __net_init int sysctl_core_net_init(struct net *net)
  91443. {
  91444. - struct ctl_table *tbl;
  91445. + ctl_table_no_const *tbl = NULL;
  91446. net->core.sysctl_somaxconn = SOMAXCONN;
  91447. - tbl = netns_core_table;
  91448. if (!net_eq(net, &init_net)) {
  91449. - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
  91450. + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
  91451. if (tbl == NULL)
  91452. goto err_dup;
  91453. @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
  91454. if (net->user_ns != &init_user_ns) {
  91455. tbl[0].procname = NULL;
  91456. }
  91457. - }
  91458. -
  91459. - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
  91460. + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
  91461. + } else
  91462. + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
  91463. if (net->core.sysctl_hdr == NULL)
  91464. goto err_reg;
  91465. return 0;
  91466. err_reg:
  91467. - if (tbl != netns_core_table)
  91468. - kfree(tbl);
  91469. + kfree(tbl);
  91470. err_dup:
  91471. return -ENOMEM;
  91472. }
  91473. @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
  91474. kfree(tbl);
  91475. }
  91476. -static __net_initdata struct pernet_operations sysctl_core_ops = {
  91477. +static __net_initconst struct pernet_operations sysctl_core_ops = {
  91478. .init = sysctl_core_net_init,
  91479. .exit = sysctl_core_net_exit,
  91480. };
  91481. diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
  91482. index 4c04848..f575934 100644
  91483. --- a/net/decnet/af_decnet.c
  91484. +++ b/net/decnet/af_decnet.c
  91485. @@ -465,6 +465,7 @@ static struct proto dn_proto = {
  91486. .sysctl_rmem = sysctl_decnet_rmem,
  91487. .max_header = DN_MAX_NSP_DATA_HEADER + 64,
  91488. .obj_size = sizeof(struct dn_sock),
  91489. + .slab_flags = SLAB_USERCOPY,
  91490. };
  91491. static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
  91492. diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
  91493. index a603823..a36ee0b 100644
  91494. --- a/net/decnet/dn_dev.c
  91495. +++ b/net/decnet/dn_dev.c
  91496. @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
  91497. .extra1 = &min_t3,
  91498. .extra2 = &max_t3
  91499. },
  91500. - {0}
  91501. + { }
  91502. },
  91503. };
  91504. diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
  91505. index 5325b54..a0d4d69 100644
  91506. --- a/net/decnet/sysctl_net_decnet.c
  91507. +++ b/net/decnet/sysctl_net_decnet.c
  91508. @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
  91509. if (len > *lenp) len = *lenp;
  91510. - if (copy_to_user(buffer, addr, len))
  91511. + if (len > sizeof addr || copy_to_user(buffer, addr, len))
  91512. return -EFAULT;
  91513. *lenp = len;
  91514. @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
  91515. if (len > *lenp) len = *lenp;
  91516. - if (copy_to_user(buffer, devname, len))
  91517. + if (len > sizeof devname || copy_to_user(buffer, devname, len))
  91518. return -EFAULT;
  91519. *lenp = len;
  91520. diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
  91521. index 1846c1f..96d4a9f 100644
  91522. --- a/net/ieee802154/dgram.c
  91523. +++ b/net/ieee802154/dgram.c
  91524. @@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
  91525. if (saddr) {
  91526. saddr->family = AF_IEEE802154;
  91527. saddr->addr = mac_cb(skb)->sa;
  91528. + }
  91529. + if (addr_len)
  91530. *addr_len = sizeof(*saddr);
  91531. - }
  91532. if (flags & MSG_TRUNC)
  91533. copied = skb->len;
  91534. diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
  91535. index 19ab78a..bf575c9 100644
  91536. --- a/net/ipv4/af_inet.c
  91537. +++ b/net/ipv4/af_inet.c
  91538. @@ -1703,13 +1703,9 @@ static int __init inet_init(void)
  91539. BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
  91540. - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
  91541. - if (!sysctl_local_reserved_ports)
  91542. - goto out;
  91543. -
  91544. rc = proto_register(&tcp_prot, 1);
  91545. if (rc)
  91546. - goto out_free_reserved_ports;
  91547. + goto out;
  91548. rc = proto_register(&udp_prot, 1);
  91549. if (rc)
  91550. @@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
  91551. proto_unregister(&udp_prot);
  91552. out_unregister_tcp_proto:
  91553. proto_unregister(&tcp_prot);
  91554. -out_free_reserved_ports:
  91555. - kfree(sysctl_local_reserved_ports);
  91556. goto out;
  91557. }
  91558. diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
  91559. index bdbf68b..deb4759 100644
  91560. --- a/net/ipv4/devinet.c
  91561. +++ b/net/ipv4/devinet.c
  91562. @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
  91563. idx = 0;
  91564. head = &net->dev_index_head[h];
  91565. rcu_read_lock();
  91566. - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
  91567. + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
  91568. net->dev_base_seq;
  91569. hlist_for_each_entry_rcu(dev, head, index_hlist) {
  91570. if (idx < s_idx)
  91571. @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
  91572. idx = 0;
  91573. head = &net->dev_index_head[h];
  91574. rcu_read_lock();
  91575. - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
  91576. + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
  91577. net->dev_base_seq;
  91578. hlist_for_each_entry_rcu(dev, head, index_hlist) {
  91579. if (idx < s_idx)
  91580. @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
  91581. #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
  91582. DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
  91583. -static struct devinet_sysctl_table {
  91584. +static const struct devinet_sysctl_table {
  91585. struct ctl_table_header *sysctl_header;
  91586. struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
  91587. } devinet_sysctl = {
  91588. @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
  91589. int err;
  91590. struct ipv4_devconf *all, *dflt;
  91591. #ifdef CONFIG_SYSCTL
  91592. - struct ctl_table *tbl = ctl_forward_entry;
  91593. + ctl_table_no_const *tbl = NULL;
  91594. struct ctl_table_header *forw_hdr;
  91595. #endif
  91596. @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
  91597. goto err_alloc_dflt;
  91598. #ifdef CONFIG_SYSCTL
  91599. - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
  91600. + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
  91601. if (tbl == NULL)
  91602. goto err_alloc_ctl;
  91603. @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
  91604. goto err_reg_dflt;
  91605. err = -ENOMEM;
  91606. - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
  91607. + if (!net_eq(net, &init_net))
  91608. + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
  91609. + else
  91610. + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
  91611. if (forw_hdr == NULL)
  91612. goto err_reg_ctl;
  91613. net->ipv4.forw_hdr = forw_hdr;
  91614. @@ -2272,8 +2275,7 @@ err_reg_ctl:
  91615. err_reg_dflt:
  91616. __devinet_sysctl_unregister(all);
  91617. err_reg_all:
  91618. - if (tbl != ctl_forward_entry)
  91619. - kfree(tbl);
  91620. + kfree(tbl);
  91621. err_alloc_ctl:
  91622. #endif
  91623. if (dflt != &ipv4_devconf_dflt)
  91624. diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
  91625. index c7539e2..b455e51 100644
  91626. --- a/net/ipv4/fib_frontend.c
  91627. +++ b/net/ipv4/fib_frontend.c
  91628. @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
  91629. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  91630. fib_sync_up(dev);
  91631. #endif
  91632. - atomic_inc(&net->ipv4.dev_addr_genid);
  91633. + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
  91634. rt_cache_flush(dev_net(dev));
  91635. break;
  91636. case NETDEV_DOWN:
  91637. fib_del_ifaddr(ifa, NULL);
  91638. - atomic_inc(&net->ipv4.dev_addr_genid);
  91639. + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
  91640. if (ifa->ifa_dev->ifa_list == NULL) {
  91641. /* Last address was deleted from this interface.
  91642. * Disable IP.
  91643. @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
  91644. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  91645. fib_sync_up(dev);
  91646. #endif
  91647. - atomic_inc(&net->ipv4.dev_addr_genid);
  91648. + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
  91649. rt_cache_flush(net);
  91650. break;
  91651. case NETDEV_DOWN:
  91652. diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
  91653. index b53f0bf..3585b33 100644
  91654. --- a/net/ipv4/fib_semantics.c
  91655. +++ b/net/ipv4/fib_semantics.c
  91656. @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
  91657. nh->nh_saddr = inet_select_addr(nh->nh_dev,
  91658. nh->nh_gw,
  91659. nh->nh_parent->fib_scope);
  91660. - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
  91661. + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
  91662. return nh->nh_saddr;
  91663. }
  91664. diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
  91665. index 0d1e2cb..4501a2c 100644
  91666. --- a/net/ipv4/inet_connection_sock.c
  91667. +++ b/net/ipv4/inet_connection_sock.c
  91668. @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
  91669. EXPORT_SYMBOL(inet_csk_timer_bug_msg);
  91670. #endif
  91671. -unsigned long *sysctl_local_reserved_ports;
  91672. +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
  91673. EXPORT_SYMBOL(sysctl_local_reserved_ports);
  91674. void inet_get_local_port_range(struct net *net, int *low, int *high)
  91675. diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
  91676. index 8b9cf27..0d8d592 100644
  91677. --- a/net/ipv4/inet_hashtables.c
  91678. +++ b/net/ipv4/inet_hashtables.c
  91679. @@ -18,6 +18,7 @@
  91680. #include <linux/sched.h>
  91681. #include <linux/slab.h>
  91682. #include <linux/wait.h>
  91683. +#include <linux/security.h>
  91684. #include <net/inet_connection_sock.h>
  91685. #include <net/inet_hashtables.h>
  91686. @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
  91687. return inet_ehashfn(net, laddr, lport, faddr, fport);
  91688. }
  91689. +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
  91690. +
  91691. /*
  91692. * Allocate and initialize a new local port bind bucket.
  91693. * The bindhash mutex for snum's hash chain must be held here.
  91694. @@ -554,6 +557,8 @@ ok:
  91695. twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
  91696. spin_unlock(&head->lock);
  91697. + gr_update_task_in_ip_table(current, inet_sk(sk));
  91698. +
  91699. if (tw) {
  91700. inet_twsk_deschedule(tw, death_row);
  91701. while (twrefcnt) {
  91702. diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
  91703. index 48f4244..f56d83a 100644
  91704. --- a/net/ipv4/inetpeer.c
  91705. +++ b/net/ipv4/inetpeer.c
  91706. @@ -496,8 +496,8 @@ relookup:
  91707. if (p) {
  91708. p->daddr = *daddr;
  91709. atomic_set(&p->refcnt, 1);
  91710. - atomic_set(&p->rid, 0);
  91711. - atomic_set(&p->ip_id_count,
  91712. + atomic_set_unchecked(&p->rid, 0);
  91713. + atomic_set_unchecked(&p->ip_id_count,
  91714. (daddr->family == AF_INET) ?
  91715. secure_ip_id(daddr->addr.a4) :
  91716. secure_ipv6_id(daddr->addr.a6));
  91717. diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
  91718. index c10a3ce..dd71f84 100644
  91719. --- a/net/ipv4/ip_fragment.c
  91720. +++ b/net/ipv4/ip_fragment.c
  91721. @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
  91722. return 0;
  91723. start = qp->rid;
  91724. - end = atomic_inc_return(&peer->rid);
  91725. + end = atomic_inc_return_unchecked(&peer->rid);
  91726. qp->rid = end;
  91727. rc = qp->q.fragments && (end - start) > max;
  91728. @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
  91729. static int __net_init ip4_frags_ns_ctl_register(struct net *net)
  91730. {
  91731. - struct ctl_table *table;
  91732. + ctl_table_no_const *table = NULL;
  91733. struct ctl_table_header *hdr;
  91734. - table = ip4_frags_ns_ctl_table;
  91735. if (!net_eq(net, &init_net)) {
  91736. - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
  91737. + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
  91738. if (table == NULL)
  91739. goto err_alloc;
  91740. @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
  91741. /* Don't export sysctls to unprivileged users */
  91742. if (net->user_ns != &init_user_ns)
  91743. table[0].procname = NULL;
  91744. - }
  91745. + hdr = register_net_sysctl(net, "net/ipv4", table);
  91746. + } else
  91747. + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
  91748. - hdr = register_net_sysctl(net, "net/ipv4", table);
  91749. if (hdr == NULL)
  91750. goto err_reg;
  91751. @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
  91752. return 0;
  91753. err_reg:
  91754. - if (!net_eq(net, &init_net))
  91755. - kfree(table);
  91756. + kfree(table);
  91757. err_alloc:
  91758. return -ENOMEM;
  91759. }
  91760. diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
  91761. index ec4f762..4ce3645 100644
  91762. --- a/net/ipv4/ip_gre.c
  91763. +++ b/net/ipv4/ip_gre.c
  91764. @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
  91765. module_param(log_ecn_error, bool, 0644);
  91766. MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
  91767. -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
  91768. +static struct rtnl_link_ops ipgre_link_ops;
  91769. static int ipgre_tunnel_init(struct net_device *dev);
  91770. static int ipgre_net_id __read_mostly;
  91771. @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
  91772. [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
  91773. };
  91774. -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
  91775. +static struct rtnl_link_ops ipgre_link_ops = {
  91776. .kind = "gre",
  91777. .maxtype = IFLA_GRE_MAX,
  91778. .policy = ipgre_policy,
  91779. @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
  91780. .fill_info = ipgre_fill_info,
  91781. };
  91782. -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
  91783. +static struct rtnl_link_ops ipgre_tap_ops = {
  91784. .kind = "gretap",
  91785. .maxtype = IFLA_GRE_MAX,
  91786. .policy = ipgre_policy,
  91787. diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
  91788. index 580dd96..9fcef7e 100644
  91789. --- a/net/ipv4/ip_sockglue.c
  91790. +++ b/net/ipv4/ip_sockglue.c
  91791. @@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
  91792. len = min_t(unsigned int, len, opt->optlen);
  91793. if (put_user(len, optlen))
  91794. return -EFAULT;
  91795. - if (copy_to_user(optval, opt->__data, len))
  91796. + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
  91797. + copy_to_user(optval, opt->__data, len))
  91798. return -EFAULT;
  91799. return 0;
  91800. }
  91801. @@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
  91802. if (sk->sk_type != SOCK_STREAM)
  91803. return -ENOPROTOOPT;
  91804. - msg.msg_control = optval;
  91805. + msg.msg_control = (void __force_kernel *)optval;
  91806. msg.msg_controllen = len;
  91807. msg.msg_flags = flags;
  91808. diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
  91809. index 48eafae..defff53 100644
  91810. --- a/net/ipv4/ip_vti.c
  91811. +++ b/net/ipv4/ip_vti.c
  91812. @@ -44,7 +44,7 @@
  91813. #include <net/net_namespace.h>
  91814. #include <net/netns/generic.h>
  91815. -static struct rtnl_link_ops vti_link_ops __read_mostly;
  91816. +static struct rtnl_link_ops vti_link_ops;
  91817. static int vti_net_id __read_mostly;
  91818. static int vti_tunnel_init(struct net_device *dev);
  91819. @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
  91820. [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
  91821. };
  91822. -static struct rtnl_link_ops vti_link_ops __read_mostly = {
  91823. +static struct rtnl_link_ops vti_link_ops = {
  91824. .kind = "vti",
  91825. .maxtype = IFLA_VTI_MAX,
  91826. .policy = vti_policy,
  91827. diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
  91828. index b3e86ea..18ce98c 100644
  91829. --- a/net/ipv4/ipconfig.c
  91830. +++ b/net/ipv4/ipconfig.c
  91831. @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
  91832. mm_segment_t oldfs = get_fs();
  91833. set_fs(get_ds());
  91834. - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
  91835. + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
  91836. set_fs(oldfs);
  91837. return res;
  91838. }
  91839. @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
  91840. mm_segment_t oldfs = get_fs();
  91841. set_fs(get_ds());
  91842. - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
  91843. + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
  91844. set_fs(oldfs);
  91845. return res;
  91846. }
  91847. @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
  91848. mm_segment_t oldfs = get_fs();
  91849. set_fs(get_ds());
  91850. - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
  91851. + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
  91852. set_fs(oldfs);
  91853. return res;
  91854. }
  91855. diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
  91856. index 812b183..56cbe9c 100644
  91857. --- a/net/ipv4/ipip.c
  91858. +++ b/net/ipv4/ipip.c
  91859. @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
  91860. static int ipip_net_id __read_mostly;
  91861. static int ipip_tunnel_init(struct net_device *dev);
  91862. -static struct rtnl_link_ops ipip_link_ops __read_mostly;
  91863. +static struct rtnl_link_ops ipip_link_ops;
  91864. static int ipip_err(struct sk_buff *skb, u32 info)
  91865. {
  91866. @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
  91867. [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
  91868. };
  91869. -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
  91870. +static struct rtnl_link_ops ipip_link_ops = {
  91871. .kind = "ipip",
  91872. .maxtype = IFLA_IPTUN_MAX,
  91873. .policy = ipip_policy,
  91874. diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
  91875. index 59da7cd..e318de1 100644
  91876. --- a/net/ipv4/netfilter/arp_tables.c
  91877. +++ b/net/ipv4/netfilter/arp_tables.c
  91878. @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
  91879. #endif
  91880. static int get_info(struct net *net, void __user *user,
  91881. - const int *len, int compat)
  91882. + int len, int compat)
  91883. {
  91884. char name[XT_TABLE_MAXNAMELEN];
  91885. struct xt_table *t;
  91886. int ret;
  91887. - if (*len != sizeof(struct arpt_getinfo)) {
  91888. - duprintf("length %u != %Zu\n", *len,
  91889. + if (len != sizeof(struct arpt_getinfo)) {
  91890. + duprintf("length %u != %Zu\n", len,
  91891. sizeof(struct arpt_getinfo));
  91892. return -EINVAL;
  91893. }
  91894. @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
  91895. info.size = private->size;
  91896. strcpy(info.name, name);
  91897. - if (copy_to_user(user, &info, *len) != 0)
  91898. + if (copy_to_user(user, &info, len) != 0)
  91899. ret = -EFAULT;
  91900. else
  91901. ret = 0;
  91902. @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
  91903. switch (cmd) {
  91904. case ARPT_SO_GET_INFO:
  91905. - ret = get_info(sock_net(sk), user, len, 1);
  91906. + ret = get_info(sock_net(sk), user, *len, 1);
  91907. break;
  91908. case ARPT_SO_GET_ENTRIES:
  91909. ret = compat_get_entries(sock_net(sk), user, len);
  91910. @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
  91911. switch (cmd) {
  91912. case ARPT_SO_GET_INFO:
  91913. - ret = get_info(sock_net(sk), user, len, 0);
  91914. + ret = get_info(sock_net(sk), user, *len, 0);
  91915. break;
  91916. case ARPT_SO_GET_ENTRIES:
  91917. diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
  91918. index 718dfbd..cef4152 100644
  91919. --- a/net/ipv4/netfilter/ip_tables.c
  91920. +++ b/net/ipv4/netfilter/ip_tables.c
  91921. @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
  91922. #endif
  91923. static int get_info(struct net *net, void __user *user,
  91924. - const int *len, int compat)
  91925. + int len, int compat)
  91926. {
  91927. char name[XT_TABLE_MAXNAMELEN];
  91928. struct xt_table *t;
  91929. int ret;
  91930. - if (*len != sizeof(struct ipt_getinfo)) {
  91931. - duprintf("length %u != %zu\n", *len,
  91932. + if (len != sizeof(struct ipt_getinfo)) {
  91933. + duprintf("length %u != %zu\n", len,
  91934. sizeof(struct ipt_getinfo));
  91935. return -EINVAL;
  91936. }
  91937. @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
  91938. info.size = private->size;
  91939. strcpy(info.name, name);
  91940. - if (copy_to_user(user, &info, *len) != 0)
  91941. + if (copy_to_user(user, &info, len) != 0)
  91942. ret = -EFAULT;
  91943. else
  91944. ret = 0;
  91945. @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
  91946. switch (cmd) {
  91947. case IPT_SO_GET_INFO:
  91948. - ret = get_info(sock_net(sk), user, len, 1);
  91949. + ret = get_info(sock_net(sk), user, *len, 1);
  91950. break;
  91951. case IPT_SO_GET_ENTRIES:
  91952. ret = compat_get_entries(sock_net(sk), user, len);
  91953. @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
  91954. switch (cmd) {
  91955. case IPT_SO_GET_INFO:
  91956. - ret = get_info(sock_net(sk), user, len, 0);
  91957. + ret = get_info(sock_net(sk), user, *len, 0);
  91958. break;
  91959. case IPT_SO_GET_ENTRIES:
  91960. diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
  91961. index 2510c02..cfb34fa 100644
  91962. --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
  91963. +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
  91964. @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
  91965. spin_lock_init(&cn->lock);
  91966. #ifdef CONFIG_PROC_FS
  91967. - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
  91968. + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
  91969. if (!cn->procdir) {
  91970. pr_err("Unable to proc dir entry\n");
  91971. return -ENOMEM;
  91972. diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
  91973. index 2d11c09..3f153f8 100644
  91974. --- a/net/ipv4/ping.c
  91975. +++ b/net/ipv4/ping.c
  91976. @@ -59,7 +59,7 @@ struct ping_table {
  91977. };
  91978. static struct ping_table ping_table;
  91979. -struct pingv6_ops pingv6_ops;
  91980. +struct pingv6_ops *pingv6_ops;
  91981. EXPORT_SYMBOL_GPL(pingv6_ops);
  91982. static u16 ping_port_rover;
  91983. @@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
  91984. struct group_info *group_info = get_current_groups();
  91985. int i, j, count = group_info->ngroups;
  91986. kgid_t low, high;
  91987. + int ret = 0;
  91988. inet_get_ping_group_range_net(net, &low, &high);
  91989. if (gid_lte(low, group) && gid_lte(group, high))
  91990. - return 0;
  91991. + goto out_release_group;
  91992. for (i = 0; i < group_info->nblocks; i++) {
  91993. int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
  91994. for (j = 0; j < cp_count; j++) {
  91995. kgid_t gid = group_info->blocks[i][j];
  91996. if (gid_lte(low, gid) && gid_lte(gid, high))
  91997. - return 0;
  91998. + goto out_release_group;
  91999. }
  92000. count -= cp_count;
  92001. }
  92002. - return -EACCES;
  92003. + ret = -EACCES;
  92004. +
  92005. +out_release_group:
  92006. + put_group_info(group_info);
  92007. + return ret;
  92008. }
  92009. EXPORT_SYMBOL_GPL(ping_init_sock);
  92010. @@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
  92011. return -ENODEV;
  92012. }
  92013. }
  92014. - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
  92015. + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
  92016. scoped);
  92017. rcu_read_unlock();
  92018. @@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
  92019. }
  92020. #if IS_ENABLED(CONFIG_IPV6)
  92021. } else if (skb->protocol == htons(ETH_P_IPV6)) {
  92022. - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
  92023. + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
  92024. #endif
  92025. }
  92026. @@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
  92027. info, (u8 *)icmph);
  92028. #if IS_ENABLED(CONFIG_IPV6)
  92029. } else if (family == AF_INET6) {
  92030. - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
  92031. + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
  92032. info, (u8 *)icmph);
  92033. #endif
  92034. }
  92035. @@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92036. {
  92037. struct inet_sock *isk = inet_sk(sk);
  92038. int family = sk->sk_family;
  92039. + struct sockaddr_in *sin;
  92040. + struct sockaddr_in6 *sin6;
  92041. struct sk_buff *skb;
  92042. int copied, err;
  92043. @@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92044. if (flags & MSG_OOB)
  92045. goto out;
  92046. + if (addr_len) {
  92047. + if (family == AF_INET)
  92048. + *addr_len = sizeof(*sin);
  92049. + else if (family == AF_INET6 && addr_len)
  92050. + *addr_len = sizeof(*sin6);
  92051. + }
  92052. +
  92053. if (flags & MSG_ERRQUEUE) {
  92054. if (family == AF_INET) {
  92055. return ip_recv_error(sk, msg, len, addr_len);
  92056. #if IS_ENABLED(CONFIG_IPV6)
  92057. } else if (family == AF_INET6) {
  92058. - return pingv6_ops.ipv6_recv_error(sk, msg, len,
  92059. + return pingv6_ops->ipv6_recv_error(sk, msg, len,
  92060. addr_len);
  92061. #endif
  92062. }
  92063. @@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92064. sin->sin_port = 0 /* skb->h.uh->source */;
  92065. sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
  92066. memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
  92067. - *addr_len = sizeof(*sin);
  92068. }
  92069. if (isk->cmsg_flags)
  92070. @@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92071. sin6->sin6_scope_id =
  92072. ipv6_iface_scope_id(&sin6->sin6_addr,
  92073. IP6CB(skb)->iif);
  92074. - *addr_len = sizeof(*sin6);
  92075. }
  92076. if (inet6_sk(sk)->rxopt.all)
  92077. - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
  92078. + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
  92079. if (skb->protocol == htons(ETH_P_IPV6) &&
  92080. inet6_sk(sk)->rxopt.all)
  92081. - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
  92082. + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
  92083. else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
  92084. ip_cmsg_recv(msg, skb);
  92085. #endif
  92086. @@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
  92087. from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
  92088. 0, sock_i_ino(sp),
  92089. atomic_read(&sp->sk_refcnt), sp,
  92090. - atomic_read(&sp->sk_drops));
  92091. + atomic_read_unchecked(&sp->sk_drops));
  92092. }
  92093. static int ping_v4_seq_show(struct seq_file *seq, void *v)
  92094. diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
  92095. index c04518f..824ebe5 100644
  92096. --- a/net/ipv4/raw.c
  92097. +++ b/net/ipv4/raw.c
  92098. @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
  92099. int raw_rcv(struct sock *sk, struct sk_buff *skb)
  92100. {
  92101. if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
  92102. - atomic_inc(&sk->sk_drops);
  92103. + atomic_inc_unchecked(&sk->sk_drops);
  92104. kfree_skb(skb);
  92105. return NET_RX_DROP;
  92106. }
  92107. @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92108. if (flags & MSG_OOB)
  92109. goto out;
  92110. + if (addr_len)
  92111. + *addr_len = sizeof(*sin);
  92112. +
  92113. if (flags & MSG_ERRQUEUE) {
  92114. err = ip_recv_error(sk, msg, len, addr_len);
  92115. goto out;
  92116. @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92117. sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
  92118. sin->sin_port = 0;
  92119. memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
  92120. - *addr_len = sizeof(*sin);
  92121. }
  92122. if (inet->cmsg_flags)
  92123. ip_cmsg_recv(msg, skb);
  92124. @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
  92125. static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
  92126. {
  92127. + struct icmp_filter filter;
  92128. +
  92129. if (optlen > sizeof(struct icmp_filter))
  92130. optlen = sizeof(struct icmp_filter);
  92131. - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
  92132. + if (copy_from_user(&filter, optval, optlen))
  92133. return -EFAULT;
  92134. + raw_sk(sk)->filter = filter;
  92135. return 0;
  92136. }
  92137. static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
  92138. {
  92139. int len, ret = -EFAULT;
  92140. + struct icmp_filter filter;
  92141. if (get_user(len, optlen))
  92142. goto out;
  92143. @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
  92144. if (len > sizeof(struct icmp_filter))
  92145. len = sizeof(struct icmp_filter);
  92146. ret = -EFAULT;
  92147. - if (put_user(len, optlen) ||
  92148. - copy_to_user(optval, &raw_sk(sk)->filter, len))
  92149. + filter = raw_sk(sk)->filter;
  92150. + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
  92151. goto out;
  92152. ret = 0;
  92153. out: return ret;
  92154. @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
  92155. 0, 0L, 0,
  92156. from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
  92157. 0, sock_i_ino(sp),
  92158. - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
  92159. + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
  92160. }
  92161. static int raw_seq_show(struct seq_file *seq, void *v)
  92162. diff --git a/net/ipv4/route.c b/net/ipv4/route.c
  92163. index 4c011ec..8fae66b 100644
  92164. --- a/net/ipv4/route.c
  92165. +++ b/net/ipv4/route.c
  92166. @@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
  92167. static int rt_cache_seq_open(struct inode *inode, struct file *file)
  92168. {
  92169. - return seq_open(file, &rt_cache_seq_ops);
  92170. + return seq_open_restrict(file, &rt_cache_seq_ops);
  92171. }
  92172. static const struct file_operations rt_cache_seq_fops = {
  92173. @@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
  92174. static int rt_cpu_seq_open(struct inode *inode, struct file *file)
  92175. {
  92176. - return seq_open(file, &rt_cpu_seq_ops);
  92177. + return seq_open_restrict(file, &rt_cpu_seq_ops);
  92178. }
  92179. static const struct file_operations rt_cpu_seq_fops = {
  92180. @@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
  92181. static int rt_acct_proc_open(struct inode *inode, struct file *file)
  92182. {
  92183. - return single_open(file, rt_acct_proc_show, NULL);
  92184. + return single_open_restrict(file, rt_acct_proc_show, NULL);
  92185. }
  92186. static const struct file_operations rt_acct_proc_fops = {
  92187. @@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
  92188. .maxlen = sizeof(int),
  92189. .mode = 0200,
  92190. .proc_handler = ipv4_sysctl_rtcache_flush,
  92191. + .extra1 = &init_net,
  92192. },
  92193. { },
  92194. };
  92195. static __net_init int sysctl_route_net_init(struct net *net)
  92196. {
  92197. - struct ctl_table *tbl;
  92198. + ctl_table_no_const *tbl = NULL;
  92199. - tbl = ipv4_route_flush_table;
  92200. if (!net_eq(net, &init_net)) {
  92201. - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
  92202. + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
  92203. if (tbl == NULL)
  92204. goto err_dup;
  92205. /* Don't export sysctls to unprivileged users */
  92206. if (net->user_ns != &init_user_ns)
  92207. tbl[0].procname = NULL;
  92208. - }
  92209. - tbl[0].extra1 = net;
  92210. + tbl[0].extra1 = net;
  92211. + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
  92212. + } else
  92213. + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
  92214. - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
  92215. if (net->ipv4.route_hdr == NULL)
  92216. goto err_reg;
  92217. return 0;
  92218. err_reg:
  92219. - if (tbl != ipv4_route_flush_table)
  92220. - kfree(tbl);
  92221. + kfree(tbl);
  92222. err_dup:
  92223. return -ENOMEM;
  92224. }
  92225. @@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
  92226. static __net_init int rt_genid_init(struct net *net)
  92227. {
  92228. - atomic_set(&net->ipv4.rt_genid, 0);
  92229. - atomic_set(&net->fnhe_genid, 0);
  92230. + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
  92231. + atomic_set_unchecked(&net->fnhe_genid, 0);
  92232. get_random_bytes(&net->ipv4.dev_addr_genid,
  92233. sizeof(net->ipv4.dev_addr_genid));
  92234. return 0;
  92235. diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
  92236. index 44eba05..b36864b 100644
  92237. --- a/net/ipv4/sysctl_net_ipv4.c
  92238. +++ b/net/ipv4/sysctl_net_ipv4.c
  92239. @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
  92240. container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
  92241. int ret;
  92242. int range[2];
  92243. - struct ctl_table tmp = {
  92244. + ctl_table_no_const tmp = {
  92245. .data = &range,
  92246. .maxlen = sizeof(range),
  92247. .mode = table->mode,
  92248. @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
  92249. int ret;
  92250. gid_t urange[2];
  92251. kgid_t low, high;
  92252. - struct ctl_table tmp = {
  92253. + ctl_table_no_const tmp = {
  92254. .data = &urange,
  92255. .maxlen = sizeof(urange),
  92256. .mode = table->mode,
  92257. @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
  92258. void __user *buffer, size_t *lenp, loff_t *ppos)
  92259. {
  92260. char val[TCP_CA_NAME_MAX];
  92261. - struct ctl_table tbl = {
  92262. + ctl_table_no_const tbl = {
  92263. .data = val,
  92264. .maxlen = TCP_CA_NAME_MAX,
  92265. };
  92266. @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
  92267. void __user *buffer, size_t *lenp,
  92268. loff_t *ppos)
  92269. {
  92270. - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
  92271. + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
  92272. int ret;
  92273. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  92274. @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
  92275. void __user *buffer, size_t *lenp,
  92276. loff_t *ppos)
  92277. {
  92278. - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
  92279. + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
  92280. int ret;
  92281. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  92282. @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
  92283. void __user *buffer, size_t *lenp,
  92284. loff_t *ppos)
  92285. {
  92286. - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
  92287. + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
  92288. struct tcp_fastopen_context *ctxt;
  92289. int ret;
  92290. u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
  92291. @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
  92292. },
  92293. {
  92294. .procname = "ip_local_reserved_ports",
  92295. - .data = NULL, /* initialized in sysctl_ipv4_init */
  92296. + .data = sysctl_local_reserved_ports,
  92297. .maxlen = 65536,
  92298. .mode = 0644,
  92299. .proc_handler = proc_do_large_bitmap,
  92300. @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
  92301. static __net_init int ipv4_sysctl_init_net(struct net *net)
  92302. {
  92303. - struct ctl_table *table;
  92304. + ctl_table_no_const *table = NULL;
  92305. - table = ipv4_net_table;
  92306. if (!net_eq(net, &init_net)) {
  92307. int i;
  92308. - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
  92309. + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
  92310. if (table == NULL)
  92311. goto err_alloc;
  92312. @@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
  92313. net->ipv4.sysctl_local_ports.range[0] = 32768;
  92314. net->ipv4.sysctl_local_ports.range[1] = 61000;
  92315. - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
  92316. + if (!net_eq(net, &init_net))
  92317. + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
  92318. + else
  92319. + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
  92320. if (net->ipv4.ipv4_hdr == NULL)
  92321. goto err_reg;
  92322. return 0;
  92323. err_reg:
  92324. - if (!net_eq(net, &init_net))
  92325. - kfree(table);
  92326. + kfree(table);
  92327. err_alloc:
  92328. return -ENOMEM;
  92329. }
  92330. @@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
  92331. static __init int sysctl_ipv4_init(void)
  92332. {
  92333. struct ctl_table_header *hdr;
  92334. - struct ctl_table *i;
  92335. -
  92336. - for (i = ipv4_table; i->procname; i++) {
  92337. - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
  92338. - i->data = sysctl_local_reserved_ports;
  92339. - break;
  92340. - }
  92341. - }
  92342. - if (!i->procname)
  92343. - return -EINVAL;
  92344. hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
  92345. if (hdr == NULL)
  92346. diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
  92347. index eeaac39..dc29942 100644
  92348. --- a/net/ipv4/tcp_input.c
  92349. +++ b/net/ipv4/tcp_input.c
  92350. @@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
  92351. * without any lock. We want to make sure compiler wont store
  92352. * intermediate values in this location.
  92353. */
  92354. - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
  92355. + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
  92356. sk->sk_max_pacing_rate);
  92357. }
  92358. @@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
  92359. * simplifies code)
  92360. */
  92361. static void
  92362. -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
  92363. +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
  92364. struct sk_buff *head, struct sk_buff *tail,
  92365. u32 start, u32 end)
  92366. {
  92367. @@ -5562,6 +5562,7 @@ discard:
  92368. tcp_paws_reject(&tp->rx_opt, 0))
  92369. goto discard_and_undo;
  92370. +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
  92371. if (th->syn) {
  92372. /* We see SYN without ACK. It is attempt of
  92373. * simultaneous connect with crossed SYNs.
  92374. @@ -5612,6 +5613,7 @@ discard:
  92375. goto discard;
  92376. #endif
  92377. }
  92378. +#endif
  92379. /* "fifth, if neither of the SYN or RST bits is set then
  92380. * drop the segment and return."
  92381. */
  92382. @@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
  92383. goto discard;
  92384. if (th->syn) {
  92385. - if (th->fin)
  92386. + if (th->fin || th->urg || th->psh)
  92387. goto discard;
  92388. if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
  92389. return 1;
  92390. diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
  92391. index 1e4eac7..a66fa4a 100644
  92392. --- a/net/ipv4/tcp_ipv4.c
  92393. +++ b/net/ipv4/tcp_ipv4.c
  92394. @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
  92395. EXPORT_SYMBOL(sysctl_tcp_low_latency);
  92396. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92397. +extern int grsec_enable_blackhole;
  92398. +#endif
  92399. +
  92400. #ifdef CONFIG_TCP_MD5SIG
  92401. static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
  92402. __be32 daddr, __be32 saddr, const struct tcphdr *th);
  92403. @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
  92404. return 0;
  92405. reset:
  92406. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92407. + if (!grsec_enable_blackhole)
  92408. +#endif
  92409. tcp_v4_send_reset(rsk, skb);
  92410. discard:
  92411. kfree_skb(skb);
  92412. @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
  92413. TCP_SKB_CB(skb)->sacked = 0;
  92414. sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
  92415. - if (!sk)
  92416. + if (!sk) {
  92417. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92418. + ret = 1;
  92419. +#endif
  92420. goto no_tcp_socket;
  92421. -
  92422. + }
  92423. process:
  92424. - if (sk->sk_state == TCP_TIME_WAIT)
  92425. + if (sk->sk_state == TCP_TIME_WAIT) {
  92426. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92427. + ret = 2;
  92428. +#endif
  92429. goto do_time_wait;
  92430. + }
  92431. if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
  92432. NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
  92433. @@ -2033,6 +2047,10 @@ csum_error:
  92434. bad_packet:
  92435. TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
  92436. } else {
  92437. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92438. + if (!grsec_enable_blackhole || (ret == 1 &&
  92439. + (skb->dev->flags & IFF_LOOPBACK)))
  92440. +#endif
  92441. tcp_v4_send_reset(NULL, skb);
  92442. }
  92443. diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
  92444. index 7a436c5..1b05c59 100644
  92445. --- a/net/ipv4/tcp_minisocks.c
  92446. +++ b/net/ipv4/tcp_minisocks.c
  92447. @@ -27,6 +27,10 @@
  92448. #include <net/inet_common.h>
  92449. #include <net/xfrm.h>
  92450. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92451. +extern int grsec_enable_blackhole;
  92452. +#endif
  92453. +
  92454. int sysctl_tcp_syncookies __read_mostly = 1;
  92455. EXPORT_SYMBOL(sysctl_tcp_syncookies);
  92456. @@ -709,7 +713,10 @@ embryonic_reset:
  92457. * avoid becoming vulnerable to outside attack aiming at
  92458. * resetting legit local connections.
  92459. */
  92460. - req->rsk_ops->send_reset(sk, skb);
  92461. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92462. + if (!grsec_enable_blackhole)
  92463. +#endif
  92464. + req->rsk_ops->send_reset(sk, skb);
  92465. } else if (fastopen) { /* received a valid RST pkt */
  92466. reqsk_fastopen_remove(sk, req, true);
  92467. tcp_reset(sk);
  92468. diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
  92469. index 1f2d376..01d18c4 100644
  92470. --- a/net/ipv4/tcp_probe.c
  92471. +++ b/net/ipv4/tcp_probe.c
  92472. @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
  92473. if (cnt + width >= len)
  92474. break;
  92475. - if (copy_to_user(buf + cnt, tbuf, width))
  92476. + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
  92477. return -EFAULT;
  92478. cnt += width;
  92479. }
  92480. diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
  92481. index 64f0354..a81b39d 100644
  92482. --- a/net/ipv4/tcp_timer.c
  92483. +++ b/net/ipv4/tcp_timer.c
  92484. @@ -22,6 +22,10 @@
  92485. #include <linux/gfp.h>
  92486. #include <net/tcp.h>
  92487. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92488. +extern int grsec_lastack_retries;
  92489. +#endif
  92490. +
  92491. int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
  92492. int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
  92493. int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
  92494. @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
  92495. }
  92496. }
  92497. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92498. + if ((sk->sk_state == TCP_LAST_ACK) &&
  92499. + (grsec_lastack_retries > 0) &&
  92500. + (grsec_lastack_retries < retry_until))
  92501. + retry_until = grsec_lastack_retries;
  92502. +#endif
  92503. +
  92504. if (retransmits_timed_out(sk, retry_until,
  92505. syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
  92506. /* Has it gone just too far? */
  92507. diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
  92508. index 77bd16f..5f7174a 100644
  92509. --- a/net/ipv4/udp.c
  92510. +++ b/net/ipv4/udp.c
  92511. @@ -87,6 +87,7 @@
  92512. #include <linux/types.h>
  92513. #include <linux/fcntl.h>
  92514. #include <linux/module.h>
  92515. +#include <linux/security.h>
  92516. #include <linux/socket.h>
  92517. #include <linux/sockios.h>
  92518. #include <linux/igmp.h>
  92519. @@ -113,6 +114,10 @@
  92520. #include <net/busy_poll.h>
  92521. #include "udp_impl.h"
  92522. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92523. +extern int grsec_enable_blackhole;
  92524. +#endif
  92525. +
  92526. struct udp_table udp_table __read_mostly;
  92527. EXPORT_SYMBOL(udp_table);
  92528. @@ -615,6 +620,9 @@ found:
  92529. return s;
  92530. }
  92531. +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
  92532. +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
  92533. +
  92534. /*
  92535. * This routine is called by the ICMP module when it gets some
  92536. * sort of error condition. If err < 0 then the socket should
  92537. @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92538. dport = usin->sin_port;
  92539. if (dport == 0)
  92540. return -EINVAL;
  92541. +
  92542. + err = gr_search_udp_sendmsg(sk, usin);
  92543. + if (err)
  92544. + return err;
  92545. } else {
  92546. if (sk->sk_state != TCP_ESTABLISHED)
  92547. return -EDESTADDRREQ;
  92548. +
  92549. + err = gr_search_udp_sendmsg(sk, NULL);
  92550. + if (err)
  92551. + return err;
  92552. +
  92553. daddr = inet->inet_daddr;
  92554. dport = inet->inet_dport;
  92555. /* Open fast path for connected socket.
  92556. @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
  92557. IS_UDPLITE(sk));
  92558. UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
  92559. IS_UDPLITE(sk));
  92560. - atomic_inc(&sk->sk_drops);
  92561. + atomic_inc_unchecked(&sk->sk_drops);
  92562. __skb_unlink(skb, rcvq);
  92563. __skb_queue_tail(&list_kill, skb);
  92564. }
  92565. @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
  92566. int is_udplite = IS_UDPLITE(sk);
  92567. bool slow;
  92568. + /*
  92569. + * Check any passed addresses
  92570. + */
  92571. + if (addr_len)
  92572. + *addr_len = sizeof(*sin);
  92573. +
  92574. if (flags & MSG_ERRQUEUE)
  92575. return ip_recv_error(sk, msg, len, addr_len);
  92576. @@ -1243,6 +1266,10 @@ try_again:
  92577. if (!skb)
  92578. goto out;
  92579. + err = gr_search_udp_recvmsg(sk, skb);
  92580. + if (err)
  92581. + goto out_free;
  92582. +
  92583. ulen = skb->len - sizeof(struct udphdr);
  92584. copied = len;
  92585. if (copied > ulen)
  92586. @@ -1276,7 +1303,7 @@ try_again:
  92587. if (unlikely(err)) {
  92588. trace_kfree_skb(skb, udp_recvmsg);
  92589. if (!peeked) {
  92590. - atomic_inc(&sk->sk_drops);
  92591. + atomic_inc_unchecked(&sk->sk_drops);
  92592. UDP_INC_STATS_USER(sock_net(sk),
  92593. UDP_MIB_INERRORS, is_udplite);
  92594. }
  92595. @@ -1295,7 +1322,6 @@ try_again:
  92596. sin->sin_port = udp_hdr(skb)->source;
  92597. sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
  92598. memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
  92599. - *addr_len = sizeof(*sin);
  92600. }
  92601. if (inet->cmsg_flags)
  92602. ip_cmsg_recv(msg, skb);
  92603. @@ -1566,7 +1592,7 @@ csum_error:
  92604. UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
  92605. drop:
  92606. UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
  92607. - atomic_inc(&sk->sk_drops);
  92608. + atomic_inc_unchecked(&sk->sk_drops);
  92609. kfree_skb(skb);
  92610. return -1;
  92611. }
  92612. @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
  92613. skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
  92614. if (!skb1) {
  92615. - atomic_inc(&sk->sk_drops);
  92616. + atomic_inc_unchecked(&sk->sk_drops);
  92617. UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
  92618. IS_UDPLITE(sk));
  92619. UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
  92620. @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
  92621. goto csum_error;
  92622. UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
  92623. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  92624. + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
  92625. +#endif
  92626. icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
  92627. /*
  92628. @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
  92629. from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
  92630. 0, sock_i_ino(sp),
  92631. atomic_read(&sp->sk_refcnt), sp,
  92632. - atomic_read(&sp->sk_drops));
  92633. + atomic_read_unchecked(&sp->sk_drops));
  92634. }
  92635. int udp4_seq_show(struct seq_file *seq, void *v)
  92636. diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
  92637. index e1a6393..f634ce5 100644
  92638. --- a/net/ipv4/xfrm4_policy.c
  92639. +++ b/net/ipv4/xfrm4_policy.c
  92640. @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
  92641. fl4->flowi4_tos = iph->tos;
  92642. }
  92643. -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
  92644. +static int xfrm4_garbage_collect(struct dst_ops *ops)
  92645. {
  92646. struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
  92647. - xfrm4_policy_afinfo.garbage_collect(net);
  92648. + xfrm_garbage_collect_deferred(net);
  92649. return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
  92650. }
  92651. @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
  92652. static int __net_init xfrm4_net_init(struct net *net)
  92653. {
  92654. - struct ctl_table *table;
  92655. + ctl_table_no_const *table = NULL;
  92656. struct ctl_table_header *hdr;
  92657. - table = xfrm4_policy_table;
  92658. if (!net_eq(net, &init_net)) {
  92659. - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
  92660. + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
  92661. if (!table)
  92662. goto err_alloc;
  92663. table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
  92664. - }
  92665. -
  92666. - hdr = register_net_sysctl(net, "net/ipv4", table);
  92667. + hdr = register_net_sysctl(net, "net/ipv4", table);
  92668. + } else
  92669. + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
  92670. if (!hdr)
  92671. goto err_reg;
  92672. @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
  92673. return 0;
  92674. err_reg:
  92675. - if (!net_eq(net, &init_net))
  92676. - kfree(table);
  92677. + kfree(table);
  92678. err_alloc:
  92679. return -ENOMEM;
  92680. }
  92681. diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
  92682. index 6c7fa08..285086c 100644
  92683. --- a/net/ipv6/addrconf.c
  92684. +++ b/net/ipv6/addrconf.c
  92685. @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
  92686. idx = 0;
  92687. head = &net->dev_index_head[h];
  92688. rcu_read_lock();
  92689. - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
  92690. + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
  92691. net->dev_base_seq;
  92692. hlist_for_each_entry_rcu(dev, head, index_hlist) {
  92693. if (idx < s_idx)
  92694. @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
  92695. p.iph.ihl = 5;
  92696. p.iph.protocol = IPPROTO_IPV6;
  92697. p.iph.ttl = 64;
  92698. - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
  92699. + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
  92700. if (ops->ndo_do_ioctl) {
  92701. mm_segment_t oldfs = get_fs();
  92702. @@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
  92703. s_ip_idx = ip_idx = cb->args[2];
  92704. rcu_read_lock();
  92705. - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
  92706. + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
  92707. for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
  92708. idx = 0;
  92709. head = &net->dev_index_head[h];
  92710. @@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
  92711. dst_free(&ifp->rt->dst);
  92712. break;
  92713. }
  92714. - atomic_inc(&net->ipv6.dev_addr_genid);
  92715. + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
  92716. rt_genid_bump_ipv6(net);
  92717. }
  92718. @@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
  92719. int *valp = ctl->data;
  92720. int val = *valp;
  92721. loff_t pos = *ppos;
  92722. - struct ctl_table lctl;
  92723. + ctl_table_no_const lctl;
  92724. int ret;
  92725. /*
  92726. @@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
  92727. int *valp = ctl->data;
  92728. int val = *valp;
  92729. loff_t pos = *ppos;
  92730. - struct ctl_table lctl;
  92731. + ctl_table_no_const lctl;
  92732. int ret;
  92733. /*
  92734. diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
  92735. index d935889..2f64330 100644
  92736. --- a/net/ipv6/af_inet6.c
  92737. +++ b/net/ipv6/af_inet6.c
  92738. @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
  92739. net->ipv6.sysctl.bindv6only = 0;
  92740. net->ipv6.sysctl.icmpv6_time = 1*HZ;
  92741. net->ipv6.sysctl.flowlabel_consistency = 1;
  92742. - atomic_set(&net->ipv6.rt_genid, 0);
  92743. + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
  92744. err = ipv6_init_mibs(net);
  92745. if (err)
  92746. diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
  92747. index c3bf2d2..1f00573 100644
  92748. --- a/net/ipv6/datagram.c
  92749. +++ b/net/ipv6/datagram.c
  92750. @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
  92751. 0,
  92752. sock_i_ino(sp),
  92753. atomic_read(&sp->sk_refcnt), sp,
  92754. - atomic_read(&sp->sk_drops));
  92755. + atomic_read_unchecked(&sp->sk_drops));
  92756. }
  92757. diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
  92758. index 7b32652..0bc348b 100644
  92759. --- a/net/ipv6/icmp.c
  92760. +++ b/net/ipv6/icmp.c
  92761. @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
  92762. struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
  92763. {
  92764. - struct ctl_table *table;
  92765. + ctl_table_no_const *table;
  92766. table = kmemdup(ipv6_icmp_table_template,
  92767. sizeof(ipv6_icmp_table_template),
  92768. diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
  92769. index f3ffb43..1172ba7 100644
  92770. --- a/net/ipv6/ip6_gre.c
  92771. +++ b/net/ipv6/ip6_gre.c
  92772. @@ -71,7 +71,7 @@ struct ip6gre_net {
  92773. struct net_device *fb_tunnel_dev;
  92774. };
  92775. -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
  92776. +static struct rtnl_link_ops ip6gre_link_ops;
  92777. static int ip6gre_tunnel_init(struct net_device *dev);
  92778. static void ip6gre_tunnel_setup(struct net_device *dev);
  92779. static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
  92780. @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
  92781. }
  92782. -static struct inet6_protocol ip6gre_protocol __read_mostly = {
  92783. +static struct inet6_protocol ip6gre_protocol = {
  92784. .handler = ip6gre_rcv,
  92785. .err_handler = ip6gre_err,
  92786. .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
  92787. @@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
  92788. [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
  92789. };
  92790. -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
  92791. +static struct rtnl_link_ops ip6gre_link_ops = {
  92792. .kind = "ip6gre",
  92793. .maxtype = IFLA_GRE_MAX,
  92794. .policy = ip6gre_policy,
  92795. @@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
  92796. .fill_info = ip6gre_fill_info,
  92797. };
  92798. -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
  92799. +static struct rtnl_link_ops ip6gre_tap_ops = {
  92800. .kind = "ip6gretap",
  92801. .maxtype = IFLA_GRE_MAX,
  92802. .policy = ip6gre_policy,
  92803. diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
  92804. index 5db8d31..4a72c26 100644
  92805. --- a/net/ipv6/ip6_tunnel.c
  92806. +++ b/net/ipv6/ip6_tunnel.c
  92807. @@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
  92808. static int ip6_tnl_dev_init(struct net_device *dev);
  92809. static void ip6_tnl_dev_setup(struct net_device *dev);
  92810. -static struct rtnl_link_ops ip6_link_ops __read_mostly;
  92811. +static struct rtnl_link_ops ip6_link_ops;
  92812. static int ip6_tnl_net_id __read_mostly;
  92813. struct ip6_tnl_net {
  92814. @@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
  92815. [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
  92816. };
  92817. -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
  92818. +static struct rtnl_link_ops ip6_link_ops = {
  92819. .kind = "ip6tnl",
  92820. .maxtype = IFLA_IPTUN_MAX,
  92821. .policy = ip6_tnl_policy,
  92822. diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
  92823. index 2d19272..3a46322 100644
  92824. --- a/net/ipv6/ip6_vti.c
  92825. +++ b/net/ipv6/ip6_vti.c
  92826. @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
  92827. static int vti6_dev_init(struct net_device *dev);
  92828. static void vti6_dev_setup(struct net_device *dev);
  92829. -static struct rtnl_link_ops vti6_link_ops __read_mostly;
  92830. +static struct rtnl_link_ops vti6_link_ops;
  92831. static int vti6_net_id __read_mostly;
  92832. struct vti6_net {
  92833. @@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
  92834. [IFLA_VTI_OKEY] = { .type = NLA_U32 },
  92835. };
  92836. -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
  92837. +static struct rtnl_link_ops vti6_link_ops = {
  92838. .kind = "vti6",
  92839. .maxtype = IFLA_VTI_MAX,
  92840. .policy = vti6_policy,
  92841. diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
  92842. index 0a00f44..bec42b2 100644
  92843. --- a/net/ipv6/ipv6_sockglue.c
  92844. +++ b/net/ipv6/ipv6_sockglue.c
  92845. @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
  92846. if (sk->sk_type != SOCK_STREAM)
  92847. return -ENOPROTOOPT;
  92848. - msg.msg_control = optval;
  92849. + msg.msg_control = (void __force_kernel *)optval;
  92850. msg.msg_controllen = len;
  92851. msg.msg_flags = flags;
  92852. diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
  92853. index 710238f..0fd1816 100644
  92854. --- a/net/ipv6/netfilter/ip6_tables.c
  92855. +++ b/net/ipv6/netfilter/ip6_tables.c
  92856. @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
  92857. #endif
  92858. static int get_info(struct net *net, void __user *user,
  92859. - const int *len, int compat)
  92860. + int len, int compat)
  92861. {
  92862. char name[XT_TABLE_MAXNAMELEN];
  92863. struct xt_table *t;
  92864. int ret;
  92865. - if (*len != sizeof(struct ip6t_getinfo)) {
  92866. - duprintf("length %u != %zu\n", *len,
  92867. + if (len != sizeof(struct ip6t_getinfo)) {
  92868. + duprintf("length %u != %zu\n", len,
  92869. sizeof(struct ip6t_getinfo));
  92870. return -EINVAL;
  92871. }
  92872. @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
  92873. info.size = private->size;
  92874. strcpy(info.name, name);
  92875. - if (copy_to_user(user, &info, *len) != 0)
  92876. + if (copy_to_user(user, &info, len) != 0)
  92877. ret = -EFAULT;
  92878. else
  92879. ret = 0;
  92880. @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
  92881. switch (cmd) {
  92882. case IP6T_SO_GET_INFO:
  92883. - ret = get_info(sock_net(sk), user, len, 1);
  92884. + ret = get_info(sock_net(sk), user, *len, 1);
  92885. break;
  92886. case IP6T_SO_GET_ENTRIES:
  92887. ret = compat_get_entries(sock_net(sk), user, len);
  92888. @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
  92889. switch (cmd) {
  92890. case IP6T_SO_GET_INFO:
  92891. - ret = get_info(sock_net(sk), user, len, 0);
  92892. + ret = get_info(sock_net(sk), user, *len, 0);
  92893. break;
  92894. case IP6T_SO_GET_ENTRIES:
  92895. diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
  92896. index 767ab8d..c5ec70a 100644
  92897. --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
  92898. +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
  92899. @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
  92900. static int nf_ct_frag6_sysctl_register(struct net *net)
  92901. {
  92902. - struct ctl_table *table;
  92903. + ctl_table_no_const *table = NULL;
  92904. struct ctl_table_header *hdr;
  92905. - table = nf_ct_frag6_sysctl_table;
  92906. if (!net_eq(net, &init_net)) {
  92907. - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
  92908. + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
  92909. GFP_KERNEL);
  92910. if (table == NULL)
  92911. goto err_alloc;
  92912. @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
  92913. table[0].data = &net->nf_frag.frags.timeout;
  92914. table[1].data = &net->nf_frag.frags.low_thresh;
  92915. table[2].data = &net->nf_frag.frags.high_thresh;
  92916. - }
  92917. -
  92918. - hdr = register_net_sysctl(net, "net/netfilter", table);
  92919. + hdr = register_net_sysctl(net, "net/netfilter", table);
  92920. + } else
  92921. + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
  92922. if (hdr == NULL)
  92923. goto err_reg;
  92924. @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
  92925. return 0;
  92926. err_reg:
  92927. - if (!net_eq(net, &init_net))
  92928. - kfree(table);
  92929. + kfree(table);
  92930. err_alloc:
  92931. return -ENOMEM;
  92932. }
  92933. diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
  92934. index 827f795..7e28e82 100644
  92935. --- a/net/ipv6/output_core.c
  92936. +++ b/net/ipv6/output_core.c
  92937. @@ -9,8 +9,8 @@
  92938. void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
  92939. {
  92940. - static atomic_t ipv6_fragmentation_id;
  92941. - int old, new;
  92942. + static atomic_unchecked_t ipv6_fragmentation_id;
  92943. + int id;
  92944. #if IS_ENABLED(CONFIG_IPV6)
  92945. if (rt && !(rt->dst.flags & DST_NOPEER)) {
  92946. @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
  92947. }
  92948. }
  92949. #endif
  92950. - do {
  92951. - old = atomic_read(&ipv6_fragmentation_id);
  92952. - new = old + 1;
  92953. - if (!new)
  92954. - new = 1;
  92955. - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
  92956. - fhdr->identification = htonl(new);
  92957. + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
  92958. + if (!id)
  92959. + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
  92960. + fhdr->identification = htonl(id);
  92961. }
  92962. EXPORT_SYMBOL(ipv6_select_ident);
  92963. diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
  92964. index bda7429..469b26b 100644
  92965. --- a/net/ipv6/ping.c
  92966. +++ b/net/ipv6/ping.c
  92967. @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
  92968. };
  92969. #endif
  92970. +static struct pingv6_ops real_pingv6_ops = {
  92971. + .ipv6_recv_error = ipv6_recv_error,
  92972. + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
  92973. + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
  92974. + .icmpv6_err_convert = icmpv6_err_convert,
  92975. + .ipv6_icmp_error = ipv6_icmp_error,
  92976. + .ipv6_chk_addr = ipv6_chk_addr,
  92977. +};
  92978. +
  92979. +static struct pingv6_ops dummy_pingv6_ops = {
  92980. + .ipv6_recv_error = dummy_ipv6_recv_error,
  92981. + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
  92982. + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
  92983. + .icmpv6_err_convert = dummy_icmpv6_err_convert,
  92984. + .ipv6_icmp_error = dummy_ipv6_icmp_error,
  92985. + .ipv6_chk_addr = dummy_ipv6_chk_addr,
  92986. +};
  92987. +
  92988. int __init pingv6_init(void)
  92989. {
  92990. #ifdef CONFIG_PROC_FS
  92991. @@ -253,13 +271,7 @@ int __init pingv6_init(void)
  92992. if (ret)
  92993. return ret;
  92994. #endif
  92995. - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
  92996. - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
  92997. - pingv6_ops.ip6_datagram_recv_specific_ctl =
  92998. - ip6_datagram_recv_specific_ctl;
  92999. - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
  93000. - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
  93001. - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
  93002. + pingv6_ops = &real_pingv6_ops;
  93003. return inet6_register_protosw(&pingv6_protosw);
  93004. }
  93005. @@ -268,14 +280,9 @@ int __init pingv6_init(void)
  93006. */
  93007. void pingv6_exit(void)
  93008. {
  93009. - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
  93010. - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
  93011. - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
  93012. - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
  93013. - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
  93014. - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
  93015. #ifdef CONFIG_PROC_FS
  93016. unregister_pernet_subsys(&ping_v6_net_ops);
  93017. #endif
  93018. + pingv6_ops = &dummy_pingv6_ops;
  93019. inet6_unregister_protosw(&pingv6_protosw);
  93020. }
  93021. diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
  93022. index 091d066..139d410 100644
  93023. --- a/net/ipv6/proc.c
  93024. +++ b/net/ipv6/proc.c
  93025. @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
  93026. if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
  93027. goto proc_snmp6_fail;
  93028. - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
  93029. + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
  93030. if (!net->mib.proc_net_devsnmp6)
  93031. goto proc_dev_snmp6_fail;
  93032. return 0;
  93033. diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
  93034. index 1f29996..46fe0c7 100644
  93035. --- a/net/ipv6/raw.c
  93036. +++ b/net/ipv6/raw.c
  93037. @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
  93038. {
  93039. if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
  93040. skb_checksum_complete(skb)) {
  93041. - atomic_inc(&sk->sk_drops);
  93042. + atomic_inc_unchecked(&sk->sk_drops);
  93043. kfree_skb(skb);
  93044. return NET_RX_DROP;
  93045. }
  93046. @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
  93047. struct raw6_sock *rp = raw6_sk(sk);
  93048. if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
  93049. - atomic_inc(&sk->sk_drops);
  93050. + atomic_inc_unchecked(&sk->sk_drops);
  93051. kfree_skb(skb);
  93052. return NET_RX_DROP;
  93053. }
  93054. @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
  93055. if (inet->hdrincl) {
  93056. if (skb_checksum_complete(skb)) {
  93057. - atomic_inc(&sk->sk_drops);
  93058. + atomic_inc_unchecked(&sk->sk_drops);
  93059. kfree_skb(skb);
  93060. return NET_RX_DROP;
  93061. }
  93062. @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
  93063. if (flags & MSG_OOB)
  93064. return -EOPNOTSUPP;
  93065. + if (addr_len)
  93066. + *addr_len=sizeof(*sin6);
  93067. +
  93068. if (flags & MSG_ERRQUEUE)
  93069. return ipv6_recv_error(sk, msg, len, addr_len);
  93070. @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
  93071. sin6->sin6_flowinfo = 0;
  93072. sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
  93073. IP6CB(skb)->iif);
  93074. - *addr_len = sizeof(*sin6);
  93075. }
  93076. sock_recv_ts_and_drops(msg, sk, skb);
  93077. @@ -610,7 +612,7 @@ out:
  93078. return err;
  93079. }
  93080. -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
  93081. +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
  93082. struct flowi6 *fl6, struct dst_entry **dstp,
  93083. unsigned int flags)
  93084. {
  93085. @@ -922,12 +924,15 @@ do_confirm:
  93086. static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
  93087. char __user *optval, int optlen)
  93088. {
  93089. + struct icmp6_filter filter;
  93090. +
  93091. switch (optname) {
  93092. case ICMPV6_FILTER:
  93093. if (optlen > sizeof(struct icmp6_filter))
  93094. optlen = sizeof(struct icmp6_filter);
  93095. - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
  93096. + if (copy_from_user(&filter, optval, optlen))
  93097. return -EFAULT;
  93098. + raw6_sk(sk)->filter = filter;
  93099. return 0;
  93100. default:
  93101. return -ENOPROTOOPT;
  93102. @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
  93103. char __user *optval, int __user *optlen)
  93104. {
  93105. int len;
  93106. + struct icmp6_filter filter;
  93107. switch (optname) {
  93108. case ICMPV6_FILTER:
  93109. @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
  93110. len = sizeof(struct icmp6_filter);
  93111. if (put_user(len, optlen))
  93112. return -EFAULT;
  93113. - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
  93114. + filter = raw6_sk(sk)->filter;
  93115. + if (len > sizeof filter || copy_to_user(optval, &filter, len))
  93116. return -EFAULT;
  93117. return 0;
  93118. default:
  93119. diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
  93120. index cc85a9b..526a133 100644
  93121. --- a/net/ipv6/reassembly.c
  93122. +++ b/net/ipv6/reassembly.c
  93123. @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
  93124. static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
  93125. {
  93126. - struct ctl_table *table;
  93127. + ctl_table_no_const *table = NULL;
  93128. struct ctl_table_header *hdr;
  93129. - table = ip6_frags_ns_ctl_table;
  93130. if (!net_eq(net, &init_net)) {
  93131. - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
  93132. + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
  93133. if (table == NULL)
  93134. goto err_alloc;
  93135. @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
  93136. /* Don't export sysctls to unprivileged users */
  93137. if (net->user_ns != &init_user_ns)
  93138. table[0].procname = NULL;
  93139. - }
  93140. + hdr = register_net_sysctl(net, "net/ipv6", table);
  93141. + } else
  93142. + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
  93143. - hdr = register_net_sysctl(net, "net/ipv6", table);
  93144. if (hdr == NULL)
  93145. goto err_reg;
  93146. @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
  93147. return 0;
  93148. err_reg:
  93149. - if (!net_eq(net, &init_net))
  93150. - kfree(table);
  93151. + kfree(table);
  93152. err_alloc:
  93153. return -ENOMEM;
  93154. }
  93155. diff --git a/net/ipv6/route.c b/net/ipv6/route.c
  93156. index fba54a4..73e374e 100644
  93157. --- a/net/ipv6/route.c
  93158. +++ b/net/ipv6/route.c
  93159. @@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
  93160. struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
  93161. {
  93162. - struct ctl_table *table;
  93163. + ctl_table_no_const *table;
  93164. table = kmemdup(ipv6_route_table_template,
  93165. sizeof(ipv6_route_table_template),
  93166. diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
  93167. index b4d74c8..b4f3fbe 100644
  93168. --- a/net/ipv6/sit.c
  93169. +++ b/net/ipv6/sit.c
  93170. @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
  93171. static void ipip6_dev_free(struct net_device *dev);
  93172. static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
  93173. __be32 *v4dst);
  93174. -static struct rtnl_link_ops sit_link_ops __read_mostly;
  93175. +static struct rtnl_link_ops sit_link_ops;
  93176. static int sit_net_id __read_mostly;
  93177. struct sit_net {
  93178. @@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
  93179. unregister_netdevice_queue(dev, head);
  93180. }
  93181. -static struct rtnl_link_ops sit_link_ops __read_mostly = {
  93182. +static struct rtnl_link_ops sit_link_ops = {
  93183. .kind = "sit",
  93184. .maxtype = IFLA_IPTUN_MAX,
  93185. .policy = ipip6_policy,
  93186. diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
  93187. index 7f405a1..eabef92 100644
  93188. --- a/net/ipv6/sysctl_net_ipv6.c
  93189. +++ b/net/ipv6/sysctl_net_ipv6.c
  93190. @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
  93191. static int __net_init ipv6_sysctl_net_init(struct net *net)
  93192. {
  93193. - struct ctl_table *ipv6_table;
  93194. + ctl_table_no_const *ipv6_table;
  93195. struct ctl_table *ipv6_route_table;
  93196. struct ctl_table *ipv6_icmp_table;
  93197. int err;
  93198. diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
  93199. index 889079b..a04512c 100644
  93200. --- a/net/ipv6/tcp_ipv6.c
  93201. +++ b/net/ipv6/tcp_ipv6.c
  93202. @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
  93203. inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
  93204. }
  93205. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93206. +extern int grsec_enable_blackhole;
  93207. +#endif
  93208. +
  93209. static void tcp_v6_hash(struct sock *sk)
  93210. {
  93211. if (sk->sk_state != TCP_CLOSE) {
  93212. @@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
  93213. return 0;
  93214. reset:
  93215. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93216. + if (!grsec_enable_blackhole)
  93217. +#endif
  93218. tcp_v6_send_reset(sk, skb);
  93219. discard:
  93220. if (opt_skb)
  93221. @@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
  93222. TCP_SKB_CB(skb)->sacked = 0;
  93223. sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
  93224. - if (!sk)
  93225. + if (!sk) {
  93226. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93227. + ret = 1;
  93228. +#endif
  93229. goto no_tcp_socket;
  93230. + }
  93231. process:
  93232. - if (sk->sk_state == TCP_TIME_WAIT)
  93233. + if (sk->sk_state == TCP_TIME_WAIT) {
  93234. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93235. + ret = 2;
  93236. +#endif
  93237. goto do_time_wait;
  93238. + }
  93239. if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
  93240. NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
  93241. @@ -1553,6 +1568,10 @@ csum_error:
  93242. bad_packet:
  93243. TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
  93244. } else {
  93245. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93246. + if (!grsec_enable_blackhole || (ret == 1 &&
  93247. + (skb->dev->flags & IFF_LOOPBACK)))
  93248. +#endif
  93249. tcp_v6_send_reset(NULL, skb);
  93250. }
  93251. diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
  93252. index 1e586d9..384a9c9 100644
  93253. --- a/net/ipv6/udp.c
  93254. +++ b/net/ipv6/udp.c
  93255. @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
  93256. udp_ipv6_hash_secret + net_hash_mix(net));
  93257. }
  93258. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93259. +extern int grsec_enable_blackhole;
  93260. +#endif
  93261. +
  93262. int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
  93263. {
  93264. const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
  93265. @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
  93266. int is_udp4;
  93267. bool slow;
  93268. + if (addr_len)
  93269. + *addr_len = sizeof(struct sockaddr_in6);
  93270. +
  93271. if (flags & MSG_ERRQUEUE)
  93272. return ipv6_recv_error(sk, msg, len, addr_len);
  93273. @@ -435,7 +442,7 @@ try_again:
  93274. if (unlikely(err)) {
  93275. trace_kfree_skb(skb, udpv6_recvmsg);
  93276. if (!peeked) {
  93277. - atomic_inc(&sk->sk_drops);
  93278. + atomic_inc_unchecked(&sk->sk_drops);
  93279. if (is_udp4)
  93280. UDP_INC_STATS_USER(sock_net(sk),
  93281. UDP_MIB_INERRORS,
  93282. @@ -475,7 +482,7 @@ try_again:
  93283. ipv6_iface_scope_id(&sin6->sin6_addr,
  93284. IP6CB(skb)->iif);
  93285. }
  93286. - *addr_len = sizeof(*sin6);
  93287. +
  93288. }
  93289. if (np->rxopt.all)
  93290. @@ -690,7 +697,7 @@ csum_error:
  93291. UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
  93292. drop:
  93293. UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
  93294. - atomic_inc(&sk->sk_drops);
  93295. + atomic_inc_unchecked(&sk->sk_drops);
  93296. kfree_skb(skb);
  93297. return -1;
  93298. }
  93299. @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
  93300. if (likely(skb1 == NULL))
  93301. skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
  93302. if (!skb1) {
  93303. - atomic_inc(&sk->sk_drops);
  93304. + atomic_inc_unchecked(&sk->sk_drops);
  93305. UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
  93306. IS_UDPLITE(sk));
  93307. UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
  93308. @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
  93309. goto csum_error;
  93310. UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
  93311. +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
  93312. + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
  93313. +#endif
  93314. icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
  93315. kfree_skb(skb);
  93316. diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
  93317. index 5f8e128..865d38e 100644
  93318. --- a/net/ipv6/xfrm6_policy.c
  93319. +++ b/net/ipv6/xfrm6_policy.c
  93320. @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
  93321. }
  93322. }
  93323. -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
  93324. +static int xfrm6_garbage_collect(struct dst_ops *ops)
  93325. {
  93326. struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
  93327. - xfrm6_policy_afinfo.garbage_collect(net);
  93328. + xfrm_garbage_collect_deferred(net);
  93329. return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
  93330. }
  93331. @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
  93332. static int __net_init xfrm6_net_init(struct net *net)
  93333. {
  93334. - struct ctl_table *table;
  93335. + ctl_table_no_const *table = NULL;
  93336. struct ctl_table_header *hdr;
  93337. - table = xfrm6_policy_table;
  93338. if (!net_eq(net, &init_net)) {
  93339. - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
  93340. + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
  93341. if (!table)
  93342. goto err_alloc;
  93343. table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
  93344. - }
  93345. + hdr = register_net_sysctl(net, "net/ipv6", table);
  93346. + } else
  93347. + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
  93348. - hdr = register_net_sysctl(net, "net/ipv6", table);
  93349. if (!hdr)
  93350. goto err_reg;
  93351. @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
  93352. return 0;
  93353. err_reg:
  93354. - if (!net_eq(net, &init_net))
  93355. - kfree(table);
  93356. + kfree(table);
  93357. err_alloc:
  93358. return -ENOMEM;
  93359. }
  93360. diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
  93361. index e15c16a..7cf07aa 100644
  93362. --- a/net/ipx/ipx_proc.c
  93363. +++ b/net/ipx/ipx_proc.c
  93364. @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
  93365. struct proc_dir_entry *p;
  93366. int rc = -ENOMEM;
  93367. - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
  93368. + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
  93369. if (!ipx_proc_dir)
  93370. goto out;
  93371. diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
  93372. index 2ba8b97..6d33010 100644
  93373. --- a/net/irda/ircomm/ircomm_tty.c
  93374. +++ b/net/irda/ircomm/ircomm_tty.c
  93375. @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
  93376. add_wait_queue(&port->open_wait, &wait);
  93377. IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
  93378. - __FILE__, __LINE__, tty->driver->name, port->count);
  93379. + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
  93380. spin_lock_irqsave(&port->lock, flags);
  93381. if (!tty_hung_up_p(filp))
  93382. - port->count--;
  93383. + atomic_dec(&port->count);
  93384. port->blocked_open++;
  93385. spin_unlock_irqrestore(&port->lock, flags);
  93386. @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
  93387. }
  93388. IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
  93389. - __FILE__, __LINE__, tty->driver->name, port->count);
  93390. + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
  93391. schedule();
  93392. }
  93393. @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
  93394. spin_lock_irqsave(&port->lock, flags);
  93395. if (!tty_hung_up_p(filp))
  93396. - port->count++;
  93397. + atomic_inc(&port->count);
  93398. port->blocked_open--;
  93399. spin_unlock_irqrestore(&port->lock, flags);
  93400. IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
  93401. - __FILE__, __LINE__, tty->driver->name, port->count);
  93402. + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
  93403. if (!retval)
  93404. port->flags |= ASYNC_NORMAL_ACTIVE;
  93405. @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
  93406. /* ++ is not atomic, so this should be protected - Jean II */
  93407. spin_lock_irqsave(&self->port.lock, flags);
  93408. - self->port.count++;
  93409. + atomic_inc(&self->port.count);
  93410. spin_unlock_irqrestore(&self->port.lock, flags);
  93411. tty_port_tty_set(&self->port, tty);
  93412. IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
  93413. - self->line, self->port.count);
  93414. + self->line, atomic_read(&self->port.count));
  93415. /* Not really used by us, but lets do it anyway */
  93416. self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  93417. @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
  93418. tty_kref_put(port->tty);
  93419. }
  93420. port->tty = NULL;
  93421. - port->count = 0;
  93422. + atomic_set(&port->count, 0);
  93423. spin_unlock_irqrestore(&port->lock, flags);
  93424. wake_up_interruptible(&port->open_wait);
  93425. @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
  93426. seq_putc(m, '\n');
  93427. seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
  93428. - seq_printf(m, "Open count: %d\n", self->port.count);
  93429. + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
  93430. seq_printf(m, "Max data size: %d\n", self->max_data_size);
  93431. seq_printf(m, "Max header size: %d\n", self->max_header_size);
  93432. diff --git a/net/irda/irproc.c b/net/irda/irproc.c
  93433. index b9ac598..f88cc56 100644
  93434. --- a/net/irda/irproc.c
  93435. +++ b/net/irda/irproc.c
  93436. @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
  93437. {
  93438. int i;
  93439. - proc_irda = proc_mkdir("irda", init_net.proc_net);
  93440. + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
  93441. if (proc_irda == NULL)
  93442. return;
  93443. diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
  93444. index c4b7218..3e83259 100644
  93445. --- a/net/iucv/af_iucv.c
  93446. +++ b/net/iucv/af_iucv.c
  93447. @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
  93448. write_lock_bh(&iucv_sk_list.lock);
  93449. - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
  93450. + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
  93451. while (__iucv_get_sock_by_name(name)) {
  93452. sprintf(name, "%08x",
  93453. - atomic_inc_return(&iucv_sk_list.autobind_name));
  93454. + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
  93455. }
  93456. write_unlock_bh(&iucv_sk_list.lock);
  93457. diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
  93458. index cd5b8ec..f205e6b 100644
  93459. --- a/net/iucv/iucv.c
  93460. +++ b/net/iucv/iucv.c
  93461. @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
  93462. return NOTIFY_OK;
  93463. }
  93464. -static struct notifier_block __refdata iucv_cpu_notifier = {
  93465. +static struct notifier_block iucv_cpu_notifier = {
  93466. .notifier_call = iucv_cpu_notify,
  93467. };
  93468. diff --git a/net/key/af_key.c b/net/key/af_key.c
  93469. index 7932697..a13d158 100644
  93470. --- a/net/key/af_key.c
  93471. +++ b/net/key/af_key.c
  93472. @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
  93473. static u32 get_acqseq(void)
  93474. {
  93475. u32 res;
  93476. - static atomic_t acqseq;
  93477. + static atomic_unchecked_t acqseq;
  93478. do {
  93479. - res = atomic_inc_return(&acqseq);
  93480. + res = atomic_inc_return_unchecked(&acqseq);
  93481. } while (!res);
  93482. return res;
  93483. }
  93484. diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
  93485. index 0b44d85..1a7f88b 100644
  93486. --- a/net/l2tp/l2tp_ip.c
  93487. +++ b/net/l2tp/l2tp_ip.c
  93488. @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
  93489. if (flags & MSG_OOB)
  93490. goto out;
  93491. + if (addr_len)
  93492. + *addr_len = sizeof(*sin);
  93493. +
  93494. skb = skb_recv_datagram(sk, flags, noblock, &err);
  93495. if (!skb)
  93496. goto out;
  93497. @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
  93498. sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
  93499. sin->sin_port = 0;
  93500. memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
  93501. - *addr_len = sizeof(*sin);
  93502. }
  93503. if (inet->cmsg_flags)
  93504. ip_cmsg_recv(msg, skb);
  93505. diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
  93506. index 1a3c7e0..80f8b0c 100644
  93507. --- a/net/llc/llc_proc.c
  93508. +++ b/net/llc/llc_proc.c
  93509. @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
  93510. int rc = -ENOMEM;
  93511. struct proc_dir_entry *p;
  93512. - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
  93513. + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
  93514. if (!llc_proc_dir)
  93515. goto out;
  93516. diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
  93517. index 453e974..b3a43a5 100644
  93518. --- a/net/mac80211/cfg.c
  93519. +++ b/net/mac80211/cfg.c
  93520. @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  93521. ret = ieee80211_vif_use_channel(sdata, chandef,
  93522. IEEE80211_CHANCTX_EXCLUSIVE);
  93523. }
  93524. - } else if (local->open_count == local->monitors) {
  93525. + } else if (local_read(&local->open_count) == local->monitors) {
  93526. local->_oper_chandef = *chandef;
  93527. ieee80211_hw_config(local, 0);
  93528. }
  93529. @@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  93530. else
  93531. local->probe_req_reg--;
  93532. - if (!local->open_count)
  93533. + if (!local_read(&local->open_count))
  93534. break;
  93535. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  93536. @@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  93537. if (chanctx_conf) {
  93538. *chandef = chanctx_conf->def;
  93539. ret = 0;
  93540. - } else if (local->open_count > 0 &&
  93541. - local->open_count == local->monitors &&
  93542. + } else if (local_read(&local->open_count) > 0 &&
  93543. + local_read(&local->open_count) == local->monitors &&
  93544. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  93545. if (local->use_chanctx)
  93546. *chandef = local->monitor_chandef;
  93547. diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
  93548. index 6bd4984..d8805c5 100644
  93549. --- a/net/mac80211/ieee80211_i.h
  93550. +++ b/net/mac80211/ieee80211_i.h
  93551. @@ -28,6 +28,7 @@
  93552. #include <net/ieee80211_radiotap.h>
  93553. #include <net/cfg80211.h>
  93554. #include <net/mac80211.h>
  93555. +#include <asm/local.h>
  93556. #include "key.h"
  93557. #include "sta_info.h"
  93558. #include "debug.h"
  93559. @@ -994,7 +995,7 @@ struct ieee80211_local {
  93560. /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
  93561. spinlock_t queue_stop_reason_lock;
  93562. - int open_count;
  93563. + local_t open_count;
  93564. int monitors, cooked_mntrs;
  93565. /* number of interfaces with corresponding FIF_ flags */
  93566. int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
  93567. diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
  93568. index ce1c443..6cd39e1 100644
  93569. --- a/net/mac80211/iface.c
  93570. +++ b/net/mac80211/iface.c
  93571. @@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
  93572. break;
  93573. }
  93574. - if (local->open_count == 0) {
  93575. + if (local_read(&local->open_count) == 0) {
  93576. res = drv_start(local);
  93577. if (res)
  93578. goto err_del_bss;
  93579. @@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
  93580. res = drv_add_interface(local, sdata);
  93581. if (res)
  93582. goto err_stop;
  93583. - } else if (local->monitors == 0 && local->open_count == 0) {
  93584. + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
  93585. res = ieee80211_add_virtual_monitor(local);
  93586. if (res)
  93587. goto err_stop;
  93588. @@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
  93589. atomic_inc(&local->iff_promiscs);
  93590. if (coming_up)
  93591. - local->open_count++;
  93592. + local_inc(&local->open_count);
  93593. if (hw_reconf_flags)
  93594. ieee80211_hw_config(local, hw_reconf_flags);
  93595. @@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
  93596. err_del_interface:
  93597. drv_remove_interface(local, sdata);
  93598. err_stop:
  93599. - if (!local->open_count)
  93600. + if (!local_read(&local->open_count))
  93601. drv_stop(local);
  93602. err_del_bss:
  93603. sdata->bss = NULL;
  93604. @@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
  93605. }
  93606. if (going_down)
  93607. - local->open_count--;
  93608. + local_dec(&local->open_count);
  93609. switch (sdata->vif.type) {
  93610. case NL80211_IFTYPE_AP_VLAN:
  93611. @@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
  93612. }
  93613. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  93614. - if (local->open_count == 0)
  93615. + if (local_read(&local->open_count) == 0)
  93616. ieee80211_clear_tx_pending(local);
  93617. /*
  93618. @@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
  93619. ieee80211_recalc_ps(local, -1);
  93620. - if (local->open_count == 0) {
  93621. + if (local_read(&local->open_count) == 0) {
  93622. ieee80211_stop_device(local);
  93623. /* no reconfiguring after stop! */
  93624. @@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
  93625. ieee80211_configure_filter(local);
  93626. ieee80211_hw_config(local, hw_reconf_flags);
  93627. - if (local->monitors == local->open_count)
  93628. + if (local->monitors == local_read(&local->open_count))
  93629. ieee80211_add_virtual_monitor(local);
  93630. }
  93631. diff --git a/net/mac80211/main.c b/net/mac80211/main.c
  93632. index c7a7a86..a74f57b 100644
  93633. --- a/net/mac80211/main.c
  93634. +++ b/net/mac80211/main.c
  93635. @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
  93636. changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
  93637. IEEE80211_CONF_CHANGE_POWER);
  93638. - if (changed && local->open_count) {
  93639. + if (changed && local_read(&local->open_count)) {
  93640. ret = drv_config(local, changed);
  93641. /*
  93642. * Goal:
  93643. diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
  93644. index d478b88..8c8d157 100644
  93645. --- a/net/mac80211/pm.c
  93646. +++ b/net/mac80211/pm.c
  93647. @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  93648. struct ieee80211_sub_if_data *sdata;
  93649. struct sta_info *sta;
  93650. - if (!local->open_count)
  93651. + if (!local_read(&local->open_count))
  93652. goto suspend;
  93653. ieee80211_scan_cancel(local);
  93654. @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  93655. cancel_work_sync(&local->dynamic_ps_enable_work);
  93656. del_timer_sync(&local->dynamic_ps_timer);
  93657. - local->wowlan = wowlan && local->open_count;
  93658. + local->wowlan = wowlan && local_read(&local->open_count);
  93659. if (local->wowlan) {
  93660. int err = drv_suspend(local, wowlan);
  93661. if (err < 0) {
  93662. @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  93663. WARN_ON(!list_empty(&local->chanctx_list));
  93664. /* stop hardware - this must stop RX */
  93665. - if (local->open_count)
  93666. + if (local_read(&local->open_count))
  93667. ieee80211_stop_device(local);
  93668. suspend:
  93669. diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
  93670. index 22b223f..ab70070 100644
  93671. --- a/net/mac80211/rate.c
  93672. +++ b/net/mac80211/rate.c
  93673. @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  93674. ASSERT_RTNL();
  93675. - if (local->open_count)
  93676. + if (local_read(&local->open_count))
  93677. return -EBUSY;
  93678. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  93679. diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
  93680. index 6ff1346..936ca9a 100644
  93681. --- a/net/mac80211/rc80211_pid_debugfs.c
  93682. +++ b/net/mac80211/rc80211_pid_debugfs.c
  93683. @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
  93684. spin_unlock_irqrestore(&events->lock, status);
  93685. - if (copy_to_user(buf, pb, p))
  93686. + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
  93687. return -EFAULT;
  93688. return p;
  93689. diff --git a/net/mac80211/util.c b/net/mac80211/util.c
  93690. index b8700d4..89086d5 100644
  93691. --- a/net/mac80211/util.c
  93692. +++ b/net/mac80211/util.c
  93693. @@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
  93694. }
  93695. #endif
  93696. /* everything else happens only if HW was up & running */
  93697. - if (!local->open_count)
  93698. + if (!local_read(&local->open_count))
  93699. goto wake_up;
  93700. /*
  93701. @@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
  93702. local->in_reconfig = false;
  93703. barrier();
  93704. - if (local->monitors == local->open_count && local->monitors > 0)
  93705. + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
  93706. ieee80211_add_virtual_monitor(local);
  93707. /*
  93708. diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
  93709. index e9410d1..77b6378 100644
  93710. --- a/net/netfilter/Kconfig
  93711. +++ b/net/netfilter/Kconfig
  93712. @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
  93713. To compile it as a module, choose M here. If unsure, say N.
  93714. +config NETFILTER_XT_MATCH_GRADM
  93715. + tristate '"gradm" match support'
  93716. + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
  93717. + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
  93718. + ---help---
  93719. + The gradm match allows to match on grsecurity RBAC being enabled.
  93720. + It is useful when iptables rules are applied early on bootup to
  93721. + prevent connections to the machine (except from a trusted host)
  93722. + while the RBAC system is disabled.
  93723. +
  93724. config NETFILTER_XT_MATCH_HASHLIMIT
  93725. tristate '"hashlimit" match support'
  93726. depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
  93727. diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
  93728. index bffdad7..f9317d1 100644
  93729. --- a/net/netfilter/Makefile
  93730. +++ b/net/netfilter/Makefile
  93731. @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
  93732. obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
  93733. obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
  93734. obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
  93735. +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
  93736. obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
  93737. obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
  93738. obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
  93739. diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
  93740. index de770ec..3fc49d2 100644
  93741. --- a/net/netfilter/ipset/ip_set_core.c
  93742. +++ b/net/netfilter/ipset/ip_set_core.c
  93743. @@ -1922,7 +1922,7 @@ done:
  93744. return ret;
  93745. }
  93746. -static struct nf_sockopt_ops so_set __read_mostly = {
  93747. +static struct nf_sockopt_ops so_set = {
  93748. .pf = PF_INET,
  93749. .get_optmin = SO_IP_SET,
  93750. .get_optmax = SO_IP_SET + 1,
  93751. diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
  93752. index a8eb0a8..86f2de4 100644
  93753. --- a/net/netfilter/ipvs/ip_vs_conn.c
  93754. +++ b/net/netfilter/ipvs/ip_vs_conn.c
  93755. @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
  93756. /* Increase the refcnt counter of the dest */
  93757. ip_vs_dest_hold(dest);
  93758. - conn_flags = atomic_read(&dest->conn_flags);
  93759. + conn_flags = atomic_read_unchecked(&dest->conn_flags);
  93760. if (cp->protocol != IPPROTO_UDP)
  93761. conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
  93762. flags = cp->flags;
  93763. @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
  93764. cp->control = NULL;
  93765. atomic_set(&cp->n_control, 0);
  93766. - atomic_set(&cp->in_pkts, 0);
  93767. + atomic_set_unchecked(&cp->in_pkts, 0);
  93768. cp->packet_xmit = NULL;
  93769. cp->app = NULL;
  93770. @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
  93771. /* Don't drop the entry if its number of incoming packets is not
  93772. located in [0, 8] */
  93773. - i = atomic_read(&cp->in_pkts);
  93774. + i = atomic_read_unchecked(&cp->in_pkts);
  93775. if (i > 8 || i < 0) return 0;
  93776. if (!todrop_rate[i]) return 0;
  93777. diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
  93778. index 4f26ee4..6a9d7c3 100644
  93779. --- a/net/netfilter/ipvs/ip_vs_core.c
  93780. +++ b/net/netfilter/ipvs/ip_vs_core.c
  93781. @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
  93782. ret = cp->packet_xmit(skb, cp, pd->pp, iph);
  93783. /* do not touch skb anymore */
  93784. - atomic_inc(&cp->in_pkts);
  93785. + atomic_inc_unchecked(&cp->in_pkts);
  93786. ip_vs_conn_put(cp);
  93787. return ret;
  93788. }
  93789. @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
  93790. if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
  93791. pkts = sysctl_sync_threshold(ipvs);
  93792. else
  93793. - pkts = atomic_add_return(1, &cp->in_pkts);
  93794. + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
  93795. if (ipvs->sync_state & IP_VS_STATE_MASTER)
  93796. ip_vs_sync_conn(net, cp, pkts);
  93797. diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
  93798. index 35be035..50f8834 100644
  93799. --- a/net/netfilter/ipvs/ip_vs_ctl.c
  93800. +++ b/net/netfilter/ipvs/ip_vs_ctl.c
  93801. @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
  93802. */
  93803. ip_vs_rs_hash(ipvs, dest);
  93804. }
  93805. - atomic_set(&dest->conn_flags, conn_flags);
  93806. + atomic_set_unchecked(&dest->conn_flags, conn_flags);
  93807. /* bind the service */
  93808. old_svc = rcu_dereference_protected(dest->svc, 1);
  93809. @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
  93810. * align with netns init in ip_vs_control_net_init()
  93811. */
  93812. -static struct ctl_table vs_vars[] = {
  93813. +static ctl_table_no_const vs_vars[] __read_only = {
  93814. {
  93815. .procname = "amemthresh",
  93816. .maxlen = sizeof(int),
  93817. @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
  93818. " %-7s %-6d %-10d %-10d\n",
  93819. &dest->addr.in6,
  93820. ntohs(dest->port),
  93821. - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
  93822. + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
  93823. atomic_read(&dest->weight),
  93824. atomic_read(&dest->activeconns),
  93825. atomic_read(&dest->inactconns));
  93826. @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
  93827. "%-7s %-6d %-10d %-10d\n",
  93828. ntohl(dest->addr.ip),
  93829. ntohs(dest->port),
  93830. - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
  93831. + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
  93832. atomic_read(&dest->weight),
  93833. atomic_read(&dest->activeconns),
  93834. atomic_read(&dest->inactconns));
  93835. @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
  93836. entry.addr = dest->addr.ip;
  93837. entry.port = dest->port;
  93838. - entry.conn_flags = atomic_read(&dest->conn_flags);
  93839. + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
  93840. entry.weight = atomic_read(&dest->weight);
  93841. entry.u_threshold = dest->u_threshold;
  93842. entry.l_threshold = dest->l_threshold;
  93843. @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
  93844. if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
  93845. nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
  93846. nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
  93847. - (atomic_read(&dest->conn_flags) &
  93848. + (atomic_read_unchecked(&dest->conn_flags) &
  93849. IP_VS_CONN_F_FWD_MASK)) ||
  93850. nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
  93851. atomic_read(&dest->weight)) ||
  93852. @@ -3580,7 +3580,7 @@ out:
  93853. }
  93854. -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
  93855. +static const struct genl_ops ip_vs_genl_ops[] = {
  93856. {
  93857. .cmd = IPVS_CMD_NEW_SERVICE,
  93858. .flags = GENL_ADMIN_PERM,
  93859. @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
  93860. {
  93861. int idx;
  93862. struct netns_ipvs *ipvs = net_ipvs(net);
  93863. - struct ctl_table *tbl;
  93864. + ctl_table_no_const *tbl;
  93865. atomic_set(&ipvs->dropentry, 0);
  93866. spin_lock_init(&ipvs->dropentry_lock);
  93867. diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
  93868. index ca056a3..9cf01ef 100644
  93869. --- a/net/netfilter/ipvs/ip_vs_lblc.c
  93870. +++ b/net/netfilter/ipvs/ip_vs_lblc.c
  93871. @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
  93872. * IPVS LBLC sysctl table
  93873. */
  93874. #ifdef CONFIG_SYSCTL
  93875. -static struct ctl_table vs_vars_table[] = {
  93876. +static ctl_table_no_const vs_vars_table[] __read_only = {
  93877. {
  93878. .procname = "lblc_expiration",
  93879. .data = NULL,
  93880. diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
  93881. index 3f21a2f..a112e85 100644
  93882. --- a/net/netfilter/ipvs/ip_vs_lblcr.c
  93883. +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
  93884. @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
  93885. * IPVS LBLCR sysctl table
  93886. */
  93887. -static struct ctl_table vs_vars_table[] = {
  93888. +static ctl_table_no_const vs_vars_table[] __read_only = {
  93889. {
  93890. .procname = "lblcr_expiration",
  93891. .data = NULL,
  93892. diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
  93893. index db80126..ef7110e 100644
  93894. --- a/net/netfilter/ipvs/ip_vs_sync.c
  93895. +++ b/net/netfilter/ipvs/ip_vs_sync.c
  93896. @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
  93897. cp = cp->control;
  93898. if (cp) {
  93899. if (cp->flags & IP_VS_CONN_F_TEMPLATE)
  93900. - pkts = atomic_add_return(1, &cp->in_pkts);
  93901. + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
  93902. else
  93903. pkts = sysctl_sync_threshold(ipvs);
  93904. ip_vs_sync_conn(net, cp->control, pkts);
  93905. @@ -771,7 +771,7 @@ control:
  93906. if (!cp)
  93907. return;
  93908. if (cp->flags & IP_VS_CONN_F_TEMPLATE)
  93909. - pkts = atomic_add_return(1, &cp->in_pkts);
  93910. + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
  93911. else
  93912. pkts = sysctl_sync_threshold(ipvs);
  93913. goto sloop;
  93914. @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
  93915. if (opt)
  93916. memcpy(&cp->in_seq, opt, sizeof(*opt));
  93917. - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
  93918. + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
  93919. cp->state = state;
  93920. cp->old_state = cp->state;
  93921. /*
  93922. diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
  93923. index c47444e..b0961c6 100644
  93924. --- a/net/netfilter/ipvs/ip_vs_xmit.c
  93925. +++ b/net/netfilter/ipvs/ip_vs_xmit.c
  93926. @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  93927. else
  93928. rc = NF_ACCEPT;
  93929. /* do not touch skb anymore */
  93930. - atomic_inc(&cp->in_pkts);
  93931. + atomic_inc_unchecked(&cp->in_pkts);
  93932. goto out;
  93933. }
  93934. @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  93935. else
  93936. rc = NF_ACCEPT;
  93937. /* do not touch skb anymore */
  93938. - atomic_inc(&cp->in_pkts);
  93939. + atomic_inc_unchecked(&cp->in_pkts);
  93940. goto out;
  93941. }
  93942. diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
  93943. index a4b5e2a..13b1de3 100644
  93944. --- a/net/netfilter/nf_conntrack_acct.c
  93945. +++ b/net/netfilter/nf_conntrack_acct.c
  93946. @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
  93947. #ifdef CONFIG_SYSCTL
  93948. static int nf_conntrack_acct_init_sysctl(struct net *net)
  93949. {
  93950. - struct ctl_table *table;
  93951. + ctl_table_no_const *table;
  93952. table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
  93953. GFP_KERNEL);
  93954. diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
  93955. index 356bef5..99932cb 100644
  93956. --- a/net/netfilter/nf_conntrack_core.c
  93957. +++ b/net/netfilter/nf_conntrack_core.c
  93958. @@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
  93959. #define DYING_NULLS_VAL ((1<<30)+1)
  93960. #define TEMPLATE_NULLS_VAL ((1<<30)+2)
  93961. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  93962. +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
  93963. +#endif
  93964. +
  93965. int nf_conntrack_init_net(struct net *net)
  93966. {
  93967. int ret;
  93968. @@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
  93969. goto err_stat;
  93970. }
  93971. +#ifdef CONFIG_GRKERNSEC_HIDESYM
  93972. + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
  93973. +#else
  93974. net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
  93975. +#endif
  93976. if (!net->ct.slabname) {
  93977. ret = -ENOMEM;
  93978. goto err_slabname;
  93979. diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
  93980. index 1df1761..ce8b88a 100644
  93981. --- a/net/netfilter/nf_conntrack_ecache.c
  93982. +++ b/net/netfilter/nf_conntrack_ecache.c
  93983. @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
  93984. #ifdef CONFIG_SYSCTL
  93985. static int nf_conntrack_event_init_sysctl(struct net *net)
  93986. {
  93987. - struct ctl_table *table;
  93988. + ctl_table_no_const *table;
  93989. table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
  93990. GFP_KERNEL);
  93991. diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
  93992. index 974a2a4..52cc6ff 100644
  93993. --- a/net/netfilter/nf_conntrack_helper.c
  93994. +++ b/net/netfilter/nf_conntrack_helper.c
  93995. @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
  93996. static int nf_conntrack_helper_init_sysctl(struct net *net)
  93997. {
  93998. - struct ctl_table *table;
  93999. + ctl_table_no_const *table;
  94000. table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
  94001. GFP_KERNEL);
  94002. diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
  94003. index b65d586..beec902 100644
  94004. --- a/net/netfilter/nf_conntrack_proto.c
  94005. +++ b/net/netfilter/nf_conntrack_proto.c
  94006. @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
  94007. static void
  94008. nf_ct_unregister_sysctl(struct ctl_table_header **header,
  94009. - struct ctl_table **table,
  94010. + ctl_table_no_const **table,
  94011. unsigned int users)
  94012. {
  94013. if (users > 0)
  94014. diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
  94015. index f641751..d3c5b51 100644
  94016. --- a/net/netfilter/nf_conntrack_standalone.c
  94017. +++ b/net/netfilter/nf_conntrack_standalone.c
  94018. @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
  94019. static int nf_conntrack_standalone_init_sysctl(struct net *net)
  94020. {
  94021. - struct ctl_table *table;
  94022. + ctl_table_no_const *table;
  94023. table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
  94024. GFP_KERNEL);
  94025. diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
  94026. index 7a394df..bd91a8a 100644
  94027. --- a/net/netfilter/nf_conntrack_timestamp.c
  94028. +++ b/net/netfilter/nf_conntrack_timestamp.c
  94029. @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
  94030. #ifdef CONFIG_SYSCTL
  94031. static int nf_conntrack_tstamp_init_sysctl(struct net *net)
  94032. {
  94033. - struct ctl_table *table;
  94034. + ctl_table_no_const *table;
  94035. table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
  94036. GFP_KERNEL);
  94037. diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
  94038. index 85296d4..8becdec 100644
  94039. --- a/net/netfilter/nf_log.c
  94040. +++ b/net/netfilter/nf_log.c
  94041. @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
  94042. #ifdef CONFIG_SYSCTL
  94043. static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
  94044. -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
  94045. +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
  94046. static int nf_log_proc_dostring(struct ctl_table *table, int write,
  94047. void __user *buffer, size_t *lenp, loff_t *ppos)
  94048. @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
  94049. rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
  94050. mutex_unlock(&nf_log_mutex);
  94051. } else {
  94052. + ctl_table_no_const nf_log_table = *table;
  94053. +
  94054. mutex_lock(&nf_log_mutex);
  94055. logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
  94056. lockdep_is_held(&nf_log_mutex));
  94057. if (!logger)
  94058. - table->data = "NONE";
  94059. + nf_log_table.data = "NONE";
  94060. else
  94061. - table->data = logger->name;
  94062. - r = proc_dostring(table, write, buffer, lenp, ppos);
  94063. + nf_log_table.data = logger->name;
  94064. + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
  94065. mutex_unlock(&nf_log_mutex);
  94066. }
  94067. diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
  94068. index f042ae5..30ea486 100644
  94069. --- a/net/netfilter/nf_sockopt.c
  94070. +++ b/net/netfilter/nf_sockopt.c
  94071. @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
  94072. }
  94073. }
  94074. - list_add(&reg->list, &nf_sockopts);
  94075. + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
  94076. out:
  94077. mutex_unlock(&nf_sockopt_mutex);
  94078. return ret;
  94079. @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
  94080. void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
  94081. {
  94082. mutex_lock(&nf_sockopt_mutex);
  94083. - list_del(&reg->list);
  94084. + pax_list_del((struct list_head *)&reg->list);
  94085. mutex_unlock(&nf_sockopt_mutex);
  94086. }
  94087. EXPORT_SYMBOL(nf_unregister_sockopt);
  94088. diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
  94089. index adce01e..8d52d50 100644
  94090. --- a/net/netfilter/nf_tables_api.c
  94091. +++ b/net/netfilter/nf_tables_api.c
  94092. @@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
  94093. #ifdef CONFIG_MODULES
  94094. if (autoload) {
  94095. nfnl_unlock(NFNL_SUBSYS_NFTABLES);
  94096. - request_module("nft-chain-%u-%*.s", afi->family,
  94097. - nla_len(nla)-1, (const char *)nla_data(nla));
  94098. + request_module("nft-chain-%u-%.*s", afi->family,
  94099. + nla_len(nla), (const char *)nla_data(nla));
  94100. nfnl_lock(NFNL_SUBSYS_NFTABLES);
  94101. type = __nf_tables_chain_type_lookup(afi->family, nla);
  94102. if (type != NULL)
  94103. @@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
  94104. static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
  94105. [NFTA_SET_TABLE] = { .type = NLA_STRING },
  94106. - [NFTA_SET_NAME] = { .type = NLA_STRING },
  94107. + [NFTA_SET_NAME] = { .type = NLA_STRING,
  94108. + .len = IFNAMSIZ - 1 },
  94109. [NFTA_SET_FLAGS] = { .type = NLA_U32 },
  94110. [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
  94111. [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
  94112. diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
  94113. index a155d19..726b0f2 100644
  94114. --- a/net/netfilter/nfnetlink_log.c
  94115. +++ b/net/netfilter/nfnetlink_log.c
  94116. @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
  94117. struct nfnl_log_net {
  94118. spinlock_t instances_lock;
  94119. struct hlist_head instance_table[INSTANCE_BUCKETS];
  94120. - atomic_t global_seq;
  94121. + atomic_unchecked_t global_seq;
  94122. };
  94123. static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
  94124. @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
  94125. /* global sequence number */
  94126. if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
  94127. nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
  94128. - htonl(atomic_inc_return(&log->global_seq))))
  94129. + htonl(atomic_inc_return_unchecked(&log->global_seq))))
  94130. goto nla_put_failure;
  94131. if (data_len) {
  94132. diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
  94133. index 82cb823..5685dd5 100644
  94134. --- a/net/netfilter/nft_compat.c
  94135. +++ b/net/netfilter/nft_compat.c
  94136. @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
  94137. /* We want to reuse existing compat_to_user */
  94138. old_fs = get_fs();
  94139. set_fs(KERNEL_DS);
  94140. - t->compat_to_user(out, in);
  94141. + t->compat_to_user((void __force_user *)out, in);
  94142. set_fs(old_fs);
  94143. ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
  94144. kfree(out);
  94145. @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
  94146. /* We want to reuse existing compat_to_user */
  94147. old_fs = get_fs();
  94148. set_fs(KERNEL_DS);
  94149. - m->compat_to_user(out, in);
  94150. + m->compat_to_user((void __force_user *)out, in);
  94151. set_fs(old_fs);
  94152. ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
  94153. kfree(out);
  94154. diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
  94155. new file mode 100644
  94156. index 0000000..c566332
  94157. --- /dev/null
  94158. +++ b/net/netfilter/xt_gradm.c
  94159. @@ -0,0 +1,51 @@
  94160. +/*
  94161. + * gradm match for netfilter
  94162. + * Copyright © Zbigniew Krzystolik, 2010
  94163. + *
  94164. + * This program is free software; you can redistribute it and/or modify
  94165. + * it under the terms of the GNU General Public License; either version
  94166. + * 2 or 3 as published by the Free Software Foundation.
  94167. + */
  94168. +#include <linux/module.h>
  94169. +#include <linux/moduleparam.h>
  94170. +#include <linux/skbuff.h>
  94171. +#include <linux/netfilter/x_tables.h>
  94172. +#include <linux/grsecurity.h>
  94173. +#include <linux/netfilter/xt_gradm.h>
  94174. +
  94175. +static bool
  94176. +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
  94177. +{
  94178. + const struct xt_gradm_mtinfo *info = par->matchinfo;
  94179. + bool retval = false;
  94180. + if (gr_acl_is_enabled())
  94181. + retval = true;
  94182. + return retval ^ info->invflags;
  94183. +}
  94184. +
  94185. +static struct xt_match gradm_mt_reg __read_mostly = {
  94186. + .name = "gradm",
  94187. + .revision = 0,
  94188. + .family = NFPROTO_UNSPEC,
  94189. + .match = gradm_mt,
  94190. + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
  94191. + .me = THIS_MODULE,
  94192. +};
  94193. +
  94194. +static int __init gradm_mt_init(void)
  94195. +{
  94196. + return xt_register_match(&gradm_mt_reg);
  94197. +}
  94198. +
  94199. +static void __exit gradm_mt_exit(void)
  94200. +{
  94201. + xt_unregister_match(&gradm_mt_reg);
  94202. +}
  94203. +
  94204. +module_init(gradm_mt_init);
  94205. +module_exit(gradm_mt_exit);
  94206. +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
  94207. +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
  94208. +MODULE_LICENSE("GPL");
  94209. +MODULE_ALIAS("ipt_gradm");
  94210. +MODULE_ALIAS("ip6t_gradm");
  94211. diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
  94212. index a3910fc..2d2ba14 100644
  94213. --- a/net/netfilter/xt_hashlimit.c
  94214. +++ b/net/netfilter/xt_hashlimit.c
  94215. @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
  94216. {
  94217. struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
  94218. - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
  94219. + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
  94220. if (!hashlimit_net->ipt_hashlimit)
  94221. return -ENOMEM;
  94222. #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
  94223. - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
  94224. + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
  94225. if (!hashlimit_net->ip6t_hashlimit) {
  94226. remove_proc_entry("ipt_hashlimit", net->proc_net);
  94227. return -ENOMEM;
  94228. diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
  94229. index 1e657cf..1eb1c34 100644
  94230. --- a/net/netfilter/xt_recent.c
  94231. +++ b/net/netfilter/xt_recent.c
  94232. @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
  94233. {
  94234. struct recent_net *recent_net = recent_pernet(net);
  94235. - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
  94236. + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
  94237. if (!recent_net->xt_recent)
  94238. return -ENOMEM;
  94239. return 0;
  94240. diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
  94241. index 11de55e..f25e448 100644
  94242. --- a/net/netfilter/xt_statistic.c
  94243. +++ b/net/netfilter/xt_statistic.c
  94244. @@ -19,7 +19,7 @@
  94245. #include <linux/module.h>
  94246. struct xt_statistic_priv {
  94247. - atomic_t count;
  94248. + atomic_unchecked_t count;
  94249. } ____cacheline_aligned_in_smp;
  94250. MODULE_LICENSE("GPL");
  94251. @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
  94252. break;
  94253. case XT_STATISTIC_MODE_NTH:
  94254. do {
  94255. - oval = atomic_read(&info->master->count);
  94256. + oval = atomic_read_unchecked(&info->master->count);
  94257. nval = (oval == info->u.nth.every) ? 0 : oval + 1;
  94258. - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
  94259. + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
  94260. if (nval == 0)
  94261. ret = !ret;
  94262. break;
  94263. @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
  94264. info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
  94265. if (info->master == NULL)
  94266. return -ENOMEM;
  94267. - atomic_set(&info->master->count, info->u.nth.count);
  94268. + atomic_set_unchecked(&info->master->count, info->u.nth.count);
  94269. return 0;
  94270. }
  94271. diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
  94272. index 04748ab6..ca8f86f 100644
  94273. --- a/net/netlink/af_netlink.c
  94274. +++ b/net/netlink/af_netlink.c
  94275. @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
  94276. sk->sk_error_report(sk);
  94277. }
  94278. }
  94279. - atomic_inc(&sk->sk_drops);
  94280. + atomic_inc_unchecked(&sk->sk_drops);
  94281. }
  94282. static void netlink_rcv_wake(struct sock *sk)
  94283. @@ -2933,7 +2933,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
  94284. sk_wmem_alloc_get(s),
  94285. nlk->cb_running,
  94286. atomic_read(&s->sk_refcnt),
  94287. - atomic_read(&s->sk_drops),
  94288. + atomic_read_unchecked(&s->sk_drops),
  94289. sock_i_ino(s)
  94290. );
  94291. diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
  94292. index b74aa07..d41926e 100644
  94293. --- a/net/netrom/af_netrom.c
  94294. +++ b/net/netrom/af_netrom.c
  94295. @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
  94296. *uaddr_len = sizeof(struct full_sockaddr_ax25);
  94297. } else {
  94298. sax->fsa_ax25.sax25_family = AF_NETROM;
  94299. - sax->fsa_ax25.sax25_ndigis = 0;
  94300. sax->fsa_ax25.sax25_call = nr->source_addr;
  94301. *uaddr_len = sizeof(struct sockaddr_ax25);
  94302. }
  94303. diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
  94304. index 48a6a93..0b0496e 100644
  94305. --- a/net/packet/af_packet.c
  94306. +++ b/net/packet/af_packet.c
  94307. @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
  94308. spin_lock(&sk->sk_receive_queue.lock);
  94309. po->stats.stats1.tp_packets++;
  94310. - skb->dropcount = atomic_read(&sk->sk_drops);
  94311. + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
  94312. __skb_queue_tail(&sk->sk_receive_queue, skb);
  94313. spin_unlock(&sk->sk_receive_queue.lock);
  94314. sk->sk_data_ready(sk, skb->len);
  94315. @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
  94316. drop_n_acct:
  94317. spin_lock(&sk->sk_receive_queue.lock);
  94318. po->stats.stats1.tp_drops++;
  94319. - atomic_inc(&sk->sk_drops);
  94320. + atomic_inc_unchecked(&sk->sk_drops);
  94321. spin_unlock(&sk->sk_receive_queue.lock);
  94322. drop_n_restore:
  94323. @@ -3449,7 +3449,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
  94324. case PACKET_HDRLEN:
  94325. if (len > sizeof(int))
  94326. len = sizeof(int);
  94327. - if (copy_from_user(&val, optval, len))
  94328. + if (len > sizeof(val) || copy_from_user(&val, optval, len))
  94329. return -EFAULT;
  94330. switch (val) {
  94331. case TPACKET_V1:
  94332. @@ -3495,7 +3495,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
  94333. len = lv;
  94334. if (put_user(len, optlen))
  94335. return -EFAULT;
  94336. - if (copy_to_user(optval, data, len))
  94337. + if (len > sizeof(st) || copy_to_user(optval, data, len))
  94338. return -EFAULT;
  94339. return 0;
  94340. }
  94341. diff --git a/net/phonet/pep.c b/net/phonet/pep.c
  94342. index e774117..900b8b7 100644
  94343. --- a/net/phonet/pep.c
  94344. +++ b/net/phonet/pep.c
  94345. @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
  94346. case PNS_PEP_CTRL_REQ:
  94347. if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
  94348. - atomic_inc(&sk->sk_drops);
  94349. + atomic_inc_unchecked(&sk->sk_drops);
  94350. break;
  94351. }
  94352. __skb_pull(skb, 4);
  94353. @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
  94354. }
  94355. if (pn->rx_credits == 0) {
  94356. - atomic_inc(&sk->sk_drops);
  94357. + atomic_inc_unchecked(&sk->sk_drops);
  94358. err = -ENOBUFS;
  94359. break;
  94360. }
  94361. @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
  94362. }
  94363. if (pn->rx_credits == 0) {
  94364. - atomic_inc(&sk->sk_drops);
  94365. + atomic_inc_unchecked(&sk->sk_drops);
  94366. err = NET_RX_DROP;
  94367. break;
  94368. }
  94369. diff --git a/net/phonet/socket.c b/net/phonet/socket.c
  94370. index 008214a..bb68240 100644
  94371. --- a/net/phonet/socket.c
  94372. +++ b/net/phonet/socket.c
  94373. @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
  94374. from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
  94375. sock_i_ino(sk),
  94376. atomic_read(&sk->sk_refcnt), sk,
  94377. - atomic_read(&sk->sk_drops));
  94378. + atomic_read_unchecked(&sk->sk_drops));
  94379. }
  94380. seq_pad(seq, '\n');
  94381. return 0;
  94382. diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
  94383. index c02a8c4..3c5b600 100644
  94384. --- a/net/phonet/sysctl.c
  94385. +++ b/net/phonet/sysctl.c
  94386. @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
  94387. {
  94388. int ret;
  94389. int range[2] = {local_port_range[0], local_port_range[1]};
  94390. - struct ctl_table tmp = {
  94391. + ctl_table_no_const tmp = {
  94392. .data = &range,
  94393. .maxlen = sizeof(range),
  94394. .mode = table->mode,
  94395. diff --git a/net/rds/cong.c b/net/rds/cong.c
  94396. index e5b65ac..f3b6fb7 100644
  94397. --- a/net/rds/cong.c
  94398. +++ b/net/rds/cong.c
  94399. @@ -78,7 +78,7 @@
  94400. * finds that the saved generation number is smaller than the global generation
  94401. * number, it wakes up the process.
  94402. */
  94403. -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
  94404. +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
  94405. /*
  94406. * Congestion monitoring
  94407. @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
  94408. rdsdebug("waking map %p for %pI4\n",
  94409. map, &map->m_addr);
  94410. rds_stats_inc(s_cong_update_received);
  94411. - atomic_inc(&rds_cong_generation);
  94412. + atomic_inc_unchecked(&rds_cong_generation);
  94413. if (waitqueue_active(&map->m_waitq))
  94414. wake_up(&map->m_waitq);
  94415. if (waitqueue_active(&rds_poll_waitq))
  94416. @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
  94417. int rds_cong_updated_since(unsigned long *recent)
  94418. {
  94419. - unsigned long gen = atomic_read(&rds_cong_generation);
  94420. + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
  94421. if (likely(*recent == gen))
  94422. return 0;
  94423. diff --git a/net/rds/ib.h b/net/rds/ib.h
  94424. index 7280ab8..e04f4ea 100644
  94425. --- a/net/rds/ib.h
  94426. +++ b/net/rds/ib.h
  94427. @@ -128,7 +128,7 @@ struct rds_ib_connection {
  94428. /* sending acks */
  94429. unsigned long i_ack_flags;
  94430. #ifdef KERNEL_HAS_ATOMIC64
  94431. - atomic64_t i_ack_next; /* next ACK to send */
  94432. + atomic64_unchecked_t i_ack_next; /* next ACK to send */
  94433. #else
  94434. spinlock_t i_ack_lock; /* protect i_ack_next */
  94435. u64 i_ack_next; /* next ACK to send */
  94436. diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
  94437. index 31b74f5..dc1fbfa 100644
  94438. --- a/net/rds/ib_cm.c
  94439. +++ b/net/rds/ib_cm.c
  94440. @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
  94441. /* Clear the ACK state */
  94442. clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
  94443. #ifdef KERNEL_HAS_ATOMIC64
  94444. - atomic64_set(&ic->i_ack_next, 0);
  94445. + atomic64_set_unchecked(&ic->i_ack_next, 0);
  94446. #else
  94447. ic->i_ack_next = 0;
  94448. #endif
  94449. diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
  94450. index b7ebe23..b6352f6 100644
  94451. --- a/net/rds/ib_recv.c
  94452. +++ b/net/rds/ib_recv.c
  94453. @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
  94454. static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
  94455. int ack_required)
  94456. {
  94457. - atomic64_set(&ic->i_ack_next, seq);
  94458. + atomic64_set_unchecked(&ic->i_ack_next, seq);
  94459. if (ack_required) {
  94460. smp_mb__before_clear_bit();
  94461. set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
  94462. @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
  94463. clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
  94464. smp_mb__after_clear_bit();
  94465. - return atomic64_read(&ic->i_ack_next);
  94466. + return atomic64_read_unchecked(&ic->i_ack_next);
  94467. }
  94468. #endif
  94469. diff --git a/net/rds/iw.h b/net/rds/iw.h
  94470. index 04ce3b1..48119a6 100644
  94471. --- a/net/rds/iw.h
  94472. +++ b/net/rds/iw.h
  94473. @@ -134,7 +134,7 @@ struct rds_iw_connection {
  94474. /* sending acks */
  94475. unsigned long i_ack_flags;
  94476. #ifdef KERNEL_HAS_ATOMIC64
  94477. - atomic64_t i_ack_next; /* next ACK to send */
  94478. + atomic64_unchecked_t i_ack_next; /* next ACK to send */
  94479. #else
  94480. spinlock_t i_ack_lock; /* protect i_ack_next */
  94481. u64 i_ack_next; /* next ACK to send */
  94482. diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
  94483. index a91e1db..cf3053f 100644
  94484. --- a/net/rds/iw_cm.c
  94485. +++ b/net/rds/iw_cm.c
  94486. @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
  94487. /* Clear the ACK state */
  94488. clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
  94489. #ifdef KERNEL_HAS_ATOMIC64
  94490. - atomic64_set(&ic->i_ack_next, 0);
  94491. + atomic64_set_unchecked(&ic->i_ack_next, 0);
  94492. #else
  94493. ic->i_ack_next = 0;
  94494. #endif
  94495. diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
  94496. index 4503335..db566b4 100644
  94497. --- a/net/rds/iw_recv.c
  94498. +++ b/net/rds/iw_recv.c
  94499. @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
  94500. static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
  94501. int ack_required)
  94502. {
  94503. - atomic64_set(&ic->i_ack_next, seq);
  94504. + atomic64_set_unchecked(&ic->i_ack_next, seq);
  94505. if (ack_required) {
  94506. smp_mb__before_clear_bit();
  94507. set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
  94508. @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
  94509. clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
  94510. smp_mb__after_clear_bit();
  94511. - return atomic64_read(&ic->i_ack_next);
  94512. + return atomic64_read_unchecked(&ic->i_ack_next);
  94513. }
  94514. #endif
  94515. diff --git a/net/rds/rds.h b/net/rds/rds.h
  94516. index 48f8ffc..0ef3eec 100644
  94517. --- a/net/rds/rds.h
  94518. +++ b/net/rds/rds.h
  94519. @@ -449,7 +449,7 @@ struct rds_transport {
  94520. void (*sync_mr)(void *trans_private, int direction);
  94521. void (*free_mr)(void *trans_private, int invalidate);
  94522. void (*flush_mrs)(void);
  94523. -};
  94524. +} __do_const;
  94525. struct rds_sock {
  94526. struct sock rs_sk;
  94527. diff --git a/net/rds/tcp.c b/net/rds/tcp.c
  94528. index edac9ef..16bcb98 100644
  94529. --- a/net/rds/tcp.c
  94530. +++ b/net/rds/tcp.c
  94531. @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
  94532. int val = 1;
  94533. set_fs(KERNEL_DS);
  94534. - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
  94535. + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
  94536. sizeof(val));
  94537. set_fs(oldfs);
  94538. }
  94539. diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
  94540. index 81cf5a4..b5826ff 100644
  94541. --- a/net/rds/tcp_send.c
  94542. +++ b/net/rds/tcp_send.c
  94543. @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
  94544. oldfs = get_fs();
  94545. set_fs(KERNEL_DS);
  94546. - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
  94547. + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
  94548. sizeof(val));
  94549. set_fs(oldfs);
  94550. }
  94551. diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
  94552. index e61aa60..f07cc89 100644
  94553. --- a/net/rxrpc/af_rxrpc.c
  94554. +++ b/net/rxrpc/af_rxrpc.c
  94555. @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
  94556. __be32 rxrpc_epoch;
  94557. /* current debugging ID */
  94558. -atomic_t rxrpc_debug_id;
  94559. +atomic_unchecked_t rxrpc_debug_id;
  94560. /* count of skbs currently in use */
  94561. atomic_t rxrpc_n_skbs;
  94562. diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
  94563. index cd97a0c..0041649 100644
  94564. --- a/net/rxrpc/ar-ack.c
  94565. +++ b/net/rxrpc/ar-ack.c
  94566. @@ -182,7 +182,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
  94567. _enter("{%d,%d,%d,%d},",
  94568. call->acks_hard, call->acks_unacked,
  94569. - atomic_read(&call->sequence),
  94570. + atomic_read_unchecked(&call->sequence),
  94571. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
  94572. stop = 0;
  94573. @@ -206,7 +206,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
  94574. /* each Tx packet has a new serial number */
  94575. sp->hdr.serial =
  94576. - htonl(atomic_inc_return(&call->conn->serial));
  94577. + htonl(atomic_inc_return_unchecked(&call->conn->serial));
  94578. hdr = (struct rxrpc_header *) txb->head;
  94579. hdr->serial = sp->hdr.serial;
  94580. @@ -410,7 +410,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
  94581. */
  94582. static void rxrpc_clear_tx_window(struct rxrpc_call *call)
  94583. {
  94584. - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
  94585. + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
  94586. }
  94587. /*
  94588. @@ -636,7 +636,7 @@ process_further:
  94589. latest = ntohl(sp->hdr.serial);
  94590. hard = ntohl(ack.firstPacket);
  94591. - tx = atomic_read(&call->sequence);
  94592. + tx = atomic_read_unchecked(&call->sequence);
  94593. _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  94594. latest,
  94595. @@ -1168,7 +1168,7 @@ void rxrpc_process_call(struct work_struct *work)
  94596. goto maybe_reschedule;
  94597. send_ACK_with_skew:
  94598. - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
  94599. + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
  94600. ntohl(ack.serial));
  94601. send_ACK:
  94602. mtu = call->conn->trans->peer->if_mtu;
  94603. @@ -1180,7 +1180,7 @@ send_ACK:
  94604. ackinfo.rxMTU = htonl(5692);
  94605. ackinfo.jumbo_max = htonl(4);
  94606. - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
  94607. + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
  94608. _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  94609. ntohl(hdr.serial),
  94610. ntohs(ack.maxSkew),
  94611. @@ -1198,7 +1198,7 @@ send_ACK:
  94612. send_message:
  94613. _debug("send message");
  94614. - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
  94615. + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
  94616. _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
  94617. send_message_2:
  94618. diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
  94619. index a3bbb36..3341fb9 100644
  94620. --- a/net/rxrpc/ar-call.c
  94621. +++ b/net/rxrpc/ar-call.c
  94622. @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
  94623. spin_lock_init(&call->lock);
  94624. rwlock_init(&call->state_lock);
  94625. atomic_set(&call->usage, 1);
  94626. - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
  94627. + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
  94628. call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
  94629. memset(&call->sock_node, 0xed, sizeof(call->sock_node));
  94630. diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
  94631. index 7bf5b5b..4a3bf2c 100644
  94632. --- a/net/rxrpc/ar-connection.c
  94633. +++ b/net/rxrpc/ar-connection.c
  94634. @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
  94635. rwlock_init(&conn->lock);
  94636. spin_lock_init(&conn->state_lock);
  94637. atomic_set(&conn->usage, 1);
  94638. - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
  94639. + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
  94640. conn->avail_calls = RXRPC_MAXCALLS;
  94641. conn->size_align = 4;
  94642. conn->header_size = sizeof(struct rxrpc_header);
  94643. diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
  94644. index e7ed43a..6afa140 100644
  94645. --- a/net/rxrpc/ar-connevent.c
  94646. +++ b/net/rxrpc/ar-connevent.c
  94647. @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
  94648. len = iov[0].iov_len + iov[1].iov_len;
  94649. - hdr.serial = htonl(atomic_inc_return(&conn->serial));
  94650. + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
  94651. _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
  94652. ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
  94653. diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
  94654. index 529572f..c758ca7 100644
  94655. --- a/net/rxrpc/ar-input.c
  94656. +++ b/net/rxrpc/ar-input.c
  94657. @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
  94658. /* track the latest serial number on this connection for ACK packet
  94659. * information */
  94660. serial = ntohl(sp->hdr.serial);
  94661. - hi_serial = atomic_read(&call->conn->hi_serial);
  94662. + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
  94663. while (serial > hi_serial)
  94664. - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
  94665. + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
  94666. serial);
  94667. /* request ACK generation for any ACK or DATA packet that requests
  94668. diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
  94669. index 5f43675..ca07817 100644
  94670. --- a/net/rxrpc/ar-internal.h
  94671. +++ b/net/rxrpc/ar-internal.h
  94672. @@ -272,8 +272,8 @@ struct rxrpc_connection {
  94673. int error; /* error code for local abort */
  94674. int debug_id; /* debug ID for printks */
  94675. unsigned int call_counter; /* call ID counter */
  94676. - atomic_t serial; /* packet serial number counter */
  94677. - atomic_t hi_serial; /* highest serial number received */
  94678. + atomic_unchecked_t serial; /* packet serial number counter */
  94679. + atomic_unchecked_t hi_serial; /* highest serial number received */
  94680. u8 avail_calls; /* number of calls available */
  94681. u8 size_align; /* data size alignment (for security) */
  94682. u8 header_size; /* rxrpc + security header size */
  94683. @@ -346,7 +346,7 @@ struct rxrpc_call {
  94684. spinlock_t lock;
  94685. rwlock_t state_lock; /* lock for state transition */
  94686. atomic_t usage;
  94687. - atomic_t sequence; /* Tx data packet sequence counter */
  94688. + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
  94689. u32 abort_code; /* local/remote abort code */
  94690. enum { /* current state of call */
  94691. RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
  94692. @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
  94693. */
  94694. extern atomic_t rxrpc_n_skbs;
  94695. extern __be32 rxrpc_epoch;
  94696. -extern atomic_t rxrpc_debug_id;
  94697. +extern atomic_unchecked_t rxrpc_debug_id;
  94698. extern struct workqueue_struct *rxrpc_workqueue;
  94699. /*
  94700. diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
  94701. index 87f7135..74d3703 100644
  94702. --- a/net/rxrpc/ar-local.c
  94703. +++ b/net/rxrpc/ar-local.c
  94704. @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
  94705. spin_lock_init(&local->lock);
  94706. rwlock_init(&local->services_lock);
  94707. atomic_set(&local->usage, 1);
  94708. - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
  94709. + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
  94710. memcpy(&local->srx, srx, sizeof(*srx));
  94711. }
  94712. diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
  94713. index d0e8f1c..a3a1686 100644
  94714. --- a/net/rxrpc/ar-output.c
  94715. +++ b/net/rxrpc/ar-output.c
  94716. @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
  94717. sp->hdr.cid = call->cid;
  94718. sp->hdr.callNumber = call->call_id;
  94719. sp->hdr.seq =
  94720. - htonl(atomic_inc_return(&call->sequence));
  94721. + htonl(atomic_inc_return_unchecked(&call->sequence));
  94722. sp->hdr.serial =
  94723. - htonl(atomic_inc_return(&conn->serial));
  94724. + htonl(atomic_inc_return_unchecked(&conn->serial));
  94725. sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
  94726. sp->hdr.userStatus = 0;
  94727. sp->hdr.securityIndex = conn->security_ix;
  94728. diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
  94729. index bebaa43..2644591 100644
  94730. --- a/net/rxrpc/ar-peer.c
  94731. +++ b/net/rxrpc/ar-peer.c
  94732. @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
  94733. INIT_LIST_HEAD(&peer->error_targets);
  94734. spin_lock_init(&peer->lock);
  94735. atomic_set(&peer->usage, 1);
  94736. - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
  94737. + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
  94738. memcpy(&peer->srx, srx, sizeof(*srx));
  94739. rxrpc_assess_MTU_size(peer);
  94740. diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
  94741. index 38047f7..9f48511 100644
  94742. --- a/net/rxrpc/ar-proc.c
  94743. +++ b/net/rxrpc/ar-proc.c
  94744. @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
  94745. atomic_read(&conn->usage),
  94746. rxrpc_conn_states[conn->state],
  94747. key_serial(conn->key),
  94748. - atomic_read(&conn->serial),
  94749. - atomic_read(&conn->hi_serial));
  94750. + atomic_read_unchecked(&conn->serial),
  94751. + atomic_read_unchecked(&conn->hi_serial));
  94752. return 0;
  94753. }
  94754. diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
  94755. index 92df566..87ec1bf 100644
  94756. --- a/net/rxrpc/ar-transport.c
  94757. +++ b/net/rxrpc/ar-transport.c
  94758. @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
  94759. spin_lock_init(&trans->client_lock);
  94760. rwlock_init(&trans->conn_lock);
  94761. atomic_set(&trans->usage, 1);
  94762. - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
  94763. + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
  94764. if (peer->srx.transport.family == AF_INET) {
  94765. switch (peer->srx.transport_type) {
  94766. diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
  94767. index f226709..0e735a8 100644
  94768. --- a/net/rxrpc/rxkad.c
  94769. +++ b/net/rxrpc/rxkad.c
  94770. @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
  94771. len = iov[0].iov_len + iov[1].iov_len;
  94772. - hdr.serial = htonl(atomic_inc_return(&conn->serial));
  94773. + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
  94774. _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
  94775. ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
  94776. @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
  94777. len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
  94778. - hdr->serial = htonl(atomic_inc_return(&conn->serial));
  94779. + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
  94780. _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
  94781. ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
  94782. diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
  94783. index 2b1738e..a9d0fc9 100644
  94784. --- a/net/sctp/ipv6.c
  94785. +++ b/net/sctp/ipv6.c
  94786. @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
  94787. .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
  94788. };
  94789. -static struct sctp_af sctp_af_inet6 = {
  94790. +static struct sctp_af sctp_af_inet6 __read_only = {
  94791. .sa_family = AF_INET6,
  94792. .sctp_xmit = sctp_v6_xmit,
  94793. .setsockopt = ipv6_setsockopt,
  94794. @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
  94795. #endif
  94796. };
  94797. -static struct sctp_pf sctp_pf_inet6 = {
  94798. +static struct sctp_pf sctp_pf_inet6 __read_only = {
  94799. .event_msgname = sctp_inet6_event_msgname,
  94800. .skb_msgname = sctp_inet6_skb_msgname,
  94801. .af_supported = sctp_inet6_af_supported,
  94802. @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
  94803. void sctp_v6_pf_exit(void)
  94804. {
  94805. - list_del(&sctp_af_inet6.list);
  94806. + pax_list_del(&sctp_af_inet6.list);
  94807. }
  94808. /* Initialize IPv6 support and register with socket layer. */
  94809. diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
  94810. index 4e1d0fc..068fef7 100644
  94811. --- a/net/sctp/protocol.c
  94812. +++ b/net/sctp/protocol.c
  94813. @@ -831,8 +831,10 @@ int sctp_register_af(struct sctp_af *af)
  94814. return 0;
  94815. }
  94816. + pax_open_kernel();
  94817. INIT_LIST_HEAD(&af->list);
  94818. - list_add_tail(&af->list, &sctp_address_families);
  94819. + pax_close_kernel();
  94820. + pax_list_add_tail(&af->list, &sctp_address_families);
  94821. return 1;
  94822. }
  94823. @@ -962,7 +964,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
  94824. static struct sctp_af sctp_af_inet;
  94825. -static struct sctp_pf sctp_pf_inet = {
  94826. +static struct sctp_pf sctp_pf_inet __read_only = {
  94827. .event_msgname = sctp_inet_event_msgname,
  94828. .skb_msgname = sctp_inet_skb_msgname,
  94829. .af_supported = sctp_inet_af_supported,
  94830. @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
  94831. };
  94832. /* IPv4 address related functions. */
  94833. -static struct sctp_af sctp_af_inet = {
  94834. +static struct sctp_af sctp_af_inet __read_only = {
  94835. .sa_family = AF_INET,
  94836. .sctp_xmit = sctp_v4_xmit,
  94837. .setsockopt = ip_setsockopt,
  94838. @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
  94839. static void sctp_v4_pf_exit(void)
  94840. {
  94841. - list_del(&sctp_af_inet.list);
  94842. + pax_list_del(&sctp_af_inet.list);
  94843. }
  94844. static int sctp_v4_protosw_init(void)
  94845. diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
  94846. index 5d6883f..394a102 100644
  94847. --- a/net/sctp/sm_sideeffect.c
  94848. +++ b/net/sctp/sm_sideeffect.c
  94849. @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
  94850. sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
  94851. }
  94852. -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
  94853. +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
  94854. NULL,
  94855. sctp_generate_t1_cookie_event,
  94856. sctp_generate_t1_init_event,
  94857. diff --git a/net/sctp/socket.c b/net/sctp/socket.c
  94858. index 981aaf8..5bc016d 100644
  94859. --- a/net/sctp/socket.c
  94860. +++ b/net/sctp/socket.c
  94861. @@ -2169,11 +2169,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
  94862. {
  94863. struct sctp_association *asoc;
  94864. struct sctp_ulpevent *event;
  94865. + struct sctp_event_subscribe subscribe;
  94866. if (optlen > sizeof(struct sctp_event_subscribe))
  94867. return -EINVAL;
  94868. - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
  94869. + if (copy_from_user(&subscribe, optval, optlen))
  94870. return -EFAULT;
  94871. + sctp_sk(sk)->subscribe = subscribe;
  94872. /*
  94873. * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
  94874. @@ -4255,13 +4257,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
  94875. static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
  94876. int __user *optlen)
  94877. {
  94878. + struct sctp_event_subscribe subscribe;
  94879. +
  94880. if (len <= 0)
  94881. return -EINVAL;
  94882. if (len > sizeof(struct sctp_event_subscribe))
  94883. len = sizeof(struct sctp_event_subscribe);
  94884. if (put_user(len, optlen))
  94885. return -EFAULT;
  94886. - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
  94887. + subscribe = sctp_sk(sk)->subscribe;
  94888. + if (copy_to_user(optval, &subscribe, len))
  94889. return -EFAULT;
  94890. return 0;
  94891. }
  94892. @@ -4279,6 +4284,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
  94893. */
  94894. static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
  94895. {
  94896. + __u32 autoclose;
  94897. +
  94898. /* Applicable to UDP-style socket only */
  94899. if (sctp_style(sk, TCP))
  94900. return -EOPNOTSUPP;
  94901. @@ -4287,7 +4294,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
  94902. len = sizeof(int);
  94903. if (put_user(len, optlen))
  94904. return -EFAULT;
  94905. - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
  94906. + autoclose = sctp_sk(sk)->autoclose;
  94907. + if (copy_to_user(optval, &autoclose, sizeof(int)))
  94908. return -EFAULT;
  94909. return 0;
  94910. }
  94911. @@ -4662,12 +4670,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
  94912. */
  94913. static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
  94914. {
  94915. + struct sctp_initmsg initmsg;
  94916. +
  94917. if (len < sizeof(struct sctp_initmsg))
  94918. return -EINVAL;
  94919. len = sizeof(struct sctp_initmsg);
  94920. if (put_user(len, optlen))
  94921. return -EFAULT;
  94922. - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
  94923. + initmsg = sctp_sk(sk)->initmsg;
  94924. + if (copy_to_user(optval, &initmsg, len))
  94925. return -EFAULT;
  94926. return 0;
  94927. }
  94928. @@ -4708,6 +4719,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
  94929. addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
  94930. if (space_left < addrlen)
  94931. return -ENOMEM;
  94932. + if (addrlen > sizeof(temp) || addrlen < 0)
  94933. + return -EFAULT;
  94934. if (copy_to_user(to, &temp, addrlen))
  94935. return -EFAULT;
  94936. to += addrlen;
  94937. diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
  94938. index 35c8923..536614e 100644
  94939. --- a/net/sctp/sysctl.c
  94940. +++ b/net/sctp/sysctl.c
  94941. @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
  94942. {
  94943. struct net *net = current->nsproxy->net_ns;
  94944. char tmp[8];
  94945. - struct ctl_table tbl;
  94946. + ctl_table_no_const tbl;
  94947. int ret;
  94948. int changed = 0;
  94949. char *none = "none";
  94950. @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
  94951. {
  94952. struct net *net = current->nsproxy->net_ns;
  94953. int new_value;
  94954. - struct ctl_table tbl;
  94955. + ctl_table_no_const tbl;
  94956. unsigned int min = *(unsigned int *) ctl->extra1;
  94957. unsigned int max = *(unsigned int *) ctl->extra2;
  94958. int ret;
  94959. @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
  94960. {
  94961. struct net *net = current->nsproxy->net_ns;
  94962. int new_value;
  94963. - struct ctl_table tbl;
  94964. + ctl_table_no_const tbl;
  94965. unsigned int min = *(unsigned int *) ctl->extra1;
  94966. unsigned int max = *(unsigned int *) ctl->extra2;
  94967. int ret;
  94968. @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
  94969. int sctp_sysctl_net_register(struct net *net)
  94970. {
  94971. - struct ctl_table *table = sctp_net_table;
  94972. + ctl_table_no_const *table = NULL;
  94973. if (!net_eq(net, &init_net)) {
  94974. int i;
  94975. @@ -415,7 +415,10 @@ int sctp_sysctl_net_register(struct net *net)
  94976. table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
  94977. }
  94978. - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
  94979. + if (!net_eq(net, &init_net))
  94980. + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
  94981. + else
  94982. + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
  94983. return 0;
  94984. }
  94985. diff --git a/net/socket.c b/net/socket.c
  94986. index a19ae19..89554dc 100644
  94987. --- a/net/socket.c
  94988. +++ b/net/socket.c
  94989. @@ -88,6 +88,7 @@
  94990. #include <linux/magic.h>
  94991. #include <linux/slab.h>
  94992. #include <linux/xattr.h>
  94993. +#include <linux/in.h>
  94994. #include <asm/uaccess.h>
  94995. #include <asm/unistd.h>
  94996. @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
  94997. unsigned int sysctl_net_busy_poll __read_mostly;
  94998. #endif
  94999. +#include <linux/grsock.h>
  95000. +
  95001. static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
  95002. static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
  95003. unsigned long nr_segs, loff_t pos);
  95004. @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
  95005. */
  95006. static DEFINE_SPINLOCK(net_family_lock);
  95007. -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
  95008. +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
  95009. /*
  95010. * Statistics counters of the socket lists
  95011. @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
  95012. &sockfs_dentry_operations, SOCKFS_MAGIC);
  95013. }
  95014. -static struct vfsmount *sock_mnt __read_mostly;
  95015. +struct vfsmount *sock_mnt __read_mostly;
  95016. static struct file_system_type sock_fs_type = {
  95017. .name = "sockfs",
  95018. @@ -1256,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
  95019. return -EAFNOSUPPORT;
  95020. if (type < 0 || type >= SOCK_MAX)
  95021. return -EINVAL;
  95022. + if (protocol < 0)
  95023. + return -EINVAL;
  95024. /* Compatibility.
  95025. @@ -1276,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
  95026. if (err)
  95027. return err;
  95028. + if(!kern && !gr_search_socket(family, type, protocol)) {
  95029. + if (rcu_access_pointer(net_families[family]) == NULL)
  95030. + return -EAFNOSUPPORT;
  95031. + else
  95032. + return -EACCES;
  95033. + }
  95034. +
  95035. + if (!kern && gr_handle_sock_all(family, type, protocol)) {
  95036. + if (rcu_access_pointer(net_families[family]) == NULL)
  95037. + return -EAFNOSUPPORT;
  95038. + else
  95039. + return -EACCES;
  95040. + }
  95041. +
  95042. /*
  95043. * Allocate the socket and allow the family to set things up. if
  95044. * the protocol is 0, the family is instructed to select an appropriate
  95045. @@ -1527,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
  95046. if (sock) {
  95047. err = move_addr_to_kernel(umyaddr, addrlen, &address);
  95048. if (err >= 0) {
  95049. + if (gr_handle_sock_server((struct sockaddr *)&address)) {
  95050. + err = -EACCES;
  95051. + goto error;
  95052. + }
  95053. + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
  95054. + if (err)
  95055. + goto error;
  95056. +
  95057. err = security_socket_bind(sock,
  95058. (struct sockaddr *)&address,
  95059. addrlen);
  95060. @@ -1535,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
  95061. (struct sockaddr *)
  95062. &address, addrlen);
  95063. }
  95064. +error:
  95065. fput_light(sock->file, fput_needed);
  95066. }
  95067. return err;
  95068. @@ -1558,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
  95069. if ((unsigned int)backlog > somaxconn)
  95070. backlog = somaxconn;
  95071. + if (gr_handle_sock_server_other(sock->sk)) {
  95072. + err = -EPERM;
  95073. + goto error;
  95074. + }
  95075. +
  95076. + err = gr_search_listen(sock);
  95077. + if (err)
  95078. + goto error;
  95079. +
  95080. err = security_socket_listen(sock, backlog);
  95081. if (!err)
  95082. err = sock->ops->listen(sock, backlog);
  95083. +error:
  95084. fput_light(sock->file, fput_needed);
  95085. }
  95086. return err;
  95087. @@ -1605,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
  95088. newsock->type = sock->type;
  95089. newsock->ops = sock->ops;
  95090. + if (gr_handle_sock_server_other(sock->sk)) {
  95091. + err = -EPERM;
  95092. + sock_release(newsock);
  95093. + goto out_put;
  95094. + }
  95095. +
  95096. + err = gr_search_accept(sock);
  95097. + if (err) {
  95098. + sock_release(newsock);
  95099. + goto out_put;
  95100. + }
  95101. +
  95102. /*
  95103. * We don't need try_module_get here, as the listening socket (sock)
  95104. * has the protocol module (sock->ops->owner) held.
  95105. @@ -1650,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
  95106. fd_install(newfd, newfile);
  95107. err = newfd;
  95108. + gr_attach_curr_ip(newsock->sk);
  95109. +
  95110. out_put:
  95111. fput_light(sock->file, fput_needed);
  95112. out:
  95113. @@ -1682,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
  95114. int, addrlen)
  95115. {
  95116. struct socket *sock;
  95117. + struct sockaddr *sck;
  95118. struct sockaddr_storage address;
  95119. int err, fput_needed;
  95120. @@ -1692,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
  95121. if (err < 0)
  95122. goto out_put;
  95123. + sck = (struct sockaddr *)&address;
  95124. +
  95125. + if (gr_handle_sock_client(sck)) {
  95126. + err = -EACCES;
  95127. + goto out_put;
  95128. + }
  95129. +
  95130. + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
  95131. + if (err)
  95132. + goto out_put;
  95133. +
  95134. err =
  95135. security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
  95136. if (err)
  95137. @@ -1773,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
  95138. * the protocol.
  95139. */
  95140. +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
  95141. +
  95142. SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
  95143. unsigned int, flags, struct sockaddr __user *, addr,
  95144. int, addr_len)
  95145. @@ -1839,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
  95146. struct socket *sock;
  95147. struct iovec iov;
  95148. struct msghdr msg;
  95149. - struct sockaddr_storage address;
  95150. + struct sockaddr_storage address = { };
  95151. int err, err2;
  95152. int fput_needed;
  95153. @@ -2065,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
  95154. * checking falls down on this.
  95155. */
  95156. if (copy_from_user(ctl_buf,
  95157. - (void __user __force *)msg_sys->msg_control,
  95158. + (void __force_user *)msg_sys->msg_control,
  95159. ctl_len))
  95160. goto out_freectl;
  95161. msg_sys->msg_control = ctl_buf;
  95162. @@ -2216,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
  95163. int err, total_len, len;
  95164. /* kernel mode address */
  95165. - struct sockaddr_storage addr;
  95166. + struct sockaddr_storage addr = { };
  95167. /* user mode address pointers */
  95168. struct sockaddr __user *uaddr;
  95169. @@ -2245,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
  95170. /* Save the user-mode address (verify_iovec will change the
  95171. * kernel msghdr to use the kernel address space)
  95172. */
  95173. - uaddr = (__force void __user *)msg_sys->msg_name;
  95174. + uaddr = (void __force_user *)msg_sys->msg_name;
  95175. uaddr_len = COMPAT_NAMELEN(msg);
  95176. if (MSG_CMSG_COMPAT & flags)
  95177. err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
  95178. @@ -2889,7 +2955,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
  95179. ifr = compat_alloc_user_space(buf_size);
  95180. rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
  95181. - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
  95182. + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
  95183. return -EFAULT;
  95184. if (put_user(convert_in ? rxnfc : compat_ptr(data),
  95185. @@ -3000,7 +3066,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
  95186. old_fs = get_fs();
  95187. set_fs(KERNEL_DS);
  95188. err = dev_ioctl(net, cmd,
  95189. - (struct ifreq __user __force *) &kifr);
  95190. + (struct ifreq __force_user *) &kifr);
  95191. set_fs(old_fs);
  95192. return err;
  95193. @@ -3093,7 +3159,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
  95194. old_fs = get_fs();
  95195. set_fs(KERNEL_DS);
  95196. - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
  95197. + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
  95198. set_fs(old_fs);
  95199. if (cmd == SIOCGIFMAP && !err) {
  95200. @@ -3177,7 +3243,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
  95201. ret |= get_user(rtdev, &(ur4->rt_dev));
  95202. if (rtdev) {
  95203. ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
  95204. - r4.rt_dev = (char __user __force *)devname;
  95205. + r4.rt_dev = (char __force_user *)devname;
  95206. devname[15] = 0;
  95207. } else
  95208. r4.rt_dev = NULL;
  95209. @@ -3404,8 +3470,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
  95210. int __user *uoptlen;
  95211. int err;
  95212. - uoptval = (char __user __force *) optval;
  95213. - uoptlen = (int __user __force *) optlen;
  95214. + uoptval = (char __force_user *) optval;
  95215. + uoptlen = (int __force_user *) optlen;
  95216. set_fs(KERNEL_DS);
  95217. if (level == SOL_SOCKET)
  95218. @@ -3425,7 +3491,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
  95219. char __user *uoptval;
  95220. int err;
  95221. - uoptval = (char __user __force *) optval;
  95222. + uoptval = (char __force_user *) optval;
  95223. set_fs(KERNEL_DS);
  95224. if (level == SOL_SOCKET)
  95225. diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
  95226. index 0f73f45..a96aa52 100644
  95227. --- a/net/sunrpc/auth_gss/svcauth_gss.c
  95228. +++ b/net/sunrpc/auth_gss/svcauth_gss.c
  95229. @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
  95230. uint64_t *handle)
  95231. {
  95232. struct rsc rsci, *rscp = NULL;
  95233. - static atomic64_t ctxhctr;
  95234. + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
  95235. long long ctxh;
  95236. struct gss_api_mech *gm = NULL;
  95237. time_t expiry;
  95238. @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
  95239. status = -ENOMEM;
  95240. /* the handle needs to be just a unique id,
  95241. * use a static counter */
  95242. - ctxh = atomic64_inc_return(&ctxhctr);
  95243. + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
  95244. /* make a copy for the caller */
  95245. *handle = ctxh;
  95246. diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
  95247. index ae333c1..18521f0 100644
  95248. --- a/net/sunrpc/cache.c
  95249. +++ b/net/sunrpc/cache.c
  95250. @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
  95251. struct sunrpc_net *sn;
  95252. sn = net_generic(net, sunrpc_net_id);
  95253. - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
  95254. + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
  95255. if (cd->u.procfs.proc_ent == NULL)
  95256. goto out_nomem;
  95257. cd->u.procfs.channel_ent = NULL;
  95258. diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
  95259. index 3ea5cda..bfb3e08 100644
  95260. --- a/net/sunrpc/clnt.c
  95261. +++ b/net/sunrpc/clnt.c
  95262. @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
  95263. (RPC_IS_ASYNC(task) ? "async" : "sync"));
  95264. /* Increment call count */
  95265. - task->tk_msg.rpc_proc->p_count++;
  95266. + pax_open_kernel();
  95267. + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
  95268. + pax_close_kernel();
  95269. clnt->cl_stats->rpccnt++;
  95270. task->tk_action = call_reserve;
  95271. }
  95272. diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
  95273. index ff3cc4b..7612a9e 100644
  95274. --- a/net/sunrpc/sched.c
  95275. +++ b/net/sunrpc/sched.c
  95276. @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
  95277. #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
  95278. static void rpc_task_set_debuginfo(struct rpc_task *task)
  95279. {
  95280. - static atomic_t rpc_pid;
  95281. + static atomic_unchecked_t rpc_pid;
  95282. - task->tk_pid = atomic_inc_return(&rpc_pid);
  95283. + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
  95284. }
  95285. #else
  95286. static inline void rpc_task_set_debuginfo(struct rpc_task *task)
  95287. diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
  95288. index 5453049..465669a 100644
  95289. --- a/net/sunrpc/stats.c
  95290. +++ b/net/sunrpc/stats.c
  95291. @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
  95292. dprintk("RPC: registering /proc/net/rpc\n");
  95293. sn = net_generic(net, sunrpc_net_id);
  95294. - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
  95295. + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
  95296. if (sn->proc_net_rpc == NULL)
  95297. return -ENOMEM;
  95298. diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
  95299. index 5de6801..b4e330d 100644
  95300. --- a/net/sunrpc/svc.c
  95301. +++ b/net/sunrpc/svc.c
  95302. @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
  95303. svc_putnl(resv, RPC_SUCCESS);
  95304. /* Bump per-procedure stats counter */
  95305. - procp->pc_count++;
  95306. + pax_open_kernel();
  95307. + (*(unsigned int *)&procp->pc_count)++;
  95308. + pax_close_kernel();
  95309. /* Initialize storage for argp and resp */
  95310. memset(rqstp->rq_argp, 0, procp->pc_argsize);
  95311. diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
  95312. index 621ca7b..59421dd 100644
  95313. --- a/net/sunrpc/svcauth_unix.c
  95314. +++ b/net/sunrpc/svcauth_unix.c
  95315. @@ -414,7 +414,7 @@ struct unix_gid {
  95316. struct group_info *gi;
  95317. };
  95318. -static int unix_gid_hash(kuid_t uid)
  95319. +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
  95320. {
  95321. return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
  95322. }
  95323. @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
  95324. (*bpp)[-1] = '\n';
  95325. }
  95326. -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
  95327. +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
  95328. static int unix_gid_parse(struct cache_detail *cd,
  95329. char *mesg, int mlen)
  95330. diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
  95331. index c1b6270..05089c1 100644
  95332. --- a/net/sunrpc/xprtrdma/svc_rdma.c
  95333. +++ b/net/sunrpc/xprtrdma/svc_rdma.c
  95334. @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
  95335. static unsigned int min_max_inline = 4096;
  95336. static unsigned int max_max_inline = 65536;
  95337. -atomic_t rdma_stat_recv;
  95338. -atomic_t rdma_stat_read;
  95339. -atomic_t rdma_stat_write;
  95340. -atomic_t rdma_stat_sq_starve;
  95341. -atomic_t rdma_stat_rq_starve;
  95342. -atomic_t rdma_stat_rq_poll;
  95343. -atomic_t rdma_stat_rq_prod;
  95344. -atomic_t rdma_stat_sq_poll;
  95345. -atomic_t rdma_stat_sq_prod;
  95346. +atomic_unchecked_t rdma_stat_recv;
  95347. +atomic_unchecked_t rdma_stat_read;
  95348. +atomic_unchecked_t rdma_stat_write;
  95349. +atomic_unchecked_t rdma_stat_sq_starve;
  95350. +atomic_unchecked_t rdma_stat_rq_starve;
  95351. +atomic_unchecked_t rdma_stat_rq_poll;
  95352. +atomic_unchecked_t rdma_stat_rq_prod;
  95353. +atomic_unchecked_t rdma_stat_sq_poll;
  95354. +atomic_unchecked_t rdma_stat_sq_prod;
  95355. /* Temporary NFS request map and context caches */
  95356. struct kmem_cache *svc_rdma_map_cachep;
  95357. @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
  95358. len -= *ppos;
  95359. if (len > *lenp)
  95360. len = *lenp;
  95361. - if (len && copy_to_user(buffer, str_buf, len))
  95362. + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
  95363. return -EFAULT;
  95364. *lenp = len;
  95365. *ppos += len;
  95366. @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
  95367. {
  95368. .procname = "rdma_stat_read",
  95369. .data = &rdma_stat_read,
  95370. - .maxlen = sizeof(atomic_t),
  95371. + .maxlen = sizeof(atomic_unchecked_t),
  95372. .mode = 0644,
  95373. .proc_handler = read_reset_stat,
  95374. },
  95375. {
  95376. .procname = "rdma_stat_recv",
  95377. .data = &rdma_stat_recv,
  95378. - .maxlen = sizeof(atomic_t),
  95379. + .maxlen = sizeof(atomic_unchecked_t),
  95380. .mode = 0644,
  95381. .proc_handler = read_reset_stat,
  95382. },
  95383. {
  95384. .procname = "rdma_stat_write",
  95385. .data = &rdma_stat_write,
  95386. - .maxlen = sizeof(atomic_t),
  95387. + .maxlen = sizeof(atomic_unchecked_t),
  95388. .mode = 0644,
  95389. .proc_handler = read_reset_stat,
  95390. },
  95391. {
  95392. .procname = "rdma_stat_sq_starve",
  95393. .data = &rdma_stat_sq_starve,
  95394. - .maxlen = sizeof(atomic_t),
  95395. + .maxlen = sizeof(atomic_unchecked_t),
  95396. .mode = 0644,
  95397. .proc_handler = read_reset_stat,
  95398. },
  95399. {
  95400. .procname = "rdma_stat_rq_starve",
  95401. .data = &rdma_stat_rq_starve,
  95402. - .maxlen = sizeof(atomic_t),
  95403. + .maxlen = sizeof(atomic_unchecked_t),
  95404. .mode = 0644,
  95405. .proc_handler = read_reset_stat,
  95406. },
  95407. {
  95408. .procname = "rdma_stat_rq_poll",
  95409. .data = &rdma_stat_rq_poll,
  95410. - .maxlen = sizeof(atomic_t),
  95411. + .maxlen = sizeof(atomic_unchecked_t),
  95412. .mode = 0644,
  95413. .proc_handler = read_reset_stat,
  95414. },
  95415. {
  95416. .procname = "rdma_stat_rq_prod",
  95417. .data = &rdma_stat_rq_prod,
  95418. - .maxlen = sizeof(atomic_t),
  95419. + .maxlen = sizeof(atomic_unchecked_t),
  95420. .mode = 0644,
  95421. .proc_handler = read_reset_stat,
  95422. },
  95423. {
  95424. .procname = "rdma_stat_sq_poll",
  95425. .data = &rdma_stat_sq_poll,
  95426. - .maxlen = sizeof(atomic_t),
  95427. + .maxlen = sizeof(atomic_unchecked_t),
  95428. .mode = 0644,
  95429. .proc_handler = read_reset_stat,
  95430. },
  95431. {
  95432. .procname = "rdma_stat_sq_prod",
  95433. .data = &rdma_stat_sq_prod,
  95434. - .maxlen = sizeof(atomic_t),
  95435. + .maxlen = sizeof(atomic_unchecked_t),
  95436. .mode = 0644,
  95437. .proc_handler = read_reset_stat,
  95438. },
  95439. diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
  95440. index 0ce7552..d074459 100644
  95441. --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
  95442. +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
  95443. @@ -501,7 +501,7 @@ next_sge:
  95444. svc_rdma_put_context(ctxt, 0);
  95445. goto out;
  95446. }
  95447. - atomic_inc(&rdma_stat_read);
  95448. + atomic_inc_unchecked(&rdma_stat_read);
  95449. if (read_wr.num_sge < chl_map->ch[ch_no].count) {
  95450. chl_map->ch[ch_no].count -= read_wr.num_sge;
  95451. @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
  95452. dto_q);
  95453. list_del_init(&ctxt->dto_q);
  95454. } else {
  95455. - atomic_inc(&rdma_stat_rq_starve);
  95456. + atomic_inc_unchecked(&rdma_stat_rq_starve);
  95457. clear_bit(XPT_DATA, &xprt->xpt_flags);
  95458. ctxt = NULL;
  95459. }
  95460. @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
  95461. dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
  95462. ctxt, rdma_xprt, rqstp, ctxt->wc_status);
  95463. BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
  95464. - atomic_inc(&rdma_stat_recv);
  95465. + atomic_inc_unchecked(&rdma_stat_recv);
  95466. /* Build up the XDR from the receive buffers. */
  95467. rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
  95468. diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
  95469. index c1d124d..acfc59e 100644
  95470. --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
  95471. +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
  95472. @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
  95473. write_wr.wr.rdma.remote_addr = to;
  95474. /* Post It */
  95475. - atomic_inc(&rdma_stat_write);
  95476. + atomic_inc_unchecked(&rdma_stat_write);
  95477. if (svc_rdma_send(xprt, &write_wr))
  95478. goto err;
  95479. return 0;
  95480. diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
  95481. index 62e4f9b..dd3f2d7 100644
  95482. --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
  95483. +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
  95484. @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
  95485. return;
  95486. ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
  95487. - atomic_inc(&rdma_stat_rq_poll);
  95488. + atomic_inc_unchecked(&rdma_stat_rq_poll);
  95489. while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
  95490. ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
  95491. @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
  95492. }
  95493. if (ctxt)
  95494. - atomic_inc(&rdma_stat_rq_prod);
  95495. + atomic_inc_unchecked(&rdma_stat_rq_prod);
  95496. set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
  95497. /*
  95498. @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
  95499. return;
  95500. ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
  95501. - atomic_inc(&rdma_stat_sq_poll);
  95502. + atomic_inc_unchecked(&rdma_stat_sq_poll);
  95503. while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
  95504. if (wc.status != IB_WC_SUCCESS)
  95505. /* Close the transport */
  95506. @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
  95507. }
  95508. if (ctxt)
  95509. - atomic_inc(&rdma_stat_sq_prod);
  95510. + atomic_inc_unchecked(&rdma_stat_sq_prod);
  95511. }
  95512. static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
  95513. @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
  95514. spin_lock_bh(&xprt->sc_lock);
  95515. if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
  95516. spin_unlock_bh(&xprt->sc_lock);
  95517. - atomic_inc(&rdma_stat_sq_starve);
  95518. + atomic_inc_unchecked(&rdma_stat_sq_starve);
  95519. /* See if we can opportunistically reap SQ WR to make room */
  95520. sq_cq_reap(xprt);
  95521. diff --git a/net/sysctl_net.c b/net/sysctl_net.c
  95522. index e7000be..e3b0ba7 100644
  95523. --- a/net/sysctl_net.c
  95524. +++ b/net/sysctl_net.c
  95525. @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
  95526. kgid_t root_gid = make_kgid(net->user_ns, 0);
  95527. /* Allow network administrator to have same access as root. */
  95528. - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
  95529. + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
  95530. uid_eq(root_uid, current_euid())) {
  95531. int mode = (table->mode >> 6) & 7;
  95532. return (mode << 6) | (mode << 3) | mode;
  95533. diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
  95534. index 6424372..afd36e9 100644
  95535. --- a/net/tipc/subscr.c
  95536. +++ b/net/tipc/subscr.c
  95537. @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
  95538. struct tipc_subscriber *subscriber = sub->subscriber;
  95539. struct kvec msg_sect;
  95540. - msg_sect.iov_base = (void *)&sub->evt;
  95541. + msg_sect.iov_base = &sub->evt;
  95542. msg_sect.iov_len = sizeof(struct tipc_event);
  95543. sub->evt.event = htohl(event, sub->swap);
  95544. sub->evt.found_lower = htohl(found_lower, sub->swap);
  95545. diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
  95546. index 94404f1..5782191 100644
  95547. --- a/net/unix/af_unix.c
  95548. +++ b/net/unix/af_unix.c
  95549. @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
  95550. err = -ECONNREFUSED;
  95551. if (!S_ISSOCK(inode->i_mode))
  95552. goto put_fail;
  95553. +
  95554. + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
  95555. + err = -EACCES;
  95556. + goto put_fail;
  95557. + }
  95558. +
  95559. u = unix_find_socket_byinode(inode);
  95560. if (!u)
  95561. goto put_fail;
  95562. @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
  95563. if (u) {
  95564. struct dentry *dentry;
  95565. dentry = unix_sk(u)->path.dentry;
  95566. +
  95567. + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
  95568. + err = -EPERM;
  95569. + sock_put(u);
  95570. + goto fail;
  95571. + }
  95572. +
  95573. if (dentry)
  95574. touch_atime(&unix_sk(u)->path);
  95575. } else
  95576. @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
  95577. */
  95578. err = security_path_mknod(&path, dentry, mode, 0);
  95579. if (!err) {
  95580. + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
  95581. + err = -EACCES;
  95582. + goto out;
  95583. + }
  95584. err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
  95585. if (!err) {
  95586. res->mnt = mntget(path.mnt);
  95587. res->dentry = dget(dentry);
  95588. + gr_handle_create(dentry, path.mnt);
  95589. }
  95590. }
  95591. +out:
  95592. done_path_create(&path, dentry);
  95593. return err;
  95594. }
  95595. @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
  95596. seq_puts(seq, "Num RefCount Protocol Flags Type St "
  95597. "Inode Path\n");
  95598. else {
  95599. - struct sock *s = v;
  95600. + struct sock *s = v, *peer;
  95601. struct unix_sock *u = unix_sk(s);
  95602. unix_state_lock(s);
  95603. + peer = unix_peer(s);
  95604. + unix_state_unlock(s);
  95605. +
  95606. + unix_state_double_lock(s, peer);
  95607. seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
  95608. s,
  95609. @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
  95610. }
  95611. for ( ; i < len; i++)
  95612. seq_putc(seq, u->addr->name->sun_path[i]);
  95613. - }
  95614. - unix_state_unlock(s);
  95615. + } else if (peer)
  95616. + seq_printf(seq, " P%lu", sock_i_ino(peer));
  95617. +
  95618. + unix_state_double_unlock(s, peer);
  95619. seq_putc(seq, '\n');
  95620. }
  95621. diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
  95622. index b3d5150..ff3a837 100644
  95623. --- a/net/unix/sysctl_net_unix.c
  95624. +++ b/net/unix/sysctl_net_unix.c
  95625. @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
  95626. int __net_init unix_sysctl_register(struct net *net)
  95627. {
  95628. - struct ctl_table *table;
  95629. + ctl_table_no_const *table;
  95630. table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
  95631. if (table == NULL)
  95632. diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
  95633. index 9a73074..aecba9a 100644
  95634. --- a/net/vmw_vsock/vmci_transport_notify.c
  95635. +++ b/net/vmw_vsock/vmci_transport_notify.c
  95636. @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
  95637. /* Socket control packet based operations. */
  95638. struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
  95639. - vmci_transport_notify_pkt_socket_init,
  95640. - vmci_transport_notify_pkt_socket_destruct,
  95641. - vmci_transport_notify_pkt_poll_in,
  95642. - vmci_transport_notify_pkt_poll_out,
  95643. - vmci_transport_notify_pkt_handle_pkt,
  95644. - vmci_transport_notify_pkt_recv_init,
  95645. - vmci_transport_notify_pkt_recv_pre_block,
  95646. - vmci_transport_notify_pkt_recv_pre_dequeue,
  95647. - vmci_transport_notify_pkt_recv_post_dequeue,
  95648. - vmci_transport_notify_pkt_send_init,
  95649. - vmci_transport_notify_pkt_send_pre_block,
  95650. - vmci_transport_notify_pkt_send_pre_enqueue,
  95651. - vmci_transport_notify_pkt_send_post_enqueue,
  95652. - vmci_transport_notify_pkt_process_request,
  95653. - vmci_transport_notify_pkt_process_negotiate,
  95654. + .socket_init = vmci_transport_notify_pkt_socket_init,
  95655. + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
  95656. + .poll_in = vmci_transport_notify_pkt_poll_in,
  95657. + .poll_out = vmci_transport_notify_pkt_poll_out,
  95658. + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
  95659. + .recv_init = vmci_transport_notify_pkt_recv_init,
  95660. + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
  95661. + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
  95662. + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
  95663. + .send_init = vmci_transport_notify_pkt_send_init,
  95664. + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
  95665. + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
  95666. + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
  95667. + .process_request = vmci_transport_notify_pkt_process_request,
  95668. + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
  95669. };
  95670. diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
  95671. index 622bd7a..b92086c 100644
  95672. --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
  95673. +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
  95674. @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
  95675. /* Socket always on control packet based operations. */
  95676. struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
  95677. - vmci_transport_notify_pkt_socket_init,
  95678. - vmci_transport_notify_pkt_socket_destruct,
  95679. - vmci_transport_notify_pkt_poll_in,
  95680. - vmci_transport_notify_pkt_poll_out,
  95681. - vmci_transport_notify_pkt_handle_pkt,
  95682. - vmci_transport_notify_pkt_recv_init,
  95683. - vmci_transport_notify_pkt_recv_pre_block,
  95684. - vmci_transport_notify_pkt_recv_pre_dequeue,
  95685. - vmci_transport_notify_pkt_recv_post_dequeue,
  95686. - vmci_transport_notify_pkt_send_init,
  95687. - vmci_transport_notify_pkt_send_pre_block,
  95688. - vmci_transport_notify_pkt_send_pre_enqueue,
  95689. - vmci_transport_notify_pkt_send_post_enqueue,
  95690. - vmci_transport_notify_pkt_process_request,
  95691. - vmci_transport_notify_pkt_process_negotiate,
  95692. + .socket_init = vmci_transport_notify_pkt_socket_init,
  95693. + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
  95694. + .poll_in = vmci_transport_notify_pkt_poll_in,
  95695. + .poll_out = vmci_transport_notify_pkt_poll_out,
  95696. + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
  95697. + .recv_init = vmci_transport_notify_pkt_recv_init,
  95698. + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
  95699. + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
  95700. + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
  95701. + .send_init = vmci_transport_notify_pkt_send_init,
  95702. + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
  95703. + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
  95704. + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
  95705. + .process_request = vmci_transport_notify_pkt_process_request,
  95706. + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
  95707. };
  95708. diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
  95709. index c8717c1..08539f5 100644
  95710. --- a/net/wireless/wext-core.c
  95711. +++ b/net/wireless/wext-core.c
  95712. @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
  95713. */
  95714. /* Support for very large requests */
  95715. - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
  95716. - (user_length > descr->max_tokens)) {
  95717. + if (user_length > descr->max_tokens) {
  95718. /* Allow userspace to GET more than max so
  95719. * we can support any size GET requests.
  95720. * There is still a limit : -ENOMEM.
  95721. @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
  95722. }
  95723. }
  95724. - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
  95725. - /*
  95726. - * If this is a GET, but not NOMAX, it means that the extra
  95727. - * data is not bounded by userspace, but by max_tokens. Thus
  95728. - * set the length to max_tokens. This matches the extra data
  95729. - * allocation.
  95730. - * The driver should fill it with the number of tokens it
  95731. - * provided, and it may check iwp->length rather than having
  95732. - * knowledge of max_tokens. If the driver doesn't change the
  95733. - * iwp->length, this ioctl just copies back max_token tokens
  95734. - * filled with zeroes. Hopefully the driver isn't claiming
  95735. - * them to be valid data.
  95736. - */
  95737. - iwp->length = descr->max_tokens;
  95738. - }
  95739. -
  95740. err = handler(dev, info, (union iwreq_data *) iwp, extra);
  95741. iwp->length += essid_compat;
  95742. diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
  95743. index 4323952..a06dfe1 100644
  95744. --- a/net/x25/sysctl_net_x25.c
  95745. +++ b/net/x25/sysctl_net_x25.c
  95746. @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
  95747. .mode = 0644,
  95748. .proc_handler = proc_dointvec,
  95749. },
  95750. - { 0, },
  95751. + { },
  95752. };
  95753. void __init x25_register_sysctl(void)
  95754. diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
  95755. index 0917f04..f4e3d8c 100644
  95756. --- a/net/x25/x25_proc.c
  95757. +++ b/net/x25/x25_proc.c
  95758. @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
  95759. int __init x25_proc_init(void)
  95760. {
  95761. - if (!proc_mkdir("x25", init_net.proc_net))
  95762. + if (!proc_mkdir_restrict("x25", init_net.proc_net))
  95763. return -ENOMEM;
  95764. if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
  95765. diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
  95766. index 1d5c7bf..f762f1f 100644
  95767. --- a/net/xfrm/xfrm_policy.c
  95768. +++ b/net/xfrm/xfrm_policy.c
  95769. @@ -327,7 +327,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
  95770. {
  95771. policy->walk.dead = 1;
  95772. - atomic_inc(&policy->genid);
  95773. + atomic_inc_unchecked(&policy->genid);
  95774. if (del_timer(&policy->polq.hold_timer))
  95775. xfrm_pol_put(policy);
  95776. @@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
  95777. hlist_add_head(&policy->bydst, chain);
  95778. xfrm_pol_hold(policy);
  95779. net->xfrm.policy_count[dir]++;
  95780. - atomic_inc(&flow_cache_genid);
  95781. + atomic_inc_unchecked(&flow_cache_genid);
  95782. /* After previous checking, family can either be AF_INET or AF_INET6 */
  95783. if (policy->family == AF_INET)
  95784. @@ -1761,7 +1761,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
  95785. xdst->num_pols = num_pols;
  95786. memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
  95787. - xdst->policy_genid = atomic_read(&pols[0]->genid);
  95788. + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
  95789. return xdst;
  95790. }
  95791. @@ -2572,11 +2572,12 @@ void xfrm_garbage_collect(struct net *net)
  95792. }
  95793. EXPORT_SYMBOL(xfrm_garbage_collect);
  95794. -static void xfrm_garbage_collect_deferred(struct net *net)
  95795. +void xfrm_garbage_collect_deferred(struct net *net)
  95796. {
  95797. flow_cache_flush_deferred();
  95798. __xfrm_garbage_collect(net);
  95799. }
  95800. +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
  95801. static void xfrm_init_pmtu(struct dst_entry *dst)
  95802. {
  95803. @@ -2626,7 +2627,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
  95804. if (xdst->xfrm_genid != dst->xfrm->genid)
  95805. return 0;
  95806. if (xdst->num_pols > 0 &&
  95807. - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
  95808. + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
  95809. return 0;
  95810. mtu = dst_mtu(dst->child);
  95811. @@ -2714,8 +2715,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
  95812. dst_ops->link_failure = xfrm_link_failure;
  95813. if (likely(dst_ops->neigh_lookup == NULL))
  95814. dst_ops->neigh_lookup = xfrm_neigh_lookup;
  95815. - if (likely(afinfo->garbage_collect == NULL))
  95816. - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
  95817. rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
  95818. }
  95819. spin_unlock(&xfrm_policy_afinfo_lock);
  95820. @@ -2769,7 +2768,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
  95821. dst_ops->check = NULL;
  95822. dst_ops->negative_advice = NULL;
  95823. dst_ops->link_failure = NULL;
  95824. - afinfo->garbage_collect = NULL;
  95825. }
  95826. return err;
  95827. }
  95828. @@ -3159,7 +3157,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
  95829. sizeof(pol->xfrm_vec[i].saddr));
  95830. pol->xfrm_vec[i].encap_family = mp->new_family;
  95831. /* flush bundles */
  95832. - atomic_inc(&pol->genid);
  95833. + atomic_inc_unchecked(&pol->genid);
  95834. }
  95835. }
  95836. diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
  95837. index 40f1b3e..e33fdfa 100644
  95838. --- a/net/xfrm/xfrm_state.c
  95839. +++ b/net/xfrm/xfrm_state.c
  95840. @@ -172,12 +172,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
  95841. if (unlikely(afinfo == NULL))
  95842. return -EAFNOSUPPORT;
  95843. - typemap = afinfo->type_map;
  95844. + typemap = (const struct xfrm_type **)afinfo->type_map;
  95845. spin_lock_bh(&xfrm_type_lock);
  95846. - if (likely(typemap[type->proto] == NULL))
  95847. + if (likely(typemap[type->proto] == NULL)) {
  95848. + pax_open_kernel();
  95849. typemap[type->proto] = type;
  95850. - else
  95851. + pax_close_kernel();
  95852. + } else
  95853. err = -EEXIST;
  95854. spin_unlock_bh(&xfrm_type_lock);
  95855. xfrm_state_put_afinfo(afinfo);
  95856. @@ -193,13 +195,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
  95857. if (unlikely(afinfo == NULL))
  95858. return -EAFNOSUPPORT;
  95859. - typemap = afinfo->type_map;
  95860. + typemap = (const struct xfrm_type **)afinfo->type_map;
  95861. spin_lock_bh(&xfrm_type_lock);
  95862. if (unlikely(typemap[type->proto] != type))
  95863. err = -ENOENT;
  95864. - else
  95865. + else {
  95866. + pax_open_kernel();
  95867. typemap[type->proto] = NULL;
  95868. + pax_close_kernel();
  95869. + }
  95870. spin_unlock_bh(&xfrm_type_lock);
  95871. xfrm_state_put_afinfo(afinfo);
  95872. return err;
  95873. @@ -209,7 +214,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
  95874. static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
  95875. {
  95876. struct xfrm_state_afinfo *afinfo;
  95877. - const struct xfrm_type **typemap;
  95878. const struct xfrm_type *type;
  95879. int modload_attempted = 0;
  95880. @@ -217,9 +221,8 @@ retry:
  95881. afinfo = xfrm_state_get_afinfo(family);
  95882. if (unlikely(afinfo == NULL))
  95883. return NULL;
  95884. - typemap = afinfo->type_map;
  95885. - type = typemap[proto];
  95886. + type = afinfo->type_map[proto];
  95887. if (unlikely(type && !try_module_get(type->owner)))
  95888. type = NULL;
  95889. if (!type && !modload_attempted) {
  95890. @@ -253,7 +256,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
  95891. return -EAFNOSUPPORT;
  95892. err = -EEXIST;
  95893. - modemap = afinfo->mode_map;
  95894. + modemap = (struct xfrm_mode **)afinfo->mode_map;
  95895. spin_lock_bh(&xfrm_mode_lock);
  95896. if (modemap[mode->encap])
  95897. goto out;
  95898. @@ -262,8 +265,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
  95899. if (!try_module_get(afinfo->owner))
  95900. goto out;
  95901. - mode->afinfo = afinfo;
  95902. + pax_open_kernel();
  95903. + *(const void **)&mode->afinfo = afinfo;
  95904. modemap[mode->encap] = mode;
  95905. + pax_close_kernel();
  95906. err = 0;
  95907. out:
  95908. @@ -287,10 +292,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
  95909. return -EAFNOSUPPORT;
  95910. err = -ENOENT;
  95911. - modemap = afinfo->mode_map;
  95912. + modemap = (struct xfrm_mode **)afinfo->mode_map;
  95913. spin_lock_bh(&xfrm_mode_lock);
  95914. if (likely(modemap[mode->encap] == mode)) {
  95915. + pax_open_kernel();
  95916. modemap[mode->encap] = NULL;
  95917. + pax_close_kernel();
  95918. module_put(mode->afinfo->owner);
  95919. err = 0;
  95920. }
  95921. @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
  95922. u32 xfrm_get_acqseq(void)
  95923. {
  95924. u32 res;
  95925. - static atomic_t acqseq;
  95926. + static atomic_unchecked_t acqseq;
  95927. do {
  95928. - res = atomic_inc_return(&acqseq);
  95929. + res = atomic_inc_return_unchecked(&acqseq);
  95930. } while (!res);
  95931. return res;
  95932. diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
  95933. index 05a6e3d..6716ec9 100644
  95934. --- a/net/xfrm/xfrm_sysctl.c
  95935. +++ b/net/xfrm/xfrm_sysctl.c
  95936. @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
  95937. int __net_init xfrm_sysctl_init(struct net *net)
  95938. {
  95939. - struct ctl_table *table;
  95940. + ctl_table_no_const *table;
  95941. __xfrm_sysctl_init(net);
  95942. diff --git a/scripts/Makefile b/scripts/Makefile
  95943. index 01e7adb..6176d5d 100644
  95944. --- a/scripts/Makefile
  95945. +++ b/scripts/Makefile
  95946. @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
  95947. # Let clean descend into subdirs
  95948. subdir- += basic kconfig package selinux
  95949. +
  95950. +clean-files := randstruct.seed
  95951. diff --git a/scripts/Makefile.build b/scripts/Makefile.build
  95952. index d5d859c..781cbcb 100644
  95953. --- a/scripts/Makefile.build
  95954. +++ b/scripts/Makefile.build
  95955. @@ -111,7 +111,7 @@ endif
  95956. endif
  95957. # Do not include host rules unless needed
  95958. -ifneq ($(hostprogs-y)$(hostprogs-m),)
  95959. +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
  95960. include scripts/Makefile.host
  95961. endif
  95962. diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
  95963. index 686cb0d..9d653bf 100644
  95964. --- a/scripts/Makefile.clean
  95965. +++ b/scripts/Makefile.clean
  95966. @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
  95967. __clean-files := $(extra-y) $(always) \
  95968. $(targets) $(clean-files) \
  95969. $(host-progs) \
  95970. - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
  95971. + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
  95972. + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
  95973. __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
  95974. diff --git a/scripts/Makefile.host b/scripts/Makefile.host
  95975. index 1ac414f..38575f7 100644
  95976. --- a/scripts/Makefile.host
  95977. +++ b/scripts/Makefile.host
  95978. @@ -31,6 +31,8 @@
  95979. # Note: Shared libraries consisting of C++ files are not supported
  95980. __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
  95981. +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
  95982. +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
  95983. # C code
  95984. # Executables compiled from a single .c file
  95985. @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
  95986. # Shared libaries (only .c supported)
  95987. # Shared libraries (.so) - all .so files referenced in "xxx-objs"
  95988. host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
  95989. +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
  95990. +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
  95991. # Remove .so files from "xxx-objs"
  95992. host-cobjs := $(filter-out %.so,$(host-cobjs))
  95993. +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
  95994. -#Object (.o) files used by the shared libaries
  95995. +# Object (.o) files used by the shared libaries
  95996. host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
  95997. +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
  95998. # output directory for programs/.o files
  95999. # hostprogs-y := tools/build may have been specified. Retrieve directory
  96000. @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
  96001. host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
  96002. host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
  96003. host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
  96004. +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
  96005. host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
  96006. +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
  96007. host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
  96008. obj-dirs += $(host-objdirs)
  96009. @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
  96010. $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
  96011. $(call if_changed_dep,host-cshobjs)
  96012. +# Compile .c file, create position independent .o file
  96013. +# host-cxxshobjs -> .o
  96014. +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
  96015. + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
  96016. +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
  96017. + $(call if_changed_dep,host-cxxshobjs)
  96018. +
  96019. # Link a shared library, based on position independent .o files
  96020. # *.o -> .so shared library (host-cshlib)
  96021. quiet_cmd_host-cshlib = HOSTLLD -shared $@
  96022. @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
  96023. $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
  96024. $(call if_changed,host-cshlib)
  96025. +# Link a shared library, based on position independent .o files
  96026. +# *.o -> .so shared library (host-cxxshlib)
  96027. +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
  96028. + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
  96029. + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
  96030. + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
  96031. +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
  96032. + $(call if_changed,host-cxxshlib)
  96033. +
  96034. targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
  96035. - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
  96036. + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
  96037. diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
  96038. index 078fe1d..fbdb363 100644
  96039. --- a/scripts/basic/fixdep.c
  96040. +++ b/scripts/basic/fixdep.c
  96041. @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
  96042. /*
  96043. * Lookup a value in the configuration string.
  96044. */
  96045. -static int is_defined_config(const char *name, int len, unsigned int hash)
  96046. +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
  96047. {
  96048. struct item *aux;
  96049. @@ -211,10 +211,10 @@ static void clear_config(void)
  96050. /*
  96051. * Record the use of a CONFIG_* word.
  96052. */
  96053. -static void use_config(const char *m, int slen)
  96054. +static void use_config(const char *m, unsigned int slen)
  96055. {
  96056. unsigned int hash = strhash(m, slen);
  96057. - int c, i;
  96058. + unsigned int c, i;
  96059. if (is_defined_config(m, slen, hash))
  96060. return;
  96061. @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
  96062. static void parse_config_file(const char *map, size_t len)
  96063. {
  96064. - const int *end = (const int *) (map + len);
  96065. + const unsigned int *end = (const unsigned int *) (map + len);
  96066. /* start at +1, so that p can never be < map */
  96067. - const int *m = (const int *) map + 1;
  96068. + const unsigned int *m = (const unsigned int *) map + 1;
  96069. const char *p, *q;
  96070. for (; m < end; m++) {
  96071. @@ -435,7 +435,7 @@ static void print_deps(void)
  96072. static void traps(void)
  96073. {
  96074. static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
  96075. - int *p = (int *)test;
  96076. + unsigned int *p = (unsigned int *)test;
  96077. if (*p != INT_CONF) {
  96078. fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
  96079. diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
  96080. new file mode 100644
  96081. index 0000000..edcbc3a
  96082. --- /dev/null
  96083. +++ b/scripts/gcc-plugin.sh
  96084. @@ -0,0 +1,16 @@
  96085. +#!/bin/bash
  96086. +srctree=$(dirname "$0")
  96087. +gccplugins_dir=$($3 -print-file-name=plugin)
  96088. +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
  96089. +#include "gcc-common.h"
  96090. +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
  96091. +#warning $2
  96092. +#else
  96093. +#warning $1
  96094. +#endif
  96095. +EOF
  96096. +)
  96097. +if [ $? -eq 0 ]
  96098. +then
  96099. + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
  96100. +fi
  96101. diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
  96102. index 5de5660..d3deb89 100644
  96103. --- a/scripts/headers_install.sh
  96104. +++ b/scripts/headers_install.sh
  96105. @@ -32,6 +32,7 @@ do
  96106. FILE="$(basename "$i")"
  96107. sed -r \
  96108. -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
  96109. + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
  96110. -e 's/__attribute_const__([ \t]|$)/\1/g' \
  96111. -e 's@^#include <linux/compiler.h>@@' \
  96112. -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
  96113. diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
  96114. index 2dcb377..a82c500 100644
  96115. --- a/scripts/link-vmlinux.sh
  96116. +++ b/scripts/link-vmlinux.sh
  96117. @@ -162,7 +162,7 @@ else
  96118. fi;
  96119. # final build of init/
  96120. -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
  96121. +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
  96122. kallsymso=""
  96123. kallsyms_vmlinux=""
  96124. diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
  96125. index 25e5cb0..6e85821 100644
  96126. --- a/scripts/mod/file2alias.c
  96127. +++ b/scripts/mod/file2alias.c
  96128. @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
  96129. unsigned long size, unsigned long id_size,
  96130. void *symval)
  96131. {
  96132. - int i;
  96133. + unsigned int i;
  96134. if (size % id_size || size < id_size) {
  96135. fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
  96136. @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
  96137. /* USB is special because the bcdDevice can be matched against a numeric range */
  96138. /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
  96139. static void do_usb_entry(void *symval,
  96140. - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
  96141. + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
  96142. unsigned char range_lo, unsigned char range_hi,
  96143. unsigned char max, struct module *mod)
  96144. {
  96145. @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
  96146. {
  96147. unsigned int devlo, devhi;
  96148. unsigned char chi, clo, max;
  96149. - int ndigits;
  96150. + unsigned int ndigits;
  96151. DEF_FIELD(symval, usb_device_id, match_flags);
  96152. DEF_FIELD(symval, usb_device_id, idVendor);
  96153. @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
  96154. for (i = 0; i < count; i++) {
  96155. DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
  96156. char acpi_id[sizeof(*id)];
  96157. - int j;
  96158. + unsigned int j;
  96159. buf_printf(&mod->dev_table_buf,
  96160. "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
  96161. @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
  96162. for (j = 0; j < PNP_MAX_DEVICES; j++) {
  96163. const char *id = (char *)(*devs)[j].id;
  96164. - int i2, j2;
  96165. + unsigned int i2, j2;
  96166. int dup = 0;
  96167. if (!id[0])
  96168. @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
  96169. /* add an individual alias for every device entry */
  96170. if (!dup) {
  96171. char acpi_id[PNP_ID_LEN];
  96172. - int k;
  96173. + unsigned int k;
  96174. buf_printf(&mod->dev_table_buf,
  96175. "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
  96176. @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
  96177. static int do_dmi_entry(const char *filename, void *symval,
  96178. char *alias)
  96179. {
  96180. - int i, j;
  96181. + unsigned int i, j;
  96182. DEF_FIELD_ADDR(symval, dmi_system_id, matches);
  96183. sprintf(alias, "dmi*");
  96184. diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
  96185. index 99a45fd..4b995a3 100644
  96186. --- a/scripts/mod/modpost.c
  96187. +++ b/scripts/mod/modpost.c
  96188. @@ -945,6 +945,7 @@ enum mismatch {
  96189. ANY_INIT_TO_ANY_EXIT,
  96190. ANY_EXIT_TO_ANY_INIT,
  96191. EXPORT_TO_INIT_EXIT,
  96192. + DATA_TO_TEXT
  96193. };
  96194. struct sectioncheck {
  96195. @@ -1031,6 +1032,12 @@ const struct sectioncheck sectioncheck[] = {
  96196. .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
  96197. .mismatch = EXPORT_TO_INIT_EXIT,
  96198. .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
  96199. +},
  96200. +/* Do not reference code from writable data */
  96201. +{
  96202. + .fromsec = { DATA_SECTIONS, NULL },
  96203. + .tosec = { TEXT_SECTIONS, NULL },
  96204. + .mismatch = DATA_TO_TEXT
  96205. }
  96206. };
  96207. @@ -1151,10 +1158,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
  96208. continue;
  96209. if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
  96210. continue;
  96211. - if (sym->st_value == addr)
  96212. - return sym;
  96213. /* Find a symbol nearby - addr are maybe negative */
  96214. d = sym->st_value - addr;
  96215. + if (d == 0)
  96216. + return sym;
  96217. if (d < 0)
  96218. d = addr - sym->st_value;
  96219. if (d < distance) {
  96220. @@ -1432,6 +1439,14 @@ static void report_sec_mismatch(const char *modname,
  96221. tosym, prl_to, prl_to, tosym);
  96222. free(prl_to);
  96223. break;
  96224. + case DATA_TO_TEXT:
  96225. +#if 0
  96226. + fprintf(stderr,
  96227. + "The %s %s:%s references\n"
  96228. + "the %s %s:%s%s\n",
  96229. + from, fromsec, fromsym, to, tosec, tosym, to_p);
  96230. +#endif
  96231. + break;
  96232. }
  96233. fprintf(stderr, "\n");
  96234. }
  96235. @@ -1679,7 +1694,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
  96236. static void check_sec_ref(struct module *mod, const char *modname,
  96237. struct elf_info *elf)
  96238. {
  96239. - int i;
  96240. + unsigned int i;
  96241. Elf_Shdr *sechdrs = elf->sechdrs;
  96242. /* Walk through all sections */
  96243. @@ -1798,7 +1813,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
  96244. va_end(ap);
  96245. }
  96246. -void buf_write(struct buffer *buf, const char *s, int len)
  96247. +void buf_write(struct buffer *buf, const char *s, unsigned int len)
  96248. {
  96249. if (buf->size - buf->pos < len) {
  96250. buf->size += len + SZ;
  96251. @@ -2017,7 +2032,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
  96252. if (fstat(fileno(file), &st) < 0)
  96253. goto close_write;
  96254. - if (st.st_size != b->pos)
  96255. + if (st.st_size != (off_t)b->pos)
  96256. goto close_write;
  96257. tmp = NOFAIL(malloc(b->pos));
  96258. diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
  96259. index 51207e4..f7d603d 100644
  96260. --- a/scripts/mod/modpost.h
  96261. +++ b/scripts/mod/modpost.h
  96262. @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
  96263. struct buffer {
  96264. char *p;
  96265. - int pos;
  96266. - int size;
  96267. + unsigned int pos;
  96268. + unsigned int size;
  96269. };
  96270. void __attribute__((format(printf, 2, 3)))
  96271. buf_printf(struct buffer *buf, const char *fmt, ...);
  96272. void
  96273. -buf_write(struct buffer *buf, const char *s, int len);
  96274. +buf_write(struct buffer *buf, const char *s, unsigned int len);
  96275. struct module {
  96276. struct module *next;
  96277. diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
  96278. index deb2994..af4f63e 100644
  96279. --- a/scripts/mod/sumversion.c
  96280. +++ b/scripts/mod/sumversion.c
  96281. @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
  96282. goto out;
  96283. }
  96284. - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
  96285. + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
  96286. warn("writing sum in %s failed: %s\n",
  96287. filename, strerror(errno));
  96288. goto out;
  96289. diff --git a/scripts/module-common.lds b/scripts/module-common.lds
  96290. index 0865b3e..7235dd4 100644
  96291. --- a/scripts/module-common.lds
  96292. +++ b/scripts/module-common.lds
  96293. @@ -6,6 +6,10 @@
  96294. SECTIONS {
  96295. /DISCARD/ : { *(.discard) }
  96296. + .rodata : {
  96297. + *(.rodata) *(.rodata.*)
  96298. + *(.data..read_only)
  96299. + }
  96300. __ksymtab : { *(SORT(___ksymtab+*)) }
  96301. __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
  96302. __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
  96303. diff --git a/scripts/package/builddeb b/scripts/package/builddeb
  96304. index f46e4dd..090e168 100644
  96305. --- a/scripts/package/builddeb
  96306. +++ b/scripts/package/builddeb
  96307. @@ -291,6 +291,7 @@ fi
  96308. (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
  96309. (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
  96310. (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
  96311. +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
  96312. destdir=$kernel_headers_dir/usr/src/linux-headers-$version
  96313. mkdir -p "$destdir"
  96314. (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
  96315. diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
  96316. index 68bb4ef..2f419e1 100644
  96317. --- a/scripts/pnmtologo.c
  96318. +++ b/scripts/pnmtologo.c
  96319. @@ -244,14 +244,14 @@ static void write_header(void)
  96320. fprintf(out, " * Linux logo %s\n", logoname);
  96321. fputs(" */\n\n", out);
  96322. fputs("#include <linux/linux_logo.h>\n\n", out);
  96323. - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
  96324. + fprintf(out, "static unsigned char %s_data[] = {\n",
  96325. logoname);
  96326. }
  96327. static void write_footer(void)
  96328. {
  96329. fputs("\n};\n\n", out);
  96330. - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
  96331. + fprintf(out, "const struct linux_logo %s = {\n", logoname);
  96332. fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
  96333. fprintf(out, "\t.width\t\t= %d,\n", logo_width);
  96334. fprintf(out, "\t.height\t\t= %d,\n", logo_height);
  96335. @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
  96336. fputs("\n};\n\n", out);
  96337. /* write logo clut */
  96338. - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
  96339. + fprintf(out, "static unsigned char %s_clut[] = {\n",
  96340. logoname);
  96341. write_hex_cnt = 0;
  96342. for (i = 0; i < logo_clutsize; i++) {
  96343. diff --git a/scripts/sortextable.h b/scripts/sortextable.h
  96344. index 8fac3fd..32ff38d 100644
  96345. --- a/scripts/sortextable.h
  96346. +++ b/scripts/sortextable.h
  96347. @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
  96348. const char *secstrtab;
  96349. const char *strtab;
  96350. char *extab_image;
  96351. - int extab_index = 0;
  96352. - int i;
  96353. - int idx;
  96354. + unsigned int extab_index = 0;
  96355. + unsigned int i;
  96356. + unsigned int idx;
  96357. unsigned int num_sections;
  96358. unsigned int secindex_strings;
  96359. diff --git a/security/Kconfig b/security/Kconfig
  96360. index beb86b5..55198cd 100644
  96361. --- a/security/Kconfig
  96362. +++ b/security/Kconfig
  96363. @@ -4,6 +4,961 @@
  96364. menu "Security options"
  96365. +menu "Grsecurity"
  96366. +
  96367. + config ARCH_TRACK_EXEC_LIMIT
  96368. + bool
  96369. +
  96370. + config PAX_KERNEXEC_PLUGIN
  96371. + bool
  96372. +
  96373. + config PAX_PER_CPU_PGD
  96374. + bool
  96375. +
  96376. + config TASK_SIZE_MAX_SHIFT
  96377. + int
  96378. + depends on X86_64
  96379. + default 47 if !PAX_PER_CPU_PGD
  96380. + default 42 if PAX_PER_CPU_PGD
  96381. +
  96382. + config PAX_ENABLE_PAE
  96383. + bool
  96384. + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
  96385. +
  96386. + config PAX_USERCOPY_SLABS
  96387. + bool
  96388. +
  96389. +config GRKERNSEC
  96390. + bool "Grsecurity"
  96391. + select CRYPTO
  96392. + select CRYPTO_SHA256
  96393. + select PROC_FS
  96394. + select STOP_MACHINE
  96395. + select TTY
  96396. + select DEBUG_KERNEL
  96397. + select DEBUG_LIST
  96398. + select DEBUG_STACKOVERFLOW if HAVE_DEBUG_STACKOVERFLOW
  96399. + help
  96400. + If you say Y here, you will be able to configure many features
  96401. + that will enhance the security of your system. It is highly
  96402. + recommended that you say Y here and read through the help
  96403. + for each option so that you fully understand the features and
  96404. + can evaluate their usefulness for your machine.
  96405. +
  96406. +choice
  96407. + prompt "Configuration Method"
  96408. + depends on GRKERNSEC
  96409. + default GRKERNSEC_CONFIG_CUSTOM
  96410. + help
  96411. +
  96412. +config GRKERNSEC_CONFIG_AUTO
  96413. + bool "Automatic"
  96414. + help
  96415. + If you choose this configuration method, you'll be able to answer a small
  96416. + number of simple questions about how you plan to use this kernel.
  96417. + The settings of grsecurity and PaX will be automatically configured for
  96418. + the highest commonly-used settings within the provided constraints.
  96419. +
  96420. + If you require additional configuration, custom changes can still be made
  96421. + from the "custom configuration" menu.
  96422. +
  96423. +config GRKERNSEC_CONFIG_CUSTOM
  96424. + bool "Custom"
  96425. + help
  96426. + If you choose this configuration method, you'll be able to configure all
  96427. + grsecurity and PaX settings manually. Via this method, no options are
  96428. + automatically enabled.
  96429. +
  96430. +endchoice
  96431. +
  96432. +choice
  96433. + prompt "Usage Type"
  96434. + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
  96435. + default GRKERNSEC_CONFIG_SERVER
  96436. + help
  96437. +
  96438. +config GRKERNSEC_CONFIG_SERVER
  96439. + bool "Server"
  96440. + help
  96441. + Choose this option if you plan to use this kernel on a server.
  96442. +
  96443. +config GRKERNSEC_CONFIG_DESKTOP
  96444. + bool "Desktop"
  96445. + help
  96446. + Choose this option if you plan to use this kernel on a desktop.
  96447. +
  96448. +endchoice
  96449. +
  96450. +choice
  96451. + prompt "Virtualization Type"
  96452. + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
  96453. + default GRKERNSEC_CONFIG_VIRT_NONE
  96454. + help
  96455. +
  96456. +config GRKERNSEC_CONFIG_VIRT_NONE
  96457. + bool "None"
  96458. + help
  96459. + Choose this option if this kernel will be run on bare metal.
  96460. +
  96461. +config GRKERNSEC_CONFIG_VIRT_GUEST
  96462. + bool "Guest"
  96463. + help
  96464. + Choose this option if this kernel will be run as a VM guest.
  96465. +
  96466. +config GRKERNSEC_CONFIG_VIRT_HOST
  96467. + bool "Host"
  96468. + help
  96469. + Choose this option if this kernel will be run as a VM host.
  96470. +
  96471. +endchoice
  96472. +
  96473. +choice
  96474. + prompt "Virtualization Hardware"
  96475. + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
  96476. + help
  96477. +
  96478. +config GRKERNSEC_CONFIG_VIRT_EPT
  96479. + bool "EPT/RVI Processor Support"
  96480. + depends on X86
  96481. + help
  96482. + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
  96483. + hardware virtualization. This allows for additional kernel hardening protections
  96484. + to operate without additional performance impact.
  96485. +
  96486. + To see if your Intel processor supports EPT, see:
  96487. + http://ark.intel.com/Products/VirtualizationTechnology
  96488. + (Most Core i3/5/7 support EPT)
  96489. +
  96490. + To see if your AMD processor supports RVI, see:
  96491. + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
  96492. +
  96493. +config GRKERNSEC_CONFIG_VIRT_SOFT
  96494. + bool "First-gen/No Hardware Virtualization"
  96495. + help
  96496. + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
  96497. + support hardware virtualization or doesn't support the EPT/RVI extensions.
  96498. +
  96499. +endchoice
  96500. +
  96501. +choice
  96502. + prompt "Virtualization Software"
  96503. + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
  96504. + help
  96505. +
  96506. +config GRKERNSEC_CONFIG_VIRT_XEN
  96507. + bool "Xen"
  96508. + help
  96509. + Choose this option if this kernel is running as a Xen guest or host.
  96510. +
  96511. +config GRKERNSEC_CONFIG_VIRT_VMWARE
  96512. + bool "VMWare"
  96513. + help
  96514. + Choose this option if this kernel is running as a VMWare guest or host.
  96515. +
  96516. +config GRKERNSEC_CONFIG_VIRT_KVM
  96517. + bool "KVM"
  96518. + help
  96519. + Choose this option if this kernel is running as a KVM guest or host.
  96520. +
  96521. +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
  96522. + bool "VirtualBox"
  96523. + help
  96524. + Choose this option if this kernel is running as a VirtualBox guest or host.
  96525. +
  96526. +endchoice
  96527. +
  96528. +choice
  96529. + prompt "Required Priorities"
  96530. + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
  96531. + default GRKERNSEC_CONFIG_PRIORITY_PERF
  96532. + help
  96533. +
  96534. +config GRKERNSEC_CONFIG_PRIORITY_PERF
  96535. + bool "Performance"
  96536. + help
  96537. + Choose this option if performance is of highest priority for this deployment
  96538. + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
  96539. + clearing of structures intended for userland, and freed memory sanitizing will
  96540. + be disabled.
  96541. +
  96542. +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
  96543. + bool "Security"
  96544. + help
  96545. + Choose this option if security is of highest priority for this deployment of
  96546. + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
  96547. + for userland, and freed memory sanitizing will be enabled for this kernel.
  96548. + In a worst-case scenario, these features can introduce a 20% performance hit
  96549. + (UDEREF on x64 contributing half of this hit).
  96550. +
  96551. +endchoice
  96552. +
  96553. +menu "Default Special Groups"
  96554. +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
  96555. +
  96556. +config GRKERNSEC_PROC_GID
  96557. + int "GID exempted from /proc restrictions"
  96558. + default 1001
  96559. + help
  96560. + Setting this GID determines which group will be exempted from
  96561. + grsecurity's /proc restrictions, allowing users of the specified
  96562. + group to view network statistics and the existence of other users'
  96563. + processes on the system. This GID may also be chosen at boot time
  96564. + via "grsec_proc_gid=" on the kernel commandline.
  96565. +
  96566. +config GRKERNSEC_TPE_UNTRUSTED_GID
  96567. + int "GID for TPE-untrusted users"
  96568. + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
  96569. + default 1005
  96570. + help
  96571. + Setting this GID determines which group untrusted users should
  96572. + be added to. These users will be placed under grsecurity's Trusted Path
  96573. + Execution mechanism, preventing them from executing their own binaries.
  96574. + The users will only be able to execute binaries in directories owned and
  96575. + writable only by the root user. If the sysctl option is enabled, a sysctl
  96576. + option with name "tpe_gid" is created.
  96577. +
  96578. +config GRKERNSEC_TPE_TRUSTED_GID
  96579. + int "GID for TPE-trusted users"
  96580. + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
  96581. + default 1005
  96582. + help
  96583. + Setting this GID determines what group TPE restrictions will be
  96584. + *disabled* for. If the sysctl option is enabled, a sysctl option
  96585. + with name "tpe_gid" is created.
  96586. +
  96587. +config GRKERNSEC_SYMLINKOWN_GID
  96588. + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
  96589. + depends on GRKERNSEC_CONFIG_SERVER
  96590. + default 1006
  96591. + help
  96592. + Setting this GID determines what group kernel-enforced
  96593. + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
  96594. + is enabled, a sysctl option with name "symlinkown_gid" is created.
  96595. +
  96596. +
  96597. +endmenu
  96598. +
  96599. +menu "Customize Configuration"
  96600. +depends on GRKERNSEC
  96601. +
  96602. +menu "PaX"
  96603. +
  96604. +config PAX
  96605. + bool "Enable various PaX features"
  96606. + default y if GRKERNSEC_CONFIG_AUTO
  96607. + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
  96608. + help
  96609. + This allows you to enable various PaX features. PaX adds
  96610. + intrusion prevention mechanisms to the kernel that reduce
  96611. + the risks posed by exploitable memory corruption bugs.
  96612. +
  96613. +menu "PaX Control"
  96614. + depends on PAX
  96615. +
  96616. +config PAX_SOFTMODE
  96617. + bool 'Support soft mode'
  96618. + help
  96619. + Enabling this option will allow you to run PaX in soft mode, that
  96620. + is, PaX features will not be enforced by default, only on executables
  96621. + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
  96622. + support as they are the only way to mark executables for soft mode use.
  96623. +
  96624. + Soft mode can be activated by using the "pax_softmode=1" kernel command
  96625. + line option on boot. Furthermore you can control various PaX features
  96626. + at runtime via the entries in /proc/sys/kernel/pax.
  96627. +
  96628. +config PAX_EI_PAX
  96629. + bool 'Use legacy ELF header marking'
  96630. + default y if GRKERNSEC_CONFIG_AUTO
  96631. + help
  96632. + Enabling this option will allow you to control PaX features on
  96633. + a per executable basis via the 'chpax' utility available at
  96634. + http://pax.grsecurity.net/. The control flags will be read from
  96635. + an otherwise reserved part of the ELF header. This marking has
  96636. + numerous drawbacks (no support for soft-mode, toolchain does not
  96637. + know about the non-standard use of the ELF header) therefore it
  96638. + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
  96639. + support.
  96640. +
  96641. + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
  96642. + support as well, they will override the legacy EI_PAX marks.
  96643. +
  96644. + If you enable none of the marking options then all applications
  96645. + will run with PaX enabled on them by default.
  96646. +
  96647. +config PAX_PT_PAX_FLAGS
  96648. + bool 'Use ELF program header marking'
  96649. + default y if GRKERNSEC_CONFIG_AUTO
  96650. + help
  96651. + Enabling this option will allow you to control PaX features on
  96652. + a per executable basis via the 'paxctl' utility available at
  96653. + http://pax.grsecurity.net/. The control flags will be read from
  96654. + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
  96655. + has the benefits of supporting both soft mode and being fully
  96656. + integrated into the toolchain (the binutils patch is available
  96657. + from http://pax.grsecurity.net).
  96658. +
  96659. + Note that if you enable the legacy EI_PAX marking support as well,
  96660. + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
  96661. +
  96662. + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
  96663. + must make sure that the marks are the same if a binary has both marks.
  96664. +
  96665. + If you enable none of the marking options then all applications
  96666. + will run with PaX enabled on them by default.
  96667. +
  96668. +config PAX_XATTR_PAX_FLAGS
  96669. + bool 'Use filesystem extended attributes marking'
  96670. + default y if GRKERNSEC_CONFIG_AUTO
  96671. + select CIFS_XATTR if CIFS
  96672. + select EXT2_FS_XATTR if EXT2_FS
  96673. + select EXT3_FS_XATTR if EXT3_FS
  96674. + select JFFS2_FS_XATTR if JFFS2_FS
  96675. + select REISERFS_FS_XATTR if REISERFS_FS
  96676. + select SQUASHFS_XATTR if SQUASHFS
  96677. + select TMPFS_XATTR if TMPFS
  96678. + select UBIFS_FS_XATTR if UBIFS_FS
  96679. + help
  96680. + Enabling this option will allow you to control PaX features on
  96681. + a per executable basis via the 'setfattr' utility. The control
  96682. + flags will be read from the user.pax.flags extended attribute of
  96683. + the file. This marking has the benefit of supporting binary-only
  96684. + applications that self-check themselves (e.g., skype) and would
  96685. + not tolerate chpax/paxctl changes. The main drawback is that
  96686. + extended attributes are not supported by some filesystems (e.g.,
  96687. + isofs, udf, vfat) so copying files through such filesystems will
  96688. + lose the extended attributes and these PaX markings.
  96689. +
  96690. + Note that if you enable the legacy EI_PAX marking support as well,
  96691. + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
  96692. +
  96693. + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
  96694. + must make sure that the marks are the same if a binary has both marks.
  96695. +
  96696. + If you enable none of the marking options then all applications
  96697. + will run with PaX enabled on them by default.
  96698. +
  96699. +choice
  96700. + prompt 'MAC system integration'
  96701. + default PAX_HAVE_ACL_FLAGS
  96702. + help
  96703. + Mandatory Access Control systems have the option of controlling
  96704. + PaX flags on a per executable basis, choose the method supported
  96705. + by your particular system.
  96706. +
  96707. + - "none": if your MAC system does not interact with PaX,
  96708. + - "direct": if your MAC system defines pax_set_initial_flags() itself,
  96709. + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
  96710. +
  96711. + NOTE: this option is for developers/integrators only.
  96712. +
  96713. + config PAX_NO_ACL_FLAGS
  96714. + bool 'none'
  96715. +
  96716. + config PAX_HAVE_ACL_FLAGS
  96717. + bool 'direct'
  96718. +
  96719. + config PAX_HOOK_ACL_FLAGS
  96720. + bool 'hook'
  96721. +endchoice
  96722. +
  96723. +endmenu
  96724. +
  96725. +menu "Non-executable pages"
  96726. + depends on PAX
  96727. +
  96728. +config PAX_NOEXEC
  96729. + bool "Enforce non-executable pages"
  96730. + default y if GRKERNSEC_CONFIG_AUTO
  96731. + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
  96732. + help
  96733. + By design some architectures do not allow for protecting memory
  96734. + pages against execution or even if they do, Linux does not make
  96735. + use of this feature. In practice this means that if a page is
  96736. + readable (such as the stack or heap) it is also executable.
  96737. +
  96738. + There is a well known exploit technique that makes use of this
  96739. + fact and a common programming mistake where an attacker can
  96740. + introduce code of his choice somewhere in the attacked program's
  96741. + memory (typically the stack or the heap) and then execute it.
  96742. +
  96743. + If the attacked program was running with different (typically
  96744. + higher) privileges than that of the attacker, then he can elevate
  96745. + his own privilege level (e.g. get a root shell, write to files for
  96746. + which he does not have write access to, etc).
  96747. +
  96748. + Enabling this option will let you choose from various features
  96749. + that prevent the injection and execution of 'foreign' code in
  96750. + a program.
  96751. +
  96752. + This will also break programs that rely on the old behaviour and
  96753. + expect that dynamically allocated memory via the malloc() family
  96754. + of functions is executable (which it is not). Notable examples
  96755. + are the XFree86 4.x server, the java runtime and wine.
  96756. +
  96757. +config PAX_PAGEEXEC
  96758. + bool "Paging based non-executable pages"
  96759. + default y if GRKERNSEC_CONFIG_AUTO
  96760. + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
  96761. + select ARCH_TRACK_EXEC_LIMIT if X86_32
  96762. + help
  96763. + This implementation is based on the paging feature of the CPU.
  96764. + On i386 without hardware non-executable bit support there is a
  96765. + variable but usually low performance impact, however on Intel's
  96766. + P4 core based CPUs it is very high so you should not enable this
  96767. + for kernels meant to be used on such CPUs.
  96768. +
  96769. + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
  96770. + with hardware non-executable bit support there is no performance
  96771. + impact, on ppc the impact is negligible.
  96772. +
  96773. + Note that several architectures require various emulations due to
  96774. + badly designed userland ABIs, this will cause a performance impact
  96775. + but will disappear as soon as userland is fixed. For example, ppc
  96776. + userland MUST have been built with secure-plt by a recent toolchain.
  96777. +
  96778. +config PAX_SEGMEXEC
  96779. + bool "Segmentation based non-executable pages"
  96780. + default y if GRKERNSEC_CONFIG_AUTO
  96781. + depends on PAX_NOEXEC && X86_32
  96782. + help
  96783. + This implementation is based on the segmentation feature of the
  96784. + CPU and has a very small performance impact, however applications
  96785. + will be limited to a 1.5 GB address space instead of the normal
  96786. + 3 GB.
  96787. +
  96788. +config PAX_EMUTRAMP
  96789. + bool "Emulate trampolines"
  96790. + default y if PARISC || GRKERNSEC_CONFIG_AUTO
  96791. + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
  96792. + help
  96793. + There are some programs and libraries that for one reason or
  96794. + another attempt to execute special small code snippets from
  96795. + non-executable memory pages. Most notable examples are the
  96796. + signal handler return code generated by the kernel itself and
  96797. + the GCC trampolines.
  96798. +
  96799. + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
  96800. + such programs will no longer work under your kernel.
  96801. +
  96802. + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
  96803. + utilities to enable trampoline emulation for the affected programs
  96804. + yet still have the protection provided by the non-executable pages.
  96805. +
  96806. + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
  96807. + your system will not even boot.
  96808. +
  96809. + Alternatively you can say N here and use the 'chpax' or 'paxctl'
  96810. + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
  96811. + for the affected files.
  96812. +
  96813. + NOTE: enabling this feature *may* open up a loophole in the
  96814. + protection provided by non-executable pages that an attacker
  96815. + could abuse. Therefore the best solution is to not have any
  96816. + files on your system that would require this option. This can
  96817. + be achieved by not using libc5 (which relies on the kernel
  96818. + signal handler return code) and not using or rewriting programs
  96819. + that make use of the nested function implementation of GCC.
  96820. + Skilled users can just fix GCC itself so that it implements
  96821. + nested function calls in a way that does not interfere with PaX.
  96822. +
  96823. +config PAX_EMUSIGRT
  96824. + bool "Automatically emulate sigreturn trampolines"
  96825. + depends on PAX_EMUTRAMP && PARISC
  96826. + default y
  96827. + help
  96828. + Enabling this option will have the kernel automatically detect
  96829. + and emulate signal return trampolines executing on the stack
  96830. + that would otherwise lead to task termination.
  96831. +
  96832. + This solution is intended as a temporary one for users with
  96833. + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
  96834. + Modula-3 runtime, etc) or executables linked to such, basically
  96835. + everything that does not specify its own SA_RESTORER function in
  96836. + normal executable memory like glibc 2.1+ does.
  96837. +
  96838. + On parisc you MUST enable this option, otherwise your system will
  96839. + not even boot.
  96840. +
  96841. + NOTE: this feature cannot be disabled on a per executable basis
  96842. + and since it *does* open up a loophole in the protection provided
  96843. + by non-executable pages, the best solution is to not have any
  96844. + files on your system that would require this option.
  96845. +
  96846. +config PAX_MPROTECT
  96847. + bool "Restrict mprotect()"
  96848. + default y if GRKERNSEC_CONFIG_AUTO
  96849. + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
  96850. + help
  96851. + Enabling this option will prevent programs from
  96852. + - changing the executable status of memory pages that were
  96853. + not originally created as executable,
  96854. + - making read-only executable pages writable again,
  96855. + - creating executable pages from anonymous memory,
  96856. + - making read-only-after-relocations (RELRO) data pages writable again.
  96857. +
  96858. + You should say Y here to complete the protection provided by
  96859. + the enforcement of non-executable pages.
  96860. +
  96861. + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
  96862. + this feature on a per file basis.
  96863. +
  96864. +config PAX_MPROTECT_COMPAT
  96865. + bool "Use legacy/compat protection demoting (read help)"
  96866. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
  96867. + depends on PAX_MPROTECT
  96868. + help
  96869. + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
  96870. + by sending the proper error code to the application. For some broken
  96871. + userland, this can cause problems with Python or other applications. The
  96872. + current implementation however allows for applications like clamav to
  96873. + detect if JIT compilation/execution is allowed and to fall back gracefully
  96874. + to an interpreter-based mode if it does not. While we encourage everyone
  96875. + to use the current implementation as-is and push upstream to fix broken
  96876. + userland (note that the RWX logging option can assist with this), in some
  96877. + environments this may not be possible. Having to disable MPROTECT
  96878. + completely on certain binaries reduces the security benefit of PaX,
  96879. + so this option is provided for those environments to revert to the old
  96880. + behavior.
  96881. +
  96882. +config PAX_ELFRELOCS
  96883. + bool "Allow ELF text relocations (read help)"
  96884. + depends on PAX_MPROTECT
  96885. + default n
  96886. + help
  96887. + Non-executable pages and mprotect() restrictions are effective
  96888. + in preventing the introduction of new executable code into an
  96889. + attacked task's address space. There remain only two venues
  96890. + for this kind of attack: if the attacker can execute already
  96891. + existing code in the attacked task then he can either have it
  96892. + create and mmap() a file containing his code or have it mmap()
  96893. + an already existing ELF library that does not have position
  96894. + independent code in it and use mprotect() on it to make it
  96895. + writable and copy his code there. While protecting against
  96896. + the former approach is beyond PaX, the latter can be prevented
  96897. + by having only PIC ELF libraries on one's system (which do not
  96898. + need to relocate their code). If you are sure this is your case,
  96899. + as is the case with all modern Linux distributions, then leave
  96900. + this option disabled. You should say 'n' here.
  96901. +
  96902. +config PAX_ETEXECRELOCS
  96903. + bool "Allow ELF ET_EXEC text relocations"
  96904. + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
  96905. + select PAX_ELFRELOCS
  96906. + default y
  96907. + help
  96908. + On some architectures there are incorrectly created applications
  96909. + that require text relocations and would not work without enabling
  96910. + this option. If you are an alpha, ia64 or parisc user, you should
  96911. + enable this option and disable it once you have made sure that
  96912. + none of your applications need it.
  96913. +
  96914. +config PAX_EMUPLT
  96915. + bool "Automatically emulate ELF PLT"
  96916. + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
  96917. + default y
  96918. + help
  96919. + Enabling this option will have the kernel automatically detect
  96920. + and emulate the Procedure Linkage Table entries in ELF files.
  96921. + On some architectures such entries are in writable memory, and
  96922. + become non-executable leading to task termination. Therefore
  96923. + it is mandatory that you enable this option on alpha, parisc,
  96924. + sparc and sparc64, otherwise your system would not even boot.
  96925. +
  96926. + NOTE: this feature *does* open up a loophole in the protection
  96927. + provided by the non-executable pages, therefore the proper
  96928. + solution is to modify the toolchain to produce a PLT that does
  96929. + not need to be writable.
  96930. +
  96931. +config PAX_DLRESOLVE
  96932. + bool 'Emulate old glibc resolver stub'
  96933. + depends on PAX_EMUPLT && SPARC
  96934. + default n
  96935. + help
  96936. + This option is needed if userland has an old glibc (before 2.4)
  96937. + that puts a 'save' instruction into the runtime generated resolver
  96938. + stub that needs special emulation.
  96939. +
  96940. +config PAX_KERNEXEC
  96941. + bool "Enforce non-executable kernel pages"
  96942. + default y if GRKERNSEC_CONFIG_AUTO && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
  96943. + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
  96944. + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
  96945. + select PAX_KERNEXEC_PLUGIN if X86_64
  96946. + help
  96947. + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
  96948. + that is, enabling this option will make it harder to inject
  96949. + and execute 'foreign' code in kernel memory itself.
  96950. +
  96951. +choice
  96952. + prompt "Return Address Instrumentation Method"
  96953. + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
  96954. + depends on PAX_KERNEXEC_PLUGIN
  96955. + help
  96956. + Select the method used to instrument function pointer dereferences.
  96957. + Note that binary modules cannot be instrumented by this approach.
  96958. +
  96959. + Note that the implementation requires a gcc with plugin support,
  96960. + i.e., gcc 4.5 or newer. You may need to install the supporting
  96961. + headers explicitly in addition to the normal gcc package.
  96962. +
  96963. + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
  96964. + bool "bts"
  96965. + help
  96966. + This method is compatible with binary only modules but has
  96967. + a higher runtime overhead.
  96968. +
  96969. + config PAX_KERNEXEC_PLUGIN_METHOD_OR
  96970. + bool "or"
  96971. + depends on !PARAVIRT
  96972. + help
  96973. + This method is incompatible with binary only modules but has
  96974. + a lower runtime overhead.
  96975. +endchoice
  96976. +
  96977. +config PAX_KERNEXEC_PLUGIN_METHOD
  96978. + string
  96979. + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
  96980. + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
  96981. + default ""
  96982. +
  96983. +config PAX_KERNEXEC_MODULE_TEXT
  96984. + int "Minimum amount of memory reserved for module code"
  96985. + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
  96986. + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
  96987. + depends on PAX_KERNEXEC && X86_32
  96988. + help
  96989. + Due to implementation details the kernel must reserve a fixed
  96990. + amount of memory for runtime allocated code (such as modules)
  96991. + at compile time that cannot be changed at runtime. Here you
  96992. + can specify the minimum amount in MB that will be reserved.
  96993. + Due to the same implementation details this size will always
  96994. + be rounded up to the next 2/4 MB boundary (depends on PAE) so
  96995. + the actually available memory for runtime allocated code will
  96996. + usually be more than this minimum.
  96997. +
  96998. + The default 4 MB should be enough for most users but if you have
  96999. + an excessive number of modules (e.g., most distribution configs
  97000. + compile many drivers as modules) or use huge modules such as
  97001. + nvidia's kernel driver, you will need to adjust this amount.
  97002. + A good rule of thumb is to look at your currently loaded kernel
  97003. + modules and add up their sizes.
  97004. +
  97005. +endmenu
  97006. +
  97007. +menu "Address Space Layout Randomization"
  97008. + depends on PAX
  97009. +
  97010. +config PAX_ASLR
  97011. + bool "Address Space Layout Randomization"
  97012. + default y if GRKERNSEC_CONFIG_AUTO
  97013. + help
  97014. + Many if not most exploit techniques rely on the knowledge of
  97015. + certain addresses in the attacked program. The following options
  97016. + will allow the kernel to apply a certain amount of randomization
  97017. + to specific parts of the program thereby forcing an attacker to
  97018. + guess them in most cases. Any failed guess will most likely crash
  97019. + the attacked program which allows the kernel to detect such attempts
  97020. + and react on them. PaX itself provides no reaction mechanisms,
  97021. + instead it is strongly encouraged that you make use of Nergal's
  97022. + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
  97023. + (http://www.grsecurity.net/) built-in crash detection features or
  97024. + develop one yourself.
  97025. +
  97026. + By saying Y here you can choose to randomize the following areas:
  97027. + - top of the task's kernel stack
  97028. + - top of the task's userland stack
  97029. + - base address for mmap() requests that do not specify one
  97030. + (this includes all libraries)
  97031. + - base address of the main executable
  97032. +
  97033. + It is strongly recommended to say Y here as address space layout
  97034. + randomization has negligible impact on performance yet it provides
  97035. + a very effective protection.
  97036. +
  97037. + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
  97038. + this feature on a per file basis.
  97039. +
  97040. +config PAX_RANDKSTACK
  97041. + bool "Randomize kernel stack base"
  97042. + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
  97043. + depends on X86_TSC && X86
  97044. + help
  97045. + By saying Y here the kernel will randomize every task's kernel
  97046. + stack on every system call. This will not only force an attacker
  97047. + to guess it but also prevent him from making use of possible
  97048. + leaked information about it.
  97049. +
  97050. + Since the kernel stack is a rather scarce resource, randomization
  97051. + may cause unexpected stack overflows, therefore you should very
  97052. + carefully test your system. Note that once enabled in the kernel
  97053. + configuration, this feature cannot be disabled on a per file basis.
  97054. +
  97055. +config PAX_RANDUSTACK
  97056. + bool "Randomize user stack base"
  97057. + default y if GRKERNSEC_CONFIG_AUTO
  97058. + depends on PAX_ASLR
  97059. + help
  97060. + By saying Y here the kernel will randomize every task's userland
  97061. + stack. The randomization is done in two steps where the second
  97062. + one may apply a big amount of shift to the top of the stack and
  97063. + cause problems for programs that want to use lots of memory (more
  97064. + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
  97065. + For this reason the second step can be controlled by 'chpax' or
  97066. + 'paxctl' on a per file basis.
  97067. +
  97068. +config PAX_RANDMMAP
  97069. + bool "Randomize mmap() base"
  97070. + default y if GRKERNSEC_CONFIG_AUTO
  97071. + depends on PAX_ASLR
  97072. + help
  97073. + By saying Y here the kernel will use a randomized base address for
  97074. + mmap() requests that do not specify one themselves. As a result
  97075. + all dynamically loaded libraries will appear at random addresses
  97076. + and therefore be harder to exploit by a technique where an attacker
  97077. + attempts to execute library code for his purposes (e.g. spawn a
  97078. + shell from an exploited program that is running at an elevated
  97079. + privilege level).
  97080. +
  97081. + Furthermore, if a program is relinked as a dynamic ELF file, its
  97082. + base address will be randomized as well, completing the full
  97083. + randomization of the address space layout. Attacking such programs
  97084. + becomes a guess game. You can find an example of doing this at
  97085. + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
  97086. + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
  97087. +
  97088. + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
  97089. + feature on a per file basis.
  97090. +
  97091. +endmenu
  97092. +
  97093. +menu "Miscellaneous hardening features"
  97094. +
  97095. +config PAX_MEMORY_SANITIZE
  97096. + bool "Sanitize all freed memory"
  97097. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
  97098. + help
  97099. + By saying Y here the kernel will erase memory pages and slab objects
  97100. + as soon as they are freed. This in turn reduces the lifetime of data
  97101. + stored in them, making it less likely that sensitive information such
  97102. + as passwords, cryptographic secrets, etc stay in memory for too long.
  97103. +
  97104. + This is especially useful for programs whose runtime is short, long
  97105. + lived processes and the kernel itself benefit from this as long as
  97106. + they ensure timely freeing of memory that may hold sensitive
  97107. + information.
  97108. +
  97109. + A nice side effect of the sanitization of slab objects is the
  97110. + reduction of possible info leaks caused by padding bytes within the
  97111. + leaky structures. Use-after-free bugs for structures containing
  97112. + pointers can also be detected as dereferencing the sanitized pointer
  97113. + will generate an access violation.
  97114. +
  97115. + The tradeoff is performance impact, on a single CPU system kernel
  97116. + compilation sees a 3% slowdown, other systems and workloads may vary
  97117. + and you are advised to test this feature on your expected workload
  97118. + before deploying it.
  97119. +
  97120. + To reduce the performance penalty by sanitizing pages only, albeit
  97121. + limiting the effectiveness of this feature at the same time, slab
  97122. + sanitization can be disabled with the kernel commandline parameter
  97123. + "pax_sanitize_slab=0".
  97124. +
  97125. + Note that this feature does not protect data stored in live pages,
  97126. + e.g., process memory swapped to disk may stay there for a long time.
  97127. +
  97128. +config PAX_MEMORY_STACKLEAK
  97129. + bool "Sanitize kernel stack"
  97130. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
  97131. + depends on X86
  97132. + help
  97133. + By saying Y here the kernel will erase the kernel stack before it
  97134. + returns from a system call. This in turn reduces the information
  97135. + that a kernel stack leak bug can reveal.
  97136. +
  97137. + Note that such a bug can still leak information that was put on
  97138. + the stack by the current system call (the one eventually triggering
  97139. + the bug) but traces of earlier system calls on the kernel stack
  97140. + cannot leak anymore.
  97141. +
  97142. + The tradeoff is performance impact: on a single CPU system kernel
  97143. + compilation sees a 1% slowdown, other systems and workloads may vary
  97144. + and you are advised to test this feature on your expected workload
  97145. + before deploying it.
  97146. +
  97147. + Note that the full feature requires a gcc with plugin support,
  97148. + i.e., gcc 4.5 or newer. You may need to install the supporting
  97149. + headers explicitly in addition to the normal gcc package. Using
  97150. + older gcc versions means that functions with large enough stack
  97151. + frames may leave uninitialized memory behind that may be exposed
  97152. + to a later syscall leaking the stack.
  97153. +
  97154. +config PAX_MEMORY_STRUCTLEAK
  97155. + bool "Forcibly initialize local variables copied to userland"
  97156. + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
  97157. + help
  97158. + By saying Y here the kernel will zero initialize some local
  97159. + variables that are going to be copied to userland. This in
  97160. + turn prevents unintended information leakage from the kernel
  97161. + stack should later code forget to explicitly set all parts of
  97162. + the copied variable.
  97163. +
  97164. + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
  97165. + at a much smaller coverage.
  97166. +
  97167. + Note that the implementation requires a gcc with plugin support,
  97168. + i.e., gcc 4.5 or newer. You may need to install the supporting
  97169. + headers explicitly in addition to the normal gcc package.
  97170. +
  97171. +config PAX_MEMORY_UDEREF
  97172. + bool "Prevent invalid userland pointer dereference"
  97173. + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
  97174. + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
  97175. + select PAX_PER_CPU_PGD if X86_64
  97176. + help
  97177. + By saying Y here the kernel will be prevented from dereferencing
  97178. + userland pointers in contexts where the kernel expects only kernel
  97179. + pointers. This is both a useful runtime debugging feature and a
  97180. + security measure that prevents exploiting a class of kernel bugs.
  97181. +
  97182. + The tradeoff is that some virtualization solutions may experience
  97183. + a huge slowdown and therefore you should not enable this feature
  97184. + for kernels meant to run in such environments. Whether a given VM
  97185. + solution is affected or not is best determined by simply trying it
  97186. + out, the performance impact will be obvious right on boot as this
  97187. + mechanism engages from very early on. A good rule of thumb is that
  97188. + VMs running on CPUs without hardware virtualization support (i.e.,
  97189. + the majority of IA-32 CPUs) will likely experience the slowdown.
  97190. +
  97191. + On X86_64 the kernel will make use of PCID support when available
  97192. + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
  97193. + or performance impact. Pass pax_weakuderef on the kernel command
  97194. + line to choose the latter.
  97195. +
  97196. +config PAX_REFCOUNT
  97197. + bool "Prevent various kernel object reference counter overflows"
  97198. + default y if GRKERNSEC_CONFIG_AUTO
  97199. + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
  97200. + help
  97201. + By saying Y here the kernel will detect and prevent overflowing
  97202. + various (but not all) kinds of object reference counters. Such
  97203. + overflows can normally occur due to bugs only and are often, if
  97204. + not always, exploitable.
  97205. +
  97206. + The tradeoff is that data structures protected by an overflowed
  97207. + refcount will never be freed and therefore will leak memory. Note
  97208. + that this leak also happens even without this protection but in
  97209. + that case the overflow can eventually trigger the freeing of the
  97210. + data structure while it is still being used elsewhere, resulting
  97211. + in the exploitable situation that this feature prevents.
  97212. +
  97213. + Since this has a negligible performance impact, you should enable
  97214. + this feature.
  97215. +
  97216. +config PAX_CONSTIFY_PLUGIN
  97217. + bool "Automatically constify eligible structures"
  97218. + default y
  97219. + depends on !UML && PAX_KERNEXEC
  97220. + help
  97221. + By saying Y here the compiler will automatically constify a class
  97222. + of types that contain only function pointers. This reduces the
  97223. + kernel's attack surface and also produces a better memory layout.
  97224. +
  97225. + Note that the implementation requires a gcc with plugin support,
  97226. + i.e., gcc 4.5 or newer. You may need to install the supporting
  97227. + headers explicitly in addition to the normal gcc package.
  97228. +
  97229. + Note that if some code really has to modify constified variables
  97230. + then the source code will have to be patched to allow it. Examples
  97231. + can be found in PaX itself (the no_const attribute) and for some
  97232. + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
  97233. +
  97234. +config PAX_USERCOPY
  97235. + bool "Harden heap object copies between kernel and userland"
  97236. + default y if GRKERNSEC_CONFIG_AUTO
  97237. + depends on ARM || IA64 || PPC || SPARC || X86
  97238. + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
  97239. + select PAX_USERCOPY_SLABS
  97240. + help
  97241. + By saying Y here the kernel will enforce the size of heap objects
  97242. + when they are copied in either direction between the kernel and
  97243. + userland, even if only a part of the heap object is copied.
  97244. +
  97245. + Specifically, this checking prevents information leaking from the
  97246. + kernel heap during kernel to userland copies (if the kernel heap
  97247. + object is otherwise fully initialized) and prevents kernel heap
  97248. + overflows during userland to kernel copies.
  97249. +
  97250. + Note that the current implementation provides the strictest bounds
  97251. + checks for the SLUB allocator.
  97252. +
  97253. + Enabling this option also enables per-slab cache protection against
  97254. + data in a given cache being copied into/out of via userland
  97255. + accessors. Though the whitelist of regions will be reduced over
  97256. + time, it notably protects important data structures like task structs.
  97257. +
  97258. + If frame pointers are enabled on x86, this option will also restrict
  97259. + copies into and out of the kernel stack to local variables within a
  97260. + single frame.
  97261. +
  97262. + Since this has a negligible performance impact, you should enable
  97263. + this feature.
  97264. +
  97265. +config PAX_USERCOPY_DEBUG
  97266. + bool
  97267. + depends on X86 && PAX_USERCOPY
  97268. + default n
  97269. +
  97270. +config PAX_SIZE_OVERFLOW
  97271. + bool "Prevent various integer overflows in function size parameters"
  97272. + default y if GRKERNSEC_CONFIG_AUTO
  97273. + depends on X86
  97274. + help
  97275. + By saying Y here the kernel recomputes expressions of function
  97276. + arguments marked by a size_overflow attribute with double integer
  97277. + precision (DImode/TImode for 32/64 bit integer types).
  97278. +
  97279. + The recomputed argument is checked against TYPE_MAX and an event
  97280. + is logged on overflow and the triggering process is killed.
  97281. +
  97282. + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
  97283. +
  97284. + Note that the implementation requires a gcc with plugin support,
  97285. + i.e., gcc 4.5 or newer. You may need to install the supporting
  97286. + headers explicitly in addition to the normal gcc package.
  97287. +
  97288. +config PAX_LATENT_ENTROPY
  97289. + bool "Generate some entropy during boot and runtime"
  97290. + default y if GRKERNSEC_CONFIG_AUTO
  97291. + help
  97292. + By saying Y here the kernel will instrument some kernel code to
  97293. + extract some entropy from both original and artificially created
  97294. + program state. This will help especially embedded systems where
  97295. + there is little 'natural' source of entropy normally. The cost
  97296. + is some slowdown of the boot process and fork and irq processing.
  97297. +
  97298. + When pax_extra_latent_entropy is passed on the kernel command line,
  97299. + entropy will be extracted from up to the first 4GB of RAM while the
  97300. + runtime memory allocator is being initialized. This costs even more
  97301. + slowdown of the boot process.
  97302. +
  97303. + Note that the implementation requires a gcc with plugin support,
  97304. + i.e., gcc 4.5 or newer. You may need to install the supporting
  97305. + headers explicitly in addition to the normal gcc package.
  97306. +
  97307. + Note that entropy extracted this way is not cryptographically
  97308. + secure!
  97309. +
  97310. +endmenu
  97311. +
  97312. +endmenu
  97313. +
  97314. +source grsecurity/Kconfig
  97315. +
  97316. +endmenu
  97317. +
  97318. +endmenu
  97319. +
  97320. source security/keys/Kconfig
  97321. config SECURITY_DMESG_RESTRICT
  97322. @@ -103,7 +1058,7 @@ config INTEL_TXT
  97323. config LSM_MMAP_MIN_ADDR
  97324. int "Low address space for LSM to protect from user allocation"
  97325. depends on SECURITY && SECURITY_SELINUX
  97326. - default 32768 if ARM || (ARM64 && COMPAT)
  97327. + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
  97328. default 65536
  97329. help
  97330. This is the portion of low virtual memory which should be protected
  97331. diff --git a/security/apparmor/file.c b/security/apparmor/file.c
  97332. index fdaa50c..2761dcb 100644
  97333. --- a/security/apparmor/file.c
  97334. +++ b/security/apparmor/file.c
  97335. @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
  97336. int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
  97337. struct path *new_dir, struct dentry *new_dentry)
  97338. {
  97339. - struct path link = { new_dir->mnt, new_dentry };
  97340. - struct path target = { new_dir->mnt, old_dentry };
  97341. + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
  97342. + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
  97343. struct path_cond cond = {
  97344. old_dentry->d_inode->i_uid,
  97345. old_dentry->d_inode->i_mode
  97346. diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
  97347. index 4257b7e..2d0732d 100644
  97348. --- a/security/apparmor/lsm.c
  97349. +++ b/security/apparmor/lsm.c
  97350. @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
  97351. struct dentry *dentry, u32 mask,
  97352. struct path_cond *cond)
  97353. {
  97354. - struct path path = { dir->mnt, dentry };
  97355. + struct path path = { .mnt = dir->mnt, .dentry = dentry };
  97356. return common_perm(op, &path, mask, cond);
  97357. }
  97358. @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
  97359. static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
  97360. struct dentry *dentry, u32 mask)
  97361. {
  97362. - struct path path = { mnt, dentry };
  97363. + struct path path = { .mnt = mnt, .dentry = dentry };
  97364. struct path_cond cond = { dentry->d_inode->i_uid,
  97365. dentry->d_inode->i_mode
  97366. };
  97367. @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
  97368. profile = aa_current_profile();
  97369. if (!unconfined(profile)) {
  97370. - struct path old_path = { old_dir->mnt, old_dentry };
  97371. - struct path new_path = { new_dir->mnt, new_dentry };
  97372. + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
  97373. + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
  97374. struct path_cond cond = { old_dentry->d_inode->i_uid,
  97375. old_dentry->d_inode->i_mode
  97376. };
  97377. @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
  97378. return error;
  97379. }
  97380. -static struct security_operations apparmor_ops = {
  97381. +static struct security_operations apparmor_ops __read_only = {
  97382. .name = "apparmor",
  97383. .ptrace_access_check = apparmor_ptrace_access_check,
  97384. diff --git a/security/commoncap.c b/security/commoncap.c
  97385. index b9d613e..f68305c 100644
  97386. --- a/security/commoncap.c
  97387. +++ b/security/commoncap.c
  97388. @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
  97389. return 0;
  97390. }
  97391. +/* returns:
  97392. + 1 for suid privilege
  97393. + 2 for sgid privilege
  97394. + 3 for fscap privilege
  97395. +*/
  97396. +int is_privileged_binary(const struct dentry *dentry)
  97397. +{
  97398. + struct cpu_vfs_cap_data capdata;
  97399. + struct inode *inode = dentry->d_inode;
  97400. +
  97401. + if (!inode || S_ISDIR(inode->i_mode))
  97402. + return 0;
  97403. +
  97404. + if (inode->i_mode & S_ISUID)
  97405. + return 1;
  97406. + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
  97407. + return 2;
  97408. +
  97409. + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
  97410. + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
  97411. + return 3;
  97412. + }
  97413. +
  97414. + return 0;
  97415. +}
  97416. +
  97417. /*
  97418. * Attempt to get the on-exec apply capability sets for an executable file from
  97419. * its xattrs and, if present, apply them to the proposed credentials being
  97420. @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
  97421. const struct cred *cred = current_cred();
  97422. kuid_t root_uid = make_kuid(cred->user_ns, 0);
  97423. + if (gr_acl_enable_at_secure())
  97424. + return 1;
  97425. +
  97426. if (!uid_eq(cred->uid, root_uid)) {
  97427. if (bprm->cap_effective)
  97428. return 1;
  97429. diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
  97430. index f79fa8b..6161868 100644
  97431. --- a/security/integrity/ima/ima.h
  97432. +++ b/security/integrity/ima/ima.h
  97433. @@ -118,8 +118,8 @@ int ima_init_template(void);
  97434. extern spinlock_t ima_queue_lock;
  97435. struct ima_h_table {
  97436. - atomic_long_t len; /* number of stored measurements in the list */
  97437. - atomic_long_t violations;
  97438. + atomic_long_unchecked_t len; /* number of stored measurements in the list */
  97439. + atomic_long_unchecked_t violations;
  97440. struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
  97441. };
  97442. extern struct ima_h_table ima_htable;
  97443. diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
  97444. index c38bbce..f45133d 100644
  97445. --- a/security/integrity/ima/ima_api.c
  97446. +++ b/security/integrity/ima/ima_api.c
  97447. @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
  97448. int result;
  97449. /* can overflow, only indicator */
  97450. - atomic_long_inc(&ima_htable.violations);
  97451. + atomic_long_inc_unchecked(&ima_htable.violations);
  97452. result = ima_alloc_init_template(NULL, file, filename,
  97453. NULL, 0, &entry);
  97454. diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
  97455. index 468a3ba..9af5cae 100644
  97456. --- a/security/integrity/ima/ima_fs.c
  97457. +++ b/security/integrity/ima/ima_fs.c
  97458. @@ -28,12 +28,12 @@
  97459. static int valid_policy = 1;
  97460. #define TMPBUFLEN 12
  97461. static ssize_t ima_show_htable_value(char __user *buf, size_t count,
  97462. - loff_t *ppos, atomic_long_t *val)
  97463. + loff_t *ppos, atomic_long_unchecked_t *val)
  97464. {
  97465. char tmpbuf[TMPBUFLEN];
  97466. ssize_t len;
  97467. - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
  97468. + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
  97469. return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
  97470. }
  97471. diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
  97472. index d85e997..6992813 100644
  97473. --- a/security/integrity/ima/ima_queue.c
  97474. +++ b/security/integrity/ima/ima_queue.c
  97475. @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
  97476. INIT_LIST_HEAD(&qe->later);
  97477. list_add_tail_rcu(&qe->later, &ima_measurements);
  97478. - atomic_long_inc(&ima_htable.len);
  97479. + atomic_long_inc_unchecked(&ima_htable.len);
  97480. key = ima_hash_key(entry->digest);
  97481. hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
  97482. return 0;
  97483. diff --git a/security/keys/compat.c b/security/keys/compat.c
  97484. index bbd32c7..c60c927 100644
  97485. --- a/security/keys/compat.c
  97486. +++ b/security/keys/compat.c
  97487. @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
  97488. if (ret == 0)
  97489. goto no_payload_free;
  97490. - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
  97491. + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
  97492. err:
  97493. if (iov != iovstack)
  97494. kfree(iov);
  97495. diff --git a/security/keys/internal.h b/security/keys/internal.h
  97496. index 80b2aac..bb7ee65 100644
  97497. --- a/security/keys/internal.h
  97498. +++ b/security/keys/internal.h
  97499. @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
  97500. extern long keyctl_invalidate_key(key_serial_t);
  97501. extern long keyctl_instantiate_key_common(key_serial_t,
  97502. - const struct iovec *,
  97503. + const struct iovec __user *,
  97504. unsigned, size_t, key_serial_t);
  97505. #ifdef CONFIG_PERSISTENT_KEYRINGS
  97506. extern long keyctl_get_persistent(uid_t, key_serial_t);
  97507. diff --git a/security/keys/key.c b/security/keys/key.c
  97508. index 6e21c11..9ed67ca 100644
  97509. --- a/security/keys/key.c
  97510. +++ b/security/keys/key.c
  97511. @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
  97512. atomic_set(&key->usage, 1);
  97513. init_rwsem(&key->sem);
  97514. - lockdep_set_class(&key->sem, &type->lock_class);
  97515. + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
  97516. key->index_key.type = type;
  97517. key->user = user;
  97518. key->quotalen = quotalen;
  97519. @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
  97520. struct key_type *p;
  97521. int ret;
  97522. - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
  97523. + pax_open_kernel();
  97524. + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
  97525. + pax_close_kernel();
  97526. ret = -EEXIST;
  97527. down_write(&key_types_sem);
  97528. @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
  97529. }
  97530. /* store the type */
  97531. - list_add(&ktype->link, &key_types_list);
  97532. + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
  97533. pr_notice("Key type %s registered\n", ktype->name);
  97534. ret = 0;
  97535. @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
  97536. void unregister_key_type(struct key_type *ktype)
  97537. {
  97538. down_write(&key_types_sem);
  97539. - list_del_init(&ktype->link);
  97540. + pax_list_del_init((struct list_head *)&ktype->link);
  97541. downgrade_write(&key_types_sem);
  97542. key_gc_keytype(ktype);
  97543. pr_notice("Key type %s unregistered\n", ktype->name);
  97544. @@ -1088,10 +1090,10 @@ void __init key_init(void)
  97545. 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
  97546. /* add the special key types */
  97547. - list_add_tail(&key_type_keyring.link, &key_types_list);
  97548. - list_add_tail(&key_type_dead.link, &key_types_list);
  97549. - list_add_tail(&key_type_user.link, &key_types_list);
  97550. - list_add_tail(&key_type_logon.link, &key_types_list);
  97551. + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
  97552. + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
  97553. + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
  97554. + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
  97555. /* record the root user tracking */
  97556. rb_link_node(&root_key_user.node,
  97557. diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
  97558. index cee72ce..e46074a 100644
  97559. --- a/security/keys/keyctl.c
  97560. +++ b/security/keys/keyctl.c
  97561. @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
  97562. /*
  97563. * Copy the iovec data from userspace
  97564. */
  97565. -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
  97566. +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
  97567. unsigned ioc)
  97568. {
  97569. for (; ioc > 0; ioc--) {
  97570. @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
  97571. * If successful, 0 will be returned.
  97572. */
  97573. long keyctl_instantiate_key_common(key_serial_t id,
  97574. - const struct iovec *payload_iov,
  97575. + const struct iovec __user *payload_iov,
  97576. unsigned ioc,
  97577. size_t plen,
  97578. key_serial_t ringid)
  97579. @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
  97580. [0].iov_len = plen
  97581. };
  97582. - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
  97583. + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
  97584. }
  97585. return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
  97586. @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
  97587. if (ret == 0)
  97588. goto no_payload_free;
  97589. - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
  97590. + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
  97591. err:
  97592. if (iov != iovstack)
  97593. kfree(iov);
  97594. diff --git a/security/min_addr.c b/security/min_addr.c
  97595. index f728728..6457a0c 100644
  97596. --- a/security/min_addr.c
  97597. +++ b/security/min_addr.c
  97598. @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
  97599. */
  97600. static void update_mmap_min_addr(void)
  97601. {
  97602. +#ifndef SPARC
  97603. #ifdef CONFIG_LSM_MMAP_MIN_ADDR
  97604. if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
  97605. mmap_min_addr = dac_mmap_min_addr;
  97606. @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
  97607. #else
  97608. mmap_min_addr = dac_mmap_min_addr;
  97609. #endif
  97610. +#endif
  97611. }
  97612. /*
  97613. diff --git a/security/security.c b/security/security.c
  97614. index 919cad9..2127be1 100644
  97615. --- a/security/security.c
  97616. +++ b/security/security.c
  97617. @@ -33,8 +33,8 @@
  97618. static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
  97619. CONFIG_DEFAULT_SECURITY;
  97620. -static struct security_operations *security_ops;
  97621. -static struct security_operations default_security_ops = {
  97622. +struct security_operations *security_ops __read_only;
  97623. +struct security_operations default_security_ops __read_only = {
  97624. .name = "default",
  97625. };
  97626. @@ -73,11 +73,6 @@ int __init security_init(void)
  97627. return 0;
  97628. }
  97629. -void reset_security_ops(void)
  97630. -{
  97631. - security_ops = &default_security_ops;
  97632. -}
  97633. -
  97634. /* Save user chosen LSM */
  97635. static int __init choose_lsm(char *str)
  97636. {
  97637. diff --git a/security/selinux/avc.c b/security/selinux/avc.c
  97638. index fc3e662..7844c60 100644
  97639. --- a/security/selinux/avc.c
  97640. +++ b/security/selinux/avc.c
  97641. @@ -59,7 +59,7 @@ struct avc_node {
  97642. struct avc_cache {
  97643. struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
  97644. spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
  97645. - atomic_t lru_hint; /* LRU hint for reclaim scan */
  97646. + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
  97647. atomic_t active_nodes;
  97648. u32 latest_notif; /* latest revocation notification */
  97649. };
  97650. @@ -167,7 +167,7 @@ void __init avc_init(void)
  97651. spin_lock_init(&avc_cache.slots_lock[i]);
  97652. }
  97653. atomic_set(&avc_cache.active_nodes, 0);
  97654. - atomic_set(&avc_cache.lru_hint, 0);
  97655. + atomic_set_unchecked(&avc_cache.lru_hint, 0);
  97656. avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
  97657. 0, SLAB_PANIC, NULL);
  97658. @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
  97659. spinlock_t *lock;
  97660. for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
  97661. - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
  97662. + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
  97663. head = &avc_cache.slots[hvalue];
  97664. lock = &avc_cache.slots_lock[hvalue];
  97665. diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
  97666. index e294b86..eda45c55 100644
  97667. --- a/security/selinux/hooks.c
  97668. +++ b/security/selinux/hooks.c
  97669. @@ -95,8 +95,6 @@
  97670. #include "audit.h"
  97671. #include "avc_ss.h"
  97672. -extern struct security_operations *security_ops;
  97673. -
  97674. /* SECMARK reference count */
  97675. static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
  97676. @@ -5759,7 +5757,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
  97677. #endif
  97678. -static struct security_operations selinux_ops = {
  97679. +static struct security_operations selinux_ops __read_only = {
  97680. .name = "selinux",
  97681. .ptrace_access_check = selinux_ptrace_access_check,
  97682. @@ -6112,6 +6110,9 @@ static void selinux_nf_ip_exit(void)
  97683. #ifdef CONFIG_SECURITY_SELINUX_DISABLE
  97684. static int selinux_disabled;
  97685. +extern struct security_operations *security_ops;
  97686. +extern struct security_operations default_security_ops;
  97687. +
  97688. int selinux_disable(void)
  97689. {
  97690. if (ss_initialized) {
  97691. @@ -6129,7 +6130,9 @@ int selinux_disable(void)
  97692. selinux_disabled = 1;
  97693. selinux_enabled = 0;
  97694. - reset_security_ops();
  97695. + pax_open_kernel();
  97696. + security_ops = &default_security_ops;
  97697. + pax_close_kernel();
  97698. /* Try to destroy the avc node cache */
  97699. avc_disable();
  97700. diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
  97701. index 9f05847..7933395 100644
  97702. --- a/security/selinux/include/xfrm.h
  97703. +++ b/security/selinux/include/xfrm.h
  97704. @@ -46,7 +46,7 @@ static inline void selinux_xfrm_notify_policyload(void)
  97705. {
  97706. struct net *net;
  97707. - atomic_inc(&flow_cache_genid);
  97708. + atomic_inc_unchecked(&flow_cache_genid);
  97709. rtnl_lock();
  97710. for_each_net(net)
  97711. rt_genid_bump_all(net);
  97712. diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
  97713. index 14f52be..7352368 100644
  97714. --- a/security/smack/smack_lsm.c
  97715. +++ b/security/smack/smack_lsm.c
  97716. @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
  97717. return 0;
  97718. }
  97719. -struct security_operations smack_ops = {
  97720. +struct security_operations smack_ops __read_only = {
  97721. .name = "smack",
  97722. .ptrace_access_check = smack_ptrace_access_check,
  97723. diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
  97724. index 4003907..13a2b55 100644
  97725. --- a/security/tomoyo/file.c
  97726. +++ b/security/tomoyo/file.c
  97727. @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
  97728. {
  97729. struct tomoyo_request_info r;
  97730. struct tomoyo_obj_info obj = {
  97731. - .path1 = *path,
  97732. + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
  97733. };
  97734. int error = -ENOMEM;
  97735. struct tomoyo_path_info buf;
  97736. @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
  97737. struct tomoyo_path_info buf;
  97738. struct tomoyo_request_info r;
  97739. struct tomoyo_obj_info obj = {
  97740. - .path1 = *path,
  97741. + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
  97742. };
  97743. int idx;
  97744. @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
  97745. {
  97746. struct tomoyo_request_info r;
  97747. struct tomoyo_obj_info obj = {
  97748. - .path1 = *path,
  97749. + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
  97750. };
  97751. int error;
  97752. struct tomoyo_path_info buf;
  97753. @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
  97754. {
  97755. struct tomoyo_request_info r;
  97756. struct tomoyo_obj_info obj = {
  97757. - .path1 = *path,
  97758. + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
  97759. };
  97760. int error = -ENOMEM;
  97761. struct tomoyo_path_info buf;
  97762. @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
  97763. struct tomoyo_path_info buf2;
  97764. struct tomoyo_request_info r;
  97765. struct tomoyo_obj_info obj = {
  97766. - .path1 = *path1,
  97767. - .path2 = *path2,
  97768. + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
  97769. + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
  97770. };
  97771. int idx;
  97772. diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
  97773. index 390c646..f2f8db3 100644
  97774. --- a/security/tomoyo/mount.c
  97775. +++ b/security/tomoyo/mount.c
  97776. @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
  97777. type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
  97778. need_dev = -1; /* dev_name is a directory */
  97779. } else {
  97780. + if (!capable(CAP_SYS_ADMIN)) {
  97781. + error = -EPERM;
  97782. + goto out;
  97783. + }
  97784. fstype = get_fs_type(type);
  97785. if (!fstype) {
  97786. error = -ENODEV;
  97787. diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
  97788. index f0b756e..8aa497b 100644
  97789. --- a/security/tomoyo/tomoyo.c
  97790. +++ b/security/tomoyo/tomoyo.c
  97791. @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
  97792. */
  97793. static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
  97794. {
  97795. - struct path path = { mnt, dentry };
  97796. + struct path path = { .mnt = mnt, .dentry = dentry };
  97797. return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
  97798. }
  97799. @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
  97800. */
  97801. static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
  97802. {
  97803. - struct path path = { parent->mnt, dentry };
  97804. + struct path path = { .mnt = parent->mnt, .dentry = dentry };
  97805. return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
  97806. }
  97807. @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
  97808. static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
  97809. umode_t mode)
  97810. {
  97811. - struct path path = { parent->mnt, dentry };
  97812. + struct path path = { .mnt = parent->mnt, .dentry = dentry };
  97813. return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
  97814. mode & S_IALLUGO);
  97815. }
  97816. @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
  97817. */
  97818. static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
  97819. {
  97820. - struct path path = { parent->mnt, dentry };
  97821. + struct path path = { .mnt = parent->mnt, .dentry = dentry };
  97822. return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
  97823. }
  97824. @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
  97825. static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
  97826. const char *old_name)
  97827. {
  97828. - struct path path = { parent->mnt, dentry };
  97829. + struct path path = { .mnt = parent->mnt, .dentry = dentry };
  97830. return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
  97831. }
  97832. @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
  97833. static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
  97834. umode_t mode, unsigned int dev)
  97835. {
  97836. - struct path path = { parent->mnt, dentry };
  97837. + struct path path = { .mnt = parent->mnt, .dentry = dentry };
  97838. int type = TOMOYO_TYPE_CREATE;
  97839. const unsigned int perm = mode & S_IALLUGO;
  97840. @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
  97841. static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
  97842. struct dentry *new_dentry)
  97843. {
  97844. - struct path path1 = { new_dir->mnt, old_dentry };
  97845. - struct path path2 = { new_dir->mnt, new_dentry };
  97846. + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
  97847. + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
  97848. return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
  97849. }
  97850. @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
  97851. struct path *new_parent,
  97852. struct dentry *new_dentry)
  97853. {
  97854. - struct path path1 = { old_parent->mnt, old_dentry };
  97855. - struct path path2 = { new_parent->mnt, new_dentry };
  97856. + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
  97857. + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
  97858. return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
  97859. }
  97860. @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
  97861. */
  97862. static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
  97863. {
  97864. - struct path path = { mnt, mnt->mnt_root };
  97865. + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
  97866. return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
  97867. }
  97868. @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
  97869. * tomoyo_security_ops is a "struct security_operations" which is used for
  97870. * registering TOMOYO.
  97871. */
  97872. -static struct security_operations tomoyo_security_ops = {
  97873. +static struct security_operations tomoyo_security_ops __read_only = {
  97874. .name = "tomoyo",
  97875. .cred_alloc_blank = tomoyo_cred_alloc_blank,
  97876. .cred_prepare = tomoyo_cred_prepare,
  97877. diff --git a/security/yama/Kconfig b/security/yama/Kconfig
  97878. index 20ef514..4182bed 100644
  97879. --- a/security/yama/Kconfig
  97880. +++ b/security/yama/Kconfig
  97881. @@ -1,6 +1,6 @@
  97882. config SECURITY_YAMA
  97883. bool "Yama support"
  97884. - depends on SECURITY
  97885. + depends on SECURITY && !GRKERNSEC
  97886. select SECURITYFS
  97887. select SECURITY_PATH
  97888. default n
  97889. diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
  97890. index 13c88fbc..f8c115e 100644
  97891. --- a/security/yama/yama_lsm.c
  97892. +++ b/security/yama/yama_lsm.c
  97893. @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
  97894. }
  97895. #ifndef CONFIG_SECURITY_YAMA_STACKED
  97896. -static struct security_operations yama_ops = {
  97897. +static struct security_operations yama_ops __read_only = {
  97898. .name = "yama",
  97899. .ptrace_access_check = yama_ptrace_access_check,
  97900. @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
  97901. #endif
  97902. #ifdef CONFIG_SYSCTL
  97903. +static int zero __read_only;
  97904. +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
  97905. +
  97906. static int yama_dointvec_minmax(struct ctl_table *table, int write,
  97907. void __user *buffer, size_t *lenp, loff_t *ppos)
  97908. {
  97909. - int rc;
  97910. + ctl_table_no_const yama_table;
  97911. if (write && !capable(CAP_SYS_PTRACE))
  97912. return -EPERM;
  97913. - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  97914. - if (rc)
  97915. - return rc;
  97916. -
  97917. + yama_table = *table;
  97918. /* Lock the max value if it ever gets set. */
  97919. - if (write && *(int *)table->data == *(int *)table->extra2)
  97920. - table->extra1 = table->extra2;
  97921. -
  97922. - return rc;
  97923. + if (ptrace_scope == max_scope)
  97924. + yama_table.extra1 = &max_scope;
  97925. + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
  97926. }
  97927. -static int zero;
  97928. -static int max_scope = YAMA_SCOPE_NO_ATTACH;
  97929. -
  97930. struct ctl_path yama_sysctl_path[] = {
  97931. { .procname = "kernel", },
  97932. { .procname = "yama", },
  97933. diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
  97934. index 4cedc69..e59d8a3 100644
  97935. --- a/sound/aoa/codecs/onyx.c
  97936. +++ b/sound/aoa/codecs/onyx.c
  97937. @@ -54,7 +54,7 @@ struct onyx {
  97938. spdif_locked:1,
  97939. analog_locked:1,
  97940. original_mute:2;
  97941. - int open_count;
  97942. + local_t open_count;
  97943. struct codec_info *codec_info;
  97944. /* mutex serializes concurrent access to the device
  97945. @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
  97946. struct onyx *onyx = cii->codec_data;
  97947. mutex_lock(&onyx->mutex);
  97948. - onyx->open_count++;
  97949. + local_inc(&onyx->open_count);
  97950. mutex_unlock(&onyx->mutex);
  97951. return 0;
  97952. @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
  97953. struct onyx *onyx = cii->codec_data;
  97954. mutex_lock(&onyx->mutex);
  97955. - onyx->open_count--;
  97956. - if (!onyx->open_count)
  97957. + if (local_dec_and_test(&onyx->open_count))
  97958. onyx->spdif_locked = onyx->analog_locked = 0;
  97959. mutex_unlock(&onyx->mutex);
  97960. diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
  97961. index ffd2025..df062c9 100644
  97962. --- a/sound/aoa/codecs/onyx.h
  97963. +++ b/sound/aoa/codecs/onyx.h
  97964. @@ -11,6 +11,7 @@
  97965. #include <linux/i2c.h>
  97966. #include <asm/pmac_low_i2c.h>
  97967. #include <asm/prom.h>
  97968. +#include <asm/local.h>
  97969. /* PCM3052 register definitions */
  97970. diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
  97971. index 4c1cc51..16040040 100644
  97972. --- a/sound/core/oss/pcm_oss.c
  97973. +++ b/sound/core/oss/pcm_oss.c
  97974. @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
  97975. if (in_kernel) {
  97976. mm_segment_t fs;
  97977. fs = snd_enter_user();
  97978. - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
  97979. + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
  97980. snd_leave_user(fs);
  97981. } else {
  97982. - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
  97983. + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
  97984. }
  97985. if (ret != -EPIPE && ret != -ESTRPIPE)
  97986. break;
  97987. @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
  97988. if (in_kernel) {
  97989. mm_segment_t fs;
  97990. fs = snd_enter_user();
  97991. - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
  97992. + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
  97993. snd_leave_user(fs);
  97994. } else {
  97995. - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
  97996. + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
  97997. }
  97998. if (ret == -EPIPE) {
  97999. if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  98000. @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
  98001. struct snd_pcm_plugin_channel *channels;
  98002. size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
  98003. if (!in_kernel) {
  98004. - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
  98005. + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
  98006. return -EFAULT;
  98007. buf = runtime->oss.buffer;
  98008. }
  98009. @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
  98010. }
  98011. } else {
  98012. tmp = snd_pcm_oss_write2(substream,
  98013. - (const char __force *)buf,
  98014. + (const char __force_kernel *)buf,
  98015. runtime->oss.period_bytes, 0);
  98016. if (tmp <= 0)
  98017. goto err;
  98018. @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
  98019. struct snd_pcm_runtime *runtime = substream->runtime;
  98020. snd_pcm_sframes_t frames, frames1;
  98021. #ifdef CONFIG_SND_PCM_OSS_PLUGINS
  98022. - char __user *final_dst = (char __force __user *)buf;
  98023. + char __user *final_dst = (char __force_user *)buf;
  98024. if (runtime->oss.plugin_first) {
  98025. struct snd_pcm_plugin_channel *channels;
  98026. size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
  98027. @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
  98028. xfer += tmp;
  98029. runtime->oss.buffer_used -= tmp;
  98030. } else {
  98031. - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
  98032. + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
  98033. runtime->oss.period_bytes, 0);
  98034. if (tmp <= 0)
  98035. goto err;
  98036. @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
  98037. size1);
  98038. size1 /= runtime->channels; /* frames */
  98039. fs = snd_enter_user();
  98040. - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
  98041. + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
  98042. snd_leave_user(fs);
  98043. }
  98044. } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
  98045. diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
  98046. index af49721..e85058e 100644
  98047. --- a/sound/core/pcm_compat.c
  98048. +++ b/sound/core/pcm_compat.c
  98049. @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
  98050. int err;
  98051. fs = snd_enter_user();
  98052. - err = snd_pcm_delay(substream, &delay);
  98053. + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
  98054. snd_leave_user(fs);
  98055. if (err < 0)
  98056. return err;
  98057. diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
  98058. index 01a5e05..c6bb425 100644
  98059. --- a/sound/core/pcm_native.c
  98060. +++ b/sound/core/pcm_native.c
  98061. @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
  98062. switch (substream->stream) {
  98063. case SNDRV_PCM_STREAM_PLAYBACK:
  98064. result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
  98065. - (void __user *)arg);
  98066. + (void __force_user *)arg);
  98067. break;
  98068. case SNDRV_PCM_STREAM_CAPTURE:
  98069. result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
  98070. - (void __user *)arg);
  98071. + (void __force_user *)arg);
  98072. break;
  98073. default:
  98074. result = -EINVAL;
  98075. diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
  98076. index 8d4d5e8..fdd0826 100644
  98077. --- a/sound/core/seq/oss/seq_oss.c
  98078. +++ b/sound/core/seq/oss/seq_oss.c
  98079. @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
  98080. {
  98081. int rc;
  98082. static struct snd_seq_dev_ops ops = {
  98083. - snd_seq_oss_synth_register,
  98084. - snd_seq_oss_synth_unregister,
  98085. + .init_device = snd_seq_oss_synth_register,
  98086. + .free_device = snd_seq_oss_synth_unregister,
  98087. };
  98088. snd_seq_autoload_lock();
  98089. diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
  98090. index 040c60e..989a19a 100644
  98091. --- a/sound/core/seq/seq_device.c
  98092. +++ b/sound/core/seq/seq_device.c
  98093. @@ -64,7 +64,7 @@ struct ops_list {
  98094. int argsize; /* argument size */
  98095. /* operators */
  98096. - struct snd_seq_dev_ops ops;
  98097. + struct snd_seq_dev_ops *ops;
  98098. /* registered devices */
  98099. struct list_head dev_list; /* list of devices */
  98100. @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
  98101. mutex_lock(&ops->reg_mutex);
  98102. /* copy driver operators */
  98103. - ops->ops = *entry;
  98104. + ops->ops = entry;
  98105. ops->driver |= DRIVER_LOADED;
  98106. ops->argsize = argsize;
  98107. @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
  98108. dev->name, ops->id, ops->argsize, dev->argsize);
  98109. return -EINVAL;
  98110. }
  98111. - if (ops->ops.init_device(dev) >= 0) {
  98112. + if (ops->ops->init_device(dev) >= 0) {
  98113. dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
  98114. ops->num_init_devices++;
  98115. } else {
  98116. @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
  98117. dev->name, ops->id, ops->argsize, dev->argsize);
  98118. return -EINVAL;
  98119. }
  98120. - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
  98121. + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
  98122. dev->status = SNDRV_SEQ_DEVICE_FREE;
  98123. dev->driver_data = NULL;
  98124. ops->num_init_devices--;
  98125. diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
  98126. index 64069db..3c6d392 100644
  98127. --- a/sound/core/seq/seq_midi.c
  98128. +++ b/sound/core/seq/seq_midi.c
  98129. @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
  98130. static int __init alsa_seq_midi_init(void)
  98131. {
  98132. static struct snd_seq_dev_ops ops = {
  98133. - snd_seq_midisynth_register_port,
  98134. - snd_seq_midisynth_unregister_port,
  98135. + .init_device = snd_seq_midisynth_register_port,
  98136. + .free_device = snd_seq_midisynth_unregister_port,
  98137. };
  98138. memset(&synths, 0, sizeof(synths));
  98139. snd_seq_autoload_lock();
  98140. diff --git a/sound/core/sound.c b/sound/core/sound.c
  98141. index 437c25e..cd040ab 100644
  98142. --- a/sound/core/sound.c
  98143. +++ b/sound/core/sound.c
  98144. @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
  98145. case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
  98146. default: return;
  98147. }
  98148. - request_module(str);
  98149. + request_module("%s", str);
  98150. }
  98151. #endif /* modular kernel */
  98152. diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
  98153. index 4e0dd22..7a1f32c 100644
  98154. --- a/sound/drivers/mts64.c
  98155. +++ b/sound/drivers/mts64.c
  98156. @@ -29,6 +29,7 @@
  98157. #include <sound/initval.h>
  98158. #include <sound/rawmidi.h>
  98159. #include <sound/control.h>
  98160. +#include <asm/local.h>
  98161. #define CARD_NAME "Miditerminal 4140"
  98162. #define DRIVER_NAME "MTS64"
  98163. @@ -67,7 +68,7 @@ struct mts64 {
  98164. struct pardevice *pardev;
  98165. int pardev_claimed;
  98166. - int open_count;
  98167. + local_t open_count;
  98168. int current_midi_output_port;
  98169. int current_midi_input_port;
  98170. u8 mode[MTS64_NUM_INPUT_PORTS];
  98171. @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
  98172. {
  98173. struct mts64 *mts = substream->rmidi->private_data;
  98174. - if (mts->open_count == 0) {
  98175. + if (local_read(&mts->open_count) == 0) {
  98176. /* We don't need a spinlock here, because this is just called
  98177. if the device has not been opened before.
  98178. So there aren't any IRQs from the device */
  98179. @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
  98180. msleep(50);
  98181. }
  98182. - ++(mts->open_count);
  98183. + local_inc(&mts->open_count);
  98184. return 0;
  98185. }
  98186. @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
  98187. struct mts64 *mts = substream->rmidi->private_data;
  98188. unsigned long flags;
  98189. - --(mts->open_count);
  98190. - if (mts->open_count == 0) {
  98191. + if (local_dec_return(&mts->open_count) == 0) {
  98192. /* We need the spinlock_irqsave here because we can still
  98193. have IRQs at this point */
  98194. spin_lock_irqsave(&mts->lock, flags);
  98195. @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
  98196. msleep(500);
  98197. - } else if (mts->open_count < 0)
  98198. - mts->open_count = 0;
  98199. + } else if (local_read(&mts->open_count) < 0)
  98200. + local_set(&mts->open_count, 0);
  98201. return 0;
  98202. }
  98203. diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
  98204. index 6839953..7a0f4b9 100644
  98205. --- a/sound/drivers/opl3/opl3_seq.c
  98206. +++ b/sound/drivers/opl3/opl3_seq.c
  98207. @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
  98208. {
  98209. static struct snd_seq_dev_ops ops =
  98210. {
  98211. - snd_opl3_seq_new_device,
  98212. - snd_opl3_seq_delete_device
  98213. + .init_device = snd_opl3_seq_new_device,
  98214. + .free_device = snd_opl3_seq_delete_device
  98215. };
  98216. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
  98217. diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
  98218. index b953fb4..1999c01 100644
  98219. --- a/sound/drivers/opl4/opl4_lib.c
  98220. +++ b/sound/drivers/opl4/opl4_lib.c
  98221. @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  98222. MODULE_DESCRIPTION("OPL4 driver");
  98223. MODULE_LICENSE("GPL");
  98224. -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
  98225. +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
  98226. {
  98227. int timeout = 10;
  98228. while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
  98229. diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
  98230. index 9919769..d7de36c 100644
  98231. --- a/sound/drivers/opl4/opl4_seq.c
  98232. +++ b/sound/drivers/opl4/opl4_seq.c
  98233. @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
  98234. static int __init alsa_opl4_synth_init(void)
  98235. {
  98236. static struct snd_seq_dev_ops ops = {
  98237. - snd_opl4_seq_new_device,
  98238. - snd_opl4_seq_delete_device
  98239. + .init_device = snd_opl4_seq_new_device,
  98240. + .free_device = snd_opl4_seq_delete_device
  98241. };
  98242. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
  98243. diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
  98244. index 991018d..8984740 100644
  98245. --- a/sound/drivers/portman2x4.c
  98246. +++ b/sound/drivers/portman2x4.c
  98247. @@ -48,6 +48,7 @@
  98248. #include <sound/initval.h>
  98249. #include <sound/rawmidi.h>
  98250. #include <sound/control.h>
  98251. +#include <asm/local.h>
  98252. #define CARD_NAME "Portman 2x4"
  98253. #define DRIVER_NAME "portman"
  98254. @@ -85,7 +86,7 @@ struct portman {
  98255. struct pardevice *pardev;
  98256. int pardev_claimed;
  98257. - int open_count;
  98258. + local_t open_count;
  98259. int mode[PORTMAN_NUM_INPUT_PORTS];
  98260. struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
  98261. };
  98262. diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
  98263. index 9048777..2d8b1fc 100644
  98264. --- a/sound/firewire/amdtp.c
  98265. +++ b/sound/firewire/amdtp.c
  98266. @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
  98267. ptr = s->pcm_buffer_pointer + data_blocks;
  98268. if (ptr >= pcm->runtime->buffer_size)
  98269. ptr -= pcm->runtime->buffer_size;
  98270. - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
  98271. + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
  98272. s->pcm_period_pointer += data_blocks;
  98273. if (s->pcm_period_pointer >= pcm->runtime->period_size) {
  98274. @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
  98275. */
  98276. void amdtp_out_stream_update(struct amdtp_out_stream *s)
  98277. {
  98278. - ACCESS_ONCE(s->source_node_id_field) =
  98279. + ACCESS_ONCE_RW(s->source_node_id_field) =
  98280. (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
  98281. }
  98282. EXPORT_SYMBOL(amdtp_out_stream_update);
  98283. diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
  98284. index 2746ecd..c35dedd 100644
  98285. --- a/sound/firewire/amdtp.h
  98286. +++ b/sound/firewire/amdtp.h
  98287. @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
  98288. static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
  98289. struct snd_pcm_substream *pcm)
  98290. {
  98291. - ACCESS_ONCE(s->pcm) = pcm;
  98292. + ACCESS_ONCE_RW(s->pcm) = pcm;
  98293. }
  98294. static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
  98295. diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
  98296. index fd42e6b..c041971 100644
  98297. --- a/sound/firewire/isight.c
  98298. +++ b/sound/firewire/isight.c
  98299. @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
  98300. ptr += count;
  98301. if (ptr >= runtime->buffer_size)
  98302. ptr -= runtime->buffer_size;
  98303. - ACCESS_ONCE(isight->buffer_pointer) = ptr;
  98304. + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
  98305. isight->period_counter += count;
  98306. if (isight->period_counter >= runtime->period_size) {
  98307. @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
  98308. if (err < 0)
  98309. return err;
  98310. - ACCESS_ONCE(isight->pcm_active) = true;
  98311. + ACCESS_ONCE_RW(isight->pcm_active) = true;
  98312. return 0;
  98313. }
  98314. @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
  98315. {
  98316. struct isight *isight = substream->private_data;
  98317. - ACCESS_ONCE(isight->pcm_active) = false;
  98318. + ACCESS_ONCE_RW(isight->pcm_active) = false;
  98319. mutex_lock(&isight->mutex);
  98320. isight_stop_streaming(isight);
  98321. @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
  98322. switch (cmd) {
  98323. case SNDRV_PCM_TRIGGER_START:
  98324. - ACCESS_ONCE(isight->pcm_running) = true;
  98325. + ACCESS_ONCE_RW(isight->pcm_running) = true;
  98326. break;
  98327. case SNDRV_PCM_TRIGGER_STOP:
  98328. - ACCESS_ONCE(isight->pcm_running) = false;
  98329. + ACCESS_ONCE_RW(isight->pcm_running) = false;
  98330. break;
  98331. default:
  98332. return -EINVAL;
  98333. diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
  98334. index 858023c..83b3d3c 100644
  98335. --- a/sound/firewire/scs1x.c
  98336. +++ b/sound/firewire/scs1x.c
  98337. @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
  98338. {
  98339. struct scs *scs = stream->rmidi->private_data;
  98340. - ACCESS_ONCE(scs->output) = up ? stream : NULL;
  98341. + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
  98342. if (up) {
  98343. scs->output_idle = false;
  98344. tasklet_schedule(&scs->tasklet);
  98345. @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
  98346. {
  98347. struct scs *scs = stream->rmidi->private_data;
  98348. - ACCESS_ONCE(scs->input) = up ? stream : NULL;
  98349. + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
  98350. }
  98351. static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
  98352. @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
  98353. snd_card_disconnect(scs->card);
  98354. - ACCESS_ONCE(scs->output) = NULL;
  98355. - ACCESS_ONCE(scs->input) = NULL;
  98356. + ACCESS_ONCE_RW(scs->output) = NULL;
  98357. + ACCESS_ONCE_RW(scs->input) = NULL;
  98358. wait_event(scs->idle_wait, scs->output_idle);
  98359. diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
  98360. index 4e3fcfb..ab45a9d 100644
  98361. --- a/sound/isa/sb/emu8000_synth.c
  98362. +++ b/sound/isa/sb/emu8000_synth.c
  98363. @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
  98364. {
  98365. static struct snd_seq_dev_ops ops = {
  98366. - snd_emu8000_new_device,
  98367. - snd_emu8000_delete_device,
  98368. + .init_device = snd_emu8000_new_device,
  98369. + .free_device = snd_emu8000_delete_device,
  98370. };
  98371. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
  98372. sizeof(struct snd_emu8000*));
  98373. diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
  98374. index 048439a..3be9f6f 100644
  98375. --- a/sound/oss/sb_audio.c
  98376. +++ b/sound/oss/sb_audio.c
  98377. @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
  98378. buf16 = (signed short *)(localbuf + localoffs);
  98379. while (c)
  98380. {
  98381. - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
  98382. + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
  98383. if (copy_from_user(lbuf8,
  98384. userbuf+useroffs + p,
  98385. locallen))
  98386. diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
  98387. index f851fd0..92576fb 100644
  98388. --- a/sound/oss/swarm_cs4297a.c
  98389. +++ b/sound/oss/swarm_cs4297a.c
  98390. @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
  98391. {
  98392. struct cs4297a_state *s;
  98393. u32 pwr, id;
  98394. - mm_segment_t fs;
  98395. int rval;
  98396. #ifndef CONFIG_BCM_CS4297A_CSWARM
  98397. u64 cfg;
  98398. @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
  98399. if (!rval) {
  98400. char *sb1250_duart_present;
  98401. +#if 0
  98402. + mm_segment_t fs;
  98403. fs = get_fs();
  98404. set_fs(KERNEL_DS);
  98405. -#if 0
  98406. val = SOUND_MASK_LINE;
  98407. mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
  98408. for (i = 0; i < ARRAY_SIZE(initvol); i++) {
  98409. val = initvol[i].vol;
  98410. mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
  98411. }
  98412. + set_fs(fs);
  98413. // cs4297a_write_ac97(s, 0x18, 0x0808);
  98414. #else
  98415. // cs4297a_write_ac97(s, 0x5e, 0x180);
  98416. cs4297a_write_ac97(s, 0x02, 0x0808);
  98417. cs4297a_write_ac97(s, 0x18, 0x0808);
  98418. #endif
  98419. - set_fs(fs);
  98420. list_add(&s->list, &cs4297a_devs);
  98421. diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
  98422. index 4c41c90..37f3631 100644
  98423. --- a/sound/pci/emu10k1/emu10k1_synth.c
  98424. +++ b/sound/pci/emu10k1/emu10k1_synth.c
  98425. @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
  98426. {
  98427. static struct snd_seq_dev_ops ops = {
  98428. - snd_emu10k1_synth_new_device,
  98429. - snd_emu10k1_synth_delete_device,
  98430. + .init_device = snd_emu10k1_synth_new_device,
  98431. + .free_device = snd_emu10k1_synth_delete_device,
  98432. };
  98433. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
  98434. sizeof(struct snd_emu10k1_synth_arg));
  98435. diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
  98436. index dafcf82..dd9356f 100644
  98437. --- a/sound/pci/hda/hda_codec.c
  98438. +++ b/sound/pci/hda/hda_codec.c
  98439. @@ -983,14 +983,10 @@ find_codec_preset(struct hda_codec *codec)
  98440. mutex_unlock(&preset_mutex);
  98441. if (mod_requested < HDA_MODREQ_MAX_COUNT) {
  98442. - char name[32];
  98443. if (!mod_requested)
  98444. - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
  98445. - codec->vendor_id);
  98446. + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
  98447. else
  98448. - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
  98449. - (codec->vendor_id >> 16) & 0xffff);
  98450. - request_module(name);
  98451. + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
  98452. mod_requested++;
  98453. goto again;
  98454. }
  98455. @@ -2739,7 +2735,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
  98456. /* FIXME: set_fs() hack for obtaining user-space TLV data */
  98457. mm_segment_t fs = get_fs();
  98458. set_fs(get_ds());
  98459. - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
  98460. + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
  98461. tlv = _tlv;
  98462. set_fs(fs);
  98463. } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
  98464. diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
  98465. index 4631a23..001ae57 100644
  98466. --- a/sound/pci/ymfpci/ymfpci.h
  98467. +++ b/sound/pci/ymfpci/ymfpci.h
  98468. @@ -358,7 +358,7 @@ struct snd_ymfpci {
  98469. spinlock_t reg_lock;
  98470. spinlock_t voice_lock;
  98471. wait_queue_head_t interrupt_sleep;
  98472. - atomic_t interrupt_sleep_count;
  98473. + atomic_unchecked_t interrupt_sleep_count;
  98474. struct snd_info_entry *proc_entry;
  98475. const struct firmware *dsp_microcode;
  98476. const struct firmware *controller_microcode;
  98477. diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
  98478. index d591c15..8cb8f94 100644
  98479. --- a/sound/pci/ymfpci/ymfpci_main.c
  98480. +++ b/sound/pci/ymfpci/ymfpci_main.c
  98481. @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
  98482. if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
  98483. break;
  98484. }
  98485. - if (atomic_read(&chip->interrupt_sleep_count)) {
  98486. - atomic_set(&chip->interrupt_sleep_count, 0);
  98487. + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
  98488. + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
  98489. wake_up(&chip->interrupt_sleep);
  98490. }
  98491. __end:
  98492. @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
  98493. continue;
  98494. init_waitqueue_entry(&wait, current);
  98495. add_wait_queue(&chip->interrupt_sleep, &wait);
  98496. - atomic_inc(&chip->interrupt_sleep_count);
  98497. + atomic_inc_unchecked(&chip->interrupt_sleep_count);
  98498. schedule_timeout_uninterruptible(msecs_to_jiffies(50));
  98499. remove_wait_queue(&chip->interrupt_sleep, &wait);
  98500. }
  98501. @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
  98502. snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
  98503. spin_unlock(&chip->reg_lock);
  98504. - if (atomic_read(&chip->interrupt_sleep_count)) {
  98505. - atomic_set(&chip->interrupt_sleep_count, 0);
  98506. + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
  98507. + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
  98508. wake_up(&chip->interrupt_sleep);
  98509. }
  98510. }
  98511. @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
  98512. spin_lock_init(&chip->reg_lock);
  98513. spin_lock_init(&chip->voice_lock);
  98514. init_waitqueue_head(&chip->interrupt_sleep);
  98515. - atomic_set(&chip->interrupt_sleep_count, 0);
  98516. + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
  98517. chip->card = card;
  98518. chip->pci = pci;
  98519. chip->irq = -1;
  98520. diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
  98521. index 5428a1f..474f651 100644
  98522. --- a/sound/soc/fsl/fsl_ssi.c
  98523. +++ b/sound/soc/fsl/fsl_ssi.c
  98524. @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
  98525. {
  98526. struct fsl_ssi_private *ssi_private;
  98527. int ret = 0;
  98528. - struct device_attribute *dev_attr = NULL;
  98529. struct device_node *np = pdev->dev.of_node;
  98530. const struct of_device_id *of_id;
  98531. enum fsl_ssi_type hw_type;
  98532. @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
  98533. &ssi_private->cpu_dai_drv, 1);
  98534. if (ret) {
  98535. dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
  98536. - goto error_dev;
  98537. + goto error_clk;
  98538. }
  98539. ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
  98540. @@ -1562,9 +1561,6 @@ error_pcm:
  98541. error_dbgfs:
  98542. snd_soc_unregister_component(&pdev->dev);
  98543. -error_dev:
  98544. - device_remove_file(&pdev->dev, dev_attr);
  98545. -
  98546. error_clk:
  98547. if (ssi_private->ssi_on_imx) {
  98548. if (!IS_ERR(ssi_private->baudclk))
  98549. diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
  98550. index fe1df50..09d3be6 100644
  98551. --- a/sound/soc/soc-core.c
  98552. +++ b/sound/soc/soc-core.c
  98553. @@ -2254,8 +2254,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
  98554. if (ret)
  98555. return ret;
  98556. - ops->warm_reset = snd_soc_ac97_warm_reset;
  98557. - ops->reset = snd_soc_ac97_reset;
  98558. + pax_open_kernel();
  98559. + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
  98560. + *(void **)&ops->reset = snd_soc_ac97_reset;
  98561. + pax_close_kernel();
  98562. snd_ac97_rst_cfg = cfg;
  98563. return 0;
  98564. diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
  98565. index 7778b8e..3d619fc 100644
  98566. --- a/sound/synth/emux/emux_seq.c
  98567. +++ b/sound/synth/emux/emux_seq.c
  98568. @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
  98569. * MIDI emulation operators
  98570. */
  98571. static struct snd_midi_op emux_ops = {
  98572. - snd_emux_note_on,
  98573. - snd_emux_note_off,
  98574. - snd_emux_key_press,
  98575. - snd_emux_terminate_note,
  98576. - snd_emux_control,
  98577. - snd_emux_nrpn,
  98578. - snd_emux_sysex,
  98579. + .note_on = snd_emux_note_on,
  98580. + .note_off = snd_emux_note_off,
  98581. + .key_press = snd_emux_key_press,
  98582. + .note_terminate = snd_emux_terminate_note,
  98583. + .control = snd_emux_control,
  98584. + .nrpn = snd_emux_nrpn,
  98585. + .sysex = snd_emux_sysex,
  98586. };
  98587. diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
  98588. new file mode 100644
  98589. index 0000000..60e7af2
  98590. --- /dev/null
  98591. +++ b/tools/gcc/.gitignore
  98592. @@ -0,0 +1,2 @@
  98593. +randomize_layout_seed.h
  98594. +randomize_layout_hash.h
  98595. diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
  98596. new file mode 100644
  98597. index 0000000..7b8921f
  98598. --- /dev/null
  98599. +++ b/tools/gcc/Makefile
  98600. @@ -0,0 +1,52 @@
  98601. +#CC := gcc
  98602. +#PLUGIN_SOURCE_FILES := pax_plugin.c
  98603. +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
  98604. +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
  98605. +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
  98606. +
  98607. +ifeq ($(PLUGINCC),$(HOSTCC))
  98608. +HOSTLIBS := hostlibs
  98609. +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
  98610. +export HOST_EXTRACFLAGS
  98611. +else
  98612. +HOSTLIBS := hostcxxlibs
  98613. +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
  98614. +export HOST_EXTRACXXFLAGS
  98615. +endif
  98616. +
  98617. +export GCCPLUGINS_DIR HOSTLIBS
  98618. +
  98619. +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
  98620. +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
  98621. +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
  98622. +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
  98623. +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
  98624. +$(HOSTLIBS)-y += colorize_plugin.so
  98625. +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
  98626. +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
  98627. +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
  98628. +
  98629. +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
  98630. +subdir- += size_overflow_plugin
  98631. +
  98632. +always := $($(HOSTLIBS)-y)
  98633. +
  98634. +constify_plugin-objs := constify_plugin.o
  98635. +stackleak_plugin-objs := stackleak_plugin.o
  98636. +kallocstat_plugin-objs := kallocstat_plugin.o
  98637. +kernexec_plugin-objs := kernexec_plugin.o
  98638. +checker_plugin-objs := checker_plugin.o
  98639. +colorize_plugin-objs := colorize_plugin.o
  98640. +latent_entropy_plugin-objs := latent_entropy_plugin.o
  98641. +structleak_plugin-objs := structleak_plugin.o
  98642. +randomize_layout_plugin-objs := randomize_layout_plugin.o
  98643. +
  98644. +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
  98645. +
  98646. +quiet_cmd_create_randomize_layout_seed = GENSEED $@
  98647. + cmd_create_randomize_layout_seed = \
  98648. + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
  98649. +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
  98650. + $(call if_changed,create_randomize_layout_seed)
  98651. +
  98652. +targets += randomize_layout_seed.h randomize_layout_hash.h
  98653. diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
  98654. new file mode 100644
  98655. index 0000000..5452feea
  98656. --- /dev/null
  98657. +++ b/tools/gcc/checker_plugin.c
  98658. @@ -0,0 +1,150 @@
  98659. +/*
  98660. + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
  98661. + * Licensed under the GPL v2
  98662. + *
  98663. + * Note: the choice of the license means that the compilation process is
  98664. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  98665. + * but for the kernel it doesn't matter since it doesn't link against
  98666. + * any of the gcc libraries
  98667. + *
  98668. + * gcc plugin to implement various sparse (source code checker) features
  98669. + *
  98670. + * TODO:
  98671. + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
  98672. + *
  98673. + * BUGS:
  98674. + * - none known
  98675. + */
  98676. +
  98677. +#include "gcc-common.h"
  98678. +
  98679. +extern void c_register_addr_space (const char *str, addr_space_t as);
  98680. +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
  98681. +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
  98682. +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
  98683. +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
  98684. +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
  98685. +
  98686. +int plugin_is_GPL_compatible;
  98687. +
  98688. +static struct plugin_info checker_plugin_info = {
  98689. + .version = "201304082245",
  98690. + .help = NULL,
  98691. +};
  98692. +
  98693. +#define ADDR_SPACE_KERNEL 0
  98694. +#define ADDR_SPACE_FORCE_KERNEL 1
  98695. +#define ADDR_SPACE_USER 2
  98696. +#define ADDR_SPACE_FORCE_USER 3
  98697. +#define ADDR_SPACE_IOMEM 0
  98698. +#define ADDR_SPACE_FORCE_IOMEM 0
  98699. +#define ADDR_SPACE_PERCPU 0
  98700. +#define ADDR_SPACE_FORCE_PERCPU 0
  98701. +#define ADDR_SPACE_RCU 0
  98702. +#define ADDR_SPACE_FORCE_RCU 0
  98703. +
  98704. +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
  98705. +{
  98706. + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
  98707. +}
  98708. +
  98709. +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
  98710. +{
  98711. + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
  98712. +}
  98713. +
  98714. +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
  98715. +{
  98716. + return default_addr_space_valid_pointer_mode(mode, as);
  98717. +}
  98718. +
  98719. +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
  98720. +{
  98721. + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
  98722. +}
  98723. +
  98724. +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
  98725. +{
  98726. + return default_addr_space_legitimize_address(x, oldx, mode, as);
  98727. +}
  98728. +
  98729. +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
  98730. +{
  98731. + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
  98732. + return true;
  98733. +
  98734. + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
  98735. + return true;
  98736. +
  98737. + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
  98738. + return true;
  98739. +
  98740. + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
  98741. + return true;
  98742. +
  98743. + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
  98744. + return true;
  98745. +
  98746. + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
  98747. + return true;
  98748. +
  98749. + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
  98750. + return true;
  98751. +
  98752. + return subset == superset;
  98753. +}
  98754. +
  98755. +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
  98756. +{
  98757. +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
  98758. +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
  98759. +
  98760. + return op;
  98761. +}
  98762. +
  98763. +static void register_checker_address_spaces(void *event_data, void *data)
  98764. +{
  98765. + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
  98766. + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
  98767. + c_register_addr_space("__user", ADDR_SPACE_USER);
  98768. + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
  98769. +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
  98770. +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
  98771. +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
  98772. +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
  98773. +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
  98774. +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
  98775. +
  98776. + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
  98777. + targetm.addr_space.address_mode = checker_addr_space_address_mode;
  98778. + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
  98779. + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
  98780. +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
  98781. + targetm.addr_space.subset_p = checker_addr_space_subset_p;
  98782. + targetm.addr_space.convert = checker_addr_space_convert;
  98783. +}
  98784. +
  98785. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  98786. +{
  98787. + const char * const plugin_name = plugin_info->base_name;
  98788. + const int argc = plugin_info->argc;
  98789. + const struct plugin_argument * const argv = plugin_info->argv;
  98790. + int i;
  98791. +
  98792. + if (!plugin_default_version_check(version, &gcc_version)) {
  98793. + error(G_("incompatible gcc/plugin versions"));
  98794. + return 1;
  98795. + }
  98796. +
  98797. + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
  98798. +
  98799. + for (i = 0; i < argc; ++i)
  98800. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  98801. +
  98802. + if (TARGET_64BIT == 0)
  98803. + return 0;
  98804. +
  98805. + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
  98806. +
  98807. + return 0;
  98808. +}
  98809. diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
  98810. new file mode 100644
  98811. index 0000000..54461af
  98812. --- /dev/null
  98813. +++ b/tools/gcc/colorize_plugin.c
  98814. @@ -0,0 +1,210 @@
  98815. +/*
  98816. + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
  98817. + * Licensed under the GPL v2
  98818. + *
  98819. + * Note: the choice of the license means that the compilation process is
  98820. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  98821. + * but for the kernel it doesn't matter since it doesn't link against
  98822. + * any of the gcc libraries
  98823. + *
  98824. + * gcc plugin to colorize diagnostic output
  98825. + *
  98826. + */
  98827. +
  98828. +#include "gcc-common.h"
  98829. +
  98830. +int plugin_is_GPL_compatible;
  98831. +
  98832. +static struct plugin_info colorize_plugin_info = {
  98833. + .version = "201404202350",
  98834. + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
  98835. +};
  98836. +
  98837. +#define GREEN "\033[32m\033[K"
  98838. +#define LIGHTGREEN "\033[1;32m\033[K"
  98839. +#define YELLOW "\033[33m\033[K"
  98840. +#define LIGHTYELLOW "\033[1;33m\033[K"
  98841. +#define RED "\033[31m\033[K"
  98842. +#define LIGHTRED "\033[1;31m\033[K"
  98843. +#define BLUE "\033[34m\033[K"
  98844. +#define LIGHTBLUE "\033[1;34m\033[K"
  98845. +#define BRIGHT "\033[1;m\033[K"
  98846. +#define NORMAL "\033[m\033[K"
  98847. +
  98848. +static diagnostic_starter_fn old_starter;
  98849. +static diagnostic_finalizer_fn old_finalizer;
  98850. +
  98851. +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
  98852. +{
  98853. + const char *color;
  98854. + char *newprefix;
  98855. +
  98856. + switch (diagnostic->kind) {
  98857. + case DK_NOTE:
  98858. + color = LIGHTBLUE;
  98859. + break;
  98860. +
  98861. + case DK_PEDWARN:
  98862. + case DK_WARNING:
  98863. + color = LIGHTYELLOW;
  98864. + break;
  98865. +
  98866. + case DK_ERROR:
  98867. + case DK_FATAL:
  98868. + case DK_ICE:
  98869. + case DK_PERMERROR:
  98870. + case DK_SORRY:
  98871. + color = LIGHTRED;
  98872. + break;
  98873. +
  98874. + default:
  98875. + color = NORMAL;
  98876. + }
  98877. +
  98878. + old_starter(context, diagnostic);
  98879. + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
  98880. + return;
  98881. + pp_destroy_prefix(context->printer);
  98882. + pp_set_prefix(context->printer, newprefix);
  98883. +}
  98884. +
  98885. +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
  98886. +{
  98887. + old_finalizer(context, diagnostic);
  98888. +}
  98889. +
  98890. +static void colorize_arm(void)
  98891. +{
  98892. + old_starter = diagnostic_starter(global_dc);
  98893. + old_finalizer = diagnostic_finalizer(global_dc);
  98894. +
  98895. + diagnostic_starter(global_dc) = start_colorize;
  98896. + diagnostic_finalizer(global_dc) = finalize_colorize;
  98897. +}
  98898. +
  98899. +static unsigned int execute_colorize_rearm(void)
  98900. +{
  98901. + if (diagnostic_starter(global_dc) == start_colorize)
  98902. + return 0;
  98903. +
  98904. + colorize_arm();
  98905. + return 0;
  98906. +}
  98907. +
  98908. +#if BUILDING_GCC_VERSION >= 4009
  98909. +static const struct pass_data colorize_rearm_pass_data = {
  98910. +#else
  98911. +struct simple_ipa_opt_pass colorize_rearm_pass = {
  98912. + .pass = {
  98913. +#endif
  98914. + .type = SIMPLE_IPA_PASS,
  98915. + .name = "colorize_rearm",
  98916. +#if BUILDING_GCC_VERSION >= 4008
  98917. + .optinfo_flags = OPTGROUP_NONE,
  98918. +#endif
  98919. +#if BUILDING_GCC_VERSION >= 4009
  98920. + .has_gate = false,
  98921. + .has_execute = true,
  98922. +#else
  98923. + .gate = NULL,
  98924. + .execute = execute_colorize_rearm,
  98925. + .sub = NULL,
  98926. + .next = NULL,
  98927. + .static_pass_number = 0,
  98928. +#endif
  98929. + .tv_id = TV_NONE,
  98930. + .properties_required = 0,
  98931. + .properties_provided = 0,
  98932. + .properties_destroyed = 0,
  98933. + .todo_flags_start = 0,
  98934. + .todo_flags_finish = 0
  98935. +#if BUILDING_GCC_VERSION < 4009
  98936. + }
  98937. +#endif
  98938. +};
  98939. +
  98940. +#if BUILDING_GCC_VERSION >= 4009
  98941. +namespace {
  98942. +class colorize_rearm_pass : public simple_ipa_opt_pass {
  98943. +public:
  98944. + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
  98945. + unsigned int execute() { return execute_colorize_rearm(); }
  98946. +};
  98947. +}
  98948. +
  98949. +static opt_pass *make_colorize_rearm_pass(void)
  98950. +{
  98951. + return new colorize_rearm_pass();
  98952. +}
  98953. +#else
  98954. +static struct opt_pass *make_colorize_rearm_pass(void)
  98955. +{
  98956. + return &colorize_rearm_pass.pass;
  98957. +}
  98958. +#endif
  98959. +
  98960. +static void colorize_start_unit(void *gcc_data, void *user_data)
  98961. +{
  98962. + colorize_arm();
  98963. +}
  98964. +
  98965. +static bool should_colorize(void)
  98966. +{
  98967. +#if BUILDING_GCC_VERSION >= 4009
  98968. + return false;
  98969. +#else
  98970. + char const *t = getenv("TERM");
  98971. +
  98972. + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
  98973. +#endif
  98974. +}
  98975. +
  98976. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  98977. +{
  98978. + const char * const plugin_name = plugin_info->base_name;
  98979. + const int argc = plugin_info->argc;
  98980. + const struct plugin_argument * const argv = plugin_info->argv;
  98981. + int i;
  98982. + struct register_pass_info colorize_rearm_pass_info;
  98983. + bool colorize;
  98984. +
  98985. + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
  98986. + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
  98987. + colorize_rearm_pass_info.ref_pass_instance_number = 1;
  98988. + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  98989. +
  98990. + if (!plugin_default_version_check(version, &gcc_version)) {
  98991. + error(G_("incompatible gcc/plugin versions"));
  98992. + return 1;
  98993. + }
  98994. +
  98995. + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
  98996. +
  98997. + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
  98998. +
  98999. + for (i = 0; i < argc; ++i) {
  99000. + if (!strcmp(argv[i].key, "color")) {
  99001. + if (!argv[i].value) {
  99002. + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  99003. + continue;
  99004. + }
  99005. + if (!strcmp(argv[i].value, "always"))
  99006. + colorize = true;
  99007. + else if (!strcmp(argv[i].value, "never"))
  99008. + colorize = false;
  99009. + else if (!strcmp(argv[i].value, "auto"))
  99010. + colorize = should_colorize();
  99011. + else
  99012. + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
  99013. + continue;
  99014. + }
  99015. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  99016. + }
  99017. +
  99018. + if (colorize) {
  99019. + // TODO: parse GCC_COLORS as used by gcc 4.9+
  99020. + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
  99021. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
  99022. + }
  99023. + return 0;
  99024. +}
  99025. diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
  99026. new file mode 100644
  99027. index 0000000..82bc5a8
  99028. --- /dev/null
  99029. +++ b/tools/gcc/constify_plugin.c
  99030. @@ -0,0 +1,557 @@
  99031. +/*
  99032. + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
  99033. + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
  99034. + * Licensed under the GPL v2, or (at your option) v3
  99035. + *
  99036. + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
  99037. + *
  99038. + * Homepage:
  99039. + * http://www.grsecurity.net/~ephox/const_plugin/
  99040. + *
  99041. + * Usage:
  99042. + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
  99043. + * $ gcc -fplugin=constify_plugin.so test.c -O2
  99044. + */
  99045. +
  99046. +#include "gcc-common.h"
  99047. +
  99048. +// unused C type flag in all versions 4.5-4.9
  99049. +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
  99050. +
  99051. +int plugin_is_GPL_compatible;
  99052. +
  99053. +static struct plugin_info const_plugin_info = {
  99054. + .version = "201401270210",
  99055. + .help = "no-constify\tturn off constification\n",
  99056. +};
  99057. +
  99058. +typedef struct {
  99059. + bool has_fptr_field;
  99060. + bool has_writable_field;
  99061. + bool has_do_const_field;
  99062. + bool has_no_const_field;
  99063. +} constify_info;
  99064. +
  99065. +static const_tree get_field_type(const_tree field)
  99066. +{
  99067. + return strip_array_types(TREE_TYPE(field));
  99068. +}
  99069. +
  99070. +static bool is_fptr(const_tree field)
  99071. +{
  99072. + const_tree ptr = get_field_type(field);
  99073. +
  99074. + if (TREE_CODE(ptr) != POINTER_TYPE)
  99075. + return false;
  99076. +
  99077. + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
  99078. +}
  99079. +
  99080. +/*
  99081. + * determine whether the given structure type meets the requirements for automatic constification,
  99082. + * including the constification attributes on nested structure types
  99083. + */
  99084. +static void constifiable(const_tree node, constify_info *cinfo)
  99085. +{
  99086. + const_tree field;
  99087. +
  99088. + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
  99089. +
  99090. + // e.g., pointer to structure fields while still constructing the structure type
  99091. + if (TYPE_FIELDS(node) == NULL_TREE)
  99092. + return;
  99093. +
  99094. + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
  99095. + const_tree type = get_field_type(field);
  99096. + enum tree_code code = TREE_CODE(type);
  99097. +
  99098. + if (node == type)
  99099. + continue;
  99100. +
  99101. + if (is_fptr(field))
  99102. + cinfo->has_fptr_field = true;
  99103. + else if (!TREE_READONLY(field))
  99104. + cinfo->has_writable_field = true;
  99105. +
  99106. + if (code == RECORD_TYPE || code == UNION_TYPE) {
  99107. + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
  99108. + cinfo->has_do_const_field = true;
  99109. + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
  99110. + cinfo->has_no_const_field = true;
  99111. + else
  99112. + constifiable(type, cinfo);
  99113. + }
  99114. + }
  99115. +}
  99116. +
  99117. +static bool constified(const_tree node)
  99118. +{
  99119. + constify_info cinfo = {
  99120. + .has_fptr_field = false,
  99121. + .has_writable_field = false,
  99122. + .has_do_const_field = false,
  99123. + .has_no_const_field = false
  99124. + };
  99125. +
  99126. + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
  99127. +
  99128. + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
  99129. +// gcc_assert(!TYPE_READONLY(node));
  99130. + return false;
  99131. + }
  99132. +
  99133. + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
  99134. + gcc_assert(TYPE_READONLY(node));
  99135. + return true;
  99136. + }
  99137. +
  99138. + constifiable(node, &cinfo);
  99139. + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
  99140. + return false;
  99141. +
  99142. + return TYPE_READONLY(node);
  99143. +}
  99144. +
  99145. +static void deconstify_tree(tree node);
  99146. +
  99147. +static void deconstify_type(tree type)
  99148. +{
  99149. + tree field;
  99150. +
  99151. + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
  99152. +
  99153. + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
  99154. + const_tree fieldtype = get_field_type(field);
  99155. +
  99156. + // special case handling of simple ptr-to-same-array-type members
  99157. + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
  99158. + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
  99159. +
  99160. + if (TREE_TYPE(TREE_TYPE(field)) == type)
  99161. + continue;
  99162. + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
  99163. + continue;
  99164. + if (!constified(ptrtype))
  99165. + continue;
  99166. + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
  99167. + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
  99168. + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
  99169. + }
  99170. + continue;
  99171. + }
  99172. + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
  99173. + continue;
  99174. + if (!constified(fieldtype))
  99175. + continue;
  99176. +
  99177. + deconstify_tree(field);
  99178. + TREE_READONLY(field) = 0;
  99179. + }
  99180. + TYPE_READONLY(type) = 0;
  99181. + C_TYPE_FIELDS_READONLY(type) = 0;
  99182. + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
  99183. + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
  99184. + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
  99185. + }
  99186. +}
  99187. +
  99188. +static void deconstify_tree(tree node)
  99189. +{
  99190. + tree old_type, new_type, field;
  99191. +
  99192. + old_type = TREE_TYPE(node);
  99193. + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
  99194. + node = TREE_TYPE(node) = copy_node(old_type);
  99195. + old_type = TREE_TYPE(old_type);
  99196. + }
  99197. +
  99198. + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
  99199. + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
  99200. +
  99201. + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
  99202. + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
  99203. + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
  99204. + DECL_FIELD_CONTEXT(field) = new_type;
  99205. +
  99206. + deconstify_type(new_type);
  99207. +
  99208. + TREE_TYPE(node) = new_type;
  99209. +}
  99210. +
  99211. +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  99212. +{
  99213. + tree type;
  99214. + constify_info cinfo = {
  99215. + .has_fptr_field = false,
  99216. + .has_writable_field = false,
  99217. + .has_do_const_field = false,
  99218. + .has_no_const_field = false
  99219. + };
  99220. +
  99221. + *no_add_attrs = true;
  99222. + if (TREE_CODE(*node) == FUNCTION_DECL) {
  99223. + error("%qE attribute does not apply to functions (%qF)", name, *node);
  99224. + return NULL_TREE;
  99225. + }
  99226. +
  99227. + if (TREE_CODE(*node) == PARM_DECL) {
  99228. + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
  99229. + return NULL_TREE;
  99230. + }
  99231. +
  99232. + if (TREE_CODE(*node) == VAR_DECL) {
  99233. + error("%qE attribute does not apply to variables (%qD)", name, *node);
  99234. + return NULL_TREE;
  99235. + }
  99236. +
  99237. + if (TYPE_P(*node)) {
  99238. + type = *node;
  99239. + } else {
  99240. + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
  99241. + type = TREE_TYPE(*node);
  99242. + }
  99243. +
  99244. + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
  99245. + error("%qE attribute used on %qT applies to struct and union types only", name, type);
  99246. + return NULL_TREE;
  99247. + }
  99248. +
  99249. + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
  99250. + error("%qE attribute is already applied to the type %qT", name, type);
  99251. + return NULL_TREE;
  99252. + }
  99253. +
  99254. + if (TYPE_P(*node)) {
  99255. + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
  99256. + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
  99257. + else
  99258. + *no_add_attrs = false;
  99259. + return NULL_TREE;
  99260. + }
  99261. +
  99262. + constifiable(type, &cinfo);
  99263. + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
  99264. + deconstify_tree(*node);
  99265. + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
  99266. + return NULL_TREE;
  99267. + }
  99268. +
  99269. + error("%qE attribute used on type %qT that is not constified", name, type);
  99270. + return NULL_TREE;
  99271. +}
  99272. +
  99273. +static void constify_type(tree type)
  99274. +{
  99275. + TYPE_READONLY(type) = 1;
  99276. + C_TYPE_FIELDS_READONLY(type) = 1;
  99277. + TYPE_CONSTIFY_VISITED(type) = 1;
  99278. +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
  99279. +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
  99280. +}
  99281. +
  99282. +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  99283. +{
  99284. + *no_add_attrs = true;
  99285. + if (!TYPE_P(*node)) {
  99286. + error("%qE attribute applies to types only (%qD)", name, *node);
  99287. + return NULL_TREE;
  99288. + }
  99289. +
  99290. + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
  99291. + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
  99292. + return NULL_TREE;
  99293. + }
  99294. +
  99295. + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
  99296. + error("%qE attribute used on %qT is already applied to the type", name, *node);
  99297. + return NULL_TREE;
  99298. + }
  99299. +
  99300. + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
  99301. + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
  99302. + return NULL_TREE;
  99303. + }
  99304. +
  99305. + *no_add_attrs = false;
  99306. + return NULL_TREE;
  99307. +}
  99308. +
  99309. +static struct attribute_spec no_const_attr = {
  99310. + .name = "no_const",
  99311. + .min_length = 0,
  99312. + .max_length = 0,
  99313. + .decl_required = false,
  99314. + .type_required = false,
  99315. + .function_type_required = false,
  99316. + .handler = handle_no_const_attribute,
  99317. +#if BUILDING_GCC_VERSION >= 4007
  99318. + .affects_type_identity = true
  99319. +#endif
  99320. +};
  99321. +
  99322. +static struct attribute_spec do_const_attr = {
  99323. + .name = "do_const",
  99324. + .min_length = 0,
  99325. + .max_length = 0,
  99326. + .decl_required = false,
  99327. + .type_required = false,
  99328. + .function_type_required = false,
  99329. + .handler = handle_do_const_attribute,
  99330. +#if BUILDING_GCC_VERSION >= 4007
  99331. + .affects_type_identity = true
  99332. +#endif
  99333. +};
  99334. +
  99335. +static void register_attributes(void *event_data, void *data)
  99336. +{
  99337. + register_attribute(&no_const_attr);
  99338. + register_attribute(&do_const_attr);
  99339. +}
  99340. +
  99341. +static void finish_type(void *event_data, void *data)
  99342. +{
  99343. + tree type = (tree)event_data;
  99344. + constify_info cinfo = {
  99345. + .has_fptr_field = false,
  99346. + .has_writable_field = false,
  99347. + .has_do_const_field = false,
  99348. + .has_no_const_field = false
  99349. + };
  99350. +
  99351. + if (type == NULL_TREE || type == error_mark_node)
  99352. + return;
  99353. +
  99354. + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
  99355. + return;
  99356. +
  99357. + constifiable(type, &cinfo);
  99358. +
  99359. + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
  99360. + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
  99361. + deconstify_type(type);
  99362. + TYPE_CONSTIFY_VISITED(type) = 1;
  99363. + } else
  99364. + error("'no_const' attribute used on type %qT that is not constified", type);
  99365. + return;
  99366. + }
  99367. +
  99368. + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
  99369. + if (!cinfo.has_writable_field) {
  99370. + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
  99371. + return;
  99372. + }
  99373. + constify_type(type);
  99374. + return;
  99375. + }
  99376. +
  99377. + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
  99378. + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
  99379. + error("'do_const' attribute used on type %qT that is constified", type);
  99380. + return;
  99381. + }
  99382. + constify_type(type);
  99383. + return;
  99384. + }
  99385. +
  99386. + deconstify_type(type);
  99387. + TYPE_CONSTIFY_VISITED(type) = 1;
  99388. +}
  99389. +
  99390. +static void check_global_variables(void *event_data, void *data)
  99391. +{
  99392. +#if BUILDING_GCC_VERSION >= 4009
  99393. + varpool_node *node;
  99394. +#else
  99395. + struct varpool_node *node;
  99396. +#endif
  99397. +
  99398. + FOR_EACH_VARIABLE(node) {
  99399. + tree var = NODE_DECL(node);
  99400. + tree type = TREE_TYPE(var);
  99401. +
  99402. + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
  99403. + continue;
  99404. +
  99405. + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
  99406. + continue;
  99407. +
  99408. + if (!TYPE_CONSTIFY_VISITED(type))
  99409. + continue;
  99410. +
  99411. + if (DECL_EXTERNAL(var))
  99412. + continue;
  99413. +
  99414. + if (DECL_INITIAL(var))
  99415. + continue;
  99416. +
  99417. + // this works around a gcc bug/feature where uninitialized globals
  99418. + // are moved into the .bss section regardless of any constification
  99419. + DECL_INITIAL(var) = build_constructor(type, NULL);
  99420. +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
  99421. + }
  99422. +}
  99423. +
  99424. +static unsigned int check_local_variables(void)
  99425. +{
  99426. + unsigned int ret = 0;
  99427. + tree var;
  99428. +
  99429. + unsigned int i;
  99430. +
  99431. + FOR_EACH_LOCAL_DECL(cfun, i, var) {
  99432. + tree type = TREE_TYPE(var);
  99433. +
  99434. + gcc_assert(DECL_P(var));
  99435. + if (is_global_var(var))
  99436. + continue;
  99437. +
  99438. + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
  99439. + continue;
  99440. +
  99441. + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
  99442. + continue;
  99443. +
  99444. + if (!TYPE_CONSTIFY_VISITED(type))
  99445. + continue;
  99446. +
  99447. + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
  99448. + ret = 1;
  99449. + }
  99450. + return ret;
  99451. +}
  99452. +
  99453. +#if BUILDING_GCC_VERSION >= 4009
  99454. +static const struct pass_data check_local_variables_pass_data = {
  99455. +#else
  99456. +static struct gimple_opt_pass check_local_variables_pass = {
  99457. + .pass = {
  99458. +#endif
  99459. + .type = GIMPLE_PASS,
  99460. + .name = "check_local_variables",
  99461. +#if BUILDING_GCC_VERSION >= 4008
  99462. + .optinfo_flags = OPTGROUP_NONE,
  99463. +#endif
  99464. +#if BUILDING_GCC_VERSION >= 4009
  99465. + .has_gate = false,
  99466. + .has_execute = true,
  99467. +#else
  99468. + .gate = NULL,
  99469. + .execute = check_local_variables,
  99470. + .sub = NULL,
  99471. + .next = NULL,
  99472. + .static_pass_number = 0,
  99473. +#endif
  99474. + .tv_id = TV_NONE,
  99475. + .properties_required = 0,
  99476. + .properties_provided = 0,
  99477. + .properties_destroyed = 0,
  99478. + .todo_flags_start = 0,
  99479. + .todo_flags_finish = 0
  99480. +#if BUILDING_GCC_VERSION < 4009
  99481. + }
  99482. +#endif
  99483. +};
  99484. +
  99485. +#if BUILDING_GCC_VERSION >= 4009
  99486. +namespace {
  99487. +class check_local_variables_pass : public gimple_opt_pass {
  99488. +public:
  99489. + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
  99490. + unsigned int execute() { return check_local_variables(); }
  99491. +};
  99492. +}
  99493. +
  99494. +static opt_pass *make_check_local_variables_pass(void)
  99495. +{
  99496. + return new check_local_variables_pass();
  99497. +}
  99498. +#else
  99499. +static struct opt_pass *make_check_local_variables_pass(void)
  99500. +{
  99501. + return &check_local_variables_pass.pass;
  99502. +}
  99503. +#endif
  99504. +
  99505. +static struct {
  99506. + const char *name;
  99507. + const char *asm_op;
  99508. +} sections[] = {
  99509. + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
  99510. + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
  99511. + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
  99512. + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
  99513. + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
  99514. + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
  99515. + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
  99516. + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
  99517. + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
  99518. +};
  99519. +
  99520. +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
  99521. +
  99522. +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
  99523. +{
  99524. + size_t i;
  99525. +
  99526. + for (i = 0; i < ARRAY_SIZE(sections); i++)
  99527. + if (!strcmp(sections[i].name, name))
  99528. + return 0;
  99529. + return old_section_type_flags(decl, name, reloc);
  99530. +}
  99531. +
  99532. +static void constify_start_unit(void *gcc_data, void *user_data)
  99533. +{
  99534. +// size_t i;
  99535. +
  99536. +// for (i = 0; i < ARRAY_SIZE(sections); i++)
  99537. +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
  99538. +// sections[i].section = get_section(sections[i].name, 0, NULL);
  99539. +
  99540. + old_section_type_flags = targetm.section_type_flags;
  99541. + targetm.section_type_flags = constify_section_type_flags;
  99542. +}
  99543. +
  99544. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  99545. +{
  99546. + const char * const plugin_name = plugin_info->base_name;
  99547. + const int argc = plugin_info->argc;
  99548. + const struct plugin_argument * const argv = plugin_info->argv;
  99549. + int i;
  99550. + bool constify = true;
  99551. +
  99552. + struct register_pass_info check_local_variables_pass_info;
  99553. +
  99554. + check_local_variables_pass_info.pass = make_check_local_variables_pass();
  99555. + check_local_variables_pass_info.reference_pass_name = "ssa";
  99556. + check_local_variables_pass_info.ref_pass_instance_number = 1;
  99557. + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
  99558. +
  99559. + if (!plugin_default_version_check(version, &gcc_version)) {
  99560. + error(G_("incompatible gcc/plugin versions"));
  99561. + return 1;
  99562. + }
  99563. +
  99564. + for (i = 0; i < argc; ++i) {
  99565. + if (!(strcmp(argv[i].key, "no-constify"))) {
  99566. + constify = false;
  99567. + continue;
  99568. + }
  99569. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  99570. + }
  99571. +
  99572. + if (strcmp(lang_hooks.name, "GNU C")) {
  99573. + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
  99574. + constify = false;
  99575. + }
  99576. +
  99577. + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
  99578. + if (constify) {
  99579. + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
  99580. + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
  99581. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
  99582. + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
  99583. + }
  99584. + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
  99585. +
  99586. + return 0;
  99587. +}
  99588. diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
  99589. new file mode 100644
  99590. index 0000000..8af3693
  99591. --- /dev/null
  99592. +++ b/tools/gcc/gcc-common.h
  99593. @@ -0,0 +1,287 @@
  99594. +#ifndef GCC_COMMON_H_INCLUDED
  99595. +#define GCC_COMMON_H_INCLUDED
  99596. +
  99597. +#include "plugin.h"
  99598. +#include "bversion.h"
  99599. +#include "plugin-version.h"
  99600. +#include "config.h"
  99601. +#include "system.h"
  99602. +#include "coretypes.h"
  99603. +#include "tm.h"
  99604. +#include "line-map.h"
  99605. +#include "input.h"
  99606. +#include "tree.h"
  99607. +
  99608. +#include "tree-inline.h"
  99609. +#include "version.h"
  99610. +#include "rtl.h"
  99611. +#include "tm_p.h"
  99612. +#include "flags.h"
  99613. +//#include "insn-attr.h"
  99614. +//#include "insn-config.h"
  99615. +//#include "insn-flags.h"
  99616. +#include "hard-reg-set.h"
  99617. +//#include "recog.h"
  99618. +#include "output.h"
  99619. +#include "except.h"
  99620. +#include "function.h"
  99621. +#include "toplev.h"
  99622. +//#include "expr.h"
  99623. +#include "basic-block.h"
  99624. +#include "intl.h"
  99625. +#include "ggc.h"
  99626. +//#include "regs.h"
  99627. +#include "timevar.h"
  99628. +
  99629. +#include "params.h"
  99630. +#include "pointer-set.h"
  99631. +#include "emit-rtl.h"
  99632. +//#include "reload.h"
  99633. +//#include "ira.h"
  99634. +//#include "dwarf2asm.h"
  99635. +#include "debug.h"
  99636. +#include "target.h"
  99637. +#include "langhooks.h"
  99638. +#include "cfgloop.h"
  99639. +//#include "hosthooks.h"
  99640. +#include "cgraph.h"
  99641. +#include "opts.h"
  99642. +//#include "coverage.h"
  99643. +//#include "value-prof.h"
  99644. +
  99645. +#if BUILDING_GCC_VERSION >= 4007
  99646. +#include "tree-pretty-print.h"
  99647. +#include "gimple-pretty-print.h"
  99648. +#include "c-tree.h"
  99649. +//#include "alloc-pool.h"
  99650. +#endif
  99651. +
  99652. +#if BUILDING_GCC_VERSION <= 4008
  99653. +#include "tree-flow.h"
  99654. +#else
  99655. +#include "tree-cfgcleanup.h"
  99656. +#endif
  99657. +
  99658. +#include "diagnostic.h"
  99659. +//#include "tree-diagnostic.h"
  99660. +#include "tree-dump.h"
  99661. +#include "tree-pass.h"
  99662. +//#include "df.h"
  99663. +#include "predict.h"
  99664. +//#include "lto-streamer.h"
  99665. +#include "ipa-utils.h"
  99666. +
  99667. +#if BUILDING_GCC_VERSION >= 4009
  99668. +#include "varasm.h"
  99669. +#include "stor-layout.h"
  99670. +#include "internal-fn.h"
  99671. +#include "gimple-expr.h"
  99672. +//#include "diagnostic-color.h"
  99673. +#include "context.h"
  99674. +#include "tree-ssa-alias.h"
  99675. +#include "stringpool.h"
  99676. +#include "tree-ssanames.h"
  99677. +#include "print-tree.h"
  99678. +#include "tree-eh.h"
  99679. +#endif
  99680. +
  99681. +#include "gimple.h"
  99682. +
  99683. +#if BUILDING_GCC_VERSION >= 4009
  99684. +#include "tree-ssa-operands.h"
  99685. +#include "tree-phinodes.h"
  99686. +#include "tree-cfg.h"
  99687. +#include "gimple-iterator.h"
  99688. +#include "gimple-ssa.h"
  99689. +#include "ssa-iterators.h"
  99690. +#endif
  99691. +
  99692. +//#include "expr.h" where are you...
  99693. +extern rtx emit_move_insn(rtx x, rtx y);
  99694. +
  99695. +// missing from basic_block.h...
  99696. +extern void debug_dominance_info(enum cdi_direction dir);
  99697. +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
  99698. +
  99699. +#define __unused __attribute__((__unused__))
  99700. +
  99701. +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
  99702. +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
  99703. +
  99704. +#if BUILDING_GCC_VERSION == 4005
  99705. +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
  99706. +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
  99707. +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
  99708. +#define TODO_rebuild_cgraph_edges 0
  99709. +
  99710. +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
  99711. +{
  99712. + tree fndecl;
  99713. +
  99714. + if (!is_gimple_call(stmt))
  99715. + return false;
  99716. + fndecl = gimple_call_fndecl(stmt);
  99717. + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
  99718. + return false;
  99719. +// print_node(stderr, "pax", fndecl, 4);
  99720. + return DECL_FUNCTION_CODE(fndecl) == code;
  99721. +}
  99722. +
  99723. +static inline bool is_simple_builtin(tree decl)
  99724. +{
  99725. + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
  99726. + return false;
  99727. +
  99728. + switch (DECL_FUNCTION_CODE(decl)) {
  99729. + /* Builtins that expand to constants. */
  99730. + case BUILT_IN_CONSTANT_P:
  99731. + case BUILT_IN_EXPECT:
  99732. + case BUILT_IN_OBJECT_SIZE:
  99733. + case BUILT_IN_UNREACHABLE:
  99734. + /* Simple register moves or loads from stack. */
  99735. + case BUILT_IN_RETURN_ADDRESS:
  99736. + case BUILT_IN_EXTRACT_RETURN_ADDR:
  99737. + case BUILT_IN_FROB_RETURN_ADDR:
  99738. + case BUILT_IN_RETURN:
  99739. + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
  99740. + case BUILT_IN_FRAME_ADDRESS:
  99741. + case BUILT_IN_VA_END:
  99742. + case BUILT_IN_STACK_SAVE:
  99743. + case BUILT_IN_STACK_RESTORE:
  99744. + /* Exception state returns or moves registers around. */
  99745. + case BUILT_IN_EH_FILTER:
  99746. + case BUILT_IN_EH_POINTER:
  99747. + case BUILT_IN_EH_COPY_VALUES:
  99748. + return true;
  99749. +
  99750. + default:
  99751. + return false;
  99752. + }
  99753. +}
  99754. +#endif
  99755. +
  99756. +#if BUILDING_GCC_VERSION <= 4006
  99757. +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
  99758. +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
  99759. +
  99760. +// should come from c-tree.h if only it were installed for gcc 4.5...
  99761. +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
  99762. +
  99763. +#define get_random_seed(noinit) ({ \
  99764. + unsigned HOST_WIDE_INT seed; \
  99765. + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
  99766. + seed * seed; })
  99767. +
  99768. +static inline bool gimple_clobber_p(gimple s)
  99769. +{
  99770. + return false;
  99771. +}
  99772. +
  99773. +static inline tree builtin_decl_implicit(enum built_in_function fncode)
  99774. +{
  99775. + return implicit_built_in_decls[fncode];
  99776. +}
  99777. +
  99778. +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
  99779. +{
  99780. + struct cgraph_node *node = cgraph_get_node(decl);
  99781. +
  99782. + return node ? node : cgraph_node(decl);
  99783. +}
  99784. +
  99785. +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
  99786. +{
  99787. + return node->analyzed && !node->thunk.thunk_p && !node->alias;
  99788. +}
  99789. +
  99790. +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
  99791. +{
  99792. + struct cgraph_node *node;
  99793. +
  99794. + for (node = cgraph_nodes; node; node = node->next)
  99795. + if (cgraph_function_with_gimple_body_p(node))
  99796. + return node;
  99797. + return NULL;
  99798. +}
  99799. +
  99800. +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
  99801. +{
  99802. + for (node = node->next; node; node = node->next)
  99803. + if (cgraph_function_with_gimple_body_p(node))
  99804. + return node;
  99805. + return NULL;
  99806. +}
  99807. +
  99808. +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
  99809. + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
  99810. + (node) = cgraph_next_function_with_gimple_body(node))
  99811. +#endif
  99812. +
  99813. +#if BUILDING_GCC_VERSION == 4006
  99814. +extern void debug_gimple_stmt(gimple);
  99815. +extern void debug_gimple_seq(gimple_seq);
  99816. +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
  99817. +extern void print_gimple_stmt(FILE *, gimple, int, int);
  99818. +extern void print_gimple_expr(FILE *, gimple, int, int);
  99819. +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
  99820. +#endif
  99821. +
  99822. +#if BUILDING_GCC_VERSION <= 4007
  99823. +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
  99824. +#define PROP_loops 0
  99825. +
  99826. +static inline int bb_loop_depth(const_basic_block bb)
  99827. +{
  99828. + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
  99829. +}
  99830. +
  99831. +static inline bool gimple_store_p(gimple gs)
  99832. +{
  99833. + tree lhs = gimple_get_lhs(gs);
  99834. + return lhs && !is_gimple_reg(lhs);
  99835. +}
  99836. +#endif
  99837. +
  99838. +#if BUILDING_GCC_VERSION >= 4007
  99839. +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
  99840. + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
  99841. +#endif
  99842. +
  99843. +#if BUILDING_GCC_VERSION <= 4008
  99844. +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
  99845. +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
  99846. +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
  99847. +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
  99848. +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
  99849. +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
  99850. +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
  99851. +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
  99852. +
  99853. +static inline const char *get_tree_code_name(enum tree_code code)
  99854. +{
  99855. + gcc_assert(code < MAX_TREE_CODES);
  99856. + return tree_code_name[code];
  99857. +}
  99858. +
  99859. +#define ipa_remove_stmt_references(cnode, stmt)
  99860. +#endif
  99861. +
  99862. +#if BUILDING_GCC_VERSION == 4008
  99863. +#define NODE_DECL(node) node->symbol.decl
  99864. +#else
  99865. +#define NODE_DECL(node) node->decl
  99866. +#endif
  99867. +
  99868. +#if BUILDING_GCC_VERSION >= 4008
  99869. +#define add_referenced_var(var)
  99870. +#define mark_sym_for_renaming(var)
  99871. +#define varpool_mark_needed_node(node)
  99872. +#define TODO_dump_func 0
  99873. +#define TODO_dump_cgraph 0
  99874. +#endif
  99875. +
  99876. +#if BUILDING_GCC_VERSION >= 4009
  99877. +#define TODO_ggc_collect 0
  99878. +#endif
  99879. +
  99880. +#endif
  99881. diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
  99882. new file mode 100644
  99883. index 0000000..7514850
  99884. --- /dev/null
  99885. +++ b/tools/gcc/gen-random-seed.sh
  99886. @@ -0,0 +1,8 @@
  99887. +#!/bin/sh
  99888. +
  99889. +if [ ! -f "$1" ]; then
  99890. + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
  99891. + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
  99892. + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
  99893. + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
  99894. +fi
  99895. diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
  99896. new file mode 100644
  99897. index 0000000..d81c094
  99898. --- /dev/null
  99899. +++ b/tools/gcc/kallocstat_plugin.c
  99900. @@ -0,0 +1,183 @@
  99901. +/*
  99902. + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
  99903. + * Licensed under the GPL v2
  99904. + *
  99905. + * Note: the choice of the license means that the compilation process is
  99906. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  99907. + * but for the kernel it doesn't matter since it doesn't link against
  99908. + * any of the gcc libraries
  99909. + *
  99910. + * gcc plugin to find the distribution of k*alloc sizes
  99911. + *
  99912. + * TODO:
  99913. + *
  99914. + * BUGS:
  99915. + * - none known
  99916. + */
  99917. +
  99918. +#include "gcc-common.h"
  99919. +
  99920. +int plugin_is_GPL_compatible;
  99921. +
  99922. +static struct plugin_info kallocstat_plugin_info = {
  99923. + .version = "201401260140",
  99924. + .help = NULL
  99925. +};
  99926. +
  99927. +static const char * const kalloc_functions[] = {
  99928. + "__kmalloc",
  99929. + "kmalloc",
  99930. + "kmalloc_large",
  99931. + "kmalloc_node",
  99932. + "kmalloc_order",
  99933. + "kmalloc_order_trace",
  99934. + "kmalloc_slab",
  99935. + "kzalloc",
  99936. + "kzalloc_node",
  99937. +};
  99938. +
  99939. +static bool is_kalloc(const char *fnname)
  99940. +{
  99941. + size_t i;
  99942. +
  99943. + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
  99944. + if (!strcmp(fnname, kalloc_functions[i]))
  99945. + return true;
  99946. + return false;
  99947. +}
  99948. +
  99949. +static unsigned int execute_kallocstat(void)
  99950. +{
  99951. + basic_block bb;
  99952. +
  99953. + // 1. loop through BBs and GIMPLE statements
  99954. + FOR_EACH_BB_FN(bb, cfun) {
  99955. + gimple_stmt_iterator gsi;
  99956. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  99957. + // gimple match:
  99958. + tree fndecl, size;
  99959. + gimple stmt;
  99960. + const char *fnname;
  99961. +
  99962. + // is it a call
  99963. + stmt = gsi_stmt(gsi);
  99964. + if (!is_gimple_call(stmt))
  99965. + continue;
  99966. + fndecl = gimple_call_fndecl(stmt);
  99967. + if (fndecl == NULL_TREE)
  99968. + continue;
  99969. + if (TREE_CODE(fndecl) != FUNCTION_DECL)
  99970. + continue;
  99971. +
  99972. + // is it a call to k*alloc
  99973. + fnname = DECL_NAME_POINTER(fndecl);
  99974. + if (!is_kalloc(fnname))
  99975. + continue;
  99976. +
  99977. + // is the size arg const or the result of a simple const assignment
  99978. + size = gimple_call_arg(stmt, 0);
  99979. + while (true) {
  99980. + expanded_location xloc;
  99981. + size_t size_val;
  99982. +
  99983. + if (TREE_CONSTANT(size)) {
  99984. + xloc = expand_location(gimple_location(stmt));
  99985. + if (!xloc.file)
  99986. + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
  99987. + size_val = TREE_INT_CST_LOW(size);
  99988. + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
  99989. + break;
  99990. + }
  99991. +
  99992. + if (TREE_CODE(size) != SSA_NAME)
  99993. + break;
  99994. + stmt = SSA_NAME_DEF_STMT(size);
  99995. +//debug_gimple_stmt(stmt);
  99996. +//debug_tree(size);
  99997. + if (!stmt || !is_gimple_assign(stmt))
  99998. + break;
  99999. + if (gimple_num_ops(stmt) != 2)
  100000. + break;
  100001. + size = gimple_assign_rhs1(stmt);
  100002. + }
  100003. +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
  100004. +//debug_tree(gimple_call_fn(call_stmt));
  100005. +//print_node(stderr, "pax", fndecl, 4);
  100006. + }
  100007. + }
  100008. +
  100009. + return 0;
  100010. +}
  100011. +
  100012. +#if BUILDING_GCC_VERSION >= 4009
  100013. +static const struct pass_data kallocstat_pass_data = {
  100014. +#else
  100015. +static struct gimple_opt_pass kallocstat_pass = {
  100016. + .pass = {
  100017. +#endif
  100018. + .type = GIMPLE_PASS,
  100019. + .name = "kallocstat",
  100020. +#if BUILDING_GCC_VERSION >= 4008
  100021. + .optinfo_flags = OPTGROUP_NONE,
  100022. +#endif
  100023. +#if BUILDING_GCC_VERSION >= 4009
  100024. + .has_gate = false,
  100025. + .has_execute = true,
  100026. +#else
  100027. + .gate = NULL,
  100028. + .execute = execute_kallocstat,
  100029. + .sub = NULL,
  100030. + .next = NULL,
  100031. + .static_pass_number = 0,
  100032. +#endif
  100033. + .tv_id = TV_NONE,
  100034. + .properties_required = 0,
  100035. + .properties_provided = 0,
  100036. + .properties_destroyed = 0,
  100037. + .todo_flags_start = 0,
  100038. + .todo_flags_finish = 0
  100039. +#if BUILDING_GCC_VERSION < 4009
  100040. + }
  100041. +#endif
  100042. +};
  100043. +
  100044. +#if BUILDING_GCC_VERSION >= 4009
  100045. +namespace {
  100046. +class kallocstat_pass : public gimple_opt_pass {
  100047. +public:
  100048. + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
  100049. + unsigned int execute() { return execute_kallocstat(); }
  100050. +};
  100051. +}
  100052. +
  100053. +static opt_pass *make_kallocstat_pass(void)
  100054. +{
  100055. + return new kallocstat_pass();
  100056. +}
  100057. +#else
  100058. +static struct opt_pass *make_kallocstat_pass(void)
  100059. +{
  100060. + return &kallocstat_pass.pass;
  100061. +}
  100062. +#endif
  100063. +
  100064. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  100065. +{
  100066. + const char * const plugin_name = plugin_info->base_name;
  100067. + struct register_pass_info kallocstat_pass_info;
  100068. +
  100069. + kallocstat_pass_info.pass = make_kallocstat_pass();
  100070. + kallocstat_pass_info.reference_pass_name = "ssa";
  100071. + kallocstat_pass_info.ref_pass_instance_number = 1;
  100072. + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  100073. +
  100074. + if (!plugin_default_version_check(version, &gcc_version)) {
  100075. + error(G_("incompatible gcc/plugin versions"));
  100076. + return 1;
  100077. + }
  100078. +
  100079. + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
  100080. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
  100081. +
  100082. + return 0;
  100083. +}
  100084. diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
  100085. new file mode 100644
  100086. index 0000000..89f256d
  100087. --- /dev/null
  100088. +++ b/tools/gcc/kernexec_plugin.c
  100089. @@ -0,0 +1,522 @@
  100090. +/*
  100091. + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
  100092. + * Licensed under the GPL v2
  100093. + *
  100094. + * Note: the choice of the license means that the compilation process is
  100095. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  100096. + * but for the kernel it doesn't matter since it doesn't link against
  100097. + * any of the gcc libraries
  100098. + *
  100099. + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
  100100. + *
  100101. + * TODO:
  100102. + *
  100103. + * BUGS:
  100104. + * - none known
  100105. + */
  100106. +
  100107. +#include "gcc-common.h"
  100108. +
  100109. +int plugin_is_GPL_compatible;
  100110. +
  100111. +static struct plugin_info kernexec_plugin_info = {
  100112. + .version = "201401260140",
  100113. + .help = "method=[bts|or]\tinstrumentation method\n"
  100114. +};
  100115. +
  100116. +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
  100117. +static void (*kernexec_instrument_retaddr)(rtx);
  100118. +
  100119. +/*
  100120. + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
  100121. + */
  100122. +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
  100123. +{
  100124. + gimple asm_movabs_stmt;
  100125. +
  100126. + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
  100127. + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
  100128. + gimple_asm_set_volatile(asm_movabs_stmt, true);
  100129. + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
  100130. + update_stmt(asm_movabs_stmt);
  100131. +}
  100132. +
  100133. +/*
  100134. + * find all asm() stmts that clobber r12 and add a reload of r12
  100135. + */
  100136. +static unsigned int execute_kernexec_reload(void)
  100137. +{
  100138. + basic_block bb;
  100139. +
  100140. + // 1. loop through BBs and GIMPLE statements
  100141. + FOR_EACH_BB_FN(bb, cfun) {
  100142. + gimple_stmt_iterator gsi;
  100143. +
  100144. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  100145. + // gimple match: __asm__ ("" : : : "r12");
  100146. + gimple asm_stmt;
  100147. + size_t nclobbers;
  100148. +
  100149. + // is it an asm ...
  100150. + asm_stmt = gsi_stmt(gsi);
  100151. + if (gimple_code(asm_stmt) != GIMPLE_ASM)
  100152. + continue;
  100153. +
  100154. + // ... clobbering r12
  100155. + nclobbers = gimple_asm_nclobbers(asm_stmt);
  100156. + while (nclobbers--) {
  100157. + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
  100158. + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
  100159. + continue;
  100160. + kernexec_reload_fptr_mask(&gsi);
  100161. +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
  100162. + break;
  100163. + }
  100164. + }
  100165. + }
  100166. +
  100167. + return 0;
  100168. +}
  100169. +
  100170. +/*
  100171. + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
  100172. + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
  100173. + */
  100174. +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
  100175. +{
  100176. + gimple assign_intptr, assign_new_fptr, call_stmt;
  100177. + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
  100178. +
  100179. + call_stmt = gsi_stmt(*gsi);
  100180. + old_fptr = gimple_call_fn(call_stmt);
  100181. +
  100182. + // create temporary unsigned long variable used for bitops and cast fptr to it
  100183. + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
  100184. + add_referenced_var(intptr);
  100185. + intptr = make_ssa_name(intptr, NULL);
  100186. + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
  100187. + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
  100188. + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
  100189. + update_stmt(assign_intptr);
  100190. +
  100191. + // apply logical or to temporary unsigned long and bitmask
  100192. + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
  100193. +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
  100194. + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
  100195. + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
  100196. + assign_intptr = gimple_build_assign(intptr, orptr);
  100197. + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
  100198. + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
  100199. + update_stmt(assign_intptr);
  100200. +
  100201. + // cast temporary unsigned long back to a temporary fptr variable
  100202. + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
  100203. + add_referenced_var(new_fptr);
  100204. + new_fptr = make_ssa_name(new_fptr, NULL);
  100205. + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
  100206. + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
  100207. + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
  100208. + update_stmt(assign_new_fptr);
  100209. +
  100210. + // replace call stmt fn with the new fptr
  100211. + gimple_call_set_fn(call_stmt, new_fptr);
  100212. + update_stmt(call_stmt);
  100213. +}
  100214. +
  100215. +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
  100216. +{
  100217. + gimple asm_or_stmt, call_stmt;
  100218. + tree old_fptr, new_fptr, input, output;
  100219. +#if BUILDING_GCC_VERSION <= 4007
  100220. + VEC(tree, gc) *inputs = NULL;
  100221. + VEC(tree, gc) *outputs = NULL;
  100222. +#else
  100223. + vec<tree, va_gc> *inputs = NULL;
  100224. + vec<tree, va_gc> *outputs = NULL;
  100225. +#endif
  100226. +
  100227. + call_stmt = gsi_stmt(*gsi);
  100228. + old_fptr = gimple_call_fn(call_stmt);
  100229. +
  100230. + // create temporary fptr variable
  100231. + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
  100232. + add_referenced_var(new_fptr);
  100233. + new_fptr = make_ssa_name(new_fptr, NULL);
  100234. +
  100235. + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
  100236. + input = build_tree_list(NULL_TREE, build_string(1, "0"));
  100237. + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
  100238. + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
  100239. + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
  100240. +#if BUILDING_GCC_VERSION <= 4007
  100241. + VEC_safe_push(tree, gc, inputs, input);
  100242. + VEC_safe_push(tree, gc, outputs, output);
  100243. +#else
  100244. + vec_safe_push(inputs, input);
  100245. + vec_safe_push(outputs, output);
  100246. +#endif
  100247. + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
  100248. + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
  100249. + gimple_asm_set_volatile(asm_or_stmt, true);
  100250. + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
  100251. + update_stmt(asm_or_stmt);
  100252. +
  100253. + // replace call stmt fn with the new fptr
  100254. + gimple_call_set_fn(call_stmt, new_fptr);
  100255. + update_stmt(call_stmt);
  100256. +}
  100257. +
  100258. +/*
  100259. + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
  100260. + */
  100261. +static unsigned int execute_kernexec_fptr(void)
  100262. +{
  100263. + basic_block bb;
  100264. +
  100265. + // 1. loop through BBs and GIMPLE statements
  100266. + FOR_EACH_BB_FN(bb, cfun) {
  100267. + gimple_stmt_iterator gsi;
  100268. +
  100269. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  100270. + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
  100271. + tree fn;
  100272. + gimple call_stmt;
  100273. +
  100274. + // is it a call ...
  100275. + call_stmt = gsi_stmt(gsi);
  100276. + if (!is_gimple_call(call_stmt))
  100277. + continue;
  100278. + fn = gimple_call_fn(call_stmt);
  100279. + if (TREE_CODE(fn) == ADDR_EXPR)
  100280. + continue;
  100281. + if (TREE_CODE(fn) != SSA_NAME)
  100282. + gcc_unreachable();
  100283. +
  100284. + // ... through a function pointer
  100285. + if (SSA_NAME_VAR(fn) != NULL_TREE) {
  100286. + fn = SSA_NAME_VAR(fn);
  100287. + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
  100288. + debug_tree(fn);
  100289. + gcc_unreachable();
  100290. + }
  100291. + }
  100292. + fn = TREE_TYPE(fn);
  100293. + if (TREE_CODE(fn) != POINTER_TYPE)
  100294. + continue;
  100295. + fn = TREE_TYPE(fn);
  100296. + if (TREE_CODE(fn) != FUNCTION_TYPE)
  100297. + continue;
  100298. +
  100299. + kernexec_instrument_fptr(&gsi);
  100300. +
  100301. +//debug_tree(gimple_call_fn(call_stmt));
  100302. +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
  100303. + }
  100304. + }
  100305. +
  100306. + return 0;
  100307. +}
  100308. +
  100309. +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
  100310. +static void kernexec_instrument_retaddr_bts(rtx insn)
  100311. +{
  100312. + rtx btsq;
  100313. + rtvec argvec, constraintvec, labelvec;
  100314. + int line;
  100315. +
  100316. + // create asm volatile("btsq $63,(%%rsp)":::)
  100317. + argvec = rtvec_alloc(0);
  100318. + constraintvec = rtvec_alloc(0);
  100319. + labelvec = rtvec_alloc(0);
  100320. + line = expand_location(RTL_LOCATION(insn)).line;
  100321. + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
  100322. + MEM_VOLATILE_P(btsq) = 1;
  100323. +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
  100324. + emit_insn_before(btsq, insn);
  100325. +}
  100326. +
  100327. +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
  100328. +static void kernexec_instrument_retaddr_or(rtx insn)
  100329. +{
  100330. + rtx orq;
  100331. + rtvec argvec, constraintvec, labelvec;
  100332. + int line;
  100333. +
  100334. + // create asm volatile("orq %%r12,(%%rsp)":::)
  100335. + argvec = rtvec_alloc(0);
  100336. + constraintvec = rtvec_alloc(0);
  100337. + labelvec = rtvec_alloc(0);
  100338. + line = expand_location(RTL_LOCATION(insn)).line;
  100339. + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
  100340. + MEM_VOLATILE_P(orq) = 1;
  100341. +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
  100342. + emit_insn_before(orq, insn);
  100343. +}
  100344. +
  100345. +/*
  100346. + * find all asm level function returns and forcibly set the highest bit of the return address
  100347. + */
  100348. +static unsigned int execute_kernexec_retaddr(void)
  100349. +{
  100350. + rtx insn;
  100351. +
  100352. +// if (stack_realign_drap)
  100353. +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
  100354. +
  100355. + // 1. find function returns
  100356. + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
  100357. + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
  100358. + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
  100359. + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
  100360. + rtx body;
  100361. +
  100362. + // is it a retn
  100363. + if (!JUMP_P(insn))
  100364. + continue;
  100365. + body = PATTERN(insn);
  100366. + if (GET_CODE(body) == PARALLEL)
  100367. + body = XVECEXP(body, 0, 0);
  100368. + if (!ANY_RETURN_P(body))
  100369. + continue;
  100370. + kernexec_instrument_retaddr(insn);
  100371. + }
  100372. +
  100373. +// print_simple_rtl(stderr, get_insns());
  100374. +// print_rtl(stderr, get_insns());
  100375. +
  100376. + return 0;
  100377. +}
  100378. +
  100379. +static bool kernexec_cmodel_check(void)
  100380. +{
  100381. + tree section;
  100382. +
  100383. + if (ix86_cmodel != CM_KERNEL)
  100384. + return false;
  100385. +
  100386. + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
  100387. + if (!section || !TREE_VALUE(section))
  100388. + return true;
  100389. +
  100390. + section = TREE_VALUE(TREE_VALUE(section));
  100391. + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
  100392. + return true;
  100393. +
  100394. + return false;
  100395. +}
  100396. +
  100397. +#if BUILDING_GCC_VERSION >= 4009
  100398. +static const struct pass_data kernexec_reload_pass_data = {
  100399. +#else
  100400. +static struct gimple_opt_pass kernexec_reload_pass = {
  100401. + .pass = {
  100402. +#endif
  100403. + .type = GIMPLE_PASS,
  100404. + .name = "kernexec_reload",
  100405. +#if BUILDING_GCC_VERSION >= 4008
  100406. + .optinfo_flags = OPTGROUP_NONE,
  100407. +#endif
  100408. +#if BUILDING_GCC_VERSION >= 4009
  100409. + .has_gate = true,
  100410. + .has_execute = true,
  100411. +#else
  100412. + .gate = kernexec_cmodel_check,
  100413. + .execute = execute_kernexec_reload,
  100414. + .sub = NULL,
  100415. + .next = NULL,
  100416. + .static_pass_number = 0,
  100417. +#endif
  100418. + .tv_id = TV_NONE,
  100419. + .properties_required = 0,
  100420. + .properties_provided = 0,
  100421. + .properties_destroyed = 0,
  100422. + .todo_flags_start = 0,
  100423. + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
  100424. +#if BUILDING_GCC_VERSION < 4009
  100425. + }
  100426. +#endif
  100427. +};
  100428. +
  100429. +#if BUILDING_GCC_VERSION >= 4009
  100430. +static const struct pass_data kernexec_fptr_pass_data = {
  100431. +#else
  100432. +static struct gimple_opt_pass kernexec_fptr_pass = {
  100433. + .pass = {
  100434. +#endif
  100435. + .type = GIMPLE_PASS,
  100436. + .name = "kernexec_fptr",
  100437. +#if BUILDING_GCC_VERSION >= 4008
  100438. + .optinfo_flags = OPTGROUP_NONE,
  100439. +#endif
  100440. +#if BUILDING_GCC_VERSION >= 4009
  100441. + .has_gate = true,
  100442. + .has_execute = true,
  100443. +#else
  100444. + .gate = kernexec_cmodel_check,
  100445. + .execute = execute_kernexec_fptr,
  100446. + .sub = NULL,
  100447. + .next = NULL,
  100448. + .static_pass_number = 0,
  100449. +#endif
  100450. + .tv_id = TV_NONE,
  100451. + .properties_required = 0,
  100452. + .properties_provided = 0,
  100453. + .properties_destroyed = 0,
  100454. + .todo_flags_start = 0,
  100455. + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
  100456. +#if BUILDING_GCC_VERSION < 4009
  100457. + }
  100458. +#endif
  100459. +};
  100460. +
  100461. +#if BUILDING_GCC_VERSION >= 4009
  100462. +static const struct pass_data kernexec_retaddr_pass_data = {
  100463. +#else
  100464. +static struct rtl_opt_pass kernexec_retaddr_pass = {
  100465. + .pass = {
  100466. +#endif
  100467. + .type = RTL_PASS,
  100468. + .name = "kernexec_retaddr",
  100469. +#if BUILDING_GCC_VERSION >= 4008
  100470. + .optinfo_flags = OPTGROUP_NONE,
  100471. +#endif
  100472. +#if BUILDING_GCC_VERSION >= 4009
  100473. + .has_gate = true,
  100474. + .has_execute = true,
  100475. +#else
  100476. + .gate = kernexec_cmodel_check,
  100477. + .execute = execute_kernexec_retaddr,
  100478. + .sub = NULL,
  100479. + .next = NULL,
  100480. + .static_pass_number = 0,
  100481. +#endif
  100482. + .tv_id = TV_NONE,
  100483. + .properties_required = 0,
  100484. + .properties_provided = 0,
  100485. + .properties_destroyed = 0,
  100486. + .todo_flags_start = 0,
  100487. + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
  100488. +#if BUILDING_GCC_VERSION < 4009
  100489. + }
  100490. +#endif
  100491. +};
  100492. +
  100493. +#if BUILDING_GCC_VERSION >= 4009
  100494. +namespace {
  100495. +class kernexec_reload_pass : public gimple_opt_pass {
  100496. +public:
  100497. + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
  100498. + bool gate() { return kernexec_cmodel_check(); }
  100499. + unsigned int execute() { return execute_kernexec_reload(); }
  100500. +};
  100501. +
  100502. +class kernexec_fptr_pass : public gimple_opt_pass {
  100503. +public:
  100504. + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
  100505. + bool gate() { return kernexec_cmodel_check(); }
  100506. + unsigned int execute() { return execute_kernexec_fptr(); }
  100507. +};
  100508. +
  100509. +class kernexec_retaddr_pass : public rtl_opt_pass {
  100510. +public:
  100511. + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
  100512. + bool gate() { return kernexec_cmodel_check(); }
  100513. + unsigned int execute() { return execute_kernexec_retaddr(); }
  100514. +};
  100515. +}
  100516. +
  100517. +static opt_pass *make_kernexec_reload_pass(void)
  100518. +{
  100519. + return new kernexec_reload_pass();
  100520. +}
  100521. +
  100522. +static opt_pass *make_kernexec_fptr_pass(void)
  100523. +{
  100524. + return new kernexec_fptr_pass();
  100525. +}
  100526. +
  100527. +static opt_pass *make_kernexec_retaddr_pass(void)
  100528. +{
  100529. + return new kernexec_retaddr_pass();
  100530. +}
  100531. +#else
  100532. +static struct opt_pass *make_kernexec_reload_pass(void)
  100533. +{
  100534. + return &kernexec_reload_pass.pass;
  100535. +}
  100536. +
  100537. +static struct opt_pass *make_kernexec_fptr_pass(void)
  100538. +{
  100539. + return &kernexec_fptr_pass.pass;
  100540. +}
  100541. +
  100542. +static struct opt_pass *make_kernexec_retaddr_pass(void)
  100543. +{
  100544. + return &kernexec_retaddr_pass.pass;
  100545. +}
  100546. +#endif
  100547. +
  100548. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  100549. +{
  100550. + const char * const plugin_name = plugin_info->base_name;
  100551. + const int argc = plugin_info->argc;
  100552. + const struct plugin_argument * const argv = plugin_info->argv;
  100553. + int i;
  100554. + struct register_pass_info kernexec_reload_pass_info;
  100555. + struct register_pass_info kernexec_fptr_pass_info;
  100556. + struct register_pass_info kernexec_retaddr_pass_info;
  100557. +
  100558. + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
  100559. + kernexec_reload_pass_info.reference_pass_name = "ssa";
  100560. + kernexec_reload_pass_info.ref_pass_instance_number = 1;
  100561. + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  100562. +
  100563. + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
  100564. + kernexec_fptr_pass_info.reference_pass_name = "ssa";
  100565. + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
  100566. + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  100567. +
  100568. + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
  100569. + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
  100570. + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
  100571. + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  100572. +
  100573. + if (!plugin_default_version_check(version, &gcc_version)) {
  100574. + error(G_("incompatible gcc/plugin versions"));
  100575. + return 1;
  100576. + }
  100577. +
  100578. + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
  100579. +
  100580. + if (TARGET_64BIT == 0)
  100581. + return 0;
  100582. +
  100583. + for (i = 0; i < argc; ++i) {
  100584. + if (!strcmp(argv[i].key, "method")) {
  100585. + if (!argv[i].value) {
  100586. + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  100587. + continue;
  100588. + }
  100589. + if (!strcmp(argv[i].value, "bts")) {
  100590. + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
  100591. + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
  100592. + } else if (!strcmp(argv[i].value, "or")) {
  100593. + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
  100594. + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
  100595. + fix_register("r12", 1, 1);
  100596. + } else
  100597. + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
  100598. + continue;
  100599. + }
  100600. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  100601. + }
  100602. + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
  100603. + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
  100604. +
  100605. + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
  100606. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
  100607. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
  100608. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
  100609. +
  100610. + return 0;
  100611. +}
  100612. diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
  100613. new file mode 100644
  100614. index 0000000..39d7cc7
  100615. --- /dev/null
  100616. +++ b/tools/gcc/latent_entropy_plugin.c
  100617. @@ -0,0 +1,462 @@
  100618. +/*
  100619. + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
  100620. + * Licensed under the GPL v2
  100621. + *
  100622. + * Note: the choice of the license means that the compilation process is
  100623. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  100624. + * but for the kernel it doesn't matter since it doesn't link against
  100625. + * any of the gcc libraries
  100626. + *
  100627. + * gcc plugin to help generate a little bit of entropy from program state,
  100628. + * used throughout the uptime of the kernel
  100629. + *
  100630. + * TODO:
  100631. + * - add ipa pass to identify not explicitly marked candidate functions
  100632. + * - mix in more program state (function arguments/return values, loop variables, etc)
  100633. + * - more instrumentation control via attribute parameters
  100634. + *
  100635. + * BUGS:
  100636. + * - LTO needs -flto-partition=none for now
  100637. + */
  100638. +
  100639. +#include "gcc-common.h"
  100640. +
  100641. +int plugin_is_GPL_compatible;
  100642. +
  100643. +static tree latent_entropy_decl;
  100644. +
  100645. +static struct plugin_info latent_entropy_plugin_info = {
  100646. + .version = "201403280150",
  100647. + .help = NULL
  100648. +};
  100649. +
  100650. +static unsigned HOST_WIDE_INT seed;
  100651. +static unsigned HOST_WIDE_INT get_random_const(void)
  100652. +{
  100653. + unsigned int i;
  100654. + unsigned HOST_WIDE_INT ret = 0;
  100655. +
  100656. + for (i = 0; i < 8 * sizeof ret; i++) {
  100657. + ret = (ret << 1) | (seed & 1);
  100658. + seed >>= 1;
  100659. + if (ret & 1)
  100660. + seed ^= 0xD800000000000000ULL;
  100661. + }
  100662. +
  100663. + return ret;
  100664. +}
  100665. +
  100666. +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  100667. +{
  100668. + tree type;
  100669. + unsigned long long mask;
  100670. +#if BUILDING_GCC_VERSION <= 4007
  100671. + VEC(constructor_elt, gc) *vals;
  100672. +#else
  100673. + vec<constructor_elt, va_gc> *vals;
  100674. +#endif
  100675. +
  100676. + switch (TREE_CODE(*node)) {
  100677. + default:
  100678. + *no_add_attrs = true;
  100679. + error("%qE attribute only applies to functions and variables", name);
  100680. + break;
  100681. +
  100682. + case VAR_DECL:
  100683. + if (DECL_INITIAL(*node)) {
  100684. + *no_add_attrs = true;
  100685. + error("variable %qD with %qE attribute must not be initialized", *node, name);
  100686. + break;
  100687. + }
  100688. +
  100689. + if (!TREE_STATIC(*node)) {
  100690. + *no_add_attrs = true;
  100691. + error("variable %qD with %qE attribute must not be local", *node, name);
  100692. + break;
  100693. + }
  100694. +
  100695. + type = TREE_TYPE(*node);
  100696. + switch (TREE_CODE(type)) {
  100697. + default:
  100698. + *no_add_attrs = true;
  100699. + error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name);
  100700. + break;
  100701. +
  100702. + case RECORD_TYPE: {
  100703. + tree field;
  100704. + unsigned int nelt = 0;
  100705. +
  100706. + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
  100707. + tree fieldtype;
  100708. +
  100709. + fieldtype = TREE_TYPE(field);
  100710. + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
  100711. + *no_add_attrs = true;
  100712. + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
  100713. + break;
  100714. + }
  100715. + }
  100716. +
  100717. + if (field)
  100718. + break;
  100719. +
  100720. +#if BUILDING_GCC_VERSION <= 4007
  100721. + vals = VEC_alloc(constructor_elt, gc, nelt);
  100722. +#else
  100723. + vec_alloc(vals, nelt);
  100724. +#endif
  100725. +
  100726. + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
  100727. + tree fieldtype;
  100728. +
  100729. + fieldtype = TREE_TYPE(field);
  100730. + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
  100731. + mask = 2 * (mask - 1) + 1;
  100732. +
  100733. + if (TYPE_UNSIGNED(fieldtype))
  100734. + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
  100735. + else
  100736. + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
  100737. + }
  100738. +
  100739. + DECL_INITIAL(*node) = build_constructor(type, vals);
  100740. +//debug_tree(DECL_INITIAL(*node));
  100741. + break;
  100742. + }
  100743. +
  100744. + case INTEGER_TYPE:
  100745. + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
  100746. + mask = 2 * (mask - 1) + 1;
  100747. +
  100748. + if (TYPE_UNSIGNED(type))
  100749. + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
  100750. + else
  100751. + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
  100752. + break;
  100753. +
  100754. + case ARRAY_TYPE: {
  100755. + tree elt_type, array_size, elt_size;
  100756. + unsigned int i, nelt;
  100757. +
  100758. + elt_type = TREE_TYPE(type);
  100759. + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
  100760. + array_size = TYPE_SIZE_UNIT(type);
  100761. +
  100762. + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
  100763. + *no_add_attrs = true;
  100764. + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
  100765. + break;
  100766. + }
  100767. +
  100768. + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
  100769. +#if BUILDING_GCC_VERSION <= 4007
  100770. + vals = VEC_alloc(constructor_elt, gc, nelt);
  100771. +#else
  100772. + vec_alloc(vals, nelt);
  100773. +#endif
  100774. +
  100775. + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
  100776. + mask = 2 * (mask - 1) + 1;
  100777. +
  100778. + for (i = 0; i < nelt; i++)
  100779. + if (TYPE_UNSIGNED(elt_type))
  100780. + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
  100781. + else
  100782. + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
  100783. +
  100784. + DECL_INITIAL(*node) = build_constructor(type, vals);
  100785. +//debug_tree(DECL_INITIAL(*node));
  100786. + break;
  100787. + }
  100788. + }
  100789. + break;
  100790. +
  100791. + case FUNCTION_DECL:
  100792. + break;
  100793. + }
  100794. +
  100795. + return NULL_TREE;
  100796. +}
  100797. +
  100798. +static struct attribute_spec latent_entropy_attr = {
  100799. + .name = "latent_entropy",
  100800. + .min_length = 0,
  100801. + .max_length = 0,
  100802. + .decl_required = true,
  100803. + .type_required = false,
  100804. + .function_type_required = false,
  100805. + .handler = handle_latent_entropy_attribute,
  100806. +#if BUILDING_GCC_VERSION >= 4007
  100807. + .affects_type_identity = false
  100808. +#endif
  100809. +};
  100810. +
  100811. +static void register_attributes(void *event_data, void *data)
  100812. +{
  100813. + register_attribute(&latent_entropy_attr);
  100814. +}
  100815. +
  100816. +static bool gate_latent_entropy(void)
  100817. +{
  100818. + // don't bother with noreturn functions for now
  100819. + if (TREE_THIS_VOLATILE(current_function_decl))
  100820. + return false;
  100821. +
  100822. + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
  100823. +}
  100824. +
  100825. +static enum tree_code get_op(tree *rhs)
  100826. +{
  100827. + static enum tree_code op;
  100828. + unsigned HOST_WIDE_INT random_const;
  100829. +
  100830. + random_const = get_random_const();
  100831. +
  100832. + switch (op) {
  100833. + case BIT_XOR_EXPR:
  100834. + op = PLUS_EXPR;
  100835. + break;
  100836. +
  100837. + case PLUS_EXPR:
  100838. + if (rhs) {
  100839. + op = LROTATE_EXPR;
  100840. + random_const &= HOST_BITS_PER_WIDE_INT - 1;
  100841. + break;
  100842. + }
  100843. +
  100844. + case LROTATE_EXPR:
  100845. + default:
  100846. + op = BIT_XOR_EXPR;
  100847. + break;
  100848. + }
  100849. + if (rhs)
  100850. + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
  100851. + return op;
  100852. +}
  100853. +
  100854. +static void perturb_local_entropy(basic_block bb, tree local_entropy)
  100855. +{
  100856. + gimple_stmt_iterator gsi;
  100857. + gimple assign;
  100858. + tree addxorrol, rhs;
  100859. + enum tree_code op;
  100860. +
  100861. + op = get_op(&rhs);
  100862. + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
  100863. + assign = gimple_build_assign(local_entropy, addxorrol);
  100864. + gsi = gsi_after_labels(bb);
  100865. + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
  100866. + update_stmt(assign);
  100867. +//debug_bb(bb);
  100868. +}
  100869. +
  100870. +static void perturb_latent_entropy(basic_block bb, tree rhs)
  100871. +{
  100872. + gimple_stmt_iterator gsi;
  100873. + gimple assign;
  100874. + tree addxorrol, temp;
  100875. +
  100876. + // 1. create temporary copy of latent_entropy
  100877. + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
  100878. + add_referenced_var(temp);
  100879. +
  100880. + // 2. read...
  100881. + temp = make_ssa_name(temp, NULL);
  100882. + assign = gimple_build_assign(temp, latent_entropy_decl);
  100883. + SSA_NAME_DEF_STMT(temp) = assign;
  100884. + add_referenced_var(latent_entropy_decl);
  100885. + gsi = gsi_after_labels(bb);
  100886. + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
  100887. + update_stmt(assign);
  100888. +
  100889. + // 3. ...modify...
  100890. + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
  100891. + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
  100892. + assign = gimple_build_assign(temp, addxorrol);
  100893. + SSA_NAME_DEF_STMT(temp) = assign;
  100894. + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
  100895. + update_stmt(assign);
  100896. +
  100897. + // 4. ...write latent_entropy
  100898. + assign = gimple_build_assign(latent_entropy_decl, temp);
  100899. + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
  100900. + update_stmt(assign);
  100901. +}
  100902. +
  100903. +static unsigned int execute_latent_entropy(void)
  100904. +{
  100905. + basic_block bb;
  100906. + gimple assign;
  100907. + gimple_stmt_iterator gsi;
  100908. + tree local_entropy;
  100909. +
  100910. + if (!latent_entropy_decl) {
  100911. +#if BUILDING_GCC_VERSION >= 4009
  100912. + varpool_node *node;
  100913. +#else
  100914. + struct varpool_node *node;
  100915. +#endif
  100916. +
  100917. + FOR_EACH_VARIABLE(node) {
  100918. + tree var = NODE_DECL(node);
  100919. +
  100920. + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
  100921. + continue;
  100922. + latent_entropy_decl = var;
  100923. +// debug_tree(var);
  100924. + break;
  100925. + }
  100926. + if (!latent_entropy_decl) {
  100927. +// debug_tree(current_function_decl);
  100928. + return 0;
  100929. + }
  100930. + }
  100931. +
  100932. +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
  100933. +
  100934. + // 1. create local entropy variable
  100935. + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
  100936. + add_referenced_var(local_entropy);
  100937. + mark_sym_for_renaming(local_entropy);
  100938. +
  100939. + // 2. initialize local entropy variable
  100940. + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
  100941. + if (dom_info_available_p(CDI_DOMINATORS))
  100942. + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
  100943. + gsi = gsi_start_bb(bb);
  100944. +
  100945. + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
  100946. +// gimple_set_location(assign, loc);
  100947. + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
  100948. + update_stmt(assign);
  100949. +//debug_bb(bb);
  100950. + gcc_assert(single_succ_p(bb));
  100951. + bb = single_succ(bb);
  100952. +
  100953. + // 3. instrument each BB with an operation on the local entropy variable
  100954. + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
  100955. + perturb_local_entropy(bb, local_entropy);
  100956. +//debug_bb(bb);
  100957. + bb = bb->next_bb;
  100958. + };
  100959. +
  100960. + // 4. mix local entropy into the global entropy variable
  100961. + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
  100962. + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
  100963. +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
  100964. + return 0;
  100965. +}
  100966. +
  100967. +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
  100968. +{
  100969. + tree latent_entropy_type;
  100970. +
  100971. + seed = get_random_seed(false);
  100972. +
  100973. + if (in_lto_p)
  100974. + return;
  100975. +
  100976. + // extern volatile u64 latent_entropy
  100977. + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
  100978. + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
  100979. + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
  100980. +
  100981. + TREE_STATIC(latent_entropy_decl) = 1;
  100982. + TREE_PUBLIC(latent_entropy_decl) = 1;
  100983. + TREE_USED(latent_entropy_decl) = 1;
  100984. + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
  100985. + DECL_EXTERNAL(latent_entropy_decl) = 1;
  100986. + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
  100987. + lang_hooks.decls.pushdecl(latent_entropy_decl);
  100988. +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
  100989. +// varpool_finalize_decl(latent_entropy_decl);
  100990. +// varpool_mark_needed_node(latent_entropy_decl);
  100991. +}
  100992. +
  100993. +#if BUILDING_GCC_VERSION >= 4009
  100994. +static const struct pass_data latent_entropy_pass_data = {
  100995. +#else
  100996. +static struct gimple_opt_pass latent_entropy_pass = {
  100997. + .pass = {
  100998. +#endif
  100999. + .type = GIMPLE_PASS,
  101000. + .name = "latent_entropy",
  101001. +#if BUILDING_GCC_VERSION >= 4008
  101002. + .optinfo_flags = OPTGROUP_NONE,
  101003. +#endif
  101004. +#if BUILDING_GCC_VERSION >= 4009
  101005. + .has_gate = true,
  101006. + .has_execute = true,
  101007. +#else
  101008. + .gate = gate_latent_entropy,
  101009. + .execute = execute_latent_entropy,
  101010. + .sub = NULL,
  101011. + .next = NULL,
  101012. + .static_pass_number = 0,
  101013. +#endif
  101014. + .tv_id = TV_NONE,
  101015. + .properties_required = PROP_gimple_leh | PROP_cfg,
  101016. + .properties_provided = 0,
  101017. + .properties_destroyed = 0,
  101018. + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
  101019. + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
  101020. +#if BUILDING_GCC_VERSION < 4009
  101021. + }
  101022. +#endif
  101023. +};
  101024. +
  101025. +#if BUILDING_GCC_VERSION >= 4009
  101026. +namespace {
  101027. +class latent_entropy_pass : public gimple_opt_pass {
  101028. +public:
  101029. + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
  101030. + bool gate() { return gate_latent_entropy(); }
  101031. + unsigned int execute() { return execute_latent_entropy(); }
  101032. +};
  101033. +}
  101034. +
  101035. +static opt_pass *make_latent_entropy_pass(void)
  101036. +{
  101037. + return new latent_entropy_pass();
  101038. +}
  101039. +#else
  101040. +static struct opt_pass *make_latent_entropy_pass(void)
  101041. +{
  101042. + return &latent_entropy_pass.pass;
  101043. +}
  101044. +#endif
  101045. +
  101046. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  101047. +{
  101048. + const char * const plugin_name = plugin_info->base_name;
  101049. + struct register_pass_info latent_entropy_pass_info;
  101050. +
  101051. + latent_entropy_pass_info.pass = make_latent_entropy_pass();
  101052. + latent_entropy_pass_info.reference_pass_name = "optimized";
  101053. + latent_entropy_pass_info.ref_pass_instance_number = 1;
  101054. + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
  101055. + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
  101056. + {
  101057. + .base = &latent_entropy_decl,
  101058. + .nelt = 1,
  101059. + .stride = sizeof(latent_entropy_decl),
  101060. + .cb = &gt_ggc_mx_tree_node,
  101061. + .pchw = &gt_pch_nx_tree_node
  101062. + },
  101063. + LAST_GGC_ROOT_TAB
  101064. + };
  101065. +
  101066. + if (!plugin_default_version_check(version, &gcc_version)) {
  101067. + error(G_("incompatible gcc/plugin versions"));
  101068. + return 1;
  101069. + }
  101070. +
  101071. + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
  101072. + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
  101073. + if (!in_lto_p)
  101074. + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
  101075. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
  101076. + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
  101077. +
  101078. + return 0;
  101079. +}
  101080. diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
  101081. new file mode 100644
  101082. index 0000000..8dafb22
  101083. --- /dev/null
  101084. +++ b/tools/gcc/randomize_layout_plugin.c
  101085. @@ -0,0 +1,910 @@
  101086. +/*
  101087. + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
  101088. + * and PaX Team <pageexec@freemail.hu>
  101089. + * Licensed under the GPL v2
  101090. + *
  101091. + * Usage:
  101092. + * $ # for 4.5/4.6/C based 4.7
  101093. + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o randomize_layout_plugin.so randomize_layout_plugin.c
  101094. + * $ # for C++ based 4.7/4.8+
  101095. + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o randomize_layout_plugin.so randomize_layout_plugin.c
  101096. + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
  101097. + */
  101098. +
  101099. +#include "gcc-common.h"
  101100. +#include "randomize_layout_seed.h"
  101101. +
  101102. +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
  101103. +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
  101104. +#endif
  101105. +
  101106. +#define ORIG_TYPE_NAME(node) \
  101107. + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
  101108. +
  101109. +int plugin_is_GPL_compatible;
  101110. +
  101111. +static int performance_mode;
  101112. +
  101113. +static struct plugin_info randomize_layout_plugin_info = {
  101114. + .version = "201402201816",
  101115. + .help = "disable\t\t\tdo not activate plugin\n"
  101116. + "performance-mode\tenable cacheline-aware layout randomization\n"
  101117. +};
  101118. +
  101119. +/* from old Linux dcache.h */
  101120. +static inline unsigned long
  101121. +partial_name_hash(unsigned long c, unsigned long prevhash)
  101122. +{
  101123. + return (prevhash + (c << 4) + (c >> 4)) * 11;
  101124. +}
  101125. +static inline unsigned int
  101126. +name_hash(const unsigned char *name)
  101127. +{
  101128. + unsigned long hash = 0;
  101129. + unsigned int len = strlen((const char *)name);
  101130. + while (len--)
  101131. + hash = partial_name_hash(*name++, hash);
  101132. + return (unsigned int)hash;
  101133. +}
  101134. +
  101135. +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  101136. +{
  101137. + tree type;
  101138. +
  101139. + *no_add_attrs = true;
  101140. + if (TREE_CODE(*node) == FUNCTION_DECL) {
  101141. + error("%qE attribute does not apply to functions (%qF)", name, *node);
  101142. + return NULL_TREE;
  101143. + }
  101144. +
  101145. + if (TREE_CODE(*node) == PARM_DECL) {
  101146. + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
  101147. + return NULL_TREE;
  101148. + }
  101149. +
  101150. + if (TREE_CODE(*node) == VAR_DECL) {
  101151. + error("%qE attribute does not apply to variables (%qD)", name, *node);
  101152. + return NULL_TREE;
  101153. + }
  101154. +
  101155. + if (TYPE_P(*node)) {
  101156. + type = *node;
  101157. + } else {
  101158. + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
  101159. + type = TREE_TYPE(*node);
  101160. + }
  101161. +
  101162. + if (TREE_CODE(type) != RECORD_TYPE) {
  101163. + error("%qE attribute used on %qT applies to struct types only", name, type);
  101164. + return NULL_TREE;
  101165. + }
  101166. +
  101167. + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
  101168. + error("%qE attribute is already applied to the type %qT", name, type);
  101169. + return NULL_TREE;
  101170. + }
  101171. +
  101172. + *no_add_attrs = false;
  101173. +
  101174. + return NULL_TREE;
  101175. +}
  101176. +
  101177. +/* set on complete types that we don't need to inspect further at all */
  101178. +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  101179. +{
  101180. + *no_add_attrs = false;
  101181. + return NULL_TREE;
  101182. +}
  101183. +
  101184. +/*
  101185. + * set on types that we've performed a shuffle on, to prevent re-shuffling
  101186. + * this does not preclude us from inspecting its fields for potential shuffles
  101187. + */
  101188. +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  101189. +{
  101190. + *no_add_attrs = false;
  101191. + return NULL_TREE;
  101192. +}
  101193. +
  101194. +/*
  101195. + * 64bit variant of Bob Jenkins' public domain PRNG
  101196. + * 256 bits of internal state
  101197. + */
  101198. +
  101199. +typedef unsigned long long u64;
  101200. +
  101201. +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
  101202. +
  101203. +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
  101204. +static u64 ranval(ranctx *x) {
  101205. + u64 e = x->a - rot(x->b, 7);
  101206. + x->a = x->b ^ rot(x->c, 13);
  101207. + x->b = x->c + rot(x->d, 37);
  101208. + x->c = x->d + e;
  101209. + x->d = e + x->a;
  101210. + return x->d;
  101211. +}
  101212. +
  101213. +static void raninit(ranctx *x, u64 *seed) {
  101214. + int i;
  101215. +
  101216. + x->a = seed[0];
  101217. + x->b = seed[1];
  101218. + x->c = seed[2];
  101219. + x->d = seed[3];
  101220. +
  101221. + for (i=0; i < 30; ++i)
  101222. + (void)ranval(x);
  101223. +}
  101224. +
  101225. +static u64 shuffle_seed[4];
  101226. +
  101227. +struct partition_group {
  101228. + tree tree_start;
  101229. + unsigned long start;
  101230. + unsigned long length;
  101231. +};
  101232. +
  101233. +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
  101234. +{
  101235. + unsigned long i;
  101236. + unsigned long accum_size = 0;
  101237. + unsigned long accum_length = 0;
  101238. + unsigned long group_idx = 0;
  101239. +
  101240. + gcc_assert(length < INT_MAX);
  101241. +
  101242. + memset(size_groups, 0, sizeof(struct partition_group) * length);
  101243. +
  101244. + for (i = 0; i < length; i++) {
  101245. + if (size_groups[group_idx].tree_start == NULL_TREE) {
  101246. + size_groups[group_idx].tree_start = fields[i];
  101247. + size_groups[group_idx].start = i;
  101248. + accum_length = 0;
  101249. + accum_size = 0;
  101250. + }
  101251. + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
  101252. + accum_length++;
  101253. + if (accum_size >= 64) {
  101254. + size_groups[group_idx].length = accum_length;
  101255. + accum_length = 0;
  101256. + group_idx++;
  101257. + }
  101258. + }
  101259. +
  101260. + if (size_groups[group_idx].tree_start != NULL_TREE &&
  101261. + !size_groups[group_idx].length) {
  101262. + size_groups[group_idx].length = accum_length;
  101263. + group_idx++;
  101264. + }
  101265. +
  101266. + *num_groups = group_idx;
  101267. +}
  101268. +
  101269. +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
  101270. +{
  101271. + unsigned long i, x;
  101272. + struct partition_group size_group[length];
  101273. + unsigned long num_groups = 0;
  101274. + unsigned long randnum;
  101275. +
  101276. + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
  101277. + for (i = num_groups - 1; i > 0; i--) {
  101278. + struct partition_group tmp;
  101279. + randnum = ranval(prng_state) % (i + 1);
  101280. + tmp = size_group[i];
  101281. + size_group[i] = size_group[randnum];
  101282. + size_group[randnum] = tmp;
  101283. + }
  101284. +
  101285. + for (x = 0; x < num_groups; x++) {
  101286. + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
  101287. + tree tmp;
  101288. + if (DECL_BIT_FIELD_TYPE(newtree[i]))
  101289. + continue;
  101290. + randnum = ranval(prng_state) % (i + 1);
  101291. + // we could handle this case differently if desired
  101292. + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
  101293. + continue;
  101294. + tmp = newtree[i];
  101295. + newtree[i] = newtree[randnum];
  101296. + newtree[randnum] = tmp;
  101297. + }
  101298. + }
  101299. +}
  101300. +
  101301. +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
  101302. +{
  101303. + unsigned long i, randnum;
  101304. +
  101305. + for (i = length - 1; i > 0; i--) {
  101306. + tree tmp;
  101307. + randnum = ranval(prng_state) % (i + 1);
  101308. + tmp = newtree[i];
  101309. + newtree[i] = newtree[randnum];
  101310. + newtree[randnum] = tmp;
  101311. + }
  101312. +}
  101313. +
  101314. +/* modern in-place Fisher-Yates shuffle */
  101315. +static void shuffle(const_tree type, tree *newtree, unsigned long length)
  101316. +{
  101317. + unsigned long i;
  101318. + u64 seed[4];
  101319. + ranctx prng_state;
  101320. + const unsigned char *structname;
  101321. +
  101322. + if (length == 0)
  101323. + return;
  101324. +
  101325. + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
  101326. +
  101327. + structname = ORIG_TYPE_NAME(type);
  101328. +
  101329. +#ifdef __DEBUG_PLUGIN
  101330. + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
  101331. +#ifdef __DEBUG_VERBOSE
  101332. + debug_tree((tree)type);
  101333. +#endif
  101334. +#endif
  101335. +
  101336. + for (i = 0; i < 4; i++) {
  101337. + seed[i] = shuffle_seed[i];
  101338. + seed[i] ^= name_hash(structname);
  101339. + }
  101340. +
  101341. + raninit(&prng_state, (u64 *)&seed);
  101342. +
  101343. + if (performance_mode)
  101344. + performance_shuffle(newtree, length, &prng_state);
  101345. + else
  101346. + full_shuffle(newtree, length, &prng_state);
  101347. +}
  101348. +
  101349. +static bool is_flexible_array(const_tree field)
  101350. +{
  101351. + const_tree fieldtype;
  101352. + const_tree typesize;
  101353. + const_tree elemtype;
  101354. + const_tree elemsize;
  101355. +
  101356. + fieldtype = TREE_TYPE(field);
  101357. + typesize = TYPE_SIZE(fieldtype);
  101358. +
  101359. + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
  101360. + return false;
  101361. +
  101362. + elemtype = TREE_TYPE(fieldtype);
  101363. + elemsize = TYPE_SIZE(elemtype);
  101364. +
  101365. + /* size of type is represented in bits */
  101366. +
  101367. + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
  101368. + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
  101369. + return true;
  101370. +
  101371. + if (typesize != NULL_TREE &&
  101372. + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
  101373. + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
  101374. + return true;
  101375. +
  101376. + return false;
  101377. +}
  101378. +
  101379. +static int relayout_struct(tree type)
  101380. +{
  101381. + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
  101382. + unsigned long shuffle_length = num_fields;
  101383. + tree field;
  101384. + tree newtree[num_fields];
  101385. + unsigned long i;
  101386. + tree list;
  101387. + tree variant;
  101388. + expanded_location xloc;
  101389. +
  101390. + if (TYPE_FIELDS(type) == NULL_TREE)
  101391. + return 0;
  101392. +
  101393. + if (num_fields < 2)
  101394. + return 0;
  101395. +
  101396. + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
  101397. +
  101398. + gcc_assert(num_fields < INT_MAX);
  101399. +
  101400. + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
  101401. + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
  101402. + return 0;
  101403. +
  101404. + /* throw out any structs in uapi */
  101405. + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
  101406. +
  101407. + if (strstr(xloc.file, "/uapi/"))
  101408. + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
  101409. +
  101410. + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
  101411. + gcc_assert(TREE_CODE(field) == FIELD_DECL);
  101412. + newtree[i] = field;
  101413. + }
  101414. +
  101415. + /*
  101416. + * enforce that we don't randomize the layout of the last
  101417. + * element of a struct if it's a 0 or 1-length array
  101418. + * or a proper flexible array
  101419. + */
  101420. + if (is_flexible_array(newtree[num_fields - 1]))
  101421. + shuffle_length--;
  101422. +
  101423. + shuffle(type, (tree *)newtree, shuffle_length);
  101424. +
  101425. + /*
  101426. + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
  101427. + * as gcc provides no other way to detect such code
  101428. + */
  101429. + list = make_node(FIELD_DECL);
  101430. + TREE_CHAIN(list) = newtree[0];
  101431. + TREE_TYPE(list) = void_type_node;
  101432. + DECL_SIZE(list) = bitsize_zero_node;
  101433. + DECL_NONADDRESSABLE_P(list) = 1;
  101434. + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
  101435. + DECL_SIZE_UNIT(list) = size_zero_node;
  101436. + DECL_FIELD_OFFSET(list) = size_zero_node;
  101437. + // to satisfy the constify plugin
  101438. + TREE_READONLY(list) = 1;
  101439. +
  101440. + for (i = 0; i < num_fields - 1; i++)
  101441. + TREE_CHAIN(newtree[i]) = newtree[i+1];
  101442. + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
  101443. +
  101444. + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
  101445. + TYPE_FIELDS(variant) = list;
  101446. + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
  101447. + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
  101448. + // force a re-layout
  101449. + TYPE_SIZE(variant) = NULL_TREE;
  101450. + layout_type(variant);
  101451. + }
  101452. +
  101453. + return 1;
  101454. +}
  101455. +
  101456. +/* from constify plugin */
  101457. +static const_tree get_field_type(const_tree field)
  101458. +{
  101459. + return strip_array_types(TREE_TYPE(field));
  101460. +}
  101461. +
  101462. +/* from constify plugin */
  101463. +static bool is_fptr(const_tree fieldtype)
  101464. +{
  101465. + if (TREE_CODE(fieldtype) != POINTER_TYPE)
  101466. + return false;
  101467. +
  101468. + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
  101469. +}
  101470. +
  101471. +/* derived from constify plugin */
  101472. +static int is_pure_ops_struct(const_tree node)
  101473. +{
  101474. + const_tree field;
  101475. +
  101476. + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
  101477. +
  101478. + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
  101479. + const_tree fieldtype = get_field_type(field);
  101480. + enum tree_code code = TREE_CODE(fieldtype);
  101481. +
  101482. + if (node == fieldtype)
  101483. + continue;
  101484. +
  101485. + if (!is_fptr(fieldtype))
  101486. + return 0;
  101487. +
  101488. + if (code != RECORD_TYPE && code != UNION_TYPE)
  101489. + continue;
  101490. +
  101491. + if (!is_pure_ops_struct(fieldtype))
  101492. + return 0;
  101493. + }
  101494. +
  101495. + return 1;
  101496. +}
  101497. +
  101498. +static void randomize_type(tree type)
  101499. +{
  101500. + tree variant;
  101501. +
  101502. + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
  101503. +
  101504. + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
  101505. + return;
  101506. +
  101507. + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
  101508. + relayout_struct(type);
  101509. +
  101510. + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
  101511. + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
  101512. + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
  101513. + }
  101514. +#ifdef __DEBUG_PLUGIN
  101515. + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
  101516. +#ifdef __DEBUG_VERBOSE
  101517. + debug_tree(type);
  101518. +#endif
  101519. +#endif
  101520. +}
  101521. +
  101522. +static void randomize_layout_finish_decl(void *event_data, void *data)
  101523. +{
  101524. + tree decl = (tree)event_data;
  101525. + tree type;
  101526. +
  101527. + if (decl == NULL_TREE || decl == error_mark_node)
  101528. + return;
  101529. +
  101530. + type = TREE_TYPE(decl);
  101531. +
  101532. + if (TREE_CODE(decl) != VAR_DECL)
  101533. + return;
  101534. +
  101535. + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
  101536. + return;
  101537. +
  101538. + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
  101539. + return;
  101540. +
  101541. + relayout_decl(decl);
  101542. +}
  101543. +
  101544. +static void finish_type(void *event_data, void *data)
  101545. +{
  101546. + tree type = (tree)event_data;
  101547. +
  101548. + if (type == NULL_TREE || type == error_mark_node)
  101549. + return;
  101550. +
  101551. + if (TREE_CODE(type) != RECORD_TYPE)
  101552. + return;
  101553. +
  101554. + if (TYPE_FIELDS(type) == NULL_TREE)
  101555. + return;
  101556. +
  101557. + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
  101558. + return;
  101559. +
  101560. +#ifdef __DEBUG_PLUGIN
  101561. + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
  101562. +#endif
  101563. +#ifdef __DEBUG_VERBOSE
  101564. + debug_tree(type);
  101565. +#endif
  101566. + randomize_type(type);
  101567. +
  101568. + return;
  101569. +}
  101570. +
  101571. +static struct attribute_spec randomize_layout_attr = {
  101572. + .name = "randomize_layout",
  101573. + // related to args
  101574. + .min_length = 0,
  101575. + .max_length = 0,
  101576. + .decl_required = false,
  101577. + // need type declaration
  101578. + .type_required = true,
  101579. + .function_type_required = false,
  101580. + .handler = handle_randomize_layout_attr,
  101581. +#if BUILDING_GCC_VERSION >= 4007
  101582. + .affects_type_identity = true
  101583. +#endif
  101584. +};
  101585. +
  101586. +static struct attribute_spec no_randomize_layout_attr = {
  101587. + .name = "no_randomize_layout",
  101588. + // related to args
  101589. + .min_length = 0,
  101590. + .max_length = 0,
  101591. + .decl_required = false,
  101592. + // need type declaration
  101593. + .type_required = true,
  101594. + .function_type_required = false,
  101595. + .handler = handle_randomize_layout_attr,
  101596. +#if BUILDING_GCC_VERSION >= 4007
  101597. + .affects_type_identity = true
  101598. +#endif
  101599. +};
  101600. +
  101601. +static struct attribute_spec randomize_considered_attr = {
  101602. + .name = "randomize_considered",
  101603. + // related to args
  101604. + .min_length = 0,
  101605. + .max_length = 0,
  101606. + .decl_required = false,
  101607. + // need type declaration
  101608. + .type_required = true,
  101609. + .function_type_required = false,
  101610. + .handler = handle_randomize_considered_attr,
  101611. +#if BUILDING_GCC_VERSION >= 4007
  101612. + .affects_type_identity = false
  101613. +#endif
  101614. +};
  101615. +
  101616. +static struct attribute_spec randomize_performed_attr = {
  101617. + .name = "randomize_performed",
  101618. + // related to args
  101619. + .min_length = 0,
  101620. + .max_length = 0,
  101621. + .decl_required = false,
  101622. + // need type declaration
  101623. + .type_required = true,
  101624. + .function_type_required = false,
  101625. + .handler = handle_randomize_performed_attr,
  101626. +#if BUILDING_GCC_VERSION >= 4007
  101627. + .affects_type_identity = false
  101628. +#endif
  101629. +};
  101630. +
  101631. +static void register_attributes(void *event_data, void *data)
  101632. +{
  101633. + register_attribute(&randomize_layout_attr);
  101634. + register_attribute(&no_randomize_layout_attr);
  101635. + register_attribute(&randomize_considered_attr);
  101636. + register_attribute(&randomize_performed_attr);
  101637. +}
  101638. +
  101639. +static void check_bad_casts_in_constructor(tree var, tree init)
  101640. +{
  101641. + unsigned HOST_WIDE_INT idx;
  101642. + tree field, val;
  101643. + tree field_type, val_type;
  101644. +
  101645. + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
  101646. + if (TREE_CODE(val) == CONSTRUCTOR) {
  101647. + check_bad_casts_in_constructor(var, val);
  101648. + continue;
  101649. + }
  101650. +
  101651. + /* pipacs' plugin creates franken-arrays that differ from those produced by
  101652. + normal code which all have valid 'field' trees. work around this */
  101653. + if (field == NULL_TREE)
  101654. + continue;
  101655. + field_type = TREE_TYPE(field);
  101656. + val_type = TREE_TYPE(val);
  101657. +
  101658. + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
  101659. + continue;
  101660. +
  101661. + if (field_type == val_type)
  101662. + continue;
  101663. +
  101664. + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
  101665. + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
  101666. +
  101667. + if (field_type == void_type_node)
  101668. + continue;
  101669. + if (field_type == val_type)
  101670. + continue;
  101671. + if (TREE_CODE(val_type) != RECORD_TYPE)
  101672. + continue;
  101673. +
  101674. + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
  101675. + continue;
  101676. + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
  101677. + }
  101678. +}
  101679. +
  101680. +/* derived from the constify plugin */
  101681. +static void check_global_variables(void *event_data, void *data)
  101682. +{
  101683. + struct varpool_node *node;
  101684. + tree init;
  101685. +
  101686. + FOR_EACH_VARIABLE(node) {
  101687. + tree var = NODE_DECL(node);
  101688. + init = DECL_INITIAL(var);
  101689. + if (init == NULL_TREE)
  101690. + continue;
  101691. +
  101692. + if (TREE_CODE(init) != CONSTRUCTOR)
  101693. + continue;
  101694. +
  101695. + check_bad_casts_in_constructor(var, init);
  101696. + }
  101697. +}
  101698. +
  101699. +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
  101700. +{
  101701. + basic_block dom;
  101702. + gimple dom_stmt;
  101703. + gimple call_stmt;
  101704. + const_tree dom_lhs;
  101705. + const_tree poss_is_err_cond;
  101706. + const_tree poss_is_err_func;
  101707. + const_tree is_err_arg;
  101708. +
  101709. + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
  101710. + if (!dom)
  101711. + return false;
  101712. +
  101713. + dom_stmt = last_stmt(dom);
  101714. + if (!dom_stmt)
  101715. + return false;
  101716. +
  101717. + if (gimple_code(dom_stmt) != GIMPLE_COND)
  101718. + return false;
  101719. +
  101720. + if (gimple_cond_code(dom_stmt) != NE_EXPR)
  101721. + return false;
  101722. +
  101723. + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
  101724. + return false;
  101725. +
  101726. + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
  101727. +
  101728. + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
  101729. + return false;
  101730. +
  101731. + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
  101732. +
  101733. + if (gimple_code(call_stmt) != GIMPLE_CALL)
  101734. + return false;
  101735. +
  101736. + dom_lhs = gimple_get_lhs(call_stmt);
  101737. + poss_is_err_func = gimple_call_fndecl(call_stmt);
  101738. + if (!poss_is_err_func)
  101739. + return false;
  101740. + if (dom_lhs != poss_is_err_cond)
  101741. + return false;
  101742. + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
  101743. + return false;
  101744. +
  101745. + is_err_arg = gimple_call_arg(call_stmt, 0);
  101746. + if (!is_err_arg)
  101747. + return false;
  101748. +
  101749. + if (is_err_arg != rhs)
  101750. + return false;
  101751. +
  101752. + return true;
  101753. +}
  101754. +
  101755. +static void handle_local_var_initializers(void)
  101756. +{
  101757. + tree var;
  101758. + unsigned int i;
  101759. +
  101760. + FOR_EACH_LOCAL_DECL(cfun, i, var) {
  101761. + tree init = DECL_INITIAL(var);
  101762. + if (!init)
  101763. + continue;
  101764. + if (TREE_CODE(init) != CONSTRUCTOR)
  101765. + continue;
  101766. + check_bad_casts_in_constructor(var, init);
  101767. + }
  101768. +}
  101769. +
  101770. +/*
  101771. + * iterate over all statements to find "bad" casts:
  101772. + * those where the address of the start of a structure is cast
  101773. + * to a pointer of a structure of a different type, or a
  101774. + * structure pointer type is cast to a different structure pointer type
  101775. + */
  101776. +static unsigned int find_bad_casts(void)
  101777. +{
  101778. + basic_block bb;
  101779. +
  101780. + handle_local_var_initializers();
  101781. +
  101782. + FOR_ALL_BB_FN(bb, cfun) {
  101783. + gimple_stmt_iterator gsi;
  101784. +
  101785. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  101786. + gimple stmt;
  101787. + const_tree lhs;
  101788. + const_tree lhs_type;
  101789. + const_tree rhs1;
  101790. + const_tree rhs_type;
  101791. + const_tree ptr_lhs_type;
  101792. + const_tree ptr_rhs_type;
  101793. + const_tree op0;
  101794. + const_tree op0_type;
  101795. + enum tree_code rhs_code;
  101796. +
  101797. + stmt = gsi_stmt(gsi);
  101798. +
  101799. +#ifdef __DEBUG_PLUGIN
  101800. +#ifdef __DEBUG_VERBOSE
  101801. + debug_gimple_stmt(stmt);
  101802. + debug_tree(gimple_get_lhs(stmt));
  101803. +#endif
  101804. +#endif
  101805. +
  101806. + if (gimple_code(stmt) != GIMPLE_ASSIGN)
  101807. + continue;
  101808. +
  101809. +#ifdef __DEBUG_PLUGIN
  101810. +#ifdef __DEBUG_VERBOSE
  101811. + debug_tree(gimple_assign_rhs1(stmt));
  101812. +#endif
  101813. +#endif
  101814. +
  101815. + rhs_code = gimple_assign_rhs_code(stmt);
  101816. +
  101817. + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
  101818. + continue;
  101819. +
  101820. + lhs = gimple_get_lhs(stmt);
  101821. + lhs_type = TREE_TYPE(lhs);
  101822. + rhs1 = gimple_assign_rhs1(stmt);
  101823. + rhs_type = TREE_TYPE(rhs1);
  101824. +
  101825. + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
  101826. + TREE_CODE(lhs_type) != POINTER_TYPE)
  101827. + continue;
  101828. +
  101829. + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
  101830. + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
  101831. +
  101832. + if (ptr_rhs_type == void_type_node)
  101833. + continue;
  101834. +
  101835. + if (ptr_lhs_type == void_type_node)
  101836. + continue;
  101837. +
  101838. + if (dominated_by_is_err(rhs1, bb))
  101839. + continue;
  101840. +
  101841. + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
  101842. +#ifndef __DEBUG_PLUGIN
  101843. + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
  101844. +#endif
  101845. + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
  101846. + continue;
  101847. + }
  101848. +
  101849. + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
  101850. + continue;
  101851. +
  101852. + if (rhs_code == ADDR_EXPR) {
  101853. + op0 = TREE_OPERAND(rhs1, 0);
  101854. +
  101855. + if (op0 == NULL_TREE)
  101856. + continue;
  101857. +
  101858. + if (TREE_CODE(op0) != VAR_DECL)
  101859. + continue;
  101860. +
  101861. + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
  101862. + if (op0_type == ptr_lhs_type)
  101863. + continue;
  101864. +
  101865. +#ifndef __DEBUG_PLUGIN
  101866. + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
  101867. +#endif
  101868. + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
  101869. + } else {
  101870. + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
  101871. + /* skip bogus type casts introduced by container_of */
  101872. + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
  101873. + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
  101874. + continue;
  101875. +#ifndef __DEBUG_PLUGIN
  101876. + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
  101877. +#endif
  101878. + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
  101879. + }
  101880. +
  101881. + }
  101882. + }
  101883. + return 0;
  101884. +}
  101885. +
  101886. +#if BUILDING_GCC_VERSION >= 4009
  101887. +static const struct pass_data randomize_layout_bad_cast_data = {
  101888. +#else
  101889. +static struct gimple_opt_pass randomize_layout_bad_cast = {
  101890. + .pass = {
  101891. +#endif
  101892. + .type = GIMPLE_PASS,
  101893. + .name = "randomize_layout_bad_cast",
  101894. +#if BUILDING_GCC_VERSION >= 4008
  101895. + .optinfo_flags = OPTGROUP_NONE,
  101896. +#endif
  101897. +#if BUILDING_GCC_VERSION >= 4009
  101898. + .has_gate = false,
  101899. + .has_execute = true,
  101900. +#else
  101901. + .gate = NULL,
  101902. + .execute = find_bad_casts,
  101903. + .sub = NULL,
  101904. + .next = NULL,
  101905. + .static_pass_number = 0,
  101906. +#endif
  101907. + .tv_id = TV_NONE,
  101908. + .properties_required = PROP_cfg,
  101909. + .properties_provided = 0,
  101910. + .properties_destroyed = 0,
  101911. + .todo_flags_start = 0,
  101912. + .todo_flags_finish = TODO_dump_func
  101913. +#if BUILDING_GCC_VERSION < 4009
  101914. + }
  101915. +#endif
  101916. +};
  101917. +
  101918. +#if BUILDING_GCC_VERSION >= 4009
  101919. +namespace {
  101920. +class randomize_layout_bad_cast : public gimple_opt_pass {
  101921. +public:
  101922. + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
  101923. + unsigned int execute() { return find_bad_casts(); }
  101924. +};
  101925. +}
  101926. +#endif
  101927. +
  101928. +static struct opt_pass *make_randomize_layout_bad_cast(void)
  101929. +{
  101930. +#if BUILDING_GCC_VERSION >= 4009
  101931. + return new randomize_layout_bad_cast();
  101932. +#else
  101933. + return &randomize_layout_bad_cast.pass;
  101934. +#endif
  101935. +}
  101936. +
  101937. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  101938. +{
  101939. + int i;
  101940. + const char * const plugin_name = plugin_info->base_name;
  101941. + const int argc = plugin_info->argc;
  101942. + const struct plugin_argument * const argv = plugin_info->argv;
  101943. + bool enable = true;
  101944. + int obtained_seed = 0;
  101945. + struct register_pass_info randomize_layout_bad_cast_info;
  101946. +
  101947. + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
  101948. + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
  101949. + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
  101950. + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
  101951. +
  101952. + if (!plugin_default_version_check(version, &gcc_version)) {
  101953. + error(G_("incompatible gcc/plugin versions"));
  101954. + return 1;
  101955. + }
  101956. +
  101957. + if (strcmp(lang_hooks.name, "GNU C")) {
  101958. + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
  101959. + enable = false;
  101960. + }
  101961. +
  101962. + for (i = 0; i < argc; ++i) {
  101963. + if (!strcmp(argv[i].key, "disable")) {
  101964. + enable = false;
  101965. + continue;
  101966. + }
  101967. + if (!strcmp(argv[i].key, "performance-mode")) {
  101968. + performance_mode = 1;
  101969. + continue;
  101970. + }
  101971. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  101972. + }
  101973. +
  101974. + if (strlen(randstruct_seed) != 64) {
  101975. + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
  101976. + return 1;
  101977. + }
  101978. + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
  101979. + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
  101980. + if (obtained_seed != 4) {
  101981. + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
  101982. + return 1;
  101983. + }
  101984. +
  101985. + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
  101986. + if (enable) {
  101987. + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
  101988. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
  101989. + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
  101990. + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
  101991. + }
  101992. + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
  101993. +
  101994. + return 0;
  101995. +}
  101996. diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
  101997. new file mode 100644
  101998. index 0000000..92d3b0c
  101999. --- /dev/null
  102000. +++ b/tools/gcc/size_overflow_plugin/.gitignore
  102001. @@ -0,0 +1,2 @@
  102002. +size_overflow_hash.h
  102003. +size_overflow_hash_aux.h
  102004. diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
  102005. new file mode 100644
  102006. index 0000000..1ae2ed5
  102007. --- /dev/null
  102008. +++ b/tools/gcc/size_overflow_plugin/Makefile
  102009. @@ -0,0 +1,20 @@
  102010. +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
  102011. +always := $($(HOSTLIBS)-y)
  102012. +
  102013. +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
  102014. +
  102015. +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
  102016. +
  102017. +quiet_cmd_build_size_overflow_hash = GENHASH $@
  102018. + cmd_build_size_overflow_hash = \
  102019. + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
  102020. +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
  102021. + $(call if_changed,build_size_overflow_hash)
  102022. +
  102023. +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
  102024. + cmd_build_size_overflow_hash_aux = \
  102025. + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
  102026. +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
  102027. + $(call if_changed,build_size_overflow_hash_aux)
  102028. +
  102029. +targets += size_overflow_hash.h size_overflow_hash_aux.h
  102030. diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
  102031. new file mode 100644
  102032. index 0000000..12b1e3b
  102033. --- /dev/null
  102034. +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
  102035. @@ -0,0 +1,102 @@
  102036. +#!/bin/bash
  102037. +
  102038. +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
  102039. +
  102040. +header1="size_overflow_hash.h"
  102041. +database="size_overflow_hash.data"
  102042. +n=65536
  102043. +hashtable_name="size_overflow_hash"
  102044. +
  102045. +usage() {
  102046. +cat <<EOF
  102047. +usage: $0 options
  102048. +OPTIONS:
  102049. + -h|--help help
  102050. + -o header file
  102051. + -d database file
  102052. + -n hash array size
  102053. + -s name of the hash table
  102054. +EOF
  102055. + return 0
  102056. +}
  102057. +
  102058. +while true
  102059. +do
  102060. + case "$1" in
  102061. + -h|--help) usage && exit 0;;
  102062. + -n) n=$2; shift 2;;
  102063. + -o) header1="$2"; shift 2;;
  102064. + -d) database="$2"; shift 2;;
  102065. + -s) hashtable_name="$2"; shift 2;;
  102066. + --) shift 1; break ;;
  102067. + *) break ;;
  102068. + esac
  102069. +done
  102070. +
  102071. +create_defines() {
  102072. + for i in `seq 0 31`
  102073. + do
  102074. + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
  102075. + done
  102076. + echo >> "$header1"
  102077. +}
  102078. +
  102079. +create_structs() {
  102080. + rm -f "$header1"
  102081. +
  102082. + create_defines
  102083. +
  102084. + cat "$database" | while read data
  102085. + do
  102086. + data_array=($data)
  102087. + struct_hash_name="${data_array[0]}"
  102088. + funcn="${data_array[1]}"
  102089. + params="${data_array[2]}"
  102090. + next="${data_array[4]}"
  102091. +
  102092. + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
  102093. +
  102094. + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
  102095. + echo -en "\t.param\t= " >> "$header1"
  102096. + line=
  102097. + for param_num in ${params//-/ };
  102098. + do
  102099. + line="${line}PARAM"$param_num"|"
  102100. + done
  102101. +
  102102. + echo -e "${line%?},\n};\n" >> "$header1"
  102103. + done
  102104. +}
  102105. +
  102106. +create_headers() {
  102107. + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
  102108. +}
  102109. +
  102110. +create_array_elements() {
  102111. + index=0
  102112. + grep -v "nohasharray" $database | sort -n -k 4 | while read data
  102113. + do
  102114. + data_array=($data)
  102115. + i="${data_array[3]}"
  102116. + hash="${data_array[0]}"
  102117. + while [[ $index -lt $i ]]
  102118. + do
  102119. + echo -e "\t["$index"]\t= NULL," >> "$header1"
  102120. + index=$(($index + 1))
  102121. + done
  102122. + index=$(($index + 1))
  102123. + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
  102124. + done
  102125. + echo '};' >> $header1
  102126. +}
  102127. +
  102128. +size_overflow_plugin_dir=`dirname $header1`
  102129. +if [ "$size_overflow_plugin_dir" != '.' ]; then
  102130. + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
  102131. +fi
  102132. +
  102133. +create_structs
  102134. +create_headers
  102135. +create_array_elements
  102136. +
  102137. +exit 0
  102138. diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
  102139. new file mode 100644
  102140. index 0000000..3e8148c
  102141. --- /dev/null
  102142. +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
  102143. @@ -0,0 +1,790 @@
  102144. +/*
  102145. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  102146. + * Licensed under the GPL v2, or (at your option) v3
  102147. + *
  102148. + * Homepage:
  102149. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  102150. + *
  102151. + * Documentation:
  102152. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  102153. + *
  102154. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  102155. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  102156. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  102157. + *
  102158. + * Usage:
  102159. + * $ make
  102160. + * $ make run
  102161. + */
  102162. +
  102163. +#include "gcc-common.h"
  102164. +#include "size_overflow.h"
  102165. +
  102166. +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
  102167. +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
  102168. +
  102169. +// data for the size_overflow asm stmt
  102170. +struct asm_data {
  102171. + gimple def_stmt;
  102172. + tree input;
  102173. + tree output;
  102174. +};
  102175. +
  102176. +#if BUILDING_GCC_VERSION <= 4007
  102177. +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
  102178. +#else
  102179. +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
  102180. +#endif
  102181. +{
  102182. + tree list;
  102183. +#if BUILDING_GCC_VERSION <= 4007
  102184. + VEC(tree, gc) *vec_list = NULL;
  102185. +#else
  102186. + vec<tree, va_gc> *vec_list = NULL;
  102187. +#endif
  102188. +
  102189. + list = build_tree_list(NULL_TREE, string);
  102190. + list = chainon(NULL_TREE, build_tree_list(list, io));
  102191. +#if BUILDING_GCC_VERSION <= 4007
  102192. + VEC_safe_push(tree, gc, vec_list, list);
  102193. +#else
  102194. + vec_safe_push(vec_list, list);
  102195. +#endif
  102196. + return vec_list;
  102197. +}
  102198. +
  102199. +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
  102200. +{
  102201. + gimple asm_stmt;
  102202. + gimple_stmt_iterator gsi;
  102203. +#if BUILDING_GCC_VERSION <= 4007
  102204. + VEC(tree, gc) *input, *output = NULL;
  102205. +#else
  102206. + vec<tree, va_gc> *input, *output = NULL;
  102207. +#endif
  102208. +
  102209. + input = create_asm_io_list(str_input, asm_data->input);
  102210. +
  102211. + if (asm_data->output)
  102212. + output = create_asm_io_list(str_output, asm_data->output);
  102213. +
  102214. + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
  102215. + gsi = gsi_for_stmt(asm_data->def_stmt);
  102216. + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
  102217. +
  102218. + if (asm_data->output)
  102219. + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
  102220. +}
  102221. +
  102222. +static void replace_call_lhs(const struct asm_data *asm_data)
  102223. +{
  102224. + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
  102225. + update_stmt(asm_data->def_stmt);
  102226. + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
  102227. +}
  102228. +
  102229. +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
  102230. +{
  102231. + enum mark cur_fndecl_attr;
  102232. + gimple phi = get_def_stmt(result);
  102233. + unsigned int i, n = gimple_phi_num_args(phi);
  102234. +
  102235. + pointer_set_insert(visited, phi);
  102236. + for (i = 0; i < n; i++) {
  102237. + tree arg = gimple_phi_arg_def(phi, i);
  102238. +
  102239. + cur_fndecl_attr = search_intentional(visited, arg);
  102240. + if (cur_fndecl_attr != MARK_NO)
  102241. + return cur_fndecl_attr;
  102242. + }
  102243. + return MARK_NO;
  102244. +}
  102245. +
  102246. +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
  102247. +{
  102248. + enum mark cur_fndecl_attr;
  102249. + const_tree rhs1, rhs2;
  102250. + gimple def_stmt = get_def_stmt(lhs);
  102251. +
  102252. + rhs1 = gimple_assign_rhs1(def_stmt);
  102253. + rhs2 = gimple_assign_rhs2(def_stmt);
  102254. +
  102255. + cur_fndecl_attr = search_intentional(visited, rhs1);
  102256. + if (cur_fndecl_attr != MARK_NO)
  102257. + return cur_fndecl_attr;
  102258. + return search_intentional(visited, rhs2);
  102259. +}
  102260. +
  102261. +// Look up the intentional_overflow attribute on the caller and the callee functions.
  102262. +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
  102263. +{
  102264. + const_gimple def_stmt;
  102265. +
  102266. + if (TREE_CODE(lhs) != SSA_NAME)
  102267. + return get_intentional_attr_type(lhs);
  102268. +
  102269. + def_stmt = get_def_stmt(lhs);
  102270. + if (!def_stmt)
  102271. + return MARK_NO;
  102272. +
  102273. + if (pointer_set_contains(visited, def_stmt))
  102274. + return MARK_NO;
  102275. +
  102276. + switch (gimple_code(def_stmt)) {
  102277. + case GIMPLE_NOP:
  102278. + return search_intentional(visited, SSA_NAME_VAR(lhs));
  102279. + case GIMPLE_ASM:
  102280. + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
  102281. + return MARK_TURN_OFF;
  102282. + return MARK_NO;
  102283. + case GIMPLE_CALL:
  102284. + return MARK_NO;
  102285. + case GIMPLE_PHI:
  102286. + return search_intentional_phi(visited, lhs);
  102287. + case GIMPLE_ASSIGN:
  102288. + switch (gimple_num_ops(def_stmt)) {
  102289. + case 2:
  102290. + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
  102291. + case 3:
  102292. + return search_intentional_binary(visited, lhs);
  102293. + }
  102294. + case GIMPLE_RETURN:
  102295. + return MARK_NO;
  102296. + default:
  102297. + debug_gimple_stmt((gimple)def_stmt);
  102298. + error("%s: unknown gimple code", __func__);
  102299. + gcc_unreachable();
  102300. + }
  102301. +}
  102302. +
  102303. +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
  102304. +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
  102305. +{
  102306. + const_tree fndecl;
  102307. + struct pointer_set_t *visited;
  102308. + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
  102309. +
  102310. + fndecl = get_interesting_orig_fndecl(stmt, argnum);
  102311. + if (is_end_intentional_intentional_attr(fndecl, argnum))
  102312. + decl_attr = MARK_NOT_INTENTIONAL;
  102313. + else if (is_yes_intentional_attr(fndecl, argnum))
  102314. + decl_attr = MARK_YES;
  102315. + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
  102316. + return MARK_TURN_OFF;
  102317. + }
  102318. +
  102319. + visited = pointer_set_create();
  102320. + cur_fndecl_attr = search_intentional(visited, arg);
  102321. + pointer_set_destroy(visited);
  102322. +
  102323. + switch (cur_fndecl_attr) {
  102324. + case MARK_NO:
  102325. + case MARK_TURN_OFF:
  102326. + return cur_fndecl_attr;
  102327. + default:
  102328. + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
  102329. + return MARK_YES;
  102330. + }
  102331. +}
  102332. +
  102333. +static void check_missing_size_overflow_attribute(tree var)
  102334. +{
  102335. + tree orig_fndecl;
  102336. + unsigned int num;
  102337. +
  102338. + if (is_a_return_check(var))
  102339. + orig_fndecl = DECL_ORIGIN(var);
  102340. + else
  102341. + orig_fndecl = DECL_ORIGIN(current_function_decl);
  102342. +
  102343. + num = get_function_num(var, orig_fndecl);
  102344. + if (num == CANNOT_FIND_ARG)
  102345. + return;
  102346. +
  102347. + is_missing_function(orig_fndecl, num);
  102348. +}
  102349. +
  102350. +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
  102351. +{
  102352. + gimple phi = get_def_stmt(result);
  102353. + unsigned int i, n = gimple_phi_num_args(phi);
  102354. +
  102355. + pointer_set_insert(visited, phi);
  102356. + for (i = 0; i < n; i++) {
  102357. + tree arg = gimple_phi_arg_def(phi, i);
  102358. +
  102359. + search_size_overflow_attribute(visited, arg);
  102360. + }
  102361. +}
  102362. +
  102363. +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
  102364. +{
  102365. + const_gimple def_stmt = get_def_stmt(lhs);
  102366. + tree rhs1, rhs2;
  102367. +
  102368. + rhs1 = gimple_assign_rhs1(def_stmt);
  102369. + rhs2 = gimple_assign_rhs2(def_stmt);
  102370. +
  102371. + search_size_overflow_attribute(visited, rhs1);
  102372. + search_size_overflow_attribute(visited, rhs2);
  102373. +}
  102374. +
  102375. +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
  102376. +{
  102377. + const_gimple def_stmt;
  102378. +
  102379. + if (TREE_CODE(lhs) == PARM_DECL) {
  102380. + check_missing_size_overflow_attribute(lhs);
  102381. + return;
  102382. + }
  102383. +
  102384. + def_stmt = get_def_stmt(lhs);
  102385. + if (!def_stmt)
  102386. + return;
  102387. +
  102388. + if (pointer_set_insert(visited, def_stmt))
  102389. + return;
  102390. +
  102391. + switch (gimple_code(def_stmt)) {
  102392. + case GIMPLE_NOP:
  102393. + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
  102394. + case GIMPLE_ASM:
  102395. + return;
  102396. + case GIMPLE_CALL: {
  102397. + tree fndecl = gimple_call_fndecl(def_stmt);
  102398. +
  102399. + if (fndecl == NULL_TREE)
  102400. + return;
  102401. + check_missing_size_overflow_attribute(fndecl);
  102402. + return;
  102403. + }
  102404. + case GIMPLE_PHI:
  102405. + return search_size_overflow_attribute_phi(visited, lhs);
  102406. + case GIMPLE_ASSIGN:
  102407. + switch (gimple_num_ops(def_stmt)) {
  102408. + case 2:
  102409. + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
  102410. + case 3:
  102411. + return search_size_overflow_attribute_binary(visited, lhs);
  102412. + }
  102413. + default:
  102414. + debug_gimple_stmt((gimple)def_stmt);
  102415. + error("%s: unknown gimple code", __func__);
  102416. + gcc_unreachable();
  102417. + }
  102418. +}
  102419. +
  102420. +// Search missing entries in the hash table (invoked from the gimple pass)
  102421. +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
  102422. +{
  102423. + tree fndecl = NULL_TREE;
  102424. + tree lhs;
  102425. + struct pointer_set_t *visited;
  102426. +
  102427. + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
  102428. + return;
  102429. +
  102430. + if (num == 0) {
  102431. + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
  102432. + lhs = gimple_return_retval(stmt);
  102433. + } else {
  102434. + gcc_assert(is_gimple_call(stmt));
  102435. + lhs = gimple_call_arg(stmt, num - 1);
  102436. + fndecl = gimple_call_fndecl(stmt);
  102437. + }
  102438. +
  102439. + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
  102440. + return;
  102441. +
  102442. + visited = pointer_set_create();
  102443. + search_size_overflow_attribute(visited, lhs);
  102444. + pointer_set_destroy(visited);
  102445. +}
  102446. +
  102447. +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
  102448. +{
  102449. + gimple_stmt_iterator gsi;
  102450. + gimple assign;
  102451. +
  102452. + assign = gimple_build_assign(asm_data->input, asm_data->output);
  102453. + gsi = gsi_for_stmt(stmt);
  102454. + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
  102455. + asm_data->def_stmt = assign;
  102456. +
  102457. + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
  102458. + asm_data->output = make_ssa_name(asm_data->output, stmt);
  102459. + if (gimple_code(stmt) == GIMPLE_RETURN)
  102460. + gimple_return_set_retval(stmt, asm_data->output);
  102461. + else
  102462. + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
  102463. + update_stmt(stmt);
  102464. +}
  102465. +
  102466. +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
  102467. +{
  102468. + const char *fn_name;
  102469. + char *asm_comment;
  102470. + unsigned int len;
  102471. +
  102472. + if (argnum == 0)
  102473. + fn_name = DECL_NAME_POINTER(current_function_decl);
  102474. + else
  102475. + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
  102476. +
  102477. + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
  102478. + gcc_assert(len > 0);
  102479. +
  102480. + return asm_comment;
  102481. +}
  102482. +
  102483. +static const char *convert_mark_to_str(enum mark mark)
  102484. +{
  102485. + switch (mark) {
  102486. + case MARK_NO:
  102487. + return OK_ASM_STR;
  102488. + case MARK_YES:
  102489. + case MARK_NOT_INTENTIONAL:
  102490. + return YES_ASM_STR;
  102491. + case MARK_TURN_OFF:
  102492. + return TURN_OFF_ASM_STR;
  102493. + }
  102494. +
  102495. + gcc_unreachable();
  102496. +}
  102497. +
  102498. +/* Create the input of the size_overflow asm stmt.
  102499. + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
  102500. + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
  102501. + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
  102502. + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
  102503. + */
  102504. +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
  102505. +{
  102506. + if (!asm_data->def_stmt) {
  102507. + asm_data->input = NULL_TREE;
  102508. + return;
  102509. + }
  102510. +
  102511. + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
  102512. + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
  102513. +
  102514. + switch (gimple_code(asm_data->def_stmt)) {
  102515. + case GIMPLE_ASSIGN:
  102516. + case GIMPLE_CALL:
  102517. + replace_call_lhs(asm_data);
  102518. + break;
  102519. + case GIMPLE_PHI:
  102520. + create_output_from_phi(stmt, argnum, asm_data);
  102521. + break;
  102522. + case GIMPLE_NOP: {
  102523. + enum mark mark;
  102524. + const char *mark_str;
  102525. + char *asm_comment;
  102526. +
  102527. + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
  102528. +
  102529. + asm_data->input = asm_data->output;
  102530. + asm_data->output = NULL;
  102531. + asm_data->def_stmt = stmt;
  102532. +
  102533. + mark_str = convert_mark_to_str(mark);
  102534. + asm_comment = create_asm_comment(argnum, stmt, mark_str);
  102535. +
  102536. + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
  102537. + free(asm_comment);
  102538. + asm_data->input = NULL_TREE;
  102539. + break;
  102540. + }
  102541. + case GIMPLE_ASM:
  102542. + if (is_size_overflow_asm(asm_data->def_stmt)) {
  102543. + asm_data->input = NULL_TREE;
  102544. + break;
  102545. + }
  102546. + default:
  102547. + debug_gimple_stmt(asm_data->def_stmt);
  102548. + gcc_unreachable();
  102549. + }
  102550. +}
  102551. +
  102552. +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
  102553. + * is of the right kind create the appropriate size_overflow asm stmts:
  102554. + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
  102555. + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
  102556. + */
  102557. +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
  102558. +{
  102559. + struct asm_data asm_data;
  102560. + const char *mark_str;
  102561. + char *asm_comment;
  102562. + enum mark mark;
  102563. +
  102564. + if (is_gimple_constant(output_node))
  102565. + return;
  102566. +
  102567. + asm_data.output = output_node;
  102568. + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
  102569. + if (mark != MARK_TURN_OFF)
  102570. + search_missing_size_overflow_attribute_gimple(stmt, argnum);
  102571. +
  102572. + asm_data.def_stmt = get_def_stmt(asm_data.output);
  102573. + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
  102574. + return;
  102575. +
  102576. + create_asm_input(stmt, argnum, &asm_data);
  102577. + if (asm_data.input == NULL_TREE)
  102578. + return;
  102579. +
  102580. + mark_str = convert_mark_to_str(mark);
  102581. + asm_comment = create_asm_comment(argnum, stmt, mark_str);
  102582. + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
  102583. + free(asm_comment);
  102584. +}
  102585. +
  102586. +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
  102587. +static bool create_mark_asm(gimple stmt, enum mark mark)
  102588. +{
  102589. + struct asm_data asm_data;
  102590. + const char *asm_str;
  102591. +
  102592. + switch (mark) {
  102593. + case MARK_TURN_OFF:
  102594. + asm_str = TURN_OFF_ASM_STR;
  102595. + break;
  102596. + case MARK_NOT_INTENTIONAL:
  102597. + case MARK_YES:
  102598. + asm_str = YES_ASM_STR;
  102599. + break;
  102600. + default:
  102601. + gcc_unreachable();
  102602. + }
  102603. +
  102604. + asm_data.def_stmt = stmt;
  102605. + asm_data.output = gimple_call_lhs(stmt);
  102606. +
  102607. + if (asm_data.output == NULL_TREE) {
  102608. + asm_data.input = gimple_call_arg(stmt, 0);
  102609. + if (is_gimple_constant(asm_data.input))
  102610. + return false;
  102611. + asm_data.output = NULL;
  102612. + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
  102613. + return true;
  102614. + }
  102615. +
  102616. + create_asm_input(stmt, 0, &asm_data);
  102617. + gcc_assert(asm_data.input != NULL_TREE);
  102618. +
  102619. + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
  102620. + return true;
  102621. +}
  102622. +
  102623. +static bool is_from_cast(const_tree node)
  102624. +{
  102625. + gimple def_stmt = get_def_stmt(node);
  102626. +
  102627. + if (!def_stmt)
  102628. + return false;
  102629. +
  102630. + if (gimple_assign_cast_p(def_stmt))
  102631. + return true;
  102632. +
  102633. + return false;
  102634. +}
  102635. +
  102636. +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
  102637. +static bool skip_ptr_minus(gimple stmt)
  102638. +{
  102639. + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
  102640. +
  102641. + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
  102642. + return false;
  102643. +
  102644. + rhs1 = gimple_assign_rhs1(stmt);
  102645. + if (!is_from_cast(rhs1))
  102646. + return false;
  102647. +
  102648. + rhs2 = gimple_assign_rhs2(stmt);
  102649. + if (!is_from_cast(rhs2))
  102650. + return false;
  102651. +
  102652. + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
  102653. + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
  102654. +
  102655. + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
  102656. + return false;
  102657. +
  102658. + create_mark_asm(stmt, MARK_YES);
  102659. + return true;
  102660. +}
  102661. +
  102662. +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
  102663. +{
  102664. + gimple def_stmt;
  102665. +
  102666. + def_stmt = get_def_stmt(lhs);
  102667. + if (!def_stmt)
  102668. + return;
  102669. +
  102670. + if (pointer_set_insert(visited, def_stmt))
  102671. + return;
  102672. +
  102673. + switch (gimple_code(def_stmt)) {
  102674. + case GIMPLE_NOP:
  102675. + case GIMPLE_ASM:
  102676. + case GIMPLE_CALL:
  102677. + break;
  102678. + case GIMPLE_PHI: {
  102679. + unsigned int i, n = gimple_phi_num_args(def_stmt);
  102680. +
  102681. + pointer_set_insert(visited, def_stmt);
  102682. +
  102683. + for (i = 0; i < n; i++) {
  102684. + tree arg = gimple_phi_arg_def(def_stmt, i);
  102685. +
  102686. + walk_use_def_ptr(visited, arg);
  102687. + }
  102688. + }
  102689. + case GIMPLE_ASSIGN:
  102690. + switch (gimple_num_ops(def_stmt)) {
  102691. + case 2:
  102692. + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
  102693. + return;
  102694. + case 3:
  102695. + if (skip_ptr_minus(def_stmt))
  102696. + return;
  102697. +
  102698. + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
  102699. + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
  102700. + return;
  102701. + default:
  102702. + return;
  102703. + }
  102704. + default:
  102705. + debug_gimple_stmt((gimple)def_stmt);
  102706. + error("%s: unknown gimple code", __func__);
  102707. + gcc_unreachable();
  102708. + }
  102709. +}
  102710. +
  102711. +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
  102712. +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
  102713. +{
  102714. + struct pointer_set_t *visited;
  102715. +
  102716. + visited = pointer_set_create();
  102717. + walk_use_def_ptr(visited, arg);
  102718. + pointer_set_destroy(visited);
  102719. +}
  102720. +
  102721. +// Determine the return value and insert the asm stmt to mark the return stmt.
  102722. +static void insert_asm_ret(gimple stmt)
  102723. +{
  102724. + tree ret;
  102725. +
  102726. + ret = gimple_return_retval(stmt);
  102727. + create_size_overflow_asm(stmt, ret, 0);
  102728. +}
  102729. +
  102730. +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
  102731. +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
  102732. +{
  102733. + tree arg;
  102734. + unsigned int argnum;
  102735. +
  102736. + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
  102737. + gcc_assert(argnum != 0);
  102738. + if (argnum == CANNOT_FIND_ARG)
  102739. + return;
  102740. +
  102741. + arg = gimple_call_arg(stmt, argnum - 1);
  102742. + gcc_assert(arg != NULL_TREE);
  102743. +
  102744. + // skip all ptr - ptr expressions
  102745. + insert_mark_not_intentional_asm_at_ptr(arg);
  102746. +
  102747. + create_size_overflow_asm(stmt, arg, argnum);
  102748. +}
  102749. +
  102750. +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
  102751. +static void set_argnum_attribute(const_tree attr, bool *argnums)
  102752. +{
  102753. + unsigned int argnum;
  102754. + tree attr_value;
  102755. +
  102756. + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
  102757. + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
  102758. + argnums[argnum] = true;
  102759. + }
  102760. +}
  102761. +
  102762. +// If a function arg or the return value is in the hash table then set its index in the array.
  102763. +static void set_argnum_hash(tree fndecl, bool *argnums)
  102764. +{
  102765. + unsigned int num;
  102766. + const struct size_overflow_hash *hash;
  102767. +
  102768. + hash = get_function_hash(DECL_ORIGIN(fndecl));
  102769. + if (!hash)
  102770. + return;
  102771. +
  102772. + for (num = 0; num <= MAX_PARAM; num++) {
  102773. + if (!(hash->param & (1U << num)))
  102774. + continue;
  102775. +
  102776. + argnums[num] = true;
  102777. + }
  102778. +}
  102779. +
  102780. +static bool is_all_the_argnums_empty(bool *argnums)
  102781. +{
  102782. + unsigned int i;
  102783. +
  102784. + for (i = 0; i <= MAX_PARAM; i++)
  102785. + if (argnums[i])
  102786. + return false;
  102787. + return true;
  102788. +}
  102789. +
  102790. +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
  102791. +static void search_interesting_args(tree fndecl, bool *argnums)
  102792. +{
  102793. + const_tree attr;
  102794. +
  102795. + set_argnum_hash(fndecl, argnums);
  102796. + if (!is_all_the_argnums_empty(argnums))
  102797. + return;
  102798. +
  102799. + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
  102800. + if (attr && TREE_VALUE(attr))
  102801. + set_argnum_attribute(attr, argnums);
  102802. +}
  102803. +
  102804. +/*
  102805. + * Look up the intentional_overflow attribute that turns off ipa based duplication
  102806. + * on the callee function.
  102807. + */
  102808. +static bool is_mark_turn_off_attribute(gimple stmt)
  102809. +{
  102810. + enum mark mark;
  102811. + const_tree fndecl = gimple_call_fndecl(stmt);
  102812. +
  102813. + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
  102814. + if (mark == MARK_TURN_OFF)
  102815. + return true;
  102816. + return false;
  102817. +}
  102818. +
  102819. +// If the argument(s) of the callee function is/are in the hash table or are marked by an attribute then mark the call stmt with an asm stmt
  102820. +static void handle_interesting_function(gimple stmt)
  102821. +{
  102822. + unsigned int argnum;
  102823. + tree fndecl;
  102824. + bool orig_argnums[MAX_PARAM + 1] = {false};
  102825. +
  102826. + if (gimple_call_num_args(stmt) == 0)
  102827. + return;
  102828. + fndecl = gimple_call_fndecl(stmt);
  102829. + if (fndecl == NULL_TREE)
  102830. + return;
  102831. + fndecl = DECL_ORIGIN(fndecl);
  102832. +
  102833. + if (is_mark_turn_off_attribute(stmt)) {
  102834. + create_mark_asm(stmt, MARK_TURN_OFF);
  102835. + return;
  102836. + }
  102837. +
  102838. + search_interesting_args(fndecl, orig_argnums);
  102839. +
  102840. + for (argnum = 1; argnum < MAX_PARAM; argnum++)
  102841. + if (orig_argnums[argnum])
  102842. + insert_asm_arg(stmt, argnum);
  102843. +}
  102844. +
  102845. +// If the return value of the caller function is in hash table (its index is 0) then mark the return stmt with an asm stmt
  102846. +static void handle_interesting_ret(gimple stmt)
  102847. +{
  102848. + bool orig_argnums[MAX_PARAM + 1] = {false};
  102849. +
  102850. + search_interesting_args(current_function_decl, orig_argnums);
  102851. +
  102852. + if (orig_argnums[0])
  102853. + insert_asm_ret(stmt);
  102854. +}
  102855. +
  102856. +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
  102857. +static unsigned int search_interesting_functions(void)
  102858. +{
  102859. + basic_block bb;
  102860. +
  102861. + FOR_ALL_BB_FN(bb, cfun) {
  102862. + gimple_stmt_iterator gsi;
  102863. +
  102864. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  102865. + gimple stmt = gsi_stmt(gsi);
  102866. +
  102867. + if (is_size_overflow_asm(stmt))
  102868. + continue;
  102869. +
  102870. + if (is_gimple_call(stmt))
  102871. + handle_interesting_function(stmt);
  102872. + else if (gimple_code(stmt) == GIMPLE_RETURN)
  102873. + handle_interesting_ret(stmt);
  102874. + }
  102875. + }
  102876. + return 0;
  102877. +}
  102878. +
  102879. +/*
  102880. + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
  102881. + * this pass inserts asm stmts to mark the interesting args
  102882. + * that the ipa pass will detect and insert the size overflow checks for.
  102883. + */
  102884. +#if BUILDING_GCC_VERSION >= 4009
  102885. +static const struct pass_data insert_size_overflow_asm_pass_data = {
  102886. +#else
  102887. +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
  102888. + .pass = {
  102889. +#endif
  102890. + .type = GIMPLE_PASS,
  102891. + .name = "insert_size_overflow_asm",
  102892. +#if BUILDING_GCC_VERSION >= 4008
  102893. + .optinfo_flags = OPTGROUP_NONE,
  102894. +#endif
  102895. +#if BUILDING_GCC_VERSION >= 4009
  102896. + .has_gate = false,
  102897. + .has_execute = true,
  102898. +#else
  102899. + .gate = NULL,
  102900. + .execute = search_interesting_functions,
  102901. + .sub = NULL,
  102902. + .next = NULL,
  102903. + .static_pass_number = 0,
  102904. +#endif
  102905. + .tv_id = TV_NONE,
  102906. + .properties_required = PROP_cfg,
  102907. + .properties_provided = 0,
  102908. + .properties_destroyed = 0,
  102909. + .todo_flags_start = 0,
  102910. + .todo_flags_finish = TODO_dump_func | TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
  102911. +#if BUILDING_GCC_VERSION < 4009
  102912. + }
  102913. +#endif
  102914. +};
  102915. +
  102916. +#if BUILDING_GCC_VERSION >= 4009
  102917. +namespace {
  102918. +class insert_size_overflow_asm_pass : public gimple_opt_pass {
  102919. +public:
  102920. + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
  102921. + unsigned int execute() { return search_interesting_functions(); }
  102922. +};
  102923. +}
  102924. +#endif
  102925. +
  102926. +struct opt_pass *make_insert_size_overflow_asm_pass(void)
  102927. +{
  102928. +#if BUILDING_GCC_VERSION >= 4009
  102929. + return new insert_size_overflow_asm_pass();
  102930. +#else
  102931. + return &insert_size_overflow_asm_pass.pass;
  102932. +#endif
  102933. +}
  102934. diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
  102935. new file mode 100644
  102936. index 0000000..880cd86
  102937. --- /dev/null
  102938. +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
  102939. @@ -0,0 +1,897 @@
  102940. +/*
  102941. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  102942. + * Licensed under the GPL v2, or (at your option) v3
  102943. + *
  102944. + * Homepage:
  102945. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  102946. + *
  102947. + * Documentation:
  102948. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  102949. + *
  102950. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  102951. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  102952. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  102953. + *
  102954. + * Usage:
  102955. + * $ make
  102956. + * $ make run
  102957. + */
  102958. +
  102959. +#include "gcc-common.h"
  102960. +#include "size_overflow.h"
  102961. +
  102962. +#define MIN_CHECK true
  102963. +#define MAX_CHECK false
  102964. +
  102965. +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
  102966. +{
  102967. + const_tree type;
  102968. + tree new_type;
  102969. +
  102970. + gcc_assert(node != NULL_TREE);
  102971. +
  102972. + type = TREE_TYPE(node);
  102973. +
  102974. + if (pointer_set_contains(visited->my_stmts, stmt))
  102975. + return TREE_TYPE(node);
  102976. +
  102977. + switch (TYPE_MODE(type)) {
  102978. + case QImode:
  102979. + new_type = size_overflow_type_HI;
  102980. + break;
  102981. + case HImode:
  102982. + new_type = size_overflow_type_SI;
  102983. + break;
  102984. + case SImode:
  102985. + new_type = size_overflow_type_DI;
  102986. + break;
  102987. + case DImode:
  102988. + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
  102989. + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
  102990. + else
  102991. + new_type = size_overflow_type_TI;
  102992. + break;
  102993. + case TImode:
  102994. + gcc_assert(!TYPE_UNSIGNED(type));
  102995. + new_type = size_overflow_type_TI;
  102996. + break;
  102997. + default:
  102998. + debug_tree((tree)node);
  102999. + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
  103000. + gcc_unreachable();
  103001. + }
  103002. +
  103003. + if (TYPE_QUALS(type) != 0)
  103004. + return build_qualified_type(new_type, TYPE_QUALS(type));
  103005. + return new_type;
  103006. +}
  103007. +
  103008. +static tree get_lhs(const_gimple stmt)
  103009. +{
  103010. + switch (gimple_code(stmt)) {
  103011. + case GIMPLE_ASSIGN:
  103012. + case GIMPLE_CALL:
  103013. + return gimple_get_lhs(stmt);
  103014. + case GIMPLE_PHI:
  103015. + return gimple_phi_result(stmt);
  103016. + default:
  103017. + return NULL_TREE;
  103018. + }
  103019. +}
  103020. +
  103021. +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
  103022. +{
  103023. + gimple_stmt_iterator gsi;
  103024. + tree lhs;
  103025. + gimple new_stmt;
  103026. +
  103027. + if (rhs == NULL_TREE)
  103028. + return NULL_TREE;
  103029. +
  103030. + gsi = gsi_for_stmt(stmt);
  103031. + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
  103032. + pointer_set_insert(visited->my_stmts, new_stmt);
  103033. +
  103034. + lhs = get_lhs(new_stmt);
  103035. + gcc_assert(lhs != NULL_TREE);
  103036. + return lhs;
  103037. +}
  103038. +
  103039. +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
  103040. +{
  103041. + tree lhs, dst_type;
  103042. + gimple_stmt_iterator gsi;
  103043. +
  103044. + if (rhs1 == NULL_TREE) {
  103045. + debug_gimple_stmt(oldstmt);
  103046. + error("%s: rhs1 is NULL_TREE", __func__);
  103047. + gcc_unreachable();
  103048. + }
  103049. +
  103050. + switch (gimple_code(oldstmt)) {
  103051. + case GIMPLE_ASM:
  103052. + lhs = rhs1;
  103053. + break;
  103054. + case GIMPLE_CALL:
  103055. + case GIMPLE_ASSIGN:
  103056. + lhs = gimple_get_lhs(oldstmt);
  103057. + break;
  103058. + default:
  103059. + debug_gimple_stmt(oldstmt);
  103060. + gcc_unreachable();
  103061. + }
  103062. +
  103063. + gsi = gsi_for_stmt(oldstmt);
  103064. + pointer_set_insert(visited->stmts, oldstmt);
  103065. + if (lookup_stmt_eh_lp(oldstmt) != 0) {
  103066. + basic_block next_bb, cur_bb;
  103067. + const_edge e;
  103068. +
  103069. + gcc_assert(before == false);
  103070. + gcc_assert(stmt_can_throw_internal(oldstmt));
  103071. + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
  103072. + gcc_assert(!gsi_end_p(gsi));
  103073. +
  103074. + cur_bb = gimple_bb(oldstmt);
  103075. + next_bb = cur_bb->next_bb;
  103076. + e = find_edge(cur_bb, next_bb);
  103077. + gcc_assert(e != NULL);
  103078. + gcc_assert(e->flags & EDGE_FALLTHRU);
  103079. +
  103080. + gsi = gsi_after_labels(next_bb);
  103081. + gcc_assert(!gsi_end_p(gsi));
  103082. +
  103083. + before = true;
  103084. + oldstmt = gsi_stmt(gsi);
  103085. + }
  103086. +
  103087. + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
  103088. +
  103089. + if (is_gimple_constant(rhs1))
  103090. + return cast_a_tree(dst_type, rhs1);
  103091. + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
  103092. +}
  103093. +
  103094. +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
  103095. +{
  103096. + gimple stmt;
  103097. + gimple_stmt_iterator gsi;
  103098. + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
  103099. +
  103100. + if (pointer_set_contains(visited->my_stmts, oldstmt))
  103101. + return lhs;
  103102. +
  103103. + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
  103104. + rhs1 = gimple_assign_rhs1(oldstmt);
  103105. + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
  103106. + }
  103107. + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
  103108. + rhs2 = gimple_assign_rhs2(oldstmt);
  103109. + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
  103110. + }
  103111. +
  103112. + stmt = gimple_copy(oldstmt);
  103113. + gimple_set_location(stmt, gimple_location(oldstmt));
  103114. + pointer_set_insert(visited->my_stmts, stmt);
  103115. +
  103116. + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
  103117. + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
  103118. +
  103119. + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
  103120. +
  103121. + new_var = create_new_var(size_overflow_type);
  103122. + new_var = make_ssa_name(new_var, stmt);
  103123. + gimple_assign_set_lhs(stmt, new_var);
  103124. +
  103125. + if (rhs1 != NULL_TREE)
  103126. + gimple_assign_set_rhs1(stmt, rhs1);
  103127. +
  103128. + if (rhs2 != NULL_TREE)
  103129. + gimple_assign_set_rhs2(stmt, rhs2);
  103130. +#if BUILDING_GCC_VERSION >= 4006
  103131. + if (rhs3 != NULL_TREE)
  103132. + gimple_assign_set_rhs3(stmt, rhs3);
  103133. +#endif
  103134. + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
  103135. + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
  103136. +
  103137. + gsi = gsi_for_stmt(oldstmt);
  103138. + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
  103139. + update_stmt(stmt);
  103140. + pointer_set_insert(visited->stmts, oldstmt);
  103141. + return gimple_assign_lhs(stmt);
  103142. +}
  103143. +
  103144. +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
  103145. +{
  103146. + gimple assign;
  103147. + gimple_stmt_iterator gsi;
  103148. + basic_block first_bb;
  103149. +
  103150. + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
  103151. +
  103152. + if (bb->index == 0) {
  103153. + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
  103154. + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
  103155. + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
  103156. + bb = first_bb;
  103157. + }
  103158. +
  103159. + gsi = gsi_after_labels(bb);
  103160. + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
  103161. + pointer_set_insert(visited->my_stmts, assign);
  103162. +
  103163. + return gimple_assign_lhs(assign);
  103164. +}
  103165. +
  103166. +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
  103167. +{
  103168. + gimple_stmt_iterator gsi;
  103169. + gimple assign, def_stmt = get_def_stmt(new_arg);
  103170. +
  103171. + if (gimple_code(def_stmt) == GIMPLE_PHI) {
  103172. + gsi = gsi_after_labels(gimple_bb(def_stmt));
  103173. + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
  103174. + } else {
  103175. + gsi = gsi_for_stmt(def_stmt);
  103176. + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
  103177. + }
  103178. +
  103179. + pointer_set_insert(visited->my_stmts, assign);
  103180. + return gimple_assign_lhs(assign);
  103181. +}
  103182. +
  103183. +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
  103184. +{
  103185. + basic_block bb;
  103186. + gimple_stmt_iterator gsi;
  103187. + const_gimple def_stmt;
  103188. + gimple assign;
  103189. +
  103190. + def_stmt = get_def_stmt(arg);
  103191. + bb = gimple_bb(def_stmt);
  103192. + gcc_assert(bb->index != 0);
  103193. + gsi = gsi_after_labels(bb);
  103194. +
  103195. + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
  103196. + pointer_set_insert(visited->my_stmts, assign);
  103197. + return gimple_assign_lhs(assign);
  103198. +}
  103199. +
  103200. +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
  103201. +{
  103202. + tree size_overflow_type;
  103203. + tree arg;
  103204. + const_gimple def_stmt;
  103205. +
  103206. + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
  103207. + return new_arg;
  103208. +
  103209. + arg = gimple_phi_arg_def(oldstmt, i);
  103210. + def_stmt = get_def_stmt(arg);
  103211. + gcc_assert(def_stmt != NULL);
  103212. + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
  103213. +
  103214. + switch (gimple_code(def_stmt)) {
  103215. + case GIMPLE_PHI:
  103216. + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
  103217. + case GIMPLE_NOP: {
  103218. + basic_block bb;
  103219. +
  103220. + bb = gimple_phi_arg_edge(oldstmt, i)->src;
  103221. + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
  103222. + }
  103223. + case GIMPLE_ASM: {
  103224. + gimple_stmt_iterator gsi;
  103225. + gimple assign, stmt = get_def_stmt(arg);
  103226. +
  103227. + gsi = gsi_for_stmt(stmt);
  103228. + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
  103229. + pointer_set_insert(visited->my_stmts, assign);
  103230. + return gimple_assign_lhs(assign);
  103231. + }
  103232. + default:
  103233. + gcc_assert(new_arg != NULL_TREE);
  103234. + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
  103235. + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
  103236. + }
  103237. +}
  103238. +
  103239. +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
  103240. +{
  103241. + basic_block bb;
  103242. + gimple phi;
  103243. + gimple_seq seq;
  103244. + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
  103245. +
  103246. + bb = gsi_bb(gsi);
  103247. +
  103248. + if (result == NULL_TREE) {
  103249. + tree old_result = gimple_phi_result(oldstmt);
  103250. + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
  103251. +
  103252. + result = create_new_var(size_overflow_type);
  103253. + }
  103254. +
  103255. + phi = create_phi_node(result, bb);
  103256. + gimple_phi_set_result(phi, make_ssa_name(result, phi));
  103257. + seq = phi_nodes(bb);
  103258. + gsi = gsi_last(seq);
  103259. + gsi_remove(&gsi, false);
  103260. +
  103261. + gsi = gsi_for_stmt(oldstmt);
  103262. + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
  103263. + gimple_set_bb(phi, bb);
  103264. + return phi;
  103265. +}
  103266. +
  103267. +#if BUILDING_GCC_VERSION <= 4007
  103268. +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
  103269. +#else
  103270. +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
  103271. +#endif
  103272. +{
  103273. + gimple new_phi;
  103274. + unsigned int i;
  103275. + tree arg, result;
  103276. + location_t loc = gimple_location(oldstmt);
  103277. +
  103278. +#if BUILDING_GCC_VERSION <= 4007
  103279. + gcc_assert(!VEC_empty(tree, *args));
  103280. +#else
  103281. + gcc_assert(!args->is_empty());
  103282. +#endif
  103283. +
  103284. + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
  103285. + result = gimple_phi_result(new_phi);
  103286. + ssa_name_var = SSA_NAME_VAR(result);
  103287. +
  103288. +#if BUILDING_GCC_VERSION <= 4007
  103289. + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
  103290. +#else
  103291. + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
  103292. +#endif
  103293. + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
  103294. + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
  103295. + }
  103296. +
  103297. +#if BUILDING_GCC_VERSION <= 4007
  103298. + VEC_free(tree, heap, *args);
  103299. +#else
  103300. + vec_free(args);
  103301. +#endif
  103302. + update_stmt(new_phi);
  103303. + pointer_set_insert(visited->my_stmts, new_phi);
  103304. + return result;
  103305. +}
  103306. +
  103307. +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
  103308. +{
  103309. + tree ssa_name_var = NULL_TREE;
  103310. +#if BUILDING_GCC_VERSION <= 4007
  103311. + VEC(tree, heap) *args = NULL;
  103312. +#else
  103313. + vec<tree, va_heap, vl_embed> *args = NULL;
  103314. +#endif
  103315. + gimple oldstmt = get_def_stmt(orig_result);
  103316. + unsigned int i, len = gimple_phi_num_args(oldstmt);
  103317. +
  103318. + pointer_set_insert(visited->stmts, oldstmt);
  103319. + for (i = 0; i < len; i++) {
  103320. + tree arg, new_arg;
  103321. +
  103322. + arg = gimple_phi_arg_def(oldstmt, i);
  103323. + new_arg = expand(visited, caller_node, arg);
  103324. +
  103325. + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
  103326. + ssa_name_var = SSA_NAME_VAR(new_arg);
  103327. +
  103328. + if (is_gimple_constant(arg)) {
  103329. + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
  103330. +
  103331. + new_arg = cast_a_tree(size_overflow_type, arg);
  103332. + }
  103333. +
  103334. +#if BUILDING_GCC_VERSION <= 4007
  103335. + VEC_safe_push(tree, heap, args, new_arg);
  103336. +#else
  103337. + vec_safe_push(args, new_arg);
  103338. +#endif
  103339. + }
  103340. +
  103341. +#if BUILDING_GCC_VERSION <= 4007
  103342. + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
  103343. +#else
  103344. + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
  103345. +#endif
  103346. +}
  103347. +
  103348. +static tree create_cast_assign(struct visited *visited, gimple stmt)
  103349. +{
  103350. + tree rhs1 = gimple_assign_rhs1(stmt);
  103351. + tree lhs = gimple_assign_lhs(stmt);
  103352. + const_tree rhs1_type = TREE_TYPE(rhs1);
  103353. + const_tree lhs_type = TREE_TYPE(lhs);
  103354. +
  103355. + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
  103356. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  103357. +
  103358. + return create_assign(visited, stmt, rhs1, AFTER_STMT);
  103359. +}
  103360. +
  103361. +static bool skip_lhs_cast_check(const_gimple stmt)
  103362. +{
  103363. + const_tree rhs = gimple_assign_rhs1(stmt);
  103364. + const_gimple def_stmt = get_def_stmt(rhs);
  103365. +
  103366. + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
  103367. + if (gimple_code(def_stmt) == GIMPLE_ASM)
  103368. + return true;
  103369. +
  103370. + if (is_const_plus_unsigned_signed_truncation(rhs))
  103371. + return true;
  103372. +
  103373. + return false;
  103374. +}
  103375. +
  103376. +static tree create_string_param(tree string)
  103377. +{
  103378. + tree i_type, a_type;
  103379. + const int length = TREE_STRING_LENGTH(string);
  103380. +
  103381. + gcc_assert(length > 0);
  103382. +
  103383. + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
  103384. + a_type = build_array_type(char_type_node, i_type);
  103385. +
  103386. + TREE_TYPE(string) = a_type;
  103387. + TREE_CONSTANT(string) = 1;
  103388. + TREE_READONLY(string) = 1;
  103389. +
  103390. + return build1(ADDR_EXPR, ptr_type_node, string);
  103391. +}
  103392. +
  103393. +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
  103394. +{
  103395. + gimple cond_stmt;
  103396. + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
  103397. +
  103398. + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
  103399. + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
  103400. + update_stmt(cond_stmt);
  103401. +}
  103402. +
  103403. +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
  103404. +{
  103405. + gimple func_stmt;
  103406. + const_gimple def_stmt;
  103407. + const_tree loc_line;
  103408. + tree loc_file, ssa_name, current_func;
  103409. + expanded_location xloc;
  103410. + char *ssa_name_buf;
  103411. + int len;
  103412. + struct cgraph_edge *edge;
  103413. + struct cgraph_node *callee_node;
  103414. + int frequency;
  103415. + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
  103416. +
  103417. + def_stmt = get_def_stmt(arg);
  103418. + xloc = expand_location(gimple_location(def_stmt));
  103419. +
  103420. + if (!gimple_has_location(def_stmt)) {
  103421. + xloc = expand_location(gimple_location(stmt));
  103422. + if (!gimple_has_location(stmt))
  103423. + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
  103424. + }
  103425. +
  103426. + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
  103427. +
  103428. + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
  103429. + loc_file = create_string_param(loc_file);
  103430. +
  103431. + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
  103432. + current_func = create_string_param(current_func);
  103433. +
  103434. + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
  103435. + call_count++;
  103436. + len = asprintf(&ssa_name_buf, "%s_%u %s, count: %u\n", DECL_NAME_POINTER(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max", call_count);
  103437. + gcc_assert(len > 0);
  103438. + ssa_name = build_string(len + 1, ssa_name_buf);
  103439. + free(ssa_name_buf);
  103440. + ssa_name = create_string_param(ssa_name);
  103441. +
  103442. + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
  103443. + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
  103444. + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
  103445. +
  103446. + callee_node = cgraph_get_create_node(report_size_overflow_decl);
  103447. + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
  103448. +
  103449. + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
  103450. + gcc_assert(edge != NULL);
  103451. +}
  103452. +
  103453. +static void insert_check_size_overflow(struct cgraph_node *caller_node, gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
  103454. +{
  103455. + basic_block cond_bb, join_bb, bb_true;
  103456. + edge e;
  103457. + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
  103458. +
  103459. + cond_bb = gimple_bb(stmt);
  103460. + if (before)
  103461. + gsi_prev(&gsi);
  103462. + if (gsi_end_p(gsi))
  103463. + e = split_block_after_labels(cond_bb);
  103464. + else
  103465. + e = split_block(cond_bb, gsi_stmt(gsi));
  103466. + cond_bb = e->src;
  103467. + join_bb = e->dest;
  103468. + e->flags = EDGE_FALSE_VALUE;
  103469. + e->probability = REG_BR_PROB_BASE;
  103470. +
  103471. + bb_true = create_empty_bb(cond_bb);
  103472. + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
  103473. + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
  103474. + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
  103475. +
  103476. + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
  103477. + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
  103478. + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
  103479. +
  103480. + if (current_loops != NULL) {
  103481. + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
  103482. + add_bb_to_loop(bb_true, cond_bb->loop_father);
  103483. + }
  103484. +
  103485. + insert_cond(cond_bb, arg, cond_code, type_value);
  103486. + insert_cond_result(caller_node, bb_true, stmt, arg, min);
  103487. +
  103488. +// print_the_code_insertions(stmt);
  103489. +}
  103490. +
  103491. +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
  103492. +{
  103493. + const_tree rhs_type = TREE_TYPE(rhs);
  103494. + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
  103495. +
  103496. + gcc_assert(rhs_type != NULL_TREE);
  103497. + if (TREE_CODE(rhs_type) == POINTER_TYPE)
  103498. + return;
  103499. +
  103500. + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
  103501. +
  103502. + if (is_const_plus_unsigned_signed_truncation(rhs))
  103503. + return;
  103504. +
  103505. + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
  103506. + // typemax (-1) < typemin (0)
  103507. + if (TREE_OVERFLOW(type_max))
  103508. + return;
  103509. +
  103510. + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
  103511. +
  103512. + cast_rhs_type = TREE_TYPE(cast_rhs);
  103513. + type_max_type = TREE_TYPE(type_max);
  103514. + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
  103515. +
  103516. + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
  103517. +
  103518. + // special case: get_size_overflow_type(), 32, u64->s
  103519. + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
  103520. + return;
  103521. +
  103522. + type_min_type = TREE_TYPE(type_min);
  103523. + gcc_assert(types_compatible_p(type_max_type, type_min_type));
  103524. + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
  103525. +}
  103526. +
  103527. +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
  103528. +{
  103529. + bool cast_lhs, cast_rhs;
  103530. + tree lhs = gimple_assign_lhs(stmt);
  103531. + tree rhs = gimple_assign_rhs1(stmt);
  103532. + const_tree lhs_type = TREE_TYPE(lhs);
  103533. + const_tree rhs_type = TREE_TYPE(rhs);
  103534. + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
  103535. + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
  103536. + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
  103537. + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
  103538. +
  103539. + static bool check_lhs[3][4] = {
  103540. + // ss su us uu
  103541. + { false, true, true, false }, // lhs > rhs
  103542. + { false, false, false, false }, // lhs = rhs
  103543. + { true, true, true, true }, // lhs < rhs
  103544. + };
  103545. +
  103546. + static bool check_rhs[3][4] = {
  103547. + // ss su us uu
  103548. + { true, false, true, true }, // lhs > rhs
  103549. + { true, false, true, true }, // lhs = rhs
  103550. + { true, false, true, true }, // lhs < rhs
  103551. + };
  103552. +
  103553. + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
  103554. + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
  103555. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  103556. +
  103557. + if (lhs_size > rhs_size) {
  103558. + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
  103559. + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
  103560. + } else if (lhs_size == rhs_size) {
  103561. + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
  103562. + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
  103563. + } else {
  103564. + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
  103565. + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
  103566. + }
  103567. +
  103568. + if (!cast_lhs && !cast_rhs)
  103569. + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
  103570. +
  103571. + if (cast_lhs && !skip_lhs_cast_check(stmt))
  103572. + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
  103573. +
  103574. + if (cast_rhs)
  103575. + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
  103576. +
  103577. + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
  103578. +}
  103579. +
  103580. +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
  103581. +{
  103582. + enum tree_code rhs_code;
  103583. + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
  103584. +
  103585. + if (pointer_set_contains(visited->my_stmts, stmt))
  103586. + return lhs;
  103587. +
  103588. + rhs1 = gimple_assign_rhs1(stmt);
  103589. + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
  103590. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  103591. +
  103592. + new_rhs1 = expand(visited, caller_node, rhs1);
  103593. +
  103594. + if (new_rhs1 == NULL_TREE)
  103595. + return create_cast_assign(visited, stmt);
  103596. +
  103597. + if (pointer_set_contains(visited->no_cast_check, stmt))
  103598. + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
  103599. +
  103600. + rhs_code = gimple_assign_rhs_code(stmt);
  103601. + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
  103602. + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
  103603. +
  103604. + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
  103605. + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
  103606. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  103607. + }
  103608. +
  103609. + if (!gimple_assign_cast_p(stmt))
  103610. + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
  103611. +
  103612. + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
  103613. +}
  103614. +
  103615. +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
  103616. +{
  103617. + tree rhs1, lhs = gimple_assign_lhs(stmt);
  103618. + gimple def_stmt = get_def_stmt(lhs);
  103619. +
  103620. + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
  103621. + rhs1 = gimple_assign_rhs1(def_stmt);
  103622. +
  103623. + if (is_gimple_constant(rhs1))
  103624. + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
  103625. +
  103626. + switch (TREE_CODE(rhs1)) {
  103627. + case SSA_NAME:
  103628. + return handle_unary_rhs(visited, caller_node, def_stmt);
  103629. + case ARRAY_REF:
  103630. + case BIT_FIELD_REF:
  103631. + case ADDR_EXPR:
  103632. + case COMPONENT_REF:
  103633. + case INDIRECT_REF:
  103634. +#if BUILDING_GCC_VERSION >= 4006
  103635. + case MEM_REF:
  103636. +#endif
  103637. + case TARGET_MEM_REF:
  103638. + case VIEW_CONVERT_EXPR:
  103639. + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
  103640. + case PARM_DECL:
  103641. + case VAR_DECL:
  103642. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  103643. +
  103644. + default:
  103645. + debug_gimple_stmt(def_stmt);
  103646. + debug_tree(rhs1);
  103647. + gcc_unreachable();
  103648. + }
  103649. +}
  103650. +
  103651. +static void __unused print_the_code_insertions(const_gimple stmt)
  103652. +{
  103653. + location_t loc = gimple_location(stmt);
  103654. +
  103655. + inform(loc, "Integer size_overflow check applied here.");
  103656. +}
  103657. +
  103658. +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
  103659. +{
  103660. + enum intentional_overflow_type res;
  103661. + tree rhs1, rhs2, new_lhs;
  103662. + gimple def_stmt = get_def_stmt(lhs);
  103663. + tree new_rhs1 = NULL_TREE;
  103664. + tree new_rhs2 = NULL_TREE;
  103665. +
  103666. + rhs1 = gimple_assign_rhs1(def_stmt);
  103667. + rhs2 = gimple_assign_rhs2(def_stmt);
  103668. +
  103669. + /* no DImode/TImode division in the 32/64 bit kernel */
  103670. + switch (gimple_assign_rhs_code(def_stmt)) {
  103671. + case RDIV_EXPR:
  103672. + case TRUNC_DIV_EXPR:
  103673. + case CEIL_DIV_EXPR:
  103674. + case FLOOR_DIV_EXPR:
  103675. + case ROUND_DIV_EXPR:
  103676. + case TRUNC_MOD_EXPR:
  103677. + case CEIL_MOD_EXPR:
  103678. + case FLOOR_MOD_EXPR:
  103679. + case ROUND_MOD_EXPR:
  103680. + case EXACT_DIV_EXPR:
  103681. + case POINTER_PLUS_EXPR:
  103682. + case BIT_AND_EXPR:
  103683. + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
  103684. + default:
  103685. + break;
  103686. + }
  103687. +
  103688. + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
  103689. + if (new_lhs != NULL_TREE)
  103690. + return new_lhs;
  103691. +
  103692. + if (TREE_CODE(rhs1) == SSA_NAME)
  103693. + new_rhs1 = expand(visited, caller_node, rhs1);
  103694. + if (TREE_CODE(rhs2) == SSA_NAME)
  103695. + new_rhs2 = expand(visited, caller_node, rhs2);
  103696. +
  103697. + res = add_mul_intentional_overflow(def_stmt);
  103698. + if (res != NO_INTENTIONAL_OVERFLOW) {
  103699. + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
  103700. + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
  103701. + return new_lhs;
  103702. + }
  103703. +
  103704. + if (skip_expr_on_double_type(def_stmt)) {
  103705. + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
  103706. + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
  103707. + return new_lhs;
  103708. + }
  103709. +
  103710. + if (is_a_neg_overflow(def_stmt, rhs2))
  103711. + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
  103712. + if (is_a_neg_overflow(def_stmt, rhs1))
  103713. + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
  103714. +
  103715. +
  103716. + if (is_a_constant_overflow(def_stmt, rhs2))
  103717. + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
  103718. + if (is_a_constant_overflow(def_stmt, rhs1))
  103719. + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
  103720. +
  103721. + // the const is between 0 and (signed) MAX
  103722. + if (is_gimple_constant(rhs1))
  103723. + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
  103724. + if (is_gimple_constant(rhs2))
  103725. + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
  103726. +
  103727. + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
  103728. +}
  103729. +
  103730. +#if BUILDING_GCC_VERSION >= 4006
  103731. +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
  103732. +{
  103733. + if (is_gimple_constant(rhs))
  103734. + return cast_a_tree(size_overflow_type, rhs);
  103735. + if (TREE_CODE(rhs) != SSA_NAME)
  103736. + return NULL_TREE;
  103737. + return expand(visited, caller_node, rhs);
  103738. +}
  103739. +
  103740. +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
  103741. +{
  103742. + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
  103743. + gimple def_stmt = get_def_stmt(lhs);
  103744. +
  103745. + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
  103746. +
  103747. + rhs1 = gimple_assign_rhs1(def_stmt);
  103748. + rhs2 = gimple_assign_rhs2(def_stmt);
  103749. + rhs3 = gimple_assign_rhs3(def_stmt);
  103750. + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
  103751. + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
  103752. + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
  103753. +
  103754. + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
  103755. +}
  103756. +#endif
  103757. +
  103758. +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
  103759. +{
  103760. + gimple_stmt_iterator gsi;
  103761. + gimple next_stmt = NULL;
  103762. +
  103763. + gsi = gsi_for_stmt(stmt);
  103764. +
  103765. + do {
  103766. + gsi_next(&gsi);
  103767. + next_stmt = gsi_stmt(gsi);
  103768. +
  103769. + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
  103770. + return NULL_TREE;
  103771. +
  103772. + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
  103773. + break;
  103774. +
  103775. + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
  103776. + } while (!gsi_end_p(gsi));
  103777. +
  103778. + gcc_assert(next_stmt);
  103779. + return get_lhs(next_stmt);
  103780. +}
  103781. +
  103782. +static tree expand_visited(struct visited *visited, gimple def_stmt)
  103783. +{
  103784. + gimple_stmt_iterator gsi;
  103785. + enum gimple_code code = gimple_code(def_stmt);
  103786. +
  103787. + if (code == GIMPLE_ASM)
  103788. + return NULL_TREE;
  103789. +
  103790. + gsi = gsi_for_stmt(def_stmt);
  103791. + gsi_next(&gsi);
  103792. +
  103793. + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
  103794. + return NULL_TREE;
  103795. + return get_my_stmt_lhs(visited, def_stmt);
  103796. +}
  103797. +
  103798. +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
  103799. +{
  103800. + gimple def_stmt;
  103801. +
  103802. + def_stmt = get_def_stmt(lhs);
  103803. +
  103804. + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
  103805. + return NULL_TREE;
  103806. +
  103807. + if (pointer_set_contains(visited->my_stmts, def_stmt))
  103808. + return lhs;
  103809. +
  103810. + if (pointer_set_contains(visited->stmts, def_stmt))
  103811. + return expand_visited(visited, def_stmt);
  103812. +
  103813. + switch (gimple_code(def_stmt)) {
  103814. + case GIMPLE_PHI:
  103815. + return handle_phi(visited, caller_node, lhs);
  103816. + case GIMPLE_CALL:
  103817. + case GIMPLE_ASM:
  103818. + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
  103819. + case GIMPLE_ASSIGN:
  103820. + switch (gimple_num_ops(def_stmt)) {
  103821. + case 2:
  103822. + return handle_unary_ops(visited, caller_node, def_stmt);
  103823. + case 3:
  103824. + return handle_binary_ops(visited, caller_node, lhs);
  103825. +#if BUILDING_GCC_VERSION >= 4006
  103826. + case 4:
  103827. + return handle_ternary_ops(visited, caller_node, lhs);
  103828. +#endif
  103829. + }
  103830. + default:
  103831. + debug_gimple_stmt(def_stmt);
  103832. + error("%s: unknown gimple code", __func__);
  103833. + gcc_unreachable();
  103834. + }
  103835. +}
  103836. +
  103837. diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
  103838. new file mode 100644
  103839. index 0000000..f8f5dd5
  103840. --- /dev/null
  103841. +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
  103842. @@ -0,0 +1,1133 @@
  103843. +/*
  103844. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  103845. + * Licensed under the GPL v2, or (at your option) v3
  103846. + *
  103847. + * Homepage:
  103848. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  103849. + *
  103850. + * Documentation:
  103851. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  103852. + *
  103853. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  103854. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  103855. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  103856. + *
  103857. + * Usage:
  103858. + * $ make
  103859. + * $ make run
  103860. + */
  103861. +
  103862. +#include "gcc-common.h"
  103863. +#include "size_overflow.h"
  103864. +
  103865. +#define VEC_LEN 128
  103866. +#define RET_CHECK NULL_TREE
  103867. +#define WRONG_NODE 32
  103868. +#define NOT_INTENTIONAL_ASM NULL
  103869. +
  103870. +unsigned int call_count;
  103871. +
  103872. +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
  103873. +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
  103874. +
  103875. +struct visited_fns {
  103876. + struct visited_fns *next;
  103877. + const_tree fndecl;
  103878. + unsigned int num;
  103879. + const_gimple first_stmt;
  103880. +};
  103881. +
  103882. +struct next_cgraph_node {
  103883. + struct next_cgraph_node *next;
  103884. + struct cgraph_node *current_function;
  103885. + tree callee_fndecl;
  103886. + unsigned int num;
  103887. +};
  103888. +
  103889. +// Don't want to duplicate entries in next_cgraph_node
  103890. +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
  103891. +{
  103892. + const_tree new_callee_fndecl;
  103893. + struct next_cgraph_node *cur_node;
  103894. +
  103895. + if (fndecl == RET_CHECK)
  103896. + new_callee_fndecl = NODE_DECL(node);
  103897. + else
  103898. + new_callee_fndecl = fndecl;
  103899. +
  103900. + for (cur_node = head; cur_node; cur_node = cur_node->next) {
  103901. + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
  103902. + continue;
  103903. + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
  103904. + continue;
  103905. + if (num == cur_node->num)
  103906. + return true;
  103907. + }
  103908. + return false;
  103909. +}
  103910. +
  103911. +/* Add a next_cgraph_node into the list for handle_function().
  103912. + * handle_function() iterates over all the next cgraph nodes and
  103913. + * starts the overflow check insertion process.
  103914. + */
  103915. +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
  103916. +{
  103917. + struct next_cgraph_node *new_node;
  103918. +
  103919. + if (is_in_next_cgraph_node(head, node, fndecl, num))
  103920. + return head;
  103921. +
  103922. + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
  103923. + new_node->current_function = node;
  103924. + new_node->next = NULL;
  103925. + new_node->num = num;
  103926. + if (fndecl == RET_CHECK)
  103927. + new_node->callee_fndecl = NODE_DECL(node);
  103928. + else
  103929. + new_node->callee_fndecl = fndecl;
  103930. +
  103931. + if (!head)
  103932. + return new_node;
  103933. +
  103934. + new_node->next = head;
  103935. + return new_node;
  103936. +}
  103937. +
  103938. +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
  103939. +{
  103940. + struct cgraph_edge *e;
  103941. +
  103942. + if (num == 0)
  103943. + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
  103944. +
  103945. + for (e = node->callers; e; e = e->next_caller) {
  103946. + tree fndecl = gimple_call_fndecl(e->call_stmt);
  103947. +
  103948. + gcc_assert(fndecl != NULL_TREE);
  103949. + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
  103950. + }
  103951. +
  103952. + return head;
  103953. +}
  103954. +
  103955. +struct missing_functions {
  103956. + struct missing_functions *next;
  103957. + const_tree node;
  103958. + tree fndecl;
  103959. +};
  103960. +
  103961. +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
  103962. +{
  103963. + struct missing_functions *new_function;
  103964. +
  103965. + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
  103966. + new_function->node = node;
  103967. + new_function->next = NULL;
  103968. +
  103969. + if (TREE_CODE(node) == FUNCTION_DECL)
  103970. + new_function->fndecl = node;
  103971. + else
  103972. + new_function->fndecl = current_function_decl;
  103973. + gcc_assert(new_function->fndecl);
  103974. +
  103975. + if (!missing_fn_head)
  103976. + return new_function;
  103977. +
  103978. + new_function->next = missing_fn_head;
  103979. + return new_function;
  103980. +}
  103981. +
  103982. +/* If the function is missing from the hash table and it is a static function
  103983. + * then create a next_cgraph_node from it for handle_function()
  103984. + */
  103985. +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
  103986. +{
  103987. + unsigned int num;
  103988. + const_tree orig_fndecl;
  103989. + struct cgraph_node *next_node = NULL;
  103990. +
  103991. + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
  103992. +
  103993. + num = get_function_num(missing_fn_head->node, orig_fndecl);
  103994. + if (num == CANNOT_FIND_ARG)
  103995. + return cnodes;
  103996. +
  103997. + if (!is_missing_function(orig_fndecl, num))
  103998. + return cnodes;
  103999. +
  104000. + next_node = cgraph_get_node(missing_fn_head->fndecl);
  104001. + if (next_node && next_node->local.local)
  104002. + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
  104003. + return cnodes;
  104004. +}
  104005. +
  104006. +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
  104007. + * into the next_cgraph_node list. They will be the next interesting returns or callees.
  104008. + */
  104009. +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
  104010. +{
  104011. + unsigned int i;
  104012. + tree node;
  104013. + struct missing_functions *cur, *missing_fn_head = NULL;
  104014. +
  104015. +#if BUILDING_GCC_VERSION <= 4007
  104016. + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
  104017. +#else
  104018. + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
  104019. +#endif
  104020. + switch (TREE_CODE(node)) {
  104021. + case PARM_DECL:
  104022. + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
  104023. + break;
  104024. + case FUNCTION_DECL:
  104025. + missing_fn_head = create_new_missing_function(missing_fn_head, node);
  104026. + break;
  104027. + default:
  104028. + break;
  104029. + }
  104030. + }
  104031. +
  104032. + while (missing_fn_head) {
  104033. + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
  104034. +
  104035. + cur = missing_fn_head->next;
  104036. + free(missing_fn_head);
  104037. + missing_fn_head = cur;
  104038. + }
  104039. +
  104040. + return cnodes;
  104041. +}
  104042. +
  104043. +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
  104044. +{
  104045. + gimple phi = get_def_stmt(result);
  104046. + unsigned int i, n = gimple_phi_num_args(phi);
  104047. +
  104048. + pointer_set_insert(visited, phi);
  104049. + for (i = 0; i < n; i++) {
  104050. + const_tree arg = gimple_phi_arg_def(phi, i);
  104051. +
  104052. + set_conditions(visited, interesting_conditions, arg);
  104053. + }
  104054. +}
  104055. +
  104056. +enum conditions {
  104057. + FROM_CONST, NOT_UNARY, CAST
  104058. +};
  104059. +
  104060. +// Search for constants, cast assignments and binary/ternary assignments
  104061. +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
  104062. +{
  104063. + gimple def_stmt = get_def_stmt(lhs);
  104064. +
  104065. + if (is_gimple_constant(lhs)) {
  104066. + interesting_conditions[FROM_CONST] = true;
  104067. + return;
  104068. + }
  104069. +
  104070. + if (!def_stmt)
  104071. + return;
  104072. +
  104073. + if (pointer_set_contains(visited, def_stmt))
  104074. + return;
  104075. +
  104076. + switch (gimple_code(def_stmt)) {
  104077. + case GIMPLE_NOP:
  104078. + case GIMPLE_CALL:
  104079. + case GIMPLE_ASM:
  104080. + return;
  104081. + case GIMPLE_PHI:
  104082. + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
  104083. + case GIMPLE_ASSIGN:
  104084. + if (gimple_num_ops(def_stmt) == 2) {
  104085. + const_tree rhs = gimple_assign_rhs1(def_stmt);
  104086. +
  104087. + if (gimple_assign_cast_p(def_stmt))
  104088. + interesting_conditions[CAST] = true;
  104089. +
  104090. + return set_conditions(visited, interesting_conditions, rhs);
  104091. + } else {
  104092. + interesting_conditions[NOT_UNARY] = true;
  104093. + return;
  104094. + }
  104095. + default:
  104096. + debug_gimple_stmt(def_stmt);
  104097. + gcc_unreachable();
  104098. + }
  104099. +}
  104100. +
  104101. +// determine whether duplication will be necessary or not.
  104102. +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
  104103. +{
  104104. + struct pointer_set_t *visited;
  104105. +
  104106. + if (gimple_assign_cast_p(cur_node->first_stmt))
  104107. + interesting_conditions[CAST] = true;
  104108. + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
  104109. + interesting_conditions[NOT_UNARY] = true;
  104110. +
  104111. + visited = pointer_set_create();
  104112. + set_conditions(visited, interesting_conditions, cur_node->node);
  104113. + pointer_set_destroy(visited);
  104114. +}
  104115. +
  104116. +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
  104117. +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
  104118. +{
  104119. + gimple assign;
  104120. + gimple_stmt_iterator gsi;
  104121. +
  104122. + // already removed
  104123. + if (gimple_bb(asm_stmt) == NULL)
  104124. + return;
  104125. + gsi = gsi_for_stmt(asm_stmt);
  104126. +
  104127. + assign = gimple_build_assign(lhs, rhs);
  104128. + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
  104129. + SSA_NAME_DEF_STMT(lhs) = assign;
  104130. +
  104131. + gsi_remove(&gsi, true);
  104132. +}
  104133. +
  104134. +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
  104135. + * stmt is a return otherwise it is the callee function.
  104136. + */
  104137. +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
  104138. +{
  104139. + const_tree fndecl;
  104140. +
  104141. + if (argnum == 0)
  104142. + fndecl = current_function_decl;
  104143. + else
  104144. + fndecl = gimple_call_fndecl(stmt);
  104145. +
  104146. + if (fndecl == NULL_TREE)
  104147. + return NULL_TREE;
  104148. +
  104149. + return DECL_ORIGIN(fndecl);
  104150. +}
  104151. +
  104152. +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
  104153. +static bool skip_asm(const_tree arg)
  104154. +{
  104155. + gimple def_stmt = get_def_stmt(arg);
  104156. +
  104157. + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
  104158. + return false;
  104159. +
  104160. + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
  104161. + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
  104162. +}
  104163. +
  104164. +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
  104165. +{
  104166. + gimple phi = get_def_stmt(result);
  104167. + unsigned int i, n = gimple_phi_num_args(phi);
  104168. +
  104169. + pointer_set_insert(visited, phi);
  104170. + for (i = 0; i < n; i++) {
  104171. + tree arg = gimple_phi_arg_def(phi, i);
  104172. +
  104173. + walk_use_def(visited, cur_node, arg);
  104174. + }
  104175. +}
  104176. +
  104177. +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
  104178. +{
  104179. + gimple def_stmt = get_def_stmt(lhs);
  104180. + tree rhs1, rhs2;
  104181. +
  104182. + rhs1 = gimple_assign_rhs1(def_stmt);
  104183. + rhs2 = gimple_assign_rhs2(def_stmt);
  104184. +
  104185. + walk_use_def(visited, cur_node, rhs1);
  104186. + walk_use_def(visited, cur_node, rhs2);
  104187. +}
  104188. +
  104189. +static void insert_last_node(struct interesting_node *cur_node, tree node)
  104190. +{
  104191. + unsigned int i;
  104192. + tree element;
  104193. + enum tree_code code;
  104194. +
  104195. + gcc_assert(node != NULL_TREE);
  104196. +
  104197. + if (is_gimple_constant(node))
  104198. + return;
  104199. +
  104200. + code = TREE_CODE(node);
  104201. + if (code == VAR_DECL) {
  104202. + node = DECL_ORIGIN(node);
  104203. + code = TREE_CODE(node);
  104204. + }
  104205. +
  104206. + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
  104207. + return;
  104208. +
  104209. +#if BUILDING_GCC_VERSION <= 4007
  104210. + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
  104211. +#else
  104212. + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
  104213. +#endif
  104214. + if (operand_equal_p(node, element, 0))
  104215. + return;
  104216. + }
  104217. +
  104218. +#if BUILDING_GCC_VERSION <= 4007
  104219. + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
  104220. + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
  104221. +#else
  104222. + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
  104223. + vec_safe_push(cur_node->last_nodes, node);
  104224. +#endif
  104225. +}
  104226. +
  104227. +// a size_overflow asm stmt in the control flow doesn't stop the recursion
  104228. +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
  104229. +{
  104230. + if (!is_size_overflow_asm(stmt))
  104231. + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
  104232. +}
  104233. +
  104234. +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
  104235. + * and component refs (for checking the intentional_overflow attribute).
  104236. + */
  104237. +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
  104238. +{
  104239. + const_gimple def_stmt;
  104240. +
  104241. + if (TREE_CODE(lhs) != SSA_NAME) {
  104242. + insert_last_node(cur_node, lhs);
  104243. + return;
  104244. + }
  104245. +
  104246. + def_stmt = get_def_stmt(lhs);
  104247. + if (!def_stmt)
  104248. + return;
  104249. +
  104250. + if (pointer_set_insert(visited, def_stmt))
  104251. + return;
  104252. +
  104253. + switch (gimple_code(def_stmt)) {
  104254. + case GIMPLE_NOP:
  104255. + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
  104256. + case GIMPLE_ASM:
  104257. + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
  104258. + case GIMPLE_CALL: {
  104259. + tree fndecl = gimple_call_fndecl(def_stmt);
  104260. +
  104261. + if (fndecl == NULL_TREE)
  104262. + return;
  104263. + insert_last_node(cur_node, fndecl);
  104264. + return;
  104265. + }
  104266. + case GIMPLE_PHI:
  104267. + return walk_use_def_phi(visited, cur_node, lhs);
  104268. + case GIMPLE_ASSIGN:
  104269. + switch (gimple_num_ops(def_stmt)) {
  104270. + case 2:
  104271. + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
  104272. + case 3:
  104273. + return walk_use_def_binary(visited, cur_node, lhs);
  104274. + }
  104275. + default:
  104276. + debug_gimple_stmt((gimple)def_stmt);
  104277. + error("%s: unknown gimple code", __func__);
  104278. + gcc_unreachable();
  104279. + }
  104280. +}
  104281. +
  104282. +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
  104283. +static void set_last_nodes(struct interesting_node *cur_node)
  104284. +{
  104285. + struct pointer_set_t *visited;
  104286. +
  104287. + visited = pointer_set_create();
  104288. + walk_use_def(visited, cur_node, cur_node->node);
  104289. + pointer_set_destroy(visited);
  104290. +}
  104291. +
  104292. +enum precond {
  104293. + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
  104294. +};
  104295. +
  104296. +/* If there is a mark_turn_off intentional attribute on the caller or the callee then there is no duplication and missing size_overflow attribute check anywhere.
  104297. + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
  104298. + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
  104299. + * It skips the possible error codes too. If the def_stmts trace back to a constant and there are no binary/ternary assigments then we assume that it is some kind of error code.
  104300. + */
  104301. +static enum precond check_preconditions(struct interesting_node *cur_node)
  104302. +{
  104303. + bool interesting_conditions[3] = {false, false, false};
  104304. +
  104305. + set_last_nodes(cur_node);
  104306. +
  104307. + check_intentional_attribute_ipa(cur_node);
  104308. + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
  104309. + return NO_ATTRIBUTE_SEARCH;
  104310. +
  104311. + search_interesting_conditions(cur_node, interesting_conditions);
  104312. +
  104313. + // error code
  104314. + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
  104315. + return NO_ATTRIBUTE_SEARCH;
  104316. +
  104317. + // unnecessary overflow check
  104318. + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
  104319. + return NO_CHECK_INSERT;
  104320. +
  104321. + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
  104322. + return NO_CHECK_INSERT;
  104323. +
  104324. + return NONE;
  104325. +}
  104326. +
  104327. +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
  104328. +{
  104329. + const_gimple assign;
  104330. + tree orig_type = TREE_TYPE(orig_node);
  104331. + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
  104332. +
  104333. + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
  104334. + return gimple_assign_lhs(assign);
  104335. +}
  104336. +
  104337. +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
  104338. +{
  104339. + void (*set_rhs)(gimple, tree);
  104340. + gimple stmt = cur_node->first_stmt;
  104341. + const_tree orig_node = cur_node->node;
  104342. +
  104343. + switch (gimple_code(stmt)) {
  104344. + case GIMPLE_RETURN:
  104345. + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
  104346. + break;
  104347. + case GIMPLE_CALL:
  104348. + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
  104349. + break;
  104350. + case GIMPLE_ASSIGN:
  104351. + switch (cur_node->num) {
  104352. + case 1:
  104353. + set_rhs = &gimple_assign_set_rhs1;
  104354. + break;
  104355. + case 2:
  104356. + set_rhs = &gimple_assign_set_rhs2;
  104357. + break;
  104358. +#if BUILDING_GCC_VERSION >= 4006
  104359. + case 3:
  104360. + set_rhs = &gimple_assign_set_rhs3;
  104361. + break;
  104362. +#endif
  104363. + default:
  104364. + gcc_unreachable();
  104365. + }
  104366. +
  104367. + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
  104368. + break;
  104369. + default:
  104370. + debug_gimple_stmt(stmt);
  104371. + gcc_unreachable();
  104372. + }
  104373. +
  104374. + update_stmt(stmt);
  104375. +}
  104376. +
  104377. +static struct visited *create_visited(void)
  104378. +{
  104379. + struct visited *new_node;
  104380. +
  104381. + new_node = (struct visited *)xmalloc(sizeof(*new_node));
  104382. + new_node->stmts = pointer_set_create();
  104383. + new_node->my_stmts = pointer_set_create();
  104384. + new_node->skip_expr_casts = pointer_set_create();
  104385. + new_node->no_cast_check = pointer_set_create();
  104386. + return new_node;
  104387. +}
  104388. +
  104389. +static void free_visited(struct visited *visited)
  104390. +{
  104391. + pointer_set_destroy(visited->stmts);
  104392. + pointer_set_destroy(visited->my_stmts);
  104393. + pointer_set_destroy(visited->skip_expr_casts);
  104394. + pointer_set_destroy(visited->no_cast_check);
  104395. +
  104396. + free(visited);
  104397. +}
  104398. +
  104399. +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
  104400. + * it decides whether the duplication is necessary or not and it searches for missing size_overflow attributes. After expand() it changes the orig node to the duplicated node
  104401. + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
  104402. + */
  104403. +static struct next_cgraph_node *handle_interesting_stmt(struct visited *visited, struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
  104404. +{
  104405. + enum precond ret;
  104406. + tree new_node, orig_node = cur_node->node;
  104407. +
  104408. + ret = check_preconditions(cur_node);
  104409. + if (ret == NO_ATTRIBUTE_SEARCH)
  104410. + return cnodes;
  104411. +
  104412. + cnodes = search_overflow_attribute(cnodes, cur_node);
  104413. +
  104414. + if (ret == NO_CHECK_INSERT)
  104415. + return cnodes;
  104416. +
  104417. + new_node = expand(visited, caller_node, orig_node);
  104418. + if (new_node == NULL_TREE)
  104419. + return cnodes;
  104420. +
  104421. + change_orig_node(visited, cur_node, new_node);
  104422. + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
  104423. +
  104424. + return cnodes;
  104425. +}
  104426. +
  104427. +// Check visited_fns interesting nodes.
  104428. +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
  104429. +{
  104430. + struct interesting_node *cur;
  104431. +
  104432. + for (cur = head; cur; cur = cur->next) {
  104433. + if (!operand_equal_p(node, cur->node, 0))
  104434. + continue;
  104435. + if (num != cur->num)
  104436. + continue;
  104437. + if (first_stmt == cur->first_stmt)
  104438. + return true;
  104439. + }
  104440. + return false;
  104441. +}
  104442. +
  104443. +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
  104444. + first_stmt: it is the call or assignment or ret stmt, change_orig_node() will change the original node (retval, or function arg) in this
  104445. + last_nodes: they are the last stmts in the recursion (they haven't a def_stmt). They are useful in the missing size_overflow attribute check and
  104446. + the intentional_overflow attribute check. They are collected by set_last_nodes().
  104447. + num: arg count of a call stmt or 0 when it is a ret
  104448. + node: the recursion starts from here, it is a call arg or a return value
  104449. + fndecl: the fndecl of the interesting node when the node is an arg. it is the fndecl of the callee function otherwise it is the fndecl of the caller (current_function_fndecl) function.
  104450. + intentional_attr_decl: intentional_overflow attribute of the callee function
  104451. + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
  104452. + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
  104453. + */
  104454. +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
  104455. +{
  104456. + struct interesting_node *new_node;
  104457. + tree fndecl;
  104458. + enum gimple_code code;
  104459. +
  104460. + gcc_assert(node != NULL_TREE);
  104461. + code = gimple_code(first_stmt);
  104462. + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
  104463. +
  104464. + if (num == CANNOT_FIND_ARG)
  104465. + return head;
  104466. +
  104467. + if (skip_types(node))
  104468. + return head;
  104469. +
  104470. + if (skip_asm(node))
  104471. + return head;
  104472. +
  104473. + if (is_gimple_call(first_stmt))
  104474. + fndecl = gimple_call_fndecl(first_stmt);
  104475. + else
  104476. + fndecl = current_function_decl;
  104477. +
  104478. + if (fndecl == NULL_TREE)
  104479. + return head;
  104480. +
  104481. + if (is_in_interesting_node(head, first_stmt, node, num))
  104482. + return head;
  104483. +
  104484. + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
  104485. +
  104486. + new_node->next = NULL;
  104487. + new_node->first_stmt = first_stmt;
  104488. +#if BUILDING_GCC_VERSION <= 4007
  104489. + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
  104490. +#else
  104491. + vec_alloc(new_node->last_nodes, VEC_LEN);
  104492. +#endif
  104493. + new_node->num = num;
  104494. + new_node->node = node;
  104495. + new_node->fndecl = fndecl;
  104496. + new_node->intentional_attr_decl = MARK_NO;
  104497. + new_node->intentional_attr_cur_fndecl = MARK_NO;
  104498. + new_node->intentional_mark_from_gimple = asm_stmt;
  104499. +
  104500. + if (!head)
  104501. + return new_node;
  104502. +
  104503. + new_node->next = head;
  104504. + return new_node;
  104505. +}
  104506. +
  104507. +/* Check the ret stmts in the functions on the next cgraph node list (these functions will be in the hash table and they are reachable from ipa).
  104508. + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
  104509. + */
  104510. +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
  104511. +{
  104512. + struct next_cgraph_node *cur_node;
  104513. + tree ret = gimple_return_retval(stmt);
  104514. +
  104515. + if (ret == NULL_TREE)
  104516. + return head;
  104517. +
  104518. + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
  104519. + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
  104520. + continue;
  104521. + if (cur_node->num == 0)
  104522. + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
  104523. + }
  104524. +
  104525. + return head;
  104526. +}
  104527. +
  104528. +/* Check the call stmts in the functions on the next cgraph node list (these functions will be in the hash table and they are reachable from ipa).
  104529. + * If the call stmt is in the next cgraph node list then it's an interesting call.
  104530. + */
  104531. +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
  104532. +{
  104533. + unsigned int argnum;
  104534. + tree arg;
  104535. + const_tree fndecl;
  104536. + struct next_cgraph_node *cur_node;
  104537. +
  104538. + fndecl = gimple_call_fndecl(stmt);
  104539. + if (fndecl == NULL_TREE)
  104540. + return head;
  104541. +
  104542. + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
  104543. + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
  104544. + continue;
  104545. + argnum = get_correct_arg_count(cur_node->num, fndecl);
  104546. + gcc_assert(argnum != CANNOT_FIND_ARG);
  104547. + if (argnum == 0)
  104548. + continue;
  104549. +
  104550. + arg = gimple_call_arg(stmt, argnum - 1);
  104551. + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
  104552. + }
  104553. +
  104554. + return head;
  104555. +}
  104556. +
  104557. +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
  104558. +{
  104559. + if (!operand_equal_p(orig_node, node, 0))
  104560. + return WRONG_NODE;
  104561. + if (skip_types(node))
  104562. + return WRONG_NODE;
  104563. + return ret_count;
  104564. +}
  104565. +
  104566. +// Get the index of the rhs node in an assignment
  104567. +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
  104568. +{
  104569. + const_tree rhs1, rhs2;
  104570. + unsigned int ret;
  104571. +
  104572. + gcc_assert(stmt);
  104573. + gcc_assert(is_gimple_assign(stmt));
  104574. +
  104575. + rhs1 = gimple_assign_rhs1(stmt);
  104576. + gcc_assert(rhs1 != NULL_TREE);
  104577. +
  104578. + switch (gimple_num_ops(stmt)) {
  104579. + case 2:
  104580. + return check_ops(node, rhs1, 1);
  104581. + case 3:
  104582. + ret = check_ops(node, rhs1, 1);
  104583. + if (ret != WRONG_NODE)
  104584. + return ret;
  104585. +
  104586. + rhs2 = gimple_assign_rhs2(stmt);
  104587. + gcc_assert(rhs2 != NULL_TREE);
  104588. + return check_ops(node, rhs2, 2);
  104589. + default:
  104590. + gcc_unreachable();
  104591. + }
  104592. +}
  104593. +
  104594. +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
  104595. +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
  104596. +{
  104597. + unsigned int i;
  104598. +
  104599. + if (gimple_call_fndecl(stmt) == NULL_TREE)
  104600. + return CANNOT_FIND_ARG;
  104601. +
  104602. + for (i = 0; i < gimple_call_num_args(stmt); i++) {
  104603. + tree node;
  104604. +
  104605. + node = gimple_call_arg(stmt, i);
  104606. + if (!operand_equal_p(arg, node, 0))
  104607. + continue;
  104608. + if (!skip_types(node))
  104609. + return i + 1;
  104610. + }
  104611. +
  104612. + return CANNOT_FIND_ARG;
  104613. +}
  104614. +
  104615. +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
  104616. + * any of return, call or assignment stmts (because of inlining).
  104617. + */
  104618. +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
  104619. +{
  104620. + use_operand_p use_p;
  104621. + imm_use_iterator imm_iter;
  104622. + unsigned int argnum;
  104623. +
  104624. + gcc_assert(TREE_CODE(node) == SSA_NAME);
  104625. +
  104626. + if (pointer_set_insert(visited, node))
  104627. + return head;
  104628. +
  104629. + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
  104630. + gimple stmt = USE_STMT(use_p);
  104631. +
  104632. + if (stmt == NULL)
  104633. + return head;
  104634. + if (is_gimple_debug(stmt))
  104635. + continue;
  104636. +
  104637. + switch (gimple_code(stmt)) {
  104638. + case GIMPLE_CALL:
  104639. + argnum = find_arg_number_gimple(node, stmt);
  104640. + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
  104641. + break;
  104642. + case GIMPLE_RETURN:
  104643. + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
  104644. + break;
  104645. + case GIMPLE_ASSIGN:
  104646. + argnum = get_assign_ops_count(stmt, node);
  104647. + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
  104648. + break;
  104649. + case GIMPLE_PHI: {
  104650. + tree result = gimple_phi_result(stmt);
  104651. + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
  104652. + break;
  104653. + }
  104654. + case GIMPLE_ASM:
  104655. + if (gimple_asm_noutputs(stmt) != 0)
  104656. + break;
  104657. + if (!is_size_overflow_asm(stmt))
  104658. + break;
  104659. + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
  104660. + break;
  104661. + case GIMPLE_COND:
  104662. + case GIMPLE_SWITCH:
  104663. + break;
  104664. + default:
  104665. + debug_gimple_stmt(stmt);
  104666. + gcc_unreachable();
  104667. + break;
  104668. + }
  104669. + }
  104670. + return head;
  104671. +}
  104672. +
  104673. +static void remove_size_overflow_asm(gimple stmt)
  104674. +{
  104675. + gimple_stmt_iterator gsi;
  104676. + tree input, output;
  104677. +
  104678. + if (!is_size_overflow_asm(stmt))
  104679. + return;
  104680. +
  104681. + if (gimple_asm_noutputs(stmt) == 0) {
  104682. + gsi = gsi_for_stmt(stmt);
  104683. + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
  104684. + gsi_remove(&gsi, true);
  104685. + return;
  104686. + }
  104687. +
  104688. + input = gimple_asm_input_op(stmt, 0);
  104689. + output = gimple_asm_output_op(stmt, 0);
  104690. + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
  104691. +}
  104692. +
  104693. +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
  104694. + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
  104695. + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
  104696. + */
  104697. +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
  104698. +{
  104699. + const_tree output;
  104700. + struct pointer_set_t *visited;
  104701. + gimple intentional_asm = NOT_INTENTIONAL_ASM;
  104702. +
  104703. + if (!is_size_overflow_asm(stmt))
  104704. + return head;
  104705. +
  104706. + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
  104707. + intentional_asm = stmt;
  104708. +
  104709. + gcc_assert(gimple_asm_ninputs(stmt) == 1);
  104710. +
  104711. + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
  104712. + return head;
  104713. +
  104714. + if (gimple_asm_noutputs(stmt) == 0) {
  104715. + const_tree input;
  104716. +
  104717. + if (!is_size_overflow_intentional_asm_turn_off(stmt))
  104718. + return head;
  104719. +
  104720. + input = gimple_asm_input_op(stmt, 0);
  104721. + remove_size_overflow_asm(stmt);
  104722. + if (is_gimple_constant(TREE_VALUE(input)))
  104723. + return head;
  104724. + visited = pointer_set_create();
  104725. + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
  104726. + pointer_set_destroy(visited);
  104727. + return head;
  104728. + }
  104729. +
  104730. + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
  104731. + remove_size_overflow_asm(stmt);
  104732. +
  104733. + visited = pointer_set_create();
  104734. + output = gimple_asm_output_op(stmt, 0);
  104735. + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
  104736. + pointer_set_destroy(visited);
  104737. + return head;
  104738. +}
  104739. +
  104740. +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
  104741. + * or a call stmt or a return stmt and store them in the interesting_node list
  104742. + */
  104743. +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
  104744. +{
  104745. + basic_block bb;
  104746. + struct interesting_node *head = NULL;
  104747. +
  104748. + FOR_ALL_BB_FN(bb, cfun) {
  104749. + gimple_stmt_iterator gsi;
  104750. +
  104751. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  104752. + enum gimple_code code;
  104753. + gimple stmt = gsi_stmt(gsi);
  104754. +
  104755. + code = gimple_code(stmt);
  104756. +
  104757. + if (code == GIMPLE_ASM)
  104758. + head = handle_stmt_by_size_overflow_asm(stmt, head);
  104759. +
  104760. + if (!next_node)
  104761. + continue;
  104762. + if (code == GIMPLE_CALL)
  104763. + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
  104764. + if (code == GIMPLE_RETURN)
  104765. + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
  104766. + }
  104767. + }
  104768. + return head;
  104769. +}
  104770. +
  104771. +static void free_interesting_node(struct interesting_node *head)
  104772. +{
  104773. + struct interesting_node *cur;
  104774. +
  104775. + while (head) {
  104776. + cur = head->next;
  104777. +#if BUILDING_GCC_VERSION <= 4007
  104778. + VEC_free(tree, gc, head->last_nodes);
  104779. +#else
  104780. + vec_free(head->last_nodes);
  104781. +#endif
  104782. + free(head);
  104783. + head = cur;
  104784. + }
  104785. +}
  104786. +
  104787. +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
  104788. +{
  104789. + struct visited_fns *new_visited_fns;
  104790. +
  104791. + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
  104792. + new_visited_fns->fndecl = cur_node->fndecl;
  104793. + new_visited_fns->num = cur_node->num;
  104794. + new_visited_fns->first_stmt = cur_node->first_stmt;
  104795. + new_visited_fns->next = NULL;
  104796. +
  104797. + if (!head)
  104798. + return new_visited_fns;
  104799. +
  104800. + new_visited_fns->next = head;
  104801. + return new_visited_fns;
  104802. +}
  104803. +
  104804. +/* Check whether the function was already visited_fns. If the fndecl, the arg count of the fndecl and the first_stmt (call or return) are same then
  104805. + * it is a visited_fns function.
  104806. + */
  104807. +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
  104808. +{
  104809. + struct visited_fns *cur;
  104810. +
  104811. + if (!head)
  104812. + return false;
  104813. +
  104814. + for (cur = head; cur; cur = cur->next) {
  104815. + if (cur_node->first_stmt != cur->first_stmt)
  104816. + continue;
  104817. + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
  104818. + continue;
  104819. + if (cur_node->num == cur->num)
  104820. + return true;
  104821. + }
  104822. + return false;
  104823. +}
  104824. +
  104825. +static void free_next_cgraph_node(struct next_cgraph_node *head)
  104826. +{
  104827. + struct next_cgraph_node *cur;
  104828. +
  104829. + while (head) {
  104830. + cur = head->next;
  104831. + free(head);
  104832. + head = cur;
  104833. + }
  104834. +}
  104835. +
  104836. +static void remove_all_size_overflow_asm(void)
  104837. +{
  104838. + basic_block bb;
  104839. +
  104840. + FOR_ALL_BB_FN(bb, cfun) {
  104841. + gimple_stmt_iterator si;
  104842. +
  104843. + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
  104844. + remove_size_overflow_asm(gsi_stmt(si));
  104845. + }
  104846. +}
  104847. +
  104848. +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
  104849. + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
  104850. + * the newly collected interesting functions (they are interesting if there is control flow between
  104851. + * the interesting stmts and them).
  104852. + */
  104853. +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
  104854. +{
  104855. + struct visited *visited;
  104856. + struct interesting_node *head, *cur_node;
  104857. + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
  104858. +
  104859. + set_current_function_decl(NODE_DECL(node));
  104860. + call_count = 0;
  104861. +
  104862. + head = collect_interesting_stmts(next_node);
  104863. +
  104864. + visited = create_visited();
  104865. + for (cur_node = head; cur_node; cur_node = cur_node->next) {
  104866. + if (is_visited_fns_function(visited_fns, cur_node))
  104867. + continue;
  104868. + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
  104869. + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
  104870. + }
  104871. +
  104872. + free_visited(visited);
  104873. + free_interesting_node(head);
  104874. + remove_all_size_overflow_asm();
  104875. + unset_current_function_decl();
  104876. +
  104877. + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
  104878. + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
  104879. +
  104880. + free_next_cgraph_node(cnodes_head);
  104881. + return visited_fns;
  104882. +}
  104883. +
  104884. +static void free_visited_fns(struct visited_fns *head)
  104885. +{
  104886. + struct visited_fns *cur;
  104887. +
  104888. + while (head) {
  104889. + cur = head->next;
  104890. + free(head);
  104891. + head = cur;
  104892. + }
  104893. +}
  104894. +
  104895. +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
  104896. +unsigned int search_function(void)
  104897. +{
  104898. + struct cgraph_node *node;
  104899. + struct visited_fns *visited_fns = NULL;
  104900. +
  104901. + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
  104902. + gcc_assert(cgraph_function_flags_ready);
  104903. +#if BUILDING_GCC_VERSION <= 4007
  104904. + gcc_assert(node->reachable);
  104905. +#endif
  104906. +
  104907. + visited_fns = handle_function(node, NULL, visited_fns);
  104908. + }
  104909. +
  104910. + free_visited_fns(visited_fns);
  104911. + return 0;
  104912. +}
  104913. +
  104914. +#if BUILDING_GCC_VERSION >= 4009
  104915. +static const struct pass_data insert_size_overflow_check_data = {
  104916. +#else
  104917. +static struct ipa_opt_pass_d insert_size_overflow_check = {
  104918. + .pass = {
  104919. +#endif
  104920. + .type = SIMPLE_IPA_PASS,
  104921. + .name = "size_overflow",
  104922. +#if BUILDING_GCC_VERSION >= 4008
  104923. + .optinfo_flags = OPTGROUP_NONE,
  104924. +#endif
  104925. +#if BUILDING_GCC_VERSION >= 4009
  104926. + .has_gate = false,
  104927. + .has_execute = true,
  104928. +#else
  104929. + .gate = NULL,
  104930. + .execute = search_function,
  104931. + .sub = NULL,
  104932. + .next = NULL,
  104933. + .static_pass_number = 0,
  104934. +#endif
  104935. + .tv_id = TV_NONE,
  104936. + .properties_required = 0,
  104937. + .properties_provided = 0,
  104938. + .properties_destroyed = 0,
  104939. + .todo_flags_start = 0,
  104940. + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_ggc_collect | TODO_verify_flow | TODO_dump_cgraph | TODO_dump_func | TODO_update_ssa_no_phi,
  104941. +#if BUILDING_GCC_VERSION < 4009
  104942. + },
  104943. + .generate_summary = NULL,
  104944. + .write_summary = NULL,
  104945. + .read_summary = NULL,
  104946. +#if BUILDING_GCC_VERSION >= 4006
  104947. + .write_optimization_summary = NULL,
  104948. + .read_optimization_summary = NULL,
  104949. +#endif
  104950. + .stmt_fixup = NULL,
  104951. + .function_transform_todo_flags_start = 0,
  104952. + .function_transform = NULL,
  104953. + .variable_transform = NULL,
  104954. +#endif
  104955. +};
  104956. +
  104957. +#if BUILDING_GCC_VERSION >= 4009
  104958. +namespace {
  104959. +class insert_size_overflow_check : public ipa_opt_pass_d {
  104960. +public:
  104961. + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
  104962. + unsigned int execute() { return search_function(); }
  104963. +};
  104964. +}
  104965. +#endif
  104966. +
  104967. +struct opt_pass *make_insert_size_overflow_check(void)
  104968. +{
  104969. +#if BUILDING_GCC_VERSION >= 4009
  104970. + return new insert_size_overflow_check();
  104971. +#else
  104972. + return &insert_size_overflow_check.pass;
  104973. +#endif
  104974. +}
  104975. +
  104976. diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
  104977. new file mode 100644
  104978. index 0000000..967c0b2
  104979. --- /dev/null
  104980. +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
  104981. @@ -0,0 +1,635 @@
  104982. +/*
  104983. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  104984. + * Licensed under the GPL v2, or (at your option) v3
  104985. + *
  104986. + * Homepage:
  104987. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  104988. + *
  104989. + * Documentation:
  104990. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  104991. + *
  104992. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  104993. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  104994. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  104995. + *
  104996. + * Usage:
  104997. + * $ make
  104998. + * $ make run
  104999. + */
  105000. +
  105001. +#include "gcc-common.h"
  105002. +#include "size_overflow.h"
  105003. +
  105004. +/* Get the param of the intentional_overflow attribute.
  105005. + * * 0: MARK_NOT_INTENTIONAL
  105006. + * * 1..MAX_PARAM: MARK_YES
  105007. + * * -1: MARK_TURN_OFF
  105008. + */
  105009. +static tree get_attribute_param(const_tree decl)
  105010. +{
  105011. + const_tree attr;
  105012. +
  105013. + if (decl == NULL_TREE)
  105014. + return NULL_TREE;
  105015. +
  105016. + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
  105017. + if (!attr || !TREE_VALUE(attr))
  105018. + return NULL_TREE;
  105019. +
  105020. + return TREE_VALUE(attr);
  105021. +}
  105022. +
  105023. +// MARK_TURN_OFF
  105024. +bool is_turn_off_intentional_attr(const_tree decl)
  105025. +{
  105026. + const_tree param_head;
  105027. +
  105028. + param_head = get_attribute_param(decl);
  105029. + if (param_head == NULL_TREE)
  105030. + return false;
  105031. +
  105032. + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
  105033. + return true;
  105034. + return false;
  105035. +}
  105036. +
  105037. +// MARK_NOT_INTENTIONAL
  105038. +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
  105039. +{
  105040. + const_tree param_head;
  105041. +
  105042. + if (argnum == 0)
  105043. + return false;
  105044. +
  105045. + param_head = get_attribute_param(decl);
  105046. + if (param_head == NULL_TREE)
  105047. + return false;
  105048. +
  105049. + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
  105050. + return true;
  105051. + return false;
  105052. +}
  105053. +
  105054. +// MARK_YES
  105055. +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
  105056. +{
  105057. + tree param, param_head;
  105058. +
  105059. + if (argnum == 0)
  105060. + return false;
  105061. +
  105062. + param_head = get_attribute_param(decl);
  105063. + for (param = param_head; param; param = TREE_CHAIN(param))
  105064. + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
  105065. + return true;
  105066. + return false;
  105067. +}
  105068. +
  105069. +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
  105070. +{
  105071. + location_t loc;
  105072. +
  105073. + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
  105074. + return;
  105075. +
  105076. + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
  105077. + return;
  105078. +
  105079. + loc = DECL_SOURCE_LOCATION(decl);
  105080. + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
  105081. +}
  105082. +
  105083. +// Get the field decl of a component ref for intentional_overflow checking
  105084. +static const_tree search_field_decl(const_tree comp_ref)
  105085. +{
  105086. + const_tree field = NULL_TREE;
  105087. + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
  105088. +
  105089. + for (i = 0; i < len; i++) {
  105090. + field = TREE_OPERAND(comp_ref, i);
  105091. + if (TREE_CODE(field) == FIELD_DECL)
  105092. + break;
  105093. + }
  105094. + gcc_assert(TREE_CODE(field) == FIELD_DECL);
  105095. + return field;
  105096. +}
  105097. +
  105098. +/* Get the type of the intentional_overflow attribute of a node
  105099. + * * MARK_TURN_OFF
  105100. + * * MARK_YES
  105101. + * * MARK_NO
  105102. + * * MARK_NOT_INTENTIONAL
  105103. + */
  105104. +enum mark get_intentional_attr_type(const_tree node)
  105105. +{
  105106. + const_tree cur_decl;
  105107. +
  105108. + if (node == NULL_TREE)
  105109. + return MARK_NO;
  105110. +
  105111. + switch (TREE_CODE(node)) {
  105112. + case COMPONENT_REF:
  105113. + cur_decl = search_field_decl(node);
  105114. + if (is_turn_off_intentional_attr(cur_decl))
  105115. + return MARK_TURN_OFF;
  105116. + if (is_end_intentional_intentional_attr(cur_decl, 1))
  105117. + return MARK_YES;
  105118. + break;
  105119. + case PARM_DECL: {
  105120. + unsigned int argnum;
  105121. +
  105122. + cur_decl = DECL_ORIGIN(current_function_decl);
  105123. + argnum = find_arg_number_tree(node, cur_decl);
  105124. + if (argnum == CANNOT_FIND_ARG)
  105125. + return MARK_NO;
  105126. + if (is_yes_intentional_attr(cur_decl, argnum))
  105127. + return MARK_YES;
  105128. + if (is_end_intentional_intentional_attr(cur_decl, argnum))
  105129. + return MARK_NOT_INTENTIONAL;
  105130. + break;
  105131. + }
  105132. + case FUNCTION_DECL:
  105133. + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
  105134. + return MARK_TURN_OFF;
  105135. + break;
  105136. + default:
  105137. + break;
  105138. + }
  105139. + return MARK_NO;
  105140. +}
  105141. +
  105142. +// Search for the intentional_overflow attribute on the last nodes
  105143. +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
  105144. +{
  105145. + unsigned int i;
  105146. + tree last_node;
  105147. + enum mark mark = MARK_NO;
  105148. +
  105149. +#if BUILDING_GCC_VERSION <= 4007
  105150. + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
  105151. +#else
  105152. + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
  105153. +#endif
  105154. + mark = get_intentional_attr_type(last_node);
  105155. + if (mark != MARK_NO)
  105156. + break;
  105157. + }
  105158. + return mark;
  105159. +}
  105160. +
  105161. +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
  105162. + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
  105163. + */
  105164. +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
  105165. +{
  105166. + if (!cur_node->intentional_mark_from_gimple)
  105167. + return false;
  105168. +
  105169. + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
  105170. + cur_node->intentional_attr_cur_fndecl = MARK_YES;
  105171. + else
  105172. + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
  105173. +
  105174. + // skip param decls
  105175. + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
  105176. + return true;
  105177. + return true;
  105178. +}
  105179. +
  105180. +/* Search intentional_overflow attribute on caller and on callee too.
  105181. + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
  105182. + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
  105183. + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
  105184. +*/
  105185. +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
  105186. +{
  105187. + const_tree fndecl;
  105188. +
  105189. + if (is_intentional_attribute_from_gimple(cur_node))
  105190. + return;
  105191. +
  105192. + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
  105193. + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
  105194. + return;
  105195. + }
  105196. +
  105197. + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
  105198. + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
  105199. + return;
  105200. + }
  105201. +
  105202. + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
  105203. + return;
  105204. +
  105205. + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
  105206. + if (is_turn_off_intentional_attr(fndecl)) {
  105207. + cur_node->intentional_attr_decl = MARK_TURN_OFF;
  105208. + return;
  105209. + }
  105210. +
  105211. + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
  105212. + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
  105213. + else if (is_yes_intentional_attr(fndecl, cur_node->num))
  105214. + cur_node->intentional_attr_decl = MARK_YES;
  105215. +
  105216. + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
  105217. + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
  105218. +}
  105219. +
  105220. +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
  105221. +{
  105222. + const_tree rhs1, lhs, rhs1_type, lhs_type;
  105223. + enum machine_mode lhs_mode, rhs_mode;
  105224. + gimple def_stmt = get_def_stmt(no_const_rhs);
  105225. +
  105226. + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
  105227. + return false;
  105228. +
  105229. + rhs1 = gimple_assign_rhs1(def_stmt);
  105230. + lhs = gimple_assign_lhs(def_stmt);
  105231. + rhs1_type = TREE_TYPE(rhs1);
  105232. + lhs_type = TREE_TYPE(lhs);
  105233. + rhs_mode = TYPE_MODE(rhs1_type);
  105234. + lhs_mode = TYPE_MODE(lhs_type);
  105235. + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
  105236. + return false;
  105237. +
  105238. + return true;
  105239. +}
  105240. +
  105241. +static bool no_uses(tree node)
  105242. +{
  105243. + imm_use_iterator imm_iter;
  105244. + use_operand_p use_p;
  105245. +
  105246. + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
  105247. + const_gimple use_stmt = USE_STMT(use_p);
  105248. +
  105249. + if (use_stmt == NULL)
  105250. + return true;
  105251. + if (is_gimple_debug(use_stmt))
  105252. + continue;
  105253. + return false;
  105254. + }
  105255. + return true;
  105256. +}
  105257. +
  105258. +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
  105259. +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
  105260. +{
  105261. + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
  105262. + gimple def_stmt = get_def_stmt(lhs);
  105263. +
  105264. + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
  105265. + return false;
  105266. +
  105267. + rhs1 = gimple_assign_rhs1(def_stmt);
  105268. + rhs_type = TREE_TYPE(rhs1);
  105269. + lhs_type = TREE_TYPE(lhs);
  105270. + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
  105271. + return false;
  105272. + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
  105273. + return false;
  105274. +
  105275. + def_stmt = get_def_stmt(rhs1);
  105276. + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
  105277. + return false;
  105278. +
  105279. + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
  105280. + return false;
  105281. +
  105282. + rhs1 = gimple_assign_rhs1(def_stmt);
  105283. + rhs2 = gimple_assign_rhs2(def_stmt);
  105284. + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
  105285. + return false;
  105286. +
  105287. + if (is_gimple_constant(rhs2))
  105288. + not_const_rhs = rhs1;
  105289. + else
  105290. + not_const_rhs = rhs2;
  105291. +
  105292. + return no_uses(not_const_rhs);
  105293. +}
  105294. +
  105295. +static bool is_lt_signed_type_max(const_tree rhs)
  105296. +{
  105297. + const_tree new_type, type_max, type = TREE_TYPE(rhs);
  105298. +
  105299. + if (!TYPE_UNSIGNED(type))
  105300. + return true;
  105301. +
  105302. + switch (TYPE_MODE(type)) {
  105303. + case QImode:
  105304. + new_type = intQI_type_node;
  105305. + break;
  105306. + case HImode:
  105307. + new_type = intHI_type_node;
  105308. + break;
  105309. + case SImode:
  105310. + new_type = intSI_type_node;
  105311. + break;
  105312. + case DImode:
  105313. + new_type = intDI_type_node;
  105314. + break;
  105315. + default:
  105316. + debug_tree((tree)type);
  105317. + gcc_unreachable();
  105318. + }
  105319. +
  105320. + type_max = TYPE_MAX_VALUE(new_type);
  105321. + if (!tree_int_cst_lt(type_max, rhs))
  105322. + return true;
  105323. +
  105324. + return false;
  105325. +}
  105326. +
  105327. +static bool is_gt_zero(const_tree rhs)
  105328. +{
  105329. + const_tree type = TREE_TYPE(rhs);
  105330. +
  105331. + if (TYPE_UNSIGNED(type))
  105332. + return true;
  105333. +
  105334. + if (!tree_int_cst_lt(rhs, integer_zero_node))
  105335. + return true;
  105336. +
  105337. + return false;
  105338. +}
  105339. +
  105340. +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
  105341. +{
  105342. + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
  105343. + return false;
  105344. + if (!is_gimple_constant(rhs))
  105345. + return false;
  105346. +
  105347. + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
  105348. + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
  105349. + return false;
  105350. +
  105351. + return true;
  105352. +}
  105353. +
  105354. +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
  105355. +{
  105356. + gimple assign;
  105357. + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
  105358. + tree origtype = TREE_TYPE(orig_rhs);
  105359. +
  105360. + gcc_assert(is_gimple_assign(stmt));
  105361. +
  105362. + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
  105363. + pointer_set_insert(visited->my_stmts, assign);
  105364. + return gimple_assign_lhs(assign);
  105365. +}
  105366. +
  105367. +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
  105368. +{
  105369. + tree new_rhs, orig_rhs;
  105370. + void (*gimple_assign_set_rhs)(gimple, tree);
  105371. + tree rhs1 = gimple_assign_rhs1(stmt);
  105372. + tree rhs2 = gimple_assign_rhs2(stmt);
  105373. + tree lhs = gimple_assign_lhs(stmt);
  105374. +
  105375. + if (!check_overflow)
  105376. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  105377. +
  105378. + if (change_rhs == NULL_TREE)
  105379. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  105380. +
  105381. + if (new_rhs2 == NULL_TREE) {
  105382. + orig_rhs = rhs1;
  105383. + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
  105384. + } else {
  105385. + orig_rhs = rhs2;
  105386. + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
  105387. + }
  105388. +
  105389. + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
  105390. +
  105391. + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
  105392. + gimple_assign_set_rhs(stmt, new_rhs);
  105393. + update_stmt(stmt);
  105394. +
  105395. + return create_assign(visited, stmt, lhs, AFTER_STMT);
  105396. +}
  105397. +
  105398. +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
  105399. +{
  105400. + gimple rhs1_def_stmt, rhs2_def_stmt;
  105401. + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
  105402. + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
  105403. + const_tree rhs1 = gimple_assign_rhs1(stmt);
  105404. + const_tree rhs2 = gimple_assign_rhs2(stmt);
  105405. +
  105406. + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
  105407. + return false;
  105408. +
  105409. + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
  105410. +
  105411. + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
  105412. + return false;
  105413. +
  105414. + rhs1_def_stmt = get_def_stmt(rhs1);
  105415. + rhs2_def_stmt = get_def_stmt(rhs2);
  105416. + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
  105417. + return false;
  105418. +
  105419. + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
  105420. + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
  105421. + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
  105422. + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
  105423. + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
  105424. + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
  105425. + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
  105426. + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
  105427. + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
  105428. + return false;
  105429. + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
  105430. + return false;
  105431. +
  105432. + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
  105433. + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
  105434. + return true;
  105435. +}
  105436. +
  105437. +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
  105438. +{
  105439. + gimple assign;
  105440. + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
  105441. + tree type = TREE_TYPE(rhs1);
  105442. + tree lhs = create_new_var(type);
  105443. +
  105444. + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
  105445. + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
  105446. + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
  105447. +
  105448. + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
  105449. + update_stmt(assign);
  105450. + pointer_set_insert(visited->my_stmts, assign);
  105451. + return assign;
  105452. +}
  105453. +
  105454. +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
  105455. +{
  105456. + gimple_stmt_iterator gsi;
  105457. + gimple cast_stmt;
  105458. + tree type = TREE_TYPE(node);
  105459. +
  105460. + if (types_compatible_p(type, intTI_type_node))
  105461. + return node;
  105462. +
  105463. + gsi = gsi_for_stmt(stmt);
  105464. + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
  105465. + pointer_set_insert(visited->my_stmts, cast_stmt);
  105466. + return gimple_assign_lhs(cast_stmt);
  105467. +}
  105468. +
  105469. +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
  105470. +{
  105471. + tree rhs1, def_stmt_rhs1;
  105472. + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
  105473. +
  105474. + def_stmt = get_def_stmt(var);
  105475. + if (!gimple_assign_cast_p(def_stmt))
  105476. + return NULL_TREE;
  105477. + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
  105478. +
  105479. + rhs1 = gimple_assign_rhs1(def_stmt);
  105480. + rhs1_def_stmt = get_def_stmt(rhs1);
  105481. + if (!gimple_assign_cast_p(rhs1_def_stmt))
  105482. + return rhs1;
  105483. +
  105484. + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
  105485. + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
  105486. +
  105487. + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
  105488. + case GIMPLE_CALL:
  105489. + case GIMPLE_NOP:
  105490. + case GIMPLE_ASM:
  105491. + case GIMPLE_PHI:
  105492. + return def_stmt_rhs1;
  105493. + case GIMPLE_ASSIGN:
  105494. + return rhs1;
  105495. + default:
  105496. + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
  105497. + gcc_unreachable();
  105498. + }
  105499. +}
  105500. +
  105501. +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
  105502. +{
  105503. + tree new_rhs1, new_rhs2;
  105504. + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
  105505. + gimple assign, stmt = get_def_stmt(lhs);
  105506. + tree rhs1 = gimple_assign_rhs1(stmt);
  105507. + tree rhs2 = gimple_assign_rhs2(stmt);
  105508. +
  105509. + if (!is_subtraction_special(visited, stmt))
  105510. + return NULL_TREE;
  105511. +
  105512. + new_rhs1 = expand(visited, caller_node, rhs1);
  105513. + new_rhs2 = expand(visited, caller_node, rhs2);
  105514. +
  105515. + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
  105516. + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
  105517. +
  105518. + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
  105519. + return NULL_TREE;
  105520. +
  105521. + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
  105522. + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
  105523. + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
  105524. + }
  105525. +
  105526. + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
  105527. + new_lhs = gimple_assign_lhs(assign);
  105528. + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
  105529. +
  105530. + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
  105531. +}
  105532. +
  105533. +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
  105534. +{
  105535. + const_gimple def_stmt;
  105536. +
  105537. + if (TREE_CODE(rhs) != SSA_NAME)
  105538. + return false;
  105539. +
  105540. + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
  105541. + return false;
  105542. +
  105543. + def_stmt = get_def_stmt(rhs);
  105544. + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
  105545. + return false;
  105546. +
  105547. + return true;
  105548. +}
  105549. +
  105550. +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
  105551. + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
  105552. + * fffffff * 16 > signed max -> truncate
  105553. + */
  105554. +static bool look_for_mult_and_add(const_gimple stmt)
  105555. +{
  105556. + const_tree res;
  105557. + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
  105558. + const_gimple def_stmt;
  105559. +
  105560. + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
  105561. + return false;
  105562. + if (!is_gimple_assign(stmt))
  105563. + return false;
  105564. + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
  105565. + return false;
  105566. +
  105567. + rhs1 = gimple_assign_rhs1(stmt);
  105568. + rhs2 = gimple_assign_rhs2(stmt);
  105569. + if (is_gimple_constant(rhs1)) {
  105570. + const_rhs = rhs1;
  105571. + def_stmt = get_def_stmt(rhs2);
  105572. + } else if (is_gimple_constant(rhs2)) {
  105573. + const_rhs = rhs2;
  105574. + def_stmt = get_def_stmt(rhs1);
  105575. + } else
  105576. + return false;
  105577. +
  105578. + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
  105579. + return false;
  105580. +
  105581. + def_rhs1 = gimple_assign_rhs1(def_stmt);
  105582. + def_rhs2 = gimple_assign_rhs2(def_stmt);
  105583. + if (is_gimple_constant(def_rhs1))
  105584. + def_const_rhs = def_rhs1;
  105585. + else if (is_gimple_constant(def_rhs2))
  105586. + def_const_rhs = def_rhs2;
  105587. + else
  105588. + return false;
  105589. +
  105590. + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
  105591. + if (is_lt_signed_type_max(res) && is_gt_zero(res))
  105592. + return false;
  105593. + return true;
  105594. +}
  105595. +
  105596. +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
  105597. +{
  105598. + const_gimple def_stmt_1, def_stmt_2;
  105599. + const_tree rhs1, rhs2;
  105600. + bool add_mul_rhs1, add_mul_rhs2;
  105601. +
  105602. + rhs1 = gimple_assign_rhs1(stmt);
  105603. + def_stmt_1 = get_def_stmt(rhs1);
  105604. + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
  105605. +
  105606. + rhs2 = gimple_assign_rhs2(stmt);
  105607. + def_stmt_2 = get_def_stmt(rhs2);
  105608. + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
  105609. +
  105610. + if (add_mul_rhs1)
  105611. + return RHS1_INTENTIONAL_OVERFLOW;
  105612. + if (add_mul_rhs2)
  105613. + return RHS2_INTENTIONAL_OVERFLOW;
  105614. + return NO_INTENTIONAL_OVERFLOW;
  105615. +}
  105616. +
  105617. diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
  105618. new file mode 100644
  105619. index 0000000..ca4def3
  105620. --- /dev/null
  105621. +++ b/tools/gcc/size_overflow_plugin/misc.c
  105622. @@ -0,0 +1,180 @@
  105623. +/*
  105624. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  105625. + * Licensed under the GPL v2, or (at your option) v3
  105626. + *
  105627. + * Homepage:
  105628. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  105629. + *
  105630. + * Documentation:
  105631. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  105632. + *
  105633. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  105634. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  105635. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  105636. + *
  105637. + * Usage:
  105638. + * $ make
  105639. + * $ make run
  105640. + */
  105641. +
  105642. +#include "gcc-common.h"
  105643. +#include "size_overflow.h"
  105644. +
  105645. +void set_current_function_decl(tree fndecl)
  105646. +{
  105647. + gcc_assert(fndecl != NULL_TREE);
  105648. +
  105649. + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
  105650. + calculate_dominance_info(CDI_DOMINATORS);
  105651. + current_function_decl = fndecl;
  105652. +}
  105653. +
  105654. +void unset_current_function_decl(void)
  105655. +{
  105656. + free_dominance_info(CDI_DOMINATORS);
  105657. + pop_cfun();
  105658. + current_function_decl = NULL_TREE;
  105659. +}
  105660. +
  105661. +static bool is_bool(const_tree node)
  105662. +{
  105663. + const_tree type;
  105664. +
  105665. + if (node == NULL_TREE)
  105666. + return false;
  105667. +
  105668. + type = TREE_TYPE(node);
  105669. + if (!INTEGRAL_TYPE_P(type))
  105670. + return false;
  105671. + if (TREE_CODE(type) == BOOLEAN_TYPE)
  105672. + return true;
  105673. + if (TYPE_PRECISION(type) == 1)
  105674. + return true;
  105675. + return false;
  105676. +}
  105677. +
  105678. +bool skip_types(const_tree var)
  105679. +{
  105680. + tree type;
  105681. + enum tree_code code;
  105682. +
  105683. + if (is_gimple_constant(var))
  105684. + return true;
  105685. +
  105686. + switch (TREE_CODE(var)) {
  105687. + case ADDR_EXPR:
  105688. +#if BUILDING_GCC_VERSION >= 4006
  105689. + case MEM_REF:
  105690. +#endif
  105691. + case ARRAY_REF:
  105692. + case BIT_FIELD_REF:
  105693. + case INDIRECT_REF:
  105694. + case TARGET_MEM_REF:
  105695. + case COMPONENT_REF:
  105696. + case VAR_DECL:
  105697. + case VIEW_CONVERT_EXPR:
  105698. + return true;
  105699. + default:
  105700. + break;
  105701. + }
  105702. +
  105703. + code = TREE_CODE(var);
  105704. + gcc_assert(code == SSA_NAME || code == PARM_DECL);
  105705. +
  105706. + type = TREE_TYPE(var);
  105707. + switch (TREE_CODE(type)) {
  105708. + case INTEGER_TYPE:
  105709. + case ENUMERAL_TYPE:
  105710. + return false;
  105711. + case BOOLEAN_TYPE:
  105712. + return is_bool(var);
  105713. + default:
  105714. + return true;
  105715. + }
  105716. +}
  105717. +
  105718. +gimple get_def_stmt(const_tree node)
  105719. +{
  105720. + gcc_assert(node != NULL_TREE);
  105721. +
  105722. + if (skip_types(node))
  105723. + return NULL;
  105724. +
  105725. + if (TREE_CODE(node) != SSA_NAME)
  105726. + return NULL;
  105727. + return SSA_NAME_DEF_STMT(node);
  105728. +}
  105729. +
  105730. +tree create_new_var(tree type)
  105731. +{
  105732. + tree new_var = create_tmp_var(type, "cicus");
  105733. +
  105734. + add_referenced_var(new_var);
  105735. + return new_var;
  105736. +}
  105737. +
  105738. +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
  105739. +{
  105740. + const_gimple def_stmt = get_def_stmt(rhs);
  105741. +
  105742. + if (force)
  105743. + return false;
  105744. +
  105745. + if (is_gimple_constant(rhs))
  105746. + return false;
  105747. +
  105748. + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
  105749. + return false;
  105750. +
  105751. + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
  105752. + return false;
  105753. +
  105754. + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
  105755. + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
  105756. + return false;
  105757. +
  105758. + return true;
  105759. +}
  105760. +
  105761. +tree cast_a_tree(tree type, tree var)
  105762. +{
  105763. + gcc_assert(type != NULL_TREE);
  105764. + gcc_assert(var != NULL_TREE);
  105765. + gcc_assert(fold_convertible_p(type, var));
  105766. +
  105767. + return fold_convert(type, var);
  105768. +}
  105769. +
  105770. +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
  105771. +{
  105772. + gimple assign, def_stmt;
  105773. +
  105774. + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
  105775. + gcc_assert(!is_gimple_constant(rhs));
  105776. + if (gsi_end_p(*gsi) && before == AFTER_STMT)
  105777. + gcc_unreachable();
  105778. +
  105779. + def_stmt = get_def_stmt(rhs);
  105780. + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
  105781. + return def_stmt;
  105782. +
  105783. + if (lhs == CREATE_NEW_VAR)
  105784. + lhs = create_new_var(dst_type);
  105785. +
  105786. + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
  105787. +
  105788. + if (!gsi_end_p(*gsi)) {
  105789. + location_t loc = gimple_location(gsi_stmt(*gsi));
  105790. + gimple_set_location(assign, loc);
  105791. + }
  105792. +
  105793. + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
  105794. +
  105795. + if (before)
  105796. + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
  105797. + else
  105798. + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
  105799. + update_stmt(assign);
  105800. + return assign;
  105801. +}
  105802. +
  105803. diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
  105804. new file mode 100644
  105805. index 0000000..ee108f0
  105806. --- /dev/null
  105807. +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
  105808. @@ -0,0 +1,161 @@
  105809. +/*
  105810. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  105811. + * Licensed under the GPL v2, or (at your option) v3
  105812. + *
  105813. + * Homepage:
  105814. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  105815. + *
  105816. + * Documentation:
  105817. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  105818. + *
  105819. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  105820. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  105821. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  105822. + *
  105823. + * Usage:
  105824. + * $ make
  105825. + * $ make run
  105826. + */
  105827. +
  105828. +#include "gcc-common.h"
  105829. +#include "size_overflow.h"
  105830. +
  105831. +bool skip_expr_on_double_type(const_gimple stmt)
  105832. +{
  105833. + enum tree_code code = gimple_assign_rhs_code(stmt);
  105834. +
  105835. + switch (code) {
  105836. + case RSHIFT_EXPR:
  105837. + case TRUNC_DIV_EXPR:
  105838. + case CEIL_DIV_EXPR:
  105839. + case FLOOR_DIV_EXPR:
  105840. + case ROUND_DIV_EXPR:
  105841. + case EXACT_DIV_EXPR:
  105842. + case RDIV_EXPR:
  105843. + case TRUNC_MOD_EXPR:
  105844. + case CEIL_MOD_EXPR:
  105845. + case FLOOR_MOD_EXPR:
  105846. + case ROUND_MOD_EXPR:
  105847. + return true;
  105848. + default:
  105849. + return false;
  105850. + }
  105851. +}
  105852. +
  105853. +static bool is_size_overflow_type(const_tree var)
  105854. +{
  105855. + const char *name;
  105856. + const_tree type_name, type;
  105857. +
  105858. + if (var == NULL_TREE)
  105859. + return false;
  105860. +
  105861. + type = TREE_TYPE(var);
  105862. + type_name = TYPE_NAME(type);
  105863. + if (type_name == NULL_TREE)
  105864. + return false;
  105865. +
  105866. + if (DECL_P(type_name))
  105867. + name = DECL_NAME_POINTER(type_name);
  105868. + else
  105869. + name = IDENTIFIER_POINTER(type_name);
  105870. +
  105871. + if (!strncmp(name, "size_overflow_type", 18))
  105872. + return true;
  105873. + return false;
  105874. +}
  105875. +
  105876. +static void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
  105877. +{
  105878. + const_tree orig_rhs1;
  105879. + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
  105880. + gimple down_cast, up_cast;
  105881. + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
  105882. +
  105883. + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
  105884. + down_lhs = gimple_assign_lhs(down_cast);
  105885. +
  105886. + gsi = gsi_for_stmt(use_stmt);
  105887. + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
  105888. + new_lhs = gimple_assign_lhs(up_cast);
  105889. +
  105890. + orig_rhs1 = gimple_assign_rhs1(use_stmt);
  105891. + if (operand_equal_p(orig_rhs1, rhs, 0))
  105892. + gimple_assign_set_rhs1(use_stmt, new_lhs);
  105893. + else
  105894. + gimple_assign_set_rhs2(use_stmt, new_lhs);
  105895. + update_stmt(use_stmt);
  105896. +
  105897. + pointer_set_insert(visited->my_stmts, up_cast);
  105898. + pointer_set_insert(visited->my_stmts, down_cast);
  105899. + pointer_set_insert(visited->skip_expr_casts, up_cast);
  105900. + pointer_set_insert(visited->skip_expr_casts, down_cast);
  105901. +}
  105902. +
  105903. +static tree get_proper_unsigned_half_type(const_tree node)
  105904. +{
  105905. + tree new_type, type;
  105906. +
  105907. + gcc_assert(is_size_overflow_type(node));
  105908. +
  105909. + type = TREE_TYPE(node);
  105910. + switch (TYPE_MODE(type)) {
  105911. + case HImode:
  105912. + new_type = unsigned_intQI_type_node;
  105913. + break;
  105914. + case SImode:
  105915. + new_type = unsigned_intHI_type_node;
  105916. + break;
  105917. + case DImode:
  105918. + new_type = unsigned_intSI_type_node;
  105919. + break;
  105920. + case TImode:
  105921. + new_type = unsigned_intDI_type_node;
  105922. + break;
  105923. + default:
  105924. + gcc_unreachable();
  105925. + }
  105926. +
  105927. + if (TYPE_QUALS(type) != 0)
  105928. + return build_qualified_type(new_type, TYPE_QUALS(type));
  105929. + return new_type;
  105930. +}
  105931. +
  105932. +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
  105933. +{
  105934. + tree type;
  105935. +
  105936. + if (rhs == NULL_TREE)
  105937. + return;
  105938. + if (!is_size_overflow_type(rhs))
  105939. + return;
  105940. +
  105941. + type = get_proper_unsigned_half_type(rhs);
  105942. + if (is_gimple_constant(rhs))
  105943. + return;
  105944. + create_up_and_down_cast(visited, stmt, type, rhs);
  105945. +}
  105946. +
  105947. +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
  105948. +{
  105949. + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
  105950. + return;
  105951. + gcc_assert(is_size_overflow_type(rhs));
  105952. + insert_cast_rhs(visited, stmt, rhs);
  105953. +}
  105954. +
  105955. +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
  105956. +{
  105957. + tree rhs1, rhs2;
  105958. +
  105959. + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
  105960. + rhs1 = gimple_assign_rhs1(stmt);
  105961. + insert_cast(visited, stmt, rhs1);
  105962. + }
  105963. +
  105964. + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
  105965. + rhs2 = gimple_assign_rhs2(stmt);
  105966. + insert_cast(visited, stmt, rhs2);
  105967. + }
  105968. +}
  105969. +
  105970. diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
  105971. new file mode 100644
  105972. index 0000000..0729973
  105973. --- /dev/null
  105974. +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
  105975. @@ -0,0 +1,124 @@
  105976. +#ifndef SIZE_OVERFLOW_H
  105977. +#define SIZE_OVERFLOW_H
  105978. +
  105979. +#define CREATE_NEW_VAR NULL_TREE
  105980. +#define CANNOT_FIND_ARG 32
  105981. +#define MAX_PARAM 31
  105982. +#define BEFORE_STMT true
  105983. +#define AFTER_STMT false
  105984. +
  105985. +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
  105986. +#define YES_ASM_STR "# size_overflow MARK_YES "
  105987. +#define OK_ASM_STR "# size_overflow "
  105988. +
  105989. +enum mark {
  105990. + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
  105991. +};
  105992. +
  105993. +enum intentional_overflow_type {
  105994. + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
  105995. +};
  105996. +
  105997. +struct visited {
  105998. + struct pointer_set_t *stmts;
  105999. + struct pointer_set_t *my_stmts;
  106000. + struct pointer_set_t *skip_expr_casts;
  106001. + struct pointer_set_t *no_cast_check;
  106002. +};
  106003. +
  106004. +// size_overflow_plugin.c
  106005. +extern tree report_size_overflow_decl;
  106006. +extern tree size_overflow_type_HI;
  106007. +extern tree size_overflow_type_SI;
  106008. +extern tree size_overflow_type_DI;
  106009. +extern tree size_overflow_type_TI;
  106010. +
  106011. +
  106012. +// size_overflow_plugin_hash.c
  106013. +struct size_overflow_hash {
  106014. + const struct size_overflow_hash * const next;
  106015. + const char * const name;
  106016. + const unsigned int param;
  106017. +};
  106018. +
  106019. +struct interesting_node {
  106020. + struct interesting_node *next;
  106021. + gimple first_stmt;
  106022. + const_tree fndecl;
  106023. + tree node;
  106024. +#if BUILDING_GCC_VERSION <= 4007
  106025. + VEC(tree, gc) *last_nodes;
  106026. +#else
  106027. + vec<tree, va_gc> *last_nodes;
  106028. +#endif
  106029. + unsigned int num;
  106030. + enum mark intentional_attr_decl;
  106031. + enum mark intentional_attr_cur_fndecl;
  106032. + gimple intentional_mark_from_gimple;
  106033. +};
  106034. +
  106035. +extern bool is_size_overflow_asm(const_gimple stmt);
  106036. +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
  106037. +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
  106038. +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
  106039. +extern bool is_a_return_check(const_tree node);
  106040. +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
  106041. +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
  106042. +
  106043. +
  106044. +// size_overflow_debug.c
  106045. +extern struct opt_pass *make_dump_pass(void);
  106046. +
  106047. +
  106048. +// intentional_overflow.c
  106049. +extern enum mark get_intentional_attr_type(const_tree node);
  106050. +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
  106051. +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
  106052. +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
  106053. +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
  106054. +extern bool is_turn_off_intentional_attr(const_tree decl);
  106055. +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
  106056. +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
  106057. +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
  106058. +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
  106059. +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
  106060. +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
  106061. +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
  106062. +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
  106063. +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
  106064. +
  106065. +
  106066. +// insert_size_overflow_check_ipa.c
  106067. +extern unsigned int search_function(void);
  106068. +extern unsigned int call_count;
  106069. +extern struct opt_pass *make_insert_size_overflow_check(void);
  106070. +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
  106071. +
  106072. +
  106073. +// insert_size_overflow_asm.c
  106074. +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
  106075. +
  106076. +
  106077. +// misc.c
  106078. +extern void set_current_function_decl(tree fndecl);
  106079. +extern void unset_current_function_decl(void);
  106080. +extern gimple get_def_stmt(const_tree node);
  106081. +extern tree create_new_var(tree type);
  106082. +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
  106083. +extern bool skip_types(const_tree var);
  106084. +extern tree cast_a_tree(tree type, tree var);
  106085. +
  106086. +
  106087. +// insert_size_overflow_check_core.c
  106088. +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
  106089. +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
  106090. +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
  106091. +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
  106092. +
  106093. +
  106094. +// remove_unnecessary_dup.c
  106095. +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
  106096. +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
  106097. +extern bool skip_expr_on_double_type(const_gimple stmt);
  106098. +
  106099. +#endif
  106100. diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
  106101. new file mode 100644
  106102. index 0000000..4378111
  106103. --- /dev/null
  106104. +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
  106105. @@ -0,0 +1,116 @@
  106106. +/*
  106107. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  106108. + * Licensed under the GPL v2, or (at your option) v3
  106109. + *
  106110. + * Homepage:
  106111. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  106112. + *
  106113. + * Documentation:
  106114. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  106115. + *
  106116. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  106117. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  106118. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  106119. + *
  106120. + * Usage:
  106121. + * $ make
  106122. + * $ make run
  106123. + */
  106124. +
  106125. +#include "gcc-common.h"
  106126. +
  106127. +static unsigned int dump_functions(void)
  106128. +{
  106129. + struct cgraph_node *node;
  106130. +
  106131. + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
  106132. + basic_block bb;
  106133. +
  106134. + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
  106135. + current_function_decl = NODE_DECL(node);
  106136. +
  106137. + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
  106138. +
  106139. + FOR_ALL_BB_FN(bb, cfun) {
  106140. + gimple_stmt_iterator si;
  106141. +
  106142. + fprintf(stderr, "<bb %u>:\n", bb->index);
  106143. + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
  106144. + debug_gimple_stmt(gsi_stmt(si));
  106145. + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
  106146. + debug_gimple_stmt(gsi_stmt(si));
  106147. + fprintf(stderr, "\n");
  106148. + }
  106149. +
  106150. + fprintf(stderr, "-------------------------------------------------------------------------\n");
  106151. +
  106152. + pop_cfun();
  106153. + current_function_decl = NULL_TREE;
  106154. + }
  106155. +
  106156. + fprintf(stderr, "###############################################################################\n");
  106157. +
  106158. + return 0;
  106159. +}
  106160. +
  106161. +#if BUILDING_GCC_VERSION >= 4009
  106162. +static const struct pass_data dump_pass_data = {
  106163. +#else
  106164. +static struct ipa_opt_pass_d dump_pass = {
  106165. + .pass = {
  106166. +#endif
  106167. + .type = SIMPLE_IPA_PASS,
  106168. + .name = "dump",
  106169. +#if BUILDING_GCC_VERSION >= 4008
  106170. + .optinfo_flags = OPTGROUP_NONE,
  106171. +#endif
  106172. +#if BUILDING_GCC_VERSION >= 4009
  106173. + .has_gate = false,
  106174. + .has_execute = true,
  106175. +#else
  106176. + .gate = NULL,
  106177. + .execute = dump_functions,
  106178. + .sub = NULL,
  106179. + .next = NULL,
  106180. + .static_pass_number = 0,
  106181. +#endif
  106182. + .tv_id = TV_NONE,
  106183. + .properties_required = 0,
  106184. + .properties_provided = 0,
  106185. + .properties_destroyed = 0,
  106186. + .todo_flags_start = 0,
  106187. + .todo_flags_finish = 0,
  106188. +#if BUILDING_GCC_VERSION < 4009
  106189. + },
  106190. + .generate_summary = NULL,
  106191. + .write_summary = NULL,
  106192. + .read_summary = NULL,
  106193. +#if BUILDING_GCC_VERSION >= 4006
  106194. + .write_optimization_summary = NULL,
  106195. + .read_optimization_summary = NULL,
  106196. +#endif
  106197. + .stmt_fixup = NULL,
  106198. + .function_transform_todo_flags_start = 0,
  106199. + .function_transform = NULL,
  106200. + .variable_transform = NULL,
  106201. +#endif
  106202. +};
  106203. +
  106204. +#if BUILDING_GCC_VERSION >= 4009
  106205. +namespace {
  106206. +class dump_pass : public ipa_opt_pass_d {
  106207. +public:
  106208. + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
  106209. + unsigned int execute() { return dump_functions(); }
  106210. +};
  106211. +}
  106212. +#endif
  106213. +
  106214. +struct opt_pass *make_dump_pass(void)
  106215. +{
  106216. +#if BUILDING_GCC_VERSION >= 4009
  106217. + return new dump_pass();
  106218. +#else
  106219. + return &dump_pass.pass;
  106220. +#endif
  106221. +}
  106222. diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
  106223. new file mode 100644
  106224. index 0000000..41777a8
  106225. --- /dev/null
  106226. +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
  106227. @@ -0,0 +1,5934 @@
  106228. +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
  106229. +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
  106230. +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
  106231. +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
  106232. +carl9170_alloc_27 carl9170_alloc 1 27 NULL
  106233. +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
  106234. +padzero_55 padzero 1 55 &sel_read_policyvers_55
  106235. +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
  106236. +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
  106237. +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
  106238. +load_msg_95 load_msg 2 95 NULL
  106239. +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
  106240. +init_q_132 init_q 4 132 NULL
  106241. +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
  106242. +gfs2_glock_get_147 gfs2_glock_get 0 147 NULL
  106243. +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
  106244. +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
  106245. +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
  106246. +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
  106247. +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
  106248. +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
  106249. +xfs_bmap_btalloc_192 xfs_bmap_btalloc 0 192 NULL
  106250. +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
  106251. +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
  106252. +br_port_info_size_268 br_port_info_size 0 268 NULL
  106253. +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
  106254. +read_file_war_stats_292 read_file_war_stats 3 292 NULL
  106255. +xfs_zero_last_block_298 xfs_zero_last_block 0 298 NULL
  106256. +SYSC_connect_304 SYSC_connect 3 304 NULL
  106257. +syslog_print_307 syslog_print 2 307 NULL
  106258. +dn_setsockopt_314 dn_setsockopt 5 314 NULL
  106259. +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
  106260. +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
  106261. +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
  106262. +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
  106263. +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
  106264. +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
  106265. +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
  106266. +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
  106267. +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
  106268. +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
  106269. +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
  106270. +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
  106271. +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
  106272. +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
  106273. +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
  106274. +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
  106275. +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
  106276. +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
  106277. +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
  106278. +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
  106279. +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
  106280. +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
  106281. +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
  106282. +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
  106283. +unlink_queued_645 unlink_queued 4 645 NULL
  106284. +dtim_interval_read_654 dtim_interval_read 3 654 NULL
  106285. +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
  106286. +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
  106287. +xfs_bmap_eof_728 xfs_bmap_eof 0 728 NULL
  106288. +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
  106289. +dvb_video_write_754 dvb_video_write 3 754 NULL
  106290. +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
  106291. +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
  106292. +if_writecmd_815 if_writecmd 2 815 NULL
  106293. +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
  106294. +error_state_read_859 error_state_read 6 859 NULL
  106295. +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
  106296. +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
  106297. +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
  106298. +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
  106299. +__nodes_weight_956 __nodes_weight 2-0 956 NULL
  106300. +mnt_want_write_975 mnt_want_write 0 975 NULL
  106301. +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
  106302. +memcmp_990 memcmp 0 990 NULL
  106303. +readreg_1017 readreg 0-1 1017 NULL
  106304. +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
  106305. +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
  106306. +mce_request_packet_1073 mce_request_packet 3 1073 NULL
  106307. +agp_create_memory_1075 agp_create_memory 1 1075 NULL
  106308. +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
  106309. +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
  106310. +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
  106311. +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
  106312. +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
  106313. +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
  106314. +ipc_alloc_1192 ipc_alloc 1 1192 NULL
  106315. +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
  106316. +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
  106317. +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
  106318. +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
  106319. +i2cdev_read_1206 i2cdev_read 3 1206 NULL
  106320. +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
  106321. +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
  106322. +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
  106323. +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
  106324. +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
  106325. +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
  106326. +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
  106327. +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
  106328. +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
  106329. +tcf_hash_create_1305 tcf_hash_create 4 1305 NULL
  106330. +ffs_1322 ffs 0 1322 NULL
  106331. +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
  106332. +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
  106333. +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
  106334. +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
  106335. +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
  106336. +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
  106337. +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
  106338. +do_msgsnd_1387 do_msgsnd 4 1387 NULL
  106339. +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
  106340. +file_read_actor_1401 file_read_actor 4-0 1401 NULL
  106341. +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
  106342. +init_rs_internal_1436 init_rs_internal 1 1436 NULL
  106343. +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
  106344. +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
  106345. +xprt_alloc_1475 xprt_alloc 2 1475 NULL
  106346. +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
  106347. +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
  106348. +fpregs_set_1497 fpregs_set 4 1497 NULL
  106349. +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
  106350. +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
  106351. +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
  106352. +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
  106353. +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
  106354. +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
  106355. +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
  106356. +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
  106357. +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
  106358. +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
  106359. +rmap_add_1677 rmap_add 3 1677 NULL
  106360. +configfs_read_file_1683 configfs_read_file 3 1683 NULL
  106361. +pdu_write_u_1710 pdu_write_u 3 1710 NULL
  106362. +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
  106363. +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
  106364. +internal_create_group_1733 internal_create_group 0 1733 NULL
  106365. +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
  106366. +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
  106367. +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
  106368. +cosa_write_1774 cosa_write 3 1774 NULL
  106369. +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
  106370. +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
  106371. +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
  106372. +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
  106373. +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
  106374. +SyS_add_key_1900 SyS_add_key 4 1900 NULL
  106375. +uhid_char_read_1920 uhid_char_read 3 1920 NULL
  106376. +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
  106377. +bdev_erase_1933 bdev_erase 3 1933 NULL
  106378. +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
  106379. +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
  106380. +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
  106381. +update_qd_1955 update_qd 0 1955 NULL
  106382. +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
  106383. +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
  106384. +gpio_power_write_1991 gpio_power_write 3 1991 NULL
  106385. +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
  106386. +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
  106387. +xfs_mru_cache_insert_2013 xfs_mru_cache_insert 0 2013 NULL
  106388. +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
  106389. +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
  106390. +BcmCopySection_2035 BcmCopySection 5 2035 NULL
  106391. +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
  106392. +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
  106393. +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
  106394. +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
  106395. +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
  106396. +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
  106397. +audit_expand_2098 audit_expand 0 2098 NULL
  106398. +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
  106399. +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
  106400. +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
  106401. +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
  106402. +enable_read_2117 enable_read 3 2117 NULL
  106403. +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
  106404. +xfs_recover_inode_owner_change_2132 xfs_recover_inode_owner_change 0 2132 NULL
  106405. +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
  106406. +iov_iter_count_2152 iov_iter_count 0 2152 NULL
  106407. +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
  106408. +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
  106409. +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
  106410. +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
  106411. +xfs_inobt_update_2206 xfs_inobt_update 0 2206 NULL
  106412. +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
  106413. +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
  106414. +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
  106415. +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
  106416. +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
  106417. +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
  106418. +do_update_counters_2259 do_update_counters 4 2259 NULL
  106419. +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
  106420. +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
  106421. +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
  106422. +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
  106423. +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
  106424. +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
  106425. +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
  106426. +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
  106427. +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
  106428. +zr364xx_read_2354 zr364xx_read 3 2354 NULL
  106429. +ntfs_file_aio_write_nolock_2360 ntfs_file_aio_write_nolock 0 2360 NULL
  106430. +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
  106431. +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5-0 2368 NULL nohasharray
  106432. +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
  106433. +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
  106434. +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
  106435. +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
  106436. +raid1_size_2419 raid1_size 0-2 2419 NULL
  106437. +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
  106438. +wiphy_new_2482 wiphy_new 2 2482 NULL
  106439. +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
  106440. +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
  106441. +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
  106442. +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
  106443. +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
  106444. +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
  106445. +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
  106446. +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
  106447. +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
  106448. +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
  106449. +slot_bytes_2609 slot_bytes 0 2609 NULL
  106450. +smk_write_logging_2618 smk_write_logging 3 2618 NULL
  106451. +switch_status_2629 switch_status 5 2629 NULL
  106452. +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
  106453. +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
  106454. +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
  106455. +oti6858_write_2692 oti6858_write 4 2692 NULL
  106456. +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
  106457. +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
  106458. +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
  106459. +gfs2_glock_nq_num_2747 gfs2_glock_nq_num 0 2747 NULL
  106460. +xfs_readdir_2767 xfs_readdir 3 2767 NULL
  106461. +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
  106462. +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
  106463. +device_add_attrs_2789 device_add_attrs 0 2789 NULL
  106464. +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
  106465. +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
  106466. +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
  106467. +wait_for_avail_2847 wait_for_avail 0 2847 NULL
  106468. +sfq_alloc_2861 sfq_alloc 1 2861 NULL
  106469. +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
  106470. +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
  106471. +nla_padlen_2883 nla_padlen 1 2883 NULL
  106472. +cmm_write_2896 cmm_write 3 2896 NULL
  106473. +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
  106474. +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
  106475. +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
  106476. +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
  106477. +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
  106478. +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
  106479. +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
  106480. +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
  106481. +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
  106482. +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
  106483. +_xfs_filestream_pick_ag_3007 _xfs_filestream_pick_ag 0 3007 NULL
  106484. +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
  106485. +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
  106486. +depth_write_3021 depth_write 3 3021 NULL
  106487. +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
  106488. +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
  106489. +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
  106490. +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
  106491. +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
  106492. +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
  106493. +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
  106494. +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
  106495. +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
  106496. +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
  106497. +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
  106498. +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
  106499. +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
  106500. +rb_alloc_3102 rb_alloc 1 3102 NULL
  106501. +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
  106502. +print_time_3132 print_time 0 3132 NULL
  106503. +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
  106504. +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
  106505. +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
  106506. +gfs2_rindex_update_3165 gfs2_rindex_update 0 3165 NULL
  106507. +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
  106508. +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
  106509. +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
  106510. +mempool_create_node_3191 mempool_create_node 1 3191 NULL
  106511. +alloc_context_3194 alloc_context 1 3194 NULL
  106512. +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
  106513. +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
  106514. +SyS_sendto_3219 SyS_sendto 6 3219 NULL
  106515. +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
  106516. +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
  106517. +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
  106518. +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
  106519. +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
  106520. +key_key_read_3241 key_key_read 3 3241 NULL
  106521. +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
  106522. +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
  106523. +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
  106524. +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
  106525. +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
  106526. +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
  106527. +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
  106528. +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
  106529. +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
  106530. +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
  106531. +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
  106532. +scnprintf_3360 scnprintf 0-2 3360 NULL
  106533. +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
  106534. +sr_read_3366 sr_read 3 3366 NULL
  106535. +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
  106536. +send_stream_3397 send_stream 4 3397 NULL
  106537. +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
  106538. +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
  106539. +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
  106540. +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
  106541. +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
  106542. +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
  106543. +softsynth_write_3455 softsynth_write 3 3455 NULL
  106544. +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
  106545. +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
  106546. +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
  106547. +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
  106548. +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
  106549. +SyS_readv_3539 SyS_readv 3 3539 NULL
  106550. +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
  106551. +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
  106552. +evtchn_read_3569 evtchn_read 3 3569 NULL
  106553. +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
  106554. +vc_resize_3585 vc_resize 3-2 3585 NULL
  106555. +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
  106556. +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
  106557. +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
  106558. +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
  106559. +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
  106560. +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
  106561. +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
  106562. +xfs_attr3_leaf_list_int_3661 xfs_attr3_leaf_list_int 0 3661 NULL
  106563. +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
  106564. +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
  106565. +ci_ll_write_3740 ci_ll_write 4 3740 NULL
  106566. +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
  106567. +ncp_file_write_3813 ncp_file_write 3 3813 NULL
  106568. +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
  106569. +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
  106570. +create_one_cdev_3852 create_one_cdev 2 3852 NULL
  106571. +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
  106572. +get_fd_set_3866 get_fd_set 1 3866 NULL
  106573. +apei_res_sub_3873 apei_res_sub 0 3873 NULL
  106574. +garp_attr_create_3883 garp_attr_create 3 3883 NULL
  106575. +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
  106576. +nvram_write_3894 nvram_write 3 3894 NULL
  106577. +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
  106578. +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
  106579. +vcs_write_3910 vcs_write 3 3910 NULL
  106580. +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
  106581. +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
  106582. +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
  106583. +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
  106584. +do_add_counters_3992 do_add_counters 3 3992 NULL
  106585. +xfs_bmbt_lookup_eq_3997 xfs_bmbt_lookup_eq 0 3997 NULL
  106586. +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
  106587. +userspace_status_4004 userspace_status 4 4004 NULL
  106588. +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
  106589. +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
  106590. +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
  106591. +blk_end_request_4024 blk_end_request 3 4024 NULL
  106592. +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
  106593. +xfs_free_ag_extent_4036 xfs_free_ag_extent 0 4036 NULL
  106594. +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
  106595. +read_file_queues_4078 read_file_queues 3 4078 NULL
  106596. +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
  106597. +tm6000_read_4151 tm6000_read 3 4151 NULL
  106598. +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
  106599. +msg_bits_4158 msg_bits 0-3-4 4158 NULL
  106600. +get_alua_req_4166 get_alua_req 3 4166 NULL
  106601. +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
  106602. +read_file_bool_4180 read_file_bool 3 4180 NULL
  106603. +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
  106604. +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
  106605. +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
  106606. +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
  106607. +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
  106608. +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
  106609. +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
  106610. +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
  106611. +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
  106612. +count_strings_4315 count_strings 0 4315 NULL
  106613. +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
  106614. +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
  106615. +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
  106616. +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
  106617. +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
  106618. +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
  106619. +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
  106620. +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
  106621. +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
  106622. +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
  106623. +do_pages_stat_4437 do_pages_stat 2 4437 NULL
  106624. +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
  106625. +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
  106626. +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
  106627. +set_link_security_4502 set_link_security 4 4502 NULL
  106628. +xfs_btree_kill_root_4526 xfs_btree_kill_root 0 4526 NULL
  106629. +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
  106630. +tty_register_device_4544 tty_register_device 2 4544 NULL
  106631. +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
  106632. +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
  106633. +bch_alloc_4593 bch_alloc 1 4593 NULL
  106634. +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
  106635. +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
  106636. +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
  106637. +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
  106638. +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
  106639. +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
  106640. +kone_receive_4690 kone_receive 4 4690 NULL
  106641. +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
  106642. +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
  106643. +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
  106644. +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
  106645. +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
  106646. +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
  106647. +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
  106648. +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
  106649. +create_subvol_4791 create_subvol 4 4791 NULL
  106650. +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
  106651. +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
  106652. +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
  106653. +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
  106654. +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
  106655. +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
  106656. +hid_register_field_4874 hid_register_field 2-3 4874 NULL
  106657. +vga_arb_read_4886 vga_arb_read 3 4886 NULL
  106658. +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
  106659. +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
  106660. +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
  106661. +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
  106662. +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
  106663. +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
  106664. +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
  106665. +do_mincore_5018 do_mincore 0-2-1 5018 NULL
  106666. +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
  106667. +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
  106668. +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
  106669. +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
  106670. +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
  106671. +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
  106672. +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
  106673. +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
  106674. +sound_write_5102 sound_write 3 5102 NULL
  106675. +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
  106676. +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
  106677. +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
  106678. +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
  106679. +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
  106680. +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
  106681. +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
  106682. +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
  106683. +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
  106684. +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
  106685. +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
  106686. +cq_free_res_5355 cq_free_res 5 5355 NULL
  106687. +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
  106688. +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
  106689. +xfs_free_extent_5411 xfs_free_extent 0 5411 NULL
  106690. +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
  106691. +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
  106692. +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
  106693. +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
  106694. +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
  106695. +tty_write_5494 tty_write 3 5494 NULL
  106696. +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
  106697. +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
  106698. +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
  106699. +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
  106700. +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
  106701. +le_readq_5557 le_readq 0 5557 NULL
  106702. +inw_5558 inw 0 5558 NULL
  106703. +gfs2_extent_map_5561 gfs2_extent_map 0 5561 NULL
  106704. +bioset_create_5580 bioset_create 1 5580 NULL
  106705. +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
  106706. +__remove_suid_5618 __remove_suid 0 5618 NULL
  106707. +gfs2_unstuffer_page_5620 gfs2_unstuffer_page 0 5620 NULL
  106708. +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
  106709. +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
  106710. +posix_clock_register_5662 posix_clock_register 2 5662 NULL
  106711. +get_arg_5694 get_arg 3 5694 NULL
  106712. +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
  106713. +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
  106714. +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
  106715. +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
  106716. +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
  106717. +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
  106718. +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
  106719. +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
  106720. +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
  106721. +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
  106722. +setup_req_5848 setup_req 3 5848 NULL
  106723. +ria_page_count_5849 ria_page_count 0 5849 NULL
  106724. +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
  106725. +config_buf_5862 config_buf 0 5862 NULL
  106726. +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
  106727. +port_show_regs_5904 port_show_regs 3 5904 NULL
  106728. +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
  106729. +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
  106730. +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
  106731. +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
  106732. +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
  106733. +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
  106734. +__apu_get_register_5967 __apu_get_register 0 5967 NULL
  106735. +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
  106736. +alloc_msg_6072 alloc_msg 1 6072 NULL
  106737. +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
  106738. +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
  106739. +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
  106740. +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
  106741. +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
  106742. +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
  106743. +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
  106744. +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
  106745. +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
  106746. +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
  106747. +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
  106748. +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
  106749. +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
  106750. +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
  106751. +f_hidg_read_6238 f_hidg_read 3 6238 NULL
  106752. +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
  106753. +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
  106754. +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
  106755. +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
  106756. +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
  106757. +serial_port_in_6291 serial_port_in 0 6291 NULL
  106758. +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
  106759. +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
  106760. +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
  106761. +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
  106762. +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
  106763. +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
  106764. +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
  106765. +_proc_do_string_6376 _proc_do_string 2 6376 NULL
  106766. +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
  106767. +xfs_bmap_extents_to_btree_6387 xfs_bmap_extents_to_btree 0 6387 NULL
  106768. +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
  106769. +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
  106770. +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
  106771. +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
  106772. +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
  106773. +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
  106774. +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
  106775. +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
  106776. +mei_read_6507 mei_read 3 6507 NULL
  106777. +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
  106778. +wdm_read_6549 wdm_read 3 6549 NULL
  106779. +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
  106780. +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
  106781. +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
  106782. +xfs_iozero_6573 xfs_iozero 0 6573 NULL
  106783. +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
  106784. +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
  106785. +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
  106786. +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
  106787. +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
  106788. +mpeg_read_6708 mpeg_read 3 6708 NULL
  106789. +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
  106790. +video_proc_write_6724 video_proc_write 3 6724 NULL
  106791. +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
  106792. +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
  106793. +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
  106794. +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
  106795. +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
  106796. +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
  106797. +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
  106798. +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
  106799. +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
  106800. +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
  106801. +mon_bin_read_6841 mon_bin_read 3 6841 NULL
  106802. +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
  106803. +xfs_rtany_summary_6851 xfs_rtany_summary 0 6851 NULL
  106804. +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
  106805. +dio_complete_6879 dio_complete 0-2-3 6879 NULL
  106806. +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
  106807. +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
  106808. +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
  106809. +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
  106810. +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
  106811. +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
  106812. +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
  106813. +lops_scan_elements_6916 lops_scan_elements 0 6916 NULL
  106814. +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
  106815. +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
  106816. +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
  106817. +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
  106818. +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
  106819. +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
  106820. +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
  106821. +request_key_async_6990 request_key_async 4 6990 NULL
  106822. +tpl_write_6998 tpl_write 3 6998 NULL
  106823. +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
  106824. +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
  106825. +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
  106826. +ld_usb_write_7022 ld_usb_write 3 7022 NULL
  106827. +wimax_msg_7030 wimax_msg 4 7030 NULL
  106828. +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
  106829. +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
  106830. +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
  106831. +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
  106832. +event_enable_read_7074 event_enable_read 3 7074 NULL
  106833. +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
  106834. +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
  106835. +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
  106836. +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
  106837. +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
  106838. +hdlc_loop_7255 hdlc_loop 0 7255 NULL
  106839. +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
  106840. +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
  106841. +get_string_7302 get_string 0 7302 NULL
  106842. +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
  106843. +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
  106844. +mgmt_control_7349 mgmt_control 3 7349 NULL
  106845. +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
  106846. +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
  106847. +xfs_btree_delete_7384 xfs_btree_delete 0 7384 NULL
  106848. +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
  106849. +hweight_long_7388 hweight_long 1-0 7388 NULL
  106850. +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
  106851. +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
  106852. +readb_7401 readb 0 7401 NULL
  106853. +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
  106854. +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
  106855. +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
  106856. +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
  106857. +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
  106858. +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
  106859. +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
  106860. +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
  106861. +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
  106862. +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
  106863. +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
  106864. +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
  106865. +array_zalloc_7519 array_zalloc 1-2 7519 NULL
  106866. +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
  106867. +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
  106868. +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
  106869. +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
  106870. +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
  106871. +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
  106872. +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
  106873. +xfs_bmap_btalloc_nullfb_7654 xfs_bmap_btalloc_nullfb 0 7654 NULL
  106874. +fault_inject_write_7662 fault_inject_write 3 7662 NULL
  106875. +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
  106876. +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
  106877. +dev_write_7708 dev_write 3 7708 NULL
  106878. +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
  106879. +vxge_device_register_7752 vxge_device_register 4 7752 NULL
  106880. +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
  106881. +alloc_candev_7776 alloc_candev 1-2 7776 NULL
  106882. +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
  106883. +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
  106884. +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
  106885. +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
  106886. +xfs_alloc_find_best_extent_7837 xfs_alloc_find_best_extent 0 7837 NULL
  106887. +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
  106888. +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
  106889. +config_desc_7878 config_desc 0 7878 NULL
  106890. +gfs2_permission_7884 gfs2_permission 0 7884 NULL
  106891. +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
  106892. +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
  106893. +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
  106894. +f_hidg_write_7932 f_hidg_write 3 7932 NULL
  106895. +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
  106896. +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
  106897. +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
  106898. +vcs_read_8017 vcs_read 3 8017 NULL
  106899. +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
  106900. +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
  106901. +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
  106902. +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
  106903. +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
  106904. +venus_lookup_8121 venus_lookup 4 8121 NULL
  106905. +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
  106906. +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
  106907. +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
  106908. +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
  106909. +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
  106910. +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
  106911. +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
  106912. +play_iframe_8219 play_iframe 3 8219 NULL
  106913. +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
  106914. +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
  106915. +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
  106916. +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
  106917. +init_cdev_8274 init_cdev 1 8274 NULL
  106918. +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
  106919. +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
  106920. +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
  106921. +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
  106922. +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
  106923. +generic_write_sync_8358 generic_write_sync 0 8358 NULL
  106924. +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
  106925. +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
  106926. +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
  106927. +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
  106928. +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
  106929. +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
  106930. +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
  106931. +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
  106932. +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
  106933. +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
  106934. +dev_config_8506 dev_config 3 8506 NULL
  106935. +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
  106936. +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
  106937. +user_on_off_8552 user_on_off 2 8552 NULL
  106938. +profile_remove_8556 profile_remove 3 8556 NULL
  106939. +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
  106940. +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
  106941. +tower_write_8580 tower_write 3 8580 NULL
  106942. +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
  106943. +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
  106944. +xfs_qm_dqattach_locked_8625 xfs_qm_dqattach_locked 0 8625 NULL
  106945. +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
  106946. +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
  106947. +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
  106948. +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
  106949. +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
  106950. +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
  106951. +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
  106952. +skb_frag_size_8695 skb_frag_size 0 8695 NULL
  106953. +arcfb_write_8702 arcfb_write 3 8702 NULL
  106954. +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
  106955. +init_header_8703 init_header 0 8703 &i_size_read_8703
  106956. +HDLC_irq_8709 HDLC_irq 2 8709 NULL
  106957. +ctrl_out_8712 ctrl_out 3-5 8712 NULL
  106958. +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
  106959. +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
  106960. +__create_irqs_8733 __create_irqs 2 8733 NULL
  106961. +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
  106962. +compound_order_8750 compound_order 0 8750 NULL
  106963. +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
  106964. +yurex_write_8761 yurex_write 3 8761 NULL
  106965. +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
  106966. +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
  106967. +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
  106968. +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
  106969. +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
  106970. +gfs2_glock_nq_8808 gfs2_glock_nq 0 8808 NULL
  106971. +ntfs_commit_pages_after_write_8809 ntfs_commit_pages_after_write 0 8809 NULL
  106972. +metronomefb_write_8823 metronomefb_write 3 8823 NULL
  106973. +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
  106974. +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
  106975. +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
  106976. +get_queue_depth_8833 get_queue_depth 0 8833 NULL
  106977. +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
  106978. +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
  106979. +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
  106980. +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
  106981. +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
  106982. +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
  106983. +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
  106984. +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
  106985. +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
  106986. +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
  106987. +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
  106988. +write_file_ani_8918 write_file_ani 3 8918 NULL
  106989. +layout_commit_8926 layout_commit 3 8926 NULL
  106990. +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
  106991. +driver_stats_read_8944 driver_stats_read 3 8944 NULL
  106992. +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
  106993. +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
  106994. +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
  106995. +venus_mkdir_8967 venus_mkdir 4 8967 NULL
  106996. +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
  106997. +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
  106998. +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
  106999. +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
  107000. +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
  107001. +xfs_inobt_get_rec_9023 xfs_inobt_get_rec 0 9023 NULL
  107002. +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
  107003. +fd_ioctl_9028 fd_ioctl 3 9028 NULL
  107004. +nla_put_9042 nla_put 3 9042 NULL
  107005. +ffs_func_revmap_intf_9043 ffs_func_revmap_intf 0 9043 NULL
  107006. +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
  107007. +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
  107008. +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
  107009. +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
  107010. +create_queues_9088 create_queues 2-3 9088 NULL
  107011. +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
  107012. +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
  107013. +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
  107014. +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110 nohasharray
  107015. +jhead_scan_9110 jhead_scan 0 9110 &gfn_to_rmap_9110
  107016. +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
  107017. +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
  107018. +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
  107019. +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
  107020. +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
  107021. +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
  107022. +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
  107023. +xfs_btree_rshift_9187 xfs_btree_rshift 0 9187 NULL
  107024. +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
  107025. +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
  107026. +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
  107027. +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
  107028. +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
  107029. +xfs_error_trap_9239 xfs_error_trap 0-1 9239 NULL
  107030. +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
  107031. +hdpvr_read_9273 hdpvr_read 3 9273 NULL
  107032. +flakey_status_9274 flakey_status 5 9274 NULL
  107033. +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
  107034. +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
  107035. +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
  107036. +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
  107037. +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
  107038. +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
  107039. +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
  107040. +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
  107041. +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
  107042. +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
  107043. +read_9397 read 3 9397 NULL
  107044. +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
  107045. +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
  107046. +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
  107047. +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
  107048. +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
  107049. +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
  107050. +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
  107051. +crypt_status_9492 crypt_status 5 9492 NULL
  107052. +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
  107053. +lp_write_9511 lp_write 3 9511 NULL
  107054. +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
  107055. +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
  107056. +read_file_dma_9530 read_file_dma 3 9530 NULL
  107057. +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
  107058. +xfs_ialloc_read_agi_9545 xfs_ialloc_read_agi 0 9545 NULL
  107059. +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
  107060. +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
  107061. +fw_node_create_9559 fw_node_create 2 9559 NULL
  107062. +kobj_map_9566 kobj_map 2-3 9566 NULL
  107063. +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
  107064. +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
  107065. +xfs_qm_dqattach_one_9612 xfs_qm_dqattach_one 0 9612 NULL
  107066. +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
  107067. +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
  107068. +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
  107069. +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
  107070. +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
  107071. +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
  107072. +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
  107073. +queue_received_packet_9657 queue_received_packet 5 9657 NULL
  107074. +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
  107075. +dns_query_9676 dns_query 3 9676 NULL
  107076. +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
  107077. +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
  107078. +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
  107079. +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
  107080. +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
  107081. +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
  107082. +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
  107083. +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
  107084. +nla_get_u8_9736 nla_get_u8 0 9736 NULL
  107085. +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
  107086. +shmem_replace_page_9740 shmem_replace_page 0 9740 NULL
  107087. +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
  107088. +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
  107089. +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
  107090. +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
  107091. +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
  107092. +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
  107093. +tpm_data_in_9802 tpm_data_in 0 9802 NULL
  107094. +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
  107095. +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
  107096. +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
  107097. +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
  107098. +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
  107099. +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
  107100. +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
  107101. +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
  107102. +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
  107103. +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
  107104. +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
  107105. +read_file_misc_9948 read_file_misc 3 9948 NULL
  107106. +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
  107107. +xfs_buf_geterror_9959 xfs_buf_geterror 0 9959 NULL
  107108. +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
  107109. +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
  107110. +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
  107111. +gameport_read_9983 gameport_read 0 9983 NULL
  107112. +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
  107113. +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
  107114. +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
  107115. +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
  107116. +xfs_attr_rmtval_get_10092 xfs_attr_rmtval_get 0 10092 NULL
  107117. +xfs_btree_check_lptr_10104 xfs_btree_check_lptr 0 10104 NULL
  107118. +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
  107119. +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
  107120. +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
  107121. +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
  107122. +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
  107123. +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
  107124. +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
  107125. +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
  107126. +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
  107127. +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
  107128. +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
  107129. +xfs_attr_rmtval_copyout_10222 xfs_attr_rmtval_copyout 0 10222 NULL nohasharray
  107130. +xfs_btree_read_buf_block_10222 xfs_btree_read_buf_block 0 10222 &xfs_attr_rmtval_copyout_10222
  107131. +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
  107132. +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
  107133. +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
  107134. +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
  107135. +read_emulate_10310 read_emulate 2-4 10310 NULL
  107136. +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
  107137. +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
  107138. +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
  107139. +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
  107140. +whci_add_cap_10350 whci_add_cap 0 10350 NULL
  107141. +dbAllocAny_10354 dbAllocAny 0 10354 NULL
  107142. +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
  107143. +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
  107144. +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
  107145. +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
  107146. +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
  107147. +fwtty_rx_10434 fwtty_rx 3 10434 NULL
  107148. +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
  107149. +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
  107150. +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
  107151. +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
  107152. +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
  107153. +sel_write_disable_10511 sel_write_disable 3 10511 NULL
  107154. +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
  107155. +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
  107156. +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
  107157. +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
  107158. +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
  107159. +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
  107160. +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
  107161. +otp_read_10594 otp_read 2-4-5 10594 NULL
  107162. +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
  107163. +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
  107164. +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
  107165. +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
  107166. +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
  107167. +parport_write_10669 parport_write 0 10669 NULL
  107168. +edge_write_10692 edge_write 4 10692 NULL
  107169. +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
  107170. +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
  107171. +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
  107172. +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
  107173. +spi_sync_10731 spi_sync 0 10731 NULL
  107174. +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
  107175. +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
  107176. +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
  107177. +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
  107178. +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
  107179. +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
  107180. +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
  107181. +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
  107182. +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
  107183. +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
  107184. +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
  107185. +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
  107186. +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
  107187. +get_scq_10897 get_scq 2 10897 NULL
  107188. +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
  107189. +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
  107190. +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
  107191. +kobject_add_10919 kobject_add 0 10919 NULL
  107192. +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
  107193. +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
  107194. +bm_entry_read_10976 bm_entry_read 3 10976 NULL
  107195. +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
  107196. +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
  107197. +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
  107198. +gfs2_dir_read_11017 gfs2_dir_read 0 11017 NULL
  107199. +SetLineNumber_11023 SetLineNumber 0 11023 NULL
  107200. +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
  107201. +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
  107202. +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
  107203. +count_argc_11083 count_argc 0 11083 NULL
  107204. +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
  107205. +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
  107206. +page_offset_11120 page_offset 0 11120 NULL
  107207. +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL nohasharray
  107208. +cea_db_payload_len_11124 cea_db_payload_len 0 11124 &tracing_buffers_read_11124
  107209. +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
  107210. +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
  107211. +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
  107212. +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
  107213. +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
  107214. +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
  107215. +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
  107216. +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
  107217. +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
  107218. +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
  107219. +shmem_radix_tree_replace_11325 shmem_radix_tree_replace 0 11325 NULL
  107220. +construct_key_11329 construct_key 3 11329 NULL nohasharray
  107221. +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
  107222. +next_segment_11330 next_segment 0-2-1 11330 NULL
  107223. +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
  107224. +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
  107225. +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
  107226. +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
  107227. +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
  107228. +nft_value_dump_11381 nft_value_dump 3 11381 NULL
  107229. +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
  107230. +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
  107231. +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
  107232. +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
  107233. +str_to_user_11411 str_to_user 2 11411 NULL
  107234. +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
  107235. +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
  107236. +xfs_btree_lookup_11417 xfs_btree_lookup 0 11417 NULL nohasharray
  107237. +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 &xfs_btree_lookup_11417
  107238. +trace_options_read_11419 trace_options_read 3 11419 NULL
  107239. +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
  107240. +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
  107241. +bttv_read_11432 bttv_read 3 11432 NULL
  107242. +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
  107243. +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
  107244. +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
  107245. +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
  107246. +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4-0 11492 NULL
  107247. +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
  107248. +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
  107249. +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
  107250. +twl_direction_in_11527 twl_direction_in 2 11527 NULL
  107251. +xfs_rtcheck_alloc_range_11553 xfs_rtcheck_alloc_range 0 11553 NULL
  107252. +radix_tree_extend_11555 radix_tree_extend 0 11555 NULL
  107253. +skb_cow_data_11565 skb_cow_data 0 11565 NULL
  107254. +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
  107255. +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
  107256. +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
  107257. +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
  107258. +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
  107259. +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
  107260. +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
  107261. +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
  107262. +nla_total_size_11658 nla_total_size 1-0 11658 NULL
  107263. +slab_ksize_11664 slab_ksize 0 11664 NULL
  107264. +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
  107265. +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
  107266. +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
  107267. +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
  107268. +split_11691 split 2 11691 NULL
  107269. +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
  107270. +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
  107271. +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
  107272. +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
  107273. +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
  107274. +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
  107275. +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
  107276. +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
  107277. +xfs_ialloc_11819 xfs_ialloc 0 11819 NULL
  107278. +umc_device_register_11824 umc_device_register 0 11824 NULL
  107279. +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
  107280. +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
  107281. +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
  107282. +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
  107283. +xfs_file_aio_write_checks_11851 xfs_file_aio_write_checks 0 11851 NULL
  107284. +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
  107285. +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
  107286. +mdc_rename_11899 mdc_rename 4-6 11899 NULL
  107287. +xstateregs_get_11906 xstateregs_get 4 11906 NULL
  107288. +ti_write_11916 ti_write 4 11916 NULL
  107289. +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
  107290. +bitmap_remap_11929 bitmap_remap 5 11929 NULL
  107291. +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
  107292. +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
  107293. +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
  107294. +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
  107295. +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
  107296. +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
  107297. +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
  107298. +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
  107299. +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
  107300. +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
  107301. +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
  107302. +gfs2_find_jhead_12117 gfs2_find_jhead 0 12117 NULL
  107303. +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
  107304. +set_powered_12129 set_powered 4 12129 NULL
  107305. +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
  107306. +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
  107307. +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
  107308. +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
  107309. +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
  107310. +vmbus_open_12154 vmbus_open 2-3 12154 NULL
  107311. +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
  107312. +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
  107313. +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
  107314. +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
  107315. +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
  107316. +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
  107317. +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
  107318. +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
  107319. +xfs_attr3_leaf_read_12222 xfs_attr3_leaf_read 0 12222 NULL
  107320. +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
  107321. +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
  107322. +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
  107323. +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
  107324. +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
  107325. +note_last_dentry_12285 note_last_dentry 3 12285 NULL
  107326. +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
  107327. +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
  107328. +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
  107329. +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
  107330. +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
  107331. +xfs_bmap_last_extent_12335 xfs_bmap_last_extent 0 12335 NULL
  107332. +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
  107333. +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
  107334. +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
  107335. +populate_dir_12391 populate_dir 0 12391 NULL nohasharray
  107336. +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
  107337. +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
  107338. +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
  107339. +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
  107340. +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
  107341. +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
  107342. +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
  107343. +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
  107344. +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
  107345. +write_inode_now_12565 write_inode_now 0 12565 NULL
  107346. +hvc_alloc_12579 hvc_alloc 4 12579 NULL
  107347. +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
  107348. +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
  107349. +vhci_put_user_12604 vhci_put_user 4 12604 NULL
  107350. +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
  107351. +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
  107352. +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
  107353. +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
  107354. +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
  107355. +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
  107356. +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
  107357. +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
  107358. +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
  107359. +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
  107360. +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
  107361. +ivtv_write_12721 ivtv_write 3 12721 NULL
  107362. +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
  107363. +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
  107364. +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
  107365. +listxattr_12769 listxattr 3 12769 NULL
  107366. +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
  107367. +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
  107368. +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
  107369. +readq_12825 readq 0 12825 NULL
  107370. +SyS_add_key_12834 SyS_add_key 4 12834 NULL
  107371. +gfs2_log_reserve_12835 gfs2_log_reserve 0 12835 NULL
  107372. +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
  107373. +spidev_sync_12842 spidev_sync 0 12842 NULL
  107374. +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
  107375. +xfs_rtallocate_extent_exact_12865 xfs_rtallocate_extent_exact 0 12865 NULL
  107376. +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
  107377. +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
  107378. +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
  107379. +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
  107380. +do_inode_permission_12946 do_inode_permission 0 12946 NULL
  107381. +bm_status_write_12964 bm_status_write 3 12964 NULL
  107382. +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
  107383. +TransmitTcb_12989 TransmitTcb 4 12989 NULL
  107384. +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
  107385. +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
  107386. +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
  107387. +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
  107388. +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
  107389. +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
  107390. +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
  107391. +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
  107392. +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
  107393. +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
  107394. +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
  107395. +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
  107396. +blk_update_request_13146 blk_update_request 3 13146 NULL
  107397. +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
  107398. +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
  107399. +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
  107400. +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
  107401. +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
  107402. +comedi_read_13199 comedi_read 3 13199 NULL
  107403. +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
  107404. +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
  107405. +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
  107406. +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
  107407. +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
  107408. +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
  107409. +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
  107410. +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
  107411. +simple_attr_write_13260 simple_attr_write 3 13260 NULL
  107412. +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
  107413. +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
  107414. +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
  107415. +sd_major_13294 sd_major 0-1 13294 NULL
  107416. +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
  107417. +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
  107418. +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
  107419. +round_event_name_len_13348 round_event_name_len 0 13348 NULL
  107420. +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
  107421. +xfs_btree_delrec_13364 xfs_btree_delrec 0 13364 NULL
  107422. +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
  107423. +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
  107424. +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
  107425. +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
  107426. +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
  107427. +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
  107428. +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
  107429. +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
  107430. +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
  107431. +data_read_13494 data_read 3 13494 NULL
  107432. +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
  107433. +core_status_13515 core_status 4 13515 NULL
  107434. +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
  107435. +bm_init_13529 bm_init 2 13529 NULL
  107436. +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
  107437. +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
  107438. +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
  107439. +read_file_antenna_13574 read_file_antenna 3 13574 NULL
  107440. +cache_write_13589 cache_write 3 13589 NULL
  107441. +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
  107442. +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
  107443. +__ntfs_grab_cache_pages_13617 __ntfs_grab_cache_pages 0 13617 NULL
  107444. +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
  107445. +packet_snd_13634 packet_snd 3 13634 NULL
  107446. +blk_msg_write_13655 blk_msg_write 3 13655 NULL
  107447. +cache_downcall_13666 cache_downcall 3 13666 NULL
  107448. +usb_get_string_13693 usb_get_string 0 13693 NULL
  107449. +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
  107450. +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
  107451. +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
  107452. +fb_sys_read_13778 fb_sys_read 3 13778 NULL
  107453. +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
  107454. +random_read_13815 random_read 3 13815 NULL
  107455. +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
  107456. +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
  107457. +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
  107458. +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
  107459. +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
  107460. +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
  107461. +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
  107462. +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
  107463. +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
  107464. +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
  107465. +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
  107466. +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
  107467. +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
  107468. +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
  107469. +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
  107470. +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
  107471. +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
  107472. +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
  107473. +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
  107474. +qcam_read_13977 qcam_read 3 13977 NULL
  107475. +dsp_read_13980 dsp_read 2 13980 NULL
  107476. +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
  107477. +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
  107478. +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
  107479. +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
  107480. +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
  107481. +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
  107482. +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
  107483. +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
  107484. +xfs_bmap_alloc_14044 xfs_bmap_alloc 0 14044 NULL
  107485. +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
  107486. +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
  107487. +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
  107488. +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
  107489. +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
  107490. +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
  107491. +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
  107492. +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
  107493. +em_canid_change_14150 em_canid_change 3 14150 NULL
  107494. +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
  107495. +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
  107496. +print_input_mask_14168 print_input_mask 3-0 14168 NULL
  107497. +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
  107498. +datafab_read_data_14186 datafab_read_data 4 14186 NULL
  107499. +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
  107500. +alloc_async_14208 alloc_async 1 14208 NULL
  107501. +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
  107502. +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
  107503. +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
  107504. +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
  107505. +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
  107506. +rr_status_14293 rr_status 5 14293 NULL
  107507. +read_default_ldt_14302 read_default_ldt 2 14302 NULL
  107508. +update_rgrp_lvb_14303 update_rgrp_lvb 0 14303 NULL
  107509. +xfs_qm_qino_alloc_14309 xfs_qm_qino_alloc 0 14309 NULL
  107510. +oo_objects_14319 oo_objects 0 14319 NULL
  107511. +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
  107512. +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
  107513. +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
  107514. +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
  107515. +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
  107516. +lowpan_read_14369 lowpan_read 3 14369 NULL
  107517. +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
  107518. +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
  107519. +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
  107520. +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
  107521. +block_size_14443 block_size 0 14443 NULL
  107522. +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
  107523. +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
  107524. +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
  107525. +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
  107526. +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
  107527. +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
  107528. +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
  107529. +split_state_14491 split_state 0 14491 NULL
  107530. +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
  107531. +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
  107532. +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
  107533. +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
  107534. +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
  107535. +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
  107536. +stuffed_readpage_14581 stuffed_readpage 0 14581 NULL
  107537. +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
  107538. +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
  107539. +dbJoin_14644 dbJoin 0 14644 NULL
  107540. +profile_replace_14652 profile_replace 3 14652 NULL
  107541. +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
  107542. +add_to_page_cache_locked_14668 add_to_page_cache_locked 0 14668 NULL
  107543. +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
  107544. +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
  107545. +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
  107546. +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
  107547. +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
  107548. +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
  107549. +u_audio_playback_14709 u_audio_playback 3 14709 NULL
  107550. +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
  107551. +vfd_write_14717 vfd_write 3 14717 NULL
  107552. +__blk_end_request_14729 __blk_end_request 3 14729 NULL
  107553. +raid1_resize_14740 raid1_resize 2 14740 NULL
  107554. +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
  107555. +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
  107556. +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
  107557. +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
  107558. +sta_dev_read_14782 sta_dev_read 3 14782 NULL
  107559. +keys_proc_write_14792 keys_proc_write 3 14792 NULL
  107560. +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
  107561. +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
  107562. +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
  107563. +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
  107564. +xfs_btree_kill_iroot_14824 xfs_btree_kill_iroot 0 14824 NULL
  107565. +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
  107566. +lcd_write_14857 lcd_write 3 14857 NULL
  107567. +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
  107568. +xfs_bmapi_convert_unwritten_14886 xfs_bmapi_convert_unwritten 0 14886 NULL
  107569. +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
  107570. +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
  107571. +SYSC_readv_14901 SYSC_readv 3 14901 NULL
  107572. +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
  107573. +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
  107574. +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
  107575. +queue_cnt_14951 queue_cnt 0 14951 NULL
  107576. +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
  107577. +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
  107578. +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
  107579. +setkey_14987 setkey 3 14987 NULL nohasharray
  107580. +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
  107581. +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
  107582. +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
  107583. +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
  107584. +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
  107585. +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
  107586. +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
  107587. +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
  107588. +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
  107589. +xfs_btree_insrec_15090 xfs_btree_insrec 0 15090 NULL
  107590. +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
  107591. +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
  107592. +start_port_15124 start_port 0 15124 NULL
  107593. +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
  107594. +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
  107595. +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
  107596. +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
  107597. +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
  107598. +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
  107599. +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
  107600. +simple_strtol_15273 simple_strtol 0 15273 NULL
  107601. +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
  107602. +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
  107603. +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
  107604. +ioread16_15342 ioread16 0 15342 NULL
  107605. +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
  107606. +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
  107607. +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
  107608. +graph_depth_read_15371 graph_depth_read 3 15371 NULL
  107609. +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
  107610. +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
  107611. +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
  107612. +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
  107613. +get_modalias_15406 get_modalias 2 15406 NULL
  107614. +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
  107615. +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
  107616. +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
  107617. +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
  107618. +memweight_15450 memweight 2 15450 NULL
  107619. +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
  107620. +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
  107621. +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
  107622. +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
  107623. +persistent_status_15574 persistent_status 4 15574 NULL
  107624. +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
  107625. +vme_user_write_15587 vme_user_write 3 15587 NULL
  107626. +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
  107627. +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
  107628. +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
  107629. +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
  107630. +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
  107631. +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
  107632. +fs_path_add_15648 fs_path_add 3 15648 NULL
  107633. +__do_readpage_15652 __do_readpage 0 15652 NULL
  107634. +xsd_read_15653 xsd_read 3 15653 NULL
  107635. +unix_bind_15668 unix_bind 3 15668 NULL
  107636. +dm_read_15674 dm_read 3 15674 NULL nohasharray
  107637. +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
  107638. +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
  107639. +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
  107640. +smk_read_direct_15803 smk_read_direct 3 15803 NULL
  107641. +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
  107642. +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
  107643. +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
  107644. +table_size_15851 table_size 0-1-2 15851 NULL
  107645. +write_file_tx99_15856 write_file_tx99 3 15856 NULL
  107646. +media_entity_init_15870 media_entity_init 2-4 15870 NULL
  107647. +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
  107648. +native_read_msr_15905 native_read_msr 0 15905 NULL
  107649. +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
  107650. +power_read_15939 power_read 3 15939 NULL
  107651. +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
  107652. +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
  107653. +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
  107654. +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
  107655. +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
  107656. +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
  107657. +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
  107658. +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
  107659. +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
  107660. +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
  107661. +gfs2_jdesc_check_16122 gfs2_jdesc_check 0 16122 NULL
  107662. +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
  107663. +compat_sys_select_16131 compat_sys_select 1 16131 NULL
  107664. +fsm_init_16134 fsm_init 2 16134 NULL
  107665. +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
  107666. +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
  107667. +mapping_level_16188 mapping_level 2-0 16188 NULL
  107668. +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
  107669. +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
  107670. +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
  107671. +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
  107672. +create_table_16213 create_table 2 16213 NULL
  107673. +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
  107674. +atomic_read_file_16227 atomic_read_file 3 16227 NULL
  107675. +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
  107676. +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
  107677. +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
  107678. +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
  107679. +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
  107680. +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
  107681. +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
  107682. +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
  107683. +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
  107684. +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
  107685. +account_16283 account 0-4-2 16283 NULL nohasharray
  107686. +mirror_status_16283 mirror_status 5 16283 &account_16283
  107687. +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
  107688. +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
  107689. +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
  107690. +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
  107691. +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
  107692. +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
  107693. +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
  107694. +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
  107695. +xfs_inobt_lookup_16367 xfs_inobt_lookup 0 16367 NULL
  107696. +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
  107697. +gfs2_dinode_in_16378 gfs2_dinode_in 0 16378 NULL
  107698. +xfs_btree_check_block_16419 xfs_btree_check_block 0 16419 NULL
  107699. +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
  107700. +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
  107701. +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
  107702. +cmdline_store_16442 cmdline_store 4 16442 NULL
  107703. +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
  107704. +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
  107705. +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
  107706. +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
  107707. +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
  107708. +snd_interval_max_16529 snd_interval_max 0 16529 NULL
  107709. +raid10_resize_16537 raid10_resize 2 16537 NULL
  107710. +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
  107711. +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
  107712. +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
  107713. +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
  107714. +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
  107715. +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
  107716. +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
  107717. +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
  107718. +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
  107719. +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
  107720. +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
  107721. +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
  107722. +get_server_iovec_16804 get_server_iovec 2 16804 NULL
  107723. +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
  107724. +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
  107725. +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
  107726. +xfs_dialloc_ag_16868 xfs_dialloc_ag 0 16868 NULL
  107727. +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL nohasharray
  107728. +xfs_iget_16872 xfs_iget 0 16872 &alloc_idx_lebs_16872
  107729. +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
  107730. +st_write_16874 st_write 3 16874 NULL
  107731. +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
  107732. +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
  107733. +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
  107734. +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
  107735. +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
  107736. +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
  107737. +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
  107738. +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
  107739. +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
  107740. +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
  107741. +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
  107742. +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
  107743. +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
  107744. +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
  107745. +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
  107746. +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
  107747. +entry_length_17093 entry_length 0 17093 NULL
  107748. +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
  107749. +write_mem_17114 write_mem 3 17114 NULL
  107750. +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
  107751. +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
  107752. +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
  107753. +sep_read_17161 sep_read 3 17161 NULL
  107754. +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
  107755. +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
  107756. +UniStrnlen_17169 UniStrnlen 0 17169 NULL
  107757. +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
  107758. +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
  107759. +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
  107760. +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
  107761. +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
  107762. +sync_request_17208 sync_request 2 17208 NULL
  107763. +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
  107764. +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
  107765. +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
  107766. +alloc_ep_17269 alloc_ep 1 17269 NULL
  107767. +pg_read_17276 pg_read 3 17276 NULL
  107768. +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
  107769. +hmac_sha256_17278 hmac_sha256 2 17278 NULL
  107770. +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
  107771. +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
  107772. +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
  107773. +mb_cache_create_17307 mb_cache_create 2 17307 NULL
  107774. +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
  107775. +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
  107776. +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
  107777. +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
  107778. +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
  107779. +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
  107780. +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
  107781. +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
  107782. +xfs_btree_lshift_17448 xfs_btree_lshift 0 17448 NULL
  107783. +nla_get_u32_17455 nla_get_u32 0 17455 NULL
  107784. +__ref_totlen_17461 __ref_totlen 0 17461 NULL
  107785. +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
  107786. +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
  107787. +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
  107788. +qp_free_res_17541 qp_free_res 5 17541 NULL
  107789. +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
  107790. +copy_from_user_17559 copy_from_user 0-3 17559 NULL
  107791. +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
  107792. +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
  107793. +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
  107794. +osst_execute_17607 osst_execute 7-6 17607 NULL
  107795. +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
  107796. +dma_map_page_17628 dma_map_page 0 17628 NULL
  107797. +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
  107798. +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
  107799. +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
  107800. +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
  107801. +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
  107802. +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
  107803. +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
  107804. +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
  107805. +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
  107806. +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
  107807. +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
  107808. +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
  107809. +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
  107810. +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
  107811. +dm_stats_message_17863 dm_stats_message 5 17863 NULL
  107812. +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
  107813. +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
  107814. +virtio_cread32_17873 virtio_cread32 0 17873 NULL
  107815. +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
  107816. +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
  107817. +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
  107818. +init_per_cpu_17880 init_per_cpu 1 17880 NULL
  107819. +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
  107820. +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
  107821. +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
  107822. +xfs_rtallocate_extent_near_17916 xfs_rtallocate_extent_near 0 17916 NULL
  107823. +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
  107824. +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
  107825. +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
  107826. +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
  107827. +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
  107828. +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
  107829. +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
  107830. +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
  107831. +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
  107832. +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
  107833. +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
  107834. +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
  107835. +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
  107836. +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
  107837. +fpregs_get_18066 fpregs_get 4 18066 NULL
  107838. +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
  107839. +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
  107840. +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
  107841. +mpi_alloc_18094 mpi_alloc 1 18094 NULL
  107842. +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
  107843. +dfs_file_read_18116 dfs_file_read 3 18116 NULL
  107844. +svc_getnl_18120 svc_getnl 0 18120 NULL
  107845. +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
  107846. +xfs_zero_eof_18134 xfs_zero_eof 0 18134 NULL
  107847. +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
  107848. +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
  107849. +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
  107850. +gsm_control_message_18209 gsm_control_message 4 18209 NULL
  107851. +read_rindex_entry_18213 read_rindex_entry 0 18213 NULL
  107852. +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
  107853. +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
  107854. +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
  107855. +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
  107856. +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
  107857. +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
  107858. +alloc_ring_18278 alloc_ring 2-4 18278 NULL
  107859. +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
  107860. +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
  107861. +ext4_readpages_18283 ext4_readpages 4 18283 NULL
  107862. +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
  107863. +um_idi_write_18293 um_idi_write 3 18293 NULL
  107864. +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
  107865. +vga_r_18310 vga_r 0 18310 NULL
  107866. +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
  107867. +csio_mem_read_18319 csio_mem_read 3 18319 NULL
  107868. +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
  107869. +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
  107870. +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
  107871. +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
  107872. +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
  107873. +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
  107874. +ep_io_18367 ep_io 0 18367 NULL
  107875. +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
  107876. +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
  107877. +ci_role_write_18388 ci_role_write 3 18388 NULL
  107878. +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
  107879. +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
  107880. +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
  107881. +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
  107882. +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
  107883. +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
  107884. +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
  107885. +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
  107886. +regset_tls_set_18459 regset_tls_set 4 18459 NULL
  107887. +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
  107888. +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
  107889. +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
  107890. +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
  107891. +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
  107892. +__block_write_begin_18511 __block_write_begin 0 18511 NULL
  107893. +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
  107894. +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
  107895. +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
  107896. +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
  107897. +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
  107898. +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
  107899. +debug_output_18575 debug_output 3 18575 NULL
  107900. +xfs_btree_read_bufl_18597 xfs_btree_read_bufl 0 18597 NULL
  107901. +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
  107902. +iowarrior_write_18604 iowarrior_write 3 18604 NULL
  107903. +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL
  107904. +from_buffer_18625 from_buffer 3 18625 NULL
  107905. +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
  107906. +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
  107907. +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
  107908. +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
  107909. +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
  107910. +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
  107911. +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
  107912. +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
  107913. +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
  107914. +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
  107915. +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
  107916. +wep_packets_read_18751 wep_packets_read 3 18751 NULL
  107917. +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
  107918. +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
  107919. +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
  107920. +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
  107921. +dm_stats_print_18815 dm_stats_print 7 18815 NULL
  107922. +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
  107923. +mtf_test_write_18844 mtf_test_write 3 18844 NULL
  107924. +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
  107925. +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
  107926. +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
  107927. +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
  107928. +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
  107929. +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
  107930. +clean_journal_18955 clean_journal 0 18955 NULL
  107931. +__nla_reserve_18974 __nla_reserve 3 18974 NULL
  107932. +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
  107933. +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
  107934. +huge_page_size_19008 huge_page_size 0 19008 NULL
  107935. +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
  107936. +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
  107937. +revalidate_19043 revalidate 2 19043 NULL
  107938. +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
  107939. +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
  107940. +get_log_header_19063 get_log_header 0 19063 NULL
  107941. +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
  107942. +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
  107943. +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
  107944. +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
  107945. +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
  107946. +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
  107947. +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
  107948. +smk_write_access2_19170 smk_write_access2 3 19170 NULL
  107949. +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
  107950. +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
  107951. +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
  107952. +dev_counters_read_19216 dev_counters_read 3 19216 NULL
  107953. +wbcir_tx_19219 wbcir_tx 3 19219 NULL
  107954. +snd_mask_max_19224 snd_mask_max 0 19224 NULL
  107955. +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
  107956. +ucma_query_19260 ucma_query 4 19260 NULL
  107957. +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
  107958. +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
  107959. +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
  107960. +qc_capture_19298 qc_capture 3 19298 NULL
  107961. +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
  107962. +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
  107963. +debug_read_19322 debug_read 3 19322 NULL
  107964. +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
  107965. +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
  107966. +closure_sub_19359 closure_sub 2 19359 NULL
  107967. +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
  107968. +read_zero_19366 read_zero 3 19366 NULL
  107969. +interpret_user_input_19393 interpret_user_input 2 19393 NULL
  107970. +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
  107971. +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
  107972. +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
  107973. +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
  107974. +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
  107975. +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
  107976. +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
  107977. +sky2_read16_19475 sky2_read16 0 19475 NULL
  107978. +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
  107979. +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
  107980. +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
  107981. +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
  107982. +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
  107983. +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
  107984. +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
  107985. +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
  107986. +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
  107987. +nfsd_read_19568 nfsd_read 5 19568 NULL
  107988. +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
  107989. +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
  107990. +bm_status_read_19583 bm_status_read 3 19583 NULL
  107991. +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
  107992. +fallocate_chunk_19610 fallocate_chunk 0 19610 NULL
  107993. +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
  107994. +LoadBitmap_19658 LoadBitmap 2 19658 NULL
  107995. +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
  107996. +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
  107997. +read_reg_19723 read_reg 0 19723 NULL
  107998. +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
  107999. +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
  108000. +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
  108001. +p9_client_read_19750 p9_client_read 5-0 19750 NULL
  108002. +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
  108003. +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
  108004. +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
  108005. +readhscx_19769 readhscx 0 19769 NULL
  108006. +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
  108007. +xfs_bmap_add_extent_hole_real_19828 xfs_bmap_add_extent_hole_real 0 19828 NULL
  108008. +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
  108009. +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
  108010. +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
  108011. +__nla_put_19857 __nla_put 3 19857 NULL
  108012. +mrp_request_join_19882 mrp_request_join 4 19882 NULL
  108013. +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
  108014. +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
  108015. +mangle_name_19923 mangle_name 0 19923 NULL
  108016. +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
  108017. +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
  108018. +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
  108019. +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
  108020. +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
  108021. +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
  108022. +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
  108023. +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
  108024. +event_trigger_write_20009 event_trigger_write 3 20009 NULL nohasharray
  108025. +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 &event_trigger_write_20009
  108026. +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
  108027. +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
  108028. +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
  108029. +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
  108030. +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
  108031. +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
  108032. +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
  108033. +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
  108034. +team_options_register_20091 team_options_register 3 20091 NULL
  108035. +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
  108036. +xfs_qm_dqget_20103 xfs_qm_dqget 0 20103 NULL
  108037. +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
  108038. +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
  108039. +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
  108040. +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
  108041. +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
  108042. +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
  108043. +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
  108044. +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
  108045. +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
  108046. +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
  108047. +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
  108048. +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
  108049. +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
  108050. +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
  108051. +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
  108052. +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
  108053. +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
  108054. +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
  108055. +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
  108056. +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
  108057. +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
  108058. +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
  108059. +read_buf_20469 read_buf 2 20469 NULL
  108060. +bio_trim_20472 bio_trim 2 20472 NULL
  108061. +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
  108062. +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
  108063. +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
  108064. +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
  108065. +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
  108066. +venus_create_20555 venus_create 4 20555 NULL
  108067. +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
  108068. +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
  108069. +xfs_bmap_isaeof_20570 xfs_bmap_isaeof 0 20570 NULL
  108070. +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
  108071. +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
  108072. +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
  108073. +lirc_write_20604 lirc_write 3 20604 NULL
  108074. +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
  108075. +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
  108076. +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
  108077. +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
  108078. +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
  108079. +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
  108080. +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
  108081. +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
  108082. +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
  108083. +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
  108084. +cpumask_size_20683 cpumask_size 0 20683 NULL
  108085. +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
  108086. +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
  108087. +__maestro_read_20700 __maestro_read 0 20700 NULL
  108088. +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
  108089. +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
  108090. +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
  108091. +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
  108092. +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
  108093. +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
  108094. +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
  108095. +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
  108096. +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
  108097. +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
  108098. +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
  108099. +lowpan_write_20800 lowpan_write 3 20800 NULL
  108100. +strndup_user_20819 strndup_user 2 20819 NULL nohasharray
  108101. +do_glock_20819 do_glock 0 20819 &strndup_user_20819
  108102. +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
  108103. +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
  108104. +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
  108105. +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
  108106. +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
  108107. +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
  108108. +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
  108109. +srq_free_res_20868 srq_free_res 5 20868 NULL
  108110. +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
  108111. +rb_simple_write_20890 rb_simple_write 3 20890 NULL
  108112. +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
  108113. +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
  108114. +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
  108115. +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
  108116. +htable_bits_20933 htable_bits 0 20933 NULL
  108117. +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
  108118. +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
  108119. +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
  108120. +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
  108121. +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
  108122. +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
  108123. +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
  108124. +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
  108125. +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
  108126. +xfs_btree_new_root_21028 xfs_btree_new_root 0 21028 NULL
  108127. +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
  108128. +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
  108129. +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
  108130. +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
  108131. +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
  108132. +event_calibration_read_21083 event_calibration_read 3 21083 NULL
  108133. +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
  108134. +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
  108135. +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
  108136. +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
  108137. +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
  108138. +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
  108139. +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
  108140. +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
  108141. +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
  108142. +get_numpages_21227 get_numpages 0-1-2 21227 NULL
  108143. +input_ff_create_21240 input_ff_create 2 21240 NULL
  108144. +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
  108145. +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
  108146. +fru_length_21257 fru_length 0 21257 NULL
  108147. +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
  108148. +xfs_alloc_ag_vextent_size_21276 xfs_alloc_ag_vextent_size 0 21276 NULL
  108149. +do_msg_fill_21307 do_msg_fill 3 21307 NULL
  108150. +add_res_range_21310 add_res_range 4 21310 NULL
  108151. +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
  108152. +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
  108153. +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
  108154. +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
  108155. +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
  108156. +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
  108157. +video_ioctl2_21380 video_ioctl2 2 21380 NULL
  108158. +insert_ptr_21386 insert_ptr 6 21386 NULL
  108159. +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
  108160. +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
  108161. +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
  108162. +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
  108163. +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
  108164. +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
  108165. +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
  108166. +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
  108167. +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
  108168. +ReadISAR_21453 ReadISAR 0 21453 NULL
  108169. +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
  108170. +read_file_xmit_21487 read_file_xmit 3 21487 NULL
  108171. +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
  108172. +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
  108173. +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
  108174. +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
  108175. +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
  108176. +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
  108177. +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
  108178. +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
  108179. +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
  108180. +filemap_get_page_21606 filemap_get_page 2 21606 NULL
  108181. +gfs2_glock_nq_init_21624 gfs2_glock_nq_init 0 21624 NULL
  108182. +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
  108183. +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
  108184. +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
  108185. +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
  108186. +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
  108187. +xfs_btree_insert_21712 xfs_btree_insert 0 21712 NULL
  108188. +update_time_21719 update_time 0 21719 NULL
  108189. +unix_skb_len_21722 unix_skb_len 0 21722 NULL
  108190. +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
  108191. +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
  108192. +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
  108193. +gen_pool_add_21776 gen_pool_add 3 21776 NULL
  108194. +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
  108195. +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
  108196. +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
  108197. +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
  108198. +oom_adj_read_21847 oom_adj_read 3 21847 NULL
  108199. +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
  108200. +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
  108201. +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
  108202. +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
  108203. +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
  108204. +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
  108205. +__build_xattrs_21979 __build_xattrs 0 21979 NULL
  108206. +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
  108207. +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
  108208. +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 &compat_rw_copy_check_uvector_22001
  108209. +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
  108210. +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
  108211. +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
  108212. +lookup_metapath_22039 lookup_metapath 0 22039 NULL
  108213. +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
  108214. +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
  108215. +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
  108216. +mem_rw_22085 mem_rw 3 22085 NULL
  108217. +xfs_bmapi_reserve_delalloc_22086 xfs_bmapi_reserve_delalloc 0 22086 NULL
  108218. +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
  108219. +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
  108220. +shmem_add_to_page_cache_22121 shmem_add_to_page_cache 0 22121 NULL
  108221. +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
  108222. +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
  108223. +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
  108224. +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
  108225. +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
  108226. +mem_write_22232 mem_write 3 22232 NULL
  108227. +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
  108228. +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
  108229. +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
  108230. +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
  108231. +add_res_tree_22263 add_res_tree 7 22263 NULL
  108232. +__btrfs_direct_write_22273 __btrfs_direct_write 4-0 22273 NULL
  108233. +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
  108234. +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
  108235. +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
  108236. +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
  108237. +lov_setstripe_22307 lov_setstripe 2 22307 NULL
  108238. +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
  108239. +atomic_read_22342 atomic_read 0 22342 NULL
  108240. +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
  108241. +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
  108242. +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
  108243. +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
  108244. +zoran_write_22404 zoran_write 3 22404 NULL
  108245. +queue_reply_22416 queue_reply 3 22416 NULL
  108246. +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
  108247. +queue_max_segments_22441 queue_max_segments 0 22441 NULL
  108248. +handle_received_packet_22457 handle_received_packet 3 22457 NULL
  108249. +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
  108250. +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
  108251. +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
  108252. +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
  108253. +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
  108254. +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
  108255. +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
  108256. +dbFindCtl_22587 dbFindCtl 0 22587 NULL
  108257. +snapshot_read_22601 snapshot_read 3 22601 NULL
  108258. +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
  108259. +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
  108260. +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
  108261. +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
  108262. +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
  108263. +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
  108264. +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
  108265. +bch_dump_read_22685 bch_dump_read 3 22685 NULL
  108266. +reg_umr_22686 reg_umr 5 22686 NULL
  108267. +alloc_libipw_22708 alloc_libipw 1 22708 NULL
  108268. +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
  108269. +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
  108270. +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
  108271. +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
  108272. +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
  108273. +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
  108274. +print_frame_22769 print_frame 0 22769 NULL
  108275. +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
  108276. +__break_lease_22777 __break_lease 0 22777 NULL
  108277. +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
  108278. +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
  108279. +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
  108280. +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
  108281. +create_attr_set_22861 create_attr_set 1 22861 NULL
  108282. +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
  108283. +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
  108284. +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
  108285. +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
  108286. +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
  108287. +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
  108288. +__set_xattr_22923 __set_xattr 0 22923 NULL
  108289. +xstateregs_set_22932 xstateregs_set 4 22932 NULL
  108290. +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
  108291. +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
  108292. +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
  108293. +vme_get_size_22964 vme_get_size 0 22964 NULL
  108294. +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
  108295. +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
  108296. +usb_get_langid_22983 usb_get_langid 0 22983 NULL
  108297. +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
  108298. +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
  108299. +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
  108300. +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0 23029 NULL
  108301. +st_status_23032 st_status 5 23032 NULL
  108302. +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
  108303. +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
  108304. +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
  108305. +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
  108306. +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
  108307. +mei_cl_send_23068 mei_cl_send 3 23068 NULL
  108308. +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
  108309. +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
  108310. +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
  108311. +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
  108312. +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
  108313. +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
  108314. +xfs_dir_ialloc_23100 xfs_dir_ialloc 0 23100 NULL
  108315. +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
  108316. +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
  108317. +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
  108318. +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL nohasharray
  108319. +bset_tree_bytes_23111 bset_tree_bytes 0 23111 &nl80211_send_rx_auth_23111
  108320. +__clear_user_23118 __clear_user 0-2 23118 NULL
  108321. +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
  108322. +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
  108323. +read_file_ani_23161 read_file_ani 3 23161 NULL
  108324. +usblp_write_23178 usblp_write 3 23178 NULL
  108325. +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
  108326. +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
  108327. +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
  108328. +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
  108329. +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
  108330. +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
  108331. +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
  108332. +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
  108333. +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
  108334. +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
  108335. +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
  108336. +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
  108337. +i2cdev_write_23310 i2cdev_write 3 23310 NULL
  108338. +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
  108339. +page_readlink_23346 page_readlink 3 23346 NULL
  108340. +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
  108341. +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
  108342. +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
  108343. +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
  108344. +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
  108345. +vga_mm_r_23419 vga_mm_r 0 23419 NULL
  108346. +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
  108347. +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
  108348. +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
  108349. +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
  108350. +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
  108351. +event_filter_read_23494 event_filter_read 3 23494 NULL
  108352. +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
  108353. +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
  108354. +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
  108355. +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
  108356. +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
  108357. +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
  108358. +venus_symlink_23570 venus_symlink 6-4 23570 NULL
  108359. +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
  108360. +xfpregs_get_23586 xfpregs_get 4 23586 NULL
  108361. +snd_interval_min_23590 snd_interval_min 0 23590 NULL
  108362. +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
  108363. +xfs_qm_dqread_23613 xfs_qm_dqread 0 23613 NULL
  108364. +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
  108365. +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
  108366. +sInW_23663 sInW 0 23663 NULL
  108367. +SyS_connect_23669 SyS_connect 3 23669 NULL
  108368. +cx18_read_23699 cx18_read 3 23699 NULL
  108369. +at_get_23708 at_get 0 23708 NULL
  108370. +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
  108371. +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
  108372. +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
  108373. +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
  108374. +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
  108375. +mpt_free_res_23793 mpt_free_res 5 23793 NULL
  108376. +map_write_23795 map_write 3 23795 NULL
  108377. +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
  108378. +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
  108379. +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
  108380. +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
  108381. +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-4-3 23829 NULL
  108382. +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
  108383. +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
  108384. +p54_init_common_23850 p54_init_common 1 23850 NULL
  108385. +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
  108386. +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
  108387. +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
  108388. +writeback_single_inode_23881 writeback_single_inode 0 23881 NULL nohasharray
  108389. +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 &writeback_single_inode_23881
  108390. +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
  108391. +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
  108392. +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
  108393. +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
  108394. +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
  108395. +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
  108396. +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
  108397. +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
  108398. +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
  108399. +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
  108400. +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
  108401. +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
  108402. +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
  108403. +give_pages_24021 give_pages 3 24021 NULL
  108404. +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
  108405. +hmac_setkey_24043 hmac_setkey 3 24043 NULL
  108406. +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
  108407. +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
  108408. +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
  108409. +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
  108410. +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
  108411. +lov_brw_24122 lov_brw 4 24122 NULL
  108412. +mpu401_read_24126 mpu401_read 3-0 24126 NULL
  108413. +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
  108414. +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL nohasharray
  108415. +xfs_btree_increment_24139 xfs_btree_increment 0 24139 &irnet_ctrl_write_24139
  108416. +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
  108417. +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
  108418. +adu_read_24177 adu_read 3 24177 NULL
  108419. +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
  108420. +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
  108421. +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
  108422. +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
  108423. +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
  108424. +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
  108425. +pci_num_vf_24235 pci_num_vf 0 24235 NULL
  108426. +sel_read_bool_24236 sel_read_bool 3 24236 NULL
  108427. +xfs_bmap_rtalloc_24237 xfs_bmap_rtalloc 0 24237 NULL
  108428. +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
  108429. +calculate_sizes_24273 calculate_sizes 2 24273 NULL
  108430. +thin_status_24278 thin_status 5 24278 NULL
  108431. +msg_size_24288 msg_size 0 24288 NULL
  108432. +gserial_connect_24302 gserial_connect 0 24302 NULL
  108433. +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
  108434. +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
  108435. +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
  108436. +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
  108437. +prepare_pages_24349 prepare_pages 0 24349 NULL
  108438. +kzalloc_node_24352 kzalloc_node 1 24352 NULL
  108439. +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
  108440. +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
  108441. +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
  108442. +igetword_24373 igetword 0 24373 NULL nohasharray
  108443. +break_deleg_24373 break_deleg 0 24373 &igetword_24373
  108444. +max_io_len_24384 max_io_len 0-1 24384 NULL
  108445. +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
  108446. +xfs_bmapi_read_24392 xfs_bmapi_read 0 24392 NULL
  108447. +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
  108448. +getxattr_24398 getxattr 4 24398 NULL nohasharray
  108449. +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
  108450. +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
  108451. +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
  108452. +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
  108453. +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
  108454. +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
  108455. +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
  108456. +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
  108457. +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
  108458. +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
  108459. +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
  108460. +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
  108461. +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
  108462. +dut_mode_read_24489 dut_mode_read 3 24489 NULL
  108463. +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
  108464. +pd_video_read_24510 pd_video_read 3 24510 NULL
  108465. +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
  108466. +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
  108467. +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
  108468. +write_cache_pages_24562 write_cache_pages 0 24562 NULL
  108469. +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
  108470. +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
  108471. +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
  108472. +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
  108473. +SyS_poll_24620 SyS_poll 2 24620 NULL
  108474. +context_alloc_24645 context_alloc 3 24645 NULL
  108475. +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
  108476. +xfs_log_commit_cil_24653 xfs_log_commit_cil 0 24653 NULL
  108477. +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
  108478. +datafab_write_data_24696 datafab_write_data 4 24696 NULL
  108479. +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
  108480. +simple_attr_read_24738 simple_attr_read 3 24738 NULL
  108481. +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
  108482. +get_dma_residue_24749 get_dma_residue 0 24749 NULL
  108483. +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
  108484. +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
  108485. +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
  108486. +cache_read_24790 cache_read 3 24790 NULL
  108487. +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
  108488. +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
  108489. +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
  108490. +net2272_read_24825 net2272_read 0 24825 NULL
  108491. +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
  108492. +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
  108493. +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
  108494. +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
  108495. +queues_read_24877 queues_read 3 24877 NULL
  108496. +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
  108497. +xfs_qm_dqattach_24898 xfs_qm_dqattach 0 24898 NULL
  108498. +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
  108499. +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 NULL nohasharray
  108500. +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 &__btrfs_free_extent_24927
  108501. +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
  108502. +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
  108503. +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
  108504. +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
  108505. +slot_get_24999 slot_get 0 24999 NULL
  108506. +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
  108507. +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
  108508. +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
  108509. +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
  108510. +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
  108511. +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
  108512. +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
  108513. +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
  108514. +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
  108515. +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
  108516. +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
  108517. +gfs2_quota_check_25130 gfs2_quota_check 0 25130 NULL
  108518. +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
  108519. +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
  108520. +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
  108521. +mon_stat_read_25238 mon_stat_read 3 25238 NULL
  108522. +stripe_status_25259 stripe_status 5 25259 NULL
  108523. +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
  108524. +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
  108525. +vfs_writev_25278 vfs_writev 3 25278 NULL
  108526. +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
  108527. +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
  108528. +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
  108529. +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
  108530. +unix_mkname_25368 unix_mkname 0-2 25368 NULL
  108531. +sel_read_mls_25369 sel_read_mls 3 25369 NULL
  108532. +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
  108533. +xfs_ialloc_pagi_init_25411 xfs_ialloc_pagi_init 0 25411 NULL
  108534. +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
  108535. +xfs_qm_dqtobp_25448 xfs_qm_dqtobp 0 25448 NULL
  108536. +generic_file_buffered_write_25464 generic_file_buffered_write 4-0-7 25464 NULL
  108537. +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
  108538. +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
  108539. +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
  108540. +xfs_alloc_fix_freelist_25514 xfs_alloc_fix_freelist 0 25514 NULL
  108541. +sb_permission_25523 sb_permission 0 25523 NULL
  108542. +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
  108543. +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
  108544. +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
  108545. +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
  108546. +skb_tailroom_25567 skb_tailroom 0 25567 NULL
  108547. +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
  108548. +copy_user_generic_25611 copy_user_generic 0 25611 NULL
  108549. +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
  108550. +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
  108551. +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
  108552. +__direct_map_25647 __direct_map 5-6 25647 NULL
  108553. +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
  108554. +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
  108555. +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
  108556. +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
  108557. +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
  108558. +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
  108559. +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
  108560. +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
  108561. +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
  108562. +sg_read_25799 sg_read 3 25799 NULL
  108563. +xfs_alloc_ag_vextent_exact_25810 xfs_alloc_ag_vextent_exact 0 25810 NULL
  108564. +system_enable_read_25815 system_enable_read 3 25815 NULL
  108565. +realloc_buffer_25816 realloc_buffer 2 25816 NULL
  108566. +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
  108567. +parport_read_25855 parport_read 0 25855 NULL
  108568. +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
  108569. +key_attr_size_25865 key_attr_size 0 25865 NULL
  108570. +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
  108571. +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
  108572. +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
  108573. +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
  108574. +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
  108575. +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
  108576. +rcname_read_25919 rcname_read 3 25919 NULL
  108577. +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
  108578. +key_flags_read_25931 key_flags_read 3 25931 NULL
  108579. +copy_play_buf_25932 copy_play_buf 3 25932 NULL
  108580. +flush_25957 flush 2 25957 NULL
  108581. +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
  108582. +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
  108583. +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
  108584. +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
  108585. +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
  108586. +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
  108587. +btrfs_wait_ordered_range_26086 btrfs_wait_ordered_range 0 26086 NULL
  108588. +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
  108589. +read_sb_page_26119 read_sb_page 5 26119 NULL
  108590. +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
  108591. +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
  108592. +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
  108593. +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
  108594. +disk_devt_26180 disk_devt 0 26180 NULL
  108595. +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
  108596. +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
  108597. +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
  108598. +mce_write_26201 mce_write 3 26201 NULL
  108599. +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
  108600. +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
  108601. +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
  108602. +simple_setattr_26234 simple_setattr 0 26234 NULL
  108603. +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
  108604. +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
  108605. +apei_resources_request_26279 apei_resources_request 0 26279 NULL
  108606. +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
  108607. +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
  108608. +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
  108609. +check_can_nocow_26336 check_can_nocow 2 26336 NULL
  108610. +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
  108611. +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
  108612. +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
  108613. +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
  108614. +ntty_write_26404 ntty_write 3 26404 NULL
  108615. +firmware_store_26408 firmware_store 4 26408 NULL
  108616. +pagemap_read_26441 pagemap_read 3 26441 NULL
  108617. +tower_read_26461 tower_read 3 26461 NULL nohasharray
  108618. +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
  108619. +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
  108620. +ulong_write_file_26485 ulong_write_file 3 26485 NULL
  108621. +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
  108622. +read_vmcore_26501 read_vmcore 3 26501 NULL
  108623. +uhid_char_write_26502 uhid_char_write 3 26502 NULL
  108624. +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
  108625. +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
  108626. +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
  108627. +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
  108628. +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
  108629. +dio_new_bio_26562 dio_new_bio 0 26562 NULL
  108630. +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
  108631. +xfs_rtcheck_range_26614 xfs_rtcheck_range 0 26614 NULL
  108632. +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
  108633. +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
  108634. +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
  108635. +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
  108636. +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
  108637. +flowinfo_read_26683 flowinfo_read 3 26683 NULL
  108638. +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
  108639. +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
  108640. +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
  108641. +bos_desc_26752 bos_desc 0 26752 NULL
  108642. +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
  108643. +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
  108644. +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
  108645. +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
  108646. +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
  108647. +smk_write_load_26829 smk_write_load 3 26829 NULL
  108648. +xfs_alloc_pagf_init_26834 xfs_alloc_pagf_init 0 26834 NULL
  108649. +scnprint_id_26842 scnprint_id 3-0 26842 NULL
  108650. +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
  108651. +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
  108652. +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
  108653. +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
  108654. +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
  108655. +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
  108656. +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
  108657. +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
  108658. +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
  108659. +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
  108660. +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
  108661. +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
  108662. +hecubafb_write_26942 hecubafb_write 3 26942 NULL
  108663. +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
  108664. +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
  108665. +do_direct_IO_26979 do_direct_IO 0 26979 NULL
  108666. +xfs_filestream_associate_27030 xfs_filestream_associate 0 27030 NULL
  108667. +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
  108668. +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
  108669. +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
  108670. +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
  108671. +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
  108672. +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
  108673. +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
  108674. +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
  108675. +get_kernel_page_27133 get_kernel_page 0 27133 NULL
  108676. +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
  108677. +pms_capture_27142 pms_capture 4 27142 NULL
  108678. +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
  108679. +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
  108680. +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
  108681. +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
  108682. +write_kmem_27225 write_kmem 3 27225 NULL
  108683. +dbAllocAG_27228 dbAllocAG 0 27228 NULL
  108684. +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
  108685. +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
  108686. +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
  108687. +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
  108688. +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
  108689. +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
  108690. +afs_cell_create_27346 afs_cell_create 2 27346 NULL
  108691. +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
  108692. +pcbit_stat_27364 pcbit_stat 2 27364 NULL
  108693. +seq_read_27411 seq_read 3 27411 NULL
  108694. +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
  108695. +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
  108696. +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0 27422 NULL
  108697. +cypress_write_27423 cypress_write 4 27423 NULL
  108698. +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
  108699. +xfs_btree_lookup_get_block_27448 xfs_btree_lookup_get_block 0 27448 NULL
  108700. +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
  108701. +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
  108702. +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
  108703. +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
  108704. +garmin_read_process_27509 garmin_read_process 3 27509 NULL
  108705. +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
  108706. +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
  108707. +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
  108708. +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
  108709. +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
  108710. +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
  108711. +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
  108712. +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
  108713. +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
  108714. +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642 nohasharray
  108715. +xfs_alloc_vextent_27642 xfs_alloc_vextent 0 27642 &ocfs2_direct_IO_27642
  108716. +add_new_gdb_27643 add_new_gdb 3 27643 NULL
  108717. +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
  108718. +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
  108719. +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
  108720. +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
  108721. +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
  108722. +evm_write_key_27715 evm_write_key 3 27715 NULL
  108723. +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
  108724. +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
  108725. +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
  108726. +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
  108727. +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
  108728. +SyS_readv_27804 SyS_readv 3 27804 NULL
  108729. +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
  108730. +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
  108731. +init_header_complete_27833 init_header_complete 0 27833 NULL
  108732. +read_profile_27859 read_profile 3 27859 NULL
  108733. +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
  108734. +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
  108735. +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
  108736. +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
  108737. +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
  108738. +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
  108739. +device_register_27972 device_register 0 27972 NULL nohasharray
  108740. +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
  108741. +xfs_alloc_fixup_trees_27975 xfs_alloc_fixup_trees 0 27975 NULL
  108742. +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL nohasharray
  108743. +__kernfs_setattr_27977 __kernfs_setattr 0 27977 &pci_enable_device_flags_27977
  108744. +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
  108745. +seq_get_buf_28006 seq_get_buf 0 28006 NULL
  108746. +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
  108747. +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
  108748. +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
  108749. +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
  108750. +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
  108751. +pool_status_28055 pool_status 5 28055 NULL
  108752. +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
  108753. +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
  108754. +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
  108755. +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
  108756. +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
  108757. +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
  108758. +memblock_virt_alloc_from_nopanic_28146 memblock_virt_alloc_from_nopanic 1 28146 NULL
  108759. +video_read_28148 video_read 3 28148 NULL
  108760. +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
  108761. +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
  108762. +vread_28173 vread 0-3 28173 NULL
  108763. +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
  108764. +counter_free_res_28187 counter_free_res 5 28187 NULL
  108765. +read_disk_sb_28188 read_disk_sb 2 28188 NULL
  108766. +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
  108767. +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
  108768. +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
  108769. +amd_nb_num_28228 amd_nb_num 0 28228 NULL
  108770. +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
  108771. +usemap_size_28281 usemap_size 0 28281 NULL
  108772. +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
  108773. +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
  108774. +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
  108775. +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
  108776. +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
  108777. +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
  108778. +generic_write_checks_28329 generic_write_checks 0 28329 NULL
  108779. +bm_entry_write_28338 bm_entry_write 3 28338 NULL
  108780. +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
  108781. +snapshot_write_28351 snapshot_write 3 28351 NULL
  108782. +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
  108783. +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
  108784. +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
  108785. +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
  108786. +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
  108787. +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
  108788. +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
  108789. +mpage_readpages_28436 mpage_readpages 3 28436 NULL
  108790. +xfs_rtfind_back_28450 xfs_rtfind_back 0 28450 NULL
  108791. +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
  108792. +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
  108793. +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
  108794. +__filemap_fdatawrite_28485 __filemap_fdatawrite 0 28485 NULL
  108795. +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
  108796. +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
  108797. +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
  108798. +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
  108799. +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
  108800. +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
  108801. +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
  108802. +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
  108803. +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
  108804. +gfs2_meta_indirect_buffer_28573 gfs2_meta_indirect_buffer 0 28573 NULL
  108805. +oxygen_read32_28582 oxygen_read32 0 28582 NULL
  108806. +extract_entropy_28604 extract_entropy 5-3 28604 NULL
  108807. +kfifo_unused_28612 kfifo_unused 0 28612 NULL
  108808. +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
  108809. +setup_usemap_28636 setup_usemap 3-4 28636 NULL
  108810. +xfs_bmap_finish_28644 xfs_bmap_finish 0 28644 NULL
  108811. +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
  108812. +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
  108813. +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
  108814. +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
  108815. +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
  108816. +drm_plane_init_28731 drm_plane_init 6 28731 NULL
  108817. +spi_execute_28736 spi_execute 5 28736 NULL
  108818. +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
  108819. +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
  108820. +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
  108821. +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
  108822. +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
  108823. +sel_write_member_28800 sel_write_member 3 28800 NULL
  108824. +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
  108825. +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
  108826. +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
  108827. +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
  108828. +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
  108829. +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
  108830. +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
  108831. +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
  108832. +push_rx_28939 push_rx 3 28939 NULL
  108833. +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
  108834. +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
  108835. +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
  108836. +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
  108837. +xfs_alloc_update_28982 xfs_alloc_update 0 28982 NULL
  108838. +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
  108839. +bin_uuid_28999 bin_uuid 3 28999 NULL
  108840. +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
  108841. +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
  108842. +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
  108843. +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
  108844. +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
  108845. +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
  108846. +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
  108847. +xfs_alloc_ag_vextent_small_29084 xfs_alloc_ag_vextent_small 0 29084 NULL
  108848. +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
  108849. +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
  108850. +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
  108851. +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
  108852. +snprintf_29125 snprintf 0 29125 NULL
  108853. +iov_shorten_29130 iov_shorten 0 29130 NULL
  108854. +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
  108855. +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
  108856. +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
  108857. +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
  108858. +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
  108859. +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
  108860. +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
  108861. +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
  108862. +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
  108863. +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
  108864. +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
  108865. +xfs_bmap_btree_to_extents_29297 xfs_bmap_btree_to_extents 0 29297 NULL
  108866. +sn9c102_read_29305 sn9c102_read 3 29305 NULL
  108867. +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
  108868. +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
  108869. +xfs_bmbt_change_owner_29325 xfs_bmbt_change_owner 0 29325 NULL
  108870. +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
  108871. +tun_put_user_29337 tun_put_user 5 29337 NULL
  108872. +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
  108873. +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
  108874. +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
  108875. +mempool_create_29437 mempool_create 1 29437 NULL
  108876. +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
  108877. +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
  108878. +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
  108879. +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
  108880. +do_register_entry_29478 do_register_entry 4 29478 NULL
  108881. +simple_strtoul_29480 simple_strtoul 0 29480 NULL
  108882. +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
  108883. +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
  108884. +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
  108885. +write_file_regidx_29517 write_file_regidx 3 29517 NULL
  108886. +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
  108887. +add_to_page_cache_lru_29534 add_to_page_cache_lru 0 29534 NULL
  108888. +ftrace_write_29551 ftrace_write 3 29551 NULL
  108889. +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
  108890. +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
  108891. +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
  108892. +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
  108893. +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
  108894. +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
  108895. +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
  108896. +slots_per_page_29601 slots_per_page 0 29601 NULL
  108897. +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
  108898. +nla_get_u16_29624 nla_get_u16 0 29624 NULL
  108899. +gfs2_alloc_blocks_29630 gfs2_alloc_blocks 0 29630 NULL
  108900. +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
  108901. +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
  108902. +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
  108903. +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
  108904. +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
  108905. +probes_write_29711 probes_write 3 29711 NULL
  108906. +read_cis_cache_29735 read_cis_cache 4 29735 NULL
  108907. +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
  108908. +std_nic_write_29752 std_nic_write 3 29752 NULL
  108909. +dbAlloc_29794 dbAlloc 0 29794 NULL
  108910. +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
  108911. +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
  108912. +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
  108913. +count_partial_29850 count_partial 0 29850 NULL
  108914. +xfs_rtfind_forw_29866 xfs_rtfind_forw 0 29866 NULL
  108915. +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
  108916. +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
  108917. +scsi_end_request_29876 scsi_end_request 3 29876 NULL
  108918. +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
  108919. +xfs_alloc_read_agf_29893 xfs_alloc_read_agf 0 29893 NULL
  108920. +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
  108921. +write_file_queue_29922 write_file_queue 3 29922 NULL
  108922. +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
  108923. +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
  108924. +dev_mem_write_30028 dev_mem_write 3 30028 NULL
  108925. +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
  108926. +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
  108927. +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
  108928. +drp_wmove_30043 drp_wmove 4 30043 NULL
  108929. +mem_cgroup_charge_common_30047 mem_cgroup_charge_common 0 30047 NULL
  108930. +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
  108931. +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
  108932. +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
  108933. +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
  108934. +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
  108935. +xfs_iget_cache_miss_30115 xfs_iget_cache_miss 0 30115 NULL
  108936. +spi_async_locked_30117 spi_async_locked 0 30117 NULL
  108937. +recv_stream_30138 recv_stream 4 30138 NULL
  108938. +u_memcpya_30139 u_memcpya 3-2 30139 NULL
  108939. +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
  108940. +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
  108941. +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
  108942. +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
  108943. +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
  108944. +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
  108945. +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
  108946. +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
  108947. +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
  108948. +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
  108949. +shmem_unuse_inode_30263 shmem_unuse_inode 0 30263 NULL
  108950. +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
  108951. +try_break_deleg_30271 try_break_deleg 0 30271 NULL nohasharray
  108952. +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 &try_break_deleg_30271
  108953. +compat_readv_30273 compat_readv 3 30273 NULL
  108954. +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
  108955. +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
  108956. +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
  108957. +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
  108958. +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
  108959. +i8254_read_30330 i8254_read 0 30330 NULL
  108960. +resource_from_user_30341 resource_from_user 3 30341 NULL
  108961. +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
  108962. +gfs2_trans_begin_30359 gfs2_trans_begin 0 30359 NULL
  108963. +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
  108964. +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
  108965. +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
  108966. +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
  108967. +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
  108968. +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
  108969. +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
  108970. +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
  108971. +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
  108972. +enable_write_30456 enable_write 3 30456 NULL
  108973. +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
  108974. +urandom_read_30462 urandom_read 3 30462 NULL
  108975. +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
  108976. +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
  108977. +adu_write_30487 adu_write 3 30487 NULL
  108978. +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
  108979. +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
  108980. +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
  108981. +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
  108982. +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
  108983. +set_config_30526 set_config 0 30526 NULL nohasharray
  108984. +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
  108985. +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
  108986. +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
  108987. +set_le_30581 set_le 4 30581 NULL
  108988. +blk_init_tags_30592 blk_init_tags 1 30592 NULL
  108989. +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
  108990. +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
  108991. +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
  108992. +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
  108993. +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
  108994. +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
  108995. +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
  108996. +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
  108997. +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL nohasharray
  108998. +xfs_bmap_add_extent_unwritten_real_30701 xfs_bmap_add_extent_unwritten_real 0 30701 &dccp_setsockopt_ccid_30701
  108999. +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
  109000. +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
  109001. +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
  109002. +snapshot_status_30744 snapshot_status 5 30744 NULL
  109003. +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
  109004. +__bio_alloc_30787 __bio_alloc 3 30787 NULL
  109005. +smk_read_doi_30813 smk_read_doi 3 30813 NULL
  109006. +xlog_grant_head_wait_30829 xlog_grant_head_wait 0 30829 NULL
  109007. +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
  109008. +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
  109009. +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
  109010. +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
  109011. +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
  109012. +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
  109013. +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
  109014. +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
  109015. +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
  109016. +huge_page_mask_30981 huge_page_mask 0 30981 NULL
  109017. +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
  109018. +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
  109019. +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
  109020. +template_fmt_size_31033 template_fmt_size 0 31033 NULL
  109021. +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
  109022. +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
  109023. +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
  109024. +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
  109025. +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
  109026. +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
  109027. +depth_read_31112 depth_read 3 31112 NULL
  109028. +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
  109029. +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
  109030. +size_inside_page_31141 size_inside_page 0 31141 NULL
  109031. +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
  109032. +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
  109033. +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
  109034. +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
  109035. +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
  109036. +cpumask_weight_31215 cpumask_weight 0 31215 NULL
  109037. +__read_reg_31216 __read_reg 0 31216 NULL
  109038. +atm_get_addr_31221 atm_get_addr 3 31221 NULL
  109039. +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
  109040. +cyy_readb_31240 cyy_readb 0 31240 NULL
  109041. +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
  109042. +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
  109043. +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
  109044. +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
  109045. +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
  109046. +command_file_write_31318 command_file_write 3 31318 NULL
  109047. +radix_tree_insert_31336 radix_tree_insert 0 31336 NULL
  109048. +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
  109049. +outlen_write_31358 outlen_write 3 31358 NULL
  109050. +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
  109051. +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
  109052. +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
  109053. +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
  109054. +inb_31388 inb 0 31388 NULL
  109055. +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
  109056. +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
  109057. +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
  109058. +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
  109059. +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
  109060. +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
  109061. +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
  109062. +alg_setkey_31485 alg_setkey 3 31485 NULL
  109063. +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
  109064. +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
  109065. +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
  109066. +hidraw_write_31536 hidraw_write 3 31536 NULL
  109067. +usbvision_read_31555 usbvision_read 3 31555 NULL
  109068. +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
  109069. +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
  109070. +osst_write_31581 osst_write 3 31581 NULL
  109071. +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
  109072. +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
  109073. +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
  109074. +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
  109075. +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
  109076. +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
  109077. +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
  109078. +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
  109079. +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
  109080. +__lgread_31668 __lgread 4 31668 NULL
  109081. +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
  109082. +forced_ps_read_31685 forced_ps_read 3 31685 NULL
  109083. +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
  109084. +gfs2_dir_check_31711 gfs2_dir_check 0 31711 NULL
  109085. +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
  109086. +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
  109087. +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
  109088. +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
  109089. +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
  109090. +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
  109091. +bcm_char_read_31750 bcm_char_read 3 31750 NULL
  109092. +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
  109093. +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
  109094. +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
  109095. +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
  109096. +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
  109097. +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
  109098. +data_write_31805 data_write 3 31805 NULL
  109099. +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
  109100. +strnlen_user_31815 strnlen_user 0-2 31815 NULL
  109101. +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
  109102. +clone_bio_31854 clone_bio 4-3 31854 NULL
  109103. +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
  109104. +foreach_descriptor_31873 foreach_descriptor 0 31873 NULL
  109105. +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
  109106. +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
  109107. +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
  109108. +xattr_permission_31907 xattr_permission 0 31907 NULL
  109109. +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
  109110. +new_dir_31919 new_dir 3 31919 NULL
  109111. +kmem_alloc_31920 kmem_alloc 1 31920 NULL
  109112. +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
  109113. +read_mem_31942 read_mem 3 31942 NULL nohasharray
  109114. +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
  109115. +vb2_write_31948 vb2_write 3 31948 NULL
  109116. +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
  109117. +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
  109118. +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
  109119. +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
  109120. +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
  109121. +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
  109122. +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
  109123. +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
  109124. +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
  109125. +calc_hmac_32010 calc_hmac 3 32010 NULL
  109126. +aead_len_32021 aead_len 0 32021 NULL
  109127. +stk_read_32038 stk_read 3 32038 NULL
  109128. +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
  109129. +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
  109130. +xfs_buf_iowait_32068 xfs_buf_iowait 0 32068 NULL
  109131. +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
  109132. +bio_alloc_32095 bio_alloc 2 32095 NULL
  109133. +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
  109134. +disk_status_32120 disk_status 4 32120 NULL
  109135. +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
  109136. +venus_link_32165 venus_link 5 32165 NULL
  109137. +do_writepages_32173 do_writepages 0 32173 NULL
  109138. +del_ptr_32197 del_ptr 4 32197 NULL
  109139. +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
  109140. +__mem_cgroup_try_charge_swapin_32204 __mem_cgroup_try_charge_swapin 0 32204 NULL
  109141. +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
  109142. +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
  109143. +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
  109144. +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
  109145. +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
  109146. +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
  109147. +SyS_select_32319 SyS_select 1 32319 NULL
  109148. +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
  109149. +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
  109150. +xfs_bmap_extsize_align_32338 xfs_bmap_extsize_align 0 32338 NULL
  109151. +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
  109152. +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
  109153. +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
  109154. +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
  109155. +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
  109156. +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
  109157. +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
  109158. +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
  109159. +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
  109160. +xfs_alloc_put_freelist_32437 xfs_alloc_put_freelist 0 32437 NULL
  109161. +cache_status_32462 cache_status 5 32462 NULL
  109162. +fill_readbuf_32464 fill_readbuf 3 32464 NULL
  109163. +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
  109164. +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
  109165. +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
  109166. +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
  109167. +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
  109168. +disconnect_32521 disconnect 4 32521 NULL
  109169. +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
  109170. +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL
  109171. +ilo_read_32531 ilo_read 3 32531 NULL
  109172. +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
  109173. +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
  109174. +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
  109175. +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
  109176. +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
  109177. +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
  109178. +read_file_beacon_32595 read_file_beacon 3 32595 NULL
  109179. +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
  109180. +xfs_bmap_last_offset_32614 xfs_bmap_last_offset 0 32614 NULL
  109181. +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
  109182. +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
  109183. +kvmalloc_32646 kvmalloc 1 32646 NULL
  109184. +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
  109185. +generic_readlink_32654 generic_readlink 3 32654 NULL
  109186. +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
  109187. +apei_res_add_32674 apei_res_add 0 32674 NULL
  109188. +jfs_readpages_32702 jfs_readpages 4 32702 NULL
  109189. +xfs_filestream_new_ag_32711 xfs_filestream_new_ag 0 32711 NULL
  109190. +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
  109191. +xfs_bmbt_update_32713 xfs_bmbt_update 0 32713 NULL
  109192. +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
  109193. +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
  109194. +stats_read_ul_32751 stats_read_ul 3 32751 NULL
  109195. +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
  109196. +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
  109197. +xfs_trans_read_buf_32795 xfs_trans_read_buf 0 32795 NULL
  109198. +rproc_name_read_32805 rproc_name_read 3 32805 NULL
  109199. +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
  109200. +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
  109201. +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
  109202. +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
  109203. +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
  109204. +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
  109205. +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
  109206. +rmap_recycle_32938 rmap_recycle 3 32938 NULL
  109207. +xfs_log_reserve_32959 xfs_log_reserve 0 32959 NULL
  109208. +compat_filldir_32999 compat_filldir 3 32999 NULL
  109209. +SyS_syslog_33007 SyS_syslog 3 33007 NULL
  109210. +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
  109211. +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
  109212. +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
  109213. +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
  109214. +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
  109215. +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
  109216. +bitmap_resize_33054 bitmap_resize 2 33054 NULL
  109217. +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
  109218. +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
  109219. +alloc_tio_33077 alloc_tio 3 33077 NULL
  109220. +acl_permission_check_33083 acl_permission_check 0 33083 NULL
  109221. +fb_sys_write_33130 fb_sys_write 3 33130 NULL
  109222. +notify_change_33143 notify_change 0 33143 NULL
  109223. +SyS_poll_33152 SyS_poll 2 33152 NULL
  109224. +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
  109225. +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
  109226. +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
  109227. +pp_read_33210 pp_read 3 33210 NULL
  109228. +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
  109229. +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
  109230. +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
  109231. +sync_pt_create_33282 sync_pt_create 2 33282 NULL
  109232. +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
  109233. +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
  109234. +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
  109235. +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
  109236. +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
  109237. +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
  109238. +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
  109239. +read_file_regidx_33370 read_file_regidx 3 33370 NULL
  109240. +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
  109241. +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
  109242. +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
  109243. +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
  109244. +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
  109245. +filemap_fdatawrite_33415 filemap_fdatawrite 0 33415 NULL
  109246. +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
  109247. +dis_tap_write_33426 dis_tap_write 3 33426 NULL
  109248. +message_stats_list_33440 message_stats_list 5 33440 NULL
  109249. +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
  109250. +create_entry_33479 create_entry 2 33479 NULL
  109251. +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
  109252. +res_counter_read_33499 res_counter_read 4 33499 NULL
  109253. +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
  109254. +fb_read_33506 fb_read 3 33506 NULL
  109255. +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
  109256. +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
  109257. +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
  109258. +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
  109259. +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
  109260. +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
  109261. +count_subheaders_33591 count_subheaders 0 33591 NULL
  109262. +scsi_execute_33596 scsi_execute 5 33596 NULL
  109263. +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
  109264. +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
  109265. +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
  109266. +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
  109267. +xfs_btree_check_sblock_33618 xfs_btree_check_sblock 0 33618 NULL
  109268. +stride_page_count_33641 stride_page_count 2 33641 NULL
  109269. +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
  109270. +inw_p_33668 inw_p 0 33668 NULL
  109271. +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
  109272. +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
  109273. +submit_one_bio_33683 submit_one_bio 0 33683 NULL
  109274. +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
  109275. +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
  109276. +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
  109277. +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
  109278. +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
  109279. +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
  109280. +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
  109281. +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
  109282. +vifs_state_read_33762 vifs_state_read 3 33762 NULL
  109283. +hashtab_create_33769 hashtab_create 3 33769 NULL
  109284. +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
  109285. +filter_write_33819 filter_write 3 33819 NULL
  109286. +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
  109287. +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
  109288. +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
  109289. +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
  109290. +get_user_pages_33908 get_user_pages 0 33908 NULL
  109291. +sg_nents_33909 sg_nents 0 33909 NULL
  109292. +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
  109293. +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
  109294. +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
  109295. +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
  109296. +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
  109297. +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
  109298. +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
  109299. +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
  109300. +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
  109301. +ppp_write_34034 ppp_write 3 34034 NULL
  109302. +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
  109303. +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
  109304. +xfs_dialloc_34078 xfs_dialloc 0 34078 NULL
  109305. +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
  109306. +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
  109307. +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
  109308. +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
  109309. +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
  109310. +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
  109311. +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
  109312. +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
  109313. +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
  109314. +xfs_bmapi_write_34208 xfs_bmapi_write 0 34208 NULL
  109315. +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
  109316. +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
  109317. +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
  109318. +device_private_init_34279 device_private_init 0 34279 NULL
  109319. +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
  109320. +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
  109321. +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
  109322. +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
  109323. +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
  109324. +rngapi_reset_34366 rngapi_reset 3 34366 NULL
  109325. +ea_read_34378 ea_read 0 34378 NULL
  109326. +fuse_send_read_34379 fuse_send_read 4 34379 NULL
  109327. +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
  109328. +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
  109329. +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
  109330. +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
  109331. +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
  109332. +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
  109333. +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
  109334. +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
  109335. +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
  109336. +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
  109337. +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
  109338. +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
  109339. +security_inode_permission_34488 security_inode_permission 0 34488 NULL
  109340. +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
  109341. +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
  109342. +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
  109343. +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
  109344. +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
  109345. +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
  109346. +dbBackSplit_34561 dbBackSplit 0 34561 NULL
  109347. +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
  109348. +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
  109349. +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
  109350. +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
  109351. +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
  109352. +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
  109353. +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
  109354. +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
  109355. +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
  109356. +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
  109357. +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
  109358. +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
  109359. +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
  109360. +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
  109361. +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
  109362. +port_print_34704 port_print 3 34704 NULL
  109363. +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
  109364. +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
  109365. +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
  109366. +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
  109367. +bootmode_store_34762 bootmode_store 4 34762 NULL
  109368. +device_add_34766 device_add 0 34766 NULL
  109369. +xfs_iget_cache_hit_34767 xfs_iget_cache_hit 0 34767 NULL
  109370. +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
  109371. +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
  109372. +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
  109373. +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
  109374. +ll_setxattr_34806 ll_setxattr 4 34806 NULL
  109375. +file_page_index_34820 file_page_index 0-2 34820 NULL
  109376. +bio_segments_34832 bio_segments 0 34832 NULL
  109377. +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
  109378. +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
  109379. +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
  109380. +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
  109381. +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
  109382. +msg_print_text_34889 msg_print_text 0 34889 NULL
  109383. +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
  109384. +gfs2_glock_wait_34913 gfs2_glock_wait 0 34913 NULL
  109385. +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
  109386. +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
  109387. +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
  109388. +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
  109389. +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
  109390. +i2c_transfer_34958 i2c_transfer 0 34958 NULL
  109391. +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
  109392. +print_message_35000 print_message 0 35000 NULL
  109393. +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
  109394. +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
  109395. +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
  109396. +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
  109397. +xfs_rtallocate_extent_35052 xfs_rtallocate_extent 0 35052 NULL
  109398. +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
  109399. +ntfs_attr_extend_initialized_35084 ntfs_attr_extend_initialized 0 35084 NULL
  109400. +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
  109401. +capi_write_35104 capi_write 3 35104 NULL nohasharray
  109402. +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
  109403. +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
  109404. +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
  109405. +message_stats_print_35158 message_stats_print 6 35158 NULL
  109406. +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
  109407. +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
  109408. +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
  109409. +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
  109410. +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
  109411. +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
  109412. +set_fd_set_35249 set_fd_set 1 35249 NULL
  109413. +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
  109414. +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
  109415. +dis_disc_write_35265 dis_disc_write 3 35265 NULL
  109416. +dma_show_regs_35266 dma_show_regs 3 35266 NULL
  109417. +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
  109418. +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
  109419. +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
  109420. +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
  109421. +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
  109422. +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
  109423. +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
  109424. +xfs_btree_check_lblock_35333 xfs_btree_check_lblock 0 35333 NULL
  109425. +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
  109426. +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
  109427. +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
  109428. +compat_filldir64_35354 compat_filldir64 3 35354 NULL
  109429. +read_kmem_35372 read_kmem 3 35372 NULL
  109430. +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
  109431. +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
  109432. +buffer_to_user_35439 buffer_to_user 3 35439 NULL
  109433. +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
  109434. +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
  109435. +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
  109436. +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
  109437. +async_setkey_35521 async_setkey 3 35521 NULL
  109438. +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
  109439. +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
  109440. +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
  109441. +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
  109442. +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
  109443. +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
  109444. +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
  109445. +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
  109446. +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
  109447. +spk_msg_set_35586 spk_msg_set 3 35586 NULL
  109448. +kernel_readv_35617 kernel_readv 3 35617 NULL
  109449. +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
  109450. +pci_request_regions_35635 pci_request_regions 0 35635 NULL
  109451. +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
  109452. +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
  109453. +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
  109454. +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
  109455. +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
  109456. +md_super_write_35703 md_super_write 4 35703 NULL
  109457. +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
  109458. +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
  109459. +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
  109460. +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
  109461. +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
  109462. +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
  109463. +fls64_35862 fls64 0 35862 NULL
  109464. +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
  109465. +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
  109466. +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
  109467. +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
  109468. +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
  109469. +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
  109470. +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
  109471. +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
  109472. +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
  109473. +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
  109474. +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
  109475. +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
  109476. +acl_alloc_35979 acl_alloc 1 35979 NULL
  109477. +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
  109478. +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
  109479. +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
  109480. +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
  109481. +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
  109482. +account_shadowed_36048 account_shadowed 2 36048 NULL
  109483. +gpio_power_read_36059 gpio_power_read 3 36059 NULL
  109484. +write_emulate_36065 write_emulate 2-4 36065 NULL
  109485. +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
  109486. +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
  109487. +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
  109488. +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
  109489. +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
  109490. +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
  109491. +vga_arb_write_36112 vga_arb_write 3 36112 NULL
  109492. +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
  109493. +ext3_readpages_36144 ext3_readpages 4 36144 NULL
  109494. +twl_set_36154 twl_set 2 36154 NULL
  109495. +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
  109496. +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
  109497. +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
  109498. +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
  109499. +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
  109500. +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
  109501. +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
  109502. +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
  109503. +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
  109504. +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
  109505. +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
  109506. +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
  109507. +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
  109508. +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
  109509. +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
  109510. +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
  109511. +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
  109512. +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
  109513. +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
  109514. +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
  109515. +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
  109516. +lc_create_36332 lc_create 4 36332 NULL
  109517. +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
  109518. +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
  109519. +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
  109520. +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
  109521. +to_sector_36361 to_sector 0-1 36361 NULL
  109522. +tunables_read_36385 tunables_read 3 36385 NULL
  109523. +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
  109524. +sierra_write_36402 sierra_write 4 36402 NULL
  109525. +qdsb_get_36409 qdsb_get 0 36409 NULL
  109526. +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
  109527. +ReadW6692B_36445 ReadW6692B 0 36445 NULL
  109528. +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
  109529. +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
  109530. +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
  109531. +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
  109532. +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
  109533. +ip6_append_data_36490 ip6_append_data 4 36490 NULL nohasharray
  109534. +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
  109535. +cmd_loop_36491 cmd_loop 0 36491 NULL
  109536. +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
  109537. +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
  109538. +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
  109539. +get_param_l_36518 get_param_l 0 36518 NULL
  109540. +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
  109541. +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
  109542. +cpu_type_read_36540 cpu_type_read 3 36540 NULL
  109543. +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
  109544. +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
  109545. +__erst_read_36579 __erst_read 0 36579 NULL
  109546. +put_cmsg_36589 put_cmsg 4 36589 NULL
  109547. +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
  109548. +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
  109549. +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
  109550. +ced_ioctl_36647 ced_ioctl 2 36647 NULL
  109551. +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
  109552. +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
  109553. +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
  109554. +xillybus_read_36678 xillybus_read 3 36678 NULL
  109555. +gsmtty_write_36702 gsmtty_write 3 36702 NULL
  109556. +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
  109557. +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
  109558. +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
  109559. +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
  109560. +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
  109561. +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
  109562. +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
  109563. +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
  109564. +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
  109565. +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
  109566. +cm_write_36858 cm_write 3 36858 NULL
  109567. +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
  109568. +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
  109569. +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
  109570. +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
  109571. +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
  109572. +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
  109573. +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
  109574. +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
  109575. +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
  109576. +xfs_btree_check_sptr_36984 xfs_btree_check_sptr 0 36984 NULL
  109577. +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
  109578. +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
  109579. +setxattr_37006 setxattr 4 37006 NULL
  109580. +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
  109581. +command_file_read_37038 command_file_read 3 37038 NULL
  109582. +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
  109583. +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
  109584. +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
  109585. +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
  109586. +parse_command_37079 parse_command 2 37079 NULL
  109587. +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
  109588. +tun_get_user_37094 tun_get_user 5 37094 NULL
  109589. +xlog_grant_head_check_37116 xlog_grant_head_check 0 37116 NULL
  109590. +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
  109591. +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
  109592. +mtt_free_res_37144 mtt_free_res 5 37144 NULL
  109593. +msg_word_37164 msg_word 0 37164 NULL
  109594. +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
  109595. +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
  109596. +forced_ps_write_37209 forced_ps_write 3 37209 NULL
  109597. +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
  109598. +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
  109599. +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
  109600. +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
  109601. +__do_replace_37227 __do_replace 5 37227 NULL
  109602. +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
  109603. +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
  109604. +xfs_reclaim_inode_37257 xfs_reclaim_inode 0 37257 NULL
  109605. +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
  109606. +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
  109607. +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
  109608. +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
  109609. +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
  109610. +send_msg_37323 send_msg 4 37323 NULL
  109611. +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
  109612. +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
  109613. +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
  109614. +xfs_iomap_write_allocate_37336 xfs_iomap_write_allocate 0 37336 NULL
  109615. +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
  109616. +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
  109617. +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
  109618. +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
  109619. +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
  109620. +fru_alloc_37442 fru_alloc 1 37442 NULL
  109621. +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
  109622. +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
  109623. +xfs_btree_dec_cursor_37452 xfs_btree_dec_cursor 0 37452 NULL
  109624. +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
  109625. +get_est_timing_37484 get_est_timing 0 37484 NULL
  109626. +kmem_realloc_37489 kmem_realloc 2 37489 NULL
  109627. +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
  109628. +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
  109629. +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
  109630. +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
  109631. +fault_inject_read_37534 fault_inject_read 3 37534 NULL
  109632. +hdr_size_37536 hdr_size 0 37536 NULL
  109633. +extent_map_end_37550 extent_map_end 0 37550 NULL
  109634. +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
  109635. +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
  109636. +ioat_chansts_37558 ioat_chansts 0 37558 NULL
  109637. +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
  109638. +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
  109639. +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
  109640. +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
  109641. +SyS_mbind_37638 SyS_mbind 5 37638 NULL
  109642. +may_delete_37656 may_delete 0 37656 NULL
  109643. +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
  109644. +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
  109645. +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
  109646. +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
  109647. +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
  109648. +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
  109649. +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
  109650. +nametbl_header_37698 nametbl_header 2-0 37698 NULL
  109651. +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
  109652. +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
  109653. +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
  109654. +xfs_read_agf_37749 xfs_read_agf 0 37749 NULL
  109655. +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
  109656. +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
  109657. +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
  109658. +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
  109659. +smk_read_logging_37804 smk_read_logging 3 37804 NULL
  109660. +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
  109661. +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
  109662. +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
  109663. +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
  109664. +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
  109665. +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
  109666. +set_registers_37883 set_registers 4 37883 NULL
  109667. +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
  109668. +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
  109669. +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
  109670. +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
  109671. +write_file_bool_37957 write_file_bool 3 37957 NULL
  109672. +fifo_alloc_37961 fifo_alloc 1 37961 NULL
  109673. +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
  109674. +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
  109675. +vfs_readv_38011 vfs_readv 3 38011 NULL
  109676. +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
  109677. +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
  109678. +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
  109679. +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
  109680. +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
  109681. +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
  109682. +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
  109683. +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
  109684. +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
  109685. +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
  109686. +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
  109687. +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
  109688. +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
  109689. +ep0_read_38095 ep0_read 3 38095 NULL
  109690. +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
  109691. +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
  109692. +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
  109693. +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
  109694. +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
  109695. +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
  109696. +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
  109697. +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
  109698. +cdev_add_38176 cdev_add 2-3 38176 NULL
  109699. +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
  109700. +get_ucode_user_38202 get_ucode_user 3 38202 NULL
  109701. +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL nohasharray
  109702. +xfs_rtallocate_range_38223 xfs_rtallocate_range 0 38223 &osd_req_list_partition_collections_38223
  109703. +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
  109704. +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
  109705. +xfs_qm_dqrepair_38262 xfs_qm_dqrepair 0 38262 NULL
  109706. +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
  109707. +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
  109708. +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
  109709. +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
  109710. +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
  109711. +ucma_query_path_38305 ucma_query_path 3 38305 NULL
  109712. +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
  109713. +ida_simple_get_38326 ida_simple_get 0 38326 NULL
  109714. +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
  109715. +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
  109716. +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
  109717. +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
  109718. +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
  109719. +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
  109720. +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
  109721. +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
  109722. +dev_names_read_38509 dev_names_read 3 38509 NULL
  109723. +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
  109724. +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
  109725. +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
  109726. +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
  109727. +kuc_len_38557 kuc_len 0-1 38557 NULL
  109728. +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
  109729. +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
  109730. +_ipw_read32_38565 _ipw_read32 0 38565 NULL
  109731. +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
  109732. +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
  109733. +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
  109734. +icn_writecmd_38629 icn_writecmd 2 38629 NULL
  109735. +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
  109736. +ext2_readpages_38640 ext2_readpages 4 38640 NULL
  109737. +audit_init_entry_38644 audit_init_entry 1 38644 NULL
  109738. +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
  109739. +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
  109740. +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
  109741. +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
  109742. +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
  109743. +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
  109744. +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
  109745. +udf_readpages_38761 udf_readpages 4 38761 NULL
  109746. +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
  109747. +bcache_device_init_38781 bcache_device_init 3 38781 NULL
  109748. +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
  109749. +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
  109750. +err_decode_38804 err_decode 2 38804 NULL
  109751. +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
  109752. +direct_entry_38836 direct_entry 3 38836 NULL
  109753. +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
  109754. +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
  109755. +interfaces_38859 interfaces 2 38859 NULL
  109756. +dbgfs_state_38894 dbgfs_state 3 38894 NULL
  109757. +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
  109758. +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
  109759. +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
  109760. +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
  109761. +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
  109762. +bio_clone_range_38997 bio_clone_range 2 38997 NULL
  109763. +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
  109764. +get_nodes_39012 get_nodes 3 39012 NULL
  109765. +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
  109766. +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
  109767. +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
  109768. +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
  109769. +ReadHFC_39104 ReadHFC 0 39104 NULL
  109770. +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
  109771. +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
  109772. +ea_foreach_39133 ea_foreach 0 39133 NULL
  109773. +generic_permission_39150 generic_permission 0 39150 NULL
  109774. +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
  109775. +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
  109776. +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
  109777. +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
  109778. +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
  109779. +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
  109780. +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
  109781. +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
  109782. +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 NULL nohasharray
  109783. +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 &pwr_cont_miss_bcns_spread_read_39250
  109784. +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
  109785. +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
  109786. +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
  109787. +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
  109788. +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
  109789. +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
  109790. +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
  109791. +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
  109792. +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
  109793. +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
  109794. +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
  109795. +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
  109796. +__send_to_port_39386 __send_to_port 3 39386 NULL
  109797. +xfs_btree_dup_cursor_39394 xfs_btree_dup_cursor 0 39394 NULL
  109798. +gfs2_internal_read_39413 gfs2_internal_read 0 39413 NULL
  109799. +user_power_read_39414 user_power_read 3 39414 NULL
  109800. +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
  109801. +mic_desc_size_39464 mic_desc_size 0 39464 NULL
  109802. +apei_resources_add_39470 apei_resources_add 0 39470 NULL
  109803. +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
  109804. +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
  109805. +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
  109806. +int_proc_write_39542 int_proc_write 3 39542 NULL
  109807. +pp_write_39554 pp_write 3 39554 NULL
  109808. +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
  109809. +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
  109810. +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
  109811. +ext_depth_39607 ext_depth 0 39607 NULL
  109812. +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
  109813. +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
  109814. +sdio_readb_39618 sdio_readb 0 39618 NULL
  109815. +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
  109816. +set_dev_class_39645 set_dev_class 4 39645 NULL
  109817. +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
  109818. +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
  109819. +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
  109820. +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
  109821. +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
  109822. +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
  109823. +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
  109824. +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
  109825. +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
  109826. +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
  109827. +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
  109828. +get_priv_size_39828 get_priv_size 0-1 39828 NULL
  109829. +pkt_add_39897 pkt_add 3 39897 NULL
  109830. +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
  109831. +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
  109832. +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
  109833. +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
  109834. +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
  109835. +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
  109836. +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
  109837. +__spi_async_39932 __spi_async 0 39932 NULL
  109838. +__get_order_39935 __get_order 0 39935 NULL
  109839. +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
  109840. +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
  109841. +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
  109842. +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
  109843. +dma_push_rx_39973 dma_push_rx 2 39973 NULL
  109844. +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
  109845. +mthca_array_init_39987 mthca_array_init 2 39987 NULL
  109846. +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
  109847. +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
  109848. +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
  109849. +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
  109850. +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
  109851. +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
  109852. +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
  109853. +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
  109854. +atomic_xchg_40070 atomic_xchg 0 40070 NULL
  109855. +xfs_rtbuf_get_40107 xfs_rtbuf_get 0 40107 NULL
  109856. +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
  109857. +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
  109858. +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
  109859. +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
  109860. +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
  109861. +pt_write_40159 pt_write 3 40159 NULL
  109862. +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
  109863. +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
  109864. +allocate_probes_40204 allocate_probes 1 40204 NULL
  109865. +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
  109866. +compress_file_range_40225 compress_file_range 3-4 40225 NULL
  109867. +osst_read_40237 osst_read 3 40237 NULL
  109868. +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
  109869. +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
  109870. +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
  109871. +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
  109872. +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
  109873. +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
  109874. +SyS_bind_40303 SyS_bind 3 40303 NULL
  109875. +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
  109876. +mmio_read_40348 mmio_read 4 40348 NULL
  109877. +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
  109878. +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
  109879. +get_chars_40373 get_chars 3 40373 NULL
  109880. +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
  109881. +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
  109882. +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
  109883. +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
  109884. +SyS_writev_40467 SyS_writev 3 40467 NULL
  109885. +SyS_select_40473 SyS_select 1 40473 NULL
  109886. +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
  109887. +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
  109888. +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
  109889. +xfs_iread_extents_40510 xfs_iread_extents 0 40510 NULL
  109890. +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
  109891. +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
  109892. +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
  109893. +ima_write_policy_40548 ima_write_policy 3 40548 NULL
  109894. +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
  109895. +b1_get_byte_40597 b1_get_byte 0 40597 NULL
  109896. +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
  109897. +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
  109898. +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
  109899. +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
  109900. +fops_read_40672 fops_read 3 40672 NULL
  109901. +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
  109902. +alloc_rbio_40676 alloc_rbio 4 40676 NULL
  109903. +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
  109904. +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
  109905. +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
  109906. +__seq_open_private_40715 __seq_open_private 3 40715 NULL
  109907. +set_extent_bit_40719 set_extent_bit 0 40719 NULL
  109908. +fuse_readpages_40737 fuse_readpages 4 40737 NULL
  109909. +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
  109910. +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
  109911. +card_send_command_40757 card_send_command 3 40757 NULL
  109912. +ad1889_readl_40765 ad1889_readl 0 40765 NULL
  109913. +pg_write_40766 pg_write 3 40766 NULL
  109914. +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
  109915. +show_list_40775 show_list 3-0 40775 NULL
  109916. +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
  109917. +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
  109918. +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
  109919. +add_action_40811 add_action 4 40811 NULL
  109920. +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
  109921. +SyS_mbind_40828 SyS_mbind 5 40828 NULL
  109922. +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
  109923. +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
  109924. +read_file_queue_40895 read_file_queue 3 40895 NULL
  109925. +waiters_read_40902 waiters_read 3 40902 NULL
  109926. +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
  109927. +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
  109928. +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
  109929. +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
  109930. +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
  109931. +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
  109932. +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
  109933. +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
  109934. +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
  109935. +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
  109936. +_req_append_segment_41031 _req_append_segment 2 41031 NULL
  109937. +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
  109938. +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
  109939. +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
  109940. +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
  109941. +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
  109942. +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
  109943. +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
  109944. +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
  109945. +dma_attach_41094 dma_attach 5-6 41094 NULL
  109946. +provide_user_output_41105 provide_user_output 3 41105 NULL
  109947. +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
  109948. +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
  109949. +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
  109950. +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
  109951. +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
  109952. +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
  109953. +dfs_file_write_41196 dfs_file_write 3 41196 NULL
  109954. +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
  109955. +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
  109956. +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
  109957. +erst_read_41260 erst_read 0 41260 NULL
  109958. +alloc_context_41283 alloc_context 1 41283 NULL
  109959. +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
  109960. +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
  109961. +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
  109962. +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
  109963. +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
  109964. +kmp_init_41373 kmp_init 2 41373 NULL
  109965. +isr_commands_read_41398 isr_commands_read 3 41398 NULL
  109966. +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
  109967. +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
  109968. +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
  109969. +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
  109970. +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
  109971. +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4-0 41442 NULL
  109972. +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
  109973. +se_io_cb_41461 se_io_cb 3 41461 NULL
  109974. +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
  109975. +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
  109976. +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
  109977. +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
  109978. +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
  109979. +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
  109980. +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
  109981. +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
  109982. +SyS_preadv_41523 SyS_preadv 3 41523 NULL
  109983. +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
  109984. +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
  109985. +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
  109986. +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
  109987. +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
  109988. +rng_dev_read_41581 rng_dev_read 3 41581 NULL
  109989. +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
  109990. +vga_io_r_41609 vga_io_r 0 41609 NULL
  109991. +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
  109992. +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
  109993. +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
  109994. +a2mp_send_41615 a2mp_send 4 41615 NULL
  109995. +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
  109996. +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
  109997. +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
  109998. +get_std_timing_41654 get_std_timing 0 41654 NULL
  109999. +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
  110000. +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
  110001. +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
  110002. +fillonedir_41746 fillonedir 3 41746 NULL
  110003. +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
  110004. +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
  110005. +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
  110006. +sco_send_frame_41815 sco_send_frame 3 41815 NULL
  110007. +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
  110008. +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
  110009. +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
  110010. +xfs_rtget_summary_41864 xfs_rtget_summary 0 41864 NULL
  110011. +pci_map_single_41869 pci_map_single 0 41869 NULL
  110012. +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
  110013. +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
  110014. +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
  110015. +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
  110016. +sci_rxfill_41945 sci_rxfill 0 41945 NULL
  110017. +read_gssp_41947 read_gssp 3 41947 NULL
  110018. +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
  110019. +portnames_read_41958 portnames_read 3 41958 NULL
  110020. +dst_mtu_41969 dst_mtu 0 41969 NULL
  110021. +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
  110022. +xfs_qm_dqalloc_41985 xfs_qm_dqalloc 0 41985 NULL
  110023. +pool_allocate_42012 pool_allocate 3 42012 NULL
  110024. +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
  110025. +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
  110026. +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
  110027. +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
  110028. +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
  110029. +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
  110030. +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
  110031. +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
  110032. +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
  110033. +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
  110034. +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
  110035. +submit_inquiry_42108 submit_inquiry 3 42108 NULL
  110036. +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
  110037. +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
  110038. +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
  110039. +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
  110040. +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
  110041. +write_file_beacon_42185 write_file_beacon 3 42185 NULL
  110042. +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
  110043. +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
  110044. +xfs_rtfree_range_42244 xfs_rtfree_range 0 42244 NULL
  110045. +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
  110046. +find_last_bit_42260 find_last_bit 0 42260 NULL
  110047. +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
  110048. +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
  110049. +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
  110050. +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
  110051. +sel_read_perm_42302 sel_read_perm 3 42302 NULL
  110052. +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
  110053. +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
  110054. +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
  110055. +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
  110056. +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
  110057. +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
  110058. +tipc_send_42374 tipc_send 3 42374 NULL
  110059. +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
  110060. +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
  110061. +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
  110062. +krng_get_random_42420 krng_get_random 3 42420 NULL
  110063. +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
  110064. +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
  110065. +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
  110066. +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
  110067. +kuc_free_42455 kuc_free 2 42455 NULL
  110068. +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
  110069. +omfs_readpages_42490 omfs_readpages 4 42490 NULL
  110070. +bypass_write_42498 bypass_write 3 42498 NULL
  110071. +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
  110072. +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
  110073. +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
  110074. +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
  110075. +dbAllocNear_42546 dbAllocNear 0 42546 NULL
  110076. +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
  110077. +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
  110078. +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
  110079. +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
  110080. +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
  110081. +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
  110082. +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
  110083. +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
  110084. +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
  110085. +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
  110086. +request_key_and_link_42693 request_key_and_link 4 42693 NULL
  110087. +vb2_read_42703 vb2_read 3 42703 NULL
  110088. +read_status_42722 read_status 0 42722 NULL
  110089. +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
  110090. +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
  110091. +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
  110092. +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
  110093. +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
  110094. +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
  110095. +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
  110096. +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
  110097. +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
  110098. +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
  110099. +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
  110100. +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
  110101. +drm_ioctl_42813 drm_ioctl 2 42813 NULL
  110102. +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
  110103. +set_arg_42824 set_arg 3 42824 NULL
  110104. +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
  110105. +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
  110106. +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
  110107. +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
  110108. +hd_end_request_42904 hd_end_request 2 42904 NULL
  110109. +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
  110110. +xfs_bmapi_allocate_42938 xfs_bmapi_allocate 0 42938 NULL
  110111. +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
  110112. +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
  110113. +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
  110114. +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
  110115. +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
  110116. +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
  110117. +xfs_da_read_buf_43008 xfs_da_read_buf 0 43008 NULL
  110118. +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
  110119. +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
  110120. +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
  110121. +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
  110122. +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
  110123. +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
  110124. +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
  110125. +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
  110126. +read_file_dfs_43145 read_file_dfs 3 43145 NULL
  110127. +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
  110128. +usb_string_sub_43164 usb_string_sub 0 43164 NULL
  110129. +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
  110130. +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
  110131. +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
  110132. +uio_write_43202 uio_write 3 43202 NULL
  110133. +iso_callback_43208 iso_callback 3 43208 NULL
  110134. +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
  110135. +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
  110136. +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
  110137. +inode_init_always_43225 inode_init_always 0 43225 NULL
  110138. +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
  110139. +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
  110140. +ide_end_rq_43269 ide_end_rq 4 43269 NULL
  110141. +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
  110142. +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
  110143. +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
  110144. +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
  110145. +mpage_alloc_43299 mpage_alloc 3 43299 NULL
  110146. +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
  110147. +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
  110148. +xfs_log_regrant_43350 xfs_log_regrant 0 43350 NULL
  110149. +gfs2_rgrp_bh_get_43375 gfs2_rgrp_bh_get 0 43375 NULL
  110150. +xfs_btree_new_iroot_43392 xfs_btree_new_iroot 0 43392 NULL
  110151. +xenfb_write_43412 xenfb_write 3 43412 NULL
  110152. +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
  110153. +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
  110154. +cifs_writev_43437 cifs_writev 4 43437 NULL
  110155. +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
  110156. +usb_string_43443 usb_string 0 43443 NULL nohasharray
  110157. +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
  110158. +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
  110159. +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
  110160. +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
  110161. +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
  110162. +do_readlink_43518 do_readlink 2 43518 NULL
  110163. +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
  110164. +read_events_43534 read_events 3 43534 NULL
  110165. +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
  110166. +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
  110167. +request_resource_43548 request_resource 0 43548 NULL
  110168. +rpc_malloc_43573 rpc_malloc 2 43573 NULL
  110169. +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
  110170. +proc_read_43614 proc_read 3 43614 NULL
  110171. +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
  110172. +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
  110173. +random_write_43656 random_write 3 43656 NULL
  110174. +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
  110175. +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
  110176. +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
  110177. +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
  110178. +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
  110179. +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
  110180. +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
  110181. +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
  110182. +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
  110183. +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
  110184. +xfs_alloc_lookup_eq_43775 xfs_alloc_lookup_eq 0 43775 NULL
  110185. +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
  110186. +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
  110187. +xfs_trans_reserve_quota_bydquots_43797 xfs_trans_reserve_quota_bydquots 0 43797 NULL
  110188. +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
  110189. +_xfs_filestream_update_ag_43824 _xfs_filestream_update_ag 0 43824 NULL
  110190. +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
  110191. +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
  110192. +read_flush_43851 read_flush 3 43851 NULL
  110193. +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
  110194. +SendString_43928 SendString 3 43928 NULL
  110195. +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
  110196. +xfs_trans_dqresv_43960 xfs_trans_dqresv 0 43960 NULL
  110197. +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
  110198. +nla_reserve_43984 nla_reserve 3 43984 NULL
  110199. +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
  110200. +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
  110201. +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
  110202. +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
  110203. +ulist_add_43994 ulist_add 0 43994 NULL
  110204. +emit_flags_44006 emit_flags 4-3 44006 NULL
  110205. +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
  110206. +fru_strlen_44046 fru_strlen 0 44046 NULL
  110207. +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
  110208. +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
  110209. +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL nohasharray
  110210. +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 &pci_msix_vec_count_44093
  110211. +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
  110212. +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
  110213. +file_remove_suid_44122 file_remove_suid 0 44122 NULL nohasharray
  110214. +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 &file_remove_suid_44122
  110215. +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
  110216. +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
  110217. +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
  110218. +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
  110219. +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
  110220. +readreg_ipac_44186 readreg_ipac 0 44186 NULL
  110221. +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
  110222. +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
  110223. +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
  110224. +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
  110225. +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
  110226. +device_create_file_44285 device_create_file 0 44285 NULL
  110227. +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
  110228. +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
  110229. +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
  110230. +ccp_init_data_44324 ccp_init_data 5 44324 NULL
  110231. +rs_init_44327 rs_init 1 44327 NULL
  110232. +radix_tree_maybe_preload_44346 radix_tree_maybe_preload 0 44346 NULL
  110233. +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
  110234. +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
  110235. +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
  110236. +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
  110237. +aoedev_flush_44398 aoedev_flush 2 44398 NULL
  110238. +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
  110239. +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
  110240. +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
  110241. +xfs_mod_incore_sb_44439 xfs_mod_incore_sb 0 44439 NULL
  110242. +write_file_debug_44476 write_file_debug 3 44476 NULL
  110243. +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
  110244. +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
  110245. +bio_advance_44496 bio_advance 2 44496 NULL
  110246. +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
  110247. +ac_register_board_44504 ac_register_board 3 44504 NULL
  110248. +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
  110249. +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
  110250. +spidev_write_44510 spidev_write 3 44510 NULL
  110251. +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
  110252. +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
  110253. +comm_write_44537 comm_write 3 44537 NULL
  110254. +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
  110255. +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
  110256. +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
  110257. +xfs_bmapi_delay_44630 xfs_bmapi_delay 0 44630 NULL
  110258. +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
  110259. +mpi_resize_44674 mpi_resize 2 44674 NULL
  110260. +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
  110261. +ts_read_44687 ts_read 3 44687 NULL
  110262. +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
  110263. +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
  110264. +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
  110265. +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
  110266. +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
  110267. +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
  110268. +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
  110269. +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
  110270. +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
  110271. +pty_write_44757 pty_write 3 44757 &tnode_new_44757
  110272. +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
  110273. +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
  110274. +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
  110275. +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
  110276. +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
  110277. +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
  110278. +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
  110279. +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
  110280. +sisusb_write_44834 sisusb_write 3 44834 NULL
  110281. +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
  110282. +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
  110283. +copydesc_user_44855 copydesc_user 3 44855 NULL
  110284. +set_advertising_44870 set_advertising 4 44870 NULL
  110285. +init_rs_44873 init_rs 1 44873 NULL
  110286. +skb_availroom_44883 skb_availroom 0 44883 NULL
  110287. +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
  110288. +do_tty_write_44896 do_tty_write 5 44896 NULL
  110289. +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
  110290. +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
  110291. +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
  110292. +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
  110293. +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
  110294. +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
  110295. +sel_write_user_45060 sel_write_user 3 45060 NULL
  110296. +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
  110297. +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
  110298. +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
  110299. +usbdev_read_45114 usbdev_read 3 45114 NULL
  110300. +send_to_tty_45141 send_to_tty 3 45141 NULL
  110301. +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
  110302. +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
  110303. +device_write_45156 device_write 3 45156 NULL nohasharray
  110304. +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
  110305. +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
  110306. +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
  110307. +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
  110308. +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
  110309. +__radix_tree_preload_45197 __radix_tree_preload 0 45197 NULL
  110310. +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
  110311. +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
  110312. +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
  110313. +event_enable_write_45238 event_enable_write 3 45238 NULL
  110314. +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
  110315. +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
  110316. +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
  110317. +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
  110318. +xfs_alert_fsblock_zero_45304 xfs_alert_fsblock_zero 0 45304 NULL
  110319. +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
  110320. +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
  110321. +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
  110322. +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
  110323. +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
  110324. +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
  110325. +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
  110326. +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
  110327. +__node_remap_45458 __node_remap 4 45458 NULL
  110328. +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
  110329. +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
  110330. +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
  110331. +xfs_btree_block_change_owner_45476 xfs_btree_block_change_owner 0 45476 NULL
  110332. +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
  110333. +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
  110334. +copy_macs_45534 copy_macs 4 45534 NULL
  110335. +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
  110336. +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
  110337. +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
  110338. +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
  110339. +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
  110340. +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
  110341. +venus_rmdir_45564 venus_rmdir 4 45564 NULL
  110342. +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
  110343. +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
  110344. +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
  110345. +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
  110346. +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
  110347. +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
  110348. +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
  110349. +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
  110350. +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
  110351. +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
  110352. +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
  110353. +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
  110354. +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
  110355. +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
  110356. +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
  110357. +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
  110358. +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
  110359. +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
  110360. +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
  110361. +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
  110362. +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
  110363. +insert_state_45848 insert_state 0 45848 NULL
  110364. +x509_process_extension_45854 x509_process_extension 5 45854 NULL
  110365. +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
  110366. +isdn_write_45863 isdn_write 3 45863 NULL
  110367. +tpm_config_in_45880 tpm_config_in 0 45880 NULL
  110368. +get_rdac_req_45882 get_rdac_req 3 45882 NULL
  110369. +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
  110370. +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
  110371. +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
  110372. +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
  110373. +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
  110374. +alloc_mr_45935 alloc_mr 1 45935 NULL
  110375. +copy_to_45969 copy_to 3 45969 NULL
  110376. +rb_simple_read_45972 rb_simple_read 3 45972 NULL
  110377. +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
  110378. +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
  110379. +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
  110380. +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
  110381. +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
  110382. +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
  110383. +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
  110384. +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
  110385. +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
  110386. +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
  110387. +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
  110388. +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
  110389. +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
  110390. +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
  110391. +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
  110392. +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
  110393. +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
  110394. +twl_direction_out_46182 twl_direction_out 2 46182 NULL
  110395. +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
  110396. +fq_resize_46195 fq_resize 2 46195 NULL
  110397. +add_conn_list_46197 add_conn_list 3-0 46197 NULL
  110398. +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
  110399. +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
  110400. +dsp_write_46218 dsp_write 2 46218 NULL
  110401. +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
  110402. +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
  110403. +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
  110404. +ReadReg_46277 ReadReg 0 46277 NULL
  110405. +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
  110406. +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
  110407. +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
  110408. +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
  110409. +smk_write_direct_46363 smk_write_direct 3 46363 NULL
  110410. +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
  110411. +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
  110412. +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
  110413. +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
  110414. +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
  110415. +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
  110416. +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
  110417. +filldir64_46469 filldir64 3 46469 NULL
  110418. +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
  110419. +pin_code_reply_46510 pin_code_reply 4 46510 NULL
  110420. +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
  110421. +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
  110422. +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
  110423. +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
  110424. +dn_current_mss_46574 dn_current_mss 0 46574 NULL
  110425. +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
  110426. +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
  110427. +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
  110428. +vscnprintf_46617 vscnprintf 0-2 46617 NULL
  110429. +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
  110430. +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
  110431. +pci_enable_device_46642 pci_enable_device 0 46642 NULL
  110432. +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
  110433. +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
  110434. +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
  110435. +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
  110436. +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
  110437. +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
  110438. +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
  110439. +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
  110440. +read_file_tx99_46741 read_file_tx99 3 46741 NULL
  110441. +ext4_count_free_46754 ext4_count_free 2 46754 NULL
  110442. +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
  110443. +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
  110444. +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
  110445. +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
  110446. +readreg_46845 readreg 0 46845 NULL
  110447. +spi_async_46857 spi_async 0 46857 NULL
  110448. +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
  110449. +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
  110450. +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
  110451. +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
  110452. +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
  110453. +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
  110454. +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
  110455. +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
  110456. +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
  110457. +fb_write_46924 fb_write 3 46924 NULL
  110458. +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
  110459. +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL nohasharray
  110460. +ntfs_truncate_46953 ntfs_truncate 0 46953 &qla4xxx_post_aen_work_46953
  110461. +SYSC_poll_46965 SYSC_poll 2 46965 NULL
  110462. +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
  110463. +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
  110464. +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
  110465. +sel_write_bool_46996 sel_write_bool 3 46996 NULL
  110466. +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
  110467. +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
  110468. +fs_path_len_47060 fs_path_len 0 47060 NULL
  110469. +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
  110470. +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
  110471. +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
  110472. +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
  110473. +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
  110474. +mousedev_read_47123 mousedev_read 3 47123 NULL
  110475. +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
  110476. +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
  110477. +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
  110478. +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
  110479. +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
  110480. +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
  110481. +xfs_btree_get_buf_block_47197 xfs_btree_get_buf_block 0 47197 NULL
  110482. +options_write_47243 options_write 3 47243 NULL
  110483. +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
  110484. +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
  110485. +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
  110486. +vsnprintf_47291 vsnprintf 0 47291 NULL
  110487. +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
  110488. +xfs_trans_reserve_quota_nblks_47313 xfs_trans_reserve_quota_nblks 0 47313 NULL
  110489. +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
  110490. +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
  110491. +gfs2_replay_read_block_47357 gfs2_replay_read_block 0 47357 NULL
  110492. +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
  110493. +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
  110494. +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
  110495. +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
  110496. +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
  110497. +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
  110498. +nametbl_list_47391 nametbl_list 2 47391 NULL
  110499. +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
  110500. +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
  110501. +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
  110502. +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
  110503. +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
  110504. +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
  110505. +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
  110506. +newpart_47485 newpart 6-4 47485 NULL
  110507. +core_sys_select_47494 core_sys_select 1 47494 NULL
  110508. +unlink_simple_47506 unlink_simple 3 47506 NULL
  110509. +pstore_decompress_47510 pstore_decompress 0 47510 NULL
  110510. +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
  110511. +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
  110512. +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
  110513. +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
  110514. +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
  110515. +read_ldt_47570 read_ldt 2 47570 NULL
  110516. +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
  110517. +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
  110518. +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
  110519. +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
  110520. +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
  110521. +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
  110522. +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
  110523. +get_size_47644 get_size 1-2 47644 NULL
  110524. +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
  110525. +save_microcode_47717 save_microcode 3 47717 NULL
  110526. +bits_to_user_47733 bits_to_user 2-3 47733 NULL
  110527. +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
  110528. +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
  110529. +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
  110530. +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
  110531. +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
  110532. +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
  110533. +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
  110534. +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
  110535. +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
  110536. +lov_packmd_47810 lov_packmd 0 47810 NULL
  110537. +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
  110538. +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
  110539. +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
  110540. +vhci_read_47878 vhci_read 3 47878 NULL
  110541. +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
  110542. +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
  110543. +comedi_write_47926 comedi_write 3 47926 NULL
  110544. +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
  110545. +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
  110546. +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
  110547. +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
  110548. +ib_umad_write_47993 ib_umad_write 3 47993 NULL
  110549. +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
  110550. +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
  110551. +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
  110552. +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
  110553. +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
  110554. +SYSC_writev_48040 SYSC_writev 3 48040 NULL
  110555. +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
  110556. +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
  110557. +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
  110558. +disc_write_48070 disc_write 3 48070 NULL
  110559. +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
  110560. +xfs_read_agi_48100 xfs_read_agi 0 48100 NULL
  110561. +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
  110562. +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
  110563. +set_discoverable_48141 set_discoverable 4 48141 NULL
  110564. +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
  110565. +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
  110566. +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
  110567. +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
  110568. +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
  110569. +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
  110570. +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
  110571. +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
  110572. +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
  110573. +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
  110574. +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
  110575. +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
  110576. +read_file_recv_48232 read_file_recv 3 48232 NULL
  110577. +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
  110578. +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
  110579. +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
  110580. +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
  110581. +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
  110582. +trace_options_write_48275 trace_options_write 3 48275 NULL
  110583. +send_set_info_48288 send_set_info 7 48288 NULL
  110584. +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
  110585. +timblogiw_read_48305 timblogiw_read 3 48305 NULL
  110586. +hash_setkey_48310 hash_setkey 3 48310 NULL
  110587. +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
  110588. +skb_add_data_48363 skb_add_data 3 48363 NULL
  110589. +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
  110590. +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
  110591. +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
  110592. +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
  110593. +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
  110594. +print_filtered_48442 print_filtered 2-0 48442 NULL
  110595. +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
  110596. +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
  110597. +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
  110598. +send_control_msg_48498 send_control_msg 6 48498 NULL
  110599. +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
  110600. +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
  110601. +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
  110602. +phantom_get_free_48514 phantom_get_free 0 48514 NULL
  110603. +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
  110604. +raid10_size_48571 raid10_size 0-2-3 48571 NULL
  110605. +llog_data_len_48607 llog_data_len 1 48607 NULL
  110606. +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
  110607. +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
  110608. +mtd_read_48655 mtd_read 0 48655 NULL
  110609. +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
  110610. +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
  110611. +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
  110612. +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
  110613. +altera_drscan_48698 altera_drscan 2 48698 NULL
  110614. +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
  110615. +recv_msg_48709 recv_msg 4 48709 NULL
  110616. +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
  110617. +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
  110618. +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
  110619. +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
  110620. +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
  110621. +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
  110622. +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
  110623. +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
  110624. +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
  110625. +azx_get_position_48841 azx_get_position 0 48841 NULL
  110626. +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
  110627. +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
  110628. +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
  110629. +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
  110630. +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
  110631. +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
  110632. +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
  110633. +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
  110634. +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
  110635. +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
  110636. +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
  110637. +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
  110638. +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
  110639. +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
  110640. +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
  110641. +xfs_trans_commit_48982 xfs_trans_commit 0 48982 NULL
  110642. +gfs2_dir_add_48987 gfs2_dir_add 0 48987 NULL
  110643. +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
  110644. +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
  110645. +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
  110646. +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
  110647. +transient_status_49027 transient_status 4 49027 NULL
  110648. +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
  110649. +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
  110650. +scsi_register_49094 scsi_register 2 49094 NULL
  110651. +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
  110652. +gfs2_diradd_alloc_required_49105 gfs2_diradd_alloc_required 0 49105 NULL
  110653. +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
  110654. +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
  110655. +pt_read_49136 pt_read 3 49136 NULL
  110656. +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
  110657. +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
  110658. +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
  110659. +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
  110660. +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
  110661. +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
  110662. +print_queue_49191 print_queue 4-0 49191 NULL
  110663. +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
  110664. +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
  110665. +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
  110666. +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
  110667. +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
  110668. +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
  110669. +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
  110670. +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
  110671. +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
  110672. +uio_read_49300 uio_read 3 49300 NULL
  110673. +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
  110674. +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
  110675. +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
  110676. +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
  110677. +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
  110678. +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
  110679. +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
  110680. +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
  110681. +tnode_alloc_49407 tnode_alloc 1 49407 NULL
  110682. +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
  110683. +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
  110684. +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
  110685. +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
  110686. +xfs_iformat_local_49472 xfs_iformat_local 4-0 49472 NULL
  110687. +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
  110688. +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
  110689. +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
  110690. +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
  110691. +smk_write_access_49561 smk_write_access 3 49561 NULL
  110692. +alloc_chunk_49575 alloc_chunk 1 49575 NULL
  110693. +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
  110694. +readfifo_49583 readfifo 1 49583 NULL
  110695. +gfs2_quota_lock_49587 gfs2_quota_lock 0 49587 NULL
  110696. +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
  110697. +tap_write_49595 tap_write 3 49595 NULL
  110698. +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
  110699. +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
  110700. +heap_init_49617 heap_init 2 49617 NULL
  110701. +smk_write_doi_49621 smk_write_doi 3 49621 NULL
  110702. +port_fops_read_49626 port_fops_read 3 49626 NULL
  110703. +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
  110704. +xfs_ialloc_get_rec_49648 xfs_ialloc_get_rec 0 49648 NULL
  110705. +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
  110706. +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
  110707. +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
  110708. +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
  110709. +write_pool_49718 write_pool 3 49718 NULL
  110710. +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
  110711. +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
  110712. +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
  110713. +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
  110714. +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
  110715. +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
  110716. +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
  110717. +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
  110718. +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
  110719. +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
  110720. +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
  110721. +add_uuid_49831 add_uuid 4 49831 NULL
  110722. +iraw_loop_49842 iraw_loop 0-1 49842 NULL
  110723. +twl4030_write_49846 twl4030_write 2 49846 NULL
  110724. +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
  110725. +timeradd_entry_49850 timeradd_entry 3 49850 NULL
  110726. +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
  110727. +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
  110728. +osc_brw_49896 osc_brw 4 49896 NULL
  110729. +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
  110730. +xfs_ialloc_ag_alloc_49960 xfs_ialloc_ag_alloc 0 49960 NULL
  110731. +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
  110732. +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
  110733. +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
  110734. +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
  110735. +xfs_ialloc_inode_init_50015 xfs_ialloc_inode_init 0 50015 NULL
  110736. +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
  110737. +isdn_read_50021 isdn_read 3 50021 NULL
  110738. +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
  110739. +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
  110740. +ioread8_50049 ioread8 0 50049 NULL
  110741. +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
  110742. +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
  110743. +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
  110744. +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
  110745. +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
  110746. +android_set_cntry_50100 android_set_cntry 0 50100 NULL
  110747. +read_file_slot_50111 read_file_slot 3 50111 NULL
  110748. +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
  110749. +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
  110750. +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
  110751. +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
  110752. +xfs_bwrite_50154 xfs_bwrite 0 50154 NULL
  110753. +kmalloc_node_50163 kmalloc_node 1 50163 NULL
  110754. +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
  110755. +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
  110756. +odev_update_50169 odev_update 2 50169 NULL
  110757. +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
  110758. +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
  110759. +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
  110760. +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
  110761. +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
  110762. +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
  110763. +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
  110764. +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
  110765. +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
  110766. +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
  110767. +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
  110768. +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
  110769. +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
  110770. +soc_camera_read_50319 soc_camera_read 3 50319 NULL
  110771. +do_launder_page_50329 do_launder_page 0 50329 NULL
  110772. +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
  110773. +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
  110774. +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
  110775. +tpm_read_50344 tpm_read 3 50344 NULL
  110776. +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
  110777. +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
  110778. +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
  110779. +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
  110780. +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
  110781. +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
  110782. +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
  110783. +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
  110784. +xfs_alloc_update_counters_50441 xfs_alloc_update_counters 0 50441 NULL
  110785. +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
  110786. +pgctrl_write_50453 pgctrl_write 3 50453 NULL
  110787. +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
  110788. +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
  110789. +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
  110790. +xfs_iformat_extents_50486 xfs_iformat_extents 0 50486 NULL
  110791. +gfs2_block_map_50492 gfs2_block_map 0 50492 NULL
  110792. +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
  110793. +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
  110794. +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
  110795. +bh_get_50543 bh_get 0 50543 NULL
  110796. +gfs2_meta_inode_buffer_50544 gfs2_meta_inode_buffer 0 50544 NULL
  110797. +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
  110798. +fat_readpages_50582 fat_readpages 4 50582 NULL
  110799. +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
  110800. +xillybus_write_50605 xillybus_write 3 50605 NULL
  110801. +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
  110802. +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
  110803. +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
  110804. +gfs2_unstuff_dinode_50644 gfs2_unstuff_dinode 0 50644 NULL
  110805. +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
  110806. +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
  110807. +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
  110808. +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
  110809. +dev_mem_read_50706 dev_mem_read 3 50706 NULL
  110810. +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
  110811. +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
  110812. +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
  110813. +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
  110814. +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
  110815. +tpm_write_50798 tpm_write 3 50798 NULL
  110816. +tun_do_read_50800 tun_do_read 4 50800 NULL
  110817. +write_flush_50803 write_flush 3 50803 NULL
  110818. +dvb_play_50814 dvb_play 3 50814 NULL
  110819. +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
  110820. +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
  110821. +SetArea_50835 SetArea 4 50835 NULL
  110822. +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
  110823. +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
  110824. +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
  110825. +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
  110826. +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
  110827. +xfs_alloc_get_freelist_50906 xfs_alloc_get_freelist 0 50906 NULL
  110828. +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
  110829. +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
  110830. +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
  110831. +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
  110832. +show_device_status_50947 show_device_status 0 50947 NULL
  110833. +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
  110834. +virtio_cread16_50951 virtio_cread16 0 50951 NULL
  110835. +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
  110836. +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
  110837. +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
  110838. +timeout_write_50991 timeout_write 3 50991 NULL
  110839. +proc_write_51003 proc_write 3 51003 NULL
  110840. +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
  110841. +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
  110842. +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
  110843. +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
  110844. +dump_midi_51040 dump_midi 3 51040 NULL
  110845. +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
  110846. +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
  110847. +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
  110848. +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
  110849. +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
  110850. +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
  110851. +ti_recv_51110 ti_recv 3 51110 NULL
  110852. +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
  110853. +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
  110854. +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
  110855. +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
  110856. +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
  110857. +drm_property_create_51239 drm_property_create 4 51239 NULL
  110858. +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
  110859. +st_read_51251 st_read 3 51251 NULL
  110860. +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
  110861. +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
  110862. +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
  110863. +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
  110864. +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
  110865. +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
  110866. +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
  110867. +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
  110868. +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
  110869. +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
  110870. +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
  110871. +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
  110872. +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
  110873. +blk_register_region_51424 blk_register_region 1-2 51424 NULL
  110874. +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
  110875. +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
  110876. +xfs_mod_incore_sb_unlocked_51439 xfs_mod_incore_sb_unlocked 0 51439 NULL
  110877. +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
  110878. +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
  110879. +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
  110880. +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
  110881. +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
  110882. +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
  110883. +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
  110884. +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
  110885. +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
  110886. +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
  110887. +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
  110888. +extent_fiemap_51621 extent_fiemap 3 51621 NULL
  110889. +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
  110890. +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
  110891. +xfs_iformat_btree_51651 xfs_iformat_btree 0 51651 NULL
  110892. +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
  110893. +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
  110894. +host_mapping_level_51696 host_mapping_level 0 51696 NULL
  110895. +sel_write_access_51704 sel_write_access 3 51704 NULL
  110896. +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
  110897. +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
  110898. +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
  110899. +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
  110900. +cm4040_read_51732 cm4040_read 3 51732 NULL
  110901. +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
  110902. +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
  110903. +if_write_51756 if_write 3 51756 NULL
  110904. +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
  110905. +buffer_from_user_51826 buffer_from_user 3 51826 NULL
  110906. +ioread32_51847 ioread32 0 51847 NULL nohasharray
  110907. +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
  110908. +do_readv_writev_51849 do_readv_writev 4 51849 NULL
  110909. +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
  110910. +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
  110911. +pointer_size_read_51863 pointer_size_read 3 51863 NULL
  110912. +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
  110913. +user_read_51881 user_read 3 51881 NULL
  110914. +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
  110915. +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
  110916. +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
  110917. +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
  110918. +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
  110919. +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
  110920. +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
  110921. +snd_mask_min_51969 snd_mask_min 0 51969 NULL
  110922. +__blkdev_get_51972 __blkdev_get 0 51972 NULL
  110923. +get_zone_51981 get_zone 0-1 51981 NULL
  110924. +cifs_strict_writev_51984 cifs_strict_writev 4 51984 NULL
  110925. +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
  110926. +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
  110927. +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
  110928. +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
  110929. +rdmalt_52022 rdmalt 0 52022 NULL
  110930. +override_release_52032 override_release 2 52032 NULL
  110931. +end_port_52042 end_port 0 52042 NULL
  110932. +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
  110933. +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
  110934. +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
  110935. +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
  110936. +isofs_readpages_52067 isofs_readpages 4 52067 NULL
  110937. +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
  110938. +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
  110939. +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
  110940. +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
  110941. +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
  110942. +retry_count_read_52129 retry_count_read 3 52129 NULL
  110943. +xfs_btree_change_owner_52137 xfs_btree_change_owner 0 52137 NULL
  110944. +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
  110945. +sub_alloc_52140 sub_alloc 0 52140 NULL
  110946. +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
  110947. +htable_size_52148 htable_size 0-1 52148 NULL
  110948. +gfs2_rs_alloc_52152 gfs2_rs_alloc 0 52152 NULL
  110949. +smk_write_load2_52155 smk_write_load2 3 52155 NULL
  110950. +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
  110951. +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
  110952. +print_prefix_52176 print_prefix 0 52176 NULL
  110953. +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
  110954. +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
  110955. +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
  110956. +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
  110957. +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 0 52243 &fuse_request_alloc_52243
  110958. +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
  110959. +shrink_slab_52261 shrink_slab 2 52261 NULL
  110960. +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
  110961. +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
  110962. +read_file_reset_52310 read_file_reset 3 52310 NULL
  110963. +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
  110964. +hwflags_read_52318 hwflags_read 3 52318 NULL
  110965. +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
  110966. +hur_len_52339 hur_len 0 52339 NULL
  110967. +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
  110968. +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
  110969. +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
  110970. +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
  110971. +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
  110972. +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
  110973. +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
  110974. +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
  110975. +aer_inject_write_52399 aer_inject_write 3 52399 NULL
  110976. +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
  110977. +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
  110978. +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
  110979. +delay_status_52431 delay_status 5 52431 NULL
  110980. +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
  110981. +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
  110982. +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
  110983. +alauda_read_data_52452 alauda_read_data 3 52452 NULL
  110984. +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
  110985. +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
  110986. +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
  110987. +fd_do_rw_52495 fd_do_rw 3 52495 NULL
  110988. +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
  110989. +xfs_alloc_get_rec_52502 xfs_alloc_get_rec 0 52502 NULL
  110990. +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
  110991. +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
  110992. +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
  110993. +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
  110994. +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
  110995. +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
  110996. +ntfs_prepare_pages_for_non_resident_write_52556 ntfs_prepare_pages_for_non_resident_write 0 52556 NULL
  110997. +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
  110998. +kernfs_setattr_52583 kernfs_setattr 0 52583 NULL
  110999. +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
  111000. +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
  111001. +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
  111002. +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
  111003. +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
  111004. +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
  111005. +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
  111006. +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
  111007. +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
  111008. +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
  111009. +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
  111010. +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
  111011. +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
  111012. +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
  111013. +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
  111014. +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
  111015. +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
  111016. +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
  111017. +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
  111018. +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
  111019. +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
  111020. +twlreg_write_52880 twlreg_write 3 52880 NULL
  111021. +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
  111022. +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
  111023. +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
  111024. +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
  111025. +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
  111026. +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
  111027. +__nodes_remap_52951 __nodes_remap 5 52951 NULL
  111028. +send_packet_52960 send_packet 4 52960 NULL
  111029. +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
  111030. +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
  111031. +num_node_state_52989 num_node_state 0 52989 NULL
  111032. +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
  111033. +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
  111034. +xfs_rtfree_extent_53024 xfs_rtfree_extent 0 53024 NULL
  111035. +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
  111036. +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
  111037. +cfi_read_query_53066 cfi_read_query 0 53066 NULL
  111038. +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
  111039. +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
  111040. +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
  111041. +verity_status_53120 verity_status 5 53120 NULL
  111042. +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
  111043. +inode_newsize_ok_53140 inode_newsize_ok 0 53140 NULL nohasharray
  111044. +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 &inode_newsize_ok_53140
  111045. +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
  111046. +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
  111047. +find_good_lh_53183 find_good_lh 0 53183 NULL
  111048. +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
  111049. +xfs_btree_updkey_53195 xfs_btree_updkey 0 53195 NULL
  111050. +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
  111051. +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
  111052. +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5-0 53258 NULL
  111053. +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
  111054. +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
  111055. +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
  111056. +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
  111057. +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
  111058. +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
  111059. +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
  111060. +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
  111061. +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
  111062. +xfs_imap_53389 xfs_imap 0 53389 NULL
  111063. +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
  111064. +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
  111065. +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
  111066. +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
  111067. +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
  111068. +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
  111069. +iowarrior_read_53483 iowarrior_read 3 53483 NULL
  111070. +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
  111071. +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
  111072. +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
  111073. +dbAllocNext_53506 dbAllocNext 0 53506 NULL
  111074. +check_acl_53512 check_acl 0 53512 NULL
  111075. +ll_xattr_cache_update_53515 ll_xattr_cache_update 4 53515 NULL
  111076. +nft_data_dump_53549 nft_data_dump 5 53549 NULL
  111077. +SYSC_bind_53582 SYSC_bind 3 53582 NULL
  111078. +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
  111079. +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
  111080. +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
  111081. +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
  111082. +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
  111083. +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
  111084. +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
  111085. +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
  111086. +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
  111087. +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
  111088. +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
  111089. +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
  111090. +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
  111091. +wdm_write_53735 wdm_write 3 53735 NULL
  111092. +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
  111093. +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
  111094. +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
  111095. +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
  111096. +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
  111097. +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
  111098. +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
  111099. +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
  111100. +nls_nullsize_53815 nls_nullsize 0 53815 NULL
  111101. +setup_data_read_53822 setup_data_read 3 53822 NULL
  111102. +pms_read_53873 pms_read 3 53873 NULL
  111103. +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
  111104. +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
  111105. +posix_acl_chmod_53904 posix_acl_chmod 0 53904 NULL
  111106. +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
  111107. +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
  111108. +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
  111109. +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
  111110. +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
  111111. +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
  111112. +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
  111113. +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
  111114. +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
  111115. +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
  111116. +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
  111117. +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
  111118. +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
  111119. +rproc_state_read_54057 rproc_state_read 3 54057 NULL
  111120. +_malloc_54077 _malloc 1 54077 NULL
  111121. +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
  111122. +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
  111123. +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2-0 54103 &altera_set_ir_pre_54103
  111124. +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
  111125. +strn_len_54122 strn_len 0 54122 NULL
  111126. +isku_receive_54130 isku_receive 4 54130 NULL
  111127. +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
  111128. +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
  111129. +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
  111130. +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
  111131. +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
  111132. +do_sys_poll_54221 do_sys_poll 2 54221 NULL
  111133. +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
  111134. +pi_read_regr_54231 pi_read_regr 0 54231 NULL
  111135. +reada_add_block_54247 reada_add_block 2 54247 NULL
  111136. +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
  111137. +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
  111138. +audio_write_54261 audio_write 4 54261 NULL nohasharray
  111139. +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
  111140. +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
  111141. +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
  111142. +tipc_multicast_54285 tipc_multicast 4 54285 NULL
  111143. +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
  111144. +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
  111145. +reclaim_pages_54301 reclaim_pages 3 54301 NULL
  111146. +sprintf_54306 sprintf 0 54306 NULL
  111147. +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
  111148. +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
  111149. +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
  111150. +__get_free_pages_54352 __get_free_pages 0 54352 NULL
  111151. +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
  111152. +vfs_readlink_54368 vfs_readlink 3 54368 NULL
  111153. +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
  111154. +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
  111155. +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
  111156. +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
  111157. +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
  111158. +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
  111159. +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
  111160. +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
  111161. +simple_strtoull_54493 simple_strtoull 0 54493 NULL
  111162. +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
  111163. +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
  111164. +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
  111165. +viacam_read_54526 viacam_read 3 54526 NULL
  111166. +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
  111167. +setsockopt_54539 setsockopt 5 54539 NULL
  111168. +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
  111169. +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
  111170. +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
  111171. +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
  111172. +nvme_npages_54601 nvme_npages 0-1 54601 NULL
  111173. +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
  111174. +port_fops_write_54627 port_fops_write 3 54627 NULL
  111175. +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
  111176. +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
  111177. +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
  111178. +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
  111179. +bus_add_device_54665 bus_add_device 0 54665 NULL
  111180. +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
  111181. +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
  111182. +evm_read_key_54674 evm_read_key 3 54674 NULL
  111183. +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
  111184. +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
  111185. +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
  111186. +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
  111187. +kzalloc_54740 kzalloc 1 54740 NULL
  111188. +wep_iv_read_54744 wep_iv_read 3 54744 NULL
  111189. +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
  111190. +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
  111191. +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
  111192. +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
  111193. +xfs_rtallocate_extent_block_54791 xfs_rtallocate_extent_block 0 54791 NULL
  111194. +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
  111195. +nfsd_write_54809 nfsd_write 6 54809 NULL
  111196. +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
  111197. +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
  111198. +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
  111199. +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
  111200. +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
  111201. +write_rio_54837 write_rio 3 54837 NULL
  111202. +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
  111203. +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
  111204. +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
  111205. +printer_read_54851 printer_read 3 54851 NULL
  111206. +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
  111207. +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
  111208. +xfs_alloc_read_agfl_54879 xfs_alloc_read_agfl 0 54879 NULL
  111209. +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
  111210. +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
  111211. +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
  111212. +bio_add_page_54933 bio_add_page 0-3 54933 NULL
  111213. +mxms_structlen_54939 mxms_structlen 0 54939 NULL
  111214. +add_port_54941 add_port 2 54941 NULL
  111215. +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
  111216. +alauda_write_data_54967 alauda_write_data 3 54967 NULL
  111217. +c4_add_card_54968 c4_add_card 3 54968 NULL
  111218. +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
  111219. +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
  111220. +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
  111221. +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
  111222. +apei_exec_run_55075 apei_exec_run 0 55075 NULL
  111223. +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
  111224. +read_dma_55086 read_dma 3 55086 NULL
  111225. +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
  111226. +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
  111227. +filldir_55137 filldir 3 55137 NULL
  111228. +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
  111229. +xfs_check_agi_freecount_55149 xfs_check_agi_freecount 0 55149 NULL nohasharray
  111230. +npages_to_npools_55149 npages_to_npools 0-1 55149 &xfs_check_agi_freecount_55149
  111231. +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
  111232. +xfs_icsb_modify_counters_55156 xfs_icsb_modify_counters 0 55156 NULL
  111233. +gfs2_ri_update_55185 gfs2_ri_update 0 55185 NULL
  111234. +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
  111235. +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
  111236. +sched_feat_write_55202 sched_feat_write 3 55202 NULL
  111237. +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
  111238. +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
  111239. +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
  111240. +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
  111241. +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
  111242. +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
  111243. +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
  111244. +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
  111245. +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
  111246. +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
  111247. +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
  111248. +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
  111249. +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
  111250. +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
  111251. +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
  111252. +vme_user_read_55338 vme_user_read 3 55338 NULL
  111253. +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
  111254. +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
  111255. +tipc_send2name_55373 tipc_send2name 5 55373 NULL
  111256. +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
  111257. +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
  111258. +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
  111259. +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
  111260. +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
  111261. +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
  111262. +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
  111263. +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
  111264. +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
  111265. +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
  111266. +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
  111267. +xfs_btree_split_55515 xfs_btree_split 0 55515 NULL
  111268. +ea_get_55522 ea_get 3-0 55522 NULL
  111269. +buffer_size_55534 buffer_size 0 55534 NULL
  111270. +set_msr_interception_55538 set_msr_interception 2 55538 NULL
  111271. +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
  111272. +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
  111273. +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
  111274. +dm_stats_list_55551 dm_stats_list 4 55551 NULL
  111275. +add_partition_55588 add_partition 2 55588 NULL
  111276. +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
  111277. +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
  111278. +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
  111279. +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
  111280. +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
  111281. +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
  111282. +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
  111283. +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
  111284. +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
  111285. +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
  111286. +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
  111287. +get_info_55681 get_info 3 55681 NULL
  111288. +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
  111289. +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
  111290. +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
  111291. +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
  111292. +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
  111293. +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
  111294. +set_local_name_55757 set_local_name 4 55757 NULL
  111295. +strlen_55778 strlen 0 55778 NULL
  111296. +set_spte_55783 set_spte 4-5 55783 NULL
  111297. +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
  111298. +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
  111299. +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
  111300. +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
  111301. +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
  111302. +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
  111303. +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
  111304. +hsc_write_55875 hsc_write 3 55875 NULL
  111305. +ramdisk_store_55885 ramdisk_store 4 55885 NULL
  111306. +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
  111307. +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
  111308. +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
  111309. +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
  111310. +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
  111311. +sel_read_policy_55947 sel_read_policy 3 55947 NULL
  111312. +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
  111313. +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
  111314. +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
  111315. +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
  111316. +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
  111317. +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
  111318. +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
  111319. +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
  111320. +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
  111321. +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
  111322. +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
  111323. +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
  111324. +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
  111325. +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
  111326. +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
  111327. +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
  111328. +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
  111329. +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
  111330. +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
  111331. +fd_copyin_56247 fd_copyin 3 56247 NULL
  111332. +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
  111333. +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
  111334. +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
  111335. +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
  111336. +dvb_aplay_56296 dvb_aplay 3 56296 NULL
  111337. +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
  111338. +speakup_file_write_56310 speakup_file_write 3 56310 NULL
  111339. +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
  111340. +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
  111341. +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
  111342. +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
  111343. +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
  111344. +qd_get_56365 qd_get 0 56365 NULL
  111345. +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
  111346. +dev_read_56369 dev_read 3 56369 NULL
  111347. +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
  111348. +write_gssp_56404 write_gssp 3 56404 NULL
  111349. +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
  111350. +do_get_write_access_56410 do_get_write_access 0 56410 NULL
  111351. +store_msg_56417 store_msg 3 56417 NULL
  111352. +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
  111353. +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
  111354. +fl_create_56435 fl_create 5 56435 NULL
  111355. +gnttab_map_56439 gnttab_map 2 56439 NULL
  111356. +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
  111357. +set_connectable_56458 set_connectable 4 56458 NULL
  111358. +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
  111359. +putused_user_56467 putused_user 3 56467 NULL
  111360. +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
  111361. +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
  111362. +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
  111363. +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
  111364. +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
  111365. +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
  111366. +init_map_ip_56508 init_map_ip 5 56508 NULL
  111367. +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3-0-2 56512 NULL
  111368. +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
  111369. +ip_options_get_56538 ip_options_get 4 56538 NULL
  111370. +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
  111371. +alloc_apertures_56561 alloc_apertures 1 56561 NULL
  111372. +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
  111373. +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
  111374. +event_filter_write_56609 event_filter_write 3 56609 NULL
  111375. +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
  111376. +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
  111377. +gather_array_56641 gather_array 3 56641 NULL
  111378. +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
  111379. +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
  111380. +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
  111381. +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
  111382. +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
  111383. +sta_flags_read_56710 sta_flags_read 3 56710 NULL
  111384. +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
  111385. +xfs_btree_decrement_56718 xfs_btree_decrement 0 56718 NULL
  111386. +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
  111387. +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
  111388. +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
  111389. +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
  111390. +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
  111391. +ion_ioctl_56806 ion_ioctl 2 56806 NULL
  111392. +do_syslog_56807 do_syslog 3 56807 NULL
  111393. +mtdchar_write_56831 mtdchar_write 3 56831 NULL
  111394. +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
  111395. +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
  111396. +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
  111397. +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
  111398. +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
  111399. +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
  111400. +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
  111401. +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
  111402. +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
  111403. +xfs_alloc_ag_vextent_56943 xfs_alloc_ag_vextent 0 56943 NULL
  111404. +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
  111405. +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
  111406. +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
  111407. +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
  111408. +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
  111409. +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
  111410. +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
  111411. +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
  111412. +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
  111413. +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
  111414. +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
  111415. +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
  111416. +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
  111417. +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
  111418. +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
  111419. +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
  111420. +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
  111421. +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
  111422. +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
  111423. +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
  111424. +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
  111425. +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
  111426. +udl_prime_create_57159 udl_prime_create 2 57159 NULL
  111427. +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
  111428. +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
  111429. +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
  111430. +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
  111431. +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
  111432. +flush_space_57241 flush_space 0 57241 NULL
  111433. +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
  111434. +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
  111435. +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
  111436. +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
  111437. +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
  111438. +pstore_file_read_57288 pstore_file_read 3 57288 NULL
  111439. +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
  111440. +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
  111441. +xfs_iread_57313 xfs_iread 0 57313 NULL nohasharray
  111442. +write_file_regval_57313 write_file_regval 3 57313 &xfs_iread_57313
  111443. +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
  111444. +usblp_read_57342 usblp_read 3 57342 NULL
  111445. +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
  111446. +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
  111447. +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
  111448. +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
  111449. +read_file_blob_57406 read_file_blob 3 57406 NULL
  111450. +enclosure_register_57412 enclosure_register 3 57412 NULL
  111451. +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
  111452. +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
  111453. +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
  111454. +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
  111455. +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
  111456. +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
  111457. +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
  111458. +skb_headlen_57501 skb_headlen 0 57501 NULL
  111459. +copy_in_user_57502 copy_in_user 3 57502 NULL
  111460. +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL nohasharray
  111461. +gfs2_quota_hold_57505 gfs2_quota_hold 0 57505 &ckhdid_printf_57505
  111462. +init_tag_map_57515 init_tag_map 3 57515 NULL
  111463. +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
  111464. +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
  111465. +cmm_read_57520 cmm_read 3 57520 NULL
  111466. +inode_permission_57531 inode_permission 0 57531 NULL
  111467. +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
  111468. +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
  111469. +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
  111470. +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
  111471. +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
  111472. +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
  111473. +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
  111474. +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
  111475. +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
  111476. +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
  111477. +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
  111478. +mem_read_57631 mem_read 3 57631 NULL
  111479. +xfs_alloc_ag_vextent_near_57653 xfs_alloc_ag_vextent_near 0 57653 NULL
  111480. +r3964_write_57662 r3964_write 4 57662 NULL
  111481. +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
  111482. +__lgwrite_57669 __lgwrite 4 57669 NULL
  111483. +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
  111484. +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
  111485. +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
  111486. +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
  111487. +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
  111488. +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
  111489. +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
  111490. +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
  111491. +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
  111492. +ld2_57794 ld2 0 57794 NULL
  111493. +ivtv_read_57796 ivtv_read 3 57796 NULL
  111494. +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
  111495. +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
  111496. +copy_to_user_57835 copy_to_user 3-0 57835 NULL
  111497. +xfs_rtpick_extent_57843 xfs_rtpick_extent 0 57843 NULL nohasharray
  111498. +flash_read_57843 flash_read 3 57843 &xfs_rtpick_extent_57843
  111499. +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
  111500. +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
  111501. +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
  111502. +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
  111503. +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
  111504. +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
  111505. +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
  111506. +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
  111507. +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
  111508. +xfs_inode_item_format_convert_57937 xfs_inode_item_format_convert 0 57937 NULL
  111509. +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
  111510. +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
  111511. +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
  111512. +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
  111513. +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
  111514. +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
  111515. +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
  111516. +mce_async_out_58056 mce_async_out 3 58056 NULL
  111517. +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
  111518. +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
  111519. +cm4040_write_58079 cm4040_write 3 58079 NULL
  111520. +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
  111521. +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
  111522. +rd_build_prot_space_58137 rd_build_prot_space 2 58137 NULL
  111523. +xfs_bmap_add_extent_delay_real_58151 xfs_bmap_add_extent_delay_real 0 58151 NULL
  111524. +xfs_btree_update_58167 xfs_btree_update 0 58167 NULL
  111525. +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
  111526. +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
  111527. +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
  111528. +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
  111529. +read_file_debug_58256 read_file_debug 3 58256 NULL
  111530. +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
  111531. +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
  111532. +profile_load_58267 profile_load 3 58267 NULL
  111533. +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
  111534. +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
  111535. +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
  111536. +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
  111537. +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
  111538. +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
  111539. +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
  111540. +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
  111541. +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
  111542. +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
  111543. +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
  111544. +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
  111545. +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
  111546. +xfs_btree_get_rec_58410 xfs_btree_get_rec 0 58410 NULL
  111547. +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
  111548. +capabilities_read_58457 capabilities_read 3 58457 NULL
  111549. +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
  111550. +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
  111551. +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
  111552. +nv_rd08_58472 nv_rd08 0 58472 NULL
  111553. +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
  111554. +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
  111555. +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
  111556. +btrfs_cont_expand_58498 btrfs_cont_expand 0-2-3 58498 NULL
  111557. +gfs2_dir_get_new_buffer_58509 gfs2_dir_get_new_buffer 0 58509 NULL
  111558. +rndis_add_response_58544 rndis_add_response 2 58544 NULL
  111559. +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
  111560. +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
  111561. +ea_read_inline_58589 ea_read_inline 0 58589 NULL
  111562. +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
  111563. +xip_file_read_58592 xip_file_read 3 58592 NULL
  111564. +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
  111565. +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
  111566. +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
  111567. +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
  111568. +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
  111569. +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
  111570. +find_zero_58685 find_zero 0-1 58685 NULL
  111571. +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
  111572. +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
  111573. +vx_send_msg_58711 vx_send_msg 0 58711 NULL
  111574. +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
  111575. +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
  111576. +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
  111577. +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
  111578. +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
  111579. +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
  111580. +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
  111581. +ep_read_58813 ep_read 3 58813 NULL
  111582. +command_write_58841 command_write 3 58841 NULL
  111583. +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
  111584. +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
  111585. +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
  111586. +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
  111587. +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
  111588. +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
  111589. +xfs_bmap_read_extents_58936 xfs_bmap_read_extents 0 58936 NULL
  111590. +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
  111591. +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
  111592. +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
  111593. +__mem_cgroup_try_charge_58976 __mem_cgroup_try_charge 0 58976 NULL
  111594. +init_list_set_59005 init_list_set 3 59005 NULL
  111595. +ep_write_59008 ep_write 3 59008 NULL
  111596. +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
  111597. +SyS_preadv_59029 SyS_preadv 3 59029 NULL
  111598. +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
  111599. +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
  111600. +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
  111601. +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
  111602. +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
  111603. +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL nohasharray
  111604. +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 &scsi_io_completion_59122
  111605. +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
  111606. +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
  111607. +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
  111608. +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
  111609. +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
  111610. +ksize_59176 ksize 0 59176 NULL
  111611. +setup_window_59178 setup_window 4-2-5-7 59178 NULL
  111612. +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
  111613. +xfs_ialloc_next_rec_59193 xfs_ialloc_next_rec 0 59193 NULL
  111614. +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
  111615. +dt3155_read_59226 dt3155_read 3 59226 NULL
  111616. +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
  111617. +nla_len_59258 nla_len 0 59258 NULL
  111618. +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
  111619. +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
  111620. +xfs_iformat_fork_59312 xfs_iformat_fork 0 59312 NULL
  111621. +fd_copyout_59323 fd_copyout 3 59323 NULL
  111622. +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
  111623. +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
  111624. +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL nohasharray
  111625. +xfs_alloc_lookup_le_59346 xfs_alloc_lookup_le 0 59346 &xfs_attrmulti_attr_set_59346
  111626. +__map_request_59350 __map_request 0 59350 NULL
  111627. +gfs2_quota_lock_check_59353 gfs2_quota_lock_check 0 59353 NULL
  111628. +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
  111629. +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
  111630. +journal_init_dev_59384 journal_init_dev 5 59384 NULL
  111631. +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
  111632. +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
  111633. +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
  111634. +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
  111635. +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
  111636. +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
  111637. +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
  111638. +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
  111639. +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
  111640. +tunables_write_59563 tunables_write 3 59563 NULL
  111641. +bio_split_59564 bio_split 2 59564 NULL
  111642. +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
  111643. +write_pbl_59583 write_pbl 4 59583 NULL
  111644. +memdup_user_59590 memdup_user 2 59590 NULL
  111645. +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
  111646. +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
  111647. +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
  111648. +mtrr_write_59622 mtrr_write 3 59622 NULL
  111649. +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
  111650. +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
  111651. +file_update_time_59647 file_update_time 0 59647 NULL
  111652. +hidraw_read_59650 hidraw_read 3 59650 NULL
  111653. +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
  111654. +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
  111655. +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
  111656. +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
  111657. +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
  111658. +ioperm_get_59701 ioperm_get 4-3 59701 NULL
  111659. +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
  111660. +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
  111661. +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
  111662. +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
  111663. +strnlen_59746 strnlen 0 59746 NULL
  111664. +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
  111665. +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
  111666. +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
  111667. +venus_remove_59781 venus_remove 4 59781 NULL
  111668. +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
  111669. +ipw_write_59807 ipw_write 3 59807 NULL
  111670. +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
  111671. +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
  111672. +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
  111673. +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
  111674. +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
  111675. +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
  111676. +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
  111677. +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
  111678. +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
  111679. +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
  111680. +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
  111681. +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
  111682. +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
  111683. +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
  111684. +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
  111685. +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
  111686. +copy_items_60009 copy_items 7 60009 NULL
  111687. +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
  111688. +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
  111689. +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
  111690. +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
  111691. +xfs_imap_to_bp_60034 xfs_imap_to_bp 0 60034 NULL
  111692. +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
  111693. +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
  111694. +vcs_size_60050 vcs_size 0 60050 NULL
  111695. +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
  111696. +compat_writev_60063 compat_writev 3 60063 NULL
  111697. +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
  111698. +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
  111699. +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
  111700. +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
  111701. +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
  111702. +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
  111703. +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
  111704. +ld_usb_read_60156 ld_usb_read 3 60156 NULL
  111705. +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
  111706. +init_state_60165 init_state 2 60165 NULL
  111707. +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
  111708. +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
  111709. +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
  111710. +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
  111711. +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
  111712. +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
  111713. +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
  111714. +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
  111715. +printer_write_60276 printer_write 3 60276 NULL
  111716. +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
  111717. +getDataLength_60301 getDataLength 0 60301 NULL
  111718. +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
  111719. +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
  111720. +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
  111721. +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
  111722. +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
  111723. +driver_names_read_60399 driver_names_read 3 60399 NULL
  111724. +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
  111725. +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
  111726. +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
  111727. +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
  111728. +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
  111729. +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
  111730. +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
  111731. +xfs_btree_make_block_unfull_60511 xfs_btree_make_block_unfull 0 60511 NULL
  111732. +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
  111733. +nonpaging_map_60551 nonpaging_map 4 60551 NULL
  111734. +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
  111735. +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
  111736. +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
  111737. +inode_change_ok_60614 inode_change_ok 0 60614 NULL
  111738. +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
  111739. +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
  111740. +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
  111741. +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
  111742. +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
  111743. +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
  111744. +vga_rcrt_60731 vga_rcrt 0 60731 NULL
  111745. +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
  111746. +raid_status_60755 raid_status 5 60755 NULL
  111747. +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
  111748. +opticon_write_60775 opticon_write 4 60775 NULL
  111749. +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
  111750. +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
  111751. +gfs2_bmap_alloc_60822 gfs2_bmap_alloc 0 60822 NULL
  111752. +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
  111753. +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 4-3 60861 NULL
  111754. +alloc_buf_60864 alloc_buf 3-2 60864 NULL
  111755. +generic_writepages_60871 generic_writepages 0 60871 NULL
  111756. +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
  111757. +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
  111758. +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
  111759. +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
  111760. +scrub_chunk_60926 scrub_chunk 5 60926 NULL
  111761. +submit_extent_page_60928 submit_extent_page 5 60928 NULL
  111762. +xfs_rtallocate_extent_size_60939 xfs_rtallocate_extent_size 0 60939 NULL
  111763. +pti_char_write_60960 pti_char_write 3 60960 NULL
  111764. +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
  111765. +__a2mp_build_60987 __a2mp_build 3 60987 NULL
  111766. +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
  111767. +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
  111768. +graph_depth_write_61024 graph_depth_write 3 61024 NULL
  111769. +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
  111770. +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
  111771. +symtab_init_61050 symtab_init 2 61050 NULL
  111772. +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
  111773. +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
  111774. +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
  111775. +xfs_dabuf_map_61093 xfs_dabuf_map 0 61093 NULL
  111776. +get_derived_key_61100 get_derived_key 4 61100 NULL
  111777. +mem_cgroup_cache_charge_61101 mem_cgroup_cache_charge 0 61101 NULL
  111778. +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
  111779. +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
  111780. +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
  111781. +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
  111782. +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
  111783. +pair_device_61175 pair_device 4 61175 NULL nohasharray
  111784. +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
  111785. +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
  111786. +SyS_prctl_61202 SyS_prctl 4 61202 NULL
  111787. +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
  111788. +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
  111789. +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
  111790. +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
  111791. +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270
  111792. +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
  111793. +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
  111794. +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
  111795. +xfer_from_user_61307 xfer_from_user 3 61307 NULL
  111796. +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
  111797. +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
  111798. +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
  111799. +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
  111800. +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
  111801. +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
  111802. +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
  111803. +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
  111804. +system_enable_write_61396 system_enable_write 3 61396 NULL
  111805. +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
  111806. +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
  111807. +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
  111808. +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
  111809. +erst_errno_61526 erst_errno 0 61526 NULL
  111810. +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
  111811. +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
  111812. +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
  111813. +fan_proc_write_61569 fan_proc_write 3 61569 NULL
  111814. +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
  111815. +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
  111816. +seq_open_private_61589 seq_open_private 3 61589 NULL
  111817. +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
  111818. +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
  111819. +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
  111820. +configfs_write_file_61621 configfs_write_file 3 61621 NULL
  111821. +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
  111822. +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
  111823. +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
  111824. +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
  111825. +resize_stripes_61650 resize_stripes 2 61650 NULL
  111826. +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
  111827. +insert_one_name_61668 insert_one_name 7 61668 NULL
  111828. +lock_loop_61681 lock_loop 1 61681 NULL
  111829. +filter_read_61692 filter_read 3 61692 NULL
  111830. +iov_length_61716 iov_length 0 61716 NULL
  111831. +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
  111832. +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
  111833. +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
  111834. +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
  111835. +SyS_sendto_61763 SyS_sendto 6 61763 NULL
  111836. +gfs2_meta_wait_61773 gfs2_meta_wait 0 61773 NULL
  111837. +xfs_file_dio_aio_write_61801 xfs_file_dio_aio_write 0 61801 NULL
  111838. +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
  111839. +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
  111840. +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
  111841. +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
  111842. +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
  111843. +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
  111844. +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
  111845. +get_fw_name_61874 get_fw_name 3 61874 NULL
  111846. +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
  111847. +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
  111848. +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
  111849. +clear_refs_write_61904 clear_refs_write 3 61904 NULL
  111850. +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
  111851. +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
  111852. +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
  111853. +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
  111854. +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
  111855. +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
  111856. +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
  111857. +fix_read_error_61965 fix_read_error 4 61965 NULL
  111858. +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
  111859. +cow_file_range_61979 cow_file_range 3 61979 NULL
  111860. +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
  111861. +dequeue_event_62000 dequeue_event 3 62000 NULL
  111862. +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
  111863. +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
  111864. +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
  111865. +SYSC_select_62024 SYSC_select 1 62024 NULL
  111866. +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
  111867. +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
  111868. +do_pselect_62061 do_pselect 1 62061 NULL
  111869. +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
  111870. +_xfs_log_force_lsn_62083 _xfs_log_force_lsn 0 62083 NULL
  111871. +fat_setattr_62084 fat_setattr 0 62084 NULL
  111872. +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
  111873. +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
  111874. +ip_recv_error_62117 ip_recv_error 3 62117 NULL
  111875. +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
  111876. +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
  111877. +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
  111878. +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
  111879. +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
  111880. +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
  111881. +video_usercopy_62151 video_usercopy 2 62151 NULL
  111882. +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
  111883. +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
  111884. +write_file_dfs_62180 write_file_dfs 3 62180 NULL
  111885. +alloc_upcall_62186 alloc_upcall 2 62186 NULL
  111886. +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
  111887. +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
  111888. +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
  111889. +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
  111890. +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
  111891. +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
  111892. +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
  111893. +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
  111894. +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
  111895. +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
  111896. +subseq_list_62332 subseq_list 3-0 62332 NULL
  111897. +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
  111898. +flash_write_62354 flash_write 3 62354 NULL
  111899. +xfpregs_set_62363 xfpregs_set 4 62363 NULL
  111900. +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
  111901. +altera_irscan_62396 altera_irscan 2 62396 NULL
  111902. +set_ssp_62411 set_ssp 4 62411 NULL
  111903. +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
  111904. +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
  111905. +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
  111906. +test_iso_queue_62534 test_iso_queue 5 62534 NULL
  111907. +debugfs_read_62535 debugfs_read 3 62535 NULL
  111908. +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
  111909. +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
  111910. +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
  111911. +compute_bitstructs_62570 compute_bitstructs 0 62570 NULL
  111912. +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
  111913. +get_subdir_62581 get_subdir 3 62581 NULL
  111914. +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
  111915. +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
  111916. +dut_mode_write_62630 dut_mode_write 3 62630 NULL
  111917. +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
  111918. +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
  111919. +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
  111920. +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
  111921. +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
  111922. +rdm_62719 rdm 0 62719 NULL
  111923. +add_to_page_cache_62724 add_to_page_cache 0 62724 NULL
  111924. +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
  111925. +key_replays_read_62746 key_replays_read 3 62746 NULL
  111926. +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
  111927. +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
  111928. +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
  111929. +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
  111930. +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
  111931. +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
  111932. +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
  111933. +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
  111934. +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
  111935. +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
  111936. +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
  111937. +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
  111938. +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
  111939. +xfs_rtmodify_range_62877 xfs_rtmodify_range 0 62877 NULL
  111940. +aoechr_write_62883 aoechr_write 3 62883 NULL
  111941. +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
  111942. +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
  111943. +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
  111944. +getdqbuf_62908 getdqbuf 1 62908 NULL
  111945. +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
  111946. +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
  111947. +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL nohasharray
  111948. +xfs_trans_reserve_63026 xfs_trans_reserve 0 63026 &kstrtoull_from_user_63026
  111949. +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
  111950. +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
  111951. +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
  111952. +unlink1_63059 unlink1 3 63059 NULL
  111953. +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
  111954. +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
  111955. +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
  111956. +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
  111957. +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
  111958. +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
  111959. +SyS_syslog_63178 SyS_syslog 3 63178 NULL
  111960. +vme_master_read_63221 vme_master_read 0 63221 NULL
  111961. +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
  111962. +ptp_read_63251 ptp_read 4 63251 NULL
  111963. +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
  111964. +raid5_resize_63306 raid5_resize 2 63306 NULL
  111965. +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
  111966. +proc_info_read_63344 proc_info_read 3 63344 NULL
  111967. +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
  111968. +idmouse_read_63374 idmouse_read 3 63374 NULL
  111969. +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
  111970. +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
  111971. +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
  111972. +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
  111973. +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
  111974. +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
  111975. +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
  111976. +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
  111977. +reada_find_extent_63486 reada_find_extent 2 63486 NULL
  111978. +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
  111979. +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
  111980. +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
  111981. +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
  111982. +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
  111983. +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
  111984. +append_to_buffer_63550 append_to_buffer 3 63550 NULL
  111985. +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
  111986. +rproc_alloc_63577 rproc_alloc 5 63577 NULL
  111987. +write_debug_level_63613 write_debug_level 3 63613 NULL
  111988. +__spi_validate_63618 __spi_validate 0 63618 NULL
  111989. +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
  111990. +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
  111991. +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
  111992. +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
  111993. +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
  111994. +vbi_read_63673 vbi_read 3 63673 NULL
  111995. +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
  111996. +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
  111997. +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
  111998. +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
  111999. +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
  112000. +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
  112001. +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
  112002. +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
  112003. +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
  112004. +sel_write_load_63830 sel_write_load 3 63830 NULL
  112005. +ll_readlink_63836 ll_readlink 3 63836 NULL
  112006. +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
  112007. +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
  112008. +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
  112009. +snd_compr_write_63923 snd_compr_write 3 63923 NULL
  112010. +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
  112011. +__team_options_register_63941 __team_options_register 3 63941 NULL
  112012. +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
  112013. +xfs_iflush_63956 xfs_iflush 0 63956 NULL
  112014. +set_bredr_63975 set_bredr 4 63975 NULL
  112015. +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
  112016. +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
  112017. +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
  112018. +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
  112019. +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
  112020. +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
  112021. +__generic_file_aio_write_64049 __generic_file_aio_write 0 64049 NULL
  112022. +get_u8_64076 get_u8 0 64076 NULL
  112023. +xilly_malloc_64077 xilly_malloc 2 64077 NULL
  112024. +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
  112025. +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
  112026. +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
  112027. +gfs2_inplace_reserve_64096 gfs2_inplace_reserve 0 64096 NULL nohasharray
  112028. +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 &gfs2_inplace_reserve_64096
  112029. +to_bytes_64103 to_bytes 0-1 64103 NULL
  112030. +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
  112031. +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
  112032. +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
  112033. +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
  112034. +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
  112035. +init_bch_64130 init_bch 1-2 64130 NULL
  112036. +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
  112037. +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
  112038. +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
  112039. +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
  112040. +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
  112041. +read_pulse_64227 read_pulse 0-3 64227 NULL
  112042. +ea_len_64229 ea_len 0 64229 NULL
  112043. +xfs_rtmodify_summary_64265 xfs_rtmodify_summary 0 64265 NULL
  112044. +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
  112045. +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
  112046. +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
  112047. +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3-0 64288 NULL nohasharray
  112048. +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
  112049. +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
  112050. +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
  112051. +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
  112052. +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
  112053. +ts_write_64336 ts_write 3 64336 NULL
  112054. +usbtmc_write_64340 usbtmc_write 3 64340 NULL
  112055. +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
  112056. +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
  112057. +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
  112058. +reg_create_64372 reg_create 5 64372 NULL
  112059. +ilo_write_64378 ilo_write 3 64378 NULL
  112060. +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
  112061. +vmcs_readl_64381 vmcs_readl 0 64381 NULL
  112062. +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
  112063. +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
  112064. +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
  112065. +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
  112066. +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
  112067. +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
  112068. +oom_adj_write_64428 oom_adj_write 3 64428 NULL
  112069. +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
  112070. +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
  112071. +single_open_size_64483 single_open_size 4 64483 NULL
  112072. +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL nohasharray
  112073. +xfs_inode_ag_walk_64493 xfs_inode_ag_walk 0 64493 &p54_parse_rssical_64493
  112074. +msg_data_sz_64503 msg_data_sz 0 64503 NULL
  112075. +remove_uuid_64505 remove_uuid 4 64505 NULL
  112076. +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
  112077. +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
  112078. +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
  112079. +ses_send_diag_64527 ses_send_diag 4 64527 NULL
  112080. +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
  112081. +SyS_bind_64544 SyS_bind 3 64544 NULL
  112082. +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
  112083. +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
  112084. +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
  112085. +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
  112086. +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
  112087. +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
  112088. +do_erase_64574 do_erase 4 64574 NULL
  112089. +fanotify_write_64623 fanotify_write 3 64623 NULL
  112090. +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
  112091. +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
  112092. +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
  112093. +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
  112094. +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
  112095. +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
  112096. +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
  112097. +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
  112098. +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
  112099. +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
  112100. +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
  112101. +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
  112102. +bio_map_kern_64751 bio_map_kern 3 64751 NULL
  112103. +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
  112104. +message_for_md_64777 message_for_md 5 64777 NULL
  112105. +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
  112106. +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
  112107. +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
  112108. +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
  112109. +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
  112110. +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
  112111. +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
  112112. +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
  112113. +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
  112114. +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
  112115. +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
  112116. +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
  112117. +xfs_imap_lookup_64906 xfs_imap_lookup 0 64906 NULL
  112118. +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
  112119. +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
  112120. +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
  112121. +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
  112122. +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
  112123. +insert_dent_65034 insert_dent 7 65034 NULL
  112124. +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
  112125. +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
  112126. +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
  112127. +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
  112128. +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
  112129. +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
  112130. +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
  112131. +__xfs_bmapi_allocate_65142 __xfs_bmapi_allocate 0 65142 NULL
  112132. +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
  112133. +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
  112134. +whci_n_caps_65247 whci_n_caps 0 65247 NULL
  112135. +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
  112136. +xfs_btree_check_ptr_65281 xfs_btree_check_ptr 0 65281 NULL
  112137. +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
  112138. +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
  112139. +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
  112140. +get_var_len_65304 get_var_len 0 65304 NULL
  112141. +unpack_array_65318 unpack_array 0 65318 NULL
  112142. +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
  112143. +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
  112144. +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
  112145. +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
  112146. +SyS_writev_65372 SyS_writev 3 65372 NULL
  112147. +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
  112148. +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
  112149. +__read_vmcore_65402 __read_vmcore 2 65402 NULL
  112150. +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
  112151. +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
  112152. +device_add_groups_65423 device_add_groups 0 65423 NULL
  112153. +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
  112154. +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
  112155. +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
  112156. +clear_user_65470 clear_user 2 65470 NULL
  112157. +xfs_alloc_lookup_ge_65481 xfs_alloc_lookup_ge 0 65481 NULL
  112158. +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
  112159. +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
  112160. +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
  112161. +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
  112162. diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
  112163. new file mode 100644
  112164. index 0000000..560cd7b
  112165. --- /dev/null
  112166. +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
  112167. @@ -0,0 +1,92 @@
  112168. +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
  112169. +zfs_lookup_2144 zfs_lookup 0 2144 NULL
  112170. +mappedread_2627 mappedread 2 2627 NULL
  112171. +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
  112172. +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
  112173. +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
  112174. +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
  112175. +dmu_write_6048 dmu_write 4-3 6048 NULL
  112176. +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
  112177. +update_pages_6225 update_pages 2-3 6225 NULL
  112178. +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
  112179. +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
  112180. +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
  112181. +ddi_copyout_9401 ddi_copyout 3 9401 NULL
  112182. +avl_numnodes_12384 avl_numnodes 0 12384 NULL
  112183. +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
  112184. +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
  112185. +zpl_read_common_14389 zpl_read_common 0 14389 NULL
  112186. +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
  112187. +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
  112188. +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
  112189. +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
  112190. +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
  112191. +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
  112192. +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
  112193. +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
  112194. +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
  112195. +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
  112196. +uiocopy_18680 uiocopy 2 18680 NULL
  112197. +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
  112198. +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
  112199. +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
  112200. +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
  112201. +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
  112202. +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
  112203. +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
  112204. +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
  112205. +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
  112206. +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
  112207. +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
  112208. +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
  112209. +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
  112210. +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
  112211. +splat_write_30943 splat_write 3 30943 NULL
  112212. +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
  112213. +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
  112214. +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
  112215. +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
  112216. +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
  112217. +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
  112218. +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
  112219. +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
  112220. +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
  112221. +copyinstr_36980 copyinstr 3 36980 NULL
  112222. +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
  112223. +splat_read_38116 splat_read 3 38116 NULL
  112224. +sa_setup_38756 sa_setup 4 38756 NULL
  112225. +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
  112226. +arc_buf_size_39982 arc_buf_size 0 39982 NULL
  112227. +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
  112228. +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
  112229. +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
  112230. +sa_find_layout_40892 sa_find_layout 4 40892 NULL
  112231. +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
  112232. +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
  112233. +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
  112234. +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
  112235. +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
  112236. +kcopy_write_43683 kcopy_write 3 43683 NULL
  112237. +uiomove_44355 uiomove 2 44355 NULL
  112238. +dmu_read_44418 dmu_read 4-3 44418 NULL
  112239. +ddi_copyin_44846 ddi_copyin 3 44846 NULL
  112240. +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
  112241. +copyin_45945 copyin 3 45945 NULL
  112242. +zil_itx_create_46555 zil_itx_create 2 46555 NULL
  112243. +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
  112244. +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
  112245. +spa_history_write_49650 spa_history_write 3 49650 NULL
  112246. +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
  112247. +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
  112248. +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
  112249. +copyout_51409 copyout 3 51409 NULL
  112250. +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
  112251. +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
  112252. +get_nvlist_56685 get_nvlist 2 56685 NULL
  112253. +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
  112254. +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
  112255. +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
  112256. +zpios_write_61823 zpios_write 3 61823 NULL
  112257. +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
  112258. +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
  112259. +zpios_read_64734 zpios_read 3 64734 NULL
  112260. diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
  112261. new file mode 100644
  112262. index 0000000..0e9dcee
  112263. --- /dev/null
  112264. +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
  112265. @@ -0,0 +1,259 @@
  112266. +/*
  112267. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  112268. + * Licensed under the GPL v2, or (at your option) v3
  112269. + *
  112270. + * Homepage:
  112271. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  112272. + *
  112273. + * Documentation:
  112274. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  112275. + *
  112276. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  112277. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  112278. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  112279. + *
  112280. + * Usage:
  112281. + * $ make
  112282. + * $ make run
  112283. + */
  112284. +
  112285. +#include "gcc-common.h"
  112286. +#include "size_overflow.h"
  112287. +
  112288. +int plugin_is_GPL_compatible;
  112289. +
  112290. +tree report_size_overflow_decl;
  112291. +
  112292. +tree size_overflow_type_HI;
  112293. +tree size_overflow_type_SI;
  112294. +tree size_overflow_type_DI;
  112295. +tree size_overflow_type_TI;
  112296. +
  112297. +static struct plugin_info size_overflow_plugin_info = {
  112298. + .version = "20140515",
  112299. + .help = "no-size-overflow\tturn off size overflow checking\n",
  112300. +};
  112301. +
  112302. +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
  112303. +{
  112304. + unsigned int arg_count;
  112305. + enum tree_code code = TREE_CODE(*node);
  112306. +
  112307. + switch (code) {
  112308. + case FUNCTION_DECL:
  112309. + arg_count = type_num_arguments(TREE_TYPE(*node));
  112310. + break;
  112311. + case FUNCTION_TYPE:
  112312. + case METHOD_TYPE:
  112313. + arg_count = type_num_arguments(*node);
  112314. + break;
  112315. + default:
  112316. + *no_add_attrs = true;
  112317. + error("%s: %qE attribute only applies to functions", __func__, name);
  112318. + return NULL_TREE;
  112319. + }
  112320. +
  112321. + for (; args; args = TREE_CHAIN(args)) {
  112322. + tree position = TREE_VALUE(args);
  112323. + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
  112324. + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
  112325. + *no_add_attrs = true;
  112326. + }
  112327. + }
  112328. + return NULL_TREE;
  112329. +}
  112330. +
  112331. +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
  112332. +{
  112333. + unsigned int arg_count;
  112334. + enum tree_code code = TREE_CODE(*node);
  112335. +
  112336. + switch (code) {
  112337. + case FUNCTION_DECL:
  112338. + arg_count = type_num_arguments(TREE_TYPE(*node));
  112339. + break;
  112340. + case FUNCTION_TYPE:
  112341. + case METHOD_TYPE:
  112342. + arg_count = type_num_arguments(*node);
  112343. + break;
  112344. + case FIELD_DECL:
  112345. + return NULL_TREE;
  112346. + default:
  112347. + *no_add_attrs = true;
  112348. + error("%qE attribute only applies to functions", name);
  112349. + return NULL_TREE;
  112350. + }
  112351. +
  112352. + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
  112353. + return NULL_TREE;
  112354. +
  112355. + for (; args; args = TREE_CHAIN(args)) {
  112356. + tree position = TREE_VALUE(args);
  112357. + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
  112358. + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
  112359. + *no_add_attrs = true;
  112360. + }
  112361. + }
  112362. + return NULL_TREE;
  112363. +}
  112364. +
  112365. +static struct attribute_spec size_overflow_attr = {
  112366. + .name = "size_overflow",
  112367. + .min_length = 1,
  112368. + .max_length = -1,
  112369. + .decl_required = true,
  112370. + .type_required = false,
  112371. + .function_type_required = false,
  112372. + .handler = handle_size_overflow_attribute,
  112373. +#if BUILDING_GCC_VERSION >= 4007
  112374. + .affects_type_identity = false
  112375. +#endif
  112376. +};
  112377. +
  112378. +static struct attribute_spec intentional_overflow_attr = {
  112379. + .name = "intentional_overflow",
  112380. + .min_length = 1,
  112381. + .max_length = -1,
  112382. + .decl_required = true,
  112383. + .type_required = false,
  112384. + .function_type_required = false,
  112385. + .handler = handle_intentional_overflow_attribute,
  112386. +#if BUILDING_GCC_VERSION >= 4007
  112387. + .affects_type_identity = false
  112388. +#endif
  112389. +};
  112390. +
  112391. +static void register_attributes(void __unused *event_data, void __unused *data)
  112392. +{
  112393. + register_attribute(&size_overflow_attr);
  112394. + register_attribute(&intentional_overflow_attr);
  112395. +}
  112396. +
  112397. +static tree create_typedef(tree type, const char* ident)
  112398. +{
  112399. + tree new_type, decl;
  112400. +
  112401. + new_type = build_variant_type_copy(type);
  112402. + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
  112403. + DECL_ORIGINAL_TYPE(decl) = type;
  112404. + TYPE_NAME(new_type) = decl;
  112405. + return new_type;
  112406. +}
  112407. +
  112408. +// Create the noreturn report_size_overflow() function decl.
  112409. +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
  112410. +{
  112411. + tree const_char_ptr_type_node;
  112412. + tree fntype;
  112413. +
  112414. + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
  112415. +
  112416. + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
  112417. + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
  112418. + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
  112419. + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
  112420. +
  112421. + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
  112422. + fntype = build_function_type_list(void_type_node,
  112423. + const_char_ptr_type_node,
  112424. + unsigned_type_node,
  112425. + const_char_ptr_type_node,
  112426. + const_char_ptr_type_node,
  112427. + NULL_TREE);
  112428. + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
  112429. +
  112430. + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
  112431. + TREE_PUBLIC(report_size_overflow_decl) = 1;
  112432. + DECL_EXTERNAL(report_size_overflow_decl) = 1;
  112433. + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
  112434. + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
  112435. +}
  112436. +
  112437. +
  112438. +extern struct gimple_opt_pass pass_dce;
  112439. +
  112440. +static struct opt_pass *make_dce_pass(void)
  112441. +{
  112442. +#if BUILDING_GCC_VERSION >= 4009
  112443. + return make_pass_dce(g);
  112444. +#else
  112445. + return &pass_dce.pass;
  112446. +#endif
  112447. +}
  112448. +
  112449. +
  112450. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  112451. +{
  112452. + int i;
  112453. + const char * const plugin_name = plugin_info->base_name;
  112454. + const int argc = plugin_info->argc;
  112455. + const struct plugin_argument * const argv = plugin_info->argv;
  112456. + bool enable = true;
  112457. + struct register_pass_info insert_size_overflow_asm_pass_info;
  112458. + struct register_pass_info __unused dump_before_pass_info;
  112459. + struct register_pass_info __unused dump_after_pass_info;
  112460. + struct register_pass_info insert_size_overflow_check_info;
  112461. + struct register_pass_info dce_pass_info;
  112462. + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
  112463. + {
  112464. + .base = &report_size_overflow_decl,
  112465. + .nelt = 1,
  112466. + .stride = sizeof(report_size_overflow_decl),
  112467. + .cb = &gt_ggc_mx_tree_node,
  112468. + .pchw = &gt_pch_nx_tree_node
  112469. + },
  112470. + LAST_GGC_ROOT_TAB
  112471. + };
  112472. +
  112473. + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
  112474. + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
  112475. + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
  112476. + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  112477. +
  112478. + dump_before_pass_info.pass = make_dump_pass();
  112479. + dump_before_pass_info.reference_pass_name = "increase_alignment";
  112480. + dump_before_pass_info.ref_pass_instance_number = 1;
  112481. + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
  112482. +
  112483. + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
  112484. + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
  112485. + insert_size_overflow_check_info.ref_pass_instance_number = 1;
  112486. + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
  112487. +
  112488. + dump_after_pass_info.pass = make_dump_pass();
  112489. + dump_after_pass_info.reference_pass_name = "increase_alignment";
  112490. + dump_after_pass_info.ref_pass_instance_number = 1;
  112491. + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
  112492. +
  112493. + dce_pass_info.pass = make_dce_pass();
  112494. + dce_pass_info.reference_pass_name = "vrp";
  112495. + dce_pass_info.ref_pass_instance_number = 1;
  112496. + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  112497. +
  112498. + if (!plugin_default_version_check(version, &gcc_version)) {
  112499. + error(G_("incompatible gcc/plugin versions"));
  112500. + return 1;
  112501. + }
  112502. +
  112503. + for (i = 0; i < argc; ++i) {
  112504. + if (!strcmp(argv[i].key, "no-size-overflow")) {
  112505. + enable = false;
  112506. + continue;
  112507. + }
  112508. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  112509. + }
  112510. +
  112511. + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
  112512. + if (enable) {
  112513. + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
  112514. + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
  112515. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
  112516. +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
  112517. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
  112518. +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
  112519. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
  112520. + }
  112521. + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
  112522. +
  112523. + return 0;
  112524. +}
  112525. diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
  112526. new file mode 100644
  112527. index 0000000..0888f6c
  112528. --- /dev/null
  112529. +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
  112530. @@ -0,0 +1,364 @@
  112531. +/*
  112532. + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
  112533. + * Licensed under the GPL v2, or (at your option) v3
  112534. + *
  112535. + * Homepage:
  112536. + * http://www.grsecurity.net/~ephox/overflow_plugin/
  112537. + *
  112538. + * Documentation:
  112539. + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
  112540. + *
  112541. + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
  112542. + * with double integer precision (DImode/TImode for 32/64 bit integer types).
  112543. + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
  112544. + *
  112545. + * Usage:
  112546. + * $ make
  112547. + * $ make run
  112548. + */
  112549. +
  112550. +#include "gcc-common.h"
  112551. +#include "size_overflow.h"
  112552. +
  112553. +#include "size_overflow_hash.h"
  112554. +#include "size_overflow_hash_aux.h"
  112555. +
  112556. +#define CODES_LIMIT 32
  112557. +
  112558. +static unsigned char get_tree_code(const_tree type)
  112559. +{
  112560. + switch (TREE_CODE(type)) {
  112561. + case ARRAY_TYPE:
  112562. + return 0;
  112563. + case BOOLEAN_TYPE:
  112564. + return 1;
  112565. + case ENUMERAL_TYPE:
  112566. + return 2;
  112567. + case FUNCTION_TYPE:
  112568. + return 3;
  112569. + case INTEGER_TYPE:
  112570. + return 4;
  112571. + case POINTER_TYPE:
  112572. + return 5;
  112573. + case RECORD_TYPE:
  112574. + return 6;
  112575. + case UNION_TYPE:
  112576. + return 7;
  112577. + case VOID_TYPE:
  112578. + return 8;
  112579. + case REAL_TYPE:
  112580. + return 9;
  112581. + case VECTOR_TYPE:
  112582. + return 10;
  112583. + case REFERENCE_TYPE:
  112584. + return 11;
  112585. + case OFFSET_TYPE:
  112586. + return 12;
  112587. + case COMPLEX_TYPE:
  112588. + return 13;
  112589. + default:
  112590. + debug_tree((tree)type);
  112591. + gcc_unreachable();
  112592. + }
  112593. +}
  112594. +
  112595. +struct function_hash {
  112596. + size_t tree_codes_len;
  112597. + unsigned char tree_codes[CODES_LIMIT];
  112598. + const_tree fndecl;
  112599. + unsigned int hash;
  112600. +};
  112601. +
  112602. +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
  112603. +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
  112604. +{
  112605. +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
  112606. +#define cwmixa( in ) { cwfold( in, m, k, h ); }
  112607. +#define cwmixb( in ) { cwfold( in, n, h, k ); }
  112608. +
  112609. + unsigned int m = 0x57559429;
  112610. + unsigned int n = 0x5052acdb;
  112611. + const unsigned int *key4 = (const unsigned int *)key;
  112612. + unsigned int h = len;
  112613. + unsigned int k = len + seed + n;
  112614. + unsigned long long p;
  112615. +
  112616. + while (len >= 8) {
  112617. + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
  112618. + len -= 8;
  112619. + }
  112620. + if (len >= 4) {
  112621. + cwmixb(key4[0]) key4 += 1;
  112622. + len -= 4;
  112623. + }
  112624. + if (len)
  112625. + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
  112626. + cwmixb(h ^ (k + n));
  112627. + return k ^ h;
  112628. +
  112629. +#undef cwfold
  112630. +#undef cwmixa
  112631. +#undef cwmixb
  112632. +}
  112633. +
  112634. +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
  112635. +{
  112636. + unsigned int fn, codes, seed = 0;
  112637. +
  112638. + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
  112639. + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
  112640. +
  112641. + fn_hash_data->hash = fn ^ codes;
  112642. +}
  112643. +
  112644. +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
  112645. +{
  112646. + gcc_assert(type != NULL_TREE);
  112647. + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
  112648. +
  112649. + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
  112650. + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
  112651. + fn_hash_data->tree_codes_len++;
  112652. + type = TREE_TYPE(type);
  112653. + }
  112654. +}
  112655. +
  112656. +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
  112657. +{
  112658. + const_tree result;
  112659. +
  112660. + gcc_assert(node != NULL_TREE);
  112661. +
  112662. + if (DECL_P(node)) {
  112663. + result = DECL_RESULT(node);
  112664. + if (result != NULL_TREE)
  112665. + return set_node_codes(TREE_TYPE(result), fn_hash_data);
  112666. + return set_result_codes(TREE_TYPE(node), fn_hash_data);
  112667. + }
  112668. +
  112669. + gcc_assert(TYPE_P(node));
  112670. +
  112671. + if (TREE_CODE(node) == FUNCTION_TYPE)
  112672. + return set_result_codes(TREE_TYPE(node), fn_hash_data);
  112673. +
  112674. + return set_node_codes(node, fn_hash_data);
  112675. +}
  112676. +
  112677. +static void set_function_codes(struct function_hash *fn_hash_data)
  112678. +{
  112679. + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
  112680. + enum tree_code code = TREE_CODE(type);
  112681. +
  112682. + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
  112683. +
  112684. + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
  112685. +
  112686. + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
  112687. + set_node_codes(TREE_VALUE(arg), fn_hash_data);
  112688. +}
  112689. +
  112690. +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
  112691. +{
  112692. + while (entry) {
  112693. + if (!strcmp(entry->name, func_name))
  112694. + return entry;
  112695. + entry = entry->next;
  112696. + }
  112697. + return NULL;
  112698. +}
  112699. +
  112700. +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
  112701. +{
  112702. + const struct size_overflow_hash *entry;
  112703. + struct function_hash fn_hash_data;
  112704. + const char *func_name;
  112705. +
  112706. + // skip builtins __builtin_constant_p
  112707. + if (DECL_BUILT_IN(fndecl))
  112708. + return NULL;
  112709. +
  112710. + fn_hash_data.fndecl = fndecl;
  112711. + fn_hash_data.tree_codes_len = 0;
  112712. +
  112713. + set_function_codes(&fn_hash_data);
  112714. + gcc_assert(fn_hash_data.tree_codes_len != 0);
  112715. +
  112716. + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
  112717. + set_hash(func_name, &fn_hash_data);
  112718. +
  112719. + entry = size_overflow_hash[fn_hash_data.hash];
  112720. + entry = get_proper_hash_chain(entry, func_name);
  112721. + if (entry)
  112722. + return entry;
  112723. + entry = size_overflow_hash_aux[fn_hash_data.hash];
  112724. + return get_proper_hash_chain(entry, func_name);
  112725. +}
  112726. +
  112727. +static void print_missing_msg(const_tree func, unsigned int argnum)
  112728. +{
  112729. + location_t loc;
  112730. + const char *curfunc;
  112731. + struct function_hash fn_hash_data;
  112732. +
  112733. + fn_hash_data.fndecl = DECL_ORIGIN(func);
  112734. + fn_hash_data.tree_codes_len = 0;
  112735. +
  112736. + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
  112737. + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
  112738. +
  112739. + set_function_codes(&fn_hash_data);
  112740. + set_hash(curfunc, &fn_hash_data);
  112741. +
  112742. + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
  112743. +}
  112744. +
  112745. +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
  112746. +{
  112747. + tree var;
  112748. + unsigned int argnum = 1;
  112749. +
  112750. + if (TREE_CODE(arg) == SSA_NAME)
  112751. + arg = SSA_NAME_VAR(arg);
  112752. +
  112753. + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
  112754. + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
  112755. + continue;
  112756. + if (!skip_types(var))
  112757. + return argnum;
  112758. + }
  112759. +
  112760. + return CANNOT_FIND_ARG;
  112761. +}
  112762. +
  112763. +static const char *get_asm_string(const_gimple stmt)
  112764. +{
  112765. + if (!stmt)
  112766. + return NULL;
  112767. + if (gimple_code(stmt) != GIMPLE_ASM)
  112768. + return NULL;
  112769. +
  112770. + return gimple_asm_string(stmt);
  112771. +}
  112772. +
  112773. +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
  112774. +{
  112775. + const char *str;
  112776. +
  112777. + str = get_asm_string(stmt);
  112778. + if (!str)
  112779. + return false;
  112780. + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
  112781. +}
  112782. +
  112783. +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
  112784. +{
  112785. + const char *str;
  112786. +
  112787. + str = get_asm_string(stmt);
  112788. + if (!str)
  112789. + return false;
  112790. + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
  112791. +}
  112792. +
  112793. +bool is_size_overflow_asm(const_gimple stmt)
  112794. +{
  112795. + const char *str;
  112796. +
  112797. + str = get_asm_string(stmt);
  112798. + if (!str)
  112799. + return false;
  112800. + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
  112801. +}
  112802. +
  112803. +bool is_a_return_check(const_tree node)
  112804. +{
  112805. + if (TREE_CODE(node) == FUNCTION_DECL)
  112806. + return true;
  112807. +
  112808. + gcc_assert(TREE_CODE(node) == PARM_DECL);
  112809. + return false;
  112810. +}
  112811. +
  112812. +// Get the argnum of a function decl, if node is a return then the argnum is 0
  112813. +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
  112814. +{
  112815. + if (is_a_return_check(node))
  112816. + return 0;
  112817. + else
  112818. + return find_arg_number_tree(node, orig_fndecl);
  112819. +}
  112820. +
  112821. +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
  112822. +{
  112823. + const struct size_overflow_hash *hash;
  112824. + unsigned int new_argnum;
  112825. + tree arg;
  112826. + const_tree origarg;
  112827. +
  112828. + if (argnum == 0)
  112829. + return argnum;
  112830. +
  112831. + hash = get_function_hash(fndecl);
  112832. + if (hash && hash->param & (1U << argnum))
  112833. + return argnum;
  112834. +
  112835. + if (DECL_EXTERNAL(fndecl))
  112836. + return argnum;
  112837. +
  112838. + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
  112839. + argnum--;
  112840. + while (origarg && argnum) {
  112841. + origarg = TREE_CHAIN(origarg);
  112842. + argnum--;
  112843. + }
  112844. + gcc_assert(argnum == 0);
  112845. + gcc_assert(origarg != NULL_TREE);
  112846. +
  112847. + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
  112848. + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
  112849. + return new_argnum;
  112850. +
  112851. + return CANNOT_FIND_ARG;
  112852. +}
  112853. +
  112854. +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
  112855. +{
  112856. + const struct size_overflow_hash *hash;
  112857. +
  112858. + hash = get_function_hash(fndecl);
  112859. + if (hash && (hash->param & (1U << num)))
  112860. + return true;
  112861. + return false;
  112862. +}
  112863. +
  112864. +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
  112865. + * If the function is missing everywhere then print the missing message into stderr.
  112866. + */
  112867. +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
  112868. +{
  112869. + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
  112870. +#if BUILDING_GCC_VERSION >= 4008
  112871. + case BUILT_IN_BSWAP16:
  112872. +#endif
  112873. + case BUILT_IN_BSWAP32:
  112874. + case BUILT_IN_BSWAP64:
  112875. + case BUILT_IN_EXPECT:
  112876. + case BUILT_IN_MEMCMP:
  112877. + return false;
  112878. + default:
  112879. + break;
  112880. + }
  112881. +
  112882. + // skip test.c
  112883. + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
  112884. + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
  112885. + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
  112886. + }
  112887. +
  112888. + if (is_in_hash_table(orig_fndecl, num))
  112889. + return false;
  112890. +
  112891. + print_missing_msg(orig_fndecl, num);
  112892. + return true;
  112893. +}
  112894. +
  112895. diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
  112896. new file mode 100644
  112897. index 0000000..dd94983
  112898. --- /dev/null
  112899. +++ b/tools/gcc/stackleak_plugin.c
  112900. @@ -0,0 +1,376 @@
  112901. +/*
  112902. + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
  112903. + * Licensed under the GPL v2
  112904. + *
  112905. + * Note: the choice of the license means that the compilation process is
  112906. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  112907. + * but for the kernel it doesn't matter since it doesn't link against
  112908. + * any of the gcc libraries
  112909. + *
  112910. + * gcc plugin to help implement various PaX features
  112911. + *
  112912. + * - track lowest stack pointer
  112913. + *
  112914. + * TODO:
  112915. + * - initialize all local variables
  112916. + *
  112917. + * BUGS:
  112918. + * - none known
  112919. + */
  112920. +
  112921. +#include "gcc-common.h"
  112922. +
  112923. +int plugin_is_GPL_compatible;
  112924. +
  112925. +static int track_frame_size = -1;
  112926. +static const char track_function[] = "pax_track_stack";
  112927. +static const char check_function[] = "pax_check_alloca";
  112928. +static tree track_function_decl, check_function_decl;
  112929. +static bool init_locals;
  112930. +
  112931. +static struct plugin_info stackleak_plugin_info = {
  112932. + .version = "201402131920",
  112933. + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
  112934. +// "initialize-locals\t\tforcibly initialize all stack frames\n"
  112935. +};
  112936. +
  112937. +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
  112938. +{
  112939. + gimple check_alloca;
  112940. + tree alloca_size;
  112941. +
  112942. + // insert call to void pax_check_alloca(unsigned long size)
  112943. + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
  112944. + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
  112945. + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
  112946. +}
  112947. +
  112948. +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
  112949. +{
  112950. + gimple track_stack;
  112951. +
  112952. + // insert call to void pax_track_stack(void)
  112953. + track_stack = gimple_build_call(track_function_decl, 0);
  112954. + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
  112955. +}
  112956. +
  112957. +static bool is_alloca(gimple stmt)
  112958. +{
  112959. + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
  112960. + return true;
  112961. +
  112962. +#if BUILDING_GCC_VERSION >= 4007
  112963. + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
  112964. + return true;
  112965. +#endif
  112966. +
  112967. + return false;
  112968. +}
  112969. +
  112970. +static unsigned int execute_stackleak_tree_instrument(void)
  112971. +{
  112972. + basic_block bb, entry_bb;
  112973. + bool prologue_instrumented = false, is_leaf = true;
  112974. +
  112975. + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
  112976. +
  112977. + // 1. loop through BBs and GIMPLE statements
  112978. + FOR_EACH_BB_FN(bb, cfun) {
  112979. + gimple_stmt_iterator gsi;
  112980. +
  112981. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  112982. + gimple stmt;
  112983. +
  112984. + stmt = gsi_stmt(gsi);
  112985. +
  112986. + if (is_gimple_call(stmt))
  112987. + is_leaf = false;
  112988. +
  112989. + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
  112990. + if (!is_alloca(stmt))
  112991. + continue;
  112992. +
  112993. + // 2. insert stack overflow check before each __builtin_alloca call
  112994. + stackleak_check_alloca(&gsi);
  112995. +
  112996. + // 3. insert track call after each __builtin_alloca call
  112997. + stackleak_add_instrumentation(&gsi);
  112998. + if (bb == entry_bb)
  112999. + prologue_instrumented = true;
  113000. + }
  113001. + }
  113002. +
  113003. + // special cases for some bad linux code: taking the address of static inline functions will materialize them
  113004. + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
  113005. + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
  113006. + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
  113007. + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
  113008. + return 0;
  113009. + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
  113010. + return 0;
  113011. +
  113012. + // 4. insert track call at the beginning
  113013. + if (!prologue_instrumented) {
  113014. + gimple_stmt_iterator gsi;
  113015. +
  113016. + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
  113017. + if (dom_info_available_p(CDI_DOMINATORS))
  113018. + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
  113019. + gsi = gsi_start_bb(bb);
  113020. + stackleak_add_instrumentation(&gsi);
  113021. + }
  113022. +
  113023. + return 0;
  113024. +}
  113025. +
  113026. +static unsigned int execute_stackleak_final(void)
  113027. +{
  113028. + rtx insn, next;
  113029. +
  113030. + if (cfun->calls_alloca)
  113031. + return 0;
  113032. +
  113033. + // keep calls only if function frame is big enough
  113034. + if (get_frame_size() >= track_frame_size)
  113035. + return 0;
  113036. +
  113037. + // 1. find pax_track_stack calls
  113038. + for (insn = get_insns(); insn; insn = next) {
  113039. + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
  113040. + rtx body;
  113041. +
  113042. + next = NEXT_INSN(insn);
  113043. + if (!CALL_P(insn))
  113044. + continue;
  113045. + body = PATTERN(insn);
  113046. + if (GET_CODE(body) != CALL)
  113047. + continue;
  113048. + body = XEXP(body, 0);
  113049. + if (GET_CODE(body) != MEM)
  113050. + continue;
  113051. + body = XEXP(body, 0);
  113052. + if (GET_CODE(body) != SYMBOL_REF)
  113053. + continue;
  113054. +// if (strcmp(XSTR(body, 0), track_function))
  113055. + if (SYMBOL_REF_DECL(body) != track_function_decl)
  113056. + continue;
  113057. +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
  113058. + // 2. delete call
  113059. + delete_insn_and_edges(insn);
  113060. +#if BUILDING_GCC_VERSION >= 4007
  113061. + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
  113062. + insn = next;
  113063. + next = NEXT_INSN(insn);
  113064. + delete_insn_and_edges(insn);
  113065. + }
  113066. +#endif
  113067. + }
  113068. +
  113069. +// print_simple_rtl(stderr, get_insns());
  113070. +// print_rtl(stderr, get_insns());
  113071. +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
  113072. +
  113073. + return 0;
  113074. +}
  113075. +
  113076. +static bool gate_stackleak_track_stack(void)
  113077. +{
  113078. + return track_frame_size >= 0;
  113079. +}
  113080. +
  113081. +static void stackleak_start_unit(void *gcc_data, void *user_data)
  113082. +{
  113083. + tree fntype;
  113084. +
  113085. + // void pax_track_stack(void)
  113086. + fntype = build_function_type_list(void_type_node, NULL_TREE);
  113087. + track_function_decl = build_fn_decl(track_function, fntype);
  113088. + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
  113089. + TREE_PUBLIC(track_function_decl) = 1;
  113090. + DECL_EXTERNAL(track_function_decl) = 1;
  113091. + DECL_ARTIFICIAL(track_function_decl) = 1;
  113092. +
  113093. + // void pax_check_alloca(unsigned long)
  113094. + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
  113095. + check_function_decl = build_fn_decl(check_function, fntype);
  113096. + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
  113097. + TREE_PUBLIC(check_function_decl) = 1;
  113098. + DECL_EXTERNAL(check_function_decl) = 1;
  113099. + DECL_ARTIFICIAL(check_function_decl) = 1;
  113100. +}
  113101. +
  113102. +#if BUILDING_GCC_VERSION >= 4009
  113103. +static const struct pass_data stackleak_tree_instrument_pass_data = {
  113104. +#else
  113105. +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
  113106. + .pass = {
  113107. +#endif
  113108. + .type = GIMPLE_PASS,
  113109. + .name = "stackleak_tree_instrument",
  113110. +#if BUILDING_GCC_VERSION >= 4008
  113111. + .optinfo_flags = OPTGROUP_NONE,
  113112. +#endif
  113113. +#if BUILDING_GCC_VERSION >= 4009
  113114. + .has_gate = true,
  113115. + .has_execute = true,
  113116. +#else
  113117. + .gate = gate_stackleak_track_stack,
  113118. + .execute = execute_stackleak_tree_instrument,
  113119. + .sub = NULL,
  113120. + .next = NULL,
  113121. + .static_pass_number = 0,
  113122. +#endif
  113123. + .tv_id = TV_NONE,
  113124. + .properties_required = PROP_gimple_leh | PROP_cfg,
  113125. + .properties_provided = 0,
  113126. + .properties_destroyed = 0,
  113127. + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
  113128. + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
  113129. +#if BUILDING_GCC_VERSION < 4009
  113130. + }
  113131. +#endif
  113132. +};
  113133. +
  113134. +#if BUILDING_GCC_VERSION >= 4009
  113135. +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
  113136. +#else
  113137. +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
  113138. + .pass = {
  113139. +#endif
  113140. + .type = RTL_PASS,
  113141. + .name = "stackleak_final",
  113142. +#if BUILDING_GCC_VERSION >= 4008
  113143. + .optinfo_flags = OPTGROUP_NONE,
  113144. +#endif
  113145. +#if BUILDING_GCC_VERSION >= 4009
  113146. + .has_gate = true,
  113147. + .has_execute = true,
  113148. +#else
  113149. + .gate = gate_stackleak_track_stack,
  113150. + .execute = execute_stackleak_final,
  113151. + .sub = NULL,
  113152. + .next = NULL,
  113153. + .static_pass_number = 0,
  113154. +#endif
  113155. + .tv_id = TV_NONE,
  113156. + .properties_required = 0,
  113157. + .properties_provided = 0,
  113158. + .properties_destroyed = 0,
  113159. + .todo_flags_start = 0,
  113160. + .todo_flags_finish = TODO_dump_func
  113161. +#if BUILDING_GCC_VERSION < 4009
  113162. + }
  113163. +#endif
  113164. +};
  113165. +
  113166. +#if BUILDING_GCC_VERSION >= 4009
  113167. +namespace {
  113168. +class stackleak_tree_instrument_pass : public gimple_opt_pass {
  113169. +public:
  113170. + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
  113171. + bool gate() { return gate_stackleak_track_stack(); }
  113172. + unsigned int execute() { return execute_stackleak_tree_instrument(); }
  113173. +};
  113174. +
  113175. +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
  113176. +public:
  113177. + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
  113178. + bool gate() { return gate_stackleak_track_stack(); }
  113179. + unsigned int execute() { return execute_stackleak_final(); }
  113180. +};
  113181. +}
  113182. +
  113183. +static opt_pass *make_stackleak_tree_instrument_pass(void)
  113184. +{
  113185. + return new stackleak_tree_instrument_pass();
  113186. +}
  113187. +
  113188. +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
  113189. +{
  113190. + return new stackleak_final_rtl_opt_pass();
  113191. +}
  113192. +#else
  113193. +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
  113194. +{
  113195. + return &stackleak_tree_instrument_pass.pass;
  113196. +}
  113197. +
  113198. +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
  113199. +{
  113200. + return &stackleak_final_rtl_opt_pass.pass;
  113201. +}
  113202. +#endif
  113203. +
  113204. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  113205. +{
  113206. + const char * const plugin_name = plugin_info->base_name;
  113207. + const int argc = plugin_info->argc;
  113208. + const struct plugin_argument * const argv = plugin_info->argv;
  113209. + int i;
  113210. + struct register_pass_info stackleak_tree_instrument_pass_info;
  113211. + struct register_pass_info stackleak_final_pass_info;
  113212. + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
  113213. + {
  113214. + .base = &track_function_decl,
  113215. + .nelt = 1,
  113216. + .stride = sizeof(track_function_decl),
  113217. + .cb = &gt_ggc_mx_tree_node,
  113218. + .pchw = &gt_pch_nx_tree_node
  113219. + },
  113220. + {
  113221. + .base = &check_function_decl,
  113222. + .nelt = 1,
  113223. + .stride = sizeof(check_function_decl),
  113224. + .cb = &gt_ggc_mx_tree_node,
  113225. + .pchw = &gt_pch_nx_tree_node
  113226. + },
  113227. + LAST_GGC_ROOT_TAB
  113228. + };
  113229. +
  113230. + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
  113231. +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
  113232. + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
  113233. + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
  113234. + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
  113235. +
  113236. + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
  113237. + stackleak_final_pass_info.reference_pass_name = "final";
  113238. + stackleak_final_pass_info.ref_pass_instance_number = 1;
  113239. + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
  113240. +
  113241. + if (!plugin_default_version_check(version, &gcc_version)) {
  113242. + error(G_("incompatible gcc/plugin versions"));
  113243. + return 1;
  113244. + }
  113245. +
  113246. + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
  113247. +
  113248. + for (i = 0; i < argc; ++i) {
  113249. + if (!strcmp(argv[i].key, "track-lowest-sp")) {
  113250. + if (!argv[i].value) {
  113251. + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  113252. + continue;
  113253. + }
  113254. + track_frame_size = atoi(argv[i].value);
  113255. + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
  113256. + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
  113257. + continue;
  113258. + }
  113259. + if (!strcmp(argv[i].key, "initialize-locals")) {
  113260. + if (argv[i].value) {
  113261. + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
  113262. + continue;
  113263. + }
  113264. + init_locals = true;
  113265. + continue;
  113266. + }
  113267. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  113268. + }
  113269. +
  113270. + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
  113271. + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
  113272. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
  113273. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
  113274. +
  113275. + return 0;
  113276. +}
  113277. diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
  113278. new file mode 100644
  113279. index 0000000..4ee2231
  113280. --- /dev/null
  113281. +++ b/tools/gcc/structleak_plugin.c
  113282. @@ -0,0 +1,274 @@
  113283. +/*
  113284. + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
  113285. + * Licensed under the GPL v2
  113286. + *
  113287. + * Note: the choice of the license means that the compilation process is
  113288. + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  113289. + * but for the kernel it doesn't matter since it doesn't link against
  113290. + * any of the gcc libraries
  113291. + *
  113292. + * gcc plugin to forcibly initialize certain local variables that could
  113293. + * otherwise leak kernel stack to userland if they aren't properly initialized
  113294. + * by later code
  113295. + *
  113296. + * Homepage: http://pax.grsecurity.net/
  113297. + *
  113298. + * Usage:
  113299. + * $ # for 4.5/4.6/C based 4.7
  113300. + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o structleak_plugin.so structleak_plugin.c
  113301. + * $ # for C++ based 4.7/4.8+
  113302. + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o structleak_plugin.so structleak_plugin.c
  113303. + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
  113304. + *
  113305. + * TODO: eliminate redundant initializers
  113306. + * increase type coverage
  113307. + */
  113308. +
  113309. +#include "gcc-common.h"
  113310. +
  113311. +// unused C type flag in all versions 4.5-4.9
  113312. +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
  113313. +
  113314. +int plugin_is_GPL_compatible;
  113315. +
  113316. +static struct plugin_info structleak_plugin_info = {
  113317. + .version = "201401260140",
  113318. + .help = "disable\tdo not activate plugin\n",
  113319. +};
  113320. +
  113321. +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
  113322. +{
  113323. + *no_add_attrs = true;
  113324. +
  113325. + // check for types? for now accept everything linux has to offer
  113326. + if (TREE_CODE(*node) != FIELD_DECL)
  113327. + return NULL_TREE;
  113328. +
  113329. + *no_add_attrs = false;
  113330. + return NULL_TREE;
  113331. +}
  113332. +
  113333. +static struct attribute_spec user_attr = {
  113334. + .name = "user",
  113335. + .min_length = 0,
  113336. + .max_length = 0,
  113337. + .decl_required = false,
  113338. + .type_required = false,
  113339. + .function_type_required = false,
  113340. + .handler = handle_user_attribute,
  113341. +#if BUILDING_GCC_VERSION >= 4007
  113342. + .affects_type_identity = true
  113343. +#endif
  113344. +};
  113345. +
  113346. +static void register_attributes(void *event_data, void *data)
  113347. +{
  113348. + register_attribute(&user_attr);
  113349. +// register_attribute(&force_attr);
  113350. +}
  113351. +
  113352. +static tree get_field_type(tree field)
  113353. +{
  113354. + return strip_array_types(TREE_TYPE(field));
  113355. +}
  113356. +
  113357. +static bool is_userspace_type(tree type)
  113358. +{
  113359. + tree field;
  113360. +
  113361. + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
  113362. + tree fieldtype = get_field_type(field);
  113363. + enum tree_code code = TREE_CODE(fieldtype);
  113364. +
  113365. + if (code == RECORD_TYPE || code == UNION_TYPE)
  113366. + if (is_userspace_type(fieldtype))
  113367. + return true;
  113368. +
  113369. + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
  113370. + return true;
  113371. + }
  113372. + return false;
  113373. +}
  113374. +
  113375. +static void finish_type(void *event_data, void *data)
  113376. +{
  113377. + tree type = (tree)event_data;
  113378. +
  113379. + if (TYPE_USERSPACE(type))
  113380. + return;
  113381. +
  113382. + if (is_userspace_type(type))
  113383. + TYPE_USERSPACE(type) = 1;
  113384. +}
  113385. +
  113386. +static void initialize(tree var)
  113387. +{
  113388. + basic_block bb;
  113389. + gimple_stmt_iterator gsi;
  113390. + tree initializer;
  113391. + gimple init_stmt;
  113392. +
  113393. + // this is the original entry bb before the forced split
  113394. + // TODO: check further BBs in case more splits occured before us
  113395. + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
  113396. +
  113397. + // first check if the variable is already initialized, warn otherwise
  113398. + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  113399. + gimple stmt = gsi_stmt(gsi);
  113400. + tree rhs1;
  113401. +
  113402. + // we're looking for an assignment of a single rhs...
  113403. + if (!gimple_assign_single_p(stmt))
  113404. + continue;
  113405. + rhs1 = gimple_assign_rhs1(stmt);
  113406. +#if BUILDING_GCC_VERSION >= 4007
  113407. + // ... of a non-clobbering expression...
  113408. + if (TREE_CLOBBER_P(rhs1))
  113409. + continue;
  113410. +#endif
  113411. + // ... to our variable...
  113412. + if (gimple_get_lhs(stmt) != var)
  113413. + continue;
  113414. + // if it's an initializer then we're good
  113415. + if (TREE_CODE(rhs1) == CONSTRUCTOR)
  113416. + return;
  113417. + }
  113418. +
  113419. + // these aren't the 0days you're looking for
  113420. +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
  113421. +
  113422. + // build the initializer expression
  113423. + initializer = build_constructor(TREE_TYPE(var), NULL);
  113424. +
  113425. + // build the initializer stmt
  113426. + init_stmt = gimple_build_assign(var, initializer);
  113427. + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
  113428. + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
  113429. + update_stmt(init_stmt);
  113430. +}
  113431. +
  113432. +static unsigned int handle_function(void)
  113433. +{
  113434. + basic_block bb;
  113435. + unsigned int ret = 0;
  113436. + tree var;
  113437. + unsigned int i;
  113438. +
  113439. + // split the first bb where we can put the forced initializers
  113440. + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
  113441. + if (dom_info_available_p(CDI_DOMINATORS))
  113442. + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
  113443. +
  113444. + // enumarate all local variables and forcibly initialize our targets
  113445. + FOR_EACH_LOCAL_DECL(cfun, i, var) {
  113446. + tree type = TREE_TYPE(var);
  113447. +
  113448. + gcc_assert(DECL_P(var));
  113449. + if (!auto_var_in_fn_p(var, current_function_decl))
  113450. + continue;
  113451. +
  113452. + // only care about structure types
  113453. + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
  113454. + continue;
  113455. +
  113456. + // if the type is of interest, examine the variable
  113457. + if (TYPE_USERSPACE(type))
  113458. + initialize(var);
  113459. + }
  113460. +
  113461. + return ret;
  113462. +}
  113463. +
  113464. +#if BUILDING_GCC_VERSION >= 4009
  113465. +static const struct pass_data structleak_pass_data = {
  113466. +#else
  113467. +static struct gimple_opt_pass structleak_pass = {
  113468. + .pass = {
  113469. +#endif
  113470. + .type = GIMPLE_PASS,
  113471. + .name = "structleak",
  113472. +#if BUILDING_GCC_VERSION >= 4008
  113473. + .optinfo_flags = OPTGROUP_NONE,
  113474. +#endif
  113475. +#if BUILDING_GCC_VERSION >= 4009
  113476. + .has_gate = false,
  113477. + .has_execute = true,
  113478. +#else
  113479. + .gate = NULL,
  113480. + .execute = handle_function,
  113481. + .sub = NULL,
  113482. + .next = NULL,
  113483. + .static_pass_number = 0,
  113484. +#endif
  113485. + .tv_id = TV_NONE,
  113486. + .properties_required = PROP_cfg,
  113487. + .properties_provided = 0,
  113488. + .properties_destroyed = 0,
  113489. + .todo_flags_start = 0,
  113490. + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa | TODO_ggc_collect | TODO_verify_flow
  113491. +#if BUILDING_GCC_VERSION < 4009
  113492. + }
  113493. +#endif
  113494. +};
  113495. +
  113496. +#if BUILDING_GCC_VERSION >= 4009
  113497. +namespace {
  113498. +class structleak_pass : public gimple_opt_pass {
  113499. +public:
  113500. + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
  113501. + unsigned int execute() { return handle_function(); }
  113502. +};
  113503. +}
  113504. +
  113505. +static opt_pass *make_structleak_pass(void)
  113506. +{
  113507. + return new structleak_pass();
  113508. +}
  113509. +#else
  113510. +static struct opt_pass *make_structleak_pass(void)
  113511. +{
  113512. + return &structleak_pass.pass;
  113513. +}
  113514. +#endif
  113515. +
  113516. +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
  113517. +{
  113518. + int i;
  113519. + const char * const plugin_name = plugin_info->base_name;
  113520. + const int argc = plugin_info->argc;
  113521. + const struct plugin_argument * const argv = plugin_info->argv;
  113522. + bool enable = true;
  113523. + struct register_pass_info structleak_pass_info;
  113524. +
  113525. + structleak_pass_info.pass = make_structleak_pass();
  113526. + structleak_pass_info.reference_pass_name = "ssa";
  113527. + structleak_pass_info.ref_pass_instance_number = 1;
  113528. + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
  113529. +
  113530. + if (!plugin_default_version_check(version, &gcc_version)) {
  113531. + error(G_("incompatible gcc/plugin versions"));
  113532. + return 1;
  113533. + }
  113534. +
  113535. + if (strcmp(lang_hooks.name, "GNU C")) {
  113536. + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
  113537. + enable = false;
  113538. + }
  113539. +
  113540. + for (i = 0; i < argc; ++i) {
  113541. + if (!strcmp(argv[i].key, "disable")) {
  113542. + enable = false;
  113543. + continue;
  113544. + }
  113545. + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
  113546. + }
  113547. +
  113548. + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
  113549. + if (enable) {
  113550. + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
  113551. + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
  113552. + }
  113553. + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
  113554. +
  113555. + return 0;
  113556. +}
  113557. diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
  113558. index fbc6665..5e9ce79 100644
  113559. --- a/tools/include/linux/compiler.h
  113560. +++ b/tools/include/linux/compiler.h
  113561. @@ -35,4 +35,12 @@
  113562. # define unlikely(x) __builtin_expect(!!(x), 0)
  113563. #endif
  113564. +#ifndef __size_overflow
  113565. +# define __size_overflow(...)
  113566. +#endif
  113567. +
  113568. +#ifndef __intentional_overflow
  113569. +# define __intentional_overflow(...)
  113570. +#endif
  113571. +
  113572. #endif /* _TOOLS_LINUX_COMPILER_H */
  113573. diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
  113574. index ed2f51e..cc2d8f6 100644
  113575. --- a/tools/lib/api/Makefile
  113576. +++ b/tools/lib/api/Makefile
  113577. @@ -14,7 +14,7 @@ LIB_OBJS += $(OUTPUT)fs/debugfs.o
  113578. LIBFILE = libapikfs.a
  113579. -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
  113580. +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
  113581. EXTLIBS = -lelf -lpthread -lrt -lm
  113582. ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
  113583. ALL_LDFLAGS = $(LDFLAGS)
  113584. diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
  113585. index 6789d78..4afd019e 100644
  113586. --- a/tools/perf/util/include/asm/alternative-asm.h
  113587. +++ b/tools/perf/util/include/asm/alternative-asm.h
  113588. @@ -5,4 +5,7 @@
  113589. #define altinstruction_entry #
  113590. + .macro pax_force_retaddr rip=0, reload=0
  113591. + .endm
  113592. +
  113593. #endif
  113594. diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
  113595. index 03a0381..8b31923 100644
  113596. --- a/virt/kvm/kvm_main.c
  113597. +++ b/virt/kvm/kvm_main.c
  113598. @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
  113599. static cpumask_var_t cpus_hardware_enabled;
  113600. static int kvm_usage_count = 0;
  113601. -static atomic_t hardware_enable_failed;
  113602. +static atomic_unchecked_t hardware_enable_failed;
  113603. struct kmem_cache *kvm_vcpu_cache;
  113604. EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
  113605. -static __read_mostly struct preempt_ops kvm_preempt_ops;
  113606. +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
  113607. +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
  113608. +static struct preempt_ops kvm_preempt_ops = {
  113609. + .sched_in = kvm_sched_in,
  113610. + .sched_out = kvm_sched_out,
  113611. +};
  113612. struct dentry *kvm_debugfs_dir;
  113613. @@ -758,7 +763,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
  113614. /* We can read the guest memory with __xxx_user() later on. */
  113615. if ((mem->slot < KVM_USER_MEM_SLOTS) &&
  113616. ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
  113617. - !access_ok(VERIFY_WRITE,
  113618. + !access_ok_noprefault(VERIFY_WRITE,
  113619. (void __user *)(unsigned long)mem->userspace_addr,
  113620. mem->memory_size)))
  113621. goto out;
  113622. @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
  113623. int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
  113624. {
  113625. - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
  113626. + int r;
  113627. + unsigned long addr;
  113628. - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
  113629. + addr = gfn_to_hva(kvm, gfn);
  113630. + if (kvm_is_error_hva(addr))
  113631. + return -EFAULT;
  113632. + r = __clear_user((void __user *)addr + offset, len);
  113633. + if (r)
  113634. + return -EFAULT;
  113635. + mark_page_dirty(kvm, gfn);
  113636. + return 0;
  113637. }
  113638. EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
  113639. @@ -1867,7 +1880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
  113640. return 0;
  113641. }
  113642. -static struct file_operations kvm_vcpu_fops = {
  113643. +static file_operations_no_const kvm_vcpu_fops __read_only = {
  113644. .release = kvm_vcpu_release,
  113645. .unlocked_ioctl = kvm_vcpu_ioctl,
  113646. #ifdef CONFIG_COMPAT
  113647. @@ -2532,7 +2545,7 @@ out:
  113648. }
  113649. #endif
  113650. -static struct file_operations kvm_vm_fops = {
  113651. +static file_operations_no_const kvm_vm_fops __read_only = {
  113652. .release = kvm_vm_release,
  113653. .unlocked_ioctl = kvm_vm_ioctl,
  113654. #ifdef CONFIG_COMPAT
  113655. @@ -2632,7 +2645,7 @@ out:
  113656. return r;
  113657. }
  113658. -static struct file_operations kvm_chardev_ops = {
  113659. +static file_operations_no_const kvm_chardev_ops __read_only = {
  113660. .unlocked_ioctl = kvm_dev_ioctl,
  113661. .compat_ioctl = kvm_dev_ioctl,
  113662. .llseek = noop_llseek,
  113663. @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
  113664. if (r) {
  113665. cpumask_clear_cpu(cpu, cpus_hardware_enabled);
  113666. - atomic_inc(&hardware_enable_failed);
  113667. + atomic_inc_unchecked(&hardware_enable_failed);
  113668. printk(KERN_INFO "kvm: enabling virtualization on "
  113669. "CPU%d failed\n", cpu);
  113670. }
  113671. @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
  113672. kvm_usage_count++;
  113673. if (kvm_usage_count == 1) {
  113674. - atomic_set(&hardware_enable_failed, 0);
  113675. + atomic_set_unchecked(&hardware_enable_failed, 0);
  113676. on_each_cpu(hardware_enable_nolock, NULL, 1);
  113677. - if (atomic_read(&hardware_enable_failed)) {
  113678. + if (atomic_read_unchecked(&hardware_enable_failed)) {
  113679. hardware_disable_all_nolock();
  113680. r = -EBUSY;
  113681. }
  113682. @@ -3121,7 +3134,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
  113683. kvm_arch_vcpu_put(vcpu);
  113684. }
  113685. -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  113686. +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  113687. struct module *module)
  113688. {
  113689. int r;
  113690. @@ -3168,7 +3181,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  113691. if (!vcpu_align)
  113692. vcpu_align = __alignof__(struct kvm_vcpu);
  113693. kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
  113694. - 0, NULL);
  113695. + SLAB_USERCOPY, NULL);
  113696. if (!kvm_vcpu_cache) {
  113697. r = -ENOMEM;
  113698. goto out_free_3;
  113699. @@ -3178,9 +3191,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  113700. if (r)
  113701. goto out_free;
  113702. + pax_open_kernel();
  113703. kvm_chardev_ops.owner = module;
  113704. kvm_vm_fops.owner = module;
  113705. kvm_vcpu_fops.owner = module;
  113706. + pax_close_kernel();
  113707. r = misc_register(&kvm_dev);
  113708. if (r) {
  113709. @@ -3190,9 +3205,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
  113710. register_syscore_ops(&kvm_syscore_ops);
  113711. - kvm_preempt_ops.sched_in = kvm_sched_in;
  113712. - kvm_preempt_ops.sched_out = kvm_sched_out;
  113713. -
  113714. r = kvm_init_debug();
  113715. if (r) {
  113716. printk(KERN_ERR "kvm: create debugfs files failed\n");