ipc_namespace.h 5.2 KB

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