]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - kernel/sysctl.c
Merge branch 'for-jeff' of git://electric-eye.fr.zoreil.com/home/romieu/linux-2.6
[mirror_ubuntu-artful-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/config.h>
22 #include <linux/module.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/capability.h>
29 #include <linux/ctype.h>
30 #include <linux/utsname.h>
31 #include <linux/capability.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47
48 #include <asm/uaccess.h>
49 #include <asm/processor.h>
50
51 #ifdef CONFIG_ROOT_NFS
52 #include <linux/nfs_fs.h>
53 #endif
54
55 #if defined(CONFIG_SYSCTL)
56
57 /* External variables not in a header file. */
58 extern int C_A_D;
59 extern int sysctl_overcommit_memory;
60 extern int sysctl_overcommit_ratio;
61 extern int max_threads;
62 extern int sysrq_enabled;
63 extern int core_uses_pid;
64 extern int suid_dumpable;
65 extern char core_pattern[];
66 extern int cad_pid;
67 extern int pid_max;
68 extern int min_free_kbytes;
69 extern int printk_ratelimit_jiffies;
70 extern int printk_ratelimit_burst;
71 extern int pid_max_min, pid_max_max;
72 extern int sysctl_drop_caches;
73 extern int percpu_pagelist_fraction;
74
75 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
76 int unknown_nmi_panic;
77 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
78 void __user *, size_t *, loff_t *);
79 #endif
80
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid = 65535;
83 static int minolduid;
84 static int min_percpu_pagelist_fract = 8;
85
86 static int ngroups_max = NGROUPS_MAX;
87
88 #ifdef CONFIG_KMOD
89 extern char modprobe_path[];
90 #endif
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff;
93 #endif
94 #ifdef CONFIG_SYSVIPC
95 extern size_t shm_ctlmax;
96 extern size_t shm_ctlall;
97 extern int shm_ctlmni;
98 extern int msg_ctlmax;
99 extern int msg_ctlmnb;
100 extern int msg_ctlmni;
101 extern int sem_ctls[];
102 #endif
103
104 #ifdef __sparc__
105 extern char reboot_command [];
106 extern int stop_a_enabled;
107 extern int scons_pwroff;
108 #endif
109
110 #ifdef __hppa__
111 extern int pwrsw_enabled;
112 extern int unaligned_enabled;
113 #endif
114
115 #ifdef CONFIG_S390
116 #ifdef CONFIG_MATHEMU
117 extern int sysctl_ieee_emulation_warnings;
118 #endif
119 extern int sysctl_userprocess_debug;
120 extern int spin_retry;
121 #endif
122
123 extern int sysctl_hz_timer;
124
125 #ifdef CONFIG_BSD_PROCESS_ACCT
126 extern int acct_parm[];
127 #endif
128
129 int randomize_va_space = 1;
130
131 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
132 ctl_table *, void **);
133 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
134 void __user *buffer, size_t *lenp, loff_t *ppos);
135
136 static ctl_table root_table[];
137 static struct ctl_table_header root_table_header =
138 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
139
140 static ctl_table kern_table[];
141 static ctl_table vm_table[];
142 static ctl_table proc_table[];
143 static ctl_table fs_table[];
144 static ctl_table debug_table[];
145 static ctl_table dev_table[];
146 extern ctl_table random_table[];
147 #ifdef CONFIG_UNIX98_PTYS
148 extern ctl_table pty_table[];
149 #endif
150 #ifdef CONFIG_INOTIFY
151 extern ctl_table inotify_table[];
152 #endif
153
154 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
155 int sysctl_legacy_va_layout;
156 #endif
157
158 /* /proc declarations: */
159
160 #ifdef CONFIG_PROC_FS
161
162 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
163 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
164 static int proc_opensys(struct inode *, struct file *);
165
166 struct file_operations proc_sys_file_operations = {
167 .open = proc_opensys,
168 .read = proc_readsys,
169 .write = proc_writesys,
170 };
171
172 extern struct proc_dir_entry *proc_sys_root;
173
174 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
175 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
176 #endif
177
178 /* The default sysctl tables: */
179
180 static ctl_table root_table[] = {
181 {
182 .ctl_name = CTL_KERN,
183 .procname = "kernel",
184 .mode = 0555,
185 .child = kern_table,
186 },
187 {
188 .ctl_name = CTL_VM,
189 .procname = "vm",
190 .mode = 0555,
191 .child = vm_table,
192 },
193 #ifdef CONFIG_NET
194 {
195 .ctl_name = CTL_NET,
196 .procname = "net",
197 .mode = 0555,
198 .child = net_table,
199 },
200 #endif
201 {
202 .ctl_name = CTL_PROC,
203 .procname = "proc",
204 .mode = 0555,
205 .child = proc_table,
206 },
207 {
208 .ctl_name = CTL_FS,
209 .procname = "fs",
210 .mode = 0555,
211 .child = fs_table,
212 },
213 {
214 .ctl_name = CTL_DEBUG,
215 .procname = "debug",
216 .mode = 0555,
217 .child = debug_table,
218 },
219 {
220 .ctl_name = CTL_DEV,
221 .procname = "dev",
222 .mode = 0555,
223 .child = dev_table,
224 },
225
226 { .ctl_name = 0 }
227 };
228
229 static ctl_table kern_table[] = {
230 {
231 .ctl_name = KERN_OSTYPE,
232 .procname = "ostype",
233 .data = system_utsname.sysname,
234 .maxlen = sizeof(system_utsname.sysname),
235 .mode = 0444,
236 .proc_handler = &proc_doutsstring,
237 .strategy = &sysctl_string,
238 },
239 {
240 .ctl_name = KERN_OSRELEASE,
241 .procname = "osrelease",
242 .data = system_utsname.release,
243 .maxlen = sizeof(system_utsname.release),
244 .mode = 0444,
245 .proc_handler = &proc_doutsstring,
246 .strategy = &sysctl_string,
247 },
248 {
249 .ctl_name = KERN_VERSION,
250 .procname = "version",
251 .data = system_utsname.version,
252 .maxlen = sizeof(system_utsname.version),
253 .mode = 0444,
254 .proc_handler = &proc_doutsstring,
255 .strategy = &sysctl_string,
256 },
257 {
258 .ctl_name = KERN_NODENAME,
259 .procname = "hostname",
260 .data = system_utsname.nodename,
261 .maxlen = sizeof(system_utsname.nodename),
262 .mode = 0644,
263 .proc_handler = &proc_doutsstring,
264 .strategy = &sysctl_string,
265 },
266 {
267 .ctl_name = KERN_DOMAINNAME,
268 .procname = "domainname",
269 .data = system_utsname.domainname,
270 .maxlen = sizeof(system_utsname.domainname),
271 .mode = 0644,
272 .proc_handler = &proc_doutsstring,
273 .strategy = &sysctl_string,
274 },
275 {
276 .ctl_name = KERN_PANIC,
277 .procname = "panic",
278 .data = &panic_timeout,
279 .maxlen = sizeof(int),
280 .mode = 0644,
281 .proc_handler = &proc_dointvec,
282 },
283 {
284 .ctl_name = KERN_CORE_USES_PID,
285 .procname = "core_uses_pid",
286 .data = &core_uses_pid,
287 .maxlen = sizeof(int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec,
290 },
291 {
292 .ctl_name = KERN_CORE_PATTERN,
293 .procname = "core_pattern",
294 .data = core_pattern,
295 .maxlen = 64,
296 .mode = 0644,
297 .proc_handler = &proc_dostring,
298 .strategy = &sysctl_string,
299 },
300 {
301 .ctl_name = KERN_TAINTED,
302 .procname = "tainted",
303 .data = &tainted,
304 .maxlen = sizeof(int),
305 .mode = 0444,
306 .proc_handler = &proc_dointvec,
307 },
308 {
309 .ctl_name = KERN_CAP_BSET,
310 .procname = "cap-bound",
311 .data = &cap_bset,
312 .maxlen = sizeof(kernel_cap_t),
313 .mode = 0600,
314 .proc_handler = &proc_dointvec_bset,
315 },
316 #ifdef CONFIG_BLK_DEV_INITRD
317 {
318 .ctl_name = KERN_REALROOTDEV,
319 .procname = "real-root-dev",
320 .data = &real_root_dev,
321 .maxlen = sizeof(int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
325 #endif
326 #ifdef __sparc__
327 {
328 .ctl_name = KERN_SPARC_REBOOT,
329 .procname = "reboot-cmd",
330 .data = reboot_command,
331 .maxlen = 256,
332 .mode = 0644,
333 .proc_handler = &proc_dostring,
334 .strategy = &sysctl_string,
335 },
336 {
337 .ctl_name = KERN_SPARC_STOP_A,
338 .procname = "stop-a",
339 .data = &stop_a_enabled,
340 .maxlen = sizeof (int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
344 {
345 .ctl_name = KERN_SPARC_SCONS_PWROFF,
346 .procname = "scons-poweroff",
347 .data = &scons_pwroff,
348 .maxlen = sizeof (int),
349 .mode = 0644,
350 .proc_handler = &proc_dointvec,
351 },
352 #endif
353 #ifdef __hppa__
354 {
355 .ctl_name = KERN_HPPA_PWRSW,
356 .procname = "soft-power",
357 .data = &pwrsw_enabled,
358 .maxlen = sizeof (int),
359 .mode = 0644,
360 .proc_handler = &proc_dointvec,
361 },
362 {
363 .ctl_name = KERN_HPPA_UNALIGNED,
364 .procname = "unaligned-trap",
365 .data = &unaligned_enabled,
366 .maxlen = sizeof (int),
367 .mode = 0644,
368 .proc_handler = &proc_dointvec,
369 },
370 #endif
371 {
372 .ctl_name = KERN_CTLALTDEL,
373 .procname = "ctrl-alt-del",
374 .data = &C_A_D,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
378 },
379 {
380 .ctl_name = KERN_PRINTK,
381 .procname = "printk",
382 .data = &console_loglevel,
383 .maxlen = 4*sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387 #ifdef CONFIG_KMOD
388 {
389 .ctl_name = KERN_MODPROBE,
390 .procname = "modprobe",
391 .data = &modprobe_path,
392 .maxlen = KMOD_PATH_LEN,
393 .mode = 0644,
394 .proc_handler = &proc_dostring,
395 .strategy = &sysctl_string,
396 },
397 #endif
398 #ifdef CONFIG_HOTPLUG
399 {
400 .ctl_name = KERN_HOTPLUG,
401 .procname = "hotplug",
402 .data = &uevent_helper,
403 .maxlen = UEVENT_HELPER_PATH_LEN,
404 .mode = 0644,
405 .proc_handler = &proc_dostring,
406 .strategy = &sysctl_string,
407 },
408 #endif
409 #ifdef CONFIG_CHR_DEV_SG
410 {
411 .ctl_name = KERN_SG_BIG_BUFF,
412 .procname = "sg-big-buff",
413 .data = &sg_big_buff,
414 .maxlen = sizeof (int),
415 .mode = 0444,
416 .proc_handler = &proc_dointvec,
417 },
418 #endif
419 #ifdef CONFIG_BSD_PROCESS_ACCT
420 {
421 .ctl_name = KERN_ACCT,
422 .procname = "acct",
423 .data = &acct_parm,
424 .maxlen = 3*sizeof(int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
427 },
428 #endif
429 #ifdef CONFIG_SYSVIPC
430 {
431 .ctl_name = KERN_SHMMAX,
432 .procname = "shmmax",
433 .data = &shm_ctlmax,
434 .maxlen = sizeof (size_t),
435 .mode = 0644,
436 .proc_handler = &proc_doulongvec_minmax,
437 },
438 {
439 .ctl_name = KERN_SHMALL,
440 .procname = "shmall",
441 .data = &shm_ctlall,
442 .maxlen = sizeof (size_t),
443 .mode = 0644,
444 .proc_handler = &proc_doulongvec_minmax,
445 },
446 {
447 .ctl_name = KERN_SHMMNI,
448 .procname = "shmmni",
449 .data = &shm_ctlmni,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
453 },
454 {
455 .ctl_name = KERN_MSGMAX,
456 .procname = "msgmax",
457 .data = &msg_ctlmax,
458 .maxlen = sizeof (int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
461 },
462 {
463 .ctl_name = KERN_MSGMNI,
464 .procname = "msgmni",
465 .data = &msg_ctlmni,
466 .maxlen = sizeof (int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
470 {
471 .ctl_name = KERN_MSGMNB,
472 .procname = "msgmnb",
473 .data = &msg_ctlmnb,
474 .maxlen = sizeof (int),
475 .mode = 0644,
476 .proc_handler = &proc_dointvec,
477 },
478 {
479 .ctl_name = KERN_SEM,
480 .procname = "sem",
481 .data = &sem_ctls,
482 .maxlen = 4*sizeof (int),
483 .mode = 0644,
484 .proc_handler = &proc_dointvec,
485 },
486 #endif
487 #ifdef CONFIG_MAGIC_SYSRQ
488 {
489 .ctl_name = KERN_SYSRQ,
490 .procname = "sysrq",
491 .data = &sysrq_enabled,
492 .maxlen = sizeof (int),
493 .mode = 0644,
494 .proc_handler = &proc_dointvec,
495 },
496 #endif
497 {
498 .ctl_name = KERN_CADPID,
499 .procname = "cad_pid",
500 .data = &cad_pid,
501 .maxlen = sizeof (int),
502 .mode = 0600,
503 .proc_handler = &proc_dointvec,
504 },
505 {
506 .ctl_name = KERN_MAX_THREADS,
507 .procname = "threads-max",
508 .data = &max_threads,
509 .maxlen = sizeof(int),
510 .mode = 0644,
511 .proc_handler = &proc_dointvec,
512 },
513 {
514 .ctl_name = KERN_RANDOM,
515 .procname = "random",
516 .mode = 0555,
517 .child = random_table,
518 },
519 #ifdef CONFIG_UNIX98_PTYS
520 {
521 .ctl_name = KERN_PTY,
522 .procname = "pty",
523 .mode = 0555,
524 .child = pty_table,
525 },
526 #endif
527 {
528 .ctl_name = KERN_OVERFLOWUID,
529 .procname = "overflowuid",
530 .data = &overflowuid,
531 .maxlen = sizeof(int),
532 .mode = 0644,
533 .proc_handler = &proc_dointvec_minmax,
534 .strategy = &sysctl_intvec,
535 .extra1 = &minolduid,
536 .extra2 = &maxolduid,
537 },
538 {
539 .ctl_name = KERN_OVERFLOWGID,
540 .procname = "overflowgid",
541 .data = &overflowgid,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec_minmax,
545 .strategy = &sysctl_intvec,
546 .extra1 = &minolduid,
547 .extra2 = &maxolduid,
548 },
549 #ifdef CONFIG_S390
550 #ifdef CONFIG_MATHEMU
551 {
552 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
553 .procname = "ieee_emulation_warnings",
554 .data = &sysctl_ieee_emulation_warnings,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = &proc_dointvec,
558 },
559 #endif
560 #ifdef CONFIG_NO_IDLE_HZ
561 {
562 .ctl_name = KERN_HZ_TIMER,
563 .procname = "hz_timer",
564 .data = &sysctl_hz_timer,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569 #endif
570 {
571 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
572 .procname = "userprocess_debug",
573 .data = &sysctl_userprocess_debug,
574 .maxlen = sizeof(int),
575 .mode = 0644,
576 .proc_handler = &proc_dointvec,
577 },
578 #endif
579 {
580 .ctl_name = KERN_PIDMAX,
581 .procname = "pid_max",
582 .data = &pid_max,
583 .maxlen = sizeof (int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec_minmax,
586 .strategy = sysctl_intvec,
587 .extra1 = &pid_max_min,
588 .extra2 = &pid_max_max,
589 },
590 {
591 .ctl_name = KERN_PANIC_ON_OOPS,
592 .procname = "panic_on_oops",
593 .data = &panic_on_oops,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec,
597 },
598 {
599 .ctl_name = KERN_PRINTK_RATELIMIT,
600 .procname = "printk_ratelimit",
601 .data = &printk_ratelimit_jiffies,
602 .maxlen = sizeof(int),
603 .mode = 0644,
604 .proc_handler = &proc_dointvec_jiffies,
605 .strategy = &sysctl_jiffies,
606 },
607 {
608 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
609 .procname = "printk_ratelimit_burst",
610 .data = &printk_ratelimit_burst,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = &proc_dointvec,
614 },
615 {
616 .ctl_name = KERN_NGROUPS_MAX,
617 .procname = "ngroups_max",
618 .data = &ngroups_max,
619 .maxlen = sizeof (int),
620 .mode = 0444,
621 .proc_handler = &proc_dointvec,
622 },
623 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
624 {
625 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
626 .procname = "unknown_nmi_panic",
627 .data = &unknown_nmi_panic,
628 .maxlen = sizeof (int),
629 .mode = 0644,
630 .proc_handler = &proc_unknown_nmi_panic,
631 },
632 #endif
633 #if defined(CONFIG_X86)
634 {
635 .ctl_name = KERN_BOOTLOADER_TYPE,
636 .procname = "bootloader_type",
637 .data = &bootloader_type,
638 .maxlen = sizeof (int),
639 .mode = 0444,
640 .proc_handler = &proc_dointvec,
641 },
642 #endif
643 {
644 .ctl_name = KERN_RANDOMIZE,
645 .procname = "randomize_va_space",
646 .data = &randomize_va_space,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 .proc_handler = &proc_dointvec,
650 },
651 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
652 {
653 .ctl_name = KERN_SPIN_RETRY,
654 .procname = "spin_retry",
655 .data = &spin_retry,
656 .maxlen = sizeof (int),
657 .mode = 0644,
658 .proc_handler = &proc_dointvec,
659 },
660 #endif
661 { .ctl_name = 0 }
662 };
663
664 /* Constants for minimum and maximum testing in vm_table.
665 We use these as one-element integer vectors. */
666 static int zero;
667 static int one_hundred = 100;
668
669
670 static ctl_table vm_table[] = {
671 {
672 .ctl_name = VM_OVERCOMMIT_MEMORY,
673 .procname = "overcommit_memory",
674 .data = &sysctl_overcommit_memory,
675 .maxlen = sizeof(sysctl_overcommit_memory),
676 .mode = 0644,
677 .proc_handler = &proc_dointvec,
678 },
679 {
680 .ctl_name = VM_OVERCOMMIT_RATIO,
681 .procname = "overcommit_ratio",
682 .data = &sysctl_overcommit_ratio,
683 .maxlen = sizeof(sysctl_overcommit_ratio),
684 .mode = 0644,
685 .proc_handler = &proc_dointvec,
686 },
687 {
688 .ctl_name = VM_PAGE_CLUSTER,
689 .procname = "page-cluster",
690 .data = &page_cluster,
691 .maxlen = sizeof(int),
692 .mode = 0644,
693 .proc_handler = &proc_dointvec,
694 },
695 {
696 .ctl_name = VM_DIRTY_BACKGROUND,
697 .procname = "dirty_background_ratio",
698 .data = &dirty_background_ratio,
699 .maxlen = sizeof(dirty_background_ratio),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec_minmax,
702 .strategy = &sysctl_intvec,
703 .extra1 = &zero,
704 .extra2 = &one_hundred,
705 },
706 {
707 .ctl_name = VM_DIRTY_RATIO,
708 .procname = "dirty_ratio",
709 .data = &vm_dirty_ratio,
710 .maxlen = sizeof(vm_dirty_ratio),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec_minmax,
713 .strategy = &sysctl_intvec,
714 .extra1 = &zero,
715 .extra2 = &one_hundred,
716 },
717 {
718 .ctl_name = VM_DIRTY_WB_CS,
719 .procname = "dirty_writeback_centisecs",
720 .data = &dirty_writeback_centisecs,
721 .maxlen = sizeof(dirty_writeback_centisecs),
722 .mode = 0644,
723 .proc_handler = &dirty_writeback_centisecs_handler,
724 },
725 {
726 .ctl_name = VM_DIRTY_EXPIRE_CS,
727 .procname = "dirty_expire_centisecs",
728 .data = &dirty_expire_centisecs,
729 .maxlen = sizeof(dirty_expire_centisecs),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
732 },
733 {
734 .ctl_name = VM_NR_PDFLUSH_THREADS,
735 .procname = "nr_pdflush_threads",
736 .data = &nr_pdflush_threads,
737 .maxlen = sizeof nr_pdflush_threads,
738 .mode = 0444 /* read-only*/,
739 .proc_handler = &proc_dointvec,
740 },
741 {
742 .ctl_name = VM_SWAPPINESS,
743 .procname = "swappiness",
744 .data = &vm_swappiness,
745 .maxlen = sizeof(vm_swappiness),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec_minmax,
748 .strategy = &sysctl_intvec,
749 .extra1 = &zero,
750 .extra2 = &one_hundred,
751 },
752 #ifdef CONFIG_HUGETLB_PAGE
753 {
754 .ctl_name = VM_HUGETLB_PAGES,
755 .procname = "nr_hugepages",
756 .data = &max_huge_pages,
757 .maxlen = sizeof(unsigned long),
758 .mode = 0644,
759 .proc_handler = &hugetlb_sysctl_handler,
760 .extra1 = (void *)&hugetlb_zero,
761 .extra2 = (void *)&hugetlb_infinity,
762 },
763 {
764 .ctl_name = VM_HUGETLB_GROUP,
765 .procname = "hugetlb_shm_group",
766 .data = &sysctl_hugetlb_shm_group,
767 .maxlen = sizeof(gid_t),
768 .mode = 0644,
769 .proc_handler = &proc_dointvec,
770 },
771 #endif
772 {
773 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
774 .procname = "lowmem_reserve_ratio",
775 .data = &sysctl_lowmem_reserve_ratio,
776 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
777 .mode = 0644,
778 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
779 .strategy = &sysctl_intvec,
780 },
781 {
782 .ctl_name = VM_DROP_PAGECACHE,
783 .procname = "drop_caches",
784 .data = &sysctl_drop_caches,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = drop_caches_sysctl_handler,
788 .strategy = &sysctl_intvec,
789 },
790 {
791 .ctl_name = VM_MIN_FREE_KBYTES,
792 .procname = "min_free_kbytes",
793 .data = &min_free_kbytes,
794 .maxlen = sizeof(min_free_kbytes),
795 .mode = 0644,
796 .proc_handler = &min_free_kbytes_sysctl_handler,
797 .strategy = &sysctl_intvec,
798 .extra1 = &zero,
799 },
800 {
801 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
802 .procname = "percpu_pagelist_fraction",
803 .data = &percpu_pagelist_fraction,
804 .maxlen = sizeof(percpu_pagelist_fraction),
805 .mode = 0644,
806 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
807 .strategy = &sysctl_intvec,
808 .extra1 = &min_percpu_pagelist_fract,
809 },
810 #ifdef CONFIG_MMU
811 {
812 .ctl_name = VM_MAX_MAP_COUNT,
813 .procname = "max_map_count",
814 .data = &sysctl_max_map_count,
815 .maxlen = sizeof(sysctl_max_map_count),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec
818 },
819 #endif
820 {
821 .ctl_name = VM_LAPTOP_MODE,
822 .procname = "laptop_mode",
823 .data = &laptop_mode,
824 .maxlen = sizeof(laptop_mode),
825 .mode = 0644,
826 .proc_handler = &proc_dointvec,
827 .strategy = &sysctl_intvec,
828 .extra1 = &zero,
829 },
830 {
831 .ctl_name = VM_BLOCK_DUMP,
832 .procname = "block_dump",
833 .data = &block_dump,
834 .maxlen = sizeof(block_dump),
835 .mode = 0644,
836 .proc_handler = &proc_dointvec,
837 .strategy = &sysctl_intvec,
838 .extra1 = &zero,
839 },
840 {
841 .ctl_name = VM_VFS_CACHE_PRESSURE,
842 .procname = "vfs_cache_pressure",
843 .data = &sysctl_vfs_cache_pressure,
844 .maxlen = sizeof(sysctl_vfs_cache_pressure),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
847 .strategy = &sysctl_intvec,
848 .extra1 = &zero,
849 },
850 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
851 {
852 .ctl_name = VM_LEGACY_VA_LAYOUT,
853 .procname = "legacy_va_layout",
854 .data = &sysctl_legacy_va_layout,
855 .maxlen = sizeof(sysctl_legacy_va_layout),
856 .mode = 0644,
857 .proc_handler = &proc_dointvec,
858 .strategy = &sysctl_intvec,
859 .extra1 = &zero,
860 },
861 #endif
862 #ifdef CONFIG_SWAP
863 {
864 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
865 .procname = "swap_token_timeout",
866 .data = &swap_token_default_timeout,
867 .maxlen = sizeof(swap_token_default_timeout),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec_jiffies,
870 .strategy = &sysctl_jiffies,
871 },
872 #endif
873 #ifdef CONFIG_NUMA
874 {
875 .ctl_name = VM_ZONE_RECLAIM_MODE,
876 .procname = "zone_reclaim_mode",
877 .data = &zone_reclaim_mode,
878 .maxlen = sizeof(zone_reclaim_mode),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
881 .strategy = &sysctl_intvec,
882 .extra1 = &zero,
883 },
884 {
885 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
886 .procname = "zone_reclaim_interval",
887 .data = &zone_reclaim_interval,
888 .maxlen = sizeof(zone_reclaim_interval),
889 .mode = 0644,
890 .proc_handler = &proc_dointvec_jiffies,
891 .strategy = &sysctl_jiffies,
892 },
893 #endif
894 { .ctl_name = 0 }
895 };
896
897 static ctl_table proc_table[] = {
898 { .ctl_name = 0 }
899 };
900
901 static ctl_table fs_table[] = {
902 {
903 .ctl_name = FS_NRINODE,
904 .procname = "inode-nr",
905 .data = &inodes_stat,
906 .maxlen = 2*sizeof(int),
907 .mode = 0444,
908 .proc_handler = &proc_dointvec,
909 },
910 {
911 .ctl_name = FS_STATINODE,
912 .procname = "inode-state",
913 .data = &inodes_stat,
914 .maxlen = 7*sizeof(int),
915 .mode = 0444,
916 .proc_handler = &proc_dointvec,
917 },
918 {
919 .ctl_name = FS_NRFILE,
920 .procname = "file-nr",
921 .data = &files_stat,
922 .maxlen = 3*sizeof(int),
923 .mode = 0444,
924 .proc_handler = &proc_dointvec,
925 },
926 {
927 .ctl_name = FS_MAXFILE,
928 .procname = "file-max",
929 .data = &files_stat.max_files,
930 .maxlen = sizeof(int),
931 .mode = 0644,
932 .proc_handler = &proc_dointvec,
933 },
934 {
935 .ctl_name = FS_DENTRY,
936 .procname = "dentry-state",
937 .data = &dentry_stat,
938 .maxlen = 6*sizeof(int),
939 .mode = 0444,
940 .proc_handler = &proc_dointvec,
941 },
942 {
943 .ctl_name = FS_OVERFLOWUID,
944 .procname = "overflowuid",
945 .data = &fs_overflowuid,
946 .maxlen = sizeof(int),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec_minmax,
949 .strategy = &sysctl_intvec,
950 .extra1 = &minolduid,
951 .extra2 = &maxolduid,
952 },
953 {
954 .ctl_name = FS_OVERFLOWGID,
955 .procname = "overflowgid",
956 .data = &fs_overflowgid,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = &proc_dointvec_minmax,
960 .strategy = &sysctl_intvec,
961 .extra1 = &minolduid,
962 .extra2 = &maxolduid,
963 },
964 {
965 .ctl_name = FS_LEASES,
966 .procname = "leases-enable",
967 .data = &leases_enable,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = &proc_dointvec,
971 },
972 #ifdef CONFIG_DNOTIFY
973 {
974 .ctl_name = FS_DIR_NOTIFY,
975 .procname = "dir-notify-enable",
976 .data = &dir_notify_enable,
977 .maxlen = sizeof(int),
978 .mode = 0644,
979 .proc_handler = &proc_dointvec,
980 },
981 #endif
982 #ifdef CONFIG_MMU
983 {
984 .ctl_name = FS_LEASE_TIME,
985 .procname = "lease-break-time",
986 .data = &lease_break_time,
987 .maxlen = sizeof(int),
988 .mode = 0644,
989 .proc_handler = &proc_dointvec,
990 },
991 {
992 .ctl_name = FS_AIO_NR,
993 .procname = "aio-nr",
994 .data = &aio_nr,
995 .maxlen = sizeof(aio_nr),
996 .mode = 0444,
997 .proc_handler = &proc_doulongvec_minmax,
998 },
999 {
1000 .ctl_name = FS_AIO_MAX_NR,
1001 .procname = "aio-max-nr",
1002 .data = &aio_max_nr,
1003 .maxlen = sizeof(aio_max_nr),
1004 .mode = 0644,
1005 .proc_handler = &proc_doulongvec_minmax,
1006 },
1007 #ifdef CONFIG_INOTIFY
1008 {
1009 .ctl_name = FS_INOTIFY,
1010 .procname = "inotify",
1011 .mode = 0555,
1012 .child = inotify_table,
1013 },
1014 #endif
1015 #endif
1016 {
1017 .ctl_name = KERN_SETUID_DUMPABLE,
1018 .procname = "suid_dumpable",
1019 .data = &suid_dumpable,
1020 .maxlen = sizeof(int),
1021 .mode = 0644,
1022 .proc_handler = &proc_dointvec,
1023 },
1024 { .ctl_name = 0 }
1025 };
1026
1027 static ctl_table debug_table[] = {
1028 { .ctl_name = 0 }
1029 };
1030
1031 static ctl_table dev_table[] = {
1032 { .ctl_name = 0 }
1033 };
1034
1035 extern void init_irq_proc (void);
1036
1037 static DEFINE_SPINLOCK(sysctl_lock);
1038
1039 /* called under sysctl_lock */
1040 static int use_table(struct ctl_table_header *p)
1041 {
1042 if (unlikely(p->unregistering))
1043 return 0;
1044 p->used++;
1045 return 1;
1046 }
1047
1048 /* called under sysctl_lock */
1049 static void unuse_table(struct ctl_table_header *p)
1050 {
1051 if (!--p->used)
1052 if (unlikely(p->unregistering))
1053 complete(p->unregistering);
1054 }
1055
1056 /* called under sysctl_lock, will reacquire if has to wait */
1057 static void start_unregistering(struct ctl_table_header *p)
1058 {
1059 /*
1060 * if p->used is 0, nobody will ever touch that entry again;
1061 * we'll eliminate all paths to it before dropping sysctl_lock
1062 */
1063 if (unlikely(p->used)) {
1064 struct completion wait;
1065 init_completion(&wait);
1066 p->unregistering = &wait;
1067 spin_unlock(&sysctl_lock);
1068 wait_for_completion(&wait);
1069 spin_lock(&sysctl_lock);
1070 }
1071 /*
1072 * do not remove from the list until nobody holds it; walking the
1073 * list in do_sysctl() relies on that.
1074 */
1075 list_del_init(&p->ctl_entry);
1076 }
1077
1078 void __init sysctl_init(void)
1079 {
1080 #ifdef CONFIG_PROC_FS
1081 register_proc_table(root_table, proc_sys_root, &root_table_header);
1082 init_irq_proc();
1083 #endif
1084 }
1085
1086 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1087 void __user *newval, size_t newlen)
1088 {
1089 struct list_head *tmp;
1090 int error = -ENOTDIR;
1091
1092 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1093 return -ENOTDIR;
1094 if (oldval) {
1095 int old_len;
1096 if (!oldlenp || get_user(old_len, oldlenp))
1097 return -EFAULT;
1098 }
1099 spin_lock(&sysctl_lock);
1100 tmp = &root_table_header.ctl_entry;
1101 do {
1102 struct ctl_table_header *head =
1103 list_entry(tmp, struct ctl_table_header, ctl_entry);
1104 void *context = NULL;
1105
1106 if (!use_table(head))
1107 continue;
1108
1109 spin_unlock(&sysctl_lock);
1110
1111 error = parse_table(name, nlen, oldval, oldlenp,
1112 newval, newlen, head->ctl_table,
1113 &context);
1114 kfree(context);
1115
1116 spin_lock(&sysctl_lock);
1117 unuse_table(head);
1118 if (error != -ENOTDIR)
1119 break;
1120 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1121 spin_unlock(&sysctl_lock);
1122 return error;
1123 }
1124
1125 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1126 {
1127 struct __sysctl_args tmp;
1128 int error;
1129
1130 if (copy_from_user(&tmp, args, sizeof(tmp)))
1131 return -EFAULT;
1132
1133 lock_kernel();
1134 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1135 tmp.newval, tmp.newlen);
1136 unlock_kernel();
1137 return error;
1138 }
1139
1140 /*
1141 * ctl_perm does NOT grant the superuser all rights automatically, because
1142 * some sysctl variables are readonly even to root.
1143 */
1144
1145 static int test_perm(int mode, int op)
1146 {
1147 if (!current->euid)
1148 mode >>= 6;
1149 else if (in_egroup_p(0))
1150 mode >>= 3;
1151 if ((mode & op & 0007) == op)
1152 return 0;
1153 return -EACCES;
1154 }
1155
1156 static inline int ctl_perm(ctl_table *table, int op)
1157 {
1158 int error;
1159 error = security_sysctl(table, op);
1160 if (error)
1161 return error;
1162 return test_perm(table->mode, op);
1163 }
1164
1165 static int parse_table(int __user *name, int nlen,
1166 void __user *oldval, size_t __user *oldlenp,
1167 void __user *newval, size_t newlen,
1168 ctl_table *table, void **context)
1169 {
1170 int n;
1171 repeat:
1172 if (!nlen)
1173 return -ENOTDIR;
1174 if (get_user(n, name))
1175 return -EFAULT;
1176 for ( ; table->ctl_name; table++) {
1177 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1178 int error;
1179 if (table->child) {
1180 if (ctl_perm(table, 001))
1181 return -EPERM;
1182 if (table->strategy) {
1183 error = table->strategy(
1184 table, name, nlen,
1185 oldval, oldlenp,
1186 newval, newlen, context);
1187 if (error)
1188 return error;
1189 }
1190 name++;
1191 nlen--;
1192 table = table->child;
1193 goto repeat;
1194 }
1195 error = do_sysctl_strategy(table, name, nlen,
1196 oldval, oldlenp,
1197 newval, newlen, context);
1198 return error;
1199 }
1200 }
1201 return -ENOTDIR;
1202 }
1203
1204 /* Perform the actual read/write of a sysctl table entry. */
1205 int do_sysctl_strategy (ctl_table *table,
1206 int __user *name, int nlen,
1207 void __user *oldval, size_t __user *oldlenp,
1208 void __user *newval, size_t newlen, void **context)
1209 {
1210 int op = 0, rc;
1211 size_t len;
1212
1213 if (oldval)
1214 op |= 004;
1215 if (newval)
1216 op |= 002;
1217 if (ctl_perm(table, op))
1218 return -EPERM;
1219
1220 if (table->strategy) {
1221 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1222 newval, newlen, context);
1223 if (rc < 0)
1224 return rc;
1225 if (rc > 0)
1226 return 0;
1227 }
1228
1229 /* If there is no strategy routine, or if the strategy returns
1230 * zero, proceed with automatic r/w */
1231 if (table->data && table->maxlen) {
1232 if (oldval && oldlenp) {
1233 if (get_user(len, oldlenp))
1234 return -EFAULT;
1235 if (len) {
1236 if (len > table->maxlen)
1237 len = table->maxlen;
1238 if(copy_to_user(oldval, table->data, len))
1239 return -EFAULT;
1240 if(put_user(len, oldlenp))
1241 return -EFAULT;
1242 }
1243 }
1244 if (newval && newlen) {
1245 len = newlen;
1246 if (len > table->maxlen)
1247 len = table->maxlen;
1248 if(copy_from_user(table->data, newval, len))
1249 return -EFAULT;
1250 }
1251 }
1252 return 0;
1253 }
1254
1255 /**
1256 * register_sysctl_table - register a sysctl hierarchy
1257 * @table: the top-level table structure
1258 * @insert_at_head: whether the entry should be inserted in front or at the end
1259 *
1260 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1261 * array. An entry with a ctl_name of 0 terminates the table.
1262 *
1263 * The members of the &ctl_table structure are used as follows:
1264 *
1265 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1266 * must be unique within that level of sysctl
1267 *
1268 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1269 * enter a sysctl file
1270 *
1271 * data - a pointer to data for use by proc_handler
1272 *
1273 * maxlen - the maximum size in bytes of the data
1274 *
1275 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1276 *
1277 * child - a pointer to the child sysctl table if this entry is a directory, or
1278 * %NULL.
1279 *
1280 * proc_handler - the text handler routine (described below)
1281 *
1282 * strategy - the strategy routine (described below)
1283 *
1284 * de - for internal use by the sysctl routines
1285 *
1286 * extra1, extra2 - extra pointers usable by the proc handler routines
1287 *
1288 * Leaf nodes in the sysctl tree will be represented by a single file
1289 * under /proc; non-leaf nodes will be represented by directories.
1290 *
1291 * sysctl(2) can automatically manage read and write requests through
1292 * the sysctl table. The data and maxlen fields of the ctl_table
1293 * struct enable minimal validation of the values being written to be
1294 * performed, and the mode field allows minimal authentication.
1295 *
1296 * More sophisticated management can be enabled by the provision of a
1297 * strategy routine with the table entry. This will be called before
1298 * any automatic read or write of the data is performed.
1299 *
1300 * The strategy routine may return
1301 *
1302 * < 0 - Error occurred (error is passed to user process)
1303 *
1304 * 0 - OK - proceed with automatic read or write.
1305 *
1306 * > 0 - OK - read or write has been done by the strategy routine, so
1307 * return immediately.
1308 *
1309 * There must be a proc_handler routine for any terminal nodes
1310 * mirrored under /proc/sys (non-terminals are handled by a built-in
1311 * directory handler). Several default handlers are available to
1312 * cover common cases -
1313 *
1314 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1315 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1316 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1317 *
1318 * It is the handler's job to read the input buffer from user memory
1319 * and process it. The handler should return 0 on success.
1320 *
1321 * This routine returns %NULL on a failure to register, and a pointer
1322 * to the table header on success.
1323 */
1324 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1325 int insert_at_head)
1326 {
1327 struct ctl_table_header *tmp;
1328 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1329 if (!tmp)
1330 return NULL;
1331 tmp->ctl_table = table;
1332 INIT_LIST_HEAD(&tmp->ctl_entry);
1333 tmp->used = 0;
1334 tmp->unregistering = NULL;
1335 spin_lock(&sysctl_lock);
1336 if (insert_at_head)
1337 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1338 else
1339 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1340 spin_unlock(&sysctl_lock);
1341 #ifdef CONFIG_PROC_FS
1342 register_proc_table(table, proc_sys_root, tmp);
1343 #endif
1344 return tmp;
1345 }
1346
1347 /**
1348 * unregister_sysctl_table - unregister a sysctl table hierarchy
1349 * @header: the header returned from register_sysctl_table
1350 *
1351 * Unregisters the sysctl table and all children. proc entries may not
1352 * actually be removed until they are no longer used by anyone.
1353 */
1354 void unregister_sysctl_table(struct ctl_table_header * header)
1355 {
1356 might_sleep();
1357 spin_lock(&sysctl_lock);
1358 start_unregistering(header);
1359 #ifdef CONFIG_PROC_FS
1360 unregister_proc_table(header->ctl_table, proc_sys_root);
1361 #endif
1362 spin_unlock(&sysctl_lock);
1363 kfree(header);
1364 }
1365
1366 /*
1367 * /proc/sys support
1368 */
1369
1370 #ifdef CONFIG_PROC_FS
1371
1372 /* Scan the sysctl entries in table and add them all into /proc */
1373 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1374 {
1375 struct proc_dir_entry *de;
1376 int len;
1377 mode_t mode;
1378
1379 for (; table->ctl_name; table++) {
1380 /* Can't do anything without a proc name. */
1381 if (!table->procname)
1382 continue;
1383 /* Maybe we can't do anything with it... */
1384 if (!table->proc_handler && !table->child) {
1385 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1386 table->procname);
1387 continue;
1388 }
1389
1390 len = strlen(table->procname);
1391 mode = table->mode;
1392
1393 de = NULL;
1394 if (table->proc_handler)
1395 mode |= S_IFREG;
1396 else {
1397 mode |= S_IFDIR;
1398 for (de = root->subdir; de; de = de->next) {
1399 if (proc_match(len, table->procname, de))
1400 break;
1401 }
1402 /* If the subdir exists already, de is non-NULL */
1403 }
1404
1405 if (!de) {
1406 de = create_proc_entry(table->procname, mode, root);
1407 if (!de)
1408 continue;
1409 de->set = set;
1410 de->data = (void *) table;
1411 if (table->proc_handler)
1412 de->proc_fops = &proc_sys_file_operations;
1413 }
1414 table->de = de;
1415 if (de->mode & S_IFDIR)
1416 register_proc_table(table->child, de, set);
1417 }
1418 }
1419
1420 /*
1421 * Unregister a /proc sysctl table and any subdirectories.
1422 */
1423 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1424 {
1425 struct proc_dir_entry *de;
1426 for (; table->ctl_name; table++) {
1427 if (!(de = table->de))
1428 continue;
1429 if (de->mode & S_IFDIR) {
1430 if (!table->child) {
1431 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1432 continue;
1433 }
1434 unregister_proc_table(table->child, de);
1435
1436 /* Don't unregister directories which still have entries.. */
1437 if (de->subdir)
1438 continue;
1439 }
1440
1441 /*
1442 * In any case, mark the entry as goner; we'll keep it
1443 * around if it's busy, but we'll know to do nothing with
1444 * its fields. We are under sysctl_lock here.
1445 */
1446 de->data = NULL;
1447
1448 /* Don't unregister proc entries that are still being used.. */
1449 if (atomic_read(&de->count))
1450 continue;
1451
1452 table->de = NULL;
1453 remove_proc_entry(table->procname, root);
1454 }
1455 }
1456
1457 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1458 size_t count, loff_t *ppos)
1459 {
1460 int op;
1461 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1462 struct ctl_table *table;
1463 size_t res;
1464 ssize_t error = -ENOTDIR;
1465
1466 spin_lock(&sysctl_lock);
1467 if (de && de->data && use_table(de->set)) {
1468 /*
1469 * at that point we know that sysctl was not unregistered
1470 * and won't be until we finish
1471 */
1472 spin_unlock(&sysctl_lock);
1473 table = (struct ctl_table *) de->data;
1474 if (!table || !table->proc_handler)
1475 goto out;
1476 error = -EPERM;
1477 op = (write ? 002 : 004);
1478 if (ctl_perm(table, op))
1479 goto out;
1480
1481 /* careful: calling conventions are nasty here */
1482 res = count;
1483 error = (*table->proc_handler)(table, write, file,
1484 buf, &res, ppos);
1485 if (!error)
1486 error = res;
1487 out:
1488 spin_lock(&sysctl_lock);
1489 unuse_table(de->set);
1490 }
1491 spin_unlock(&sysctl_lock);
1492 return error;
1493 }
1494
1495 static int proc_opensys(struct inode *inode, struct file *file)
1496 {
1497 if (file->f_mode & FMODE_WRITE) {
1498 /*
1499 * sysctl entries that are not writable,
1500 * are _NOT_ writable, capabilities or not.
1501 */
1502 if (!(inode->i_mode & S_IWUSR))
1503 return -EPERM;
1504 }
1505
1506 return 0;
1507 }
1508
1509 static ssize_t proc_readsys(struct file * file, char __user * buf,
1510 size_t count, loff_t *ppos)
1511 {
1512 return do_rw_proc(0, file, buf, count, ppos);
1513 }
1514
1515 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1516 size_t count, loff_t *ppos)
1517 {
1518 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1519 }
1520
1521 /**
1522 * proc_dostring - read a string sysctl
1523 * @table: the sysctl table
1524 * @write: %TRUE if this is a write to the sysctl file
1525 * @filp: the file structure
1526 * @buffer: the user buffer
1527 * @lenp: the size of the user buffer
1528 * @ppos: file position
1529 *
1530 * Reads/writes a string from/to the user buffer. If the kernel
1531 * buffer provided is not large enough to hold the string, the
1532 * string is truncated. The copied string is %NULL-terminated.
1533 * If the string is being read by the user process, it is copied
1534 * and a newline '\n' is added. It is truncated if the buffer is
1535 * not large enough.
1536 *
1537 * Returns 0 on success.
1538 */
1539 int proc_dostring(ctl_table *table, int write, struct file *filp,
1540 void __user *buffer, size_t *lenp, loff_t *ppos)
1541 {
1542 size_t len;
1543 char __user *p;
1544 char c;
1545
1546 if (!table->data || !table->maxlen || !*lenp ||
1547 (*ppos && !write)) {
1548 *lenp = 0;
1549 return 0;
1550 }
1551
1552 if (write) {
1553 len = 0;
1554 p = buffer;
1555 while (len < *lenp) {
1556 if (get_user(c, p++))
1557 return -EFAULT;
1558 if (c == 0 || c == '\n')
1559 break;
1560 len++;
1561 }
1562 if (len >= table->maxlen)
1563 len = table->maxlen-1;
1564 if(copy_from_user(table->data, buffer, len))
1565 return -EFAULT;
1566 ((char *) table->data)[len] = 0;
1567 *ppos += *lenp;
1568 } else {
1569 len = strlen(table->data);
1570 if (len > table->maxlen)
1571 len = table->maxlen;
1572 if (len > *lenp)
1573 len = *lenp;
1574 if (len)
1575 if(copy_to_user(buffer, table->data, len))
1576 return -EFAULT;
1577 if (len < *lenp) {
1578 if(put_user('\n', ((char __user *) buffer) + len))
1579 return -EFAULT;
1580 len++;
1581 }
1582 *lenp = len;
1583 *ppos += len;
1584 }
1585 return 0;
1586 }
1587
1588 /*
1589 * Special case of dostring for the UTS structure. This has locks
1590 * to observe. Should this be in kernel/sys.c ????
1591 */
1592
1593 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1594 void __user *buffer, size_t *lenp, loff_t *ppos)
1595 {
1596 int r;
1597
1598 if (!write) {
1599 down_read(&uts_sem);
1600 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1601 up_read(&uts_sem);
1602 } else {
1603 down_write(&uts_sem);
1604 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1605 up_write(&uts_sem);
1606 }
1607 return r;
1608 }
1609
1610 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1611 int *valp,
1612 int write, void *data)
1613 {
1614 if (write) {
1615 *valp = *negp ? -*lvalp : *lvalp;
1616 } else {
1617 int val = *valp;
1618 if (val < 0) {
1619 *negp = -1;
1620 *lvalp = (unsigned long)-val;
1621 } else {
1622 *negp = 0;
1623 *lvalp = (unsigned long)val;
1624 }
1625 }
1626 return 0;
1627 }
1628
1629 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1630 void __user *buffer, size_t *lenp, loff_t *ppos,
1631 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1632 int write, void *data),
1633 void *data)
1634 {
1635 #define TMPBUFLEN 21
1636 int *i, vleft, first=1, neg, val;
1637 unsigned long lval;
1638 size_t left, len;
1639
1640 char buf[TMPBUFLEN], *p;
1641 char __user *s = buffer;
1642
1643 if (!table->data || !table->maxlen || !*lenp ||
1644 (*ppos && !write)) {
1645 *lenp = 0;
1646 return 0;
1647 }
1648
1649 i = (int *) table->data;
1650 vleft = table->maxlen / sizeof(*i);
1651 left = *lenp;
1652
1653 if (!conv)
1654 conv = do_proc_dointvec_conv;
1655
1656 for (; left && vleft--; i++, first=0) {
1657 if (write) {
1658 while (left) {
1659 char c;
1660 if (get_user(c, s))
1661 return -EFAULT;
1662 if (!isspace(c))
1663 break;
1664 left--;
1665 s++;
1666 }
1667 if (!left)
1668 break;
1669 neg = 0;
1670 len = left;
1671 if (len > sizeof(buf) - 1)
1672 len = sizeof(buf) - 1;
1673 if (copy_from_user(buf, s, len))
1674 return -EFAULT;
1675 buf[len] = 0;
1676 p = buf;
1677 if (*p == '-' && left > 1) {
1678 neg = 1;
1679 left--, p++;
1680 }
1681 if (*p < '0' || *p > '9')
1682 break;
1683
1684 lval = simple_strtoul(p, &p, 0);
1685
1686 len = p-buf;
1687 if ((len < left) && *p && !isspace(*p))
1688 break;
1689 if (neg)
1690 val = -val;
1691 s += len;
1692 left -= len;
1693
1694 if (conv(&neg, &lval, i, 1, data))
1695 break;
1696 } else {
1697 p = buf;
1698 if (!first)
1699 *p++ = '\t';
1700
1701 if (conv(&neg, &lval, i, 0, data))
1702 break;
1703
1704 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1705 len = strlen(buf);
1706 if (len > left)
1707 len = left;
1708 if(copy_to_user(s, buf, len))
1709 return -EFAULT;
1710 left -= len;
1711 s += len;
1712 }
1713 }
1714
1715 if (!write && !first && left) {
1716 if(put_user('\n', s))
1717 return -EFAULT;
1718 left--, s++;
1719 }
1720 if (write) {
1721 while (left) {
1722 char c;
1723 if (get_user(c, s++))
1724 return -EFAULT;
1725 if (!isspace(c))
1726 break;
1727 left--;
1728 }
1729 }
1730 if (write && first)
1731 return -EINVAL;
1732 *lenp -= left;
1733 *ppos += *lenp;
1734 return 0;
1735 #undef TMPBUFLEN
1736 }
1737
1738 /**
1739 * proc_dointvec - read a vector of integers
1740 * @table: the sysctl table
1741 * @write: %TRUE if this is a write to the sysctl file
1742 * @filp: the file structure
1743 * @buffer: the user buffer
1744 * @lenp: the size of the user buffer
1745 * @ppos: file position
1746 *
1747 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1748 * values from/to the user buffer, treated as an ASCII string.
1749 *
1750 * Returns 0 on success.
1751 */
1752 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1753 void __user *buffer, size_t *lenp, loff_t *ppos)
1754 {
1755 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1756 NULL,NULL);
1757 }
1758
1759 #define OP_SET 0
1760 #define OP_AND 1
1761 #define OP_OR 2
1762 #define OP_MAX 3
1763 #define OP_MIN 4
1764
1765 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1766 int *valp,
1767 int write, void *data)
1768 {
1769 int op = *(int *)data;
1770 if (write) {
1771 int val = *negp ? -*lvalp : *lvalp;
1772 switch(op) {
1773 case OP_SET: *valp = val; break;
1774 case OP_AND: *valp &= val; break;
1775 case OP_OR: *valp |= val; break;
1776 case OP_MAX: if(*valp < val)
1777 *valp = val;
1778 break;
1779 case OP_MIN: if(*valp > val)
1780 *valp = val;
1781 break;
1782 }
1783 } else {
1784 int val = *valp;
1785 if (val < 0) {
1786 *negp = -1;
1787 *lvalp = (unsigned long)-val;
1788 } else {
1789 *negp = 0;
1790 *lvalp = (unsigned long)val;
1791 }
1792 }
1793 return 0;
1794 }
1795
1796 /*
1797 * init may raise the set.
1798 */
1799
1800 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1801 void __user *buffer, size_t *lenp, loff_t *ppos)
1802 {
1803 int op;
1804
1805 if (!capable(CAP_SYS_MODULE)) {
1806 return -EPERM;
1807 }
1808
1809 op = (current->pid == 1) ? OP_SET : OP_AND;
1810 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1811 do_proc_dointvec_bset_conv,&op);
1812 }
1813
1814 struct do_proc_dointvec_minmax_conv_param {
1815 int *min;
1816 int *max;
1817 };
1818
1819 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1820 int *valp,
1821 int write, void *data)
1822 {
1823 struct do_proc_dointvec_minmax_conv_param *param = data;
1824 if (write) {
1825 int val = *negp ? -*lvalp : *lvalp;
1826 if ((param->min && *param->min > val) ||
1827 (param->max && *param->max < val))
1828 return -EINVAL;
1829 *valp = val;
1830 } else {
1831 int val = *valp;
1832 if (val < 0) {
1833 *negp = -1;
1834 *lvalp = (unsigned long)-val;
1835 } else {
1836 *negp = 0;
1837 *lvalp = (unsigned long)val;
1838 }
1839 }
1840 return 0;
1841 }
1842
1843 /**
1844 * proc_dointvec_minmax - read a vector of integers with min/max values
1845 * @table: the sysctl table
1846 * @write: %TRUE if this is a write to the sysctl file
1847 * @filp: the file structure
1848 * @buffer: the user buffer
1849 * @lenp: the size of the user buffer
1850 * @ppos: file position
1851 *
1852 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1853 * values from/to the user buffer, treated as an ASCII string.
1854 *
1855 * This routine will ensure the values are within the range specified by
1856 * table->extra1 (min) and table->extra2 (max).
1857 *
1858 * Returns 0 on success.
1859 */
1860 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1861 void __user *buffer, size_t *lenp, loff_t *ppos)
1862 {
1863 struct do_proc_dointvec_minmax_conv_param param = {
1864 .min = (int *) table->extra1,
1865 .max = (int *) table->extra2,
1866 };
1867 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1868 do_proc_dointvec_minmax_conv, &param);
1869 }
1870
1871 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1872 struct file *filp,
1873 void __user *buffer,
1874 size_t *lenp, loff_t *ppos,
1875 unsigned long convmul,
1876 unsigned long convdiv)
1877 {
1878 #define TMPBUFLEN 21
1879 unsigned long *i, *min, *max, val;
1880 int vleft, first=1, neg;
1881 size_t len, left;
1882 char buf[TMPBUFLEN], *p;
1883 char __user *s = buffer;
1884
1885 if (!table->data || !table->maxlen || !*lenp ||
1886 (*ppos && !write)) {
1887 *lenp = 0;
1888 return 0;
1889 }
1890
1891 i = (unsigned long *) table->data;
1892 min = (unsigned long *) table->extra1;
1893 max = (unsigned long *) table->extra2;
1894 vleft = table->maxlen / sizeof(unsigned long);
1895 left = *lenp;
1896
1897 for (; left && vleft--; i++, min++, max++, first=0) {
1898 if (write) {
1899 while (left) {
1900 char c;
1901 if (get_user(c, s))
1902 return -EFAULT;
1903 if (!isspace(c))
1904 break;
1905 left--;
1906 s++;
1907 }
1908 if (!left)
1909 break;
1910 neg = 0;
1911 len = left;
1912 if (len > TMPBUFLEN-1)
1913 len = TMPBUFLEN-1;
1914 if (copy_from_user(buf, s, len))
1915 return -EFAULT;
1916 buf[len] = 0;
1917 p = buf;
1918 if (*p == '-' && left > 1) {
1919 neg = 1;
1920 left--, p++;
1921 }
1922 if (*p < '0' || *p > '9')
1923 break;
1924 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1925 len = p-buf;
1926 if ((len < left) && *p && !isspace(*p))
1927 break;
1928 if (neg)
1929 val = -val;
1930 s += len;
1931 left -= len;
1932
1933 if(neg)
1934 continue;
1935 if ((min && val < *min) || (max && val > *max))
1936 continue;
1937 *i = val;
1938 } else {
1939 p = buf;
1940 if (!first)
1941 *p++ = '\t';
1942 sprintf(p, "%lu", convdiv * (*i) / convmul);
1943 len = strlen(buf);
1944 if (len > left)
1945 len = left;
1946 if(copy_to_user(s, buf, len))
1947 return -EFAULT;
1948 left -= len;
1949 s += len;
1950 }
1951 }
1952
1953 if (!write && !first && left) {
1954 if(put_user('\n', s))
1955 return -EFAULT;
1956 left--, s++;
1957 }
1958 if (write) {
1959 while (left) {
1960 char c;
1961 if (get_user(c, s++))
1962 return -EFAULT;
1963 if (!isspace(c))
1964 break;
1965 left--;
1966 }
1967 }
1968 if (write && first)
1969 return -EINVAL;
1970 *lenp -= left;
1971 *ppos += *lenp;
1972 return 0;
1973 #undef TMPBUFLEN
1974 }
1975
1976 /**
1977 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1978 * @table: the sysctl table
1979 * @write: %TRUE if this is a write to the sysctl file
1980 * @filp: the file structure
1981 * @buffer: the user buffer
1982 * @lenp: the size of the user buffer
1983 * @ppos: file position
1984 *
1985 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1986 * values from/to the user buffer, treated as an ASCII string.
1987 *
1988 * This routine will ensure the values are within the range specified by
1989 * table->extra1 (min) and table->extra2 (max).
1990 *
1991 * Returns 0 on success.
1992 */
1993 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1994 void __user *buffer, size_t *lenp, loff_t *ppos)
1995 {
1996 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1997 }
1998
1999 /**
2000 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2001 * @table: the sysctl table
2002 * @write: %TRUE if this is a write to the sysctl file
2003 * @filp: the file structure
2004 * @buffer: the user buffer
2005 * @lenp: the size of the user buffer
2006 * @ppos: file position
2007 *
2008 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2009 * values from/to the user buffer, treated as an ASCII string. The values
2010 * are treated as milliseconds, and converted to jiffies when they are stored.
2011 *
2012 * This routine will ensure the values are within the range specified by
2013 * table->extra1 (min) and table->extra2 (max).
2014 *
2015 * Returns 0 on success.
2016 */
2017 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2018 struct file *filp,
2019 void __user *buffer,
2020 size_t *lenp, loff_t *ppos)
2021 {
2022 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2023 lenp, ppos, HZ, 1000l);
2024 }
2025
2026
2027 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2028 int *valp,
2029 int write, void *data)
2030 {
2031 if (write) {
2032 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2033 } else {
2034 int val = *valp;
2035 unsigned long lval;
2036 if (val < 0) {
2037 *negp = -1;
2038 lval = (unsigned long)-val;
2039 } else {
2040 *negp = 0;
2041 lval = (unsigned long)val;
2042 }
2043 *lvalp = lval / HZ;
2044 }
2045 return 0;
2046 }
2047
2048 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2049 int *valp,
2050 int write, void *data)
2051 {
2052 if (write) {
2053 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2054 } else {
2055 int val = *valp;
2056 unsigned long lval;
2057 if (val < 0) {
2058 *negp = -1;
2059 lval = (unsigned long)-val;
2060 } else {
2061 *negp = 0;
2062 lval = (unsigned long)val;
2063 }
2064 *lvalp = jiffies_to_clock_t(lval);
2065 }
2066 return 0;
2067 }
2068
2069 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2070 int *valp,
2071 int write, void *data)
2072 {
2073 if (write) {
2074 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2075 } else {
2076 int val = *valp;
2077 unsigned long lval;
2078 if (val < 0) {
2079 *negp = -1;
2080 lval = (unsigned long)-val;
2081 } else {
2082 *negp = 0;
2083 lval = (unsigned long)val;
2084 }
2085 *lvalp = jiffies_to_msecs(lval);
2086 }
2087 return 0;
2088 }
2089
2090 /**
2091 * proc_dointvec_jiffies - read a vector of integers as seconds
2092 * @table: the sysctl table
2093 * @write: %TRUE if this is a write to the sysctl file
2094 * @filp: the file structure
2095 * @buffer: the user buffer
2096 * @lenp: the size of the user buffer
2097 * @ppos: file position
2098 *
2099 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2100 * values from/to the user buffer, treated as an ASCII string.
2101 * The values read are assumed to be in seconds, and are converted into
2102 * jiffies.
2103 *
2104 * Returns 0 on success.
2105 */
2106 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2107 void __user *buffer, size_t *lenp, loff_t *ppos)
2108 {
2109 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2110 do_proc_dointvec_jiffies_conv,NULL);
2111 }
2112
2113 /**
2114 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2115 * @table: the sysctl table
2116 * @write: %TRUE if this is a write to the sysctl file
2117 * @filp: the file structure
2118 * @buffer: the user buffer
2119 * @lenp: the size of the user buffer
2120 * @ppos: pointer to the file position
2121 *
2122 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2123 * values from/to the user buffer, treated as an ASCII string.
2124 * The values read are assumed to be in 1/USER_HZ seconds, and
2125 * are converted into jiffies.
2126 *
2127 * Returns 0 on success.
2128 */
2129 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2130 void __user *buffer, size_t *lenp, loff_t *ppos)
2131 {
2132 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2133 do_proc_dointvec_userhz_jiffies_conv,NULL);
2134 }
2135
2136 /**
2137 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2138 * @table: the sysctl table
2139 * @write: %TRUE if this is a write to the sysctl file
2140 * @filp: the file structure
2141 * @buffer: the user buffer
2142 * @lenp: the size of the user buffer
2143 * @ppos: file position
2144 * @ppos: the current position in the file
2145 *
2146 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2147 * values from/to the user buffer, treated as an ASCII string.
2148 * The values read are assumed to be in 1/1000 seconds, and
2149 * are converted into jiffies.
2150 *
2151 * Returns 0 on success.
2152 */
2153 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2154 void __user *buffer, size_t *lenp, loff_t *ppos)
2155 {
2156 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2157 do_proc_dointvec_ms_jiffies_conv, NULL);
2158 }
2159
2160 #else /* CONFIG_PROC_FS */
2161
2162 int proc_dostring(ctl_table *table, int write, struct file *filp,
2163 void __user *buffer, size_t *lenp, loff_t *ppos)
2164 {
2165 return -ENOSYS;
2166 }
2167
2168 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2169 void __user *buffer, size_t *lenp, loff_t *ppos)
2170 {
2171 return -ENOSYS;
2172 }
2173
2174 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2175 void __user *buffer, size_t *lenp, loff_t *ppos)
2176 {
2177 return -ENOSYS;
2178 }
2179
2180 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2181 void __user *buffer, size_t *lenp, loff_t *ppos)
2182 {
2183 return -ENOSYS;
2184 }
2185
2186 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2187 void __user *buffer, size_t *lenp, loff_t *ppos)
2188 {
2189 return -ENOSYS;
2190 }
2191
2192 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2193 void __user *buffer, size_t *lenp, loff_t *ppos)
2194 {
2195 return -ENOSYS;
2196 }
2197
2198 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2199 void __user *buffer, size_t *lenp, loff_t *ppos)
2200 {
2201 return -ENOSYS;
2202 }
2203
2204 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2205 void __user *buffer, size_t *lenp, loff_t *ppos)
2206 {
2207 return -ENOSYS;
2208 }
2209
2210 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2211 void __user *buffer, size_t *lenp, loff_t *ppos)
2212 {
2213 return -ENOSYS;
2214 }
2215
2216 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2217 struct file *filp,
2218 void __user *buffer,
2219 size_t *lenp, loff_t *ppos)
2220 {
2221 return -ENOSYS;
2222 }
2223
2224
2225 #endif /* CONFIG_PROC_FS */
2226
2227
2228 /*
2229 * General sysctl support routines
2230 */
2231
2232 /* The generic string strategy routine: */
2233 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2234 void __user *oldval, size_t __user *oldlenp,
2235 void __user *newval, size_t newlen, void **context)
2236 {
2237 if (!table->data || !table->maxlen)
2238 return -ENOTDIR;
2239
2240 if (oldval && oldlenp) {
2241 size_t bufsize;
2242 if (get_user(bufsize, oldlenp))
2243 return -EFAULT;
2244 if (bufsize) {
2245 size_t len = strlen(table->data), copied;
2246
2247 /* This shouldn't trigger for a well-formed sysctl */
2248 if (len > table->maxlen)
2249 len = table->maxlen;
2250
2251 /* Copy up to a max of bufsize-1 bytes of the string */
2252 copied = (len >= bufsize) ? bufsize - 1 : len;
2253
2254 if (copy_to_user(oldval, table->data, copied) ||
2255 put_user(0, (char __user *)(oldval + copied)))
2256 return -EFAULT;
2257 if (put_user(len, oldlenp))
2258 return -EFAULT;
2259 }
2260 }
2261 if (newval && newlen) {
2262 size_t len = newlen;
2263 if (len > table->maxlen)
2264 len = table->maxlen;
2265 if(copy_from_user(table->data, newval, len))
2266 return -EFAULT;
2267 if (len == table->maxlen)
2268 len--;
2269 ((char *) table->data)[len] = 0;
2270 }
2271 return 1;
2272 }
2273
2274 /*
2275 * This function makes sure that all of the integers in the vector
2276 * are between the minimum and maximum values given in the arrays
2277 * table->extra1 and table->extra2, respectively.
2278 */
2279 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2280 void __user *oldval, size_t __user *oldlenp,
2281 void __user *newval, size_t newlen, void **context)
2282 {
2283
2284 if (newval && newlen) {
2285 int __user *vec = (int __user *) newval;
2286 int *min = (int *) table->extra1;
2287 int *max = (int *) table->extra2;
2288 size_t length;
2289 int i;
2290
2291 if (newlen % sizeof(int) != 0)
2292 return -EINVAL;
2293
2294 if (!table->extra1 && !table->extra2)
2295 return 0;
2296
2297 if (newlen > table->maxlen)
2298 newlen = table->maxlen;
2299 length = newlen / sizeof(int);
2300
2301 for (i = 0; i < length; i++) {
2302 int value;
2303 if (get_user(value, vec + i))
2304 return -EFAULT;
2305 if (min && value < min[i])
2306 return -EINVAL;
2307 if (max && value > max[i])
2308 return -EINVAL;
2309 }
2310 }
2311 return 0;
2312 }
2313
2314 /* Strategy function to convert jiffies to seconds */
2315 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2316 void __user *oldval, size_t __user *oldlenp,
2317 void __user *newval, size_t newlen, void **context)
2318 {
2319 if (oldval) {
2320 size_t olen;
2321 if (oldlenp) {
2322 if (get_user(olen, oldlenp))
2323 return -EFAULT;
2324 if (olen!=sizeof(int))
2325 return -EINVAL;
2326 }
2327 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2328 (oldlenp && put_user(sizeof(int),oldlenp)))
2329 return -EFAULT;
2330 }
2331 if (newval && newlen) {
2332 int new;
2333 if (newlen != sizeof(int))
2334 return -EINVAL;
2335 if (get_user(new, (int __user *)newval))
2336 return -EFAULT;
2337 *(int *)(table->data) = new*HZ;
2338 }
2339 return 1;
2340 }
2341
2342 /* Strategy function to convert jiffies to seconds */
2343 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2344 void __user *oldval, size_t __user *oldlenp,
2345 void __user *newval, size_t newlen, void **context)
2346 {
2347 if (oldval) {
2348 size_t olen;
2349 if (oldlenp) {
2350 if (get_user(olen, oldlenp))
2351 return -EFAULT;
2352 if (olen!=sizeof(int))
2353 return -EINVAL;
2354 }
2355 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2356 (oldlenp && put_user(sizeof(int),oldlenp)))
2357 return -EFAULT;
2358 }
2359 if (newval && newlen) {
2360 int new;
2361 if (newlen != sizeof(int))
2362 return -EINVAL;
2363 if (get_user(new, (int __user *)newval))
2364 return -EFAULT;
2365 *(int *)(table->data) = msecs_to_jiffies(new);
2366 }
2367 return 1;
2368 }
2369
2370 #else /* CONFIG_SYSCTL */
2371
2372
2373 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2374 {
2375 return -ENOSYS;
2376 }
2377
2378 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2379 void __user *oldval, size_t __user *oldlenp,
2380 void __user *newval, size_t newlen, void **context)
2381 {
2382 return -ENOSYS;
2383 }
2384
2385 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2386 void __user *oldval, size_t __user *oldlenp,
2387 void __user *newval, size_t newlen, void **context)
2388 {
2389 return -ENOSYS;
2390 }
2391
2392 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2393 void __user *oldval, size_t __user *oldlenp,
2394 void __user *newval, size_t newlen, void **context)
2395 {
2396 return -ENOSYS;
2397 }
2398
2399 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2400 void __user *oldval, size_t __user *oldlenp,
2401 void __user *newval, size_t newlen, void **context)
2402 {
2403 return -ENOSYS;
2404 }
2405
2406 int proc_dostring(ctl_table *table, int write, struct file *filp,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2408 {
2409 return -ENOSYS;
2410 }
2411
2412 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2413 void __user *buffer, size_t *lenp, loff_t *ppos)
2414 {
2415 return -ENOSYS;
2416 }
2417
2418 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 {
2421 return -ENOSYS;
2422 }
2423
2424 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426 {
2427 return -ENOSYS;
2428 }
2429
2430 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2431 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 {
2433 return -ENOSYS;
2434 }
2435
2436 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 {
2439 return -ENOSYS;
2440 }
2441
2442 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2443 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 {
2445 return -ENOSYS;
2446 }
2447
2448 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2449 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 {
2451 return -ENOSYS;
2452 }
2453
2454 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2455 struct file *filp,
2456 void __user *buffer,
2457 size_t *lenp, loff_t *ppos)
2458 {
2459 return -ENOSYS;
2460 }
2461
2462 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2463 int insert_at_head)
2464 {
2465 return NULL;
2466 }
2467
2468 void unregister_sysctl_table(struct ctl_table_header * table)
2469 {
2470 }
2471
2472 #endif /* CONFIG_SYSCTL */
2473
2474 /*
2475 * No sense putting this after each symbol definition, twice,
2476 * exception granted :-)
2477 */
2478 EXPORT_SYMBOL(proc_dointvec);
2479 EXPORT_SYMBOL(proc_dointvec_jiffies);
2480 EXPORT_SYMBOL(proc_dointvec_minmax);
2481 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2482 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2483 EXPORT_SYMBOL(proc_dostring);
2484 EXPORT_SYMBOL(proc_doulongvec_minmax);
2485 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2486 EXPORT_SYMBOL(register_sysctl_table);
2487 EXPORT_SYMBOL(sysctl_intvec);
2488 EXPORT_SYMBOL(sysctl_jiffies);
2489 EXPORT_SYMBOL(sysctl_ms_jiffies);
2490 EXPORT_SYMBOL(sysctl_string);
2491 EXPORT_SYMBOL(unregister_sysctl_table);