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