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