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 CLG |
10 | #include <linux/nsproxy.h> |
11 | #include <linux/kref.h> | |
435d5f4b | 12 | #include <linux/ns_common.h> |
aa5a6662 SB |
13 | |
14 | struct pidmap { | |
15 | atomic_t nr_free; | |
16 | void *page; | |
17 | }; | |
18 | ||
5cc54451 RC |
19 | #define BITS_PER_PAGE (PAGE_SIZE * 8) |
20 | #define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1) | |
21 | #define PIDMAP_ENTRIES ((PID_MAX_LIMIT+BITS_PER_PAGE-1)/BITS_PER_PAGE) | |
aa5a6662 | 22 | |
59eda0e0 | 23 | struct fs_pin; |
20fad13a | 24 | |
796f571b LW |
25 | enum { /* definitions for pid_namespace's hide_pid field */ |
26 | HIDEPID_OFF = 0, | |
27 | HIDEPID_NO_ACCESS = 1, | |
28 | HIDEPID_INVISIBLE = 2, | |
29 | }; | |
30 | ||
61a58c6c | 31 | struct pid_namespace { |
9a575a92 CLG |
32 | struct kref kref; |
33 | struct pidmap pidmap[PIDMAP_ENTRIES]; | |
1adfcb03 | 34 | struct rcu_head rcu; |
9a575a92 | 35 | int last_pid; |
c876ad76 | 36 | unsigned int nr_hashed; |
84d73786 | 37 | struct task_struct *child_reaper; |
baf8f0f8 | 38 | struct kmem_cache *pid_cachep; |
caafa432 | 39 | unsigned int level; |
faacbfd3 | 40 | struct pid_namespace *parent; |
07543f5c PE |
41 | #ifdef CONFIG_PROC_FS |
42 | struct vfsmount *proc_mnt; | |
021ada7d | 43 | struct dentry *proc_self; |
0097875b | 44 | struct dentry *proc_thread_self; |
07543f5c | 45 | #endif |
20fad13a | 46 | #ifdef CONFIG_BSD_PROCESS_ACCT |
59eda0e0 | 47 | struct fs_pin *bacct; |
20fad13a | 48 | #endif |
49f4d8b9 | 49 | struct user_namespace *user_ns; |
f333c700 | 50 | struct ucounts *ucounts; |
0a01f2cc | 51 | struct work_struct proc_work; |
dcb0f222 | 52 | kgid_t pid_gid; |
0499680a | 53 | int hide_pid; |
cf3f8921 | 54 | int reboot; /* group exit code if this pidns was rebooted */ |
435d5f4b | 55 | struct ns_common ns; |
3859a271 | 56 | } __randomize_layout; |
3fbc9648 | 57 | |
61a58c6c | 58 | extern struct pid_namespace init_pid_ns; |
3fbc9648 | 59 | |
c876ad76 EB |
60 | #define PIDNS_HASH_ADDING (1U << 31) |
61 | ||
57d5f66b | 62 | #ifdef CONFIG_PID_NS |
a05f7b15 | 63 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
9a575a92 | 64 | { |
b461cc03 PE |
65 | if (ns != &init_pid_ns) |
66 | kref_get(&ns->kref); | |
a05f7b15 | 67 | return ns; |
9a575a92 CLG |
68 | } |
69 | ||
49f4d8b9 EB |
70 | extern struct pid_namespace *copy_pid_ns(unsigned long flags, |
71 | struct user_namespace *user_ns, struct pid_namespace *ns); | |
74bd59bb | 72 | extern void zap_pid_ns_processes(struct pid_namespace *pid_ns); |
cf3f8921 | 73 | extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd); |
bbc2e3ef | 74 | extern void put_pid_ns(struct pid_namespace *ns); |
9a575a92 | 75 | |
57d5f66b EB |
76 | #else /* !CONFIG_PID_NS */ |
77 | #include <linux/err.h> | |
78 | ||
79 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) | |
80 | { | |
81 | return ns; | |
82 | } | |
83 | ||
49f4d8b9 EB |
84 | static inline struct pid_namespace *copy_pid_ns(unsigned long flags, |
85 | struct user_namespace *user_ns, struct pid_namespace *ns) | |
57d5f66b EB |
86 | { |
87 | if (flags & CLONE_NEWPID) | |
88 | ns = ERR_PTR(-EINVAL); | |
89 | return ns; | |
90 | } | |
91 | ||
92 | static inline void put_pid_ns(struct pid_namespace *ns) | |
93 | { | |
94 | } | |
95 | ||
74bd59bb PE |
96 | static inline void zap_pid_ns_processes(struct pid_namespace *ns) |
97 | { | |
98 | BUG(); | |
99 | } | |
cf3f8921 DL |
100 | |
101 | static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | |
102 | { | |
103 | return 0; | |
104 | } | |
57d5f66b EB |
105 | #endif /* CONFIG_PID_NS */ |
106 | ||
61bce0f1 | 107 | extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk); |
3ae4eed3 AB |
108 | void pidhash_init(void); |
109 | void pidmap_init(void); | |
110 | ||
61a58c6c | 111 | #endif /* _LINUX_PID_NS_H */ |