xref: /openbmc/linux/kernel/sysctl.c (revision 6b49a257850fb8ad91f4c76bb712e9213141a34a)
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/module.h>
221da177e4SLinus Torvalds #include <linux/mm.h>
231da177e4SLinus Torvalds #include <linux/swap.h>
241da177e4SLinus Torvalds #include <linux/slab.h>
251da177e4SLinus Torvalds #include <linux/sysctl.h>
261da177e4SLinus Torvalds #include <linux/proc_fs.h>
27c59ede7bSRandy.Dunlap #include <linux/capability.h>
281da177e4SLinus Torvalds #include <linux/ctype.h>
291da177e4SLinus Torvalds #include <linux/utsname.h>
301da177e4SLinus Torvalds #include <linux/capability.h>
311da177e4SLinus Torvalds #include <linux/smp_lock.h>
321da177e4SLinus Torvalds #include <linux/init.h>
331da177e4SLinus Torvalds #include <linux/kernel.h>
340296b228SKay Sievers #include <linux/kobject.h>
3520380731SArnaldo Carvalho de Melo #include <linux/net.h>
361da177e4SLinus Torvalds #include <linux/sysrq.h>
371da177e4SLinus Torvalds #include <linux/highuid.h>
381da177e4SLinus Torvalds #include <linux/writeback.h>
391da177e4SLinus Torvalds #include <linux/hugetlb.h>
401da177e4SLinus Torvalds #include <linux/security.h>
411da177e4SLinus Torvalds #include <linux/initrd.h>
421da177e4SLinus Torvalds #include <linux/times.h>
431da177e4SLinus Torvalds #include <linux/limits.h>
441da177e4SLinus Torvalds #include <linux/dcache.h>
451da177e4SLinus Torvalds #include <linux/syscalls.h>
46c255d844SPavel Machek #include <linux/nfs_fs.h>
47c255d844SPavel Machek #include <linux/acpi.h>
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #include <asm/uaccess.h>
501da177e4SLinus Torvalds #include <asm/processor.h>
511da177e4SLinus Torvalds 
52529bf6beSDipankar Sarma extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53529bf6beSDipankar Sarma                      void __user *buffer, size_t *lenp, loff_t *ppos);
54529bf6beSDipankar Sarma 
5529cbc78bSAndi Kleen #ifdef CONFIG_X86
5629cbc78bSAndi Kleen #include <asm/nmi.h>
570741f4d2SChuck Ebbert #include <asm/stacktrace.h>
5829cbc78bSAndi Kleen #endif
5929cbc78bSAndi Kleen 
601da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds /* External variables not in a header file. */
631da177e4SLinus Torvalds extern int C_A_D;
641da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
651da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
66fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom;
671da177e4SLinus Torvalds extern int max_threads;
681da177e4SLinus Torvalds extern int sysrq_enabled;
691da177e4SLinus Torvalds extern int core_uses_pid;
70d6e71144SAlan Cox extern int suid_dumpable;
711da177e4SLinus Torvalds extern char core_pattern[];
721da177e4SLinus Torvalds extern int pid_max;
731da177e4SLinus Torvalds extern int min_free_kbytes;
741da177e4SLinus Torvalds extern int printk_ratelimit_jiffies;
751da177e4SLinus Torvalds extern int printk_ratelimit_burst;
761da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
779d0243bcSAndrew Morton extern int sysctl_drop_caches;
788ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
79bebfa101SAndi Kleen extern int compat_log;
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
959bc9a6bdSEric W. Biederman static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
969bc9a6bdSEric W. Biederman 		void __user *buffer, size_t *lenp, loff_t *ppos);
979bc9a6bdSEric W. Biederman static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
98fcfbd547SKirill Korotaev 		void __user *buffer, size_t *lenp, loff_t *ppos);
991da177e4SLinus Torvalds #endif
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds #ifdef __sparc__
1021da177e4SLinus Torvalds extern char reboot_command [];
1031da177e4SLinus Torvalds extern int stop_a_enabled;
1041da177e4SLinus Torvalds extern int scons_pwroff;
1051da177e4SLinus Torvalds #endif
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds #ifdef __hppa__
1081da177e4SLinus Torvalds extern int pwrsw_enabled;
1091da177e4SLinus Torvalds extern int unaligned_enabled;
1101da177e4SLinus Torvalds #endif
1111da177e4SLinus Torvalds 
112347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1131da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1141da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1151da177e4SLinus Torvalds #endif
1161da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
117951f22d5SMartin Schwidefsky extern int spin_retry;
1181da177e4SLinus Torvalds #endif
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds extern int sysctl_hz_timer;
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
1231da177e4SLinus Torvalds extern int acct_parm[];
1241da177e4SLinus Torvalds #endif
1251da177e4SLinus Torvalds 
126d2b176edSJes Sorensen #ifdef CONFIG_IA64
127d2b176edSJes Sorensen extern int no_unaligned_warning;
128d2b176edSJes Sorensen #endif
129d2b176edSJes Sorensen 
13023f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
13123f78d4aSIngo Molnar extern int max_lock_depth;
13223f78d4aSIngo Molnar #endif
13323f78d4aSIngo Molnar 
134b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
135b89a8171SEric W. Biederman static int parse_table(int __user *, int, void __user *, size_t __user *,
136b89a8171SEric W. Biederman 		void __user *, size_t, ctl_table *, void **);
137b89a8171SEric W. Biederman #endif
138b89a8171SEric W. Biederman 
1398218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1401da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos);
1411da177e4SLinus Torvalds 
142c4b8b769SEric W. Biederman static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
143c4b8b769SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
144c4b8b769SEric W. Biederman 		  void __user *newval, size_t newlen, void **context);
145c4b8b769SEric W. Biederman 
146*6b49a257SEric W. Biederman #ifdef CONFIG_SYSVIPC
147*6b49a257SEric W. Biederman static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
148*6b49a257SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
149*6b49a257SEric W. Biederman 		  void __user *newval, size_t newlen, void **context);
150*6b49a257SEric W. Biederman #endif
151*6b49a257SEric W. Biederman 
152d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
1539ec52099SCedric Le Goater static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
1549ec52099SCedric Le Goater 		  void __user *buffer, size_t *lenp, loff_t *ppos);
155d6f8ff73SRandy Dunlap #endif
1569ec52099SCedric Le Goater 
1571da177e4SLinus Torvalds static ctl_table root_table[];
1581da177e4SLinus Torvalds static struct ctl_table_header root_table_header =
1591da177e4SLinus Torvalds 	{ root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds static ctl_table kern_table[];
1621da177e4SLinus Torvalds static ctl_table vm_table[];
1631da177e4SLinus Torvalds static ctl_table fs_table[];
1641da177e4SLinus Torvalds static ctl_table debug_table[];
1651da177e4SLinus Torvalds static ctl_table dev_table[];
1661da177e4SLinus Torvalds extern ctl_table random_table[];
1671da177e4SLinus Torvalds #ifdef CONFIG_UNIX98_PTYS
1681da177e4SLinus Torvalds extern ctl_table pty_table[];
1691da177e4SLinus Torvalds #endif
1702d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
1710399cb08SRobert Love extern ctl_table inotify_table[];
1720399cb08SRobert Love #endif
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1751da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1761da177e4SLinus Torvalds #endif
1771da177e4SLinus Torvalds 
178cf9f151cSEric W. Biederman static void *get_uts(ctl_table *table, int write)
179cf9f151cSEric W. Biederman {
180cf9f151cSEric W. Biederman 	char *which = table->data;
181cf9f151cSEric W. Biederman #ifdef CONFIG_UTS_NS
182cf9f151cSEric W. Biederman 	struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
183cf9f151cSEric W. Biederman 	which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
184cf9f151cSEric W. Biederman #endif
185cf9f151cSEric W. Biederman 	if (!write)
186cf9f151cSEric W. Biederman 		down_read(&uts_sem);
187cf9f151cSEric W. Biederman 	else
188cf9f151cSEric W. Biederman 		down_write(&uts_sem);
189cf9f151cSEric W. Biederman 	return which;
190cf9f151cSEric W. Biederman }
191cf9f151cSEric W. Biederman 
192cf9f151cSEric W. Biederman static void put_uts(ctl_table *table, int write, void *which)
193cf9f151cSEric W. Biederman {
194cf9f151cSEric W. Biederman 	if (!write)
195cf9f151cSEric W. Biederman 		up_read(&uts_sem);
196cf9f151cSEric W. Biederman 	else
197cf9f151cSEric W. Biederman 		up_write(&uts_sem);
198cf9f151cSEric W. Biederman }
199cf9f151cSEric W. Biederman 
2009bc9a6bdSEric W. Biederman #ifdef CONFIG_SYSVIPC
2019bc9a6bdSEric W. Biederman static void *get_ipc(ctl_table *table, int write)
2029bc9a6bdSEric W. Biederman {
2039bc9a6bdSEric W. Biederman 	char *which = table->data;
2049bc9a6bdSEric W. Biederman 	struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
2059bc9a6bdSEric W. Biederman 	which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
2069bc9a6bdSEric W. Biederman 	return which;
2079bc9a6bdSEric W. Biederman }
2089bc9a6bdSEric W. Biederman #else
2099bc9a6bdSEric W. Biederman #define get_ipc(T,W) ((T)->data)
2109bc9a6bdSEric W. Biederman #endif
2119bc9a6bdSEric W. Biederman 
2121da177e4SLinus Torvalds /* /proc declarations: */
2131da177e4SLinus Torvalds 
214b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
2171da177e4SLinus Torvalds static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
2181da177e4SLinus Torvalds static int proc_opensys(struct inode *, struct file *);
2191da177e4SLinus Torvalds 
22015ad7cdcSHelge Deller const struct file_operations proc_sys_file_operations = {
2211da177e4SLinus Torvalds 	.open		= proc_opensys,
2221da177e4SLinus Torvalds 	.read		= proc_readsys,
2231da177e4SLinus Torvalds 	.write		= proc_writesys,
2241da177e4SLinus Torvalds };
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds extern struct proc_dir_entry *proc_sys_root;
2271da177e4SLinus Torvalds 
228330d57fbSAl Viro static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
2291da177e4SLinus Torvalds static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
2301da177e4SLinus Torvalds #endif
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds /* The default sysctl tables: */
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds static ctl_table root_table[] = {
2351da177e4SLinus Torvalds 	{
2361da177e4SLinus Torvalds 		.ctl_name	= CTL_KERN,
2371da177e4SLinus Torvalds 		.procname	= "kernel",
2381da177e4SLinus Torvalds 		.mode		= 0555,
2391da177e4SLinus Torvalds 		.child		= kern_table,
2401da177e4SLinus Torvalds 	},
2411da177e4SLinus Torvalds 	{
2421da177e4SLinus Torvalds 		.ctl_name	= CTL_VM,
2431da177e4SLinus Torvalds 		.procname	= "vm",
2441da177e4SLinus Torvalds 		.mode		= 0555,
2451da177e4SLinus Torvalds 		.child		= vm_table,
2461da177e4SLinus Torvalds 	},
2471da177e4SLinus Torvalds #ifdef CONFIG_NET
2481da177e4SLinus Torvalds 	{
2491da177e4SLinus Torvalds 		.ctl_name	= CTL_NET,
2501da177e4SLinus Torvalds 		.procname	= "net",
2511da177e4SLinus Torvalds 		.mode		= 0555,
2521da177e4SLinus Torvalds 		.child		= net_table,
2531da177e4SLinus Torvalds 	},
2541da177e4SLinus Torvalds #endif
2551da177e4SLinus Torvalds 	{
2561da177e4SLinus Torvalds 		.ctl_name	= CTL_FS,
2571da177e4SLinus Torvalds 		.procname	= "fs",
2581da177e4SLinus Torvalds 		.mode		= 0555,
2591da177e4SLinus Torvalds 		.child		= fs_table,
2601da177e4SLinus Torvalds 	},
2611da177e4SLinus Torvalds 	{
2621da177e4SLinus Torvalds 		.ctl_name	= CTL_DEBUG,
2631da177e4SLinus Torvalds 		.procname	= "debug",
2641da177e4SLinus Torvalds 		.mode		= 0555,
2651da177e4SLinus Torvalds 		.child		= debug_table,
2661da177e4SLinus Torvalds 	},
2671da177e4SLinus Torvalds 	{
2681da177e4SLinus Torvalds 		.ctl_name	= CTL_DEV,
2691da177e4SLinus Torvalds 		.procname	= "dev",
2701da177e4SLinus Torvalds 		.mode		= 0555,
2711da177e4SLinus Torvalds 		.child		= dev_table,
2721da177e4SLinus Torvalds 	},
2730eeca283SRobert Love 
2741da177e4SLinus Torvalds 	{ .ctl_name = 0 }
2751da177e4SLinus Torvalds };
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds static ctl_table kern_table[] = {
2781da177e4SLinus Torvalds 	{
2791da177e4SLinus Torvalds 		.ctl_name	= KERN_OSTYPE,
2801da177e4SLinus Torvalds 		.procname	= "ostype",
2818218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.sysname,
2828218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.sysname),
2831da177e4SLinus Torvalds 		.mode		= 0444,
2848218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
285c4b8b769SEric W. Biederman 		.strategy	= &sysctl_uts_string,
2861da177e4SLinus Torvalds 	},
2871da177e4SLinus Torvalds 	{
2881da177e4SLinus Torvalds 		.ctl_name	= KERN_OSRELEASE,
2891da177e4SLinus Torvalds 		.procname	= "osrelease",
2908218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.release,
2918218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.release),
2921da177e4SLinus Torvalds 		.mode		= 0444,
2938218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
294c4b8b769SEric W. Biederman 		.strategy	= &sysctl_uts_string,
2951da177e4SLinus Torvalds 	},
2961da177e4SLinus Torvalds 	{
2971da177e4SLinus Torvalds 		.ctl_name	= KERN_VERSION,
2981da177e4SLinus Torvalds 		.procname	= "version",
2998218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.version,
3008218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.version),
3011da177e4SLinus Torvalds 		.mode		= 0444,
3028218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
303c4b8b769SEric W. Biederman 		.strategy	= &sysctl_uts_string,
3041da177e4SLinus Torvalds 	},
3051da177e4SLinus Torvalds 	{
3061da177e4SLinus Torvalds 		.ctl_name	= KERN_NODENAME,
3071da177e4SLinus Torvalds 		.procname	= "hostname",
3088218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.nodename,
3098218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.nodename),
3101da177e4SLinus Torvalds 		.mode		= 0644,
3118218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
312c4b8b769SEric W. Biederman 		.strategy	= &sysctl_uts_string,
3131da177e4SLinus Torvalds 	},
3141da177e4SLinus Torvalds 	{
3151da177e4SLinus Torvalds 		.ctl_name	= KERN_DOMAINNAME,
3161da177e4SLinus Torvalds 		.procname	= "domainname",
3178218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.domainname,
3188218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.domainname),
3191da177e4SLinus Torvalds 		.mode		= 0644,
3208218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
321c4b8b769SEric W. Biederman 		.strategy	= &sysctl_uts_string,
3221da177e4SLinus Torvalds 	},
3231da177e4SLinus Torvalds 	{
3241da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC,
3251da177e4SLinus Torvalds 		.procname	= "panic",
3261da177e4SLinus Torvalds 		.data		= &panic_timeout,
3271da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3281da177e4SLinus Torvalds 		.mode		= 0644,
3291da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3301da177e4SLinus Torvalds 	},
3311da177e4SLinus Torvalds 	{
3321da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_USES_PID,
3331da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
3341da177e4SLinus Torvalds 		.data		= &core_uses_pid,
3351da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3361da177e4SLinus Torvalds 		.mode		= 0644,
3371da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3381da177e4SLinus Torvalds 	},
3391da177e4SLinus Torvalds 	{
3401da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_PATTERN,
3411da177e4SLinus Torvalds 		.procname	= "core_pattern",
3421da177e4SLinus Torvalds 		.data		= core_pattern,
343d025c9dbSAndi Kleen 		.maxlen		= 128,
3441da177e4SLinus Torvalds 		.mode		= 0644,
3451da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3461da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3471da177e4SLinus Torvalds 	},
3481da177e4SLinus Torvalds 	{
3491da177e4SLinus Torvalds 		.ctl_name	= KERN_TAINTED,
3501da177e4SLinus Torvalds 		.procname	= "tainted",
3511da177e4SLinus Torvalds 		.data		= &tainted,
3521da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3531da177e4SLinus Torvalds 		.mode		= 0444,
3541da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3551da177e4SLinus Torvalds 	},
3561da177e4SLinus Torvalds 	{
3571da177e4SLinus Torvalds 		.ctl_name	= KERN_CAP_BSET,
3581da177e4SLinus Torvalds 		.procname	= "cap-bound",
3591da177e4SLinus Torvalds 		.data		= &cap_bset,
3601da177e4SLinus Torvalds 		.maxlen		= sizeof(kernel_cap_t),
3611da177e4SLinus Torvalds 		.mode		= 0600,
3621da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_bset,
3631da177e4SLinus Torvalds 	},
3641da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
3651da177e4SLinus Torvalds 	{
3661da177e4SLinus Torvalds 		.ctl_name	= KERN_REALROOTDEV,
3671da177e4SLinus Torvalds 		.procname	= "real-root-dev",
3681da177e4SLinus Torvalds 		.data		= &real_root_dev,
3691da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3701da177e4SLinus Torvalds 		.mode		= 0644,
3711da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3721da177e4SLinus Torvalds 	},
3731da177e4SLinus Torvalds #endif
3741da177e4SLinus Torvalds #ifdef __sparc__
3751da177e4SLinus Torvalds 	{
3761da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_REBOOT,
3771da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
3781da177e4SLinus Torvalds 		.data		= reboot_command,
3791da177e4SLinus Torvalds 		.maxlen		= 256,
3801da177e4SLinus Torvalds 		.mode		= 0644,
3811da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3821da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3831da177e4SLinus Torvalds 	},
3841da177e4SLinus Torvalds 	{
3851da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_STOP_A,
3861da177e4SLinus Torvalds 		.procname	= "stop-a",
3871da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
3881da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3891da177e4SLinus Torvalds 		.mode		= 0644,
3901da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3911da177e4SLinus Torvalds 	},
3921da177e4SLinus Torvalds 	{
3931da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
3941da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
3951da177e4SLinus Torvalds 		.data		= &scons_pwroff,
3961da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3971da177e4SLinus Torvalds 		.mode		= 0644,
3981da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3991da177e4SLinus Torvalds 	},
4001da177e4SLinus Torvalds #endif
4011da177e4SLinus Torvalds #ifdef __hppa__
4021da177e4SLinus Torvalds 	{
4031da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_PWRSW,
4041da177e4SLinus Torvalds 		.procname	= "soft-power",
4051da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
4061da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4071da177e4SLinus Torvalds 	 	.mode		= 0644,
4081da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4091da177e4SLinus Torvalds 	},
4101da177e4SLinus Torvalds 	{
4111da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_UNALIGNED,
4121da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
4131da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
4141da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4151da177e4SLinus Torvalds 		.mode		= 0644,
4161da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4171da177e4SLinus Torvalds 	},
4181da177e4SLinus Torvalds #endif
4191da177e4SLinus Torvalds 	{
4201da177e4SLinus Torvalds 		.ctl_name	= KERN_CTLALTDEL,
4211da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
4221da177e4SLinus Torvalds 		.data		= &C_A_D,
4231da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4241da177e4SLinus Torvalds 		.mode		= 0644,
4251da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4261da177e4SLinus Torvalds 	},
4271da177e4SLinus Torvalds 	{
4281da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK,
4291da177e4SLinus Torvalds 		.procname	= "printk",
4301da177e4SLinus Torvalds 		.data		= &console_loglevel,
4311da177e4SLinus Torvalds 		.maxlen		= 4*sizeof(int),
4321da177e4SLinus Torvalds 		.mode		= 0644,
4331da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4341da177e4SLinus Torvalds 	},
4351da177e4SLinus Torvalds #ifdef CONFIG_KMOD
4361da177e4SLinus Torvalds 	{
4371da177e4SLinus Torvalds 		.ctl_name	= KERN_MODPROBE,
4381da177e4SLinus Torvalds 		.procname	= "modprobe",
4391da177e4SLinus Torvalds 		.data		= &modprobe_path,
4401da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
4411da177e4SLinus Torvalds 		.mode		= 0644,
4421da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4431da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4441da177e4SLinus Torvalds 	},
4451da177e4SLinus Torvalds #endif
44657ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
4471da177e4SLinus Torvalds 	{
4481da177e4SLinus Torvalds 		.ctl_name	= KERN_HOTPLUG,
4491da177e4SLinus Torvalds 		.procname	= "hotplug",
450312c004dSKay Sievers 		.data		= &uevent_helper,
451312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
4521da177e4SLinus Torvalds 		.mode		= 0644,
4531da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4541da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4551da177e4SLinus Torvalds 	},
4561da177e4SLinus Torvalds #endif
4571da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
4581da177e4SLinus Torvalds 	{
4591da177e4SLinus Torvalds 		.ctl_name	= KERN_SG_BIG_BUFF,
4601da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
4611da177e4SLinus Torvalds 		.data		= &sg_big_buff,
4621da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4631da177e4SLinus Torvalds 		.mode		= 0444,
4641da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4651da177e4SLinus Torvalds 	},
4661da177e4SLinus Torvalds #endif
4671da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
4681da177e4SLinus Torvalds 	{
4691da177e4SLinus Torvalds 		.ctl_name	= KERN_ACCT,
4701da177e4SLinus Torvalds 		.procname	= "acct",
4711da177e4SLinus Torvalds 		.data		= &acct_parm,
4721da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
4731da177e4SLinus Torvalds 		.mode		= 0644,
4741da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4751da177e4SLinus Torvalds 	},
4761da177e4SLinus Torvalds #endif
4771da177e4SLinus Torvalds #ifdef CONFIG_SYSVIPC
4781da177e4SLinus Torvalds 	{
4791da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMMAX,
4801da177e4SLinus Torvalds 		.procname	= "shmmax",
4819bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.shm_ctlmax,
4829bc9a6bdSEric W. Biederman 		.maxlen		= sizeof (init_ipc_ns.shm_ctlmax),
4831da177e4SLinus Torvalds 		.mode		= 0644,
4849bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_doulongvec_minmax,
485*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
4861da177e4SLinus Torvalds 	},
4871da177e4SLinus Torvalds 	{
4881da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMALL,
4891da177e4SLinus Torvalds 		.procname	= "shmall",
4909bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.shm_ctlall,
4919bc9a6bdSEric W. Biederman 		.maxlen		= sizeof (init_ipc_ns.shm_ctlall),
4921da177e4SLinus Torvalds 		.mode		= 0644,
4939bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_doulongvec_minmax,
494*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
4951da177e4SLinus Torvalds 	},
4961da177e4SLinus Torvalds 	{
4971da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMMNI,
4981da177e4SLinus Torvalds 		.procname	= "shmmni",
4999bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.shm_ctlmni,
5009bc9a6bdSEric W. Biederman 		.maxlen		= sizeof (init_ipc_ns.shm_ctlmni),
5011da177e4SLinus Torvalds 		.mode		= 0644,
5029bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_dointvec,
503*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
5041da177e4SLinus Torvalds 	},
5051da177e4SLinus Torvalds 	{
5061da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMAX,
5071da177e4SLinus Torvalds 		.procname	= "msgmax",
5089bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.msg_ctlmax,
5099bc9a6bdSEric W. Biederman 		.maxlen		= sizeof (init_ipc_ns.msg_ctlmax),
5101da177e4SLinus Torvalds 		.mode		= 0644,
5119bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_dointvec,
512*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
5131da177e4SLinus Torvalds 	},
5141da177e4SLinus Torvalds 	{
5151da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMNI,
5161da177e4SLinus Torvalds 		.procname	= "msgmni",
5179bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.msg_ctlmni,
5189bc9a6bdSEric W. Biederman 		.maxlen		= sizeof (init_ipc_ns.msg_ctlmni),
5191da177e4SLinus Torvalds 		.mode		= 0644,
5209bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_dointvec,
521*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
5221da177e4SLinus Torvalds 	},
5231da177e4SLinus Torvalds 	{
5241da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMNB,
5251da177e4SLinus Torvalds 		.procname	=  "msgmnb",
5269bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.msg_ctlmnb,
5279bc9a6bdSEric W. Biederman 		.maxlen		= sizeof (init_ipc_ns.msg_ctlmnb),
5281da177e4SLinus Torvalds 		.mode		= 0644,
5299bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_dointvec,
530*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
5311da177e4SLinus Torvalds 	},
5321da177e4SLinus Torvalds 	{
5331da177e4SLinus Torvalds 		.ctl_name	= KERN_SEM,
5341da177e4SLinus Torvalds 		.procname	= "sem",
5359bc9a6bdSEric W. Biederman 		.data		= &init_ipc_ns.sem_ctls,
5361da177e4SLinus Torvalds 		.maxlen		= 4*sizeof (int),
5371da177e4SLinus Torvalds 		.mode		= 0644,
5389bc9a6bdSEric W. Biederman 		.proc_handler	= &proc_ipc_dointvec,
539*6b49a257SEric W. Biederman 		.strategy	= sysctl_ipc_data,
5401da177e4SLinus Torvalds 	},
5411da177e4SLinus Torvalds #endif
5421da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
5431da177e4SLinus Torvalds 	{
5441da177e4SLinus Torvalds 		.ctl_name	= KERN_SYSRQ,
5451da177e4SLinus Torvalds 		.procname	= "sysrq",
5461da177e4SLinus Torvalds 		.data		= &sysrq_enabled,
5471da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5481da177e4SLinus Torvalds 		.mode		= 0644,
5491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5501da177e4SLinus Torvalds 	},
5511da177e4SLinus Torvalds #endif
552d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
5531da177e4SLinus Torvalds 	{
5541da177e4SLinus Torvalds 		.ctl_name	= KERN_CADPID,
5551da177e4SLinus Torvalds 		.procname	= "cad_pid",
5569ec52099SCedric Le Goater 		.data		= NULL,
5571da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5581da177e4SLinus Torvalds 		.mode		= 0600,
5599ec52099SCedric Le Goater 		.proc_handler	= &proc_do_cad_pid,
5601da177e4SLinus Torvalds 	},
561d6f8ff73SRandy Dunlap #endif
5621da177e4SLinus Torvalds 	{
5631da177e4SLinus Torvalds 		.ctl_name	= KERN_MAX_THREADS,
5641da177e4SLinus Torvalds 		.procname	= "threads-max",
5651da177e4SLinus Torvalds 		.data		= &max_threads,
5661da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5671da177e4SLinus Torvalds 		.mode		= 0644,
5681da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5691da177e4SLinus Torvalds 	},
5701da177e4SLinus Torvalds 	{
5711da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOM,
5721da177e4SLinus Torvalds 		.procname	= "random",
5731da177e4SLinus Torvalds 		.mode		= 0555,
5741da177e4SLinus Torvalds 		.child		= random_table,
5751da177e4SLinus Torvalds 	},
5761da177e4SLinus Torvalds #ifdef CONFIG_UNIX98_PTYS
5771da177e4SLinus Torvalds 	{
5781da177e4SLinus Torvalds 		.ctl_name	= KERN_PTY,
5791da177e4SLinus Torvalds 		.procname	= "pty",
5801da177e4SLinus Torvalds 		.mode		= 0555,
5811da177e4SLinus Torvalds 		.child		= pty_table,
5821da177e4SLinus Torvalds 	},
5831da177e4SLinus Torvalds #endif
5841da177e4SLinus Torvalds 	{
5851da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWUID,
5861da177e4SLinus Torvalds 		.procname	= "overflowuid",
5871da177e4SLinus Torvalds 		.data		= &overflowuid,
5881da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5891da177e4SLinus Torvalds 		.mode		= 0644,
5901da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5911da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5921da177e4SLinus Torvalds 		.extra1		= &minolduid,
5931da177e4SLinus Torvalds 		.extra2		= &maxolduid,
5941da177e4SLinus Torvalds 	},
5951da177e4SLinus Torvalds 	{
5961da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWGID,
5971da177e4SLinus Torvalds 		.procname	= "overflowgid",
5981da177e4SLinus Torvalds 		.data		= &overflowgid,
5991da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6001da177e4SLinus Torvalds 		.mode		= 0644,
6011da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6021da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
6031da177e4SLinus Torvalds 		.extra1		= &minolduid,
6041da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6051da177e4SLinus Torvalds 	},
606347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
6071da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
6081da177e4SLinus Torvalds 	{
6091da177e4SLinus Torvalds 		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
6101da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
6111da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
6121da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6131da177e4SLinus Torvalds 		.mode		= 0644,
6141da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6151da177e4SLinus Torvalds 	},
6161da177e4SLinus Torvalds #endif
6171da177e4SLinus Torvalds #ifdef CONFIG_NO_IDLE_HZ
6181da177e4SLinus Torvalds 	{
6191da177e4SLinus Torvalds 		.ctl_name       = KERN_HZ_TIMER,
6201da177e4SLinus Torvalds 		.procname       = "hz_timer",
6211da177e4SLinus Torvalds 		.data           = &sysctl_hz_timer,
6221da177e4SLinus Torvalds 		.maxlen         = sizeof(int),
6231da177e4SLinus Torvalds 		.mode           = 0644,
6241da177e4SLinus Torvalds 		.proc_handler   = &proc_dointvec,
6251da177e4SLinus Torvalds 	},
6261da177e4SLinus Torvalds #endif
6271da177e4SLinus Torvalds 	{
6281da177e4SLinus Torvalds 		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
6291da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
6301da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
6311da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6321da177e4SLinus Torvalds 		.mode		= 0644,
6331da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6341da177e4SLinus Torvalds 	},
6351da177e4SLinus Torvalds #endif
6361da177e4SLinus Torvalds 	{
6371da177e4SLinus Torvalds 		.ctl_name	= KERN_PIDMAX,
6381da177e4SLinus Torvalds 		.procname	= "pid_max",
6391da177e4SLinus Torvalds 		.data		= &pid_max,
6401da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6411da177e4SLinus Torvalds 		.mode		= 0644,
6421da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6431da177e4SLinus Torvalds 		.strategy	= sysctl_intvec,
6441da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
6451da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
6461da177e4SLinus Torvalds 	},
6471da177e4SLinus Torvalds 	{
6481da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC_ON_OOPS,
6491da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
6501da177e4SLinus Torvalds 		.data		= &panic_on_oops,
6511da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6521da177e4SLinus Torvalds 		.mode		= 0644,
6531da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6541da177e4SLinus Torvalds 	},
6551da177e4SLinus Torvalds 	{
6561da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT,
6571da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
6581da177e4SLinus Torvalds 		.data		= &printk_ratelimit_jiffies,
6591da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6601da177e4SLinus Torvalds 		.mode		= 0644,
6611da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
6621da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
6631da177e4SLinus Torvalds 	},
6641da177e4SLinus Torvalds 	{
6651da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
6661da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
6671da177e4SLinus Torvalds 		.data		= &printk_ratelimit_burst,
6681da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6691da177e4SLinus Torvalds 		.mode		= 0644,
6701da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6711da177e4SLinus Torvalds 	},
6721da177e4SLinus Torvalds 	{
6731da177e4SLinus Torvalds 		.ctl_name	= KERN_NGROUPS_MAX,
6741da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6751da177e4SLinus Torvalds 		.data		= &ngroups_max,
6761da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6771da177e4SLinus Torvalds 		.mode		= 0444,
6781da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6791da177e4SLinus Torvalds 	},
6801da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6811da177e4SLinus Torvalds 	{
6821da177e4SLinus Torvalds 		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
6831da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
6841da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
6851da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
6861da177e4SLinus Torvalds 		.mode           = 0644,
6872fbe7b25SDon Zickus 		.proc_handler   = &proc_dointvec,
6881da177e4SLinus Torvalds 	},
689407984f1SDon Zickus 	{
690407984f1SDon Zickus 		.ctl_name       = KERN_NMI_WATCHDOG,
691407984f1SDon Zickus 		.procname       = "nmi_watchdog",
692407984f1SDon Zickus 		.data           = &nmi_watchdog_enabled,
693407984f1SDon Zickus 		.maxlen         = sizeof (int),
694407984f1SDon Zickus 		.mode           = 0644,
695407984f1SDon Zickus 		.proc_handler   = &proc_nmi_enabled,
6961da177e4SLinus Torvalds 	},
6971da177e4SLinus Torvalds #endif
6981da177e4SLinus Torvalds #if defined(CONFIG_X86)
6991da177e4SLinus Torvalds 	{
7008da5addaSDon Zickus 		.ctl_name	= KERN_PANIC_ON_NMI,
7018da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
7028da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
7038da5addaSDon Zickus 		.maxlen		= sizeof(int),
7048da5addaSDon Zickus 		.mode		= 0644,
7058da5addaSDon Zickus 		.proc_handler	= &proc_dointvec,
7068da5addaSDon Zickus 	},
7078da5addaSDon Zickus 	{
7081da177e4SLinus Torvalds 		.ctl_name	= KERN_BOOTLOADER_TYPE,
7091da177e4SLinus Torvalds 		.procname	= "bootloader_type",
7101da177e4SLinus Torvalds 		.data		= &bootloader_type,
7111da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
7121da177e4SLinus Torvalds 		.mode		= 0444,
7131da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7141da177e4SLinus Torvalds 	},
7150741f4d2SChuck Ebbert 	{
7160741f4d2SChuck Ebbert 		.ctl_name	= CTL_UNNUMBERED,
7170741f4d2SChuck Ebbert 		.procname	= "kstack_depth_to_print",
7180741f4d2SChuck Ebbert 		.data		= &kstack_depth_to_print,
7190741f4d2SChuck Ebbert 		.maxlen		= sizeof(int),
7200741f4d2SChuck Ebbert 		.mode		= 0644,
7210741f4d2SChuck Ebbert 		.proc_handler	= &proc_dointvec,
7220741f4d2SChuck Ebbert 	},
7231da177e4SLinus Torvalds #endif
7247a9166e3SLuke Yang #if defined(CONFIG_MMU)
7251da177e4SLinus Torvalds 	{
7261da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOMIZE,
7271da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
7281da177e4SLinus Torvalds 		.data		= &randomize_va_space,
7291da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
7301da177e4SLinus Torvalds 		.mode		= 0644,
7311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7321da177e4SLinus Torvalds 	},
7337a9166e3SLuke Yang #endif
7340152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
735951f22d5SMartin Schwidefsky 	{
736951f22d5SMartin Schwidefsky 		.ctl_name	= KERN_SPIN_RETRY,
737951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
738951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
739951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
740951f22d5SMartin Schwidefsky 		.mode		= 0644,
741951f22d5SMartin Schwidefsky 		.proc_handler	= &proc_dointvec,
742951f22d5SMartin Schwidefsky 	},
743951f22d5SMartin Schwidefsky #endif
744c255d844SPavel Machek #ifdef CONFIG_ACPI_SLEEP
745c255d844SPavel Machek 	{
746c255d844SPavel Machek 		.ctl_name	= KERN_ACPI_VIDEO_FLAGS,
747c255d844SPavel Machek 		.procname	= "acpi_video_flags",
748c255d844SPavel Machek 		.data		= &acpi_video_flags,
749c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
750c255d844SPavel Machek 		.mode		= 0644,
7517f99f06fSStefan Seyfried 		.proc_handler	= &proc_doulongvec_minmax,
752c255d844SPavel Machek 	},
753c255d844SPavel Machek #endif
754d2b176edSJes Sorensen #ifdef CONFIG_IA64
755d2b176edSJes Sorensen 	{
756d2b176edSJes Sorensen 		.ctl_name	= KERN_IA64_UNALIGNED,
757d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
758d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
759d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
760d2b176edSJes Sorensen 	 	.mode		= 0644,
761d2b176edSJes Sorensen 		.proc_handler	= &proc_dointvec,
762d2b176edSJes Sorensen 	},
763d2b176edSJes Sorensen #endif
764bebfa101SAndi Kleen #ifdef CONFIG_COMPAT
765bebfa101SAndi Kleen 	{
766bebfa101SAndi Kleen 		.ctl_name	= KERN_COMPAT_LOG,
767bebfa101SAndi Kleen 		.procname	= "compat-log",
768bebfa101SAndi Kleen 		.data		= &compat_log,
769bebfa101SAndi Kleen 		.maxlen		= sizeof (int),
770bebfa101SAndi Kleen 	 	.mode		= 0644,
771bebfa101SAndi Kleen 		.proc_handler	= &proc_dointvec,
772bebfa101SAndi Kleen 	},
773bebfa101SAndi Kleen #endif
77423f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
77523f78d4aSIngo Molnar 	{
77623f78d4aSIngo Molnar 		.ctl_name	= KERN_MAX_LOCK_DEPTH,
77723f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
77823f78d4aSIngo Molnar 		.data		= &max_lock_depth,
77923f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
78023f78d4aSIngo Molnar 		.mode		= 0644,
78123f78d4aSIngo Molnar 		.proc_handler	= &proc_dointvec,
78223f78d4aSIngo Molnar 	},
78323f78d4aSIngo Molnar #endif
78423f78d4aSIngo Molnar 
7851da177e4SLinus Torvalds 	{ .ctl_name = 0 }
7861da177e4SLinus Torvalds };
7871da177e4SLinus Torvalds 
7881da177e4SLinus Torvalds /* Constants for minimum and maximum testing in vm_table.
7891da177e4SLinus Torvalds    We use these as one-element integer vectors. */
7901da177e4SLinus Torvalds static int zero;
7911da177e4SLinus Torvalds static int one_hundred = 100;
7921da177e4SLinus Torvalds 
7931da177e4SLinus Torvalds 
7941da177e4SLinus Torvalds static ctl_table vm_table[] = {
7951da177e4SLinus Torvalds 	{
7961da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_MEMORY,
7971da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
7981da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
7991da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
8001da177e4SLinus Torvalds 		.mode		= 0644,
8011da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8021da177e4SLinus Torvalds 	},
8031da177e4SLinus Torvalds 	{
804fadd8fbdSKAMEZAWA Hiroyuki 		.ctl_name	= VM_PANIC_ON_OOM,
805fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
806fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
807fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
808fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
809fadd8fbdSKAMEZAWA Hiroyuki 		.proc_handler	= &proc_dointvec,
810fadd8fbdSKAMEZAWA Hiroyuki 	},
811fadd8fbdSKAMEZAWA Hiroyuki 	{
8121da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_RATIO,
8131da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
8141da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
8151da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
8161da177e4SLinus Torvalds 		.mode		= 0644,
8171da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8181da177e4SLinus Torvalds 	},
8191da177e4SLinus Torvalds 	{
8201da177e4SLinus Torvalds 		.ctl_name	= VM_PAGE_CLUSTER,
8211da177e4SLinus Torvalds 		.procname	= "page-cluster",
8221da177e4SLinus Torvalds 		.data		= &page_cluster,
8231da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
8241da177e4SLinus Torvalds 		.mode		= 0644,
8251da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8261da177e4SLinus Torvalds 	},
8271da177e4SLinus Torvalds 	{
8281da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_BACKGROUND,
8291da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
8301da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
8311da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
8321da177e4SLinus Torvalds 		.mode		= 0644,
8331da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
8341da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8351da177e4SLinus Torvalds 		.extra1		= &zero,
8361da177e4SLinus Torvalds 		.extra2		= &one_hundred,
8371da177e4SLinus Torvalds 	},
8381da177e4SLinus Torvalds 	{
8391da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_RATIO,
8401da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
8411da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
8421da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
8431da177e4SLinus Torvalds 		.mode		= 0644,
8441da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
8451da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8461da177e4SLinus Torvalds 		.extra1		= &zero,
8471da177e4SLinus Torvalds 		.extra2		= &one_hundred,
8481da177e4SLinus Torvalds 	},
8491da177e4SLinus Torvalds 	{
8501da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_WB_CS,
8511da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
852f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
853f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
8541da177e4SLinus Torvalds 		.mode		= 0644,
8551da177e4SLinus Torvalds 		.proc_handler	= &dirty_writeback_centisecs_handler,
8561da177e4SLinus Torvalds 	},
8571da177e4SLinus Torvalds 	{
8581da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_EXPIRE_CS,
8591da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
860f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
861f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
8621da177e4SLinus Torvalds 		.mode		= 0644,
863f6ef9438SBart Samwel 		.proc_handler	= &proc_dointvec_userhz_jiffies,
8641da177e4SLinus Torvalds 	},
8651da177e4SLinus Torvalds 	{
8661da177e4SLinus Torvalds 		.ctl_name	= VM_NR_PDFLUSH_THREADS,
8671da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
8681da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
8691da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
8701da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
8711da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8721da177e4SLinus Torvalds 	},
8731da177e4SLinus Torvalds 	{
8741da177e4SLinus Torvalds 		.ctl_name	= VM_SWAPPINESS,
8751da177e4SLinus Torvalds 		.procname	= "swappiness",
8761da177e4SLinus Torvalds 		.data		= &vm_swappiness,
8771da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
8781da177e4SLinus Torvalds 		.mode		= 0644,
8791da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
8801da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8811da177e4SLinus Torvalds 		.extra1		= &zero,
8821da177e4SLinus Torvalds 		.extra2		= &one_hundred,
8831da177e4SLinus Torvalds 	},
8841da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
8851da177e4SLinus Torvalds 	 {
8861da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_PAGES,
8871da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
8881da177e4SLinus Torvalds 		.data		= &max_huge_pages,
8891da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
8901da177e4SLinus Torvalds 		.mode		= 0644,
8911da177e4SLinus Torvalds 		.proc_handler	= &hugetlb_sysctl_handler,
8921da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
8931da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
8941da177e4SLinus Torvalds 	 },
8951da177e4SLinus Torvalds 	 {
8961da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_GROUP,
8971da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
8981da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
8991da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
9001da177e4SLinus Torvalds 		.mode		= 0644,
9011da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9021da177e4SLinus Torvalds 	 },
9031da177e4SLinus Torvalds #endif
9041da177e4SLinus Torvalds 	{
9051da177e4SLinus Torvalds 		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
9061da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
9071da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
9081da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
9091da177e4SLinus Torvalds 		.mode		= 0644,
9101da177e4SLinus Torvalds 		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
9111da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9121da177e4SLinus Torvalds 	},
9131da177e4SLinus Torvalds 	{
9149d0243bcSAndrew Morton 		.ctl_name	= VM_DROP_PAGECACHE,
9159d0243bcSAndrew Morton 		.procname	= "drop_caches",
9169d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
9179d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
9189d0243bcSAndrew Morton 		.mode		= 0644,
9199d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
9209d0243bcSAndrew Morton 		.strategy	= &sysctl_intvec,
9219d0243bcSAndrew Morton 	},
9229d0243bcSAndrew Morton 	{
9231da177e4SLinus Torvalds 		.ctl_name	= VM_MIN_FREE_KBYTES,
9241da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
9251da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
9261da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
9271da177e4SLinus Torvalds 		.mode		= 0644,
9281da177e4SLinus Torvalds 		.proc_handler	= &min_free_kbytes_sysctl_handler,
9291da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9301da177e4SLinus Torvalds 		.extra1		= &zero,
9311da177e4SLinus Torvalds 	},
9328ad4b1fbSRohit Seth 	{
9338ad4b1fbSRohit Seth 		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
9348ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
9358ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
9368ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
9378ad4b1fbSRohit Seth 		.mode		= 0644,
9388ad4b1fbSRohit Seth 		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
9398ad4b1fbSRohit Seth 		.strategy	= &sysctl_intvec,
9408ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
9418ad4b1fbSRohit Seth 	},
9421da177e4SLinus Torvalds #ifdef CONFIG_MMU
9431da177e4SLinus Torvalds 	{
9441da177e4SLinus Torvalds 		.ctl_name	= VM_MAX_MAP_COUNT,
9451da177e4SLinus Torvalds 		.procname	= "max_map_count",
9461da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
9471da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
9481da177e4SLinus Torvalds 		.mode		= 0644,
9491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec
9501da177e4SLinus Torvalds 	},
9511da177e4SLinus Torvalds #endif
9521da177e4SLinus Torvalds 	{
9531da177e4SLinus Torvalds 		.ctl_name	= VM_LAPTOP_MODE,
9541da177e4SLinus Torvalds 		.procname	= "laptop_mode",
9551da177e4SLinus Torvalds 		.data		= &laptop_mode,
9561da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
9571da177e4SLinus Torvalds 		.mode		= 0644,
958ed5b43f1SBart Samwel 		.proc_handler	= &proc_dointvec_jiffies,
959ed5b43f1SBart Samwel 		.strategy	= &sysctl_jiffies,
9601da177e4SLinus Torvalds 	},
9611da177e4SLinus Torvalds 	{
9621da177e4SLinus Torvalds 		.ctl_name	= VM_BLOCK_DUMP,
9631da177e4SLinus Torvalds 		.procname	= "block_dump",
9641da177e4SLinus Torvalds 		.data		= &block_dump,
9651da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
9661da177e4SLinus Torvalds 		.mode		= 0644,
9671da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9681da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9691da177e4SLinus Torvalds 		.extra1		= &zero,
9701da177e4SLinus Torvalds 	},
9711da177e4SLinus Torvalds 	{
9721da177e4SLinus Torvalds 		.ctl_name	= VM_VFS_CACHE_PRESSURE,
9731da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
9741da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
9751da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
9761da177e4SLinus Torvalds 		.mode		= 0644,
9771da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9781da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9791da177e4SLinus Torvalds 		.extra1		= &zero,
9801da177e4SLinus Torvalds 	},
9811da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
9821da177e4SLinus Torvalds 	{
9831da177e4SLinus Torvalds 		.ctl_name	= VM_LEGACY_VA_LAYOUT,
9841da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
9851da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
9861da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
9871da177e4SLinus Torvalds 		.mode		= 0644,
9881da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9891da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9901da177e4SLinus Torvalds 		.extra1		= &zero,
9911da177e4SLinus Torvalds 	},
9921da177e4SLinus Torvalds #endif
9931743660bSChristoph Lameter #ifdef CONFIG_NUMA
9941743660bSChristoph Lameter 	{
9951743660bSChristoph Lameter 		.ctl_name	= VM_ZONE_RECLAIM_MODE,
9961743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
9971743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
9981743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
9991743660bSChristoph Lameter 		.mode		= 0644,
10001743660bSChristoph Lameter 		.proc_handler	= &proc_dointvec,
1001c84db23cSChristoph Lameter 		.strategy	= &sysctl_intvec,
1002c84db23cSChristoph Lameter 		.extra1		= &zero,
10031743660bSChristoph Lameter 	},
10049614634fSChristoph Lameter 	{
10059614634fSChristoph Lameter 		.ctl_name	= VM_MIN_UNMAPPED,
10069614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
10079614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
10089614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
10099614634fSChristoph Lameter 		.mode		= 0644,
10109614634fSChristoph Lameter 		.proc_handler	= &sysctl_min_unmapped_ratio_sysctl_handler,
10119614634fSChristoph Lameter 		.strategy	= &sysctl_intvec,
10129614634fSChristoph Lameter 		.extra1		= &zero,
10139614634fSChristoph Lameter 		.extra2		= &one_hundred,
10149614634fSChristoph Lameter 	},
10150ff38490SChristoph Lameter 	{
10160ff38490SChristoph Lameter 		.ctl_name	= VM_MIN_SLAB,
10170ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
10180ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
10190ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
10200ff38490SChristoph Lameter 		.mode		= 0644,
10210ff38490SChristoph Lameter 		.proc_handler	= &sysctl_min_slab_ratio_sysctl_handler,
10220ff38490SChristoph Lameter 		.strategy	= &sysctl_intvec,
10230ff38490SChristoph Lameter 		.extra1		= &zero,
10240ff38490SChristoph Lameter 		.extra2		= &one_hundred,
10250ff38490SChristoph Lameter 	},
10261743660bSChristoph Lameter #endif
1027e6e5494cSIngo Molnar #ifdef CONFIG_X86_32
1028e6e5494cSIngo Molnar 	{
1029e6e5494cSIngo Molnar 		.ctl_name	= VM_VDSO_ENABLED,
1030e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
1031e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
1032e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
1033e6e5494cSIngo Molnar 		.mode		= 0644,
1034e6e5494cSIngo Molnar 		.proc_handler	= &proc_dointvec,
1035e6e5494cSIngo Molnar 		.strategy	= &sysctl_intvec,
1036e6e5494cSIngo Molnar 		.extra1		= &zero,
1037e6e5494cSIngo Molnar 	},
1038e6e5494cSIngo Molnar #endif
10391da177e4SLinus Torvalds 	{ .ctl_name = 0 }
10401da177e4SLinus Torvalds };
10411da177e4SLinus Torvalds 
10421da177e4SLinus Torvalds static ctl_table fs_table[] = {
10431da177e4SLinus Torvalds 	{
10441da177e4SLinus Torvalds 		.ctl_name	= FS_NRINODE,
10451da177e4SLinus Torvalds 		.procname	= "inode-nr",
10461da177e4SLinus Torvalds 		.data		= &inodes_stat,
10471da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
10481da177e4SLinus Torvalds 		.mode		= 0444,
10491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10501da177e4SLinus Torvalds 	},
10511da177e4SLinus Torvalds 	{
10521da177e4SLinus Torvalds 		.ctl_name	= FS_STATINODE,
10531da177e4SLinus Torvalds 		.procname	= "inode-state",
10541da177e4SLinus Torvalds 		.data		= &inodes_stat,
10551da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
10561da177e4SLinus Torvalds 		.mode		= 0444,
10571da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10581da177e4SLinus Torvalds 	},
10591da177e4SLinus Torvalds 	{
10601da177e4SLinus Torvalds 		.ctl_name	= FS_NRFILE,
10611da177e4SLinus Torvalds 		.procname	= "file-nr",
10621da177e4SLinus Torvalds 		.data		= &files_stat,
10631da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
10641da177e4SLinus Torvalds 		.mode		= 0444,
1065529bf6beSDipankar Sarma 		.proc_handler	= &proc_nr_files,
10661da177e4SLinus Torvalds 	},
10671da177e4SLinus Torvalds 	{
10681da177e4SLinus Torvalds 		.ctl_name	= FS_MAXFILE,
10691da177e4SLinus Torvalds 		.procname	= "file-max",
10701da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
10711da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
10721da177e4SLinus Torvalds 		.mode		= 0644,
10731da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10741da177e4SLinus Torvalds 	},
10751da177e4SLinus Torvalds 	{
10761da177e4SLinus Torvalds 		.ctl_name	= FS_DENTRY,
10771da177e4SLinus Torvalds 		.procname	= "dentry-state",
10781da177e4SLinus Torvalds 		.data		= &dentry_stat,
10791da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
10801da177e4SLinus Torvalds 		.mode		= 0444,
10811da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10821da177e4SLinus Torvalds 	},
10831da177e4SLinus Torvalds 	{
10841da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWUID,
10851da177e4SLinus Torvalds 		.procname	= "overflowuid",
10861da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
10871da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
10881da177e4SLinus Torvalds 		.mode		= 0644,
10891da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
10901da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10911da177e4SLinus Torvalds 		.extra1		= &minolduid,
10921da177e4SLinus Torvalds 		.extra2		= &maxolduid,
10931da177e4SLinus Torvalds 	},
10941da177e4SLinus Torvalds 	{
10951da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWGID,
10961da177e4SLinus Torvalds 		.procname	= "overflowgid",
10971da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
10981da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
10991da177e4SLinus Torvalds 		.mode		= 0644,
11001da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
11011da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11021da177e4SLinus Torvalds 		.extra1		= &minolduid,
11031da177e4SLinus Torvalds 		.extra2		= &maxolduid,
11041da177e4SLinus Torvalds 	},
11051da177e4SLinus Torvalds 	{
11061da177e4SLinus Torvalds 		.ctl_name	= FS_LEASES,
11071da177e4SLinus Torvalds 		.procname	= "leases-enable",
11081da177e4SLinus Torvalds 		.data		= &leases_enable,
11091da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
11101da177e4SLinus Torvalds 		.mode		= 0644,
11111da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11121da177e4SLinus Torvalds 	},
11131da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
11141da177e4SLinus Torvalds 	{
11151da177e4SLinus Torvalds 		.ctl_name	= FS_DIR_NOTIFY,
11161da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
11171da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
11181da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
11191da177e4SLinus Torvalds 		.mode		= 0644,
11201da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11211da177e4SLinus Torvalds 	},
11221da177e4SLinus Torvalds #endif
11231da177e4SLinus Torvalds #ifdef CONFIG_MMU
11241da177e4SLinus Torvalds 	{
11251da177e4SLinus Torvalds 		.ctl_name	= FS_LEASE_TIME,
11261da177e4SLinus Torvalds 		.procname	= "lease-break-time",
11271da177e4SLinus Torvalds 		.data		= &lease_break_time,
11281da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
11291da177e4SLinus Torvalds 		.mode		= 0644,
11301da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11311da177e4SLinus Torvalds 	},
11321da177e4SLinus Torvalds 	{
11331da177e4SLinus Torvalds 		.ctl_name	= FS_AIO_NR,
11341da177e4SLinus Torvalds 		.procname	= "aio-nr",
11351da177e4SLinus Torvalds 		.data		= &aio_nr,
11361da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
11371da177e4SLinus Torvalds 		.mode		= 0444,
1138d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
11391da177e4SLinus Torvalds 	},
11401da177e4SLinus Torvalds 	{
11411da177e4SLinus Torvalds 		.ctl_name	= FS_AIO_MAX_NR,
11421da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
11431da177e4SLinus Torvalds 		.data		= &aio_max_nr,
11441da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
11451da177e4SLinus Torvalds 		.mode		= 0644,
1146d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
11471da177e4SLinus Torvalds 	},
11482d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
11490399cb08SRobert Love 	{
11500399cb08SRobert Love 		.ctl_name	= FS_INOTIFY,
11510399cb08SRobert Love 		.procname	= "inotify",
11520399cb08SRobert Love 		.mode		= 0555,
11530399cb08SRobert Love 		.child		= inotify_table,
11540399cb08SRobert Love 	},
11550399cb08SRobert Love #endif
11561da177e4SLinus Torvalds #endif
1157d6e71144SAlan Cox 	{
1158d6e71144SAlan Cox 		.ctl_name	= KERN_SETUID_DUMPABLE,
1159d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1160d6e71144SAlan Cox 		.data		= &suid_dumpable,
1161d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1162d6e71144SAlan Cox 		.mode		= 0644,
1163d6e71144SAlan Cox 		.proc_handler	= &proc_dointvec,
1164d6e71144SAlan Cox 	},
11651da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11661da177e4SLinus Torvalds };
11671da177e4SLinus Torvalds 
11681da177e4SLinus Torvalds static ctl_table debug_table[] = {
11691da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11701da177e4SLinus Torvalds };
11711da177e4SLinus Torvalds 
11721da177e4SLinus Torvalds static ctl_table dev_table[] = {
11731da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11741da177e4SLinus Torvalds };
11751da177e4SLinus Torvalds 
11761da177e4SLinus Torvalds extern void init_irq_proc (void);
11771da177e4SLinus Torvalds 
1178330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1179330d57fbSAl Viro 
1180330d57fbSAl Viro /* called under sysctl_lock */
1181330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1182330d57fbSAl Viro {
1183330d57fbSAl Viro 	if (unlikely(p->unregistering))
1184330d57fbSAl Viro 		return 0;
1185330d57fbSAl Viro 	p->used++;
1186330d57fbSAl Viro 	return 1;
1187330d57fbSAl Viro }
1188330d57fbSAl Viro 
1189330d57fbSAl Viro /* called under sysctl_lock */
1190330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1191330d57fbSAl Viro {
1192330d57fbSAl Viro 	if (!--p->used)
1193330d57fbSAl Viro 		if (unlikely(p->unregistering))
1194330d57fbSAl Viro 			complete(p->unregistering);
1195330d57fbSAl Viro }
1196330d57fbSAl Viro 
1197330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1198330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1199330d57fbSAl Viro {
1200330d57fbSAl Viro 	/*
1201330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1202330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1203330d57fbSAl Viro 	 */
1204330d57fbSAl Viro 	if (unlikely(p->used)) {
1205330d57fbSAl Viro 		struct completion wait;
1206330d57fbSAl Viro 		init_completion(&wait);
1207330d57fbSAl Viro 		p->unregistering = &wait;
1208330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1209330d57fbSAl Viro 		wait_for_completion(&wait);
1210330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1211330d57fbSAl Viro 	}
1212330d57fbSAl Viro 	/*
1213330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1214330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1215330d57fbSAl Viro 	 */
1216330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1217330d57fbSAl Viro }
1218330d57fbSAl Viro 
12191da177e4SLinus Torvalds void __init sysctl_init(void)
12201da177e4SLinus Torvalds {
1221b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
1222330d57fbSAl Viro 	register_proc_table(root_table, proc_sys_root, &root_table_header);
12231da177e4SLinus Torvalds 	init_irq_proc();
12241da177e4SLinus Torvalds #endif
12251da177e4SLinus Torvalds }
12261da177e4SLinus Torvalds 
1227b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
12281da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
12291da177e4SLinus Torvalds 	       void __user *newval, size_t newlen)
12301da177e4SLinus Torvalds {
12311da177e4SLinus Torvalds 	struct list_head *tmp;
1232330d57fbSAl Viro 	int error = -ENOTDIR;
12331da177e4SLinus Torvalds 
12341da177e4SLinus Torvalds 	if (nlen <= 0 || nlen >= CTL_MAXNAME)
12351da177e4SLinus Torvalds 		return -ENOTDIR;
12361da177e4SLinus Torvalds 	if (oldval) {
12371da177e4SLinus Torvalds 		int old_len;
12381da177e4SLinus Torvalds 		if (!oldlenp || get_user(old_len, oldlenp))
12391da177e4SLinus Torvalds 			return -EFAULT;
12401da177e4SLinus Torvalds 	}
1241330d57fbSAl Viro 	spin_lock(&sysctl_lock);
12421da177e4SLinus Torvalds 	tmp = &root_table_header.ctl_entry;
12431da177e4SLinus Torvalds 	do {
12441da177e4SLinus Torvalds 		struct ctl_table_header *head =
12451da177e4SLinus Torvalds 			list_entry(tmp, struct ctl_table_header, ctl_entry);
12461da177e4SLinus Torvalds 		void *context = NULL;
1247330d57fbSAl Viro 
1248330d57fbSAl Viro 		if (!use_table(head))
1249330d57fbSAl Viro 			continue;
1250330d57fbSAl Viro 
1251330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1252330d57fbSAl Viro 
1253330d57fbSAl Viro 		error = parse_table(name, nlen, oldval, oldlenp,
12541da177e4SLinus Torvalds 					newval, newlen, head->ctl_table,
12551da177e4SLinus Torvalds 					&context);
12561da177e4SLinus Torvalds 		kfree(context);
1257330d57fbSAl Viro 
1258330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1259330d57fbSAl Viro 		unuse_table(head);
12601da177e4SLinus Torvalds 		if (error != -ENOTDIR)
1261330d57fbSAl Viro 			break;
1262330d57fbSAl Viro 	} while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1263330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
12641da177e4SLinus Torvalds 	return error;
12651da177e4SLinus Torvalds }
12661da177e4SLinus Torvalds 
12671da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
12681da177e4SLinus Torvalds {
12691da177e4SLinus Torvalds 	struct __sysctl_args tmp;
12701da177e4SLinus Torvalds 	int error;
12711da177e4SLinus Torvalds 
12721da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
12731da177e4SLinus Torvalds 		return -EFAULT;
12741da177e4SLinus Torvalds 
12751da177e4SLinus Torvalds 	lock_kernel();
12761da177e4SLinus Torvalds 	error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
12771da177e4SLinus Torvalds 			  tmp.newval, tmp.newlen);
12781da177e4SLinus Torvalds 	unlock_kernel();
12791da177e4SLinus Torvalds 	return error;
12801da177e4SLinus Torvalds }
1281b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
12821da177e4SLinus Torvalds 
12831da177e4SLinus Torvalds /*
12841da177e4SLinus Torvalds  * ctl_perm does NOT grant the superuser all rights automatically, because
12851da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
12861da177e4SLinus Torvalds  */
12871da177e4SLinus Torvalds 
12881da177e4SLinus Torvalds static int test_perm(int mode, int op)
12891da177e4SLinus Torvalds {
12901da177e4SLinus Torvalds 	if (!current->euid)
12911da177e4SLinus Torvalds 		mode >>= 6;
12921da177e4SLinus Torvalds 	else if (in_egroup_p(0))
12931da177e4SLinus Torvalds 		mode >>= 3;
12941da177e4SLinus Torvalds 	if ((mode & op & 0007) == op)
12951da177e4SLinus Torvalds 		return 0;
12961da177e4SLinus Torvalds 	return -EACCES;
12971da177e4SLinus Torvalds }
12981da177e4SLinus Torvalds 
12991da177e4SLinus Torvalds static inline int ctl_perm(ctl_table *table, int op)
13001da177e4SLinus Torvalds {
13011da177e4SLinus Torvalds 	int error;
13021da177e4SLinus Torvalds 	error = security_sysctl(table, op);
13031da177e4SLinus Torvalds 	if (error)
13041da177e4SLinus Torvalds 		return error;
13051da177e4SLinus Torvalds 	return test_perm(table->mode, op);
13061da177e4SLinus Torvalds }
13071da177e4SLinus Torvalds 
1308b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
13091da177e4SLinus Torvalds static int parse_table(int __user *name, int nlen,
13101da177e4SLinus Torvalds 		       void __user *oldval, size_t __user *oldlenp,
13111da177e4SLinus Torvalds 		       void __user *newval, size_t newlen,
13121da177e4SLinus Torvalds 		       ctl_table *table, void **context)
13131da177e4SLinus Torvalds {
13141da177e4SLinus Torvalds 	int n;
13151da177e4SLinus Torvalds repeat:
13161da177e4SLinus Torvalds 	if (!nlen)
13171da177e4SLinus Torvalds 		return -ENOTDIR;
13181da177e4SLinus Torvalds 	if (get_user(n, name))
13191da177e4SLinus Torvalds 		return -EFAULT;
1320d99f160aSEric W. Biederman 	for ( ; table->ctl_name || table->procname; table++) {
1321d99f160aSEric W. Biederman 		if (!table->ctl_name)
1322d99f160aSEric W. Biederman 			continue;
13231da177e4SLinus Torvalds 		if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
13241da177e4SLinus Torvalds 			int error;
13251da177e4SLinus Torvalds 			if (table->child) {
13261da177e4SLinus Torvalds 				if (ctl_perm(table, 001))
13271da177e4SLinus Torvalds 					return -EPERM;
13281da177e4SLinus Torvalds 				if (table->strategy) {
13291da177e4SLinus Torvalds 					error = table->strategy(
13301da177e4SLinus Torvalds 						table, name, nlen,
13311da177e4SLinus Torvalds 						oldval, oldlenp,
13321da177e4SLinus Torvalds 						newval, newlen, context);
13331da177e4SLinus Torvalds 					if (error)
13341da177e4SLinus Torvalds 						return error;
13351da177e4SLinus Torvalds 				}
13361da177e4SLinus Torvalds 				name++;
13371da177e4SLinus Torvalds 				nlen--;
13381da177e4SLinus Torvalds 				table = table->child;
13391da177e4SLinus Torvalds 				goto repeat;
13401da177e4SLinus Torvalds 			}
13411da177e4SLinus Torvalds 			error = do_sysctl_strategy(table, name, nlen,
13421da177e4SLinus Torvalds 						   oldval, oldlenp,
13431da177e4SLinus Torvalds 						   newval, newlen, context);
13441da177e4SLinus Torvalds 			return error;
13451da177e4SLinus Torvalds 		}
13461da177e4SLinus Torvalds 	}
13471da177e4SLinus Torvalds 	return -ENOTDIR;
13481da177e4SLinus Torvalds }
13491da177e4SLinus Torvalds 
13501da177e4SLinus Torvalds /* Perform the actual read/write of a sysctl table entry. */
13511da177e4SLinus Torvalds int do_sysctl_strategy (ctl_table *table,
13521da177e4SLinus Torvalds 			int __user *name, int nlen,
13531da177e4SLinus Torvalds 			void __user *oldval, size_t __user *oldlenp,
13541da177e4SLinus Torvalds 			void __user *newval, size_t newlen, void **context)
13551da177e4SLinus Torvalds {
13561da177e4SLinus Torvalds 	int op = 0, rc;
13571da177e4SLinus Torvalds 	size_t len;
13581da177e4SLinus Torvalds 
13591da177e4SLinus Torvalds 	if (oldval)
13601da177e4SLinus Torvalds 		op |= 004;
13611da177e4SLinus Torvalds 	if (newval)
13621da177e4SLinus Torvalds 		op |= 002;
13631da177e4SLinus Torvalds 	if (ctl_perm(table, op))
13641da177e4SLinus Torvalds 		return -EPERM;
13651da177e4SLinus Torvalds 
13661da177e4SLinus Torvalds 	if (table->strategy) {
13671da177e4SLinus Torvalds 		rc = table->strategy(table, name, nlen, oldval, oldlenp,
13681da177e4SLinus Torvalds 				     newval, newlen, context);
13691da177e4SLinus Torvalds 		if (rc < 0)
13701da177e4SLinus Torvalds 			return rc;
13711da177e4SLinus Torvalds 		if (rc > 0)
13721da177e4SLinus Torvalds 			return 0;
13731da177e4SLinus Torvalds 	}
13741da177e4SLinus Torvalds 
13751da177e4SLinus Torvalds 	/* If there is no strategy routine, or if the strategy returns
13761da177e4SLinus Torvalds 	 * zero, proceed with automatic r/w */
13771da177e4SLinus Torvalds 	if (table->data && table->maxlen) {
13781da177e4SLinus Torvalds 		if (oldval && oldlenp) {
13791da177e4SLinus Torvalds 			if (get_user(len, oldlenp))
13801da177e4SLinus Torvalds 				return -EFAULT;
13811da177e4SLinus Torvalds 			if (len) {
13821da177e4SLinus Torvalds 				if (len > table->maxlen)
13831da177e4SLinus Torvalds 					len = table->maxlen;
13841da177e4SLinus Torvalds 				if(copy_to_user(oldval, table->data, len))
13851da177e4SLinus Torvalds 					return -EFAULT;
13861da177e4SLinus Torvalds 				if(put_user(len, oldlenp))
13871da177e4SLinus Torvalds 					return -EFAULT;
13881da177e4SLinus Torvalds 			}
13891da177e4SLinus Torvalds 		}
13901da177e4SLinus Torvalds 		if (newval && newlen) {
13911da177e4SLinus Torvalds 			len = newlen;
13921da177e4SLinus Torvalds 			if (len > table->maxlen)
13931da177e4SLinus Torvalds 				len = table->maxlen;
13941da177e4SLinus Torvalds 			if(copy_from_user(table->data, newval, len))
13951da177e4SLinus Torvalds 				return -EFAULT;
13961da177e4SLinus Torvalds 		}
13971da177e4SLinus Torvalds 	}
13981da177e4SLinus Torvalds 	return 0;
13991da177e4SLinus Torvalds }
1400b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
14011da177e4SLinus Torvalds 
14021da177e4SLinus Torvalds /**
14031da177e4SLinus Torvalds  * register_sysctl_table - register a sysctl hierarchy
14041da177e4SLinus Torvalds  * @table: the top-level table structure
14051da177e4SLinus Torvalds  * @insert_at_head: whether the entry should be inserted in front or at the end
14061da177e4SLinus Torvalds  *
14071da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
14081da177e4SLinus Torvalds  * array. An entry with a ctl_name of 0 terminates the table.
14091da177e4SLinus Torvalds  *
14101da177e4SLinus Torvalds  * The members of the &ctl_table structure are used as follows:
14111da177e4SLinus Torvalds  *
14121da177e4SLinus Torvalds  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
14131da177e4SLinus Torvalds  *            must be unique within that level of sysctl
14141da177e4SLinus Torvalds  *
14151da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
14161da177e4SLinus Torvalds  *            enter a sysctl file
14171da177e4SLinus Torvalds  *
14181da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
14191da177e4SLinus Torvalds  *
14201da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
14211da177e4SLinus Torvalds  *
14221da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
14231da177e4SLinus Torvalds  *
14241da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
14251da177e4SLinus Torvalds  *         %NULL.
14261da177e4SLinus Torvalds  *
14271da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
14281da177e4SLinus Torvalds  *
14291da177e4SLinus Torvalds  * strategy - the strategy routine (described below)
14301da177e4SLinus Torvalds  *
14311da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
14321da177e4SLinus Torvalds  *
14331da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
14341da177e4SLinus Torvalds  *
14351da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
14361da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
14371da177e4SLinus Torvalds  *
14381da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
14391da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
14401da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
14411da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
14421da177e4SLinus Torvalds  *
14431da177e4SLinus Torvalds  * More sophisticated management can be enabled by the provision of a
14441da177e4SLinus Torvalds  * strategy routine with the table entry.  This will be called before
14451da177e4SLinus Torvalds  * any automatic read or write of the data is performed.
14461da177e4SLinus Torvalds  *
14471da177e4SLinus Torvalds  * The strategy routine may return
14481da177e4SLinus Torvalds  *
14491da177e4SLinus Torvalds  * < 0 - Error occurred (error is passed to user process)
14501da177e4SLinus Torvalds  *
14511da177e4SLinus Torvalds  * 0   - OK - proceed with automatic read or write.
14521da177e4SLinus Torvalds  *
14531da177e4SLinus Torvalds  * > 0 - OK - read or write has been done by the strategy routine, so
14541da177e4SLinus Torvalds  *       return immediately.
14551da177e4SLinus Torvalds  *
14561da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
14571da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
14581da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
14591da177e4SLinus Torvalds  * cover common cases -
14601da177e4SLinus Torvalds  *
14611da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
14621da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
14631da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
14641da177e4SLinus Torvalds  *
14651da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
14661da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
14671da177e4SLinus Torvalds  *
14681da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
14691da177e4SLinus Torvalds  * to the table header on success.
14701da177e4SLinus Torvalds  */
14711da177e4SLinus Torvalds struct ctl_table_header *register_sysctl_table(ctl_table * table,
14721da177e4SLinus Torvalds 					       int insert_at_head)
14731da177e4SLinus Torvalds {
14741da177e4SLinus Torvalds 	struct ctl_table_header *tmp;
14751da177e4SLinus Torvalds 	tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
14761da177e4SLinus Torvalds 	if (!tmp)
14771da177e4SLinus Torvalds 		return NULL;
14781da177e4SLinus Torvalds 	tmp->ctl_table = table;
14791da177e4SLinus Torvalds 	INIT_LIST_HEAD(&tmp->ctl_entry);
1480330d57fbSAl Viro 	tmp->used = 0;
1481330d57fbSAl Viro 	tmp->unregistering = NULL;
1482330d57fbSAl Viro 	spin_lock(&sysctl_lock);
14831da177e4SLinus Torvalds 	if (insert_at_head)
14841da177e4SLinus Torvalds 		list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
14851da177e4SLinus Torvalds 	else
14861da177e4SLinus Torvalds 		list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1487330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
1488b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
1489330d57fbSAl Viro 	register_proc_table(table, proc_sys_root, tmp);
14901da177e4SLinus Torvalds #endif
14911da177e4SLinus Torvalds 	return tmp;
14921da177e4SLinus Torvalds }
14931da177e4SLinus Torvalds 
14941da177e4SLinus Torvalds /**
14951da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
14961da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
14971da177e4SLinus Torvalds  *
14981da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
14991da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
15001da177e4SLinus Torvalds  */
15011da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
15021da177e4SLinus Torvalds {
1503330d57fbSAl Viro 	might_sleep();
1504330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1505330d57fbSAl Viro 	start_unregistering(header);
1506b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
15071da177e4SLinus Torvalds 	unregister_proc_table(header->ctl_table, proc_sys_root);
15081da177e4SLinus Torvalds #endif
1509330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
15101da177e4SLinus Torvalds 	kfree(header);
15111da177e4SLinus Torvalds }
15121da177e4SLinus Torvalds 
1513b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */
1514b89a8171SEric W. Biederman struct ctl_table_header * register_sysctl_table(ctl_table * table,
1515b89a8171SEric W. Biederman 						int insert_at_head)
1516b89a8171SEric W. Biederman {
1517b89a8171SEric W. Biederman 	return NULL;
1518b89a8171SEric W. Biederman }
1519b89a8171SEric W. Biederman 
1520b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table)
1521b89a8171SEric W. Biederman {
1522b89a8171SEric W. Biederman }
1523b89a8171SEric W. Biederman 
1524b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
1525b89a8171SEric W. Biederman 
15261da177e4SLinus Torvalds /*
15271da177e4SLinus Torvalds  * /proc/sys support
15281da177e4SLinus Torvalds  */
15291da177e4SLinus Torvalds 
1530b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
15311da177e4SLinus Torvalds 
15321da177e4SLinus Torvalds /* Scan the sysctl entries in table and add them all into /proc */
1533330d57fbSAl Viro static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
15341da177e4SLinus Torvalds {
15351da177e4SLinus Torvalds 	struct proc_dir_entry *de;
15361da177e4SLinus Torvalds 	int len;
15371da177e4SLinus Torvalds 	mode_t mode;
15381da177e4SLinus Torvalds 
1539d99f160aSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
15401da177e4SLinus Torvalds 		/* Can't do anything without a proc name. */
15411da177e4SLinus Torvalds 		if (!table->procname)
15421da177e4SLinus Torvalds 			continue;
15431da177e4SLinus Torvalds 		/* Maybe we can't do anything with it... */
15441da177e4SLinus Torvalds 		if (!table->proc_handler && !table->child) {
15451da177e4SLinus Torvalds 			printk(KERN_WARNING "SYSCTL: Can't register %s\n",
15461da177e4SLinus Torvalds 				table->procname);
15471da177e4SLinus Torvalds 			continue;
15481da177e4SLinus Torvalds 		}
15491da177e4SLinus Torvalds 
15501da177e4SLinus Torvalds 		len = strlen(table->procname);
15511da177e4SLinus Torvalds 		mode = table->mode;
15521da177e4SLinus Torvalds 
15531da177e4SLinus Torvalds 		de = NULL;
15541da177e4SLinus Torvalds 		if (table->proc_handler)
15551da177e4SLinus Torvalds 			mode |= S_IFREG;
15561da177e4SLinus Torvalds 		else {
15571da177e4SLinus Torvalds 			mode |= S_IFDIR;
15581da177e4SLinus Torvalds 			for (de = root->subdir; de; de = de->next) {
15591da177e4SLinus Torvalds 				if (proc_match(len, table->procname, de))
15601da177e4SLinus Torvalds 					break;
15611da177e4SLinus Torvalds 			}
15621da177e4SLinus Torvalds 			/* If the subdir exists already, de is non-NULL */
15631da177e4SLinus Torvalds 		}
15641da177e4SLinus Torvalds 
15651da177e4SLinus Torvalds 		if (!de) {
15661da177e4SLinus Torvalds 			de = create_proc_entry(table->procname, mode, root);
15671da177e4SLinus Torvalds 			if (!de)
15681da177e4SLinus Torvalds 				continue;
1569330d57fbSAl Viro 			de->set = set;
15701da177e4SLinus Torvalds 			de->data = (void *) table;
15711da177e4SLinus Torvalds 			if (table->proc_handler)
15721da177e4SLinus Torvalds 				de->proc_fops = &proc_sys_file_operations;
15731da177e4SLinus Torvalds 		}
15741da177e4SLinus Torvalds 		table->de = de;
15751da177e4SLinus Torvalds 		if (de->mode & S_IFDIR)
1576330d57fbSAl Viro 			register_proc_table(table->child, de, set);
15771da177e4SLinus Torvalds 	}
15781da177e4SLinus Torvalds }
15791da177e4SLinus Torvalds 
15801da177e4SLinus Torvalds /*
15811da177e4SLinus Torvalds  * Unregister a /proc sysctl table and any subdirectories.
15821da177e4SLinus Torvalds  */
15831da177e4SLinus Torvalds static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
15841da177e4SLinus Torvalds {
15851da177e4SLinus Torvalds 	struct proc_dir_entry *de;
1586d99f160aSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
15871da177e4SLinus Torvalds 		if (!(de = table->de))
15881da177e4SLinus Torvalds 			continue;
15891da177e4SLinus Torvalds 		if (de->mode & S_IFDIR) {
15901da177e4SLinus Torvalds 			if (!table->child) {
15911da177e4SLinus Torvalds 				printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
15921da177e4SLinus Torvalds 				continue;
15931da177e4SLinus Torvalds 			}
15941da177e4SLinus Torvalds 			unregister_proc_table(table->child, de);
15951da177e4SLinus Torvalds 
15961da177e4SLinus Torvalds 			/* Don't unregister directories which still have entries.. */
15971da177e4SLinus Torvalds 			if (de->subdir)
15981da177e4SLinus Torvalds 				continue;
15991da177e4SLinus Torvalds 		}
16001da177e4SLinus Torvalds 
1601330d57fbSAl Viro 		/*
1602330d57fbSAl Viro 		 * In any case, mark the entry as goner; we'll keep it
1603330d57fbSAl Viro 		 * around if it's busy, but we'll know to do nothing with
1604330d57fbSAl Viro 		 * its fields.  We are under sysctl_lock here.
1605330d57fbSAl Viro 		 */
1606330d57fbSAl Viro 		de->data = NULL;
1607330d57fbSAl Viro 
16081da177e4SLinus Torvalds 		/* Don't unregister proc entries that are still being used.. */
16091da177e4SLinus Torvalds 		if (atomic_read(&de->count))
16101da177e4SLinus Torvalds 			continue;
16111da177e4SLinus Torvalds 
16121da177e4SLinus Torvalds 		table->de = NULL;
16131da177e4SLinus Torvalds 		remove_proc_entry(table->procname, root);
16141da177e4SLinus Torvalds 	}
16151da177e4SLinus Torvalds }
16161da177e4SLinus Torvalds 
16171da177e4SLinus Torvalds static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
16181da177e4SLinus Torvalds 			  size_t count, loff_t *ppos)
16191da177e4SLinus Torvalds {
16201da177e4SLinus Torvalds 	int op;
1621f3a43f3fSJosef "Jeff" Sipek 	struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
16221da177e4SLinus Torvalds 	struct ctl_table *table;
16231da177e4SLinus Torvalds 	size_t res;
1624330d57fbSAl Viro 	ssize_t error = -ENOTDIR;
16251da177e4SLinus Torvalds 
1626330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1627330d57fbSAl Viro 	if (de && de->data && use_table(de->set)) {
1628330d57fbSAl Viro 		/*
1629330d57fbSAl Viro 		 * at that point we know that sysctl was not unregistered
1630330d57fbSAl Viro 		 * and won't be until we finish
1631330d57fbSAl Viro 		 */
1632330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
16331da177e4SLinus Torvalds 		table = (struct ctl_table *) de->data;
16341da177e4SLinus Torvalds 		if (!table || !table->proc_handler)
1635330d57fbSAl Viro 			goto out;
1636330d57fbSAl Viro 		error = -EPERM;
16371da177e4SLinus Torvalds 		op = (write ? 002 : 004);
16381da177e4SLinus Torvalds 		if (ctl_perm(table, op))
1639330d57fbSAl Viro 			goto out;
16401da177e4SLinus Torvalds 
1641330d57fbSAl Viro 		/* careful: calling conventions are nasty here */
16421da177e4SLinus Torvalds 		res = count;
1643330d57fbSAl Viro 		error = (*table->proc_handler)(table, write, file,
1644330d57fbSAl Viro 						buf, &res, ppos);
1645330d57fbSAl Viro 		if (!error)
1646330d57fbSAl Viro 			error = res;
1647330d57fbSAl Viro 	out:
1648330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1649330d57fbSAl Viro 		unuse_table(de->set);
1650330d57fbSAl Viro 	}
1651330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
16521da177e4SLinus Torvalds 	return error;
16531da177e4SLinus Torvalds }
16541da177e4SLinus Torvalds 
16551da177e4SLinus Torvalds static int proc_opensys(struct inode *inode, struct file *file)
16561da177e4SLinus Torvalds {
16571da177e4SLinus Torvalds 	if (file->f_mode & FMODE_WRITE) {
16581da177e4SLinus Torvalds 		/*
16591da177e4SLinus Torvalds 		 * sysctl entries that are not writable,
16601da177e4SLinus Torvalds 		 * are _NOT_ writable, capabilities or not.
16611da177e4SLinus Torvalds 		 */
16621da177e4SLinus Torvalds 		if (!(inode->i_mode & S_IWUSR))
16631da177e4SLinus Torvalds 			return -EPERM;
16641da177e4SLinus Torvalds 	}
16651da177e4SLinus Torvalds 
16661da177e4SLinus Torvalds 	return 0;
16671da177e4SLinus Torvalds }
16681da177e4SLinus Torvalds 
16691da177e4SLinus Torvalds static ssize_t proc_readsys(struct file * file, char __user * buf,
16701da177e4SLinus Torvalds 			    size_t count, loff_t *ppos)
16711da177e4SLinus Torvalds {
16721da177e4SLinus Torvalds 	return do_rw_proc(0, file, buf, count, ppos);
16731da177e4SLinus Torvalds }
16741da177e4SLinus Torvalds 
16751da177e4SLinus Torvalds static ssize_t proc_writesys(struct file * file, const char __user * buf,
16761da177e4SLinus Torvalds 			     size_t count, loff_t *ppos)
16771da177e4SLinus Torvalds {
16781da177e4SLinus Torvalds 	return do_rw_proc(1, file, (char __user *) buf, count, ppos);
16791da177e4SLinus Torvalds }
16801da177e4SLinus Torvalds 
1681b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write,
1682b1ba4dddSAdrian Bunk 			   struct file *filp, void __user *buffer,
1683b1ba4dddSAdrian Bunk 			   size_t *lenp, loff_t *ppos)
1684f5dd3d6fSSam Vilain {
1685f5dd3d6fSSam Vilain 	size_t len;
1686f5dd3d6fSSam Vilain 	char __user *p;
1687f5dd3d6fSSam Vilain 	char c;
1688f5dd3d6fSSam Vilain 
1689f5dd3d6fSSam Vilain 	if (!data || !maxlen || !*lenp ||
1690f5dd3d6fSSam Vilain 	    (*ppos && !write)) {
1691f5dd3d6fSSam Vilain 		*lenp = 0;
1692f5dd3d6fSSam Vilain 		return 0;
1693f5dd3d6fSSam Vilain 	}
1694f5dd3d6fSSam Vilain 
1695f5dd3d6fSSam Vilain 	if (write) {
1696f5dd3d6fSSam Vilain 		len = 0;
1697f5dd3d6fSSam Vilain 		p = buffer;
1698f5dd3d6fSSam Vilain 		while (len < *lenp) {
1699f5dd3d6fSSam Vilain 			if (get_user(c, p++))
1700f5dd3d6fSSam Vilain 				return -EFAULT;
1701f5dd3d6fSSam Vilain 			if (c == 0 || c == '\n')
1702f5dd3d6fSSam Vilain 				break;
1703f5dd3d6fSSam Vilain 			len++;
1704f5dd3d6fSSam Vilain 		}
1705f5dd3d6fSSam Vilain 		if (len >= maxlen)
1706f5dd3d6fSSam Vilain 			len = maxlen-1;
1707f5dd3d6fSSam Vilain 		if(copy_from_user(data, buffer, len))
1708f5dd3d6fSSam Vilain 			return -EFAULT;
1709f5dd3d6fSSam Vilain 		((char *) data)[len] = 0;
1710f5dd3d6fSSam Vilain 		*ppos += *lenp;
1711f5dd3d6fSSam Vilain 	} else {
1712f5dd3d6fSSam Vilain 		len = strlen(data);
1713f5dd3d6fSSam Vilain 		if (len > maxlen)
1714f5dd3d6fSSam Vilain 			len = maxlen;
1715f5dd3d6fSSam Vilain 		if (len > *lenp)
1716f5dd3d6fSSam Vilain 			len = *lenp;
1717f5dd3d6fSSam Vilain 		if (len)
1718f5dd3d6fSSam Vilain 			if(copy_to_user(buffer, data, len))
1719f5dd3d6fSSam Vilain 				return -EFAULT;
1720f5dd3d6fSSam Vilain 		if (len < *lenp) {
1721f5dd3d6fSSam Vilain 			if(put_user('\n', ((char __user *) buffer) + len))
1722f5dd3d6fSSam Vilain 				return -EFAULT;
1723f5dd3d6fSSam Vilain 			len++;
1724f5dd3d6fSSam Vilain 		}
1725f5dd3d6fSSam Vilain 		*lenp = len;
1726f5dd3d6fSSam Vilain 		*ppos += len;
1727f5dd3d6fSSam Vilain 	}
1728f5dd3d6fSSam Vilain 	return 0;
1729f5dd3d6fSSam Vilain }
1730f5dd3d6fSSam Vilain 
17311da177e4SLinus Torvalds /**
17321da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
17331da177e4SLinus Torvalds  * @table: the sysctl table
17341da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
17351da177e4SLinus Torvalds  * @filp: the file structure
17361da177e4SLinus Torvalds  * @buffer: the user buffer
17371da177e4SLinus Torvalds  * @lenp: the size of the user buffer
17381da177e4SLinus Torvalds  * @ppos: file position
17391da177e4SLinus Torvalds  *
17401da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
17411da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
17421da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
17431da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
17441da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
17451da177e4SLinus Torvalds  * not large enough.
17461da177e4SLinus Torvalds  *
17471da177e4SLinus Torvalds  * Returns 0 on success.
17481da177e4SLinus Torvalds  */
17491da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
17501da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
17511da177e4SLinus Torvalds {
1752f5dd3d6fSSam Vilain 	return _proc_do_string(table->data, table->maxlen, write, filp,
1753f5dd3d6fSSam Vilain 			       buffer, lenp, ppos);
17541da177e4SLinus Torvalds }
17551da177e4SLinus Torvalds 
17561da177e4SLinus Torvalds /*
17571da177e4SLinus Torvalds  *	Special case of dostring for the UTS structure. This has locks
17581da177e4SLinus Torvalds  *	to observe. Should this be in kernel/sys.c ????
17591da177e4SLinus Torvalds  */
17601da177e4SLinus Torvalds 
17618218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
17621da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
17631da177e4SLinus Torvalds {
17641da177e4SLinus Torvalds 	int r;
1765cf9f151cSEric W. Biederman 	void *which;
1766cf9f151cSEric W. Biederman 	which = get_uts(table, write);
1767cf9f151cSEric W. Biederman 	r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1768cf9f151cSEric W. Biederman 	put_uts(table, write, which);
17691da177e4SLinus Torvalds 	return r;
17701da177e4SLinus Torvalds }
17711da177e4SLinus Torvalds 
17721da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
17731da177e4SLinus Torvalds 				 int *valp,
17741da177e4SLinus Torvalds 				 int write, void *data)
17751da177e4SLinus Torvalds {
17761da177e4SLinus Torvalds 	if (write) {
17771da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
17781da177e4SLinus Torvalds 	} else {
17791da177e4SLinus Torvalds 		int val = *valp;
17801da177e4SLinus Torvalds 		if (val < 0) {
17811da177e4SLinus Torvalds 			*negp = -1;
17821da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
17831da177e4SLinus Torvalds 		} else {
17841da177e4SLinus Torvalds 			*negp = 0;
17851da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
17861da177e4SLinus Torvalds 		}
17871da177e4SLinus Torvalds 	}
17881da177e4SLinus Torvalds 	return 0;
17891da177e4SLinus Torvalds }
17901da177e4SLinus Torvalds 
1791fcfbd547SKirill Korotaev static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1792fcfbd547SKirill Korotaev 		  int write, struct file *filp, void __user *buffer,
1793fcfbd547SKirill Korotaev 		  size_t *lenp, loff_t *ppos,
17941da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
17951da177e4SLinus Torvalds 			      int write, void *data),
17961da177e4SLinus Torvalds 		  void *data)
17971da177e4SLinus Torvalds {
17981da177e4SLinus Torvalds #define TMPBUFLEN 21
17991da177e4SLinus Torvalds 	int *i, vleft, first=1, neg, val;
18001da177e4SLinus Torvalds 	unsigned long lval;
18011da177e4SLinus Torvalds 	size_t left, len;
18021da177e4SLinus Torvalds 
18031da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
18041da177e4SLinus Torvalds 	char __user *s = buffer;
18051da177e4SLinus Torvalds 
1806fcfbd547SKirill Korotaev 	if (!tbl_data || !table->maxlen || !*lenp ||
18071da177e4SLinus Torvalds 	    (*ppos && !write)) {
18081da177e4SLinus Torvalds 		*lenp = 0;
18091da177e4SLinus Torvalds 		return 0;
18101da177e4SLinus Torvalds 	}
18111da177e4SLinus Torvalds 
1812fcfbd547SKirill Korotaev 	i = (int *) tbl_data;
18131da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
18141da177e4SLinus Torvalds 	left = *lenp;
18151da177e4SLinus Torvalds 
18161da177e4SLinus Torvalds 	if (!conv)
18171da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
18181da177e4SLinus Torvalds 
18191da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
18201da177e4SLinus Torvalds 		if (write) {
18211da177e4SLinus Torvalds 			while (left) {
18221da177e4SLinus Torvalds 				char c;
18231da177e4SLinus Torvalds 				if (get_user(c, s))
18241da177e4SLinus Torvalds 					return -EFAULT;
18251da177e4SLinus Torvalds 				if (!isspace(c))
18261da177e4SLinus Torvalds 					break;
18271da177e4SLinus Torvalds 				left--;
18281da177e4SLinus Torvalds 				s++;
18291da177e4SLinus Torvalds 			}
18301da177e4SLinus Torvalds 			if (!left)
18311da177e4SLinus Torvalds 				break;
18321da177e4SLinus Torvalds 			neg = 0;
18331da177e4SLinus Torvalds 			len = left;
18341da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
18351da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
18361da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
18371da177e4SLinus Torvalds 				return -EFAULT;
18381da177e4SLinus Torvalds 			buf[len] = 0;
18391da177e4SLinus Torvalds 			p = buf;
18401da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
18411da177e4SLinus Torvalds 				neg = 1;
1842bd9b0bacSBP, Praveen 				p++;
18431da177e4SLinus Torvalds 			}
18441da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
18451da177e4SLinus Torvalds 				break;
18461da177e4SLinus Torvalds 
18471da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
18481da177e4SLinus Torvalds 
18491da177e4SLinus Torvalds 			len = p-buf;
18501da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
18511da177e4SLinus Torvalds 				break;
18521da177e4SLinus Torvalds 			if (neg)
18531da177e4SLinus Torvalds 				val = -val;
18541da177e4SLinus Torvalds 			s += len;
18551da177e4SLinus Torvalds 			left -= len;
18561da177e4SLinus Torvalds 
18571da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
18581da177e4SLinus Torvalds 				break;
18591da177e4SLinus Torvalds 		} else {
18601da177e4SLinus Torvalds 			p = buf;
18611da177e4SLinus Torvalds 			if (!first)
18621da177e4SLinus Torvalds 				*p++ = '\t';
18631da177e4SLinus Torvalds 
18641da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
18651da177e4SLinus Torvalds 				break;
18661da177e4SLinus Torvalds 
18671da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
18681da177e4SLinus Torvalds 			len = strlen(buf);
18691da177e4SLinus Torvalds 			if (len > left)
18701da177e4SLinus Torvalds 				len = left;
18711da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
18721da177e4SLinus Torvalds 				return -EFAULT;
18731da177e4SLinus Torvalds 			left -= len;
18741da177e4SLinus Torvalds 			s += len;
18751da177e4SLinus Torvalds 		}
18761da177e4SLinus Torvalds 	}
18771da177e4SLinus Torvalds 
18781da177e4SLinus Torvalds 	if (!write && !first && left) {
18791da177e4SLinus Torvalds 		if(put_user('\n', s))
18801da177e4SLinus Torvalds 			return -EFAULT;
18811da177e4SLinus Torvalds 		left--, s++;
18821da177e4SLinus Torvalds 	}
18831da177e4SLinus Torvalds 	if (write) {
18841da177e4SLinus Torvalds 		while (left) {
18851da177e4SLinus Torvalds 			char c;
18861da177e4SLinus Torvalds 			if (get_user(c, s++))
18871da177e4SLinus Torvalds 				return -EFAULT;
18881da177e4SLinus Torvalds 			if (!isspace(c))
18891da177e4SLinus Torvalds 				break;
18901da177e4SLinus Torvalds 			left--;
18911da177e4SLinus Torvalds 		}
18921da177e4SLinus Torvalds 	}
18931da177e4SLinus Torvalds 	if (write && first)
18941da177e4SLinus Torvalds 		return -EINVAL;
18951da177e4SLinus Torvalds 	*lenp -= left;
18961da177e4SLinus Torvalds 	*ppos += *lenp;
18971da177e4SLinus Torvalds 	return 0;
18981da177e4SLinus Torvalds #undef TMPBUFLEN
18991da177e4SLinus Torvalds }
19001da177e4SLinus Torvalds 
1901fcfbd547SKirill Korotaev static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1902fcfbd547SKirill Korotaev 		  void __user *buffer, size_t *lenp, loff_t *ppos,
1903fcfbd547SKirill Korotaev 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1904fcfbd547SKirill Korotaev 			      int write, void *data),
1905fcfbd547SKirill Korotaev 		  void *data)
1906fcfbd547SKirill Korotaev {
1907fcfbd547SKirill Korotaev 	return __do_proc_dointvec(table->data, table, write, filp,
1908fcfbd547SKirill Korotaev 			buffer, lenp, ppos, conv, data);
1909fcfbd547SKirill Korotaev }
1910fcfbd547SKirill Korotaev 
19111da177e4SLinus Torvalds /**
19121da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
19131da177e4SLinus Torvalds  * @table: the sysctl table
19141da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
19151da177e4SLinus Torvalds  * @filp: the file structure
19161da177e4SLinus Torvalds  * @buffer: the user buffer
19171da177e4SLinus Torvalds  * @lenp: the size of the user buffer
19181da177e4SLinus Torvalds  * @ppos: file position
19191da177e4SLinus Torvalds  *
19201da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
19211da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
19221da177e4SLinus Torvalds  *
19231da177e4SLinus Torvalds  * Returns 0 on success.
19241da177e4SLinus Torvalds  */
19251da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
19261da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
19271da177e4SLinus Torvalds {
19281da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
19291da177e4SLinus Torvalds 		    	    NULL,NULL);
19301da177e4SLinus Torvalds }
19311da177e4SLinus Torvalds 
19321da177e4SLinus Torvalds #define OP_SET	0
19331da177e4SLinus Torvalds #define OP_AND	1
19341da177e4SLinus Torvalds #define OP_OR	2
19351da177e4SLinus Torvalds #define OP_MAX	3
19361da177e4SLinus Torvalds #define OP_MIN	4
19371da177e4SLinus Torvalds 
19381da177e4SLinus Torvalds static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
19391da177e4SLinus Torvalds 				      int *valp,
19401da177e4SLinus Torvalds 				      int write, void *data)
19411da177e4SLinus Torvalds {
19421da177e4SLinus Torvalds 	int op = *(int *)data;
19431da177e4SLinus Torvalds 	if (write) {
19441da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
19451da177e4SLinus Torvalds 		switch(op) {
19461da177e4SLinus Torvalds 		case OP_SET:	*valp = val; break;
19471da177e4SLinus Torvalds 		case OP_AND:	*valp &= val; break;
19481da177e4SLinus Torvalds 		case OP_OR:	*valp |= val; break;
19491da177e4SLinus Torvalds 		case OP_MAX:	if(*valp < val)
19501da177e4SLinus Torvalds 					*valp = val;
19511da177e4SLinus Torvalds 				break;
19521da177e4SLinus Torvalds 		case OP_MIN:	if(*valp > val)
19531da177e4SLinus Torvalds 				*valp = val;
19541da177e4SLinus Torvalds 				break;
19551da177e4SLinus Torvalds 		}
19561da177e4SLinus Torvalds 	} else {
19571da177e4SLinus Torvalds 		int val = *valp;
19581da177e4SLinus Torvalds 		if (val < 0) {
19591da177e4SLinus Torvalds 			*negp = -1;
19601da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
19611da177e4SLinus Torvalds 		} else {
19621da177e4SLinus Torvalds 			*negp = 0;
19631da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
19641da177e4SLinus Torvalds 		}
19651da177e4SLinus Torvalds 	}
19661da177e4SLinus Torvalds 	return 0;
19671da177e4SLinus Torvalds }
19681da177e4SLinus Torvalds 
19691da177e4SLinus Torvalds /*
19701da177e4SLinus Torvalds  *	init may raise the set.
19711da177e4SLinus Torvalds  */
19721da177e4SLinus Torvalds 
19731da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
19741da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
19751da177e4SLinus Torvalds {
19761da177e4SLinus Torvalds 	int op;
19771da177e4SLinus Torvalds 
19781da177e4SLinus Torvalds 	if (!capable(CAP_SYS_MODULE)) {
19791da177e4SLinus Torvalds 		return -EPERM;
19801da177e4SLinus Torvalds 	}
19811da177e4SLinus Torvalds 
1982f400e198SSukadev Bhattiprolu 	op = is_init(current) ? OP_SET : OP_AND;
19831da177e4SLinus Torvalds 	return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
19841da177e4SLinus Torvalds 				do_proc_dointvec_bset_conv,&op);
19851da177e4SLinus Torvalds }
19861da177e4SLinus Torvalds 
19871da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
19881da177e4SLinus Torvalds 	int *min;
19891da177e4SLinus Torvalds 	int *max;
19901da177e4SLinus Torvalds };
19911da177e4SLinus Torvalds 
19921da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
19931da177e4SLinus Torvalds 					int *valp,
19941da177e4SLinus Torvalds 					int write, void *data)
19951da177e4SLinus Torvalds {
19961da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
19971da177e4SLinus Torvalds 	if (write) {
19981da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
19991da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
20001da177e4SLinus Torvalds 		    (param->max && *param->max < val))
20011da177e4SLinus Torvalds 			return -EINVAL;
20021da177e4SLinus Torvalds 		*valp = val;
20031da177e4SLinus Torvalds 	} else {
20041da177e4SLinus Torvalds 		int val = *valp;
20051da177e4SLinus Torvalds 		if (val < 0) {
20061da177e4SLinus Torvalds 			*negp = -1;
20071da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
20081da177e4SLinus Torvalds 		} else {
20091da177e4SLinus Torvalds 			*negp = 0;
20101da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
20111da177e4SLinus Torvalds 		}
20121da177e4SLinus Torvalds 	}
20131da177e4SLinus Torvalds 	return 0;
20141da177e4SLinus Torvalds }
20151da177e4SLinus Torvalds 
20161da177e4SLinus Torvalds /**
20171da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
20181da177e4SLinus Torvalds  * @table: the sysctl table
20191da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
20201da177e4SLinus Torvalds  * @filp: the file structure
20211da177e4SLinus Torvalds  * @buffer: the user buffer
20221da177e4SLinus Torvalds  * @lenp: the size of the user buffer
20231da177e4SLinus Torvalds  * @ppos: file position
20241da177e4SLinus Torvalds  *
20251da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
20261da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
20271da177e4SLinus Torvalds  *
20281da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
20291da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
20301da177e4SLinus Torvalds  *
20311da177e4SLinus Torvalds  * Returns 0 on success.
20321da177e4SLinus Torvalds  */
20331da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
20341da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
20351da177e4SLinus Torvalds {
20361da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
20371da177e4SLinus Torvalds 		.min = (int *) table->extra1,
20381da177e4SLinus Torvalds 		.max = (int *) table->extra2,
20391da177e4SLinus Torvalds 	};
20401da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
20411da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
20421da177e4SLinus Torvalds }
20431da177e4SLinus Torvalds 
2044fcfbd547SKirill Korotaev static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
20451da177e4SLinus Torvalds 				     struct file *filp,
20461da177e4SLinus Torvalds 				     void __user *buffer,
20471da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
20481da177e4SLinus Torvalds 				     unsigned long convmul,
20491da177e4SLinus Torvalds 				     unsigned long convdiv)
20501da177e4SLinus Torvalds {
20511da177e4SLinus Torvalds #define TMPBUFLEN 21
20521da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
20531da177e4SLinus Torvalds 	int vleft, first=1, neg;
20541da177e4SLinus Torvalds 	size_t len, left;
20551da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
20561da177e4SLinus Torvalds 	char __user *s = buffer;
20571da177e4SLinus Torvalds 
2058fcfbd547SKirill Korotaev 	if (!data || !table->maxlen || !*lenp ||
20591da177e4SLinus Torvalds 	    (*ppos && !write)) {
20601da177e4SLinus Torvalds 		*lenp = 0;
20611da177e4SLinus Torvalds 		return 0;
20621da177e4SLinus Torvalds 	}
20631da177e4SLinus Torvalds 
2064fcfbd547SKirill Korotaev 	i = (unsigned long *) data;
20651da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
20661da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
20671da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
20681da177e4SLinus Torvalds 	left = *lenp;
20691da177e4SLinus Torvalds 
20701da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
20711da177e4SLinus Torvalds 		if (write) {
20721da177e4SLinus Torvalds 			while (left) {
20731da177e4SLinus Torvalds 				char c;
20741da177e4SLinus Torvalds 				if (get_user(c, s))
20751da177e4SLinus Torvalds 					return -EFAULT;
20761da177e4SLinus Torvalds 				if (!isspace(c))
20771da177e4SLinus Torvalds 					break;
20781da177e4SLinus Torvalds 				left--;
20791da177e4SLinus Torvalds 				s++;
20801da177e4SLinus Torvalds 			}
20811da177e4SLinus Torvalds 			if (!left)
20821da177e4SLinus Torvalds 				break;
20831da177e4SLinus Torvalds 			neg = 0;
20841da177e4SLinus Torvalds 			len = left;
20851da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
20861da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
20871da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
20881da177e4SLinus Torvalds 				return -EFAULT;
20891da177e4SLinus Torvalds 			buf[len] = 0;
20901da177e4SLinus Torvalds 			p = buf;
20911da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
20921da177e4SLinus Torvalds 				neg = 1;
2093bd9b0bacSBP, Praveen 				p++;
20941da177e4SLinus Torvalds 			}
20951da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
20961da177e4SLinus Torvalds 				break;
20971da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
20981da177e4SLinus Torvalds 			len = p-buf;
20991da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
21001da177e4SLinus Torvalds 				break;
21011da177e4SLinus Torvalds 			if (neg)
21021da177e4SLinus Torvalds 				val = -val;
21031da177e4SLinus Torvalds 			s += len;
21041da177e4SLinus Torvalds 			left -= len;
21051da177e4SLinus Torvalds 
21061da177e4SLinus Torvalds 			if(neg)
21071da177e4SLinus Torvalds 				continue;
21081da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
21091da177e4SLinus Torvalds 				continue;
21101da177e4SLinus Torvalds 			*i = val;
21111da177e4SLinus Torvalds 		} else {
21121da177e4SLinus Torvalds 			p = buf;
21131da177e4SLinus Torvalds 			if (!first)
21141da177e4SLinus Torvalds 				*p++ = '\t';
21151da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
21161da177e4SLinus Torvalds 			len = strlen(buf);
21171da177e4SLinus Torvalds 			if (len > left)
21181da177e4SLinus Torvalds 				len = left;
21191da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
21201da177e4SLinus Torvalds 				return -EFAULT;
21211da177e4SLinus Torvalds 			left -= len;
21221da177e4SLinus Torvalds 			s += len;
21231da177e4SLinus Torvalds 		}
21241da177e4SLinus Torvalds 	}
21251da177e4SLinus Torvalds 
21261da177e4SLinus Torvalds 	if (!write && !first && left) {
21271da177e4SLinus Torvalds 		if(put_user('\n', s))
21281da177e4SLinus Torvalds 			return -EFAULT;
21291da177e4SLinus Torvalds 		left--, s++;
21301da177e4SLinus Torvalds 	}
21311da177e4SLinus Torvalds 	if (write) {
21321da177e4SLinus Torvalds 		while (left) {
21331da177e4SLinus Torvalds 			char c;
21341da177e4SLinus Torvalds 			if (get_user(c, s++))
21351da177e4SLinus Torvalds 				return -EFAULT;
21361da177e4SLinus Torvalds 			if (!isspace(c))
21371da177e4SLinus Torvalds 				break;
21381da177e4SLinus Torvalds 			left--;
21391da177e4SLinus Torvalds 		}
21401da177e4SLinus Torvalds 	}
21411da177e4SLinus Torvalds 	if (write && first)
21421da177e4SLinus Torvalds 		return -EINVAL;
21431da177e4SLinus Torvalds 	*lenp -= left;
21441da177e4SLinus Torvalds 	*ppos += *lenp;
21451da177e4SLinus Torvalds 	return 0;
21461da177e4SLinus Torvalds #undef TMPBUFLEN
21471da177e4SLinus Torvalds }
21481da177e4SLinus Torvalds 
2149fcfbd547SKirill Korotaev static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2150fcfbd547SKirill Korotaev 				     struct file *filp,
2151fcfbd547SKirill Korotaev 				     void __user *buffer,
2152fcfbd547SKirill Korotaev 				     size_t *lenp, loff_t *ppos,
2153fcfbd547SKirill Korotaev 				     unsigned long convmul,
2154fcfbd547SKirill Korotaev 				     unsigned long convdiv)
2155fcfbd547SKirill Korotaev {
2156fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(table->data, table, write,
2157fcfbd547SKirill Korotaev 			filp, buffer, lenp, ppos, convmul, convdiv);
2158fcfbd547SKirill Korotaev }
2159fcfbd547SKirill Korotaev 
21601da177e4SLinus Torvalds /**
21611da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
21621da177e4SLinus Torvalds  * @table: the sysctl table
21631da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
21641da177e4SLinus Torvalds  * @filp: the file structure
21651da177e4SLinus Torvalds  * @buffer: the user buffer
21661da177e4SLinus Torvalds  * @lenp: the size of the user buffer
21671da177e4SLinus Torvalds  * @ppos: file position
21681da177e4SLinus Torvalds  *
21691da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
21701da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
21711da177e4SLinus Torvalds  *
21721da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
21731da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
21741da177e4SLinus Torvalds  *
21751da177e4SLinus Torvalds  * Returns 0 on success.
21761da177e4SLinus Torvalds  */
21771da177e4SLinus Torvalds int proc_doulongvec_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 do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
21811da177e4SLinus Torvalds }
21821da177e4SLinus Torvalds 
21831da177e4SLinus Torvalds /**
21841da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
21851da177e4SLinus Torvalds  * @table: the sysctl table
21861da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
21871da177e4SLinus Torvalds  * @filp: the file structure
21881da177e4SLinus Torvalds  * @buffer: the user buffer
21891da177e4SLinus Torvalds  * @lenp: the size of the user buffer
21901da177e4SLinus Torvalds  * @ppos: file position
21911da177e4SLinus Torvalds  *
21921da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
21931da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
21941da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
21951da177e4SLinus Torvalds  *
21961da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
21971da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
21981da177e4SLinus Torvalds  *
21991da177e4SLinus Torvalds  * Returns 0 on success.
22001da177e4SLinus Torvalds  */
22011da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
22021da177e4SLinus Torvalds 				      struct file *filp,
22031da177e4SLinus Torvalds 				      void __user *buffer,
22041da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
22051da177e4SLinus Torvalds {
22061da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer,
22071da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
22081da177e4SLinus Torvalds }
22091da177e4SLinus Torvalds 
22101da177e4SLinus Torvalds 
22111da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
22121da177e4SLinus Torvalds 					 int *valp,
22131da177e4SLinus Torvalds 					 int write, void *data)
22141da177e4SLinus Torvalds {
22151da177e4SLinus Torvalds 	if (write) {
2216cba9f33dSBart Samwel 		if (*lvalp > LONG_MAX / HZ)
2217cba9f33dSBart Samwel 			return 1;
22181da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
22191da177e4SLinus Torvalds 	} else {
22201da177e4SLinus Torvalds 		int val = *valp;
22211da177e4SLinus Torvalds 		unsigned long lval;
22221da177e4SLinus Torvalds 		if (val < 0) {
22231da177e4SLinus Torvalds 			*negp = -1;
22241da177e4SLinus Torvalds 			lval = (unsigned long)-val;
22251da177e4SLinus Torvalds 		} else {
22261da177e4SLinus Torvalds 			*negp = 0;
22271da177e4SLinus Torvalds 			lval = (unsigned long)val;
22281da177e4SLinus Torvalds 		}
22291da177e4SLinus Torvalds 		*lvalp = lval / HZ;
22301da177e4SLinus Torvalds 	}
22311da177e4SLinus Torvalds 	return 0;
22321da177e4SLinus Torvalds }
22331da177e4SLinus Torvalds 
22341da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
22351da177e4SLinus Torvalds 						int *valp,
22361da177e4SLinus Torvalds 						int write, void *data)
22371da177e4SLinus Torvalds {
22381da177e4SLinus Torvalds 	if (write) {
2239cba9f33dSBart Samwel 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2240cba9f33dSBart Samwel 			return 1;
22411da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
22421da177e4SLinus Torvalds 	} else {
22431da177e4SLinus Torvalds 		int val = *valp;
22441da177e4SLinus Torvalds 		unsigned long lval;
22451da177e4SLinus Torvalds 		if (val < 0) {
22461da177e4SLinus Torvalds 			*negp = -1;
22471da177e4SLinus Torvalds 			lval = (unsigned long)-val;
22481da177e4SLinus Torvalds 		} else {
22491da177e4SLinus Torvalds 			*negp = 0;
22501da177e4SLinus Torvalds 			lval = (unsigned long)val;
22511da177e4SLinus Torvalds 		}
22521da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
22531da177e4SLinus Torvalds 	}
22541da177e4SLinus Torvalds 	return 0;
22551da177e4SLinus Torvalds }
22561da177e4SLinus Torvalds 
22571da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
22581da177e4SLinus Torvalds 					    int *valp,
22591da177e4SLinus Torvalds 					    int write, void *data)
22601da177e4SLinus Torvalds {
22611da177e4SLinus Torvalds 	if (write) {
22621da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
22631da177e4SLinus Torvalds 	} else {
22641da177e4SLinus Torvalds 		int val = *valp;
22651da177e4SLinus Torvalds 		unsigned long lval;
22661da177e4SLinus Torvalds 		if (val < 0) {
22671da177e4SLinus Torvalds 			*negp = -1;
22681da177e4SLinus Torvalds 			lval = (unsigned long)-val;
22691da177e4SLinus Torvalds 		} else {
22701da177e4SLinus Torvalds 			*negp = 0;
22711da177e4SLinus Torvalds 			lval = (unsigned long)val;
22721da177e4SLinus Torvalds 		}
22731da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
22741da177e4SLinus Torvalds 	}
22751da177e4SLinus Torvalds 	return 0;
22761da177e4SLinus Torvalds }
22771da177e4SLinus Torvalds 
22781da177e4SLinus Torvalds /**
22791da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
22801da177e4SLinus Torvalds  * @table: the sysctl table
22811da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
22821da177e4SLinus Torvalds  * @filp: the file structure
22831da177e4SLinus Torvalds  * @buffer: the user buffer
22841da177e4SLinus Torvalds  * @lenp: the size of the user buffer
22851da177e4SLinus Torvalds  * @ppos: file position
22861da177e4SLinus Torvalds  *
22871da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
22881da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
22891da177e4SLinus Torvalds  * The values read are assumed to be in seconds, and are converted into
22901da177e4SLinus Torvalds  * jiffies.
22911da177e4SLinus Torvalds  *
22921da177e4SLinus Torvalds  * Returns 0 on success.
22931da177e4SLinus Torvalds  */
22941da177e4SLinus Torvalds int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
22951da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
22961da177e4SLinus Torvalds {
22971da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
22981da177e4SLinus Torvalds 		    	    do_proc_dointvec_jiffies_conv,NULL);
22991da177e4SLinus Torvalds }
23001da177e4SLinus Torvalds 
23011da177e4SLinus Torvalds /**
23021da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
23031da177e4SLinus Torvalds  * @table: the sysctl table
23041da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23051da177e4SLinus Torvalds  * @filp: the file structure
23061da177e4SLinus Torvalds  * @buffer: the user buffer
23071da177e4SLinus Torvalds  * @lenp: the size of the user buffer
23081e5d5331SRandy Dunlap  * @ppos: pointer to the file position
23091da177e4SLinus Torvalds  *
23101da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23111da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23121da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
23131da177e4SLinus Torvalds  * are converted into jiffies.
23141da177e4SLinus Torvalds  *
23151da177e4SLinus Torvalds  * Returns 0 on success.
23161da177e4SLinus Torvalds  */
23171da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
23181da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
23191da177e4SLinus Torvalds {
23201da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
23211da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
23221da177e4SLinus Torvalds }
23231da177e4SLinus Torvalds 
23241da177e4SLinus Torvalds /**
23251da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
23261da177e4SLinus Torvalds  * @table: the sysctl table
23271da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23281da177e4SLinus Torvalds  * @filp: the file structure
23291da177e4SLinus Torvalds  * @buffer: the user buffer
23301da177e4SLinus Torvalds  * @lenp: the size of the user buffer
233167be2dd1SMartin Waitz  * @ppos: file position
233267be2dd1SMartin Waitz  * @ppos: the current position in the file
23331da177e4SLinus Torvalds  *
23341da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23351da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23361da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
23371da177e4SLinus Torvalds  * are converted into jiffies.
23381da177e4SLinus Torvalds  *
23391da177e4SLinus Torvalds  * Returns 0 on success.
23401da177e4SLinus Torvalds  */
23411da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
23421da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
23431da177e4SLinus Torvalds {
23441da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
23451da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
23461da177e4SLinus Torvalds }
23471da177e4SLinus Torvalds 
2348fcfbd547SKirill Korotaev #ifdef CONFIG_SYSVIPC
23499bc9a6bdSEric W. Biederman static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2350fcfbd547SKirill Korotaev 	void __user *buffer, size_t *lenp, loff_t *ppos)
2351fcfbd547SKirill Korotaev {
23529bc9a6bdSEric W. Biederman 	void *which;
23539bc9a6bdSEric W. Biederman 	which = get_ipc(table, write);
23549bc9a6bdSEric W. Biederman 	return __do_proc_dointvec(which, table, write, filp, buffer,
23559bc9a6bdSEric W. Biederman 			lenp, ppos, NULL, NULL);
2356fcfbd547SKirill Korotaev }
2357fcfbd547SKirill Korotaev 
23589bc9a6bdSEric W. Biederman static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
23599bc9a6bdSEric W. Biederman 	struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
23609bc9a6bdSEric W. Biederman {
23619bc9a6bdSEric W. Biederman 	void *which;
23629bc9a6bdSEric W. Biederman 	which = get_ipc(table, write);
23639bc9a6bdSEric W. Biederman 	return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2364fcfbd547SKirill Korotaev 			lenp, ppos, 1l, 1l);
2365fcfbd547SKirill Korotaev }
23669bc9a6bdSEric W. Biederman 
2367fcfbd547SKirill Korotaev #endif
2368fcfbd547SKirill Korotaev 
23699ec52099SCedric Le Goater static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
23709ec52099SCedric Le Goater 			   void __user *buffer, size_t *lenp, loff_t *ppos)
23719ec52099SCedric Le Goater {
23729ec52099SCedric Le Goater 	struct pid *new_pid;
23739ec52099SCedric Le Goater 	pid_t tmp;
23749ec52099SCedric Le Goater 	int r;
23759ec52099SCedric Le Goater 
23769ec52099SCedric Le Goater 	tmp = pid_nr(cad_pid);
23779ec52099SCedric Le Goater 
23789ec52099SCedric Le Goater 	r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
23799ec52099SCedric Le Goater 			       lenp, ppos, NULL, NULL);
23809ec52099SCedric Le Goater 	if (r || !write)
23819ec52099SCedric Le Goater 		return r;
23829ec52099SCedric Le Goater 
23839ec52099SCedric Le Goater 	new_pid = find_get_pid(tmp);
23849ec52099SCedric Le Goater 	if (!new_pid)
23859ec52099SCedric Le Goater 		return -ESRCH;
23869ec52099SCedric Le Goater 
23879ec52099SCedric Le Goater 	put_pid(xchg(&cad_pid, new_pid));
23889ec52099SCedric Le Goater 	return 0;
23899ec52099SCedric Le Goater }
23909ec52099SCedric Le Goater 
23911da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
23921da177e4SLinus Torvalds 
23931da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
23941da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
23951da177e4SLinus Torvalds {
23961da177e4SLinus Torvalds 	return -ENOSYS;
23971da177e4SLinus Torvalds }
23981da177e4SLinus Torvalds 
23998218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
24001da177e4SLinus Torvalds 		void __user *buffer, size_t *lenp, loff_t *ppos)
24011da177e4SLinus Torvalds {
24021da177e4SLinus Torvalds 	return -ENOSYS;
24031da177e4SLinus Torvalds }
24041da177e4SLinus Torvalds 
24058218c74cSSerge E. Hallyn #ifdef CONFIG_SYSVIPC
24068218c74cSSerge E. Hallyn static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
24078218c74cSSerge E. Hallyn 		void __user *buffer, size_t *lenp, loff_t *ppos)
24088218c74cSSerge E. Hallyn {
24098218c74cSSerge E. Hallyn 	return -ENOSYS;
24108218c74cSSerge E. Hallyn }
24118218c74cSSerge E. Hallyn #endif
24128218c74cSSerge E. Hallyn 
24131da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
24141da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
24151da177e4SLinus Torvalds {
24161da177e4SLinus Torvalds 	return -ENOSYS;
24171da177e4SLinus Torvalds }
24181da177e4SLinus Torvalds 
24191da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
24201da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
24211da177e4SLinus Torvalds {
24221da177e4SLinus Torvalds 	return -ENOSYS;
24231da177e4SLinus Torvalds }
24241da177e4SLinus Torvalds 
24251da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
24261da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24271da177e4SLinus Torvalds {
24281da177e4SLinus Torvalds 	return -ENOSYS;
24291da177e4SLinus Torvalds }
24301da177e4SLinus Torvalds 
24311da177e4SLinus Torvalds int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
24321da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24331da177e4SLinus Torvalds {
24341da177e4SLinus Torvalds 	return -ENOSYS;
24351da177e4SLinus Torvalds }
24361da177e4SLinus Torvalds 
24371da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
24381da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24391da177e4SLinus Torvalds {
24401da177e4SLinus Torvalds 	return -ENOSYS;
24411da177e4SLinus Torvalds }
24421da177e4SLinus Torvalds 
24431da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
24441da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
24451da177e4SLinus Torvalds {
24461da177e4SLinus Torvalds 	return -ENOSYS;
24471da177e4SLinus Torvalds }
24481da177e4SLinus Torvalds 
24491da177e4SLinus Torvalds int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
24501da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24511da177e4SLinus Torvalds {
24521da177e4SLinus Torvalds 	return -ENOSYS;
24531da177e4SLinus Torvalds }
24541da177e4SLinus Torvalds 
24551da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
24561da177e4SLinus Torvalds 				      struct file *filp,
24571da177e4SLinus Torvalds 				      void __user *buffer,
24581da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
24591da177e4SLinus Torvalds {
24601da177e4SLinus Torvalds     return -ENOSYS;
24611da177e4SLinus Torvalds }
24621da177e4SLinus Torvalds 
24631da177e4SLinus Torvalds 
24641da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
24651da177e4SLinus Torvalds 
24661da177e4SLinus Torvalds 
2467b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
24681da177e4SLinus Torvalds /*
24691da177e4SLinus Torvalds  * General sysctl support routines
24701da177e4SLinus Torvalds  */
24711da177e4SLinus Torvalds 
24721da177e4SLinus Torvalds /* The generic string strategy routine: */
24731da177e4SLinus Torvalds int sysctl_string(ctl_table *table, int __user *name, int nlen,
24741da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
24751da177e4SLinus Torvalds 		  void __user *newval, size_t newlen, void **context)
24761da177e4SLinus Torvalds {
24771da177e4SLinus Torvalds 	if (!table->data || !table->maxlen)
24781da177e4SLinus Torvalds 		return -ENOTDIR;
24791da177e4SLinus Torvalds 
24801da177e4SLinus Torvalds 	if (oldval && oldlenp) {
2481de9e007dSLinus Torvalds 		size_t bufsize;
2482de9e007dSLinus Torvalds 		if (get_user(bufsize, oldlenp))
24831da177e4SLinus Torvalds 			return -EFAULT;
2484de9e007dSLinus Torvalds 		if (bufsize) {
2485de9e007dSLinus Torvalds 			size_t len = strlen(table->data), copied;
2486de9e007dSLinus Torvalds 
2487de9e007dSLinus Torvalds 			/* This shouldn't trigger for a well-formed sysctl */
2488de9e007dSLinus Torvalds 			if (len > table->maxlen)
24891da177e4SLinus Torvalds 				len = table->maxlen;
2490de9e007dSLinus Torvalds 
2491de9e007dSLinus Torvalds 			/* Copy up to a max of bufsize-1 bytes of the string */
2492de9e007dSLinus Torvalds 			copied = (len >= bufsize) ? bufsize - 1 : len;
2493de9e007dSLinus Torvalds 
2494de9e007dSLinus Torvalds 			if (copy_to_user(oldval, table->data, copied) ||
2495de9e007dSLinus Torvalds 			    put_user(0, (char __user *)(oldval + copied)))
24961da177e4SLinus Torvalds 				return -EFAULT;
24971da177e4SLinus Torvalds 			if (put_user(len, oldlenp))
24981da177e4SLinus Torvalds 				return -EFAULT;
24991da177e4SLinus Torvalds 		}
25001da177e4SLinus Torvalds 	}
25011da177e4SLinus Torvalds 	if (newval && newlen) {
2502de9e007dSLinus Torvalds 		size_t len = newlen;
25031da177e4SLinus Torvalds 		if (len > table->maxlen)
25041da177e4SLinus Torvalds 			len = table->maxlen;
25051da177e4SLinus Torvalds 		if(copy_from_user(table->data, newval, len))
25061da177e4SLinus Torvalds 			return -EFAULT;
25071da177e4SLinus Torvalds 		if (len == table->maxlen)
25081da177e4SLinus Torvalds 			len--;
25091da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
25101da177e4SLinus Torvalds 	}
251182c9df82SYi Yang 	return 1;
25121da177e4SLinus Torvalds }
25131da177e4SLinus Torvalds 
25141da177e4SLinus Torvalds /*
25151da177e4SLinus Torvalds  * This function makes sure that all of the integers in the vector
25161da177e4SLinus Torvalds  * are between the minimum and maximum values given in the arrays
25171da177e4SLinus Torvalds  * table->extra1 and table->extra2, respectively.
25181da177e4SLinus Torvalds  */
25191da177e4SLinus Torvalds int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
25201da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
25211da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
25221da177e4SLinus Torvalds {
25231da177e4SLinus Torvalds 
25241da177e4SLinus Torvalds 	if (newval && newlen) {
25251da177e4SLinus Torvalds 		int __user *vec = (int __user *) newval;
25261da177e4SLinus Torvalds 		int *min = (int *) table->extra1;
25271da177e4SLinus Torvalds 		int *max = (int *) table->extra2;
25281da177e4SLinus Torvalds 		size_t length;
25291da177e4SLinus Torvalds 		int i;
25301da177e4SLinus Torvalds 
25311da177e4SLinus Torvalds 		if (newlen % sizeof(int) != 0)
25321da177e4SLinus Torvalds 			return -EINVAL;
25331da177e4SLinus Torvalds 
25341da177e4SLinus Torvalds 		if (!table->extra1 && !table->extra2)
25351da177e4SLinus Torvalds 			return 0;
25361da177e4SLinus Torvalds 
25371da177e4SLinus Torvalds 		if (newlen > table->maxlen)
25381da177e4SLinus Torvalds 			newlen = table->maxlen;
25391da177e4SLinus Torvalds 		length = newlen / sizeof(int);
25401da177e4SLinus Torvalds 
25411da177e4SLinus Torvalds 		for (i = 0; i < length; i++) {
25421da177e4SLinus Torvalds 			int value;
25431da177e4SLinus Torvalds 			if (get_user(value, vec + i))
25441da177e4SLinus Torvalds 				return -EFAULT;
25451da177e4SLinus Torvalds 			if (min && value < min[i])
25461da177e4SLinus Torvalds 				return -EINVAL;
25471da177e4SLinus Torvalds 			if (max && value > max[i])
25481da177e4SLinus Torvalds 				return -EINVAL;
25491da177e4SLinus Torvalds 		}
25501da177e4SLinus Torvalds 	}
25511da177e4SLinus Torvalds 	return 0;
25521da177e4SLinus Torvalds }
25531da177e4SLinus Torvalds 
25541da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
25551da177e4SLinus Torvalds int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
25561da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
25571da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
25581da177e4SLinus Torvalds {
25591da177e4SLinus Torvalds 	if (oldval) {
25601da177e4SLinus Torvalds 		size_t olen;
25611da177e4SLinus Torvalds 		if (oldlenp) {
25621da177e4SLinus Torvalds 			if (get_user(olen, oldlenp))
25631da177e4SLinus Torvalds 				return -EFAULT;
25641da177e4SLinus Torvalds 			if (olen!=sizeof(int))
25651da177e4SLinus Torvalds 				return -EINVAL;
25661da177e4SLinus Torvalds 		}
25671da177e4SLinus Torvalds 		if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
25681da177e4SLinus Torvalds 		    (oldlenp && put_user(sizeof(int),oldlenp)))
25691da177e4SLinus Torvalds 			return -EFAULT;
25701da177e4SLinus Torvalds 	}
25711da177e4SLinus Torvalds 	if (newval && newlen) {
25721da177e4SLinus Torvalds 		int new;
25731da177e4SLinus Torvalds 		if (newlen != sizeof(int))
25741da177e4SLinus Torvalds 			return -EINVAL;
25751da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
25761da177e4SLinus Torvalds 			return -EFAULT;
25771da177e4SLinus Torvalds 		*(int *)(table->data) = new*HZ;
25781da177e4SLinus Torvalds 	}
25791da177e4SLinus Torvalds 	return 1;
25801da177e4SLinus Torvalds }
25811da177e4SLinus Torvalds 
25821da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
25831da177e4SLinus Torvalds int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
25841da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
25851da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
25861da177e4SLinus Torvalds {
25871da177e4SLinus Torvalds 	if (oldval) {
25881da177e4SLinus Torvalds 		size_t olen;
25891da177e4SLinus Torvalds 		if (oldlenp) {
25901da177e4SLinus Torvalds 			if (get_user(olen, oldlenp))
25911da177e4SLinus Torvalds 				return -EFAULT;
25921da177e4SLinus Torvalds 			if (olen!=sizeof(int))
25931da177e4SLinus Torvalds 				return -EINVAL;
25941da177e4SLinus Torvalds 		}
25951da177e4SLinus Torvalds 		if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
25961da177e4SLinus Torvalds 		    (oldlenp && put_user(sizeof(int),oldlenp)))
25971da177e4SLinus Torvalds 			return -EFAULT;
25981da177e4SLinus Torvalds 	}
25991da177e4SLinus Torvalds 	if (newval && newlen) {
26001da177e4SLinus Torvalds 		int new;
26011da177e4SLinus Torvalds 		if (newlen != sizeof(int))
26021da177e4SLinus Torvalds 			return -EINVAL;
26031da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
26041da177e4SLinus Torvalds 			return -EFAULT;
26051da177e4SLinus Torvalds 		*(int *)(table->data) = msecs_to_jiffies(new);
26061da177e4SLinus Torvalds 	}
26071da177e4SLinus Torvalds 	return 1;
26081da177e4SLinus Torvalds }
26091da177e4SLinus Torvalds 
2610c4b8b769SEric W. Biederman 
2611c4b8b769SEric W. Biederman /* The generic string strategy routine: */
2612c4b8b769SEric W. Biederman static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2613c4b8b769SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
2614c4b8b769SEric W. Biederman 		  void __user *newval, size_t newlen, void **context)
2615c4b8b769SEric W. Biederman {
2616c4b8b769SEric W. Biederman 	struct ctl_table uts_table;
2617c4b8b769SEric W. Biederman 	int r, write;
2618c4b8b769SEric W. Biederman 	write = newval && newlen;
2619c4b8b769SEric W. Biederman 	memcpy(&uts_table, table, sizeof(uts_table));
2620c4b8b769SEric W. Biederman 	uts_table.data = get_uts(table, write);
2621c4b8b769SEric W. Biederman 	r = sysctl_string(&uts_table, name, nlen,
2622c4b8b769SEric W. Biederman 		oldval, oldlenp, newval, newlen, context);
2623c4b8b769SEric W. Biederman 	put_uts(table, write, uts_table.data);
2624c4b8b769SEric W. Biederman 	return r;
2625c4b8b769SEric W. Biederman }
2626c4b8b769SEric W. Biederman 
2627*6b49a257SEric W. Biederman #ifdef CONFIG_SYSVIPC
2628*6b49a257SEric W. Biederman /* The generic sysctl ipc data routine. */
2629*6b49a257SEric W. Biederman static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2630*6b49a257SEric W. Biederman 		void __user *oldval, size_t __user *oldlenp,
2631*6b49a257SEric W. Biederman 		void __user *newval, size_t newlen, void **context)
2632*6b49a257SEric W. Biederman {
2633*6b49a257SEric W. Biederman 	size_t len;
2634*6b49a257SEric W. Biederman 	void *data;
2635*6b49a257SEric W. Biederman 
2636*6b49a257SEric W. Biederman 	/* Get out of I don't have a variable */
2637*6b49a257SEric W. Biederman 	if (!table->data || !table->maxlen)
2638*6b49a257SEric W. Biederman 		return -ENOTDIR;
2639*6b49a257SEric W. Biederman 
2640*6b49a257SEric W. Biederman 	data = get_ipc(table, 1);
2641*6b49a257SEric W. Biederman 	if (!data)
2642*6b49a257SEric W. Biederman 		return -ENOTDIR;
2643*6b49a257SEric W. Biederman 
2644*6b49a257SEric W. Biederman 	if (oldval && oldlenp) {
2645*6b49a257SEric W. Biederman 		if (get_user(len, oldlenp))
2646*6b49a257SEric W. Biederman 			return -EFAULT;
2647*6b49a257SEric W. Biederman 		if (len) {
2648*6b49a257SEric W. Biederman 			if (len > table->maxlen)
2649*6b49a257SEric W. Biederman 				len = table->maxlen;
2650*6b49a257SEric W. Biederman 			if (copy_to_user(oldval, data, len))
2651*6b49a257SEric W. Biederman 				return -EFAULT;
2652*6b49a257SEric W. Biederman 			if (put_user(len, oldlenp))
2653*6b49a257SEric W. Biederman 				return -EFAULT;
2654*6b49a257SEric W. Biederman 		}
2655*6b49a257SEric W. Biederman 	}
2656*6b49a257SEric W. Biederman 
2657*6b49a257SEric W. Biederman 	if (newval && newlen) {
2658*6b49a257SEric W. Biederman 		if (newlen > table->maxlen)
2659*6b49a257SEric W. Biederman 			newlen = table->maxlen;
2660*6b49a257SEric W. Biederman 
2661*6b49a257SEric W. Biederman 		if (copy_from_user(data, newval, newlen))
2662*6b49a257SEric W. Biederman 			return -EFAULT;
2663*6b49a257SEric W. Biederman 	}
2664*6b49a257SEric W. Biederman 	return 1;
2665*6b49a257SEric W. Biederman }
2666*6b49a257SEric W. Biederman #endif
2667*6b49a257SEric W. Biederman 
2668b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */
26691da177e4SLinus Torvalds 
26701da177e4SLinus Torvalds 
26711da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
26721da177e4SLinus Torvalds {
2673b89a8171SEric W. Biederman 	static int msg_count;
26740e009be8SEric W. Biederman 	struct __sysctl_args tmp;
26750e009be8SEric W. Biederman 	int name[CTL_MAXNAME];
26760e009be8SEric W. Biederman 	int i;
26770e009be8SEric W. Biederman 
26780e009be8SEric W. Biederman 	/* Read in the sysctl name for better debug message logging */
26790e009be8SEric W. Biederman 	if (copy_from_user(&tmp, args, sizeof(tmp)))
26800e009be8SEric W. Biederman 		return -EFAULT;
26810e009be8SEric W. Biederman 	if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
26820e009be8SEric W. Biederman 		return -ENOTDIR;
26830e009be8SEric W. Biederman 	for (i = 0; i < tmp.nlen; i++)
26840e009be8SEric W. Biederman 		if (get_user(name[i], tmp.name + i))
26850e009be8SEric W. Biederman 			return -EFAULT;
26860e009be8SEric W. Biederman 
26870e009be8SEric W. Biederman 	/* Ignore accesses to kernel.version */
26880e009be8SEric W. Biederman 	if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
26890e009be8SEric W. Biederman 		goto out;
2690b89a8171SEric W. Biederman 
2691b89a8171SEric W. Biederman 	if (msg_count < 5) {
2692b89a8171SEric W. Biederman 		msg_count++;
2693b89a8171SEric W. Biederman 		printk(KERN_INFO
2694b89a8171SEric W. Biederman 			"warning: process `%s' used the removed sysctl "
26950e009be8SEric W. Biederman 			"system call with ", current->comm);
26960e009be8SEric W. Biederman 		for (i = 0; i < tmp.nlen; i++)
26970e009be8SEric W. Biederman 			printk("%d.", name[i]);
26980e009be8SEric W. Biederman 		printk("\n");
2699b89a8171SEric W. Biederman 	}
27000e009be8SEric W. Biederman out:
27011da177e4SLinus Torvalds 	return -ENOSYS;
27021da177e4SLinus Torvalds }
27031da177e4SLinus Torvalds 
27041da177e4SLinus Torvalds int sysctl_string(ctl_table *table, int __user *name, int nlen,
27051da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
27061da177e4SLinus Torvalds 		  void __user *newval, size_t newlen, void **context)
27071da177e4SLinus Torvalds {
27081da177e4SLinus Torvalds 	return -ENOSYS;
27091da177e4SLinus Torvalds }
27101da177e4SLinus Torvalds 
27111da177e4SLinus Torvalds int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
27121da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
27131da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
27141da177e4SLinus Torvalds {
27151da177e4SLinus Torvalds 	return -ENOSYS;
27161da177e4SLinus Torvalds }
27171da177e4SLinus Torvalds 
27181da177e4SLinus Torvalds int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
27191da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
27201da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
27211da177e4SLinus Torvalds {
27221da177e4SLinus Torvalds 	return -ENOSYS;
27231da177e4SLinus Torvalds }
27241da177e4SLinus Torvalds 
27251da177e4SLinus Torvalds int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
27261da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
27271da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
27281da177e4SLinus Torvalds {
27291da177e4SLinus Torvalds 	return -ENOSYS;
27301da177e4SLinus Torvalds }
27311da177e4SLinus Torvalds 
2732c4b8b769SEric W. Biederman static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2733c4b8b769SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
2734c4b8b769SEric W. Biederman 		  void __user *newval, size_t newlen, void **context)
2735c4b8b769SEric W. Biederman {
2736c4b8b769SEric W. Biederman 	return -ENOSYS;
2737c4b8b769SEric W. Biederman }
2738*6b49a257SEric W. Biederman static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2739*6b49a257SEric W. Biederman 		void __user *oldval, size_t __user *oldlenp,
2740*6b49a257SEric W. Biederman 		void __user *newval, size_t newlen, void **context)
2741*6b49a257SEric W. Biederman {
2742*6b49a257SEric W. Biederman 	return -ENOSYS;
2743*6b49a257SEric W. Biederman }
2744b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
27451da177e4SLinus Torvalds 
27461da177e4SLinus Torvalds /*
27471da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
27481da177e4SLinus Torvalds  * exception granted :-)
27491da177e4SLinus Torvalds  */
27501da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
27511da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
27521da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
27531da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
27541da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
27551da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
27561da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
27571da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
27581da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
27591da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec);
27601da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies);
27611da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies);
27621da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string);
27631da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
2764