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