]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/sysctl.c
printk: declare printk_ratelimit_state in ratelimit.h
[net-next-2.6.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 },
7ef3d2fd 705#endif
1da177e4 706 {
1da177e4
LT
707 .procname = "ngroups_max",
708 .data = &ngroups_max,
709 .maxlen = sizeof (int),
710 .mode = 0444,
6d456111 711 .proc_handler = proc_dointvec,
1da177e4 712 },
58687acb 713#if defined(CONFIG_LOCKUP_DETECTOR)
504d7cf1 714 {
58687acb
DZ
715 .procname = "watchdog",
716 .data = &watchdog_enabled,
504d7cf1
DZ
717 .maxlen = sizeof (int),
718 .mode = 0644,
58687acb
DZ
719 .proc_handler = proc_dowatchdog_enabled,
720 },
721 {
722 .procname = "watchdog_thresh",
723 .data = &softlockup_thresh,
724 .maxlen = sizeof(int),
725 .mode = 0644,
726 .proc_handler = proc_dowatchdog_thresh,
727 .extra1 = &neg_one,
728 .extra2 = &sixty,
504d7cf1 729 },
2508ce18
DZ
730 {
731 .procname = "softlockup_panic",
732 .data = &softlockup_panic,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = proc_dointvec_minmax,
736 .extra1 = &zero,
737 .extra2 = &one,
738 },
504d7cf1 739#endif
58687acb 740#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
1da177e4 741 {
1da177e4
LT
742 .procname = "unknown_nmi_panic",
743 .data = &unknown_nmi_panic,
744 .maxlen = sizeof (int),
745 .mode = 0644,
6d456111 746 .proc_handler = proc_dointvec,
1da177e4 747 },
407984f1 748 {
407984f1
DZ
749 .procname = "nmi_watchdog",
750 .data = &nmi_watchdog_enabled,
751 .maxlen = sizeof (int),
752 .mode = 0644,
6d456111 753 .proc_handler = proc_nmi_enabled,
1da177e4
LT
754 },
755#endif
756#if defined(CONFIG_X86)
8da5adda 757 {
8da5adda
DZ
758 .procname = "panic_on_unrecovered_nmi",
759 .data = &panic_on_unrecovered_nmi,
760 .maxlen = sizeof(int),
761 .mode = 0644,
6d456111 762 .proc_handler = proc_dointvec,
8da5adda 763 },
5211a242 764 {
5211a242
KG
765 .procname = "panic_on_io_nmi",
766 .data = &panic_on_io_nmi,
767 .maxlen = sizeof(int),
768 .mode = 0644,
6d456111 769 .proc_handler = proc_dointvec,
5211a242 770 },
1da177e4 771 {
1da177e4
LT
772 .procname = "bootloader_type",
773 .data = &bootloader_type,
774 .maxlen = sizeof (int),
775 .mode = 0444,
6d456111 776 .proc_handler = proc_dointvec,
1da177e4 777 },
5031296c 778 {
5031296c
PA
779 .procname = "bootloader_version",
780 .data = &bootloader_version,
781 .maxlen = sizeof (int),
782 .mode = 0444,
6d456111 783 .proc_handler = proc_dointvec,
5031296c 784 },
0741f4d2 785 {
0741f4d2
CE
786 .procname = "kstack_depth_to_print",
787 .data = &kstack_depth_to_print,
788 .maxlen = sizeof(int),
789 .mode = 0644,
6d456111 790 .proc_handler = proc_dointvec,
0741f4d2 791 },
6e7c4025 792 {
6e7c4025
IM
793 .procname = "io_delay_type",
794 .data = &io_delay_type,
795 .maxlen = sizeof(int),
796 .mode = 0644,
6d456111 797 .proc_handler = proc_dointvec,
6e7c4025 798 },
1da177e4 799#endif
7a9166e3 800#if defined(CONFIG_MMU)
1da177e4 801 {
1da177e4
LT
802 .procname = "randomize_va_space",
803 .data = &randomize_va_space,
804 .maxlen = sizeof(int),
805 .mode = 0644,
6d456111 806 .proc_handler = proc_dointvec,
1da177e4 807 },
7a9166e3 808#endif
0152fb37 809#if defined(CONFIG_S390) && defined(CONFIG_SMP)
951f22d5 810 {
951f22d5
MS
811 .procname = "spin_retry",
812 .data = &spin_retry,
813 .maxlen = sizeof (int),
814 .mode = 0644,
6d456111 815 .proc_handler = proc_dointvec,
951f22d5 816 },
c255d844 817#endif
673d5b43 818#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
c255d844 819 {
c255d844 820 .procname = "acpi_video_flags",
77afcf78 821 .data = &acpi_realmode_flags,
c255d844
PM
822 .maxlen = sizeof (unsigned long),
823 .mode = 0644,
6d456111 824 .proc_handler = proc_doulongvec_minmax,
c255d844 825 },
d2b176ed
JS
826#endif
827#ifdef CONFIG_IA64
828 {
d2b176ed
JS
829 .procname = "ignore-unaligned-usertrap",
830 .data = &no_unaligned_warning,
831 .maxlen = sizeof (int),
832 .mode = 0644,
6d456111 833 .proc_handler = proc_dointvec,
d2b176ed 834 },
88fc241f 835 {
88fc241f
DC
836 .procname = "unaligned-dump-stack",
837 .data = &unaligned_dump_stack,
838 .maxlen = sizeof (int),
839 .mode = 0644,
6d456111 840 .proc_handler = proc_dointvec,
88fc241f 841 },
bebfa101 842#endif
e162b39a
MSB
843#ifdef CONFIG_DETECT_HUNG_TASK
844 {
e162b39a
MSB
845 .procname = "hung_task_panic",
846 .data = &sysctl_hung_task_panic,
847 .maxlen = sizeof(int),
848 .mode = 0644,
6d456111 849 .proc_handler = proc_dointvec_minmax,
e162b39a
MSB
850 .extra1 = &zero,
851 .extra2 = &one,
852 },
82a1fcb9 853 {
82a1fcb9
IM
854 .procname = "hung_task_check_count",
855 .data = &sysctl_hung_task_check_count,
90739081 856 .maxlen = sizeof(unsigned long),
82a1fcb9 857 .mode = 0644,
6d456111 858 .proc_handler = proc_doulongvec_minmax,
82a1fcb9
IM
859 },
860 {
82a1fcb9
IM
861 .procname = "hung_task_timeout_secs",
862 .data = &sysctl_hung_task_timeout_secs,
90739081 863 .maxlen = sizeof(unsigned long),
82a1fcb9 864 .mode = 0644,
6d456111 865 .proc_handler = proc_dohung_task_timeout_secs,
82a1fcb9
IM
866 },
867 {
82a1fcb9
IM
868 .procname = "hung_task_warnings",
869 .data = &sysctl_hung_task_warnings,
90739081 870 .maxlen = sizeof(unsigned long),
82a1fcb9 871 .mode = 0644,
6d456111 872 .proc_handler = proc_doulongvec_minmax,
82a1fcb9 873 },
c4f3b63f 874#endif
bebfa101
AK
875#ifdef CONFIG_COMPAT
876 {
bebfa101
AK
877 .procname = "compat-log",
878 .data = &compat_log,
879 .maxlen = sizeof (int),
880 .mode = 0644,
6d456111 881 .proc_handler = proc_dointvec,
bebfa101 882 },
951f22d5 883#endif
23f78d4a
IM
884#ifdef CONFIG_RT_MUTEXES
885 {
23f78d4a
IM
886 .procname = "max_lock_depth",
887 .data = &max_lock_depth,
888 .maxlen = sizeof(int),
889 .mode = 0644,
6d456111 890 .proc_handler = proc_dointvec,
23f78d4a 891 },
5096add8 892#endif
10a0a8d4 893 {
10a0a8d4
JF
894 .procname = "poweroff_cmd",
895 .data = &poweroff_cmd,
896 .maxlen = POWEROFF_CMD_PATH_LEN,
897 .mode = 0644,
6d456111 898 .proc_handler = proc_dostring,
10a0a8d4 899 },
0b77f5bf
DH
900#ifdef CONFIG_KEYS
901 {
0b77f5bf
DH
902 .procname = "keys",
903 .mode = 0555,
904 .child = key_sysctls,
905 },
906#endif
31a72bce
PM
907#ifdef CONFIG_RCU_TORTURE_TEST
908 {
31a72bce
PM
909 .procname = "rcutorture_runnable",
910 .data = &rcutorture_runnable,
911 .maxlen = sizeof(int),
912 .mode = 0644,
6d456111 913 .proc_handler = proc_dointvec,
31a72bce
PM
914 },
915#endif
cdd6c482 916#ifdef CONFIG_PERF_EVENTS
1ccd1549 917 {
cdd6c482
IM
918 .procname = "perf_event_paranoid",
919 .data = &sysctl_perf_event_paranoid,
920 .maxlen = sizeof(sysctl_perf_event_paranoid),
1ccd1549 921 .mode = 0644,
6d456111 922 .proc_handler = proc_dointvec,
1ccd1549 923 },
c5078f78 924 {
cdd6c482
IM
925 .procname = "perf_event_mlock_kb",
926 .data = &sysctl_perf_event_mlock,
927 .maxlen = sizeof(sysctl_perf_event_mlock),
c5078f78 928 .mode = 0644,
6d456111 929 .proc_handler = proc_dointvec,
c5078f78 930 },
a78ac325 931 {
cdd6c482
IM
932 .procname = "perf_event_max_sample_rate",
933 .data = &sysctl_perf_event_sample_rate,
934 .maxlen = sizeof(sysctl_perf_event_sample_rate),
a78ac325 935 .mode = 0644,
6d456111 936 .proc_handler = proc_dointvec,
a78ac325 937 },
1ccd1549 938#endif
dfec072e
VN
939#ifdef CONFIG_KMEMCHECK
940 {
dfec072e
VN
941 .procname = "kmemcheck",
942 .data = &kmemcheck_enabled,
943 .maxlen = sizeof(int),
944 .mode = 0644,
6d456111 945 .proc_handler = proc_dointvec,
dfec072e
VN
946 },
947#endif
cb684b5b 948#ifdef CONFIG_BLOCK
5e605b64 949 {
5e605b64
JA
950 .procname = "blk_iopoll",
951 .data = &blk_iopoll_enabled,
952 .maxlen = sizeof(int),
953 .mode = 0644,
6d456111 954 .proc_handler = proc_dointvec,
5e605b64 955 },
cb684b5b 956#endif
ed2c12f3
AM
957/*
958 * NOTE: do not add new entries to this table unless you have read
959 * Documentation/sysctl/ctl_unnumbered.txt
960 */
6fce56ec 961 { }
1da177e4
LT
962};
963
d8217f07 964static struct ctl_table vm_table[] = {
1da177e4 965 {
1da177e4
LT
966 .procname = "overcommit_memory",
967 .data = &sysctl_overcommit_memory,
968 .maxlen = sizeof(sysctl_overcommit_memory),
969 .mode = 0644,
6d456111 970 .proc_handler = proc_dointvec,
1da177e4 971 },
fadd8fbd 972 {
fadd8fbd
KH
973 .procname = "panic_on_oom",
974 .data = &sysctl_panic_on_oom,
975 .maxlen = sizeof(sysctl_panic_on_oom),
976 .mode = 0644,
6d456111 977 .proc_handler = proc_dointvec,
fadd8fbd 978 },
fe071d7e 979 {
fe071d7e
DR
980 .procname = "oom_kill_allocating_task",
981 .data = &sysctl_oom_kill_allocating_task,
982 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
983 .mode = 0644,
6d456111 984 .proc_handler = proc_dointvec,
fe071d7e 985 },
fef1bdd6 986 {
fef1bdd6
DR
987 .procname = "oom_dump_tasks",
988 .data = &sysctl_oom_dump_tasks,
989 .maxlen = sizeof(sysctl_oom_dump_tasks),
990 .mode = 0644,
6d456111 991 .proc_handler = proc_dointvec,
fef1bdd6 992 },
1da177e4 993 {
1da177e4
LT
994 .procname = "overcommit_ratio",
995 .data = &sysctl_overcommit_ratio,
996 .maxlen = sizeof(sysctl_overcommit_ratio),
997 .mode = 0644,
6d456111 998 .proc_handler = proc_dointvec,
1da177e4
LT
999 },
1000 {
1da177e4
LT
1001 .procname = "page-cluster",
1002 .data = &page_cluster,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
6d456111 1005 .proc_handler = proc_dointvec,
1da177e4
LT
1006 },
1007 {
1da177e4
LT
1008 .procname = "dirty_background_ratio",
1009 .data = &dirty_background_ratio,
1010 .maxlen = sizeof(dirty_background_ratio),
1011 .mode = 0644,
6d456111 1012 .proc_handler = dirty_background_ratio_handler,
1da177e4
LT
1013 .extra1 = &zero,
1014 .extra2 = &one_hundred,
1015 },
2da02997 1016 {
2da02997
DR
1017 .procname = "dirty_background_bytes",
1018 .data = &dirty_background_bytes,
1019 .maxlen = sizeof(dirty_background_bytes),
1020 .mode = 0644,
6d456111 1021 .proc_handler = dirty_background_bytes_handler,
fc3501d4 1022 .extra1 = &one_ul,
2da02997 1023 },
1da177e4 1024 {
1da177e4
LT
1025 .procname = "dirty_ratio",
1026 .data = &vm_dirty_ratio,
1027 .maxlen = sizeof(vm_dirty_ratio),
1028 .mode = 0644,
6d456111 1029 .proc_handler = dirty_ratio_handler,
1da177e4
LT
1030 .extra1 = &zero,
1031 .extra2 = &one_hundred,
1032 },
2da02997 1033 {
2da02997
DR
1034 .procname = "dirty_bytes",
1035 .data = &vm_dirty_bytes,
1036 .maxlen = sizeof(vm_dirty_bytes),
1037 .mode = 0644,
6d456111 1038 .proc_handler = dirty_bytes_handler,
9e4a5bda 1039 .extra1 = &dirty_bytes_min,
2da02997 1040 },
1da177e4 1041 {
1da177e4 1042 .procname = "dirty_writeback_centisecs",
f6ef9438
BS
1043 .data = &dirty_writeback_interval,
1044 .maxlen = sizeof(dirty_writeback_interval),
1da177e4 1045 .mode = 0644,
6d456111 1046 .proc_handler = dirty_writeback_centisecs_handler,
1da177e4
LT
1047 },
1048 {
1da177e4 1049 .procname = "dirty_expire_centisecs",
f6ef9438
BS
1050 .data = &dirty_expire_interval,
1051 .maxlen = sizeof(dirty_expire_interval),
1da177e4 1052 .mode = 0644,
6d456111 1053 .proc_handler = proc_dointvec,
1da177e4
LT
1054 },
1055 {
1da177e4
LT
1056 .procname = "nr_pdflush_threads",
1057 .data = &nr_pdflush_threads,
1058 .maxlen = sizeof nr_pdflush_threads,
1059 .mode = 0444 /* read-only*/,
6d456111 1060 .proc_handler = proc_dointvec,
1da177e4
LT
1061 },
1062 {
1da177e4
LT
1063 .procname = "swappiness",
1064 .data = &vm_swappiness,
1065 .maxlen = sizeof(vm_swappiness),
1066 .mode = 0644,
6d456111 1067 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1068 .extra1 = &zero,
1069 .extra2 = &one_hundred,
1070 },
1071#ifdef CONFIG_HUGETLB_PAGE
06808b08 1072 {
1da177e4 1073 .procname = "nr_hugepages",
e5ff2159 1074 .data = NULL,
1da177e4
LT
1075 .maxlen = sizeof(unsigned long),
1076 .mode = 0644,
6d456111 1077 .proc_handler = hugetlb_sysctl_handler,
1da177e4
LT
1078 .extra1 = (void *)&hugetlb_zero,
1079 .extra2 = (void *)&hugetlb_infinity,
06808b08
LS
1080 },
1081#ifdef CONFIG_NUMA
1082 {
1083 .procname = "nr_hugepages_mempolicy",
1084 .data = NULL,
1085 .maxlen = sizeof(unsigned long),
1086 .mode = 0644,
1087 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1088 .extra1 = (void *)&hugetlb_zero,
1089 .extra2 = (void *)&hugetlb_infinity,
1090 },
1091#endif
1da177e4 1092 {
1da177e4
LT
1093 .procname = "hugetlb_shm_group",
1094 .data = &sysctl_hugetlb_shm_group,
1095 .maxlen = sizeof(gid_t),
1096 .mode = 0644,
6d456111 1097 .proc_handler = proc_dointvec,
1da177e4 1098 },
396faf03 1099 {
396faf03
MG
1100 .procname = "hugepages_treat_as_movable",
1101 .data = &hugepages_treat_as_movable,
1102 .maxlen = sizeof(int),
1103 .mode = 0644,
6d456111 1104 .proc_handler = hugetlb_treat_movable_handler,
396faf03 1105 },
d1c3fb1f 1106 {
d1c3fb1f 1107 .procname = "nr_overcommit_hugepages",
e5ff2159
AK
1108 .data = NULL,
1109 .maxlen = sizeof(unsigned long),
d1c3fb1f 1110 .mode = 0644,
6d456111 1111 .proc_handler = hugetlb_overcommit_handler,
e5ff2159
AK
1112 .extra1 = (void *)&hugetlb_zero,
1113 .extra2 = (void *)&hugetlb_infinity,
d1c3fb1f 1114 },
1da177e4
LT
1115#endif
1116 {
1da177e4
LT
1117 .procname = "lowmem_reserve_ratio",
1118 .data = &sysctl_lowmem_reserve_ratio,
1119 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1120 .mode = 0644,
6d456111 1121 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1da177e4 1122 },
9d0243bc 1123 {
9d0243bc
AM
1124 .procname = "drop_caches",
1125 .data = &sysctl_drop_caches,
1126 .maxlen = sizeof(int),
1127 .mode = 0644,
1128 .proc_handler = drop_caches_sysctl_handler,
9d0243bc 1129 },
76ab0f53
MG
1130#ifdef CONFIG_COMPACTION
1131 {
1132 .procname = "compact_memory",
1133 .data = &sysctl_compact_memory,
1134 .maxlen = sizeof(int),
1135 .mode = 0200,
1136 .proc_handler = sysctl_compaction_handler,
1137 },
5e771905
MG
1138 {
1139 .procname = "extfrag_threshold",
1140 .data = &sysctl_extfrag_threshold,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
1143 .proc_handler = sysctl_extfrag_handler,
1144 .extra1 = &min_extfrag_threshold,
1145 .extra2 = &max_extfrag_threshold,
1146 },
1147
76ab0f53 1148#endif /* CONFIG_COMPACTION */
1da177e4 1149 {
1da177e4
LT
1150 .procname = "min_free_kbytes",
1151 .data = &min_free_kbytes,
1152 .maxlen = sizeof(min_free_kbytes),
1153 .mode = 0644,
6d456111 1154 .proc_handler = min_free_kbytes_sysctl_handler,
1da177e4
LT
1155 .extra1 = &zero,
1156 },
8ad4b1fb 1157 {
8ad4b1fb
RS
1158 .procname = "percpu_pagelist_fraction",
1159 .data = &percpu_pagelist_fraction,
1160 .maxlen = sizeof(percpu_pagelist_fraction),
1161 .mode = 0644,
6d456111 1162 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
8ad4b1fb
RS
1163 .extra1 = &min_percpu_pagelist_fract,
1164 },
1da177e4
LT
1165#ifdef CONFIG_MMU
1166 {
1da177e4
LT
1167 .procname = "max_map_count",
1168 .data = &sysctl_max_map_count,
1169 .maxlen = sizeof(sysctl_max_map_count),
1170 .mode = 0644,
3e26120c 1171 .proc_handler = proc_dointvec_minmax,
70da2340 1172 .extra1 = &zero,
1da177e4 1173 },
dd8632a1
PM
1174#else
1175 {
dd8632a1
PM
1176 .procname = "nr_trim_pages",
1177 .data = &sysctl_nr_trim_pages,
1178 .maxlen = sizeof(sysctl_nr_trim_pages),
1179 .mode = 0644,
6d456111 1180 .proc_handler = proc_dointvec_minmax,
dd8632a1
PM
1181 .extra1 = &zero,
1182 },
1da177e4
LT
1183#endif
1184 {
1da177e4
LT
1185 .procname = "laptop_mode",
1186 .data = &laptop_mode,
1187 .maxlen = sizeof(laptop_mode),
1188 .mode = 0644,
6d456111 1189 .proc_handler = proc_dointvec_jiffies,
1da177e4
LT
1190 },
1191 {
1da177e4
LT
1192 .procname = "block_dump",
1193 .data = &block_dump,
1194 .maxlen = sizeof(block_dump),
1195 .mode = 0644,
6d456111 1196 .proc_handler = proc_dointvec,
1da177e4
LT
1197 .extra1 = &zero,
1198 },
1199 {
1da177e4
LT
1200 .procname = "vfs_cache_pressure",
1201 .data = &sysctl_vfs_cache_pressure,
1202 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1203 .mode = 0644,
6d456111 1204 .proc_handler = proc_dointvec,
1da177e4
LT
1205 .extra1 = &zero,
1206 },
1207#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1208 {
1da177e4
LT
1209 .procname = "legacy_va_layout",
1210 .data = &sysctl_legacy_va_layout,
1211 .maxlen = sizeof(sysctl_legacy_va_layout),
1212 .mode = 0644,
6d456111 1213 .proc_handler = proc_dointvec,
1da177e4
LT
1214 .extra1 = &zero,
1215 },
1216#endif
1743660b
CL
1217#ifdef CONFIG_NUMA
1218 {
1743660b
CL
1219 .procname = "zone_reclaim_mode",
1220 .data = &zone_reclaim_mode,
1221 .maxlen = sizeof(zone_reclaim_mode),
1222 .mode = 0644,
6d456111 1223 .proc_handler = proc_dointvec,
c84db23c 1224 .extra1 = &zero,
1743660b 1225 },
9614634f 1226 {
9614634f
CL
1227 .procname = "min_unmapped_ratio",
1228 .data = &sysctl_min_unmapped_ratio,
1229 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1230 .mode = 0644,
6d456111 1231 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
9614634f
CL
1232 .extra1 = &zero,
1233 .extra2 = &one_hundred,
1234 },
0ff38490 1235 {
0ff38490
CL
1236 .procname = "min_slab_ratio",
1237 .data = &sysctl_min_slab_ratio,
1238 .maxlen = sizeof(sysctl_min_slab_ratio),
1239 .mode = 0644,
6d456111 1240 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
0ff38490
CL
1241 .extra1 = &zero,
1242 .extra2 = &one_hundred,
1243 },
e6e5494c 1244#endif
77461ab3
CL
1245#ifdef CONFIG_SMP
1246 {
77461ab3
CL
1247 .procname = "stat_interval",
1248 .data = &sysctl_stat_interval,
1249 .maxlen = sizeof(sysctl_stat_interval),
1250 .mode = 0644,
6d456111 1251 .proc_handler = proc_dointvec_jiffies,
77461ab3
CL
1252 },
1253#endif
6e141546 1254#ifdef CONFIG_MMU
ed032189 1255 {
ed032189 1256 .procname = "mmap_min_addr",
788084ab
EP
1257 .data = &dac_mmap_min_addr,
1258 .maxlen = sizeof(unsigned long),
ed032189 1259 .mode = 0644,
6d456111 1260 .proc_handler = mmap_min_addr_handler,
ed032189 1261 },
6e141546 1262#endif
f0c0b2b8
KH
1263#ifdef CONFIG_NUMA
1264 {
f0c0b2b8
KH
1265 .procname = "numa_zonelist_order",
1266 .data = &numa_zonelist_order,
1267 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1268 .mode = 0644,
6d456111 1269 .proc_handler = numa_zonelist_order_handler,
f0c0b2b8
KH
1270 },
1271#endif
2b8232ce 1272#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
5c36e657 1273 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
e6e5494c 1274 {
e6e5494c
IM
1275 .procname = "vdso_enabled",
1276 .data = &vdso_enabled,
1277 .maxlen = sizeof(vdso_enabled),
1278 .mode = 0644,
6d456111 1279 .proc_handler = proc_dointvec,
e6e5494c
IM
1280 .extra1 = &zero,
1281 },
1da177e4 1282#endif
195cf453
BG
1283#ifdef CONFIG_HIGHMEM
1284 {
195cf453
BG
1285 .procname = "highmem_is_dirtyable",
1286 .data = &vm_highmem_is_dirtyable,
1287 .maxlen = sizeof(vm_highmem_is_dirtyable),
1288 .mode = 0644,
6d456111 1289 .proc_handler = proc_dointvec_minmax,
195cf453
BG
1290 .extra1 = &zero,
1291 .extra2 = &one,
1292 },
1293#endif
4be6f6bb 1294 {
4be6f6bb
PZ
1295 .procname = "scan_unevictable_pages",
1296 .data = &scan_unevictable_pages,
1297 .maxlen = sizeof(scan_unevictable_pages),
1298 .mode = 0644,
6d456111 1299 .proc_handler = scan_unevictable_handler,
4be6f6bb 1300 },
6a46079c
AK
1301#ifdef CONFIG_MEMORY_FAILURE
1302 {
6a46079c
AK
1303 .procname = "memory_failure_early_kill",
1304 .data = &sysctl_memory_failure_early_kill,
1305 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1306 .mode = 0644,
6d456111 1307 .proc_handler = proc_dointvec_minmax,
6a46079c
AK
1308 .extra1 = &zero,
1309 .extra2 = &one,
1310 },
1311 {
6a46079c
AK
1312 .procname = "memory_failure_recovery",
1313 .data = &sysctl_memory_failure_recovery,
1314 .maxlen = sizeof(sysctl_memory_failure_recovery),
1315 .mode = 0644,
6d456111 1316 .proc_handler = proc_dointvec_minmax,
6a46079c
AK
1317 .extra1 = &zero,
1318 .extra2 = &one,
1319 },
1320#endif
1321
2be7fe07
AM
1322/*
1323 * NOTE: do not add new entries to this table unless you have read
1324 * Documentation/sysctl/ctl_unnumbered.txt
1325 */
6fce56ec 1326 { }
1da177e4
LT
1327};
1328
2abc26fc 1329#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
d8217f07 1330static struct ctl_table binfmt_misc_table[] = {
6fce56ec 1331 { }
2abc26fc
EB
1332};
1333#endif
1334
d8217f07 1335static struct ctl_table fs_table[] = {
1da177e4 1336 {
1da177e4
LT
1337 .procname = "inode-nr",
1338 .data = &inodes_stat,
1339 .maxlen = 2*sizeof(int),
1340 .mode = 0444,
6d456111 1341 .proc_handler = proc_dointvec,
1da177e4
LT
1342 },
1343 {
1da177e4
LT
1344 .procname = "inode-state",
1345 .data = &inodes_stat,
1346 .maxlen = 7*sizeof(int),
1347 .mode = 0444,
6d456111 1348 .proc_handler = proc_dointvec,
1da177e4
LT
1349 },
1350 {
1da177e4
LT
1351 .procname = "file-nr",
1352 .data = &files_stat,
518de9b3 1353 .maxlen = sizeof(files_stat),
1da177e4 1354 .mode = 0444,
6d456111 1355 .proc_handler = proc_nr_files,
1da177e4
LT
1356 },
1357 {
1da177e4
LT
1358 .procname = "file-max",
1359 .data = &files_stat.max_files,
518de9b3 1360 .maxlen = sizeof(files_stat.max_files),
1da177e4 1361 .mode = 0644,
518de9b3 1362 .proc_handler = proc_doulongvec_minmax,
1da177e4 1363 },
9cfe015a 1364 {
9cfe015a
ED
1365 .procname = "nr_open",
1366 .data = &sysctl_nr_open,
1367 .maxlen = sizeof(int),
1368 .mode = 0644,
6d456111 1369 .proc_handler = proc_dointvec_minmax,
eceea0b3
AV
1370 .extra1 = &sysctl_nr_open_min,
1371 .extra2 = &sysctl_nr_open_max,
9cfe015a 1372 },
1da177e4 1373 {
1da177e4
LT
1374 .procname = "dentry-state",
1375 .data = &dentry_stat,
1376 .maxlen = 6*sizeof(int),
1377 .mode = 0444,
6d456111 1378 .proc_handler = proc_dointvec,
1da177e4
LT
1379 },
1380 {
1da177e4
LT
1381 .procname = "overflowuid",
1382 .data = &fs_overflowuid,
1383 .maxlen = sizeof(int),
1384 .mode = 0644,
6d456111 1385 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1386 .extra1 = &minolduid,
1387 .extra2 = &maxolduid,
1388 },
1389 {
1da177e4
LT
1390 .procname = "overflowgid",
1391 .data = &fs_overflowgid,
1392 .maxlen = sizeof(int),
1393 .mode = 0644,
6d456111 1394 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1395 .extra1 = &minolduid,
1396 .extra2 = &maxolduid,
1397 },
bfcd17a6 1398#ifdef CONFIG_FILE_LOCKING
1da177e4 1399 {
1da177e4
LT
1400 .procname = "leases-enable",
1401 .data = &leases_enable,
1402 .maxlen = sizeof(int),
1403 .mode = 0644,
6d456111 1404 .proc_handler = proc_dointvec,
1da177e4 1405 },
bfcd17a6 1406#endif
1da177e4
LT
1407#ifdef CONFIG_DNOTIFY
1408 {
1da177e4
LT
1409 .procname = "dir-notify-enable",
1410 .data = &dir_notify_enable,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
6d456111 1413 .proc_handler = proc_dointvec,
1da177e4
LT
1414 },
1415#endif
1416#ifdef CONFIG_MMU
bfcd17a6 1417#ifdef CONFIG_FILE_LOCKING
1da177e4 1418 {
1da177e4
LT
1419 .procname = "lease-break-time",
1420 .data = &lease_break_time,
1421 .maxlen = sizeof(int),
1422 .mode = 0644,
6d456111 1423 .proc_handler = proc_dointvec,
1da177e4 1424 },
bfcd17a6 1425#endif
ebf3f09c 1426#ifdef CONFIG_AIO
1da177e4 1427 {
1da177e4
LT
1428 .procname = "aio-nr",
1429 .data = &aio_nr,
1430 .maxlen = sizeof(aio_nr),
1431 .mode = 0444,
6d456111 1432 .proc_handler = proc_doulongvec_minmax,
1da177e4
LT
1433 },
1434 {
1da177e4
LT
1435 .procname = "aio-max-nr",
1436 .data = &aio_max_nr,
1437 .maxlen = sizeof(aio_max_nr),
1438 .mode = 0644,
6d456111 1439 .proc_handler = proc_doulongvec_minmax,
1da177e4 1440 },
ebf3f09c 1441#endif /* CONFIG_AIO */
2d9048e2 1442#ifdef CONFIG_INOTIFY_USER
0399cb08 1443 {
0399cb08
RL
1444 .procname = "inotify",
1445 .mode = 0555,
1446 .child = inotify_table,
1447 },
1448#endif
7ef9964e
DL
1449#ifdef CONFIG_EPOLL
1450 {
1451 .procname = "epoll",
1452 .mode = 0555,
1453 .child = epoll_table,
1454 },
1455#endif
1da177e4 1456#endif
d6e71144 1457 {
d6e71144
AC
1458 .procname = "suid_dumpable",
1459 .data = &suid_dumpable,
1460 .maxlen = sizeof(int),
1461 .mode = 0644,
6d456111 1462 .proc_handler = proc_dointvec_minmax,
8e654fba
MW
1463 .extra1 = &zero,
1464 .extra2 = &two,
d6e71144 1465 },
2abc26fc
EB
1466#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1467 {
2abc26fc
EB
1468 .procname = "binfmt_misc",
1469 .mode = 0555,
1470 .child = binfmt_misc_table,
1471 },
1472#endif
b492e95b 1473 {
ff9da691
JA
1474 .procname = "pipe-max-size",
1475 .data = &pipe_max_size,
b492e95b
JA
1476 .maxlen = sizeof(int),
1477 .mode = 0644,
ff9da691
JA
1478 .proc_handler = &pipe_proc_fn,
1479 .extra1 = &pipe_min_size,
b492e95b 1480 },
2be7fe07
AM
1481/*
1482 * NOTE: do not add new entries to this table unless you have read
1483 * Documentation/sysctl/ctl_unnumbered.txt
2be7fe07 1484 */
6fce56ec 1485 { }
1da177e4
LT
1486};
1487
d8217f07 1488static struct ctl_table debug_table[] = {
ab3c68ee
HC
1489#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1490 defined(CONFIG_S390)
abd4f750 1491 {
abd4f750
MAS
1492 .procname = "exception-trace",
1493 .data = &show_unhandled_signals,
1494 .maxlen = sizeof(int),
1495 .mode = 0644,
1496 .proc_handler = proc_dointvec
1497 },
b2be84df
MH
1498#endif
1499#if defined(CONFIG_OPTPROBES)
1500 {
1501 .procname = "kprobes-optimization",
1502 .data = &sysctl_kprobes_optimization,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
1505 .proc_handler = proc_kprobes_optimization_handler,
1506 .extra1 = &zero,
1507 .extra2 = &one,
1508 },
abd4f750 1509#endif
6fce56ec 1510 { }
1da177e4
LT
1511};
1512
d8217f07 1513static struct ctl_table dev_table[] = {
6fce56ec 1514 { }
0eeca283 1515};
1da177e4 1516
330d57fb
AV
1517static DEFINE_SPINLOCK(sysctl_lock);
1518
1519/* called under sysctl_lock */
1520static int use_table(struct ctl_table_header *p)
1521{
1522 if (unlikely(p->unregistering))
1523 return 0;
1524 p->used++;
1525 return 1;
1526}
1527
1528/* called under sysctl_lock */
1529static void unuse_table(struct ctl_table_header *p)
1530{
1531 if (!--p->used)
1532 if (unlikely(p->unregistering))
1533 complete(p->unregistering);
1534}
1535
1536/* called under sysctl_lock, will reacquire if has to wait */
1537static void start_unregistering(struct ctl_table_header *p)
1538{
1539 /*
1540 * if p->used is 0, nobody will ever touch that entry again;
1541 * we'll eliminate all paths to it before dropping sysctl_lock
1542 */
1543 if (unlikely(p->used)) {
1544 struct completion wait;
1545 init_completion(&wait);
1546 p->unregistering = &wait;
1547 spin_unlock(&sysctl_lock);
1548 wait_for_completion(&wait);
1549 spin_lock(&sysctl_lock);
f7e6ced4
AV
1550 } else {
1551 /* anything non-NULL; we'll never dereference it */
1552 p->unregistering = ERR_PTR(-EINVAL);
330d57fb
AV
1553 }
1554 /*
1555 * do not remove from the list until nobody holds it; walking the
1556 * list in do_sysctl() relies on that.
1557 */
1558 list_del_init(&p->ctl_entry);
1559}
1560
f7e6ced4
AV
1561void sysctl_head_get(struct ctl_table_header *head)
1562{
1563 spin_lock(&sysctl_lock);
1564 head->count++;
1565 spin_unlock(&sysctl_lock);
1566}
1567
1568void sysctl_head_put(struct ctl_table_header *head)
1569{
1570 spin_lock(&sysctl_lock);
1571 if (!--head->count)
1572 kfree(head);
1573 spin_unlock(&sysctl_lock);
1574}
1575
1576struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1577{
1578 if (!head)
1579 BUG();
1580 spin_lock(&sysctl_lock);
1581 if (!use_table(head))
1582 head = ERR_PTR(-ENOENT);
1583 spin_unlock(&sysctl_lock);
1584 return head;
1585}
1586
805b5d5e
EB
1587void sysctl_head_finish(struct ctl_table_header *head)
1588{
1589 if (!head)
1590 return;
1591 spin_lock(&sysctl_lock);
1592 unuse_table(head);
1593 spin_unlock(&sysctl_lock);
1594}
1595
73455092
AV
1596static struct ctl_table_set *
1597lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1598{
1599 struct ctl_table_set *set = &root->default_set;
1600 if (root->lookup)
1601 set = root->lookup(root, namespaces);
1602 return set;
1603}
1604
e51b6ba0
EB
1605static struct list_head *
1606lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
805b5d5e 1607{
73455092
AV
1608 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1609 return &set->list;
e51b6ba0
EB
1610}
1611
1612struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1613 struct ctl_table_header *prev)
1614{
1615 struct ctl_table_root *root;
1616 struct list_head *header_list;
805b5d5e
EB
1617 struct ctl_table_header *head;
1618 struct list_head *tmp;
e51b6ba0 1619
805b5d5e
EB
1620 spin_lock(&sysctl_lock);
1621 if (prev) {
e51b6ba0 1622 head = prev;
805b5d5e
EB
1623 tmp = &prev->ctl_entry;
1624 unuse_table(prev);
1625 goto next;
1626 }
1627 tmp = &root_table_header.ctl_entry;
1628 for (;;) {
1629 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1630
1631 if (!use_table(head))
1632 goto next;
1633 spin_unlock(&sysctl_lock);
1634 return head;
1635 next:
e51b6ba0 1636 root = head->root;
805b5d5e 1637 tmp = tmp->next;
e51b6ba0
EB
1638 header_list = lookup_header_list(root, namespaces);
1639 if (tmp != header_list)
1640 continue;
1641
1642 do {
1643 root = list_entry(root->root_list.next,
1644 struct ctl_table_root, root_list);
1645 if (root == &sysctl_table_root)
1646 goto out;
1647 header_list = lookup_header_list(root, namespaces);
1648 } while (list_empty(header_list));
1649 tmp = header_list->next;
805b5d5e 1650 }
e51b6ba0 1651out:
805b5d5e
EB
1652 spin_unlock(&sysctl_lock);
1653 return NULL;
1654}
1655
e51b6ba0
EB
1656struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1657{
1658 return __sysctl_head_next(current->nsproxy, prev);
1659}
1660
1661void register_sysctl_root(struct ctl_table_root *root)
1662{
1663 spin_lock(&sysctl_lock);
1664 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1665 spin_unlock(&sysctl_lock);
1666}
1667
1da177e4 1668/*
1ff007eb 1669 * sysctl_perm does NOT grant the superuser all rights automatically, because
1da177e4
LT
1670 * some sysctl variables are readonly even to root.
1671 */
1672
1673static int test_perm(int mode, int op)
1674{
76aac0e9 1675 if (!current_euid())
1da177e4
LT
1676 mode >>= 6;
1677 else if (in_egroup_p(0))
1678 mode >>= 3;
e6305c43 1679 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1da177e4
LT
1680 return 0;
1681 return -EACCES;
1682}
1683
d7321cd6 1684int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1da177e4
LT
1685{
1686 int error;
d7321cd6
PE
1687 int mode;
1688
e6305c43 1689 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1da177e4
LT
1690 if (error)
1691 return error;
d7321cd6
PE
1692
1693 if (root->permissions)
1694 mode = root->permissions(root, current->nsproxy, table);
1695 else
1696 mode = table->mode;
1697
1698 return test_perm(mode, op);
1da177e4
LT
1699}
1700
d912b0cc
EB
1701static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1702{
2315ffa0 1703 for (; table->procname; table++) {
d912b0cc
EB
1704 table->parent = parent;
1705 if (table->child)
1706 sysctl_set_parent(table, table->child);
1707 }
1708}
1709
1710static __init int sysctl_init(void)
1711{
1712 sysctl_set_parent(NULL, root_table);
88f458e4 1713#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
b3bd3de6 1714 sysctl_check_table(current->nsproxy, root_table);
88f458e4 1715#endif
d912b0cc
EB
1716 return 0;
1717}
1718
1719core_initcall(sysctl_init);
1720
bfbcf034
AV
1721static struct ctl_table *is_branch_in(struct ctl_table *branch,
1722 struct ctl_table *table)
ae7edecc
AV
1723{
1724 struct ctl_table *p;
1725 const char *s = branch->procname;
1726
1727 /* branch should have named subdirectory as its first element */
1728 if (!s || !branch->child)
bfbcf034 1729 return NULL;
ae7edecc
AV
1730
1731 /* ... and nothing else */
2315ffa0 1732 if (branch[1].procname)
bfbcf034 1733 return NULL;
ae7edecc
AV
1734
1735 /* table should contain subdirectory with the same name */
2315ffa0 1736 for (p = table; p->procname; p++) {
ae7edecc
AV
1737 if (!p->child)
1738 continue;
1739 if (p->procname && strcmp(p->procname, s) == 0)
bfbcf034 1740 return p;
ae7edecc 1741 }
bfbcf034 1742 return NULL;
ae7edecc
AV
1743}
1744
1745/* see if attaching q to p would be an improvement */
1746static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1747{
1748 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
bfbcf034 1749 struct ctl_table *next;
ae7edecc
AV
1750 int is_better = 0;
1751 int not_in_parent = !p->attached_by;
1752
bfbcf034 1753 while ((next = is_branch_in(by, to)) != NULL) {
ae7edecc
AV
1754 if (by == q->attached_by)
1755 is_better = 1;
1756 if (to == p->attached_by)
1757 not_in_parent = 1;
1758 by = by->child;
bfbcf034 1759 to = next->child;
ae7edecc
AV
1760 }
1761
1762 if (is_better && not_in_parent) {
1763 q->attached_by = by;
1764 q->attached_to = to;
1765 q->parent = p;
1766 }
1767}
1768
1da177e4 1769/**
e51b6ba0
EB
1770 * __register_sysctl_paths - register a sysctl hierarchy
1771 * @root: List of sysctl headers to register on
1772 * @namespaces: Data to compute which lists of sysctl entries are visible
29e796fd 1773 * @path: The path to the directory the sysctl table is in.
1da177e4 1774 * @table: the top-level table structure
1da177e4
LT
1775 *
1776 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
29e796fd 1777 * array. A completely 0 filled entry terminates the table.
1da177e4 1778 *
d8217f07 1779 * The members of the &struct ctl_table structure are used as follows:
1da177e4 1780 *
1da177e4
LT
1781 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1782 * enter a sysctl file
1783 *
1784 * data - a pointer to data for use by proc_handler
1785 *
1786 * maxlen - the maximum size in bytes of the data
1787 *
1788 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1789 *
1790 * child - a pointer to the child sysctl table if this entry is a directory, or
1791 * %NULL.
1792 *
1793 * proc_handler - the text handler routine (described below)
1794 *
1da177e4
LT
1795 * de - for internal use by the sysctl routines
1796 *
1797 * extra1, extra2 - extra pointers usable by the proc handler routines
1798 *
1799 * Leaf nodes in the sysctl tree will be represented by a single file
1800 * under /proc; non-leaf nodes will be represented by directories.
1801 *
1802 * sysctl(2) can automatically manage read and write requests through
1803 * the sysctl table. The data and maxlen fields of the ctl_table
1804 * struct enable minimal validation of the values being written to be
1805 * performed, and the mode field allows minimal authentication.
1806 *
1da177e4
LT
1807 * There must be a proc_handler routine for any terminal nodes
1808 * mirrored under /proc/sys (non-terminals are handled by a built-in
1809 * directory handler). Several default handlers are available to
1810 * cover common cases -
1811 *
1812 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1813 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1814 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1815 *
1816 * It is the handler's job to read the input buffer from user memory
1817 * and process it. The handler should return 0 on success.
1818 *
1819 * This routine returns %NULL on a failure to register, and a pointer
1820 * to the table header on success.
1821 */
e51b6ba0
EB
1822struct ctl_table_header *__register_sysctl_paths(
1823 struct ctl_table_root *root,
1824 struct nsproxy *namespaces,
1825 const struct ctl_path *path, struct ctl_table *table)
1da177e4 1826{
29e796fd
EB
1827 struct ctl_table_header *header;
1828 struct ctl_table *new, **prevp;
1829 unsigned int n, npath;
ae7edecc 1830 struct ctl_table_set *set;
29e796fd
EB
1831
1832 /* Count the path components */
2315ffa0 1833 for (npath = 0; path[npath].procname; ++npath)
29e796fd
EB
1834 ;
1835
1836 /*
1837 * For each path component, allocate a 2-element ctl_table array.
1838 * The first array element will be filled with the sysctl entry
2315ffa0 1839 * for this, the second will be the sentinel (procname == 0).
29e796fd
EB
1840 *
1841 * We allocate everything in one go so that we don't have to
1842 * worry about freeing additional memory in unregister_sysctl_table.
1843 */
1844 header = kzalloc(sizeof(struct ctl_table_header) +
1845 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1846 if (!header)
1da177e4 1847 return NULL;
29e796fd
EB
1848
1849 new = (struct ctl_table *) (header + 1);
1850
1851 /* Now connect the dots */
1852 prevp = &header->ctl_table;
1853 for (n = 0; n < npath; ++n, ++path) {
1854 /* Copy the procname */
1855 new->procname = path->procname;
29e796fd
EB
1856 new->mode = 0555;
1857
1858 *prevp = new;
1859 prevp = &new->child;
1860
1861 new += 2;
1862 }
1863 *prevp = table;
23eb06de 1864 header->ctl_table_arg = table;
29e796fd
EB
1865
1866 INIT_LIST_HEAD(&header->ctl_entry);
1867 header->used = 0;
1868 header->unregistering = NULL;
e51b6ba0 1869 header->root = root;
29e796fd 1870 sysctl_set_parent(NULL, header->ctl_table);
f7e6ced4 1871 header->count = 1;
88f458e4 1872#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
e51b6ba0 1873 if (sysctl_check_table(namespaces, header->ctl_table)) {
29e796fd 1874 kfree(header);
fc6cd25b
EB
1875 return NULL;
1876 }
88f458e4 1877#endif
330d57fb 1878 spin_lock(&sysctl_lock);
73455092 1879 header->set = lookup_header_set(root, namespaces);
ae7edecc
AV
1880 header->attached_by = header->ctl_table;
1881 header->attached_to = root_table;
1882 header->parent = &root_table_header;
1883 for (set = header->set; set; set = set->parent) {
1884 struct ctl_table_header *p;
1885 list_for_each_entry(p, &set->list, ctl_entry) {
1886 if (p->unregistering)
1887 continue;
1888 try_attach(p, header);
1889 }
1890 }
1891 header->parent->count++;
73455092 1892 list_add_tail(&header->ctl_entry, &header->set->list);
330d57fb 1893 spin_unlock(&sysctl_lock);
29e796fd
EB
1894
1895 return header;
1896}
1897
e51b6ba0
EB
1898/**
1899 * register_sysctl_table_path - register a sysctl table hierarchy
1900 * @path: The path to the directory the sysctl table is in.
1901 * @table: the top-level table structure
1902 *
1903 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1904 * array. A completely 0 filled entry terminates the table.
1905 *
1906 * See __register_sysctl_paths for more details.
1907 */
1908struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1909 struct ctl_table *table)
1910{
1911 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1912 path, table);
1913}
1914
29e796fd
EB
1915/**
1916 * register_sysctl_table - register a sysctl table hierarchy
1917 * @table: the top-level table structure
1918 *
1919 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1920 * array. A completely 0 filled entry terminates the table.
1921 *
1922 * See register_sysctl_paths for more details.
1923 */
1924struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1925{
1926 static const struct ctl_path null_path[] = { {} };
1927
1928 return register_sysctl_paths(null_path, table);
1da177e4
LT
1929}
1930
1931/**
1932 * unregister_sysctl_table - unregister a sysctl table hierarchy
1933 * @header: the header returned from register_sysctl_table
1934 *
1935 * Unregisters the sysctl table and all children. proc entries may not
1936 * actually be removed until they are no longer used by anyone.
1937 */
1938void unregister_sysctl_table(struct ctl_table_header * header)
1939{
330d57fb 1940 might_sleep();
f1dad166
PE
1941
1942 if (header == NULL)
1943 return;
1944
330d57fb
AV
1945 spin_lock(&sysctl_lock);
1946 start_unregistering(header);
ae7edecc
AV
1947 if (!--header->parent->count) {
1948 WARN_ON(1);
1949 kfree(header->parent);
1950 }
f7e6ced4
AV
1951 if (!--header->count)
1952 kfree(header);
330d57fb 1953 spin_unlock(&sysctl_lock);
1da177e4
LT
1954}
1955
9043476f
AV
1956int sysctl_is_seen(struct ctl_table_header *p)
1957{
1958 struct ctl_table_set *set = p->set;
1959 int res;
1960 spin_lock(&sysctl_lock);
1961 if (p->unregistering)
1962 res = 0;
1963 else if (!set->is_seen)
1964 res = 1;
1965 else
1966 res = set->is_seen(set);
1967 spin_unlock(&sysctl_lock);
1968 return res;
1969}
1970
73455092
AV
1971void setup_sysctl_set(struct ctl_table_set *p,
1972 struct ctl_table_set *parent,
1973 int (*is_seen)(struct ctl_table_set *))
1974{
1975 INIT_LIST_HEAD(&p->list);
1976 p->parent = parent ? parent : &sysctl_table_root.default_set;
1977 p->is_seen = is_seen;
1978}
1979
b89a8171 1980#else /* !CONFIG_SYSCTL */
d8217f07 1981struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
b89a8171
EB
1982{
1983 return NULL;
1984}
1985
29e796fd
EB
1986struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1987 struct ctl_table *table)
1988{
1989 return NULL;
1990}
1991
b89a8171
EB
1992void unregister_sysctl_table(struct ctl_table_header * table)
1993{
1994}
1995
73455092
AV
1996void setup_sysctl_set(struct ctl_table_set *p,
1997 struct ctl_table_set *parent,
1998 int (*is_seen)(struct ctl_table_set *))
1999{
2000}
2001
f7e6ced4
AV
2002void sysctl_head_put(struct ctl_table_header *head)
2003{
2004}
2005
b89a8171
EB
2006#endif /* CONFIG_SYSCTL */
2007
1da177e4
LT
2008/*
2009 * /proc/sys support
2010 */
2011
b89a8171 2012#ifdef CONFIG_PROC_SYSCTL
1da177e4 2013
b1ba4ddd 2014static int _proc_do_string(void* data, int maxlen, int write,
8d65af78 2015 void __user *buffer,
b1ba4ddd 2016 size_t *lenp, loff_t *ppos)
1da177e4
LT
2017{
2018 size_t len;
2019 char __user *p;
2020 char c;
8d060877
ON
2021
2022 if (!data || !maxlen || !*lenp) {
1da177e4
LT
2023 *lenp = 0;
2024 return 0;
2025 }
8d060877 2026
1da177e4
LT
2027 if (write) {
2028 len = 0;
2029 p = buffer;
2030 while (len < *lenp) {
2031 if (get_user(c, p++))
2032 return -EFAULT;
2033 if (c == 0 || c == '\n')
2034 break;
2035 len++;
2036 }
f5dd3d6f
SV
2037 if (len >= maxlen)
2038 len = maxlen-1;
2039 if(copy_from_user(data, buffer, len))
1da177e4 2040 return -EFAULT;
f5dd3d6f 2041 ((char *) data)[len] = 0;
1da177e4
LT
2042 *ppos += *lenp;
2043 } else {
f5dd3d6f
SV
2044 len = strlen(data);
2045 if (len > maxlen)
2046 len = maxlen;
8d060877
ON
2047
2048 if (*ppos > len) {
2049 *lenp = 0;
2050 return 0;
2051 }
2052
2053 data += *ppos;
2054 len -= *ppos;
2055
1da177e4
LT
2056 if (len > *lenp)
2057 len = *lenp;
2058 if (len)
f5dd3d6f 2059 if(copy_to_user(buffer, data, len))
1da177e4
LT
2060 return -EFAULT;
2061 if (len < *lenp) {
2062 if(put_user('\n', ((char __user *) buffer) + len))
2063 return -EFAULT;
2064 len++;
2065 }
2066 *lenp = len;
2067 *ppos += len;
2068 }
2069 return 0;
2070}
2071
f5dd3d6f
SV
2072/**
2073 * proc_dostring - read a string sysctl
2074 * @table: the sysctl table
2075 * @write: %TRUE if this is a write to the sysctl file
f5dd3d6f
SV
2076 * @buffer: the user buffer
2077 * @lenp: the size of the user buffer
2078 * @ppos: file position
2079 *
2080 * Reads/writes a string from/to the user buffer. If the kernel
2081 * buffer provided is not large enough to hold the string, the
2082 * string is truncated. The copied string is %NULL-terminated.
2083 * If the string is being read by the user process, it is copied
2084 * and a newline '\n' is added. It is truncated if the buffer is
2085 * not large enough.
2086 *
2087 * Returns 0 on success.
2088 */
8d65af78 2089int proc_dostring(struct ctl_table *table, int write,
f5dd3d6f
SV
2090 void __user *buffer, size_t *lenp, loff_t *ppos)
2091{
8d65af78 2092 return _proc_do_string(table->data, table->maxlen, write,
f5dd3d6f
SV
2093 buffer, lenp, ppos);
2094}
2095
00b7c339
AW
2096static size_t proc_skip_spaces(char **buf)
2097{
2098 size_t ret;
2099 char *tmp = skip_spaces(*buf);
2100 ret = tmp - *buf;
2101 *buf = tmp;
2102 return ret;
2103}
2104
9f977fb7
OP
2105static void proc_skip_char(char **buf, size_t *size, const char v)
2106{
2107 while (*size) {
2108 if (**buf != v)
2109 break;
2110 (*size)--;
2111 (*buf)++;
2112 }
2113}
2114
00b7c339
AW
2115#define TMPBUFLEN 22
2116/**
0fc377bd 2117 * proc_get_long - reads an ASCII formatted integer from a user buffer
00b7c339 2118 *
0fc377bd
RD
2119 * @buf: a kernel buffer
2120 * @size: size of the kernel buffer
2121 * @val: this is where the number will be stored
2122 * @neg: set to %TRUE if number is negative
2123 * @perm_tr: a vector which contains the allowed trailers
2124 * @perm_tr_len: size of the perm_tr vector
2125 * @tr: pointer to store the trailer character
00b7c339 2126 *
0fc377bd
RD
2127 * In case of success %0 is returned and @buf and @size are updated with
2128 * the amount of bytes read. If @tr is non-NULL and a trailing
2129 * character exists (size is non-zero after returning from this
2130 * function), @tr is updated with the trailing character.
00b7c339
AW
2131 */
2132static int proc_get_long(char **buf, size_t *size,
2133 unsigned long *val, bool *neg,
2134 const char *perm_tr, unsigned perm_tr_len, char *tr)
2135{
2136 int len;
2137 char *p, tmp[TMPBUFLEN];
2138
2139 if (!*size)
2140 return -EINVAL;
2141
2142 len = *size;
2143 if (len > TMPBUFLEN - 1)
2144 len = TMPBUFLEN - 1;
2145
2146 memcpy(tmp, *buf, len);
2147
2148 tmp[len] = 0;
2149 p = tmp;
2150 if (*p == '-' && *size > 1) {
2151 *neg = true;
2152 p++;
2153 } else
2154 *neg = false;
2155 if (!isdigit(*p))
2156 return -EINVAL;
2157
2158 *val = simple_strtoul(p, &p, 0);
2159
2160 len = p - tmp;
2161
2162 /* We don't know if the next char is whitespace thus we may accept
2163 * invalid integers (e.g. 1234...a) or two integers instead of one
2164 * (e.g. 123...1). So lets not allow such large numbers. */
2165 if (len == TMPBUFLEN - 1)
2166 return -EINVAL;
2167
2168 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2169 return -EINVAL;
1da177e4 2170
00b7c339
AW
2171 if (tr && (len < *size))
2172 *tr = *p;
2173
2174 *buf += len;
2175 *size -= len;
2176
2177 return 0;
2178}
2179
2180/**
0fc377bd 2181 * proc_put_long - converts an integer to a decimal ASCII formatted string
00b7c339 2182 *
0fc377bd
RD
2183 * @buf: the user buffer
2184 * @size: the size of the user buffer
2185 * @val: the integer to be converted
2186 * @neg: sign of the number, %TRUE for negative
00b7c339 2187 *
0fc377bd
RD
2188 * In case of success %0 is returned and @buf and @size are updated with
2189 * the amount of bytes written.
00b7c339
AW
2190 */
2191static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2192 bool neg)
2193{
2194 int len;
2195 char tmp[TMPBUFLEN], *p = tmp;
2196
2197 sprintf(p, "%s%lu", neg ? "-" : "", val);
2198 len = strlen(tmp);
2199 if (len > *size)
2200 len = *size;
2201 if (copy_to_user(*buf, tmp, len))
2202 return -EFAULT;
2203 *size -= len;
2204 *buf += len;
2205 return 0;
2206}
2207#undef TMPBUFLEN
2208
2209static int proc_put_char(void __user **buf, size_t *size, char c)
2210{
2211 if (*size) {
2212 char __user **buffer = (char __user **)buf;
2213 if (put_user(c, *buffer))
2214 return -EFAULT;
2215 (*size)--, (*buffer)++;
2216 *buf = *buffer;
2217 }
2218 return 0;
2219}
1da177e4 2220
00b7c339 2221static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2222 int *valp,
2223 int write, void *data)
2224{
2225 if (write) {
2226 *valp = *negp ? -*lvalp : *lvalp;
2227 } else {
2228 int val = *valp;
2229 if (val < 0) {
00b7c339 2230 *negp = true;
1da177e4
LT
2231 *lvalp = (unsigned long)-val;
2232 } else {
00b7c339 2233 *negp = false;
1da177e4
LT
2234 *lvalp = (unsigned long)val;
2235 }
2236 }
2237 return 0;
2238}
2239
00b7c339
AW
2240static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2241
d8217f07 2242static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
8d65af78 2243 int write, void __user *buffer,
fcfbd547 2244 size_t *lenp, loff_t *ppos,
00b7c339 2245 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1da177e4
LT
2246 int write, void *data),
2247 void *data)
2248{
00b7c339
AW
2249 int *i, vleft, first = 1, err = 0;
2250 unsigned long page = 0;
2251 size_t left;
2252 char *kbuf;
1da177e4 2253
00b7c339 2254 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1da177e4
LT
2255 *lenp = 0;
2256 return 0;
2257 }
2258
fcfbd547 2259 i = (int *) tbl_data;
1da177e4
LT
2260 vleft = table->maxlen / sizeof(*i);
2261 left = *lenp;
2262
2263 if (!conv)
2264 conv = do_proc_dointvec_conv;
2265
00b7c339
AW
2266 if (write) {
2267 if (left > PAGE_SIZE - 1)
2268 left = PAGE_SIZE - 1;
2269 page = __get_free_page(GFP_TEMPORARY);
2270 kbuf = (char *) page;
2271 if (!kbuf)
2272 return -ENOMEM;
2273 if (copy_from_user(kbuf, buffer, left)) {
2274 err = -EFAULT;
2275 goto free;
2276 }
2277 kbuf[left] = 0;
2278 }
2279
1da177e4 2280 for (; left && vleft--; i++, first=0) {
00b7c339
AW
2281 unsigned long lval;
2282 bool neg;
1da177e4 2283
00b7c339
AW
2284 if (write) {
2285 left -= proc_skip_spaces(&kbuf);
1da177e4 2286
563b0467
O
2287 if (!left)
2288 break;
00b7c339
AW
2289 err = proc_get_long(&kbuf, &left, &lval, &neg,
2290 proc_wspace_sep,
2291 sizeof(proc_wspace_sep), NULL);
2292 if (err)
1da177e4 2293 break;
00b7c339
AW
2294 if (conv(&neg, &lval, i, 1, data)) {
2295 err = -EINVAL;
1da177e4 2296 break;
00b7c339 2297 }
1da177e4 2298 } else {
00b7c339
AW
2299 if (conv(&neg, &lval, i, 0, data)) {
2300 err = -EINVAL;
2301 break;
2302 }
1da177e4 2303 if (!first)
00b7c339
AW
2304 err = proc_put_char(&buffer, &left, '\t');
2305 if (err)
2306 break;
2307 err = proc_put_long(&buffer, &left, lval, neg);
2308 if (err)
1da177e4 2309 break;
1da177e4
LT
2310 }
2311 }
2312
00b7c339
AW
2313 if (!write && !first && left && !err)
2314 err = proc_put_char(&buffer, &left, '\n');
563b0467 2315 if (write && !err && left)
00b7c339
AW
2316 left -= proc_skip_spaces(&kbuf);
2317free:
1da177e4 2318 if (write) {
00b7c339
AW
2319 free_page(page);
2320 if (first)
2321 return err ? : -EINVAL;
1da177e4 2322 }
1da177e4
LT
2323 *lenp -= left;
2324 *ppos += *lenp;
00b7c339 2325 return err;
1da177e4
LT
2326}
2327
8d65af78 2328static int do_proc_dointvec(struct ctl_table *table, int write,
fcfbd547 2329 void __user *buffer, size_t *lenp, loff_t *ppos,
00b7c339 2330 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
fcfbd547
KK
2331 int write, void *data),
2332 void *data)
2333{
8d65af78 2334 return __do_proc_dointvec(table->data, table, write,
fcfbd547
KK
2335 buffer, lenp, ppos, conv, data);
2336}
2337
1da177e4
LT
2338/**
2339 * proc_dointvec - read a vector of integers
2340 * @table: the sysctl table
2341 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2342 * @buffer: the user buffer
2343 * @lenp: the size of the user buffer
2344 * @ppos: file position
2345 *
2346 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2347 * values from/to the user buffer, treated as an ASCII string.
2348 *
2349 * Returns 0 on success.
2350 */
8d65af78 2351int proc_dointvec(struct ctl_table *table, int write,
1da177e4
LT
2352 void __user *buffer, size_t *lenp, loff_t *ppos)
2353{
8d65af78 2354 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2355 NULL,NULL);
2356}
2357
34f5a398 2358/*
25ddbb18
AK
2359 * Taint values can only be increased
2360 * This means we can safely use a temporary.
34f5a398 2361 */
8d65af78 2362static int proc_taint(struct ctl_table *table, int write,
34f5a398
TT
2363 void __user *buffer, size_t *lenp, loff_t *ppos)
2364{
25ddbb18
AK
2365 struct ctl_table t;
2366 unsigned long tmptaint = get_taint();
2367 int err;
34f5a398 2368
91fcd412 2369 if (write && !capable(CAP_SYS_ADMIN))
34f5a398
TT
2370 return -EPERM;
2371
25ddbb18
AK
2372 t = *table;
2373 t.data = &tmptaint;
8d65af78 2374 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
25ddbb18
AK
2375 if (err < 0)
2376 return err;
2377
2378 if (write) {
2379 /*
2380 * Poor man's atomic or. Not worth adding a primitive
2381 * to everyone's atomic.h for this
2382 */
2383 int i;
2384 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2385 if ((tmptaint >> i) & 1)
2386 add_taint(i);
2387 }
2388 }
2389
2390 return err;
34f5a398
TT
2391}
2392
1da177e4
LT
2393struct do_proc_dointvec_minmax_conv_param {
2394 int *min;
2395 int *max;
2396};
2397
00b7c339
AW
2398static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2399 int *valp,
1da177e4
LT
2400 int write, void *data)
2401{
2402 struct do_proc_dointvec_minmax_conv_param *param = data;
2403 if (write) {
2404 int val = *negp ? -*lvalp : *lvalp;
2405 if ((param->min && *param->min > val) ||
2406 (param->max && *param->max < val))
2407 return -EINVAL;
2408 *valp = val;
2409 } else {
2410 int val = *valp;
2411 if (val < 0) {
00b7c339 2412 *negp = true;
1da177e4
LT
2413 *lvalp = (unsigned long)-val;
2414 } else {
00b7c339 2415 *negp = false;
1da177e4
LT
2416 *lvalp = (unsigned long)val;
2417 }
2418 }
2419 return 0;
2420}
2421
2422/**
2423 * proc_dointvec_minmax - read a vector of integers with min/max values
2424 * @table: the sysctl table
2425 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2426 * @buffer: the user buffer
2427 * @lenp: the size of the user buffer
2428 * @ppos: file position
2429 *
2430 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2431 * values from/to the user buffer, treated as an ASCII string.
2432 *
2433 * This routine will ensure the values are within the range specified by
2434 * table->extra1 (min) and table->extra2 (max).
2435 *
2436 * Returns 0 on success.
2437 */
8d65af78 2438int proc_dointvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2440{
2441 struct do_proc_dointvec_minmax_conv_param param = {
2442 .min = (int *) table->extra1,
2443 .max = (int *) table->extra2,
2444 };
8d65af78 2445 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1da177e4
LT
2446 do_proc_dointvec_minmax_conv, &param);
2447}
2448
d8217f07 2449static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1da177e4
LT
2450 void __user *buffer,
2451 size_t *lenp, loff_t *ppos,
2452 unsigned long convmul,
2453 unsigned long convdiv)
2454{
00b7c339
AW
2455 unsigned long *i, *min, *max;
2456 int vleft, first = 1, err = 0;
2457 unsigned long page = 0;
2458 size_t left;
2459 char *kbuf;
2460
2461 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1da177e4
LT
2462 *lenp = 0;
2463 return 0;
2464 }
00b7c339 2465
fcfbd547 2466 i = (unsigned long *) data;
1da177e4
LT
2467 min = (unsigned long *) table->extra1;
2468 max = (unsigned long *) table->extra2;
2469 vleft = table->maxlen / sizeof(unsigned long);
2470 left = *lenp;
00b7c339
AW
2471
2472 if (write) {
2473 if (left > PAGE_SIZE - 1)
2474 left = PAGE_SIZE - 1;
2475 page = __get_free_page(GFP_TEMPORARY);
2476 kbuf = (char *) page;
2477 if (!kbuf)
2478 return -ENOMEM;
2479 if (copy_from_user(kbuf, buffer, left)) {
2480 err = -EFAULT;
2481 goto free;
2482 }
2483 kbuf[left] = 0;
2484 }
2485
27b3d80a 2486 for (; left && vleft--; i++, first = 0) {
00b7c339
AW
2487 unsigned long val;
2488
1da177e4 2489 if (write) {
00b7c339
AW
2490 bool neg;
2491
2492 left -= proc_skip_spaces(&kbuf);
2493
2494 err = proc_get_long(&kbuf, &left, &val, &neg,
2495 proc_wspace_sep,
2496 sizeof(proc_wspace_sep), NULL);
2497 if (err)
1da177e4
LT
2498 break;
2499 if (neg)
1da177e4
LT
2500 continue;
2501 if ((min && val < *min) || (max && val > *max))
2502 continue;
2503 *i = val;
2504 } else {
00b7c339 2505 val = convdiv * (*i) / convmul;
1da177e4 2506 if (!first)
00b7c339
AW
2507 err = proc_put_char(&buffer, &left, '\t');
2508 err = proc_put_long(&buffer, &left, val, false);
2509 if (err)
2510 break;
1da177e4
LT
2511 }
2512 }
2513
00b7c339
AW
2514 if (!write && !first && left && !err)
2515 err = proc_put_char(&buffer, &left, '\n');
2516 if (write && !err)
2517 left -= proc_skip_spaces(&kbuf);
2518free:
1da177e4 2519 if (write) {
00b7c339
AW
2520 free_page(page);
2521 if (first)
2522 return err ? : -EINVAL;
1da177e4 2523 }
1da177e4
LT
2524 *lenp -= left;
2525 *ppos += *lenp;
00b7c339 2526 return err;
1da177e4
LT
2527}
2528
d8217f07 2529static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
fcfbd547
KK
2530 void __user *buffer,
2531 size_t *lenp, loff_t *ppos,
2532 unsigned long convmul,
2533 unsigned long convdiv)
2534{
2535 return __do_proc_doulongvec_minmax(table->data, table, write,
8d65af78 2536 buffer, lenp, ppos, convmul, convdiv);
fcfbd547
KK
2537}
2538
1da177e4
LT
2539/**
2540 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2541 * @table: the sysctl table
2542 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2543 * @buffer: the user buffer
2544 * @lenp: the size of the user buffer
2545 * @ppos: file position
2546 *
2547 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2548 * values from/to the user buffer, treated as an ASCII string.
2549 *
2550 * This routine will ensure the values are within the range specified by
2551 * table->extra1 (min) and table->extra2 (max).
2552 *
2553 * Returns 0 on success.
2554 */
8d65af78 2555int proc_doulongvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2556 void __user *buffer, size_t *lenp, loff_t *ppos)
2557{
8d65af78 2558 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1da177e4
LT
2559}
2560
2561/**
2562 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2563 * @table: the sysctl table
2564 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2565 * @buffer: the user buffer
2566 * @lenp: the size of the user buffer
2567 * @ppos: file position
2568 *
2569 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2570 * values from/to the user buffer, treated as an ASCII string. The values
2571 * are treated as milliseconds, and converted to jiffies when they are stored.
2572 *
2573 * This routine will ensure the values are within the range specified by
2574 * table->extra1 (min) and table->extra2 (max).
2575 *
2576 * Returns 0 on success.
2577 */
d8217f07 2578int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2579 void __user *buffer,
2580 size_t *lenp, loff_t *ppos)
2581{
8d65af78 2582 return do_proc_doulongvec_minmax(table, write, buffer,
1da177e4
LT
2583 lenp, ppos, HZ, 1000l);
2584}
2585
2586
00b7c339 2587static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2588 int *valp,
2589 int write, void *data)
2590{
2591 if (write) {
cba9f33d
BS
2592 if (*lvalp > LONG_MAX / HZ)
2593 return 1;
1da177e4
LT
2594 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2595 } else {
2596 int val = *valp;
2597 unsigned long lval;
2598 if (val < 0) {
00b7c339 2599 *negp = true;
1da177e4
LT
2600 lval = (unsigned long)-val;
2601 } else {
00b7c339 2602 *negp = false;
1da177e4
LT
2603 lval = (unsigned long)val;
2604 }
2605 *lvalp = lval / HZ;
2606 }
2607 return 0;
2608}
2609
00b7c339 2610static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2611 int *valp,
2612 int write, void *data)
2613{
2614 if (write) {
cba9f33d
BS
2615 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2616 return 1;
1da177e4
LT
2617 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2618 } else {
2619 int val = *valp;
2620 unsigned long lval;
2621 if (val < 0) {
00b7c339 2622 *negp = true;
1da177e4
LT
2623 lval = (unsigned long)-val;
2624 } else {
00b7c339 2625 *negp = false;
1da177e4
LT
2626 lval = (unsigned long)val;
2627 }
2628 *lvalp = jiffies_to_clock_t(lval);
2629 }
2630 return 0;
2631}
2632
00b7c339 2633static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2634 int *valp,
2635 int write, void *data)
2636{
2637 if (write) {
2638 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2639 } else {
2640 int val = *valp;
2641 unsigned long lval;
2642 if (val < 0) {
00b7c339 2643 *negp = true;
1da177e4
LT
2644 lval = (unsigned long)-val;
2645 } else {
00b7c339 2646 *negp = false;
1da177e4
LT
2647 lval = (unsigned long)val;
2648 }
2649 *lvalp = jiffies_to_msecs(lval);
2650 }
2651 return 0;
2652}
2653
2654/**
2655 * proc_dointvec_jiffies - read a vector of integers as seconds
2656 * @table: the sysctl table
2657 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2658 * @buffer: the user buffer
2659 * @lenp: the size of the user buffer
2660 * @ppos: file position
2661 *
2662 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2663 * values from/to the user buffer, treated as an ASCII string.
2664 * The values read are assumed to be in seconds, and are converted into
2665 * jiffies.
2666 *
2667 * Returns 0 on success.
2668 */
8d65af78 2669int proc_dointvec_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2670 void __user *buffer, size_t *lenp, loff_t *ppos)
2671{
8d65af78 2672 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2673 do_proc_dointvec_jiffies_conv,NULL);
2674}
2675
2676/**
2677 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2678 * @table: the sysctl table
2679 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2680 * @buffer: the user buffer
2681 * @lenp: the size of the user buffer
1e5d5331 2682 * @ppos: pointer to the file position
1da177e4
LT
2683 *
2684 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2685 * values from/to the user buffer, treated as an ASCII string.
2686 * The values read are assumed to be in 1/USER_HZ seconds, and
2687 * are converted into jiffies.
2688 *
2689 * Returns 0 on success.
2690 */
8d65af78 2691int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2692 void __user *buffer, size_t *lenp, loff_t *ppos)
2693{
8d65af78 2694 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2695 do_proc_dointvec_userhz_jiffies_conv,NULL);
2696}
2697
2698/**
2699 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2700 * @table: the sysctl table
2701 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2702 * @buffer: the user buffer
2703 * @lenp: the size of the user buffer
67be2dd1
MW
2704 * @ppos: file position
2705 * @ppos: the current position in the file
1da177e4
LT
2706 *
2707 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2708 * values from/to the user buffer, treated as an ASCII string.
2709 * The values read are assumed to be in 1/1000 seconds, and
2710 * are converted into jiffies.
2711 *
2712 * Returns 0 on success.
2713 */
8d65af78 2714int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2715 void __user *buffer, size_t *lenp, loff_t *ppos)
2716{
8d65af78 2717 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1da177e4
LT
2718 do_proc_dointvec_ms_jiffies_conv, NULL);
2719}
2720
8d65af78 2721static int proc_do_cad_pid(struct ctl_table *table, int write,
9ec52099
CLG
2722 void __user *buffer, size_t *lenp, loff_t *ppos)
2723{
2724 struct pid *new_pid;
2725 pid_t tmp;
2726 int r;
2727
6c5f3e7b 2728 tmp = pid_vnr(cad_pid);
9ec52099 2729
8d65af78 2730 r = __do_proc_dointvec(&tmp, table, write, buffer,
9ec52099
CLG
2731 lenp, ppos, NULL, NULL);
2732 if (r || !write)
2733 return r;
2734
2735 new_pid = find_get_pid(tmp);
2736 if (!new_pid)
2737 return -ESRCH;
2738
2739 put_pid(xchg(&cad_pid, new_pid));
2740 return 0;
2741}
2742
9f977fb7
OP
2743/**
2744 * proc_do_large_bitmap - read/write from/to a large bitmap
2745 * @table: the sysctl table
2746 * @write: %TRUE if this is a write to the sysctl file
2747 * @buffer: the user buffer
2748 * @lenp: the size of the user buffer
2749 * @ppos: file position
2750 *
2751 * The bitmap is stored at table->data and the bitmap length (in bits)
2752 * in table->maxlen.
2753 *
2754 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2755 * large bitmaps may be represented in a compact manner. Writing into
2756 * the file will clear the bitmap then update it with the given input.
2757 *
2758 * Returns 0 on success.
2759 */
2760int proc_do_large_bitmap(struct ctl_table *table, int write,
2761 void __user *buffer, size_t *lenp, loff_t *ppos)
2762{
2763 int err = 0;
2764 bool first = 1;
2765 size_t left = *lenp;
2766 unsigned long bitmap_len = table->maxlen;
2767 unsigned long *bitmap = (unsigned long *) table->data;
2768 unsigned long *tmp_bitmap = NULL;
2769 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2770
2771 if (!bitmap_len || !left || (*ppos && !write)) {
2772 *lenp = 0;
2773 return 0;
2774 }
2775
2776 if (write) {
2777 unsigned long page = 0;
2778 char *kbuf;
2779
2780 if (left > PAGE_SIZE - 1)
2781 left = PAGE_SIZE - 1;
2782
2783 page = __get_free_page(GFP_TEMPORARY);
2784 kbuf = (char *) page;
2785 if (!kbuf)
2786 return -ENOMEM;
2787 if (copy_from_user(kbuf, buffer, left)) {
2788 free_page(page);
2789 return -EFAULT;
2790 }
2791 kbuf[left] = 0;
2792
2793 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2794 GFP_KERNEL);
2795 if (!tmp_bitmap) {
2796 free_page(page);
2797 return -ENOMEM;
2798 }
2799 proc_skip_char(&kbuf, &left, '\n');
2800 while (!err && left) {
2801 unsigned long val_a, val_b;
2802 bool neg;
2803
2804 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2805 sizeof(tr_a), &c);
2806 if (err)
2807 break;
2808 if (val_a >= bitmap_len || neg) {
2809 err = -EINVAL;
2810 break;
2811 }
2812
2813 val_b = val_a;
2814 if (left) {
2815 kbuf++;
2816 left--;
2817 }
2818
2819 if (c == '-') {
2820 err = proc_get_long(&kbuf, &left, &val_b,
2821 &neg, tr_b, sizeof(tr_b),
2822 &c);
2823 if (err)
2824 break;
2825 if (val_b >= bitmap_len || neg ||
2826 val_a > val_b) {
2827 err = -EINVAL;
2828 break;
2829 }
2830 if (left) {
2831 kbuf++;
2832 left--;
2833 }
2834 }
2835
2836 while (val_a <= val_b)
2837 set_bit(val_a++, tmp_bitmap);
2838
2839 first = 0;
2840 proc_skip_char(&kbuf, &left, '\n');
2841 }
2842 free_page(page);
2843 } else {
2844 unsigned long bit_a, bit_b = 0;
2845
2846 while (left) {
2847 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2848 if (bit_a >= bitmap_len)
2849 break;
2850 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2851 bit_a + 1) - 1;
2852
2853 if (!first) {
2854 err = proc_put_char(&buffer, &left, ',');
2855 if (err)
2856 break;
2857 }
2858 err = proc_put_long(&buffer, &left, bit_a, false);
2859 if (err)
2860 break;
2861 if (bit_a != bit_b) {
2862 err = proc_put_char(&buffer, &left, '-');
2863 if (err)
2864 break;
2865 err = proc_put_long(&buffer, &left, bit_b, false);
2866 if (err)
2867 break;
2868 }
2869
2870 first = 0; bit_b++;
2871 }
2872 if (!err)
2873 err = proc_put_char(&buffer, &left, '\n');
2874 }
2875
2876 if (!err) {
2877 if (write) {
2878 if (*ppos)
2879 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2880 else
2881 memcpy(bitmap, tmp_bitmap,
2882 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2883 }
2884 kfree(tmp_bitmap);
2885 *lenp -= left;
2886 *ppos += *lenp;
2887 return 0;
2888 } else {
2889 kfree(tmp_bitmap);
2890 return err;
2891 }
2892}
2893
1da177e4
LT
2894#else /* CONFIG_PROC_FS */
2895
8d65af78 2896int proc_dostring(struct ctl_table *table, int write,
1da177e4
LT
2897 void __user *buffer, size_t *lenp, loff_t *ppos)
2898{
2899 return -ENOSYS;
2900}
2901
8d65af78 2902int proc_dointvec(struct ctl_table *table, int write,
1da177e4 2903 void __user *buffer, size_t *lenp, loff_t *ppos)
1da177e4
LT
2904{
2905 return -ENOSYS;
2906}
2907
8d65af78 2908int proc_dointvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2909 void __user *buffer, size_t *lenp, loff_t *ppos)
2910{
2911 return -ENOSYS;
2912}
2913
8d65af78 2914int proc_dointvec_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2915 void __user *buffer, size_t *lenp, loff_t *ppos)
2916{
2917 return -ENOSYS;
2918}
2919
8d65af78 2920int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2921 void __user *buffer, size_t *lenp, loff_t *ppos)
2922{
2923 return -ENOSYS;
2924}
2925
8d65af78 2926int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2927 void __user *buffer, size_t *lenp, loff_t *ppos)
2928{
2929 return -ENOSYS;
2930}
2931
8d65af78 2932int proc_doulongvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2933 void __user *buffer, size_t *lenp, loff_t *ppos)
2934{
2935 return -ENOSYS;
2936}
2937
d8217f07 2938int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2939 void __user *buffer,
2940 size_t *lenp, loff_t *ppos)
2941{
2942 return -ENOSYS;
2943}
2944
2945
2946#endif /* CONFIG_PROC_FS */
2947
1da177e4
LT
2948/*
2949 * No sense putting this after each symbol definition, twice,
2950 * exception granted :-)
2951 */
2952EXPORT_SYMBOL(proc_dointvec);
2953EXPORT_SYMBOL(proc_dointvec_jiffies);
2954EXPORT_SYMBOL(proc_dointvec_minmax);
2955EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2956EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2957EXPORT_SYMBOL(proc_dostring);
2958EXPORT_SYMBOL(proc_doulongvec_minmax);
2959EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2960EXPORT_SYMBOL(register_sysctl_table);
29e796fd 2961EXPORT_SYMBOL(register_sysctl_paths);
1da177e4 2962EXPORT_SYMBOL(unregister_sysctl_table);