0001
0002 #ifndef __IPC_NAMESPACE_H__
0003 #define __IPC_NAMESPACE_H__
0004
0005 #include <linux/err.h>
0006 #include <linux/idr.h>
0007 #include <linux/rwsem.h>
0008 #include <linux/notifier.h>
0009 #include <linux/nsproxy.h>
0010 #include <linux/ns_common.h>
0011 #include <linux/refcount.h>
0012 #include <linux/rhashtable-types.h>
0013 #include <linux/sysctl.h>
0014
0015 struct user_namespace;
0016
0017 struct ipc_ids {
0018 int in_use;
0019 unsigned short seq;
0020 struct rw_semaphore rwsem;
0021 struct idr ipcs_idr;
0022 int max_idx;
0023 int last_idx;
0024 #ifdef CONFIG_CHECKPOINT_RESTORE
0025 int next_id;
0026 #endif
0027 struct rhashtable key_ht;
0028 };
0029
0030 struct ipc_namespace {
0031 struct ipc_ids ids[3];
0032
0033 int sem_ctls[4];
0034 int used_sems;
0035
0036 unsigned int msg_ctlmax;
0037 unsigned int msg_ctlmnb;
0038 unsigned int msg_ctlmni;
0039 atomic_t msg_bytes;
0040 atomic_t msg_hdrs;
0041
0042 size_t shm_ctlmax;
0043 size_t shm_ctlall;
0044 unsigned long shm_tot;
0045 int shm_ctlmni;
0046
0047
0048
0049
0050 int shm_rmid_forced;
0051
0052 struct notifier_block ipcns_nb;
0053
0054
0055 struct vfsmount *mq_mnt;
0056
0057
0058 unsigned int mq_queues_count;
0059
0060
0061 unsigned int mq_queues_max;
0062 unsigned int mq_msg_max;
0063 unsigned int mq_msgsize_max;
0064 unsigned int mq_msg_default;
0065 unsigned int mq_msgsize_default;
0066
0067 struct ctl_table_set mq_set;
0068 struct ctl_table_header *mq_sysctls;
0069
0070 struct ctl_table_set ipc_set;
0071 struct ctl_table_header *ipc_sysctls;
0072
0073
0074 struct user_namespace *user_ns;
0075 struct ucounts *ucounts;
0076
0077 struct llist_node mnt_llist;
0078
0079 struct ns_common ns;
0080 } __randomize_layout;
0081
0082 extern struct ipc_namespace init_ipc_ns;
0083 extern spinlock_t mq_lock;
0084
0085 #ifdef CONFIG_SYSVIPC
0086 extern void shm_destroy_orphaned(struct ipc_namespace *ns);
0087 #else
0088 static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
0089 #endif
0090
0091 #ifdef CONFIG_POSIX_MQUEUE
0092 extern int mq_init_ns(struct ipc_namespace *ns);
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 #define DFLT_QUEUESMAX 256
0118 #define MIN_MSGMAX 1
0119 #define DFLT_MSG 10U
0120 #define DFLT_MSGMAX 10
0121 #define HARD_MSGMAX 65536
0122 #define MIN_MSGSIZEMAX 128
0123 #define DFLT_MSGSIZE 8192U
0124 #define DFLT_MSGSIZEMAX 8192
0125 #define HARD_MSGSIZEMAX (16*1024*1024)
0126 #else
0127 static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
0128 #endif
0129
0130 #if defined(CONFIG_IPC_NS)
0131 extern struct ipc_namespace *copy_ipcs(unsigned long flags,
0132 struct user_namespace *user_ns, struct ipc_namespace *ns);
0133
0134 static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
0135 {
0136 if (ns)
0137 refcount_inc(&ns->ns.count);
0138 return ns;
0139 }
0140
0141 static inline struct ipc_namespace *get_ipc_ns_not_zero(struct ipc_namespace *ns)
0142 {
0143 if (ns) {
0144 if (refcount_inc_not_zero(&ns->ns.count))
0145 return ns;
0146 }
0147
0148 return NULL;
0149 }
0150
0151 extern void put_ipc_ns(struct ipc_namespace *ns);
0152 #else
0153 static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
0154 struct user_namespace *user_ns, struct ipc_namespace *ns)
0155 {
0156 if (flags & CLONE_NEWIPC)
0157 return ERR_PTR(-EINVAL);
0158
0159 return ns;
0160 }
0161
0162 static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
0163 {
0164 return ns;
0165 }
0166
0167 static inline struct ipc_namespace *get_ipc_ns_not_zero(struct ipc_namespace *ns)
0168 {
0169 return ns;
0170 }
0171
0172 static inline void put_ipc_ns(struct ipc_namespace *ns)
0173 {
0174 }
0175 #endif
0176
0177 #ifdef CONFIG_POSIX_MQUEUE_SYSCTL
0178
0179 void retire_mq_sysctls(struct ipc_namespace *ns);
0180 bool setup_mq_sysctls(struct ipc_namespace *ns);
0181
0182 #else
0183
0184 static inline void retire_mq_sysctls(struct ipc_namespace *ns)
0185 {
0186 }
0187
0188 static inline bool setup_mq_sysctls(struct ipc_namespace *ns)
0189 {
0190 return true;
0191 }
0192
0193 #endif
0194
0195 #ifdef CONFIG_SYSVIPC_SYSCTL
0196
0197 bool setup_ipc_sysctls(struct ipc_namespace *ns);
0198 void retire_ipc_sysctls(struct ipc_namespace *ns);
0199
0200 #else
0201
0202 static inline void retire_ipc_sysctls(struct ipc_namespace *ns)
0203 {
0204 }
0205
0206 static inline bool setup_ipc_sysctls(struct ipc_namespace *ns)
0207 {
0208 return true;
0209 }
0210
0211 #endif
0212 #endif