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