smb2ops.c 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757
  1. /*
  2. * SMB2 version specific operations
  3. *
  4. * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License v2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/pagemap.h>
  20. #include <linux/vfs.h>
  21. #include <linux/falloc.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/uuid.h>
  24. #include <crypto/aead.h>
  25. #include "cifsglob.h"
  26. #include "smb2pdu.h"
  27. #include "smb2proto.h"
  28. #include "cifsproto.h"
  29. #include "cifs_debug.h"
  30. #include "cifs_unicode.h"
  31. #include "smb2status.h"
  32. #include "smb2glob.h"
  33. #include "cifs_ioctl.h"
  34. #include "smbdirect.h"
  35. static int
  36. change_conf(struct TCP_Server_Info *server)
  37. {
  38. server->credits += server->echo_credits + server->oplock_credits;
  39. server->oplock_credits = server->echo_credits = 0;
  40. switch (server->credits) {
  41. case 0:
  42. return -1;
  43. case 1:
  44. server->echoes = false;
  45. server->oplocks = false;
  46. cifs_dbg(VFS, "disabling echoes and oplocks\n");
  47. break;
  48. case 2:
  49. server->echoes = true;
  50. server->oplocks = false;
  51. server->echo_credits = 1;
  52. cifs_dbg(FYI, "disabling oplocks\n");
  53. break;
  54. default:
  55. server->echoes = true;
  56. if (enable_oplocks) {
  57. server->oplocks = true;
  58. server->oplock_credits = 1;
  59. } else
  60. server->oplocks = false;
  61. server->echo_credits = 1;
  62. }
  63. server->credits -= server->echo_credits + server->oplock_credits;
  64. return 0;
  65. }
  66. static void
  67. smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
  68. const int optype)
  69. {
  70. int *val, rc = 0;
  71. spin_lock(&server->req_lock);
  72. val = server->ops->get_credits_field(server, optype);
  73. *val += add;
  74. if (*val > 65000) {
  75. *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
  76. printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
  77. }
  78. server->in_flight--;
  79. if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
  80. rc = change_conf(server);
  81. /*
  82. * Sometimes server returns 0 credits on oplock break ack - we need to
  83. * rebalance credits in this case.
  84. */
  85. else if (server->in_flight > 0 && server->oplock_credits == 0 &&
  86. server->oplocks) {
  87. if (server->credits > 1) {
  88. server->credits--;
  89. server->oplock_credits++;
  90. }
  91. }
  92. spin_unlock(&server->req_lock);
  93. wake_up(&server->request_q);
  94. if (rc)
  95. cifs_reconnect(server);
  96. }
  97. static void
  98. smb2_set_credits(struct TCP_Server_Info *server, const int val)
  99. {
  100. spin_lock(&server->req_lock);
  101. server->credits = val;
  102. spin_unlock(&server->req_lock);
  103. }
  104. static int *
  105. smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
  106. {
  107. switch (optype) {
  108. case CIFS_ECHO_OP:
  109. return &server->echo_credits;
  110. case CIFS_OBREAK_OP:
  111. return &server->oplock_credits;
  112. default:
  113. return &server->credits;
  114. }
  115. }
  116. static unsigned int
  117. smb2_get_credits(struct mid_q_entry *mid)
  118. {
  119. struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
  120. return le16_to_cpu(shdr->CreditRequest);
  121. }
  122. static int
  123. smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
  124. unsigned int *num, unsigned int *credits)
  125. {
  126. int rc = 0;
  127. unsigned int scredits;
  128. spin_lock(&server->req_lock);
  129. while (1) {
  130. if (server->credits <= 0) {
  131. spin_unlock(&server->req_lock);
  132. cifs_num_waiters_inc(server);
  133. rc = wait_event_killable(server->request_q,
  134. has_credits(server, &server->credits));
  135. cifs_num_waiters_dec(server);
  136. if (rc)
  137. return rc;
  138. spin_lock(&server->req_lock);
  139. } else {
  140. if (server->tcpStatus == CifsExiting) {
  141. spin_unlock(&server->req_lock);
  142. return -ENOENT;
  143. }
  144. scredits = server->credits;
  145. /* can deadlock with reopen */
  146. if (scredits == 1) {
  147. *num = SMB2_MAX_BUFFER_SIZE;
  148. *credits = 0;
  149. break;
  150. }
  151. /* leave one credit for a possible reopen */
  152. scredits--;
  153. *num = min_t(unsigned int, size,
  154. scredits * SMB2_MAX_BUFFER_SIZE);
  155. *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
  156. server->credits -= *credits;
  157. server->in_flight++;
  158. break;
  159. }
  160. }
  161. spin_unlock(&server->req_lock);
  162. return rc;
  163. }
  164. static __u64
  165. smb2_get_next_mid(struct TCP_Server_Info *server)
  166. {
  167. __u64 mid;
  168. /* for SMB2 we need the current value */
  169. spin_lock(&GlobalMid_Lock);
  170. mid = server->CurrentMid++;
  171. spin_unlock(&GlobalMid_Lock);
  172. return mid;
  173. }
  174. static struct mid_q_entry *
  175. smb2_find_mid(struct TCP_Server_Info *server, char *buf)
  176. {
  177. struct mid_q_entry *mid;
  178. struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
  179. __u64 wire_mid = le64_to_cpu(shdr->MessageId);
  180. if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
  181. cifs_dbg(VFS, "encrypted frame parsing not supported yet");
  182. return NULL;
  183. }
  184. spin_lock(&GlobalMid_Lock);
  185. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  186. if ((mid->mid == wire_mid) &&
  187. (mid->mid_state == MID_REQUEST_SUBMITTED) &&
  188. (mid->command == shdr->Command)) {
  189. kref_get(&mid->refcount);
  190. spin_unlock(&GlobalMid_Lock);
  191. return mid;
  192. }
  193. }
  194. spin_unlock(&GlobalMid_Lock);
  195. return NULL;
  196. }
  197. static void
  198. smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
  199. {
  200. #ifdef CONFIG_CIFS_DEBUG2
  201. struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
  202. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
  203. shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
  204. shdr->ProcessId);
  205. cifs_dbg(VFS, "smb buf %p len %u\n", buf,
  206. server->ops->calc_smb_size(buf, server));
  207. #endif
  208. }
  209. static bool
  210. smb2_need_neg(struct TCP_Server_Info *server)
  211. {
  212. return server->max_read == 0;
  213. }
  214. static int
  215. smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
  216. {
  217. int rc;
  218. ses->server->CurrentMid = 0;
  219. rc = SMB2_negotiate(xid, ses);
  220. /* BB we probably don't need to retry with modern servers */
  221. if (rc == -EAGAIN)
  222. rc = -EHOSTDOWN;
  223. return rc;
  224. }
  225. static unsigned int
  226. smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  227. {
  228. struct TCP_Server_Info *server = tcon->ses->server;
  229. unsigned int wsize;
  230. /* start with specified wsize, or default */
  231. wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
  232. wsize = min_t(unsigned int, wsize, server->max_write);
  233. #ifdef CONFIG_CIFS_SMB_DIRECT
  234. if (server->rdma) {
  235. if (server->sign)
  236. wsize = min_t(unsigned int,
  237. wsize, server->smbd_conn->max_fragmented_send_size);
  238. else
  239. wsize = min_t(unsigned int,
  240. wsize, server->smbd_conn->max_readwrite_size);
  241. }
  242. #endif
  243. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  244. wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
  245. return wsize;
  246. }
  247. static unsigned int
  248. smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  249. {
  250. struct TCP_Server_Info *server = tcon->ses->server;
  251. unsigned int rsize;
  252. /* start with specified rsize, or default */
  253. rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
  254. rsize = min_t(unsigned int, rsize, server->max_read);
  255. #ifdef CONFIG_CIFS_SMB_DIRECT
  256. if (server->rdma) {
  257. if (server->sign)
  258. rsize = min_t(unsigned int,
  259. rsize, server->smbd_conn->max_fragmented_recv_size);
  260. else
  261. rsize = min_t(unsigned int,
  262. rsize, server->smbd_conn->max_readwrite_size);
  263. }
  264. #endif
  265. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  266. rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
  267. return rsize;
  268. }
  269. static int
  270. parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
  271. size_t buf_len,
  272. struct cifs_server_iface **iface_list,
  273. size_t *iface_count)
  274. {
  275. struct network_interface_info_ioctl_rsp *p;
  276. struct sockaddr_in *addr4;
  277. struct sockaddr_in6 *addr6;
  278. struct iface_info_ipv4 *p4;
  279. struct iface_info_ipv6 *p6;
  280. struct cifs_server_iface *info;
  281. ssize_t bytes_left;
  282. size_t next = 0;
  283. int nb_iface = 0;
  284. int rc = 0;
  285. *iface_list = NULL;
  286. *iface_count = 0;
  287. /*
  288. * Fist pass: count and sanity check
  289. */
  290. bytes_left = buf_len;
  291. p = buf;
  292. while (bytes_left >= sizeof(*p)) {
  293. nb_iface++;
  294. next = le32_to_cpu(p->Next);
  295. if (!next) {
  296. bytes_left -= sizeof(*p);
  297. break;
  298. }
  299. p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
  300. bytes_left -= next;
  301. }
  302. if (!nb_iface) {
  303. cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
  304. rc = -EINVAL;
  305. goto out;
  306. }
  307. if (bytes_left || p->Next)
  308. cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
  309. /*
  310. * Second pass: extract info to internal structure
  311. */
  312. *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
  313. if (!*iface_list) {
  314. rc = -ENOMEM;
  315. goto out;
  316. }
  317. info = *iface_list;
  318. bytes_left = buf_len;
  319. p = buf;
  320. while (bytes_left >= sizeof(*p)) {
  321. info->speed = le64_to_cpu(p->LinkSpeed);
  322. info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
  323. info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
  324. cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
  325. cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
  326. cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
  327. le32_to_cpu(p->Capability));
  328. switch (p->Family) {
  329. /*
  330. * The kernel and wire socket structures have the same
  331. * layout and use network byte order but make the
  332. * conversion explicit in case either one changes.
  333. */
  334. case INTERNETWORK:
  335. addr4 = (struct sockaddr_in *)&info->sockaddr;
  336. p4 = (struct iface_info_ipv4 *)p->Buffer;
  337. addr4->sin_family = AF_INET;
  338. memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
  339. /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
  340. addr4->sin_port = cpu_to_be16(CIFS_PORT);
  341. cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
  342. &addr4->sin_addr);
  343. break;
  344. case INTERNETWORKV6:
  345. addr6 = (struct sockaddr_in6 *)&info->sockaddr;
  346. p6 = (struct iface_info_ipv6 *)p->Buffer;
  347. addr6->sin6_family = AF_INET6;
  348. memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
  349. /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
  350. addr6->sin6_flowinfo = 0;
  351. addr6->sin6_scope_id = 0;
  352. addr6->sin6_port = cpu_to_be16(CIFS_PORT);
  353. cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
  354. &addr6->sin6_addr);
  355. break;
  356. default:
  357. cifs_dbg(VFS,
  358. "%s: skipping unsupported socket family\n",
  359. __func__);
  360. goto next_iface;
  361. }
  362. (*iface_count)++;
  363. info++;
  364. next_iface:
  365. next = le32_to_cpu(p->Next);
  366. if (!next)
  367. break;
  368. p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
  369. bytes_left -= next;
  370. }
  371. if (!*iface_count) {
  372. rc = -EINVAL;
  373. goto out;
  374. }
  375. out:
  376. if (rc) {
  377. kfree(*iface_list);
  378. *iface_count = 0;
  379. *iface_list = NULL;
  380. }
  381. return rc;
  382. }
  383. static int
  384. SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
  385. {
  386. int rc;
  387. unsigned int ret_data_len = 0;
  388. struct network_interface_info_ioctl_rsp *out_buf = NULL;
  389. struct cifs_server_iface *iface_list;
  390. size_t iface_count;
  391. struct cifs_ses *ses = tcon->ses;
  392. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  393. FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
  394. NULL /* no data input */, 0 /* no data input */,
  395. (char **)&out_buf, &ret_data_len);
  396. if (rc == -EOPNOTSUPP) {
  397. cifs_dbg(FYI,
  398. "server does not support query network interfaces\n");
  399. goto out;
  400. } else if (rc != 0) {
  401. cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
  402. goto out;
  403. }
  404. rc = parse_server_interfaces(out_buf, ret_data_len,
  405. &iface_list, &iface_count);
  406. if (rc)
  407. goto out;
  408. spin_lock(&ses->iface_lock);
  409. kfree(ses->iface_list);
  410. ses->iface_list = iface_list;
  411. ses->iface_count = iface_count;
  412. ses->iface_last_update = jiffies;
  413. spin_unlock(&ses->iface_lock);
  414. out:
  415. kfree(out_buf);
  416. return rc;
  417. }
  418. static void
  419. smb2_close_cached_fid(struct kref *ref)
  420. {
  421. struct cached_fid *cfid = container_of(ref, struct cached_fid,
  422. refcount);
  423. if (cfid->is_valid) {
  424. cifs_dbg(FYI, "clear cached root file handle\n");
  425. SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
  426. cfid->fid->volatile_fid);
  427. cfid->is_valid = false;
  428. }
  429. }
  430. void close_shroot(struct cached_fid *cfid)
  431. {
  432. mutex_lock(&cfid->fid_mutex);
  433. kref_put(&cfid->refcount, smb2_close_cached_fid);
  434. mutex_unlock(&cfid->fid_mutex);
  435. }
  436. void
  437. smb2_cached_lease_break(struct work_struct *work)
  438. {
  439. struct cached_fid *cfid = container_of(work,
  440. struct cached_fid, lease_break);
  441. close_shroot(cfid);
  442. }
  443. /*
  444. * Open the directory at the root of a share
  445. */
  446. int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
  447. {
  448. struct cifs_open_parms oparams;
  449. int rc;
  450. __le16 srch_path = 0; /* Null - since an open of top of share */
  451. u8 oplock = SMB2_OPLOCK_LEVEL_II;
  452. mutex_lock(&tcon->crfid.fid_mutex);
  453. if (tcon->crfid.is_valid) {
  454. cifs_dbg(FYI, "found a cached root file handle\n");
  455. memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
  456. kref_get(&tcon->crfid.refcount);
  457. mutex_unlock(&tcon->crfid.fid_mutex);
  458. return 0;
  459. }
  460. oparams.tcon = tcon;
  461. oparams.create_options = 0;
  462. oparams.desired_access = FILE_READ_ATTRIBUTES;
  463. oparams.disposition = FILE_OPEN;
  464. oparams.fid = pfid;
  465. oparams.reconnect = false;
  466. rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
  467. if (rc == 0) {
  468. memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
  469. tcon->crfid.tcon = tcon;
  470. tcon->crfid.is_valid = true;
  471. kref_init(&tcon->crfid.refcount);
  472. kref_get(&tcon->crfid.refcount);
  473. }
  474. mutex_unlock(&tcon->crfid.fid_mutex);
  475. return rc;
  476. }
  477. static void
  478. smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  479. {
  480. int rc;
  481. __le16 srch_path = 0; /* Null - open root of share */
  482. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  483. struct cifs_open_parms oparms;
  484. struct cifs_fid fid;
  485. bool no_cached_open = tcon->nohandlecache;
  486. oparms.tcon = tcon;
  487. oparms.desired_access = FILE_READ_ATTRIBUTES;
  488. oparms.disposition = FILE_OPEN;
  489. oparms.create_options = 0;
  490. oparms.fid = &fid;
  491. oparms.reconnect = false;
  492. if (no_cached_open)
  493. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
  494. NULL);
  495. else
  496. rc = open_shroot(xid, tcon, &fid);
  497. if (rc)
  498. return;
  499. SMB3_request_interfaces(xid, tcon);
  500. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  501. FS_ATTRIBUTE_INFORMATION);
  502. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  503. FS_DEVICE_INFORMATION);
  504. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  505. FS_VOLUME_INFORMATION);
  506. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  507. FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
  508. if (no_cached_open)
  509. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  510. else
  511. close_shroot(&tcon->crfid);
  512. return;
  513. }
  514. static void
  515. smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  516. {
  517. int rc;
  518. __le16 srch_path = 0; /* Null - open root of share */
  519. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  520. struct cifs_open_parms oparms;
  521. struct cifs_fid fid;
  522. oparms.tcon = tcon;
  523. oparms.desired_access = FILE_READ_ATTRIBUTES;
  524. oparms.disposition = FILE_OPEN;
  525. oparms.create_options = 0;
  526. oparms.fid = &fid;
  527. oparms.reconnect = false;
  528. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
  529. if (rc)
  530. return;
  531. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  532. FS_ATTRIBUTE_INFORMATION);
  533. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  534. FS_DEVICE_INFORMATION);
  535. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  536. return;
  537. }
  538. static int
  539. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  540. struct cifs_sb_info *cifs_sb, const char *full_path)
  541. {
  542. int rc;
  543. __le16 *utf16_path;
  544. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  545. struct cifs_open_parms oparms;
  546. struct cifs_fid fid;
  547. if ((*full_path == 0) && tcon->crfid.is_valid)
  548. return 0;
  549. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  550. if (!utf16_path)
  551. return -ENOMEM;
  552. oparms.tcon = tcon;
  553. oparms.desired_access = FILE_READ_ATTRIBUTES;
  554. oparms.disposition = FILE_OPEN;
  555. if (backup_cred(cifs_sb))
  556. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  557. else
  558. oparms.create_options = 0;
  559. oparms.fid = &fid;
  560. oparms.reconnect = false;
  561. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
  562. if (rc) {
  563. kfree(utf16_path);
  564. return rc;
  565. }
  566. rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  567. kfree(utf16_path);
  568. return rc;
  569. }
  570. static int
  571. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  572. struct cifs_sb_info *cifs_sb, const char *full_path,
  573. u64 *uniqueid, FILE_ALL_INFO *data)
  574. {
  575. *uniqueid = le64_to_cpu(data->IndexNumber);
  576. return 0;
  577. }
  578. static int
  579. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  580. struct cifs_fid *fid, FILE_ALL_INFO *data)
  581. {
  582. int rc;
  583. struct smb2_file_all_info *smb2_data;
  584. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
  585. GFP_KERNEL);
  586. if (smb2_data == NULL)
  587. return -ENOMEM;
  588. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  589. smb2_data);
  590. if (!rc)
  591. move_smb2_info_to_cifs(data, smb2_data);
  592. kfree(smb2_data);
  593. return rc;
  594. }
  595. #ifdef CONFIG_CIFS_XATTR
  596. static ssize_t
  597. move_smb2_ea_to_cifs(char *dst, size_t dst_size,
  598. struct smb2_file_full_ea_info *src, size_t src_size,
  599. const unsigned char *ea_name)
  600. {
  601. int rc = 0;
  602. unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
  603. char *name, *value;
  604. size_t name_len, value_len, user_name_len;
  605. while (src_size > 0) {
  606. name = &src->ea_data[0];
  607. name_len = (size_t)src->ea_name_length;
  608. value = &src->ea_data[src->ea_name_length + 1];
  609. value_len = (size_t)le16_to_cpu(src->ea_value_length);
  610. if (name_len == 0) {
  611. break;
  612. }
  613. if (src_size < 8 + name_len + 1 + value_len) {
  614. cifs_dbg(FYI, "EA entry goes beyond length of list\n");
  615. rc = -EIO;
  616. goto out;
  617. }
  618. if (ea_name) {
  619. if (ea_name_len == name_len &&
  620. memcmp(ea_name, name, name_len) == 0) {
  621. rc = value_len;
  622. if (dst_size == 0)
  623. goto out;
  624. if (dst_size < value_len) {
  625. rc = -ERANGE;
  626. goto out;
  627. }
  628. memcpy(dst, value, value_len);
  629. goto out;
  630. }
  631. } else {
  632. /* 'user.' plus a terminating null */
  633. user_name_len = 5 + 1 + name_len;
  634. rc += user_name_len;
  635. if (dst_size >= user_name_len) {
  636. dst_size -= user_name_len;
  637. memcpy(dst, "user.", 5);
  638. dst += 5;
  639. memcpy(dst, src->ea_data, name_len);
  640. dst += name_len;
  641. *dst = 0;
  642. ++dst;
  643. } else if (dst_size == 0) {
  644. /* skip copy - calc size only */
  645. } else {
  646. /* stop before overrun buffer */
  647. rc = -ERANGE;
  648. break;
  649. }
  650. }
  651. if (!src->next_entry_offset)
  652. break;
  653. if (src_size < le32_to_cpu(src->next_entry_offset)) {
  654. /* stop before overrun buffer */
  655. rc = -ERANGE;
  656. break;
  657. }
  658. src_size -= le32_to_cpu(src->next_entry_offset);
  659. src = (void *)((char *)src +
  660. le32_to_cpu(src->next_entry_offset));
  661. }
  662. /* didn't find the named attribute */
  663. if (ea_name)
  664. rc = -ENODATA;
  665. out:
  666. return (ssize_t)rc;
  667. }
  668. static ssize_t
  669. smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
  670. const unsigned char *path, const unsigned char *ea_name,
  671. char *ea_data, size_t buf_size,
  672. struct cifs_sb_info *cifs_sb)
  673. {
  674. int rc;
  675. __le16 *utf16_path;
  676. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  677. struct cifs_open_parms oparms;
  678. struct cifs_fid fid;
  679. struct smb2_file_full_ea_info *smb2_data;
  680. int ea_buf_size = SMB2_MIN_EA_BUF;
  681. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  682. if (!utf16_path)
  683. return -ENOMEM;
  684. oparms.tcon = tcon;
  685. oparms.desired_access = FILE_READ_EA;
  686. oparms.disposition = FILE_OPEN;
  687. if (backup_cred(cifs_sb))
  688. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  689. else
  690. oparms.create_options = 0;
  691. oparms.fid = &fid;
  692. oparms.reconnect = false;
  693. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
  694. kfree(utf16_path);
  695. if (rc) {
  696. cifs_dbg(FYI, "open failed rc=%d\n", rc);
  697. return rc;
  698. }
  699. while (1) {
  700. smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
  701. if (smb2_data == NULL) {
  702. SMB2_close(xid, tcon, fid.persistent_fid,
  703. fid.volatile_fid);
  704. return -ENOMEM;
  705. }
  706. rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
  707. fid.volatile_fid,
  708. ea_buf_size, smb2_data);
  709. if (rc != -E2BIG)
  710. break;
  711. kfree(smb2_data);
  712. ea_buf_size <<= 1;
  713. if (ea_buf_size > SMB2_MAX_EA_BUF) {
  714. cifs_dbg(VFS, "EA size is too large\n");
  715. SMB2_close(xid, tcon, fid.persistent_fid,
  716. fid.volatile_fid);
  717. return -ENOMEM;
  718. }
  719. }
  720. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  721. /*
  722. * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's
  723. * not an error. Otherwise, the specified ea_name was not found.
  724. */
  725. if (!rc)
  726. rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
  727. SMB2_MAX_EA_BUF, ea_name);
  728. else if (!ea_name && rc == -ENODATA)
  729. rc = 0;
  730. kfree(smb2_data);
  731. return rc;
  732. }
  733. static int
  734. smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
  735. const char *path, const char *ea_name, const void *ea_value,
  736. const __u16 ea_value_len, const struct nls_table *nls_codepage,
  737. struct cifs_sb_info *cifs_sb)
  738. {
  739. int rc;
  740. __le16 *utf16_path;
  741. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  742. struct cifs_open_parms oparms;
  743. struct cifs_fid fid;
  744. struct smb2_file_full_ea_info *ea;
  745. int ea_name_len = strlen(ea_name);
  746. int len;
  747. if (ea_name_len > 255)
  748. return -EINVAL;
  749. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  750. if (!utf16_path)
  751. return -ENOMEM;
  752. oparms.tcon = tcon;
  753. oparms.desired_access = FILE_WRITE_EA;
  754. oparms.disposition = FILE_OPEN;
  755. if (backup_cred(cifs_sb))
  756. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  757. else
  758. oparms.create_options = 0;
  759. oparms.fid = &fid;
  760. oparms.reconnect = false;
  761. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
  762. kfree(utf16_path);
  763. if (rc) {
  764. cifs_dbg(FYI, "open failed rc=%d\n", rc);
  765. return rc;
  766. }
  767. len = sizeof(ea) + ea_name_len + ea_value_len + 1;
  768. ea = kzalloc(len, GFP_KERNEL);
  769. if (ea == NULL) {
  770. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  771. return -ENOMEM;
  772. }
  773. ea->ea_name_length = ea_name_len;
  774. ea->ea_value_length = cpu_to_le16(ea_value_len);
  775. memcpy(ea->ea_data, ea_name, ea_name_len + 1);
  776. memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
  777. rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
  778. len);
  779. kfree(ea);
  780. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  781. return rc;
  782. }
  783. #endif
  784. static bool
  785. smb2_can_echo(struct TCP_Server_Info *server)
  786. {
  787. return server->echoes;
  788. }
  789. static void
  790. smb2_clear_stats(struct cifs_tcon *tcon)
  791. {
  792. int i;
  793. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  794. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  795. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  796. }
  797. }
  798. static void
  799. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  800. {
  801. seq_puts(m, "\n\tShare Capabilities:");
  802. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  803. seq_puts(m, " DFS,");
  804. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  805. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  806. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  807. seq_puts(m, " SCALEOUT,");
  808. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  809. seq_puts(m, " CLUSTER,");
  810. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  811. seq_puts(m, " ASYMMETRIC,");
  812. if (tcon->capabilities == 0)
  813. seq_puts(m, " None");
  814. if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
  815. seq_puts(m, " Aligned,");
  816. if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
  817. seq_puts(m, " Partition Aligned,");
  818. if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
  819. seq_puts(m, " SSD,");
  820. if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
  821. seq_puts(m, " TRIM-support,");
  822. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  823. seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
  824. if (tcon->perf_sector_size)
  825. seq_printf(m, "\tOptimal sector size: 0x%x",
  826. tcon->perf_sector_size);
  827. seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
  828. }
  829. static void
  830. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  831. {
  832. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  833. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  834. /*
  835. * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
  836. * totals (requests sent) since those SMBs are per-session not per tcon
  837. */
  838. seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
  839. (long long)(tcon->bytes_read),
  840. (long long)(tcon->bytes_written));
  841. seq_printf(m, "\nTreeConnects: %d total %d failed",
  842. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  843. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  844. seq_printf(m, "\nTreeDisconnects: %d total %d failed",
  845. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  846. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  847. seq_printf(m, "\nCreates: %d total %d failed",
  848. atomic_read(&sent[SMB2_CREATE_HE]),
  849. atomic_read(&failed[SMB2_CREATE_HE]));
  850. seq_printf(m, "\nCloses: %d total %d failed",
  851. atomic_read(&sent[SMB2_CLOSE_HE]),
  852. atomic_read(&failed[SMB2_CLOSE_HE]));
  853. seq_printf(m, "\nFlushes: %d total %d failed",
  854. atomic_read(&sent[SMB2_FLUSH_HE]),
  855. atomic_read(&failed[SMB2_FLUSH_HE]));
  856. seq_printf(m, "\nReads: %d total %d failed",
  857. atomic_read(&sent[SMB2_READ_HE]),
  858. atomic_read(&failed[SMB2_READ_HE]));
  859. seq_printf(m, "\nWrites: %d total %d failed",
  860. atomic_read(&sent[SMB2_WRITE_HE]),
  861. atomic_read(&failed[SMB2_WRITE_HE]));
  862. seq_printf(m, "\nLocks: %d total %d failed",
  863. atomic_read(&sent[SMB2_LOCK_HE]),
  864. atomic_read(&failed[SMB2_LOCK_HE]));
  865. seq_printf(m, "\nIOCTLs: %d total %d failed",
  866. atomic_read(&sent[SMB2_IOCTL_HE]),
  867. atomic_read(&failed[SMB2_IOCTL_HE]));
  868. seq_printf(m, "\nQueryDirectories: %d total %d failed",
  869. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  870. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  871. seq_printf(m, "\nChangeNotifies: %d total %d failed",
  872. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  873. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  874. seq_printf(m, "\nQueryInfos: %d total %d failed",
  875. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  876. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  877. seq_printf(m, "\nSetInfos: %d total %d failed",
  878. atomic_read(&sent[SMB2_SET_INFO_HE]),
  879. atomic_read(&failed[SMB2_SET_INFO_HE]));
  880. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  881. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  882. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  883. }
  884. static void
  885. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  886. {
  887. struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
  888. struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
  889. cfile->fid.persistent_fid = fid->persistent_fid;
  890. cfile->fid.volatile_fid = fid->volatile_fid;
  891. server->ops->set_oplock_level(cinode, oplock, fid->epoch,
  892. &fid->purge_cache);
  893. cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
  894. memcpy(cfile->fid.create_guid, fid->create_guid, 16);
  895. }
  896. static void
  897. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  898. struct cifs_fid *fid)
  899. {
  900. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  901. }
  902. static int
  903. SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
  904. u64 persistent_fid, u64 volatile_fid,
  905. struct copychunk_ioctl *pcchunk)
  906. {
  907. int rc;
  908. unsigned int ret_data_len;
  909. struct resume_key_req *res_key;
  910. rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
  911. FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
  912. NULL, 0 /* no input */,
  913. (char **)&res_key, &ret_data_len);
  914. if (rc) {
  915. cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
  916. goto req_res_key_exit;
  917. }
  918. if (ret_data_len < sizeof(struct resume_key_req)) {
  919. cifs_dbg(VFS, "Invalid refcopy resume key length\n");
  920. rc = -EINVAL;
  921. goto req_res_key_exit;
  922. }
  923. memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
  924. req_res_key_exit:
  925. kfree(res_key);
  926. return rc;
  927. }
  928. static ssize_t
  929. smb2_copychunk_range(const unsigned int xid,
  930. struct cifsFileInfo *srcfile,
  931. struct cifsFileInfo *trgtfile, u64 src_off,
  932. u64 len, u64 dest_off)
  933. {
  934. int rc;
  935. unsigned int ret_data_len;
  936. struct copychunk_ioctl *pcchunk;
  937. struct copychunk_ioctl_rsp *retbuf = NULL;
  938. struct cifs_tcon *tcon;
  939. int chunks_copied = 0;
  940. bool chunk_sizes_updated = false;
  941. ssize_t bytes_written, total_bytes_written = 0;
  942. pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
  943. if (pcchunk == NULL)
  944. return -ENOMEM;
  945. cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
  946. /* Request a key from the server to identify the source of the copy */
  947. rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
  948. srcfile->fid.persistent_fid,
  949. srcfile->fid.volatile_fid, pcchunk);
  950. /* Note: request_res_key sets res_key null only if rc !=0 */
  951. if (rc)
  952. goto cchunk_out;
  953. /* For now array only one chunk long, will make more flexible later */
  954. pcchunk->ChunkCount = cpu_to_le32(1);
  955. pcchunk->Reserved = 0;
  956. pcchunk->Reserved2 = 0;
  957. tcon = tlink_tcon(trgtfile->tlink);
  958. while (len > 0) {
  959. pcchunk->SourceOffset = cpu_to_le64(src_off);
  960. pcchunk->TargetOffset = cpu_to_le64(dest_off);
  961. pcchunk->Length =
  962. cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
  963. /* Request server copy to target from src identified by key */
  964. rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
  965. trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
  966. true /* is_fsctl */, (char *)pcchunk,
  967. sizeof(struct copychunk_ioctl), (char **)&retbuf,
  968. &ret_data_len);
  969. if (rc == 0) {
  970. if (ret_data_len !=
  971. sizeof(struct copychunk_ioctl_rsp)) {
  972. cifs_dbg(VFS, "invalid cchunk response size\n");
  973. rc = -EIO;
  974. goto cchunk_out;
  975. }
  976. if (retbuf->TotalBytesWritten == 0) {
  977. cifs_dbg(FYI, "no bytes copied\n");
  978. rc = -EIO;
  979. goto cchunk_out;
  980. }
  981. /*
  982. * Check if server claimed to write more than we asked
  983. */
  984. if (le32_to_cpu(retbuf->TotalBytesWritten) >
  985. le32_to_cpu(pcchunk->Length)) {
  986. cifs_dbg(VFS, "invalid copy chunk response\n");
  987. rc = -EIO;
  988. goto cchunk_out;
  989. }
  990. if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
  991. cifs_dbg(VFS, "invalid num chunks written\n");
  992. rc = -EIO;
  993. goto cchunk_out;
  994. }
  995. chunks_copied++;
  996. bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
  997. src_off += bytes_written;
  998. dest_off += bytes_written;
  999. len -= bytes_written;
  1000. total_bytes_written += bytes_written;
  1001. cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
  1002. le32_to_cpu(retbuf->ChunksWritten),
  1003. le32_to_cpu(retbuf->ChunkBytesWritten),
  1004. bytes_written);
  1005. } else if (rc == -EINVAL) {
  1006. if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
  1007. goto cchunk_out;
  1008. cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
  1009. le32_to_cpu(retbuf->ChunksWritten),
  1010. le32_to_cpu(retbuf->ChunkBytesWritten),
  1011. le32_to_cpu(retbuf->TotalBytesWritten));
  1012. /*
  1013. * Check if this is the first request using these sizes,
  1014. * (ie check if copy succeed once with original sizes
  1015. * and check if the server gave us different sizes after
  1016. * we already updated max sizes on previous request).
  1017. * if not then why is the server returning an error now
  1018. */
  1019. if ((chunks_copied != 0) || chunk_sizes_updated)
  1020. goto cchunk_out;
  1021. /* Check that server is not asking us to grow size */
  1022. if (le32_to_cpu(retbuf->ChunkBytesWritten) <
  1023. tcon->max_bytes_chunk)
  1024. tcon->max_bytes_chunk =
  1025. le32_to_cpu(retbuf->ChunkBytesWritten);
  1026. else
  1027. goto cchunk_out; /* server gave us bogus size */
  1028. /* No need to change MaxChunks since already set to 1 */
  1029. chunk_sizes_updated = true;
  1030. } else
  1031. goto cchunk_out;
  1032. }
  1033. cchunk_out:
  1034. kfree(pcchunk);
  1035. kfree(retbuf);
  1036. if (rc)
  1037. return rc;
  1038. else
  1039. return total_bytes_written;
  1040. }
  1041. static int
  1042. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  1043. struct cifs_fid *fid)
  1044. {
  1045. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  1046. }
  1047. static unsigned int
  1048. smb2_read_data_offset(char *buf)
  1049. {
  1050. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  1051. return rsp->DataOffset;
  1052. }
  1053. static unsigned int
  1054. smb2_read_data_length(char *buf, bool in_remaining)
  1055. {
  1056. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  1057. if (in_remaining)
  1058. return le32_to_cpu(rsp->DataRemaining);
  1059. return le32_to_cpu(rsp->DataLength);
  1060. }
  1061. static int
  1062. smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
  1063. struct cifs_io_parms *parms, unsigned int *bytes_read,
  1064. char **buf, int *buf_type)
  1065. {
  1066. parms->persistent_fid = pfid->persistent_fid;
  1067. parms->volatile_fid = pfid->volatile_fid;
  1068. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  1069. }
  1070. static int
  1071. smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
  1072. struct cifs_io_parms *parms, unsigned int *written,
  1073. struct kvec *iov, unsigned long nr_segs)
  1074. {
  1075. parms->persistent_fid = pfid->persistent_fid;
  1076. parms->volatile_fid = pfid->volatile_fid;
  1077. return SMB2_write(xid, parms, written, iov, nr_segs);
  1078. }
  1079. /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
  1080. static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
  1081. struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
  1082. {
  1083. struct cifsInodeInfo *cifsi;
  1084. int rc;
  1085. cifsi = CIFS_I(inode);
  1086. /* if file already sparse don't bother setting sparse again */
  1087. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
  1088. return true; /* already sparse */
  1089. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
  1090. return true; /* already not sparse */
  1091. /*
  1092. * Can't check for sparse support on share the usual way via the
  1093. * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
  1094. * since Samba server doesn't set the flag on the share, yet
  1095. * supports the set sparse FSCTL and returns sparse correctly
  1096. * in the file attributes. If we fail setting sparse though we
  1097. * mark that server does not support sparse files for this share
  1098. * to avoid repeatedly sending the unsupported fsctl to server
  1099. * if the file is repeatedly extended.
  1100. */
  1101. if (tcon->broken_sparse_sup)
  1102. return false;
  1103. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1104. cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
  1105. true /* is_fctl */,
  1106. &setsparse, 1, NULL, NULL);
  1107. if (rc) {
  1108. tcon->broken_sparse_sup = true;
  1109. cifs_dbg(FYI, "set sparse rc = %d\n", rc);
  1110. return false;
  1111. }
  1112. if (setsparse)
  1113. cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
  1114. else
  1115. cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
  1116. return true;
  1117. }
  1118. static int
  1119. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  1120. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  1121. {
  1122. __le64 eof = cpu_to_le64(size);
  1123. struct inode *inode;
  1124. /*
  1125. * If extending file more than one page make sparse. Many Linux fs
  1126. * make files sparse by default when extending via ftruncate
  1127. */
  1128. inode = d_inode(cfile->dentry);
  1129. if (!set_alloc && (size > inode->i_size + 8192)) {
  1130. __u8 set_sparse = 1;
  1131. /* whether set sparse succeeds or not, extend the file */
  1132. smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
  1133. }
  1134. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  1135. cfile->fid.volatile_fid, cfile->pid, &eof, false);
  1136. }
  1137. static int
  1138. smb2_duplicate_extents(const unsigned int xid,
  1139. struct cifsFileInfo *srcfile,
  1140. struct cifsFileInfo *trgtfile, u64 src_off,
  1141. u64 len, u64 dest_off)
  1142. {
  1143. int rc;
  1144. unsigned int ret_data_len;
  1145. struct duplicate_extents_to_file dup_ext_buf;
  1146. struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
  1147. /* server fileays advertise duplicate extent support with this flag */
  1148. if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
  1149. FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
  1150. return -EOPNOTSUPP;
  1151. dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
  1152. dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
  1153. dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
  1154. dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
  1155. dup_ext_buf.ByteCount = cpu_to_le64(len);
  1156. cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
  1157. src_off, dest_off, len);
  1158. rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
  1159. if (rc)
  1160. goto duplicate_extents_out;
  1161. rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
  1162. trgtfile->fid.volatile_fid,
  1163. FSCTL_DUPLICATE_EXTENTS_TO_FILE,
  1164. true /* is_fsctl */,
  1165. (char *)&dup_ext_buf,
  1166. sizeof(struct duplicate_extents_to_file),
  1167. NULL,
  1168. &ret_data_len);
  1169. if (ret_data_len > 0)
  1170. cifs_dbg(FYI, "non-zero response length in duplicate extents");
  1171. duplicate_extents_out:
  1172. return rc;
  1173. }
  1174. static int
  1175. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  1176. struct cifsFileInfo *cfile)
  1177. {
  1178. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  1179. cfile->fid.volatile_fid);
  1180. }
  1181. static int
  1182. smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
  1183. struct cifsFileInfo *cfile)
  1184. {
  1185. struct fsctl_set_integrity_information_req integr_info;
  1186. unsigned int ret_data_len;
  1187. integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
  1188. integr_info.Flags = 0;
  1189. integr_info.Reserved = 0;
  1190. return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1191. cfile->fid.volatile_fid,
  1192. FSCTL_SET_INTEGRITY_INFORMATION,
  1193. true /* is_fsctl */,
  1194. (char *)&integr_info,
  1195. sizeof(struct fsctl_set_integrity_information_req),
  1196. NULL,
  1197. &ret_data_len);
  1198. }
  1199. /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
  1200. #define GMT_TOKEN_SIZE 50
  1201. /*
  1202. * Input buffer contains (empty) struct smb_snapshot array with size filled in
  1203. * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
  1204. */
  1205. static int
  1206. smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
  1207. struct cifsFileInfo *cfile, void __user *ioc_buf)
  1208. {
  1209. char *retbuf = NULL;
  1210. unsigned int ret_data_len = 0;
  1211. int rc;
  1212. struct smb_snapshot_array snapshot_in;
  1213. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1214. cfile->fid.volatile_fid,
  1215. FSCTL_SRV_ENUMERATE_SNAPSHOTS,
  1216. true /* is_fsctl */,
  1217. NULL, 0 /* no input data */,
  1218. (char **)&retbuf,
  1219. &ret_data_len);
  1220. cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
  1221. rc, ret_data_len);
  1222. if (rc)
  1223. return rc;
  1224. if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
  1225. /* Fixup buffer */
  1226. if (copy_from_user(&snapshot_in, ioc_buf,
  1227. sizeof(struct smb_snapshot_array))) {
  1228. rc = -EFAULT;
  1229. kfree(retbuf);
  1230. return rc;
  1231. }
  1232. /*
  1233. * Check for min size, ie not large enough to fit even one GMT
  1234. * token (snapshot). On the first ioctl some users may pass in
  1235. * smaller size (or zero) to simply get the size of the array
  1236. * so the user space caller can allocate sufficient memory
  1237. * and retry the ioctl again with larger array size sufficient
  1238. * to hold all of the snapshot GMT tokens on the second try.
  1239. */
  1240. if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
  1241. ret_data_len = sizeof(struct smb_snapshot_array);
  1242. /*
  1243. * We return struct SRV_SNAPSHOT_ARRAY, followed by
  1244. * the snapshot array (of 50 byte GMT tokens) each
  1245. * representing an available previous version of the data
  1246. */
  1247. if (ret_data_len > (snapshot_in.snapshot_array_size +
  1248. sizeof(struct smb_snapshot_array)))
  1249. ret_data_len = snapshot_in.snapshot_array_size +
  1250. sizeof(struct smb_snapshot_array);
  1251. if (copy_to_user(ioc_buf, retbuf, ret_data_len))
  1252. rc = -EFAULT;
  1253. }
  1254. kfree(retbuf);
  1255. return rc;
  1256. }
  1257. static int
  1258. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  1259. const char *path, struct cifs_sb_info *cifs_sb,
  1260. struct cifs_fid *fid, __u16 search_flags,
  1261. struct cifs_search_info *srch_inf)
  1262. {
  1263. __le16 *utf16_path;
  1264. int rc;
  1265. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1266. struct cifs_open_parms oparms;
  1267. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  1268. if (!utf16_path)
  1269. return -ENOMEM;
  1270. oparms.tcon = tcon;
  1271. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  1272. oparms.disposition = FILE_OPEN;
  1273. if (backup_cred(cifs_sb))
  1274. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  1275. else
  1276. oparms.create_options = 0;
  1277. oparms.fid = fid;
  1278. oparms.reconnect = false;
  1279. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
  1280. kfree(utf16_path);
  1281. if (rc) {
  1282. cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
  1283. return rc;
  1284. }
  1285. srch_inf->entries_in_buffer = 0;
  1286. srch_inf->index_of_last_entry = 2;
  1287. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  1288. fid->volatile_fid, 0, srch_inf);
  1289. if (rc) {
  1290. cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
  1291. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  1292. }
  1293. return rc;
  1294. }
  1295. static int
  1296. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  1297. struct cifs_fid *fid, __u16 search_flags,
  1298. struct cifs_search_info *srch_inf)
  1299. {
  1300. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  1301. fid->volatile_fid, 0, srch_inf);
  1302. }
  1303. static int
  1304. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  1305. struct cifs_fid *fid)
  1306. {
  1307. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  1308. }
  1309. /*
  1310. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  1311. * the number of credits and return true. Otherwise - return false.
  1312. */
  1313. static bool
  1314. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  1315. {
  1316. struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
  1317. if (shdr->Status != STATUS_PENDING)
  1318. return false;
  1319. if (!length) {
  1320. spin_lock(&server->req_lock);
  1321. server->credits += le16_to_cpu(shdr->CreditRequest);
  1322. spin_unlock(&server->req_lock);
  1323. wake_up(&server->request_q);
  1324. }
  1325. return true;
  1326. }
  1327. static bool
  1328. smb2_is_session_expired(char *buf)
  1329. {
  1330. struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
  1331. if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
  1332. shdr->Status != STATUS_USER_SESSION_DELETED)
  1333. return false;
  1334. trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
  1335. le16_to_cpu(shdr->Command),
  1336. le64_to_cpu(shdr->MessageId));
  1337. cifs_dbg(FYI, "Session expired or deleted\n");
  1338. return true;
  1339. }
  1340. static int
  1341. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  1342. struct cifsInodeInfo *cinode)
  1343. {
  1344. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  1345. return SMB2_lease_break(0, tcon, cinode->lease_key,
  1346. smb2_get_lease_state(cinode));
  1347. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  1348. fid->volatile_fid,
  1349. CIFS_CACHE_READ(cinode) ? 1 : 0);
  1350. }
  1351. static void
  1352. smb2_set_related(struct smb_rqst *rqst)
  1353. {
  1354. struct smb2_sync_hdr *shdr;
  1355. shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
  1356. shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
  1357. }
  1358. char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
  1359. static void
  1360. smb2_set_next_command(struct TCP_Server_Info *server, struct smb_rqst *rqst)
  1361. {
  1362. struct smb2_sync_hdr *shdr;
  1363. unsigned long len = smb_rqst_len(server, rqst);
  1364. /* SMB headers in a compound are 8 byte aligned. */
  1365. if (len & 7) {
  1366. rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
  1367. rqst->rq_iov[rqst->rq_nvec].iov_len = 8 - (len & 7);
  1368. rqst->rq_nvec++;
  1369. len = smb_rqst_len(server, rqst);
  1370. }
  1371. shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
  1372. shdr->NextCommand = cpu_to_le32(len);
  1373. }
  1374. static int
  1375. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  1376. struct kstatfs *buf)
  1377. {
  1378. struct smb2_query_info_rsp *rsp;
  1379. struct smb2_fs_full_size_info *info = NULL;
  1380. struct smb_rqst rqst[3];
  1381. int resp_buftype[3];
  1382. struct kvec rsp_iov[3];
  1383. struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
  1384. struct kvec qi_iov[1];
  1385. struct kvec close_iov[1];
  1386. struct cifs_ses *ses = tcon->ses;
  1387. struct TCP_Server_Info *server = ses->server;
  1388. __le16 srch_path = 0; /* Null - open root of share */
  1389. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1390. struct cifs_open_parms oparms;
  1391. struct cifs_fid fid;
  1392. int flags = 0;
  1393. int rc;
  1394. if (smb3_encryption_required(tcon))
  1395. flags |= CIFS_TRANSFORM_REQ;
  1396. memset(rqst, 0, sizeof(rqst));
  1397. memset(resp_buftype, 0, sizeof(resp_buftype));
  1398. memset(rsp_iov, 0, sizeof(rsp_iov));
  1399. memset(&open_iov, 0, sizeof(open_iov));
  1400. rqst[0].rq_iov = open_iov;
  1401. rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
  1402. oparms.tcon = tcon;
  1403. oparms.desired_access = FILE_READ_ATTRIBUTES;
  1404. oparms.disposition = FILE_OPEN;
  1405. oparms.create_options = 0;
  1406. oparms.fid = &fid;
  1407. oparms.reconnect = false;
  1408. rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &srch_path);
  1409. if (rc)
  1410. goto qfs_exit;
  1411. smb2_set_next_command(server, &rqst[0]);
  1412. memset(&qi_iov, 0, sizeof(qi_iov));
  1413. rqst[1].rq_iov = qi_iov;
  1414. rqst[1].rq_nvec = 1;
  1415. rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
  1416. FS_FULL_SIZE_INFORMATION,
  1417. SMB2_O_INFO_FILESYSTEM, 0,
  1418. sizeof(struct smb2_fs_full_size_info));
  1419. if (rc)
  1420. goto qfs_exit;
  1421. smb2_set_next_command(server, &rqst[1]);
  1422. smb2_set_related(&rqst[1]);
  1423. memset(&close_iov, 0, sizeof(close_iov));
  1424. rqst[2].rq_iov = close_iov;
  1425. rqst[2].rq_nvec = 1;
  1426. rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
  1427. if (rc)
  1428. goto qfs_exit;
  1429. smb2_set_related(&rqst[2]);
  1430. rc = compound_send_recv(xid, ses, flags, 3, rqst,
  1431. resp_buftype, rsp_iov);
  1432. if (rc)
  1433. goto qfs_exit;
  1434. rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
  1435. buf->f_type = SMB2_MAGIC_NUMBER;
  1436. info = (struct smb2_fs_full_size_info *)(
  1437. le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
  1438. rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
  1439. le32_to_cpu(rsp->OutputBufferLength),
  1440. &rsp_iov[1],
  1441. sizeof(struct smb2_fs_full_size_info));
  1442. if (!rc)
  1443. smb2_copy_fs_info_to_kstatfs(info, buf);
  1444. qfs_exit:
  1445. SMB2_open_free(&rqst[0]);
  1446. SMB2_query_info_free(&rqst[1]);
  1447. SMB2_close_free(&rqst[2]);
  1448. free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
  1449. free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
  1450. free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
  1451. return rc;
  1452. }
  1453. static int
  1454. smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  1455. struct kstatfs *buf)
  1456. {
  1457. int rc;
  1458. __le16 srch_path = 0; /* Null - open root of share */
  1459. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1460. struct cifs_open_parms oparms;
  1461. struct cifs_fid fid;
  1462. if (!tcon->posix_extensions)
  1463. return smb2_queryfs(xid, tcon, buf);
  1464. oparms.tcon = tcon;
  1465. oparms.desired_access = FILE_READ_ATTRIBUTES;
  1466. oparms.disposition = FILE_OPEN;
  1467. oparms.create_options = 0;
  1468. oparms.fid = &fid;
  1469. oparms.reconnect = false;
  1470. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
  1471. if (rc)
  1472. return rc;
  1473. rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
  1474. fid.volatile_fid, buf);
  1475. buf->f_type = SMB2_MAGIC_NUMBER;
  1476. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  1477. return rc;
  1478. }
  1479. static bool
  1480. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  1481. {
  1482. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  1483. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  1484. }
  1485. static int
  1486. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  1487. __u64 length, __u32 type, int lock, int unlock, bool wait)
  1488. {
  1489. if (unlock && !lock)
  1490. type = SMB2_LOCKFLAG_UNLOCK;
  1491. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  1492. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  1493. current->tgid, length, offset, type, wait);
  1494. }
  1495. static void
  1496. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  1497. {
  1498. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  1499. }
  1500. static void
  1501. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  1502. {
  1503. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  1504. }
  1505. static void
  1506. smb2_new_lease_key(struct cifs_fid *fid)
  1507. {
  1508. generate_random_uuid(fid->lease_key);
  1509. }
  1510. static int
  1511. smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
  1512. const char *search_name,
  1513. struct dfs_info3_param **target_nodes,
  1514. unsigned int *num_of_nodes,
  1515. const struct nls_table *nls_codepage, int remap)
  1516. {
  1517. int rc;
  1518. __le16 *utf16_path = NULL;
  1519. int utf16_path_len = 0;
  1520. struct cifs_tcon *tcon;
  1521. struct fsctl_get_dfs_referral_req *dfs_req = NULL;
  1522. struct get_dfs_referral_rsp *dfs_rsp = NULL;
  1523. u32 dfs_req_size = 0, dfs_rsp_size = 0;
  1524. cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
  1525. /*
  1526. * Try to use the IPC tcon, otherwise just use any
  1527. */
  1528. tcon = ses->tcon_ipc;
  1529. if (tcon == NULL) {
  1530. spin_lock(&cifs_tcp_ses_lock);
  1531. tcon = list_first_entry_or_null(&ses->tcon_list,
  1532. struct cifs_tcon,
  1533. tcon_list);
  1534. if (tcon)
  1535. tcon->tc_count++;
  1536. spin_unlock(&cifs_tcp_ses_lock);
  1537. }
  1538. if (tcon == NULL) {
  1539. cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
  1540. ses);
  1541. rc = -ENOTCONN;
  1542. goto out;
  1543. }
  1544. utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
  1545. &utf16_path_len,
  1546. nls_codepage, remap);
  1547. if (!utf16_path) {
  1548. rc = -ENOMEM;
  1549. goto out;
  1550. }
  1551. dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
  1552. dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
  1553. if (!dfs_req) {
  1554. rc = -ENOMEM;
  1555. goto out;
  1556. }
  1557. /* Highest DFS referral version understood */
  1558. dfs_req->MaxReferralLevel = DFS_VERSION;
  1559. /* Path to resolve in an UTF-16 null-terminated string */
  1560. memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
  1561. do {
  1562. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  1563. FSCTL_DFS_GET_REFERRALS,
  1564. true /* is_fsctl */,
  1565. (char *)dfs_req, dfs_req_size,
  1566. (char **)&dfs_rsp, &dfs_rsp_size);
  1567. } while (rc == -EAGAIN);
  1568. if (rc) {
  1569. if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
  1570. cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
  1571. goto out;
  1572. }
  1573. rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
  1574. num_of_nodes, target_nodes,
  1575. nls_codepage, remap, search_name,
  1576. true /* is_unicode */);
  1577. if (rc) {
  1578. cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
  1579. goto out;
  1580. }
  1581. out:
  1582. if (tcon && !tcon->ipc) {
  1583. /* ipc tcons are not refcounted */
  1584. spin_lock(&cifs_tcp_ses_lock);
  1585. tcon->tc_count--;
  1586. spin_unlock(&cifs_tcp_ses_lock);
  1587. }
  1588. kfree(utf16_path);
  1589. kfree(dfs_req);
  1590. kfree(dfs_rsp);
  1591. return rc;
  1592. }
  1593. #define SMB2_SYMLINK_STRUCT_SIZE \
  1594. (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
  1595. static int
  1596. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  1597. const char *full_path, char **target_path,
  1598. struct cifs_sb_info *cifs_sb)
  1599. {
  1600. int rc;
  1601. __le16 *utf16_path;
  1602. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1603. struct cifs_open_parms oparms;
  1604. struct cifs_fid fid;
  1605. struct kvec err_iov = {NULL, 0};
  1606. struct smb2_err_rsp *err_buf = NULL;
  1607. int resp_buftype;
  1608. struct smb2_symlink_err_rsp *symlink;
  1609. unsigned int sub_len;
  1610. unsigned int sub_offset;
  1611. unsigned int print_len;
  1612. unsigned int print_offset;
  1613. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  1614. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  1615. if (!utf16_path)
  1616. return -ENOMEM;
  1617. oparms.tcon = tcon;
  1618. oparms.desired_access = FILE_READ_ATTRIBUTES;
  1619. oparms.disposition = FILE_OPEN;
  1620. if (backup_cred(cifs_sb))
  1621. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  1622. else
  1623. oparms.create_options = 0;
  1624. oparms.fid = &fid;
  1625. oparms.reconnect = false;
  1626. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
  1627. &resp_buftype);
  1628. if (!rc || !err_iov.iov_base) {
  1629. rc = -ENOENT;
  1630. goto free_path;
  1631. }
  1632. err_buf = err_iov.iov_base;
  1633. if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
  1634. err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
  1635. rc = -ENOENT;
  1636. goto querty_exit;
  1637. }
  1638. /* open must fail on symlink - reset rc */
  1639. rc = 0;
  1640. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  1641. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  1642. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  1643. print_len = le16_to_cpu(symlink->PrintNameLength);
  1644. print_offset = le16_to_cpu(symlink->PrintNameOffset);
  1645. if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
  1646. rc = -ENOENT;
  1647. goto querty_exit;
  1648. }
  1649. if (err_iov.iov_len <
  1650. SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
  1651. rc = -ENOENT;
  1652. goto querty_exit;
  1653. }
  1654. *target_path = cifs_strndup_from_utf16(
  1655. (char *)symlink->PathBuffer + sub_offset,
  1656. sub_len, true, cifs_sb->local_nls);
  1657. if (!(*target_path)) {
  1658. rc = -ENOMEM;
  1659. goto querty_exit;
  1660. }
  1661. convert_delimiter(*target_path, '/');
  1662. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  1663. querty_exit:
  1664. free_rsp_buf(resp_buftype, err_buf);
  1665. free_path:
  1666. kfree(utf16_path);
  1667. return rc;
  1668. }
  1669. #ifdef CONFIG_CIFS_ACL
  1670. static struct cifs_ntsd *
  1671. get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
  1672. const struct cifs_fid *cifsfid, u32 *pacllen)
  1673. {
  1674. struct cifs_ntsd *pntsd = NULL;
  1675. unsigned int xid;
  1676. int rc = -EOPNOTSUPP;
  1677. struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
  1678. if (IS_ERR(tlink))
  1679. return ERR_CAST(tlink);
  1680. xid = get_xid();
  1681. cifs_dbg(FYI, "trying to get acl\n");
  1682. rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
  1683. cifsfid->volatile_fid, (void **)&pntsd, pacllen);
  1684. free_xid(xid);
  1685. cifs_put_tlink(tlink);
  1686. cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
  1687. if (rc)
  1688. return ERR_PTR(rc);
  1689. return pntsd;
  1690. }
  1691. static struct cifs_ntsd *
  1692. get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
  1693. const char *path, u32 *pacllen)
  1694. {
  1695. struct cifs_ntsd *pntsd = NULL;
  1696. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1697. unsigned int xid;
  1698. int rc;
  1699. struct cifs_tcon *tcon;
  1700. struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
  1701. struct cifs_fid fid;
  1702. struct cifs_open_parms oparms;
  1703. __le16 *utf16_path;
  1704. cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
  1705. if (IS_ERR(tlink))
  1706. return ERR_CAST(tlink);
  1707. tcon = tlink_tcon(tlink);
  1708. xid = get_xid();
  1709. if (backup_cred(cifs_sb))
  1710. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  1711. else
  1712. oparms.create_options = 0;
  1713. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  1714. if (!utf16_path) {
  1715. rc = -ENOMEM;
  1716. free_xid(xid);
  1717. return ERR_PTR(rc);
  1718. }
  1719. oparms.tcon = tcon;
  1720. oparms.desired_access = READ_CONTROL;
  1721. oparms.disposition = FILE_OPEN;
  1722. oparms.fid = &fid;
  1723. oparms.reconnect = false;
  1724. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
  1725. kfree(utf16_path);
  1726. if (!rc) {
  1727. rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
  1728. fid.volatile_fid, (void **)&pntsd, pacllen);
  1729. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  1730. }
  1731. cifs_put_tlink(tlink);
  1732. free_xid(xid);
  1733. cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
  1734. if (rc)
  1735. return ERR_PTR(rc);
  1736. return pntsd;
  1737. }
  1738. #ifdef CONFIG_CIFS_ACL
  1739. static int
  1740. set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
  1741. struct inode *inode, const char *path, int aclflag)
  1742. {
  1743. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  1744. unsigned int xid;
  1745. int rc, access_flags = 0;
  1746. struct cifs_tcon *tcon;
  1747. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  1748. struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
  1749. struct cifs_fid fid;
  1750. struct cifs_open_parms oparms;
  1751. __le16 *utf16_path;
  1752. cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
  1753. if (IS_ERR(tlink))
  1754. return PTR_ERR(tlink);
  1755. tcon = tlink_tcon(tlink);
  1756. xid = get_xid();
  1757. if (backup_cred(cifs_sb))
  1758. oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
  1759. else
  1760. oparms.create_options = 0;
  1761. if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
  1762. access_flags = WRITE_OWNER;
  1763. else
  1764. access_flags = WRITE_DAC;
  1765. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  1766. if (!utf16_path) {
  1767. rc = -ENOMEM;
  1768. free_xid(xid);
  1769. return rc;
  1770. }
  1771. oparms.tcon = tcon;
  1772. oparms.desired_access = access_flags;
  1773. oparms.disposition = FILE_OPEN;
  1774. oparms.path = path;
  1775. oparms.fid = &fid;
  1776. oparms.reconnect = false;
  1777. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
  1778. kfree(utf16_path);
  1779. if (!rc) {
  1780. rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
  1781. fid.volatile_fid, pnntsd, acllen, aclflag);
  1782. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  1783. }
  1784. cifs_put_tlink(tlink);
  1785. free_xid(xid);
  1786. return rc;
  1787. }
  1788. #endif /* CIFS_ACL */
  1789. /* Retrieve an ACL from the server */
  1790. static struct cifs_ntsd *
  1791. get_smb2_acl(struct cifs_sb_info *cifs_sb,
  1792. struct inode *inode, const char *path,
  1793. u32 *pacllen)
  1794. {
  1795. struct cifs_ntsd *pntsd = NULL;
  1796. struct cifsFileInfo *open_file = NULL;
  1797. if (inode)
  1798. open_file = find_readable_file(CIFS_I(inode), true);
  1799. if (!open_file)
  1800. return get_smb2_acl_by_path(cifs_sb, path, pacllen);
  1801. pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
  1802. cifsFileInfo_put(open_file);
  1803. return pntsd;
  1804. }
  1805. #endif
  1806. static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
  1807. loff_t offset, loff_t len, bool keep_size)
  1808. {
  1809. struct inode *inode;
  1810. struct cifsInodeInfo *cifsi;
  1811. struct cifsFileInfo *cfile = file->private_data;
  1812. struct file_zero_data_information fsctl_buf;
  1813. long rc;
  1814. unsigned int xid;
  1815. xid = get_xid();
  1816. inode = d_inode(cfile->dentry);
  1817. cifsi = CIFS_I(inode);
  1818. /* if file not oplocked can't be sure whether asking to extend size */
  1819. if (!CIFS_CACHE_READ(cifsi))
  1820. if (keep_size == false) {
  1821. rc = -EOPNOTSUPP;
  1822. free_xid(xid);
  1823. return rc;
  1824. }
  1825. /*
  1826. * Must check if file sparse since fallocate -z (zero range) assumes
  1827. * non-sparse allocation
  1828. */
  1829. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
  1830. rc = -EOPNOTSUPP;
  1831. free_xid(xid);
  1832. return rc;
  1833. }
  1834. /*
  1835. * need to make sure we are not asked to extend the file since the SMB3
  1836. * fsctl does not change the file size. In the future we could change
  1837. * this to zero the first part of the range then set the file size
  1838. * which for a non sparse file would zero the newly extended range
  1839. */
  1840. if (keep_size == false)
  1841. if (i_size_read(inode) < offset + len) {
  1842. rc = -EOPNOTSUPP;
  1843. free_xid(xid);
  1844. return rc;
  1845. }
  1846. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  1847. fsctl_buf.FileOffset = cpu_to_le64(offset);
  1848. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  1849. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1850. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  1851. true /* is_fctl */, (char *)&fsctl_buf,
  1852. sizeof(struct file_zero_data_information), NULL, NULL);
  1853. free_xid(xid);
  1854. return rc;
  1855. }
  1856. static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
  1857. loff_t offset, loff_t len)
  1858. {
  1859. struct inode *inode;
  1860. struct cifsInodeInfo *cifsi;
  1861. struct cifsFileInfo *cfile = file->private_data;
  1862. struct file_zero_data_information fsctl_buf;
  1863. long rc;
  1864. unsigned int xid;
  1865. __u8 set_sparse = 1;
  1866. xid = get_xid();
  1867. inode = d_inode(cfile->dentry);
  1868. cifsi = CIFS_I(inode);
  1869. /* Need to make file sparse, if not already, before freeing range. */
  1870. /* Consider adding equivalent for compressed since it could also work */
  1871. if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
  1872. rc = -EOPNOTSUPP;
  1873. free_xid(xid);
  1874. return rc;
  1875. }
  1876. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  1877. fsctl_buf.FileOffset = cpu_to_le64(offset);
  1878. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  1879. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  1880. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  1881. true /* is_fctl */, (char *)&fsctl_buf,
  1882. sizeof(struct file_zero_data_information), NULL, NULL);
  1883. free_xid(xid);
  1884. return rc;
  1885. }
  1886. static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
  1887. loff_t off, loff_t len, bool keep_size)
  1888. {
  1889. struct inode *inode;
  1890. struct cifsInodeInfo *cifsi;
  1891. struct cifsFileInfo *cfile = file->private_data;
  1892. long rc = -EOPNOTSUPP;
  1893. unsigned int xid;
  1894. xid = get_xid();
  1895. inode = d_inode(cfile->dentry);
  1896. cifsi = CIFS_I(inode);
  1897. /* if file not oplocked can't be sure whether asking to extend size */
  1898. if (!CIFS_CACHE_READ(cifsi))
  1899. if (keep_size == false) {
  1900. free_xid(xid);
  1901. return rc;
  1902. }
  1903. /*
  1904. * Files are non-sparse by default so falloc may be a no-op
  1905. * Must check if file sparse. If not sparse, and not extending
  1906. * then no need to do anything since file already allocated
  1907. */
  1908. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
  1909. if (keep_size == true)
  1910. rc = 0;
  1911. /* check if extending file */
  1912. else if (i_size_read(inode) >= off + len)
  1913. /* not extending file and already not sparse */
  1914. rc = 0;
  1915. /* BB: in future add else clause to extend file */
  1916. else
  1917. rc = -EOPNOTSUPP;
  1918. free_xid(xid);
  1919. return rc;
  1920. }
  1921. if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
  1922. /*
  1923. * Check if falloc starts within first few pages of file
  1924. * and ends within a few pages of the end of file to
  1925. * ensure that most of file is being forced to be
  1926. * fallocated now. If so then setting whole file sparse
  1927. * ie potentially making a few extra pages at the beginning
  1928. * or end of the file non-sparse via set_sparse is harmless.
  1929. */
  1930. if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
  1931. rc = -EOPNOTSUPP;
  1932. free_xid(xid);
  1933. return rc;
  1934. }
  1935. rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
  1936. }
  1937. /* BB: else ... in future add code to extend file and set sparse */
  1938. free_xid(xid);
  1939. return rc;
  1940. }
  1941. static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
  1942. loff_t off, loff_t len)
  1943. {
  1944. /* KEEP_SIZE already checked for by do_fallocate */
  1945. if (mode & FALLOC_FL_PUNCH_HOLE)
  1946. return smb3_punch_hole(file, tcon, off, len);
  1947. else if (mode & FALLOC_FL_ZERO_RANGE) {
  1948. if (mode & FALLOC_FL_KEEP_SIZE)
  1949. return smb3_zero_range(file, tcon, off, len, true);
  1950. return smb3_zero_range(file, tcon, off, len, false);
  1951. } else if (mode == FALLOC_FL_KEEP_SIZE)
  1952. return smb3_simple_falloc(file, tcon, off, len, true);
  1953. else if (mode == 0)
  1954. return smb3_simple_falloc(file, tcon, off, len, false);
  1955. return -EOPNOTSUPP;
  1956. }
  1957. static void
  1958. smb2_downgrade_oplock(struct TCP_Server_Info *server,
  1959. struct cifsInodeInfo *cinode, bool set_level2)
  1960. {
  1961. if (set_level2)
  1962. server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
  1963. 0, NULL);
  1964. else
  1965. server->ops->set_oplock_level(cinode, 0, 0, NULL);
  1966. }
  1967. static void
  1968. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1969. unsigned int epoch, bool *purge_cache)
  1970. {
  1971. oplock &= 0xFF;
  1972. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1973. return;
  1974. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  1975. cinode->oplock = CIFS_CACHE_RHW_FLG;
  1976. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  1977. &cinode->vfs_inode);
  1978. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  1979. cinode->oplock = CIFS_CACHE_RW_FLG;
  1980. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  1981. &cinode->vfs_inode);
  1982. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  1983. cinode->oplock = CIFS_CACHE_READ_FLG;
  1984. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  1985. &cinode->vfs_inode);
  1986. } else
  1987. cinode->oplock = 0;
  1988. }
  1989. static void
  1990. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1991. unsigned int epoch, bool *purge_cache)
  1992. {
  1993. char message[5] = {0};
  1994. oplock &= 0xFF;
  1995. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1996. return;
  1997. cinode->oplock = 0;
  1998. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  1999. cinode->oplock |= CIFS_CACHE_READ_FLG;
  2000. strcat(message, "R");
  2001. }
  2002. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  2003. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  2004. strcat(message, "H");
  2005. }
  2006. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  2007. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  2008. strcat(message, "W");
  2009. }
  2010. if (!cinode->oplock)
  2011. strcat(message, "None");
  2012. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  2013. &cinode->vfs_inode);
  2014. }
  2015. static void
  2016. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  2017. unsigned int epoch, bool *purge_cache)
  2018. {
  2019. unsigned int old_oplock = cinode->oplock;
  2020. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  2021. if (purge_cache) {
  2022. *purge_cache = false;
  2023. if (old_oplock == CIFS_CACHE_READ_FLG) {
  2024. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  2025. (epoch - cinode->epoch > 0))
  2026. *purge_cache = true;
  2027. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  2028. (epoch - cinode->epoch > 1))
  2029. *purge_cache = true;
  2030. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  2031. (epoch - cinode->epoch > 1))
  2032. *purge_cache = true;
  2033. else if (cinode->oplock == 0 &&
  2034. (epoch - cinode->epoch > 0))
  2035. *purge_cache = true;
  2036. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  2037. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  2038. (epoch - cinode->epoch > 0))
  2039. *purge_cache = true;
  2040. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  2041. (epoch - cinode->epoch > 1))
  2042. *purge_cache = true;
  2043. }
  2044. cinode->epoch = epoch;
  2045. }
  2046. }
  2047. static bool
  2048. smb2_is_read_op(__u32 oplock)
  2049. {
  2050. return oplock == SMB2_OPLOCK_LEVEL_II;
  2051. }
  2052. static bool
  2053. smb21_is_read_op(__u32 oplock)
  2054. {
  2055. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  2056. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  2057. }
  2058. static __le32
  2059. map_oplock_to_lease(u8 oplock)
  2060. {
  2061. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  2062. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  2063. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  2064. return SMB2_LEASE_READ_CACHING;
  2065. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  2066. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  2067. SMB2_LEASE_WRITE_CACHING;
  2068. return 0;
  2069. }
  2070. static char *
  2071. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  2072. {
  2073. struct create_lease *buf;
  2074. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  2075. if (!buf)
  2076. return NULL;
  2077. memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
  2078. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  2079. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  2080. (struct create_lease, lcontext));
  2081. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  2082. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  2083. (struct create_lease, Name));
  2084. buf->ccontext.NameLength = cpu_to_le16(4);
  2085. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  2086. buf->Name[0] = 'R';
  2087. buf->Name[1] = 'q';
  2088. buf->Name[2] = 'L';
  2089. buf->Name[3] = 's';
  2090. return (char *)buf;
  2091. }
  2092. static char *
  2093. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  2094. {
  2095. struct create_lease_v2 *buf;
  2096. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  2097. if (!buf)
  2098. return NULL;
  2099. memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
  2100. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  2101. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  2102. (struct create_lease_v2, lcontext));
  2103. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  2104. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  2105. (struct create_lease_v2, Name));
  2106. buf->ccontext.NameLength = cpu_to_le16(4);
  2107. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  2108. buf->Name[0] = 'R';
  2109. buf->Name[1] = 'q';
  2110. buf->Name[2] = 'L';
  2111. buf->Name[3] = 's';
  2112. return (char *)buf;
  2113. }
  2114. static __u8
  2115. smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
  2116. {
  2117. struct create_lease *lc = (struct create_lease *)buf;
  2118. *epoch = 0; /* not used */
  2119. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  2120. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  2121. return le32_to_cpu(lc->lcontext.LeaseState);
  2122. }
  2123. static __u8
  2124. smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
  2125. {
  2126. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  2127. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  2128. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  2129. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  2130. if (lease_key)
  2131. memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
  2132. return le32_to_cpu(lc->lcontext.LeaseState);
  2133. }
  2134. static unsigned int
  2135. smb2_wp_retry_size(struct inode *inode)
  2136. {
  2137. return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
  2138. SMB2_MAX_BUFFER_SIZE);
  2139. }
  2140. static bool
  2141. smb2_dir_needs_close(struct cifsFileInfo *cfile)
  2142. {
  2143. return !cfile->invalidHandle;
  2144. }
  2145. static void
  2146. fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
  2147. struct smb_rqst *old_rq)
  2148. {
  2149. struct smb2_sync_hdr *shdr =
  2150. (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
  2151. memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
  2152. tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
  2153. tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
  2154. tr_hdr->Flags = cpu_to_le16(0x01);
  2155. get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
  2156. memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
  2157. }
  2158. /* We can not use the normal sg_set_buf() as we will sometimes pass a
  2159. * stack object as buf.
  2160. */
  2161. static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
  2162. unsigned int buflen)
  2163. {
  2164. sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
  2165. }
  2166. /* Assumes the first rqst has a transform header as the first iov.
  2167. * I.e.
  2168. * rqst[0].rq_iov[0] is transform header
  2169. * rqst[0].rq_iov[1+] data to be encrypted/decrypted
  2170. * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
  2171. */
  2172. static struct scatterlist *
  2173. init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
  2174. {
  2175. unsigned int sg_len;
  2176. struct scatterlist *sg;
  2177. unsigned int i;
  2178. unsigned int j;
  2179. unsigned int idx = 0;
  2180. int skip;
  2181. sg_len = 1;
  2182. for (i = 0; i < num_rqst; i++)
  2183. sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
  2184. sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
  2185. if (!sg)
  2186. return NULL;
  2187. sg_init_table(sg, sg_len);
  2188. for (i = 0; i < num_rqst; i++) {
  2189. for (j = 0; j < rqst[i].rq_nvec; j++) {
  2190. /*
  2191. * The first rqst has a transform header where the
  2192. * first 20 bytes are not part of the encrypted blob
  2193. */
  2194. skip = (i == 0) && (j == 0) ? 20 : 0;
  2195. smb2_sg_set_buf(&sg[idx++],
  2196. rqst[i].rq_iov[j].iov_base + skip,
  2197. rqst[i].rq_iov[j].iov_len - skip);
  2198. }
  2199. for (j = 0; j < rqst[i].rq_npages; j++) {
  2200. unsigned int len, offset;
  2201. rqst_page_get_length(&rqst[i], j, &len, &offset);
  2202. sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
  2203. }
  2204. }
  2205. smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
  2206. return sg;
  2207. }
  2208. static int
  2209. smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
  2210. {
  2211. struct cifs_ses *ses;
  2212. u8 *ses_enc_key;
  2213. spin_lock(&cifs_tcp_ses_lock);
  2214. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  2215. if (ses->Suid != ses_id)
  2216. continue;
  2217. ses_enc_key = enc ? ses->smb3encryptionkey :
  2218. ses->smb3decryptionkey;
  2219. memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
  2220. spin_unlock(&cifs_tcp_ses_lock);
  2221. return 0;
  2222. }
  2223. spin_unlock(&cifs_tcp_ses_lock);
  2224. return 1;
  2225. }
  2226. /*
  2227. * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
  2228. * iov[0] - transform header (associate data),
  2229. * iov[1-N] - SMB2 header and pages - data to encrypt.
  2230. * On success return encrypted data in iov[1-N] and pages, leave iov[0]
  2231. * untouched.
  2232. */
  2233. static int
  2234. crypt_message(struct TCP_Server_Info *server, int num_rqst,
  2235. struct smb_rqst *rqst, int enc)
  2236. {
  2237. struct smb2_transform_hdr *tr_hdr =
  2238. (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
  2239. unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
  2240. int rc = 0;
  2241. struct scatterlist *sg;
  2242. u8 sign[SMB2_SIGNATURE_SIZE] = {};
  2243. u8 key[SMB3_SIGN_KEY_SIZE];
  2244. struct aead_request *req;
  2245. char *iv;
  2246. unsigned int iv_len;
  2247. DECLARE_CRYPTO_WAIT(wait);
  2248. struct crypto_aead *tfm;
  2249. unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
  2250. rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
  2251. if (rc) {
  2252. cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
  2253. enc ? "en" : "de");
  2254. return 0;
  2255. }
  2256. rc = smb3_crypto_aead_allocate(server);
  2257. if (rc) {
  2258. cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
  2259. return rc;
  2260. }
  2261. tfm = enc ? server->secmech.ccmaesencrypt :
  2262. server->secmech.ccmaesdecrypt;
  2263. rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
  2264. if (rc) {
  2265. cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
  2266. return rc;
  2267. }
  2268. rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
  2269. if (rc) {
  2270. cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
  2271. return rc;
  2272. }
  2273. req = aead_request_alloc(tfm, GFP_KERNEL);
  2274. if (!req) {
  2275. cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
  2276. return -ENOMEM;
  2277. }
  2278. if (!enc) {
  2279. memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
  2280. crypt_len += SMB2_SIGNATURE_SIZE;
  2281. }
  2282. sg = init_sg(num_rqst, rqst, sign);
  2283. if (!sg) {
  2284. cifs_dbg(VFS, "%s: Failed to init sg", __func__);
  2285. rc = -ENOMEM;
  2286. goto free_req;
  2287. }
  2288. iv_len = crypto_aead_ivsize(tfm);
  2289. iv = kzalloc(iv_len, GFP_KERNEL);
  2290. if (!iv) {
  2291. cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
  2292. rc = -ENOMEM;
  2293. goto free_sg;
  2294. }
  2295. iv[0] = 3;
  2296. memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
  2297. aead_request_set_crypt(req, sg, sg, crypt_len, iv);
  2298. aead_request_set_ad(req, assoc_data_len);
  2299. aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  2300. crypto_req_done, &wait);
  2301. rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
  2302. : crypto_aead_decrypt(req), &wait);
  2303. if (!rc && enc)
  2304. memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
  2305. kfree(iv);
  2306. free_sg:
  2307. kfree(sg);
  2308. free_req:
  2309. kfree(req);
  2310. return rc;
  2311. }
  2312. void
  2313. smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
  2314. {
  2315. int i, j;
  2316. for (i = 0; i < num_rqst; i++) {
  2317. if (rqst[i].rq_pages) {
  2318. for (j = rqst[i].rq_npages - 1; j >= 0; j--)
  2319. put_page(rqst[i].rq_pages[j]);
  2320. kfree(rqst[i].rq_pages);
  2321. }
  2322. }
  2323. }
  2324. /*
  2325. * This function will initialize new_rq and encrypt the content.
  2326. * The first entry, new_rq[0], only contains a single iov which contains
  2327. * a smb2_transform_hdr and is pre-allocated by the caller.
  2328. * This function then populates new_rq[1+] with the content from olq_rq[0+].
  2329. *
  2330. * The end result is an array of smb_rqst structures where the first structure
  2331. * only contains a single iov for the transform header which we then can pass
  2332. * to crypt_message().
  2333. *
  2334. * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
  2335. * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
  2336. */
  2337. static int
  2338. smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
  2339. struct smb_rqst *new_rq, struct smb_rqst *old_rq)
  2340. {
  2341. struct page **pages;
  2342. struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
  2343. unsigned int npages;
  2344. unsigned int orig_len = 0;
  2345. int i, j;
  2346. int rc = -ENOMEM;
  2347. for (i = 1; i < num_rqst; i++) {
  2348. npages = old_rq[i - 1].rq_npages;
  2349. pages = kmalloc_array(npages, sizeof(struct page *),
  2350. GFP_KERNEL);
  2351. if (!pages)
  2352. goto err_free;
  2353. new_rq[i].rq_pages = pages;
  2354. new_rq[i].rq_npages = npages;
  2355. new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
  2356. new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
  2357. new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
  2358. new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
  2359. new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
  2360. orig_len += smb_rqst_len(server, &old_rq[i - 1]);
  2361. for (j = 0; j < npages; j++) {
  2362. pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
  2363. if (!pages[j])
  2364. goto err_free;
  2365. }
  2366. /* copy pages form the old */
  2367. for (j = 0; j < npages; j++) {
  2368. char *dst, *src;
  2369. unsigned int offset, len;
  2370. rqst_page_get_length(&new_rq[i], j, &len, &offset);
  2371. dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
  2372. src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
  2373. memcpy(dst, src, len);
  2374. kunmap(new_rq[i].rq_pages[j]);
  2375. kunmap(old_rq[i - 1].rq_pages[j]);
  2376. }
  2377. }
  2378. /* fill the 1st iov with a transform header */
  2379. fill_transform_hdr(tr_hdr, orig_len, old_rq);
  2380. rc = crypt_message(server, num_rqst, new_rq, 1);
  2381. cifs_dbg(FYI, "encrypt message returned %d", rc);
  2382. if (rc)
  2383. goto err_free;
  2384. return rc;
  2385. err_free:
  2386. smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
  2387. return rc;
  2388. }
  2389. static int
  2390. smb3_is_transform_hdr(void *buf)
  2391. {
  2392. struct smb2_transform_hdr *trhdr = buf;
  2393. return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
  2394. }
  2395. static int
  2396. decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
  2397. unsigned int buf_data_size, struct page **pages,
  2398. unsigned int npages, unsigned int page_data_size)
  2399. {
  2400. struct kvec iov[2];
  2401. struct smb_rqst rqst = {NULL};
  2402. int rc;
  2403. iov[0].iov_base = buf;
  2404. iov[0].iov_len = sizeof(struct smb2_transform_hdr);
  2405. iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
  2406. iov[1].iov_len = buf_data_size;
  2407. rqst.rq_iov = iov;
  2408. rqst.rq_nvec = 2;
  2409. rqst.rq_pages = pages;
  2410. rqst.rq_npages = npages;
  2411. rqst.rq_pagesz = PAGE_SIZE;
  2412. rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
  2413. rc = crypt_message(server, 1, &rqst, 0);
  2414. cifs_dbg(FYI, "decrypt message returned %d\n", rc);
  2415. if (rc)
  2416. return rc;
  2417. memmove(buf, iov[1].iov_base, buf_data_size);
  2418. server->total_read = buf_data_size + page_data_size;
  2419. return rc;
  2420. }
  2421. static int
  2422. read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
  2423. unsigned int npages, unsigned int len)
  2424. {
  2425. int i;
  2426. int length;
  2427. for (i = 0; i < npages; i++) {
  2428. struct page *page = pages[i];
  2429. size_t n;
  2430. n = len;
  2431. if (len >= PAGE_SIZE) {
  2432. /* enough data to fill the page */
  2433. n = PAGE_SIZE;
  2434. len -= n;
  2435. } else {
  2436. zero_user(page, len, PAGE_SIZE - len);
  2437. len = 0;
  2438. }
  2439. length = cifs_read_page_from_socket(server, page, 0, n);
  2440. if (length < 0)
  2441. return length;
  2442. server->total_read += length;
  2443. }
  2444. return 0;
  2445. }
  2446. static int
  2447. init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
  2448. unsigned int cur_off, struct bio_vec **page_vec)
  2449. {
  2450. struct bio_vec *bvec;
  2451. int i;
  2452. bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
  2453. if (!bvec)
  2454. return -ENOMEM;
  2455. for (i = 0; i < npages; i++) {
  2456. bvec[i].bv_page = pages[i];
  2457. bvec[i].bv_offset = (i == 0) ? cur_off : 0;
  2458. bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
  2459. data_size -= bvec[i].bv_len;
  2460. }
  2461. if (data_size != 0) {
  2462. cifs_dbg(VFS, "%s: something went wrong\n", __func__);
  2463. kfree(bvec);
  2464. return -EIO;
  2465. }
  2466. *page_vec = bvec;
  2467. return 0;
  2468. }
  2469. static int
  2470. handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
  2471. char *buf, unsigned int buf_len, struct page **pages,
  2472. unsigned int npages, unsigned int page_data_size)
  2473. {
  2474. unsigned int data_offset;
  2475. unsigned int data_len;
  2476. unsigned int cur_off;
  2477. unsigned int cur_page_idx;
  2478. unsigned int pad_len;
  2479. struct cifs_readdata *rdata = mid->callback_data;
  2480. struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
  2481. struct bio_vec *bvec = NULL;
  2482. struct iov_iter iter;
  2483. struct kvec iov;
  2484. int length;
  2485. bool use_rdma_mr = false;
  2486. if (shdr->Command != SMB2_READ) {
  2487. cifs_dbg(VFS, "only big read responses are supported\n");
  2488. return -ENOTSUPP;
  2489. }
  2490. if (server->ops->is_session_expired &&
  2491. server->ops->is_session_expired(buf)) {
  2492. cifs_reconnect(server);
  2493. wake_up(&server->response_q);
  2494. return -1;
  2495. }
  2496. if (server->ops->is_status_pending &&
  2497. server->ops->is_status_pending(buf, server, 0))
  2498. return -1;
  2499. rdata->result = server->ops->map_error(buf, false);
  2500. if (rdata->result != 0) {
  2501. cifs_dbg(FYI, "%s: server returned error %d\n",
  2502. __func__, rdata->result);
  2503. dequeue_mid(mid, rdata->result);
  2504. return 0;
  2505. }
  2506. data_offset = server->ops->read_data_offset(buf);
  2507. #ifdef CONFIG_CIFS_SMB_DIRECT
  2508. use_rdma_mr = rdata->mr;
  2509. #endif
  2510. data_len = server->ops->read_data_length(buf, use_rdma_mr);
  2511. if (data_offset < server->vals->read_rsp_size) {
  2512. /*
  2513. * win2k8 sometimes sends an offset of 0 when the read
  2514. * is beyond the EOF. Treat it as if the data starts just after
  2515. * the header.
  2516. */
  2517. cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
  2518. __func__, data_offset);
  2519. data_offset = server->vals->read_rsp_size;
  2520. } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
  2521. /* data_offset is beyond the end of smallbuf */
  2522. cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
  2523. __func__, data_offset);
  2524. rdata->result = -EIO;
  2525. dequeue_mid(mid, rdata->result);
  2526. return 0;
  2527. }
  2528. pad_len = data_offset - server->vals->read_rsp_size;
  2529. if (buf_len <= data_offset) {
  2530. /* read response payload is in pages */
  2531. cur_page_idx = pad_len / PAGE_SIZE;
  2532. cur_off = pad_len % PAGE_SIZE;
  2533. if (cur_page_idx != 0) {
  2534. /* data offset is beyond the 1st page of response */
  2535. cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
  2536. __func__, data_offset);
  2537. rdata->result = -EIO;
  2538. dequeue_mid(mid, rdata->result);
  2539. return 0;
  2540. }
  2541. if (data_len > page_data_size - pad_len) {
  2542. /* data_len is corrupt -- discard frame */
  2543. rdata->result = -EIO;
  2544. dequeue_mid(mid, rdata->result);
  2545. return 0;
  2546. }
  2547. rdata->result = init_read_bvec(pages, npages, page_data_size,
  2548. cur_off, &bvec);
  2549. if (rdata->result != 0) {
  2550. dequeue_mid(mid, rdata->result);
  2551. return 0;
  2552. }
  2553. iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
  2554. } else if (buf_len >= data_offset + data_len) {
  2555. /* read response payload is in buf */
  2556. WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
  2557. iov.iov_base = buf + data_offset;
  2558. iov.iov_len = data_len;
  2559. iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
  2560. } else {
  2561. /* read response payload cannot be in both buf and pages */
  2562. WARN_ONCE(1, "buf can not contain only a part of read data");
  2563. rdata->result = -EIO;
  2564. dequeue_mid(mid, rdata->result);
  2565. return 0;
  2566. }
  2567. /* set up first iov for signature check */
  2568. rdata->iov[0].iov_base = buf;
  2569. rdata->iov[0].iov_len = 4;
  2570. rdata->iov[1].iov_base = buf + 4;
  2571. rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
  2572. cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
  2573. rdata->iov[0].iov_base, server->vals->read_rsp_size);
  2574. length = rdata->copy_into_pages(server, rdata, &iter);
  2575. kfree(bvec);
  2576. if (length < 0)
  2577. return length;
  2578. dequeue_mid(mid, false);
  2579. return length;
  2580. }
  2581. static int
  2582. receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
  2583. {
  2584. char *buf = server->smallbuf;
  2585. struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
  2586. unsigned int npages;
  2587. struct page **pages;
  2588. unsigned int len;
  2589. unsigned int buflen = server->pdu_size;
  2590. int rc;
  2591. int i = 0;
  2592. len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
  2593. sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
  2594. rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
  2595. if (rc < 0)
  2596. return rc;
  2597. server->total_read += rc;
  2598. len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
  2599. server->vals->read_rsp_size;
  2600. npages = DIV_ROUND_UP(len, PAGE_SIZE);
  2601. pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
  2602. if (!pages) {
  2603. rc = -ENOMEM;
  2604. goto discard_data;
  2605. }
  2606. for (; i < npages; i++) {
  2607. pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
  2608. if (!pages[i]) {
  2609. rc = -ENOMEM;
  2610. goto discard_data;
  2611. }
  2612. }
  2613. /* read read data into pages */
  2614. rc = read_data_into_pages(server, pages, npages, len);
  2615. if (rc)
  2616. goto free_pages;
  2617. rc = cifs_discard_remaining_data(server);
  2618. if (rc)
  2619. goto free_pages;
  2620. rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
  2621. pages, npages, len);
  2622. if (rc)
  2623. goto free_pages;
  2624. *mid = smb2_find_mid(server, buf);
  2625. if (*mid == NULL)
  2626. cifs_dbg(FYI, "mid not found\n");
  2627. else {
  2628. cifs_dbg(FYI, "mid found\n");
  2629. (*mid)->decrypted = true;
  2630. rc = handle_read_data(server, *mid, buf,
  2631. server->vals->read_rsp_size,
  2632. pages, npages, len);
  2633. }
  2634. free_pages:
  2635. for (i = i - 1; i >= 0; i--)
  2636. put_page(pages[i]);
  2637. kfree(pages);
  2638. return rc;
  2639. discard_data:
  2640. cifs_discard_remaining_data(server);
  2641. goto free_pages;
  2642. }
  2643. static int
  2644. receive_encrypted_standard(struct TCP_Server_Info *server,
  2645. struct mid_q_entry **mids, char **bufs,
  2646. int *num_mids)
  2647. {
  2648. int ret, length;
  2649. char *buf = server->smallbuf;
  2650. char *tmpbuf;
  2651. struct smb2_sync_hdr *shdr;
  2652. unsigned int pdu_length = server->pdu_size;
  2653. unsigned int buf_size;
  2654. struct mid_q_entry *mid_entry;
  2655. int next_is_large;
  2656. char *next_buffer = NULL;
  2657. *num_mids = 0;
  2658. /* switch to large buffer if too big for a small one */
  2659. if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
  2660. server->large_buf = true;
  2661. memcpy(server->bigbuf, buf, server->total_read);
  2662. buf = server->bigbuf;
  2663. }
  2664. /* now read the rest */
  2665. length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
  2666. pdu_length - HEADER_SIZE(server) + 1);
  2667. if (length < 0)
  2668. return length;
  2669. server->total_read += length;
  2670. buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
  2671. length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
  2672. if (length)
  2673. return length;
  2674. next_is_large = server->large_buf;
  2675. one_more:
  2676. shdr = (struct smb2_sync_hdr *)buf;
  2677. if (shdr->NextCommand) {
  2678. if (next_is_large) {
  2679. tmpbuf = server->bigbuf;
  2680. next_buffer = (char *)cifs_buf_get();
  2681. } else {
  2682. tmpbuf = server->smallbuf;
  2683. next_buffer = (char *)cifs_small_buf_get();
  2684. }
  2685. memcpy(next_buffer,
  2686. tmpbuf + le32_to_cpu(shdr->NextCommand),
  2687. pdu_length - le32_to_cpu(shdr->NextCommand));
  2688. }
  2689. mid_entry = smb2_find_mid(server, buf);
  2690. if (mid_entry == NULL)
  2691. cifs_dbg(FYI, "mid not found\n");
  2692. else {
  2693. cifs_dbg(FYI, "mid found\n");
  2694. mid_entry->decrypted = true;
  2695. mid_entry->resp_buf_size = server->pdu_size;
  2696. }
  2697. if (*num_mids >= MAX_COMPOUND) {
  2698. cifs_dbg(VFS, "too many PDUs in compound\n");
  2699. return -1;
  2700. }
  2701. bufs[*num_mids] = buf;
  2702. mids[(*num_mids)++] = mid_entry;
  2703. if (mid_entry && mid_entry->handle)
  2704. ret = mid_entry->handle(server, mid_entry);
  2705. else
  2706. ret = cifs_handle_standard(server, mid_entry);
  2707. if (ret == 0 && shdr->NextCommand) {
  2708. pdu_length -= le32_to_cpu(shdr->NextCommand);
  2709. server->large_buf = next_is_large;
  2710. if (next_is_large)
  2711. server->bigbuf = next_buffer;
  2712. else
  2713. server->smallbuf = next_buffer;
  2714. buf += le32_to_cpu(shdr->NextCommand);
  2715. goto one_more;
  2716. }
  2717. return ret;
  2718. }
  2719. static int
  2720. smb3_receive_transform(struct TCP_Server_Info *server,
  2721. struct mid_q_entry **mids, char **bufs, int *num_mids)
  2722. {
  2723. char *buf = server->smallbuf;
  2724. unsigned int pdu_length = server->pdu_size;
  2725. struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
  2726. unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
  2727. if (pdu_length < sizeof(struct smb2_transform_hdr) +
  2728. sizeof(struct smb2_sync_hdr)) {
  2729. cifs_dbg(VFS, "Transform message is too small (%u)\n",
  2730. pdu_length);
  2731. cifs_reconnect(server);
  2732. wake_up(&server->response_q);
  2733. return -ECONNABORTED;
  2734. }
  2735. if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
  2736. cifs_dbg(VFS, "Transform message is broken\n");
  2737. cifs_reconnect(server);
  2738. wake_up(&server->response_q);
  2739. return -ECONNABORTED;
  2740. }
  2741. /* TODO: add support for compounds containing READ. */
  2742. if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
  2743. return receive_encrypted_read(server, &mids[0]);
  2744. return receive_encrypted_standard(server, mids, bufs, num_mids);
  2745. }
  2746. int
  2747. smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
  2748. {
  2749. char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
  2750. return handle_read_data(server, mid, buf, server->pdu_size,
  2751. NULL, 0, 0);
  2752. }
  2753. static int
  2754. smb2_next_header(char *buf)
  2755. {
  2756. struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
  2757. struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
  2758. if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
  2759. return sizeof(struct smb2_transform_hdr) +
  2760. le32_to_cpu(t_hdr->OriginalMessageSize);
  2761. return le32_to_cpu(hdr->NextCommand);
  2762. }
  2763. struct smb_version_operations smb20_operations = {
  2764. .compare_fids = smb2_compare_fids,
  2765. .setup_request = smb2_setup_request,
  2766. .setup_async_request = smb2_setup_async_request,
  2767. .check_receive = smb2_check_receive,
  2768. .add_credits = smb2_add_credits,
  2769. .set_credits = smb2_set_credits,
  2770. .get_credits_field = smb2_get_credits_field,
  2771. .get_credits = smb2_get_credits,
  2772. .wait_mtu_credits = cifs_wait_mtu_credits,
  2773. .get_next_mid = smb2_get_next_mid,
  2774. .read_data_offset = smb2_read_data_offset,
  2775. .read_data_length = smb2_read_data_length,
  2776. .map_error = map_smb2_to_linux_error,
  2777. .find_mid = smb2_find_mid,
  2778. .check_message = smb2_check_message,
  2779. .dump_detail = smb2_dump_detail,
  2780. .clear_stats = smb2_clear_stats,
  2781. .print_stats = smb2_print_stats,
  2782. .is_oplock_break = smb2_is_valid_oplock_break,
  2783. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2784. .downgrade_oplock = smb2_downgrade_oplock,
  2785. .need_neg = smb2_need_neg,
  2786. .negotiate = smb2_negotiate,
  2787. .negotiate_wsize = smb2_negotiate_wsize,
  2788. .negotiate_rsize = smb2_negotiate_rsize,
  2789. .sess_setup = SMB2_sess_setup,
  2790. .logoff = SMB2_logoff,
  2791. .tree_connect = SMB2_tcon,
  2792. .tree_disconnect = SMB2_tdis,
  2793. .qfs_tcon = smb2_qfs_tcon,
  2794. .is_path_accessible = smb2_is_path_accessible,
  2795. .can_echo = smb2_can_echo,
  2796. .echo = SMB2_echo,
  2797. .query_path_info = smb2_query_path_info,
  2798. .get_srv_inum = smb2_get_srv_inum,
  2799. .query_file_info = smb2_query_file_info,
  2800. .set_path_size = smb2_set_path_size,
  2801. .set_file_size = smb2_set_file_size,
  2802. .set_file_info = smb2_set_file_info,
  2803. .set_compression = smb2_set_compression,
  2804. .mkdir = smb2_mkdir,
  2805. .mkdir_setinfo = smb2_mkdir_setinfo,
  2806. .rmdir = smb2_rmdir,
  2807. .unlink = smb2_unlink,
  2808. .rename = smb2_rename_path,
  2809. .create_hardlink = smb2_create_hardlink,
  2810. .query_symlink = smb2_query_symlink,
  2811. .query_mf_symlink = smb3_query_mf_symlink,
  2812. .create_mf_symlink = smb3_create_mf_symlink,
  2813. .open = smb2_open_file,
  2814. .set_fid = smb2_set_fid,
  2815. .close = smb2_close_file,
  2816. .flush = smb2_flush_file,
  2817. .async_readv = smb2_async_readv,
  2818. .async_writev = smb2_async_writev,
  2819. .sync_read = smb2_sync_read,
  2820. .sync_write = smb2_sync_write,
  2821. .query_dir_first = smb2_query_dir_first,
  2822. .query_dir_next = smb2_query_dir_next,
  2823. .close_dir = smb2_close_dir,
  2824. .calc_smb_size = smb2_calc_size,
  2825. .is_status_pending = smb2_is_status_pending,
  2826. .is_session_expired = smb2_is_session_expired,
  2827. .oplock_response = smb2_oplock_response,
  2828. .queryfs = smb2_queryfs,
  2829. .mand_lock = smb2_mand_lock,
  2830. .mand_unlock_range = smb2_unlock_range,
  2831. .push_mand_locks = smb2_push_mandatory_locks,
  2832. .get_lease_key = smb2_get_lease_key,
  2833. .set_lease_key = smb2_set_lease_key,
  2834. .new_lease_key = smb2_new_lease_key,
  2835. .calc_signature = smb2_calc_signature,
  2836. .is_read_op = smb2_is_read_op,
  2837. .set_oplock_level = smb2_set_oplock_level,
  2838. .create_lease_buf = smb2_create_lease_buf,
  2839. .parse_lease_buf = smb2_parse_lease_buf,
  2840. .copychunk_range = smb2_copychunk_range,
  2841. .wp_retry_size = smb2_wp_retry_size,
  2842. .dir_needs_close = smb2_dir_needs_close,
  2843. .get_dfs_refer = smb2_get_dfs_refer,
  2844. .select_sectype = smb2_select_sectype,
  2845. #ifdef CONFIG_CIFS_XATTR
  2846. .query_all_EAs = smb2_query_eas,
  2847. .set_EA = smb2_set_ea,
  2848. #endif /* CIFS_XATTR */
  2849. #ifdef CONFIG_CIFS_ACL
  2850. .get_acl = get_smb2_acl,
  2851. .get_acl_by_fid = get_smb2_acl_by_fid,
  2852. .set_acl = set_smb2_acl,
  2853. #endif /* CIFS_ACL */
  2854. .next_header = smb2_next_header,
  2855. };
  2856. struct smb_version_operations smb21_operations = {
  2857. .compare_fids = smb2_compare_fids,
  2858. .setup_request = smb2_setup_request,
  2859. .setup_async_request = smb2_setup_async_request,
  2860. .check_receive = smb2_check_receive,
  2861. .add_credits = smb2_add_credits,
  2862. .set_credits = smb2_set_credits,
  2863. .get_credits_field = smb2_get_credits_field,
  2864. .get_credits = smb2_get_credits,
  2865. .wait_mtu_credits = smb2_wait_mtu_credits,
  2866. .get_next_mid = smb2_get_next_mid,
  2867. .read_data_offset = smb2_read_data_offset,
  2868. .read_data_length = smb2_read_data_length,
  2869. .map_error = map_smb2_to_linux_error,
  2870. .find_mid = smb2_find_mid,
  2871. .check_message = smb2_check_message,
  2872. .dump_detail = smb2_dump_detail,
  2873. .clear_stats = smb2_clear_stats,
  2874. .print_stats = smb2_print_stats,
  2875. .is_oplock_break = smb2_is_valid_oplock_break,
  2876. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2877. .downgrade_oplock = smb2_downgrade_oplock,
  2878. .need_neg = smb2_need_neg,
  2879. .negotiate = smb2_negotiate,
  2880. .negotiate_wsize = smb2_negotiate_wsize,
  2881. .negotiate_rsize = smb2_negotiate_rsize,
  2882. .sess_setup = SMB2_sess_setup,
  2883. .logoff = SMB2_logoff,
  2884. .tree_connect = SMB2_tcon,
  2885. .tree_disconnect = SMB2_tdis,
  2886. .qfs_tcon = smb2_qfs_tcon,
  2887. .is_path_accessible = smb2_is_path_accessible,
  2888. .can_echo = smb2_can_echo,
  2889. .echo = SMB2_echo,
  2890. .query_path_info = smb2_query_path_info,
  2891. .get_srv_inum = smb2_get_srv_inum,
  2892. .query_file_info = smb2_query_file_info,
  2893. .set_path_size = smb2_set_path_size,
  2894. .set_file_size = smb2_set_file_size,
  2895. .set_file_info = smb2_set_file_info,
  2896. .set_compression = smb2_set_compression,
  2897. .mkdir = smb2_mkdir,
  2898. .mkdir_setinfo = smb2_mkdir_setinfo,
  2899. .rmdir = smb2_rmdir,
  2900. .unlink = smb2_unlink,
  2901. .rename = smb2_rename_path,
  2902. .create_hardlink = smb2_create_hardlink,
  2903. .query_symlink = smb2_query_symlink,
  2904. .query_mf_symlink = smb3_query_mf_symlink,
  2905. .create_mf_symlink = smb3_create_mf_symlink,
  2906. .open = smb2_open_file,
  2907. .set_fid = smb2_set_fid,
  2908. .close = smb2_close_file,
  2909. .flush = smb2_flush_file,
  2910. .async_readv = smb2_async_readv,
  2911. .async_writev = smb2_async_writev,
  2912. .sync_read = smb2_sync_read,
  2913. .sync_write = smb2_sync_write,
  2914. .query_dir_first = smb2_query_dir_first,
  2915. .query_dir_next = smb2_query_dir_next,
  2916. .close_dir = smb2_close_dir,
  2917. .calc_smb_size = smb2_calc_size,
  2918. .is_status_pending = smb2_is_status_pending,
  2919. .is_session_expired = smb2_is_session_expired,
  2920. .oplock_response = smb2_oplock_response,
  2921. .queryfs = smb2_queryfs,
  2922. .mand_lock = smb2_mand_lock,
  2923. .mand_unlock_range = smb2_unlock_range,
  2924. .push_mand_locks = smb2_push_mandatory_locks,
  2925. .get_lease_key = smb2_get_lease_key,
  2926. .set_lease_key = smb2_set_lease_key,
  2927. .new_lease_key = smb2_new_lease_key,
  2928. .calc_signature = smb2_calc_signature,
  2929. .is_read_op = smb21_is_read_op,
  2930. .set_oplock_level = smb21_set_oplock_level,
  2931. .create_lease_buf = smb2_create_lease_buf,
  2932. .parse_lease_buf = smb2_parse_lease_buf,
  2933. .copychunk_range = smb2_copychunk_range,
  2934. .wp_retry_size = smb2_wp_retry_size,
  2935. .dir_needs_close = smb2_dir_needs_close,
  2936. .enum_snapshots = smb3_enum_snapshots,
  2937. .get_dfs_refer = smb2_get_dfs_refer,
  2938. .select_sectype = smb2_select_sectype,
  2939. #ifdef CONFIG_CIFS_XATTR
  2940. .query_all_EAs = smb2_query_eas,
  2941. .set_EA = smb2_set_ea,
  2942. #endif /* CIFS_XATTR */
  2943. #ifdef CONFIG_CIFS_ACL
  2944. .get_acl = get_smb2_acl,
  2945. .get_acl_by_fid = get_smb2_acl_by_fid,
  2946. .set_acl = set_smb2_acl,
  2947. #endif /* CIFS_ACL */
  2948. .next_header = smb2_next_header,
  2949. };
  2950. struct smb_version_operations smb30_operations = {
  2951. .compare_fids = smb2_compare_fids,
  2952. .setup_request = smb2_setup_request,
  2953. .setup_async_request = smb2_setup_async_request,
  2954. .check_receive = smb2_check_receive,
  2955. .add_credits = smb2_add_credits,
  2956. .set_credits = smb2_set_credits,
  2957. .get_credits_field = smb2_get_credits_field,
  2958. .get_credits = smb2_get_credits,
  2959. .wait_mtu_credits = smb2_wait_mtu_credits,
  2960. .get_next_mid = smb2_get_next_mid,
  2961. .read_data_offset = smb2_read_data_offset,
  2962. .read_data_length = smb2_read_data_length,
  2963. .map_error = map_smb2_to_linux_error,
  2964. .find_mid = smb2_find_mid,
  2965. .check_message = smb2_check_message,
  2966. .dump_detail = smb2_dump_detail,
  2967. .clear_stats = smb2_clear_stats,
  2968. .print_stats = smb2_print_stats,
  2969. .dump_share_caps = smb2_dump_share_caps,
  2970. .is_oplock_break = smb2_is_valid_oplock_break,
  2971. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  2972. .downgrade_oplock = smb2_downgrade_oplock,
  2973. .need_neg = smb2_need_neg,
  2974. .negotiate = smb2_negotiate,
  2975. .negotiate_wsize = smb2_negotiate_wsize,
  2976. .negotiate_rsize = smb2_negotiate_rsize,
  2977. .sess_setup = SMB2_sess_setup,
  2978. .logoff = SMB2_logoff,
  2979. .tree_connect = SMB2_tcon,
  2980. .tree_disconnect = SMB2_tdis,
  2981. .qfs_tcon = smb3_qfs_tcon,
  2982. .is_path_accessible = smb2_is_path_accessible,
  2983. .can_echo = smb2_can_echo,
  2984. .echo = SMB2_echo,
  2985. .query_path_info = smb2_query_path_info,
  2986. .get_srv_inum = smb2_get_srv_inum,
  2987. .query_file_info = smb2_query_file_info,
  2988. .set_path_size = smb2_set_path_size,
  2989. .set_file_size = smb2_set_file_size,
  2990. .set_file_info = smb2_set_file_info,
  2991. .set_compression = smb2_set_compression,
  2992. .mkdir = smb2_mkdir,
  2993. .mkdir_setinfo = smb2_mkdir_setinfo,
  2994. .rmdir = smb2_rmdir,
  2995. .unlink = smb2_unlink,
  2996. .rename = smb2_rename_path,
  2997. .create_hardlink = smb2_create_hardlink,
  2998. .query_symlink = smb2_query_symlink,
  2999. .query_mf_symlink = smb3_query_mf_symlink,
  3000. .create_mf_symlink = smb3_create_mf_symlink,
  3001. .open = smb2_open_file,
  3002. .set_fid = smb2_set_fid,
  3003. .close = smb2_close_file,
  3004. .flush = smb2_flush_file,
  3005. .async_readv = smb2_async_readv,
  3006. .async_writev = smb2_async_writev,
  3007. .sync_read = smb2_sync_read,
  3008. .sync_write = smb2_sync_write,
  3009. .query_dir_first = smb2_query_dir_first,
  3010. .query_dir_next = smb2_query_dir_next,
  3011. .close_dir = smb2_close_dir,
  3012. .calc_smb_size = smb2_calc_size,
  3013. .is_status_pending = smb2_is_status_pending,
  3014. .is_session_expired = smb2_is_session_expired,
  3015. .oplock_response = smb2_oplock_response,
  3016. .queryfs = smb2_queryfs,
  3017. .mand_lock = smb2_mand_lock,
  3018. .mand_unlock_range = smb2_unlock_range,
  3019. .push_mand_locks = smb2_push_mandatory_locks,
  3020. .get_lease_key = smb2_get_lease_key,
  3021. .set_lease_key = smb2_set_lease_key,
  3022. .new_lease_key = smb2_new_lease_key,
  3023. .generate_signingkey = generate_smb30signingkey,
  3024. .calc_signature = smb3_calc_signature,
  3025. .set_integrity = smb3_set_integrity,
  3026. .is_read_op = smb21_is_read_op,
  3027. .set_oplock_level = smb3_set_oplock_level,
  3028. .create_lease_buf = smb3_create_lease_buf,
  3029. .parse_lease_buf = smb3_parse_lease_buf,
  3030. .copychunk_range = smb2_copychunk_range,
  3031. .duplicate_extents = smb2_duplicate_extents,
  3032. .validate_negotiate = smb3_validate_negotiate,
  3033. .wp_retry_size = smb2_wp_retry_size,
  3034. .dir_needs_close = smb2_dir_needs_close,
  3035. .fallocate = smb3_fallocate,
  3036. .enum_snapshots = smb3_enum_snapshots,
  3037. .init_transform_rq = smb3_init_transform_rq,
  3038. .is_transform_hdr = smb3_is_transform_hdr,
  3039. .receive_transform = smb3_receive_transform,
  3040. .get_dfs_refer = smb2_get_dfs_refer,
  3041. .select_sectype = smb2_select_sectype,
  3042. #ifdef CONFIG_CIFS_XATTR
  3043. .query_all_EAs = smb2_query_eas,
  3044. .set_EA = smb2_set_ea,
  3045. #endif /* CIFS_XATTR */
  3046. #ifdef CONFIG_CIFS_ACL
  3047. .get_acl = get_smb2_acl,
  3048. .get_acl_by_fid = get_smb2_acl_by_fid,
  3049. .set_acl = set_smb2_acl,
  3050. #endif /* CIFS_ACL */
  3051. .next_header = smb2_next_header,
  3052. };
  3053. struct smb_version_operations smb311_operations = {
  3054. .compare_fids = smb2_compare_fids,
  3055. .setup_request = smb2_setup_request,
  3056. .setup_async_request = smb2_setup_async_request,
  3057. .check_receive = smb2_check_receive,
  3058. .add_credits = smb2_add_credits,
  3059. .set_credits = smb2_set_credits,
  3060. .get_credits_field = smb2_get_credits_field,
  3061. .get_credits = smb2_get_credits,
  3062. .wait_mtu_credits = smb2_wait_mtu_credits,
  3063. .get_next_mid = smb2_get_next_mid,
  3064. .read_data_offset = smb2_read_data_offset,
  3065. .read_data_length = smb2_read_data_length,
  3066. .map_error = map_smb2_to_linux_error,
  3067. .find_mid = smb2_find_mid,
  3068. .check_message = smb2_check_message,
  3069. .dump_detail = smb2_dump_detail,
  3070. .clear_stats = smb2_clear_stats,
  3071. .print_stats = smb2_print_stats,
  3072. .dump_share_caps = smb2_dump_share_caps,
  3073. .is_oplock_break = smb2_is_valid_oplock_break,
  3074. .handle_cancelled_mid = smb2_handle_cancelled_mid,
  3075. .downgrade_oplock = smb2_downgrade_oplock,
  3076. .need_neg = smb2_need_neg,
  3077. .negotiate = smb2_negotiate,
  3078. .negotiate_wsize = smb2_negotiate_wsize,
  3079. .negotiate_rsize = smb2_negotiate_rsize,
  3080. .sess_setup = SMB2_sess_setup,
  3081. .logoff = SMB2_logoff,
  3082. .tree_connect = SMB2_tcon,
  3083. .tree_disconnect = SMB2_tdis,
  3084. .qfs_tcon = smb3_qfs_tcon,
  3085. .is_path_accessible = smb2_is_path_accessible,
  3086. .can_echo = smb2_can_echo,
  3087. .echo = SMB2_echo,
  3088. .query_path_info = smb2_query_path_info,
  3089. .get_srv_inum = smb2_get_srv_inum,
  3090. .query_file_info = smb2_query_file_info,
  3091. .set_path_size = smb2_set_path_size,
  3092. .set_file_size = smb2_set_file_size,
  3093. .set_file_info = smb2_set_file_info,
  3094. .set_compression = smb2_set_compression,
  3095. .mkdir = smb2_mkdir,
  3096. .mkdir_setinfo = smb2_mkdir_setinfo,
  3097. .posix_mkdir = smb311_posix_mkdir,
  3098. .rmdir = smb2_rmdir,
  3099. .unlink = smb2_unlink,
  3100. .rename = smb2_rename_path,
  3101. .create_hardlink = smb2_create_hardlink,
  3102. .query_symlink = smb2_query_symlink,
  3103. .query_mf_symlink = smb3_query_mf_symlink,
  3104. .create_mf_symlink = smb3_create_mf_symlink,
  3105. .open = smb2_open_file,
  3106. .set_fid = smb2_set_fid,
  3107. .close = smb2_close_file,
  3108. .flush = smb2_flush_file,
  3109. .async_readv = smb2_async_readv,
  3110. .async_writev = smb2_async_writev,
  3111. .sync_read = smb2_sync_read,
  3112. .sync_write = smb2_sync_write,
  3113. .query_dir_first = smb2_query_dir_first,
  3114. .query_dir_next = smb2_query_dir_next,
  3115. .close_dir = smb2_close_dir,
  3116. .calc_smb_size = smb2_calc_size,
  3117. .is_status_pending = smb2_is_status_pending,
  3118. .is_session_expired = smb2_is_session_expired,
  3119. .oplock_response = smb2_oplock_response,
  3120. .queryfs = smb311_queryfs,
  3121. .mand_lock = smb2_mand_lock,
  3122. .mand_unlock_range = smb2_unlock_range,
  3123. .push_mand_locks = smb2_push_mandatory_locks,
  3124. .get_lease_key = smb2_get_lease_key,
  3125. .set_lease_key = smb2_set_lease_key,
  3126. .new_lease_key = smb2_new_lease_key,
  3127. .generate_signingkey = generate_smb311signingkey,
  3128. .calc_signature = smb3_calc_signature,
  3129. .set_integrity = smb3_set_integrity,
  3130. .is_read_op = smb21_is_read_op,
  3131. .set_oplock_level = smb3_set_oplock_level,
  3132. .create_lease_buf = smb3_create_lease_buf,
  3133. .parse_lease_buf = smb3_parse_lease_buf,
  3134. .copychunk_range = smb2_copychunk_range,
  3135. .duplicate_extents = smb2_duplicate_extents,
  3136. /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
  3137. .wp_retry_size = smb2_wp_retry_size,
  3138. .dir_needs_close = smb2_dir_needs_close,
  3139. .fallocate = smb3_fallocate,
  3140. .enum_snapshots = smb3_enum_snapshots,
  3141. .init_transform_rq = smb3_init_transform_rq,
  3142. .is_transform_hdr = smb3_is_transform_hdr,
  3143. .receive_transform = smb3_receive_transform,
  3144. .get_dfs_refer = smb2_get_dfs_refer,
  3145. .select_sectype = smb2_select_sectype,
  3146. #ifdef CONFIG_CIFS_XATTR
  3147. .query_all_EAs = smb2_query_eas,
  3148. .set_EA = smb2_set_ea,
  3149. #endif /* CIFS_XATTR */
  3150. #ifdef CONFIG_CIFS_ACL
  3151. .get_acl = get_smb2_acl,
  3152. .get_acl_by_fid = get_smb2_acl_by_fid,
  3153. .set_acl = set_smb2_acl,
  3154. #endif /* CIFS_ACL */
  3155. .next_header = smb2_next_header,
  3156. };
  3157. struct smb_version_values smb20_values = {
  3158. .version_string = SMB20_VERSION_STRING,
  3159. .protocol_id = SMB20_PROT_ID,
  3160. .req_capabilities = 0, /* MBZ */
  3161. .large_lock_type = 0,
  3162. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3163. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3164. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3165. .header_size = sizeof(struct smb2_sync_hdr),
  3166. .header_preamble_size = 0,
  3167. .max_header_size = MAX_SMB2_HDR_SIZE,
  3168. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3169. .lock_cmd = SMB2_LOCK,
  3170. .cap_unix = 0,
  3171. .cap_nt_find = SMB2_NT_FIND,
  3172. .cap_large_files = SMB2_LARGE_FILES,
  3173. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3174. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3175. .create_lease_size = sizeof(struct create_lease),
  3176. };
  3177. struct smb_version_values smb21_values = {
  3178. .version_string = SMB21_VERSION_STRING,
  3179. .protocol_id = SMB21_PROT_ID,
  3180. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  3181. .large_lock_type = 0,
  3182. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3183. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3184. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3185. .header_size = sizeof(struct smb2_sync_hdr),
  3186. .header_preamble_size = 0,
  3187. .max_header_size = MAX_SMB2_HDR_SIZE,
  3188. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3189. .lock_cmd = SMB2_LOCK,
  3190. .cap_unix = 0,
  3191. .cap_nt_find = SMB2_NT_FIND,
  3192. .cap_large_files = SMB2_LARGE_FILES,
  3193. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3194. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3195. .create_lease_size = sizeof(struct create_lease),
  3196. };
  3197. struct smb_version_values smb3any_values = {
  3198. .version_string = SMB3ANY_VERSION_STRING,
  3199. .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
  3200. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
  3201. .large_lock_type = 0,
  3202. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3203. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3204. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3205. .header_size = sizeof(struct smb2_sync_hdr),
  3206. .header_preamble_size = 0,
  3207. .max_header_size = MAX_SMB2_HDR_SIZE,
  3208. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3209. .lock_cmd = SMB2_LOCK,
  3210. .cap_unix = 0,
  3211. .cap_nt_find = SMB2_NT_FIND,
  3212. .cap_large_files = SMB2_LARGE_FILES,
  3213. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3214. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3215. .create_lease_size = sizeof(struct create_lease_v2),
  3216. };
  3217. struct smb_version_values smbdefault_values = {
  3218. .version_string = SMBDEFAULT_VERSION_STRING,
  3219. .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
  3220. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
  3221. .large_lock_type = 0,
  3222. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3223. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3224. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3225. .header_size = sizeof(struct smb2_sync_hdr),
  3226. .header_preamble_size = 0,
  3227. .max_header_size = MAX_SMB2_HDR_SIZE,
  3228. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3229. .lock_cmd = SMB2_LOCK,
  3230. .cap_unix = 0,
  3231. .cap_nt_find = SMB2_NT_FIND,
  3232. .cap_large_files = SMB2_LARGE_FILES,
  3233. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3234. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3235. .create_lease_size = sizeof(struct create_lease_v2),
  3236. };
  3237. struct smb_version_values smb30_values = {
  3238. .version_string = SMB30_VERSION_STRING,
  3239. .protocol_id = SMB30_PROT_ID,
  3240. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
  3241. .large_lock_type = 0,
  3242. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3243. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3244. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3245. .header_size = sizeof(struct smb2_sync_hdr),
  3246. .header_preamble_size = 0,
  3247. .max_header_size = MAX_SMB2_HDR_SIZE,
  3248. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3249. .lock_cmd = SMB2_LOCK,
  3250. .cap_unix = 0,
  3251. .cap_nt_find = SMB2_NT_FIND,
  3252. .cap_large_files = SMB2_LARGE_FILES,
  3253. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3254. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3255. .create_lease_size = sizeof(struct create_lease_v2),
  3256. };
  3257. struct smb_version_values smb302_values = {
  3258. .version_string = SMB302_VERSION_STRING,
  3259. .protocol_id = SMB302_PROT_ID,
  3260. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
  3261. .large_lock_type = 0,
  3262. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3263. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3264. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3265. .header_size = sizeof(struct smb2_sync_hdr),
  3266. .header_preamble_size = 0,
  3267. .max_header_size = MAX_SMB2_HDR_SIZE,
  3268. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3269. .lock_cmd = SMB2_LOCK,
  3270. .cap_unix = 0,
  3271. .cap_nt_find = SMB2_NT_FIND,
  3272. .cap_large_files = SMB2_LARGE_FILES,
  3273. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3274. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3275. .create_lease_size = sizeof(struct create_lease_v2),
  3276. };
  3277. struct smb_version_values smb311_values = {
  3278. .version_string = SMB311_VERSION_STRING,
  3279. .protocol_id = SMB311_PROT_ID,
  3280. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
  3281. .large_lock_type = 0,
  3282. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  3283. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  3284. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  3285. .header_size = sizeof(struct smb2_sync_hdr),
  3286. .header_preamble_size = 0,
  3287. .max_header_size = MAX_SMB2_HDR_SIZE,
  3288. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  3289. .lock_cmd = SMB2_LOCK,
  3290. .cap_unix = 0,
  3291. .cap_nt_find = SMB2_NT_FIND,
  3292. .cap_large_files = SMB2_LARGE_FILES,
  3293. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3294. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  3295. .create_lease_size = sizeof(struct create_lease_v2),
  3296. };