namespace.c 47 KB

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