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