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