xref: /openbmc/linux/kernel/sysctl.c (revision d99f160ac53e51090f015a8f0617cea25f81a191)
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>
5729cbc78bSAndi Kleen #endif
5829cbc78bSAndi Kleen 
591da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds /* External variables not in a header file. */
621da177e4SLinus Torvalds extern int C_A_D;
631da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
641da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
65fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom;
661da177e4SLinus Torvalds extern int max_threads;
671da177e4SLinus Torvalds extern int sysrq_enabled;
681da177e4SLinus Torvalds extern int core_uses_pid;
69d6e71144SAlan Cox extern int suid_dumpable;
701da177e4SLinus Torvalds extern char core_pattern[];
711da177e4SLinus Torvalds extern int pid_max;
721da177e4SLinus Torvalds extern int min_free_kbytes;
731da177e4SLinus Torvalds extern int printk_ratelimit_jiffies;
741da177e4SLinus Torvalds extern int printk_ratelimit_burst;
751da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
769d0243bcSAndrew Morton extern int sysctl_drop_caches;
778ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
78bebfa101SAndi Kleen extern int compat_log;
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
811da177e4SLinus Torvalds static int maxolduid = 65535;
821da177e4SLinus Torvalds static int minolduid;
838ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8;
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds #ifdef CONFIG_KMOD
881da177e4SLinus Torvalds extern char modprobe_path[];
891da177e4SLinus Torvalds #endif
901da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
911da177e4SLinus Torvalds extern int sg_big_buff;
921da177e4SLinus Torvalds #endif
931da177e4SLinus Torvalds #ifdef CONFIG_SYSVIPC
94fcfbd547SKirill Korotaev static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
95fcfbd547SKirill Korotaev 		void __user *buffer, size_t *lenp, loff_t *ppos);
961da177e4SLinus Torvalds #endif
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds #ifdef __sparc__
991da177e4SLinus Torvalds extern char reboot_command [];
1001da177e4SLinus Torvalds extern int stop_a_enabled;
1011da177e4SLinus Torvalds extern int scons_pwroff;
1021da177e4SLinus Torvalds #endif
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds #ifdef __hppa__
1051da177e4SLinus Torvalds extern int pwrsw_enabled;
1061da177e4SLinus Torvalds extern int unaligned_enabled;
1071da177e4SLinus Torvalds #endif
1081da177e4SLinus Torvalds 
109347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1101da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1111da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1121da177e4SLinus Torvalds #endif
1131da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
114951f22d5SMartin Schwidefsky extern int spin_retry;
1151da177e4SLinus Torvalds #endif
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds extern int sysctl_hz_timer;
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
1201da177e4SLinus Torvalds extern int acct_parm[];
1211da177e4SLinus Torvalds #endif
1221da177e4SLinus Torvalds 
123d2b176edSJes Sorensen #ifdef CONFIG_IA64
124d2b176edSJes Sorensen extern int no_unaligned_warning;
125d2b176edSJes Sorensen #endif
126d2b176edSJes Sorensen 
12723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
12823f78d4aSIngo Molnar extern int max_lock_depth;
12923f78d4aSIngo Molnar #endif
13023f78d4aSIngo Molnar 
131b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
132b89a8171SEric W. Biederman static int parse_table(int __user *, int, void __user *, size_t __user *,
133b89a8171SEric W. Biederman 		void __user *, size_t, ctl_table *, void **);
134b89a8171SEric W. Biederman #endif
135b89a8171SEric W. Biederman 
1368218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1371da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos);
1381da177e4SLinus Torvalds 
139d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
1409ec52099SCedric Le Goater static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
1419ec52099SCedric Le Goater 		  void __user *buffer, size_t *lenp, loff_t *ppos);
142d6f8ff73SRandy Dunlap #endif
1439ec52099SCedric Le Goater 
1441da177e4SLinus Torvalds static ctl_table root_table[];
1451da177e4SLinus Torvalds static struct ctl_table_header root_table_header =
1461da177e4SLinus Torvalds 	{ root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds static ctl_table kern_table[];
1491da177e4SLinus Torvalds static ctl_table vm_table[];
1501da177e4SLinus Torvalds static ctl_table fs_table[];
1511da177e4SLinus Torvalds static ctl_table debug_table[];
1521da177e4SLinus Torvalds static ctl_table dev_table[];
1531da177e4SLinus Torvalds extern ctl_table random_table[];
1541da177e4SLinus Torvalds #ifdef CONFIG_UNIX98_PTYS
1551da177e4SLinus Torvalds extern ctl_table pty_table[];
1561da177e4SLinus Torvalds #endif
1572d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
1580399cb08SRobert Love extern ctl_table inotify_table[];
1590399cb08SRobert Love #endif
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1621da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1631da177e4SLinus Torvalds #endif
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds /* /proc declarations: */
1661da177e4SLinus Torvalds 
167b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
1681da177e4SLinus Torvalds 
1691da177e4SLinus Torvalds static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
1701da177e4SLinus Torvalds static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
1711da177e4SLinus Torvalds static int proc_opensys(struct inode *, struct file *);
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds struct file_operations proc_sys_file_operations = {
1741da177e4SLinus Torvalds 	.open		= proc_opensys,
1751da177e4SLinus Torvalds 	.read		= proc_readsys,
1761da177e4SLinus Torvalds 	.write		= proc_writesys,
1771da177e4SLinus Torvalds };
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds extern struct proc_dir_entry *proc_sys_root;
1801da177e4SLinus Torvalds 
181330d57fbSAl Viro static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
1821da177e4SLinus Torvalds static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
1831da177e4SLinus Torvalds #endif
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds /* The default sysctl tables: */
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds static ctl_table root_table[] = {
1881da177e4SLinus Torvalds 	{
1891da177e4SLinus Torvalds 		.ctl_name	= CTL_KERN,
1901da177e4SLinus Torvalds 		.procname	= "kernel",
1911da177e4SLinus Torvalds 		.mode		= 0555,
1921da177e4SLinus Torvalds 		.child		= kern_table,
1931da177e4SLinus Torvalds 	},
1941da177e4SLinus Torvalds 	{
1951da177e4SLinus Torvalds 		.ctl_name	= CTL_VM,
1961da177e4SLinus Torvalds 		.procname	= "vm",
1971da177e4SLinus Torvalds 		.mode		= 0555,
1981da177e4SLinus Torvalds 		.child		= vm_table,
1991da177e4SLinus Torvalds 	},
2001da177e4SLinus Torvalds #ifdef CONFIG_NET
2011da177e4SLinus Torvalds 	{
2021da177e4SLinus Torvalds 		.ctl_name	= CTL_NET,
2031da177e4SLinus Torvalds 		.procname	= "net",
2041da177e4SLinus Torvalds 		.mode		= 0555,
2051da177e4SLinus Torvalds 		.child		= net_table,
2061da177e4SLinus Torvalds 	},
2071da177e4SLinus Torvalds #endif
2081da177e4SLinus Torvalds 	{
2091da177e4SLinus Torvalds 		.ctl_name	= CTL_FS,
2101da177e4SLinus Torvalds 		.procname	= "fs",
2111da177e4SLinus Torvalds 		.mode		= 0555,
2121da177e4SLinus Torvalds 		.child		= fs_table,
2131da177e4SLinus Torvalds 	},
2141da177e4SLinus Torvalds 	{
2151da177e4SLinus Torvalds 		.ctl_name	= CTL_DEBUG,
2161da177e4SLinus Torvalds 		.procname	= "debug",
2171da177e4SLinus Torvalds 		.mode		= 0555,
2181da177e4SLinus Torvalds 		.child		= debug_table,
2191da177e4SLinus Torvalds 	},
2201da177e4SLinus Torvalds 	{
2211da177e4SLinus Torvalds 		.ctl_name	= CTL_DEV,
2221da177e4SLinus Torvalds 		.procname	= "dev",
2231da177e4SLinus Torvalds 		.mode		= 0555,
2241da177e4SLinus Torvalds 		.child		= dev_table,
2251da177e4SLinus Torvalds 	},
2260eeca283SRobert Love 
2271da177e4SLinus Torvalds 	{ .ctl_name = 0 }
2281da177e4SLinus Torvalds };
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds static ctl_table kern_table[] = {
2318218c74cSSerge E. Hallyn #ifndef CONFIG_UTS_NS
2321da177e4SLinus Torvalds 	{
2331da177e4SLinus Torvalds 		.ctl_name	= KERN_OSTYPE,
2341da177e4SLinus Torvalds 		.procname	= "ostype",
2358218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.sysname,
2368218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.sysname),
2371da177e4SLinus Torvalds 		.mode		= 0444,
2388218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2391da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2401da177e4SLinus Torvalds 	},
2411da177e4SLinus Torvalds 	{
2421da177e4SLinus Torvalds 		.ctl_name	= KERN_OSRELEASE,
2431da177e4SLinus Torvalds 		.procname	= "osrelease",
2448218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.release,
2458218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.release),
2461da177e4SLinus Torvalds 		.mode		= 0444,
2478218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2481da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2491da177e4SLinus Torvalds 	},
2501da177e4SLinus Torvalds 	{
2511da177e4SLinus Torvalds 		.ctl_name	= KERN_VERSION,
2521da177e4SLinus Torvalds 		.procname	= "version",
2538218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.version,
2548218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.version),
2551da177e4SLinus Torvalds 		.mode		= 0444,
2568218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2571da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2581da177e4SLinus Torvalds 	},
2591da177e4SLinus Torvalds 	{
2601da177e4SLinus Torvalds 		.ctl_name	= KERN_NODENAME,
2611da177e4SLinus Torvalds 		.procname	= "hostname",
2628218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.nodename,
2638218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.nodename),
2641da177e4SLinus Torvalds 		.mode		= 0644,
2658218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2661da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2671da177e4SLinus Torvalds 	},
2681da177e4SLinus Torvalds 	{
2691da177e4SLinus Torvalds 		.ctl_name	= KERN_DOMAINNAME,
2701da177e4SLinus Torvalds 		.procname	= "domainname",
2718218c74cSSerge E. Hallyn 		.data		= init_uts_ns.name.domainname,
2728218c74cSSerge E. Hallyn 		.maxlen		= sizeof(init_uts_ns.name.domainname),
2731da177e4SLinus Torvalds 		.mode		= 0644,
2748218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2751da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
2761da177e4SLinus Torvalds 	},
2778218c74cSSerge E. Hallyn #else  /* !CONFIG_UTS_NS */
2788218c74cSSerge E. Hallyn 	{
2798218c74cSSerge E. Hallyn 		.ctl_name	= KERN_OSTYPE,
2808218c74cSSerge E. Hallyn 		.procname	= "ostype",
2818218c74cSSerge E. Hallyn 		.data		= NULL,
2828218c74cSSerge E. Hallyn 		/* could maybe use __NEW_UTS_LEN here? */
2838218c74cSSerge E. Hallyn 		.maxlen		= FIELD_SIZEOF(struct new_utsname, sysname),
2848218c74cSSerge E. Hallyn 		.mode		= 0444,
2858218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2868218c74cSSerge E. Hallyn 		.strategy	= &sysctl_string,
2878218c74cSSerge E. Hallyn 	},
2888218c74cSSerge E. Hallyn 	{
2898218c74cSSerge E. Hallyn 		.ctl_name	= KERN_OSRELEASE,
2908218c74cSSerge E. Hallyn 		.procname	= "osrelease",
2918218c74cSSerge E. Hallyn 		.data		= NULL,
2928218c74cSSerge E. Hallyn 		.maxlen		= FIELD_SIZEOF(struct new_utsname, release),
2938218c74cSSerge E. Hallyn 		.mode		= 0444,
2948218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
2958218c74cSSerge E. Hallyn 		.strategy	= &sysctl_string,
2968218c74cSSerge E. Hallyn 	},
2978218c74cSSerge E. Hallyn 	{
2988218c74cSSerge E. Hallyn 		.ctl_name	= KERN_VERSION,
2998218c74cSSerge E. Hallyn 		.procname	= "version",
3008218c74cSSerge E. Hallyn 		.data		= NULL,
3018218c74cSSerge E. Hallyn 		.maxlen		= FIELD_SIZEOF(struct new_utsname, version),
3028218c74cSSerge E. Hallyn 		.mode		= 0444,
3038218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
3048218c74cSSerge E. Hallyn 		.strategy	= &sysctl_string,
3058218c74cSSerge E. Hallyn 	},
3068218c74cSSerge E. Hallyn 	{
3078218c74cSSerge E. Hallyn 		.ctl_name	= KERN_NODENAME,
3088218c74cSSerge E. Hallyn 		.procname	= "hostname",
3098218c74cSSerge E. Hallyn 		.data		= NULL,
3108218c74cSSerge E. Hallyn 		.maxlen		= FIELD_SIZEOF(struct new_utsname, nodename),
3118218c74cSSerge E. Hallyn 		.mode		= 0644,
3128218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
3138218c74cSSerge E. Hallyn 		.strategy	= &sysctl_string,
3148218c74cSSerge E. Hallyn 	},
3158218c74cSSerge E. Hallyn 	{
3168218c74cSSerge E. Hallyn 		.ctl_name	= KERN_DOMAINNAME,
3178218c74cSSerge E. Hallyn 		.procname	= "domainname",
3188218c74cSSerge E. Hallyn 		.data		= NULL,
3198218c74cSSerge E. Hallyn 		.maxlen		= FIELD_SIZEOF(struct new_utsname, domainname),
3208218c74cSSerge E. Hallyn 		.mode		= 0644,
3218218c74cSSerge E. Hallyn 		.proc_handler	= &proc_do_uts_string,
3228218c74cSSerge E. Hallyn 		.strategy	= &sysctl_string,
3238218c74cSSerge E. Hallyn 	},
3248218c74cSSerge E. Hallyn #endif /* !CONFIG_UTS_NS */
3251da177e4SLinus Torvalds 	{
3261da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC,
3271da177e4SLinus Torvalds 		.procname	= "panic",
3281da177e4SLinus Torvalds 		.data		= &panic_timeout,
3291da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3301da177e4SLinus Torvalds 		.mode		= 0644,
3311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3321da177e4SLinus Torvalds 	},
3331da177e4SLinus Torvalds 	{
3341da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_USES_PID,
3351da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
3361da177e4SLinus Torvalds 		.data		= &core_uses_pid,
3371da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3381da177e4SLinus Torvalds 		.mode		= 0644,
3391da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3401da177e4SLinus Torvalds 	},
3411da177e4SLinus Torvalds 	{
3421da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_PATTERN,
3431da177e4SLinus Torvalds 		.procname	= "core_pattern",
3441da177e4SLinus Torvalds 		.data		= core_pattern,
345d025c9dbSAndi Kleen 		.maxlen		= 128,
3461da177e4SLinus Torvalds 		.mode		= 0644,
3471da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3481da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3491da177e4SLinus Torvalds 	},
3501da177e4SLinus Torvalds 	{
3511da177e4SLinus Torvalds 		.ctl_name	= KERN_TAINTED,
3521da177e4SLinus Torvalds 		.procname	= "tainted",
3531da177e4SLinus Torvalds 		.data		= &tainted,
3541da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3551da177e4SLinus Torvalds 		.mode		= 0444,
3561da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3571da177e4SLinus Torvalds 	},
3581da177e4SLinus Torvalds 	{
3591da177e4SLinus Torvalds 		.ctl_name	= KERN_CAP_BSET,
3601da177e4SLinus Torvalds 		.procname	= "cap-bound",
3611da177e4SLinus Torvalds 		.data		= &cap_bset,
3621da177e4SLinus Torvalds 		.maxlen		= sizeof(kernel_cap_t),
3631da177e4SLinus Torvalds 		.mode		= 0600,
3641da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_bset,
3651da177e4SLinus Torvalds 	},
3661da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
3671da177e4SLinus Torvalds 	{
3681da177e4SLinus Torvalds 		.ctl_name	= KERN_REALROOTDEV,
3691da177e4SLinus Torvalds 		.procname	= "real-root-dev",
3701da177e4SLinus Torvalds 		.data		= &real_root_dev,
3711da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3721da177e4SLinus Torvalds 		.mode		= 0644,
3731da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3741da177e4SLinus Torvalds 	},
3751da177e4SLinus Torvalds #endif
3761da177e4SLinus Torvalds #ifdef __sparc__
3771da177e4SLinus Torvalds 	{
3781da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_REBOOT,
3791da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
3801da177e4SLinus Torvalds 		.data		= reboot_command,
3811da177e4SLinus Torvalds 		.maxlen		= 256,
3821da177e4SLinus Torvalds 		.mode		= 0644,
3831da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3841da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3851da177e4SLinus Torvalds 	},
3861da177e4SLinus Torvalds 	{
3871da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_STOP_A,
3881da177e4SLinus Torvalds 		.procname	= "stop-a",
3891da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
3901da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3911da177e4SLinus Torvalds 		.mode		= 0644,
3921da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3931da177e4SLinus Torvalds 	},
3941da177e4SLinus Torvalds 	{
3951da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
3961da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
3971da177e4SLinus Torvalds 		.data		= &scons_pwroff,
3981da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
3991da177e4SLinus Torvalds 		.mode		= 0644,
4001da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4011da177e4SLinus Torvalds 	},
4021da177e4SLinus Torvalds #endif
4031da177e4SLinus Torvalds #ifdef __hppa__
4041da177e4SLinus Torvalds 	{
4051da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_PWRSW,
4061da177e4SLinus Torvalds 		.procname	= "soft-power",
4071da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
4081da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4091da177e4SLinus Torvalds 	 	.mode		= 0644,
4101da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4111da177e4SLinus Torvalds 	},
4121da177e4SLinus Torvalds 	{
4131da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_UNALIGNED,
4141da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
4151da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
4161da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4171da177e4SLinus Torvalds 		.mode		= 0644,
4181da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4191da177e4SLinus Torvalds 	},
4201da177e4SLinus Torvalds #endif
4211da177e4SLinus Torvalds 	{
4221da177e4SLinus Torvalds 		.ctl_name	= KERN_CTLALTDEL,
4231da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
4241da177e4SLinus Torvalds 		.data		= &C_A_D,
4251da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4261da177e4SLinus Torvalds 		.mode		= 0644,
4271da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4281da177e4SLinus Torvalds 	},
4291da177e4SLinus Torvalds 	{
4301da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK,
4311da177e4SLinus Torvalds 		.procname	= "printk",
4321da177e4SLinus Torvalds 		.data		= &console_loglevel,
4331da177e4SLinus Torvalds 		.maxlen		= 4*sizeof(int),
4341da177e4SLinus Torvalds 		.mode		= 0644,
4351da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4361da177e4SLinus Torvalds 	},
4371da177e4SLinus Torvalds #ifdef CONFIG_KMOD
4381da177e4SLinus Torvalds 	{
4391da177e4SLinus Torvalds 		.ctl_name	= KERN_MODPROBE,
4401da177e4SLinus Torvalds 		.procname	= "modprobe",
4411da177e4SLinus Torvalds 		.data		= &modprobe_path,
4421da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
4431da177e4SLinus Torvalds 		.mode		= 0644,
4441da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4451da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4461da177e4SLinus Torvalds 	},
4471da177e4SLinus Torvalds #endif
44857ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
4491da177e4SLinus Torvalds 	{
4501da177e4SLinus Torvalds 		.ctl_name	= KERN_HOTPLUG,
4511da177e4SLinus Torvalds 		.procname	= "hotplug",
452312c004dSKay Sievers 		.data		= &uevent_helper,
453312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
4541da177e4SLinus Torvalds 		.mode		= 0644,
4551da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4561da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4571da177e4SLinus Torvalds 	},
4581da177e4SLinus Torvalds #endif
4591da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
4601da177e4SLinus Torvalds 	{
4611da177e4SLinus Torvalds 		.ctl_name	= KERN_SG_BIG_BUFF,
4621da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
4631da177e4SLinus Torvalds 		.data		= &sg_big_buff,
4641da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4651da177e4SLinus Torvalds 		.mode		= 0444,
4661da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4671da177e4SLinus Torvalds 	},
4681da177e4SLinus Torvalds #endif
4691da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
4701da177e4SLinus Torvalds 	{
4711da177e4SLinus Torvalds 		.ctl_name	= KERN_ACCT,
4721da177e4SLinus Torvalds 		.procname	= "acct",
4731da177e4SLinus Torvalds 		.data		= &acct_parm,
4741da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
4751da177e4SLinus Torvalds 		.mode		= 0644,
4761da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4771da177e4SLinus Torvalds 	},
4781da177e4SLinus Torvalds #endif
4791da177e4SLinus Torvalds #ifdef CONFIG_SYSVIPC
4801da177e4SLinus Torvalds 	{
4811da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMMAX,
4821da177e4SLinus Torvalds 		.procname	= "shmmax",
483fcfbd547SKirill Korotaev 		.data		= NULL,
4841da177e4SLinus Torvalds 		.maxlen		= sizeof (size_t),
4851da177e4SLinus Torvalds 		.mode		= 0644,
486fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
4871da177e4SLinus Torvalds 	},
4881da177e4SLinus Torvalds 	{
4891da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMALL,
4901da177e4SLinus Torvalds 		.procname	= "shmall",
491fcfbd547SKirill Korotaev 		.data		= NULL,
4921da177e4SLinus Torvalds 		.maxlen		= sizeof (size_t),
4931da177e4SLinus Torvalds 		.mode		= 0644,
494fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
4951da177e4SLinus Torvalds 	},
4961da177e4SLinus Torvalds 	{
4971da177e4SLinus Torvalds 		.ctl_name	= KERN_SHMMNI,
4981da177e4SLinus Torvalds 		.procname	= "shmmni",
499fcfbd547SKirill Korotaev 		.data		= NULL,
5001da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5011da177e4SLinus Torvalds 		.mode		= 0644,
502fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
5031da177e4SLinus Torvalds 	},
5041da177e4SLinus Torvalds 	{
5051da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMAX,
5061da177e4SLinus Torvalds 		.procname	= "msgmax",
507fcfbd547SKirill Korotaev 		.data		= NULL,
5081da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5091da177e4SLinus Torvalds 		.mode		= 0644,
510fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
5111da177e4SLinus Torvalds 	},
5121da177e4SLinus Torvalds 	{
5131da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMNI,
5141da177e4SLinus Torvalds 		.procname	= "msgmni",
515fcfbd547SKirill Korotaev 		.data		= NULL,
5161da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5171da177e4SLinus Torvalds 		.mode		= 0644,
518fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
5191da177e4SLinus Torvalds 	},
5201da177e4SLinus Torvalds 	{
5211da177e4SLinus Torvalds 		.ctl_name	= KERN_MSGMNB,
5221da177e4SLinus Torvalds 		.procname	=  "msgmnb",
523fcfbd547SKirill Korotaev 		.data		= NULL,
5241da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5251da177e4SLinus Torvalds 		.mode		= 0644,
526fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
5271da177e4SLinus Torvalds 	},
5281da177e4SLinus Torvalds 	{
5291da177e4SLinus Torvalds 		.ctl_name	= KERN_SEM,
5301da177e4SLinus Torvalds 		.procname	= "sem",
531fcfbd547SKirill Korotaev 		.data		= NULL,
5321da177e4SLinus Torvalds 		.maxlen		= 4*sizeof (int),
5331da177e4SLinus Torvalds 		.mode		= 0644,
534fcfbd547SKirill Korotaev 		.proc_handler	= &proc_do_ipc_string,
5351da177e4SLinus Torvalds 	},
5361da177e4SLinus Torvalds #endif
5371da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
5381da177e4SLinus Torvalds 	{
5391da177e4SLinus Torvalds 		.ctl_name	= KERN_SYSRQ,
5401da177e4SLinus Torvalds 		.procname	= "sysrq",
5411da177e4SLinus Torvalds 		.data		= &sysrq_enabled,
5421da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5431da177e4SLinus Torvalds 		.mode		= 0644,
5441da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5451da177e4SLinus Torvalds 	},
5461da177e4SLinus Torvalds #endif
547d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
5481da177e4SLinus Torvalds 	{
5491da177e4SLinus Torvalds 		.ctl_name	= KERN_CADPID,
5501da177e4SLinus Torvalds 		.procname	= "cad_pid",
5519ec52099SCedric Le Goater 		.data		= NULL,
5521da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5531da177e4SLinus Torvalds 		.mode		= 0600,
5549ec52099SCedric Le Goater 		.proc_handler	= &proc_do_cad_pid,
5551da177e4SLinus Torvalds 	},
556d6f8ff73SRandy Dunlap #endif
5571da177e4SLinus Torvalds 	{
5581da177e4SLinus Torvalds 		.ctl_name	= KERN_MAX_THREADS,
5591da177e4SLinus Torvalds 		.procname	= "threads-max",
5601da177e4SLinus Torvalds 		.data		= &max_threads,
5611da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5621da177e4SLinus Torvalds 		.mode		= 0644,
5631da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5641da177e4SLinus Torvalds 	},
5651da177e4SLinus Torvalds 	{
5661da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOM,
5671da177e4SLinus Torvalds 		.procname	= "random",
5681da177e4SLinus Torvalds 		.mode		= 0555,
5691da177e4SLinus Torvalds 		.child		= random_table,
5701da177e4SLinus Torvalds 	},
5711da177e4SLinus Torvalds #ifdef CONFIG_UNIX98_PTYS
5721da177e4SLinus Torvalds 	{
5731da177e4SLinus Torvalds 		.ctl_name	= KERN_PTY,
5741da177e4SLinus Torvalds 		.procname	= "pty",
5751da177e4SLinus Torvalds 		.mode		= 0555,
5761da177e4SLinus Torvalds 		.child		= pty_table,
5771da177e4SLinus Torvalds 	},
5781da177e4SLinus Torvalds #endif
5791da177e4SLinus Torvalds 	{
5801da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWUID,
5811da177e4SLinus Torvalds 		.procname	= "overflowuid",
5821da177e4SLinus Torvalds 		.data		= &overflowuid,
5831da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5841da177e4SLinus Torvalds 		.mode		= 0644,
5851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5861da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5871da177e4SLinus Torvalds 		.extra1		= &minolduid,
5881da177e4SLinus Torvalds 		.extra2		= &maxolduid,
5891da177e4SLinus Torvalds 	},
5901da177e4SLinus Torvalds 	{
5911da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWGID,
5921da177e4SLinus Torvalds 		.procname	= "overflowgid",
5931da177e4SLinus Torvalds 		.data		= &overflowgid,
5941da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5951da177e4SLinus Torvalds 		.mode		= 0644,
5961da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5971da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5981da177e4SLinus Torvalds 		.extra1		= &minolduid,
5991da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6001da177e4SLinus Torvalds 	},
601347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
6021da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
6031da177e4SLinus Torvalds 	{
6041da177e4SLinus Torvalds 		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
6051da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
6061da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
6071da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6081da177e4SLinus Torvalds 		.mode		= 0644,
6091da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6101da177e4SLinus Torvalds 	},
6111da177e4SLinus Torvalds #endif
6121da177e4SLinus Torvalds #ifdef CONFIG_NO_IDLE_HZ
6131da177e4SLinus Torvalds 	{
6141da177e4SLinus Torvalds 		.ctl_name       = KERN_HZ_TIMER,
6151da177e4SLinus Torvalds 		.procname       = "hz_timer",
6161da177e4SLinus Torvalds 		.data           = &sysctl_hz_timer,
6171da177e4SLinus Torvalds 		.maxlen         = sizeof(int),
6181da177e4SLinus Torvalds 		.mode           = 0644,
6191da177e4SLinus Torvalds 		.proc_handler   = &proc_dointvec,
6201da177e4SLinus Torvalds 	},
6211da177e4SLinus Torvalds #endif
6221da177e4SLinus Torvalds 	{
6231da177e4SLinus Torvalds 		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
6241da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
6251da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
6261da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6271da177e4SLinus Torvalds 		.mode		= 0644,
6281da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6291da177e4SLinus Torvalds 	},
6301da177e4SLinus Torvalds #endif
6311da177e4SLinus Torvalds 	{
6321da177e4SLinus Torvalds 		.ctl_name	= KERN_PIDMAX,
6331da177e4SLinus Torvalds 		.procname	= "pid_max",
6341da177e4SLinus Torvalds 		.data		= &pid_max,
6351da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6361da177e4SLinus Torvalds 		.mode		= 0644,
6371da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6381da177e4SLinus Torvalds 		.strategy	= sysctl_intvec,
6391da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
6401da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
6411da177e4SLinus Torvalds 	},
6421da177e4SLinus Torvalds 	{
6431da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC_ON_OOPS,
6441da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
6451da177e4SLinus Torvalds 		.data		= &panic_on_oops,
6461da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6471da177e4SLinus Torvalds 		.mode		= 0644,
6481da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6491da177e4SLinus Torvalds 	},
6501da177e4SLinus Torvalds 	{
6511da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT,
6521da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
6531da177e4SLinus Torvalds 		.data		= &printk_ratelimit_jiffies,
6541da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6551da177e4SLinus Torvalds 		.mode		= 0644,
6561da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
6571da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
6581da177e4SLinus Torvalds 	},
6591da177e4SLinus Torvalds 	{
6601da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
6611da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
6621da177e4SLinus Torvalds 		.data		= &printk_ratelimit_burst,
6631da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6641da177e4SLinus Torvalds 		.mode		= 0644,
6651da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6661da177e4SLinus Torvalds 	},
6671da177e4SLinus Torvalds 	{
6681da177e4SLinus Torvalds 		.ctl_name	= KERN_NGROUPS_MAX,
6691da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6701da177e4SLinus Torvalds 		.data		= &ngroups_max,
6711da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6721da177e4SLinus Torvalds 		.mode		= 0444,
6731da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6741da177e4SLinus Torvalds 	},
6751da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6761da177e4SLinus Torvalds 	{
6771da177e4SLinus Torvalds 		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
6781da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
6791da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
6801da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
6811da177e4SLinus Torvalds 		.mode           = 0644,
6822fbe7b25SDon Zickus 		.proc_handler   = &proc_dointvec,
6831da177e4SLinus Torvalds 	},
684407984f1SDon Zickus 	{
685407984f1SDon Zickus 		.ctl_name       = KERN_NMI_WATCHDOG,
686407984f1SDon Zickus 		.procname       = "nmi_watchdog",
687407984f1SDon Zickus 		.data           = &nmi_watchdog_enabled,
688407984f1SDon Zickus 		.maxlen         = sizeof (int),
689407984f1SDon Zickus 		.mode           = 0644,
690407984f1SDon Zickus 		.proc_handler   = &proc_nmi_enabled,
6911da177e4SLinus Torvalds 	},
6921da177e4SLinus Torvalds #endif
6931da177e4SLinus Torvalds #if defined(CONFIG_X86)
6941da177e4SLinus Torvalds 	{
6958da5addaSDon Zickus 		.ctl_name	= KERN_PANIC_ON_NMI,
6968da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
6978da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
6988da5addaSDon Zickus 		.maxlen		= sizeof(int),
6998da5addaSDon Zickus 		.mode		= 0644,
7008da5addaSDon Zickus 		.proc_handler	= &proc_dointvec,
7018da5addaSDon Zickus 	},
7028da5addaSDon Zickus 	{
7031da177e4SLinus Torvalds 		.ctl_name	= KERN_BOOTLOADER_TYPE,
7041da177e4SLinus Torvalds 		.procname	= "bootloader_type",
7051da177e4SLinus Torvalds 		.data		= &bootloader_type,
7061da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
7071da177e4SLinus Torvalds 		.mode		= 0444,
7081da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7091da177e4SLinus Torvalds 	},
7101da177e4SLinus Torvalds #endif
7117a9166e3SLuke Yang #if defined(CONFIG_MMU)
7121da177e4SLinus Torvalds 	{
7131da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOMIZE,
7141da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
7151da177e4SLinus Torvalds 		.data		= &randomize_va_space,
7161da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
7171da177e4SLinus Torvalds 		.mode		= 0644,
7181da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7191da177e4SLinus Torvalds 	},
7207a9166e3SLuke Yang #endif
7210152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
722951f22d5SMartin Schwidefsky 	{
723951f22d5SMartin Schwidefsky 		.ctl_name	= KERN_SPIN_RETRY,
724951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
725951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
726951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
727951f22d5SMartin Schwidefsky 		.mode		= 0644,
728951f22d5SMartin Schwidefsky 		.proc_handler	= &proc_dointvec,
729951f22d5SMartin Schwidefsky 	},
730951f22d5SMartin Schwidefsky #endif
731c255d844SPavel Machek #ifdef CONFIG_ACPI_SLEEP
732c255d844SPavel Machek 	{
733c255d844SPavel Machek 		.ctl_name	= KERN_ACPI_VIDEO_FLAGS,
734c255d844SPavel Machek 		.procname	= "acpi_video_flags",
735c255d844SPavel Machek 		.data		= &acpi_video_flags,
736c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
737c255d844SPavel Machek 		.mode		= 0644,
7387f99f06fSStefan Seyfried 		.proc_handler	= &proc_doulongvec_minmax,
739c255d844SPavel Machek 	},
740c255d844SPavel Machek #endif
741d2b176edSJes Sorensen #ifdef CONFIG_IA64
742d2b176edSJes Sorensen 	{
743d2b176edSJes Sorensen 		.ctl_name	= KERN_IA64_UNALIGNED,
744d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
745d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
746d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
747d2b176edSJes Sorensen 	 	.mode		= 0644,
748d2b176edSJes Sorensen 		.proc_handler	= &proc_dointvec,
749d2b176edSJes Sorensen 	},
750d2b176edSJes Sorensen #endif
751bebfa101SAndi Kleen #ifdef CONFIG_COMPAT
752bebfa101SAndi Kleen 	{
753bebfa101SAndi Kleen 		.ctl_name	= KERN_COMPAT_LOG,
754bebfa101SAndi Kleen 		.procname	= "compat-log",
755bebfa101SAndi Kleen 		.data		= &compat_log,
756bebfa101SAndi Kleen 		.maxlen		= sizeof (int),
757bebfa101SAndi Kleen 	 	.mode		= 0644,
758bebfa101SAndi Kleen 		.proc_handler	= &proc_dointvec,
759bebfa101SAndi Kleen 	},
760bebfa101SAndi Kleen #endif
76123f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
76223f78d4aSIngo Molnar 	{
76323f78d4aSIngo Molnar 		.ctl_name	= KERN_MAX_LOCK_DEPTH,
76423f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
76523f78d4aSIngo Molnar 		.data		= &max_lock_depth,
76623f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
76723f78d4aSIngo Molnar 		.mode		= 0644,
76823f78d4aSIngo Molnar 		.proc_handler	= &proc_dointvec,
76923f78d4aSIngo Molnar 	},
77023f78d4aSIngo Molnar #endif
77123f78d4aSIngo Molnar 
7721da177e4SLinus Torvalds 	{ .ctl_name = 0 }
7731da177e4SLinus Torvalds };
7741da177e4SLinus Torvalds 
7751da177e4SLinus Torvalds /* Constants for minimum and maximum testing in vm_table.
7761da177e4SLinus Torvalds    We use these as one-element integer vectors. */
7771da177e4SLinus Torvalds static int zero;
7781da177e4SLinus Torvalds static int one_hundred = 100;
7791da177e4SLinus Torvalds 
7801da177e4SLinus Torvalds 
7811da177e4SLinus Torvalds static ctl_table vm_table[] = {
7821da177e4SLinus Torvalds 	{
7831da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_MEMORY,
7841da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
7851da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
7861da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
7871da177e4SLinus Torvalds 		.mode		= 0644,
7881da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7891da177e4SLinus Torvalds 	},
7901da177e4SLinus Torvalds 	{
791fadd8fbdSKAMEZAWA Hiroyuki 		.ctl_name	= VM_PANIC_ON_OOM,
792fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
793fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
794fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
795fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
796fadd8fbdSKAMEZAWA Hiroyuki 		.proc_handler	= &proc_dointvec,
797fadd8fbdSKAMEZAWA Hiroyuki 	},
798fadd8fbdSKAMEZAWA Hiroyuki 	{
7991da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_RATIO,
8001da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
8011da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
8021da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
8031da177e4SLinus Torvalds 		.mode		= 0644,
8041da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8051da177e4SLinus Torvalds 	},
8061da177e4SLinus Torvalds 	{
8071da177e4SLinus Torvalds 		.ctl_name	= VM_PAGE_CLUSTER,
8081da177e4SLinus Torvalds 		.procname	= "page-cluster",
8091da177e4SLinus Torvalds 		.data		= &page_cluster,
8101da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
8111da177e4SLinus Torvalds 		.mode		= 0644,
8121da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8131da177e4SLinus Torvalds 	},
8141da177e4SLinus Torvalds 	{
8151da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_BACKGROUND,
8161da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
8171da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
8181da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
8191da177e4SLinus Torvalds 		.mode		= 0644,
8201da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
8211da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8221da177e4SLinus Torvalds 		.extra1		= &zero,
8231da177e4SLinus Torvalds 		.extra2		= &one_hundred,
8241da177e4SLinus Torvalds 	},
8251da177e4SLinus Torvalds 	{
8261da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_RATIO,
8271da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
8281da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
8291da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
8301da177e4SLinus Torvalds 		.mode		= 0644,
8311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
8321da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8331da177e4SLinus Torvalds 		.extra1		= &zero,
8341da177e4SLinus Torvalds 		.extra2		= &one_hundred,
8351da177e4SLinus Torvalds 	},
8361da177e4SLinus Torvalds 	{
8371da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_WB_CS,
8381da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
839f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
840f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
8411da177e4SLinus Torvalds 		.mode		= 0644,
8421da177e4SLinus Torvalds 		.proc_handler	= &dirty_writeback_centisecs_handler,
8431da177e4SLinus Torvalds 	},
8441da177e4SLinus Torvalds 	{
8451da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_EXPIRE_CS,
8461da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
847f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
848f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
8491da177e4SLinus Torvalds 		.mode		= 0644,
850f6ef9438SBart Samwel 		.proc_handler	= &proc_dointvec_userhz_jiffies,
8511da177e4SLinus Torvalds 	},
8521da177e4SLinus Torvalds 	{
8531da177e4SLinus Torvalds 		.ctl_name	= VM_NR_PDFLUSH_THREADS,
8541da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
8551da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
8561da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
8571da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
8581da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8591da177e4SLinus Torvalds 	},
8601da177e4SLinus Torvalds 	{
8611da177e4SLinus Torvalds 		.ctl_name	= VM_SWAPPINESS,
8621da177e4SLinus Torvalds 		.procname	= "swappiness",
8631da177e4SLinus Torvalds 		.data		= &vm_swappiness,
8641da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
8651da177e4SLinus Torvalds 		.mode		= 0644,
8661da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
8671da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8681da177e4SLinus Torvalds 		.extra1		= &zero,
8691da177e4SLinus Torvalds 		.extra2		= &one_hundred,
8701da177e4SLinus Torvalds 	},
8711da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
8721da177e4SLinus Torvalds 	 {
8731da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_PAGES,
8741da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
8751da177e4SLinus Torvalds 		.data		= &max_huge_pages,
8761da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
8771da177e4SLinus Torvalds 		.mode		= 0644,
8781da177e4SLinus Torvalds 		.proc_handler	= &hugetlb_sysctl_handler,
8791da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
8801da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
8811da177e4SLinus Torvalds 	 },
8821da177e4SLinus Torvalds 	 {
8831da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_GROUP,
8841da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
8851da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
8861da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
8871da177e4SLinus Torvalds 		.mode		= 0644,
8881da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8891da177e4SLinus Torvalds 	 },
8901da177e4SLinus Torvalds #endif
8911da177e4SLinus Torvalds 	{
8921da177e4SLinus Torvalds 		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
8931da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
8941da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
8951da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
8961da177e4SLinus Torvalds 		.mode		= 0644,
8971da177e4SLinus Torvalds 		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
8981da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
8991da177e4SLinus Torvalds 	},
9001da177e4SLinus Torvalds 	{
9019d0243bcSAndrew Morton 		.ctl_name	= VM_DROP_PAGECACHE,
9029d0243bcSAndrew Morton 		.procname	= "drop_caches",
9039d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
9049d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
9059d0243bcSAndrew Morton 		.mode		= 0644,
9069d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
9079d0243bcSAndrew Morton 		.strategy	= &sysctl_intvec,
9089d0243bcSAndrew Morton 	},
9099d0243bcSAndrew Morton 	{
9101da177e4SLinus Torvalds 		.ctl_name	= VM_MIN_FREE_KBYTES,
9111da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
9121da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
9131da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
9141da177e4SLinus Torvalds 		.mode		= 0644,
9151da177e4SLinus Torvalds 		.proc_handler	= &min_free_kbytes_sysctl_handler,
9161da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9171da177e4SLinus Torvalds 		.extra1		= &zero,
9181da177e4SLinus Torvalds 	},
9198ad4b1fbSRohit Seth 	{
9208ad4b1fbSRohit Seth 		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
9218ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
9228ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
9238ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
9248ad4b1fbSRohit Seth 		.mode		= 0644,
9258ad4b1fbSRohit Seth 		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
9268ad4b1fbSRohit Seth 		.strategy	= &sysctl_intvec,
9278ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
9288ad4b1fbSRohit Seth 	},
9291da177e4SLinus Torvalds #ifdef CONFIG_MMU
9301da177e4SLinus Torvalds 	{
9311da177e4SLinus Torvalds 		.ctl_name	= VM_MAX_MAP_COUNT,
9321da177e4SLinus Torvalds 		.procname	= "max_map_count",
9331da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
9341da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
9351da177e4SLinus Torvalds 		.mode		= 0644,
9361da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec
9371da177e4SLinus Torvalds 	},
9381da177e4SLinus Torvalds #endif
9391da177e4SLinus Torvalds 	{
9401da177e4SLinus Torvalds 		.ctl_name	= VM_LAPTOP_MODE,
9411da177e4SLinus Torvalds 		.procname	= "laptop_mode",
9421da177e4SLinus Torvalds 		.data		= &laptop_mode,
9431da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
9441da177e4SLinus Torvalds 		.mode		= 0644,
945ed5b43f1SBart Samwel 		.proc_handler	= &proc_dointvec_jiffies,
946ed5b43f1SBart Samwel 		.strategy	= &sysctl_jiffies,
9471da177e4SLinus Torvalds 	},
9481da177e4SLinus Torvalds 	{
9491da177e4SLinus Torvalds 		.ctl_name	= VM_BLOCK_DUMP,
9501da177e4SLinus Torvalds 		.procname	= "block_dump",
9511da177e4SLinus Torvalds 		.data		= &block_dump,
9521da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
9531da177e4SLinus Torvalds 		.mode		= 0644,
9541da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9551da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9561da177e4SLinus Torvalds 		.extra1		= &zero,
9571da177e4SLinus Torvalds 	},
9581da177e4SLinus Torvalds 	{
9591da177e4SLinus Torvalds 		.ctl_name	= VM_VFS_CACHE_PRESSURE,
9601da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
9611da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
9621da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
9631da177e4SLinus Torvalds 		.mode		= 0644,
9641da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9651da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9661da177e4SLinus Torvalds 		.extra1		= &zero,
9671da177e4SLinus Torvalds 	},
9681da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
9691da177e4SLinus Torvalds 	{
9701da177e4SLinus Torvalds 		.ctl_name	= VM_LEGACY_VA_LAYOUT,
9711da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
9721da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
9731da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
9741da177e4SLinus Torvalds 		.mode		= 0644,
9751da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9761da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9771da177e4SLinus Torvalds 		.extra1		= &zero,
9781da177e4SLinus Torvalds 	},
9791da177e4SLinus Torvalds #endif
9801da177e4SLinus Torvalds #ifdef CONFIG_SWAP
9811da177e4SLinus Torvalds 	{
9821da177e4SLinus Torvalds 		.ctl_name	= VM_SWAP_TOKEN_TIMEOUT,
9831da177e4SLinus Torvalds 		.procname	= "swap_token_timeout",
9841da177e4SLinus Torvalds 		.data		= &swap_token_default_timeout,
9851da177e4SLinus Torvalds 		.maxlen		= sizeof(swap_token_default_timeout),
9861da177e4SLinus Torvalds 		.mode		= 0644,
9871da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
9881da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
9891da177e4SLinus Torvalds 	},
9901da177e4SLinus Torvalds #endif
9911743660bSChristoph Lameter #ifdef CONFIG_NUMA
9921743660bSChristoph Lameter 	{
9931743660bSChristoph Lameter 		.ctl_name	= VM_ZONE_RECLAIM_MODE,
9941743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
9951743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
9961743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
9971743660bSChristoph Lameter 		.mode		= 0644,
9981743660bSChristoph Lameter 		.proc_handler	= &proc_dointvec,
999c84db23cSChristoph Lameter 		.strategy	= &sysctl_intvec,
1000c84db23cSChristoph Lameter 		.extra1		= &zero,
10011743660bSChristoph Lameter 	},
10029614634fSChristoph Lameter 	{
10039614634fSChristoph Lameter 		.ctl_name	= VM_MIN_UNMAPPED,
10049614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
10059614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
10069614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
10079614634fSChristoph Lameter 		.mode		= 0644,
10089614634fSChristoph Lameter 		.proc_handler	= &sysctl_min_unmapped_ratio_sysctl_handler,
10099614634fSChristoph Lameter 		.strategy	= &sysctl_intvec,
10109614634fSChristoph Lameter 		.extra1		= &zero,
10119614634fSChristoph Lameter 		.extra2		= &one_hundred,
10129614634fSChristoph Lameter 	},
10130ff38490SChristoph Lameter 	{
10140ff38490SChristoph Lameter 		.ctl_name	= VM_MIN_SLAB,
10150ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
10160ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
10170ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
10180ff38490SChristoph Lameter 		.mode		= 0644,
10190ff38490SChristoph Lameter 		.proc_handler	= &sysctl_min_slab_ratio_sysctl_handler,
10200ff38490SChristoph Lameter 		.strategy	= &sysctl_intvec,
10210ff38490SChristoph Lameter 		.extra1		= &zero,
10220ff38490SChristoph Lameter 		.extra2		= &one_hundred,
10230ff38490SChristoph Lameter 	},
10241743660bSChristoph Lameter #endif
1025e6e5494cSIngo Molnar #ifdef CONFIG_X86_32
1026e6e5494cSIngo Molnar 	{
1027e6e5494cSIngo Molnar 		.ctl_name	= VM_VDSO_ENABLED,
1028e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
1029e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
1030e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
1031e6e5494cSIngo Molnar 		.mode		= 0644,
1032e6e5494cSIngo Molnar 		.proc_handler	= &proc_dointvec,
1033e6e5494cSIngo Molnar 		.strategy	= &sysctl_intvec,
1034e6e5494cSIngo Molnar 		.extra1		= &zero,
1035e6e5494cSIngo Molnar 	},
1036e6e5494cSIngo Molnar #endif
10371da177e4SLinus Torvalds 	{ .ctl_name = 0 }
10381da177e4SLinus Torvalds };
10391da177e4SLinus Torvalds 
10401da177e4SLinus Torvalds static ctl_table fs_table[] = {
10411da177e4SLinus Torvalds 	{
10421da177e4SLinus Torvalds 		.ctl_name	= FS_NRINODE,
10431da177e4SLinus Torvalds 		.procname	= "inode-nr",
10441da177e4SLinus Torvalds 		.data		= &inodes_stat,
10451da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
10461da177e4SLinus Torvalds 		.mode		= 0444,
10471da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10481da177e4SLinus Torvalds 	},
10491da177e4SLinus Torvalds 	{
10501da177e4SLinus Torvalds 		.ctl_name	= FS_STATINODE,
10511da177e4SLinus Torvalds 		.procname	= "inode-state",
10521da177e4SLinus Torvalds 		.data		= &inodes_stat,
10531da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
10541da177e4SLinus Torvalds 		.mode		= 0444,
10551da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10561da177e4SLinus Torvalds 	},
10571da177e4SLinus Torvalds 	{
10581da177e4SLinus Torvalds 		.ctl_name	= FS_NRFILE,
10591da177e4SLinus Torvalds 		.procname	= "file-nr",
10601da177e4SLinus Torvalds 		.data		= &files_stat,
10611da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
10621da177e4SLinus Torvalds 		.mode		= 0444,
1063529bf6beSDipankar Sarma 		.proc_handler	= &proc_nr_files,
10641da177e4SLinus Torvalds 	},
10651da177e4SLinus Torvalds 	{
10661da177e4SLinus Torvalds 		.ctl_name	= FS_MAXFILE,
10671da177e4SLinus Torvalds 		.procname	= "file-max",
10681da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
10691da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
10701da177e4SLinus Torvalds 		.mode		= 0644,
10711da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10721da177e4SLinus Torvalds 	},
10731da177e4SLinus Torvalds 	{
10741da177e4SLinus Torvalds 		.ctl_name	= FS_DENTRY,
10751da177e4SLinus Torvalds 		.procname	= "dentry-state",
10761da177e4SLinus Torvalds 		.data		= &dentry_stat,
10771da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
10781da177e4SLinus Torvalds 		.mode		= 0444,
10791da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10801da177e4SLinus Torvalds 	},
10811da177e4SLinus Torvalds 	{
10821da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWUID,
10831da177e4SLinus Torvalds 		.procname	= "overflowuid",
10841da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
10851da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
10861da177e4SLinus Torvalds 		.mode		= 0644,
10871da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
10881da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10891da177e4SLinus Torvalds 		.extra1		= &minolduid,
10901da177e4SLinus Torvalds 		.extra2		= &maxolduid,
10911da177e4SLinus Torvalds 	},
10921da177e4SLinus Torvalds 	{
10931da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWGID,
10941da177e4SLinus Torvalds 		.procname	= "overflowgid",
10951da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
10961da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
10971da177e4SLinus Torvalds 		.mode		= 0644,
10981da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
10991da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11001da177e4SLinus Torvalds 		.extra1		= &minolduid,
11011da177e4SLinus Torvalds 		.extra2		= &maxolduid,
11021da177e4SLinus Torvalds 	},
11031da177e4SLinus Torvalds 	{
11041da177e4SLinus Torvalds 		.ctl_name	= FS_LEASES,
11051da177e4SLinus Torvalds 		.procname	= "leases-enable",
11061da177e4SLinus Torvalds 		.data		= &leases_enable,
11071da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
11081da177e4SLinus Torvalds 		.mode		= 0644,
11091da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11101da177e4SLinus Torvalds 	},
11111da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
11121da177e4SLinus Torvalds 	{
11131da177e4SLinus Torvalds 		.ctl_name	= FS_DIR_NOTIFY,
11141da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
11151da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
11161da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
11171da177e4SLinus Torvalds 		.mode		= 0644,
11181da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11191da177e4SLinus Torvalds 	},
11201da177e4SLinus Torvalds #endif
11211da177e4SLinus Torvalds #ifdef CONFIG_MMU
11221da177e4SLinus Torvalds 	{
11231da177e4SLinus Torvalds 		.ctl_name	= FS_LEASE_TIME,
11241da177e4SLinus Torvalds 		.procname	= "lease-break-time",
11251da177e4SLinus Torvalds 		.data		= &lease_break_time,
11261da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
11271da177e4SLinus Torvalds 		.mode		= 0644,
11281da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11291da177e4SLinus Torvalds 	},
11301da177e4SLinus Torvalds 	{
11311da177e4SLinus Torvalds 		.ctl_name	= FS_AIO_NR,
11321da177e4SLinus Torvalds 		.procname	= "aio-nr",
11331da177e4SLinus Torvalds 		.data		= &aio_nr,
11341da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
11351da177e4SLinus Torvalds 		.mode		= 0444,
1136d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
11371da177e4SLinus Torvalds 	},
11381da177e4SLinus Torvalds 	{
11391da177e4SLinus Torvalds 		.ctl_name	= FS_AIO_MAX_NR,
11401da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
11411da177e4SLinus Torvalds 		.data		= &aio_max_nr,
11421da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
11431da177e4SLinus Torvalds 		.mode		= 0644,
1144d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
11451da177e4SLinus Torvalds 	},
11462d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
11470399cb08SRobert Love 	{
11480399cb08SRobert Love 		.ctl_name	= FS_INOTIFY,
11490399cb08SRobert Love 		.procname	= "inotify",
11500399cb08SRobert Love 		.mode		= 0555,
11510399cb08SRobert Love 		.child		= inotify_table,
11520399cb08SRobert Love 	},
11530399cb08SRobert Love #endif
11541da177e4SLinus Torvalds #endif
1155d6e71144SAlan Cox 	{
1156d6e71144SAlan Cox 		.ctl_name	= KERN_SETUID_DUMPABLE,
1157d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1158d6e71144SAlan Cox 		.data		= &suid_dumpable,
1159d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1160d6e71144SAlan Cox 		.mode		= 0644,
1161d6e71144SAlan Cox 		.proc_handler	= &proc_dointvec,
1162d6e71144SAlan Cox 	},
11631da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11641da177e4SLinus Torvalds };
11651da177e4SLinus Torvalds 
11661da177e4SLinus Torvalds static ctl_table debug_table[] = {
11671da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11681da177e4SLinus Torvalds };
11691da177e4SLinus Torvalds 
11701da177e4SLinus Torvalds static ctl_table dev_table[] = {
11711da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11721da177e4SLinus Torvalds };
11731da177e4SLinus Torvalds 
11741da177e4SLinus Torvalds extern void init_irq_proc (void);
11751da177e4SLinus Torvalds 
1176330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1177330d57fbSAl Viro 
1178330d57fbSAl Viro /* called under sysctl_lock */
1179330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1180330d57fbSAl Viro {
1181330d57fbSAl Viro 	if (unlikely(p->unregistering))
1182330d57fbSAl Viro 		return 0;
1183330d57fbSAl Viro 	p->used++;
1184330d57fbSAl Viro 	return 1;
1185330d57fbSAl Viro }
1186330d57fbSAl Viro 
1187330d57fbSAl Viro /* called under sysctl_lock */
1188330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1189330d57fbSAl Viro {
1190330d57fbSAl Viro 	if (!--p->used)
1191330d57fbSAl Viro 		if (unlikely(p->unregistering))
1192330d57fbSAl Viro 			complete(p->unregistering);
1193330d57fbSAl Viro }
1194330d57fbSAl Viro 
1195330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1196330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1197330d57fbSAl Viro {
1198330d57fbSAl Viro 	/*
1199330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1200330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1201330d57fbSAl Viro 	 */
1202330d57fbSAl Viro 	if (unlikely(p->used)) {
1203330d57fbSAl Viro 		struct completion wait;
1204330d57fbSAl Viro 		init_completion(&wait);
1205330d57fbSAl Viro 		p->unregistering = &wait;
1206330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1207330d57fbSAl Viro 		wait_for_completion(&wait);
1208330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1209330d57fbSAl Viro 	}
1210330d57fbSAl Viro 	/*
1211330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1212330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1213330d57fbSAl Viro 	 */
1214330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1215330d57fbSAl Viro }
1216330d57fbSAl Viro 
12171da177e4SLinus Torvalds void __init sysctl_init(void)
12181da177e4SLinus Torvalds {
1219b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
1220330d57fbSAl Viro 	register_proc_table(root_table, proc_sys_root, &root_table_header);
12211da177e4SLinus Torvalds 	init_irq_proc();
12221da177e4SLinus Torvalds #endif
12231da177e4SLinus Torvalds }
12241da177e4SLinus Torvalds 
1225b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
12261da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
12271da177e4SLinus Torvalds 	       void __user *newval, size_t newlen)
12281da177e4SLinus Torvalds {
12291da177e4SLinus Torvalds 	struct list_head *tmp;
1230330d57fbSAl Viro 	int error = -ENOTDIR;
12311da177e4SLinus Torvalds 
12321da177e4SLinus Torvalds 	if (nlen <= 0 || nlen >= CTL_MAXNAME)
12331da177e4SLinus Torvalds 		return -ENOTDIR;
12341da177e4SLinus Torvalds 	if (oldval) {
12351da177e4SLinus Torvalds 		int old_len;
12361da177e4SLinus Torvalds 		if (!oldlenp || get_user(old_len, oldlenp))
12371da177e4SLinus Torvalds 			return -EFAULT;
12381da177e4SLinus Torvalds 	}
1239330d57fbSAl Viro 	spin_lock(&sysctl_lock);
12401da177e4SLinus Torvalds 	tmp = &root_table_header.ctl_entry;
12411da177e4SLinus Torvalds 	do {
12421da177e4SLinus Torvalds 		struct ctl_table_header *head =
12431da177e4SLinus Torvalds 			list_entry(tmp, struct ctl_table_header, ctl_entry);
12441da177e4SLinus Torvalds 		void *context = NULL;
1245330d57fbSAl Viro 
1246330d57fbSAl Viro 		if (!use_table(head))
1247330d57fbSAl Viro 			continue;
1248330d57fbSAl Viro 
1249330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1250330d57fbSAl Viro 
1251330d57fbSAl Viro 		error = parse_table(name, nlen, oldval, oldlenp,
12521da177e4SLinus Torvalds 					newval, newlen, head->ctl_table,
12531da177e4SLinus Torvalds 					&context);
12541da177e4SLinus Torvalds 		kfree(context);
1255330d57fbSAl Viro 
1256330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1257330d57fbSAl Viro 		unuse_table(head);
12581da177e4SLinus Torvalds 		if (error != -ENOTDIR)
1259330d57fbSAl Viro 			break;
1260330d57fbSAl Viro 	} while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1261330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
12621da177e4SLinus Torvalds 	return error;
12631da177e4SLinus Torvalds }
12641da177e4SLinus Torvalds 
12651da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
12661da177e4SLinus Torvalds {
12671da177e4SLinus Torvalds 	struct __sysctl_args tmp;
12681da177e4SLinus Torvalds 	int error;
12691da177e4SLinus Torvalds 
12701da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
12711da177e4SLinus Torvalds 		return -EFAULT;
12721da177e4SLinus Torvalds 
12731da177e4SLinus Torvalds 	lock_kernel();
12741da177e4SLinus Torvalds 	error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
12751da177e4SLinus Torvalds 			  tmp.newval, tmp.newlen);
12761da177e4SLinus Torvalds 	unlock_kernel();
12771da177e4SLinus Torvalds 	return error;
12781da177e4SLinus Torvalds }
1279b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
12801da177e4SLinus Torvalds 
12811da177e4SLinus Torvalds /*
12821da177e4SLinus Torvalds  * ctl_perm does NOT grant the superuser all rights automatically, because
12831da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
12841da177e4SLinus Torvalds  */
12851da177e4SLinus Torvalds 
12861da177e4SLinus Torvalds static int test_perm(int mode, int op)
12871da177e4SLinus Torvalds {
12881da177e4SLinus Torvalds 	if (!current->euid)
12891da177e4SLinus Torvalds 		mode >>= 6;
12901da177e4SLinus Torvalds 	else if (in_egroup_p(0))
12911da177e4SLinus Torvalds 		mode >>= 3;
12921da177e4SLinus Torvalds 	if ((mode & op & 0007) == op)
12931da177e4SLinus Torvalds 		return 0;
12941da177e4SLinus Torvalds 	return -EACCES;
12951da177e4SLinus Torvalds }
12961da177e4SLinus Torvalds 
12971da177e4SLinus Torvalds static inline int ctl_perm(ctl_table *table, int op)
12981da177e4SLinus Torvalds {
12991da177e4SLinus Torvalds 	int error;
13001da177e4SLinus Torvalds 	error = security_sysctl(table, op);
13011da177e4SLinus Torvalds 	if (error)
13021da177e4SLinus Torvalds 		return error;
13031da177e4SLinus Torvalds 	return test_perm(table->mode, op);
13041da177e4SLinus Torvalds }
13051da177e4SLinus Torvalds 
1306b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
13071da177e4SLinus Torvalds static int parse_table(int __user *name, int nlen,
13081da177e4SLinus Torvalds 		       void __user *oldval, size_t __user *oldlenp,
13091da177e4SLinus Torvalds 		       void __user *newval, size_t newlen,
13101da177e4SLinus Torvalds 		       ctl_table *table, void **context)
13111da177e4SLinus Torvalds {
13121da177e4SLinus Torvalds 	int n;
13131da177e4SLinus Torvalds repeat:
13141da177e4SLinus Torvalds 	if (!nlen)
13151da177e4SLinus Torvalds 		return -ENOTDIR;
13161da177e4SLinus Torvalds 	if (get_user(n, name))
13171da177e4SLinus Torvalds 		return -EFAULT;
1318*d99f160aSEric W. Biederman 	for ( ; table->ctl_name || table->procname; table++) {
1319*d99f160aSEric W. Biederman 		if (!table->ctl_name)
1320*d99f160aSEric W. Biederman 			continue;
13211da177e4SLinus Torvalds 		if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
13221da177e4SLinus Torvalds 			int error;
13231da177e4SLinus Torvalds 			if (table->child) {
13241da177e4SLinus Torvalds 				if (ctl_perm(table, 001))
13251da177e4SLinus Torvalds 					return -EPERM;
13261da177e4SLinus Torvalds 				if (table->strategy) {
13271da177e4SLinus Torvalds 					error = table->strategy(
13281da177e4SLinus Torvalds 						table, name, nlen,
13291da177e4SLinus Torvalds 						oldval, oldlenp,
13301da177e4SLinus Torvalds 						newval, newlen, context);
13311da177e4SLinus Torvalds 					if (error)
13321da177e4SLinus Torvalds 						return error;
13331da177e4SLinus Torvalds 				}
13341da177e4SLinus Torvalds 				name++;
13351da177e4SLinus Torvalds 				nlen--;
13361da177e4SLinus Torvalds 				table = table->child;
13371da177e4SLinus Torvalds 				goto repeat;
13381da177e4SLinus Torvalds 			}
13391da177e4SLinus Torvalds 			error = do_sysctl_strategy(table, name, nlen,
13401da177e4SLinus Torvalds 						   oldval, oldlenp,
13411da177e4SLinus Torvalds 						   newval, newlen, context);
13421da177e4SLinus Torvalds 			return error;
13431da177e4SLinus Torvalds 		}
13441da177e4SLinus Torvalds 	}
13451da177e4SLinus Torvalds 	return -ENOTDIR;
13461da177e4SLinus Torvalds }
13471da177e4SLinus Torvalds 
13481da177e4SLinus Torvalds /* Perform the actual read/write of a sysctl table entry. */
13491da177e4SLinus Torvalds int do_sysctl_strategy (ctl_table *table,
13501da177e4SLinus Torvalds 			int __user *name, int nlen,
13511da177e4SLinus Torvalds 			void __user *oldval, size_t __user *oldlenp,
13521da177e4SLinus Torvalds 			void __user *newval, size_t newlen, void **context)
13531da177e4SLinus Torvalds {
13541da177e4SLinus Torvalds 	int op = 0, rc;
13551da177e4SLinus Torvalds 	size_t len;
13561da177e4SLinus Torvalds 
13571da177e4SLinus Torvalds 	if (oldval)
13581da177e4SLinus Torvalds 		op |= 004;
13591da177e4SLinus Torvalds 	if (newval)
13601da177e4SLinus Torvalds 		op |= 002;
13611da177e4SLinus Torvalds 	if (ctl_perm(table, op))
13621da177e4SLinus Torvalds 		return -EPERM;
13631da177e4SLinus Torvalds 
13641da177e4SLinus Torvalds 	if (table->strategy) {
13651da177e4SLinus Torvalds 		rc = table->strategy(table, name, nlen, oldval, oldlenp,
13661da177e4SLinus Torvalds 				     newval, newlen, context);
13671da177e4SLinus Torvalds 		if (rc < 0)
13681da177e4SLinus Torvalds 			return rc;
13691da177e4SLinus Torvalds 		if (rc > 0)
13701da177e4SLinus Torvalds 			return 0;
13711da177e4SLinus Torvalds 	}
13721da177e4SLinus Torvalds 
13731da177e4SLinus Torvalds 	/* If there is no strategy routine, or if the strategy returns
13741da177e4SLinus Torvalds 	 * zero, proceed with automatic r/w */
13751da177e4SLinus Torvalds 	if (table->data && table->maxlen) {
13761da177e4SLinus Torvalds 		if (oldval && oldlenp) {
13771da177e4SLinus Torvalds 			if (get_user(len, oldlenp))
13781da177e4SLinus Torvalds 				return -EFAULT;
13791da177e4SLinus Torvalds 			if (len) {
13801da177e4SLinus Torvalds 				if (len > table->maxlen)
13811da177e4SLinus Torvalds 					len = table->maxlen;
13821da177e4SLinus Torvalds 				if(copy_to_user(oldval, table->data, len))
13831da177e4SLinus Torvalds 					return -EFAULT;
13841da177e4SLinus Torvalds 				if(put_user(len, oldlenp))
13851da177e4SLinus Torvalds 					return -EFAULT;
13861da177e4SLinus Torvalds 			}
13871da177e4SLinus Torvalds 		}
13881da177e4SLinus Torvalds 		if (newval && newlen) {
13891da177e4SLinus Torvalds 			len = newlen;
13901da177e4SLinus Torvalds 			if (len > table->maxlen)
13911da177e4SLinus Torvalds 				len = table->maxlen;
13921da177e4SLinus Torvalds 			if(copy_from_user(table->data, newval, len))
13931da177e4SLinus Torvalds 				return -EFAULT;
13941da177e4SLinus Torvalds 		}
13951da177e4SLinus Torvalds 	}
13961da177e4SLinus Torvalds 	return 0;
13971da177e4SLinus Torvalds }
1398b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
13991da177e4SLinus Torvalds 
14001da177e4SLinus Torvalds /**
14011da177e4SLinus Torvalds  * register_sysctl_table - register a sysctl hierarchy
14021da177e4SLinus Torvalds  * @table: the top-level table structure
14031da177e4SLinus Torvalds  * @insert_at_head: whether the entry should be inserted in front or at the end
14041da177e4SLinus Torvalds  *
14051da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
14061da177e4SLinus Torvalds  * array. An entry with a ctl_name of 0 terminates the table.
14071da177e4SLinus Torvalds  *
14081da177e4SLinus Torvalds  * The members of the &ctl_table structure are used as follows:
14091da177e4SLinus Torvalds  *
14101da177e4SLinus Torvalds  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
14111da177e4SLinus Torvalds  *            must be unique within that level of sysctl
14121da177e4SLinus Torvalds  *
14131da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
14141da177e4SLinus Torvalds  *            enter a sysctl file
14151da177e4SLinus Torvalds  *
14161da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
14171da177e4SLinus Torvalds  *
14181da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
14191da177e4SLinus Torvalds  *
14201da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
14211da177e4SLinus Torvalds  *
14221da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
14231da177e4SLinus Torvalds  *         %NULL.
14241da177e4SLinus Torvalds  *
14251da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
14261da177e4SLinus Torvalds  *
14271da177e4SLinus Torvalds  * strategy - the strategy routine (described below)
14281da177e4SLinus Torvalds  *
14291da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
14301da177e4SLinus Torvalds  *
14311da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
14321da177e4SLinus Torvalds  *
14331da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
14341da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
14351da177e4SLinus Torvalds  *
14361da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
14371da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
14381da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
14391da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
14401da177e4SLinus Torvalds  *
14411da177e4SLinus Torvalds  * More sophisticated management can be enabled by the provision of a
14421da177e4SLinus Torvalds  * strategy routine with the table entry.  This will be called before
14431da177e4SLinus Torvalds  * any automatic read or write of the data is performed.
14441da177e4SLinus Torvalds  *
14451da177e4SLinus Torvalds  * The strategy routine may return
14461da177e4SLinus Torvalds  *
14471da177e4SLinus Torvalds  * < 0 - Error occurred (error is passed to user process)
14481da177e4SLinus Torvalds  *
14491da177e4SLinus Torvalds  * 0   - OK - proceed with automatic read or write.
14501da177e4SLinus Torvalds  *
14511da177e4SLinus Torvalds  * > 0 - OK - read or write has been done by the strategy routine, so
14521da177e4SLinus Torvalds  *       return immediately.
14531da177e4SLinus Torvalds  *
14541da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
14551da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
14561da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
14571da177e4SLinus Torvalds  * cover common cases -
14581da177e4SLinus Torvalds  *
14591da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
14601da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
14611da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
14621da177e4SLinus Torvalds  *
14631da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
14641da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
14651da177e4SLinus Torvalds  *
14661da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
14671da177e4SLinus Torvalds  * to the table header on success.
14681da177e4SLinus Torvalds  */
14691da177e4SLinus Torvalds struct ctl_table_header *register_sysctl_table(ctl_table * table,
14701da177e4SLinus Torvalds 					       int insert_at_head)
14711da177e4SLinus Torvalds {
14721da177e4SLinus Torvalds 	struct ctl_table_header *tmp;
14731da177e4SLinus Torvalds 	tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
14741da177e4SLinus Torvalds 	if (!tmp)
14751da177e4SLinus Torvalds 		return NULL;
14761da177e4SLinus Torvalds 	tmp->ctl_table = table;
14771da177e4SLinus Torvalds 	INIT_LIST_HEAD(&tmp->ctl_entry);
1478330d57fbSAl Viro 	tmp->used = 0;
1479330d57fbSAl Viro 	tmp->unregistering = NULL;
1480330d57fbSAl Viro 	spin_lock(&sysctl_lock);
14811da177e4SLinus Torvalds 	if (insert_at_head)
14821da177e4SLinus Torvalds 		list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
14831da177e4SLinus Torvalds 	else
14841da177e4SLinus Torvalds 		list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1485330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
1486b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
1487330d57fbSAl Viro 	register_proc_table(table, proc_sys_root, tmp);
14881da177e4SLinus Torvalds #endif
14891da177e4SLinus Torvalds 	return tmp;
14901da177e4SLinus Torvalds }
14911da177e4SLinus Torvalds 
14921da177e4SLinus Torvalds /**
14931da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
14941da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
14951da177e4SLinus Torvalds  *
14961da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
14971da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
14981da177e4SLinus Torvalds  */
14991da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
15001da177e4SLinus Torvalds {
1501330d57fbSAl Viro 	might_sleep();
1502330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1503330d57fbSAl Viro 	start_unregistering(header);
1504b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
15051da177e4SLinus Torvalds 	unregister_proc_table(header->ctl_table, proc_sys_root);
15061da177e4SLinus Torvalds #endif
1507330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
15081da177e4SLinus Torvalds 	kfree(header);
15091da177e4SLinus Torvalds }
15101da177e4SLinus Torvalds 
1511b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */
1512b89a8171SEric W. Biederman struct ctl_table_header * register_sysctl_table(ctl_table * table,
1513b89a8171SEric W. Biederman 						int insert_at_head)
1514b89a8171SEric W. Biederman {
1515b89a8171SEric W. Biederman 	return NULL;
1516b89a8171SEric W. Biederman }
1517b89a8171SEric W. Biederman 
1518b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table)
1519b89a8171SEric W. Biederman {
1520b89a8171SEric W. Biederman }
1521b89a8171SEric W. Biederman 
1522b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
1523b89a8171SEric W. Biederman 
15241da177e4SLinus Torvalds /*
15251da177e4SLinus Torvalds  * /proc/sys support
15261da177e4SLinus Torvalds  */
15271da177e4SLinus Torvalds 
1528b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
15291da177e4SLinus Torvalds 
15301da177e4SLinus Torvalds /* Scan the sysctl entries in table and add them all into /proc */
1531330d57fbSAl Viro static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
15321da177e4SLinus Torvalds {
15331da177e4SLinus Torvalds 	struct proc_dir_entry *de;
15341da177e4SLinus Torvalds 	int len;
15351da177e4SLinus Torvalds 	mode_t mode;
15361da177e4SLinus Torvalds 
1537*d99f160aSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
15381da177e4SLinus Torvalds 		/* Can't do anything without a proc name. */
15391da177e4SLinus Torvalds 		if (!table->procname)
15401da177e4SLinus Torvalds 			continue;
15411da177e4SLinus Torvalds 		/* Maybe we can't do anything with it... */
15421da177e4SLinus Torvalds 		if (!table->proc_handler && !table->child) {
15431da177e4SLinus Torvalds 			printk(KERN_WARNING "SYSCTL: Can't register %s\n",
15441da177e4SLinus Torvalds 				table->procname);
15451da177e4SLinus Torvalds 			continue;
15461da177e4SLinus Torvalds 		}
15471da177e4SLinus Torvalds 
15481da177e4SLinus Torvalds 		len = strlen(table->procname);
15491da177e4SLinus Torvalds 		mode = table->mode;
15501da177e4SLinus Torvalds 
15511da177e4SLinus Torvalds 		de = NULL;
15521da177e4SLinus Torvalds 		if (table->proc_handler)
15531da177e4SLinus Torvalds 			mode |= S_IFREG;
15541da177e4SLinus Torvalds 		else {
15551da177e4SLinus Torvalds 			mode |= S_IFDIR;
15561da177e4SLinus Torvalds 			for (de = root->subdir; de; de = de->next) {
15571da177e4SLinus Torvalds 				if (proc_match(len, table->procname, de))
15581da177e4SLinus Torvalds 					break;
15591da177e4SLinus Torvalds 			}
15601da177e4SLinus Torvalds 			/* If the subdir exists already, de is non-NULL */
15611da177e4SLinus Torvalds 		}
15621da177e4SLinus Torvalds 
15631da177e4SLinus Torvalds 		if (!de) {
15641da177e4SLinus Torvalds 			de = create_proc_entry(table->procname, mode, root);
15651da177e4SLinus Torvalds 			if (!de)
15661da177e4SLinus Torvalds 				continue;
1567330d57fbSAl Viro 			de->set = set;
15681da177e4SLinus Torvalds 			de->data = (void *) table;
15691da177e4SLinus Torvalds 			if (table->proc_handler)
15701da177e4SLinus Torvalds 				de->proc_fops = &proc_sys_file_operations;
15711da177e4SLinus Torvalds 		}
15721da177e4SLinus Torvalds 		table->de = de;
15731da177e4SLinus Torvalds 		if (de->mode & S_IFDIR)
1574330d57fbSAl Viro 			register_proc_table(table->child, de, set);
15751da177e4SLinus Torvalds 	}
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds 
15781da177e4SLinus Torvalds /*
15791da177e4SLinus Torvalds  * Unregister a /proc sysctl table and any subdirectories.
15801da177e4SLinus Torvalds  */
15811da177e4SLinus Torvalds static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
15821da177e4SLinus Torvalds {
15831da177e4SLinus Torvalds 	struct proc_dir_entry *de;
1584*d99f160aSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
15851da177e4SLinus Torvalds 		if (!(de = table->de))
15861da177e4SLinus Torvalds 			continue;
15871da177e4SLinus Torvalds 		if (de->mode & S_IFDIR) {
15881da177e4SLinus Torvalds 			if (!table->child) {
15891da177e4SLinus Torvalds 				printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
15901da177e4SLinus Torvalds 				continue;
15911da177e4SLinus Torvalds 			}
15921da177e4SLinus Torvalds 			unregister_proc_table(table->child, de);
15931da177e4SLinus Torvalds 
15941da177e4SLinus Torvalds 			/* Don't unregister directories which still have entries.. */
15951da177e4SLinus Torvalds 			if (de->subdir)
15961da177e4SLinus Torvalds 				continue;
15971da177e4SLinus Torvalds 		}
15981da177e4SLinus Torvalds 
1599330d57fbSAl Viro 		/*
1600330d57fbSAl Viro 		 * In any case, mark the entry as goner; we'll keep it
1601330d57fbSAl Viro 		 * around if it's busy, but we'll know to do nothing with
1602330d57fbSAl Viro 		 * its fields.  We are under sysctl_lock here.
1603330d57fbSAl Viro 		 */
1604330d57fbSAl Viro 		de->data = NULL;
1605330d57fbSAl Viro 
16061da177e4SLinus Torvalds 		/* Don't unregister proc entries that are still being used.. */
16071da177e4SLinus Torvalds 		if (atomic_read(&de->count))
16081da177e4SLinus Torvalds 			continue;
16091da177e4SLinus Torvalds 
16101da177e4SLinus Torvalds 		table->de = NULL;
16111da177e4SLinus Torvalds 		remove_proc_entry(table->procname, root);
16121da177e4SLinus Torvalds 	}
16131da177e4SLinus Torvalds }
16141da177e4SLinus Torvalds 
16151da177e4SLinus Torvalds static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
16161da177e4SLinus Torvalds 			  size_t count, loff_t *ppos)
16171da177e4SLinus Torvalds {
16181da177e4SLinus Torvalds 	int op;
1619330d57fbSAl Viro 	struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
16201da177e4SLinus Torvalds 	struct ctl_table *table;
16211da177e4SLinus Torvalds 	size_t res;
1622330d57fbSAl Viro 	ssize_t error = -ENOTDIR;
16231da177e4SLinus Torvalds 
1624330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1625330d57fbSAl Viro 	if (de && de->data && use_table(de->set)) {
1626330d57fbSAl Viro 		/*
1627330d57fbSAl Viro 		 * at that point we know that sysctl was not unregistered
1628330d57fbSAl Viro 		 * and won't be until we finish
1629330d57fbSAl Viro 		 */
1630330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
16311da177e4SLinus Torvalds 		table = (struct ctl_table *) de->data;
16321da177e4SLinus Torvalds 		if (!table || !table->proc_handler)
1633330d57fbSAl Viro 			goto out;
1634330d57fbSAl Viro 		error = -EPERM;
16351da177e4SLinus Torvalds 		op = (write ? 002 : 004);
16361da177e4SLinus Torvalds 		if (ctl_perm(table, op))
1637330d57fbSAl Viro 			goto out;
16381da177e4SLinus Torvalds 
1639330d57fbSAl Viro 		/* careful: calling conventions are nasty here */
16401da177e4SLinus Torvalds 		res = count;
1641330d57fbSAl Viro 		error = (*table->proc_handler)(table, write, file,
1642330d57fbSAl Viro 						buf, &res, ppos);
1643330d57fbSAl Viro 		if (!error)
1644330d57fbSAl Viro 			error = res;
1645330d57fbSAl Viro 	out:
1646330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1647330d57fbSAl Viro 		unuse_table(de->set);
1648330d57fbSAl Viro 	}
1649330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
16501da177e4SLinus Torvalds 	return error;
16511da177e4SLinus Torvalds }
16521da177e4SLinus Torvalds 
16531da177e4SLinus Torvalds static int proc_opensys(struct inode *inode, struct file *file)
16541da177e4SLinus Torvalds {
16551da177e4SLinus Torvalds 	if (file->f_mode & FMODE_WRITE) {
16561da177e4SLinus Torvalds 		/*
16571da177e4SLinus Torvalds 		 * sysctl entries that are not writable,
16581da177e4SLinus Torvalds 		 * are _NOT_ writable, capabilities or not.
16591da177e4SLinus Torvalds 		 */
16601da177e4SLinus Torvalds 		if (!(inode->i_mode & S_IWUSR))
16611da177e4SLinus Torvalds 			return -EPERM;
16621da177e4SLinus Torvalds 	}
16631da177e4SLinus Torvalds 
16641da177e4SLinus Torvalds 	return 0;
16651da177e4SLinus Torvalds }
16661da177e4SLinus Torvalds 
16671da177e4SLinus Torvalds static ssize_t proc_readsys(struct file * file, char __user * buf,
16681da177e4SLinus Torvalds 			    size_t count, loff_t *ppos)
16691da177e4SLinus Torvalds {
16701da177e4SLinus Torvalds 	return do_rw_proc(0, file, buf, count, ppos);
16711da177e4SLinus Torvalds }
16721da177e4SLinus Torvalds 
16731da177e4SLinus Torvalds static ssize_t proc_writesys(struct file * file, const char __user * buf,
16741da177e4SLinus Torvalds 			     size_t count, loff_t *ppos)
16751da177e4SLinus Torvalds {
16761da177e4SLinus Torvalds 	return do_rw_proc(1, file, (char __user *) buf, count, ppos);
16771da177e4SLinus Torvalds }
16781da177e4SLinus Torvalds 
1679b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write,
1680b1ba4dddSAdrian Bunk 			   struct file *filp, void __user *buffer,
1681b1ba4dddSAdrian Bunk 			   size_t *lenp, loff_t *ppos)
1682f5dd3d6fSSam Vilain {
1683f5dd3d6fSSam Vilain 	size_t len;
1684f5dd3d6fSSam Vilain 	char __user *p;
1685f5dd3d6fSSam Vilain 	char c;
1686f5dd3d6fSSam Vilain 
1687f5dd3d6fSSam Vilain 	if (!data || !maxlen || !*lenp ||
1688f5dd3d6fSSam Vilain 	    (*ppos && !write)) {
1689f5dd3d6fSSam Vilain 		*lenp = 0;
1690f5dd3d6fSSam Vilain 		return 0;
1691f5dd3d6fSSam Vilain 	}
1692f5dd3d6fSSam Vilain 
1693f5dd3d6fSSam Vilain 	if (write) {
1694f5dd3d6fSSam Vilain 		len = 0;
1695f5dd3d6fSSam Vilain 		p = buffer;
1696f5dd3d6fSSam Vilain 		while (len < *lenp) {
1697f5dd3d6fSSam Vilain 			if (get_user(c, p++))
1698f5dd3d6fSSam Vilain 				return -EFAULT;
1699f5dd3d6fSSam Vilain 			if (c == 0 || c == '\n')
1700f5dd3d6fSSam Vilain 				break;
1701f5dd3d6fSSam Vilain 			len++;
1702f5dd3d6fSSam Vilain 		}
1703f5dd3d6fSSam Vilain 		if (len >= maxlen)
1704f5dd3d6fSSam Vilain 			len = maxlen-1;
1705f5dd3d6fSSam Vilain 		if(copy_from_user(data, buffer, len))
1706f5dd3d6fSSam Vilain 			return -EFAULT;
1707f5dd3d6fSSam Vilain 		((char *) data)[len] = 0;
1708f5dd3d6fSSam Vilain 		*ppos += *lenp;
1709f5dd3d6fSSam Vilain 	} else {
1710f5dd3d6fSSam Vilain 		len = strlen(data);
1711f5dd3d6fSSam Vilain 		if (len > maxlen)
1712f5dd3d6fSSam Vilain 			len = maxlen;
1713f5dd3d6fSSam Vilain 		if (len > *lenp)
1714f5dd3d6fSSam Vilain 			len = *lenp;
1715f5dd3d6fSSam Vilain 		if (len)
1716f5dd3d6fSSam Vilain 			if(copy_to_user(buffer, data, len))
1717f5dd3d6fSSam Vilain 				return -EFAULT;
1718f5dd3d6fSSam Vilain 		if (len < *lenp) {
1719f5dd3d6fSSam Vilain 			if(put_user('\n', ((char __user *) buffer) + len))
1720f5dd3d6fSSam Vilain 				return -EFAULT;
1721f5dd3d6fSSam Vilain 			len++;
1722f5dd3d6fSSam Vilain 		}
1723f5dd3d6fSSam Vilain 		*lenp = len;
1724f5dd3d6fSSam Vilain 		*ppos += len;
1725f5dd3d6fSSam Vilain 	}
1726f5dd3d6fSSam Vilain 	return 0;
1727f5dd3d6fSSam Vilain }
1728f5dd3d6fSSam Vilain 
17291da177e4SLinus Torvalds /**
17301da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
17311da177e4SLinus Torvalds  * @table: the sysctl table
17321da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
17331da177e4SLinus Torvalds  * @filp: the file structure
17341da177e4SLinus Torvalds  * @buffer: the user buffer
17351da177e4SLinus Torvalds  * @lenp: the size of the user buffer
17361da177e4SLinus Torvalds  * @ppos: file position
17371da177e4SLinus Torvalds  *
17381da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
17391da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
17401da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
17411da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
17421da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
17431da177e4SLinus Torvalds  * not large enough.
17441da177e4SLinus Torvalds  *
17451da177e4SLinus Torvalds  * Returns 0 on success.
17461da177e4SLinus Torvalds  */
17471da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
17481da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
17491da177e4SLinus Torvalds {
1750f5dd3d6fSSam Vilain 	return _proc_do_string(table->data, table->maxlen, write, filp,
1751f5dd3d6fSSam Vilain 			       buffer, lenp, ppos);
17521da177e4SLinus Torvalds }
17531da177e4SLinus Torvalds 
17541da177e4SLinus Torvalds /*
17551da177e4SLinus Torvalds  *	Special case of dostring for the UTS structure. This has locks
17561da177e4SLinus Torvalds  *	to observe. Should this be in kernel/sys.c ????
17571da177e4SLinus Torvalds  */
17581da177e4SLinus Torvalds 
17598218c74cSSerge E. Hallyn #ifndef CONFIG_UTS_NS
17608218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
17611da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
17621da177e4SLinus Torvalds {
17631da177e4SLinus Torvalds 	int r;
17641da177e4SLinus Torvalds 
17651da177e4SLinus Torvalds 	if (!write) {
17661da177e4SLinus Torvalds 		down_read(&uts_sem);
17671da177e4SLinus Torvalds 		r=proc_dostring(table,0,filp,buffer,lenp, ppos);
17681da177e4SLinus Torvalds 		up_read(&uts_sem);
17691da177e4SLinus Torvalds 	} else {
17701da177e4SLinus Torvalds 		down_write(&uts_sem);
17711da177e4SLinus Torvalds 		r=proc_dostring(table,1,filp,buffer,lenp, ppos);
17721da177e4SLinus Torvalds 		up_write(&uts_sem);
17731da177e4SLinus Torvalds 	}
17741da177e4SLinus Torvalds 	return r;
17751da177e4SLinus Torvalds }
17768218c74cSSerge E. Hallyn #else /* !CONFIG_UTS_NS */
17778218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
17788218c74cSSerge E. Hallyn 		  void __user *buffer, size_t *lenp, loff_t *ppos)
17798218c74cSSerge E. Hallyn {
17808218c74cSSerge E. Hallyn 	int r;
17818218c74cSSerge E. Hallyn 	struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
17828218c74cSSerge E. Hallyn 	char* which;
17838218c74cSSerge E. Hallyn 
17848218c74cSSerge E. Hallyn 	switch (table->ctl_name) {
17858218c74cSSerge E. Hallyn 	case KERN_OSTYPE:
17868218c74cSSerge E. Hallyn 		which = uts_ns->name.sysname;
17878218c74cSSerge E. Hallyn 		break;
17888218c74cSSerge E. Hallyn 	case KERN_NODENAME:
17898218c74cSSerge E. Hallyn 		which = uts_ns->name.nodename;
17908218c74cSSerge E. Hallyn 		break;
17918218c74cSSerge E. Hallyn 	case KERN_OSRELEASE:
17928218c74cSSerge E. Hallyn 		which = uts_ns->name.release;
17938218c74cSSerge E. Hallyn 		break;
17948218c74cSSerge E. Hallyn 	case KERN_VERSION:
17958218c74cSSerge E. Hallyn 		which = uts_ns->name.version;
17968218c74cSSerge E. Hallyn 		break;
17978218c74cSSerge E. Hallyn 	case KERN_DOMAINNAME:
17988218c74cSSerge E. Hallyn 		which = uts_ns->name.domainname;
17998218c74cSSerge E. Hallyn 		break;
18008218c74cSSerge E. Hallyn 	default:
18018218c74cSSerge E. Hallyn 		r = -EINVAL;
18028218c74cSSerge E. Hallyn 		goto out;
18038218c74cSSerge E. Hallyn 	}
18048218c74cSSerge E. Hallyn 
18058218c74cSSerge E. Hallyn 	if (!write) {
18068218c74cSSerge E. Hallyn 		down_read(&uts_sem);
18078218c74cSSerge E. Hallyn 		r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
18088218c74cSSerge E. Hallyn 		up_read(&uts_sem);
18098218c74cSSerge E. Hallyn 	} else {
18108218c74cSSerge E. Hallyn 		down_write(&uts_sem);
18118218c74cSSerge E. Hallyn 		r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
18128218c74cSSerge E. Hallyn 		up_write(&uts_sem);
18138218c74cSSerge E. Hallyn 	}
18148218c74cSSerge E. Hallyn  out:
18158218c74cSSerge E. Hallyn 	return r;
18168218c74cSSerge E. Hallyn }
18178218c74cSSerge E. Hallyn #endif /* !CONFIG_UTS_NS */
18181da177e4SLinus Torvalds 
18191da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
18201da177e4SLinus Torvalds 				 int *valp,
18211da177e4SLinus Torvalds 				 int write, void *data)
18221da177e4SLinus Torvalds {
18231da177e4SLinus Torvalds 	if (write) {
18241da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
18251da177e4SLinus Torvalds 	} else {
18261da177e4SLinus Torvalds 		int val = *valp;
18271da177e4SLinus Torvalds 		if (val < 0) {
18281da177e4SLinus Torvalds 			*negp = -1;
18291da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
18301da177e4SLinus Torvalds 		} else {
18311da177e4SLinus Torvalds 			*negp = 0;
18321da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
18331da177e4SLinus Torvalds 		}
18341da177e4SLinus Torvalds 	}
18351da177e4SLinus Torvalds 	return 0;
18361da177e4SLinus Torvalds }
18371da177e4SLinus Torvalds 
1838fcfbd547SKirill Korotaev static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1839fcfbd547SKirill Korotaev 		  int write, struct file *filp, void __user *buffer,
1840fcfbd547SKirill Korotaev 		  size_t *lenp, loff_t *ppos,
18411da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
18421da177e4SLinus Torvalds 			      int write, void *data),
18431da177e4SLinus Torvalds 		  void *data)
18441da177e4SLinus Torvalds {
18451da177e4SLinus Torvalds #define TMPBUFLEN 21
18461da177e4SLinus Torvalds 	int *i, vleft, first=1, neg, val;
18471da177e4SLinus Torvalds 	unsigned long lval;
18481da177e4SLinus Torvalds 	size_t left, len;
18491da177e4SLinus Torvalds 
18501da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
18511da177e4SLinus Torvalds 	char __user *s = buffer;
18521da177e4SLinus Torvalds 
1853fcfbd547SKirill Korotaev 	if (!tbl_data || !table->maxlen || !*lenp ||
18541da177e4SLinus Torvalds 	    (*ppos && !write)) {
18551da177e4SLinus Torvalds 		*lenp = 0;
18561da177e4SLinus Torvalds 		return 0;
18571da177e4SLinus Torvalds 	}
18581da177e4SLinus Torvalds 
1859fcfbd547SKirill Korotaev 	i = (int *) tbl_data;
18601da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
18611da177e4SLinus Torvalds 	left = *lenp;
18621da177e4SLinus Torvalds 
18631da177e4SLinus Torvalds 	if (!conv)
18641da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
18651da177e4SLinus Torvalds 
18661da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
18671da177e4SLinus Torvalds 		if (write) {
18681da177e4SLinus Torvalds 			while (left) {
18691da177e4SLinus Torvalds 				char c;
18701da177e4SLinus Torvalds 				if (get_user(c, s))
18711da177e4SLinus Torvalds 					return -EFAULT;
18721da177e4SLinus Torvalds 				if (!isspace(c))
18731da177e4SLinus Torvalds 					break;
18741da177e4SLinus Torvalds 				left--;
18751da177e4SLinus Torvalds 				s++;
18761da177e4SLinus Torvalds 			}
18771da177e4SLinus Torvalds 			if (!left)
18781da177e4SLinus Torvalds 				break;
18791da177e4SLinus Torvalds 			neg = 0;
18801da177e4SLinus Torvalds 			len = left;
18811da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
18821da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
18831da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
18841da177e4SLinus Torvalds 				return -EFAULT;
18851da177e4SLinus Torvalds 			buf[len] = 0;
18861da177e4SLinus Torvalds 			p = buf;
18871da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
18881da177e4SLinus Torvalds 				neg = 1;
18891da177e4SLinus Torvalds 				left--, p++;
18901da177e4SLinus Torvalds 			}
18911da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
18921da177e4SLinus Torvalds 				break;
18931da177e4SLinus Torvalds 
18941da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
18951da177e4SLinus Torvalds 
18961da177e4SLinus Torvalds 			len = p-buf;
18971da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
18981da177e4SLinus Torvalds 				break;
18991da177e4SLinus Torvalds 			if (neg)
19001da177e4SLinus Torvalds 				val = -val;
19011da177e4SLinus Torvalds 			s += len;
19021da177e4SLinus Torvalds 			left -= len;
19031da177e4SLinus Torvalds 
19041da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
19051da177e4SLinus Torvalds 				break;
19061da177e4SLinus Torvalds 		} else {
19071da177e4SLinus Torvalds 			p = buf;
19081da177e4SLinus Torvalds 			if (!first)
19091da177e4SLinus Torvalds 				*p++ = '\t';
19101da177e4SLinus Torvalds 
19111da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
19121da177e4SLinus Torvalds 				break;
19131da177e4SLinus Torvalds 
19141da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
19151da177e4SLinus Torvalds 			len = strlen(buf);
19161da177e4SLinus Torvalds 			if (len > left)
19171da177e4SLinus Torvalds 				len = left;
19181da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
19191da177e4SLinus Torvalds 				return -EFAULT;
19201da177e4SLinus Torvalds 			left -= len;
19211da177e4SLinus Torvalds 			s += len;
19221da177e4SLinus Torvalds 		}
19231da177e4SLinus Torvalds 	}
19241da177e4SLinus Torvalds 
19251da177e4SLinus Torvalds 	if (!write && !first && left) {
19261da177e4SLinus Torvalds 		if(put_user('\n', s))
19271da177e4SLinus Torvalds 			return -EFAULT;
19281da177e4SLinus Torvalds 		left--, s++;
19291da177e4SLinus Torvalds 	}
19301da177e4SLinus Torvalds 	if (write) {
19311da177e4SLinus Torvalds 		while (left) {
19321da177e4SLinus Torvalds 			char c;
19331da177e4SLinus Torvalds 			if (get_user(c, s++))
19341da177e4SLinus Torvalds 				return -EFAULT;
19351da177e4SLinus Torvalds 			if (!isspace(c))
19361da177e4SLinus Torvalds 				break;
19371da177e4SLinus Torvalds 			left--;
19381da177e4SLinus Torvalds 		}
19391da177e4SLinus Torvalds 	}
19401da177e4SLinus Torvalds 	if (write && first)
19411da177e4SLinus Torvalds 		return -EINVAL;
19421da177e4SLinus Torvalds 	*lenp -= left;
19431da177e4SLinus Torvalds 	*ppos += *lenp;
19441da177e4SLinus Torvalds 	return 0;
19451da177e4SLinus Torvalds #undef TMPBUFLEN
19461da177e4SLinus Torvalds }
19471da177e4SLinus Torvalds 
1948fcfbd547SKirill Korotaev static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1949fcfbd547SKirill Korotaev 		  void __user *buffer, size_t *lenp, loff_t *ppos,
1950fcfbd547SKirill Korotaev 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1951fcfbd547SKirill Korotaev 			      int write, void *data),
1952fcfbd547SKirill Korotaev 		  void *data)
1953fcfbd547SKirill Korotaev {
1954fcfbd547SKirill Korotaev 	return __do_proc_dointvec(table->data, table, write, filp,
1955fcfbd547SKirill Korotaev 			buffer, lenp, ppos, conv, data);
1956fcfbd547SKirill Korotaev }
1957fcfbd547SKirill Korotaev 
19581da177e4SLinus Torvalds /**
19591da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
19601da177e4SLinus Torvalds  * @table: the sysctl table
19611da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
19621da177e4SLinus Torvalds  * @filp: the file structure
19631da177e4SLinus Torvalds  * @buffer: the user buffer
19641da177e4SLinus Torvalds  * @lenp: the size of the user buffer
19651da177e4SLinus Torvalds  * @ppos: file position
19661da177e4SLinus Torvalds  *
19671da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
19681da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
19691da177e4SLinus Torvalds  *
19701da177e4SLinus Torvalds  * Returns 0 on success.
19711da177e4SLinus Torvalds  */
19721da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
19731da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
19741da177e4SLinus Torvalds {
19751da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
19761da177e4SLinus Torvalds 		    	    NULL,NULL);
19771da177e4SLinus Torvalds }
19781da177e4SLinus Torvalds 
19791da177e4SLinus Torvalds #define OP_SET	0
19801da177e4SLinus Torvalds #define OP_AND	1
19811da177e4SLinus Torvalds #define OP_OR	2
19821da177e4SLinus Torvalds #define OP_MAX	3
19831da177e4SLinus Torvalds #define OP_MIN	4
19841da177e4SLinus Torvalds 
19851da177e4SLinus Torvalds static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
19861da177e4SLinus Torvalds 				      int *valp,
19871da177e4SLinus Torvalds 				      int write, void *data)
19881da177e4SLinus Torvalds {
19891da177e4SLinus Torvalds 	int op = *(int *)data;
19901da177e4SLinus Torvalds 	if (write) {
19911da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
19921da177e4SLinus Torvalds 		switch(op) {
19931da177e4SLinus Torvalds 		case OP_SET:	*valp = val; break;
19941da177e4SLinus Torvalds 		case OP_AND:	*valp &= val; break;
19951da177e4SLinus Torvalds 		case OP_OR:	*valp |= val; break;
19961da177e4SLinus Torvalds 		case OP_MAX:	if(*valp < val)
19971da177e4SLinus Torvalds 					*valp = val;
19981da177e4SLinus Torvalds 				break;
19991da177e4SLinus Torvalds 		case OP_MIN:	if(*valp > val)
20001da177e4SLinus Torvalds 				*valp = val;
20011da177e4SLinus Torvalds 				break;
20021da177e4SLinus Torvalds 		}
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  *	init may raise the set.
20181da177e4SLinus Torvalds  */
20191da177e4SLinus Torvalds 
20201da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
20211da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
20221da177e4SLinus Torvalds {
20231da177e4SLinus Torvalds 	int op;
20241da177e4SLinus Torvalds 
20251da177e4SLinus Torvalds 	if (!capable(CAP_SYS_MODULE)) {
20261da177e4SLinus Torvalds 		return -EPERM;
20271da177e4SLinus Torvalds 	}
20281da177e4SLinus Torvalds 
2029f400e198SSukadev Bhattiprolu 	op = is_init(current) ? OP_SET : OP_AND;
20301da177e4SLinus Torvalds 	return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
20311da177e4SLinus Torvalds 				do_proc_dointvec_bset_conv,&op);
20321da177e4SLinus Torvalds }
20331da177e4SLinus Torvalds 
20341da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
20351da177e4SLinus Torvalds 	int *min;
20361da177e4SLinus Torvalds 	int *max;
20371da177e4SLinus Torvalds };
20381da177e4SLinus Torvalds 
20391da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
20401da177e4SLinus Torvalds 					int *valp,
20411da177e4SLinus Torvalds 					int write, void *data)
20421da177e4SLinus Torvalds {
20431da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
20441da177e4SLinus Torvalds 	if (write) {
20451da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
20461da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
20471da177e4SLinus Torvalds 		    (param->max && *param->max < val))
20481da177e4SLinus Torvalds 			return -EINVAL;
20491da177e4SLinus Torvalds 		*valp = val;
20501da177e4SLinus Torvalds 	} else {
20511da177e4SLinus Torvalds 		int val = *valp;
20521da177e4SLinus Torvalds 		if (val < 0) {
20531da177e4SLinus Torvalds 			*negp = -1;
20541da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
20551da177e4SLinus Torvalds 		} else {
20561da177e4SLinus Torvalds 			*negp = 0;
20571da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
20581da177e4SLinus Torvalds 		}
20591da177e4SLinus Torvalds 	}
20601da177e4SLinus Torvalds 	return 0;
20611da177e4SLinus Torvalds }
20621da177e4SLinus Torvalds 
20631da177e4SLinus Torvalds /**
20641da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
20651da177e4SLinus Torvalds  * @table: the sysctl table
20661da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
20671da177e4SLinus Torvalds  * @filp: the file structure
20681da177e4SLinus Torvalds  * @buffer: the user buffer
20691da177e4SLinus Torvalds  * @lenp: the size of the user buffer
20701da177e4SLinus Torvalds  * @ppos: file position
20711da177e4SLinus Torvalds  *
20721da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
20731da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
20741da177e4SLinus Torvalds  *
20751da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
20761da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
20771da177e4SLinus Torvalds  *
20781da177e4SLinus Torvalds  * Returns 0 on success.
20791da177e4SLinus Torvalds  */
20801da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
20811da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
20821da177e4SLinus Torvalds {
20831da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
20841da177e4SLinus Torvalds 		.min = (int *) table->extra1,
20851da177e4SLinus Torvalds 		.max = (int *) table->extra2,
20861da177e4SLinus Torvalds 	};
20871da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
20881da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
20891da177e4SLinus Torvalds }
20901da177e4SLinus Torvalds 
2091fcfbd547SKirill Korotaev static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
20921da177e4SLinus Torvalds 				     struct file *filp,
20931da177e4SLinus Torvalds 				     void __user *buffer,
20941da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
20951da177e4SLinus Torvalds 				     unsigned long convmul,
20961da177e4SLinus Torvalds 				     unsigned long convdiv)
20971da177e4SLinus Torvalds {
20981da177e4SLinus Torvalds #define TMPBUFLEN 21
20991da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
21001da177e4SLinus Torvalds 	int vleft, first=1, neg;
21011da177e4SLinus Torvalds 	size_t len, left;
21021da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
21031da177e4SLinus Torvalds 	char __user *s = buffer;
21041da177e4SLinus Torvalds 
2105fcfbd547SKirill Korotaev 	if (!data || !table->maxlen || !*lenp ||
21061da177e4SLinus Torvalds 	    (*ppos && !write)) {
21071da177e4SLinus Torvalds 		*lenp = 0;
21081da177e4SLinus Torvalds 		return 0;
21091da177e4SLinus Torvalds 	}
21101da177e4SLinus Torvalds 
2111fcfbd547SKirill Korotaev 	i = (unsigned long *) data;
21121da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
21131da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
21141da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
21151da177e4SLinus Torvalds 	left = *lenp;
21161da177e4SLinus Torvalds 
21171da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
21181da177e4SLinus Torvalds 		if (write) {
21191da177e4SLinus Torvalds 			while (left) {
21201da177e4SLinus Torvalds 				char c;
21211da177e4SLinus Torvalds 				if (get_user(c, s))
21221da177e4SLinus Torvalds 					return -EFAULT;
21231da177e4SLinus Torvalds 				if (!isspace(c))
21241da177e4SLinus Torvalds 					break;
21251da177e4SLinus Torvalds 				left--;
21261da177e4SLinus Torvalds 				s++;
21271da177e4SLinus Torvalds 			}
21281da177e4SLinus Torvalds 			if (!left)
21291da177e4SLinus Torvalds 				break;
21301da177e4SLinus Torvalds 			neg = 0;
21311da177e4SLinus Torvalds 			len = left;
21321da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
21331da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
21341da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
21351da177e4SLinus Torvalds 				return -EFAULT;
21361da177e4SLinus Torvalds 			buf[len] = 0;
21371da177e4SLinus Torvalds 			p = buf;
21381da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
21391da177e4SLinus Torvalds 				neg = 1;
21401da177e4SLinus Torvalds 				left--, p++;
21411da177e4SLinus Torvalds 			}
21421da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
21431da177e4SLinus Torvalds 				break;
21441da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
21451da177e4SLinus Torvalds 			len = p-buf;
21461da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
21471da177e4SLinus Torvalds 				break;
21481da177e4SLinus Torvalds 			if (neg)
21491da177e4SLinus Torvalds 				val = -val;
21501da177e4SLinus Torvalds 			s += len;
21511da177e4SLinus Torvalds 			left -= len;
21521da177e4SLinus Torvalds 
21531da177e4SLinus Torvalds 			if(neg)
21541da177e4SLinus Torvalds 				continue;
21551da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
21561da177e4SLinus Torvalds 				continue;
21571da177e4SLinus Torvalds 			*i = val;
21581da177e4SLinus Torvalds 		} else {
21591da177e4SLinus Torvalds 			p = buf;
21601da177e4SLinus Torvalds 			if (!first)
21611da177e4SLinus Torvalds 				*p++ = '\t';
21621da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
21631da177e4SLinus Torvalds 			len = strlen(buf);
21641da177e4SLinus Torvalds 			if (len > left)
21651da177e4SLinus Torvalds 				len = left;
21661da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
21671da177e4SLinus Torvalds 				return -EFAULT;
21681da177e4SLinus Torvalds 			left -= len;
21691da177e4SLinus Torvalds 			s += len;
21701da177e4SLinus Torvalds 		}
21711da177e4SLinus Torvalds 	}
21721da177e4SLinus Torvalds 
21731da177e4SLinus Torvalds 	if (!write && !first && left) {
21741da177e4SLinus Torvalds 		if(put_user('\n', s))
21751da177e4SLinus Torvalds 			return -EFAULT;
21761da177e4SLinus Torvalds 		left--, s++;
21771da177e4SLinus Torvalds 	}
21781da177e4SLinus Torvalds 	if (write) {
21791da177e4SLinus Torvalds 		while (left) {
21801da177e4SLinus Torvalds 			char c;
21811da177e4SLinus Torvalds 			if (get_user(c, s++))
21821da177e4SLinus Torvalds 				return -EFAULT;
21831da177e4SLinus Torvalds 			if (!isspace(c))
21841da177e4SLinus Torvalds 				break;
21851da177e4SLinus Torvalds 			left--;
21861da177e4SLinus Torvalds 		}
21871da177e4SLinus Torvalds 	}
21881da177e4SLinus Torvalds 	if (write && first)
21891da177e4SLinus Torvalds 		return -EINVAL;
21901da177e4SLinus Torvalds 	*lenp -= left;
21911da177e4SLinus Torvalds 	*ppos += *lenp;
21921da177e4SLinus Torvalds 	return 0;
21931da177e4SLinus Torvalds #undef TMPBUFLEN
21941da177e4SLinus Torvalds }
21951da177e4SLinus Torvalds 
2196fcfbd547SKirill Korotaev static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2197fcfbd547SKirill Korotaev 				     struct file *filp,
2198fcfbd547SKirill Korotaev 				     void __user *buffer,
2199fcfbd547SKirill Korotaev 				     size_t *lenp, loff_t *ppos,
2200fcfbd547SKirill Korotaev 				     unsigned long convmul,
2201fcfbd547SKirill Korotaev 				     unsigned long convdiv)
2202fcfbd547SKirill Korotaev {
2203fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(table->data, table, write,
2204fcfbd547SKirill Korotaev 			filp, buffer, lenp, ppos, convmul, convdiv);
2205fcfbd547SKirill Korotaev }
2206fcfbd547SKirill Korotaev 
22071da177e4SLinus Torvalds /**
22081da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
22091da177e4SLinus Torvalds  * @table: the sysctl table
22101da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
22111da177e4SLinus Torvalds  * @filp: the file structure
22121da177e4SLinus Torvalds  * @buffer: the user buffer
22131da177e4SLinus Torvalds  * @lenp: the size of the user buffer
22141da177e4SLinus Torvalds  * @ppos: file position
22151da177e4SLinus Torvalds  *
22161da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
22171da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
22181da177e4SLinus Torvalds  *
22191da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
22201da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
22211da177e4SLinus Torvalds  *
22221da177e4SLinus Torvalds  * Returns 0 on success.
22231da177e4SLinus Torvalds  */
22241da177e4SLinus Torvalds int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
22251da177e4SLinus Torvalds 			   void __user *buffer, size_t *lenp, loff_t *ppos)
22261da177e4SLinus Torvalds {
22271da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
22281da177e4SLinus Torvalds }
22291da177e4SLinus Torvalds 
22301da177e4SLinus Torvalds /**
22311da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
22321da177e4SLinus Torvalds  * @table: the sysctl table
22331da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
22341da177e4SLinus Torvalds  * @filp: the file structure
22351da177e4SLinus Torvalds  * @buffer: the user buffer
22361da177e4SLinus Torvalds  * @lenp: the size of the user buffer
22371da177e4SLinus Torvalds  * @ppos: file position
22381da177e4SLinus Torvalds  *
22391da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
22401da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
22411da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
22421da177e4SLinus Torvalds  *
22431da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
22441da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
22451da177e4SLinus Torvalds  *
22461da177e4SLinus Torvalds  * Returns 0 on success.
22471da177e4SLinus Torvalds  */
22481da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
22491da177e4SLinus Torvalds 				      struct file *filp,
22501da177e4SLinus Torvalds 				      void __user *buffer,
22511da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
22521da177e4SLinus Torvalds {
22531da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer,
22541da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
22551da177e4SLinus Torvalds }
22561da177e4SLinus Torvalds 
22571da177e4SLinus Torvalds 
22581da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
22591da177e4SLinus Torvalds 					 int *valp,
22601da177e4SLinus Torvalds 					 int write, void *data)
22611da177e4SLinus Torvalds {
22621da177e4SLinus Torvalds 	if (write) {
2263cba9f33dSBart Samwel 		if (*lvalp > LONG_MAX / HZ)
2264cba9f33dSBart Samwel 			return 1;
22651da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
22661da177e4SLinus Torvalds 	} else {
22671da177e4SLinus Torvalds 		int val = *valp;
22681da177e4SLinus Torvalds 		unsigned long lval;
22691da177e4SLinus Torvalds 		if (val < 0) {
22701da177e4SLinus Torvalds 			*negp = -1;
22711da177e4SLinus Torvalds 			lval = (unsigned long)-val;
22721da177e4SLinus Torvalds 		} else {
22731da177e4SLinus Torvalds 			*negp = 0;
22741da177e4SLinus Torvalds 			lval = (unsigned long)val;
22751da177e4SLinus Torvalds 		}
22761da177e4SLinus Torvalds 		*lvalp = lval / HZ;
22771da177e4SLinus Torvalds 	}
22781da177e4SLinus Torvalds 	return 0;
22791da177e4SLinus Torvalds }
22801da177e4SLinus Torvalds 
22811da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
22821da177e4SLinus Torvalds 						int *valp,
22831da177e4SLinus Torvalds 						int write, void *data)
22841da177e4SLinus Torvalds {
22851da177e4SLinus Torvalds 	if (write) {
2286cba9f33dSBart Samwel 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2287cba9f33dSBart Samwel 			return 1;
22881da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
22891da177e4SLinus Torvalds 	} else {
22901da177e4SLinus Torvalds 		int val = *valp;
22911da177e4SLinus Torvalds 		unsigned long lval;
22921da177e4SLinus Torvalds 		if (val < 0) {
22931da177e4SLinus Torvalds 			*negp = -1;
22941da177e4SLinus Torvalds 			lval = (unsigned long)-val;
22951da177e4SLinus Torvalds 		} else {
22961da177e4SLinus Torvalds 			*negp = 0;
22971da177e4SLinus Torvalds 			lval = (unsigned long)val;
22981da177e4SLinus Torvalds 		}
22991da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
23001da177e4SLinus Torvalds 	}
23011da177e4SLinus Torvalds 	return 0;
23021da177e4SLinus Torvalds }
23031da177e4SLinus Torvalds 
23041da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
23051da177e4SLinus Torvalds 					    int *valp,
23061da177e4SLinus Torvalds 					    int write, void *data)
23071da177e4SLinus Torvalds {
23081da177e4SLinus Torvalds 	if (write) {
23091da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
23101da177e4SLinus Torvalds 	} else {
23111da177e4SLinus Torvalds 		int val = *valp;
23121da177e4SLinus Torvalds 		unsigned long lval;
23131da177e4SLinus Torvalds 		if (val < 0) {
23141da177e4SLinus Torvalds 			*negp = -1;
23151da177e4SLinus Torvalds 			lval = (unsigned long)-val;
23161da177e4SLinus Torvalds 		} else {
23171da177e4SLinus Torvalds 			*negp = 0;
23181da177e4SLinus Torvalds 			lval = (unsigned long)val;
23191da177e4SLinus Torvalds 		}
23201da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
23211da177e4SLinus Torvalds 	}
23221da177e4SLinus Torvalds 	return 0;
23231da177e4SLinus Torvalds }
23241da177e4SLinus Torvalds 
23251da177e4SLinus Torvalds /**
23261da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
23271da177e4SLinus Torvalds  * @table: the sysctl table
23281da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23291da177e4SLinus Torvalds  * @filp: the file structure
23301da177e4SLinus Torvalds  * @buffer: the user buffer
23311da177e4SLinus Torvalds  * @lenp: the size of the user buffer
23321da177e4SLinus Torvalds  * @ppos: file position
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 seconds, and are converted into
23371da177e4SLinus Torvalds  * jiffies.
23381da177e4SLinus Torvalds  *
23391da177e4SLinus Torvalds  * Returns 0 on success.
23401da177e4SLinus Torvalds  */
23411da177e4SLinus Torvalds int proc_dointvec_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_jiffies_conv,NULL);
23461da177e4SLinus Torvalds }
23471da177e4SLinus Torvalds 
23481da177e4SLinus Torvalds /**
23491da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
23501da177e4SLinus Torvalds  * @table: the sysctl table
23511da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23521da177e4SLinus Torvalds  * @filp: the file structure
23531da177e4SLinus Torvalds  * @buffer: the user buffer
23541da177e4SLinus Torvalds  * @lenp: the size of the user buffer
23551e5d5331SRandy Dunlap  * @ppos: pointer to the file position
23561da177e4SLinus Torvalds  *
23571da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23581da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23591da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
23601da177e4SLinus Torvalds  * are converted into jiffies.
23611da177e4SLinus Torvalds  *
23621da177e4SLinus Torvalds  * Returns 0 on success.
23631da177e4SLinus Torvalds  */
23641da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
23651da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
23661da177e4SLinus Torvalds {
23671da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
23681da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
23691da177e4SLinus Torvalds }
23701da177e4SLinus Torvalds 
23711da177e4SLinus Torvalds /**
23721da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
23731da177e4SLinus Torvalds  * @table: the sysctl table
23741da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23751da177e4SLinus Torvalds  * @filp: the file structure
23761da177e4SLinus Torvalds  * @buffer: the user buffer
23771da177e4SLinus Torvalds  * @lenp: the size of the user buffer
237867be2dd1SMartin Waitz  * @ppos: file position
237967be2dd1SMartin Waitz  * @ppos: the current position in the file
23801da177e4SLinus Torvalds  *
23811da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23821da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23831da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
23841da177e4SLinus Torvalds  * are converted into jiffies.
23851da177e4SLinus Torvalds  *
23861da177e4SLinus Torvalds  * Returns 0 on success.
23871da177e4SLinus Torvalds  */
23881da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
23891da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
23901da177e4SLinus Torvalds {
23911da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
23921da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
23931da177e4SLinus Torvalds }
23941da177e4SLinus Torvalds 
2395fcfbd547SKirill Korotaev #ifdef CONFIG_SYSVIPC
2396fcfbd547SKirill Korotaev static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2397fcfbd547SKirill Korotaev 		void __user *buffer, size_t *lenp, loff_t *ppos)
2398fcfbd547SKirill Korotaev {
2399fcfbd547SKirill Korotaev 	void *data;
2400fcfbd547SKirill Korotaev 	struct ipc_namespace *ns;
2401fcfbd547SKirill Korotaev 
2402fcfbd547SKirill Korotaev 	ns = current->nsproxy->ipc_ns;
2403fcfbd547SKirill Korotaev 
2404fcfbd547SKirill Korotaev 	switch (table->ctl_name) {
2405fcfbd547SKirill Korotaev 	case KERN_SHMMAX:
2406fcfbd547SKirill Korotaev 		data = &ns->shm_ctlmax;
2407fcfbd547SKirill Korotaev 		goto proc_minmax;
2408fcfbd547SKirill Korotaev 	case KERN_SHMALL:
2409fcfbd547SKirill Korotaev 		data = &ns->shm_ctlall;
2410fcfbd547SKirill Korotaev 		goto proc_minmax;
2411fcfbd547SKirill Korotaev 	case KERN_SHMMNI:
2412fcfbd547SKirill Korotaev 		data = &ns->shm_ctlmni;
2413fcfbd547SKirill Korotaev 		break;
2414fcfbd547SKirill Korotaev 	case KERN_MSGMAX:
2415fcfbd547SKirill Korotaev 		data = &ns->msg_ctlmax;
2416fcfbd547SKirill Korotaev 		break;
2417fcfbd547SKirill Korotaev 	case KERN_MSGMNI:
2418fcfbd547SKirill Korotaev 		data = &ns->msg_ctlmni;
2419fcfbd547SKirill Korotaev 		break;
2420fcfbd547SKirill Korotaev 	case KERN_MSGMNB:
2421fcfbd547SKirill Korotaev 		data = &ns->msg_ctlmnb;
2422fcfbd547SKirill Korotaev 		break;
2423fcfbd547SKirill Korotaev 	case KERN_SEM:
2424fcfbd547SKirill Korotaev 		data = &ns->sem_ctls;
2425fcfbd547SKirill Korotaev 		break;
2426fcfbd547SKirill Korotaev 	default:
2427fcfbd547SKirill Korotaev 		return -EINVAL;
2428fcfbd547SKirill Korotaev 	}
2429fcfbd547SKirill Korotaev 
2430fcfbd547SKirill Korotaev 	return __do_proc_dointvec(data, table, write, filp, buffer,
2431fcfbd547SKirill Korotaev 			lenp, ppos, NULL, NULL);
2432fcfbd547SKirill Korotaev proc_minmax:
2433fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2434fcfbd547SKirill Korotaev 			lenp, ppos, 1l, 1l);
2435fcfbd547SKirill Korotaev }
2436fcfbd547SKirill Korotaev #endif
2437fcfbd547SKirill Korotaev 
24389ec52099SCedric Le Goater static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
24399ec52099SCedric Le Goater 			   void __user *buffer, size_t *lenp, loff_t *ppos)
24409ec52099SCedric Le Goater {
24419ec52099SCedric Le Goater 	struct pid *new_pid;
24429ec52099SCedric Le Goater 	pid_t tmp;
24439ec52099SCedric Le Goater 	int r;
24449ec52099SCedric Le Goater 
24459ec52099SCedric Le Goater 	tmp = pid_nr(cad_pid);
24469ec52099SCedric Le Goater 
24479ec52099SCedric Le Goater 	r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
24489ec52099SCedric Le Goater 			       lenp, ppos, NULL, NULL);
24499ec52099SCedric Le Goater 	if (r || !write)
24509ec52099SCedric Le Goater 		return r;
24519ec52099SCedric Le Goater 
24529ec52099SCedric Le Goater 	new_pid = find_get_pid(tmp);
24539ec52099SCedric Le Goater 	if (!new_pid)
24549ec52099SCedric Le Goater 		return -ESRCH;
24559ec52099SCedric Le Goater 
24569ec52099SCedric Le Goater 	put_pid(xchg(&cad_pid, new_pid));
24579ec52099SCedric Le Goater 	return 0;
24589ec52099SCedric Le Goater }
24599ec52099SCedric Le Goater 
24601da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
24611da177e4SLinus Torvalds 
24621da177e4SLinus Torvalds int proc_dostring(ctl_table *table, int write, struct file *filp,
24631da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
24641da177e4SLinus Torvalds {
24651da177e4SLinus Torvalds 	return -ENOSYS;
24661da177e4SLinus Torvalds }
24671da177e4SLinus Torvalds 
24688218c74cSSerge E. Hallyn static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
24691da177e4SLinus Torvalds 		void __user *buffer, size_t *lenp, loff_t *ppos)
24701da177e4SLinus Torvalds {
24711da177e4SLinus Torvalds 	return -ENOSYS;
24721da177e4SLinus Torvalds }
24731da177e4SLinus Torvalds 
24748218c74cSSerge E. Hallyn #ifdef CONFIG_SYSVIPC
24758218c74cSSerge E. Hallyn static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
24768218c74cSSerge E. Hallyn 		void __user *buffer, size_t *lenp, loff_t *ppos)
24778218c74cSSerge E. Hallyn {
24788218c74cSSerge E. Hallyn 	return -ENOSYS;
24798218c74cSSerge E. Hallyn }
24808218c74cSSerge E. Hallyn #endif
24818218c74cSSerge E. Hallyn 
24821da177e4SLinus Torvalds int proc_dointvec(ctl_table *table, int write, struct file *filp,
24831da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
24841da177e4SLinus Torvalds {
24851da177e4SLinus Torvalds 	return -ENOSYS;
24861da177e4SLinus Torvalds }
24871da177e4SLinus Torvalds 
24881da177e4SLinus Torvalds int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
24891da177e4SLinus Torvalds 			void __user *buffer, size_t *lenp, loff_t *ppos)
24901da177e4SLinus Torvalds {
24911da177e4SLinus Torvalds 	return -ENOSYS;
24921da177e4SLinus Torvalds }
24931da177e4SLinus Torvalds 
24941da177e4SLinus Torvalds int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
24951da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
24961da177e4SLinus Torvalds {
24971da177e4SLinus Torvalds 	return -ENOSYS;
24981da177e4SLinus Torvalds }
24991da177e4SLinus Torvalds 
25001da177e4SLinus Torvalds int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
25011da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
25021da177e4SLinus Torvalds {
25031da177e4SLinus Torvalds 	return -ENOSYS;
25041da177e4SLinus Torvalds }
25051da177e4SLinus Torvalds 
25061da177e4SLinus Torvalds int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
25071da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
25081da177e4SLinus Torvalds {
25091da177e4SLinus Torvalds 	return -ENOSYS;
25101da177e4SLinus Torvalds }
25111da177e4SLinus Torvalds 
25121da177e4SLinus Torvalds int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
25131da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
25141da177e4SLinus Torvalds {
25151da177e4SLinus Torvalds 	return -ENOSYS;
25161da177e4SLinus Torvalds }
25171da177e4SLinus Torvalds 
25181da177e4SLinus Torvalds int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
25191da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
25201da177e4SLinus Torvalds {
25211da177e4SLinus Torvalds 	return -ENOSYS;
25221da177e4SLinus Torvalds }
25231da177e4SLinus Torvalds 
25241da177e4SLinus Torvalds int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
25251da177e4SLinus Torvalds 				      struct file *filp,
25261da177e4SLinus Torvalds 				      void __user *buffer,
25271da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
25281da177e4SLinus Torvalds {
25291da177e4SLinus Torvalds     return -ENOSYS;
25301da177e4SLinus Torvalds }
25311da177e4SLinus Torvalds 
25321da177e4SLinus Torvalds 
25331da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
25341da177e4SLinus Torvalds 
25351da177e4SLinus Torvalds 
2536b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
25371da177e4SLinus Torvalds /*
25381da177e4SLinus Torvalds  * General sysctl support routines
25391da177e4SLinus Torvalds  */
25401da177e4SLinus Torvalds 
25411da177e4SLinus Torvalds /* The generic string strategy routine: */
25421da177e4SLinus Torvalds int sysctl_string(ctl_table *table, int __user *name, int nlen,
25431da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
25441da177e4SLinus Torvalds 		  void __user *newval, size_t newlen, void **context)
25451da177e4SLinus Torvalds {
25461da177e4SLinus Torvalds 	if (!table->data || !table->maxlen)
25471da177e4SLinus Torvalds 		return -ENOTDIR;
25481da177e4SLinus Torvalds 
25491da177e4SLinus Torvalds 	if (oldval && oldlenp) {
2550de9e007dSLinus Torvalds 		size_t bufsize;
2551de9e007dSLinus Torvalds 		if (get_user(bufsize, oldlenp))
25521da177e4SLinus Torvalds 			return -EFAULT;
2553de9e007dSLinus Torvalds 		if (bufsize) {
2554de9e007dSLinus Torvalds 			size_t len = strlen(table->data), copied;
2555de9e007dSLinus Torvalds 
2556de9e007dSLinus Torvalds 			/* This shouldn't trigger for a well-formed sysctl */
2557de9e007dSLinus Torvalds 			if (len > table->maxlen)
25581da177e4SLinus Torvalds 				len = table->maxlen;
2559de9e007dSLinus Torvalds 
2560de9e007dSLinus Torvalds 			/* Copy up to a max of bufsize-1 bytes of the string */
2561de9e007dSLinus Torvalds 			copied = (len >= bufsize) ? bufsize - 1 : len;
2562de9e007dSLinus Torvalds 
2563de9e007dSLinus Torvalds 			if (copy_to_user(oldval, table->data, copied) ||
2564de9e007dSLinus Torvalds 			    put_user(0, (char __user *)(oldval + copied)))
25651da177e4SLinus Torvalds 				return -EFAULT;
25661da177e4SLinus Torvalds 			if (put_user(len, oldlenp))
25671da177e4SLinus Torvalds 				return -EFAULT;
25681da177e4SLinus Torvalds 		}
25691da177e4SLinus Torvalds 	}
25701da177e4SLinus Torvalds 	if (newval && newlen) {
2571de9e007dSLinus Torvalds 		size_t len = newlen;
25721da177e4SLinus Torvalds 		if (len > table->maxlen)
25731da177e4SLinus Torvalds 			len = table->maxlen;
25741da177e4SLinus Torvalds 		if(copy_from_user(table->data, newval, len))
25751da177e4SLinus Torvalds 			return -EFAULT;
25761da177e4SLinus Torvalds 		if (len == table->maxlen)
25771da177e4SLinus Torvalds 			len--;
25781da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
25791da177e4SLinus Torvalds 	}
258082c9df82SYi Yang 	return 1;
25811da177e4SLinus Torvalds }
25821da177e4SLinus Torvalds 
25831da177e4SLinus Torvalds /*
25841da177e4SLinus Torvalds  * This function makes sure that all of the integers in the vector
25851da177e4SLinus Torvalds  * are between the minimum and maximum values given in the arrays
25861da177e4SLinus Torvalds  * table->extra1 and table->extra2, respectively.
25871da177e4SLinus Torvalds  */
25881da177e4SLinus Torvalds int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
25891da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
25901da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
25911da177e4SLinus Torvalds {
25921da177e4SLinus Torvalds 
25931da177e4SLinus Torvalds 	if (newval && newlen) {
25941da177e4SLinus Torvalds 		int __user *vec = (int __user *) newval;
25951da177e4SLinus Torvalds 		int *min = (int *) table->extra1;
25961da177e4SLinus Torvalds 		int *max = (int *) table->extra2;
25971da177e4SLinus Torvalds 		size_t length;
25981da177e4SLinus Torvalds 		int i;
25991da177e4SLinus Torvalds 
26001da177e4SLinus Torvalds 		if (newlen % sizeof(int) != 0)
26011da177e4SLinus Torvalds 			return -EINVAL;
26021da177e4SLinus Torvalds 
26031da177e4SLinus Torvalds 		if (!table->extra1 && !table->extra2)
26041da177e4SLinus Torvalds 			return 0;
26051da177e4SLinus Torvalds 
26061da177e4SLinus Torvalds 		if (newlen > table->maxlen)
26071da177e4SLinus Torvalds 			newlen = table->maxlen;
26081da177e4SLinus Torvalds 		length = newlen / sizeof(int);
26091da177e4SLinus Torvalds 
26101da177e4SLinus Torvalds 		for (i = 0; i < length; i++) {
26111da177e4SLinus Torvalds 			int value;
26121da177e4SLinus Torvalds 			if (get_user(value, vec + i))
26131da177e4SLinus Torvalds 				return -EFAULT;
26141da177e4SLinus Torvalds 			if (min && value < min[i])
26151da177e4SLinus Torvalds 				return -EINVAL;
26161da177e4SLinus Torvalds 			if (max && value > max[i])
26171da177e4SLinus Torvalds 				return -EINVAL;
26181da177e4SLinus Torvalds 		}
26191da177e4SLinus Torvalds 	}
26201da177e4SLinus Torvalds 	return 0;
26211da177e4SLinus Torvalds }
26221da177e4SLinus Torvalds 
26231da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
26241da177e4SLinus Torvalds int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
26251da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
26261da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
26271da177e4SLinus Torvalds {
26281da177e4SLinus Torvalds 	if (oldval) {
26291da177e4SLinus Torvalds 		size_t olen;
26301da177e4SLinus Torvalds 		if (oldlenp) {
26311da177e4SLinus Torvalds 			if (get_user(olen, oldlenp))
26321da177e4SLinus Torvalds 				return -EFAULT;
26331da177e4SLinus Torvalds 			if (olen!=sizeof(int))
26341da177e4SLinus Torvalds 				return -EINVAL;
26351da177e4SLinus Torvalds 		}
26361da177e4SLinus Torvalds 		if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
26371da177e4SLinus Torvalds 		    (oldlenp && put_user(sizeof(int),oldlenp)))
26381da177e4SLinus Torvalds 			return -EFAULT;
26391da177e4SLinus Torvalds 	}
26401da177e4SLinus Torvalds 	if (newval && newlen) {
26411da177e4SLinus Torvalds 		int new;
26421da177e4SLinus Torvalds 		if (newlen != sizeof(int))
26431da177e4SLinus Torvalds 			return -EINVAL;
26441da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
26451da177e4SLinus Torvalds 			return -EFAULT;
26461da177e4SLinus Torvalds 		*(int *)(table->data) = new*HZ;
26471da177e4SLinus Torvalds 	}
26481da177e4SLinus Torvalds 	return 1;
26491da177e4SLinus Torvalds }
26501da177e4SLinus Torvalds 
26511da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
26521da177e4SLinus Torvalds int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
26531da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
26541da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
26551da177e4SLinus Torvalds {
26561da177e4SLinus Torvalds 	if (oldval) {
26571da177e4SLinus Torvalds 		size_t olen;
26581da177e4SLinus Torvalds 		if (oldlenp) {
26591da177e4SLinus Torvalds 			if (get_user(olen, oldlenp))
26601da177e4SLinus Torvalds 				return -EFAULT;
26611da177e4SLinus Torvalds 			if (olen!=sizeof(int))
26621da177e4SLinus Torvalds 				return -EINVAL;
26631da177e4SLinus Torvalds 		}
26641da177e4SLinus Torvalds 		if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
26651da177e4SLinus Torvalds 		    (oldlenp && put_user(sizeof(int),oldlenp)))
26661da177e4SLinus Torvalds 			return -EFAULT;
26671da177e4SLinus Torvalds 	}
26681da177e4SLinus Torvalds 	if (newval && newlen) {
26691da177e4SLinus Torvalds 		int new;
26701da177e4SLinus Torvalds 		if (newlen != sizeof(int))
26711da177e4SLinus Torvalds 			return -EINVAL;
26721da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
26731da177e4SLinus Torvalds 			return -EFAULT;
26741da177e4SLinus Torvalds 		*(int *)(table->data) = msecs_to_jiffies(new);
26751da177e4SLinus Torvalds 	}
26761da177e4SLinus Torvalds 	return 1;
26771da177e4SLinus Torvalds }
26781da177e4SLinus Torvalds 
2679b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */
26801da177e4SLinus Torvalds 
26811da177e4SLinus Torvalds 
26821da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
26831da177e4SLinus Torvalds {
2684b89a8171SEric W. Biederman 	static int msg_count;
26850e009be8SEric W. Biederman 	struct __sysctl_args tmp;
26860e009be8SEric W. Biederman 	int name[CTL_MAXNAME];
26870e009be8SEric W. Biederman 	int i;
26880e009be8SEric W. Biederman 
26890e009be8SEric W. Biederman 	/* Read in the sysctl name for better debug message logging */
26900e009be8SEric W. Biederman 	if (copy_from_user(&tmp, args, sizeof(tmp)))
26910e009be8SEric W. Biederman 		return -EFAULT;
26920e009be8SEric W. Biederman 	if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
26930e009be8SEric W. Biederman 		return -ENOTDIR;
26940e009be8SEric W. Biederman 	for (i = 0; i < tmp.nlen; i++)
26950e009be8SEric W. Biederman 		if (get_user(name[i], tmp.name + i))
26960e009be8SEric W. Biederman 			return -EFAULT;
26970e009be8SEric W. Biederman 
26980e009be8SEric W. Biederman 	/* Ignore accesses to kernel.version */
26990e009be8SEric W. Biederman 	if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
27000e009be8SEric W. Biederman 		goto out;
2701b89a8171SEric W. Biederman 
2702b89a8171SEric W. Biederman 	if (msg_count < 5) {
2703b89a8171SEric W. Biederman 		msg_count++;
2704b89a8171SEric W. Biederman 		printk(KERN_INFO
2705b89a8171SEric W. Biederman 			"warning: process `%s' used the removed sysctl "
27060e009be8SEric W. Biederman 			"system call with ", current->comm);
27070e009be8SEric W. Biederman 		for (i = 0; i < tmp.nlen; i++)
27080e009be8SEric W. Biederman 			printk("%d.", name[i]);
27090e009be8SEric W. Biederman 		printk("\n");
2710b89a8171SEric W. Biederman 	}
27110e009be8SEric W. Biederman out:
27121da177e4SLinus Torvalds 	return -ENOSYS;
27131da177e4SLinus Torvalds }
27141da177e4SLinus Torvalds 
27151da177e4SLinus Torvalds int sysctl_string(ctl_table *table, int __user *name, int nlen,
27161da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
27171da177e4SLinus Torvalds 		  void __user *newval, size_t newlen, void **context)
27181da177e4SLinus Torvalds {
27191da177e4SLinus Torvalds 	return -ENOSYS;
27201da177e4SLinus Torvalds }
27211da177e4SLinus Torvalds 
27221da177e4SLinus Torvalds int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
27231da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
27241da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
27251da177e4SLinus Torvalds {
27261da177e4SLinus Torvalds 	return -ENOSYS;
27271da177e4SLinus Torvalds }
27281da177e4SLinus Torvalds 
27291da177e4SLinus Torvalds int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
27301da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
27311da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
27321da177e4SLinus Torvalds {
27331da177e4SLinus Torvalds 	return -ENOSYS;
27341da177e4SLinus Torvalds }
27351da177e4SLinus Torvalds 
27361da177e4SLinus Torvalds int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
27371da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
27381da177e4SLinus Torvalds 		void __user *newval, size_t newlen, void **context)
27391da177e4SLinus Torvalds {
27401da177e4SLinus Torvalds 	return -ENOSYS;
27411da177e4SLinus Torvalds }
27421da177e4SLinus Torvalds 
2743b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
27441da177e4SLinus Torvalds 
27451da177e4SLinus Torvalds /*
27461da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
27471da177e4SLinus Torvalds  * exception granted :-)
27481da177e4SLinus Torvalds  */
27491da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
27501da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
27511da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
27521da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
27531da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
27541da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
27551da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
27561da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
27571da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
27581da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec);
27591da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies);
27601da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies);
27611da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string);
27621da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
2763