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