aboutsummaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorManfred Spraul <manfred@colorfullife.com>2014-12-12 19:58:17 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-13 15:42:52 -0500
commit0050ee059f7fc86b1df2527aaa14ed5dc72f9973 (patch)
tree9fa11fd54259ed433d89b0a483e172b8e75d8f23 /ipc
parente843e7d2c88b7db107a86bd2c7145dc715c058f4 (diff)
ipc/msg: increase MSGMNI, remove scaling
SysV can be abused to allocate locked kernel memory. For most systems, a small limit doesn't make sense, see the discussion with regards to SHMMAX. Therefore: increase MSGMNI to the maximum supported. And: If we ignore the risk of locking too much memory, then an automatic scaling of MSGMNI doesn't make sense. Therefore the logic can be removed. The code preserves auto_msgmni to avoid breaking any user space applications that expect that the value exists. Notes: 1) If an administrator must limit the memory allocations, then he can set MSGMNI as necessary. Or he can disable sysv entirely (as e.g. done by Android). 2) MSGMAX and MSGMNB are intentionally not increased, as these values are used to control latency vs. throughput: If MSGMNB is large, then msgsnd() just returns and more messages can be queued before a task switch to a task that calls msgrcv() is forced. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Rafael Aquini <aquini@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r--ipc/Makefile2
-rw-r--r--ipc/ipc_sysctl.c93
-rw-r--r--ipc/ipcns_notifier.c92
-rw-r--r--ipc/msg.c36
-rw-r--r--ipc/namespace.c22
-rw-r--r--ipc/util.c40
6 files changed, 19 insertions, 266 deletions
diff --git a/ipc/Makefile b/ipc/Makefile
index 9075e172e52c..86c7300ecdf5 100644
--- a/ipc/Makefile
+++ b/ipc/Makefile
@@ -3,7 +3,7 @@
3# 3#
4 4
5obj-$(CONFIG_SYSVIPC_COMPAT) += compat.o 5obj-$(CONFIG_SYSVIPC_COMPAT) += compat.o
6obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o ipcns_notifier.o syscall.o 6obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o syscall.o
7obj-$(CONFIG_SYSVIPC_SYSCTL) += ipc_sysctl.o 7obj-$(CONFIG_SYSVIPC_SYSCTL) += ipc_sysctl.o
8obj_mq-$(CONFIG_COMPAT) += compat_mq.o 8obj_mq-$(CONFIG_COMPAT) += compat_mq.o
9obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y) 9obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y)
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index e8075b247497..8ad93c29f511 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -62,29 +62,6 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
62 return err; 62 return err;
63} 63}
64 64
65static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
66 void __user *buffer, size_t *lenp, loff_t *ppos)
67{
68 struct ctl_table ipc_table;
69 size_t lenp_bef = *lenp;
70 int rc;
71
72 memcpy(&ipc_table, table, sizeof(ipc_table));
73 ipc_table.data = get_ipc(table);
74
75 rc = proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
76
77 if (write && !rc && lenp_bef == *lenp)
78 /*
79 * Tunable has successfully been changed by hand. Disable its
80 * automatic adjustment. This simply requires unregistering
81 * the notifiers that trigger recalculation.
82 */
83 unregister_ipcns_notifier(current->nsproxy->ipc_ns);
84
85 return rc;
86}
87
88static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write, 65static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
89 void __user *buffer, size_t *lenp, loff_t *ppos) 66 void __user *buffer, size_t *lenp, loff_t *ppos)
90{ 67{
@@ -96,54 +73,19 @@ static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
96 lenp, ppos); 73 lenp, ppos);
97} 74}
98 75
99/* 76static int proc_ipc_auto_msgmni(struct ctl_table *table, int write,
100 * Routine that is called when the file "auto_msgmni" has successfully been
101 * written.
102 * Two values are allowed:
103 * 0: unregister msgmni's callback routine from the ipc namespace notifier
104 * chain. This means that msgmni won't be recomputed anymore upon memory
105 * add/remove or ipc namespace creation/removal.
106 * 1: register back the callback routine.
107 */
108static void ipc_auto_callback(int val)
109{
110 if (!val)
111 unregister_ipcns_notifier(current->nsproxy->ipc_ns);
112 else {
113 /*
114 * Re-enable automatic recomputing only if not already
115 * enabled.
116 */
117 recompute_msgmni(current->nsproxy->ipc_ns);
118 cond_register_ipcns_notifier(current->nsproxy->ipc_ns);
119 }
120}
121
122static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
123 void __user *buffer, size_t *lenp, loff_t *ppos) 77 void __user *buffer, size_t *lenp, loff_t *ppos)
124{ 78{
125 struct ctl_table ipc_table; 79 struct ctl_table ipc_table;
126 int oldval; 80 int dummy = 0;
127 int rc;
128 81
129 memcpy(&ipc_table, table, sizeof(ipc_table)); 82 memcpy(&ipc_table, table, sizeof(ipc_table));
130 ipc_table.data = get_ipc(table); 83 ipc_table.data = &dummy;
131 oldval = *((int *)(ipc_table.data));
132 84
133 rc = proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos); 85 if (write)
86 pr_info_once("writing to auto_msgmni has no effect");
134 87
135 if (write && !rc) { 88 return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
136 int newval = *((int *)(ipc_table.data));
137 /*
138 * The file "auto_msgmni" has correctly been set.
139 * React by (un)registering the corresponding tunable, if the
140 * value has changed.
141 */
142 if (newval != oldval)
143 ipc_auto_callback(newval);
144 }
145
146 return rc;
147} 89}
148 90
149#else 91#else
@@ -151,8 +93,7 @@ static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
151#define proc_ipc_dointvec NULL 93#define proc_ipc_dointvec NULL
152#define proc_ipc_dointvec_minmax NULL 94#define proc_ipc_dointvec_minmax NULL
153#define proc_ipc_dointvec_minmax_orphans NULL 95#define proc_ipc_dointvec_minmax_orphans NULL
154#define proc_ipc_callback_dointvec_minmax NULL 96#define proc_ipc_auto_msgmni NULL
155#define proc_ipcauto_dointvec_minmax NULL
156#endif 97#endif
157 98
158static int zero; 99static int zero;
@@ -204,11 +145,20 @@ static struct ctl_table ipc_kern_table[] = {
204 .data = &init_ipc_ns.msg_ctlmni, 145 .data = &init_ipc_ns.msg_ctlmni,
205 .maxlen = sizeof(init_ipc_ns.msg_ctlmni), 146 .maxlen = sizeof(init_ipc_ns.msg_ctlmni),
206 .mode = 0644, 147 .mode = 0644,
207 .proc_handler = proc_ipc_callback_dointvec_minmax, 148 .proc_handler = proc_ipc_dointvec_minmax,
208 .extra1 = &zero, 149 .extra1 = &zero,
209 .extra2 = &int_max, 150 .extra2 = &int_max,
210 }, 151 },
211 { 152 {
153 .procname = "auto_msgmni",
154 .data = NULL,
155 .maxlen = sizeof(int),
156 .mode = 0644,
157 .proc_handler = proc_ipc_auto_msgmni,
158 .extra1 = &zero,
159 .extra2 = &one,
160 },
161 {
212 .procname = "msgmnb", 162 .procname = "msgmnb",
213 .data = &init_ipc_ns.msg_ctlmnb, 163 .data = &init_ipc_ns.msg_ctlmnb,
214 .maxlen = sizeof(init_ipc_ns.msg_ctlmnb), 164 .maxlen = sizeof(init_ipc_ns.msg_ctlmnb),
@@ -224,15 +174,6 @@ static struct ctl_table ipc_kern_table[] = {
224 .mode = 0644, 174 .mode = 0644,
225 .proc_handler = proc_ipc_dointvec, 175 .proc_handler = proc_ipc_dointvec,
226 }, 176 },
227 {
228 .procname = "auto_msgmni",
229 .data = &init_ipc_ns.auto_msgmni,
230 .maxlen = sizeof(int),
231 .mode = 0644,
232 .proc_handler = proc_ipcauto_dointvec_minmax,
233 .extra1 = &zero,
234 .extra2 = &one,
235 },
236#ifdef CONFIG_CHECKPOINT_RESTORE 177#ifdef CONFIG_CHECKPOINT_RESTORE
237 { 178 {
238 .procname = "sem_next_id", 179 .procname = "sem_next_id",
diff --git a/ipc/ipcns_notifier.c b/ipc/ipcns_notifier.c
deleted file mode 100644
index b9b31a4f77e1..000000000000
--- a/ipc/ipcns_notifier.c
+++ /dev/null
@@ -1,92 +0,0 @@
1/*
2 * linux/ipc/ipcns_notifier.c
3 * Copyright (C) 2007 BULL SA. Nadia Derbey
4 *
5 * Notification mechanism for ipc namespaces:
6 * The callback routine registered in the memory chain invokes the ipcns
7 * notifier chain with the IPCNS_MEMCHANGED event.
8 * Each callback routine registered in the ipcns namespace recomputes msgmni
9 * for the owning namespace.
10 */
11
12#include <linux/msg.h>
13#include <linux/rcupdate.h>
14#include <linux/notifier.h>
15#include <linux/nsproxy.h>
16#include <linux/ipc_namespace.h>
17
18#include "util.h"
19
20