1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
20bb80f24SDavid Howells /*
30bb80f24SDavid Howells * procfs namespace bits
40bb80f24SDavid Howells */
50bb80f24SDavid Howells #ifndef _LINUX_PROC_NS_H
60bb80f24SDavid Howells #define _LINUX_PROC_NS_H
70bb80f24SDavid Howells
8e149ed2bSAl Viro #include <linux/ns_common.h>
9e149ed2bSAl Viro
100bb80f24SDavid Howells struct pid_namespace;
11f2a8d52eSChristian Brauner struct nsset;
12e149ed2bSAl Viro struct path;
13a79a908fSAditya Kali struct task_struct;
14a79a908fSAditya Kali struct inode;
150bb80f24SDavid Howells
160bb80f24SDavid Howells struct proc_ns_operations {
170bb80f24SDavid Howells const char *name;
1825b14e92SKirill Tkhai const char *real_ns_name;
190bb80f24SDavid Howells int type;
2064964528SAl Viro struct ns_common *(*get)(struct task_struct *task);
2164964528SAl Viro void (*put)(struct ns_common *ns);
22f2a8d52eSChristian Brauner int (*install)(struct nsset *nsset, struct ns_common *ns);
23bcac25a5SAndrey Vagin struct user_namespace *(*owner)(struct ns_common *ns);
24a7306ed8SAndrey Vagin struct ns_common *(*get_parent)(struct ns_common *ns);
253859a271SKees Cook } __randomize_layout;
260bb80f24SDavid Howells
270bb80f24SDavid Howells extern const struct proc_ns_operations netns_operations;
280bb80f24SDavid Howells extern const struct proc_ns_operations utsns_operations;
290bb80f24SDavid Howells extern const struct proc_ns_operations ipcns_operations;
300bb80f24SDavid Howells extern const struct proc_ns_operations pidns_operations;
31eaa0d190SKirill Tkhai extern const struct proc_ns_operations pidns_for_children_operations;
320bb80f24SDavid Howells extern const struct proc_ns_operations userns_operations;
330bb80f24SDavid Howells extern const struct proc_ns_operations mntns_operations;
34a79a908fSAditya Kali extern const struct proc_ns_operations cgroupns_operations;
35769071acSAndrei Vagin extern const struct proc_ns_operations timens_operations;
36769071acSAndrei Vagin extern const struct proc_ns_operations timens_for_children_operations;
370bb80f24SDavid Howells
380bb80f24SDavid Howells /*
390bb80f24SDavid Howells * We always define these enumerators
400bb80f24SDavid Howells */
410bb80f24SDavid Howells enum {
420bb80f24SDavid Howells PROC_ROOT_INO = 1,
430bb80f24SDavid Howells PROC_IPC_INIT_INO = 0xEFFFFFFFU,
440bb80f24SDavid Howells PROC_UTS_INIT_INO = 0xEFFFFFFEU,
450bb80f24SDavid Howells PROC_USER_INIT_INO = 0xEFFFFFFDU,
460bb80f24SDavid Howells PROC_PID_INIT_INO = 0xEFFFFFFCU,
47a79a908fSAditya Kali PROC_CGROUP_INIT_INO = 0xEFFFFFFBU,
48769071acSAndrei Vagin PROC_TIME_INIT_INO = 0xEFFFFFFAU,
490bb80f24SDavid Howells };
500bb80f24SDavid Howells
510bb80f24SDavid Howells #ifdef CONFIG_PROC_FS
520bb80f24SDavid Howells
530bb80f24SDavid Howells extern int proc_alloc_inum(unsigned int *pino);
540bb80f24SDavid Howells extern void proc_free_inum(unsigned int inum);
550bb80f24SDavid Howells
560bb80f24SDavid Howells #else /* CONFIG_PROC_FS */
570bb80f24SDavid Howells
proc_alloc_inum(unsigned int * inum)580bb80f24SDavid Howells static inline int proc_alloc_inum(unsigned int *inum)
590bb80f24SDavid Howells {
600bb80f24SDavid Howells *inum = 1;
610bb80f24SDavid Howells return 0;
620bb80f24SDavid Howells }
proc_free_inum(unsigned int inum)630bb80f24SDavid Howells static inline void proc_free_inum(unsigned int inum) {}
640bb80f24SDavid Howells
650bb80f24SDavid Howells #endif /* CONFIG_PROC_FS */
660bb80f24SDavid Howells
ns_alloc_inum(struct ns_common * ns)67e149ed2bSAl Viro static inline int ns_alloc_inum(struct ns_common *ns)
68e149ed2bSAl Viro {
69*1fa08aecSChristian Brauner WRITE_ONCE(ns->stashed, NULL);
70e149ed2bSAl Viro return proc_alloc_inum(&ns->inum);
71e149ed2bSAl Viro }
72e149ed2bSAl Viro
736344c433SAl Viro #define ns_free_inum(ns) proc_free_inum((ns)->inum)
746344c433SAl Viro
75e149ed2bSAl Viro #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
76ce623f89SAleksa Sarai extern int ns_get_path(struct path *path, struct task_struct *task,
77e149ed2bSAl Viro const struct proc_ns_operations *ns_ops);
78cdab6ba8SJakub Kicinski typedef struct ns_common *ns_get_path_helper_t(void *);
79ce623f89SAleksa Sarai extern int ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
80cdab6ba8SJakub Kicinski void *private_data);
81e149ed2bSAl Viro
821e2328e7SCarlos Neira extern bool ns_match(const struct ns_common *ns, dev_t dev, ino_t ino);
831e2328e7SCarlos Neira
84e149ed2bSAl Viro extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
85e149ed2bSAl Viro const struct proc_ns_operations *ns_ops);
86e149ed2bSAl Viro extern void nsfs_init(void);
87e149ed2bSAl Viro
880bb80f24SDavid Howells #endif /* _LINUX_PROC_NS_H */
89