pid_namespace.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_PID_NS_H
  3. #define _LINUX_PID_NS_H
  4. #include <linux/sched.h>
  5. #include <linux/bug.h>
  6. #include <linux/mm.h>
  7. #include <linux/workqueue.h>
  8. #include <linux/threads.h>
  9. #include <linux/nsproxy.h>
  10. #include <linux/ns_common.h>
  11. #include <linux/idr.h>
  12. /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
  13. #define MAX_PID_NS_LEVEL 32
  14. struct fs_pin;
  15. struct pid_namespace {
  16. struct idr idr;
  17. struct rcu_head rcu;
  18. unsigned int pid_allocated;
  19. struct task_struct *child_reaper;
  20. struct kmem_cache *pid_cachep;
  21. unsigned int level;
  22. struct pid_namespace *parent;
  23. #ifdef CONFIG_BSD_PROCESS_ACCT
  24. struct fs_pin *bacct;
  25. #endif
  26. struct user_namespace *user_ns;
  27. struct ucounts *ucounts;
  28. int reboot; /* group exit code if this pidns was rebooted */
  29. struct ns_common ns;
  30. } __randomize_layout;
  31. extern struct pid_namespace init_pid_ns;
  32. #define PIDNS_ADDING (1U << 31)
  33. #ifdef CONFIG_PID_NS
  34. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  35. {
  36. if (ns != &init_pid_ns)
  37. refcount_inc(&ns->ns.count);
  38. return ns;
  39. }
  40. extern struct pid_namespace *copy_pid_ns(unsigned long flags,
  41. struct user_namespace *user_ns, struct pid_namespace *ns);
  42. extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
  43. extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
  44. extern void put_pid_ns(struct pid_namespace *ns);
  45. #else /* !CONFIG_PID_NS */
  46. #include <linux/err.h>
  47. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  48. {
  49. return ns;
  50. }
  51. static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
  52. struct user_namespace *user_ns, struct pid_namespace *ns)
  53. {
  54. if (flags & CLONE_NEWPID)
  55. ns = ERR_PTR(-EINVAL);
  56. return ns;
  57. }
  58. static inline void put_pid_ns(struct pid_namespace *ns)
  59. {
  60. }
  61. static inline void zap_pid_ns_processes(struct pid_namespace *ns)
  62. {
  63. BUG();
  64. }
  65. static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
  66. {
  67. return 0;
  68. }
  69. #endif /* CONFIG_PID_NS */
  70. extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
  71. void pidhash_init(void);
  72. void pid_idr_init(void);
  73. static inline bool task_is_in_init_pid_ns(struct task_struct *tsk)
  74. {
  75. return task_active_pid_ns(tsk) == &init_pid_ns;
  76. }
  77. #endif /* _LINUX_PID_NS_H */