namespace.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. /*
  2. * linux/fs/namespace.c
  3. *
  4. * (C) Copyright Al Viro 2000, 2001
  5. * Released under GPL v2.
  6. *
  7. * Based on code from fs/super.c, copyright Linus Torvalds and others.
  8. * Heavily rewritten.
  9. */
  10. #include <linux/syscalls.h>
  11. #include <linux/slab.h>
  12. #include <linux/sched.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/quotaops.h>
  17. #include <linux/acct.h>
  18. #include <linux/capability.h>
  19. #include <linux/module.h>
  20. #include <linux/sysfs.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/mnt_namespace.h>
  23. #include <linux/namei.h>
  24. #include <linux/security.h>
  25. #include <linux/mount.h>
  26. #include <linux/ramfs.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/unistd.h>
  29. #include "pnode.h"
  30. #include "internal.h"
  31. /* spinlock for vfsmount related operations, inplace of dcache_lock */
  32. __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
  33. static int event;
  34. static struct list_head *mount_hashtable __read_mostly;
  35. static int hash_mask __read_mostly, hash_bits __read_mostly;
  36. static struct kmem_cache *mnt_cache __read_mostly;
  37. static struct rw_semaphore namespace_sem;
  38. /* /sys/fs */
  39. decl_subsys(fs, NULL, NULL);
  40. EXPORT_SYMBOL_GPL(fs_subsys);
  41. static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
  42. {
  43. unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
  44. tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
  45. tmp = tmp + (tmp >> hash_bits);
  46. return tmp & hash_mask;
  47. }
  48. struct vfsmount *alloc_vfsmnt(const char *name)
  49. {
  50. struct vfsmount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
  51. if (mnt) {
  52. atomic_set(&mnt->mnt_count, 1);
  53. INIT_LIST_HEAD(&mnt->mnt_hash);
  54. INIT_LIST_HEAD(&mnt->mnt_child);
  55. INIT_LIST_HEAD(&mnt->mnt_mounts);
  56. INIT_LIST_HEAD(&mnt->mnt_list);
  57. INIT_LIST_HEAD(&mnt->mnt_expire);
  58. INIT_LIST_HEAD(&mnt->mnt_share);
  59. INIT_LIST_HEAD(&mnt->mnt_slave_list);
  60. INIT_LIST_HEAD(&mnt->mnt_slave);
  61. if (name) {
  62. int size = strlen(name) + 1;
  63. char *newname = kmalloc(size, GFP_KERNEL);
  64. if (newname) {
  65. memcpy(newname, name, size);
  66. mnt->mnt_devname = newname;
  67. }
  68. }
  69. }
  70. return mnt;
  71. }
  72. int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
  73. {
  74. mnt->mnt_sb = sb;
  75. mnt->mnt_root = dget(sb->s_root);
  76. return 0;
  77. }
  78. EXPORT_SYMBOL(simple_set_mnt);
  79. void free_vfsmnt(struct vfsmount *mnt)
  80. {
  81. kfree(mnt->mnt_devname);
  82. kmem_cache_free(mnt_cache, mnt);
  83. }
  84. /*
  85. * find the first or last mount at @dentry on vfsmount @mnt depending on
  86. * @dir. If @dir is set return the first mount else return the last mount.
  87. */
  88. struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry,
  89. int dir)
  90. {
  91. struct list_head *head = mount_hashtable + hash(mnt, dentry);
  92. struct list_head *tmp = head;
  93. struct vfsmount *p, *found = NULL;
  94. for (;;) {
  95. tmp = dir ? tmp->next : tmp->prev;
  96. p = NULL;
  97. if (tmp == head)
  98. break;
  99. p = list_entry(tmp, struct vfsmount, mnt_hash);
  100. if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) {
  101. found = p;
  102. break;
  103. }
  104. }
  105. return found;
  106. }
  107. /*
  108. * lookup_mnt increments the ref count before returning
  109. * the vfsmount struct.
  110. */
  111. struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
  112. {
  113. struct vfsmount *child_mnt;
  114. spin_lock(&vfsmount_lock);
  115. if ((child_mnt = __lookup_mnt(mnt, dentry, 1)))
  116. mntget(child_mnt);
  117. spin_unlock(&vfsmount_lock);
  118. return child_mnt;
  119. }
  120. static inline int check_mnt(struct vfsmount *mnt)
  121. {
  122. return mnt->mnt_ns == current->nsproxy->mnt_ns;
  123. }
  124. static void touch_mnt_namespace(struct mnt_namespace *ns)
  125. {
  126. if (ns) {
  127. ns->event = ++event;
  128. wake_up_interruptible(&ns->poll);
  129. }
  130. }
  131. static void __touch_mnt_namespace(struct mnt_namespace *ns)
  132. {
  133. if (ns && ns->event != event) {
  134. ns->event = event;
  135. wake_up_interruptible(&ns->poll);
  136. }
  137. }
  138. static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd)
  139. {
  140. old_nd->dentry = mnt->mnt_mountpoint;
  141. old_nd->mnt = mnt->mnt_parent;
  142. mnt->mnt_parent = mnt;
  143. mnt->mnt_mountpoint = mnt->mnt_root;
  144. list_del_init(&mnt->mnt_child);
  145. list_del_init(&mnt->mnt_hash);
  146. old_nd->dentry->d_mounted--;
  147. }
  148. void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
  149. struct vfsmount *child_mnt)
  150. {
  151. child_mnt->mnt_parent = mntget(mnt);
  152. child_mnt->mnt_mountpoint = dget(dentry);
  153. dentry->d_mounted++;
  154. }
  155. static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd)
  156. {
  157. mnt_set_mountpoint(nd->mnt, nd->dentry, mnt);
  158. list_add_tail(&mnt->mnt_hash, mount_hashtable +
  159. hash(nd->mnt, nd->dentry));
  160. list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts);
  161. }
  162. /*
  163. * the caller must hold vfsmount_lock
  164. */
  165. static void commit_tree(struct vfsmount *mnt)
  166. {
  167. struct vfsmount *parent = mnt->mnt_parent;
  168. struct vfsmount *m;
  169. LIST_HEAD(head);
  170. struct mnt_namespace *n = parent->mnt_ns;
  171. BUG_ON(parent == mnt);
  172. list_add_tail(&head, &mnt->mnt_list);
  173. list_for_each_entry(m, &head, mnt_list)
  174. m->mnt_ns = n;
  175. list_splice(&head, n->list.prev);
  176. list_add_tail(&mnt->mnt_hash, mount_hashtable +
  177. hash(parent, mnt->mnt_mountpoint));
  178. list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
  179. touch_mnt_namespace(n);
  180. }
  181. static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
  182. {
  183. struct list_head *next = p->mnt_mounts.next;
  184. if (next == &p->mnt_mounts) {
  185. while (1) {
  186. if (p == root)
  187. return NULL;
  188. next = p->mnt_child.next;
  189. if (next != &p->mnt_parent->mnt_mounts)
  190. break;
  191. p = p->mnt_parent;
  192. }
  193. }
  194. return list_entry(next, struct vfsmount, mnt_child);
  195. }
  196. static struct vfsmount *skip_mnt_tree(struct vfsmount *p)
  197. {
  198. struct list_head *prev = p->mnt_mounts.prev;
  199. while (prev != &p->mnt_mounts) {
  200. p = list_entry(prev, struct vfsmount, mnt_child);
  201. prev = p->mnt_mounts.prev;
  202. }
  203. return p;
  204. }
  205. static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
  206. int flag)
  207. {
  208. struct super_block *sb = old->mnt_sb;
  209. struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
  210. if (mnt) {
  211. mnt->mnt_flags = old->mnt_flags;
  212. atomic_inc(&sb->s_active);
  213. mnt->mnt_sb = sb;
  214. mnt->mnt_root = dget(root);
  215. mnt->mnt_mountpoint = mnt->mnt_root;
  216. mnt->mnt_parent = mnt;
  217. if (flag & CL_SLAVE) {
  218. list_add(&mnt->mnt_slave, &old->mnt_slave_list);
  219. mnt->mnt_master = old;
  220. CLEAR_MNT_SHARED(mnt);
  221. } else {
  222. if ((flag & CL_PROPAGATION) || IS_MNT_SHARED(old))
  223. list_add(&mnt->mnt_share, &old->mnt_share);
  224. if (IS_MNT_SLAVE(old))
  225. list_add(&mnt->mnt_slave, &old->mnt_slave);
  226. mnt->mnt_master = old->mnt_master;
  227. }
  228. if (flag & CL_MAKE_SHARED)
  229. set_mnt_shared(mnt);
  230. /* stick the duplicate mount on the same expiry list
  231. * as the original if that was on one */
  232. if (flag & CL_EXPIRE) {
  233. spin_lock(&vfsmount_lock);
  234. if (!list_empty(&old->mnt_expire))
  235. list_add(&mnt->mnt_expire, &old->mnt_expire);
  236. spin_unlock(&vfsmount_lock);
  237. }
  238. }
  239. return mnt;
  240. }
  241. static inline void __mntput(struct vfsmount *mnt)
  242. {
  243. struct super_block *sb = mnt->mnt_sb;
  244. dput(mnt->mnt_root);
  245. free_vfsmnt(mnt);
  246. deactivate_super(sb);
  247. }
  248. void mntput_no_expire(struct vfsmount *mnt)
  249. {
  250. repeat:
  251. if (atomic_dec_and_lock(&mnt->mnt_count, &vfsmount_lock)) {
  252. if (likely(!mnt->mnt_pinned)) {
  253. spin_unlock(&vfsmount_lock);
  254. __mntput(mnt);
  255. return;
  256. }
  257. atomic_add(mnt->mnt_pinned + 1, &mnt->mnt_count);
  258. mnt->mnt_pinned = 0;
  259. spin_unlock(&vfsmount_lock);
  260. acct_auto_close_mnt(mnt);
  261. security_sb_umount_close(mnt);
  262. goto repeat;
  263. }
  264. }
  265. EXPORT_SYMBOL(mntput_no_expire);
  266. void mnt_pin(struct vfsmount *mnt)
  267. {
  268. spin_lock(&vfsmount_lock);
  269. mnt->mnt_pinned++;
  270. spin_unlock(&vfsmount_lock);
  271. }
  272. EXPORT_SYMBOL(mnt_pin);
  273. void mnt_unpin(struct vfsmount *mnt)
  274. {
  275. spin_lock(&vfsmount_lock);
  276. if (mnt->mnt_pinned) {
  277. atomic_inc(&mnt->mnt_count);
  278. mnt->mnt_pinned--;
  279. }
  280. spin_unlock(&vfsmount_lock);
  281. }
  282. EXPORT_SYMBOL(mnt_unpin);
  283. /* iterator */
  284. static void *m_start(struct seq_file *m, loff_t *pos)
  285. {
  286. struct mnt_namespace *n = m->private;
  287. down_read(&namespace_sem);
  288. return seq_list_start(&n->list, *pos);
  289. }
  290. static void *m_next(struct seq_file *m, void *v, loff_t *pos)
  291. {
  292. struct mnt_namespace *n = m->private;
  293. return seq_list_next(v, &n->list, pos);
  294. }
  295. static void m_stop(struct seq_file *m, void *v)
  296. {
  297. up_read(&namespace_sem);
  298. }
  299. static inline void mangle(struct seq_file *m, const char *s)
  300. {
  301. seq_escape(m, s, " \t\n\\");
  302. }
  303. static int show_vfsmnt(struct seq_file *m, void *v)
  304. {
  305. struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
  306. int err = 0;
  307. static struct proc_fs_info {
  308. int flag;
  309. char *str;
  310. } fs_info[] = {
  311. { MS_SYNCHRONOUS, ",sync" },
  312. { MS_DIRSYNC, ",dirsync" },
  313. { MS_MANDLOCK, ",mand" },
  314. { 0, NULL }
  315. };
  316. static struct proc_fs_info mnt_info[] = {
  317. { MNT_NOSUID, ",nosuid" },
  318. { MNT_NODEV, ",nodev" },
  319. { MNT_NOEXEC, ",noexec" },
  320. { MNT_NOATIME, ",noatime" },
  321. { MNT_NODIRATIME, ",nodiratime" },
  322. { MNT_RELATIME, ",relatime" },
  323. { 0, NULL }
  324. };
  325. struct proc_fs_info *fs_infop;
  326. mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
  327. seq_putc(m, ' ');
  328. seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
  329. seq_putc(m, ' ');
  330. mangle(m, mnt->mnt_sb->s_type->name);
  331. if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
  332. seq_putc(m, '.');
  333. mangle(m, mnt->mnt_sb->s_subtype);
  334. }
  335. seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
  336. for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
  337. if (mnt->mnt_sb->s_flags & fs_infop->flag)
  338. seq_puts(m, fs_infop->str);
  339. }
  340. for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
  341. if (mnt->mnt_flags & fs_infop->flag)
  342. seq_puts(m, fs_infop->str);
  343. }
  344. if (mnt->mnt_sb->s_op->show_options)
  345. err = mnt->mnt_sb->s_op->show_options(m, mnt);
  346. seq_puts(m, " 0 0\n");
  347. return err;
  348. }
  349. struct seq_operations mounts_op = {
  350. .start = m_start,
  351. .next = m_next,
  352. .stop = m_stop,
  353. .show = show_vfsmnt
  354. };
  355. static int show_vfsstat(struct seq_file *m, void *v)
  356. {
  357. struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
  358. int err = 0;
  359. /* device */
  360. if (mnt->mnt_devname) {
  361. seq_puts(m, "device ");
  362. mangle(m, mnt->mnt_devname);
  363. } else
  364. seq_puts(m, "no device");
  365. /* mount point */
  366. seq_puts(m, " mounted on ");
  367. seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
  368. seq_putc(m, ' ');
  369. /* file system type */
  370. seq_puts(m, "with fstype ");
  371. mangle(m, mnt->mnt_sb->s_type->name);
  372. /* optional statistics */
  373. if (mnt->mnt_sb->s_op->show_stats) {
  374. seq_putc(m, ' ');
  375. err = mnt->mnt_sb->s_op->show_stats(m, mnt);
  376. }
  377. seq_putc(m, '\n');
  378. return err;
  379. }
  380. struct seq_operations mountstats_op = {
  381. .start = m_start,
  382. .next = m_next,
  383. .stop = m_stop,
  384. .show = show_vfsstat,
  385. };
  386. /**
  387. * may_umount_tree - check if a mount tree is busy
  388. * @mnt: root of mount tree
  389. *
  390. * This is called to check if a tree of mounts has any
  391. * open files, pwds, chroots or sub mounts that are
  392. * busy.
  393. */
  394. int may_umount_tree(struct vfsmount *mnt)
  395. {
  396. int actual_refs = 0;
  397. int minimum_refs = 0;
  398. struct vfsmount *p;
  399. spin_lock(&vfsmount_lock);
  400. for (p = mnt; p; p = next_mnt(p, mnt)) {
  401. actual_refs += atomic_read(&p->mnt_count);
  402. minimum_refs += 2;
  403. }
  404. spin_unlock(&vfsmount_lock);
  405. if (actual_refs > minimum_refs)
  406. return 0;
  407. return 1;
  408. }
  409. EXPORT_SYMBOL(may_umount_tree);
  410. /**
  411. * may_umount - check if a mount point is busy
  412. * @mnt: root of mount
  413. *
  414. * This is called to check if a mount point has any
  415. * open files, pwds, chroots or sub mounts. If the
  416. * mount has sub mounts this will return busy
  417. * regardless of whether the sub mounts are busy.
  418. *
  419. * Doesn't take quota and stuff into account. IOW, in some cases it will
  420. * give false negatives. The main reason why it's here is that we need
  421. * a non-destructive way to look for easily umountable filesystems.
  422. */
  423. int may_umount(struct vfsmount *mnt)
  424. {
  425. int ret = 1;
  426. spin_lock(&vfsmount_lock);
  427. if (propagate_mount_busy(mnt, 2))
  428. ret = 0;
  429. spin_unlock(&vfsmount_lock);
  430. return ret;
  431. }
  432. EXPORT_SYMBOL(may_umount);
  433. void release_mounts(struct list_head *head)
  434. {
  435. struct vfsmount *mnt;
  436. while (!list_empty(head)) {
  437. mnt = list_first_entry(head, struct vfsmount, mnt_hash);
  438. list_del_init(&mnt->mnt_hash);
  439. if (mnt->mnt_parent != mnt) {
  440. struct dentry *dentry;
  441. struct vfsmount *m;
  442. spin_lock(&vfsmount_lock);
  443. dentry = mnt->mnt_mountpoint;
  444. m = mnt->mnt_parent;
  445. mnt->mnt_mountpoint = mnt->mnt_root;
  446. mnt->mnt_parent = mnt;
  447. spin_unlock(&vfsmount_lock);
  448. dput(dentry);
  449. mntput(m);
  450. }
  451. mntput(mnt);
  452. }
  453. }
  454. void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
  455. {
  456. struct vfsmount *p;
  457. for (p = mnt; p; p = next_mnt(p, mnt))
  458. list_move(&p->mnt_hash, kill);
  459. if (propagate)
  460. propagate_umount(kill);
  461. list_for_each_entry(p, kill, mnt_hash) {
  462. list_del_init(&p->mnt_expire);
  463. list_del_init(&p->mnt_list);
  464. __touch_mnt_namespace(p->mnt_ns);
  465. p->mnt_ns = NULL;
  466. list_del_init(&p->mnt_child);
  467. if (p->mnt_parent != p)
  468. p->mnt_mountpoint->d_mounted--;
  469. change_mnt_propagation(p, MS_PRIVATE);
  470. }
  471. }
  472. static int do_umount(struct vfsmount *mnt, int flags)
  473. {
  474. struct super_block *sb = mnt->mnt_sb;
  475. int retval;
  476. LIST_HEAD(umount_list);
  477. retval = security_sb_umount(mnt, flags);
  478. if (retval)
  479. return retval;
  480. /*
  481. * Allow userspace to request a mountpoint be expired rather than
  482. * unmounting unconditionally. Unmount only happens if:
  483. * (1) the mark is already set (the mark is cleared by mntput())
  484. * (2) the usage count == 1 [parent vfsmount] + 1 [sys_umount]
  485. */
  486. if (flags & MNT_EXPIRE) {
  487. if (mnt == current->fs->rootmnt ||
  488. flags & (MNT_FORCE | MNT_DETACH))
  489. return -EINVAL;
  490. if (atomic_read(&mnt->mnt_count) != 2)
  491. return -EBUSY;
  492. if (!xchg(&mnt->mnt_expiry_mark, 1))
  493. return -EAGAIN;
  494. }
  495. /*
  496. * If we may have to abort operations to get out of this
  497. * mount, and they will themselves hold resources we must
  498. * allow the fs to do things. In the Unix tradition of
  499. * 'Gee thats tricky lets do it in userspace' the umount_begin
  500. * might fail to complete on the first run through as other tasks
  501. * must return, and the like. Thats for the mount program to worry
  502. * about for the moment.
  503. */
  504. lock_kernel();
  505. if (sb->s_op->umount_begin)
  506. sb->s_op->umount_begin(mnt, flags);
  507. unlock_kernel();
  508. /*
  509. * No sense to grab the lock for this test, but test itself looks
  510. * somewhat bogus. Suggestions for better replacement?
  511. * Ho-hum... In principle, we might treat that as umount + switch
  512. * to rootfs. GC would eventually take care of the old vfsmount.
  513. * Actually it makes sense, especially if rootfs would contain a
  514. * /reboot - static binary that would close all descriptors and
  515. * call reboot(9). Then init(8) could umount root and exec /reboot.
  516. */
  517. if (mnt == current->fs->rootmnt && !(flags & MNT_DETACH)) {
  518. /*
  519. * Special case for "unmounting" root ...
  520. * we just try to remount it readonly.
  521. */
  522. down_write(&sb->s_umount);
  523. if (!(sb->s_flags & MS_RDONLY)) {
  524. lock_kernel();
  525. DQUOT_OFF(sb);
  526. retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
  527. unlock_kernel();
  528. }
  529. up_write(&sb->s_umount);
  530. return retval;
  531. }
  532. down_write(&namespace_sem);
  533. spin_lock(&vfsmount_lock);
  534. event++;
  535. retval = -EBUSY;
  536. if (flags & MNT_DETACH || !propagate_mount_busy(mnt, 2)) {
  537. if (!list_empty(&mnt->mnt_list))
  538. umount_tree(mnt, 1, &umount_list);
  539. retval = 0;
  540. }
  541. spin_unlock(&vfsmount_lock);
  542. if (retval)
  543. security_sb_umount_busy(mnt);
  544. up_write(&namespace_sem);
  545. release_mounts(&umount_list);
  546. return retval;
  547. }
  548. /*
  549. * Now umount can handle mount points as well as block devices.
  550. * This is important for filesystems which use unnamed block devices.
  551. *
  552. * We now support a flag for forced unmount like the other 'big iron'
  553. * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
  554. */
  555. asmlinkage long sys_umount(char __user * name, int flags)
  556. {
  557. struct nameidata nd;
  558. int retval;
  559. retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
  560. if (retval)
  561. goto out;
  562. retval = -EINVAL;
  563. if (nd.dentry != nd.mnt->mnt_root)
  564. goto dput_and_out;
  565. if (!check_mnt(nd.mnt))
  566. goto dput_and_out;
  567. retval = -EPERM;
  568. if (!capable(CAP_SYS_ADMIN))
  569. goto dput_and_out;
  570. retval = do_umount(nd.mnt, flags);
  571. dput_and_out:
  572. path_release_on_umount(&nd);
  573. out:
  574. return retval;
  575. }
  576. #ifdef __ARCH_WANT_SYS_OLDUMOUNT
  577. /*
  578. * The 2.0 compatible umount. No flags.
  579. */
  580. asmlinkage long sys_oldumount(char __user * name)
  581. {
  582. return sys_umount(name, 0);
  583. }
  584. #endif
  585. static int mount_is_safe(struct nameidata *nd)
  586. {
  587. if (capable(CAP_SYS_ADMIN))
  588. return 0;
  589. return -EPERM;
  590. #ifdef notyet
  591. if (S_ISLNK(nd->dentry->d_inode->i_mode))
  592. return -EPERM;
  593. if (nd->dentry->d_inode->i_mode & S_ISVTX) {
  594. if (current->uid != nd->dentry->d_inode->i_uid)
  595. return -EPERM;
  596. }
  597. if (vfs_permission(nd, MAY_WRITE))
  598. return -EPERM;
  599. return 0;
  600. #endif
  601. }
  602. static int lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
  603. {
  604. while (1) {
  605. if (d == dentry)
  606. return 1;
  607. if (d == NULL || d == d->d_parent)
  608. return 0;
  609. d = d->d_parent;
  610. }
  611. }
  612. struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
  613. int flag)
  614. {
  615. struct vfsmount *res, *p, *q, *r, *s;
  616. struct nameidata nd;
  617. if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
  618. return NULL;
  619. res = q = clone_mnt(mnt, dentry, flag);
  620. if (!q)
  621. goto Enomem;
  622. q->mnt_mountpoint = mnt->mnt_mountpoint;
  623. p = mnt;
  624. list_for_each_entry(r, &mnt->mnt_mounts, mnt_child) {
  625. if (!lives_below_in_same_fs(r->mnt_mountpoint, dentry))
  626. continue;
  627. for (s = r; s; s = next_mnt(s, r)) {
  628. if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(s)) {
  629. s = skip_mnt_tree(s);
  630. continue;
  631. }
  632. while (p != s->mnt_parent) {
  633. p = p->mnt_parent;
  634. q = q->mnt_parent;
  635. }
  636. p = s;
  637. nd.mnt = q;
  638. nd.dentry = p->mnt_mountpoint;
  639. q = clone_mnt(p, p->mnt_root, flag);
  640. if (!q)
  641. goto Enomem;
  642. spin_lock(&vfsmount_lock);
  643. list_add_tail(&q->mnt_list, &res->mnt_list);
  644. attach_mnt(q, &nd);
  645. spin_unlock(&vfsmount_lock);
  646. }
  647. }
  648. return res;
  649. Enomem:
  650. if (res) {
  651. LIST_HEAD(umount_list);
  652. spin_lock(&vfsmount_lock);
  653. umount_tree(res, 0, &umount_list);
  654. spin_unlock(&vfsmount_lock);
  655. release_mounts(&umount_list);
  656. }
  657. return NULL;
  658. }
  659. /*
  660. * @source_mnt : mount tree to be attached
  661. * @nd : place the mount tree @source_mnt is attached
  662. * @parent_nd : if non-null, detach the source_mnt from its parent and
  663. * store the parent mount and mountpoint dentry.
  664. * (done when source_mnt is moved)
  665. *
  666. * NOTE: in the table below explains the semantics when a source mount
  667. * of a given type is attached to a destination mount of a given type.
  668. * ---------------------------------------------------------------------------
  669. * | BIND MOUNT OPERATION |
  670. * |**************************************************************************
  671. * | source-->| shared | private | slave | unbindable |
  672. * | dest | | | | |
  673. * | | | | | | |
  674. * | v | | | | |
  675. * |**************************************************************************
  676. * | shared | shared (++) | shared (+) | shared(+++)| invalid |
  677. * | | | | | |
  678. * |non-shared| shared (+) | private | slave (*) | invalid |
  679. * ***************************************************************************
  680. * A bind operation clones the source mount and mounts the clone on the
  681. * destination mount.
  682. *
  683. * (++) the cloned mount is propagated to all the mounts in the propagation
  684. * tree of the destination mount and the cloned mount is added to
  685. * the peer group of the source mount.
  686. * (+) the cloned mount is created under the destination mount and is marked
  687. * as shared. The cloned mount is added to the peer group of the source
  688. * mount.
  689. * (+++) the mount is propagated to all the mounts in the propagation tree
  690. * of the destination mount and the cloned mount is made slave
  691. * of the same master as that of the source mount. The cloned mount
  692. * is marked as 'shared and slave'.
  693. * (*) the cloned mount is made a slave of the same master as that of the
  694. * source mount.
  695. *
  696. * ---------------------------------------------------------------------------
  697. * | MOVE MOUNT OPERATION |
  698. * |**************************************************************************
  699. * | source-->| shared | private | slave | unbindable |
  700. * | dest | | | | |
  701. * | | | | | | |
  702. * | v | | | | |
  703. * |**************************************************************************
  704. * | shared | shared (+) | shared (+) | shared(+++) | invalid |
  705. * | | | | | |
  706. * |non-shared| shared (+*) | private | slave (*) | unbindable |
  707. * ***************************************************************************
  708. *
  709. * (+) the mount is moved to the destination. And is then propagated to
  710. * all the mounts in the propagation tree of the destination mount.
  711. * (+*) the mount is moved to the destination.
  712. * (+++) the mount is moved to the destination and is then propagated to
  713. * all the mounts belonging to the destination mount's propagation tree.
  714. * the mount is marked as 'shared and slave'.
  715. * (*) the mount continues to be a slave at the new location.
  716. *
  717. * if the source mount is a tree, the operations explained above is
  718. * applied to each mount in the tree.
  719. * Must be called without spinlocks held, since this function can sleep
  720. * in allocations.
  721. */
  722. static int attach_recursive_mnt(struct vfsmount *source_mnt,
  723. struct nameidata *nd, struct nameidata *parent_nd)
  724. {
  725. LIST_HEAD(tree_list);
  726. struct vfsmount *dest_mnt = nd->mnt;
  727. struct dentry *dest_dentry = nd->dentry;
  728. struct vfsmount *child, *p;
  729. if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list))
  730. return -EINVAL;
  731. if (IS_MNT_SHARED(dest_mnt)) {
  732. for (p = source_mnt; p; p = next_mnt(p, source_mnt))
  733. set_mnt_shared(p);
  734. }
  735. spin_lock(&vfsmount_lock);
  736. if (parent_nd) {
  737. detach_mnt(source_mnt, parent_nd);
  738. attach_mnt(source_mnt, nd);
  739. touch_mnt_namespace(current->nsproxy->mnt_ns);
  740. } else {
  741. mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
  742. commit_tree(source_mnt);
  743. }
  744. list_for_each_entry_safe(child, p, &tree_list, mnt_hash) {
  745. list_del_init(&child->mnt_hash);
  746. commit_tree(child);
  747. }
  748. spin_unlock(&vfsmount_lock);
  749. return 0;
  750. }
  751. static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
  752. {
  753. int err;
  754. if (mnt->mnt_sb->s_flags & MS_NOUSER)
  755. return -EINVAL;
  756. if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
  757. S_ISDIR(mnt->mnt_root->d_inode->i_mode))
  758. return -ENOTDIR;
  759. err = -ENOENT;
  760. mutex_lock(&nd->dentry->d_inode->i_mutex);
  761. if (IS_DEADDIR(nd->dentry->d_inode))
  762. goto out_unlock;
  763. err = security_sb_check_sb(mnt, nd);
  764. if (err)
  765. goto out_unlock;
  766. err = -ENOENT;
  767. if (IS_ROOT(nd->dentry) || !d_unhashed(nd->dentry))
  768. err = attach_recursive_mnt(mnt, nd, NULL);
  769. out_unlock:
  770. mutex_unlock(&nd->dentry->d_inode->i_mutex);
  771. if (!err)
  772. security_sb_post_addmount(mnt, nd);
  773. return err;
  774. }
  775. /*
  776. * recursively change the type of the mountpoint.
  777. */
  778. static int do_change_type(struct nameidata *nd, int flag)
  779. {
  780. struct vfsmount *m, *mnt = nd->mnt;
  781. int recurse = flag & MS_REC;
  782. int type = flag & ~MS_REC;
  783. if (!capable(CAP_SYS_ADMIN))
  784. return -EPERM;
  785. if (nd->dentry != nd->mnt->mnt_root)
  786. return -EINVAL;
  787. down_write(&namespace_sem);
  788. spin_lock(&vfsmount_lock);
  789. for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
  790. change_mnt_propagation(m, type);
  791. spin_unlock(&vfsmount_lock);
  792. up_write(&namespace_sem);
  793. return 0;
  794. }
  795. /*
  796. * do loopback mount.
  797. */
  798. static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
  799. {
  800. struct nameidata old_nd;
  801. struct vfsmount *mnt = NULL;
  802. int err = mount_is_safe(nd);
  803. if (err)
  804. return err;
  805. if (!old_name || !*old_name)
  806. return -EINVAL;
  807. err = path_lookup(old_name, LOOKUP_FOLLOW, &old_nd);
  808. if (err)
  809. return err;
  810. down_write(&namespace_sem);
  811. err = -EINVAL;
  812. if (IS_MNT_UNBINDABLE(old_nd.mnt))
  813. goto out;
  814. if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
  815. goto out;
  816. err = -ENOMEM;
  817. if (recurse)
  818. mnt = copy_tree(old_nd.mnt, old_nd.dentry, 0);
  819. else
  820. mnt = clone_mnt(old_nd.mnt, old_nd.dentry, 0);
  821. if (!mnt)
  822. goto out;
  823. err = graft_tree(mnt, nd);
  824. if (err) {
  825. LIST_HEAD(umount_list);
  826. spin_lock(&vfsmount_lock);
  827. umount_tree(mnt, 0, &umount_list);
  828. spin_unlock(&vfsmount_lock);
  829. release_mounts(&umount_list);
  830. }
  831. out:
  832. up_write(&namespace_sem);
  833. path_release(&old_nd);
  834. return err;
  835. }
  836. /*
  837. * change filesystem flags. dir should be a physical root of filesystem.
  838. * If you've mounted a non-root directory somewhere and want to do remount
  839. * on it - tough luck.
  840. */
  841. static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
  842. void *data)
  843. {
  844. int err;
  845. struct super_block *sb = nd->mnt->mnt_sb;
  846. if (!capable(CAP_SYS_ADMIN))
  847. return -EPERM;
  848. if (!check_mnt(nd->mnt))
  849. return -EINVAL;
  850. if (nd->dentry != nd->mnt->mnt_root)
  851. return -EINVAL;
  852. down_write(&sb->s_umount);
  853. err = do_remount_sb(sb, flags, data, 0);
  854. if (!err)
  855. nd->mnt->mnt_flags = mnt_flags;
  856. up_write(&sb->s_umount);
  857. if (!err)
  858. security_sb_post_remount(nd->mnt, flags, data);
  859. return err;
  860. }
  861. static inline int tree_contains_unbindable(struct vfsmount *mnt)
  862. {
  863. struct vfsmount *p;
  864. for (p = mnt; p; p = next_mnt(p, mnt)) {
  865. if (IS_MNT_UNBINDABLE(p))
  866. return 1;
  867. }
  868. return 0;
  869. }
  870. static int do_move_mount(struct nameidata *nd, char *old_name)
  871. {
  872. struct nameidata old_nd, parent_nd;
  873. struct vfsmount *p;
  874. int err = 0;
  875. if (!capable(CAP_SYS_ADMIN))
  876. return -EPERM;
  877. if (!old_name || !*old_name)
  878. return -EINVAL;
  879. err = path_lookup(old_name, LOOKUP_FOLLOW, &old_nd);
  880. if (err)
  881. return err;
  882. down_write(&namespace_sem);
  883. while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
  884. ;
  885. err = -EINVAL;
  886. if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
  887. goto out;
  888. err = -ENOENT;
  889. mutex_lock(&nd->dentry->d_inode->i_mutex);
  890. if (IS_DEADDIR(nd->dentry->d_inode))
  891. goto out1;
  892. if (!IS_ROOT(nd->dentry) && d_unhashed(nd->dentry))
  893. goto out1;
  894. err = -EINVAL;
  895. if (old_nd.dentry != old_nd.mnt->mnt_root)
  896. goto out1;
  897. if (old_nd.mnt == old_nd.mnt->mnt_parent)
  898. goto out1;
  899. if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
  900. S_ISDIR(old_nd.dentry->d_inode->i_mode))
  901. goto out1;
  902. /*
  903. * Don't move a mount residing in a shared parent.
  904. */
  905. if (old_nd.mnt->mnt_parent && IS_MNT_SHARED(old_nd.mnt->mnt_parent))
  906. goto out1;
  907. /*
  908. * Don't move a mount tree containing unbindable mounts to a destination
  909. * mount which is shared.
  910. */
  911. if (IS_MNT_SHARED(nd->mnt) && tree_contains_unbindable(old_nd.mnt))
  912. goto out1;
  913. err = -ELOOP;
  914. for (p = nd->mnt; p->mnt_parent != p; p = p->mnt_parent)
  915. if (p == old_nd.mnt)
  916. goto out1;
  917. if ((err = attach_recursive_mnt(old_nd.mnt, nd, &parent_nd)))
  918. goto out1;
  919. spin_lock(&vfsmount_lock);
  920. /* if the mount is moved, it should no longer be expire
  921. * automatically */
  922. list_del_init(&old_nd.mnt->mnt_expire);
  923. spin_unlock(&vfsmount_lock);
  924. out1:
  925. mutex_unlock(&nd->dentry->d_inode->i_mutex);
  926. out:
  927. up_write(&namespace_sem);
  928. if (!err)
  929. path_release(&parent_nd);
  930. path_release(&old_nd);
  931. return err;
  932. }
  933. /*
  934. * create a new mount for userspace and request it to be added into the
  935. * namespace's tree
  936. */
  937. static int do_new_mount(struct nameidata *nd, char *type, int flags,
  938. int mnt_flags, char *name, void *data)
  939. {
  940. struct vfsmount *mnt;
  941. if (!type || !memchr(type, 0, PAGE_SIZE))
  942. return -EINVAL;
  943. /* we need capabilities... */
  944. if (!capable(CAP_SYS_ADMIN))
  945. return -EPERM;
  946. mnt = do_kern_mount(type, flags, name, data);
  947. if (IS_ERR(mnt))
  948. return PTR_ERR(mnt);
  949. return do_add_mount(mnt, nd, mnt_flags, NULL);
  950. }
  951. /*
  952. * add a mount into a namespace's mount tree
  953. * - provide the option of adding the new mount to an expiration list
  954. */
  955. int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
  956. int mnt_flags, struct list_head *fslist)
  957. {
  958. int err;
  959. down_write(&namespace_sem);
  960. /* Something was mounted here while we slept */
  961. while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
  962. ;
  963. err = -EINVAL;
  964. if (!check_mnt(nd->mnt))
  965. goto unlock;
  966. /* Refuse the same filesystem on the same mount point */
  967. err = -EBUSY;
  968. if (nd->mnt->mnt_sb == newmnt->mnt_sb &&
  969. nd->mnt->mnt_root == nd->dentry)
  970. goto unlock;
  971. err = -EINVAL;
  972. if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode))
  973. goto unlock;
  974. newmnt->mnt_flags = mnt_flags;
  975. if ((err = graft_tree(newmnt, nd)))
  976. goto unlock;
  977. if (fslist) {
  978. /* add to the specified expiration list */
  979. spin_lock(&vfsmount_lock);
  980. list_add_tail(&newmnt->mnt_expire, fslist);
  981. spin_unlock(&vfsmount_lock);
  982. }
  983. up_write(&namespace_sem);
  984. return 0;
  985. unlock:
  986. up_write(&namespace_sem);
  987. mntput(newmnt);
  988. return err;
  989. }
  990. EXPORT_SYMBOL_GPL(do_add_mount);
  991. static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
  992. struct list_head *umounts)
  993. {
  994. spin_lock(&vfsmount_lock);
  995. /*
  996. * Check if mount is still attached, if not, let whoever holds it deal
  997. * with the sucker
  998. */
  999. if (mnt->mnt_parent == mnt) {
  1000. spin_unlock(&vfsmount_lock);
  1001. return;
  1002. }
  1003. /*
  1004. * Check that it is still dead: the count should now be 2 - as
  1005. * contributed by the vfsmount parent and the mntget above
  1006. */
  1007. if (!propagate_mount_busy(mnt, 2)) {
  1008. /* delete from the namespace */
  1009. touch_mnt_namespace(mnt->mnt_ns);
  1010. list_del_init(&mnt->mnt_list);
  1011. mnt->mnt_ns = NULL;
  1012. umount_tree(mnt, 1, umounts);
  1013. spin_unlock(&vfsmount_lock);
  1014. } else {
  1015. /*
  1016. * Someone brought it back to life whilst we didn't have any
  1017. * locks held so return it to the expiration list
  1018. */
  1019. list_add_tail(&mnt->mnt_expire, mounts);
  1020. spin_unlock(&vfsmount_lock);
  1021. }
  1022. }
  1023. /*
  1024. * go through the vfsmounts we've just consigned to the graveyard to
  1025. * - check that they're still dead
  1026. * - delete the vfsmount from the appropriate namespace under lock
  1027. * - dispose of the corpse
  1028. */
  1029. static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
  1030. {
  1031. struct mnt_namespace *ns;
  1032. struct vfsmount *mnt;
  1033. while (!list_empty(graveyard)) {
  1034. LIST_HEAD(umounts);
  1035. mnt = list_first_entry(graveyard, struct vfsmount, mnt_expire);
  1036. list_del_init(&mnt->mnt_expire);
  1037. /* don't do anything if the namespace is dead - all the
  1038. * vfsmounts from it are going away anyway */
  1039. ns = mnt->mnt_ns;
  1040. if (!ns || !ns->root)
  1041. continue;
  1042. get_mnt_ns(ns);
  1043. spin_unlock(&vfsmount_lock);
  1044. down_write(&namespace_sem);
  1045. expire_mount(mnt, mounts, &umounts);
  1046. up_write(&namespace_sem);
  1047. release_mounts(&umounts);
  1048. mntput(mnt);
  1049. put_mnt_ns(ns);
  1050. spin_lock(&vfsmount_lock);
  1051. }
  1052. }
  1053. /*
  1054. * process a list of expirable mountpoints with the intent of discarding any
  1055. * mountpoints that aren't in use and haven't been touched since last we came
  1056. * here
  1057. */
  1058. void mark_mounts_for_expiry(struct list_head *mounts)
  1059. {
  1060. struct vfsmount *mnt, *next;
  1061. LIST_HEAD(graveyard);
  1062. if (list_empty(mounts))
  1063. return;
  1064. spin_lock(&vfsmount_lock);
  1065. /* extract from the expiration list every vfsmount that matches the
  1066. * following criteria:
  1067. * - only referenced by its parent vfsmount
  1068. * - still marked for expiry (marked on the last call here; marks are
  1069. * cleared by mntput())
  1070. */
  1071. list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
  1072. if (!xchg(&mnt->mnt_expiry_mark, 1) ||
  1073. atomic_read(&mnt->mnt_count) != 1)
  1074. continue;
  1075. mntget(mnt);
  1076. list_move(&mnt->mnt_expire, &graveyard);
  1077. }
  1078. expire_mount_list(&graveyard, mounts);
  1079. spin_unlock(&vfsmount_lock);
  1080. }
  1081. EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
  1082. /*
  1083. * Ripoff of 'select_parent()'
  1084. *
  1085. * search the list of submounts for a given mountpoint, and move any
  1086. * shrinkable submounts to the 'graveyard' list.
  1087. */
  1088. static int select_submounts(struct vfsmount *parent, struct list_head *graveyard)
  1089. {
  1090. struct vfsmount *this_parent = parent;
  1091. struct list_head *next;
  1092. int found = 0;
  1093. repeat:
  1094. next = this_parent->mnt_mounts.next;
  1095. resume:
  1096. while (next != &this_parent->mnt_mounts) {
  1097. struct list_head *tmp = next;
  1098. struct vfsmount *mnt = list_entry(tmp, struct vfsmount, mnt_child);
  1099. next = tmp->next;
  1100. if (!(mnt->mnt_flags & MNT_SHRINKABLE))
  1101. continue;
  1102. /*
  1103. * Descend a level if the d_mounts list is non-empty.
  1104. */
  1105. if (!list_empty(&mnt->mnt_mounts)) {
  1106. this_parent = mnt;
  1107. goto repeat;
  1108. }
  1109. if (!propagate_mount_busy(mnt, 1)) {
  1110. mntget(mnt);
  1111. list_move_tail(&mnt->mnt_expire, graveyard);
  1112. found++;
  1113. }
  1114. }
  1115. /*
  1116. * All done at this level ... ascend and resume the search
  1117. */
  1118. if (this_parent != parent) {
  1119. next = this_parent->mnt_child.next;
  1120. this_parent = this_parent->mnt_parent;
  1121. goto resume;
  1122. }
  1123. return found;
  1124. }
  1125. /*
  1126. * process a list of expirable mountpoints with the intent of discarding any
  1127. * submounts of a specific parent mountpoint
  1128. */
  1129. void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts)
  1130. {
  1131. LIST_HEAD(graveyard);
  1132. int found;
  1133. spin_lock(&vfsmount_lock);
  1134. /* extract submounts of 'mountpoint' from the expiration list */
  1135. while ((found = select_submounts(mountpoint, &graveyard)) != 0)
  1136. expire_mount_list(&graveyard, mounts);
  1137. spin_unlock(&vfsmount_lock);
  1138. }
  1139. EXPORT_SYMBOL_GPL(shrink_submounts);
  1140. /*
  1141. * Some copy_from_user() implementations do not return the exact number of
  1142. * bytes remaining to copy on a fault. But copy_mount_options() requires that.
  1143. * Note that this function differs from copy_from_user() in that it will oops
  1144. * on bad values of `to', rather than returning a short copy.
  1145. */
  1146. static long exact_copy_from_user(void *to, const void __user * from,
  1147. unsigned long n)
  1148. {
  1149. char *t = to;
  1150. const char __user *f = from;
  1151. char c;
  1152. if (!access_ok(VERIFY_READ, from, n))
  1153. return n;
  1154. while (n) {
  1155. if (__get_user(c, f)) {
  1156. memset(t, 0, n);
  1157. break;
  1158. }
  1159. *t++ = c;
  1160. f++;
  1161. n--;
  1162. }
  1163. return n;
  1164. }
  1165. int copy_mount_options(const void __user * data, unsigned long *where)
  1166. {
  1167. int i;
  1168. unsigned long page;
  1169. unsigned long size;
  1170. *where = 0;
  1171. if (!data)
  1172. return 0;
  1173. if (!(page = __get_free_page(GFP_KERNEL)))
  1174. return -ENOMEM;
  1175. /* We only care that *some* data at the address the user
  1176. * gave us is valid. Just in case, we'll zero
  1177. * the remainder of the page.
  1178. */
  1179. /* copy_from_user cannot cross TASK_SIZE ! */
  1180. size = TASK_SIZE - (unsigned long)data;
  1181. if (size > PAGE_SIZE)
  1182. size = PAGE_SIZE;
  1183. i = size - exact_copy_from_user((void *)page, data, size);
  1184. if (!i) {
  1185. free_page(page);
  1186. return -EFAULT;
  1187. }
  1188. if (i != PAGE_SIZE)
  1189. memset((char *)page + i, 0, PAGE_SIZE - i);
  1190. *where = page;
  1191. return 0;
  1192. }
  1193. /*
  1194. * Flags is a 32-bit value that allows up to 31 non-fs dependent flags to
  1195. * be given to the mount() call (ie: read-only, no-dev, no-suid etc).
  1196. *
  1197. * data is a (void *) that can point to any structure up to
  1198. * PAGE_SIZE-1 bytes, which can contain arbitrary fs-dependent
  1199. * information (or be NULL).
  1200. *
  1201. * Pre-0.97 versions of mount() didn't have a flags word.
  1202. * When the flags word was introduced its top half was required
  1203. * to have the magic value 0xC0ED, and this remained so until 2.4.0-test9.
  1204. * Therefore, if this magic number is present, it carries no information
  1205. * and must be discarded.
  1206. */
  1207. long do_mount(char *dev_name, char *dir_name, char *type_page,
  1208. unsigned long flags, void *data_page)
  1209. {
  1210. struct nameidata nd;
  1211. int retval = 0;
  1212. int mnt_flags = 0;
  1213. /* Discard magic */
  1214. if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
  1215. flags &= ~MS_MGC_MSK;
  1216. /* Basic sanity checks */
  1217. if (!dir_name || !*dir_name || !memchr(dir_name, 0, PAGE_SIZE))
  1218. return -EINVAL;
  1219. if (dev_name && !memchr(dev_name, 0, PAGE_SIZE))
  1220. return -EINVAL;
  1221. if (data_page)
  1222. ((char *)data_page)[PAGE_SIZE - 1] = 0;
  1223. /* Separate the per-mountpoint flags */
  1224. if (flags & MS_NOSUID)
  1225. mnt_flags |= MNT_NOSUID;
  1226. if (flags & MS_NODEV)
  1227. mnt_flags |= MNT_NODEV;
  1228. if (flags & MS_NOEXEC)
  1229. mnt_flags |= MNT_NOEXEC;
  1230. if (flags & MS_NOATIME)
  1231. mnt_flags |= MNT_NOATIME;
  1232. if (flags & MS_NODIRATIME)
  1233. mnt_flags |= MNT_NODIRATIME;
  1234. if (flags & MS_RELATIME)
  1235. mnt_flags |= MNT_RELATIME;
  1236. flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
  1237. MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
  1238. /* ... and get the mountpoint */
  1239. retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
  1240. if (retval)
  1241. return retval;
  1242. retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page);
  1243. if (retval)
  1244. goto dput_out;
  1245. if (flags & MS_REMOUNT)
  1246. retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
  1247. data_page);
  1248. else if (flags & MS_BIND)
  1249. retval = do_loopback(&nd, dev_name, flags & MS_REC);
  1250. else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
  1251. retval = do_change_type(&nd, flags);
  1252. else if (flags & MS_MOVE)
  1253. retval = do_move_mount(&nd, dev_name);
  1254. else
  1255. retval = do_new_mount(&nd, type_page, flags, mnt_flags,
  1256. dev_name, data_page);
  1257. dput_out:
  1258. path_release(&nd);
  1259. return retval;
  1260. }
  1261. /*
  1262. * Allocate a new namespace structure and populate it with contents
  1263. * copied from the namespace of the passed in task structure.
  1264. */
  1265. static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
  1266. struct fs_struct *fs)
  1267. {
  1268. struct mnt_namespace *new_ns;
  1269. struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
  1270. struct vfsmount *p, *q;
  1271. new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
  1272. if (!new_ns)
  1273. return ERR_PTR(-ENOMEM);
  1274. atomic_set(&new_ns->count, 1);
  1275. INIT_LIST_HEAD(&new_ns->list);
  1276. init_waitqueue_head(&new_ns->poll);
  1277. new_ns->event = 0;
  1278. down_write(&namespace_sem);
  1279. /* First pass: copy the tree topology */
  1280. new_ns->root = copy_tree(mnt_ns->root, mnt_ns->root->mnt_root,
  1281. CL_COPY_ALL | CL_EXPIRE);
  1282. if (!new_ns->root) {
  1283. up_write(&namespace_sem);
  1284. kfree(new_ns);
  1285. return ERR_PTR(-ENOMEM);;
  1286. }
  1287. spin_lock(&vfsmount_lock);
  1288. list_add_tail(&new_ns->list, &new_ns->root->mnt_list);
  1289. spin_unlock(&vfsmount_lock);
  1290. /*
  1291. * Second pass: switch the tsk->fs->* elements and mark new vfsmounts
  1292. * as belonging to new namespace. We have already acquired a private
  1293. * fs_struct, so tsk->fs->lock is not needed.
  1294. */
  1295. p = mnt_ns->root;
  1296. q = new_ns->root;
  1297. while (p) {
  1298. q->mnt_ns = new_ns;
  1299. if (fs) {
  1300. if (p == fs->rootmnt) {
  1301. rootmnt = p;
  1302. fs->rootmnt = mntget(q);
  1303. }
  1304. if (p == fs->pwdmnt) {
  1305. pwdmnt = p;
  1306. fs->pwdmnt = mntget(q);
  1307. }
  1308. if (p == fs->altrootmnt) {
  1309. altrootmnt = p;
  1310. fs->altrootmnt = mntget(q);
  1311. }
  1312. }
  1313. p = next_mnt(p, mnt_ns->root);
  1314. q = next_mnt(q, new_ns->root);
  1315. }
  1316. up_write(&namespace_sem);
  1317. if (rootmnt)
  1318. mntput(rootmnt);
  1319. if (pwdmnt)
  1320. mntput(pwdmnt);
  1321. if (altrootmnt)
  1322. mntput(altrootmnt);
  1323. return new_ns;
  1324. }
  1325. struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
  1326. struct fs_struct *new_fs)
  1327. {
  1328. struct mnt_namespace *new_ns;
  1329. BUG_ON(!ns);
  1330. get_mnt_ns(ns);
  1331. if (!(flags & CLONE_NEWNS))
  1332. return ns;
  1333. new_ns = dup_mnt_ns(ns, new_fs);
  1334. put_mnt_ns(ns);
  1335. return new_ns;
  1336. }
  1337. asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
  1338. char __user * type, unsigned long flags,
  1339. void __user * data)
  1340. {
  1341. int retval;
  1342. unsigned long data_page;
  1343. unsigned long type_page;
  1344. unsigned long dev_page;
  1345. char *dir_page;
  1346. retval = copy_mount_options(type, &type_page);
  1347. if (retval < 0)
  1348. return retval;
  1349. dir_page = getname(dir_name);
  1350. retval = PTR_ERR(dir_page);
  1351. if (IS_ERR(dir_page))
  1352. goto out1;
  1353. retval = copy_mount_options(dev_name, &dev_page);
  1354. if (retval < 0)
  1355. goto out2;
  1356. retval = copy_mount_options(data, &data_page);
  1357. if (retval < 0)
  1358. goto out3;
  1359. lock_kernel();
  1360. retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
  1361. flags, (void *)data_page);
  1362. unlock_kernel();
  1363. free_page(data_page);
  1364. out3:
  1365. free_page(dev_page);
  1366. out2:
  1367. putname(dir_page);
  1368. out1:
  1369. free_page(type_page);
  1370. return retval;
  1371. }
  1372. /*
  1373. * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
  1374. * It can block. Requires the big lock held.
  1375. */
  1376. void set_fs_root(struct fs_struct *fs, struct vfsmount *mnt,
  1377. struct dentry *dentry)
  1378. {
  1379. struct dentry *old_root;
  1380. struct vfsmount *old_rootmnt;
  1381. write_lock(&fs->lock);
  1382. old_root = fs->root;
  1383. old_rootmnt = fs->rootmnt;
  1384. fs->rootmnt = mntget(mnt);
  1385. fs->root = dget(dentry);
  1386. write_unlock(&fs->lock);
  1387. if (old_root) {
  1388. dput(old_root);
  1389. mntput(old_rootmnt);
  1390. }
  1391. }
  1392. /*
  1393. * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
  1394. * It can block. Requires the big lock held.
  1395. */
  1396. void set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
  1397. struct dentry *dentry)
  1398. {
  1399. struct dentry *old_pwd;
  1400. struct vfsmount *old_pwdmnt;
  1401. write_lock(&fs->lock);
  1402. old_pwd = fs->pwd;
  1403. old_pwdmnt = fs->pwdmnt;
  1404. fs->pwdmnt = mntget(mnt);
  1405. fs->pwd = dget(dentry);
  1406. write_unlock(&fs->lock);
  1407. if (old_pwd) {
  1408. dput(old_pwd);
  1409. mntput(old_pwdmnt);
  1410. }
  1411. }
  1412. static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
  1413. {
  1414. struct task_struct *g, *p;
  1415. struct fs_struct *fs;
  1416. read_lock(&tasklist_lock);
  1417. do_each_thread(g, p) {
  1418. task_lock(p);
  1419. fs = p->fs;
  1420. if (fs) {
  1421. atomic_inc(&fs->count);
  1422. task_unlock(p);
  1423. if (fs->root == old_nd->dentry
  1424. && fs->rootmnt == old_nd->mnt)
  1425. set_fs_root(fs, new_nd->mnt, new_nd->dentry);
  1426. if (fs->pwd == old_nd->dentry
  1427. && fs->pwdmnt == old_nd->mnt)
  1428. set_fs_pwd(fs, new_nd->mnt, new_nd->dentry);
  1429. put_fs_struct(fs);
  1430. } else
  1431. task_unlock(p);
  1432. } while_each_thread(g, p);
  1433. read_unlock(&tasklist_lock);
  1434. }
  1435. /*
  1436. * pivot_root Semantics:
  1437. * Moves the root file system of the current process to the directory put_old,
  1438. * makes new_root as the new root file system of the current process, and sets
  1439. * root/cwd of all processes which had them on the current root to new_root.
  1440. *
  1441. * Restrictions:
  1442. * The new_root and put_old must be directories, and must not be on the
  1443. * same file system as the current process root. The put_old must be
  1444. * underneath new_root, i.e. adding a non-zero number of /.. to the string
  1445. * pointed to by put_old must yield the same directory as new_root. No other
  1446. * file system may be mounted on put_old. After all, new_root is a mountpoint.
  1447. *
  1448. * Also, the current root cannot be on the 'rootfs' (initial ramfs) filesystem.
  1449. * See Documentation/filesystems/ramfs-rootfs-initramfs.txt for alternatives
  1450. * in this situation.
  1451. *
  1452. * Notes:
  1453. * - we don't move root/cwd if they are not at the root (reason: if something
  1454. * cared enough to change them, it's probably wrong to force them elsewhere)
  1455. * - it's okay to pick a root that isn't the root of a file system, e.g.
  1456. * /nfs/my_root where /nfs is the mount point. It must be a mountpoint,
  1457. * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root
  1458. * first.
  1459. */
  1460. asmlinkage long sys_pivot_root(const char __user * new_root,
  1461. const char __user * put_old)
  1462. {
  1463. struct vfsmount *tmp;
  1464. struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;
  1465. int error;
  1466. if (!capable(CAP_SYS_ADMIN))
  1467. return -EPERM;
  1468. lock_kernel();
  1469. error = __user_walk(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
  1470. &new_nd);
  1471. if (error)
  1472. goto out0;
  1473. error = -EINVAL;
  1474. if (!check_mnt(new_nd.mnt))
  1475. goto out1;
  1476. error = __user_walk(put_old, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &old_nd);
  1477. if (error)
  1478. goto out1;
  1479. error = security_sb_pivotroot(&old_nd, &new_nd);
  1480. if (error) {
  1481. path_release(&old_nd);
  1482. goto out1;
  1483. }
  1484. read_lock(&current->fs->lock);
  1485. user_nd.mnt = mntget(current->fs->rootmnt);
  1486. user_nd.dentry = dget(current->fs->root);
  1487. read_unlock(&current->fs->lock);
  1488. down_write(&namespace_sem);
  1489. mutex_lock(&old_nd.dentry->d_inode->i_mutex);
  1490. error = -EINVAL;
  1491. if (IS_MNT_SHARED(old_nd.mnt) ||
  1492. IS_MNT_SHARED(new_nd.mnt->mnt_parent) ||
  1493. IS_MNT_SHARED(user_nd.mnt->mnt_parent))
  1494. goto out2;
  1495. if (!check_mnt(user_nd.mnt))
  1496. goto out2;
  1497. error = -ENOENT;
  1498. if (IS_DEADDIR(new_nd.dentry->d_inode))
  1499. goto out2;
  1500. if (d_unhashed(new_nd.dentry) && !IS_ROOT(new_nd.dentry))
  1501. goto out2;
  1502. if (d_unhashed(old_nd.dentry) && !IS_ROOT(old_nd.dentry))
  1503. goto out2;
  1504. error = -EBUSY;
  1505. if (new_nd.mnt == user_nd.mnt || old_nd.mnt == user_nd.mnt)
  1506. goto out2; /* loop, on the same file system */
  1507. error = -EINVAL;
  1508. if (user_nd.mnt->mnt_root != user_nd.dentry)
  1509. goto out2; /* not a mountpoint */
  1510. if (user_nd.mnt->mnt_parent == user_nd.mnt)
  1511. goto out2; /* not attached */
  1512. if (new_nd.mnt->mnt_root != new_nd.dentry)
  1513. goto out2; /* not a mountpoint */
  1514. if (new_nd.mnt->mnt_parent == new_nd.mnt)
  1515. goto out2; /* not attached */
  1516. tmp = old_nd.mnt; /* make sure we can reach put_old from new_root */
  1517. spin_lock(&vfsmount_lock);
  1518. if (tmp != new_nd.mnt) {
  1519. for (;;) {
  1520. if (tmp->mnt_parent == tmp)
  1521. goto out3; /* already mounted on put_old */
  1522. if (tmp->mnt_parent == new_nd.mnt)
  1523. break;
  1524. tmp = tmp->mnt_parent;
  1525. }
  1526. if (!is_subdir(tmp->mnt_mountpoint, new_nd.dentry))
  1527. goto out3;
  1528. } else if (!is_subdir(old_nd.dentry, new_nd.dentry))
  1529. goto out3;
  1530. detach_mnt(new_nd.mnt, &parent_nd);
  1531. detach_mnt(user_nd.mnt, &root_parent);
  1532. attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */
  1533. attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
  1534. touch_mnt_namespace(current->nsproxy->mnt_ns);
  1535. spin_unlock(&vfsmount_lock);
  1536. chroot_fs_refs(&user_nd, &new_nd);
  1537. security_sb_post_pivotroot(&user_nd, &new_nd);
  1538. error = 0;
  1539. path_release(&root_parent);
  1540. path_release(&parent_nd);
  1541. out2:
  1542. mutex_unlock(&old_nd.dentry->d_inode->i_mutex);
  1543. up_write(&namespace_sem);
  1544. path_release(&user_nd);
  1545. path_release(&old_nd);
  1546. out1:
  1547. path_release(&new_nd);
  1548. out0:
  1549. unlock_kernel();
  1550. return error;
  1551. out3:
  1552. spin_unlock(&vfsmount_lock);
  1553. goto out2;
  1554. }
  1555. static void __init init_mount_tree(void)
  1556. {
  1557. struct vfsmount *mnt;
  1558. struct mnt_namespace *ns;
  1559. mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
  1560. if (IS_ERR(mnt))
  1561. panic("Can't create rootfs");
  1562. ns = kmalloc(sizeof(*ns), GFP_KERNEL);
  1563. if (!ns)
  1564. panic("Can't allocate initial namespace");
  1565. atomic_set(&ns->count, 1);
  1566. INIT_LIST_HEAD(&ns->list);
  1567. init_waitqueue_head(&ns->poll);
  1568. ns->event = 0;
  1569. list_add(&mnt->mnt_list, &ns->list);
  1570. ns->root = mnt;
  1571. mnt->mnt_ns = ns;
  1572. init_task.nsproxy->mnt_ns = ns;
  1573. get_mnt_ns(ns);
  1574. set_fs_pwd(current->fs, ns->root, ns->root->mnt_root);
  1575. set_fs_root(current->fs, ns->root, ns->root->mnt_root);
  1576. }
  1577. void __init mnt_init(void)
  1578. {
  1579. struct list_head *d;
  1580. unsigned int nr_hash;
  1581. int i;
  1582. int err;
  1583. init_rwsem(&namespace_sem);
  1584. mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),
  1585. 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
  1586. mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC);
  1587. if (!mount_hashtable)
  1588. panic("Failed to allocate mount hash table\n");
  1589. /*
  1590. * Find the power-of-two list-heads that can fit into the allocation..
  1591. * We don't guarantee that "sizeof(struct list_head)" is necessarily
  1592. * a power-of-two.
  1593. */
  1594. nr_hash = PAGE_SIZE / sizeof(struct list_head);
  1595. hash_bits = 0;
  1596. do {
  1597. hash_bits++;
  1598. } while ((nr_hash >> hash_bits) != 0);
  1599. hash_bits--;
  1600. /*
  1601. * Re-calculate the actual number of entries and the mask
  1602. * from the number of bits we can fit.
  1603. */
  1604. nr_hash = 1UL << hash_bits;
  1605. hash_mask = nr_hash - 1;
  1606. printk("Mount-cache hash table entries: %d\n", nr_hash);
  1607. /* And initialize the newly allocated array */
  1608. d = mount_hashtable;
  1609. i = nr_hash;
  1610. do {
  1611. INIT_LIST_HEAD(d);
  1612. d++;
  1613. i--;
  1614. } while (i);
  1615. err = sysfs_init();
  1616. if (err)
  1617. printk(KERN_WARNING "%s: sysfs_init error: %d\n",
  1618. __FUNCTION__, err);
  1619. err = subsystem_register(&fs_subsys);
  1620. if (err)
  1621. printk(KERN_WARNING "%s: subsystem_register error: %d\n",
  1622. __FUNCTION__, err);
  1623. init_rootfs();
  1624. init_mount_tree();
  1625. }
  1626. void __put_mnt_ns(struct mnt_namespace *ns)
  1627. {
  1628. struct vfsmount *root = ns->root;
  1629. LIST_HEAD(umount_list);
  1630. ns->root = NULL;
  1631. spin_unlock(&vfsmount_lock);
  1632. down_write(&namespace_sem);
  1633. spin_lock(&vfsmount_lock);
  1634. umount_tree(root, 0, &umount_list);
  1635. spin_unlock(&vfsmount_lock);
  1636. up_write(&namespace_sem);
  1637. release_mounts(&umount_list);
  1638. kfree(ns);
  1639. }