1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * procfs namespace bits
4 */
5 #ifndef _LINUX_PROC_NS_H
6 #define _LINUX_PROC_NS_H
7
8 #include <linux/ns_common.h>
9
10 struct pid_namespace;
11 struct nsproxy;
12 struct path;
13 struct task_struct;
14 struct inode;
15
16 struct proc_ns_operations {
17 const char *name;
18 const char *real_ns_name;
19 int type;
20 struct ns_common *(*get)(struct task_struct *task);
21 void (*put)(struct ns_common *ns);
22 int (*install)(struct nsproxy *nsproxy, struct ns_common *ns);
23 struct user_namespace *(*owner)(struct ns_common *ns);
24 struct ns_common *(*get_parent)(struct ns_common *ns);
25 } __randomize_layout;
26
27 extern const struct proc_ns_operations netns_operations;
28 extern const struct proc_ns_operations utsns_operations;
29 extern const struct proc_ns_operations ipcns_operations;
30 extern const struct proc_ns_operations pidns_operations;
31 extern const struct proc_ns_operations pidns_for_children_operations;
32 extern const struct proc_ns_operations userns_operations;
33 extern const struct proc_ns_operations mntns_operations;
34 extern const struct proc_ns_operations cgroupns_operations;
35
36 /*
37 * We always define these enumerators
38 */
39 enum {
40 PROC_ROOT_INO = 1,
41 PROC_IPC_INIT_INO = 0xEFFFFFFFU,
42 PROC_UTS_INIT_INO = 0xEFFFFFFEU,
43 PROC_USER_INIT_INO = 0xEFFFFFFDU,
44 PROC_PID_INIT_INO = 0xEFFFFFFCU,
45 PROC_CGROUP_INIT_INO = 0xEFFFFFFBU,
46 };
47
48 #ifdef CONFIG_PROC_FS
49
50 extern int pid_ns_prepare_proc(struct pid_namespace *ns);
51 extern void pid_ns_release_proc(struct pid_namespace *ns);
52 extern int proc_alloc_inum(unsigned int *pino);
53 extern void proc_free_inum(unsigned int inum);
54
55 #else /* CONFIG_PROC_FS */
56
pid_ns_prepare_proc(struct pid_namespace * ns)57 static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; }
pid_ns_release_proc(struct pid_namespace * ns)58 static inline void pid_ns_release_proc(struct pid_namespace *ns) {}
59
proc_alloc_inum(unsigned int * inum)60 static inline int proc_alloc_inum(unsigned int *inum)
61 {
62 *inum = 1;
63 return 0;
64 }
proc_free_inum(unsigned int inum)65 static inline void proc_free_inum(unsigned int inum) {}
66
67 #endif /* CONFIG_PROC_FS */
68
ns_alloc_inum(struct ns_common * ns)69 static inline int ns_alloc_inum(struct ns_common *ns)
70 {
71 atomic_long_set(&ns->stashed, 0);
72 return proc_alloc_inum(&ns->inum);
73 }
74
75 #define ns_free_inum(ns) proc_free_inum((ns)->inum)
76
77 extern struct file *proc_ns_fget(int fd);
78 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
79 extern void *ns_get_path(struct path *path, struct task_struct *task,
80 const struct proc_ns_operations *ns_ops);
81 typedef struct ns_common *ns_get_path_helper_t(void *);
82 extern void *ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
83 void *private_data);
84
85 extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
86 const struct proc_ns_operations *ns_ops);
87 extern void nsfs_init(void);
88
89 #endif /* _LINUX_PROC_NS_H */
90