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