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