namespace.c 47 KB

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