1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_PID_NS_H
3 #define _LINUX_PID_NS_H
5 #include <linux/sched.h>
8 #include <linux/workqueue.h>
9 #include <linux/threads.h>
10 #include <linux/nsproxy.h>
11 #include <linux/ns_common.h>
12 #include <linux/idr.h>
14 /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
15 #define MAX_PID_NS_LEVEL 32
19 #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE)
21 * sysctl for vm.memfd_noexec
22 * 0: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL
23 * acts like MFD_EXEC was set.
24 * 1: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL
25 * acts like MFD_NOEXEC_SEAL was set.
26 * 2: memfd_create() without MFD_NOEXEC_SEAL will be
29 #define MEMFD_NOEXEC_SCOPE_EXEC 0
30 #define MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL 1
31 #define MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED 2
34 struct pid_namespace {
37 unsigned int pid_allocated;
38 struct task_struct *child_reaper;
39 struct kmem_cache *pid_cachep;
41 struct pid_namespace *parent;
42 #ifdef CONFIG_BSD_PROCESS_ACCT
45 struct user_namespace *user_ns;
46 struct ucounts *ucounts;
47 int reboot; /* group exit code if this pidns was rebooted */
49 #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE)
50 /* sysctl for vm.memfd_noexec */
51 int memfd_noexec_scope;
55 extern struct pid_namespace init_pid_ns;
57 #define PIDNS_ADDING (1U << 31)
60 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
62 if (ns != &init_pid_ns)
63 refcount_inc(&ns->ns.count);
67 extern struct pid_namespace *copy_pid_ns(unsigned long flags,
68 struct user_namespace *user_ns, struct pid_namespace *ns);
69 extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
70 extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
71 extern void put_pid_ns(struct pid_namespace *ns);
73 #else /* !CONFIG_PID_NS */
74 #include <linux/err.h>
76 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
81 static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
82 struct user_namespace *user_ns, struct pid_namespace *ns)
84 if (flags & CLONE_NEWPID)
85 ns = ERR_PTR(-EINVAL);
89 static inline void put_pid_ns(struct pid_namespace *ns)
93 static inline void zap_pid_ns_processes(struct pid_namespace *ns)
98 static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
102 #endif /* CONFIG_PID_NS */
104 extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
105 void pidhash_init(void);
106 void pid_idr_init(void);
108 static inline bool task_is_in_init_pid_ns(struct task_struct *tsk)
110 return task_active_pid_ns(tsk) == &init_pid_ns;
113 #endif /* _LINUX_PID_NS_H */