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