Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
61a58c6c SB |
2 | #ifndef _LINUX_PID_NS_H |
3 | #define _LINUX_PID_NS_H | |
aa5a6662 SB |
4 | |
5 | #include <linux/sched.h> | |
187f1882 | 6 | #include <linux/bug.h> |
aa5a6662 | 7 | #include <linux/mm.h> |
a27bb332 | 8 | #include <linux/workqueue.h> |
aa5a6662 | 9 | #include <linux/threads.h> |
9a575a92 | 10 | #include <linux/nsproxy.h> |
435d5f4b | 11 | #include <linux/ns_common.h> |
95846ecf | 12 | #include <linux/idr.h> |
aa5a6662 | 13 | |
49cb2fc4 AR |
14 | /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */ |
15 | #define MAX_PID_NS_LEVEL 32 | |
aa5a6662 | 16 | |
59eda0e0 | 17 | struct fs_pin; |
20fad13a | 18 | |
105ff533 | 19 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) |
202e1422 AS |
20 | /* modes for vm.memfd_noexec sysctl */ |
21 | #define MEMFD_NOEXEC_SCOPE_EXEC 0 /* MFD_EXEC implied if unset */ | |
22 | #define MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL 1 /* MFD_NOEXEC_SEAL implied if unset */ | |
23 | #define MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED 2 /* same as 1, except MFD_EXEC rejected */ | |
105ff533 JX |
24 | #endif |
25 | ||
61a58c6c | 26 | struct pid_namespace { |
95846ecf | 27 | struct idr idr; |
1adfcb03 | 28 | struct rcu_head rcu; |
e8cfbc24 | 29 | unsigned int pid_allocated; |
84d73786 | 30 | struct task_struct *child_reaper; |
baf8f0f8 | 31 | struct kmem_cache *pid_cachep; |
caafa432 | 32 | unsigned int level; |
7863dcc7 | 33 | int pid_max; |
faacbfd3 | 34 | struct pid_namespace *parent; |
20fad13a | 35 | #ifdef CONFIG_BSD_PROCESS_ACCT |
59eda0e0 | 36 | struct fs_pin *bacct; |
20fad13a | 37 | #endif |
49f4d8b9 | 38 | struct user_namespace *user_ns; |
f333c700 | 39 | struct ucounts *ucounts; |
cf3f8921 | 40 | int reboot; /* group exit code if this pidns was rebooted */ |
435d5f4b | 41 | struct ns_common ns; |
7863dcc7 CB |
42 | struct work_struct work; |
43 | #ifdef CONFIG_SYSCTL | |
44 | struct ctl_table_set set; | |
45 | struct ctl_table_header *sysctls; | |
46 | #if defined(CONFIG_MEMFD_CREATE) | |
105ff533 JX |
47 | int memfd_noexec_scope; |
48 | #endif | |
7863dcc7 | 49 | #endif |
3859a271 | 50 | } __randomize_layout; |
3fbc9648 | 51 | |
61a58c6c | 52 | extern struct pid_namespace init_pid_ns; |
3fbc9648 | 53 | |
e8cfbc24 | 54 | #define PIDNS_ADDING (1U << 31) |
c876ad76 | 55 | |
57d5f66b | 56 | #ifdef CONFIG_PID_NS |
a05f7b15 | 57 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
9a575a92 | 58 | { |
b461cc03 | 59 | if (ns != &init_pid_ns) |
8eb71d95 | 60 | refcount_inc(&ns->ns.count); |
a05f7b15 | 61 | return ns; |
9a575a92 CLG |
62 | } |
63 | ||
9876cfe8 AS |
64 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) |
65 | static inline int pidns_memfd_noexec_scope(struct pid_namespace *ns) | |
66 | { | |
67 | int scope = MEMFD_NOEXEC_SCOPE_EXEC; | |
68 | ||
69 | for (; ns; ns = ns->parent) | |
70 | scope = max(scope, READ_ONCE(ns->memfd_noexec_scope)); | |
71 | ||
72 | return scope; | |
73 | } | |
74 | #else | |
75 | static inline int pidns_memfd_noexec_scope(struct pid_namespace *ns) | |
76 | { | |
77 | return 0; | |
78 | } | |
79 | #endif | |
80 | ||
49f4d8b9 EB |
81 | extern struct pid_namespace *copy_pid_ns(unsigned long flags, |
82 | struct user_namespace *user_ns, struct pid_namespace *ns); | |
74bd59bb | 83 | extern void zap_pid_ns_processes(struct pid_namespace *pid_ns); |
cf3f8921 | 84 | extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd); |
bbc2e3ef | 85 | extern void put_pid_ns(struct pid_namespace *ns); |
9a575a92 | 86 | |
57d5f66b EB |
87 | #else /* !CONFIG_PID_NS */ |
88 | #include <linux/err.h> | |
89 | ||
90 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) | |
91 | { | |
92 | return ns; | |
93 | } | |
94 | ||
9876cfe8 AS |
95 | static inline int pidns_memfd_noexec_scope(struct pid_namespace *ns) |
96 | { | |
97 | return 0; | |
98 | } | |
99 | ||
49f4d8b9 EB |
100 | static inline struct pid_namespace *copy_pid_ns(unsigned long flags, |
101 | struct user_namespace *user_ns, struct pid_namespace *ns) | |
57d5f66b EB |
102 | { |
103 | if (flags & CLONE_NEWPID) | |
104 | ns = ERR_PTR(-EINVAL); | |
105 | return ns; | |
106 | } | |
107 | ||
108 | static inline void put_pid_ns(struct pid_namespace *ns) | |
109 | { | |
110 | } | |
111 | ||
74bd59bb PE |
112 | static inline void zap_pid_ns_processes(struct pid_namespace *ns) |
113 | { | |
114 | BUG(); | |
115 | } | |
cf3f8921 DL |
116 | |
117 | static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | |
118 | { | |
119 | return 0; | |
120 | } | |
57d5f66b EB |
121 | #endif /* CONFIG_PID_NS */ |
122 | ||
61bce0f1 | 123 | extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk); |
3ae4eed3 | 124 | void pidhash_init(void); |
95846ecf | 125 | void pid_idr_init(void); |
7863dcc7 CB |
126 | int register_pidns_sysctls(struct pid_namespace *pidns); |
127 | void unregister_pidns_sysctls(struct pid_namespace *pidns); | |
3ae4eed3 | 128 | |
d7e4f854 LY |
129 | static inline bool task_is_in_init_pid_ns(struct task_struct *tsk) |
130 | { | |
131 | return task_active_pid_ns(tsk) == &init_pid_ns; | |
132 | } | |
133 | ||
61a58c6c | 134 | #endif /* _LINUX_PID_NS_H */ |