nfs4xdr.c 170 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395
  1. /*
  2. * Server-side XDR for NFSv4
  3. *
  4. * Copyright (c) 2002 The Regents of the University of Michigan.
  5. * All rights reserved.
  6. *
  7. * Kendrick Smith <kmsmith@umich.edu>
  8. * Andy Adamson <andros@umich.edu>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <linux/file.h>
  36. #include <linux/slab.h>
  37. #include <linux/namei.h>
  38. #include <linux/statfs.h>
  39. #include <linux/utsname.h>
  40. #include <linux/pagemap.h>
  41. #include <linux/sunrpc/svcauth_gss.h>
  42. #include <linux/sunrpc/addr.h>
  43. #include <linux/xattr.h>
  44. #include <linux/vmalloc.h>
  45. #include <linux/nfsacl.h>
  46. #include <uapi/linux/xattr.h>
  47. #include "idmap.h"
  48. #include "acl.h"
  49. #include "xdr4.h"
  50. #include "vfs.h"
  51. #include "state.h"
  52. #include "cache.h"
  53. #include "netns.h"
  54. #include "pnfs.h"
  55. #include "filecache.h"
  56. #include "nfs4xdr_gen.h"
  57. #include "trace.h"
  58. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  59. #include <linux/security.h>
  60. #endif
  61. #define NFSDDBG_FACILITY NFSDDBG_XDR
  62. const u32 nfsd_suppattrs[3][3] = {
  63. {NFSD4_SUPPORTED_ATTRS_WORD0,
  64. NFSD4_SUPPORTED_ATTRS_WORD1,
  65. NFSD4_SUPPORTED_ATTRS_WORD2},
  66. {NFSD4_1_SUPPORTED_ATTRS_WORD0,
  67. NFSD4_1_SUPPORTED_ATTRS_WORD1,
  68. NFSD4_1_SUPPORTED_ATTRS_WORD2},
  69. {NFSD4_1_SUPPORTED_ATTRS_WORD0,
  70. NFSD4_1_SUPPORTED_ATTRS_WORD1,
  71. NFSD4_2_SUPPORTED_ATTRS_WORD2},
  72. };
  73. /*
  74. * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
  75. * directory in order to indicate to the client that a filesystem boundary is present
  76. * We use a fixed fsid for a referral
  77. */
  78. #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
  79. #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
  80. static __be32
  81. check_filename(char *str, int len)
  82. {
  83. int i;
  84. if (len == 0)
  85. return nfserr_inval;
  86. if (len > NFS4_MAXNAMLEN)
  87. return nfserr_nametoolong;
  88. if (isdotent(str, len))
  89. return nfserr_badname;
  90. for (i = 0; i < len; i++)
  91. if (str[i] == '/')
  92. return nfserr_badname;
  93. return 0;
  94. }
  95. static int zero_clientid(clientid_t *clid)
  96. {
  97. return (clid->cl_boot == 0) && (clid->cl_id == 0);
  98. }
  99. /**
  100. * svcxdr_tmpalloc - allocate memory to be freed after compound processing
  101. * @argp: NFSv4 compound argument structure
  102. * @len: length of buffer to allocate
  103. *
  104. * Allocates a buffer of size @len to be freed when processing the compound
  105. * operation described in @argp finishes.
  106. */
  107. static void *
  108. svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, size_t len)
  109. {
  110. struct svcxdr_tmpbuf *tb;
  111. tb = kmalloc_flex(*tb, buf, len);
  112. if (!tb)
  113. return NULL;
  114. tb->next = argp->to_free;
  115. argp->to_free = tb;
  116. return tb->buf;
  117. }
  118. /*
  119. * For xdr strings that need to be passed to other kernel api's
  120. * as null-terminated strings.
  121. *
  122. * Note null-terminating in place usually isn't safe since the
  123. * buffer might end on a page boundary.
  124. */
  125. static char *
  126. svcxdr_dupstr(struct nfsd4_compoundargs *argp, void *buf, size_t len)
  127. {
  128. char *p = svcxdr_tmpalloc(argp, size_add(len, 1));
  129. if (!p)
  130. return NULL;
  131. memcpy(p, buf, len);
  132. p[len] = '\0';
  133. return p;
  134. }
  135. static void *
  136. svcxdr_savemem(struct nfsd4_compoundargs *argp, __be32 *p, size_t len)
  137. {
  138. __be32 *tmp;
  139. /*
  140. * The location of the decoded data item is stable,
  141. * so @p is OK to use. This is the common case.
  142. */
  143. if (p != argp->xdr->scratch.iov_base)
  144. return p;
  145. tmp = svcxdr_tmpalloc(argp, len);
  146. if (!tmp)
  147. return NULL;
  148. memcpy(tmp, p, len);
  149. return tmp;
  150. }
  151. /*
  152. * NFSv4 basic data type decoders
  153. */
  154. /*
  155. * This helper handles variable-length opaques which belong to protocol
  156. * elements that this implementation does not support.
  157. */
  158. static __be32
  159. nfsd4_decode_ignored_string(struct nfsd4_compoundargs *argp, u32 maxlen)
  160. {
  161. u32 len;
  162. if (xdr_stream_decode_u32(argp->xdr, &len) < 0)
  163. return nfserr_bad_xdr;
  164. if (maxlen && len > maxlen)
  165. return nfserr_bad_xdr;
  166. if (!xdr_inline_decode(argp->xdr, len))
  167. return nfserr_bad_xdr;
  168. return nfs_ok;
  169. }
  170. static __be32
  171. nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o)
  172. {
  173. __be32 *p;
  174. u32 len;
  175. if (xdr_stream_decode_u32(argp->xdr, &len) < 0)
  176. return nfserr_bad_xdr;
  177. if (len == 0 || len > NFS4_OPAQUE_LIMIT)
  178. return nfserr_bad_xdr;
  179. p = xdr_inline_decode(argp->xdr, len);
  180. if (!p)
  181. return nfserr_bad_xdr;
  182. o->data = svcxdr_savemem(argp, p, len);
  183. if (!o->data)
  184. return nfserr_jukebox;
  185. o->len = len;
  186. return nfs_ok;
  187. }
  188. static __be32
  189. nfsd4_decode_component4(struct nfsd4_compoundargs *argp, char **namp, u32 *lenp)
  190. {
  191. __be32 *p, status;
  192. if (xdr_stream_decode_u32(argp->xdr, lenp) < 0)
  193. return nfserr_bad_xdr;
  194. p = xdr_inline_decode(argp->xdr, *lenp);
  195. if (!p)
  196. return nfserr_bad_xdr;
  197. status = check_filename((char *)p, *lenp);
  198. if (status)
  199. return status;
  200. *namp = svcxdr_savemem(argp, p, *lenp);
  201. if (!*namp)
  202. return nfserr_jukebox;
  203. return nfs_ok;
  204. }
  205. static __be32
  206. nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv)
  207. {
  208. __be32 *p;
  209. p = xdr_inline_decode(argp->xdr, XDR_UNIT * 3);
  210. if (!p)
  211. return nfserr_bad_xdr;
  212. p = xdr_decode_hyper(p, &tv->tv_sec);
  213. tv->tv_nsec = be32_to_cpup(p++);
  214. if (tv->tv_nsec >= (u32)1000000000)
  215. return nfserr_inval;
  216. return nfs_ok;
  217. }
  218. static __be32
  219. nfsd4_decode_verifier4(struct nfsd4_compoundargs *argp, nfs4_verifier *verf)
  220. {
  221. __be32 *p;
  222. p = xdr_inline_decode(argp->xdr, NFS4_VERIFIER_SIZE);
  223. if (!p)
  224. return nfserr_bad_xdr;
  225. memcpy(verf->data, p, sizeof(verf->data));
  226. return nfs_ok;
  227. }
  228. /**
  229. * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4
  230. * @argp: NFSv4 compound argument structure
  231. * @bmval: pointer to an array of u32's to decode into
  232. * @bmlen: size of the @bmval array
  233. *
  234. * The server needs to return nfs_ok rather than nfserr_bad_xdr when
  235. * encountering bitmaps containing bits it does not recognize. This
  236. * includes bits in bitmap words past WORDn, where WORDn is the last
  237. * bitmap WORD the implementation currently supports. Thus we are
  238. * careful here to simply ignore bits in bitmap words that this
  239. * implementation has yet to support explicitly.
  240. *
  241. * Return values:
  242. * %nfs_ok: @bmval populated successfully
  243. * %nfserr_bad_xdr: the encoded bitmap was invalid
  244. */
  245. static __be32
  246. nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen)
  247. {
  248. ssize_t status;
  249. status = xdr_stream_decode_uint32_array(argp->xdr, bmval, bmlen);
  250. return status == -EBADMSG ? nfserr_bad_xdr : nfs_ok;
  251. }
  252. static __be32
  253. nfsd4_decode_nfsace4(struct nfsd4_compoundargs *argp, struct nfs4_ace *ace)
  254. {
  255. __be32 *p, status;
  256. u32 length;
  257. if (xdr_stream_decode_u32(argp->xdr, &ace->type) < 0)
  258. return nfserr_bad_xdr;
  259. if (xdr_stream_decode_u32(argp->xdr, &ace->flag) < 0)
  260. return nfserr_bad_xdr;
  261. if (xdr_stream_decode_u32(argp->xdr, &ace->access_mask) < 0)
  262. return nfserr_bad_xdr;
  263. if (xdr_stream_decode_u32(argp->xdr, &length) < 0)
  264. return nfserr_bad_xdr;
  265. p = xdr_inline_decode(argp->xdr, length);
  266. if (!p)
  267. return nfserr_bad_xdr;
  268. ace->whotype = nfs4_acl_get_whotype((char *)p, length);
  269. if (ace->whotype != NFS4_ACL_WHO_NAMED)
  270. status = nfs_ok;
  271. else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
  272. status = nfsd_map_name_to_gid(argp->rqstp,
  273. (char *)p, length, &ace->who_gid);
  274. else
  275. status = nfsd_map_name_to_uid(argp->rqstp,
  276. (char *)p, length, &ace->who_uid);
  277. return status;
  278. }
  279. /* A counted array of nfsace4's */
  280. static noinline __be32
  281. nfsd4_decode_acl(struct nfsd4_compoundargs *argp, struct nfs4_acl **acl)
  282. {
  283. struct nfs4_ace *ace;
  284. __be32 status;
  285. u32 count;
  286. if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
  287. return nfserr_bad_xdr;
  288. if (count > xdr_stream_remaining(argp->xdr) / 20)
  289. /*
  290. * Even with 4-byte names there wouldn't be
  291. * space for that many aces; something fishy is
  292. * going on:
  293. */
  294. return nfserr_fbig;
  295. *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(count));
  296. if (*acl == NULL)
  297. return nfserr_jukebox;
  298. (*acl)->naces = count;
  299. for (ace = (*acl)->aces; ace < (*acl)->aces + count; ace++) {
  300. status = nfsd4_decode_nfsace4(argp, ace);
  301. if (status)
  302. return status;
  303. }
  304. return nfs_ok;
  305. }
  306. static noinline __be32
  307. nfsd4_decode_security_label(struct nfsd4_compoundargs *argp,
  308. struct xdr_netobj *label)
  309. {
  310. u32 lfs, pi, length;
  311. __be32 *p;
  312. if (xdr_stream_decode_u32(argp->xdr, &lfs) < 0)
  313. return nfserr_bad_xdr;
  314. if (xdr_stream_decode_u32(argp->xdr, &pi) < 0)
  315. return nfserr_bad_xdr;
  316. if (xdr_stream_decode_u32(argp->xdr, &length) < 0)
  317. return nfserr_bad_xdr;
  318. if (length > NFS4_MAXLABELLEN)
  319. return nfserr_badlabel;
  320. p = xdr_inline_decode(argp->xdr, length);
  321. if (!p)
  322. return nfserr_bad_xdr;
  323. label->len = length;
  324. label->data = svcxdr_dupstr(argp, p, length);
  325. if (!label->data)
  326. return nfserr_jukebox;
  327. return nfs_ok;
  328. }
  329. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  330. static short nfsd4_posixacetag4_to_tag(posixacetag4 tag)
  331. {
  332. switch (tag) {
  333. case POSIXACE4_TAG_USER_OBJ: return ACL_USER_OBJ;
  334. case POSIXACE4_TAG_GROUP_OBJ: return ACL_GROUP_OBJ;
  335. case POSIXACE4_TAG_USER: return ACL_USER;
  336. case POSIXACE4_TAG_GROUP: return ACL_GROUP;
  337. case POSIXACE4_TAG_MASK: return ACL_MASK;
  338. case POSIXACE4_TAG_OTHER: return ACL_OTHER;
  339. }
  340. return ACL_OTHER;
  341. }
  342. static __be32
  343. nfsd4_decode_posixace4(struct nfsd4_compoundargs *argp,
  344. struct posix_acl_entry *ace)
  345. {
  346. posixaceperm4 perm;
  347. __be32 *p, status;
  348. posixacetag4 tag;
  349. u32 len;
  350. if (!xdrgen_decode_posixacetag4(argp->xdr, &tag))
  351. return nfserr_bad_xdr;
  352. ace->e_tag = nfsd4_posixacetag4_to_tag(tag);
  353. if (!xdrgen_decode_posixaceperm4(argp->xdr, &perm))
  354. return nfserr_bad_xdr;
  355. if (perm & ~S_IRWXO)
  356. return nfserr_bad_xdr;
  357. ace->e_perm = perm;
  358. if (xdr_stream_decode_u32(argp->xdr, &len) < 0)
  359. return nfserr_bad_xdr;
  360. p = xdr_inline_decode(argp->xdr, len);
  361. if (!p)
  362. return nfserr_bad_xdr;
  363. switch (tag) {
  364. case POSIXACE4_TAG_USER:
  365. if (len > 0)
  366. status = nfsd_map_name_to_uid(argp->rqstp,
  367. (char *)p, len, &ace->e_uid);
  368. else
  369. status = nfserr_bad_xdr;
  370. break;
  371. case POSIXACE4_TAG_GROUP:
  372. if (len > 0)
  373. status = nfsd_map_name_to_gid(argp->rqstp,
  374. (char *)p, len, &ace->e_gid);
  375. else
  376. status = nfserr_bad_xdr;
  377. break;
  378. default:
  379. status = nfs_ok;
  380. }
  381. return status;
  382. }
  383. static noinline __be32
  384. nfsd4_decode_posixacl(struct nfsd4_compoundargs *argp, struct posix_acl **acl)
  385. {
  386. struct posix_acl_entry *ace;
  387. __be32 status;
  388. u32 count;
  389. if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
  390. return nfserr_bad_xdr;
  391. *acl = posix_acl_alloc(count, GFP_KERNEL);
  392. if (*acl == NULL)
  393. return nfserr_resource;
  394. (*acl)->a_count = count;
  395. for (ace = (*acl)->a_entries; ace < (*acl)->a_entries + count; ace++) {
  396. status = nfsd4_decode_posixace4(argp, ace);
  397. if (status) {
  398. posix_acl_release(*acl);
  399. *acl = NULL;
  400. return status;
  401. }
  402. }
  403. /*
  404. * posix_acl_valid() requires the ACEs to be sorted.
  405. * If they are already sorted, sort_pacl_range() will return
  406. * after one pass through the ACEs, since it implements bubble sort.
  407. * Note that a count == 0 is used to delete a POSIX ACL and a count
  408. * of 1 or 2 will always be found invalid by posix_acl_valid().
  409. */
  410. if (count >= 3)
  411. sort_pacl_range(*acl, 0, count - 1);
  412. return nfs_ok;
  413. }
  414. #endif /* CONFIG_NFSD_V4_POSIX_ACLS */
  415. static __be32
  416. nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
  417. struct iattr *iattr, struct nfs4_acl **acl,
  418. struct xdr_netobj *label, int *umask,
  419. struct posix_acl **dpaclp, struct posix_acl **paclp)
  420. {
  421. unsigned int starting_pos;
  422. u32 attrlist4_count;
  423. __be32 *p, status;
  424. iattr->ia_valid = 0;
  425. status = nfsd4_decode_bitmap4(argp, bmval, bmlen);
  426. if (status)
  427. return nfserr_bad_xdr;
  428. if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
  429. || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
  430. || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) {
  431. if (nfsd_attrs_supported(argp->minorversion, bmval))
  432. return nfserr_inval;
  433. return nfserr_attrnotsupp;
  434. }
  435. if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0)
  436. return nfserr_bad_xdr;
  437. starting_pos = xdr_stream_pos(argp->xdr);
  438. if (bmval[0] & FATTR4_WORD0_SIZE) {
  439. u64 size;
  440. if (xdr_stream_decode_u64(argp->xdr, &size) < 0)
  441. return nfserr_bad_xdr;
  442. iattr->ia_size = size;
  443. iattr->ia_valid |= ATTR_SIZE;
  444. }
  445. if (bmval[0] & FATTR4_WORD0_ACL) {
  446. status = nfsd4_decode_acl(argp, acl);
  447. if (status)
  448. return status;
  449. } else
  450. *acl = NULL;
  451. if (bmval[1] & FATTR4_WORD1_MODE) {
  452. u32 mode;
  453. if (xdr_stream_decode_u32(argp->xdr, &mode) < 0)
  454. return nfserr_bad_xdr;
  455. iattr->ia_mode = mode;
  456. iattr->ia_mode &= (S_IFMT | S_IALLUGO);
  457. iattr->ia_valid |= ATTR_MODE;
  458. }
  459. if (bmval[1] & FATTR4_WORD1_OWNER) {
  460. u32 length;
  461. if (xdr_stream_decode_u32(argp->xdr, &length) < 0)
  462. return nfserr_bad_xdr;
  463. p = xdr_inline_decode(argp->xdr, length);
  464. if (!p)
  465. return nfserr_bad_xdr;
  466. status = nfsd_map_name_to_uid(argp->rqstp, (char *)p, length,
  467. &iattr->ia_uid);
  468. if (status)
  469. return status;
  470. iattr->ia_valid |= ATTR_UID;
  471. }
  472. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
  473. u32 length;
  474. if (xdr_stream_decode_u32(argp->xdr, &length) < 0)
  475. return nfserr_bad_xdr;
  476. p = xdr_inline_decode(argp->xdr, length);
  477. if (!p)
  478. return nfserr_bad_xdr;
  479. status = nfsd_map_name_to_gid(argp->rqstp, (char *)p, length,
  480. &iattr->ia_gid);
  481. if (status)
  482. return status;
  483. iattr->ia_valid |= ATTR_GID;
  484. }
  485. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  486. u32 set_it;
  487. if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0)
  488. return nfserr_bad_xdr;
  489. switch (set_it) {
  490. case NFS4_SET_TO_CLIENT_TIME:
  491. status = nfsd4_decode_nfstime4(argp, &iattr->ia_atime);
  492. if (status)
  493. return status;
  494. iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
  495. break;
  496. case NFS4_SET_TO_SERVER_TIME:
  497. iattr->ia_valid |= ATTR_ATIME;
  498. break;
  499. default:
  500. return nfserr_bad_xdr;
  501. }
  502. }
  503. if (bmval[1] & FATTR4_WORD1_TIME_CREATE) {
  504. struct timespec64 ts;
  505. /* No Linux filesystem supports setting this attribute. */
  506. bmval[1] &= ~FATTR4_WORD1_TIME_CREATE;
  507. status = nfsd4_decode_nfstime4(argp, &ts);
  508. if (status)
  509. return status;
  510. }
  511. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  512. u32 set_it;
  513. if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0)
  514. return nfserr_bad_xdr;
  515. switch (set_it) {
  516. case NFS4_SET_TO_CLIENT_TIME:
  517. status = nfsd4_decode_nfstime4(argp, &iattr->ia_mtime);
  518. if (status)
  519. return status;
  520. iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
  521. break;
  522. case NFS4_SET_TO_SERVER_TIME:
  523. iattr->ia_valid |= ATTR_MTIME;
  524. break;
  525. default:
  526. return nfserr_bad_xdr;
  527. }
  528. }
  529. label->len = 0;
  530. if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) &&
  531. bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
  532. status = nfsd4_decode_security_label(argp, label);
  533. if (status)
  534. return status;
  535. }
  536. if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
  537. u32 mode, mask;
  538. if (!umask)
  539. return nfserr_bad_xdr;
  540. if (xdr_stream_decode_u32(argp->xdr, &mode) < 0)
  541. return nfserr_bad_xdr;
  542. iattr->ia_mode = mode & (S_IFMT | S_IALLUGO);
  543. if (xdr_stream_decode_u32(argp->xdr, &mask) < 0)
  544. return nfserr_bad_xdr;
  545. *umask = mask & S_IRWXUGO;
  546. iattr->ia_valid |= ATTR_MODE;
  547. }
  548. if (bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) {
  549. fattr4_time_deleg_access access;
  550. if (!xdrgen_decode_fattr4_time_deleg_access(argp->xdr, &access))
  551. return nfserr_bad_xdr;
  552. iattr->ia_atime.tv_sec = access.seconds;
  553. iattr->ia_atime.tv_nsec = access.nseconds;
  554. iattr->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET | ATTR_DELEG;
  555. }
  556. if (bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) {
  557. fattr4_time_deleg_modify modify;
  558. if (!xdrgen_decode_fattr4_time_deleg_modify(argp->xdr, &modify))
  559. return nfserr_bad_xdr;
  560. iattr->ia_mtime.tv_sec = modify.seconds;
  561. iattr->ia_mtime.tv_nsec = modify.nseconds;
  562. iattr->ia_ctime.tv_sec = modify.seconds;
  563. iattr->ia_ctime.tv_nsec = modify.nseconds;
  564. iattr->ia_valid |= ATTR_CTIME | ATTR_CTIME_SET |
  565. ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG;
  566. }
  567. *dpaclp = NULL;
  568. *paclp = NULL;
  569. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  570. if (bmval[2] & FATTR4_WORD2_POSIX_DEFAULT_ACL) {
  571. struct posix_acl *dpacl;
  572. status = nfsd4_decode_posixacl(argp, &dpacl);
  573. if (status)
  574. return status;
  575. *dpaclp = dpacl;
  576. }
  577. if (bmval[2] & FATTR4_WORD2_POSIX_ACCESS_ACL) {
  578. struct posix_acl *pacl;
  579. status = nfsd4_decode_posixacl(argp, &pacl);
  580. if (status) {
  581. posix_acl_release(*dpaclp);
  582. *dpaclp = NULL;
  583. return status;
  584. }
  585. *paclp = pacl;
  586. }
  587. #endif /* CONFIG_NFSD_V4_POSIX_ACLS */
  588. /* request sanity: did attrlist4 contain the expected number of words? */
  589. if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos) {
  590. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  591. posix_acl_release(*dpaclp);
  592. posix_acl_release(*paclp);
  593. *dpaclp = NULL;
  594. *paclp = NULL;
  595. #endif
  596. return nfserr_bad_xdr;
  597. }
  598. return nfs_ok;
  599. }
  600. static __be32
  601. nfsd4_decode_stateid4(struct nfsd4_compoundargs *argp, stateid_t *sid)
  602. {
  603. __be32 *p;
  604. p = xdr_inline_decode(argp->xdr, NFS4_STATEID_SIZE);
  605. if (!p)
  606. return nfserr_bad_xdr;
  607. sid->si_generation = be32_to_cpup(p++);
  608. memcpy(&sid->si_opaque, p, sizeof(sid->si_opaque));
  609. return nfs_ok;
  610. }
  611. static __be32
  612. nfsd4_decode_clientid4(struct nfsd4_compoundargs *argp, clientid_t *clientid)
  613. {
  614. __be32 *p;
  615. p = xdr_inline_decode(argp->xdr, sizeof(__be64));
  616. if (!p)
  617. return nfserr_bad_xdr;
  618. memcpy(clientid, p, sizeof(*clientid));
  619. return nfs_ok;
  620. }
  621. static __be32
  622. nfsd4_decode_state_owner4(struct nfsd4_compoundargs *argp,
  623. clientid_t *clientid, struct xdr_netobj *owner)
  624. {
  625. __be32 status;
  626. status = nfsd4_decode_clientid4(argp, clientid);
  627. if (status)
  628. return status;
  629. return nfsd4_decode_opaque(argp, owner);
  630. }
  631. #ifdef CONFIG_NFSD_PNFS
  632. static __be32
  633. nfsd4_decode_layoutupdate4(struct nfsd4_compoundargs *argp,
  634. struct nfsd4_layoutcommit *lcp)
  635. {
  636. u32 len;
  637. if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_layout_type) < 0)
  638. return nfserr_bad_xdr;
  639. if (lcp->lc_layout_type < LAYOUT_NFSV4_1_FILES)
  640. return nfserr_bad_xdr;
  641. if (lcp->lc_layout_type >= LAYOUT_TYPE_MAX)
  642. return nfserr_bad_xdr;
  643. if (xdr_stream_decode_u32(argp->xdr, &len) < 0)
  644. return nfserr_bad_xdr;
  645. if (!xdr_stream_subsegment(argp->xdr, &lcp->lc_up_layout, len))
  646. return nfserr_bad_xdr;
  647. return nfs_ok;
  648. }
  649. static __be32
  650. nfsd4_decode_layoutreturn4(struct nfsd4_compoundargs *argp,
  651. struct nfsd4_layoutreturn *lrp)
  652. {
  653. __be32 status;
  654. if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_return_type) < 0)
  655. return nfserr_bad_xdr;
  656. switch (lrp->lr_return_type) {
  657. case RETURN_FILE:
  658. if (xdr_stream_decode_u64(argp->xdr, &lrp->lr_seg.offset) < 0)
  659. return nfserr_bad_xdr;
  660. if (xdr_stream_decode_u64(argp->xdr, &lrp->lr_seg.length) < 0)
  661. return nfserr_bad_xdr;
  662. status = nfsd4_decode_stateid4(argp, &lrp->lr_sid);
  663. if (status)
  664. return status;
  665. if (xdr_stream_decode_u32(argp->xdr, &lrp->lrf_body_len) < 0)
  666. return nfserr_bad_xdr;
  667. if (lrp->lrf_body_len > 0) {
  668. lrp->lrf_body = xdr_inline_decode(argp->xdr, lrp->lrf_body_len);
  669. if (!lrp->lrf_body)
  670. return nfserr_bad_xdr;
  671. }
  672. break;
  673. case RETURN_FSID:
  674. case RETURN_ALL:
  675. lrp->lr_seg.offset = 0;
  676. lrp->lr_seg.length = NFS4_MAX_UINT64;
  677. break;
  678. default:
  679. return nfserr_bad_xdr;
  680. }
  681. return nfs_ok;
  682. }
  683. #endif /* CONFIG_NFSD_PNFS */
  684. static __be32
  685. nfsd4_decode_sessionid4(struct nfsd4_compoundargs *argp,
  686. struct nfs4_sessionid *sessionid)
  687. {
  688. __be32 *p;
  689. p = xdr_inline_decode(argp->xdr, NFS4_MAX_SESSIONID_LEN);
  690. if (!p)
  691. return nfserr_bad_xdr;
  692. memcpy(sessionid->data, p, sizeof(sessionid->data));
  693. return nfs_ok;
  694. }
  695. /* Defined in Appendix A of RFC 5531 */
  696. static __be32
  697. nfsd4_decode_authsys_parms(struct nfsd4_compoundargs *argp,
  698. struct nfsd4_cb_sec *cbs)
  699. {
  700. u32 stamp, gidcount, uid, gid;
  701. __be32 *p, status;
  702. if (xdr_stream_decode_u32(argp->xdr, &stamp) < 0)
  703. return nfserr_bad_xdr;
  704. /* machine name */
  705. status = nfsd4_decode_ignored_string(argp, 255);
  706. if (status)
  707. return status;
  708. if (xdr_stream_decode_u32(argp->xdr, &uid) < 0)
  709. return nfserr_bad_xdr;
  710. if (xdr_stream_decode_u32(argp->xdr, &gid) < 0)
  711. return nfserr_bad_xdr;
  712. if (xdr_stream_decode_u32(argp->xdr, &gidcount) < 0)
  713. return nfserr_bad_xdr;
  714. if (gidcount > 16)
  715. return nfserr_bad_xdr;
  716. p = xdr_inline_decode(argp->xdr, gidcount << 2);
  717. if (!p)
  718. return nfserr_bad_xdr;
  719. if (cbs->flavor == (u32)(-1)) {
  720. struct user_namespace *userns = nfsd_user_namespace(argp->rqstp);
  721. kuid_t kuid = make_kuid(userns, uid);
  722. kgid_t kgid = make_kgid(userns, gid);
  723. if (uid_valid(kuid) && gid_valid(kgid)) {
  724. cbs->uid = kuid;
  725. cbs->gid = kgid;
  726. cbs->flavor = RPC_AUTH_UNIX;
  727. } else {
  728. dprintk("RPC_AUTH_UNIX with invalid uid or gid, ignoring!\n");
  729. }
  730. }
  731. return nfs_ok;
  732. }
  733. static __be32
  734. nfsd4_decode_gss_cb_handles4(struct nfsd4_compoundargs *argp,
  735. struct nfsd4_cb_sec *cbs)
  736. {
  737. __be32 status;
  738. u32 service;
  739. dprintk("RPC_AUTH_GSS callback secflavor not supported!\n");
  740. if (xdr_stream_decode_u32(argp->xdr, &service) < 0)
  741. return nfserr_bad_xdr;
  742. if (service < RPC_GSS_SVC_NONE || service > RPC_GSS_SVC_PRIVACY)
  743. return nfserr_bad_xdr;
  744. /* gcbp_handle_from_server */
  745. status = nfsd4_decode_ignored_string(argp, 0);
  746. if (status)
  747. return status;
  748. /* gcbp_handle_from_client */
  749. status = nfsd4_decode_ignored_string(argp, 0);
  750. if (status)
  751. return status;
  752. return nfs_ok;
  753. }
  754. /* a counted array of callback_sec_parms4 items */
  755. static __be32
  756. nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs)
  757. {
  758. u32 i, secflavor, nr_secflavs;
  759. __be32 status;
  760. /* callback_sec_params4 */
  761. if (xdr_stream_decode_u32(argp->xdr, &nr_secflavs) < 0)
  762. return nfserr_bad_xdr;
  763. if (nr_secflavs)
  764. cbs->flavor = (u32)(-1);
  765. else
  766. /* Is this legal? Be generous, take it to mean AUTH_NONE: */
  767. cbs->flavor = 0;
  768. for (i = 0; i < nr_secflavs; ++i) {
  769. if (xdr_stream_decode_u32(argp->xdr, &secflavor) < 0)
  770. return nfserr_bad_xdr;
  771. switch (secflavor) {
  772. case RPC_AUTH_NULL:
  773. /* void */
  774. if (cbs->flavor == (u32)(-1))
  775. cbs->flavor = RPC_AUTH_NULL;
  776. break;
  777. case RPC_AUTH_UNIX:
  778. status = nfsd4_decode_authsys_parms(argp, cbs);
  779. if (status)
  780. return status;
  781. break;
  782. case RPC_AUTH_GSS:
  783. status = nfsd4_decode_gss_cb_handles4(argp, cbs);
  784. if (status)
  785. return status;
  786. break;
  787. default:
  788. return nfserr_inval;
  789. }
  790. }
  791. return nfs_ok;
  792. }
  793. /*
  794. * NFSv4 operation argument decoders
  795. */
  796. static __be32
  797. nfsd4_decode_access(struct nfsd4_compoundargs *argp,
  798. union nfsd4_op_u *u)
  799. {
  800. struct nfsd4_access *access = &u->access;
  801. if (xdr_stream_decode_u32(argp->xdr, &access->ac_req_access) < 0)
  802. return nfserr_bad_xdr;
  803. return nfs_ok;
  804. }
  805. static __be32
  806. nfsd4_decode_close(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  807. {
  808. struct nfsd4_close *close = &u->close;
  809. if (xdr_stream_decode_u32(argp->xdr, &close->cl_seqid) < 0)
  810. return nfserr_bad_xdr;
  811. return nfsd4_decode_stateid4(argp, &close->cl_stateid);
  812. }
  813. static __be32
  814. nfsd4_decode_commit(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  815. {
  816. struct nfsd4_commit *commit = &u->commit;
  817. if (xdr_stream_decode_u64(argp->xdr, &commit->co_offset) < 0)
  818. return nfserr_bad_xdr;
  819. if (xdr_stream_decode_u32(argp->xdr, &commit->co_count) < 0)
  820. return nfserr_bad_xdr;
  821. memset(&commit->co_verf, 0, sizeof(commit->co_verf));
  822. return nfs_ok;
  823. }
  824. static __be32
  825. nfsd4_decode_create(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  826. {
  827. struct nfsd4_create *create = &u->create;
  828. __be32 *p, status;
  829. memset(create, 0, sizeof(*create));
  830. if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0)
  831. return nfserr_bad_xdr;
  832. switch (create->cr_type) {
  833. case NF4LNK:
  834. if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0)
  835. return nfserr_bad_xdr;
  836. p = xdr_inline_decode(argp->xdr, create->cr_datalen);
  837. if (!p)
  838. return nfserr_bad_xdr;
  839. create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen);
  840. if (!create->cr_data)
  841. return nfserr_jukebox;
  842. break;
  843. case NF4BLK:
  844. case NF4CHR:
  845. if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0)
  846. return nfserr_bad_xdr;
  847. if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0)
  848. return nfserr_bad_xdr;
  849. break;
  850. case NF4SOCK:
  851. case NF4FIFO:
  852. case NF4DIR:
  853. default:
  854. break;
  855. }
  856. status = nfsd4_decode_component4(argp, &create->cr_name,
  857. &create->cr_namelen);
  858. if (status)
  859. return status;
  860. status = nfsd4_decode_fattr4(argp, create->cr_bmval,
  861. ARRAY_SIZE(create->cr_bmval),
  862. &create->cr_iattr, &create->cr_acl,
  863. &create->cr_label, &create->cr_umask,
  864. &create->cr_dpacl, &create->cr_pacl);
  865. if (status)
  866. return status;
  867. return nfs_ok;
  868. }
  869. static inline __be32
  870. nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  871. {
  872. struct nfsd4_delegreturn *dr = &u->delegreturn;
  873. return nfsd4_decode_stateid4(argp, &dr->dr_stateid);
  874. }
  875. static inline __be32
  876. nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  877. {
  878. struct nfsd4_getattr *getattr = &u->getattr;
  879. memset(getattr, 0, sizeof(*getattr));
  880. return nfsd4_decode_bitmap4(argp, getattr->ga_bmval,
  881. ARRAY_SIZE(getattr->ga_bmval));
  882. }
  883. static __be32
  884. nfsd4_decode_link(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  885. {
  886. struct nfsd4_link *link = &u->link;
  887. memset(link, 0, sizeof(*link));
  888. return nfsd4_decode_component4(argp, &link->li_name, &link->li_namelen);
  889. }
  890. static __be32
  891. nfsd4_decode_open_to_lock_owner4(struct nfsd4_compoundargs *argp,
  892. struct nfsd4_lock *lock)
  893. {
  894. __be32 status;
  895. if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_open_seqid) < 0)
  896. return nfserr_bad_xdr;
  897. status = nfsd4_decode_stateid4(argp, &lock->lk_new_open_stateid);
  898. if (status)
  899. return status;
  900. if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_lock_seqid) < 0)
  901. return nfserr_bad_xdr;
  902. return nfsd4_decode_state_owner4(argp, &lock->lk_new_clientid,
  903. &lock->lk_new_owner);
  904. }
  905. static __be32
  906. nfsd4_decode_exist_lock_owner4(struct nfsd4_compoundargs *argp,
  907. struct nfsd4_lock *lock)
  908. {
  909. __be32 status;
  910. status = nfsd4_decode_stateid4(argp, &lock->lk_old_lock_stateid);
  911. if (status)
  912. return status;
  913. if (xdr_stream_decode_u32(argp->xdr, &lock->lk_old_lock_seqid) < 0)
  914. return nfserr_bad_xdr;
  915. return nfs_ok;
  916. }
  917. static __be32
  918. nfsd4_decode_locker4(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
  919. {
  920. if (xdr_stream_decode_bool(argp->xdr, &lock->lk_is_new) < 0)
  921. return nfserr_bad_xdr;
  922. if (lock->lk_is_new)
  923. return nfsd4_decode_open_to_lock_owner4(argp, lock);
  924. return nfsd4_decode_exist_lock_owner4(argp, lock);
  925. }
  926. static __be32
  927. nfsd4_decode_lock(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  928. {
  929. struct nfsd4_lock *lock = &u->lock;
  930. memset(lock, 0, sizeof(*lock));
  931. if (xdr_stream_decode_u32(argp->xdr, &lock->lk_type) < 0)
  932. return nfserr_bad_xdr;
  933. if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
  934. return nfserr_bad_xdr;
  935. if (xdr_stream_decode_bool(argp->xdr, &lock->lk_reclaim) < 0)
  936. return nfserr_bad_xdr;
  937. if (xdr_stream_decode_u64(argp->xdr, &lock->lk_offset) < 0)
  938. return nfserr_bad_xdr;
  939. if (xdr_stream_decode_u64(argp->xdr, &lock->lk_length) < 0)
  940. return nfserr_bad_xdr;
  941. return nfsd4_decode_locker4(argp, lock);
  942. }
  943. static __be32
  944. nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  945. {
  946. struct nfsd4_lockt *lockt = &u->lockt;
  947. memset(lockt, 0, sizeof(*lockt));
  948. if (xdr_stream_decode_u32(argp->xdr, &lockt->lt_type) < 0)
  949. return nfserr_bad_xdr;
  950. if ((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
  951. return nfserr_bad_xdr;
  952. if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_offset) < 0)
  953. return nfserr_bad_xdr;
  954. if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_length) < 0)
  955. return nfserr_bad_xdr;
  956. return nfsd4_decode_state_owner4(argp, &lockt->lt_clientid,
  957. &lockt->lt_owner);
  958. }
  959. static __be32
  960. nfsd4_decode_locku(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  961. {
  962. struct nfsd4_locku *locku = &u->locku;
  963. __be32 status;
  964. if (xdr_stream_decode_u32(argp->xdr, &locku->lu_type) < 0)
  965. return nfserr_bad_xdr;
  966. if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
  967. return nfserr_bad_xdr;
  968. if (xdr_stream_decode_u32(argp->xdr, &locku->lu_seqid) < 0)
  969. return nfserr_bad_xdr;
  970. status = nfsd4_decode_stateid4(argp, &locku->lu_stateid);
  971. if (status)
  972. return status;
  973. if (xdr_stream_decode_u64(argp->xdr, &locku->lu_offset) < 0)
  974. return nfserr_bad_xdr;
  975. if (xdr_stream_decode_u64(argp->xdr, &locku->lu_length) < 0)
  976. return nfserr_bad_xdr;
  977. return nfs_ok;
  978. }
  979. static __be32
  980. nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  981. {
  982. struct nfsd4_lookup *lookup = &u->lookup;
  983. return nfsd4_decode_component4(argp, &lookup->lo_name, &lookup->lo_len);
  984. }
  985. static __be32
  986. nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
  987. {
  988. __be32 status;
  989. if (xdr_stream_decode_u32(argp->xdr, &open->op_createmode) < 0)
  990. return nfserr_bad_xdr;
  991. switch (open->op_createmode) {
  992. case NFS4_CREATE_UNCHECKED:
  993. case NFS4_CREATE_GUARDED:
  994. status = nfsd4_decode_fattr4(argp, open->op_bmval,
  995. ARRAY_SIZE(open->op_bmval),
  996. &open->op_iattr, &open->op_acl,
  997. &open->op_label, &open->op_umask,
  998. &open->op_dpacl, &open->op_pacl);
  999. if (status)
  1000. return status;
  1001. break;
  1002. case NFS4_CREATE_EXCLUSIVE:
  1003. status = nfsd4_decode_verifier4(argp, &open->op_verf);
  1004. if (status)
  1005. return status;
  1006. break;
  1007. case NFS4_CREATE_EXCLUSIVE4_1:
  1008. if (argp->minorversion < 1)
  1009. return nfserr_bad_xdr;
  1010. status = nfsd4_decode_verifier4(argp, &open->op_verf);
  1011. if (status)
  1012. return status;
  1013. status = nfsd4_decode_fattr4(argp, open->op_bmval,
  1014. ARRAY_SIZE(open->op_bmval),
  1015. &open->op_iattr, &open->op_acl,
  1016. &open->op_label, &open->op_umask,
  1017. &open->op_dpacl, &open->op_pacl);
  1018. if (status)
  1019. return status;
  1020. break;
  1021. default:
  1022. return nfserr_bad_xdr;
  1023. }
  1024. return nfs_ok;
  1025. }
  1026. static __be32
  1027. nfsd4_decode_openflag4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
  1028. {
  1029. __be32 status;
  1030. if (xdr_stream_decode_u32(argp->xdr, &open->op_create) < 0)
  1031. return nfserr_bad_xdr;
  1032. switch (open->op_create) {
  1033. case NFS4_OPEN_NOCREATE:
  1034. break;
  1035. case NFS4_OPEN_CREATE:
  1036. status = nfsd4_decode_createhow4(argp, open);
  1037. if (status)
  1038. return status;
  1039. break;
  1040. default:
  1041. return nfserr_bad_xdr;
  1042. }
  1043. return nfs_ok;
  1044. }
  1045. static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when)
  1046. {
  1047. u32 w;
  1048. if (xdr_stream_decode_u32(argp->xdr, &w) < 0)
  1049. return nfserr_bad_xdr;
  1050. *share_access = w & NFS4_SHARE_ACCESS_MASK;
  1051. *deleg_want = w & NFS4_SHARE_WANT_MASK;
  1052. if (deleg_when)
  1053. *deleg_when = w & NFS4_SHARE_WHEN_MASK;
  1054. switch (w & NFS4_SHARE_ACCESS_MASK) {
  1055. case NFS4_SHARE_ACCESS_READ:
  1056. case NFS4_SHARE_ACCESS_WRITE:
  1057. case NFS4_SHARE_ACCESS_BOTH:
  1058. break;
  1059. default:
  1060. return nfserr_bad_xdr;
  1061. }
  1062. w &= ~NFS4_SHARE_ACCESS_MASK;
  1063. if (!w)
  1064. return nfs_ok;
  1065. if (!argp->minorversion)
  1066. return nfserr_bad_xdr;
  1067. switch (w & NFS4_SHARE_WANT_TYPE_MASK) {
  1068. case OPEN4_SHARE_ACCESS_WANT_NO_PREFERENCE:
  1069. case OPEN4_SHARE_ACCESS_WANT_READ_DELEG:
  1070. case OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG:
  1071. case OPEN4_SHARE_ACCESS_WANT_ANY_DELEG:
  1072. case OPEN4_SHARE_ACCESS_WANT_NO_DELEG:
  1073. case OPEN4_SHARE_ACCESS_WANT_CANCEL:
  1074. break;
  1075. default:
  1076. return nfserr_bad_xdr;
  1077. }
  1078. w &= ~NFS4_SHARE_WANT_MASK;
  1079. if (!w)
  1080. return nfs_ok;
  1081. if (!deleg_when) /* open_downgrade */
  1082. return nfserr_inval;
  1083. switch (w) {
  1084. case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL:
  1085. case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED:
  1086. case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL |
  1087. NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED):
  1088. return nfs_ok;
  1089. }
  1090. return nfserr_bad_xdr;
  1091. }
  1092. static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x)
  1093. {
  1094. if (xdr_stream_decode_u32(argp->xdr, x) < 0)
  1095. return nfserr_bad_xdr;
  1096. /* Note: unlike access bits, deny bits may be zero. */
  1097. if (*x & ~NFS4_SHARE_DENY_BOTH)
  1098. return nfserr_bad_xdr;
  1099. return nfs_ok;
  1100. }
  1101. static __be32
  1102. nfsd4_decode_open_claim4(struct nfsd4_compoundargs *argp,
  1103. struct nfsd4_open *open)
  1104. {
  1105. __be32 status;
  1106. if (xdr_stream_decode_u32(argp->xdr, &open->op_claim_type) < 0)
  1107. return nfserr_bad_xdr;
  1108. switch (open->op_claim_type) {
  1109. case NFS4_OPEN_CLAIM_NULL:
  1110. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  1111. status = nfsd4_decode_component4(argp, &open->op_fname,
  1112. &open->op_fnamelen);
  1113. if (status)
  1114. return status;
  1115. break;
  1116. case NFS4_OPEN_CLAIM_PREVIOUS:
  1117. if (xdr_stream_decode_u32(argp->xdr, &open->op_delegate_type) < 0)
  1118. return nfserr_bad_xdr;
  1119. break;
  1120. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  1121. status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid);
  1122. if (status)
  1123. return status;
  1124. status = nfsd4_decode_component4(argp, &open->op_fname,
  1125. &open->op_fnamelen);
  1126. if (status)
  1127. return status;
  1128. break;
  1129. case NFS4_OPEN_CLAIM_FH:
  1130. case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
  1131. if (argp->minorversion < 1)
  1132. return nfserr_bad_xdr;
  1133. /* void */
  1134. break;
  1135. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  1136. if (argp->minorversion < 1)
  1137. return nfserr_bad_xdr;
  1138. status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid);
  1139. if (status)
  1140. return status;
  1141. break;
  1142. default:
  1143. return nfserr_bad_xdr;
  1144. }
  1145. return nfs_ok;
  1146. }
  1147. static __be32
  1148. nfsd4_decode_open(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1149. {
  1150. struct nfsd4_open *open = &u->open;
  1151. __be32 status;
  1152. u32 dummy;
  1153. memset(open, 0, sizeof(*open));
  1154. if (xdr_stream_decode_u32(argp->xdr, &open->op_seqid) < 0)
  1155. return nfserr_bad_xdr;
  1156. /* deleg_want is ignored */
  1157. status = nfsd4_decode_share_access(argp, &open->op_share_access,
  1158. &open->op_deleg_want, &dummy);
  1159. if (status)
  1160. return status;
  1161. status = nfsd4_decode_share_deny(argp, &open->op_share_deny);
  1162. if (status)
  1163. return status;
  1164. status = nfsd4_decode_state_owner4(argp, &open->op_clientid,
  1165. &open->op_owner);
  1166. if (status)
  1167. return status;
  1168. status = nfsd4_decode_openflag4(argp, open);
  1169. if (status)
  1170. return status;
  1171. return nfsd4_decode_open_claim4(argp, open);
  1172. }
  1173. static __be32
  1174. nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp,
  1175. union nfsd4_op_u *u)
  1176. {
  1177. struct nfsd4_open_confirm *open_conf = &u->open_confirm;
  1178. __be32 status;
  1179. if (argp->minorversion >= 1)
  1180. return nfserr_notsupp;
  1181. status = nfsd4_decode_stateid4(argp, &open_conf->oc_req_stateid);
  1182. if (status)
  1183. return status;
  1184. if (xdr_stream_decode_u32(argp->xdr, &open_conf->oc_seqid) < 0)
  1185. return nfserr_bad_xdr;
  1186. memset(&open_conf->oc_resp_stateid, 0,
  1187. sizeof(open_conf->oc_resp_stateid));
  1188. return nfs_ok;
  1189. }
  1190. static __be32
  1191. nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp,
  1192. union nfsd4_op_u *u)
  1193. {
  1194. struct nfsd4_open_downgrade *open_down = &u->open_downgrade;
  1195. __be32 status;
  1196. memset(open_down, 0, sizeof(*open_down));
  1197. status = nfsd4_decode_stateid4(argp, &open_down->od_stateid);
  1198. if (status)
  1199. return status;
  1200. if (xdr_stream_decode_u32(argp->xdr, &open_down->od_seqid) < 0)
  1201. return nfserr_bad_xdr;
  1202. /* deleg_want is ignored */
  1203. status = nfsd4_decode_share_access(argp, &open_down->od_share_access,
  1204. &open_down->od_deleg_want, NULL);
  1205. if (status)
  1206. return status;
  1207. return nfsd4_decode_share_deny(argp, &open_down->od_share_deny);
  1208. }
  1209. static __be32
  1210. nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1211. {
  1212. struct nfsd4_putfh *putfh = &u->putfh;
  1213. __be32 *p;
  1214. if (xdr_stream_decode_u32(argp->xdr, &putfh->pf_fhlen) < 0)
  1215. return nfserr_bad_xdr;
  1216. if (putfh->pf_fhlen > NFS4_FHSIZE)
  1217. return nfserr_bad_xdr;
  1218. p = xdr_inline_decode(argp->xdr, putfh->pf_fhlen);
  1219. if (!p)
  1220. return nfserr_bad_xdr;
  1221. putfh->pf_fhval = svcxdr_savemem(argp, p, putfh->pf_fhlen);
  1222. if (!putfh->pf_fhval)
  1223. return nfserr_jukebox;
  1224. putfh->no_verify = false;
  1225. return nfs_ok;
  1226. }
  1227. static __be32
  1228. nfsd4_decode_read(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1229. {
  1230. struct nfsd4_read *read = &u->read;
  1231. __be32 status;
  1232. memset(read, 0, sizeof(*read));
  1233. status = nfsd4_decode_stateid4(argp, &read->rd_stateid);
  1234. if (status)
  1235. return status;
  1236. if (xdr_stream_decode_u64(argp->xdr, &read->rd_offset) < 0)
  1237. return nfserr_bad_xdr;
  1238. if (xdr_stream_decode_u32(argp->xdr, &read->rd_length) < 0)
  1239. return nfserr_bad_xdr;
  1240. return nfs_ok;
  1241. }
  1242. static __be32
  1243. nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1244. {
  1245. struct nfsd4_readdir *readdir = &u->readdir;
  1246. __be32 status;
  1247. memset(readdir, 0, sizeof(*readdir));
  1248. if (xdr_stream_decode_u64(argp->xdr, &readdir->rd_cookie) < 0)
  1249. return nfserr_bad_xdr;
  1250. status = nfsd4_decode_verifier4(argp, &readdir->rd_verf);
  1251. if (status)
  1252. return status;
  1253. if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_dircount) < 0)
  1254. return nfserr_bad_xdr;
  1255. if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_maxcount) < 0)
  1256. return nfserr_bad_xdr;
  1257. if (xdr_stream_decode_uint32_array(argp->xdr, readdir->rd_bmval,
  1258. ARRAY_SIZE(readdir->rd_bmval)) < 0)
  1259. return nfserr_bad_xdr;
  1260. return nfs_ok;
  1261. }
  1262. static __be32
  1263. nfsd4_decode_remove(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1264. {
  1265. struct nfsd4_remove *remove = &u->remove;
  1266. memset(&remove->rm_cinfo, 0, sizeof(remove->rm_cinfo));
  1267. return nfsd4_decode_component4(argp, &remove->rm_name, &remove->rm_namelen);
  1268. }
  1269. static __be32
  1270. nfsd4_decode_rename(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1271. {
  1272. struct nfsd4_rename *rename = &u->rename;
  1273. __be32 status;
  1274. memset(rename, 0, sizeof(*rename));
  1275. status = nfsd4_decode_component4(argp, &rename->rn_sname, &rename->rn_snamelen);
  1276. if (status)
  1277. return status;
  1278. return nfsd4_decode_component4(argp, &rename->rn_tname, &rename->rn_tnamelen);
  1279. }
  1280. static __be32
  1281. nfsd4_decode_renew(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1282. {
  1283. clientid_t *clientid = &u->renew;
  1284. return nfsd4_decode_clientid4(argp, clientid);
  1285. }
  1286. static __be32
  1287. nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
  1288. union nfsd4_op_u *u)
  1289. {
  1290. struct nfsd4_secinfo *secinfo = &u->secinfo;
  1291. secinfo->si_exp = NULL;
  1292. return nfsd4_decode_component4(argp, &secinfo->si_name, &secinfo->si_namelen);
  1293. }
  1294. static __be32
  1295. nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1296. {
  1297. struct nfsd4_setattr *setattr = &u->setattr;
  1298. __be32 status;
  1299. memset(setattr, 0, sizeof(*setattr));
  1300. status = nfsd4_decode_stateid4(argp, &setattr->sa_stateid);
  1301. if (status)
  1302. return status;
  1303. return nfsd4_decode_fattr4(argp, setattr->sa_bmval,
  1304. ARRAY_SIZE(setattr->sa_bmval),
  1305. &setattr->sa_iattr, &setattr->sa_acl,
  1306. &setattr->sa_label, NULL, &setattr->sa_dpacl,
  1307. &setattr->sa_pacl);
  1308. }
  1309. static __be32
  1310. nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1311. {
  1312. struct nfsd4_setclientid *setclientid = &u->setclientid;
  1313. __be32 *p, status;
  1314. memset(setclientid, 0, sizeof(*setclientid));
  1315. if (argp->minorversion >= 1)
  1316. return nfserr_notsupp;
  1317. status = nfsd4_decode_verifier4(argp, &setclientid->se_verf);
  1318. if (status)
  1319. return status;
  1320. status = nfsd4_decode_opaque(argp, &setclientid->se_name);
  1321. if (status)
  1322. return status;
  1323. if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_prog) < 0)
  1324. return nfserr_bad_xdr;
  1325. if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_netid_len) < 0)
  1326. return nfserr_bad_xdr;
  1327. p = xdr_inline_decode(argp->xdr, setclientid->se_callback_netid_len);
  1328. if (!p)
  1329. return nfserr_bad_xdr;
  1330. setclientid->se_callback_netid_val = svcxdr_savemem(argp, p,
  1331. setclientid->se_callback_netid_len);
  1332. if (!setclientid->se_callback_netid_val)
  1333. return nfserr_jukebox;
  1334. if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_addr_len) < 0)
  1335. return nfserr_bad_xdr;
  1336. p = xdr_inline_decode(argp->xdr, setclientid->se_callback_addr_len);
  1337. if (!p)
  1338. return nfserr_bad_xdr;
  1339. setclientid->se_callback_addr_val = svcxdr_savemem(argp, p,
  1340. setclientid->se_callback_addr_len);
  1341. if (!setclientid->se_callback_addr_val)
  1342. return nfserr_jukebox;
  1343. if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_ident) < 0)
  1344. return nfserr_bad_xdr;
  1345. return nfs_ok;
  1346. }
  1347. static __be32
  1348. nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp,
  1349. union nfsd4_op_u *u)
  1350. {
  1351. struct nfsd4_setclientid_confirm *scd_c = &u->setclientid_confirm;
  1352. __be32 status;
  1353. if (argp->minorversion >= 1)
  1354. return nfserr_notsupp;
  1355. status = nfsd4_decode_clientid4(argp, &scd_c->sc_clientid);
  1356. if (status)
  1357. return status;
  1358. return nfsd4_decode_verifier4(argp, &scd_c->sc_confirm);
  1359. }
  1360. /* Also used for NVERIFY */
  1361. static __be32
  1362. nfsd4_decode_verify(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1363. {
  1364. struct nfsd4_verify *verify = &u->verify;
  1365. __be32 *p, status;
  1366. memset(verify, 0, sizeof(*verify));
  1367. status = nfsd4_decode_bitmap4(argp, verify->ve_bmval,
  1368. ARRAY_SIZE(verify->ve_bmval));
  1369. if (status)
  1370. return status;
  1371. /* For convenience's sake, we compare raw xdr'd attributes in
  1372. * nfsd4_proc_verify */
  1373. if (xdr_stream_decode_u32(argp->xdr, &verify->ve_attrlen) < 0)
  1374. return nfserr_bad_xdr;
  1375. p = xdr_inline_decode(argp->xdr, verify->ve_attrlen);
  1376. if (!p)
  1377. return nfserr_bad_xdr;
  1378. verify->ve_attrval = svcxdr_savemem(argp, p, verify->ve_attrlen);
  1379. if (!verify->ve_attrval)
  1380. return nfserr_jukebox;
  1381. return nfs_ok;
  1382. }
  1383. static __be32
  1384. nfsd4_decode_write(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1385. {
  1386. struct nfsd4_write *write = &u->write;
  1387. __be32 status;
  1388. status = nfsd4_decode_stateid4(argp, &write->wr_stateid);
  1389. if (status)
  1390. return status;
  1391. if (xdr_stream_decode_u64(argp->xdr, &write->wr_offset) < 0)
  1392. return nfserr_bad_xdr;
  1393. if (xdr_stream_decode_u32(argp->xdr, &write->wr_stable_how) < 0)
  1394. return nfserr_bad_xdr;
  1395. if (write->wr_stable_how > NFS_FILE_SYNC)
  1396. return nfserr_bad_xdr;
  1397. if (xdr_stream_decode_u32(argp->xdr, &write->wr_buflen) < 0)
  1398. return nfserr_bad_xdr;
  1399. if (!xdr_stream_subsegment(argp->xdr, &write->wr_payload, write->wr_buflen))
  1400. return nfserr_bad_xdr;
  1401. write->wr_bytes_written = 0;
  1402. write->wr_how_written = 0;
  1403. memset(&write->wr_verifier, 0, sizeof(write->wr_verifier));
  1404. return nfs_ok;
  1405. }
  1406. static __be32
  1407. nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp,
  1408. union nfsd4_op_u *u)
  1409. {
  1410. struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner;
  1411. __be32 status;
  1412. if (argp->minorversion >= 1)
  1413. return nfserr_notsupp;
  1414. status = nfsd4_decode_state_owner4(argp, &rlockowner->rl_clientid,
  1415. &rlockowner->rl_owner);
  1416. if (status)
  1417. return status;
  1418. if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
  1419. return nfserr_inval;
  1420. return nfs_ok;
  1421. }
  1422. static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp,
  1423. union nfsd4_op_u *u)
  1424. {
  1425. struct nfsd4_backchannel_ctl *bc = &u->backchannel_ctl;
  1426. memset(bc, 0, sizeof(*bc));
  1427. if (xdr_stream_decode_u32(argp->xdr, &bc->bc_cb_program) < 0)
  1428. return nfserr_bad_xdr;
  1429. return nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec);
  1430. }
  1431. static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp,
  1432. union nfsd4_op_u *u)
  1433. {
  1434. struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session;
  1435. u32 use_conn_in_rdma_mode;
  1436. __be32 status;
  1437. memset(bcts, 0, sizeof(*bcts));
  1438. status = nfsd4_decode_sessionid4(argp, &bcts->sessionid);
  1439. if (status)
  1440. return status;
  1441. if (xdr_stream_decode_u32(argp->xdr, &bcts->dir) < 0)
  1442. return nfserr_bad_xdr;
  1443. if (xdr_stream_decode_u32(argp->xdr, &use_conn_in_rdma_mode) < 0)
  1444. return nfserr_bad_xdr;
  1445. return nfs_ok;
  1446. }
  1447. static __be32
  1448. nfsd4_decode_state_protect_ops(struct nfsd4_compoundargs *argp,
  1449. struct nfsd4_exchange_id *exid)
  1450. {
  1451. __be32 status;
  1452. status = nfsd4_decode_bitmap4(argp, exid->spo_must_enforce,
  1453. ARRAY_SIZE(exid->spo_must_enforce));
  1454. if (status)
  1455. return nfserr_bad_xdr;
  1456. status = nfsd4_decode_bitmap4(argp, exid->spo_must_allow,
  1457. ARRAY_SIZE(exid->spo_must_allow));
  1458. if (status)
  1459. return nfserr_bad_xdr;
  1460. return nfs_ok;
  1461. }
  1462. /*
  1463. * This implementation currently does not support SP4_SSV.
  1464. * This decoder simply skips over these arguments.
  1465. */
  1466. static noinline __be32
  1467. nfsd4_decode_ssv_sp_parms(struct nfsd4_compoundargs *argp,
  1468. struct nfsd4_exchange_id *exid)
  1469. {
  1470. u32 count, window, num_gss_handles;
  1471. __be32 status;
  1472. /* ssp_ops */
  1473. status = nfsd4_decode_state_protect_ops(argp, exid);
  1474. if (status)
  1475. return status;
  1476. /* ssp_hash_algs<> */
  1477. if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
  1478. return nfserr_bad_xdr;
  1479. while (count--) {
  1480. status = nfsd4_decode_ignored_string(argp, 0);
  1481. if (status)
  1482. return status;
  1483. }
  1484. /* ssp_encr_algs<> */
  1485. if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
  1486. return nfserr_bad_xdr;
  1487. while (count--) {
  1488. status = nfsd4_decode_ignored_string(argp, 0);
  1489. if (status)
  1490. return status;
  1491. }
  1492. if (xdr_stream_decode_u32(argp->xdr, &window) < 0)
  1493. return nfserr_bad_xdr;
  1494. if (xdr_stream_decode_u32(argp->xdr, &num_gss_handles) < 0)
  1495. return nfserr_bad_xdr;
  1496. return nfs_ok;
  1497. }
  1498. static __be32
  1499. nfsd4_decode_state_protect4_a(struct nfsd4_compoundargs *argp,
  1500. struct nfsd4_exchange_id *exid)
  1501. {
  1502. __be32 status;
  1503. if (xdr_stream_decode_u32(argp->xdr, &exid->spa_how) < 0)
  1504. return nfserr_bad_xdr;
  1505. switch (exid->spa_how) {
  1506. case SP4_NONE:
  1507. break;
  1508. case SP4_MACH_CRED:
  1509. status = nfsd4_decode_state_protect_ops(argp, exid);
  1510. if (status)
  1511. return status;
  1512. break;
  1513. case SP4_SSV:
  1514. status = nfsd4_decode_ssv_sp_parms(argp, exid);
  1515. if (status)
  1516. return status;
  1517. break;
  1518. default:
  1519. return nfserr_bad_xdr;
  1520. }
  1521. return nfs_ok;
  1522. }
  1523. static __be32
  1524. nfsd4_decode_nfs_impl_id4(struct nfsd4_compoundargs *argp,
  1525. struct nfsd4_exchange_id *exid)
  1526. {
  1527. __be32 status;
  1528. u32 count;
  1529. if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
  1530. return nfserr_bad_xdr;
  1531. switch (count) {
  1532. case 0:
  1533. break;
  1534. case 1:
  1535. /* Note that RFC 8881 places no length limit on
  1536. * nii_domain, but this implementation permits no
  1537. * more than NFS4_OPAQUE_LIMIT bytes */
  1538. status = nfsd4_decode_opaque(argp, &exid->nii_domain);
  1539. if (status)
  1540. return status;
  1541. /* Note that RFC 8881 places no length limit on
  1542. * nii_name, but this implementation permits no
  1543. * more than NFS4_OPAQUE_LIMIT bytes */
  1544. status = nfsd4_decode_opaque(argp, &exid->nii_name);
  1545. if (status)
  1546. return status;
  1547. status = nfsd4_decode_nfstime4(argp, &exid->nii_time);
  1548. if (status)
  1549. return status;
  1550. break;
  1551. default:
  1552. return nfserr_bad_xdr;
  1553. }
  1554. return nfs_ok;
  1555. }
  1556. static __be32
  1557. nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
  1558. union nfsd4_op_u *u)
  1559. {
  1560. struct nfsd4_exchange_id *exid = &u->exchange_id;
  1561. __be32 status;
  1562. memset(exid, 0, sizeof(*exid));
  1563. status = nfsd4_decode_verifier4(argp, &exid->verifier);
  1564. if (status)
  1565. return status;
  1566. status = nfsd4_decode_opaque(argp, &exid->clname);
  1567. if (status)
  1568. return status;
  1569. if (xdr_stream_decode_u32(argp->xdr, &exid->flags) < 0)
  1570. return nfserr_bad_xdr;
  1571. status = nfsd4_decode_state_protect4_a(argp, exid);
  1572. if (status)
  1573. return status;
  1574. return nfsd4_decode_nfs_impl_id4(argp, exid);
  1575. }
  1576. static __be32
  1577. nfsd4_decode_channel_attrs4(struct nfsd4_compoundargs *argp,
  1578. struct nfsd4_channel_attrs *ca)
  1579. {
  1580. __be32 *p;
  1581. p = xdr_inline_decode(argp->xdr, XDR_UNIT * 7);
  1582. if (!p)
  1583. return nfserr_bad_xdr;
  1584. /* headerpadsz is ignored */
  1585. p++;
  1586. ca->maxreq_sz = be32_to_cpup(p++);
  1587. ca->maxresp_sz = be32_to_cpup(p++);
  1588. ca->maxresp_cached = be32_to_cpup(p++);
  1589. ca->maxops = be32_to_cpup(p++);
  1590. ca->maxreqs = be32_to_cpup(p++);
  1591. ca->nr_rdma_attrs = be32_to_cpup(p);
  1592. switch (ca->nr_rdma_attrs) {
  1593. case 0:
  1594. break;
  1595. case 1:
  1596. if (xdr_stream_decode_u32(argp->xdr, &ca->rdma_attrs) < 0)
  1597. return nfserr_bad_xdr;
  1598. break;
  1599. default:
  1600. return nfserr_bad_xdr;
  1601. }
  1602. return nfs_ok;
  1603. }
  1604. static __be32
  1605. nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
  1606. union nfsd4_op_u *u)
  1607. {
  1608. struct nfsd4_create_session *sess = &u->create_session;
  1609. __be32 status;
  1610. memset(sess, 0, sizeof(*sess));
  1611. status = nfsd4_decode_clientid4(argp, &sess->clientid);
  1612. if (status)
  1613. return status;
  1614. if (xdr_stream_decode_u32(argp->xdr, &sess->seqid) < 0)
  1615. return nfserr_bad_xdr;
  1616. if (xdr_stream_decode_u32(argp->xdr, &sess->flags) < 0)
  1617. return nfserr_bad_xdr;
  1618. status = nfsd4_decode_channel_attrs4(argp, &sess->fore_channel);
  1619. if (status)
  1620. return status;
  1621. status = nfsd4_decode_channel_attrs4(argp, &sess->back_channel);
  1622. if (status)
  1623. return status;
  1624. if (xdr_stream_decode_u32(argp->xdr, &sess->callback_prog) < 0)
  1625. return nfserr_bad_xdr;
  1626. return nfsd4_decode_cb_sec(argp, &sess->cb_sec);
  1627. }
  1628. static __be32
  1629. nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
  1630. union nfsd4_op_u *u)
  1631. {
  1632. struct nfsd4_destroy_session *destroy_session = &u->destroy_session;
  1633. return nfsd4_decode_sessionid4(argp, &destroy_session->sessionid);
  1634. }
  1635. static __be32
  1636. nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp,
  1637. union nfsd4_op_u *u)
  1638. {
  1639. struct nfsd4_free_stateid *free_stateid = &u->free_stateid;
  1640. return nfsd4_decode_stateid4(argp, &free_stateid->fr_stateid);
  1641. }
  1642. static __be32
  1643. nfsd4_decode_get_dir_delegation(struct nfsd4_compoundargs *argp,
  1644. union nfsd4_op_u *u)
  1645. {
  1646. struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation;
  1647. __be32 status;
  1648. memset(gdd, 0, sizeof(*gdd));
  1649. if (xdr_stream_decode_bool(argp->xdr, &gdd->gdda_signal_deleg_avail) < 0)
  1650. return nfserr_bad_xdr;
  1651. status = nfsd4_decode_bitmap4(argp, gdd->gdda_notification_types,
  1652. ARRAY_SIZE(gdd->gdda_notification_types));
  1653. if (status)
  1654. return status;
  1655. status = nfsd4_decode_nfstime4(argp, &gdd->gdda_child_attr_delay);
  1656. if (status)
  1657. return status;
  1658. status = nfsd4_decode_nfstime4(argp, &gdd->gdda_dir_attr_delay);
  1659. if (status)
  1660. return status;
  1661. status = nfsd4_decode_bitmap4(argp, gdd->gdda_child_attributes,
  1662. ARRAY_SIZE(gdd->gdda_child_attributes));
  1663. if (status)
  1664. return status;
  1665. return nfsd4_decode_bitmap4(argp, gdd->gdda_dir_attributes,
  1666. ARRAY_SIZE(gdd->gdda_dir_attributes));
  1667. }
  1668. #ifdef CONFIG_NFSD_PNFS
  1669. static __be32
  1670. nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp,
  1671. union nfsd4_op_u *u)
  1672. {
  1673. struct nfsd4_getdeviceinfo *gdev = &u->getdeviceinfo;
  1674. __be32 status;
  1675. memset(gdev, 0, sizeof(*gdev));
  1676. status = nfsd4_decode_deviceid4(argp->xdr, &gdev->gd_devid);
  1677. if (status)
  1678. return status;
  1679. if (xdr_stream_decode_u32(argp->xdr, &gdev->gd_layout_type) < 0)
  1680. return nfserr_bad_xdr;
  1681. if (xdr_stream_decode_u32(argp->xdr, &gdev->gd_maxcount) < 0)
  1682. return nfserr_bad_xdr;
  1683. if (xdr_stream_decode_uint32_array(argp->xdr,
  1684. &gdev->gd_notify_types, 1) < 0)
  1685. return nfserr_bad_xdr;
  1686. return nfs_ok;
  1687. }
  1688. static __be32
  1689. nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp,
  1690. union nfsd4_op_u *u)
  1691. {
  1692. struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
  1693. __be32 *p, status;
  1694. memset(lcp, 0, sizeof(*lcp));
  1695. if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_seg.offset) < 0)
  1696. return nfserr_bad_xdr;
  1697. if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_seg.length) < 0)
  1698. return nfserr_bad_xdr;
  1699. if (xdr_stream_decode_bool(argp->xdr, &lcp->lc_reclaim) < 0)
  1700. return nfserr_bad_xdr;
  1701. status = nfsd4_decode_stateid4(argp, &lcp->lc_sid);
  1702. if (status)
  1703. return status;
  1704. if (xdr_stream_decode_bool(argp->xdr, &lcp->lc_newoffset) < 0)
  1705. return nfserr_bad_xdr;
  1706. if (lcp->lc_newoffset) {
  1707. if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_last_wr) < 0)
  1708. return nfserr_bad_xdr;
  1709. } else
  1710. lcp->lc_last_wr = 0;
  1711. p = xdr_inline_decode(argp->xdr, XDR_UNIT);
  1712. if (!p)
  1713. return nfserr_bad_xdr;
  1714. if (xdr_item_is_present(p)) {
  1715. status = nfsd4_decode_nfstime4(argp, &lcp->lc_mtime);
  1716. if (status)
  1717. return status;
  1718. } else {
  1719. lcp->lc_mtime.tv_nsec = UTIME_NOW;
  1720. }
  1721. return nfsd4_decode_layoutupdate4(argp, lcp);
  1722. }
  1723. static __be32
  1724. nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp,
  1725. union nfsd4_op_u *u)
  1726. {
  1727. struct nfsd4_layoutget *lgp = &u->layoutget;
  1728. __be32 status;
  1729. memset(lgp, 0, sizeof(*lgp));
  1730. if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_signal) < 0)
  1731. return nfserr_bad_xdr;
  1732. if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_layout_type) < 0)
  1733. return nfserr_bad_xdr;
  1734. if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_seg.iomode) < 0)
  1735. return nfserr_bad_xdr;
  1736. if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_seg.offset) < 0)
  1737. return nfserr_bad_xdr;
  1738. if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_seg.length) < 0)
  1739. return nfserr_bad_xdr;
  1740. if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_minlength) < 0)
  1741. return nfserr_bad_xdr;
  1742. status = nfsd4_decode_stateid4(argp, &lgp->lg_sid);
  1743. if (status)
  1744. return status;
  1745. if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_maxcount) < 0)
  1746. return nfserr_bad_xdr;
  1747. return nfs_ok;
  1748. }
  1749. static __be32
  1750. nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp,
  1751. union nfsd4_op_u *u)
  1752. {
  1753. struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
  1754. memset(lrp, 0, sizeof(*lrp));
  1755. if (xdr_stream_decode_bool(argp->xdr, &lrp->lr_reclaim) < 0)
  1756. return nfserr_bad_xdr;
  1757. if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_layout_type) < 0)
  1758. return nfserr_bad_xdr;
  1759. if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_seg.iomode) < 0)
  1760. return nfserr_bad_xdr;
  1761. return nfsd4_decode_layoutreturn4(argp, lrp);
  1762. }
  1763. #endif /* CONFIG_NFSD_PNFS */
  1764. static __be32 nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp,
  1765. union nfsd4_op_u *u)
  1766. {
  1767. struct nfsd4_secinfo_no_name *sin = &u->secinfo_no_name;
  1768. if (xdr_stream_decode_u32(argp->xdr, &sin->sin_style) < 0)
  1769. return nfserr_bad_xdr;
  1770. sin->sin_exp = NULL;
  1771. return nfs_ok;
  1772. }
  1773. static __be32
  1774. nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
  1775. union nfsd4_op_u *u)
  1776. {
  1777. struct nfsd4_sequence *seq = &u->sequence;
  1778. __be32 *p, status;
  1779. status = nfsd4_decode_sessionid4(argp, &seq->sessionid);
  1780. if (status)
  1781. return status;
  1782. p = xdr_inline_decode(argp->xdr, XDR_UNIT * 4);
  1783. if (!p)
  1784. return nfserr_bad_xdr;
  1785. seq->seqid = be32_to_cpup(p++);
  1786. seq->slotid = be32_to_cpup(p++);
  1787. /* sa_highest_slotid counts from 0 but maxslots counts from 1 ... */
  1788. seq->maxslots = be32_to_cpup(p++) + 1;
  1789. seq->cachethis = be32_to_cpup(p);
  1790. seq->status_flags = 0;
  1791. return nfs_ok;
  1792. }
  1793. static __be32
  1794. nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp,
  1795. union nfsd4_op_u *u)
  1796. {
  1797. struct nfsd4_test_stateid *test_stateid = &u->test_stateid;
  1798. struct nfsd4_test_stateid_id *stateid;
  1799. __be32 status;
  1800. u32 i;
  1801. memset(test_stateid, 0, sizeof(*test_stateid));
  1802. if (xdr_stream_decode_u32(argp->xdr, &test_stateid->ts_num_ids) < 0)
  1803. return nfserr_bad_xdr;
  1804. INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
  1805. for (i = 0; i < test_stateid->ts_num_ids; i++) {
  1806. stateid = svcxdr_tmpalloc(argp, sizeof(*stateid));
  1807. if (!stateid)
  1808. return nfserr_jukebox;
  1809. INIT_LIST_HEAD(&stateid->ts_id_list);
  1810. list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list);
  1811. status = nfsd4_decode_stateid4(argp, &stateid->ts_id_stateid);
  1812. if (status)
  1813. return status;
  1814. }
  1815. return nfs_ok;
  1816. }
  1817. static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp,
  1818. union nfsd4_op_u *u)
  1819. {
  1820. struct nfsd4_destroy_clientid *dc = &u->destroy_clientid;
  1821. return nfsd4_decode_clientid4(argp, &dc->clientid);
  1822. }
  1823. static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp,
  1824. union nfsd4_op_u *u)
  1825. {
  1826. struct nfsd4_reclaim_complete *rc = &u->reclaim_complete;
  1827. if (xdr_stream_decode_bool(argp->xdr, &rc->rca_one_fs) < 0)
  1828. return nfserr_bad_xdr;
  1829. return nfs_ok;
  1830. }
  1831. static __be32
  1832. nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp,
  1833. union nfsd4_op_u *u)
  1834. {
  1835. struct nfsd4_fallocate *fallocate = &u->allocate;
  1836. __be32 status;
  1837. status = nfsd4_decode_stateid4(argp, &fallocate->falloc_stateid);
  1838. if (status)
  1839. return status;
  1840. if (xdr_stream_decode_u64(argp->xdr, &fallocate->falloc_offset) < 0)
  1841. return nfserr_bad_xdr;
  1842. if (xdr_stream_decode_u64(argp->xdr, &fallocate->falloc_length) < 0)
  1843. return nfserr_bad_xdr;
  1844. return nfs_ok;
  1845. }
  1846. static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp,
  1847. struct nl4_server *ns)
  1848. {
  1849. struct nfs42_netaddr *naddr;
  1850. __be32 *p;
  1851. if (xdr_stream_decode_u32(argp->xdr, &ns->nl4_type) < 0)
  1852. return nfserr_bad_xdr;
  1853. /* currently support for 1 inter-server source server */
  1854. switch (ns->nl4_type) {
  1855. case NL4_NETADDR:
  1856. naddr = &ns->u.nl4_addr;
  1857. if (xdr_stream_decode_u32(argp->xdr, &naddr->netid_len) < 0)
  1858. return nfserr_bad_xdr;
  1859. if (naddr->netid_len > RPCBIND_MAXNETIDLEN)
  1860. return nfserr_bad_xdr;
  1861. p = xdr_inline_decode(argp->xdr, naddr->netid_len);
  1862. if (!p)
  1863. return nfserr_bad_xdr;
  1864. memcpy(naddr->netid, p, naddr->netid_len);
  1865. if (xdr_stream_decode_u32(argp->xdr, &naddr->addr_len) < 0)
  1866. return nfserr_bad_xdr;
  1867. if (naddr->addr_len > RPCBIND_MAXUADDRLEN)
  1868. return nfserr_bad_xdr;
  1869. p = xdr_inline_decode(argp->xdr, naddr->addr_len);
  1870. if (!p)
  1871. return nfserr_bad_xdr;
  1872. memcpy(naddr->addr, p, naddr->addr_len);
  1873. break;
  1874. default:
  1875. return nfserr_bad_xdr;
  1876. }
  1877. return nfs_ok;
  1878. }
  1879. static __be32
  1880. nfsd4_decode_copy(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1881. {
  1882. struct nfsd4_copy *copy = &u->copy;
  1883. u32 consecutive, i, count, sync;
  1884. struct nl4_server *ns_dummy;
  1885. __be32 status;
  1886. memset(copy, 0, sizeof(*copy));
  1887. status = nfsd4_decode_stateid4(argp, &copy->cp_src_stateid);
  1888. if (status)
  1889. return status;
  1890. status = nfsd4_decode_stateid4(argp, &copy->cp_dst_stateid);
  1891. if (status)
  1892. return status;
  1893. if (xdr_stream_decode_u64(argp->xdr, &copy->cp_src_pos) < 0)
  1894. return nfserr_bad_xdr;
  1895. if (xdr_stream_decode_u64(argp->xdr, &copy->cp_dst_pos) < 0)
  1896. return nfserr_bad_xdr;
  1897. if (xdr_stream_decode_u64(argp->xdr, &copy->cp_count) < 0)
  1898. return nfserr_bad_xdr;
  1899. /* ca_consecutive: we always do consecutive copies */
  1900. if (xdr_stream_decode_u32(argp->xdr, &consecutive) < 0)
  1901. return nfserr_bad_xdr;
  1902. if (xdr_stream_decode_bool(argp->xdr, &sync) < 0)
  1903. return nfserr_bad_xdr;
  1904. nfsd4_copy_set_sync(copy, sync);
  1905. if (xdr_stream_decode_u32(argp->xdr, &count) < 0)
  1906. return nfserr_bad_xdr;
  1907. copy->cp_src = svcxdr_tmpalloc(argp, sizeof(*copy->cp_src));
  1908. if (copy->cp_src == NULL)
  1909. return nfserr_jukebox;
  1910. if (count == 0) { /* intra-server copy */
  1911. __set_bit(NFSD4_COPY_F_INTRA, &copy->cp_flags);
  1912. return nfs_ok;
  1913. }
  1914. /* decode all the supplied server addresses but use only the first */
  1915. status = nfsd4_decode_nl4_server(argp, copy->cp_src);
  1916. if (status)
  1917. return status;
  1918. ns_dummy = kmalloc_obj(struct nl4_server);
  1919. if (ns_dummy == NULL)
  1920. return nfserr_jukebox;
  1921. for (i = 0; i < count - 1; i++) {
  1922. status = nfsd4_decode_nl4_server(argp, ns_dummy);
  1923. if (status) {
  1924. kfree(ns_dummy);
  1925. return status;
  1926. }
  1927. }
  1928. kfree(ns_dummy);
  1929. return nfs_ok;
  1930. }
  1931. static __be32
  1932. nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp,
  1933. union nfsd4_op_u *u)
  1934. {
  1935. struct nfsd4_copy_notify *cn = &u->copy_notify;
  1936. __be32 status;
  1937. memset(cn, 0, sizeof(*cn));
  1938. cn->cpn_src = svcxdr_tmpalloc(argp, sizeof(*cn->cpn_src));
  1939. if (cn->cpn_src == NULL)
  1940. return nfserr_jukebox;
  1941. cn->cpn_dst = svcxdr_tmpalloc(argp, sizeof(*cn->cpn_dst));
  1942. if (cn->cpn_dst == NULL)
  1943. return nfserr_jukebox;
  1944. status = nfsd4_decode_stateid4(argp, &cn->cpn_src_stateid);
  1945. if (status)
  1946. return status;
  1947. return nfsd4_decode_nl4_server(argp, cn->cpn_dst);
  1948. }
  1949. static __be32
  1950. nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp,
  1951. union nfsd4_op_u *u)
  1952. {
  1953. struct nfsd4_offload_status *os = &u->offload_status;
  1954. os->count = 0;
  1955. os->status = 0;
  1956. return nfsd4_decode_stateid4(argp, &os->stateid);
  1957. }
  1958. static __be32
  1959. nfsd4_decode_seek(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1960. {
  1961. struct nfsd4_seek *seek = &u->seek;
  1962. __be32 status;
  1963. status = nfsd4_decode_stateid4(argp, &seek->seek_stateid);
  1964. if (status)
  1965. return status;
  1966. if (xdr_stream_decode_u64(argp->xdr, &seek->seek_offset) < 0)
  1967. return nfserr_bad_xdr;
  1968. if (xdr_stream_decode_u32(argp->xdr, &seek->seek_whence) < 0)
  1969. return nfserr_bad_xdr;
  1970. seek->seek_eof = 0;
  1971. seek->seek_pos = 0;
  1972. return nfs_ok;
  1973. }
  1974. static __be32
  1975. nfsd4_decode_clone(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
  1976. {
  1977. struct nfsd4_clone *clone = &u->clone;
  1978. __be32 status;
  1979. status = nfsd4_decode_stateid4(argp, &clone->cl_src_stateid);
  1980. if (status)
  1981. return status;
  1982. status = nfsd4_decode_stateid4(argp, &clone->cl_dst_stateid);
  1983. if (status)
  1984. return status;
  1985. if (xdr_stream_decode_u64(argp->xdr, &clone->cl_src_pos) < 0)
  1986. return nfserr_bad_xdr;
  1987. if (xdr_stream_decode_u64(argp->xdr, &clone->cl_dst_pos) < 0)
  1988. return nfserr_bad_xdr;
  1989. if (xdr_stream_decode_u64(argp->xdr, &clone->cl_count) < 0)
  1990. return nfserr_bad_xdr;
  1991. return nfs_ok;
  1992. }
  1993. /*
  1994. * XDR data that is more than PAGE_SIZE in size is normally part of a
  1995. * read or write. However, the size of extended attributes is limited
  1996. * by the maximum request size, and then further limited by the underlying
  1997. * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX
  1998. * is 64k). Since there is no kvec- or page-based interface to xattrs,
  1999. * and we're not dealing with contiguous pages, we need to do some copying.
  2000. */
  2001. /*
  2002. * Decode data into buffer.
  2003. */
  2004. static __be32
  2005. nfsd4_vbuf_from_vector(struct nfsd4_compoundargs *argp, struct xdr_buf *xdr,
  2006. char **bufp, size_t buflen)
  2007. {
  2008. struct page **pages = xdr->pages;
  2009. struct kvec *head = xdr->head;
  2010. char *tmp, *dp;
  2011. u32 len;
  2012. if (buflen <= head->iov_len) {
  2013. /*
  2014. * We're in luck, the head has enough space. Just return
  2015. * the head, no need for copying.
  2016. */
  2017. *bufp = head->iov_base;
  2018. return 0;
  2019. }
  2020. tmp = svcxdr_tmpalloc(argp, buflen);
  2021. if (tmp == NULL)
  2022. return nfserr_jukebox;
  2023. dp = tmp;
  2024. memcpy(dp, head->iov_base, head->iov_len);
  2025. buflen -= head->iov_len;
  2026. dp += head->iov_len;
  2027. while (buflen > 0) {
  2028. len = min_t(u32, buflen, PAGE_SIZE);
  2029. memcpy(dp, page_address(*pages), len);
  2030. buflen -= len;
  2031. dp += len;
  2032. pages++;
  2033. }
  2034. *bufp = tmp;
  2035. return 0;
  2036. }
  2037. /*
  2038. * Get a user extended attribute name from the XDR buffer.
  2039. * It will not have the "user." prefix, so prepend it.
  2040. * Lastly, check for nul characters in the name.
  2041. */
  2042. static __be32
  2043. nfsd4_decode_xattr_name(struct nfsd4_compoundargs *argp, char **namep)
  2044. {
  2045. char *name, *sp, *dp;
  2046. u32 namelen, cnt;
  2047. __be32 *p;
  2048. if (xdr_stream_decode_u32(argp->xdr, &namelen) < 0)
  2049. return nfserr_bad_xdr;
  2050. if (namelen > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN))
  2051. return nfserr_nametoolong;
  2052. if (namelen == 0)
  2053. return nfserr_bad_xdr;
  2054. p = xdr_inline_decode(argp->xdr, namelen);
  2055. if (!p)
  2056. return nfserr_bad_xdr;
  2057. name = svcxdr_tmpalloc(argp, namelen + XATTR_USER_PREFIX_LEN + 1);
  2058. if (!name)
  2059. return nfserr_jukebox;
  2060. memcpy(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
  2061. /*
  2062. * Copy the extended attribute name over while checking for 0
  2063. * characters.
  2064. */
  2065. sp = (char *)p;
  2066. dp = name + XATTR_USER_PREFIX_LEN;
  2067. cnt = namelen;
  2068. while (cnt-- > 0) {
  2069. if (*sp == '\0')
  2070. return nfserr_bad_xdr;
  2071. *dp++ = *sp++;
  2072. }
  2073. *dp = '\0';
  2074. *namep = name;
  2075. return nfs_ok;
  2076. }
  2077. /*
  2078. * A GETXATTR op request comes without a length specifier. We just set the
  2079. * maximum length for the reply based on XATTR_SIZE_MAX and the maximum
  2080. * channel reply size. nfsd_getxattr will probe the length of the xattr,
  2081. * check it against getxa_len, and allocate + return the value.
  2082. */
  2083. static __be32
  2084. nfsd4_decode_getxattr(struct nfsd4_compoundargs *argp,
  2085. union nfsd4_op_u *u)
  2086. {
  2087. struct nfsd4_getxattr *getxattr = &u->getxattr;
  2088. __be32 status;
  2089. u32 maxcount;
  2090. memset(getxattr, 0, sizeof(*getxattr));
  2091. status = nfsd4_decode_xattr_name(argp, &getxattr->getxa_name);
  2092. if (status)
  2093. return status;
  2094. maxcount = svc_max_payload(argp->rqstp);
  2095. maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount);
  2096. getxattr->getxa_len = maxcount;
  2097. return nfs_ok;
  2098. }
  2099. static __be32
  2100. nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp,
  2101. union nfsd4_op_u *u)
  2102. {
  2103. struct nfsd4_setxattr *setxattr = &u->setxattr;
  2104. u32 flags, maxcount, size;
  2105. __be32 status;
  2106. memset(setxattr, 0, sizeof(*setxattr));
  2107. if (xdr_stream_decode_u32(argp->xdr, &flags) < 0)
  2108. return nfserr_bad_xdr;
  2109. if (flags > SETXATTR4_REPLACE)
  2110. return nfserr_inval;
  2111. setxattr->setxa_flags = flags;
  2112. status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name);
  2113. if (status)
  2114. return status;
  2115. maxcount = svc_max_payload(argp->rqstp);
  2116. maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount);
  2117. if (xdr_stream_decode_u32(argp->xdr, &size) < 0)
  2118. return nfserr_bad_xdr;
  2119. if (size > maxcount)
  2120. return nfserr_xattr2big;
  2121. setxattr->setxa_len = size;
  2122. if (size > 0) {
  2123. struct xdr_buf payload;
  2124. if (!xdr_stream_subsegment(argp->xdr, &payload, size))
  2125. return nfserr_bad_xdr;
  2126. status = nfsd4_vbuf_from_vector(argp, &payload,
  2127. &setxattr->setxa_buf, size);
  2128. }
  2129. return nfs_ok;
  2130. }
  2131. static __be32
  2132. nfsd4_decode_listxattrs(struct nfsd4_compoundargs *argp,
  2133. union nfsd4_op_u *u)
  2134. {
  2135. struct nfsd4_listxattrs *listxattrs = &u->listxattrs;
  2136. u32 maxcount;
  2137. memset(listxattrs, 0, sizeof(*listxattrs));
  2138. if (xdr_stream_decode_u64(argp->xdr, &listxattrs->lsxa_cookie) < 0)
  2139. return nfserr_bad_xdr;
  2140. /*
  2141. * If the cookie is too large to have even one user.x attribute
  2142. * plus trailing '\0' left in a maximum size buffer, it's invalid.
  2143. */
  2144. if (listxattrs->lsxa_cookie >=
  2145. (XATTR_LIST_MAX / (XATTR_USER_PREFIX_LEN + 2)))
  2146. return nfserr_badcookie;
  2147. if (xdr_stream_decode_u32(argp->xdr, &maxcount) < 0)
  2148. return nfserr_bad_xdr;
  2149. if (maxcount < 8)
  2150. /* Always need at least 2 words (length and one character) */
  2151. return nfserr_inval;
  2152. maxcount = min(maxcount, svc_max_payload(argp->rqstp));
  2153. listxattrs->lsxa_maxcount = maxcount;
  2154. return nfs_ok;
  2155. }
  2156. static __be32
  2157. nfsd4_decode_removexattr(struct nfsd4_compoundargs *argp,
  2158. union nfsd4_op_u *u)
  2159. {
  2160. struct nfsd4_removexattr *removexattr = &u->removexattr;
  2161. memset(removexattr, 0, sizeof(*removexattr));
  2162. return nfsd4_decode_xattr_name(argp, &removexattr->rmxa_name);
  2163. }
  2164. static __be32
  2165. nfsd4_decode_noop(struct nfsd4_compoundargs *argp, union nfsd4_op_u *p)
  2166. {
  2167. return nfs_ok;
  2168. }
  2169. static __be32
  2170. nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, union nfsd4_op_u *p)
  2171. {
  2172. return nfserr_notsupp;
  2173. }
  2174. typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u);
  2175. static const nfsd4_dec nfsd4_dec_ops[] = {
  2176. [OP_ACCESS] = nfsd4_decode_access,
  2177. [OP_CLOSE] = nfsd4_decode_close,
  2178. [OP_COMMIT] = nfsd4_decode_commit,
  2179. [OP_CREATE] = nfsd4_decode_create,
  2180. [OP_DELEGPURGE] = nfsd4_decode_notsupp,
  2181. [OP_DELEGRETURN] = nfsd4_decode_delegreturn,
  2182. [OP_GETATTR] = nfsd4_decode_getattr,
  2183. [OP_GETFH] = nfsd4_decode_noop,
  2184. [OP_LINK] = nfsd4_decode_link,
  2185. [OP_LOCK] = nfsd4_decode_lock,
  2186. [OP_LOCKT] = nfsd4_decode_lockt,
  2187. [OP_LOCKU] = nfsd4_decode_locku,
  2188. [OP_LOOKUP] = nfsd4_decode_lookup,
  2189. [OP_LOOKUPP] = nfsd4_decode_noop,
  2190. [OP_NVERIFY] = nfsd4_decode_verify,
  2191. [OP_OPEN] = nfsd4_decode_open,
  2192. [OP_OPENATTR] = nfsd4_decode_notsupp,
  2193. [OP_OPEN_CONFIRM] = nfsd4_decode_open_confirm,
  2194. [OP_OPEN_DOWNGRADE] = nfsd4_decode_open_downgrade,
  2195. [OP_PUTFH] = nfsd4_decode_putfh,
  2196. [OP_PUTPUBFH] = nfsd4_decode_noop,
  2197. [OP_PUTROOTFH] = nfsd4_decode_noop,
  2198. [OP_READ] = nfsd4_decode_read,
  2199. [OP_READDIR] = nfsd4_decode_readdir,
  2200. [OP_READLINK] = nfsd4_decode_noop,
  2201. [OP_REMOVE] = nfsd4_decode_remove,
  2202. [OP_RENAME] = nfsd4_decode_rename,
  2203. [OP_RENEW] = nfsd4_decode_renew,
  2204. [OP_RESTOREFH] = nfsd4_decode_noop,
  2205. [OP_SAVEFH] = nfsd4_decode_noop,
  2206. [OP_SECINFO] = nfsd4_decode_secinfo,
  2207. [OP_SETATTR] = nfsd4_decode_setattr,
  2208. [OP_SETCLIENTID] = nfsd4_decode_setclientid,
  2209. [OP_SETCLIENTID_CONFIRM] = nfsd4_decode_setclientid_confirm,
  2210. [OP_VERIFY] = nfsd4_decode_verify,
  2211. [OP_WRITE] = nfsd4_decode_write,
  2212. [OP_RELEASE_LOCKOWNER] = nfsd4_decode_release_lockowner,
  2213. /* new operations for NFSv4.1 */
  2214. [OP_BACKCHANNEL_CTL] = nfsd4_decode_backchannel_ctl,
  2215. [OP_BIND_CONN_TO_SESSION] = nfsd4_decode_bind_conn_to_session,
  2216. [OP_EXCHANGE_ID] = nfsd4_decode_exchange_id,
  2217. [OP_CREATE_SESSION] = nfsd4_decode_create_session,
  2218. [OP_DESTROY_SESSION] = nfsd4_decode_destroy_session,
  2219. [OP_FREE_STATEID] = nfsd4_decode_free_stateid,
  2220. [OP_GET_DIR_DELEGATION] = nfsd4_decode_get_dir_delegation,
  2221. #ifdef CONFIG_NFSD_PNFS
  2222. [OP_GETDEVICEINFO] = nfsd4_decode_getdeviceinfo,
  2223. [OP_GETDEVICELIST] = nfsd4_decode_notsupp,
  2224. [OP_LAYOUTCOMMIT] = nfsd4_decode_layoutcommit,
  2225. [OP_LAYOUTGET] = nfsd4_decode_layoutget,
  2226. [OP_LAYOUTRETURN] = nfsd4_decode_layoutreturn,
  2227. #else
  2228. [OP_GETDEVICEINFO] = nfsd4_decode_notsupp,
  2229. [OP_GETDEVICELIST] = nfsd4_decode_notsupp,
  2230. [OP_LAYOUTCOMMIT] = nfsd4_decode_notsupp,
  2231. [OP_LAYOUTGET] = nfsd4_decode_notsupp,
  2232. [OP_LAYOUTRETURN] = nfsd4_decode_notsupp,
  2233. #endif
  2234. [OP_SECINFO_NO_NAME] = nfsd4_decode_secinfo_no_name,
  2235. [OP_SEQUENCE] = nfsd4_decode_sequence,
  2236. [OP_SET_SSV] = nfsd4_decode_notsupp,
  2237. [OP_TEST_STATEID] = nfsd4_decode_test_stateid,
  2238. [OP_WANT_DELEGATION] = nfsd4_decode_notsupp,
  2239. [OP_DESTROY_CLIENTID] = nfsd4_decode_destroy_clientid,
  2240. [OP_RECLAIM_COMPLETE] = nfsd4_decode_reclaim_complete,
  2241. /* new operations for NFSv4.2 */
  2242. [OP_ALLOCATE] = nfsd4_decode_fallocate,
  2243. [OP_COPY] = nfsd4_decode_copy,
  2244. [OP_COPY_NOTIFY] = nfsd4_decode_copy_notify,
  2245. [OP_DEALLOCATE] = nfsd4_decode_fallocate,
  2246. [OP_IO_ADVISE] = nfsd4_decode_notsupp,
  2247. [OP_LAYOUTERROR] = nfsd4_decode_notsupp,
  2248. [OP_LAYOUTSTATS] = nfsd4_decode_notsupp,
  2249. [OP_OFFLOAD_CANCEL] = nfsd4_decode_offload_status,
  2250. [OP_OFFLOAD_STATUS] = nfsd4_decode_offload_status,
  2251. [OP_READ_PLUS] = nfsd4_decode_read,
  2252. [OP_SEEK] = nfsd4_decode_seek,
  2253. [OP_WRITE_SAME] = nfsd4_decode_notsupp,
  2254. [OP_CLONE] = nfsd4_decode_clone,
  2255. /* RFC 8276 extended atributes operations */
  2256. [OP_GETXATTR] = nfsd4_decode_getxattr,
  2257. [OP_SETXATTR] = nfsd4_decode_setxattr,
  2258. [OP_LISTXATTRS] = nfsd4_decode_listxattrs,
  2259. [OP_REMOVEXATTR] = nfsd4_decode_removexattr,
  2260. };
  2261. static inline bool
  2262. nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op)
  2263. {
  2264. if (op->opnum < FIRST_NFS4_OP)
  2265. return false;
  2266. else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP)
  2267. return false;
  2268. else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP)
  2269. return false;
  2270. else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP)
  2271. return false;
  2272. return true;
  2273. }
  2274. static bool
  2275. nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
  2276. {
  2277. struct nfsd4_op *op;
  2278. bool cachethis = false;
  2279. int auth_slack= argp->rqstp->rq_auth_slack;
  2280. int max_reply = auth_slack + 8; /* opcnt, status */
  2281. int readcount = 0;
  2282. int readbytes = 0;
  2283. __be32 *p;
  2284. int i;
  2285. if (xdr_stream_decode_u32(argp->xdr, &argp->taglen) < 0)
  2286. return false;
  2287. max_reply += XDR_UNIT;
  2288. argp->tag = NULL;
  2289. if (unlikely(argp->taglen)) {
  2290. if (argp->taglen > NFSD4_MAX_TAGLEN)
  2291. return false;
  2292. p = xdr_inline_decode(argp->xdr, argp->taglen);
  2293. if (!p)
  2294. return false;
  2295. argp->tag = svcxdr_savemem(argp, p, argp->taglen);
  2296. if (!argp->tag)
  2297. return false;
  2298. max_reply += xdr_align_size(argp->taglen);
  2299. }
  2300. if (xdr_stream_decode_u32(argp->xdr, &argp->minorversion) < 0)
  2301. return false;
  2302. if (xdr_stream_decode_u32(argp->xdr, &argp->client_opcnt) < 0)
  2303. return false;
  2304. argp->opcnt = min_t(u32, argp->client_opcnt,
  2305. NFSD_MAX_OPS_PER_COMPOUND);
  2306. if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
  2307. argp->ops = vcalloc(argp->opcnt, sizeof(*argp->ops));
  2308. if (!argp->ops) {
  2309. argp->ops = argp->iops;
  2310. return false;
  2311. }
  2312. }
  2313. if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION)
  2314. argp->opcnt = 0;
  2315. for (i = 0; i < argp->opcnt; i++) {
  2316. op = &argp->ops[i];
  2317. op->replay = NULL;
  2318. op->opdesc = NULL;
  2319. if (xdr_stream_decode_u32(argp->xdr, &op->opnum) < 0)
  2320. return false;
  2321. if (nfsd4_opnum_in_range(argp, op)) {
  2322. op->opdesc = OPDESC(op);
  2323. op->status = nfsd4_dec_ops[op->opnum](argp, &op->u);
  2324. if (op->status != nfs_ok)
  2325. trace_nfsd_compound_decode_err(argp->rqstp,
  2326. argp->opcnt, i,
  2327. op->opnum,
  2328. op->status);
  2329. } else {
  2330. op->opnum = OP_ILLEGAL;
  2331. op->status = nfserr_op_illegal;
  2332. }
  2333. /*
  2334. * We'll try to cache the result in the DRC if any one
  2335. * op in the compound wants to be cached:
  2336. */
  2337. cachethis |= nfsd4_cache_this_op(op);
  2338. if (op->opnum == OP_READ || op->opnum == OP_READ_PLUS) {
  2339. readcount++;
  2340. readbytes += nfsd4_max_reply(argp->rqstp, op);
  2341. } else
  2342. max_reply += nfsd4_max_reply(argp->rqstp, op);
  2343. /*
  2344. * OP_LOCK and OP_LOCKT may return a conflicting lock.
  2345. * (Special case because it will just skip encoding this
  2346. * if it runs out of xdr buffer space, and it is the only
  2347. * operation that behaves this way.)
  2348. */
  2349. if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT)
  2350. max_reply += NFS4_OPAQUE_LIMIT;
  2351. if (op->status) {
  2352. argp->opcnt = i+1;
  2353. break;
  2354. }
  2355. }
  2356. /* Sessions make the DRC unnecessary: */
  2357. if (argp->minorversion)
  2358. cachethis = false;
  2359. svc_reserve_auth(argp->rqstp, max_reply + readbytes);
  2360. argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
  2361. argp->splice_ok = nfsd_read_splice_ok(argp->rqstp);
  2362. if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack)
  2363. argp->splice_ok = false;
  2364. return true;
  2365. }
  2366. static __be32 nfsd4_encode_nfs_fh4(struct xdr_stream *xdr,
  2367. struct knfsd_fh *fh_handle)
  2368. {
  2369. return nfsd4_encode_opaque(xdr, fh_handle->fh_raw, fh_handle->fh_size);
  2370. }
  2371. /* This is a frequently-encoded type; open-coded for speed */
  2372. static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr,
  2373. const struct timespec64 *tv)
  2374. {
  2375. __be32 *p;
  2376. p = xdr_reserve_space(xdr, XDR_UNIT * 3);
  2377. if (!p)
  2378. return nfserr_resource;
  2379. p = xdr_encode_hyper(p, tv->tv_sec);
  2380. *p = cpu_to_be32(tv->tv_nsec);
  2381. return nfs_ok;
  2382. }
  2383. static __be32 nfsd4_encode_specdata4(struct xdr_stream *xdr,
  2384. unsigned int major, unsigned int minor)
  2385. {
  2386. __be32 status;
  2387. status = nfsd4_encode_uint32_t(xdr, major);
  2388. if (status != nfs_ok)
  2389. return status;
  2390. return nfsd4_encode_uint32_t(xdr, minor);
  2391. }
  2392. static __be32
  2393. nfsd4_encode_change_info4(struct xdr_stream *xdr, const struct nfsd4_change_info *c)
  2394. {
  2395. __be32 status;
  2396. status = nfsd4_encode_bool(xdr, c->atomic);
  2397. if (status != nfs_ok)
  2398. return status;
  2399. status = nfsd4_encode_changeid4(xdr, c->before_change);
  2400. if (status != nfs_ok)
  2401. return status;
  2402. return nfsd4_encode_changeid4(xdr, c->after_change);
  2403. }
  2404. static __be32 nfsd4_encode_netaddr4(struct xdr_stream *xdr,
  2405. const struct nfs42_netaddr *addr)
  2406. {
  2407. __be32 status;
  2408. /* na_r_netid */
  2409. status = nfsd4_encode_opaque(xdr, addr->netid, addr->netid_len);
  2410. if (status != nfs_ok)
  2411. return status;
  2412. /* na_r_addr */
  2413. return nfsd4_encode_opaque(xdr, addr->addr, addr->addr_len);
  2414. }
  2415. /* Encode as an array of strings the string given with components
  2416. * separated @sep, escaped with esc_enter and esc_exit.
  2417. */
  2418. static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep,
  2419. char *components, char esc_enter,
  2420. char esc_exit)
  2421. {
  2422. __be32 *p;
  2423. __be32 pathlen;
  2424. int pathlen_offset;
  2425. char *str, *end, *next;
  2426. int count = 0;
  2427. pathlen_offset = xdr->buf->len;
  2428. p = xdr_reserve_space(xdr, 4);
  2429. if (!p)
  2430. return nfserr_resource;
  2431. p++; /* We will fill this in with @count later */
  2432. end = str = components;
  2433. while (*end) {
  2434. bool found_esc = false;
  2435. /* try to parse as esc_start, ..., esc_end, sep */
  2436. if (*str == esc_enter) {
  2437. for (; *end && (*end != esc_exit); end++)
  2438. /* find esc_exit or end of string */;
  2439. next = end + 1;
  2440. if (*end && (!*next || *next == sep)) {
  2441. str++;
  2442. found_esc = true;
  2443. }
  2444. }
  2445. if (!found_esc)
  2446. for (; *end && (*end != sep); end++)
  2447. /* find sep or end of string */;
  2448. if (end > str) {
  2449. if (xdr_stream_encode_opaque(xdr, str, end - str) < 0)
  2450. return nfserr_resource;
  2451. count++;
  2452. } else
  2453. end++;
  2454. if (found_esc)
  2455. end = next;
  2456. str = end;
  2457. }
  2458. pathlen = htonl(count);
  2459. write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4);
  2460. return 0;
  2461. }
  2462. /* Encode as an array of strings the string given with components
  2463. * separated @sep.
  2464. */
  2465. static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep,
  2466. char *components)
  2467. {
  2468. return nfsd4_encode_components_esc(xdr, sep, components, 0, 0);
  2469. }
  2470. static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr,
  2471. struct nfsd4_fs_location *location)
  2472. {
  2473. __be32 status;
  2474. status = nfsd4_encode_components_esc(xdr, ':', location->hosts,
  2475. '[', ']');
  2476. if (status)
  2477. return status;
  2478. status = nfsd4_encode_components(xdr, '/', location->path);
  2479. if (status)
  2480. return status;
  2481. return nfs_ok;
  2482. }
  2483. static __be32 nfsd4_encode_pathname4(struct xdr_stream *xdr,
  2484. const struct path *root,
  2485. const struct path *path)
  2486. {
  2487. struct path cur = *path;
  2488. struct dentry **components = NULL;
  2489. unsigned int ncomponents = 0;
  2490. __be32 err = nfserr_jukebox;
  2491. dprintk("nfsd4_encode_components(");
  2492. path_get(&cur);
  2493. /* First walk the path up to the nfsd root, and store the
  2494. * dentries/path components in an array.
  2495. */
  2496. for (;;) {
  2497. if (path_equal(&cur, root))
  2498. break;
  2499. if (cur.dentry == cur.mnt->mnt_root) {
  2500. if (follow_up(&cur))
  2501. continue;
  2502. goto out_free;
  2503. }
  2504. if ((ncomponents & 15) == 0) {
  2505. struct dentry **new;
  2506. new = krealloc(components,
  2507. sizeof(*new) * (ncomponents + 16),
  2508. GFP_KERNEL);
  2509. if (!new)
  2510. goto out_free;
  2511. components = new;
  2512. }
  2513. components[ncomponents++] = cur.dentry;
  2514. cur.dentry = dget_parent(cur.dentry);
  2515. }
  2516. err = nfserr_resource;
  2517. if (xdr_stream_encode_u32(xdr, ncomponents) != XDR_UNIT)
  2518. goto out_free;
  2519. while (ncomponents) {
  2520. struct dentry *dentry = components[ncomponents - 1];
  2521. spin_lock(&dentry->d_lock);
  2522. if (xdr_stream_encode_opaque(xdr, dentry->d_name.name,
  2523. dentry->d_name.len) < 0) {
  2524. spin_unlock(&dentry->d_lock);
  2525. goto out_free;
  2526. }
  2527. dprintk("/%pd", dentry);
  2528. spin_unlock(&dentry->d_lock);
  2529. dput(dentry);
  2530. ncomponents--;
  2531. }
  2532. err = 0;
  2533. out_free:
  2534. dprintk(")\n");
  2535. while (ncomponents)
  2536. dput(components[--ncomponents]);
  2537. kfree(components);
  2538. path_put(&cur);
  2539. return err;
  2540. }
  2541. static __be32 nfsd4_encode_fs_locations4(struct xdr_stream *xdr,
  2542. struct svc_rqst *rqstp,
  2543. struct svc_export *exp)
  2544. {
  2545. struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
  2546. struct svc_export *exp_ps;
  2547. unsigned int i;
  2548. __be32 status;
  2549. /* fs_root */
  2550. exp_ps = rqst_find_fsidzero_export(rqstp);
  2551. if (IS_ERR(exp_ps))
  2552. return nfserrno(PTR_ERR(exp_ps));
  2553. status = nfsd4_encode_pathname4(xdr, &exp_ps->ex_path, &exp->ex_path);
  2554. exp_put(exp_ps);
  2555. if (status != nfs_ok)
  2556. return status;
  2557. /* locations<> */
  2558. if (xdr_stream_encode_u32(xdr, fslocs->locations_count) != XDR_UNIT)
  2559. return nfserr_resource;
  2560. for (i = 0; i < fslocs->locations_count; i++) {
  2561. status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]);
  2562. if (status != nfs_ok)
  2563. return status;
  2564. }
  2565. return nfs_ok;
  2566. }
  2567. static __be32 nfsd4_encode_nfsace4(struct xdr_stream *xdr, struct svc_rqst *rqstp,
  2568. struct nfs4_ace *ace)
  2569. {
  2570. __be32 status;
  2571. /* type */
  2572. status = nfsd4_encode_acetype4(xdr, ace->type);
  2573. if (status != nfs_ok)
  2574. return nfserr_resource;
  2575. /* flag */
  2576. status = nfsd4_encode_aceflag4(xdr, ace->flag);
  2577. if (status != nfs_ok)
  2578. return nfserr_resource;
  2579. /* access mask */
  2580. status = nfsd4_encode_acemask4(xdr, ace->access_mask & NFS4_ACE_MASK_ALL);
  2581. if (status != nfs_ok)
  2582. return nfserr_resource;
  2583. /* who */
  2584. if (ace->whotype != NFS4_ACL_WHO_NAMED)
  2585. return nfs4_acl_write_who(xdr, ace->whotype);
  2586. if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
  2587. return nfsd4_encode_group(xdr, rqstp, ace->who_gid);
  2588. return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
  2589. }
  2590. #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
  2591. FATTR4_WORD0_RDATTR_ERROR)
  2592. #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
  2593. #define WORD2_ABSENT_FS_ATTRS 0
  2594. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  2595. static inline __be32
  2596. nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
  2597. const struct lsm_context *context)
  2598. {
  2599. __be32 *p;
  2600. p = xdr_reserve_space(xdr, context->len + 4 + 4 + 4);
  2601. if (!p)
  2602. return nfserr_resource;
  2603. /*
  2604. * For now we use a 0 here to indicate the null translation; in
  2605. * the future we may place a call to translation code here.
  2606. */
  2607. *p++ = cpu_to_be32(0); /* lfs */
  2608. *p++ = cpu_to_be32(0); /* pi */
  2609. p = xdr_encode_opaque(p, context->context, context->len);
  2610. return 0;
  2611. }
  2612. #else
  2613. static inline __be32
  2614. nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
  2615. struct lsm_context *context)
  2616. { return 0; }
  2617. #endif
  2618. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  2619. static int nfsd4_posix_tagtotype(short tag)
  2620. {
  2621. switch (tag) {
  2622. case ACL_USER_OBJ: return POSIXACE4_TAG_USER_OBJ;
  2623. case ACL_GROUP_OBJ: return POSIXACE4_TAG_GROUP_OBJ;
  2624. case ACL_USER: return POSIXACE4_TAG_USER;
  2625. case ACL_GROUP: return POSIXACE4_TAG_GROUP;
  2626. case ACL_MASK: return POSIXACE4_TAG_MASK;
  2627. case ACL_OTHER: return POSIXACE4_TAG_OTHER;
  2628. default: return -EINVAL;
  2629. }
  2630. }
  2631. static __be32
  2632. nfsd4_encode_posixace4(struct xdr_stream *xdr, struct svc_rqst *rqstp,
  2633. struct posix_acl_entry *acep)
  2634. {
  2635. __be32 status;
  2636. int type;
  2637. type = nfsd4_posix_tagtotype(acep->e_tag);
  2638. if (type < 0)
  2639. return nfserr_resource;
  2640. if (!xdrgen_encode_posixacetag4(xdr, type))
  2641. return nfserr_resource;
  2642. if (!xdrgen_encode_posixaceperm4(xdr, acep->e_perm))
  2643. return nfserr_resource;
  2644. /* who */
  2645. switch (acep->e_tag) {
  2646. case ACL_USER_OBJ:
  2647. case ACL_GROUP_OBJ:
  2648. case ACL_MASK:
  2649. case ACL_OTHER:
  2650. if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
  2651. return nfserr_resource;
  2652. break;
  2653. case ACL_USER:
  2654. status = nfsd4_encode_user(xdr, rqstp, acep->e_uid);
  2655. if (status != nfs_ok)
  2656. return status;
  2657. break;
  2658. case ACL_GROUP:
  2659. status = nfsd4_encode_group(xdr, rqstp, acep->e_gid);
  2660. if (status != nfs_ok)
  2661. return status;
  2662. break;
  2663. default:
  2664. return nfserr_resource;
  2665. }
  2666. return nfs_ok;
  2667. }
  2668. static __be32
  2669. nfsd4_encode_posixacl(struct xdr_stream *xdr, struct svc_rqst *rqstp,
  2670. struct posix_acl *acl)
  2671. {
  2672. __be32 status;
  2673. int i;
  2674. if (!acl) {
  2675. if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
  2676. return nfserr_resource;
  2677. return nfs_ok;
  2678. }
  2679. if (acl->a_count > NFS_ACL_MAX_ENTRIES)
  2680. return nfserr_resource;
  2681. if (xdr_stream_encode_u32(xdr, acl->a_count) != XDR_UNIT)
  2682. return nfserr_resource;
  2683. for (i = 0; i < acl->a_count; i++) {
  2684. status = nfsd4_encode_posixace4(xdr, rqstp, &acl->a_entries[i]);
  2685. if (status != nfs_ok)
  2686. return status;
  2687. }
  2688. return nfs_ok;
  2689. }
  2690. #endif /* CONFIG_NFSD_V4_POSIX_ACL */
  2691. static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *bmval2, u32 *rdattr_err)
  2692. {
  2693. /* As per referral draft: */
  2694. if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
  2695. *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
  2696. if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
  2697. *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
  2698. *rdattr_err = NFSERR_MOVED;
  2699. else
  2700. return nfserr_moved;
  2701. }
  2702. *bmval0 &= WORD0_ABSENT_FS_ATTRS;
  2703. *bmval1 &= WORD1_ABSENT_FS_ATTRS;
  2704. *bmval2 &= WORD2_ABSENT_FS_ATTRS;
  2705. return 0;
  2706. }
  2707. static int nfsd4_get_mounted_on_ino(struct svc_export *exp, u64 *pino)
  2708. {
  2709. struct path path = exp->ex_path;
  2710. struct kstat stat;
  2711. int err;
  2712. path_get(&path);
  2713. while (follow_up(&path)) {
  2714. if (path.dentry != path.mnt->mnt_root)
  2715. break;
  2716. }
  2717. err = vfs_getattr(&path, &stat, STATX_INO, AT_STATX_SYNC_AS_STAT);
  2718. path_put(&path);
  2719. if (!err)
  2720. *pino = stat.ino;
  2721. return err;
  2722. }
  2723. static __be32
  2724. nfsd4_encode_bitmap4(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
  2725. {
  2726. __be32 *p;
  2727. if (bmval2) {
  2728. p = xdr_reserve_space(xdr, XDR_UNIT * 4);
  2729. if (!p)
  2730. goto out_resource;
  2731. *p++ = cpu_to_be32(3);
  2732. *p++ = cpu_to_be32(bmval0);
  2733. *p++ = cpu_to_be32(bmval1);
  2734. *p++ = cpu_to_be32(bmval2);
  2735. } else if (bmval1) {
  2736. p = xdr_reserve_space(xdr, XDR_UNIT * 3);
  2737. if (!p)
  2738. goto out_resource;
  2739. *p++ = cpu_to_be32(2);
  2740. *p++ = cpu_to_be32(bmval0);
  2741. *p++ = cpu_to_be32(bmval1);
  2742. } else {
  2743. p = xdr_reserve_space(xdr, XDR_UNIT * 2);
  2744. if (!p)
  2745. goto out_resource;
  2746. *p++ = cpu_to_be32(1);
  2747. *p++ = cpu_to_be32(bmval0);
  2748. }
  2749. return nfs_ok;
  2750. out_resource:
  2751. return nfserr_resource;
  2752. }
  2753. struct nfsd4_fattr_args {
  2754. struct svc_rqst *rqstp;
  2755. struct svc_fh *fhp;
  2756. struct svc_export *exp;
  2757. struct dentry *dentry;
  2758. struct kstat stat;
  2759. struct kstatfs statfs;
  2760. struct nfs4_acl *acl;
  2761. u64 change_attr;
  2762. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  2763. struct lsm_context context;
  2764. #endif
  2765. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  2766. struct posix_acl *dpacl;
  2767. struct posix_acl *pacl;
  2768. #endif
  2769. u32 rdattr_err;
  2770. bool contextsupport;
  2771. bool ignore_crossmnt;
  2772. };
  2773. typedef __be32(*nfsd4_enc_attr)(struct xdr_stream *xdr,
  2774. const struct nfsd4_fattr_args *args);
  2775. static __be32 nfsd4_encode_fattr4__inval(struct xdr_stream *xdr,
  2776. const struct nfsd4_fattr_args *args)
  2777. {
  2778. return nfserr_inval;
  2779. }
  2780. static __be32 nfsd4_encode_fattr4__noop(struct xdr_stream *xdr,
  2781. const struct nfsd4_fattr_args *args)
  2782. {
  2783. return nfs_ok;
  2784. }
  2785. static __be32 nfsd4_encode_fattr4__true(struct xdr_stream *xdr,
  2786. const struct nfsd4_fattr_args *args)
  2787. {
  2788. return nfsd4_encode_bool(xdr, true);
  2789. }
  2790. static __be32 nfsd4_encode_fattr4__false(struct xdr_stream *xdr,
  2791. const struct nfsd4_fattr_args *args)
  2792. {
  2793. return nfsd4_encode_bool(xdr, false);
  2794. }
  2795. static __be32 nfsd4_encode_fattr4_supported_attrs(struct xdr_stream *xdr,
  2796. const struct nfsd4_fattr_args *args)
  2797. {
  2798. struct nfsd4_compoundres *resp = args->rqstp->rq_resp;
  2799. u32 minorversion = resp->cstate.minorversion;
  2800. u32 supp[3];
  2801. memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp));
  2802. if (!IS_POSIXACL(d_inode(args->dentry)))
  2803. supp[0] &= ~FATTR4_WORD0_ACL;
  2804. if (!args->contextsupport)
  2805. supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  2806. return nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
  2807. }
  2808. static __be32 nfsd4_encode_fattr4_type(struct xdr_stream *xdr,
  2809. const struct nfsd4_fattr_args *args)
  2810. {
  2811. __be32 *p;
  2812. p = xdr_reserve_space(xdr, XDR_UNIT);
  2813. if (!p)
  2814. return nfserr_resource;
  2815. switch (args->stat.mode & S_IFMT) {
  2816. case S_IFIFO:
  2817. *p = cpu_to_be32(NF4FIFO);
  2818. break;
  2819. case S_IFCHR:
  2820. *p = cpu_to_be32(NF4CHR);
  2821. break;
  2822. case S_IFDIR:
  2823. *p = cpu_to_be32(NF4DIR);
  2824. break;
  2825. case S_IFBLK:
  2826. *p = cpu_to_be32(NF4BLK);
  2827. break;
  2828. case S_IFLNK:
  2829. *p = cpu_to_be32(NF4LNK);
  2830. break;
  2831. case S_IFREG:
  2832. *p = cpu_to_be32(NF4REG);
  2833. break;
  2834. case S_IFSOCK:
  2835. *p = cpu_to_be32(NF4SOCK);
  2836. break;
  2837. default:
  2838. return nfserr_serverfault;
  2839. }
  2840. return nfs_ok;
  2841. }
  2842. static __be32 nfsd4_encode_fattr4_fh_expire_type(struct xdr_stream *xdr,
  2843. const struct nfsd4_fattr_args *args)
  2844. {
  2845. u32 mask;
  2846. mask = NFS4_FH_PERSISTENT;
  2847. if (!(args->exp->ex_flags & NFSEXP_NOSUBTREECHECK))
  2848. mask |= NFS4_FH_VOL_RENAME;
  2849. return nfsd4_encode_uint32_t(xdr, mask);
  2850. }
  2851. static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr,
  2852. const struct nfsd4_fattr_args *args)
  2853. {
  2854. const struct svc_export *exp = args->exp;
  2855. if (unlikely(exp->ex_flags & NFSEXP_V4ROOT)) {
  2856. u32 flush_time = convert_to_wallclock(exp->cd->flush_time);
  2857. if (xdr_stream_encode_u32(xdr, flush_time) != XDR_UNIT)
  2858. return nfserr_resource;
  2859. if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
  2860. return nfserr_resource;
  2861. return nfs_ok;
  2862. }
  2863. return nfsd4_encode_changeid4(xdr, args->change_attr);
  2864. }
  2865. static __be32 nfsd4_encode_fattr4_size(struct xdr_stream *xdr,
  2866. const struct nfsd4_fattr_args *args)
  2867. {
  2868. return nfsd4_encode_uint64_t(xdr, args->stat.size);
  2869. }
  2870. static __be32 nfsd4_encode_fattr4_fsid(struct xdr_stream *xdr,
  2871. const struct nfsd4_fattr_args *args)
  2872. {
  2873. __be32 *p;
  2874. p = xdr_reserve_space(xdr, XDR_UNIT * 2 + XDR_UNIT * 2);
  2875. if (!p)
  2876. return nfserr_resource;
  2877. if (unlikely(args->exp->ex_fslocs.migrated)) {
  2878. p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR);
  2879. xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR);
  2880. return nfs_ok;
  2881. }
  2882. switch (fsid_source(args->fhp)) {
  2883. case FSIDSOURCE_FSID:
  2884. p = xdr_encode_hyper(p, (u64)args->exp->ex_fsid);
  2885. xdr_encode_hyper(p, (u64)0);
  2886. break;
  2887. case FSIDSOURCE_DEV:
  2888. *p++ = xdr_zero;
  2889. *p++ = cpu_to_be32(MAJOR(args->stat.dev));
  2890. *p++ = xdr_zero;
  2891. *p = cpu_to_be32(MINOR(args->stat.dev));
  2892. break;
  2893. case FSIDSOURCE_UUID:
  2894. xdr_encode_opaque_fixed(p, args->exp->ex_uuid, EX_UUID_LEN);
  2895. break;
  2896. }
  2897. return nfs_ok;
  2898. }
  2899. static __be32 nfsd4_encode_fattr4_lease_time(struct xdr_stream *xdr,
  2900. const struct nfsd4_fattr_args *args)
  2901. {
  2902. struct nfsd_net *nn = net_generic(SVC_NET(args->rqstp), nfsd_net_id);
  2903. return nfsd4_encode_nfs_lease4(xdr, nn->nfsd4_lease);
  2904. }
  2905. static __be32 nfsd4_encode_fattr4_rdattr_error(struct xdr_stream *xdr,
  2906. const struct nfsd4_fattr_args *args)
  2907. {
  2908. return nfsd4_encode_uint32_t(xdr, args->rdattr_err);
  2909. }
  2910. static __be32 nfsd4_encode_fattr4_aclsupport(struct xdr_stream *xdr,
  2911. const struct nfsd4_fattr_args *args)
  2912. {
  2913. u32 mask;
  2914. mask = 0;
  2915. if (IS_POSIXACL(d_inode(args->dentry)))
  2916. mask = ACL4_SUPPORT_ALLOW_ACL | ACL4_SUPPORT_DENY_ACL;
  2917. return nfsd4_encode_uint32_t(xdr, mask);
  2918. }
  2919. static __be32 nfsd4_encode_fattr4_acl(struct xdr_stream *xdr,
  2920. const struct nfsd4_fattr_args *args)
  2921. {
  2922. struct nfs4_acl *acl = args->acl;
  2923. struct nfs4_ace *ace;
  2924. __be32 status;
  2925. /* nfsace4<> */
  2926. if (!acl) {
  2927. if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
  2928. return nfserr_resource;
  2929. } else {
  2930. if (xdr_stream_encode_u32(xdr, acl->naces) != XDR_UNIT)
  2931. return nfserr_resource;
  2932. for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
  2933. status = nfsd4_encode_nfsace4(xdr, args->rqstp, ace);
  2934. if (status != nfs_ok)
  2935. return status;
  2936. }
  2937. }
  2938. return nfs_ok;
  2939. }
  2940. static __be32 nfsd4_encode_fattr4_filehandle(struct xdr_stream *xdr,
  2941. const struct nfsd4_fattr_args *args)
  2942. {
  2943. return nfsd4_encode_nfs_fh4(xdr, &args->fhp->fh_handle);
  2944. }
  2945. static __be32 nfsd4_encode_fattr4_fileid(struct xdr_stream *xdr,
  2946. const struct nfsd4_fattr_args *args)
  2947. {
  2948. return nfsd4_encode_uint64_t(xdr, args->stat.ino);
  2949. }
  2950. static __be32 nfsd4_encode_fattr4_files_avail(struct xdr_stream *xdr,
  2951. const struct nfsd4_fattr_args *args)
  2952. {
  2953. return nfsd4_encode_uint64_t(xdr, args->statfs.f_ffree);
  2954. }
  2955. static __be32 nfsd4_encode_fattr4_files_free(struct xdr_stream *xdr,
  2956. const struct nfsd4_fattr_args *args)
  2957. {
  2958. return nfsd4_encode_uint64_t(xdr, args->statfs.f_ffree);
  2959. }
  2960. static __be32 nfsd4_encode_fattr4_files_total(struct xdr_stream *xdr,
  2961. const struct nfsd4_fattr_args *args)
  2962. {
  2963. return nfsd4_encode_uint64_t(xdr, args->statfs.f_files);
  2964. }
  2965. static __be32 nfsd4_encode_fattr4_fs_locations(struct xdr_stream *xdr,
  2966. const struct nfsd4_fattr_args *args)
  2967. {
  2968. return nfsd4_encode_fs_locations4(xdr, args->rqstp, args->exp);
  2969. }
  2970. static __be32 nfsd4_encode_fattr4_maxfilesize(struct xdr_stream *xdr,
  2971. const struct nfsd4_fattr_args *args)
  2972. {
  2973. struct super_block *sb = args->exp->ex_path.mnt->mnt_sb;
  2974. return nfsd4_encode_uint64_t(xdr, sb->s_maxbytes);
  2975. }
  2976. static __be32 nfsd4_encode_fattr4_maxlink(struct xdr_stream *xdr,
  2977. const struct nfsd4_fattr_args *args)
  2978. {
  2979. return nfsd4_encode_uint32_t(xdr, 255);
  2980. }
  2981. static __be32 nfsd4_encode_fattr4_maxname(struct xdr_stream *xdr,
  2982. const struct nfsd4_fattr_args *args)
  2983. {
  2984. return nfsd4_encode_uint32_t(xdr, args->statfs.f_namelen);
  2985. }
  2986. static __be32 nfsd4_encode_fattr4_maxread(struct xdr_stream *xdr,
  2987. const struct nfsd4_fattr_args *args)
  2988. {
  2989. return nfsd4_encode_uint64_t(xdr, svc_max_payload(args->rqstp));
  2990. }
  2991. static __be32 nfsd4_encode_fattr4_maxwrite(struct xdr_stream *xdr,
  2992. const struct nfsd4_fattr_args *args)
  2993. {
  2994. return nfsd4_encode_uint64_t(xdr, svc_max_payload(args->rqstp));
  2995. }
  2996. static __be32 nfsd4_encode_fattr4_mode(struct xdr_stream *xdr,
  2997. const struct nfsd4_fattr_args *args)
  2998. {
  2999. return nfsd4_encode_mode4(xdr, args->stat.mode & S_IALLUGO);
  3000. }
  3001. static __be32 nfsd4_encode_fattr4_numlinks(struct xdr_stream *xdr,
  3002. const struct nfsd4_fattr_args *args)
  3003. {
  3004. return nfsd4_encode_uint32_t(xdr, args->stat.nlink);
  3005. }
  3006. static __be32 nfsd4_encode_fattr4_owner(struct xdr_stream *xdr,
  3007. const struct nfsd4_fattr_args *args)
  3008. {
  3009. return nfsd4_encode_user(xdr, args->rqstp, args->stat.uid);
  3010. }
  3011. static __be32 nfsd4_encode_fattr4_owner_group(struct xdr_stream *xdr,
  3012. const struct nfsd4_fattr_args *args)
  3013. {
  3014. return nfsd4_encode_group(xdr, args->rqstp, args->stat.gid);
  3015. }
  3016. static __be32 nfsd4_encode_fattr4_rawdev(struct xdr_stream *xdr,
  3017. const struct nfsd4_fattr_args *args)
  3018. {
  3019. return nfsd4_encode_specdata4(xdr, MAJOR(args->stat.rdev),
  3020. MINOR(args->stat.rdev));
  3021. }
  3022. static __be32 nfsd4_encode_fattr4_space_avail(struct xdr_stream *xdr,
  3023. const struct nfsd4_fattr_args *args)
  3024. {
  3025. u64 avail = (u64)args->statfs.f_bavail * (u64)args->statfs.f_bsize;
  3026. return nfsd4_encode_uint64_t(xdr, avail);
  3027. }
  3028. static __be32 nfsd4_encode_fattr4_space_free(struct xdr_stream *xdr,
  3029. const struct nfsd4_fattr_args *args)
  3030. {
  3031. u64 free = (u64)args->statfs.f_bfree * (u64)args->statfs.f_bsize;
  3032. return nfsd4_encode_uint64_t(xdr, free);
  3033. }
  3034. static __be32 nfsd4_encode_fattr4_space_total(struct xdr_stream *xdr,
  3035. const struct nfsd4_fattr_args *args)
  3036. {
  3037. u64 total = (u64)args->statfs.f_blocks * (u64)args->statfs.f_bsize;
  3038. return nfsd4_encode_uint64_t(xdr, total);
  3039. }
  3040. static __be32 nfsd4_encode_fattr4_space_used(struct xdr_stream *xdr,
  3041. const struct nfsd4_fattr_args *args)
  3042. {
  3043. return nfsd4_encode_uint64_t(xdr, (u64)args->stat.blocks << 9);
  3044. }
  3045. static __be32 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
  3046. const struct nfsd4_fattr_args *args)
  3047. {
  3048. return nfsd4_encode_nfstime4(xdr, &args->stat.atime);
  3049. }
  3050. static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
  3051. const struct nfsd4_fattr_args *args)
  3052. {
  3053. return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
  3054. }
  3055. /*
  3056. * ctime (in NFSv4, time_metadata) is not writeable, and the client
  3057. * doesn't really care what resolution could theoretically be stored by
  3058. * the filesystem.
  3059. *
  3060. * The client cares how close together changes can be while still
  3061. * guaranteeing ctime changes. For most filesystems (which have
  3062. * timestamps with nanosecond fields) that is limited by the resolution
  3063. * of the time returned from current_time() (which I'm assuming to be
  3064. * 1/HZ).
  3065. */
  3066. static __be32 nfsd4_encode_fattr4_time_delta(struct xdr_stream *xdr,
  3067. const struct nfsd4_fattr_args *args)
  3068. {
  3069. const struct inode *inode = d_inode(args->dentry);
  3070. u32 ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran);
  3071. struct timespec64 ts = ns_to_timespec64(ns);
  3072. return nfsd4_encode_nfstime4(xdr, &ts);
  3073. }
  3074. static __be32 nfsd4_encode_fattr4_time_metadata(struct xdr_stream *xdr,
  3075. const struct nfsd4_fattr_args *args)
  3076. {
  3077. return nfsd4_encode_nfstime4(xdr, &args->stat.ctime);
  3078. }
  3079. static __be32 nfsd4_encode_fattr4_time_modify(struct xdr_stream *xdr,
  3080. const struct nfsd4_fattr_args *args)
  3081. {
  3082. return nfsd4_encode_nfstime4(xdr, &args->stat.mtime);
  3083. }
  3084. static __be32 nfsd4_encode_fattr4_mounted_on_fileid(struct xdr_stream *xdr,
  3085. const struct nfsd4_fattr_args *args)
  3086. {
  3087. u64 ino;
  3088. int err;
  3089. if (!args->ignore_crossmnt &&
  3090. args->dentry == args->exp->ex_path.mnt->mnt_root) {
  3091. err = nfsd4_get_mounted_on_ino(args->exp, &ino);
  3092. if (err)
  3093. return nfserrno(err);
  3094. } else
  3095. ino = args->stat.ino;
  3096. return nfsd4_encode_uint64_t(xdr, ino);
  3097. }
  3098. #ifdef CONFIG_NFSD_PNFS
  3099. static __be32 nfsd4_encode_fattr4_fs_layout_types(struct xdr_stream *xdr,
  3100. const struct nfsd4_fattr_args *args)
  3101. {
  3102. unsigned long mask = args->exp->ex_layout_types;
  3103. int i;
  3104. /* Hamming weight of @mask is the number of layout types to return */
  3105. if (xdr_stream_encode_u32(xdr, hweight_long(mask)) != XDR_UNIT)
  3106. return nfserr_resource;
  3107. for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i)
  3108. if (mask & BIT(i)) {
  3109. /* layouttype4 */
  3110. if (xdr_stream_encode_u32(xdr, i) != XDR_UNIT)
  3111. return nfserr_resource;
  3112. }
  3113. return nfs_ok;
  3114. }
  3115. static __be32 nfsd4_encode_fattr4_layout_types(struct xdr_stream *xdr,
  3116. const struct nfsd4_fattr_args *args)
  3117. {
  3118. unsigned long mask = args->exp->ex_layout_types;
  3119. int i;
  3120. /* Hamming weight of @mask is the number of layout types to return */
  3121. if (xdr_stream_encode_u32(xdr, hweight_long(mask)) != XDR_UNIT)
  3122. return nfserr_resource;
  3123. for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i)
  3124. if (mask & BIT(i)) {
  3125. /* layouttype4 */
  3126. if (xdr_stream_encode_u32(xdr, i) != XDR_UNIT)
  3127. return nfserr_resource;
  3128. }
  3129. return nfs_ok;
  3130. }
  3131. static __be32 nfsd4_encode_fattr4_layout_blksize(struct xdr_stream *xdr,
  3132. const struct nfsd4_fattr_args *args)
  3133. {
  3134. return nfsd4_encode_uint32_t(xdr, args->stat.blksize);
  3135. }
  3136. #endif
  3137. static __be32 nfsd4_encode_fattr4_suppattr_exclcreat(struct xdr_stream *xdr,
  3138. const struct nfsd4_fattr_args *args)
  3139. {
  3140. struct nfsd4_compoundres *resp = args->rqstp->rq_resp;
  3141. u32 supp[3];
  3142. memcpy(supp, nfsd_suppattrs[resp->cstate.minorversion], sizeof(supp));
  3143. if (!IS_POSIXACL(d_inode(args->dentry)))
  3144. supp[0] &= ~FATTR4_WORD0_ACL;
  3145. if (!args->contextsupport)
  3146. supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3147. supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0;
  3148. supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1;
  3149. supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2;
  3150. return nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
  3151. }
  3152. /*
  3153. * Copied from generic_remap_checks/generic_remap_file_range_prep.
  3154. *
  3155. * These generic functions use the file system's s_blocksize, but
  3156. * individual file systems aren't required to use
  3157. * generic_remap_file_range_prep. Until there is a mechanism for
  3158. * determining a particular file system's (or file's) clone block
  3159. * size, this is the best NFSD can do.
  3160. */
  3161. static __be32 nfsd4_encode_fattr4_clone_blksize(struct xdr_stream *xdr,
  3162. const struct nfsd4_fattr_args *args)
  3163. {
  3164. struct inode *inode = d_inode(args->dentry);
  3165. return nfsd4_encode_uint32_t(xdr, inode->i_sb->s_blocksize);
  3166. }
  3167. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  3168. static __be32 nfsd4_encode_fattr4_sec_label(struct xdr_stream *xdr,
  3169. const struct nfsd4_fattr_args *args)
  3170. {
  3171. return nfsd4_encode_security_label(xdr, args->rqstp, &args->context);
  3172. }
  3173. #endif
  3174. static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
  3175. const struct nfsd4_fattr_args *args)
  3176. {
  3177. int err = xattr_supports_user_prefix(d_inode(args->dentry));
  3178. return nfsd4_encode_bool(xdr, err == 0);
  3179. }
  3180. #define NFSD_OA_SHARE_ACCESS (BIT(OPEN_ARGS_SHARE_ACCESS_READ) | \
  3181. BIT(OPEN_ARGS_SHARE_ACCESS_WRITE) | \
  3182. BIT(OPEN_ARGS_SHARE_ACCESS_BOTH))
  3183. #define NFSD_OA_SHARE_DENY (BIT(OPEN_ARGS_SHARE_DENY_NONE) | \
  3184. BIT(OPEN_ARGS_SHARE_DENY_READ) | \
  3185. BIT(OPEN_ARGS_SHARE_DENY_WRITE) | \
  3186. BIT(OPEN_ARGS_SHARE_DENY_BOTH))
  3187. #define NFSD_OA_SHARE_ACCESS_WANT (BIT(OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG) | \
  3188. BIT(OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG) | \
  3189. BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL) | \
  3190. BIT(OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS) | \
  3191. BIT(OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION))
  3192. #define NFSD_OA_OPEN_CLAIM (BIT(OPEN_ARGS_OPEN_CLAIM_NULL) | \
  3193. BIT(OPEN_ARGS_OPEN_CLAIM_PREVIOUS) | \
  3194. BIT(OPEN_ARGS_OPEN_CLAIM_DELEGATE_CUR) | \
  3195. BIT(OPEN_ARGS_OPEN_CLAIM_DELEGATE_PREV)| \
  3196. BIT(OPEN_ARGS_OPEN_CLAIM_FH) | \
  3197. BIT(OPEN_ARGS_OPEN_CLAIM_DELEG_CUR_FH) | \
  3198. BIT(OPEN_ARGS_OPEN_CLAIM_DELEG_PREV_FH))
  3199. #define NFSD_OA_CREATE_MODE (BIT(OPEN_ARGS_CREATEMODE_UNCHECKED4) | \
  3200. BIT(OPEN_ARGS_CREATE_MODE_GUARDED) | \
  3201. BIT(OPEN_ARGS_CREATEMODE_EXCLUSIVE4) | \
  3202. BIT(OPEN_ARGS_CREATE_MODE_EXCLUSIVE4_1))
  3203. static uint32_t oa_share_access = NFSD_OA_SHARE_ACCESS;
  3204. static uint32_t oa_share_deny = NFSD_OA_SHARE_DENY;
  3205. static uint32_t oa_share_access_want = NFSD_OA_SHARE_ACCESS_WANT;
  3206. static uint32_t oa_open_claim = NFSD_OA_OPEN_CLAIM;
  3207. static uint32_t oa_create_mode = NFSD_OA_CREATE_MODE;
  3208. static const struct open_arguments4 nfsd_open_arguments = {
  3209. .oa_share_access = { .count = 1, .element = &oa_share_access },
  3210. .oa_share_deny = { .count = 1, .element = &oa_share_deny },
  3211. .oa_share_access_want = { .count = 1, .element = &oa_share_access_want },
  3212. .oa_open_claim = { .count = 1, .element = &oa_open_claim },
  3213. .oa_create_mode = { .count = 1, .element = &oa_create_mode },
  3214. };
  3215. static __be32 nfsd4_encode_fattr4_open_arguments(struct xdr_stream *xdr,
  3216. const struct nfsd4_fattr_args *args)
  3217. {
  3218. if (!xdrgen_encode_fattr4_open_arguments(xdr, &nfsd_open_arguments))
  3219. return nfserr_resource;
  3220. return nfs_ok;
  3221. }
  3222. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  3223. static __be32 nfsd4_encode_fattr4_acl_trueform(struct xdr_stream *xdr,
  3224. const struct nfsd4_fattr_args *args)
  3225. {
  3226. aclmodel4 trueform = ACL_MODEL_NONE;
  3227. if (IS_POSIXACL(d_inode(args->dentry)))
  3228. trueform = ACL_MODEL_POSIX_DRAFT;
  3229. if (!xdrgen_encode_aclmodel4(xdr, trueform))
  3230. return nfserr_resource;
  3231. return nfs_ok;
  3232. }
  3233. static __be32 nfsd4_encode_fattr4_acl_trueform_scope(struct xdr_stream *xdr,
  3234. const struct nfsd4_fattr_args *args)
  3235. {
  3236. if (!xdrgen_encode_aclscope4(xdr, ACL_SCOPE_FILE_SYSTEM))
  3237. return nfserr_resource;
  3238. return nfs_ok;
  3239. }
  3240. static __be32 nfsd4_encode_fattr4_posix_default_acl(struct xdr_stream *xdr,
  3241. const struct nfsd4_fattr_args *args)
  3242. {
  3243. return nfsd4_encode_posixacl(xdr, args->rqstp, args->dpacl);
  3244. }
  3245. static __be32 nfsd4_encode_fattr4_posix_access_acl(struct xdr_stream *xdr,
  3246. const struct nfsd4_fattr_args *args)
  3247. {
  3248. return nfsd4_encode_posixacl(xdr, args->rqstp, args->pacl);
  3249. }
  3250. #endif /* CONFIG_NFSD_V4_POSIX_ACLS */
  3251. static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
  3252. [FATTR4_SUPPORTED_ATTRS] = nfsd4_encode_fattr4_supported_attrs,
  3253. [FATTR4_TYPE] = nfsd4_encode_fattr4_type,
  3254. [FATTR4_FH_EXPIRE_TYPE] = nfsd4_encode_fattr4_fh_expire_type,
  3255. [FATTR4_CHANGE] = nfsd4_encode_fattr4_change,
  3256. [FATTR4_SIZE] = nfsd4_encode_fattr4_size,
  3257. [FATTR4_LINK_SUPPORT] = nfsd4_encode_fattr4__true,
  3258. [FATTR4_SYMLINK_SUPPORT] = nfsd4_encode_fattr4__true,
  3259. [FATTR4_NAMED_ATTR] = nfsd4_encode_fattr4__false,
  3260. [FATTR4_FSID] = nfsd4_encode_fattr4_fsid,
  3261. [FATTR4_UNIQUE_HANDLES] = nfsd4_encode_fattr4__true,
  3262. [FATTR4_LEASE_TIME] = nfsd4_encode_fattr4_lease_time,
  3263. [FATTR4_RDATTR_ERROR] = nfsd4_encode_fattr4_rdattr_error,
  3264. [FATTR4_ACL] = nfsd4_encode_fattr4_acl,
  3265. [FATTR4_ACLSUPPORT] = nfsd4_encode_fattr4_aclsupport,
  3266. [FATTR4_ARCHIVE] = nfsd4_encode_fattr4__noop,
  3267. [FATTR4_CANSETTIME] = nfsd4_encode_fattr4__true,
  3268. [FATTR4_CASE_INSENSITIVE] = nfsd4_encode_fattr4__false,
  3269. [FATTR4_CASE_PRESERVING] = nfsd4_encode_fattr4__true,
  3270. [FATTR4_CHOWN_RESTRICTED] = nfsd4_encode_fattr4__true,
  3271. [FATTR4_FILEHANDLE] = nfsd4_encode_fattr4_filehandle,
  3272. [FATTR4_FILEID] = nfsd4_encode_fattr4_fileid,
  3273. [FATTR4_FILES_AVAIL] = nfsd4_encode_fattr4_files_avail,
  3274. [FATTR4_FILES_FREE] = nfsd4_encode_fattr4_files_free,
  3275. [FATTR4_FILES_TOTAL] = nfsd4_encode_fattr4_files_total,
  3276. [FATTR4_FS_LOCATIONS] = nfsd4_encode_fattr4_fs_locations,
  3277. [FATTR4_HIDDEN] = nfsd4_encode_fattr4__noop,
  3278. [FATTR4_HOMOGENEOUS] = nfsd4_encode_fattr4__true,
  3279. [FATTR4_MAXFILESIZE] = nfsd4_encode_fattr4_maxfilesize,
  3280. [FATTR4_MAXLINK] = nfsd4_encode_fattr4_maxlink,
  3281. [FATTR4_MAXNAME] = nfsd4_encode_fattr4_maxname,
  3282. [FATTR4_MAXREAD] = nfsd4_encode_fattr4_maxread,
  3283. [FATTR4_MAXWRITE] = nfsd4_encode_fattr4_maxwrite,
  3284. [FATTR4_MIMETYPE] = nfsd4_encode_fattr4__noop,
  3285. [FATTR4_MODE] = nfsd4_encode_fattr4_mode,
  3286. [FATTR4_NO_TRUNC] = nfsd4_encode_fattr4__true,
  3287. [FATTR4_NUMLINKS] = nfsd4_encode_fattr4_numlinks,
  3288. [FATTR4_OWNER] = nfsd4_encode_fattr4_owner,
  3289. [FATTR4_OWNER_GROUP] = nfsd4_encode_fattr4_owner_group,
  3290. [FATTR4_QUOTA_AVAIL_HARD] = nfsd4_encode_fattr4__noop,
  3291. [FATTR4_QUOTA_AVAIL_SOFT] = nfsd4_encode_fattr4__noop,
  3292. [FATTR4_QUOTA_USED] = nfsd4_encode_fattr4__noop,
  3293. [FATTR4_RAWDEV] = nfsd4_encode_fattr4_rawdev,
  3294. [FATTR4_SPACE_AVAIL] = nfsd4_encode_fattr4_space_avail,
  3295. [FATTR4_SPACE_FREE] = nfsd4_encode_fattr4_space_free,
  3296. [FATTR4_SPACE_TOTAL] = nfsd4_encode_fattr4_space_total,
  3297. [FATTR4_SPACE_USED] = nfsd4_encode_fattr4_space_used,
  3298. [FATTR4_SYSTEM] = nfsd4_encode_fattr4__noop,
  3299. [FATTR4_TIME_ACCESS] = nfsd4_encode_fattr4_time_access,
  3300. [FATTR4_TIME_ACCESS_SET] = nfsd4_encode_fattr4__noop,
  3301. [FATTR4_TIME_BACKUP] = nfsd4_encode_fattr4__noop,
  3302. [FATTR4_TIME_CREATE] = nfsd4_encode_fattr4_time_create,
  3303. [FATTR4_TIME_DELTA] = nfsd4_encode_fattr4_time_delta,
  3304. [FATTR4_TIME_METADATA] = nfsd4_encode_fattr4_time_metadata,
  3305. [FATTR4_TIME_MODIFY] = nfsd4_encode_fattr4_time_modify,
  3306. [FATTR4_TIME_MODIFY_SET] = nfsd4_encode_fattr4__noop,
  3307. [FATTR4_MOUNTED_ON_FILEID] = nfsd4_encode_fattr4_mounted_on_fileid,
  3308. [FATTR4_DIR_NOTIF_DELAY] = nfsd4_encode_fattr4__noop,
  3309. [FATTR4_DIRENT_NOTIF_DELAY] = nfsd4_encode_fattr4__noop,
  3310. [FATTR4_DACL] = nfsd4_encode_fattr4__noop,
  3311. [FATTR4_SACL] = nfsd4_encode_fattr4__noop,
  3312. [FATTR4_CHANGE_POLICY] = nfsd4_encode_fattr4__noop,
  3313. [FATTR4_FS_STATUS] = nfsd4_encode_fattr4__noop,
  3314. #ifdef CONFIG_NFSD_PNFS
  3315. [FATTR4_FS_LAYOUT_TYPES] = nfsd4_encode_fattr4_fs_layout_types,
  3316. [FATTR4_LAYOUT_HINT] = nfsd4_encode_fattr4__noop,
  3317. [FATTR4_LAYOUT_TYPES] = nfsd4_encode_fattr4_layout_types,
  3318. [FATTR4_LAYOUT_BLKSIZE] = nfsd4_encode_fattr4_layout_blksize,
  3319. [FATTR4_LAYOUT_ALIGNMENT] = nfsd4_encode_fattr4__noop,
  3320. #else
  3321. [FATTR4_FS_LAYOUT_TYPES] = nfsd4_encode_fattr4__noop,
  3322. [FATTR4_LAYOUT_HINT] = nfsd4_encode_fattr4__noop,
  3323. [FATTR4_LAYOUT_TYPES] = nfsd4_encode_fattr4__noop,
  3324. [FATTR4_LAYOUT_BLKSIZE] = nfsd4_encode_fattr4__noop,
  3325. [FATTR4_LAYOUT_ALIGNMENT] = nfsd4_encode_fattr4__noop,
  3326. #endif
  3327. [FATTR4_FS_LOCATIONS_INFO] = nfsd4_encode_fattr4__noop,
  3328. [FATTR4_MDSTHRESHOLD] = nfsd4_encode_fattr4__noop,
  3329. [FATTR4_RETENTION_GET] = nfsd4_encode_fattr4__noop,
  3330. [FATTR4_RETENTION_SET] = nfsd4_encode_fattr4__noop,
  3331. [FATTR4_RETENTEVT_GET] = nfsd4_encode_fattr4__noop,
  3332. [FATTR4_RETENTEVT_SET] = nfsd4_encode_fattr4__noop,
  3333. [FATTR4_RETENTION_HOLD] = nfsd4_encode_fattr4__noop,
  3334. [FATTR4_MODE_SET_MASKED] = nfsd4_encode_fattr4__noop,
  3335. [FATTR4_SUPPATTR_EXCLCREAT] = nfsd4_encode_fattr4_suppattr_exclcreat,
  3336. [FATTR4_FS_CHARSET_CAP] = nfsd4_encode_fattr4__noop,
  3337. [FATTR4_CLONE_BLKSIZE] = nfsd4_encode_fattr4_clone_blksize,
  3338. [FATTR4_SPACE_FREED] = nfsd4_encode_fattr4__noop,
  3339. [FATTR4_CHANGE_ATTR_TYPE] = nfsd4_encode_fattr4__noop,
  3340. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  3341. [FATTR4_SEC_LABEL] = nfsd4_encode_fattr4_sec_label,
  3342. #else
  3343. [FATTR4_SEC_LABEL] = nfsd4_encode_fattr4__noop,
  3344. #endif
  3345. [FATTR4_MODE_UMASK] = nfsd4_encode_fattr4__noop,
  3346. [FATTR4_XATTR_SUPPORT] = nfsd4_encode_fattr4_xattr_support,
  3347. [FATTR4_TIME_DELEG_ACCESS] = nfsd4_encode_fattr4__inval,
  3348. [FATTR4_TIME_DELEG_MODIFY] = nfsd4_encode_fattr4__inval,
  3349. [FATTR4_OPEN_ARGUMENTS] = nfsd4_encode_fattr4_open_arguments,
  3350. /* Reserved */
  3351. [87] = nfsd4_encode_fattr4__inval,
  3352. [88] = nfsd4_encode_fattr4__inval,
  3353. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  3354. [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4_acl_trueform,
  3355. [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4_acl_trueform_scope,
  3356. [FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4_posix_default_acl,
  3357. [FATTR4_POSIX_ACCESS_ACL] = nfsd4_encode_fattr4_posix_access_acl,
  3358. #else
  3359. [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4__noop,
  3360. [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4__noop,
  3361. [FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4__noop,
  3362. [FATTR4_POSIX_ACCESS_ACL] = nfsd4_encode_fattr4__noop,
  3363. #endif
  3364. };
  3365. /*
  3366. * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  3367. * ourselves.
  3368. */
  3369. static __be32
  3370. nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
  3371. struct svc_fh *fhp, struct svc_export *exp,
  3372. struct dentry *dentry, const u32 *bmval,
  3373. int ignore_crossmnt)
  3374. {
  3375. DECLARE_BITMAP(attr_bitmap, ARRAY_SIZE(nfsd4_enc_fattr4_encode_ops));
  3376. struct nfs4_delegation *dp = NULL;
  3377. struct nfsd4_fattr_args args;
  3378. struct svc_fh *tempfh = NULL;
  3379. int starting_len = xdr->buf->len;
  3380. unsigned int attrlen_offset;
  3381. __be32 attrlen, status;
  3382. u32 attrmask[3];
  3383. int err;
  3384. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  3385. u32 minorversion = resp->cstate.minorversion;
  3386. struct path path = {
  3387. .mnt = exp->ex_path.mnt,
  3388. .dentry = dentry,
  3389. };
  3390. unsigned long bit;
  3391. WARN_ON_ONCE(bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1);
  3392. WARN_ON_ONCE(!nfsd_attrs_supported(minorversion, bmval));
  3393. args.rqstp = rqstp;
  3394. args.exp = exp;
  3395. args.dentry = dentry;
  3396. args.ignore_crossmnt = (ignore_crossmnt != 0);
  3397. args.acl = NULL;
  3398. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  3399. args.context.context = NULL;
  3400. #endif
  3401. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  3402. args.dpacl = NULL;
  3403. args.pacl = NULL;
  3404. #endif
  3405. /*
  3406. * Make a local copy of the attribute bitmap that can be modified.
  3407. */
  3408. attrmask[0] = bmval[0];
  3409. attrmask[1] = bmval[1];
  3410. attrmask[2] = bmval[2];
  3411. args.rdattr_err = 0;
  3412. if (exp->ex_fslocs.migrated) {
  3413. status = fattr_handle_absent_fs(&attrmask[0], &attrmask[1],
  3414. &attrmask[2], &args.rdattr_err);
  3415. if (status)
  3416. goto out;
  3417. }
  3418. if ((attrmask[0] & (FATTR4_WORD0_CHANGE |
  3419. FATTR4_WORD0_SIZE)) ||
  3420. (attrmask[1] & (FATTR4_WORD1_TIME_ACCESS |
  3421. FATTR4_WORD1_TIME_MODIFY |
  3422. FATTR4_WORD1_TIME_METADATA))) {
  3423. status = nfsd4_deleg_getattr_conflict(rqstp, dentry, &dp);
  3424. if (status)
  3425. goto out;
  3426. }
  3427. err = vfs_getattr(&path, &args.stat,
  3428. STATX_BASIC_STATS | STATX_BTIME | STATX_CHANGE_COOKIE,
  3429. AT_STATX_SYNC_AS_STAT);
  3430. if (dp) {
  3431. struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr;
  3432. if (ncf->ncf_file_modified) {
  3433. ++ncf->ncf_initial_cinfo;
  3434. args.stat.size = ncf->ncf_cur_fsize;
  3435. if (!timespec64_is_epoch(&ncf->ncf_cb_mtime))
  3436. args.stat.mtime = ncf->ncf_cb_mtime;
  3437. }
  3438. args.change_attr = ncf->ncf_initial_cinfo;
  3439. if (!timespec64_is_epoch(&ncf->ncf_cb_atime))
  3440. args.stat.atime = ncf->ncf_cb_atime;
  3441. nfs4_put_stid(&dp->dl_stid);
  3442. } else {
  3443. args.change_attr = nfsd4_change_attribute(&args.stat);
  3444. }
  3445. if (err)
  3446. goto out_nfserr;
  3447. if (!(args.stat.result_mask & STATX_BTIME))
  3448. /* underlying FS does not offer btime so we can't share it */
  3449. attrmask[1] &= ~FATTR4_WORD1_TIME_CREATE;
  3450. if ((attrmask[0] & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
  3451. FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) ||
  3452. (attrmask[1] & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
  3453. FATTR4_WORD1_SPACE_TOTAL))) {
  3454. err = vfs_statfs(&path, &args.statfs);
  3455. if (err)
  3456. goto out_nfserr;
  3457. }
  3458. if ((attrmask[0] & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) &&
  3459. !fhp) {
  3460. tempfh = kmalloc_obj(struct svc_fh);
  3461. status = nfserr_jukebox;
  3462. if (!tempfh)
  3463. goto out;
  3464. fh_init(tempfh, NFS4_FHSIZE);
  3465. status = fh_compose(tempfh, exp, dentry, NULL);
  3466. if (status)
  3467. goto out;
  3468. args.fhp = tempfh;
  3469. } else
  3470. args.fhp = fhp;
  3471. if (attrmask[0] & FATTR4_WORD0_ACL) {
  3472. err = nfsd4_get_nfs4_acl(rqstp, dentry, &args.acl);
  3473. if (err == -EOPNOTSUPP)
  3474. attrmask[0] &= ~FATTR4_WORD0_ACL;
  3475. else if (err == -EINVAL) {
  3476. status = nfserr_attrnotsupp;
  3477. goto out;
  3478. } else if (err != 0)
  3479. goto out_nfserr;
  3480. }
  3481. args.contextsupport = false;
  3482. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  3483. if ((attrmask[2] & FATTR4_WORD2_SECURITY_LABEL) ||
  3484. attrmask[0] & FATTR4_WORD0_SUPPORTED_ATTRS) {
  3485. if (exp->ex_flags & NFSEXP_SECURITY_LABEL)
  3486. err = security_inode_getsecctx(d_inode(dentry),
  3487. &args.context);
  3488. else
  3489. err = -EOPNOTSUPP;
  3490. args.contextsupport = (err == 0);
  3491. if (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL) {
  3492. if (err == -EOPNOTSUPP)
  3493. attrmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3494. else if (err)
  3495. goto out_nfserr;
  3496. }
  3497. }
  3498. #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
  3499. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  3500. if (attrmask[2] & FATTR4_WORD2_POSIX_DEFAULT_ACL) {
  3501. struct inode *inode = d_inode(dentry);
  3502. struct posix_acl *dpacl;
  3503. if (S_ISDIR(inode->i_mode)) {
  3504. dpacl = get_inode_acl(inode, ACL_TYPE_DEFAULT);
  3505. if (IS_ERR(dpacl)) {
  3506. switch (PTR_ERR(dpacl)) {
  3507. case -EOPNOTSUPP:
  3508. attrmask[2] &= ~FATTR4_WORD2_POSIX_DEFAULT_ACL;
  3509. break;
  3510. case -EINVAL:
  3511. status = nfserr_attrnotsupp;
  3512. goto out;
  3513. default:
  3514. err = PTR_ERR(dpacl);
  3515. goto out_nfserr;
  3516. }
  3517. } else {
  3518. args.dpacl = dpacl;
  3519. }
  3520. }
  3521. }
  3522. if (attrmask[2] & FATTR4_WORD2_POSIX_ACCESS_ACL) {
  3523. struct inode *inode = d_inode(dentry);
  3524. struct posix_acl *pacl;
  3525. pacl = get_inode_acl(inode, ACL_TYPE_ACCESS);
  3526. if (!pacl)
  3527. pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
  3528. if (IS_ERR(pacl)) {
  3529. switch (PTR_ERR(pacl)) {
  3530. case -EOPNOTSUPP:
  3531. attrmask[2] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL;
  3532. break;
  3533. case -EINVAL:
  3534. status = nfserr_attrnotsupp;
  3535. goto out;
  3536. default:
  3537. err = PTR_ERR(pacl);
  3538. goto out_nfserr;
  3539. }
  3540. } else {
  3541. args.pacl = pacl;
  3542. }
  3543. }
  3544. #endif /* CONFIG_NFSD_V4_POSIX_ACLS */
  3545. /* attrmask */
  3546. status = nfsd4_encode_bitmap4(xdr, attrmask[0], attrmask[1],
  3547. attrmask[2]);
  3548. if (status)
  3549. goto out;
  3550. /* attr_vals */
  3551. attrlen_offset = xdr->buf->len;
  3552. if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT)))
  3553. goto out_resource;
  3554. bitmap_from_arr32(attr_bitmap, attrmask,
  3555. ARRAY_SIZE(nfsd4_enc_fattr4_encode_ops));
  3556. for_each_set_bit(bit, attr_bitmap,
  3557. ARRAY_SIZE(nfsd4_enc_fattr4_encode_ops)) {
  3558. status = nfsd4_enc_fattr4_encode_ops[bit](xdr, &args);
  3559. if (status != nfs_ok)
  3560. goto out;
  3561. }
  3562. attrlen = cpu_to_be32(xdr->buf->len - attrlen_offset - XDR_UNIT);
  3563. write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, XDR_UNIT);
  3564. status = nfs_ok;
  3565. out:
  3566. #ifdef CONFIG_NFSD_V4_POSIX_ACLS
  3567. if (args.dpacl)
  3568. posix_acl_release(args.dpacl);
  3569. if (args.pacl)
  3570. posix_acl_release(args.pacl);
  3571. #endif /* CONFIG_NFSD_V4_POSIX_ACLS */
  3572. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  3573. if (args.context.context)
  3574. security_release_secctx(&args.context);
  3575. #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
  3576. kfree(args.acl);
  3577. if (tempfh) {
  3578. fh_put(tempfh);
  3579. kfree(tempfh);
  3580. }
  3581. if (status)
  3582. xdr_truncate_encode(xdr, starting_len);
  3583. return status;
  3584. out_nfserr:
  3585. status = nfserrno(err);
  3586. goto out;
  3587. out_resource:
  3588. status = nfserr_resource;
  3589. goto out;
  3590. }
  3591. static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr,
  3592. struct xdr_buf *buf, __be32 *p, int bytes)
  3593. {
  3594. xdr->scratch.iov_len = 0;
  3595. memset(buf, 0, sizeof(struct xdr_buf));
  3596. buf->head[0].iov_base = p;
  3597. buf->head[0].iov_len = 0;
  3598. buf->len = 0;
  3599. xdr->buf = buf;
  3600. xdr->iov = buf->head;
  3601. xdr->p = p;
  3602. xdr->end = (void *)p + bytes;
  3603. buf->buflen = bytes;
  3604. }
  3605. __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
  3606. struct svc_fh *fhp, struct svc_export *exp,
  3607. struct dentry *dentry, u32 *bmval,
  3608. struct svc_rqst *rqstp, int ignore_crossmnt)
  3609. {
  3610. struct xdr_buf dummy;
  3611. struct xdr_stream xdr;
  3612. __be32 ret;
  3613. svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2);
  3614. ret = nfsd4_encode_fattr4(rqstp, &xdr, fhp, exp, dentry, bmval,
  3615. ignore_crossmnt);
  3616. *p = xdr.p;
  3617. return ret;
  3618. }
  3619. /*
  3620. * The buffer space for this field was reserved during a previous
  3621. * call to nfsd4_encode_entry4().
  3622. */
  3623. static void nfsd4_encode_entry4_nfs_cookie4(const struct nfsd4_readdir *readdir,
  3624. u64 offset)
  3625. {
  3626. __be64 cookie = cpu_to_be64(offset);
  3627. struct xdr_stream *xdr = readdir->xdr;
  3628. if (!readdir->cookie_offset)
  3629. return;
  3630. write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, &cookie,
  3631. sizeof(cookie));
  3632. }
  3633. static inline int attributes_need_mount(u32 *bmval)
  3634. {
  3635. if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
  3636. return 1;
  3637. if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
  3638. return 1;
  3639. return 0;
  3640. }
  3641. static __be32
  3642. nfsd4_encode_entry4_fattr(struct nfsd4_readdir *cd, const char *name,
  3643. int namlen)
  3644. {
  3645. struct svc_export *exp = cd->rd_fhp->fh_export;
  3646. struct dentry *dentry;
  3647. __be32 nfserr;
  3648. int ignore_crossmnt = 0;
  3649. dentry = lookup_one_positive_unlocked(&nop_mnt_idmap,
  3650. &QSTR_LEN(name, namlen),
  3651. cd->rd_fhp->fh_dentry);
  3652. if (IS_ERR(dentry))
  3653. return nfserrno(PTR_ERR(dentry));
  3654. exp_get(exp);
  3655. /*
  3656. * In the case of a mountpoint, the client may be asking for
  3657. * attributes that are only properties of the underlying filesystem
  3658. * as opposed to the cross-mounted file system. In such a case,
  3659. * we will not follow the cross mount and will fill the attribtutes
  3660. * directly from the mountpoint dentry.
  3661. */
  3662. if (nfsd_mountpoint(dentry, exp)) {
  3663. int err;
  3664. if (!(exp->ex_flags & NFSEXP_V4ROOT)
  3665. && !attributes_need_mount(cd->rd_bmval)) {
  3666. ignore_crossmnt = 1;
  3667. goto out_encode;
  3668. }
  3669. /*
  3670. * Why the heck aren't we just using nfsd_lookup??
  3671. * Different "."/".." handling? Something else?
  3672. * At least, add a comment here to explain....
  3673. */
  3674. err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
  3675. if (err) {
  3676. nfserr = nfserrno(err);
  3677. goto out_put;
  3678. }
  3679. nfserr = check_nfsd_access(exp, cd->rd_rqstp, false);
  3680. if (nfserr)
  3681. goto out_put;
  3682. }
  3683. out_encode:
  3684. nfserr = nfsd4_encode_fattr4(cd->rd_rqstp, cd->xdr, NULL, exp, dentry,
  3685. cd->rd_bmval, ignore_crossmnt);
  3686. out_put:
  3687. dput(dentry);
  3688. exp_put(exp);
  3689. return nfserr;
  3690. }
  3691. static __be32
  3692. nfsd4_encode_entry4_rdattr_error(struct xdr_stream *xdr, __be32 nfserr)
  3693. {
  3694. __be32 status;
  3695. /* attrmask */
  3696. status = nfsd4_encode_bitmap4(xdr, FATTR4_WORD0_RDATTR_ERROR, 0, 0);
  3697. if (status != nfs_ok)
  3698. return status;
  3699. /* attr_vals */
  3700. if (xdr_stream_encode_u32(xdr, XDR_UNIT) != XDR_UNIT)
  3701. return nfserr_resource;
  3702. /* rdattr_error */
  3703. if (xdr_stream_encode_be32(xdr, nfserr) != XDR_UNIT)
  3704. return nfserr_resource;
  3705. return nfs_ok;
  3706. }
  3707. static int
  3708. nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
  3709. loff_t offset, u64 ino, unsigned int d_type)
  3710. {
  3711. struct readdir_cd *ccd = ccdv;
  3712. struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
  3713. struct xdr_stream *xdr = cd->xdr;
  3714. int start_offset = xdr->buf->len;
  3715. int cookie_offset;
  3716. u32 name_and_cookie;
  3717. int entry_bytes;
  3718. __be32 nfserr = nfserr_toosmall;
  3719. /* In nfsv4, "." and ".." never make it onto the wire.. */
  3720. if (name && isdotent(name, namlen)) {
  3721. cd->common.err = nfs_ok;
  3722. return 0;
  3723. }
  3724. /* Encode the previous entry's cookie value */
  3725. nfsd4_encode_entry4_nfs_cookie4(cd, offset);
  3726. if (xdr_stream_encode_item_present(xdr) != XDR_UNIT)
  3727. goto fail;
  3728. /* Reserve send buffer space for this entry's cookie value. */
  3729. cookie_offset = xdr->buf->len;
  3730. if (nfsd4_encode_nfs_cookie4(xdr, OFFSET_MAX) != nfs_ok)
  3731. goto fail;
  3732. if (nfsd4_encode_component4(xdr, name, namlen) != nfs_ok)
  3733. goto fail;
  3734. nfserr = nfsd4_encode_entry4_fattr(cd, name, namlen);
  3735. switch (nfserr) {
  3736. case nfs_ok:
  3737. break;
  3738. case nfserr_resource:
  3739. nfserr = nfserr_toosmall;
  3740. goto fail;
  3741. case nfserr_noent:
  3742. xdr_truncate_encode(xdr, start_offset);
  3743. goto skip_entry;
  3744. case nfserr_jukebox:
  3745. /*
  3746. * The pseudoroot should only display dentries that lead to
  3747. * exports. If we get EJUKEBOX here, then we can't tell whether
  3748. * this entry should be included. Just fail the whole READDIR
  3749. * with NFS4ERR_DELAY in that case, and hope that the situation
  3750. * will resolve itself by the client's next attempt.
  3751. */
  3752. if (cd->rd_fhp->fh_export->ex_flags & NFSEXP_V4ROOT)
  3753. goto fail;
  3754. fallthrough;
  3755. default:
  3756. /*
  3757. * If the client requested the RDATTR_ERROR attribute,
  3758. * we stuff the error code into this attribute
  3759. * and continue. If this attribute was not requested,
  3760. * then in accordance with the spec, we fail the
  3761. * entire READDIR operation(!)
  3762. */
  3763. if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
  3764. goto fail;
  3765. if (nfsd4_encode_entry4_rdattr_error(xdr, nfserr)) {
  3766. nfserr = nfserr_toosmall;
  3767. goto fail;
  3768. }
  3769. }
  3770. nfserr = nfserr_toosmall;
  3771. entry_bytes = xdr->buf->len - start_offset;
  3772. if (entry_bytes > cd->rd_maxcount)
  3773. goto fail;
  3774. cd->rd_maxcount -= entry_bytes;
  3775. /*
  3776. * RFC 3530 14.2.24 describes rd_dircount as only a "hint", and
  3777. * notes that it could be zero. If it is zero, then the server
  3778. * should enforce only the rd_maxcount value.
  3779. */
  3780. if (cd->rd_dircount) {
  3781. name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8;
  3782. if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
  3783. goto fail;
  3784. cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
  3785. if (!cd->rd_dircount)
  3786. cd->rd_maxcount = 0;
  3787. }
  3788. cd->cookie_offset = cookie_offset;
  3789. skip_entry:
  3790. cd->common.err = nfs_ok;
  3791. return 0;
  3792. fail:
  3793. xdr_truncate_encode(xdr, start_offset);
  3794. cd->common.err = nfserr;
  3795. return -EINVAL;
  3796. }
  3797. static __be32
  3798. nfsd4_encode_verifier4(struct xdr_stream *xdr, const nfs4_verifier *verf)
  3799. {
  3800. __be32 *p;
  3801. p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
  3802. if (!p)
  3803. return nfserr_resource;
  3804. memcpy(p, verf->data, sizeof(verf->data));
  3805. return nfs_ok;
  3806. }
  3807. static __be32
  3808. nfsd4_encode_clientid4(struct xdr_stream *xdr, const clientid_t *clientid)
  3809. {
  3810. __be32 *p;
  3811. p = xdr_reserve_space(xdr, sizeof(__be64));
  3812. if (!p)
  3813. return nfserr_resource;
  3814. memcpy(p, clientid, sizeof(*clientid));
  3815. return nfs_ok;
  3816. }
  3817. /* This is a frequently-encoded item; open-coded for speed */
  3818. static __be32
  3819. nfsd4_encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid)
  3820. {
  3821. __be32 *p;
  3822. p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE);
  3823. if (!p)
  3824. return nfserr_resource;
  3825. *p++ = cpu_to_be32(sid->si_generation);
  3826. memcpy(p, &sid->si_opaque, sizeof(sid->si_opaque));
  3827. return nfs_ok;
  3828. }
  3829. static __be32
  3830. nfsd4_encode_sessionid4(struct xdr_stream *xdr,
  3831. const struct nfs4_sessionid *sessionid)
  3832. {
  3833. return nfsd4_encode_opaque_fixed(xdr, sessionid->data,
  3834. NFS4_MAX_SESSIONID_LEN);
  3835. }
  3836. static __be32
  3837. nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr,
  3838. union nfsd4_op_u *u)
  3839. {
  3840. struct nfsd4_access *access = &u->access;
  3841. struct xdr_stream *xdr = resp->xdr;
  3842. __be32 status;
  3843. /* supported */
  3844. status = nfsd4_encode_uint32_t(xdr, access->ac_supported);
  3845. if (status != nfs_ok)
  3846. return status;
  3847. /* access */
  3848. return nfsd4_encode_uint32_t(xdr, access->ac_resp_access);
  3849. }
  3850. static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr,
  3851. union nfsd4_op_u *u)
  3852. {
  3853. struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session;
  3854. struct xdr_stream *xdr = resp->xdr;
  3855. /* bctsr_sessid */
  3856. nfserr = nfsd4_encode_sessionid4(xdr, &bcts->sessionid);
  3857. if (nfserr != nfs_ok)
  3858. return nfserr;
  3859. /* bctsr_dir */
  3860. if (xdr_stream_encode_u32(xdr, bcts->dir) != XDR_UNIT)
  3861. return nfserr_resource;
  3862. /* bctsr_use_conn_in_rdma_mode */
  3863. return nfsd4_encode_bool(xdr, false);
  3864. }
  3865. static __be32
  3866. nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr,
  3867. union nfsd4_op_u *u)
  3868. {
  3869. struct nfsd4_close *close = &u->close;
  3870. struct xdr_stream *xdr = resp->xdr;
  3871. /* open_stateid */
  3872. return nfsd4_encode_stateid4(xdr, &close->cl_stateid);
  3873. }
  3874. static __be32
  3875. nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr,
  3876. union nfsd4_op_u *u)
  3877. {
  3878. struct nfsd4_commit *commit = &u->commit;
  3879. return nfsd4_encode_verifier4(resp->xdr, &commit->co_verf);
  3880. }
  3881. static __be32
  3882. nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr,
  3883. union nfsd4_op_u *u)
  3884. {
  3885. struct nfsd4_create *create = &u->create;
  3886. struct xdr_stream *xdr = resp->xdr;
  3887. /* cinfo */
  3888. nfserr = nfsd4_encode_change_info4(xdr, &create->cr_cinfo);
  3889. if (nfserr)
  3890. return nfserr;
  3891. /* attrset */
  3892. return nfsd4_encode_bitmap4(xdr, create->cr_bmval[0],
  3893. create->cr_bmval[1], create->cr_bmval[2]);
  3894. }
  3895. static __be32
  3896. nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr,
  3897. union nfsd4_op_u *u)
  3898. {
  3899. struct nfsd4_getattr *getattr = &u->getattr;
  3900. struct svc_fh *fhp = getattr->ga_fhp;
  3901. struct xdr_stream *xdr = resp->xdr;
  3902. /* obj_attributes */
  3903. return nfsd4_encode_fattr4(resp->rqstp, xdr, fhp, fhp->fh_export,
  3904. fhp->fh_dentry, getattr->ga_bmval, 0);
  3905. }
  3906. static __be32
  3907. nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr,
  3908. union nfsd4_op_u *u)
  3909. {
  3910. struct xdr_stream *xdr = resp->xdr;
  3911. struct svc_fh *fhp = u->getfh;
  3912. /* object */
  3913. return nfsd4_encode_nfs_fh4(xdr, &fhp->fh_handle);
  3914. }
  3915. static __be32
  3916. nfsd4_encode_lock_owner4(struct xdr_stream *xdr, const clientid_t *clientid,
  3917. const struct xdr_netobj *owner)
  3918. {
  3919. __be32 status;
  3920. /* clientid */
  3921. status = nfsd4_encode_clientid4(xdr, clientid);
  3922. if (status != nfs_ok)
  3923. return status;
  3924. /* owner */
  3925. return nfsd4_encode_opaque(xdr, owner->data, owner->len);
  3926. }
  3927. static __be32
  3928. nfsd4_encode_lock4denied(struct xdr_stream *xdr,
  3929. const struct nfsd4_lock_denied *ld)
  3930. {
  3931. __be32 status;
  3932. /* offset */
  3933. status = nfsd4_encode_offset4(xdr, ld->ld_start);
  3934. if (status != nfs_ok)
  3935. return status;
  3936. /* length */
  3937. status = nfsd4_encode_length4(xdr, ld->ld_length);
  3938. if (status != nfs_ok)
  3939. return status;
  3940. /* locktype */
  3941. if (xdr_stream_encode_u32(xdr, ld->ld_type) != XDR_UNIT)
  3942. return nfserr_resource;
  3943. /* owner */
  3944. return nfsd4_encode_lock_owner4(xdr, &ld->ld_clientid,
  3945. &ld->ld_owner);
  3946. }
  3947. static __be32
  3948. nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr,
  3949. union nfsd4_op_u *u)
  3950. {
  3951. struct nfsd4_lock *lock = &u->lock;
  3952. struct xdr_stream *xdr = resp->xdr;
  3953. __be32 status;
  3954. switch (nfserr) {
  3955. case nfs_ok:
  3956. /* resok4 */
  3957. status = nfsd4_encode_stateid4(xdr, &lock->lk_resp_stateid);
  3958. break;
  3959. case nfserr_denied:
  3960. /* denied */
  3961. status = nfsd4_encode_lock4denied(xdr, &lock->lk_denied);
  3962. break;
  3963. default:
  3964. return nfserr;
  3965. }
  3966. return status != nfs_ok ? status : nfserr;
  3967. }
  3968. static __be32
  3969. nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr,
  3970. union nfsd4_op_u *u)
  3971. {
  3972. struct nfsd4_lockt *lockt = &u->lockt;
  3973. struct xdr_stream *xdr = resp->xdr;
  3974. __be32 status;
  3975. if (nfserr == nfserr_denied) {
  3976. /* denied */
  3977. status = nfsd4_encode_lock4denied(xdr, &lockt->lt_denied);
  3978. if (status != nfs_ok)
  3979. return status;
  3980. }
  3981. return nfserr;
  3982. }
  3983. static __be32
  3984. nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr,
  3985. union nfsd4_op_u *u)
  3986. {
  3987. struct nfsd4_locku *locku = &u->locku;
  3988. struct xdr_stream *xdr = resp->xdr;
  3989. /* lock_stateid */
  3990. return nfsd4_encode_stateid4(xdr, &locku->lu_stateid);
  3991. }
  3992. static __be32
  3993. nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr,
  3994. union nfsd4_op_u *u)
  3995. {
  3996. struct nfsd4_link *link = &u->link;
  3997. struct xdr_stream *xdr = resp->xdr;
  3998. return nfsd4_encode_change_info4(xdr, &link->li_cinfo);
  3999. }
  4000. /*
  4001. * This implementation does not yet support returning an ACE in an
  4002. * OPEN that offers a delegation.
  4003. */
  4004. static __be32
  4005. nfsd4_encode_open_nfsace4(struct xdr_stream *xdr)
  4006. {
  4007. __be32 status;
  4008. /* type */
  4009. status = nfsd4_encode_acetype4(xdr, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  4010. if (status != nfs_ok)
  4011. return nfserr_resource;
  4012. /* flag */
  4013. status = nfsd4_encode_aceflag4(xdr, 0);
  4014. if (status != nfs_ok)
  4015. return nfserr_resource;
  4016. /* access mask */
  4017. status = nfsd4_encode_acemask4(xdr, 0);
  4018. if (status != nfs_ok)
  4019. return nfserr_resource;
  4020. /* who - empty for now */
  4021. if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
  4022. return nfserr_resource;
  4023. return nfs_ok;
  4024. }
  4025. static __be32
  4026. nfsd4_encode_open_read_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open)
  4027. {
  4028. __be32 status;
  4029. /* stateid */
  4030. status = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid);
  4031. if (status != nfs_ok)
  4032. return status;
  4033. /* recall */
  4034. status = nfsd4_encode_bool(xdr, open->op_recall);
  4035. if (status != nfs_ok)
  4036. return status;
  4037. /* permissions */
  4038. return nfsd4_encode_open_nfsace4(xdr);
  4039. }
  4040. static __be32
  4041. nfsd4_encode_nfs_space_limit4(struct xdr_stream *xdr, u64 filesize)
  4042. {
  4043. /* limitby */
  4044. if (xdr_stream_encode_u32(xdr, NFS4_LIMIT_SIZE) != XDR_UNIT)
  4045. return nfserr_resource;
  4046. /* filesize */
  4047. return nfsd4_encode_uint64_t(xdr, filesize);
  4048. }
  4049. static __be32
  4050. nfsd4_encode_open_write_delegation4(struct xdr_stream *xdr,
  4051. struct nfsd4_open *open)
  4052. {
  4053. __be32 status;
  4054. /* stateid */
  4055. status = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid);
  4056. if (status != nfs_ok)
  4057. return status;
  4058. /* recall */
  4059. status = nfsd4_encode_bool(xdr, open->op_recall);
  4060. if (status != nfs_ok)
  4061. return status;
  4062. /* space_limit */
  4063. status = nfsd4_encode_nfs_space_limit4(xdr, 0);
  4064. if (status != nfs_ok)
  4065. return status;
  4066. return nfsd4_encode_open_nfsace4(xdr);
  4067. }
  4068. static __be32
  4069. nfsd4_encode_open_none_delegation4(struct xdr_stream *xdr,
  4070. struct nfsd4_open *open)
  4071. {
  4072. __be32 status = nfs_ok;
  4073. /* ond_why */
  4074. if (xdr_stream_encode_u32(xdr, open->op_why_no_deleg) != XDR_UNIT)
  4075. return nfserr_resource;
  4076. switch (open->op_why_no_deleg) {
  4077. case WND4_CONTENTION:
  4078. /* ond_server_will_push_deleg */
  4079. status = nfsd4_encode_bool(xdr, false);
  4080. break;
  4081. case WND4_RESOURCE:
  4082. /* ond_server_will_signal_avail */
  4083. status = nfsd4_encode_bool(xdr, false);
  4084. }
  4085. return status;
  4086. }
  4087. static __be32
  4088. nfsd4_encode_open_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open)
  4089. {
  4090. __be32 status;
  4091. /* delegation_type */
  4092. if (xdr_stream_encode_u32(xdr, open->op_delegate_type) != XDR_UNIT)
  4093. return nfserr_resource;
  4094. switch (open->op_delegate_type) {
  4095. case OPEN_DELEGATE_NONE:
  4096. status = nfs_ok;
  4097. break;
  4098. case OPEN_DELEGATE_READ:
  4099. case OPEN_DELEGATE_READ_ATTRS_DELEG:
  4100. /* read */
  4101. status = nfsd4_encode_open_read_delegation4(xdr, open);
  4102. break;
  4103. case OPEN_DELEGATE_WRITE:
  4104. case OPEN_DELEGATE_WRITE_ATTRS_DELEG:
  4105. /* write */
  4106. status = nfsd4_encode_open_write_delegation4(xdr, open);
  4107. break;
  4108. case OPEN_DELEGATE_NONE_EXT:
  4109. /* od_whynone */
  4110. status = nfsd4_encode_open_none_delegation4(xdr, open);
  4111. break;
  4112. default:
  4113. status = nfserr_serverfault;
  4114. }
  4115. return status;
  4116. }
  4117. static __be32
  4118. nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
  4119. union nfsd4_op_u *u)
  4120. {
  4121. struct nfsd4_open *open = &u->open;
  4122. struct xdr_stream *xdr = resp->xdr;
  4123. /* stateid */
  4124. nfserr = nfsd4_encode_stateid4(xdr, &open->op_stateid);
  4125. if (nfserr != nfs_ok)
  4126. return nfserr;
  4127. /* cinfo */
  4128. nfserr = nfsd4_encode_change_info4(xdr, &open->op_cinfo);
  4129. if (nfserr != nfs_ok)
  4130. return nfserr;
  4131. /* rflags */
  4132. nfserr = nfsd4_encode_uint32_t(xdr, open->op_rflags);
  4133. if (nfserr != nfs_ok)
  4134. return nfserr;
  4135. /* attrset */
  4136. nfserr = nfsd4_encode_bitmap4(xdr, open->op_bmval[0],
  4137. open->op_bmval[1], open->op_bmval[2]);
  4138. if (nfserr != nfs_ok)
  4139. return nfserr;
  4140. /* delegation */
  4141. return nfsd4_encode_open_delegation4(xdr, open);
  4142. }
  4143. static __be32
  4144. nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr,
  4145. union nfsd4_op_u *u)
  4146. {
  4147. struct nfsd4_open_confirm *oc = &u->open_confirm;
  4148. struct xdr_stream *xdr = resp->xdr;
  4149. /* open_stateid */
  4150. return nfsd4_encode_stateid4(xdr, &oc->oc_resp_stateid);
  4151. }
  4152. static __be32
  4153. nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr,
  4154. union nfsd4_op_u *u)
  4155. {
  4156. struct nfsd4_open_downgrade *od = &u->open_downgrade;
  4157. struct xdr_stream *xdr = resp->xdr;
  4158. /* open_stateid */
  4159. return nfsd4_encode_stateid4(xdr, &od->od_stateid);
  4160. }
  4161. /*
  4162. * The operation of this function assumes that this is the only
  4163. * READ operation in the COMPOUND. If there are multiple READs,
  4164. * we use nfsd4_encode_readv().
  4165. */
  4166. static __be32 nfsd4_encode_splice_read(
  4167. struct nfsd4_compoundres *resp,
  4168. struct nfsd4_read *read,
  4169. struct file *file, unsigned long maxcount)
  4170. {
  4171. struct xdr_stream *xdr = resp->xdr;
  4172. struct xdr_buf *buf = xdr->buf;
  4173. int status, space_left;
  4174. __be32 nfserr;
  4175. /*
  4176. * Splice read doesn't work if encoding has already wandered
  4177. * into the XDR buf's page array.
  4178. */
  4179. if (unlikely(xdr->buf->page_len)) {
  4180. WARN_ON_ONCE(1);
  4181. return nfserr_serverfault;
  4182. }
  4183. /*
  4184. * Make sure there is room at the end of buf->head for
  4185. * svcxdr_encode_opaque_pages() to create a tail buffer
  4186. * to XDR-pad the payload.
  4187. */
  4188. if (xdr->iov != xdr->buf->head || xdr->end - xdr->p < 1)
  4189. return nfserr_resource;
  4190. nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp,
  4191. file, read->rd_offset, &maxcount,
  4192. &read->rd_eof);
  4193. read->rd_length = maxcount;
  4194. if (nfserr)
  4195. goto out_err;
  4196. svcxdr_encode_opaque_pages(read->rd_rqstp, xdr, buf->pages,
  4197. buf->page_base, maxcount);
  4198. status = svc_encode_result_payload(read->rd_rqstp,
  4199. buf->head[0].iov_len, maxcount);
  4200. if (status) {
  4201. nfserr = nfserrno(status);
  4202. goto out_err;
  4203. }
  4204. /*
  4205. * Prepare to encode subsequent operations.
  4206. *
  4207. * xdr_truncate_encode() is not safe to use after a successful
  4208. * splice read has been done, so the following stream
  4209. * manipulations are open-coded.
  4210. */
  4211. space_left = min_t(int, (void *)xdr->end - (void *)xdr->p,
  4212. buf->buflen - buf->len);
  4213. buf->buflen = buf->len + space_left;
  4214. xdr->end = (__be32 *)((void *)xdr->end + space_left);
  4215. return nfs_ok;
  4216. out_err:
  4217. /*
  4218. * nfsd_splice_actor may have already messed with the
  4219. * page length; reset it so as not to confuse
  4220. * xdr_truncate_encode in our caller.
  4221. */
  4222. buf->page_len = 0;
  4223. return nfserr;
  4224. }
  4225. static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp,
  4226. struct nfsd4_read *read,
  4227. unsigned long maxcount)
  4228. {
  4229. struct xdr_stream *xdr = resp->xdr;
  4230. unsigned int base = xdr->buf->page_len & ~PAGE_MASK;
  4231. unsigned int starting_len = xdr->buf->len;
  4232. __be32 zero = xdr_zero;
  4233. __be32 nfserr;
  4234. nfserr = nfsd_iter_read(resp->rqstp, read->rd_fhp, read->rd_nf,
  4235. read->rd_offset, &maxcount, base,
  4236. &read->rd_eof);
  4237. read->rd_length = maxcount;
  4238. if (nfserr)
  4239. return nfserr;
  4240. /*
  4241. * svcxdr_encode_opaque_pages() is not used here because
  4242. * we don't want to encode subsequent results in this
  4243. * COMPOUND into the xdr->buf's tail, but rather those
  4244. * results should follow the NFS READ payload in the
  4245. * buf's pages.
  4246. */
  4247. if (xdr_reserve_space_vec(xdr, maxcount) < 0)
  4248. return nfserr_resource;
  4249. /*
  4250. * Mark the buffer location of the NFS READ payload so that
  4251. * direct placement-capable transports send only the
  4252. * payload bytes out-of-band.
  4253. */
  4254. if (svc_encode_result_payload(resp->rqstp, starting_len, maxcount))
  4255. return nfserr_io;
  4256. write_bytes_to_xdr_buf(xdr->buf, starting_len + maxcount, &zero,
  4257. xdr_pad_size(maxcount));
  4258. return nfs_ok;
  4259. }
  4260. static __be32
  4261. nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
  4262. union nfsd4_op_u *u)
  4263. {
  4264. struct nfsd4_compoundargs *argp = resp->rqstp->rq_argp;
  4265. struct nfsd4_read *read = &u->read;
  4266. struct xdr_stream *xdr = resp->xdr;
  4267. bool splice_ok = argp->splice_ok;
  4268. unsigned int eof_offset;
  4269. unsigned long maxcount;
  4270. __be32 wire_data[2];
  4271. struct file *file;
  4272. if (nfserr)
  4273. return nfserr;
  4274. eof_offset = xdr->buf->len;
  4275. file = read->rd_nf->nf_file;
  4276. /* Reserve space for the eof flag and byte count */
  4277. if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT * 2))) {
  4278. WARN_ON_ONCE(splice_ok);
  4279. return nfserr_resource;
  4280. }
  4281. xdr_commit_encode(xdr);
  4282. maxcount = min_t(unsigned long, read->rd_length,
  4283. (xdr->buf->buflen - xdr->buf->len));
  4284. if (file->f_op->splice_read && splice_ok)
  4285. nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
  4286. else
  4287. nfserr = nfsd4_encode_readv(resp, read, maxcount);
  4288. if (nfserr) {
  4289. xdr_truncate_encode(xdr, eof_offset);
  4290. return nfserr;
  4291. }
  4292. wire_data[0] = read->rd_eof ? xdr_one : xdr_zero;
  4293. wire_data[1] = cpu_to_be32(read->rd_length);
  4294. write_bytes_to_xdr_buf(xdr->buf, eof_offset, &wire_data, XDR_UNIT * 2);
  4295. return nfs_ok;
  4296. }
  4297. static __be32
  4298. nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr,
  4299. union nfsd4_op_u *u)
  4300. {
  4301. struct nfsd4_readlink *readlink = &u->readlink;
  4302. __be32 *p, wire_count, zero = xdr_zero;
  4303. struct xdr_stream *xdr = resp->xdr;
  4304. unsigned int length_offset;
  4305. int maxcount, status;
  4306. /* linktext4.count */
  4307. length_offset = xdr->buf->len;
  4308. if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT)))
  4309. return nfserr_resource;
  4310. /* linktext4.data */
  4311. maxcount = PAGE_SIZE;
  4312. p = xdr_reserve_space(xdr, maxcount);
  4313. if (!p)
  4314. return nfserr_resource;
  4315. nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp,
  4316. (char *)p, &maxcount);
  4317. if (nfserr == nfserr_isdir)
  4318. nfserr = nfserr_inval;
  4319. if (nfserr)
  4320. goto out_err;
  4321. status = svc_encode_result_payload(readlink->rl_rqstp, length_offset,
  4322. maxcount);
  4323. if (status) {
  4324. nfserr = nfserrno(status);
  4325. goto out_err;
  4326. }
  4327. wire_count = cpu_to_be32(maxcount);
  4328. write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, XDR_UNIT);
  4329. xdr_truncate_encode(xdr, length_offset + 4 + xdr_align_size(maxcount));
  4330. write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, &zero,
  4331. xdr_pad_size(maxcount));
  4332. return nfs_ok;
  4333. out_err:
  4334. xdr_truncate_encode(xdr, length_offset);
  4335. return nfserr;
  4336. }
  4337. static __be32 nfsd4_encode_dirlist4(struct xdr_stream *xdr,
  4338. struct nfsd4_readdir *readdir,
  4339. u32 max_payload)
  4340. {
  4341. int bytes_left, maxcount, starting_len = xdr->buf->len;
  4342. loff_t offset;
  4343. __be32 status;
  4344. /*
  4345. * Number of bytes left for directory entries allowing for the
  4346. * final 8 bytes of the readdir and a following failed op.
  4347. */
  4348. bytes_left = xdr->buf->buflen - xdr->buf->len -
  4349. COMPOUND_ERR_SLACK_SPACE - XDR_UNIT * 2;
  4350. if (bytes_left < 0)
  4351. return nfserr_resource;
  4352. maxcount = min_t(u32, readdir->rd_maxcount, max_payload);
  4353. /*
  4354. * The RFC defines rd_maxcount as the size of the
  4355. * READDIR4resok structure, which includes the verifier
  4356. * and the 8 bytes encoded at the end of this function.
  4357. */
  4358. if (maxcount < XDR_UNIT * 4)
  4359. return nfserr_toosmall;
  4360. maxcount = min_t(int, maxcount - XDR_UNIT * 4, bytes_left);
  4361. /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0 */
  4362. if (!readdir->rd_dircount)
  4363. readdir->rd_dircount = max_payload;
  4364. /* *entries */
  4365. readdir->xdr = xdr;
  4366. readdir->rd_maxcount = maxcount;
  4367. readdir->common.err = 0;
  4368. readdir->cookie_offset = 0;
  4369. offset = readdir->rd_cookie;
  4370. status = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, &offset,
  4371. &readdir->common, nfsd4_encode_entry4);
  4372. if (status)
  4373. return status;
  4374. if (readdir->common.err == nfserr_toosmall &&
  4375. xdr->buf->len == starting_len) {
  4376. /* No entries were encoded. Which limit did we hit? */
  4377. if (maxcount - XDR_UNIT * 4 < bytes_left)
  4378. /* It was the fault of rd_maxcount */
  4379. return nfserr_toosmall;
  4380. /* We ran out of buffer space */
  4381. return nfserr_resource;
  4382. }
  4383. /* Encode the final entry's cookie value */
  4384. nfsd4_encode_entry4_nfs_cookie4(readdir, offset);
  4385. /* No entries follow */
  4386. if (xdr_stream_encode_item_absent(xdr) != XDR_UNIT)
  4387. return nfserr_resource;
  4388. /* eof */
  4389. return nfsd4_encode_bool(xdr, readdir->common.err == nfserr_eof);
  4390. }
  4391. static __be32
  4392. nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr,
  4393. union nfsd4_op_u *u)
  4394. {
  4395. struct nfsd4_readdir *readdir = &u->readdir;
  4396. struct xdr_stream *xdr = resp->xdr;
  4397. int starting_len = xdr->buf->len;
  4398. /* cookieverf */
  4399. nfserr = nfsd4_encode_verifier4(xdr, &readdir->rd_verf);
  4400. if (nfserr != nfs_ok)
  4401. return nfserr;
  4402. /* reply */
  4403. nfserr = nfsd4_encode_dirlist4(xdr, readdir, svc_max_payload(resp->rqstp));
  4404. if (nfserr != nfs_ok)
  4405. xdr_truncate_encode(xdr, starting_len);
  4406. return nfserr;
  4407. }
  4408. static __be32
  4409. nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr,
  4410. union nfsd4_op_u *u)
  4411. {
  4412. struct nfsd4_remove *remove = &u->remove;
  4413. struct xdr_stream *xdr = resp->xdr;
  4414. return nfsd4_encode_change_info4(xdr, &remove->rm_cinfo);
  4415. }
  4416. static __be32
  4417. nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr,
  4418. union nfsd4_op_u *u)
  4419. {
  4420. struct nfsd4_rename *rename = &u->rename;
  4421. struct xdr_stream *xdr = resp->xdr;
  4422. nfserr = nfsd4_encode_change_info4(xdr, &rename->rn_sinfo);
  4423. if (nfserr)
  4424. return nfserr;
  4425. return nfsd4_encode_change_info4(xdr, &rename->rn_tinfo);
  4426. }
  4427. static __be32
  4428. nfsd4_encode_rpcsec_gss_info(struct xdr_stream *xdr,
  4429. struct rpcsec_gss_info *info)
  4430. {
  4431. __be32 status;
  4432. /* oid */
  4433. if (xdr_stream_encode_opaque(xdr, info->oid.data, info->oid.len) < 0)
  4434. return nfserr_resource;
  4435. /* qop */
  4436. status = nfsd4_encode_qop4(xdr, info->qop);
  4437. if (status != nfs_ok)
  4438. return status;
  4439. /* service */
  4440. if (xdr_stream_encode_u32(xdr, info->service) != XDR_UNIT)
  4441. return nfserr_resource;
  4442. return nfs_ok;
  4443. }
  4444. static __be32
  4445. nfsd4_encode_secinfo4(struct xdr_stream *xdr, rpc_authflavor_t pf,
  4446. u32 *supported)
  4447. {
  4448. struct rpcsec_gss_info info;
  4449. __be32 status;
  4450. if (rpcauth_get_gssinfo(pf, &info) == 0) {
  4451. (*supported)++;
  4452. /* flavor */
  4453. status = nfsd4_encode_uint32_t(xdr, RPC_AUTH_GSS);
  4454. if (status != nfs_ok)
  4455. return status;
  4456. /* flavor_info */
  4457. status = nfsd4_encode_rpcsec_gss_info(xdr, &info);
  4458. if (status != nfs_ok)
  4459. return status;
  4460. } else if (pf < RPC_AUTH_MAXFLAVOR) {
  4461. (*supported)++;
  4462. /* flavor */
  4463. status = nfsd4_encode_uint32_t(xdr, pf);
  4464. if (status != nfs_ok)
  4465. return status;
  4466. }
  4467. return nfs_ok;
  4468. }
  4469. static __be32
  4470. nfsd4_encode_SECINFO4resok(struct xdr_stream *xdr, struct svc_export *exp)
  4471. {
  4472. u32 i, nflavs, supported;
  4473. struct exp_flavor_info *flavs;
  4474. struct exp_flavor_info def_flavs[2];
  4475. unsigned int count_offset;
  4476. __be32 status, wire_count;
  4477. if (exp->ex_nflavors) {
  4478. flavs = exp->ex_flavors;
  4479. nflavs = exp->ex_nflavors;
  4480. } else { /* Handling of some defaults in absence of real secinfo: */
  4481. flavs = def_flavs;
  4482. if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
  4483. nflavs = 2;
  4484. flavs[0].pseudoflavor = RPC_AUTH_UNIX;
  4485. flavs[1].pseudoflavor = RPC_AUTH_NULL;
  4486. } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
  4487. nflavs = 1;
  4488. flavs[0].pseudoflavor
  4489. = svcauth_gss_flavor(exp->ex_client);
  4490. } else {
  4491. nflavs = 1;
  4492. flavs[0].pseudoflavor
  4493. = exp->ex_client->flavour->flavour;
  4494. }
  4495. }
  4496. count_offset = xdr->buf->len;
  4497. if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT)))
  4498. return nfserr_resource;
  4499. for (i = 0, supported = 0; i < nflavs; i++) {
  4500. status = nfsd4_encode_secinfo4(xdr, flavs[i].pseudoflavor,
  4501. &supported);
  4502. if (status != nfs_ok)
  4503. return status;
  4504. }
  4505. wire_count = cpu_to_be32(supported);
  4506. write_bytes_to_xdr_buf(xdr->buf, count_offset, &wire_count,
  4507. XDR_UNIT);
  4508. return 0;
  4509. }
  4510. static __be32
  4511. nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
  4512. union nfsd4_op_u *u)
  4513. {
  4514. struct nfsd4_secinfo *secinfo = &u->secinfo;
  4515. struct xdr_stream *xdr = resp->xdr;
  4516. return nfsd4_encode_SECINFO4resok(xdr, secinfo->si_exp);
  4517. }
  4518. static __be32
  4519. nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
  4520. union nfsd4_op_u *u)
  4521. {
  4522. struct nfsd4_secinfo_no_name *secinfo = &u->secinfo_no_name;
  4523. struct xdr_stream *xdr = resp->xdr;
  4524. return nfsd4_encode_SECINFO4resok(xdr, secinfo->sin_exp);
  4525. }
  4526. static __be32
  4527. nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr,
  4528. union nfsd4_op_u *u)
  4529. {
  4530. struct nfsd4_setattr *setattr = &u->setattr;
  4531. __be32 status;
  4532. switch (nfserr) {
  4533. case nfs_ok:
  4534. /* attrsset */
  4535. status = nfsd4_encode_bitmap4(resp->xdr, setattr->sa_bmval[0],
  4536. setattr->sa_bmval[1],
  4537. setattr->sa_bmval[2]);
  4538. break;
  4539. default:
  4540. /* attrsset */
  4541. status = nfsd4_encode_bitmap4(resp->xdr, 0, 0, 0);
  4542. }
  4543. return status != nfs_ok ? status : nfserr;
  4544. }
  4545. static __be32
  4546. nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr,
  4547. union nfsd4_op_u *u)
  4548. {
  4549. struct nfsd4_setclientid *scd = &u->setclientid;
  4550. struct xdr_stream *xdr = resp->xdr;
  4551. if (!nfserr) {
  4552. nfserr = nfsd4_encode_clientid4(xdr, &scd->se_clientid);
  4553. if (nfserr != nfs_ok)
  4554. goto out;
  4555. nfserr = nfsd4_encode_verifier4(xdr, &scd->se_confirm);
  4556. } else if (nfserr == nfserr_clid_inuse) {
  4557. /* empty network id */
  4558. if (xdr_stream_encode_u32(xdr, 0) < 0) {
  4559. nfserr = nfserr_resource;
  4560. goto out;
  4561. }
  4562. /* empty universal address */
  4563. if (xdr_stream_encode_u32(xdr, 0) < 0) {
  4564. nfserr = nfserr_resource;
  4565. goto out;
  4566. }
  4567. }
  4568. out:
  4569. return nfserr;
  4570. }
  4571. static __be32
  4572. nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr,
  4573. union nfsd4_op_u *u)
  4574. {
  4575. struct nfsd4_write *write = &u->write;
  4576. struct xdr_stream *xdr = resp->xdr;
  4577. /* count */
  4578. nfserr = nfsd4_encode_count4(xdr, write->wr_bytes_written);
  4579. if (nfserr)
  4580. return nfserr;
  4581. /* committed */
  4582. if (xdr_stream_encode_u32(xdr, write->wr_how_written) != XDR_UNIT)
  4583. return nfserr_resource;
  4584. /* writeverf */
  4585. return nfsd4_encode_verifier4(xdr, &write->wr_verifier);
  4586. }
  4587. static __be32
  4588. nfsd4_encode_state_protect_ops4(struct xdr_stream *xdr,
  4589. struct nfsd4_exchange_id *exid)
  4590. {
  4591. __be32 status;
  4592. /* spo_must_enforce */
  4593. status = nfsd4_encode_bitmap4(xdr, exid->spo_must_enforce[0],
  4594. exid->spo_must_enforce[1],
  4595. exid->spo_must_enforce[2]);
  4596. if (status != nfs_ok)
  4597. return status;
  4598. /* spo_must_allow */
  4599. return nfsd4_encode_bitmap4(xdr, exid->spo_must_allow[0],
  4600. exid->spo_must_allow[1],
  4601. exid->spo_must_allow[2]);
  4602. }
  4603. static __be32
  4604. nfsd4_encode_state_protect4_r(struct xdr_stream *xdr, struct nfsd4_exchange_id *exid)
  4605. {
  4606. __be32 status;
  4607. if (xdr_stream_encode_u32(xdr, exid->spa_how) != XDR_UNIT)
  4608. return nfserr_resource;
  4609. switch (exid->spa_how) {
  4610. case SP4_NONE:
  4611. status = nfs_ok;
  4612. break;
  4613. case SP4_MACH_CRED:
  4614. /* spr_mach_ops */
  4615. status = nfsd4_encode_state_protect_ops4(xdr, exid);
  4616. break;
  4617. default:
  4618. status = nfserr_serverfault;
  4619. }
  4620. return status;
  4621. }
  4622. static __be32
  4623. nfsd4_encode_server_owner4(struct xdr_stream *xdr, struct svc_rqst *rqstp)
  4624. {
  4625. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  4626. __be32 status;
  4627. /* so_minor_id */
  4628. status = nfsd4_encode_uint64_t(xdr, 0);
  4629. if (status != nfs_ok)
  4630. return status;
  4631. /* so_major_id */
  4632. return nfsd4_encode_opaque(xdr, nn->nfsd_name, strlen(nn->nfsd_name));
  4633. }
  4634. static __be32
  4635. nfsd4_encode_nfs_impl_id4(struct xdr_stream *xdr, struct nfsd4_exchange_id *exid)
  4636. {
  4637. __be32 status;
  4638. /* nii_domain */
  4639. status = nfsd4_encode_opaque(xdr, exid->nii_domain.data,
  4640. exid->nii_domain.len);
  4641. if (status != nfs_ok)
  4642. return status;
  4643. /* nii_name */
  4644. status = nfsd4_encode_opaque(xdr, exid->nii_name.data,
  4645. exid->nii_name.len);
  4646. if (status != nfs_ok)
  4647. return status;
  4648. /* nii_time */
  4649. return nfsd4_encode_nfstime4(xdr, &exid->nii_time);
  4650. }
  4651. static __be32
  4652. nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
  4653. union nfsd4_op_u *u)
  4654. {
  4655. struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
  4656. struct nfsd4_exchange_id *exid = &u->exchange_id;
  4657. struct xdr_stream *xdr = resp->xdr;
  4658. /* eir_clientid */
  4659. nfserr = nfsd4_encode_clientid4(xdr, &exid->clientid);
  4660. if (nfserr != nfs_ok)
  4661. return nfserr;
  4662. /* eir_sequenceid */
  4663. nfserr = nfsd4_encode_sequenceid4(xdr, exid->seqid);
  4664. if (nfserr != nfs_ok)
  4665. return nfserr;
  4666. /* eir_flags */
  4667. nfserr = nfsd4_encode_uint32_t(xdr, exid->flags);
  4668. if (nfserr != nfs_ok)
  4669. return nfserr;
  4670. /* eir_state_protect */
  4671. nfserr = nfsd4_encode_state_protect4_r(xdr, exid);
  4672. if (nfserr != nfs_ok)
  4673. return nfserr;
  4674. /* eir_server_owner */
  4675. nfserr = nfsd4_encode_server_owner4(xdr, resp->rqstp);
  4676. if (nfserr != nfs_ok)
  4677. return nfserr;
  4678. /* eir_server_scope */
  4679. nfserr = nfsd4_encode_opaque(xdr, nn->nfsd_name,
  4680. strlen(nn->nfsd_name));
  4681. if (nfserr != nfs_ok)
  4682. return nfserr;
  4683. /* eir_server_impl_id<1> */
  4684. if (xdr_stream_encode_u32(xdr, 1) != XDR_UNIT)
  4685. return nfserr_resource;
  4686. nfserr = nfsd4_encode_nfs_impl_id4(xdr, exid);
  4687. if (nfserr != nfs_ok)
  4688. return nfserr;
  4689. return nfs_ok;
  4690. }
  4691. static __be32
  4692. nfsd4_encode_channel_attrs4(struct xdr_stream *xdr,
  4693. const struct nfsd4_channel_attrs *attrs)
  4694. {
  4695. __be32 status;
  4696. /* ca_headerpadsize */
  4697. status = nfsd4_encode_count4(xdr, 0);
  4698. if (status != nfs_ok)
  4699. return status;
  4700. /* ca_maxrequestsize */
  4701. status = nfsd4_encode_count4(xdr, attrs->maxreq_sz);
  4702. if (status != nfs_ok)
  4703. return status;
  4704. /* ca_maxresponsesize */
  4705. status = nfsd4_encode_count4(xdr, attrs->maxresp_sz);
  4706. if (status != nfs_ok)
  4707. return status;
  4708. /* ca_maxresponsesize_cached */
  4709. status = nfsd4_encode_count4(xdr, attrs->maxresp_cached);
  4710. if (status != nfs_ok)
  4711. return status;
  4712. /* ca_maxoperations */
  4713. status = nfsd4_encode_count4(xdr, attrs->maxops);
  4714. if (status != nfs_ok)
  4715. return status;
  4716. /* ca_maxrequests */
  4717. status = nfsd4_encode_count4(xdr, attrs->maxreqs);
  4718. if (status != nfs_ok)
  4719. return status;
  4720. /* ca_rdma_ird<1> */
  4721. if (xdr_stream_encode_u32(xdr, attrs->nr_rdma_attrs) != XDR_UNIT)
  4722. return nfserr_resource;
  4723. if (attrs->nr_rdma_attrs)
  4724. return nfsd4_encode_uint32_t(xdr, attrs->rdma_attrs);
  4725. return nfs_ok;
  4726. }
  4727. static __be32
  4728. nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
  4729. union nfsd4_op_u *u)
  4730. {
  4731. struct nfsd4_create_session *sess = &u->create_session;
  4732. struct xdr_stream *xdr = resp->xdr;
  4733. /* csr_sessionid */
  4734. nfserr = nfsd4_encode_sessionid4(xdr, &sess->sessionid);
  4735. if (nfserr != nfs_ok)
  4736. return nfserr;
  4737. /* csr_sequence */
  4738. nfserr = nfsd4_encode_sequenceid4(xdr, sess->seqid);
  4739. if (nfserr != nfs_ok)
  4740. return nfserr;
  4741. /* csr_flags */
  4742. nfserr = nfsd4_encode_uint32_t(xdr, sess->flags);
  4743. if (nfserr != nfs_ok)
  4744. return nfserr;
  4745. /* csr_fore_chan_attrs */
  4746. nfserr = nfsd4_encode_channel_attrs4(xdr, &sess->fore_channel);
  4747. if (nfserr != nfs_ok)
  4748. return nfserr;
  4749. /* csr_back_chan_attrs */
  4750. return nfsd4_encode_channel_attrs4(xdr, &sess->back_channel);
  4751. }
  4752. static __be32
  4753. nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
  4754. union nfsd4_op_u *u)
  4755. {
  4756. struct nfsd4_sequence *seq = &u->sequence;
  4757. struct xdr_stream *xdr = resp->xdr;
  4758. /* sr_sessionid */
  4759. nfserr = nfsd4_encode_sessionid4(xdr, &seq->sessionid);
  4760. if (nfserr != nfs_ok)
  4761. return nfserr;
  4762. /* sr_sequenceid */
  4763. nfserr = nfsd4_encode_sequenceid4(xdr, seq->seqid);
  4764. if (nfserr != nfs_ok)
  4765. return nfserr;
  4766. /* sr_slotid */
  4767. nfserr = nfsd4_encode_slotid4(xdr, seq->slotid);
  4768. if (nfserr != nfs_ok)
  4769. return nfserr;
  4770. /* Note slotid's are numbered from zero: */
  4771. /* sr_highest_slotid */
  4772. nfserr = nfsd4_encode_slotid4(xdr, seq->maxslots_response - 1);
  4773. if (nfserr != nfs_ok)
  4774. return nfserr;
  4775. /* sr_target_highest_slotid */
  4776. nfserr = nfsd4_encode_slotid4(xdr, seq->target_maxslots - 1);
  4777. if (nfserr != nfs_ok)
  4778. return nfserr;
  4779. /* sr_status_flags */
  4780. nfserr = nfsd4_encode_uint32_t(xdr, seq->status_flags);
  4781. if (nfserr != nfs_ok)
  4782. return nfserr;
  4783. resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */
  4784. return nfs_ok;
  4785. }
  4786. static __be32
  4787. nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
  4788. union nfsd4_op_u *u)
  4789. {
  4790. struct nfsd4_test_stateid *test_stateid = &u->test_stateid;
  4791. struct nfsd4_test_stateid_id *stateid, *next;
  4792. struct xdr_stream *xdr = resp->xdr;
  4793. /* tsr_status_codes<> */
  4794. if (xdr_stream_encode_u32(xdr, test_stateid->ts_num_ids) != XDR_UNIT)
  4795. return nfserr_resource;
  4796. list_for_each_entry_safe(stateid, next,
  4797. &test_stateid->ts_stateid_list, ts_id_list) {
  4798. if (xdr_stream_encode_be32(xdr, stateid->ts_id_status) != XDR_UNIT)
  4799. return nfserr_resource;
  4800. }
  4801. return nfs_ok;
  4802. }
  4803. static __be32
  4804. nfsd4_encode_get_dir_delegation(struct nfsd4_compoundres *resp, __be32 nfserr,
  4805. union nfsd4_op_u *u)
  4806. {
  4807. struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation;
  4808. struct xdr_stream *xdr = resp->xdr;
  4809. __be32 status = nfserr_resource;
  4810. switch(gdd->gddrnf_status) {
  4811. case GDD4_OK:
  4812. if (xdr_stream_encode_u32(xdr, GDD4_OK) != XDR_UNIT)
  4813. break;
  4814. status = nfsd4_encode_verifier4(xdr, &gdd->gddr_cookieverf);
  4815. if (status)
  4816. break;
  4817. status = nfsd4_encode_stateid4(xdr, &gdd->gddr_stateid);
  4818. if (status)
  4819. break;
  4820. status = nfsd4_encode_bitmap4(xdr, gdd->gddr_notification[0], 0, 0);
  4821. if (status)
  4822. break;
  4823. status = nfsd4_encode_bitmap4(xdr, gdd->gddr_child_attributes[0],
  4824. gdd->gddr_child_attributes[1],
  4825. gdd->gddr_child_attributes[2]);
  4826. if (status)
  4827. break;
  4828. status = nfsd4_encode_bitmap4(xdr, gdd->gddr_dir_attributes[0],
  4829. gdd->gddr_dir_attributes[1],
  4830. gdd->gddr_dir_attributes[2]);
  4831. break;
  4832. default:
  4833. pr_warn("nfsd: bad gddrnf_status (%u)\n", gdd->gddrnf_status);
  4834. gdd->gddrnf_will_signal_deleg_avail = 0;
  4835. fallthrough;
  4836. case GDD4_UNAVAIL:
  4837. if (xdr_stream_encode_u32(xdr, GDD4_UNAVAIL) != XDR_UNIT)
  4838. break;
  4839. status = nfsd4_encode_bool(xdr, gdd->gddrnf_will_signal_deleg_avail);
  4840. break;
  4841. }
  4842. return status;
  4843. }
  4844. #ifdef CONFIG_NFSD_PNFS
  4845. static __be32
  4846. nfsd4_encode_device_addr4(struct xdr_stream *xdr,
  4847. const struct nfsd4_getdeviceinfo *gdev)
  4848. {
  4849. u32 needed_len, starting_len = xdr->buf->len;
  4850. const struct nfsd4_layout_ops *ops;
  4851. __be32 status;
  4852. /* da_layout_type */
  4853. if (xdr_stream_encode_u32(xdr, gdev->gd_layout_type) != XDR_UNIT)
  4854. return nfserr_resource;
  4855. /* da_addr_body */
  4856. ops = nfsd4_layout_ops[gdev->gd_layout_type];
  4857. status = ops->encode_getdeviceinfo(xdr, gdev);
  4858. if (status != nfs_ok) {
  4859. /*
  4860. * Don't burden the layout drivers with enforcing
  4861. * gd_maxcount. Just tell the client to come back
  4862. * with a bigger buffer if it's not enough.
  4863. */
  4864. if (xdr->buf->len + XDR_UNIT > gdev->gd_maxcount)
  4865. goto toosmall;
  4866. return status;
  4867. }
  4868. return nfs_ok;
  4869. toosmall:
  4870. needed_len = xdr->buf->len + XDR_UNIT; /* notifications */
  4871. xdr_truncate_encode(xdr, starting_len);
  4872. status = nfsd4_encode_count4(xdr, needed_len);
  4873. if (status != nfs_ok)
  4874. return status;
  4875. return nfserr_toosmall;
  4876. }
  4877. static __be32
  4878. nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
  4879. union nfsd4_op_u *u)
  4880. {
  4881. struct nfsd4_getdeviceinfo *gdev = &u->getdeviceinfo;
  4882. struct xdr_stream *xdr = resp->xdr;
  4883. /* gdir_device_addr */
  4884. nfserr = nfsd4_encode_device_addr4(xdr, gdev);
  4885. if (nfserr)
  4886. return nfserr;
  4887. /* gdir_notification */
  4888. return nfsd4_encode_bitmap4(xdr, gdev->gd_notify_types, 0, 0);
  4889. }
  4890. static __be32
  4891. nfsd4_encode_layout4(struct xdr_stream *xdr, const struct nfsd4_layoutget *lgp)
  4892. {
  4893. const struct nfsd4_layout_ops *ops = nfsd4_layout_ops[lgp->lg_layout_type];
  4894. __be32 status;
  4895. /* lo_offset */
  4896. status = nfsd4_encode_offset4(xdr, lgp->lg_seg.offset);
  4897. if (status != nfs_ok)
  4898. return status;
  4899. /* lo_length */
  4900. status = nfsd4_encode_length4(xdr, lgp->lg_seg.length);
  4901. if (status != nfs_ok)
  4902. return status;
  4903. /* lo_iomode */
  4904. if (xdr_stream_encode_u32(xdr, lgp->lg_seg.iomode) != XDR_UNIT)
  4905. return nfserr_resource;
  4906. /* lo_content */
  4907. if (xdr_stream_encode_u32(xdr, lgp->lg_layout_type) != XDR_UNIT)
  4908. return nfserr_resource;
  4909. return ops->encode_layoutget(xdr, lgp);
  4910. }
  4911. static __be32
  4912. nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr,
  4913. union nfsd4_op_u *u)
  4914. {
  4915. struct nfsd4_layoutget *lgp = &u->layoutget;
  4916. struct xdr_stream *xdr = resp->xdr;
  4917. /* logr_return_on_close */
  4918. nfserr = nfsd4_encode_bool(xdr, true);
  4919. if (nfserr != nfs_ok)
  4920. return nfserr;
  4921. /* logr_stateid */
  4922. nfserr = nfsd4_encode_stateid4(xdr, &lgp->lg_sid);
  4923. if (nfserr != nfs_ok)
  4924. return nfserr;
  4925. /* logr_layout<> */
  4926. if (xdr_stream_encode_u32(xdr, 1) != XDR_UNIT)
  4927. return nfserr_resource;
  4928. return nfsd4_encode_layout4(xdr, lgp);
  4929. }
  4930. static __be32
  4931. nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr,
  4932. union nfsd4_op_u *u)
  4933. {
  4934. struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
  4935. struct xdr_stream *xdr = resp->xdr;
  4936. /* ns_sizechanged */
  4937. nfserr = nfsd4_encode_bool(xdr, lcp->lc_size_chg);
  4938. if (nfserr != nfs_ok)
  4939. return nfserr;
  4940. if (lcp->lc_size_chg)
  4941. /* ns_size */
  4942. return nfsd4_encode_length4(xdr, lcp->lc_newsize);
  4943. return nfs_ok;
  4944. }
  4945. static __be32
  4946. nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr,
  4947. union nfsd4_op_u *u)
  4948. {
  4949. struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
  4950. struct xdr_stream *xdr = resp->xdr;
  4951. /* lrs_present */
  4952. nfserr = nfsd4_encode_bool(xdr, lrp->lrs_present);
  4953. if (nfserr != nfs_ok)
  4954. return nfserr;
  4955. if (lrp->lrs_present)
  4956. /* lrs_stateid */
  4957. return nfsd4_encode_stateid4(xdr, &lrp->lr_sid);
  4958. return nfs_ok;
  4959. }
  4960. #endif /* CONFIG_NFSD_PNFS */
  4961. static __be32
  4962. nfsd4_encode_write_response4(struct xdr_stream *xdr,
  4963. const struct nfsd4_copy *copy)
  4964. {
  4965. const struct nfsd42_write_res *write = &copy->cp_res;
  4966. u32 count = nfsd4_copy_is_sync(copy) ? 0 : 1;
  4967. __be32 status;
  4968. /* wr_callback_id<1> */
  4969. if (xdr_stream_encode_u32(xdr, count) != XDR_UNIT)
  4970. return nfserr_resource;
  4971. if (count) {
  4972. status = nfsd4_encode_stateid4(xdr, &write->cb_stateid);
  4973. if (status != nfs_ok)
  4974. return status;
  4975. }
  4976. /* wr_count */
  4977. status = nfsd4_encode_length4(xdr, write->wr_bytes_written);
  4978. if (status != nfs_ok)
  4979. return status;
  4980. /* wr_committed */
  4981. if (xdr_stream_encode_u32(xdr, write->wr_stable_how) != XDR_UNIT)
  4982. return nfserr_resource;
  4983. /* wr_writeverf */
  4984. return nfsd4_encode_verifier4(xdr, &write->wr_verifier);
  4985. }
  4986. static __be32 nfsd4_encode_copy_requirements4(struct xdr_stream *xdr,
  4987. const struct nfsd4_copy *copy)
  4988. {
  4989. __be32 status;
  4990. /* cr_consecutive */
  4991. status = nfsd4_encode_bool(xdr, true);
  4992. if (status != nfs_ok)
  4993. return status;
  4994. /* cr_synchronous */
  4995. return nfsd4_encode_bool(xdr, nfsd4_copy_is_sync(copy));
  4996. }
  4997. static __be32
  4998. nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
  4999. union nfsd4_op_u *u)
  5000. {
  5001. struct nfsd4_copy *copy = &u->copy;
  5002. nfserr = nfsd4_encode_write_response4(resp->xdr, copy);
  5003. if (nfserr != nfs_ok)
  5004. return nfserr;
  5005. return nfsd4_encode_copy_requirements4(resp->xdr, copy);
  5006. }
  5007. static __be32
  5008. nfsd4_encode_netloc4(struct xdr_stream *xdr, const struct nl4_server *ns)
  5009. {
  5010. __be32 status;
  5011. if (xdr_stream_encode_u32(xdr, ns->nl4_type) != XDR_UNIT)
  5012. return nfserr_resource;
  5013. switch (ns->nl4_type) {
  5014. case NL4_NETADDR:
  5015. /* nl_addr */
  5016. status = nfsd4_encode_netaddr4(xdr, &ns->u.nl4_addr);
  5017. break;
  5018. default:
  5019. status = nfserr_serverfault;
  5020. }
  5021. return status;
  5022. }
  5023. static __be32
  5024. nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr,
  5025. union nfsd4_op_u *u)
  5026. {
  5027. struct nfsd4_copy_notify *cn = &u->copy_notify;
  5028. struct xdr_stream *xdr = resp->xdr;
  5029. /* cnr_lease_time */
  5030. nfserr = nfsd4_encode_nfstime4(xdr, &cn->cpn_lease_time);
  5031. if (nfserr)
  5032. return nfserr;
  5033. /* cnr_stateid */
  5034. nfserr = nfsd4_encode_stateid4(xdr, &cn->cpn_cnr_stateid);
  5035. if (nfserr)
  5036. return nfserr;
  5037. /* cnr_source_server<> */
  5038. if (xdr_stream_encode_u32(xdr, 1) != XDR_UNIT)
  5039. return nfserr_resource;
  5040. return nfsd4_encode_netloc4(xdr, cn->cpn_src);
  5041. }
  5042. static __be32
  5043. nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr,
  5044. union nfsd4_op_u *u)
  5045. {
  5046. struct nfsd4_offload_status *os = &u->offload_status;
  5047. struct xdr_stream *xdr = resp->xdr;
  5048. /* osr_count */
  5049. nfserr = nfsd4_encode_length4(xdr, os->count);
  5050. if (nfserr != nfs_ok)
  5051. return nfserr;
  5052. /* osr_complete<1> */
  5053. if (os->completed) {
  5054. if (xdr_stream_encode_u32(xdr, 1) != XDR_UNIT)
  5055. return nfserr_resource;
  5056. if (xdr_stream_encode_be32(xdr, os->status) != XDR_UNIT)
  5057. return nfserr_resource;
  5058. } else if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
  5059. return nfserr_resource;
  5060. return nfs_ok;
  5061. }
  5062. static __be32
  5063. nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp,
  5064. struct nfsd4_read *read)
  5065. {
  5066. struct nfsd4_compoundargs *argp = resp->rqstp->rq_argp;
  5067. struct file *file = read->rd_nf->nf_file;
  5068. struct xdr_stream *xdr = resp->xdr;
  5069. bool splice_ok = argp->splice_ok;
  5070. unsigned int offset_offset;
  5071. __be32 nfserr, wire_count;
  5072. unsigned long maxcount;
  5073. __be64 wire_offset;
  5074. if (xdr_stream_encode_u32(xdr, NFS4_CONTENT_DATA) != XDR_UNIT)
  5075. return nfserr_io;
  5076. offset_offset = xdr->buf->len;
  5077. /* Reserve space for the byte offset and count */
  5078. if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT * 3)))
  5079. return nfserr_io;
  5080. xdr_commit_encode(xdr);
  5081. maxcount = min_t(unsigned long, read->rd_length,
  5082. (xdr->buf->buflen - xdr->buf->len));
  5083. if (file->f_op->splice_read && splice_ok)
  5084. nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
  5085. else
  5086. nfserr = nfsd4_encode_readv(resp, read, maxcount);
  5087. if (nfserr)
  5088. return nfserr;
  5089. wire_offset = cpu_to_be64(read->rd_offset);
  5090. write_bytes_to_xdr_buf(xdr->buf, offset_offset, &wire_offset,
  5091. XDR_UNIT * 2);
  5092. wire_count = cpu_to_be32(read->rd_length);
  5093. write_bytes_to_xdr_buf(xdr->buf, offset_offset + XDR_UNIT * 2,
  5094. &wire_count, XDR_UNIT);
  5095. return nfs_ok;
  5096. }
  5097. static __be32
  5098. nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
  5099. union nfsd4_op_u *u)
  5100. {
  5101. struct nfsd4_read *read = &u->read;
  5102. struct file *file = read->rd_nf->nf_file;
  5103. struct xdr_stream *xdr = resp->xdr;
  5104. unsigned int eof_offset;
  5105. __be32 wire_data[2];
  5106. u32 segments = 0;
  5107. if (nfserr)
  5108. return nfserr;
  5109. eof_offset = xdr->buf->len;
  5110. /* Reserve space for the eof flag and segment count */
  5111. if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT * 2)))
  5112. return nfserr_io;
  5113. xdr_commit_encode(xdr);
  5114. read->rd_eof = read->rd_offset >= i_size_read(file_inode(file));
  5115. if (read->rd_eof)
  5116. goto out;
  5117. nfserr = nfsd4_encode_read_plus_data(resp, read);
  5118. if (nfserr) {
  5119. xdr_truncate_encode(xdr, eof_offset);
  5120. return nfserr;
  5121. }
  5122. segments++;
  5123. out:
  5124. wire_data[0] = read->rd_eof ? xdr_one : xdr_zero;
  5125. wire_data[1] = cpu_to_be32(segments);
  5126. write_bytes_to_xdr_buf(xdr->buf, eof_offset, &wire_data, XDR_UNIT * 2);
  5127. return nfserr;
  5128. }
  5129. static __be32
  5130. nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr,
  5131. union nfsd4_op_u *u)
  5132. {
  5133. struct nfsd4_seek *seek = &u->seek;
  5134. struct xdr_stream *xdr = resp->xdr;
  5135. /* sr_eof */
  5136. nfserr = nfsd4_encode_bool(xdr, seek->seek_eof);
  5137. if (nfserr != nfs_ok)
  5138. return nfserr;
  5139. /* sr_offset */
  5140. return nfsd4_encode_offset4(xdr, seek->seek_pos);
  5141. }
  5142. static __be32
  5143. nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr,
  5144. union nfsd4_op_u *p)
  5145. {
  5146. return nfserr;
  5147. }
  5148. /*
  5149. * Encode kmalloc-ed buffer in to XDR stream.
  5150. */
  5151. static __be32
  5152. nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen)
  5153. {
  5154. u32 cplen;
  5155. __be32 *p;
  5156. cplen = min_t(unsigned long, buflen,
  5157. ((void *)xdr->end - (void *)xdr->p));
  5158. p = xdr_reserve_space(xdr, cplen);
  5159. if (!p)
  5160. return nfserr_resource;
  5161. memcpy(p, buf, cplen);
  5162. buf += cplen;
  5163. buflen -= cplen;
  5164. while (buflen) {
  5165. cplen = min_t(u32, buflen, PAGE_SIZE);
  5166. p = xdr_reserve_space(xdr, cplen);
  5167. if (!p)
  5168. return nfserr_resource;
  5169. memcpy(p, buf, cplen);
  5170. if (cplen < PAGE_SIZE) {
  5171. /*
  5172. * We're done, with a length that wasn't page
  5173. * aligned, so possibly not word aligned. Pad
  5174. * any trailing bytes with 0.
  5175. */
  5176. xdr_encode_opaque_fixed(p, NULL, cplen);
  5177. break;
  5178. }
  5179. buflen -= PAGE_SIZE;
  5180. buf += PAGE_SIZE;
  5181. }
  5182. return 0;
  5183. }
  5184. static __be32
  5185. nfsd4_encode_getxattr(struct nfsd4_compoundres *resp, __be32 nfserr,
  5186. union nfsd4_op_u *u)
  5187. {
  5188. struct nfsd4_getxattr *getxattr = &u->getxattr;
  5189. struct xdr_stream *xdr = resp->xdr;
  5190. __be32 *p, err;
  5191. p = xdr_reserve_space(xdr, 4);
  5192. if (!p)
  5193. return nfserr_resource;
  5194. *p = cpu_to_be32(getxattr->getxa_len);
  5195. if (getxattr->getxa_len == 0)
  5196. return 0;
  5197. err = nfsd4_vbuf_to_stream(xdr, getxattr->getxa_buf,
  5198. getxattr->getxa_len);
  5199. kvfree(getxattr->getxa_buf);
  5200. return err;
  5201. }
  5202. static __be32
  5203. nfsd4_encode_setxattr(struct nfsd4_compoundres *resp, __be32 nfserr,
  5204. union nfsd4_op_u *u)
  5205. {
  5206. struct nfsd4_setxattr *setxattr = &u->setxattr;
  5207. struct xdr_stream *xdr = resp->xdr;
  5208. return nfsd4_encode_change_info4(xdr, &setxattr->setxa_cinfo);
  5209. }
  5210. /*
  5211. * See if there are cookie values that can be rejected outright.
  5212. */
  5213. static __be32
  5214. nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs,
  5215. u32 *offsetp)
  5216. {
  5217. u64 cookie = listxattrs->lsxa_cookie;
  5218. /*
  5219. * If the cookie is larger than the maximum number we can fit
  5220. * in the buffer we just got back from vfs_listxattr, it's invalid.
  5221. */
  5222. if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2))
  5223. return nfserr_badcookie;
  5224. *offsetp = (u32)cookie;
  5225. return 0;
  5226. }
  5227. static __be32
  5228. nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr,
  5229. union nfsd4_op_u *u)
  5230. {
  5231. struct nfsd4_listxattrs *listxattrs = &u->listxattrs;
  5232. struct xdr_stream *xdr = resp->xdr;
  5233. u32 cookie_offset, count_offset, eof;
  5234. u32 left, xdrleft, slen, count;
  5235. u32 xdrlen, offset;
  5236. u64 cookie;
  5237. char *sp;
  5238. __be32 status, tmp;
  5239. __be64 wire_cookie;
  5240. __be32 *p;
  5241. u32 nuser;
  5242. eof = 1;
  5243. status = nfsd4_listxattr_validate_cookie(listxattrs, &offset);
  5244. if (status)
  5245. goto out;
  5246. /*
  5247. * Reserve space for the cookie and the name array count. Record
  5248. * the offsets to save them later.
  5249. */
  5250. cookie_offset = xdr->buf->len;
  5251. count_offset = cookie_offset + 8;
  5252. p = xdr_reserve_space(xdr, XDR_UNIT * 3);
  5253. if (!p) {
  5254. status = nfserr_resource;
  5255. goto out;
  5256. }
  5257. count = 0;
  5258. left = listxattrs->lsxa_len;
  5259. sp = listxattrs->lsxa_buf;
  5260. nuser = 0;
  5261. /* Bytes left is maxcount - 8 (cookie) - 4 (array count) */
  5262. xdrleft = listxattrs->lsxa_maxcount - XDR_UNIT * 3;
  5263. while (left > 0 && xdrleft > 0) {
  5264. slen = strlen(sp);
  5265. /*
  5266. * Check if this is a "user." attribute, skip it if not.
  5267. */
  5268. if (strncmp(sp, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
  5269. goto contloop;
  5270. slen -= XATTR_USER_PREFIX_LEN;
  5271. xdrlen = 4 + ((slen + 3) & ~3);
  5272. /* Check if both entry and eof can fit in the XDR buffer */
  5273. if (xdrlen + XDR_UNIT > xdrleft) {
  5274. if (count == 0) {
  5275. /*
  5276. * Can't even fit the first attribute name.
  5277. */
  5278. status = nfserr_toosmall;
  5279. goto out;
  5280. }
  5281. eof = 0;
  5282. goto wreof;
  5283. }
  5284. left -= XATTR_USER_PREFIX_LEN;
  5285. sp += XATTR_USER_PREFIX_LEN;
  5286. if (nuser++ < offset)
  5287. goto contloop;
  5288. p = xdr_reserve_space(xdr, xdrlen);
  5289. if (!p) {
  5290. status = nfserr_resource;
  5291. goto out;
  5292. }
  5293. xdr_encode_opaque(p, sp, slen);
  5294. xdrleft -= xdrlen;
  5295. count++;
  5296. contloop:
  5297. sp += slen + 1;
  5298. left -= slen + 1;
  5299. }
  5300. /*
  5301. * If there were user attributes to copy, but we didn't copy
  5302. * any, the offset was too large (e.g. the cookie was invalid).
  5303. */
  5304. if (nuser > 0 && count == 0) {
  5305. status = nfserr_badcookie;
  5306. goto out;
  5307. }
  5308. wreof:
  5309. p = xdr_reserve_space(xdr, 4);
  5310. if (!p) {
  5311. status = nfserr_resource;
  5312. goto out;
  5313. }
  5314. *p = cpu_to_be32(eof);
  5315. cookie = offset + count;
  5316. wire_cookie = cpu_to_be64(cookie);
  5317. write_bytes_to_xdr_buf(xdr->buf, cookie_offset, &wire_cookie, 8);
  5318. tmp = cpu_to_be32(count);
  5319. write_bytes_to_xdr_buf(xdr->buf, count_offset, &tmp, 4);
  5320. out:
  5321. if (listxattrs->lsxa_len)
  5322. kvfree(listxattrs->lsxa_buf);
  5323. return status;
  5324. }
  5325. static __be32
  5326. nfsd4_encode_removexattr(struct nfsd4_compoundres *resp, __be32 nfserr,
  5327. union nfsd4_op_u *u)
  5328. {
  5329. struct nfsd4_removexattr *removexattr = &u->removexattr;
  5330. struct xdr_stream *xdr = resp->xdr;
  5331. return nfsd4_encode_change_info4(xdr, &removexattr->rmxa_cinfo);
  5332. }
  5333. typedef __be32(*nfsd4_enc)(struct nfsd4_compoundres *, __be32, union nfsd4_op_u *u);
  5334. /*
  5335. * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
  5336. * since we don't need to filter out obsolete ops as this is
  5337. * done in the decoding phase.
  5338. */
  5339. static const nfsd4_enc nfsd4_enc_ops[] = {
  5340. [OP_ACCESS] = nfsd4_encode_access,
  5341. [OP_CLOSE] = nfsd4_encode_close,
  5342. [OP_COMMIT] = nfsd4_encode_commit,
  5343. [OP_CREATE] = nfsd4_encode_create,
  5344. [OP_DELEGPURGE] = nfsd4_encode_noop,
  5345. [OP_DELEGRETURN] = nfsd4_encode_noop,
  5346. [OP_GETATTR] = nfsd4_encode_getattr,
  5347. [OP_GETFH] = nfsd4_encode_getfh,
  5348. [OP_LINK] = nfsd4_encode_link,
  5349. [OP_LOCK] = nfsd4_encode_lock,
  5350. [OP_LOCKT] = nfsd4_encode_lockt,
  5351. [OP_LOCKU] = nfsd4_encode_locku,
  5352. [OP_LOOKUP] = nfsd4_encode_noop,
  5353. [OP_LOOKUPP] = nfsd4_encode_noop,
  5354. [OP_NVERIFY] = nfsd4_encode_noop,
  5355. [OP_OPEN] = nfsd4_encode_open,
  5356. [OP_OPENATTR] = nfsd4_encode_noop,
  5357. [OP_OPEN_CONFIRM] = nfsd4_encode_open_confirm,
  5358. [OP_OPEN_DOWNGRADE] = nfsd4_encode_open_downgrade,
  5359. [OP_PUTFH] = nfsd4_encode_noop,
  5360. [OP_PUTPUBFH] = nfsd4_encode_noop,
  5361. [OP_PUTROOTFH] = nfsd4_encode_noop,
  5362. [OP_READ] = nfsd4_encode_read,
  5363. [OP_READDIR] = nfsd4_encode_readdir,
  5364. [OP_READLINK] = nfsd4_encode_readlink,
  5365. [OP_REMOVE] = nfsd4_encode_remove,
  5366. [OP_RENAME] = nfsd4_encode_rename,
  5367. [OP_RENEW] = nfsd4_encode_noop,
  5368. [OP_RESTOREFH] = nfsd4_encode_noop,
  5369. [OP_SAVEFH] = nfsd4_encode_noop,
  5370. [OP_SECINFO] = nfsd4_encode_secinfo,
  5371. [OP_SETATTR] = nfsd4_encode_setattr,
  5372. [OP_SETCLIENTID] = nfsd4_encode_setclientid,
  5373. [OP_SETCLIENTID_CONFIRM] = nfsd4_encode_noop,
  5374. [OP_VERIFY] = nfsd4_encode_noop,
  5375. [OP_WRITE] = nfsd4_encode_write,
  5376. [OP_RELEASE_LOCKOWNER] = nfsd4_encode_noop,
  5377. /* NFSv4.1 operations */
  5378. [OP_BACKCHANNEL_CTL] = nfsd4_encode_noop,
  5379. [OP_BIND_CONN_TO_SESSION] = nfsd4_encode_bind_conn_to_session,
  5380. [OP_EXCHANGE_ID] = nfsd4_encode_exchange_id,
  5381. [OP_CREATE_SESSION] = nfsd4_encode_create_session,
  5382. [OP_DESTROY_SESSION] = nfsd4_encode_noop,
  5383. [OP_FREE_STATEID] = nfsd4_encode_noop,
  5384. [OP_GET_DIR_DELEGATION] = nfsd4_encode_get_dir_delegation,
  5385. #ifdef CONFIG_NFSD_PNFS
  5386. [OP_GETDEVICEINFO] = nfsd4_encode_getdeviceinfo,
  5387. [OP_GETDEVICELIST] = nfsd4_encode_noop,
  5388. [OP_LAYOUTCOMMIT] = nfsd4_encode_layoutcommit,
  5389. [OP_LAYOUTGET] = nfsd4_encode_layoutget,
  5390. [OP_LAYOUTRETURN] = nfsd4_encode_layoutreturn,
  5391. #else
  5392. [OP_GETDEVICEINFO] = nfsd4_encode_noop,
  5393. [OP_GETDEVICELIST] = nfsd4_encode_noop,
  5394. [OP_LAYOUTCOMMIT] = nfsd4_encode_noop,
  5395. [OP_LAYOUTGET] = nfsd4_encode_noop,
  5396. [OP_LAYOUTRETURN] = nfsd4_encode_noop,
  5397. #endif
  5398. [OP_SECINFO_NO_NAME] = nfsd4_encode_secinfo_no_name,
  5399. [OP_SEQUENCE] = nfsd4_encode_sequence,
  5400. [OP_SET_SSV] = nfsd4_encode_noop,
  5401. [OP_TEST_STATEID] = nfsd4_encode_test_stateid,
  5402. [OP_WANT_DELEGATION] = nfsd4_encode_noop,
  5403. [OP_DESTROY_CLIENTID] = nfsd4_encode_noop,
  5404. [OP_RECLAIM_COMPLETE] = nfsd4_encode_noop,
  5405. /* NFSv4.2 operations */
  5406. [OP_ALLOCATE] = nfsd4_encode_noop,
  5407. [OP_COPY] = nfsd4_encode_copy,
  5408. [OP_COPY_NOTIFY] = nfsd4_encode_copy_notify,
  5409. [OP_DEALLOCATE] = nfsd4_encode_noop,
  5410. [OP_IO_ADVISE] = nfsd4_encode_noop,
  5411. [OP_LAYOUTERROR] = nfsd4_encode_noop,
  5412. [OP_LAYOUTSTATS] = nfsd4_encode_noop,
  5413. [OP_OFFLOAD_CANCEL] = nfsd4_encode_noop,
  5414. [OP_OFFLOAD_STATUS] = nfsd4_encode_offload_status,
  5415. [OP_READ_PLUS] = nfsd4_encode_read_plus,
  5416. [OP_SEEK] = nfsd4_encode_seek,
  5417. [OP_WRITE_SAME] = nfsd4_encode_noop,
  5418. [OP_CLONE] = nfsd4_encode_noop,
  5419. /* RFC 8276 extended atributes operations */
  5420. [OP_GETXATTR] = nfsd4_encode_getxattr,
  5421. [OP_SETXATTR] = nfsd4_encode_setxattr,
  5422. [OP_LISTXATTRS] = nfsd4_encode_listxattrs,
  5423. [OP_REMOVEXATTR] = nfsd4_encode_removexattr,
  5424. };
  5425. /*
  5426. * Calculate whether we still have space to encode repsize bytes.
  5427. * There are two considerations:
  5428. * - For NFS versions >=4.1, the size of the reply must stay within
  5429. * session limits
  5430. * - For all NFS versions, we must stay within limited preallocated
  5431. * buffer space.
  5432. *
  5433. * This is called before the operation is processed, so can only provide
  5434. * an upper estimate. For some nonidempotent operations (such as
  5435. * getattr), it's not necessarily a problem if that estimate is wrong,
  5436. * as we can fail it after processing without significant side effects.
  5437. */
  5438. __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize)
  5439. {
  5440. struct xdr_buf *buf = &resp->rqstp->rq_res;
  5441. struct nfsd4_slot *slot = resp->cstate.slot;
  5442. if (buf->len + respsize <= buf->buflen)
  5443. return nfs_ok;
  5444. if (!nfsd4_has_session(&resp->cstate))
  5445. return nfserr_resource;
  5446. if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) {
  5447. WARN_ON_ONCE(1);
  5448. return nfserr_rep_too_big_to_cache;
  5449. }
  5450. return nfserr_rep_too_big;
  5451. }
  5452. static __be32 nfsd4_map_status(__be32 status, u32 minor)
  5453. {
  5454. switch (status) {
  5455. case nfs_ok:
  5456. break;
  5457. case nfserr_wrong_type:
  5458. /* RFC 8881 - 15.1.2.9 */
  5459. if (minor == 0)
  5460. status = nfserr_inval;
  5461. break;
  5462. case nfserr_symlink_not_dir:
  5463. status = nfserr_symlink;
  5464. break;
  5465. }
  5466. return status;
  5467. }
  5468. void
  5469. nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
  5470. {
  5471. struct xdr_stream *xdr = resp->xdr;
  5472. struct nfs4_stateowner *so = resp->cstate.replay_owner;
  5473. struct svc_rqst *rqstp = resp->rqstp;
  5474. const struct nfsd4_operation *opdesc = op->opdesc;
  5475. unsigned int op_status_offset;
  5476. nfsd4_enc encoder;
  5477. if (xdr_stream_encode_u32(xdr, op->opnum) != XDR_UNIT)
  5478. goto release;
  5479. op_status_offset = xdr->buf->len;
  5480. if (!xdr_reserve_space(xdr, XDR_UNIT))
  5481. goto release;
  5482. if (op->opnum == OP_ILLEGAL)
  5483. goto status;
  5484. if (op->status && opdesc &&
  5485. !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE))
  5486. goto status;
  5487. BUG_ON(op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
  5488. !nfsd4_enc_ops[op->opnum]);
  5489. encoder = nfsd4_enc_ops[op->opnum];
  5490. op->status = encoder(resp, op->status, &op->u);
  5491. if (op->status)
  5492. trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status);
  5493. xdr_commit_encode(xdr);
  5494. /* nfsd4_check_resp_size guarantees enough room for error status */
  5495. if (!op->status) {
  5496. int space_needed = 0;
  5497. if (!nfsd4_last_compound_op(rqstp))
  5498. space_needed = COMPOUND_ERR_SLACK_SPACE;
  5499. op->status = nfsd4_check_resp_size(resp, space_needed);
  5500. }
  5501. if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) {
  5502. struct nfsd4_slot *slot = resp->cstate.slot;
  5503. if (slot->sl_flags & NFSD4_SLOT_CACHETHIS)
  5504. op->status = nfserr_rep_too_big_to_cache;
  5505. else
  5506. op->status = nfserr_rep_too_big;
  5507. }
  5508. if (op->status == nfserr_resource ||
  5509. op->status == nfserr_rep_too_big ||
  5510. op->status == nfserr_rep_too_big_to_cache) {
  5511. /*
  5512. * The operation may have already been encoded or
  5513. * partially encoded. No op returns anything additional
  5514. * in the case of one of these three errors, so we can
  5515. * just truncate back to after the status. But it's a
  5516. * bug if we had to do this on a non-idempotent op:
  5517. */
  5518. warn_on_nonidempotent_op(op);
  5519. xdr_truncate_encode(xdr, op_status_offset + XDR_UNIT);
  5520. } else if (so) {
  5521. int len = xdr->buf->len - (op_status_offset + XDR_UNIT);
  5522. so->so_replay.rp_status = op->status;
  5523. if (len <= NFSD4_REPLAY_ISIZE) {
  5524. so->so_replay.rp_buflen = len;
  5525. read_bytes_from_xdr_buf(xdr->buf,
  5526. op_status_offset + XDR_UNIT,
  5527. so->so_replay.rp_buf, len);
  5528. } else {
  5529. so->so_replay.rp_buflen = 0;
  5530. }
  5531. }
  5532. status:
  5533. op->status = nfsd4_map_status(op->status,
  5534. resp->cstate.minorversion);
  5535. write_bytes_to_xdr_buf(xdr->buf, op_status_offset,
  5536. &op->status, XDR_UNIT);
  5537. release:
  5538. if (opdesc && opdesc->op_release)
  5539. opdesc->op_release(&op->u);
  5540. /*
  5541. * Account for pages consumed while encoding this operation.
  5542. * The xdr_stream primitives don't manage rq_next_page.
  5543. */
  5544. rqstp->rq_next_page = xdr->page_ptr + 1;
  5545. }
  5546. /**
  5547. * nfsd4_encode_replay - encode a result stored in the stateowner reply cache
  5548. * @xdr: send buffer's XDR stream
  5549. * @op: operation being replayed
  5550. *
  5551. * @op->replay->rp_buf contains the previously-sent already-encoded result.
  5552. */
  5553. void nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
  5554. {
  5555. struct nfs4_replay *rp = op->replay;
  5556. trace_nfsd_stateowner_replay(op->opnum, rp);
  5557. if (xdr_stream_encode_u32(xdr, op->opnum) != XDR_UNIT)
  5558. return;
  5559. if (xdr_stream_encode_be32(xdr, rp->rp_status) != XDR_UNIT)
  5560. return;
  5561. xdr_stream_encode_opaque_fixed(xdr, rp->rp_buf, rp->rp_buflen);
  5562. }
  5563. void nfsd4_release_compoundargs(struct svc_rqst *rqstp)
  5564. {
  5565. struct nfsd4_compoundargs *args = rqstp->rq_argp;
  5566. if (args->ops != args->iops) {
  5567. vfree(args->ops);
  5568. args->ops = args->iops;
  5569. }
  5570. while (args->to_free) {
  5571. struct svcxdr_tmpbuf *tb = args->to_free;
  5572. args->to_free = tb->next;
  5573. kfree(tb);
  5574. }
  5575. }
  5576. bool
  5577. nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  5578. {
  5579. struct nfsd4_compoundargs *args = rqstp->rq_argp;
  5580. /* svcxdr_tmp_alloc */
  5581. args->to_free = NULL;
  5582. args->xdr = xdr;
  5583. args->ops = args->iops;
  5584. args->rqstp = rqstp;
  5585. /*
  5586. * NFSv4 operation decoders can invoke svc cache lookups
  5587. * that trigger svc_defer() when RQ_USEDEFERRAL is set,
  5588. * setting RQ_DROPME. This creates two problems:
  5589. *
  5590. * 1. Non-idempotency: Compounds make it too hard to avoid
  5591. * problems if a request is deferred and replayed.
  5592. *
  5593. * 2. Session slot leakage (NFSv4.1+): If RQ_DROPME is set
  5594. * during decode but SEQUENCE executes successfully, the
  5595. * session slot will be marked INUSE. The request is then
  5596. * dropped before encoding, so the slot is never released,
  5597. * rendering it permanently unusable by the client.
  5598. */
  5599. clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  5600. return nfsd4_decode_compound(args);
  5601. }
  5602. bool
  5603. nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
  5604. {
  5605. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  5606. __be32 *p;
  5607. /*
  5608. * Send buffer space for the following items is reserved
  5609. * at the top of nfsd4_proc_compound().
  5610. */
  5611. p = resp->statusp;
  5612. *p++ = resp->cstate.status;
  5613. *p++ = htonl(resp->taglen);
  5614. memcpy(p, resp->tag, resp->taglen);
  5615. p += XDR_QUADLEN(resp->taglen);
  5616. *p++ = htonl(resp->opcnt);
  5617. nfsd4_sequence_done(resp);
  5618. return true;
  5619. }