xref: /openbmc/linux/kernel/sysctl.c (revision c5078f78b455fbf67ea71442c7e7ca8acf9ff095)
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>
5112e22c5eSDavid Howells #include <linux/slow-work.h>
521ccd1549SPeter Zijlstra #include <linux/perf_counter.h>
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds #include <asm/uaccess.h>
551da177e4SLinus Torvalds #include <asm/processor.h>
561da177e4SLinus Torvalds 
5729cbc78bSAndi Kleen #ifdef CONFIG_X86
5829cbc78bSAndi Kleen #include <asm/nmi.h>
590741f4d2SChuck Ebbert #include <asm/stacktrace.h>
606e7c4025SIngo Molnar #include <asm/io.h>
6129cbc78bSAndi Kleen #endif
6229cbc78bSAndi Kleen 
637058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args);
647058cb02SEric W. Biederman 
651da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds /* External variables not in a header file. */
681da177e4SLinus Torvalds extern int C_A_D;
6945807a1dSIngo Molnar extern int print_fatal_signals;
701da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
711da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
72fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom;
73fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task;
74fef1bdd6SDavid Rientjes extern int sysctl_oom_dump_tasks;
751da177e4SLinus Torvalds extern int max_threads;
761da177e4SLinus Torvalds extern int core_uses_pid;
77d6e71144SAlan Cox extern int suid_dumpable;
781da177e4SLinus Torvalds extern char core_pattern[];
791da177e4SLinus Torvalds extern int pid_max;
801da177e4SLinus Torvalds extern int min_free_kbytes;
811da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
829d0243bcSAndrew Morton extern int sysctl_drop_caches;
838ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
84bebfa101SAndi Kleen extern int compat_log;
859745512cSArjan van de Ven extern int latencytop_enabled;
86eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max;
87dd8632a1SPaul Mundt #ifndef CONFIG_MMU
88dd8632a1SPaul Mundt extern int sysctl_nr_trim_pages;
89dd8632a1SPaul Mundt #endif
9031a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
9131a72bceSPaul E. McKenney extern int rcutorture_runnable;
9231a72bceSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
931da177e4SLinus Torvalds 
94c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
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 static int zero;
101cd5f9a4cSLinus Torvalds static int __maybe_unused one = 1;
102cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2;
103fc3501d4SSven Wegener static unsigned long one_ul = 1;
104c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100;
105fafd688eSPeter W Morreale static int one_thousand = 1000;
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 
12172c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
12217f04fbbSDavid S. Miller #include <asm/system.h>
1231da177e4SLinus Torvalds #endif
1241da177e4SLinus Torvalds 
1250871420fSDavid S. Miller #ifdef CONFIG_SPARC64
1260871420fSDavid S. Miller extern int sysctl_tsb_ratio;
1270871420fSDavid S. Miller #endif
1280871420fSDavid S. Miller 
1291da177e4SLinus Torvalds #ifdef __hppa__
1301da177e4SLinus Torvalds extern int pwrsw_enabled;
1311da177e4SLinus Torvalds extern int unaligned_enabled;
1321da177e4SLinus Torvalds #endif
1331da177e4SLinus Torvalds 
134347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1351da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1361da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1371da177e4SLinus Torvalds #endif
1381da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
139951f22d5SMartin Schwidefsky extern int spin_retry;
1401da177e4SLinus Torvalds #endif
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
1431da177e4SLinus Torvalds extern int acct_parm[];
1441da177e4SLinus Torvalds #endif
1451da177e4SLinus Torvalds 
146d2b176edSJes Sorensen #ifdef CONFIG_IA64
147d2b176edSJes Sorensen extern int no_unaligned_warning;
14888fc241fSDoug Chapman extern int unaligned_dump_stack;
149d2b176edSJes Sorensen #endif
150d2b176edSJes Sorensen 
15123f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
15223f78d4aSIngo Molnar extern int max_lock_depth;
15323f78d4aSIngo Molnar #endif
15423f78d4aSIngo Molnar 
155d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
156d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
1579ec52099SCedric Le Goater 		  void __user *buffer, size_t *lenp, loff_t *ppos);
15825ddbb18SAndi Kleen static int proc_taint(struct ctl_table *table, int write, struct file *filp,
15934f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos);
160d6f8ff73SRandy Dunlap #endif
1619ec52099SCedric Le Goater 
162d8217f07SEric W. Biederman static struct ctl_table root_table[];
163e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root;
164e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = {
165b380b0d4SAl Viro 	.count = 1,
166e51b6ba0SEric W. Biederman 	.ctl_table = root_table,
16773455092SAl Viro 	.ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
168e51b6ba0SEric W. Biederman 	.root = &sysctl_table_root,
16973455092SAl Viro 	.set = &sysctl_table_root.default_set,
170e51b6ba0SEric W. Biederman };
171e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = {
172e51b6ba0SEric W. Biederman 	.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
17373455092SAl Viro 	.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
174e51b6ba0SEric W. Biederman };
1751da177e4SLinus Torvalds 
176d8217f07SEric W. Biederman static struct ctl_table kern_table[];
177d8217f07SEric W. Biederman static struct ctl_table vm_table[];
178d8217f07SEric W. Biederman static struct ctl_table fs_table[];
179d8217f07SEric W. Biederman static struct ctl_table debug_table[];
180d8217f07SEric W. Biederman static struct ctl_table dev_table[];
181d8217f07SEric W. Biederman extern struct ctl_table random_table[];
1822d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
183d8217f07SEric W. Biederman extern struct ctl_table inotify_table[];
1840399cb08SRobert Love #endif
1857ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
1867ef9964eSDavide Libenzi extern struct ctl_table epoll_table[];
1877ef9964eSDavide Libenzi #endif
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1901da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1911da177e4SLinus Torvalds #endif
1921da177e4SLinus Torvalds 
193f20786ffSPeter Zijlstra extern int prove_locking;
194f20786ffSPeter Zijlstra extern int lock_stat;
1959bc9a6bdSEric W. Biederman 
1961da177e4SLinus Torvalds /* The default sysctl tables: */
1971da177e4SLinus Torvalds 
198d8217f07SEric W. Biederman static struct ctl_table root_table[] = {
1991da177e4SLinus Torvalds 	{
2001da177e4SLinus Torvalds 		.ctl_name	= CTL_KERN,
2011da177e4SLinus Torvalds 		.procname	= "kernel",
2021da177e4SLinus Torvalds 		.mode		= 0555,
2031da177e4SLinus Torvalds 		.child		= kern_table,
2041da177e4SLinus Torvalds 	},
2051da177e4SLinus Torvalds 	{
2061da177e4SLinus Torvalds 		.ctl_name	= CTL_VM,
2071da177e4SLinus Torvalds 		.procname	= "vm",
2081da177e4SLinus Torvalds 		.mode		= 0555,
2091da177e4SLinus Torvalds 		.child		= vm_table,
2101da177e4SLinus Torvalds 	},
2111da177e4SLinus Torvalds 	{
2121da177e4SLinus Torvalds 		.ctl_name	= CTL_FS,
2131da177e4SLinus Torvalds 		.procname	= "fs",
2141da177e4SLinus Torvalds 		.mode		= 0555,
2151da177e4SLinus Torvalds 		.child		= fs_table,
2161da177e4SLinus Torvalds 	},
2171da177e4SLinus Torvalds 	{
2181da177e4SLinus Torvalds 		.ctl_name	= CTL_DEBUG,
2191da177e4SLinus Torvalds 		.procname	= "debug",
2201da177e4SLinus Torvalds 		.mode		= 0555,
2211da177e4SLinus Torvalds 		.child		= debug_table,
2221da177e4SLinus Torvalds 	},
2231da177e4SLinus Torvalds 	{
2241da177e4SLinus Torvalds 		.ctl_name	= CTL_DEV,
2251da177e4SLinus Torvalds 		.procname	= "dev",
2261da177e4SLinus Torvalds 		.mode		= 0555,
2271da177e4SLinus Torvalds 		.child		= dev_table,
2281da177e4SLinus Torvalds 	},
2292be7fe07SAndrew Morton /*
2302be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
2312be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
2322be7fe07SAndrew Morton  */
2331da177e4SLinus Torvalds 	{ .ctl_name = 0 }
2341da177e4SLinus Torvalds };
2351da177e4SLinus Torvalds 
23677e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
23773c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000;		/* 100 usecs */
23873c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
23973c4efd2SEric Dumazet static int min_wakeup_granularity_ns;			/* 0 usecs */
24073c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
24177e54a1fSIngo Molnar #endif
24277e54a1fSIngo Molnar 
243d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
24477e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
24577e54a1fSIngo Molnar 	{
24677e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
247b2be5e96SPeter Zijlstra 		.procname	= "sched_min_granularity_ns",
248b2be5e96SPeter Zijlstra 		.data		= &sysctl_sched_min_granularity,
24977e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
25077e54a1fSIngo Molnar 		.mode		= 0644,
251b2be5e96SPeter Zijlstra 		.proc_handler	= &sched_nr_latency_handler,
252b2be5e96SPeter Zijlstra 		.strategy	= &sysctl_intvec,
253b2be5e96SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
254b2be5e96SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
25577e54a1fSIngo Molnar 	},
25677e54a1fSIngo Molnar 	{
25777e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
25821805085SPeter Zijlstra 		.procname	= "sched_latency_ns",
25921805085SPeter Zijlstra 		.data		= &sysctl_sched_latency,
26021805085SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
26121805085SPeter Zijlstra 		.mode		= 0644,
262b2be5e96SPeter Zijlstra 		.proc_handler	= &sched_nr_latency_handler,
26321805085SPeter Zijlstra 		.strategy	= &sysctl_intvec,
26421805085SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
26521805085SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
26621805085SPeter Zijlstra 	},
26721805085SPeter Zijlstra 	{
26821805085SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
26977e54a1fSIngo Molnar 		.procname	= "sched_wakeup_granularity_ns",
27077e54a1fSIngo Molnar 		.data		= &sysctl_sched_wakeup_granularity,
27177e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
27277e54a1fSIngo Molnar 		.mode		= 0644,
27377e54a1fSIngo Molnar 		.proc_handler	= &proc_dointvec_minmax,
27477e54a1fSIngo Molnar 		.strategy	= &sysctl_intvec,
27577e54a1fSIngo Molnar 		.extra1		= &min_wakeup_granularity_ns,
27677e54a1fSIngo Molnar 		.extra2		= &max_wakeup_granularity_ns,
27777e54a1fSIngo Molnar 	},
27877e54a1fSIngo Molnar 	{
27977e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
2802398f2c6SPeter Zijlstra 		.procname	= "sched_shares_ratelimit",
2812398f2c6SPeter Zijlstra 		.data		= &sysctl_sched_shares_ratelimit,
2822398f2c6SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
2832398f2c6SPeter Zijlstra 		.mode		= 0644,
2842398f2c6SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
2852398f2c6SPeter Zijlstra 	},
2862398f2c6SPeter Zijlstra 	{
2872398f2c6SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
288ffda12a1SPeter Zijlstra 		.procname	= "sched_shares_thresh",
289ffda12a1SPeter Zijlstra 		.data		= &sysctl_sched_shares_thresh,
290ffda12a1SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
291ffda12a1SPeter Zijlstra 		.mode		= 0644,
292ffda12a1SPeter Zijlstra 		.proc_handler	= &proc_dointvec_minmax,
293ffda12a1SPeter Zijlstra 		.strategy	= &sysctl_intvec,
294ffda12a1SPeter Zijlstra 		.extra1		= &zero,
295ffda12a1SPeter Zijlstra 	},
296ffda12a1SPeter Zijlstra 	{
297ffda12a1SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
29877e54a1fSIngo Molnar 		.procname	= "sched_child_runs_first",
29977e54a1fSIngo Molnar 		.data		= &sysctl_sched_child_runs_first,
30077e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
30177e54a1fSIngo Molnar 		.mode		= 0644,
30277e54a1fSIngo Molnar 		.proc_handler	= &proc_dointvec,
30377e54a1fSIngo Molnar 	},
3041fc84aaaSPeter Zijlstra 	{
3051fc84aaaSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3061fc84aaaSPeter Zijlstra 		.procname	= "sched_features",
3071fc84aaaSPeter Zijlstra 		.data		= &sysctl_sched_features,
3081fc84aaaSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
3091fc84aaaSPeter Zijlstra 		.mode		= 0644,
3101fc84aaaSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
3111fc84aaaSPeter Zijlstra 	},
312da84d961SIngo Molnar 	{
313da84d961SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
314da84d961SIngo Molnar 		.procname	= "sched_migration_cost",
315da84d961SIngo Molnar 		.data		= &sysctl_sched_migration_cost,
316da84d961SIngo Molnar 		.maxlen		= sizeof(unsigned int),
317da84d961SIngo Molnar 		.mode		= 0644,
318da84d961SIngo Molnar 		.proc_handler	= &proc_dointvec,
319da84d961SIngo Molnar 	},
320b82d9fddSPeter Zijlstra 	{
321b82d9fddSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
322b82d9fddSPeter Zijlstra 		.procname	= "sched_nr_migrate",
323b82d9fddSPeter Zijlstra 		.data		= &sysctl_sched_nr_migrate,
324b82d9fddSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
325fa85ae24SPeter Zijlstra 		.mode		= 0644,
326fa85ae24SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
327fa85ae24SPeter Zijlstra 	},
3281fc84aaaSPeter Zijlstra #endif
3291799e35dSIngo Molnar 	{
3301799e35dSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
3319f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
3329f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
3339f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
3349f0c1e56SPeter Zijlstra 		.mode		= 0644,
335d0b27fa7SPeter Zijlstra 		.proc_handler	= &sched_rt_handler,
3369f0c1e56SPeter Zijlstra 	},
3379f0c1e56SPeter Zijlstra 	{
3389f0c1e56SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3399f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
3409f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
3419f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
3429f0c1e56SPeter Zijlstra 		.mode		= 0644,
343d0b27fa7SPeter Zijlstra 		.proc_handler	= &sched_rt_handler,
3449f0c1e56SPeter Zijlstra 	},
3459f0c1e56SPeter Zijlstra 	{
3469f0c1e56SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3471799e35dSIngo Molnar 		.procname	= "sched_compat_yield",
3481799e35dSIngo Molnar 		.data		= &sysctl_sched_compat_yield,
3491799e35dSIngo Molnar 		.maxlen		= sizeof(unsigned int),
3501799e35dSIngo Molnar 		.mode		= 0644,
3511799e35dSIngo Molnar 		.proc_handler	= &proc_dointvec,
3521799e35dSIngo Molnar 	},
353f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
354f20786ffSPeter Zijlstra 	{
355f20786ffSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
356f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
357f20786ffSPeter Zijlstra 		.data		= &prove_locking,
358f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
359f20786ffSPeter Zijlstra 		.mode		= 0644,
360f20786ffSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
361f20786ffSPeter Zijlstra 	},
362f20786ffSPeter Zijlstra #endif
363f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
364f20786ffSPeter Zijlstra 	{
365f20786ffSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
366f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
367f20786ffSPeter Zijlstra 		.data		= &lock_stat,
368f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
369f20786ffSPeter Zijlstra 		.mode		= 0644,
370f20786ffSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
371f20786ffSPeter Zijlstra 	},
372f20786ffSPeter Zijlstra #endif
37377e54a1fSIngo Molnar 	{
3741da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC,
3751da177e4SLinus Torvalds 		.procname	= "panic",
3761da177e4SLinus Torvalds 		.data		= &panic_timeout,
3771da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3781da177e4SLinus Torvalds 		.mode		= 0644,
3791da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3801da177e4SLinus Torvalds 	},
3811da177e4SLinus Torvalds 	{
3821da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_USES_PID,
3831da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
3841da177e4SLinus Torvalds 		.data		= &core_uses_pid,
3851da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3861da177e4SLinus Torvalds 		.mode		= 0644,
3871da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3881da177e4SLinus Torvalds 	},
3891da177e4SLinus Torvalds 	{
3901da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_PATTERN,
3911da177e4SLinus Torvalds 		.procname	= "core_pattern",
3921da177e4SLinus Torvalds 		.data		= core_pattern,
39371ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
3941da177e4SLinus Torvalds 		.mode		= 0644,
3951da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3961da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3971da177e4SLinus Torvalds 	},
39834f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
3991da177e4SLinus Torvalds 	{
4001da177e4SLinus Torvalds 		.procname	= "tainted",
40125ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
40234f5a398STheodore Ts'o 		.mode		= 0644,
40325ddbb18SAndi Kleen 		.proc_handler	= &proc_taint,
4041da177e4SLinus Torvalds 	},
40534f5a398STheodore Ts'o #endif
4069745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
4079745512cSArjan van de Ven 	{
4089745512cSArjan van de Ven 		.procname	= "latencytop",
4099745512cSArjan van de Ven 		.data		= &latencytop_enabled,
4109745512cSArjan van de Ven 		.maxlen		= sizeof(int),
4119745512cSArjan van de Ven 		.mode		= 0644,
4129745512cSArjan van de Ven 		.proc_handler	= &proc_dointvec,
4139745512cSArjan van de Ven 	},
4149745512cSArjan van de Ven #endif
4151da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
4161da177e4SLinus Torvalds 	{
4171da177e4SLinus Torvalds 		.ctl_name	= KERN_REALROOTDEV,
4181da177e4SLinus Torvalds 		.procname	= "real-root-dev",
4191da177e4SLinus Torvalds 		.data		= &real_root_dev,
4201da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4211da177e4SLinus Torvalds 		.mode		= 0644,
4221da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4231da177e4SLinus Torvalds 	},
4241da177e4SLinus Torvalds #endif
42545807a1dSIngo Molnar 	{
42645807a1dSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
42745807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
42845807a1dSIngo Molnar 		.data		= &print_fatal_signals,
42945807a1dSIngo Molnar 		.maxlen		= sizeof(int),
43045807a1dSIngo Molnar 		.mode		= 0644,
43145807a1dSIngo Molnar 		.proc_handler	= &proc_dointvec,
43245807a1dSIngo Molnar 	},
43372c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
4341da177e4SLinus Torvalds 	{
4351da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_REBOOT,
4361da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
4371da177e4SLinus Torvalds 		.data		= reboot_command,
4381da177e4SLinus Torvalds 		.maxlen		= 256,
4391da177e4SLinus Torvalds 		.mode		= 0644,
4401da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4411da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4421da177e4SLinus Torvalds 	},
4431da177e4SLinus Torvalds 	{
4441da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_STOP_A,
4451da177e4SLinus Torvalds 		.procname	= "stop-a",
4461da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
4471da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4481da177e4SLinus Torvalds 		.mode		= 0644,
4491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4501da177e4SLinus Torvalds 	},
4511da177e4SLinus Torvalds 	{
4521da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
4531da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
4541da177e4SLinus Torvalds 		.data		= &scons_pwroff,
4551da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4561da177e4SLinus Torvalds 		.mode		= 0644,
4571da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4581da177e4SLinus Torvalds 	},
4591da177e4SLinus Torvalds #endif
4600871420fSDavid S. Miller #ifdef CONFIG_SPARC64
4610871420fSDavid S. Miller 	{
4620871420fSDavid S. Miller 		.ctl_name	= CTL_UNNUMBERED,
4630871420fSDavid S. Miller 		.procname	= "tsb-ratio",
4640871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
4650871420fSDavid S. Miller 		.maxlen		= sizeof (int),
4660871420fSDavid S. Miller 		.mode		= 0644,
4670871420fSDavid S. Miller 		.proc_handler	= &proc_dointvec,
4680871420fSDavid S. Miller 	},
4690871420fSDavid S. Miller #endif
4701da177e4SLinus Torvalds #ifdef __hppa__
4711da177e4SLinus Torvalds 	{
4721da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_PWRSW,
4731da177e4SLinus Torvalds 		.procname	= "soft-power",
4741da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
4751da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4761da177e4SLinus Torvalds 	 	.mode		= 0644,
4771da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4781da177e4SLinus Torvalds 	},
4791da177e4SLinus Torvalds 	{
4801da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_UNALIGNED,
4811da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
4821da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
4831da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4841da177e4SLinus Torvalds 		.mode		= 0644,
4851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4861da177e4SLinus Torvalds 	},
4871da177e4SLinus Torvalds #endif
4881da177e4SLinus Torvalds 	{
4891da177e4SLinus Torvalds 		.ctl_name	= KERN_CTLALTDEL,
4901da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
4911da177e4SLinus Torvalds 		.data		= &C_A_D,
4921da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4931da177e4SLinus Torvalds 		.mode		= 0644,
4941da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4951da177e4SLinus Torvalds 	},
496606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER
497b0fc494fSSteven Rostedt 	{
498b0fc494fSSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
499b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
500b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
501b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
502b0fc494fSSteven Rostedt 		.mode		= 0644,
503b0fc494fSSteven Rostedt 		.proc_handler	= &ftrace_enable_sysctl,
504b0fc494fSSteven Rostedt 	},
505b0fc494fSSteven Rostedt #endif
506f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
507f38f1d2aSSteven Rostedt 	{
508f38f1d2aSSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
509f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
510f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
511f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
512f38f1d2aSSteven Rostedt 		.mode		= 0644,
513f38f1d2aSSteven Rostedt 		.proc_handler	= &stack_trace_sysctl,
514f38f1d2aSSteven Rostedt 	},
515f38f1d2aSSteven Rostedt #endif
516944ac425SSteven Rostedt #ifdef CONFIG_TRACING
517944ac425SSteven Rostedt 	{
518944ac425SSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
5193299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
520944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
521944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
522944ac425SSteven Rostedt 		.mode		= 0644,
523944ac425SSteven Rostedt 		.proc_handler	= &proc_dointvec,
524944ac425SSteven Rostedt 	},
525944ac425SSteven Rostedt #endif
526a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
5271da177e4SLinus Torvalds 	{
5281da177e4SLinus Torvalds 		.ctl_name	= KERN_MODPROBE,
5291da177e4SLinus Torvalds 		.procname	= "modprobe",
5301da177e4SLinus Torvalds 		.data		= &modprobe_path,
5311da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
5321da177e4SLinus Torvalds 		.mode		= 0644,
5331da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
5341da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
5351da177e4SLinus Torvalds 	},
5361da177e4SLinus Torvalds #endif
53757ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
5381da177e4SLinus Torvalds 	{
5391da177e4SLinus Torvalds 		.ctl_name	= KERN_HOTPLUG,
5401da177e4SLinus Torvalds 		.procname	= "hotplug",
541312c004dSKay Sievers 		.data		= &uevent_helper,
542312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
5431da177e4SLinus Torvalds 		.mode		= 0644,
5441da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
5451da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
5461da177e4SLinus Torvalds 	},
5471da177e4SLinus Torvalds #endif
5481da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
5491da177e4SLinus Torvalds 	{
5501da177e4SLinus Torvalds 		.ctl_name	= KERN_SG_BIG_BUFF,
5511da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
5521da177e4SLinus Torvalds 		.data		= &sg_big_buff,
5531da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5541da177e4SLinus Torvalds 		.mode		= 0444,
5551da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5561da177e4SLinus Torvalds 	},
5571da177e4SLinus Torvalds #endif
5581da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
5591da177e4SLinus Torvalds 	{
5601da177e4SLinus Torvalds 		.ctl_name	= KERN_ACCT,
5611da177e4SLinus Torvalds 		.procname	= "acct",
5621da177e4SLinus Torvalds 		.data		= &acct_parm,
5631da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
5641da177e4SLinus Torvalds 		.mode		= 0644,
5651da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5661da177e4SLinus Torvalds 	},
5671da177e4SLinus Torvalds #endif
5681da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
5691da177e4SLinus Torvalds 	{
5701da177e4SLinus Torvalds 		.ctl_name	= KERN_SYSRQ,
5711da177e4SLinus Torvalds 		.procname	= "sysrq",
5725d6f647fSIngo Molnar 		.data		= &__sysrq_enabled,
5731da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5741da177e4SLinus Torvalds 		.mode		= 0644,
5751da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5761da177e4SLinus Torvalds 	},
5771da177e4SLinus Torvalds #endif
578d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
5791da177e4SLinus Torvalds 	{
5801da177e4SLinus Torvalds 		.procname	= "cad_pid",
5819ec52099SCedric Le Goater 		.data		= NULL,
5821da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5831da177e4SLinus Torvalds 		.mode		= 0600,
5849ec52099SCedric Le Goater 		.proc_handler	= &proc_do_cad_pid,
5851da177e4SLinus Torvalds 	},
586d6f8ff73SRandy Dunlap #endif
5871da177e4SLinus Torvalds 	{
5881da177e4SLinus Torvalds 		.ctl_name	= KERN_MAX_THREADS,
5891da177e4SLinus Torvalds 		.procname	= "threads-max",
5901da177e4SLinus Torvalds 		.data		= &max_threads,
5911da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5921da177e4SLinus Torvalds 		.mode		= 0644,
5931da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5941da177e4SLinus Torvalds 	},
5951da177e4SLinus Torvalds 	{
5961da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOM,
5971da177e4SLinus Torvalds 		.procname	= "random",
5981da177e4SLinus Torvalds 		.mode		= 0555,
5991da177e4SLinus Torvalds 		.child		= random_table,
6001da177e4SLinus Torvalds 	},
6011da177e4SLinus Torvalds 	{
6021da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWUID,
6031da177e4SLinus Torvalds 		.procname	= "overflowuid",
6041da177e4SLinus Torvalds 		.data		= &overflowuid,
6051da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6061da177e4SLinus Torvalds 		.mode		= 0644,
6071da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6081da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
6091da177e4SLinus Torvalds 		.extra1		= &minolduid,
6101da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6111da177e4SLinus Torvalds 	},
6121da177e4SLinus Torvalds 	{
6131da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWGID,
6141da177e4SLinus Torvalds 		.procname	= "overflowgid",
6151da177e4SLinus Torvalds 		.data		= &overflowgid,
6161da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6171da177e4SLinus Torvalds 		.mode		= 0644,
6181da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6191da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
6201da177e4SLinus Torvalds 		.extra1		= &minolduid,
6211da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6221da177e4SLinus Torvalds 	},
623347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
6241da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
6251da177e4SLinus Torvalds 	{
6261da177e4SLinus Torvalds 		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
6271da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
6281da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
6291da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6301da177e4SLinus Torvalds 		.mode		= 0644,
6311da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6321da177e4SLinus Torvalds 	},
6331da177e4SLinus Torvalds #endif
6341da177e4SLinus Torvalds 	{
6351da177e4SLinus Torvalds 		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
6361da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
6371da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
6381da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6391da177e4SLinus Torvalds 		.mode		= 0644,
6401da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6411da177e4SLinus Torvalds 	},
6421da177e4SLinus Torvalds #endif
6431da177e4SLinus Torvalds 	{
6441da177e4SLinus Torvalds 		.ctl_name	= KERN_PIDMAX,
6451da177e4SLinus Torvalds 		.procname	= "pid_max",
6461da177e4SLinus Torvalds 		.data		= &pid_max,
6471da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6481da177e4SLinus Torvalds 		.mode		= 0644,
6491da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6501da177e4SLinus Torvalds 		.strategy	= sysctl_intvec,
6511da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
6521da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
6531da177e4SLinus Torvalds 	},
6541da177e4SLinus Torvalds 	{
6551da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC_ON_OOPS,
6561da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
6571da177e4SLinus Torvalds 		.data		= &panic_on_oops,
6581da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6591da177e4SLinus Torvalds 		.mode		= 0644,
6601da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6611da177e4SLinus Torvalds 	},
6627ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
6637ef3d2fdSJoe Perches 	{
6647ef3d2fdSJoe Perches 		.ctl_name	= KERN_PRINTK,
6657ef3d2fdSJoe Perches 		.procname	= "printk",
6667ef3d2fdSJoe Perches 		.data		= &console_loglevel,
6677ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
6687ef3d2fdSJoe Perches 		.mode		= 0644,
6697ef3d2fdSJoe Perches 		.proc_handler	= &proc_dointvec,
6707ef3d2fdSJoe Perches 	},
6711da177e4SLinus Torvalds 	{
6721da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT,
6731da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
674717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
6751da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6761da177e4SLinus Torvalds 		.mode		= 0644,
6771da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
6781da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
6791da177e4SLinus Torvalds 	},
6801da177e4SLinus Torvalds 	{
6811da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
6821da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
683717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
6841da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6851da177e4SLinus Torvalds 		.mode		= 0644,
6861da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6871da177e4SLinus Torvalds 	},
6887ef3d2fdSJoe Perches #endif
6891da177e4SLinus Torvalds 	{
6901da177e4SLinus Torvalds 		.ctl_name	= KERN_NGROUPS_MAX,
6911da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6921da177e4SLinus Torvalds 		.data		= &ngroups_max,
6931da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6941da177e4SLinus Torvalds 		.mode		= 0444,
6951da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6961da177e4SLinus Torvalds 	},
6971da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6981da177e4SLinus Torvalds 	{
6991da177e4SLinus Torvalds 		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
7001da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
7011da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
7021da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
7031da177e4SLinus Torvalds 		.mode           = 0644,
7042fbe7b25SDon Zickus 		.proc_handler   = &proc_dointvec,
7051da177e4SLinus Torvalds 	},
706407984f1SDon Zickus 	{
707407984f1SDon Zickus 		.procname       = "nmi_watchdog",
708407984f1SDon Zickus 		.data           = &nmi_watchdog_enabled,
709407984f1SDon Zickus 		.maxlen         = sizeof (int),
710407984f1SDon Zickus 		.mode           = 0644,
711407984f1SDon Zickus 		.proc_handler   = &proc_nmi_enabled,
7121da177e4SLinus Torvalds 	},
7131da177e4SLinus Torvalds #endif
7141da177e4SLinus Torvalds #if defined(CONFIG_X86)
7151da177e4SLinus Torvalds 	{
7168da5addaSDon Zickus 		.ctl_name	= KERN_PANIC_ON_NMI,
7178da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
7188da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
7198da5addaSDon Zickus 		.maxlen		= sizeof(int),
7208da5addaSDon Zickus 		.mode		= 0644,
7218da5addaSDon Zickus 		.proc_handler	= &proc_dointvec,
7228da5addaSDon Zickus 	},
7238da5addaSDon Zickus 	{
7241da177e4SLinus Torvalds 		.ctl_name	= KERN_BOOTLOADER_TYPE,
7251da177e4SLinus Torvalds 		.procname	= "bootloader_type",
7261da177e4SLinus Torvalds 		.data		= &bootloader_type,
7271da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
7281da177e4SLinus Torvalds 		.mode		= 0444,
7291da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7301da177e4SLinus Torvalds 	},
7310741f4d2SChuck Ebbert 	{
7320741f4d2SChuck Ebbert 		.ctl_name	= CTL_UNNUMBERED,
7330741f4d2SChuck Ebbert 		.procname	= "kstack_depth_to_print",
7340741f4d2SChuck Ebbert 		.data		= &kstack_depth_to_print,
7350741f4d2SChuck Ebbert 		.maxlen		= sizeof(int),
7360741f4d2SChuck Ebbert 		.mode		= 0644,
7370741f4d2SChuck Ebbert 		.proc_handler	= &proc_dointvec,
7380741f4d2SChuck Ebbert 	},
7396e7c4025SIngo Molnar 	{
7406e7c4025SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
7416e7c4025SIngo Molnar 		.procname	= "io_delay_type",
7426e7c4025SIngo Molnar 		.data		= &io_delay_type,
7436e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
7446e7c4025SIngo Molnar 		.mode		= 0644,
7456e7c4025SIngo Molnar 		.proc_handler	= &proc_dointvec,
7466e7c4025SIngo Molnar 	},
7471da177e4SLinus Torvalds #endif
7487a9166e3SLuke Yang #if defined(CONFIG_MMU)
7491da177e4SLinus Torvalds 	{
7501da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOMIZE,
7511da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
7521da177e4SLinus Torvalds 		.data		= &randomize_va_space,
7531da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
7541da177e4SLinus Torvalds 		.mode		= 0644,
7551da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7561da177e4SLinus Torvalds 	},
7577a9166e3SLuke Yang #endif
7580152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
759951f22d5SMartin Schwidefsky 	{
760951f22d5SMartin Schwidefsky 		.ctl_name	= KERN_SPIN_RETRY,
761951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
762951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
763951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
764951f22d5SMartin Schwidefsky 		.mode		= 0644,
765951f22d5SMartin Schwidefsky 		.proc_handler	= &proc_dointvec,
766951f22d5SMartin Schwidefsky 	},
767951f22d5SMartin Schwidefsky #endif
768673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
769c255d844SPavel Machek 	{
770c255d844SPavel Machek 		.procname	= "acpi_video_flags",
77177afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
772c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
773c255d844SPavel Machek 		.mode		= 0644,
7747f99f06fSStefan Seyfried 		.proc_handler	= &proc_doulongvec_minmax,
775c255d844SPavel Machek 	},
776c255d844SPavel Machek #endif
777d2b176edSJes Sorensen #ifdef CONFIG_IA64
778d2b176edSJes Sorensen 	{
779d2b176edSJes Sorensen 		.ctl_name	= KERN_IA64_UNALIGNED,
780d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
781d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
782d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
783d2b176edSJes Sorensen 	 	.mode		= 0644,
784d2b176edSJes Sorensen 		.proc_handler	= &proc_dointvec,
785d2b176edSJes Sorensen 	},
78688fc241fSDoug Chapman 	{
78788fc241fSDoug Chapman 		.ctl_name	= CTL_UNNUMBERED,
78888fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
78988fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
79088fc241fSDoug Chapman 		.maxlen		= sizeof (int),
79188fc241fSDoug Chapman 		.mode		= 0644,
79288fc241fSDoug Chapman 		.proc_handler	= &proc_dointvec,
79388fc241fSDoug Chapman 	},
794d2b176edSJes Sorensen #endif
795c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP
796c4f3b63fSRavikiran G Thirumalai 	{
797c4f3b63fSRavikiran G Thirumalai 		.ctl_name	= CTL_UNNUMBERED,
7989c44bc03SIngo Molnar 		.procname	= "softlockup_panic",
7999c44bc03SIngo Molnar 		.data		= &softlockup_panic,
8009c44bc03SIngo Molnar 		.maxlen		= sizeof(int),
8019c44bc03SIngo Molnar 		.mode		= 0644,
8024dca10a9SHiroshi Shimamoto 		.proc_handler	= &proc_dointvec_minmax,
8039c44bc03SIngo Molnar 		.strategy	= &sysctl_intvec,
8049c44bc03SIngo Molnar 		.extra1		= &zero,
8059c44bc03SIngo Molnar 		.extra2		= &one,
8069c44bc03SIngo Molnar 	},
8079c44bc03SIngo Molnar 	{
8089c44bc03SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
809c4f3b63fSRavikiran G Thirumalai 		.procname	= "softlockup_thresh",
810c4f3b63fSRavikiran G Thirumalai 		.data		= &softlockup_thresh,
8119383d967SDimitri Sivanich 		.maxlen		= sizeof(int),
812c4f3b63fSRavikiran G Thirumalai 		.mode		= 0644,
813baf48f65SMandeep Singh Baines 		.proc_handler	= &proc_dosoftlockup_thresh,
814c4f3b63fSRavikiran G Thirumalai 		.strategy	= &sysctl_intvec,
8159383d967SDimitri Sivanich 		.extra1		= &neg_one,
816c4f3b63fSRavikiran G Thirumalai 		.extra2		= &sixty,
817c4f3b63fSRavikiran G Thirumalai 	},
818e162b39aSMandeep Singh Baines #endif
819e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
820e162b39aSMandeep Singh Baines 	{
821e162b39aSMandeep Singh Baines 		.ctl_name	= CTL_UNNUMBERED,
822e162b39aSMandeep Singh Baines 		.procname	= "hung_task_panic",
823e162b39aSMandeep Singh Baines 		.data		= &sysctl_hung_task_panic,
824e162b39aSMandeep Singh Baines 		.maxlen		= sizeof(int),
825e162b39aSMandeep Singh Baines 		.mode		= 0644,
826e162b39aSMandeep Singh Baines 		.proc_handler	= &proc_dointvec_minmax,
827e162b39aSMandeep Singh Baines 		.strategy	= &sysctl_intvec,
828e162b39aSMandeep Singh Baines 		.extra1		= &zero,
829e162b39aSMandeep Singh Baines 		.extra2		= &one,
830e162b39aSMandeep Singh Baines 	},
83182a1fcb9SIngo Molnar 	{
83282a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
83382a1fcb9SIngo Molnar 		.procname	= "hung_task_check_count",
83482a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_check_count,
83590739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
83682a1fcb9SIngo Molnar 		.mode		= 0644,
83790739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
83882a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
83982a1fcb9SIngo Molnar 	},
84082a1fcb9SIngo Molnar 	{
84182a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
84282a1fcb9SIngo Molnar 		.procname	= "hung_task_timeout_secs",
84382a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_timeout_secs,
84490739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
84582a1fcb9SIngo Molnar 		.mode		= 0644,
846e162b39aSMandeep Singh Baines 		.proc_handler	= &proc_dohung_task_timeout_secs,
84782a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
84882a1fcb9SIngo Molnar 	},
84982a1fcb9SIngo Molnar 	{
85082a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
85182a1fcb9SIngo Molnar 		.procname	= "hung_task_warnings",
85282a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_warnings,
85390739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
85482a1fcb9SIngo Molnar 		.mode		= 0644,
85590739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
85682a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
85782a1fcb9SIngo Molnar 	},
858c4f3b63fSRavikiran G Thirumalai #endif
859bebfa101SAndi Kleen #ifdef CONFIG_COMPAT
860bebfa101SAndi Kleen 	{
861bebfa101SAndi Kleen 		.ctl_name	= KERN_COMPAT_LOG,
862bebfa101SAndi Kleen 		.procname	= "compat-log",
863bebfa101SAndi Kleen 		.data		= &compat_log,
864bebfa101SAndi Kleen 		.maxlen		= sizeof (int),
865bebfa101SAndi Kleen 	 	.mode		= 0644,
866bebfa101SAndi Kleen 		.proc_handler	= &proc_dointvec,
867bebfa101SAndi Kleen 	},
868bebfa101SAndi Kleen #endif
86923f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
87023f78d4aSIngo Molnar 	{
87123f78d4aSIngo Molnar 		.ctl_name	= KERN_MAX_LOCK_DEPTH,
87223f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
87323f78d4aSIngo Molnar 		.data		= &max_lock_depth,
87423f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
87523f78d4aSIngo Molnar 		.mode		= 0644,
87623f78d4aSIngo Molnar 		.proc_handler	= &proc_dointvec,
87723f78d4aSIngo Molnar 	},
87823f78d4aSIngo Molnar #endif
87910a0a8d4SJeremy Fitzhardinge 	{
88010a0a8d4SJeremy Fitzhardinge 		.ctl_name	= CTL_UNNUMBERED,
88110a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
88210a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
88310a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
88410a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
88510a0a8d4SJeremy Fitzhardinge 		.proc_handler	= &proc_dostring,
88610a0a8d4SJeremy Fitzhardinge 		.strategy	= &sysctl_string,
88710a0a8d4SJeremy Fitzhardinge 	},
8880b77f5bfSDavid Howells #ifdef CONFIG_KEYS
8890b77f5bfSDavid Howells 	{
8900b77f5bfSDavid Howells 		.ctl_name	= CTL_UNNUMBERED,
8910b77f5bfSDavid Howells 		.procname	= "keys",
8920b77f5bfSDavid Howells 		.mode		= 0555,
8930b77f5bfSDavid Howells 		.child		= key_sysctls,
8940b77f5bfSDavid Howells 	},
8950b77f5bfSDavid Howells #endif
89631a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
89731a72bceSPaul E. McKenney 	{
89831a72bceSPaul E. McKenney 		.ctl_name       = CTL_UNNUMBERED,
89931a72bceSPaul E. McKenney 		.procname       = "rcutorture_runnable",
90031a72bceSPaul E. McKenney 		.data           = &rcutorture_runnable,
90131a72bceSPaul E. McKenney 		.maxlen         = sizeof(int),
90231a72bceSPaul E. McKenney 		.mode           = 0644,
90331a72bceSPaul E. McKenney 		.proc_handler   = &proc_dointvec,
90431a72bceSPaul E. McKenney 	},
90531a72bceSPaul E. McKenney #endif
90612e22c5eSDavid Howells #ifdef CONFIG_SLOW_WORK
90712e22c5eSDavid Howells 	{
90812e22c5eSDavid Howells 		.ctl_name	= CTL_UNNUMBERED,
90912e22c5eSDavid Howells 		.procname	= "slow-work",
91012e22c5eSDavid Howells 		.mode		= 0555,
91112e22c5eSDavid Howells 		.child		= slow_work_sysctls,
91212e22c5eSDavid Howells 	},
91312e22c5eSDavid Howells #endif
9141ccd1549SPeter Zijlstra #ifdef CONFIG_PERF_COUNTERS
9151ccd1549SPeter Zijlstra 	{
9161ccd1549SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
9171ccd1549SPeter Zijlstra 		.procname	= "perf_counter_privileged",
9181ccd1549SPeter Zijlstra 		.data		= &sysctl_perf_counter_priv,
9191ccd1549SPeter Zijlstra 		.maxlen		= sizeof(sysctl_perf_counter_priv),
9201ccd1549SPeter Zijlstra 		.mode		= 0644,
9211ccd1549SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
9221ccd1549SPeter Zijlstra 	},
923*c5078f78SPeter Zijlstra 	{
924*c5078f78SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
925*c5078f78SPeter Zijlstra 		.procname	= "perf_counter_mlock_kb",
926*c5078f78SPeter Zijlstra 		.data		= &sysctl_perf_counter_mlock,
927*c5078f78SPeter Zijlstra 		.maxlen		= sizeof(sysctl_perf_counter_mlock),
928*c5078f78SPeter Zijlstra 		.mode		= 0644,
929*c5078f78SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
930*c5078f78SPeter Zijlstra 	},
9311ccd1549SPeter Zijlstra #endif
932ed2c12f3SAndrew Morton /*
933ed2c12f3SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
934ed2c12f3SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
935ed2c12f3SAndrew Morton  */
9361da177e4SLinus Torvalds 	{ .ctl_name = 0 }
9371da177e4SLinus Torvalds };
9381da177e4SLinus Torvalds 
939d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
9401da177e4SLinus Torvalds 	{
9411da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_MEMORY,
9421da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
9431da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
9441da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
9451da177e4SLinus Torvalds 		.mode		= 0644,
9461da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9471da177e4SLinus Torvalds 	},
9481da177e4SLinus Torvalds 	{
949fadd8fbdSKAMEZAWA Hiroyuki 		.ctl_name	= VM_PANIC_ON_OOM,
950fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
951fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
952fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
953fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
954fadd8fbdSKAMEZAWA Hiroyuki 		.proc_handler	= &proc_dointvec,
955fadd8fbdSKAMEZAWA Hiroyuki 	},
956fadd8fbdSKAMEZAWA Hiroyuki 	{
957fe071d7eSDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
958fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
959fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
960fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
961fe071d7eSDavid Rientjes 		.mode		= 0644,
962fe071d7eSDavid Rientjes 		.proc_handler	= &proc_dointvec,
963fe071d7eSDavid Rientjes 	},
964fe071d7eSDavid Rientjes 	{
965fef1bdd6SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
966fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
967fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
968fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
969fef1bdd6SDavid Rientjes 		.mode		= 0644,
970fef1bdd6SDavid Rientjes 		.proc_handler	= &proc_dointvec,
971fef1bdd6SDavid Rientjes 	},
972fef1bdd6SDavid Rientjes 	{
9731da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_RATIO,
9741da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
9751da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
9761da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
9771da177e4SLinus Torvalds 		.mode		= 0644,
9781da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9791da177e4SLinus Torvalds 	},
9801da177e4SLinus Torvalds 	{
9811da177e4SLinus Torvalds 		.ctl_name	= VM_PAGE_CLUSTER,
9821da177e4SLinus Torvalds 		.procname	= "page-cluster",
9831da177e4SLinus Torvalds 		.data		= &page_cluster,
9841da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9851da177e4SLinus Torvalds 		.mode		= 0644,
9861da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9871da177e4SLinus Torvalds 	},
9881da177e4SLinus Torvalds 	{
9891da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_BACKGROUND,
9901da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
9911da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
9921da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
9931da177e4SLinus Torvalds 		.mode		= 0644,
9942da02997SDavid Rientjes 		.proc_handler	= &dirty_background_ratio_handler,
9951da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9961da177e4SLinus Torvalds 		.extra1		= &zero,
9971da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9981da177e4SLinus Torvalds 	},
9991da177e4SLinus Torvalds 	{
10002da02997SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
10012da02997SDavid Rientjes 		.procname	= "dirty_background_bytes",
10022da02997SDavid Rientjes 		.data		= &dirty_background_bytes,
10032da02997SDavid Rientjes 		.maxlen		= sizeof(dirty_background_bytes),
10042da02997SDavid Rientjes 		.mode		= 0644,
10052da02997SDavid Rientjes 		.proc_handler	= &dirty_background_bytes_handler,
10062da02997SDavid Rientjes 		.strategy	= &sysctl_intvec,
1007fc3501d4SSven Wegener 		.extra1		= &one_ul,
10082da02997SDavid Rientjes 	},
10092da02997SDavid Rientjes 	{
10101da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_RATIO,
10111da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
10121da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
10131da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
10141da177e4SLinus Torvalds 		.mode		= 0644,
101504fbfdc1SPeter Zijlstra 		.proc_handler	= &dirty_ratio_handler,
10161da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10171da177e4SLinus Torvalds 		.extra1		= &zero,
10181da177e4SLinus Torvalds 		.extra2		= &one_hundred,
10191da177e4SLinus Torvalds 	},
10201da177e4SLinus Torvalds 	{
10212da02997SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
10222da02997SDavid Rientjes 		.procname	= "dirty_bytes",
10232da02997SDavid Rientjes 		.data		= &vm_dirty_bytes,
10242da02997SDavid Rientjes 		.maxlen		= sizeof(vm_dirty_bytes),
10252da02997SDavid Rientjes 		.mode		= 0644,
10262da02997SDavid Rientjes 		.proc_handler	= &dirty_bytes_handler,
10272da02997SDavid Rientjes 		.strategy	= &sysctl_intvec,
1028fc3501d4SSven Wegener 		.extra1		= &one_ul,
10292da02997SDavid Rientjes 	},
10302da02997SDavid Rientjes 	{
10311da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
1032f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
1033f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
10341da177e4SLinus Torvalds 		.mode		= 0644,
10351da177e4SLinus Torvalds 		.proc_handler	= &dirty_writeback_centisecs_handler,
10361da177e4SLinus Torvalds 	},
10371da177e4SLinus Torvalds 	{
10381da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
1039f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
1040f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
10411da177e4SLinus Torvalds 		.mode		= 0644,
1042704503d8SAlexey Dobriyan 		.proc_handler	= &proc_dointvec,
10431da177e4SLinus Torvalds 	},
10441da177e4SLinus Torvalds 	{
10451da177e4SLinus Torvalds 		.ctl_name	= VM_NR_PDFLUSH_THREADS,
10461da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
10471da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
10481da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
10491da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
10501da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10511da177e4SLinus Torvalds 	},
10521da177e4SLinus Torvalds 	{
1053fafd688eSPeter W Morreale 		.ctl_name	= CTL_UNNUMBERED,
1054fafd688eSPeter W Morreale 		.procname	= "nr_pdflush_threads_min",
1055fafd688eSPeter W Morreale 		.data		= &nr_pdflush_threads_min,
1056fafd688eSPeter W Morreale 		.maxlen		= sizeof nr_pdflush_threads_min,
1057fafd688eSPeter W Morreale 		.mode		= 0644 /* read-write */,
1058fafd688eSPeter W Morreale 		.proc_handler	= &proc_dointvec_minmax,
1059fafd688eSPeter W Morreale 		.strategy	= &sysctl_intvec,
1060fafd688eSPeter W Morreale 		.extra1		= &one,
1061fafd688eSPeter W Morreale 		.extra2		= &nr_pdflush_threads_max,
1062fafd688eSPeter W Morreale 	},
1063fafd688eSPeter W Morreale 	{
1064fafd688eSPeter W Morreale 		.ctl_name	= CTL_UNNUMBERED,
1065fafd688eSPeter W Morreale 		.procname	= "nr_pdflush_threads_max",
1066fafd688eSPeter W Morreale 		.data		= &nr_pdflush_threads_max,
1067fafd688eSPeter W Morreale 		.maxlen		= sizeof nr_pdflush_threads_max,
1068fafd688eSPeter W Morreale 		.mode		= 0644 /* read-write */,
1069fafd688eSPeter W Morreale 		.proc_handler	= &proc_dointvec_minmax,
1070fafd688eSPeter W Morreale 		.strategy	= &sysctl_intvec,
1071fafd688eSPeter W Morreale 		.extra1		= &nr_pdflush_threads_min,
1072fafd688eSPeter W Morreale 		.extra2		= &one_thousand,
1073fafd688eSPeter W Morreale 	},
1074fafd688eSPeter W Morreale 	{
10751da177e4SLinus Torvalds 		.ctl_name	= VM_SWAPPINESS,
10761da177e4SLinus Torvalds 		.procname	= "swappiness",
10771da177e4SLinus Torvalds 		.data		= &vm_swappiness,
10781da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
10791da177e4SLinus Torvalds 		.mode		= 0644,
10801da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
10811da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10821da177e4SLinus Torvalds 		.extra1		= &zero,
10831da177e4SLinus Torvalds 		.extra2		= &one_hundred,
10841da177e4SLinus Torvalds 	},
10851da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
10861da177e4SLinus Torvalds 	 {
10871da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
1088e5ff2159SAndi Kleen 		.data		= NULL,
10891da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
10901da177e4SLinus Torvalds 		.mode		= 0644,
10911da177e4SLinus Torvalds 		.proc_handler	= &hugetlb_sysctl_handler,
10921da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
10931da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
10941da177e4SLinus Torvalds 	 },
10951da177e4SLinus Torvalds 	 {
10961da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_GROUP,
10971da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
10981da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
10991da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
11001da177e4SLinus Torvalds 		.mode		= 0644,
11011da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11021da177e4SLinus Torvalds 	 },
1103396faf03SMel Gorman 	 {
1104396faf03SMel Gorman 		.ctl_name	= CTL_UNNUMBERED,
1105396faf03SMel Gorman 		.procname	= "hugepages_treat_as_movable",
1106396faf03SMel Gorman 		.data		= &hugepages_treat_as_movable,
1107396faf03SMel Gorman 		.maxlen		= sizeof(int),
1108396faf03SMel Gorman 		.mode		= 0644,
1109396faf03SMel Gorman 		.proc_handler	= &hugetlb_treat_movable_handler,
1110396faf03SMel Gorman 	},
111154f9f80dSAdam Litke 	{
111254f9f80dSAdam Litke 		.ctl_name	= CTL_UNNUMBERED,
1113d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
1114e5ff2159SAndi Kleen 		.data		= NULL,
1115e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
1116d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
1117a3d0c6aaSNishanth Aravamudan 		.proc_handler	= &hugetlb_overcommit_handler,
1118e5ff2159SAndi Kleen 		.extra1		= (void *)&hugetlb_zero,
1119e5ff2159SAndi Kleen 		.extra2		= (void *)&hugetlb_infinity,
1120d1c3fb1fSNishanth Aravamudan 	},
11211da177e4SLinus Torvalds #endif
11221da177e4SLinus Torvalds 	{
11231da177e4SLinus Torvalds 		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
11241da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
11251da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
11261da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
11271da177e4SLinus Torvalds 		.mode		= 0644,
11281da177e4SLinus Torvalds 		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
11291da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11301da177e4SLinus Torvalds 	},
11311da177e4SLinus Torvalds 	{
11329d0243bcSAndrew Morton 		.ctl_name	= VM_DROP_PAGECACHE,
11339d0243bcSAndrew Morton 		.procname	= "drop_caches",
11349d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
11359d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
11369d0243bcSAndrew Morton 		.mode		= 0644,
11379d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
11389d0243bcSAndrew Morton 		.strategy	= &sysctl_intvec,
11399d0243bcSAndrew Morton 	},
11409d0243bcSAndrew Morton 	{
11411da177e4SLinus Torvalds 		.ctl_name	= VM_MIN_FREE_KBYTES,
11421da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
11431da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
11441da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
11451da177e4SLinus Torvalds 		.mode		= 0644,
11461da177e4SLinus Torvalds 		.proc_handler	= &min_free_kbytes_sysctl_handler,
11471da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11481da177e4SLinus Torvalds 		.extra1		= &zero,
11491da177e4SLinus Torvalds 	},
11508ad4b1fbSRohit Seth 	{
11518ad4b1fbSRohit Seth 		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
11528ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
11538ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
11548ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
11558ad4b1fbSRohit Seth 		.mode		= 0644,
11568ad4b1fbSRohit Seth 		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
11578ad4b1fbSRohit Seth 		.strategy	= &sysctl_intvec,
11588ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
11598ad4b1fbSRohit Seth 	},
11601da177e4SLinus Torvalds #ifdef CONFIG_MMU
11611da177e4SLinus Torvalds 	{
11621da177e4SLinus Torvalds 		.ctl_name	= VM_MAX_MAP_COUNT,
11631da177e4SLinus Torvalds 		.procname	= "max_map_count",
11641da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
11651da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
11661da177e4SLinus Torvalds 		.mode		= 0644,
11671da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec
11681da177e4SLinus Torvalds 	},
1169dd8632a1SPaul Mundt #else
1170dd8632a1SPaul Mundt 	{
1171dd8632a1SPaul Mundt 		.ctl_name	= CTL_UNNUMBERED,
1172dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
1173dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
1174dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
1175dd8632a1SPaul Mundt 		.mode		= 0644,
1176dd8632a1SPaul Mundt 		.proc_handler	= &proc_dointvec_minmax,
1177dd8632a1SPaul Mundt 		.strategy	= &sysctl_intvec,
1178dd8632a1SPaul Mundt 		.extra1		= &zero,
1179dd8632a1SPaul Mundt 	},
11801da177e4SLinus Torvalds #endif
11811da177e4SLinus Torvalds 	{
11821da177e4SLinus Torvalds 		.ctl_name	= VM_LAPTOP_MODE,
11831da177e4SLinus Torvalds 		.procname	= "laptop_mode",
11841da177e4SLinus Torvalds 		.data		= &laptop_mode,
11851da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
11861da177e4SLinus Torvalds 		.mode		= 0644,
1187ed5b43f1SBart Samwel 		.proc_handler	= &proc_dointvec_jiffies,
1188ed5b43f1SBart Samwel 		.strategy	= &sysctl_jiffies,
11891da177e4SLinus Torvalds 	},
11901da177e4SLinus Torvalds 	{
11911da177e4SLinus Torvalds 		.ctl_name	= VM_BLOCK_DUMP,
11921da177e4SLinus Torvalds 		.procname	= "block_dump",
11931da177e4SLinus Torvalds 		.data		= &block_dump,
11941da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
11951da177e4SLinus Torvalds 		.mode		= 0644,
11961da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11971da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11981da177e4SLinus Torvalds 		.extra1		= &zero,
11991da177e4SLinus Torvalds 	},
12001da177e4SLinus Torvalds 	{
12011da177e4SLinus Torvalds 		.ctl_name	= VM_VFS_CACHE_PRESSURE,
12021da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
12031da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
12041da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
12051da177e4SLinus Torvalds 		.mode		= 0644,
12061da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12071da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
12081da177e4SLinus Torvalds 		.extra1		= &zero,
12091da177e4SLinus Torvalds 	},
12101da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
12111da177e4SLinus Torvalds 	{
12121da177e4SLinus Torvalds 		.ctl_name	= VM_LEGACY_VA_LAYOUT,
12131da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
12141da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
12151da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
12161da177e4SLinus Torvalds 		.mode		= 0644,
12171da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
12181da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
12191da177e4SLinus Torvalds 		.extra1		= &zero,
12201da177e4SLinus Torvalds 	},
12211da177e4SLinus Torvalds #endif
12221743660bSChristoph Lameter #ifdef CONFIG_NUMA
12231743660bSChristoph Lameter 	{
12241743660bSChristoph Lameter 		.ctl_name	= VM_ZONE_RECLAIM_MODE,
12251743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
12261743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
12271743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
12281743660bSChristoph Lameter 		.mode		= 0644,
12291743660bSChristoph Lameter 		.proc_handler	= &proc_dointvec,
1230c84db23cSChristoph Lameter 		.strategy	= &sysctl_intvec,
1231c84db23cSChristoph Lameter 		.extra1		= &zero,
12321743660bSChristoph Lameter 	},
12339614634fSChristoph Lameter 	{
12349614634fSChristoph Lameter 		.ctl_name	= VM_MIN_UNMAPPED,
12359614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
12369614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
12379614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
12389614634fSChristoph Lameter 		.mode		= 0644,
12399614634fSChristoph Lameter 		.proc_handler	= &sysctl_min_unmapped_ratio_sysctl_handler,
12409614634fSChristoph Lameter 		.strategy	= &sysctl_intvec,
12419614634fSChristoph Lameter 		.extra1		= &zero,
12429614634fSChristoph Lameter 		.extra2		= &one_hundred,
12439614634fSChristoph Lameter 	},
12440ff38490SChristoph Lameter 	{
12450ff38490SChristoph Lameter 		.ctl_name	= VM_MIN_SLAB,
12460ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
12470ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
12480ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
12490ff38490SChristoph Lameter 		.mode		= 0644,
12500ff38490SChristoph Lameter 		.proc_handler	= &sysctl_min_slab_ratio_sysctl_handler,
12510ff38490SChristoph Lameter 		.strategy	= &sysctl_intvec,
12520ff38490SChristoph Lameter 		.extra1		= &zero,
12530ff38490SChristoph Lameter 		.extra2		= &one_hundred,
12540ff38490SChristoph Lameter 	},
12551743660bSChristoph Lameter #endif
125677461ab3SChristoph Lameter #ifdef CONFIG_SMP
125777461ab3SChristoph Lameter 	{
125877461ab3SChristoph Lameter 		.ctl_name	= CTL_UNNUMBERED,
125977461ab3SChristoph Lameter 		.procname	= "stat_interval",
126077461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
126177461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
126277461ab3SChristoph Lameter 		.mode		= 0644,
126377461ab3SChristoph Lameter 		.proc_handler	= &proc_dointvec_jiffies,
126477461ab3SChristoph Lameter 		.strategy	= &sysctl_jiffies,
126577461ab3SChristoph Lameter 	},
126677461ab3SChristoph Lameter #endif
1267ed032189SEric Paris #ifdef CONFIG_SECURITY
1268ed032189SEric Paris 	{
1269ed032189SEric Paris 		.ctl_name	= CTL_UNNUMBERED,
1270ed032189SEric Paris 		.procname	= "mmap_min_addr",
1271ed032189SEric Paris 		.data		= &mmap_min_addr,
1272ed032189SEric Paris 		.maxlen         = sizeof(unsigned long),
1273ed032189SEric Paris 		.mode		= 0644,
1274ed032189SEric Paris 		.proc_handler	= &proc_doulongvec_minmax,
1275ed032189SEric Paris 	},
12768daec965SLee Schermerhorn #endif
1277f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
1278f0c0b2b8SKAMEZAWA Hiroyuki 	{
1279f0c0b2b8SKAMEZAWA Hiroyuki 		.ctl_name	= CTL_UNNUMBERED,
1280f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
1281f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
1282f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
1283f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
1284f0c0b2b8SKAMEZAWA Hiroyuki 		.proc_handler	= &numa_zonelist_order_handler,
1285f0c0b2b8SKAMEZAWA Hiroyuki 		.strategy	= &sysctl_string,
1286f0c0b2b8SKAMEZAWA Hiroyuki 	},
1287f0c0b2b8SKAMEZAWA Hiroyuki #endif
12882b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
12895c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1290e6e5494cSIngo Molnar 	{
1291e6e5494cSIngo Molnar 		.ctl_name	= VM_VDSO_ENABLED,
1292e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
1293e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
1294e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
1295e6e5494cSIngo Molnar 		.mode		= 0644,
1296e6e5494cSIngo Molnar 		.proc_handler	= &proc_dointvec,
1297e6e5494cSIngo Molnar 		.strategy	= &sysctl_intvec,
1298e6e5494cSIngo Molnar 		.extra1		= &zero,
1299e6e5494cSIngo Molnar 	},
1300e6e5494cSIngo Molnar #endif
1301195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
1302195cf453SBron Gondwana 	{
1303195cf453SBron Gondwana 		.ctl_name	= CTL_UNNUMBERED,
1304195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
1305195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
1306195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
1307195cf453SBron Gondwana 		.mode		= 0644,
1308195cf453SBron Gondwana 		.proc_handler	= &proc_dointvec_minmax,
1309195cf453SBron Gondwana 		.strategy	= &sysctl_intvec,
1310195cf453SBron Gondwana 		.extra1		= &zero,
1311195cf453SBron Gondwana 		.extra2		= &one,
1312195cf453SBron Gondwana 	},
1313195cf453SBron Gondwana #endif
13144be6f6bbSPeter Zijlstra #ifdef CONFIG_UNEVICTABLE_LRU
13154be6f6bbSPeter Zijlstra 	{
13164be6f6bbSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
13174be6f6bbSPeter Zijlstra 		.procname	= "scan_unevictable_pages",
13184be6f6bbSPeter Zijlstra 		.data		= &scan_unevictable_pages,
13194be6f6bbSPeter Zijlstra 		.maxlen		= sizeof(scan_unevictable_pages),
13204be6f6bbSPeter Zijlstra 		.mode		= 0644,
13214be6f6bbSPeter Zijlstra 		.proc_handler	= &scan_unevictable_handler,
13224be6f6bbSPeter Zijlstra 	},
13234be6f6bbSPeter Zijlstra #endif
13242be7fe07SAndrew Morton /*
13252be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
13262be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
13272be7fe07SAndrew Morton  */
13281da177e4SLinus Torvalds 	{ .ctl_name = 0 }
13291da177e4SLinus Torvalds };
13301da177e4SLinus Torvalds 
13312abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1332d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = {
13332abc26fcSEric W. Biederman 	{ .ctl_name = 0 }
13342abc26fcSEric W. Biederman };
13352abc26fcSEric W. Biederman #endif
13362abc26fcSEric W. Biederman 
1337d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
13381da177e4SLinus Torvalds 	{
13391da177e4SLinus Torvalds 		.ctl_name	= FS_NRINODE,
13401da177e4SLinus Torvalds 		.procname	= "inode-nr",
13411da177e4SLinus Torvalds 		.data		= &inodes_stat,
13421da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
13431da177e4SLinus Torvalds 		.mode		= 0444,
13441da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13451da177e4SLinus Torvalds 	},
13461da177e4SLinus Torvalds 	{
13471da177e4SLinus Torvalds 		.ctl_name	= FS_STATINODE,
13481da177e4SLinus Torvalds 		.procname	= "inode-state",
13491da177e4SLinus Torvalds 		.data		= &inodes_stat,
13501da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
13511da177e4SLinus Torvalds 		.mode		= 0444,
13521da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13531da177e4SLinus Torvalds 	},
13541da177e4SLinus Torvalds 	{
13551da177e4SLinus Torvalds 		.procname	= "file-nr",
13561da177e4SLinus Torvalds 		.data		= &files_stat,
13571da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
13581da177e4SLinus Torvalds 		.mode		= 0444,
1359529bf6beSDipankar Sarma 		.proc_handler	= &proc_nr_files,
13601da177e4SLinus Torvalds 	},
13611da177e4SLinus Torvalds 	{
13621da177e4SLinus Torvalds 		.ctl_name	= FS_MAXFILE,
13631da177e4SLinus Torvalds 		.procname	= "file-max",
13641da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
13651da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13661da177e4SLinus Torvalds 		.mode		= 0644,
13671da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13681da177e4SLinus Torvalds 	},
13691da177e4SLinus Torvalds 	{
13709cfe015aSEric Dumazet 		.ctl_name	= CTL_UNNUMBERED,
13719cfe015aSEric Dumazet 		.procname	= "nr_open",
13729cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
13739cfe015aSEric Dumazet 		.maxlen		= sizeof(int),
13749cfe015aSEric Dumazet 		.mode		= 0644,
1375eceea0b3SAl Viro 		.proc_handler	= &proc_dointvec_minmax,
1376eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
1377eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
13789cfe015aSEric Dumazet 	},
13799cfe015aSEric Dumazet 	{
13801da177e4SLinus Torvalds 		.ctl_name	= FS_DENTRY,
13811da177e4SLinus Torvalds 		.procname	= "dentry-state",
13821da177e4SLinus Torvalds 		.data		= &dentry_stat,
13831da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
13841da177e4SLinus Torvalds 		.mode		= 0444,
13851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13861da177e4SLinus Torvalds 	},
13871da177e4SLinus Torvalds 	{
13881da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWUID,
13891da177e4SLinus Torvalds 		.procname	= "overflowuid",
13901da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
13911da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13921da177e4SLinus Torvalds 		.mode		= 0644,
13931da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
13941da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
13951da177e4SLinus Torvalds 		.extra1		= &minolduid,
13961da177e4SLinus Torvalds 		.extra2		= &maxolduid,
13971da177e4SLinus Torvalds 	},
13981da177e4SLinus Torvalds 	{
13991da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWGID,
14001da177e4SLinus Torvalds 		.procname	= "overflowgid",
14011da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
14021da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
14031da177e4SLinus Torvalds 		.mode		= 0644,
14041da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
14051da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
14061da177e4SLinus Torvalds 		.extra1		= &minolduid,
14071da177e4SLinus Torvalds 		.extra2		= &maxolduid,
14081da177e4SLinus Torvalds 	},
1409bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
14101da177e4SLinus Torvalds 	{
14111da177e4SLinus Torvalds 		.ctl_name	= FS_LEASES,
14121da177e4SLinus Torvalds 		.procname	= "leases-enable",
14131da177e4SLinus Torvalds 		.data		= &leases_enable,
14141da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
14151da177e4SLinus Torvalds 		.mode		= 0644,
14161da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
14171da177e4SLinus Torvalds 	},
1418bfcd17a6SThomas Petazzoni #endif
14191da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
14201da177e4SLinus Torvalds 	{
14211da177e4SLinus Torvalds 		.ctl_name	= FS_DIR_NOTIFY,
14221da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
14231da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
14241da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
14251da177e4SLinus Torvalds 		.mode		= 0644,
14261da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
14271da177e4SLinus Torvalds 	},
14281da177e4SLinus Torvalds #endif
14291da177e4SLinus Torvalds #ifdef CONFIG_MMU
1430bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
14311da177e4SLinus Torvalds 	{
14321da177e4SLinus Torvalds 		.ctl_name	= FS_LEASE_TIME,
14331da177e4SLinus Torvalds 		.procname	= "lease-break-time",
14341da177e4SLinus Torvalds 		.data		= &lease_break_time,
14351da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
14361da177e4SLinus Torvalds 		.mode		= 0644,
14378e654fbaSMatthew Wilcox 		.proc_handler	= &proc_dointvec,
14381da177e4SLinus Torvalds 	},
1439bfcd17a6SThomas Petazzoni #endif
1440ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO
14411da177e4SLinus Torvalds 	{
14421da177e4SLinus Torvalds 		.procname	= "aio-nr",
14431da177e4SLinus Torvalds 		.data		= &aio_nr,
14441da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
14451da177e4SLinus Torvalds 		.mode		= 0444,
1446d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
14471da177e4SLinus Torvalds 	},
14481da177e4SLinus Torvalds 	{
14491da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
14501da177e4SLinus Torvalds 		.data		= &aio_max_nr,
14511da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
14521da177e4SLinus Torvalds 		.mode		= 0644,
1453d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
14541da177e4SLinus Torvalds 	},
1455ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */
14562d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
14570399cb08SRobert Love 	{
14580399cb08SRobert Love 		.ctl_name	= FS_INOTIFY,
14590399cb08SRobert Love 		.procname	= "inotify",
14600399cb08SRobert Love 		.mode		= 0555,
14610399cb08SRobert Love 		.child		= inotify_table,
14620399cb08SRobert Love 	},
14630399cb08SRobert Love #endif
14647ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
14657ef9964eSDavide Libenzi 	{
14667ef9964eSDavide Libenzi 		.procname	= "epoll",
14677ef9964eSDavide Libenzi 		.mode		= 0555,
14687ef9964eSDavide Libenzi 		.child		= epoll_table,
14697ef9964eSDavide Libenzi 	},
14707ef9964eSDavide Libenzi #endif
14711da177e4SLinus Torvalds #endif
1472d6e71144SAlan Cox 	{
1473d6e71144SAlan Cox 		.ctl_name	= KERN_SETUID_DUMPABLE,
1474d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1475d6e71144SAlan Cox 		.data		= &suid_dumpable,
1476d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1477d6e71144SAlan Cox 		.mode		= 0644,
14788e654fbaSMatthew Wilcox 		.proc_handler	= &proc_dointvec_minmax,
14798e654fbaSMatthew Wilcox 		.strategy	= &sysctl_intvec,
14808e654fbaSMatthew Wilcox 		.extra1		= &zero,
14818e654fbaSMatthew Wilcox 		.extra2		= &two,
1482d6e71144SAlan Cox 	},
14832abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
14842abc26fcSEric W. Biederman 	{
14852abc26fcSEric W. Biederman 		.ctl_name	= CTL_UNNUMBERED,
14862abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
14872abc26fcSEric W. Biederman 		.mode		= 0555,
14882abc26fcSEric W. Biederman 		.child		= binfmt_misc_table,
14892abc26fcSEric W. Biederman 	},
14902abc26fcSEric W. Biederman #endif
14912be7fe07SAndrew Morton /*
14922be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
14932be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
14942be7fe07SAndrew Morton  */
14951da177e4SLinus Torvalds 	{ .ctl_name = 0 }
14961da177e4SLinus Torvalds };
14971da177e4SLinus Torvalds 
1498d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
1499d0c3d534SOlof Johansson #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1500abd4f750SMasoud Asgharifard Sharbiani 	{
1501abd4f750SMasoud Asgharifard Sharbiani 		.ctl_name	= CTL_UNNUMBERED,
1502abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
1503abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
1504abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
1505abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
1506abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
1507abd4f750SMasoud Asgharifard Sharbiani 	},
1508abd4f750SMasoud Asgharifard Sharbiani #endif
15091da177e4SLinus Torvalds 	{ .ctl_name = 0 }
15101da177e4SLinus Torvalds };
15111da177e4SLinus Torvalds 
1512d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
15131da177e4SLinus Torvalds 	{ .ctl_name = 0 }
15141da177e4SLinus Torvalds };
15151da177e4SLinus Torvalds 
1516330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1517330d57fbSAl Viro 
1518330d57fbSAl Viro /* called under sysctl_lock */
1519330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1520330d57fbSAl Viro {
1521330d57fbSAl Viro 	if (unlikely(p->unregistering))
1522330d57fbSAl Viro 		return 0;
1523330d57fbSAl Viro 	p->used++;
1524330d57fbSAl Viro 	return 1;
1525330d57fbSAl Viro }
1526330d57fbSAl Viro 
1527330d57fbSAl Viro /* called under sysctl_lock */
1528330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1529330d57fbSAl Viro {
1530330d57fbSAl Viro 	if (!--p->used)
1531330d57fbSAl Viro 		if (unlikely(p->unregistering))
1532330d57fbSAl Viro 			complete(p->unregistering);
1533330d57fbSAl Viro }
1534330d57fbSAl Viro 
1535330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1536330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1537330d57fbSAl Viro {
1538330d57fbSAl Viro 	/*
1539330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1540330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1541330d57fbSAl Viro 	 */
1542330d57fbSAl Viro 	if (unlikely(p->used)) {
1543330d57fbSAl Viro 		struct completion wait;
1544330d57fbSAl Viro 		init_completion(&wait);
1545330d57fbSAl Viro 		p->unregistering = &wait;
1546330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1547330d57fbSAl Viro 		wait_for_completion(&wait);
1548330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1549f7e6ced4SAl Viro 	} else {
1550f7e6ced4SAl Viro 		/* anything non-NULL; we'll never dereference it */
1551f7e6ced4SAl Viro 		p->unregistering = ERR_PTR(-EINVAL);
1552330d57fbSAl Viro 	}
1553330d57fbSAl Viro 	/*
1554330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1555330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1556330d57fbSAl Viro 	 */
1557330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1558330d57fbSAl Viro }
1559330d57fbSAl Viro 
1560f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head)
1561f7e6ced4SAl Viro {
1562f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1563f7e6ced4SAl Viro 	head->count++;
1564f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1565f7e6ced4SAl Viro }
1566f7e6ced4SAl Viro 
1567f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
1568f7e6ced4SAl Viro {
1569f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1570f7e6ced4SAl Viro 	if (!--head->count)
1571f7e6ced4SAl Viro 		kfree(head);
1572f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1573f7e6ced4SAl Viro }
1574f7e6ced4SAl Viro 
1575f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1576f7e6ced4SAl Viro {
1577f7e6ced4SAl Viro 	if (!head)
1578f7e6ced4SAl Viro 		BUG();
1579f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1580f7e6ced4SAl Viro 	if (!use_table(head))
1581f7e6ced4SAl Viro 		head = ERR_PTR(-ENOENT);
1582f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1583f7e6ced4SAl Viro 	return head;
1584f7e6ced4SAl Viro }
1585f7e6ced4SAl Viro 
1586805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head)
1587805b5d5eSEric W. Biederman {
1588805b5d5eSEric W. Biederman 	if (!head)
1589805b5d5eSEric W. Biederman 		return;
1590805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1591805b5d5eSEric W. Biederman 	unuse_table(head);
1592805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1593805b5d5eSEric W. Biederman }
1594805b5d5eSEric W. Biederman 
159573455092SAl Viro static struct ctl_table_set *
159673455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
159773455092SAl Viro {
159873455092SAl Viro 	struct ctl_table_set *set = &root->default_set;
159973455092SAl Viro 	if (root->lookup)
160073455092SAl Viro 		set = root->lookup(root, namespaces);
160173455092SAl Viro 	return set;
160273455092SAl Viro }
160373455092SAl Viro 
1604e51b6ba0SEric W. Biederman static struct list_head *
1605e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1606805b5d5eSEric W. Biederman {
160773455092SAl Viro 	struct ctl_table_set *set = lookup_header_set(root, namespaces);
160873455092SAl Viro 	return &set->list;
1609e51b6ba0SEric W. Biederman }
1610e51b6ba0SEric W. Biederman 
1611e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1612e51b6ba0SEric W. Biederman 					    struct ctl_table_header *prev)
1613e51b6ba0SEric W. Biederman {
1614e51b6ba0SEric W. Biederman 	struct ctl_table_root *root;
1615e51b6ba0SEric W. Biederman 	struct list_head *header_list;
1616805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1617805b5d5eSEric W. Biederman 	struct list_head *tmp;
1618e51b6ba0SEric W. Biederman 
1619805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1620805b5d5eSEric W. Biederman 	if (prev) {
1621e51b6ba0SEric W. Biederman 		head = prev;
1622805b5d5eSEric W. Biederman 		tmp = &prev->ctl_entry;
1623805b5d5eSEric W. Biederman 		unuse_table(prev);
1624805b5d5eSEric W. Biederman 		goto next;
1625805b5d5eSEric W. Biederman 	}
1626805b5d5eSEric W. Biederman 	tmp = &root_table_header.ctl_entry;
1627805b5d5eSEric W. Biederman 	for (;;) {
1628805b5d5eSEric W. Biederman 		head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1629805b5d5eSEric W. Biederman 
1630805b5d5eSEric W. Biederman 		if (!use_table(head))
1631805b5d5eSEric W. Biederman 			goto next;
1632805b5d5eSEric W. Biederman 		spin_unlock(&sysctl_lock);
1633805b5d5eSEric W. Biederman 		return head;
1634805b5d5eSEric W. Biederman 	next:
1635e51b6ba0SEric W. Biederman 		root = head->root;
1636805b5d5eSEric W. Biederman 		tmp = tmp->next;
1637e51b6ba0SEric W. Biederman 		header_list = lookup_header_list(root, namespaces);
1638e51b6ba0SEric W. Biederman 		if (tmp != header_list)
1639e51b6ba0SEric W. Biederman 			continue;
1640e51b6ba0SEric W. Biederman 
1641e51b6ba0SEric W. Biederman 		do {
1642e51b6ba0SEric W. Biederman 			root = list_entry(root->root_list.next,
1643e51b6ba0SEric W. Biederman 					struct ctl_table_root, root_list);
1644e51b6ba0SEric W. Biederman 			if (root == &sysctl_table_root)
1645e51b6ba0SEric W. Biederman 				goto out;
1646e51b6ba0SEric W. Biederman 			header_list = lookup_header_list(root, namespaces);
1647e51b6ba0SEric W. Biederman 		} while (list_empty(header_list));
1648e51b6ba0SEric W. Biederman 		tmp = header_list->next;
1649805b5d5eSEric W. Biederman 	}
1650e51b6ba0SEric W. Biederman out:
1651805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1652805b5d5eSEric W. Biederman 	return NULL;
1653805b5d5eSEric W. Biederman }
1654805b5d5eSEric W. Biederman 
1655e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1656e51b6ba0SEric W. Biederman {
1657e51b6ba0SEric W. Biederman 	return __sysctl_head_next(current->nsproxy, prev);
1658e51b6ba0SEric W. Biederman }
1659e51b6ba0SEric W. Biederman 
1660e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root)
1661e51b6ba0SEric W. Biederman {
1662e51b6ba0SEric W. Biederman 	spin_lock(&sysctl_lock);
1663e51b6ba0SEric W. Biederman 	list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1664e51b6ba0SEric W. Biederman 	spin_unlock(&sysctl_lock);
1665e51b6ba0SEric W. Biederman }
1666e51b6ba0SEric W. Biederman 
1667b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
16682c4c7155SPavel Emelyanov /* Perform the actual read/write of a sysctl table entry. */
1669d7321cd6SPavel Emelyanov static int do_sysctl_strategy(struct ctl_table_root *root,
1670d7321cd6SPavel Emelyanov 			struct ctl_table *table,
16712c4c7155SPavel Emelyanov 			void __user *oldval, size_t __user *oldlenp,
16722c4c7155SPavel Emelyanov 			void __user *newval, size_t newlen)
16732c4c7155SPavel Emelyanov {
16742c4c7155SPavel Emelyanov 	int op = 0, rc;
16752c4c7155SPavel Emelyanov 
16762c4c7155SPavel Emelyanov 	if (oldval)
1677e6305c43SAl Viro 		op |= MAY_READ;
16782c4c7155SPavel Emelyanov 	if (newval)
1679e6305c43SAl Viro 		op |= MAY_WRITE;
1680d7321cd6SPavel Emelyanov 	if (sysctl_perm(root, table, op))
16812c4c7155SPavel Emelyanov 		return -EPERM;
16822c4c7155SPavel Emelyanov 
16832c4c7155SPavel Emelyanov 	if (table->strategy) {
1684f221e726SAlexey Dobriyan 		rc = table->strategy(table, oldval, oldlenp, newval, newlen);
16852c4c7155SPavel Emelyanov 		if (rc < 0)
16862c4c7155SPavel Emelyanov 			return rc;
16872c4c7155SPavel Emelyanov 		if (rc > 0)
16882c4c7155SPavel Emelyanov 			return 0;
16892c4c7155SPavel Emelyanov 	}
16902c4c7155SPavel Emelyanov 
16912c4c7155SPavel Emelyanov 	/* If there is no strategy routine, or if the strategy returns
16922c4c7155SPavel Emelyanov 	 * zero, proceed with automatic r/w */
16932c4c7155SPavel Emelyanov 	if (table->data && table->maxlen) {
1694f221e726SAlexey Dobriyan 		rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
16952c4c7155SPavel Emelyanov 		if (rc < 0)
16962c4c7155SPavel Emelyanov 			return rc;
16972c4c7155SPavel Emelyanov 	}
16982c4c7155SPavel Emelyanov 	return 0;
16992c4c7155SPavel Emelyanov }
17002c4c7155SPavel Emelyanov 
17012c4c7155SPavel Emelyanov static int parse_table(int __user *name, int nlen,
17022c4c7155SPavel Emelyanov 		       void __user *oldval, size_t __user *oldlenp,
17032c4c7155SPavel Emelyanov 		       void __user *newval, size_t newlen,
1704d7321cd6SPavel Emelyanov 		       struct ctl_table_root *root,
17052c4c7155SPavel Emelyanov 		       struct ctl_table *table)
17062c4c7155SPavel Emelyanov {
17072c4c7155SPavel Emelyanov 	int n;
17082c4c7155SPavel Emelyanov repeat:
17092c4c7155SPavel Emelyanov 	if (!nlen)
17102c4c7155SPavel Emelyanov 		return -ENOTDIR;
17112c4c7155SPavel Emelyanov 	if (get_user(n, name))
17122c4c7155SPavel Emelyanov 		return -EFAULT;
17132c4c7155SPavel Emelyanov 	for ( ; table->ctl_name || table->procname; table++) {
17142c4c7155SPavel Emelyanov 		if (!table->ctl_name)
17152c4c7155SPavel Emelyanov 			continue;
17162c4c7155SPavel Emelyanov 		if (n == table->ctl_name) {
17172c4c7155SPavel Emelyanov 			int error;
17182c4c7155SPavel Emelyanov 			if (table->child) {
1719e6305c43SAl Viro 				if (sysctl_perm(root, table, MAY_EXEC))
17202c4c7155SPavel Emelyanov 					return -EPERM;
17212c4c7155SPavel Emelyanov 				name++;
17222c4c7155SPavel Emelyanov 				nlen--;
17232c4c7155SPavel Emelyanov 				table = table->child;
17242c4c7155SPavel Emelyanov 				goto repeat;
17252c4c7155SPavel Emelyanov 			}
1726f221e726SAlexey Dobriyan 			error = do_sysctl_strategy(root, table,
17272c4c7155SPavel Emelyanov 						   oldval, oldlenp,
17282c4c7155SPavel Emelyanov 						   newval, newlen);
17292c4c7155SPavel Emelyanov 			return error;
17302c4c7155SPavel Emelyanov 		}
17312c4c7155SPavel Emelyanov 	}
17322c4c7155SPavel Emelyanov 	return -ENOTDIR;
17332c4c7155SPavel Emelyanov }
17342c4c7155SPavel Emelyanov 
17351da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
17361da177e4SLinus Torvalds 	       void __user *newval, size_t newlen)
17371da177e4SLinus Torvalds {
1738805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1739330d57fbSAl Viro 	int error = -ENOTDIR;
17401da177e4SLinus Torvalds 
17411da177e4SLinus Torvalds 	if (nlen <= 0 || nlen >= CTL_MAXNAME)
17421da177e4SLinus Torvalds 		return -ENOTDIR;
17431da177e4SLinus Torvalds 	if (oldval) {
17441da177e4SLinus Torvalds 		int old_len;
17451da177e4SLinus Torvalds 		if (!oldlenp || get_user(old_len, oldlenp))
17461da177e4SLinus Torvalds 			return -EFAULT;
17471da177e4SLinus Torvalds 	}
1748330d57fbSAl Viro 
1749805b5d5eSEric W. Biederman 	for (head = sysctl_head_next(NULL); head;
1750805b5d5eSEric W. Biederman 			head = sysctl_head_next(head)) {
1751330d57fbSAl Viro 		error = parse_table(name, nlen, oldval, oldlenp,
1752d7321cd6SPavel Emelyanov 					newval, newlen,
1753d7321cd6SPavel Emelyanov 					head->root, head->ctl_table);
1754805b5d5eSEric W. Biederman 		if (error != -ENOTDIR) {
1755805b5d5eSEric W. Biederman 			sysctl_head_finish(head);
1756330d57fbSAl Viro 			break;
1757805b5d5eSEric W. Biederman 		}
1758805b5d5eSEric W. Biederman 	}
17591da177e4SLinus Torvalds 	return error;
17601da177e4SLinus Torvalds }
17611da177e4SLinus Torvalds 
17621e7bfb21SHeiko Carstens SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
17631da177e4SLinus Torvalds {
17641da177e4SLinus Torvalds 	struct __sysctl_args tmp;
17651da177e4SLinus Torvalds 	int error;
17661da177e4SLinus Torvalds 
17671da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
17681da177e4SLinus Torvalds 		return -EFAULT;
17691da177e4SLinus Torvalds 
17707058cb02SEric W. Biederman 	error = deprecated_sysctl_warning(&tmp);
17717058cb02SEric W. Biederman 	if (error)
17727058cb02SEric W. Biederman 		goto out;
17737058cb02SEric W. Biederman 
17741da177e4SLinus Torvalds 	lock_kernel();
17751da177e4SLinus Torvalds 	error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
17761da177e4SLinus Torvalds 			  tmp.newval, tmp.newlen);
17771da177e4SLinus Torvalds 	unlock_kernel();
17787058cb02SEric W. Biederman out:
17791da177e4SLinus Torvalds 	return error;
17801da177e4SLinus Torvalds }
1781b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
17821da177e4SLinus Torvalds 
17831da177e4SLinus Torvalds /*
17841ff007ebSEric W. Biederman  * sysctl_perm does NOT grant the superuser all rights automatically, because
17851da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
17861da177e4SLinus Torvalds  */
17871da177e4SLinus Torvalds 
17881da177e4SLinus Torvalds static int test_perm(int mode, int op)
17891da177e4SLinus Torvalds {
179076aac0e9SDavid Howells 	if (!current_euid())
17911da177e4SLinus Torvalds 		mode >>= 6;
17921da177e4SLinus Torvalds 	else if (in_egroup_p(0))
17931da177e4SLinus Torvalds 		mode >>= 3;
1794e6305c43SAl Viro 	if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
17951da177e4SLinus Torvalds 		return 0;
17961da177e4SLinus Torvalds 	return -EACCES;
17971da177e4SLinus Torvalds }
17981da177e4SLinus Torvalds 
1799d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
18001da177e4SLinus Torvalds {
18011da177e4SLinus Torvalds 	int error;
1802d7321cd6SPavel Emelyanov 	int mode;
1803d7321cd6SPavel Emelyanov 
1804e6305c43SAl Viro 	error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
18051da177e4SLinus Torvalds 	if (error)
18061da177e4SLinus Torvalds 		return error;
1807d7321cd6SPavel Emelyanov 
1808d7321cd6SPavel Emelyanov 	if (root->permissions)
1809d7321cd6SPavel Emelyanov 		mode = root->permissions(root, current->nsproxy, table);
1810d7321cd6SPavel Emelyanov 	else
1811d7321cd6SPavel Emelyanov 		mode = table->mode;
1812d7321cd6SPavel Emelyanov 
1813d7321cd6SPavel Emelyanov 	return test_perm(mode, op);
18141da177e4SLinus Torvalds }
18151da177e4SLinus Torvalds 
1816d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1817d912b0ccSEric W. Biederman {
1818d912b0ccSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
1819d912b0ccSEric W. Biederman 		table->parent = parent;
1820d912b0ccSEric W. Biederman 		if (table->child)
1821d912b0ccSEric W. Biederman 			sysctl_set_parent(table, table->child);
1822d912b0ccSEric W. Biederman 	}
1823d912b0ccSEric W. Biederman }
1824d912b0ccSEric W. Biederman 
1825d912b0ccSEric W. Biederman static __init int sysctl_init(void)
1826d912b0ccSEric W. Biederman {
1827d912b0ccSEric W. Biederman 	sysctl_set_parent(NULL, root_table);
182888f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
182988f458e4SHolger Schurig 	{
183088f458e4SHolger Schurig 		int err;
1831e51b6ba0SEric W. Biederman 		err = sysctl_check_table(current->nsproxy, root_table);
183288f458e4SHolger Schurig 	}
183388f458e4SHolger Schurig #endif
1834d912b0ccSEric W. Biederman 	return 0;
1835d912b0ccSEric W. Biederman }
1836d912b0ccSEric W. Biederman 
1837d912b0ccSEric W. Biederman core_initcall(sysctl_init);
1838d912b0ccSEric W. Biederman 
1839bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch,
1840bfbcf034SAl Viro 				      struct ctl_table *table)
1841ae7edeccSAl Viro {
1842ae7edeccSAl Viro 	struct ctl_table *p;
1843ae7edeccSAl Viro 	const char *s = branch->procname;
1844ae7edeccSAl Viro 
1845ae7edeccSAl Viro 	/* branch should have named subdirectory as its first element */
1846ae7edeccSAl Viro 	if (!s || !branch->child)
1847bfbcf034SAl Viro 		return NULL;
1848ae7edeccSAl Viro 
1849ae7edeccSAl Viro 	/* ... and nothing else */
1850ae7edeccSAl Viro 	if (branch[1].procname || branch[1].ctl_name)
1851bfbcf034SAl Viro 		return NULL;
1852ae7edeccSAl Viro 
1853ae7edeccSAl Viro 	/* table should contain subdirectory with the same name */
1854ae7edeccSAl Viro 	for (p = table; p->procname || p->ctl_name; p++) {
1855ae7edeccSAl Viro 		if (!p->child)
1856ae7edeccSAl Viro 			continue;
1857ae7edeccSAl Viro 		if (p->procname && strcmp(p->procname, s) == 0)
1858bfbcf034SAl Viro 			return p;
1859ae7edeccSAl Viro 	}
1860bfbcf034SAl Viro 	return NULL;
1861ae7edeccSAl Viro }
1862ae7edeccSAl Viro 
1863ae7edeccSAl Viro /* see if attaching q to p would be an improvement */
1864ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1865ae7edeccSAl Viro {
1866ae7edeccSAl Viro 	struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1867bfbcf034SAl Viro 	struct ctl_table *next;
1868ae7edeccSAl Viro 	int is_better = 0;
1869ae7edeccSAl Viro 	int not_in_parent = !p->attached_by;
1870ae7edeccSAl Viro 
1871bfbcf034SAl Viro 	while ((next = is_branch_in(by, to)) != NULL) {
1872ae7edeccSAl Viro 		if (by == q->attached_by)
1873ae7edeccSAl Viro 			is_better = 1;
1874ae7edeccSAl Viro 		if (to == p->attached_by)
1875ae7edeccSAl Viro 			not_in_parent = 1;
1876ae7edeccSAl Viro 		by = by->child;
1877bfbcf034SAl Viro 		to = next->child;
1878ae7edeccSAl Viro 	}
1879ae7edeccSAl Viro 
1880ae7edeccSAl Viro 	if (is_better && not_in_parent) {
1881ae7edeccSAl Viro 		q->attached_by = by;
1882ae7edeccSAl Viro 		q->attached_to = to;
1883ae7edeccSAl Viro 		q->parent = p;
1884ae7edeccSAl Viro 	}
1885ae7edeccSAl Viro }
1886ae7edeccSAl Viro 
18871da177e4SLinus Torvalds /**
1888e51b6ba0SEric W. Biederman  * __register_sysctl_paths - register a sysctl hierarchy
1889e51b6ba0SEric W. Biederman  * @root: List of sysctl headers to register on
1890e51b6ba0SEric W. Biederman  * @namespaces: Data to compute which lists of sysctl entries are visible
189129e796fdSEric W. Biederman  * @path: The path to the directory the sysctl table is in.
18921da177e4SLinus Torvalds  * @table: the top-level table structure
18931da177e4SLinus Torvalds  *
18941da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
189529e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
18961da177e4SLinus Torvalds  *
1897d8217f07SEric W. Biederman  * The members of the &struct ctl_table structure are used as follows:
18981da177e4SLinus Torvalds  *
18991da177e4SLinus Torvalds  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
19001da177e4SLinus Torvalds  *            must be unique within that level of sysctl
19011da177e4SLinus Torvalds  *
19021da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
19031da177e4SLinus Torvalds  *            enter a sysctl file
19041da177e4SLinus Torvalds  *
19051da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
19061da177e4SLinus Torvalds  *
19071da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
19081da177e4SLinus Torvalds  *
19091da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
19101da177e4SLinus Torvalds  *
19111da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
19121da177e4SLinus Torvalds  *         %NULL.
19131da177e4SLinus Torvalds  *
19141da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
19151da177e4SLinus Torvalds  *
19161da177e4SLinus Torvalds  * strategy - the strategy routine (described below)
19171da177e4SLinus Torvalds  *
19181da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
19191da177e4SLinus Torvalds  *
19201da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
19211da177e4SLinus Torvalds  *
19221da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
19231da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
19241da177e4SLinus Torvalds  *
19251da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
19261da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
19271da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
19281da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
19291da177e4SLinus Torvalds  *
19301da177e4SLinus Torvalds  * More sophisticated management can be enabled by the provision of a
19311da177e4SLinus Torvalds  * strategy routine with the table entry.  This will be called before
19321da177e4SLinus Torvalds  * any automatic read or write of the data is performed.
19331da177e4SLinus Torvalds  *
19341da177e4SLinus Torvalds  * The strategy routine may return
19351da177e4SLinus Torvalds  *
19361da177e4SLinus Torvalds  * < 0 - Error occurred (error is passed to user process)
19371da177e4SLinus Torvalds  *
19381da177e4SLinus Torvalds  * 0   - OK - proceed with automatic read or write.
19391da177e4SLinus Torvalds  *
19401da177e4SLinus Torvalds  * > 0 - OK - read or write has been done by the strategy routine, so
19411da177e4SLinus Torvalds  *       return immediately.
19421da177e4SLinus Torvalds  *
19431da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
19441da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
19451da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
19461da177e4SLinus Torvalds  * cover common cases -
19471da177e4SLinus Torvalds  *
19481da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
19491da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
19501da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
19511da177e4SLinus Torvalds  *
19521da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
19531da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
19541da177e4SLinus Torvalds  *
19551da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
19561da177e4SLinus Torvalds  * to the table header on success.
19571da177e4SLinus Torvalds  */
1958e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths(
1959e51b6ba0SEric W. Biederman 	struct ctl_table_root *root,
1960e51b6ba0SEric W. Biederman 	struct nsproxy *namespaces,
1961e51b6ba0SEric W. Biederman 	const struct ctl_path *path, struct ctl_table *table)
19621da177e4SLinus Torvalds {
196329e796fdSEric W. Biederman 	struct ctl_table_header *header;
196429e796fdSEric W. Biederman 	struct ctl_table *new, **prevp;
196529e796fdSEric W. Biederman 	unsigned int n, npath;
1966ae7edeccSAl Viro 	struct ctl_table_set *set;
196729e796fdSEric W. Biederman 
196829e796fdSEric W. Biederman 	/* Count the path components */
196929e796fdSEric W. Biederman 	for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
197029e796fdSEric W. Biederman 		;
197129e796fdSEric W. Biederman 
197229e796fdSEric W. Biederman 	/*
197329e796fdSEric W. Biederman 	 * For each path component, allocate a 2-element ctl_table array.
197429e796fdSEric W. Biederman 	 * The first array element will be filled with the sysctl entry
197529e796fdSEric W. Biederman 	 * for this, the second will be the sentinel (ctl_name == 0).
197629e796fdSEric W. Biederman 	 *
197729e796fdSEric W. Biederman 	 * We allocate everything in one go so that we don't have to
197829e796fdSEric W. Biederman 	 * worry about freeing additional memory in unregister_sysctl_table.
197929e796fdSEric W. Biederman 	 */
198029e796fdSEric W. Biederman 	header = kzalloc(sizeof(struct ctl_table_header) +
198129e796fdSEric W. Biederman 			 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
198229e796fdSEric W. Biederman 	if (!header)
19831da177e4SLinus Torvalds 		return NULL;
198429e796fdSEric W. Biederman 
198529e796fdSEric W. Biederman 	new = (struct ctl_table *) (header + 1);
198629e796fdSEric W. Biederman 
198729e796fdSEric W. Biederman 	/* Now connect the dots */
198829e796fdSEric W. Biederman 	prevp = &header->ctl_table;
198929e796fdSEric W. Biederman 	for (n = 0; n < npath; ++n, ++path) {
199029e796fdSEric W. Biederman 		/* Copy the procname */
199129e796fdSEric W. Biederman 		new->procname = path->procname;
199229e796fdSEric W. Biederman 		new->ctl_name = path->ctl_name;
199329e796fdSEric W. Biederman 		new->mode     = 0555;
199429e796fdSEric W. Biederman 
199529e796fdSEric W. Biederman 		*prevp = new;
199629e796fdSEric W. Biederman 		prevp = &new->child;
199729e796fdSEric W. Biederman 
199829e796fdSEric W. Biederman 		new += 2;
199929e796fdSEric W. Biederman 	}
200029e796fdSEric W. Biederman 	*prevp = table;
200123eb06deSEric W. Biederman 	header->ctl_table_arg = table;
200229e796fdSEric W. Biederman 
200329e796fdSEric W. Biederman 	INIT_LIST_HEAD(&header->ctl_entry);
200429e796fdSEric W. Biederman 	header->used = 0;
200529e796fdSEric W. Biederman 	header->unregistering = NULL;
2006e51b6ba0SEric W. Biederman 	header->root = root;
200729e796fdSEric W. Biederman 	sysctl_set_parent(NULL, header->ctl_table);
2008f7e6ced4SAl Viro 	header->count = 1;
200988f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2010e51b6ba0SEric W. Biederman 	if (sysctl_check_table(namespaces, header->ctl_table)) {
201129e796fdSEric W. Biederman 		kfree(header);
2012fc6cd25bSEric W. Biederman 		return NULL;
2013fc6cd25bSEric W. Biederman 	}
201488f458e4SHolger Schurig #endif
2015330d57fbSAl Viro 	spin_lock(&sysctl_lock);
201673455092SAl Viro 	header->set = lookup_header_set(root, namespaces);
2017ae7edeccSAl Viro 	header->attached_by = header->ctl_table;
2018ae7edeccSAl Viro 	header->attached_to = root_table;
2019ae7edeccSAl Viro 	header->parent = &root_table_header;
2020ae7edeccSAl Viro 	for (set = header->set; set; set = set->parent) {
2021ae7edeccSAl Viro 		struct ctl_table_header *p;
2022ae7edeccSAl Viro 		list_for_each_entry(p, &set->list, ctl_entry) {
2023ae7edeccSAl Viro 			if (p->unregistering)
2024ae7edeccSAl Viro 				continue;
2025ae7edeccSAl Viro 			try_attach(p, header);
2026ae7edeccSAl Viro 		}
2027ae7edeccSAl Viro 	}
2028ae7edeccSAl Viro 	header->parent->count++;
202973455092SAl Viro 	list_add_tail(&header->ctl_entry, &header->set->list);
2030330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
203129e796fdSEric W. Biederman 
203229e796fdSEric W. Biederman 	return header;
203329e796fdSEric W. Biederman }
203429e796fdSEric W. Biederman 
203529e796fdSEric W. Biederman /**
2036e51b6ba0SEric W. Biederman  * register_sysctl_table_path - register a sysctl table hierarchy
2037e51b6ba0SEric W. Biederman  * @path: The path to the directory the sysctl table is in.
2038e51b6ba0SEric W. Biederman  * @table: the top-level table structure
2039e51b6ba0SEric W. Biederman  *
2040e51b6ba0SEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2041e51b6ba0SEric W. Biederman  * array. A completely 0 filled entry terminates the table.
2042e51b6ba0SEric W. Biederman  *
2043e51b6ba0SEric W. Biederman  * See __register_sysctl_paths for more details.
2044e51b6ba0SEric W. Biederman  */
2045e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2046e51b6ba0SEric W. Biederman 						struct ctl_table *table)
2047e51b6ba0SEric W. Biederman {
2048e51b6ba0SEric W. Biederman 	return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2049e51b6ba0SEric W. Biederman 					path, table);
2050e51b6ba0SEric W. Biederman }
2051e51b6ba0SEric W. Biederman 
2052e51b6ba0SEric W. Biederman /**
205329e796fdSEric W. Biederman  * register_sysctl_table - register a sysctl table hierarchy
205429e796fdSEric W. Biederman  * @table: the top-level table structure
205529e796fdSEric W. Biederman  *
205629e796fdSEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
205729e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
205829e796fdSEric W. Biederman  *
205929e796fdSEric W. Biederman  * See register_sysctl_paths for more details.
206029e796fdSEric W. Biederman  */
206129e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
206229e796fdSEric W. Biederman {
206329e796fdSEric W. Biederman 	static const struct ctl_path null_path[] = { {} };
206429e796fdSEric W. Biederman 
206529e796fdSEric W. Biederman 	return register_sysctl_paths(null_path, table);
20661da177e4SLinus Torvalds }
20671da177e4SLinus Torvalds 
20681da177e4SLinus Torvalds /**
20691da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
20701da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
20711da177e4SLinus Torvalds  *
20721da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
20731da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
20741da177e4SLinus Torvalds  */
20751da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
20761da177e4SLinus Torvalds {
2077330d57fbSAl Viro 	might_sleep();
2078f1dad166SPavel Emelyanov 
2079f1dad166SPavel Emelyanov 	if (header == NULL)
2080f1dad166SPavel Emelyanov 		return;
2081f1dad166SPavel Emelyanov 
2082330d57fbSAl Viro 	spin_lock(&sysctl_lock);
2083330d57fbSAl Viro 	start_unregistering(header);
2084ae7edeccSAl Viro 	if (!--header->parent->count) {
2085ae7edeccSAl Viro 		WARN_ON(1);
2086ae7edeccSAl Viro 		kfree(header->parent);
2087ae7edeccSAl Viro 	}
2088f7e6ced4SAl Viro 	if (!--header->count)
20891da177e4SLinus Torvalds 		kfree(header);
2090f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
20911da177e4SLinus Torvalds }
20921da177e4SLinus Torvalds 
20939043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p)
20949043476fSAl Viro {
20959043476fSAl Viro 	struct ctl_table_set *set = p->set;
20969043476fSAl Viro 	int res;
20979043476fSAl Viro 	spin_lock(&sysctl_lock);
20989043476fSAl Viro 	if (p->unregistering)
20999043476fSAl Viro 		res = 0;
21009043476fSAl Viro 	else if (!set->is_seen)
21019043476fSAl Viro 		res = 1;
21029043476fSAl Viro 	else
21039043476fSAl Viro 		res = set->is_seen(set);
21049043476fSAl Viro 	spin_unlock(&sysctl_lock);
21059043476fSAl Viro 	return res;
21069043476fSAl Viro }
21079043476fSAl Viro 
210873455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
210973455092SAl Viro 	struct ctl_table_set *parent,
211073455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
211173455092SAl Viro {
211273455092SAl Viro 	INIT_LIST_HEAD(&p->list);
211373455092SAl Viro 	p->parent = parent ? parent : &sysctl_table_root.default_set;
211473455092SAl Viro 	p->is_seen = is_seen;
211573455092SAl Viro }
211673455092SAl Viro 
2117b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */
2118d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2119b89a8171SEric W. Biederman {
2120b89a8171SEric W. Biederman 	return NULL;
2121b89a8171SEric W. Biederman }
2122b89a8171SEric W. Biederman 
212329e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
212429e796fdSEric W. Biederman 						    struct ctl_table *table)
212529e796fdSEric W. Biederman {
212629e796fdSEric W. Biederman 	return NULL;
212729e796fdSEric W. Biederman }
212829e796fdSEric W. Biederman 
2129b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table)
2130b89a8171SEric W. Biederman {
2131b89a8171SEric W. Biederman }
2132b89a8171SEric W. Biederman 
213373455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
213473455092SAl Viro 	struct ctl_table_set *parent,
213573455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
213673455092SAl Viro {
213773455092SAl Viro }
213873455092SAl Viro 
2139f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
2140f7e6ced4SAl Viro {
2141f7e6ced4SAl Viro }
2142f7e6ced4SAl Viro 
2143b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
2144b89a8171SEric W. Biederman 
21451da177e4SLinus Torvalds /*
21461da177e4SLinus Torvalds  * /proc/sys support
21471da177e4SLinus Torvalds  */
21481da177e4SLinus Torvalds 
2149b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
21501da177e4SLinus Torvalds 
2151b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write,
2152b1ba4dddSAdrian Bunk 			   struct file *filp, void __user *buffer,
2153b1ba4dddSAdrian Bunk 			   size_t *lenp, loff_t *ppos)
2154f5dd3d6fSSam Vilain {
2155f5dd3d6fSSam Vilain 	size_t len;
2156f5dd3d6fSSam Vilain 	char __user *p;
2157f5dd3d6fSSam Vilain 	char c;
2158f5dd3d6fSSam Vilain 
21598d060877SOleg Nesterov 	if (!data || !maxlen || !*lenp) {
2160f5dd3d6fSSam Vilain 		*lenp = 0;
2161f5dd3d6fSSam Vilain 		return 0;
2162f5dd3d6fSSam Vilain 	}
2163f5dd3d6fSSam Vilain 
2164f5dd3d6fSSam Vilain 	if (write) {
2165f5dd3d6fSSam Vilain 		len = 0;
2166f5dd3d6fSSam Vilain 		p = buffer;
2167f5dd3d6fSSam Vilain 		while (len < *lenp) {
2168f5dd3d6fSSam Vilain 			if (get_user(c, p++))
2169f5dd3d6fSSam Vilain 				return -EFAULT;
2170f5dd3d6fSSam Vilain 			if (c == 0 || c == '\n')
2171f5dd3d6fSSam Vilain 				break;
2172f5dd3d6fSSam Vilain 			len++;
2173f5dd3d6fSSam Vilain 		}
2174f5dd3d6fSSam Vilain 		if (len >= maxlen)
2175f5dd3d6fSSam Vilain 			len = maxlen-1;
2176f5dd3d6fSSam Vilain 		if(copy_from_user(data, buffer, len))
2177f5dd3d6fSSam Vilain 			return -EFAULT;
2178f5dd3d6fSSam Vilain 		((char *) data)[len] = 0;
2179f5dd3d6fSSam Vilain 		*ppos += *lenp;
2180f5dd3d6fSSam Vilain 	} else {
2181f5dd3d6fSSam Vilain 		len = strlen(data);
2182f5dd3d6fSSam Vilain 		if (len > maxlen)
2183f5dd3d6fSSam Vilain 			len = maxlen;
21848d060877SOleg Nesterov 
21858d060877SOleg Nesterov 		if (*ppos > len) {
21868d060877SOleg Nesterov 			*lenp = 0;
21878d060877SOleg Nesterov 			return 0;
21888d060877SOleg Nesterov 		}
21898d060877SOleg Nesterov 
21908d060877SOleg Nesterov 		data += *ppos;
21918d060877SOleg Nesterov 		len  -= *ppos;
21928d060877SOleg Nesterov 
2193f5dd3d6fSSam Vilain 		if (len > *lenp)
2194f5dd3d6fSSam Vilain 			len = *lenp;
2195f5dd3d6fSSam Vilain 		if (len)
2196f5dd3d6fSSam Vilain 			if(copy_to_user(buffer, data, len))
2197f5dd3d6fSSam Vilain 				return -EFAULT;
2198f5dd3d6fSSam Vilain 		if (len < *lenp) {
2199f5dd3d6fSSam Vilain 			if(put_user('\n', ((char __user *) buffer) + len))
2200f5dd3d6fSSam Vilain 				return -EFAULT;
2201f5dd3d6fSSam Vilain 			len++;
2202f5dd3d6fSSam Vilain 		}
2203f5dd3d6fSSam Vilain 		*lenp = len;
2204f5dd3d6fSSam Vilain 		*ppos += len;
2205f5dd3d6fSSam Vilain 	}
2206f5dd3d6fSSam Vilain 	return 0;
2207f5dd3d6fSSam Vilain }
2208f5dd3d6fSSam Vilain 
22091da177e4SLinus Torvalds /**
22101da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
22111da177e4SLinus Torvalds  * @table: the sysctl table
22121da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
22131da177e4SLinus Torvalds  * @filp: the file structure
22141da177e4SLinus Torvalds  * @buffer: the user buffer
22151da177e4SLinus Torvalds  * @lenp: the size of the user buffer
22161da177e4SLinus Torvalds  * @ppos: file position
22171da177e4SLinus Torvalds  *
22181da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
22191da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
22201da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
22211da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
22221da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
22231da177e4SLinus Torvalds  * not large enough.
22241da177e4SLinus Torvalds  *
22251da177e4SLinus Torvalds  * Returns 0 on success.
22261da177e4SLinus Torvalds  */
2227d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp,
22281da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
22291da177e4SLinus Torvalds {
2230f5dd3d6fSSam Vilain 	return _proc_do_string(table->data, table->maxlen, write, filp,
2231f5dd3d6fSSam Vilain 			       buffer, lenp, ppos);
22321da177e4SLinus Torvalds }
22331da177e4SLinus Torvalds 
22341da177e4SLinus Torvalds 
22351da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
22361da177e4SLinus Torvalds 				 int *valp,
22371da177e4SLinus Torvalds 				 int write, void *data)
22381da177e4SLinus Torvalds {
22391da177e4SLinus Torvalds 	if (write) {
22401da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
22411da177e4SLinus Torvalds 	} else {
22421da177e4SLinus Torvalds 		int val = *valp;
22431da177e4SLinus Torvalds 		if (val < 0) {
22441da177e4SLinus Torvalds 			*negp = -1;
22451da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
22461da177e4SLinus Torvalds 		} else {
22471da177e4SLinus Torvalds 			*negp = 0;
22481da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
22491da177e4SLinus Torvalds 		}
22501da177e4SLinus Torvalds 	}
22511da177e4SLinus Torvalds 	return 0;
22521da177e4SLinus Torvalds }
22531da177e4SLinus Torvalds 
2254d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2255fcfbd547SKirill Korotaev 		  int write, struct file *filp, void __user *buffer,
2256fcfbd547SKirill Korotaev 		  size_t *lenp, loff_t *ppos,
22571da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
22581da177e4SLinus Torvalds 			      int write, void *data),
22591da177e4SLinus Torvalds 		  void *data)
22601da177e4SLinus Torvalds {
22611da177e4SLinus Torvalds #define TMPBUFLEN 21
22621da177e4SLinus Torvalds 	int *i, vleft, first=1, neg, val;
22631da177e4SLinus Torvalds 	unsigned long lval;
22641da177e4SLinus Torvalds 	size_t left, len;
22651da177e4SLinus Torvalds 
22661da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
22671da177e4SLinus Torvalds 	char __user *s = buffer;
22681da177e4SLinus Torvalds 
2269fcfbd547SKirill Korotaev 	if (!tbl_data || !table->maxlen || !*lenp ||
22701da177e4SLinus Torvalds 	    (*ppos && !write)) {
22711da177e4SLinus Torvalds 		*lenp = 0;
22721da177e4SLinus Torvalds 		return 0;
22731da177e4SLinus Torvalds 	}
22741da177e4SLinus Torvalds 
2275fcfbd547SKirill Korotaev 	i = (int *) tbl_data;
22761da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
22771da177e4SLinus Torvalds 	left = *lenp;
22781da177e4SLinus Torvalds 
22791da177e4SLinus Torvalds 	if (!conv)
22801da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
22811da177e4SLinus Torvalds 
22821da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
22831da177e4SLinus Torvalds 		if (write) {
22841da177e4SLinus Torvalds 			while (left) {
22851da177e4SLinus Torvalds 				char c;
22861da177e4SLinus Torvalds 				if (get_user(c, s))
22871da177e4SLinus Torvalds 					return -EFAULT;
22881da177e4SLinus Torvalds 				if (!isspace(c))
22891da177e4SLinus Torvalds 					break;
22901da177e4SLinus Torvalds 				left--;
22911da177e4SLinus Torvalds 				s++;
22921da177e4SLinus Torvalds 			}
22931da177e4SLinus Torvalds 			if (!left)
22941da177e4SLinus Torvalds 				break;
22951da177e4SLinus Torvalds 			neg = 0;
22961da177e4SLinus Torvalds 			len = left;
22971da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
22981da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
22991da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
23001da177e4SLinus Torvalds 				return -EFAULT;
23011da177e4SLinus Torvalds 			buf[len] = 0;
23021da177e4SLinus Torvalds 			p = buf;
23031da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
23041da177e4SLinus Torvalds 				neg = 1;
2305bd9b0bacSBP, Praveen 				p++;
23061da177e4SLinus Torvalds 			}
23071da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
23081da177e4SLinus Torvalds 				break;
23091da177e4SLinus Torvalds 
23101da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
23111da177e4SLinus Torvalds 
23121da177e4SLinus Torvalds 			len = p-buf;
23131da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
23141da177e4SLinus Torvalds 				break;
23151da177e4SLinus Torvalds 			if (neg)
23161da177e4SLinus Torvalds 				val = -val;
23171da177e4SLinus Torvalds 			s += len;
23181da177e4SLinus Torvalds 			left -= len;
23191da177e4SLinus Torvalds 
23201da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
23211da177e4SLinus Torvalds 				break;
23221da177e4SLinus Torvalds 		} else {
23231da177e4SLinus Torvalds 			p = buf;
23241da177e4SLinus Torvalds 			if (!first)
23251da177e4SLinus Torvalds 				*p++ = '\t';
23261da177e4SLinus Torvalds 
23271da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
23281da177e4SLinus Torvalds 				break;
23291da177e4SLinus Torvalds 
23301da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
23311da177e4SLinus Torvalds 			len = strlen(buf);
23321da177e4SLinus Torvalds 			if (len > left)
23331da177e4SLinus Torvalds 				len = left;
23341da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
23351da177e4SLinus Torvalds 				return -EFAULT;
23361da177e4SLinus Torvalds 			left -= len;
23371da177e4SLinus Torvalds 			s += len;
23381da177e4SLinus Torvalds 		}
23391da177e4SLinus Torvalds 	}
23401da177e4SLinus Torvalds 
23411da177e4SLinus Torvalds 	if (!write && !first && left) {
23421da177e4SLinus Torvalds 		if(put_user('\n', s))
23431da177e4SLinus Torvalds 			return -EFAULT;
23441da177e4SLinus Torvalds 		left--, s++;
23451da177e4SLinus Torvalds 	}
23461da177e4SLinus Torvalds 	if (write) {
23471da177e4SLinus Torvalds 		while (left) {
23481da177e4SLinus Torvalds 			char c;
23491da177e4SLinus Torvalds 			if (get_user(c, s++))
23501da177e4SLinus Torvalds 				return -EFAULT;
23511da177e4SLinus Torvalds 			if (!isspace(c))
23521da177e4SLinus Torvalds 				break;
23531da177e4SLinus Torvalds 			left--;
23541da177e4SLinus Torvalds 		}
23551da177e4SLinus Torvalds 	}
23561da177e4SLinus Torvalds 	if (write && first)
23571da177e4SLinus Torvalds 		return -EINVAL;
23581da177e4SLinus Torvalds 	*lenp -= left;
23591da177e4SLinus Torvalds 	*ppos += *lenp;
23601da177e4SLinus Torvalds 	return 0;
23611da177e4SLinus Torvalds #undef TMPBUFLEN
23621da177e4SLinus Torvalds }
23631da177e4SLinus Torvalds 
2364d8217f07SEric W. Biederman static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2365fcfbd547SKirill Korotaev 		  void __user *buffer, size_t *lenp, loff_t *ppos,
2366fcfbd547SKirill Korotaev 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2367fcfbd547SKirill Korotaev 			      int write, void *data),
2368fcfbd547SKirill Korotaev 		  void *data)
2369fcfbd547SKirill Korotaev {
2370fcfbd547SKirill Korotaev 	return __do_proc_dointvec(table->data, table, write, filp,
2371fcfbd547SKirill Korotaev 			buffer, lenp, ppos, conv, data);
2372fcfbd547SKirill Korotaev }
2373fcfbd547SKirill Korotaev 
23741da177e4SLinus Torvalds /**
23751da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
23761da177e4SLinus Torvalds  * @table: the sysctl table
23771da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23781da177e4SLinus Torvalds  * @filp: the file structure
23791da177e4SLinus Torvalds  * @buffer: the user buffer
23801da177e4SLinus Torvalds  * @lenp: the size of the user buffer
23811da177e4SLinus Torvalds  * @ppos: file position
23821da177e4SLinus Torvalds  *
23831da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23841da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23851da177e4SLinus Torvalds  *
23861da177e4SLinus Torvalds  * Returns 0 on success.
23871da177e4SLinus Torvalds  */
2388d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
23891da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
23901da177e4SLinus Torvalds {
23911da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
23921da177e4SLinus Torvalds 		    	    NULL,NULL);
23931da177e4SLinus Torvalds }
23941da177e4SLinus Torvalds 
239534f5a398STheodore Ts'o /*
239634f5a398STheodore Ts'o  * Taint values can only be increased
239725ddbb18SAndi Kleen  * This means we can safely use a temporary.
239834f5a398STheodore Ts'o  */
239925ddbb18SAndi Kleen static int proc_taint(struct ctl_table *table, int write, struct file *filp,
240034f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos)
240134f5a398STheodore Ts'o {
240225ddbb18SAndi Kleen 	struct ctl_table t;
240325ddbb18SAndi Kleen 	unsigned long tmptaint = get_taint();
240425ddbb18SAndi Kleen 	int err;
240534f5a398STheodore Ts'o 
240691fcd412SBastian Blank 	if (write && !capable(CAP_SYS_ADMIN))
240734f5a398STheodore Ts'o 		return -EPERM;
240834f5a398STheodore Ts'o 
240925ddbb18SAndi Kleen 	t = *table;
241025ddbb18SAndi Kleen 	t.data = &tmptaint;
241125ddbb18SAndi Kleen 	err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
241225ddbb18SAndi Kleen 	if (err < 0)
241325ddbb18SAndi Kleen 		return err;
241425ddbb18SAndi Kleen 
241525ddbb18SAndi Kleen 	if (write) {
241625ddbb18SAndi Kleen 		/*
241725ddbb18SAndi Kleen 		 * Poor man's atomic or. Not worth adding a primitive
241825ddbb18SAndi Kleen 		 * to everyone's atomic.h for this
241925ddbb18SAndi Kleen 		 */
242025ddbb18SAndi Kleen 		int i;
242125ddbb18SAndi Kleen 		for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
242225ddbb18SAndi Kleen 			if ((tmptaint >> i) & 1)
242325ddbb18SAndi Kleen 				add_taint(i);
242425ddbb18SAndi Kleen 		}
242525ddbb18SAndi Kleen 	}
242625ddbb18SAndi Kleen 
242725ddbb18SAndi Kleen 	return err;
242834f5a398STheodore Ts'o }
242934f5a398STheodore Ts'o 
24301da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
24311da177e4SLinus Torvalds 	int *min;
24321da177e4SLinus Torvalds 	int *max;
24331da177e4SLinus Torvalds };
24341da177e4SLinus Torvalds 
24351da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
24361da177e4SLinus Torvalds 					int *valp,
24371da177e4SLinus Torvalds 					int write, void *data)
24381da177e4SLinus Torvalds {
24391da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
24401da177e4SLinus Torvalds 	if (write) {
24411da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
24421da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
24431da177e4SLinus Torvalds 		    (param->max && *param->max < val))
24441da177e4SLinus Torvalds 			return -EINVAL;
24451da177e4SLinus Torvalds 		*valp = val;
24461da177e4SLinus Torvalds 	} else {
24471da177e4SLinus Torvalds 		int val = *valp;
24481da177e4SLinus Torvalds 		if (val < 0) {
24491da177e4SLinus Torvalds 			*negp = -1;
24501da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
24511da177e4SLinus Torvalds 		} else {
24521da177e4SLinus Torvalds 			*negp = 0;
24531da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
24541da177e4SLinus Torvalds 		}
24551da177e4SLinus Torvalds 	}
24561da177e4SLinus Torvalds 	return 0;
24571da177e4SLinus Torvalds }
24581da177e4SLinus Torvalds 
24591da177e4SLinus Torvalds /**
24601da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
24611da177e4SLinus Torvalds  * @table: the sysctl table
24621da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
24631da177e4SLinus Torvalds  * @filp: the file structure
24641da177e4SLinus Torvalds  * @buffer: the user buffer
24651da177e4SLinus Torvalds  * @lenp: the size of the user buffer
24661da177e4SLinus Torvalds  * @ppos: file position
24671da177e4SLinus Torvalds  *
24681da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
24691da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
24701da177e4SLinus Torvalds  *
24711da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
24721da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
24731da177e4SLinus Torvalds  *
24741da177e4SLinus Torvalds  * Returns 0 on success.
24751da177e4SLinus Torvalds  */
2476d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
24771da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
24781da177e4SLinus Torvalds {
24791da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
24801da177e4SLinus Torvalds 		.min = (int *) table->extra1,
24811da177e4SLinus Torvalds 		.max = (int *) table->extra2,
24821da177e4SLinus Torvalds 	};
24831da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
24841da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
24851da177e4SLinus Torvalds }
24861da177e4SLinus Torvalds 
2487d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
24881da177e4SLinus Torvalds 				     struct file *filp,
24891da177e4SLinus Torvalds 				     void __user *buffer,
24901da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
24911da177e4SLinus Torvalds 				     unsigned long convmul,
24921da177e4SLinus Torvalds 				     unsigned long convdiv)
24931da177e4SLinus Torvalds {
24941da177e4SLinus Torvalds #define TMPBUFLEN 21
24951da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
24961da177e4SLinus Torvalds 	int vleft, first=1, neg;
24971da177e4SLinus Torvalds 	size_t len, left;
24981da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
24991da177e4SLinus Torvalds 	char __user *s = buffer;
25001da177e4SLinus Torvalds 
2501fcfbd547SKirill Korotaev 	if (!data || !table->maxlen || !*lenp ||
25021da177e4SLinus Torvalds 	    (*ppos && !write)) {
25031da177e4SLinus Torvalds 		*lenp = 0;
25041da177e4SLinus Torvalds 		return 0;
25051da177e4SLinus Torvalds 	}
25061da177e4SLinus Torvalds 
2507fcfbd547SKirill Korotaev 	i = (unsigned long *) data;
25081da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
25091da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
25101da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
25111da177e4SLinus Torvalds 	left = *lenp;
25121da177e4SLinus Torvalds 
25131da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
25141da177e4SLinus Torvalds 		if (write) {
25151da177e4SLinus Torvalds 			while (left) {
25161da177e4SLinus Torvalds 				char c;
25171da177e4SLinus Torvalds 				if (get_user(c, s))
25181da177e4SLinus Torvalds 					return -EFAULT;
25191da177e4SLinus Torvalds 				if (!isspace(c))
25201da177e4SLinus Torvalds 					break;
25211da177e4SLinus Torvalds 				left--;
25221da177e4SLinus Torvalds 				s++;
25231da177e4SLinus Torvalds 			}
25241da177e4SLinus Torvalds 			if (!left)
25251da177e4SLinus Torvalds 				break;
25261da177e4SLinus Torvalds 			neg = 0;
25271da177e4SLinus Torvalds 			len = left;
25281da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
25291da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
25301da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
25311da177e4SLinus Torvalds 				return -EFAULT;
25321da177e4SLinus Torvalds 			buf[len] = 0;
25331da177e4SLinus Torvalds 			p = buf;
25341da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
25351da177e4SLinus Torvalds 				neg = 1;
2536bd9b0bacSBP, Praveen 				p++;
25371da177e4SLinus Torvalds 			}
25381da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
25391da177e4SLinus Torvalds 				break;
25401da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
25411da177e4SLinus Torvalds 			len = p-buf;
25421da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
25431da177e4SLinus Torvalds 				break;
25441da177e4SLinus Torvalds 			if (neg)
25451da177e4SLinus Torvalds 				val = -val;
25461da177e4SLinus Torvalds 			s += len;
25471da177e4SLinus Torvalds 			left -= len;
25481da177e4SLinus Torvalds 
25491da177e4SLinus Torvalds 			if(neg)
25501da177e4SLinus Torvalds 				continue;
25511da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
25521da177e4SLinus Torvalds 				continue;
25531da177e4SLinus Torvalds 			*i = val;
25541da177e4SLinus Torvalds 		} else {
25551da177e4SLinus Torvalds 			p = buf;
25561da177e4SLinus Torvalds 			if (!first)
25571da177e4SLinus Torvalds 				*p++ = '\t';
25581da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
25591da177e4SLinus Torvalds 			len = strlen(buf);
25601da177e4SLinus Torvalds 			if (len > left)
25611da177e4SLinus Torvalds 				len = left;
25621da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
25631da177e4SLinus Torvalds 				return -EFAULT;
25641da177e4SLinus Torvalds 			left -= len;
25651da177e4SLinus Torvalds 			s += len;
25661da177e4SLinus Torvalds 		}
25671da177e4SLinus Torvalds 	}
25681da177e4SLinus Torvalds 
25691da177e4SLinus Torvalds 	if (!write && !first && left) {
25701da177e4SLinus Torvalds 		if(put_user('\n', s))
25711da177e4SLinus Torvalds 			return -EFAULT;
25721da177e4SLinus Torvalds 		left--, s++;
25731da177e4SLinus Torvalds 	}
25741da177e4SLinus Torvalds 	if (write) {
25751da177e4SLinus Torvalds 		while (left) {
25761da177e4SLinus Torvalds 			char c;
25771da177e4SLinus Torvalds 			if (get_user(c, s++))
25781da177e4SLinus Torvalds 				return -EFAULT;
25791da177e4SLinus Torvalds 			if (!isspace(c))
25801da177e4SLinus Torvalds 				break;
25811da177e4SLinus Torvalds 			left--;
25821da177e4SLinus Torvalds 		}
25831da177e4SLinus Torvalds 	}
25841da177e4SLinus Torvalds 	if (write && first)
25851da177e4SLinus Torvalds 		return -EINVAL;
25861da177e4SLinus Torvalds 	*lenp -= left;
25871da177e4SLinus Torvalds 	*ppos += *lenp;
25881da177e4SLinus Torvalds 	return 0;
25891da177e4SLinus Torvalds #undef TMPBUFLEN
25901da177e4SLinus Torvalds }
25911da177e4SLinus Torvalds 
2592d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2593fcfbd547SKirill Korotaev 				     struct file *filp,
2594fcfbd547SKirill Korotaev 				     void __user *buffer,
2595fcfbd547SKirill Korotaev 				     size_t *lenp, loff_t *ppos,
2596fcfbd547SKirill Korotaev 				     unsigned long convmul,
2597fcfbd547SKirill Korotaev 				     unsigned long convdiv)
2598fcfbd547SKirill Korotaev {
2599fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(table->data, table, write,
2600fcfbd547SKirill Korotaev 			filp, buffer, lenp, ppos, convmul, convdiv);
2601fcfbd547SKirill Korotaev }
2602fcfbd547SKirill Korotaev 
26031da177e4SLinus Torvalds /**
26041da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
26051da177e4SLinus Torvalds  * @table: the sysctl table
26061da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
26071da177e4SLinus Torvalds  * @filp: the file structure
26081da177e4SLinus Torvalds  * @buffer: the user buffer
26091da177e4SLinus Torvalds  * @lenp: the size of the user buffer
26101da177e4SLinus Torvalds  * @ppos: file position
26111da177e4SLinus Torvalds  *
26121da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
26131da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
26141da177e4SLinus Torvalds  *
26151da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
26161da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
26171da177e4SLinus Torvalds  *
26181da177e4SLinus Torvalds  * Returns 0 on success.
26191da177e4SLinus Torvalds  */
2620d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
26211da177e4SLinus Torvalds 			   void __user *buffer, size_t *lenp, loff_t *ppos)
26221da177e4SLinus Torvalds {
26231da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
26241da177e4SLinus Torvalds }
26251da177e4SLinus Torvalds 
26261da177e4SLinus Torvalds /**
26271da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
26281da177e4SLinus Torvalds  * @table: the sysctl table
26291da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
26301da177e4SLinus Torvalds  * @filp: the file structure
26311da177e4SLinus Torvalds  * @buffer: the user buffer
26321da177e4SLinus Torvalds  * @lenp: the size of the user buffer
26331da177e4SLinus Torvalds  * @ppos: file position
26341da177e4SLinus Torvalds  *
26351da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
26361da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
26371da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
26381da177e4SLinus Torvalds  *
26391da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
26401da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
26411da177e4SLinus Torvalds  *
26421da177e4SLinus Torvalds  * Returns 0 on success.
26431da177e4SLinus Torvalds  */
2644d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
26451da177e4SLinus Torvalds 				      struct file *filp,
26461da177e4SLinus Torvalds 				      void __user *buffer,
26471da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
26481da177e4SLinus Torvalds {
26491da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer,
26501da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
26511da177e4SLinus Torvalds }
26521da177e4SLinus Torvalds 
26531da177e4SLinus Torvalds 
26541da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
26551da177e4SLinus Torvalds 					 int *valp,
26561da177e4SLinus Torvalds 					 int write, void *data)
26571da177e4SLinus Torvalds {
26581da177e4SLinus Torvalds 	if (write) {
2659cba9f33dSBart Samwel 		if (*lvalp > LONG_MAX / HZ)
2660cba9f33dSBart Samwel 			return 1;
26611da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
26621da177e4SLinus Torvalds 	} else {
26631da177e4SLinus Torvalds 		int val = *valp;
26641da177e4SLinus Torvalds 		unsigned long lval;
26651da177e4SLinus Torvalds 		if (val < 0) {
26661da177e4SLinus Torvalds 			*negp = -1;
26671da177e4SLinus Torvalds 			lval = (unsigned long)-val;
26681da177e4SLinus Torvalds 		} else {
26691da177e4SLinus Torvalds 			*negp = 0;
26701da177e4SLinus Torvalds 			lval = (unsigned long)val;
26711da177e4SLinus Torvalds 		}
26721da177e4SLinus Torvalds 		*lvalp = lval / HZ;
26731da177e4SLinus Torvalds 	}
26741da177e4SLinus Torvalds 	return 0;
26751da177e4SLinus Torvalds }
26761da177e4SLinus Torvalds 
26771da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
26781da177e4SLinus Torvalds 						int *valp,
26791da177e4SLinus Torvalds 						int write, void *data)
26801da177e4SLinus Torvalds {
26811da177e4SLinus Torvalds 	if (write) {
2682cba9f33dSBart Samwel 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2683cba9f33dSBart Samwel 			return 1;
26841da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
26851da177e4SLinus Torvalds 	} else {
26861da177e4SLinus Torvalds 		int val = *valp;
26871da177e4SLinus Torvalds 		unsigned long lval;
26881da177e4SLinus Torvalds 		if (val < 0) {
26891da177e4SLinus Torvalds 			*negp = -1;
26901da177e4SLinus Torvalds 			lval = (unsigned long)-val;
26911da177e4SLinus Torvalds 		} else {
26921da177e4SLinus Torvalds 			*negp = 0;
26931da177e4SLinus Torvalds 			lval = (unsigned long)val;
26941da177e4SLinus Torvalds 		}
26951da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
26961da177e4SLinus Torvalds 	}
26971da177e4SLinus Torvalds 	return 0;
26981da177e4SLinus Torvalds }
26991da177e4SLinus Torvalds 
27001da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
27011da177e4SLinus Torvalds 					    int *valp,
27021da177e4SLinus Torvalds 					    int write, void *data)
27031da177e4SLinus Torvalds {
27041da177e4SLinus Torvalds 	if (write) {
27051da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
27061da177e4SLinus Torvalds 	} else {
27071da177e4SLinus Torvalds 		int val = *valp;
27081da177e4SLinus Torvalds 		unsigned long lval;
27091da177e4SLinus Torvalds 		if (val < 0) {
27101da177e4SLinus Torvalds 			*negp = -1;
27111da177e4SLinus Torvalds 			lval = (unsigned long)-val;
27121da177e4SLinus Torvalds 		} else {
27131da177e4SLinus Torvalds 			*negp = 0;
27141da177e4SLinus Torvalds 			lval = (unsigned long)val;
27151da177e4SLinus Torvalds 		}
27161da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
27171da177e4SLinus Torvalds 	}
27181da177e4SLinus Torvalds 	return 0;
27191da177e4SLinus Torvalds }
27201da177e4SLinus Torvalds 
27211da177e4SLinus Torvalds /**
27221da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
27231da177e4SLinus Torvalds  * @table: the sysctl table
27241da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
27251da177e4SLinus Torvalds  * @filp: the file structure
27261da177e4SLinus Torvalds  * @buffer: the user buffer
27271da177e4SLinus Torvalds  * @lenp: the size of the user buffer
27281da177e4SLinus Torvalds  * @ppos: file position
27291da177e4SLinus Torvalds  *
27301da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
27311da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
27321da177e4SLinus Torvalds  * The values read are assumed to be in seconds, and are converted into
27331da177e4SLinus Torvalds  * jiffies.
27341da177e4SLinus Torvalds  *
27351da177e4SLinus Torvalds  * Returns 0 on success.
27361da177e4SLinus Torvalds  */
2737d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
27381da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
27391da177e4SLinus Torvalds {
27401da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
27411da177e4SLinus Torvalds 		    	    do_proc_dointvec_jiffies_conv,NULL);
27421da177e4SLinus Torvalds }
27431da177e4SLinus Torvalds 
27441da177e4SLinus Torvalds /**
27451da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
27461da177e4SLinus Torvalds  * @table: the sysctl table
27471da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
27481da177e4SLinus Torvalds  * @filp: the file structure
27491da177e4SLinus Torvalds  * @buffer: the user buffer
27501da177e4SLinus Torvalds  * @lenp: the size of the user buffer
27511e5d5331SRandy Dunlap  * @ppos: pointer to the file position
27521da177e4SLinus Torvalds  *
27531da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
27541da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
27551da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
27561da177e4SLinus Torvalds  * are converted into jiffies.
27571da177e4SLinus Torvalds  *
27581da177e4SLinus Torvalds  * Returns 0 on success.
27591da177e4SLinus Torvalds  */
2760d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
27611da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
27621da177e4SLinus Torvalds {
27631da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
27641da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
27651da177e4SLinus Torvalds }
27661da177e4SLinus Torvalds 
27671da177e4SLinus Torvalds /**
27681da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
27691da177e4SLinus Torvalds  * @table: the sysctl table
27701da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
27711da177e4SLinus Torvalds  * @filp: the file structure
27721da177e4SLinus Torvalds  * @buffer: the user buffer
27731da177e4SLinus Torvalds  * @lenp: the size of the user buffer
277467be2dd1SMartin Waitz  * @ppos: file position
277567be2dd1SMartin Waitz  * @ppos: the current position in the file
27761da177e4SLinus Torvalds  *
27771da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
27781da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
27791da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
27801da177e4SLinus Torvalds  * are converted into jiffies.
27811da177e4SLinus Torvalds  *
27821da177e4SLinus Torvalds  * Returns 0 on success.
27831da177e4SLinus Torvalds  */
2784d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
27851da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
27861da177e4SLinus Torvalds {
27871da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
27881da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
27891da177e4SLinus Torvalds }
27901da177e4SLinus Torvalds 
2791d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
27929ec52099SCedric Le Goater 			   void __user *buffer, size_t *lenp, loff_t *ppos)
27939ec52099SCedric Le Goater {
27949ec52099SCedric Le Goater 	struct pid *new_pid;
27959ec52099SCedric Le Goater 	pid_t tmp;
27969ec52099SCedric Le Goater 	int r;
27979ec52099SCedric Le Goater 
27986c5f3e7bSPavel Emelyanov 	tmp = pid_vnr(cad_pid);
27999ec52099SCedric Le Goater 
28009ec52099SCedric Le Goater 	r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
28019ec52099SCedric Le Goater 			       lenp, ppos, NULL, NULL);
28029ec52099SCedric Le Goater 	if (r || !write)
28039ec52099SCedric Le Goater 		return r;
28049ec52099SCedric Le Goater 
28059ec52099SCedric Le Goater 	new_pid = find_get_pid(tmp);
28069ec52099SCedric Le Goater 	if (!new_pid)
28079ec52099SCedric Le Goater 		return -ESRCH;
28089ec52099SCedric Le Goater 
28099ec52099SCedric Le Goater 	put_pid(xchg(&cad_pid, new_pid));
28109ec52099SCedric Le Goater 	return 0;
28119ec52099SCedric Le Goater }
28129ec52099SCedric Le Goater 
28131da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
28141da177e4SLinus Torvalds 
2815d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp,
28161da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
28171da177e4SLinus Torvalds {
28181da177e4SLinus Torvalds 	return -ENOSYS;
28191da177e4SLinus Torvalds }
28201da177e4SLinus Torvalds 
2821d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
28221da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
28231da177e4SLinus Torvalds {
28241da177e4SLinus Torvalds 	return -ENOSYS;
28251da177e4SLinus Torvalds }
28261da177e4SLinus Torvalds 
2827d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
28281da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28291da177e4SLinus Torvalds {
28301da177e4SLinus Torvalds 	return -ENOSYS;
28311da177e4SLinus Torvalds }
28321da177e4SLinus Torvalds 
2833d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
28341da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28351da177e4SLinus Torvalds {
28361da177e4SLinus Torvalds 	return -ENOSYS;
28371da177e4SLinus Torvalds }
28381da177e4SLinus Torvalds 
2839d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
28401da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28411da177e4SLinus Torvalds {
28421da177e4SLinus Torvalds 	return -ENOSYS;
28431da177e4SLinus Torvalds }
28441da177e4SLinus Torvalds 
2845d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
28461da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
28471da177e4SLinus Torvalds {
28481da177e4SLinus Torvalds 	return -ENOSYS;
28491da177e4SLinus Torvalds }
28501da177e4SLinus Torvalds 
2851d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
28521da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28531da177e4SLinus Torvalds {
28541da177e4SLinus Torvalds 	return -ENOSYS;
28551da177e4SLinus Torvalds }
28561da177e4SLinus Torvalds 
2857d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
28581da177e4SLinus Torvalds 				      struct file *filp,
28591da177e4SLinus Torvalds 				      void __user *buffer,
28601da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
28611da177e4SLinus Torvalds {
28621da177e4SLinus Torvalds     return -ENOSYS;
28631da177e4SLinus Torvalds }
28641da177e4SLinus Torvalds 
28651da177e4SLinus Torvalds 
28661da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
28671da177e4SLinus Torvalds 
28681da177e4SLinus Torvalds 
2869b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
28701da177e4SLinus Torvalds /*
28711da177e4SLinus Torvalds  * General sysctl support routines
28721da177e4SLinus Torvalds  */
28731da177e4SLinus Torvalds 
287449a0c458SEric W. Biederman /* The generic sysctl data routine (used if no strategy routine supplied) */
2875f221e726SAlexey Dobriyan int sysctl_data(struct ctl_table *table,
287649a0c458SEric W. Biederman 		void __user *oldval, size_t __user *oldlenp,
287749a0c458SEric W. Biederman 		void __user *newval, size_t newlen)
287849a0c458SEric W. Biederman {
287949a0c458SEric W. Biederman 	size_t len;
288049a0c458SEric W. Biederman 
288149a0c458SEric W. Biederman 	/* Get out of I don't have a variable */
288249a0c458SEric W. Biederman 	if (!table->data || !table->maxlen)
288349a0c458SEric W. Biederman 		return -ENOTDIR;
288449a0c458SEric W. Biederman 
288549a0c458SEric W. Biederman 	if (oldval && oldlenp) {
288649a0c458SEric W. Biederman 		if (get_user(len, oldlenp))
288749a0c458SEric W. Biederman 			return -EFAULT;
288849a0c458SEric W. Biederman 		if (len) {
288949a0c458SEric W. Biederman 			if (len > table->maxlen)
289049a0c458SEric W. Biederman 				len = table->maxlen;
289149a0c458SEric W. Biederman 			if (copy_to_user(oldval, table->data, len))
289249a0c458SEric W. Biederman 				return -EFAULT;
289349a0c458SEric W. Biederman 			if (put_user(len, oldlenp))
289449a0c458SEric W. Biederman 				return -EFAULT;
289549a0c458SEric W. Biederman 		}
289649a0c458SEric W. Biederman 	}
289749a0c458SEric W. Biederman 
289849a0c458SEric W. Biederman 	if (newval && newlen) {
289949a0c458SEric W. Biederman 		if (newlen > table->maxlen)
290049a0c458SEric W. Biederman 			newlen = table->maxlen;
290149a0c458SEric W. Biederman 
290249a0c458SEric W. Biederman 		if (copy_from_user(table->data, newval, newlen))
290349a0c458SEric W. Biederman 			return -EFAULT;
290449a0c458SEric W. Biederman 	}
290549a0c458SEric W. Biederman 	return 1;
290649a0c458SEric W. Biederman }
290749a0c458SEric W. Biederman 
29081da177e4SLinus Torvalds /* The generic string strategy routine: */
2909f221e726SAlexey Dobriyan int sysctl_string(struct ctl_table *table,
29101da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
29111f29bcd7SAlexey Dobriyan 		  void __user *newval, size_t newlen)
29121da177e4SLinus Torvalds {
29131da177e4SLinus Torvalds 	if (!table->data || !table->maxlen)
29141da177e4SLinus Torvalds 		return -ENOTDIR;
29151da177e4SLinus Torvalds 
29161da177e4SLinus Torvalds 	if (oldval && oldlenp) {
2917de9e007dSLinus Torvalds 		size_t bufsize;
2918de9e007dSLinus Torvalds 		if (get_user(bufsize, oldlenp))
29191da177e4SLinus Torvalds 			return -EFAULT;
2920de9e007dSLinus Torvalds 		if (bufsize) {
2921de9e007dSLinus Torvalds 			size_t len = strlen(table->data), copied;
2922de9e007dSLinus Torvalds 
2923de9e007dSLinus Torvalds 			/* This shouldn't trigger for a well-formed sysctl */
2924de9e007dSLinus Torvalds 			if (len > table->maxlen)
29251da177e4SLinus Torvalds 				len = table->maxlen;
2926de9e007dSLinus Torvalds 
2927de9e007dSLinus Torvalds 			/* Copy up to a max of bufsize-1 bytes of the string */
2928de9e007dSLinus Torvalds 			copied = (len >= bufsize) ? bufsize - 1 : len;
2929de9e007dSLinus Torvalds 
2930de9e007dSLinus Torvalds 			if (copy_to_user(oldval, table->data, copied) ||
2931de9e007dSLinus Torvalds 			    put_user(0, (char __user *)(oldval + copied)))
29321da177e4SLinus Torvalds 				return -EFAULT;
29331da177e4SLinus Torvalds 			if (put_user(len, oldlenp))
29341da177e4SLinus Torvalds 				return -EFAULT;
29351da177e4SLinus Torvalds 		}
29361da177e4SLinus Torvalds 	}
29371da177e4SLinus Torvalds 	if (newval && newlen) {
2938de9e007dSLinus Torvalds 		size_t len = newlen;
29391da177e4SLinus Torvalds 		if (len > table->maxlen)
29401da177e4SLinus Torvalds 			len = table->maxlen;
29411da177e4SLinus Torvalds 		if(copy_from_user(table->data, newval, len))
29421da177e4SLinus Torvalds 			return -EFAULT;
29431da177e4SLinus Torvalds 		if (len == table->maxlen)
29441da177e4SLinus Torvalds 			len--;
29451da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
29461da177e4SLinus Torvalds 	}
294782c9df82SYi Yang 	return 1;
29481da177e4SLinus Torvalds }
29491da177e4SLinus Torvalds 
29501da177e4SLinus Torvalds /*
29511da177e4SLinus Torvalds  * This function makes sure that all of the integers in the vector
29521da177e4SLinus Torvalds  * are between the minimum and maximum values given in the arrays
29531da177e4SLinus Torvalds  * table->extra1 and table->extra2, respectively.
29541da177e4SLinus Torvalds  */
2955f221e726SAlexey Dobriyan int sysctl_intvec(struct ctl_table *table,
29561da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29571f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29581da177e4SLinus Torvalds {
29591da177e4SLinus Torvalds 
29601da177e4SLinus Torvalds 	if (newval && newlen) {
29611da177e4SLinus Torvalds 		int __user *vec = (int __user *) newval;
29621da177e4SLinus Torvalds 		int *min = (int *) table->extra1;
29631da177e4SLinus Torvalds 		int *max = (int *) table->extra2;
29641da177e4SLinus Torvalds 		size_t length;
29651da177e4SLinus Torvalds 		int i;
29661da177e4SLinus Torvalds 
29671da177e4SLinus Torvalds 		if (newlen % sizeof(int) != 0)
29681da177e4SLinus Torvalds 			return -EINVAL;
29691da177e4SLinus Torvalds 
29701da177e4SLinus Torvalds 		if (!table->extra1 && !table->extra2)
29711da177e4SLinus Torvalds 			return 0;
29721da177e4SLinus Torvalds 
29731da177e4SLinus Torvalds 		if (newlen > table->maxlen)
29741da177e4SLinus Torvalds 			newlen = table->maxlen;
29751da177e4SLinus Torvalds 		length = newlen / sizeof(int);
29761da177e4SLinus Torvalds 
29771da177e4SLinus Torvalds 		for (i = 0; i < length; i++) {
29781da177e4SLinus Torvalds 			int value;
29791da177e4SLinus Torvalds 			if (get_user(value, vec + i))
29801da177e4SLinus Torvalds 				return -EFAULT;
29811da177e4SLinus Torvalds 			if (min && value < min[i])
29821da177e4SLinus Torvalds 				return -EINVAL;
29831da177e4SLinus Torvalds 			if (max && value > max[i])
29841da177e4SLinus Torvalds 				return -EINVAL;
29851da177e4SLinus Torvalds 		}
29861da177e4SLinus Torvalds 	}
29871da177e4SLinus Torvalds 	return 0;
29881da177e4SLinus Torvalds }
29891da177e4SLinus Torvalds 
29901da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
2991f221e726SAlexey Dobriyan int sysctl_jiffies(struct ctl_table *table,
29921da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29931f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29941da177e4SLinus Torvalds {
29953ee75ac3SAlexey Dobriyan 	if (oldval && oldlenp) {
29961da177e4SLinus Torvalds 		size_t olen;
29973ee75ac3SAlexey Dobriyan 
29981da177e4SLinus Torvalds 		if (get_user(olen, oldlenp))
29991da177e4SLinus Torvalds 			return -EFAULT;
30003ee75ac3SAlexey Dobriyan 		if (olen) {
30013ee75ac3SAlexey Dobriyan 			int val;
30023ee75ac3SAlexey Dobriyan 
30033ee75ac3SAlexey Dobriyan 			if (olen < sizeof(int))
30041da177e4SLinus Torvalds 				return -EINVAL;
30053ee75ac3SAlexey Dobriyan 
30063ee75ac3SAlexey Dobriyan 			val = *(int *)(table->data) / HZ;
30073ee75ac3SAlexey Dobriyan 			if (put_user(val, (int __user *)oldval))
30081da177e4SLinus Torvalds 				return -EFAULT;
30093ee75ac3SAlexey Dobriyan 			if (put_user(sizeof(int), oldlenp))
30103ee75ac3SAlexey Dobriyan 				return -EFAULT;
30113ee75ac3SAlexey Dobriyan 		}
30121da177e4SLinus Torvalds 	}
30131da177e4SLinus Torvalds 	if (newval && newlen) {
30141da177e4SLinus Torvalds 		int new;
30151da177e4SLinus Torvalds 		if (newlen != sizeof(int))
30161da177e4SLinus Torvalds 			return -EINVAL;
30171da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
30181da177e4SLinus Torvalds 			return -EFAULT;
30191da177e4SLinus Torvalds 		*(int *)(table->data) = new*HZ;
30201da177e4SLinus Torvalds 	}
30211da177e4SLinus Torvalds 	return 1;
30221da177e4SLinus Torvalds }
30231da177e4SLinus Torvalds 
30241da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
3025f221e726SAlexey Dobriyan int sysctl_ms_jiffies(struct ctl_table *table,
30261da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
30271f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
30281da177e4SLinus Torvalds {
30293ee75ac3SAlexey Dobriyan 	if (oldval && oldlenp) {
30301da177e4SLinus Torvalds 		size_t olen;
30313ee75ac3SAlexey Dobriyan 
30321da177e4SLinus Torvalds 		if (get_user(olen, oldlenp))
30331da177e4SLinus Torvalds 			return -EFAULT;
30343ee75ac3SAlexey Dobriyan 		if (olen) {
30353ee75ac3SAlexey Dobriyan 			int val;
30363ee75ac3SAlexey Dobriyan 
30373ee75ac3SAlexey Dobriyan 			if (olen < sizeof(int))
30381da177e4SLinus Torvalds 				return -EINVAL;
30393ee75ac3SAlexey Dobriyan 
30403ee75ac3SAlexey Dobriyan 			val = jiffies_to_msecs(*(int *)(table->data));
30413ee75ac3SAlexey Dobriyan 			if (put_user(val, (int __user *)oldval))
30421da177e4SLinus Torvalds 				return -EFAULT;
30433ee75ac3SAlexey Dobriyan 			if (put_user(sizeof(int), oldlenp))
30443ee75ac3SAlexey Dobriyan 				return -EFAULT;
30453ee75ac3SAlexey Dobriyan 		}
30461da177e4SLinus Torvalds 	}
30471da177e4SLinus Torvalds 	if (newval && newlen) {
30481da177e4SLinus Torvalds 		int new;
30491da177e4SLinus Torvalds 		if (newlen != sizeof(int))
30501da177e4SLinus Torvalds 			return -EINVAL;
30511da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
30521da177e4SLinus Torvalds 			return -EFAULT;
30531da177e4SLinus Torvalds 		*(int *)(table->data) = msecs_to_jiffies(new);
30541da177e4SLinus Torvalds 	}
30551da177e4SLinus Torvalds 	return 1;
30561da177e4SLinus Torvalds }
30571da177e4SLinus Torvalds 
3058c4b8b769SEric W. Biederman 
3059c4b8b769SEric W. Biederman 
3060b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */
30611da177e4SLinus Torvalds 
30621da177e4SLinus Torvalds 
30631e7bfb21SHeiko Carstens SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
30641da177e4SLinus Torvalds {
30650e009be8SEric W. Biederman 	struct __sysctl_args tmp;
30667058cb02SEric W. Biederman 	int error;
30670e009be8SEric W. Biederman 
30680e009be8SEric W. Biederman 	if (copy_from_user(&tmp, args, sizeof(tmp)))
30690e009be8SEric W. Biederman 		return -EFAULT;
30700e009be8SEric W. Biederman 
30717058cb02SEric W. Biederman 	error = deprecated_sysctl_warning(&tmp);
3072b89a8171SEric W. Biederman 
30737058cb02SEric W. Biederman 	/* If no error reading the parameters then just -ENOSYS ... */
30747058cb02SEric W. Biederman 	if (!error)
30757058cb02SEric W. Biederman 		error = -ENOSYS;
30767058cb02SEric W. Biederman 
30777058cb02SEric W. Biederman 	return error;
30781da177e4SLinus Torvalds }
30791da177e4SLinus Torvalds 
3080f221e726SAlexey Dobriyan int sysctl_data(struct ctl_table *table,
308149a0c458SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
308249a0c458SEric W. Biederman 		  void __user *newval, size_t newlen)
308349a0c458SEric W. Biederman {
308449a0c458SEric W. Biederman 	return -ENOSYS;
308549a0c458SEric W. Biederman }
308649a0c458SEric W. Biederman 
3087f221e726SAlexey Dobriyan int sysctl_string(struct ctl_table *table,
30881da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
30891f29bcd7SAlexey Dobriyan 		  void __user *newval, size_t newlen)
30901da177e4SLinus Torvalds {
30911da177e4SLinus Torvalds 	return -ENOSYS;
30921da177e4SLinus Torvalds }
30931da177e4SLinus Torvalds 
3094f221e726SAlexey Dobriyan int sysctl_intvec(struct ctl_table *table,
30951da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
30961f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
30971da177e4SLinus Torvalds {
30981da177e4SLinus Torvalds 	return -ENOSYS;
30991da177e4SLinus Torvalds }
31001da177e4SLinus Torvalds 
3101f221e726SAlexey Dobriyan int sysctl_jiffies(struct ctl_table *table,
31021da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
31031f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
31041da177e4SLinus Torvalds {
31051da177e4SLinus Torvalds 	return -ENOSYS;
31061da177e4SLinus Torvalds }
31071da177e4SLinus Torvalds 
3108f221e726SAlexey Dobriyan int sysctl_ms_jiffies(struct ctl_table *table,
31091da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
31101f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
31111da177e4SLinus Torvalds {
31121da177e4SLinus Torvalds 	return -ENOSYS;
31131da177e4SLinus Torvalds }
31141da177e4SLinus Torvalds 
3115b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
31161da177e4SLinus Torvalds 
31177058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args)
31187058cb02SEric W. Biederman {
31197058cb02SEric W. Biederman 	static int msg_count;
31207058cb02SEric W. Biederman 	int name[CTL_MAXNAME];
31217058cb02SEric W. Biederman 	int i;
31227058cb02SEric W. Biederman 
31236fc48af8STetsuo Handa 	/* Check args->nlen. */
31246fc48af8STetsuo Handa 	if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
31256fc48af8STetsuo Handa 		return -ENOTDIR;
31266fc48af8STetsuo Handa 
31277058cb02SEric W. Biederman 	/* Read in the sysctl name for better debug message logging */
31287058cb02SEric W. Biederman 	for (i = 0; i < args->nlen; i++)
31297058cb02SEric W. Biederman 		if (get_user(name[i], args->name + i))
31307058cb02SEric W. Biederman 			return -EFAULT;
31317058cb02SEric W. Biederman 
31327058cb02SEric W. Biederman 	/* Ignore accesses to kernel.version */
31337058cb02SEric W. Biederman 	if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
31347058cb02SEric W. Biederman 		return 0;
31357058cb02SEric W. Biederman 
31367058cb02SEric W. Biederman 	if (msg_count < 5) {
31377058cb02SEric W. Biederman 		msg_count++;
31387058cb02SEric W. Biederman 		printk(KERN_INFO
31397058cb02SEric W. Biederman 			"warning: process `%s' used the deprecated sysctl "
31407058cb02SEric W. Biederman 			"system call with ", current->comm);
31417058cb02SEric W. Biederman 		for (i = 0; i < args->nlen; i++)
31427058cb02SEric W. Biederman 			printk("%d.", name[i]);
31437058cb02SEric W. Biederman 		printk("\n");
31447058cb02SEric W. Biederman 	}
31457058cb02SEric W. Biederman 	return 0;
31467058cb02SEric W. Biederman }
31477058cb02SEric W. Biederman 
31481da177e4SLinus Torvalds /*
31491da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
31501da177e4SLinus Torvalds  * exception granted :-)
31511da177e4SLinus Torvalds  */
31521da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
31531da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
31541da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
31551da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
31561da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
31571da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
31581da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
31591da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
31601da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
316129e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths);
31621da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec);
31631da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies);
31641da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies);
31651da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string);
316649a0c458SEric W. Biederman EXPORT_SYMBOL(sysctl_data);
31671da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
3168