at v4.14 2.6 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_PID_NS_H 3#define _LINUX_PID_NS_H 4 5#include <linux/sched.h> 6#include <linux/bug.h> 7#include <linux/mm.h> 8#include <linux/workqueue.h> 9#include <linux/threads.h> 10#include <linux/nsproxy.h> 11#include <linux/kref.h> 12#include <linux/ns_common.h> 13 14struct pidmap { 15 atomic_t nr_free; 16 void *page; 17}; 18 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) 22 23struct fs_pin; 24 25enum { /* definitions for pid_namespace's hide_pid field */ 26 HIDEPID_OFF = 0, 27 HIDEPID_NO_ACCESS = 1, 28 HIDEPID_INVISIBLE = 2, 29}; 30 31struct pid_namespace { 32 struct kref kref; 33 struct pidmap pidmap[PIDMAP_ENTRIES]; 34 struct rcu_head rcu; 35 int last_pid; 36 unsigned int nr_hashed; 37 struct task_struct *child_reaper; 38 struct kmem_cache *pid_cachep; 39 unsigned int level; 40 struct pid_namespace *parent; 41#ifdef CONFIG_PROC_FS 42 struct vfsmount *proc_mnt; 43 struct dentry *proc_self; 44 struct dentry *proc_thread_self; 45#endif 46#ifdef CONFIG_BSD_PROCESS_ACCT 47 struct fs_pin *bacct; 48#endif 49 struct user_namespace *user_ns; 50 struct ucounts *ucounts; 51 struct work_struct proc_work; 52 kgid_t pid_gid; 53 int hide_pid; 54 int reboot; /* group exit code if this pidns was rebooted */ 55 struct ns_common ns; 56} __randomize_layout; 57 58extern struct pid_namespace init_pid_ns; 59 60#define PIDNS_HASH_ADDING (1U << 31) 61 62#ifdef CONFIG_PID_NS 63static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) 64{ 65 if (ns != &init_pid_ns) 66 kref_get(&ns->kref); 67 return ns; 68} 69 70extern struct pid_namespace *copy_pid_ns(unsigned long flags, 71 struct user_namespace *user_ns, struct pid_namespace *ns); 72extern void zap_pid_ns_processes(struct pid_namespace *pid_ns); 73extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd); 74extern void put_pid_ns(struct pid_namespace *ns); 75 76#else /* !CONFIG_PID_NS */ 77#include <linux/err.h> 78 79static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) 80{ 81 return ns; 82} 83 84static inline struct pid_namespace *copy_pid_ns(unsigned long flags, 85 struct user_namespace *user_ns, struct pid_namespace *ns) 86{ 87 if (flags & CLONE_NEWPID) 88 ns = ERR_PTR(-EINVAL); 89 return ns; 90} 91 92static inline void put_pid_ns(struct pid_namespace *ns) 93{ 94} 95 96static inline void zap_pid_ns_processes(struct pid_namespace *ns) 97{ 98 BUG(); 99} 100 101static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) 102{ 103 return 0; 104} 105#endif /* CONFIG_PID_NS */ 106 107extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk); 108void pidhash_init(void); 109void pidmap_init(void); 110 111#endif /* _LINUX_PID_NS_H */