xref: /linux/fs/nsfs.c (revision 9b8a0ba68246a61d903ce62c35c303b1501df28b)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/mount.h>
3 #include <linux/pseudo_fs.h>
4 #include <linux/file.h>
5 #include <linux/fs.h>
6 #include <linux/proc_fs.h>
7 #include <linux/proc_ns.h>
8 #include <linux/magic.h>
9 #include <linux/ktime.h>
10 #include <linux/seq_file.h>
11 #include <linux/pid_namespace.h>
12 #include <linux/user_namespace.h>
13 #include <linux/nsfs.h>
14 #include <linux/uaccess.h>
15 #include <linux/mnt_namespace.h>
16 #include <linux/ipc_namespace.h>
17 #include <linux/time_namespace.h>
18 #include <linux/utsname.h>
19 #include <linux/exportfs.h>
20 #include <linux/nstree.h>
21 #include <net/net_namespace.h>
22 
23 #include "mount.h"
24 #include "internal.h"
25 
26 static struct vfsmount *nsfs_mnt;
27 
28 static struct path nsfs_root_path = {};
29 
30 void nsfs_get_root(struct path *path)
31 {
32 	*path = nsfs_root_path;
33 	path_get(path);
34 }
35 
36 static long ns_ioctl(struct file *filp, unsigned int ioctl,
37 			unsigned long arg);
38 static const struct file_operations ns_file_operations = {
39 	.unlocked_ioctl = ns_ioctl,
40 	.compat_ioctl   = compat_ptr_ioctl,
41 };
42 
43 static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
44 {
45 	struct inode *inode = d_inode(dentry);
46 	struct ns_common *ns = inode->i_private;
47 	const struct proc_ns_operations *ns_ops = ns->ops;
48 
49 	return dynamic_dname(buffer, buflen, "%s:[%lu]",
50 		ns_ops->name, inode->i_ino);
51 }
52 
53 const struct dentry_operations ns_dentry_operations = {
54 	.d_dname	= ns_dname,
55 	.d_prune	= stashed_dentry_prune,
56 };
57 
58 static void nsfs_evict(struct inode *inode)
59 {
60 	struct ns_common *ns = inode->i_private;
61 
62 	__ns_ref_active_put(ns);
63 	clear_inode(inode);
64 	ns->ops->put(ns);
65 }
66 
67 int ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
68 		     void *private_data)
69 {
70 	struct ns_common *ns;
71 
72 	ns = ns_get_cb(private_data);
73 	if (!ns)
74 		return -ENOENT;
75 
76 	return path_from_stashed(&ns->stashed, nsfs_mnt, ns, path);
77 }
78 
79 struct ns_get_path_task_args {
80 	const struct proc_ns_operations *ns_ops;
81 	struct task_struct *task;
82 };
83 
84 static struct ns_common *ns_get_path_task(void *private_data)
85 {
86 	struct ns_get_path_task_args *args = private_data;
87 
88 	return args->ns_ops->get(args->task);
89 }
90 
91 int ns_get_path(struct path *path, struct task_struct *task,
92 		  const struct proc_ns_operations *ns_ops)
93 {
94 	struct ns_get_path_task_args args = {
95 		.ns_ops	= ns_ops,
96 		.task	= task,
97 	};
98 
99 	return ns_get_path_cb(path, ns_get_path_task, &args);
100 }
101 
102 struct file *open_namespace_file(struct ns_common *ns)
103 {
104 	struct path path __free(path_put) = {};
105 	int err;
106 
107 	/* call first to consume reference */
108 	err = path_from_stashed(&ns->stashed, nsfs_mnt, ns, &path);
109 	if (err < 0)
110 		return ERR_PTR(err);
111 
112 	return dentry_open(&path, O_RDONLY, current_cred());
113 }
114 
115 /**
116  * open_namespace - open a namespace
117  * @ns: the namespace to open
118  *
119  * This will consume a reference to @ns indendent of success or failure.
120  *
121  * Return: A file descriptor on success or a negative error code on failure.
122  */
123 int open_namespace(struct ns_common *ns)
124 {
125 	struct path path __free(path_put) = {};
126 	int err;
127 
128 	/* call first to consume reference */
129 	err = path_from_stashed(&ns->stashed, nsfs_mnt, ns, &path);
130 	if (err < 0)
131 		return err;
132 
133 	return FD_ADD(O_CLOEXEC, dentry_open(&path, O_RDONLY, current_cred()));
134 }
135 
136 int open_related_ns(struct ns_common *ns,
137 		   struct ns_common *(*get_ns)(struct ns_common *ns))
138 {
139 	struct ns_common *relative;
140 
141 	relative = get_ns(ns);
142 	if (IS_ERR(relative))
143 		return PTR_ERR(relative);
144 
145 	return open_namespace(relative);
146 }
147 EXPORT_SYMBOL_GPL(open_related_ns);
148 
149 static int copy_ns_info_to_user(const struct mnt_namespace *mnt_ns,
150 				struct mnt_ns_info __user *uinfo, size_t usize,
151 				struct mnt_ns_info *kinfo)
152 {
153 	/*
154 	 * If userspace and the kernel have the same struct size it can just
155 	 * be copied. If userspace provides an older struct, only the bits that
156 	 * userspace knows about will be copied. If userspace provides a new
157 	 * struct, only the bits that the kernel knows aobut will be copied and
158 	 * the size value will be set to the size the kernel knows about.
159 	 */
160 	kinfo->size		= min(usize, sizeof(*kinfo));
161 	kinfo->mnt_ns_id	= mnt_ns->ns.ns_id;
162 	kinfo->nr_mounts	= READ_ONCE(mnt_ns->nr_mounts);
163 	/* Subtract the root mount of the mount namespace. */
164 	if (kinfo->nr_mounts)
165 		kinfo->nr_mounts--;
166 
167 	if (copy_to_user(uinfo, kinfo, kinfo->size))
168 		return -EFAULT;
169 
170 	return 0;
171 }
172 
173 static bool nsfs_ioctl_valid(unsigned int cmd)
174 {
175 	switch (cmd) {
176 	case NS_GET_USERNS:
177 	case NS_GET_PARENT:
178 	case NS_GET_NSTYPE:
179 	case NS_GET_OWNER_UID:
180 	case NS_GET_MNTNS_ID:
181 	case NS_GET_PID_FROM_PIDNS:
182 	case NS_GET_TGID_FROM_PIDNS:
183 	case NS_GET_PID_IN_PIDNS:
184 	case NS_GET_TGID_IN_PIDNS:
185 	case NS_GET_ID:
186 		return true;
187 	}
188 
189 	/* Extensible ioctls require some extra handling. */
190 	switch (_IOC_NR(cmd)) {
191 	case _IOC_NR(NS_MNT_GET_INFO):
192 		return extensible_ioctl_valid(cmd, NS_MNT_GET_INFO, MNT_NS_INFO_SIZE_VER0);
193 	case _IOC_NR(NS_MNT_GET_NEXT):
194 		return extensible_ioctl_valid(cmd, NS_MNT_GET_NEXT, MNT_NS_INFO_SIZE_VER0);
195 	case _IOC_NR(NS_MNT_GET_PREV):
196 		return extensible_ioctl_valid(cmd, NS_MNT_GET_PREV, MNT_NS_INFO_SIZE_VER0);
197 	}
198 
199 	return false;
200 }
201 
202 static long ns_ioctl(struct file *filp, unsigned int ioctl,
203 			unsigned long arg)
204 {
205 	struct user_namespace *user_ns;
206 	struct pid_namespace *pid_ns;
207 	struct task_struct *tsk;
208 	struct ns_common *ns;
209 	struct mnt_namespace *mnt_ns;
210 	bool previous = false;
211 	uid_t __user *argp;
212 	uid_t uid;
213 	int ret;
214 
215 	if (!nsfs_ioctl_valid(ioctl))
216 		return -ENOIOCTLCMD;
217 
218 	ns = get_proc_ns(file_inode(filp));
219 	switch (ioctl) {
220 	case NS_GET_USERNS:
221 		return open_related_ns(ns, ns_get_owner);
222 	case NS_GET_PARENT:
223 		if (!ns->ops->get_parent)
224 			return -EINVAL;
225 		return open_related_ns(ns, ns->ops->get_parent);
226 	case NS_GET_NSTYPE:
227 		return ns->ns_type;
228 	case NS_GET_OWNER_UID:
229 		if (ns->ns_type != CLONE_NEWUSER)
230 			return -EINVAL;
231 		user_ns = container_of(ns, struct user_namespace, ns);
232 		argp = (uid_t __user *) arg;
233 		uid = from_kuid_munged(current_user_ns(), user_ns->owner);
234 		return put_user(uid, argp);
235 	case NS_GET_PID_FROM_PIDNS:
236 		fallthrough;
237 	case NS_GET_TGID_FROM_PIDNS:
238 		fallthrough;
239 	case NS_GET_PID_IN_PIDNS:
240 		fallthrough;
241 	case NS_GET_TGID_IN_PIDNS: {
242 		if (ns->ns_type != CLONE_NEWPID)
243 			return -EINVAL;
244 
245 		ret = -ESRCH;
246 		pid_ns = container_of(ns, struct pid_namespace, ns);
247 
248 		guard(rcu)();
249 
250 		if (ioctl == NS_GET_PID_IN_PIDNS ||
251 		    ioctl == NS_GET_TGID_IN_PIDNS)
252 			tsk = find_task_by_vpid(arg);
253 		else
254 			tsk = find_task_by_pid_ns(arg, pid_ns);
255 		if (!tsk)
256 			break;
257 
258 		switch (ioctl) {
259 		case NS_GET_PID_FROM_PIDNS:
260 			ret = task_pid_vnr(tsk);
261 			break;
262 		case NS_GET_TGID_FROM_PIDNS:
263 			ret = task_tgid_vnr(tsk);
264 			break;
265 		case NS_GET_PID_IN_PIDNS:
266 			ret = task_pid_nr_ns(tsk, pid_ns);
267 			break;
268 		case NS_GET_TGID_IN_PIDNS:
269 			ret = task_tgid_nr_ns(tsk, pid_ns);
270 			break;
271 		default:
272 			ret = 0;
273 			break;
274 		}
275 
276 		if (!ret)
277 			ret = -ESRCH;
278 		return ret;
279 	}
280 	case NS_GET_MNTNS_ID:
281 		if (ns->ns_type != CLONE_NEWNS)
282 			return -EINVAL;
283 		fallthrough;
284 	case NS_GET_ID: {
285 		__u64 __user *idp;
286 		__u64 id;
287 
288 		idp = (__u64 __user *)arg;
289 		id = ns->ns_id;
290 		return put_user(id, idp);
291 	}
292 	}
293 
294 	/* extensible ioctls */
295 	switch (_IOC_NR(ioctl)) {
296 	case _IOC_NR(NS_MNT_GET_INFO): {
297 		struct mnt_ns_info kinfo = {};
298 		struct mnt_ns_info __user *uinfo = (struct mnt_ns_info __user *)arg;
299 		size_t usize = _IOC_SIZE(ioctl);
300 
301 		if (ns->ns_type != CLONE_NEWNS)
302 			return -EINVAL;
303 
304 		if (!uinfo)
305 			return -EINVAL;
306 
307 		if (usize < MNT_NS_INFO_SIZE_VER0)
308 			return -EINVAL;
309 
310 		return copy_ns_info_to_user(to_mnt_ns(ns), uinfo, usize, &kinfo);
311 	}
312 	case _IOC_NR(NS_MNT_GET_PREV):
313 		previous = true;
314 		fallthrough;
315 	case _IOC_NR(NS_MNT_GET_NEXT): {
316 		struct mnt_ns_info kinfo = {};
317 		struct mnt_ns_info __user *uinfo = (struct mnt_ns_info __user *)arg;
318 		struct path path __free(path_put) = {};
319 		size_t usize = _IOC_SIZE(ioctl);
320 
321 		if (ns->ns_type != CLONE_NEWNS)
322 			return -EINVAL;
323 
324 		if (usize < MNT_NS_INFO_SIZE_VER0)
325 			return -EINVAL;
326 
327 		mnt_ns = get_sequential_mnt_ns(to_mnt_ns(ns), previous);
328 		if (IS_ERR(mnt_ns))
329 			return PTR_ERR(mnt_ns);
330 
331 		ns = to_ns_common(mnt_ns);
332 		/* Transfer ownership of @mnt_ns reference to @path. */
333 		ret = path_from_stashed(&ns->stashed, nsfs_mnt, ns, &path);
334 		if (ret)
335 			return ret;
336 
337 		FD_PREPARE(fdf, O_CLOEXEC, dentry_open(&path, O_RDONLY, current_cred()));
338 		if (fdf.err)
339 			return fdf.err;
340 		/*
341 		 * If @uinfo is passed return all information about the
342 		 * mount namespace as well.
343 		 */
344 		ret = copy_ns_info_to_user(to_mnt_ns(ns), uinfo, usize, &kinfo);
345 		if (ret)
346 			return ret;
347 		ret = fd_publish(fdf);
348 		break;
349 	}
350 	default:
351 		ret = -ENOTTY;
352 	}
353 
354 	return ret;
355 }
356 
357 int ns_get_name(char *buf, size_t size, struct task_struct *task,
358 			const struct proc_ns_operations *ns_ops)
359 {
360 	struct ns_common *ns;
361 	int res = -ENOENT;
362 	const char *name;
363 	ns = ns_ops->get(task);
364 	if (ns) {
365 		name = ns_ops->real_ns_name ? : ns_ops->name;
366 		res = snprintf(buf, size, "%s:[%u]", name, ns->inum);
367 		ns_ops->put(ns);
368 	}
369 	return res;
370 }
371 
372 bool proc_ns_file(const struct file *file)
373 {
374 	return file->f_op == &ns_file_operations;
375 }
376 
377 /**
378  * ns_match() - Returns true if current namespace matches dev/ino provided.
379  * @ns: current namespace
380  * @dev: dev_t from nsfs that will be matched against current nsfs
381  * @ino: ino_t from nsfs that will be matched against current nsfs
382  *
383  * Return: true if dev and ino matches the current nsfs.
384  */
385 bool ns_match(const struct ns_common *ns, dev_t dev, ino_t ino)
386 {
387 	return (ns->inum == ino) && (nsfs_mnt->mnt_sb->s_dev == dev);
388 }
389 
390 
391 static int nsfs_show_path(struct seq_file *seq, struct dentry *dentry)
392 {
393 	struct inode *inode = d_inode(dentry);
394 	const struct ns_common *ns = inode->i_private;
395 	const struct proc_ns_operations *ns_ops = ns->ops;
396 
397 	seq_printf(seq, "%s:[%lu]", ns_ops->name, inode->i_ino);
398 	return 0;
399 }
400 
401 static const struct super_operations nsfs_ops = {
402 	.statfs = simple_statfs,
403 	.evict_inode = nsfs_evict,
404 	.show_path = nsfs_show_path,
405 	.drop_inode = inode_just_drop,
406 };
407 
408 static int nsfs_init_inode(struct inode *inode, void *data)
409 {
410 	struct ns_common *ns = data;
411 
412 	inode->i_private = data;
413 	inode->i_mode |= S_IRUGO;
414 	inode->i_fop = &ns_file_operations;
415 	inode->i_ino = ns->inum;
416 
417 	/*
418 	 * Bring the namespace subtree back to life if we have to. This
419 	 * can happen when e.g., all processes using a network namespace
420 	 * and all namespace files or namespace file bind-mounts have
421 	 * died but there are still sockets pinning it. The SIOCGSKNS
422 	 * ioctl on such a socket will resurrect the relevant namespace
423 	 * subtree.
424 	 */
425 	__ns_ref_active_get(ns);
426 	return 0;
427 }
428 
429 static void nsfs_put_data(void *data)
430 {
431 	struct ns_common *ns = data;
432 	ns->ops->put(ns);
433 }
434 
435 static const struct stashed_operations nsfs_stashed_ops = {
436 	.init_inode = nsfs_init_inode,
437 	.put_data = nsfs_put_data,
438 };
439 
440 #define NSFS_FID_SIZE_U32_VER0 (NSFS_FILE_HANDLE_SIZE_VER0 / sizeof(u32))
441 #define NSFS_FID_SIZE_U32_LATEST (NSFS_FILE_HANDLE_SIZE_LATEST / sizeof(u32))
442 
443 static int nsfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
444 			  struct inode *parent)
445 {
446 	struct nsfs_file_handle *fid = (struct nsfs_file_handle *)fh;
447 	struct ns_common *ns = inode->i_private;
448 	int len = *max_len;
449 
450 	if (parent)
451 		return FILEID_INVALID;
452 
453 	if (len < NSFS_FID_SIZE_U32_VER0) {
454 		*max_len = NSFS_FID_SIZE_U32_LATEST;
455 		return FILEID_INVALID;
456 	} else if (len > NSFS_FID_SIZE_U32_LATEST) {
457 		*max_len = NSFS_FID_SIZE_U32_LATEST;
458 	}
459 
460 	fid->ns_id	= ns->ns_id;
461 	fid->ns_type	= ns->ns_type;
462 	fid->ns_inum	= inode->i_ino;
463 	return FILEID_NSFS;
464 }
465 
466 bool is_current_namespace(struct ns_common *ns)
467 {
468 	switch (ns->ns_type) {
469 #ifdef CONFIG_CGROUPS
470 	case CLONE_NEWCGROUP:
471 		return current_in_namespace(to_cg_ns(ns));
472 #endif
473 #ifdef CONFIG_IPC_NS
474 	case CLONE_NEWIPC:
475 		return current_in_namespace(to_ipc_ns(ns));
476 #endif
477 	case CLONE_NEWNS:
478 		return current_in_namespace(to_mnt_ns(ns));
479 #ifdef CONFIG_NET_NS
480 	case CLONE_NEWNET:
481 		return current_in_namespace(to_net_ns(ns));
482 #endif
483 #ifdef CONFIG_PID_NS
484 	case CLONE_NEWPID:
485 		return current_in_namespace(to_pid_ns(ns));
486 #endif
487 #ifdef CONFIG_TIME_NS
488 	case CLONE_NEWTIME:
489 		return current_in_namespace(to_time_ns(ns));
490 #endif
491 #ifdef CONFIG_USER_NS
492 	case CLONE_NEWUSER:
493 		return current_in_namespace(to_user_ns(ns));
494 #endif
495 #ifdef CONFIG_UTS_NS
496 	case CLONE_NEWUTS:
497 		return current_in_namespace(to_uts_ns(ns));
498 #endif
499 	default:
500 		VFS_WARN_ON_ONCE(true);
501 		return false;
502 	}
503 }
504 
505 static struct dentry *nsfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
506 					int fh_len, int fh_type)
507 {
508 	struct path path __free(path_put) = {};
509 	struct nsfs_file_handle *fid = (struct nsfs_file_handle *)fh;
510 	struct user_namespace *owning_ns = NULL;
511 	struct ns_common *ns;
512 	int ret;
513 
514 	if (fh_len < NSFS_FID_SIZE_U32_VER0)
515 		return NULL;
516 
517 	/* Check that any trailing bytes are zero. */
518 	if ((fh_len > NSFS_FID_SIZE_U32_LATEST) &&
519 	    memchr_inv((void *)fid + NSFS_FID_SIZE_U32_LATEST, 0,
520 		       fh_len - NSFS_FID_SIZE_U32_LATEST))
521 		return NULL;
522 
523 	switch (fh_type) {
524 	case FILEID_NSFS:
525 		break;
526 	default:
527 		return NULL;
528 	}
529 
530 	if (!fid->ns_id)
531 		return NULL;
532 	/* Either both are set or both are unset. */
533 	if (!fid->ns_inum != !fid->ns_type)
534 		return NULL;
535 
536 	scoped_guard(rcu) {
537 		ns = ns_tree_lookup_rcu(fid->ns_id, fid->ns_type);
538 		if (!ns)
539 			return NULL;
540 
541 		VFS_WARN_ON_ONCE(ns->ns_id != fid->ns_id);
542 
543 		if (fid->ns_inum && (fid->ns_inum != ns->inum))
544 			return NULL;
545 		if (fid->ns_type && (fid->ns_type != ns->ns_type))
546 			return NULL;
547 
548 		/*
549 		 * This is racy because we're not actually taking an
550 		 * active reference. IOW, it could happen that the
551 		 * namespace becomes inactive after this check.
552 		 * We don't care because nsfs_init_inode() will just
553 		 * resurrect the relevant namespace tree for us. If it
554 		 * has been active here we just allow it's resurrection.
555 		 * We could try to take an active reference here and
556 		 * then drop it again. But really, why bother.
557 		 */
558 		if (!ns_get_unless_inactive(ns))
559 			return NULL;
560 	}
561 
562 	switch (ns->ns_type) {
563 #ifdef CONFIG_CGROUPS
564 	case CLONE_NEWCGROUP:
565 		if (!current_in_namespace(to_cg_ns(ns)))
566 			owning_ns = to_cg_ns(ns)->user_ns;
567 		break;
568 #endif
569 #ifdef CONFIG_IPC_NS
570 	case CLONE_NEWIPC:
571 		if (!current_in_namespace(to_ipc_ns(ns)))
572 			owning_ns = to_ipc_ns(ns)->user_ns;
573 		break;
574 #endif
575 	case CLONE_NEWNS:
576 		if (!current_in_namespace(to_mnt_ns(ns)))
577 			owning_ns = to_mnt_ns(ns)->user_ns;
578 		break;
579 #ifdef CONFIG_NET_NS
580 	case CLONE_NEWNET:
581 		if (!current_in_namespace(to_net_ns(ns)))
582 			owning_ns = to_net_ns(ns)->user_ns;
583 		break;
584 #endif
585 #ifdef CONFIG_PID_NS
586 	case CLONE_NEWPID:
587 		if (!current_in_namespace(to_pid_ns(ns))) {
588 			owning_ns = to_pid_ns(ns)->user_ns;
589 		} else if (!READ_ONCE(to_pid_ns(ns)->child_reaper)) {
590 			ns->ops->put(ns);
591 			return ERR_PTR(-EPERM);
592 		}
593 		break;
594 #endif
595 #ifdef CONFIG_TIME_NS
596 	case CLONE_NEWTIME:
597 		if (!current_in_namespace(to_time_ns(ns)))
598 			owning_ns = to_time_ns(ns)->user_ns;
599 		break;
600 #endif
601 #ifdef CONFIG_USER_NS
602 	case CLONE_NEWUSER:
603 		if (!current_in_namespace(to_user_ns(ns)))
604 			owning_ns = to_user_ns(ns);
605 		break;
606 #endif
607 #ifdef CONFIG_UTS_NS
608 	case CLONE_NEWUTS:
609 		if (!current_in_namespace(to_uts_ns(ns)))
610 			owning_ns = to_uts_ns(ns)->user_ns;
611 		break;
612 #endif
613 	default:
614 		return ERR_PTR(-EOPNOTSUPP);
615 	}
616 
617 	if (owning_ns && !ns_capable(owning_ns, CAP_SYS_ADMIN)) {
618 		ns->ops->put(ns);
619 		return ERR_PTR(-EPERM);
620 	}
621 
622 	/* path_from_stashed() unconditionally consumes the reference. */
623 	ret = path_from_stashed(&ns->stashed, nsfs_mnt, ns, &path);
624 	if (ret)
625 		return ERR_PTR(ret);
626 
627 	return no_free_ptr(path.dentry);
628 }
629 
630 static int nsfs_export_permission(struct handle_to_path_ctx *ctx,
631 				   unsigned int oflags)
632 {
633 	/* nsfs_fh_to_dentry() performs all permission checks. */
634 	return 0;
635 }
636 
637 static struct file *nsfs_export_open(const struct path *path, unsigned int oflags)
638 {
639 	return file_open_root(path, "", oflags, 0);
640 }
641 
642 static const struct export_operations nsfs_export_operations = {
643 	.encode_fh	= nsfs_encode_fh,
644 	.fh_to_dentry	= nsfs_fh_to_dentry,
645 	.open		= nsfs_export_open,
646 	.permission	= nsfs_export_permission,
647 };
648 
649 static int nsfs_init_fs_context(struct fs_context *fc)
650 {
651 	struct pseudo_fs_context *ctx = init_pseudo(fc, NSFS_MAGIC);
652 	if (!ctx)
653 		return -ENOMEM;
654 	fc->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
655 	ctx->s_d_flags |= DCACHE_DONTCACHE;
656 	ctx->ops = &nsfs_ops;
657 	ctx->eops = &nsfs_export_operations;
658 	ctx->dops = &ns_dentry_operations;
659 	fc->s_fs_info = (void *)&nsfs_stashed_ops;
660 	return 0;
661 }
662 
663 static struct file_system_type nsfs = {
664 	.name = "nsfs",
665 	.init_fs_context = nsfs_init_fs_context,
666 	.kill_sb = kill_anon_super,
667 };
668 
669 void __init nsfs_init(void)
670 {
671 	nsfs_mnt = kern_mount(&nsfs);
672 	if (IS_ERR(nsfs_mnt))
673 		panic("can't set nsfs up\n");
674 	nsfs_mnt->mnt_sb->s_flags &= ~SB_NOUSER;
675 	nsfs_root_path.mnt = nsfs_mnt;
676 	nsfs_root_path.dentry = nsfs_mnt->mnt_root;
677 }
678 
679 void nsproxy_ns_active_get(struct nsproxy *ns)
680 {
681 	ns_ref_active_get(ns->mnt_ns);
682 	ns_ref_active_get(ns->uts_ns);
683 	ns_ref_active_get(ns->ipc_ns);
684 	ns_ref_active_get(ns->pid_ns_for_children);
685 	ns_ref_active_get(ns->cgroup_ns);
686 	ns_ref_active_get(ns->net_ns);
687 	ns_ref_active_get(ns->time_ns);
688 	ns_ref_active_get(ns->time_ns_for_children);
689 }
690 
691 void nsproxy_ns_active_put(struct nsproxy *ns)
692 {
693 	ns_ref_active_put(ns->mnt_ns);
694 	ns_ref_active_put(ns->uts_ns);
695 	ns_ref_active_put(ns->ipc_ns);
696 	ns_ref_active_put(ns->pid_ns_for_children);
697 	ns_ref_active_put(ns->cgroup_ns);
698 	ns_ref_active_put(ns->net_ns);
699 	ns_ref_active_put(ns->time_ns);
700 	ns_ref_active_put(ns->time_ns_for_children);
701 }
702