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