1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __IPC_NAMESPACE_H__
3 #define __IPC_NAMESPACE_H__
7 #include <linux/rwsem.h>
8 #include <linux/notifier.h>
9 #include <linux/nsproxy.h>
10 #include <linux/ns_common.h>
11 #include <linux/refcount.h>
12 #include <linux/rhashtable-types.h>
13 #include <linux/sysctl.h>
14 #include <linux/percpu_counter.h>
16 struct user_namespace
;
21 struct rw_semaphore rwsem
;
24 int last_idx
; /* For wrap around detection */
25 #ifdef CONFIG_CHECKPOINT_RESTORE
28 struct rhashtable key_ht
;
31 struct ipc_namespace
{
32 struct ipc_ids ids
[3];
37 unsigned int msg_ctlmax
;
38 unsigned int msg_ctlmnb
;
39 unsigned int msg_ctlmni
;
40 struct percpu_counter percpu_msg_bytes
;
41 struct percpu_counter percpu_msg_hdrs
;
45 unsigned long shm_tot
;
48 * Defines whether IPC_RMID is forced for _all_ shm segments regardless
53 struct notifier_block ipcns_nb
;
55 /* The kern_mount of the mqueuefs sb. We take a ref on it */
56 struct vfsmount
*mq_mnt
;
58 /* # queues in this ns, protected by mq_lock */
59 unsigned int mq_queues_count
;
61 /* next fields are set through sysctl */
62 unsigned int mq_queues_max
; /* initialized to DFLT_QUEUESMAX */
63 unsigned int mq_msg_max
; /* initialized to DFLT_MSGMAX */
64 unsigned int mq_msgsize_max
; /* initialized to DFLT_MSGSIZEMAX */
65 unsigned int mq_msg_default
;
66 unsigned int mq_msgsize_default
;
68 struct ctl_table_set mq_set
;
69 struct ctl_table_header
*mq_sysctls
;
71 struct ctl_table_set ipc_set
;
72 struct ctl_table_header
*ipc_sysctls
;
74 /* user_ns which owns the ipc ns */
75 struct user_namespace
*user_ns
;
76 struct ucounts
*ucounts
;
78 struct llist_node mnt_llist
;
83 extern struct ipc_namespace init_ipc_ns
;
84 extern spinlock_t mq_lock
;
87 extern void shm_destroy_orphaned(struct ipc_namespace
*ns
);
88 #else /* CONFIG_SYSVIPC */
89 static inline void shm_destroy_orphaned(struct ipc_namespace
*ns
) {}
90 #endif /* CONFIG_SYSVIPC */
92 #ifdef CONFIG_POSIX_MQUEUE
93 extern int mq_init_ns(struct ipc_namespace
*ns
);
95 * POSIX Message Queue default values:
97 * MIN_*: Lowest value an admin can set the maximum unprivileged limit to
98 * DFLT_*MAX: Default values for the maximum unprivileged limits
99 * DFLT_{MSG,MSGSIZE}: Default values used when the user doesn't supply
100 * an attribute to the open call and the queue must be created
101 * HARD_*: Highest value the maximums can be set to. These are enforced
102 * on CAP_SYS_RESOURCE apps as well making them inviolate (so make them
105 * POSIX Requirements:
106 * Per app minimum openable message queues - 8. This does not map well
107 * to the fact that we limit the number of queues on a per namespace
108 * basis instead of a per app basis. So, make the default high enough
109 * that no given app should have a hard time opening 8 queues.
110 * Minimum maximum for HARD_MSGMAX - 32767. I bumped this to 65536.
111 * Minimum maximum for HARD_MSGSIZEMAX - POSIX is silent on this. However,
112 * we have run into a situation where running applications in the wild
113 * require this to be at least 5MB, and preferably 10MB, so I set the
114 * value to 16MB in hopes that this user is the worst of the bunch and
115 * the new maximum will handle anyone else. I may have to revisit this
118 #define DFLT_QUEUESMAX 256
121 #define DFLT_MSGMAX 10
122 #define HARD_MSGMAX 65536
123 #define MIN_MSGSIZEMAX 128
124 #define DFLT_MSGSIZE 8192U
125 #define DFLT_MSGSIZEMAX 8192
126 #define HARD_MSGSIZEMAX (16*1024*1024)
128 static inline int mq_init_ns(struct ipc_namespace
*ns
) { return 0; }
131 #if defined(CONFIG_IPC_NS)
132 extern struct ipc_namespace
*copy_ipcs(unsigned long flags
,
133 struct user_namespace
*user_ns
, struct ipc_namespace
*ns
);
135 static inline struct ipc_namespace
*get_ipc_ns(struct ipc_namespace
*ns
)
138 refcount_inc(&ns
->ns
.count
);
142 static inline struct ipc_namespace
*get_ipc_ns_not_zero(struct ipc_namespace
*ns
)
145 if (refcount_inc_not_zero(&ns
->ns
.count
))
152 extern void put_ipc_ns(struct ipc_namespace
*ns
);
154 static inline struct ipc_namespace
*copy_ipcs(unsigned long flags
,
155 struct user_namespace
*user_ns
, struct ipc_namespace
*ns
)
157 if (flags
& CLONE_NEWIPC
)
158 return ERR_PTR(-EINVAL
);
163 static inline struct ipc_namespace
*get_ipc_ns(struct ipc_namespace
*ns
)
168 static inline struct ipc_namespace
*get_ipc_ns_not_zero(struct ipc_namespace
*ns
)
173 static inline void put_ipc_ns(struct ipc_namespace
*ns
)
178 #ifdef CONFIG_POSIX_MQUEUE_SYSCTL
180 void retire_mq_sysctls(struct ipc_namespace
*ns
);
181 bool setup_mq_sysctls(struct ipc_namespace
*ns
);
183 #else /* CONFIG_POSIX_MQUEUE_SYSCTL */
185 static inline void retire_mq_sysctls(struct ipc_namespace
*ns
)
189 static inline bool setup_mq_sysctls(struct ipc_namespace
*ns
)
194 #endif /* CONFIG_POSIX_MQUEUE_SYSCTL */
196 #ifdef CONFIG_SYSVIPC_SYSCTL
198 bool setup_ipc_sysctls(struct ipc_namespace
*ns
);
199 void retire_ipc_sysctls(struct ipc_namespace
*ns
);
201 #else /* CONFIG_SYSVIPC_SYSCTL */
203 static inline void retire_ipc_sysctls(struct ipc_namespace
*ns
)
207 static inline bool setup_ipc_sysctls(struct ipc_namespace
*ns
)
212 #endif /* CONFIG_SYSVIPC_SYSCTL */