xref: /openbmc/linux/kernel/sysctl.c (revision b492e95be0ae672922f4734acf3f5d35c30be948)
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>
26d33ed52dSDave Young #include <linux/signal.h>
271da177e4SLinus Torvalds #include <linux/proc_fs.h>
2872c2d582SAndrew Morgan #include <linux/security.h>
291da177e4SLinus Torvalds #include <linux/ctype.h>
30dfec072eSVegard Nossum #include <linux/kmemcheck.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>
393fff4c42SIngo Molnar #include <linux/ratelimit.h>
401da177e4SLinus Torvalds #include <linux/hugetlb.h>
411da177e4SLinus Torvalds #include <linux/initrd.h>
420b77f5bfSDavid Howells #include <linux/key.h>
431da177e4SLinus Torvalds #include <linux/times.h>
441da177e4SLinus Torvalds #include <linux/limits.h>
451da177e4SLinus Torvalds #include <linux/dcache.h>
461da177e4SLinus Torvalds #include <linux/syscalls.h>
47c748e134SAdrian Bunk #include <linux/vmstat.h>
48c255d844SPavel Machek #include <linux/nfs_fs.h>
49c255d844SPavel Machek #include <linux/acpi.h>
5010a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h>
51b0fc494fSSteven Rostedt #include <linux/ftrace.h>
5212e22c5eSDavid Howells #include <linux/slow-work.h>
53cdd6c482SIngo Molnar #include <linux/perf_event.h>
54b2be84dfSMasami Hiramatsu #include <linux/kprobes.h>
55*b492e95bSJens Axboe #include <linux/pipe_fs_i.h>
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds #include <asm/uaccess.h>
581da177e4SLinus Torvalds #include <asm/processor.h>
591da177e4SLinus Torvalds 
6029cbc78bSAndi Kleen #ifdef CONFIG_X86
6129cbc78bSAndi Kleen #include <asm/nmi.h>
620741f4d2SChuck Ebbert #include <asm/stacktrace.h>
636e7c4025SIngo Molnar #include <asm/io.h>
6429cbc78bSAndi Kleen #endif
65c55b7c3eSDave Young #ifdef CONFIG_BSD_PROCESS_ACCT
66c55b7c3eSDave Young #include <linux/acct.h>
67c55b7c3eSDave Young #endif
684f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES
694f0e056fSDave Young #include <linux/rtmutex.h>
704f0e056fSDave Young #endif
712edf5e49SDave Young #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
722edf5e49SDave Young #include <linux/lockdep.h>
732edf5e49SDave Young #endif
7415485a46SDave Young #ifdef CONFIG_CHR_DEV_SG
7515485a46SDave Young #include <scsi/sg.h>
7615485a46SDave Young #endif
7729cbc78bSAndi Kleen 
787058cb02SEric W. Biederman 
791da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds /* External variables not in a header file. */
821da177e4SLinus Torvalds extern int sysctl_overcommit_memory;
831da177e4SLinus Torvalds extern int sysctl_overcommit_ratio;
84fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom;
85fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task;
86fef1bdd6SDavid Rientjes extern int sysctl_oom_dump_tasks;
871da177e4SLinus Torvalds extern int max_threads;
881da177e4SLinus Torvalds extern int core_uses_pid;
89d6e71144SAlan Cox extern int suid_dumpable;
901da177e4SLinus Torvalds extern char core_pattern[];
91a293980cSNeil Horman extern unsigned int core_pipe_limit;
921da177e4SLinus Torvalds extern int pid_max;
931da177e4SLinus Torvalds extern int min_free_kbytes;
941da177e4SLinus Torvalds extern int pid_max_min, pid_max_max;
959d0243bcSAndrew Morton extern int sysctl_drop_caches;
968ad4b1fbSRohit Seth extern int percpu_pagelist_fraction;
97bebfa101SAndi Kleen extern int compat_log;
989745512cSArjan van de Ven extern int latencytop_enabled;
99eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max;
100dd8632a1SPaul Mundt #ifndef CONFIG_MMU
101dd8632a1SPaul Mundt extern int sysctl_nr_trim_pages;
102dd8632a1SPaul Mundt #endif
103cb684b5bSJens Axboe #ifdef CONFIG_BLOCK
1045e605b64SJens Axboe extern int blk_iopoll_enabled;
105cb684b5bSJens Axboe #endif
1061da177e4SLinus Torvalds 
107c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
108195cf453SBron Gondwana #ifdef CONFIG_DETECT_SOFTLOCKUP
109c4f3b63fSRavikiran G Thirumalai static int sixty = 60;
1109383d967SDimitri Sivanich static int neg_one = -1;
111c4f3b63fSRavikiran G Thirumalai #endif
112c4f3b63fSRavikiran G Thirumalai 
113c4f3b63fSRavikiran G Thirumalai static int zero;
114cd5f9a4cSLinus Torvalds static int __maybe_unused one = 1;
115cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2;
116fc3501d4SSven Wegener static unsigned long one_ul = 1;
117c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100;
118af91322eSDave Young #ifdef CONFIG_PRINTK
119af91322eSDave Young static int ten_thousand = 10000;
120af91322eSDave Young #endif
121c4f3b63fSRavikiran G Thirumalai 
1229e4a5bdaSAndrea Righi /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
1239e4a5bdaSAndrea Righi static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
1249e4a5bdaSAndrea Righi 
1251da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
1261da177e4SLinus Torvalds static int maxolduid = 65535;
1271da177e4SLinus Torvalds static int minolduid;
1288ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8;
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
1311da177e4SLinus Torvalds 
13272c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
13317f04fbbSDavid S. Miller #include <asm/system.h>
1341da177e4SLinus Torvalds #endif
1351da177e4SLinus Torvalds 
1360871420fSDavid S. Miller #ifdef CONFIG_SPARC64
1370871420fSDavid S. Miller extern int sysctl_tsb_ratio;
1380871420fSDavid S. Miller #endif
1390871420fSDavid S. Miller 
1401da177e4SLinus Torvalds #ifdef __hppa__
1411da177e4SLinus Torvalds extern int pwrsw_enabled;
1421da177e4SLinus Torvalds extern int unaligned_enabled;
1431da177e4SLinus Torvalds #endif
1441da177e4SLinus Torvalds 
145347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
1461da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
1471da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings;
1481da177e4SLinus Torvalds #endif
1491da177e4SLinus Torvalds extern int sysctl_userprocess_debug;
150951f22d5SMartin Schwidefsky extern int spin_retry;
1511da177e4SLinus Torvalds #endif
1521da177e4SLinus Torvalds 
153d2b176edSJes Sorensen #ifdef CONFIG_IA64
154d2b176edSJes Sorensen extern int no_unaligned_warning;
15588fc241fSDoug Chapman extern int unaligned_dump_stack;
156d2b176edSJes Sorensen #endif
157d2b176edSJes Sorensen 
1583fff4c42SIngo Molnar extern struct ratelimit_state printk_ratelimit_state;
1593fff4c42SIngo Molnar 
160d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
1618d65af78SAlexey Dobriyan static int proc_do_cad_pid(struct ctl_table *table, int write,
1629ec52099SCedric Le Goater 		  void __user *buffer, size_t *lenp, loff_t *ppos);
1638d65af78SAlexey Dobriyan static int proc_taint(struct ctl_table *table, int write,
16434f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos);
165d6f8ff73SRandy Dunlap #endif
1669ec52099SCedric Le Goater 
167d8217f07SEric W. Biederman static struct ctl_table root_table[];
168e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root;
169e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = {
170b380b0d4SAl Viro 	.count = 1,
171e51b6ba0SEric W. Biederman 	.ctl_table = root_table,
17273455092SAl Viro 	.ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
173e51b6ba0SEric W. Biederman 	.root = &sysctl_table_root,
17473455092SAl Viro 	.set = &sysctl_table_root.default_set,
175e51b6ba0SEric W. Biederman };
176e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = {
177e51b6ba0SEric W. Biederman 	.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
17873455092SAl Viro 	.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
179e51b6ba0SEric W. Biederman };
1801da177e4SLinus Torvalds 
181d8217f07SEric W. Biederman static struct ctl_table kern_table[];
182d8217f07SEric W. Biederman static struct ctl_table vm_table[];
183d8217f07SEric W. Biederman static struct ctl_table fs_table[];
184d8217f07SEric W. Biederman static struct ctl_table debug_table[];
185d8217f07SEric W. Biederman static struct ctl_table dev_table[];
186d8217f07SEric W. Biederman extern struct ctl_table random_table[];
1872d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
188d8217f07SEric W. Biederman extern struct ctl_table inotify_table[];
1890399cb08SRobert Love #endif
1907ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
1917ef9964eSDavide Libenzi extern struct ctl_table epoll_table[];
1927ef9964eSDavide Libenzi #endif
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1951da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1961da177e4SLinus Torvalds #endif
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds /* The default sysctl tables: */
1991da177e4SLinus Torvalds 
200d8217f07SEric W. Biederman static struct ctl_table root_table[] = {
2011da177e4SLinus Torvalds 	{
2021da177e4SLinus Torvalds 		.procname	= "kernel",
2031da177e4SLinus Torvalds 		.mode		= 0555,
2041da177e4SLinus Torvalds 		.child		= kern_table,
2051da177e4SLinus Torvalds 	},
2061da177e4SLinus Torvalds 	{
2071da177e4SLinus Torvalds 		.procname	= "vm",
2081da177e4SLinus Torvalds 		.mode		= 0555,
2091da177e4SLinus Torvalds 		.child		= vm_table,
2101da177e4SLinus Torvalds 	},
2111da177e4SLinus Torvalds 	{
2121da177e4SLinus Torvalds 		.procname	= "fs",
2131da177e4SLinus Torvalds 		.mode		= 0555,
2141da177e4SLinus Torvalds 		.child		= fs_table,
2151da177e4SLinus Torvalds 	},
2161da177e4SLinus Torvalds 	{
2171da177e4SLinus Torvalds 		.procname	= "debug",
2181da177e4SLinus Torvalds 		.mode		= 0555,
2191da177e4SLinus Torvalds 		.child		= debug_table,
2201da177e4SLinus Torvalds 	},
2211da177e4SLinus Torvalds 	{
2221da177e4SLinus Torvalds 		.procname	= "dev",
2231da177e4SLinus Torvalds 		.mode		= 0555,
2241da177e4SLinus Torvalds 		.child		= dev_table,
2251da177e4SLinus Torvalds 	},
2262be7fe07SAndrew Morton /*
2272be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
2282be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
2292be7fe07SAndrew Morton  */
2306fce56ecSEric W. Biederman 	{ }
2311da177e4SLinus Torvalds };
2321da177e4SLinus Torvalds 
23377e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
23473c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000;		/* 100 usecs */
23573c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
23673c4efd2SEric Dumazet static int min_wakeup_granularity_ns;			/* 0 usecs */
23773c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
2381983a922SChristian Ehrhardt static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
2391983a922SChristian Ehrhardt static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
240acb4a848SChristian Ehrhardt static int min_sched_shares_ratelimit = 100000; /* 100 usec */
241acb4a848SChristian Ehrhardt static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
24277e54a1fSIngo Molnar #endif
24377e54a1fSIngo Molnar 
244d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
2452bba22c5SMike Galbraith 	{
2462bba22c5SMike Galbraith 		.procname	= "sched_child_runs_first",
2472bba22c5SMike Galbraith 		.data		= &sysctl_sched_child_runs_first,
2482bba22c5SMike Galbraith 		.maxlen		= sizeof(unsigned int),
2492bba22c5SMike Galbraith 		.mode		= 0644,
2506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2512bba22c5SMike Galbraith 	},
25277e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
25377e54a1fSIngo Molnar 	{
254b2be5e96SPeter Zijlstra 		.procname	= "sched_min_granularity_ns",
255b2be5e96SPeter Zijlstra 		.data		= &sysctl_sched_min_granularity,
25677e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
25777e54a1fSIngo Molnar 		.mode		= 0644,
258702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
259b2be5e96SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
260b2be5e96SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
26177e54a1fSIngo Molnar 	},
26277e54a1fSIngo Molnar 	{
26321805085SPeter Zijlstra 		.procname	= "sched_latency_ns",
26421805085SPeter Zijlstra 		.data		= &sysctl_sched_latency,
26521805085SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
26621805085SPeter Zijlstra 		.mode		= 0644,
267702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
26821805085SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
26921805085SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
27021805085SPeter Zijlstra 	},
27121805085SPeter Zijlstra 	{
27277e54a1fSIngo Molnar 		.procname	= "sched_wakeup_granularity_ns",
27377e54a1fSIngo Molnar 		.data		= &sysctl_sched_wakeup_granularity,
27477e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
27577e54a1fSIngo Molnar 		.mode		= 0644,
276702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
27777e54a1fSIngo Molnar 		.extra1		= &min_wakeup_granularity_ns,
27877e54a1fSIngo Molnar 		.extra2		= &max_wakeup_granularity_ns,
27977e54a1fSIngo Molnar 	},
28077e54a1fSIngo Molnar 	{
2812398f2c6SPeter Zijlstra 		.procname	= "sched_shares_ratelimit",
2822398f2c6SPeter Zijlstra 		.data		= &sysctl_sched_shares_ratelimit,
2832398f2c6SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
2842398f2c6SPeter Zijlstra 		.mode		= 0644,
285702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
286acb4a848SChristian Ehrhardt 		.extra1		= &min_sched_shares_ratelimit,
287acb4a848SChristian Ehrhardt 		.extra2		= &max_sched_shares_ratelimit,
2882398f2c6SPeter Zijlstra 	},
2892398f2c6SPeter Zijlstra 	{
2901983a922SChristian Ehrhardt 		.procname	= "sched_tunable_scaling",
2911983a922SChristian Ehrhardt 		.data		= &sysctl_sched_tunable_scaling,
2921983a922SChristian Ehrhardt 		.maxlen		= sizeof(enum sched_tunable_scaling),
2931983a922SChristian Ehrhardt 		.mode		= 0644,
294702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
2951983a922SChristian Ehrhardt 		.extra1		= &min_sched_tunable_scaling,
2961983a922SChristian Ehrhardt 		.extra2		= &max_sched_tunable_scaling,
2972398f2c6SPeter Zijlstra 	},
2982398f2c6SPeter Zijlstra 	{
299ffda12a1SPeter Zijlstra 		.procname	= "sched_shares_thresh",
300ffda12a1SPeter Zijlstra 		.data		= &sysctl_sched_shares_thresh,
301ffda12a1SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
302ffda12a1SPeter Zijlstra 		.mode		= 0644,
3036d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
304ffda12a1SPeter Zijlstra 		.extra1		= &zero,
305ffda12a1SPeter Zijlstra 	},
306ffda12a1SPeter Zijlstra 	{
307da84d961SIngo Molnar 		.procname	= "sched_migration_cost",
308da84d961SIngo Molnar 		.data		= &sysctl_sched_migration_cost,
309da84d961SIngo Molnar 		.maxlen		= sizeof(unsigned int),
310da84d961SIngo Molnar 		.mode		= 0644,
3116d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
312da84d961SIngo Molnar 	},
313b82d9fddSPeter Zijlstra 	{
314b82d9fddSPeter Zijlstra 		.procname	= "sched_nr_migrate",
315b82d9fddSPeter Zijlstra 		.data		= &sysctl_sched_nr_migrate,
316b82d9fddSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
317fa85ae24SPeter Zijlstra 		.mode		= 0644,
3186d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
319fa85ae24SPeter Zijlstra 	},
320cd1bb94bSArun R Bharadwaj 	{
321e9e9250bSPeter Zijlstra 		.procname	= "sched_time_avg",
322e9e9250bSPeter Zijlstra 		.data		= &sysctl_sched_time_avg,
323e9e9250bSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
324e9e9250bSPeter Zijlstra 		.mode		= 0644,
3256d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
326e9e9250bSPeter Zijlstra 	},
327e9e9250bSPeter Zijlstra 	{
328cd1bb94bSArun R Bharadwaj 		.procname	= "timer_migration",
329cd1bb94bSArun R Bharadwaj 		.data		= &sysctl_timer_migration,
330cd1bb94bSArun R Bharadwaj 		.maxlen		= sizeof(unsigned int),
331cd1bb94bSArun R Bharadwaj 		.mode		= 0644,
3326d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
333bfdb4d9fSArun R Bharadwaj 		.extra1		= &zero,
334bfdb4d9fSArun R Bharadwaj 		.extra2		= &one,
335cd1bb94bSArun R Bharadwaj 	},
3361fc84aaaSPeter Zijlstra #endif
3371799e35dSIngo Molnar 	{
3389f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
3399f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
3409f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
3419f0c1e56SPeter Zijlstra 		.mode		= 0644,
3426d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
3439f0c1e56SPeter Zijlstra 	},
3449f0c1e56SPeter Zijlstra 	{
3459f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
3469f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
3479f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
3489f0c1e56SPeter Zijlstra 		.mode		= 0644,
3496d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
3509f0c1e56SPeter Zijlstra 	},
3519f0c1e56SPeter Zijlstra 	{
3521799e35dSIngo Molnar 		.procname	= "sched_compat_yield",
3531799e35dSIngo Molnar 		.data		= &sysctl_sched_compat_yield,
3541799e35dSIngo Molnar 		.maxlen		= sizeof(unsigned int),
3551799e35dSIngo Molnar 		.mode		= 0644,
3566d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
3571799e35dSIngo Molnar 	},
358f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
359f20786ffSPeter Zijlstra 	{
360f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
361f20786ffSPeter Zijlstra 		.data		= &prove_locking,
362f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
363f20786ffSPeter Zijlstra 		.mode		= 0644,
3646d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
365f20786ffSPeter Zijlstra 	},
366f20786ffSPeter Zijlstra #endif
367f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
368f20786ffSPeter Zijlstra 	{
369f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
370f20786ffSPeter Zijlstra 		.data		= &lock_stat,
371f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
372f20786ffSPeter Zijlstra 		.mode		= 0644,
3736d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
374f20786ffSPeter Zijlstra 	},
375f20786ffSPeter Zijlstra #endif
37677e54a1fSIngo Molnar 	{
3771da177e4SLinus Torvalds 		.procname	= "panic",
3781da177e4SLinus Torvalds 		.data		= &panic_timeout,
3791da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3801da177e4SLinus Torvalds 		.mode		= 0644,
3816d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
3821da177e4SLinus Torvalds 	},
3831da177e4SLinus Torvalds 	{
3841da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
3851da177e4SLinus Torvalds 		.data		= &core_uses_pid,
3861da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
3871da177e4SLinus Torvalds 		.mode		= 0644,
3886d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
3891da177e4SLinus Torvalds 	},
3901da177e4SLinus Torvalds 	{
3911da177e4SLinus Torvalds 		.procname	= "core_pattern",
3921da177e4SLinus Torvalds 		.data		= core_pattern,
39371ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
3941da177e4SLinus Torvalds 		.mode		= 0644,
3956d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
3961da177e4SLinus Torvalds 	},
397a293980cSNeil Horman 	{
398a293980cSNeil Horman 		.procname	= "core_pipe_limit",
399a293980cSNeil Horman 		.data		= &core_pipe_limit,
400a293980cSNeil Horman 		.maxlen		= sizeof(unsigned int),
401a293980cSNeil Horman 		.mode		= 0644,
4026d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
403a293980cSNeil Horman 	},
40434f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
4051da177e4SLinus Torvalds 	{
4061da177e4SLinus Torvalds 		.procname	= "tainted",
40725ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
40834f5a398STheodore Ts'o 		.mode		= 0644,
4096d456111SEric W. Biederman 		.proc_handler	= proc_taint,
4101da177e4SLinus Torvalds 	},
41134f5a398STheodore Ts'o #endif
4129745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
4139745512cSArjan van de Ven 	{
4149745512cSArjan van de Ven 		.procname	= "latencytop",
4159745512cSArjan van de Ven 		.data		= &latencytop_enabled,
4169745512cSArjan van de Ven 		.maxlen		= sizeof(int),
4179745512cSArjan van de Ven 		.mode		= 0644,
4186d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4199745512cSArjan van de Ven 	},
4209745512cSArjan van de Ven #endif
4211da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
4221da177e4SLinus Torvalds 	{
4231da177e4SLinus Torvalds 		.procname	= "real-root-dev",
4241da177e4SLinus Torvalds 		.data		= &real_root_dev,
4251da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4261da177e4SLinus Torvalds 		.mode		= 0644,
4276d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4281da177e4SLinus Torvalds 	},
4291da177e4SLinus Torvalds #endif
43045807a1dSIngo Molnar 	{
43145807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
43245807a1dSIngo Molnar 		.data		= &print_fatal_signals,
43345807a1dSIngo Molnar 		.maxlen		= sizeof(int),
43445807a1dSIngo Molnar 		.mode		= 0644,
4356d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
43645807a1dSIngo Molnar 	},
43772c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
4381da177e4SLinus Torvalds 	{
4391da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
4401da177e4SLinus Torvalds 		.data		= reboot_command,
4411da177e4SLinus Torvalds 		.maxlen		= 256,
4421da177e4SLinus Torvalds 		.mode		= 0644,
4436d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
4441da177e4SLinus Torvalds 	},
4451da177e4SLinus Torvalds 	{
4461da177e4SLinus Torvalds 		.procname	= "stop-a",
4471da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
4481da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4491da177e4SLinus Torvalds 		.mode		= 0644,
4506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4511da177e4SLinus Torvalds 	},
4521da177e4SLinus Torvalds 	{
4531da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
4541da177e4SLinus Torvalds 		.data		= &scons_pwroff,
4551da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4561da177e4SLinus Torvalds 		.mode		= 0644,
4576d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4581da177e4SLinus Torvalds 	},
4591da177e4SLinus Torvalds #endif
4600871420fSDavid S. Miller #ifdef CONFIG_SPARC64
4610871420fSDavid S. Miller 	{
4620871420fSDavid S. Miller 		.procname	= "tsb-ratio",
4630871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
4640871420fSDavid S. Miller 		.maxlen		= sizeof (int),
4650871420fSDavid S. Miller 		.mode		= 0644,
4666d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4670871420fSDavid S. Miller 	},
4680871420fSDavid S. Miller #endif
4691da177e4SLinus Torvalds #ifdef __hppa__
4701da177e4SLinus Torvalds 	{
4711da177e4SLinus Torvalds 		.procname	= "soft-power",
4721da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
4731da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4741da177e4SLinus Torvalds 	 	.mode		= 0644,
4756d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4761da177e4SLinus Torvalds 	},
4771da177e4SLinus Torvalds 	{
4781da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
4791da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
4801da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
4811da177e4SLinus Torvalds 		.mode		= 0644,
4826d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4831da177e4SLinus Torvalds 	},
4841da177e4SLinus Torvalds #endif
4851da177e4SLinus Torvalds 	{
4861da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
4871da177e4SLinus Torvalds 		.data		= &C_A_D,
4881da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
4891da177e4SLinus Torvalds 		.mode		= 0644,
4906d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
4911da177e4SLinus Torvalds 	},
492606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER
493b0fc494fSSteven Rostedt 	{
494b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
495b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
496b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
497b0fc494fSSteven Rostedt 		.mode		= 0644,
4986d456111SEric W. Biederman 		.proc_handler	= ftrace_enable_sysctl,
499b0fc494fSSteven Rostedt 	},
500b0fc494fSSteven Rostedt #endif
501f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
502f38f1d2aSSteven Rostedt 	{
503f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
504f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
505f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
506f38f1d2aSSteven Rostedt 		.mode		= 0644,
5076d456111SEric W. Biederman 		.proc_handler	= stack_trace_sysctl,
508f38f1d2aSSteven Rostedt 	},
509f38f1d2aSSteven Rostedt #endif
510944ac425SSteven Rostedt #ifdef CONFIG_TRACING
511944ac425SSteven Rostedt 	{
5123299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
513944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
514944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
515944ac425SSteven Rostedt 		.mode		= 0644,
5166d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
517944ac425SSteven Rostedt 	},
518944ac425SSteven Rostedt #endif
519a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
5201da177e4SLinus Torvalds 	{
5211da177e4SLinus Torvalds 		.procname	= "modprobe",
5221da177e4SLinus Torvalds 		.data		= &modprobe_path,
5231da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
5241da177e4SLinus Torvalds 		.mode		= 0644,
5256d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
5261da177e4SLinus Torvalds 	},
5273d43321bSKees Cook 	{
5283d43321bSKees Cook 		.procname	= "modules_disabled",
5293d43321bSKees Cook 		.data		= &modules_disabled,
5303d43321bSKees Cook 		.maxlen		= sizeof(int),
5313d43321bSKees Cook 		.mode		= 0644,
5323d43321bSKees Cook 		/* only handle a transition from default "0" to "1" */
5336d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
5343d43321bSKees Cook 		.extra1		= &one,
5353d43321bSKees Cook 		.extra2		= &one,
5363d43321bSKees Cook 	},
5371da177e4SLinus Torvalds #endif
53857ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
5391da177e4SLinus Torvalds 	{
5401da177e4SLinus Torvalds 		.procname	= "hotplug",
541312c004dSKay Sievers 		.data		= &uevent_helper,
542312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
5431da177e4SLinus Torvalds 		.mode		= 0644,
5446d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
5451da177e4SLinus Torvalds 	},
5461da177e4SLinus Torvalds #endif
5471da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
5481da177e4SLinus Torvalds 	{
5491da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
5501da177e4SLinus Torvalds 		.data		= &sg_big_buff,
5511da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5521da177e4SLinus Torvalds 		.mode		= 0444,
5536d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
5541da177e4SLinus Torvalds 	},
5551da177e4SLinus Torvalds #endif
5561da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
5571da177e4SLinus Torvalds 	{
5581da177e4SLinus Torvalds 		.procname	= "acct",
5591da177e4SLinus Torvalds 		.data		= &acct_parm,
5601da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
5611da177e4SLinus Torvalds 		.mode		= 0644,
5626d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
5631da177e4SLinus Torvalds 	},
5641da177e4SLinus Torvalds #endif
5651da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
5661da177e4SLinus Torvalds 	{
5671da177e4SLinus Torvalds 		.procname	= "sysrq",
5685d6f647fSIngo Molnar 		.data		= &__sysrq_enabled,
5691da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5701da177e4SLinus Torvalds 		.mode		= 0644,
5716d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
5721da177e4SLinus Torvalds 	},
5731da177e4SLinus Torvalds #endif
574d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
5751da177e4SLinus Torvalds 	{
5761da177e4SLinus Torvalds 		.procname	= "cad_pid",
5779ec52099SCedric Le Goater 		.data		= NULL,
5781da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
5791da177e4SLinus Torvalds 		.mode		= 0600,
5806d456111SEric W. Biederman 		.proc_handler	= proc_do_cad_pid,
5811da177e4SLinus Torvalds 	},
582d6f8ff73SRandy Dunlap #endif
5831da177e4SLinus Torvalds 	{
5841da177e4SLinus Torvalds 		.procname	= "threads-max",
5851da177e4SLinus Torvalds 		.data		= &max_threads,
5861da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5871da177e4SLinus Torvalds 		.mode		= 0644,
5886d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
5891da177e4SLinus Torvalds 	},
5901da177e4SLinus Torvalds 	{
5911da177e4SLinus Torvalds 		.procname	= "random",
5921da177e4SLinus Torvalds 		.mode		= 0555,
5931da177e4SLinus Torvalds 		.child		= random_table,
5941da177e4SLinus Torvalds 	},
5951da177e4SLinus Torvalds 	{
5961da177e4SLinus Torvalds 		.procname	= "overflowuid",
5971da177e4SLinus Torvalds 		.data		= &overflowuid,
5981da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
5991da177e4SLinus Torvalds 		.mode		= 0644,
6006d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
6011da177e4SLinus Torvalds 		.extra1		= &minolduid,
6021da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6031da177e4SLinus Torvalds 	},
6041da177e4SLinus Torvalds 	{
6051da177e4SLinus Torvalds 		.procname	= "overflowgid",
6061da177e4SLinus Torvalds 		.data		= &overflowgid,
6071da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6081da177e4SLinus Torvalds 		.mode		= 0644,
6096d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
6101da177e4SLinus Torvalds 		.extra1		= &minolduid,
6111da177e4SLinus Torvalds 		.extra2		= &maxolduid,
6121da177e4SLinus Torvalds 	},
613347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
6141da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU
6151da177e4SLinus Torvalds 	{
6161da177e4SLinus Torvalds 		.procname	= "ieee_emulation_warnings",
6171da177e4SLinus Torvalds 		.data		= &sysctl_ieee_emulation_warnings,
6181da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6191da177e4SLinus Torvalds 		.mode		= 0644,
6206d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
6211da177e4SLinus Torvalds 	},
6221da177e4SLinus Torvalds #endif
6231da177e4SLinus Torvalds 	{
6241da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
6251da177e4SLinus Torvalds 		.data		= &sysctl_userprocess_debug,
6261da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6271da177e4SLinus Torvalds 		.mode		= 0644,
6286d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
6291da177e4SLinus Torvalds 	},
6301da177e4SLinus Torvalds #endif
6311da177e4SLinus Torvalds 	{
6321da177e4SLinus Torvalds 		.procname	= "pid_max",
6331da177e4SLinus Torvalds 		.data		= &pid_max,
6341da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6351da177e4SLinus Torvalds 		.mode		= 0644,
6366d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
6371da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
6381da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
6391da177e4SLinus Torvalds 	},
6401da177e4SLinus Torvalds 	{
6411da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
6421da177e4SLinus Torvalds 		.data		= &panic_on_oops,
6431da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6441da177e4SLinus Torvalds 		.mode		= 0644,
6456d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
6461da177e4SLinus Torvalds 	},
6477ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
6487ef3d2fdSJoe Perches 	{
6497ef3d2fdSJoe Perches 		.procname	= "printk",
6507ef3d2fdSJoe Perches 		.data		= &console_loglevel,
6517ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
6527ef3d2fdSJoe Perches 		.mode		= 0644,
6536d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
6547ef3d2fdSJoe Perches 	},
6551da177e4SLinus Torvalds 	{
6561da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
657717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
6581da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6591da177e4SLinus Torvalds 		.mode		= 0644,
6606d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
6611da177e4SLinus Torvalds 	},
6621da177e4SLinus Torvalds 	{
6631da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
664717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
6651da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
6661da177e4SLinus Torvalds 		.mode		= 0644,
6676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
6681da177e4SLinus Torvalds 	},
669af91322eSDave Young 	{
670af91322eSDave Young 		.procname	= "printk_delay",
671af91322eSDave Young 		.data		= &printk_delay_msec,
672af91322eSDave Young 		.maxlen		= sizeof(int),
673af91322eSDave Young 		.mode		= 0644,
6746d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
675af91322eSDave Young 		.extra1		= &zero,
676af91322eSDave Young 		.extra2		= &ten_thousand,
677af91322eSDave Young 	},
6787ef3d2fdSJoe Perches #endif
6791da177e4SLinus Torvalds 	{
6801da177e4SLinus Torvalds 		.procname	= "ngroups_max",
6811da177e4SLinus Torvalds 		.data		= &ngroups_max,
6821da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
6831da177e4SLinus Torvalds 		.mode		= 0444,
6846d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
6851da177e4SLinus Torvalds 	},
6861da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
6871da177e4SLinus Torvalds 	{
6881da177e4SLinus Torvalds 		.procname       = "unknown_nmi_panic",
6891da177e4SLinus Torvalds 		.data           = &unknown_nmi_panic,
6901da177e4SLinus Torvalds 		.maxlen         = sizeof (int),
6911da177e4SLinus Torvalds 		.mode           = 0644,
6926d456111SEric W. Biederman 		.proc_handler   = proc_dointvec,
6931da177e4SLinus Torvalds 	},
694407984f1SDon Zickus 	{
695407984f1SDon Zickus 		.procname       = "nmi_watchdog",
696407984f1SDon Zickus 		.data           = &nmi_watchdog_enabled,
697407984f1SDon Zickus 		.maxlen         = sizeof (int),
698407984f1SDon Zickus 		.mode           = 0644,
6996d456111SEric W. Biederman 		.proc_handler   = proc_nmi_enabled,
7001da177e4SLinus Torvalds 	},
7011da177e4SLinus Torvalds #endif
7021da177e4SLinus Torvalds #if defined(CONFIG_X86)
7031da177e4SLinus Torvalds 	{
7048da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
7058da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
7068da5addaSDon Zickus 		.maxlen		= sizeof(int),
7078da5addaSDon Zickus 		.mode		= 0644,
7086d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7098da5addaSDon Zickus 	},
7108da5addaSDon Zickus 	{
7115211a242SKurt Garloff 		.procname	= "panic_on_io_nmi",
7125211a242SKurt Garloff 		.data		= &panic_on_io_nmi,
7135211a242SKurt Garloff 		.maxlen		= sizeof(int),
7145211a242SKurt Garloff 		.mode		= 0644,
7156d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7165211a242SKurt Garloff 	},
7175211a242SKurt Garloff 	{
7181da177e4SLinus Torvalds 		.procname	= "bootloader_type",
7191da177e4SLinus Torvalds 		.data		= &bootloader_type,
7201da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
7211da177e4SLinus Torvalds 		.mode		= 0444,
7226d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7231da177e4SLinus Torvalds 	},
7240741f4d2SChuck Ebbert 	{
7255031296cSH. Peter Anvin 		.procname	= "bootloader_version",
7265031296cSH. Peter Anvin 		.data		= &bootloader_version,
7275031296cSH. Peter Anvin 		.maxlen		= sizeof (int),
7285031296cSH. Peter Anvin 		.mode		= 0444,
7296d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7305031296cSH. Peter Anvin 	},
7315031296cSH. Peter Anvin 	{
7320741f4d2SChuck Ebbert 		.procname	= "kstack_depth_to_print",
7330741f4d2SChuck Ebbert 		.data		= &kstack_depth_to_print,
7340741f4d2SChuck Ebbert 		.maxlen		= sizeof(int),
7350741f4d2SChuck Ebbert 		.mode		= 0644,
7366d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7370741f4d2SChuck Ebbert 	},
7386e7c4025SIngo Molnar 	{
7396e7c4025SIngo Molnar 		.procname	= "io_delay_type",
7406e7c4025SIngo Molnar 		.data		= &io_delay_type,
7416e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
7426e7c4025SIngo Molnar 		.mode		= 0644,
7436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7446e7c4025SIngo Molnar 	},
7451da177e4SLinus Torvalds #endif
7467a9166e3SLuke Yang #if defined(CONFIG_MMU)
7471da177e4SLinus Torvalds 	{
7481da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
7491da177e4SLinus Torvalds 		.data		= &randomize_va_space,
7501da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
7511da177e4SLinus Torvalds 		.mode		= 0644,
7526d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
7531da177e4SLinus Torvalds 	},
7547a9166e3SLuke Yang #endif
7550152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
756951f22d5SMartin Schwidefsky 	{
757951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
758951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
759951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
760951f22d5SMartin Schwidefsky 		.mode		= 0644,
7616d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
762951f22d5SMartin Schwidefsky 	},
763951f22d5SMartin Schwidefsky #endif
764673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
765c255d844SPavel Machek 	{
766c255d844SPavel Machek 		.procname	= "acpi_video_flags",
76777afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
768c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
769c255d844SPavel Machek 		.mode		= 0644,
7706d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
771c255d844SPavel Machek 	},
772c255d844SPavel Machek #endif
773d2b176edSJes Sorensen #ifdef CONFIG_IA64
774d2b176edSJes Sorensen 	{
775d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
776d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
777d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
778d2b176edSJes Sorensen 	 	.mode		= 0644,
7796d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
780d2b176edSJes Sorensen 	},
78188fc241fSDoug Chapman 	{
78288fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
78388fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
78488fc241fSDoug Chapman 		.maxlen		= sizeof (int),
78588fc241fSDoug Chapman 		.mode		= 0644,
7866d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
78788fc241fSDoug Chapman 	},
788d2b176edSJes Sorensen #endif
789c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP
790c4f3b63fSRavikiran G Thirumalai 	{
7919c44bc03SIngo Molnar 		.procname	= "softlockup_panic",
7929c44bc03SIngo Molnar 		.data		= &softlockup_panic,
7939c44bc03SIngo Molnar 		.maxlen		= sizeof(int),
7949c44bc03SIngo Molnar 		.mode		= 0644,
7956d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
7969c44bc03SIngo Molnar 		.extra1		= &zero,
7979c44bc03SIngo Molnar 		.extra2		= &one,
7989c44bc03SIngo Molnar 	},
7999c44bc03SIngo Molnar 	{
800c4f3b63fSRavikiran G Thirumalai 		.procname	= "softlockup_thresh",
801c4f3b63fSRavikiran G Thirumalai 		.data		= &softlockup_thresh,
8029383d967SDimitri Sivanich 		.maxlen		= sizeof(int),
803c4f3b63fSRavikiran G Thirumalai 		.mode		= 0644,
8046d456111SEric W. Biederman 		.proc_handler	= proc_dosoftlockup_thresh,
8059383d967SDimitri Sivanich 		.extra1		= &neg_one,
806c4f3b63fSRavikiran G Thirumalai 		.extra2		= &sixty,
807c4f3b63fSRavikiran G Thirumalai 	},
808e162b39aSMandeep Singh Baines #endif
809e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
810e162b39aSMandeep Singh Baines 	{
811e162b39aSMandeep Singh Baines 		.procname	= "hung_task_panic",
812e162b39aSMandeep Singh Baines 		.data		= &sysctl_hung_task_panic,
813e162b39aSMandeep Singh Baines 		.maxlen		= sizeof(int),
814e162b39aSMandeep Singh Baines 		.mode		= 0644,
8156d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
816e162b39aSMandeep Singh Baines 		.extra1		= &zero,
817e162b39aSMandeep Singh Baines 		.extra2		= &one,
818e162b39aSMandeep Singh Baines 	},
81982a1fcb9SIngo Molnar 	{
82082a1fcb9SIngo Molnar 		.procname	= "hung_task_check_count",
82182a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_check_count,
82290739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
82382a1fcb9SIngo Molnar 		.mode		= 0644,
8246d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
82582a1fcb9SIngo Molnar 	},
82682a1fcb9SIngo Molnar 	{
82782a1fcb9SIngo Molnar 		.procname	= "hung_task_timeout_secs",
82882a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_timeout_secs,
82990739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
83082a1fcb9SIngo Molnar 		.mode		= 0644,
8316d456111SEric W. Biederman 		.proc_handler	= proc_dohung_task_timeout_secs,
83282a1fcb9SIngo Molnar 	},
83382a1fcb9SIngo Molnar 	{
83482a1fcb9SIngo Molnar 		.procname	= "hung_task_warnings",
83582a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_warnings,
83690739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
83782a1fcb9SIngo Molnar 		.mode		= 0644,
8386d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
83982a1fcb9SIngo Molnar 	},
840c4f3b63fSRavikiran G Thirumalai #endif
841bebfa101SAndi Kleen #ifdef CONFIG_COMPAT
842bebfa101SAndi Kleen 	{
843bebfa101SAndi Kleen 		.procname	= "compat-log",
844bebfa101SAndi Kleen 		.data		= &compat_log,
845bebfa101SAndi Kleen 		.maxlen		= sizeof (int),
846bebfa101SAndi Kleen 	 	.mode		= 0644,
8476d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
848bebfa101SAndi Kleen 	},
849bebfa101SAndi Kleen #endif
85023f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
85123f78d4aSIngo Molnar 	{
85223f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
85323f78d4aSIngo Molnar 		.data		= &max_lock_depth,
85423f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
85523f78d4aSIngo Molnar 		.mode		= 0644,
8566d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
85723f78d4aSIngo Molnar 	},
85823f78d4aSIngo Molnar #endif
85910a0a8d4SJeremy Fitzhardinge 	{
86010a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
86110a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
86210a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
86310a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
8646d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
86510a0a8d4SJeremy Fitzhardinge 	},
8660b77f5bfSDavid Howells #ifdef CONFIG_KEYS
8670b77f5bfSDavid Howells 	{
8680b77f5bfSDavid Howells 		.procname	= "keys",
8690b77f5bfSDavid Howells 		.mode		= 0555,
8700b77f5bfSDavid Howells 		.child		= key_sysctls,
8710b77f5bfSDavid Howells 	},
8720b77f5bfSDavid Howells #endif
87331a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST
87431a72bceSPaul E. McKenney 	{
87531a72bceSPaul E. McKenney 		.procname       = "rcutorture_runnable",
87631a72bceSPaul E. McKenney 		.data           = &rcutorture_runnable,
87731a72bceSPaul E. McKenney 		.maxlen         = sizeof(int),
87831a72bceSPaul E. McKenney 		.mode           = 0644,
8796d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
88031a72bceSPaul E. McKenney 	},
88131a72bceSPaul E. McKenney #endif
88212e22c5eSDavid Howells #ifdef CONFIG_SLOW_WORK
88312e22c5eSDavid Howells 	{
88412e22c5eSDavid Howells 		.procname	= "slow-work",
88512e22c5eSDavid Howells 		.mode		= 0555,
88612e22c5eSDavid Howells 		.child		= slow_work_sysctls,
88712e22c5eSDavid Howells 	},
88812e22c5eSDavid Howells #endif
889cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
8901ccd1549SPeter Zijlstra 	{
891cdd6c482SIngo Molnar 		.procname	= "perf_event_paranoid",
892cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_paranoid,
893cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
8941ccd1549SPeter Zijlstra 		.mode		= 0644,
8956d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
8961ccd1549SPeter Zijlstra 	},
897c5078f78SPeter Zijlstra 	{
898cdd6c482SIngo Molnar 		.procname	= "perf_event_mlock_kb",
899cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_mlock,
900cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_mlock),
901c5078f78SPeter Zijlstra 		.mode		= 0644,
9026d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
903c5078f78SPeter Zijlstra 	},
904a78ac325SPeter Zijlstra 	{
905cdd6c482SIngo Molnar 		.procname	= "perf_event_max_sample_rate",
906cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_sample_rate,
907cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
908a78ac325SPeter Zijlstra 		.mode		= 0644,
9096d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
910a78ac325SPeter Zijlstra 	},
9111ccd1549SPeter Zijlstra #endif
912dfec072eSVegard Nossum #ifdef CONFIG_KMEMCHECK
913dfec072eSVegard Nossum 	{
914dfec072eSVegard Nossum 		.procname	= "kmemcheck",
915dfec072eSVegard Nossum 		.data		= &kmemcheck_enabled,
916dfec072eSVegard Nossum 		.maxlen		= sizeof(int),
917dfec072eSVegard Nossum 		.mode		= 0644,
9186d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
919dfec072eSVegard Nossum 	},
920dfec072eSVegard Nossum #endif
921cb684b5bSJens Axboe #ifdef CONFIG_BLOCK
9225e605b64SJens Axboe 	{
9235e605b64SJens Axboe 		.procname	= "blk_iopoll",
9245e605b64SJens Axboe 		.data		= &blk_iopoll_enabled,
9255e605b64SJens Axboe 		.maxlen		= sizeof(int),
9265e605b64SJens Axboe 		.mode		= 0644,
9276d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
9285e605b64SJens Axboe 	},
929cb684b5bSJens Axboe #endif
930ed2c12f3SAndrew Morton /*
931ed2c12f3SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
932ed2c12f3SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
933ed2c12f3SAndrew Morton  */
9346fce56ecSEric W. Biederman 	{ }
9351da177e4SLinus Torvalds };
9361da177e4SLinus Torvalds 
937d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
9381da177e4SLinus Torvalds 	{
9391da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
9401da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
9411da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
9421da177e4SLinus Torvalds 		.mode		= 0644,
9436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
9441da177e4SLinus Torvalds 	},
9451da177e4SLinus Torvalds 	{
946fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
947fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
948fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
949fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
9506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
951fadd8fbdSKAMEZAWA Hiroyuki 	},
952fadd8fbdSKAMEZAWA Hiroyuki 	{
953fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
954fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
955fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
956fe071d7eSDavid Rientjes 		.mode		= 0644,
9576d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
958fe071d7eSDavid Rientjes 	},
959fe071d7eSDavid Rientjes 	{
960fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
961fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
962fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
963fef1bdd6SDavid Rientjes 		.mode		= 0644,
9646d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
965fef1bdd6SDavid Rientjes 	},
966fef1bdd6SDavid Rientjes 	{
9671da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
9681da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
9691da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
9701da177e4SLinus Torvalds 		.mode		= 0644,
9716d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
9721da177e4SLinus Torvalds 	},
9731da177e4SLinus Torvalds 	{
9741da177e4SLinus Torvalds 		.procname	= "page-cluster",
9751da177e4SLinus Torvalds 		.data		= &page_cluster,
9761da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
9771da177e4SLinus Torvalds 		.mode		= 0644,
9786d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
9791da177e4SLinus Torvalds 	},
9801da177e4SLinus Torvalds 	{
9811da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
9821da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
9831da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
9841da177e4SLinus Torvalds 		.mode		= 0644,
9856d456111SEric W. Biederman 		.proc_handler	= dirty_background_ratio_handler,
9861da177e4SLinus Torvalds 		.extra1		= &zero,
9871da177e4SLinus Torvalds 		.extra2		= &one_hundred,
9881da177e4SLinus Torvalds 	},
9891da177e4SLinus Torvalds 	{
9902da02997SDavid Rientjes 		.procname	= "dirty_background_bytes",
9912da02997SDavid Rientjes 		.data		= &dirty_background_bytes,
9922da02997SDavid Rientjes 		.maxlen		= sizeof(dirty_background_bytes),
9932da02997SDavid Rientjes 		.mode		= 0644,
9946d456111SEric W. Biederman 		.proc_handler	= dirty_background_bytes_handler,
995fc3501d4SSven Wegener 		.extra1		= &one_ul,
9962da02997SDavid Rientjes 	},
9972da02997SDavid Rientjes 	{
9981da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
9991da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
10001da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
10011da177e4SLinus Torvalds 		.mode		= 0644,
10026d456111SEric W. Biederman 		.proc_handler	= dirty_ratio_handler,
10031da177e4SLinus Torvalds 		.extra1		= &zero,
10041da177e4SLinus Torvalds 		.extra2		= &one_hundred,
10051da177e4SLinus Torvalds 	},
10061da177e4SLinus Torvalds 	{
10072da02997SDavid Rientjes 		.procname	= "dirty_bytes",
10082da02997SDavid Rientjes 		.data		= &vm_dirty_bytes,
10092da02997SDavid Rientjes 		.maxlen		= sizeof(vm_dirty_bytes),
10102da02997SDavid Rientjes 		.mode		= 0644,
10116d456111SEric W. Biederman 		.proc_handler	= dirty_bytes_handler,
10129e4a5bdaSAndrea Righi 		.extra1		= &dirty_bytes_min,
10132da02997SDavid Rientjes 	},
10142da02997SDavid Rientjes 	{
10151da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
1016f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
1017f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
10181da177e4SLinus Torvalds 		.mode		= 0644,
10196d456111SEric W. Biederman 		.proc_handler	= dirty_writeback_centisecs_handler,
10201da177e4SLinus Torvalds 	},
10211da177e4SLinus Torvalds 	{
10221da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
1023f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
1024f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
10251da177e4SLinus Torvalds 		.mode		= 0644,
10266d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
10271da177e4SLinus Torvalds 	},
10281da177e4SLinus Torvalds 	{
10291da177e4SLinus Torvalds 		.procname	= "nr_pdflush_threads",
10301da177e4SLinus Torvalds 		.data		= &nr_pdflush_threads,
10311da177e4SLinus Torvalds 		.maxlen		= sizeof nr_pdflush_threads,
10321da177e4SLinus Torvalds 		.mode		= 0444 /* read-only*/,
10336d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
10341da177e4SLinus Torvalds 	},
10351da177e4SLinus Torvalds 	{
10361da177e4SLinus Torvalds 		.procname	= "swappiness",
10371da177e4SLinus Torvalds 		.data		= &vm_swappiness,
10381da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
10391da177e4SLinus Torvalds 		.mode		= 0644,
10406d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
10411da177e4SLinus Torvalds 		.extra1		= &zero,
10421da177e4SLinus Torvalds 		.extra2		= &one_hundred,
10431da177e4SLinus Torvalds 	},
10441da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
10451da177e4SLinus Torvalds 	{
10461da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
1047e5ff2159SAndi Kleen 		.data		= NULL,
10481da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
10491da177e4SLinus Torvalds 		.mode		= 0644,
10506d456111SEric W. Biederman 		.proc_handler	= hugetlb_sysctl_handler,
10511da177e4SLinus Torvalds 		.extra1		= (void *)&hugetlb_zero,
10521da177e4SLinus Torvalds 		.extra2		= (void *)&hugetlb_infinity,
10531da177e4SLinus Torvalds 	},
105406808b08SLee Schermerhorn #ifdef CONFIG_NUMA
105506808b08SLee Schermerhorn 	{
105606808b08SLee Schermerhorn 		.procname       = "nr_hugepages_mempolicy",
105706808b08SLee Schermerhorn 		.data           = NULL,
105806808b08SLee Schermerhorn 		.maxlen         = sizeof(unsigned long),
105906808b08SLee Schermerhorn 		.mode           = 0644,
106006808b08SLee Schermerhorn 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
106106808b08SLee Schermerhorn 		.extra1		= (void *)&hugetlb_zero,
106206808b08SLee Schermerhorn 		.extra2		= (void *)&hugetlb_infinity,
106306808b08SLee Schermerhorn 	},
106406808b08SLee Schermerhorn #endif
10651da177e4SLinus Torvalds 	 {
10661da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
10671da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
10681da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
10691da177e4SLinus Torvalds 		.mode		= 0644,
10706d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
10711da177e4SLinus Torvalds 	 },
1072396faf03SMel Gorman 	 {
1073396faf03SMel Gorman 		.procname	= "hugepages_treat_as_movable",
1074396faf03SMel Gorman 		.data		= &hugepages_treat_as_movable,
1075396faf03SMel Gorman 		.maxlen		= sizeof(int),
1076396faf03SMel Gorman 		.mode		= 0644,
10776d456111SEric W. Biederman 		.proc_handler	= hugetlb_treat_movable_handler,
1078396faf03SMel Gorman 	},
107954f9f80dSAdam Litke 	{
1080d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
1081e5ff2159SAndi Kleen 		.data		= NULL,
1082e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
1083d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
10846d456111SEric W. Biederman 		.proc_handler	= hugetlb_overcommit_handler,
1085e5ff2159SAndi Kleen 		.extra1		= (void *)&hugetlb_zero,
1086e5ff2159SAndi Kleen 		.extra2		= (void *)&hugetlb_infinity,
1087d1c3fb1fSNishanth Aravamudan 	},
10881da177e4SLinus Torvalds #endif
10891da177e4SLinus Torvalds 	{
10901da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
10911da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
10921da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
10931da177e4SLinus Torvalds 		.mode		= 0644,
10946d456111SEric W. Biederman 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
10951da177e4SLinus Torvalds 	},
10961da177e4SLinus Torvalds 	{
10979d0243bcSAndrew Morton 		.procname	= "drop_caches",
10989d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
10999d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
11009d0243bcSAndrew Morton 		.mode		= 0644,
11019d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
11029d0243bcSAndrew Morton 	},
11039d0243bcSAndrew Morton 	{
11041da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
11051da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
11061da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
11071da177e4SLinus Torvalds 		.mode		= 0644,
11086d456111SEric W. Biederman 		.proc_handler	= min_free_kbytes_sysctl_handler,
11091da177e4SLinus Torvalds 		.extra1		= &zero,
11101da177e4SLinus Torvalds 	},
11118ad4b1fbSRohit Seth 	{
11128ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
11138ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
11148ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
11158ad4b1fbSRohit Seth 		.mode		= 0644,
11166d456111SEric W. Biederman 		.proc_handler	= percpu_pagelist_fraction_sysctl_handler,
11178ad4b1fbSRohit Seth 		.extra1		= &min_percpu_pagelist_fract,
11188ad4b1fbSRohit Seth 	},
11191da177e4SLinus Torvalds #ifdef CONFIG_MMU
11201da177e4SLinus Torvalds 	{
11211da177e4SLinus Torvalds 		.procname	= "max_map_count",
11221da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
11231da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
11241da177e4SLinus Torvalds 		.mode		= 0644,
11253e26120cSWANG Cong 		.proc_handler	= proc_dointvec_minmax,
112670da2340SAmerigo Wang 		.extra1		= &zero,
11271da177e4SLinus Torvalds 	},
1128dd8632a1SPaul Mundt #else
1129dd8632a1SPaul Mundt 	{
1130dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
1131dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
1132dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
1133dd8632a1SPaul Mundt 		.mode		= 0644,
11346d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
1135dd8632a1SPaul Mundt 		.extra1		= &zero,
1136dd8632a1SPaul Mundt 	},
11371da177e4SLinus Torvalds #endif
11381da177e4SLinus Torvalds 	{
11391da177e4SLinus Torvalds 		.procname	= "laptop_mode",
11401da177e4SLinus Torvalds 		.data		= &laptop_mode,
11411da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
11421da177e4SLinus Torvalds 		.mode		= 0644,
11436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
11441da177e4SLinus Torvalds 	},
11451da177e4SLinus Torvalds 	{
11461da177e4SLinus Torvalds 		.procname	= "block_dump",
11471da177e4SLinus Torvalds 		.data		= &block_dump,
11481da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
11491da177e4SLinus Torvalds 		.mode		= 0644,
11506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
11511da177e4SLinus Torvalds 		.extra1		= &zero,
11521da177e4SLinus Torvalds 	},
11531da177e4SLinus Torvalds 	{
11541da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
11551da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
11561da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
11571da177e4SLinus Torvalds 		.mode		= 0644,
11586d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
11591da177e4SLinus Torvalds 		.extra1		= &zero,
11601da177e4SLinus Torvalds 	},
11611da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
11621da177e4SLinus Torvalds 	{
11631da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
11641da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
11651da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
11661da177e4SLinus Torvalds 		.mode		= 0644,
11676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
11681da177e4SLinus Torvalds 		.extra1		= &zero,
11691da177e4SLinus Torvalds 	},
11701da177e4SLinus Torvalds #endif
11711743660bSChristoph Lameter #ifdef CONFIG_NUMA
11721743660bSChristoph Lameter 	{
11731743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
11741743660bSChristoph Lameter 		.data		= &zone_reclaim_mode,
11751743660bSChristoph Lameter 		.maxlen		= sizeof(zone_reclaim_mode),
11761743660bSChristoph Lameter 		.mode		= 0644,
11776d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1178c84db23cSChristoph Lameter 		.extra1		= &zero,
11791743660bSChristoph Lameter 	},
11809614634fSChristoph Lameter 	{
11819614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
11829614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
11839614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
11849614634fSChristoph Lameter 		.mode		= 0644,
11856d456111SEric W. Biederman 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
11869614634fSChristoph Lameter 		.extra1		= &zero,
11879614634fSChristoph Lameter 		.extra2		= &one_hundred,
11889614634fSChristoph Lameter 	},
11890ff38490SChristoph Lameter 	{
11900ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
11910ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
11920ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
11930ff38490SChristoph Lameter 		.mode		= 0644,
11946d456111SEric W. Biederman 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
11950ff38490SChristoph Lameter 		.extra1		= &zero,
11960ff38490SChristoph Lameter 		.extra2		= &one_hundred,
11970ff38490SChristoph Lameter 	},
11981743660bSChristoph Lameter #endif
119977461ab3SChristoph Lameter #ifdef CONFIG_SMP
120077461ab3SChristoph Lameter 	{
120177461ab3SChristoph Lameter 		.procname	= "stat_interval",
120277461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
120377461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
120477461ab3SChristoph Lameter 		.mode		= 0644,
12056d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
120677461ab3SChristoph Lameter 	},
120777461ab3SChristoph Lameter #endif
12086e141546SDavid Howells #ifdef CONFIG_MMU
1209ed032189SEric Paris 	{
1210ed032189SEric Paris 		.procname	= "mmap_min_addr",
1211788084abSEric Paris 		.data		= &dac_mmap_min_addr,
1212ed032189SEric Paris 		.maxlen		= sizeof(unsigned long),
1213ed032189SEric Paris 		.mode		= 0644,
12146d456111SEric W. Biederman 		.proc_handler	= mmap_min_addr_handler,
1215ed032189SEric Paris 	},
12166e141546SDavid Howells #endif
1217f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
1218f0c0b2b8SKAMEZAWA Hiroyuki 	{
1219f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
1220f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
1221f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
1222f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
12236d456111SEric W. Biederman 		.proc_handler	= numa_zonelist_order_handler,
1224f0c0b2b8SKAMEZAWA Hiroyuki 	},
1225f0c0b2b8SKAMEZAWA Hiroyuki #endif
12262b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
12275c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1228e6e5494cSIngo Molnar 	{
1229e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
1230e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
1231e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
1232e6e5494cSIngo Molnar 		.mode		= 0644,
12336d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1234e6e5494cSIngo Molnar 		.extra1		= &zero,
1235e6e5494cSIngo Molnar 	},
1236e6e5494cSIngo Molnar #endif
1237195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
1238195cf453SBron Gondwana 	{
1239195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
1240195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
1241195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
1242195cf453SBron Gondwana 		.mode		= 0644,
12436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
1244195cf453SBron Gondwana 		.extra1		= &zero,
1245195cf453SBron Gondwana 		.extra2		= &one,
1246195cf453SBron Gondwana 	},
1247195cf453SBron Gondwana #endif
12484be6f6bbSPeter Zijlstra 	{
12494be6f6bbSPeter Zijlstra 		.procname	= "scan_unevictable_pages",
12504be6f6bbSPeter Zijlstra 		.data		= &scan_unevictable_pages,
12514be6f6bbSPeter Zijlstra 		.maxlen		= sizeof(scan_unevictable_pages),
12524be6f6bbSPeter Zijlstra 		.mode		= 0644,
12536d456111SEric W. Biederman 		.proc_handler	= scan_unevictable_handler,
12544be6f6bbSPeter Zijlstra 	},
12556a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
12566a46079cSAndi Kleen 	{
12576a46079cSAndi Kleen 		.procname	= "memory_failure_early_kill",
12586a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_early_kill,
12596a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
12606a46079cSAndi Kleen 		.mode		= 0644,
12616d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
12626a46079cSAndi Kleen 		.extra1		= &zero,
12636a46079cSAndi Kleen 		.extra2		= &one,
12646a46079cSAndi Kleen 	},
12656a46079cSAndi Kleen 	{
12666a46079cSAndi Kleen 		.procname	= "memory_failure_recovery",
12676a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_recovery,
12686a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
12696a46079cSAndi Kleen 		.mode		= 0644,
12706d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
12716a46079cSAndi Kleen 		.extra1		= &zero,
12726a46079cSAndi Kleen 		.extra2		= &one,
12736a46079cSAndi Kleen 	},
12746a46079cSAndi Kleen #endif
12756a46079cSAndi Kleen 
12762be7fe07SAndrew Morton /*
12772be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
12782be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
12792be7fe07SAndrew Morton  */
12806fce56ecSEric W. Biederman 	{ }
12811da177e4SLinus Torvalds };
12821da177e4SLinus Torvalds 
12832abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1284d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = {
12856fce56ecSEric W. Biederman 	{ }
12862abc26fcSEric W. Biederman };
12872abc26fcSEric W. Biederman #endif
12882abc26fcSEric W. Biederman 
1289d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
12901da177e4SLinus Torvalds 	{
12911da177e4SLinus Torvalds 		.procname	= "inode-nr",
12921da177e4SLinus Torvalds 		.data		= &inodes_stat,
12931da177e4SLinus Torvalds 		.maxlen		= 2*sizeof(int),
12941da177e4SLinus Torvalds 		.mode		= 0444,
12956d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
12961da177e4SLinus Torvalds 	},
12971da177e4SLinus Torvalds 	{
12981da177e4SLinus Torvalds 		.procname	= "inode-state",
12991da177e4SLinus Torvalds 		.data		= &inodes_stat,
13001da177e4SLinus Torvalds 		.maxlen		= 7*sizeof(int),
13011da177e4SLinus Torvalds 		.mode		= 0444,
13026d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
13031da177e4SLinus Torvalds 	},
13041da177e4SLinus Torvalds 	{
13051da177e4SLinus Torvalds 		.procname	= "file-nr",
13061da177e4SLinus Torvalds 		.data		= &files_stat,
13071da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
13081da177e4SLinus Torvalds 		.mode		= 0444,
13096d456111SEric W. Biederman 		.proc_handler	= proc_nr_files,
13101da177e4SLinus Torvalds 	},
13111da177e4SLinus Torvalds 	{
13121da177e4SLinus Torvalds 		.procname	= "file-max",
13131da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
13141da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13151da177e4SLinus Torvalds 		.mode		= 0644,
13166d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
13171da177e4SLinus Torvalds 	},
13181da177e4SLinus Torvalds 	{
13199cfe015aSEric Dumazet 		.procname	= "nr_open",
13209cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
13219cfe015aSEric Dumazet 		.maxlen		= sizeof(int),
13229cfe015aSEric Dumazet 		.mode		= 0644,
13236d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
1324eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
1325eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
13269cfe015aSEric Dumazet 	},
13279cfe015aSEric Dumazet 	{
13281da177e4SLinus Torvalds 		.procname	= "dentry-state",
13291da177e4SLinus Torvalds 		.data		= &dentry_stat,
13301da177e4SLinus Torvalds 		.maxlen		= 6*sizeof(int),
13311da177e4SLinus Torvalds 		.mode		= 0444,
13326d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
13331da177e4SLinus Torvalds 	},
13341da177e4SLinus Torvalds 	{
13351da177e4SLinus Torvalds 		.procname	= "overflowuid",
13361da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
13371da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13381da177e4SLinus Torvalds 		.mode		= 0644,
13396d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
13401da177e4SLinus Torvalds 		.extra1		= &minolduid,
13411da177e4SLinus Torvalds 		.extra2		= &maxolduid,
13421da177e4SLinus Torvalds 	},
13431da177e4SLinus Torvalds 	{
13441da177e4SLinus Torvalds 		.procname	= "overflowgid",
13451da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
13461da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13471da177e4SLinus Torvalds 		.mode		= 0644,
13486d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
13491da177e4SLinus Torvalds 		.extra1		= &minolduid,
13501da177e4SLinus Torvalds 		.extra2		= &maxolduid,
13511da177e4SLinus Torvalds 	},
1352bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
13531da177e4SLinus Torvalds 	{
13541da177e4SLinus Torvalds 		.procname	= "leases-enable",
13551da177e4SLinus Torvalds 		.data		= &leases_enable,
13561da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13571da177e4SLinus Torvalds 		.mode		= 0644,
13586d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
13591da177e4SLinus Torvalds 	},
1360bfcd17a6SThomas Petazzoni #endif
13611da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
13621da177e4SLinus Torvalds 	{
13631da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
13641da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
13651da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13661da177e4SLinus Torvalds 		.mode		= 0644,
13676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
13681da177e4SLinus Torvalds 	},
13691da177e4SLinus Torvalds #endif
13701da177e4SLinus Torvalds #ifdef CONFIG_MMU
1371bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
13721da177e4SLinus Torvalds 	{
13731da177e4SLinus Torvalds 		.procname	= "lease-break-time",
13741da177e4SLinus Torvalds 		.data		= &lease_break_time,
13751da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
13761da177e4SLinus Torvalds 		.mode		= 0644,
13776d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
13781da177e4SLinus Torvalds 	},
1379bfcd17a6SThomas Petazzoni #endif
1380ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO
13811da177e4SLinus Torvalds 	{
13821da177e4SLinus Torvalds 		.procname	= "aio-nr",
13831da177e4SLinus Torvalds 		.data		= &aio_nr,
13841da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
13851da177e4SLinus Torvalds 		.mode		= 0444,
13866d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
13871da177e4SLinus Torvalds 	},
13881da177e4SLinus Torvalds 	{
13891da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
13901da177e4SLinus Torvalds 		.data		= &aio_max_nr,
13911da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
13921da177e4SLinus Torvalds 		.mode		= 0644,
13936d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
13941da177e4SLinus Torvalds 	},
1395ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */
13962d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
13970399cb08SRobert Love 	{
13980399cb08SRobert Love 		.procname	= "inotify",
13990399cb08SRobert Love 		.mode		= 0555,
14000399cb08SRobert Love 		.child		= inotify_table,
14010399cb08SRobert Love 	},
14020399cb08SRobert Love #endif
14037ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
14047ef9964eSDavide Libenzi 	{
14057ef9964eSDavide Libenzi 		.procname	= "epoll",
14067ef9964eSDavide Libenzi 		.mode		= 0555,
14077ef9964eSDavide Libenzi 		.child		= epoll_table,
14087ef9964eSDavide Libenzi 	},
14097ef9964eSDavide Libenzi #endif
14101da177e4SLinus Torvalds #endif
1411d6e71144SAlan Cox 	{
1412d6e71144SAlan Cox 		.procname	= "suid_dumpable",
1413d6e71144SAlan Cox 		.data		= &suid_dumpable,
1414d6e71144SAlan Cox 		.maxlen		= sizeof(int),
1415d6e71144SAlan Cox 		.mode		= 0644,
14166d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
14178e654fbaSMatthew Wilcox 		.extra1		= &zero,
14188e654fbaSMatthew Wilcox 		.extra2		= &two,
1419d6e71144SAlan Cox 	},
14202abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
14212abc26fcSEric W. Biederman 	{
14222abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
14232abc26fcSEric W. Biederman 		.mode		= 0555,
14242abc26fcSEric W. Biederman 		.child		= binfmt_misc_table,
14252abc26fcSEric W. Biederman 	},
14262abc26fcSEric W. Biederman #endif
1427*b492e95bSJens Axboe 	{
1428*b492e95bSJens Axboe 		.procname	= "pipe-max-pages",
1429*b492e95bSJens Axboe 		.data		= &pipe_max_pages,
1430*b492e95bSJens Axboe 		.maxlen		= sizeof(int),
1431*b492e95bSJens Axboe 		.mode		= 0644,
1432*b492e95bSJens Axboe 		.proc_handler	= &proc_dointvec_minmax,
1433*b492e95bSJens Axboe 		.extra1		= &two,
1434*b492e95bSJens Axboe 	},
14352be7fe07SAndrew Morton /*
14362be7fe07SAndrew Morton  * NOTE: do not add new entries to this table unless you have read
14372be7fe07SAndrew Morton  * Documentation/sysctl/ctl_unnumbered.txt
14382be7fe07SAndrew Morton  */
14396fce56ecSEric W. Biederman 	{ }
14401da177e4SLinus Torvalds };
14411da177e4SLinus Torvalds 
1442d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
14434b177647SDavid S. Miller #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1444abd4f750SMasoud Asgharifard Sharbiani 	{
1445abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
1446abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
1447abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
1448abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
1449abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
1450abd4f750SMasoud Asgharifard Sharbiani 	},
1451abd4f750SMasoud Asgharifard Sharbiani #endif
1452b2be84dfSMasami Hiramatsu #if defined(CONFIG_OPTPROBES)
1453b2be84dfSMasami Hiramatsu 	{
1454b2be84dfSMasami Hiramatsu 		.procname	= "kprobes-optimization",
1455b2be84dfSMasami Hiramatsu 		.data		= &sysctl_kprobes_optimization,
1456b2be84dfSMasami Hiramatsu 		.maxlen		= sizeof(int),
1457b2be84dfSMasami Hiramatsu 		.mode		= 0644,
1458b2be84dfSMasami Hiramatsu 		.proc_handler	= proc_kprobes_optimization_handler,
1459b2be84dfSMasami Hiramatsu 		.extra1		= &zero,
1460b2be84dfSMasami Hiramatsu 		.extra2		= &one,
1461b2be84dfSMasami Hiramatsu 	},
1462b2be84dfSMasami Hiramatsu #endif
14636fce56ecSEric W. Biederman 	{ }
14641da177e4SLinus Torvalds };
14651da177e4SLinus Torvalds 
1466d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
14676fce56ecSEric W. Biederman 	{ }
14681da177e4SLinus Torvalds };
14691da177e4SLinus Torvalds 
1470330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock);
1471330d57fbSAl Viro 
1472330d57fbSAl Viro /* called under sysctl_lock */
1473330d57fbSAl Viro static int use_table(struct ctl_table_header *p)
1474330d57fbSAl Viro {
1475330d57fbSAl Viro 	if (unlikely(p->unregistering))
1476330d57fbSAl Viro 		return 0;
1477330d57fbSAl Viro 	p->used++;
1478330d57fbSAl Viro 	return 1;
1479330d57fbSAl Viro }
1480330d57fbSAl Viro 
1481330d57fbSAl Viro /* called under sysctl_lock */
1482330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p)
1483330d57fbSAl Viro {
1484330d57fbSAl Viro 	if (!--p->used)
1485330d57fbSAl Viro 		if (unlikely(p->unregistering))
1486330d57fbSAl Viro 			complete(p->unregistering);
1487330d57fbSAl Viro }
1488330d57fbSAl Viro 
1489330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */
1490330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p)
1491330d57fbSAl Viro {
1492330d57fbSAl Viro 	/*
1493330d57fbSAl Viro 	 * if p->used is 0, nobody will ever touch that entry again;
1494330d57fbSAl Viro 	 * we'll eliminate all paths to it before dropping sysctl_lock
1495330d57fbSAl Viro 	 */
1496330d57fbSAl Viro 	if (unlikely(p->used)) {
1497330d57fbSAl Viro 		struct completion wait;
1498330d57fbSAl Viro 		init_completion(&wait);
1499330d57fbSAl Viro 		p->unregistering = &wait;
1500330d57fbSAl Viro 		spin_unlock(&sysctl_lock);
1501330d57fbSAl Viro 		wait_for_completion(&wait);
1502330d57fbSAl Viro 		spin_lock(&sysctl_lock);
1503f7e6ced4SAl Viro 	} else {
1504f7e6ced4SAl Viro 		/* anything non-NULL; we'll never dereference it */
1505f7e6ced4SAl Viro 		p->unregistering = ERR_PTR(-EINVAL);
1506330d57fbSAl Viro 	}
1507330d57fbSAl Viro 	/*
1508330d57fbSAl Viro 	 * do not remove from the list until nobody holds it; walking the
1509330d57fbSAl Viro 	 * list in do_sysctl() relies on that.
1510330d57fbSAl Viro 	 */
1511330d57fbSAl Viro 	list_del_init(&p->ctl_entry);
1512330d57fbSAl Viro }
1513330d57fbSAl Viro 
1514f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head)
1515f7e6ced4SAl Viro {
1516f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1517f7e6ced4SAl Viro 	head->count++;
1518f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1519f7e6ced4SAl Viro }
1520f7e6ced4SAl Viro 
1521f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
1522f7e6ced4SAl Viro {
1523f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1524f7e6ced4SAl Viro 	if (!--head->count)
1525f7e6ced4SAl Viro 		kfree(head);
1526f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1527f7e6ced4SAl Viro }
1528f7e6ced4SAl Viro 
1529f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1530f7e6ced4SAl Viro {
1531f7e6ced4SAl Viro 	if (!head)
1532f7e6ced4SAl Viro 		BUG();
1533f7e6ced4SAl Viro 	spin_lock(&sysctl_lock);
1534f7e6ced4SAl Viro 	if (!use_table(head))
1535f7e6ced4SAl Viro 		head = ERR_PTR(-ENOENT);
1536f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
1537f7e6ced4SAl Viro 	return head;
1538f7e6ced4SAl Viro }
1539f7e6ced4SAl Viro 
1540805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head)
1541805b5d5eSEric W. Biederman {
1542805b5d5eSEric W. Biederman 	if (!head)
1543805b5d5eSEric W. Biederman 		return;
1544805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1545805b5d5eSEric W. Biederman 	unuse_table(head);
1546805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1547805b5d5eSEric W. Biederman }
1548805b5d5eSEric W. Biederman 
154973455092SAl Viro static struct ctl_table_set *
155073455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
155173455092SAl Viro {
155273455092SAl Viro 	struct ctl_table_set *set = &root->default_set;
155373455092SAl Viro 	if (root->lookup)
155473455092SAl Viro 		set = root->lookup(root, namespaces);
155573455092SAl Viro 	return set;
155673455092SAl Viro }
155773455092SAl Viro 
1558e51b6ba0SEric W. Biederman static struct list_head *
1559e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1560805b5d5eSEric W. Biederman {
156173455092SAl Viro 	struct ctl_table_set *set = lookup_header_set(root, namespaces);
156273455092SAl Viro 	return &set->list;
1563e51b6ba0SEric W. Biederman }
1564e51b6ba0SEric W. Biederman 
1565e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1566e51b6ba0SEric W. Biederman 					    struct ctl_table_header *prev)
1567e51b6ba0SEric W. Biederman {
1568e51b6ba0SEric W. Biederman 	struct ctl_table_root *root;
1569e51b6ba0SEric W. Biederman 	struct list_head *header_list;
1570805b5d5eSEric W. Biederman 	struct ctl_table_header *head;
1571805b5d5eSEric W. Biederman 	struct list_head *tmp;
1572e51b6ba0SEric W. Biederman 
1573805b5d5eSEric W. Biederman 	spin_lock(&sysctl_lock);
1574805b5d5eSEric W. Biederman 	if (prev) {
1575e51b6ba0SEric W. Biederman 		head = prev;
1576805b5d5eSEric W. Biederman 		tmp = &prev->ctl_entry;
1577805b5d5eSEric W. Biederman 		unuse_table(prev);
1578805b5d5eSEric W. Biederman 		goto next;
1579805b5d5eSEric W. Biederman 	}
1580805b5d5eSEric W. Biederman 	tmp = &root_table_header.ctl_entry;
1581805b5d5eSEric W. Biederman 	for (;;) {
1582805b5d5eSEric W. Biederman 		head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1583805b5d5eSEric W. Biederman 
1584805b5d5eSEric W. Biederman 		if (!use_table(head))
1585805b5d5eSEric W. Biederman 			goto next;
1586805b5d5eSEric W. Biederman 		spin_unlock(&sysctl_lock);
1587805b5d5eSEric W. Biederman 		return head;
1588805b5d5eSEric W. Biederman 	next:
1589e51b6ba0SEric W. Biederman 		root = head->root;
1590805b5d5eSEric W. Biederman 		tmp = tmp->next;
1591e51b6ba0SEric W. Biederman 		header_list = lookup_header_list(root, namespaces);
1592e51b6ba0SEric W. Biederman 		if (tmp != header_list)
1593e51b6ba0SEric W. Biederman 			continue;
1594e51b6ba0SEric W. Biederman 
1595e51b6ba0SEric W. Biederman 		do {
1596e51b6ba0SEric W. Biederman 			root = list_entry(root->root_list.next,
1597e51b6ba0SEric W. Biederman 					struct ctl_table_root, root_list);
1598e51b6ba0SEric W. Biederman 			if (root == &sysctl_table_root)
1599e51b6ba0SEric W. Biederman 				goto out;
1600e51b6ba0SEric W. Biederman 			header_list = lookup_header_list(root, namespaces);
1601e51b6ba0SEric W. Biederman 		} while (list_empty(header_list));
1602e51b6ba0SEric W. Biederman 		tmp = header_list->next;
1603805b5d5eSEric W. Biederman 	}
1604e51b6ba0SEric W. Biederman out:
1605805b5d5eSEric W. Biederman 	spin_unlock(&sysctl_lock);
1606805b5d5eSEric W. Biederman 	return NULL;
1607805b5d5eSEric W. Biederman }
1608805b5d5eSEric W. Biederman 
1609e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1610e51b6ba0SEric W. Biederman {
1611e51b6ba0SEric W. Biederman 	return __sysctl_head_next(current->nsproxy, prev);
1612e51b6ba0SEric W. Biederman }
1613e51b6ba0SEric W. Biederman 
1614e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root)
1615e51b6ba0SEric W. Biederman {
1616e51b6ba0SEric W. Biederman 	spin_lock(&sysctl_lock);
1617e51b6ba0SEric W. Biederman 	list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1618e51b6ba0SEric W. Biederman 	spin_unlock(&sysctl_lock);
1619e51b6ba0SEric W. Biederman }
1620e51b6ba0SEric W. Biederman 
16211da177e4SLinus Torvalds /*
16221ff007ebSEric W. Biederman  * sysctl_perm does NOT grant the superuser all rights automatically, because
16231da177e4SLinus Torvalds  * some sysctl variables are readonly even to root.
16241da177e4SLinus Torvalds  */
16251da177e4SLinus Torvalds 
16261da177e4SLinus Torvalds static int test_perm(int mode, int op)
16271da177e4SLinus Torvalds {
162876aac0e9SDavid Howells 	if (!current_euid())
16291da177e4SLinus Torvalds 		mode >>= 6;
16301da177e4SLinus Torvalds 	else if (in_egroup_p(0))
16311da177e4SLinus Torvalds 		mode >>= 3;
1632e6305c43SAl Viro 	if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
16331da177e4SLinus Torvalds 		return 0;
16341da177e4SLinus Torvalds 	return -EACCES;
16351da177e4SLinus Torvalds }
16361da177e4SLinus Torvalds 
1637d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
16381da177e4SLinus Torvalds {
16391da177e4SLinus Torvalds 	int error;
1640d7321cd6SPavel Emelyanov 	int mode;
1641d7321cd6SPavel Emelyanov 
1642e6305c43SAl Viro 	error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
16431da177e4SLinus Torvalds 	if (error)
16441da177e4SLinus Torvalds 		return error;
1645d7321cd6SPavel Emelyanov 
1646d7321cd6SPavel Emelyanov 	if (root->permissions)
1647d7321cd6SPavel Emelyanov 		mode = root->permissions(root, current->nsproxy, table);
1648d7321cd6SPavel Emelyanov 	else
1649d7321cd6SPavel Emelyanov 		mode = table->mode;
1650d7321cd6SPavel Emelyanov 
1651d7321cd6SPavel Emelyanov 	return test_perm(mode, op);
16521da177e4SLinus Torvalds }
16531da177e4SLinus Torvalds 
1654d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1655d912b0ccSEric W. Biederman {
16562315ffa0SEric W. Biederman 	for (; table->procname; table++) {
1657d912b0ccSEric W. Biederman 		table->parent = parent;
1658d912b0ccSEric W. Biederman 		if (table->child)
1659d912b0ccSEric W. Biederman 			sysctl_set_parent(table, table->child);
1660d912b0ccSEric W. Biederman 	}
1661d912b0ccSEric W. Biederman }
1662d912b0ccSEric W. Biederman 
1663d912b0ccSEric W. Biederman static __init int sysctl_init(void)
1664d912b0ccSEric W. Biederman {
1665d912b0ccSEric W. Biederman 	sysctl_set_parent(NULL, root_table);
166688f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
166788f458e4SHolger Schurig 	{
166888f458e4SHolger Schurig 		int err;
1669e51b6ba0SEric W. Biederman 		err = sysctl_check_table(current->nsproxy, root_table);
167088f458e4SHolger Schurig 	}
167188f458e4SHolger Schurig #endif
1672d912b0ccSEric W. Biederman 	return 0;
1673d912b0ccSEric W. Biederman }
1674d912b0ccSEric W. Biederman 
1675d912b0ccSEric W. Biederman core_initcall(sysctl_init);
1676d912b0ccSEric W. Biederman 
1677bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch,
1678bfbcf034SAl Viro 				      struct ctl_table *table)
1679ae7edeccSAl Viro {
1680ae7edeccSAl Viro 	struct ctl_table *p;
1681ae7edeccSAl Viro 	const char *s = branch->procname;
1682ae7edeccSAl Viro 
1683ae7edeccSAl Viro 	/* branch should have named subdirectory as its first element */
1684ae7edeccSAl Viro 	if (!s || !branch->child)
1685bfbcf034SAl Viro 		return NULL;
1686ae7edeccSAl Viro 
1687ae7edeccSAl Viro 	/* ... and nothing else */
16882315ffa0SEric W. Biederman 	if (branch[1].procname)
1689bfbcf034SAl Viro 		return NULL;
1690ae7edeccSAl Viro 
1691ae7edeccSAl Viro 	/* table should contain subdirectory with the same name */
16922315ffa0SEric W. Biederman 	for (p = table; p->procname; p++) {
1693ae7edeccSAl Viro 		if (!p->child)
1694ae7edeccSAl Viro 			continue;
1695ae7edeccSAl Viro 		if (p->procname && strcmp(p->procname, s) == 0)
1696bfbcf034SAl Viro 			return p;
1697ae7edeccSAl Viro 	}
1698bfbcf034SAl Viro 	return NULL;
1699ae7edeccSAl Viro }
1700ae7edeccSAl Viro 
1701ae7edeccSAl Viro /* see if attaching q to p would be an improvement */
1702ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1703ae7edeccSAl Viro {
1704ae7edeccSAl Viro 	struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1705bfbcf034SAl Viro 	struct ctl_table *next;
1706ae7edeccSAl Viro 	int is_better = 0;
1707ae7edeccSAl Viro 	int not_in_parent = !p->attached_by;
1708ae7edeccSAl Viro 
1709bfbcf034SAl Viro 	while ((next = is_branch_in(by, to)) != NULL) {
1710ae7edeccSAl Viro 		if (by == q->attached_by)
1711ae7edeccSAl Viro 			is_better = 1;
1712ae7edeccSAl Viro 		if (to == p->attached_by)
1713ae7edeccSAl Viro 			not_in_parent = 1;
1714ae7edeccSAl Viro 		by = by->child;
1715bfbcf034SAl Viro 		to = next->child;
1716ae7edeccSAl Viro 	}
1717ae7edeccSAl Viro 
1718ae7edeccSAl Viro 	if (is_better && not_in_parent) {
1719ae7edeccSAl Viro 		q->attached_by = by;
1720ae7edeccSAl Viro 		q->attached_to = to;
1721ae7edeccSAl Viro 		q->parent = p;
1722ae7edeccSAl Viro 	}
1723ae7edeccSAl Viro }
1724ae7edeccSAl Viro 
17251da177e4SLinus Torvalds /**
1726e51b6ba0SEric W. Biederman  * __register_sysctl_paths - register a sysctl hierarchy
1727e51b6ba0SEric W. Biederman  * @root: List of sysctl headers to register on
1728e51b6ba0SEric W. Biederman  * @namespaces: Data to compute which lists of sysctl entries are visible
172929e796fdSEric W. Biederman  * @path: The path to the directory the sysctl table is in.
17301da177e4SLinus Torvalds  * @table: the top-level table structure
17311da177e4SLinus Torvalds  *
17321da177e4SLinus Torvalds  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
173329e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
17341da177e4SLinus Torvalds  *
1735d8217f07SEric W. Biederman  * The members of the &struct ctl_table structure are used as follows:
17361da177e4SLinus Torvalds  *
17371da177e4SLinus Torvalds  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
17381da177e4SLinus Torvalds  *            enter a sysctl file
17391da177e4SLinus Torvalds  *
17401da177e4SLinus Torvalds  * data - a pointer to data for use by proc_handler
17411da177e4SLinus Torvalds  *
17421da177e4SLinus Torvalds  * maxlen - the maximum size in bytes of the data
17431da177e4SLinus Torvalds  *
17441da177e4SLinus Torvalds  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
17451da177e4SLinus Torvalds  *
17461da177e4SLinus Torvalds  * child - a pointer to the child sysctl table if this entry is a directory, or
17471da177e4SLinus Torvalds  *         %NULL.
17481da177e4SLinus Torvalds  *
17491da177e4SLinus Torvalds  * proc_handler - the text handler routine (described below)
17501da177e4SLinus Torvalds  *
17511da177e4SLinus Torvalds  * de - for internal use by the sysctl routines
17521da177e4SLinus Torvalds  *
17531da177e4SLinus Torvalds  * extra1, extra2 - extra pointers usable by the proc handler routines
17541da177e4SLinus Torvalds  *
17551da177e4SLinus Torvalds  * Leaf nodes in the sysctl tree will be represented by a single file
17561da177e4SLinus Torvalds  * under /proc; non-leaf nodes will be represented by directories.
17571da177e4SLinus Torvalds  *
17581da177e4SLinus Torvalds  * sysctl(2) can automatically manage read and write requests through
17591da177e4SLinus Torvalds  * the sysctl table.  The data and maxlen fields of the ctl_table
17601da177e4SLinus Torvalds  * struct enable minimal validation of the values being written to be
17611da177e4SLinus Torvalds  * performed, and the mode field allows minimal authentication.
17621da177e4SLinus Torvalds  *
17631da177e4SLinus Torvalds  * There must be a proc_handler routine for any terminal nodes
17641da177e4SLinus Torvalds  * mirrored under /proc/sys (non-terminals are handled by a built-in
17651da177e4SLinus Torvalds  * directory handler).  Several default handlers are available to
17661da177e4SLinus Torvalds  * cover common cases -
17671da177e4SLinus Torvalds  *
17681da177e4SLinus Torvalds  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
17691da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
17701da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
17711da177e4SLinus Torvalds  *
17721da177e4SLinus Torvalds  * It is the handler's job to read the input buffer from user memory
17731da177e4SLinus Torvalds  * and process it. The handler should return 0 on success.
17741da177e4SLinus Torvalds  *
17751da177e4SLinus Torvalds  * This routine returns %NULL on a failure to register, and a pointer
17761da177e4SLinus Torvalds  * to the table header on success.
17771da177e4SLinus Torvalds  */
1778e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths(
1779e51b6ba0SEric W. Biederman 	struct ctl_table_root *root,
1780e51b6ba0SEric W. Biederman 	struct nsproxy *namespaces,
1781e51b6ba0SEric W. Biederman 	const struct ctl_path *path, struct ctl_table *table)
17821da177e4SLinus Torvalds {
178329e796fdSEric W. Biederman 	struct ctl_table_header *header;
178429e796fdSEric W. Biederman 	struct ctl_table *new, **prevp;
178529e796fdSEric W. Biederman 	unsigned int n, npath;
1786ae7edeccSAl Viro 	struct ctl_table_set *set;
178729e796fdSEric W. Biederman 
178829e796fdSEric W. Biederman 	/* Count the path components */
17892315ffa0SEric W. Biederman 	for (npath = 0; path[npath].procname; ++npath)
179029e796fdSEric W. Biederman 		;
179129e796fdSEric W. Biederman 
179229e796fdSEric W. Biederman 	/*
179329e796fdSEric W. Biederman 	 * For each path component, allocate a 2-element ctl_table array.
179429e796fdSEric W. Biederman 	 * The first array element will be filled with the sysctl entry
17952315ffa0SEric W. Biederman 	 * for this, the second will be the sentinel (procname == 0).
179629e796fdSEric W. Biederman 	 *
179729e796fdSEric W. Biederman 	 * We allocate everything in one go so that we don't have to
179829e796fdSEric W. Biederman 	 * worry about freeing additional memory in unregister_sysctl_table.
179929e796fdSEric W. Biederman 	 */
180029e796fdSEric W. Biederman 	header = kzalloc(sizeof(struct ctl_table_header) +
180129e796fdSEric W. Biederman 			 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
180229e796fdSEric W. Biederman 	if (!header)
18031da177e4SLinus Torvalds 		return NULL;
180429e796fdSEric W. Biederman 
180529e796fdSEric W. Biederman 	new = (struct ctl_table *) (header + 1);
180629e796fdSEric W. Biederman 
180729e796fdSEric W. Biederman 	/* Now connect the dots */
180829e796fdSEric W. Biederman 	prevp = &header->ctl_table;
180929e796fdSEric W. Biederman 	for (n = 0; n < npath; ++n, ++path) {
181029e796fdSEric W. Biederman 		/* Copy the procname */
181129e796fdSEric W. Biederman 		new->procname = path->procname;
181229e796fdSEric W. Biederman 		new->mode     = 0555;
181329e796fdSEric W. Biederman 
181429e796fdSEric W. Biederman 		*prevp = new;
181529e796fdSEric W. Biederman 		prevp = &new->child;
181629e796fdSEric W. Biederman 
181729e796fdSEric W. Biederman 		new += 2;
181829e796fdSEric W. Biederman 	}
181929e796fdSEric W. Biederman 	*prevp = table;
182023eb06deSEric W. Biederman 	header->ctl_table_arg = table;
182129e796fdSEric W. Biederman 
182229e796fdSEric W. Biederman 	INIT_LIST_HEAD(&header->ctl_entry);
182329e796fdSEric W. Biederman 	header->used = 0;
182429e796fdSEric W. Biederman 	header->unregistering = NULL;
1825e51b6ba0SEric W. Biederman 	header->root = root;
182629e796fdSEric W. Biederman 	sysctl_set_parent(NULL, header->ctl_table);
1827f7e6ced4SAl Viro 	header->count = 1;
182888f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1829e51b6ba0SEric W. Biederman 	if (sysctl_check_table(namespaces, header->ctl_table)) {
183029e796fdSEric W. Biederman 		kfree(header);
1831fc6cd25bSEric W. Biederman 		return NULL;
1832fc6cd25bSEric W. Biederman 	}
183388f458e4SHolger Schurig #endif
1834330d57fbSAl Viro 	spin_lock(&sysctl_lock);
183573455092SAl Viro 	header->set = lookup_header_set(root, namespaces);
1836ae7edeccSAl Viro 	header->attached_by = header->ctl_table;
1837ae7edeccSAl Viro 	header->attached_to = root_table;
1838ae7edeccSAl Viro 	header->parent = &root_table_header;
1839ae7edeccSAl Viro 	for (set = header->set; set; set = set->parent) {
1840ae7edeccSAl Viro 		struct ctl_table_header *p;
1841ae7edeccSAl Viro 		list_for_each_entry(p, &set->list, ctl_entry) {
1842ae7edeccSAl Viro 			if (p->unregistering)
1843ae7edeccSAl Viro 				continue;
1844ae7edeccSAl Viro 			try_attach(p, header);
1845ae7edeccSAl Viro 		}
1846ae7edeccSAl Viro 	}
1847ae7edeccSAl Viro 	header->parent->count++;
184873455092SAl Viro 	list_add_tail(&header->ctl_entry, &header->set->list);
1849330d57fbSAl Viro 	spin_unlock(&sysctl_lock);
185029e796fdSEric W. Biederman 
185129e796fdSEric W. Biederman 	return header;
185229e796fdSEric W. Biederman }
185329e796fdSEric W. Biederman 
185429e796fdSEric W. Biederman /**
1855e51b6ba0SEric W. Biederman  * register_sysctl_table_path - register a sysctl table hierarchy
1856e51b6ba0SEric W. Biederman  * @path: The path to the directory the sysctl table is in.
1857e51b6ba0SEric W. Biederman  * @table: the top-level table structure
1858e51b6ba0SEric W. Biederman  *
1859e51b6ba0SEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1860e51b6ba0SEric W. Biederman  * array. A completely 0 filled entry terminates the table.
1861e51b6ba0SEric W. Biederman  *
1862e51b6ba0SEric W. Biederman  * See __register_sysctl_paths for more details.
1863e51b6ba0SEric W. Biederman  */
1864e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1865e51b6ba0SEric W. Biederman 						struct ctl_table *table)
1866e51b6ba0SEric W. Biederman {
1867e51b6ba0SEric W. Biederman 	return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1868e51b6ba0SEric W. Biederman 					path, table);
1869e51b6ba0SEric W. Biederman }
1870e51b6ba0SEric W. Biederman 
1871e51b6ba0SEric W. Biederman /**
187229e796fdSEric W. Biederman  * register_sysctl_table - register a sysctl table hierarchy
187329e796fdSEric W. Biederman  * @table: the top-level table structure
187429e796fdSEric W. Biederman  *
187529e796fdSEric W. Biederman  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
187629e796fdSEric W. Biederman  * array. A completely 0 filled entry terminates the table.
187729e796fdSEric W. Biederman  *
187829e796fdSEric W. Biederman  * See register_sysctl_paths for more details.
187929e796fdSEric W. Biederman  */
188029e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
188129e796fdSEric W. Biederman {
188229e796fdSEric W. Biederman 	static const struct ctl_path null_path[] = { {} };
188329e796fdSEric W. Biederman 
188429e796fdSEric W. Biederman 	return register_sysctl_paths(null_path, table);
18851da177e4SLinus Torvalds }
18861da177e4SLinus Torvalds 
18871da177e4SLinus Torvalds /**
18881da177e4SLinus Torvalds  * unregister_sysctl_table - unregister a sysctl table hierarchy
18891da177e4SLinus Torvalds  * @header: the header returned from register_sysctl_table
18901da177e4SLinus Torvalds  *
18911da177e4SLinus Torvalds  * Unregisters the sysctl table and all children. proc entries may not
18921da177e4SLinus Torvalds  * actually be removed until they are no longer used by anyone.
18931da177e4SLinus Torvalds  */
18941da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header)
18951da177e4SLinus Torvalds {
1896330d57fbSAl Viro 	might_sleep();
1897f1dad166SPavel Emelyanov 
1898f1dad166SPavel Emelyanov 	if (header == NULL)
1899f1dad166SPavel Emelyanov 		return;
1900f1dad166SPavel Emelyanov 
1901330d57fbSAl Viro 	spin_lock(&sysctl_lock);
1902330d57fbSAl Viro 	start_unregistering(header);
1903ae7edeccSAl Viro 	if (!--header->parent->count) {
1904ae7edeccSAl Viro 		WARN_ON(1);
1905ae7edeccSAl Viro 		kfree(header->parent);
1906ae7edeccSAl Viro 	}
1907f7e6ced4SAl Viro 	if (!--header->count)
19081da177e4SLinus Torvalds 		kfree(header);
1909f7e6ced4SAl Viro 	spin_unlock(&sysctl_lock);
19101da177e4SLinus Torvalds }
19111da177e4SLinus Torvalds 
19129043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p)
19139043476fSAl Viro {
19149043476fSAl Viro 	struct ctl_table_set *set = p->set;
19159043476fSAl Viro 	int res;
19169043476fSAl Viro 	spin_lock(&sysctl_lock);
19179043476fSAl Viro 	if (p->unregistering)
19189043476fSAl Viro 		res = 0;
19199043476fSAl Viro 	else if (!set->is_seen)
19209043476fSAl Viro 		res = 1;
19219043476fSAl Viro 	else
19229043476fSAl Viro 		res = set->is_seen(set);
19239043476fSAl Viro 	spin_unlock(&sysctl_lock);
19249043476fSAl Viro 	return res;
19259043476fSAl Viro }
19269043476fSAl Viro 
192773455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
192873455092SAl Viro 	struct ctl_table_set *parent,
192973455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
193073455092SAl Viro {
193173455092SAl Viro 	INIT_LIST_HEAD(&p->list);
193273455092SAl Viro 	p->parent = parent ? parent : &sysctl_table_root.default_set;
193373455092SAl Viro 	p->is_seen = is_seen;
193473455092SAl Viro }
193573455092SAl Viro 
1936b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */
1937d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1938b89a8171SEric W. Biederman {
1939b89a8171SEric W. Biederman 	return NULL;
1940b89a8171SEric W. Biederman }
1941b89a8171SEric W. Biederman 
194229e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
194329e796fdSEric W. Biederman 						    struct ctl_table *table)
194429e796fdSEric W. Biederman {
194529e796fdSEric W. Biederman 	return NULL;
194629e796fdSEric W. Biederman }
194729e796fdSEric W. Biederman 
1948b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table)
1949b89a8171SEric W. Biederman {
1950b89a8171SEric W. Biederman }
1951b89a8171SEric W. Biederman 
195273455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p,
195373455092SAl Viro 	struct ctl_table_set *parent,
195473455092SAl Viro 	int (*is_seen)(struct ctl_table_set *))
195573455092SAl Viro {
195673455092SAl Viro }
195773455092SAl Viro 
1958f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head)
1959f7e6ced4SAl Viro {
1960f7e6ced4SAl Viro }
1961f7e6ced4SAl Viro 
1962b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
1963b89a8171SEric W. Biederman 
19641da177e4SLinus Torvalds /*
19651da177e4SLinus Torvalds  * /proc/sys support
19661da177e4SLinus Torvalds  */
19671da177e4SLinus Torvalds 
1968b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL
19691da177e4SLinus Torvalds 
1970b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write,
19718d65af78SAlexey Dobriyan 			   void __user *buffer,
1972b1ba4dddSAdrian Bunk 			   size_t *lenp, loff_t *ppos)
1973f5dd3d6fSSam Vilain {
1974f5dd3d6fSSam Vilain 	size_t len;
1975f5dd3d6fSSam Vilain 	char __user *p;
1976f5dd3d6fSSam Vilain 	char c;
1977f5dd3d6fSSam Vilain 
19788d060877SOleg Nesterov 	if (!data || !maxlen || !*lenp) {
1979f5dd3d6fSSam Vilain 		*lenp = 0;
1980f5dd3d6fSSam Vilain 		return 0;
1981f5dd3d6fSSam Vilain 	}
1982f5dd3d6fSSam Vilain 
1983f5dd3d6fSSam Vilain 	if (write) {
1984f5dd3d6fSSam Vilain 		len = 0;
1985f5dd3d6fSSam Vilain 		p = buffer;
1986f5dd3d6fSSam Vilain 		while (len < *lenp) {
1987f5dd3d6fSSam Vilain 			if (get_user(c, p++))
1988f5dd3d6fSSam Vilain 				return -EFAULT;
1989f5dd3d6fSSam Vilain 			if (c == 0 || c == '\n')
1990f5dd3d6fSSam Vilain 				break;
1991f5dd3d6fSSam Vilain 			len++;
1992f5dd3d6fSSam Vilain 		}
1993f5dd3d6fSSam Vilain 		if (len >= maxlen)
1994f5dd3d6fSSam Vilain 			len = maxlen-1;
1995f5dd3d6fSSam Vilain 		if(copy_from_user(data, buffer, len))
1996f5dd3d6fSSam Vilain 			return -EFAULT;
1997f5dd3d6fSSam Vilain 		((char *) data)[len] = 0;
1998f5dd3d6fSSam Vilain 		*ppos += *lenp;
1999f5dd3d6fSSam Vilain 	} else {
2000f5dd3d6fSSam Vilain 		len = strlen(data);
2001f5dd3d6fSSam Vilain 		if (len > maxlen)
2002f5dd3d6fSSam Vilain 			len = maxlen;
20038d060877SOleg Nesterov 
20048d060877SOleg Nesterov 		if (*ppos > len) {
20058d060877SOleg Nesterov 			*lenp = 0;
20068d060877SOleg Nesterov 			return 0;
20078d060877SOleg Nesterov 		}
20088d060877SOleg Nesterov 
20098d060877SOleg Nesterov 		data += *ppos;
20108d060877SOleg Nesterov 		len  -= *ppos;
20118d060877SOleg Nesterov 
2012f5dd3d6fSSam Vilain 		if (len > *lenp)
2013f5dd3d6fSSam Vilain 			len = *lenp;
2014f5dd3d6fSSam Vilain 		if (len)
2015f5dd3d6fSSam Vilain 			if(copy_to_user(buffer, data, len))
2016f5dd3d6fSSam Vilain 				return -EFAULT;
2017f5dd3d6fSSam Vilain 		if (len < *lenp) {
2018f5dd3d6fSSam Vilain 			if(put_user('\n', ((char __user *) buffer) + len))
2019f5dd3d6fSSam Vilain 				return -EFAULT;
2020f5dd3d6fSSam Vilain 			len++;
2021f5dd3d6fSSam Vilain 		}
2022f5dd3d6fSSam Vilain 		*lenp = len;
2023f5dd3d6fSSam Vilain 		*ppos += len;
2024f5dd3d6fSSam Vilain 	}
2025f5dd3d6fSSam Vilain 	return 0;
2026f5dd3d6fSSam Vilain }
2027f5dd3d6fSSam Vilain 
20281da177e4SLinus Torvalds /**
20291da177e4SLinus Torvalds  * proc_dostring - read a string sysctl
20301da177e4SLinus Torvalds  * @table: the sysctl table
20311da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
20321da177e4SLinus Torvalds  * @buffer: the user buffer
20331da177e4SLinus Torvalds  * @lenp: the size of the user buffer
20341da177e4SLinus Torvalds  * @ppos: file position
20351da177e4SLinus Torvalds  *
20361da177e4SLinus Torvalds  * Reads/writes a string from/to the user buffer. If the kernel
20371da177e4SLinus Torvalds  * buffer provided is not large enough to hold the string, the
20381da177e4SLinus Torvalds  * string is truncated. The copied string is %NULL-terminated.
20391da177e4SLinus Torvalds  * If the string is being read by the user process, it is copied
20401da177e4SLinus Torvalds  * and a newline '\n' is added. It is truncated if the buffer is
20411da177e4SLinus Torvalds  * not large enough.
20421da177e4SLinus Torvalds  *
20431da177e4SLinus Torvalds  * Returns 0 on success.
20441da177e4SLinus Torvalds  */
20458d65af78SAlexey Dobriyan int proc_dostring(struct ctl_table *table, int write,
20461da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
20471da177e4SLinus Torvalds {
20488d65af78SAlexey Dobriyan 	return _proc_do_string(table->data, table->maxlen, write,
2049f5dd3d6fSSam Vilain 			       buffer, lenp, ppos);
20501da177e4SLinus Torvalds }
20511da177e4SLinus Torvalds 
20521da177e4SLinus Torvalds 
20531da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
20541da177e4SLinus Torvalds 				 int *valp,
20551da177e4SLinus Torvalds 				 int write, void *data)
20561da177e4SLinus Torvalds {
20571da177e4SLinus Torvalds 	if (write) {
20581da177e4SLinus Torvalds 		*valp = *negp ? -*lvalp : *lvalp;
20591da177e4SLinus Torvalds 	} else {
20601da177e4SLinus Torvalds 		int val = *valp;
20611da177e4SLinus Torvalds 		if (val < 0) {
20621da177e4SLinus Torvalds 			*negp = -1;
20631da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
20641da177e4SLinus Torvalds 		} else {
20651da177e4SLinus Torvalds 			*negp = 0;
20661da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
20671da177e4SLinus Torvalds 		}
20681da177e4SLinus Torvalds 	}
20691da177e4SLinus Torvalds 	return 0;
20701da177e4SLinus Torvalds }
20711da177e4SLinus Torvalds 
2072d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
20738d65af78SAlexey Dobriyan 		  int write, void __user *buffer,
2074fcfbd547SKirill Korotaev 		  size_t *lenp, loff_t *ppos,
20751da177e4SLinus Torvalds 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
20761da177e4SLinus Torvalds 			      int write, void *data),
20771da177e4SLinus Torvalds 		  void *data)
20781da177e4SLinus Torvalds {
20791da177e4SLinus Torvalds #define TMPBUFLEN 21
20807338f299SSukanto Ghosh 	int *i, vleft, first = 1, neg;
20811da177e4SLinus Torvalds 	unsigned long lval;
20821da177e4SLinus Torvalds 	size_t left, len;
20831da177e4SLinus Torvalds 
20841da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
20851da177e4SLinus Torvalds 	char __user *s = buffer;
20861da177e4SLinus Torvalds 
2087fcfbd547SKirill Korotaev 	if (!tbl_data || !table->maxlen || !*lenp ||
20881da177e4SLinus Torvalds 	    (*ppos && !write)) {
20891da177e4SLinus Torvalds 		*lenp = 0;
20901da177e4SLinus Torvalds 		return 0;
20911da177e4SLinus Torvalds 	}
20921da177e4SLinus Torvalds 
2093fcfbd547SKirill Korotaev 	i = (int *) tbl_data;
20941da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(*i);
20951da177e4SLinus Torvalds 	left = *lenp;
20961da177e4SLinus Torvalds 
20971da177e4SLinus Torvalds 	if (!conv)
20981da177e4SLinus Torvalds 		conv = do_proc_dointvec_conv;
20991da177e4SLinus Torvalds 
21001da177e4SLinus Torvalds 	for (; left && vleft--; i++, first=0) {
21011da177e4SLinus Torvalds 		if (write) {
21021da177e4SLinus Torvalds 			while (left) {
21031da177e4SLinus Torvalds 				char c;
21041da177e4SLinus Torvalds 				if (get_user(c, s))
21051da177e4SLinus Torvalds 					return -EFAULT;
21061da177e4SLinus Torvalds 				if (!isspace(c))
21071da177e4SLinus Torvalds 					break;
21081da177e4SLinus Torvalds 				left--;
21091da177e4SLinus Torvalds 				s++;
21101da177e4SLinus Torvalds 			}
21111da177e4SLinus Torvalds 			if (!left)
21121da177e4SLinus Torvalds 				break;
21131da177e4SLinus Torvalds 			neg = 0;
21141da177e4SLinus Torvalds 			len = left;
21151da177e4SLinus Torvalds 			if (len > sizeof(buf) - 1)
21161da177e4SLinus Torvalds 				len = sizeof(buf) - 1;
21171da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
21181da177e4SLinus Torvalds 				return -EFAULT;
21191da177e4SLinus Torvalds 			buf[len] = 0;
21201da177e4SLinus Torvalds 			p = buf;
21211da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
21221da177e4SLinus Torvalds 				neg = 1;
2123bd9b0bacSBP, Praveen 				p++;
21241da177e4SLinus Torvalds 			}
21251da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
21261da177e4SLinus Torvalds 				break;
21271da177e4SLinus Torvalds 
21281da177e4SLinus Torvalds 			lval = simple_strtoul(p, &p, 0);
21291da177e4SLinus Torvalds 
21301da177e4SLinus Torvalds 			len = p-buf;
21311da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
21321da177e4SLinus Torvalds 				break;
21331da177e4SLinus Torvalds 			s += len;
21341da177e4SLinus Torvalds 			left -= len;
21351da177e4SLinus Torvalds 
21361da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 1, data))
21371da177e4SLinus Torvalds 				break;
21381da177e4SLinus Torvalds 		} else {
21391da177e4SLinus Torvalds 			p = buf;
21401da177e4SLinus Torvalds 			if (!first)
21411da177e4SLinus Torvalds 				*p++ = '\t';
21421da177e4SLinus Torvalds 
21431da177e4SLinus Torvalds 			if (conv(&neg, &lval, i, 0, data))
21441da177e4SLinus Torvalds 				break;
21451da177e4SLinus Torvalds 
21461da177e4SLinus Torvalds 			sprintf(p, "%s%lu", neg ? "-" : "", lval);
21471da177e4SLinus Torvalds 			len = strlen(buf);
21481da177e4SLinus Torvalds 			if (len > left)
21491da177e4SLinus Torvalds 				len = left;
21501da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
21511da177e4SLinus Torvalds 				return -EFAULT;
21521da177e4SLinus Torvalds 			left -= len;
21531da177e4SLinus Torvalds 			s += len;
21541da177e4SLinus Torvalds 		}
21551da177e4SLinus Torvalds 	}
21561da177e4SLinus Torvalds 
21571da177e4SLinus Torvalds 	if (!write && !first && left) {
21581da177e4SLinus Torvalds 		if(put_user('\n', s))
21591da177e4SLinus Torvalds 			return -EFAULT;
21601da177e4SLinus Torvalds 		left--, s++;
21611da177e4SLinus Torvalds 	}
21621da177e4SLinus Torvalds 	if (write) {
21631da177e4SLinus Torvalds 		while (left) {
21641da177e4SLinus Torvalds 			char c;
21651da177e4SLinus Torvalds 			if (get_user(c, s++))
21661da177e4SLinus Torvalds 				return -EFAULT;
21671da177e4SLinus Torvalds 			if (!isspace(c))
21681da177e4SLinus Torvalds 				break;
21691da177e4SLinus Torvalds 			left--;
21701da177e4SLinus Torvalds 		}
21711da177e4SLinus Torvalds 	}
21721da177e4SLinus Torvalds 	if (write && first)
21731da177e4SLinus Torvalds 		return -EINVAL;
21741da177e4SLinus Torvalds 	*lenp -= left;
21751da177e4SLinus Torvalds 	*ppos += *lenp;
21761da177e4SLinus Torvalds 	return 0;
21771da177e4SLinus Torvalds #undef TMPBUFLEN
21781da177e4SLinus Torvalds }
21791da177e4SLinus Torvalds 
21808d65af78SAlexey Dobriyan static int do_proc_dointvec(struct ctl_table *table, int write,
2181fcfbd547SKirill Korotaev 		  void __user *buffer, size_t *lenp, loff_t *ppos,
2182fcfbd547SKirill Korotaev 		  int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2183fcfbd547SKirill Korotaev 			      int write, void *data),
2184fcfbd547SKirill Korotaev 		  void *data)
2185fcfbd547SKirill Korotaev {
21868d65af78SAlexey Dobriyan 	return __do_proc_dointvec(table->data, table, write,
2187fcfbd547SKirill Korotaev 			buffer, lenp, ppos, conv, data);
2188fcfbd547SKirill Korotaev }
2189fcfbd547SKirill Korotaev 
21901da177e4SLinus Torvalds /**
21911da177e4SLinus Torvalds  * proc_dointvec - read a vector of integers
21921da177e4SLinus Torvalds  * @table: the sysctl table
21931da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
21941da177e4SLinus Torvalds  * @buffer: the user buffer
21951da177e4SLinus Torvalds  * @lenp: the size of the user buffer
21961da177e4SLinus Torvalds  * @ppos: file position
21971da177e4SLinus Torvalds  *
21981da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
21991da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
22001da177e4SLinus Torvalds  *
22011da177e4SLinus Torvalds  * Returns 0 on success.
22021da177e4SLinus Torvalds  */
22038d65af78SAlexey Dobriyan int proc_dointvec(struct ctl_table *table, int write,
22041da177e4SLinus Torvalds 		     void __user *buffer, size_t *lenp, loff_t *ppos)
22051da177e4SLinus Torvalds {
22068d65af78SAlexey Dobriyan     return do_proc_dointvec(table,write,buffer,lenp,ppos,
22071da177e4SLinus Torvalds 		    	    NULL,NULL);
22081da177e4SLinus Torvalds }
22091da177e4SLinus Torvalds 
221034f5a398STheodore Ts'o /*
221134f5a398STheodore Ts'o  * Taint values can only be increased
221225ddbb18SAndi Kleen  * This means we can safely use a temporary.
221334f5a398STheodore Ts'o  */
22148d65af78SAlexey Dobriyan static int proc_taint(struct ctl_table *table, int write,
221534f5a398STheodore Ts'o 			       void __user *buffer, size_t *lenp, loff_t *ppos)
221634f5a398STheodore Ts'o {
221725ddbb18SAndi Kleen 	struct ctl_table t;
221825ddbb18SAndi Kleen 	unsigned long tmptaint = get_taint();
221925ddbb18SAndi Kleen 	int err;
222034f5a398STheodore Ts'o 
222191fcd412SBastian Blank 	if (write && !capable(CAP_SYS_ADMIN))
222234f5a398STheodore Ts'o 		return -EPERM;
222334f5a398STheodore Ts'o 
222425ddbb18SAndi Kleen 	t = *table;
222525ddbb18SAndi Kleen 	t.data = &tmptaint;
22268d65af78SAlexey Dobriyan 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
222725ddbb18SAndi Kleen 	if (err < 0)
222825ddbb18SAndi Kleen 		return err;
222925ddbb18SAndi Kleen 
223025ddbb18SAndi Kleen 	if (write) {
223125ddbb18SAndi Kleen 		/*
223225ddbb18SAndi Kleen 		 * Poor man's atomic or. Not worth adding a primitive
223325ddbb18SAndi Kleen 		 * to everyone's atomic.h for this
223425ddbb18SAndi Kleen 		 */
223525ddbb18SAndi Kleen 		int i;
223625ddbb18SAndi Kleen 		for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
223725ddbb18SAndi Kleen 			if ((tmptaint >> i) & 1)
223825ddbb18SAndi Kleen 				add_taint(i);
223925ddbb18SAndi Kleen 		}
224025ddbb18SAndi Kleen 	}
224125ddbb18SAndi Kleen 
224225ddbb18SAndi Kleen 	return err;
224334f5a398STheodore Ts'o }
224434f5a398STheodore Ts'o 
22451da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param {
22461da177e4SLinus Torvalds 	int *min;
22471da177e4SLinus Torvalds 	int *max;
22481da177e4SLinus Torvalds };
22491da177e4SLinus Torvalds 
22501da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
22511da177e4SLinus Torvalds 					int *valp,
22521da177e4SLinus Torvalds 					int write, void *data)
22531da177e4SLinus Torvalds {
22541da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param *param = data;
22551da177e4SLinus Torvalds 	if (write) {
22561da177e4SLinus Torvalds 		int val = *negp ? -*lvalp : *lvalp;
22571da177e4SLinus Torvalds 		if ((param->min && *param->min > val) ||
22581da177e4SLinus Torvalds 		    (param->max && *param->max < val))
22591da177e4SLinus Torvalds 			return -EINVAL;
22601da177e4SLinus Torvalds 		*valp = val;
22611da177e4SLinus Torvalds 	} else {
22621da177e4SLinus Torvalds 		int val = *valp;
22631da177e4SLinus Torvalds 		if (val < 0) {
22641da177e4SLinus Torvalds 			*negp = -1;
22651da177e4SLinus Torvalds 			*lvalp = (unsigned long)-val;
22661da177e4SLinus Torvalds 		} else {
22671da177e4SLinus Torvalds 			*negp = 0;
22681da177e4SLinus Torvalds 			*lvalp = (unsigned long)val;
22691da177e4SLinus Torvalds 		}
22701da177e4SLinus Torvalds 	}
22711da177e4SLinus Torvalds 	return 0;
22721da177e4SLinus Torvalds }
22731da177e4SLinus Torvalds 
22741da177e4SLinus Torvalds /**
22751da177e4SLinus Torvalds  * proc_dointvec_minmax - read a vector of integers with min/max values
22761da177e4SLinus Torvalds  * @table: the sysctl table
22771da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
22781da177e4SLinus Torvalds  * @buffer: the user buffer
22791da177e4SLinus Torvalds  * @lenp: the size of the user buffer
22801da177e4SLinus Torvalds  * @ppos: file position
22811da177e4SLinus Torvalds  *
22821da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
22831da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
22841da177e4SLinus Torvalds  *
22851da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
22861da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
22871da177e4SLinus Torvalds  *
22881da177e4SLinus Torvalds  * Returns 0 on success.
22891da177e4SLinus Torvalds  */
22908d65af78SAlexey Dobriyan int proc_dointvec_minmax(struct ctl_table *table, int write,
22911da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
22921da177e4SLinus Torvalds {
22931da177e4SLinus Torvalds 	struct do_proc_dointvec_minmax_conv_param param = {
22941da177e4SLinus Torvalds 		.min = (int *) table->extra1,
22951da177e4SLinus Torvalds 		.max = (int *) table->extra2,
22961da177e4SLinus Torvalds 	};
22978d65af78SAlexey Dobriyan 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
22981da177e4SLinus Torvalds 				do_proc_dointvec_minmax_conv, &param);
22991da177e4SLinus Torvalds }
23001da177e4SLinus Torvalds 
2301d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
23021da177e4SLinus Torvalds 				     void __user *buffer,
23031da177e4SLinus Torvalds 				     size_t *lenp, loff_t *ppos,
23041da177e4SLinus Torvalds 				     unsigned long convmul,
23051da177e4SLinus Torvalds 				     unsigned long convdiv)
23061da177e4SLinus Torvalds {
23071da177e4SLinus Torvalds #define TMPBUFLEN 21
23081da177e4SLinus Torvalds 	unsigned long *i, *min, *max, val;
23091da177e4SLinus Torvalds 	int vleft, first=1, neg;
23101da177e4SLinus Torvalds 	size_t len, left;
23111da177e4SLinus Torvalds 	char buf[TMPBUFLEN], *p;
23121da177e4SLinus Torvalds 	char __user *s = buffer;
23131da177e4SLinus Torvalds 
2314fcfbd547SKirill Korotaev 	if (!data || !table->maxlen || !*lenp ||
23151da177e4SLinus Torvalds 	    (*ppos && !write)) {
23161da177e4SLinus Torvalds 		*lenp = 0;
23171da177e4SLinus Torvalds 		return 0;
23181da177e4SLinus Torvalds 	}
23191da177e4SLinus Torvalds 
2320fcfbd547SKirill Korotaev 	i = (unsigned long *) data;
23211da177e4SLinus Torvalds 	min = (unsigned long *) table->extra1;
23221da177e4SLinus Torvalds 	max = (unsigned long *) table->extra2;
23231da177e4SLinus Torvalds 	vleft = table->maxlen / sizeof(unsigned long);
23241da177e4SLinus Torvalds 	left = *lenp;
23251da177e4SLinus Torvalds 
23261da177e4SLinus Torvalds 	for (; left && vleft--; i++, min++, max++, first=0) {
23271da177e4SLinus Torvalds 		if (write) {
23281da177e4SLinus Torvalds 			while (left) {
23291da177e4SLinus Torvalds 				char c;
23301da177e4SLinus Torvalds 				if (get_user(c, s))
23311da177e4SLinus Torvalds 					return -EFAULT;
23321da177e4SLinus Torvalds 				if (!isspace(c))
23331da177e4SLinus Torvalds 					break;
23341da177e4SLinus Torvalds 				left--;
23351da177e4SLinus Torvalds 				s++;
23361da177e4SLinus Torvalds 			}
23371da177e4SLinus Torvalds 			if (!left)
23381da177e4SLinus Torvalds 				break;
23391da177e4SLinus Torvalds 			neg = 0;
23401da177e4SLinus Torvalds 			len = left;
23411da177e4SLinus Torvalds 			if (len > TMPBUFLEN-1)
23421da177e4SLinus Torvalds 				len = TMPBUFLEN-1;
23431da177e4SLinus Torvalds 			if (copy_from_user(buf, s, len))
23441da177e4SLinus Torvalds 				return -EFAULT;
23451da177e4SLinus Torvalds 			buf[len] = 0;
23461da177e4SLinus Torvalds 			p = buf;
23471da177e4SLinus Torvalds 			if (*p == '-' && left > 1) {
23481da177e4SLinus Torvalds 				neg = 1;
2349bd9b0bacSBP, Praveen 				p++;
23501da177e4SLinus Torvalds 			}
23511da177e4SLinus Torvalds 			if (*p < '0' || *p > '9')
23521da177e4SLinus Torvalds 				break;
23531da177e4SLinus Torvalds 			val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
23541da177e4SLinus Torvalds 			len = p-buf;
23551da177e4SLinus Torvalds 			if ((len < left) && *p && !isspace(*p))
23561da177e4SLinus Torvalds 				break;
23571da177e4SLinus Torvalds 			if (neg)
23581da177e4SLinus Torvalds 				val = -val;
23591da177e4SLinus Torvalds 			s += len;
23601da177e4SLinus Torvalds 			left -= len;
23611da177e4SLinus Torvalds 
23621da177e4SLinus Torvalds 			if(neg)
23631da177e4SLinus Torvalds 				continue;
23641da177e4SLinus Torvalds 			if ((min && val < *min) || (max && val > *max))
23651da177e4SLinus Torvalds 				continue;
23661da177e4SLinus Torvalds 			*i = val;
23671da177e4SLinus Torvalds 		} else {
23681da177e4SLinus Torvalds 			p = buf;
23691da177e4SLinus Torvalds 			if (!first)
23701da177e4SLinus Torvalds 				*p++ = '\t';
23711da177e4SLinus Torvalds 			sprintf(p, "%lu", convdiv * (*i) / convmul);
23721da177e4SLinus Torvalds 			len = strlen(buf);
23731da177e4SLinus Torvalds 			if (len > left)
23741da177e4SLinus Torvalds 				len = left;
23751da177e4SLinus Torvalds 			if(copy_to_user(s, buf, len))
23761da177e4SLinus Torvalds 				return -EFAULT;
23771da177e4SLinus Torvalds 			left -= len;
23781da177e4SLinus Torvalds 			s += len;
23791da177e4SLinus Torvalds 		}
23801da177e4SLinus Torvalds 	}
23811da177e4SLinus Torvalds 
23821da177e4SLinus Torvalds 	if (!write && !first && left) {
23831da177e4SLinus Torvalds 		if(put_user('\n', s))
23841da177e4SLinus Torvalds 			return -EFAULT;
23851da177e4SLinus Torvalds 		left--, s++;
23861da177e4SLinus Torvalds 	}
23871da177e4SLinus Torvalds 	if (write) {
23881da177e4SLinus Torvalds 		while (left) {
23891da177e4SLinus Torvalds 			char c;
23901da177e4SLinus Torvalds 			if (get_user(c, s++))
23911da177e4SLinus Torvalds 				return -EFAULT;
23921da177e4SLinus Torvalds 			if (!isspace(c))
23931da177e4SLinus Torvalds 				break;
23941da177e4SLinus Torvalds 			left--;
23951da177e4SLinus Torvalds 		}
23961da177e4SLinus Torvalds 	}
23971da177e4SLinus Torvalds 	if (write && first)
23981da177e4SLinus Torvalds 		return -EINVAL;
23991da177e4SLinus Torvalds 	*lenp -= left;
24001da177e4SLinus Torvalds 	*ppos += *lenp;
24011da177e4SLinus Torvalds 	return 0;
24021da177e4SLinus Torvalds #undef TMPBUFLEN
24031da177e4SLinus Torvalds }
24041da177e4SLinus Torvalds 
2405d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2406fcfbd547SKirill Korotaev 				     void __user *buffer,
2407fcfbd547SKirill Korotaev 				     size_t *lenp, loff_t *ppos,
2408fcfbd547SKirill Korotaev 				     unsigned long convmul,
2409fcfbd547SKirill Korotaev 				     unsigned long convdiv)
2410fcfbd547SKirill Korotaev {
2411fcfbd547SKirill Korotaev 	return __do_proc_doulongvec_minmax(table->data, table, write,
24128d65af78SAlexey Dobriyan 			buffer, lenp, ppos, convmul, convdiv);
2413fcfbd547SKirill Korotaev }
2414fcfbd547SKirill Korotaev 
24151da177e4SLinus Torvalds /**
24161da177e4SLinus Torvalds  * proc_doulongvec_minmax - read a vector of long integers with min/max values
24171da177e4SLinus Torvalds  * @table: the sysctl table
24181da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
24191da177e4SLinus Torvalds  * @buffer: the user buffer
24201da177e4SLinus Torvalds  * @lenp: the size of the user buffer
24211da177e4SLinus Torvalds  * @ppos: file position
24221da177e4SLinus Torvalds  *
24231da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
24241da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
24251da177e4SLinus Torvalds  *
24261da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
24271da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
24281da177e4SLinus Torvalds  *
24291da177e4SLinus Torvalds  * Returns 0 on success.
24301da177e4SLinus Torvalds  */
24318d65af78SAlexey Dobriyan int proc_doulongvec_minmax(struct ctl_table *table, int write,
24321da177e4SLinus Torvalds 			   void __user *buffer, size_t *lenp, loff_t *ppos)
24331da177e4SLinus Torvalds {
24348d65af78SAlexey Dobriyan     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
24351da177e4SLinus Torvalds }
24361da177e4SLinus Torvalds 
24371da177e4SLinus Torvalds /**
24381da177e4SLinus Torvalds  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
24391da177e4SLinus Torvalds  * @table: the sysctl table
24401da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
24411da177e4SLinus Torvalds  * @buffer: the user buffer
24421da177e4SLinus Torvalds  * @lenp: the size of the user buffer
24431da177e4SLinus Torvalds  * @ppos: file position
24441da177e4SLinus Torvalds  *
24451da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
24461da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string. The values
24471da177e4SLinus Torvalds  * are treated as milliseconds, and converted to jiffies when they are stored.
24481da177e4SLinus Torvalds  *
24491da177e4SLinus Torvalds  * This routine will ensure the values are within the range specified by
24501da177e4SLinus Torvalds  * table->extra1 (min) and table->extra2 (max).
24511da177e4SLinus Torvalds  *
24521da177e4SLinus Torvalds  * Returns 0 on success.
24531da177e4SLinus Torvalds  */
2454d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
24551da177e4SLinus Torvalds 				      void __user *buffer,
24561da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
24571da177e4SLinus Torvalds {
24588d65af78SAlexey Dobriyan     return do_proc_doulongvec_minmax(table, write, buffer,
24591da177e4SLinus Torvalds 				     lenp, ppos, HZ, 1000l);
24601da177e4SLinus Torvalds }
24611da177e4SLinus Torvalds 
24621da177e4SLinus Torvalds 
24631da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
24641da177e4SLinus Torvalds 					 int *valp,
24651da177e4SLinus Torvalds 					 int write, void *data)
24661da177e4SLinus Torvalds {
24671da177e4SLinus Torvalds 	if (write) {
2468cba9f33dSBart Samwel 		if (*lvalp > LONG_MAX / HZ)
2469cba9f33dSBart Samwel 			return 1;
24701da177e4SLinus Torvalds 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
24711da177e4SLinus Torvalds 	} else {
24721da177e4SLinus Torvalds 		int val = *valp;
24731da177e4SLinus Torvalds 		unsigned long lval;
24741da177e4SLinus Torvalds 		if (val < 0) {
24751da177e4SLinus Torvalds 			*negp = -1;
24761da177e4SLinus Torvalds 			lval = (unsigned long)-val;
24771da177e4SLinus Torvalds 		} else {
24781da177e4SLinus Torvalds 			*negp = 0;
24791da177e4SLinus Torvalds 			lval = (unsigned long)val;
24801da177e4SLinus Torvalds 		}
24811da177e4SLinus Torvalds 		*lvalp = lval / HZ;
24821da177e4SLinus Torvalds 	}
24831da177e4SLinus Torvalds 	return 0;
24841da177e4SLinus Torvalds }
24851da177e4SLinus Torvalds 
24861da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
24871da177e4SLinus Torvalds 						int *valp,
24881da177e4SLinus Torvalds 						int write, void *data)
24891da177e4SLinus Torvalds {
24901da177e4SLinus Torvalds 	if (write) {
2491cba9f33dSBart Samwel 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2492cba9f33dSBart Samwel 			return 1;
24931da177e4SLinus Torvalds 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
24941da177e4SLinus Torvalds 	} else {
24951da177e4SLinus Torvalds 		int val = *valp;
24961da177e4SLinus Torvalds 		unsigned long lval;
24971da177e4SLinus Torvalds 		if (val < 0) {
24981da177e4SLinus Torvalds 			*negp = -1;
24991da177e4SLinus Torvalds 			lval = (unsigned long)-val;
25001da177e4SLinus Torvalds 		} else {
25011da177e4SLinus Torvalds 			*negp = 0;
25021da177e4SLinus Torvalds 			lval = (unsigned long)val;
25031da177e4SLinus Torvalds 		}
25041da177e4SLinus Torvalds 		*lvalp = jiffies_to_clock_t(lval);
25051da177e4SLinus Torvalds 	}
25061da177e4SLinus Torvalds 	return 0;
25071da177e4SLinus Torvalds }
25081da177e4SLinus Torvalds 
25091da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
25101da177e4SLinus Torvalds 					    int *valp,
25111da177e4SLinus Torvalds 					    int write, void *data)
25121da177e4SLinus Torvalds {
25131da177e4SLinus Torvalds 	if (write) {
25141da177e4SLinus Torvalds 		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
25151da177e4SLinus Torvalds 	} else {
25161da177e4SLinus Torvalds 		int val = *valp;
25171da177e4SLinus Torvalds 		unsigned long lval;
25181da177e4SLinus Torvalds 		if (val < 0) {
25191da177e4SLinus Torvalds 			*negp = -1;
25201da177e4SLinus Torvalds 			lval = (unsigned long)-val;
25211da177e4SLinus Torvalds 		} else {
25221da177e4SLinus Torvalds 			*negp = 0;
25231da177e4SLinus Torvalds 			lval = (unsigned long)val;
25241da177e4SLinus Torvalds 		}
25251da177e4SLinus Torvalds 		*lvalp = jiffies_to_msecs(lval);
25261da177e4SLinus Torvalds 	}
25271da177e4SLinus Torvalds 	return 0;
25281da177e4SLinus Torvalds }
25291da177e4SLinus Torvalds 
25301da177e4SLinus Torvalds /**
25311da177e4SLinus Torvalds  * proc_dointvec_jiffies - read a vector of integers as seconds
25321da177e4SLinus Torvalds  * @table: the sysctl table
25331da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
25341da177e4SLinus Torvalds  * @buffer: the user buffer
25351da177e4SLinus Torvalds  * @lenp: the size of the user buffer
25361da177e4SLinus Torvalds  * @ppos: file position
25371da177e4SLinus Torvalds  *
25381da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
25391da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
25401da177e4SLinus Torvalds  * The values read are assumed to be in seconds, and are converted into
25411da177e4SLinus Torvalds  * jiffies.
25421da177e4SLinus Torvalds  *
25431da177e4SLinus Torvalds  * Returns 0 on success.
25441da177e4SLinus Torvalds  */
25458d65af78SAlexey Dobriyan int proc_dointvec_jiffies(struct ctl_table *table, int write,
25461da177e4SLinus Torvalds 			  void __user *buffer, size_t *lenp, loff_t *ppos)
25471da177e4SLinus Torvalds {
25488d65af78SAlexey Dobriyan     return do_proc_dointvec(table,write,buffer,lenp,ppos,
25491da177e4SLinus Torvalds 		    	    do_proc_dointvec_jiffies_conv,NULL);
25501da177e4SLinus Torvalds }
25511da177e4SLinus Torvalds 
25521da177e4SLinus Torvalds /**
25531da177e4SLinus Torvalds  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
25541da177e4SLinus Torvalds  * @table: the sysctl table
25551da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
25561da177e4SLinus Torvalds  * @buffer: the user buffer
25571da177e4SLinus Torvalds  * @lenp: the size of the user buffer
25581e5d5331SRandy Dunlap  * @ppos: pointer to the file position
25591da177e4SLinus Torvalds  *
25601da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
25611da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
25621da177e4SLinus Torvalds  * The values read are assumed to be in 1/USER_HZ seconds, and
25631da177e4SLinus Torvalds  * are converted into jiffies.
25641da177e4SLinus Torvalds  *
25651da177e4SLinus Torvalds  * Returns 0 on success.
25661da177e4SLinus Torvalds  */
25678d65af78SAlexey Dobriyan int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
25681da177e4SLinus Torvalds 				 void __user *buffer, size_t *lenp, loff_t *ppos)
25691da177e4SLinus Torvalds {
25708d65af78SAlexey Dobriyan     return do_proc_dointvec(table,write,buffer,lenp,ppos,
25711da177e4SLinus Torvalds 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
25721da177e4SLinus Torvalds }
25731da177e4SLinus Torvalds 
25741da177e4SLinus Torvalds /**
25751da177e4SLinus Torvalds  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
25761da177e4SLinus Torvalds  * @table: the sysctl table
25771da177e4SLinus Torvalds  * @write: %TRUE if this is a write to the sysctl file
25781da177e4SLinus Torvalds  * @buffer: the user buffer
25791da177e4SLinus Torvalds  * @lenp: the size of the user buffer
258067be2dd1SMartin Waitz  * @ppos: file position
258167be2dd1SMartin Waitz  * @ppos: the current position in the file
25821da177e4SLinus Torvalds  *
25831da177e4SLinus Torvalds  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
25841da177e4SLinus Torvalds  * values from/to the user buffer, treated as an ASCII string.
25851da177e4SLinus Torvalds  * The values read are assumed to be in 1/1000 seconds, and
25861da177e4SLinus Torvalds  * are converted into jiffies.
25871da177e4SLinus Torvalds  *
25881da177e4SLinus Torvalds  * Returns 0 on success.
25891da177e4SLinus Torvalds  */
25908d65af78SAlexey Dobriyan int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
25911da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
25921da177e4SLinus Torvalds {
25938d65af78SAlexey Dobriyan 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
25941da177e4SLinus Torvalds 				do_proc_dointvec_ms_jiffies_conv, NULL);
25951da177e4SLinus Torvalds }
25961da177e4SLinus Torvalds 
25978d65af78SAlexey Dobriyan static int proc_do_cad_pid(struct ctl_table *table, int write,
25989ec52099SCedric Le Goater 			   void __user *buffer, size_t *lenp, loff_t *ppos)
25999ec52099SCedric Le Goater {
26009ec52099SCedric Le Goater 	struct pid *new_pid;
26019ec52099SCedric Le Goater 	pid_t tmp;
26029ec52099SCedric Le Goater 	int r;
26039ec52099SCedric Le Goater 
26046c5f3e7bSPavel Emelyanov 	tmp = pid_vnr(cad_pid);
26059ec52099SCedric Le Goater 
26068d65af78SAlexey Dobriyan 	r = __do_proc_dointvec(&tmp, table, write, buffer,
26079ec52099SCedric Le Goater 			       lenp, ppos, NULL, NULL);
26089ec52099SCedric Le Goater 	if (r || !write)
26099ec52099SCedric Le Goater 		return r;
26109ec52099SCedric Le Goater 
26119ec52099SCedric Le Goater 	new_pid = find_get_pid(tmp);
26129ec52099SCedric Le Goater 	if (!new_pid)
26139ec52099SCedric Le Goater 		return -ESRCH;
26149ec52099SCedric Le Goater 
26159ec52099SCedric Le Goater 	put_pid(xchg(&cad_pid, new_pid));
26169ec52099SCedric Le Goater 	return 0;
26179ec52099SCedric Le Goater }
26189ec52099SCedric Le Goater 
26191da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */
26201da177e4SLinus Torvalds 
26218d65af78SAlexey Dobriyan int proc_dostring(struct ctl_table *table, int write,
26221da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
26231da177e4SLinus Torvalds {
26241da177e4SLinus Torvalds 	return -ENOSYS;
26251da177e4SLinus Torvalds }
26261da177e4SLinus Torvalds 
26278d65af78SAlexey Dobriyan int proc_dointvec(struct ctl_table *table, int write,
26281da177e4SLinus Torvalds 		  void __user *buffer, size_t *lenp, loff_t *ppos)
26291da177e4SLinus Torvalds {
26301da177e4SLinus Torvalds 	return -ENOSYS;
26311da177e4SLinus Torvalds }
26321da177e4SLinus Torvalds 
26338d65af78SAlexey Dobriyan int proc_dointvec_minmax(struct ctl_table *table, int write,
26341da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26351da177e4SLinus Torvalds {
26361da177e4SLinus Torvalds 	return -ENOSYS;
26371da177e4SLinus Torvalds }
26381da177e4SLinus Torvalds 
26398d65af78SAlexey Dobriyan int proc_dointvec_jiffies(struct ctl_table *table, int write,
26401da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26411da177e4SLinus Torvalds {
26421da177e4SLinus Torvalds 	return -ENOSYS;
26431da177e4SLinus Torvalds }
26441da177e4SLinus Torvalds 
26458d65af78SAlexey Dobriyan int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
26461da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26471da177e4SLinus Torvalds {
26481da177e4SLinus Torvalds 	return -ENOSYS;
26491da177e4SLinus Torvalds }
26501da177e4SLinus Torvalds 
26518d65af78SAlexey Dobriyan int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
26521da177e4SLinus Torvalds 			     void __user *buffer, size_t *lenp, loff_t *ppos)
26531da177e4SLinus Torvalds {
26541da177e4SLinus Torvalds 	return -ENOSYS;
26551da177e4SLinus Torvalds }
26561da177e4SLinus Torvalds 
26578d65af78SAlexey Dobriyan int proc_doulongvec_minmax(struct ctl_table *table, int write,
26581da177e4SLinus Torvalds 		    void __user *buffer, size_t *lenp, loff_t *ppos)
26591da177e4SLinus Torvalds {
26601da177e4SLinus Torvalds 	return -ENOSYS;
26611da177e4SLinus Torvalds }
26621da177e4SLinus Torvalds 
2663d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
26641da177e4SLinus Torvalds 				      void __user *buffer,
26651da177e4SLinus Torvalds 				      size_t *lenp, loff_t *ppos)
26661da177e4SLinus Torvalds {
26671da177e4SLinus Torvalds     return -ENOSYS;
26681da177e4SLinus Torvalds }
26691da177e4SLinus Torvalds 
26701da177e4SLinus Torvalds 
26711da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */
26721da177e4SLinus Torvalds 
26731da177e4SLinus Torvalds /*
26741da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
26751da177e4SLinus Torvalds  * exception granted :-)
26761da177e4SLinus Torvalds  */
26771da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
26781da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
26791da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
26801da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
26811da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
26821da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
26831da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
26841da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
26851da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table);
268629e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths);
26871da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table);
2688