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