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 #include <uapi/linux/nsfs.h>
10
11 struct pid_namespace;
12 struct nsset;
13 struct path;
14 struct task_struct;
15 struct inode;
16
17 struct proc_ns_operations {
18 const char *name;
19 const char *real_ns_name;
20 int type;
21 struct ns_common *(*get)(struct task_struct *task);
22 void (*put)(struct ns_common *ns);
23 int (*install)(struct nsset *nsset, struct ns_common *ns);
24 struct user_namespace *(*owner)(struct ns_common *ns);
25 struct ns_common *(*get_parent)(struct ns_common *ns);
26 } __randomize_layout;
27
28 extern const struct proc_ns_operations netns_operations;
29 extern const struct proc_ns_operations utsns_operations;
30 extern const struct proc_ns_operations ipcns_operations;
31 extern const struct proc_ns_operations pidns_operations;
32 extern const struct proc_ns_operations pidns_for_children_operations;
33 extern const struct proc_ns_operations userns_operations;
34 extern const struct proc_ns_operations mntns_operations;
35 extern const struct proc_ns_operations cgroupns_operations;
36 extern const struct proc_ns_operations timens_operations;
37 extern const struct proc_ns_operations timens_for_children_operations;
38
39 /*
40 * We always define these enumerators
41 */
42 enum {
43 PROC_IPC_INIT_INO = IPC_NS_INIT_INO,
44 PROC_UTS_INIT_INO = UTS_NS_INIT_INO,
45 PROC_USER_INIT_INO = USER_NS_INIT_INO,
46 PROC_PID_INIT_INO = PID_NS_INIT_INO,
47 PROC_CGROUP_INIT_INO = CGROUP_NS_INIT_INO,
48 PROC_TIME_INIT_INO = TIME_NS_INIT_INO,
49 PROC_NET_INIT_INO = NET_NS_INIT_INO,
50 PROC_MNT_INIT_INO = MNT_NS_INIT_INO,
51 };
52
53 #ifdef CONFIG_PROC_FS
54
55 extern int proc_alloc_inum(unsigned int *pino);
56 extern void proc_free_inum(unsigned int inum);
57
58 #else /* CONFIG_PROC_FS */
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 WRITE_ONCE(ns->stashed, NULL);
72 return proc_alloc_inum(&ns->inum);
73 }
74
75 #define ns_free_inum(ns) proc_free_inum((ns)->inum)
76
77 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
78 extern int ns_get_path(struct path *path, struct task_struct *task,
79 const struct proc_ns_operations *ns_ops);
80 typedef struct ns_common *ns_get_path_helper_t(void *);
81 extern int ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
82 void *private_data);
83
84 extern bool ns_match(const struct ns_common *ns, dev_t dev, ino_t ino);
85
86 extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
87 const struct proc_ns_operations *ns_ops);
88 extern void nsfs_init(void);
89
90 #endif /* _LINUX_PROC_NS_H */
91