2 * sysctl.c: General linux system control interface
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
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
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
21 #include <linux/module.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>
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/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
55 #include <linux/pipe_fs_i.h>
57 #include <asm/uaccess.h>
58 #include <asm/processor.h>
62 #include <asm/stacktrace.h>
65 #ifdef CONFIG_BSD_PROCESS_ACCT
66 #include <linux/acct.h>
68 #ifdef CONFIG_RT_MUTEXES
69 #include <linux/rtmutex.h>
71 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
72 #include <linux/lockdep.h>
74 #ifdef CONFIG_CHR_DEV_SG
79 #if defined(CONFIG_SYSCTL)
81 /* External variables not in a header file. */
82 extern int sysctl_overcommit_memory
;
83 extern int sysctl_overcommit_ratio
;
84 extern int sysctl_panic_on_oom
;
85 extern int sysctl_oom_kill_allocating_task
;
86 extern int sysctl_oom_dump_tasks
;
87 extern int max_threads
;
88 extern int core_uses_pid
;
89 extern int suid_dumpable
;
90 extern char core_pattern
[];
91 extern unsigned int core_pipe_limit
;
93 extern int min_free_kbytes
;
94 extern int pid_max_min
, pid_max_max
;
95 extern int sysctl_drop_caches
;
96 extern int percpu_pagelist_fraction
;
97 extern int compat_log
;
98 extern int latencytop_enabled
;
99 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
101 extern int sysctl_nr_trim_pages
;
104 extern int blk_iopoll_enabled
;
107 /* Constants used for minimum and maximum */
108 #ifdef CONFIG_DETECT_SOFTLOCKUP
109 static int sixty
= 60;
110 static int neg_one
= -1;
114 static int __maybe_unused one
= 1;
115 static int __maybe_unused two
= 2;
116 static unsigned long one_ul
= 1;
117 static int one_hundred
= 100;
119 static int ten_thousand
= 10000;
122 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
123 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
125 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
126 static int maxolduid
= 65535;
127 static int minolduid
;
128 static int min_percpu_pagelist_fract
= 8;
130 static int ngroups_max
= NGROUPS_MAX
;
133 #include <asm/system.h>
136 #ifdef CONFIG_SPARC64
137 extern int sysctl_tsb_ratio
;
141 extern int pwrsw_enabled
;
142 extern int unaligned_enabled
;
146 #ifdef CONFIG_MATHEMU
147 extern int sysctl_ieee_emulation_warnings
;
149 extern int sysctl_userprocess_debug
;
150 extern int spin_retry
;
154 extern int no_unaligned_warning
;
155 extern int unaligned_dump_stack
;
158 extern struct ratelimit_state printk_ratelimit_state
;
160 #ifdef CONFIG_PROC_SYSCTL
161 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
163 static int proc_taint(struct ctl_table
*table
, int write
,
164 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
167 #ifdef CONFIG_MAGIC_SYSRQ
168 static int __sysrq_enabled
; /* Note: sysrq code ises it's own private copy */
170 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
171 void __user
*buffer
, size_t *lenp
,
176 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
181 sysrq_toggle_support(__sysrq_enabled
);
188 static struct ctl_table root_table
[];
189 static struct ctl_table_root sysctl_table_root
;
190 static struct ctl_table_header root_table_header
= {
192 .ctl_table
= root_table
,
193 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
194 .root
= &sysctl_table_root
,
195 .set
= &sysctl_table_root
.default_set
,
197 static struct ctl_table_root sysctl_table_root
= {
198 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
199 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
202 static struct ctl_table kern_table
[];
203 static struct ctl_table vm_table
[];
204 static struct ctl_table fs_table
[];
205 static struct ctl_table debug_table
[];
206 static struct ctl_table dev_table
[];
207 extern struct ctl_table random_table
[];
208 #ifdef CONFIG_INOTIFY_USER
209 extern struct ctl_table inotify_table
[];
212 extern struct ctl_table epoll_table
[];
215 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
216 int sysctl_legacy_va_layout
;
219 /* The default sysctl tables: */
221 static struct ctl_table root_table
[] = {
223 .procname
= "kernel",
240 .child
= debug_table
,
248 * NOTE: do not add new entries to this table unless you have read
249 * Documentation/sysctl/ctl_unnumbered.txt
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
256 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
257 static int min_wakeup_granularity_ns
; /* 0 usecs */
258 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
259 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
260 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
261 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
262 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
265 static struct ctl_table kern_table
[] = {
267 .procname
= "sched_child_runs_first",
268 .data
= &sysctl_sched_child_runs_first
,
269 .maxlen
= sizeof(unsigned int),
271 .proc_handler
= proc_dointvec
,
273 #ifdef CONFIG_SCHED_DEBUG
275 .procname
= "sched_min_granularity_ns",
276 .data
= &sysctl_sched_min_granularity
,
277 .maxlen
= sizeof(unsigned int),
279 .proc_handler
= sched_proc_update_handler
,
280 .extra1
= &min_sched_granularity_ns
,
281 .extra2
= &max_sched_granularity_ns
,
284 .procname
= "sched_latency_ns",
285 .data
= &sysctl_sched_latency
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= sched_proc_update_handler
,
289 .extra1
= &min_sched_granularity_ns
,
290 .extra2
= &max_sched_granularity_ns
,
293 .procname
= "sched_wakeup_granularity_ns",
294 .data
= &sysctl_sched_wakeup_granularity
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= sched_proc_update_handler
,
298 .extra1
= &min_wakeup_granularity_ns
,
299 .extra2
= &max_wakeup_granularity_ns
,
302 .procname
= "sched_shares_ratelimit",
303 .data
= &sysctl_sched_shares_ratelimit
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= sched_proc_update_handler
,
307 .extra1
= &min_sched_shares_ratelimit
,
308 .extra2
= &max_sched_shares_ratelimit
,
311 .procname
= "sched_tunable_scaling",
312 .data
= &sysctl_sched_tunable_scaling
,
313 .maxlen
= sizeof(enum sched_tunable_scaling
),
315 .proc_handler
= sched_proc_update_handler
,
316 .extra1
= &min_sched_tunable_scaling
,
317 .extra2
= &max_sched_tunable_scaling
,
320 .procname
= "sched_shares_thresh",
321 .data
= &sysctl_sched_shares_thresh
,
322 .maxlen
= sizeof(unsigned int),
324 .proc_handler
= proc_dointvec_minmax
,
328 .procname
= "sched_migration_cost",
329 .data
= &sysctl_sched_migration_cost
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
335 .procname
= "sched_nr_migrate",
336 .data
= &sysctl_sched_nr_migrate
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "sched_time_avg",
343 .data
= &sysctl_sched_time_avg
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec
,
349 .procname
= "timer_migration",
350 .data
= &sysctl_timer_migration
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= proc_dointvec_minmax
,
359 .procname
= "sched_rt_period_us",
360 .data
= &sysctl_sched_rt_period
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= sched_rt_handler
,
366 .procname
= "sched_rt_runtime_us",
367 .data
= &sysctl_sched_rt_runtime
,
368 .maxlen
= sizeof(int),
370 .proc_handler
= sched_rt_handler
,
373 .procname
= "sched_compat_yield",
374 .data
= &sysctl_sched_compat_yield
,
375 .maxlen
= sizeof(unsigned int),
377 .proc_handler
= proc_dointvec
,
379 #ifdef CONFIG_PROVE_LOCKING
381 .procname
= "prove_locking",
382 .data
= &prove_locking
,
383 .maxlen
= sizeof(int),
385 .proc_handler
= proc_dointvec
,
388 #ifdef CONFIG_LOCK_STAT
390 .procname
= "lock_stat",
392 .maxlen
= sizeof(int),
394 .proc_handler
= proc_dointvec
,
399 .data
= &panic_timeout
,
400 .maxlen
= sizeof(int),
402 .proc_handler
= proc_dointvec
,
405 .procname
= "core_uses_pid",
406 .data
= &core_uses_pid
,
407 .maxlen
= sizeof(int),
409 .proc_handler
= proc_dointvec
,
412 .procname
= "core_pattern",
413 .data
= core_pattern
,
414 .maxlen
= CORENAME_MAX_SIZE
,
416 .proc_handler
= proc_dostring
,
419 .procname
= "core_pipe_limit",
420 .data
= &core_pipe_limit
,
421 .maxlen
= sizeof(unsigned int),
423 .proc_handler
= proc_dointvec
,
425 #ifdef CONFIG_PROC_SYSCTL
427 .procname
= "tainted",
428 .maxlen
= sizeof(long),
430 .proc_handler
= proc_taint
,
433 #ifdef CONFIG_LATENCYTOP
435 .procname
= "latencytop",
436 .data
= &latencytop_enabled
,
437 .maxlen
= sizeof(int),
439 .proc_handler
= proc_dointvec
,
442 #ifdef CONFIG_BLK_DEV_INITRD
444 .procname
= "real-root-dev",
445 .data
= &real_root_dev
,
446 .maxlen
= sizeof(int),
448 .proc_handler
= proc_dointvec
,
452 .procname
= "print-fatal-signals",
453 .data
= &print_fatal_signals
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= proc_dointvec
,
460 .procname
= "reboot-cmd",
461 .data
= reboot_command
,
464 .proc_handler
= proc_dostring
,
467 .procname
= "stop-a",
468 .data
= &stop_a_enabled
,
469 .maxlen
= sizeof (int),
471 .proc_handler
= proc_dointvec
,
474 .procname
= "scons-poweroff",
475 .data
= &scons_pwroff
,
476 .maxlen
= sizeof (int),
478 .proc_handler
= proc_dointvec
,
481 #ifdef CONFIG_SPARC64
483 .procname
= "tsb-ratio",
484 .data
= &sysctl_tsb_ratio
,
485 .maxlen
= sizeof (int),
487 .proc_handler
= proc_dointvec
,
492 .procname
= "soft-power",
493 .data
= &pwrsw_enabled
,
494 .maxlen
= sizeof (int),
496 .proc_handler
= proc_dointvec
,
499 .procname
= "unaligned-trap",
500 .data
= &unaligned_enabled
,
501 .maxlen
= sizeof (int),
503 .proc_handler
= proc_dointvec
,
507 .procname
= "ctrl-alt-del",
509 .maxlen
= sizeof(int),
511 .proc_handler
= proc_dointvec
,
513 #ifdef CONFIG_FUNCTION_TRACER
515 .procname
= "ftrace_enabled",
516 .data
= &ftrace_enabled
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= ftrace_enable_sysctl
,
522 #ifdef CONFIG_STACK_TRACER
524 .procname
= "stack_tracer_enabled",
525 .data
= &stack_tracer_enabled
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= stack_trace_sysctl
,
531 #ifdef CONFIG_TRACING
533 .procname
= "ftrace_dump_on_oops",
534 .data
= &ftrace_dump_on_oops
,
535 .maxlen
= sizeof(int),
537 .proc_handler
= proc_dointvec
,
540 #ifdef CONFIG_MODULES
542 .procname
= "modprobe",
543 .data
= &modprobe_path
,
544 .maxlen
= KMOD_PATH_LEN
,
546 .proc_handler
= proc_dostring
,
549 .procname
= "modules_disabled",
550 .data
= &modules_disabled
,
551 .maxlen
= sizeof(int),
553 /* only handle a transition from default "0" to "1" */
554 .proc_handler
= proc_dointvec_minmax
,
559 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
561 .procname
= "hotplug",
562 .data
= &uevent_helper
,
563 .maxlen
= UEVENT_HELPER_PATH_LEN
,
565 .proc_handler
= proc_dostring
,
568 #ifdef CONFIG_CHR_DEV_SG
570 .procname
= "sg-big-buff",
571 .data
= &sg_big_buff
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= proc_dointvec
,
577 #ifdef CONFIG_BSD_PROCESS_ACCT
581 .maxlen
= 3*sizeof(int),
583 .proc_handler
= proc_dointvec
,
586 #ifdef CONFIG_MAGIC_SYSRQ
589 .data
= &__sysrq_enabled
,
590 .maxlen
= sizeof (int),
592 .proc_handler
= sysrq_sysctl_handler
,
595 #ifdef CONFIG_PROC_SYSCTL
597 .procname
= "cad_pid",
599 .maxlen
= sizeof (int),
601 .proc_handler
= proc_do_cad_pid
,
605 .procname
= "threads-max",
606 .data
= &max_threads
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= proc_dointvec
,
612 .procname
= "random",
614 .child
= random_table
,
617 .procname
= "overflowuid",
618 .data
= &overflowuid
,
619 .maxlen
= sizeof(int),
621 .proc_handler
= proc_dointvec_minmax
,
622 .extra1
= &minolduid
,
623 .extra2
= &maxolduid
,
626 .procname
= "overflowgid",
627 .data
= &overflowgid
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= proc_dointvec_minmax
,
631 .extra1
= &minolduid
,
632 .extra2
= &maxolduid
,
635 #ifdef CONFIG_MATHEMU
637 .procname
= "ieee_emulation_warnings",
638 .data
= &sysctl_ieee_emulation_warnings
,
639 .maxlen
= sizeof(int),
641 .proc_handler
= proc_dointvec
,
645 .procname
= "userprocess_debug",
646 .data
= &show_unhandled_signals
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= proc_dointvec
,
653 .procname
= "pid_max",
655 .maxlen
= sizeof (int),
657 .proc_handler
= proc_dointvec_minmax
,
658 .extra1
= &pid_max_min
,
659 .extra2
= &pid_max_max
,
662 .procname
= "panic_on_oops",
663 .data
= &panic_on_oops
,
664 .maxlen
= sizeof(int),
666 .proc_handler
= proc_dointvec
,
668 #if defined CONFIG_PRINTK
670 .procname
= "printk",
671 .data
= &console_loglevel
,
672 .maxlen
= 4*sizeof(int),
674 .proc_handler
= proc_dointvec
,
677 .procname
= "printk_ratelimit",
678 .data
= &printk_ratelimit_state
.interval
,
679 .maxlen
= sizeof(int),
681 .proc_handler
= proc_dointvec_jiffies
,
684 .procname
= "printk_ratelimit_burst",
685 .data
= &printk_ratelimit_state
.burst
,
686 .maxlen
= sizeof(int),
688 .proc_handler
= proc_dointvec
,
691 .procname
= "printk_delay",
692 .data
= &printk_delay_msec
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= proc_dointvec_minmax
,
697 .extra2
= &ten_thousand
,
701 .procname
= "ngroups_max",
702 .data
= &ngroups_max
,
703 .maxlen
= sizeof (int),
705 .proc_handler
= proc_dointvec
,
707 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
709 .procname
= "unknown_nmi_panic",
710 .data
= &unknown_nmi_panic
,
711 .maxlen
= sizeof (int),
713 .proc_handler
= proc_dointvec
,
716 .procname
= "nmi_watchdog",
717 .data
= &nmi_watchdog_enabled
,
718 .maxlen
= sizeof (int),
720 .proc_handler
= proc_nmi_enabled
,
723 #if defined(CONFIG_X86)
725 .procname
= "panic_on_unrecovered_nmi",
726 .data
= &panic_on_unrecovered_nmi
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= proc_dointvec
,
732 .procname
= "panic_on_io_nmi",
733 .data
= &panic_on_io_nmi
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= proc_dointvec
,
739 .procname
= "bootloader_type",
740 .data
= &bootloader_type
,
741 .maxlen
= sizeof (int),
743 .proc_handler
= proc_dointvec
,
746 .procname
= "bootloader_version",
747 .data
= &bootloader_version
,
748 .maxlen
= sizeof (int),
750 .proc_handler
= proc_dointvec
,
753 .procname
= "kstack_depth_to_print",
754 .data
= &kstack_depth_to_print
,
755 .maxlen
= sizeof(int),
757 .proc_handler
= proc_dointvec
,
760 .procname
= "io_delay_type",
761 .data
= &io_delay_type
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= proc_dointvec
,
767 #if defined(CONFIG_MMU)
769 .procname
= "randomize_va_space",
770 .data
= &randomize_va_space
,
771 .maxlen
= sizeof(int),
773 .proc_handler
= proc_dointvec
,
776 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
778 .procname
= "spin_retry",
780 .maxlen
= sizeof (int),
782 .proc_handler
= proc_dointvec
,
785 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
787 .procname
= "acpi_video_flags",
788 .data
= &acpi_realmode_flags
,
789 .maxlen
= sizeof (unsigned long),
791 .proc_handler
= proc_doulongvec_minmax
,
796 .procname
= "ignore-unaligned-usertrap",
797 .data
= &no_unaligned_warning
,
798 .maxlen
= sizeof (int),
800 .proc_handler
= proc_dointvec
,
803 .procname
= "unaligned-dump-stack",
804 .data
= &unaligned_dump_stack
,
805 .maxlen
= sizeof (int),
807 .proc_handler
= proc_dointvec
,
810 #ifdef CONFIG_DETECT_SOFTLOCKUP
812 .procname
= "softlockup_panic",
813 .data
= &softlockup_panic
,
814 .maxlen
= sizeof(int),
816 .proc_handler
= proc_dointvec_minmax
,
821 .procname
= "softlockup_thresh",
822 .data
= &softlockup_thresh
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= proc_dosoftlockup_thresh
,
830 #ifdef CONFIG_DETECT_HUNG_TASK
832 .procname
= "hung_task_panic",
833 .data
= &sysctl_hung_task_panic
,
834 .maxlen
= sizeof(int),
836 .proc_handler
= proc_dointvec_minmax
,
841 .procname
= "hung_task_check_count",
842 .data
= &sysctl_hung_task_check_count
,
843 .maxlen
= sizeof(unsigned long),
845 .proc_handler
= proc_doulongvec_minmax
,
848 .procname
= "hung_task_timeout_secs",
849 .data
= &sysctl_hung_task_timeout_secs
,
850 .maxlen
= sizeof(unsigned long),
852 .proc_handler
= proc_dohung_task_timeout_secs
,
855 .procname
= "hung_task_warnings",
856 .data
= &sysctl_hung_task_warnings
,
857 .maxlen
= sizeof(unsigned long),
859 .proc_handler
= proc_doulongvec_minmax
,
864 .procname
= "compat-log",
866 .maxlen
= sizeof (int),
868 .proc_handler
= proc_dointvec
,
871 #ifdef CONFIG_RT_MUTEXES
873 .procname
= "max_lock_depth",
874 .data
= &max_lock_depth
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= proc_dointvec
,
881 .procname
= "poweroff_cmd",
882 .data
= &poweroff_cmd
,
883 .maxlen
= POWEROFF_CMD_PATH_LEN
,
885 .proc_handler
= proc_dostring
,
891 .child
= key_sysctls
,
894 #ifdef CONFIG_RCU_TORTURE_TEST
896 .procname
= "rcutorture_runnable",
897 .data
= &rcutorture_runnable
,
898 .maxlen
= sizeof(int),
900 .proc_handler
= proc_dointvec
,
903 #ifdef CONFIG_SLOW_WORK
905 .procname
= "slow-work",
907 .child
= slow_work_sysctls
,
910 #ifdef CONFIG_PERF_EVENTS
912 .procname
= "perf_event_paranoid",
913 .data
= &sysctl_perf_event_paranoid
,
914 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
916 .proc_handler
= proc_dointvec
,
919 .procname
= "perf_event_mlock_kb",
920 .data
= &sysctl_perf_event_mlock
,
921 .maxlen
= sizeof(sysctl_perf_event_mlock
),
923 .proc_handler
= proc_dointvec
,
926 .procname
= "perf_event_max_sample_rate",
927 .data
= &sysctl_perf_event_sample_rate
,
928 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
930 .proc_handler
= proc_dointvec
,
933 #ifdef CONFIG_KMEMCHECK
935 .procname
= "kmemcheck",
936 .data
= &kmemcheck_enabled
,
937 .maxlen
= sizeof(int),
939 .proc_handler
= proc_dointvec
,
944 .procname
= "blk_iopoll",
945 .data
= &blk_iopoll_enabled
,
946 .maxlen
= sizeof(int),
948 .proc_handler
= proc_dointvec
,
952 * NOTE: do not add new entries to this table unless you have read
953 * Documentation/sysctl/ctl_unnumbered.txt
958 static struct ctl_table vm_table
[] = {
960 .procname
= "overcommit_memory",
961 .data
= &sysctl_overcommit_memory
,
962 .maxlen
= sizeof(sysctl_overcommit_memory
),
964 .proc_handler
= proc_dointvec
,
967 .procname
= "panic_on_oom",
968 .data
= &sysctl_panic_on_oom
,
969 .maxlen
= sizeof(sysctl_panic_on_oom
),
971 .proc_handler
= proc_dointvec
,
974 .procname
= "oom_kill_allocating_task",
975 .data
= &sysctl_oom_kill_allocating_task
,
976 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
978 .proc_handler
= proc_dointvec
,
981 .procname
= "oom_dump_tasks",
982 .data
= &sysctl_oom_dump_tasks
,
983 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
985 .proc_handler
= proc_dointvec
,
988 .procname
= "overcommit_ratio",
989 .data
= &sysctl_overcommit_ratio
,
990 .maxlen
= sizeof(sysctl_overcommit_ratio
),
992 .proc_handler
= proc_dointvec
,
995 .procname
= "page-cluster",
996 .data
= &page_cluster
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= proc_dointvec
,
1002 .procname
= "dirty_background_ratio",
1003 .data
= &dirty_background_ratio
,
1004 .maxlen
= sizeof(dirty_background_ratio
),
1006 .proc_handler
= dirty_background_ratio_handler
,
1008 .extra2
= &one_hundred
,
1011 .procname
= "dirty_background_bytes",
1012 .data
= &dirty_background_bytes
,
1013 .maxlen
= sizeof(dirty_background_bytes
),
1015 .proc_handler
= dirty_background_bytes_handler
,
1019 .procname
= "dirty_ratio",
1020 .data
= &vm_dirty_ratio
,
1021 .maxlen
= sizeof(vm_dirty_ratio
),
1023 .proc_handler
= dirty_ratio_handler
,
1025 .extra2
= &one_hundred
,
1028 .procname
= "dirty_bytes",
1029 .data
= &vm_dirty_bytes
,
1030 .maxlen
= sizeof(vm_dirty_bytes
),
1032 .proc_handler
= dirty_bytes_handler
,
1033 .extra1
= &dirty_bytes_min
,
1036 .procname
= "dirty_writeback_centisecs",
1037 .data
= &dirty_writeback_interval
,
1038 .maxlen
= sizeof(dirty_writeback_interval
),
1040 .proc_handler
= dirty_writeback_centisecs_handler
,
1043 .procname
= "dirty_expire_centisecs",
1044 .data
= &dirty_expire_interval
,
1045 .maxlen
= sizeof(dirty_expire_interval
),
1047 .proc_handler
= proc_dointvec
,
1050 .procname
= "nr_pdflush_threads",
1051 .data
= &nr_pdflush_threads
,
1052 .maxlen
= sizeof nr_pdflush_threads
,
1053 .mode
= 0444 /* read-only*/,
1054 .proc_handler
= proc_dointvec
,
1057 .procname
= "swappiness",
1058 .data
= &vm_swappiness
,
1059 .maxlen
= sizeof(vm_swappiness
),
1061 .proc_handler
= proc_dointvec_minmax
,
1063 .extra2
= &one_hundred
,
1065 #ifdef CONFIG_HUGETLB_PAGE
1067 .procname
= "nr_hugepages",
1069 .maxlen
= sizeof(unsigned long),
1071 .proc_handler
= hugetlb_sysctl_handler
,
1072 .extra1
= (void *)&hugetlb_zero
,
1073 .extra2
= (void *)&hugetlb_infinity
,
1077 .procname
= "nr_hugepages_mempolicy",
1079 .maxlen
= sizeof(unsigned long),
1081 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1082 .extra1
= (void *)&hugetlb_zero
,
1083 .extra2
= (void *)&hugetlb_infinity
,
1087 .procname
= "hugetlb_shm_group",
1088 .data
= &sysctl_hugetlb_shm_group
,
1089 .maxlen
= sizeof(gid_t
),
1091 .proc_handler
= proc_dointvec
,
1094 .procname
= "hugepages_treat_as_movable",
1095 .data
= &hugepages_treat_as_movable
,
1096 .maxlen
= sizeof(int),
1098 .proc_handler
= hugetlb_treat_movable_handler
,
1101 .procname
= "nr_overcommit_hugepages",
1103 .maxlen
= sizeof(unsigned long),
1105 .proc_handler
= hugetlb_overcommit_handler
,
1106 .extra1
= (void *)&hugetlb_zero
,
1107 .extra2
= (void *)&hugetlb_infinity
,
1111 .procname
= "lowmem_reserve_ratio",
1112 .data
= &sysctl_lowmem_reserve_ratio
,
1113 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1115 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1118 .procname
= "drop_caches",
1119 .data
= &sysctl_drop_caches
,
1120 .maxlen
= sizeof(int),
1122 .proc_handler
= drop_caches_sysctl_handler
,
1125 .procname
= "min_free_kbytes",
1126 .data
= &min_free_kbytes
,
1127 .maxlen
= sizeof(min_free_kbytes
),
1129 .proc_handler
= min_free_kbytes_sysctl_handler
,
1133 .procname
= "percpu_pagelist_fraction",
1134 .data
= &percpu_pagelist_fraction
,
1135 .maxlen
= sizeof(percpu_pagelist_fraction
),
1137 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1138 .extra1
= &min_percpu_pagelist_fract
,
1142 .procname
= "max_map_count",
1143 .data
= &sysctl_max_map_count
,
1144 .maxlen
= sizeof(sysctl_max_map_count
),
1146 .proc_handler
= proc_dointvec_minmax
,
1151 .procname
= "nr_trim_pages",
1152 .data
= &sysctl_nr_trim_pages
,
1153 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1155 .proc_handler
= proc_dointvec_minmax
,
1160 .procname
= "laptop_mode",
1161 .data
= &laptop_mode
,
1162 .maxlen
= sizeof(laptop_mode
),
1164 .proc_handler
= proc_dointvec_jiffies
,
1167 .procname
= "block_dump",
1168 .data
= &block_dump
,
1169 .maxlen
= sizeof(block_dump
),
1171 .proc_handler
= proc_dointvec
,
1175 .procname
= "vfs_cache_pressure",
1176 .data
= &sysctl_vfs_cache_pressure
,
1177 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1179 .proc_handler
= proc_dointvec
,
1182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1184 .procname
= "legacy_va_layout",
1185 .data
= &sysctl_legacy_va_layout
,
1186 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1188 .proc_handler
= proc_dointvec
,
1194 .procname
= "zone_reclaim_mode",
1195 .data
= &zone_reclaim_mode
,
1196 .maxlen
= sizeof(zone_reclaim_mode
),
1198 .proc_handler
= proc_dointvec
,
1202 .procname
= "min_unmapped_ratio",
1203 .data
= &sysctl_min_unmapped_ratio
,
1204 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1206 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1208 .extra2
= &one_hundred
,
1211 .procname
= "min_slab_ratio",
1212 .data
= &sysctl_min_slab_ratio
,
1213 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1215 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1217 .extra2
= &one_hundred
,
1222 .procname
= "stat_interval",
1223 .data
= &sysctl_stat_interval
,
1224 .maxlen
= sizeof(sysctl_stat_interval
),
1226 .proc_handler
= proc_dointvec_jiffies
,
1231 .procname
= "mmap_min_addr",
1232 .data
= &dac_mmap_min_addr
,
1233 .maxlen
= sizeof(unsigned long),
1235 .proc_handler
= mmap_min_addr_handler
,
1240 .procname
= "numa_zonelist_order",
1241 .data
= &numa_zonelist_order
,
1242 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1244 .proc_handler
= numa_zonelist_order_handler
,
1247 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1248 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1250 .procname
= "vdso_enabled",
1251 .data
= &vdso_enabled
,
1252 .maxlen
= sizeof(vdso_enabled
),
1254 .proc_handler
= proc_dointvec
,
1258 #ifdef CONFIG_HIGHMEM
1260 .procname
= "highmem_is_dirtyable",
1261 .data
= &vm_highmem_is_dirtyable
,
1262 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1264 .proc_handler
= proc_dointvec_minmax
,
1270 .procname
= "scan_unevictable_pages",
1271 .data
= &scan_unevictable_pages
,
1272 .maxlen
= sizeof(scan_unevictable_pages
),
1274 .proc_handler
= scan_unevictable_handler
,
1276 #ifdef CONFIG_MEMORY_FAILURE
1278 .procname
= "memory_failure_early_kill",
1279 .data
= &sysctl_memory_failure_early_kill
,
1280 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1282 .proc_handler
= proc_dointvec_minmax
,
1287 .procname
= "memory_failure_recovery",
1288 .data
= &sysctl_memory_failure_recovery
,
1289 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1291 .proc_handler
= proc_dointvec_minmax
,
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1304 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1305 static struct ctl_table binfmt_misc_table
[] = {
1310 static struct ctl_table fs_table
[] = {
1312 .procname
= "inode-nr",
1313 .data
= &inodes_stat
,
1314 .maxlen
= 2*sizeof(int),
1316 .proc_handler
= proc_dointvec
,
1319 .procname
= "inode-state",
1320 .data
= &inodes_stat
,
1321 .maxlen
= 7*sizeof(int),
1323 .proc_handler
= proc_dointvec
,
1326 .procname
= "file-nr",
1327 .data
= &files_stat
,
1328 .maxlen
= 3*sizeof(int),
1330 .proc_handler
= proc_nr_files
,
1333 .procname
= "file-max",
1334 .data
= &files_stat
.max_files
,
1335 .maxlen
= sizeof(int),
1337 .proc_handler
= proc_dointvec
,
1340 .procname
= "nr_open",
1341 .data
= &sysctl_nr_open
,
1342 .maxlen
= sizeof(int),
1344 .proc_handler
= proc_dointvec_minmax
,
1345 .extra1
= &sysctl_nr_open_min
,
1346 .extra2
= &sysctl_nr_open_max
,
1349 .procname
= "dentry-state",
1350 .data
= &dentry_stat
,
1351 .maxlen
= 6*sizeof(int),
1353 .proc_handler
= proc_dointvec
,
1356 .procname
= "overflowuid",
1357 .data
= &fs_overflowuid
,
1358 .maxlen
= sizeof(int),
1360 .proc_handler
= proc_dointvec_minmax
,
1361 .extra1
= &minolduid
,
1362 .extra2
= &maxolduid
,
1365 .procname
= "overflowgid",
1366 .data
= &fs_overflowgid
,
1367 .maxlen
= sizeof(int),
1369 .proc_handler
= proc_dointvec_minmax
,
1370 .extra1
= &minolduid
,
1371 .extra2
= &maxolduid
,
1373 #ifdef CONFIG_FILE_LOCKING
1375 .procname
= "leases-enable",
1376 .data
= &leases_enable
,
1377 .maxlen
= sizeof(int),
1379 .proc_handler
= proc_dointvec
,
1382 #ifdef CONFIG_DNOTIFY
1384 .procname
= "dir-notify-enable",
1385 .data
= &dir_notify_enable
,
1386 .maxlen
= sizeof(int),
1388 .proc_handler
= proc_dointvec
,
1392 #ifdef CONFIG_FILE_LOCKING
1394 .procname
= "lease-break-time",
1395 .data
= &lease_break_time
,
1396 .maxlen
= sizeof(int),
1398 .proc_handler
= proc_dointvec
,
1403 .procname
= "aio-nr",
1405 .maxlen
= sizeof(aio_nr
),
1407 .proc_handler
= proc_doulongvec_minmax
,
1410 .procname
= "aio-max-nr",
1411 .data
= &aio_max_nr
,
1412 .maxlen
= sizeof(aio_max_nr
),
1414 .proc_handler
= proc_doulongvec_minmax
,
1416 #endif /* CONFIG_AIO */
1417 #ifdef CONFIG_INOTIFY_USER
1419 .procname
= "inotify",
1421 .child
= inotify_table
,
1426 .procname
= "epoll",
1428 .child
= epoll_table
,
1433 .procname
= "suid_dumpable",
1434 .data
= &suid_dumpable
,
1435 .maxlen
= sizeof(int),
1437 .proc_handler
= proc_dointvec_minmax
,
1441 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1443 .procname
= "binfmt_misc",
1445 .child
= binfmt_misc_table
,
1449 .procname
= "pipe-max-pages",
1450 .data
= &pipe_max_pages
,
1451 .maxlen
= sizeof(int),
1453 .proc_handler
= &proc_dointvec_minmax
,
1457 * NOTE: do not add new entries to this table unless you have read
1458 * Documentation/sysctl/ctl_unnumbered.txt
1463 static struct ctl_table debug_table
[] = {
1464 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1465 defined(CONFIG_S390)
1467 .procname
= "exception-trace",
1468 .data
= &show_unhandled_signals
,
1469 .maxlen
= sizeof(int),
1471 .proc_handler
= proc_dointvec
1474 #if defined(CONFIG_OPTPROBES)
1476 .procname
= "kprobes-optimization",
1477 .data
= &sysctl_kprobes_optimization
,
1478 .maxlen
= sizeof(int),
1480 .proc_handler
= proc_kprobes_optimization_handler
,
1488 static struct ctl_table dev_table
[] = {
1492 static DEFINE_SPINLOCK(sysctl_lock
);
1494 /* called under sysctl_lock */
1495 static int use_table(struct ctl_table_header
*p
)
1497 if (unlikely(p
->unregistering
))
1503 /* called under sysctl_lock */
1504 static void unuse_table(struct ctl_table_header
*p
)
1507 if (unlikely(p
->unregistering
))
1508 complete(p
->unregistering
);
1511 /* called under sysctl_lock, will reacquire if has to wait */
1512 static void start_unregistering(struct ctl_table_header
*p
)
1515 * if p->used is 0, nobody will ever touch that entry again;
1516 * we'll eliminate all paths to it before dropping sysctl_lock
1518 if (unlikely(p
->used
)) {
1519 struct completion wait
;
1520 init_completion(&wait
);
1521 p
->unregistering
= &wait
;
1522 spin_unlock(&sysctl_lock
);
1523 wait_for_completion(&wait
);
1524 spin_lock(&sysctl_lock
);
1526 /* anything non-NULL; we'll never dereference it */
1527 p
->unregistering
= ERR_PTR(-EINVAL
);
1530 * do not remove from the list until nobody holds it; walking the
1531 * list in do_sysctl() relies on that.
1533 list_del_init(&p
->ctl_entry
);
1536 void sysctl_head_get(struct ctl_table_header
*head
)
1538 spin_lock(&sysctl_lock
);
1540 spin_unlock(&sysctl_lock
);
1543 void sysctl_head_put(struct ctl_table_header
*head
)
1545 spin_lock(&sysctl_lock
);
1548 spin_unlock(&sysctl_lock
);
1551 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1555 spin_lock(&sysctl_lock
);
1556 if (!use_table(head
))
1557 head
= ERR_PTR(-ENOENT
);
1558 spin_unlock(&sysctl_lock
);
1562 void sysctl_head_finish(struct ctl_table_header
*head
)
1566 spin_lock(&sysctl_lock
);
1568 spin_unlock(&sysctl_lock
);
1571 static struct ctl_table_set
*
1572 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1574 struct ctl_table_set
*set
= &root
->default_set
;
1576 set
= root
->lookup(root
, namespaces
);
1580 static struct list_head
*
1581 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1583 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1587 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1588 struct ctl_table_header
*prev
)
1590 struct ctl_table_root
*root
;
1591 struct list_head
*header_list
;
1592 struct ctl_table_header
*head
;
1593 struct list_head
*tmp
;
1595 spin_lock(&sysctl_lock
);
1598 tmp
= &prev
->ctl_entry
;
1602 tmp
= &root_table_header
.ctl_entry
;
1604 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1606 if (!use_table(head
))
1608 spin_unlock(&sysctl_lock
);
1613 header_list
= lookup_header_list(root
, namespaces
);
1614 if (tmp
!= header_list
)
1618 root
= list_entry(root
->root_list
.next
,
1619 struct ctl_table_root
, root_list
);
1620 if (root
== &sysctl_table_root
)
1622 header_list
= lookup_header_list(root
, namespaces
);
1623 } while (list_empty(header_list
));
1624 tmp
= header_list
->next
;
1627 spin_unlock(&sysctl_lock
);
1631 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1633 return __sysctl_head_next(current
->nsproxy
, prev
);
1636 void register_sysctl_root(struct ctl_table_root
*root
)
1638 spin_lock(&sysctl_lock
);
1639 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1640 spin_unlock(&sysctl_lock
);
1644 * sysctl_perm does NOT grant the superuser all rights automatically, because
1645 * some sysctl variables are readonly even to root.
1648 static int test_perm(int mode
, int op
)
1650 if (!current_euid())
1652 else if (in_egroup_p(0))
1654 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1659 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1664 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1668 if (root
->permissions
)
1669 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1673 return test_perm(mode
, op
);
1676 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1678 for (; table
->procname
; table
++) {
1679 table
->parent
= parent
;
1681 sysctl_set_parent(table
, table
->child
);
1685 static __init
int sysctl_init(void)
1687 sysctl_set_parent(NULL
, root_table
);
1688 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1691 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1697 core_initcall(sysctl_init
);
1699 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1700 struct ctl_table
*table
)
1702 struct ctl_table
*p
;
1703 const char *s
= branch
->procname
;
1705 /* branch should have named subdirectory as its first element */
1706 if (!s
|| !branch
->child
)
1709 /* ... and nothing else */
1710 if (branch
[1].procname
)
1713 /* table should contain subdirectory with the same name */
1714 for (p
= table
; p
->procname
; p
++) {
1717 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1723 /* see if attaching q to p would be an improvement */
1724 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1726 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1727 struct ctl_table
*next
;
1729 int not_in_parent
= !p
->attached_by
;
1731 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1732 if (by
== q
->attached_by
)
1734 if (to
== p
->attached_by
)
1740 if (is_better
&& not_in_parent
) {
1741 q
->attached_by
= by
;
1742 q
->attached_to
= to
;
1748 * __register_sysctl_paths - register a sysctl hierarchy
1749 * @root: List of sysctl headers to register on
1750 * @namespaces: Data to compute which lists of sysctl entries are visible
1751 * @path: The path to the directory the sysctl table is in.
1752 * @table: the top-level table structure
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1755 * array. A completely 0 filled entry terminates the table.
1757 * The members of the &struct ctl_table structure are used as follows:
1759 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1760 * enter a sysctl file
1762 * data - a pointer to data for use by proc_handler
1764 * maxlen - the maximum size in bytes of the data
1766 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1768 * child - a pointer to the child sysctl table if this entry is a directory, or
1771 * proc_handler - the text handler routine (described below)
1773 * de - for internal use by the sysctl routines
1775 * extra1, extra2 - extra pointers usable by the proc handler routines
1777 * Leaf nodes in the sysctl tree will be represented by a single file
1778 * under /proc; non-leaf nodes will be represented by directories.
1780 * sysctl(2) can automatically manage read and write requests through
1781 * the sysctl table. The data and maxlen fields of the ctl_table
1782 * struct enable minimal validation of the values being written to be
1783 * performed, and the mode field allows minimal authentication.
1785 * There must be a proc_handler routine for any terminal nodes
1786 * mirrored under /proc/sys (non-terminals are handled by a built-in
1787 * directory handler). Several default handlers are available to
1788 * cover common cases -
1790 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1791 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1792 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1794 * It is the handler's job to read the input buffer from user memory
1795 * and process it. The handler should return 0 on success.
1797 * This routine returns %NULL on a failure to register, and a pointer
1798 * to the table header on success.
1800 struct ctl_table_header
*__register_sysctl_paths(
1801 struct ctl_table_root
*root
,
1802 struct nsproxy
*namespaces
,
1803 const struct ctl_path
*path
, struct ctl_table
*table
)
1805 struct ctl_table_header
*header
;
1806 struct ctl_table
*new, **prevp
;
1807 unsigned int n
, npath
;
1808 struct ctl_table_set
*set
;
1810 /* Count the path components */
1811 for (npath
= 0; path
[npath
].procname
; ++npath
)
1815 * For each path component, allocate a 2-element ctl_table array.
1816 * The first array element will be filled with the sysctl entry
1817 * for this, the second will be the sentinel (procname == 0).
1819 * We allocate everything in one go so that we don't have to
1820 * worry about freeing additional memory in unregister_sysctl_table.
1822 header
= kzalloc(sizeof(struct ctl_table_header
) +
1823 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1827 new = (struct ctl_table
*) (header
+ 1);
1829 /* Now connect the dots */
1830 prevp
= &header
->ctl_table
;
1831 for (n
= 0; n
< npath
; ++n
, ++path
) {
1832 /* Copy the procname */
1833 new->procname
= path
->procname
;
1837 prevp
= &new->child
;
1842 header
->ctl_table_arg
= table
;
1844 INIT_LIST_HEAD(&header
->ctl_entry
);
1846 header
->unregistering
= NULL
;
1847 header
->root
= root
;
1848 sysctl_set_parent(NULL
, header
->ctl_table
);
1850 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1851 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1856 spin_lock(&sysctl_lock
);
1857 header
->set
= lookup_header_set(root
, namespaces
);
1858 header
->attached_by
= header
->ctl_table
;
1859 header
->attached_to
= root_table
;
1860 header
->parent
= &root_table_header
;
1861 for (set
= header
->set
; set
; set
= set
->parent
) {
1862 struct ctl_table_header
*p
;
1863 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1864 if (p
->unregistering
)
1866 try_attach(p
, header
);
1869 header
->parent
->count
++;
1870 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1871 spin_unlock(&sysctl_lock
);
1877 * register_sysctl_table_path - register a sysctl table hierarchy
1878 * @path: The path to the directory the sysctl table is in.
1879 * @table: the top-level table structure
1881 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1882 * array. A completely 0 filled entry terminates the table.
1884 * See __register_sysctl_paths for more details.
1886 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1887 struct ctl_table
*table
)
1889 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1894 * register_sysctl_table - register a sysctl table hierarchy
1895 * @table: the top-level table structure
1897 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1898 * array. A completely 0 filled entry terminates the table.
1900 * See register_sysctl_paths for more details.
1902 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1904 static const struct ctl_path null_path
[] = { {} };
1906 return register_sysctl_paths(null_path
, table
);
1910 * unregister_sysctl_table - unregister a sysctl table hierarchy
1911 * @header: the header returned from register_sysctl_table
1913 * Unregisters the sysctl table and all children. proc entries may not
1914 * actually be removed until they are no longer used by anyone.
1916 void unregister_sysctl_table(struct ctl_table_header
* header
)
1923 spin_lock(&sysctl_lock
);
1924 start_unregistering(header
);
1925 if (!--header
->parent
->count
) {
1927 kfree(header
->parent
);
1929 if (!--header
->count
)
1931 spin_unlock(&sysctl_lock
);
1934 int sysctl_is_seen(struct ctl_table_header
*p
)
1936 struct ctl_table_set
*set
= p
->set
;
1938 spin_lock(&sysctl_lock
);
1939 if (p
->unregistering
)
1941 else if (!set
->is_seen
)
1944 res
= set
->is_seen(set
);
1945 spin_unlock(&sysctl_lock
);
1949 void setup_sysctl_set(struct ctl_table_set
*p
,
1950 struct ctl_table_set
*parent
,
1951 int (*is_seen
)(struct ctl_table_set
*))
1953 INIT_LIST_HEAD(&p
->list
);
1954 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1955 p
->is_seen
= is_seen
;
1958 #else /* !CONFIG_SYSCTL */
1959 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1964 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1965 struct ctl_table
*table
)
1970 void unregister_sysctl_table(struct ctl_table_header
* table
)
1974 void setup_sysctl_set(struct ctl_table_set
*p
,
1975 struct ctl_table_set
*parent
,
1976 int (*is_seen
)(struct ctl_table_set
*))
1980 void sysctl_head_put(struct ctl_table_header
*head
)
1984 #endif /* CONFIG_SYSCTL */
1990 #ifdef CONFIG_PROC_SYSCTL
1992 static int _proc_do_string(void* data
, int maxlen
, int write
,
1993 void __user
*buffer
,
1994 size_t *lenp
, loff_t
*ppos
)
2000 if (!data
|| !maxlen
|| !*lenp
) {
2008 while (len
< *lenp
) {
2009 if (get_user(c
, p
++))
2011 if (c
== 0 || c
== '\n')
2017 if(copy_from_user(data
, buffer
, len
))
2019 ((char *) data
)[len
] = 0;
2037 if(copy_to_user(buffer
, data
, len
))
2040 if(put_user('\n', ((char __user
*) buffer
) + len
))
2051 * proc_dostring - read a string sysctl
2052 * @table: the sysctl table
2053 * @write: %TRUE if this is a write to the sysctl file
2054 * @buffer: the user buffer
2055 * @lenp: the size of the user buffer
2056 * @ppos: file position
2058 * Reads/writes a string from/to the user buffer. If the kernel
2059 * buffer provided is not large enough to hold the string, the
2060 * string is truncated. The copied string is %NULL-terminated.
2061 * If the string is being read by the user process, it is copied
2062 * and a newline '\n' is added. It is truncated if the buffer is
2065 * Returns 0 on success.
2067 int proc_dostring(struct ctl_table
*table
, int write
,
2068 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2070 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2071 buffer
, lenp
, ppos
);
2074 static size_t proc_skip_spaces(char **buf
)
2077 char *tmp
= skip_spaces(*buf
);
2083 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2093 #define TMPBUFLEN 22
2095 * proc_get_long - reads an ASCII formatted integer from a user buffer
2097 * @buf: a kernel buffer
2098 * @size: size of the kernel buffer
2099 * @val: this is where the number will be stored
2100 * @neg: set to %TRUE if number is negative
2101 * @perm_tr: a vector which contains the allowed trailers
2102 * @perm_tr_len: size of the perm_tr vector
2103 * @tr: pointer to store the trailer character
2105 * In case of success %0 is returned and @buf and @size are updated with
2106 * the amount of bytes read. If @tr is non-NULL and a trailing
2107 * character exists (size is non-zero after returning from this
2108 * function), @tr is updated with the trailing character.
2110 static int proc_get_long(char **buf
, size_t *size
,
2111 unsigned long *val
, bool *neg
,
2112 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2115 char *p
, tmp
[TMPBUFLEN
];
2121 if (len
> TMPBUFLEN
- 1)
2122 len
= TMPBUFLEN
- 1;
2124 memcpy(tmp
, *buf
, len
);
2128 if (*p
== '-' && *size
> 1) {
2136 *val
= simple_strtoul(p
, &p
, 0);
2140 /* We don't know if the next char is whitespace thus we may accept
2141 * invalid integers (e.g. 1234...a) or two integers instead of one
2142 * (e.g. 123...1). So lets not allow such large numbers. */
2143 if (len
== TMPBUFLEN
- 1)
2146 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2149 if (tr
&& (len
< *size
))
2159 * proc_put_long - converts an integer to a decimal ASCII formatted string
2161 * @buf: the user buffer
2162 * @size: the size of the user buffer
2163 * @val: the integer to be converted
2164 * @neg: sign of the number, %TRUE for negative
2166 * In case of success %0 is returned and @buf and @size are updated with
2167 * the amount of bytes written.
2169 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2173 char tmp
[TMPBUFLEN
], *p
= tmp
;
2175 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2179 if (copy_to_user(*buf
, tmp
, len
))
2187 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2190 char __user
**buffer
= (char __user
**)buf
;
2191 if (put_user(c
, *buffer
))
2193 (*size
)--, (*buffer
)++;
2199 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2201 int write
, void *data
)
2204 *valp
= *negp
? -*lvalp
: *lvalp
;
2209 *lvalp
= (unsigned long)-val
;
2212 *lvalp
= (unsigned long)val
;
2218 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2220 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2221 int write
, void __user
*buffer
,
2222 size_t *lenp
, loff_t
*ppos
,
2223 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2224 int write
, void *data
),
2227 int *i
, vleft
, first
= 1, err
= 0;
2228 unsigned long page
= 0;
2232 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2237 i
= (int *) tbl_data
;
2238 vleft
= table
->maxlen
/ sizeof(*i
);
2242 conv
= do_proc_dointvec_conv
;
2245 if (left
> PAGE_SIZE
- 1)
2246 left
= PAGE_SIZE
- 1;
2247 page
= __get_free_page(GFP_TEMPORARY
);
2248 kbuf
= (char *) page
;
2251 if (copy_from_user(kbuf
, buffer
, left
)) {
2258 for (; left
&& vleft
--; i
++, first
=0) {
2263 left
-= proc_skip_spaces(&kbuf
);
2265 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2267 sizeof(proc_wspace_sep
), NULL
);
2270 if (conv(&neg
, &lval
, i
, 1, data
)) {
2275 if (conv(&neg
, &lval
, i
, 0, data
)) {
2280 err
= proc_put_char(&buffer
, &left
, '\t');
2283 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2289 if (!write
&& !first
&& left
&& !err
)
2290 err
= proc_put_char(&buffer
, &left
, '\n');
2292 left
-= proc_skip_spaces(&kbuf
);
2297 return err
? : -EINVAL
;
2304 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2305 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2306 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2307 int write
, void *data
),
2310 return __do_proc_dointvec(table
->data
, table
, write
,
2311 buffer
, lenp
, ppos
, conv
, data
);
2315 * proc_dointvec - read a vector of integers
2316 * @table: the sysctl table
2317 * @write: %TRUE if this is a write to the sysctl file
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2325 * Returns 0 on success.
2327 int proc_dointvec(struct ctl_table
*table
, int write
,
2328 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2330 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2335 * Taint values can only be increased
2336 * This means we can safely use a temporary.
2338 static int proc_taint(struct ctl_table
*table
, int write
,
2339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2342 unsigned long tmptaint
= get_taint();
2345 if (write
&& !capable(CAP_SYS_ADMIN
))
2350 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2356 * Poor man's atomic or. Not worth adding a primitive
2357 * to everyone's atomic.h for this
2360 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2361 if ((tmptaint
>> i
) & 1)
2369 struct do_proc_dointvec_minmax_conv_param
{
2374 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2376 int write
, void *data
)
2378 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2380 int val
= *negp
? -*lvalp
: *lvalp
;
2381 if ((param
->min
&& *param
->min
> val
) ||
2382 (param
->max
&& *param
->max
< val
))
2389 *lvalp
= (unsigned long)-val
;
2392 *lvalp
= (unsigned long)val
;
2399 * proc_dointvec_minmax - read a vector of integers with min/max values
2400 * @table: the sysctl table
2401 * @write: %TRUE if this is a write to the sysctl file
2402 * @buffer: the user buffer
2403 * @lenp: the size of the user buffer
2404 * @ppos: file position
2406 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2407 * values from/to the user buffer, treated as an ASCII string.
2409 * This routine will ensure the values are within the range specified by
2410 * table->extra1 (min) and table->extra2 (max).
2412 * Returns 0 on success.
2414 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2415 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2417 struct do_proc_dointvec_minmax_conv_param param
= {
2418 .min
= (int *) table
->extra1
,
2419 .max
= (int *) table
->extra2
,
2421 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2422 do_proc_dointvec_minmax_conv
, ¶m
);
2425 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2426 void __user
*buffer
,
2427 size_t *lenp
, loff_t
*ppos
,
2428 unsigned long convmul
,
2429 unsigned long convdiv
)
2431 unsigned long *i
, *min
, *max
;
2432 int vleft
, first
= 1, err
= 0;
2433 unsigned long page
= 0;
2437 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2442 i
= (unsigned long *) data
;
2443 min
= (unsigned long *) table
->extra1
;
2444 max
= (unsigned long *) table
->extra2
;
2445 vleft
= table
->maxlen
/ sizeof(unsigned long);
2449 if (left
> PAGE_SIZE
- 1)
2450 left
= PAGE_SIZE
- 1;
2451 page
= __get_free_page(GFP_TEMPORARY
);
2452 kbuf
= (char *) page
;
2455 if (copy_from_user(kbuf
, buffer
, left
)) {
2462 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2468 left
-= proc_skip_spaces(&kbuf
);
2470 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2472 sizeof(proc_wspace_sep
), NULL
);
2477 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2481 val
= convdiv
* (*i
) / convmul
;
2483 err
= proc_put_char(&buffer
, &left
, '\t');
2484 err
= proc_put_long(&buffer
, &left
, val
, false);
2490 if (!write
&& !first
&& left
&& !err
)
2491 err
= proc_put_char(&buffer
, &left
, '\n');
2493 left
-= proc_skip_spaces(&kbuf
);
2498 return err
? : -EINVAL
;
2505 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2506 void __user
*buffer
,
2507 size_t *lenp
, loff_t
*ppos
,
2508 unsigned long convmul
,
2509 unsigned long convdiv
)
2511 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2512 buffer
, lenp
, ppos
, convmul
, convdiv
);
2516 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2517 * @table: the sysctl table
2518 * @write: %TRUE if this is a write to the sysctl file
2519 * @buffer: the user buffer
2520 * @lenp: the size of the user buffer
2521 * @ppos: file position
2523 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2524 * values from/to the user buffer, treated as an ASCII string.
2526 * This routine will ensure the values are within the range specified by
2527 * table->extra1 (min) and table->extra2 (max).
2529 * Returns 0 on success.
2531 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2532 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2534 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2538 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2539 * @table: the sysctl table
2540 * @write: %TRUE if this is a write to the sysctl file
2541 * @buffer: the user buffer
2542 * @lenp: the size of the user buffer
2543 * @ppos: file position
2545 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2546 * values from/to the user buffer, treated as an ASCII string. The values
2547 * are treated as milliseconds, and converted to jiffies when they are stored.
2549 * This routine will ensure the values are within the range specified by
2550 * table->extra1 (min) and table->extra2 (max).
2552 * Returns 0 on success.
2554 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2555 void __user
*buffer
,
2556 size_t *lenp
, loff_t
*ppos
)
2558 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2559 lenp
, ppos
, HZ
, 1000l);
2563 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2565 int write
, void *data
)
2568 if (*lvalp
> LONG_MAX
/ HZ
)
2570 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2576 lval
= (unsigned long)-val
;
2579 lval
= (unsigned long)val
;
2586 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2588 int write
, void *data
)
2591 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2593 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2599 lval
= (unsigned long)-val
;
2602 lval
= (unsigned long)val
;
2604 *lvalp
= jiffies_to_clock_t(lval
);
2609 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2611 int write
, void *data
)
2614 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2620 lval
= (unsigned long)-val
;
2623 lval
= (unsigned long)val
;
2625 *lvalp
= jiffies_to_msecs(lval
);
2631 * proc_dointvec_jiffies - read a vector of integers as seconds
2632 * @table: the sysctl table
2633 * @write: %TRUE if this is a write to the sysctl file
2634 * @buffer: the user buffer
2635 * @lenp: the size of the user buffer
2636 * @ppos: file position
2638 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2639 * values from/to the user buffer, treated as an ASCII string.
2640 * The values read are assumed to be in seconds, and are converted into
2643 * Returns 0 on success.
2645 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2646 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2648 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2649 do_proc_dointvec_jiffies_conv
,NULL
);
2653 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2654 * @table: the sysctl table
2655 * @write: %TRUE if this is a write to the sysctl file
2656 * @buffer: the user buffer
2657 * @lenp: the size of the user buffer
2658 * @ppos: pointer to the file position
2660 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2661 * values from/to the user buffer, treated as an ASCII string.
2662 * The values read are assumed to be in 1/USER_HZ seconds, and
2663 * are converted into jiffies.
2665 * Returns 0 on success.
2667 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2668 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2670 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2671 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2675 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2676 * @table: the sysctl table
2677 * @write: %TRUE if this is a write to the sysctl file
2678 * @buffer: the user buffer
2679 * @lenp: the size of the user buffer
2680 * @ppos: file position
2681 * @ppos: the current position in the file
2683 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2684 * values from/to the user buffer, treated as an ASCII string.
2685 * The values read are assumed to be in 1/1000 seconds, and
2686 * are converted into jiffies.
2688 * Returns 0 on success.
2690 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2691 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2693 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2694 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2697 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2698 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2700 struct pid
*new_pid
;
2704 tmp
= pid_vnr(cad_pid
);
2706 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2707 lenp
, ppos
, NULL
, NULL
);
2711 new_pid
= find_get_pid(tmp
);
2715 put_pid(xchg(&cad_pid
, new_pid
));
2720 * proc_do_large_bitmap - read/write from/to a large bitmap
2721 * @table: the sysctl table
2722 * @write: %TRUE if this is a write to the sysctl file
2723 * @buffer: the user buffer
2724 * @lenp: the size of the user buffer
2725 * @ppos: file position
2727 * The bitmap is stored at table->data and the bitmap length (in bits)
2730 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2731 * large bitmaps may be represented in a compact manner. Writing into
2732 * the file will clear the bitmap then update it with the given input.
2734 * Returns 0 on success.
2736 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2737 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2741 size_t left
= *lenp
;
2742 unsigned long bitmap_len
= table
->maxlen
;
2743 unsigned long *bitmap
= (unsigned long *) table
->data
;
2744 unsigned long *tmp_bitmap
= NULL
;
2745 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2747 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2753 unsigned long page
= 0;
2756 if (left
> PAGE_SIZE
- 1)
2757 left
= PAGE_SIZE
- 1;
2759 page
= __get_free_page(GFP_TEMPORARY
);
2760 kbuf
= (char *) page
;
2763 if (copy_from_user(kbuf
, buffer
, left
)) {
2769 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2775 proc_skip_char(&kbuf
, &left
, '\n');
2776 while (!err
&& left
) {
2777 unsigned long val_a
, val_b
;
2780 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2784 if (val_a
>= bitmap_len
|| neg
) {
2796 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2797 &neg
, tr_b
, sizeof(tr_b
),
2801 if (val_b
>= bitmap_len
|| neg
||
2812 while (val_a
<= val_b
)
2813 set_bit(val_a
++, tmp_bitmap
);
2816 proc_skip_char(&kbuf
, &left
, '\n');
2820 unsigned long bit_a
, bit_b
= 0;
2823 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2824 if (bit_a
>= bitmap_len
)
2826 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2830 err
= proc_put_char(&buffer
, &left
, ',');
2834 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2837 if (bit_a
!= bit_b
) {
2838 err
= proc_put_char(&buffer
, &left
, '-');
2841 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2849 err
= proc_put_char(&buffer
, &left
, '\n');
2855 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2857 memcpy(bitmap
, tmp_bitmap
,
2858 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2870 #else /* CONFIG_PROC_FS */
2872 int proc_dostring(struct ctl_table
*table
, int write
,
2873 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2878 int proc_dointvec(struct ctl_table
*table
, int write
,
2879 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2884 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2885 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2890 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2891 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2896 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2897 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2902 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2903 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2908 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2909 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2914 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2915 void __user
*buffer
,
2916 size_t *lenp
, loff_t
*ppos
)
2922 #endif /* CONFIG_PROC_FS */
2925 * No sense putting this after each symbol definition, twice,
2926 * exception granted :-)
2928 EXPORT_SYMBOL(proc_dointvec
);
2929 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2930 EXPORT_SYMBOL(proc_dointvec_minmax
);
2931 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2932 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2933 EXPORT_SYMBOL(proc_dostring
);
2934 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2935 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2936 EXPORT_SYMBOL(register_sysctl_table
);
2937 EXPORT_SYMBOL(register_sysctl_paths
);
2938 EXPORT_SYMBOL(unregister_sysctl_table
);