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