blob: ea468b1232ac39385d46e59e7200d6a32409a4e0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040059#include <linux/kmod.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#include <asm/uaccess.h>
62#include <asm/processor.h>
63
Andi Kleen29cbc782006-09-30 01:47:55 +020064#ifdef CONFIG_X86
65#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010066#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010067#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020068#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080069#ifdef CONFIG_BSD_PROCESS_ACCT
70#include <linux/acct.h>
71#endif
Dave Young4f0e0562010-03-10 15:24:09 -080072#ifdef CONFIG_RT_MUTEXES
73#include <linux/rtmutex.h>
74#endif
Dave Young2edf5e42010-03-10 15:24:10 -080075#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
76#include <linux/lockdep.h>
77#endif
Dave Young15485a42010-03-10 15:24:07 -080078#ifdef CONFIG_CHR_DEV_SG
79#include <scsi/sg.h>
80#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020081
Don Zickus58687ac2010-05-07 17:11:44 -040082#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050083#include <linux/nmi.h>
84#endif
85
Eric W. Biederman7058cb02007-10-18 03:05:58 -070086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#if defined(CONFIG_SYSCTL)
88
89/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090extern int sysctl_overcommit_memory;
91extern int sysctl_overcommit_ratio;
92extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070094extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070096extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int pid_max;
98extern int min_free_kbytes;
Arve Hjønnevåg83de7312009-02-17 14:51:02 -080099extern int min_free_order_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -0800101extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800102extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200103extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100104extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400105extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000106#ifndef CONFIG_MMU
107extern int sysctl_nr_trim_pages;
108#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200109#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200110extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400114#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200116static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117#endif
118
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700120static int __maybe_unused one = 1;
121static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700122static int __maybe_unused three = 3;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800123static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700125#ifdef CONFIG_PRINTK
126static int ten_thousand = 10000;
127#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700129/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
130static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
133static int maxolduid = 65535;
134static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800135static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137static int ngroups_max = NGROUPS_MAX;
138
Dave Youngd14f1722010-02-25 20:28:57 -0500139#ifdef CONFIG_INOTIFY_USER
140#include <linux/inotify.h>
141#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700142#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700143#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#endif
145
David S. Miller08714202008-11-16 23:49:24 -0800146#ifdef CONFIG_SPARC64
147extern int sysctl_tsb_ratio;
148#endif
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#ifdef __hppa__
151extern int pwrsw_enabled;
152extern int unaligned_enabled;
153#endif
154
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800155#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#ifdef CONFIG_MATHEMU
157extern int sysctl_ieee_emulation_warnings;
158#endif
159extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700160extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#endif
162
Jes Sorensend2b176e2006-02-28 09:42:23 -0800163#ifdef CONFIG_IA64
164extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800165extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800166#endif
167
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700168#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700171static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800172 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700173#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700174
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700175#ifdef CONFIG_PRINTK
176static int proc_dmesg_restrict(struct ctl_table *table, int write,
177 void __user *buffer, size_t *lenp, loff_t *ppos);
178#endif
179
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700180#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800181/* Note: sysrq code uses it's own private copy */
182static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700183
184static int sysrq_sysctl_handler(ctl_table *table, int write,
185 void __user *buffer, size_t *lenp,
186 loff_t *ppos)
187{
188 int error;
189
190 error = proc_dointvec(table, write, buffer, lenp, ppos);
191 if (error)
192 return error;
193
194 if (write)
195 sysrq_toggle_support(__sysrq_enabled);
196
197 return 0;
198}
199
200#endif
201
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700202static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100203static struct ctl_table_root sysctl_table_root;
204static struct ctl_table_header root_table_header = {
Al Virodfef6dc2011-03-08 01:25:28 -0500205 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100206 .ctl_table = root_table,
Al Virodfef6dc2011-03-08 01:25:28 -0500207 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100208 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400209 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100210};
211static struct ctl_table_root sysctl_table_root = {
212 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400213 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100214};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700216static struct ctl_table kern_table[];
217static struct ctl_table vm_table[];
218static struct ctl_table fs_table[];
219static struct ctl_table debug_table[];
220static struct ctl_table dev_table[];
221extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800222#ifdef CONFIG_EPOLL
223extern struct ctl_table epoll_table[];
224#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
227int sysctl_legacy_va_layout;
228#endif
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/* The default sysctl tables: */
231
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700232static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 .procname = "kernel",
235 .mode = 0555,
236 .child = kern_table,
237 },
238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .procname = "vm",
240 .mode = 0555,
241 .child = vm_table,
242 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .procname = "fs",
245 .mode = 0555,
246 .child = fs_table,
247 },
248 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 .procname = "debug",
250 .mode = 0555,
251 .child = debug_table,
252 },
253 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 .procname = "dev",
255 .mode = 0555,
256 .child = dev_table,
257 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700258 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259};
260
Ingo Molnar77e54a12007-07-09 18:52:00 +0200261#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100262static int min_sched_granularity_ns = 100000; /* 100 usecs */
263static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
264static int min_wakeup_granularity_ns; /* 0 usecs */
265static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100266static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
267static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268#endif
269
Mel Gorman5e771902010-05-24 14:32:31 -0700270#ifdef CONFIG_COMPACTION
271static int min_extfrag_threshold;
272static int max_extfrag_threshold = 1000;
273#endif
274
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700275static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200276 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800281 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200282 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283#ifdef CONFIG_SCHED_DEBUG
284 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100285 .procname = "sched_min_granularity_ns",
286 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800289 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 },
293 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200294 .procname = "sched_latency_ns",
295 .data = &sysctl_sched_latency,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
301 },
302 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200303 .procname = "sched_wakeup_granularity_ns",
304 .data = &sysctl_sched_wakeup_granularity,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200308 .extra1 = &min_wakeup_granularity_ns,
309 .extra2 = &max_wakeup_granularity_ns,
310 },
311 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
315 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800316 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200319 },
320 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200321 .procname = "sched_migration_cost",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800325 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200326 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100327 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100328 .procname = "sched_nr_migrate",
329 .data = &sysctl_sched_nr_migrate,
330 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100331 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800332 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100333 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530334 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200335 .procname = "sched_time_avg",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800339 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200340 },
341 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800342 .procname = "sched_shares_window",
343 .data = &sysctl_sched_shares_window,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
346 .proc_handler = proc_dointvec,
347 },
348 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800353 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530354 .extra1 = &zero,
355 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530356 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200357#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200358 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100359 .procname = "sched_rt_period_us",
360 .data = &sysctl_sched_rt_period,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 },
365 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100366 .procname = "sched_rt_runtime_us",
367 .data = &sysctl_sched_rt_runtime,
368 .maxlen = sizeof(int),
369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800370 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100371 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100372#ifdef CONFIG_SCHED_AUTOGROUP
373 {
374 .procname = "sched_autogroup_enabled",
375 .data = &sysctl_sched_autogroup_enabled,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800378 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100379 .extra1 = &zero,
380 .extra2 = &one,
381 },
382#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700383#ifdef CONFIG_PROVE_LOCKING
384 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700385 .procname = "prove_locking",
386 .data = &prove_locking,
387 .maxlen = sizeof(int),
388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800389 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700390 },
391#endif
392#ifdef CONFIG_LOCK_STAT
393 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700394 .procname = "lock_stat",
395 .data = &lock_stat,
396 .maxlen = sizeof(int),
397 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800398 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700399 },
400#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .procname = "panic",
403 .data = &panic_timeout,
404 .maxlen = sizeof(int),
405 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800406 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 },
408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .procname = "core_uses_pid",
410 .data = &core_uses_pid,
411 .maxlen = sizeof(int),
412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800413 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 },
415 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .procname = "core_pattern",
417 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700418 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800420 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 },
Neil Hormana2939802009-09-23 15:56:56 -0700422 {
Neil Hormana2939802009-09-23 15:56:56 -0700423 .procname = "core_pipe_limit",
424 .data = &core_pipe_limit,
425 .maxlen = sizeof(unsigned int),
426 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800427 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700428 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800429#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700432 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800434 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800436#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100437#ifdef CONFIG_LATENCYTOP
438 {
439 .procname = "latencytop",
440 .data = &latencytop_enabled,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100444 },
445#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#ifdef CONFIG_BLK_DEV_INITRD
447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 .procname = "real-root-dev",
449 .data = &real_root_dev,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800452 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 },
454#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700455 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700456 .procname = "print-fatal-signals",
457 .data = &print_fatal_signals,
458 .maxlen = sizeof(int),
459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800460 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700461 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700462#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "reboot-cmd",
465 .data = reboot_command,
466 .maxlen = 256,
467 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800468 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 .procname = "stop-a",
472 .data = &stop_a_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800475 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 },
477 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 .procname = "scons-poweroff",
479 .data = &scons_pwroff,
480 .maxlen = sizeof (int),
481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800482 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 },
484#endif
David S. Miller08714202008-11-16 23:49:24 -0800485#ifdef CONFIG_SPARC64
486 {
David S. Miller08714202008-11-16 23:49:24 -0800487 .procname = "tsb-ratio",
488 .data = &sysctl_tsb_ratio,
489 .maxlen = sizeof (int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800492 },
493#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494#ifdef __hppa__
495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "soft-power",
497 .data = &pwrsw_enabled,
498 .maxlen = sizeof (int),
499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800500 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 },
502 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 .procname = "unaligned-trap",
504 .data = &unaligned_enabled,
505 .maxlen = sizeof (int),
506 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800507 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 },
509#endif
510 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .procname = "ctrl-alt-del",
512 .data = &C_A_D,
513 .maxlen = sizeof(int),
514 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800515 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400517#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200518 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200519 .procname = "ftrace_enabled",
520 .data = &ftrace_enabled,
521 .maxlen = sizeof(int),
522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800523 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200524 },
525#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500526#ifdef CONFIG_STACK_TRACER
527 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500528 .procname = "stack_tracer_enabled",
529 .data = &stack_tracer_enabled,
530 .maxlen = sizeof(int),
531 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800532 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500533 },
534#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400535#ifdef CONFIG_TRACING
536 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100537 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400538 .data = &ftrace_dump_on_oops,
539 .maxlen = sizeof(int),
540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400542 },
543#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200544#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "modprobe",
547 .data = &modprobe_path,
548 .maxlen = KMOD_PATH_LEN,
549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800550 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
Kees Cook3d433212009-04-02 15:49:29 -0700552 {
Kees Cook3d433212009-04-02 15:49:29 -0700553 .procname = "modules_disabled",
554 .data = &modules_disabled,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800558 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700559 .extra1 = &one,
560 .extra2 = &one,
561 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100563#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100566 .data = &uevent_helper,
567 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 },
571#endif
572#ifdef CONFIG_CHR_DEV_SG
573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "sg-big-buff",
575 .data = &sg_big_buff,
576 .maxlen = sizeof (int),
577 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
580#endif
581#ifdef CONFIG_BSD_PROCESS_ACCT
582 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .procname = "acct",
584 .data = &acct_parm,
585 .maxlen = 3*sizeof(int),
586 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800587 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 },
589#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#ifdef CONFIG_MAGIC_SYSRQ
591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800593 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .maxlen = sizeof (int),
595 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700596 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
598#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700599#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700602 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .maxlen = sizeof (int),
604 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800605 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700607#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .procname = "threads-max",
610 .data = &max_threads,
611 .maxlen = sizeof(int),
612 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800613 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 },
615 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .procname = "random",
617 .mode = 0555,
618 .child = random_table,
619 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 {
Eric Paris17f60a72011-04-01 17:07:50 -0400621 .procname = "usermodehelper",
622 .mode = 0555,
623 .child = usermodehelper_table,
624 },
625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .procname = "overflowuid",
627 .data = &overflowuid,
628 .maxlen = sizeof(int),
629 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800630 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .extra1 = &minolduid,
632 .extra2 = &maxolduid,
633 },
634 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 .procname = "overflowgid",
636 .data = &overflowgid,
637 .maxlen = sizeof(int),
638 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800639 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .extra1 = &minolduid,
641 .extra2 = &maxolduid,
642 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800643#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#ifdef CONFIG_MATHEMU
645 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 .procname = "ieee_emulation_warnings",
647 .data = &sysctl_ieee_emulation_warnings,
648 .maxlen = sizeof(int),
649 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800650 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 },
652#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200655 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .maxlen = sizeof(int),
657 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800658 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 },
660#endif
661 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .procname = "pid_max",
663 .data = &pid_max,
664 .maxlen = sizeof (int),
665 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800666 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .extra1 = &pid_max_min,
668 .extra2 = &pid_max_max,
669 },
670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .procname = "panic_on_oops",
672 .data = &panic_on_oops,
673 .maxlen = sizeof(int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800677#if defined CONFIG_PRINTK
678 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800679 .procname = "printk",
680 .data = &console_loglevel,
681 .maxlen = 4*sizeof(int),
682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800684 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700687 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof(int),
689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800690 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
692 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700694 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .maxlen = sizeof(int),
696 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800697 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 },
Dave Youngaf913222009-09-22 16:43:33 -0700699 {
Dave Youngaf913222009-09-22 16:43:33 -0700700 .procname = "printk_delay",
701 .data = &printk_delay_msec,
702 .maxlen = sizeof(int),
703 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800704 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700705 .extra1 = &zero,
706 .extra2 = &ten_thousand,
707 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800709 .procname = "dmesg_restrict",
710 .data = &dmesg_restrict,
711 .maxlen = sizeof(int),
712 .mode = 0644,
713 .proc_handler = proc_dointvec_minmax,
714 .extra1 = &zero,
715 .extra2 = &one,
716 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800717 {
718 .procname = "kptr_restrict",
719 .data = &kptr_restrict,
720 .maxlen = sizeof(int),
721 .mode = 0644,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700722 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800723 .extra1 = &zero,
724 .extra2 = &two,
725 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800726#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .procname = "ngroups_max",
729 .data = &ngroups_max,
730 .maxlen = sizeof (int),
731 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800732 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 },
Don Zickus58687ac2010-05-07 17:11:44 -0400734#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500735 {
Don Zickus58687ac2010-05-07 17:11:44 -0400736 .procname = "watchdog",
737 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500738 .maxlen = sizeof (int),
739 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700740 .proc_handler = proc_dowatchdog,
741 .extra1 = &zero,
742 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400743 },
744 {
745 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700746 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400747 .maxlen = sizeof(int),
748 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700749 .proc_handler = proc_dowatchdog,
Don Zickus58687ac2010-05-07 17:11:44 -0400750 .extra1 = &neg_one,
751 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500752 },
Don Zickus2508ce12010-05-07 17:11:46 -0400753 {
754 .procname = "softlockup_panic",
755 .data = &softlockup_panic,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = proc_dointvec_minmax,
759 .extra1 = &zero,
760 .extra2 = &one,
761 },
Don Zickus5dc30552010-11-29 17:07:17 -0500762 {
763 .procname = "nmi_watchdog",
764 .data = &watchdog_enabled,
765 .maxlen = sizeof (int),
766 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700767 .proc_handler = proc_dowatchdog,
768 .extra1 = &zero,
769 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500770 },
771#endif
772#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
773 {
774 .procname = "unknown_nmi_panic",
775 .data = &unknown_nmi_panic,
776 .maxlen = sizeof (int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec,
779 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500780#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781#if defined(CONFIG_X86)
782 {
Don Zickus8da5add2006-09-26 10:52:27 +0200783 .procname = "panic_on_unrecovered_nmi",
784 .data = &panic_on_unrecovered_nmi,
785 .maxlen = sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200788 },
789 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700790 .procname = "panic_on_io_nmi",
791 .data = &panic_on_io_nmi,
792 .maxlen = sizeof(int),
793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700795 },
796 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .procname = "bootloader_type",
798 .data = &bootloader_type,
799 .maxlen = sizeof (int),
800 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100803 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700804 .procname = "bootloader_version",
805 .data = &bootloader_version,
806 .maxlen = sizeof (int),
807 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700809 },
810 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100811 .procname = "kstack_depth_to_print",
812 .data = &kstack_depth_to_print,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100816 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100817 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100818 .procname = "io_delay_type",
819 .data = &io_delay_type,
820 .maxlen = sizeof(int),
821 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800822 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100823 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800825#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 .procname = "randomize_va_space",
828 .data = &randomize_va_space,
829 .maxlen = sizeof(int),
830 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800831 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800833#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800834#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700835 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700836 .procname = "spin_retry",
837 .data = &spin_retry,
838 .maxlen = sizeof (int),
839 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800840 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700841 },
842#endif
Len Brown673d5b42007-07-28 03:33:16 -0400843#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800844 {
Pavel Machekc255d842006-02-20 18:27:58 -0800845 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700846 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800847 .maxlen = sizeof (unsigned long),
848 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800849 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800850 },
851#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800852#ifdef CONFIG_IA64
853 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800854 .procname = "ignore-unaligned-usertrap",
855 .data = &no_unaligned_warning,
856 .maxlen = sizeof (int),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800859 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800860 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800861 .procname = "unaligned-dump-stack",
862 .data = &unaligned_dump_stack,
863 .maxlen = sizeof (int),
864 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800865 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800866 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800867#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800868#ifdef CONFIG_DETECT_HUNG_TASK
869 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800870 .procname = "hung_task_panic",
871 .data = &sysctl_hung_task_panic,
872 .maxlen = sizeof(int),
873 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800874 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800875 .extra1 = &zero,
876 .extra2 = &one,
877 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100878 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .procname = "hung_task_check_count",
880 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100881 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800883 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100884 },
885 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100886 .procname = "hung_task_timeout_secs",
887 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100888 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100889 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800890 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100891 },
892 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100893 .procname = "hung_task_warnings",
894 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100895 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100896 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800897 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100898 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700899#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200900#ifdef CONFIG_COMPAT
901 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200902 .procname = "compat-log",
903 .data = &compat_log,
904 .maxlen = sizeof (int),
905 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800906 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200907 },
908#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700909#ifdef CONFIG_RT_MUTEXES
910 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700911 .procname = "max_lock_depth",
912 .data = &max_lock_depth,
913 .maxlen = sizeof(int),
914 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800915 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700916 },
917#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700918 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700919 .procname = "poweroff_cmd",
920 .data = &poweroff_cmd,
921 .maxlen = POWEROFF_CMD_PATH_LEN,
922 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800923 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700924 },
David Howells0b77f5b2008-04-29 01:01:32 -0700925#ifdef CONFIG_KEYS
926 {
David Howells0b77f5b2008-04-29 01:01:32 -0700927 .procname = "keys",
928 .mode = 0555,
929 .child = key_sysctls,
930 },
931#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700932#ifdef CONFIG_RCU_TORTURE_TEST
933 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700934 .procname = "rcutorture_runnable",
935 .data = &rcutorture_runnable,
936 .maxlen = sizeof(int),
937 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800938 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700939 },
940#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200941#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -0400942 /*
943 * User-space scripts rely on the existence of this file
944 * as a feature check for perf_events being enabled.
945 *
946 * So it's an ABI, do not remove!
947 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200948 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200949 .procname = "perf_event_paranoid",
950 .data = &sysctl_perf_event_paranoid,
951 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200952 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800953 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200954 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200955 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200956 .procname = "perf_event_mlock_kb",
957 .data = &sysctl_perf_event_mlock,
958 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200959 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800960 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200961 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200962 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200963 .procname = "perf_event_max_sample_rate",
964 .data = &sysctl_perf_event_sample_rate,
965 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200966 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100967 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200968 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200969#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200970#ifdef CONFIG_KMEMCHECK
971 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200972 .procname = "kmemcheck",
973 .data = &kmemcheck_enabled,
974 .maxlen = sizeof(int),
975 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800976 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200977 },
978#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200979#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200980 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200981 .procname = "blk_iopoll",
982 .data = &blk_iopoll_enabled,
983 .maxlen = sizeof(int),
984 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800985 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200986 },
Jens Axboecb684b52009-09-15 21:53:11 +0200987#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700988 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989};
990
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700991static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 .procname = "overcommit_memory",
994 .data = &sysctl_overcommit_memory,
995 .maxlen = sizeof(sysctl_overcommit_memory),
996 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700997 .proc_handler = proc_dointvec_minmax,
998 .extra1 = &zero,
999 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 },
1001 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001002 .procname = "panic_on_oom",
1003 .data = &sysctl_panic_on_oom,
1004 .maxlen = sizeof(sysctl_panic_on_oom),
1005 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001006 .proc_handler = proc_dointvec_minmax,
1007 .extra1 = &zero,
1008 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001009 },
1010 {
David Rientjesfe071d72007-10-16 23:25:56 -07001011 .procname = "oom_kill_allocating_task",
1012 .data = &sysctl_oom_kill_allocating_task,
1013 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1014 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001016 },
1017 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001018 .procname = "oom_dump_tasks",
1019 .data = &sysctl_oom_dump_tasks,
1020 .maxlen = sizeof(sysctl_oom_dump_tasks),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001023 },
1024 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .procname = "overcommit_ratio",
1026 .data = &sysctl_overcommit_ratio,
1027 .maxlen = sizeof(sysctl_overcommit_ratio),
1028 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001029 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 },
1031 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 .procname = "page-cluster",
1033 .data = &page_cluster,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001036 .proc_handler = proc_dointvec_minmax,
1037 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 },
1039 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .procname = "dirty_background_ratio",
1041 .data = &dirty_background_ratio,
1042 .maxlen = sizeof(dirty_background_ratio),
1043 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001044 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 .extra1 = &zero,
1046 .extra2 = &one_hundred,
1047 },
1048 {
David Rientjes2da02992009-01-06 14:39:31 -08001049 .procname = "dirty_background_bytes",
1050 .data = &dirty_background_bytes,
1051 .maxlen = sizeof(dirty_background_bytes),
1052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001054 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001055 },
1056 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 .procname = "dirty_ratio",
1058 .data = &vm_dirty_ratio,
1059 .maxlen = sizeof(vm_dirty_ratio),
1060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 .extra1 = &zero,
1063 .extra2 = &one_hundred,
1064 },
1065 {
David Rientjes2da02992009-01-06 14:39:31 -08001066 .procname = "dirty_bytes",
1067 .data = &vm_dirty_bytes,
1068 .maxlen = sizeof(vm_dirty_bytes),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001071 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001072 },
1073 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001075 .data = &dirty_writeback_interval,
1076 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 },
1080 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001082 .data = &dirty_expire_interval,
1083 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001085 .proc_handler = proc_dointvec_minmax,
1086 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 },
1088 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .procname = "nr_pdflush_threads",
1090 .data = &nr_pdflush_threads,
1091 .maxlen = sizeof nr_pdflush_threads,
1092 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001093 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 },
1095 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .procname = "swappiness",
1097 .data = &vm_swappiness,
1098 .maxlen = sizeof(vm_swappiness),
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 .extra1 = &zero,
1102 .extra2 = &one_hundred,
1103 },
1104#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001105 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001107 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 .maxlen = sizeof(unsigned long),
1109 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001110 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .extra1 = (void *)&hugetlb_zero,
1112 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001113 },
1114#ifdef CONFIG_NUMA
1115 {
1116 .procname = "nr_hugepages_mempolicy",
1117 .data = NULL,
1118 .maxlen = sizeof(unsigned long),
1119 .mode = 0644,
1120 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1121 .extra1 = (void *)&hugetlb_zero,
1122 .extra2 = (void *)&hugetlb_infinity,
1123 },
1124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 .procname = "hugetlb_shm_group",
1127 .data = &sysctl_hugetlb_shm_group,
1128 .maxlen = sizeof(gid_t),
1129 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001130 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 },
Mel Gorman396faf02007-07-17 04:03:13 -07001132 {
Mel Gorman396faf02007-07-17 04:03:13 -07001133 .procname = "hugepages_treat_as_movable",
1134 .data = &hugepages_treat_as_movable,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001137 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001138 },
Adam Litke54f9f802007-10-16 01:26:20 -07001139 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001140 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001141 .data = NULL,
1142 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001143 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001144 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001145 .extra1 = (void *)&hugetlb_zero,
1146 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001147 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148#endif
1149 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 .procname = "lowmem_reserve_ratio",
1151 .data = &sysctl_lowmem_reserve_ratio,
1152 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1153 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001154 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 },
1156 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001157 .procname = "drop_caches",
1158 .data = &sysctl_drop_caches,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001162 .extra1 = &one,
1163 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001164 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001165#ifdef CONFIG_COMPACTION
1166 {
1167 .procname = "compact_memory",
1168 .data = &sysctl_compact_memory,
1169 .maxlen = sizeof(int),
1170 .mode = 0200,
1171 .proc_handler = sysctl_compaction_handler,
1172 },
Mel Gorman5e771902010-05-24 14:32:31 -07001173 {
1174 .procname = "extfrag_threshold",
1175 .data = &sysctl_extfrag_threshold,
1176 .maxlen = sizeof(int),
1177 .mode = 0644,
1178 .proc_handler = sysctl_extfrag_handler,
1179 .extra1 = &min_extfrag_threshold,
1180 .extra2 = &max_extfrag_threshold,
1181 },
1182
Mel Gorman76ab0f52010-05-24 14:32:28 -07001183#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001184 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .procname = "min_free_kbytes",
1186 .data = &min_free_kbytes,
1187 .maxlen = sizeof(min_free_kbytes),
1188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001189 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 .extra1 = &zero,
1191 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001192 {
Arve Hjønnevåg83de7312009-02-17 14:51:02 -08001193 .procname = "min_free_order_shift",
1194 .data = &min_free_order_shift,
1195 .maxlen = sizeof(min_free_order_shift),
1196 .mode = 0644,
1197 .proc_handler = &proc_dointvec
1198 },
1199 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001200 .procname = "percpu_pagelist_fraction",
1201 .data = &percpu_pagelist_fraction,
1202 .maxlen = sizeof(percpu_pagelist_fraction),
1203 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001204 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001205 .extra1 = &min_percpu_pagelist_fract,
1206 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207#ifdef CONFIG_MMU
1208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .procname = "max_map_count",
1210 .data = &sysctl_max_map_count,
1211 .maxlen = sizeof(sysctl_max_map_count),
1212 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001213 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001214 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001216#else
1217 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001218 .procname = "nr_trim_pages",
1219 .data = &sysctl_nr_trim_pages,
1220 .maxlen = sizeof(sysctl_nr_trim_pages),
1221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001222 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001223 .extra1 = &zero,
1224 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225#endif
1226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .procname = "laptop_mode",
1228 .data = &laptop_mode,
1229 .maxlen = sizeof(laptop_mode),
1230 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001231 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 },
1233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 .procname = "block_dump",
1235 .data = &block_dump,
1236 .maxlen = sizeof(block_dump),
1237 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001238 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 .extra1 = &zero,
1240 },
1241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 .procname = "vfs_cache_pressure",
1243 .data = &sysctl_vfs_cache_pressure,
1244 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1245 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001246 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 .extra1 = &zero,
1248 },
1249#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 .procname = "legacy_va_layout",
1252 .data = &sysctl_legacy_va_layout,
1253 .maxlen = sizeof(sysctl_legacy_va_layout),
1254 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001255 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 .extra1 = &zero,
1257 },
1258#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001259#ifdef CONFIG_NUMA
1260 {
Christoph Lameter17436602006-01-18 17:42:32 -08001261 .procname = "zone_reclaim_mode",
1262 .data = &zone_reclaim_mode,
1263 .maxlen = sizeof(zone_reclaim_mode),
1264 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001265 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001266 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001267 },
Christoph Lameter96146342006-07-03 00:24:13 -07001268 {
Christoph Lameter96146342006-07-03 00:24:13 -07001269 .procname = "min_unmapped_ratio",
1270 .data = &sysctl_min_unmapped_ratio,
1271 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001273 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001274 .extra1 = &zero,
1275 .extra2 = &one_hundred,
1276 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001277 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001278 .procname = "min_slab_ratio",
1279 .data = &sysctl_min_slab_ratio,
1280 .maxlen = sizeof(sysctl_min_slab_ratio),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001283 .extra1 = &zero,
1284 .extra2 = &one_hundred,
1285 },
Christoph Lameter17436602006-01-18 17:42:32 -08001286#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001287#ifdef CONFIG_SMP
1288 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001289 .procname = "stat_interval",
1290 .data = &sysctl_stat_interval,
1291 .maxlen = sizeof(sysctl_stat_interval),
1292 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001293 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001294 },
1295#endif
David Howells6e141542009-12-15 19:27:45 +00001296#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001297 {
Eric Parised032182007-06-28 15:55:21 -04001298 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001299 .data = &dac_mmap_min_addr,
1300 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001303 },
David Howells6e141542009-12-15 19:27:45 +00001304#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001305#ifdef CONFIG_NUMA
1306 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001307 .procname = "numa_zonelist_order",
1308 .data = &numa_zonelist_order,
1309 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001312 },
1313#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001314#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001315 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001316 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001317 .procname = "vdso_enabled",
1318 .data = &vdso_enabled,
1319 .maxlen = sizeof(vdso_enabled),
1320 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001321 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001322 .extra1 = &zero,
1323 },
1324#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001325#ifdef CONFIG_HIGHMEM
1326 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001327 .procname = "highmem_is_dirtyable",
1328 .data = &vm_highmem_is_dirtyable,
1329 .maxlen = sizeof(vm_highmem_is_dirtyable),
1330 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001331 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001332 .extra1 = &zero,
1333 .extra2 = &one,
1334 },
1335#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001336 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001337 .procname = "scan_unevictable_pages",
1338 .data = &scan_unevictable_pages,
1339 .maxlen = sizeof(scan_unevictable_pages),
1340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001341 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001342 },
Andi Kleen6a460792009-09-16 11:50:15 +02001343#ifdef CONFIG_MEMORY_FAILURE
1344 {
Andi Kleen6a460792009-09-16 11:50:15 +02001345 .procname = "memory_failure_early_kill",
1346 .data = &sysctl_memory_failure_early_kill,
1347 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001350 .extra1 = &zero,
1351 .extra2 = &one,
1352 },
1353 {
Andi Kleen6a460792009-09-16 11:50:15 +02001354 .procname = "memory_failure_recovery",
1355 .data = &sysctl_memory_failure_recovery,
1356 .maxlen = sizeof(sysctl_memory_failure_recovery),
1357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001358 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001359 .extra1 = &zero,
1360 .extra2 = &one,
1361 },
1362#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001363 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364};
1365
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001366#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001367static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001368 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001369};
1370#endif
1371
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001372static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .procname = "inode-nr",
1375 .data = &inodes_stat,
1376 .maxlen = 2*sizeof(int),
1377 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001378 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 },
1380 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 .procname = "inode-state",
1382 .data = &inodes_stat,
1383 .maxlen = 7*sizeof(int),
1384 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001385 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 },
1387 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .procname = "file-nr",
1389 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001390 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001392 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 },
1394 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .procname = "file-max",
1396 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001397 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001399 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 },
1401 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001402 .procname = "nr_open",
1403 .data = &sysctl_nr_open,
1404 .maxlen = sizeof(int),
1405 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001406 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001407 .extra1 = &sysctl_nr_open_min,
1408 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001409 },
1410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 .procname = "dentry-state",
1412 .data = &dentry_stat,
1413 .maxlen = 6*sizeof(int),
1414 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001415 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 },
1417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "overflowuid",
1419 .data = &fs_overflowuid,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .extra1 = &minolduid,
1424 .extra2 = &maxolduid,
1425 },
1426 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 .procname = "overflowgid",
1428 .data = &fs_overflowgid,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .extra1 = &minolduid,
1433 .extra2 = &maxolduid,
1434 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001435#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 .procname = "leases-enable",
1438 .data = &leases_enable,
1439 .maxlen = sizeof(int),
1440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001443#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444#ifdef CONFIG_DNOTIFY
1445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .procname = "dir-notify-enable",
1447 .data = &dir_notify_enable,
1448 .maxlen = sizeof(int),
1449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001450 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 },
1452#endif
1453#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001454#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .procname = "lease-break-time",
1457 .data = &lease_break_time,
1458 .maxlen = sizeof(int),
1459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001462#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001463#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 .procname = "aio-nr",
1466 .data = &aio_nr,
1467 .maxlen = sizeof(aio_nr),
1468 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001469 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 },
1471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 .procname = "aio-max-nr",
1473 .data = &aio_max_nr,
1474 .maxlen = sizeof(aio_max_nr),
1475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001476 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001478#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001479#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001480 {
Robert Love0399cb02005-07-13 12:38:18 -04001481 .procname = "inotify",
1482 .mode = 0555,
1483 .child = inotify_table,
1484 },
1485#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001486#ifdef CONFIG_EPOLL
1487 {
1488 .procname = "epoll",
1489 .mode = 0555,
1490 .child = epoll_table,
1491 },
1492#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001494 {
Alan Coxd6e71142005-06-23 00:09:43 -07001495 .procname = "suid_dumpable",
1496 .data = &suid_dumpable,
1497 .maxlen = sizeof(int),
1498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001499 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001500 .extra1 = &zero,
1501 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001502 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001503#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1504 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001505 .procname = "binfmt_misc",
1506 .mode = 0555,
1507 .child = binfmt_misc_table,
1508 },
1509#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001510 {
Jens Axboeff9da692010-06-03 14:54:39 +02001511 .procname = "pipe-max-size",
1512 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001513 .maxlen = sizeof(int),
1514 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001515 .proc_handler = &pipe_proc_fn,
1516 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001517 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001518 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519};
1520
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001521static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001522#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
Chris Metcalf571d76a2011-05-16 14:23:44 -04001523 defined(CONFIG_S390) || defined(CONFIG_TILE)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001524 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001525 .procname = "exception-trace",
1526 .data = &show_unhandled_signals,
1527 .maxlen = sizeof(int),
1528 .mode = 0644,
1529 .proc_handler = proc_dointvec
1530 },
1531#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001532#if defined(CONFIG_OPTPROBES)
1533 {
1534 .procname = "kprobes-optimization",
1535 .data = &sysctl_kprobes_optimization,
1536 .maxlen = sizeof(int),
1537 .mode = 0644,
1538 .proc_handler = proc_kprobes_optimization_handler,
1539 .extra1 = &zero,
1540 .extra2 = &one,
1541 },
1542#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001543 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544};
1545
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001546static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001547 { }
Robert Love0eeca282005-07-12 17:06:03 -04001548};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Al Viro330d57f2005-11-04 10:18:40 +00001550static DEFINE_SPINLOCK(sysctl_lock);
1551
1552/* called under sysctl_lock */
1553static int use_table(struct ctl_table_header *p)
1554{
1555 if (unlikely(p->unregistering))
1556 return 0;
1557 p->used++;
1558 return 1;
1559}
1560
1561/* called under sysctl_lock */
1562static void unuse_table(struct ctl_table_header *p)
1563{
1564 if (!--p->used)
1565 if (unlikely(p->unregistering))
1566 complete(p->unregistering);
1567}
1568
1569/* called under sysctl_lock, will reacquire if has to wait */
1570static void start_unregistering(struct ctl_table_header *p)
1571{
1572 /*
1573 * if p->used is 0, nobody will ever touch that entry again;
1574 * we'll eliminate all paths to it before dropping sysctl_lock
1575 */
1576 if (unlikely(p->used)) {
1577 struct completion wait;
1578 init_completion(&wait);
1579 p->unregistering = &wait;
1580 spin_unlock(&sysctl_lock);
1581 wait_for_completion(&wait);
1582 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001583 } else {
1584 /* anything non-NULL; we'll never dereference it */
1585 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001586 }
1587 /*
1588 * do not remove from the list until nobody holds it; walking the
1589 * list in do_sysctl() relies on that.
1590 */
1591 list_del_init(&p->ctl_entry);
1592}
1593
Al Virof7e6ced2008-07-15 01:44:23 -04001594void sysctl_head_get(struct ctl_table_header *head)
1595{
1596 spin_lock(&sysctl_lock);
1597 head->count++;
1598 spin_unlock(&sysctl_lock);
1599}
1600
Al Virodfef6dc2011-03-08 01:25:28 -05001601static void free_head(struct rcu_head *rcu)
1602{
1603 kfree(container_of(rcu, struct ctl_table_header, rcu));
1604}
1605
Al Virof7e6ced2008-07-15 01:44:23 -04001606void sysctl_head_put(struct ctl_table_header *head)
1607{
1608 spin_lock(&sysctl_lock);
1609 if (!--head->count)
Al Virodfef6dc2011-03-08 01:25:28 -05001610 call_rcu(&head->rcu, free_head);
Al Virof7e6ced2008-07-15 01:44:23 -04001611 spin_unlock(&sysctl_lock);
1612}
1613
1614struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1615{
1616 if (!head)
1617 BUG();
1618 spin_lock(&sysctl_lock);
1619 if (!use_table(head))
1620 head = ERR_PTR(-ENOENT);
1621 spin_unlock(&sysctl_lock);
1622 return head;
1623}
1624
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625void sysctl_head_finish(struct ctl_table_header *head)
1626{
1627 if (!head)
1628 return;
1629 spin_lock(&sysctl_lock);
1630 unuse_table(head);
1631 spin_unlock(&sysctl_lock);
1632}
1633
Al Viro73455092008-07-14 21:22:20 -04001634static struct ctl_table_set *
1635lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1636{
1637 struct ctl_table_set *set = &root->default_set;
1638 if (root->lookup)
1639 set = root->lookup(root, namespaces);
1640 return set;
1641}
1642
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001643static struct list_head *
1644lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001645{
Al Viro73455092008-07-14 21:22:20 -04001646 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1647 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001648}
1649
1650struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1651 struct ctl_table_header *prev)
1652{
1653 struct ctl_table_root *root;
1654 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001655 struct ctl_table_header *head;
1656 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001657
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001658 spin_lock(&sysctl_lock);
1659 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001660 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001661 tmp = &prev->ctl_entry;
1662 unuse_table(prev);
1663 goto next;
1664 }
1665 tmp = &root_table_header.ctl_entry;
1666 for (;;) {
1667 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1668
1669 if (!use_table(head))
1670 goto next;
1671 spin_unlock(&sysctl_lock);
1672 return head;
1673 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001674 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001675 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001676 header_list = lookup_header_list(root, namespaces);
1677 if (tmp != header_list)
1678 continue;
1679
1680 do {
1681 root = list_entry(root->root_list.next,
1682 struct ctl_table_root, root_list);
1683 if (root == &sysctl_table_root)
1684 goto out;
1685 header_list = lookup_header_list(root, namespaces);
1686 } while (list_empty(header_list));
1687 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001688 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001689out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001690 spin_unlock(&sysctl_lock);
1691 return NULL;
1692}
1693
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001694struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1695{
1696 return __sysctl_head_next(current->nsproxy, prev);
1697}
1698
1699void register_sysctl_root(struct ctl_table_root *root)
1700{
1701 spin_lock(&sysctl_lock);
1702 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1703 spin_unlock(&sysctl_lock);
1704}
1705
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001707 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 * some sysctl variables are readonly even to root.
1709 */
1710
1711static int test_perm(int mode, int op)
1712{
David Howells76aac0e2008-11-14 10:39:12 +11001713 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 mode >>= 6;
1715 else if (in_egroup_p(0))
1716 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001717 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 return 0;
1719 return -EACCES;
1720}
1721
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001722int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001724 int mode;
1725
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001726 if (root->permissions)
1727 mode = root->permissions(root, current->nsproxy, table);
1728 else
1729 mode = table->mode;
1730
1731 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001734static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1735{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001736 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001737 table->parent = parent;
1738 if (table->child)
1739 sysctl_set_parent(table, table->child);
1740 }
1741}
1742
1743static __init int sysctl_init(void)
1744{
1745 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001746#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001747 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001748#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001749 return 0;
1750}
1751
1752core_initcall(sysctl_init);
1753
Al Virobfbcf032008-07-27 06:31:22 +01001754static struct ctl_table *is_branch_in(struct ctl_table *branch,
1755 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001756{
1757 struct ctl_table *p;
1758 const char *s = branch->procname;
1759
1760 /* branch should have named subdirectory as its first element */
1761 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001762 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001763
1764 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001765 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001766 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001767
1768 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001769 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001770 if (!p->child)
1771 continue;
1772 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001773 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001774 }
Al Virobfbcf032008-07-27 06:31:22 +01001775 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001776}
1777
1778/* see if attaching q to p would be an improvement */
1779static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1780{
1781 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001782 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001783 int is_better = 0;
1784 int not_in_parent = !p->attached_by;
1785
Al Virobfbcf032008-07-27 06:31:22 +01001786 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001787 if (by == q->attached_by)
1788 is_better = 1;
1789 if (to == p->attached_by)
1790 not_in_parent = 1;
1791 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001792 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001793 }
1794
1795 if (is_better && not_in_parent) {
1796 q->attached_by = by;
1797 q->attached_to = to;
1798 q->parent = p;
1799 }
1800}
1801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001803 * __register_sysctl_paths - register a sysctl hierarchy
1804 * @root: List of sysctl headers to register on
1805 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001806 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 *
1809 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001810 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001812 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1815 * enter a sysctl file
1816 *
1817 * data - a pointer to data for use by proc_handler
1818 *
1819 * maxlen - the maximum size in bytes of the data
1820 *
1821 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1822 *
1823 * child - a pointer to the child sysctl table if this entry is a directory, or
1824 * %NULL.
1825 *
1826 * proc_handler - the text handler routine (described below)
1827 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 * de - for internal use by the sysctl routines
1829 *
1830 * extra1, extra2 - extra pointers usable by the proc handler routines
1831 *
1832 * Leaf nodes in the sysctl tree will be represented by a single file
1833 * under /proc; non-leaf nodes will be represented by directories.
1834 *
1835 * sysctl(2) can automatically manage read and write requests through
1836 * the sysctl table. The data and maxlen fields of the ctl_table
1837 * struct enable minimal validation of the values being written to be
1838 * performed, and the mode field allows minimal authentication.
1839 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 * There must be a proc_handler routine for any terminal nodes
1841 * mirrored under /proc/sys (non-terminals are handled by a built-in
1842 * directory handler). Several default handlers are available to
1843 * cover common cases -
1844 *
1845 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1846 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1847 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1848 *
1849 * It is the handler's job to read the input buffer from user memory
1850 * and process it. The handler should return 0 on success.
1851 *
1852 * This routine returns %NULL on a failure to register, and a pointer
1853 * to the table header on success.
1854 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001855struct ctl_table_header *__register_sysctl_paths(
1856 struct ctl_table_root *root,
1857 struct nsproxy *namespaces,
1858 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001860 struct ctl_table_header *header;
1861 struct ctl_table *new, **prevp;
1862 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001863 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864
1865 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001866 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001867 ;
1868
1869 /*
1870 * For each path component, allocate a 2-element ctl_table array.
1871 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001872 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001873 *
1874 * We allocate everything in one go so that we don't have to
1875 * worry about freeing additional memory in unregister_sysctl_table.
1876 */
1877 header = kzalloc(sizeof(struct ctl_table_header) +
1878 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1879 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001881
1882 new = (struct ctl_table *) (header + 1);
1883
1884 /* Now connect the dots */
1885 prevp = &header->ctl_table;
1886 for (n = 0; n < npath; ++n, ++path) {
1887 /* Copy the procname */
1888 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001889 new->mode = 0555;
1890
1891 *prevp = new;
1892 prevp = &new->child;
1893
1894 new += 2;
1895 }
1896 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001897 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001898
1899 INIT_LIST_HEAD(&header->ctl_entry);
1900 header->used = 0;
1901 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001902 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001903 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001904 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001905#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001906 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001907 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001908 return NULL;
1909 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001910#endif
Al Viro330d57f2005-11-04 10:18:40 +00001911 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001912 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001913 header->attached_by = header->ctl_table;
1914 header->attached_to = root_table;
1915 header->parent = &root_table_header;
1916 for (set = header->set; set; set = set->parent) {
1917 struct ctl_table_header *p;
1918 list_for_each_entry(p, &set->list, ctl_entry) {
1919 if (p->unregistering)
1920 continue;
1921 try_attach(p, header);
1922 }
1923 }
1924 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001925 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001926 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001927
1928 return header;
1929}
1930
1931/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001932 * register_sysctl_table_path - register a sysctl table hierarchy
1933 * @path: The path to the directory the sysctl table is in.
1934 * @table: the top-level table structure
1935 *
1936 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1937 * array. A completely 0 filled entry terminates the table.
1938 *
1939 * See __register_sysctl_paths for more details.
1940 */
1941struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1942 struct ctl_table *table)
1943{
1944 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1945 path, table);
1946}
1947
1948/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001949 * register_sysctl_table - register a sysctl table hierarchy
1950 * @table: the top-level table structure
1951 *
1952 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1953 * array. A completely 0 filled entry terminates the table.
1954 *
1955 * See register_sysctl_paths for more details.
1956 */
1957struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1958{
1959 static const struct ctl_path null_path[] = { {} };
1960
1961 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962}
1963
1964/**
1965 * unregister_sysctl_table - unregister a sysctl table hierarchy
1966 * @header: the header returned from register_sysctl_table
1967 *
1968 * Unregisters the sysctl table and all children. proc entries may not
1969 * actually be removed until they are no longer used by anyone.
1970 */
1971void unregister_sysctl_table(struct ctl_table_header * header)
1972{
Al Viro330d57f2005-11-04 10:18:40 +00001973 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001974
1975 if (header == NULL)
1976 return;
1977
Al Viro330d57f2005-11-04 10:18:40 +00001978 spin_lock(&sysctl_lock);
1979 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001980 if (!--header->parent->count) {
1981 WARN_ON(1);
Al Virodfef6dc2011-03-08 01:25:28 -05001982 call_rcu(&header->parent->rcu, free_head);
Al Viroae7edec2008-07-15 06:33:31 -04001983 }
Al Virof7e6ced2008-07-15 01:44:23 -04001984 if (!--header->count)
Al Virodfef6dc2011-03-08 01:25:28 -05001985 call_rcu(&header->rcu, free_head);
Al Viro330d57f2005-11-04 10:18:40 +00001986 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987}
1988
Al Viro90434762008-07-15 08:54:06 -04001989int sysctl_is_seen(struct ctl_table_header *p)
1990{
1991 struct ctl_table_set *set = p->set;
1992 int res;
1993 spin_lock(&sysctl_lock);
1994 if (p->unregistering)
1995 res = 0;
1996 else if (!set->is_seen)
1997 res = 1;
1998 else
1999 res = set->is_seen(set);
2000 spin_unlock(&sysctl_lock);
2001 return res;
2002}
2003
Al Viro73455092008-07-14 21:22:20 -04002004void setup_sysctl_set(struct ctl_table_set *p,
2005 struct ctl_table_set *parent,
2006 int (*is_seen)(struct ctl_table_set *))
2007{
2008 INIT_LIST_HEAD(&p->list);
2009 p->parent = parent ? parent : &sysctl_table_root.default_set;
2010 p->is_seen = is_seen;
2011}
2012
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002013#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002014struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002015{
2016 return NULL;
2017}
2018
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002019struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2020 struct ctl_table *table)
2021{
2022 return NULL;
2023}
2024
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002025void unregister_sysctl_table(struct ctl_table_header * table)
2026{
2027}
2028
Al Viro73455092008-07-14 21:22:20 -04002029void setup_sysctl_set(struct ctl_table_set *p,
2030 struct ctl_table_set *parent,
2031 int (*is_seen)(struct ctl_table_set *))
2032{
2033}
2034
Al Virof7e6ced2008-07-15 01:44:23 -04002035void sysctl_head_put(struct ctl_table_header *head)
2036{
2037}
2038
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002039#endif /* CONFIG_SYSCTL */
2040
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041/*
2042 * /proc/sys support
2043 */
2044
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002045#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002047static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002048 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002049 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002050{
2051 size_t len;
2052 char __user *p;
2053 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002054
2055 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002056 *lenp = 0;
2057 return 0;
2058 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002059
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002060 if (write) {
2061 len = 0;
2062 p = buffer;
2063 while (len < *lenp) {
2064 if (get_user(c, p++))
2065 return -EFAULT;
2066 if (c == 0 || c == '\n')
2067 break;
2068 len++;
2069 }
2070 if (len >= maxlen)
2071 len = maxlen-1;
2072 if(copy_from_user(data, buffer, len))
2073 return -EFAULT;
2074 ((char *) data)[len] = 0;
2075 *ppos += *lenp;
2076 } else {
2077 len = strlen(data);
2078 if (len > maxlen)
2079 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002080
2081 if (*ppos > len) {
2082 *lenp = 0;
2083 return 0;
2084 }
2085
2086 data += *ppos;
2087 len -= *ppos;
2088
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002089 if (len > *lenp)
2090 len = *lenp;
2091 if (len)
2092 if(copy_to_user(buffer, data, len))
2093 return -EFAULT;
2094 if (len < *lenp) {
2095 if(put_user('\n', ((char __user *) buffer) + len))
2096 return -EFAULT;
2097 len++;
2098 }
2099 *lenp = len;
2100 *ppos += len;
2101 }
2102 return 0;
2103}
2104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105/**
2106 * proc_dostring - read a string sysctl
2107 * @table: the sysctl table
2108 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 * @buffer: the user buffer
2110 * @lenp: the size of the user buffer
2111 * @ppos: file position
2112 *
2113 * Reads/writes a string from/to the user buffer. If the kernel
2114 * buffer provided is not large enough to hold the string, the
2115 * string is truncated. The copied string is %NULL-terminated.
2116 * If the string is being read by the user process, it is copied
2117 * and a newline '\n' is added. It is truncated if the buffer is
2118 * not large enough.
2119 *
2120 * Returns 0 on success.
2121 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002122int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 void __user *buffer, size_t *lenp, loff_t *ppos)
2124{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002125 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002126 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127}
2128
Amerigo Wang00b7c332010-05-05 00:26:45 +00002129static size_t proc_skip_spaces(char **buf)
2130{
2131 size_t ret;
2132 char *tmp = skip_spaces(*buf);
2133 ret = tmp - *buf;
2134 *buf = tmp;
2135 return ret;
2136}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002138static void proc_skip_char(char **buf, size_t *size, const char v)
2139{
2140 while (*size) {
2141 if (**buf != v)
2142 break;
2143 (*size)--;
2144 (*buf)++;
2145 }
2146}
2147
Amerigo Wang00b7c332010-05-05 00:26:45 +00002148#define TMPBUFLEN 22
2149/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002150 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002151 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002152 * @buf: a kernel buffer
2153 * @size: size of the kernel buffer
2154 * @val: this is where the number will be stored
2155 * @neg: set to %TRUE if number is negative
2156 * @perm_tr: a vector which contains the allowed trailers
2157 * @perm_tr_len: size of the perm_tr vector
2158 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002159 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002160 * In case of success %0 is returned and @buf and @size are updated with
2161 * the amount of bytes read. If @tr is non-NULL and a trailing
2162 * character exists (size is non-zero after returning from this
2163 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002164 */
2165static int proc_get_long(char **buf, size_t *size,
2166 unsigned long *val, bool *neg,
2167 const char *perm_tr, unsigned perm_tr_len, char *tr)
2168{
2169 int len;
2170 char *p, tmp[TMPBUFLEN];
2171
2172 if (!*size)
2173 return -EINVAL;
2174
2175 len = *size;
2176 if (len > TMPBUFLEN - 1)
2177 len = TMPBUFLEN - 1;
2178
2179 memcpy(tmp, *buf, len);
2180
2181 tmp[len] = 0;
2182 p = tmp;
2183 if (*p == '-' && *size > 1) {
2184 *neg = true;
2185 p++;
2186 } else
2187 *neg = false;
2188 if (!isdigit(*p))
2189 return -EINVAL;
2190
2191 *val = simple_strtoul(p, &p, 0);
2192
2193 len = p - tmp;
2194
2195 /* We don't know if the next char is whitespace thus we may accept
2196 * invalid integers (e.g. 1234...a) or two integers instead of one
2197 * (e.g. 123...1). So lets not allow such large numbers. */
2198 if (len == TMPBUFLEN - 1)
2199 return -EINVAL;
2200
2201 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2202 return -EINVAL;
2203
2204 if (tr && (len < *size))
2205 *tr = *p;
2206
2207 *buf += len;
2208 *size -= len;
2209
2210 return 0;
2211}
2212
2213/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002214 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002215 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002216 * @buf: the user buffer
2217 * @size: the size of the user buffer
2218 * @val: the integer to be converted
2219 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002220 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002221 * In case of success %0 is returned and @buf and @size are updated with
2222 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002223 */
2224static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2225 bool neg)
2226{
2227 int len;
2228 char tmp[TMPBUFLEN], *p = tmp;
2229
2230 sprintf(p, "%s%lu", neg ? "-" : "", val);
2231 len = strlen(tmp);
2232 if (len > *size)
2233 len = *size;
2234 if (copy_to_user(*buf, tmp, len))
2235 return -EFAULT;
2236 *size -= len;
2237 *buf += len;
2238 return 0;
2239}
2240#undef TMPBUFLEN
2241
2242static int proc_put_char(void __user **buf, size_t *size, char c)
2243{
2244 if (*size) {
2245 char __user **buffer = (char __user **)buf;
2246 if (put_user(c, *buffer))
2247 return -EFAULT;
2248 (*size)--, (*buffer)++;
2249 *buf = *buffer;
2250 }
2251 return 0;
2252}
2253
2254static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 int *valp,
2256 int write, void *data)
2257{
2258 if (write) {
2259 *valp = *negp ? -*lvalp : *lvalp;
2260 } else {
2261 int val = *valp;
2262 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *lvalp = (unsigned long)-val;
2265 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002266 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 *lvalp = (unsigned long)val;
2268 }
2269 }
2270 return 0;
2271}
2272
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2274
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002275static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002276 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002277 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002278 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 int write, void *data),
2280 void *data)
2281{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002282 int *i, vleft, first = 1, err = 0;
2283 unsigned long page = 0;
2284 size_t left;
2285 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 *lenp = 0;
2289 return 0;
2290 }
2291
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002292 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 vleft = table->maxlen / sizeof(*i);
2294 left = *lenp;
2295
2296 if (!conv)
2297 conv = do_proc_dointvec_conv;
2298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002300 if (left > PAGE_SIZE - 1)
2301 left = PAGE_SIZE - 1;
2302 page = __get_free_page(GFP_TEMPORARY);
2303 kbuf = (char *) page;
2304 if (!kbuf)
2305 return -ENOMEM;
2306 if (copy_from_user(kbuf, buffer, left)) {
2307 err = -EFAULT;
2308 goto free;
2309 }
2310 kbuf[left] = 0;
2311 }
2312
2313 for (; left && vleft--; i++, first=0) {
2314 unsigned long lval;
2315 bool neg;
2316
2317 if (write) {
2318 left -= proc_skip_spaces(&kbuf);
2319
J. R. Okajima563b0462010-05-25 16:10:14 -07002320 if (!left)
2321 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 err = proc_get_long(&kbuf, &left, &lval, &neg,
2323 proc_wspace_sep,
2324 sizeof(proc_wspace_sep), NULL);
2325 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002327 if (conv(&neg, &lval, i, 1, data)) {
2328 err = -EINVAL;
2329 break;
2330 }
2331 } else {
2332 if (conv(&neg, &lval, i, 0, data)) {
2333 err = -EINVAL;
2334 break;
2335 }
2336 if (!first)
2337 err = proc_put_char(&buffer, &left, '\t');
2338 if (err)
2339 break;
2340 err = proc_put_long(&buffer, &left, lval, neg);
2341 if (err)
2342 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 }
2344 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002345
2346 if (!write && !first && left && !err)
2347 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002348 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002349 left -= proc_skip_spaces(&kbuf);
2350free:
2351 if (write) {
2352 free_page(page);
2353 if (first)
2354 return err ? : -EINVAL;
2355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 *lenp -= left;
2357 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359}
2360
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002361static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002362 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002363 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002364 int write, void *data),
2365 void *data)
2366{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002367 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002368 buffer, lenp, ppos, conv, data);
2369}
2370
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371/**
2372 * proc_dointvec - read a vector of integers
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2378 *
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2381 *
2382 * Returns 0 on success.
2383 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002384int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 void __user *buffer, size_t *lenp, loff_t *ppos)
2386{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002387 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 NULL,NULL);
2389}
2390
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002391/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002392 * Taint values can only be increased
2393 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002394 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002395static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002396 void __user *buffer, size_t *lenp, loff_t *ppos)
2397{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002398 struct ctl_table t;
2399 unsigned long tmptaint = get_taint();
2400 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002401
Bastian Blank91fcd412007-04-23 14:41:14 -07002402 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002403 return -EPERM;
2404
Andi Kleen25ddbb12008-10-15 22:01:41 -07002405 t = *table;
2406 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002407 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002408 if (err < 0)
2409 return err;
2410
2411 if (write) {
2412 /*
2413 * Poor man's atomic or. Not worth adding a primitive
2414 * to everyone's atomic.h for this
2415 */
2416 int i;
2417 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2418 if ((tmptaint >> i) & 1)
2419 add_taint(i);
2420 }
2421 }
2422
2423 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002424}
2425
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002426#ifdef CONFIG_PRINTK
2427static int proc_dmesg_restrict(struct ctl_table *table, int write,
2428 void __user *buffer, size_t *lenp, loff_t *ppos)
2429{
2430 if (write && !capable(CAP_SYS_ADMIN))
2431 return -EPERM;
2432
2433 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2434}
2435#endif
2436
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437struct do_proc_dointvec_minmax_conv_param {
2438 int *min;
2439 int *max;
2440};
2441
Amerigo Wang00b7c332010-05-05 00:26:45 +00002442static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2443 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 int write, void *data)
2445{
2446 struct do_proc_dointvec_minmax_conv_param *param = data;
2447 if (write) {
2448 int val = *negp ? -*lvalp : *lvalp;
2449 if ((param->min && *param->min > val) ||
2450 (param->max && *param->max < val))
2451 return -EINVAL;
2452 *valp = val;
2453 } else {
2454 int val = *valp;
2455 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002456 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 *lvalp = (unsigned long)-val;
2458 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002459 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 *lvalp = (unsigned long)val;
2461 }
2462 }
2463 return 0;
2464}
2465
2466/**
2467 * proc_dointvec_minmax - read a vector of integers with min/max values
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 * @buffer: the user buffer
2471 * @lenp: the size of the user buffer
2472 * @ppos: file position
2473 *
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2476 *
2477 * This routine will ensure the values are within the range specified by
2478 * table->extra1 (min) and table->extra2 (max).
2479 *
2480 * Returns 0 on success.
2481 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002482int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 void __user *buffer, size_t *lenp, loff_t *ppos)
2484{
2485 struct do_proc_dointvec_minmax_conv_param param = {
2486 .min = (int *) table->extra1,
2487 .max = (int *) table->extra2,
2488 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002489 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 do_proc_dointvec_minmax_conv, &param);
2491}
2492
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002493static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 void __user *buffer,
2495 size_t *lenp, loff_t *ppos,
2496 unsigned long convmul,
2497 unsigned long convdiv)
2498{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002499 unsigned long *i, *min, *max;
2500 int vleft, first = 1, err = 0;
2501 unsigned long page = 0;
2502 size_t left;
2503 char *kbuf;
2504
2505 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 *lenp = 0;
2507 return 0;
2508 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002509
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002510 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 min = (unsigned long *) table->extra1;
2512 max = (unsigned long *) table->extra2;
2513 vleft = table->maxlen / sizeof(unsigned long);
2514 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002515
2516 if (write) {
2517 if (left > PAGE_SIZE - 1)
2518 left = PAGE_SIZE - 1;
2519 page = __get_free_page(GFP_TEMPORARY);
2520 kbuf = (char *) page;
2521 if (!kbuf)
2522 return -ENOMEM;
2523 if (copy_from_user(kbuf, buffer, left)) {
2524 err = -EFAULT;
2525 goto free;
2526 }
2527 kbuf[left] = 0;
2528 }
2529
Eric Dumazet27b3d802010-10-07 12:59:29 -07002530 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002531 unsigned long val;
2532
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002534 bool neg;
2535
2536 left -= proc_skip_spaces(&kbuf);
2537
2538 err = proc_get_long(&kbuf, &left, &val, &neg,
2539 proc_wspace_sep,
2540 sizeof(proc_wspace_sep), NULL);
2541 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 break;
2543 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 continue;
2545 if ((min && val < *min) || (max && val > *max))
2546 continue;
2547 *i = val;
2548 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002549 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002551 err = proc_put_char(&buffer, &left, '\t');
2552 err = proc_put_long(&buffer, &left, val, false);
2553 if (err)
2554 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 }
2556 }
2557
Amerigo Wang00b7c332010-05-05 00:26:45 +00002558 if (!write && !first && left && !err)
2559 err = proc_put_char(&buffer, &left, '\n');
2560 if (write && !err)
2561 left -= proc_skip_spaces(&kbuf);
2562free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002564 free_page(page);
2565 if (first)
2566 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 *lenp -= left;
2569 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002570 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002573static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002574 void __user *buffer,
2575 size_t *lenp, loff_t *ppos,
2576 unsigned long convmul,
2577 unsigned long convdiv)
2578{
2579 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002580 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002581}
2582
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583/**
2584 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 * @buffer: the user buffer
2588 * @lenp: the size of the user buffer
2589 * @ppos: file position
2590 *
2591 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2592 * values from/to the user buffer, treated as an ASCII string.
2593 *
2594 * This routine will ensure the values are within the range specified by
2595 * table->extra1 (min) and table->extra2 (max).
2596 *
2597 * Returns 0 on success.
2598 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002599int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 void __user *buffer, size_t *lenp, loff_t *ppos)
2601{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002602 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603}
2604
2605/**
2606 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2607 * @table: the sysctl table
2608 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
2611 * @ppos: file position
2612 *
2613 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2614 * values from/to the user buffer, treated as an ASCII string. The values
2615 * are treated as milliseconds, and converted to jiffies when they are stored.
2616 *
2617 * This routine will ensure the values are within the range specified by
2618 * table->extra1 (min) and table->extra2 (max).
2619 *
2620 * Returns 0 on success.
2621 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002622int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 void __user *buffer,
2624 size_t *lenp, loff_t *ppos)
2625{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002626 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 lenp, ppos, HZ, 1000l);
2628}
2629
2630
Amerigo Wang00b7c332010-05-05 00:26:45 +00002631static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 int *valp,
2633 int write, void *data)
2634{
2635 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002636 if (*lvalp > LONG_MAX / HZ)
2637 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2639 } else {
2640 int val = *valp;
2641 unsigned long lval;
2642 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002643 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 lval = (unsigned long)-val;
2645 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002646 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 lval = (unsigned long)val;
2648 }
2649 *lvalp = lval / HZ;
2650 }
2651 return 0;
2652}
2653
Amerigo Wang00b7c332010-05-05 00:26:45 +00002654static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 int *valp,
2656 int write, void *data)
2657{
2658 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002659 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2660 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2662 } else {
2663 int val = *valp;
2664 unsigned long lval;
2665 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002666 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 lval = (unsigned long)-val;
2668 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002669 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 lval = (unsigned long)val;
2671 }
2672 *lvalp = jiffies_to_clock_t(lval);
2673 }
2674 return 0;
2675}
2676
Amerigo Wang00b7c332010-05-05 00:26:45 +00002677static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 int *valp,
2679 int write, void *data)
2680{
2681 if (write) {
2682 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2683 } else {
2684 int val = *valp;
2685 unsigned long lval;
2686 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002687 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 lval = (unsigned long)-val;
2689 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002690 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 lval = (unsigned long)val;
2692 }
2693 *lvalp = jiffies_to_msecs(lval);
2694 }
2695 return 0;
2696}
2697
2698/**
2699 * proc_dointvec_jiffies - read a vector of integers as seconds
2700 * @table: the sysctl table
2701 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 * @buffer: the user buffer
2703 * @lenp: the size of the user buffer
2704 * @ppos: file position
2705 *
2706 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2707 * values from/to the user buffer, treated as an ASCII string.
2708 * The values read are assumed to be in seconds, and are converted into
2709 * jiffies.
2710 *
2711 * Returns 0 on success.
2712 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002713int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 void __user *buffer, size_t *lenp, loff_t *ppos)
2715{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002716 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 do_proc_dointvec_jiffies_conv,NULL);
2718}
2719
2720/**
2721 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2722 * @table: the sysctl table
2723 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 * @buffer: the user buffer
2725 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002726 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 *
2728 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2729 * values from/to the user buffer, treated as an ASCII string.
2730 * The values read are assumed to be in 1/USER_HZ seconds, and
2731 * are converted into jiffies.
2732 *
2733 * Returns 0 on success.
2734 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 void __user *buffer, size_t *lenp, loff_t *ppos)
2737{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002738 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 do_proc_dointvec_userhz_jiffies_conv,NULL);
2740}
2741
2742/**
2743 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2744 * @table: the sysctl table
2745 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 * @buffer: the user buffer
2747 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002748 * @ppos: file position
2749 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 *
2751 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2752 * values from/to the user buffer, treated as an ASCII string.
2753 * The values read are assumed to be in 1/1000 seconds, and
2754 * are converted into jiffies.
2755 *
2756 * Returns 0 on success.
2757 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002758int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 void __user *buffer, size_t *lenp, loff_t *ppos)
2760{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002761 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 do_proc_dointvec_ms_jiffies_conv, NULL);
2763}
2764
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002765static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002766 void __user *buffer, size_t *lenp, loff_t *ppos)
2767{
2768 struct pid *new_pid;
2769 pid_t tmp;
2770 int r;
2771
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002772 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002773
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002774 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002775 lenp, ppos, NULL, NULL);
2776 if (r || !write)
2777 return r;
2778
2779 new_pid = find_get_pid(tmp);
2780 if (!new_pid)
2781 return -ESRCH;
2782
2783 put_pid(xchg(&cad_pid, new_pid));
2784 return 0;
2785}
2786
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002787/**
2788 * proc_do_large_bitmap - read/write from/to a large bitmap
2789 * @table: the sysctl table
2790 * @write: %TRUE if this is a write to the sysctl file
2791 * @buffer: the user buffer
2792 * @lenp: the size of the user buffer
2793 * @ppos: file position
2794 *
2795 * The bitmap is stored at table->data and the bitmap length (in bits)
2796 * in table->maxlen.
2797 *
2798 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2799 * large bitmaps may be represented in a compact manner. Writing into
2800 * the file will clear the bitmap then update it with the given input.
2801 *
2802 * Returns 0 on success.
2803 */
2804int proc_do_large_bitmap(struct ctl_table *table, int write,
2805 void __user *buffer, size_t *lenp, loff_t *ppos)
2806{
2807 int err = 0;
2808 bool first = 1;
2809 size_t left = *lenp;
2810 unsigned long bitmap_len = table->maxlen;
2811 unsigned long *bitmap = (unsigned long *) table->data;
2812 unsigned long *tmp_bitmap = NULL;
2813 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2814
2815 if (!bitmap_len || !left || (*ppos && !write)) {
2816 *lenp = 0;
2817 return 0;
2818 }
2819
2820 if (write) {
2821 unsigned long page = 0;
2822 char *kbuf;
2823
2824 if (left > PAGE_SIZE - 1)
2825 left = PAGE_SIZE - 1;
2826
2827 page = __get_free_page(GFP_TEMPORARY);
2828 kbuf = (char *) page;
2829 if (!kbuf)
2830 return -ENOMEM;
2831 if (copy_from_user(kbuf, buffer, left)) {
2832 free_page(page);
2833 return -EFAULT;
2834 }
2835 kbuf[left] = 0;
2836
2837 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2838 GFP_KERNEL);
2839 if (!tmp_bitmap) {
2840 free_page(page);
2841 return -ENOMEM;
2842 }
2843 proc_skip_char(&kbuf, &left, '\n');
2844 while (!err && left) {
2845 unsigned long val_a, val_b;
2846 bool neg;
2847
2848 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2849 sizeof(tr_a), &c);
2850 if (err)
2851 break;
2852 if (val_a >= bitmap_len || neg) {
2853 err = -EINVAL;
2854 break;
2855 }
2856
2857 val_b = val_a;
2858 if (left) {
2859 kbuf++;
2860 left--;
2861 }
2862
2863 if (c == '-') {
2864 err = proc_get_long(&kbuf, &left, &val_b,
2865 &neg, tr_b, sizeof(tr_b),
2866 &c);
2867 if (err)
2868 break;
2869 if (val_b >= bitmap_len || neg ||
2870 val_a > val_b) {
2871 err = -EINVAL;
2872 break;
2873 }
2874 if (left) {
2875 kbuf++;
2876 left--;
2877 }
2878 }
2879
2880 while (val_a <= val_b)
2881 set_bit(val_a++, tmp_bitmap);
2882
2883 first = 0;
2884 proc_skip_char(&kbuf, &left, '\n');
2885 }
2886 free_page(page);
2887 } else {
2888 unsigned long bit_a, bit_b = 0;
2889
2890 while (left) {
2891 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2892 if (bit_a >= bitmap_len)
2893 break;
2894 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2895 bit_a + 1) - 1;
2896
2897 if (!first) {
2898 err = proc_put_char(&buffer, &left, ',');
2899 if (err)
2900 break;
2901 }
2902 err = proc_put_long(&buffer, &left, bit_a, false);
2903 if (err)
2904 break;
2905 if (bit_a != bit_b) {
2906 err = proc_put_char(&buffer, &left, '-');
2907 if (err)
2908 break;
2909 err = proc_put_long(&buffer, &left, bit_b, false);
2910 if (err)
2911 break;
2912 }
2913
2914 first = 0; bit_b++;
2915 }
2916 if (!err)
2917 err = proc_put_char(&buffer, &left, '\n');
2918 }
2919
2920 if (!err) {
2921 if (write) {
2922 if (*ppos)
2923 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2924 else
2925 memcpy(bitmap, tmp_bitmap,
2926 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2927 }
2928 kfree(tmp_bitmap);
2929 *lenp -= left;
2930 *ppos += *lenp;
2931 return 0;
2932 } else {
2933 kfree(tmp_bitmap);
2934 return err;
2935 }
2936}
2937
Jovi Zhang55610502011-01-12 17:00:45 -08002938#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 void __user *buffer, size_t *lenp, loff_t *ppos)
2942{
2943 return -ENOSYS;
2944}
2945
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002946int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *buffer, size_t *lenp, loff_t *ppos)
2948{
2949 return -ENOSYS;
2950}
2951
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002952int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 void __user *buffer, size_t *lenp, loff_t *ppos)
2954{
2955 return -ENOSYS;
2956}
2957
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002958int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 void __user *buffer, size_t *lenp, loff_t *ppos)
2960{
2961 return -ENOSYS;
2962}
2963
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002964int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 void __user *buffer, size_t *lenp, loff_t *ppos)
2966{
2967 return -ENOSYS;
2968}
2969
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002970int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 void __user *buffer, size_t *lenp, loff_t *ppos)
2972{
2973 return -ENOSYS;
2974}
2975
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002976int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 void __user *buffer, size_t *lenp, loff_t *ppos)
2978{
2979 return -ENOSYS;
2980}
2981
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002982int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 void __user *buffer,
2984 size_t *lenp, loff_t *ppos)
2985{
2986 return -ENOSYS;
2987}
2988
2989
Jovi Zhang55610502011-01-12 17:00:45 -08002990#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992/*
2993 * No sense putting this after each symbol definition, twice,
2994 * exception granted :-)
2995 */
2996EXPORT_SYMBOL(proc_dointvec);
2997EXPORT_SYMBOL(proc_dointvec_jiffies);
2998EXPORT_SYMBOL(proc_dointvec_minmax);
2999EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3000EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3001EXPORT_SYMBOL(proc_dostring);
3002EXPORT_SYMBOL(proc_doulongvec_minmax);
3003EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3004EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003005EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006EXPORT_SYMBOL(unregister_sysctl_table);