Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 2 | #ifndef _LINUX_PID_NS_H |
| 3 | #define _LINUX_PID_NS_H |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 4 | |
| 5 | #include <linux/sched.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 6 | #include <linux/bug.h> |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 7 | #include <linux/mm.h> |
Kent Overstreet | a27bb33 | 2013-05-07 16:19:08 -0700 | [diff] [blame] | 8 | #include <linux/workqueue.h> |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 9 | #include <linux/threads.h> |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 10 | #include <linux/nsproxy.h> |
| 11 | #include <linux/kref.h> |
Al Viro | 435d5f4 | 2014-10-31 22:56:04 -0400 | [diff] [blame] | 12 | #include <linux/ns_common.h> |
Gargi Sharma | 95846ec | 2017-11-17 15:30:30 -0800 | [diff] [blame] | 13 | #include <linux/idr.h> |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 14 | |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 15 | |
Al Viro | 59eda0e | 2015-01-10 17:53:21 -0500 | [diff] [blame] | 16 | struct fs_pin; |
Pavel Emelyanov | 20fad13 | 2008-07-25 01:48:43 -0700 | [diff] [blame] | 17 | |
Lafcadio Wluiki | 796f571 | 2017-02-24 15:00:23 -0800 | [diff] [blame] | 18 | enum { /* definitions for pid_namespace's hide_pid field */ |
| 19 | HIDEPID_OFF = 0, |
| 20 | HIDEPID_NO_ACCESS = 1, |
| 21 | HIDEPID_INVISIBLE = 2, |
| 22 | }; |
| 23 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 24 | struct pid_namespace { |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 25 | struct kref kref; |
Gargi Sharma | 95846ec | 2017-11-17 15:30:30 -0800 | [diff] [blame] | 26 | struct idr idr; |
Al Viro | 1adfcb0 | 2013-10-03 13:28:06 -0400 | [diff] [blame] | 27 | struct rcu_head rcu; |
Gargi Sharma | e8cfbc2 | 2017-11-17 15:30:34 -0800 | [diff] [blame] | 28 | unsigned int pid_allocated; |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 29 | struct task_struct *child_reaper; |
Pavel Emelianov | baf8f0f | 2007-10-18 23:39:48 -0700 | [diff] [blame] | 30 | struct kmem_cache *pid_cachep; |
Pavel Emelyanov | caafa43 | 2008-04-30 00:54:31 -0700 | [diff] [blame] | 31 | unsigned int level; |
Pavel Emelyanov | faacbfd | 2007-10-18 23:40:04 -0700 | [diff] [blame] | 32 | struct pid_namespace *parent; |
Pavel Emelyanov | 07543f5 | 2007-10-18 23:40:08 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_PROC_FS |
| 34 | struct vfsmount *proc_mnt; |
Al Viro | 021ada7 | 2013-03-29 19:27:05 -0400 | [diff] [blame] | 35 | struct dentry *proc_self; |
Eric W. Biederman | 0097875 | 2014-07-31 03:10:50 -0700 | [diff] [blame] | 36 | struct dentry *proc_thread_self; |
Pavel Emelyanov | 07543f5 | 2007-10-18 23:40:08 -0700 | [diff] [blame] | 37 | #endif |
Pavel Emelyanov | 20fad13 | 2008-07-25 01:48:43 -0700 | [diff] [blame] | 38 | #ifdef CONFIG_BSD_PROCESS_ACCT |
Al Viro | 59eda0e | 2015-01-10 17:53:21 -0500 | [diff] [blame] | 39 | struct fs_pin *bacct; |
Pavel Emelyanov | 20fad13 | 2008-07-25 01:48:43 -0700 | [diff] [blame] | 40 | #endif |
Eric W. Biederman | 49f4d8b | 2012-08-02 04:25:10 -0700 | [diff] [blame] | 41 | struct user_namespace *user_ns; |
Eric W. Biederman | f333c70 | 2016-08-08 14:08:36 -0500 | [diff] [blame] | 42 | struct ucounts *ucounts; |
Eric W. Biederman | 0a01f2c | 2012-08-01 10:33:47 -0700 | [diff] [blame] | 43 | struct work_struct proc_work; |
Eric W. Biederman | dcb0f22 | 2012-02-09 08:48:21 -0800 | [diff] [blame] | 44 | kgid_t pid_gid; |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 45 | int hide_pid; |
Daniel Lezcano | cf3f892 | 2012-03-28 14:42:51 -0700 | [diff] [blame] | 46 | int reboot; /* group exit code if this pidns was rebooted */ |
Al Viro | 435d5f4 | 2014-10-31 22:56:04 -0400 | [diff] [blame] | 47 | struct ns_common ns; |
Kees Cook | 3859a27 | 2016-10-28 01:22:25 -0700 | [diff] [blame] | 48 | } __randomize_layout; |
Sukadev Bhattiprolu | 3fbc964 | 2006-10-02 02:17:24 -0700 | [diff] [blame] | 49 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 50 | extern struct pid_namespace init_pid_ns; |
Sukadev Bhattiprolu | 3fbc964 | 2006-10-02 02:17:24 -0700 | [diff] [blame] | 51 | |
Gargi Sharma | e8cfbc2 | 2017-11-17 15:30:34 -0800 | [diff] [blame] | 52 | #define PIDNS_ADDING (1U << 31) |
Eric W. Biederman | c876ad76 | 2012-12-21 20:27:12 -0800 | [diff] [blame] | 53 | |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 54 | #ifdef CONFIG_PID_NS |
Pavel Emelianov | a05f7b1 | 2007-10-18 23:39:47 -0700 | [diff] [blame] | 55 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 56 | { |
Pavel Emelyanov | b461cc0 | 2007-10-18 23:40:09 -0700 | [diff] [blame] | 57 | if (ns != &init_pid_ns) |
| 58 | kref_get(&ns->kref); |
Pavel Emelianov | a05f7b1 | 2007-10-18 23:39:47 -0700 | [diff] [blame] | 59 | return ns; |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Eric W. Biederman | 49f4d8b | 2012-08-02 04:25:10 -0700 | [diff] [blame] | 62 | extern struct pid_namespace *copy_pid_ns(unsigned long flags, |
| 63 | struct user_namespace *user_ns, struct pid_namespace *ns); |
Pavel Emelyanov | 74bd59b | 2008-02-08 04:18:24 -0800 | [diff] [blame] | 64 | extern void zap_pid_ns_processes(struct pid_namespace *pid_ns); |
Daniel Lezcano | cf3f892 | 2012-03-28 14:42:51 -0700 | [diff] [blame] | 65 | extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd); |
Cyrill Gorcunov | bbc2e3e | 2012-10-19 13:56:53 -0700 | [diff] [blame] | 66 | extern void put_pid_ns(struct pid_namespace *ns); |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 67 | |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 68 | #else /* !CONFIG_PID_NS */ |
| 69 | #include <linux/err.h> |
| 70 | |
| 71 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
| 72 | { |
| 73 | return ns; |
| 74 | } |
| 75 | |
Eric W. Biederman | 49f4d8b | 2012-08-02 04:25:10 -0700 | [diff] [blame] | 76 | static inline struct pid_namespace *copy_pid_ns(unsigned long flags, |
| 77 | struct user_namespace *user_ns, struct pid_namespace *ns) |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 78 | { |
| 79 | if (flags & CLONE_NEWPID) |
| 80 | ns = ERR_PTR(-EINVAL); |
| 81 | return ns; |
| 82 | } |
| 83 | |
| 84 | static inline void put_pid_ns(struct pid_namespace *ns) |
| 85 | { |
| 86 | } |
| 87 | |
Pavel Emelyanov | 74bd59b | 2008-02-08 04:18:24 -0800 | [diff] [blame] | 88 | static inline void zap_pid_ns_processes(struct pid_namespace *ns) |
| 89 | { |
| 90 | BUG(); |
| 91 | } |
Daniel Lezcano | cf3f892 | 2012-03-28 14:42:51 -0700 | [diff] [blame] | 92 | |
| 93 | static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) |
| 94 | { |
| 95 | return 0; |
| 96 | } |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 97 | #endif /* CONFIG_PID_NS */ |
| 98 | |
Eric W. Biederman | 61bce0f | 2009-01-07 18:08:49 -0800 | [diff] [blame] | 99 | extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk); |
Adrian Bunk | 3ae4eed | 2008-07-25 01:48:34 -0700 | [diff] [blame] | 100 | void pidhash_init(void); |
Gargi Sharma | 95846ec | 2017-11-17 15:30:30 -0800 | [diff] [blame] | 101 | void pid_idr_init(void); |
Adrian Bunk | 3ae4eed | 2008-07-25 01:48:34 -0700 | [diff] [blame] | 102 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 103 | #endif /* _LINUX_PID_NS_H */ |