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