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