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