hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/ipc/ipc_sysctl.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2007
34 *
45 * Author: Eric Biederman <ebiederm@xmision.com>
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as
8
- * published by the Free Software Foundation, version 2 of the
9
- * License.
106 */
117
128 #include <linux/module.h>
....@@ -28,7 +24,7 @@
2824
2925 #ifdef CONFIG_PROC_SYSCTL
3026 static int proc_ipc_dointvec(struct ctl_table *table, int write,
31
- void __user *buffer, size_t *lenp, loff_t *ppos)
27
+ void *buffer, size_t *lenp, loff_t *ppos)
3228 {
3329 struct ctl_table ipc_table;
3430
....@@ -39,7 +35,7 @@
3935 }
4036
4137 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
42
- void __user *buffer, size_t *lenp, loff_t *ppos)
38
+ void *buffer, size_t *lenp, loff_t *ppos)
4339 {
4440 struct ctl_table ipc_table;
4541
....@@ -50,7 +46,7 @@
5046 }
5147
5248 static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
53
- void __user *buffer, size_t *lenp, loff_t *ppos)
49
+ void *buffer, size_t *lenp, loff_t *ppos)
5450 {
5551 struct ipc_namespace *ns = current->nsproxy->ipc_ns;
5652 int err = proc_ipc_dointvec_minmax(table, write, buffer, lenp, ppos);
....@@ -63,7 +59,7 @@
6359 }
6460
6561 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
66
- void __user *buffer, size_t *lenp, loff_t *ppos)
62
+ void *buffer, size_t *lenp, loff_t *ppos)
6763 {
6864 struct ctl_table ipc_table;
6965 memcpy(&ipc_table, table, sizeof(ipc_table));
....@@ -74,7 +70,7 @@
7470 }
7571
7672 static int proc_ipc_auto_msgmni(struct ctl_table *table, int write,
77
- void __user *buffer, size_t *lenp, loff_t *ppos)
73
+ void *buffer, size_t *lenp, loff_t *ppos)
7874 {
7975 struct ctl_table ipc_table;
8076 int dummy = 0;
....@@ -88,17 +84,38 @@
8884 return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
8985 }
9086
87
+static int proc_ipc_sem_dointvec(struct ctl_table *table, int write,
88
+ void *buffer, size_t *lenp, loff_t *ppos)
89
+{
90
+ int ret, semmni;
91
+ struct ipc_namespace *ns = current->nsproxy->ipc_ns;
92
+
93
+ semmni = ns->sem_ctls[3];
94
+ ret = proc_ipc_dointvec(table, write, buffer, lenp, ppos);
95
+
96
+ if (!ret)
97
+ ret = sem_check_semmni(current->nsproxy->ipc_ns);
98
+
99
+ /*
100
+ * Reset the semmni value if an error happens.
101
+ */
102
+ if (ret)
103
+ ns->sem_ctls[3] = semmni;
104
+ return ret;
105
+}
106
+
91107 #else
92108 #define proc_ipc_doulongvec_minmax NULL
93109 #define proc_ipc_dointvec NULL
94110 #define proc_ipc_dointvec_minmax NULL
95111 #define proc_ipc_dointvec_minmax_orphans NULL
96112 #define proc_ipc_auto_msgmni NULL
113
+#define proc_ipc_sem_dointvec NULL
97114 #endif
98115
99
-static int zero;
100
-static int one = 1;
101
-static int int_max = INT_MAX;
116
+int ipc_mni = IPCMNI;
117
+int ipc_mni_shift = IPCMNI_SHIFT;
118
+int ipc_min_cycle = RADIX_TREE_MAP_SIZE;
102119
103120 static struct ctl_table ipc_kern_table[] = {
104121 {
....@@ -120,7 +137,9 @@
120137 .data = &init_ipc_ns.shm_ctlmni,
121138 .maxlen = sizeof(init_ipc_ns.shm_ctlmni),
122139 .mode = 0644,
123
- .proc_handler = proc_ipc_dointvec,
140
+ .proc_handler = proc_ipc_dointvec_minmax,
141
+ .extra1 = SYSCTL_ZERO,
142
+ .extra2 = &ipc_mni,
124143 },
125144 {
126145 .procname = "shm_rmid_forced",
....@@ -128,8 +147,8 @@
128147 .maxlen = sizeof(init_ipc_ns.shm_rmid_forced),
129148 .mode = 0644,
130149 .proc_handler = proc_ipc_dointvec_minmax_orphans,
131
- .extra1 = &zero,
132
- .extra2 = &one,
150
+ .extra1 = SYSCTL_ZERO,
151
+ .extra2 = SYSCTL_ONE,
133152 },
134153 {
135154 .procname = "msgmax",
....@@ -137,8 +156,8 @@
137156 .maxlen = sizeof(init_ipc_ns.msg_ctlmax),
138157 .mode = 0644,
139158 .proc_handler = proc_ipc_dointvec_minmax,
140
- .extra1 = &zero,
141
- .extra2 = &int_max,
159
+ .extra1 = SYSCTL_ZERO,
160
+ .extra2 = SYSCTL_INT_MAX,
142161 },
143162 {
144163 .procname = "msgmni",
....@@ -146,8 +165,8 @@
146165 .maxlen = sizeof(init_ipc_ns.msg_ctlmni),
147166 .mode = 0644,
148167 .proc_handler = proc_ipc_dointvec_minmax,
149
- .extra1 = &zero,
150
- .extra2 = &int_max,
168
+ .extra1 = SYSCTL_ZERO,
169
+ .extra2 = &ipc_mni,
151170 },
152171 {
153172 .procname = "auto_msgmni",
....@@ -155,8 +174,8 @@
155174 .maxlen = sizeof(int),
156175 .mode = 0644,
157176 .proc_handler = proc_ipc_auto_msgmni,
158
- .extra1 = &zero,
159
- .extra2 = &one,
177
+ .extra1 = SYSCTL_ZERO,
178
+ .extra2 = SYSCTL_ONE,
160179 },
161180 {
162181 .procname = "msgmnb",
....@@ -164,15 +183,15 @@
164183 .maxlen = sizeof(init_ipc_ns.msg_ctlmnb),
165184 .mode = 0644,
166185 .proc_handler = proc_ipc_dointvec_minmax,
167
- .extra1 = &zero,
168
- .extra2 = &int_max,
186
+ .extra1 = SYSCTL_ZERO,
187
+ .extra2 = SYSCTL_INT_MAX,
169188 },
170189 {
171190 .procname = "sem",
172191 .data = &init_ipc_ns.sem_ctls,
173192 .maxlen = 4*sizeof(int),
174193 .mode = 0644,
175
- .proc_handler = proc_ipc_dointvec,
194
+ .proc_handler = proc_ipc_sem_dointvec,
176195 },
177196 #ifdef CONFIG_CHECKPOINT_RESTORE
178197 {
....@@ -181,8 +200,8 @@
181200 .maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id),
182201 .mode = 0644,
183202 .proc_handler = proc_ipc_dointvec_minmax,
184
- .extra1 = &zero,
185
- .extra2 = &int_max,
203
+ .extra1 = SYSCTL_ZERO,
204
+ .extra2 = SYSCTL_INT_MAX,
186205 },
187206 {
188207 .procname = "msg_next_id",
....@@ -190,8 +209,8 @@
190209 .maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id),
191210 .mode = 0644,
192211 .proc_handler = proc_ipc_dointvec_minmax,
193
- .extra1 = &zero,
194
- .extra2 = &int_max,
212
+ .extra1 = SYSCTL_ZERO,
213
+ .extra2 = SYSCTL_INT_MAX,
195214 },
196215 {
197216 .procname = "shm_next_id",
....@@ -199,8 +218,8 @@
199218 .maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id),
200219 .mode = 0644,
201220 .proc_handler = proc_ipc_dointvec_minmax,
202
- .extra1 = &zero,
203
- .extra2 = &int_max,
221
+ .extra1 = SYSCTL_ZERO,
222
+ .extra2 = SYSCTL_INT_MAX,
204223 },
205224 #endif
206225 {}
....@@ -222,3 +241,13 @@
222241 }
223242
224243 device_initcall(ipc_sysctl_init);
244
+
245
+static int __init ipc_mni_extend(char *str)
246
+{
247
+ ipc_mni = IPCMNI_EXTEND;
248
+ ipc_mni_shift = IPCMNI_EXTEND_SHIFT;
249
+ ipc_min_cycle = IPCMNI_EXTEND_MIN_CYCLE;
250
+ pr_info("IPCMNI extended to %d.\n", ipc_mni);
251
+ return 0;
252
+}
253
+early_param("ipcmni_extend", ipc_mni_extend);