]>
Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* |
3 | * sysctl.c: General linux system control interface | |
4 | * | |
5 | * Begun 24 March 1995, Stephen Tweedie | |
6 | * Added /proc support, Dec 1995 | |
7 | * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. | |
8 | * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. | |
9 | * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. | |
10 | * Dynamic registration fixes, Stephen Tweedie. | |
11 | * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. | |
12 | * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris | |
13 | * Horn. | |
14 | * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. | |
15 | * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. | |
16 | * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill | |
17 | * Wendling. | |
18 | * The list_for_each() macro wasn't appropriate for the sysctl loop. | |
19 | * Removed it and replaced it with older style, 03/23/00, Bill Wendling | |
20 | */ | |
21 | ||
1da177e4 LT |
22 | #include <linux/module.h> |
23 | #include <linux/mm.h> | |
24 | #include <linux/swap.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/sysctl.h> | |
5a04cca6 | 27 | #include <linux/bitmap.h> |
d33ed52d | 28 | #include <linux/signal.h> |
f39650de | 29 | #include <linux/panic.h> |
455cd5ab | 30 | #include <linux/printk.h> |
1da177e4 | 31 | #include <linux/proc_fs.h> |
72c2d582 | 32 | #include <linux/security.h> |
1da177e4 | 33 | #include <linux/ctype.h> |
fd4b616b | 34 | #include <linux/kmemleak.h> |
b6459415 | 35 | #include <linux/filter.h> |
62239ac2 | 36 | #include <linux/fs.h> |
1da177e4 LT |
37 | #include <linux/init.h> |
38 | #include <linux/kernel.h> | |
0296b228 | 39 | #include <linux/kobject.h> |
20380731 | 40 | #include <linux/net.h> |
1da177e4 LT |
41 | #include <linux/sysrq.h> |
42 | #include <linux/highuid.h> | |
43 | #include <linux/writeback.h> | |
3fff4c42 | 44 | #include <linux/ratelimit.h> |
76ab0f53 | 45 | #include <linux/compaction.h> |
1da177e4 | 46 | #include <linux/hugetlb.h> |
1da177e4 | 47 | #include <linux/initrd.h> |
0b77f5bf | 48 | #include <linux/key.h> |
1da177e4 LT |
49 | #include <linux/times.h> |
50 | #include <linux/limits.h> | |
51 | #include <linux/dcache.h> | |
52 | #include <linux/syscalls.h> | |
c748e134 | 53 | #include <linux/vmstat.h> |
c255d844 PM |
54 | #include <linux/nfs_fs.h> |
55 | #include <linux/acpi.h> | |
10a0a8d4 | 56 | #include <linux/reboot.h> |
b0fc494f | 57 | #include <linux/ftrace.h> |
cdd6c482 | 58 | #include <linux/perf_event.h> |
8e4228e1 | 59 | #include <linux/oom.h> |
17f60a7d | 60 | #include <linux/kmod.h> |
73efc039 | 61 | #include <linux/capability.h> |
40401530 | 62 | #include <linux/binfmts.h> |
cf4aebc2 | 63 | #include <linux/sched/sysctl.h> |
d2921684 | 64 | #include <linux/mount.h> |
cefdca0a | 65 | #include <linux/userfaultfd_k.h> |
2374c09b | 66 | #include <linux/pid.h> |
1da177e4 | 67 | |
7f2923c4 CB |
68 | #include "../lib/kstrtox.h" |
69 | ||
7c0f6ba6 | 70 | #include <linux/uaccess.h> |
1da177e4 LT |
71 | #include <asm/processor.h> |
72 | ||
29cbc78b AK |
73 | #ifdef CONFIG_X86 |
74 | #include <asm/nmi.h> | |
0741f4d2 | 75 | #include <asm/stacktrace.h> |
6e7c4025 | 76 | #include <asm/io.h> |
29cbc78b | 77 | #endif |
d550bbd4 DH |
78 | #ifdef CONFIG_SPARC |
79 | #include <asm/setup.h> | |
80 | #endif | |
4f0e056f DY |
81 | #ifdef CONFIG_RT_MUTEXES |
82 | #include <linux/rtmutex.h> | |
83 | #endif | |
504d7cf1 | 84 | |
1da177e4 LT |
85 | #if defined(CONFIG_SYSCTL) |
86 | ||
c4f3b63f | 87 | /* Constants used for minimum and maximum */ |
c4f3b63f | 88 | |
c5dfd78e | 89 | #ifdef CONFIG_PERF_EVENTS |
d73840ec | 90 | static const int six_hundred_forty_kb = 640 * 1024; |
c5dfd78e | 91 | #endif |
c4f3b63f | 92 | |
9e4a5bda | 93 | |
f628867d | 94 | static const int ngroups_max = NGROUPS_MAX; |
73efc039 | 95 | static const int cap_last_cap = CAP_LAST_CAP; |
1da177e4 | 96 | |
d6f8ff73 | 97 | #ifdef CONFIG_PROC_SYSCTL |
f4aacea2 | 98 | |
a19ac337 LR |
99 | /** |
100 | * enum sysctl_writes_mode - supported sysctl write modes | |
101 | * | |
102 | * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value | |
65f50f25 WH |
103 | * to be written, and multiple writes on the same sysctl file descriptor |
104 | * will rewrite the sysctl value, regardless of file position. No warning | |
105 | * is issued when the initial position is not 0. | |
a19ac337 | 106 | * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is |
65f50f25 | 107 | * not 0. |
a19ac337 | 108 | * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at |
65f50f25 WH |
109 | * file position 0 and the value must be fully contained in the buffer |
110 | * sent to the write syscall. If dealing with strings respect the file | |
111 | * position, but restrict this to the max length of the buffer, anything | |
112 | * passed the max length will be ignored. Multiple writes will append | |
113 | * to the buffer. | |
a19ac337 LR |
114 | * |
115 | * These write modes control how current file position affects the behavior of | |
116 | * updating sysctl values through the proc interface on each write. | |
117 | */ | |
118 | enum sysctl_writes_mode { | |
119 | SYSCTL_WRITES_LEGACY = -1, | |
120 | SYSCTL_WRITES_WARN = 0, | |
121 | SYSCTL_WRITES_STRICT = 1, | |
122 | }; | |
f4aacea2 | 123 | |
a19ac337 | 124 | static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; |
f461d2dc | 125 | #endif /* CONFIG_PROC_SYSCTL */ |
ceb18132 | 126 | |
67f3977f AG |
127 | #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ |
128 | defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) | |
1da177e4 LT |
129 | int sysctl_legacy_va_layout; |
130 | #endif | |
131 | ||
f461d2dc CH |
132 | #endif /* CONFIG_SYSCTL */ |
133 | ||
134 | /* | |
135 | * /proc/sys support | |
136 | */ | |
137 | ||
b89a8171 | 138 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 | 139 | |
f8808300 | 140 | static int _proc_do_string(char *data, int maxlen, int write, |
32927393 | 141 | char *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
142 | { |
143 | size_t len; | |
32927393 | 144 | char c, *p; |
8d060877 ON |
145 | |
146 | if (!data || !maxlen || !*lenp) { | |
1da177e4 LT |
147 | *lenp = 0; |
148 | return 0; | |
149 | } | |
8d060877 | 150 | |
1da177e4 | 151 | if (write) { |
f4aacea2 KC |
152 | if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) { |
153 | /* Only continue writes not past the end of buffer. */ | |
154 | len = strlen(data); | |
155 | if (len > maxlen - 1) | |
156 | len = maxlen - 1; | |
157 | ||
158 | if (*ppos > len) | |
159 | return 0; | |
160 | len = *ppos; | |
161 | } else { | |
162 | /* Start writing from beginning of buffer. */ | |
163 | len = 0; | |
164 | } | |
165 | ||
2ca9bb45 | 166 | *ppos += *lenp; |
1da177e4 | 167 | p = buffer; |
2ca9bb45 | 168 | while ((p - buffer) < *lenp && len < maxlen - 1) { |
32927393 | 169 | c = *(p++); |
1da177e4 LT |
170 | if (c == 0 || c == '\n') |
171 | break; | |
2ca9bb45 | 172 | data[len++] = c; |
1da177e4 | 173 | } |
f8808300 | 174 | data[len] = 0; |
1da177e4 | 175 | } else { |
f5dd3d6f SV |
176 | len = strlen(data); |
177 | if (len > maxlen) | |
178 | len = maxlen; | |
8d060877 ON |
179 | |
180 | if (*ppos > len) { | |
181 | *lenp = 0; | |
182 | return 0; | |
183 | } | |
184 | ||
185 | data += *ppos; | |
186 | len -= *ppos; | |
187 | ||
1da177e4 LT |
188 | if (len > *lenp) |
189 | len = *lenp; | |
190 | if (len) | |
32927393 | 191 | memcpy(buffer, data, len); |
1da177e4 | 192 | if (len < *lenp) { |
32927393 | 193 | buffer[len] = '\n'; |
1da177e4 LT |
194 | len++; |
195 | } | |
196 | *lenp = len; | |
197 | *ppos += len; | |
198 | } | |
199 | return 0; | |
200 | } | |
201 | ||
f4aacea2 KC |
202 | static void warn_sysctl_write(struct ctl_table *table) |
203 | { | |
204 | pr_warn_once("%s wrote to %s when file position was not 0!\n" | |
205 | "This will not be supported in the future. To silence this\n" | |
206 | "warning, set kernel.sysctl_writes_strict = -1\n", | |
207 | current->comm, table->procname); | |
208 | } | |
209 | ||
d383d484 | 210 | /** |
5f733e8a | 211 | * proc_first_pos_non_zero_ignore - check if first position is allowed |
d383d484 LR |
212 | * @ppos: file position |
213 | * @table: the sysctl table | |
214 | * | |
215 | * Returns true if the first position is non-zero and the sysctl_writes_strict | |
216 | * mode indicates this is not allowed for numeric input types. String proc | |
5f733e8a | 217 | * handlers can ignore the return value. |
d383d484 LR |
218 | */ |
219 | static bool proc_first_pos_non_zero_ignore(loff_t *ppos, | |
220 | struct ctl_table *table) | |
221 | { | |
222 | if (!*ppos) | |
223 | return false; | |
224 | ||
225 | switch (sysctl_writes_strict) { | |
226 | case SYSCTL_WRITES_STRICT: | |
227 | return true; | |
228 | case SYSCTL_WRITES_WARN: | |
229 | warn_sysctl_write(table); | |
230 | return false; | |
231 | default: | |
232 | return false; | |
233 | } | |
234 | } | |
235 | ||
f5dd3d6f SV |
236 | /** |
237 | * proc_dostring - read a string sysctl | |
238 | * @table: the sysctl table | |
239 | * @write: %TRUE if this is a write to the sysctl file | |
f5dd3d6f SV |
240 | * @buffer: the user buffer |
241 | * @lenp: the size of the user buffer | |
242 | * @ppos: file position | |
243 | * | |
244 | * Reads/writes a string from/to the user buffer. If the kernel | |
245 | * buffer provided is not large enough to hold the string, the | |
246 | * string is truncated. The copied string is %NULL-terminated. | |
247 | * If the string is being read by the user process, it is copied | |
248 | * and a newline '\n' is added. It is truncated if the buffer is | |
249 | * not large enough. | |
250 | * | |
251 | * Returns 0 on success. | |
252 | */ | |
8d65af78 | 253 | int proc_dostring(struct ctl_table *table, int write, |
32927393 | 254 | void *buffer, size_t *lenp, loff_t *ppos) |
f5dd3d6f | 255 | { |
d383d484 LR |
256 | if (write) |
257 | proc_first_pos_non_zero_ignore(ppos, table); | |
f4aacea2 | 258 | |
32927393 CH |
259 | return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, |
260 | ppos); | |
f5dd3d6f SV |
261 | } |
262 | ||
00b7c339 AW |
263 | static size_t proc_skip_spaces(char **buf) |
264 | { | |
265 | size_t ret; | |
266 | char *tmp = skip_spaces(*buf); | |
267 | ret = tmp - *buf; | |
268 | *buf = tmp; | |
269 | return ret; | |
270 | } | |
271 | ||
9f977fb7 OP |
272 | static void proc_skip_char(char **buf, size_t *size, const char v) |
273 | { | |
274 | while (*size) { | |
275 | if (**buf != v) | |
276 | break; | |
277 | (*size)--; | |
278 | (*buf)++; | |
279 | } | |
280 | } | |
281 | ||
7f2923c4 CB |
282 | /** |
283 | * strtoul_lenient - parse an ASCII formatted integer from a buffer and only | |
284 | * fail on overflow | |
285 | * | |
286 | * @cp: kernel buffer containing the string to parse | |
287 | * @endp: pointer to store the trailing characters | |
288 | * @base: the base to use | |
289 | * @res: where the parsed integer will be stored | |
290 | * | |
291 | * In case of success 0 is returned and @res will contain the parsed integer, | |
292 | * @endp will hold any trailing characters. | |
293 | * This function will fail the parse on overflow. If there wasn't an overflow | |
294 | * the function will defer the decision what characters count as invalid to the | |
295 | * caller. | |
296 | */ | |
297 | static int strtoul_lenient(const char *cp, char **endp, unsigned int base, | |
298 | unsigned long *res) | |
299 | { | |
300 | unsigned long long result; | |
301 | unsigned int rv; | |
302 | ||
303 | cp = _parse_integer_fixup_radix(cp, &base); | |
304 | rv = _parse_integer(cp, base, &result); | |
305 | if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result)) | |
306 | return -ERANGE; | |
307 | ||
308 | cp += rv; | |
309 | ||
310 | if (endp) | |
311 | *endp = (char *)cp; | |
312 | ||
313 | *res = (unsigned long)result; | |
314 | return 0; | |
315 | } | |
316 | ||
00b7c339 AW |
317 | #define TMPBUFLEN 22 |
318 | /** | |
0fc377bd | 319 | * proc_get_long - reads an ASCII formatted integer from a user buffer |
00b7c339 | 320 | * |
0fc377bd RD |
321 | * @buf: a kernel buffer |
322 | * @size: size of the kernel buffer | |
323 | * @val: this is where the number will be stored | |
324 | * @neg: set to %TRUE if number is negative | |
325 | * @perm_tr: a vector which contains the allowed trailers | |
326 | * @perm_tr_len: size of the perm_tr vector | |
327 | * @tr: pointer to store the trailer character | |
00b7c339 | 328 | * |
0fc377bd RD |
329 | * In case of success %0 is returned and @buf and @size are updated with |
330 | * the amount of bytes read. If @tr is non-NULL and a trailing | |
331 | * character exists (size is non-zero after returning from this | |
332 | * function), @tr is updated with the trailing character. | |
00b7c339 AW |
333 | */ |
334 | static int proc_get_long(char **buf, size_t *size, | |
335 | unsigned long *val, bool *neg, | |
336 | const char *perm_tr, unsigned perm_tr_len, char *tr) | |
337 | { | |
338 | int len; | |
339 | char *p, tmp[TMPBUFLEN]; | |
340 | ||
341 | if (!*size) | |
342 | return -EINVAL; | |
343 | ||
344 | len = *size; | |
345 | if (len > TMPBUFLEN - 1) | |
346 | len = TMPBUFLEN - 1; | |
347 | ||
348 | memcpy(tmp, *buf, len); | |
349 | ||
350 | tmp[len] = 0; | |
351 | p = tmp; | |
352 | if (*p == '-' && *size > 1) { | |
353 | *neg = true; | |
354 | p++; | |
355 | } else | |
356 | *neg = false; | |
357 | if (!isdigit(*p)) | |
358 | return -EINVAL; | |
359 | ||
7f2923c4 CB |
360 | if (strtoul_lenient(p, &p, 0, val)) |
361 | return -EINVAL; | |
00b7c339 AW |
362 | |
363 | len = p - tmp; | |
364 | ||
365 | /* We don't know if the next char is whitespace thus we may accept | |
366 | * invalid integers (e.g. 1234...a) or two integers instead of one | |
367 | * (e.g. 123...1). So lets not allow such large numbers. */ | |
368 | if (len == TMPBUFLEN - 1) | |
369 | return -EINVAL; | |
370 | ||
371 | if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) | |
372 | return -EINVAL; | |
1da177e4 | 373 | |
00b7c339 AW |
374 | if (tr && (len < *size)) |
375 | *tr = *p; | |
376 | ||
377 | *buf += len; | |
378 | *size -= len; | |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | /** | |
0fc377bd | 384 | * proc_put_long - converts an integer to a decimal ASCII formatted string |
00b7c339 | 385 | * |
0fc377bd RD |
386 | * @buf: the user buffer |
387 | * @size: the size of the user buffer | |
388 | * @val: the integer to be converted | |
389 | * @neg: sign of the number, %TRUE for negative | |
00b7c339 | 390 | * |
32927393 CH |
391 | * In case of success @buf and @size are updated with the amount of bytes |
392 | * written. | |
00b7c339 | 393 | */ |
32927393 | 394 | static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) |
00b7c339 AW |
395 | { |
396 | int len; | |
397 | char tmp[TMPBUFLEN], *p = tmp; | |
398 | ||
399 | sprintf(p, "%s%lu", neg ? "-" : "", val); | |
400 | len = strlen(tmp); | |
401 | if (len > *size) | |
402 | len = *size; | |
32927393 | 403 | memcpy(*buf, tmp, len); |
00b7c339 AW |
404 | *size -= len; |
405 | *buf += len; | |
00b7c339 AW |
406 | } |
407 | #undef TMPBUFLEN | |
408 | ||
32927393 | 409 | static void proc_put_char(void **buf, size_t *size, char c) |
00b7c339 AW |
410 | { |
411 | if (*size) { | |
32927393 CH |
412 | char **buffer = (char **)buf; |
413 | **buffer = c; | |
414 | ||
415 | (*size)--; | |
416 | (*buffer)++; | |
00b7c339 AW |
417 | *buf = *buffer; |
418 | } | |
00b7c339 | 419 | } |
1da177e4 | 420 | |
a2071573 JH |
421 | static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp, |
422 | int *valp, | |
423 | int write, void *data) | |
424 | { | |
425 | if (write) { | |
426 | *(bool *)valp = *lvalp; | |
427 | } else { | |
428 | int val = *(bool *)valp; | |
429 | ||
430 | *lvalp = (unsigned long)val; | |
431 | *negp = false; | |
432 | } | |
433 | return 0; | |
434 | } | |
435 | ||
00b7c339 | 436 | static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
437 | int *valp, |
438 | int write, void *data) | |
439 | { | |
440 | if (write) { | |
230633d1 HS |
441 | if (*negp) { |
442 | if (*lvalp > (unsigned long) INT_MAX + 1) | |
443 | return -EINVAL; | |
1f1be04b | 444 | WRITE_ONCE(*valp, -*lvalp); |
230633d1 HS |
445 | } else { |
446 | if (*lvalp > (unsigned long) INT_MAX) | |
447 | return -EINVAL; | |
1f1be04b | 448 | WRITE_ONCE(*valp, *lvalp); |
230633d1 | 449 | } |
1da177e4 | 450 | } else { |
1f1be04b | 451 | int val = READ_ONCE(*valp); |
1da177e4 | 452 | if (val < 0) { |
00b7c339 | 453 | *negp = true; |
9a5bc726 | 454 | *lvalp = -(unsigned long)val; |
1da177e4 | 455 | } else { |
00b7c339 | 456 | *negp = false; |
1da177e4 LT |
457 | *lvalp = (unsigned long)val; |
458 | } | |
459 | } | |
460 | return 0; | |
461 | } | |
462 | ||
4f2fec00 LR |
463 | static int do_proc_douintvec_conv(unsigned long *lvalp, |
464 | unsigned int *valp, | |
465 | int write, void *data) | |
e7d316a0 SAK |
466 | { |
467 | if (write) { | |
425fffd8 LZ |
468 | if (*lvalp > UINT_MAX) |
469 | return -EINVAL; | |
4762b532 | 470 | WRITE_ONCE(*valp, *lvalp); |
e7d316a0 | 471 | } else { |
4762b532 | 472 | unsigned int val = READ_ONCE(*valp); |
e7d316a0 SAK |
473 | *lvalp = (unsigned long)val; |
474 | } | |
475 | return 0; | |
476 | } | |
477 | ||
00b7c339 AW |
478 | static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; |
479 | ||
d8217f07 | 480 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, |
32927393 | 481 | int write, void *buffer, |
fcfbd547 | 482 | size_t *lenp, loff_t *ppos, |
00b7c339 | 483 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
1da177e4 LT |
484 | int write, void *data), |
485 | void *data) | |
486 | { | |
00b7c339 | 487 | int *i, vleft, first = 1, err = 0; |
00b7c339 | 488 | size_t left; |
32927393 | 489 | char *p; |
374a723c | 490 | |
00b7c339 | 491 | if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { |
1da177e4 LT |
492 | *lenp = 0; |
493 | return 0; | |
494 | } | |
374a723c | 495 | |
fcfbd547 | 496 | i = (int *) tbl_data; |
1da177e4 LT |
497 | vleft = table->maxlen / sizeof(*i); |
498 | left = *lenp; | |
499 | ||
500 | if (!conv) | |
501 | conv = do_proc_dointvec_conv; | |
502 | ||
00b7c339 | 503 | if (write) { |
d383d484 LR |
504 | if (proc_first_pos_non_zero_ignore(ppos, table)) |
505 | goto out; | |
f4aacea2 | 506 | |
00b7c339 AW |
507 | if (left > PAGE_SIZE - 1) |
508 | left = PAGE_SIZE - 1; | |
32927393 | 509 | p = buffer; |
00b7c339 AW |
510 | } |
511 | ||
1da177e4 | 512 | for (; left && vleft--; i++, first=0) { |
00b7c339 AW |
513 | unsigned long lval; |
514 | bool neg; | |
1da177e4 | 515 | |
00b7c339 | 516 | if (write) { |
70f6cbb6 | 517 | left -= proc_skip_spaces(&p); |
1da177e4 | 518 | |
563b0467 O |
519 | if (!left) |
520 | break; | |
70f6cbb6 | 521 | err = proc_get_long(&p, &left, &lval, &neg, |
00b7c339 AW |
522 | proc_wspace_sep, |
523 | sizeof(proc_wspace_sep), NULL); | |
524 | if (err) | |
1da177e4 | 525 | break; |
00b7c339 AW |
526 | if (conv(&neg, &lval, i, 1, data)) { |
527 | err = -EINVAL; | |
1da177e4 | 528 | break; |
00b7c339 | 529 | } |
1da177e4 | 530 | } else { |
00b7c339 AW |
531 | if (conv(&neg, &lval, i, 0, data)) { |
532 | err = -EINVAL; | |
533 | break; | |
534 | } | |
1da177e4 | 535 | if (!first) |
32927393 CH |
536 | proc_put_char(&buffer, &left, '\t'); |
537 | proc_put_long(&buffer, &left, lval, neg); | |
1da177e4 LT |
538 | } |
539 | } | |
540 | ||
00b7c339 | 541 | if (!write && !first && left && !err) |
32927393 | 542 | proc_put_char(&buffer, &left, '\n'); |
563b0467 | 543 | if (write && !err && left) |
70f6cbb6 | 544 | left -= proc_skip_spaces(&p); |
32927393 CH |
545 | if (write && first) |
546 | return err ? : -EINVAL; | |
1da177e4 | 547 | *lenp -= left; |
f4aacea2 | 548 | out: |
1da177e4 | 549 | *ppos += *lenp; |
00b7c339 | 550 | return err; |
1da177e4 LT |
551 | } |
552 | ||
8d65af78 | 553 | static int do_proc_dointvec(struct ctl_table *table, int write, |
32927393 | 554 | void *buffer, size_t *lenp, loff_t *ppos, |
00b7c339 | 555 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
fcfbd547 KK |
556 | int write, void *data), |
557 | void *data) | |
558 | { | |
8d65af78 | 559 | return __do_proc_dointvec(table->data, table, write, |
fcfbd547 KK |
560 | buffer, lenp, ppos, conv, data); |
561 | } | |
562 | ||
4f2fec00 LR |
563 | static int do_proc_douintvec_w(unsigned int *tbl_data, |
564 | struct ctl_table *table, | |
32927393 | 565 | void *buffer, |
4f2fec00 LR |
566 | size_t *lenp, loff_t *ppos, |
567 | int (*conv)(unsigned long *lvalp, | |
568 | unsigned int *valp, | |
569 | int write, void *data), | |
570 | void *data) | |
571 | { | |
572 | unsigned long lval; | |
573 | int err = 0; | |
574 | size_t left; | |
575 | bool neg; | |
32927393 | 576 | char *p = buffer; |
4f2fec00 LR |
577 | |
578 | left = *lenp; | |
579 | ||
580 | if (proc_first_pos_non_zero_ignore(ppos, table)) | |
581 | goto bail_early; | |
582 | ||
583 | if (left > PAGE_SIZE - 1) | |
584 | left = PAGE_SIZE - 1; | |
585 | ||
4f2fec00 LR |
586 | left -= proc_skip_spaces(&p); |
587 | if (!left) { | |
588 | err = -EINVAL; | |
589 | goto out_free; | |
590 | } | |
591 | ||
592 | err = proc_get_long(&p, &left, &lval, &neg, | |
593 | proc_wspace_sep, | |
594 | sizeof(proc_wspace_sep), NULL); | |
595 | if (err || neg) { | |
596 | err = -EINVAL; | |
597 | goto out_free; | |
598 | } | |
599 | ||
600 | if (conv(&lval, tbl_data, 1, data)) { | |
601 | err = -EINVAL; | |
602 | goto out_free; | |
603 | } | |
604 | ||
605 | if (!err && left) | |
606 | left -= proc_skip_spaces(&p); | |
607 | ||
608 | out_free: | |
4f2fec00 LR |
609 | if (err) |
610 | return -EINVAL; | |
611 | ||
612 | return 0; | |
613 | ||
614 | /* This is in keeping with old __do_proc_dointvec() */ | |
615 | bail_early: | |
616 | *ppos += *lenp; | |
617 | return err; | |
618 | } | |
619 | ||
32927393 | 620 | static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer, |
4f2fec00 LR |
621 | size_t *lenp, loff_t *ppos, |
622 | int (*conv)(unsigned long *lvalp, | |
623 | unsigned int *valp, | |
624 | int write, void *data), | |
625 | void *data) | |
626 | { | |
627 | unsigned long lval; | |
628 | int err = 0; | |
629 | size_t left; | |
630 | ||
631 | left = *lenp; | |
632 | ||
633 | if (conv(&lval, tbl_data, 0, data)) { | |
634 | err = -EINVAL; | |
635 | goto out; | |
636 | } | |
637 | ||
32927393 CH |
638 | proc_put_long(&buffer, &left, lval, false); |
639 | if (!left) | |
4f2fec00 LR |
640 | goto out; |
641 | ||
32927393 | 642 | proc_put_char(&buffer, &left, '\n'); |
4f2fec00 LR |
643 | |
644 | out: | |
645 | *lenp -= left; | |
646 | *ppos += *lenp; | |
647 | ||
648 | return err; | |
649 | } | |
650 | ||
651 | static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table, | |
32927393 | 652 | int write, void *buffer, |
4f2fec00 LR |
653 | size_t *lenp, loff_t *ppos, |
654 | int (*conv)(unsigned long *lvalp, | |
655 | unsigned int *valp, | |
656 | int write, void *data), | |
657 | void *data) | |
658 | { | |
659 | unsigned int *i, vleft; | |
660 | ||
661 | if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { | |
662 | *lenp = 0; | |
663 | return 0; | |
664 | } | |
665 | ||
666 | i = (unsigned int *) tbl_data; | |
667 | vleft = table->maxlen / sizeof(*i); | |
668 | ||
669 | /* | |
670 | * Arrays are not supported, keep this simple. *Do not* add | |
671 | * support for them. | |
672 | */ | |
673 | if (vleft != 1) { | |
674 | *lenp = 0; | |
675 | return -EINVAL; | |
676 | } | |
677 | ||
678 | if (!conv) | |
679 | conv = do_proc_douintvec_conv; | |
680 | ||
681 | if (write) | |
682 | return do_proc_douintvec_w(i, table, buffer, lenp, ppos, | |
683 | conv, data); | |
684 | return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data); | |
685 | } | |
686 | ||
1998f193 LC |
687 | int do_proc_douintvec(struct ctl_table *table, int write, |
688 | void *buffer, size_t *lenp, loff_t *ppos, | |
689 | int (*conv)(unsigned long *lvalp, | |
690 | unsigned int *valp, | |
691 | int write, void *data), | |
692 | void *data) | |
4f2fec00 LR |
693 | { |
694 | return __do_proc_douintvec(table->data, table, write, | |
695 | buffer, lenp, ppos, conv, data); | |
696 | } | |
697 | ||
a2071573 JH |
698 | /** |
699 | * proc_dobool - read/write a bool | |
700 | * @table: the sysctl table | |
701 | * @write: %TRUE if this is a write to the sysctl file | |
702 | * @buffer: the user buffer | |
703 | * @lenp: the size of the user buffer | |
704 | * @ppos: file position | |
705 | * | |
706 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
707 | * values from/to the user buffer, treated as an ASCII string. | |
708 | * | |
709 | * Returns 0 on success. | |
710 | */ | |
711 | int proc_dobool(struct ctl_table *table, int write, void *buffer, | |
712 | size_t *lenp, loff_t *ppos) | |
713 | { | |
714 | return do_proc_dointvec(table, write, buffer, lenp, ppos, | |
715 | do_proc_dobool_conv, NULL); | |
716 | } | |
717 | ||
1da177e4 LT |
718 | /** |
719 | * proc_dointvec - read a vector of integers | |
720 | * @table: the sysctl table | |
721 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
722 | * @buffer: the user buffer |
723 | * @lenp: the size of the user buffer | |
724 | * @ppos: file position | |
725 | * | |
726 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
374a723c | 727 | * values from/to the user buffer, treated as an ASCII string. |
1da177e4 LT |
728 | * |
729 | * Returns 0 on success. | |
730 | */ | |
32927393 CH |
731 | int proc_dointvec(struct ctl_table *table, int write, void *buffer, |
732 | size_t *lenp, loff_t *ppos) | |
1da177e4 | 733 | { |
e7d316a0 SAK |
734 | return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); |
735 | } | |
736 | ||
6923aa0d SAS |
737 | #ifdef CONFIG_COMPACTION |
738 | static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table, | |
32927393 | 739 | int write, void *buffer, size_t *lenp, loff_t *ppos) |
6923aa0d SAS |
740 | { |
741 | int ret, old; | |
742 | ||
743 | if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write) | |
744 | return proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
745 | ||
746 | old = *(int *)table->data; | |
747 | ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
748 | if (ret) | |
749 | return ret; | |
750 | if (old != *(int *)table->data) | |
751 | pr_warn_once("sysctl attribute %s changed by %s[%d]\n", | |
752 | table->procname, current->comm, | |
753 | task_pid_nr(current)); | |
754 | return ret; | |
755 | } | |
756 | #endif | |
757 | ||
e7d316a0 SAK |
758 | /** |
759 | * proc_douintvec - read a vector of unsigned integers | |
760 | * @table: the sysctl table | |
761 | * @write: %TRUE if this is a write to the sysctl file | |
762 | * @buffer: the user buffer | |
763 | * @lenp: the size of the user buffer | |
764 | * @ppos: file position | |
765 | * | |
766 | * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer | |
767 | * values from/to the user buffer, treated as an ASCII string. | |
768 | * | |
769 | * Returns 0 on success. | |
770 | */ | |
32927393 CH |
771 | int proc_douintvec(struct ctl_table *table, int write, void *buffer, |
772 | size_t *lenp, loff_t *ppos) | |
e7d316a0 | 773 | { |
4f2fec00 LR |
774 | return do_proc_douintvec(table, write, buffer, lenp, ppos, |
775 | do_proc_douintvec_conv, NULL); | |
1da177e4 LT |
776 | } |
777 | ||
34f5a398 | 778 | /* |
25ddbb18 AK |
779 | * Taint values can only be increased |
780 | * This means we can safely use a temporary. | |
34f5a398 | 781 | */ |
8d65af78 | 782 | static int proc_taint(struct ctl_table *table, int write, |
32927393 | 783 | void *buffer, size_t *lenp, loff_t *ppos) |
34f5a398 | 784 | { |
25ddbb18 AK |
785 | struct ctl_table t; |
786 | unsigned long tmptaint = get_taint(); | |
787 | int err; | |
34f5a398 | 788 | |
91fcd412 | 789 | if (write && !capable(CAP_SYS_ADMIN)) |
34f5a398 TT |
790 | return -EPERM; |
791 | ||
25ddbb18 AK |
792 | t = *table; |
793 | t.data = &tmptaint; | |
8d65af78 | 794 | err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); |
25ddbb18 AK |
795 | if (err < 0) |
796 | return err; | |
797 | ||
798 | if (write) { | |
db38d5c1 RA |
799 | int i; |
800 | ||
801 | /* | |
802 | * If we are relying on panic_on_taint not producing | |
803 | * false positives due to userspace input, bail out | |
804 | * before setting the requested taint flags. | |
805 | */ | |
806 | if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint)) | |
807 | return -EINVAL; | |
808 | ||
25ddbb18 AK |
809 | /* |
810 | * Poor man's atomic or. Not worth adding a primitive | |
811 | * to everyone's atomic.h for this | |
812 | */ | |
e77132e7 RA |
813 | for (i = 0; i < TAINT_FLAGS_COUNT; i++) |
814 | if ((1UL << i) & tmptaint) | |
373d4d09 | 815 | add_taint(i, LOCKDEP_STILL_OK); |
25ddbb18 AK |
816 | } |
817 | ||
818 | return err; | |
34f5a398 TT |
819 | } |
820 | ||
24704f36 WL |
821 | /** |
822 | * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure | |
823 | * @min: pointer to minimum allowable value | |
824 | * @max: pointer to maximum allowable value | |
825 | * | |
826 | * The do_proc_dointvec_minmax_conv_param structure provides the | |
827 | * minimum and maximum values for doing range checking for those sysctl | |
828 | * parameters that use the proc_dointvec_minmax() handler. | |
829 | */ | |
1da177e4 LT |
830 | struct do_proc_dointvec_minmax_conv_param { |
831 | int *min; | |
832 | int *max; | |
833 | }; | |
834 | ||
00b7c339 AW |
835 | static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, |
836 | int *valp, | |
1da177e4 LT |
837 | int write, void *data) |
838 | { | |
2bc4fc60 | 839 | int tmp, ret; |
1da177e4 | 840 | struct do_proc_dointvec_minmax_conv_param *param = data; |
2bc4fc60 ZW |
841 | /* |
842 | * If writing, first do so via a temporary local int so we can | |
843 | * bounds-check it before touching *valp. | |
844 | */ | |
845 | int *ip = write ? &tmp : valp; | |
846 | ||
847 | ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data); | |
848 | if (ret) | |
849 | return ret; | |
850 | ||
1da177e4 | 851 | if (write) { |
2bc4fc60 ZW |
852 | if ((param->min && *param->min > tmp) || |
853 | (param->max && *param->max < tmp)) | |
1da177e4 | 854 | return -EINVAL; |
f613d86d | 855 | WRITE_ONCE(*valp, tmp); |
1da177e4 | 856 | } |
2bc4fc60 | 857 | |
1da177e4 LT |
858 | return 0; |
859 | } | |
860 | ||
861 | /** | |
862 | * proc_dointvec_minmax - read a vector of integers with min/max values | |
863 | * @table: the sysctl table | |
864 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
865 | * @buffer: the user buffer |
866 | * @lenp: the size of the user buffer | |
867 | * @ppos: file position | |
868 | * | |
869 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
870 | * values from/to the user buffer, treated as an ASCII string. | |
871 | * | |
872 | * This routine will ensure the values are within the range specified by | |
873 | * table->extra1 (min) and table->extra2 (max). | |
874 | * | |
24704f36 | 875 | * Returns 0 on success or -EINVAL on write when the range check fails. |
1da177e4 | 876 | */ |
8d65af78 | 877 | int proc_dointvec_minmax(struct ctl_table *table, int write, |
32927393 | 878 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
879 | { |
880 | struct do_proc_dointvec_minmax_conv_param param = { | |
881 | .min = (int *) table->extra1, | |
882 | .max = (int *) table->extra2, | |
883 | }; | |
8d65af78 | 884 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1da177e4 LT |
885 | do_proc_dointvec_minmax_conv, ¶m); |
886 | } | |
887 | ||
24704f36 WL |
888 | /** |
889 | * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure | |
890 | * @min: pointer to minimum allowable value | |
891 | * @max: pointer to maximum allowable value | |
892 | * | |
893 | * The do_proc_douintvec_minmax_conv_param structure provides the | |
894 | * minimum and maximum values for doing range checking for those sysctl | |
895 | * parameters that use the proc_douintvec_minmax() handler. | |
896 | */ | |
61d9b56a LR |
897 | struct do_proc_douintvec_minmax_conv_param { |
898 | unsigned int *min; | |
899 | unsigned int *max; | |
900 | }; | |
901 | ||
902 | static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, | |
903 | unsigned int *valp, | |
904 | int write, void *data) | |
905 | { | |
2bc4fc60 ZW |
906 | int ret; |
907 | unsigned int tmp; | |
61d9b56a | 908 | struct do_proc_douintvec_minmax_conv_param *param = data; |
2bc4fc60 ZW |
909 | /* write via temporary local uint for bounds-checking */ |
910 | unsigned int *up = write ? &tmp : valp; | |
61d9b56a | 911 | |
2bc4fc60 ZW |
912 | ret = do_proc_douintvec_conv(lvalp, up, write, data); |
913 | if (ret) | |
914 | return ret; | |
fb910c42 | 915 | |
2bc4fc60 ZW |
916 | if (write) { |
917 | if ((param->min && *param->min > tmp) || | |
918 | (param->max && *param->max < tmp)) | |
61d9b56a LR |
919 | return -ERANGE; |
920 | ||
2d3b559d | 921 | WRITE_ONCE(*valp, tmp); |
61d9b56a LR |
922 | } |
923 | ||
924 | return 0; | |
925 | } | |
926 | ||
927 | /** | |
928 | * proc_douintvec_minmax - read a vector of unsigned ints with min/max values | |
929 | * @table: the sysctl table | |
930 | * @write: %TRUE if this is a write to the sysctl file | |
931 | * @buffer: the user buffer | |
932 | * @lenp: the size of the user buffer | |
933 | * @ppos: file position | |
934 | * | |
935 | * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer | |
936 | * values from/to the user buffer, treated as an ASCII string. Negative | |
937 | * strings are not allowed. | |
938 | * | |
939 | * This routine will ensure the values are within the range specified by | |
940 | * table->extra1 (min) and table->extra2 (max). There is a final sanity | |
941 | * check for UINT_MAX to avoid having to support wrap around uses from | |
942 | * userspace. | |
943 | * | |
24704f36 | 944 | * Returns 0 on success or -ERANGE on write when the range check fails. |
61d9b56a LR |
945 | */ |
946 | int proc_douintvec_minmax(struct ctl_table *table, int write, | |
32927393 | 947 | void *buffer, size_t *lenp, loff_t *ppos) |
61d9b56a LR |
948 | { |
949 | struct do_proc_douintvec_minmax_conv_param param = { | |
950 | .min = (unsigned int *) table->extra1, | |
951 | .max = (unsigned int *) table->extra2, | |
952 | }; | |
953 | return do_proc_douintvec(table, write, buffer, lenp, ppos, | |
954 | do_proc_douintvec_minmax_conv, ¶m); | |
955 | } | |
956 | ||
cb944413 ED |
957 | /** |
958 | * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values | |
959 | * @table: the sysctl table | |
960 | * @write: %TRUE if this is a write to the sysctl file | |
961 | * @buffer: the user buffer | |
962 | * @lenp: the size of the user buffer | |
963 | * @ppos: file position | |
964 | * | |
965 | * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars | |
966 | * values from/to the user buffer, treated as an ASCII string. Negative | |
967 | * strings are not allowed. | |
968 | * | |
969 | * This routine will ensure the values are within the range specified by | |
970 | * table->extra1 (min) and table->extra2 (max). | |
971 | * | |
972 | * Returns 0 on success or an error on write when the range check fails. | |
973 | */ | |
974 | int proc_dou8vec_minmax(struct ctl_table *table, int write, | |
975 | void *buffer, size_t *lenp, loff_t *ppos) | |
976 | { | |
977 | struct ctl_table tmp; | |
978 | unsigned int min = 0, max = 255U, val; | |
979 | u8 *data = table->data; | |
980 | struct do_proc_douintvec_minmax_conv_param param = { | |
981 | .min = &min, | |
982 | .max = &max, | |
983 | }; | |
984 | int res; | |
985 | ||
986 | /* Do not support arrays yet. */ | |
987 | if (table->maxlen != sizeof(u8)) | |
988 | return -EINVAL; | |
989 | ||
990 | if (table->extra1) { | |
991 | min = *(unsigned int *) table->extra1; | |
992 | if (min > 255U) | |
993 | return -EINVAL; | |
994 | } | |
995 | if (table->extra2) { | |
996 | max = *(unsigned int *) table->extra2; | |
997 | if (max > 255U) | |
998 | return -EINVAL; | |
999 | } | |
1000 | ||
1001 | tmp = *table; | |
1002 | ||
1003 | tmp.maxlen = sizeof(val); | |
1004 | tmp.data = &val; | |
7dee5d77 | 1005 | val = READ_ONCE(*data); |
cb944413 ED |
1006 | res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos, |
1007 | do_proc_douintvec_minmax_conv, ¶m); | |
1008 | if (res) | |
1009 | return res; | |
1010 | if (write) | |
7dee5d77 | 1011 | WRITE_ONCE(*data, val); |
cb944413 ED |
1012 | return 0; |
1013 | } | |
1014 | EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); | |
1015 | ||
eaee4172 DS |
1016 | #ifdef CONFIG_MAGIC_SYSRQ |
1017 | static int sysrq_sysctl_handler(struct ctl_table *table, int write, | |
32927393 | 1018 | void *buffer, size_t *lenp, loff_t *ppos) |
eaee4172 DS |
1019 | { |
1020 | int tmp, ret; | |
1021 | ||
1022 | tmp = sysrq_mask(); | |
1023 | ||
1024 | ret = __do_proc_dointvec(&tmp, table, write, buffer, | |
1025 | lenp, ppos, NULL, NULL); | |
1026 | if (ret || !write) | |
1027 | return ret; | |
1028 | ||
1029 | if (write) | |
1030 | sysrq_toggle_support(tmp); | |
1031 | ||
1032 | return 0; | |
1033 | } | |
1034 | #endif | |
1035 | ||
32927393 CH |
1036 | static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, |
1037 | int write, void *buffer, size_t *lenp, loff_t *ppos, | |
1038 | unsigned long convmul, unsigned long convdiv) | |
1da177e4 | 1039 | { |
00b7c339 AW |
1040 | unsigned long *i, *min, *max; |
1041 | int vleft, first = 1, err = 0; | |
00b7c339 | 1042 | size_t left; |
32927393 | 1043 | char *p; |
00b7c339 AW |
1044 | |
1045 | if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { | |
1da177e4 LT |
1046 | *lenp = 0; |
1047 | return 0; | |
1048 | } | |
00b7c339 | 1049 | |
8ebc4123 DC |
1050 | i = data; |
1051 | min = table->extra1; | |
1052 | max = table->extra2; | |
1da177e4 LT |
1053 | vleft = table->maxlen / sizeof(unsigned long); |
1054 | left = *lenp; | |
00b7c339 AW |
1055 | |
1056 | if (write) { | |
d383d484 LR |
1057 | if (proc_first_pos_non_zero_ignore(ppos, table)) |
1058 | goto out; | |
f4aacea2 | 1059 | |
00b7c339 AW |
1060 | if (left > PAGE_SIZE - 1) |
1061 | left = PAGE_SIZE - 1; | |
32927393 | 1062 | p = buffer; |
00b7c339 AW |
1063 | } |
1064 | ||
27b3d80a | 1065 | for (; left && vleft--; i++, first = 0) { |
00b7c339 AW |
1066 | unsigned long val; |
1067 | ||
1da177e4 | 1068 | if (write) { |
00b7c339 AW |
1069 | bool neg; |
1070 | ||
70f6cbb6 | 1071 | left -= proc_skip_spaces(&p); |
09be1784 CL |
1072 | if (!left) |
1073 | break; | |
00b7c339 | 1074 | |
70f6cbb6 | 1075 | err = proc_get_long(&p, &left, &val, &neg, |
00b7c339 AW |
1076 | proc_wspace_sep, |
1077 | sizeof(proc_wspace_sep), NULL); | |
1622ed7d BL |
1078 | if (err || neg) { |
1079 | err = -EINVAL; | |
1da177e4 | 1080 | break; |
1622ed7d BL |
1081 | } |
1082 | ||
ff9f8a7c | 1083 | val = convmul * val / convdiv; |
e260ad01 CB |
1084 | if ((min && val < *min) || (max && val > *max)) { |
1085 | err = -EINVAL; | |
1086 | break; | |
1087 | } | |
c31bcc8f | 1088 | WRITE_ONCE(*i, val); |
1da177e4 | 1089 | } else { |
c31bcc8f | 1090 | val = convdiv * READ_ONCE(*i) / convmul; |
32927393 CH |
1091 | if (!first) |
1092 | proc_put_char(&buffer, &left, '\t'); | |
1093 | proc_put_long(&buffer, &left, val, false); | |
1da177e4 LT |
1094 | } |
1095 | } | |
1096 | ||
00b7c339 | 1097 | if (!write && !first && left && !err) |
32927393 | 1098 | proc_put_char(&buffer, &left, '\n'); |
00b7c339 | 1099 | if (write && !err) |
70f6cbb6 | 1100 | left -= proc_skip_spaces(&p); |
32927393 CH |
1101 | if (write && first) |
1102 | return err ? : -EINVAL; | |
1da177e4 | 1103 | *lenp -= left; |
f4aacea2 | 1104 | out: |
1da177e4 | 1105 | *ppos += *lenp; |
00b7c339 | 1106 | return err; |
1da177e4 LT |
1107 | } |
1108 | ||
d8217f07 | 1109 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, |
32927393 CH |
1110 | void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, |
1111 | unsigned long convdiv) | |
fcfbd547 KK |
1112 | { |
1113 | return __do_proc_doulongvec_minmax(table->data, table, write, | |
8d65af78 | 1114 | buffer, lenp, ppos, convmul, convdiv); |
fcfbd547 KK |
1115 | } |
1116 | ||
1da177e4 LT |
1117 | /** |
1118 | * proc_doulongvec_minmax - read a vector of long integers with min/max values | |
1119 | * @table: the sysctl table | |
1120 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1121 | * @buffer: the user buffer |
1122 | * @lenp: the size of the user buffer | |
1123 | * @ppos: file position | |
1124 | * | |
1125 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
1126 | * values from/to the user buffer, treated as an ASCII string. | |
1127 | * | |
1128 | * This routine will ensure the values are within the range specified by | |
1129 | * table->extra1 (min) and table->extra2 (max). | |
1130 | * | |
1131 | * Returns 0 on success. | |
1132 | */ | |
8d65af78 | 1133 | int proc_doulongvec_minmax(struct ctl_table *table, int write, |
32927393 | 1134 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1135 | { |
8d65af78 | 1136 | return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); |
1da177e4 LT |
1137 | } |
1138 | ||
1139 | /** | |
1140 | * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values | |
1141 | * @table: the sysctl table | |
1142 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1143 | * @buffer: the user buffer |
1144 | * @lenp: the size of the user buffer | |
1145 | * @ppos: file position | |
1146 | * | |
1147 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
1148 | * values from/to the user buffer, treated as an ASCII string. The values | |
1149 | * are treated as milliseconds, and converted to jiffies when they are stored. | |
1150 | * | |
1151 | * This routine will ensure the values are within the range specified by | |
1152 | * table->extra1 (min) and table->extra2 (max). | |
1153 | * | |
1154 | * Returns 0 on success. | |
1155 | */ | |
d8217f07 | 1156 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
32927393 | 1157 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1158 | { |
8d65af78 | 1159 | return do_proc_doulongvec_minmax(table, write, buffer, |
1da177e4 LT |
1160 | lenp, ppos, HZ, 1000l); |
1161 | } | |
1162 | ||
1163 | ||
00b7c339 | 1164 | static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
1165 | int *valp, |
1166 | int write, void *data) | |
1167 | { | |
1168 | if (write) { | |
63259457 | 1169 | if (*lvalp > INT_MAX / HZ) |
cba9f33d | 1170 | return 1; |
e8778208 KI |
1171 | if (*negp) |
1172 | WRITE_ONCE(*valp, -*lvalp * HZ); | |
1173 | else | |
1174 | WRITE_ONCE(*valp, *lvalp * HZ); | |
1da177e4 | 1175 | } else { |
e8778208 | 1176 | int val = READ_ONCE(*valp); |
1da177e4 LT |
1177 | unsigned long lval; |
1178 | if (val < 0) { | |
00b7c339 | 1179 | *negp = true; |
9a5bc726 | 1180 | lval = -(unsigned long)val; |
1da177e4 | 1181 | } else { |
00b7c339 | 1182 | *negp = false; |
1da177e4 LT |
1183 | lval = (unsigned long)val; |
1184 | } | |
1185 | *lvalp = lval / HZ; | |
1186 | } | |
1187 | return 0; | |
1188 | } | |
1189 | ||
00b7c339 | 1190 | static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
1191 | int *valp, |
1192 | int write, void *data) | |
1193 | { | |
1194 | if (write) { | |
cba9f33d BS |
1195 | if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) |
1196 | return 1; | |
1da177e4 LT |
1197 | *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); |
1198 | } else { | |
1199 | int val = *valp; | |
1200 | unsigned long lval; | |
1201 | if (val < 0) { | |
00b7c339 | 1202 | *negp = true; |
9a5bc726 | 1203 | lval = -(unsigned long)val; |
1da177e4 | 1204 | } else { |
00b7c339 | 1205 | *negp = false; |
1da177e4 LT |
1206 | lval = (unsigned long)val; |
1207 | } | |
1208 | *lvalp = jiffies_to_clock_t(lval); | |
1209 | } | |
1210 | return 0; | |
1211 | } | |
1212 | ||
00b7c339 | 1213 | static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
1214 | int *valp, |
1215 | int write, void *data) | |
1216 | { | |
1217 | if (write) { | |
d738ce8f FF |
1218 | unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); |
1219 | ||
1220 | if (jif > INT_MAX) | |
1221 | return 1; | |
7d1025e5 | 1222 | WRITE_ONCE(*valp, (int)jif); |
1da177e4 | 1223 | } else { |
7d1025e5 | 1224 | int val = READ_ONCE(*valp); |
1da177e4 LT |
1225 | unsigned long lval; |
1226 | if (val < 0) { | |
00b7c339 | 1227 | *negp = true; |
9a5bc726 | 1228 | lval = -(unsigned long)val; |
1da177e4 | 1229 | } else { |
00b7c339 | 1230 | *negp = false; |
1da177e4 LT |
1231 | lval = (unsigned long)val; |
1232 | } | |
1233 | *lvalp = jiffies_to_msecs(lval); | |
1234 | } | |
1235 | return 0; | |
1236 | } | |
1237 | ||
c381d02b YW |
1238 | static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp, |
1239 | int *valp, int write, void *data) | |
1240 | { | |
1241 | int tmp, ret; | |
1242 | struct do_proc_dointvec_minmax_conv_param *param = data; | |
1243 | /* | |
1244 | * If writing, first do so via a temporary local int so we can | |
1245 | * bounds-check it before touching *valp. | |
1246 | */ | |
1247 | int *ip = write ? &tmp : valp; | |
1248 | ||
1249 | ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data); | |
1250 | if (ret) | |
1251 | return ret; | |
1252 | ||
1253 | if (write) { | |
1254 | if ((param->min && *param->min > tmp) || | |
1255 | (param->max && *param->max < tmp)) | |
1256 | return -EINVAL; | |
1257 | *valp = tmp; | |
1258 | } | |
1259 | return 0; | |
1260 | } | |
1261 | ||
1da177e4 LT |
1262 | /** |
1263 | * proc_dointvec_jiffies - read a vector of integers as seconds | |
1264 | * @table: the sysctl table | |
1265 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1266 | * @buffer: the user buffer |
1267 | * @lenp: the size of the user buffer | |
1268 | * @ppos: file position | |
1269 | * | |
1270 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
374a723c | 1271 | * values from/to the user buffer, treated as an ASCII string. |
1da177e4 LT |
1272 | * The values read are assumed to be in seconds, and are converted into |
1273 | * jiffies. | |
1274 | * | |
1275 | * Returns 0 on success. | |
1276 | */ | |
8d65af78 | 1277 | int proc_dointvec_jiffies(struct ctl_table *table, int write, |
32927393 | 1278 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1279 | { |
8d65af78 | 1280 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
1da177e4 LT |
1281 | do_proc_dointvec_jiffies_conv,NULL); |
1282 | } | |
1283 | ||
c381d02b YW |
1284 | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
1285 | void *buffer, size_t *lenp, loff_t *ppos) | |
1286 | { | |
1287 | struct do_proc_dointvec_minmax_conv_param param = { | |
1288 | .min = (int *) table->extra1, | |
1289 | .max = (int *) table->extra2, | |
1290 | }; | |
1291 | return do_proc_dointvec(table, write, buffer, lenp, ppos, | |
1292 | do_proc_dointvec_ms_jiffies_minmax_conv, ¶m); | |
1293 | } | |
1294 | ||
1da177e4 LT |
1295 | /** |
1296 | * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds | |
1297 | * @table: the sysctl table | |
1298 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1299 | * @buffer: the user buffer |
1300 | * @lenp: the size of the user buffer | |
1e5d5331 | 1301 | * @ppos: pointer to the file position |
1da177e4 LT |
1302 | * |
1303 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
374a723c FK |
1304 | * values from/to the user buffer, treated as an ASCII string. |
1305 | * The values read are assumed to be in 1/USER_HZ seconds, and | |
1da177e4 LT |
1306 | * are converted into jiffies. |
1307 | * | |
1308 | * Returns 0 on success. | |
1309 | */ | |
8d65af78 | 1310 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, |
32927393 | 1311 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1312 | { |
5bfd5d3e FK |
1313 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1314 | do_proc_dointvec_userhz_jiffies_conv, NULL); | |
1da177e4 LT |
1315 | } |
1316 | ||
1317 | /** | |
1318 | * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds | |
1319 | * @table: the sysctl table | |
1320 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
1321 | * @buffer: the user buffer |
1322 | * @lenp: the size of the user buffer | |
67be2dd1 MW |
1323 | * @ppos: file position |
1324 | * @ppos: the current position in the file | |
1da177e4 LT |
1325 | * |
1326 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
7d1025e5 KI |
1327 | * values from/to the user buffer, treated as an ASCII string. |
1328 | * The values read are assumed to be in 1/1000 seconds, and | |
1da177e4 LT |
1329 | * are converted into jiffies. |
1330 | * | |
1331 | * Returns 0 on success. | |
1332 | */ | |
32927393 CH |
1333 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer, |
1334 | size_t *lenp, loff_t *ppos) | |
1da177e4 | 1335 | { |
8d65af78 | 1336 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1da177e4 LT |
1337 | do_proc_dointvec_ms_jiffies_conv, NULL); |
1338 | } | |
1339 | ||
32927393 CH |
1340 | static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, |
1341 | size_t *lenp, loff_t *ppos) | |
9ec52099 CLG |
1342 | { |
1343 | struct pid *new_pid; | |
1344 | pid_t tmp; | |
1345 | int r; | |
1346 | ||
6c5f3e7b | 1347 | tmp = pid_vnr(cad_pid); |
9ec52099 | 1348 | |
8d65af78 | 1349 | r = __do_proc_dointvec(&tmp, table, write, buffer, |
9ec52099 CLG |
1350 | lenp, ppos, NULL, NULL); |
1351 | if (r || !write) | |
1352 | return r; | |
1353 | ||
1354 | new_pid = find_get_pid(tmp); | |
1355 | if (!new_pid) | |
1356 | return -ESRCH; | |
1357 | ||
1358 | put_pid(xchg(&cad_pid, new_pid)); | |
1359 | return 0; | |
1360 | } | |
1361 | ||
9f977fb7 OP |
1362 | /** |
1363 | * proc_do_large_bitmap - read/write from/to a large bitmap | |
1364 | * @table: the sysctl table | |
1365 | * @write: %TRUE if this is a write to the sysctl file | |
1366 | * @buffer: the user buffer | |
1367 | * @lenp: the size of the user buffer | |
1368 | * @ppos: file position | |
1369 | * | |
1370 | * The bitmap is stored at table->data and the bitmap length (in bits) | |
1371 | * in table->maxlen. | |
1372 | * | |
1373 | * We use a range comma separated format (e.g. 1,3-4,10-10) so that | |
1374 | * large bitmaps may be represented in a compact manner. Writing into | |
1375 | * the file will clear the bitmap then update it with the given input. | |
1376 | * | |
1377 | * Returns 0 on success. | |
1378 | */ | |
1379 | int proc_do_large_bitmap(struct ctl_table *table, int write, | |
32927393 | 1380 | void *buffer, size_t *lenp, loff_t *ppos) |
9f977fb7 OP |
1381 | { |
1382 | int err = 0; | |
9f977fb7 OP |
1383 | size_t left = *lenp; |
1384 | unsigned long bitmap_len = table->maxlen; | |
122ff243 | 1385 | unsigned long *bitmap = *(unsigned long **) table->data; |
9f977fb7 OP |
1386 | unsigned long *tmp_bitmap = NULL; |
1387 | char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; | |
1388 | ||
122ff243 | 1389 | if (!bitmap || !bitmap_len || !left || (*ppos && !write)) { |
9f977fb7 OP |
1390 | *lenp = 0; |
1391 | return 0; | |
1392 | } | |
1393 | ||
1394 | if (write) { | |
32927393 | 1395 | char *p = buffer; |
3116ad38 | 1396 | size_t skipped = 0; |
9f977fb7 | 1397 | |
3116ad38 | 1398 | if (left > PAGE_SIZE - 1) { |
9f977fb7 | 1399 | left = PAGE_SIZE - 1; |
3116ad38 ES |
1400 | /* How much of the buffer we'll skip this pass */ |
1401 | skipped = *lenp - left; | |
1402 | } | |
9f977fb7 | 1403 | |
475dae38 | 1404 | tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL); |
32927393 | 1405 | if (!tmp_bitmap) |
9f977fb7 | 1406 | return -ENOMEM; |
70f6cbb6 | 1407 | proc_skip_char(&p, &left, '\n'); |
9f977fb7 OP |
1408 | while (!err && left) { |
1409 | unsigned long val_a, val_b; | |
1410 | bool neg; | |
3116ad38 | 1411 | size_t saved_left; |
9f977fb7 | 1412 | |
3116ad38 ES |
1413 | /* In case we stop parsing mid-number, we can reset */ |
1414 | saved_left = left; | |
70f6cbb6 | 1415 | err = proc_get_long(&p, &left, &val_a, &neg, tr_a, |
9f977fb7 | 1416 | sizeof(tr_a), &c); |
3116ad38 ES |
1417 | /* |
1418 | * If we consumed the entirety of a truncated buffer or | |
1419 | * only one char is left (may be a "-"), then stop here, | |
1420 | * reset, & come back for more. | |
1421 | */ | |
1422 | if ((left <= 1) && skipped) { | |
1423 | left = saved_left; | |
1424 | break; | |
1425 | } | |
1426 | ||
9f977fb7 OP |
1427 | if (err) |
1428 | break; | |
1429 | if (val_a >= bitmap_len || neg) { | |
1430 | err = -EINVAL; | |
1431 | break; | |
1432 | } | |
1433 | ||
1434 | val_b = val_a; | |
1435 | if (left) { | |
70f6cbb6 | 1436 | p++; |
9f977fb7 OP |
1437 | left--; |
1438 | } | |
1439 | ||
1440 | if (c == '-') { | |
70f6cbb6 | 1441 | err = proc_get_long(&p, &left, &val_b, |
9f977fb7 OP |
1442 | &neg, tr_b, sizeof(tr_b), |
1443 | &c); | |
3116ad38 ES |
1444 | /* |
1445 | * If we consumed all of a truncated buffer or | |
1446 | * then stop here, reset, & come back for more. | |
1447 | */ | |
1448 | if (!left && skipped) { | |
1449 | left = saved_left; | |
1450 | break; | |
1451 | } | |
1452 | ||
9f977fb7 OP |
1453 | if (err) |
1454 | break; | |
1455 | if (val_b >= bitmap_len || neg || | |
1456 | val_a > val_b) { | |
1457 | err = -EINVAL; | |
1458 | break; | |
1459 | } | |
1460 | if (left) { | |
70f6cbb6 | 1461 | p++; |
9f977fb7 OP |
1462 | left--; |
1463 | } | |
1464 | } | |
1465 | ||
5a04cca6 | 1466 | bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); |
70f6cbb6 | 1467 | proc_skip_char(&p, &left, '\n'); |
9f977fb7 | 1468 | } |
3116ad38 | 1469 | left += skipped; |
9f977fb7 OP |
1470 | } else { |
1471 | unsigned long bit_a, bit_b = 0; | |
9a52c5f3 | 1472 | bool first = 1; |
9f977fb7 OP |
1473 | |
1474 | while (left) { | |
1475 | bit_a = find_next_bit(bitmap, bitmap_len, bit_b); | |
1476 | if (bit_a >= bitmap_len) | |
1477 | break; | |
1478 | bit_b = find_next_zero_bit(bitmap, bitmap_len, | |
1479 | bit_a + 1) - 1; | |
1480 | ||
32927393 CH |
1481 | if (!first) |
1482 | proc_put_char(&buffer, &left, ','); | |
1483 | proc_put_long(&buffer, &left, bit_a, false); | |
9f977fb7 | 1484 | if (bit_a != bit_b) { |
32927393 CH |
1485 | proc_put_char(&buffer, &left, '-'); |
1486 | proc_put_long(&buffer, &left, bit_b, false); | |
9f977fb7 OP |
1487 | } |
1488 | ||
1489 | first = 0; bit_b++; | |
1490 | } | |
32927393 | 1491 | proc_put_char(&buffer, &left, '\n'); |
9f977fb7 OP |
1492 | } |
1493 | ||
1494 | if (!err) { | |
1495 | if (write) { | |
1496 | if (*ppos) | |
1497 | bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); | |
1498 | else | |
5a04cca6 | 1499 | bitmap_copy(bitmap, tmp_bitmap, bitmap_len); |
9f977fb7 | 1500 | } |
9f977fb7 OP |
1501 | *lenp -= left; |
1502 | *ppos += *lenp; | |
9f977fb7 | 1503 | } |
f9eb2fdd | 1504 | |
475dae38 | 1505 | bitmap_free(tmp_bitmap); |
f9eb2fdd | 1506 | return err; |
9f977fb7 OP |
1507 | } |
1508 | ||
55610500 | 1509 | #else /* CONFIG_PROC_SYSCTL */ |
1da177e4 | 1510 | |
8d65af78 | 1511 | int proc_dostring(struct ctl_table *table, int write, |
32927393 | 1512 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1513 | { |
1514 | return -ENOSYS; | |
1515 | } | |
1516 | ||
a2071573 JH |
1517 | int proc_dobool(struct ctl_table *table, int write, |
1518 | void *buffer, size_t *lenp, loff_t *ppos) | |
1519 | { | |
1520 | return -ENOSYS; | |
1521 | } | |
1522 | ||
f461d2dc | 1523 | int proc_dointvec(struct ctl_table *table, int write, |
32927393 | 1524 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1525 | { |
1526 | return -ENOSYS; | |
1527 | } | |
1528 | ||
1529 | int proc_douintvec(struct ctl_table *table, int write, | |
32927393 | 1530 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1531 | { |
1532 | return -ENOSYS; | |
1533 | } | |
1534 | ||
1535 | int proc_dointvec_minmax(struct ctl_table *table, int write, | |
32927393 | 1536 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1537 | { |
1538 | return -ENOSYS; | |
1539 | } | |
1540 | ||
1541 | int proc_douintvec_minmax(struct ctl_table *table, int write, | |
32927393 | 1542 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1543 | { |
1544 | return -ENOSYS; | |
9f977fb7 OP |
1545 | } |
1546 | ||
cb944413 ED |
1547 | int proc_dou8vec_minmax(struct ctl_table *table, int write, |
1548 | void *buffer, size_t *lenp, loff_t *ppos) | |
1549 | { | |
1550 | return -ENOSYS; | |
1551 | } | |
1552 | ||
f461d2dc | 1553 | int proc_dointvec_jiffies(struct ctl_table *table, int write, |
32927393 | 1554 | void *buffer, size_t *lenp, loff_t *ppos) |
f461d2dc CH |
1555 | { |
1556 | return -ENOSYS; | |
1557 | } | |
1da177e4 | 1558 | |
c381d02b YW |
1559 | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
1560 | void *buffer, size_t *lenp, loff_t *ppos) | |
1561 | { | |
1562 | return -ENOSYS; | |
1563 | } | |
1564 | ||
f461d2dc | 1565 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, |
32927393 | 1566 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1567 | { |
1568 | return -ENOSYS; | |
1569 | } | |
1570 | ||
f461d2dc | 1571 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, |
32927393 | 1572 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1573 | { |
1574 | return -ENOSYS; | |
1575 | } | |
1576 | ||
f461d2dc | 1577 | int proc_doulongvec_minmax(struct ctl_table *table, int write, |
32927393 | 1578 | void *buffer, size_t *lenp, loff_t *ppos) |
e7d316a0 SAK |
1579 | { |
1580 | return -ENOSYS; | |
1581 | } | |
1582 | ||
f461d2dc | 1583 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
32927393 | 1584 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1585 | { |
32927393 | 1586 | return -ENOSYS; |
1da177e4 LT |
1587 | } |
1588 | ||
f461d2dc | 1589 | int proc_do_large_bitmap(struct ctl_table *table, int write, |
32927393 | 1590 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
1591 | { |
1592 | return -ENOSYS; | |
1593 | } | |
1594 | ||
f461d2dc CH |
1595 | #endif /* CONFIG_PROC_SYSCTL */ |
1596 | ||
1597 | #if defined(CONFIG_SYSCTL) | |
1598 | int proc_do_static_key(struct ctl_table *table, int write, | |
32927393 | 1599 | void *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 | 1600 | { |
f461d2dc CH |
1601 | struct static_key *key = (struct static_key *)table->data; |
1602 | static DEFINE_MUTEX(static_key_mutex); | |
1603 | int val, ret; | |
1604 | struct ctl_table tmp = { | |
1605 | .data = &val, | |
1606 | .maxlen = sizeof(val), | |
1607 | .mode = table->mode, | |
1608 | .extra1 = SYSCTL_ZERO, | |
1609 | .extra2 = SYSCTL_ONE, | |
1610 | }; | |
1611 | ||
1612 | if (write && !capable(CAP_SYS_ADMIN)) | |
1613 | return -EPERM; | |
1614 | ||
1615 | mutex_lock(&static_key_mutex); | |
1616 | val = static_key_enabled(key); | |
1617 | ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); | |
1618 | if (write && !ret) { | |
1619 | if (val) | |
1620 | static_key_enable(key); | |
1621 | else | |
1622 | static_key_disable(key); | |
1623 | } | |
1624 | mutex_unlock(&static_key_mutex); | |
1625 | return ret; | |
1da177e4 LT |
1626 | } |
1627 | ||
f461d2dc | 1628 | static struct ctl_table kern_table[] = { |
b7cc6ec7 | 1629 | #ifdef CONFIG_NUMA_BALANCING |
f461d2dc CH |
1630 | { |
1631 | .procname = "numa_balancing", | |
1632 | .data = NULL, /* filled in by handler */ | |
1633 | .maxlen = sizeof(unsigned int), | |
1634 | .mode = 0644, | |
1635 | .proc_handler = sysctl_numa_balancing, | |
1636 | .extra1 = SYSCTL_ZERO, | |
c574bbe9 | 1637 | .extra2 = SYSCTL_FOUR, |
f461d2dc CH |
1638 | }, |
1639 | #endif /* CONFIG_NUMA_BALANCING */ | |
f461d2dc CH |
1640 | { |
1641 | .procname = "panic", | |
1642 | .data = &panic_timeout, | |
1643 | .maxlen = sizeof(int), | |
1644 | .mode = 0644, | |
1645 | .proc_handler = proc_dointvec, | |
1646 | }, | |
f461d2dc CH |
1647 | #ifdef CONFIG_PROC_SYSCTL |
1648 | { | |
1649 | .procname = "tainted", | |
1650 | .maxlen = sizeof(long), | |
1651 | .mode = 0644, | |
1652 | .proc_handler = proc_taint, | |
1653 | }, | |
1654 | { | |
1655 | .procname = "sysctl_writes_strict", | |
1656 | .data = &sysctl_writes_strict, | |
1657 | .maxlen = sizeof(int), | |
1658 | .mode = 0644, | |
1659 | .proc_handler = proc_dointvec_minmax, | |
78e36f3b | 1660 | .extra1 = SYSCTL_NEG_ONE, |
f461d2dc CH |
1661 | .extra2 = SYSCTL_ONE, |
1662 | }, | |
f461d2dc CH |
1663 | #endif |
1664 | { | |
1665 | .procname = "print-fatal-signals", | |
1666 | .data = &print_fatal_signals, | |
1667 | .maxlen = sizeof(int), | |
1668 | .mode = 0644, | |
1669 | .proc_handler = proc_dointvec, | |
1670 | }, | |
1671 | #ifdef CONFIG_SPARC | |
1672 | { | |
1673 | .procname = "reboot-cmd", | |
1674 | .data = reboot_command, | |
1675 | .maxlen = 256, | |
1676 | .mode = 0644, | |
1677 | .proc_handler = proc_dostring, | |
1678 | }, | |
1679 | { | |
1680 | .procname = "stop-a", | |
1681 | .data = &stop_a_enabled, | |
1682 | .maxlen = sizeof (int), | |
1683 | .mode = 0644, | |
1684 | .proc_handler = proc_dointvec, | |
1685 | }, | |
1686 | { | |
1687 | .procname = "scons-poweroff", | |
1688 | .data = &scons_pwroff, | |
1689 | .maxlen = sizeof (int), | |
1690 | .mode = 0644, | |
1691 | .proc_handler = proc_dointvec, | |
1692 | }, | |
1693 | #endif | |
1694 | #ifdef CONFIG_SPARC64 | |
1695 | { | |
1696 | .procname = "tsb-ratio", | |
1697 | .data = &sysctl_tsb_ratio, | |
1698 | .maxlen = sizeof (int), | |
1699 | .mode = 0644, | |
1700 | .proc_handler = proc_dointvec, | |
1701 | }, | |
1702 | #endif | |
1703 | #ifdef CONFIG_PARISC | |
1704 | { | |
1705 | .procname = "soft-power", | |
1706 | .data = &pwrsw_enabled, | |
1707 | .maxlen = sizeof (int), | |
1708 | .mode = 0644, | |
1709 | .proc_handler = proc_dointvec, | |
1710 | }, | |
1711 | #endif | |
1712 | #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW | |
1713 | { | |
1714 | .procname = "unaligned-trap", | |
1715 | .data = &unaligned_enabled, | |
1716 | .maxlen = sizeof (int), | |
1717 | .mode = 0644, | |
1718 | .proc_handler = proc_dointvec, | |
1719 | }, | |
f461d2dc CH |
1720 | #endif |
1721 | #ifdef CONFIG_STACK_TRACER | |
1722 | { | |
1723 | .procname = "stack_tracer_enabled", | |
1724 | .data = &stack_tracer_enabled, | |
1725 | .maxlen = sizeof(int), | |
1726 | .mode = 0644, | |
1727 | .proc_handler = stack_trace_sysctl, | |
1728 | }, | |
1729 | #endif | |
1730 | #ifdef CONFIG_TRACING | |
1731 | { | |
1732 | .procname = "ftrace_dump_on_oops", | |
1733 | .data = &ftrace_dump_on_oops, | |
1734 | .maxlen = sizeof(int), | |
1735 | .mode = 0644, | |
1736 | .proc_handler = proc_dointvec, | |
1737 | }, | |
1738 | { | |
1739 | .procname = "traceoff_on_warning", | |
1740 | .data = &__disable_trace_on_warning, | |
1741 | .maxlen = sizeof(__disable_trace_on_warning), | |
1742 | .mode = 0644, | |
1743 | .proc_handler = proc_dointvec, | |
1744 | }, | |
1745 | { | |
1746 | .procname = "tracepoint_printk", | |
1747 | .data = &tracepoint_printk, | |
1748 | .maxlen = sizeof(tracepoint_printk), | |
1749 | .mode = 0644, | |
1750 | .proc_handler = tracepoint_printk_sysctl, | |
1751 | }, | |
1752 | #endif | |
f461d2dc CH |
1753 | #ifdef CONFIG_MODULES |
1754 | { | |
1755 | .procname = "modprobe", | |
1756 | .data = &modprobe_path, | |
1757 | .maxlen = KMOD_PATH_LEN, | |
1758 | .mode = 0644, | |
1759 | .proc_handler = proc_dostring, | |
1760 | }, | |
1761 | { | |
1762 | .procname = "modules_disabled", | |
1763 | .data = &modules_disabled, | |
1764 | .maxlen = sizeof(int), | |
1765 | .mode = 0644, | |
1766 | /* only handle a transition from default "0" to "1" */ | |
1767 | .proc_handler = proc_dointvec_minmax, | |
1768 | .extra1 = SYSCTL_ONE, | |
1769 | .extra2 = SYSCTL_ONE, | |
1770 | }, | |
1771 | #endif | |
1772 | #ifdef CONFIG_UEVENT_HELPER | |
1773 | { | |
1774 | .procname = "hotplug", | |
1775 | .data = &uevent_helper, | |
1776 | .maxlen = UEVENT_HELPER_PATH_LEN, | |
1777 | .mode = 0644, | |
1778 | .proc_handler = proc_dostring, | |
1779 | }, | |
1780 | #endif | |
f461d2dc CH |
1781 | #ifdef CONFIG_MAGIC_SYSRQ |
1782 | { | |
1783 | .procname = "sysrq", | |
1784 | .data = NULL, | |
1785 | .maxlen = sizeof (int), | |
1786 | .mode = 0644, | |
1787 | .proc_handler = sysrq_sysctl_handler, | |
1788 | }, | |
1789 | #endif | |
1790 | #ifdef CONFIG_PROC_SYSCTL | |
1791 | { | |
1792 | .procname = "cad_pid", | |
1793 | .data = NULL, | |
1794 | .maxlen = sizeof (int), | |
1795 | .mode = 0600, | |
1796 | .proc_handler = proc_do_cad_pid, | |
1797 | }, | |
1798 | #endif | |
1799 | { | |
1800 | .procname = "threads-max", | |
1801 | .data = NULL, | |
1802 | .maxlen = sizeof(int), | |
1803 | .mode = 0644, | |
1804 | .proc_handler = sysctl_max_threads, | |
1805 | }, | |
f461d2dc CH |
1806 | { |
1807 | .procname = "usermodehelper", | |
1808 | .mode = 0555, | |
1809 | .child = usermodehelper_table, | |
1810 | }, | |
f461d2dc CH |
1811 | { |
1812 | .procname = "overflowuid", | |
1813 | .data = &overflowuid, | |
1814 | .maxlen = sizeof(int), | |
1815 | .mode = 0644, | |
1816 | .proc_handler = proc_dointvec_minmax, | |
2452dcb9 | 1817 | .extra1 = SYSCTL_ZERO, |
54771613 | 1818 | .extra2 = SYSCTL_MAXOLDUID, |
f461d2dc CH |
1819 | }, |
1820 | { | |
1821 | .procname = "overflowgid", | |
1822 | .data = &overflowgid, | |
1823 | .maxlen = sizeof(int), | |
1824 | .mode = 0644, | |
1825 | .proc_handler = proc_dointvec_minmax, | |
2452dcb9 | 1826 | .extra1 = SYSCTL_ZERO, |
54771613 | 1827 | .extra2 = SYSCTL_MAXOLDUID, |
f461d2dc CH |
1828 | }, |
1829 | #ifdef CONFIG_S390 | |
1830 | { | |
1831 | .procname = "userprocess_debug", | |
1832 | .data = &show_unhandled_signals, | |
1833 | .maxlen = sizeof(int), | |
1834 | .mode = 0644, | |
1835 | .proc_handler = proc_dointvec, | |
1836 | }, | |
1837 | #endif | |
1838 | { | |
1839 | .procname = "pid_max", | |
1840 | .data = &pid_max, | |
1841 | .maxlen = sizeof (int), | |
1842 | .mode = 0644, | |
1843 | .proc_handler = proc_dointvec_minmax, | |
1844 | .extra1 = &pid_max_min, | |
1845 | .extra2 = &pid_max_max, | |
1846 | }, | |
1847 | { | |
1848 | .procname = "panic_on_oops", | |
1849 | .data = &panic_on_oops, | |
1850 | .maxlen = sizeof(int), | |
1851 | .mode = 0644, | |
1852 | .proc_handler = proc_dointvec, | |
1853 | }, | |
1854 | { | |
1855 | .procname = "panic_print", | |
1856 | .data = &panic_print, | |
1857 | .maxlen = sizeof(unsigned long), | |
1858 | .mode = 0644, | |
1859 | .proc_handler = proc_doulongvec_minmax, | |
1860 | }, | |
f461d2dc CH |
1861 | { |
1862 | .procname = "ngroups_max", | |
f628867d | 1863 | .data = (void *)&ngroups_max, |
f461d2dc CH |
1864 | .maxlen = sizeof (int), |
1865 | .mode = 0444, | |
1866 | .proc_handler = proc_dointvec, | |
1867 | }, | |
1868 | { | |
1869 | .procname = "cap_last_cap", | |
1870 | .data = (void *)&cap_last_cap, | |
1871 | .maxlen = sizeof(int), | |
1872 | .mode = 0444, | |
1873 | .proc_handler = proc_dointvec, | |
1874 | }, | |
f461d2dc CH |
1875 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) |
1876 | { | |
1877 | .procname = "unknown_nmi_panic", | |
1878 | .data = &unknown_nmi_panic, | |
1879 | .maxlen = sizeof (int), | |
1880 | .mode = 0644, | |
1881 | .proc_handler = proc_dointvec, | |
1882 | }, | |
1883 | #endif | |
61d9b56a | 1884 | |
cb8e59cc LT |
1885 | #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \ |
1886 | defined(CONFIG_DEBUG_STACKOVERFLOW) | |
f461d2dc | 1887 | { |
cb8e59cc LT |
1888 | .procname = "panic_on_stackoverflow", |
1889 | .data = &sysctl_panic_on_stackoverflow, | |
f461d2dc CH |
1890 | .maxlen = sizeof(int), |
1891 | .mode = 0644, | |
1892 | .proc_handler = proc_dointvec, | |
1893 | }, | |
cb8e59cc LT |
1894 | #endif |
1895 | #if defined(CONFIG_X86) | |
f461d2dc | 1896 | { |
cb8e59cc LT |
1897 | .procname = "panic_on_unrecovered_nmi", |
1898 | .data = &panic_on_unrecovered_nmi, | |
f461d2dc CH |
1899 | .maxlen = sizeof(int), |
1900 | .mode = 0644, | |
1901 | .proc_handler = proc_dointvec, | |
1902 | }, | |
f461d2dc | 1903 | { |
cb8e59cc LT |
1904 | .procname = "panic_on_io_nmi", |
1905 | .data = &panic_on_io_nmi, | |
f461d2dc CH |
1906 | .maxlen = sizeof(int), |
1907 | .mode = 0644, | |
1908 | .proc_handler = proc_dointvec, | |
1909 | }, | |
f461d2dc CH |
1910 | { |
1911 | .procname = "bootloader_type", | |
1912 | .data = &bootloader_type, | |
1913 | .maxlen = sizeof (int), | |
1914 | .mode = 0444, | |
1915 | .proc_handler = proc_dointvec, | |
1916 | }, | |
1917 | { | |
1918 | .procname = "bootloader_version", | |
1919 | .data = &bootloader_version, | |
1920 | .maxlen = sizeof (int), | |
1921 | .mode = 0444, | |
1922 | .proc_handler = proc_dointvec, | |
1923 | }, | |
1924 | { | |
1925 | .procname = "io_delay_type", | |
1926 | .data = &io_delay_type, | |
1927 | .maxlen = sizeof(int), | |
1928 | .mode = 0644, | |
1929 | .proc_handler = proc_dointvec, | |
1930 | }, | |
1931 | #endif | |
1932 | #if defined(CONFIG_MMU) | |
1933 | { | |
1934 | .procname = "randomize_va_space", | |
1935 | .data = &randomize_va_space, | |
1936 | .maxlen = sizeof(int), | |
1937 | .mode = 0644, | |
1938 | .proc_handler = proc_dointvec, | |
1939 | }, | |
1940 | #endif | |
1941 | #if defined(CONFIG_S390) && defined(CONFIG_SMP) | |
1942 | { | |
1943 | .procname = "spin_retry", | |
1944 | .data = &spin_retry, | |
1945 | .maxlen = sizeof (int), | |
1946 | .mode = 0644, | |
1947 | .proc_handler = proc_dointvec, | |
1948 | }, | |
1949 | #endif | |
1950 | #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) | |
1951 | { | |
1952 | .procname = "acpi_video_flags", | |
1953 | .data = &acpi_realmode_flags, | |
1954 | .maxlen = sizeof (unsigned long), | |
1955 | .mode = 0644, | |
1956 | .proc_handler = proc_doulongvec_minmax, | |
1957 | }, | |
1958 | #endif | |
1959 | #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN | |
1960 | { | |
1961 | .procname = "ignore-unaligned-usertrap", | |
1962 | .data = &no_unaligned_warning, | |
1963 | .maxlen = sizeof (int), | |
1964 | .mode = 0644, | |
1965 | .proc_handler = proc_dointvec, | |
1966 | }, | |
1967 | #endif | |
1968 | #ifdef CONFIG_IA64 | |
1969 | { | |
1970 | .procname = "unaligned-dump-stack", | |
1971 | .data = &unaligned_dump_stack, | |
1972 | .maxlen = sizeof (int), | |
1973 | .mode = 0644, | |
1974 | .proc_handler = proc_dointvec, | |
1975 | }, | |
1976 | #endif | |
f461d2dc CH |
1977 | #ifdef CONFIG_RT_MUTEXES |
1978 | { | |
1979 | .procname = "max_lock_depth", | |
1980 | .data = &max_lock_depth, | |
1981 | .maxlen = sizeof(int), | |
1982 | .mode = 0644, | |
1983 | .proc_handler = proc_dointvec, | |
1984 | }, | |
1985 | #endif | |
f461d2dc CH |
1986 | #ifdef CONFIG_KEYS |
1987 | { | |
1988 | .procname = "keys", | |
1989 | .mode = 0555, | |
1990 | .child = key_sysctls, | |
1991 | }, | |
1992 | #endif | |
1993 | #ifdef CONFIG_PERF_EVENTS | |
1994 | /* | |
1995 | * User-space scripts rely on the existence of this file | |
1996 | * as a feature check for perf_events being enabled. | |
1997 | * | |
1998 | * So it's an ABI, do not remove! | |
1999 | */ | |
2000 | { | |
2001 | .procname = "perf_event_paranoid", | |
2002 | .data = &sysctl_perf_event_paranoid, | |
2003 | .maxlen = sizeof(sysctl_perf_event_paranoid), | |
2004 | .mode = 0644, | |
2005 | .proc_handler = proc_dointvec, | |
2006 | }, | |
2007 | { | |
2008 | .procname = "perf_event_mlock_kb", | |
2009 | .data = &sysctl_perf_event_mlock, | |
2010 | .maxlen = sizeof(sysctl_perf_event_mlock), | |
2011 | .mode = 0644, | |
2012 | .proc_handler = proc_dointvec, | |
2013 | }, | |
2014 | { | |
2015 | .procname = "perf_event_max_sample_rate", | |
2016 | .data = &sysctl_perf_event_sample_rate, | |
2017 | .maxlen = sizeof(sysctl_perf_event_sample_rate), | |
2018 | .mode = 0644, | |
2019 | .proc_handler = perf_proc_update_handler, | |
2020 | .extra1 = SYSCTL_ONE, | |
2021 | }, | |
2022 | { | |
2023 | .procname = "perf_cpu_time_max_percent", | |
2024 | .data = &sysctl_perf_cpu_time_max_percent, | |
2025 | .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), | |
2026 | .mode = 0644, | |
2027 | .proc_handler = perf_cpu_time_max_percent_handler, | |
2028 | .extra1 = SYSCTL_ZERO, | |
78e36f3b | 2029 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
2030 | }, |
2031 | { | |
2032 | .procname = "perf_event_max_stack", | |
2033 | .data = &sysctl_perf_event_max_stack, | |
2034 | .maxlen = sizeof(sysctl_perf_event_max_stack), | |
2035 | .mode = 0644, | |
2036 | .proc_handler = perf_event_max_stack_handler, | |
2037 | .extra1 = SYSCTL_ZERO, | |
d73840ec | 2038 | .extra2 = (void *)&six_hundred_forty_kb, |
f461d2dc CH |
2039 | }, |
2040 | { | |
2041 | .procname = "perf_event_max_contexts_per_stack", | |
2042 | .data = &sysctl_perf_event_max_contexts_per_stack, | |
2043 | .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), | |
2044 | .mode = 0644, | |
2045 | .proc_handler = perf_event_max_stack_handler, | |
2046 | .extra1 = SYSCTL_ZERO, | |
78e36f3b | 2047 | .extra2 = SYSCTL_ONE_THOUSAND, |
f461d2dc CH |
2048 | }, |
2049 | #endif | |
2050 | { | |
2051 | .procname = "panic_on_warn", | |
2052 | .data = &panic_on_warn, | |
2053 | .maxlen = sizeof(int), | |
2054 | .mode = 0644, | |
2055 | .proc_handler = proc_dointvec_minmax, | |
2056 | .extra1 = SYSCTL_ZERO, | |
2057 | .extra2 = SYSCTL_ONE, | |
2058 | }, | |
7251ceb5 | 2059 | #ifdef CONFIG_TREE_RCU |
f461d2dc CH |
2060 | { |
2061 | .procname = "panic_on_rcu_stall", | |
2062 | .data = &sysctl_panic_on_rcu_stall, | |
2063 | .maxlen = sizeof(sysctl_panic_on_rcu_stall), | |
2064 | .mode = 0644, | |
2065 | .proc_handler = proc_dointvec_minmax, | |
2066 | .extra1 = SYSCTL_ZERO, | |
2067 | .extra2 = SYSCTL_ONE, | |
2068 | }, | |
dfe56404 | 2069 | { |
2070 | .procname = "max_rcu_stall_to_panic", | |
2071 | .data = &sysctl_max_rcu_stall_to_panic, | |
2072 | .maxlen = sizeof(sysctl_max_rcu_stall_to_panic), | |
2073 | .mode = 0644, | |
2074 | .proc_handler = proc_dointvec_minmax, | |
2075 | .extra1 = SYSCTL_ONE, | |
2076 | .extra2 = SYSCTL_INT_MAX, | |
2077 | }, | |
f461d2dc CH |
2078 | #endif |
2079 | { } | |
2080 | }; | |
1da177e4 | 2081 | |
f461d2dc CH |
2082 | static struct ctl_table vm_table[] = { |
2083 | { | |
2084 | .procname = "overcommit_memory", | |
2085 | .data = &sysctl_overcommit_memory, | |
2086 | .maxlen = sizeof(sysctl_overcommit_memory), | |
2087 | .mode = 0644, | |
56f3547b | 2088 | .proc_handler = overcommit_policy_handler, |
f461d2dc | 2089 | .extra1 = SYSCTL_ZERO, |
78e36f3b | 2090 | .extra2 = SYSCTL_TWO, |
f461d2dc | 2091 | }, |
f461d2dc CH |
2092 | { |
2093 | .procname = "overcommit_ratio", | |
2094 | .data = &sysctl_overcommit_ratio, | |
2095 | .maxlen = sizeof(sysctl_overcommit_ratio), | |
2096 | .mode = 0644, | |
2097 | .proc_handler = overcommit_ratio_handler, | |
2098 | }, | |
2099 | { | |
2100 | .procname = "overcommit_kbytes", | |
2101 | .data = &sysctl_overcommit_kbytes, | |
2102 | .maxlen = sizeof(sysctl_overcommit_kbytes), | |
2103 | .mode = 0644, | |
2104 | .proc_handler = overcommit_kbytes_handler, | |
2105 | }, | |
2106 | { | |
2107 | .procname = "page-cluster", | |
2108 | .data = &page_cluster, | |
2109 | .maxlen = sizeof(int), | |
2110 | .mode = 0644, | |
2111 | .proc_handler = proc_dointvec_minmax, | |
2112 | .extra1 = SYSCTL_ZERO, | |
2113 | }, | |
f461d2dc CH |
2114 | { |
2115 | .procname = "dirtytime_expire_seconds", | |
2116 | .data = &dirtytime_expire_interval, | |
2117 | .maxlen = sizeof(dirtytime_expire_interval), | |
2118 | .mode = 0644, | |
2119 | .proc_handler = dirtytime_interval_handler, | |
2120 | .extra1 = SYSCTL_ZERO, | |
2121 | }, | |
2122 | { | |
2123 | .procname = "swappiness", | |
2124 | .data = &vm_swappiness, | |
2125 | .maxlen = sizeof(vm_swappiness), | |
2126 | .mode = 0644, | |
2127 | .proc_handler = proc_dointvec_minmax, | |
2128 | .extra1 = SYSCTL_ZERO, | |
78e36f3b | 2129 | .extra2 = SYSCTL_TWO_HUNDRED, |
f461d2dc | 2130 | }, |
43b5240c MS |
2131 | #ifdef CONFIG_NUMA |
2132 | { | |
2133 | .procname = "numa_stat", | |
2134 | .data = &sysctl_vm_numa_stat, | |
2135 | .maxlen = sizeof(int), | |
2136 | .mode = 0644, | |
2137 | .proc_handler = sysctl_vm_numa_stat_handler, | |
2138 | .extra1 = SYSCTL_ZERO, | |
2139 | .extra2 = SYSCTL_ONE, | |
2140 | }, | |
2141 | #endif | |
f461d2dc CH |
2142 | #ifdef CONFIG_HUGETLB_PAGE |
2143 | { | |
2144 | .procname = "nr_hugepages", | |
2145 | .data = NULL, | |
2146 | .maxlen = sizeof(unsigned long), | |
2147 | .mode = 0644, | |
2148 | .proc_handler = hugetlb_sysctl_handler, | |
2149 | }, | |
2150 | #ifdef CONFIG_NUMA | |
2151 | { | |
2152 | .procname = "nr_hugepages_mempolicy", | |
2153 | .data = NULL, | |
2154 | .maxlen = sizeof(unsigned long), | |
2155 | .mode = 0644, | |
2156 | .proc_handler = &hugetlb_mempolicy_sysctl_handler, | |
2157 | }, | |
f461d2dc CH |
2158 | #endif |
2159 | { | |
2160 | .procname = "hugetlb_shm_group", | |
2161 | .data = &sysctl_hugetlb_shm_group, | |
2162 | .maxlen = sizeof(gid_t), | |
2163 | .mode = 0644, | |
2164 | .proc_handler = proc_dointvec, | |
2165 | }, | |
2166 | { | |
2167 | .procname = "nr_overcommit_hugepages", | |
2168 | .data = NULL, | |
2169 | .maxlen = sizeof(unsigned long), | |
2170 | .mode = 0644, | |
2171 | .proc_handler = hugetlb_overcommit_handler, | |
2172 | }, | |
2173 | #endif | |
2174 | { | |
2175 | .procname = "lowmem_reserve_ratio", | |
2176 | .data = &sysctl_lowmem_reserve_ratio, | |
2177 | .maxlen = sizeof(sysctl_lowmem_reserve_ratio), | |
2178 | .mode = 0644, | |
2179 | .proc_handler = lowmem_reserve_ratio_sysctl_handler, | |
2180 | }, | |
2181 | { | |
2182 | .procname = "drop_caches", | |
2183 | .data = &sysctl_drop_caches, | |
2184 | .maxlen = sizeof(int), | |
2185 | .mode = 0200, | |
2186 | .proc_handler = drop_caches_sysctl_handler, | |
2187 | .extra1 = SYSCTL_ONE, | |
78e36f3b | 2188 | .extra2 = SYSCTL_FOUR, |
f461d2dc CH |
2189 | }, |
2190 | #ifdef CONFIG_COMPACTION | |
2191 | { | |
2192 | .procname = "compact_memory", | |
ef498438 | 2193 | .data = NULL, |
f461d2dc CH |
2194 | .maxlen = sizeof(int), |
2195 | .mode = 0200, | |
2196 | .proc_handler = sysctl_compaction_handler, | |
2197 | }, | |
facdaa91 NG |
2198 | { |
2199 | .procname = "compaction_proactiveness", | |
2200 | .data = &sysctl_compaction_proactiveness, | |
d34c0a75 | 2201 | .maxlen = sizeof(sysctl_compaction_proactiveness), |
facdaa91 | 2202 | .mode = 0644, |
65d759c8 | 2203 | .proc_handler = compaction_proactiveness_sysctl_handler, |
facdaa91 | 2204 | .extra1 = SYSCTL_ZERO, |
78e36f3b | 2205 | .extra2 = SYSCTL_ONE_HUNDRED, |
facdaa91 | 2206 | }, |
f461d2dc CH |
2207 | { |
2208 | .procname = "extfrag_threshold", | |
2209 | .data = &sysctl_extfrag_threshold, | |
2210 | .maxlen = sizeof(int), | |
2211 | .mode = 0644, | |
2212 | .proc_handler = proc_dointvec_minmax, | |
2452dcb9 | 2213 | .extra1 = SYSCTL_ZERO, |
feb2bd01 | 2214 | .extra2 = SYSCTL_ONE_THOUSAND, |
f461d2dc CH |
2215 | }, |
2216 | { | |
2217 | .procname = "compact_unevictable_allowed", | |
2218 | .data = &sysctl_compact_unevictable_allowed, | |
2219 | .maxlen = sizeof(int), | |
2220 | .mode = 0644, | |
2221 | .proc_handler = proc_dointvec_minmax_warn_RT_change, | |
2222 | .extra1 = SYSCTL_ZERO, | |
2223 | .extra2 = SYSCTL_ONE, | |
2224 | }, | |
1da177e4 | 2225 | |
f461d2dc CH |
2226 | #endif /* CONFIG_COMPACTION */ |
2227 | { | |
2228 | .procname = "min_free_kbytes", | |
2229 | .data = &min_free_kbytes, | |
2230 | .maxlen = sizeof(min_free_kbytes), | |
2231 | .mode = 0644, | |
2232 | .proc_handler = min_free_kbytes_sysctl_handler, | |
2233 | .extra1 = SYSCTL_ZERO, | |
2234 | }, | |
2235 | { | |
2236 | .procname = "watermark_boost_factor", | |
2237 | .data = &watermark_boost_factor, | |
2238 | .maxlen = sizeof(watermark_boost_factor), | |
2239 | .mode = 0644, | |
2240 | .proc_handler = proc_dointvec_minmax, | |
2241 | .extra1 = SYSCTL_ZERO, | |
2242 | }, | |
2243 | { | |
2244 | .procname = "watermark_scale_factor", | |
2245 | .data = &watermark_scale_factor, | |
2246 | .maxlen = sizeof(watermark_scale_factor), | |
2247 | .mode = 0644, | |
2248 | .proc_handler = watermark_scale_factor_sysctl_handler, | |
2249 | .extra1 = SYSCTL_ONE, | |
78e36f3b | 2250 | .extra2 = SYSCTL_THREE_THOUSAND, |
f461d2dc CH |
2251 | }, |
2252 | { | |
74f44822 MG |
2253 | .procname = "percpu_pagelist_high_fraction", |
2254 | .data = &percpu_pagelist_high_fraction, | |
2255 | .maxlen = sizeof(percpu_pagelist_high_fraction), | |
f461d2dc | 2256 | .mode = 0644, |
74f44822 | 2257 | .proc_handler = percpu_pagelist_high_fraction_sysctl_handler, |
f461d2dc CH |
2258 | .extra1 = SYSCTL_ZERO, |
2259 | }, | |
5ef64cc8 LT |
2260 | { |
2261 | .procname = "page_lock_unfairness", | |
2262 | .data = &sysctl_page_lock_unfairness, | |
2263 | .maxlen = sizeof(sysctl_page_lock_unfairness), | |
2264 | .mode = 0644, | |
2265 | .proc_handler = proc_dointvec_minmax, | |
2266 | .extra1 = SYSCTL_ZERO, | |
2267 | }, | |
f461d2dc CH |
2268 | #ifdef CONFIG_MMU |
2269 | { | |
2270 | .procname = "max_map_count", | |
2271 | .data = &sysctl_max_map_count, | |
2272 | .maxlen = sizeof(sysctl_max_map_count), | |
2273 | .mode = 0644, | |
2274 | .proc_handler = proc_dointvec_minmax, | |
2275 | .extra1 = SYSCTL_ZERO, | |
2276 | }, | |
2277 | #else | |
2278 | { | |
2279 | .procname = "nr_trim_pages", | |
2280 | .data = &sysctl_nr_trim_pages, | |
2281 | .maxlen = sizeof(sysctl_nr_trim_pages), | |
2282 | .mode = 0644, | |
2283 | .proc_handler = proc_dointvec_minmax, | |
2284 | .extra1 = SYSCTL_ZERO, | |
2285 | }, | |
2286 | #endif | |
f461d2dc CH |
2287 | { |
2288 | .procname = "vfs_cache_pressure", | |
2289 | .data = &sysctl_vfs_cache_pressure, | |
2290 | .maxlen = sizeof(sysctl_vfs_cache_pressure), | |
2291 | .mode = 0644, | |
3b3376f2 | 2292 | .proc_handler = proc_dointvec_minmax, |
f461d2dc CH |
2293 | .extra1 = SYSCTL_ZERO, |
2294 | }, | |
2295 | #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ | |
2296 | defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) | |
2297 | { | |
2298 | .procname = "legacy_va_layout", | |
2299 | .data = &sysctl_legacy_va_layout, | |
2300 | .maxlen = sizeof(sysctl_legacy_va_layout), | |
2301 | .mode = 0644, | |
3b3376f2 | 2302 | .proc_handler = proc_dointvec_minmax, |
f461d2dc CH |
2303 | .extra1 = SYSCTL_ZERO, |
2304 | }, | |
2305 | #endif | |
2306 | #ifdef CONFIG_NUMA | |
2307 | { | |
2308 | .procname = "zone_reclaim_mode", | |
2309 | .data = &node_reclaim_mode, | |
2310 | .maxlen = sizeof(node_reclaim_mode), | |
2311 | .mode = 0644, | |
3b3376f2 | 2312 | .proc_handler = proc_dointvec_minmax, |
f461d2dc CH |
2313 | .extra1 = SYSCTL_ZERO, |
2314 | }, | |
2315 | { | |
2316 | .procname = "min_unmapped_ratio", | |
2317 | .data = &sysctl_min_unmapped_ratio, | |
2318 | .maxlen = sizeof(sysctl_min_unmapped_ratio), | |
2319 | .mode = 0644, | |
2320 | .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, | |
2321 | .extra1 = SYSCTL_ZERO, | |
78e36f3b | 2322 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
2323 | }, |
2324 | { | |
2325 | .procname = "min_slab_ratio", | |
2326 | .data = &sysctl_min_slab_ratio, | |
2327 | .maxlen = sizeof(sysctl_min_slab_ratio), | |
2328 | .mode = 0644, | |
2329 | .proc_handler = sysctl_min_slab_ratio_sysctl_handler, | |
2330 | .extra1 = SYSCTL_ZERO, | |
78e36f3b | 2331 | .extra2 = SYSCTL_ONE_HUNDRED, |
f461d2dc CH |
2332 | }, |
2333 | #endif | |
2334 | #ifdef CONFIG_SMP | |
2335 | { | |
2336 | .procname = "stat_interval", | |
2337 | .data = &sysctl_stat_interval, | |
2338 | .maxlen = sizeof(sysctl_stat_interval), | |
2339 | .mode = 0644, | |
2340 | .proc_handler = proc_dointvec_jiffies, | |
2341 | }, | |
2342 | { | |
2343 | .procname = "stat_refresh", | |
2344 | .data = NULL, | |
2345 | .maxlen = 0, | |
2346 | .mode = 0600, | |
2347 | .proc_handler = vmstat_refresh, | |
2348 | }, | |
2349 | #endif | |
2350 | #ifdef CONFIG_MMU | |
2351 | { | |
2352 | .procname = "mmap_min_addr", | |
2353 | .data = &dac_mmap_min_addr, | |
2354 | .maxlen = sizeof(unsigned long), | |
2355 | .mode = 0644, | |
2356 | .proc_handler = mmap_min_addr_handler, | |
2357 | }, | |
2358 | #endif | |
2359 | #ifdef CONFIG_NUMA | |
2360 | { | |
2361 | .procname = "numa_zonelist_order", | |
2362 | .data = &numa_zonelist_order, | |
2363 | .maxlen = NUMA_ZONELIST_ORDER_LEN, | |
2364 | .mode = 0644, | |
2365 | .proc_handler = numa_zonelist_order_handler, | |
2366 | }, | |
2367 | #endif | |
2368 | #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ | |
2369 | (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) | |
2370 | { | |
2371 | .procname = "vdso_enabled", | |
2372 | #ifdef CONFIG_X86_32 | |
2373 | .data = &vdso32_enabled, | |
2374 | .maxlen = sizeof(vdso32_enabled), | |
2375 | #else | |
2376 | .data = &vdso_enabled, | |
2377 | .maxlen = sizeof(vdso_enabled), | |
2378 | #endif | |
2379 | .mode = 0644, | |
2380 | .proc_handler = proc_dointvec, | |
2381 | .extra1 = SYSCTL_ZERO, | |
2382 | }, | |
2383 | #endif | |
f461d2dc CH |
2384 | #ifdef CONFIG_MEMORY_FAILURE |
2385 | { | |
2386 | .procname = "memory_failure_early_kill", | |
2387 | .data = &sysctl_memory_failure_early_kill, | |
2388 | .maxlen = sizeof(sysctl_memory_failure_early_kill), | |
2389 | .mode = 0644, | |
2390 | .proc_handler = proc_dointvec_minmax, | |
2391 | .extra1 = SYSCTL_ZERO, | |
2392 | .extra2 = SYSCTL_ONE, | |
2393 | }, | |
2394 | { | |
2395 | .procname = "memory_failure_recovery", | |
2396 | .data = &sysctl_memory_failure_recovery, | |
2397 | .maxlen = sizeof(sysctl_memory_failure_recovery), | |
2398 | .mode = 0644, | |
2399 | .proc_handler = proc_dointvec_minmax, | |
2400 | .extra1 = SYSCTL_ZERO, | |
2401 | .extra2 = SYSCTL_ONE, | |
2402 | }, | |
2403 | #endif | |
2404 | { | |
2405 | .procname = "user_reserve_kbytes", | |
2406 | .data = &sysctl_user_reserve_kbytes, | |
2407 | .maxlen = sizeof(sysctl_user_reserve_kbytes), | |
2408 | .mode = 0644, | |
2409 | .proc_handler = proc_doulongvec_minmax, | |
2410 | }, | |
2411 | { | |
2412 | .procname = "admin_reserve_kbytes", | |
2413 | .data = &sysctl_admin_reserve_kbytes, | |
2414 | .maxlen = sizeof(sysctl_admin_reserve_kbytes), | |
2415 | .mode = 0644, | |
2416 | .proc_handler = proc_doulongvec_minmax, | |
2417 | }, | |
2418 | #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS | |
2419 | { | |
2420 | .procname = "mmap_rnd_bits", | |
2421 | .data = &mmap_rnd_bits, | |
2422 | .maxlen = sizeof(mmap_rnd_bits), | |
2423 | .mode = 0600, | |
2424 | .proc_handler = proc_dointvec_minmax, | |
2425 | .extra1 = (void *)&mmap_rnd_bits_min, | |
2426 | .extra2 = (void *)&mmap_rnd_bits_max, | |
2427 | }, | |
2428 | #endif | |
2429 | #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS | |
2430 | { | |
2431 | .procname = "mmap_rnd_compat_bits", | |
2432 | .data = &mmap_rnd_compat_bits, | |
2433 | .maxlen = sizeof(mmap_rnd_compat_bits), | |
2434 | .mode = 0600, | |
2435 | .proc_handler = proc_dointvec_minmax, | |
2436 | .extra1 = (void *)&mmap_rnd_compat_bits_min, | |
2437 | .extra2 = (void *)&mmap_rnd_compat_bits_max, | |
2438 | }, | |
2439 | #endif | |
2440 | #ifdef CONFIG_USERFAULTFD | |
2441 | { | |
2442 | .procname = "unprivileged_userfaultfd", | |
2443 | .data = &sysctl_unprivileged_userfaultfd, | |
2444 | .maxlen = sizeof(sysctl_unprivileged_userfaultfd), | |
2445 | .mode = 0644, | |
2446 | .proc_handler = proc_dointvec_minmax, | |
2447 | .extra1 = SYSCTL_ZERO, | |
2448 | .extra2 = SYSCTL_ONE, | |
2449 | }, | |
2450 | #endif | |
2451 | { } | |
2452 | }; | |
1da177e4 | 2453 | |
f461d2dc CH |
2454 | static struct ctl_table debug_table[] = { |
2455 | #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE | |
2456 | { | |
2457 | .procname = "exception-trace", | |
2458 | .data = &show_unhandled_signals, | |
2459 | .maxlen = sizeof(int), | |
2460 | .mode = 0644, | |
2461 | .proc_handler = proc_dointvec | |
2462 | }, | |
f461d2dc CH |
2463 | #endif |
2464 | { } | |
2465 | }; | |
1da177e4 | 2466 | |
f461d2dc CH |
2467 | static struct ctl_table dev_table[] = { |
2468 | { } | |
2469 | }; | |
1da177e4 | 2470 | |
51cb8dfc LC |
2471 | DECLARE_SYSCTL_BASE(kernel, kern_table); |
2472 | DECLARE_SYSCTL_BASE(vm, vm_table); | |
51cb8dfc LC |
2473 | DECLARE_SYSCTL_BASE(debug, debug_table); |
2474 | DECLARE_SYSCTL_BASE(dev, dev_table); | |
1da177e4 | 2475 | |
d8c0418a | 2476 | int __init sysctl_init_bases(void) |
492ecee8 | 2477 | { |
51cb8dfc LC |
2478 | register_sysctl_base(kernel); |
2479 | register_sysctl_base(vm); | |
51cb8dfc LC |
2480 | register_sysctl_base(debug); |
2481 | register_sysctl_base(dev); | |
492ecee8 | 2482 | |
f461d2dc | 2483 | return 0; |
492ecee8 | 2484 | } |
f461d2dc | 2485 | #endif /* CONFIG_SYSCTL */ |
1da177e4 LT |
2486 | /* |
2487 | * No sense putting this after each symbol definition, twice, | |
2488 | * exception granted :-) | |
2489 | */ | |
a2071573 | 2490 | EXPORT_SYMBOL(proc_dobool); |
1da177e4 | 2491 | EXPORT_SYMBOL(proc_dointvec); |
e7d316a0 | 2492 | EXPORT_SYMBOL(proc_douintvec); |
1da177e4 LT |
2493 | EXPORT_SYMBOL(proc_dointvec_jiffies); |
2494 | EXPORT_SYMBOL(proc_dointvec_minmax); | |
61d9b56a | 2495 | EXPORT_SYMBOL_GPL(proc_douintvec_minmax); |
1da177e4 LT |
2496 | EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); |
2497 | EXPORT_SYMBOL(proc_dointvec_ms_jiffies); | |
2498 | EXPORT_SYMBOL(proc_dostring); | |
2499 | EXPORT_SYMBOL(proc_doulongvec_minmax); | |
2500 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); | |
0bc19985 | 2501 | EXPORT_SYMBOL(proc_do_large_bitmap); |