Merge tag 'pm+acpi-fixes-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6/cjktty.git] / kernel / sysctl.c
blobd8df00e69c14ddabeafc9fdeb5031baeb0a2f1d0
1 /*
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
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
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/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
34 #include <linux/fs.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
69 #ifdef CONFIG_X86
70 #include <asm/nmi.h>
71 #include <asm/stacktrace.h>
72 #include <asm/io.h>
73 #endif
74 #ifdef CONFIG_SPARC
75 #include <asm/setup.h>
76 #endif
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
79 #endif
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
82 #endif
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
85 #endif
86 #ifdef CONFIG_CHR_DEV_SG
87 #include <scsi/sg.h>
88 #endif
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
92 #endif
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory;
99 extern int sysctl_overcommit_ratio;
100 extern int max_threads;
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
106 #endif
107 extern int pid_max;
108 extern int pid_max_min, pid_max_max;
109 extern int sysctl_drop_caches;
110 extern int percpu_pagelist_fraction;
111 extern int compat_log;
112 extern int latencytop_enabled;
113 extern int sysctl_nr_open_min, sysctl_nr_open_max;
114 #ifndef CONFIG_MMU
115 extern int sysctl_nr_trim_pages;
116 #endif
117 #ifdef CONFIG_BLOCK
118 extern int blk_iopoll_enabled;
119 #endif
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty = 60;
124 static int neg_one = -1;
125 #endif
127 static int zero;
128 static int __maybe_unused one = 1;
129 static int __maybe_unused two = 2;
130 static int __maybe_unused three = 3;
131 static unsigned long one_ul = 1;
132 static int one_hundred = 100;
133 #ifdef CONFIG_PRINTK
134 static int ten_thousand = 10000;
135 #endif
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid = 65535;
142 static int minolduid;
143 static int min_percpu_pagelist_fract = 8;
145 static int ngroups_max = NGROUPS_MAX;
146 static const int cap_last_cap = CAP_LAST_CAP;
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
150 #endif
151 #ifdef CONFIG_SPARC
152 #endif
154 #ifdef CONFIG_SPARC64
155 extern int sysctl_tsb_ratio;
156 #endif
158 #ifdef __hppa__
159 extern int pwrsw_enabled;
160 extern int unaligned_enabled;
161 #endif
163 #ifdef CONFIG_IA64
164 extern int unaligned_dump_stack;
165 #endif
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
169 #endif
171 #ifdef CONFIG_PROC_SYSCTL
172 static int proc_do_cad_pid(struct ctl_table *table, int write,
173 void __user *buffer, size_t *lenp, loff_t *ppos);
174 static int proc_taint(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
176 #endif
178 #ifdef CONFIG_PRINTK
179 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos);
181 #endif
183 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
185 #ifdef CONFIG_COREDUMP
186 static int proc_dostring_coredump(struct ctl_table *table, int write,
187 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #endif
190 #ifdef CONFIG_MAGIC_SYSRQ
191 /* Note: sysrq code uses it's own private copy */
192 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
194 static int sysrq_sysctl_handler(ctl_table *table, int write,
195 void __user *buffer, size_t *lenp,
196 loff_t *ppos)
198 int error;
200 error = proc_dointvec(table, write, buffer, lenp, ppos);
201 if (error)
202 return error;
204 if (write)
205 sysrq_toggle_support(__sysrq_enabled);
207 return 0;
210 #endif
212 static struct ctl_table kern_table[];
213 static struct ctl_table vm_table[];
214 static struct ctl_table fs_table[];
215 static struct ctl_table debug_table[];
216 static struct ctl_table dev_table[];
217 extern struct ctl_table random_table[];
218 #ifdef CONFIG_EPOLL
219 extern struct ctl_table epoll_table[];
220 #endif
222 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
223 int sysctl_legacy_va_layout;
224 #endif
226 /* The default sysctl tables: */
228 static struct ctl_table sysctl_base_table[] = {
230 .procname = "kernel",
231 .mode = 0555,
232 .child = kern_table,
235 .procname = "vm",
236 .mode = 0555,
237 .child = vm_table,
240 .procname = "fs",
241 .mode = 0555,
242 .child = fs_table,
245 .procname = "debug",
246 .mode = 0555,
247 .child = debug_table,
250 .procname = "dev",
251 .mode = 0555,
252 .child = dev_table,
257 #ifdef CONFIG_SCHED_DEBUG
258 static int min_sched_granularity_ns = 100000; /* 100 usecs */
259 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
260 static int min_wakeup_granularity_ns; /* 0 usecs */
261 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
262 #ifdef CONFIG_SMP
263 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
264 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
265 #endif /* CONFIG_SMP */
266 #endif /* CONFIG_SCHED_DEBUG */
268 #ifdef CONFIG_COMPACTION
269 static int min_extfrag_threshold;
270 static int max_extfrag_threshold = 1000;
271 #endif
273 static struct ctl_table kern_table[] = {
275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = proc_dointvec,
281 #ifdef CONFIG_SCHED_DEBUG
283 .procname = "sched_min_granularity_ns",
284 .data = &sysctl_sched_min_granularity,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_latency_ns",
293 .data = &sysctl_sched_latency,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
301 .procname = "sched_wakeup_granularity_ns",
302 .data = &sysctl_sched_wakeup_granularity,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_wakeup_granularity_ns,
307 .extra2 = &max_wakeup_granularity_ns,
309 #ifdef CONFIG_SMP
311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
314 .mode = 0644,
315 .proc_handler = sched_proc_update_handler,
316 .extra1 = &min_sched_tunable_scaling,
317 .extra2 = &max_sched_tunable_scaling,
320 .procname = "sched_migration_cost_ns",
321 .data = &sysctl_sched_migration_cost,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
334 .procname = "sched_time_avg_ms",
335 .data = &sysctl_sched_time_avg,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
341 .procname = "sched_shares_window_ns",
342 .data = &sysctl_sched_shares_window,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec,
348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec_minmax,
353 .extra1 = &zero,
354 .extra2 = &one,
356 #endif /* CONFIG_SMP */
357 #ifdef CONFIG_NUMA_BALANCING
359 .procname = "numa_balancing_scan_delay_ms",
360 .data = &sysctl_numa_balancing_scan_delay,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = proc_dointvec,
366 .procname = "numa_balancing_scan_period_min_ms",
367 .data = &sysctl_numa_balancing_scan_period_min,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
373 .procname = "numa_balancing_scan_period_reset",
374 .data = &sysctl_numa_balancing_scan_period_reset,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
380 .procname = "numa_balancing_scan_period_max_ms",
381 .data = &sysctl_numa_balancing_scan_period_max,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = proc_dointvec,
387 .procname = "numa_balancing_scan_size_mb",
388 .data = &sysctl_numa_balancing_scan_size,
389 .maxlen = sizeof(unsigned int),
390 .mode = 0644,
391 .proc_handler = proc_dointvec,
393 #endif /* CONFIG_NUMA_BALANCING */
394 #endif /* CONFIG_SCHED_DEBUG */
396 .procname = "sched_rt_period_us",
397 .data = &sysctl_sched_rt_period,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = sched_rt_handler,
403 .procname = "sched_rt_runtime_us",
404 .data = &sysctl_sched_rt_runtime,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = sched_rt_handler,
410 .procname = "sched_rr_timeslice_ms",
411 .data = &sched_rr_timeslice,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = sched_rr_handler,
416 #ifdef CONFIG_SCHED_AUTOGROUP
418 .procname = "sched_autogroup_enabled",
419 .data = &sysctl_sched_autogroup_enabled,
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
422 .proc_handler = proc_dointvec_minmax,
423 .extra1 = &zero,
424 .extra2 = &one,
426 #endif
427 #ifdef CONFIG_CFS_BANDWIDTH
429 .procname = "sched_cfs_bandwidth_slice_us",
430 .data = &sysctl_sched_cfs_bandwidth_slice,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
433 .proc_handler = proc_dointvec_minmax,
434 .extra1 = &one,
436 #endif
437 #ifdef CONFIG_PROVE_LOCKING
439 .procname = "prove_locking",
440 .data = &prove_locking,
441 .maxlen = sizeof(int),
442 .mode = 0644,
443 .proc_handler = proc_dointvec,
445 #endif
446 #ifdef CONFIG_LOCK_STAT
448 .procname = "lock_stat",
449 .data = &lock_stat,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = proc_dointvec,
454 #endif
456 .procname = "panic",
457 .data = &panic_timeout,
458 .maxlen = sizeof(int),
459 .mode = 0644,
460 .proc_handler = proc_dointvec,
462 #ifdef CONFIG_COREDUMP
464 .procname = "core_uses_pid",
465 .data = &core_uses_pid,
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = proc_dointvec,
471 .procname = "core_pattern",
472 .data = core_pattern,
473 .maxlen = CORENAME_MAX_SIZE,
474 .mode = 0644,
475 .proc_handler = proc_dostring_coredump,
478 .procname = "core_pipe_limit",
479 .data = &core_pipe_limit,
480 .maxlen = sizeof(unsigned int),
481 .mode = 0644,
482 .proc_handler = proc_dointvec,
484 #endif
485 #ifdef CONFIG_PROC_SYSCTL
487 .procname = "tainted",
488 .maxlen = sizeof(long),
489 .mode = 0644,
490 .proc_handler = proc_taint,
492 #endif
493 #ifdef CONFIG_LATENCYTOP
495 .procname = "latencytop",
496 .data = &latencytop_enabled,
497 .maxlen = sizeof(int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec,
501 #endif
502 #ifdef CONFIG_BLK_DEV_INITRD
504 .procname = "real-root-dev",
505 .data = &real_root_dev,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = proc_dointvec,
510 #endif
512 .procname = "print-fatal-signals",
513 .data = &print_fatal_signals,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = proc_dointvec,
518 #ifdef CONFIG_SPARC
520 .procname = "reboot-cmd",
521 .data = reboot_command,
522 .maxlen = 256,
523 .mode = 0644,
524 .proc_handler = proc_dostring,
527 .procname = "stop-a",
528 .data = &stop_a_enabled,
529 .maxlen = sizeof (int),
530 .mode = 0644,
531 .proc_handler = proc_dointvec,
534 .procname = "scons-poweroff",
535 .data = &scons_pwroff,
536 .maxlen = sizeof (int),
537 .mode = 0644,
538 .proc_handler = proc_dointvec,
540 #endif
541 #ifdef CONFIG_SPARC64
543 .procname = "tsb-ratio",
544 .data = &sysctl_tsb_ratio,
545 .maxlen = sizeof (int),
546 .mode = 0644,
547 .proc_handler = proc_dointvec,
549 #endif
550 #ifdef __hppa__
552 .procname = "soft-power",
553 .data = &pwrsw_enabled,
554 .maxlen = sizeof (int),
555 .mode = 0644,
556 .proc_handler = proc_dointvec,
559 .procname = "unaligned-trap",
560 .data = &unaligned_enabled,
561 .maxlen = sizeof (int),
562 .mode = 0644,
563 .proc_handler = proc_dointvec,
565 #endif
567 .procname = "ctrl-alt-del",
568 .data = &C_A_D,
569 .maxlen = sizeof(int),
570 .mode = 0644,
571 .proc_handler = proc_dointvec,
573 #ifdef CONFIG_FUNCTION_TRACER
575 .procname = "ftrace_enabled",
576 .data = &ftrace_enabled,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 .proc_handler = ftrace_enable_sysctl,
581 #endif
582 #ifdef CONFIG_STACK_TRACER
584 .procname = "stack_tracer_enabled",
585 .data = &stack_tracer_enabled,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = stack_trace_sysctl,
590 #endif
591 #ifdef CONFIG_TRACING
593 .procname = "ftrace_dump_on_oops",
594 .data = &ftrace_dump_on_oops,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = proc_dointvec,
599 #endif
600 #ifdef CONFIG_MODULES
602 .procname = "modprobe",
603 .data = &modprobe_path,
604 .maxlen = KMOD_PATH_LEN,
605 .mode = 0644,
606 .proc_handler = proc_dostring,
609 .procname = "modules_disabled",
610 .data = &modules_disabled,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 /* only handle a transition from default "0" to "1" */
614 .proc_handler = proc_dointvec_minmax,
615 .extra1 = &one,
616 .extra2 = &one,
618 #endif
621 .procname = "hotplug",
622 .data = &uevent_helper,
623 .maxlen = UEVENT_HELPER_PATH_LEN,
624 .mode = 0644,
625 .proc_handler = proc_dostring,
628 #ifdef CONFIG_CHR_DEV_SG
630 .procname = "sg-big-buff",
631 .data = &sg_big_buff,
632 .maxlen = sizeof (int),
633 .mode = 0444,
634 .proc_handler = proc_dointvec,
636 #endif
637 #ifdef CONFIG_BSD_PROCESS_ACCT
639 .procname = "acct",
640 .data = &acct_parm,
641 .maxlen = 3*sizeof(int),
642 .mode = 0644,
643 .proc_handler = proc_dointvec,
645 #endif
646 #ifdef CONFIG_MAGIC_SYSRQ
648 .procname = "sysrq",
649 .data = &__sysrq_enabled,
650 .maxlen = sizeof (int),
651 .mode = 0644,
652 .proc_handler = sysrq_sysctl_handler,
654 #endif
655 #ifdef CONFIG_PROC_SYSCTL
657 .procname = "cad_pid",
658 .data = NULL,
659 .maxlen = sizeof (int),
660 .mode = 0600,
661 .proc_handler = proc_do_cad_pid,
663 #endif
665 .procname = "threads-max",
666 .data = &max_threads,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = proc_dointvec,
672 .procname = "random",
673 .mode = 0555,
674 .child = random_table,
677 .procname = "usermodehelper",
678 .mode = 0555,
679 .child = usermodehelper_table,
682 .procname = "overflowuid",
683 .data = &overflowuid,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = proc_dointvec_minmax,
687 .extra1 = &minolduid,
688 .extra2 = &maxolduid,
691 .procname = "overflowgid",
692 .data = &overflowgid,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = proc_dointvec_minmax,
696 .extra1 = &minolduid,
697 .extra2 = &maxolduid,
699 #ifdef CONFIG_S390
700 #ifdef CONFIG_MATHEMU
702 .procname = "ieee_emulation_warnings",
703 .data = &sysctl_ieee_emulation_warnings,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = proc_dointvec,
708 #endif
710 .procname = "userprocess_debug",
711 .data = &show_unhandled_signals,
712 .maxlen = sizeof(int),
713 .mode = 0644,
714 .proc_handler = proc_dointvec,
716 #endif
718 .procname = "pid_max",
719 .data = &pid_max,
720 .maxlen = sizeof (int),
721 .mode = 0644,
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &pid_max_min,
724 .extra2 = &pid_max_max,
727 .procname = "panic_on_oops",
728 .data = &panic_on_oops,
729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = proc_dointvec,
733 #if defined CONFIG_PRINTK
735 .procname = "printk",
736 .data = &console_loglevel,
737 .maxlen = 4*sizeof(int),
738 .mode = 0644,
739 .proc_handler = proc_dointvec,
742 .procname = "printk_ratelimit",
743 .data = &printk_ratelimit_state.interval,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = proc_dointvec_jiffies,
749 .procname = "printk_ratelimit_burst",
750 .data = &printk_ratelimit_state.burst,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec,
756 .procname = "printk_delay",
757 .data = &printk_delay_msec,
758 .maxlen = sizeof(int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec_minmax,
761 .extra1 = &zero,
762 .extra2 = &ten_thousand,
765 .procname = "dmesg_restrict",
766 .data = &dmesg_restrict,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec_minmax_sysadmin,
770 .extra1 = &zero,
771 .extra2 = &one,
774 .procname = "kptr_restrict",
775 .data = &kptr_restrict,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec_minmax_sysadmin,
779 .extra1 = &zero,
780 .extra2 = &two,
782 #endif
784 .procname = "ngroups_max",
785 .data = &ngroups_max,
786 .maxlen = sizeof (int),
787 .mode = 0444,
788 .proc_handler = proc_dointvec,
791 .procname = "cap_last_cap",
792 .data = (void *)&cap_last_cap,
793 .maxlen = sizeof(int),
794 .mode = 0444,
795 .proc_handler = proc_dointvec,
797 #if defined(CONFIG_LOCKUP_DETECTOR)
799 .procname = "watchdog",
800 .data = &watchdog_enabled,
801 .maxlen = sizeof (int),
802 .mode = 0644,
803 .proc_handler = proc_dowatchdog,
804 .extra1 = &zero,
805 .extra2 = &one,
808 .procname = "watchdog_thresh",
809 .data = &watchdog_thresh,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = proc_dowatchdog,
813 .extra1 = &neg_one,
814 .extra2 = &sixty,
817 .procname = "softlockup_panic",
818 .data = &softlockup_panic,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = proc_dointvec_minmax,
822 .extra1 = &zero,
823 .extra2 = &one,
826 .procname = "nmi_watchdog",
827 .data = &watchdog_enabled,
828 .maxlen = sizeof (int),
829 .mode = 0644,
830 .proc_handler = proc_dowatchdog,
831 .extra1 = &zero,
832 .extra2 = &one,
834 #endif
835 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
837 .procname = "unknown_nmi_panic",
838 .data = &unknown_nmi_panic,
839 .maxlen = sizeof (int),
840 .mode = 0644,
841 .proc_handler = proc_dointvec,
843 #endif
844 #if defined(CONFIG_X86)
846 .procname = "panic_on_unrecovered_nmi",
847 .data = &panic_on_unrecovered_nmi,
848 .maxlen = sizeof(int),
849 .mode = 0644,
850 .proc_handler = proc_dointvec,
853 .procname = "panic_on_io_nmi",
854 .data = &panic_on_io_nmi,
855 .maxlen = sizeof(int),
856 .mode = 0644,
857 .proc_handler = proc_dointvec,
859 #ifdef CONFIG_DEBUG_STACKOVERFLOW
861 .procname = "panic_on_stackoverflow",
862 .data = &sysctl_panic_on_stackoverflow,
863 .maxlen = sizeof(int),
864 .mode = 0644,
865 .proc_handler = proc_dointvec,
867 #endif
869 .procname = "bootloader_type",
870 .data = &bootloader_type,
871 .maxlen = sizeof (int),
872 .mode = 0444,
873 .proc_handler = proc_dointvec,
876 .procname = "bootloader_version",
877 .data = &bootloader_version,
878 .maxlen = sizeof (int),
879 .mode = 0444,
880 .proc_handler = proc_dointvec,
883 .procname = "kstack_depth_to_print",
884 .data = &kstack_depth_to_print,
885 .maxlen = sizeof(int),
886 .mode = 0644,
887 .proc_handler = proc_dointvec,
890 .procname = "io_delay_type",
891 .data = &io_delay_type,
892 .maxlen = sizeof(int),
893 .mode = 0644,
894 .proc_handler = proc_dointvec,
896 #endif
897 #if defined(CONFIG_MMU)
899 .procname = "randomize_va_space",
900 .data = &randomize_va_space,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = proc_dointvec,
905 #endif
906 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
908 .procname = "spin_retry",
909 .data = &spin_retry,
910 .maxlen = sizeof (int),
911 .mode = 0644,
912 .proc_handler = proc_dointvec,
914 #endif
915 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
917 .procname = "acpi_video_flags",
918 .data = &acpi_realmode_flags,
919 .maxlen = sizeof (unsigned long),
920 .mode = 0644,
921 .proc_handler = proc_doulongvec_minmax,
923 #endif
924 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
926 .procname = "ignore-unaligned-usertrap",
927 .data = &no_unaligned_warning,
928 .maxlen = sizeof (int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
932 #endif
933 #ifdef CONFIG_IA64
935 .procname = "unaligned-dump-stack",
936 .data = &unaligned_dump_stack,
937 .maxlen = sizeof (int),
938 .mode = 0644,
939 .proc_handler = proc_dointvec,
941 #endif
942 #ifdef CONFIG_DETECT_HUNG_TASK
944 .procname = "hung_task_panic",
945 .data = &sysctl_hung_task_panic,
946 .maxlen = sizeof(int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec_minmax,
949 .extra1 = &zero,
950 .extra2 = &one,
953 .procname = "hung_task_check_count",
954 .data = &sysctl_hung_task_check_count,
955 .maxlen = sizeof(unsigned long),
956 .mode = 0644,
957 .proc_handler = proc_doulongvec_minmax,
960 .procname = "hung_task_timeout_secs",
961 .data = &sysctl_hung_task_timeout_secs,
962 .maxlen = sizeof(unsigned long),
963 .mode = 0644,
964 .proc_handler = proc_dohung_task_timeout_secs,
967 .procname = "hung_task_warnings",
968 .data = &sysctl_hung_task_warnings,
969 .maxlen = sizeof(unsigned long),
970 .mode = 0644,
971 .proc_handler = proc_doulongvec_minmax,
973 #endif
974 #ifdef CONFIG_COMPAT
976 .procname = "compat-log",
977 .data = &compat_log,
978 .maxlen = sizeof (int),
979 .mode = 0644,
980 .proc_handler = proc_dointvec,
982 #endif
983 #ifdef CONFIG_RT_MUTEXES
985 .procname = "max_lock_depth",
986 .data = &max_lock_depth,
987 .maxlen = sizeof(int),
988 .mode = 0644,
989 .proc_handler = proc_dointvec,
991 #endif
993 .procname = "poweroff_cmd",
994 .data = &poweroff_cmd,
995 .maxlen = POWEROFF_CMD_PATH_LEN,
996 .mode = 0644,
997 .proc_handler = proc_dostring,
999 #ifdef CONFIG_KEYS
1001 .procname = "keys",
1002 .mode = 0555,
1003 .child = key_sysctls,
1005 #endif
1006 #ifdef CONFIG_RCU_TORTURE_TEST
1008 .procname = "rcutorture_runnable",
1009 .data = &rcutorture_runnable,
1010 .maxlen = sizeof(int),
1011 .mode = 0644,
1012 .proc_handler = proc_dointvec,
1014 #endif
1015 #ifdef CONFIG_PERF_EVENTS
1017 * User-space scripts rely on the existence of this file
1018 * as a feature check for perf_events being enabled.
1020 * So it's an ABI, do not remove!
1023 .procname = "perf_event_paranoid",
1024 .data = &sysctl_perf_event_paranoid,
1025 .maxlen = sizeof(sysctl_perf_event_paranoid),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec,
1030 .procname = "perf_event_mlock_kb",
1031 .data = &sysctl_perf_event_mlock,
1032 .maxlen = sizeof(sysctl_perf_event_mlock),
1033 .mode = 0644,
1034 .proc_handler = proc_dointvec,
1037 .procname = "perf_event_max_sample_rate",
1038 .data = &sysctl_perf_event_sample_rate,
1039 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1040 .mode = 0644,
1041 .proc_handler = perf_proc_update_handler,
1043 #endif
1044 #ifdef CONFIG_KMEMCHECK
1046 .procname = "kmemcheck",
1047 .data = &kmemcheck_enabled,
1048 .maxlen = sizeof(int),
1049 .mode = 0644,
1050 .proc_handler = proc_dointvec,
1052 #endif
1053 #ifdef CONFIG_BLOCK
1055 .procname = "blk_iopoll",
1056 .data = &blk_iopoll_enabled,
1057 .maxlen = sizeof(int),
1058 .mode = 0644,
1059 .proc_handler = proc_dointvec,
1061 #endif
1065 static struct ctl_table vm_table[] = {
1067 .procname = "overcommit_memory",
1068 .data = &sysctl_overcommit_memory,
1069 .maxlen = sizeof(sysctl_overcommit_memory),
1070 .mode = 0644,
1071 .proc_handler = proc_dointvec_minmax,
1072 .extra1 = &zero,
1073 .extra2 = &two,
1076 .procname = "panic_on_oom",
1077 .data = &sysctl_panic_on_oom,
1078 .maxlen = sizeof(sysctl_panic_on_oom),
1079 .mode = 0644,
1080 .proc_handler = proc_dointvec_minmax,
1081 .extra1 = &zero,
1082 .extra2 = &two,
1085 .procname = "oom_kill_allocating_task",
1086 .data = &sysctl_oom_kill_allocating_task,
1087 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1088 .mode = 0644,
1089 .proc_handler = proc_dointvec,
1092 .procname = "oom_dump_tasks",
1093 .data = &sysctl_oom_dump_tasks,
1094 .maxlen = sizeof(sysctl_oom_dump_tasks),
1095 .mode = 0644,
1096 .proc_handler = proc_dointvec,
1099 .procname = "overcommit_ratio",
1100 .data = &sysctl_overcommit_ratio,
1101 .maxlen = sizeof(sysctl_overcommit_ratio),
1102 .mode = 0644,
1103 .proc_handler = proc_dointvec,
1106 .procname = "page-cluster",
1107 .data = &page_cluster,
1108 .maxlen = sizeof(int),
1109 .mode = 0644,
1110 .proc_handler = proc_dointvec_minmax,
1111 .extra1 = &zero,
1114 .procname = "dirty_background_ratio",
1115 .data = &dirty_background_ratio,
1116 .maxlen = sizeof(dirty_background_ratio),
1117 .mode = 0644,
1118 .proc_handler = dirty_background_ratio_handler,
1119 .extra1 = &zero,
1120 .extra2 = &one_hundred,
1123 .procname = "dirty_background_bytes",
1124 .data = &dirty_background_bytes,
1125 .maxlen = sizeof(dirty_background_bytes),
1126 .mode = 0644,
1127 .proc_handler = dirty_background_bytes_handler,
1128 .extra1 = &one_ul,
1131 .procname = "dirty_ratio",
1132 .data = &vm_dirty_ratio,
1133 .maxlen = sizeof(vm_dirty_ratio),
1134 .mode = 0644,
1135 .proc_handler = dirty_ratio_handler,
1136 .extra1 = &zero,
1137 .extra2 = &one_hundred,
1140 .procname = "dirty_bytes",
1141 .data = &vm_dirty_bytes,
1142 .maxlen = sizeof(vm_dirty_bytes),
1143 .mode = 0644,
1144 .proc_handler = dirty_bytes_handler,
1145 .extra1 = &dirty_bytes_min,
1148 .procname = "dirty_writeback_centisecs",
1149 .data = &dirty_writeback_interval,
1150 .maxlen = sizeof(dirty_writeback_interval),
1151 .mode = 0644,
1152 .proc_handler = dirty_writeback_centisecs_handler,
1155 .procname = "dirty_expire_centisecs",
1156 .data = &dirty_expire_interval,
1157 .maxlen = sizeof(dirty_expire_interval),
1158 .mode = 0644,
1159 .proc_handler = proc_dointvec_minmax,
1160 .extra1 = &zero,
1163 .procname = "nr_pdflush_threads",
1164 .mode = 0444 /* read-only */,
1165 .proc_handler = pdflush_proc_obsolete,
1168 .procname = "swappiness",
1169 .data = &vm_swappiness,
1170 .maxlen = sizeof(vm_swappiness),
1171 .mode = 0644,
1172 .proc_handler = proc_dointvec_minmax,
1173 .extra1 = &zero,
1174 .extra2 = &one_hundred,
1176 #ifdef CONFIG_HUGETLB_PAGE
1178 .procname = "nr_hugepages",
1179 .data = NULL,
1180 .maxlen = sizeof(unsigned long),
1181 .mode = 0644,
1182 .proc_handler = hugetlb_sysctl_handler,
1183 .extra1 = (void *)&hugetlb_zero,
1184 .extra2 = (void *)&hugetlb_infinity,
1186 #ifdef CONFIG_NUMA
1188 .procname = "nr_hugepages_mempolicy",
1189 .data = NULL,
1190 .maxlen = sizeof(unsigned long),
1191 .mode = 0644,
1192 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1193 .extra1 = (void *)&hugetlb_zero,
1194 .extra2 = (void *)&hugetlb_infinity,
1196 #endif
1198 .procname = "hugetlb_shm_group",
1199 .data = &sysctl_hugetlb_shm_group,
1200 .maxlen = sizeof(gid_t),
1201 .mode = 0644,
1202 .proc_handler = proc_dointvec,
1205 .procname = "hugepages_treat_as_movable",
1206 .data = &hugepages_treat_as_movable,
1207 .maxlen = sizeof(int),
1208 .mode = 0644,
1209 .proc_handler = hugetlb_treat_movable_handler,
1212 .procname = "nr_overcommit_hugepages",
1213 .data = NULL,
1214 .maxlen = sizeof(unsigned long),
1215 .mode = 0644,
1216 .proc_handler = hugetlb_overcommit_handler,
1217 .extra1 = (void *)&hugetlb_zero,
1218 .extra2 = (void *)&hugetlb_infinity,
1220 #endif
1222 .procname = "lowmem_reserve_ratio",
1223 .data = &sysctl_lowmem_reserve_ratio,
1224 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1225 .mode = 0644,
1226 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1229 .procname = "drop_caches",
1230 .data = &sysctl_drop_caches,
1231 .maxlen = sizeof(int),
1232 .mode = 0644,
1233 .proc_handler = drop_caches_sysctl_handler,
1234 .extra1 = &one,
1235 .extra2 = &three,
1237 #ifdef CONFIG_COMPACTION
1239 .procname = "compact_memory",
1240 .data = &sysctl_compact_memory,
1241 .maxlen = sizeof(int),
1242 .mode = 0200,
1243 .proc_handler = sysctl_compaction_handler,
1246 .procname = "extfrag_threshold",
1247 .data = &sysctl_extfrag_threshold,
1248 .maxlen = sizeof(int),
1249 .mode = 0644,
1250 .proc_handler = sysctl_extfrag_handler,
1251 .extra1 = &min_extfrag_threshold,
1252 .extra2 = &max_extfrag_threshold,
1255 #endif /* CONFIG_COMPACTION */
1257 .procname = "min_free_kbytes",
1258 .data = &min_free_kbytes,
1259 .maxlen = sizeof(min_free_kbytes),
1260 .mode = 0644,
1261 .proc_handler = min_free_kbytes_sysctl_handler,
1262 .extra1 = &zero,
1265 .procname = "percpu_pagelist_fraction",
1266 .data = &percpu_pagelist_fraction,
1267 .maxlen = sizeof(percpu_pagelist_fraction),
1268 .mode = 0644,
1269 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1270 .extra1 = &min_percpu_pagelist_fract,
1272 #ifdef CONFIG_MMU
1274 .procname = "max_map_count",
1275 .data = &sysctl_max_map_count,
1276 .maxlen = sizeof(sysctl_max_map_count),
1277 .mode = 0644,
1278 .proc_handler = proc_dointvec_minmax,
1279 .extra1 = &zero,
1281 #else
1283 .procname = "nr_trim_pages",
1284 .data = &sysctl_nr_trim_pages,
1285 .maxlen = sizeof(sysctl_nr_trim_pages),
1286 .mode = 0644,
1287 .proc_handler = proc_dointvec_minmax,
1288 .extra1 = &zero,
1290 #endif
1292 .procname = "laptop_mode",
1293 .data = &laptop_mode,
1294 .maxlen = sizeof(laptop_mode),
1295 .mode = 0644,
1296 .proc_handler = proc_dointvec_jiffies,
1299 .procname = "block_dump",
1300 .data = &block_dump,
1301 .maxlen = sizeof(block_dump),
1302 .mode = 0644,
1303 .proc_handler = proc_dointvec,
1304 .extra1 = &zero,
1307 .procname = "vfs_cache_pressure",
1308 .data = &sysctl_vfs_cache_pressure,
1309 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1310 .mode = 0644,
1311 .proc_handler = proc_dointvec,
1312 .extra1 = &zero,
1314 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1316 .procname = "legacy_va_layout",
1317 .data = &sysctl_legacy_va_layout,
1318 .maxlen = sizeof(sysctl_legacy_va_layout),
1319 .mode = 0644,
1320 .proc_handler = proc_dointvec,
1321 .extra1 = &zero,
1323 #endif
1324 #ifdef CONFIG_NUMA
1326 .procname = "zone_reclaim_mode",
1327 .data = &zone_reclaim_mode,
1328 .maxlen = sizeof(zone_reclaim_mode),
1329 .mode = 0644,
1330 .proc_handler = proc_dointvec,
1331 .extra1 = &zero,
1334 .procname = "min_unmapped_ratio",
1335 .data = &sysctl_min_unmapped_ratio,
1336 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1337 .mode = 0644,
1338 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1339 .extra1 = &zero,
1340 .extra2 = &one_hundred,
1343 .procname = "min_slab_ratio",
1344 .data = &sysctl_min_slab_ratio,
1345 .maxlen = sizeof(sysctl_min_slab_ratio),
1346 .mode = 0644,
1347 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1348 .extra1 = &zero,
1349 .extra2 = &one_hundred,
1351 #endif
1352 #ifdef CONFIG_SMP
1354 .procname = "stat_interval",
1355 .data = &sysctl_stat_interval,
1356 .maxlen = sizeof(sysctl_stat_interval),
1357 .mode = 0644,
1358 .proc_handler = proc_dointvec_jiffies,
1360 #endif
1361 #ifdef CONFIG_MMU
1363 .procname = "mmap_min_addr",
1364 .data = &dac_mmap_min_addr,
1365 .maxlen = sizeof(unsigned long),
1366 .mode = 0644,
1367 .proc_handler = mmap_min_addr_handler,
1369 #endif
1370 #ifdef CONFIG_NUMA
1372 .procname = "numa_zonelist_order",
1373 .data = &numa_zonelist_order,
1374 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1375 .mode = 0644,
1376 .proc_handler = numa_zonelist_order_handler,
1378 #endif
1379 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1380 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1382 .procname = "vdso_enabled",
1383 .data = &vdso_enabled,
1384 .maxlen = sizeof(vdso_enabled),
1385 .mode = 0644,
1386 .proc_handler = proc_dointvec,
1387 .extra1 = &zero,
1389 #endif
1390 #ifdef CONFIG_HIGHMEM
1392 .procname = "highmem_is_dirtyable",
1393 .data = &vm_highmem_is_dirtyable,
1394 .maxlen = sizeof(vm_highmem_is_dirtyable),
1395 .mode = 0644,
1396 .proc_handler = proc_dointvec_minmax,
1397 .extra1 = &zero,
1398 .extra2 = &one,
1400 #endif
1402 .procname = "scan_unevictable_pages",
1403 .data = &scan_unevictable_pages,
1404 .maxlen = sizeof(scan_unevictable_pages),
1405 .mode = 0644,
1406 .proc_handler = scan_unevictable_handler,
1408 #ifdef CONFIG_MEMORY_FAILURE
1410 .procname = "memory_failure_early_kill",
1411 .data = &sysctl_memory_failure_early_kill,
1412 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1413 .mode = 0644,
1414 .proc_handler = proc_dointvec_minmax,
1415 .extra1 = &zero,
1416 .extra2 = &one,
1419 .procname = "memory_failure_recovery",
1420 .data = &sysctl_memory_failure_recovery,
1421 .maxlen = sizeof(sysctl_memory_failure_recovery),
1422 .mode = 0644,
1423 .proc_handler = proc_dointvec_minmax,
1424 .extra1 = &zero,
1425 .extra2 = &one,
1427 #endif
1431 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1432 static struct ctl_table binfmt_misc_table[] = {
1435 #endif
1437 static struct ctl_table fs_table[] = {
1439 .procname = "inode-nr",
1440 .data = &inodes_stat,
1441 .maxlen = 2*sizeof(int),
1442 .mode = 0444,
1443 .proc_handler = proc_nr_inodes,
1446 .procname = "inode-state",
1447 .data = &inodes_stat,
1448 .maxlen = 7*sizeof(int),
1449 .mode = 0444,
1450 .proc_handler = proc_nr_inodes,
1453 .procname = "file-nr",
1454 .data = &files_stat,
1455 .maxlen = sizeof(files_stat),
1456 .mode = 0444,
1457 .proc_handler = proc_nr_files,
1460 .procname = "file-max",
1461 .data = &files_stat.max_files,
1462 .maxlen = sizeof(files_stat.max_files),
1463 .mode = 0644,
1464 .proc_handler = proc_doulongvec_minmax,
1467 .procname = "nr_open",
1468 .data = &sysctl_nr_open,
1469 .maxlen = sizeof(int),
1470 .mode = 0644,
1471 .proc_handler = proc_dointvec_minmax,
1472 .extra1 = &sysctl_nr_open_min,
1473 .extra2 = &sysctl_nr_open_max,
1476 .procname = "dentry-state",
1477 .data = &dentry_stat,
1478 .maxlen = 6*sizeof(int),
1479 .mode = 0444,
1480 .proc_handler = proc_nr_dentry,
1483 .procname = "overflowuid",
1484 .data = &fs_overflowuid,
1485 .maxlen = sizeof(int),
1486 .mode = 0644,
1487 .proc_handler = proc_dointvec_minmax,
1488 .extra1 = &minolduid,
1489 .extra2 = &maxolduid,
1492 .procname = "overflowgid",
1493 .data = &fs_overflowgid,
1494 .maxlen = sizeof(int),
1495 .mode = 0644,
1496 .proc_handler = proc_dointvec_minmax,
1497 .extra1 = &minolduid,
1498 .extra2 = &maxolduid,
1500 #ifdef CONFIG_FILE_LOCKING
1502 .procname = "leases-enable",
1503 .data = &leases_enable,
1504 .maxlen = sizeof(int),
1505 .mode = 0644,
1506 .proc_handler = proc_dointvec,
1508 #endif
1509 #ifdef CONFIG_DNOTIFY
1511 .procname = "dir-notify-enable",
1512 .data = &dir_notify_enable,
1513 .maxlen = sizeof(int),
1514 .mode = 0644,
1515 .proc_handler = proc_dointvec,
1517 #endif
1518 #ifdef CONFIG_MMU
1519 #ifdef CONFIG_FILE_LOCKING
1521 .procname = "lease-break-time",
1522 .data = &lease_break_time,
1523 .maxlen = sizeof(int),
1524 .mode = 0644,
1525 .proc_handler = proc_dointvec,
1527 #endif
1528 #ifdef CONFIG_AIO
1530 .procname = "aio-nr",
1531 .data = &aio_nr,
1532 .maxlen = sizeof(aio_nr),
1533 .mode = 0444,
1534 .proc_handler = proc_doulongvec_minmax,
1537 .procname = "aio-max-nr",
1538 .data = &aio_max_nr,
1539 .maxlen = sizeof(aio_max_nr),
1540 .mode = 0644,
1541 .proc_handler = proc_doulongvec_minmax,
1543 #endif /* CONFIG_AIO */
1544 #ifdef CONFIG_INOTIFY_USER
1546 .procname = "inotify",
1547 .mode = 0555,
1548 .child = inotify_table,
1550 #endif
1551 #ifdef CONFIG_EPOLL
1553 .procname = "epoll",
1554 .mode = 0555,
1555 .child = epoll_table,
1557 #endif
1558 #endif
1560 .procname = "protected_symlinks",
1561 .data = &sysctl_protected_symlinks,
1562 .maxlen = sizeof(int),
1563 .mode = 0600,
1564 .proc_handler = proc_dointvec_minmax,
1565 .extra1 = &zero,
1566 .extra2 = &one,
1569 .procname = "protected_hardlinks",
1570 .data = &sysctl_protected_hardlinks,
1571 .maxlen = sizeof(int),
1572 .mode = 0600,
1573 .proc_handler = proc_dointvec_minmax,
1574 .extra1 = &zero,
1575 .extra2 = &one,
1578 .procname = "suid_dumpable",
1579 .data = &suid_dumpable,
1580 .maxlen = sizeof(int),
1581 .mode = 0644,
1582 .proc_handler = proc_dointvec_minmax_coredump,
1583 .extra1 = &zero,
1584 .extra2 = &two,
1586 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1588 .procname = "binfmt_misc",
1589 .mode = 0555,
1590 .child = binfmt_misc_table,
1592 #endif
1594 .procname = "pipe-max-size",
1595 .data = &pipe_max_size,
1596 .maxlen = sizeof(int),
1597 .mode = 0644,
1598 .proc_handler = &pipe_proc_fn,
1599 .extra1 = &pipe_min_size,
1604 static struct ctl_table debug_table[] = {
1605 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1607 .procname = "exception-trace",
1608 .data = &show_unhandled_signals,
1609 .maxlen = sizeof(int),
1610 .mode = 0644,
1611 .proc_handler = proc_dointvec
1613 #endif
1614 #if defined(CONFIG_OPTPROBES)
1616 .procname = "kprobes-optimization",
1617 .data = &sysctl_kprobes_optimization,
1618 .maxlen = sizeof(int),
1619 .mode = 0644,
1620 .proc_handler = proc_kprobes_optimization_handler,
1621 .extra1 = &zero,
1622 .extra2 = &one,
1624 #endif
1628 static struct ctl_table dev_table[] = {
1632 int __init sysctl_init(void)
1634 struct ctl_table_header *hdr;
1636 hdr = register_sysctl_table(sysctl_base_table);
1637 kmemleak_not_leak(hdr);
1638 return 0;
1641 #endif /* CONFIG_SYSCTL */
1644 * /proc/sys support
1647 #ifdef CONFIG_PROC_SYSCTL
1649 static int _proc_do_string(void* data, int maxlen, int write,
1650 void __user *buffer,
1651 size_t *lenp, loff_t *ppos)
1653 size_t len;
1654 char __user *p;
1655 char c;
1657 if (!data || !maxlen || !*lenp) {
1658 *lenp = 0;
1659 return 0;
1662 if (write) {
1663 len = 0;
1664 p = buffer;
1665 while (len < *lenp) {
1666 if (get_user(c, p++))
1667 return -EFAULT;
1668 if (c == 0 || c == '\n')
1669 break;
1670 len++;
1672 if (len >= maxlen)
1673 len = maxlen-1;
1674 if(copy_from_user(data, buffer, len))
1675 return -EFAULT;
1676 ((char *) data)[len] = 0;
1677 *ppos += *lenp;
1678 } else {
1679 len = strlen(data);
1680 if (len > maxlen)
1681 len = maxlen;
1683 if (*ppos > len) {
1684 *lenp = 0;
1685 return 0;
1688 data += *ppos;
1689 len -= *ppos;
1691 if (len > *lenp)
1692 len = *lenp;
1693 if (len)
1694 if(copy_to_user(buffer, data, len))
1695 return -EFAULT;
1696 if (len < *lenp) {
1697 if(put_user('\n', ((char __user *) buffer) + len))
1698 return -EFAULT;
1699 len++;
1701 *lenp = len;
1702 *ppos += len;
1704 return 0;
1708 * proc_dostring - read a string sysctl
1709 * @table: the sysctl table
1710 * @write: %TRUE if this is a write to the sysctl file
1711 * @buffer: the user buffer
1712 * @lenp: the size of the user buffer
1713 * @ppos: file position
1715 * Reads/writes a string from/to the user buffer. If the kernel
1716 * buffer provided is not large enough to hold the string, the
1717 * string is truncated. The copied string is %NULL-terminated.
1718 * If the string is being read by the user process, it is copied
1719 * and a newline '\n' is added. It is truncated if the buffer is
1720 * not large enough.
1722 * Returns 0 on success.
1724 int proc_dostring(struct ctl_table *table, int write,
1725 void __user *buffer, size_t *lenp, loff_t *ppos)
1727 return _proc_do_string(table->data, table->maxlen, write,
1728 buffer, lenp, ppos);
1731 static size_t proc_skip_spaces(char **buf)
1733 size_t ret;
1734 char *tmp = skip_spaces(*buf);
1735 ret = tmp - *buf;
1736 *buf = tmp;
1737 return ret;
1740 static void proc_skip_char(char **buf, size_t *size, const char v)
1742 while (*size) {
1743 if (**buf != v)
1744 break;
1745 (*size)--;
1746 (*buf)++;
1750 #define TMPBUFLEN 22
1752 * proc_get_long - reads an ASCII formatted integer from a user buffer
1754 * @buf: a kernel buffer
1755 * @size: size of the kernel buffer
1756 * @val: this is where the number will be stored
1757 * @neg: set to %TRUE if number is negative
1758 * @perm_tr: a vector which contains the allowed trailers
1759 * @perm_tr_len: size of the perm_tr vector
1760 * @tr: pointer to store the trailer character
1762 * In case of success %0 is returned and @buf and @size are updated with
1763 * the amount of bytes read. If @tr is non-NULL and a trailing
1764 * character exists (size is non-zero after returning from this
1765 * function), @tr is updated with the trailing character.
1767 static int proc_get_long(char **buf, size_t *size,
1768 unsigned long *val, bool *neg,
1769 const char *perm_tr, unsigned perm_tr_len, char *tr)
1771 int len;
1772 char *p, tmp[TMPBUFLEN];
1774 if (!*size)
1775 return -EINVAL;
1777 len = *size;
1778 if (len > TMPBUFLEN - 1)
1779 len = TMPBUFLEN - 1;
1781 memcpy(tmp, *buf, len);
1783 tmp[len] = 0;
1784 p = tmp;
1785 if (*p == '-' && *size > 1) {
1786 *neg = true;
1787 p++;
1788 } else
1789 *neg = false;
1790 if (!isdigit(*p))
1791 return -EINVAL;
1793 *val = simple_strtoul(p, &p, 0);
1795 len = p - tmp;
1797 /* We don't know if the next char is whitespace thus we may accept
1798 * invalid integers (e.g. 1234...a) or two integers instead of one
1799 * (e.g. 123...1). So lets not allow such large numbers. */
1800 if (len == TMPBUFLEN - 1)
1801 return -EINVAL;
1803 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1804 return -EINVAL;
1806 if (tr && (len < *size))
1807 *tr = *p;
1809 *buf += len;
1810 *size -= len;
1812 return 0;
1816 * proc_put_long - converts an integer to a decimal ASCII formatted string
1818 * @buf: the user buffer
1819 * @size: the size of the user buffer
1820 * @val: the integer to be converted
1821 * @neg: sign of the number, %TRUE for negative
1823 * In case of success %0 is returned and @buf and @size are updated with
1824 * the amount of bytes written.
1826 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1827 bool neg)
1829 int len;
1830 char tmp[TMPBUFLEN], *p = tmp;
1832 sprintf(p, "%s%lu", neg ? "-" : "", val);
1833 len = strlen(tmp);
1834 if (len > *size)
1835 len = *size;
1836 if (copy_to_user(*buf, tmp, len))
1837 return -EFAULT;
1838 *size -= len;
1839 *buf += len;
1840 return 0;
1842 #undef TMPBUFLEN
1844 static int proc_put_char(void __user **buf, size_t *size, char c)
1846 if (*size) {
1847 char __user **buffer = (char __user **)buf;
1848 if (put_user(c, *buffer))
1849 return -EFAULT;
1850 (*size)--, (*buffer)++;
1851 *buf = *buffer;
1853 return 0;
1856 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1857 int *valp,
1858 int write, void *data)
1860 if (write) {
1861 *valp = *negp ? -*lvalp : *lvalp;
1862 } else {
1863 int val = *valp;
1864 if (val < 0) {
1865 *negp = true;
1866 *lvalp = (unsigned long)-val;
1867 } else {
1868 *negp = false;
1869 *lvalp = (unsigned long)val;
1872 return 0;
1875 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1877 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1878 int write, void __user *buffer,
1879 size_t *lenp, loff_t *ppos,
1880 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1881 int write, void *data),
1882 void *data)
1884 int *i, vleft, first = 1, err = 0;
1885 unsigned long page = 0;
1886 size_t left;
1887 char *kbuf;
1889 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1890 *lenp = 0;
1891 return 0;
1894 i = (int *) tbl_data;
1895 vleft = table->maxlen / sizeof(*i);
1896 left = *lenp;
1898 if (!conv)
1899 conv = do_proc_dointvec_conv;
1901 if (write) {
1902 if (left > PAGE_SIZE - 1)
1903 left = PAGE_SIZE - 1;
1904 page = __get_free_page(GFP_TEMPORARY);
1905 kbuf = (char *) page;
1906 if (!kbuf)
1907 return -ENOMEM;
1908 if (copy_from_user(kbuf, buffer, left)) {
1909 err = -EFAULT;
1910 goto free;
1912 kbuf[left] = 0;
1915 for (; left && vleft--; i++, first=0) {
1916 unsigned long lval;
1917 bool neg;
1919 if (write) {
1920 left -= proc_skip_spaces(&kbuf);
1922 if (!left)
1923 break;
1924 err = proc_get_long(&kbuf, &left, &lval, &neg,
1925 proc_wspace_sep,
1926 sizeof(proc_wspace_sep), NULL);
1927 if (err)
1928 break;
1929 if (conv(&neg, &lval, i, 1, data)) {
1930 err = -EINVAL;
1931 break;
1933 } else {
1934 if (conv(&neg, &lval, i, 0, data)) {
1935 err = -EINVAL;
1936 break;
1938 if (!first)
1939 err = proc_put_char(&buffer, &left, '\t');
1940 if (err)
1941 break;
1942 err = proc_put_long(&buffer, &left, lval, neg);
1943 if (err)
1944 break;
1948 if (!write && !first && left && !err)
1949 err = proc_put_char(&buffer, &left, '\n');
1950 if (write && !err && left)
1951 left -= proc_skip_spaces(&kbuf);
1952 free:
1953 if (write) {
1954 free_page(page);
1955 if (first)
1956 return err ? : -EINVAL;
1958 *lenp -= left;
1959 *ppos += *lenp;
1960 return err;
1963 static int do_proc_dointvec(struct ctl_table *table, int write,
1964 void __user *buffer, size_t *lenp, loff_t *ppos,
1965 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1966 int write, void *data),
1967 void *data)
1969 return __do_proc_dointvec(table->data, table, write,
1970 buffer, lenp, ppos, conv, data);
1974 * proc_dointvec - read a vector of integers
1975 * @table: the sysctl table
1976 * @write: %TRUE if this is a write to the sysctl file
1977 * @buffer: the user buffer
1978 * @lenp: the size of the user buffer
1979 * @ppos: file position
1981 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1982 * values from/to the user buffer, treated as an ASCII string.
1984 * Returns 0 on success.
1986 int proc_dointvec(struct ctl_table *table, int write,
1987 void __user *buffer, size_t *lenp, loff_t *ppos)
1989 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1990 NULL,NULL);
1994 * Taint values can only be increased
1995 * This means we can safely use a temporary.
1997 static int proc_taint(struct ctl_table *table, int write,
1998 void __user *buffer, size_t *lenp, loff_t *ppos)
2000 struct ctl_table t;
2001 unsigned long tmptaint = get_taint();
2002 int err;
2004 if (write && !capable(CAP_SYS_ADMIN))
2005 return -EPERM;
2007 t = *table;
2008 t.data = &tmptaint;
2009 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2010 if (err < 0)
2011 return err;
2013 if (write) {
2015 * Poor man's atomic or. Not worth adding a primitive
2016 * to everyone's atomic.h for this
2018 int i;
2019 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2020 if ((tmptaint >> i) & 1)
2021 add_taint(i, LOCKDEP_STILL_OK);
2025 return err;
2028 #ifdef CONFIG_PRINTK
2029 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2030 void __user *buffer, size_t *lenp, loff_t *ppos)
2032 if (write && !capable(CAP_SYS_ADMIN))
2033 return -EPERM;
2035 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2037 #endif
2039 struct do_proc_dointvec_minmax_conv_param {
2040 int *min;
2041 int *max;
2044 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2045 int *valp,
2046 int write, void *data)
2048 struct do_proc_dointvec_minmax_conv_param *param = data;
2049 if (write) {
2050 int val = *negp ? -*lvalp : *lvalp;
2051 if ((param->min && *param->min > val) ||
2052 (param->max && *param->max < val))
2053 return -EINVAL;
2054 *valp = val;
2055 } else {
2056 int val = *valp;
2057 if (val < 0) {
2058 *negp = true;
2059 *lvalp = (unsigned long)-val;
2060 } else {
2061 *negp = false;
2062 *lvalp = (unsigned long)val;
2065 return 0;
2069 * proc_dointvec_minmax - read a vector of integers with min/max values
2070 * @table: the sysctl table
2071 * @write: %TRUE if this is a write to the sysctl file
2072 * @buffer: the user buffer
2073 * @lenp: the size of the user buffer
2074 * @ppos: file position
2076 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2077 * values from/to the user buffer, treated as an ASCII string.
2079 * This routine will ensure the values are within the range specified by
2080 * table->extra1 (min) and table->extra2 (max).
2082 * Returns 0 on success.
2084 int proc_dointvec_minmax(struct ctl_table *table, int write,
2085 void __user *buffer, size_t *lenp, loff_t *ppos)
2087 struct do_proc_dointvec_minmax_conv_param param = {
2088 .min = (int *) table->extra1,
2089 .max = (int *) table->extra2,
2091 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2092 do_proc_dointvec_minmax_conv, &param);
2095 static void validate_coredump_safety(void)
2097 #ifdef CONFIG_COREDUMP
2098 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2099 core_pattern[0] != '/' && core_pattern[0] != '|') {
2100 printk(KERN_WARNING "Unsafe core_pattern used with "\
2101 "suid_dumpable=2. Pipe handler or fully qualified "\
2102 "core dump path required.\n");
2104 #endif
2107 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2108 void __user *buffer, size_t *lenp, loff_t *ppos)
2110 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2111 if (!error)
2112 validate_coredump_safety();
2113 return error;
2116 #ifdef CONFIG_COREDUMP
2117 static int proc_dostring_coredump(struct ctl_table *table, int write,
2118 void __user *buffer, size_t *lenp, loff_t *ppos)
2120 int error = proc_dostring(table, write, buffer, lenp, ppos);
2121 if (!error)
2122 validate_coredump_safety();
2123 return error;
2125 #endif
2127 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2128 void __user *buffer,
2129 size_t *lenp, loff_t *ppos,
2130 unsigned long convmul,
2131 unsigned long convdiv)
2133 unsigned long *i, *min, *max;
2134 int vleft, first = 1, err = 0;
2135 unsigned long page = 0;
2136 size_t left;
2137 char *kbuf;
2139 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2140 *lenp = 0;
2141 return 0;
2144 i = (unsigned long *) data;
2145 min = (unsigned long *) table->extra1;
2146 max = (unsigned long *) table->extra2;
2147 vleft = table->maxlen / sizeof(unsigned long);
2148 left = *lenp;
2150 if (write) {
2151 if (left > PAGE_SIZE - 1)
2152 left = PAGE_SIZE - 1;
2153 page = __get_free_page(GFP_TEMPORARY);
2154 kbuf = (char *) page;
2155 if (!kbuf)
2156 return -ENOMEM;
2157 if (copy_from_user(kbuf, buffer, left)) {
2158 err = -EFAULT;
2159 goto free;
2161 kbuf[left] = 0;
2164 for (; left && vleft--; i++, first = 0) {
2165 unsigned long val;
2167 if (write) {
2168 bool neg;
2170 left -= proc_skip_spaces(&kbuf);
2172 err = proc_get_long(&kbuf, &left, &val, &neg,
2173 proc_wspace_sep,
2174 sizeof(proc_wspace_sep), NULL);
2175 if (err)
2176 break;
2177 if (neg)
2178 continue;
2179 if ((min && val < *min) || (max && val > *max))
2180 continue;
2181 *i = val;
2182 } else {
2183 val = convdiv * (*i) / convmul;
2184 if (!first)
2185 err = proc_put_char(&buffer, &left, '\t');
2186 err = proc_put_long(&buffer, &left, val, false);
2187 if (err)
2188 break;
2192 if (!write && !first && left && !err)
2193 err = proc_put_char(&buffer, &left, '\n');
2194 if (write && !err)
2195 left -= proc_skip_spaces(&kbuf);
2196 free:
2197 if (write) {
2198 free_page(page);
2199 if (first)
2200 return err ? : -EINVAL;
2202 *lenp -= left;
2203 *ppos += *lenp;
2204 return err;
2207 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2208 void __user *buffer,
2209 size_t *lenp, loff_t *ppos,
2210 unsigned long convmul,
2211 unsigned long convdiv)
2213 return __do_proc_doulongvec_minmax(table->data, table, write,
2214 buffer, lenp, ppos, convmul, convdiv);
2218 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2219 * @table: the sysctl table
2220 * @write: %TRUE if this is a write to the sysctl file
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
2223 * @ppos: file position
2225 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2226 * values from/to the user buffer, treated as an ASCII string.
2228 * This routine will ensure the values are within the range specified by
2229 * table->extra1 (min) and table->extra2 (max).
2231 * Returns 0 on success.
2233 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2234 void __user *buffer, size_t *lenp, loff_t *ppos)
2236 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2240 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2241 * @table: the sysctl table
2242 * @write: %TRUE if this is a write to the sysctl file
2243 * @buffer: the user buffer
2244 * @lenp: the size of the user buffer
2245 * @ppos: file position
2247 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2248 * values from/to the user buffer, treated as an ASCII string. The values
2249 * are treated as milliseconds, and converted to jiffies when they are stored.
2251 * This routine will ensure the values are within the range specified by
2252 * table->extra1 (min) and table->extra2 (max).
2254 * Returns 0 on success.
2256 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2257 void __user *buffer,
2258 size_t *lenp, loff_t *ppos)
2260 return do_proc_doulongvec_minmax(table, write, buffer,
2261 lenp, ppos, HZ, 1000l);
2265 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2266 int *valp,
2267 int write, void *data)
2269 if (write) {
2270 if (*lvalp > LONG_MAX / HZ)
2271 return 1;
2272 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2273 } else {
2274 int val = *valp;
2275 unsigned long lval;
2276 if (val < 0) {
2277 *negp = true;
2278 lval = (unsigned long)-val;
2279 } else {
2280 *negp = false;
2281 lval = (unsigned long)val;
2283 *lvalp = lval / HZ;
2285 return 0;
2288 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2289 int *valp,
2290 int write, void *data)
2292 if (write) {
2293 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2294 return 1;
2295 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2296 } else {
2297 int val = *valp;
2298 unsigned long lval;
2299 if (val < 0) {
2300 *negp = true;
2301 lval = (unsigned long)-val;
2302 } else {
2303 *negp = false;
2304 lval = (unsigned long)val;
2306 *lvalp = jiffies_to_clock_t(lval);
2308 return 0;
2311 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2312 int *valp,
2313 int write, void *data)
2315 if (write) {
2316 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2317 } else {
2318 int val = *valp;
2319 unsigned long lval;
2320 if (val < 0) {
2321 *negp = true;
2322 lval = (unsigned long)-val;
2323 } else {
2324 *negp = false;
2325 lval = (unsigned long)val;
2327 *lvalp = jiffies_to_msecs(lval);
2329 return 0;
2333 * proc_dointvec_jiffies - read a vector of integers as seconds
2334 * @table: the sysctl table
2335 * @write: %TRUE if this is a write to the sysctl file
2336 * @buffer: the user buffer
2337 * @lenp: the size of the user buffer
2338 * @ppos: file position
2340 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2341 * values from/to the user buffer, treated as an ASCII string.
2342 * The values read are assumed to be in seconds, and are converted into
2343 * jiffies.
2345 * Returns 0 on success.
2347 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2348 void __user *buffer, size_t *lenp, loff_t *ppos)
2350 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2351 do_proc_dointvec_jiffies_conv,NULL);
2355 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2356 * @table: the sysctl table
2357 * @write: %TRUE if this is a write to the sysctl file
2358 * @buffer: the user buffer
2359 * @lenp: the size of the user buffer
2360 * @ppos: pointer to the file position
2362 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2363 * values from/to the user buffer, treated as an ASCII string.
2364 * The values read are assumed to be in 1/USER_HZ seconds, and
2365 * are converted into jiffies.
2367 * Returns 0 on success.
2369 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2370 void __user *buffer, size_t *lenp, loff_t *ppos)
2372 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2373 do_proc_dointvec_userhz_jiffies_conv,NULL);
2377 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2378 * @table: the sysctl table
2379 * @write: %TRUE if this is a write to the sysctl file
2380 * @buffer: the user buffer
2381 * @lenp: the size of the user buffer
2382 * @ppos: file position
2383 * @ppos: the current position in the file
2385 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2386 * values from/to the user buffer, treated as an ASCII string.
2387 * The values read are assumed to be in 1/1000 seconds, and
2388 * are converted into jiffies.
2390 * Returns 0 on success.
2392 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2395 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2396 do_proc_dointvec_ms_jiffies_conv, NULL);
2399 static int proc_do_cad_pid(struct ctl_table *table, int write,
2400 void __user *buffer, size_t *lenp, loff_t *ppos)
2402 struct pid *new_pid;
2403 pid_t tmp;
2404 int r;
2406 tmp = pid_vnr(cad_pid);
2408 r = __do_proc_dointvec(&tmp, table, write, buffer,
2409 lenp, ppos, NULL, NULL);
2410 if (r || !write)
2411 return r;
2413 new_pid = find_get_pid(tmp);
2414 if (!new_pid)
2415 return -ESRCH;
2417 put_pid(xchg(&cad_pid, new_pid));
2418 return 0;
2422 * proc_do_large_bitmap - read/write from/to a large bitmap
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2429 * The bitmap is stored at table->data and the bitmap length (in bits)
2430 * in table->maxlen.
2432 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2433 * large bitmaps may be represented in a compact manner. Writing into
2434 * the file will clear the bitmap then update it with the given input.
2436 * Returns 0 on success.
2438 int proc_do_large_bitmap(struct ctl_table *table, int write,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2441 int err = 0;
2442 bool first = 1;
2443 size_t left = *lenp;
2444 unsigned long bitmap_len = table->maxlen;
2445 unsigned long *bitmap = (unsigned long *) table->data;
2446 unsigned long *tmp_bitmap = NULL;
2447 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2449 if (!bitmap_len || !left || (*ppos && !write)) {
2450 *lenp = 0;
2451 return 0;
2454 if (write) {
2455 unsigned long page = 0;
2456 char *kbuf;
2458 if (left > PAGE_SIZE - 1)
2459 left = PAGE_SIZE - 1;
2461 page = __get_free_page(GFP_TEMPORARY);
2462 kbuf = (char *) page;
2463 if (!kbuf)
2464 return -ENOMEM;
2465 if (copy_from_user(kbuf, buffer, left)) {
2466 free_page(page);
2467 return -EFAULT;
2469 kbuf[left] = 0;
2471 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2472 GFP_KERNEL);
2473 if (!tmp_bitmap) {
2474 free_page(page);
2475 return -ENOMEM;
2477 proc_skip_char(&kbuf, &left, '\n');
2478 while (!err && left) {
2479 unsigned long val_a, val_b;
2480 bool neg;
2482 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2483 sizeof(tr_a), &c);
2484 if (err)
2485 break;
2486 if (val_a >= bitmap_len || neg) {
2487 err = -EINVAL;
2488 break;
2491 val_b = val_a;
2492 if (left) {
2493 kbuf++;
2494 left--;
2497 if (c == '-') {
2498 err = proc_get_long(&kbuf, &left, &val_b,
2499 &neg, tr_b, sizeof(tr_b),
2500 &c);
2501 if (err)
2502 break;
2503 if (val_b >= bitmap_len || neg ||
2504 val_a > val_b) {
2505 err = -EINVAL;
2506 break;
2508 if (left) {
2509 kbuf++;
2510 left--;
2514 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2515 first = 0;
2516 proc_skip_char(&kbuf, &left, '\n');
2518 free_page(page);
2519 } else {
2520 unsigned long bit_a, bit_b = 0;
2522 while (left) {
2523 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2524 if (bit_a >= bitmap_len)
2525 break;
2526 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2527 bit_a + 1) - 1;
2529 if (!first) {
2530 err = proc_put_char(&buffer, &left, ',');
2531 if (err)
2532 break;
2534 err = proc_put_long(&buffer, &left, bit_a, false);
2535 if (err)
2536 break;
2537 if (bit_a != bit_b) {
2538 err = proc_put_char(&buffer, &left, '-');
2539 if (err)
2540 break;
2541 err = proc_put_long(&buffer, &left, bit_b, false);
2542 if (err)
2543 break;
2546 first = 0; bit_b++;
2548 if (!err)
2549 err = proc_put_char(&buffer, &left, '\n');
2552 if (!err) {
2553 if (write) {
2554 if (*ppos)
2555 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2556 else
2557 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2559 kfree(tmp_bitmap);
2560 *lenp -= left;
2561 *ppos += *lenp;
2562 return 0;
2563 } else {
2564 kfree(tmp_bitmap);
2565 return err;
2569 #else /* CONFIG_PROC_SYSCTL */
2571 int proc_dostring(struct ctl_table *table, int write,
2572 void __user *buffer, size_t *lenp, loff_t *ppos)
2574 return -ENOSYS;
2577 int proc_dointvec(struct ctl_table *table, int write,
2578 void __user *buffer, size_t *lenp, loff_t *ppos)
2580 return -ENOSYS;
2583 int proc_dointvec_minmax(struct ctl_table *table, int write,
2584 void __user *buffer, size_t *lenp, loff_t *ppos)
2586 return -ENOSYS;
2589 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2590 void __user *buffer, size_t *lenp, loff_t *ppos)
2592 return -ENOSYS;
2595 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2596 void __user *buffer, size_t *lenp, loff_t *ppos)
2598 return -ENOSYS;
2601 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2602 void __user *buffer, size_t *lenp, loff_t *ppos)
2604 return -ENOSYS;
2607 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2608 void __user *buffer, size_t *lenp, loff_t *ppos)
2610 return -ENOSYS;
2613 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2614 void __user *buffer,
2615 size_t *lenp, loff_t *ppos)
2617 return -ENOSYS;
2621 #endif /* CONFIG_PROC_SYSCTL */
2624 * No sense putting this after each symbol definition, twice,
2625 * exception granted :-)
2627 EXPORT_SYMBOL(proc_dointvec);
2628 EXPORT_SYMBOL(proc_dointvec_jiffies);
2629 EXPORT_SYMBOL(proc_dointvec_minmax);
2630 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2631 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2632 EXPORT_SYMBOL(proc_dostring);
2633 EXPORT_SYMBOL(proc_doulongvec_minmax);
2634 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);