xref: /openbmc/linux/kernel/sysctl.c (revision bfbcf034798b2ca45338cee5049b5694b7ddc865)
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>
2772c2d582SAndrew Morgan #include <linux/security.h>
281da177e4SLinus Torvalds #include <linux/ctype.h>
291da177e4SLinus Torvalds #include <linux/utsname.h>
301da177e4SLinus Torvalds #include <linux/smp_lock.h>
3162239ac2SAdrian Bunk #include <linux/fs.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/initrd.h>
410b77f5bfSDavid Howells #include <linux/key.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>
46c748e134SAdrian Bunk #include <linux/vmstat.h>
47c255d844SPavel Machek #include <linux/nfs_fs.h>
48c255d844SPavel Machek #include <linux/acpi.h>
4910a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h>
50b0fc494fSSteven Rostedt #include <linux/ftrace.h>
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #include <asm/uaccess.h>
531da177e4SLinus Torvalds #include <asm/processor.h>
541da177e4SLinus Torvalds 
5529cbc78bSAndi Kleen #ifdef CONFIG_X86
5629cbc78bSAndi Kleen #include <asm/nmi.h>
570741f4d2SChuck Ebbert #include <asm/stacktrace.h>
586e7c4025SIngo Molnar #include <asm/io.h>
5929cbc78bSAndi Kleen #endif
6029cbc78bSAndi Kleen 
617058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args);
627058cb02SEric W. Biederman 
631da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /* External variables not in a header file. */
661da177e4SLinus Torvalds extern int C_A_D;
6745807a1dSIngo Molnar extern int print_fatal_signals;
681da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
691da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
70fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom;
71fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task;
72fef1bdd6SDavid Rientjes extern int sysctl_oom_dump_tasks;
731da177e4SLinus Torvalds extern int max_threads;
741da177e4SLinus Torvalds extern int core_uses_pid;
75d6e71144SAlan Cox extern int suid_dumpable;
761da177e4SLinus Torvalds extern char core_pattern[];
771da177e4SLinus Torvalds extern int pid_max;
781da177e4SLinus Torvalds extern int min_free_kbytes;
791da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
809d0243bcSAndrew Morton extern int sysctl_drop_caches;
818ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
82bebfa101SAndi Kleen extern int compat_log;
835096add8SKees Cook extern int maps_protect;
849745512cSArjan van de Ven extern int latencytop_enabled;
85eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max;
8631a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
8731a72bceSPaul E. McKenney extern int rcutorture_runnable;
8831a72bceSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
891da177e4SLinus Torvalds 
90c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
911c4cd6ddSIngo Molnar #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
92c4f3b63fSRavikiran G Thirumalai static int one = 1;
93195cf453SBron Gondwana #endif
94195cf453SBron Gondwana 
95195cf453SBron Gondwana #ifdef CONFIG_DETECT_SOFTLOCKUP
96c4f3b63fSRavikiran G Thirumalai static int sixty = 60;
979383d967SDimitri Sivanich static int neg_one = -1;
98c4f3b63fSRavikiran G Thirumalai #endif
99c4f3b63fSRavikiran G Thirumalai 
100c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_MMU
101c4f3b63fSRavikiran G Thirumalai static int two = 2;
102c4f3b63fSRavikiran G Thirumalai #endif
103c4f3b63fSRavikiran G Thirumalai 
104c4f3b63fSRavikiran G Thirumalai static int zero;
105c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100;
106c4f3b63fSRavikiran G Thirumalai 
1071da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
1081da177e4SLinus Torvalds static int maxolduid = 65535;
1091da177e4SLinus Torvalds static int minolduid;
1108ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
1131da177e4SLinus Torvalds 
114a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
1151da177e4SLinus Torvalds extern char modprobe_path[];
1161da177e4SLinus Torvalds #endif
1171da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
1181da177e4SLinus Torvalds extern int sg_big_buff;
1191da177e4SLinus Torvalds #endif
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds #ifdef __sparc__
1221da177e4SLinus Torvalds extern char reboot_command [];
1231da177e4SLinus Torvalds extern int stop_a_enabled;
1241da177e4SLinus Torvalds extern int scons_pwroff;
1251da177e4SLinus Torvalds #endif
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds #ifdef __hppa__
1281da177e4SLinus Torvalds extern int pwrsw_enabled;
1291da177e4SLinus Torvalds extern int unaligned_enabled;
1301da177e4SLinus Torvalds #endif
1311da177e4SLinus Torvalds 
132347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1331da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1341da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1351da177e4SLinus Torvalds #endif
1361da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
137951f22d5SMartin Schwidefsky extern int spin_retry;
1381da177e4SLinus Torvalds #endif
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
1411da177e4SLinus Torvalds extern int acct_parm[];
1421da177e4SLinus Torvalds #endif
1431da177e4SLinus Torvalds 
144d2b176edSJes Sorensen #ifdef CONFIG_IA64
145d2b176edSJes Sorensen extern int no_unaligned_warning;
146d2b176edSJes Sorensen #endif
147d2b176edSJes Sorensen 
14823f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
14923f78d4aSIngo Molnar extern int max_lock_depth;
15023f78d4aSIngo Molnar #endif
15123f78d4aSIngo Molnar 
152d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
153d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
1549ec52099SCedric Le Goater 		  void __user *buffer, size_t *lenp, loff_t *ppos);
155d8217f07SEric W. Biederman static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
15634f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos);
157d6f8ff73SRandy Dunlap #endif
1589ec52099SCedric Le Goater 
159d8217f07SEric W. Biederman static struct ctl_table root_table[];
160e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root;
161e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = {
162e51b6ba0SEric W. Biederman 	.ctl_table = root_table,
16373455092SAl Viro 	.ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
164e51b6ba0SEric W. Biederman 	.root = &sysctl_table_root,
16573455092SAl Viro 	.set = &sysctl_table_root.default_set,
166e51b6ba0SEric W. Biederman };
167e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = {
168e51b6ba0SEric W. Biederman 	.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
16973455092SAl Viro 	.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
170e51b6ba0SEric W. Biederman };
1711da177e4SLinus Torvalds 
172d8217f07SEric W. Biederman static struct ctl_table kern_table[];
173d8217f07SEric W. Biederman static struct ctl_table vm_table[];
174d8217f07SEric W. Biederman static struct ctl_table fs_table[];
175d8217f07SEric W. Biederman static struct ctl_table debug_table[];
176d8217f07SEric W. Biederman static struct ctl_table dev_table[];
177d8217f07SEric W. Biederman extern struct ctl_table random_table[];
1782d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
179d8217f07SEric W. Biederman extern struct ctl_table inotify_table[];
1800399cb08SRobert Love #endif
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1831da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1841da177e4SLinus Torvalds #endif
1851da177e4SLinus Torvalds 
186f20786ffSPeter Zijlstra extern int prove_locking;
187f20786ffSPeter Zijlstra extern int lock_stat;
1889bc9a6bdSEric W. Biederman 
1891da177e4SLinus Torvalds /* The default sysctl tables: */
1901da177e4SLinus Torvalds 
191d8217f07SEric W. Biederman static struct ctl_table root_table[] = {
1921da177e4SLinus Torvalds 	{
1931da177e4SLinus Torvalds 		.ctl_name	= CTL_KERN,
1941da177e4SLinus Torvalds 		.procname	= "kernel",
1951da177e4SLinus Torvalds 		.mode		= 0555,
1961da177e4SLinus Torvalds 		.child		= kern_table,
1971da177e4SLinus Torvalds 	},
1981da177e4SLinus Torvalds 	{
1991da177e4SLinus Torvalds 		.ctl_name	= CTL_VM,
2001da177e4SLinus Torvalds 		.procname	= "vm",
2011da177e4SLinus Torvalds 		.mode		= 0555,
2021da177e4SLinus Torvalds 		.child		= vm_table,
2031da177e4SLinus Torvalds 	},
2041da177e4SLinus Torvalds 	{
2051da177e4SLinus Torvalds 		.ctl_name	= CTL_FS,
2061da177e4SLinus Torvalds 		.procname	= "fs",
2071da177e4SLinus Torvalds 		.mode		= 0555,
2081da177e4SLinus Torvalds 		.child		= fs_table,
2091da177e4SLinus Torvalds 	},
2101da177e4SLinus Torvalds 	{
2111da177e4SLinus Torvalds 		.ctl_name	= CTL_DEBUG,
2121da177e4SLinus Torvalds 		.procname	= "debug",
2131da177e4SLinus Torvalds 		.mode		= 0555,
2141da177e4SLinus Torvalds 		.child		= debug_table,
2151da177e4SLinus Torvalds 	},
2161da177e4SLinus Torvalds 	{
2171da177e4SLinus Torvalds 		.ctl_name	= CTL_DEV,
2181da177e4SLinus Torvalds 		.procname	= "dev",
2191da177e4SLinus Torvalds 		.mode		= 0555,
2201da177e4SLinus Torvalds 		.child		= dev_table,
2211da177e4SLinus Torvalds 	},
2222be7fe07SAndrew Morton /*
2232be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
2242be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
2252be7fe07SAndrew Morton  */
2261da177e4SLinus Torvalds 	{ .ctl_name = 0 }
2271da177e4SLinus Torvalds };
2281da177e4SLinus Torvalds 
22977e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
23073c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000;		/* 100 usecs */
23173c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
23273c4efd2SEric Dumazet static int min_wakeup_granularity_ns;			/* 0 usecs */
23373c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
23477e54a1fSIngo Molnar #endif
23577e54a1fSIngo Molnar 
236d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
23777e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
23877e54a1fSIngo Molnar 	{
23977e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
240b2be5e96SPeter Zijlstra 		.procname	= "sched_min_granularity_ns",
241b2be5e96SPeter Zijlstra 		.data		= &sysctl_sched_min_granularity,
24277e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
24377e54a1fSIngo Molnar 		.mode		= 0644,
244b2be5e96SPeter Zijlstra 		.proc_handler	= &sched_nr_latency_handler,
245b2be5e96SPeter Zijlstra 		.strategy	= &sysctl_intvec,
246b2be5e96SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
247b2be5e96SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
24877e54a1fSIngo Molnar 	},
24977e54a1fSIngo Molnar 	{
25077e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
25121805085SPeter Zijlstra 		.procname	= "sched_latency_ns",
25221805085SPeter Zijlstra 		.data		= &sysctl_sched_latency,
25321805085SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
25421805085SPeter Zijlstra 		.mode		= 0644,
255b2be5e96SPeter Zijlstra 		.proc_handler	= &sched_nr_latency_handler,
25621805085SPeter Zijlstra 		.strategy	= &sysctl_intvec,
25721805085SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
25821805085SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
25921805085SPeter Zijlstra 	},
26021805085SPeter Zijlstra 	{
26121805085SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
26277e54a1fSIngo Molnar 		.procname	= "sched_wakeup_granularity_ns",
26377e54a1fSIngo Molnar 		.data		= &sysctl_sched_wakeup_granularity,
26477e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
26577e54a1fSIngo Molnar 		.mode		= 0644,
26677e54a1fSIngo Molnar 		.proc_handler	= &proc_dointvec_minmax,
26777e54a1fSIngo Molnar 		.strategy	= &sysctl_intvec,
26877e54a1fSIngo Molnar 		.extra1		= &min_wakeup_granularity_ns,
26977e54a1fSIngo Molnar 		.extra2		= &max_wakeup_granularity_ns,
27077e54a1fSIngo Molnar 	},
27177e54a1fSIngo Molnar 	{
27277e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
2732398f2c6SPeter Zijlstra 		.procname	= "sched_shares_ratelimit",
2742398f2c6SPeter Zijlstra 		.data		= &sysctl_sched_shares_ratelimit,
2752398f2c6SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
2762398f2c6SPeter Zijlstra 		.mode		= 0644,
2772398f2c6SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
2782398f2c6SPeter Zijlstra 	},
2792398f2c6SPeter Zijlstra 	{
2802398f2c6SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
28177e54a1fSIngo Molnar 		.procname	= "sched_child_runs_first",
28277e54a1fSIngo Molnar 		.data		= &sysctl_sched_child_runs_first,
28377e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
28477e54a1fSIngo Molnar 		.mode		= 0644,
28577e54a1fSIngo Molnar 		.proc_handler	= &proc_dointvec,
28677e54a1fSIngo Molnar 	},
2871fc84aaaSPeter Zijlstra 	{
2881fc84aaaSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
2891fc84aaaSPeter Zijlstra 		.procname	= "sched_features",
2901fc84aaaSPeter Zijlstra 		.data		= &sysctl_sched_features,
2911fc84aaaSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
2921fc84aaaSPeter Zijlstra 		.mode		= 0644,
2931fc84aaaSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
2941fc84aaaSPeter Zijlstra 	},
295da84d961SIngo Molnar 	{
296da84d961SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
297da84d961SIngo Molnar 		.procname	= "sched_migration_cost",
298da84d961SIngo Molnar 		.data		= &sysctl_sched_migration_cost,
299da84d961SIngo Molnar 		.maxlen		= sizeof(unsigned int),
300da84d961SIngo Molnar 		.mode		= 0644,
301da84d961SIngo Molnar 		.proc_handler	= &proc_dointvec,
302da84d961SIngo Molnar 	},
303b82d9fddSPeter Zijlstra 	{
304b82d9fddSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
305b82d9fddSPeter Zijlstra 		.procname	= "sched_nr_migrate",
306b82d9fddSPeter Zijlstra 		.data		= &sysctl_sched_nr_migrate,
307b82d9fddSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
308fa85ae24SPeter Zijlstra 		.mode		= 0644,
309fa85ae24SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
310fa85ae24SPeter Zijlstra 	},
3111fc84aaaSPeter Zijlstra #endif
3121799e35dSIngo Molnar 	{
3131799e35dSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
3149f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
3159f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
3169f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
3179f0c1e56SPeter Zijlstra 		.mode		= 0644,
318d0b27fa7SPeter Zijlstra 		.proc_handler	= &sched_rt_handler,
3199f0c1e56SPeter Zijlstra 	},
3209f0c1e56SPeter Zijlstra 	{
3219f0c1e56SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3229f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
3239f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
3249f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
3259f0c1e56SPeter Zijlstra 		.mode		= 0644,
326d0b27fa7SPeter Zijlstra 		.proc_handler	= &sched_rt_handler,
3279f0c1e56SPeter Zijlstra 	},
3289f0c1e56SPeter Zijlstra 	{
3299f0c1e56SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3301799e35dSIngo Molnar 		.procname	= "sched_compat_yield",
3311799e35dSIngo Molnar 		.data		= &sysctl_sched_compat_yield,
3321799e35dSIngo Molnar 		.maxlen		= sizeof(unsigned int),
3331799e35dSIngo Molnar 		.mode		= 0644,
3341799e35dSIngo Molnar 		.proc_handler	= &proc_dointvec,
3351799e35dSIngo Molnar 	},
336f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
337f20786ffSPeter Zijlstra 	{
338f20786ffSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
339f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
340f20786ffSPeter Zijlstra 		.data		= &prove_locking,
341f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
342f20786ffSPeter Zijlstra 		.mode		= 0644,
343f20786ffSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
344f20786ffSPeter Zijlstra 	},
345f20786ffSPeter Zijlstra #endif
346f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
347f20786ffSPeter Zijlstra 	{
348f20786ffSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
349f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
350f20786ffSPeter Zijlstra 		.data		= &lock_stat,
351f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
352f20786ffSPeter Zijlstra 		.mode		= 0644,
353f20786ffSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
354f20786ffSPeter Zijlstra 	},
355f20786ffSPeter Zijlstra #endif
35677e54a1fSIngo Molnar 	{
3571da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC,
3581da177e4SLinus Torvalds 		.procname	= "panic",
3591da177e4SLinus Torvalds 		.data		= &panic_timeout,
3601da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3611da177e4SLinus Torvalds 		.mode		= 0644,
3621da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3631da177e4SLinus Torvalds 	},
3641da177e4SLinus Torvalds 	{
3651da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_USES_PID,
3661da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
3671da177e4SLinus Torvalds 		.data		= &core_uses_pid,
3681da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3691da177e4SLinus Torvalds 		.mode		= 0644,
3701da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3711da177e4SLinus Torvalds 	},
3721da177e4SLinus Torvalds 	{
3731da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_PATTERN,
3741da177e4SLinus Torvalds 		.procname	= "core_pattern",
3751da177e4SLinus Torvalds 		.data		= core_pattern,
37671ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
3771da177e4SLinus Torvalds 		.mode		= 0644,
3781da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3791da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3801da177e4SLinus Torvalds 	},
38134f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
3821da177e4SLinus Torvalds 	{
3831da177e4SLinus Torvalds 		.procname	= "tainted",
3841da177e4SLinus Torvalds 		.data		= &tainted,
3851da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
38634f5a398STheodore Ts'o 		.mode		= 0644,
38734f5a398STheodore Ts'o 		.proc_handler	= &proc_dointvec_taint,
3881da177e4SLinus Torvalds 	},
38934f5a398STheodore Ts'o #endif
3909745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
3919745512cSArjan van de Ven 	{
3929745512cSArjan van de Ven 		.procname	= "latencytop",
3939745512cSArjan van de Ven 		.data		= &latencytop_enabled,
3949745512cSArjan van de Ven 		.maxlen		= sizeof(int),
3959745512cSArjan van de Ven 		.mode		= 0644,
3969745512cSArjan van de Ven 		.proc_handler	= &proc_dointvec,
3979745512cSArjan van de Ven 	},
3989745512cSArjan van de Ven #endif
3991da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
4001da177e4SLinus Torvalds 	{
4011da177e4SLinus Torvalds 		.ctl_name	= KERN_REALROOTDEV,
4021da177e4SLinus Torvalds 		.procname	= "real-root-dev",
4031da177e4SLinus Torvalds 		.data		= &real_root_dev,
4041da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4051da177e4SLinus Torvalds 		.mode		= 0644,
4061da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4071da177e4SLinus Torvalds 	},
4081da177e4SLinus Torvalds #endif
40945807a1dSIngo Molnar 	{
41045807a1dSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
41145807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
41245807a1dSIngo Molnar 		.data		= &print_fatal_signals,
41345807a1dSIngo Molnar 		.maxlen		= sizeof(int),
41445807a1dSIngo Molnar 		.mode		= 0644,
41545807a1dSIngo Molnar 		.proc_handler	= &proc_dointvec,
41645807a1dSIngo Molnar 	},
4171da177e4SLinus Torvalds #ifdef __sparc__
4181da177e4SLinus Torvalds 	{
4191da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_REBOOT,
4201da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
4211da177e4SLinus Torvalds 		.data		= reboot_command,
4221da177e4SLinus Torvalds 		.maxlen		= 256,
4231da177e4SLinus Torvalds 		.mode		= 0644,
4241da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4251da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4261da177e4SLinus Torvalds 	},
4271da177e4SLinus Torvalds 	{
4281da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_STOP_A,
4291da177e4SLinus Torvalds 		.procname	= "stop-a",
4301da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
4311da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4321da177e4SLinus Torvalds 		.mode		= 0644,
4331da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4341da177e4SLinus Torvalds 	},
4351da177e4SLinus Torvalds 	{
4361da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
4371da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
4381da177e4SLinus Torvalds 		.data		= &scons_pwroff,
4391da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4401da177e4SLinus Torvalds 		.mode		= 0644,
4411da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4421da177e4SLinus Torvalds 	},
4431da177e4SLinus Torvalds #endif
4441da177e4SLinus Torvalds #ifdef __hppa__
4451da177e4SLinus Torvalds 	{
4461da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_PWRSW,
4471da177e4SLinus Torvalds 		.procname	= "soft-power",
4481da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
4491da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4501da177e4SLinus Torvalds 	 	.mode		= 0644,
4511da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4521da177e4SLinus Torvalds 	},
4531da177e4SLinus Torvalds 	{
4541da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_UNALIGNED,
4551da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
4561da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
4571da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4581da177e4SLinus Torvalds 		.mode		= 0644,
4591da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4601da177e4SLinus Torvalds 	},
4611da177e4SLinus Torvalds #endif
4621da177e4SLinus Torvalds 	{
4631da177e4SLinus Torvalds 		.ctl_name	= KERN_CTLALTDEL,
4641da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
4651da177e4SLinus Torvalds 		.data		= &C_A_D,
4661da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4671da177e4SLinus Torvalds 		.mode		= 0644,
4681da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4691da177e4SLinus Torvalds 	},
470b0fc494fSSteven Rostedt #ifdef CONFIG_FTRACE
471b0fc494fSSteven Rostedt 	{
472b0fc494fSSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
473b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
474b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
475b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
476b0fc494fSSteven Rostedt 		.mode		= 0644,
477b0fc494fSSteven Rostedt 		.proc_handler	= &ftrace_enable_sysctl,
478b0fc494fSSteven Rostedt 	},
479b0fc494fSSteven Rostedt #endif
480a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
4811da177e4SLinus Torvalds 	{
4821da177e4SLinus Torvalds 		.ctl_name	= KERN_MODPROBE,
4831da177e4SLinus Torvalds 		.procname	= "modprobe",
4841da177e4SLinus Torvalds 		.data		= &modprobe_path,
4851da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
4861da177e4SLinus Torvalds 		.mode		= 0644,
4871da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4881da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4891da177e4SLinus Torvalds 	},
4901da177e4SLinus Torvalds #endif
49157ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
4921da177e4SLinus Torvalds 	{
4931da177e4SLinus Torvalds 		.ctl_name	= KERN_HOTPLUG,
4941da177e4SLinus Torvalds 		.procname	= "hotplug",
495312c004dSKay Sievers 		.data		= &uevent_helper,
496312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
4971da177e4SLinus Torvalds 		.mode		= 0644,
4981da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4991da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
5001da177e4SLinus Torvalds 	},
5011da177e4SLinus Torvalds #endif
5021da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
5031da177e4SLinus Torvalds 	{
5041da177e4SLinus Torvalds 		.ctl_name	= KERN_SG_BIG_BUFF,
5051da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
5061da177e4SLinus Torvalds 		.data		= &sg_big_buff,
5071da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5081da177e4SLinus Torvalds 		.mode		= 0444,
5091da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5101da177e4SLinus Torvalds 	},
5111da177e4SLinus Torvalds #endif
5121da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
5131da177e4SLinus Torvalds 	{
5141da177e4SLinus Torvalds 		.ctl_name	= KERN_ACCT,
5151da177e4SLinus Torvalds 		.procname	= "acct",
5161da177e4SLinus Torvalds 		.data		= &acct_parm,
5171da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
5181da177e4SLinus Torvalds 		.mode		= 0644,
5191da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5201da177e4SLinus Torvalds 	},
5211da177e4SLinus Torvalds #endif
5221da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
5231da177e4SLinus Torvalds 	{
5241da177e4SLinus Torvalds 		.ctl_name	= KERN_SYSRQ,
5251da177e4SLinus Torvalds 		.procname	= "sysrq",
5265d6f647fSIngo Molnar 		.data		= &__sysrq_enabled,
5271da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5281da177e4SLinus Torvalds 		.mode		= 0644,
5291da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5301da177e4SLinus Torvalds 	},
5311da177e4SLinus Torvalds #endif
532d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
5331da177e4SLinus Torvalds 	{
5341da177e4SLinus Torvalds 		.procname	= "cad_pid",
5359ec52099SCedric Le Goater 		.data		= NULL,
5361da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5371da177e4SLinus Torvalds 		.mode		= 0600,
5389ec52099SCedric Le Goater 		.proc_handler	= &proc_do_cad_pid,
5391da177e4SLinus Torvalds 	},
540d6f8ff73SRandy Dunlap #endif
5411da177e4SLinus Torvalds 	{
5421da177e4SLinus Torvalds 		.ctl_name	= KERN_MAX_THREADS,
5431da177e4SLinus Torvalds 		.procname	= "threads-max",
5441da177e4SLinus Torvalds 		.data		= &max_threads,
5451da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5461da177e4SLinus Torvalds 		.mode		= 0644,
5471da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5481da177e4SLinus Torvalds 	},
5491da177e4SLinus Torvalds 	{
5501da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOM,
5511da177e4SLinus Torvalds 		.procname	= "random",
5521da177e4SLinus Torvalds 		.mode		= 0555,
5531da177e4SLinus Torvalds 		.child		= random_table,
5541da177e4SLinus Torvalds 	},
5551da177e4SLinus Torvalds 	{
5561da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWUID,
5571da177e4SLinus Torvalds 		.procname	= "overflowuid",
5581da177e4SLinus Torvalds 		.data		= &overflowuid,
5591da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5601da177e4SLinus Torvalds 		.mode		= 0644,
5611da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5621da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5631da177e4SLinus Torvalds 		.extra1		= &minolduid,
5641da177e4SLinus Torvalds 		.extra2		= &maxolduid,
5651da177e4SLinus Torvalds 	},
5661da177e4SLinus Torvalds 	{
5671da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWGID,
5681da177e4SLinus Torvalds 		.procname	= "overflowgid",
5691da177e4SLinus Torvalds 		.data		= &overflowgid,
5701da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5711da177e4SLinus Torvalds 		.mode		= 0644,
5721da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
5731da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
5741da177e4SLinus Torvalds 		.extra1		= &minolduid,
5751da177e4SLinus Torvalds 		.extra2		= &maxolduid,
5761da177e4SLinus Torvalds 	},
577347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
5781da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
5791da177e4SLinus Torvalds 	{
5801da177e4SLinus Torvalds 		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
5811da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
5821da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
5831da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5841da177e4SLinus Torvalds 		.mode		= 0644,
5851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5861da177e4SLinus Torvalds 	},
5871da177e4SLinus Torvalds #endif
5881da177e4SLinus Torvalds 	{
5891da177e4SLinus Torvalds 		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
5901da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
5911da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
5921da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5931da177e4SLinus Torvalds 		.mode		= 0644,
5941da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5951da177e4SLinus Torvalds 	},
5961da177e4SLinus Torvalds #endif
5971da177e4SLinus Torvalds 	{
5981da177e4SLinus Torvalds 		.ctl_name	= KERN_PIDMAX,
5991da177e4SLinus Torvalds 		.procname	= "pid_max",
6001da177e4SLinus Torvalds 		.data		= &pid_max,
6011da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6021da177e4SLinus Torvalds 		.mode		= 0644,
6031da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6041da177e4SLinus Torvalds 		.strategy	= sysctl_intvec,
6051da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
6061da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
6071da177e4SLinus Torvalds 	},
6081da177e4SLinus Torvalds 	{
6091da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC_ON_OOPS,
6101da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
6111da177e4SLinus Torvalds 		.data		= &panic_on_oops,
6121da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6131da177e4SLinus Torvalds 		.mode		= 0644,
6141da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6151da177e4SLinus Torvalds 	},
6167ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
6177ef3d2fdSJoe Perches 	{
6187ef3d2fdSJoe Perches 		.ctl_name	= KERN_PRINTK,
6197ef3d2fdSJoe Perches 		.procname	= "printk",
6207ef3d2fdSJoe Perches 		.data		= &console_loglevel,
6217ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
6227ef3d2fdSJoe Perches 		.mode		= 0644,
6237ef3d2fdSJoe Perches 		.proc_handler	= &proc_dointvec,
6247ef3d2fdSJoe Perches 	},
6251da177e4SLinus Torvalds 	{
6261da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT,
6271da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
628717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
6291da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6301da177e4SLinus Torvalds 		.mode		= 0644,
6311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
6321da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
6331da177e4SLinus Torvalds 	},
6341da177e4SLinus Torvalds 	{
6351da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
6361da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
637717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
6381da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6391da177e4SLinus Torvalds 		.mode		= 0644,
6401da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6411da177e4SLinus Torvalds 	},
6427ef3d2fdSJoe Perches #endif
6431da177e4SLinus Torvalds 	{
6441da177e4SLinus Torvalds 		.ctl_name	= KERN_NGROUPS_MAX,
6451da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6461da177e4SLinus Torvalds 		.data		= &ngroups_max,
6471da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6481da177e4SLinus Torvalds 		.mode		= 0444,
6491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6501da177e4SLinus Torvalds 	},
6511da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6521da177e4SLinus Torvalds 	{
6531da177e4SLinus Torvalds 		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
6541da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
6551da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
6561da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
6571da177e4SLinus Torvalds 		.mode           = 0644,
6582fbe7b25SDon Zickus 		.proc_handler   = &proc_dointvec,
6591da177e4SLinus Torvalds 	},
660407984f1SDon Zickus 	{
661407984f1SDon Zickus 		.procname       = "nmi_watchdog",
662407984f1SDon Zickus 		.data           = &nmi_watchdog_enabled,
663407984f1SDon Zickus 		.maxlen         = sizeof (int),
664407984f1SDon Zickus 		.mode           = 0644,
665407984f1SDon Zickus 		.proc_handler   = &proc_nmi_enabled,
6661da177e4SLinus Torvalds 	},
6671da177e4SLinus Torvalds #endif
6681da177e4SLinus Torvalds #if defined(CONFIG_X86)
6691da177e4SLinus Torvalds 	{
6708da5addaSDon Zickus 		.ctl_name	= KERN_PANIC_ON_NMI,
6718da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
6728da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
6738da5addaSDon Zickus 		.maxlen		= sizeof(int),
6748da5addaSDon Zickus 		.mode		= 0644,
6758da5addaSDon Zickus 		.proc_handler	= &proc_dointvec,
6768da5addaSDon Zickus 	},
6778da5addaSDon Zickus 	{
6781da177e4SLinus Torvalds 		.ctl_name	= KERN_BOOTLOADER_TYPE,
6791da177e4SLinus Torvalds 		.procname	= "bootloader_type",
6801da177e4SLinus Torvalds 		.data		= &bootloader_type,
6811da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6821da177e4SLinus Torvalds 		.mode		= 0444,
6831da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6841da177e4SLinus Torvalds 	},
6850741f4d2SChuck Ebbert 	{
6860741f4d2SChuck Ebbert 		.ctl_name	= CTL_UNNUMBERED,
6870741f4d2SChuck Ebbert 		.procname	= "kstack_depth_to_print",
6880741f4d2SChuck Ebbert 		.data		= &kstack_depth_to_print,
6890741f4d2SChuck Ebbert 		.maxlen		= sizeof(int),
6900741f4d2SChuck Ebbert 		.mode		= 0644,
6910741f4d2SChuck Ebbert 		.proc_handler	= &proc_dointvec,
6920741f4d2SChuck Ebbert 	},
6936e7c4025SIngo Molnar 	{
6946e7c4025SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
6956e7c4025SIngo Molnar 		.procname	= "io_delay_type",
6966e7c4025SIngo Molnar 		.data		= &io_delay_type,
6976e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
6986e7c4025SIngo Molnar 		.mode		= 0644,
6996e7c4025SIngo Molnar 		.proc_handler	= &proc_dointvec,
7006e7c4025SIngo Molnar 	},
7011da177e4SLinus Torvalds #endif
7027a9166e3SLuke Yang #if defined(CONFIG_MMU)
7031da177e4SLinus Torvalds 	{
7041da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOMIZE,
7051da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
7061da177e4SLinus Torvalds 		.data		= &randomize_va_space,
7071da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
7081da177e4SLinus Torvalds 		.mode		= 0644,
7091da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7101da177e4SLinus Torvalds 	},
7117a9166e3SLuke Yang #endif
7120152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
713951f22d5SMartin Schwidefsky 	{
714951f22d5SMartin Schwidefsky 		.ctl_name	= KERN_SPIN_RETRY,
715951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
716951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
717951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
718951f22d5SMartin Schwidefsky 		.mode		= 0644,
719951f22d5SMartin Schwidefsky 		.proc_handler	= &proc_dointvec,
720951f22d5SMartin Schwidefsky 	},
721951f22d5SMartin Schwidefsky #endif
722673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
723c255d844SPavel Machek 	{
724c255d844SPavel Machek 		.procname	= "acpi_video_flags",
72577afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
726c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
727c255d844SPavel Machek 		.mode		= 0644,
7287f99f06fSStefan Seyfried 		.proc_handler	= &proc_doulongvec_minmax,
729c255d844SPavel Machek 	},
730c255d844SPavel Machek #endif
731d2b176edSJes Sorensen #ifdef CONFIG_IA64
732d2b176edSJes Sorensen 	{
733d2b176edSJes Sorensen 		.ctl_name	= KERN_IA64_UNALIGNED,
734d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
735d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
736d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
737d2b176edSJes Sorensen 	 	.mode		= 0644,
738d2b176edSJes Sorensen 		.proc_handler	= &proc_dointvec,
739d2b176edSJes Sorensen 	},
740d2b176edSJes Sorensen #endif
741c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP
742c4f3b63fSRavikiran G Thirumalai 	{
743c4f3b63fSRavikiran G Thirumalai 		.ctl_name	= CTL_UNNUMBERED,
7449c44bc03SIngo Molnar 		.procname	= "softlockup_panic",
7459c44bc03SIngo Molnar 		.data		= &softlockup_panic,
7469c44bc03SIngo Molnar 		.maxlen		= sizeof(int),
7479c44bc03SIngo Molnar 		.mode		= 0644,
7484dca10a9SHiroshi Shimamoto 		.proc_handler	= &proc_dointvec_minmax,
7499c44bc03SIngo Molnar 		.strategy	= &sysctl_intvec,
7509c44bc03SIngo Molnar 		.extra1		= &zero,
7519c44bc03SIngo Molnar 		.extra2		= &one,
7529c44bc03SIngo Molnar 	},
7539c44bc03SIngo Molnar 	{
7549c44bc03SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
755c4f3b63fSRavikiran G Thirumalai 		.procname	= "softlockup_thresh",
756c4f3b63fSRavikiran G Thirumalai 		.data		= &softlockup_thresh,
7579383d967SDimitri Sivanich 		.maxlen		= sizeof(int),
758c4f3b63fSRavikiran G Thirumalai 		.mode		= 0644,
7599383d967SDimitri Sivanich 		.proc_handler	= &proc_dointvec_minmax,
760c4f3b63fSRavikiran G Thirumalai 		.strategy	= &sysctl_intvec,
7619383d967SDimitri Sivanich 		.extra1		= &neg_one,
762c4f3b63fSRavikiran G Thirumalai 		.extra2		= &sixty,
763c4f3b63fSRavikiran G Thirumalai 	},
76482a1fcb9SIngo Molnar 	{
76582a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
76682a1fcb9SIngo Molnar 		.procname	= "hung_task_check_count",
76782a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_check_count,
76890739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
76982a1fcb9SIngo Molnar 		.mode		= 0644,
77090739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
77182a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
77282a1fcb9SIngo Molnar 	},
77382a1fcb9SIngo Molnar 	{
77482a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
77582a1fcb9SIngo Molnar 		.procname	= "hung_task_timeout_secs",
77682a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_timeout_secs,
77790739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
77882a1fcb9SIngo Molnar 		.mode		= 0644,
77990739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
78082a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
78182a1fcb9SIngo Molnar 	},
78282a1fcb9SIngo Molnar 	{
78382a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
78482a1fcb9SIngo Molnar 		.procname	= "hung_task_warnings",
78582a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_warnings,
78690739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
78782a1fcb9SIngo Molnar 		.mode		= 0644,
78890739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
78982a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
79082a1fcb9SIngo Molnar 	},
791c4f3b63fSRavikiran G Thirumalai #endif
792bebfa101SAndi Kleen #ifdef CONFIG_COMPAT
793bebfa101SAndi Kleen 	{
794bebfa101SAndi Kleen 		.ctl_name	= KERN_COMPAT_LOG,
795bebfa101SAndi Kleen 		.procname	= "compat-log",
796bebfa101SAndi Kleen 		.data		= &compat_log,
797bebfa101SAndi Kleen 		.maxlen		= sizeof (int),
798bebfa101SAndi Kleen 	 	.mode		= 0644,
799bebfa101SAndi Kleen 		.proc_handler	= &proc_dointvec,
800bebfa101SAndi Kleen 	},
801bebfa101SAndi Kleen #endif
80223f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
80323f78d4aSIngo Molnar 	{
80423f78d4aSIngo Molnar 		.ctl_name	= KERN_MAX_LOCK_DEPTH,
80523f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
80623f78d4aSIngo Molnar 		.data		= &max_lock_depth,
80723f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
80823f78d4aSIngo Molnar 		.mode		= 0644,
80923f78d4aSIngo Molnar 		.proc_handler	= &proc_dointvec,
81023f78d4aSIngo Molnar 	},
81123f78d4aSIngo Molnar #endif
8125096add8SKees Cook #ifdef CONFIG_PROC_FS
8135096add8SKees Cook 	{
8145096add8SKees Cook 		.ctl_name       = CTL_UNNUMBERED,
8155096add8SKees Cook 		.procname       = "maps_protect",
8165096add8SKees Cook 		.data           = &maps_protect,
8175096add8SKees Cook 		.maxlen         = sizeof(int),
8185096add8SKees Cook 		.mode           = 0644,
8195096add8SKees Cook 		.proc_handler   = &proc_dointvec,
8205096add8SKees Cook 	},
8215096add8SKees Cook #endif
82210a0a8d4SJeremy Fitzhardinge 	{
82310a0a8d4SJeremy Fitzhardinge 		.ctl_name	= CTL_UNNUMBERED,
82410a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
82510a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
82610a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
82710a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
82810a0a8d4SJeremy Fitzhardinge 		.proc_handler	= &proc_dostring,
82910a0a8d4SJeremy Fitzhardinge 		.strategy	= &sysctl_string,
83010a0a8d4SJeremy Fitzhardinge 	},
8310b77f5bfSDavid Howells #ifdef CONFIG_KEYS
8320b77f5bfSDavid Howells 	{
8330b77f5bfSDavid Howells 		.ctl_name	= CTL_UNNUMBERED,
8340b77f5bfSDavid Howells 		.procname	= "keys",
8350b77f5bfSDavid Howells 		.mode		= 0555,
8360b77f5bfSDavid Howells 		.child		= key_sysctls,
8370b77f5bfSDavid Howells 	},
8380b77f5bfSDavid Howells #endif
83931a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
84031a72bceSPaul E. McKenney 	{
84131a72bceSPaul E. McKenney 		.ctl_name       = CTL_UNNUMBERED,
84231a72bceSPaul E. McKenney 		.procname       = "rcutorture_runnable",
84331a72bceSPaul E. McKenney 		.data           = &rcutorture_runnable,
84431a72bceSPaul E. McKenney 		.maxlen         = sizeof(int),
84531a72bceSPaul E. McKenney 		.mode           = 0644,
84631a72bceSPaul E. McKenney 		.proc_handler   = &proc_dointvec,
84731a72bceSPaul E. McKenney 	},
84831a72bceSPaul E. McKenney #endif
849ed2c12f3SAndrew Morton /*
850ed2c12f3SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
851ed2c12f3SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
852ed2c12f3SAndrew Morton  */
8531da177e4SLinus Torvalds 	{ .ctl_name = 0 }
8541da177e4SLinus Torvalds };
8551da177e4SLinus Torvalds 
856d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
8571da177e4SLinus Torvalds 	{
8581da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_MEMORY,
8591da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
8601da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
8611da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
8621da177e4SLinus Torvalds 		.mode		= 0644,
8631da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8641da177e4SLinus Torvalds 	},
8651da177e4SLinus Torvalds 	{
866fadd8fbdSKAMEZAWA Hiroyuki 		.ctl_name	= VM_PANIC_ON_OOM,
867fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
868fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
869fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
870fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
871fadd8fbdSKAMEZAWA Hiroyuki 		.proc_handler	= &proc_dointvec,
872fadd8fbdSKAMEZAWA Hiroyuki 	},
873fadd8fbdSKAMEZAWA Hiroyuki 	{
874fe071d7eSDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
875fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
876fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
877fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
878fe071d7eSDavid Rientjes 		.mode		= 0644,
879fe071d7eSDavid Rientjes 		.proc_handler	= &proc_dointvec,
880fe071d7eSDavid Rientjes 	},
881fe071d7eSDavid Rientjes 	{
882fef1bdd6SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
883fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
884fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
885fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
886fef1bdd6SDavid Rientjes 		.mode		= 0644,
887fef1bdd6SDavid Rientjes 		.proc_handler	= &proc_dointvec,
888fef1bdd6SDavid Rientjes 	},
889fef1bdd6SDavid Rientjes 	{
8901da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_RATIO,
8911da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
8921da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
8931da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
8941da177e4SLinus Torvalds 		.mode		= 0644,
8951da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
8961da177e4SLinus Torvalds 	},
8971da177e4SLinus Torvalds 	{
8981da177e4SLinus Torvalds 		.ctl_name	= VM_PAGE_CLUSTER,
8991da177e4SLinus Torvalds 		.procname	= "page-cluster",
9001da177e4SLinus Torvalds 		.data		= &page_cluster,
9011da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9021da177e4SLinus Torvalds 		.mode		= 0644,
9031da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9041da177e4SLinus Torvalds 	},
9051da177e4SLinus Torvalds 	{
9061da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_BACKGROUND,
9071da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
9081da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
9091da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
9101da177e4SLinus Torvalds 		.mode		= 0644,
9111da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
9121da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9131da177e4SLinus Torvalds 		.extra1		= &zero,
9141da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9151da177e4SLinus Torvalds 	},
9161da177e4SLinus Torvalds 	{
9171da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_RATIO,
9181da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
9191da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
9201da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
9211da177e4SLinus Torvalds 		.mode		= 0644,
92204fbfdc1SPeter Zijlstra 		.proc_handler	= &dirty_ratio_handler,
9231da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9241da177e4SLinus Torvalds 		.extra1		= &zero,
9251da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9261da177e4SLinus Torvalds 	},
9271da177e4SLinus Torvalds 	{
9281da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
929f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
930f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
9311da177e4SLinus Torvalds 		.mode		= 0644,
9321da177e4SLinus Torvalds 		.proc_handler	= &dirty_writeback_centisecs_handler,
9331da177e4SLinus Torvalds 	},
9341da177e4SLinus Torvalds 	{
9351da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
936f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
937f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
9381da177e4SLinus Torvalds 		.mode		= 0644,
939f6ef9438SBart Samwel 		.proc_handler	= &proc_dointvec_userhz_jiffies,
9401da177e4SLinus Torvalds 	},
9411da177e4SLinus Torvalds 	{
9421da177e4SLinus Torvalds 		.ctl_name	= VM_NR_PDFLUSH_THREADS,
9431da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
9441da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
9451da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
9461da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
9471da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9481da177e4SLinus Torvalds 	},
9491da177e4SLinus Torvalds 	{
9501da177e4SLinus Torvalds 		.ctl_name	= VM_SWAPPINESS,
9511da177e4SLinus Torvalds 		.procname	= "swappiness",
9521da177e4SLinus Torvalds 		.data		= &vm_swappiness,
9531da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
9541da177e4SLinus Torvalds 		.mode		= 0644,
9551da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
9561da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9571da177e4SLinus Torvalds 		.extra1		= &zero,
9581da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9591da177e4SLinus Torvalds 	},
9601da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
9611da177e4SLinus Torvalds 	 {
9621da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
963e5ff2159SAndi Kleen 		.data		= NULL,
9641da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
9651da177e4SLinus Torvalds 		.mode		= 0644,
9661da177e4SLinus Torvalds 		.proc_handler	= &hugetlb_sysctl_handler,
9671da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
9681da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
9691da177e4SLinus Torvalds 	 },
9701da177e4SLinus Torvalds 	 {
9711da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_GROUP,
9721da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
9731da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
9741da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
9751da177e4SLinus Torvalds 		.mode		= 0644,
9761da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9771da177e4SLinus Torvalds 	 },
978396faf03SMel Gorman 	 {
979396faf03SMel Gorman 		.ctl_name	= CTL_UNNUMBERED,
980396faf03SMel Gorman 		.procname	= "hugepages_treat_as_movable",
981396faf03SMel Gorman 		.data		= &hugepages_treat_as_movable,
982396faf03SMel Gorman 		.maxlen		= sizeof(int),
983396faf03SMel Gorman 		.mode		= 0644,
984396faf03SMel Gorman 		.proc_handler	= &hugetlb_treat_movable_handler,
985396faf03SMel Gorman 	},
98654f9f80dSAdam Litke 	{
98754f9f80dSAdam Litke 		.ctl_name	= CTL_UNNUMBERED,
988d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
989e5ff2159SAndi Kleen 		.data		= NULL,
990e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
991d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
992a3d0c6aaSNishanth Aravamudan 		.proc_handler	= &hugetlb_overcommit_handler,
993e5ff2159SAndi Kleen 		.extra1		= (void *)&hugetlb_zero,
994e5ff2159SAndi Kleen 		.extra2		= (void *)&hugetlb_infinity,
995d1c3fb1fSNishanth Aravamudan 	},
9961da177e4SLinus Torvalds #endif
9971da177e4SLinus Torvalds 	{
9981da177e4SLinus Torvalds 		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
9991da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
10001da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
10011da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
10021da177e4SLinus Torvalds 		.mode		= 0644,
10031da177e4SLinus Torvalds 		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
10041da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10051da177e4SLinus Torvalds 	},
10061da177e4SLinus Torvalds 	{
10079d0243bcSAndrew Morton 		.ctl_name	= VM_DROP_PAGECACHE,
10089d0243bcSAndrew Morton 		.procname	= "drop_caches",
10099d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
10109d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
10119d0243bcSAndrew Morton 		.mode		= 0644,
10129d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
10139d0243bcSAndrew Morton 		.strategy	= &sysctl_intvec,
10149d0243bcSAndrew Morton 	},
10159d0243bcSAndrew Morton 	{
10161da177e4SLinus Torvalds 		.ctl_name	= VM_MIN_FREE_KBYTES,
10171da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
10181da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
10191da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
10201da177e4SLinus Torvalds 		.mode		= 0644,
10211da177e4SLinus Torvalds 		.proc_handler	= &min_free_kbytes_sysctl_handler,
10221da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10231da177e4SLinus Torvalds 		.extra1		= &zero,
10241da177e4SLinus Torvalds 	},
10258ad4b1fbSRohit Seth 	{
10268ad4b1fbSRohit Seth 		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
10278ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
10288ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
10298ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
10308ad4b1fbSRohit Seth 		.mode		= 0644,
10318ad4b1fbSRohit Seth 		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
10328ad4b1fbSRohit Seth 		.strategy	= &sysctl_intvec,
10338ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
10348ad4b1fbSRohit Seth 	},
10351da177e4SLinus Torvalds #ifdef CONFIG_MMU
10361da177e4SLinus Torvalds 	{
10371da177e4SLinus Torvalds 		.ctl_name	= VM_MAX_MAP_COUNT,
10381da177e4SLinus Torvalds 		.procname	= "max_map_count",
10391da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
10401da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
10411da177e4SLinus Torvalds 		.mode		= 0644,
10421da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec
10431da177e4SLinus Torvalds 	},
10441da177e4SLinus Torvalds #endif
10451da177e4SLinus Torvalds 	{
10461da177e4SLinus Torvalds 		.ctl_name	= VM_LAPTOP_MODE,
10471da177e4SLinus Torvalds 		.procname	= "laptop_mode",
10481da177e4SLinus Torvalds 		.data		= &laptop_mode,
10491da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
10501da177e4SLinus Torvalds 		.mode		= 0644,
1051ed5b43f1SBart Samwel 		.proc_handler	= &proc_dointvec_jiffies,
1052ed5b43f1SBart Samwel 		.strategy	= &sysctl_jiffies,
10531da177e4SLinus Torvalds 	},
10541da177e4SLinus Torvalds 	{
10551da177e4SLinus Torvalds 		.ctl_name	= VM_BLOCK_DUMP,
10561da177e4SLinus Torvalds 		.procname	= "block_dump",
10571da177e4SLinus Torvalds 		.data		= &block_dump,
10581da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
10591da177e4SLinus Torvalds 		.mode		= 0644,
10601da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10611da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10621da177e4SLinus Torvalds 		.extra1		= &zero,
10631da177e4SLinus Torvalds 	},
10641da177e4SLinus Torvalds 	{
10651da177e4SLinus Torvalds 		.ctl_name	= VM_VFS_CACHE_PRESSURE,
10661da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
10671da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
10681da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
10691da177e4SLinus Torvalds 		.mode		= 0644,
10701da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10711da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10721da177e4SLinus Torvalds 		.extra1		= &zero,
10731da177e4SLinus Torvalds 	},
10741da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
10751da177e4SLinus Torvalds 	{
10761da177e4SLinus Torvalds 		.ctl_name	= VM_LEGACY_VA_LAYOUT,
10771da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
10781da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
10791da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
10801da177e4SLinus Torvalds 		.mode		= 0644,
10811da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10821da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10831da177e4SLinus Torvalds 		.extra1		= &zero,
10841da177e4SLinus Torvalds 	},
10851da177e4SLinus Torvalds #endif
10861743660bSChristoph Lameter #ifdef CONFIG_NUMA
10871743660bSChristoph Lameter 	{
10881743660bSChristoph Lameter 		.ctl_name	= VM_ZONE_RECLAIM_MODE,
10891743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
10901743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
10911743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
10921743660bSChristoph Lameter 		.mode		= 0644,
10931743660bSChristoph Lameter 		.proc_handler	= &proc_dointvec,
1094c84db23cSChristoph Lameter 		.strategy	= &sysctl_intvec,
1095c84db23cSChristoph Lameter 		.extra1		= &zero,
10961743660bSChristoph Lameter 	},
10979614634fSChristoph Lameter 	{
10989614634fSChristoph Lameter 		.ctl_name	= VM_MIN_UNMAPPED,
10999614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
11009614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
11019614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
11029614634fSChristoph Lameter 		.mode		= 0644,
11039614634fSChristoph Lameter 		.proc_handler	= &sysctl_min_unmapped_ratio_sysctl_handler,
11049614634fSChristoph Lameter 		.strategy	= &sysctl_intvec,
11059614634fSChristoph Lameter 		.extra1		= &zero,
11069614634fSChristoph Lameter 		.extra2		= &one_hundred,
11079614634fSChristoph Lameter 	},
11080ff38490SChristoph Lameter 	{
11090ff38490SChristoph Lameter 		.ctl_name	= VM_MIN_SLAB,
11100ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
11110ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
11120ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
11130ff38490SChristoph Lameter 		.mode		= 0644,
11140ff38490SChristoph Lameter 		.proc_handler	= &sysctl_min_slab_ratio_sysctl_handler,
11150ff38490SChristoph Lameter 		.strategy	= &sysctl_intvec,
11160ff38490SChristoph Lameter 		.extra1		= &zero,
11170ff38490SChristoph Lameter 		.extra2		= &one_hundred,
11180ff38490SChristoph Lameter 	},
11191743660bSChristoph Lameter #endif
112077461ab3SChristoph Lameter #ifdef CONFIG_SMP
112177461ab3SChristoph Lameter 	{
112277461ab3SChristoph Lameter 		.ctl_name	= CTL_UNNUMBERED,
112377461ab3SChristoph Lameter 		.procname	= "stat_interval",
112477461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
112577461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
112677461ab3SChristoph Lameter 		.mode		= 0644,
112777461ab3SChristoph Lameter 		.proc_handler	= &proc_dointvec_jiffies,
112877461ab3SChristoph Lameter 		.strategy	= &sysctl_jiffies,
112977461ab3SChristoph Lameter 	},
113077461ab3SChristoph Lameter #endif
1131ed032189SEric Paris #ifdef CONFIG_SECURITY
1132ed032189SEric Paris 	{
1133ed032189SEric Paris 		.ctl_name	= CTL_UNNUMBERED,
1134ed032189SEric Paris 		.procname	= "mmap_min_addr",
1135ed032189SEric Paris 		.data		= &mmap_min_addr,
1136ed032189SEric Paris 		.maxlen         = sizeof(unsigned long),
1137ed032189SEric Paris 		.mode		= 0644,
1138ed032189SEric Paris 		.proc_handler	= &proc_doulongvec_minmax,
1139ed032189SEric Paris 	},
11408daec965SLee Schermerhorn #endif
1141f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
1142f0c0b2b8SKAMEZAWA Hiroyuki 	{
1143f0c0b2b8SKAMEZAWA Hiroyuki 		.ctl_name	= CTL_UNNUMBERED,
1144f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
1145f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
1146f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
1147f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
1148f0c0b2b8SKAMEZAWA Hiroyuki 		.proc_handler	= &numa_zonelist_order_handler,
1149f0c0b2b8SKAMEZAWA Hiroyuki 		.strategy	= &sysctl_string,
1150f0c0b2b8SKAMEZAWA Hiroyuki 	},
1151f0c0b2b8SKAMEZAWA Hiroyuki #endif
11522b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
11535c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1154e6e5494cSIngo Molnar 	{
1155e6e5494cSIngo Molnar 		.ctl_name	= VM_VDSO_ENABLED,
1156e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
1157e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
1158e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
1159e6e5494cSIngo Molnar 		.mode		= 0644,
1160e6e5494cSIngo Molnar 		.proc_handler	= &proc_dointvec,
1161e6e5494cSIngo Molnar 		.strategy	= &sysctl_intvec,
1162e6e5494cSIngo Molnar 		.extra1		= &zero,
1163e6e5494cSIngo Molnar 	},
1164e6e5494cSIngo Molnar #endif
1165195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
1166195cf453SBron Gondwana 	{
1167195cf453SBron Gondwana 		.ctl_name	= CTL_UNNUMBERED,
1168195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
1169195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
1170195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
1171195cf453SBron Gondwana 		.mode		= 0644,
1172195cf453SBron Gondwana 		.proc_handler	= &proc_dointvec_minmax,
1173195cf453SBron Gondwana 		.strategy	= &sysctl_intvec,
1174195cf453SBron Gondwana 		.extra1		= &zero,
1175195cf453SBron Gondwana 		.extra2		= &one,
1176195cf453SBron Gondwana 	},
1177195cf453SBron Gondwana #endif
11782be7fe07SAndrew Morton /*
11792be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
11802be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
11812be7fe07SAndrew Morton  */
11821da177e4SLinus Torvalds 	{ .ctl_name = 0 }
11831da177e4SLinus Torvalds };
11841da177e4SLinus Torvalds 
11852abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1186d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = {
11872abc26fcSEric W. Biederman 	{ .ctl_name = 0 }
11882abc26fcSEric W. Biederman };
11892abc26fcSEric W. Biederman #endif
11902abc26fcSEric W. Biederman 
1191d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
11921da177e4SLinus Torvalds 	{
11931da177e4SLinus Torvalds 		.ctl_name	= FS_NRINODE,
11941da177e4SLinus Torvalds 		.procname	= "inode-nr",
11951da177e4SLinus Torvalds 		.data		= &inodes_stat,
11961da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
11971da177e4SLinus Torvalds 		.mode		= 0444,
11981da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11991da177e4SLinus Torvalds 	},
12001da177e4SLinus Torvalds 	{
12011da177e4SLinus Torvalds 		.ctl_name	= FS_STATINODE,
12021da177e4SLinus Torvalds 		.procname	= "inode-state",
12031da177e4SLinus Torvalds 		.data		= &inodes_stat,
12041da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
12051da177e4SLinus Torvalds 		.mode		= 0444,
12061da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12071da177e4SLinus Torvalds 	},
12081da177e4SLinus Torvalds 	{
12091da177e4SLinus Torvalds 		.procname	= "file-nr",
12101da177e4SLinus Torvalds 		.data		= &files_stat,
12111da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
12121da177e4SLinus Torvalds 		.mode		= 0444,
1213529bf6beSDipankar Sarma 		.proc_handler	= &proc_nr_files,
12141da177e4SLinus Torvalds 	},
12151da177e4SLinus Torvalds 	{
12161da177e4SLinus Torvalds 		.ctl_name	= FS_MAXFILE,
12171da177e4SLinus Torvalds 		.procname	= "file-max",
12181da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
12191da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
12201da177e4SLinus Torvalds 		.mode		= 0644,
12211da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12221da177e4SLinus Torvalds 	},
12231da177e4SLinus Torvalds 	{
12249cfe015aSEric Dumazet 		.ctl_name	= CTL_UNNUMBERED,
12259cfe015aSEric Dumazet 		.procname	= "nr_open",
12269cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
12279cfe015aSEric Dumazet 		.maxlen		= sizeof(int),
12289cfe015aSEric Dumazet 		.mode		= 0644,
1229eceea0b3SAl Viro 		.proc_handler	= &proc_dointvec_minmax,
1230eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
1231eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
12329cfe015aSEric Dumazet 	},
12339cfe015aSEric Dumazet 	{
12341da177e4SLinus Torvalds 		.ctl_name	= FS_DENTRY,
12351da177e4SLinus Torvalds 		.procname	= "dentry-state",
12361da177e4SLinus Torvalds 		.data		= &dentry_stat,
12371da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
12381da177e4SLinus Torvalds 		.mode		= 0444,
12391da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12401da177e4SLinus Torvalds 	},
12411da177e4SLinus Torvalds 	{
12421da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWUID,
12431da177e4SLinus Torvalds 		.procname	= "overflowuid",
12441da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
12451da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
12461da177e4SLinus Torvalds 		.mode		= 0644,
12471da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
12481da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
12491da177e4SLinus Torvalds 		.extra1		= &minolduid,
12501da177e4SLinus Torvalds 		.extra2		= &maxolduid,
12511da177e4SLinus Torvalds 	},
12521da177e4SLinus Torvalds 	{
12531da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWGID,
12541da177e4SLinus Torvalds 		.procname	= "overflowgid",
12551da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
12561da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
12571da177e4SLinus Torvalds 		.mode		= 0644,
12581da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
12591da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
12601da177e4SLinus Torvalds 		.extra1		= &minolduid,
12611da177e4SLinus Torvalds 		.extra2		= &maxolduid,
12621da177e4SLinus Torvalds 	},
12631da177e4SLinus Torvalds 	{
12641da177e4SLinus Torvalds 		.ctl_name	= FS_LEASES,
12651da177e4SLinus Torvalds 		.procname	= "leases-enable",
12661da177e4SLinus Torvalds 		.data		= &leases_enable,
12671da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
12681da177e4SLinus Torvalds 		.mode		= 0644,
12691da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12701da177e4SLinus Torvalds 	},
12711da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
12721da177e4SLinus Torvalds 	{
12731da177e4SLinus Torvalds 		.ctl_name	= FS_DIR_NOTIFY,
12741da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
12751da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
12761da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
12771da177e4SLinus Torvalds 		.mode		= 0644,
12781da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12791da177e4SLinus Torvalds 	},
12801da177e4SLinus Torvalds #endif
12811da177e4SLinus Torvalds #ifdef CONFIG_MMU
12821da177e4SLinus Torvalds 	{
12831da177e4SLinus Torvalds 		.ctl_name	= FS_LEASE_TIME,
12841da177e4SLinus Torvalds 		.procname	= "lease-break-time",
12851da177e4SLinus Torvalds 		.data		= &lease_break_time,
12861da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
12871da177e4SLinus Torvalds 		.mode		= 0644,
128876fdbb25SKawai, Hidehiro 		.proc_handler	= &proc_dointvec_minmax,
128976fdbb25SKawai, Hidehiro 		.strategy	= &sysctl_intvec,
129076fdbb25SKawai, Hidehiro 		.extra1		= &zero,
129176fdbb25SKawai, Hidehiro 		.extra2		= &two,
12921da177e4SLinus Torvalds 	},
12931da177e4SLinus Torvalds 	{
12941da177e4SLinus Torvalds 		.procname	= "aio-nr",
12951da177e4SLinus Torvalds 		.data		= &aio_nr,
12961da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
12971da177e4SLinus Torvalds 		.mode		= 0444,
1298d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
12991da177e4SLinus Torvalds 	},
13001da177e4SLinus Torvalds 	{
13011da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
13021da177e4SLinus Torvalds 		.data		= &aio_max_nr,
13031da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
13041da177e4SLinus Torvalds 		.mode		= 0644,
1305d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
13061da177e4SLinus Torvalds 	},
13072d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
13080399cb08SRobert Love 	{
13090399cb08SRobert Love 		.ctl_name	= FS_INOTIFY,
13100399cb08SRobert Love 		.procname	= "inotify",
13110399cb08SRobert Love 		.mode		= 0555,
13120399cb08SRobert Love 		.child		= inotify_table,
13130399cb08SRobert Love 	},
13140399cb08SRobert Love #endif
13151da177e4SLinus Torvalds #endif
1316d6e71144SAlan Cox 	{
1317d6e71144SAlan Cox 		.ctl_name	= KERN_SETUID_DUMPABLE,
1318d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1319d6e71144SAlan Cox 		.data		= &suid_dumpable,
1320d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1321d6e71144SAlan Cox 		.mode		= 0644,
1322d6e71144SAlan Cox 		.proc_handler	= &proc_dointvec,
1323d6e71144SAlan Cox 	},
13242abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
13252abc26fcSEric W. Biederman 	{
13262abc26fcSEric W. Biederman 		.ctl_name	= CTL_UNNUMBERED,
13272abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
13282abc26fcSEric W. Biederman 		.mode		= 0555,
13292abc26fcSEric W. Biederman 		.child		= binfmt_misc_table,
13302abc26fcSEric W. Biederman 	},
13312abc26fcSEric W. Biederman #endif
13322be7fe07SAndrew Morton /*
13332be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
13342be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
13352be7fe07SAndrew Morton  */
13361da177e4SLinus Torvalds 	{ .ctl_name = 0 }
13371da177e4SLinus Torvalds };
13381da177e4SLinus Torvalds 
1339d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
1340d0c3d534SOlof Johansson #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1341abd4f750SMasoud Asgharifard Sharbiani 	{
1342abd4f750SMasoud Asgharifard Sharbiani 		.ctl_name	= CTL_UNNUMBERED,
1343abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
1344abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
1345abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
1346abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
1347abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
1348abd4f750SMasoud Asgharifard Sharbiani 	},
1349abd4f750SMasoud Asgharifard Sharbiani #endif
13501da177e4SLinus Torvalds 	{ .ctl_name = 0 }
13511da177e4SLinus Torvalds };
13521da177e4SLinus Torvalds 
1353d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
13541da177e4SLinus Torvalds 	{ .ctl_name = 0 }
13551da177e4SLinus Torvalds };
13561da177e4SLinus Torvalds 
1357330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1358330d57fbSAl Viro 
1359330d57fbSAl Viro /* called under sysctl_lock */
1360330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1361330d57fbSAl Viro {
1362330d57fbSAl Viro 	if (unlikely(p->unregistering))
1363330d57fbSAl Viro 		return 0;
1364330d57fbSAl Viro 	p->used++;
1365330d57fbSAl Viro 	return 1;
1366330d57fbSAl Viro }
1367330d57fbSAl Viro 
1368330d57fbSAl Viro /* called under sysctl_lock */
1369330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1370330d57fbSAl Viro {
1371330d57fbSAl Viro 	if (!--p->used)
1372330d57fbSAl Viro 		if (unlikely(p->unregistering))
1373330d57fbSAl Viro 			complete(p->unregistering);
1374330d57fbSAl Viro }
1375330d57fbSAl Viro 
1376330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1377330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1378330d57fbSAl Viro {
1379330d57fbSAl Viro 	/*
1380330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1381330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1382330d57fbSAl Viro 	 */
1383330d57fbSAl Viro 	if (unlikely(p->used)) {
1384330d57fbSAl Viro 		struct completion wait;
1385330d57fbSAl Viro 		init_completion(&wait);
1386330d57fbSAl Viro 		p->unregistering = &wait;
1387330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1388330d57fbSAl Viro 		wait_for_completion(&wait);
1389330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1390f7e6ced4SAl Viro 	} else {
1391f7e6ced4SAl Viro 		/* anything non-NULL; we'll never dereference it */
1392f7e6ced4SAl Viro 		p->unregistering = ERR_PTR(-EINVAL);
1393330d57fbSAl Viro 	}
1394330d57fbSAl Viro 	/*
1395330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1396330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1397330d57fbSAl Viro 	 */
1398330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1399330d57fbSAl Viro }
1400330d57fbSAl Viro 
1401f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head)
1402f7e6ced4SAl Viro {
1403f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1404f7e6ced4SAl Viro 	head->count++;
1405f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1406f7e6ced4SAl Viro }
1407f7e6ced4SAl Viro 
1408f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
1409f7e6ced4SAl Viro {
1410f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1411f7e6ced4SAl Viro 	if (!--head->count)
1412f7e6ced4SAl Viro 		kfree(head);
1413f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1414f7e6ced4SAl Viro }
1415f7e6ced4SAl Viro 
1416f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1417f7e6ced4SAl Viro {
1418f7e6ced4SAl Viro 	if (!head)
1419f7e6ced4SAl Viro 		BUG();
1420f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1421f7e6ced4SAl Viro 	if (!use_table(head))
1422f7e6ced4SAl Viro 		head = ERR_PTR(-ENOENT);
1423f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1424f7e6ced4SAl Viro 	return head;
1425f7e6ced4SAl Viro }
1426f7e6ced4SAl Viro 
1427805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head)
1428805b5d5eSEric W. Biederman {
1429805b5d5eSEric W. Biederman 	if (!head)
1430805b5d5eSEric W. Biederman 		return;
1431805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1432805b5d5eSEric W. Biederman 	unuse_table(head);
1433805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1434805b5d5eSEric W. Biederman }
1435805b5d5eSEric W. Biederman 
143673455092SAl Viro static struct ctl_table_set *
143773455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
143873455092SAl Viro {
143973455092SAl Viro 	struct ctl_table_set *set = &root->default_set;
144073455092SAl Viro 	if (root->lookup)
144173455092SAl Viro 		set = root->lookup(root, namespaces);
144273455092SAl Viro 	return set;
144373455092SAl Viro }
144473455092SAl Viro 
1445e51b6ba0SEric W. Biederman static struct list_head *
1446e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1447805b5d5eSEric W. Biederman {
144873455092SAl Viro 	struct ctl_table_set *set = lookup_header_set(root, namespaces);
144973455092SAl Viro 	return &set->list;
1450e51b6ba0SEric W. Biederman }
1451e51b6ba0SEric W. Biederman 
1452e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1453e51b6ba0SEric W. Biederman 					    struct ctl_table_header *prev)
1454e51b6ba0SEric W. Biederman {
1455e51b6ba0SEric W. Biederman 	struct ctl_table_root *root;
1456e51b6ba0SEric W. Biederman 	struct list_head *header_list;
1457805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1458805b5d5eSEric W. Biederman 	struct list_head *tmp;
1459e51b6ba0SEric W. Biederman 
1460805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1461805b5d5eSEric W. Biederman 	if (prev) {
1462e51b6ba0SEric W. Biederman 		head = prev;
1463805b5d5eSEric W. Biederman 		tmp = &prev->ctl_entry;
1464805b5d5eSEric W. Biederman 		unuse_table(prev);
1465805b5d5eSEric W. Biederman 		goto next;
1466805b5d5eSEric W. Biederman 	}
1467805b5d5eSEric W. Biederman 	tmp = &root_table_header.ctl_entry;
1468805b5d5eSEric W. Biederman 	for (;;) {
1469805b5d5eSEric W. Biederman 		head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1470805b5d5eSEric W. Biederman 
1471805b5d5eSEric W. Biederman 		if (!use_table(head))
1472805b5d5eSEric W. Biederman 			goto next;
1473805b5d5eSEric W. Biederman 		spin_unlock(&sysctl_lock);
1474805b5d5eSEric W. Biederman 		return head;
1475805b5d5eSEric W. Biederman 	next:
1476e51b6ba0SEric W. Biederman 		root = head->root;
1477805b5d5eSEric W. Biederman 		tmp = tmp->next;
1478e51b6ba0SEric W. Biederman 		header_list = lookup_header_list(root, namespaces);
1479e51b6ba0SEric W. Biederman 		if (tmp != header_list)
1480e51b6ba0SEric W. Biederman 			continue;
1481e51b6ba0SEric W. Biederman 
1482e51b6ba0SEric W. Biederman 		do {
1483e51b6ba0SEric W. Biederman 			root = list_entry(root->root_list.next,
1484e51b6ba0SEric W. Biederman 					struct ctl_table_root, root_list);
1485e51b6ba0SEric W. Biederman 			if (root == &sysctl_table_root)
1486e51b6ba0SEric W. Biederman 				goto out;
1487e51b6ba0SEric W. Biederman 			header_list = lookup_header_list(root, namespaces);
1488e51b6ba0SEric W. Biederman 		} while (list_empty(header_list));
1489e51b6ba0SEric W. Biederman 		tmp = header_list->next;
1490805b5d5eSEric W. Biederman 	}
1491e51b6ba0SEric W. Biederman out:
1492805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1493805b5d5eSEric W. Biederman 	return NULL;
1494805b5d5eSEric W. Biederman }
1495805b5d5eSEric W. Biederman 
1496e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1497e51b6ba0SEric W. Biederman {
1498e51b6ba0SEric W. Biederman 	return __sysctl_head_next(current->nsproxy, prev);
1499e51b6ba0SEric W. Biederman }
1500e51b6ba0SEric W. Biederman 
1501e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root)
1502e51b6ba0SEric W. Biederman {
1503e51b6ba0SEric W. Biederman 	spin_lock(&sysctl_lock);
1504e51b6ba0SEric W. Biederman 	list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1505e51b6ba0SEric W. Biederman 	spin_unlock(&sysctl_lock);
1506e51b6ba0SEric W. Biederman }
1507e51b6ba0SEric W. Biederman 
1508b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
15092c4c7155SPavel Emelyanov /* Perform the actual read/write of a sysctl table entry. */
1510d7321cd6SPavel Emelyanov static int do_sysctl_strategy(struct ctl_table_root *root,
1511d7321cd6SPavel Emelyanov 			struct ctl_table *table,
15122c4c7155SPavel Emelyanov 			int __user *name, int nlen,
15132c4c7155SPavel Emelyanov 			void __user *oldval, size_t __user *oldlenp,
15142c4c7155SPavel Emelyanov 			void __user *newval, size_t newlen)
15152c4c7155SPavel Emelyanov {
15162c4c7155SPavel Emelyanov 	int op = 0, rc;
15172c4c7155SPavel Emelyanov 
15182c4c7155SPavel Emelyanov 	if (oldval)
1519e6305c43SAl Viro 		op |= MAY_READ;
15202c4c7155SPavel Emelyanov 	if (newval)
1521e6305c43SAl Viro 		op |= MAY_WRITE;
1522d7321cd6SPavel Emelyanov 	if (sysctl_perm(root, table, op))
15232c4c7155SPavel Emelyanov 		return -EPERM;
15242c4c7155SPavel Emelyanov 
15252c4c7155SPavel Emelyanov 	if (table->strategy) {
15262c4c7155SPavel Emelyanov 		rc = table->strategy(table, name, nlen, oldval, oldlenp,
15272c4c7155SPavel Emelyanov 				     newval, newlen);
15282c4c7155SPavel Emelyanov 		if (rc < 0)
15292c4c7155SPavel Emelyanov 			return rc;
15302c4c7155SPavel Emelyanov 		if (rc > 0)
15312c4c7155SPavel Emelyanov 			return 0;
15322c4c7155SPavel Emelyanov 	}
15332c4c7155SPavel Emelyanov 
15342c4c7155SPavel Emelyanov 	/* If there is no strategy routine, or if the strategy returns
15352c4c7155SPavel Emelyanov 	 * zero, proceed with automatic r/w */
15362c4c7155SPavel Emelyanov 	if (table->data && table->maxlen) {
15372c4c7155SPavel Emelyanov 		rc = sysctl_data(table, name, nlen, oldval, oldlenp,
15382c4c7155SPavel Emelyanov 				 newval, newlen);
15392c4c7155SPavel Emelyanov 		if (rc < 0)
15402c4c7155SPavel Emelyanov 			return rc;
15412c4c7155SPavel Emelyanov 	}
15422c4c7155SPavel Emelyanov 	return 0;
15432c4c7155SPavel Emelyanov }
15442c4c7155SPavel Emelyanov 
15452c4c7155SPavel Emelyanov static int parse_table(int __user *name, int nlen,
15462c4c7155SPavel Emelyanov 		       void __user *oldval, size_t __user *oldlenp,
15472c4c7155SPavel Emelyanov 		       void __user *newval, size_t newlen,
1548d7321cd6SPavel Emelyanov 		       struct ctl_table_root *root,
15492c4c7155SPavel Emelyanov 		       struct ctl_table *table)
15502c4c7155SPavel Emelyanov {
15512c4c7155SPavel Emelyanov 	int n;
15522c4c7155SPavel Emelyanov repeat:
15532c4c7155SPavel Emelyanov 	if (!nlen)
15542c4c7155SPavel Emelyanov 		return -ENOTDIR;
15552c4c7155SPavel Emelyanov 	if (get_user(n, name))
15562c4c7155SPavel Emelyanov 		return -EFAULT;
15572c4c7155SPavel Emelyanov 	for ( ; table->ctl_name || table->procname; table++) {
15582c4c7155SPavel Emelyanov 		if (!table->ctl_name)
15592c4c7155SPavel Emelyanov 			continue;
15602c4c7155SPavel Emelyanov 		if (n == table->ctl_name) {
15612c4c7155SPavel Emelyanov 			int error;
15622c4c7155SPavel Emelyanov 			if (table->child) {
1563e6305c43SAl Viro 				if (sysctl_perm(root, table, MAY_EXEC))
15642c4c7155SPavel Emelyanov 					return -EPERM;
15652c4c7155SPavel Emelyanov 				name++;
15662c4c7155SPavel Emelyanov 				nlen--;
15672c4c7155SPavel Emelyanov 				table = table->child;
15682c4c7155SPavel Emelyanov 				goto repeat;
15692c4c7155SPavel Emelyanov 			}
1570d7321cd6SPavel Emelyanov 			error = do_sysctl_strategy(root, table, name, nlen,
15712c4c7155SPavel Emelyanov 						   oldval, oldlenp,
15722c4c7155SPavel Emelyanov 						   newval, newlen);
15732c4c7155SPavel Emelyanov 			return error;
15742c4c7155SPavel Emelyanov 		}
15752c4c7155SPavel Emelyanov 	}
15762c4c7155SPavel Emelyanov 	return -ENOTDIR;
15772c4c7155SPavel Emelyanov }
15782c4c7155SPavel Emelyanov 
15791da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
15801da177e4SLinus Torvalds 	       void __user *newval, size_t newlen)
15811da177e4SLinus Torvalds {
1582805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1583330d57fbSAl Viro 	int error = -ENOTDIR;
15841da177e4SLinus Torvalds 
15851da177e4SLinus Torvalds 	if (nlen <= 0 || nlen >= CTL_MAXNAME)
15861da177e4SLinus Torvalds 		return -ENOTDIR;
15871da177e4SLinus Torvalds 	if (oldval) {
15881da177e4SLinus Torvalds 		int old_len;
15891da177e4SLinus Torvalds 		if (!oldlenp || get_user(old_len, oldlenp))
15901da177e4SLinus Torvalds 			return -EFAULT;
15911da177e4SLinus Torvalds 	}
1592330d57fbSAl Viro 
1593805b5d5eSEric W. Biederman 	for (head = sysctl_head_next(NULL); head;
1594805b5d5eSEric W. Biederman 			head = sysctl_head_next(head)) {
1595330d57fbSAl Viro 		error = parse_table(name, nlen, oldval, oldlenp,
1596d7321cd6SPavel Emelyanov 					newval, newlen,
1597d7321cd6SPavel Emelyanov 					head->root, head->ctl_table);
1598805b5d5eSEric W. Biederman 		if (error != -ENOTDIR) {
1599805b5d5eSEric W. Biederman 			sysctl_head_finish(head);
1600330d57fbSAl Viro 			break;
1601805b5d5eSEric W. Biederman 		}
1602805b5d5eSEric W. Biederman 	}
16031da177e4SLinus Torvalds 	return error;
16041da177e4SLinus Torvalds }
16051da177e4SLinus Torvalds 
16061da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
16071da177e4SLinus Torvalds {
16081da177e4SLinus Torvalds 	struct __sysctl_args tmp;
16091da177e4SLinus Torvalds 	int error;
16101da177e4SLinus Torvalds 
16111da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
16121da177e4SLinus Torvalds 		return -EFAULT;
16131da177e4SLinus Torvalds 
16147058cb02SEric W. Biederman 	error = deprecated_sysctl_warning(&tmp);
16157058cb02SEric W. Biederman 	if (error)
16167058cb02SEric W. Biederman 		goto out;
16177058cb02SEric W. Biederman 
16181da177e4SLinus Torvalds 	lock_kernel();
16191da177e4SLinus Torvalds 	error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
16201da177e4SLinus Torvalds 			  tmp.newval, tmp.newlen);
16211da177e4SLinus Torvalds 	unlock_kernel();
16227058cb02SEric W. Biederman out:
16231da177e4SLinus Torvalds 	return error;
16241da177e4SLinus Torvalds }
1625b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
16261da177e4SLinus Torvalds 
16271da177e4SLinus Torvalds /*
16281ff007ebSEric W. Biederman  * sysctl_perm does NOT grant the superuser all rights automatically, because
16291da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
16301da177e4SLinus Torvalds  */
16311da177e4SLinus Torvalds 
16321da177e4SLinus Torvalds static int test_perm(int mode, int op)
16331da177e4SLinus Torvalds {
16341da177e4SLinus Torvalds 	if (!current->euid)
16351da177e4SLinus Torvalds 		mode >>= 6;
16361da177e4SLinus Torvalds 	else if (in_egroup_p(0))
16371da177e4SLinus Torvalds 		mode >>= 3;
1638e6305c43SAl Viro 	if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
16391da177e4SLinus Torvalds 		return 0;
16401da177e4SLinus Torvalds 	return -EACCES;
16411da177e4SLinus Torvalds }
16421da177e4SLinus Torvalds 
1643d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
16441da177e4SLinus Torvalds {
16451da177e4SLinus Torvalds 	int error;
1646d7321cd6SPavel Emelyanov 	int mode;
1647d7321cd6SPavel Emelyanov 
1648e6305c43SAl Viro 	error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
16491da177e4SLinus Torvalds 	if (error)
16501da177e4SLinus Torvalds 		return error;
1651d7321cd6SPavel Emelyanov 
1652d7321cd6SPavel Emelyanov 	if (root->permissions)
1653d7321cd6SPavel Emelyanov 		mode = root->permissions(root, current->nsproxy, table);
1654d7321cd6SPavel Emelyanov 	else
1655d7321cd6SPavel Emelyanov 		mode = table->mode;
1656d7321cd6SPavel Emelyanov 
1657d7321cd6SPavel Emelyanov 	return test_perm(mode, op);
16581da177e4SLinus Torvalds }
16591da177e4SLinus Torvalds 
1660d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1661d912b0ccSEric W. Biederman {
1662d912b0ccSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
1663d912b0ccSEric W. Biederman 		table->parent = parent;
1664d912b0ccSEric W. Biederman 		if (table->child)
1665d912b0ccSEric W. Biederman 			sysctl_set_parent(table, table->child);
1666d912b0ccSEric W. Biederman 	}
1667d912b0ccSEric W. Biederman }
1668d912b0ccSEric W. Biederman 
1669d912b0ccSEric W. Biederman static __init int sysctl_init(void)
1670d912b0ccSEric W. Biederman {
1671d912b0ccSEric W. Biederman 	sysctl_set_parent(NULL, root_table);
167288f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
167388f458e4SHolger Schurig 	{
167488f458e4SHolger Schurig 		int err;
1675e51b6ba0SEric W. Biederman 		err = sysctl_check_table(current->nsproxy, root_table);
167688f458e4SHolger Schurig 	}
167788f458e4SHolger Schurig #endif
1678d912b0ccSEric W. Biederman 	return 0;
1679d912b0ccSEric W. Biederman }
1680d912b0ccSEric W. Biederman 
1681d912b0ccSEric W. Biederman core_initcall(sysctl_init);
1682d912b0ccSEric W. Biederman 
1683*bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch,
1684*bfbcf034SAl Viro 				      struct ctl_table *table)
1685ae7edeccSAl Viro {
1686ae7edeccSAl Viro 	struct ctl_table *p;
1687ae7edeccSAl Viro 	const char *s = branch->procname;
1688ae7edeccSAl Viro 
1689ae7edeccSAl Viro 	/* branch should have named subdirectory as its first element */
1690ae7edeccSAl Viro 	if (!s || !branch->child)
1691*bfbcf034SAl Viro 		return NULL;
1692ae7edeccSAl Viro 
1693ae7edeccSAl Viro 	/* ... and nothing else */
1694ae7edeccSAl Viro 	if (branch[1].procname || branch[1].ctl_name)
1695*bfbcf034SAl Viro 		return NULL;
1696ae7edeccSAl Viro 
1697ae7edeccSAl Viro 	/* table should contain subdirectory with the same name */
1698ae7edeccSAl Viro 	for (p = table; p->procname || p->ctl_name; p++) {
1699ae7edeccSAl Viro 		if (!p->child)
1700ae7edeccSAl Viro 			continue;
1701ae7edeccSAl Viro 		if (p->procname && strcmp(p->procname, s) == 0)
1702*bfbcf034SAl Viro 			return p;
1703ae7edeccSAl Viro 	}
1704*bfbcf034SAl Viro 	return NULL;
1705ae7edeccSAl Viro }
1706ae7edeccSAl Viro 
1707ae7edeccSAl Viro /* see if attaching q to p would be an improvement */
1708ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1709ae7edeccSAl Viro {
1710ae7edeccSAl Viro 	struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1711*bfbcf034SAl Viro 	struct ctl_table *next;
1712ae7edeccSAl Viro 	int is_better = 0;
1713ae7edeccSAl Viro 	int not_in_parent = !p->attached_by;
1714ae7edeccSAl Viro 
1715*bfbcf034SAl Viro 	while ((next = is_branch_in(by, to)) != NULL) {
1716ae7edeccSAl Viro 		if (by == q->attached_by)
1717ae7edeccSAl Viro 			is_better = 1;
1718ae7edeccSAl Viro 		if (to == p->attached_by)
1719ae7edeccSAl Viro 			not_in_parent = 1;
1720ae7edeccSAl Viro 		by = by->child;
1721*bfbcf034SAl Viro 		to = next->child;
1722ae7edeccSAl Viro 	}
1723ae7edeccSAl Viro 
1724ae7edeccSAl Viro 	if (is_better && not_in_parent) {
1725ae7edeccSAl Viro 		q->attached_by = by;
1726ae7edeccSAl Viro 		q->attached_to = to;
1727ae7edeccSAl Viro 		q->parent = p;
1728ae7edeccSAl Viro 	}
1729ae7edeccSAl Viro }
1730ae7edeccSAl Viro 
17311da177e4SLinus Torvalds /**
1732e51b6ba0SEric W. Biederman  * __register_sysctl_paths - register a sysctl hierarchy
1733e51b6ba0SEric W. Biederman  * @root: List of sysctl headers to register on
1734e51b6ba0SEric W. Biederman  * @namespaces: Data to compute which lists of sysctl entries are visible
173529e796fdSEric W. Biederman  * @path: The path to the directory the sysctl table is in.
17361da177e4SLinus Torvalds  * @table: the top-level table structure
17371da177e4SLinus Torvalds  *
17381da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
173929e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
17401da177e4SLinus Torvalds  *
1741d8217f07SEric W. Biederman  * The members of the &struct ctl_table structure are used as follows:
17421da177e4SLinus Torvalds  *
17431da177e4SLinus Torvalds  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
17441da177e4SLinus Torvalds  *            must be unique within that level of sysctl
17451da177e4SLinus Torvalds  *
17461da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
17471da177e4SLinus Torvalds  *            enter a sysctl file
17481da177e4SLinus Torvalds  *
17491da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
17501da177e4SLinus Torvalds  *
17511da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
17521da177e4SLinus Torvalds  *
17531da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
17541da177e4SLinus Torvalds  *
17551da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
17561da177e4SLinus Torvalds  *         %NULL.
17571da177e4SLinus Torvalds  *
17581da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
17591da177e4SLinus Torvalds  *
17601da177e4SLinus Torvalds  * strategy - the strategy routine (described below)
17611da177e4SLinus Torvalds  *
17621da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
17631da177e4SLinus Torvalds  *
17641da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
17651da177e4SLinus Torvalds  *
17661da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
17671da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
17681da177e4SLinus Torvalds  *
17691da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
17701da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
17711da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
17721da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
17731da177e4SLinus Torvalds  *
17741da177e4SLinus Torvalds  * More sophisticated management can be enabled by the provision of a
17751da177e4SLinus Torvalds  * strategy routine with the table entry.  This will be called before
17761da177e4SLinus Torvalds  * any automatic read or write of the data is performed.
17771da177e4SLinus Torvalds  *
17781da177e4SLinus Torvalds  * The strategy routine may return
17791da177e4SLinus Torvalds  *
17801da177e4SLinus Torvalds  * < 0 - Error occurred (error is passed to user process)
17811da177e4SLinus Torvalds  *
17821da177e4SLinus Torvalds  * 0   - OK - proceed with automatic read or write.
17831da177e4SLinus Torvalds  *
17841da177e4SLinus Torvalds  * > 0 - OK - read or write has been done by the strategy routine, so
17851da177e4SLinus Torvalds  *       return immediately.
17861da177e4SLinus Torvalds  *
17871da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
17881da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
17891da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
17901da177e4SLinus Torvalds  * cover common cases -
17911da177e4SLinus Torvalds  *
17921da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
17931da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
17941da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
17951da177e4SLinus Torvalds  *
17961da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
17971da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
17981da177e4SLinus Torvalds  *
17991da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
18001da177e4SLinus Torvalds  * to the table header on success.
18011da177e4SLinus Torvalds  */
1802e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths(
1803e51b6ba0SEric W. Biederman 	struct ctl_table_root *root,
1804e51b6ba0SEric W. Biederman 	struct nsproxy *namespaces,
1805e51b6ba0SEric W. Biederman 	const struct ctl_path *path, struct ctl_table *table)
18061da177e4SLinus Torvalds {
180729e796fdSEric W. Biederman 	struct ctl_table_header *header;
180829e796fdSEric W. Biederman 	struct ctl_table *new, **prevp;
180929e796fdSEric W. Biederman 	unsigned int n, npath;
1810ae7edeccSAl Viro 	struct ctl_table_set *set;
181129e796fdSEric W. Biederman 
181229e796fdSEric W. Biederman 	/* Count the path components */
181329e796fdSEric W. Biederman 	for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
181429e796fdSEric W. Biederman 		;
181529e796fdSEric W. Biederman 
181629e796fdSEric W. Biederman 	/*
181729e796fdSEric W. Biederman 	 * For each path component, allocate a 2-element ctl_table array.
181829e796fdSEric W. Biederman 	 * The first array element will be filled with the sysctl entry
181929e796fdSEric W. Biederman 	 * for this, the second will be the sentinel (ctl_name == 0).
182029e796fdSEric W. Biederman 	 *
182129e796fdSEric W. Biederman 	 * We allocate everything in one go so that we don't have to
182229e796fdSEric W. Biederman 	 * worry about freeing additional memory in unregister_sysctl_table.
182329e796fdSEric W. Biederman 	 */
182429e796fdSEric W. Biederman 	header = kzalloc(sizeof(struct ctl_table_header) +
182529e796fdSEric W. Biederman 			 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
182629e796fdSEric W. Biederman 	if (!header)
18271da177e4SLinus Torvalds 		return NULL;
182829e796fdSEric W. Biederman 
182929e796fdSEric W. Biederman 	new = (struct ctl_table *) (header + 1);
183029e796fdSEric W. Biederman 
183129e796fdSEric W. Biederman 	/* Now connect the dots */
183229e796fdSEric W. Biederman 	prevp = &header->ctl_table;
183329e796fdSEric W. Biederman 	for (n = 0; n < npath; ++n, ++path) {
183429e796fdSEric W. Biederman 		/* Copy the procname */
183529e796fdSEric W. Biederman 		new->procname = path->procname;
183629e796fdSEric W. Biederman 		new->ctl_name = path->ctl_name;
183729e796fdSEric W. Biederman 		new->mode     = 0555;
183829e796fdSEric W. Biederman 
183929e796fdSEric W. Biederman 		*prevp = new;
184029e796fdSEric W. Biederman 		prevp = &new->child;
184129e796fdSEric W. Biederman 
184229e796fdSEric W. Biederman 		new += 2;
184329e796fdSEric W. Biederman 	}
184429e796fdSEric W. Biederman 	*prevp = table;
184523eb06deSEric W. Biederman 	header->ctl_table_arg = table;
184629e796fdSEric W. Biederman 
184729e796fdSEric W. Biederman 	INIT_LIST_HEAD(&header->ctl_entry);
184829e796fdSEric W. Biederman 	header->used = 0;
184929e796fdSEric W. Biederman 	header->unregistering = NULL;
1850e51b6ba0SEric W. Biederman 	header->root = root;
185129e796fdSEric W. Biederman 	sysctl_set_parent(NULL, header->ctl_table);
1852f7e6ced4SAl Viro 	header->count = 1;
185388f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1854e51b6ba0SEric W. Biederman 	if (sysctl_check_table(namespaces, header->ctl_table)) {
185529e796fdSEric W. Biederman 		kfree(header);
1856fc6cd25bSEric W. Biederman 		return NULL;
1857fc6cd25bSEric W. Biederman 	}
185888f458e4SHolger Schurig #endif
1859330d57fbSAl Viro 	spin_lock(&sysctl_lock);
186073455092SAl Viro 	header->set = lookup_header_set(root, namespaces);
1861ae7edeccSAl Viro 	header->attached_by = header->ctl_table;
1862ae7edeccSAl Viro 	header->attached_to = root_table;
1863ae7edeccSAl Viro 	header->parent = &root_table_header;
1864ae7edeccSAl Viro 	for (set = header->set; set; set = set->parent) {
1865ae7edeccSAl Viro 		struct ctl_table_header *p;
1866ae7edeccSAl Viro 		list_for_each_entry(p, &set->list, ctl_entry) {
1867ae7edeccSAl Viro 			if (p->unregistering)
1868ae7edeccSAl Viro 				continue;
1869ae7edeccSAl Viro 			try_attach(p, header);
1870ae7edeccSAl Viro 		}
1871ae7edeccSAl Viro 	}
1872ae7edeccSAl Viro 	header->parent->count++;
187373455092SAl Viro 	list_add_tail(&header->ctl_entry, &header->set->list);
1874330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
187529e796fdSEric W. Biederman 
187629e796fdSEric W. Biederman 	return header;
187729e796fdSEric W. Biederman }
187829e796fdSEric W. Biederman 
187929e796fdSEric W. Biederman /**
1880e51b6ba0SEric W. Biederman  * register_sysctl_table_path - register a sysctl table hierarchy
1881e51b6ba0SEric W. Biederman  * @path: The path to the directory the sysctl table is in.
1882e51b6ba0SEric W. Biederman  * @table: the top-level table structure
1883e51b6ba0SEric W. Biederman  *
1884e51b6ba0SEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1885e51b6ba0SEric W. Biederman  * array. A completely 0 filled entry terminates the table.
1886e51b6ba0SEric W. Biederman  *
1887e51b6ba0SEric W. Biederman  * See __register_sysctl_paths for more details.
1888e51b6ba0SEric W. Biederman  */
1889e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1890e51b6ba0SEric W. Biederman 						struct ctl_table *table)
1891e51b6ba0SEric W. Biederman {
1892e51b6ba0SEric W. Biederman 	return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1893e51b6ba0SEric W. Biederman 					path, table);
1894e51b6ba0SEric W. Biederman }
1895e51b6ba0SEric W. Biederman 
1896e51b6ba0SEric W. Biederman /**
189729e796fdSEric W. Biederman  * register_sysctl_table - register a sysctl table hierarchy
189829e796fdSEric W. Biederman  * @table: the top-level table structure
189929e796fdSEric W. Biederman  *
190029e796fdSEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
190129e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
190229e796fdSEric W. Biederman  *
190329e796fdSEric W. Biederman  * See register_sysctl_paths for more details.
190429e796fdSEric W. Biederman  */
190529e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
190629e796fdSEric W. Biederman {
190729e796fdSEric W. Biederman 	static const struct ctl_path null_path[] = { {} };
190829e796fdSEric W. Biederman 
190929e796fdSEric W. Biederman 	return register_sysctl_paths(null_path, table);
19101da177e4SLinus Torvalds }
19111da177e4SLinus Torvalds 
19121da177e4SLinus Torvalds /**
19131da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
19141da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
19151da177e4SLinus Torvalds  *
19161da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
19171da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
19181da177e4SLinus Torvalds  */
19191da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
19201da177e4SLinus Torvalds {
1921330d57fbSAl Viro 	might_sleep();
1922f1dad166SPavel Emelyanov 
1923f1dad166SPavel Emelyanov 	if (header == NULL)
1924f1dad166SPavel Emelyanov 		return;
1925f1dad166SPavel Emelyanov 
1926330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1927330d57fbSAl Viro 	start_unregistering(header);
1928ae7edeccSAl Viro 	if (!--header->parent->count) {
1929ae7edeccSAl Viro 		WARN_ON(1);
1930ae7edeccSAl Viro 		kfree(header->parent);
1931ae7edeccSAl Viro 	}
1932f7e6ced4SAl Viro 	if (!--header->count)
19331da177e4SLinus Torvalds 		kfree(header);
1934f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
19351da177e4SLinus Torvalds }
19361da177e4SLinus Torvalds 
19379043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p)
19389043476fSAl Viro {
19399043476fSAl Viro 	struct ctl_table_set *set = p->set;
19409043476fSAl Viro 	int res;
19419043476fSAl Viro 	spin_lock(&sysctl_lock);
19429043476fSAl Viro 	if (p->unregistering)
19439043476fSAl Viro 		res = 0;
19449043476fSAl Viro 	else if (!set->is_seen)
19459043476fSAl Viro 		res = 1;
19469043476fSAl Viro 	else
19479043476fSAl Viro 		res = set->is_seen(set);
19489043476fSAl Viro 	spin_unlock(&sysctl_lock);
19499043476fSAl Viro 	return res;
19509043476fSAl Viro }
19519043476fSAl Viro 
195273455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
195373455092SAl Viro 	struct ctl_table_set *parent,
195473455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
195573455092SAl Viro {
195673455092SAl Viro 	INIT_LIST_HEAD(&p->list);
195773455092SAl Viro 	p->parent = parent ? parent : &sysctl_table_root.default_set;
195873455092SAl Viro 	p->is_seen = is_seen;
195973455092SAl Viro }
196073455092SAl Viro 
1961b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */
1962d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1963b89a8171SEric W. Biederman {
1964b89a8171SEric W. Biederman 	return NULL;
1965b89a8171SEric W. Biederman }
1966b89a8171SEric W. Biederman 
196729e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
196829e796fdSEric W. Biederman 						    struct ctl_table *table)
196929e796fdSEric W. Biederman {
197029e796fdSEric W. Biederman 	return NULL;
197129e796fdSEric W. Biederman }
197229e796fdSEric W. Biederman 
1973b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table)
1974b89a8171SEric W. Biederman {
1975b89a8171SEric W. Biederman }
1976b89a8171SEric W. Biederman 
197773455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
197873455092SAl Viro 	struct ctl_table_set *parent,
197973455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
198073455092SAl Viro {
198173455092SAl Viro }
198273455092SAl Viro 
1983f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
1984f7e6ced4SAl Viro {
1985f7e6ced4SAl Viro }
1986f7e6ced4SAl Viro 
1987b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
1988b89a8171SEric W. Biederman 
19891da177e4SLinus Torvalds /*
19901da177e4SLinus Torvalds  * /proc/sys support
19911da177e4SLinus Torvalds  */
19921da177e4SLinus Torvalds 
1993b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
19941da177e4SLinus Torvalds 
1995b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write,
1996b1ba4dddSAdrian Bunk 			   struct file *filp, void __user *buffer,
1997b1ba4dddSAdrian Bunk 			   size_t *lenp, loff_t *ppos)
1998f5dd3d6fSSam Vilain {
1999f5dd3d6fSSam Vilain 	size_t len;
2000f5dd3d6fSSam Vilain 	char __user *p;
2001f5dd3d6fSSam Vilain 	char c;
2002f5dd3d6fSSam Vilain 
20038d060877SOleg Nesterov 	if (!data || !maxlen || !*lenp) {
2004f5dd3d6fSSam Vilain 		*lenp = 0;
2005f5dd3d6fSSam Vilain 		return 0;
2006f5dd3d6fSSam Vilain 	}
2007f5dd3d6fSSam Vilain 
2008f5dd3d6fSSam Vilain 	if (write) {
2009f5dd3d6fSSam Vilain 		len = 0;
2010f5dd3d6fSSam Vilain 		p = buffer;
2011f5dd3d6fSSam Vilain 		while (len < *lenp) {
2012f5dd3d6fSSam Vilain 			if (get_user(c, p++))
2013f5dd3d6fSSam Vilain 				return -EFAULT;
2014f5dd3d6fSSam Vilain 			if (c == 0 || c == '\n')
2015f5dd3d6fSSam Vilain 				break;
2016f5dd3d6fSSam Vilain 			len++;
2017f5dd3d6fSSam Vilain 		}
2018f5dd3d6fSSam Vilain 		if (len >= maxlen)
2019f5dd3d6fSSam Vilain 			len = maxlen-1;
2020f5dd3d6fSSam Vilain 		if(copy_from_user(data, buffer, len))
2021f5dd3d6fSSam Vilain 			return -EFAULT;
2022f5dd3d6fSSam Vilain 		((char *) data)[len] = 0;
2023f5dd3d6fSSam Vilain 		*ppos += *lenp;
2024f5dd3d6fSSam Vilain 	} else {
2025f5dd3d6fSSam Vilain 		len = strlen(data);
2026f5dd3d6fSSam Vilain 		if (len > maxlen)
2027f5dd3d6fSSam Vilain 			len = maxlen;
20288d060877SOleg Nesterov 
20298d060877SOleg Nesterov 		if (*ppos > len) {
20308d060877SOleg Nesterov 			*lenp = 0;
20318d060877SOleg Nesterov 			return 0;
20328d060877SOleg Nesterov 		}
20338d060877SOleg Nesterov 
20348d060877SOleg Nesterov 		data += *ppos;
20358d060877SOleg Nesterov 		len  -= *ppos;
20368d060877SOleg Nesterov 
2037f5dd3d6fSSam Vilain 		if (len > *lenp)
2038f5dd3d6fSSam Vilain 			len = *lenp;
2039f5dd3d6fSSam Vilain 		if (len)
2040f5dd3d6fSSam Vilain 			if(copy_to_user(buffer, data, len))
2041f5dd3d6fSSam Vilain 				return -EFAULT;
2042f5dd3d6fSSam Vilain 		if (len < *lenp) {
2043f5dd3d6fSSam Vilain 			if(put_user('\n', ((char __user *) buffer) + len))
2044f5dd3d6fSSam Vilain 				return -EFAULT;
2045f5dd3d6fSSam Vilain 			len++;
2046f5dd3d6fSSam Vilain 		}
2047f5dd3d6fSSam Vilain 		*lenp = len;
2048f5dd3d6fSSam Vilain 		*ppos += len;
2049f5dd3d6fSSam Vilain 	}
2050f5dd3d6fSSam Vilain 	return 0;
2051f5dd3d6fSSam Vilain }
2052f5dd3d6fSSam Vilain 
20531da177e4SLinus Torvalds /**
20541da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
20551da177e4SLinus Torvalds  * @table: the sysctl table
20561da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
20571da177e4SLinus Torvalds  * @filp: the file structure
20581da177e4SLinus Torvalds  * @buffer: the user buffer
20591da177e4SLinus Torvalds  * @lenp: the size of the user buffer
20601da177e4SLinus Torvalds  * @ppos: file position
20611da177e4SLinus Torvalds  *
20621da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
20631da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
20641da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
20651da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
20661da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
20671da177e4SLinus Torvalds  * not large enough.
20681da177e4SLinus Torvalds  *
20691da177e4SLinus Torvalds  * Returns 0 on success.
20701da177e4SLinus Torvalds  */
2071d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp,
20721da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
20731da177e4SLinus Torvalds {
2074f5dd3d6fSSam Vilain 	return _proc_do_string(table->data, table->maxlen, write, filp,
2075f5dd3d6fSSam Vilain 			       buffer, lenp, ppos);
20761da177e4SLinus Torvalds }
20771da177e4SLinus Torvalds 
20781da177e4SLinus Torvalds 
20791da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
20801da177e4SLinus Torvalds 				 int *valp,
20811da177e4SLinus Torvalds 				 int write, void *data)
20821da177e4SLinus Torvalds {
20831da177e4SLinus Torvalds 	if (write) {
20841da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
20851da177e4SLinus Torvalds 	} else {
20861da177e4SLinus Torvalds 		int val = *valp;
20871da177e4SLinus Torvalds 		if (val < 0) {
20881da177e4SLinus Torvalds 			*negp = -1;
20891da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
20901da177e4SLinus Torvalds 		} else {
20911da177e4SLinus Torvalds 			*negp = 0;
20921da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
20931da177e4SLinus Torvalds 		}
20941da177e4SLinus Torvalds 	}
20951da177e4SLinus Torvalds 	return 0;
20961da177e4SLinus Torvalds }
20971da177e4SLinus Torvalds 
2098d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2099fcfbd547SKirill Korotaev 		  int write, struct file *filp, void __user *buffer,
2100fcfbd547SKirill Korotaev 		  size_t *lenp, loff_t *ppos,
21011da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
21021da177e4SLinus Torvalds 			      int write, void *data),
21031da177e4SLinus Torvalds 		  void *data)
21041da177e4SLinus Torvalds {
21051da177e4SLinus Torvalds #define TMPBUFLEN 21
21061da177e4SLinus Torvalds 	int *i, vleft, first=1, neg, val;
21071da177e4SLinus Torvalds 	unsigned long lval;
21081da177e4SLinus Torvalds 	size_t left, len;
21091da177e4SLinus Torvalds 
21101da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
21111da177e4SLinus Torvalds 	char __user *s = buffer;
21121da177e4SLinus Torvalds 
2113fcfbd547SKirill Korotaev 	if (!tbl_data || !table->maxlen || !*lenp ||
21141da177e4SLinus Torvalds 	    (*ppos && !write)) {
21151da177e4SLinus Torvalds 		*lenp = 0;
21161da177e4SLinus Torvalds 		return 0;
21171da177e4SLinus Torvalds 	}
21181da177e4SLinus Torvalds 
2119fcfbd547SKirill Korotaev 	i = (int *) tbl_data;
21201da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
21211da177e4SLinus Torvalds 	left = *lenp;
21221da177e4SLinus Torvalds 
21231da177e4SLinus Torvalds 	if (!conv)
21241da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
21251da177e4SLinus Torvalds 
21261da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
21271da177e4SLinus Torvalds 		if (write) {
21281da177e4SLinus Torvalds 			while (left) {
21291da177e4SLinus Torvalds 				char c;
21301da177e4SLinus Torvalds 				if (get_user(c, s))
21311da177e4SLinus Torvalds 					return -EFAULT;
21321da177e4SLinus Torvalds 				if (!isspace(c))
21331da177e4SLinus Torvalds 					break;
21341da177e4SLinus Torvalds 				left--;
21351da177e4SLinus Torvalds 				s++;
21361da177e4SLinus Torvalds 			}
21371da177e4SLinus Torvalds 			if (!left)
21381da177e4SLinus Torvalds 				break;
21391da177e4SLinus Torvalds 			neg = 0;
21401da177e4SLinus Torvalds 			len = left;
21411da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
21421da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
21431da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
21441da177e4SLinus Torvalds 				return -EFAULT;
21451da177e4SLinus Torvalds 			buf[len] = 0;
21461da177e4SLinus Torvalds 			p = buf;
21471da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
21481da177e4SLinus Torvalds 				neg = 1;
2149bd9b0bacSBP, Praveen 				p++;
21501da177e4SLinus Torvalds 			}
21511da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
21521da177e4SLinus Torvalds 				break;
21531da177e4SLinus Torvalds 
21541da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
21551da177e4SLinus Torvalds 
21561da177e4SLinus Torvalds 			len = p-buf;
21571da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
21581da177e4SLinus Torvalds 				break;
21591da177e4SLinus Torvalds 			if (neg)
21601da177e4SLinus Torvalds 				val = -val;
21611da177e4SLinus Torvalds 			s += len;
21621da177e4SLinus Torvalds 			left -= len;
21631da177e4SLinus Torvalds 
21641da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
21651da177e4SLinus Torvalds 				break;
21661da177e4SLinus Torvalds 		} else {
21671da177e4SLinus Torvalds 			p = buf;
21681da177e4SLinus Torvalds 			if (!first)
21691da177e4SLinus Torvalds 				*p++ = '\t';
21701da177e4SLinus Torvalds 
21711da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
21721da177e4SLinus Torvalds 				break;
21731da177e4SLinus Torvalds 
21741da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
21751da177e4SLinus Torvalds 			len = strlen(buf);
21761da177e4SLinus Torvalds 			if (len > left)
21771da177e4SLinus Torvalds 				len = left;
21781da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
21791da177e4SLinus Torvalds 				return -EFAULT;
21801da177e4SLinus Torvalds 			left -= len;
21811da177e4SLinus Torvalds 			s += len;
21821da177e4SLinus Torvalds 		}
21831da177e4SLinus Torvalds 	}
21841da177e4SLinus Torvalds 
21851da177e4SLinus Torvalds 	if (!write && !first && left) {
21861da177e4SLinus Torvalds 		if(put_user('\n', s))
21871da177e4SLinus Torvalds 			return -EFAULT;
21881da177e4SLinus Torvalds 		left--, s++;
21891da177e4SLinus Torvalds 	}
21901da177e4SLinus Torvalds 	if (write) {
21911da177e4SLinus Torvalds 		while (left) {
21921da177e4SLinus Torvalds 			char c;
21931da177e4SLinus Torvalds 			if (get_user(c, s++))
21941da177e4SLinus Torvalds 				return -EFAULT;
21951da177e4SLinus Torvalds 			if (!isspace(c))
21961da177e4SLinus Torvalds 				break;
21971da177e4SLinus Torvalds 			left--;
21981da177e4SLinus Torvalds 		}
21991da177e4SLinus Torvalds 	}
22001da177e4SLinus Torvalds 	if (write && first)
22011da177e4SLinus Torvalds 		return -EINVAL;
22021da177e4SLinus Torvalds 	*lenp -= left;
22031da177e4SLinus Torvalds 	*ppos += *lenp;
22041da177e4SLinus Torvalds 	return 0;
22051da177e4SLinus Torvalds #undef TMPBUFLEN
22061da177e4SLinus Torvalds }
22071da177e4SLinus Torvalds 
2208d8217f07SEric W. Biederman static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2209fcfbd547SKirill Korotaev 		  void __user *buffer, size_t *lenp, loff_t *ppos,
2210fcfbd547SKirill Korotaev 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2211fcfbd547SKirill Korotaev 			      int write, void *data),
2212fcfbd547SKirill Korotaev 		  void *data)
2213fcfbd547SKirill Korotaev {
2214fcfbd547SKirill Korotaev 	return __do_proc_dointvec(table->data, table, write, filp,
2215fcfbd547SKirill Korotaev 			buffer, lenp, ppos, conv, data);
2216fcfbd547SKirill Korotaev }
2217fcfbd547SKirill Korotaev 
22181da177e4SLinus Torvalds /**
22191da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
22201da177e4SLinus Torvalds  * @table: the sysctl table
22211da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
22221da177e4SLinus Torvalds  * @filp: the file structure
22231da177e4SLinus Torvalds  * @buffer: the user buffer
22241da177e4SLinus Torvalds  * @lenp: the size of the user buffer
22251da177e4SLinus Torvalds  * @ppos: file position
22261da177e4SLinus Torvalds  *
22271da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
22281da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
22291da177e4SLinus Torvalds  *
22301da177e4SLinus Torvalds  * Returns 0 on success.
22311da177e4SLinus Torvalds  */
2232d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
22331da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
22341da177e4SLinus Torvalds {
22351da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
22361da177e4SLinus Torvalds 		    	    NULL,NULL);
22371da177e4SLinus Torvalds }
22381da177e4SLinus Torvalds 
22391da177e4SLinus Torvalds #define OP_SET	0
22401da177e4SLinus Torvalds #define OP_AND	1
224134f5a398STheodore Ts'o #define OP_OR	2
22421da177e4SLinus Torvalds 
22431da177e4SLinus Torvalds static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
22441da177e4SLinus Torvalds 				      int *valp,
22451da177e4SLinus Torvalds 				      int write, void *data)
22461da177e4SLinus Torvalds {
22471da177e4SLinus Torvalds 	int op = *(int *)data;
22481da177e4SLinus Torvalds 	if (write) {
22491da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
22501da177e4SLinus Torvalds 		switch(op) {
22511da177e4SLinus Torvalds 		case OP_SET:	*valp = val; break;
22521da177e4SLinus Torvalds 		case OP_AND:	*valp &= val; break;
225334f5a398STheodore Ts'o 		case OP_OR:	*valp |= val; break;
22541da177e4SLinus Torvalds 		}
22551da177e4SLinus Torvalds 	} else {
22561da177e4SLinus Torvalds 		int val = *valp;
22571da177e4SLinus Torvalds 		if (val < 0) {
22581da177e4SLinus Torvalds 			*negp = -1;
22591da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
22601da177e4SLinus Torvalds 		} else {
22611da177e4SLinus Torvalds 			*negp = 0;
22621da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
22631da177e4SLinus Torvalds 		}
22641da177e4SLinus Torvalds 	}
22651da177e4SLinus Torvalds 	return 0;
22661da177e4SLinus Torvalds }
22671da177e4SLinus Torvalds 
226834f5a398STheodore Ts'o /*
226934f5a398STheodore Ts'o  *	Taint values can only be increased
227034f5a398STheodore Ts'o  */
2271d8217f07SEric W. Biederman static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
227234f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos)
227334f5a398STheodore Ts'o {
227434f5a398STheodore Ts'o 	int op;
227534f5a398STheodore Ts'o 
227691fcd412SBastian Blank 	if (write && !capable(CAP_SYS_ADMIN))
227734f5a398STheodore Ts'o 		return -EPERM;
227834f5a398STheodore Ts'o 
227934f5a398STheodore Ts'o 	op = OP_OR;
228034f5a398STheodore Ts'o 	return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
228134f5a398STheodore Ts'o 				do_proc_dointvec_bset_conv,&op);
228234f5a398STheodore Ts'o }
228334f5a398STheodore Ts'o 
22841da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
22851da177e4SLinus Torvalds 	int *min;
22861da177e4SLinus Torvalds 	int *max;
22871da177e4SLinus Torvalds };
22881da177e4SLinus Torvalds 
22891da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
22901da177e4SLinus Torvalds 					int *valp,
22911da177e4SLinus Torvalds 					int write, void *data)
22921da177e4SLinus Torvalds {
22931da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
22941da177e4SLinus Torvalds 	if (write) {
22951da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
22961da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
22971da177e4SLinus Torvalds 		    (param->max && *param->max < val))
22981da177e4SLinus Torvalds 			return -EINVAL;
22991da177e4SLinus Torvalds 		*valp = val;
23001da177e4SLinus Torvalds 	} else {
23011da177e4SLinus Torvalds 		int val = *valp;
23021da177e4SLinus Torvalds 		if (val < 0) {
23031da177e4SLinus Torvalds 			*negp = -1;
23041da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
23051da177e4SLinus Torvalds 		} else {
23061da177e4SLinus Torvalds 			*negp = 0;
23071da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
23081da177e4SLinus Torvalds 		}
23091da177e4SLinus Torvalds 	}
23101da177e4SLinus Torvalds 	return 0;
23111da177e4SLinus Torvalds }
23121da177e4SLinus Torvalds 
23131da177e4SLinus Torvalds /**
23141da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
23151da177e4SLinus Torvalds  * @table: the sysctl table
23161da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23171da177e4SLinus Torvalds  * @filp: the file structure
23181da177e4SLinus Torvalds  * @buffer: the user buffer
23191da177e4SLinus Torvalds  * @lenp: the size of the user buffer
23201da177e4SLinus Torvalds  * @ppos: file position
23211da177e4SLinus Torvalds  *
23221da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23231da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23241da177e4SLinus Torvalds  *
23251da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
23261da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
23271da177e4SLinus Torvalds  *
23281da177e4SLinus Torvalds  * Returns 0 on success.
23291da177e4SLinus Torvalds  */
2330d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
23311da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
23321da177e4SLinus Torvalds {
23331da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
23341da177e4SLinus Torvalds 		.min = (int *) table->extra1,
23351da177e4SLinus Torvalds 		.max = (int *) table->extra2,
23361da177e4SLinus Torvalds 	};
23371da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
23381da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
23391da177e4SLinus Torvalds }
23401da177e4SLinus Torvalds 
2341d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
23421da177e4SLinus Torvalds 				     struct file *filp,
23431da177e4SLinus Torvalds 				     void __user *buffer,
23441da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
23451da177e4SLinus Torvalds 				     unsigned long convmul,
23461da177e4SLinus Torvalds 				     unsigned long convdiv)
23471da177e4SLinus Torvalds {
23481da177e4SLinus Torvalds #define TMPBUFLEN 21
23491da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
23501da177e4SLinus Torvalds 	int vleft, first=1, neg;
23511da177e4SLinus Torvalds 	size_t len, left;
23521da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
23531da177e4SLinus Torvalds 	char __user *s = buffer;
23541da177e4SLinus Torvalds 
2355fcfbd547SKirill Korotaev 	if (!data || !table->maxlen || !*lenp ||
23561da177e4SLinus Torvalds 	    (*ppos && !write)) {
23571da177e4SLinus Torvalds 		*lenp = 0;
23581da177e4SLinus Torvalds 		return 0;
23591da177e4SLinus Torvalds 	}
23601da177e4SLinus Torvalds 
2361fcfbd547SKirill Korotaev 	i = (unsigned long *) data;
23621da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
23631da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
23641da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
23651da177e4SLinus Torvalds 	left = *lenp;
23661da177e4SLinus Torvalds 
23671da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
23681da177e4SLinus Torvalds 		if (write) {
23691da177e4SLinus Torvalds 			while (left) {
23701da177e4SLinus Torvalds 				char c;
23711da177e4SLinus Torvalds 				if (get_user(c, s))
23721da177e4SLinus Torvalds 					return -EFAULT;
23731da177e4SLinus Torvalds 				if (!isspace(c))
23741da177e4SLinus Torvalds 					break;
23751da177e4SLinus Torvalds 				left--;
23761da177e4SLinus Torvalds 				s++;
23771da177e4SLinus Torvalds 			}
23781da177e4SLinus Torvalds 			if (!left)
23791da177e4SLinus Torvalds 				break;
23801da177e4SLinus Torvalds 			neg = 0;
23811da177e4SLinus Torvalds 			len = left;
23821da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
23831da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
23841da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
23851da177e4SLinus Torvalds 				return -EFAULT;
23861da177e4SLinus Torvalds 			buf[len] = 0;
23871da177e4SLinus Torvalds 			p = buf;
23881da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
23891da177e4SLinus Torvalds 				neg = 1;
2390bd9b0bacSBP, Praveen 				p++;
23911da177e4SLinus Torvalds 			}
23921da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
23931da177e4SLinus Torvalds 				break;
23941da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
23951da177e4SLinus Torvalds 			len = p-buf;
23961da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
23971da177e4SLinus Torvalds 				break;
23981da177e4SLinus Torvalds 			if (neg)
23991da177e4SLinus Torvalds 				val = -val;
24001da177e4SLinus Torvalds 			s += len;
24011da177e4SLinus Torvalds 			left -= len;
24021da177e4SLinus Torvalds 
24031da177e4SLinus Torvalds 			if(neg)
24041da177e4SLinus Torvalds 				continue;
24051da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
24061da177e4SLinus Torvalds 				continue;
24071da177e4SLinus Torvalds 			*i = val;
24081da177e4SLinus Torvalds 		} else {
24091da177e4SLinus Torvalds 			p = buf;
24101da177e4SLinus Torvalds 			if (!first)
24111da177e4SLinus Torvalds 				*p++ = '\t';
24121da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
24131da177e4SLinus Torvalds 			len = strlen(buf);
24141da177e4SLinus Torvalds 			if (len > left)
24151da177e4SLinus Torvalds 				len = left;
24161da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
24171da177e4SLinus Torvalds 				return -EFAULT;
24181da177e4SLinus Torvalds 			left -= len;
24191da177e4SLinus Torvalds 			s += len;
24201da177e4SLinus Torvalds 		}
24211da177e4SLinus Torvalds 	}
24221da177e4SLinus Torvalds 
24231da177e4SLinus Torvalds 	if (!write && !first && left) {
24241da177e4SLinus Torvalds 		if(put_user('\n', s))
24251da177e4SLinus Torvalds 			return -EFAULT;
24261da177e4SLinus Torvalds 		left--, s++;
24271da177e4SLinus Torvalds 	}
24281da177e4SLinus Torvalds 	if (write) {
24291da177e4SLinus Torvalds 		while (left) {
24301da177e4SLinus Torvalds 			char c;
24311da177e4SLinus Torvalds 			if (get_user(c, s++))
24321da177e4SLinus Torvalds 				return -EFAULT;
24331da177e4SLinus Torvalds 			if (!isspace(c))
24341da177e4SLinus Torvalds 				break;
24351da177e4SLinus Torvalds 			left--;
24361da177e4SLinus Torvalds 		}
24371da177e4SLinus Torvalds 	}
24381da177e4SLinus Torvalds 	if (write && first)
24391da177e4SLinus Torvalds 		return -EINVAL;
24401da177e4SLinus Torvalds 	*lenp -= left;
24411da177e4SLinus Torvalds 	*ppos += *lenp;
24421da177e4SLinus Torvalds 	return 0;
24431da177e4SLinus Torvalds #undef TMPBUFLEN
24441da177e4SLinus Torvalds }
24451da177e4SLinus Torvalds 
2446d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2447fcfbd547SKirill Korotaev 				     struct file *filp,
2448fcfbd547SKirill Korotaev 				     void __user *buffer,
2449fcfbd547SKirill Korotaev 				     size_t *lenp, loff_t *ppos,
2450fcfbd547SKirill Korotaev 				     unsigned long convmul,
2451fcfbd547SKirill Korotaev 				     unsigned long convdiv)
2452fcfbd547SKirill Korotaev {
2453fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(table->data, table, write,
2454fcfbd547SKirill Korotaev 			filp, buffer, lenp, ppos, convmul, convdiv);
2455fcfbd547SKirill Korotaev }
2456fcfbd547SKirill Korotaev 
24571da177e4SLinus Torvalds /**
24581da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
24591da177e4SLinus Torvalds  * @table: the sysctl table
24601da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
24611da177e4SLinus Torvalds  * @filp: the file structure
24621da177e4SLinus Torvalds  * @buffer: the user buffer
24631da177e4SLinus Torvalds  * @lenp: the size of the user buffer
24641da177e4SLinus Torvalds  * @ppos: file position
24651da177e4SLinus Torvalds  *
24661da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
24671da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
24681da177e4SLinus Torvalds  *
24691da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
24701da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
24711da177e4SLinus Torvalds  *
24721da177e4SLinus Torvalds  * Returns 0 on success.
24731da177e4SLinus Torvalds  */
2474d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
24751da177e4SLinus Torvalds 			   void __user *buffer, size_t *lenp, loff_t *ppos)
24761da177e4SLinus Torvalds {
24771da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
24781da177e4SLinus Torvalds }
24791da177e4SLinus Torvalds 
24801da177e4SLinus Torvalds /**
24811da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
24821da177e4SLinus Torvalds  * @table: the sysctl table
24831da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
24841da177e4SLinus Torvalds  * @filp: the file structure
24851da177e4SLinus Torvalds  * @buffer: the user buffer
24861da177e4SLinus Torvalds  * @lenp: the size of the user buffer
24871da177e4SLinus Torvalds  * @ppos: file position
24881da177e4SLinus Torvalds  *
24891da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
24901da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
24911da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
24921da177e4SLinus Torvalds  *
24931da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
24941da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
24951da177e4SLinus Torvalds  *
24961da177e4SLinus Torvalds  * Returns 0 on success.
24971da177e4SLinus Torvalds  */
2498d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
24991da177e4SLinus Torvalds 				      struct file *filp,
25001da177e4SLinus Torvalds 				      void __user *buffer,
25011da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
25021da177e4SLinus Torvalds {
25031da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer,
25041da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
25051da177e4SLinus Torvalds }
25061da177e4SLinus Torvalds 
25071da177e4SLinus Torvalds 
25081da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
25091da177e4SLinus Torvalds 					 int *valp,
25101da177e4SLinus Torvalds 					 int write, void *data)
25111da177e4SLinus Torvalds {
25121da177e4SLinus Torvalds 	if (write) {
2513cba9f33dSBart Samwel 		if (*lvalp > LONG_MAX / HZ)
2514cba9f33dSBart Samwel 			return 1;
25151da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
25161da177e4SLinus Torvalds 	} else {
25171da177e4SLinus Torvalds 		int val = *valp;
25181da177e4SLinus Torvalds 		unsigned long lval;
25191da177e4SLinus Torvalds 		if (val < 0) {
25201da177e4SLinus Torvalds 			*negp = -1;
25211da177e4SLinus Torvalds 			lval = (unsigned long)-val;
25221da177e4SLinus Torvalds 		} else {
25231da177e4SLinus Torvalds 			*negp = 0;
25241da177e4SLinus Torvalds 			lval = (unsigned long)val;
25251da177e4SLinus Torvalds 		}
25261da177e4SLinus Torvalds 		*lvalp = lval / HZ;
25271da177e4SLinus Torvalds 	}
25281da177e4SLinus Torvalds 	return 0;
25291da177e4SLinus Torvalds }
25301da177e4SLinus Torvalds 
25311da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
25321da177e4SLinus Torvalds 						int *valp,
25331da177e4SLinus Torvalds 						int write, void *data)
25341da177e4SLinus Torvalds {
25351da177e4SLinus Torvalds 	if (write) {
2536cba9f33dSBart Samwel 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2537cba9f33dSBart Samwel 			return 1;
25381da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
25391da177e4SLinus Torvalds 	} else {
25401da177e4SLinus Torvalds 		int val = *valp;
25411da177e4SLinus Torvalds 		unsigned long lval;
25421da177e4SLinus Torvalds 		if (val < 0) {
25431da177e4SLinus Torvalds 			*negp = -1;
25441da177e4SLinus Torvalds 			lval = (unsigned long)-val;
25451da177e4SLinus Torvalds 		} else {
25461da177e4SLinus Torvalds 			*negp = 0;
25471da177e4SLinus Torvalds 			lval = (unsigned long)val;
25481da177e4SLinus Torvalds 		}
25491da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
25501da177e4SLinus Torvalds 	}
25511da177e4SLinus Torvalds 	return 0;
25521da177e4SLinus Torvalds }
25531da177e4SLinus Torvalds 
25541da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
25551da177e4SLinus Torvalds 					    int *valp,
25561da177e4SLinus Torvalds 					    int write, void *data)
25571da177e4SLinus Torvalds {
25581da177e4SLinus Torvalds 	if (write) {
25591da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
25601da177e4SLinus Torvalds 	} else {
25611da177e4SLinus Torvalds 		int val = *valp;
25621da177e4SLinus Torvalds 		unsigned long lval;
25631da177e4SLinus Torvalds 		if (val < 0) {
25641da177e4SLinus Torvalds 			*negp = -1;
25651da177e4SLinus Torvalds 			lval = (unsigned long)-val;
25661da177e4SLinus Torvalds 		} else {
25671da177e4SLinus Torvalds 			*negp = 0;
25681da177e4SLinus Torvalds 			lval = (unsigned long)val;
25691da177e4SLinus Torvalds 		}
25701da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
25711da177e4SLinus Torvalds 	}
25721da177e4SLinus Torvalds 	return 0;
25731da177e4SLinus Torvalds }
25741da177e4SLinus Torvalds 
25751da177e4SLinus Torvalds /**
25761da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
25771da177e4SLinus Torvalds  * @table: the sysctl table
25781da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
25791da177e4SLinus Torvalds  * @filp: the file structure
25801da177e4SLinus Torvalds  * @buffer: the user buffer
25811da177e4SLinus Torvalds  * @lenp: the size of the user buffer
25821da177e4SLinus Torvalds  * @ppos: file position
25831da177e4SLinus Torvalds  *
25841da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
25851da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
25861da177e4SLinus Torvalds  * The values read are assumed to be in seconds, and are converted into
25871da177e4SLinus Torvalds  * jiffies.
25881da177e4SLinus Torvalds  *
25891da177e4SLinus Torvalds  * Returns 0 on success.
25901da177e4SLinus Torvalds  */
2591d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
25921da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
25931da177e4SLinus Torvalds {
25941da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
25951da177e4SLinus Torvalds 		    	    do_proc_dointvec_jiffies_conv,NULL);
25961da177e4SLinus Torvalds }
25971da177e4SLinus Torvalds 
25981da177e4SLinus Torvalds /**
25991da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
26001da177e4SLinus Torvalds  * @table: the sysctl table
26011da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
26021da177e4SLinus Torvalds  * @filp: the file structure
26031da177e4SLinus Torvalds  * @buffer: the user buffer
26041da177e4SLinus Torvalds  * @lenp: the size of the user buffer
26051e5d5331SRandy Dunlap  * @ppos: pointer to the file position
26061da177e4SLinus Torvalds  *
26071da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
26081da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
26091da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
26101da177e4SLinus Torvalds  * are converted into jiffies.
26111da177e4SLinus Torvalds  *
26121da177e4SLinus Torvalds  * Returns 0 on success.
26131da177e4SLinus Torvalds  */
2614d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
26151da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
26161da177e4SLinus Torvalds {
26171da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
26181da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
26191da177e4SLinus Torvalds }
26201da177e4SLinus Torvalds 
26211da177e4SLinus Torvalds /**
26221da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
26231da177e4SLinus Torvalds  * @table: the sysctl table
26241da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
26251da177e4SLinus Torvalds  * @filp: the file structure
26261da177e4SLinus Torvalds  * @buffer: the user buffer
26271da177e4SLinus Torvalds  * @lenp: the size of the user buffer
262867be2dd1SMartin Waitz  * @ppos: file position
262967be2dd1SMartin Waitz  * @ppos: the current position in the file
26301da177e4SLinus Torvalds  *
26311da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
26321da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
26331da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
26341da177e4SLinus Torvalds  * are converted into jiffies.
26351da177e4SLinus Torvalds  *
26361da177e4SLinus Torvalds  * Returns 0 on success.
26371da177e4SLinus Torvalds  */
2638d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
26391da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
26401da177e4SLinus Torvalds {
26411da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
26421da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
26431da177e4SLinus Torvalds }
26441da177e4SLinus Torvalds 
2645d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
26469ec52099SCedric Le Goater 			   void __user *buffer, size_t *lenp, loff_t *ppos)
26479ec52099SCedric Le Goater {
26489ec52099SCedric Le Goater 	struct pid *new_pid;
26499ec52099SCedric Le Goater 	pid_t tmp;
26509ec52099SCedric Le Goater 	int r;
26519ec52099SCedric Le Goater 
26526c5f3e7bSPavel Emelyanov 	tmp = pid_vnr(cad_pid);
26539ec52099SCedric Le Goater 
26549ec52099SCedric Le Goater 	r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
26559ec52099SCedric Le Goater 			       lenp, ppos, NULL, NULL);
26569ec52099SCedric Le Goater 	if (r || !write)
26579ec52099SCedric Le Goater 		return r;
26589ec52099SCedric Le Goater 
26599ec52099SCedric Le Goater 	new_pid = find_get_pid(tmp);
26609ec52099SCedric Le Goater 	if (!new_pid)
26619ec52099SCedric Le Goater 		return -ESRCH;
26629ec52099SCedric Le Goater 
26639ec52099SCedric Le Goater 	put_pid(xchg(&cad_pid, new_pid));
26649ec52099SCedric Le Goater 	return 0;
26659ec52099SCedric Le Goater }
26669ec52099SCedric Le Goater 
26671da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
26681da177e4SLinus Torvalds 
2669d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp,
26701da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
26711da177e4SLinus Torvalds {
26721da177e4SLinus Torvalds 	return -ENOSYS;
26731da177e4SLinus Torvalds }
26741da177e4SLinus Torvalds 
2675d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
26761da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
26771da177e4SLinus Torvalds {
26781da177e4SLinus Torvalds 	return -ENOSYS;
26791da177e4SLinus Torvalds }
26801da177e4SLinus Torvalds 
2681d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
26821da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26831da177e4SLinus Torvalds {
26841da177e4SLinus Torvalds 	return -ENOSYS;
26851da177e4SLinus Torvalds }
26861da177e4SLinus Torvalds 
2687d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
26881da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26891da177e4SLinus Torvalds {
26901da177e4SLinus Torvalds 	return -ENOSYS;
26911da177e4SLinus Torvalds }
26921da177e4SLinus Torvalds 
2693d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
26941da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26951da177e4SLinus Torvalds {
26961da177e4SLinus Torvalds 	return -ENOSYS;
26971da177e4SLinus Torvalds }
26981da177e4SLinus Torvalds 
2699d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
27001da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
27011da177e4SLinus Torvalds {
27021da177e4SLinus Torvalds 	return -ENOSYS;
27031da177e4SLinus Torvalds }
27041da177e4SLinus Torvalds 
2705d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
27061da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
27071da177e4SLinus Torvalds {
27081da177e4SLinus Torvalds 	return -ENOSYS;
27091da177e4SLinus Torvalds }
27101da177e4SLinus Torvalds 
2711d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
27121da177e4SLinus Torvalds 				      struct file *filp,
27131da177e4SLinus Torvalds 				      void __user *buffer,
27141da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
27151da177e4SLinus Torvalds {
27161da177e4SLinus Torvalds     return -ENOSYS;
27171da177e4SLinus Torvalds }
27181da177e4SLinus Torvalds 
27191da177e4SLinus Torvalds 
27201da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
27211da177e4SLinus Torvalds 
27221da177e4SLinus Torvalds 
2723b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
27241da177e4SLinus Torvalds /*
27251da177e4SLinus Torvalds  * General sysctl support routines
27261da177e4SLinus Torvalds  */
27271da177e4SLinus Torvalds 
272849a0c458SEric W. Biederman /* The generic sysctl data routine (used if no strategy routine supplied) */
272949a0c458SEric W. Biederman int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
273049a0c458SEric W. Biederman 		void __user *oldval, size_t __user *oldlenp,
273149a0c458SEric W. Biederman 		void __user *newval, size_t newlen)
273249a0c458SEric W. Biederman {
273349a0c458SEric W. Biederman 	size_t len;
273449a0c458SEric W. Biederman 
273549a0c458SEric W. Biederman 	/* Get out of I don't have a variable */
273649a0c458SEric W. Biederman 	if (!table->data || !table->maxlen)
273749a0c458SEric W. Biederman 		return -ENOTDIR;
273849a0c458SEric W. Biederman 
273949a0c458SEric W. Biederman 	if (oldval && oldlenp) {
274049a0c458SEric W. Biederman 		if (get_user(len, oldlenp))
274149a0c458SEric W. Biederman 			return -EFAULT;
274249a0c458SEric W. Biederman 		if (len) {
274349a0c458SEric W. Biederman 			if (len > table->maxlen)
274449a0c458SEric W. Biederman 				len = table->maxlen;
274549a0c458SEric W. Biederman 			if (copy_to_user(oldval, table->data, len))
274649a0c458SEric W. Biederman 				return -EFAULT;
274749a0c458SEric W. Biederman 			if (put_user(len, oldlenp))
274849a0c458SEric W. Biederman 				return -EFAULT;
274949a0c458SEric W. Biederman 		}
275049a0c458SEric W. Biederman 	}
275149a0c458SEric W. Biederman 
275249a0c458SEric W. Biederman 	if (newval && newlen) {
275349a0c458SEric W. Biederman 		if (newlen > table->maxlen)
275449a0c458SEric W. Biederman 			newlen = table->maxlen;
275549a0c458SEric W. Biederman 
275649a0c458SEric W. Biederman 		if (copy_from_user(table->data, newval, newlen))
275749a0c458SEric W. Biederman 			return -EFAULT;
275849a0c458SEric W. Biederman 	}
275949a0c458SEric W. Biederman 	return 1;
276049a0c458SEric W. Biederman }
276149a0c458SEric W. Biederman 
27621da177e4SLinus Torvalds /* The generic string strategy routine: */
2763d8217f07SEric W. Biederman int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
27641da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
27651f29bcd7SAlexey Dobriyan 		  void __user *newval, size_t newlen)
27661da177e4SLinus Torvalds {
27671da177e4SLinus Torvalds 	if (!table->data || !table->maxlen)
27681da177e4SLinus Torvalds 		return -ENOTDIR;
27691da177e4SLinus Torvalds 
27701da177e4SLinus Torvalds 	if (oldval && oldlenp) {
2771de9e007dSLinus Torvalds 		size_t bufsize;
2772de9e007dSLinus Torvalds 		if (get_user(bufsize, oldlenp))
27731da177e4SLinus Torvalds 			return -EFAULT;
2774de9e007dSLinus Torvalds 		if (bufsize) {
2775de9e007dSLinus Torvalds 			size_t len = strlen(table->data), copied;
2776de9e007dSLinus Torvalds 
2777de9e007dSLinus Torvalds 			/* This shouldn't trigger for a well-formed sysctl */
2778de9e007dSLinus Torvalds 			if (len > table->maxlen)
27791da177e4SLinus Torvalds 				len = table->maxlen;
2780de9e007dSLinus Torvalds 
2781de9e007dSLinus Torvalds 			/* Copy up to a max of bufsize-1 bytes of the string */
2782de9e007dSLinus Torvalds 			copied = (len >= bufsize) ? bufsize - 1 : len;
2783de9e007dSLinus Torvalds 
2784de9e007dSLinus Torvalds 			if (copy_to_user(oldval, table->data, copied) ||
2785de9e007dSLinus Torvalds 			    put_user(0, (char __user *)(oldval + copied)))
27861da177e4SLinus Torvalds 				return -EFAULT;
27871da177e4SLinus Torvalds 			if (put_user(len, oldlenp))
27881da177e4SLinus Torvalds 				return -EFAULT;
27891da177e4SLinus Torvalds 		}
27901da177e4SLinus Torvalds 	}
27911da177e4SLinus Torvalds 	if (newval && newlen) {
2792de9e007dSLinus Torvalds 		size_t len = newlen;
27931da177e4SLinus Torvalds 		if (len > table->maxlen)
27941da177e4SLinus Torvalds 			len = table->maxlen;
27951da177e4SLinus Torvalds 		if(copy_from_user(table->data, newval, len))
27961da177e4SLinus Torvalds 			return -EFAULT;
27971da177e4SLinus Torvalds 		if (len == table->maxlen)
27981da177e4SLinus Torvalds 			len--;
27991da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
28001da177e4SLinus Torvalds 	}
280182c9df82SYi Yang 	return 1;
28021da177e4SLinus Torvalds }
28031da177e4SLinus Torvalds 
28041da177e4SLinus Torvalds /*
28051da177e4SLinus Torvalds  * This function makes sure that all of the integers in the vector
28061da177e4SLinus Torvalds  * are between the minimum and maximum values given in the arrays
28071da177e4SLinus Torvalds  * table->extra1 and table->extra2, respectively.
28081da177e4SLinus Torvalds  */
2809d8217f07SEric W. Biederman int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
28101da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
28111f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
28121da177e4SLinus Torvalds {
28131da177e4SLinus Torvalds 
28141da177e4SLinus Torvalds 	if (newval && newlen) {
28151da177e4SLinus Torvalds 		int __user *vec = (int __user *) newval;
28161da177e4SLinus Torvalds 		int *min = (int *) table->extra1;
28171da177e4SLinus Torvalds 		int *max = (int *) table->extra2;
28181da177e4SLinus Torvalds 		size_t length;
28191da177e4SLinus Torvalds 		int i;
28201da177e4SLinus Torvalds 
28211da177e4SLinus Torvalds 		if (newlen % sizeof(int) != 0)
28221da177e4SLinus Torvalds 			return -EINVAL;
28231da177e4SLinus Torvalds 
28241da177e4SLinus Torvalds 		if (!table->extra1 && !table->extra2)
28251da177e4SLinus Torvalds 			return 0;
28261da177e4SLinus Torvalds 
28271da177e4SLinus Torvalds 		if (newlen > table->maxlen)
28281da177e4SLinus Torvalds 			newlen = table->maxlen;
28291da177e4SLinus Torvalds 		length = newlen / sizeof(int);
28301da177e4SLinus Torvalds 
28311da177e4SLinus Torvalds 		for (i = 0; i < length; i++) {
28321da177e4SLinus Torvalds 			int value;
28331da177e4SLinus Torvalds 			if (get_user(value, vec + i))
28341da177e4SLinus Torvalds 				return -EFAULT;
28351da177e4SLinus Torvalds 			if (min && value < min[i])
28361da177e4SLinus Torvalds 				return -EINVAL;
28371da177e4SLinus Torvalds 			if (max && value > max[i])
28381da177e4SLinus Torvalds 				return -EINVAL;
28391da177e4SLinus Torvalds 		}
28401da177e4SLinus Torvalds 	}
28411da177e4SLinus Torvalds 	return 0;
28421da177e4SLinus Torvalds }
28431da177e4SLinus Torvalds 
28441da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
2845d8217f07SEric W. Biederman int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
28461da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
28471f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
28481da177e4SLinus Torvalds {
28493ee75ac3SAlexey Dobriyan 	if (oldval && oldlenp) {
28501da177e4SLinus Torvalds 		size_t olen;
28513ee75ac3SAlexey Dobriyan 
28521da177e4SLinus Torvalds 		if (get_user(olen, oldlenp))
28531da177e4SLinus Torvalds 			return -EFAULT;
28543ee75ac3SAlexey Dobriyan 		if (olen) {
28553ee75ac3SAlexey Dobriyan 			int val;
28563ee75ac3SAlexey Dobriyan 
28573ee75ac3SAlexey Dobriyan 			if (olen < sizeof(int))
28581da177e4SLinus Torvalds 				return -EINVAL;
28593ee75ac3SAlexey Dobriyan 
28603ee75ac3SAlexey Dobriyan 			val = *(int *)(table->data) / HZ;
28613ee75ac3SAlexey Dobriyan 			if (put_user(val, (int __user *)oldval))
28621da177e4SLinus Torvalds 				return -EFAULT;
28633ee75ac3SAlexey Dobriyan 			if (put_user(sizeof(int), oldlenp))
28643ee75ac3SAlexey Dobriyan 				return -EFAULT;
28653ee75ac3SAlexey Dobriyan 		}
28661da177e4SLinus Torvalds 	}
28671da177e4SLinus Torvalds 	if (newval && newlen) {
28681da177e4SLinus Torvalds 		int new;
28691da177e4SLinus Torvalds 		if (newlen != sizeof(int))
28701da177e4SLinus Torvalds 			return -EINVAL;
28711da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
28721da177e4SLinus Torvalds 			return -EFAULT;
28731da177e4SLinus Torvalds 		*(int *)(table->data) = new*HZ;
28741da177e4SLinus Torvalds 	}
28751da177e4SLinus Torvalds 	return 1;
28761da177e4SLinus Torvalds }
28771da177e4SLinus Torvalds 
28781da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
2879d8217f07SEric W. Biederman int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
28801da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
28811f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
28821da177e4SLinus Torvalds {
28833ee75ac3SAlexey Dobriyan 	if (oldval && oldlenp) {
28841da177e4SLinus Torvalds 		size_t olen;
28853ee75ac3SAlexey Dobriyan 
28861da177e4SLinus Torvalds 		if (get_user(olen, oldlenp))
28871da177e4SLinus Torvalds 			return -EFAULT;
28883ee75ac3SAlexey Dobriyan 		if (olen) {
28893ee75ac3SAlexey Dobriyan 			int val;
28903ee75ac3SAlexey Dobriyan 
28913ee75ac3SAlexey Dobriyan 			if (olen < sizeof(int))
28921da177e4SLinus Torvalds 				return -EINVAL;
28933ee75ac3SAlexey Dobriyan 
28943ee75ac3SAlexey Dobriyan 			val = jiffies_to_msecs(*(int *)(table->data));
28953ee75ac3SAlexey Dobriyan 			if (put_user(val, (int __user *)oldval))
28961da177e4SLinus Torvalds 				return -EFAULT;
28973ee75ac3SAlexey Dobriyan 			if (put_user(sizeof(int), oldlenp))
28983ee75ac3SAlexey Dobriyan 				return -EFAULT;
28993ee75ac3SAlexey Dobriyan 		}
29001da177e4SLinus Torvalds 	}
29011da177e4SLinus Torvalds 	if (newval && newlen) {
29021da177e4SLinus Torvalds 		int new;
29031da177e4SLinus Torvalds 		if (newlen != sizeof(int))
29041da177e4SLinus Torvalds 			return -EINVAL;
29051da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
29061da177e4SLinus Torvalds 			return -EFAULT;
29071da177e4SLinus Torvalds 		*(int *)(table->data) = msecs_to_jiffies(new);
29081da177e4SLinus Torvalds 	}
29091da177e4SLinus Torvalds 	return 1;
29101da177e4SLinus Torvalds }
29111da177e4SLinus Torvalds 
2912c4b8b769SEric W. Biederman 
2913c4b8b769SEric W. Biederman 
2914b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */
29151da177e4SLinus Torvalds 
29161da177e4SLinus Torvalds 
29171da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
29181da177e4SLinus Torvalds {
29190e009be8SEric W. Biederman 	struct __sysctl_args tmp;
29207058cb02SEric W. Biederman 	int error;
29210e009be8SEric W. Biederman 
29220e009be8SEric W. Biederman 	if (copy_from_user(&tmp, args, sizeof(tmp)))
29230e009be8SEric W. Biederman 		return -EFAULT;
29240e009be8SEric W. Biederman 
29257058cb02SEric W. Biederman 	error = deprecated_sysctl_warning(&tmp);
2926b89a8171SEric W. Biederman 
29277058cb02SEric W. Biederman 	/* If no error reading the parameters then just -ENOSYS ... */
29287058cb02SEric W. Biederman 	if (!error)
29297058cb02SEric W. Biederman 		error = -ENOSYS;
29307058cb02SEric W. Biederman 
29317058cb02SEric W. Biederman 	return error;
29321da177e4SLinus Torvalds }
29331da177e4SLinus Torvalds 
293449a0c458SEric W. Biederman int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
293549a0c458SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
293649a0c458SEric W. Biederman 		  void __user *newval, size_t newlen)
293749a0c458SEric W. Biederman {
293849a0c458SEric W. Biederman 	return -ENOSYS;
293949a0c458SEric W. Biederman }
294049a0c458SEric W. Biederman 
2941d8217f07SEric W. Biederman int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
29421da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
29431f29bcd7SAlexey Dobriyan 		  void __user *newval, size_t newlen)
29441da177e4SLinus Torvalds {
29451da177e4SLinus Torvalds 	return -ENOSYS;
29461da177e4SLinus Torvalds }
29471da177e4SLinus Torvalds 
2948d8217f07SEric W. Biederman int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
29491da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29501f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29511da177e4SLinus Torvalds {
29521da177e4SLinus Torvalds 	return -ENOSYS;
29531da177e4SLinus Torvalds }
29541da177e4SLinus Torvalds 
2955d8217f07SEric W. Biederman int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
29561da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29571f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29581da177e4SLinus Torvalds {
29591da177e4SLinus Torvalds 	return -ENOSYS;
29601da177e4SLinus Torvalds }
29611da177e4SLinus Torvalds 
2962d8217f07SEric W. Biederman int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
29631da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29641f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29651da177e4SLinus Torvalds {
29661da177e4SLinus Torvalds 	return -ENOSYS;
29671da177e4SLinus Torvalds }
29681da177e4SLinus Torvalds 
2969b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
29701da177e4SLinus Torvalds 
29717058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args)
29727058cb02SEric W. Biederman {
29737058cb02SEric W. Biederman 	static int msg_count;
29747058cb02SEric W. Biederman 	int name[CTL_MAXNAME];
29757058cb02SEric W. Biederman 	int i;
29767058cb02SEric W. Biederman 
29776fc48af8STetsuo Handa 	/* Check args->nlen. */
29786fc48af8STetsuo Handa 	if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
29796fc48af8STetsuo Handa 		return -ENOTDIR;
29806fc48af8STetsuo Handa 
29817058cb02SEric W. Biederman 	/* Read in the sysctl name for better debug message logging */
29827058cb02SEric W. Biederman 	for (i = 0; i < args->nlen; i++)
29837058cb02SEric W. Biederman 		if (get_user(name[i], args->name + i))
29847058cb02SEric W. Biederman 			return -EFAULT;
29857058cb02SEric W. Biederman 
29867058cb02SEric W. Biederman 	/* Ignore accesses to kernel.version */
29877058cb02SEric W. Biederman 	if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
29887058cb02SEric W. Biederman 		return 0;
29897058cb02SEric W. Biederman 
29907058cb02SEric W. Biederman 	if (msg_count < 5) {
29917058cb02SEric W. Biederman 		msg_count++;
29927058cb02SEric W. Biederman 		printk(KERN_INFO
29937058cb02SEric W. Biederman 			"warning: process `%s' used the deprecated sysctl "
29947058cb02SEric W. Biederman 			"system call with ", current->comm);
29957058cb02SEric W. Biederman 		for (i = 0; i < args->nlen; i++)
29967058cb02SEric W. Biederman 			printk("%d.", name[i]);
29977058cb02SEric W. Biederman 		printk("\n");
29987058cb02SEric W. Biederman 	}
29997058cb02SEric W. Biederman 	return 0;
30007058cb02SEric W. Biederman }
30017058cb02SEric W. Biederman 
30021da177e4SLinus Torvalds /*
30031da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
30041da177e4SLinus Torvalds  * exception granted :-)
30051da177e4SLinus Torvalds  */
30061da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
30071da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
30081da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
30091da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
30101da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
30111da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
30121da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
30131da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
30141da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
301529e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths);
30161da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec);
30171da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies);
30181da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies);
30191da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string);
302049a0c458SEric W. Biederman EXPORT_SYMBOL(sysctl_data);
30211da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
3022