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