blob: f487f257e05e4f1dc8836ded96ca36556b048706 [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>
Dan Ballard73efc032011-10-31 17:11:20 -070060#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#include <asm/uaccess.h>
63#include <asm/processor.h>
64
Andi Kleen29cbc782006-09-30 01:47:55 +020065#ifdef CONFIG_X86
66#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010067#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010068#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020069#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080070#ifdef CONFIG_BSD_PROCESS_ACCT
71#include <linux/acct.h>
72#endif
Dave Young4f0e0562010-03-10 15:24:09 -080073#ifdef CONFIG_RT_MUTEXES
74#include <linux/rtmutex.h>
75#endif
Dave Young2edf5e42010-03-10 15:24:10 -080076#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
77#include <linux/lockdep.h>
78#endif
Dave Young15485a42010-03-10 15:24:07 -080079#ifdef CONFIG_CHR_DEV_SG
80#include <scsi/sg.h>
81#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020082
Don Zickus58687ac2010-05-07 17:11:44 -040083#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050084#include <linux/nmi.h>
85#endif
86
Eric W. Biederman7058cb02007-10-18 03:05:58 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#if defined(CONFIG_SYSCTL)
89
90/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern int sysctl_overcommit_memory;
92extern int sysctl_overcommit_ratio;
93extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070095extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070097extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max;
99extern int min_free_kbytes;
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;
Dan Ballard73efc032011-10-31 17:11:20 -0700138static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dave Youngd14f1722010-02-25 20:28:57 -0500140#ifdef CONFIG_INOTIFY_USER
141#include <linux/inotify.h>
142#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700143#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700144#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif
146
David S. Miller08714202008-11-16 23:49:24 -0800147#ifdef CONFIG_SPARC64
148extern int sysctl_tsb_ratio;
149#endif
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#ifdef __hppa__
152extern int pwrsw_enabled;
153extern int unaligned_enabled;
154#endif
155
Jes Sorensend2b176e2006-02-28 09:42:23 -0800156#ifdef CONFIG_IA64
157extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800158extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800159#endif
160
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700161#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700162static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700164static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800165 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700166#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700168#ifdef CONFIG_PRINTK
169static int proc_dmesg_restrict(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171#endif
172
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700173#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800174/* Note: sysrq code uses it's own private copy */
175static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700176
177static int sysrq_sysctl_handler(ctl_table *table, int write,
178 void __user *buffer, size_t *lenp,
179 loff_t *ppos)
180{
181 int error;
182
183 error = proc_dointvec(table, write, buffer, lenp, ppos);
184 if (error)
185 return error;
186
187 if (write)
188 sysrq_toggle_support(__sysrq_enabled);
189
190 return 0;
191}
192
193#endif
194
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700195static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196static struct ctl_table_root sysctl_table_root;
197static struct ctl_table_header root_table_header = {
Al Virodfef6dcd32011-03-08 01:25:28 -0500198 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100199 .ctl_table = root_table,
Al Virodfef6dcd32011-03-08 01:25:28 -0500200 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400202 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100203};
204static struct ctl_table_root sysctl_table_root = {
205 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400206 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100207};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700209static struct ctl_table kern_table[];
210static struct ctl_table vm_table[];
211static struct ctl_table fs_table[];
212static struct ctl_table debug_table[];
213static struct ctl_table dev_table[];
214extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800215#ifdef CONFIG_EPOLL
216extern struct ctl_table epoll_table[];
217#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220int sysctl_legacy_va_layout;
221#endif
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/* The default sysctl tables: */
224
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700225static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .procname = "kernel",
228 .mode = 0555,
229 .child = kern_table,
230 },
231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .procname = "vm",
233 .mode = 0555,
234 .child = vm_table,
235 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "fs",
238 .mode = 0555,
239 .child = fs_table,
240 },
241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "debug",
243 .mode = 0555,
244 .child = debug_table,
245 },
246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "dev",
248 .mode = 0555,
249 .child = dev_table,
250 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700251 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100255static int min_sched_granularity_ns = 100000; /* 100 usecs */
256static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257static int min_wakeup_granularity_ns; /* 0 usecs */
258static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100259static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
260static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200261#endif
262
Mel Gorman5e771902010-05-24 14:32:31 -0700263#ifdef CONFIG_COMPACTION
264static int min_extfrag_threshold;
265static int max_extfrag_threshold = 1000;
266#endif
267
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700268static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200269 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200270 .procname = "sched_child_runs_first",
271 .data = &sysctl_sched_child_runs_first,
272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800274 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200275 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200276#ifdef CONFIG_SCHED_DEBUG
277 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100278 .procname = "sched_min_granularity_ns",
279 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800282 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100283 .extra1 = &min_sched_granularity_ns,
284 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200285 },
286 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200287 .procname = "sched_latency_ns",
288 .data = &sysctl_sched_latency,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800291 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200292 .extra1 = &min_sched_granularity_ns,
293 .extra2 = &max_sched_granularity_ns,
294 },
295 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 .procname = "sched_wakeup_granularity_ns",
297 .data = &sysctl_sched_wakeup_granularity,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800300 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 .extra1 = &min_wakeup_granularity_ns,
302 .extra2 = &max_wakeup_granularity_ns,
303 },
304 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100305 .procname = "sched_tunable_scaling",
306 .data = &sysctl_sched_tunable_scaling,
307 .maxlen = sizeof(enum sched_tunable_scaling),
308 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800309 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100310 .extra1 = &min_sched_tunable_scaling,
311 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200312 },
313 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200314 .procname = "sched_migration_cost",
315 .data = &sysctl_sched_migration_cost,
316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800318 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200319 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100320 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800325 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100326 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530327 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200328 .procname = "sched_time_avg",
329 .data = &sysctl_sched_time_avg,
330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800332 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200333 },
334 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800335 .procname = "sched_shares_window",
336 .data = &sysctl_sched_shares_window,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = proc_dointvec,
340 },
341 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530342 .procname = "timer_migration",
343 .data = &sysctl_timer_migration,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800346 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530347 .extra1 = &zero,
348 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530349 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200350#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200351 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100352 .procname = "sched_rt_period_us",
353 .data = &sysctl_sched_rt_period,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800356 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100357 },
358 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100359 .procname = "sched_rt_runtime_us",
360 .data = &sysctl_sched_rt_runtime,
361 .maxlen = sizeof(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 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100365#ifdef CONFIG_SCHED_AUTOGROUP
366 {
367 .procname = "sched_autogroup_enabled",
368 .data = &sysctl_sched_autogroup_enabled,
369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800371 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100372 .extra1 = &zero,
373 .extra2 = &one,
374 },
375#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700376#ifdef CONFIG_CFS_BANDWIDTH
377 {
378 .procname = "sched_cfs_bandwidth_slice_us",
379 .data = &sysctl_sched_cfs_bandwidth_slice,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec_minmax,
383 .extra1 = &one,
384 },
385#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700386#ifdef CONFIG_PROVE_LOCKING
387 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800392 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700393 },
394#endif
395#ifdef CONFIG_LOCK_STAT
396 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700397 .procname = "lock_stat",
398 .data = &lock_stat,
399 .maxlen = sizeof(int),
400 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800401 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700402 },
403#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .procname = "panic",
406 .data = &panic_timeout,
407 .maxlen = sizeof(int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 },
411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .procname = "core_uses_pid",
413 .data = &core_uses_pid,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800416 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 },
418 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 .procname = "core_pattern",
420 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700421 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800423 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 },
Neil Hormana2939802009-09-23 15:56:56 -0700425 {
Neil Hormana2939802009-09-23 15:56:56 -0700426 .procname = "core_pipe_limit",
427 .data = &core_pipe_limit,
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800430 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700431 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800432#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700435 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800437 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800439#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100440#ifdef CONFIG_LATENCYTOP
441 {
442 .procname = "latencytop",
443 .data = &latencytop_enabled,
444 .maxlen = sizeof(int),
445 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800446 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100447 },
448#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#ifdef CONFIG_BLK_DEV_INITRD
450 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 .procname = "real-root-dev",
452 .data = &real_root_dev,
453 .maxlen = sizeof(int),
454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800455 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 },
457#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700458 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700459 .procname = "print-fatal-signals",
460 .data = &print_fatal_signals,
461 .maxlen = sizeof(int),
462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800463 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700464 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700465#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "reboot-cmd",
468 .data = reboot_command,
469 .maxlen = 256,
470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800471 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "stop-a",
475 .data = &stop_a_enabled,
476 .maxlen = sizeof (int),
477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800478 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800485 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
487#endif
David S. Miller08714202008-11-16 23:49:24 -0800488#ifdef CONFIG_SPARC64
489 {
David S. Miller08714202008-11-16 23:49:24 -0800490 .procname = "tsb-ratio",
491 .data = &sysctl_tsb_ratio,
492 .maxlen = sizeof (int),
493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800494 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800495 },
496#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#ifdef __hppa__
498 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .procname = "soft-power",
500 .data = &pwrsw_enabled,
501 .maxlen = sizeof (int),
502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800503 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .procname = "unaligned-trap",
507 .data = &unaligned_enabled,
508 .maxlen = sizeof (int),
509 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800510 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 },
512#endif
513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .procname = "ctrl-alt-del",
515 .data = &C_A_D,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400520#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200521 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200522 .procname = "ftrace_enabled",
523 .data = &ftrace_enabled,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200527 },
528#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500529#ifdef CONFIG_STACK_TRACER
530 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500531 .procname = "stack_tracer_enabled",
532 .data = &stack_tracer_enabled,
533 .maxlen = sizeof(int),
534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800535 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500536 },
537#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400538#ifdef CONFIG_TRACING
539 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100540 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400541 .data = &ftrace_dump_on_oops,
542 .maxlen = sizeof(int),
543 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800544 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400545 },
546#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200547#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .procname = "modprobe",
550 .data = &modprobe_path,
551 .maxlen = KMOD_PATH_LEN,
552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800553 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 },
Kees Cook3d433212009-04-02 15:49:29 -0700555 {
Kees Cook3d433212009-04-02 15:49:29 -0700556 .procname = "modules_disabled",
557 .data = &modules_disabled,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800561 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700562 .extra1 = &one,
563 .extra2 = &one,
564 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100566#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100569 .data = &uevent_helper,
570 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800572 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 },
574#endif
575#ifdef CONFIG_CHR_DEV_SG
576 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 .procname = "sg-big-buff",
578 .data = &sg_big_buff,
579 .maxlen = sizeof (int),
580 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800581 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 },
583#endif
584#ifdef CONFIG_BSD_PROCESS_ACCT
585 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .procname = "acct",
587 .data = &acct_parm,
588 .maxlen = 3*sizeof(int),
589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800590 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 },
592#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#ifdef CONFIG_MAGIC_SYSRQ
594 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800596 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .maxlen = sizeof (int),
598 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700599 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 },
601#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700602#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700605 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .maxlen = sizeof (int),
607 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700610#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .procname = "threads-max",
613 .data = &max_threads,
614 .maxlen = sizeof(int),
615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800616 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 },
618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .procname = "random",
620 .mode = 0555,
621 .child = random_table,
622 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 {
Eric Paris17f60a72011-04-01 17:07:50 -0400624 .procname = "usermodehelper",
625 .mode = 0555,
626 .child = usermodehelper_table,
627 },
628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .procname = "overflowuid",
630 .data = &overflowuid,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800633 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .extra1 = &minolduid,
635 .extra2 = &maxolduid,
636 },
637 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 .procname = "overflowgid",
639 .data = &overflowgid,
640 .maxlen = sizeof(int),
641 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800642 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 .extra1 = &minolduid,
644 .extra2 = &maxolduid,
645 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800646#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#ifdef CONFIG_MATHEMU
648 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .procname = "ieee_emulation_warnings",
650 .data = &sysctl_ieee_emulation_warnings,
651 .maxlen = sizeof(int),
652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
655#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200658 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .maxlen = sizeof(int),
660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800661 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
663#endif
664 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 .procname = "pid_max",
666 .data = &pid_max,
667 .maxlen = sizeof (int),
668 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800669 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .extra1 = &pid_max_min,
671 .extra2 = &pid_max_max,
672 },
673 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .procname = "panic_on_oops",
675 .data = &panic_on_oops,
676 .maxlen = sizeof(int),
677 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800678 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800680#if defined CONFIG_PRINTK
681 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800682 .procname = "printk",
683 .data = &console_loglevel,
684 .maxlen = 4*sizeof(int),
685 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800686 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800687 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700690 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .maxlen = sizeof(int),
692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800693 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 },
695 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700697 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .maxlen = sizeof(int),
699 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
Dave Youngaf913222009-09-22 16:43:33 -0700702 {
Dave Youngaf913222009-09-22 16:43:33 -0700703 .procname = "printk_delay",
704 .data = &printk_delay_msec,
705 .maxlen = sizeof(int),
706 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800707 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700708 .extra1 = &zero,
709 .extra2 = &ten_thousand,
710 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800712 .procname = "dmesg_restrict",
713 .data = &dmesg_restrict,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = proc_dointvec_minmax,
717 .extra1 = &zero,
718 .extra2 = &one,
719 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800720 {
721 .procname = "kptr_restrict",
722 .data = &kptr_restrict,
723 .maxlen = sizeof(int),
724 .mode = 0644,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700725 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800726 .extra1 = &zero,
727 .extra2 = &two,
728 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800729#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .procname = "ngroups_max",
732 .data = &ngroups_max,
733 .maxlen = sizeof (int),
734 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800735 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 },
Dan Ballard73efc032011-10-31 17:11:20 -0700737 {
738 .procname = "cap_last_cap",
739 .data = (void *)&cap_last_cap,
740 .maxlen = sizeof(int),
741 .mode = 0444,
742 .proc_handler = proc_dointvec,
743 },
Don Zickus58687ac2010-05-07 17:11:44 -0400744#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500745 {
Don Zickus58687ac2010-05-07 17:11:44 -0400746 .procname = "watchdog",
747 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500748 .maxlen = sizeof (int),
749 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700750 .proc_handler = proc_dowatchdog,
751 .extra1 = &zero,
752 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400753 },
754 {
755 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700756 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400757 .maxlen = sizeof(int),
758 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700759 .proc_handler = proc_dowatchdog,
Don Zickus58687ac2010-05-07 17:11:44 -0400760 .extra1 = &neg_one,
761 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500762 },
Don Zickus2508ce12010-05-07 17:11:46 -0400763 {
764 .procname = "softlockup_panic",
765 .data = &softlockup_panic,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = proc_dointvec_minmax,
769 .extra1 = &zero,
770 .extra2 = &one,
771 },
Don Zickus5dc30552010-11-29 17:07:17 -0500772 {
773 .procname = "nmi_watchdog",
774 .data = &watchdog_enabled,
775 .maxlen = sizeof (int),
776 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700777 .proc_handler = proc_dowatchdog,
778 .extra1 = &zero,
779 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500780 },
781#endif
782#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
783 {
784 .procname = "unknown_nmi_panic",
785 .data = &unknown_nmi_panic,
786 .maxlen = sizeof (int),
787 .mode = 0644,
788 .proc_handler = proc_dointvec,
789 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500790#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791#if defined(CONFIG_X86)
792 {
Don Zickus8da5add2006-09-26 10:52:27 +0200793 .procname = "panic_on_unrecovered_nmi",
794 .data = &panic_on_unrecovered_nmi,
795 .maxlen = sizeof(int),
796 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800797 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200798 },
799 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700800 .procname = "panic_on_io_nmi",
801 .data = &panic_on_io_nmi,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800804 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700805 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900806#ifdef CONFIG_DEBUG_STACKOVERFLOW
807 {
808 .procname = "panic_on_stackoverflow",
809 .data = &sysctl_panic_on_stackoverflow,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = proc_dointvec,
813 },
814#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700815 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .procname = "bootloader_type",
817 .data = &bootloader_type,
818 .maxlen = sizeof (int),
819 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800820 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100822 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700823 .procname = "bootloader_version",
824 .data = &bootloader_version,
825 .maxlen = sizeof (int),
826 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700828 },
829 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100830 .procname = "kstack_depth_to_print",
831 .data = &kstack_depth_to_print,
832 .maxlen = sizeof(int),
833 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800834 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100835 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100836 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100837 .procname = "io_delay_type",
838 .data = &io_delay_type,
839 .maxlen = sizeof(int),
840 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800841 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100842 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800844#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 .procname = "randomize_va_space",
847 .data = &randomize_va_space,
848 .maxlen = sizeof(int),
849 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800850 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800852#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800853#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700854 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700855 .procname = "spin_retry",
856 .data = &spin_retry,
857 .maxlen = sizeof (int),
858 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800859 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700860 },
861#endif
Len Brown673d5b42007-07-28 03:33:16 -0400862#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800863 {
Pavel Machekc255d842006-02-20 18:27:58 -0800864 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700865 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800866 .maxlen = sizeof (unsigned long),
867 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800869 },
870#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800871#ifdef CONFIG_IA64
872 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800873 .procname = "ignore-unaligned-usertrap",
874 .data = &no_unaligned_warning,
875 .maxlen = sizeof (int),
876 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800877 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800878 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800879 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800880 .procname = "unaligned-dump-stack",
881 .data = &unaligned_dump_stack,
882 .maxlen = sizeof (int),
883 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800884 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800885 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800886#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800887#ifdef CONFIG_DETECT_HUNG_TASK
888 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800889 .procname = "hung_task_panic",
890 .data = &sysctl_hung_task_panic,
891 .maxlen = sizeof(int),
892 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800893 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800894 .extra1 = &zero,
895 .extra2 = &one,
896 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100897 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100898 .procname = "hung_task_check_count",
899 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100900 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100901 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800902 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100903 },
904 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100905 .procname = "hung_task_timeout_secs",
906 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100907 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100908 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800909 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100910 },
911 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100912 .procname = "hung_task_warnings",
913 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100914 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100915 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100917 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700918#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200919#ifdef CONFIG_COMPAT
920 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200921 .procname = "compat-log",
922 .data = &compat_log,
923 .maxlen = sizeof (int),
924 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800925 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200926 },
927#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700928#ifdef CONFIG_RT_MUTEXES
929 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700930 .procname = "max_lock_depth",
931 .data = &max_lock_depth,
932 .maxlen = sizeof(int),
933 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800934 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700935 },
936#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700937 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700938 .procname = "poweroff_cmd",
939 .data = &poweroff_cmd,
940 .maxlen = POWEROFF_CMD_PATH_LEN,
941 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800942 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700943 },
David Howells0b77f5b2008-04-29 01:01:32 -0700944#ifdef CONFIG_KEYS
945 {
David Howells0b77f5b2008-04-29 01:01:32 -0700946 .procname = "keys",
947 .mode = 0555,
948 .child = key_sysctls,
949 },
950#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700951#ifdef CONFIG_RCU_TORTURE_TEST
952 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700953 .procname = "rcutorture_runnable",
954 .data = &rcutorture_runnable,
955 .maxlen = sizeof(int),
956 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800957 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700958 },
959#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200960#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -0400961 /*
962 * User-space scripts rely on the existence of this file
963 * as a feature check for perf_events being enabled.
964 *
965 * So it's an ABI, do not remove!
966 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200967 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200968 .procname = "perf_event_paranoid",
969 .data = &sysctl_perf_event_paranoid,
970 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200973 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200974 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200975 .procname = "perf_event_mlock_kb",
976 .data = &sysctl_perf_event_mlock,
977 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200978 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800979 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200980 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200981 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200982 .procname = "perf_event_max_sample_rate",
983 .data = &sysctl_perf_event_sample_rate,
984 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200985 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100986 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200987 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200988#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200989#ifdef CONFIG_KMEMCHECK
990 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200991 .procname = "kmemcheck",
992 .data = &kmemcheck_enabled,
993 .maxlen = sizeof(int),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200996 },
997#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200998#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200999 {
Jens Axboe5e605b62009-08-05 09:07:21 +02001000 .procname = "blk_iopoll",
1001 .data = &blk_iopoll_enabled,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001004 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +02001005 },
Jens Axboecb684b52009-09-15 21:53:11 +02001006#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001007 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008};
1009
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001010static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "overcommit_memory",
1013 .data = &sysctl_overcommit_memory,
1014 .maxlen = sizeof(sysctl_overcommit_memory),
1015 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001016 .proc_handler = proc_dointvec_minmax,
1017 .extra1 = &zero,
1018 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 },
1020 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001021 .procname = "panic_on_oom",
1022 .data = &sysctl_panic_on_oom,
1023 .maxlen = sizeof(sysctl_panic_on_oom),
1024 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001025 .proc_handler = proc_dointvec_minmax,
1026 .extra1 = &zero,
1027 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001028 },
1029 {
David Rientjesfe071d72007-10-16 23:25:56 -07001030 .procname = "oom_kill_allocating_task",
1031 .data = &sysctl_oom_kill_allocating_task,
1032 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1033 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001034 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001035 },
1036 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001037 .procname = "oom_dump_tasks",
1038 .data = &sysctl_oom_dump_tasks,
1039 .maxlen = sizeof(sysctl_oom_dump_tasks),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001042 },
1043 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 .procname = "overcommit_ratio",
1045 .data = &sysctl_overcommit_ratio,
1046 .maxlen = sizeof(sysctl_overcommit_ratio),
1047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 },
1050 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 .procname = "page-cluster",
1052 .data = &page_cluster,
1053 .maxlen = sizeof(int),
1054 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001055 .proc_handler = proc_dointvec_minmax,
1056 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .procname = "dirty_background_ratio",
1060 .data = &dirty_background_ratio,
1061 .maxlen = sizeof(dirty_background_ratio),
1062 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 .extra1 = &zero,
1065 .extra2 = &one_hundred,
1066 },
1067 {
David Rientjes2da02992009-01-06 14:39:31 -08001068 .procname = "dirty_background_bytes",
1069 .data = &dirty_background_bytes,
1070 .maxlen = sizeof(dirty_background_bytes),
1071 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001072 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001073 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001074 },
1075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .procname = "dirty_ratio",
1077 .data = &vm_dirty_ratio,
1078 .maxlen = sizeof(vm_dirty_ratio),
1079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .extra1 = &zero,
1082 .extra2 = &one_hundred,
1083 },
1084 {
David Rientjes2da02992009-01-06 14:39:31 -08001085 .procname = "dirty_bytes",
1086 .data = &vm_dirty_bytes,
1087 .maxlen = sizeof(vm_dirty_bytes),
1088 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001089 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001090 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001091 },
1092 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001094 .data = &dirty_writeback_interval,
1095 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001097 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 },
1099 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001101 .data = &dirty_expire_interval,
1102 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001104 .proc_handler = proc_dointvec_minmax,
1105 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 },
1107 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 .procname = "nr_pdflush_threads",
1109 .data = &nr_pdflush_threads,
1110 .maxlen = sizeof nr_pdflush_threads,
1111 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001112 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 },
1114 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 .procname = "swappiness",
1116 .data = &vm_swappiness,
1117 .maxlen = sizeof(vm_swappiness),
1118 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001119 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 .extra1 = &zero,
1121 .extra2 = &one_hundred,
1122 },
1123#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001126 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 .maxlen = sizeof(unsigned long),
1128 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001129 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 .extra1 = (void *)&hugetlb_zero,
1131 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001132 },
1133#ifdef CONFIG_NUMA
1134 {
1135 .procname = "nr_hugepages_mempolicy",
1136 .data = NULL,
1137 .maxlen = sizeof(unsigned long),
1138 .mode = 0644,
1139 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1140 .extra1 = (void *)&hugetlb_zero,
1141 .extra2 = (void *)&hugetlb_infinity,
1142 },
1143#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 .procname = "hugetlb_shm_group",
1146 .data = &sysctl_hugetlb_shm_group,
1147 .maxlen = sizeof(gid_t),
1148 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001149 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 },
Mel Gorman396faf02007-07-17 04:03:13 -07001151 {
Mel Gorman396faf02007-07-17 04:03:13 -07001152 .procname = "hugepages_treat_as_movable",
1153 .data = &hugepages_treat_as_movable,
1154 .maxlen = sizeof(int),
1155 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001156 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001157 },
Adam Litke54f9f802007-10-16 01:26:20 -07001158 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001159 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001160 .data = NULL,
1161 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001162 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001163 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001164 .extra1 = (void *)&hugetlb_zero,
1165 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001166 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167#endif
1168 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 .procname = "lowmem_reserve_ratio",
1170 .data = &sysctl_lowmem_reserve_ratio,
1171 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1172 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001173 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 },
1175 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001176 .procname = "drop_caches",
1177 .data = &sysctl_drop_caches,
1178 .maxlen = sizeof(int),
1179 .mode = 0644,
1180 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001181 .extra1 = &one,
1182 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001183 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001184#ifdef CONFIG_COMPACTION
1185 {
1186 .procname = "compact_memory",
1187 .data = &sysctl_compact_memory,
1188 .maxlen = sizeof(int),
1189 .mode = 0200,
1190 .proc_handler = sysctl_compaction_handler,
1191 },
Mel Gorman5e771902010-05-24 14:32:31 -07001192 {
1193 .procname = "extfrag_threshold",
1194 .data = &sysctl_extfrag_threshold,
1195 .maxlen = sizeof(int),
1196 .mode = 0644,
1197 .proc_handler = sysctl_extfrag_handler,
1198 .extra1 = &min_extfrag_threshold,
1199 .extra2 = &max_extfrag_threshold,
1200 },
1201
Mel Gorman76ab0f52010-05-24 14:32:28 -07001202#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001203 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 .procname = "min_free_kbytes",
1205 .data = &min_free_kbytes,
1206 .maxlen = sizeof(min_free_kbytes),
1207 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001208 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .extra1 = &zero,
1210 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001211 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001212 .procname = "percpu_pagelist_fraction",
1213 .data = &percpu_pagelist_fraction,
1214 .maxlen = sizeof(percpu_pagelist_fraction),
1215 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001216 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001217 .extra1 = &min_percpu_pagelist_fract,
1218 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219#ifdef CONFIG_MMU
1220 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 .procname = "max_map_count",
1222 .data = &sysctl_max_map_count,
1223 .maxlen = sizeof(sysctl_max_map_count),
1224 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001225 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001226 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001228#else
1229 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001230 .procname = "nr_trim_pages",
1231 .data = &sysctl_nr_trim_pages,
1232 .maxlen = sizeof(sysctl_nr_trim_pages),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001235 .extra1 = &zero,
1236 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237#endif
1238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 .procname = "laptop_mode",
1240 .data = &laptop_mode,
1241 .maxlen = sizeof(laptop_mode),
1242 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001243 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 },
1245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 .procname = "block_dump",
1247 .data = &block_dump,
1248 .maxlen = sizeof(block_dump),
1249 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001250 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 .extra1 = &zero,
1252 },
1253 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 .procname = "vfs_cache_pressure",
1255 .data = &sysctl_vfs_cache_pressure,
1256 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1257 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001258 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 .extra1 = &zero,
1260 },
1261#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1262 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 .procname = "legacy_va_layout",
1264 .data = &sysctl_legacy_va_layout,
1265 .maxlen = sizeof(sysctl_legacy_va_layout),
1266 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001267 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .extra1 = &zero,
1269 },
1270#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001271#ifdef CONFIG_NUMA
1272 {
Christoph Lameter17436602006-01-18 17:42:32 -08001273 .procname = "zone_reclaim_mode",
1274 .data = &zone_reclaim_mode,
1275 .maxlen = sizeof(zone_reclaim_mode),
1276 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001277 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001278 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001279 },
Christoph Lameter96146342006-07-03 00:24:13 -07001280 {
Christoph Lameter96146342006-07-03 00:24:13 -07001281 .procname = "min_unmapped_ratio",
1282 .data = &sysctl_min_unmapped_ratio,
1283 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1284 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001285 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001286 .extra1 = &zero,
1287 .extra2 = &one_hundred,
1288 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001289 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001290 .procname = "min_slab_ratio",
1291 .data = &sysctl_min_slab_ratio,
1292 .maxlen = sizeof(sysctl_min_slab_ratio),
1293 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001294 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001295 .extra1 = &zero,
1296 .extra2 = &one_hundred,
1297 },
Christoph Lameter17436602006-01-18 17:42:32 -08001298#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001299#ifdef CONFIG_SMP
1300 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001301 .procname = "stat_interval",
1302 .data = &sysctl_stat_interval,
1303 .maxlen = sizeof(sysctl_stat_interval),
1304 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001305 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001306 },
1307#endif
David Howells6e141542009-12-15 19:27:45 +00001308#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001309 {
Eric Parised032182007-06-28 15:55:21 -04001310 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001311 .data = &dac_mmap_min_addr,
1312 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001313 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001314 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001315 },
David Howells6e141542009-12-15 19:27:45 +00001316#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001317#ifdef CONFIG_NUMA
1318 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001319 .procname = "numa_zonelist_order",
1320 .data = &numa_zonelist_order,
1321 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1322 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001323 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001324 },
1325#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001326#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001327 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001328 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001329 .procname = "vdso_enabled",
1330 .data = &vdso_enabled,
1331 .maxlen = sizeof(vdso_enabled),
1332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001333 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001334 .extra1 = &zero,
1335 },
1336#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001337#ifdef CONFIG_HIGHMEM
1338 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001339 .procname = "highmem_is_dirtyable",
1340 .data = &vm_highmem_is_dirtyable,
1341 .maxlen = sizeof(vm_highmem_is_dirtyable),
1342 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001343 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001344 .extra1 = &zero,
1345 .extra2 = &one,
1346 },
1347#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001348 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001349 .procname = "scan_unevictable_pages",
1350 .data = &scan_unevictable_pages,
1351 .maxlen = sizeof(scan_unevictable_pages),
1352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001354 },
Andi Kleen6a460792009-09-16 11:50:15 +02001355#ifdef CONFIG_MEMORY_FAILURE
1356 {
Andi Kleen6a460792009-09-16 11:50:15 +02001357 .procname = "memory_failure_early_kill",
1358 .data = &sysctl_memory_failure_early_kill,
1359 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1360 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001361 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001362 .extra1 = &zero,
1363 .extra2 = &one,
1364 },
1365 {
Andi Kleen6a460792009-09-16 11:50:15 +02001366 .procname = "memory_failure_recovery",
1367 .data = &sysctl_memory_failure_recovery,
1368 .maxlen = sizeof(sysctl_memory_failure_recovery),
1369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001370 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001371 .extra1 = &zero,
1372 .extra2 = &one,
1373 },
1374#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001375 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376};
1377
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001378#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001379static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001380 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001381};
1382#endif
1383
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001384static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .procname = "inode-nr",
1387 .data = &inodes_stat,
1388 .maxlen = 2*sizeof(int),
1389 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001390 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 },
1392 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .procname = "inode-state",
1394 .data = &inodes_stat,
1395 .maxlen = 7*sizeof(int),
1396 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001397 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 },
1399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .procname = "file-nr",
1401 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001402 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001404 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 },
1406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 .procname = "file-max",
1408 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001409 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001411 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 },
1413 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001414 .procname = "nr_open",
1415 .data = &sysctl_nr_open,
1416 .maxlen = sizeof(int),
1417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001418 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001419 .extra1 = &sysctl_nr_open_min,
1420 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001421 },
1422 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .procname = "dentry-state",
1424 .data = &dentry_stat,
1425 .maxlen = 6*sizeof(int),
1426 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001427 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 },
1429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "overflowuid",
1431 .data = &fs_overflowuid,
1432 .maxlen = sizeof(int),
1433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001434 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 .extra1 = &minolduid,
1436 .extra2 = &maxolduid,
1437 },
1438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 .procname = "overflowgid",
1440 .data = &fs_overflowgid,
1441 .maxlen = sizeof(int),
1442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001443 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 .extra1 = &minolduid,
1445 .extra2 = &maxolduid,
1446 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001447#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 .procname = "leases-enable",
1450 .data = &leases_enable,
1451 .maxlen = sizeof(int),
1452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001453 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001455#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456#ifdef CONFIG_DNOTIFY
1457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 .procname = "dir-notify-enable",
1459 .data = &dir_notify_enable,
1460 .maxlen = sizeof(int),
1461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001462 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 },
1464#endif
1465#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001466#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 .procname = "lease-break-time",
1469 .data = &lease_break_time,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001472 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001474#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001475#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 .procname = "aio-nr",
1478 .data = &aio_nr,
1479 .maxlen = sizeof(aio_nr),
1480 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001481 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 },
1483 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 .procname = "aio-max-nr",
1485 .data = &aio_max_nr,
1486 .maxlen = sizeof(aio_max_nr),
1487 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001488 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001490#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001491#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001492 {
Robert Love0399cb02005-07-13 12:38:18 -04001493 .procname = "inotify",
1494 .mode = 0555,
1495 .child = inotify_table,
1496 },
1497#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001498#ifdef CONFIG_EPOLL
1499 {
1500 .procname = "epoll",
1501 .mode = 0555,
1502 .child = epoll_table,
1503 },
1504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001506 {
Alan Coxd6e71142005-06-23 00:09:43 -07001507 .procname = "suid_dumpable",
1508 .data = &suid_dumpable,
1509 .maxlen = sizeof(int),
1510 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001511 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001512 .extra1 = &zero,
1513 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001514 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001515#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1516 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001517 .procname = "binfmt_misc",
1518 .mode = 0555,
1519 .child = binfmt_misc_table,
1520 },
1521#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001522 {
Jens Axboeff9da692010-06-03 14:54:39 +02001523 .procname = "pipe-max-size",
1524 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001525 .maxlen = sizeof(int),
1526 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001527 .proc_handler = &pipe_proc_fn,
1528 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001529 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001530 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531};
1532
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001533static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001534#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
Chris Metcalf571d76a2011-05-16 14:23:44 -04001535 defined(CONFIG_S390) || defined(CONFIG_TILE)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001536 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001537 .procname = "exception-trace",
1538 .data = &show_unhandled_signals,
1539 .maxlen = sizeof(int),
1540 .mode = 0644,
1541 .proc_handler = proc_dointvec
1542 },
1543#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001544#if defined(CONFIG_OPTPROBES)
1545 {
1546 .procname = "kprobes-optimization",
1547 .data = &sysctl_kprobes_optimization,
1548 .maxlen = sizeof(int),
1549 .mode = 0644,
1550 .proc_handler = proc_kprobes_optimization_handler,
1551 .extra1 = &zero,
1552 .extra2 = &one,
1553 },
1554#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001555 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556};
1557
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001558static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001559 { }
Robert Love0eeca282005-07-12 17:06:03 -04001560};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Al Viro330d57f2005-11-04 10:18:40 +00001562static DEFINE_SPINLOCK(sysctl_lock);
1563
1564/* called under sysctl_lock */
1565static int use_table(struct ctl_table_header *p)
1566{
1567 if (unlikely(p->unregistering))
1568 return 0;
1569 p->used++;
1570 return 1;
1571}
1572
1573/* called under sysctl_lock */
1574static void unuse_table(struct ctl_table_header *p)
1575{
1576 if (!--p->used)
1577 if (unlikely(p->unregistering))
1578 complete(p->unregistering);
1579}
1580
1581/* called under sysctl_lock, will reacquire if has to wait */
1582static void start_unregistering(struct ctl_table_header *p)
1583{
1584 /*
1585 * if p->used is 0, nobody will ever touch that entry again;
1586 * we'll eliminate all paths to it before dropping sysctl_lock
1587 */
1588 if (unlikely(p->used)) {
1589 struct completion wait;
1590 init_completion(&wait);
1591 p->unregistering = &wait;
1592 spin_unlock(&sysctl_lock);
1593 wait_for_completion(&wait);
1594 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001595 } else {
1596 /* anything non-NULL; we'll never dereference it */
1597 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001598 }
1599 /*
1600 * do not remove from the list until nobody holds it; walking the
1601 * list in do_sysctl() relies on that.
1602 */
1603 list_del_init(&p->ctl_entry);
1604}
1605
Al Virof7e6ced2008-07-15 01:44:23 -04001606void sysctl_head_get(struct ctl_table_header *head)
1607{
1608 spin_lock(&sysctl_lock);
1609 head->count++;
1610 spin_unlock(&sysctl_lock);
1611}
1612
1613void sysctl_head_put(struct ctl_table_header *head)
1614{
1615 spin_lock(&sysctl_lock);
1616 if (!--head->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001617 kfree_rcu(head, rcu);
Al Virof7e6ced2008-07-15 01:44:23 -04001618 spin_unlock(&sysctl_lock);
1619}
1620
1621struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1622{
1623 if (!head)
1624 BUG();
1625 spin_lock(&sysctl_lock);
1626 if (!use_table(head))
1627 head = ERR_PTR(-ENOENT);
1628 spin_unlock(&sysctl_lock);
1629 return head;
1630}
1631
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001632void sysctl_head_finish(struct ctl_table_header *head)
1633{
1634 if (!head)
1635 return;
1636 spin_lock(&sysctl_lock);
1637 unuse_table(head);
1638 spin_unlock(&sysctl_lock);
1639}
1640
Al Viro73455092008-07-14 21:22:20 -04001641static struct ctl_table_set *
1642lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1643{
1644 struct ctl_table_set *set = &root->default_set;
1645 if (root->lookup)
1646 set = root->lookup(root, namespaces);
1647 return set;
1648}
1649
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001650static struct list_head *
1651lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001652{
Al Viro73455092008-07-14 21:22:20 -04001653 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1654 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001655}
1656
1657struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1658 struct ctl_table_header *prev)
1659{
1660 struct ctl_table_root *root;
1661 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001662 struct ctl_table_header *head;
1663 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001664
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001665 spin_lock(&sysctl_lock);
1666 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001667 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001668 tmp = &prev->ctl_entry;
1669 unuse_table(prev);
1670 goto next;
1671 }
1672 tmp = &root_table_header.ctl_entry;
1673 for (;;) {
1674 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1675
1676 if (!use_table(head))
1677 goto next;
1678 spin_unlock(&sysctl_lock);
1679 return head;
1680 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001681 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001682 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001683 header_list = lookup_header_list(root, namespaces);
1684 if (tmp != header_list)
1685 continue;
1686
1687 do {
1688 root = list_entry(root->root_list.next,
1689 struct ctl_table_root, root_list);
1690 if (root == &sysctl_table_root)
1691 goto out;
1692 header_list = lookup_header_list(root, namespaces);
1693 } while (list_empty(header_list));
1694 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001695 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001696out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001697 spin_unlock(&sysctl_lock);
1698 return NULL;
1699}
1700
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001701struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1702{
1703 return __sysctl_head_next(current->nsproxy, prev);
1704}
1705
1706void register_sysctl_root(struct ctl_table_root *root)
1707{
1708 spin_lock(&sysctl_lock);
1709 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1710 spin_unlock(&sysctl_lock);
1711}
1712
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001714 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 * some sysctl variables are readonly even to root.
1716 */
1717
1718static int test_perm(int mode, int op)
1719{
David Howells76aac0e2008-11-14 10:39:12 +11001720 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 mode >>= 6;
1722 else if (in_egroup_p(0))
1723 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001724 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 return 0;
1726 return -EACCES;
1727}
1728
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001729int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001731 int mode;
1732
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001733 if (root->permissions)
1734 mode = root->permissions(root, current->nsproxy, table);
1735 else
1736 mode = table->mode;
1737
1738 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739}
1740
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001741static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1742{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001743 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001744 table->parent = parent;
1745 if (table->child)
1746 sysctl_set_parent(table, table->child);
1747 }
1748}
1749
1750static __init int sysctl_init(void)
1751{
1752 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001753#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001754 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001755#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001756 return 0;
1757}
1758
1759core_initcall(sysctl_init);
1760
Al Virobfbcf032008-07-27 06:31:22 +01001761static struct ctl_table *is_branch_in(struct ctl_table *branch,
1762 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001763{
1764 struct ctl_table *p;
1765 const char *s = branch->procname;
1766
1767 /* branch should have named subdirectory as its first element */
1768 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001769 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001770
1771 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001772 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001773 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001774
1775 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001776 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001777 if (!p->child)
1778 continue;
1779 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001780 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001781 }
Al Virobfbcf032008-07-27 06:31:22 +01001782 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001783}
1784
1785/* see if attaching q to p would be an improvement */
1786static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1787{
1788 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001789 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001790 int is_better = 0;
1791 int not_in_parent = !p->attached_by;
1792
Al Virobfbcf032008-07-27 06:31:22 +01001793 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001794 if (by == q->attached_by)
1795 is_better = 1;
1796 if (to == p->attached_by)
1797 not_in_parent = 1;
1798 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001799 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001800 }
1801
1802 if (is_better && not_in_parent) {
1803 q->attached_by = by;
1804 q->attached_to = to;
1805 q->parent = p;
1806 }
1807}
1808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001810 * __register_sysctl_paths - register a sysctl hierarchy
1811 * @root: List of sysctl headers to register on
1812 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001813 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 *
1816 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001817 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001819 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1822 * enter a sysctl file
1823 *
1824 * data - a pointer to data for use by proc_handler
1825 *
1826 * maxlen - the maximum size in bytes of the data
1827 *
1828 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1829 *
1830 * child - a pointer to the child sysctl table if this entry is a directory, or
1831 * %NULL.
1832 *
1833 * proc_handler - the text handler routine (described below)
1834 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 * de - for internal use by the sysctl routines
1836 *
1837 * extra1, extra2 - extra pointers usable by the proc handler routines
1838 *
1839 * Leaf nodes in the sysctl tree will be represented by a single file
1840 * under /proc; non-leaf nodes will be represented by directories.
1841 *
1842 * sysctl(2) can automatically manage read and write requests through
1843 * the sysctl table. The data and maxlen fields of the ctl_table
1844 * struct enable minimal validation of the values being written to be
1845 * performed, and the mode field allows minimal authentication.
1846 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 * There must be a proc_handler routine for any terminal nodes
1848 * mirrored under /proc/sys (non-terminals are handled by a built-in
1849 * directory handler). Several default handlers are available to
1850 * cover common cases -
1851 *
1852 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1853 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1854 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1855 *
1856 * It is the handler's job to read the input buffer from user memory
1857 * and process it. The handler should return 0 on success.
1858 *
1859 * This routine returns %NULL on a failure to register, and a pointer
1860 * to the table header on success.
1861 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001862struct ctl_table_header *__register_sysctl_paths(
1863 struct ctl_table_root *root,
1864 struct nsproxy *namespaces,
1865 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001867 struct ctl_table_header *header;
1868 struct ctl_table *new, **prevp;
1869 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001870 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001871
1872 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001873 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001874 ;
1875
1876 /*
1877 * For each path component, allocate a 2-element ctl_table array.
1878 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001879 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001880 *
1881 * We allocate everything in one go so that we don't have to
1882 * worry about freeing additional memory in unregister_sysctl_table.
1883 */
1884 header = kzalloc(sizeof(struct ctl_table_header) +
1885 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1886 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001888
1889 new = (struct ctl_table *) (header + 1);
1890
1891 /* Now connect the dots */
1892 prevp = &header->ctl_table;
1893 for (n = 0; n < npath; ++n, ++path) {
1894 /* Copy the procname */
1895 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001896 new->mode = 0555;
1897
1898 *prevp = new;
1899 prevp = &new->child;
1900
1901 new += 2;
1902 }
1903 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001904 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001905
1906 INIT_LIST_HEAD(&header->ctl_entry);
1907 header->used = 0;
1908 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001909 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001910 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001911 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001912#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001913 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001914 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001915 return NULL;
1916 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001917#endif
Al Viro330d57f2005-11-04 10:18:40 +00001918 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001919 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001920 header->attached_by = header->ctl_table;
1921 header->attached_to = root_table;
1922 header->parent = &root_table_header;
1923 for (set = header->set; set; set = set->parent) {
1924 struct ctl_table_header *p;
1925 list_for_each_entry(p, &set->list, ctl_entry) {
1926 if (p->unregistering)
1927 continue;
1928 try_attach(p, header);
1929 }
1930 }
1931 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001932 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001933 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001934
1935 return header;
1936}
1937
1938/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001939 * register_sysctl_table_path - register a sysctl table hierarchy
1940 * @path: The path to the directory the sysctl table is in.
1941 * @table: the top-level table structure
1942 *
1943 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1944 * array. A completely 0 filled entry terminates the table.
1945 *
1946 * See __register_sysctl_paths for more details.
1947 */
1948struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1949 struct ctl_table *table)
1950{
1951 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1952 path, table);
1953}
1954
1955/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001956 * register_sysctl_table - register a sysctl table hierarchy
1957 * @table: the top-level table structure
1958 *
1959 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1960 * array. A completely 0 filled entry terminates the table.
1961 *
1962 * See register_sysctl_paths for more details.
1963 */
1964struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1965{
1966 static const struct ctl_path null_path[] = { {} };
1967
1968 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969}
1970
1971/**
1972 * unregister_sysctl_table - unregister a sysctl table hierarchy
1973 * @header: the header returned from register_sysctl_table
1974 *
1975 * Unregisters the sysctl table and all children. proc entries may not
1976 * actually be removed until they are no longer used by anyone.
1977 */
1978void unregister_sysctl_table(struct ctl_table_header * header)
1979{
Al Viro330d57f2005-11-04 10:18:40 +00001980 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001981
1982 if (header == NULL)
1983 return;
1984
Al Viro330d57f2005-11-04 10:18:40 +00001985 spin_lock(&sysctl_lock);
1986 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001987 if (!--header->parent->count) {
1988 WARN_ON(1);
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001989 kfree_rcu(header->parent, rcu);
Al Viroae7edec2008-07-15 06:33:31 -04001990 }
Al Virof7e6ced2008-07-15 01:44:23 -04001991 if (!--header->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001992 kfree_rcu(header, rcu);
Al Viro330d57f2005-11-04 10:18:40 +00001993 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994}
1995
Al Viro9043476f2008-07-15 08:54:06 -04001996int sysctl_is_seen(struct ctl_table_header *p)
1997{
1998 struct ctl_table_set *set = p->set;
1999 int res;
2000 spin_lock(&sysctl_lock);
2001 if (p->unregistering)
2002 res = 0;
2003 else if (!set->is_seen)
2004 res = 1;
2005 else
2006 res = set->is_seen(set);
2007 spin_unlock(&sysctl_lock);
2008 return res;
2009}
2010
Al Viro73455092008-07-14 21:22:20 -04002011void setup_sysctl_set(struct ctl_table_set *p,
2012 struct ctl_table_set *parent,
2013 int (*is_seen)(struct ctl_table_set *))
2014{
2015 INIT_LIST_HEAD(&p->list);
2016 p->parent = parent ? parent : &sysctl_table_root.default_set;
2017 p->is_seen = is_seen;
2018}
2019
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002020#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002021struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002022{
2023 return NULL;
2024}
2025
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002026struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2027 struct ctl_table *table)
2028{
2029 return NULL;
2030}
2031
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002032void unregister_sysctl_table(struct ctl_table_header * table)
2033{
2034}
2035
Al Viro73455092008-07-14 21:22:20 -04002036void setup_sysctl_set(struct ctl_table_set *p,
2037 struct ctl_table_set *parent,
2038 int (*is_seen)(struct ctl_table_set *))
2039{
2040}
2041
Al Virof7e6ced2008-07-15 01:44:23 -04002042void sysctl_head_put(struct ctl_table_header *head)
2043{
2044}
2045
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002046#endif /* CONFIG_SYSCTL */
2047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048/*
2049 * /proc/sys support
2050 */
2051
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002052#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002054static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002055 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002056 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002057{
2058 size_t len;
2059 char __user *p;
2060 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002061
2062 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002063 *lenp = 0;
2064 return 0;
2065 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002066
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002067 if (write) {
2068 len = 0;
2069 p = buffer;
2070 while (len < *lenp) {
2071 if (get_user(c, p++))
2072 return -EFAULT;
2073 if (c == 0 || c == '\n')
2074 break;
2075 len++;
2076 }
2077 if (len >= maxlen)
2078 len = maxlen-1;
2079 if(copy_from_user(data, buffer, len))
2080 return -EFAULT;
2081 ((char *) data)[len] = 0;
2082 *ppos += *lenp;
2083 } else {
2084 len = strlen(data);
2085 if (len > maxlen)
2086 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002087
2088 if (*ppos > len) {
2089 *lenp = 0;
2090 return 0;
2091 }
2092
2093 data += *ppos;
2094 len -= *ppos;
2095
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002096 if (len > *lenp)
2097 len = *lenp;
2098 if (len)
2099 if(copy_to_user(buffer, data, len))
2100 return -EFAULT;
2101 if (len < *lenp) {
2102 if(put_user('\n', ((char __user *) buffer) + len))
2103 return -EFAULT;
2104 len++;
2105 }
2106 *lenp = len;
2107 *ppos += len;
2108 }
2109 return 0;
2110}
2111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112/**
2113 * proc_dostring - read a string sysctl
2114 * @table: the sysctl table
2115 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 * @buffer: the user buffer
2117 * @lenp: the size of the user buffer
2118 * @ppos: file position
2119 *
2120 * Reads/writes a string from/to the user buffer. If the kernel
2121 * buffer provided is not large enough to hold the string, the
2122 * string is truncated. The copied string is %NULL-terminated.
2123 * If the string is being read by the user process, it is copied
2124 * and a newline '\n' is added. It is truncated if the buffer is
2125 * not large enough.
2126 *
2127 * Returns 0 on success.
2128 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002129int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 void __user *buffer, size_t *lenp, loff_t *ppos)
2131{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002132 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002133 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
Amerigo Wang00b7c332010-05-05 00:26:45 +00002136static size_t proc_skip_spaces(char **buf)
2137{
2138 size_t ret;
2139 char *tmp = skip_spaces(*buf);
2140 ret = tmp - *buf;
2141 *buf = tmp;
2142 return ret;
2143}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002145static void proc_skip_char(char **buf, size_t *size, const char v)
2146{
2147 while (*size) {
2148 if (**buf != v)
2149 break;
2150 (*size)--;
2151 (*buf)++;
2152 }
2153}
2154
Amerigo Wang00b7c332010-05-05 00:26:45 +00002155#define TMPBUFLEN 22
2156/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002157 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002158 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002159 * @buf: a kernel buffer
2160 * @size: size of the kernel buffer
2161 * @val: this is where the number will be stored
2162 * @neg: set to %TRUE if number is negative
2163 * @perm_tr: a vector which contains the allowed trailers
2164 * @perm_tr_len: size of the perm_tr vector
2165 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002166 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002167 * In case of success %0 is returned and @buf and @size are updated with
2168 * the amount of bytes read. If @tr is non-NULL and a trailing
2169 * character exists (size is non-zero after returning from this
2170 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002171 */
2172static int proc_get_long(char **buf, size_t *size,
2173 unsigned long *val, bool *neg,
2174 const char *perm_tr, unsigned perm_tr_len, char *tr)
2175{
2176 int len;
2177 char *p, tmp[TMPBUFLEN];
2178
2179 if (!*size)
2180 return -EINVAL;
2181
2182 len = *size;
2183 if (len > TMPBUFLEN - 1)
2184 len = TMPBUFLEN - 1;
2185
2186 memcpy(tmp, *buf, len);
2187
2188 tmp[len] = 0;
2189 p = tmp;
2190 if (*p == '-' && *size > 1) {
2191 *neg = true;
2192 p++;
2193 } else
2194 *neg = false;
2195 if (!isdigit(*p))
2196 return -EINVAL;
2197
2198 *val = simple_strtoul(p, &p, 0);
2199
2200 len = p - tmp;
2201
2202 /* We don't know if the next char is whitespace thus we may accept
2203 * invalid integers (e.g. 1234...a) or two integers instead of one
2204 * (e.g. 123...1). So lets not allow such large numbers. */
2205 if (len == TMPBUFLEN - 1)
2206 return -EINVAL;
2207
2208 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2209 return -EINVAL;
2210
2211 if (tr && (len < *size))
2212 *tr = *p;
2213
2214 *buf += len;
2215 *size -= len;
2216
2217 return 0;
2218}
2219
2220/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002221 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002222 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002223 * @buf: the user buffer
2224 * @size: the size of the user buffer
2225 * @val: the integer to be converted
2226 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002227 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002228 * In case of success %0 is returned and @buf and @size are updated with
2229 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230 */
2231static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2232 bool neg)
2233{
2234 int len;
2235 char tmp[TMPBUFLEN], *p = tmp;
2236
2237 sprintf(p, "%s%lu", neg ? "-" : "", val);
2238 len = strlen(tmp);
2239 if (len > *size)
2240 len = *size;
2241 if (copy_to_user(*buf, tmp, len))
2242 return -EFAULT;
2243 *size -= len;
2244 *buf += len;
2245 return 0;
2246}
2247#undef TMPBUFLEN
2248
2249static int proc_put_char(void __user **buf, size_t *size, char c)
2250{
2251 if (*size) {
2252 char __user **buffer = (char __user **)buf;
2253 if (put_user(c, *buffer))
2254 return -EFAULT;
2255 (*size)--, (*buffer)++;
2256 *buf = *buffer;
2257 }
2258 return 0;
2259}
2260
2261static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 int *valp,
2263 int write, void *data)
2264{
2265 if (write) {
2266 *valp = *negp ? -*lvalp : *lvalp;
2267 } else {
2268 int val = *valp;
2269 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 *lvalp = (unsigned long)-val;
2272 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 *lvalp = (unsigned long)val;
2275 }
2276 }
2277 return 0;
2278}
2279
Amerigo Wang00b7c332010-05-05 00:26:45 +00002280static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2281
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002282static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002283 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002284 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002285 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 int write, void *data),
2287 void *data)
2288{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002289 int *i, vleft, first = 1, err = 0;
2290 unsigned long page = 0;
2291 size_t left;
2292 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
Amerigo Wang00b7c332010-05-05 00:26:45 +00002294 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 *lenp = 0;
2296 return 0;
2297 }
2298
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002299 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 vleft = table->maxlen / sizeof(*i);
2301 left = *lenp;
2302
2303 if (!conv)
2304 conv = do_proc_dointvec_conv;
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 if (left > PAGE_SIZE - 1)
2308 left = PAGE_SIZE - 1;
2309 page = __get_free_page(GFP_TEMPORARY);
2310 kbuf = (char *) page;
2311 if (!kbuf)
2312 return -ENOMEM;
2313 if (copy_from_user(kbuf, buffer, left)) {
2314 err = -EFAULT;
2315 goto free;
2316 }
2317 kbuf[left] = 0;
2318 }
2319
2320 for (; left && vleft--; i++, first=0) {
2321 unsigned long lval;
2322 bool neg;
2323
2324 if (write) {
2325 left -= proc_skip_spaces(&kbuf);
2326
J. R. Okajima563b0462010-05-25 16:10:14 -07002327 if (!left)
2328 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002329 err = proc_get_long(&kbuf, &left, &lval, &neg,
2330 proc_wspace_sep,
2331 sizeof(proc_wspace_sep), NULL);
2332 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 if (conv(&neg, &lval, i, 1, data)) {
2335 err = -EINVAL;
2336 break;
2337 }
2338 } else {
2339 if (conv(&neg, &lval, i, 0, data)) {
2340 err = -EINVAL;
2341 break;
2342 }
2343 if (!first)
2344 err = proc_put_char(&buffer, &left, '\t');
2345 if (err)
2346 break;
2347 err = proc_put_long(&buffer, &left, lval, neg);
2348 if (err)
2349 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 }
2351 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002352
2353 if (!write && !first && left && !err)
2354 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002355 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002356 left -= proc_skip_spaces(&kbuf);
2357free:
2358 if (write) {
2359 free_page(page);
2360 if (first)
2361 return err ? : -EINVAL;
2362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 *lenp -= left;
2364 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002365 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002369 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002370 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002371 int write, void *data),
2372 void *data)
2373{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002374 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002375 buffer, lenp, ppos, conv, data);
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378/**
2379 * proc_dointvec - read a vector of integers
2380 * @table: the sysctl table
2381 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 * @buffer: the user buffer
2383 * @lenp: the size of the user buffer
2384 * @ppos: file position
2385 *
2386 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2387 * values from/to the user buffer, treated as an ASCII string.
2388 *
2389 * Returns 0 on success.
2390 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002391int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 void __user *buffer, size_t *lenp, loff_t *ppos)
2393{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002394 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 NULL,NULL);
2396}
2397
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002398/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002399 * Taint values can only be increased
2400 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002401 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002402static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002403 void __user *buffer, size_t *lenp, loff_t *ppos)
2404{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002405 struct ctl_table t;
2406 unsigned long tmptaint = get_taint();
2407 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002408
Bastian Blank91fcd412007-04-23 14:41:14 -07002409 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002410 return -EPERM;
2411
Andi Kleen25ddbb12008-10-15 22:01:41 -07002412 t = *table;
2413 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002414 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002415 if (err < 0)
2416 return err;
2417
2418 if (write) {
2419 /*
2420 * Poor man's atomic or. Not worth adding a primitive
2421 * to everyone's atomic.h for this
2422 */
2423 int i;
2424 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2425 if ((tmptaint >> i) & 1)
2426 add_taint(i);
2427 }
2428 }
2429
2430 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002431}
2432
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002433#ifdef CONFIG_PRINTK
2434static int proc_dmesg_restrict(struct ctl_table *table, int write,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2436{
2437 if (write && !capable(CAP_SYS_ADMIN))
2438 return -EPERM;
2439
2440 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2441}
2442#endif
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444struct do_proc_dointvec_minmax_conv_param {
2445 int *min;
2446 int *max;
2447};
2448
Amerigo Wang00b7c332010-05-05 00:26:45 +00002449static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2450 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 int write, void *data)
2452{
2453 struct do_proc_dointvec_minmax_conv_param *param = data;
2454 if (write) {
2455 int val = *negp ? -*lvalp : *lvalp;
2456 if ((param->min && *param->min > val) ||
2457 (param->max && *param->max < val))
2458 return -EINVAL;
2459 *valp = val;
2460 } else {
2461 int val = *valp;
2462 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002463 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 *lvalp = (unsigned long)-val;
2465 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002466 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 *lvalp = (unsigned long)val;
2468 }
2469 }
2470 return 0;
2471}
2472
2473/**
2474 * proc_dointvec_minmax - read a vector of integers with min/max values
2475 * @table: the sysctl table
2476 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 * @buffer: the user buffer
2478 * @lenp: the size of the user buffer
2479 * @ppos: file position
2480 *
2481 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2482 * values from/to the user buffer, treated as an ASCII string.
2483 *
2484 * This routine will ensure the values are within the range specified by
2485 * table->extra1 (min) and table->extra2 (max).
2486 *
2487 * Returns 0 on success.
2488 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002489int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 void __user *buffer, size_t *lenp, loff_t *ppos)
2491{
2492 struct do_proc_dointvec_minmax_conv_param param = {
2493 .min = (int *) table->extra1,
2494 .max = (int *) table->extra2,
2495 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002496 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 do_proc_dointvec_minmax_conv, &param);
2498}
2499
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002500static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 void __user *buffer,
2502 size_t *lenp, loff_t *ppos,
2503 unsigned long convmul,
2504 unsigned long convdiv)
2505{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506 unsigned long *i, *min, *max;
2507 int vleft, first = 1, err = 0;
2508 unsigned long page = 0;
2509 size_t left;
2510 char *kbuf;
2511
2512 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 *lenp = 0;
2514 return 0;
2515 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002516
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002517 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 min = (unsigned long *) table->extra1;
2519 max = (unsigned long *) table->extra2;
2520 vleft = table->maxlen / sizeof(unsigned long);
2521 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002522
2523 if (write) {
2524 if (left > PAGE_SIZE - 1)
2525 left = PAGE_SIZE - 1;
2526 page = __get_free_page(GFP_TEMPORARY);
2527 kbuf = (char *) page;
2528 if (!kbuf)
2529 return -ENOMEM;
2530 if (copy_from_user(kbuf, buffer, left)) {
2531 err = -EFAULT;
2532 goto free;
2533 }
2534 kbuf[left] = 0;
2535 }
2536
Eric Dumazet27b3d802010-10-07 12:59:29 -07002537 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002538 unsigned long val;
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002541 bool neg;
2542
2543 left -= proc_skip_spaces(&kbuf);
2544
2545 err = proc_get_long(&kbuf, &left, &val, &neg,
2546 proc_wspace_sep,
2547 sizeof(proc_wspace_sep), NULL);
2548 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 break;
2550 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 continue;
2552 if ((min && val < *min) || (max && val > *max))
2553 continue;
2554 *i = val;
2555 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002556 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002558 err = proc_put_char(&buffer, &left, '\t');
2559 err = proc_put_long(&buffer, &left, val, false);
2560 if (err)
2561 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 }
2563 }
2564
Amerigo Wang00b7c332010-05-05 00:26:45 +00002565 if (!write && !first && left && !err)
2566 err = proc_put_char(&buffer, &left, '\n');
2567 if (write && !err)
2568 left -= proc_skip_spaces(&kbuf);
2569free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002571 free_page(page);
2572 if (first)
2573 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 *lenp -= left;
2576 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002577 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578}
2579
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002580static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002581 void __user *buffer,
2582 size_t *lenp, loff_t *ppos,
2583 unsigned long convmul,
2584 unsigned long convdiv)
2585{
2586 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002587 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002588}
2589
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590/**
2591 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2592 * @table: the sysctl table
2593 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 * @buffer: the user buffer
2595 * @lenp: the size of the user buffer
2596 * @ppos: file position
2597 *
2598 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2599 * values from/to the user buffer, treated as an ASCII string.
2600 *
2601 * This routine will ensure the values are within the range specified by
2602 * table->extra1 (min) and table->extra2 (max).
2603 *
2604 * Returns 0 on success.
2605 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002606int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 void __user *buffer, size_t *lenp, loff_t *ppos)
2608{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002609 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/**
2613 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2614 * @table: the sysctl table
2615 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 * @buffer: the user buffer
2617 * @lenp: the size of the user buffer
2618 * @ppos: file position
2619 *
2620 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2621 * values from/to the user buffer, treated as an ASCII string. The values
2622 * are treated as milliseconds, and converted to jiffies when they are stored.
2623 *
2624 * This routine will ensure the values are within the range specified by
2625 * table->extra1 (min) and table->extra2 (max).
2626 *
2627 * Returns 0 on success.
2628 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002629int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 void __user *buffer,
2631 size_t *lenp, loff_t *ppos)
2632{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002633 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 lenp, ppos, HZ, 1000l);
2635}
2636
2637
Amerigo Wang00b7c332010-05-05 00:26:45 +00002638static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 int *valp,
2640 int write, void *data)
2641{
2642 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002643 if (*lvalp > LONG_MAX / HZ)
2644 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2646 } else {
2647 int val = *valp;
2648 unsigned long lval;
2649 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002650 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 lval = (unsigned long)-val;
2652 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002653 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 lval = (unsigned long)val;
2655 }
2656 *lvalp = lval / HZ;
2657 }
2658 return 0;
2659}
2660
Amerigo Wang00b7c332010-05-05 00:26:45 +00002661static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 int *valp,
2663 int write, void *data)
2664{
2665 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002666 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2667 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2669 } else {
2670 int val = *valp;
2671 unsigned long lval;
2672 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002673 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 lval = (unsigned long)-val;
2675 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002676 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 lval = (unsigned long)val;
2678 }
2679 *lvalp = jiffies_to_clock_t(lval);
2680 }
2681 return 0;
2682}
2683
Amerigo Wang00b7c332010-05-05 00:26:45 +00002684static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 int *valp,
2686 int write, void *data)
2687{
2688 if (write) {
2689 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2690 } else {
2691 int val = *valp;
2692 unsigned long lval;
2693 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002694 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 lval = (unsigned long)-val;
2696 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002697 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 lval = (unsigned long)val;
2699 }
2700 *lvalp = jiffies_to_msecs(lval);
2701 }
2702 return 0;
2703}
2704
2705/**
2706 * proc_dointvec_jiffies - read a vector of integers as seconds
2707 * @table: the sysctl table
2708 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 * @buffer: the user buffer
2710 * @lenp: the size of the user buffer
2711 * @ppos: file position
2712 *
2713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2714 * values from/to the user buffer, treated as an ASCII string.
2715 * The values read are assumed to be in seconds, and are converted into
2716 * jiffies.
2717 *
2718 * Returns 0 on success.
2719 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002720int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 void __user *buffer, size_t *lenp, loff_t *ppos)
2722{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 do_proc_dointvec_jiffies_conv,NULL);
2725}
2726
2727/**
2728 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2729 * @table: the sysctl table
2730 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 * @buffer: the user buffer
2732 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002733 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 *
2735 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2736 * values from/to the user buffer, treated as an ASCII string.
2737 * The values read are assumed to be in 1/USER_HZ seconds, and
2738 * are converted into jiffies.
2739 *
2740 * Returns 0 on success.
2741 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002742int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 void __user *buffer, size_t *lenp, loff_t *ppos)
2744{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002745 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 do_proc_dointvec_userhz_jiffies_conv,NULL);
2747}
2748
2749/**
2750 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2751 * @table: the sysctl table
2752 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 * @buffer: the user buffer
2754 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002755 * @ppos: file position
2756 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 *
2758 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2759 * values from/to the user buffer, treated as an ASCII string.
2760 * The values read are assumed to be in 1/1000 seconds, and
2761 * are converted into jiffies.
2762 *
2763 * Returns 0 on success.
2764 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002765int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 void __user *buffer, size_t *lenp, loff_t *ppos)
2767{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002768 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 do_proc_dointvec_ms_jiffies_conv, NULL);
2770}
2771
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002772static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002773 void __user *buffer, size_t *lenp, loff_t *ppos)
2774{
2775 struct pid *new_pid;
2776 pid_t tmp;
2777 int r;
2778
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002779 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002780
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002781 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002782 lenp, ppos, NULL, NULL);
2783 if (r || !write)
2784 return r;
2785
2786 new_pid = find_get_pid(tmp);
2787 if (!new_pid)
2788 return -ESRCH;
2789
2790 put_pid(xchg(&cad_pid, new_pid));
2791 return 0;
2792}
2793
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002794/**
2795 * proc_do_large_bitmap - read/write from/to a large bitmap
2796 * @table: the sysctl table
2797 * @write: %TRUE if this is a write to the sysctl file
2798 * @buffer: the user buffer
2799 * @lenp: the size of the user buffer
2800 * @ppos: file position
2801 *
2802 * The bitmap is stored at table->data and the bitmap length (in bits)
2803 * in table->maxlen.
2804 *
2805 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2806 * large bitmaps may be represented in a compact manner. Writing into
2807 * the file will clear the bitmap then update it with the given input.
2808 *
2809 * Returns 0 on success.
2810 */
2811int proc_do_large_bitmap(struct ctl_table *table, int write,
2812 void __user *buffer, size_t *lenp, loff_t *ppos)
2813{
2814 int err = 0;
2815 bool first = 1;
2816 size_t left = *lenp;
2817 unsigned long bitmap_len = table->maxlen;
2818 unsigned long *bitmap = (unsigned long *) table->data;
2819 unsigned long *tmp_bitmap = NULL;
2820 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2821
2822 if (!bitmap_len || !left || (*ppos && !write)) {
2823 *lenp = 0;
2824 return 0;
2825 }
2826
2827 if (write) {
2828 unsigned long page = 0;
2829 char *kbuf;
2830
2831 if (left > PAGE_SIZE - 1)
2832 left = PAGE_SIZE - 1;
2833
2834 page = __get_free_page(GFP_TEMPORARY);
2835 kbuf = (char *) page;
2836 if (!kbuf)
2837 return -ENOMEM;
2838 if (copy_from_user(kbuf, buffer, left)) {
2839 free_page(page);
2840 return -EFAULT;
2841 }
2842 kbuf[left] = 0;
2843
2844 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2845 GFP_KERNEL);
2846 if (!tmp_bitmap) {
2847 free_page(page);
2848 return -ENOMEM;
2849 }
2850 proc_skip_char(&kbuf, &left, '\n');
2851 while (!err && left) {
2852 unsigned long val_a, val_b;
2853 bool neg;
2854
2855 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2856 sizeof(tr_a), &c);
2857 if (err)
2858 break;
2859 if (val_a >= bitmap_len || neg) {
2860 err = -EINVAL;
2861 break;
2862 }
2863
2864 val_b = val_a;
2865 if (left) {
2866 kbuf++;
2867 left--;
2868 }
2869
2870 if (c == '-') {
2871 err = proc_get_long(&kbuf, &left, &val_b,
2872 &neg, tr_b, sizeof(tr_b),
2873 &c);
2874 if (err)
2875 break;
2876 if (val_b >= bitmap_len || neg ||
2877 val_a > val_b) {
2878 err = -EINVAL;
2879 break;
2880 }
2881 if (left) {
2882 kbuf++;
2883 left--;
2884 }
2885 }
2886
2887 while (val_a <= val_b)
2888 set_bit(val_a++, tmp_bitmap);
2889
2890 first = 0;
2891 proc_skip_char(&kbuf, &left, '\n');
2892 }
2893 free_page(page);
2894 } else {
2895 unsigned long bit_a, bit_b = 0;
2896
2897 while (left) {
2898 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2899 if (bit_a >= bitmap_len)
2900 break;
2901 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2902 bit_a + 1) - 1;
2903
2904 if (!first) {
2905 err = proc_put_char(&buffer, &left, ',');
2906 if (err)
2907 break;
2908 }
2909 err = proc_put_long(&buffer, &left, bit_a, false);
2910 if (err)
2911 break;
2912 if (bit_a != bit_b) {
2913 err = proc_put_char(&buffer, &left, '-');
2914 if (err)
2915 break;
2916 err = proc_put_long(&buffer, &left, bit_b, false);
2917 if (err)
2918 break;
2919 }
2920
2921 first = 0; bit_b++;
2922 }
2923 if (!err)
2924 err = proc_put_char(&buffer, &left, '\n');
2925 }
2926
2927 if (!err) {
2928 if (write) {
2929 if (*ppos)
2930 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2931 else
2932 memcpy(bitmap, tmp_bitmap,
2933 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2934 }
2935 kfree(tmp_bitmap);
2936 *lenp -= left;
2937 *ppos += *lenp;
2938 return 0;
2939 } else {
2940 kfree(tmp_bitmap);
2941 return err;
2942 }
2943}
2944
Jovi Zhang55610502011-01-12 17:00:45 -08002945#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002947int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 void __user *buffer, size_t *lenp, loff_t *ppos)
2949{
2950 return -ENOSYS;
2951}
2952
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002953int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 void __user *buffer, size_t *lenp, loff_t *ppos)
2955{
2956 return -ENOSYS;
2957}
2958
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002959int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 void __user *buffer, size_t *lenp, loff_t *ppos)
2961{
2962 return -ENOSYS;
2963}
2964
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002965int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 void __user *buffer, size_t *lenp, loff_t *ppos)
2967{
2968 return -ENOSYS;
2969}
2970
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002971int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 void __user *buffer, size_t *lenp, loff_t *ppos)
2973{
2974 return -ENOSYS;
2975}
2976
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002977int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 void __user *buffer, size_t *lenp, loff_t *ppos)
2979{
2980 return -ENOSYS;
2981}
2982
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002983int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 void __user *buffer, size_t *lenp, loff_t *ppos)
2985{
2986 return -ENOSYS;
2987}
2988
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002989int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 void __user *buffer,
2991 size_t *lenp, loff_t *ppos)
2992{
2993 return -ENOSYS;
2994}
2995
2996
Jovi Zhang55610502011-01-12 17:00:45 -08002997#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999/*
3000 * No sense putting this after each symbol definition, twice,
3001 * exception granted :-)
3002 */
3003EXPORT_SYMBOL(proc_dointvec);
3004EXPORT_SYMBOL(proc_dointvec_jiffies);
3005EXPORT_SYMBOL(proc_dointvec_minmax);
3006EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3007EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3008EXPORT_SYMBOL(proc_dostring);
3009EXPORT_SYMBOL(proc_doulongvec_minmax);
3010EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3011EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003012EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013EXPORT_SYMBOL(unregister_sysctl_table);