super.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879
  1. /*
  2. * linux/fs/nfs/super.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * nfs superblock handling functions
  7. *
  8. * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
  9. * experimental NFS changes. Modularisation taken straight from SYS5 fs.
  10. *
  11. * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
  12. * J.S.Peatfield@damtp.cam.ac.uk
  13. *
  14. * Split from inode.c by David Howells <dhowells@redhat.com>
  15. *
  16. * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
  17. * particular server are held in the same superblock
  18. * - NFS superblocks can have several effective roots to the dentry tree
  19. * - directory type roots are spliced into the tree when a path from one root reaches the root
  20. * of another (see nfs_lookup())
  21. */
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/time.h>
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/string.h>
  28. #include <linux/stat.h>
  29. #include <linux/errno.h>
  30. #include <linux/unistd.h>
  31. #include <linux/sunrpc/clnt.h>
  32. #include <linux/sunrpc/addr.h>
  33. #include <linux/sunrpc/stats.h>
  34. #include <linux/sunrpc/metrics.h>
  35. #include <linux/sunrpc/xprtsock.h>
  36. #include <linux/sunrpc/xprtrdma.h>
  37. #include <linux/nfs_fs.h>
  38. #include <linux/nfs_mount.h>
  39. #include <linux/nfs4_mount.h>
  40. #include <linux/lockd/bind.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/mount.h>
  43. #include <linux/namei.h>
  44. #include <linux/nfs_idmap.h>
  45. #include <linux/vfs.h>
  46. #include <linux/inet.h>
  47. #include <linux/in6.h>
  48. #include <linux/slab.h>
  49. #include <net/ipv6.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/nfs_xdr.h>
  52. #include <linux/magic.h>
  53. #include <linux/parser.h>
  54. #include <linux/nsproxy.h>
  55. #include <linux/rcupdate.h>
  56. #include <asm/uaccess.h>
  57. #include "nfs4_fs.h"
  58. #include "callback.h"
  59. #include "delegation.h"
  60. #include "iostat.h"
  61. #include "internal.h"
  62. #include "fscache.h"
  63. #include "nfs4session.h"
  64. #include "pnfs.h"
  65. #include "nfs.h"
  66. #define NFSDBG_FACILITY NFSDBG_VFS
  67. #define NFS_TEXT_DATA 1
  68. #if IS_ENABLED(CONFIG_NFS_V3)
  69. #define NFS_DEFAULT_VERSION 3
  70. #else
  71. #define NFS_DEFAULT_VERSION 2
  72. #endif
  73. enum {
  74. /* Mount options that take no arguments */
  75. Opt_soft, Opt_hard,
  76. Opt_posix, Opt_noposix,
  77. Opt_cto, Opt_nocto,
  78. Opt_ac, Opt_noac,
  79. Opt_lock, Opt_nolock,
  80. Opt_udp, Opt_tcp, Opt_rdma,
  81. Opt_acl, Opt_noacl,
  82. Opt_rdirplus, Opt_nordirplus,
  83. Opt_sharecache, Opt_nosharecache,
  84. Opt_resvport, Opt_noresvport,
  85. Opt_fscache, Opt_nofscache,
  86. Opt_migration, Opt_nomigration,
  87. /* Mount options that take integer arguments */
  88. Opt_port,
  89. Opt_rsize, Opt_wsize, Opt_bsize,
  90. Opt_timeo, Opt_retrans,
  91. Opt_acregmin, Opt_acregmax,
  92. Opt_acdirmin, Opt_acdirmax,
  93. Opt_actimeo,
  94. Opt_namelen,
  95. Opt_mountport,
  96. Opt_mountvers,
  97. Opt_minorversion,
  98. /* Mount options that take string arguments */
  99. Opt_nfsvers,
  100. Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
  101. Opt_addr, Opt_mountaddr, Opt_clientaddr,
  102. Opt_lookupcache,
  103. Opt_fscache_uniq,
  104. Opt_local_lock,
  105. /* Special mount options */
  106. Opt_userspace, Opt_deprecated, Opt_sloppy,
  107. Opt_err
  108. };
  109. static const match_table_t nfs_mount_option_tokens = {
  110. { Opt_userspace, "bg" },
  111. { Opt_userspace, "fg" },
  112. { Opt_userspace, "retry=%s" },
  113. { Opt_sloppy, "sloppy" },
  114. { Opt_soft, "soft" },
  115. { Opt_hard, "hard" },
  116. { Opt_deprecated, "intr" },
  117. { Opt_deprecated, "nointr" },
  118. { Opt_posix, "posix" },
  119. { Opt_noposix, "noposix" },
  120. { Opt_cto, "cto" },
  121. { Opt_nocto, "nocto" },
  122. { Opt_ac, "ac" },
  123. { Opt_noac, "noac" },
  124. { Opt_lock, "lock" },
  125. { Opt_nolock, "nolock" },
  126. { Opt_udp, "udp" },
  127. { Opt_tcp, "tcp" },
  128. { Opt_rdma, "rdma" },
  129. { Opt_acl, "acl" },
  130. { Opt_noacl, "noacl" },
  131. { Opt_rdirplus, "rdirplus" },
  132. { Opt_nordirplus, "nordirplus" },
  133. { Opt_sharecache, "sharecache" },
  134. { Opt_nosharecache, "nosharecache" },
  135. { Opt_resvport, "resvport" },
  136. { Opt_noresvport, "noresvport" },
  137. { Opt_fscache, "fsc" },
  138. { Opt_nofscache, "nofsc" },
  139. { Opt_migration, "migration" },
  140. { Opt_nomigration, "nomigration" },
  141. { Opt_port, "port=%s" },
  142. { Opt_rsize, "rsize=%s" },
  143. { Opt_wsize, "wsize=%s" },
  144. { Opt_bsize, "bsize=%s" },
  145. { Opt_timeo, "timeo=%s" },
  146. { Opt_retrans, "retrans=%s" },
  147. { Opt_acregmin, "acregmin=%s" },
  148. { Opt_acregmax, "acregmax=%s" },
  149. { Opt_acdirmin, "acdirmin=%s" },
  150. { Opt_acdirmax, "acdirmax=%s" },
  151. { Opt_actimeo, "actimeo=%s" },
  152. { Opt_namelen, "namlen=%s" },
  153. { Opt_mountport, "mountport=%s" },
  154. { Opt_mountvers, "mountvers=%s" },
  155. { Opt_minorversion, "minorversion=%s" },
  156. { Opt_nfsvers, "nfsvers=%s" },
  157. { Opt_nfsvers, "vers=%s" },
  158. { Opt_sec, "sec=%s" },
  159. { Opt_proto, "proto=%s" },
  160. { Opt_mountproto, "mountproto=%s" },
  161. { Opt_addr, "addr=%s" },
  162. { Opt_clientaddr, "clientaddr=%s" },
  163. { Opt_mounthost, "mounthost=%s" },
  164. { Opt_mountaddr, "mountaddr=%s" },
  165. { Opt_lookupcache, "lookupcache=%s" },
  166. { Opt_fscache_uniq, "fsc=%s" },
  167. { Opt_local_lock, "local_lock=%s" },
  168. /* The following needs to be listed after all other options */
  169. { Opt_nfsvers, "v%s" },
  170. { Opt_err, NULL }
  171. };
  172. enum {
  173. Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
  174. Opt_xprt_err
  175. };
  176. static const match_table_t nfs_xprt_protocol_tokens = {
  177. { Opt_xprt_udp, "udp" },
  178. { Opt_xprt_udp6, "udp6" },
  179. { Opt_xprt_tcp, "tcp" },
  180. { Opt_xprt_tcp6, "tcp6" },
  181. { Opt_xprt_rdma, "rdma" },
  182. { Opt_xprt_err, NULL }
  183. };
  184. enum {
  185. Opt_sec_none, Opt_sec_sys,
  186. Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
  187. Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
  188. Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
  189. Opt_sec_err
  190. };
  191. static const match_table_t nfs_secflavor_tokens = {
  192. { Opt_sec_none, "none" },
  193. { Opt_sec_none, "null" },
  194. { Opt_sec_sys, "sys" },
  195. { Opt_sec_krb5, "krb5" },
  196. { Opt_sec_krb5i, "krb5i" },
  197. { Opt_sec_krb5p, "krb5p" },
  198. { Opt_sec_lkey, "lkey" },
  199. { Opt_sec_lkeyi, "lkeyi" },
  200. { Opt_sec_lkeyp, "lkeyp" },
  201. { Opt_sec_spkm, "spkm3" },
  202. { Opt_sec_spkmi, "spkm3i" },
  203. { Opt_sec_spkmp, "spkm3p" },
  204. { Opt_sec_err, NULL }
  205. };
  206. enum {
  207. Opt_lookupcache_all, Opt_lookupcache_positive,
  208. Opt_lookupcache_none,
  209. Opt_lookupcache_err
  210. };
  211. static match_table_t nfs_lookupcache_tokens = {
  212. { Opt_lookupcache_all, "all" },
  213. { Opt_lookupcache_positive, "pos" },
  214. { Opt_lookupcache_positive, "positive" },
  215. { Opt_lookupcache_none, "none" },
  216. { Opt_lookupcache_err, NULL }
  217. };
  218. enum {
  219. Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
  220. Opt_local_lock_none,
  221. Opt_local_lock_err
  222. };
  223. static match_table_t nfs_local_lock_tokens = {
  224. { Opt_local_lock_all, "all" },
  225. { Opt_local_lock_flock, "flock" },
  226. { Opt_local_lock_posix, "posix" },
  227. { Opt_local_lock_none, "none" },
  228. { Opt_local_lock_err, NULL }
  229. };
  230. enum {
  231. Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
  232. Opt_vers_4_1, Opt_vers_4_2,
  233. Opt_vers_err
  234. };
  235. static match_table_t nfs_vers_tokens = {
  236. { Opt_vers_2, "2" },
  237. { Opt_vers_3, "3" },
  238. { Opt_vers_4, "4" },
  239. { Opt_vers_4_0, "4.0" },
  240. { Opt_vers_4_1, "4.1" },
  241. { Opt_vers_4_2, "4.2" },
  242. { Opt_vers_err, NULL }
  243. };
  244. static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
  245. int flags, const char *dev_name, void *raw_data);
  246. struct file_system_type nfs_fs_type = {
  247. .owner = THIS_MODULE,
  248. .name = "nfs",
  249. .mount = nfs_fs_mount,
  250. .kill_sb = nfs_kill_super,
  251. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
  252. };
  253. MODULE_ALIAS_FS("nfs");
  254. EXPORT_SYMBOL_GPL(nfs_fs_type);
  255. struct file_system_type nfs_xdev_fs_type = {
  256. .owner = THIS_MODULE,
  257. .name = "nfs",
  258. .mount = nfs_xdev_mount,
  259. .kill_sb = nfs_kill_super,
  260. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
  261. };
  262. const struct super_operations nfs_sops = {
  263. .alloc_inode = nfs_alloc_inode,
  264. .destroy_inode = nfs_destroy_inode,
  265. .write_inode = nfs_write_inode,
  266. .drop_inode = nfs_drop_inode,
  267. .statfs = nfs_statfs,
  268. .evict_inode = nfs_evict_inode,
  269. .umount_begin = nfs_umount_begin,
  270. .show_options = nfs_show_options,
  271. .show_devname = nfs_show_devname,
  272. .show_path = nfs_show_path,
  273. .show_stats = nfs_show_stats,
  274. .remount_fs = nfs_remount,
  275. };
  276. EXPORT_SYMBOL_GPL(nfs_sops);
  277. #if IS_ENABLED(CONFIG_NFS_V4)
  278. static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
  279. static int nfs4_validate_mount_data(void *options,
  280. struct nfs_parsed_mount_data *args, const char *dev_name);
  281. struct file_system_type nfs4_fs_type = {
  282. .owner = THIS_MODULE,
  283. .name = "nfs4",
  284. .mount = nfs_fs_mount,
  285. .kill_sb = nfs_kill_super,
  286. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
  287. };
  288. MODULE_ALIAS_FS("nfs4");
  289. MODULE_ALIAS("nfs4");
  290. EXPORT_SYMBOL_GPL(nfs4_fs_type);
  291. static int __init register_nfs4_fs(void)
  292. {
  293. return register_filesystem(&nfs4_fs_type);
  294. }
  295. static void unregister_nfs4_fs(void)
  296. {
  297. unregister_filesystem(&nfs4_fs_type);
  298. }
  299. #else
  300. static int __init register_nfs4_fs(void)
  301. {
  302. return 0;
  303. }
  304. static void unregister_nfs4_fs(void)
  305. {
  306. }
  307. #endif
  308. static struct shrinker acl_shrinker = {
  309. .count_objects = nfs_access_cache_count,
  310. .scan_objects = nfs_access_cache_scan,
  311. .seeks = DEFAULT_SEEKS,
  312. };
  313. /*
  314. * Register the NFS filesystems
  315. */
  316. int __init register_nfs_fs(void)
  317. {
  318. int ret;
  319. ret = register_filesystem(&nfs_fs_type);
  320. if (ret < 0)
  321. goto error_0;
  322. ret = register_nfs4_fs();
  323. if (ret < 0)
  324. goto error_1;
  325. ret = nfs_register_sysctl();
  326. if (ret < 0)
  327. goto error_2;
  328. register_shrinker(&acl_shrinker);
  329. return 0;
  330. error_2:
  331. unregister_nfs4_fs();
  332. error_1:
  333. unregister_filesystem(&nfs_fs_type);
  334. error_0:
  335. return ret;
  336. }
  337. /*
  338. * Unregister the NFS filesystems
  339. */
  340. void __exit unregister_nfs_fs(void)
  341. {
  342. unregister_shrinker(&acl_shrinker);
  343. nfs_unregister_sysctl();
  344. unregister_nfs4_fs();
  345. unregister_filesystem(&nfs_fs_type);
  346. }
  347. bool nfs_sb_active(struct super_block *sb)
  348. {
  349. struct nfs_server *server = NFS_SB(sb);
  350. if (!atomic_inc_not_zero(&sb->s_active))
  351. return false;
  352. if (atomic_inc_return(&server->active) != 1)
  353. atomic_dec(&sb->s_active);
  354. return true;
  355. }
  356. EXPORT_SYMBOL_GPL(nfs_sb_active);
  357. void nfs_sb_deactive(struct super_block *sb)
  358. {
  359. struct nfs_server *server = NFS_SB(sb);
  360. if (atomic_dec_and_test(&server->active))
  361. deactivate_super(sb);
  362. }
  363. EXPORT_SYMBOL_GPL(nfs_sb_deactive);
  364. /*
  365. * Deliver file system statistics to userspace
  366. */
  367. int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  368. {
  369. struct nfs_server *server = NFS_SB(dentry->d_sb);
  370. unsigned char blockbits;
  371. unsigned long blockres;
  372. struct nfs_fh *fh = NFS_FH(dentry->d_inode);
  373. struct nfs_fsstat res;
  374. int error = -ENOMEM;
  375. res.fattr = nfs_alloc_fattr();
  376. if (res.fattr == NULL)
  377. goto out_err;
  378. error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
  379. if (unlikely(error == -ESTALE)) {
  380. struct dentry *pd_dentry;
  381. pd_dentry = dget_parent(dentry);
  382. if (pd_dentry != NULL) {
  383. nfs_zap_caches(pd_dentry->d_inode);
  384. dput(pd_dentry);
  385. }
  386. }
  387. nfs_free_fattr(res.fattr);
  388. if (error < 0)
  389. goto out_err;
  390. buf->f_type = NFS_SUPER_MAGIC;
  391. /*
  392. * Current versions of glibc do not correctly handle the
  393. * case where f_frsize != f_bsize. Eventually we want to
  394. * report the value of wtmult in this field.
  395. */
  396. buf->f_frsize = dentry->d_sb->s_blocksize;
  397. /*
  398. * On most *nix systems, f_blocks, f_bfree, and f_bavail
  399. * are reported in units of f_frsize. Linux hasn't had
  400. * an f_frsize field in its statfs struct until recently,
  401. * thus historically Linux's sys_statfs reports these
  402. * fields in units of f_bsize.
  403. */
  404. buf->f_bsize = dentry->d_sb->s_blocksize;
  405. blockbits = dentry->d_sb->s_blocksize_bits;
  406. blockres = (1 << blockbits) - 1;
  407. buf->f_blocks = (res.tbytes + blockres) >> blockbits;
  408. buf->f_bfree = (res.fbytes + blockres) >> blockbits;
  409. buf->f_bavail = (res.abytes + blockres) >> blockbits;
  410. buf->f_files = res.tfiles;
  411. buf->f_ffree = res.afiles;
  412. buf->f_namelen = server->namelen;
  413. return 0;
  414. out_err:
  415. dprintk("%s: statfs error = %d\n", __func__, -error);
  416. return error;
  417. }
  418. EXPORT_SYMBOL_GPL(nfs_statfs);
  419. /*
  420. * Map the security flavour number to a name
  421. */
  422. static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
  423. {
  424. static const struct {
  425. rpc_authflavor_t flavour;
  426. const char *str;
  427. } sec_flavours[NFS_AUTH_INFO_MAX_FLAVORS] = {
  428. /* update NFS_AUTH_INFO_MAX_FLAVORS when this list changes! */
  429. { RPC_AUTH_NULL, "null" },
  430. { RPC_AUTH_UNIX, "sys" },
  431. { RPC_AUTH_GSS_KRB5, "krb5" },
  432. { RPC_AUTH_GSS_KRB5I, "krb5i" },
  433. { RPC_AUTH_GSS_KRB5P, "krb5p" },
  434. { RPC_AUTH_GSS_LKEY, "lkey" },
  435. { RPC_AUTH_GSS_LKEYI, "lkeyi" },
  436. { RPC_AUTH_GSS_LKEYP, "lkeyp" },
  437. { RPC_AUTH_GSS_SPKM, "spkm" },
  438. { RPC_AUTH_GSS_SPKMI, "spkmi" },
  439. { RPC_AUTH_GSS_SPKMP, "spkmp" },
  440. { UINT_MAX, "unknown" }
  441. };
  442. int i;
  443. for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
  444. if (sec_flavours[i].flavour == flavour)
  445. break;
  446. }
  447. return sec_flavours[i].str;
  448. }
  449. static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
  450. int showdefaults)
  451. {
  452. struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
  453. seq_printf(m, ",mountproto=");
  454. switch (sap->sa_family) {
  455. case AF_INET:
  456. switch (nfss->mountd_protocol) {
  457. case IPPROTO_UDP:
  458. seq_printf(m, RPCBIND_NETID_UDP);
  459. break;
  460. case IPPROTO_TCP:
  461. seq_printf(m, RPCBIND_NETID_TCP);
  462. break;
  463. default:
  464. if (showdefaults)
  465. seq_printf(m, "auto");
  466. }
  467. break;
  468. case AF_INET6:
  469. switch (nfss->mountd_protocol) {
  470. case IPPROTO_UDP:
  471. seq_printf(m, RPCBIND_NETID_UDP6);
  472. break;
  473. case IPPROTO_TCP:
  474. seq_printf(m, RPCBIND_NETID_TCP6);
  475. break;
  476. default:
  477. if (showdefaults)
  478. seq_printf(m, "auto");
  479. }
  480. break;
  481. default:
  482. if (showdefaults)
  483. seq_printf(m, "auto");
  484. }
  485. }
  486. static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
  487. int showdefaults)
  488. {
  489. struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
  490. if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
  491. return;
  492. switch (sap->sa_family) {
  493. case AF_INET: {
  494. struct sockaddr_in *sin = (struct sockaddr_in *)sap;
  495. seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
  496. break;
  497. }
  498. case AF_INET6: {
  499. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
  500. seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
  501. break;
  502. }
  503. default:
  504. if (showdefaults)
  505. seq_printf(m, ",mountaddr=unspecified");
  506. }
  507. if (nfss->mountd_version || showdefaults)
  508. seq_printf(m, ",mountvers=%u", nfss->mountd_version);
  509. if ((nfss->mountd_port &&
  510. nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
  511. showdefaults)
  512. seq_printf(m, ",mountport=%u", nfss->mountd_port);
  513. nfs_show_mountd_netid(m, nfss, showdefaults);
  514. }
  515. #if IS_ENABLED(CONFIG_NFS_V4)
  516. static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
  517. int showdefaults)
  518. {
  519. struct nfs_client *clp = nfss->nfs_client;
  520. seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
  521. }
  522. #else
  523. static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
  524. int showdefaults)
  525. {
  526. }
  527. #endif
  528. static void nfs_show_nfs_version(struct seq_file *m,
  529. unsigned int version,
  530. unsigned int minorversion)
  531. {
  532. seq_printf(m, ",vers=%u", version);
  533. if (version == 4)
  534. seq_printf(m, ".%u", minorversion);
  535. }
  536. /*
  537. * Describe the mount options in force on this server representation
  538. */
  539. static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
  540. int showdefaults)
  541. {
  542. static const struct proc_nfs_info {
  543. int flag;
  544. const char *str;
  545. const char *nostr;
  546. } nfs_info[] = {
  547. { NFS_MOUNT_SOFT, ",soft", ",hard" },
  548. { NFS_MOUNT_POSIX, ",posix", "" },
  549. { NFS_MOUNT_NOCTO, ",nocto", "" },
  550. { NFS_MOUNT_NOAC, ",noac", "" },
  551. { NFS_MOUNT_NONLM, ",nolock", "" },
  552. { NFS_MOUNT_NOACL, ",noacl", "" },
  553. { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
  554. { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
  555. { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
  556. { 0, NULL, NULL }
  557. };
  558. const struct proc_nfs_info *nfs_infop;
  559. struct nfs_client *clp = nfss->nfs_client;
  560. u32 version = clp->rpc_ops->version;
  561. int local_flock, local_fcntl;
  562. nfs_show_nfs_version(m, version, clp->cl_minorversion);
  563. seq_printf(m, ",rsize=%u", nfss->rsize);
  564. seq_printf(m, ",wsize=%u", nfss->wsize);
  565. if (nfss->bsize != 0)
  566. seq_printf(m, ",bsize=%u", nfss->bsize);
  567. seq_printf(m, ",namlen=%u", nfss->namelen);
  568. if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
  569. seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
  570. if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
  571. seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
  572. if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
  573. seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
  574. if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
  575. seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
  576. for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
  577. if (nfss->flags & nfs_infop->flag)
  578. seq_puts(m, nfs_infop->str);
  579. else
  580. seq_puts(m, nfs_infop->nostr);
  581. }
  582. rcu_read_lock();
  583. seq_printf(m, ",proto=%s",
  584. rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
  585. rcu_read_unlock();
  586. if (version == 4) {
  587. if (nfss->port != NFS_PORT)
  588. seq_printf(m, ",port=%u", nfss->port);
  589. } else
  590. if (nfss->port)
  591. seq_printf(m, ",port=%u", nfss->port);
  592. seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
  593. seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
  594. seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
  595. if (version != 4)
  596. nfs_show_mountd_options(m, nfss, showdefaults);
  597. else
  598. nfs_show_nfsv4_options(m, nfss, showdefaults);
  599. if (nfss->options & NFS_OPTION_FSCACHE)
  600. seq_printf(m, ",fsc");
  601. if (nfss->options & NFS_OPTION_MIGRATION)
  602. seq_printf(m, ",migration");
  603. if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
  604. if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
  605. seq_printf(m, ",lookupcache=none");
  606. else
  607. seq_printf(m, ",lookupcache=pos");
  608. }
  609. local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
  610. local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
  611. if (!local_flock && !local_fcntl)
  612. seq_printf(m, ",local_lock=none");
  613. else if (local_flock && local_fcntl)
  614. seq_printf(m, ",local_lock=all");
  615. else if (local_flock)
  616. seq_printf(m, ",local_lock=flock");
  617. else
  618. seq_printf(m, ",local_lock=posix");
  619. }
  620. /*
  621. * Describe the mount options on this VFS mountpoint
  622. */
  623. int nfs_show_options(struct seq_file *m, struct dentry *root)
  624. {
  625. struct nfs_server *nfss = NFS_SB(root->d_sb);
  626. nfs_show_mount_options(m, nfss, 0);
  627. rcu_read_lock();
  628. seq_printf(m, ",addr=%s",
  629. rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
  630. RPC_DISPLAY_ADDR));
  631. rcu_read_unlock();
  632. return 0;
  633. }
  634. EXPORT_SYMBOL_GPL(nfs_show_options);
  635. #if IS_ENABLED(CONFIG_NFS_V4)
  636. #ifdef CONFIG_NFS_V4_1
  637. static void show_sessions(struct seq_file *m, struct nfs_server *server)
  638. {
  639. if (nfs4_has_session(server->nfs_client))
  640. seq_printf(m, ",sessions");
  641. }
  642. #else
  643. static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
  644. #endif
  645. #endif
  646. #ifdef CONFIG_NFS_V4_1
  647. static void show_pnfs(struct seq_file *m, struct nfs_server *server)
  648. {
  649. seq_printf(m, ",pnfs=");
  650. if (server->pnfs_curr_ld)
  651. seq_printf(m, "%s", server->pnfs_curr_ld->name);
  652. else
  653. seq_printf(m, "not configured");
  654. }
  655. static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
  656. {
  657. if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
  658. struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
  659. seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
  660. "date='%llu,%u'",
  661. impl_id->name, impl_id->domain,
  662. impl_id->date.seconds, impl_id->date.nseconds);
  663. }
  664. }
  665. #else
  666. #if IS_ENABLED(CONFIG_NFS_V4)
  667. static void show_pnfs(struct seq_file *m, struct nfs_server *server)
  668. {
  669. }
  670. #endif
  671. static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
  672. {
  673. }
  674. #endif
  675. int nfs_show_devname(struct seq_file *m, struct dentry *root)
  676. {
  677. char *page = (char *) __get_free_page(GFP_KERNEL);
  678. char *devname, *dummy;
  679. int err = 0;
  680. if (!page)
  681. return -ENOMEM;
  682. devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
  683. if (IS_ERR(devname))
  684. err = PTR_ERR(devname);
  685. else
  686. seq_escape(m, devname, " \t\n\\");
  687. free_page((unsigned long)page);
  688. return err;
  689. }
  690. EXPORT_SYMBOL_GPL(nfs_show_devname);
  691. int nfs_show_path(struct seq_file *m, struct dentry *dentry)
  692. {
  693. seq_puts(m, "/");
  694. return 0;
  695. }
  696. EXPORT_SYMBOL_GPL(nfs_show_path);
  697. /*
  698. * Present statistical information for this VFS mountpoint
  699. */
  700. int nfs_show_stats(struct seq_file *m, struct dentry *root)
  701. {
  702. int i, cpu;
  703. struct nfs_server *nfss = NFS_SB(root->d_sb);
  704. struct rpc_auth *auth = nfss->client->cl_auth;
  705. struct nfs_iostats totals = { };
  706. seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
  707. /*
  708. * Display all mount option settings
  709. */
  710. seq_printf(m, "\n\topts:\t");
  711. seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
  712. seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
  713. seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
  714. seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
  715. nfs_show_mount_options(m, nfss, 1);
  716. seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
  717. show_implementation_id(m, nfss);
  718. seq_printf(m, "\n\tcaps:\t");
  719. seq_printf(m, "caps=0x%x", nfss->caps);
  720. seq_printf(m, ",wtmult=%u", nfss->wtmult);
  721. seq_printf(m, ",dtsize=%u", nfss->dtsize);
  722. seq_printf(m, ",bsize=%u", nfss->bsize);
  723. seq_printf(m, ",namlen=%u", nfss->namelen);
  724. #if IS_ENABLED(CONFIG_NFS_V4)
  725. if (nfss->nfs_client->rpc_ops->version == 4) {
  726. seq_printf(m, "\n\tnfsv4:\t");
  727. seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
  728. seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
  729. seq_printf(m, ",bm2=0x%x", nfss->attr_bitmask[2]);
  730. seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
  731. show_sessions(m, nfss);
  732. show_pnfs(m, nfss);
  733. }
  734. #endif
  735. /*
  736. * Display security flavor in effect for this mount
  737. */
  738. seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
  739. if (auth->au_flavor)
  740. seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
  741. /*
  742. * Display superblock I/O counters
  743. */
  744. for_each_possible_cpu(cpu) {
  745. struct nfs_iostats *stats;
  746. preempt_disable();
  747. stats = per_cpu_ptr(nfss->io_stats, cpu);
  748. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  749. totals.events[i] += stats->events[i];
  750. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  751. totals.bytes[i] += stats->bytes[i];
  752. #ifdef CONFIG_NFS_FSCACHE
  753. for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
  754. totals.fscache[i] += stats->fscache[i];
  755. #endif
  756. preempt_enable();
  757. }
  758. seq_printf(m, "\n\tevents:\t");
  759. for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
  760. seq_printf(m, "%lu ", totals.events[i]);
  761. seq_printf(m, "\n\tbytes:\t");
  762. for (i = 0; i < __NFSIOS_BYTESMAX; i++)
  763. seq_printf(m, "%Lu ", totals.bytes[i]);
  764. #ifdef CONFIG_NFS_FSCACHE
  765. if (nfss->options & NFS_OPTION_FSCACHE) {
  766. seq_printf(m, "\n\tfsc:\t");
  767. for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
  768. seq_printf(m, "%Lu ", totals.bytes[i]);
  769. }
  770. #endif
  771. seq_printf(m, "\n");
  772. rpc_print_iostats(m, nfss->client);
  773. return 0;
  774. }
  775. EXPORT_SYMBOL_GPL(nfs_show_stats);
  776. /*
  777. * Begin unmount by attempting to remove all automounted mountpoints we added
  778. * in response to xdev traversals and referrals
  779. */
  780. void nfs_umount_begin(struct super_block *sb)
  781. {
  782. struct nfs_server *server;
  783. struct rpc_clnt *rpc;
  784. server = NFS_SB(sb);
  785. /* -EIO all pending I/O */
  786. rpc = server->client_acl;
  787. if (!IS_ERR(rpc))
  788. rpc_killall_tasks(rpc);
  789. rpc = server->client;
  790. if (!IS_ERR(rpc))
  791. rpc_killall_tasks(rpc);
  792. }
  793. EXPORT_SYMBOL_GPL(nfs_umount_begin);
  794. static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
  795. {
  796. struct nfs_parsed_mount_data *data;
  797. data = kzalloc(sizeof(*data), GFP_KERNEL);
  798. if (data) {
  799. data->acregmin = NFS_DEF_ACREGMIN;
  800. data->acregmax = NFS_DEF_ACREGMAX;
  801. data->acdirmin = NFS_DEF_ACDIRMIN;
  802. data->acdirmax = NFS_DEF_ACDIRMAX;
  803. data->mount_server.port = NFS_UNSPEC_PORT;
  804. data->nfs_server.port = NFS_UNSPEC_PORT;
  805. data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  806. data->selected_flavor = RPC_AUTH_MAXFLAVOR;
  807. data->minorversion = 0;
  808. data->need_mount = true;
  809. data->net = current->nsproxy->net_ns;
  810. security_init_mnt_opts(&data->lsm_opts);
  811. }
  812. return data;
  813. }
  814. static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
  815. {
  816. if (data) {
  817. kfree(data->client_address);
  818. kfree(data->mount_server.hostname);
  819. kfree(data->nfs_server.export_path);
  820. kfree(data->nfs_server.hostname);
  821. kfree(data->fscache_uniq);
  822. security_free_mnt_opts(&data->lsm_opts);
  823. kfree(data);
  824. }
  825. }
  826. /*
  827. * Sanity-check a server address provided by the mount command.
  828. *
  829. * Address family must be initialized, and address must not be
  830. * the ANY address for that family.
  831. */
  832. static int nfs_verify_server_address(struct sockaddr *addr)
  833. {
  834. switch (addr->sa_family) {
  835. case AF_INET: {
  836. struct sockaddr_in *sa = (struct sockaddr_in *)addr;
  837. return sa->sin_addr.s_addr != htonl(INADDR_ANY);
  838. }
  839. case AF_INET6: {
  840. struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
  841. return !ipv6_addr_any(sa);
  842. }
  843. }
  844. dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
  845. return 0;
  846. }
  847. /*
  848. * Select between a default port value and a user-specified port value.
  849. * If a zero value is set, then autobind will be used.
  850. */
  851. static void nfs_set_port(struct sockaddr *sap, int *port,
  852. const unsigned short default_port)
  853. {
  854. if (*port == NFS_UNSPEC_PORT)
  855. *port = default_port;
  856. rpc_set_port(sap, *port);
  857. }
  858. /*
  859. * Sanity check the NFS transport protocol.
  860. *
  861. */
  862. static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
  863. {
  864. switch (mnt->nfs_server.protocol) {
  865. case XPRT_TRANSPORT_UDP:
  866. case XPRT_TRANSPORT_TCP:
  867. case XPRT_TRANSPORT_RDMA:
  868. break;
  869. default:
  870. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  871. }
  872. }
  873. /*
  874. * For text based NFSv2/v3 mounts, the mount protocol transport default
  875. * settings should depend upon the specified NFS transport.
  876. */
  877. static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
  878. {
  879. nfs_validate_transport_protocol(mnt);
  880. if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
  881. mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
  882. return;
  883. switch (mnt->nfs_server.protocol) {
  884. case XPRT_TRANSPORT_UDP:
  885. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  886. break;
  887. case XPRT_TRANSPORT_TCP:
  888. case XPRT_TRANSPORT_RDMA:
  889. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  890. }
  891. }
  892. /*
  893. * Add 'flavor' to 'auth_info' if not already present.
  894. * Returns true if 'flavor' ends up in the list, false otherwise
  895. */
  896. static bool nfs_auth_info_add(struct nfs_auth_info *auth_info,
  897. rpc_authflavor_t flavor)
  898. {
  899. unsigned int i;
  900. unsigned int max_flavor_len = ARRAY_SIZE(auth_info->flavors);
  901. /* make sure this flavor isn't already in the list */
  902. for (i = 0; i < auth_info->flavor_len; i++) {
  903. if (flavor == auth_info->flavors[i])
  904. return true;
  905. }
  906. if (auth_info->flavor_len + 1 >= max_flavor_len) {
  907. dfprintk(MOUNT, "NFS: too many sec= flavors\n");
  908. return false;
  909. }
  910. auth_info->flavors[auth_info->flavor_len++] = flavor;
  911. return true;
  912. }
  913. /*
  914. * Return true if 'match' is in auth_info or auth_info is empty.
  915. * Return false otherwise.
  916. */
  917. bool nfs_auth_info_match(const struct nfs_auth_info *auth_info,
  918. rpc_authflavor_t match)
  919. {
  920. int i;
  921. if (!auth_info->flavor_len)
  922. return true;
  923. for (i = 0; i < auth_info->flavor_len; i++) {
  924. if (auth_info->flavors[i] == match)
  925. return true;
  926. }
  927. return false;
  928. }
  929. EXPORT_SYMBOL_GPL(nfs_auth_info_match);
  930. /*
  931. * Parse the value of the 'sec=' option.
  932. */
  933. static int nfs_parse_security_flavors(char *value,
  934. struct nfs_parsed_mount_data *mnt)
  935. {
  936. substring_t args[MAX_OPT_ARGS];
  937. rpc_authflavor_t pseudoflavor;
  938. char *p;
  939. dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
  940. while ((p = strsep(&value, ":")) != NULL) {
  941. switch (match_token(p, nfs_secflavor_tokens, args)) {
  942. case Opt_sec_none:
  943. pseudoflavor = RPC_AUTH_NULL;
  944. break;
  945. case Opt_sec_sys:
  946. pseudoflavor = RPC_AUTH_UNIX;
  947. break;
  948. case Opt_sec_krb5:
  949. pseudoflavor = RPC_AUTH_GSS_KRB5;
  950. break;
  951. case Opt_sec_krb5i:
  952. pseudoflavor = RPC_AUTH_GSS_KRB5I;
  953. break;
  954. case Opt_sec_krb5p:
  955. pseudoflavor = RPC_AUTH_GSS_KRB5P;
  956. break;
  957. case Opt_sec_lkey:
  958. pseudoflavor = RPC_AUTH_GSS_LKEY;
  959. break;
  960. case Opt_sec_lkeyi:
  961. pseudoflavor = RPC_AUTH_GSS_LKEYI;
  962. break;
  963. case Opt_sec_lkeyp:
  964. pseudoflavor = RPC_AUTH_GSS_LKEYP;
  965. break;
  966. case Opt_sec_spkm:
  967. pseudoflavor = RPC_AUTH_GSS_SPKM;
  968. break;
  969. case Opt_sec_spkmi:
  970. pseudoflavor = RPC_AUTH_GSS_SPKMI;
  971. break;
  972. case Opt_sec_spkmp:
  973. pseudoflavor = RPC_AUTH_GSS_SPKMP;
  974. break;
  975. default:
  976. dfprintk(MOUNT,
  977. "NFS: sec= option '%s' not recognized\n", p);
  978. return 0;
  979. }
  980. if (!nfs_auth_info_add(&mnt->auth_info, pseudoflavor))
  981. return 0;
  982. }
  983. return 1;
  984. }
  985. static int nfs_parse_version_string(char *string,
  986. struct nfs_parsed_mount_data *mnt,
  987. substring_t *args)
  988. {
  989. mnt->flags &= ~NFS_MOUNT_VER3;
  990. switch (match_token(string, nfs_vers_tokens, args)) {
  991. case Opt_vers_2:
  992. mnt->version = 2;
  993. break;
  994. case Opt_vers_3:
  995. mnt->flags |= NFS_MOUNT_VER3;
  996. mnt->version = 3;
  997. break;
  998. case Opt_vers_4:
  999. /* Backward compatibility option. In future,
  1000. * the mount program should always supply
  1001. * a NFSv4 minor version number.
  1002. */
  1003. mnt->version = 4;
  1004. break;
  1005. case Opt_vers_4_0:
  1006. mnt->version = 4;
  1007. mnt->minorversion = 0;
  1008. break;
  1009. case Opt_vers_4_1:
  1010. mnt->version = 4;
  1011. mnt->minorversion = 1;
  1012. break;
  1013. case Opt_vers_4_2:
  1014. mnt->version = 4;
  1015. mnt->minorversion = 2;
  1016. break;
  1017. default:
  1018. return 0;
  1019. }
  1020. return 1;
  1021. }
  1022. static int nfs_get_option_str(substring_t args[], char **option)
  1023. {
  1024. kfree(*option);
  1025. *option = match_strdup(args);
  1026. return !*option;
  1027. }
  1028. static int nfs_get_option_ul(substring_t args[], unsigned long *option)
  1029. {
  1030. int rc;
  1031. char *string;
  1032. string = match_strdup(args);
  1033. if (string == NULL)
  1034. return -ENOMEM;
  1035. rc = kstrtoul(string, 10, option);
  1036. kfree(string);
  1037. return rc;
  1038. }
  1039. /*
  1040. * Error-check and convert a string of mount options from user space into
  1041. * a data structure. The whole mount string is processed; bad options are
  1042. * skipped as they are encountered. If there were no errors, return 1;
  1043. * otherwise return 0 (zero).
  1044. */
  1045. static int nfs_parse_mount_options(char *raw,
  1046. struct nfs_parsed_mount_data *mnt)
  1047. {
  1048. char *p, *string, *secdata;
  1049. int rc, sloppy = 0, invalid_option = 0;
  1050. unsigned short protofamily = AF_UNSPEC;
  1051. unsigned short mountfamily = AF_UNSPEC;
  1052. if (!raw) {
  1053. dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
  1054. return 1;
  1055. }
  1056. dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
  1057. secdata = alloc_secdata();
  1058. if (!secdata)
  1059. goto out_nomem;
  1060. rc = security_sb_copy_data(raw, secdata);
  1061. if (rc)
  1062. goto out_security_failure;
  1063. rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
  1064. if (rc)
  1065. goto out_security_failure;
  1066. free_secdata(secdata);
  1067. while ((p = strsep(&raw, ",")) != NULL) {
  1068. substring_t args[MAX_OPT_ARGS];
  1069. unsigned long option;
  1070. int token;
  1071. if (!*p)
  1072. continue;
  1073. dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
  1074. token = match_token(p, nfs_mount_option_tokens, args);
  1075. switch (token) {
  1076. /*
  1077. * boolean options: foo/nofoo
  1078. */
  1079. case Opt_soft:
  1080. mnt->flags |= NFS_MOUNT_SOFT;
  1081. break;
  1082. case Opt_hard:
  1083. mnt->flags &= ~NFS_MOUNT_SOFT;
  1084. break;
  1085. case Opt_posix:
  1086. mnt->flags |= NFS_MOUNT_POSIX;
  1087. break;
  1088. case Opt_noposix:
  1089. mnt->flags &= ~NFS_MOUNT_POSIX;
  1090. break;
  1091. case Opt_cto:
  1092. mnt->flags &= ~NFS_MOUNT_NOCTO;
  1093. break;
  1094. case Opt_nocto:
  1095. mnt->flags |= NFS_MOUNT_NOCTO;
  1096. break;
  1097. case Opt_ac:
  1098. mnt->flags &= ~NFS_MOUNT_NOAC;
  1099. break;
  1100. case Opt_noac:
  1101. mnt->flags |= NFS_MOUNT_NOAC;
  1102. break;
  1103. case Opt_lock:
  1104. mnt->flags &= ~NFS_MOUNT_NONLM;
  1105. mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
  1106. NFS_MOUNT_LOCAL_FCNTL);
  1107. break;
  1108. case Opt_nolock:
  1109. mnt->flags |= NFS_MOUNT_NONLM;
  1110. mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
  1111. NFS_MOUNT_LOCAL_FCNTL);
  1112. break;
  1113. case Opt_udp:
  1114. mnt->flags &= ~NFS_MOUNT_TCP;
  1115. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1116. break;
  1117. case Opt_tcp:
  1118. mnt->flags |= NFS_MOUNT_TCP;
  1119. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1120. break;
  1121. case Opt_rdma:
  1122. mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
  1123. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1124. xprt_load_transport(p);
  1125. break;
  1126. case Opt_acl:
  1127. mnt->flags &= ~NFS_MOUNT_NOACL;
  1128. break;
  1129. case Opt_noacl:
  1130. mnt->flags |= NFS_MOUNT_NOACL;
  1131. break;
  1132. case Opt_rdirplus:
  1133. mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
  1134. break;
  1135. case Opt_nordirplus:
  1136. mnt->flags |= NFS_MOUNT_NORDIRPLUS;
  1137. break;
  1138. case Opt_sharecache:
  1139. mnt->flags &= ~NFS_MOUNT_UNSHARED;
  1140. break;
  1141. case Opt_nosharecache:
  1142. mnt->flags |= NFS_MOUNT_UNSHARED;
  1143. break;
  1144. case Opt_resvport:
  1145. mnt->flags &= ~NFS_MOUNT_NORESVPORT;
  1146. break;
  1147. case Opt_noresvport:
  1148. mnt->flags |= NFS_MOUNT_NORESVPORT;
  1149. break;
  1150. case Opt_fscache:
  1151. mnt->options |= NFS_OPTION_FSCACHE;
  1152. kfree(mnt->fscache_uniq);
  1153. mnt->fscache_uniq = NULL;
  1154. break;
  1155. case Opt_nofscache:
  1156. mnt->options &= ~NFS_OPTION_FSCACHE;
  1157. kfree(mnt->fscache_uniq);
  1158. mnt->fscache_uniq = NULL;
  1159. break;
  1160. case Opt_migration:
  1161. mnt->options |= NFS_OPTION_MIGRATION;
  1162. break;
  1163. case Opt_nomigration:
  1164. mnt->options &= NFS_OPTION_MIGRATION;
  1165. break;
  1166. /*
  1167. * options that take numeric values
  1168. */
  1169. case Opt_port:
  1170. if (nfs_get_option_ul(args, &option) ||
  1171. option > USHRT_MAX)
  1172. goto out_invalid_value;
  1173. mnt->nfs_server.port = option;
  1174. break;
  1175. case Opt_rsize:
  1176. if (nfs_get_option_ul(args, &option))
  1177. goto out_invalid_value;
  1178. mnt->rsize = option;
  1179. break;
  1180. case Opt_wsize:
  1181. if (nfs_get_option_ul(args, &option))
  1182. goto out_invalid_value;
  1183. mnt->wsize = option;
  1184. break;
  1185. case Opt_bsize:
  1186. if (nfs_get_option_ul(args, &option))
  1187. goto out_invalid_value;
  1188. mnt->bsize = option;
  1189. break;
  1190. case Opt_timeo:
  1191. if (nfs_get_option_ul(args, &option) || option == 0)
  1192. goto out_invalid_value;
  1193. mnt->timeo = option;
  1194. break;
  1195. case Opt_retrans:
  1196. if (nfs_get_option_ul(args, &option) || option == 0)
  1197. goto out_invalid_value;
  1198. mnt->retrans = option;
  1199. break;
  1200. case Opt_acregmin:
  1201. if (nfs_get_option_ul(args, &option))
  1202. goto out_invalid_value;
  1203. mnt->acregmin = option;
  1204. break;
  1205. case Opt_acregmax:
  1206. if (nfs_get_option_ul(args, &option))
  1207. goto out_invalid_value;
  1208. mnt->acregmax = option;
  1209. break;
  1210. case Opt_acdirmin:
  1211. if (nfs_get_option_ul(args, &option))
  1212. goto out_invalid_value;
  1213. mnt->acdirmin = option;
  1214. break;
  1215. case Opt_acdirmax:
  1216. if (nfs_get_option_ul(args, &option))
  1217. goto out_invalid_value;
  1218. mnt->acdirmax = option;
  1219. break;
  1220. case Opt_actimeo:
  1221. if (nfs_get_option_ul(args, &option))
  1222. goto out_invalid_value;
  1223. mnt->acregmin = mnt->acregmax =
  1224. mnt->acdirmin = mnt->acdirmax = option;
  1225. break;
  1226. case Opt_namelen:
  1227. if (nfs_get_option_ul(args, &option))
  1228. goto out_invalid_value;
  1229. mnt->namlen = option;
  1230. break;
  1231. case Opt_mountport:
  1232. if (nfs_get_option_ul(args, &option) ||
  1233. option > USHRT_MAX)
  1234. goto out_invalid_value;
  1235. mnt->mount_server.port = option;
  1236. break;
  1237. case Opt_mountvers:
  1238. if (nfs_get_option_ul(args, &option) ||
  1239. option < NFS_MNT_VERSION ||
  1240. option > NFS_MNT3_VERSION)
  1241. goto out_invalid_value;
  1242. mnt->mount_server.version = option;
  1243. break;
  1244. case Opt_minorversion:
  1245. if (nfs_get_option_ul(args, &option))
  1246. goto out_invalid_value;
  1247. if (option > NFS4_MAX_MINOR_VERSION)
  1248. goto out_invalid_value;
  1249. mnt->minorversion = option;
  1250. break;
  1251. /*
  1252. * options that take text values
  1253. */
  1254. case Opt_nfsvers:
  1255. string = match_strdup(args);
  1256. if (string == NULL)
  1257. goto out_nomem;
  1258. rc = nfs_parse_version_string(string, mnt, args);
  1259. kfree(string);
  1260. if (!rc)
  1261. goto out_invalid_value;
  1262. break;
  1263. case Opt_sec:
  1264. string = match_strdup(args);
  1265. if (string == NULL)
  1266. goto out_nomem;
  1267. rc = nfs_parse_security_flavors(string, mnt);
  1268. kfree(string);
  1269. if (!rc) {
  1270. dfprintk(MOUNT, "NFS: unrecognized "
  1271. "security flavor\n");
  1272. return 0;
  1273. }
  1274. break;
  1275. case Opt_proto:
  1276. string = match_strdup(args);
  1277. if (string == NULL)
  1278. goto out_nomem;
  1279. token = match_token(string,
  1280. nfs_xprt_protocol_tokens, args);
  1281. protofamily = AF_INET;
  1282. switch (token) {
  1283. case Opt_xprt_udp6:
  1284. protofamily = AF_INET6;
  1285. case Opt_xprt_udp:
  1286. mnt->flags &= ~NFS_MOUNT_TCP;
  1287. mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1288. break;
  1289. case Opt_xprt_tcp6:
  1290. protofamily = AF_INET6;
  1291. case Opt_xprt_tcp:
  1292. mnt->flags |= NFS_MOUNT_TCP;
  1293. mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
  1294. break;
  1295. case Opt_xprt_rdma:
  1296. /* vector side protocols to TCP */
  1297. mnt->flags |= NFS_MOUNT_TCP;
  1298. mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
  1299. xprt_load_transport(string);
  1300. break;
  1301. default:
  1302. dfprintk(MOUNT, "NFS: unrecognized "
  1303. "transport protocol\n");
  1304. kfree(string);
  1305. return 0;
  1306. }
  1307. kfree(string);
  1308. break;
  1309. case Opt_mountproto:
  1310. string = match_strdup(args);
  1311. if (string == NULL)
  1312. goto out_nomem;
  1313. token = match_token(string,
  1314. nfs_xprt_protocol_tokens, args);
  1315. kfree(string);
  1316. mountfamily = AF_INET;
  1317. switch (token) {
  1318. case Opt_xprt_udp6:
  1319. mountfamily = AF_INET6;
  1320. case Opt_xprt_udp:
  1321. mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
  1322. break;
  1323. case Opt_xprt_tcp6:
  1324. mountfamily = AF_INET6;
  1325. case Opt_xprt_tcp:
  1326. mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
  1327. break;
  1328. case Opt_xprt_rdma: /* not used for side protocols */
  1329. default:
  1330. dfprintk(MOUNT, "NFS: unrecognized "
  1331. "transport protocol\n");
  1332. return 0;
  1333. }
  1334. break;
  1335. case Opt_addr:
  1336. string = match_strdup(args);
  1337. if (string == NULL)
  1338. goto out_nomem;
  1339. mnt->nfs_server.addrlen =
  1340. rpc_pton(mnt->net, string, strlen(string),
  1341. (struct sockaddr *)
  1342. &mnt->nfs_server.address,
  1343. sizeof(mnt->nfs_server.address));
  1344. kfree(string);
  1345. if (mnt->nfs_server.addrlen == 0)
  1346. goto out_invalid_address;
  1347. break;
  1348. case Opt_clientaddr:
  1349. if (nfs_get_option_str(args, &mnt->client_address))
  1350. goto out_nomem;
  1351. break;
  1352. case Opt_mounthost:
  1353. if (nfs_get_option_str(args,
  1354. &mnt->mount_server.hostname))
  1355. goto out_nomem;
  1356. break;
  1357. case Opt_mountaddr:
  1358. string = match_strdup(args);
  1359. if (string == NULL)
  1360. goto out_nomem;
  1361. mnt->mount_server.addrlen =
  1362. rpc_pton(mnt->net, string, strlen(string),
  1363. (struct sockaddr *)
  1364. &mnt->mount_server.address,
  1365. sizeof(mnt->mount_server.address));
  1366. kfree(string);
  1367. if (mnt->mount_server.addrlen == 0)
  1368. goto out_invalid_address;
  1369. break;
  1370. case Opt_lookupcache:
  1371. string = match_strdup(args);
  1372. if (string == NULL)
  1373. goto out_nomem;
  1374. token = match_token(string,
  1375. nfs_lookupcache_tokens, args);
  1376. kfree(string);
  1377. switch (token) {
  1378. case Opt_lookupcache_all:
  1379. mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
  1380. break;
  1381. case Opt_lookupcache_positive:
  1382. mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
  1383. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
  1384. break;
  1385. case Opt_lookupcache_none:
  1386. mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
  1387. break;
  1388. default:
  1389. dfprintk(MOUNT, "NFS: invalid "
  1390. "lookupcache argument\n");
  1391. return 0;
  1392. };
  1393. break;
  1394. case Opt_fscache_uniq:
  1395. if (nfs_get_option_str(args, &mnt->fscache_uniq))
  1396. goto out_nomem;
  1397. mnt->options |= NFS_OPTION_FSCACHE;
  1398. break;
  1399. case Opt_local_lock:
  1400. string = match_strdup(args);
  1401. if (string == NULL)
  1402. goto out_nomem;
  1403. token = match_token(string, nfs_local_lock_tokens,
  1404. args);
  1405. kfree(string);
  1406. switch (token) {
  1407. case Opt_local_lock_all:
  1408. mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
  1409. NFS_MOUNT_LOCAL_FCNTL);
  1410. break;
  1411. case Opt_local_lock_flock:
  1412. mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
  1413. break;
  1414. case Opt_local_lock_posix:
  1415. mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
  1416. break;
  1417. case Opt_local_lock_none:
  1418. mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
  1419. NFS_MOUNT_LOCAL_FCNTL);
  1420. break;
  1421. default:
  1422. dfprintk(MOUNT, "NFS: invalid "
  1423. "local_lock argument\n");
  1424. return 0;
  1425. };
  1426. break;
  1427. /*
  1428. * Special options
  1429. */
  1430. case Opt_sloppy:
  1431. sloppy = 1;
  1432. dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
  1433. break;
  1434. case Opt_userspace:
  1435. case Opt_deprecated:
  1436. dfprintk(MOUNT, "NFS: ignoring mount option "
  1437. "'%s'\n", p);
  1438. break;
  1439. default:
  1440. invalid_option = 1;
  1441. dfprintk(MOUNT, "NFS: unrecognized mount option "
  1442. "'%s'\n", p);
  1443. }
  1444. }
  1445. if (!sloppy && invalid_option)
  1446. return 0;
  1447. if (mnt->minorversion && mnt->version != 4)
  1448. goto out_minorversion_mismatch;
  1449. if (mnt->options & NFS_OPTION_MIGRATION &&
  1450. (mnt->version != 4 || mnt->minorversion != 0))
  1451. goto out_migration_misuse;
  1452. /*
  1453. * verify that any proto=/mountproto= options match the address
  1454. * families in the addr=/mountaddr= options.
  1455. */
  1456. if (protofamily != AF_UNSPEC &&
  1457. protofamily != mnt->nfs_server.address.ss_family)
  1458. goto out_proto_mismatch;
  1459. if (mountfamily != AF_UNSPEC) {
  1460. if (mnt->mount_server.addrlen) {
  1461. if (mountfamily != mnt->mount_server.address.ss_family)
  1462. goto out_mountproto_mismatch;
  1463. } else {
  1464. if (mountfamily != mnt->nfs_server.address.ss_family)
  1465. goto out_mountproto_mismatch;
  1466. }
  1467. }
  1468. return 1;
  1469. out_mountproto_mismatch:
  1470. printk(KERN_INFO "NFS: mount server address does not match mountproto= "
  1471. "option\n");
  1472. return 0;
  1473. out_proto_mismatch:
  1474. printk(KERN_INFO "NFS: server address does not match proto= option\n");
  1475. return 0;
  1476. out_invalid_address:
  1477. printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
  1478. return 0;
  1479. out_invalid_value:
  1480. printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
  1481. return 0;
  1482. out_minorversion_mismatch:
  1483. printk(KERN_INFO "NFS: mount option vers=%u does not support "
  1484. "minorversion=%u\n", mnt->version, mnt->minorversion);
  1485. return 0;
  1486. out_migration_misuse:
  1487. printk(KERN_INFO
  1488. "NFS: 'migration' not supported for this NFS version\n");
  1489. return 0;
  1490. out_nomem:
  1491. printk(KERN_INFO "NFS: not enough memory to parse option\n");
  1492. return 0;
  1493. out_security_failure:
  1494. free_secdata(secdata);
  1495. printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
  1496. return 0;
  1497. }
  1498. /*
  1499. * Ensure that a specified authtype in args->auth_info is supported by
  1500. * the server. Returns 0 and sets args->selected_flavor if it's ok, and
  1501. * -EACCES if not.
  1502. */
  1503. static int nfs_verify_authflavors(struct nfs_parsed_mount_data *args,
  1504. rpc_authflavor_t *server_authlist, unsigned int count)
  1505. {
  1506. rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR;
  1507. unsigned int i;
  1508. /*
  1509. * If the sec= mount option is used, the specified flavor or AUTH_NULL
  1510. * must be in the list returned by the server.
  1511. *
  1512. * AUTH_NULL has a special meaning when it's in the server list - it
  1513. * means that the server will ignore the rpc creds, so any flavor
  1514. * can be used.
  1515. */
  1516. for (i = 0; i < count; i++) {
  1517. flavor = server_authlist[i];
  1518. if (nfs_auth_info_match(&args->auth_info, flavor) ||
  1519. flavor == RPC_AUTH_NULL)
  1520. goto out;
  1521. }
  1522. dfprintk(MOUNT,
  1523. "NFS: specified auth flavors not supported by server\n");
  1524. return -EACCES;
  1525. out:
  1526. args->selected_flavor = flavor;
  1527. dfprintk(MOUNT, "NFS: using auth flavor %u\n", args->selected_flavor);
  1528. return 0;
  1529. }
  1530. /*
  1531. * Use the remote server's MOUNT service to request the NFS file handle
  1532. * corresponding to the provided path.
  1533. */
  1534. static int nfs_request_mount(struct nfs_parsed_mount_data *args,
  1535. struct nfs_fh *root_fh,
  1536. rpc_authflavor_t *server_authlist,
  1537. unsigned int *server_authlist_len)
  1538. {
  1539. struct nfs_mount_request request = {
  1540. .sap = (struct sockaddr *)
  1541. &args->mount_server.address,
  1542. .dirpath = args->nfs_server.export_path,
  1543. .protocol = args->mount_server.protocol,
  1544. .fh = root_fh,
  1545. .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
  1546. .auth_flav_len = server_authlist_len,
  1547. .auth_flavs = server_authlist,
  1548. .net = args->net,
  1549. };
  1550. int status;
  1551. if (args->mount_server.version == 0) {
  1552. switch (args->version) {
  1553. default:
  1554. args->mount_server.version = NFS_MNT3_VERSION;
  1555. break;
  1556. case 2:
  1557. args->mount_server.version = NFS_MNT_VERSION;
  1558. }
  1559. }
  1560. request.version = args->mount_server.version;
  1561. if (args->mount_server.hostname)
  1562. request.hostname = args->mount_server.hostname;
  1563. else
  1564. request.hostname = args->nfs_server.hostname;
  1565. /*
  1566. * Construct the mount server's address.
  1567. */
  1568. if (args->mount_server.address.ss_family == AF_UNSPEC) {
  1569. memcpy(request.sap, &args->nfs_server.address,
  1570. args->nfs_server.addrlen);
  1571. args->mount_server.addrlen = args->nfs_server.addrlen;
  1572. }
  1573. request.salen = args->mount_server.addrlen;
  1574. nfs_set_port(request.sap, &args->mount_server.port, 0);
  1575. /*
  1576. * Now ask the mount server to map our export path
  1577. * to a file handle.
  1578. */
  1579. status = nfs_mount(&request);
  1580. if (status != 0) {
  1581. dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
  1582. request.hostname, status);
  1583. return status;
  1584. }
  1585. return 0;
  1586. }
  1587. static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_info,
  1588. struct nfs_subversion *nfs_mod)
  1589. {
  1590. int status;
  1591. unsigned int i;
  1592. bool tried_auth_unix = false;
  1593. bool auth_null_in_list = false;
  1594. struct nfs_server *server = ERR_PTR(-EACCES);
  1595. struct nfs_parsed_mount_data *args = mount_info->parsed;
  1596. rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS];
  1597. unsigned int authlist_len = ARRAY_SIZE(authlist);
  1598. status = nfs_request_mount(args, mount_info->mntfh, authlist,
  1599. &authlist_len);
  1600. if (status)
  1601. return ERR_PTR(status);
  1602. /*
  1603. * Was a sec= authflavor specified in the options? First, verify
  1604. * whether the server supports it, and then just try to use it if so.
  1605. */
  1606. if (args->auth_info.flavor_len > 0) {
  1607. status = nfs_verify_authflavors(args, authlist, authlist_len);
  1608. dfprintk(MOUNT, "NFS: using auth flavor %u\n",
  1609. args->selected_flavor);
  1610. if (status)
  1611. return ERR_PTR(status);
  1612. return nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1613. }
  1614. /*
  1615. * No sec= option was provided. RFC 2623, section 2.7 suggests we
  1616. * SHOULD prefer the flavor listed first. However, some servers list
  1617. * AUTH_NULL first. Avoid ever choosing AUTH_NULL.
  1618. */
  1619. for (i = 0; i < authlist_len; ++i) {
  1620. rpc_authflavor_t flavor;
  1621. struct rpcsec_gss_info info;
  1622. flavor = authlist[i];
  1623. switch (flavor) {
  1624. case RPC_AUTH_UNIX:
  1625. tried_auth_unix = true;
  1626. break;
  1627. case RPC_AUTH_NULL:
  1628. auth_null_in_list = true;
  1629. continue;
  1630. default:
  1631. if (rpcauth_get_gssinfo(flavor, &info) != 0)
  1632. continue;
  1633. /* Fallthrough */
  1634. }
  1635. dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
  1636. args->selected_flavor = flavor;
  1637. server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1638. if (!IS_ERR(server))
  1639. return server;
  1640. }
  1641. /*
  1642. * Nothing we tried so far worked. At this point, give up if we've
  1643. * already tried AUTH_UNIX or if the server's list doesn't contain
  1644. * AUTH_NULL
  1645. */
  1646. if (tried_auth_unix || !auth_null_in_list)
  1647. return server;
  1648. /* Last chance! Try AUTH_UNIX */
  1649. dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", RPC_AUTH_UNIX);
  1650. args->selected_flavor = RPC_AUTH_UNIX;
  1651. return nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1652. }
  1653. struct dentry *nfs_try_mount(int flags, const char *dev_name,
  1654. struct nfs_mount_info *mount_info,
  1655. struct nfs_subversion *nfs_mod)
  1656. {
  1657. struct nfs_server *server;
  1658. if (mount_info->parsed->need_mount)
  1659. server = nfs_try_mount_request(mount_info, nfs_mod);
  1660. else
  1661. server = nfs_mod->rpc_ops->create_server(mount_info, nfs_mod);
  1662. if (IS_ERR(server))
  1663. return ERR_CAST(server);
  1664. return nfs_fs_mount_common(server, flags, dev_name, mount_info, nfs_mod);
  1665. }
  1666. EXPORT_SYMBOL_GPL(nfs_try_mount);
  1667. /*
  1668. * Split "dev_name" into "hostname:export_path".
  1669. *
  1670. * The leftmost colon demarks the split between the server's hostname
  1671. * and the export path. If the hostname starts with a left square
  1672. * bracket, then it may contain colons.
  1673. *
  1674. * Note: caller frees hostname and export path, even on error.
  1675. */
  1676. static int nfs_parse_devname(const char *dev_name,
  1677. char **hostname, size_t maxnamlen,
  1678. char **export_path, size_t maxpathlen)
  1679. {
  1680. size_t len;
  1681. char *end;
  1682. /* Is the host name protected with square brakcets? */
  1683. if (*dev_name == '[') {
  1684. end = strchr(++dev_name, ']');
  1685. if (end == NULL || end[1] != ':')
  1686. goto out_bad_devname;
  1687. len = end - dev_name;
  1688. end++;
  1689. } else {
  1690. char *comma;
  1691. end = strchr(dev_name, ':');
  1692. if (end == NULL)
  1693. goto out_bad_devname;
  1694. len = end - dev_name;
  1695. /* kill possible hostname list: not supported */
  1696. comma = strchr(dev_name, ',');
  1697. if (comma != NULL && comma < end)
  1698. *comma = 0;
  1699. }
  1700. if (len > maxnamlen)
  1701. goto out_hostname;
  1702. /* N.B. caller will free nfs_server.hostname in all cases */
  1703. *hostname = kstrndup(dev_name, len, GFP_KERNEL);
  1704. if (*hostname == NULL)
  1705. goto out_nomem;
  1706. len = strlen(++end);
  1707. if (len > maxpathlen)
  1708. goto out_path;
  1709. *export_path = kstrndup(end, len, GFP_KERNEL);
  1710. if (!*export_path)
  1711. goto out_nomem;
  1712. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
  1713. return 0;
  1714. out_bad_devname:
  1715. dfprintk(MOUNT, "NFS: device name not in host:path format\n");
  1716. return -EINVAL;
  1717. out_nomem:
  1718. dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
  1719. return -ENOMEM;
  1720. out_hostname:
  1721. dfprintk(MOUNT, "NFS: server hostname too long\n");
  1722. return -ENAMETOOLONG;
  1723. out_path:
  1724. dfprintk(MOUNT, "NFS: export pathname too long\n");
  1725. return -ENAMETOOLONG;
  1726. }
  1727. /*
  1728. * Validate the NFS2/NFS3 mount data
  1729. * - fills in the mount root filehandle
  1730. *
  1731. * For option strings, user space handles the following behaviors:
  1732. *
  1733. * + DNS: mapping server host name to IP address ("addr=" option)
  1734. *
  1735. * + failure mode: how to behave if a mount request can't be handled
  1736. * immediately ("fg/bg" option)
  1737. *
  1738. * + retry: how often to retry a mount request ("retry=" option)
  1739. *
  1740. * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
  1741. * mountproto=tcp after mountproto=udp, and so on
  1742. */
  1743. static int nfs23_validate_mount_data(void *options,
  1744. struct nfs_parsed_mount_data *args,
  1745. struct nfs_fh *mntfh,
  1746. const char *dev_name)
  1747. {
  1748. struct nfs_mount_data *data = (struct nfs_mount_data *)options;
  1749. struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
  1750. int extra_flags = NFS_MOUNT_LEGACY_INTERFACE;
  1751. if (data == NULL)
  1752. goto out_no_data;
  1753. args->version = NFS_DEFAULT_VERSION;
  1754. switch (data->version) {
  1755. case 1:
  1756. data->namlen = 0;
  1757. case 2:
  1758. data->bsize = 0;
  1759. case 3:
  1760. if (data->flags & NFS_MOUNT_VER3)
  1761. goto out_no_v3;
  1762. data->root.size = NFS2_FHSIZE;
  1763. memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
  1764. /* Turn off security negotiation */
  1765. extra_flags |= NFS_MOUNT_SECFLAVOUR;
  1766. case 4:
  1767. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1768. goto out_no_sec;
  1769. case 5:
  1770. memset(data->context, 0, sizeof(data->context));
  1771. case 6:
  1772. if (data->flags & NFS_MOUNT_VER3) {
  1773. if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
  1774. goto out_invalid_fh;
  1775. mntfh->size = data->root.size;
  1776. args->version = 3;
  1777. } else {
  1778. mntfh->size = NFS2_FHSIZE;
  1779. args->version = 2;
  1780. }
  1781. memcpy(mntfh->data, data->root.data, mntfh->size);
  1782. if (mntfh->size < sizeof(mntfh->data))
  1783. memset(mntfh->data + mntfh->size, 0,
  1784. sizeof(mntfh->data) - mntfh->size);
  1785. /*
  1786. * Translate to nfs_parsed_mount_data, which nfs_fill_super
  1787. * can deal with.
  1788. */
  1789. args->flags = data->flags & NFS_MOUNT_FLAGMASK;
  1790. args->flags |= extra_flags;
  1791. args->rsize = data->rsize;
  1792. args->wsize = data->wsize;
  1793. args->timeo = data->timeo;
  1794. args->retrans = data->retrans;
  1795. args->acregmin = data->acregmin;
  1796. args->acregmax = data->acregmax;
  1797. args->acdirmin = data->acdirmin;
  1798. args->acdirmax = data->acdirmax;
  1799. args->need_mount = false;
  1800. memcpy(sap, &data->addr, sizeof(data->addr));
  1801. args->nfs_server.addrlen = sizeof(data->addr);
  1802. args->nfs_server.port = ntohs(data->addr.sin_port);
  1803. if (!nfs_verify_server_address(sap))
  1804. goto out_no_address;
  1805. if (!(data->flags & NFS_MOUNT_TCP))
  1806. args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
  1807. /* N.B. caller will free nfs_server.hostname in all cases */
  1808. args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
  1809. args->namlen = data->namlen;
  1810. args->bsize = data->bsize;
  1811. if (data->flags & NFS_MOUNT_SECFLAVOUR)
  1812. args->selected_flavor = data->pseudoflavor;
  1813. else
  1814. args->selected_flavor = RPC_AUTH_UNIX;
  1815. if (!args->nfs_server.hostname)
  1816. goto out_nomem;
  1817. if (!(data->flags & NFS_MOUNT_NONLM))
  1818. args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
  1819. NFS_MOUNT_LOCAL_FCNTL);
  1820. else
  1821. args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
  1822. NFS_MOUNT_LOCAL_FCNTL);
  1823. /*
  1824. * The legacy version 6 binary mount data from userspace has a
  1825. * field used only to transport selinux information into the
  1826. * the kernel. To continue to support that functionality we
  1827. * have a touch of selinux knowledge here in the NFS code. The
  1828. * userspace code converted context=blah to just blah so we are
  1829. * converting back to the full string selinux understands.
  1830. */
  1831. if (data->context[0]){
  1832. #ifdef CONFIG_SECURITY_SELINUX
  1833. int rc;
  1834. char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
  1835. if (!opts_str)
  1836. return -ENOMEM;
  1837. strcpy(opts_str, "context=");
  1838. data->context[NFS_MAX_CONTEXT_LEN] = '\0';
  1839. strcat(opts_str, &data->context[0]);
  1840. rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
  1841. kfree(opts_str);
  1842. if (rc)
  1843. return rc;
  1844. #else
  1845. return -EINVAL;
  1846. #endif
  1847. }
  1848. break;
  1849. default:
  1850. return NFS_TEXT_DATA;
  1851. }
  1852. return 0;
  1853. out_no_data:
  1854. dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
  1855. return -EINVAL;
  1856. out_no_v3:
  1857. dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
  1858. data->version);
  1859. return -EINVAL;
  1860. out_no_sec:
  1861. dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
  1862. return -EINVAL;
  1863. out_nomem:
  1864. dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
  1865. return -ENOMEM;
  1866. out_no_address:
  1867. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1868. return -EINVAL;
  1869. out_invalid_fh:
  1870. dfprintk(MOUNT, "NFS: invalid root filehandle\n");
  1871. return -EINVAL;
  1872. }
  1873. #if IS_ENABLED(CONFIG_NFS_V4)
  1874. static int nfs_validate_mount_data(struct file_system_type *fs_type,
  1875. void *options,
  1876. struct nfs_parsed_mount_data *args,
  1877. struct nfs_fh *mntfh,
  1878. const char *dev_name)
  1879. {
  1880. if (fs_type == &nfs_fs_type)
  1881. return nfs23_validate_mount_data(options, args, mntfh, dev_name);
  1882. return nfs4_validate_mount_data(options, args, dev_name);
  1883. }
  1884. #else
  1885. static int nfs_validate_mount_data(struct file_system_type *fs_type,
  1886. void *options,
  1887. struct nfs_parsed_mount_data *args,
  1888. struct nfs_fh *mntfh,
  1889. const char *dev_name)
  1890. {
  1891. return nfs23_validate_mount_data(options, args, mntfh, dev_name);
  1892. }
  1893. #endif
  1894. static int nfs_validate_text_mount_data(void *options,
  1895. struct nfs_parsed_mount_data *args,
  1896. const char *dev_name)
  1897. {
  1898. int port = 0;
  1899. int max_namelen = PAGE_SIZE;
  1900. int max_pathlen = NFS_MAXPATHLEN;
  1901. struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
  1902. if (nfs_parse_mount_options((char *)options, args) == 0)
  1903. return -EINVAL;
  1904. if (!nfs_verify_server_address(sap))
  1905. goto out_no_address;
  1906. if (args->version == 4) {
  1907. #if IS_ENABLED(CONFIG_NFS_V4)
  1908. port = NFS_PORT;
  1909. max_namelen = NFS4_MAXNAMLEN;
  1910. max_pathlen = NFS4_MAXPATHLEN;
  1911. nfs_validate_transport_protocol(args);
  1912. if (args->nfs_server.protocol == XPRT_TRANSPORT_UDP)
  1913. goto out_invalid_transport_udp;
  1914. nfs4_validate_mount_flags(args);
  1915. #else
  1916. goto out_v4_not_compiled;
  1917. #endif /* CONFIG_NFS_V4 */
  1918. } else
  1919. nfs_set_mount_transport_protocol(args);
  1920. nfs_set_port(sap, &args->nfs_server.port, port);
  1921. return nfs_parse_devname(dev_name,
  1922. &args->nfs_server.hostname,
  1923. max_namelen,
  1924. &args->nfs_server.export_path,
  1925. max_pathlen);
  1926. #if !IS_ENABLED(CONFIG_NFS_V4)
  1927. out_v4_not_compiled:
  1928. dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
  1929. return -EPROTONOSUPPORT;
  1930. #else
  1931. out_invalid_transport_udp:
  1932. dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
  1933. return -EINVAL;
  1934. #endif /* !CONFIG_NFS_V4 */
  1935. out_no_address:
  1936. dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
  1937. return -EINVAL;
  1938. }
  1939. #define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \
  1940. | NFS_MOUNT_SECURE \
  1941. | NFS_MOUNT_TCP \
  1942. | NFS_MOUNT_VER3 \
  1943. | NFS_MOUNT_KERBEROS \
  1944. | NFS_MOUNT_NONLM \
  1945. | NFS_MOUNT_BROKEN_SUID \
  1946. | NFS_MOUNT_STRICTLOCK \
  1947. | NFS_MOUNT_LEGACY_INTERFACE)
  1948. #define NFS_MOUNT_CMP_FLAGMASK (NFS_REMOUNT_CMP_FLAGMASK & \
  1949. ~(NFS_MOUNT_UNSHARED | NFS_MOUNT_NORESVPORT))
  1950. static int
  1951. nfs_compare_remount_data(struct nfs_server *nfss,
  1952. struct nfs_parsed_mount_data *data)
  1953. {
  1954. if ((data->flags ^ nfss->flags) & NFS_REMOUNT_CMP_FLAGMASK ||
  1955. data->rsize != nfss->rsize ||
  1956. data->wsize != nfss->wsize ||
  1957. data->version != nfss->nfs_client->rpc_ops->version ||
  1958. data->minorversion != nfss->nfs_client->cl_minorversion ||
  1959. data->retrans != nfss->client->cl_timeout->to_retries ||
  1960. data->selected_flavor != nfss->client->cl_auth->au_flavor ||
  1961. data->acregmin != nfss->acregmin / HZ ||
  1962. data->acregmax != nfss->acregmax / HZ ||
  1963. data->acdirmin != nfss->acdirmin / HZ ||
  1964. data->acdirmax != nfss->acdirmax / HZ ||
  1965. data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
  1966. data->nfs_server.port != nfss->port ||
  1967. data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
  1968. !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
  1969. (struct sockaddr *)&nfss->nfs_client->cl_addr))
  1970. return -EINVAL;
  1971. return 0;
  1972. }
  1973. int
  1974. nfs_remount(struct super_block *sb, int *flags, char *raw_data)
  1975. {
  1976. int error;
  1977. struct nfs_server *nfss = sb->s_fs_info;
  1978. struct nfs_parsed_mount_data *data;
  1979. struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
  1980. struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
  1981. u32 nfsvers = nfss->nfs_client->rpc_ops->version;
  1982. sync_filesystem(sb);
  1983. /*
  1984. * Userspace mount programs that send binary options generally send
  1985. * them populated with default values. We have no way to know which
  1986. * ones were explicitly specified. Fall back to legacy behavior and
  1987. * just return success.
  1988. */
  1989. if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
  1990. (nfsvers <= 3 && (!options || (options->version >= 1 &&
  1991. options->version <= 6))))
  1992. return 0;
  1993. data = kzalloc(sizeof(*data), GFP_KERNEL);
  1994. if (data == NULL)
  1995. return -ENOMEM;
  1996. /* fill out struct with values from existing mount */
  1997. data->flags = nfss->flags;
  1998. data->rsize = nfss->rsize;
  1999. data->wsize = nfss->wsize;
  2000. data->retrans = nfss->client->cl_timeout->to_retries;
  2001. data->selected_flavor = nfss->client->cl_auth->au_flavor;
  2002. data->auth_info = nfss->auth_info;
  2003. data->acregmin = nfss->acregmin / HZ;
  2004. data->acregmax = nfss->acregmax / HZ;
  2005. data->acdirmin = nfss->acdirmin / HZ;
  2006. data->acdirmax = nfss->acdirmax / HZ;
  2007. data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
  2008. data->nfs_server.port = nfss->port;
  2009. data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
  2010. data->version = nfsvers;
  2011. data->minorversion = nfss->nfs_client->cl_minorversion;
  2012. data->net = current->nsproxy->net_ns;
  2013. memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
  2014. data->nfs_server.addrlen);
  2015. /* overwrite those values with any that were specified */
  2016. error = -EINVAL;
  2017. if (!nfs_parse_mount_options((char *)options, data))
  2018. goto out;
  2019. /*
  2020. * noac is a special case. It implies -o sync, but that's not
  2021. * necessarily reflected in the mtab options. do_remount_sb
  2022. * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
  2023. * remount options, so we have to explicitly reset it.
  2024. */
  2025. if (data->flags & NFS_MOUNT_NOAC)
  2026. *flags |= MS_SYNCHRONOUS;
  2027. /* compare new mount options with old ones */
  2028. error = nfs_compare_remount_data(nfss, data);
  2029. out:
  2030. kfree(data);
  2031. return error;
  2032. }
  2033. EXPORT_SYMBOL_GPL(nfs_remount);
  2034. /*
  2035. * Initialise the common bits of the superblock
  2036. */
  2037. inline void nfs_initialise_sb(struct super_block *sb)
  2038. {
  2039. struct nfs_server *server = NFS_SB(sb);
  2040. sb->s_magic = NFS_SUPER_MAGIC;
  2041. /* We probably want something more informative here */
  2042. snprintf(sb->s_id, sizeof(sb->s_id),
  2043. "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
  2044. if (sb->s_blocksize == 0)
  2045. sb->s_blocksize = nfs_block_bits(server->wsize,
  2046. &sb->s_blocksize_bits);
  2047. sb->s_bdi = &server->backing_dev_info;
  2048. nfs_super_set_maxbytes(sb, server->maxfilesize);
  2049. }
  2050. /*
  2051. * Finish setting up an NFS2/3 superblock
  2052. */
  2053. void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
  2054. {
  2055. struct nfs_parsed_mount_data *data = mount_info->parsed;
  2056. struct nfs_server *server = NFS_SB(sb);
  2057. sb->s_blocksize_bits = 0;
  2058. sb->s_blocksize = 0;
  2059. sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
  2060. sb->s_op = server->nfs_client->cl_nfs_mod->sops;
  2061. if (data && data->bsize)
  2062. sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
  2063. if (server->nfs_client->rpc_ops->version != 2) {
  2064. /* The VFS shouldn't apply the umask to mode bits. We will do
  2065. * so ourselves when necessary.
  2066. */
  2067. sb->s_flags |= MS_POSIXACL;
  2068. sb->s_time_gran = 1;
  2069. }
  2070. nfs_initialise_sb(sb);
  2071. }
  2072. EXPORT_SYMBOL_GPL(nfs_fill_super);
  2073. /*
  2074. * Finish setting up a cloned NFS2/3/4 superblock
  2075. */
  2076. void nfs_clone_super(struct super_block *sb, struct nfs_mount_info *mount_info)
  2077. {
  2078. const struct super_block *old_sb = mount_info->cloned->sb;
  2079. struct nfs_server *server = NFS_SB(sb);
  2080. sb->s_blocksize_bits = old_sb->s_blocksize_bits;
  2081. sb->s_blocksize = old_sb->s_blocksize;
  2082. sb->s_maxbytes = old_sb->s_maxbytes;
  2083. sb->s_xattr = old_sb->s_xattr;
  2084. sb->s_op = old_sb->s_op;
  2085. sb->s_time_gran = 1;
  2086. if (server->nfs_client->rpc_ops->version != 2) {
  2087. /* The VFS shouldn't apply the umask to mode bits. We will do
  2088. * so ourselves when necessary.
  2089. */
  2090. sb->s_flags |= MS_POSIXACL;
  2091. }
  2092. nfs_initialise_sb(sb);
  2093. }
  2094. static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
  2095. {
  2096. const struct nfs_server *a = s->s_fs_info;
  2097. const struct rpc_clnt *clnt_a = a->client;
  2098. const struct rpc_clnt *clnt_b = b->client;
  2099. if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
  2100. goto Ebusy;
  2101. if (a->nfs_client != b->nfs_client)
  2102. goto Ebusy;
  2103. if ((a->flags ^ b->flags) & NFS_MOUNT_CMP_FLAGMASK)
  2104. goto Ebusy;
  2105. if (a->wsize != b->wsize)
  2106. goto Ebusy;
  2107. if (a->rsize != b->rsize)
  2108. goto Ebusy;
  2109. if (a->acregmin != b->acregmin)
  2110. goto Ebusy;
  2111. if (a->acregmax != b->acregmax)
  2112. goto Ebusy;
  2113. if (a->acdirmin != b->acdirmin)
  2114. goto Ebusy;
  2115. if (a->acdirmax != b->acdirmax)
  2116. goto Ebusy;
  2117. if (b->auth_info.flavor_len > 0 &&
  2118. clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
  2119. goto Ebusy;
  2120. return 1;
  2121. Ebusy:
  2122. return 0;
  2123. }
  2124. struct nfs_sb_mountdata {
  2125. struct nfs_server *server;
  2126. int mntflags;
  2127. };
  2128. static int nfs_set_super(struct super_block *s, void *data)
  2129. {
  2130. struct nfs_sb_mountdata *sb_mntdata = data;
  2131. struct nfs_server *server = sb_mntdata->server;
  2132. int ret;
  2133. s->s_flags = sb_mntdata->mntflags;
  2134. s->s_fs_info = server;
  2135. s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
  2136. ret = set_anon_super(s, server);
  2137. if (ret == 0)
  2138. server->s_dev = s->s_dev;
  2139. return ret;
  2140. }
  2141. static int nfs_compare_super_address(struct nfs_server *server1,
  2142. struct nfs_server *server2)
  2143. {
  2144. struct sockaddr *sap1, *sap2;
  2145. sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
  2146. sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
  2147. if (sap1->sa_family != sap2->sa_family)
  2148. return 0;
  2149. switch (sap1->sa_family) {
  2150. case AF_INET: {
  2151. struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
  2152. struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
  2153. if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
  2154. return 0;
  2155. if (sin1->sin_port != sin2->sin_port)
  2156. return 0;
  2157. break;
  2158. }
  2159. case AF_INET6: {
  2160. struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
  2161. struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
  2162. if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
  2163. return 0;
  2164. if (sin1->sin6_port != sin2->sin6_port)
  2165. return 0;
  2166. break;
  2167. }
  2168. default:
  2169. return 0;
  2170. }
  2171. return 1;
  2172. }
  2173. static int nfs_compare_super(struct super_block *sb, void *data)
  2174. {
  2175. struct nfs_sb_mountdata *sb_mntdata = data;
  2176. struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
  2177. int mntflags = sb_mntdata->mntflags;
  2178. if (!nfs_compare_super_address(old, server))
  2179. return 0;
  2180. /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
  2181. if (old->flags & NFS_MOUNT_UNSHARED)
  2182. return 0;
  2183. if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
  2184. return 0;
  2185. return nfs_compare_mount_options(sb, server, mntflags);
  2186. }
  2187. #ifdef CONFIG_NFS_FSCACHE
  2188. static void nfs_get_cache_cookie(struct super_block *sb,
  2189. struct nfs_parsed_mount_data *parsed,
  2190. struct nfs_clone_mount *cloned)
  2191. {
  2192. struct nfs_server *nfss = NFS_SB(sb);
  2193. char *uniq = NULL;
  2194. int ulen = 0;
  2195. nfss->fscache_key = NULL;
  2196. nfss->fscache = NULL;
  2197. if (parsed) {
  2198. if (!(parsed->options & NFS_OPTION_FSCACHE))
  2199. return;
  2200. if (parsed->fscache_uniq) {
  2201. uniq = parsed->fscache_uniq;
  2202. ulen = strlen(parsed->fscache_uniq);
  2203. }
  2204. } else if (cloned) {
  2205. struct nfs_server *mnt_s = NFS_SB(cloned->sb);
  2206. if (!(mnt_s->options & NFS_OPTION_FSCACHE))
  2207. return;
  2208. if (mnt_s->fscache_key) {
  2209. uniq = mnt_s->fscache_key->key.uniquifier;
  2210. ulen = mnt_s->fscache_key->key.uniq_len;
  2211. };
  2212. } else
  2213. return;
  2214. nfs_fscache_get_super_cookie(sb, uniq, ulen);
  2215. }
  2216. #else
  2217. static void nfs_get_cache_cookie(struct super_block *sb,
  2218. struct nfs_parsed_mount_data *parsed,
  2219. struct nfs_clone_mount *cloned)
  2220. {
  2221. }
  2222. #endif
  2223. static int nfs_bdi_register(struct nfs_server *server)
  2224. {
  2225. return bdi_register_dev(&server->backing_dev_info, server->s_dev);
  2226. }
  2227. int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
  2228. struct nfs_mount_info *mount_info)
  2229. {
  2230. int error;
  2231. unsigned long kflags = 0, kflags_out = 0;
  2232. if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL)
  2233. kflags |= SECURITY_LSM_NATIVE_LABELS;
  2234. error = security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts,
  2235. kflags, &kflags_out);
  2236. if (error)
  2237. goto err;
  2238. if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL &&
  2239. !(kflags_out & SECURITY_LSM_NATIVE_LABELS))
  2240. NFS_SB(s)->caps &= ~NFS_CAP_SECURITY_LABEL;
  2241. err:
  2242. return error;
  2243. }
  2244. EXPORT_SYMBOL_GPL(nfs_set_sb_security);
  2245. int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
  2246. struct nfs_mount_info *mount_info)
  2247. {
  2248. /* clone any lsm security options from the parent to the new sb */
  2249. if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
  2250. return -ESTALE;
  2251. return security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
  2252. }
  2253. EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
  2254. struct dentry *nfs_fs_mount_common(struct nfs_server *server,
  2255. int flags, const char *dev_name,
  2256. struct nfs_mount_info *mount_info,
  2257. struct nfs_subversion *nfs_mod)
  2258. {
  2259. struct super_block *s;
  2260. struct dentry *mntroot = ERR_PTR(-ENOMEM);
  2261. int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
  2262. struct nfs_sb_mountdata sb_mntdata = {
  2263. .mntflags = flags,
  2264. .server = server,
  2265. };
  2266. int error;
  2267. if (server->flags & NFS_MOUNT_UNSHARED)
  2268. compare_super = NULL;
  2269. /* -o noac implies -o sync */
  2270. if (server->flags & NFS_MOUNT_NOAC)
  2271. sb_mntdata.mntflags |= MS_SYNCHRONOUS;
  2272. if (mount_info->cloned != NULL && mount_info->cloned->sb != NULL)
  2273. if (mount_info->cloned->sb->s_flags & MS_SYNCHRONOUS)
  2274. sb_mntdata.mntflags |= MS_SYNCHRONOUS;
  2275. /* Get a superblock - note that we may end up sharing one that already exists */
  2276. s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
  2277. if (IS_ERR(s)) {
  2278. mntroot = ERR_CAST(s);
  2279. goto out_err_nosb;
  2280. }
  2281. if (s->s_fs_info != server) {
  2282. nfs_free_server(server);
  2283. server = NULL;
  2284. } else {
  2285. error = nfs_bdi_register(server);
  2286. if (error) {
  2287. mntroot = ERR_PTR(error);
  2288. goto error_splat_super;
  2289. }
  2290. server->super = s;
  2291. }
  2292. if (!s->s_root) {
  2293. /* initial superblock/root creation */
  2294. mount_info->fill_super(s, mount_info);
  2295. nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
  2296. }
  2297. mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
  2298. if (IS_ERR(mntroot))
  2299. goto error_splat_super;
  2300. error = mount_info->set_security(s, mntroot, mount_info);
  2301. if (error)
  2302. goto error_splat_root;
  2303. s->s_flags |= MS_ACTIVE;
  2304. out:
  2305. return mntroot;
  2306. out_err_nosb:
  2307. nfs_free_server(server);
  2308. goto out;
  2309. error_splat_root:
  2310. dput(mntroot);
  2311. mntroot = ERR_PTR(error);
  2312. error_splat_super:
  2313. deactivate_locked_super(s);
  2314. goto out;
  2315. }
  2316. EXPORT_SYMBOL_GPL(nfs_fs_mount_common);
  2317. struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
  2318. int flags, const char *dev_name, void *raw_data)
  2319. {
  2320. struct nfs_mount_info mount_info = {
  2321. .fill_super = nfs_fill_super,
  2322. .set_security = nfs_set_sb_security,
  2323. };
  2324. struct dentry *mntroot = ERR_PTR(-ENOMEM);
  2325. struct nfs_subversion *nfs_mod;
  2326. int error;
  2327. mount_info.parsed = nfs_alloc_parsed_mount_data();
  2328. mount_info.mntfh = nfs_alloc_fhandle();
  2329. if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
  2330. goto out;
  2331. /* Validate the mount data */
  2332. error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
  2333. if (error == NFS_TEXT_DATA)
  2334. error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
  2335. if (error < 0) {
  2336. mntroot = ERR_PTR(error);
  2337. goto out;
  2338. }
  2339. nfs_mod = get_nfs_version(mount_info.parsed->version);
  2340. if (IS_ERR(nfs_mod)) {
  2341. mntroot = ERR_CAST(nfs_mod);
  2342. goto out;
  2343. }
  2344. mntroot = nfs_mod->rpc_ops->try_mount(flags, dev_name, &mount_info, nfs_mod);
  2345. put_nfs_version(nfs_mod);
  2346. out:
  2347. nfs_free_parsed_mount_data(mount_info.parsed);
  2348. nfs_free_fhandle(mount_info.mntfh);
  2349. return mntroot;
  2350. }
  2351. EXPORT_SYMBOL_GPL(nfs_fs_mount);
  2352. /*
  2353. * Destroy an NFS2/3 superblock
  2354. */
  2355. void nfs_kill_super(struct super_block *s)
  2356. {
  2357. struct nfs_server *server = NFS_SB(s);
  2358. dev_t dev = s->s_dev;
  2359. generic_shutdown_super(s);
  2360. nfs_fscache_release_super_cookie(s);
  2361. nfs_free_server(server);
  2362. free_anon_bdev(dev);
  2363. }
  2364. EXPORT_SYMBOL_GPL(nfs_kill_super);
  2365. /*
  2366. * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
  2367. */
  2368. static struct dentry *
  2369. nfs_xdev_mount(struct file_system_type *fs_type, int flags,
  2370. const char *dev_name, void *raw_data)
  2371. {
  2372. struct nfs_clone_mount *data = raw_data;
  2373. struct nfs_mount_info mount_info = {
  2374. .fill_super = nfs_clone_super,
  2375. .set_security = nfs_clone_sb_security,
  2376. .cloned = data,
  2377. };
  2378. struct nfs_server *server;
  2379. struct dentry *mntroot = ERR_PTR(-ENOMEM);
  2380. struct nfs_subversion *nfs_mod = NFS_SB(data->sb)->nfs_client->cl_nfs_mod;
  2381. dprintk("--> nfs_xdev_mount()\n");
  2382. mount_info.mntfh = mount_info.cloned->fh;
  2383. /* create a new volume representation */
  2384. server = nfs_mod->rpc_ops->clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
  2385. if (IS_ERR(server))
  2386. mntroot = ERR_CAST(server);
  2387. else
  2388. mntroot = nfs_fs_mount_common(server, flags,
  2389. dev_name, &mount_info, nfs_mod);
  2390. dprintk("<-- nfs_xdev_mount() = %ld\n",
  2391. IS_ERR(mntroot) ? PTR_ERR(mntroot) : 0L);
  2392. return mntroot;
  2393. }
  2394. #if IS_ENABLED(CONFIG_NFS_V4)
  2395. static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
  2396. {
  2397. args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
  2398. NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
  2399. }
  2400. /*
  2401. * Validate NFSv4 mount options
  2402. */
  2403. static int nfs4_validate_mount_data(void *options,
  2404. struct nfs_parsed_mount_data *args,
  2405. const char *dev_name)
  2406. {
  2407. struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
  2408. struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
  2409. char *c;
  2410. if (data == NULL)
  2411. goto out_no_data;
  2412. args->version = 4;
  2413. switch (data->version) {
  2414. case 1:
  2415. if (data->host_addrlen > sizeof(args->nfs_server.address))
  2416. goto out_no_address;
  2417. if (data->host_addrlen == 0)
  2418. goto out_no_address;
  2419. args->nfs_server.addrlen = data->host_addrlen;
  2420. if (copy_from_user(sap, data->host_addr, data->host_addrlen))
  2421. return -EFAULT;
  2422. if (!nfs_verify_server_address(sap))
  2423. goto out_no_address;
  2424. args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
  2425. if (data->auth_flavourlen) {
  2426. rpc_authflavor_t pseudoflavor;
  2427. if (data->auth_flavourlen > 1)
  2428. goto out_inval_auth;
  2429. if (copy_from_user(&pseudoflavor,
  2430. data->auth_flavours,
  2431. sizeof(pseudoflavor)))
  2432. return -EFAULT;
  2433. args->selected_flavor = pseudoflavor;
  2434. } else
  2435. args->selected_flavor = RPC_AUTH_UNIX;
  2436. c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
  2437. if (IS_ERR(c))
  2438. return PTR_ERR(c);
  2439. args->nfs_server.hostname = c;
  2440. c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
  2441. if (IS_ERR(c))
  2442. return PTR_ERR(c);
  2443. args->nfs_server.export_path = c;
  2444. dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
  2445. c = strndup_user(data->client_addr.data, 16);
  2446. if (IS_ERR(c))
  2447. return PTR_ERR(c);
  2448. args->client_address = c;
  2449. /*
  2450. * Translate to nfs_parsed_mount_data, which nfs4_fill_super
  2451. * can deal with.
  2452. */
  2453. args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
  2454. args->rsize = data->rsize;
  2455. args->wsize = data->wsize;
  2456. args->timeo = data->timeo;
  2457. args->retrans = data->retrans;
  2458. args->acregmin = data->acregmin;
  2459. args->acregmax = data->acregmax;
  2460. args->acdirmin = data->acdirmin;
  2461. args->acdirmax = data->acdirmax;
  2462. args->nfs_server.protocol = data->proto;
  2463. nfs_validate_transport_protocol(args);
  2464. if (args->nfs_server.protocol == XPRT_TRANSPORT_UDP)
  2465. goto out_invalid_transport_udp;
  2466. break;
  2467. default:
  2468. return NFS_TEXT_DATA;
  2469. }
  2470. return 0;
  2471. out_no_data:
  2472. dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
  2473. return -EINVAL;
  2474. out_inval_auth:
  2475. dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
  2476. data->auth_flavourlen);
  2477. return -EINVAL;
  2478. out_no_address:
  2479. dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
  2480. return -EINVAL;
  2481. out_invalid_transport_udp:
  2482. dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
  2483. return -EINVAL;
  2484. }
  2485. /*
  2486. * NFS v4 module parameters need to stay in the
  2487. * NFS client for backwards compatibility
  2488. */
  2489. unsigned int nfs_callback_set_tcpport;
  2490. unsigned short nfs_callback_tcpport;
  2491. /* Default cache timeout is 10 minutes */
  2492. unsigned int nfs_idmap_cache_timeout = 600;
  2493. /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
  2494. bool nfs4_disable_idmapping = true;
  2495. unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
  2496. unsigned short send_implementation_id = 1;
  2497. char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
  2498. bool recover_lost_locks = false;
  2499. EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
  2500. EXPORT_SYMBOL_GPL(nfs_callback_tcpport);
  2501. EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
  2502. EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
  2503. EXPORT_SYMBOL_GPL(max_session_slots);
  2504. EXPORT_SYMBOL_GPL(send_implementation_id);
  2505. EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
  2506. EXPORT_SYMBOL_GPL(recover_lost_locks);
  2507. #define NFS_CALLBACK_MAXPORTNR (65535U)
  2508. static int param_set_portnr(const char *val, const struct kernel_param *kp)
  2509. {
  2510. unsigned long num;
  2511. int ret;
  2512. if (!val)
  2513. return -EINVAL;
  2514. ret = kstrtoul(val, 0, &num);
  2515. if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
  2516. return -EINVAL;
  2517. *((unsigned int *)kp->arg) = num;
  2518. return 0;
  2519. }
  2520. static struct kernel_param_ops param_ops_portnr = {
  2521. .set = param_set_portnr,
  2522. .get = param_get_uint,
  2523. };
  2524. #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
  2525. module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
  2526. module_param(nfs_idmap_cache_timeout, int, 0644);
  2527. module_param(nfs4_disable_idmapping, bool, 0644);
  2528. module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
  2529. NFS4_CLIENT_ID_UNIQ_LEN, 0600);
  2530. MODULE_PARM_DESC(nfs4_disable_idmapping,
  2531. "Turn off NFSv4 idmapping when using 'sec=sys'");
  2532. module_param(max_session_slots, ushort, 0644);
  2533. MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
  2534. "requests the client will negotiate");
  2535. module_param(send_implementation_id, ushort, 0644);
  2536. MODULE_PARM_DESC(send_implementation_id,
  2537. "Send implementation ID with NFSv4.1 exchange_id");
  2538. MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
  2539. module_param(recover_lost_locks, bool, 0644);
  2540. MODULE_PARM_DESC(recover_lost_locks,
  2541. "If the server reports that a lock might be lost, "
  2542. "try to recover it risking data corruption.");
  2543. #endif /* CONFIG_NFS_V4 */