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 JX |
19 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) |
20 | /* | |
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 | |
27 | * rejected. | |
28 | */ | |
29 | #define MEMFD_NOEXEC_SCOPE_EXEC 0 | |
30 | #define MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL 1 | |
31 | #define MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED 2 | |
32 | #endif | |
33 | ||
61a58c6c | 34 | struct pid_namespace { |
95846ecf | 35 | struct idr idr; |
1adfcb03 | 36 | struct rcu_head rcu; |
e8cfbc24 | 37 | unsigned int pid_allocated; |
84d73786 | 38 | struct task_struct *child_reaper; |
baf8f0f8 | 39 | struct kmem_cache *pid_cachep; |
caafa432 | 40 | unsigned int level; |
faacbfd3 | 41 | struct pid_namespace *parent; |
20fad13a | 42 | #ifdef CONFIG_BSD_PROCESS_ACCT |
59eda0e0 | 43 | struct fs_pin *bacct; |
20fad13a | 44 | #endif |
49f4d8b9 | 45 | struct user_namespace *user_ns; |
f333c700 | 46 | struct ucounts *ucounts; |
cf3f8921 | 47 | int reboot; /* group exit code if this pidns was rebooted */ |
435d5f4b | 48 | struct ns_common ns; |
105ff533 JX |
49 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) |
50 | /* sysctl for vm.memfd_noexec */ | |
51 | int memfd_noexec_scope; | |
52 | #endif | |
3859a271 | 53 | } __randomize_layout; |
3fbc9648 | 54 | |
61a58c6c | 55 | extern struct pid_namespace init_pid_ns; |
3fbc9648 | 56 | |
e8cfbc24 | 57 | #define PIDNS_ADDING (1U << 31) |
c876ad76 | 58 | |
57d5f66b | 59 | #ifdef CONFIG_PID_NS |
a05f7b15 | 60 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
9a575a92 | 61 | { |
b461cc03 | 62 | if (ns != &init_pid_ns) |
8eb71d95 | 63 | refcount_inc(&ns->ns.count); |
a05f7b15 | 64 | return ns; |
9a575a92 CLG |
65 | } |
66 | ||
49f4d8b9 EB |
67 | extern struct pid_namespace *copy_pid_ns(unsigned long flags, |
68 | struct user_namespace *user_ns, struct pid_namespace *ns); | |
74bd59bb | 69 | extern void zap_pid_ns_processes(struct pid_namespace *pid_ns); |
cf3f8921 | 70 | extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd); |
bbc2e3ef | 71 | extern void put_pid_ns(struct pid_namespace *ns); |
9a575a92 | 72 | |
57d5f66b EB |
73 | #else /* !CONFIG_PID_NS */ |
74 | #include <linux/err.h> | |
75 | ||
76 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) | |
77 | { | |
78 | return ns; | |
79 | } | |
80 | ||
49f4d8b9 EB |
81 | static inline struct pid_namespace *copy_pid_ns(unsigned long flags, |
82 | struct user_namespace *user_ns, struct pid_namespace *ns) | |
57d5f66b EB |
83 | { |
84 | if (flags & CLONE_NEWPID) | |
85 | ns = ERR_PTR(-EINVAL); | |
86 | return ns; | |
87 | } | |
88 | ||
89 | static inline void put_pid_ns(struct pid_namespace *ns) | |
90 | { | |
91 | } | |
92 | ||
74bd59bb PE |
93 | static inline void zap_pid_ns_processes(struct pid_namespace *ns) |
94 | { | |
95 | BUG(); | |
96 | } | |
cf3f8921 DL |
97 | |
98 | static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | |
99 | { | |
100 | return 0; | |
101 | } | |
57d5f66b EB |
102 | #endif /* CONFIG_PID_NS */ |
103 | ||
61bce0f1 | 104 | extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk); |
3ae4eed3 | 105 | void pidhash_init(void); |
95846ecf | 106 | void pid_idr_init(void); |
3ae4eed3 | 107 | |
d7e4f854 LY |
108 | static inline bool task_is_in_init_pid_ns(struct task_struct *tsk) |
109 | { | |
110 | return task_active_pid_ns(tsk) == &init_pid_ns; | |
111 | } | |
112 | ||
61a58c6c | 113 | #endif /* _LINUX_PID_NS_H */ |