mm: compaction: direct compact when a high-order allocation fails
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / sysctl.c
CommitLineData
1da177e4
LT
1/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
1da177e4
LT
21#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
d33ed52d 26#include <linux/signal.h>
1da177e4 27#include <linux/proc_fs.h>
72c2d582 28#include <linux/security.h>
1da177e4 29#include <linux/ctype.h>
dfec072e 30#include <linux/kmemcheck.h>
62239ac2 31#include <linux/fs.h>
1da177e4
LT
32#include <linux/init.h>
33#include <linux/kernel.h>
0296b228 34#include <linux/kobject.h>
20380731 35#include <linux/net.h>
1da177e4
LT
36#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
3fff4c42 39#include <linux/ratelimit.h>
76ab0f53 40#include <linux/compaction.h>
1da177e4 41#include <linux/hugetlb.h>
1da177e4 42#include <linux/initrd.h>
0b77f5bf 43#include <linux/key.h>
1da177e4
LT
44#include <linux/times.h>
45#include <linux/limits.h>
46#include <linux/dcache.h>
47#include <linux/syscalls.h>
c748e134 48#include <linux/vmstat.h>
c255d844
PM
49#include <linux/nfs_fs.h>
50#include <linux/acpi.h>
10a0a8d4 51#include <linux/reboot.h>
b0fc494f 52#include <linux/ftrace.h>
12e22c5e 53#include <linux/slow-work.h>
cdd6c482 54#include <linux/perf_event.h>
b2be84df 55#include <linux/kprobes.h>
b492e95b 56#include <linux/pipe_fs_i.h>
1da177e4
LT
57
58#include <asm/uaccess.h>
59#include <asm/processor.h>
60
29cbc78b
AK
61#ifdef CONFIG_X86
62#include <asm/nmi.h>
0741f4d2 63#include <asm/stacktrace.h>
6e7c4025 64#include <asm/io.h>
29cbc78b 65#endif
c55b7c3e
DY
66#ifdef CONFIG_BSD_PROCESS_ACCT
67#include <linux/acct.h>
68#endif
4f0e056f
DY
69#ifdef CONFIG_RT_MUTEXES
70#include <linux/rtmutex.h>
71#endif
2edf5e49
DY
72#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
73#include <linux/lockdep.h>
74#endif
15485a46
DY
75#ifdef CONFIG_CHR_DEV_SG
76#include <scsi/sg.h>
77#endif
29cbc78b 78
7058cb02 79
1da177e4
LT
80#if defined(CONFIG_SYSCTL)
81
82/* External variables not in a header file. */
1da177e4
LT
83extern int sysctl_overcommit_memory;
84extern int sysctl_overcommit_ratio;
fadd8fbd 85extern int sysctl_panic_on_oom;
fe071d7e 86extern int sysctl_oom_kill_allocating_task;
fef1bdd6 87extern int sysctl_oom_dump_tasks;
1da177e4 88extern int max_threads;
1da177e4 89extern int core_uses_pid;
d6e71144 90extern int suid_dumpable;
1da177e4 91extern char core_pattern[];
a293980c 92extern unsigned int core_pipe_limit;
1da177e4
LT
93extern int pid_max;
94extern int min_free_kbytes;
1da177e4 95extern int pid_max_min, pid_max_max;
9d0243bc 96extern int sysctl_drop_caches;
8ad4b1fb 97extern int percpu_pagelist_fraction;
bebfa101 98extern int compat_log;
9745512c 99extern int latencytop_enabled;
eceea0b3 100extern int sysctl_nr_open_min, sysctl_nr_open_max;
dd8632a1
PM
101#ifndef CONFIG_MMU
102extern int sysctl_nr_trim_pages;
103#endif
cb684b5b 104#ifdef CONFIG_BLOCK
5e605b64 105extern int blk_iopoll_enabled;
cb684b5b 106#endif
1da177e4 107
c4f3b63f 108/* Constants used for minimum and maximum */
195cf453 109#ifdef CONFIG_DETECT_SOFTLOCKUP
c4f3b63f 110static int sixty = 60;
9383d967 111static int neg_one = -1;
c4f3b63f
RT
112#endif
113
c4f3b63f 114static int zero;
cd5f9a4c
LT
115static int __maybe_unused one = 1;
116static int __maybe_unused two = 2;
fc3501d4 117static unsigned long one_ul = 1;
c4f3b63f 118static int one_hundred = 100;
af91322e
DY
119#ifdef CONFIG_PRINTK
120static int ten_thousand = 10000;
121#endif
c4f3b63f 122
9e4a5bda
AR
123/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
124static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
125
1da177e4
LT
126/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
127static int maxolduid = 65535;
128static int minolduid;
8ad4b1fb 129static int min_percpu_pagelist_fract = 8;
1da177e4
LT
130
131static int ngroups_max = NGROUPS_MAX;
132
72c57ed5 133#ifdef CONFIG_SPARC
17f04fbb 134#include <asm/system.h>
1da177e4
LT
135#endif
136
0871420f
DM
137#ifdef CONFIG_SPARC64
138extern int sysctl_tsb_ratio;
139#endif
140
1da177e4
LT
141#ifdef __hppa__
142extern int pwrsw_enabled;
143extern int unaligned_enabled;
144#endif
145
347a8dc3 146#ifdef CONFIG_S390
1da177e4
LT
147#ifdef CONFIG_MATHEMU
148extern int sysctl_ieee_emulation_warnings;
149#endif
150extern int sysctl_userprocess_debug;
951f22d5 151extern int spin_retry;
1da177e4
LT
152#endif
153
d2b176ed
JS
154#ifdef CONFIG_IA64
155extern int no_unaligned_warning;
88fc241f 156extern int unaligned_dump_stack;
d2b176ed
JS
157#endif
158
3fff4c42
IM
159extern struct ratelimit_state printk_ratelimit_state;
160
d6f8ff73 161#ifdef CONFIG_PROC_SYSCTL
8d65af78 162static int proc_do_cad_pid(struct ctl_table *table, int write,
9ec52099 163 void __user *buffer, size_t *lenp, loff_t *ppos);
8d65af78 164static int proc_taint(struct ctl_table *table, int write,
34f5a398 165 void __user *buffer, size_t *lenp, loff_t *ppos);
d6f8ff73 166#endif
9ec52099 167
97f5f0cd
DT
168#ifdef CONFIG_MAGIC_SYSRQ
169static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
170
171static int sysrq_sysctl_handler(ctl_table *table, int write,
172 void __user *buffer, size_t *lenp,
173 loff_t *ppos)
174{
175 int error;
176
177 error = proc_dointvec(table, write, buffer, lenp, ppos);
178 if (error)
179 return error;
180
181 if (write)
182 sysrq_toggle_support(__sysrq_enabled);
183
184 return 0;
185}
186
187#endif
188
d8217f07 189static struct ctl_table root_table[];
e51b6ba0
EB
190static struct ctl_table_root sysctl_table_root;
191static struct ctl_table_header root_table_header = {
b380b0d4 192 .count = 1,
e51b6ba0 193 .ctl_table = root_table,
73455092 194 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
e51b6ba0 195 .root = &sysctl_table_root,
73455092 196 .set = &sysctl_table_root.default_set,
e51b6ba0
EB
197};
198static struct ctl_table_root sysctl_table_root = {
199 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
73455092 200 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
e51b6ba0 201};
1da177e4 202
d8217f07
EB
203static struct ctl_table kern_table[];
204static struct ctl_table vm_table[];
205static struct ctl_table fs_table[];
206static struct ctl_table debug_table[];
207static struct ctl_table dev_table[];
208extern struct ctl_table random_table[];
2d9048e2 209#ifdef CONFIG_INOTIFY_USER
d8217f07 210extern struct ctl_table inotify_table[];
0399cb08 211#endif
7ef9964e
DL
212#ifdef CONFIG_EPOLL
213extern struct ctl_table epoll_table[];
214#endif
1da177e4
LT
215
216#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217int sysctl_legacy_va_layout;
218#endif
219
1da177e4
LT
220/* The default sysctl tables: */
221
d8217f07 222static struct ctl_table root_table[] = {
1da177e4 223 {
1da177e4
LT
224 .procname = "kernel",
225 .mode = 0555,
226 .child = kern_table,
227 },
228 {
1da177e4
LT
229 .procname = "vm",
230 .mode = 0555,
231 .child = vm_table,
232 },
1da177e4 233 {
1da177e4
LT
234 .procname = "fs",
235 .mode = 0555,
236 .child = fs_table,
237 },
238 {
1da177e4
LT
239 .procname = "debug",
240 .mode = 0555,
241 .child = debug_table,
242 },
243 {
1da177e4
LT
244 .procname = "dev",
245 .mode = 0555,
246 .child = dev_table,
247 },
2be7fe07
AM
248/*
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
251 */
6fce56ec 252 { }
1da177e4
LT
253};
254
77e54a1f 255#ifdef CONFIG_SCHED_DEBUG
73c4efd2
ED
256static int min_sched_granularity_ns = 100000; /* 100 usecs */
257static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
258static int min_wakeup_granularity_ns; /* 0 usecs */
259static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
1983a922
CE
260static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
acb4a848
CE
262static int min_sched_shares_ratelimit = 100000; /* 100 usec */
263static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
77e54a1f
IM
264#endif
265
d8217f07 266static struct ctl_table kern_table[] = {
2bba22c5 267 {
2bba22c5
MG
268 .procname = "sched_child_runs_first",
269 .data = &sysctl_sched_child_runs_first,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
6d456111 272 .proc_handler = proc_dointvec,
2bba22c5 273 },
77e54a1f
IM
274#ifdef CONFIG_SCHED_DEBUG
275 {
b2be5e96
PZ
276 .procname = "sched_min_granularity_ns",
277 .data = &sysctl_sched_min_granularity,
77e54a1f
IM
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
702a7c76 280 .proc_handler = sched_proc_update_handler,
b2be5e96
PZ
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
77e54a1f 283 },
21805085 284 {
21805085
PZ
285 .procname = "sched_latency_ns",
286 .data = &sysctl_sched_latency,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
702a7c76 289 .proc_handler = sched_proc_update_handler,
21805085
PZ
290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
292 },
77e54a1f 293 {
77e54a1f
IM
294 .procname = "sched_wakeup_granularity_ns",
295 .data = &sysctl_sched_wakeup_granularity,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
702a7c76 298 .proc_handler = sched_proc_update_handler,
77e54a1f
IM
299 .extra1 = &min_wakeup_granularity_ns,
300 .extra2 = &max_wakeup_granularity_ns,
301 },
2398f2c6 302 {
2398f2c6
PZ
303 .procname = "sched_shares_ratelimit",
304 .data = &sysctl_sched_shares_ratelimit,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
702a7c76 307 .proc_handler = sched_proc_update_handler,
acb4a848
CE
308 .extra1 = &min_sched_shares_ratelimit,
309 .extra2 = &max_sched_shares_ratelimit,
2398f2c6 310 },
1983a922 311 {
1983a922
CE
312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
315 .mode = 0644,
702a7c76 316 .proc_handler = sched_proc_update_handler,
1983a922
CE
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
2398f2c6 319 },
ffda12a1 320 {
ffda12a1
PZ
321 .procname = "sched_shares_thresh",
322 .data = &sysctl_sched_shares_thresh,
323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
6d456111 325 .proc_handler = proc_dointvec_minmax,
ffda12a1
PZ
326 .extra1 = &zero,
327 },
da84d961 328 {
da84d961
IM
329 .procname = "sched_migration_cost",
330 .data = &sysctl_sched_migration_cost,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
6d456111 333 .proc_handler = proc_dointvec,
da84d961 334 },
b82d9fdd 335 {
b82d9fdd
PZ
336 .procname = "sched_nr_migrate",
337 .data = &sysctl_sched_nr_migrate,
338 .maxlen = sizeof(unsigned int),
fa85ae24 339 .mode = 0644,
6d456111 340 .proc_handler = proc_dointvec,
fa85ae24 341 },
e9e9250b 342 {
e9e9250b
PZ
343 .procname = "sched_time_avg",
344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
6d456111 347 .proc_handler = proc_dointvec,
e9e9250b 348 },
cd1bb94b 349 {
cd1bb94b
AB
350 .procname = "timer_migration",
351 .data = &sysctl_timer_migration,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
6d456111 354 .proc_handler = proc_dointvec_minmax,
bfdb4d9f
AB
355 .extra1 = &zero,
356 .extra2 = &one,
fa85ae24 357 },
1fc84aaa 358#endif
9f0c1e56 359 {
9f0c1e56
PZ
360 .procname = "sched_rt_period_us",
361 .data = &sysctl_sched_rt_period,
362 .maxlen = sizeof(unsigned int),
363 .mode = 0644,
6d456111 364 .proc_handler = sched_rt_handler,
9f0c1e56
PZ
365 },
366 {
9f0c1e56
PZ
367 .procname = "sched_rt_runtime_us",
368 .data = &sysctl_sched_rt_runtime,
369 .maxlen = sizeof(int),
370 .mode = 0644,
6d456111 371 .proc_handler = sched_rt_handler,
9f0c1e56 372 },
1799e35d 373 {
1799e35d
IM
374 .procname = "sched_compat_yield",
375 .data = &sysctl_sched_compat_yield,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
6d456111 378 .proc_handler = proc_dointvec,
1799e35d 379 },
f20786ff
PZ
380#ifdef CONFIG_PROVE_LOCKING
381 {
f20786ff
PZ
382 .procname = "prove_locking",
383 .data = &prove_locking,
384 .maxlen = sizeof(int),
385 .mode = 0644,
6d456111 386 .proc_handler = proc_dointvec,
f20786ff
PZ
387 },
388#endif
389#ifdef CONFIG_LOCK_STAT
390 {
f20786ff
PZ
391 .procname = "lock_stat",
392 .data = &lock_stat,
393 .maxlen = sizeof(int),
394 .mode = 0644,
6d456111 395 .proc_handler = proc_dointvec,
f20786ff 396 },
77e54a1f 397#endif
1da177e4 398 {
1da177e4
LT
399 .procname = "panic",
400 .data = &panic_timeout,
401 .maxlen = sizeof(int),
402 .mode = 0644,
6d456111 403 .proc_handler = proc_dointvec,
1da177e4
LT
404 },
405 {
1da177e4
LT
406 .procname = "core_uses_pid",
407 .data = &core_uses_pid,
408 .maxlen = sizeof(int),
409 .mode = 0644,
6d456111 410 .proc_handler = proc_dointvec,
1da177e4
LT
411 },
412 {
1da177e4
LT
413 .procname = "core_pattern",
414 .data = core_pattern,
71ce92f3 415 .maxlen = CORENAME_MAX_SIZE,
1da177e4 416 .mode = 0644,
6d456111 417 .proc_handler = proc_dostring,
1da177e4 418 },
a293980c 419 {
a293980c
NH
420 .procname = "core_pipe_limit",
421 .data = &core_pipe_limit,
422 .maxlen = sizeof(unsigned int),
423 .mode = 0644,
6d456111 424 .proc_handler = proc_dointvec,
a293980c 425 },
34f5a398 426#ifdef CONFIG_PROC_SYSCTL
1da177e4 427 {
1da177e4 428 .procname = "tainted",
25ddbb18 429 .maxlen = sizeof(long),
34f5a398 430 .mode = 0644,
6d456111 431 .proc_handler = proc_taint,
1da177e4 432 },
34f5a398 433#endif
9745512c
AV
434#ifdef CONFIG_LATENCYTOP
435 {
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
439 .mode = 0644,
6d456111 440 .proc_handler = proc_dointvec,
9745512c
AV
441 },
442#endif
1da177e4
LT
443#ifdef CONFIG_BLK_DEV_INITRD
444 {
1da177e4
LT
445 .procname = "real-root-dev",
446 .data = &real_root_dev,
447 .maxlen = sizeof(int),
448 .mode = 0644,
6d456111 449 .proc_handler = proc_dointvec,
1da177e4
LT
450 },
451#endif
45807a1d 452 {
45807a1d
IM
453 .procname = "print-fatal-signals",
454 .data = &print_fatal_signals,
455 .maxlen = sizeof(int),
456 .mode = 0644,
6d456111 457 .proc_handler = proc_dointvec,
45807a1d 458 },
72c57ed5 459#ifdef CONFIG_SPARC
1da177e4 460 {
1da177e4
LT
461 .procname = "reboot-cmd",
462 .data = reboot_command,
463 .maxlen = 256,
464 .mode = 0644,
6d456111 465 .proc_handler = proc_dostring,
1da177e4
LT
466 },
467 {
1da177e4
LT
468 .procname = "stop-a",
469 .data = &stop_a_enabled,
470 .maxlen = sizeof (int),
471 .mode = 0644,
6d456111 472 .proc_handler = proc_dointvec,
1da177e4
LT
473 },
474 {
1da177e4
LT
475 .procname = "scons-poweroff",
476 .data = &scons_pwroff,
477 .maxlen = sizeof (int),
478 .mode = 0644,
6d456111 479 .proc_handler = proc_dointvec,
1da177e4
LT
480 },
481#endif
0871420f
DM
482#ifdef CONFIG_SPARC64
483 {
0871420f
DM
484 .procname = "tsb-ratio",
485 .data = &sysctl_tsb_ratio,
486 .maxlen = sizeof (int),
487 .mode = 0644,
6d456111 488 .proc_handler = proc_dointvec,
0871420f
DM
489 },
490#endif
1da177e4
LT
491#ifdef __hppa__
492 {
1da177e4
LT
493 .procname = "soft-power",
494 .data = &pwrsw_enabled,
495 .maxlen = sizeof (int),
496 .mode = 0644,
6d456111 497 .proc_handler = proc_dointvec,
1da177e4
LT
498 },
499 {
1da177e4
LT
500 .procname = "unaligned-trap",
501 .data = &unaligned_enabled,
502 .maxlen = sizeof (int),
503 .mode = 0644,
6d456111 504 .proc_handler = proc_dointvec,
1da177e4
LT
505 },
506#endif
507 {
1da177e4
LT
508 .procname = "ctrl-alt-del",
509 .data = &C_A_D,
510 .maxlen = sizeof(int),
511 .mode = 0644,
6d456111 512 .proc_handler = proc_dointvec,
1da177e4 513 },
606576ce 514#ifdef CONFIG_FUNCTION_TRACER
b0fc494f 515 {
b0fc494f
SR
516 .procname = "ftrace_enabled",
517 .data = &ftrace_enabled,
518 .maxlen = sizeof(int),
519 .mode = 0644,
6d456111 520 .proc_handler = ftrace_enable_sysctl,
b0fc494f
SR
521 },
522#endif
f38f1d2a
SR
523#ifdef CONFIG_STACK_TRACER
524 {
f38f1d2a
SR
525 .procname = "stack_tracer_enabled",
526 .data = &stack_tracer_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
6d456111 529 .proc_handler = stack_trace_sysctl,
f38f1d2a
SR
530 },
531#endif
944ac425
SR
532#ifdef CONFIG_TRACING
533 {
3299b4dd 534 .procname = "ftrace_dump_on_oops",
944ac425
SR
535 .data = &ftrace_dump_on_oops,
536 .maxlen = sizeof(int),
537 .mode = 0644,
6d456111 538 .proc_handler = proc_dointvec,
944ac425
SR
539 },
540#endif
a1ef5adb 541#ifdef CONFIG_MODULES
1da177e4 542 {
1da177e4
LT
543 .procname = "modprobe",
544 .data = &modprobe_path,
545 .maxlen = KMOD_PATH_LEN,
546 .mode = 0644,
6d456111 547 .proc_handler = proc_dostring,
1da177e4 548 },
3d43321b 549 {
3d43321b
KC
550 .procname = "modules_disabled",
551 .data = &modules_disabled,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 /* only handle a transition from default "0" to "1" */
6d456111 555 .proc_handler = proc_dointvec_minmax,
3d43321b
KC
556 .extra1 = &one,
557 .extra2 = &one,
558 },
1da177e4 559#endif
57ae2508 560#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
1da177e4 561 {
1da177e4 562 .procname = "hotplug",
312c004d
KS
563 .data = &uevent_helper,
564 .maxlen = UEVENT_HELPER_PATH_LEN,
1da177e4 565 .mode = 0644,
6d456111 566 .proc_handler = proc_dostring,
1da177e4
LT
567 },
568#endif
569#ifdef CONFIG_CHR_DEV_SG
570 {
1da177e4
LT
571 .procname = "sg-big-buff",
572 .data = &sg_big_buff,
573 .maxlen = sizeof (int),
574 .mode = 0444,
6d456111 575 .proc_handler = proc_dointvec,
1da177e4
LT
576 },
577#endif
578#ifdef CONFIG_BSD_PROCESS_ACCT
579 {
1da177e4
LT
580 .procname = "acct",
581 .data = &acct_parm,
582 .maxlen = 3*sizeof(int),
583 .mode = 0644,
6d456111 584 .proc_handler = proc_dointvec,
1da177e4
LT
585 },
586#endif
1da177e4
LT
587#ifdef CONFIG_MAGIC_SYSRQ
588 {
1da177e4 589 .procname = "sysrq",
5d6f647f 590 .data = &__sysrq_enabled,
1da177e4
LT
591 .maxlen = sizeof (int),
592 .mode = 0644,
97f5f0cd 593 .proc_handler = sysrq_sysctl_handler,
1da177e4
LT
594 },
595#endif
d6f8ff73 596#ifdef CONFIG_PROC_SYSCTL
1da177e4 597 {
1da177e4 598 .procname = "cad_pid",
9ec52099 599 .data = NULL,
1da177e4
LT
600 .maxlen = sizeof (int),
601 .mode = 0600,
6d456111 602 .proc_handler = proc_do_cad_pid,
1da177e4 603 },
d6f8ff73 604#endif
1da177e4 605 {
1da177e4
LT
606 .procname = "threads-max",
607 .data = &max_threads,
608 .maxlen = sizeof(int),
609 .mode = 0644,
6d456111 610 .proc_handler = proc_dointvec,
1da177e4
LT
611 },
612 {
1da177e4
LT
613 .procname = "random",
614 .mode = 0555,
615 .child = random_table,
616 },
1da177e4 617 {
1da177e4
LT
618 .procname = "overflowuid",
619 .data = &overflowuid,
620 .maxlen = sizeof(int),
621 .mode = 0644,
6d456111 622 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
623 .extra1 = &minolduid,
624 .extra2 = &maxolduid,
625 },
626 {
1da177e4
LT
627 .procname = "overflowgid",
628 .data = &overflowgid,
629 .maxlen = sizeof(int),
630 .mode = 0644,
6d456111 631 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
634 },
347a8dc3 635#ifdef CONFIG_S390
1da177e4
LT
636#ifdef CONFIG_MATHEMU
637 {
1da177e4
LT
638 .procname = "ieee_emulation_warnings",
639 .data = &sysctl_ieee_emulation_warnings,
640 .maxlen = sizeof(int),
641 .mode = 0644,
6d456111 642 .proc_handler = proc_dointvec,
1da177e4 643 },
1da177e4
LT
644#endif
645 {
1da177e4 646 .procname = "userprocess_debug",
ab3c68ee 647 .data = &show_unhandled_signals,
1da177e4
LT
648 .maxlen = sizeof(int),
649 .mode = 0644,
6d456111 650 .proc_handler = proc_dointvec,
1da177e4
LT
651 },
652#endif
653 {
1da177e4
LT
654 .procname = "pid_max",
655 .data = &pid_max,
656 .maxlen = sizeof (int),
657 .mode = 0644,
6d456111 658 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
659 .extra1 = &pid_max_min,
660 .extra2 = &pid_max_max,
661 },
662 {
1da177e4
LT
663 .procname = "panic_on_oops",
664 .data = &panic_on_oops,
665 .maxlen = sizeof(int),
666 .mode = 0644,
6d456111 667 .proc_handler = proc_dointvec,
1da177e4 668 },
7ef3d2fd
JP
669#if defined CONFIG_PRINTK
670 {
7ef3d2fd
JP
671 .procname = "printk",
672 .data = &console_loglevel,
673 .maxlen = 4*sizeof(int),
674 .mode = 0644,
6d456111 675 .proc_handler = proc_dointvec,
7ef3d2fd 676 },
1da177e4 677 {
1da177e4 678 .procname = "printk_ratelimit",
717115e1 679 .data = &printk_ratelimit_state.interval,
1da177e4
LT
680 .maxlen = sizeof(int),
681 .mode = 0644,
6d456111 682 .proc_handler = proc_dointvec_jiffies,
1da177e4
LT
683 },
684 {
1da177e4 685 .procname = "printk_ratelimit_burst",
717115e1 686 .data = &printk_ratelimit_state.burst,
1da177e4
LT
687 .maxlen = sizeof(int),
688 .mode = 0644,
6d456111 689 .proc_handler = proc_dointvec,
1da177e4 690 },
af91322e 691 {
af91322e
DY
692 .procname = "printk_delay",
693 .data = &printk_delay_msec,
694 .maxlen = sizeof(int),
695 .mode = 0644,
6d456111 696 .proc_handler = proc_dointvec_minmax,
af91322e
DY
697 .extra1 = &zero,
698 .extra2 = &ten_thousand,
699 },
7ef3d2fd 700#endif
1da177e4 701 {
1da177e4
LT
702 .procname = "ngroups_max",
703 .data = &ngroups_max,
704 .maxlen = sizeof (int),
705 .mode = 0444,
6d456111 706 .proc_handler = proc_dointvec,
1da177e4
LT
707 },
708#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
709 {
1da177e4
LT
710 .procname = "unknown_nmi_panic",
711 .data = &unknown_nmi_panic,
712 .maxlen = sizeof (int),
713 .mode = 0644,
6d456111 714 .proc_handler = proc_dointvec,
1da177e4 715 },
407984f1 716 {
407984f1
DZ
717 .procname = "nmi_watchdog",
718 .data = &nmi_watchdog_enabled,
719 .maxlen = sizeof (int),
720 .mode = 0644,
6d456111 721 .proc_handler = proc_nmi_enabled,
1da177e4
LT
722 },
723#endif
724#if defined(CONFIG_X86)
8da5adda 725 {
8da5adda
DZ
726 .procname = "panic_on_unrecovered_nmi",
727 .data = &panic_on_unrecovered_nmi,
728 .maxlen = sizeof(int),
729 .mode = 0644,
6d456111 730 .proc_handler = proc_dointvec,
8da5adda 731 },
5211a242 732 {
5211a242
KG
733 .procname = "panic_on_io_nmi",
734 .data = &panic_on_io_nmi,
735 .maxlen = sizeof(int),
736 .mode = 0644,
6d456111 737 .proc_handler = proc_dointvec,
5211a242 738 },
1da177e4 739 {
1da177e4
LT
740 .procname = "bootloader_type",
741 .data = &bootloader_type,
742 .maxlen = sizeof (int),
743 .mode = 0444,
6d456111 744 .proc_handler = proc_dointvec,
1da177e4 745 },
5031296c 746 {
5031296c
PA
747 .procname = "bootloader_version",
748 .data = &bootloader_version,
749 .maxlen = sizeof (int),
750 .mode = 0444,
6d456111 751 .proc_handler = proc_dointvec,
5031296c 752 },
0741f4d2 753 {
0741f4d2
CE
754 .procname = "kstack_depth_to_print",
755 .data = &kstack_depth_to_print,
756 .maxlen = sizeof(int),
757 .mode = 0644,
6d456111 758 .proc_handler = proc_dointvec,
0741f4d2 759 },
6e7c4025 760 {
6e7c4025
IM
761 .procname = "io_delay_type",
762 .data = &io_delay_type,
763 .maxlen = sizeof(int),
764 .mode = 0644,
6d456111 765 .proc_handler = proc_dointvec,
6e7c4025 766 },
1da177e4 767#endif
7a9166e3 768#if defined(CONFIG_MMU)
1da177e4 769 {
1da177e4
LT
770 .procname = "randomize_va_space",
771 .data = &randomize_va_space,
772 .maxlen = sizeof(int),
773 .mode = 0644,
6d456111 774 .proc_handler = proc_dointvec,
1da177e4 775 },
7a9166e3 776#endif
0152fb37 777#if defined(CONFIG_S390) && defined(CONFIG_SMP)
951f22d5 778 {
951f22d5
MS
779 .procname = "spin_retry",
780 .data = &spin_retry,
781 .maxlen = sizeof (int),
782 .mode = 0644,
6d456111 783 .proc_handler = proc_dointvec,
951f22d5 784 },
c255d844 785#endif
673d5b43 786#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
c255d844 787 {
c255d844 788 .procname = "acpi_video_flags",
77afcf78 789 .data = &acpi_realmode_flags,
c255d844
PM
790 .maxlen = sizeof (unsigned long),
791 .mode = 0644,
6d456111 792 .proc_handler = proc_doulongvec_minmax,
c255d844 793 },
d2b176ed
JS
794#endif
795#ifdef CONFIG_IA64
796 {
d2b176ed
JS
797 .procname = "ignore-unaligned-usertrap",
798 .data = &no_unaligned_warning,
799 .maxlen = sizeof (int),
800 .mode = 0644,
6d456111 801 .proc_handler = proc_dointvec,
d2b176ed 802 },
88fc241f 803 {
88fc241f
DC
804 .procname = "unaligned-dump-stack",
805 .data = &unaligned_dump_stack,
806 .maxlen = sizeof (int),
807 .mode = 0644,
6d456111 808 .proc_handler = proc_dointvec,
88fc241f 809 },
bebfa101 810#endif
c4f3b63f 811#ifdef CONFIG_DETECT_SOFTLOCKUP
9c44bc03 812 {
9c44bc03
IM
813 .procname = "softlockup_panic",
814 .data = &softlockup_panic,
815 .maxlen = sizeof(int),
816 .mode = 0644,
6d456111 817 .proc_handler = proc_dointvec_minmax,
9c44bc03
IM
818 .extra1 = &zero,
819 .extra2 = &one,
820 },
c4f3b63f 821 {
c4f3b63f
RT
822 .procname = "softlockup_thresh",
823 .data = &softlockup_thresh,
9383d967 824 .maxlen = sizeof(int),
c4f3b63f 825 .mode = 0644,
6d456111 826 .proc_handler = proc_dosoftlockup_thresh,
9383d967 827 .extra1 = &neg_one,
c4f3b63f
RT
828 .extra2 = &sixty,
829 },
e162b39a
MSB
830#endif
831#ifdef CONFIG_DETECT_HUNG_TASK
832 {
e162b39a
MSB
833 .procname = "hung_task_panic",
834 .data = &sysctl_hung_task_panic,
835 .maxlen = sizeof(int),
836 .mode = 0644,
6d456111 837 .proc_handler = proc_dointvec_minmax,
e162b39a
MSB
838 .extra1 = &zero,
839 .extra2 = &one,
840 },
82a1fcb9 841 {
82a1fcb9
IM
842 .procname = "hung_task_check_count",
843 .data = &sysctl_hung_task_check_count,
90739081 844 .maxlen = sizeof(unsigned long),
82a1fcb9 845 .mode = 0644,
6d456111 846 .proc_handler = proc_doulongvec_minmax,
82a1fcb9
IM
847 },
848 {
82a1fcb9
IM
849 .procname = "hung_task_timeout_secs",
850 .data = &sysctl_hung_task_timeout_secs,
90739081 851 .maxlen = sizeof(unsigned long),
82a1fcb9 852 .mode = 0644,
6d456111 853 .proc_handler = proc_dohung_task_timeout_secs,
82a1fcb9
IM
854 },
855 {
82a1fcb9
IM
856 .procname = "hung_task_warnings",
857 .data = &sysctl_hung_task_warnings,
90739081 858 .maxlen = sizeof(unsigned long),
82a1fcb9 859 .mode = 0644,
6d456111 860 .proc_handler = proc_doulongvec_minmax,
82a1fcb9 861 },
c4f3b63f 862#endif
bebfa101
AK
863#ifdef CONFIG_COMPAT
864 {
bebfa101
AK
865 .procname = "compat-log",
866 .data = &compat_log,
867 .maxlen = sizeof (int),
868 .mode = 0644,
6d456111 869 .proc_handler = proc_dointvec,
bebfa101 870 },
951f22d5 871#endif
23f78d4a
IM
872#ifdef CONFIG_RT_MUTEXES
873 {
23f78d4a
IM
874 .procname = "max_lock_depth",
875 .data = &max_lock_depth,
876 .maxlen = sizeof(int),
877 .mode = 0644,
6d456111 878 .proc_handler = proc_dointvec,
23f78d4a 879 },
5096add8 880#endif
10a0a8d4 881 {
10a0a8d4
JF
882 .procname = "poweroff_cmd",
883 .data = &poweroff_cmd,
884 .maxlen = POWEROFF_CMD_PATH_LEN,
885 .mode = 0644,
6d456111 886 .proc_handler = proc_dostring,
10a0a8d4 887 },
0b77f5bf
DH
888#ifdef CONFIG_KEYS
889 {
0b77f5bf
DH
890 .procname = "keys",
891 .mode = 0555,
892 .child = key_sysctls,
893 },
894#endif
31a72bce
PM
895#ifdef CONFIG_RCU_TORTURE_TEST
896 {
31a72bce
PM
897 .procname = "rcutorture_runnable",
898 .data = &rcutorture_runnable,
899 .maxlen = sizeof(int),
900 .mode = 0644,
6d456111 901 .proc_handler = proc_dointvec,
31a72bce
PM
902 },
903#endif
12e22c5e
DH
904#ifdef CONFIG_SLOW_WORK
905 {
12e22c5e
DH
906 .procname = "slow-work",
907 .mode = 0555,
908 .child = slow_work_sysctls,
909 },
910#endif
cdd6c482 911#ifdef CONFIG_PERF_EVENTS
1ccd1549 912 {
cdd6c482
IM
913 .procname = "perf_event_paranoid",
914 .data = &sysctl_perf_event_paranoid,
915 .maxlen = sizeof(sysctl_perf_event_paranoid),
1ccd1549 916 .mode = 0644,
6d456111 917 .proc_handler = proc_dointvec,
1ccd1549 918 },
c5078f78 919 {
cdd6c482
IM
920 .procname = "perf_event_mlock_kb",
921 .data = &sysctl_perf_event_mlock,
922 .maxlen = sizeof(sysctl_perf_event_mlock),
c5078f78 923 .mode = 0644,
6d456111 924 .proc_handler = proc_dointvec,
c5078f78 925 },
a78ac325 926 {
cdd6c482
IM
927 .procname = "perf_event_max_sample_rate",
928 .data = &sysctl_perf_event_sample_rate,
929 .maxlen = sizeof(sysctl_perf_event_sample_rate),
a78ac325 930 .mode = 0644,
6d456111 931 .proc_handler = proc_dointvec,
a78ac325 932 },
1ccd1549 933#endif
dfec072e
VN
934#ifdef CONFIG_KMEMCHECK
935 {
dfec072e
VN
936 .procname = "kmemcheck",
937 .data = &kmemcheck_enabled,
938 .maxlen = sizeof(int),
939 .mode = 0644,
6d456111 940 .proc_handler = proc_dointvec,
dfec072e
VN
941 },
942#endif
cb684b5b 943#ifdef CONFIG_BLOCK
5e605b64 944 {
5e605b64
JA
945 .procname = "blk_iopoll",
946 .data = &blk_iopoll_enabled,
947 .maxlen = sizeof(int),
948 .mode = 0644,
6d456111 949 .proc_handler = proc_dointvec,
5e605b64 950 },
cb684b5b 951#endif
ed2c12f3
AM
952/*
953 * NOTE: do not add new entries to this table unless you have read
954 * Documentation/sysctl/ctl_unnumbered.txt
955 */
6fce56ec 956 { }
1da177e4
LT
957};
958
d8217f07 959static struct ctl_table vm_table[] = {
1da177e4 960 {
1da177e4
LT
961 .procname = "overcommit_memory",
962 .data = &sysctl_overcommit_memory,
963 .maxlen = sizeof(sysctl_overcommit_memory),
964 .mode = 0644,
6d456111 965 .proc_handler = proc_dointvec,
1da177e4 966 },
fadd8fbd 967 {
fadd8fbd
KH
968 .procname = "panic_on_oom",
969 .data = &sysctl_panic_on_oom,
970 .maxlen = sizeof(sysctl_panic_on_oom),
971 .mode = 0644,
6d456111 972 .proc_handler = proc_dointvec,
fadd8fbd 973 },
fe071d7e 974 {
fe071d7e
DR
975 .procname = "oom_kill_allocating_task",
976 .data = &sysctl_oom_kill_allocating_task,
977 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
978 .mode = 0644,
6d456111 979 .proc_handler = proc_dointvec,
fe071d7e 980 },
fef1bdd6 981 {
fef1bdd6
DR
982 .procname = "oom_dump_tasks",
983 .data = &sysctl_oom_dump_tasks,
984 .maxlen = sizeof(sysctl_oom_dump_tasks),
985 .mode = 0644,
6d456111 986 .proc_handler = proc_dointvec,
fef1bdd6 987 },
1da177e4 988 {
1da177e4
LT
989 .procname = "overcommit_ratio",
990 .data = &sysctl_overcommit_ratio,
991 .maxlen = sizeof(sysctl_overcommit_ratio),
992 .mode = 0644,
6d456111 993 .proc_handler = proc_dointvec,
1da177e4
LT
994 },
995 {
1da177e4
LT
996 .procname = "page-cluster",
997 .data = &page_cluster,
998 .maxlen = sizeof(int),
999 .mode = 0644,
6d456111 1000 .proc_handler = proc_dointvec,
1da177e4
LT
1001 },
1002 {
1da177e4
LT
1003 .procname = "dirty_background_ratio",
1004 .data = &dirty_background_ratio,
1005 .maxlen = sizeof(dirty_background_ratio),
1006 .mode = 0644,
6d456111 1007 .proc_handler = dirty_background_ratio_handler,
1da177e4
LT
1008 .extra1 = &zero,
1009 .extra2 = &one_hundred,
1010 },
2da02997 1011 {
2da02997
DR
1012 .procname = "dirty_background_bytes",
1013 .data = &dirty_background_bytes,
1014 .maxlen = sizeof(dirty_background_bytes),
1015 .mode = 0644,
6d456111 1016 .proc_handler = dirty_background_bytes_handler,
fc3501d4 1017 .extra1 = &one_ul,
2da02997 1018 },
1da177e4 1019 {
1da177e4
LT
1020 .procname = "dirty_ratio",
1021 .data = &vm_dirty_ratio,
1022 .maxlen = sizeof(vm_dirty_ratio),
1023 .mode = 0644,
6d456111 1024 .proc_handler = dirty_ratio_handler,
1da177e4
LT
1025 .extra1 = &zero,
1026 .extra2 = &one_hundred,
1027 },
2da02997 1028 {
2da02997
DR
1029 .procname = "dirty_bytes",
1030 .data = &vm_dirty_bytes,
1031 .maxlen = sizeof(vm_dirty_bytes),
1032 .mode = 0644,
6d456111 1033 .proc_handler = dirty_bytes_handler,
9e4a5bda 1034 .extra1 = &dirty_bytes_min,
2da02997 1035 },
1da177e4 1036 {
1da177e4 1037 .procname = "dirty_writeback_centisecs",
f6ef9438
BS
1038 .data = &dirty_writeback_interval,
1039 .maxlen = sizeof(dirty_writeback_interval),
1da177e4 1040 .mode = 0644,
6d456111 1041 .proc_handler = dirty_writeback_centisecs_handler,
1da177e4
LT
1042 },
1043 {
1da177e4 1044 .procname = "dirty_expire_centisecs",
f6ef9438
BS
1045 .data = &dirty_expire_interval,
1046 .maxlen = sizeof(dirty_expire_interval),
1da177e4 1047 .mode = 0644,
6d456111 1048 .proc_handler = proc_dointvec,
1da177e4
LT
1049 },
1050 {
1da177e4
LT
1051 .procname = "nr_pdflush_threads",
1052 .data = &nr_pdflush_threads,
1053 .maxlen = sizeof nr_pdflush_threads,
1054 .mode = 0444 /* read-only*/,
6d456111 1055 .proc_handler = proc_dointvec,
1da177e4
LT
1056 },
1057 {
1da177e4
LT
1058 .procname = "swappiness",
1059 .data = &vm_swappiness,
1060 .maxlen = sizeof(vm_swappiness),
1061 .mode = 0644,
6d456111 1062 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1063 .extra1 = &zero,
1064 .extra2 = &one_hundred,
1065 },
1066#ifdef CONFIG_HUGETLB_PAGE
06808b08 1067 {
1da177e4 1068 .procname = "nr_hugepages",
e5ff2159 1069 .data = NULL,
1da177e4
LT
1070 .maxlen = sizeof(unsigned long),
1071 .mode = 0644,
6d456111 1072 .proc_handler = hugetlb_sysctl_handler,
1da177e4
LT
1073 .extra1 = (void *)&hugetlb_zero,
1074 .extra2 = (void *)&hugetlb_infinity,
06808b08
LS
1075 },
1076#ifdef CONFIG_NUMA
1077 {
1078 .procname = "nr_hugepages_mempolicy",
1079 .data = NULL,
1080 .maxlen = sizeof(unsigned long),
1081 .mode = 0644,
1082 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1083 .extra1 = (void *)&hugetlb_zero,
1084 .extra2 = (void *)&hugetlb_infinity,
1085 },
1086#endif
1da177e4 1087 {
1da177e4
LT
1088 .procname = "hugetlb_shm_group",
1089 .data = &sysctl_hugetlb_shm_group,
1090 .maxlen = sizeof(gid_t),
1091 .mode = 0644,
6d456111 1092 .proc_handler = proc_dointvec,
1da177e4 1093 },
396faf03 1094 {
396faf03
MG
1095 .procname = "hugepages_treat_as_movable",
1096 .data = &hugepages_treat_as_movable,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
6d456111 1099 .proc_handler = hugetlb_treat_movable_handler,
396faf03 1100 },
d1c3fb1f 1101 {
d1c3fb1f 1102 .procname = "nr_overcommit_hugepages",
e5ff2159
AK
1103 .data = NULL,
1104 .maxlen = sizeof(unsigned long),
d1c3fb1f 1105 .mode = 0644,
6d456111 1106 .proc_handler = hugetlb_overcommit_handler,
e5ff2159
AK
1107 .extra1 = (void *)&hugetlb_zero,
1108 .extra2 = (void *)&hugetlb_infinity,
d1c3fb1f 1109 },
1da177e4
LT
1110#endif
1111 {
1da177e4
LT
1112 .procname = "lowmem_reserve_ratio",
1113 .data = &sysctl_lowmem_reserve_ratio,
1114 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1115 .mode = 0644,
6d456111 1116 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1da177e4 1117 },
9d0243bc 1118 {
9d0243bc
AM
1119 .procname = "drop_caches",
1120 .data = &sysctl_drop_caches,
1121 .maxlen = sizeof(int),
1122 .mode = 0644,
1123 .proc_handler = drop_caches_sysctl_handler,
9d0243bc 1124 },
76ab0f53
MG
1125#ifdef CONFIG_COMPACTION
1126 {
1127 .procname = "compact_memory",
1128 .data = &sysctl_compact_memory,
1129 .maxlen = sizeof(int),
1130 .mode = 0200,
1131 .proc_handler = sysctl_compaction_handler,
1132 },
1133#endif /* CONFIG_COMPACTION */
1da177e4 1134 {
1da177e4
LT
1135 .procname = "min_free_kbytes",
1136 .data = &min_free_kbytes,
1137 .maxlen = sizeof(min_free_kbytes),
1138 .mode = 0644,
6d456111 1139 .proc_handler = min_free_kbytes_sysctl_handler,
1da177e4
LT
1140 .extra1 = &zero,
1141 },
8ad4b1fb 1142 {
8ad4b1fb
RS
1143 .procname = "percpu_pagelist_fraction",
1144 .data = &percpu_pagelist_fraction,
1145 .maxlen = sizeof(percpu_pagelist_fraction),
1146 .mode = 0644,
6d456111 1147 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
8ad4b1fb
RS
1148 .extra1 = &min_percpu_pagelist_fract,
1149 },
1da177e4
LT
1150#ifdef CONFIG_MMU
1151 {
1da177e4
LT
1152 .procname = "max_map_count",
1153 .data = &sysctl_max_map_count,
1154 .maxlen = sizeof(sysctl_max_map_count),
1155 .mode = 0644,
3e26120c 1156 .proc_handler = proc_dointvec_minmax,
70da2340 1157 .extra1 = &zero,
1da177e4 1158 },
dd8632a1
PM
1159#else
1160 {
dd8632a1
PM
1161 .procname = "nr_trim_pages",
1162 .data = &sysctl_nr_trim_pages,
1163 .maxlen = sizeof(sysctl_nr_trim_pages),
1164 .mode = 0644,
6d456111 1165 .proc_handler = proc_dointvec_minmax,
dd8632a1
PM
1166 .extra1 = &zero,
1167 },
1da177e4
LT
1168#endif
1169 {
1da177e4
LT
1170 .procname = "laptop_mode",
1171 .data = &laptop_mode,
1172 .maxlen = sizeof(laptop_mode),
1173 .mode = 0644,
6d456111 1174 .proc_handler = proc_dointvec_jiffies,
1da177e4
LT
1175 },
1176 {
1da177e4
LT
1177 .procname = "block_dump",
1178 .data = &block_dump,
1179 .maxlen = sizeof(block_dump),
1180 .mode = 0644,
6d456111 1181 .proc_handler = proc_dointvec,
1da177e4
LT
1182 .extra1 = &zero,
1183 },
1184 {
1da177e4
LT
1185 .procname = "vfs_cache_pressure",
1186 .data = &sysctl_vfs_cache_pressure,
1187 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1188 .mode = 0644,
6d456111 1189 .proc_handler = proc_dointvec,
1da177e4
LT
1190 .extra1 = &zero,
1191 },
1192#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1193 {
1da177e4
LT
1194 .procname = "legacy_va_layout",
1195 .data = &sysctl_legacy_va_layout,
1196 .maxlen = sizeof(sysctl_legacy_va_layout),
1197 .mode = 0644,
6d456111 1198 .proc_handler = proc_dointvec,
1da177e4
LT
1199 .extra1 = &zero,
1200 },
1201#endif
1743660b
CL
1202#ifdef CONFIG_NUMA
1203 {
1743660b
CL
1204 .procname = "zone_reclaim_mode",
1205 .data = &zone_reclaim_mode,
1206 .maxlen = sizeof(zone_reclaim_mode),
1207 .mode = 0644,
6d456111 1208 .proc_handler = proc_dointvec,
c84db23c 1209 .extra1 = &zero,
1743660b 1210 },
9614634f 1211 {
9614634f
CL
1212 .procname = "min_unmapped_ratio",
1213 .data = &sysctl_min_unmapped_ratio,
1214 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1215 .mode = 0644,
6d456111 1216 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
9614634f
CL
1217 .extra1 = &zero,
1218 .extra2 = &one_hundred,
1219 },
0ff38490 1220 {
0ff38490
CL
1221 .procname = "min_slab_ratio",
1222 .data = &sysctl_min_slab_ratio,
1223 .maxlen = sizeof(sysctl_min_slab_ratio),
1224 .mode = 0644,
6d456111 1225 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
0ff38490
CL
1226 .extra1 = &zero,
1227 .extra2 = &one_hundred,
1228 },
e6e5494c 1229#endif
77461ab3
CL
1230#ifdef CONFIG_SMP
1231 {
77461ab3
CL
1232 .procname = "stat_interval",
1233 .data = &sysctl_stat_interval,
1234 .maxlen = sizeof(sysctl_stat_interval),
1235 .mode = 0644,
6d456111 1236 .proc_handler = proc_dointvec_jiffies,
77461ab3
CL
1237 },
1238#endif
6e141546 1239#ifdef CONFIG_MMU
ed032189 1240 {
ed032189 1241 .procname = "mmap_min_addr",
788084ab
EP
1242 .data = &dac_mmap_min_addr,
1243 .maxlen = sizeof(unsigned long),
ed032189 1244 .mode = 0644,
6d456111 1245 .proc_handler = mmap_min_addr_handler,
ed032189 1246 },
6e141546 1247#endif
f0c0b2b8
KH
1248#ifdef CONFIG_NUMA
1249 {
f0c0b2b8
KH
1250 .procname = "numa_zonelist_order",
1251 .data = &numa_zonelist_order,
1252 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1253 .mode = 0644,
6d456111 1254 .proc_handler = numa_zonelist_order_handler,
f0c0b2b8
KH
1255 },
1256#endif
2b8232ce 1257#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
5c36e657 1258 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
e6e5494c 1259 {
e6e5494c
IM
1260 .procname = "vdso_enabled",
1261 .data = &vdso_enabled,
1262 .maxlen = sizeof(vdso_enabled),
1263 .mode = 0644,
6d456111 1264 .proc_handler = proc_dointvec,
e6e5494c
IM
1265 .extra1 = &zero,
1266 },
1da177e4 1267#endif
195cf453
BG
1268#ifdef CONFIG_HIGHMEM
1269 {
195cf453
BG
1270 .procname = "highmem_is_dirtyable",
1271 .data = &vm_highmem_is_dirtyable,
1272 .maxlen = sizeof(vm_highmem_is_dirtyable),
1273 .mode = 0644,
6d456111 1274 .proc_handler = proc_dointvec_minmax,
195cf453
BG
1275 .extra1 = &zero,
1276 .extra2 = &one,
1277 },
1278#endif
4be6f6bb 1279 {
4be6f6bb
PZ
1280 .procname = "scan_unevictable_pages",
1281 .data = &scan_unevictable_pages,
1282 .maxlen = sizeof(scan_unevictable_pages),
1283 .mode = 0644,
6d456111 1284 .proc_handler = scan_unevictable_handler,
4be6f6bb 1285 },
6a46079c
AK
1286#ifdef CONFIG_MEMORY_FAILURE
1287 {
6a46079c
AK
1288 .procname = "memory_failure_early_kill",
1289 .data = &sysctl_memory_failure_early_kill,
1290 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1291 .mode = 0644,
6d456111 1292 .proc_handler = proc_dointvec_minmax,
6a46079c
AK
1293 .extra1 = &zero,
1294 .extra2 = &one,
1295 },
1296 {
6a46079c
AK
1297 .procname = "memory_failure_recovery",
1298 .data = &sysctl_memory_failure_recovery,
1299 .maxlen = sizeof(sysctl_memory_failure_recovery),
1300 .mode = 0644,
6d456111 1301 .proc_handler = proc_dointvec_minmax,
6a46079c
AK
1302 .extra1 = &zero,
1303 .extra2 = &one,
1304 },
1305#endif
1306
2be7fe07
AM
1307/*
1308 * NOTE: do not add new entries to this table unless you have read
1309 * Documentation/sysctl/ctl_unnumbered.txt
1310 */
6fce56ec 1311 { }
1da177e4
LT
1312};
1313
2abc26fc 1314#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
d8217f07 1315static struct ctl_table binfmt_misc_table[] = {
6fce56ec 1316 { }
2abc26fc
EB
1317};
1318#endif
1319
d8217f07 1320static struct ctl_table fs_table[] = {
1da177e4 1321 {
1da177e4
LT
1322 .procname = "inode-nr",
1323 .data = &inodes_stat,
1324 .maxlen = 2*sizeof(int),
1325 .mode = 0444,
6d456111 1326 .proc_handler = proc_dointvec,
1da177e4
LT
1327 },
1328 {
1da177e4
LT
1329 .procname = "inode-state",
1330 .data = &inodes_stat,
1331 .maxlen = 7*sizeof(int),
1332 .mode = 0444,
6d456111 1333 .proc_handler = proc_dointvec,
1da177e4
LT
1334 },
1335 {
1da177e4
LT
1336 .procname = "file-nr",
1337 .data = &files_stat,
1338 .maxlen = 3*sizeof(int),
1339 .mode = 0444,
6d456111 1340 .proc_handler = proc_nr_files,
1da177e4
LT
1341 },
1342 {
1da177e4
LT
1343 .procname = "file-max",
1344 .data = &files_stat.max_files,
1345 .maxlen = sizeof(int),
1346 .mode = 0644,
6d456111 1347 .proc_handler = proc_dointvec,
1da177e4 1348 },
9cfe015a 1349 {
9cfe015a
ED
1350 .procname = "nr_open",
1351 .data = &sysctl_nr_open,
1352 .maxlen = sizeof(int),
1353 .mode = 0644,
6d456111 1354 .proc_handler = proc_dointvec_minmax,
eceea0b3
AV
1355 .extra1 = &sysctl_nr_open_min,
1356 .extra2 = &sysctl_nr_open_max,
9cfe015a 1357 },
1da177e4 1358 {
1da177e4
LT
1359 .procname = "dentry-state",
1360 .data = &dentry_stat,
1361 .maxlen = 6*sizeof(int),
1362 .mode = 0444,
6d456111 1363 .proc_handler = proc_dointvec,
1da177e4
LT
1364 },
1365 {
1da177e4
LT
1366 .procname = "overflowuid",
1367 .data = &fs_overflowuid,
1368 .maxlen = sizeof(int),
1369 .mode = 0644,
6d456111 1370 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1371 .extra1 = &minolduid,
1372 .extra2 = &maxolduid,
1373 },
1374 {
1da177e4
LT
1375 .procname = "overflowgid",
1376 .data = &fs_overflowgid,
1377 .maxlen = sizeof(int),
1378 .mode = 0644,
6d456111 1379 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1380 .extra1 = &minolduid,
1381 .extra2 = &maxolduid,
1382 },
bfcd17a6 1383#ifdef CONFIG_FILE_LOCKING
1da177e4 1384 {
1da177e4
LT
1385 .procname = "leases-enable",
1386 .data = &leases_enable,
1387 .maxlen = sizeof(int),
1388 .mode = 0644,
6d456111 1389 .proc_handler = proc_dointvec,
1da177e4 1390 },
bfcd17a6 1391#endif
1da177e4
LT
1392#ifdef CONFIG_DNOTIFY
1393 {
1da177e4
LT
1394 .procname = "dir-notify-enable",
1395 .data = &dir_notify_enable,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
6d456111 1398 .proc_handler = proc_dointvec,
1da177e4
LT
1399 },
1400#endif
1401#ifdef CONFIG_MMU
bfcd17a6 1402#ifdef CONFIG_FILE_LOCKING
1da177e4 1403 {
1da177e4
LT
1404 .procname = "lease-break-time",
1405 .data = &lease_break_time,
1406 .maxlen = sizeof(int),
1407 .mode = 0644,
6d456111 1408 .proc_handler = proc_dointvec,
1da177e4 1409 },
bfcd17a6 1410#endif
ebf3f09c 1411#ifdef CONFIG_AIO
1da177e4 1412 {
1da177e4
LT
1413 .procname = "aio-nr",
1414 .data = &aio_nr,
1415 .maxlen = sizeof(aio_nr),
1416 .mode = 0444,
6d456111 1417 .proc_handler = proc_doulongvec_minmax,
1da177e4
LT
1418 },
1419 {
1da177e4
LT
1420 .procname = "aio-max-nr",
1421 .data = &aio_max_nr,
1422 .maxlen = sizeof(aio_max_nr),
1423 .mode = 0644,
6d456111 1424 .proc_handler = proc_doulongvec_minmax,
1da177e4 1425 },
ebf3f09c 1426#endif /* CONFIG_AIO */
2d9048e2 1427#ifdef CONFIG_INOTIFY_USER
0399cb08 1428 {
0399cb08
RL
1429 .procname = "inotify",
1430 .mode = 0555,
1431 .child = inotify_table,
1432 },
1433#endif
7ef9964e
DL
1434#ifdef CONFIG_EPOLL
1435 {
1436 .procname = "epoll",
1437 .mode = 0555,
1438 .child = epoll_table,
1439 },
1440#endif
1da177e4 1441#endif
d6e71144 1442 {
d6e71144
AC
1443 .procname = "suid_dumpable",
1444 .data = &suid_dumpable,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
6d456111 1447 .proc_handler = proc_dointvec_minmax,
8e654fba
MW
1448 .extra1 = &zero,
1449 .extra2 = &two,
d6e71144 1450 },
2abc26fc
EB
1451#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1452 {
2abc26fc
EB
1453 .procname = "binfmt_misc",
1454 .mode = 0555,
1455 .child = binfmt_misc_table,
1456 },
1457#endif
b492e95b
JA
1458 {
1459 .procname = "pipe-max-pages",
1460 .data = &pipe_max_pages,
1461 .maxlen = sizeof(int),
1462 .mode = 0644,
1463 .proc_handler = &proc_dointvec_minmax,
1464 .extra1 = &two,
1465 },
2be7fe07
AM
1466/*
1467 * NOTE: do not add new entries to this table unless you have read
1468 * Documentation/sysctl/ctl_unnumbered.txt
2be7fe07 1469 */
6fce56ec 1470 { }
1da177e4
LT
1471};
1472
d8217f07 1473static struct ctl_table debug_table[] = {
ab3c68ee
HC
1474#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1475 defined(CONFIG_S390)
abd4f750 1476 {
abd4f750
MAS
1477 .procname = "exception-trace",
1478 .data = &show_unhandled_signals,
1479 .maxlen = sizeof(int),
1480 .mode = 0644,
1481 .proc_handler = proc_dointvec
1482 },
b2be84df
MH
1483#endif
1484#if defined(CONFIG_OPTPROBES)
1485 {
1486 .procname = "kprobes-optimization",
1487 .data = &sysctl_kprobes_optimization,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
1490 .proc_handler = proc_kprobes_optimization_handler,
1491 .extra1 = &zero,
1492 .extra2 = &one,
1493 },
abd4f750 1494#endif
6fce56ec 1495 { }
1da177e4
LT
1496};
1497
d8217f07 1498static struct ctl_table dev_table[] = {
6fce56ec 1499 { }
0eeca283 1500};
1da177e4 1501
330d57fb
AV
1502static DEFINE_SPINLOCK(sysctl_lock);
1503
1504/* called under sysctl_lock */
1505static int use_table(struct ctl_table_header *p)
1506{
1507 if (unlikely(p->unregistering))
1508 return 0;
1509 p->used++;
1510 return 1;
1511}
1512
1513/* called under sysctl_lock */
1514static void unuse_table(struct ctl_table_header *p)
1515{
1516 if (!--p->used)
1517 if (unlikely(p->unregistering))
1518 complete(p->unregistering);
1519}
1520
1521/* called under sysctl_lock, will reacquire if has to wait */
1522static void start_unregistering(struct ctl_table_header *p)
1523{
1524 /*
1525 * if p->used is 0, nobody will ever touch that entry again;
1526 * we'll eliminate all paths to it before dropping sysctl_lock
1527 */
1528 if (unlikely(p->used)) {
1529 struct completion wait;
1530 init_completion(&wait);
1531 p->unregistering = &wait;
1532 spin_unlock(&sysctl_lock);
1533 wait_for_completion(&wait);
1534 spin_lock(&sysctl_lock);
f7e6ced4
AV
1535 } else {
1536 /* anything non-NULL; we'll never dereference it */
1537 p->unregistering = ERR_PTR(-EINVAL);
330d57fb
AV
1538 }
1539 /*
1540 * do not remove from the list until nobody holds it; walking the
1541 * list in do_sysctl() relies on that.
1542 */
1543 list_del_init(&p->ctl_entry);
1544}
1545
f7e6ced4
AV
1546void sysctl_head_get(struct ctl_table_header *head)
1547{
1548 spin_lock(&sysctl_lock);
1549 head->count++;
1550 spin_unlock(&sysctl_lock);
1551}
1552
1553void sysctl_head_put(struct ctl_table_header *head)
1554{
1555 spin_lock(&sysctl_lock);
1556 if (!--head->count)
1557 kfree(head);
1558 spin_unlock(&sysctl_lock);
1559}
1560
1561struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1562{
1563 if (!head)
1564 BUG();
1565 spin_lock(&sysctl_lock);
1566 if (!use_table(head))
1567 head = ERR_PTR(-ENOENT);
1568 spin_unlock(&sysctl_lock);
1569 return head;
1570}
1571
805b5d5e
EB
1572void sysctl_head_finish(struct ctl_table_header *head)
1573{
1574 if (!head)
1575 return;
1576 spin_lock(&sysctl_lock);
1577 unuse_table(head);
1578 spin_unlock(&sysctl_lock);
1579}
1580
73455092
AV
1581static struct ctl_table_set *
1582lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1583{
1584 struct ctl_table_set *set = &root->default_set;
1585 if (root->lookup)
1586 set = root->lookup(root, namespaces);
1587 return set;
1588}
1589
e51b6ba0
EB
1590static struct list_head *
1591lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
805b5d5e 1592{
73455092
AV
1593 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1594 return &set->list;
e51b6ba0
EB
1595}
1596
1597struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1598 struct ctl_table_header *prev)
1599{
1600 struct ctl_table_root *root;
1601 struct list_head *header_list;
805b5d5e
EB
1602 struct ctl_table_header *head;
1603 struct list_head *tmp;
e51b6ba0 1604
805b5d5e
EB
1605 spin_lock(&sysctl_lock);
1606 if (prev) {
e51b6ba0 1607 head = prev;
805b5d5e
EB
1608 tmp = &prev->ctl_entry;
1609 unuse_table(prev);
1610 goto next;
1611 }
1612 tmp = &root_table_header.ctl_entry;
1613 for (;;) {
1614 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1615
1616 if (!use_table(head))
1617 goto next;
1618 spin_unlock(&sysctl_lock);
1619 return head;
1620 next:
e51b6ba0 1621 root = head->root;
805b5d5e 1622 tmp = tmp->next;
e51b6ba0
EB
1623 header_list = lookup_header_list(root, namespaces);
1624 if (tmp != header_list)
1625 continue;
1626
1627 do {
1628 root = list_entry(root->root_list.next,
1629 struct ctl_table_root, root_list);
1630 if (root == &sysctl_table_root)
1631 goto out;
1632 header_list = lookup_header_list(root, namespaces);
1633 } while (list_empty(header_list));
1634 tmp = header_list->next;
805b5d5e 1635 }
e51b6ba0 1636out:
805b5d5e
EB
1637 spin_unlock(&sysctl_lock);
1638 return NULL;
1639}
1640
e51b6ba0
EB
1641struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1642{
1643 return __sysctl_head_next(current->nsproxy, prev);
1644}
1645
1646void register_sysctl_root(struct ctl_table_root *root)
1647{
1648 spin_lock(&sysctl_lock);
1649 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1650 spin_unlock(&sysctl_lock);
1651}
1652
1da177e4 1653/*
1ff007eb 1654 * sysctl_perm does NOT grant the superuser all rights automatically, because
1da177e4
LT
1655 * some sysctl variables are readonly even to root.
1656 */
1657
1658static int test_perm(int mode, int op)
1659{
76aac0e9 1660 if (!current_euid())
1da177e4
LT
1661 mode >>= 6;
1662 else if (in_egroup_p(0))
1663 mode >>= 3;
e6305c43 1664 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1da177e4
LT
1665 return 0;
1666 return -EACCES;
1667}
1668
d7321cd6 1669int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1da177e4
LT
1670{
1671 int error;
d7321cd6
PE
1672 int mode;
1673
e6305c43 1674 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1da177e4
LT
1675 if (error)
1676 return error;
d7321cd6
PE
1677
1678 if (root->permissions)
1679 mode = root->permissions(root, current->nsproxy, table);
1680 else
1681 mode = table->mode;
1682
1683 return test_perm(mode, op);
1da177e4
LT
1684}
1685
d912b0cc
EB
1686static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1687{
2315ffa0 1688 for (; table->procname; table++) {
d912b0cc
EB
1689 table->parent = parent;
1690 if (table->child)
1691 sysctl_set_parent(table, table->child);
1692 }
1693}
1694
1695static __init int sysctl_init(void)
1696{
1697 sysctl_set_parent(NULL, root_table);
88f458e4
HS
1698#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1699 {
1700 int err;
1701 err = sysctl_check_table(current->nsproxy, root_table);
1702 }
1703#endif
d912b0cc
EB
1704 return 0;
1705}
1706
1707core_initcall(sysctl_init);
1708
bfbcf034
AV
1709static struct ctl_table *is_branch_in(struct ctl_table *branch,
1710 struct ctl_table *table)
ae7edecc
AV
1711{
1712 struct ctl_table *p;
1713 const char *s = branch->procname;
1714
1715 /* branch should have named subdirectory as its first element */
1716 if (!s || !branch->child)
bfbcf034 1717 return NULL;
ae7edecc
AV
1718
1719 /* ... and nothing else */
2315ffa0 1720 if (branch[1].procname)
bfbcf034 1721 return NULL;
ae7edecc
AV
1722
1723 /* table should contain subdirectory with the same name */
2315ffa0 1724 for (p = table; p->procname; p++) {
ae7edecc
AV
1725 if (!p->child)
1726 continue;
1727 if (p->procname && strcmp(p->procname, s) == 0)
bfbcf034 1728 return p;
ae7edecc 1729 }
bfbcf034 1730 return NULL;
ae7edecc
AV
1731}
1732
1733/* see if attaching q to p would be an improvement */
1734static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1735{
1736 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
bfbcf034 1737 struct ctl_table *next;
ae7edecc
AV
1738 int is_better = 0;
1739 int not_in_parent = !p->attached_by;
1740
bfbcf034 1741 while ((next = is_branch_in(by, to)) != NULL) {
ae7edecc
AV
1742 if (by == q->attached_by)
1743 is_better = 1;
1744 if (to == p->attached_by)
1745 not_in_parent = 1;
1746 by = by->child;
bfbcf034 1747 to = next->child;
ae7edecc
AV
1748 }
1749
1750 if (is_better && not_in_parent) {
1751 q->attached_by = by;
1752 q->attached_to = to;
1753 q->parent = p;
1754 }
1755}
1756
1da177e4 1757/**
e51b6ba0
EB
1758 * __register_sysctl_paths - register a sysctl hierarchy
1759 * @root: List of sysctl headers to register on
1760 * @namespaces: Data to compute which lists of sysctl entries are visible
29e796fd 1761 * @path: The path to the directory the sysctl table is in.
1da177e4 1762 * @table: the top-level table structure
1da177e4
LT
1763 *
1764 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
29e796fd 1765 * array. A completely 0 filled entry terminates the table.
1da177e4 1766 *
d8217f07 1767 * The members of the &struct ctl_table structure are used as follows:
1da177e4 1768 *
1da177e4
LT
1769 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1770 * enter a sysctl file
1771 *
1772 * data - a pointer to data for use by proc_handler
1773 *
1774 * maxlen - the maximum size in bytes of the data
1775 *
1776 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1777 *
1778 * child - a pointer to the child sysctl table if this entry is a directory, or
1779 * %NULL.
1780 *
1781 * proc_handler - the text handler routine (described below)
1782 *
1da177e4
LT
1783 * de - for internal use by the sysctl routines
1784 *
1785 * extra1, extra2 - extra pointers usable by the proc handler routines
1786 *
1787 * Leaf nodes in the sysctl tree will be represented by a single file
1788 * under /proc; non-leaf nodes will be represented by directories.
1789 *
1790 * sysctl(2) can automatically manage read and write requests through
1791 * the sysctl table. The data and maxlen fields of the ctl_table
1792 * struct enable minimal validation of the values being written to be
1793 * performed, and the mode field allows minimal authentication.
1794 *
1da177e4
LT
1795 * There must be a proc_handler routine for any terminal nodes
1796 * mirrored under /proc/sys (non-terminals are handled by a built-in
1797 * directory handler). Several default handlers are available to
1798 * cover common cases -
1799 *
1800 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1801 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1802 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1803 *
1804 * It is the handler's job to read the input buffer from user memory
1805 * and process it. The handler should return 0 on success.
1806 *
1807 * This routine returns %NULL on a failure to register, and a pointer
1808 * to the table header on success.
1809 */
e51b6ba0
EB
1810struct ctl_table_header *__register_sysctl_paths(
1811 struct ctl_table_root *root,
1812 struct nsproxy *namespaces,
1813 const struct ctl_path *path, struct ctl_table *table)
1da177e4 1814{
29e796fd
EB
1815 struct ctl_table_header *header;
1816 struct ctl_table *new, **prevp;
1817 unsigned int n, npath;
ae7edecc 1818 struct ctl_table_set *set;
29e796fd
EB
1819
1820 /* Count the path components */
2315ffa0 1821 for (npath = 0; path[npath].procname; ++npath)
29e796fd
EB
1822 ;
1823
1824 /*
1825 * For each path component, allocate a 2-element ctl_table array.
1826 * The first array element will be filled with the sysctl entry
2315ffa0 1827 * for this, the second will be the sentinel (procname == 0).
29e796fd
EB
1828 *
1829 * We allocate everything in one go so that we don't have to
1830 * worry about freeing additional memory in unregister_sysctl_table.
1831 */
1832 header = kzalloc(sizeof(struct ctl_table_header) +
1833 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1834 if (!header)
1da177e4 1835 return NULL;
29e796fd
EB
1836
1837 new = (struct ctl_table *) (header + 1);
1838
1839 /* Now connect the dots */
1840 prevp = &header->ctl_table;
1841 for (n = 0; n < npath; ++n, ++path) {
1842 /* Copy the procname */
1843 new->procname = path->procname;
29e796fd
EB
1844 new->mode = 0555;
1845
1846 *prevp = new;
1847 prevp = &new->child;
1848
1849 new += 2;
1850 }
1851 *prevp = table;
23eb06de 1852 header->ctl_table_arg = table;
29e796fd
EB
1853
1854 INIT_LIST_HEAD(&header->ctl_entry);
1855 header->used = 0;
1856 header->unregistering = NULL;
e51b6ba0 1857 header->root = root;
29e796fd 1858 sysctl_set_parent(NULL, header->ctl_table);
f7e6ced4 1859 header->count = 1;
88f458e4 1860#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
e51b6ba0 1861 if (sysctl_check_table(namespaces, header->ctl_table)) {
29e796fd 1862 kfree(header);
fc6cd25b
EB
1863 return NULL;
1864 }
88f458e4 1865#endif
330d57fb 1866 spin_lock(&sysctl_lock);
73455092 1867 header->set = lookup_header_set(root, namespaces);
ae7edecc
AV
1868 header->attached_by = header->ctl_table;
1869 header->attached_to = root_table;
1870 header->parent = &root_table_header;
1871 for (set = header->set; set; set = set->parent) {
1872 struct ctl_table_header *p;
1873 list_for_each_entry(p, &set->list, ctl_entry) {
1874 if (p->unregistering)
1875 continue;
1876 try_attach(p, header);
1877 }
1878 }
1879 header->parent->count++;
73455092 1880 list_add_tail(&header->ctl_entry, &header->set->list);
330d57fb 1881 spin_unlock(&sysctl_lock);
29e796fd
EB
1882
1883 return header;
1884}
1885
e51b6ba0
EB
1886/**
1887 * register_sysctl_table_path - register a sysctl table hierarchy
1888 * @path: The path to the directory the sysctl table is in.
1889 * @table: the top-level table structure
1890 *
1891 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1892 * array. A completely 0 filled entry terminates the table.
1893 *
1894 * See __register_sysctl_paths for more details.
1895 */
1896struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1897 struct ctl_table *table)
1898{
1899 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1900 path, table);
1901}
1902
29e796fd
EB
1903/**
1904 * register_sysctl_table - register a sysctl table hierarchy
1905 * @table: the top-level table structure
1906 *
1907 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1908 * array. A completely 0 filled entry terminates the table.
1909 *
1910 * See register_sysctl_paths for more details.
1911 */
1912struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1913{
1914 static const struct ctl_path null_path[] = { {} };
1915
1916 return register_sysctl_paths(null_path, table);
1da177e4
LT
1917}
1918
1919/**
1920 * unregister_sysctl_table - unregister a sysctl table hierarchy
1921 * @header: the header returned from register_sysctl_table
1922 *
1923 * Unregisters the sysctl table and all children. proc entries may not
1924 * actually be removed until they are no longer used by anyone.
1925 */
1926void unregister_sysctl_table(struct ctl_table_header * header)
1927{
330d57fb 1928 might_sleep();
f1dad166
PE
1929
1930 if (header == NULL)
1931 return;
1932
330d57fb
AV
1933 spin_lock(&sysctl_lock);
1934 start_unregistering(header);
ae7edecc
AV
1935 if (!--header->parent->count) {
1936 WARN_ON(1);
1937 kfree(header->parent);
1938 }
f7e6ced4
AV
1939 if (!--header->count)
1940 kfree(header);
330d57fb 1941 spin_unlock(&sysctl_lock);
1da177e4
LT
1942}
1943
9043476f
AV
1944int sysctl_is_seen(struct ctl_table_header *p)
1945{
1946 struct ctl_table_set *set = p->set;
1947 int res;
1948 spin_lock(&sysctl_lock);
1949 if (p->unregistering)
1950 res = 0;
1951 else if (!set->is_seen)
1952 res = 1;
1953 else
1954 res = set->is_seen(set);
1955 spin_unlock(&sysctl_lock);
1956 return res;
1957}
1958
73455092
AV
1959void setup_sysctl_set(struct ctl_table_set *p,
1960 struct ctl_table_set *parent,
1961 int (*is_seen)(struct ctl_table_set *))
1962{
1963 INIT_LIST_HEAD(&p->list);
1964 p->parent = parent ? parent : &sysctl_table_root.default_set;
1965 p->is_seen = is_seen;
1966}
1967
b89a8171 1968#else /* !CONFIG_SYSCTL */
d8217f07 1969struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
b89a8171
EB
1970{
1971 return NULL;
1972}
1973
29e796fd
EB
1974struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1975 struct ctl_table *table)
1976{
1977 return NULL;
1978}
1979
b89a8171
EB
1980void unregister_sysctl_table(struct ctl_table_header * table)
1981{
1982}
1983
73455092
AV
1984void setup_sysctl_set(struct ctl_table_set *p,
1985 struct ctl_table_set *parent,
1986 int (*is_seen)(struct ctl_table_set *))
1987{
1988}
1989
f7e6ced4
AV
1990void sysctl_head_put(struct ctl_table_header *head)
1991{
1992}
1993
b89a8171
EB
1994#endif /* CONFIG_SYSCTL */
1995
1da177e4
LT
1996/*
1997 * /proc/sys support
1998 */
1999
b89a8171 2000#ifdef CONFIG_PROC_SYSCTL
1da177e4 2001
b1ba4ddd 2002static int _proc_do_string(void* data, int maxlen, int write,
8d65af78 2003 void __user *buffer,
b1ba4ddd 2004 size_t *lenp, loff_t *ppos)
1da177e4
LT
2005{
2006 size_t len;
2007 char __user *p;
2008 char c;
8d060877
ON
2009
2010 if (!data || !maxlen || !*lenp) {
1da177e4
LT
2011 *lenp = 0;
2012 return 0;
2013 }
8d060877 2014
1da177e4
LT
2015 if (write) {
2016 len = 0;
2017 p = buffer;
2018 while (len < *lenp) {
2019 if (get_user(c, p++))
2020 return -EFAULT;
2021 if (c == 0 || c == '\n')
2022 break;
2023 len++;
2024 }
f5dd3d6f
SV
2025 if (len >= maxlen)
2026 len = maxlen-1;
2027 if(copy_from_user(data, buffer, len))
1da177e4 2028 return -EFAULT;
f5dd3d6f 2029 ((char *) data)[len] = 0;
1da177e4
LT
2030 *ppos += *lenp;
2031 } else {
f5dd3d6f
SV
2032 len = strlen(data);
2033 if (len > maxlen)
2034 len = maxlen;
8d060877
ON
2035
2036 if (*ppos > len) {
2037 *lenp = 0;
2038 return 0;
2039 }
2040
2041 data += *ppos;
2042 len -= *ppos;
2043
1da177e4
LT
2044 if (len > *lenp)
2045 len = *lenp;
2046 if (len)
f5dd3d6f 2047 if(copy_to_user(buffer, data, len))
1da177e4
LT
2048 return -EFAULT;
2049 if (len < *lenp) {
2050 if(put_user('\n', ((char __user *) buffer) + len))
2051 return -EFAULT;
2052 len++;
2053 }
2054 *lenp = len;
2055 *ppos += len;
2056 }
2057 return 0;
2058}
2059
f5dd3d6f
SV
2060/**
2061 * proc_dostring - read a string sysctl
2062 * @table: the sysctl table
2063 * @write: %TRUE if this is a write to the sysctl file
f5dd3d6f
SV
2064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2067 *
2068 * Reads/writes a string from/to the user buffer. If the kernel
2069 * buffer provided is not large enough to hold the string, the
2070 * string is truncated. The copied string is %NULL-terminated.
2071 * If the string is being read by the user process, it is copied
2072 * and a newline '\n' is added. It is truncated if the buffer is
2073 * not large enough.
2074 *
2075 * Returns 0 on success.
2076 */
8d65af78 2077int proc_dostring(struct ctl_table *table, int write,
f5dd3d6f
SV
2078 void __user *buffer, size_t *lenp, loff_t *ppos)
2079{
8d65af78 2080 return _proc_do_string(table->data, table->maxlen, write,
f5dd3d6f
SV
2081 buffer, lenp, ppos);
2082}
2083
00b7c339
AW
2084static size_t proc_skip_spaces(char **buf)
2085{
2086 size_t ret;
2087 char *tmp = skip_spaces(*buf);
2088 ret = tmp - *buf;
2089 *buf = tmp;
2090 return ret;
2091}
2092
9f977fb7
OP
2093static void proc_skip_char(char **buf, size_t *size, const char v)
2094{
2095 while (*size) {
2096 if (**buf != v)
2097 break;
2098 (*size)--;
2099 (*buf)++;
2100 }
2101}
2102
00b7c339
AW
2103#define TMPBUFLEN 22
2104/**
0fc377bd 2105 * proc_get_long - reads an ASCII formatted integer from a user buffer
00b7c339 2106 *
0fc377bd
RD
2107 * @buf: a kernel buffer
2108 * @size: size of the kernel buffer
2109 * @val: this is where the number will be stored
2110 * @neg: set to %TRUE if number is negative
2111 * @perm_tr: a vector which contains the allowed trailers
2112 * @perm_tr_len: size of the perm_tr vector
2113 * @tr: pointer to store the trailer character
00b7c339 2114 *
0fc377bd
RD
2115 * In case of success %0 is returned and @buf and @size are updated with
2116 * the amount of bytes read. If @tr is non-NULL and a trailing
2117 * character exists (size is non-zero after returning from this
2118 * function), @tr is updated with the trailing character.
00b7c339
AW
2119 */
2120static int proc_get_long(char **buf, size_t *size,
2121 unsigned long *val, bool *neg,
2122 const char *perm_tr, unsigned perm_tr_len, char *tr)
2123{
2124 int len;
2125 char *p, tmp[TMPBUFLEN];
2126
2127 if (!*size)
2128 return -EINVAL;
2129
2130 len = *size;
2131 if (len > TMPBUFLEN - 1)
2132 len = TMPBUFLEN - 1;
2133
2134 memcpy(tmp, *buf, len);
2135
2136 tmp[len] = 0;
2137 p = tmp;
2138 if (*p == '-' && *size > 1) {
2139 *neg = true;
2140 p++;
2141 } else
2142 *neg = false;
2143 if (!isdigit(*p))
2144 return -EINVAL;
2145
2146 *val = simple_strtoul(p, &p, 0);
2147
2148 len = p - tmp;
2149
2150 /* We don't know if the next char is whitespace thus we may accept
2151 * invalid integers (e.g. 1234...a) or two integers instead of one
2152 * (e.g. 123...1). So lets not allow such large numbers. */
2153 if (len == TMPBUFLEN - 1)
2154 return -EINVAL;
2155
2156 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2157 return -EINVAL;
1da177e4 2158
00b7c339
AW
2159 if (tr && (len < *size))
2160 *tr = *p;
2161
2162 *buf += len;
2163 *size -= len;
2164
2165 return 0;
2166}
2167
2168/**
0fc377bd 2169 * proc_put_long - converts an integer to a decimal ASCII formatted string
00b7c339 2170 *
0fc377bd
RD
2171 * @buf: the user buffer
2172 * @size: the size of the user buffer
2173 * @val: the integer to be converted
2174 * @neg: sign of the number, %TRUE for negative
00b7c339 2175 *
0fc377bd
RD
2176 * In case of success %0 is returned and @buf and @size are updated with
2177 * the amount of bytes written.
00b7c339
AW
2178 */
2179static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2180 bool neg)
2181{
2182 int len;
2183 char tmp[TMPBUFLEN], *p = tmp;
2184
2185 sprintf(p, "%s%lu", neg ? "-" : "", val);
2186 len = strlen(tmp);
2187 if (len > *size)
2188 len = *size;
2189 if (copy_to_user(*buf, tmp, len))
2190 return -EFAULT;
2191 *size -= len;
2192 *buf += len;
2193 return 0;
2194}
2195#undef TMPBUFLEN
2196
2197static int proc_put_char(void __user **buf, size_t *size, char c)
2198{
2199 if (*size) {
2200 char __user **buffer = (char __user **)buf;
2201 if (put_user(c, *buffer))
2202 return -EFAULT;
2203 (*size)--, (*buffer)++;
2204 *buf = *buffer;
2205 }
2206 return 0;
2207}
1da177e4 2208
00b7c339 2209static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2210 int *valp,
2211 int write, void *data)
2212{
2213 if (write) {
2214 *valp = *negp ? -*lvalp : *lvalp;
2215 } else {
2216 int val = *valp;
2217 if (val < 0) {
00b7c339 2218 *negp = true;
1da177e4
LT
2219 *lvalp = (unsigned long)-val;
2220 } else {
00b7c339 2221 *negp = false;
1da177e4
LT
2222 *lvalp = (unsigned long)val;
2223 }
2224 }
2225 return 0;
2226}
2227
00b7c339
AW
2228static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2229
d8217f07 2230static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
8d65af78 2231 int write, void __user *buffer,
fcfbd547 2232 size_t *lenp, loff_t *ppos,
00b7c339 2233 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1da177e4
LT
2234 int write, void *data),
2235 void *data)
2236{
00b7c339
AW
2237 int *i, vleft, first = 1, err = 0;
2238 unsigned long page = 0;
2239 size_t left;
2240 char *kbuf;
1da177e4 2241
00b7c339 2242 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1da177e4
LT
2243 *lenp = 0;
2244 return 0;
2245 }
2246
fcfbd547 2247 i = (int *) tbl_data;
1da177e4
LT
2248 vleft = table->maxlen / sizeof(*i);
2249 left = *lenp;
2250
2251 if (!conv)
2252 conv = do_proc_dointvec_conv;
2253
00b7c339
AW
2254 if (write) {
2255 if (left > PAGE_SIZE - 1)
2256 left = PAGE_SIZE - 1;
2257 page = __get_free_page(GFP_TEMPORARY);
2258 kbuf = (char *) page;
2259 if (!kbuf)
2260 return -ENOMEM;
2261 if (copy_from_user(kbuf, buffer, left)) {
2262 err = -EFAULT;
2263 goto free;
2264 }
2265 kbuf[left] = 0;
2266 }
2267
1da177e4 2268 for (; left && vleft--; i++, first=0) {
00b7c339
AW
2269 unsigned long lval;
2270 bool neg;
1da177e4 2271
00b7c339
AW
2272 if (write) {
2273 left -= proc_skip_spaces(&kbuf);
1da177e4 2274
00b7c339
AW
2275 err = proc_get_long(&kbuf, &left, &lval, &neg,
2276 proc_wspace_sep,
2277 sizeof(proc_wspace_sep), NULL);
2278 if (err)
1da177e4 2279 break;
00b7c339
AW
2280 if (conv(&neg, &lval, i, 1, data)) {
2281 err = -EINVAL;
1da177e4 2282 break;
00b7c339 2283 }
1da177e4 2284 } else {
00b7c339
AW
2285 if (conv(&neg, &lval, i, 0, data)) {
2286 err = -EINVAL;
2287 break;
2288 }
1da177e4 2289 if (!first)
00b7c339
AW
2290 err = proc_put_char(&buffer, &left, '\t');
2291 if (err)
2292 break;
2293 err = proc_put_long(&buffer, &left, lval, neg);
2294 if (err)
1da177e4 2295 break;
1da177e4
LT
2296 }
2297 }
2298
00b7c339
AW
2299 if (!write && !first && left && !err)
2300 err = proc_put_char(&buffer, &left, '\n');
2301 if (write && !err)
2302 left -= proc_skip_spaces(&kbuf);
2303free:
1da177e4 2304 if (write) {
00b7c339
AW
2305 free_page(page);
2306 if (first)
2307 return err ? : -EINVAL;
1da177e4 2308 }
1da177e4
LT
2309 *lenp -= left;
2310 *ppos += *lenp;
00b7c339 2311 return err;
1da177e4
LT
2312}
2313
8d65af78 2314static int do_proc_dointvec(struct ctl_table *table, int write,
fcfbd547 2315 void __user *buffer, size_t *lenp, loff_t *ppos,
00b7c339 2316 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
fcfbd547
KK
2317 int write, void *data),
2318 void *data)
2319{
8d65af78 2320 return __do_proc_dointvec(table->data, table, write,
fcfbd547
KK
2321 buffer, lenp, ppos, conv, data);
2322}
2323
1da177e4
LT
2324/**
2325 * proc_dointvec - read a vector of integers
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2331 *
2332 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2333 * values from/to the user buffer, treated as an ASCII string.
2334 *
2335 * Returns 0 on success.
2336 */
8d65af78 2337int proc_dointvec(struct ctl_table *table, int write,
1da177e4
LT
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2339{
8d65af78 2340 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2341 NULL,NULL);
2342}
2343
34f5a398 2344/*
25ddbb18
AK
2345 * Taint values can only be increased
2346 * This means we can safely use a temporary.
34f5a398 2347 */
8d65af78 2348static int proc_taint(struct ctl_table *table, int write,
34f5a398
TT
2349 void __user *buffer, size_t *lenp, loff_t *ppos)
2350{
25ddbb18
AK
2351 struct ctl_table t;
2352 unsigned long tmptaint = get_taint();
2353 int err;
34f5a398 2354
91fcd412 2355 if (write && !capable(CAP_SYS_ADMIN))
34f5a398
TT
2356 return -EPERM;
2357
25ddbb18
AK
2358 t = *table;
2359 t.data = &tmptaint;
8d65af78 2360 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
25ddbb18
AK
2361 if (err < 0)
2362 return err;
2363
2364 if (write) {
2365 /*
2366 * Poor man's atomic or. Not worth adding a primitive
2367 * to everyone's atomic.h for this
2368 */
2369 int i;
2370 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2371 if ((tmptaint >> i) & 1)
2372 add_taint(i);
2373 }
2374 }
2375
2376 return err;
34f5a398
TT
2377}
2378
1da177e4
LT
2379struct do_proc_dointvec_minmax_conv_param {
2380 int *min;
2381 int *max;
2382};
2383
00b7c339
AW
2384static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2385 int *valp,
1da177e4
LT
2386 int write, void *data)
2387{
2388 struct do_proc_dointvec_minmax_conv_param *param = data;
2389 if (write) {
2390 int val = *negp ? -*lvalp : *lvalp;
2391 if ((param->min && *param->min > val) ||
2392 (param->max && *param->max < val))
2393 return -EINVAL;
2394 *valp = val;
2395 } else {
2396 int val = *valp;
2397 if (val < 0) {
00b7c339 2398 *negp = true;
1da177e4
LT
2399 *lvalp = (unsigned long)-val;
2400 } else {
00b7c339 2401 *negp = false;
1da177e4
LT
2402 *lvalp = (unsigned long)val;
2403 }
2404 }
2405 return 0;
2406}
2407
2408/**
2409 * proc_dointvec_minmax - read a vector of integers with min/max values
2410 * @table: the sysctl table
2411 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: file position
2415 *
2416 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2417 * values from/to the user buffer, treated as an ASCII string.
2418 *
2419 * This routine will ensure the values are within the range specified by
2420 * table->extra1 (min) and table->extra2 (max).
2421 *
2422 * Returns 0 on success.
2423 */
8d65af78 2424int proc_dointvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426{
2427 struct do_proc_dointvec_minmax_conv_param param = {
2428 .min = (int *) table->extra1,
2429 .max = (int *) table->extra2,
2430 };
8d65af78 2431 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1da177e4
LT
2432 do_proc_dointvec_minmax_conv, &param);
2433}
2434
d8217f07 2435static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1da177e4
LT
2436 void __user *buffer,
2437 size_t *lenp, loff_t *ppos,
2438 unsigned long convmul,
2439 unsigned long convdiv)
2440{
00b7c339
AW
2441 unsigned long *i, *min, *max;
2442 int vleft, first = 1, err = 0;
2443 unsigned long page = 0;
2444 size_t left;
2445 char *kbuf;
2446
2447 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1da177e4
LT
2448 *lenp = 0;
2449 return 0;
2450 }
00b7c339 2451
fcfbd547 2452 i = (unsigned long *) data;
1da177e4
LT
2453 min = (unsigned long *) table->extra1;
2454 max = (unsigned long *) table->extra2;
2455 vleft = table->maxlen / sizeof(unsigned long);
2456 left = *lenp;
00b7c339
AW
2457
2458 if (write) {
2459 if (left > PAGE_SIZE - 1)
2460 left = PAGE_SIZE - 1;
2461 page = __get_free_page(GFP_TEMPORARY);
2462 kbuf = (char *) page;
2463 if (!kbuf)
2464 return -ENOMEM;
2465 if (copy_from_user(kbuf, buffer, left)) {
2466 err = -EFAULT;
2467 goto free;
2468 }
2469 kbuf[left] = 0;
2470 }
2471
1da177e4 2472 for (; left && vleft--; i++, min++, max++, first=0) {
00b7c339
AW
2473 unsigned long val;
2474
1da177e4 2475 if (write) {
00b7c339
AW
2476 bool neg;
2477
2478 left -= proc_skip_spaces(&kbuf);
2479
2480 err = proc_get_long(&kbuf, &left, &val, &neg,
2481 proc_wspace_sep,
2482 sizeof(proc_wspace_sep), NULL);
2483 if (err)
1da177e4
LT
2484 break;
2485 if (neg)
1da177e4
LT
2486 continue;
2487 if ((min && val < *min) || (max && val > *max))
2488 continue;
2489 *i = val;
2490 } else {
00b7c339 2491 val = convdiv * (*i) / convmul;
1da177e4 2492 if (!first)
00b7c339
AW
2493 err = proc_put_char(&buffer, &left, '\t');
2494 err = proc_put_long(&buffer, &left, val, false);
2495 if (err)
2496 break;
1da177e4
LT
2497 }
2498 }
2499
00b7c339
AW
2500 if (!write && !first && left && !err)
2501 err = proc_put_char(&buffer, &left, '\n');
2502 if (write && !err)
2503 left -= proc_skip_spaces(&kbuf);
2504free:
1da177e4 2505 if (write) {
00b7c339
AW
2506 free_page(page);
2507 if (first)
2508 return err ? : -EINVAL;
1da177e4 2509 }
1da177e4
LT
2510 *lenp -= left;
2511 *ppos += *lenp;
00b7c339 2512 return err;
1da177e4
LT
2513}
2514
d8217f07 2515static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
fcfbd547
KK
2516 void __user *buffer,
2517 size_t *lenp, loff_t *ppos,
2518 unsigned long convmul,
2519 unsigned long convdiv)
2520{
2521 return __do_proc_doulongvec_minmax(table->data, table, write,
8d65af78 2522 buffer, lenp, ppos, convmul, convdiv);
fcfbd547
KK
2523}
2524
1da177e4
LT
2525/**
2526 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2529 * @buffer: the user buffer
2530 * @lenp: the size of the user buffer
2531 * @ppos: file position
2532 *
2533 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2534 * values from/to the user buffer, treated as an ASCII string.
2535 *
2536 * This routine will ensure the values are within the range specified by
2537 * table->extra1 (min) and table->extra2 (max).
2538 *
2539 * Returns 0 on success.
2540 */
8d65af78 2541int proc_doulongvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2542 void __user *buffer, size_t *lenp, loff_t *ppos)
2543{
8d65af78 2544 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1da177e4
LT
2545}
2546
2547/**
2548 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2554 *
2555 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2556 * values from/to the user buffer, treated as an ASCII string. The values
2557 * are treated as milliseconds, and converted to jiffies when they are stored.
2558 *
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2561 *
2562 * Returns 0 on success.
2563 */
d8217f07 2564int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2565 void __user *buffer,
2566 size_t *lenp, loff_t *ppos)
2567{
8d65af78 2568 return do_proc_doulongvec_minmax(table, write, buffer,
1da177e4
LT
2569 lenp, ppos, HZ, 1000l);
2570}
2571
2572
00b7c339 2573static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2574 int *valp,
2575 int write, void *data)
2576{
2577 if (write) {
cba9f33d
BS
2578 if (*lvalp > LONG_MAX / HZ)
2579 return 1;
1da177e4
LT
2580 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2581 } else {
2582 int val = *valp;
2583 unsigned long lval;
2584 if (val < 0) {
00b7c339 2585 *negp = true;
1da177e4
LT
2586 lval = (unsigned long)-val;
2587 } else {
00b7c339 2588 *negp = false;
1da177e4
LT
2589 lval = (unsigned long)val;
2590 }
2591 *lvalp = lval / HZ;
2592 }
2593 return 0;
2594}
2595
00b7c339 2596static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2597 int *valp,
2598 int write, void *data)
2599{
2600 if (write) {
cba9f33d
BS
2601 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2602 return 1;
1da177e4
LT
2603 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2604 } else {
2605 int val = *valp;
2606 unsigned long lval;
2607 if (val < 0) {
00b7c339 2608 *negp = true;
1da177e4
LT
2609 lval = (unsigned long)-val;
2610 } else {
00b7c339 2611 *negp = false;
1da177e4
LT
2612 lval = (unsigned long)val;
2613 }
2614 *lvalp = jiffies_to_clock_t(lval);
2615 }
2616 return 0;
2617}
2618
00b7c339 2619static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2620 int *valp,
2621 int write, void *data)
2622{
2623 if (write) {
2624 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2625 } else {
2626 int val = *valp;
2627 unsigned long lval;
2628 if (val < 0) {
00b7c339 2629 *negp = true;
1da177e4
LT
2630 lval = (unsigned long)-val;
2631 } else {
00b7c339 2632 *negp = false;
1da177e4
LT
2633 lval = (unsigned long)val;
2634 }
2635 *lvalp = jiffies_to_msecs(lval);
2636 }
2637 return 0;
2638}
2639
2640/**
2641 * proc_dointvec_jiffies - read a vector of integers as seconds
2642 * @table: the sysctl table
2643 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2644 * @buffer: the user buffer
2645 * @lenp: the size of the user buffer
2646 * @ppos: file position
2647 *
2648 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2649 * values from/to the user buffer, treated as an ASCII string.
2650 * The values read are assumed to be in seconds, and are converted into
2651 * jiffies.
2652 *
2653 * Returns 0 on success.
2654 */
8d65af78 2655int proc_dointvec_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2656 void __user *buffer, size_t *lenp, loff_t *ppos)
2657{
8d65af78 2658 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2659 do_proc_dointvec_jiffies_conv,NULL);
2660}
2661
2662/**
2663 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2664 * @table: the sysctl table
2665 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2666 * @buffer: the user buffer
2667 * @lenp: the size of the user buffer
1e5d5331 2668 * @ppos: pointer to the file position
1da177e4
LT
2669 *
2670 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2671 * values from/to the user buffer, treated as an ASCII string.
2672 * The values read are assumed to be in 1/USER_HZ seconds, and
2673 * are converted into jiffies.
2674 *
2675 * Returns 0 on success.
2676 */
8d65af78 2677int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2678 void __user *buffer, size_t *lenp, loff_t *ppos)
2679{
8d65af78 2680 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2681 do_proc_dointvec_userhz_jiffies_conv,NULL);
2682}
2683
2684/**
2685 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2686 * @table: the sysctl table
2687 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2688 * @buffer: the user buffer
2689 * @lenp: the size of the user buffer
67be2dd1
MW
2690 * @ppos: file position
2691 * @ppos: the current position in the file
1da177e4
LT
2692 *
2693 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2694 * values from/to the user buffer, treated as an ASCII string.
2695 * The values read are assumed to be in 1/1000 seconds, and
2696 * are converted into jiffies.
2697 *
2698 * Returns 0 on success.
2699 */
8d65af78 2700int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2701 void __user *buffer, size_t *lenp, loff_t *ppos)
2702{
8d65af78 2703 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1da177e4
LT
2704 do_proc_dointvec_ms_jiffies_conv, NULL);
2705}
2706
8d65af78 2707static int proc_do_cad_pid(struct ctl_table *table, int write,
9ec52099
CLG
2708 void __user *buffer, size_t *lenp, loff_t *ppos)
2709{
2710 struct pid *new_pid;
2711 pid_t tmp;
2712 int r;
2713
6c5f3e7b 2714 tmp = pid_vnr(cad_pid);
9ec52099 2715
8d65af78 2716 r = __do_proc_dointvec(&tmp, table, write, buffer,
9ec52099
CLG
2717 lenp, ppos, NULL, NULL);
2718 if (r || !write)
2719 return r;
2720
2721 new_pid = find_get_pid(tmp);
2722 if (!new_pid)
2723 return -ESRCH;
2724
2725 put_pid(xchg(&cad_pid, new_pid));
2726 return 0;
2727}
2728
9f977fb7
OP
2729/**
2730 * proc_do_large_bitmap - read/write from/to a large bitmap
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2736 *
2737 * The bitmap is stored at table->data and the bitmap length (in bits)
2738 * in table->maxlen.
2739 *
2740 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2741 * large bitmaps may be represented in a compact manner. Writing into
2742 * the file will clear the bitmap then update it with the given input.
2743 *
2744 * Returns 0 on success.
2745 */
2746int proc_do_large_bitmap(struct ctl_table *table, int write,
2747 void __user *buffer, size_t *lenp, loff_t *ppos)
2748{
2749 int err = 0;
2750 bool first = 1;
2751 size_t left = *lenp;
2752 unsigned long bitmap_len = table->maxlen;
2753 unsigned long *bitmap = (unsigned long *) table->data;
2754 unsigned long *tmp_bitmap = NULL;
2755 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2756
2757 if (!bitmap_len || !left || (*ppos && !write)) {
2758 *lenp = 0;
2759 return 0;
2760 }
2761
2762 if (write) {
2763 unsigned long page = 0;
2764 char *kbuf;
2765
2766 if (left > PAGE_SIZE - 1)
2767 left = PAGE_SIZE - 1;
2768
2769 page = __get_free_page(GFP_TEMPORARY);
2770 kbuf = (char *) page;
2771 if (!kbuf)
2772 return -ENOMEM;
2773 if (copy_from_user(kbuf, buffer, left)) {
2774 free_page(page);
2775 return -EFAULT;
2776 }
2777 kbuf[left] = 0;
2778
2779 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2780 GFP_KERNEL);
2781 if (!tmp_bitmap) {
2782 free_page(page);
2783 return -ENOMEM;
2784 }
2785 proc_skip_char(&kbuf, &left, '\n');
2786 while (!err && left) {
2787 unsigned long val_a, val_b;
2788 bool neg;
2789
2790 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2791 sizeof(tr_a), &c);
2792 if (err)
2793 break;
2794 if (val_a >= bitmap_len || neg) {
2795 err = -EINVAL;
2796 break;
2797 }
2798
2799 val_b = val_a;
2800 if (left) {
2801 kbuf++;
2802 left--;
2803 }
2804
2805 if (c == '-') {
2806 err = proc_get_long(&kbuf, &left, &val_b,
2807 &neg, tr_b, sizeof(tr_b),
2808 &c);
2809 if (err)
2810 break;
2811 if (val_b >= bitmap_len || neg ||
2812 val_a > val_b) {
2813 err = -EINVAL;
2814 break;
2815 }
2816 if (left) {
2817 kbuf++;
2818 left--;
2819 }
2820 }
2821
2822 while (val_a <= val_b)
2823 set_bit(val_a++, tmp_bitmap);
2824
2825 first = 0;
2826 proc_skip_char(&kbuf, &left, '\n');
2827 }
2828 free_page(page);
2829 } else {
2830 unsigned long bit_a, bit_b = 0;
2831
2832 while (left) {
2833 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2834 if (bit_a >= bitmap_len)
2835 break;
2836 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2837 bit_a + 1) - 1;
2838
2839 if (!first) {
2840 err = proc_put_char(&buffer, &left, ',');
2841 if (err)
2842 break;
2843 }
2844 err = proc_put_long(&buffer, &left, bit_a, false);
2845 if (err)
2846 break;
2847 if (bit_a != bit_b) {
2848 err = proc_put_char(&buffer, &left, '-');
2849 if (err)
2850 break;
2851 err = proc_put_long(&buffer, &left, bit_b, false);
2852 if (err)
2853 break;
2854 }
2855
2856 first = 0; bit_b++;
2857 }
2858 if (!err)
2859 err = proc_put_char(&buffer, &left, '\n');
2860 }
2861
2862 if (!err) {
2863 if (write) {
2864 if (*ppos)
2865 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2866 else
2867 memcpy(bitmap, tmp_bitmap,
2868 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2869 }
2870 kfree(tmp_bitmap);
2871 *lenp -= left;
2872 *ppos += *lenp;
2873 return 0;
2874 } else {
2875 kfree(tmp_bitmap);
2876 return err;
2877 }
2878}
2879
1da177e4
LT
2880#else /* CONFIG_PROC_FS */
2881
8d65af78 2882int proc_dostring(struct ctl_table *table, int write,
1da177e4
LT
2883 void __user *buffer, size_t *lenp, loff_t *ppos)
2884{
2885 return -ENOSYS;
2886}
2887
8d65af78 2888int proc_dointvec(struct ctl_table *table, int write,
1da177e4 2889 void __user *buffer, size_t *lenp, loff_t *ppos)
1da177e4
LT
2890{
2891 return -ENOSYS;
2892}
2893
8d65af78 2894int proc_dointvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2895 void __user *buffer, size_t *lenp, loff_t *ppos)
2896{
2897 return -ENOSYS;
2898}
2899
8d65af78 2900int proc_dointvec_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2901 void __user *buffer, size_t *lenp, loff_t *ppos)
2902{
2903 return -ENOSYS;
2904}
2905
8d65af78 2906int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2907 void __user *buffer, size_t *lenp, loff_t *ppos)
2908{
2909 return -ENOSYS;
2910}
2911
8d65af78 2912int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2913 void __user *buffer, size_t *lenp, loff_t *ppos)
2914{
2915 return -ENOSYS;
2916}
2917
8d65af78 2918int proc_doulongvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2919 void __user *buffer, size_t *lenp, loff_t *ppos)
2920{
2921 return -ENOSYS;
2922}
2923
d8217f07 2924int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2925 void __user *buffer,
2926 size_t *lenp, loff_t *ppos)
2927{
2928 return -ENOSYS;
2929}
2930
2931
2932#endif /* CONFIG_PROC_FS */
2933
1da177e4
LT
2934/*
2935 * No sense putting this after each symbol definition, twice,
2936 * exception granted :-)
2937 */
2938EXPORT_SYMBOL(proc_dointvec);
2939EXPORT_SYMBOL(proc_dointvec_jiffies);
2940EXPORT_SYMBOL(proc_dointvec_minmax);
2941EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2942EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2943EXPORT_SYMBOL(proc_dostring);
2944EXPORT_SYMBOL(proc_doulongvec_minmax);
2945EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2946EXPORT_SYMBOL(register_sysctl_table);
29e796fd 2947EXPORT_SYMBOL(register_sysctl_paths);
1da177e4 2948EXPORT_SYMBOL(unregister_sysctl_table);