xref: /linux-6.15/kernel/sysctl.c (revision fafd688e)
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>
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds #include <asm/uaccess.h>
541da177e4SLinus Torvalds #include <asm/processor.h>
551da177e4SLinus Torvalds 
5629cbc78bSAndi Kleen #ifdef CONFIG_X86
5729cbc78bSAndi Kleen #include <asm/nmi.h>
580741f4d2SChuck Ebbert #include <asm/stacktrace.h>
596e7c4025SIngo Molnar #include <asm/io.h>
6029cbc78bSAndi Kleen #endif
6129cbc78bSAndi Kleen 
627058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args);
637058cb02SEric W. Biederman 
641da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /* External variables not in a header file. */
671da177e4SLinus Torvalds extern int C_A_D;
6845807a1dSIngo Molnar extern int print_fatal_signals;
691da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
701da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
71fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom;
72fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task;
73fef1bdd6SDavid Rientjes extern int sysctl_oom_dump_tasks;
741da177e4SLinus Torvalds extern int max_threads;
751da177e4SLinus Torvalds extern int core_uses_pid;
76d6e71144SAlan Cox extern int suid_dumpable;
771da177e4SLinus Torvalds extern char core_pattern[];
781da177e4SLinus Torvalds extern int pid_max;
791da177e4SLinus Torvalds extern int min_free_kbytes;
801da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
819d0243bcSAndrew Morton extern int sysctl_drop_caches;
828ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
83bebfa101SAndi Kleen extern int compat_log;
849745512cSArjan van de Ven extern int latencytop_enabled;
85eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max;
86dd8632a1SPaul Mundt #ifndef CONFIG_MMU
87dd8632a1SPaul Mundt extern int sysctl_nr_trim_pages;
88dd8632a1SPaul Mundt #endif
8931a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
9031a72bceSPaul E. McKenney extern int rcutorture_runnable;
9131a72bceSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
921da177e4SLinus Torvalds 
93c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
94195cf453SBron Gondwana #ifdef CONFIG_DETECT_SOFTLOCKUP
95c4f3b63fSRavikiran G Thirumalai static int sixty = 60;
969383d967SDimitri Sivanich static int neg_one = -1;
97c4f3b63fSRavikiran G Thirumalai #endif
98c4f3b63fSRavikiran G Thirumalai 
99c4f3b63fSRavikiran G Thirumalai static int zero;
100cd5f9a4cSLinus Torvalds static int __maybe_unused one = 1;
101cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2;
102fc3501d4SSven Wegener static unsigned long one_ul = 1;
103c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100;
104*fafd688eSPeter W Morreale static int one_thousand = 1000;
105c4f3b63fSRavikiran G Thirumalai 
1061da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
1071da177e4SLinus Torvalds static int maxolduid = 65535;
1081da177e4SLinus Torvalds static int minolduid;
1098ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8;
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
1121da177e4SLinus Torvalds 
113a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
1141da177e4SLinus Torvalds extern char modprobe_path[];
1151da177e4SLinus Torvalds #endif
1161da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
1171da177e4SLinus Torvalds extern int sg_big_buff;
1181da177e4SLinus Torvalds #endif
1191da177e4SLinus Torvalds 
12072c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
12117f04fbbSDavid S. Miller #include <asm/system.h>
1221da177e4SLinus Torvalds #endif
1231da177e4SLinus Torvalds 
1240871420fSDavid S. Miller #ifdef CONFIG_SPARC64
1250871420fSDavid S. Miller extern int sysctl_tsb_ratio;
1260871420fSDavid S. Miller #endif
1270871420fSDavid S. Miller 
1281da177e4SLinus Torvalds #ifdef __hppa__
1291da177e4SLinus Torvalds extern int pwrsw_enabled;
1301da177e4SLinus Torvalds extern int unaligned_enabled;
1311da177e4SLinus Torvalds #endif
1321da177e4SLinus Torvalds 
133347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1341da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1351da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1361da177e4SLinus Torvalds #endif
1371da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
138951f22d5SMartin Schwidefsky extern int spin_retry;
1391da177e4SLinus Torvalds #endif
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
1421da177e4SLinus Torvalds extern int acct_parm[];
1431da177e4SLinus Torvalds #endif
1441da177e4SLinus Torvalds 
145d2b176edSJes Sorensen #ifdef CONFIG_IA64
146d2b176edSJes Sorensen extern int no_unaligned_warning;
14788fc241fSDoug Chapman extern int unaligned_dump_stack;
148d2b176edSJes Sorensen #endif
149d2b176edSJes Sorensen 
15023f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
15123f78d4aSIngo Molnar extern int max_lock_depth;
15223f78d4aSIngo Molnar #endif
15323f78d4aSIngo Molnar 
154d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
155d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
1569ec52099SCedric Le Goater 		  void __user *buffer, size_t *lenp, loff_t *ppos);
15725ddbb18SAndi Kleen static int proc_taint(struct ctl_table *table, int write, struct file *filp,
15834f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos);
159d6f8ff73SRandy Dunlap #endif
1609ec52099SCedric Le Goater 
161d8217f07SEric W. Biederman static struct ctl_table root_table[];
162e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root;
163e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = {
164b380b0d4SAl Viro 	.count = 1,
165e51b6ba0SEric W. Biederman 	.ctl_table = root_table,
16673455092SAl Viro 	.ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
167e51b6ba0SEric W. Biederman 	.root = &sysctl_table_root,
16873455092SAl Viro 	.set = &sysctl_table_root.default_set,
169e51b6ba0SEric W. Biederman };
170e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = {
171e51b6ba0SEric W. Biederman 	.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
17273455092SAl Viro 	.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
173e51b6ba0SEric W. Biederman };
1741da177e4SLinus Torvalds 
175d8217f07SEric W. Biederman static struct ctl_table kern_table[];
176d8217f07SEric W. Biederman static struct ctl_table vm_table[];
177d8217f07SEric W. Biederman static struct ctl_table fs_table[];
178d8217f07SEric W. Biederman static struct ctl_table debug_table[];
179d8217f07SEric W. Biederman static struct ctl_table dev_table[];
180d8217f07SEric W. Biederman extern struct ctl_table random_table[];
1812d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
182d8217f07SEric W. Biederman extern struct ctl_table inotify_table[];
1830399cb08SRobert Love #endif
1847ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
1857ef9964eSDavide Libenzi extern struct ctl_table epoll_table[];
1867ef9964eSDavide Libenzi #endif
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1891da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1901da177e4SLinus Torvalds #endif
1911da177e4SLinus Torvalds 
192f20786ffSPeter Zijlstra extern int prove_locking;
193f20786ffSPeter Zijlstra extern int lock_stat;
1949bc9a6bdSEric W. Biederman 
1951da177e4SLinus Torvalds /* The default sysctl tables: */
1961da177e4SLinus Torvalds 
197d8217f07SEric W. Biederman static struct ctl_table root_table[] = {
1981da177e4SLinus Torvalds 	{
1991da177e4SLinus Torvalds 		.ctl_name	= CTL_KERN,
2001da177e4SLinus Torvalds 		.procname	= "kernel",
2011da177e4SLinus Torvalds 		.mode		= 0555,
2021da177e4SLinus Torvalds 		.child		= kern_table,
2031da177e4SLinus Torvalds 	},
2041da177e4SLinus Torvalds 	{
2051da177e4SLinus Torvalds 		.ctl_name	= CTL_VM,
2061da177e4SLinus Torvalds 		.procname	= "vm",
2071da177e4SLinus Torvalds 		.mode		= 0555,
2081da177e4SLinus Torvalds 		.child		= vm_table,
2091da177e4SLinus Torvalds 	},
2101da177e4SLinus Torvalds 	{
2111da177e4SLinus Torvalds 		.ctl_name	= CTL_FS,
2121da177e4SLinus Torvalds 		.procname	= "fs",
2131da177e4SLinus Torvalds 		.mode		= 0555,
2141da177e4SLinus Torvalds 		.child		= fs_table,
2151da177e4SLinus Torvalds 	},
2161da177e4SLinus Torvalds 	{
2171da177e4SLinus Torvalds 		.ctl_name	= CTL_DEBUG,
2181da177e4SLinus Torvalds 		.procname	= "debug",
2191da177e4SLinus Torvalds 		.mode		= 0555,
2201da177e4SLinus Torvalds 		.child		= debug_table,
2211da177e4SLinus Torvalds 	},
2221da177e4SLinus Torvalds 	{
2231da177e4SLinus Torvalds 		.ctl_name	= CTL_DEV,
2241da177e4SLinus Torvalds 		.procname	= "dev",
2251da177e4SLinus Torvalds 		.mode		= 0555,
2261da177e4SLinus Torvalds 		.child		= dev_table,
2271da177e4SLinus Torvalds 	},
2282be7fe07SAndrew Morton /*
2292be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
2302be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
2312be7fe07SAndrew Morton  */
2321da177e4SLinus Torvalds 	{ .ctl_name = 0 }
2331da177e4SLinus Torvalds };
2341da177e4SLinus Torvalds 
23577e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
23673c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000;		/* 100 usecs */
23773c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
23873c4efd2SEric Dumazet static int min_wakeup_granularity_ns;			/* 0 usecs */
23973c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
24077e54a1fSIngo Molnar #endif
24177e54a1fSIngo Molnar 
242d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
24377e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
24477e54a1fSIngo Molnar 	{
24577e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
246b2be5e96SPeter Zijlstra 		.procname	= "sched_min_granularity_ns",
247b2be5e96SPeter Zijlstra 		.data		= &sysctl_sched_min_granularity,
24877e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
24977e54a1fSIngo Molnar 		.mode		= 0644,
250b2be5e96SPeter Zijlstra 		.proc_handler	= &sched_nr_latency_handler,
251b2be5e96SPeter Zijlstra 		.strategy	= &sysctl_intvec,
252b2be5e96SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
253b2be5e96SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
25477e54a1fSIngo Molnar 	},
25577e54a1fSIngo Molnar 	{
25677e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
25721805085SPeter Zijlstra 		.procname	= "sched_latency_ns",
25821805085SPeter Zijlstra 		.data		= &sysctl_sched_latency,
25921805085SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
26021805085SPeter Zijlstra 		.mode		= 0644,
261b2be5e96SPeter Zijlstra 		.proc_handler	= &sched_nr_latency_handler,
26221805085SPeter Zijlstra 		.strategy	= &sysctl_intvec,
26321805085SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
26421805085SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
26521805085SPeter Zijlstra 	},
26621805085SPeter Zijlstra 	{
26721805085SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
26877e54a1fSIngo Molnar 		.procname	= "sched_wakeup_granularity_ns",
26977e54a1fSIngo Molnar 		.data		= &sysctl_sched_wakeup_granularity,
27077e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
27177e54a1fSIngo Molnar 		.mode		= 0644,
27277e54a1fSIngo Molnar 		.proc_handler	= &proc_dointvec_minmax,
27377e54a1fSIngo Molnar 		.strategy	= &sysctl_intvec,
27477e54a1fSIngo Molnar 		.extra1		= &min_wakeup_granularity_ns,
27577e54a1fSIngo Molnar 		.extra2		= &max_wakeup_granularity_ns,
27677e54a1fSIngo Molnar 	},
27777e54a1fSIngo Molnar 	{
27877e54a1fSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
2792398f2c6SPeter Zijlstra 		.procname	= "sched_shares_ratelimit",
2802398f2c6SPeter Zijlstra 		.data		= &sysctl_sched_shares_ratelimit,
2812398f2c6SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
2822398f2c6SPeter Zijlstra 		.mode		= 0644,
2832398f2c6SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
2842398f2c6SPeter Zijlstra 	},
2852398f2c6SPeter Zijlstra 	{
2862398f2c6SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
287ffda12a1SPeter Zijlstra 		.procname	= "sched_shares_thresh",
288ffda12a1SPeter Zijlstra 		.data		= &sysctl_sched_shares_thresh,
289ffda12a1SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
290ffda12a1SPeter Zijlstra 		.mode		= 0644,
291ffda12a1SPeter Zijlstra 		.proc_handler	= &proc_dointvec_minmax,
292ffda12a1SPeter Zijlstra 		.strategy	= &sysctl_intvec,
293ffda12a1SPeter Zijlstra 		.extra1		= &zero,
294ffda12a1SPeter Zijlstra 	},
295ffda12a1SPeter Zijlstra 	{
296ffda12a1SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
29777e54a1fSIngo Molnar 		.procname	= "sched_child_runs_first",
29877e54a1fSIngo Molnar 		.data		= &sysctl_sched_child_runs_first,
29977e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
30077e54a1fSIngo Molnar 		.mode		= 0644,
30177e54a1fSIngo Molnar 		.proc_handler	= &proc_dointvec,
30277e54a1fSIngo Molnar 	},
3031fc84aaaSPeter Zijlstra 	{
3041fc84aaaSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3051fc84aaaSPeter Zijlstra 		.procname	= "sched_features",
3061fc84aaaSPeter Zijlstra 		.data		= &sysctl_sched_features,
3071fc84aaaSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
3081fc84aaaSPeter Zijlstra 		.mode		= 0644,
3091fc84aaaSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
3101fc84aaaSPeter Zijlstra 	},
311da84d961SIngo Molnar 	{
312da84d961SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
313da84d961SIngo Molnar 		.procname	= "sched_migration_cost",
314da84d961SIngo Molnar 		.data		= &sysctl_sched_migration_cost,
315da84d961SIngo Molnar 		.maxlen		= sizeof(unsigned int),
316da84d961SIngo Molnar 		.mode		= 0644,
317da84d961SIngo Molnar 		.proc_handler	= &proc_dointvec,
318da84d961SIngo Molnar 	},
319b82d9fddSPeter Zijlstra 	{
320b82d9fddSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
321b82d9fddSPeter Zijlstra 		.procname	= "sched_nr_migrate",
322b82d9fddSPeter Zijlstra 		.data		= &sysctl_sched_nr_migrate,
323b82d9fddSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
324fa85ae24SPeter Zijlstra 		.mode		= 0644,
325fa85ae24SPeter Zijlstra 		.proc_handler	= &proc_dointvec,
326fa85ae24SPeter Zijlstra 	},
3271fc84aaaSPeter Zijlstra #endif
3281799e35dSIngo Molnar 	{
3291799e35dSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
3309f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
3319f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
3329f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
3339f0c1e56SPeter Zijlstra 		.mode		= 0644,
334d0b27fa7SPeter Zijlstra 		.proc_handler	= &sched_rt_handler,
3359f0c1e56SPeter Zijlstra 	},
3369f0c1e56SPeter Zijlstra 	{
3379f0c1e56SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3389f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
3399f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
3409f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
3419f0c1e56SPeter Zijlstra 		.mode		= 0644,
342d0b27fa7SPeter Zijlstra 		.proc_handler	= &sched_rt_handler,
3439f0c1e56SPeter Zijlstra 	},
3449f0c1e56SPeter Zijlstra 	{
3459f0c1e56SPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
3461799e35dSIngo Molnar 		.procname	= "sched_compat_yield",
3471799e35dSIngo Molnar 		.data		= &sysctl_sched_compat_yield,
3481799e35dSIngo Molnar 		.maxlen		= sizeof(unsigned int),
3491799e35dSIngo Molnar 		.mode		= 0644,
3501799e35dSIngo Molnar 		.proc_handler	= &proc_dointvec,
3511799e35dSIngo Molnar 	},
352f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
353f20786ffSPeter Zijlstra 	{
354f20786ffSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
355f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
356f20786ffSPeter Zijlstra 		.data		= &prove_locking,
357f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
358f20786ffSPeter Zijlstra 		.mode		= 0644,
359f20786ffSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
360f20786ffSPeter Zijlstra 	},
361f20786ffSPeter Zijlstra #endif
362f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
363f20786ffSPeter Zijlstra 	{
364f20786ffSPeter Zijlstra 		.ctl_name	= CTL_UNNUMBERED,
365f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
366f20786ffSPeter Zijlstra 		.data		= &lock_stat,
367f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
368f20786ffSPeter Zijlstra 		.mode		= 0644,
369f20786ffSPeter Zijlstra 		.proc_handler	= &proc_dointvec,
370f20786ffSPeter Zijlstra 	},
371f20786ffSPeter Zijlstra #endif
37277e54a1fSIngo Molnar 	{
3731da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC,
3741da177e4SLinus Torvalds 		.procname	= "panic",
3751da177e4SLinus Torvalds 		.data		= &panic_timeout,
3761da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3771da177e4SLinus Torvalds 		.mode		= 0644,
3781da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3791da177e4SLinus Torvalds 	},
3801da177e4SLinus Torvalds 	{
3811da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_USES_PID,
3821da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
3831da177e4SLinus Torvalds 		.data		= &core_uses_pid,
3841da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3851da177e4SLinus Torvalds 		.mode		= 0644,
3861da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
3871da177e4SLinus Torvalds 	},
3881da177e4SLinus Torvalds 	{
3891da177e4SLinus Torvalds 		.ctl_name	= KERN_CORE_PATTERN,
3901da177e4SLinus Torvalds 		.procname	= "core_pattern",
3911da177e4SLinus Torvalds 		.data		= core_pattern,
39271ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
3931da177e4SLinus Torvalds 		.mode		= 0644,
3941da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
3951da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
3961da177e4SLinus Torvalds 	},
39734f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
3981da177e4SLinus Torvalds 	{
3991da177e4SLinus Torvalds 		.procname	= "tainted",
40025ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
40134f5a398STheodore Ts'o 		.mode		= 0644,
40225ddbb18SAndi Kleen 		.proc_handler	= &proc_taint,
4031da177e4SLinus Torvalds 	},
40434f5a398STheodore Ts'o #endif
4059745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
4069745512cSArjan van de Ven 	{
4079745512cSArjan van de Ven 		.procname	= "latencytop",
4089745512cSArjan van de Ven 		.data		= &latencytop_enabled,
4099745512cSArjan van de Ven 		.maxlen		= sizeof(int),
4109745512cSArjan van de Ven 		.mode		= 0644,
4119745512cSArjan van de Ven 		.proc_handler	= &proc_dointvec,
4129745512cSArjan van de Ven 	},
4139745512cSArjan van de Ven #endif
4141da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
4151da177e4SLinus Torvalds 	{
4161da177e4SLinus Torvalds 		.ctl_name	= KERN_REALROOTDEV,
4171da177e4SLinus Torvalds 		.procname	= "real-root-dev",
4181da177e4SLinus Torvalds 		.data		= &real_root_dev,
4191da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4201da177e4SLinus Torvalds 		.mode		= 0644,
4211da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4221da177e4SLinus Torvalds 	},
4231da177e4SLinus Torvalds #endif
42445807a1dSIngo Molnar 	{
42545807a1dSIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
42645807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
42745807a1dSIngo Molnar 		.data		= &print_fatal_signals,
42845807a1dSIngo Molnar 		.maxlen		= sizeof(int),
42945807a1dSIngo Molnar 		.mode		= 0644,
43045807a1dSIngo Molnar 		.proc_handler	= &proc_dointvec,
43145807a1dSIngo Molnar 	},
43272c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
4331da177e4SLinus Torvalds 	{
4341da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_REBOOT,
4351da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
4361da177e4SLinus Torvalds 		.data		= reboot_command,
4371da177e4SLinus Torvalds 		.maxlen		= 256,
4381da177e4SLinus Torvalds 		.mode		= 0644,
4391da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
4401da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
4411da177e4SLinus Torvalds 	},
4421da177e4SLinus Torvalds 	{
4431da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_STOP_A,
4441da177e4SLinus Torvalds 		.procname	= "stop-a",
4451da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
4461da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4471da177e4SLinus Torvalds 		.mode		= 0644,
4481da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4491da177e4SLinus Torvalds 	},
4501da177e4SLinus Torvalds 	{
4511da177e4SLinus Torvalds 		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
4521da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
4531da177e4SLinus Torvalds 		.data		= &scons_pwroff,
4541da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4551da177e4SLinus Torvalds 		.mode		= 0644,
4561da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4571da177e4SLinus Torvalds 	},
4581da177e4SLinus Torvalds #endif
4590871420fSDavid S. Miller #ifdef CONFIG_SPARC64
4600871420fSDavid S. Miller 	{
4610871420fSDavid S. Miller 		.ctl_name	= CTL_UNNUMBERED,
4620871420fSDavid S. Miller 		.procname	= "tsb-ratio",
4630871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
4640871420fSDavid S. Miller 		.maxlen		= sizeof (int),
4650871420fSDavid S. Miller 		.mode		= 0644,
4660871420fSDavid S. Miller 		.proc_handler	= &proc_dointvec,
4670871420fSDavid S. Miller 	},
4680871420fSDavid S. Miller #endif
4691da177e4SLinus Torvalds #ifdef __hppa__
4701da177e4SLinus Torvalds 	{
4711da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_PWRSW,
4721da177e4SLinus Torvalds 		.procname	= "soft-power",
4731da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
4741da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4751da177e4SLinus Torvalds 	 	.mode		= 0644,
4761da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4771da177e4SLinus Torvalds 	},
4781da177e4SLinus Torvalds 	{
4791da177e4SLinus Torvalds 		.ctl_name	= KERN_HPPA_UNALIGNED,
4801da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
4811da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
4821da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4831da177e4SLinus Torvalds 		.mode		= 0644,
4841da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4851da177e4SLinus Torvalds 	},
4861da177e4SLinus Torvalds #endif
4871da177e4SLinus Torvalds 	{
4881da177e4SLinus Torvalds 		.ctl_name	= KERN_CTLALTDEL,
4891da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
4901da177e4SLinus Torvalds 		.data		= &C_A_D,
4911da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4921da177e4SLinus Torvalds 		.mode		= 0644,
4931da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
4941da177e4SLinus Torvalds 	},
495606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER
496b0fc494fSSteven Rostedt 	{
497b0fc494fSSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
498b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
499b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
500b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
501b0fc494fSSteven Rostedt 		.mode		= 0644,
502b0fc494fSSteven Rostedt 		.proc_handler	= &ftrace_enable_sysctl,
503b0fc494fSSteven Rostedt 	},
504b0fc494fSSteven Rostedt #endif
505f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
506f38f1d2aSSteven Rostedt 	{
507f38f1d2aSSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
508f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
509f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
510f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
511f38f1d2aSSteven Rostedt 		.mode		= 0644,
512f38f1d2aSSteven Rostedt 		.proc_handler	= &stack_trace_sysctl,
513f38f1d2aSSteven Rostedt 	},
514f38f1d2aSSteven Rostedt #endif
515944ac425SSteven Rostedt #ifdef CONFIG_TRACING
516944ac425SSteven Rostedt 	{
517944ac425SSteven Rostedt 		.ctl_name	= CTL_UNNUMBERED,
5183299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
519944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
520944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
521944ac425SSteven Rostedt 		.mode		= 0644,
522944ac425SSteven Rostedt 		.proc_handler	= &proc_dointvec,
523944ac425SSteven Rostedt 	},
524944ac425SSteven Rostedt #endif
525a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
5261da177e4SLinus Torvalds 	{
5271da177e4SLinus Torvalds 		.ctl_name	= KERN_MODPROBE,
5281da177e4SLinus Torvalds 		.procname	= "modprobe",
5291da177e4SLinus Torvalds 		.data		= &modprobe_path,
5301da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
5311da177e4SLinus Torvalds 		.mode		= 0644,
5321da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
5331da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
5341da177e4SLinus Torvalds 	},
5351da177e4SLinus Torvalds #endif
53657ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
5371da177e4SLinus Torvalds 	{
5381da177e4SLinus Torvalds 		.ctl_name	= KERN_HOTPLUG,
5391da177e4SLinus Torvalds 		.procname	= "hotplug",
540312c004dSKay Sievers 		.data		= &uevent_helper,
541312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
5421da177e4SLinus Torvalds 		.mode		= 0644,
5431da177e4SLinus Torvalds 		.proc_handler	= &proc_dostring,
5441da177e4SLinus Torvalds 		.strategy	= &sysctl_string,
5451da177e4SLinus Torvalds 	},
5461da177e4SLinus Torvalds #endif
5471da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
5481da177e4SLinus Torvalds 	{
5491da177e4SLinus Torvalds 		.ctl_name	= KERN_SG_BIG_BUFF,
5501da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
5511da177e4SLinus Torvalds 		.data		= &sg_big_buff,
5521da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5531da177e4SLinus Torvalds 		.mode		= 0444,
5541da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5551da177e4SLinus Torvalds 	},
5561da177e4SLinus Torvalds #endif
5571da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
5581da177e4SLinus Torvalds 	{
5591da177e4SLinus Torvalds 		.ctl_name	= KERN_ACCT,
5601da177e4SLinus Torvalds 		.procname	= "acct",
5611da177e4SLinus Torvalds 		.data		= &acct_parm,
5621da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
5631da177e4SLinus Torvalds 		.mode		= 0644,
5641da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5651da177e4SLinus Torvalds 	},
5661da177e4SLinus Torvalds #endif
5671da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
5681da177e4SLinus Torvalds 	{
5691da177e4SLinus Torvalds 		.ctl_name	= KERN_SYSRQ,
5701da177e4SLinus Torvalds 		.procname	= "sysrq",
5715d6f647fSIngo Molnar 		.data		= &__sysrq_enabled,
5721da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5731da177e4SLinus Torvalds 		.mode		= 0644,
5741da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5751da177e4SLinus Torvalds 	},
5761da177e4SLinus Torvalds #endif
577d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
5781da177e4SLinus Torvalds 	{
5791da177e4SLinus Torvalds 		.procname	= "cad_pid",
5809ec52099SCedric Le Goater 		.data		= NULL,
5811da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5821da177e4SLinus Torvalds 		.mode		= 0600,
5839ec52099SCedric Le Goater 		.proc_handler	= &proc_do_cad_pid,
5841da177e4SLinus Torvalds 	},
585d6f8ff73SRandy Dunlap #endif
5861da177e4SLinus Torvalds 	{
5871da177e4SLinus Torvalds 		.ctl_name	= KERN_MAX_THREADS,
5881da177e4SLinus Torvalds 		.procname	= "threads-max",
5891da177e4SLinus Torvalds 		.data		= &max_threads,
5901da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5911da177e4SLinus Torvalds 		.mode		= 0644,
5921da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
5931da177e4SLinus Torvalds 	},
5941da177e4SLinus Torvalds 	{
5951da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOM,
5961da177e4SLinus Torvalds 		.procname	= "random",
5971da177e4SLinus Torvalds 		.mode		= 0555,
5981da177e4SLinus Torvalds 		.child		= random_table,
5991da177e4SLinus Torvalds 	},
6001da177e4SLinus Torvalds 	{
6011da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWUID,
6021da177e4SLinus Torvalds 		.procname	= "overflowuid",
6031da177e4SLinus Torvalds 		.data		= &overflowuid,
6041da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6051da177e4SLinus Torvalds 		.mode		= 0644,
6061da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6071da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
6081da177e4SLinus Torvalds 		.extra1		= &minolduid,
6091da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6101da177e4SLinus Torvalds 	},
6111da177e4SLinus Torvalds 	{
6121da177e4SLinus Torvalds 		.ctl_name	= KERN_OVERFLOWGID,
6131da177e4SLinus Torvalds 		.procname	= "overflowgid",
6141da177e4SLinus Torvalds 		.data		= &overflowgid,
6151da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6161da177e4SLinus Torvalds 		.mode		= 0644,
6171da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6181da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
6191da177e4SLinus Torvalds 		.extra1		= &minolduid,
6201da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6211da177e4SLinus Torvalds 	},
622347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
6231da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
6241da177e4SLinus Torvalds 	{
6251da177e4SLinus Torvalds 		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
6261da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
6271da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
6281da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6291da177e4SLinus Torvalds 		.mode		= 0644,
6301da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6311da177e4SLinus Torvalds 	},
6321da177e4SLinus Torvalds #endif
6331da177e4SLinus Torvalds 	{
6341da177e4SLinus Torvalds 		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
6351da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
6361da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
6371da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6381da177e4SLinus Torvalds 		.mode		= 0644,
6391da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6401da177e4SLinus Torvalds 	},
6411da177e4SLinus Torvalds #endif
6421da177e4SLinus Torvalds 	{
6431da177e4SLinus Torvalds 		.ctl_name	= KERN_PIDMAX,
6441da177e4SLinus Torvalds 		.procname	= "pid_max",
6451da177e4SLinus Torvalds 		.data		= &pid_max,
6461da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6471da177e4SLinus Torvalds 		.mode		= 0644,
6481da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
6491da177e4SLinus Torvalds 		.strategy	= sysctl_intvec,
6501da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
6511da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
6521da177e4SLinus Torvalds 	},
6531da177e4SLinus Torvalds 	{
6541da177e4SLinus Torvalds 		.ctl_name	= KERN_PANIC_ON_OOPS,
6551da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
6561da177e4SLinus Torvalds 		.data		= &panic_on_oops,
6571da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6581da177e4SLinus Torvalds 		.mode		= 0644,
6591da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6601da177e4SLinus Torvalds 	},
6617ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
6627ef3d2fdSJoe Perches 	{
6637ef3d2fdSJoe Perches 		.ctl_name	= KERN_PRINTK,
6647ef3d2fdSJoe Perches 		.procname	= "printk",
6657ef3d2fdSJoe Perches 		.data		= &console_loglevel,
6667ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
6677ef3d2fdSJoe Perches 		.mode		= 0644,
6687ef3d2fdSJoe Perches 		.proc_handler	= &proc_dointvec,
6697ef3d2fdSJoe Perches 	},
6701da177e4SLinus Torvalds 	{
6711da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT,
6721da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
673717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
6741da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6751da177e4SLinus Torvalds 		.mode		= 0644,
6761da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_jiffies,
6771da177e4SLinus Torvalds 		.strategy	= &sysctl_jiffies,
6781da177e4SLinus Torvalds 	},
6791da177e4SLinus Torvalds 	{
6801da177e4SLinus Torvalds 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
6811da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
682717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
6831da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6841da177e4SLinus Torvalds 		.mode		= 0644,
6851da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6861da177e4SLinus Torvalds 	},
6877ef3d2fdSJoe Perches #endif
6881da177e4SLinus Torvalds 	{
6891da177e4SLinus Torvalds 		.ctl_name	= KERN_NGROUPS_MAX,
6901da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6911da177e4SLinus Torvalds 		.data		= &ngroups_max,
6921da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6931da177e4SLinus Torvalds 		.mode		= 0444,
6941da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
6951da177e4SLinus Torvalds 	},
6961da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6971da177e4SLinus Torvalds 	{
6981da177e4SLinus Torvalds 		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
6991da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
7001da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
7011da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
7021da177e4SLinus Torvalds 		.mode           = 0644,
7032fbe7b25SDon Zickus 		.proc_handler   = &proc_dointvec,
7041da177e4SLinus Torvalds 	},
705407984f1SDon Zickus 	{
706407984f1SDon Zickus 		.procname       = "nmi_watchdog",
707407984f1SDon Zickus 		.data           = &nmi_watchdog_enabled,
708407984f1SDon Zickus 		.maxlen         = sizeof (int),
709407984f1SDon Zickus 		.mode           = 0644,
710407984f1SDon Zickus 		.proc_handler   = &proc_nmi_enabled,
7111da177e4SLinus Torvalds 	},
7121da177e4SLinus Torvalds #endif
7131da177e4SLinus Torvalds #if defined(CONFIG_X86)
7141da177e4SLinus Torvalds 	{
7158da5addaSDon Zickus 		.ctl_name	= KERN_PANIC_ON_NMI,
7168da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
7178da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
7188da5addaSDon Zickus 		.maxlen		= sizeof(int),
7198da5addaSDon Zickus 		.mode		= 0644,
7208da5addaSDon Zickus 		.proc_handler	= &proc_dointvec,
7218da5addaSDon Zickus 	},
7228da5addaSDon Zickus 	{
7231da177e4SLinus Torvalds 		.ctl_name	= KERN_BOOTLOADER_TYPE,
7241da177e4SLinus Torvalds 		.procname	= "bootloader_type",
7251da177e4SLinus Torvalds 		.data		= &bootloader_type,
7261da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
7271da177e4SLinus Torvalds 		.mode		= 0444,
7281da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7291da177e4SLinus Torvalds 	},
7300741f4d2SChuck Ebbert 	{
7310741f4d2SChuck Ebbert 		.ctl_name	= CTL_UNNUMBERED,
7320741f4d2SChuck Ebbert 		.procname	= "kstack_depth_to_print",
7330741f4d2SChuck Ebbert 		.data		= &kstack_depth_to_print,
7340741f4d2SChuck Ebbert 		.maxlen		= sizeof(int),
7350741f4d2SChuck Ebbert 		.mode		= 0644,
7360741f4d2SChuck Ebbert 		.proc_handler	= &proc_dointvec,
7370741f4d2SChuck Ebbert 	},
7386e7c4025SIngo Molnar 	{
7396e7c4025SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
7406e7c4025SIngo Molnar 		.procname	= "io_delay_type",
7416e7c4025SIngo Molnar 		.data		= &io_delay_type,
7426e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
7436e7c4025SIngo Molnar 		.mode		= 0644,
7446e7c4025SIngo Molnar 		.proc_handler	= &proc_dointvec,
7456e7c4025SIngo Molnar 	},
7461da177e4SLinus Torvalds #endif
7477a9166e3SLuke Yang #if defined(CONFIG_MMU)
7481da177e4SLinus Torvalds 	{
7491da177e4SLinus Torvalds 		.ctl_name	= KERN_RANDOMIZE,
7501da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
7511da177e4SLinus Torvalds 		.data		= &randomize_va_space,
7521da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
7531da177e4SLinus Torvalds 		.mode		= 0644,
7541da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
7551da177e4SLinus Torvalds 	},
7567a9166e3SLuke Yang #endif
7570152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
758951f22d5SMartin Schwidefsky 	{
759951f22d5SMartin Schwidefsky 		.ctl_name	= KERN_SPIN_RETRY,
760951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
761951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
762951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
763951f22d5SMartin Schwidefsky 		.mode		= 0644,
764951f22d5SMartin Schwidefsky 		.proc_handler	= &proc_dointvec,
765951f22d5SMartin Schwidefsky 	},
766951f22d5SMartin Schwidefsky #endif
767673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
768c255d844SPavel Machek 	{
769c255d844SPavel Machek 		.procname	= "acpi_video_flags",
77077afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
771c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
772c255d844SPavel Machek 		.mode		= 0644,
7737f99f06fSStefan Seyfried 		.proc_handler	= &proc_doulongvec_minmax,
774c255d844SPavel Machek 	},
775c255d844SPavel Machek #endif
776d2b176edSJes Sorensen #ifdef CONFIG_IA64
777d2b176edSJes Sorensen 	{
778d2b176edSJes Sorensen 		.ctl_name	= KERN_IA64_UNALIGNED,
779d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
780d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
781d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
782d2b176edSJes Sorensen 	 	.mode		= 0644,
783d2b176edSJes Sorensen 		.proc_handler	= &proc_dointvec,
784d2b176edSJes Sorensen 	},
78588fc241fSDoug Chapman 	{
78688fc241fSDoug Chapman 		.ctl_name	= CTL_UNNUMBERED,
78788fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
78888fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
78988fc241fSDoug Chapman 		.maxlen		= sizeof (int),
79088fc241fSDoug Chapman 		.mode		= 0644,
79188fc241fSDoug Chapman 		.proc_handler	= &proc_dointvec,
79288fc241fSDoug Chapman 	},
793d2b176edSJes Sorensen #endif
794c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP
795c4f3b63fSRavikiran G Thirumalai 	{
796c4f3b63fSRavikiran G Thirumalai 		.ctl_name	= CTL_UNNUMBERED,
7979c44bc03SIngo Molnar 		.procname	= "softlockup_panic",
7989c44bc03SIngo Molnar 		.data		= &softlockup_panic,
7999c44bc03SIngo Molnar 		.maxlen		= sizeof(int),
8009c44bc03SIngo Molnar 		.mode		= 0644,
8014dca10a9SHiroshi Shimamoto 		.proc_handler	= &proc_dointvec_minmax,
8029c44bc03SIngo Molnar 		.strategy	= &sysctl_intvec,
8039c44bc03SIngo Molnar 		.extra1		= &zero,
8049c44bc03SIngo Molnar 		.extra2		= &one,
8059c44bc03SIngo Molnar 	},
8069c44bc03SIngo Molnar 	{
8079c44bc03SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
808c4f3b63fSRavikiran G Thirumalai 		.procname	= "softlockup_thresh",
809c4f3b63fSRavikiran G Thirumalai 		.data		= &softlockup_thresh,
8109383d967SDimitri Sivanich 		.maxlen		= sizeof(int),
811c4f3b63fSRavikiran G Thirumalai 		.mode		= 0644,
812baf48f65SMandeep Singh Baines 		.proc_handler	= &proc_dosoftlockup_thresh,
813c4f3b63fSRavikiran G Thirumalai 		.strategy	= &sysctl_intvec,
8149383d967SDimitri Sivanich 		.extra1		= &neg_one,
815c4f3b63fSRavikiran G Thirumalai 		.extra2		= &sixty,
816c4f3b63fSRavikiran G Thirumalai 	},
81782a1fcb9SIngo Molnar 	{
81882a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
81982a1fcb9SIngo Molnar 		.procname	= "hung_task_check_count",
82082a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_check_count,
82190739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
82282a1fcb9SIngo Molnar 		.mode		= 0644,
82390739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
82482a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
82582a1fcb9SIngo Molnar 	},
82682a1fcb9SIngo Molnar 	{
82782a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
82882a1fcb9SIngo Molnar 		.procname	= "hung_task_timeout_secs",
82982a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_timeout_secs,
83090739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
83182a1fcb9SIngo Molnar 		.mode		= 0644,
83290739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
83382a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
83482a1fcb9SIngo Molnar 	},
83582a1fcb9SIngo Molnar 	{
83682a1fcb9SIngo Molnar 		.ctl_name	= CTL_UNNUMBERED,
83782a1fcb9SIngo Molnar 		.procname	= "hung_task_warnings",
83882a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_warnings,
83990739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
84082a1fcb9SIngo Molnar 		.mode		= 0644,
84190739081SIngo Molnar 		.proc_handler	= &proc_doulongvec_minmax,
84282a1fcb9SIngo Molnar 		.strategy	= &sysctl_intvec,
84382a1fcb9SIngo Molnar 	},
844c4f3b63fSRavikiran G Thirumalai #endif
845bebfa101SAndi Kleen #ifdef CONFIG_COMPAT
846bebfa101SAndi Kleen 	{
847bebfa101SAndi Kleen 		.ctl_name	= KERN_COMPAT_LOG,
848bebfa101SAndi Kleen 		.procname	= "compat-log",
849bebfa101SAndi Kleen 		.data		= &compat_log,
850bebfa101SAndi Kleen 		.maxlen		= sizeof (int),
851bebfa101SAndi Kleen 	 	.mode		= 0644,
852bebfa101SAndi Kleen 		.proc_handler	= &proc_dointvec,
853bebfa101SAndi Kleen 	},
854bebfa101SAndi Kleen #endif
85523f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
85623f78d4aSIngo Molnar 	{
85723f78d4aSIngo Molnar 		.ctl_name	= KERN_MAX_LOCK_DEPTH,
85823f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
85923f78d4aSIngo Molnar 		.data		= &max_lock_depth,
86023f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
86123f78d4aSIngo Molnar 		.mode		= 0644,
86223f78d4aSIngo Molnar 		.proc_handler	= &proc_dointvec,
86323f78d4aSIngo Molnar 	},
86423f78d4aSIngo Molnar #endif
86510a0a8d4SJeremy Fitzhardinge 	{
86610a0a8d4SJeremy Fitzhardinge 		.ctl_name	= CTL_UNNUMBERED,
86710a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
86810a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
86910a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
87010a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
87110a0a8d4SJeremy Fitzhardinge 		.proc_handler	= &proc_dostring,
87210a0a8d4SJeremy Fitzhardinge 		.strategy	= &sysctl_string,
87310a0a8d4SJeremy Fitzhardinge 	},
8740b77f5bfSDavid Howells #ifdef CONFIG_KEYS
8750b77f5bfSDavid Howells 	{
8760b77f5bfSDavid Howells 		.ctl_name	= CTL_UNNUMBERED,
8770b77f5bfSDavid Howells 		.procname	= "keys",
8780b77f5bfSDavid Howells 		.mode		= 0555,
8790b77f5bfSDavid Howells 		.child		= key_sysctls,
8800b77f5bfSDavid Howells 	},
8810b77f5bfSDavid Howells #endif
88231a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
88331a72bceSPaul E. McKenney 	{
88431a72bceSPaul E. McKenney 		.ctl_name       = CTL_UNNUMBERED,
88531a72bceSPaul E. McKenney 		.procname       = "rcutorture_runnable",
88631a72bceSPaul E. McKenney 		.data           = &rcutorture_runnable,
88731a72bceSPaul E. McKenney 		.maxlen         = sizeof(int),
88831a72bceSPaul E. McKenney 		.mode           = 0644,
88931a72bceSPaul E. McKenney 		.proc_handler   = &proc_dointvec,
89031a72bceSPaul E. McKenney 	},
89131a72bceSPaul E. McKenney #endif
892af936a16SLee Schermerhorn #ifdef CONFIG_UNEVICTABLE_LRU
893af936a16SLee Schermerhorn 	{
894af936a16SLee Schermerhorn 		.ctl_name	= CTL_UNNUMBERED,
895af936a16SLee Schermerhorn 		.procname	= "scan_unevictable_pages",
896af936a16SLee Schermerhorn 		.data		= &scan_unevictable_pages,
897af936a16SLee Schermerhorn 		.maxlen		= sizeof(scan_unevictable_pages),
898af936a16SLee Schermerhorn 		.mode		= 0644,
899af936a16SLee Schermerhorn 		.proc_handler	= &scan_unevictable_handler,
900af936a16SLee Schermerhorn 	},
901af936a16SLee Schermerhorn #endif
90212e22c5eSDavid Howells #ifdef CONFIG_SLOW_WORK
90312e22c5eSDavid Howells 	{
90412e22c5eSDavid Howells 		.ctl_name	= CTL_UNNUMBERED,
90512e22c5eSDavid Howells 		.procname	= "slow-work",
90612e22c5eSDavid Howells 		.mode		= 0555,
90712e22c5eSDavid Howells 		.child		= slow_work_sysctls,
90812e22c5eSDavid Howells 	},
90912e22c5eSDavid Howells #endif
910ed2c12f3SAndrew Morton /*
911ed2c12f3SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
912ed2c12f3SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
913ed2c12f3SAndrew Morton  */
9141da177e4SLinus Torvalds 	{ .ctl_name = 0 }
9151da177e4SLinus Torvalds };
9161da177e4SLinus Torvalds 
917d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
9181da177e4SLinus Torvalds 	{
9191da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_MEMORY,
9201da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
9211da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
9221da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
9231da177e4SLinus Torvalds 		.mode		= 0644,
9241da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9251da177e4SLinus Torvalds 	},
9261da177e4SLinus Torvalds 	{
927fadd8fbdSKAMEZAWA Hiroyuki 		.ctl_name	= VM_PANIC_ON_OOM,
928fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
929fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
930fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
931fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
932fadd8fbdSKAMEZAWA Hiroyuki 		.proc_handler	= &proc_dointvec,
933fadd8fbdSKAMEZAWA Hiroyuki 	},
934fadd8fbdSKAMEZAWA Hiroyuki 	{
935fe071d7eSDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
936fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
937fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
938fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
939fe071d7eSDavid Rientjes 		.mode		= 0644,
940fe071d7eSDavid Rientjes 		.proc_handler	= &proc_dointvec,
941fe071d7eSDavid Rientjes 	},
942fe071d7eSDavid Rientjes 	{
943fef1bdd6SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
944fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
945fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
946fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
947fef1bdd6SDavid Rientjes 		.mode		= 0644,
948fef1bdd6SDavid Rientjes 		.proc_handler	= &proc_dointvec,
949fef1bdd6SDavid Rientjes 	},
950fef1bdd6SDavid Rientjes 	{
9511da177e4SLinus Torvalds 		.ctl_name	= VM_OVERCOMMIT_RATIO,
9521da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
9531da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
9541da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
9551da177e4SLinus Torvalds 		.mode		= 0644,
9561da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9571da177e4SLinus Torvalds 	},
9581da177e4SLinus Torvalds 	{
9591da177e4SLinus Torvalds 		.ctl_name	= VM_PAGE_CLUSTER,
9601da177e4SLinus Torvalds 		.procname	= "page-cluster",
9611da177e4SLinus Torvalds 		.data		= &page_cluster,
9621da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9631da177e4SLinus Torvalds 		.mode		= 0644,
9641da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
9651da177e4SLinus Torvalds 	},
9661da177e4SLinus Torvalds 	{
9671da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_BACKGROUND,
9681da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
9691da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
9701da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
9711da177e4SLinus Torvalds 		.mode		= 0644,
9722da02997SDavid Rientjes 		.proc_handler	= &dirty_background_ratio_handler,
9731da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9741da177e4SLinus Torvalds 		.extra1		= &zero,
9751da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9761da177e4SLinus Torvalds 	},
9771da177e4SLinus Torvalds 	{
9782da02997SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
9792da02997SDavid Rientjes 		.procname	= "dirty_background_bytes",
9802da02997SDavid Rientjes 		.data		= &dirty_background_bytes,
9812da02997SDavid Rientjes 		.maxlen		= sizeof(dirty_background_bytes),
9822da02997SDavid Rientjes 		.mode		= 0644,
9832da02997SDavid Rientjes 		.proc_handler	= &dirty_background_bytes_handler,
9842da02997SDavid Rientjes 		.strategy	= &sysctl_intvec,
985fc3501d4SSven Wegener 		.extra1		= &one_ul,
9862da02997SDavid Rientjes 	},
9872da02997SDavid Rientjes 	{
9881da177e4SLinus Torvalds 		.ctl_name	= VM_DIRTY_RATIO,
9891da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
9901da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
9911da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
9921da177e4SLinus Torvalds 		.mode		= 0644,
99304fbfdc1SPeter Zijlstra 		.proc_handler	= &dirty_ratio_handler,
9941da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
9951da177e4SLinus Torvalds 		.extra1		= &zero,
9961da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9971da177e4SLinus Torvalds 	},
9981da177e4SLinus Torvalds 	{
9992da02997SDavid Rientjes 		.ctl_name	= CTL_UNNUMBERED,
10002da02997SDavid Rientjes 		.procname	= "dirty_bytes",
10012da02997SDavid Rientjes 		.data		= &vm_dirty_bytes,
10022da02997SDavid Rientjes 		.maxlen		= sizeof(vm_dirty_bytes),
10032da02997SDavid Rientjes 		.mode		= 0644,
10042da02997SDavid Rientjes 		.proc_handler	= &dirty_bytes_handler,
10052da02997SDavid Rientjes 		.strategy	= &sysctl_intvec,
1006fc3501d4SSven Wegener 		.extra1		= &one_ul,
10072da02997SDavid Rientjes 	},
10082da02997SDavid Rientjes 	{
10091da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
1010f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
1011f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
10121da177e4SLinus Torvalds 		.mode		= 0644,
10131da177e4SLinus Torvalds 		.proc_handler	= &dirty_writeback_centisecs_handler,
10141da177e4SLinus Torvalds 	},
10151da177e4SLinus Torvalds 	{
10161da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
1017f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
1018f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
10191da177e4SLinus Torvalds 		.mode		= 0644,
1020704503d8SAlexey Dobriyan 		.proc_handler	= &proc_dointvec,
10211da177e4SLinus Torvalds 	},
10221da177e4SLinus Torvalds 	{
10231da177e4SLinus Torvalds 		.ctl_name	= VM_NR_PDFLUSH_THREADS,
10241da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
10251da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
10261da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
10271da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
10281da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10291da177e4SLinus Torvalds 	},
10301da177e4SLinus Torvalds 	{
1031*fafd688eSPeter W Morreale 		.ctl_name	= CTL_UNNUMBERED,
1032*fafd688eSPeter W Morreale 		.procname	= "nr_pdflush_threads_min",
1033*fafd688eSPeter W Morreale 		.data		= &nr_pdflush_threads_min,
1034*fafd688eSPeter W Morreale 		.maxlen		= sizeof nr_pdflush_threads_min,
1035*fafd688eSPeter W Morreale 		.mode		= 0644 /* read-write */,
1036*fafd688eSPeter W Morreale 		.proc_handler	= &proc_dointvec_minmax,
1037*fafd688eSPeter W Morreale 		.strategy	= &sysctl_intvec,
1038*fafd688eSPeter W Morreale 		.extra1		= &one,
1039*fafd688eSPeter W Morreale 		.extra2		= &nr_pdflush_threads_max,
1040*fafd688eSPeter W Morreale 	},
1041*fafd688eSPeter W Morreale 	{
1042*fafd688eSPeter W Morreale 		.ctl_name	= CTL_UNNUMBERED,
1043*fafd688eSPeter W Morreale 		.procname	= "nr_pdflush_threads_max",
1044*fafd688eSPeter W Morreale 		.data		= &nr_pdflush_threads_max,
1045*fafd688eSPeter W Morreale 		.maxlen		= sizeof nr_pdflush_threads_max,
1046*fafd688eSPeter W Morreale 		.mode		= 0644 /* read-write */,
1047*fafd688eSPeter W Morreale 		.proc_handler	= &proc_dointvec_minmax,
1048*fafd688eSPeter W Morreale 		.strategy	= &sysctl_intvec,
1049*fafd688eSPeter W Morreale 		.extra1		= &nr_pdflush_threads_min,
1050*fafd688eSPeter W Morreale 		.extra2		= &one_thousand,
1051*fafd688eSPeter W Morreale 	},
1052*fafd688eSPeter W Morreale 	{
10531da177e4SLinus Torvalds 		.ctl_name	= VM_SWAPPINESS,
10541da177e4SLinus Torvalds 		.procname	= "swappiness",
10551da177e4SLinus Torvalds 		.data		= &vm_swappiness,
10561da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
10571da177e4SLinus Torvalds 		.mode		= 0644,
10581da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
10591da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
10601da177e4SLinus Torvalds 		.extra1		= &zero,
10611da177e4SLinus Torvalds 		.extra2		= &one_hundred,
10621da177e4SLinus Torvalds 	},
10631da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
10641da177e4SLinus Torvalds 	 {
10651da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
1066e5ff2159SAndi Kleen 		.data		= NULL,
10671da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
10681da177e4SLinus Torvalds 		.mode		= 0644,
10691da177e4SLinus Torvalds 		.proc_handler	= &hugetlb_sysctl_handler,
10701da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
10711da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
10721da177e4SLinus Torvalds 	 },
10731da177e4SLinus Torvalds 	 {
10741da177e4SLinus Torvalds 		.ctl_name	= VM_HUGETLB_GROUP,
10751da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
10761da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
10771da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
10781da177e4SLinus Torvalds 		.mode		= 0644,
10791da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
10801da177e4SLinus Torvalds 	 },
1081396faf03SMel Gorman 	 {
1082396faf03SMel Gorman 		.ctl_name	= CTL_UNNUMBERED,
1083396faf03SMel Gorman 		.procname	= "hugepages_treat_as_movable",
1084396faf03SMel Gorman 		.data		= &hugepages_treat_as_movable,
1085396faf03SMel Gorman 		.maxlen		= sizeof(int),
1086396faf03SMel Gorman 		.mode		= 0644,
1087396faf03SMel Gorman 		.proc_handler	= &hugetlb_treat_movable_handler,
1088396faf03SMel Gorman 	},
108954f9f80dSAdam Litke 	{
109054f9f80dSAdam Litke 		.ctl_name	= CTL_UNNUMBERED,
1091d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
1092e5ff2159SAndi Kleen 		.data		= NULL,
1093e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
1094d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
1095a3d0c6aaSNishanth Aravamudan 		.proc_handler	= &hugetlb_overcommit_handler,
1096e5ff2159SAndi Kleen 		.extra1		= (void *)&hugetlb_zero,
1097e5ff2159SAndi Kleen 		.extra2		= (void *)&hugetlb_infinity,
1098d1c3fb1fSNishanth Aravamudan 	},
10991da177e4SLinus Torvalds #endif
11001da177e4SLinus Torvalds 	{
11011da177e4SLinus Torvalds 		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
11021da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
11031da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
11041da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
11051da177e4SLinus Torvalds 		.mode		= 0644,
11061da177e4SLinus Torvalds 		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
11071da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11081da177e4SLinus Torvalds 	},
11091da177e4SLinus Torvalds 	{
11109d0243bcSAndrew Morton 		.ctl_name	= VM_DROP_PAGECACHE,
11119d0243bcSAndrew Morton 		.procname	= "drop_caches",
11129d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
11139d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
11149d0243bcSAndrew Morton 		.mode		= 0644,
11159d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
11169d0243bcSAndrew Morton 		.strategy	= &sysctl_intvec,
11179d0243bcSAndrew Morton 	},
11189d0243bcSAndrew Morton 	{
11191da177e4SLinus Torvalds 		.ctl_name	= VM_MIN_FREE_KBYTES,
11201da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
11211da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
11221da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
11231da177e4SLinus Torvalds 		.mode		= 0644,
11241da177e4SLinus Torvalds 		.proc_handler	= &min_free_kbytes_sysctl_handler,
11251da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11261da177e4SLinus Torvalds 		.extra1		= &zero,
11271da177e4SLinus Torvalds 	},
11288ad4b1fbSRohit Seth 	{
11298ad4b1fbSRohit Seth 		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
11308ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
11318ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
11328ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
11338ad4b1fbSRohit Seth 		.mode		= 0644,
11348ad4b1fbSRohit Seth 		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
11358ad4b1fbSRohit Seth 		.strategy	= &sysctl_intvec,
11368ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
11378ad4b1fbSRohit Seth 	},
11381da177e4SLinus Torvalds #ifdef CONFIG_MMU
11391da177e4SLinus Torvalds 	{
11401da177e4SLinus Torvalds 		.ctl_name	= VM_MAX_MAP_COUNT,
11411da177e4SLinus Torvalds 		.procname	= "max_map_count",
11421da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
11431da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
11441da177e4SLinus Torvalds 		.mode		= 0644,
11451da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec
11461da177e4SLinus Torvalds 	},
1147dd8632a1SPaul Mundt #else
1148dd8632a1SPaul Mundt 	{
1149dd8632a1SPaul Mundt 		.ctl_name	= CTL_UNNUMBERED,
1150dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
1151dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
1152dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
1153dd8632a1SPaul Mundt 		.mode		= 0644,
1154dd8632a1SPaul Mundt 		.proc_handler	= &proc_dointvec_minmax,
1155dd8632a1SPaul Mundt 		.strategy	= &sysctl_intvec,
1156dd8632a1SPaul Mundt 		.extra1		= &zero,
1157dd8632a1SPaul Mundt 	},
11581da177e4SLinus Torvalds #endif
11591da177e4SLinus Torvalds 	{
11601da177e4SLinus Torvalds 		.ctl_name	= VM_LAPTOP_MODE,
11611da177e4SLinus Torvalds 		.procname	= "laptop_mode",
11621da177e4SLinus Torvalds 		.data		= &laptop_mode,
11631da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
11641da177e4SLinus Torvalds 		.mode		= 0644,
1165ed5b43f1SBart Samwel 		.proc_handler	= &proc_dointvec_jiffies,
1166ed5b43f1SBart Samwel 		.strategy	= &sysctl_jiffies,
11671da177e4SLinus Torvalds 	},
11681da177e4SLinus Torvalds 	{
11691da177e4SLinus Torvalds 		.ctl_name	= VM_BLOCK_DUMP,
11701da177e4SLinus Torvalds 		.procname	= "block_dump",
11711da177e4SLinus Torvalds 		.data		= &block_dump,
11721da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
11731da177e4SLinus Torvalds 		.mode		= 0644,
11741da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11751da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11761da177e4SLinus Torvalds 		.extra1		= &zero,
11771da177e4SLinus Torvalds 	},
11781da177e4SLinus Torvalds 	{
11791da177e4SLinus Torvalds 		.ctl_name	= VM_VFS_CACHE_PRESSURE,
11801da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
11811da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
11821da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
11831da177e4SLinus Torvalds 		.mode		= 0644,
11841da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11851da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11861da177e4SLinus Torvalds 		.extra1		= &zero,
11871da177e4SLinus Torvalds 	},
11881da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
11891da177e4SLinus Torvalds 	{
11901da177e4SLinus Torvalds 		.ctl_name	= VM_LEGACY_VA_LAYOUT,
11911da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
11921da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
11931da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
11941da177e4SLinus Torvalds 		.mode		= 0644,
11951da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
11961da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
11971da177e4SLinus Torvalds 		.extra1		= &zero,
11981da177e4SLinus Torvalds 	},
11991da177e4SLinus Torvalds #endif
12001743660bSChristoph Lameter #ifdef CONFIG_NUMA
12011743660bSChristoph Lameter 	{
12021743660bSChristoph Lameter 		.ctl_name	= VM_ZONE_RECLAIM_MODE,
12031743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
12041743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
12051743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
12061743660bSChristoph Lameter 		.mode		= 0644,
12071743660bSChristoph Lameter 		.proc_handler	= &proc_dointvec,
1208c84db23cSChristoph Lameter 		.strategy	= &sysctl_intvec,
1209c84db23cSChristoph Lameter 		.extra1		= &zero,
12101743660bSChristoph Lameter 	},
12119614634fSChristoph Lameter 	{
12129614634fSChristoph Lameter 		.ctl_name	= VM_MIN_UNMAPPED,
12139614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
12149614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
12159614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
12169614634fSChristoph Lameter 		.mode		= 0644,
12179614634fSChristoph Lameter 		.proc_handler	= &sysctl_min_unmapped_ratio_sysctl_handler,
12189614634fSChristoph Lameter 		.strategy	= &sysctl_intvec,
12199614634fSChristoph Lameter 		.extra1		= &zero,
12209614634fSChristoph Lameter 		.extra2		= &one_hundred,
12219614634fSChristoph Lameter 	},
12220ff38490SChristoph Lameter 	{
12230ff38490SChristoph Lameter 		.ctl_name	= VM_MIN_SLAB,
12240ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
12250ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
12260ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
12270ff38490SChristoph Lameter 		.mode		= 0644,
12280ff38490SChristoph Lameter 		.proc_handler	= &sysctl_min_slab_ratio_sysctl_handler,
12290ff38490SChristoph Lameter 		.strategy	= &sysctl_intvec,
12300ff38490SChristoph Lameter 		.extra1		= &zero,
12310ff38490SChristoph Lameter 		.extra2		= &one_hundred,
12320ff38490SChristoph Lameter 	},
12331743660bSChristoph Lameter #endif
123477461ab3SChristoph Lameter #ifdef CONFIG_SMP
123577461ab3SChristoph Lameter 	{
123677461ab3SChristoph Lameter 		.ctl_name	= CTL_UNNUMBERED,
123777461ab3SChristoph Lameter 		.procname	= "stat_interval",
123877461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
123977461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
124077461ab3SChristoph Lameter 		.mode		= 0644,
124177461ab3SChristoph Lameter 		.proc_handler	= &proc_dointvec_jiffies,
124277461ab3SChristoph Lameter 		.strategy	= &sysctl_jiffies,
124377461ab3SChristoph Lameter 	},
124477461ab3SChristoph Lameter #endif
1245ed032189SEric Paris #ifdef CONFIG_SECURITY
1246ed032189SEric Paris 	{
1247ed032189SEric Paris 		.ctl_name	= CTL_UNNUMBERED,
1248ed032189SEric Paris 		.procname	= "mmap_min_addr",
1249ed032189SEric Paris 		.data		= &mmap_min_addr,
1250ed032189SEric Paris 		.maxlen         = sizeof(unsigned long),
1251ed032189SEric Paris 		.mode		= 0644,
1252ed032189SEric Paris 		.proc_handler	= &proc_doulongvec_minmax,
1253ed032189SEric Paris 	},
12548daec965SLee Schermerhorn #endif
1255f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
1256f0c0b2b8SKAMEZAWA Hiroyuki 	{
1257f0c0b2b8SKAMEZAWA Hiroyuki 		.ctl_name	= CTL_UNNUMBERED,
1258f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
1259f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
1260f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
1261f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
1262f0c0b2b8SKAMEZAWA Hiroyuki 		.proc_handler	= &numa_zonelist_order_handler,
1263f0c0b2b8SKAMEZAWA Hiroyuki 		.strategy	= &sysctl_string,
1264f0c0b2b8SKAMEZAWA Hiroyuki 	},
1265f0c0b2b8SKAMEZAWA Hiroyuki #endif
12662b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
12675c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1268e6e5494cSIngo Molnar 	{
1269e6e5494cSIngo Molnar 		.ctl_name	= VM_VDSO_ENABLED,
1270e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
1271e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
1272e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
1273e6e5494cSIngo Molnar 		.mode		= 0644,
1274e6e5494cSIngo Molnar 		.proc_handler	= &proc_dointvec,
1275e6e5494cSIngo Molnar 		.strategy	= &sysctl_intvec,
1276e6e5494cSIngo Molnar 		.extra1		= &zero,
1277e6e5494cSIngo Molnar 	},
1278e6e5494cSIngo Molnar #endif
1279195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
1280195cf453SBron Gondwana 	{
1281195cf453SBron Gondwana 		.ctl_name	= CTL_UNNUMBERED,
1282195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
1283195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
1284195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
1285195cf453SBron Gondwana 		.mode		= 0644,
1286195cf453SBron Gondwana 		.proc_handler	= &proc_dointvec_minmax,
1287195cf453SBron Gondwana 		.strategy	= &sysctl_intvec,
1288195cf453SBron Gondwana 		.extra1		= &zero,
1289195cf453SBron Gondwana 		.extra2		= &one,
1290195cf453SBron Gondwana 	},
1291195cf453SBron Gondwana #endif
12922be7fe07SAndrew Morton /*
12932be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
12942be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
12952be7fe07SAndrew Morton  */
12961da177e4SLinus Torvalds 	{ .ctl_name = 0 }
12971da177e4SLinus Torvalds };
12981da177e4SLinus Torvalds 
12992abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1300d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = {
13012abc26fcSEric W. Biederman 	{ .ctl_name = 0 }
13022abc26fcSEric W. Biederman };
13032abc26fcSEric W. Biederman #endif
13042abc26fcSEric W. Biederman 
1305d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
13061da177e4SLinus Torvalds 	{
13071da177e4SLinus Torvalds 		.ctl_name	= FS_NRINODE,
13081da177e4SLinus Torvalds 		.procname	= "inode-nr",
13091da177e4SLinus Torvalds 		.data		= &inodes_stat,
13101da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
13111da177e4SLinus Torvalds 		.mode		= 0444,
13121da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13131da177e4SLinus Torvalds 	},
13141da177e4SLinus Torvalds 	{
13151da177e4SLinus Torvalds 		.ctl_name	= FS_STATINODE,
13161da177e4SLinus Torvalds 		.procname	= "inode-state",
13171da177e4SLinus Torvalds 		.data		= &inodes_stat,
13181da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
13191da177e4SLinus Torvalds 		.mode		= 0444,
13201da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13211da177e4SLinus Torvalds 	},
13221da177e4SLinus Torvalds 	{
13231da177e4SLinus Torvalds 		.procname	= "file-nr",
13241da177e4SLinus Torvalds 		.data		= &files_stat,
13251da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
13261da177e4SLinus Torvalds 		.mode		= 0444,
1327529bf6beSDipankar Sarma 		.proc_handler	= &proc_nr_files,
13281da177e4SLinus Torvalds 	},
13291da177e4SLinus Torvalds 	{
13301da177e4SLinus Torvalds 		.ctl_name	= FS_MAXFILE,
13311da177e4SLinus Torvalds 		.procname	= "file-max",
13321da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
13331da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13341da177e4SLinus Torvalds 		.mode		= 0644,
13351da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13361da177e4SLinus Torvalds 	},
13371da177e4SLinus Torvalds 	{
13389cfe015aSEric Dumazet 		.ctl_name	= CTL_UNNUMBERED,
13399cfe015aSEric Dumazet 		.procname	= "nr_open",
13409cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
13419cfe015aSEric Dumazet 		.maxlen		= sizeof(int),
13429cfe015aSEric Dumazet 		.mode		= 0644,
1343eceea0b3SAl Viro 		.proc_handler	= &proc_dointvec_minmax,
1344eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
1345eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
13469cfe015aSEric Dumazet 	},
13479cfe015aSEric Dumazet 	{
13481da177e4SLinus Torvalds 		.ctl_name	= FS_DENTRY,
13491da177e4SLinus Torvalds 		.procname	= "dentry-state",
13501da177e4SLinus Torvalds 		.data		= &dentry_stat,
13511da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
13521da177e4SLinus Torvalds 		.mode		= 0444,
13531da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13541da177e4SLinus Torvalds 	},
13551da177e4SLinus Torvalds 	{
13561da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWUID,
13571da177e4SLinus Torvalds 		.procname	= "overflowuid",
13581da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
13591da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13601da177e4SLinus Torvalds 		.mode		= 0644,
13611da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
13621da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
13631da177e4SLinus Torvalds 		.extra1		= &minolduid,
13641da177e4SLinus Torvalds 		.extra2		= &maxolduid,
13651da177e4SLinus Torvalds 	},
13661da177e4SLinus Torvalds 	{
13671da177e4SLinus Torvalds 		.ctl_name	= FS_OVERFLOWGID,
13681da177e4SLinus Torvalds 		.procname	= "overflowgid",
13691da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
13701da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13711da177e4SLinus Torvalds 		.mode		= 0644,
13721da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec_minmax,
13731da177e4SLinus Torvalds 		.strategy	= &sysctl_intvec,
13741da177e4SLinus Torvalds 		.extra1		= &minolduid,
13751da177e4SLinus Torvalds 		.extra2		= &maxolduid,
13761da177e4SLinus Torvalds 	},
1377bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
13781da177e4SLinus Torvalds 	{
13791da177e4SLinus Torvalds 		.ctl_name	= FS_LEASES,
13801da177e4SLinus Torvalds 		.procname	= "leases-enable",
13811da177e4SLinus Torvalds 		.data		= &leases_enable,
13821da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13831da177e4SLinus Torvalds 		.mode		= 0644,
13841da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13851da177e4SLinus Torvalds 	},
1386bfcd17a6SThomas Petazzoni #endif
13871da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
13881da177e4SLinus Torvalds 	{
13891da177e4SLinus Torvalds 		.ctl_name	= FS_DIR_NOTIFY,
13901da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
13911da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
13921da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13931da177e4SLinus Torvalds 		.mode		= 0644,
13941da177e4SLinus Torvalds 		.proc_handler	= &proc_dointvec,
13951da177e4SLinus Torvalds 	},
13961da177e4SLinus Torvalds #endif
13971da177e4SLinus Torvalds #ifdef CONFIG_MMU
1398bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
13991da177e4SLinus Torvalds 	{
14001da177e4SLinus Torvalds 		.ctl_name	= FS_LEASE_TIME,
14011da177e4SLinus Torvalds 		.procname	= "lease-break-time",
14021da177e4SLinus Torvalds 		.data		= &lease_break_time,
14031da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
14041da177e4SLinus Torvalds 		.mode		= 0644,
14058e654fbaSMatthew Wilcox 		.proc_handler	= &proc_dointvec,
14061da177e4SLinus Torvalds 	},
1407bfcd17a6SThomas Petazzoni #endif
1408ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO
14091da177e4SLinus Torvalds 	{
14101da177e4SLinus Torvalds 		.procname	= "aio-nr",
14111da177e4SLinus Torvalds 		.data		= &aio_nr,
14121da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
14131da177e4SLinus Torvalds 		.mode		= 0444,
1414d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
14151da177e4SLinus Torvalds 	},
14161da177e4SLinus Torvalds 	{
14171da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
14181da177e4SLinus Torvalds 		.data		= &aio_max_nr,
14191da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
14201da177e4SLinus Torvalds 		.mode		= 0644,
1421d55b5fdaSZach Brown 		.proc_handler	= &proc_doulongvec_minmax,
14221da177e4SLinus Torvalds 	},
1423ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */
14242d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
14250399cb08SRobert Love 	{
14260399cb08SRobert Love 		.ctl_name	= FS_INOTIFY,
14270399cb08SRobert Love 		.procname	= "inotify",
14280399cb08SRobert Love 		.mode		= 0555,
14290399cb08SRobert Love 		.child		= inotify_table,
14300399cb08SRobert Love 	},
14310399cb08SRobert Love #endif
14327ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
14337ef9964eSDavide Libenzi 	{
14347ef9964eSDavide Libenzi 		.procname	= "epoll",
14357ef9964eSDavide Libenzi 		.mode		= 0555,
14367ef9964eSDavide Libenzi 		.child		= epoll_table,
14377ef9964eSDavide Libenzi 	},
14387ef9964eSDavide Libenzi #endif
14391da177e4SLinus Torvalds #endif
1440d6e71144SAlan Cox 	{
1441d6e71144SAlan Cox 		.ctl_name	= KERN_SETUID_DUMPABLE,
1442d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1443d6e71144SAlan Cox 		.data		= &suid_dumpable,
1444d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1445d6e71144SAlan Cox 		.mode		= 0644,
14468e654fbaSMatthew Wilcox 		.proc_handler	= &proc_dointvec_minmax,
14478e654fbaSMatthew Wilcox 		.strategy	= &sysctl_intvec,
14488e654fbaSMatthew Wilcox 		.extra1		= &zero,
14498e654fbaSMatthew Wilcox 		.extra2		= &two,
1450d6e71144SAlan Cox 	},
14512abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
14522abc26fcSEric W. Biederman 	{
14532abc26fcSEric W. Biederman 		.ctl_name	= CTL_UNNUMBERED,
14542abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
14552abc26fcSEric W. Biederman 		.mode		= 0555,
14562abc26fcSEric W. Biederman 		.child		= binfmt_misc_table,
14572abc26fcSEric W. Biederman 	},
14582abc26fcSEric W. Biederman #endif
14592be7fe07SAndrew Morton /*
14602be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
14612be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
14622be7fe07SAndrew Morton  */
14631da177e4SLinus Torvalds 	{ .ctl_name = 0 }
14641da177e4SLinus Torvalds };
14651da177e4SLinus Torvalds 
1466d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
1467d0c3d534SOlof Johansson #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1468abd4f750SMasoud Asgharifard Sharbiani 	{
1469abd4f750SMasoud Asgharifard Sharbiani 		.ctl_name	= CTL_UNNUMBERED,
1470abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
1471abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
1472abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
1473abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
1474abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
1475abd4f750SMasoud Asgharifard Sharbiani 	},
1476abd4f750SMasoud Asgharifard Sharbiani #endif
14771da177e4SLinus Torvalds 	{ .ctl_name = 0 }
14781da177e4SLinus Torvalds };
14791da177e4SLinus Torvalds 
1480d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
14811da177e4SLinus Torvalds 	{ .ctl_name = 0 }
14821da177e4SLinus Torvalds };
14831da177e4SLinus Torvalds 
1484330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1485330d57fbSAl Viro 
1486330d57fbSAl Viro /* called under sysctl_lock */
1487330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1488330d57fbSAl Viro {
1489330d57fbSAl Viro 	if (unlikely(p->unregistering))
1490330d57fbSAl Viro 		return 0;
1491330d57fbSAl Viro 	p->used++;
1492330d57fbSAl Viro 	return 1;
1493330d57fbSAl Viro }
1494330d57fbSAl Viro 
1495330d57fbSAl Viro /* called under sysctl_lock */
1496330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1497330d57fbSAl Viro {
1498330d57fbSAl Viro 	if (!--p->used)
1499330d57fbSAl Viro 		if (unlikely(p->unregistering))
1500330d57fbSAl Viro 			complete(p->unregistering);
1501330d57fbSAl Viro }
1502330d57fbSAl Viro 
1503330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1504330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1505330d57fbSAl Viro {
1506330d57fbSAl Viro 	/*
1507330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1508330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1509330d57fbSAl Viro 	 */
1510330d57fbSAl Viro 	if (unlikely(p->used)) {
1511330d57fbSAl Viro 		struct completion wait;
1512330d57fbSAl Viro 		init_completion(&wait);
1513330d57fbSAl Viro 		p->unregistering = &wait;
1514330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1515330d57fbSAl Viro 		wait_for_completion(&wait);
1516330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1517f7e6ced4SAl Viro 	} else {
1518f7e6ced4SAl Viro 		/* anything non-NULL; we'll never dereference it */
1519f7e6ced4SAl Viro 		p->unregistering = ERR_PTR(-EINVAL);
1520330d57fbSAl Viro 	}
1521330d57fbSAl Viro 	/*
1522330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1523330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1524330d57fbSAl Viro 	 */
1525330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1526330d57fbSAl Viro }
1527330d57fbSAl Viro 
1528f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head)
1529f7e6ced4SAl Viro {
1530f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1531f7e6ced4SAl Viro 	head->count++;
1532f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1533f7e6ced4SAl Viro }
1534f7e6ced4SAl Viro 
1535f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
1536f7e6ced4SAl Viro {
1537f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1538f7e6ced4SAl Viro 	if (!--head->count)
1539f7e6ced4SAl Viro 		kfree(head);
1540f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1541f7e6ced4SAl Viro }
1542f7e6ced4SAl Viro 
1543f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1544f7e6ced4SAl Viro {
1545f7e6ced4SAl Viro 	if (!head)
1546f7e6ced4SAl Viro 		BUG();
1547f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1548f7e6ced4SAl Viro 	if (!use_table(head))
1549f7e6ced4SAl Viro 		head = ERR_PTR(-ENOENT);
1550f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1551f7e6ced4SAl Viro 	return head;
1552f7e6ced4SAl Viro }
1553f7e6ced4SAl Viro 
1554805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head)
1555805b5d5eSEric W. Biederman {
1556805b5d5eSEric W. Biederman 	if (!head)
1557805b5d5eSEric W. Biederman 		return;
1558805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1559805b5d5eSEric W. Biederman 	unuse_table(head);
1560805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1561805b5d5eSEric W. Biederman }
1562805b5d5eSEric W. Biederman 
156373455092SAl Viro static struct ctl_table_set *
156473455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
156573455092SAl Viro {
156673455092SAl Viro 	struct ctl_table_set *set = &root->default_set;
156773455092SAl Viro 	if (root->lookup)
156873455092SAl Viro 		set = root->lookup(root, namespaces);
156973455092SAl Viro 	return set;
157073455092SAl Viro }
157173455092SAl Viro 
1572e51b6ba0SEric W. Biederman static struct list_head *
1573e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1574805b5d5eSEric W. Biederman {
157573455092SAl Viro 	struct ctl_table_set *set = lookup_header_set(root, namespaces);
157673455092SAl Viro 	return &set->list;
1577e51b6ba0SEric W. Biederman }
1578e51b6ba0SEric W. Biederman 
1579e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1580e51b6ba0SEric W. Biederman 					    struct ctl_table_header *prev)
1581e51b6ba0SEric W. Biederman {
1582e51b6ba0SEric W. Biederman 	struct ctl_table_root *root;
1583e51b6ba0SEric W. Biederman 	struct list_head *header_list;
1584805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1585805b5d5eSEric W. Biederman 	struct list_head *tmp;
1586e51b6ba0SEric W. Biederman 
1587805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1588805b5d5eSEric W. Biederman 	if (prev) {
1589e51b6ba0SEric W. Biederman 		head = prev;
1590805b5d5eSEric W. Biederman 		tmp = &prev->ctl_entry;
1591805b5d5eSEric W. Biederman 		unuse_table(prev);
1592805b5d5eSEric W. Biederman 		goto next;
1593805b5d5eSEric W. Biederman 	}
1594805b5d5eSEric W. Biederman 	tmp = &root_table_header.ctl_entry;
1595805b5d5eSEric W. Biederman 	for (;;) {
1596805b5d5eSEric W. Biederman 		head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1597805b5d5eSEric W. Biederman 
1598805b5d5eSEric W. Biederman 		if (!use_table(head))
1599805b5d5eSEric W. Biederman 			goto next;
1600805b5d5eSEric W. Biederman 		spin_unlock(&sysctl_lock);
1601805b5d5eSEric W. Biederman 		return head;
1602805b5d5eSEric W. Biederman 	next:
1603e51b6ba0SEric W. Biederman 		root = head->root;
1604805b5d5eSEric W. Biederman 		tmp = tmp->next;
1605e51b6ba0SEric W. Biederman 		header_list = lookup_header_list(root, namespaces);
1606e51b6ba0SEric W. Biederman 		if (tmp != header_list)
1607e51b6ba0SEric W. Biederman 			continue;
1608e51b6ba0SEric W. Biederman 
1609e51b6ba0SEric W. Biederman 		do {
1610e51b6ba0SEric W. Biederman 			root = list_entry(root->root_list.next,
1611e51b6ba0SEric W. Biederman 					struct ctl_table_root, root_list);
1612e51b6ba0SEric W. Biederman 			if (root == &sysctl_table_root)
1613e51b6ba0SEric W. Biederman 				goto out;
1614e51b6ba0SEric W. Biederman 			header_list = lookup_header_list(root, namespaces);
1615e51b6ba0SEric W. Biederman 		} while (list_empty(header_list));
1616e51b6ba0SEric W. Biederman 		tmp = header_list->next;
1617805b5d5eSEric W. Biederman 	}
1618e51b6ba0SEric W. Biederman out:
1619805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1620805b5d5eSEric W. Biederman 	return NULL;
1621805b5d5eSEric W. Biederman }
1622805b5d5eSEric W. Biederman 
1623e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1624e51b6ba0SEric W. Biederman {
1625e51b6ba0SEric W. Biederman 	return __sysctl_head_next(current->nsproxy, prev);
1626e51b6ba0SEric W. Biederman }
1627e51b6ba0SEric W. Biederman 
1628e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root)
1629e51b6ba0SEric W. Biederman {
1630e51b6ba0SEric W. Biederman 	spin_lock(&sysctl_lock);
1631e51b6ba0SEric W. Biederman 	list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1632e51b6ba0SEric W. Biederman 	spin_unlock(&sysctl_lock);
1633e51b6ba0SEric W. Biederman }
1634e51b6ba0SEric W. Biederman 
1635b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
16362c4c7155SPavel Emelyanov /* Perform the actual read/write of a sysctl table entry. */
1637d7321cd6SPavel Emelyanov static int do_sysctl_strategy(struct ctl_table_root *root,
1638d7321cd6SPavel Emelyanov 			struct ctl_table *table,
16392c4c7155SPavel Emelyanov 			void __user *oldval, size_t __user *oldlenp,
16402c4c7155SPavel Emelyanov 			void __user *newval, size_t newlen)
16412c4c7155SPavel Emelyanov {
16422c4c7155SPavel Emelyanov 	int op = 0, rc;
16432c4c7155SPavel Emelyanov 
16442c4c7155SPavel Emelyanov 	if (oldval)
1645e6305c43SAl Viro 		op |= MAY_READ;
16462c4c7155SPavel Emelyanov 	if (newval)
1647e6305c43SAl Viro 		op |= MAY_WRITE;
1648d7321cd6SPavel Emelyanov 	if (sysctl_perm(root, table, op))
16492c4c7155SPavel Emelyanov 		return -EPERM;
16502c4c7155SPavel Emelyanov 
16512c4c7155SPavel Emelyanov 	if (table->strategy) {
1652f221e726SAlexey Dobriyan 		rc = table->strategy(table, oldval, oldlenp, newval, newlen);
16532c4c7155SPavel Emelyanov 		if (rc < 0)
16542c4c7155SPavel Emelyanov 			return rc;
16552c4c7155SPavel Emelyanov 		if (rc > 0)
16562c4c7155SPavel Emelyanov 			return 0;
16572c4c7155SPavel Emelyanov 	}
16582c4c7155SPavel Emelyanov 
16592c4c7155SPavel Emelyanov 	/* If there is no strategy routine, or if the strategy returns
16602c4c7155SPavel Emelyanov 	 * zero, proceed with automatic r/w */
16612c4c7155SPavel Emelyanov 	if (table->data && table->maxlen) {
1662f221e726SAlexey Dobriyan 		rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
16632c4c7155SPavel Emelyanov 		if (rc < 0)
16642c4c7155SPavel Emelyanov 			return rc;
16652c4c7155SPavel Emelyanov 	}
16662c4c7155SPavel Emelyanov 	return 0;
16672c4c7155SPavel Emelyanov }
16682c4c7155SPavel Emelyanov 
16692c4c7155SPavel Emelyanov static int parse_table(int __user *name, int nlen,
16702c4c7155SPavel Emelyanov 		       void __user *oldval, size_t __user *oldlenp,
16712c4c7155SPavel Emelyanov 		       void __user *newval, size_t newlen,
1672d7321cd6SPavel Emelyanov 		       struct ctl_table_root *root,
16732c4c7155SPavel Emelyanov 		       struct ctl_table *table)
16742c4c7155SPavel Emelyanov {
16752c4c7155SPavel Emelyanov 	int n;
16762c4c7155SPavel Emelyanov repeat:
16772c4c7155SPavel Emelyanov 	if (!nlen)
16782c4c7155SPavel Emelyanov 		return -ENOTDIR;
16792c4c7155SPavel Emelyanov 	if (get_user(n, name))
16802c4c7155SPavel Emelyanov 		return -EFAULT;
16812c4c7155SPavel Emelyanov 	for ( ; table->ctl_name || table->procname; table++) {
16822c4c7155SPavel Emelyanov 		if (!table->ctl_name)
16832c4c7155SPavel Emelyanov 			continue;
16842c4c7155SPavel Emelyanov 		if (n == table->ctl_name) {
16852c4c7155SPavel Emelyanov 			int error;
16862c4c7155SPavel Emelyanov 			if (table->child) {
1687e6305c43SAl Viro 				if (sysctl_perm(root, table, MAY_EXEC))
16882c4c7155SPavel Emelyanov 					return -EPERM;
16892c4c7155SPavel Emelyanov 				name++;
16902c4c7155SPavel Emelyanov 				nlen--;
16912c4c7155SPavel Emelyanov 				table = table->child;
16922c4c7155SPavel Emelyanov 				goto repeat;
16932c4c7155SPavel Emelyanov 			}
1694f221e726SAlexey Dobriyan 			error = do_sysctl_strategy(root, table,
16952c4c7155SPavel Emelyanov 						   oldval, oldlenp,
16962c4c7155SPavel Emelyanov 						   newval, newlen);
16972c4c7155SPavel Emelyanov 			return error;
16982c4c7155SPavel Emelyanov 		}
16992c4c7155SPavel Emelyanov 	}
17002c4c7155SPavel Emelyanov 	return -ENOTDIR;
17012c4c7155SPavel Emelyanov }
17022c4c7155SPavel Emelyanov 
17031da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
17041da177e4SLinus Torvalds 	       void __user *newval, size_t newlen)
17051da177e4SLinus Torvalds {
1706805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1707330d57fbSAl Viro 	int error = -ENOTDIR;
17081da177e4SLinus Torvalds 
17091da177e4SLinus Torvalds 	if (nlen <= 0 || nlen >= CTL_MAXNAME)
17101da177e4SLinus Torvalds 		return -ENOTDIR;
17111da177e4SLinus Torvalds 	if (oldval) {
17121da177e4SLinus Torvalds 		int old_len;
17131da177e4SLinus Torvalds 		if (!oldlenp || get_user(old_len, oldlenp))
17141da177e4SLinus Torvalds 			return -EFAULT;
17151da177e4SLinus Torvalds 	}
1716330d57fbSAl Viro 
1717805b5d5eSEric W. Biederman 	for (head = sysctl_head_next(NULL); head;
1718805b5d5eSEric W. Biederman 			head = sysctl_head_next(head)) {
1719330d57fbSAl Viro 		error = parse_table(name, nlen, oldval, oldlenp,
1720d7321cd6SPavel Emelyanov 					newval, newlen,
1721d7321cd6SPavel Emelyanov 					head->root, head->ctl_table);
1722805b5d5eSEric W. Biederman 		if (error != -ENOTDIR) {
1723805b5d5eSEric W. Biederman 			sysctl_head_finish(head);
1724330d57fbSAl Viro 			break;
1725805b5d5eSEric W. Biederman 		}
1726805b5d5eSEric W. Biederman 	}
17271da177e4SLinus Torvalds 	return error;
17281da177e4SLinus Torvalds }
17291da177e4SLinus Torvalds 
17301e7bfb21SHeiko Carstens SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
17311da177e4SLinus Torvalds {
17321da177e4SLinus Torvalds 	struct __sysctl_args tmp;
17331da177e4SLinus Torvalds 	int error;
17341da177e4SLinus Torvalds 
17351da177e4SLinus Torvalds 	if (copy_from_user(&tmp, args, sizeof(tmp)))
17361da177e4SLinus Torvalds 		return -EFAULT;
17371da177e4SLinus Torvalds 
17387058cb02SEric W. Biederman 	error = deprecated_sysctl_warning(&tmp);
17397058cb02SEric W. Biederman 	if (error)
17407058cb02SEric W. Biederman 		goto out;
17417058cb02SEric W. Biederman 
17421da177e4SLinus Torvalds 	lock_kernel();
17431da177e4SLinus Torvalds 	error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
17441da177e4SLinus Torvalds 			  tmp.newval, tmp.newlen);
17451da177e4SLinus Torvalds 	unlock_kernel();
17467058cb02SEric W. Biederman out:
17471da177e4SLinus Torvalds 	return error;
17481da177e4SLinus Torvalds }
1749b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
17501da177e4SLinus Torvalds 
17511da177e4SLinus Torvalds /*
17521ff007ebSEric W. Biederman  * sysctl_perm does NOT grant the superuser all rights automatically, because
17531da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
17541da177e4SLinus Torvalds  */
17551da177e4SLinus Torvalds 
17561da177e4SLinus Torvalds static int test_perm(int mode, int op)
17571da177e4SLinus Torvalds {
175876aac0e9SDavid Howells 	if (!current_euid())
17591da177e4SLinus Torvalds 		mode >>= 6;
17601da177e4SLinus Torvalds 	else if (in_egroup_p(0))
17611da177e4SLinus Torvalds 		mode >>= 3;
1762e6305c43SAl Viro 	if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
17631da177e4SLinus Torvalds 		return 0;
17641da177e4SLinus Torvalds 	return -EACCES;
17651da177e4SLinus Torvalds }
17661da177e4SLinus Torvalds 
1767d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
17681da177e4SLinus Torvalds {
17691da177e4SLinus Torvalds 	int error;
1770d7321cd6SPavel Emelyanov 	int mode;
1771d7321cd6SPavel Emelyanov 
1772e6305c43SAl Viro 	error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
17731da177e4SLinus Torvalds 	if (error)
17741da177e4SLinus Torvalds 		return error;
1775d7321cd6SPavel Emelyanov 
1776d7321cd6SPavel Emelyanov 	if (root->permissions)
1777d7321cd6SPavel Emelyanov 		mode = root->permissions(root, current->nsproxy, table);
1778d7321cd6SPavel Emelyanov 	else
1779d7321cd6SPavel Emelyanov 		mode = table->mode;
1780d7321cd6SPavel Emelyanov 
1781d7321cd6SPavel Emelyanov 	return test_perm(mode, op);
17821da177e4SLinus Torvalds }
17831da177e4SLinus Torvalds 
1784d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1785d912b0ccSEric W. Biederman {
1786d912b0ccSEric W. Biederman 	for (; table->ctl_name || table->procname; table++) {
1787d912b0ccSEric W. Biederman 		table->parent = parent;
1788d912b0ccSEric W. Biederman 		if (table->child)
1789d912b0ccSEric W. Biederman 			sysctl_set_parent(table, table->child);
1790d912b0ccSEric W. Biederman 	}
1791d912b0ccSEric W. Biederman }
1792d912b0ccSEric W. Biederman 
1793d912b0ccSEric W. Biederman static __init int sysctl_init(void)
1794d912b0ccSEric W. Biederman {
1795d912b0ccSEric W. Biederman 	sysctl_set_parent(NULL, root_table);
179688f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
179788f458e4SHolger Schurig 	{
179888f458e4SHolger Schurig 		int err;
1799e51b6ba0SEric W. Biederman 		err = sysctl_check_table(current->nsproxy, root_table);
180088f458e4SHolger Schurig 	}
180188f458e4SHolger Schurig #endif
1802d912b0ccSEric W. Biederman 	return 0;
1803d912b0ccSEric W. Biederman }
1804d912b0ccSEric W. Biederman 
1805d912b0ccSEric W. Biederman core_initcall(sysctl_init);
1806d912b0ccSEric W. Biederman 
1807bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch,
1808bfbcf034SAl Viro 				      struct ctl_table *table)
1809ae7edeccSAl Viro {
1810ae7edeccSAl Viro 	struct ctl_table *p;
1811ae7edeccSAl Viro 	const char *s = branch->procname;
1812ae7edeccSAl Viro 
1813ae7edeccSAl Viro 	/* branch should have named subdirectory as its first element */
1814ae7edeccSAl Viro 	if (!s || !branch->child)
1815bfbcf034SAl Viro 		return NULL;
1816ae7edeccSAl Viro 
1817ae7edeccSAl Viro 	/* ... and nothing else */
1818ae7edeccSAl Viro 	if (branch[1].procname || branch[1].ctl_name)
1819bfbcf034SAl Viro 		return NULL;
1820ae7edeccSAl Viro 
1821ae7edeccSAl Viro 	/* table should contain subdirectory with the same name */
1822ae7edeccSAl Viro 	for (p = table; p->procname || p->ctl_name; p++) {
1823ae7edeccSAl Viro 		if (!p->child)
1824ae7edeccSAl Viro 			continue;
1825ae7edeccSAl Viro 		if (p->procname && strcmp(p->procname, s) == 0)
1826bfbcf034SAl Viro 			return p;
1827ae7edeccSAl Viro 	}
1828bfbcf034SAl Viro 	return NULL;
1829ae7edeccSAl Viro }
1830ae7edeccSAl Viro 
1831ae7edeccSAl Viro /* see if attaching q to p would be an improvement */
1832ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1833ae7edeccSAl Viro {
1834ae7edeccSAl Viro 	struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1835bfbcf034SAl Viro 	struct ctl_table *next;
1836ae7edeccSAl Viro 	int is_better = 0;
1837ae7edeccSAl Viro 	int not_in_parent = !p->attached_by;
1838ae7edeccSAl Viro 
1839bfbcf034SAl Viro 	while ((next = is_branch_in(by, to)) != NULL) {
1840ae7edeccSAl Viro 		if (by == q->attached_by)
1841ae7edeccSAl Viro 			is_better = 1;
1842ae7edeccSAl Viro 		if (to == p->attached_by)
1843ae7edeccSAl Viro 			not_in_parent = 1;
1844ae7edeccSAl Viro 		by = by->child;
1845bfbcf034SAl Viro 		to = next->child;
1846ae7edeccSAl Viro 	}
1847ae7edeccSAl Viro 
1848ae7edeccSAl Viro 	if (is_better && not_in_parent) {
1849ae7edeccSAl Viro 		q->attached_by = by;
1850ae7edeccSAl Viro 		q->attached_to = to;
1851ae7edeccSAl Viro 		q->parent = p;
1852ae7edeccSAl Viro 	}
1853ae7edeccSAl Viro }
1854ae7edeccSAl Viro 
18551da177e4SLinus Torvalds /**
1856e51b6ba0SEric W. Biederman  * __register_sysctl_paths - register a sysctl hierarchy
1857e51b6ba0SEric W. Biederman  * @root: List of sysctl headers to register on
1858e51b6ba0SEric W. Biederman  * @namespaces: Data to compute which lists of sysctl entries are visible
185929e796fdSEric W. Biederman  * @path: The path to the directory the sysctl table is in.
18601da177e4SLinus Torvalds  * @table: the top-level table structure
18611da177e4SLinus Torvalds  *
18621da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
186329e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
18641da177e4SLinus Torvalds  *
1865d8217f07SEric W. Biederman  * The members of the &struct ctl_table structure are used as follows:
18661da177e4SLinus Torvalds  *
18671da177e4SLinus Torvalds  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
18681da177e4SLinus Torvalds  *            must be unique within that level of sysctl
18691da177e4SLinus Torvalds  *
18701da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
18711da177e4SLinus Torvalds  *            enter a sysctl file
18721da177e4SLinus Torvalds  *
18731da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
18741da177e4SLinus Torvalds  *
18751da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
18761da177e4SLinus Torvalds  *
18771da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
18781da177e4SLinus Torvalds  *
18791da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
18801da177e4SLinus Torvalds  *         %NULL.
18811da177e4SLinus Torvalds  *
18821da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
18831da177e4SLinus Torvalds  *
18841da177e4SLinus Torvalds  * strategy - the strategy routine (described below)
18851da177e4SLinus Torvalds  *
18861da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
18871da177e4SLinus Torvalds  *
18881da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
18891da177e4SLinus Torvalds  *
18901da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
18911da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
18921da177e4SLinus Torvalds  *
18931da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
18941da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
18951da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
18961da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
18971da177e4SLinus Torvalds  *
18981da177e4SLinus Torvalds  * More sophisticated management can be enabled by the provision of a
18991da177e4SLinus Torvalds  * strategy routine with the table entry.  This will be called before
19001da177e4SLinus Torvalds  * any automatic read or write of the data is performed.
19011da177e4SLinus Torvalds  *
19021da177e4SLinus Torvalds  * The strategy routine may return
19031da177e4SLinus Torvalds  *
19041da177e4SLinus Torvalds  * < 0 - Error occurred (error is passed to user process)
19051da177e4SLinus Torvalds  *
19061da177e4SLinus Torvalds  * 0   - OK - proceed with automatic read or write.
19071da177e4SLinus Torvalds  *
19081da177e4SLinus Torvalds  * > 0 - OK - read or write has been done by the strategy routine, so
19091da177e4SLinus Torvalds  *       return immediately.
19101da177e4SLinus Torvalds  *
19111da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
19121da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
19131da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
19141da177e4SLinus Torvalds  * cover common cases -
19151da177e4SLinus Torvalds  *
19161da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
19171da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
19181da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
19191da177e4SLinus Torvalds  *
19201da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
19211da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
19221da177e4SLinus Torvalds  *
19231da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
19241da177e4SLinus Torvalds  * to the table header on success.
19251da177e4SLinus Torvalds  */
1926e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths(
1927e51b6ba0SEric W. Biederman 	struct ctl_table_root *root,
1928e51b6ba0SEric W. Biederman 	struct nsproxy *namespaces,
1929e51b6ba0SEric W. Biederman 	const struct ctl_path *path, struct ctl_table *table)
19301da177e4SLinus Torvalds {
193129e796fdSEric W. Biederman 	struct ctl_table_header *header;
193229e796fdSEric W. Biederman 	struct ctl_table *new, **prevp;
193329e796fdSEric W. Biederman 	unsigned int n, npath;
1934ae7edeccSAl Viro 	struct ctl_table_set *set;
193529e796fdSEric W. Biederman 
193629e796fdSEric W. Biederman 	/* Count the path components */
193729e796fdSEric W. Biederman 	for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
193829e796fdSEric W. Biederman 		;
193929e796fdSEric W. Biederman 
194029e796fdSEric W. Biederman 	/*
194129e796fdSEric W. Biederman 	 * For each path component, allocate a 2-element ctl_table array.
194229e796fdSEric W. Biederman 	 * The first array element will be filled with the sysctl entry
194329e796fdSEric W. Biederman 	 * for this, the second will be the sentinel (ctl_name == 0).
194429e796fdSEric W. Biederman 	 *
194529e796fdSEric W. Biederman 	 * We allocate everything in one go so that we don't have to
194629e796fdSEric W. Biederman 	 * worry about freeing additional memory in unregister_sysctl_table.
194729e796fdSEric W. Biederman 	 */
194829e796fdSEric W. Biederman 	header = kzalloc(sizeof(struct ctl_table_header) +
194929e796fdSEric W. Biederman 			 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
195029e796fdSEric W. Biederman 	if (!header)
19511da177e4SLinus Torvalds 		return NULL;
195229e796fdSEric W. Biederman 
195329e796fdSEric W. Biederman 	new = (struct ctl_table *) (header + 1);
195429e796fdSEric W. Biederman 
195529e796fdSEric W. Biederman 	/* Now connect the dots */
195629e796fdSEric W. Biederman 	prevp = &header->ctl_table;
195729e796fdSEric W. Biederman 	for (n = 0; n < npath; ++n, ++path) {
195829e796fdSEric W. Biederman 		/* Copy the procname */
195929e796fdSEric W. Biederman 		new->procname = path->procname;
196029e796fdSEric W. Biederman 		new->ctl_name = path->ctl_name;
196129e796fdSEric W. Biederman 		new->mode     = 0555;
196229e796fdSEric W. Biederman 
196329e796fdSEric W. Biederman 		*prevp = new;
196429e796fdSEric W. Biederman 		prevp = &new->child;
196529e796fdSEric W. Biederman 
196629e796fdSEric W. Biederman 		new += 2;
196729e796fdSEric W. Biederman 	}
196829e796fdSEric W. Biederman 	*prevp = table;
196923eb06deSEric W. Biederman 	header->ctl_table_arg = table;
197029e796fdSEric W. Biederman 
197129e796fdSEric W. Biederman 	INIT_LIST_HEAD(&header->ctl_entry);
197229e796fdSEric W. Biederman 	header->used = 0;
197329e796fdSEric W. Biederman 	header->unregistering = NULL;
1974e51b6ba0SEric W. Biederman 	header->root = root;
197529e796fdSEric W. Biederman 	sysctl_set_parent(NULL, header->ctl_table);
1976f7e6ced4SAl Viro 	header->count = 1;
197788f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1978e51b6ba0SEric W. Biederman 	if (sysctl_check_table(namespaces, header->ctl_table)) {
197929e796fdSEric W. Biederman 		kfree(header);
1980fc6cd25bSEric W. Biederman 		return NULL;
1981fc6cd25bSEric W. Biederman 	}
198288f458e4SHolger Schurig #endif
1983330d57fbSAl Viro 	spin_lock(&sysctl_lock);
198473455092SAl Viro 	header->set = lookup_header_set(root, namespaces);
1985ae7edeccSAl Viro 	header->attached_by = header->ctl_table;
1986ae7edeccSAl Viro 	header->attached_to = root_table;
1987ae7edeccSAl Viro 	header->parent = &root_table_header;
1988ae7edeccSAl Viro 	for (set = header->set; set; set = set->parent) {
1989ae7edeccSAl Viro 		struct ctl_table_header *p;
1990ae7edeccSAl Viro 		list_for_each_entry(p, &set->list, ctl_entry) {
1991ae7edeccSAl Viro 			if (p->unregistering)
1992ae7edeccSAl Viro 				continue;
1993ae7edeccSAl Viro 			try_attach(p, header);
1994ae7edeccSAl Viro 		}
1995ae7edeccSAl Viro 	}
1996ae7edeccSAl Viro 	header->parent->count++;
199773455092SAl Viro 	list_add_tail(&header->ctl_entry, &header->set->list);
1998330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
199929e796fdSEric W. Biederman 
200029e796fdSEric W. Biederman 	return header;
200129e796fdSEric W. Biederman }
200229e796fdSEric W. Biederman 
200329e796fdSEric W. Biederman /**
2004e51b6ba0SEric W. Biederman  * register_sysctl_table_path - register a sysctl table hierarchy
2005e51b6ba0SEric W. Biederman  * @path: The path to the directory the sysctl table is in.
2006e51b6ba0SEric W. Biederman  * @table: the top-level table structure
2007e51b6ba0SEric W. Biederman  *
2008e51b6ba0SEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2009e51b6ba0SEric W. Biederman  * array. A completely 0 filled entry terminates the table.
2010e51b6ba0SEric W. Biederman  *
2011e51b6ba0SEric W. Biederman  * See __register_sysctl_paths for more details.
2012e51b6ba0SEric W. Biederman  */
2013e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2014e51b6ba0SEric W. Biederman 						struct ctl_table *table)
2015e51b6ba0SEric W. Biederman {
2016e51b6ba0SEric W. Biederman 	return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2017e51b6ba0SEric W. Biederman 					path, table);
2018e51b6ba0SEric W. Biederman }
2019e51b6ba0SEric W. Biederman 
2020e51b6ba0SEric W. Biederman /**
202129e796fdSEric W. Biederman  * register_sysctl_table - register a sysctl table hierarchy
202229e796fdSEric W. Biederman  * @table: the top-level table structure
202329e796fdSEric W. Biederman  *
202429e796fdSEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
202529e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
202629e796fdSEric W. Biederman  *
202729e796fdSEric W. Biederman  * See register_sysctl_paths for more details.
202829e796fdSEric W. Biederman  */
202929e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
203029e796fdSEric W. Biederman {
203129e796fdSEric W. Biederman 	static const struct ctl_path null_path[] = { {} };
203229e796fdSEric W. Biederman 
203329e796fdSEric W. Biederman 	return register_sysctl_paths(null_path, table);
20341da177e4SLinus Torvalds }
20351da177e4SLinus Torvalds 
20361da177e4SLinus Torvalds /**
20371da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
20381da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
20391da177e4SLinus Torvalds  *
20401da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
20411da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
20421da177e4SLinus Torvalds  */
20431da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
20441da177e4SLinus Torvalds {
2045330d57fbSAl Viro 	might_sleep();
2046f1dad166SPavel Emelyanov 
2047f1dad166SPavel Emelyanov 	if (header == NULL)
2048f1dad166SPavel Emelyanov 		return;
2049f1dad166SPavel Emelyanov 
2050330d57fbSAl Viro 	spin_lock(&sysctl_lock);
2051330d57fbSAl Viro 	start_unregistering(header);
2052ae7edeccSAl Viro 	if (!--header->parent->count) {
2053ae7edeccSAl Viro 		WARN_ON(1);
2054ae7edeccSAl Viro 		kfree(header->parent);
2055ae7edeccSAl Viro 	}
2056f7e6ced4SAl Viro 	if (!--header->count)
20571da177e4SLinus Torvalds 		kfree(header);
2058f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
20591da177e4SLinus Torvalds }
20601da177e4SLinus Torvalds 
20619043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p)
20629043476fSAl Viro {
20639043476fSAl Viro 	struct ctl_table_set *set = p->set;
20649043476fSAl Viro 	int res;
20659043476fSAl Viro 	spin_lock(&sysctl_lock);
20669043476fSAl Viro 	if (p->unregistering)
20679043476fSAl Viro 		res = 0;
20689043476fSAl Viro 	else if (!set->is_seen)
20699043476fSAl Viro 		res = 1;
20709043476fSAl Viro 	else
20719043476fSAl Viro 		res = set->is_seen(set);
20729043476fSAl Viro 	spin_unlock(&sysctl_lock);
20739043476fSAl Viro 	return res;
20749043476fSAl Viro }
20759043476fSAl Viro 
207673455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
207773455092SAl Viro 	struct ctl_table_set *parent,
207873455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
207973455092SAl Viro {
208073455092SAl Viro 	INIT_LIST_HEAD(&p->list);
208173455092SAl Viro 	p->parent = parent ? parent : &sysctl_table_root.default_set;
208273455092SAl Viro 	p->is_seen = is_seen;
208373455092SAl Viro }
208473455092SAl Viro 
2085b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */
2086d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2087b89a8171SEric W. Biederman {
2088b89a8171SEric W. Biederman 	return NULL;
2089b89a8171SEric W. Biederman }
2090b89a8171SEric W. Biederman 
209129e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
209229e796fdSEric W. Biederman 						    struct ctl_table *table)
209329e796fdSEric W. Biederman {
209429e796fdSEric W. Biederman 	return NULL;
209529e796fdSEric W. Biederman }
209629e796fdSEric W. Biederman 
2097b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table)
2098b89a8171SEric W. Biederman {
2099b89a8171SEric W. Biederman }
2100b89a8171SEric W. Biederman 
210173455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
210273455092SAl Viro 	struct ctl_table_set *parent,
210373455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
210473455092SAl Viro {
210573455092SAl Viro }
210673455092SAl Viro 
2107f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
2108f7e6ced4SAl Viro {
2109f7e6ced4SAl Viro }
2110f7e6ced4SAl Viro 
2111b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
2112b89a8171SEric W. Biederman 
21131da177e4SLinus Torvalds /*
21141da177e4SLinus Torvalds  * /proc/sys support
21151da177e4SLinus Torvalds  */
21161da177e4SLinus Torvalds 
2117b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
21181da177e4SLinus Torvalds 
2119b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write,
2120b1ba4dddSAdrian Bunk 			   struct file *filp, void __user *buffer,
2121b1ba4dddSAdrian Bunk 			   size_t *lenp, loff_t *ppos)
2122f5dd3d6fSSam Vilain {
2123f5dd3d6fSSam Vilain 	size_t len;
2124f5dd3d6fSSam Vilain 	char __user *p;
2125f5dd3d6fSSam Vilain 	char c;
2126f5dd3d6fSSam Vilain 
21278d060877SOleg Nesterov 	if (!data || !maxlen || !*lenp) {
2128f5dd3d6fSSam Vilain 		*lenp = 0;
2129f5dd3d6fSSam Vilain 		return 0;
2130f5dd3d6fSSam Vilain 	}
2131f5dd3d6fSSam Vilain 
2132f5dd3d6fSSam Vilain 	if (write) {
2133f5dd3d6fSSam Vilain 		len = 0;
2134f5dd3d6fSSam Vilain 		p = buffer;
2135f5dd3d6fSSam Vilain 		while (len < *lenp) {
2136f5dd3d6fSSam Vilain 			if (get_user(c, p++))
2137f5dd3d6fSSam Vilain 				return -EFAULT;
2138f5dd3d6fSSam Vilain 			if (c == 0 || c == '\n')
2139f5dd3d6fSSam Vilain 				break;
2140f5dd3d6fSSam Vilain 			len++;
2141f5dd3d6fSSam Vilain 		}
2142f5dd3d6fSSam Vilain 		if (len >= maxlen)
2143f5dd3d6fSSam Vilain 			len = maxlen-1;
2144f5dd3d6fSSam Vilain 		if(copy_from_user(data, buffer, len))
2145f5dd3d6fSSam Vilain 			return -EFAULT;
2146f5dd3d6fSSam Vilain 		((char *) data)[len] = 0;
2147f5dd3d6fSSam Vilain 		*ppos += *lenp;
2148f5dd3d6fSSam Vilain 	} else {
2149f5dd3d6fSSam Vilain 		len = strlen(data);
2150f5dd3d6fSSam Vilain 		if (len > maxlen)
2151f5dd3d6fSSam Vilain 			len = maxlen;
21528d060877SOleg Nesterov 
21538d060877SOleg Nesterov 		if (*ppos > len) {
21548d060877SOleg Nesterov 			*lenp = 0;
21558d060877SOleg Nesterov 			return 0;
21568d060877SOleg Nesterov 		}
21578d060877SOleg Nesterov 
21588d060877SOleg Nesterov 		data += *ppos;
21598d060877SOleg Nesterov 		len  -= *ppos;
21608d060877SOleg Nesterov 
2161f5dd3d6fSSam Vilain 		if (len > *lenp)
2162f5dd3d6fSSam Vilain 			len = *lenp;
2163f5dd3d6fSSam Vilain 		if (len)
2164f5dd3d6fSSam Vilain 			if(copy_to_user(buffer, data, len))
2165f5dd3d6fSSam Vilain 				return -EFAULT;
2166f5dd3d6fSSam Vilain 		if (len < *lenp) {
2167f5dd3d6fSSam Vilain 			if(put_user('\n', ((char __user *) buffer) + len))
2168f5dd3d6fSSam Vilain 				return -EFAULT;
2169f5dd3d6fSSam Vilain 			len++;
2170f5dd3d6fSSam Vilain 		}
2171f5dd3d6fSSam Vilain 		*lenp = len;
2172f5dd3d6fSSam Vilain 		*ppos += len;
2173f5dd3d6fSSam Vilain 	}
2174f5dd3d6fSSam Vilain 	return 0;
2175f5dd3d6fSSam Vilain }
2176f5dd3d6fSSam Vilain 
21771da177e4SLinus Torvalds /**
21781da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
21791da177e4SLinus Torvalds  * @table: the sysctl table
21801da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
21811da177e4SLinus Torvalds  * @filp: the file structure
21821da177e4SLinus Torvalds  * @buffer: the user buffer
21831da177e4SLinus Torvalds  * @lenp: the size of the user buffer
21841da177e4SLinus Torvalds  * @ppos: file position
21851da177e4SLinus Torvalds  *
21861da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
21871da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
21881da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
21891da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
21901da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
21911da177e4SLinus Torvalds  * not large enough.
21921da177e4SLinus Torvalds  *
21931da177e4SLinus Torvalds  * Returns 0 on success.
21941da177e4SLinus Torvalds  */
2195d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp,
21961da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
21971da177e4SLinus Torvalds {
2198f5dd3d6fSSam Vilain 	return _proc_do_string(table->data, table->maxlen, write, filp,
2199f5dd3d6fSSam Vilain 			       buffer, lenp, ppos);
22001da177e4SLinus Torvalds }
22011da177e4SLinus Torvalds 
22021da177e4SLinus Torvalds 
22031da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
22041da177e4SLinus Torvalds 				 int *valp,
22051da177e4SLinus Torvalds 				 int write, void *data)
22061da177e4SLinus Torvalds {
22071da177e4SLinus Torvalds 	if (write) {
22081da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
22091da177e4SLinus Torvalds 	} else {
22101da177e4SLinus Torvalds 		int val = *valp;
22111da177e4SLinus Torvalds 		if (val < 0) {
22121da177e4SLinus Torvalds 			*negp = -1;
22131da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
22141da177e4SLinus Torvalds 		} else {
22151da177e4SLinus Torvalds 			*negp = 0;
22161da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
22171da177e4SLinus Torvalds 		}
22181da177e4SLinus Torvalds 	}
22191da177e4SLinus Torvalds 	return 0;
22201da177e4SLinus Torvalds }
22211da177e4SLinus Torvalds 
2222d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2223fcfbd547SKirill Korotaev 		  int write, struct file *filp, void __user *buffer,
2224fcfbd547SKirill Korotaev 		  size_t *lenp, loff_t *ppos,
22251da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
22261da177e4SLinus Torvalds 			      int write, void *data),
22271da177e4SLinus Torvalds 		  void *data)
22281da177e4SLinus Torvalds {
22291da177e4SLinus Torvalds #define TMPBUFLEN 21
22301da177e4SLinus Torvalds 	int *i, vleft, first=1, neg, val;
22311da177e4SLinus Torvalds 	unsigned long lval;
22321da177e4SLinus Torvalds 	size_t left, len;
22331da177e4SLinus Torvalds 
22341da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
22351da177e4SLinus Torvalds 	char __user *s = buffer;
22361da177e4SLinus Torvalds 
2237fcfbd547SKirill Korotaev 	if (!tbl_data || !table->maxlen || !*lenp ||
22381da177e4SLinus Torvalds 	    (*ppos && !write)) {
22391da177e4SLinus Torvalds 		*lenp = 0;
22401da177e4SLinus Torvalds 		return 0;
22411da177e4SLinus Torvalds 	}
22421da177e4SLinus Torvalds 
2243fcfbd547SKirill Korotaev 	i = (int *) tbl_data;
22441da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
22451da177e4SLinus Torvalds 	left = *lenp;
22461da177e4SLinus Torvalds 
22471da177e4SLinus Torvalds 	if (!conv)
22481da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
22491da177e4SLinus Torvalds 
22501da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
22511da177e4SLinus Torvalds 		if (write) {
22521da177e4SLinus Torvalds 			while (left) {
22531da177e4SLinus Torvalds 				char c;
22541da177e4SLinus Torvalds 				if (get_user(c, s))
22551da177e4SLinus Torvalds 					return -EFAULT;
22561da177e4SLinus Torvalds 				if (!isspace(c))
22571da177e4SLinus Torvalds 					break;
22581da177e4SLinus Torvalds 				left--;
22591da177e4SLinus Torvalds 				s++;
22601da177e4SLinus Torvalds 			}
22611da177e4SLinus Torvalds 			if (!left)
22621da177e4SLinus Torvalds 				break;
22631da177e4SLinus Torvalds 			neg = 0;
22641da177e4SLinus Torvalds 			len = left;
22651da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
22661da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
22671da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
22681da177e4SLinus Torvalds 				return -EFAULT;
22691da177e4SLinus Torvalds 			buf[len] = 0;
22701da177e4SLinus Torvalds 			p = buf;
22711da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
22721da177e4SLinus Torvalds 				neg = 1;
2273bd9b0bacSBP, Praveen 				p++;
22741da177e4SLinus Torvalds 			}
22751da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
22761da177e4SLinus Torvalds 				break;
22771da177e4SLinus Torvalds 
22781da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
22791da177e4SLinus Torvalds 
22801da177e4SLinus Torvalds 			len = p-buf;
22811da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
22821da177e4SLinus Torvalds 				break;
22831da177e4SLinus Torvalds 			if (neg)
22841da177e4SLinus Torvalds 				val = -val;
22851da177e4SLinus Torvalds 			s += len;
22861da177e4SLinus Torvalds 			left -= len;
22871da177e4SLinus Torvalds 
22881da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
22891da177e4SLinus Torvalds 				break;
22901da177e4SLinus Torvalds 		} else {
22911da177e4SLinus Torvalds 			p = buf;
22921da177e4SLinus Torvalds 			if (!first)
22931da177e4SLinus Torvalds 				*p++ = '\t';
22941da177e4SLinus Torvalds 
22951da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
22961da177e4SLinus Torvalds 				break;
22971da177e4SLinus Torvalds 
22981da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
22991da177e4SLinus Torvalds 			len = strlen(buf);
23001da177e4SLinus Torvalds 			if (len > left)
23011da177e4SLinus Torvalds 				len = left;
23021da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
23031da177e4SLinus Torvalds 				return -EFAULT;
23041da177e4SLinus Torvalds 			left -= len;
23051da177e4SLinus Torvalds 			s += len;
23061da177e4SLinus Torvalds 		}
23071da177e4SLinus Torvalds 	}
23081da177e4SLinus Torvalds 
23091da177e4SLinus Torvalds 	if (!write && !first && left) {
23101da177e4SLinus Torvalds 		if(put_user('\n', s))
23111da177e4SLinus Torvalds 			return -EFAULT;
23121da177e4SLinus Torvalds 		left--, s++;
23131da177e4SLinus Torvalds 	}
23141da177e4SLinus Torvalds 	if (write) {
23151da177e4SLinus Torvalds 		while (left) {
23161da177e4SLinus Torvalds 			char c;
23171da177e4SLinus Torvalds 			if (get_user(c, s++))
23181da177e4SLinus Torvalds 				return -EFAULT;
23191da177e4SLinus Torvalds 			if (!isspace(c))
23201da177e4SLinus Torvalds 				break;
23211da177e4SLinus Torvalds 			left--;
23221da177e4SLinus Torvalds 		}
23231da177e4SLinus Torvalds 	}
23241da177e4SLinus Torvalds 	if (write && first)
23251da177e4SLinus Torvalds 		return -EINVAL;
23261da177e4SLinus Torvalds 	*lenp -= left;
23271da177e4SLinus Torvalds 	*ppos += *lenp;
23281da177e4SLinus Torvalds 	return 0;
23291da177e4SLinus Torvalds #undef TMPBUFLEN
23301da177e4SLinus Torvalds }
23311da177e4SLinus Torvalds 
2332d8217f07SEric W. Biederman static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2333fcfbd547SKirill Korotaev 		  void __user *buffer, size_t *lenp, loff_t *ppos,
2334fcfbd547SKirill Korotaev 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2335fcfbd547SKirill Korotaev 			      int write, void *data),
2336fcfbd547SKirill Korotaev 		  void *data)
2337fcfbd547SKirill Korotaev {
2338fcfbd547SKirill Korotaev 	return __do_proc_dointvec(table->data, table, write, filp,
2339fcfbd547SKirill Korotaev 			buffer, lenp, ppos, conv, data);
2340fcfbd547SKirill Korotaev }
2341fcfbd547SKirill Korotaev 
23421da177e4SLinus Torvalds /**
23431da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
23441da177e4SLinus Torvalds  * @table: the sysctl table
23451da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
23461da177e4SLinus Torvalds  * @filp: the file structure
23471da177e4SLinus Torvalds  * @buffer: the user buffer
23481da177e4SLinus Torvalds  * @lenp: the size of the user buffer
23491da177e4SLinus Torvalds  * @ppos: file position
23501da177e4SLinus Torvalds  *
23511da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
23521da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
23531da177e4SLinus Torvalds  *
23541da177e4SLinus Torvalds  * Returns 0 on success.
23551da177e4SLinus Torvalds  */
2356d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
23571da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
23581da177e4SLinus Torvalds {
23591da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
23601da177e4SLinus Torvalds 		    	    NULL,NULL);
23611da177e4SLinus Torvalds }
23621da177e4SLinus Torvalds 
236334f5a398STheodore Ts'o /*
236434f5a398STheodore Ts'o  * Taint values can only be increased
236525ddbb18SAndi Kleen  * This means we can safely use a temporary.
236634f5a398STheodore Ts'o  */
236725ddbb18SAndi Kleen static int proc_taint(struct ctl_table *table, int write, struct file *filp,
236834f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos)
236934f5a398STheodore Ts'o {
237025ddbb18SAndi Kleen 	struct ctl_table t;
237125ddbb18SAndi Kleen 	unsigned long tmptaint = get_taint();
237225ddbb18SAndi Kleen 	int err;
237334f5a398STheodore Ts'o 
237491fcd412SBastian Blank 	if (write && !capable(CAP_SYS_ADMIN))
237534f5a398STheodore Ts'o 		return -EPERM;
237634f5a398STheodore Ts'o 
237725ddbb18SAndi Kleen 	t = *table;
237825ddbb18SAndi Kleen 	t.data = &tmptaint;
237925ddbb18SAndi Kleen 	err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
238025ddbb18SAndi Kleen 	if (err < 0)
238125ddbb18SAndi Kleen 		return err;
238225ddbb18SAndi Kleen 
238325ddbb18SAndi Kleen 	if (write) {
238425ddbb18SAndi Kleen 		/*
238525ddbb18SAndi Kleen 		 * Poor man's atomic or. Not worth adding a primitive
238625ddbb18SAndi Kleen 		 * to everyone's atomic.h for this
238725ddbb18SAndi Kleen 		 */
238825ddbb18SAndi Kleen 		int i;
238925ddbb18SAndi Kleen 		for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
239025ddbb18SAndi Kleen 			if ((tmptaint >> i) & 1)
239125ddbb18SAndi Kleen 				add_taint(i);
239225ddbb18SAndi Kleen 		}
239325ddbb18SAndi Kleen 	}
239425ddbb18SAndi Kleen 
239525ddbb18SAndi Kleen 	return err;
239634f5a398STheodore Ts'o }
239734f5a398STheodore Ts'o 
23981da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
23991da177e4SLinus Torvalds 	int *min;
24001da177e4SLinus Torvalds 	int *max;
24011da177e4SLinus Torvalds };
24021da177e4SLinus Torvalds 
24031da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
24041da177e4SLinus Torvalds 					int *valp,
24051da177e4SLinus Torvalds 					int write, void *data)
24061da177e4SLinus Torvalds {
24071da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
24081da177e4SLinus Torvalds 	if (write) {
24091da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
24101da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
24111da177e4SLinus Torvalds 		    (param->max && *param->max < val))
24121da177e4SLinus Torvalds 			return -EINVAL;
24131da177e4SLinus Torvalds 		*valp = val;
24141da177e4SLinus Torvalds 	} else {
24151da177e4SLinus Torvalds 		int val = *valp;
24161da177e4SLinus Torvalds 		if (val < 0) {
24171da177e4SLinus Torvalds 			*negp = -1;
24181da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
24191da177e4SLinus Torvalds 		} else {
24201da177e4SLinus Torvalds 			*negp = 0;
24211da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
24221da177e4SLinus Torvalds 		}
24231da177e4SLinus Torvalds 	}
24241da177e4SLinus Torvalds 	return 0;
24251da177e4SLinus Torvalds }
24261da177e4SLinus Torvalds 
24271da177e4SLinus Torvalds /**
24281da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
24291da177e4SLinus Torvalds  * @table: the sysctl table
24301da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
24311da177e4SLinus Torvalds  * @filp: the file structure
24321da177e4SLinus Torvalds  * @buffer: the user buffer
24331da177e4SLinus Torvalds  * @lenp: the size of the user buffer
24341da177e4SLinus Torvalds  * @ppos: file position
24351da177e4SLinus Torvalds  *
24361da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
24371da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
24381da177e4SLinus Torvalds  *
24391da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
24401da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
24411da177e4SLinus Torvalds  *
24421da177e4SLinus Torvalds  * Returns 0 on success.
24431da177e4SLinus Torvalds  */
2444d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
24451da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
24461da177e4SLinus Torvalds {
24471da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
24481da177e4SLinus Torvalds 		.min = (int *) table->extra1,
24491da177e4SLinus Torvalds 		.max = (int *) table->extra2,
24501da177e4SLinus Torvalds 	};
24511da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
24521da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
24531da177e4SLinus Torvalds }
24541da177e4SLinus Torvalds 
2455d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
24561da177e4SLinus Torvalds 				     struct file *filp,
24571da177e4SLinus Torvalds 				     void __user *buffer,
24581da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
24591da177e4SLinus Torvalds 				     unsigned long convmul,
24601da177e4SLinus Torvalds 				     unsigned long convdiv)
24611da177e4SLinus Torvalds {
24621da177e4SLinus Torvalds #define TMPBUFLEN 21
24631da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
24641da177e4SLinus Torvalds 	int vleft, first=1, neg;
24651da177e4SLinus Torvalds 	size_t len, left;
24661da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
24671da177e4SLinus Torvalds 	char __user *s = buffer;
24681da177e4SLinus Torvalds 
2469fcfbd547SKirill Korotaev 	if (!data || !table->maxlen || !*lenp ||
24701da177e4SLinus Torvalds 	    (*ppos && !write)) {
24711da177e4SLinus Torvalds 		*lenp = 0;
24721da177e4SLinus Torvalds 		return 0;
24731da177e4SLinus Torvalds 	}
24741da177e4SLinus Torvalds 
2475fcfbd547SKirill Korotaev 	i = (unsigned long *) data;
24761da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
24771da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
24781da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
24791da177e4SLinus Torvalds 	left = *lenp;
24801da177e4SLinus Torvalds 
24811da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
24821da177e4SLinus Torvalds 		if (write) {
24831da177e4SLinus Torvalds 			while (left) {
24841da177e4SLinus Torvalds 				char c;
24851da177e4SLinus Torvalds 				if (get_user(c, s))
24861da177e4SLinus Torvalds 					return -EFAULT;
24871da177e4SLinus Torvalds 				if (!isspace(c))
24881da177e4SLinus Torvalds 					break;
24891da177e4SLinus Torvalds 				left--;
24901da177e4SLinus Torvalds 				s++;
24911da177e4SLinus Torvalds 			}
24921da177e4SLinus Torvalds 			if (!left)
24931da177e4SLinus Torvalds 				break;
24941da177e4SLinus Torvalds 			neg = 0;
24951da177e4SLinus Torvalds 			len = left;
24961da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
24971da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
24981da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
24991da177e4SLinus Torvalds 				return -EFAULT;
25001da177e4SLinus Torvalds 			buf[len] = 0;
25011da177e4SLinus Torvalds 			p = buf;
25021da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
25031da177e4SLinus Torvalds 				neg = 1;
2504bd9b0bacSBP, Praveen 				p++;
25051da177e4SLinus Torvalds 			}
25061da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
25071da177e4SLinus Torvalds 				break;
25081da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
25091da177e4SLinus Torvalds 			len = p-buf;
25101da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
25111da177e4SLinus Torvalds 				break;
25121da177e4SLinus Torvalds 			if (neg)
25131da177e4SLinus Torvalds 				val = -val;
25141da177e4SLinus Torvalds 			s += len;
25151da177e4SLinus Torvalds 			left -= len;
25161da177e4SLinus Torvalds 
25171da177e4SLinus Torvalds 			if(neg)
25181da177e4SLinus Torvalds 				continue;
25191da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
25201da177e4SLinus Torvalds 				continue;
25211da177e4SLinus Torvalds 			*i = val;
25221da177e4SLinus Torvalds 		} else {
25231da177e4SLinus Torvalds 			p = buf;
25241da177e4SLinus Torvalds 			if (!first)
25251da177e4SLinus Torvalds 				*p++ = '\t';
25261da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
25271da177e4SLinus Torvalds 			len = strlen(buf);
25281da177e4SLinus Torvalds 			if (len > left)
25291da177e4SLinus Torvalds 				len = left;
25301da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
25311da177e4SLinus Torvalds 				return -EFAULT;
25321da177e4SLinus Torvalds 			left -= len;
25331da177e4SLinus Torvalds 			s += len;
25341da177e4SLinus Torvalds 		}
25351da177e4SLinus Torvalds 	}
25361da177e4SLinus Torvalds 
25371da177e4SLinus Torvalds 	if (!write && !first && left) {
25381da177e4SLinus Torvalds 		if(put_user('\n', s))
25391da177e4SLinus Torvalds 			return -EFAULT;
25401da177e4SLinus Torvalds 		left--, s++;
25411da177e4SLinus Torvalds 	}
25421da177e4SLinus Torvalds 	if (write) {
25431da177e4SLinus Torvalds 		while (left) {
25441da177e4SLinus Torvalds 			char c;
25451da177e4SLinus Torvalds 			if (get_user(c, s++))
25461da177e4SLinus Torvalds 				return -EFAULT;
25471da177e4SLinus Torvalds 			if (!isspace(c))
25481da177e4SLinus Torvalds 				break;
25491da177e4SLinus Torvalds 			left--;
25501da177e4SLinus Torvalds 		}
25511da177e4SLinus Torvalds 	}
25521da177e4SLinus Torvalds 	if (write && first)
25531da177e4SLinus Torvalds 		return -EINVAL;
25541da177e4SLinus Torvalds 	*lenp -= left;
25551da177e4SLinus Torvalds 	*ppos += *lenp;
25561da177e4SLinus Torvalds 	return 0;
25571da177e4SLinus Torvalds #undef TMPBUFLEN
25581da177e4SLinus Torvalds }
25591da177e4SLinus Torvalds 
2560d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2561fcfbd547SKirill Korotaev 				     struct file *filp,
2562fcfbd547SKirill Korotaev 				     void __user *buffer,
2563fcfbd547SKirill Korotaev 				     size_t *lenp, loff_t *ppos,
2564fcfbd547SKirill Korotaev 				     unsigned long convmul,
2565fcfbd547SKirill Korotaev 				     unsigned long convdiv)
2566fcfbd547SKirill Korotaev {
2567fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(table->data, table, write,
2568fcfbd547SKirill Korotaev 			filp, buffer, lenp, ppos, convmul, convdiv);
2569fcfbd547SKirill Korotaev }
2570fcfbd547SKirill Korotaev 
25711da177e4SLinus Torvalds /**
25721da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
25731da177e4SLinus Torvalds  * @table: the sysctl table
25741da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
25751da177e4SLinus Torvalds  * @filp: the file structure
25761da177e4SLinus Torvalds  * @buffer: the user buffer
25771da177e4SLinus Torvalds  * @lenp: the size of the user buffer
25781da177e4SLinus Torvalds  * @ppos: file position
25791da177e4SLinus Torvalds  *
25801da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
25811da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
25821da177e4SLinus Torvalds  *
25831da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
25841da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
25851da177e4SLinus Torvalds  *
25861da177e4SLinus Torvalds  * Returns 0 on success.
25871da177e4SLinus Torvalds  */
2588d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
25891da177e4SLinus Torvalds 			   void __user *buffer, size_t *lenp, loff_t *ppos)
25901da177e4SLinus Torvalds {
25911da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
25921da177e4SLinus Torvalds }
25931da177e4SLinus Torvalds 
25941da177e4SLinus Torvalds /**
25951da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
25961da177e4SLinus Torvalds  * @table: the sysctl table
25971da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
25981da177e4SLinus Torvalds  * @filp: the file structure
25991da177e4SLinus Torvalds  * @buffer: the user buffer
26001da177e4SLinus Torvalds  * @lenp: the size of the user buffer
26011da177e4SLinus Torvalds  * @ppos: file position
26021da177e4SLinus Torvalds  *
26031da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
26041da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
26051da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
26061da177e4SLinus Torvalds  *
26071da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
26081da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
26091da177e4SLinus Torvalds  *
26101da177e4SLinus Torvalds  * Returns 0 on success.
26111da177e4SLinus Torvalds  */
2612d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
26131da177e4SLinus Torvalds 				      struct file *filp,
26141da177e4SLinus Torvalds 				      void __user *buffer,
26151da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
26161da177e4SLinus Torvalds {
26171da177e4SLinus Torvalds     return do_proc_doulongvec_minmax(table, write, filp, buffer,
26181da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
26191da177e4SLinus Torvalds }
26201da177e4SLinus Torvalds 
26211da177e4SLinus Torvalds 
26221da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
26231da177e4SLinus Torvalds 					 int *valp,
26241da177e4SLinus Torvalds 					 int write, void *data)
26251da177e4SLinus Torvalds {
26261da177e4SLinus Torvalds 	if (write) {
2627cba9f33dSBart Samwel 		if (*lvalp > LONG_MAX / HZ)
2628cba9f33dSBart Samwel 			return 1;
26291da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
26301da177e4SLinus Torvalds 	} else {
26311da177e4SLinus Torvalds 		int val = *valp;
26321da177e4SLinus Torvalds 		unsigned long lval;
26331da177e4SLinus Torvalds 		if (val < 0) {
26341da177e4SLinus Torvalds 			*negp = -1;
26351da177e4SLinus Torvalds 			lval = (unsigned long)-val;
26361da177e4SLinus Torvalds 		} else {
26371da177e4SLinus Torvalds 			*negp = 0;
26381da177e4SLinus Torvalds 			lval = (unsigned long)val;
26391da177e4SLinus Torvalds 		}
26401da177e4SLinus Torvalds 		*lvalp = lval / HZ;
26411da177e4SLinus Torvalds 	}
26421da177e4SLinus Torvalds 	return 0;
26431da177e4SLinus Torvalds }
26441da177e4SLinus Torvalds 
26451da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
26461da177e4SLinus Torvalds 						int *valp,
26471da177e4SLinus Torvalds 						int write, void *data)
26481da177e4SLinus Torvalds {
26491da177e4SLinus Torvalds 	if (write) {
2650cba9f33dSBart Samwel 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2651cba9f33dSBart Samwel 			return 1;
26521da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
26531da177e4SLinus Torvalds 	} else {
26541da177e4SLinus Torvalds 		int val = *valp;
26551da177e4SLinus Torvalds 		unsigned long lval;
26561da177e4SLinus Torvalds 		if (val < 0) {
26571da177e4SLinus Torvalds 			*negp = -1;
26581da177e4SLinus Torvalds 			lval = (unsigned long)-val;
26591da177e4SLinus Torvalds 		} else {
26601da177e4SLinus Torvalds 			*negp = 0;
26611da177e4SLinus Torvalds 			lval = (unsigned long)val;
26621da177e4SLinus Torvalds 		}
26631da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
26641da177e4SLinus Torvalds 	}
26651da177e4SLinus Torvalds 	return 0;
26661da177e4SLinus Torvalds }
26671da177e4SLinus Torvalds 
26681da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
26691da177e4SLinus Torvalds 					    int *valp,
26701da177e4SLinus Torvalds 					    int write, void *data)
26711da177e4SLinus Torvalds {
26721da177e4SLinus Torvalds 	if (write) {
26731da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
26741da177e4SLinus Torvalds 	} else {
26751da177e4SLinus Torvalds 		int val = *valp;
26761da177e4SLinus Torvalds 		unsigned long lval;
26771da177e4SLinus Torvalds 		if (val < 0) {
26781da177e4SLinus Torvalds 			*negp = -1;
26791da177e4SLinus Torvalds 			lval = (unsigned long)-val;
26801da177e4SLinus Torvalds 		} else {
26811da177e4SLinus Torvalds 			*negp = 0;
26821da177e4SLinus Torvalds 			lval = (unsigned long)val;
26831da177e4SLinus Torvalds 		}
26841da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
26851da177e4SLinus Torvalds 	}
26861da177e4SLinus Torvalds 	return 0;
26871da177e4SLinus Torvalds }
26881da177e4SLinus Torvalds 
26891da177e4SLinus Torvalds /**
26901da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
26911da177e4SLinus Torvalds  * @table: the sysctl table
26921da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
26931da177e4SLinus Torvalds  * @filp: the file structure
26941da177e4SLinus Torvalds  * @buffer: the user buffer
26951da177e4SLinus Torvalds  * @lenp: the size of the user buffer
26961da177e4SLinus Torvalds  * @ppos: file position
26971da177e4SLinus Torvalds  *
26981da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
26991da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
27001da177e4SLinus Torvalds  * The values read are assumed to be in seconds, and are converted into
27011da177e4SLinus Torvalds  * jiffies.
27021da177e4SLinus Torvalds  *
27031da177e4SLinus Torvalds  * Returns 0 on success.
27041da177e4SLinus Torvalds  */
2705d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
27061da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
27071da177e4SLinus Torvalds {
27081da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
27091da177e4SLinus Torvalds 		    	    do_proc_dointvec_jiffies_conv,NULL);
27101da177e4SLinus Torvalds }
27111da177e4SLinus Torvalds 
27121da177e4SLinus Torvalds /**
27131da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
27141da177e4SLinus Torvalds  * @table: the sysctl table
27151da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
27161da177e4SLinus Torvalds  * @filp: the file structure
27171da177e4SLinus Torvalds  * @buffer: the user buffer
27181da177e4SLinus Torvalds  * @lenp: the size of the user buffer
27191e5d5331SRandy Dunlap  * @ppos: pointer to the file position
27201da177e4SLinus Torvalds  *
27211da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
27221da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
27231da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
27241da177e4SLinus Torvalds  * are converted into jiffies.
27251da177e4SLinus Torvalds  *
27261da177e4SLinus Torvalds  * Returns 0 on success.
27271da177e4SLinus Torvalds  */
2728d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
27291da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
27301da177e4SLinus Torvalds {
27311da177e4SLinus Torvalds     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
27321da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
27331da177e4SLinus Torvalds }
27341da177e4SLinus Torvalds 
27351da177e4SLinus Torvalds /**
27361da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
27371da177e4SLinus Torvalds  * @table: the sysctl table
27381da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
27391da177e4SLinus Torvalds  * @filp: the file structure
27401da177e4SLinus Torvalds  * @buffer: the user buffer
27411da177e4SLinus Torvalds  * @lenp: the size of the user buffer
274267be2dd1SMartin Waitz  * @ppos: file position
274367be2dd1SMartin Waitz  * @ppos: the current position in the file
27441da177e4SLinus Torvalds  *
27451da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
27461da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
27471da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
27481da177e4SLinus Torvalds  * are converted into jiffies.
27491da177e4SLinus Torvalds  *
27501da177e4SLinus Torvalds  * Returns 0 on success.
27511da177e4SLinus Torvalds  */
2752d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
27531da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
27541da177e4SLinus Torvalds {
27551da177e4SLinus Torvalds 	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
27561da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
27571da177e4SLinus Torvalds }
27581da177e4SLinus Torvalds 
2759d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
27609ec52099SCedric Le Goater 			   void __user *buffer, size_t *lenp, loff_t *ppos)
27619ec52099SCedric Le Goater {
27629ec52099SCedric Le Goater 	struct pid *new_pid;
27639ec52099SCedric Le Goater 	pid_t tmp;
27649ec52099SCedric Le Goater 	int r;
27659ec52099SCedric Le Goater 
27666c5f3e7bSPavel Emelyanov 	tmp = pid_vnr(cad_pid);
27679ec52099SCedric Le Goater 
27689ec52099SCedric Le Goater 	r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
27699ec52099SCedric Le Goater 			       lenp, ppos, NULL, NULL);
27709ec52099SCedric Le Goater 	if (r || !write)
27719ec52099SCedric Le Goater 		return r;
27729ec52099SCedric Le Goater 
27739ec52099SCedric Le Goater 	new_pid = find_get_pid(tmp);
27749ec52099SCedric Le Goater 	if (!new_pid)
27759ec52099SCedric Le Goater 		return -ESRCH;
27769ec52099SCedric Le Goater 
27779ec52099SCedric Le Goater 	put_pid(xchg(&cad_pid, new_pid));
27789ec52099SCedric Le Goater 	return 0;
27799ec52099SCedric Le Goater }
27809ec52099SCedric Le Goater 
27811da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
27821da177e4SLinus Torvalds 
2783d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp,
27841da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
27851da177e4SLinus Torvalds {
27861da177e4SLinus Torvalds 	return -ENOSYS;
27871da177e4SLinus Torvalds }
27881da177e4SLinus Torvalds 
2789d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
27901da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
27911da177e4SLinus Torvalds {
27921da177e4SLinus Torvalds 	return -ENOSYS;
27931da177e4SLinus Torvalds }
27941da177e4SLinus Torvalds 
2795d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
27961da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
27971da177e4SLinus Torvalds {
27981da177e4SLinus Torvalds 	return -ENOSYS;
27991da177e4SLinus Torvalds }
28001da177e4SLinus Torvalds 
2801d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
28021da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28031da177e4SLinus Torvalds {
28041da177e4SLinus Torvalds 	return -ENOSYS;
28051da177e4SLinus Torvalds }
28061da177e4SLinus Torvalds 
2807d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
28081da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28091da177e4SLinus Torvalds {
28101da177e4SLinus Torvalds 	return -ENOSYS;
28111da177e4SLinus Torvalds }
28121da177e4SLinus Torvalds 
2813d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
28141da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
28151da177e4SLinus Torvalds {
28161da177e4SLinus Torvalds 	return -ENOSYS;
28171da177e4SLinus Torvalds }
28181da177e4SLinus Torvalds 
2819d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
28201da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
28211da177e4SLinus Torvalds {
28221da177e4SLinus Torvalds 	return -ENOSYS;
28231da177e4SLinus Torvalds }
28241da177e4SLinus Torvalds 
2825d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
28261da177e4SLinus Torvalds 				      struct file *filp,
28271da177e4SLinus Torvalds 				      void __user *buffer,
28281da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
28291da177e4SLinus Torvalds {
28301da177e4SLinus Torvalds     return -ENOSYS;
28311da177e4SLinus Torvalds }
28321da177e4SLinus Torvalds 
28331da177e4SLinus Torvalds 
28341da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
28351da177e4SLinus Torvalds 
28361da177e4SLinus Torvalds 
2837b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL
28381da177e4SLinus Torvalds /*
28391da177e4SLinus Torvalds  * General sysctl support routines
28401da177e4SLinus Torvalds  */
28411da177e4SLinus Torvalds 
284249a0c458SEric W. Biederman /* The generic sysctl data routine (used if no strategy routine supplied) */
2843f221e726SAlexey Dobriyan int sysctl_data(struct ctl_table *table,
284449a0c458SEric W. Biederman 		void __user *oldval, size_t __user *oldlenp,
284549a0c458SEric W. Biederman 		void __user *newval, size_t newlen)
284649a0c458SEric W. Biederman {
284749a0c458SEric W. Biederman 	size_t len;
284849a0c458SEric W. Biederman 
284949a0c458SEric W. Biederman 	/* Get out of I don't have a variable */
285049a0c458SEric W. Biederman 	if (!table->data || !table->maxlen)
285149a0c458SEric W. Biederman 		return -ENOTDIR;
285249a0c458SEric W. Biederman 
285349a0c458SEric W. Biederman 	if (oldval && oldlenp) {
285449a0c458SEric W. Biederman 		if (get_user(len, oldlenp))
285549a0c458SEric W. Biederman 			return -EFAULT;
285649a0c458SEric W. Biederman 		if (len) {
285749a0c458SEric W. Biederman 			if (len > table->maxlen)
285849a0c458SEric W. Biederman 				len = table->maxlen;
285949a0c458SEric W. Biederman 			if (copy_to_user(oldval, table->data, len))
286049a0c458SEric W. Biederman 				return -EFAULT;
286149a0c458SEric W. Biederman 			if (put_user(len, oldlenp))
286249a0c458SEric W. Biederman 				return -EFAULT;
286349a0c458SEric W. Biederman 		}
286449a0c458SEric W. Biederman 	}
286549a0c458SEric W. Biederman 
286649a0c458SEric W. Biederman 	if (newval && newlen) {
286749a0c458SEric W. Biederman 		if (newlen > table->maxlen)
286849a0c458SEric W. Biederman 			newlen = table->maxlen;
286949a0c458SEric W. Biederman 
287049a0c458SEric W. Biederman 		if (copy_from_user(table->data, newval, newlen))
287149a0c458SEric W. Biederman 			return -EFAULT;
287249a0c458SEric W. Biederman 	}
287349a0c458SEric W. Biederman 	return 1;
287449a0c458SEric W. Biederman }
287549a0c458SEric W. Biederman 
28761da177e4SLinus Torvalds /* The generic string strategy routine: */
2877f221e726SAlexey Dobriyan int sysctl_string(struct ctl_table *table,
28781da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
28791f29bcd7SAlexey Dobriyan 		  void __user *newval, size_t newlen)
28801da177e4SLinus Torvalds {
28811da177e4SLinus Torvalds 	if (!table->data || !table->maxlen)
28821da177e4SLinus Torvalds 		return -ENOTDIR;
28831da177e4SLinus Torvalds 
28841da177e4SLinus Torvalds 	if (oldval && oldlenp) {
2885de9e007dSLinus Torvalds 		size_t bufsize;
2886de9e007dSLinus Torvalds 		if (get_user(bufsize, oldlenp))
28871da177e4SLinus Torvalds 			return -EFAULT;
2888de9e007dSLinus Torvalds 		if (bufsize) {
2889de9e007dSLinus Torvalds 			size_t len = strlen(table->data), copied;
2890de9e007dSLinus Torvalds 
2891de9e007dSLinus Torvalds 			/* This shouldn't trigger for a well-formed sysctl */
2892de9e007dSLinus Torvalds 			if (len > table->maxlen)
28931da177e4SLinus Torvalds 				len = table->maxlen;
2894de9e007dSLinus Torvalds 
2895de9e007dSLinus Torvalds 			/* Copy up to a max of bufsize-1 bytes of the string */
2896de9e007dSLinus Torvalds 			copied = (len >= bufsize) ? bufsize - 1 : len;
2897de9e007dSLinus Torvalds 
2898de9e007dSLinus Torvalds 			if (copy_to_user(oldval, table->data, copied) ||
2899de9e007dSLinus Torvalds 			    put_user(0, (char __user *)(oldval + copied)))
29001da177e4SLinus Torvalds 				return -EFAULT;
29011da177e4SLinus Torvalds 			if (put_user(len, oldlenp))
29021da177e4SLinus Torvalds 				return -EFAULT;
29031da177e4SLinus Torvalds 		}
29041da177e4SLinus Torvalds 	}
29051da177e4SLinus Torvalds 	if (newval && newlen) {
2906de9e007dSLinus Torvalds 		size_t len = newlen;
29071da177e4SLinus Torvalds 		if (len > table->maxlen)
29081da177e4SLinus Torvalds 			len = table->maxlen;
29091da177e4SLinus Torvalds 		if(copy_from_user(table->data, newval, len))
29101da177e4SLinus Torvalds 			return -EFAULT;
29111da177e4SLinus Torvalds 		if (len == table->maxlen)
29121da177e4SLinus Torvalds 			len--;
29131da177e4SLinus Torvalds 		((char *) table->data)[len] = 0;
29141da177e4SLinus Torvalds 	}
291582c9df82SYi Yang 	return 1;
29161da177e4SLinus Torvalds }
29171da177e4SLinus Torvalds 
29181da177e4SLinus Torvalds /*
29191da177e4SLinus Torvalds  * This function makes sure that all of the integers in the vector
29201da177e4SLinus Torvalds  * are between the minimum and maximum values given in the arrays
29211da177e4SLinus Torvalds  * table->extra1 and table->extra2, respectively.
29221da177e4SLinus Torvalds  */
2923f221e726SAlexey Dobriyan int sysctl_intvec(struct ctl_table *table,
29241da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29251f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29261da177e4SLinus Torvalds {
29271da177e4SLinus Torvalds 
29281da177e4SLinus Torvalds 	if (newval && newlen) {
29291da177e4SLinus Torvalds 		int __user *vec = (int __user *) newval;
29301da177e4SLinus Torvalds 		int *min = (int *) table->extra1;
29311da177e4SLinus Torvalds 		int *max = (int *) table->extra2;
29321da177e4SLinus Torvalds 		size_t length;
29331da177e4SLinus Torvalds 		int i;
29341da177e4SLinus Torvalds 
29351da177e4SLinus Torvalds 		if (newlen % sizeof(int) != 0)
29361da177e4SLinus Torvalds 			return -EINVAL;
29371da177e4SLinus Torvalds 
29381da177e4SLinus Torvalds 		if (!table->extra1 && !table->extra2)
29391da177e4SLinus Torvalds 			return 0;
29401da177e4SLinus Torvalds 
29411da177e4SLinus Torvalds 		if (newlen > table->maxlen)
29421da177e4SLinus Torvalds 			newlen = table->maxlen;
29431da177e4SLinus Torvalds 		length = newlen / sizeof(int);
29441da177e4SLinus Torvalds 
29451da177e4SLinus Torvalds 		for (i = 0; i < length; i++) {
29461da177e4SLinus Torvalds 			int value;
29471da177e4SLinus Torvalds 			if (get_user(value, vec + i))
29481da177e4SLinus Torvalds 				return -EFAULT;
29491da177e4SLinus Torvalds 			if (min && value < min[i])
29501da177e4SLinus Torvalds 				return -EINVAL;
29511da177e4SLinus Torvalds 			if (max && value > max[i])
29521da177e4SLinus Torvalds 				return -EINVAL;
29531da177e4SLinus Torvalds 		}
29541da177e4SLinus Torvalds 	}
29551da177e4SLinus Torvalds 	return 0;
29561da177e4SLinus Torvalds }
29571da177e4SLinus Torvalds 
29581da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
2959f221e726SAlexey Dobriyan int sysctl_jiffies(struct ctl_table *table,
29601da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29611f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29621da177e4SLinus Torvalds {
29633ee75ac3SAlexey Dobriyan 	if (oldval && oldlenp) {
29641da177e4SLinus Torvalds 		size_t olen;
29653ee75ac3SAlexey Dobriyan 
29661da177e4SLinus Torvalds 		if (get_user(olen, oldlenp))
29671da177e4SLinus Torvalds 			return -EFAULT;
29683ee75ac3SAlexey Dobriyan 		if (olen) {
29693ee75ac3SAlexey Dobriyan 			int val;
29703ee75ac3SAlexey Dobriyan 
29713ee75ac3SAlexey Dobriyan 			if (olen < sizeof(int))
29721da177e4SLinus Torvalds 				return -EINVAL;
29733ee75ac3SAlexey Dobriyan 
29743ee75ac3SAlexey Dobriyan 			val = *(int *)(table->data) / HZ;
29753ee75ac3SAlexey Dobriyan 			if (put_user(val, (int __user *)oldval))
29761da177e4SLinus Torvalds 				return -EFAULT;
29773ee75ac3SAlexey Dobriyan 			if (put_user(sizeof(int), oldlenp))
29783ee75ac3SAlexey Dobriyan 				return -EFAULT;
29793ee75ac3SAlexey Dobriyan 		}
29801da177e4SLinus Torvalds 	}
29811da177e4SLinus Torvalds 	if (newval && newlen) {
29821da177e4SLinus Torvalds 		int new;
29831da177e4SLinus Torvalds 		if (newlen != sizeof(int))
29841da177e4SLinus Torvalds 			return -EINVAL;
29851da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
29861da177e4SLinus Torvalds 			return -EFAULT;
29871da177e4SLinus Torvalds 		*(int *)(table->data) = new*HZ;
29881da177e4SLinus Torvalds 	}
29891da177e4SLinus Torvalds 	return 1;
29901da177e4SLinus Torvalds }
29911da177e4SLinus Torvalds 
29921da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */
2993f221e726SAlexey Dobriyan int sysctl_ms_jiffies(struct ctl_table *table,
29941da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
29951f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
29961da177e4SLinus Torvalds {
29973ee75ac3SAlexey Dobriyan 	if (oldval && oldlenp) {
29981da177e4SLinus Torvalds 		size_t olen;
29993ee75ac3SAlexey Dobriyan 
30001da177e4SLinus Torvalds 		if (get_user(olen, oldlenp))
30011da177e4SLinus Torvalds 			return -EFAULT;
30023ee75ac3SAlexey Dobriyan 		if (olen) {
30033ee75ac3SAlexey Dobriyan 			int val;
30043ee75ac3SAlexey Dobriyan 
30053ee75ac3SAlexey Dobriyan 			if (olen < sizeof(int))
30061da177e4SLinus Torvalds 				return -EINVAL;
30073ee75ac3SAlexey Dobriyan 
30083ee75ac3SAlexey Dobriyan 			val = jiffies_to_msecs(*(int *)(table->data));
30093ee75ac3SAlexey Dobriyan 			if (put_user(val, (int __user *)oldval))
30101da177e4SLinus Torvalds 				return -EFAULT;
30113ee75ac3SAlexey Dobriyan 			if (put_user(sizeof(int), oldlenp))
30123ee75ac3SAlexey Dobriyan 				return -EFAULT;
30133ee75ac3SAlexey Dobriyan 		}
30141da177e4SLinus Torvalds 	}
30151da177e4SLinus Torvalds 	if (newval && newlen) {
30161da177e4SLinus Torvalds 		int new;
30171da177e4SLinus Torvalds 		if (newlen != sizeof(int))
30181da177e4SLinus Torvalds 			return -EINVAL;
30191da177e4SLinus Torvalds 		if (get_user(new, (int __user *)newval))
30201da177e4SLinus Torvalds 			return -EFAULT;
30211da177e4SLinus Torvalds 		*(int *)(table->data) = msecs_to_jiffies(new);
30221da177e4SLinus Torvalds 	}
30231da177e4SLinus Torvalds 	return 1;
30241da177e4SLinus Torvalds }
30251da177e4SLinus Torvalds 
3026c4b8b769SEric W. Biederman 
3027c4b8b769SEric W. Biederman 
3028b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */
30291da177e4SLinus Torvalds 
30301da177e4SLinus Torvalds 
30311e7bfb21SHeiko Carstens SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
30321da177e4SLinus Torvalds {
30330e009be8SEric W. Biederman 	struct __sysctl_args tmp;
30347058cb02SEric W. Biederman 	int error;
30350e009be8SEric W. Biederman 
30360e009be8SEric W. Biederman 	if (copy_from_user(&tmp, args, sizeof(tmp)))
30370e009be8SEric W. Biederman 		return -EFAULT;
30380e009be8SEric W. Biederman 
30397058cb02SEric W. Biederman 	error = deprecated_sysctl_warning(&tmp);
3040b89a8171SEric W. Biederman 
30417058cb02SEric W. Biederman 	/* If no error reading the parameters then just -ENOSYS ... */
30427058cb02SEric W. Biederman 	if (!error)
30437058cb02SEric W. Biederman 		error = -ENOSYS;
30447058cb02SEric W. Biederman 
30457058cb02SEric W. Biederman 	return error;
30461da177e4SLinus Torvalds }
30471da177e4SLinus Torvalds 
3048f221e726SAlexey Dobriyan int sysctl_data(struct ctl_table *table,
304949a0c458SEric W. Biederman 		  void __user *oldval, size_t __user *oldlenp,
305049a0c458SEric W. Biederman 		  void __user *newval, size_t newlen)
305149a0c458SEric W. Biederman {
305249a0c458SEric W. Biederman 	return -ENOSYS;
305349a0c458SEric W. Biederman }
305449a0c458SEric W. Biederman 
3055f221e726SAlexey Dobriyan int sysctl_string(struct ctl_table *table,
30561da177e4SLinus Torvalds 		  void __user *oldval, size_t __user *oldlenp,
30571f29bcd7SAlexey Dobriyan 		  void __user *newval, size_t newlen)
30581da177e4SLinus Torvalds {
30591da177e4SLinus Torvalds 	return -ENOSYS;
30601da177e4SLinus Torvalds }
30611da177e4SLinus Torvalds 
3062f221e726SAlexey Dobriyan int sysctl_intvec(struct ctl_table *table,
30631da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
30641f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
30651da177e4SLinus Torvalds {
30661da177e4SLinus Torvalds 	return -ENOSYS;
30671da177e4SLinus Torvalds }
30681da177e4SLinus Torvalds 
3069f221e726SAlexey Dobriyan int sysctl_jiffies(struct ctl_table *table,
30701da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
30711f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
30721da177e4SLinus Torvalds {
30731da177e4SLinus Torvalds 	return -ENOSYS;
30741da177e4SLinus Torvalds }
30751da177e4SLinus Torvalds 
3076f221e726SAlexey Dobriyan int sysctl_ms_jiffies(struct ctl_table *table,
30771da177e4SLinus Torvalds 		void __user *oldval, size_t __user *oldlenp,
30781f29bcd7SAlexey Dobriyan 		void __user *newval, size_t newlen)
30791da177e4SLinus Torvalds {
30801da177e4SLinus Torvalds 	return -ENOSYS;
30811da177e4SLinus Torvalds }
30821da177e4SLinus Torvalds 
3083b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */
30841da177e4SLinus Torvalds 
30857058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args)
30867058cb02SEric W. Biederman {
30877058cb02SEric W. Biederman 	static int msg_count;
30887058cb02SEric W. Biederman 	int name[CTL_MAXNAME];
30897058cb02SEric W. Biederman 	int i;
30907058cb02SEric W. Biederman 
30916fc48af8STetsuo Handa 	/* Check args->nlen. */
30926fc48af8STetsuo Handa 	if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
30936fc48af8STetsuo Handa 		return -ENOTDIR;
30946fc48af8STetsuo Handa 
30957058cb02SEric W. Biederman 	/* Read in the sysctl name for better debug message logging */
30967058cb02SEric W. Biederman 	for (i = 0; i < args->nlen; i++)
30977058cb02SEric W. Biederman 		if (get_user(name[i], args->name + i))
30987058cb02SEric W. Biederman 			return -EFAULT;
30997058cb02SEric W. Biederman 
31007058cb02SEric W. Biederman 	/* Ignore accesses to kernel.version */
31017058cb02SEric W. Biederman 	if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
31027058cb02SEric W. Biederman 		return 0;
31037058cb02SEric W. Biederman 
31047058cb02SEric W. Biederman 	if (msg_count < 5) {
31057058cb02SEric W. Biederman 		msg_count++;
31067058cb02SEric W. Biederman 		printk(KERN_INFO
31077058cb02SEric W. Biederman 			"warning: process `%s' used the deprecated sysctl "
31087058cb02SEric W. Biederman 			"system call with ", current->comm);
31097058cb02SEric W. Biederman 		for (i = 0; i < args->nlen; i++)
31107058cb02SEric W. Biederman 			printk("%d.", name[i]);
31117058cb02SEric W. Biederman 		printk("\n");
31127058cb02SEric W. Biederman 	}
31137058cb02SEric W. Biederman 	return 0;
31147058cb02SEric W. Biederman }
31157058cb02SEric W. Biederman 
31161da177e4SLinus Torvalds /*
31171da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
31181da177e4SLinus Torvalds  * exception granted :-)
31191da177e4SLinus Torvalds  */
31201da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
31211da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
31221da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
31231da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
31241da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
31251da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
31261da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
31271da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
31281da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
312929e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths);
31301da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec);
31311da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies);
31321da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies);
31331da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string);
313449a0c458SEric W. Biederman EXPORT_SYMBOL(sysctl_data);
31351da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
3136