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