blob: 49538b172483c4f519100e1617f42d0f897bfbaa [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -08002#ifndef _LINUX_PID_NS_H
3#define _LINUX_PID_NS_H
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07004
5#include <linux/sched.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -05006#include <linux/bug.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07007#include <linux/mm.h>
Kent Overstreeta27bb332013-05-07 16:19:08 -07008#include <linux/workqueue.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07009#include <linux/threads.h>
Cedric Le Goater9a575a92006-12-08 02:37:59 -080010#include <linux/nsproxy.h>
11#include <linux/kref.h>
Al Viro435d5f42014-10-31 22:56:04 -040012#include <linux/ns_common.h>
Gargi Sharma95846ec2017-11-17 15:30:30 -080013#include <linux/idr.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -070014
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -070015
Al Viro59eda0e2015-01-10 17:53:21 -050016struct fs_pin;
Pavel Emelyanov20fad132008-07-25 01:48:43 -070017
Lafcadio Wluiki796f5712017-02-24 15:00:23 -080018enum { /* definitions for pid_namespace's hide_pid field */
19 HIDEPID_OFF = 0,
20 HIDEPID_NO_ACCESS = 1,
21 HIDEPID_INVISIBLE = 2,
22};
23
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080024struct pid_namespace {
Cedric Le Goater9a575a92006-12-08 02:37:59 -080025 struct kref kref;
Gargi Sharma95846ec2017-11-17 15:30:30 -080026 struct idr idr;
Al Viro1adfcb02013-10-03 13:28:06 -040027 struct rcu_head rcu;
Gargi Sharmae8cfbc22017-11-17 15:30:34 -080028 unsigned int pid_allocated;
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080029 struct task_struct *child_reaper;
Pavel Emelianovbaf8f0f2007-10-18 23:39:48 -070030 struct kmem_cache *pid_cachep;
Pavel Emelyanovcaafa432008-04-30 00:54:31 -070031 unsigned int level;
Pavel Emelyanovfaacbfd2007-10-18 23:40:04 -070032 struct pid_namespace *parent;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070033#ifdef CONFIG_PROC_FS
34 struct vfsmount *proc_mnt;
Al Viro021ada72013-03-29 19:27:05 -040035 struct dentry *proc_self;
Eric W. Biederman00978752014-07-31 03:10:50 -070036 struct dentry *proc_thread_self;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070037#endif
Pavel Emelyanov20fad132008-07-25 01:48:43 -070038#ifdef CONFIG_BSD_PROCESS_ACCT
Al Viro59eda0e2015-01-10 17:53:21 -050039 struct fs_pin *bacct;
Pavel Emelyanov20fad132008-07-25 01:48:43 -070040#endif
Eric W. Biederman49f4d8b2012-08-02 04:25:10 -070041 struct user_namespace *user_ns;
Eric W. Biedermanf333c702016-08-08 14:08:36 -050042 struct ucounts *ucounts;
Eric W. Biederman0a01f2c2012-08-01 10:33:47 -070043 struct work_struct proc_work;
Eric W. Biedermandcb0f222012-02-09 08:48:21 -080044 kgid_t pid_gid;
Vasiliy Kulikov04996802012-01-10 15:11:31 -080045 int hide_pid;
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070046 int reboot; /* group exit code if this pidns was rebooted */
Al Viro435d5f42014-10-31 22:56:04 -040047 struct ns_common ns;
Kees Cook3859a272016-10-28 01:22:25 -070048} __randomize_layout;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070049
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080050extern struct pid_namespace init_pid_ns;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070051
Gargi Sharmae8cfbc22017-11-17 15:30:34 -080052#define PIDNS_ADDING (1U << 31)
Eric W. Biedermanc876ad762012-12-21 20:27:12 -080053
Eric W. Biederman57d5f662007-11-14 17:00:13 -080054#ifdef CONFIG_PID_NS
Pavel Emelianova05f7b12007-10-18 23:39:47 -070055static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
Cedric Le Goater9a575a92006-12-08 02:37:59 -080056{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070057 if (ns != &init_pid_ns)
58 kref_get(&ns->kref);
Pavel Emelianova05f7b12007-10-18 23:39:47 -070059 return ns;
Cedric Le Goater9a575a92006-12-08 02:37:59 -080060}
61
Eric W. Biederman49f4d8b2012-08-02 04:25:10 -070062extern struct pid_namespace *copy_pid_ns(unsigned long flags,
63 struct user_namespace *user_ns, struct pid_namespace *ns);
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080064extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070065extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
Cyrill Gorcunovbbc2e3e2012-10-19 13:56:53 -070066extern void put_pid_ns(struct pid_namespace *ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080067
Eric W. Biederman57d5f662007-11-14 17:00:13 -080068#else /* !CONFIG_PID_NS */
69#include <linux/err.h>
70
71static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
72{
73 return ns;
74}
75
Eric W. Biederman49f4d8b2012-08-02 04:25:10 -070076static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
77 struct user_namespace *user_ns, struct pid_namespace *ns)
Eric W. Biederman57d5f662007-11-14 17:00:13 -080078{
79 if (flags & CLONE_NEWPID)
80 ns = ERR_PTR(-EINVAL);
81 return ns;
82}
83
84static inline void put_pid_ns(struct pid_namespace *ns)
85{
86}
87
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080088static inline void zap_pid_ns_processes(struct pid_namespace *ns)
89{
90 BUG();
91}
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070092
93static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
94{
95 return 0;
96}
Eric W. Biederman57d5f662007-11-14 17:00:13 -080097#endif /* CONFIG_PID_NS */
98
Eric W. Biederman61bce0f2009-01-07 18:08:49 -080099extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
Adrian Bunk3ae4eed2008-07-25 01:48:34 -0700100void pidhash_init(void);
Gargi Sharma95846ec2017-11-17 15:30:30 -0800101void pid_idr_init(void);
Adrian Bunk3ae4eed2008-07-25 01:48:34 -0700102
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -0800103#endif /* _LINUX_PID_NS_H */