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