xref: /openbmc/linux/kernel/sysctl.c (revision c84db23c6e587d3ab00a41c51fedf758e1f6ecd4)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * sysctl.c: General linux system control interface
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Begun 24 March 1995, Stephen Tweedie
51da177e4SLinus Torvalds  * Added /proc support, Dec 1995
61da177e4SLinus Torvalds  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
71da177e4SLinus Torvalds  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
81da177e4SLinus Torvalds  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
91da177e4SLinus Torvalds  * Dynamic registration fixes, Stephen Tweedie.
101da177e4SLinus Torvalds  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
111da177e4SLinus Torvalds  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
121da177e4SLinus Torvalds  *  Horn.
131da177e4SLinus Torvalds  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
141da177e4SLinus Torvalds  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
151da177e4SLinus Torvalds  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
161da177e4SLinus Torvalds  *  Wendling.
171da177e4SLinus Torvalds  * The list_for_each() macro wasn't appropriate for the sysctl loop.
181da177e4SLinus Torvalds  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
191da177e4SLinus Torvalds  */
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds #include <linux/config.h>
221da177e4SLinus Torvalds #include <linux/module.h>
231da177e4SLinus Torvalds #include <linux/mm.h>
241da177e4SLinus Torvalds #include <linux/swap.h>
251da177e4SLinus Torvalds #include <linux/slab.h>
261da177e4SLinus Torvalds #include <linux/sysctl.h>
271da177e4SLinus Torvalds #include <linux/proc_fs.h>
28c59ede7bSRandy.Dunlap #include <linux/capability.h>
291da177e4SLinus Torvalds #include <linux/ctype.h>
301da177e4SLinus Torvalds #include <linux/utsname.h>
311da177e4SLinus Torvalds #include <linux/capability.h>
321da177e4SLinus Torvalds #include <linux/smp_lock.h>
331da177e4SLinus Torvalds #include <linux/init.h>
341da177e4SLinus Torvalds #include <linux/kernel.h>
350296b228SKay Sievers #include <linux/kobject.h>
3620380731SArnaldo Carvalho de Melo #include <linux/net.h>
371da177e4SLinus Torvalds #include <linux/sysrq.h>
381da177e4SLinus Torvalds #include <linux/highuid.h>
391da177e4SLinus Torvalds #include <linux/writeback.h>
401da177e4SLinus Torvalds #include <linux/hugetlb.h>
411da177e4SLinus Torvalds #include <linux/security.h>
421da177e4SLinus Torvalds #include <linux/initrd.h>
431da177e4SLinus Torvalds #include <linux/times.h>
441da177e4SLinus Torvalds #include <linux/limits.h>
451da177e4SLinus Torvalds #include <linux/dcache.h>
461da177e4SLinus Torvalds #include <linux/syscalls.h>
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #include <asm/uaccess.h>
491da177e4SLinus Torvalds #include <asm/processor.h>
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #ifdef CONFIG_ROOT_NFS
521da177e4SLinus Torvalds #include <linux/nfs_fs.h>
531da177e4SLinus Torvalds #endif
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds /* External variables not in a header file. */
581da177e4SLinus Torvalds extern int C_A_D;
591da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
601da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
611da177e4SLinus Torvalds extern int max_threads;
621da177e4SLinus Torvalds extern int sysrq_enabled;
631da177e4SLinus Torvalds extern int core_uses_pid;
64d6e71144SAlan Cox extern int suid_dumpable;
651da177e4SLinus Torvalds extern char core_pattern[];
661da177e4SLinus Torvalds extern int cad_pid;
671da177e4SLinus Torvalds extern int pid_max;
681da177e4SLinus Torvalds extern int min_free_kbytes;
691da177e4SLinus Torvalds extern int printk_ratelimit_jiffies;
701da177e4SLinus Torvalds extern int printk_ratelimit_burst;
711da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
729d0243bcSAndrew Morton extern int sysctl_drop_caches;
738ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
761da177e4SLinus Torvalds int unknown_nmi_panic;
771da177e4SLinus Torvalds extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
781da177e4SLinus Torvalds 				  void __user *, size_t *, loff_t *);
791da177e4SLinus Torvalds #endif
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
821da177e4SLinus Torvalds static int maxolduid = 65535;
831da177e4SLinus Torvalds static int minolduid;
848ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8;
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds #ifdef CONFIG_KMOD
891da177e4SLinus Torvalds extern char modprobe_path[];
901da177e4SLinus Torvalds #endif
911da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
921da177e4SLinus Torvalds extern int sg_big_buff;
931da177e4SLinus Torvalds #endif
941da177e4SLinus Torvalds #ifdef CONFIG_SYSVIPC
951da177e4SLinus Torvalds extern size_t shm_ctlmax;
961da177e4SLinus Torvalds extern size_t shm_ctlall;
971da177e4SLinus Torvalds extern int shm_ctlmni;
981da177e4SLinus Torvalds extern int msg_ctlmax;
991da177e4SLinus Torvalds extern int msg_ctlmnb;
1001da177e4SLinus Torvalds extern int msg_ctlmni;
1011da177e4SLinus Torvalds extern int sem_ctls[];
1021da177e4SLinus Torvalds #endif
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds #ifdef __sparc__
1051da177e4SLinus Torvalds extern char reboot_command [];
1061da177e4SLinus Torvalds extern int stop_a_enabled;
1071da177e4SLinus Torvalds extern int scons_pwroff;
1081da177e4SLinus Torvalds #endif
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds #ifdef __hppa__
1111da177e4SLinus Torvalds extern int pwrsw_enabled;
1121da177e4SLinus Torvalds extern int unaligned_enabled;
1131da177e4SLinus Torvalds #endif
1141da177e4SLinus Torvalds 
115347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1161da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1171da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1181da177e4SLinus Torvalds #endif
1191da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
120951f22d5SMartin Schwidefsky extern int spin_retry;
1211da177e4SLinus Torvalds #endif
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds extern int sysctl_hz_timer;
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
1261da177e4SLinus Torvalds extern int acct_parm[];
1271da177e4SLinus Torvalds #endif
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds int randomize_va_space = 1;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
1321da177e4SLinus Torvalds 		       ctl_table *, void **);
1331da177e4SLinus Torvalds static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1341da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos);
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds static ctl_table root_table[];
1371da177e4SLinus Torvalds static struct ctl_table_header root_table_header =
1381da177e4SLinus Torvalds 	{ root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds static ctl_table kern_table[];
1411da177e4SLinus Torvalds static ctl_table vm_table[];
1421da177e4SLinus Torvalds static ctl_table proc_table[];
1431da177e4SLinus Torvalds static ctl_table fs_table[];
1441da177e4SLinus Torvalds static ctl_table debug_table[];
1451da177e4SLinus Torvalds static ctl_table dev_table[];
1461da177e4SLinus Torvalds extern ctl_table random_table[];
1471da177e4SLinus Torvalds #ifdef CONFIG_UNIX98_PTYS
1481da177e4SLinus Torvalds extern ctl_table pty_table[];
1491da177e4SLinus Torvalds #endif
1500399cb08SRobert Love #ifdef CONFIG_INOTIFY
1510399cb08SRobert Love extern ctl_table inotify_table[];
1520399cb08SRobert Love #endif
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1551da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1561da177e4SLinus Torvalds #endif
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds /* /proc declarations: */
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
1631da177e4SLinus Torvalds static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
1641da177e4SLinus Torvalds static int proc_opensys(struct inode *, struct file *);
1651da177e4SLinus Torvalds 
1661da177e4SLinus Torvalds struct file_operations proc_sys_file_operations = {
1671da177e4SLinus Torvalds 	.open		= proc_opensys,
1681da177e4SLinus Torvalds 	.read		= proc_readsys,
1691da177e4SLinus Torvalds 	.write		= proc_writesys,
1701da177e4SLinus Torvalds };
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds extern struct proc_dir_entry *proc_sys_root;
1731da177e4SLinus Torvalds 
174330d57fbSAl Viro static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
1751da177e4SLinus Torvalds static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
1761da177e4SLinus Torvalds #endif
1771da177e4SLinus Torvalds 
1781da177e4SLinus Torvalds /* The default sysctl tables: */
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds static ctl_table root_table[] = {
1811da177e4SLinus Torvalds 	{
1821da177e4SLinus Torvalds 		.ctl_name	= CTL_KERN,
1831da177e4SLinus Torvalds 		.procname	= "kernel",
1841da177e4SLinus Torvalds 		.mode		= 0555,
1851da177e4SLinus Torvalds 		.child		= kern_table,
1861da177e4SLinus Torvalds 	},
1871da177e4SLinus Torvalds 	{
1881da177e4SLinus Torvalds 		.ctl_name	= CTL_VM,
1891da177e4SLinus Torvalds 		.procname	= "vm",
1901da177e4SLinus Torvalds 		.mode		= 0555,
1911da177e4SLinus Torvalds 		.child		= vm_table,
1921da177e4SLinus Torvalds 	},
1931da177e4SLinus Torvalds #ifdef CONFIG_NET
1941da177e4SLinus Torvalds 	{
1951da177e4SLinus Torvalds 		.ctl_name	= CTL_NET,
1961da177e4SLinus Torvalds 		.procname	= "net",
1971da177e4SLinus Torvalds 		.mode		= 0555,
1981da177e4SLinus Torvalds 		.child		= net_table,
1991da177e4SLinus Torvalds 	},
2001da177e4SLinus Torvalds #endif
2011da177e4SLinus Torvalds 	{
2021da177e4SLinus Torvalds 		.ctl_name	= CTL_PROC,
2031da177e4SLinus Torvalds 		.procname	= "proc",
2041da177e4SLinus Torvalds 		.mode		= 0555,
2051da177e4SLinus Torvalds 		.child		= proc_table,
2061da177e4SLinus Torvalds 	},
2071da177e4SLinus Torvalds 	{
2081da177e4SLinus Torvalds 		.ctl_name	= CTL_FS,
2091da177e4SLinus Torvalds 		.procname	= "fs",
2101da177e4SLinus Torvalds 		.mode		= 0555,
2111da177e4SLinus Torvalds 		.child		= fs_table,
2121da177e4SLinus Torvalds 	},
2131da177e4SLinus Torvalds 	{
2141da177e4SLinus Torvalds 		.ctl_name	= CTL_DEBUG,
2151da177e4SLinus Torvalds 		.procname	= "debug",
2161da177e4SLinus Torvalds 		.mode		= 0555,
2171da177e4SLinus Torvalds 		.child		= debug_table,
2181da177e4SLinus Torvalds 	},
2191da177e4SLinus Torvalds 	{
2201da177e4SLinus Torvalds 		.ctl_name	= CTL_DEV,
2211da177e4SLinus Torvalds 		.procname	= "dev",
2221da177e4SLinus Torvalds 		.mode		= 0555,
2231da177e4SLinus Torvalds 		.child		= dev_table,
2241da177e4SLinus Torvalds 	},
2250eeca283SRobert Love 
2261da177e4SLinus Torvalds 	{ .ctl_name = 0 }
2271da177e4SLinus Torvalds };
2281da177e4SLinus Torvalds 
2291da177e4SLinus Torvalds static ctl_table kern_table[] = {
2301da177e4SLinus Torvalds 	{
2311da177e4SLinus Torvalds 		.ctl_name	= KERN_OSTYPE,
2321da177e4SLinus Torvalds 		.procname	= "ostype",
2331da177e4SLinus Torvalds 		.data		= system_utsname.sysname,
2341da177e4SLinus Torvalds 		.maxlen		= sizeof(system_utsname.sysname),
2351da177e4SLinus Torvalds 		.mode		= 0444,
2361da177e4SLinus Torvalds 		.proc_handler	= &proc_doutsstring,
2371da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2381da177e4SLinus Torvalds 	},
2391da177e4SLinus Torvalds 	{
2401da177e4SLinus Torvalds 		.ctl_name	= KERN_OSRELEASE,
2411da177e4SLinus Torvalds 		.procname	= "osrelease",
2421da177e4SLinus Torvalds 		.data		= system_utsname.release,
2431da177e4SLinus Torvalds 		.maxlen		= sizeof(system_utsname.release),
2441da177e4SLinus Torvalds 		.mode		= 0444,
2451da177e4SLinus Torvalds 		.proc_handler	= &proc_doutsstring,
2461da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2471da177e4SLinus Torvalds 	},
2481da177e4SLinus Torvalds 	{
2491da177e4SLinus Torvalds 		.ctl_name	= KERN_VERSION,
2501da177e4SLinus Torvalds 		.procname	= "version",
2511da177e4SLinus Torvalds 		.data		= system_utsname.version,
2521da177e4SLinus Torvalds 		.maxlen		= sizeof(system_utsname.version),
2531da177e4SLinus Torvalds 		.mode		= 0444,
2541da177e4SLinus Torvalds 		.proc_handler	= &proc_doutsstring,
2551da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2561da177e4SLinus Torvalds 	},
2571da177e4SLinus Torvalds 	{
2581da177e4SLinus Torvalds 		.ctl_name	= KERN_NODENAME,
2591da177e4SLinus Torvalds 		.procname	= "hostname",
2601da177e4SLinus Torvalds 		.data		= system_utsname.nodename,
2611da177e4SLinus Torvalds 		.maxlen		= sizeof(system_utsname.nodename),
2621da177e4SLinus Torvalds 		.mode		= 0644,
2631da177e4SLinus Torvalds 		.proc_handler	= &proc_doutsstring,
2641da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2651da177e4SLinus Torvalds 	},
2661da177e4SLinus Torvalds 	{
2671da177e4SLinus Torvalds 		.ctl_name	= KERN_DOMAINNAME,
2681da177e4SLinus Torvalds 		.procname	= "domainname",
2691da177e4SLinus Torvalds 		.data		= system_utsname.domainname,
2701da177e4SLinus Torvalds 		.maxlen		= sizeof(system_utsname.domainname),
2711da177e4SLinus Torvalds 		.mode		= 0644,
2721da177e4SLinus Torvalds 		.proc_handler	= &proc_doutsstring,
2731da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2741da177e4SLinus Torvalds 	},
2751da177e4SLinus Torvalds 	{
2761da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC,
2771da177e4SLinus Torvalds 		.procname	= "panic",
2781da177e4SLinus Torvalds 		.data		= &panic_timeout,
2791da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
2801da177e4SLinus Torvalds 		.mode		= 0644,
2811da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
2821da177e4SLinus Torvalds 	},
2831da177e4SLinus Torvalds 	{
2841da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_USES_PID,
2851da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
2861da177e4SLinus Torvalds 		.data		= &core_uses_pid,
2871da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
2881da177e4SLinus Torvalds 		.mode		= 0644,
2891da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
2901da177e4SLinus Torvalds 	},
2911da177e4SLinus Torvalds 	{
2921da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_PATTERN,
2931da177e4SLinus Torvalds 		.procname	= "core_pattern",
2941da177e4SLinus Torvalds 		.data		= core_pattern,
2951da177e4SLinus Torvalds 		.maxlen		= 64,
2961da177e4SLinus Torvalds 		.mode		= 0644,
2971da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
2981da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2991da177e4SLinus Torvalds 	},
3001da177e4SLinus Torvalds 	{
3011da177e4SLinus Torvalds 		.ctl_name	= KERN_TAINTED,
3021da177e4SLinus Torvalds 		.procname	= "tainted",
3031da177e4SLinus Torvalds 		.data		= &tainted,
3041da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3051da177e4SLinus Torvalds 		.mode		= 0444,
3061da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3071da177e4SLinus Torvalds 	},
3081da177e4SLinus Torvalds 	{
3091da177e4SLinus Torvalds 		.ctl_name	= KERN_CAP_BSET,
3101da177e4SLinus Torvalds 		.procname	= "cap-bound",
3111da177e4SLinus Torvalds 		.data		= &cap_bset,
3121da177e4SLinus Torvalds 		.maxlen		= sizeof(kernel_cap_t),
3131da177e4SLinus Torvalds 		.mode		= 0600,
3141da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_bset,
3151da177e4SLinus Torvalds 	},
3161da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
3171da177e4SLinus Torvalds 	{
3181da177e4SLinus Torvalds 		.ctl_name	= KERN_REALROOTDEV,
3191da177e4SLinus Torvalds 		.procname	= "real-root-dev",
3201da177e4SLinus Torvalds 		.data		= &real_root_dev,
3211da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3221da177e4SLinus Torvalds 		.mode		= 0644,
3231da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3241da177e4SLinus Torvalds 	},
3251da177e4SLinus Torvalds #endif
3261da177e4SLinus Torvalds #ifdef __sparc__
3271da177e4SLinus Torvalds 	{
3281da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_REBOOT,
3291da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
3301da177e4SLinus Torvalds 		.data		= reboot_command,
3311da177e4SLinus Torvalds 		.maxlen		= 256,
3321da177e4SLinus Torvalds 		.mode		= 0644,
3331da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3341da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3351da177e4SLinus Torvalds 	},
3361da177e4SLinus Torvalds 	{
3371da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_STOP_A,
3381da177e4SLinus Torvalds 		.procname	= "stop-a",
3391da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
3401da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3411da177e4SLinus Torvalds 		.mode		= 0644,
3421da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3431da177e4SLinus Torvalds 	},
3441da177e4SLinus Torvalds 	{
3451da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
3461da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
3471da177e4SLinus Torvalds 		.data		= &scons_pwroff,
3481da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3491da177e4SLinus Torvalds 		.mode		= 0644,
3501da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3511da177e4SLinus Torvalds 	},
3521da177e4SLinus Torvalds #endif
3531da177e4SLinus Torvalds #ifdef __hppa__
3541da177e4SLinus Torvalds 	{
3551da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_PWRSW,
3561da177e4SLinus Torvalds 		.procname	= "soft-power",
3571da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
3581da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3591da177e4SLinus Torvalds 	 	.mode		= 0644,
3601da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3611da177e4SLinus Torvalds 	},
3621da177e4SLinus Torvalds 	{
3631da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_UNALIGNED,
3641da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
3651da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
3661da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3671da177e4SLinus Torvalds 		.mode		= 0644,
3681da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3691da177e4SLinus Torvalds 	},
3701da177e4SLinus Torvalds #endif
3711da177e4SLinus Torvalds 	{
3721da177e4SLinus Torvalds 		.ctl_name	= KERN_CTLALTDEL,
3731da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
3741da177e4SLinus Torvalds 		.data		= &C_A_D,
3751da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3761da177e4SLinus Torvalds 		.mode		= 0644,
3771da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3781da177e4SLinus Torvalds 	},
3791da177e4SLinus Torvalds 	{
3801da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK,
3811da177e4SLinus Torvalds 		.procname	= "printk",
3821da177e4SLinus Torvalds 		.data		= &console_loglevel,
3831da177e4SLinus Torvalds 		.maxlen		= 4*sizeof(int),
3841da177e4SLinus Torvalds 		.mode		= 0644,
3851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3861da177e4SLinus Torvalds 	},
3871da177e4SLinus Torvalds #ifdef CONFIG_KMOD
3881da177e4SLinus Torvalds 	{
3891da177e4SLinus Torvalds 		.ctl_name	= KERN_MODPROBE,
3901da177e4SLinus Torvalds 		.procname	= "modprobe",
3911da177e4SLinus Torvalds 		.data		= &modprobe_path,
3921da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
3931da177e4SLinus Torvalds 		.mode		= 0644,
3941da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3951da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3961da177e4SLinus Torvalds 	},
3971da177e4SLinus Torvalds #endif
3981da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG
3991da177e4SLinus Torvalds 	{
4001da177e4SLinus Torvalds 		.ctl_name	= KERN_HOTPLUG,
4011da177e4SLinus Torvalds 		.procname	= "hotplug",
402312c004dSKay Sievers 		.data		= &uevent_helper,
403312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
4041da177e4SLinus Torvalds 		.mode		= 0644,
4051da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4061da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4071da177e4SLinus Torvalds 	},
4081da177e4SLinus Torvalds #endif
4091da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
4101da177e4SLinus Torvalds 	{
4111da177e4SLinus Torvalds 		.ctl_name	= KERN_SG_BIG_BUFF,
4121da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
4131da177e4SLinus Torvalds 		.data		= &sg_big_buff,
4141da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4151da177e4SLinus Torvalds 		.mode		= 0444,
4161da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4171da177e4SLinus Torvalds 	},
4181da177e4SLinus Torvalds #endif
4191da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
4201da177e4SLinus Torvalds 	{
4211da177e4SLinus Torvalds 		.ctl_name	= KERN_ACCT,
4221da177e4SLinus Torvalds 		.procname	= "acct",
4231da177e4SLinus Torvalds 		.data		= &acct_parm,
4241da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
4251da177e4SLinus Torvalds 		.mode		= 0644,
4261da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4271da177e4SLinus Torvalds 	},
4281da177e4SLinus Torvalds #endif
4291da177e4SLinus Torvalds #ifdef CONFIG_SYSVIPC
4301da177e4SLinus Torvalds 	{
4311da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMMAX,
4321da177e4SLinus Torvalds 		.procname	= "shmmax",
4331da177e4SLinus Torvalds 		.data		= &shm_ctlmax,
4341da177e4SLinus Torvalds 		.maxlen		= sizeof (size_t),
4351da177e4SLinus Torvalds 		.mode		= 0644,
4361da177e4SLinus Torvalds 		.proc_handler	= &proc_doulongvec_minmax,
4371da177e4SLinus Torvalds 	},
4381da177e4SLinus Torvalds 	{
4391da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMALL,
4401da177e4SLinus Torvalds 		.procname	= "shmall",
4411da177e4SLinus Torvalds 		.data		= &shm_ctlall,
4421da177e4SLinus Torvalds 		.maxlen		= sizeof (size_t),
4431da177e4SLinus Torvalds 		.mode		= 0644,
4441da177e4SLinus Torvalds 		.proc_handler	= &proc_doulongvec_minmax,
4451da177e4SLinus Torvalds 	},
4461da177e4SLinus Torvalds 	{
4471da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMMNI,
4481da177e4SLinus Torvalds 		.procname	= "shmmni",
4491da177e4SLinus Torvalds 		.data		= &shm_ctlmni,
4501da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4511da177e4SLinus Torvalds 		.mode		= 0644,
4521da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4531da177e4SLinus Torvalds 	},
4541da177e4SLinus Torvalds 	{
4551da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMAX,
4561da177e4SLinus Torvalds 		.procname	= "msgmax",
4571da177e4SLinus Torvalds 		.data		= &msg_ctlmax,
4581da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4591da177e4SLinus Torvalds 		.mode		= 0644,
4601da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4611da177e4SLinus Torvalds 	},
4621da177e4SLinus Torvalds 	{
4631da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMNI,
4641da177e4SLinus Torvalds 		.procname	= "msgmni",
4651da177e4SLinus Torvalds 		.data		= &msg_ctlmni,
4661da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4671da177e4SLinus Torvalds 		.mode		= 0644,
4681da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4691da177e4SLinus Torvalds 	},
4701da177e4SLinus Torvalds 	{
4711da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMNB,
4721da177e4SLinus Torvalds 		.procname	=  "msgmnb",
4731da177e4SLinus Torvalds 		.data		= &msg_ctlmnb,
4741da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4751da177e4SLinus Torvalds 		.mode		= 0644,
4761da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4771da177e4SLinus Torvalds 	},
4781da177e4SLinus Torvalds 	{
4791da177e4SLinus Torvalds 		.ctl_name	= KERN_SEM,
4801da177e4SLinus Torvalds 		.procname	= "sem",
4811da177e4SLinus Torvalds 		.data		= &sem_ctls,
4821da177e4SLinus Torvalds 		.maxlen		= 4*sizeof (int),
4831da177e4SLinus Torvalds 		.mode		= 0644,
4841da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4851da177e4SLinus Torvalds 	},
4861da177e4SLinus Torvalds #endif
4871da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
4881da177e4SLinus Torvalds 	{
4891da177e4SLinus Torvalds 		.ctl_name	= KERN_SYSRQ,
4901da177e4SLinus Torvalds 		.procname	= "sysrq",
4911da177e4SLinus Torvalds 		.data		= &sysrq_enabled,
4921da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4931da177e4SLinus Torvalds 		.mode		= 0644,
4941da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4951da177e4SLinus Torvalds 	},
4961da177e4SLinus Torvalds #endif
4971da177e4SLinus Torvalds 	{
4981da177e4SLinus Torvalds 		.ctl_name	= KERN_CADPID,
4991da177e4SLinus Torvalds 		.procname	= "cad_pid",
5001da177e4SLinus Torvalds 		.data		= &cad_pid,
5011da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5021da177e4SLinus Torvalds 		.mode		= 0600,
5031da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5041da177e4SLinus Torvalds 	},
5051da177e4SLinus Torvalds 	{
5061da177e4SLinus Torvalds 		.ctl_name	= KERN_MAX_THREADS,
5071da177e4SLinus Torvalds 		.procname	= "threads-max",
5081da177e4SLinus Torvalds 		.data		= &max_threads,
5091da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5101da177e4SLinus Torvalds 		.mode		= 0644,
5111da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5121da177e4SLinus Torvalds 	},
5131da177e4SLinus Torvalds 	{
5141da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOM,
5151da177e4SLinus Torvalds 		.procname	= "random",
5161da177e4SLinus Torvalds 		.mode		= 0555,
5171da177e4SLinus Torvalds 		.child		= random_table,
5181da177e4SLinus Torvalds 	},
5191da177e4SLinus Torvalds #ifdef CONFIG_UNIX98_PTYS
5201da177e4SLinus Torvalds 	{
5211da177e4SLinus Torvalds 		.ctl_name	= KERN_PTY,
5221da177e4SLinus Torvalds 		.procname	= "pty",
5231da177e4SLinus Torvalds 		.mode		= 0555,
5241da177e4SLinus Torvalds 		.child		= pty_table,
5251da177e4SLinus Torvalds 	},
5261da177e4SLinus Torvalds #endif
5271da177e4SLinus Torvalds 	{
5281da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWUID,
5291da177e4SLinus Torvalds 		.procname	= "overflowuid",
5301da177e4SLinus Torvalds 		.data		= &overflowuid,
5311da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5321da177e4SLinus Torvalds 		.mode		= 0644,
5331da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5341da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5351da177e4SLinus Torvalds 		.extra1		= &minolduid,
5361da177e4SLinus Torvalds 		.extra2		= &maxolduid,
5371da177e4SLinus Torvalds 	},
5381da177e4SLinus Torvalds 	{
5391da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWGID,
5401da177e4SLinus Torvalds 		.procname	= "overflowgid",
5411da177e4SLinus Torvalds 		.data		= &overflowgid,
5421da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5431da177e4SLinus Torvalds 		.mode		= 0644,
5441da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5451da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5461da177e4SLinus Torvalds 		.extra1		= &minolduid,
5471da177e4SLinus Torvalds 		.extra2		= &maxolduid,
5481da177e4SLinus Torvalds 	},
549347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
5501da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
5511da177e4SLinus Torvalds 	{
5521da177e4SLinus Torvalds 		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
5531da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
5541da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
5551da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5561da177e4SLinus Torvalds 		.mode		= 0644,
5571da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5581da177e4SLinus Torvalds 	},
5591da177e4SLinus Torvalds #endif
5601da177e4SLinus Torvalds #ifdef CONFIG_NO_IDLE_HZ
5611da177e4SLinus Torvalds 	{
5621da177e4SLinus Torvalds 		.ctl_name       = KERN_HZ_TIMER,
5631da177e4SLinus Torvalds 		.procname       = "hz_timer",
5641da177e4SLinus Torvalds 		.data           = &sysctl_hz_timer,
5651da177e4SLinus Torvalds 		.maxlen         = sizeof(int),
5661da177e4SLinus Torvalds 		.mode           = 0644,
5671da177e4SLinus Torvalds 		.proc_handler   = &proc_dointvec,
5681da177e4SLinus Torvalds 	},
5691da177e4SLinus Torvalds #endif
5701da177e4SLinus Torvalds 	{
5711da177e4SLinus Torvalds 		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
5721da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
5731da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
5741da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5751da177e4SLinus Torvalds 		.mode		= 0644,
5761da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5771da177e4SLinus Torvalds 	},
5781da177e4SLinus Torvalds #endif
5791da177e4SLinus Torvalds 	{
5801da177e4SLinus Torvalds 		.ctl_name	= KERN_PIDMAX,
5811da177e4SLinus Torvalds 		.procname	= "pid_max",
5821da177e4SLinus Torvalds 		.data		= &pid_max,
5831da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5841da177e4SLinus Torvalds 		.mode		= 0644,
5851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5861da177e4SLinus Torvalds 		.strategy	= sysctl_intvec,
5871da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
5881da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
5891da177e4SLinus Torvalds 	},
5901da177e4SLinus Torvalds 	{
5911da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC_ON_OOPS,
5921da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
5931da177e4SLinus Torvalds 		.data		= &panic_on_oops,
5941da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5951da177e4SLinus Torvalds 		.mode		= 0644,
5961da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5971da177e4SLinus Torvalds 	},
5981da177e4SLinus Torvalds 	{
5991da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT,
6001da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
6011da177e4SLinus Torvalds 		.data		= &printk_ratelimit_jiffies,
6021da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6031da177e4SLinus Torvalds 		.mode		= 0644,
6041da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
6051da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
6061da177e4SLinus Torvalds 	},
6071da177e4SLinus Torvalds 	{
6081da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
6091da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
6101da177e4SLinus Torvalds 		.data		= &printk_ratelimit_burst,
6111da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6121da177e4SLinus Torvalds 		.mode		= 0644,
6131da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6141da177e4SLinus Torvalds 	},
6151da177e4SLinus Torvalds 	{
6161da177e4SLinus Torvalds 		.ctl_name	= KERN_NGROUPS_MAX,
6171da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6181da177e4SLinus Torvalds 		.data		= &ngroups_max,
6191da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6201da177e4SLinus Torvalds 		.mode		= 0444,
6211da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6221da177e4SLinus Torvalds 	},
6231da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6241da177e4SLinus Torvalds 	{
6251da177e4SLinus Torvalds 		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
6261da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
6271da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
6281da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
6291da177e4SLinus Torvalds 		.mode           = 0644,
6301da177e4SLinus Torvalds 		.proc_handler   = &proc_unknown_nmi_panic,
6311da177e4SLinus Torvalds 	},
6321da177e4SLinus Torvalds #endif
6331da177e4SLinus Torvalds #if defined(CONFIG_X86)
6341da177e4SLinus Torvalds 	{
6351da177e4SLinus Torvalds 		.ctl_name	= KERN_BOOTLOADER_TYPE,
6361da177e4SLinus Torvalds 		.procname	= "bootloader_type",
6371da177e4SLinus Torvalds 		.data		= &bootloader_type,
6381da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6391da177e4SLinus Torvalds 		.mode		= 0444,
6401da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6411da177e4SLinus Torvalds 	},
6421da177e4SLinus Torvalds #endif
6431da177e4SLinus Torvalds 	{
6441da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOMIZE,
6451da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
6461da177e4SLinus Torvalds 		.data		= &randomize_va_space,
6471da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6481da177e4SLinus Torvalds 		.mode		= 0644,
6491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6501da177e4SLinus Torvalds 	},
6510152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
652951f22d5SMartin Schwidefsky 	{
653951f22d5SMartin Schwidefsky 		.ctl_name	= KERN_SPIN_RETRY,
654951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
655951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
656951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
657951f22d5SMartin Schwidefsky 		.mode		= 0644,
658951f22d5SMartin Schwidefsky 		.proc_handler	= &proc_dointvec,
659951f22d5SMartin Schwidefsky 	},
660951f22d5SMartin Schwidefsky #endif
6611da177e4SLinus Torvalds 	{ .ctl_name = 0 }
6621da177e4SLinus Torvalds };
6631da177e4SLinus Torvalds 
6641da177e4SLinus Torvalds /* Constants for minimum and maximum testing in vm_table.
6651da177e4SLinus Torvalds    We use these as one-element integer vectors. */
6661da177e4SLinus Torvalds static int zero;
6671da177e4SLinus Torvalds static int one_hundred = 100;
6681da177e4SLinus Torvalds 
6691da177e4SLinus Torvalds 
6701da177e4SLinus Torvalds static ctl_table vm_table[] = {
6711da177e4SLinus Torvalds 	{
6721da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_MEMORY,
6731da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
6741da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
6751da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
6761da177e4SLinus Torvalds 		.mode		= 0644,
6771da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6781da177e4SLinus Torvalds 	},
6791da177e4SLinus Torvalds 	{
6801da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_RATIO,
6811da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
6821da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
6831da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
6841da177e4SLinus Torvalds 		.mode		= 0644,
6851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6861da177e4SLinus Torvalds 	},
6871da177e4SLinus Torvalds 	{
6881da177e4SLinus Torvalds 		.ctl_name	= VM_PAGE_CLUSTER,
6891da177e4SLinus Torvalds 		.procname	= "page-cluster",
6901da177e4SLinus Torvalds 		.data		= &page_cluster,
6911da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6921da177e4SLinus Torvalds 		.mode		= 0644,
6931da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6941da177e4SLinus Torvalds 	},
6951da177e4SLinus Torvalds 	{
6961da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_BACKGROUND,
6971da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
6981da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
6991da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
7001da177e4SLinus Torvalds 		.mode		= 0644,
7011da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
7021da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
7031da177e4SLinus Torvalds 		.extra1		= &zero,
7041da177e4SLinus Torvalds 		.extra2		= &one_hundred,
7051da177e4SLinus Torvalds 	},
7061da177e4SLinus Torvalds 	{
7071da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_RATIO,
7081da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
7091da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
7101da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
7111da177e4SLinus Torvalds 		.mode		= 0644,
7121da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
7131da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
7141da177e4SLinus Torvalds 		.extra1		= &zero,
7151da177e4SLinus Torvalds 		.extra2		= &one_hundred,
7161da177e4SLinus Torvalds 	},
7171da177e4SLinus Torvalds 	{
7181da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_WB_CS,
7191da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
7201da177e4SLinus Torvalds 		.data		= &dirty_writeback_centisecs,
7211da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_writeback_centisecs),
7221da177e4SLinus Torvalds 		.mode		= 0644,
7231da177e4SLinus Torvalds 		.proc_handler	= &dirty_writeback_centisecs_handler,
7241da177e4SLinus Torvalds 	},
7251da177e4SLinus Torvalds 	{
7261da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_EXPIRE_CS,
7271da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
7281da177e4SLinus Torvalds 		.data		= &dirty_expire_centisecs,
7291da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_expire_centisecs),
7301da177e4SLinus Torvalds 		.mode		= 0644,
7311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7321da177e4SLinus Torvalds 	},
7331da177e4SLinus Torvalds 	{
7341da177e4SLinus Torvalds 		.ctl_name	= VM_NR_PDFLUSH_THREADS,
7351da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
7361da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
7371da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
7381da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
7391da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7401da177e4SLinus Torvalds 	},
7411da177e4SLinus Torvalds 	{
7421da177e4SLinus Torvalds 		.ctl_name	= VM_SWAPPINESS,
7431da177e4SLinus Torvalds 		.procname	= "swappiness",
7441da177e4SLinus Torvalds 		.data		= &vm_swappiness,
7451da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
7461da177e4SLinus Torvalds 		.mode		= 0644,
7471da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
7481da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
7491da177e4SLinus Torvalds 		.extra1		= &zero,
7501da177e4SLinus Torvalds 		.extra2		= &one_hundred,
7511da177e4SLinus Torvalds 	},
7521da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
7531da177e4SLinus Torvalds 	 {
7541da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_PAGES,
7551da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
7561da177e4SLinus Torvalds 		.data		= &max_huge_pages,
7571da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
7581da177e4SLinus Torvalds 		.mode		= 0644,
7591da177e4SLinus Torvalds 		.proc_handler	= &hugetlb_sysctl_handler,
7601da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
7611da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
7621da177e4SLinus Torvalds 	 },
7631da177e4SLinus Torvalds 	 {
7641da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_GROUP,
7651da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
7661da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
7671da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
7681da177e4SLinus Torvalds 		.mode		= 0644,
7691da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7701da177e4SLinus Torvalds 	 },
7711da177e4SLinus Torvalds #endif
7721da177e4SLinus Torvalds 	{
7731da177e4SLinus Torvalds 		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
7741da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
7751da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
7761da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
7771da177e4SLinus Torvalds 		.mode		= 0644,
7781da177e4SLinus Torvalds 		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
7791da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
7801da177e4SLinus Torvalds 	},
7811da177e4SLinus Torvalds 	{
7829d0243bcSAndrew Morton 		.ctl_name	= VM_DROP_PAGECACHE,
7839d0243bcSAndrew Morton 		.procname	= "drop_caches",
7849d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
7859d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
7869d0243bcSAndrew Morton 		.mode		= 0644,
7879d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
7889d0243bcSAndrew Morton 		.strategy	= &sysctl_intvec,
7899d0243bcSAndrew Morton 	},
7909d0243bcSAndrew Morton 	{
7911da177e4SLinus Torvalds 		.ctl_name	= VM_MIN_FREE_KBYTES,
7921da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
7931da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
7941da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
7951da177e4SLinus Torvalds 		.mode		= 0644,
7961da177e4SLinus Torvalds 		.proc_handler	= &min_free_kbytes_sysctl_handler,
7971da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
7981da177e4SLinus Torvalds 		.extra1		= &zero,
7991da177e4SLinus Torvalds 	},
8008ad4b1fbSRohit Seth 	{
8018ad4b1fbSRohit Seth 		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
8028ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
8038ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
8048ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
8058ad4b1fbSRohit Seth 		.mode		= 0644,
8068ad4b1fbSRohit Seth 		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
8078ad4b1fbSRohit Seth 		.strategy	= &sysctl_intvec,
8088ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
8098ad4b1fbSRohit Seth 	},
8101da177e4SLinus Torvalds #ifdef CONFIG_MMU
8111da177e4SLinus Torvalds 	{
8121da177e4SLinus Torvalds 		.ctl_name	= VM_MAX_MAP_COUNT,
8131da177e4SLinus Torvalds 		.procname	= "max_map_count",
8141da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
8151da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
8161da177e4SLinus Torvalds 		.mode		= 0644,
8171da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec
8181da177e4SLinus Torvalds 	},
8191da177e4SLinus Torvalds #endif
8201da177e4SLinus Torvalds 	{
8211da177e4SLinus Torvalds 		.ctl_name	= VM_LAPTOP_MODE,
8221da177e4SLinus Torvalds 		.procname	= "laptop_mode",
8231da177e4SLinus Torvalds 		.data		= &laptop_mode,
8241da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
8251da177e4SLinus Torvalds 		.mode		= 0644,
8261da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8271da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8281da177e4SLinus Torvalds 		.extra1		= &zero,
8291da177e4SLinus Torvalds 	},
8301da177e4SLinus Torvalds 	{
8311da177e4SLinus Torvalds 		.ctl_name	= VM_BLOCK_DUMP,
8321da177e4SLinus Torvalds 		.procname	= "block_dump",
8331da177e4SLinus Torvalds 		.data		= &block_dump,
8341da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
8351da177e4SLinus Torvalds 		.mode		= 0644,
8361da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8371da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8381da177e4SLinus Torvalds 		.extra1		= &zero,
8391da177e4SLinus Torvalds 	},
8401da177e4SLinus Torvalds 	{
8411da177e4SLinus Torvalds 		.ctl_name	= VM_VFS_CACHE_PRESSURE,
8421da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
8431da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
8441da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
8451da177e4SLinus Torvalds 		.mode		= 0644,
8461da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8471da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8481da177e4SLinus Torvalds 		.extra1		= &zero,
8491da177e4SLinus Torvalds 	},
8501da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
8511da177e4SLinus Torvalds 	{
8521da177e4SLinus Torvalds 		.ctl_name	= VM_LEGACY_VA_LAYOUT,
8531da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
8541da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
8551da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
8561da177e4SLinus Torvalds 		.mode		= 0644,
8571da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8581da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8591da177e4SLinus Torvalds 		.extra1		= &zero,
8601da177e4SLinus Torvalds 	},
8611da177e4SLinus Torvalds #endif
8621da177e4SLinus Torvalds #ifdef CONFIG_SWAP
8631da177e4SLinus Torvalds 	{
8641da177e4SLinus Torvalds 		.ctl_name	= VM_SWAP_TOKEN_TIMEOUT,
8651da177e4SLinus Torvalds 		.procname	= "swap_token_timeout",
8661da177e4SLinus Torvalds 		.data		= &swap_token_default_timeout,
8671da177e4SLinus Torvalds 		.maxlen		= sizeof(swap_token_default_timeout),
8681da177e4SLinus Torvalds 		.mode		= 0644,
8691da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
8701da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
8711da177e4SLinus Torvalds 	},
8721da177e4SLinus Torvalds #endif
8731743660bSChristoph Lameter #ifdef CONFIG_NUMA
8741743660bSChristoph Lameter 	{
8751743660bSChristoph Lameter 		.ctl_name	= VM_ZONE_RECLAIM_MODE,
8761743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
8771743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
8781743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
8791743660bSChristoph Lameter 		.mode		= 0644,
8801743660bSChristoph Lameter 		.proc_handler	= &proc_dointvec,
881*c84db23cSChristoph Lameter 		.strategy	= &sysctl_intvec,
882*c84db23cSChristoph Lameter 		.extra1		= &zero,
8831743660bSChristoph Lameter 	},
8841743660bSChristoph Lameter #endif
8851da177e4SLinus Torvalds 	{ .ctl_name = 0 }
8861da177e4SLinus Torvalds };
8871da177e4SLinus Torvalds 
8881da177e4SLinus Torvalds static ctl_table proc_table[] = {
8891da177e4SLinus Torvalds 	{ .ctl_name = 0 }
8901da177e4SLinus Torvalds };
8911da177e4SLinus Torvalds 
8921da177e4SLinus Torvalds static ctl_table fs_table[] = {
8931da177e4SLinus Torvalds 	{
8941da177e4SLinus Torvalds 		.ctl_name	= FS_NRINODE,
8951da177e4SLinus Torvalds 		.procname	= "inode-nr",
8961da177e4SLinus Torvalds 		.data		= &inodes_stat,
8971da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
8981da177e4SLinus Torvalds 		.mode		= 0444,
8991da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9001da177e4SLinus Torvalds 	},
9011da177e4SLinus Torvalds 	{
9021da177e4SLinus Torvalds 		.ctl_name	= FS_STATINODE,
9031da177e4SLinus Torvalds 		.procname	= "inode-state",
9041da177e4SLinus Torvalds 		.data		= &inodes_stat,
9051da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
9061da177e4SLinus Torvalds 		.mode		= 0444,
9071da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9081da177e4SLinus Torvalds 	},
9091da177e4SLinus Torvalds 	{
9101da177e4SLinus Torvalds 		.ctl_name	= FS_NRFILE,
9111da177e4SLinus Torvalds 		.procname	= "file-nr",
9121da177e4SLinus Torvalds 		.data		= &files_stat,
9131da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
9141da177e4SLinus Torvalds 		.mode		= 0444,
9151da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9161da177e4SLinus Torvalds 	},
9171da177e4SLinus Torvalds 	{
9181da177e4SLinus Torvalds 		.ctl_name	= FS_MAXFILE,
9191da177e4SLinus Torvalds 		.procname	= "file-max",
9201da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
9211da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9221da177e4SLinus Torvalds 		.mode		= 0644,
9231da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9241da177e4SLinus Torvalds 	},
9251da177e4SLinus Torvalds 	{
9261da177e4SLinus Torvalds 		.ctl_name	= FS_DENTRY,
9271da177e4SLinus Torvalds 		.procname	= "dentry-state",
9281da177e4SLinus Torvalds 		.data		= &dentry_stat,
9291da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
9301da177e4SLinus Torvalds 		.mode		= 0444,
9311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9321da177e4SLinus Torvalds 	},
9331da177e4SLinus Torvalds 	{
9341da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWUID,
9351da177e4SLinus Torvalds 		.procname	= "overflowuid",
9361da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
9371da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9381da177e4SLinus Torvalds 		.mode		= 0644,
9391da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
9401da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9411da177e4SLinus Torvalds 		.extra1		= &minolduid,
9421da177e4SLinus Torvalds 		.extra2		= &maxolduid,
9431da177e4SLinus Torvalds 	},
9441da177e4SLinus Torvalds 	{
9451da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWGID,
9461da177e4SLinus Torvalds 		.procname	= "overflowgid",
9471da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
9481da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9491da177e4SLinus Torvalds 		.mode		= 0644,
9501da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
9511da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9521da177e4SLinus Torvalds 		.extra1		= &minolduid,
9531da177e4SLinus Torvalds 		.extra2		= &maxolduid,
9541da177e4SLinus Torvalds 	},
9551da177e4SLinus Torvalds 	{
9561da177e4SLinus Torvalds 		.ctl_name	= FS_LEASES,
9571da177e4SLinus Torvalds 		.procname	= "leases-enable",
9581da177e4SLinus Torvalds 		.data		= &leases_enable,
9591da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9601da177e4SLinus Torvalds 		.mode		= 0644,
9611da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9621da177e4SLinus Torvalds 	},
9631da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
9641da177e4SLinus Torvalds 	{
9651da177e4SLinus Torvalds 		.ctl_name	= FS_DIR_NOTIFY,
9661da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
9671da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
9681da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9691da177e4SLinus Torvalds 		.mode		= 0644,
9701da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9711da177e4SLinus Torvalds 	},
9721da177e4SLinus Torvalds #endif
9731da177e4SLinus Torvalds #ifdef CONFIG_MMU
9741da177e4SLinus Torvalds 	{
9751da177e4SLinus Torvalds 		.ctl_name	= FS_LEASE_TIME,
9761da177e4SLinus Torvalds 		.procname	= "lease-break-time",
9771da177e4SLinus Torvalds 		.data		= &lease_break_time,
9781da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9791da177e4SLinus Torvalds 		.mode		= 0644,
9801da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9811da177e4SLinus Torvalds 	},
9821da177e4SLinus Torvalds 	{
9831da177e4SLinus Torvalds 		.ctl_name	= FS_AIO_NR,
9841da177e4SLinus Torvalds 		.procname	= "aio-nr",
9851da177e4SLinus Torvalds 		.data		= &aio_nr,
9861da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
9871da177e4SLinus Torvalds 		.mode		= 0444,
988d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
9891da177e4SLinus Torvalds 	},
9901da177e4SLinus Torvalds 	{
9911da177e4SLinus Torvalds 		.ctl_name	= FS_AIO_MAX_NR,
9921da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
9931da177e4SLinus Torvalds 		.data		= &aio_max_nr,
9941da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
9951da177e4SLinus Torvalds 		.mode		= 0644,
996d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
9971da177e4SLinus Torvalds 	},
9980399cb08SRobert Love #ifdef CONFIG_INOTIFY
9990399cb08SRobert Love 	{
10000399cb08SRobert Love 		.ctl_name	= FS_INOTIFY,
10010399cb08SRobert Love 		.procname	= "inotify",
10020399cb08SRobert Love 		.mode		= 0555,
10030399cb08SRobert Love 		.child		= inotify_table,
10040399cb08SRobert Love 	},
10050399cb08SRobert Love #endif
10061da177e4SLinus Torvalds #endif
1007d6e71144SAlan Cox 	{
1008d6e71144SAlan Cox 		.ctl_name	= KERN_SETUID_DUMPABLE,
1009d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1010d6e71144SAlan Cox 		.data		= &suid_dumpable,
1011d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1012d6e71144SAlan Cox 		.mode		= 0644,
1013d6e71144SAlan Cox 		.proc_handler	= &proc_dointvec,
1014d6e71144SAlan Cox 	},
10151da177e4SLinus Torvalds 	{ .ctl_name = 0 }
10161da177e4SLinus Torvalds };
10171da177e4SLinus Torvalds 
10181da177e4SLinus Torvalds static ctl_table debug_table[] = {
10191da177e4SLinus Torvalds 	{ .ctl_name = 0 }
10201da177e4SLinus Torvalds };
10211da177e4SLinus Torvalds 
10221da177e4SLinus Torvalds static ctl_table dev_table[] = {
10231da177e4SLinus Torvalds 	{ .ctl_name = 0 }
10241da177e4SLinus Torvalds };
10251da177e4SLinus Torvalds 
10261da177e4SLinus Torvalds extern void init_irq_proc (void);
10271da177e4SLinus Torvalds 
1028330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1029330d57fbSAl Viro 
1030330d57fbSAl Viro /* called under sysctl_lock */
1031330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1032330d57fbSAl Viro {
1033330d57fbSAl Viro 	if (unlikely(p->unregistering))
1034330d57fbSAl Viro 		return 0;
1035330d57fbSAl Viro 	p->used++;
1036330d57fbSAl Viro 	return 1;
1037330d57fbSAl Viro }
1038330d57fbSAl Viro 
1039330d57fbSAl Viro /* called under sysctl_lock */
1040330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1041330d57fbSAl Viro {
1042330d57fbSAl Viro 	if (!--p->used)
1043330d57fbSAl Viro 		if (unlikely(p->unregistering))
1044330d57fbSAl Viro 			complete(p->unregistering);
1045330d57fbSAl Viro }
1046330d57fbSAl Viro 
1047330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1048330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1049330d57fbSAl Viro {
1050330d57fbSAl Viro 	/*
1051330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1052330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1053330d57fbSAl Viro 	 */
1054330d57fbSAl Viro 	if (unlikely(p->used)) {
1055330d57fbSAl Viro 		struct completion wait;
1056330d57fbSAl Viro 		init_completion(&wait);
1057330d57fbSAl Viro 		p->unregistering = &wait;
1058330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1059330d57fbSAl Viro 		wait_for_completion(&wait);
1060330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1061330d57fbSAl Viro 	}
1062330d57fbSAl Viro 	/*
1063330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1064330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1065330d57fbSAl Viro 	 */
1066330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1067330d57fbSAl Viro }
1068330d57fbSAl Viro 
10691da177e4SLinus Torvalds void __init sysctl_init(void)
10701da177e4SLinus Torvalds {
10711da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
1072330d57fbSAl Viro 	register_proc_table(root_table, proc_sys_root, &root_table_header);
10731da177e4SLinus Torvalds 	init_irq_proc();
10741da177e4SLinus Torvalds #endif
10751da177e4SLinus Torvalds }
10761da177e4SLinus Torvalds 
10771da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
10781da177e4SLinus Torvalds 	       void __user *newval, size_t newlen)
10791da177e4SLinus Torvalds {
10801da177e4SLinus Torvalds 	struct list_head *tmp;
1081330d57fbSAl Viro 	int error = -ENOTDIR;
10821da177e4SLinus Torvalds 
10831da177e4SLinus Torvalds 	if (nlen <= 0 || nlen >= CTL_MAXNAME)
10841da177e4SLinus Torvalds 		return -ENOTDIR;
10851da177e4SLinus Torvalds 	if (oldval) {
10861da177e4SLinus Torvalds 		int old_len;
10871da177e4SLinus Torvalds 		if (!oldlenp || get_user(old_len, oldlenp))
10881da177e4SLinus Torvalds 			return -EFAULT;
10891da177e4SLinus Torvalds 	}
1090330d57fbSAl Viro 	spin_lock(&sysctl_lock);
10911da177e4SLinus Torvalds 	tmp = &root_table_header.ctl_entry;
10921da177e4SLinus Torvalds 	do {
10931da177e4SLinus Torvalds 		struct ctl_table_header *head =
10941da177e4SLinus Torvalds 			list_entry(tmp, struct ctl_table_header, ctl_entry);
10951da177e4SLinus Torvalds 		void *context = NULL;
1096330d57fbSAl Viro 
1097330d57fbSAl Viro 		if (!use_table(head))
1098330d57fbSAl Viro 			continue;
1099330d57fbSAl Viro 
1100330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1101330d57fbSAl Viro 
1102330d57fbSAl Viro 		error = parse_table(name, nlen, oldval, oldlenp,
11031da177e4SLinus Torvalds 					newval, newlen, head->ctl_table,
11041da177e4SLinus Torvalds 					&context);
11051da177e4SLinus Torvalds 		kfree(context);
1106330d57fbSAl Viro 
1107330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1108330d57fbSAl Viro 		unuse_table(head);
11091da177e4SLinus Torvalds 		if (error != -ENOTDIR)
1110330d57fbSAl Viro 			break;
1111330d57fbSAl Viro 	} while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1112330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
11131da177e4SLinus Torvalds 	return error;
11141da177e4SLinus Torvalds }
11151da177e4SLinus Torvalds 
11161da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
11171da177e4SLinus Torvalds {
11181da177e4SLinus Torvalds 	struct __sysctl_args tmp;
11191da177e4SLinus Torvalds 	int error;
11201da177e4SLinus Torvalds 
11211da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
11221da177e4SLinus Torvalds 		return -EFAULT;
11231da177e4SLinus Torvalds 
11241da177e4SLinus Torvalds 	lock_kernel();
11251da177e4SLinus Torvalds 	error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
11261da177e4SLinus Torvalds 			  tmp.newval, tmp.newlen);
11271da177e4SLinus Torvalds 	unlock_kernel();
11281da177e4SLinus Torvalds 	return error;
11291da177e4SLinus Torvalds }
11301da177e4SLinus Torvalds 
11311da177e4SLinus Torvalds /*
11321da177e4SLinus Torvalds  * ctl_perm does NOT grant the superuser all rights automatically, because
11331da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
11341da177e4SLinus Torvalds  */
11351da177e4SLinus Torvalds 
11361da177e4SLinus Torvalds static int test_perm(int mode, int op)
11371da177e4SLinus Torvalds {
11381da177e4SLinus Torvalds 	if (!current->euid)
11391da177e4SLinus Torvalds 		mode >>= 6;
11401da177e4SLinus Torvalds 	else if (in_egroup_p(0))
11411da177e4SLinus Torvalds 		mode >>= 3;
11421da177e4SLinus Torvalds 	if ((mode & op & 0007) == op)
11431da177e4SLinus Torvalds 		return 0;
11441da177e4SLinus Torvalds 	return -EACCES;
11451da177e4SLinus Torvalds }
11461da177e4SLinus Torvalds 
11471da177e4SLinus Torvalds static inline int ctl_perm(ctl_table *table, int op)
11481da177e4SLinus Torvalds {
11491da177e4SLinus Torvalds 	int error;
11501da177e4SLinus Torvalds 	error = security_sysctl(table, op);
11511da177e4SLinus Torvalds 	if (error)
11521da177e4SLinus Torvalds 		return error;
11531da177e4SLinus Torvalds 	return test_perm(table->mode, op);
11541da177e4SLinus Torvalds }
11551da177e4SLinus Torvalds 
11561da177e4SLinus Torvalds static int parse_table(int __user *name, int nlen,
11571da177e4SLinus Torvalds 		       void __user *oldval, size_t __user *oldlenp,
11581da177e4SLinus Torvalds 		       void __user *newval, size_t newlen,
11591da177e4SLinus Torvalds 		       ctl_table *table, void **context)
11601da177e4SLinus Torvalds {
11611da177e4SLinus Torvalds 	int n;
11621da177e4SLinus Torvalds repeat:
11631da177e4SLinus Torvalds 	if (!nlen)
11641da177e4SLinus Torvalds 		return -ENOTDIR;
11651da177e4SLinus Torvalds 	if (get_user(n, name))
11661da177e4SLinus Torvalds 		return -EFAULT;
11671da177e4SLinus Torvalds 	for ( ; table->ctl_name; table++) {
11681da177e4SLinus Torvalds 		if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
11691da177e4SLinus Torvalds 			int error;
11701da177e4SLinus Torvalds 			if (table->child) {
11711da177e4SLinus Torvalds 				if (ctl_perm(table, 001))
11721da177e4SLinus Torvalds 					return -EPERM;
11731da177e4SLinus Torvalds 				if (table->strategy) {
11741da177e4SLinus Torvalds 					error = table->strategy(
11751da177e4SLinus Torvalds 						table, name, nlen,
11761da177e4SLinus Torvalds 						oldval, oldlenp,
11771da177e4SLinus Torvalds 						newval, newlen, context);
11781da177e4SLinus Torvalds 					if (error)
11791da177e4SLinus Torvalds 						return error;
11801da177e4SLinus Torvalds 				}
11811da177e4SLinus Torvalds 				name++;
11821da177e4SLinus Torvalds 				nlen--;
11831da177e4SLinus Torvalds 				table = table->child;
11841da177e4SLinus Torvalds 				goto repeat;
11851da177e4SLinus Torvalds 			}
11861da177e4SLinus Torvalds 			error = do_sysctl_strategy(table, name, nlen,
11871da177e4SLinus Torvalds 						   oldval, oldlenp,
11881da177e4SLinus Torvalds 						   newval, newlen, context);
11891da177e4SLinus Torvalds 			return error;
11901da177e4SLinus Torvalds 		}
11911da177e4SLinus Torvalds 	}
11921da177e4SLinus Torvalds 	return -ENOTDIR;
11931da177e4SLinus Torvalds }
11941da177e4SLinus Torvalds 
11951da177e4SLinus Torvalds /* Perform the actual read/write of a sysctl table entry. */
11961da177e4SLinus Torvalds int do_sysctl_strategy (ctl_table *table,
11971da177e4SLinus Torvalds 			int __user *name, int nlen,
11981da177e4SLinus Torvalds 			void __user *oldval, size_t __user *oldlenp,
11991da177e4SLinus Torvalds 			void __user *newval, size_t newlen, void **context)
12001da177e4SLinus Torvalds {
12011da177e4SLinus Torvalds 	int op = 0, rc;
12021da177e4SLinus Torvalds 	size_t len;
12031da177e4SLinus Torvalds 
12041da177e4SLinus Torvalds 	if (oldval)
12051da177e4SLinus Torvalds 		op |= 004;
12061da177e4SLinus Torvalds 	if (newval)
12071da177e4SLinus Torvalds 		op |= 002;
12081da177e4SLinus Torvalds 	if (ctl_perm(table, op))
12091da177e4SLinus Torvalds 		return -EPERM;
12101da177e4SLinus Torvalds 
12111da177e4SLinus Torvalds 	if (table->strategy) {
12121da177e4SLinus Torvalds 		rc = table->strategy(table, name, nlen, oldval, oldlenp,
12131da177e4SLinus Torvalds 				     newval, newlen, context);
12141da177e4SLinus Torvalds 		if (rc < 0)
12151da177e4SLinus Torvalds 			return rc;
12161da177e4SLinus Torvalds 		if (rc > 0)
12171da177e4SLinus Torvalds 			return 0;
12181da177e4SLinus Torvalds 	}
12191da177e4SLinus Torvalds 
12201da177e4SLinus Torvalds 	/* If there is no strategy routine, or if the strategy returns
12211da177e4SLinus Torvalds 	 * zero, proceed with automatic r/w */
12221da177e4SLinus Torvalds 	if (table->data && table->maxlen) {
12231da177e4SLinus Torvalds 		if (oldval && oldlenp) {
12241da177e4SLinus Torvalds 			if (get_user(len, oldlenp))
12251da177e4SLinus Torvalds 				return -EFAULT;
12261da177e4SLinus Torvalds 			if (len) {
12271da177e4SLinus Torvalds 				if (len > table->maxlen)
12281da177e4SLinus Torvalds 					len = table->maxlen;
12291da177e4SLinus Torvalds 				if(copy_to_user(oldval, table->data, len))
12301da177e4SLinus Torvalds 					return -EFAULT;
12311da177e4SLinus Torvalds 				if(put_user(len, oldlenp))
12321da177e4SLinus Torvalds 					return -EFAULT;
12331da177e4SLinus Torvalds 			}
12341da177e4SLinus Torvalds 		}
12351da177e4SLinus Torvalds 		if (newval && newlen) {
12361da177e4SLinus Torvalds 			len = newlen;
12371da177e4SLinus Torvalds 			if (len > table->maxlen)
12381da177e4SLinus Torvalds 				len = table->maxlen;
12391da177e4SLinus Torvalds 			if(copy_from_user(table->data, newval, len))
12401da177e4SLinus Torvalds 				return -EFAULT;
12411da177e4SLinus Torvalds 		}
12421da177e4SLinus Torvalds 	}
12431da177e4SLinus Torvalds 	return 0;
12441da177e4SLinus Torvalds }
12451da177e4SLinus Torvalds 
12461da177e4SLinus Torvalds /**
12471da177e4SLinus Torvalds  * register_sysctl_table - register a sysctl hierarchy
12481da177e4SLinus Torvalds  * @table: the top-level table structure
12491da177e4SLinus Torvalds  * @insert_at_head: whether the entry should be inserted in front or at the end
12501da177e4SLinus Torvalds  *
12511da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
12521da177e4SLinus Torvalds  * array. An entry with a ctl_name of 0 terminates the table.
12531da177e4SLinus Torvalds  *
12541da177e4SLinus Torvalds  * The members of the &ctl_table structure are used as follows:
12551da177e4SLinus Torvalds  *
12561da177e4SLinus Torvalds  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
12571da177e4SLinus Torvalds  *            must be unique within that level of sysctl
12581da177e4SLinus Torvalds  *
12591da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
12601da177e4SLinus Torvalds  *            enter a sysctl file
12611da177e4SLinus Torvalds  *
12621da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
12631da177e4SLinus Torvalds  *
12641da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
12651da177e4SLinus Torvalds  *
12661da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
12671da177e4SLinus Torvalds  *
12681da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
12691da177e4SLinus Torvalds  *         %NULL.
12701da177e4SLinus Torvalds  *
12711da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
12721da177e4SLinus Torvalds  *
12731da177e4SLinus Torvalds  * strategy - the strategy routine (described below)
12741da177e4SLinus Torvalds  *
12751da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
12761da177e4SLinus Torvalds  *
12771da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
12781da177e4SLinus Torvalds  *
12791da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
12801da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
12811da177e4SLinus Torvalds  *
12821da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
12831da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
12841da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
12851da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
12861da177e4SLinus Torvalds  *
12871da177e4SLinus Torvalds  * More sophisticated management can be enabled by the provision of a
12881da177e4SLinus Torvalds  * strategy routine with the table entry.  This will be called before
12891da177e4SLinus Torvalds  * any automatic read or write of the data is performed.
12901da177e4SLinus Torvalds  *
12911da177e4SLinus Torvalds  * The strategy routine may return
12921da177e4SLinus Torvalds  *
12931da177e4SLinus Torvalds  * < 0 - Error occurred (error is passed to user process)
12941da177e4SLinus Torvalds  *
12951da177e4SLinus Torvalds  * 0   - OK - proceed with automatic read or write.
12961da177e4SLinus Torvalds  *
12971da177e4SLinus Torvalds  * > 0 - OK - read or write has been done by the strategy routine, so
12981da177e4SLinus Torvalds  *       return immediately.
12991da177e4SLinus Torvalds  *
13001da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
13011da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
13021da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
13031da177e4SLinus Torvalds  * cover common cases -
13041da177e4SLinus Torvalds  *
13051da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
13061da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
13071da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
13081da177e4SLinus Torvalds  *
13091da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
13101da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
13111da177e4SLinus Torvalds  *
13121da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
13131da177e4SLinus Torvalds  * to the table header on success.
13141da177e4SLinus Torvalds  */
13151da177e4SLinus Torvalds struct ctl_table_header *register_sysctl_table(ctl_table * table,
13161da177e4SLinus Torvalds 					       int insert_at_head)
13171da177e4SLinus Torvalds {
13181da177e4SLinus Torvalds 	struct ctl_table_header *tmp;
13191da177e4SLinus Torvalds 	tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
13201da177e4SLinus Torvalds 	if (!tmp)
13211da177e4SLinus Torvalds 		return NULL;
13221da177e4SLinus Torvalds 	tmp->ctl_table = table;
13231da177e4SLinus Torvalds 	INIT_LIST_HEAD(&tmp->ctl_entry);
1324330d57fbSAl Viro 	tmp->used = 0;
1325330d57fbSAl Viro 	tmp->unregistering = NULL;
1326330d57fbSAl Viro 	spin_lock(&sysctl_lock);
13271da177e4SLinus Torvalds 	if (insert_at_head)
13281da177e4SLinus Torvalds 		list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
13291da177e4SLinus Torvalds 	else
13301da177e4SLinus Torvalds 		list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1331330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
13321da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
1333330d57fbSAl Viro 	register_proc_table(table, proc_sys_root, tmp);
13341da177e4SLinus Torvalds #endif
13351da177e4SLinus Torvalds 	return tmp;
13361da177e4SLinus Torvalds }
13371da177e4SLinus Torvalds 
13381da177e4SLinus Torvalds /**
13391da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
13401da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
13411da177e4SLinus Torvalds  *
13421da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
13431da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
13441da177e4SLinus Torvalds  */
13451da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
13461da177e4SLinus Torvalds {
1347330d57fbSAl Viro 	might_sleep();
1348330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1349330d57fbSAl Viro 	start_unregistering(header);
13501da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
13511da177e4SLinus Torvalds 	unregister_proc_table(header->ctl_table, proc_sys_root);
13521da177e4SLinus Torvalds #endif
1353330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
13541da177e4SLinus Torvalds 	kfree(header);
13551da177e4SLinus Torvalds }
13561da177e4SLinus Torvalds 
13571da177e4SLinus Torvalds /*
13581da177e4SLinus Torvalds  * /proc/sys support
13591da177e4SLinus Torvalds  */
13601da177e4SLinus Torvalds 
13611da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS
13621da177e4SLinus Torvalds 
13631da177e4SLinus Torvalds /* Scan the sysctl entries in table and add them all into /proc */
1364330d57fbSAl Viro static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
13651da177e4SLinus Torvalds {
13661da177e4SLinus Torvalds 	struct proc_dir_entry *de;
13671da177e4SLinus Torvalds 	int len;
13681da177e4SLinus Torvalds 	mode_t mode;
13691da177e4SLinus Torvalds 
13701da177e4SLinus Torvalds 	for (; table->ctl_name; table++) {
13711da177e4SLinus Torvalds 		/* Can't do anything without a proc name. */
13721da177e4SLinus Torvalds 		if (!table->procname)
13731da177e4SLinus Torvalds 			continue;
13741da177e4SLinus Torvalds 		/* Maybe we can't do anything with it... */
13751da177e4SLinus Torvalds 		if (!table->proc_handler && !table->child) {
13761da177e4SLinus Torvalds 			printk(KERN_WARNING "SYSCTL: Can't register %s\n",
13771da177e4SLinus Torvalds 				table->procname);
13781da177e4SLinus Torvalds 			continue;
13791da177e4SLinus Torvalds 		}
13801da177e4SLinus Torvalds 
13811da177e4SLinus Torvalds 		len = strlen(table->procname);
13821da177e4SLinus Torvalds 		mode = table->mode;
13831da177e4SLinus Torvalds 
13841da177e4SLinus Torvalds 		de = NULL;
13851da177e4SLinus Torvalds 		if (table->proc_handler)
13861da177e4SLinus Torvalds 			mode |= S_IFREG;
13871da177e4SLinus Torvalds 		else {
13881da177e4SLinus Torvalds 			mode |= S_IFDIR;
13891da177e4SLinus Torvalds 			for (de = root->subdir; de; de = de->next) {
13901da177e4SLinus Torvalds 				if (proc_match(len, table->procname, de))
13911da177e4SLinus Torvalds 					break;
13921da177e4SLinus Torvalds 			}
13931da177e4SLinus Torvalds 			/* If the subdir exists already, de is non-NULL */
13941da177e4SLinus Torvalds 		}
13951da177e4SLinus Torvalds 
13961da177e4SLinus Torvalds 		if (!de) {
13971da177e4SLinus Torvalds 			de = create_proc_entry(table->procname, mode, root);
13981da177e4SLinus Torvalds 			if (!de)
13991da177e4SLinus Torvalds 				continue;
1400330d57fbSAl Viro 			de->set = set;
14011da177e4SLinus Torvalds 			de->data = (void *) table;
14021da177e4SLinus Torvalds 			if (table->proc_handler)
14031da177e4SLinus Torvalds 				de->proc_fops = &proc_sys_file_operations;
14041da177e4SLinus Torvalds 		}
14051da177e4SLinus Torvalds 		table->de = de;
14061da177e4SLinus Torvalds 		if (de->mode & S_IFDIR)
1407330d57fbSAl Viro 			register_proc_table(table->child, de, set);
14081da177e4SLinus Torvalds 	}
14091da177e4SLinus Torvalds }
14101da177e4SLinus Torvalds 
14111da177e4SLinus Torvalds /*
14121da177e4SLinus Torvalds  * Unregister a /proc sysctl table and any subdirectories.
14131da177e4SLinus Torvalds  */
14141da177e4SLinus Torvalds static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
14151da177e4SLinus Torvalds {
14161da177e4SLinus Torvalds 	struct proc_dir_entry *de;
14171da177e4SLinus Torvalds 	for (; table->ctl_name; table++) {
14181da177e4SLinus Torvalds 		if (!(de = table->de))
14191da177e4SLinus Torvalds 			continue;
14201da177e4SLinus Torvalds 		if (de->mode & S_IFDIR) {
14211da177e4SLinus Torvalds 			if (!table->child) {
14221da177e4SLinus Torvalds 				printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
14231da177e4SLinus Torvalds 				continue;
14241da177e4SLinus Torvalds 			}
14251da177e4SLinus Torvalds 			unregister_proc_table(table->child, de);
14261da177e4SLinus Torvalds 
14271da177e4SLinus Torvalds 			/* Don't unregister directories which still have entries.. */
14281da177e4SLinus Torvalds 			if (de->subdir)
14291da177e4SLinus Torvalds 				continue;
14301da177e4SLinus Torvalds 		}
14311da177e4SLinus Torvalds 
1432330d57fbSAl Viro 		/*
1433330d57fbSAl Viro 		 * In any case, mark the entry as goner; we'll keep it
1434330d57fbSAl Viro 		 * around if it's busy, but we'll know to do nothing with
1435330d57fbSAl Viro 		 * its fields.  We are under sysctl_lock here.
1436330d57fbSAl Viro 		 */
1437330d57fbSAl Viro 		de->data = NULL;
1438330d57fbSAl Viro 
14391da177e4SLinus Torvalds 		/* Don't unregister proc entries that are still being used.. */
14401da177e4SLinus Torvalds 		if (atomic_read(&de->count))
14411da177e4SLinus Torvalds 			continue;
14421da177e4SLinus Torvalds 
14431da177e4SLinus Torvalds 		table->de = NULL;
14441da177e4SLinus Torvalds 		remove_proc_entry(table->procname, root);
14451da177e4SLinus Torvalds 	}
14461da177e4SLinus Torvalds }
14471da177e4SLinus Torvalds 
14481da177e4SLinus Torvalds static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
14491da177e4SLinus Torvalds 			  size_t count, loff_t *ppos)
14501da177e4SLinus Torvalds {
14511da177e4SLinus Torvalds 	int op;
1452330d57fbSAl Viro 	struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
14531da177e4SLinus Torvalds 	struct ctl_table *table;
14541da177e4SLinus Torvalds 	size_t res;
1455330d57fbSAl Viro 	ssize_t error = -ENOTDIR;
14561da177e4SLinus Torvalds 
1457330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1458330d57fbSAl Viro 	if (de && de->data && use_table(de->set)) {
1459330d57fbSAl Viro 		/*
1460330d57fbSAl Viro 		 * at that point we know that sysctl was not unregistered
1461330d57fbSAl Viro 		 * and won't be until we finish
1462330d57fbSAl Viro 		 */
1463330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
14641da177e4SLinus Torvalds 		table = (struct ctl_table *) de->data;
14651da177e4SLinus Torvalds 		if (!table || !table->proc_handler)
1466330d57fbSAl Viro 			goto out;
1467330d57fbSAl Viro 		error = -EPERM;
14681da177e4SLinus Torvalds 		op = (write ? 002 : 004);
14691da177e4SLinus Torvalds 		if (ctl_perm(table, op))
1470330d57fbSAl Viro 			goto out;
14711da177e4SLinus Torvalds 
1472330d57fbSAl Viro 		/* careful: calling conventions are nasty here */
14731da177e4SLinus Torvalds 		res = count;
1474330d57fbSAl Viro 		error = (*table->proc_handler)(table, write, file,
1475330d57fbSAl Viro 						buf, &res, ppos);
1476330d57fbSAl Viro 		if (!error)
1477330d57fbSAl Viro 			error = res;
1478330d57fbSAl Viro 	out:
1479330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1480330d57fbSAl Viro 		unuse_table(de->set);
1481330d57fbSAl Viro 	}
1482330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
14831da177e4SLinus Torvalds 	return error;
14841da177e4SLinus Torvalds }
14851da177e4SLinus Torvalds 
14861da177e4SLinus Torvalds static int proc_opensys(struct inode *inode, struct file *file)
14871da177e4SLinus Torvalds {
14881da177e4SLinus Torvalds 	if (file->f_mode & FMODE_WRITE) {
14891da177e4SLinus Torvalds 		/*
14901da177e4SLinus Torvalds 		 * sysctl entries that are not writable,
14911da177e4SLinus Torvalds 		 * are _NOT_ writable, capabilities or not.
14921da177e4SLinus Torvalds 		 */
14931da177e4SLinus Torvalds 		if (!(inode->i_mode & S_IWUSR))
14941da177e4SLinus Torvalds 			return -EPERM;
14951da177e4SLinus Torvalds 	}
14961da177e4SLinus Torvalds 
14971da177e4SLinus Torvalds 	return 0;
14981da177e4SLinus Torvalds }
14991da177e4SLinus Torvalds 
15001da177e4SLinus Torvalds static ssize_t proc_readsys(struct file * file, char __user * buf,
15011da177e4SLinus Torvalds 			    size_t count, loff_t *ppos)
15021da177e4SLinus Torvalds {
15031da177e4SLinus Torvalds 	return do_rw_proc(0, file, buf, count, ppos);
15041da177e4SLinus Torvalds }
15051da177e4SLinus Torvalds 
15061da177e4SLinus Torvalds static ssize_t proc_writesys(struct file * file, const char __user * buf,
15071da177e4SLinus Torvalds 			     size_t count, loff_t *ppos)
15081da177e4SLinus Torvalds {
15091da177e4SLinus Torvalds 	return do_rw_proc(1, file, (char __user *) buf, count, ppos);
15101da177e4SLinus Torvalds }
15111da177e4SLinus Torvalds 
15121da177e4SLinus Torvalds /**
15131da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
15141da177e4SLinus Torvalds  * @table: the sysctl table
15151da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
15161da177e4SLinus Torvalds  * @filp: the file structure
15171da177e4SLinus Torvalds  * @buffer: the user buffer
15181da177e4SLinus Torvalds  * @lenp: the size of the user buffer
15191da177e4SLinus Torvalds  * @ppos: file position
15201da177e4SLinus Torvalds  *
15211da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
15221da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
15231da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
15241da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
15251da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
15261da177e4SLinus Torvalds  * not large enough.
15271da177e4SLinus Torvalds  *
15281da177e4SLinus Torvalds  * Returns 0 on success.
15291da177e4SLinus Torvalds  */
15301da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
15311da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
15321da177e4SLinus Torvalds {
15331da177e4SLinus Torvalds 	size_t len;
15341da177e4SLinus Torvalds 	char __user *p;
15351da177e4SLinus Torvalds 	char c;
15361da177e4SLinus Torvalds 
15371da177e4SLinus Torvalds 	if (!table->data || !table->maxlen || !*lenp ||
15381da177e4SLinus Torvalds 	    (*ppos && !write)) {
15391da177e4SLinus Torvalds 		*lenp = 0;
15401da177e4SLinus Torvalds 		return 0;
15411da177e4SLinus Torvalds 	}
15421da177e4SLinus Torvalds 
15431da177e4SLinus Torvalds 	if (write) {
15441da177e4SLinus Torvalds 		len = 0;
15451da177e4SLinus Torvalds 		p = buffer;
15461da177e4SLinus Torvalds 		while (len < *lenp) {
15471da177e4SLinus Torvalds 			if (get_user(c, p++))
15481da177e4SLinus Torvalds 				return -EFAULT;
15491da177e4SLinus Torvalds 			if (c == 0 || c == '\n')
15501da177e4SLinus Torvalds 				break;
15511da177e4SLinus Torvalds 			len++;
15521da177e4SLinus Torvalds 		}
15531da177e4SLinus Torvalds 		if (len >= table->maxlen)
15541da177e4SLinus Torvalds 			len = table->maxlen-1;
15551da177e4SLinus Torvalds 		if(copy_from_user(table->data, buffer, len))
15561da177e4SLinus Torvalds 			return -EFAULT;
15571da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
15581da177e4SLinus Torvalds 		*ppos += *lenp;
15591da177e4SLinus Torvalds 	} else {
15601da177e4SLinus Torvalds 		len = strlen(table->data);
15611da177e4SLinus Torvalds 		if (len > table->maxlen)
15621da177e4SLinus Torvalds 			len = table->maxlen;
15631da177e4SLinus Torvalds 		if (len > *lenp)
15641da177e4SLinus Torvalds 			len = *lenp;
15651da177e4SLinus Torvalds 		if (len)
15661da177e4SLinus Torvalds 			if(copy_to_user(buffer, table->data, len))
15671da177e4SLinus Torvalds 				return -EFAULT;
15681da177e4SLinus Torvalds 		if (len < *lenp) {
15691da177e4SLinus Torvalds 			if(put_user('\n', ((char __user *) buffer) + len))
15701da177e4SLinus Torvalds 				return -EFAULT;
15711da177e4SLinus Torvalds 			len++;
15721da177e4SLinus Torvalds 		}
15731da177e4SLinus Torvalds 		*lenp = len;
15741da177e4SLinus Torvalds 		*ppos += len;
15751da177e4SLinus Torvalds 	}
15761da177e4SLinus Torvalds 	return 0;
15771da177e4SLinus Torvalds }
15781da177e4SLinus Torvalds 
15791da177e4SLinus Torvalds /*
15801da177e4SLinus Torvalds  *	Special case of dostring for the UTS structure. This has locks
15811da177e4SLinus Torvalds  *	to observe. Should this be in kernel/sys.c ????
15821da177e4SLinus Torvalds  */
15831da177e4SLinus Torvalds 
15841da177e4SLinus Torvalds static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
15851da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
15861da177e4SLinus Torvalds {
15871da177e4SLinus Torvalds 	int r;
15881da177e4SLinus Torvalds 
15891da177e4SLinus Torvalds 	if (!write) {
15901da177e4SLinus Torvalds 		down_read(&uts_sem);
15911da177e4SLinus Torvalds 		r=proc_dostring(table,0,filp,buffer,lenp, ppos);
15921da177e4SLinus Torvalds 		up_read(&uts_sem);
15931da177e4SLinus Torvalds 	} else {
15941da177e4SLinus Torvalds 		down_write(&uts_sem);
15951da177e4SLinus Torvalds 		r=proc_dostring(table,1,filp,buffer,lenp, ppos);
15961da177e4SLinus Torvalds 		up_write(&uts_sem);
15971da177e4SLinus Torvalds 	}
15981da177e4SLinus Torvalds 	return r;
15991da177e4SLinus Torvalds }
16001da177e4SLinus Torvalds 
16011da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
16021da177e4SLinus Torvalds 				 int *valp,
16031da177e4SLinus Torvalds 				 int write, void *data)
16041da177e4SLinus Torvalds {
16051da177e4SLinus Torvalds 	if (write) {
16061da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
16071da177e4SLinus Torvalds 	} else {
16081da177e4SLinus Torvalds 		int val = *valp;
16091da177e4SLinus Torvalds 		if (val < 0) {
16101da177e4SLinus Torvalds 			*negp = -1;
16111da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
16121da177e4SLinus Torvalds 		} else {
16131da177e4SLinus Torvalds 			*negp = 0;
16141da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
16151da177e4SLinus Torvalds 		}
16161da177e4SLinus Torvalds 	}
16171da177e4SLinus Torvalds 	return 0;
16181da177e4SLinus Torvalds }
16191da177e4SLinus Torvalds 
16201da177e4SLinus Torvalds static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
16211da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos,
16221da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
16231da177e4SLinus Torvalds 			      int write, void *data),
16241da177e4SLinus Torvalds 		  void *data)
16251da177e4SLinus Torvalds {
16261da177e4SLinus Torvalds #define TMPBUFLEN 21
16271da177e4SLinus Torvalds 	int *i, vleft, first=1, neg, val;
16281da177e4SLinus Torvalds 	unsigned long lval;
16291da177e4SLinus Torvalds 	size_t left, len;
16301da177e4SLinus Torvalds 
16311da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
16321da177e4SLinus Torvalds 	char __user *s = buffer;
16331da177e4SLinus Torvalds 
16341da177e4SLinus Torvalds 	if (!table->data || !table->maxlen || !*lenp ||
16351da177e4SLinus Torvalds 	    (*ppos && !write)) {
16361da177e4SLinus Torvalds 		*lenp = 0;
16371da177e4SLinus Torvalds 		return 0;
16381da177e4SLinus Torvalds 	}
16391da177e4SLinus Torvalds 
16401da177e4SLinus Torvalds 	i = (int *) table->data;
16411da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
16421da177e4SLinus Torvalds 	left = *lenp;
16431da177e4SLinus Torvalds 
16441da177e4SLinus Torvalds 	if (!conv)
16451da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
16461da177e4SLinus Torvalds 
16471da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
16481da177e4SLinus Torvalds 		if (write) {
16491da177e4SLinus Torvalds 			while (left) {
16501da177e4SLinus Torvalds 				char c;
16511da177e4SLinus Torvalds 				if (get_user(c, s))
16521da177e4SLinus Torvalds 					return -EFAULT;
16531da177e4SLinus Torvalds 				if (!isspace(c))
16541da177e4SLinus Torvalds 					break;
16551da177e4SLinus Torvalds 				left--;
16561da177e4SLinus Torvalds 				s++;
16571da177e4SLinus Torvalds 			}
16581da177e4SLinus Torvalds 			if (!left)
16591da177e4SLinus Torvalds 				break;
16601da177e4SLinus Torvalds 			neg = 0;
16611da177e4SLinus Torvalds 			len = left;
16621da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
16631da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
16641da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
16651da177e4SLinus Torvalds 				return -EFAULT;
16661da177e4SLinus Torvalds 			buf[len] = 0;
16671da177e4SLinus Torvalds 			p = buf;
16681da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
16691da177e4SLinus Torvalds 				neg = 1;
16701da177e4SLinus Torvalds 				left--, p++;
16711da177e4SLinus Torvalds 			}
16721da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
16731da177e4SLinus Torvalds 				break;
16741da177e4SLinus Torvalds 
16751da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
16761da177e4SLinus Torvalds 
16771da177e4SLinus Torvalds 			len = p-buf;
16781da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
16791da177e4SLinus Torvalds 				break;
16801da177e4SLinus Torvalds 			if (neg)
16811da177e4SLinus Torvalds 				val = -val;
16821da177e4SLinus Torvalds 			s += len;
16831da177e4SLinus Torvalds 			left -= len;
16841da177e4SLinus Torvalds 
16851da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
16861da177e4SLinus Torvalds 				break;
16871da177e4SLinus Torvalds 		} else {
16881da177e4SLinus Torvalds 			p = buf;
16891da177e4SLinus Torvalds 			if (!first)
16901da177e4SLinus Torvalds 				*p++ = '\t';
16911da177e4SLinus Torvalds 
16921da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
16931da177e4SLinus Torvalds 				break;
16941da177e4SLinus Torvalds 
16951da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
16961da177e4SLinus Torvalds 			len = strlen(buf);
16971da177e4SLinus Torvalds 			if (len > left)
16981da177e4SLinus Torvalds 				len = left;
16991da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
17001da177e4SLinus Torvalds 				return -EFAULT;
17011da177e4SLinus Torvalds 			left -= len;
17021da177e4SLinus Torvalds 			s += len;
17031da177e4SLinus Torvalds 		}
17041da177e4SLinus Torvalds 	}
17051da177e4SLinus Torvalds 
17061da177e4SLinus Torvalds 	if (!write && !first && left) {
17071da177e4SLinus Torvalds 		if(put_user('\n', s))
17081da177e4SLinus Torvalds 			return -EFAULT;
17091da177e4SLinus Torvalds 		left--, s++;
17101da177e4SLinus Torvalds 	}
17111da177e4SLinus Torvalds 	if (write) {
17121da177e4SLinus Torvalds 		while (left) {
17131da177e4SLinus Torvalds 			char c;
17141da177e4SLinus Torvalds 			if (get_user(c, s++))
17151da177e4SLinus Torvalds 				return -EFAULT;
17161da177e4SLinus Torvalds 			if (!isspace(c))
17171da177e4SLinus Torvalds 				break;
17181da177e4SLinus Torvalds 			left--;
17191da177e4SLinus Torvalds 		}
17201da177e4SLinus Torvalds 	}
17211da177e4SLinus Torvalds 	if (write && first)
17221da177e4SLinus Torvalds 		return -EINVAL;
17231da177e4SLinus Torvalds 	*lenp -= left;
17241da177e4SLinus Torvalds 	*ppos += *lenp;
17251da177e4SLinus Torvalds 	return 0;
17261da177e4SLinus Torvalds #undef TMPBUFLEN
17271da177e4SLinus Torvalds }
17281da177e4SLinus Torvalds 
17291da177e4SLinus Torvalds /**
17301da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
17311da177e4SLinus Torvalds  * @table: the sysctl table
17321da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
17331da177e4SLinus Torvalds  * @filp: the file structure
17341da177e4SLinus Torvalds  * @buffer: the user buffer
17351da177e4SLinus Torvalds  * @lenp: the size of the user buffer
17361da177e4SLinus Torvalds  * @ppos: file position
17371da177e4SLinus Torvalds  *
17381da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
17391da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
17401da177e4SLinus Torvalds  *
17411da177e4SLinus Torvalds  * Returns 0 on success.
17421da177e4SLinus Torvalds  */
17431da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
17441da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
17451da177e4SLinus Torvalds {
17461da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
17471da177e4SLinus Torvalds 		    	    NULL,NULL);
17481da177e4SLinus Torvalds }
17491da177e4SLinus Torvalds 
17501da177e4SLinus Torvalds #define OP_SET	0
17511da177e4SLinus Torvalds #define OP_AND	1
17521da177e4SLinus Torvalds #define OP_OR	2
17531da177e4SLinus Torvalds #define OP_MAX	3
17541da177e4SLinus Torvalds #define OP_MIN	4
17551da177e4SLinus Torvalds 
17561da177e4SLinus Torvalds static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
17571da177e4SLinus Torvalds 				      int *valp,
17581da177e4SLinus Torvalds 				      int write, void *data)
17591da177e4SLinus Torvalds {
17601da177e4SLinus Torvalds 	int op = *(int *)data;
17611da177e4SLinus Torvalds 	if (write) {
17621da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
17631da177e4SLinus Torvalds 		switch(op) {
17641da177e4SLinus Torvalds 		case OP_SET:	*valp = val; break;
17651da177e4SLinus Torvalds 		case OP_AND:	*valp &= val; break;
17661da177e4SLinus Torvalds 		case OP_OR:	*valp |= val; break;
17671da177e4SLinus Torvalds 		case OP_MAX:	if(*valp < val)
17681da177e4SLinus Torvalds 					*valp = val;
17691da177e4SLinus Torvalds 				break;
17701da177e4SLinus Torvalds 		case OP_MIN:	if(*valp > val)
17711da177e4SLinus Torvalds 				*valp = val;
17721da177e4SLinus Torvalds 				break;
17731da177e4SLinus Torvalds 		}
17741da177e4SLinus Torvalds 	} else {
17751da177e4SLinus Torvalds 		int val = *valp;
17761da177e4SLinus Torvalds 		if (val < 0) {
17771da177e4SLinus Torvalds 			*negp = -1;
17781da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
17791da177e4SLinus Torvalds 		} else {
17801da177e4SLinus Torvalds 			*negp = 0;
17811da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
17821da177e4SLinus Torvalds 		}
17831da177e4SLinus Torvalds 	}
17841da177e4SLinus Torvalds 	return 0;
17851da177e4SLinus Torvalds }
17861da177e4SLinus Torvalds 
17871da177e4SLinus Torvalds /*
17881da177e4SLinus Torvalds  *	init may raise the set.
17891da177e4SLinus Torvalds  */
17901da177e4SLinus Torvalds 
17911da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
17921da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
17931da177e4SLinus Torvalds {
17941da177e4SLinus Torvalds 	int op;
17951da177e4SLinus Torvalds 
17961da177e4SLinus Torvalds 	if (!capable(CAP_SYS_MODULE)) {
17971da177e4SLinus Torvalds 		return -EPERM;
17981da177e4SLinus Torvalds 	}
17991da177e4SLinus Torvalds 
18001da177e4SLinus Torvalds 	op = (current->pid == 1) ? OP_SET : OP_AND;
18011da177e4SLinus Torvalds 	return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
18021da177e4SLinus Torvalds 				do_proc_dointvec_bset_conv,&op);
18031da177e4SLinus Torvalds }
18041da177e4SLinus Torvalds 
18051da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
18061da177e4SLinus Torvalds 	int *min;
18071da177e4SLinus Torvalds 	int *max;
18081da177e4SLinus Torvalds };
18091da177e4SLinus Torvalds 
18101da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
18111da177e4SLinus Torvalds 					int *valp,
18121da177e4SLinus Torvalds 					int write, void *data)
18131da177e4SLinus Torvalds {
18141da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
18151da177e4SLinus Torvalds 	if (write) {
18161da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
18171da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
18181da177e4SLinus Torvalds 		    (param->max && *param->max < val))
18191da177e4SLinus Torvalds 			return -EINVAL;
18201da177e4SLinus Torvalds 		*valp = val;
18211da177e4SLinus Torvalds 	} else {
18221da177e4SLinus Torvalds 		int val = *valp;
18231da177e4SLinus Torvalds 		if (val < 0) {
18241da177e4SLinus Torvalds 			*negp = -1;
18251da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
18261da177e4SLinus Torvalds 		} else {
18271da177e4SLinus Torvalds 			*negp = 0;
18281da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
18291da177e4SLinus Torvalds 		}
18301da177e4SLinus Torvalds 	}
18311da177e4SLinus Torvalds 	return 0;
18321da177e4SLinus Torvalds }
18331da177e4SLinus Torvalds 
18341da177e4SLinus Torvalds /**
18351da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
18361da177e4SLinus Torvalds  * @table: the sysctl table
18371da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
18381da177e4SLinus Torvalds  * @filp: the file structure
18391da177e4SLinus Torvalds  * @buffer: the user buffer
18401da177e4SLinus Torvalds  * @lenp: the size of the user buffer
18411da177e4SLinus Torvalds  * @ppos: file position
18421da177e4SLinus Torvalds  *
18431da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
18441da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
18451da177e4SLinus Torvalds  *
18461da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
18471da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
18481da177e4SLinus Torvalds  *
18491da177e4SLinus Torvalds  * Returns 0 on success.
18501da177e4SLinus Torvalds  */
18511da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
18521da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
18531da177e4SLinus Torvalds {
18541da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
18551da177e4SLinus Torvalds 		.min = (int *) table->extra1,
18561da177e4SLinus Torvalds 		.max = (int *) table->extra2,
18571da177e4SLinus Torvalds 	};
18581da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
18591da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
18601da177e4SLinus Torvalds }
18611da177e4SLinus Torvalds 
18621da177e4SLinus Torvalds static int do_proc_doulongvec_minmax(ctl_table *table, int write,
18631da177e4SLinus Torvalds 				     struct file *filp,
18641da177e4SLinus Torvalds 				     void __user *buffer,
18651da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
18661da177e4SLinus Torvalds 				     unsigned long convmul,
18671da177e4SLinus Torvalds 				     unsigned long convdiv)
18681da177e4SLinus Torvalds {
18691da177e4SLinus Torvalds #define TMPBUFLEN 21
18701da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
18711da177e4SLinus Torvalds 	int vleft, first=1, neg;
18721da177e4SLinus Torvalds 	size_t len, left;
18731da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
18741da177e4SLinus Torvalds 	char __user *s = buffer;
18751da177e4SLinus Torvalds 
18761da177e4SLinus Torvalds 	if (!table->data || !table->maxlen || !*lenp ||
18771da177e4SLinus Torvalds 	    (*ppos && !write)) {
18781da177e4SLinus Torvalds 		*lenp = 0;
18791da177e4SLinus Torvalds 		return 0;
18801da177e4SLinus Torvalds 	}
18811da177e4SLinus Torvalds 
18821da177e4SLinus Torvalds 	i = (unsigned long *) table->data;
18831da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
18841da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
18851da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
18861da177e4SLinus Torvalds 	left = *lenp;
18871da177e4SLinus Torvalds 
18881da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
18891da177e4SLinus Torvalds 		if (write) {
18901da177e4SLinus Torvalds 			while (left) {
18911da177e4SLinus Torvalds 				char c;
18921da177e4SLinus Torvalds 				if (get_user(c, s))
18931da177e4SLinus Torvalds 					return -EFAULT;
18941da177e4SLinus Torvalds 				if (!isspace(c))
18951da177e4SLinus Torvalds 					break;
18961da177e4SLinus Torvalds 				left--;
18971da177e4SLinus Torvalds 				s++;
18981da177e4SLinus Torvalds 			}
18991da177e4SLinus Torvalds 			if (!left)
19001da177e4SLinus Torvalds 				break;
19011da177e4SLinus Torvalds 			neg = 0;
19021da177e4SLinus Torvalds 			len = left;
19031da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
19041da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
19051da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
19061da177e4SLinus Torvalds 				return -EFAULT;
19071da177e4SLinus Torvalds 			buf[len] = 0;
19081da177e4SLinus Torvalds 			p = buf;
19091da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
19101da177e4SLinus Torvalds 				neg = 1;
19111da177e4SLinus Torvalds 				left--, p++;
19121da177e4SLinus Torvalds 			}
19131da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
19141da177e4SLinus Torvalds 				break;
19151da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
19161da177e4SLinus Torvalds 			len = p-buf;
19171da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
19181da177e4SLinus Torvalds 				break;
19191da177e4SLinus Torvalds 			if (neg)
19201da177e4SLinus Torvalds 				val = -val;
19211da177e4SLinus Torvalds 			s += len;
19221da177e4SLinus Torvalds 			left -= len;
19231da177e4SLinus Torvalds 
19241da177e4SLinus Torvalds 			if(neg)
19251da177e4SLinus Torvalds 				continue;
19261da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
19271da177e4SLinus Torvalds 				continue;
19281da177e4SLinus Torvalds 			*i = val;
19291da177e4SLinus Torvalds 		} else {
19301da177e4SLinus Torvalds 			p = buf;
19311da177e4SLinus Torvalds 			if (!first)
19321da177e4SLinus Torvalds 				*p++ = '\t';
19331da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
19341da177e4SLinus Torvalds 			len = strlen(buf);
19351da177e4SLinus Torvalds 			if (len > left)
19361da177e4SLinus Torvalds 				len = left;
19371da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
19381da177e4SLinus Torvalds 				return -EFAULT;
19391da177e4SLinus Torvalds 			left -= len;
19401da177e4SLinus Torvalds 			s += len;
19411da177e4SLinus Torvalds 		}
19421da177e4SLinus Torvalds 	}
19431da177e4SLinus Torvalds 
19441da177e4SLinus Torvalds 	if (!write && !first && left) {
19451da177e4SLinus Torvalds 		if(put_user('\n', s))
19461da177e4SLinus Torvalds 			return -EFAULT;
19471da177e4SLinus Torvalds 		left--, s++;
19481da177e4SLinus Torvalds 	}
19491da177e4SLinus Torvalds 	if (write) {
19501da177e4SLinus Torvalds 		while (left) {
19511da177e4SLinus Torvalds 			char c;
19521da177e4SLinus Torvalds 			if (get_user(c, s++))
19531da177e4SLinus Torvalds 				return -EFAULT;
19541da177e4SLinus Torvalds 			if (!isspace(c))
19551da177e4SLinus Torvalds 				break;
19561da177e4SLinus Torvalds 			left--;
19571da177e4SLinus Torvalds 		}
19581da177e4SLinus Torvalds 	}
19591da177e4SLinus Torvalds 	if (write && first)
19601da177e4SLinus Torvalds 		return -EINVAL;
19611da177e4SLinus Torvalds 	*lenp -= left;
19621da177e4SLinus Torvalds 	*ppos += *lenp;
19631da177e4SLinus Torvalds 	return 0;
19641da177e4SLinus Torvalds #undef TMPBUFLEN
19651da177e4SLinus Torvalds }
19661da177e4SLinus Torvalds 
19671da177e4SLinus Torvalds /**
19681da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
19691da177e4SLinus Torvalds  * @table: the sysctl table
19701da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
19711da177e4SLinus Torvalds  * @filp: the file structure
19721da177e4SLinus Torvalds  * @buffer: the user buffer
19731da177e4SLinus Torvalds  * @lenp: the size of the user buffer
19741da177e4SLinus Torvalds  * @ppos: file position
19751da177e4SLinus Torvalds  *
19761da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
19771da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
19781da177e4SLinus Torvalds  *
19791da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
19801da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
19811da177e4SLinus Torvalds  *
19821da177e4SLinus Torvalds  * Returns 0 on success.
19831da177e4SLinus Torvalds  */
19841da177e4SLinus Torvalds int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
19851da177e4SLinus Torvalds 			   void __user *buffer, size_t *lenp, loff_t *ppos)
19861da177e4SLinus Torvalds {
19871da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
19881da177e4SLinus Torvalds }
19891da177e4SLinus Torvalds 
19901da177e4SLinus Torvalds /**
19911da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
19921da177e4SLinus Torvalds  * @table: the sysctl table
19931da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
19941da177e4SLinus Torvalds  * @filp: the file structure
19951da177e4SLinus Torvalds  * @buffer: the user buffer
19961da177e4SLinus Torvalds  * @lenp: the size of the user buffer
19971da177e4SLinus Torvalds  * @ppos: file position
19981da177e4SLinus Torvalds  *
19991da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
20001da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
20011da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
20021da177e4SLinus Torvalds  *
20031da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
20041da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
20051da177e4SLinus Torvalds  *
20061da177e4SLinus Torvalds  * Returns 0 on success.
20071da177e4SLinus Torvalds  */
20081da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
20091da177e4SLinus Torvalds 				      struct file *filp,
20101da177e4SLinus Torvalds 				      void __user *buffer,
20111da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
20121da177e4SLinus Torvalds {
20131da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer,
20141da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
20151da177e4SLinus Torvalds }
20161da177e4SLinus Torvalds 
20171da177e4SLinus Torvalds 
20181da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
20191da177e4SLinus Torvalds 					 int *valp,
20201da177e4SLinus Torvalds 					 int write, void *data)
20211da177e4SLinus Torvalds {
20221da177e4SLinus Torvalds 	if (write) {
20231da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
20241da177e4SLinus Torvalds 	} else {
20251da177e4SLinus Torvalds 		int val = *valp;
20261da177e4SLinus Torvalds 		unsigned long lval;
20271da177e4SLinus Torvalds 		if (val < 0) {
20281da177e4SLinus Torvalds 			*negp = -1;
20291da177e4SLinus Torvalds 			lval = (unsigned long)-val;
20301da177e4SLinus Torvalds 		} else {
20311da177e4SLinus Torvalds 			*negp = 0;
20321da177e4SLinus Torvalds 			lval = (unsigned long)val;
20331da177e4SLinus Torvalds 		}
20341da177e4SLinus Torvalds 		*lvalp = lval / HZ;
20351da177e4SLinus Torvalds 	}
20361da177e4SLinus Torvalds 	return 0;
20371da177e4SLinus Torvalds }
20381da177e4SLinus Torvalds 
20391da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
20401da177e4SLinus Torvalds 						int *valp,
20411da177e4SLinus Torvalds 						int write, void *data)
20421da177e4SLinus Torvalds {
20431da177e4SLinus Torvalds 	if (write) {
20441da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
20451da177e4SLinus Torvalds 	} else {
20461da177e4SLinus Torvalds 		int val = *valp;
20471da177e4SLinus Torvalds 		unsigned long lval;
20481da177e4SLinus Torvalds 		if (val < 0) {
20491da177e4SLinus Torvalds 			*negp = -1;
20501da177e4SLinus Torvalds 			lval = (unsigned long)-val;
20511da177e4SLinus Torvalds 		} else {
20521da177e4SLinus Torvalds 			*negp = 0;
20531da177e4SLinus Torvalds 			lval = (unsigned long)val;
20541da177e4SLinus Torvalds 		}
20551da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
20561da177e4SLinus Torvalds 	}
20571da177e4SLinus Torvalds 	return 0;
20581da177e4SLinus Torvalds }
20591da177e4SLinus Torvalds 
20601da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
20611da177e4SLinus Torvalds 					    int *valp,
20621da177e4SLinus Torvalds 					    int write, void *data)
20631da177e4SLinus Torvalds {
20641da177e4SLinus Torvalds 	if (write) {
20651da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
20661da177e4SLinus Torvalds 	} else {
20671da177e4SLinus Torvalds 		int val = *valp;
20681da177e4SLinus Torvalds 		unsigned long lval;
20691da177e4SLinus Torvalds 		if (val < 0) {
20701da177e4SLinus Torvalds 			*negp = -1;
20711da177e4SLinus Torvalds 			lval = (unsigned long)-val;
20721da177e4SLinus Torvalds 		} else {
20731da177e4SLinus Torvalds 			*negp = 0;
20741da177e4SLinus Torvalds 			lval = (unsigned long)val;
20751da177e4SLinus Torvalds 		}
20761da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
20771da177e4SLinus Torvalds 	}
20781da177e4SLinus Torvalds 	return 0;
20791da177e4SLinus Torvalds }
20801da177e4SLinus Torvalds 
20811da177e4SLinus Torvalds /**
20821da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
20831da177e4SLinus Torvalds  * @table: the sysctl table
20841da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
20851da177e4SLinus Torvalds  * @filp: the file structure
20861da177e4SLinus Torvalds  * @buffer: the user buffer
20871da177e4SLinus Torvalds  * @lenp: the size of the user buffer
20881da177e4SLinus Torvalds  * @ppos: file position
20891da177e4SLinus Torvalds  *
20901da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
20911da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
20921da177e4SLinus Torvalds  * The values read are assumed to be in seconds, and are converted into
20931da177e4SLinus Torvalds  * jiffies.
20941da177e4SLinus Torvalds  *
20951da177e4SLinus Torvalds  * Returns 0 on success.
20961da177e4SLinus Torvalds  */
20971da177e4SLinus Torvalds int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
20981da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
20991da177e4SLinus Torvalds {
21001da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
21011da177e4SLinus Torvalds 		    	    do_proc_dointvec_jiffies_conv,NULL);
21021da177e4SLinus Torvalds }
21031da177e4SLinus Torvalds 
21041da177e4SLinus Torvalds /**
21051da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
21061da177e4SLinus Torvalds  * @table: the sysctl table
21071da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
21081da177e4SLinus Torvalds  * @filp: the file structure
21091da177e4SLinus Torvalds  * @buffer: the user buffer
21101da177e4SLinus Torvalds  * @lenp: the size of the user buffer
21111e5d5331SRandy Dunlap  * @ppos: pointer to the file position
21121da177e4SLinus Torvalds  *
21131da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
21141da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
21151da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
21161da177e4SLinus Torvalds  * are converted into jiffies.
21171da177e4SLinus Torvalds  *
21181da177e4SLinus Torvalds  * Returns 0 on success.
21191da177e4SLinus Torvalds  */
21201da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
21211da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
21221da177e4SLinus Torvalds {
21231da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
21241da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
21251da177e4SLinus Torvalds }
21261da177e4SLinus Torvalds 
21271da177e4SLinus Torvalds /**
21281da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
21291da177e4SLinus Torvalds  * @table: the sysctl table
21301da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
21311da177e4SLinus Torvalds  * @filp: the file structure
21321da177e4SLinus Torvalds  * @buffer: the user buffer
21331da177e4SLinus Torvalds  * @lenp: the size of the user buffer
213467be2dd1SMartin Waitz  * @ppos: file position
213567be2dd1SMartin Waitz  * @ppos: the current position in the file
21361da177e4SLinus Torvalds  *
21371da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
21381da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
21391da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
21401da177e4SLinus Torvalds  * are converted into jiffies.
21411da177e4SLinus Torvalds  *
21421da177e4SLinus Torvalds  * Returns 0 on success.
21431da177e4SLinus Torvalds  */
21441da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
21451da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
21461da177e4SLinus Torvalds {
21471da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
21481da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
21491da177e4SLinus Torvalds }
21501da177e4SLinus Torvalds 
21511da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
21521da177e4SLinus Torvalds 
21531da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
21541da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
21551da177e4SLinus Torvalds {
21561da177e4SLinus Torvalds 	return -ENOSYS;
21571da177e4SLinus Torvalds }
21581da177e4SLinus Torvalds 
21591da177e4SLinus Torvalds static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
21601da177e4SLinus Torvalds 			    void __user *buffer, size_t *lenp, loff_t *ppos)
21611da177e4SLinus Torvalds {
21621da177e4SLinus Torvalds 	return -ENOSYS;
21631da177e4SLinus Torvalds }
21641da177e4SLinus Torvalds 
21651da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
21661da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
21671da177e4SLinus Torvalds {
21681da177e4SLinus Torvalds 	return -ENOSYS;
21691da177e4SLinus Torvalds }
21701da177e4SLinus Torvalds 
21711da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
21721da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
21731da177e4SLinus Torvalds {
21741da177e4SLinus Torvalds 	return -ENOSYS;
21751da177e4SLinus Torvalds }
21761da177e4SLinus Torvalds 
21771da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
21781da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
21791da177e4SLinus Torvalds {
21801da177e4SLinus Torvalds 	return -ENOSYS;
21811da177e4SLinus Torvalds }
21821da177e4SLinus Torvalds 
21831da177e4SLinus Torvalds int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
21841da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
21851da177e4SLinus Torvalds {
21861da177e4SLinus Torvalds 	return -ENOSYS;
21871da177e4SLinus Torvalds }
21881da177e4SLinus Torvalds 
21891da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
21901da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
21911da177e4SLinus Torvalds {
21921da177e4SLinus Torvalds 	return -ENOSYS;
21931da177e4SLinus Torvalds }
21941da177e4SLinus Torvalds 
21951da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
21961da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
21971da177e4SLinus Torvalds {
21981da177e4SLinus Torvalds 	return -ENOSYS;
21991da177e4SLinus Torvalds }
22001da177e4SLinus Torvalds 
22011da177e4SLinus Torvalds int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
22021da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
22031da177e4SLinus Torvalds {
22041da177e4SLinus Torvalds 	return -ENOSYS;
22051da177e4SLinus Torvalds }
22061da177e4SLinus Torvalds 
22071da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
22081da177e4SLinus Torvalds 				      struct file *filp,
22091da177e4SLinus Torvalds 				      void __user *buffer,
22101da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
22111da177e4SLinus Torvalds {
22121da177e4SLinus Torvalds     return -ENOSYS;
22131da177e4SLinus Torvalds }
22141da177e4SLinus Torvalds 
22151da177e4SLinus Torvalds 
22161da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
22171da177e4SLinus Torvalds 
22181da177e4SLinus Torvalds 
22191da177e4SLinus Torvalds /*
22201da177e4SLinus Torvalds  * General sysctl support routines
22211da177e4SLinus Torvalds  */
22221da177e4SLinus Torvalds 
22231da177e4SLinus Torvalds /* The generic string strategy routine: */
22241da177e4SLinus Torvalds int sysctl_string(ctl_table *table, int __user *name, int nlen,
22251da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
22261da177e4SLinus Torvalds 		  void __user *newval, size_t newlen, void **context)
22271da177e4SLinus Torvalds {
22281da177e4SLinus Torvalds 	if (!table->data || !table->maxlen)
22291da177e4SLinus Torvalds 		return -ENOTDIR;
22301da177e4SLinus Torvalds 
22311da177e4SLinus Torvalds 	if (oldval && oldlenp) {
2232de9e007dSLinus Torvalds 		size_t bufsize;
2233de9e007dSLinus Torvalds 		if (get_user(bufsize, oldlenp))
22341da177e4SLinus Torvalds 			return -EFAULT;
2235de9e007dSLinus Torvalds 		if (bufsize) {
2236de9e007dSLinus Torvalds 			size_t len = strlen(table->data), copied;
2237de9e007dSLinus Torvalds 
2238de9e007dSLinus Torvalds 			/* This shouldn't trigger for a well-formed sysctl */
2239de9e007dSLinus Torvalds 			if (len > table->maxlen)
22401da177e4SLinus Torvalds 				len = table->maxlen;
2241de9e007dSLinus Torvalds 
2242de9e007dSLinus Torvalds 			/* Copy up to a max of bufsize-1 bytes of the string */
2243de9e007dSLinus Torvalds 			copied = (len >= bufsize) ? bufsize - 1 : len;
2244de9e007dSLinus Torvalds 
2245de9e007dSLinus Torvalds 			if (copy_to_user(oldval, table->data, copied) ||
2246de9e007dSLinus Torvalds 			    put_user(0, (char __user *)(oldval + copied)))
22471da177e4SLinus Torvalds 				return -EFAULT;
22481da177e4SLinus Torvalds 			if (put_user(len, oldlenp))
22491da177e4SLinus Torvalds 				return -EFAULT;
22501da177e4SLinus Torvalds 		}
22511da177e4SLinus Torvalds 	}
22521da177e4SLinus Torvalds 	if (newval && newlen) {
2253de9e007dSLinus Torvalds 		size_t len = newlen;
22541da177e4SLinus Torvalds 		if (len > table->maxlen)
22551da177e4SLinus Torvalds 			len = table->maxlen;
22561da177e4SLinus Torvalds 		if(copy_from_user(table->data, newval, len))
22571da177e4SLinus Torvalds 			return -EFAULT;
22581da177e4SLinus Torvalds 		if (len == table->maxlen)
22591da177e4SLinus Torvalds 			len--;
22601da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
22611da177e4SLinus Torvalds 	}
226282c9df82SYi Yang 	return 1;
22631da177e4SLinus Torvalds }
22641da177e4SLinus Torvalds 
22651da177e4SLinus Torvalds /*
22661da177e4SLinus Torvalds  * This function makes sure that all of the integers in the vector
22671da177e4SLinus Torvalds  * are between the minimum and maximum values given in the arrays
22681da177e4SLinus Torvalds  * table->extra1 and table->extra2, respectively.
22691da177e4SLinus Torvalds  */
22701da177e4SLinus Torvalds int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
22711da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
22721da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
22731da177e4SLinus Torvalds {
22741da177e4SLinus Torvalds 
22751da177e4SLinus Torvalds 	if (newval && newlen) {
22761da177e4SLinus Torvalds 		int __user *vec = (int __user *) newval;
22771da177e4SLinus Torvalds 		int *min = (int *) table->extra1;
22781da177e4SLinus Torvalds 		int *max = (int *) table->extra2;
22791da177e4SLinus Torvalds 		size_t length;
22801da177e4SLinus Torvalds 		int i;
22811da177e4SLinus Torvalds 
22821da177e4SLinus Torvalds 		if (newlen % sizeof(int) != 0)
22831da177e4SLinus Torvalds 			return -EINVAL;
22841da177e4SLinus Torvalds 
22851da177e4SLinus Torvalds 		if (!table->extra1 && !table->extra2)
22861da177e4SLinus Torvalds 			return 0;
22871da177e4SLinus Torvalds 
22881da177e4SLinus Torvalds 		if (newlen > table->maxlen)
22891da177e4SLinus Torvalds 			newlen = table->maxlen;
22901da177e4SLinus Torvalds 		length = newlen / sizeof(int);
22911da177e4SLinus Torvalds 
22921da177e4SLinus Torvalds 		for (i = 0; i < length; i++) {
22931da177e4SLinus Torvalds 			int value;
22941da177e4SLinus Torvalds 			if (get_user(value, vec + i))
22951da177e4SLinus Torvalds 				return -EFAULT;
22961da177e4SLinus Torvalds 			if (min && value < min[i])
22971da177e4SLinus Torvalds 				return -EINVAL;
22981da177e4SLinus Torvalds 			if (max && value > max[i])
22991da177e4SLinus Torvalds 				return -EINVAL;
23001da177e4SLinus Torvalds 		}
23011da177e4SLinus Torvalds 	}
23021da177e4SLinus Torvalds 	return 0;
23031da177e4SLinus Torvalds }
23041da177e4SLinus Torvalds 
23051da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
23061da177e4SLinus Torvalds int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
23071da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
23081da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
23091da177e4SLinus Torvalds {
23101da177e4SLinus Torvalds 	if (oldval) {
23111da177e4SLinus Torvalds 		size_t olen;
23121da177e4SLinus Torvalds 		if (oldlenp) {
23131da177e4SLinus Torvalds 			if (get_user(olen, oldlenp))
23141da177e4SLinus Torvalds 				return -EFAULT;
23151da177e4SLinus Torvalds 			if (olen!=sizeof(int))
23161da177e4SLinus Torvalds 				return -EINVAL;
23171da177e4SLinus Torvalds 		}
23181da177e4SLinus Torvalds 		if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
23191da177e4SLinus Torvalds 		    (oldlenp && put_user(sizeof(int),oldlenp)))
23201da177e4SLinus Torvalds 			return -EFAULT;
23211da177e4SLinus Torvalds 	}
23221da177e4SLinus Torvalds 	if (newval && newlen) {
23231da177e4SLinus Torvalds 		int new;
23241da177e4SLinus Torvalds 		if (newlen != sizeof(int))
23251da177e4SLinus Torvalds 			return -EINVAL;
23261da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
23271da177e4SLinus Torvalds 			return -EFAULT;
23281da177e4SLinus Torvalds 		*(int *)(table->data) = new*HZ;
23291da177e4SLinus Torvalds 	}
23301da177e4SLinus Torvalds 	return 1;
23311da177e4SLinus Torvalds }
23321da177e4SLinus Torvalds 
23331da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
23341da177e4SLinus Torvalds int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
23351da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
23361da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
23371da177e4SLinus Torvalds {
23381da177e4SLinus Torvalds 	if (oldval) {
23391da177e4SLinus Torvalds 		size_t olen;
23401da177e4SLinus Torvalds 		if (oldlenp) {
23411da177e4SLinus Torvalds 			if (get_user(olen, oldlenp))
23421da177e4SLinus Torvalds 				return -EFAULT;
23431da177e4SLinus Torvalds 			if (olen!=sizeof(int))
23441da177e4SLinus Torvalds 				return -EINVAL;
23451da177e4SLinus Torvalds 		}
23461da177e4SLinus Torvalds 		if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
23471da177e4SLinus Torvalds 		    (oldlenp && put_user(sizeof(int),oldlenp)))
23481da177e4SLinus Torvalds 			return -EFAULT;
23491da177e4SLinus Torvalds 	}
23501da177e4SLinus Torvalds 	if (newval && newlen) {
23511da177e4SLinus Torvalds 		int new;
23521da177e4SLinus Torvalds 		if (newlen != sizeof(int))
23531da177e4SLinus Torvalds 			return -EINVAL;
23541da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
23551da177e4SLinus Torvalds 			return -EFAULT;
23561da177e4SLinus Torvalds 		*(int *)(table->data) = msecs_to_jiffies(new);
23571da177e4SLinus Torvalds 	}
23581da177e4SLinus Torvalds 	return 1;
23591da177e4SLinus Torvalds }
23601da177e4SLinus Torvalds 
23611da177e4SLinus Torvalds #else /* CONFIG_SYSCTL */
23621da177e4SLinus Torvalds 
23631da177e4SLinus Torvalds 
23641da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
23651da177e4SLinus Torvalds {
23661da177e4SLinus Torvalds 	return -ENOSYS;
23671da177e4SLinus Torvalds }
23681da177e4SLinus Torvalds 
23691da177e4SLinus Torvalds int sysctl_string(ctl_table *table, int __user *name, int nlen,
23701da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
23711da177e4SLinus Torvalds 		  void __user *newval, size_t newlen, void **context)
23721da177e4SLinus Torvalds {
23731da177e4SLinus Torvalds 	return -ENOSYS;
23741da177e4SLinus Torvalds }
23751da177e4SLinus Torvalds 
23761da177e4SLinus Torvalds int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
23771da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
23781da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
23791da177e4SLinus Torvalds {
23801da177e4SLinus Torvalds 	return -ENOSYS;
23811da177e4SLinus Torvalds }
23821da177e4SLinus Torvalds 
23831da177e4SLinus Torvalds int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
23841da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
23851da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
23861da177e4SLinus Torvalds {
23871da177e4SLinus Torvalds 	return -ENOSYS;
23881da177e4SLinus Torvalds }
23891da177e4SLinus Torvalds 
23901da177e4SLinus Torvalds int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
23911da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
23921da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
23931da177e4SLinus Torvalds {
23941da177e4SLinus Torvalds 	return -ENOSYS;
23951da177e4SLinus Torvalds }
23961da177e4SLinus Torvalds 
23971da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
23981da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
23991da177e4SLinus Torvalds {
24001da177e4SLinus Torvalds 	return -ENOSYS;
24011da177e4SLinus Torvalds }
24021da177e4SLinus Torvalds 
24031da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
24041da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
24051da177e4SLinus Torvalds {
24061da177e4SLinus Torvalds 	return -ENOSYS;
24071da177e4SLinus Torvalds }
24081da177e4SLinus Torvalds 
24091da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
24101da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
24111da177e4SLinus Torvalds {
24121da177e4SLinus Torvalds 	return -ENOSYS;
24131da177e4SLinus Torvalds }
24141da177e4SLinus Torvalds 
24151da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
24161da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24171da177e4SLinus Torvalds {
24181da177e4SLinus Torvalds 	return -ENOSYS;
24191da177e4SLinus Torvalds }
24201da177e4SLinus Torvalds 
24211da177e4SLinus Torvalds int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
24221da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
24231da177e4SLinus Torvalds {
24241da177e4SLinus Torvalds 	return -ENOSYS;
24251da177e4SLinus Torvalds }
24261da177e4SLinus Torvalds 
24271da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
24281da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
24291da177e4SLinus Torvalds {
24301da177e4SLinus Torvalds 	return -ENOSYS;
24311da177e4SLinus Torvalds }
24321da177e4SLinus Torvalds 
24331da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
24341da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
24351da177e4SLinus Torvalds {
24361da177e4SLinus Torvalds 	return -ENOSYS;
24371da177e4SLinus Torvalds }
24381da177e4SLinus Torvalds 
24391da177e4SLinus Torvalds int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
24401da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24411da177e4SLinus Torvalds {
24421da177e4SLinus Torvalds 	return -ENOSYS;
24431da177e4SLinus Torvalds }
24441da177e4SLinus Torvalds 
24451da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
24461da177e4SLinus Torvalds 				      struct file *filp,
24471da177e4SLinus Torvalds 				      void __user *buffer,
24481da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
24491da177e4SLinus Torvalds {
24501da177e4SLinus Torvalds     return -ENOSYS;
24511da177e4SLinus Torvalds }
24521da177e4SLinus Torvalds 
24531da177e4SLinus Torvalds struct ctl_table_header * register_sysctl_table(ctl_table * table,
24541da177e4SLinus Torvalds 						int insert_at_head)
24551da177e4SLinus Torvalds {
24561da177e4SLinus Torvalds 	return NULL;
24571da177e4SLinus Torvalds }
24581da177e4SLinus Torvalds 
24591da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * table)
24601da177e4SLinus Torvalds {
24611da177e4SLinus Torvalds }
24621da177e4SLinus Torvalds 
24631da177e4SLinus Torvalds #endif /* CONFIG_SYSCTL */
24641da177e4SLinus Torvalds 
24651da177e4SLinus Torvalds /*
24661da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
24671da177e4SLinus Torvalds  * exception granted :-)
24681da177e4SLinus Torvalds  */
24691da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
24701da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
24711da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
24721da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
24731da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
24741da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
24751da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
24761da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
24771da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
24781da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec);
24791da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies);
24801da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies);
24811da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string);
24821da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
2483