ipc_namespace.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef __IPC_NAMESPACE_H__
  2. #define __IPC_NAMESPACE_H__
  3. #include <linux/err.h>
  4. #include <linux/idr.h>
  5. #include <linux/rwsem.h>
  6. #include <linux/notifier.h>
  7. #include <linux/nsproxy.h>
  8. #include <linux/ns_common.h>
  9. struct user_namespace;
  10. struct ipc_ids {
  11. int in_use;
  12. unsigned short seq;
  13. struct rw_semaphore rwsem;
  14. struct idr ipcs_idr;
  15. int next_id;
  16. };
  17. struct ipc_namespace {
  18. atomic_t count;
  19. struct ipc_ids ids[3];
  20. int sem_ctls[4];
  21. int used_sems;
  22. unsigned int msg_ctlmax;
  23. unsigned int msg_ctlmnb;
  24. unsigned int msg_ctlmni;
  25. atomic_t msg_bytes;
  26. atomic_t msg_hdrs;
  27. size_t shm_ctlmax;
  28. size_t shm_ctlall;
  29. unsigned long shm_tot;
  30. int shm_ctlmni;
  31. /*
  32. * Defines whether IPC_RMID is forced for _all_ shm segments regardless
  33. * of shmctl()
  34. */
  35. int shm_rmid_forced;
  36. struct notifier_block ipcns_nb;
  37. /* The kern_mount of the mqueuefs sb. We take a ref on it */
  38. struct vfsmount *mq_mnt;
  39. /* # queues in this ns, protected by mq_lock */
  40. unsigned int mq_queues_count;
  41. /* next fields are set through sysctl */
  42. unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */
  43. unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */
  44. unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */
  45. unsigned int mq_msg_default;
  46. unsigned int mq_msgsize_default;
  47. /* user_ns which owns the ipc ns */
  48. struct user_namespace *user_ns;
  49. struct ns_common ns;
  50. };
  51. extern struct ipc_namespace init_ipc_ns;
  52. extern atomic_t nr_ipc_ns;
  53. extern spinlock_t mq_lock;
  54. #ifdef CONFIG_SYSVIPC
  55. extern void shm_destroy_orphaned(struct ipc_namespace *ns);
  56. #else /* CONFIG_SYSVIPC */
  57. static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
  58. #endif /* CONFIG_SYSVIPC */
  59. #ifdef CONFIG_POSIX_MQUEUE
  60. extern int mq_init_ns(struct ipc_namespace *ns);
  61. /*
  62. * POSIX Message Queue default values:
  63. *
  64. * MIN_*: Lowest value an admin can set the maximum unprivileged limit to
  65. * DFLT_*MAX: Default values for the maximum unprivileged limits
  66. * DFLT_{MSG,MSGSIZE}: Default values used when the user doesn't supply
  67. * an attribute to the open call and the queue must be created
  68. * HARD_*: Highest value the maximums can be set to. These are enforced
  69. * on CAP_SYS_RESOURCE apps as well making them inviolate (so make them
  70. * suitably high)
  71. *
  72. * POSIX Requirements:
  73. * Per app minimum openable message queues - 8. This does not map well
  74. * to the fact that we limit the number of queues on a per namespace
  75. * basis instead of a per app basis. So, make the default high enough
  76. * that no given app should have a hard time opening 8 queues.
  77. * Minimum maximum for HARD_MSGMAX - 32767. I bumped this to 65536.
  78. * Minimum maximum for HARD_MSGSIZEMAX - POSIX is silent on this. However,
  79. * we have run into a situation where running applications in the wild
  80. * require this to be at least 5MB, and preferably 10MB, so I set the
  81. * value to 16MB in hopes that this user is the worst of the bunch and
  82. * the new maximum will handle anyone else. I may have to revisit this
  83. * in the future.
  84. */
  85. #define DFLT_QUEUESMAX 256
  86. #define MIN_MSGMAX 1
  87. #define DFLT_MSG 10U
  88. #define DFLT_MSGMAX 10
  89. #define HARD_MSGMAX 65536
  90. #define MIN_MSGSIZEMAX 128
  91. #define DFLT_MSGSIZE 8192U
  92. #define DFLT_MSGSIZEMAX 8192
  93. #define HARD_MSGSIZEMAX (16*1024*1024)
  94. #else
  95. static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
  96. #endif
  97. #if defined(CONFIG_IPC_NS)
  98. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  99. struct user_namespace *user_ns, struct ipc_namespace *ns);
  100. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  101. {
  102. if (ns)
  103. atomic_inc(&ns->count);
  104. return ns;
  105. }
  106. extern void put_ipc_ns(struct ipc_namespace *ns);
  107. #else
  108. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  109. struct user_namespace *user_ns, struct ipc_namespace *ns)
  110. {
  111. if (flags & CLONE_NEWIPC)
  112. return ERR_PTR(-EINVAL);
  113. return ns;
  114. }
  115. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  116. {
  117. return ns;
  118. }
  119. static inline void put_ipc_ns(struct ipc_namespace *ns)
  120. {
  121. }
  122. #endif
  123. #ifdef CONFIG_POSIX_MQUEUE_SYSCTL
  124. struct ctl_table_header;
  125. extern struct ctl_table_header *mq_register_sysctl_table(void);
  126. #else /* CONFIG_POSIX_MQUEUE_SYSCTL */
  127. static inline struct ctl_table_header *mq_register_sysctl_table(void)
  128. {
  129. return NULL;
  130. }
  131. #endif /* CONFIG_POSIX_MQUEUE_SYSCTL */
  132. #endif