Lines Matching +full:current +full:- +full:path
1 // SPDX-License-Identifier: GPL-2.0-only
132 if (ns && refcount_dec_and_test(&ns->passive)) { in mnt_ns_release()
134 put_user_ns(ns->user_ns); in mnt_ns_release()
152 call_rcu(&ns->ns.ns_rcu, mnt_ns_release_rcu); in mnt_ns_tree_remove()
184 refcount_inc(&mnt_ns->passive); in lookup_mnt_ns()
218 res = __xa_alloc(&mnt_id_xa, &mnt->mnt_id, mnt, xa_limit_31b, GFP_KERNEL); in mnt_alloc_id()
220 mnt->mnt_id_unique = ++mnt_id_ctr; in mnt_alloc_id()
227 xa_erase(&mnt_id_xa, mnt->mnt_id); in mnt_free_id()
239 mnt->mnt_group_id = res; in mnt_alloc_group_id()
248 ida_free(&mnt_group_ida, mnt->mnt_group_id); in mnt_release_group_id()
249 mnt->mnt_group_id = 0; in mnt_release_group_id()
258 this_cpu_add(mnt->mnt_pcp->mnt_count, n); in mnt_add_count()
261 mnt->mnt_count += n; in mnt_add_count()
276 count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count; in mnt_get_count()
281 return mnt->mnt_count; in mnt_get_count()
296 mnt->mnt_devname = kstrdup_const(name, in alloc_vfsmnt()
299 mnt->mnt_devname = "none"; in alloc_vfsmnt()
300 if (!mnt->mnt_devname) in alloc_vfsmnt()
304 mnt->mnt_pcp = alloc_percpu(struct mnt_pcp); in alloc_vfsmnt()
305 if (!mnt->mnt_pcp) in alloc_vfsmnt()
308 this_cpu_add(mnt->mnt_pcp->mnt_count, 1); in alloc_vfsmnt()
310 mnt->mnt_count = 1; in alloc_vfsmnt()
311 mnt->mnt_writers = 0; in alloc_vfsmnt()
314 INIT_HLIST_NODE(&mnt->mnt_hash); in alloc_vfsmnt()
315 INIT_LIST_HEAD(&mnt->mnt_child); in alloc_vfsmnt()
316 INIT_LIST_HEAD(&mnt->mnt_mounts); in alloc_vfsmnt()
317 INIT_LIST_HEAD(&mnt->mnt_list); in alloc_vfsmnt()
318 INIT_LIST_HEAD(&mnt->mnt_expire); in alloc_vfsmnt()
319 INIT_LIST_HEAD(&mnt->mnt_share); in alloc_vfsmnt()
320 INIT_HLIST_HEAD(&mnt->mnt_slave_list); in alloc_vfsmnt()
321 INIT_HLIST_NODE(&mnt->mnt_slave); in alloc_vfsmnt()
322 INIT_HLIST_NODE(&mnt->mnt_mp_list); in alloc_vfsmnt()
323 INIT_HLIST_HEAD(&mnt->mnt_stuck_children); in alloc_vfsmnt()
324 INIT_HLIST_NODE(&mnt->mnt_ns_visible); in alloc_vfsmnt()
325 RB_CLEAR_NODE(&mnt->mnt_node); in alloc_vfsmnt()
326 mnt->mnt.mnt_idmap = &nop_mnt_idmap; in alloc_vfsmnt()
332 kfree_const(mnt->mnt_devname); in alloc_vfsmnt()
350 * __mnt_is_readonly: check whether a mount is read-only
362 return (mnt->mnt_flags & MNT_READONLY) || sb_rdonly(mnt->mnt_sb); in __mnt_is_readonly()
369 this_cpu_inc(mnt->mnt_pcp->mnt_writers); in mnt_inc_writers()
371 mnt->mnt_writers++; in mnt_inc_writers()
378 this_cpu_dec(mnt->mnt_pcp->mnt_writers); in mnt_dec_writers()
380 mnt->mnt_writers--; in mnt_dec_writers()
391 count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_writers; in mnt_get_writers()
396 return mnt->mnt_writers; in mnt_get_writers()
402 if (READ_ONCE(mnt->mnt_sb->s_readonly_remount)) in mnt_is_readonly()
423 * mnt_get_write_access - get write access to a mount without freeze protection
426 * This tells the low-level filesystem that a write is about to be performed to
427 * it, and makes sure that writes are allowed (mnt it read-write) before
446 while (__test_write_hold(READ_ONCE(mnt->mnt_pprev_for_sb))) { in mnt_get_write_access()
468 * read-only. in mnt_get_write_access()
473 ret = -EROFS; in mnt_get_write_access()
482 * mnt_want_write - get write access to a mount
485 * This tells the low-level filesystem that a write is about to be performed to
486 * it, and makes sure that writes are allowed (mount is read-write, filesystem
494 sb_start_write(m->mnt_sb); in mnt_want_write()
497 sb_end_write(m->mnt_sb); in mnt_want_write()
503 * mnt_get_write_access_file - get write access to a file's mount
513 if (file->f_mode & FMODE_WRITER) { in mnt_get_write_access_file()
516 * writable fd's, e.g. due to a fs error with errors=remount-ro in mnt_get_write_access_file()
518 if (__mnt_is_readonly(file->f_path.mnt)) in mnt_get_write_access_file()
519 return -EROFS; in mnt_get_write_access_file()
522 return mnt_get_write_access(file->f_path.mnt); in mnt_get_write_access_file()
526 * mnt_want_write_file - get write access to a file's mount
538 sb_start_write(file_inode(file)->i_sb); in mnt_want_write_file()
541 sb_end_write(file_inode(file)->i_sb); in mnt_want_write_file()
547 * mnt_put_write_access - give up write access to a mount
550 * Tells the low-level filesystem that we are done
563 * mnt_drop_write - give up write access to a mount
566 * Tells the low-level filesystem that we are done performing writes to it and
573 sb_end_write(mnt->mnt_sb); in mnt_drop_write()
579 if (!(file->f_mode & FMODE_WRITER)) in mnt_put_write_access_file()
580 mnt_put_write_access(file->f_path.mnt); in mnt_put_write_access_file()
586 sb_end_write(file_inode(file)->i_sb); in mnt_drop_write_file()
591 * mnt_hold_writers - prevent write access to the given mount
606 * On error, -EBUSY is returned.
627 * decremented from -- we would see more decrements than we should. in mnt_hold_writers()
634 return -EBUSY; in mnt_hold_writers()
640 * mnt_unhold_writers - stop preventing write access to the given mount
665 struct mount **p = m->mnt_pprev_for_sb; in mnt_del_instance()
666 struct mount *next = m->mnt_next_for_sb; in mnt_del_instance()
669 next->mnt_pprev_for_sb = p; in mnt_del_instance()
675 struct mount *first = s->s_mounts; in mnt_add_instance()
678 first->mnt_pprev_for_sb = &m->mnt_next_for_sb; in mnt_add_instance()
679 m->mnt_next_for_sb = first; in mnt_add_instance()
680 m->mnt_pprev_for_sb = &s->s_mounts; in mnt_add_instance()
681 s->s_mounts = m; in mnt_add_instance()
690 mnt->mnt.mnt_flags |= MNT_READONLY; in mnt_make_readonly()
700 if (atomic_long_read(&sb->s_remove_count)) in sb_prepare_remount_readonly()
701 return -EBUSY; in sb_prepare_remount_readonly()
705 for (struct mount *m = sb->s_mounts; m; m = m->mnt_next_for_sb) { in sb_prepare_remount_readonly()
706 if (!(m->mnt.mnt_flags & MNT_READONLY)) { in sb_prepare_remount_readonly()
712 if (!err && atomic_long_read(&sb->s_remove_count)) in sb_prepare_remount_readonly()
713 err = -EBUSY; in sb_prepare_remount_readonly()
717 for (struct mount *m = sb->s_mounts; m; m = m->mnt_next_for_sb) { in sb_prepare_remount_readonly()
727 mnt_idmap_put(mnt_idmap(&mnt->mnt)); in free_vfsmnt()
728 kfree_const(mnt->mnt_devname); in free_vfsmnt()
730 free_percpu(mnt->mnt_pcp); in free_vfsmnt()
754 if (unlikely(bastard->mnt_flags & (MNT_SYNC_UMOUNT | MNT_DOOMED))) { in __legitimize_mnt()
755 mnt_add_count(mnt, -1); in __legitimize_mnt()
761 return -1; in __legitimize_mnt()
779 * __lookup_mnt - mount hash lookup
796 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) in __lookup_mnt()
802 * lookup_mnt - Return the child mount mounted at given location
803 * @path: location in the namespace
808 struct vfsmount *lookup_mnt(const struct path *path) in lookup_mnt() argument
817 child_mnt = __lookup_mnt(path->mnt, path->dentry); in lookup_mnt()
818 m = child_mnt ? &child_mnt->mnt : NULL; in lookup_mnt()
825 * __is_local_mountpoint - Test to see if dentry is a mountpoint in the
826 * current mount namespace.
831 * mounts in the current mount namespace and test to see if the dentry
835 * need to identify all mounts that may be in the current mount
841 struct mnt_namespace *ns = current->nsproxy->mnt_ns; in __is_local_mountpoint()
846 rbtree_postorder_for_each_entry_safe(mnt, n, &ns->mounts, mnt_node) in __is_local_mountpoint()
847 if (mnt->mnt_mountpoint == dentry) in __is_local_mountpoint()
865 if (mp->m_dentry == dentry) { in lookup_mountpoint()
866 hlist_add_head(&m->node, &mp->m_list); in lookup_mountpoint()
867 m->mp = mp; in lookup_mountpoint()
883 return -ENOENT; in get_mountpoint()
895 return -ENOMEM; in get_mountpoint()
901 if (ret == -EBUSY) in get_mountpoint()
910 mp->m_dentry = dget(dentry); in get_mountpoint()
911 hlist_add_head(&mp->m_hash, mp_hash(dentry)); in get_mountpoint()
912 INIT_HLIST_HEAD(&mp->m_list); in get_mountpoint()
913 hlist_add_head(&m->node, &mp->m_list); in get_mountpoint()
914 m->mp = no_free_ptr(mp); in get_mountpoint()
925 if (hlist_empty(&mp->m_list)) { in maybe_free_mountpoint()
926 struct dentry *dentry = mp->m_dentry; in maybe_free_mountpoint()
927 spin_lock(&dentry->d_lock); in maybe_free_mountpoint()
928 dentry->d_flags &= ~DCACHE_MOUNTED; in maybe_free_mountpoint()
929 spin_unlock(&dentry->d_lock); in maybe_free_mountpoint()
931 hlist_del(&mp->m_hash); in maybe_free_mountpoint()
941 if (m->mp) { in unpin_mountpoint()
942 hlist_del(&m->node); in unpin_mountpoint()
943 maybe_free_mountpoint(m->mp, &ex_mountpoints); in unpin_mountpoint()
949 return mnt->mnt_ns == current->nsproxy->mnt_ns; in check_mnt()
956 if (!is_anon_ns(mnt->mnt_ns)) in check_anonymous_mnt()
959 seq = mnt->mnt_ns->seq_origin; in check_anonymous_mnt()
960 return !seq || (seq == current->nsproxy->mnt_ns->ns.ns_id); in check_anonymous_mnt()
969 ns->event = ++event; in touch_mnt_namespace()
970 wake_up_interruptible(&ns->poll); in touch_mnt_namespace()
979 if (ns && ns->event != event) { in __touch_mnt_namespace()
980 ns->event = event; in __touch_mnt_namespace()
981 wake_up_interruptible(&ns->poll); in __touch_mnt_namespace()
991 struct mount *parent = mnt->mnt_parent; in __umount_mnt()
992 if (unlikely(parent->overmount == mnt)) in __umount_mnt()
993 parent->overmount = NULL; in __umount_mnt()
994 mnt->mnt_parent = mnt; in __umount_mnt()
995 mnt->mnt_mountpoint = mnt->mnt.mnt_root; in __umount_mnt()
996 list_del_init(&mnt->mnt_child); in __umount_mnt()
997 hlist_del_init_rcu(&mnt->mnt_hash); in __umount_mnt()
998 hlist_del_init(&mnt->mnt_mp_list); in __umount_mnt()
999 mp = mnt->mnt_mp; in __umount_mnt()
1000 mnt->mnt_mp = NULL; in __umount_mnt()
1019 child_mnt->mnt_mountpoint = mp->m_dentry; in mnt_set_mountpoint()
1020 child_mnt->mnt_parent = mnt; in mnt_set_mountpoint()
1021 child_mnt->mnt_mp = mp; in mnt_set_mountpoint()
1022 hlist_add_head(&child_mnt->mnt_mp_list, &mp->m_list); in mnt_set_mountpoint()
1027 struct mount *parent = mnt->mnt_parent; in make_visible()
1028 if (unlikely(mnt->mnt_mountpoint == parent->mnt.mnt_root)) in make_visible()
1029 parent->overmount = mnt; in make_visible()
1030 hlist_add_head_rcu(&mnt->mnt_hash, in make_visible()
1031 m_hash(&parent->mnt, mnt->mnt_mountpoint)); in make_visible()
1032 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); in make_visible()
1036 * attach_mnt - mount a mount, attach to @mount_hashtable and parent's
1045 * Note, when make_visible() is called @mnt->mnt_parent already points
1060 struct mountpoint *old_mp = mnt->mnt_mp; in mnt_change_mountpoint()
1062 list_del_init(&mnt->mnt_child); in mnt_change_mountpoint()
1063 hlist_del_init(&mnt->mnt_mp_list); in mnt_change_mountpoint()
1064 hlist_del_init_rcu(&mnt->mnt_hash); in mnt_change_mountpoint()
1078 struct rb_node **link = &ns->mounts.rb_node; in mnt_add_to_ns()
1083 WRITE_ONCE(mnt->mnt_ns, ns); in mnt_add_to_ns()
1086 if (mnt->mnt_id_unique < node_to_mount(parent)->mnt_id_unique) { in mnt_add_to_ns()
1087 link = &parent->rb_left; in mnt_add_to_ns()
1090 link = &parent->rb_right; in mnt_add_to_ns()
1096 ns->mnt_last_node = &mnt->mnt_node; in mnt_add_to_ns()
1098 ns->mnt_first_node = &mnt->mnt_node; in mnt_add_to_ns()
1099 rb_link_node(&mnt->mnt_node, parent, link); in mnt_add_to_ns()
1100 rb_insert_color(&mnt->mnt_node, &ns->mounts); in mnt_add_to_ns()
1102 if ((mnt->mnt.mnt_sb->s_type->fs_flags & FS_USERNS_MOUNT_RESTRICTED) && in mnt_add_to_ns()
1103 mnt->mnt.mnt_root == mnt->mnt.mnt_sb->s_root) in mnt_add_to_ns()
1104 hlist_add_head(&mnt->mnt_ns_visible, &ns->mnt_visible_mounts); in mnt_add_to_ns()
1111 struct list_head *next = p->mnt_mounts.next; in next_mnt()
1112 if (next == &p->mnt_mounts) { in next_mnt()
1116 next = p->mnt_child.next; in next_mnt()
1117 if (next != &p->mnt_parent->mnt_mounts) in next_mnt()
1119 p = p->mnt_parent; in next_mnt()
1127 struct list_head *prev = p->mnt_mounts.prev; in skip_mnt_tree()
1128 while (prev != &p->mnt_mounts) { in skip_mnt_tree()
1130 prev = p->mnt_mounts.prev; in skip_mnt_tree()
1140 struct mnt_namespace *n = mnt->mnt_parent->mnt_ns; in commit_tree()
1145 n->nr_mounts += n->pending_mounts; in commit_tree()
1146 n->pending_mounts = 0; in commit_tree()
1155 struct super_block *s = root->d_sb; in setup_mnt()
1157 atomic_inc(&s->s_active); in setup_mnt()
1158 m->mnt.mnt_sb = s; in setup_mnt()
1159 m->mnt.mnt_root = dget(root); in setup_mnt()
1160 m->mnt_mountpoint = m->mnt.mnt_root; in setup_mnt()
1161 m->mnt_parent = m; in setup_mnt()
1168 * vfs_create_mount - Create a mount for a configured superblock
1180 if (!fc->root) in vfs_create_mount()
1181 return ERR_PTR(-EINVAL); in vfs_create_mount()
1183 mnt = alloc_vfsmnt(fc->source); in vfs_create_mount()
1185 return ERR_PTR(-ENOMEM); in vfs_create_mount()
1187 if (fc->sb_flags & SB_KERNMOUNT) in vfs_create_mount()
1188 mnt->mnt.mnt_flags = MNT_INTERNAL; in vfs_create_mount()
1190 setup_mnt(mnt, fc->root); in vfs_create_mount()
1192 return &mnt->mnt; in vfs_create_mount()
1200 up_write(&fc->root->d_sb->s_umount); in fc_mount()
1211 real_mount(mnt)->mnt_ns = MNT_NS_INTERNAL; in fc_mount_longterm()
1225 return ERR_PTR(-EINVAL); in vfs_kern_mount()
1251 mnt = alloc_vfsmnt(old->mnt_devname); in clone_mnt()
1253 return ERR_PTR(-ENOMEM); in clone_mnt()
1255 mnt->mnt.mnt_flags = READ_ONCE(old->mnt.mnt_flags) & in clone_mnt()
1259 mnt->mnt_group_id = 0; /* not a peer of original */ in clone_mnt()
1261 mnt->mnt_group_id = old->mnt_group_id; in clone_mnt()
1263 if ((flag & CL_MAKE_SHARED) && !mnt->mnt_group_id) { in clone_mnt()
1269 if (mnt->mnt_group_id) in clone_mnt()
1272 mnt->mnt.mnt_idmap = mnt_idmap_get(mnt_idmap(&old->mnt)); in clone_mnt()
1280 list_add(&mnt->mnt_share, &old->mnt_share); in clone_mnt()
1282 if ((flag & CL_SLAVE) && old->mnt_group_id) { in clone_mnt()
1283 hlist_add_head(&mnt->mnt_slave, &old->mnt_slave_list); in clone_mnt()
1284 mnt->mnt_master = old; in clone_mnt()
1286 hlist_add_behind(&mnt->mnt_slave, &old->mnt_slave); in clone_mnt()
1287 mnt->mnt_master = old->mnt_master; in clone_mnt()
1304 * filesystem was probably unable to make r/w->r/o transitions. in cleanup_mnt()
1309 if (unlikely(mnt->mnt_pins.first)) in cleanup_mnt()
1311 hlist_for_each_entry_safe(m, p, &mnt->mnt_stuck_children, mnt_umount) { in cleanup_mnt()
1312 hlist_del(&m->mnt_umount); in cleanup_mnt()
1313 mntput(&m->mnt); in cleanup_mnt()
1315 fsnotify_vfsmount_delete(&mnt->mnt); in cleanup_mnt()
1316 dput(mnt->mnt.mnt_root); in cleanup_mnt()
1317 deactivate_super(mnt->mnt.mnt_sb); in cleanup_mnt()
1319 call_rcu(&mnt->mnt_rcu, delayed_free_vfsmnt); in cleanup_mnt()
1343 VFS_BUG_ON(mnt->mnt_ns); in mntput_no_expire_slowpath()
1350 mnt_add_count(mnt, -1); in mntput_no_expire_slowpath()
1358 if (unlikely(mnt->mnt.mnt_flags & MNT_DOOMED)) { in mntput_no_expire_slowpath()
1363 mnt->mnt.mnt_flags |= MNT_DOOMED; in mntput_no_expire_slowpath()
1367 if (unlikely(!list_empty(&mnt->mnt_expire))) in mntput_no_expire_slowpath()
1368 list_del(&mnt->mnt_expire); in mntput_no_expire_slowpath()
1370 if (unlikely(!list_empty(&mnt->mnt_mounts))) { in mntput_no_expire_slowpath()
1372 list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts, mnt_child) { in mntput_no_expire_slowpath()
1374 hlist_add_head(&p->mnt_umount, &mnt->mnt_stuck_children); in mntput_no_expire_slowpath()
1380 if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) { in mntput_no_expire_slowpath()
1381 struct task_struct *task = current; in mntput_no_expire_slowpath()
1382 if (likely(!(task->flags & PF_KTHREAD))) { in mntput_no_expire_slowpath()
1383 init_task_work(&mnt->mnt_rcu, __cleanup_mnt); in mntput_no_expire_slowpath()
1384 if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME)) in mntput_no_expire_slowpath()
1387 if (llist_add(&mnt->mnt_llist, &delayed_mntput_list)) in mntput_no_expire_slowpath()
1397 if (likely(READ_ONCE(mnt->mnt_ns))) { in mntput_no_expire()
1400 * ->mnt_ns can change under us. However, if it's in mntput_no_expire()
1401 * non-NULL, then there's a reference that won't in mntput_no_expire()
1403 * turning ->mnt_ns NULL. So if we observe it in mntput_no_expire()
1404 * non-NULL under rcu_read_lock(), the reference in mntput_no_expire()
1407 mnt_add_count(mnt, -1); in mntput_no_expire()
1419 if (unlikely(m->mnt_expiry_mark)) in mntput()
1420 WRITE_ONCE(m->mnt_expiry_mark, 0); in mntput()
1436 * Because there may still be current users, the caller MUST WAIT
1442 WRITE_ONCE(real_mount(mnt)->mnt_ns, NULL); in mnt_make_shortterm()
1446 * path_is_mountpoint() - Check if path is a mount in the current namespace.
1447 * @path: path to check
1453 * checks if the passed in path is a mountpoint rather than the dentry
1456 bool path_is_mountpoint(const struct path *path) in path_is_mountpoint() argument
1461 if (!d_mountpoint(path->dentry)) in path_is_mountpoint()
1467 res = __path_is_mountpoint(path); in path_is_mountpoint()
1475 struct vfsmount *mnt_clone_internal(const struct path *path) in mnt_clone_internal() argument
1478 p = clone_mnt(real_mount(path->mnt), path->dentry, CL_PRIVATE); in mnt_clone_internal()
1481 p->mnt.mnt_flags |= MNT_INTERNAL; in mnt_clone_internal()
1482 return &p->mnt; in mnt_clone_internal()
1491 struct rb_node *node = ns->mounts.rb_node; in mnt_find_id_at()
1497 if (mnt_id <= m->mnt_id_unique) { in mnt_find_id_at()
1499 if (mnt_id == m->mnt_id_unique) in mnt_find_id_at()
1501 node = node->rb_left; in mnt_find_id_at()
1503 node = node->rb_right; in mnt_find_id_at()
1515 struct rb_node *node = ns->mounts.rb_node; in mnt_find_id_at_reverse()
1521 if (mnt_id >= m->mnt_id_unique) { in mnt_find_id_at_reverse()
1523 if (mnt_id == m->mnt_id_unique) in mnt_find_id_at_reverse()
1525 node = node->rb_right; in mnt_find_id_at_reverse()
1527 node = node->rb_left; in mnt_find_id_at_reverse()
1538 struct proc_mounts *p = m->private; in m_start()
1543 mnt = mnt_find_id_at(p->ns, *pos); in m_start()
1545 *pos = mnt->mnt_id_unique; in m_start()
1552 struct rb_node *node = rb_next(&mnt->mnt_node); in m_next()
1556 *pos = next->mnt_id_unique; in m_next()
1561 * No more mounts. Set pos past current mount's ID so that if in m_next()
1564 *pos = mnt->mnt_id_unique + 1; in m_next()
1575 struct proc_mounts *p = m->private; in m_show()
1577 return p->show(m, &r->mnt); in m_show()
1590 * may_umount_tree - check if a mount tree is busy
1618 * may_umount - check if a mount point is busy
1628 * a non-destructive way to look for easily umountable filesystems.
1647 if (!p->prev_ns && p->mnt_ns) { in mnt_notify()
1648 fsnotify_mnt_attach(p->mnt_ns, &p->mnt); in mnt_notify()
1649 } else if (p->prev_ns && !p->mnt_ns) { in mnt_notify()
1650 fsnotify_mnt_detach(p->prev_ns, &p->mnt); in mnt_notify()
1651 } else if (p->prev_ns == p->mnt_ns) { in mnt_notify()
1652 fsnotify_mnt_move(p->mnt_ns, &p->mnt); in mnt_notify()
1654 fsnotify_mnt_detach(p->prev_ns, &p->mnt); in mnt_notify()
1655 fsnotify_mnt_attach(p->mnt_ns, &p->mnt); in mnt_notify()
1657 p->prev_ns = p->mnt_ns; in mnt_notify()
1669 list_del_init(&m->to_notify); in notify_mnt_list()
1727 hlist_del(&m->mnt_umount); in namespace_unlock()
1728 mntput(&m->mnt); in namespace_unlock()
1757 if (!(mnt->mnt_parent->mnt.mnt_flags & MNT_UMOUNT)) in disconnect_mount()
1786 p->mnt.mnt_flags |= MNT_UMOUNT; in umount_tree()
1789 list_add_tail(&p->mnt_list, &tmp_list); in umount_tree()
1794 list_del_init(&p->mnt_child); in umount_tree()
1807 list_del_init(&p->mnt_expire); in umount_tree()
1808 list_del_init(&p->mnt_list); in umount_tree()
1809 ns = p->mnt_ns; in umount_tree()
1811 ns->nr_mounts--; in umount_tree()
1814 WRITE_ONCE(p->mnt_ns, NULL); in umount_tree()
1816 p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; in umount_tree()
1822 list_add_tail(&p->mnt_child, &p->mnt_parent->mnt_mounts); in umount_tree()
1828 hlist_add_head(&p->mnt_umount, &unmounted); in umount_tree()
1831 * At this point p->mnt_ns is NULL, notification will be queued in umount_tree()
1834 * - p->prev_ns is non-NULL *and* in umount_tree()
1835 * - p->prev_ns->n_fsnotify_marks is non-NULL in umount_tree()
1851 down_write(&sb->s_umount); in do_umount_root()
1855 fc = fs_context_for_reconfigure(sb->s_root, SB_RDONLY, in do_umount_root()
1866 up_write(&sb->s_umount); in do_umount_root()
1872 struct super_block *sb = mnt->mnt.mnt_sb; in do_umount()
1875 retval = security_sb_umount(&mnt->mnt, flags); in do_umount()
1886 if (&mnt->mnt == current->fs->root.mnt || in do_umount()
1888 return -EINVAL; in do_umount()
1895 if (!list_empty(&mnt->mnt_mounts) || mnt_get_count(mnt) != 2) { in do_umount()
1897 return -EBUSY; in do_umount()
1901 if (!xchg(&mnt->mnt_expiry_mark, 1)) in do_umount()
1902 return -EAGAIN; in do_umount()
1915 if (flags & MNT_FORCE && sb->s_op->umount_begin) { in do_umount()
1916 sb->s_op->umount_begin(sb); in do_umount()
1922 * Ho-hum... In principle, we might treat that as umount + switch in do_umount()
1925 * /reboot - static binary that would close all descriptors and in do_umount()
1928 if (&mnt->mnt == current->fs->root.mnt && !(flags & MNT_DETACH)) { in do_umount()
1933 if (!ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) in do_umount()
1934 return -EPERM; in do_umount()
1942 retval = -EINVAL; in do_umount()
1946 if (mnt->mnt.mnt_flags & MNT_LOCKED) in do_umount()
1959 retval = -EBUSY; in do_umount()
1972 * __detach_mounts - lazily unmount all mounts on the specified dentry
1974 * During unlink, rmdir, and d_drop it is possible to loose the path
1979 * The caller may hold dentry->d_inode->i_rwsem.
1995 if (mnt->mnt.mnt_flags & MNT_UMOUNT) { in __detach_mounts()
1997 hlist_add_head(&mnt->mnt_umount, &unmounted); in __detach_mounts()
2009 return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN); in may_mount()
2021 static int can_umount(const struct path *path, int flags) in can_umount() argument
2023 struct mount *mnt = real_mount(path->mnt); in can_umount()
2024 struct super_block *sb = path->dentry->d_sb; in can_umount()
2027 return -EPERM; in can_umount()
2028 if (!path_mounted(path)) in can_umount()
2029 return -EINVAL; in can_umount()
2031 return -EINVAL; in can_umount()
2032 if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */ in can_umount()
2033 return -EINVAL; in can_umount()
2034 if (flags & MNT_FORCE && !ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) in can_umount()
2035 return -EPERM; in can_umount()
2040 int path_umount(const struct path *path, int flags) in path_umount() argument
2042 struct mount *mnt = real_mount(path->mnt); in path_umount()
2045 ret = can_umount(path, flags); in path_umount()
2050 dput(path->dentry); in path_umount()
2058 struct path path; in ksys_umount() local
2063 return -EINVAL; in ksys_umount()
2067 ret = user_path_at(AT_FDCWD, name, lookup_flags, &path); in ksys_umount()
2070 return path_umount(&path, flags); in ksys_umount()
2095 if (dentry->d_op != &ns_dentry_operations) in is_mnt_ns_file()
2098 ns = d_inode(dentry)->i_private; in is_mnt_ns_file()
2100 return ns->ops == &mntns_operations; in is_mnt_ns_file()
2105 return &mnt->ns; in from_mnt_ns()
2126 if (!ns_capable_noaudit(mntns->user_ns, CAP_SYS_ADMIN)) in get_sequential_mnt_ns()
2146 return to_mnt_ns(get_proc_ns(dentry->d_inode)); in mnt_ns_from_dentry()
2159 return current->nsproxy->mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id; in mnt_ns_loop()
2169 return ERR_PTR(-EINVAL); in copy_tree()
2172 return ERR_PTR(-EINVAL); in copy_tree()
2180 list_for_each_entry(src_root_child, &src_root->mnt_mounts, mnt_child) { in copy_tree()
2181 if (!is_subdir(src_root_child->mnt_mountpoint, dentry)) in copy_tree()
2188 if (src_mnt->mnt.mnt_flags & MNT_LOCKED) { in copy_tree()
2190 dst_mnt = ERR_PTR(-EPERM); in copy_tree()
2198 is_mnt_ns_file(src_mnt->mnt.mnt_root)) { in copy_tree()
2202 while (src_parent != src_mnt->mnt_parent) { in copy_tree()
2203 src_parent = src_parent->mnt_parent; in copy_tree()
2204 dst_mnt = dst_mnt->mnt_parent; in copy_tree()
2209 dst_mnt = clone_mnt(src_mnt, src_mnt->mnt.mnt_root, flag); in copy_tree()
2213 if (src_mnt->mnt.mnt_flags & MNT_LOCKED) in copy_tree()
2214 dst_mnt->mnt.mnt_flags |= MNT_LOCKED; in copy_tree()
2218 if (!list_empty(&src_mnt->mnt_expire)) in copy_tree()
2219 list_add(&dst_mnt->mnt_expire, in copy_tree()
2220 &src_mnt->mnt_expire); in copy_tree()
2222 attach_mnt(dst_mnt, dst_parent, src_parent->mnt_mp); in copy_tree()
2237 static inline bool extend_array(struct path **res, struct path **to_free, in extend_array()
2240 struct path *p; in extend_array()
2244 p = kmalloc_objs(struct path, new_count); in extend_array()
2246 memcpy(p, *res, *count * sizeof(struct path)); in extend_array()
2253 const struct path *collect_paths(const struct path *path, in collect_paths() argument
2254 struct path *prealloc, unsigned count) in collect_paths()
2256 struct mount *root = real_mount(path->mnt); in collect_paths()
2258 struct path *res = prealloc, *to_free = NULL; in collect_paths()
2264 return ERR_PTR(-EINVAL); in collect_paths()
2266 return ERR_PTR(-ENOMEM); in collect_paths()
2267 res[n++] = *path; in collect_paths()
2268 list_for_each_entry(child, &root->mnt_mounts, mnt_child) { in collect_paths()
2269 if (!is_subdir(child->mnt_mountpoint, path->dentry)) in collect_paths()
2273 return ERR_PTR(-ENOMEM); in collect_paths()
2274 res[n].mnt = &m->mnt; in collect_paths()
2275 res[n].dentry = m->mnt.mnt_root; in collect_paths()
2280 return ERR_PTR(-ENOMEM); in collect_paths()
2281 memset(res + n, 0, (count - n) * sizeof(struct path)); in collect_paths()
2282 for (struct path *p = res; p->mnt; p++) in collect_paths()
2287 void drop_collected_paths(const struct path *paths, const struct path *prealloc) in drop_collected_paths()
2289 for (const struct path *p = paths; p->mnt; p++) in drop_collected_paths()
2305 * that there's nothing to do without it - rcu_read_lock() is in dissolve_on_fput()
2306 * enough to make anon_ns_root() memory-safe and once m has in dissolve_on_fput()
2320 emptied_ns = m->mnt_ns; in dissolve_on_fput()
2332 list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { in __has_locked_children()
2333 if (!is_subdir(child->mnt_mountpoint, dentry)) in __has_locked_children()
2336 if (child->mnt.mnt_flags & MNT_LOCKED) in __has_locked_children()
2351 * that aren't checked by the mount-cycle checking code, thereby allowing
2359 if (mnt_ns_loop(p->mnt.mnt_root)) in check_for_nsfs_mounts()
2365 * clone_private_mount - create a private clone of a path
2366 * @path: path to clone
2368 * This creates a new vfsmount, which will be the clone of @path. The new mount
2376 struct vfsmount *clone_private_mount(const struct path *path) in clone_private_mount() argument
2378 struct mount *old_mnt = real_mount(path->mnt); in clone_private_mount()
2384 return ERR_PTR(-EINVAL); in clone_private_mount()
2395 return ERR_PTR(-EINVAL); in clone_private_mount()
2398 return ERR_PTR(-EINVAL); in clone_private_mount()
2401 if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN)) in clone_private_mount()
2402 return ERR_PTR(-EPERM); in clone_private_mount()
2404 if (__has_locked_children(old_mnt, path->dentry)) in clone_private_mount()
2405 return ERR_PTR(-EINVAL); in clone_private_mount()
2407 new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE); in clone_private_mount()
2409 return ERR_PTR(-EINVAL); in clone_private_mount()
2412 new_mnt->mnt_ns = MNT_NS_INTERNAL; in clone_private_mount()
2413 return &new_mnt->mnt; in clone_private_mount()
2422 int flags = p->mnt.mnt_flags; in lock_mnt_tree()
2438 if (list_empty(&p->mnt_expire) && p != mnt) in lock_mnt_tree()
2440 p->mnt.mnt_flags = flags; in lock_mnt_tree()
2449 if (p->mnt_group_id && !IS_MNT_SHARED(p)) in cleanup_group_ids()
2459 if (!p->mnt_group_id) { in invent_group_ids()
2477 if (ns->nr_mounts >= max) in count_mounts()
2478 return -ENOSPC; in count_mounts()
2479 max -= ns->nr_mounts; in count_mounts()
2480 if (ns->pending_mounts >= max) in count_mounts()
2481 return -ENOSPC; in count_mounts()
2482 max -= ns->pending_mounts; in count_mounts()
2488 return -ENOSPC; in count_mounts()
2490 ns->pending_mounts += mounts; in count_mounts()
2500 * attach_recursive_mnt - attach a source mount tree
2506 * ---------------------------------------------------------------------------
2509 * | source-->| shared | private | slave | unbindable |
2516 * |non-shared| shared (+) | private | slave (*) | invalid |
2534 * ---------------------------------------------------------------------------
2537 * | source-->| shared | private | slave | unbindable |
2544 * |non-shared| shared (+*) | private | slave (*) | unbindable |
2567 struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns; in attach_recursive_mnt()
2568 struct mount *dest_mnt = dest->parent; in attach_recursive_mnt()
2569 struct mountpoint *dest_mp = dest->mp; in attach_recursive_mnt()
2571 struct mnt_namespace *ns = dest_mnt->mnt_ns; in attach_recursive_mnt()
2584 for (top = source_mnt; unlikely(top->overmount); top = top->overmount) { in attach_recursive_mnt()
2585 if (!shorter && is_mnt_ns_file(top->mnt.mnt_root)) in attach_recursive_mnt()
2586 shorter = top->mnt_mp; in attach_recursive_mnt()
2588 err = get_mountpoint(top->mnt.mnt_root, &root); in attach_recursive_mnt()
2619 list_del_init(&source_mnt->mnt_expire); in attach_recursive_mnt()
2621 if (source_mnt->mnt_ns) { in attach_recursive_mnt()
2622 /* move from anon - the caller will destroy */ in attach_recursive_mnt()
2623 emptied_ns = source_mnt->mnt_ns; in attach_recursive_mnt()
2631 * Now the original copy is in the same state as the secondaries - in attach_recursive_mnt()
2637 hlist_add_head(&source_mnt->mnt_hash, &tree_list); in attach_recursive_mnt()
2641 hlist_del_init(&child->mnt_hash); in attach_recursive_mnt()
2643 if (child->mnt_parent->mnt_ns->user_ns != user_ns) in attach_recursive_mnt()
2645 q = __lookup_mnt(&child->mnt_parent->mnt, in attach_recursive_mnt()
2646 child->mnt_mountpoint); in attach_recursive_mnt()
2664 child->mnt.mnt_flags |= MNT_LOCKED; in attach_recursive_mnt()
2665 q->mnt.mnt_flags &= ~MNT_LOCKED; in attach_recursive_mnt()
2678 child->mnt_parent->mnt_ns->pending_mounts = 0; in attach_recursive_mnt()
2684 ns->pending_mounts = 0; in attach_recursive_mnt()
2693 static inline struct mount *where_to_mount(const struct path *path, in where_to_mount() argument
2700 m = topmost_overmount(real_mount(path->mnt)); in where_to_mount()
2701 *dentry = m->mnt_mountpoint; in where_to_mount()
2702 return m->mnt_parent; in where_to_mount()
2704 m = __lookup_mnt(path->mnt, path->dentry); in where_to_mount()
2707 *dentry = m->mnt.mnt_root; in where_to_mount()
2710 *dentry = path->dentry; in where_to_mount()
2711 return real_mount(path->mnt); in where_to_mount()
2715 * do_lock_mount - acquire environment for mounting
2716 * @path: target path
2718 * @beneath: whether the intention is to mount beneath @path
2726 * Results are stored in caller-supplied context (pinned_mountpoint);
2727 * on success we have res->parent and res->mp pointing to parent and
2728 * mountpoint respectively and res->node inserted into the ->m_list
2730 * On failure we have res->parent set to ERR_PTR(-E...), res->mp
2731 * left NULL, res->node - empty.
2733 * proper order - inode lock nests outside of namespace_sem).
2737 * a location - "mount immediately beneath the topmost mount at that
2745 static void do_lock_mount(const struct path *path, in do_lock_mount() argument
2751 if (unlikely(beneath) && !path_mounted(path)) { in do_lock_mount()
2752 res->parent = ERR_PTR(-EINVAL); in do_lock_mount()
2761 m = where_to_mount(path, &dentry, beneath); in do_lock_mount()
2762 if (&m->mnt != path->mnt) { in do_lock_mount()
2763 mntget(&m->mnt); in do_lock_mount()
2768 inode_lock(dentry->d_inode); in do_lock_mount()
2773 n = where_to_mount(path, &d, beneath); in do_lock_mount()
2776 err = -EAGAIN; // something moved, retry in do_lock_mount()
2777 else if (unlikely(cant_mount(dentry) || !is_mounted(path->mnt))) in do_lock_mount()
2778 err = -ENOENT; // not to be mounted on in do_lock_mount()
2779 else if (beneath && &m->mnt == path->mnt && !m->overmount) in do_lock_mount()
2780 err = -EINVAL; in do_lock_mount()
2785 res->parent = ERR_PTR(err); in do_lock_mount()
2787 inode_unlock(dentry->d_inode); in do_lock_mount()
2789 res->parent = m; in do_lock_mount()
2792 * Drop the temporary references. This is subtle - on success in do_lock_mount()
2795 * refcounts won't reach zero, since we know that path->mnt in do_lock_mount()
2799 if (&m->mnt != path->mnt) { in do_lock_mount()
2801 mntput(&m->mnt); in do_lock_mount()
2803 } while (err == -EAGAIN); in do_lock_mount()
2808 inode_unlock(m->mp->m_dentry->d_inode); in __unlock_mount()
2817 if (!IS_ERR(m->parent)) in unlock_mount()
2821 static void lock_mount_exact(const struct path *path,
2825 #define LOCK_MOUNT_MAYBE_BENEATH(mp, path, beneath) \ argument
2827 do_lock_mount((path), &mp, (beneath))
2828 #define LOCK_MOUNT(mp, path) LOCK_MOUNT_MAYBE_BENEATH(mp, (path), false) argument
2829 #define LOCK_MOUNT_EXACT(mp, path) \ argument
2831 lock_mount_exact((path), &mp, false, 0)
2832 #define LOCK_MOUNT_EXACT_COPY(mp, path, copy_flags) \ argument
2834 lock_mount_exact((path), &mp, true, (copy_flags))
2838 if (mnt->mnt.mnt_sb->s_flags & SB_NOUSER) in graft_tree()
2839 return -EINVAL; in graft_tree()
2841 if (d_is_dir(mp->mp->m_dentry) != in graft_tree()
2842 d_is_dir(mnt->mnt.mnt_root)) in graft_tree()
2843 return -ENOTDIR; in graft_tree()
2850 struct mnt_namespace *ns = m->mnt_ns; in may_change_propagation()
2854 return -EINVAL; in may_change_propagation()
2856 if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN)) in may_change_propagation()
2857 return -EPERM; in may_change_propagation()
2869 /* Fail if any non-propagation flags are set */ in flags_to_propagation_type()
2881 static int do_change_type(const struct path *path, int ms_flags) in do_change_type() argument
2884 struct mount *mnt = real_mount(path->mnt); in do_change_type()
2889 if (!path_mounted(path)) in do_change_type()
2890 return -EINVAL; in do_change_type()
2894 return -EINVAL; in do_change_type()
2912 touch_mnt_namespace(mnt->mnt_ns); in do_change_type()
2917 /* may_copy_tree() - check if a mount tree can be copied
2918 * @path: path to the mount tree to be copied
2921 * from @path->mnt. The caller may copy the mount tree under the
2939 * This is not strictly necessary. The current semantics of the new
2946 * The ownership of a non-anonymous mount namespace such as the
2960 static inline bool may_copy_tree(const struct path *path) in may_copy_tree() argument
2962 struct mount *mnt = real_mount(path->mnt); in may_copy_tree()
2968 d_op = path->dentry->d_op; in may_copy_tree()
2975 if (!is_mounted(path->mnt)) in may_copy_tree()
2981 static struct mount *__do_loopback(const struct path *old_path, in __do_loopback()
2984 struct mount *old = real_mount(old_path->mnt); in __do_loopback()
2987 return ERR_PTR(-EINVAL); in __do_loopback()
2990 return ERR_PTR(-EINVAL); in __do_loopback()
2992 if (!recurse && __has_locked_children(old, old_path->dentry)) in __do_loopback()
2993 return ERR_PTR(-EINVAL); in __do_loopback()
2996 return copy_tree(old, old_path->dentry, copy_flags); in __do_loopback()
2998 return clone_mnt(old, old_path->dentry, copy_flags); in __do_loopback()
3004 static int do_loopback(const struct path *path, const char *old_name, in do_loopback() argument
3007 struct path old_path __free(path_put) = {}; in do_loopback()
3012 return -EINVAL; in do_loopback()
3018 return -EINVAL; in do_loopback()
3020 LOCK_MOUNT(mp, path); in do_loopback()
3025 return -EINVAL; in do_loopback()
3040 static struct mnt_namespace *get_detached_copy(const struct path *path, unsigned int flags) in get_detached_copy() argument
3042 struct mnt_namespace *ns, *mnt_ns = current->nsproxy->mnt_ns, *src_mnt_ns; in get_detached_copy()
3043 struct user_namespace *user_ns = mnt_ns->user_ns; in get_detached_copy()
3057 if (is_mounted(path->mnt)) { in get_detached_copy()
3058 src_mnt_ns = real_mount(path->mnt)->mnt_ns; in get_detached_copy()
3060 ns->seq_origin = src_mnt_ns->seq_origin; in get_detached_copy()
3062 ns->seq_origin = src_mnt_ns->ns.ns_id; in get_detached_copy()
3065 mnt = __do_loopback(path, (flags & AT_RECURSIVE), CL_COPY_MNT_NS_FILE); in get_detached_copy()
3073 ns->nr_mounts++; in get_detached_copy()
3075 ns->root = mnt; in get_detached_copy()
3079 static struct file *open_detached_copy(struct path *path, unsigned int flags) in open_detached_copy() argument
3081 struct mnt_namespace *ns = get_detached_copy(path, flags); in open_detached_copy()
3087 mntput(path->mnt); in open_detached_copy()
3088 path->mnt = mntget(&ns->root->mnt); in open_detached_copy()
3089 file = dentry_open(path, O_PATH, current_cred()); in open_detached_copy()
3091 dissolve_on_fput(path->mnt); in open_detached_copy()
3093 file->f_mode |= FMODE_NEED_UNMOUNT; in open_detached_copy()
3102 static struct mnt_namespace *create_new_namespace(struct path *path, in create_new_namespace() argument
3105 struct mnt_namespace *ns = current->nsproxy->mnt_ns; in create_new_namespace()
3109 struct path to_path; in create_new_namespace()
3114 if (unlikely(!d_can_lookup(path->dentry))) in create_new_namespace()
3115 return ERR_PTR(-ENOTDIR); in create_new_namespace()
3117 if (user_ns != ns->user_ns) in create_new_namespace()
3124 old_ns_root = ns->root; in create_new_namespace()
3125 to_path.mnt = &old_ns_root->mnt; in create_new_namespace()
3126 to_path.dentry = old_ns_root->mnt.mnt_root; in create_new_namespace()
3128 VFS_WARN_ON_ONCE(old_ns_root->mnt.mnt_sb->s_type != &nullfs_fs_type); in create_new_namespace()
3143 while (mnt->overmount) { in create_new_namespace()
3144 mnt = mnt->overmount; in create_new_namespace()
3145 if (mnt->mnt.mnt_flags & MNT_LOCKED) in create_new_namespace()
3151 * the restrictions of creating detached bind-mounts. It has a in create_new_namespace()
3155 mnt = clone_mnt(real_mount(path->mnt), path->dentry, copy_flags); in create_new_namespace()
3157 mnt = __do_loopback(path, recurse, copy_flags); in create_new_namespace()
3166 mnt->mnt.mnt_flags |= MNT_LOCKED; in create_new_namespace()
3172 if (user_ns != ns->user_ns) in create_new_namespace()
3178 new_ns->nr_mounts++; in create_new_namespace()
3181 new_ns->root = new_ns_root; in create_new_namespace()
3186 static struct file *open_new_namespace(struct path *path, in open_new_namespace() argument
3191 new_ns = create_new_namespace(path, flags); in open_new_namespace()
3200 struct path path __free(path_put) = {}; in vfs_open_tree()
3208 return ERR_PTR(-EINVAL); in vfs_open_tree()
3212 return ERR_PTR(-EINVAL); in vfs_open_tree()
3215 return ERR_PTR(-EINVAL); in vfs_open_tree()
3224 * just care about being privileged over our current user namespace. in vfs_open_tree()
3229 return ERR_PTR(-EPERM); in vfs_open_tree()
3232 return ERR_PTR(-EPERM); in vfs_open_tree()
3235 ret = filename_lookup(dfd, name, lookup_flags, &path, NULL); in vfs_open_tree()
3240 return open_new_namespace(&path, (flags & AT_RECURSIVE) ? MOUNT_COPY_RECURSIVE : 0); in vfs_open_tree()
3243 return open_detached_copy(&path, flags); in vfs_open_tree()
3245 return dentry_open(&path, O_PATH, current_cred()); in vfs_open_tree()
3261 unsigned int fl = mnt->mnt.mnt_flags; in can_change_locked_flags()
3290 if (readonly_request == __mnt_is_readonly(&mnt->mnt)) in change_mount_ro_state()
3296 mnt->mnt.mnt_flags &= ~MNT_READONLY; in change_mount_ro_state()
3302 mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK; in set_mount_attributes()
3303 mnt->mnt.mnt_flags = mnt_flags; in set_mount_attributes()
3304 touch_mnt_namespace(mnt->mnt_ns); in set_mount_attributes()
3307 static void mnt_warn_timestamp_expiry(const struct path *mountpoint, in mnt_warn_timestamp_expiry()
3310 struct super_block *sb = mnt->mnt_sb; in mnt_warn_timestamp_expiry()
3313 (!(sb->s_iflags & SB_I_TS_EXPIRY_WARNED)) && in mnt_warn_timestamp_expiry()
3314 (ktime_get_real_seconds() + TIME_UPTIME_SEC_MAX > sb->s_time_max)) { in mnt_warn_timestamp_expiry()
3321 mntpath = ERR_PTR(-ENOMEM); in mnt_warn_timestamp_expiry()
3326 sb->s_type->name, in mnt_warn_timestamp_expiry()
3328 mntpath, &sb->s_time_max, in mnt_warn_timestamp_expiry()
3329 (unsigned long long)sb->s_time_max); in mnt_warn_timestamp_expiry()
3331 sb->s_iflags |= SB_I_TS_EXPIRY_WARNED; in mnt_warn_timestamp_expiry()
3341 static int do_reconfigure_mnt(const struct path *path, unsigned int mnt_flags) in do_reconfigure_mnt() argument
3343 struct super_block *sb = path->mnt->mnt_sb; in do_reconfigure_mnt()
3344 struct mount *mnt = real_mount(path->mnt); in do_reconfigure_mnt()
3348 return -EINVAL; in do_reconfigure_mnt()
3350 if (!path_mounted(path)) in do_reconfigure_mnt()
3351 return -EINVAL; in do_reconfigure_mnt()
3354 return -EPERM; in do_reconfigure_mnt()
3357 * We're only checking whether the superblock is read-only not in do_reconfigure_mnt()
3358 * changing it, so only take down_read(&sb->s_umount). in do_reconfigure_mnt()
3360 down_read(&sb->s_umount); in do_reconfigure_mnt()
3366 up_read(&sb->s_umount); in do_reconfigure_mnt()
3368 mnt_warn_timestamp_expiry(path, &mnt->mnt); in do_reconfigure_mnt()
3375 * If you've mounted a non-root directory somewhere and want to do remount
3376 * on it - tough luck.
3378 static int do_remount(const struct path *path, int sb_flags, in do_remount() argument
3382 struct super_block *sb = path->mnt->mnt_sb; in do_remount()
3383 struct mount *mnt = real_mount(path->mnt); in do_remount()
3387 return -EINVAL; in do_remount()
3389 if (!path_mounted(path)) in do_remount()
3390 return -EINVAL; in do_remount()
3393 return -EPERM; in do_remount()
3395 fc = fs_context_for_reconfigure(path->dentry, sb_flags, MS_RMT_MASK); in do_remount()
3403 fc->oldapi = true; in do_remount()
3407 down_write(&sb->s_umount); in do_remount()
3408 err = -EPERM; in do_remount()
3409 if (ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) { in do_remount()
3417 up_write(&sb->s_umount); in do_remount()
3420 mnt_warn_timestamp_expiry(path, &mnt->mnt); in do_remount()
3436 static int do_set_group(const struct path *from_path, const struct path *to_path) in do_set_group()
3438 struct mount *from = real_mount(from_path->mnt); in do_set_group()
3439 struct mount *to = real_mount(to_path->mnt); in do_set_group()
3453 return -EINVAL; in do_set_group()
3455 return -EINVAL; in do_set_group()
3458 if (from->mnt.mnt_sb != to->mnt.mnt_sb) in do_set_group()
3459 return -EINVAL; in do_set_group()
3462 if (!is_subdir(to->mnt.mnt_root, from->mnt.mnt_root)) in do_set_group()
3463 return -EINVAL; in do_set_group()
3466 if (__has_locked_children(from, to->mnt.mnt_root)) in do_set_group()
3467 return -EINVAL; in do_set_group()
3471 return -EINVAL; in do_set_group()
3475 return -EINVAL; in do_set_group()
3478 hlist_add_behind(&to->mnt_slave, &from->mnt_slave); in do_set_group()
3479 to->mnt_master = from->mnt_master; in do_set_group()
3483 to->mnt_group_id = from->mnt_group_id; in do_set_group()
3484 list_add(&to->mnt_share, &from->mnt_share); in do_set_group()
3489 touch_mnt_namespace(to->mnt_ns); in do_set_group()
3495 * path_overmounted - check if path is overmounted
3496 * @path: path to check
3498 * Check if path is overmounted, i.e., if there's a mount on top of
3499 * @path->mnt with @path->dentry as mountpoint.
3504 * Return: If path is overmounted true is returned, false if not.
3506 static inline bool path_overmounted(const struct path *path) in path_overmounted() argument
3512 no_child = !__lookup_mnt(path->mnt, path->dentry); in path_overmounted()
3516 no_child = !__lookup_mnt(path->mnt, path->dentry); in path_overmounted()
3529 p2 = p2->mnt_parent; in mount_is_ancestor()
3534 * can_move_mount_beneath - check that we can mount beneath the top mount
3539 * - Make sure that the caller can unmount the topmost mount ensuring
3541 * - Ensure that nothing has been mounted on top of @mnt_from before we
3543 * - Prevent mounting beneath a mount if the propagation relationship
3554 struct mount *parent_mnt_to = mnt_to->mnt_parent; in can_move_mount_beneath()
3557 if (mnt_from->overmount) in can_move_mount_beneath()
3558 return -EINVAL; in can_move_mount_beneath()
3561 return -EINVAL; in can_move_mount_beneath()
3565 * mean mounting @mnt_from on @mnt_to->mnt_parent and then in can_move_mount_beneath()
3569 if (propagation_would_overmount(parent_mnt_to, mnt_to, mp->mp)) in can_move_mount_beneath()
3570 return -EINVAL; in can_move_mount_beneath()
3573 * If @mnt_to->mnt_parent propagates to @mnt_from this would in can_move_mount_beneath()
3576 * @mnt_to->mnt_parent and @mnt_to would be unmounted from in can_move_mount_beneath()
3577 * @mnt->mnt_parent and remounted on @mnt_from. But since @c is in can_move_mount_beneath()
3585 propagation_would_overmount(parent_mnt_to, mnt_from, mp->mp)) in can_move_mount_beneath()
3586 return -EINVAL; in can_move_mount_beneath()
3591 /* may_use_mount() - check if a mount tree can be used
3595 * from @path->mnt. The caller may use the mount tree under the
3609 * The ownership of a non-anonymous mount namespace such as the
3629 * Make sure that noone unmounted the target path or somehow in may_use_mount()
3633 if (!is_mounted(&mnt->mnt)) in may_use_mount()
3639 static int do_move_mount(const struct path *old_path, in do_move_mount()
3640 const struct path *new_path, in do_move_mount()
3643 struct mount *old = real_mount(old_path->mnt); in do_move_mount()
3648 return -EINVAL; in do_move_mount()
3650 if (d_is_dir(new_path->dentry) != d_is_dir(old_path->dentry)) in do_move_mount()
3651 return -EINVAL; in do_move_mount()
3661 return -EINVAL; in do_move_mount()
3663 if (IS_MNT_SHARED(old->mnt_parent)) in do_move_mount()
3664 return -EINVAL; in do_move_mount()
3667 return -EINVAL; in do_move_mount()
3673 return -EINVAL; in do_move_mount()
3675 * Bail out early if the target is within the same namespace - in do_move_mount()
3679 if (old->mnt_ns == mp.parent->mnt_ns) in do_move_mount()
3680 return -EINVAL; in do_move_mount()
3686 return -EINVAL; in do_move_mount()
3690 struct mount *over = real_mount(new_path->mnt); in do_move_mount()
3692 if (mp.parent != over->mnt_parent) in do_move_mount()
3693 over = mp.parent->overmount; in do_move_mount()
3704 return -EINVAL; in do_move_mount()
3706 return -ELOOP; in do_move_mount()
3708 return -ELOOP; in do_move_mount()
3713 static int do_move_mount_old(const struct path *path, const char *old_name) in do_move_mount_old() argument
3715 struct path old_path __free(path_put) = {}; in do_move_mount_old()
3719 return -EINVAL; in do_move_mount_old()
3725 return do_move_mount(&old_path, path, 0); in do_move_mount_old()
3734 struct mount *parent = mp->parent; in do_add_mount()
3744 return -EINVAL; in do_add_mount()
3746 if (!parent->mnt_ns) in do_add_mount()
3747 return -EINVAL; in do_add_mount()
3751 if (parent->mnt.mnt_sb == newmnt->mnt.mnt_sb && in do_add_mount()
3752 parent->mnt.mnt_root == mp->mp->m_dentry) in do_add_mount()
3753 return -EBUSY; in do_add_mount()
3755 if (d_is_symlink(newmnt->mnt.mnt_root)) in do_add_mount()
3756 return -EINVAL; in do_add_mount()
3758 newmnt->mnt.mnt_flags = mnt_flags; in do_add_mount()
3768 static int do_new_mount_fc(struct fs_context *fc, const struct path *mountpoint, in do_new_mount_fc()
3778 sb = fc->root->d_sb; in do_new_mount_fc()
3785 return -EPERM; in do_new_mount_fc()
3801 static int do_new_mount(const struct path *path, const char *fstype, in do_new_mount() argument
3811 return -EINVAL; in do_new_mount()
3815 return -ENODEV; in do_new_mount()
3817 if (type->fs_flags & FS_HAS_SUBTYPE) { in do_new_mount()
3823 return -EINVAL; in do_new_mount()
3837 fc->oldapi = true; in do_new_mount()
3846 err = -EPERM; in do_new_mount()
3848 err = do_new_mount_fc(fc, path, mnt_flags); in do_new_mount()
3854 static void lock_mount_exact(const struct path *path, in lock_mount_exact() argument
3858 struct dentry *dentry = path->dentry; in lock_mount_exact()
3862 VFS_WARN_ON_ONCE(copy_mount && !path_mounted(path)); in lock_mount_exact()
3864 inode_lock(dentry->d_inode); in lock_mount_exact()
3867 err = -ENOENT; in lock_mount_exact()
3868 else if (!copy_mount && path_overmounted(path)) in lock_mount_exact()
3869 err = -EBUSY; in lock_mount_exact()
3874 inode_unlock(dentry->d_inode); in lock_mount_exact()
3875 mp->parent = ERR_PTR(err); in lock_mount_exact()
3880 mp->parent = clone_mnt(real_mount(path->mnt), dentry, copy_flags); in lock_mount_exact()
3882 mp->parent = real_mount(path->mnt); in lock_mount_exact()
3883 if (unlikely(IS_ERR(mp->parent))) in lock_mount_exact()
3887 int finish_automount(struct vfsmount *__m, const struct path *path) in finish_automount() argument
3900 if (m->mnt_root == path->dentry) in finish_automount()
3901 return -ELOOP; in finish_automount()
3904 * we don't want to use LOCK_MOUNT() - in this case finding something in finish_automount()
3908 LOCK_MOUNT_EXACT(mp, path); in finish_automount()
3909 if (mp.parent == ERR_PTR(-EBUSY)) in finish_automount()
3912 err = do_add_mount(mnt, &mp, path->mnt->mnt_flags | MNT_SHRINKABLE); in finish_automount()
3919 * mnt_set_expiry - Put a mount on an expiration list
3926 list_add_tail(&real_mount(mnt)->mnt_expire, expiry_list); in mnt_set_expiry()
3948 * - already mounted in mark_mounts_for_expiry()
3949 * - only referenced by its parent vfsmount in mark_mounts_for_expiry()
3950 * - still marked for expiry (marked on the last call here; marks are in mark_mounts_for_expiry()
3954 if (!is_mounted(&mnt->mnt)) in mark_mounts_for_expiry()
3956 if (!xchg(&mnt->mnt_expiry_mark, 1) || in mark_mounts_for_expiry()
3959 list_move(&mnt->mnt_expire, &graveyard); in mark_mounts_for_expiry()
3963 touch_mnt_namespace(mnt->mnt_ns); in mark_mounts_for_expiry()
3983 next = this_parent->mnt_mounts.next; in select_submounts()
3985 while (next != &this_parent->mnt_mounts) { in select_submounts()
3989 next = tmp->next; in select_submounts()
3990 if (!(mnt->mnt.mnt_flags & MNT_SHRINKABLE)) in select_submounts()
3993 * Descend a level if the d_mounts list is non-empty. in select_submounts()
3995 if (!list_empty(&mnt->mnt_mounts)) { in select_submounts()
4001 list_move_tail(&mnt->mnt_expire, graveyard); in select_submounts()
4009 next = this_parent->mnt_child.next; in select_submounts()
4010 this_parent = this_parent->mnt_parent; in select_submounts()
4032 touch_mnt_namespace(m->mnt_ns); in shrink_submounts()
4048 return ERR_PTR(-ENOMEM); in copy_mount_options()
4056 offset = PAGE_SIZE - left; in copy_mount_options()
4062 left--; in copy_mount_options()
4068 return ERR_PTR(-EFAULT); in copy_mount_options()
4080 * Flags is a 32-bit value that allows up to 31 non-fs dependent flags to
4081 * be given to the mount() call (ie: read-only, no-dev, no-suid etc).
4084 * PAGE_SIZE-1 bytes, which can contain arbitrary fs-dependent
4087 * Pre-0.97 versions of mount() didn't have a flags word.
4089 * to have the magic value 0xC0ED, and this remained so until 2.4.0-test9.
4093 int path_mount(const char *dev_name, const struct path *path, in path_mount() argument
4105 ((char *)data_page)[PAGE_SIZE - 1] = 0; in path_mount()
4108 return -EINVAL; in path_mount()
4110 ret = security_sb_mount(dev_name, path, type_page, flags, data_page); in path_mount()
4114 return -EPERM; in path_mount()
4122 /* Separate the per-mountpoint flags */ in path_mount()
4145 mnt_flags |= path->mnt->mnt_flags & MNT_ATIME_MASK; in path_mount()
4158 return do_reconfigure_mnt(path, mnt_flags); in path_mount()
4160 return do_remount(path, sb_flags, mnt_flags, data_page); in path_mount()
4162 return do_loopback(path, dev_name, flags & MS_REC); in path_mount()
4164 return do_change_type(path, flags); in path_mount()
4166 return do_move_mount_old(path, dev_name); in path_mount()
4168 return do_new_mount(path, type_page, sb_flags, mnt_flags, dev_name, in path_mount()
4175 struct path path __free(path_put) = {}; in do_mount()
4178 ret = user_path_at(AT_FDCWD, dir_name, LOOKUP_FOLLOW, &path); in do_mount()
4181 return path_mount(dev_name, &path, type_page, flags, data_page); in do_mount()
4198 dec_mnt_namespaces(ns->ucounts); in free_mnt_ns()
4210 return ERR_PTR(-ENOSPC); in alloc_mnt_ns()
4215 return ERR_PTR(-ENOMEM); in alloc_mnt_ns()
4229 new_ns->is_anon = anon; in alloc_mnt_ns()
4230 refcount_set(&new_ns->passive, 1); in alloc_mnt_ns()
4231 new_ns->mounts = RB_ROOT; in alloc_mnt_ns()
4232 init_waitqueue_head(&new_ns->poll); in alloc_mnt_ns()
4233 new_ns->user_ns = get_user_ns(user_ns); in alloc_mnt_ns()
4234 new_ns->ucounts = ucounts; in alloc_mnt_ns()
4243 struct path old_root __free(path_put) = {}; in copy_mnt_ns()
4244 struct path old_pwd __free(path_put) = {}; in copy_mnt_ns()
4257 old = ns->root; in copy_mnt_ns()
4269 if (user_ns != ns->user_ns) in copy_mnt_ns()
4273 new = clone_mnt(old, old->mnt.mnt_root, copy_flags); in copy_mnt_ns()
4275 new = copy_tree(old, old->mnt.mnt_root, copy_flags); in copy_mnt_ns()
4280 if (user_ns != ns->user_ns) { in copy_mnt_ns()
4284 new_ns->root = new; in copy_mnt_ns()
4292 old_root = new_fs->root; in copy_mnt_ns()
4293 old_pwd = new_fs->pwd; in copy_mnt_ns()
4295 new_fs->root.mnt = mntget(&new->mnt); in copy_mnt_ns()
4296 new_fs->root.dentry = dget(new->mnt.mnt_root); in copy_mnt_ns()
4298 new_fs->pwd.mnt = mntget(&new->mnt); in copy_mnt_ns()
4299 new_fs->pwd.dentry = dget(new->mnt.mnt_root); in copy_mnt_ns()
4302 new_ns->nr_mounts++; in copy_mnt_ns()
4306 * the tsk->fs->* elements and marking new vfsmounts as in copy_mnt_ns()
4308 * private fs_struct, so tsk->fs->lock is not needed. in copy_mnt_ns()
4314 new_ns->nr_mounts++; in copy_mnt_ns()
4316 if (&p->mnt == new_fs->root.mnt) { in copy_mnt_ns()
4317 old_root.mnt = new_fs->root.mnt; in copy_mnt_ns()
4318 new_fs->root.mnt = mntget(&q->mnt); in copy_mnt_ns()
4320 if (&p->mnt == new_fs->pwd.mnt) { in copy_mnt_ns()
4321 old_pwd.mnt = new_fs->pwd.mnt; in copy_mnt_ns()
4322 new_fs->pwd.mnt = mntget(&q->mnt); in copy_mnt_ns()
4330 while (p->mnt.mnt_root != q->mnt.mnt_root) in copy_mnt_ns()
4343 struct path path; in mount_subtree() local
4351 ns->root = mnt; in mount_subtree()
4352 ns->nr_mounts++; in mount_subtree()
4355 err = vfs_path_lookup(m->mnt_root, m, in mount_subtree()
4356 name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path); in mount_subtree()
4364 s = path.mnt->mnt_sb; in mount_subtree()
4365 atomic_inc(&s->s_active); in mount_subtree()
4366 mntput(path.mnt); in mount_subtree()
4368 down_write(&s->s_umount); in mount_subtree()
4370 return path.dentry; in mount_subtree()
4440 * (specified by fs_fd) and attach to an open_tree-like file descriptor.
4445 struct path new_path __free(path_put) = {}; in SYSCALL_DEFINE3()
4454 return -EINVAL; in SYSCALL_DEFINE3()
4458 return -EPERM; in SYSCALL_DEFINE3()
4461 return -EPERM; in SYSCALL_DEFINE3()
4464 return -EINVAL; in SYSCALL_DEFINE3()
4478 return -EINVAL; in SYSCALL_DEFINE3()
4483 return -EBADF; in SYSCALL_DEFINE3()
4485 if (fd_file(f)->f_op != &fscontext_fops) in SYSCALL_DEFINE3()
4486 return -EINVAL; in SYSCALL_DEFINE3()
4488 fc = fd_file(f)->private_data; in SYSCALL_DEFINE3()
4490 ACQUIRE(mutex_intr, uapi_mutex)(&fc->uapi_mutex); in SYSCALL_DEFINE3()
4496 ret = -EINVAL; in SYSCALL_DEFINE3()
4497 if (!fc->root) in SYSCALL_DEFINE3()
4500 ret = -EPERM; in SYSCALL_DEFINE3()
4501 if (mount_too_revealing(fc->root->d_sb, &mnt_flags)) { in SYSCALL_DEFINE3()
4506 ret = -EBUSY; in SYSCALL_DEFINE3()
4507 if (fc->phase != FS_CONTEXT_AWAITING_MOUNT) in SYSCALL_DEFINE3()
4510 if (fc->sb_flags & SB_MANDLOCK) in SYSCALL_DEFINE3()
4516 if (new_mnt->mnt_sb->s_flags & SB_NOUSER) { in SYSCALL_DEFINE3()
4518 return -EINVAL; in SYSCALL_DEFINE3()
4520 new_mnt->mnt_flags = mnt_flags; in SYSCALL_DEFINE3()
4522 new_path.dentry = dget(fc->root); in SYSCALL_DEFINE3()
4525 /* We've done the mount bit - now move the file context into more or in SYSCALL_DEFINE3()
4536 ns = alloc_mnt_ns(current->nsproxy->mnt_ns->user_ns, true); in SYSCALL_DEFINE3()
4540 ns->root = mnt; in SYSCALL_DEFINE3()
4541 ns->nr_mounts = 1; in SYSCALL_DEFINE3()
4546 dentry_open(&new_path, O_PATH, fc->cred)); in SYSCALL_DEFINE3()
4556 fd_prepare_file(fdf)->f_mode |= FMODE_NEED_UNMOUNT; in SYSCALL_DEFINE3()
4560 static inline int vfs_move_mount(const struct path *from_path, in vfs_move_mount()
4561 const struct path *to_path, in vfs_move_mount()
4589 struct path to_path __free(path_put) = {}; in SYSCALL_DEFINE5()
4590 struct path from_path __free(path_put) = {}; in SYSCALL_DEFINE5()
4596 return -EPERM; in SYSCALL_DEFINE5()
4599 return -EINVAL; in SYSCALL_DEFINE5()
4603 return -EINVAL; in SYSCALL_DEFINE5()
4616 return -EBADF; in SYSCALL_DEFINE5()
4618 to_path = fd_file(f_to)->f_path; in SYSCALL_DEFINE5()
4639 return -EBADF; in SYSCALL_DEFINE5()
4641 return vfs_move_mount(&fd_file(f_from)->f_path, &to_path, mflags); in SYSCALL_DEFINE5()
4657 * Return true if path is reachable from root
4662 const struct path *root) in is_path_reachable()
4664 while (&mnt->mnt != root->mnt && mnt_has_parent(mnt)) { in is_path_reachable()
4665 dentry = mnt->mnt_mountpoint; in is_path_reachable()
4666 mnt = mnt->mnt_parent; in is_path_reachable()
4668 return &mnt->mnt == root->mnt && is_subdir(dentry, root->dentry); in is_path_reachable()
4671 bool path_is_under(const struct path *path1, const struct path *path2) in path_is_under()
4674 return is_path_reachable(real_mount(path1->mnt), path1->dentry, path2); in path_is_under()
4678 int path_pivot_root(struct path *new, struct path *old) in path_pivot_root()
4680 struct path root __free(path_put) = {}; in path_pivot_root()
4685 return -EPERM; in path_pivot_root()
4691 get_fs_root(current->fs, &root); in path_pivot_root()
4698 new_mnt = real_mount(new->mnt); in path_pivot_root()
4700 ex_parent = new_mnt->mnt_parent; in path_pivot_root()
4701 root_parent = root_mnt->mnt_parent; in path_pivot_root()
4705 return -EINVAL; in path_pivot_root()
4707 return -EINVAL; in path_pivot_root()
4708 if (new_mnt->mnt.mnt_flags & MNT_LOCKED) in path_pivot_root()
4709 return -EINVAL; in path_pivot_root()
4710 if (d_unlinked(new->dentry)) in path_pivot_root()
4711 return -ENOENT; in path_pivot_root()
4713 return -EBUSY; /* loop, on the same file system */ in path_pivot_root()
4715 return -EINVAL; /* not a mountpoint */ in path_pivot_root()
4717 return -EINVAL; /* absolute root */ in path_pivot_root()
4719 return -EINVAL; /* not a mountpoint */ in path_pivot_root()
4721 return -EINVAL; /* absolute root */ in path_pivot_root()
4723 if (!is_path_reachable(old_mnt, old_mp.mp->m_dentry, new)) in path_pivot_root()
4724 return -EINVAL; in path_pivot_root()
4726 if (!is_path_reachable(new_mnt, new->dentry, &root)) in path_pivot_root()
4727 return -EINVAL; in path_pivot_root()
4730 if (root_mnt->mnt.mnt_flags & MNT_LOCKED) { in path_pivot_root()
4731 new_mnt->mnt.mnt_flags |= MNT_LOCKED; in path_pivot_root()
4732 root_mnt->mnt.mnt_flags &= ~MNT_LOCKED; in path_pivot_root()
4735 attach_mnt(new_mnt, root_parent, root_mnt->mnt_mp); in path_pivot_root()
4739 touch_mnt_namespace(current->nsproxy->mnt_ns); in path_pivot_root()
4741 list_del_init(&new_mnt->mnt_expire); in path_pivot_root()
4751 * Moves the root file system of the current process to the directory put_old,
4752 * makes new_root as the new root file system of the current process, and sets
4753 * root/cwd of all processes which had them on the current root to new_root.
4757 * same file system as the current process root. The put_old must be
4758 * underneath new_root, i.e. adding a non-zero number of /.. to the string
4767 * - we don't move root/cwd if they are not at the root (reason: if something
4769 * - it's okay to pick a root that isn't the root of a file system, e.g.
4771 * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root
4777 struct path new __free(path_put) = {}; in SYSCALL_DEFINE2()
4778 struct path old __free(path_put) = {}; in SYSCALL_DEFINE2()
4796 unsigned int flags = mnt->mnt.mnt_flags; in recalc_flags()
4799 flags &= ~kattr->attr_clr; in recalc_flags()
4801 flags |= kattr->attr_set; in recalc_flags()
4808 struct vfsmount *m = &mnt->mnt; in can_idmap_mount()
4809 struct user_namespace *fs_userns = m->mnt_sb->s_user_ns; in can_idmap_mount()
4811 if (!kattr->mnt_idmap) in can_idmap_mount()
4818 if (kattr->mnt_userns == m->mnt_sb->s_user_ns) in can_idmap_mount()
4819 return -EINVAL; in can_idmap_mount()
4825 if (!(kattr->kflags & MOUNT_KATTR_IDMAP_REPLACE) && is_idmapped_mnt(m)) in can_idmap_mount()
4826 return -EPERM; in can_idmap_mount()
4829 if (!(m->mnt_sb->s_type->fs_flags & FS_ALLOW_IDMAP)) in can_idmap_mount()
4830 return -EINVAL; in can_idmap_mount()
4833 if (m->mnt_sb->s_iflags & SB_I_NOIDMAP) in can_idmap_mount()
4834 return -EINVAL; in can_idmap_mount()
4838 return -EPERM; in can_idmap_mount()
4841 if (!is_anon_ns(mnt->mnt_ns)) in can_idmap_mount()
4842 return -EINVAL; in can_idmap_mount()
4848 * mnt_allow_writers() - check whether the attribute change allows writers
4859 return (!(kattr->attr_set & MNT_READONLY) || in mnt_allow_writers()
4860 (mnt->mnt.mnt_flags & MNT_READONLY)) && in mnt_allow_writers()
4861 !kattr->mnt_idmap; in mnt_allow_writers()
4871 err = -EPERM; in mount_setattr_prepare()
4887 if (!(kattr->kflags & MOUNT_KATTR_RECURSE)) in mount_setattr_prepare()
4903 if (!kattr->mnt_idmap) in do_idmap_mount()
4906 old_idmap = mnt_idmap(&mnt->mnt); in do_idmap_mount()
4909 smp_store_release(&mnt->mnt.mnt_idmap, mnt_idmap_get(kattr->mnt_idmap)); in do_idmap_mount()
4922 WRITE_ONCE(m->mnt.mnt_flags, flags); in mount_setattr_commit()
4927 if (kattr->propagation) in mount_setattr_commit()
4928 change_mnt_propagation(m, kattr->propagation); in mount_setattr_commit()
4929 if (!(kattr->kflags & MOUNT_KATTR_RECURSE)) in mount_setattr_commit()
4932 touch_mnt_namespace(mnt->mnt_ns); in mount_setattr_commit()
4935 static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr) in do_mount_setattr() argument
4937 struct mount *mnt = real_mount(path->mnt); in do_mount_setattr()
4940 if (!path_mounted(path)) in do_mount_setattr()
4941 return -EINVAL; in do_mount_setattr()
4943 if (kattr->mnt_userns) { in do_mount_setattr()
4946 mnt_idmap = alloc_mnt_idmap(kattr->mnt_userns); in do_mount_setattr()
4949 kattr->mnt_idmap = mnt_idmap; in do_mount_setattr()
4952 if (kattr->propagation) { in do_mount_setattr()
4958 if (kattr->propagation == MS_SHARED) { in do_mount_setattr()
4959 err = invent_group_ids(mnt, kattr->kflags & MOUNT_KATTR_RECURSE); in do_mount_setattr()
4967 err = -EINVAL; in do_mount_setattr()
4985 if (kattr->propagation) { in do_mount_setattr()
5000 if (!((attr->attr_set | attr->attr_clr) & MOUNT_ATTR_IDMAP)) in build_mount_idmapped()
5003 if (attr->attr_clr & MOUNT_ATTR_IDMAP) { in build_mount_idmapped()
5008 if (!(kattr->kflags & MOUNT_KATTR_IDMAP_REPLACE)) in build_mount_idmapped()
5009 return -EINVAL; in build_mount_idmapped()
5015 if (!(attr->attr_set & MOUNT_ATTR_IDMAP)) { in build_mount_idmapped()
5016 kattr->mnt_idmap = &nop_mnt_idmap; in build_mount_idmapped()
5021 if (attr->userns_fd > INT_MAX) in build_mount_idmapped()
5022 return -EINVAL; in build_mount_idmapped()
5024 CLASS(fd, f)(attr->userns_fd); in build_mount_idmapped()
5026 return -EBADF; in build_mount_idmapped()
5029 return -EINVAL; in build_mount_idmapped()
5032 if (ns->ns_type != CLONE_NEWUSER) in build_mount_idmapped()
5033 return -EINVAL; in build_mount_idmapped()
5045 return -EPERM; in build_mount_idmapped()
5049 return -EPERM; in build_mount_idmapped()
5051 kattr->mnt_userns = get_user_ns(mnt_userns); in build_mount_idmapped()
5058 if (attr->propagation & ~MOUNT_SETATTR_PROPAGATION_FLAGS) in build_mount_kattr()
5059 return -EINVAL; in build_mount_kattr()
5060 if (hweight32(attr->propagation & MOUNT_SETATTR_PROPAGATION_FLAGS) > 1) in build_mount_kattr()
5061 return -EINVAL; in build_mount_kattr()
5062 kattr->propagation = attr->propagation; in build_mount_kattr()
5064 if ((attr->attr_set | attr->attr_clr) & ~MOUNT_SETATTR_VALID_FLAGS) in build_mount_kattr()
5065 return -EINVAL; in build_mount_kattr()
5067 kattr->attr_set = attr_flags_to_mnt_flags(attr->attr_set); in build_mount_kattr()
5068 kattr->attr_clr = attr_flags_to_mnt_flags(attr->attr_clr); in build_mount_kattr()
5079 if (attr->attr_clr & MOUNT_ATTR__ATIME) { in build_mount_kattr()
5080 if ((attr->attr_clr & MOUNT_ATTR__ATIME) != MOUNT_ATTR__ATIME) in build_mount_kattr()
5081 return -EINVAL; in build_mount_kattr()
5087 kattr->attr_clr |= MNT_RELATIME | MNT_NOATIME; in build_mount_kattr()
5088 switch (attr->attr_set & MOUNT_ATTR__ATIME) { in build_mount_kattr()
5090 kattr->attr_set |= MNT_RELATIME; in build_mount_kattr()
5093 kattr->attr_set |= MNT_NOATIME; in build_mount_kattr()
5098 return -EINVAL; in build_mount_kattr()
5101 if (attr->attr_set & MOUNT_ATTR__ATIME) in build_mount_kattr()
5102 return -EINVAL; in build_mount_kattr()
5110 if (kattr->mnt_userns) { in finish_mount_kattr()
5111 put_user_ns(kattr->mnt_userns); in finish_mount_kattr()
5112 kattr->mnt_userns = NULL; in finish_mount_kattr()
5115 if (kattr->mnt_idmap) in finish_mount_kattr()
5116 mnt_idmap_put(kattr->mnt_idmap); in finish_mount_kattr()
5128 return -E2BIG; in wants_mount_setattr()
5130 return -EINVAL; in wants_mount_setattr()
5133 return -EPERM; in wants_mount_setattr()
5152 SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path, in SYSCALL_DEFINE5() argument
5157 struct path target; in SYSCALL_DEFINE5()
5165 return -EINVAL; in SYSCALL_DEFINE5()
5183 CLASS(filename_uflags, name)(path, flags); in SYSCALL_DEFINE5()
5198 return -EINVAL; in SYSCALL_DEFINE5()
5216 ret = do_mount_setattr(&file->f_path, &kattr); in SYSCALL_DEFINE5()
5228 if (root->d_sb->s_op->show_path) in show_path()
5229 return root->d_sb->s_op->show_path(m, root); in show_path()
5239 if (!mnt || mnt->mnt_id_unique != id) in lookup_mnt_in_ns()
5242 return &mnt->mnt; in lookup_mnt_in_ns()
5251 struct path root;
5254 /* Must be last --ends in a flexible-array member. */
5260 unsigned int mnt_flags = READ_ONCE(mnt->mnt_flags); in mnt_to_attr_flags()
5313 struct super_block *sb = s->mnt->mnt_sb; in statmount_sb_basic()
5315 s->sm.mask |= STATMOUNT_SB_BASIC; in statmount_sb_basic()
5316 s->sm.sb_dev_major = MAJOR(sb->s_dev); in statmount_sb_basic()
5317 s->sm.sb_dev_minor = MINOR(sb->s_dev); in statmount_sb_basic()
5318 s->sm.sb_magic = sb->s_magic; in statmount_sb_basic()
5319 s->sm.sb_flags = sb->s_flags & (SB_RDONLY|SB_SYNCHRONOUS|SB_DIRSYNC|SB_LAZYTIME); in statmount_sb_basic()
5324 struct mount *m = real_mount(s->mnt); in statmount_mnt_basic()
5326 s->sm.mask |= STATMOUNT_MNT_BASIC; in statmount_mnt_basic()
5327 s->sm.mnt_id = m->mnt_id_unique; in statmount_mnt_basic()
5328 s->sm.mnt_parent_id = m->mnt_parent->mnt_id_unique; in statmount_mnt_basic()
5329 s->sm.mnt_id_old = m->mnt_id; in statmount_mnt_basic()
5330 s->sm.mnt_parent_id_old = m->mnt_parent->mnt_id; in statmount_mnt_basic()
5331 s->sm.mnt_attr = mnt_to_attr_flags(&m->mnt); in statmount_mnt_basic()
5332 s->sm.mnt_propagation = mnt_to_propagation_flags(m); in statmount_mnt_basic()
5333 s->sm.mnt_peer_group = m->mnt_group_id; in statmount_mnt_basic()
5334 s->sm.mnt_master = IS_MNT_SLAVE(m) ? m->mnt_master->mnt_group_id : 0; in statmount_mnt_basic()
5339 struct mount *m = real_mount(s->mnt); in statmount_propagate_from()
5341 s->sm.mask |= STATMOUNT_PROPAGATE_FROM; in statmount_propagate_from()
5343 s->sm.propagate_from = get_dominating_id(m, ¤t->fs->root); in statmount_propagate_from()
5349 size_t start = seq->count; in statmount_mnt_root()
5351 ret = show_path(seq, s->mnt->mnt_root); in statmount_mnt_root()
5356 return -EAGAIN; in statmount_mnt_root()
5362 seq->buf[seq->count] = '\0'; in statmount_mnt_root()
5363 seq->count = start; in statmount_mnt_root()
5364 seq_commit(seq, string_unescape_inplace(seq->buf + start, UNESCAPE_OCTAL)); in statmount_mnt_root()
5370 struct vfsmount *mnt = s->mnt; in statmount_mnt_point()
5371 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; in statmount_mnt_point()
5374 err = seq_path_root(seq, &mnt_path, &s->root, ""); in statmount_mnt_point()
5380 struct super_block *sb = s->mnt->mnt_sb; in statmount_fs_type()
5382 seq_puts(seq, sb->s_type->name); in statmount_fs_type()
5388 struct super_block *sb = s->mnt->mnt_sb; in statmount_fs_subtype()
5390 if (sb->s_subtype) in statmount_fs_subtype()
5391 seq_puts(seq, sb->s_subtype); in statmount_fs_subtype()
5396 struct super_block *sb = s->mnt->mnt_sb; in statmount_sb_source()
5397 struct mount *r = real_mount(s->mnt); in statmount_sb_source()
5399 if (sb->s_op->show_devname) { in statmount_sb_source()
5400 size_t start = seq->count; in statmount_sb_source()
5403 ret = sb->s_op->show_devname(seq, s->mnt->mnt_root); in statmount_sb_source()
5408 return -EAGAIN; in statmount_sb_source()
5411 seq->buf[seq->count] = '\0'; in statmount_sb_source()
5412 seq->count = start; in statmount_sb_source()
5413 seq_commit(seq, string_unescape_inplace(seq->buf + start, UNESCAPE_OCTAL)); in statmount_sb_source()
5415 seq_puts(seq, r->mnt_devname); in statmount_sb_source()
5422 s->sm.mask |= STATMOUNT_MNT_NS_ID; in statmount_mnt_ns_id()
5423 s->sm.mnt_ns_id = ns->ns.ns_id; in statmount_mnt_ns_id()
5428 struct vfsmount *mnt = s->mnt; in statmount_mnt_opts()
5429 struct super_block *sb = mnt->mnt_sb; in statmount_mnt_opts()
5430 size_t start = seq->count; in statmount_mnt_opts()
5437 if (sb->s_op->show_options) { in statmount_mnt_opts()
5438 err = sb->s_op->show_options(seq, mnt->mnt_root); in statmount_mnt_opts()
5444 return -EAGAIN; in statmount_mnt_opts()
5446 if (seq->count == start) in statmount_mnt_opts()
5450 memmove(seq->buf + start, seq->buf + start + 1, in statmount_mnt_opts()
5451 seq->count - start - 1); in statmount_mnt_opts()
5452 seq->count--; in statmount_mnt_opts()
5463 return -EAGAIN; in statmount_opt_process()
5465 buf_end = seq->buf + seq->count; in statmount_opt_process()
5466 dst = seq->buf + start; in statmount_opt_process()
5470 seq->count = start; in statmount_opt_process()
5480 return -EOVERFLOW; in statmount_opt_process()
5482 seq->count = dst - 1 - seq->buf; in statmount_opt_process()
5488 struct vfsmount *mnt = s->mnt; in statmount_opt_array()
5489 struct super_block *sb = mnt->mnt_sb; in statmount_opt_array()
5490 size_t start = seq->count; in statmount_opt_array()
5493 if (!sb->s_op->show_options) in statmount_opt_array()
5496 err = sb->s_op->show_options(seq, mnt->mnt_root); in statmount_opt_array()
5504 s->sm.opt_num = err; in statmount_opt_array()
5510 struct vfsmount *mnt = s->mnt; in statmount_opt_sec_array()
5511 struct super_block *sb = mnt->mnt_sb; in statmount_opt_sec_array()
5512 size_t start = seq->count; in statmount_opt_sec_array()
5523 s->sm.opt_sec_num = err; in statmount_opt_sec_array()
5531 ret = statmount_mnt_idmap(s->idmap, seq, true); in statmount_mnt_uidmap()
5535 s->sm.mnt_uidmap_num = ret; in statmount_mnt_uidmap()
5539 * non-idmapped mount and an idmapped mount where none of the in statmount_mnt_uidmap()
5542 if (is_valid_mnt_idmap(s->idmap)) in statmount_mnt_uidmap()
5543 s->sm.mask |= STATMOUNT_MNT_UIDMAP; in statmount_mnt_uidmap()
5551 ret = statmount_mnt_idmap(s->idmap, seq, false); in statmount_mnt_gidmap()
5555 s->sm.mnt_gidmap_num = ret; in statmount_mnt_gidmap()
5559 * non-idmapped mount and an idmapped mount where none of the in statmount_mnt_gidmap()
5562 if (is_valid_mnt_idmap(s->idmap)) in statmount_mnt_gidmap()
5563 s->sm.mask |= STATMOUNT_MNT_GIDMAP; in statmount_mnt_gidmap()
5571 struct seq_file *seq = &s->seq; in statmount_string()
5572 struct statmount *sm = &s->sm; in statmount_string()
5576 if (!seq->count) in statmount_string()
5579 start = seq->count; in statmount_string()
5583 offp = &sm->fs_type; in statmount_string()
5587 offp = &sm->mnt_root; in statmount_string()
5591 offp = &sm->mnt_point; in statmount_string()
5595 offp = &sm->mnt_opts; in statmount_string()
5599 offp = &sm->opt_array; in statmount_string()
5603 offp = &sm->opt_sec_array; in statmount_string()
5607 offp = &sm->fs_subtype; in statmount_string()
5611 offp = &sm->sb_source; in statmount_string()
5615 offp = &sm->mnt_uidmap; in statmount_string()
5619 offp = &sm->mnt_gidmap; in statmount_string()
5624 return -EINVAL; in statmount_string()
5631 if (seq->count == start) in statmount_string()
5633 if (unlikely(check_add_overflow(sizeof(*sm), seq->count, &kbufsize))) in statmount_string()
5634 return -EOVERFLOW; in statmount_string()
5635 if (kbufsize >= s->bufsize) in statmount_string()
5636 return -EOVERFLOW; in statmount_string()
5640 return -EAGAIN; in statmount_string()
5645 seq->buf[seq->count++] = '\0'; in statmount_string()
5646 sm->mask |= flag; in statmount_string()
5653 struct statmount *sm = &s->sm; in copy_statmount_to_user()
5654 struct seq_file *seq = &s->seq; in copy_statmount_to_user()
5655 char __user *str = ((char __user *)s->buf) + sizeof(*sm); in copy_statmount_to_user()
5656 size_t copysize = min_t(size_t, s->bufsize, sizeof(*sm)); in copy_statmount_to_user()
5658 if (seq->count && copy_to_user(str, seq->buf, seq->count)) in copy_statmount_to_user()
5659 return -EFAULT; in copy_statmount_to_user()
5662 sm->size = copysize + seq->count; in copy_statmount_to_user()
5663 if (copy_to_user(s->buf, sm, copysize)) in copy_statmount_to_user()
5664 return -EFAULT; in copy_statmount_to_user()
5674 node = rb_prev(&curr->mnt_node); in listmnt_next()
5676 node = rb_next(&curr->mnt_node); in listmnt_next()
5681 static int grab_requested_root(struct mnt_namespace *ns, struct path *root) in grab_requested_root()
5688 if (ns == current->nsproxy->mnt_ns) { in grab_requested_root()
5689 get_fs_root(current->fs, root); in grab_requested_root()
5698 return -ENOENT; in grab_requested_root()
5700 first = ns->root; in grab_requested_root()
5701 for (child = node_to_mount(ns->mnt_first_node); child; in grab_requested_root()
5703 if (child != first && child->mnt_parent == first) in grab_requested_root()
5707 return -ENOENT; in grab_requested_root()
5709 root->mnt = mntget(&child->mnt); in grab_requested_root()
5710 root->dentry = dget(root->mnt->mnt_root); in grab_requested_root()
5740 s->mnt = mnt_file->f_path.mnt; in do_statmount()
5741 ns = real_mount(s->mnt)->mnt_ns; in do_statmount()
5750 s->mask &= ~(STATMOUNT_MNT_POINT | STATMOUNT_MNT_NS_ID); in do_statmount()
5754 return -ENOENT; in do_statmount()
5756 s->mnt = lookup_mnt_in_ns(mnt_id, ns); in do_statmount()
5757 if (!s->mnt) in do_statmount()
5758 return -ENOENT; in do_statmount()
5762 err = grab_requested_root(ns, &s->root); in do_statmount()
5772 m = real_mount(s->mnt); in do_statmount()
5773 if (!is_path_reachable(m, m->mnt.mnt_root, &s->root) && in do_statmount()
5774 !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN)) in do_statmount()
5775 return -EPERM; in do_statmount()
5779 err = security_sb_statfs(s->mnt->mnt_root); in do_statmount()
5784 * Note that mount properties in mnt->mnt_flags, mnt->mnt_idmap in do_statmount()
5785 * can change concurrently as we only hold the read-side of the in do_statmount()
5791 * happens is that the mnt->mnt_idmap pointer is already changed in do_statmount()
5792 * while mnt->mnt_flags isn't or vica versa. So what. in do_statmount()
5794 * Both mnt->mnt_flags and mnt->mnt_idmap are set and retrieved in do_statmount()
5798 s->idmap = mnt_idmap(s->mnt); in do_statmount()
5799 if (s->mask & STATMOUNT_MNT_BASIC) in do_statmount()
5802 if (s->mask & STATMOUNT_SB_BASIC) in do_statmount()
5805 if (s->mask & STATMOUNT_PROPAGATE_FROM) in do_statmount()
5808 if (s->mask & STATMOUNT_FS_TYPE) in do_statmount()
5811 if (!err && s->mask & STATMOUNT_MNT_ROOT) in do_statmount()
5814 if (!err && s->mask & STATMOUNT_MNT_POINT) in do_statmount()
5817 if (!err && s->mask & STATMOUNT_MNT_OPTS) in do_statmount()
5820 if (!err && s->mask & STATMOUNT_OPT_ARRAY) in do_statmount()
5823 if (!err && s->mask & STATMOUNT_OPT_SEC_ARRAY) in do_statmount()
5826 if (!err && s->mask & STATMOUNT_FS_SUBTYPE) in do_statmount()
5829 if (!err && s->mask & STATMOUNT_SB_SOURCE) in do_statmount()
5832 if (!err && s->mask & STATMOUNT_MNT_UIDMAP) in do_statmount()
5835 if (!err && s->mask & STATMOUNT_MNT_GIDMAP) in do_statmount()
5838 if (!err && s->mask & STATMOUNT_MNT_NS_ID) in do_statmount()
5841 if (!err && s->mask & STATMOUNT_SUPPORTED_MASK) { in do_statmount()
5842 s->sm.mask |= STATMOUNT_SUPPORTED_MASK; in do_statmount()
5843 s->sm.supported_mask = STATMOUNT_SUPPORTED; in do_statmount()
5850 WARN_ON_ONCE(~STATMOUNT_SUPPORTED & s->sm.mask); in do_statmount()
5857 if (likely(ret != -EAGAIN)) in retry_statmount()
5877 return -EFAULT; in prepare_kstatmount()
5880 ks->mask = kreq->param; in prepare_kstatmount()
5881 ks->buf = buf; in prepare_kstatmount()
5882 ks->bufsize = bufsize; in prepare_kstatmount()
5884 if (ks->mask & STATMOUNT_STRING_REQ) { in prepare_kstatmount()
5885 if (bufsize == sizeof(ks->sm)) in prepare_kstatmount()
5886 return -EOVERFLOW; in prepare_kstatmount()
5888 ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT); in prepare_kstatmount()
5889 if (!ks->seq.buf) in prepare_kstatmount()
5890 return -ENOMEM; in prepare_kstatmount()
5892 ks->seq.size = seq_size; in prepare_kstatmount()
5906 ret = get_user(usize, &req->size); in copy_mnt_id_req()
5908 return -EFAULT; in copy_mnt_id_req()
5910 return -E2BIG; in copy_mnt_id_req()
5912 return -EINVAL; in copy_mnt_id_req()
5919 if (kreq->mnt_id || kreq->mnt_ns_id) in copy_mnt_id_req()
5920 return -EINVAL; in copy_mnt_id_req()
5922 if (kreq->mnt_ns_fd != 0 && kreq->mnt_ns_id) in copy_mnt_id_req()
5923 return -EINVAL; in copy_mnt_id_req()
5925 if (kreq->mnt_id <= MNT_UNIQUE_ID_OFFSET) in copy_mnt_id_req()
5926 return -EINVAL; in copy_mnt_id_req()
5940 if (kreq->mnt_ns_id) { in grab_requested_mnt_ns()
5941 mnt_ns = lookup_mnt_ns(kreq->mnt_ns_id); in grab_requested_mnt_ns()
5943 return ERR_PTR(-ENOENT); in grab_requested_mnt_ns()
5944 } else if (kreq->mnt_ns_fd) { in grab_requested_mnt_ns()
5947 CLASS(fd, f)(kreq->mnt_ns_fd); in grab_requested_mnt_ns()
5949 return ERR_PTR(-EBADF); in grab_requested_mnt_ns()
5952 return ERR_PTR(-EINVAL); in grab_requested_mnt_ns()
5955 if (ns->ns_type != CLONE_NEWNS) in grab_requested_mnt_ns()
5956 return ERR_PTR(-EINVAL); in grab_requested_mnt_ns()
5959 refcount_inc(&mnt_ns->passive); in grab_requested_mnt_ns()
5961 mnt_ns = current->nsproxy->mnt_ns; in grab_requested_mnt_ns()
5962 refcount_inc(&mnt_ns->passive); in grab_requested_mnt_ns()
5981 return -EINVAL; in SYSCALL_DEFINE4()
5990 return -EBADF; in SYSCALL_DEFINE4()
5997 if (kreq.mnt_ns_id && (ns != current->nsproxy->mnt_ns) && in SYSCALL_DEFINE4()
5998 !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN)) in SYSCALL_DEFINE4()
5999 return -EPERM; in SYSCALL_DEFINE4()
6004 return -ENOMEM; in SYSCALL_DEFINE4()
6016 kvfree(ks->seq.buf); in SYSCALL_DEFINE4()
6017 path_put(&ks->root); in SYSCALL_DEFINE4()
6029 struct path root;
6035 struct mnt_namespace *ns = kls->ns; in do_listmount()
6036 u64 mnt_parent_id = kls->mnt_parent_id; in do_listmount()
6037 u64 last_mnt_id = kls->last_mnt_id; in do_listmount()
6038 u64 *mnt_ids = kls->kmnt_ids; in do_listmount()
6039 size_t nr_mnt_ids = kls->nr_mnt_ids; in do_listmount()
6040 struct path orig; in do_listmount()
6046 ret = grab_requested_root(ns, &kls->root); in do_listmount()
6051 orig = kls->root; in do_listmount()
6055 return -ENOENT; in do_listmount()
6056 orig.dentry = orig.mnt->mnt_root; in do_listmount()
6063 if (!is_path_reachable(real_mount(orig.mnt), orig.dentry, &kls->root) && in do_listmount()
6064 !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN)) in do_listmount()
6065 return -EPERM; in do_listmount()
6073 first = node_to_mount(ns->mnt_last_node); in do_listmount()
6075 first = node_to_mount(ns->mnt_first_node); in do_listmount()
6078 first = mnt_find_id_at_reverse(ns, last_mnt_id - 1); in do_listmount()
6084 if (r->mnt_id_unique == mnt_parent_id) in do_listmount()
6086 if (!is_path_reachable(r, r->mnt.mnt_root, &orig)) in do_listmount()
6088 *mnt_ids = r->mnt_id_unique; in do_listmount()
6090 nr_mnt_ids--; in do_listmount()
6098 path_put(&kls->root); in __free_klistmount_free()
6099 kvfree(kls->kmnt_ids); in __free_klistmount_free()
6100 mnt_ns_release(kls->ns); in __free_klistmount_free()
6106 u64 last_mnt_id = kreq->param; in prepare_klistmount()
6111 return -EINVAL; in prepare_klistmount()
6113 kls->last_mnt_id = last_mnt_id; in prepare_klistmount()
6115 kls->nr_mnt_ids = nr_mnt_ids; in prepare_klistmount()
6116 kls->kmnt_ids = kvmalloc_array(nr_mnt_ids, sizeof(*kls->kmnt_ids), in prepare_klistmount()
6118 if (!kls->kmnt_ids) in prepare_klistmount()
6119 return -ENOMEM; in prepare_klistmount()
6124 kls->ns = ns; in prepare_klistmount()
6126 kls->mnt_parent_id = kreq->mnt_id; in prepare_klistmount()
6139 return -EINVAL; in SYSCALL_DEFINE4()
6147 return -EOVERFLOW; in SYSCALL_DEFINE4()
6150 return -EFAULT; in SYSCALL_DEFINE4()
6160 if (kreq.mnt_ns_id && (kls.ns != current->nsproxy->mnt_ns) && in SYSCALL_DEFINE4()
6161 !ns_capable_noaudit(kls.ns->user_ns, CAP_SYS_ADMIN)) in SYSCALL_DEFINE4()
6162 return -ENOENT; in SYSCALL_DEFINE4()
6174 return -EFAULT; in SYSCALL_DEFINE4()
6191 struct path root; in init_mount_tree()
6211 VFS_WARN_ON_ONCE(real_mount(nullfs_mnt)->mnt_id != 1); in init_mount_tree()
6212 VFS_WARN_ON_ONCE(real_mount(mnt)->mnt_id != 2); in init_mount_tree()
6220 root.dentry = nullfs_mnt->mnt_root; in init_mount_tree()
6245 root.dentry = nullfs_mnt->mnt_root; in init_mount_tree()
6247 init_task.nsproxy->mnt_ns = &init_mnt_ns; in init_mount_tree()
6249 set_fs_pwd(current->fs, &root); in init_mount_tree()
6250 set_fs_root(current->fs, &root); in init_mount_tree()
6262 mount_hashtable = alloc_large_system_hash("Mount-cache", in mnt_init()
6267 mountpoint_hashtable = alloc_large_system_hash("Mountpoint-cache", in mnt_init()
6297 umount_tree(ns->root, UMOUNT_CONNECTED); in put_mnt_ns()
6303 mnt = vfs_kern_mount(type, SB_KERNMOUNT, type->name, NULL); in kern_mount()
6309 real_mount(mnt)->mnt_ns = MNT_NS_INTERNAL; in kern_mount()
6345 /* Does the current process have a non-standard root */ in current_chrooted()
6346 struct path fs_root __free(path_put) = {}; in current_chrooted()
6349 get_fs_root(current->fs, &fs_root); in current_chrooted()
6355 root = topmost_overmount(current->nsproxy->mnt_ns->root); in current_chrooted()
6357 return fs_root.mnt != &root->mnt || !path_mounted(&fs_root); in current_chrooted()
6368 if (hlist_empty(&ns->mnt_visible_mounts)) in mnt_already_visible()
6372 hlist_for_each_entry(mnt, &ns->mnt_visible_mounts, mnt_ns_visible) { in mnt_already_visible()
6373 const struct super_block *sb_visible = mnt->mnt.mnt_sb; in mnt_already_visible()
6377 if (sb_visible->s_type != sb->s_type) in mnt_already_visible()
6384 if (sb_visible->s_iflags & SB_I_RESTRICTED_VARIANT) in mnt_already_visible()
6388 mnt_flags = mnt->mnt.mnt_flags; in mnt_already_visible()
6391 if (sb_rdonly(mnt->mnt.mnt_sb)) in mnt_already_visible()
6408 list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { in mnt_already_visible()
6409 struct inode *inode = child->mnt_mountpoint->d_inode; in mnt_already_visible()
6411 if (!(child->mnt.mnt_flags & MNT_LOCKED)) in mnt_already_visible()
6429 struct mnt_namespace *ns = current->nsproxy->mnt_ns; in mount_too_revealing()
6432 if (ns->user_ns == &init_user_ns) in mount_too_revealing()
6436 if (!(sb->s_type->fs_flags & FS_USERNS_MOUNT_RESTRICTED)) in mount_too_revealing()
6439 s_iflags = sb->s_iflags; in mount_too_revealing()
6465 return !(mnt->mnt_flags & MNT_NOSUID) && check_mnt(real_mount(mnt)) && in mnt_may_suid()
6466 current_in_userns(mnt->mnt_sb->s_user_ns); in mnt_may_suid()
6475 nsproxy = task->nsproxy; in mntns_get()
6477 ns = &nsproxy->mnt_ns->ns; in mntns_get()
6492 struct nsproxy *nsproxy = nsset->nsproxy; in mntns_install()
6493 struct fs_struct *fs = nsset->fs; in mntns_install()
6495 struct user_namespace *user_ns = nsset->cred->user_ns; in mntns_install()
6496 struct path root; in mntns_install()
6499 if (!ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN) || in mntns_install()
6502 return -EPERM; in mntns_install()
6505 return -EINVAL; in mntns_install()
6507 if (fs->users != 1) in mntns_install()
6508 return -EINVAL; in mntns_install()
6511 old_mnt_ns = nsproxy->mnt_ns; in mntns_install()
6512 nsproxy->mnt_ns = mnt_ns; in mntns_install()
6515 err = vfs_path_lookup(mnt_ns->root->mnt.mnt_root, &mnt_ns->root->mnt, in mntns_install()
6519 nsproxy->mnt_ns = old_mnt_ns; in mntns_install()
6536 return to_mnt_ns(ns)->user_ns; in mntns_owner()
6550 .procname = "mount-max",