blob: ad460248acc797cead25c386de00718608b091de [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. Biedermande4e83bd2012-01-06 03:34:20 -0800195static struct ctl_table root_table[1];
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. Biedermande4e83bd2012-01-06 03:34:20 -0800225static struct ctl_table sysctl_base_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
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001750int __init sysctl_init(void)
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001751{
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001752 register_sysctl_table(sysctl_base_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001753 return 0;
1754}
1755
Al Virobfbcf032008-07-27 06:31:22 +01001756static struct ctl_table *is_branch_in(struct ctl_table *branch,
1757 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001758{
1759 struct ctl_table *p;
1760 const char *s = branch->procname;
1761
1762 /* branch should have named subdirectory as its first element */
1763 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001764 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001765
1766 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001767 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001768 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001769
1770 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001771 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001772 if (!p->child)
1773 continue;
1774 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001775 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001776 }
Al Virobfbcf032008-07-27 06:31:22 +01001777 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001778}
1779
1780/* see if attaching q to p would be an improvement */
1781static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1782{
1783 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001784 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001785 int is_better = 0;
1786 int not_in_parent = !p->attached_by;
1787
Al Virobfbcf032008-07-27 06:31:22 +01001788 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001789 if (by == q->attached_by)
1790 is_better = 1;
1791 if (to == p->attached_by)
1792 not_in_parent = 1;
1793 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001794 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001795 }
1796
1797 if (is_better && not_in_parent) {
1798 q->attached_by = by;
1799 q->attached_to = to;
1800 q->parent = p;
1801 }
1802}
1803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001805 * __register_sysctl_paths - register a sysctl hierarchy
1806 * @root: List of sysctl headers to register on
1807 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001808 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 *
1811 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001812 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001814 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1817 * enter a sysctl file
1818 *
1819 * data - a pointer to data for use by proc_handler
1820 *
1821 * maxlen - the maximum size in bytes of the data
1822 *
1823 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1824 *
1825 * child - a pointer to the child sysctl table if this entry is a directory, or
1826 * %NULL.
1827 *
1828 * proc_handler - the text handler routine (described below)
1829 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 * de - for internal use by the sysctl routines
1831 *
1832 * extra1, extra2 - extra pointers usable by the proc handler routines
1833 *
1834 * Leaf nodes in the sysctl tree will be represented by a single file
1835 * under /proc; non-leaf nodes will be represented by directories.
1836 *
1837 * sysctl(2) can automatically manage read and write requests through
1838 * the sysctl table. The data and maxlen fields of the ctl_table
1839 * struct enable minimal validation of the values being written to be
1840 * performed, and the mode field allows minimal authentication.
1841 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 * There must be a proc_handler routine for any terminal nodes
1843 * mirrored under /proc/sys (non-terminals are handled by a built-in
1844 * directory handler). Several default handlers are available to
1845 * cover common cases -
1846 *
1847 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1848 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1849 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1850 *
1851 * It is the handler's job to read the input buffer from user memory
1852 * and process it. The handler should return 0 on success.
1853 *
1854 * This routine returns %NULL on a failure to register, and a pointer
1855 * to the table header on success.
1856 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001857struct ctl_table_header *__register_sysctl_paths(
1858 struct ctl_table_root *root,
1859 struct nsproxy *namespaces,
1860 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862 struct ctl_table_header *header;
1863 struct ctl_table *new, **prevp;
1864 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001865 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001866
1867 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001868 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001869 ;
1870
1871 /*
1872 * For each path component, allocate a 2-element ctl_table array.
1873 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001874 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001875 *
1876 * We allocate everything in one go so that we don't have to
1877 * worry about freeing additional memory in unregister_sysctl_table.
1878 */
1879 header = kzalloc(sizeof(struct ctl_table_header) +
1880 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1881 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001883
1884 new = (struct ctl_table *) (header + 1);
1885
1886 /* Now connect the dots */
1887 prevp = &header->ctl_table;
1888 for (n = 0; n < npath; ++n, ++path) {
1889 /* Copy the procname */
1890 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001891 new->mode = 0555;
1892
1893 *prevp = new;
1894 prevp = &new->child;
1895
1896 new += 2;
1897 }
1898 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001899 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001900
1901 INIT_LIST_HEAD(&header->ctl_entry);
1902 header->used = 0;
1903 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001904 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001905 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001906 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001907#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001908 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001909 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001910 return NULL;
1911 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001912#endif
Al Viro330d57f2005-11-04 10:18:40 +00001913 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001914 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001915 header->attached_by = header->ctl_table;
1916 header->attached_to = root_table;
1917 header->parent = &root_table_header;
1918 for (set = header->set; set; set = set->parent) {
1919 struct ctl_table_header *p;
1920 list_for_each_entry(p, &set->list, ctl_entry) {
1921 if (p->unregistering)
1922 continue;
1923 try_attach(p, header);
1924 }
1925 }
1926 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001927 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001928 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001929
1930 return header;
1931}
1932
1933/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001934 * register_sysctl_table_path - register a sysctl table hierarchy
1935 * @path: The path to the directory the sysctl table is in.
1936 * @table: the top-level table structure
1937 *
1938 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1939 * array. A completely 0 filled entry terminates the table.
1940 *
1941 * See __register_sysctl_paths for more details.
1942 */
1943struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1944 struct ctl_table *table)
1945{
1946 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1947 path, table);
1948}
1949
1950/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001951 * register_sysctl_table - register a sysctl table hierarchy
1952 * @table: the top-level table structure
1953 *
1954 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1955 * array. A completely 0 filled entry terminates the table.
1956 *
1957 * See register_sysctl_paths for more details.
1958 */
1959struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1960{
1961 static const struct ctl_path null_path[] = { {} };
1962
1963 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
1966/**
1967 * unregister_sysctl_table - unregister a sysctl table hierarchy
1968 * @header: the header returned from register_sysctl_table
1969 *
1970 * Unregisters the sysctl table and all children. proc entries may not
1971 * actually be removed until they are no longer used by anyone.
1972 */
1973void unregister_sysctl_table(struct ctl_table_header * header)
1974{
Al Viro330d57f2005-11-04 10:18:40 +00001975 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001976
1977 if (header == NULL)
1978 return;
1979
Al Viro330d57f2005-11-04 10:18:40 +00001980 spin_lock(&sysctl_lock);
1981 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001982 if (!--header->parent->count) {
1983 WARN_ON(1);
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001984 kfree_rcu(header->parent, rcu);
Al Viroae7edec2008-07-15 06:33:31 -04001985 }
Al Virof7e6ced2008-07-15 01:44:23 -04001986 if (!--header->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001987 kfree_rcu(header, rcu);
Al Viro330d57f2005-11-04 10:18:40 +00001988 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989}
1990
Al Viro9043476f2008-07-15 08:54:06 -04001991int sysctl_is_seen(struct ctl_table_header *p)
1992{
1993 struct ctl_table_set *set = p->set;
1994 int res;
1995 spin_lock(&sysctl_lock);
1996 if (p->unregistering)
1997 res = 0;
1998 else if (!set->is_seen)
1999 res = 1;
2000 else
2001 res = set->is_seen(set);
2002 spin_unlock(&sysctl_lock);
2003 return res;
2004}
2005
Al Viro73455092008-07-14 21:22:20 -04002006void setup_sysctl_set(struct ctl_table_set *p,
2007 struct ctl_table_set *parent,
2008 int (*is_seen)(struct ctl_table_set *))
2009{
2010 INIT_LIST_HEAD(&p->list);
2011 p->parent = parent ? parent : &sysctl_table_root.default_set;
2012 p->is_seen = is_seen;
2013}
2014
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002015#endif /* CONFIG_SYSCTL */
2016
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017/*
2018 * /proc/sys support
2019 */
2020
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002021#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002023static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002024 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002025 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002026{
2027 size_t len;
2028 char __user *p;
2029 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002030
2031 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002032 *lenp = 0;
2033 return 0;
2034 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002035
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 if (write) {
2037 len = 0;
2038 p = buffer;
2039 while (len < *lenp) {
2040 if (get_user(c, p++))
2041 return -EFAULT;
2042 if (c == 0 || c == '\n')
2043 break;
2044 len++;
2045 }
2046 if (len >= maxlen)
2047 len = maxlen-1;
2048 if(copy_from_user(data, buffer, len))
2049 return -EFAULT;
2050 ((char *) data)[len] = 0;
2051 *ppos += *lenp;
2052 } else {
2053 len = strlen(data);
2054 if (len > maxlen)
2055 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002056
2057 if (*ppos > len) {
2058 *lenp = 0;
2059 return 0;
2060 }
2061
2062 data += *ppos;
2063 len -= *ppos;
2064
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002065 if (len > *lenp)
2066 len = *lenp;
2067 if (len)
2068 if(copy_to_user(buffer, data, len))
2069 return -EFAULT;
2070 if (len < *lenp) {
2071 if(put_user('\n', ((char __user *) buffer) + len))
2072 return -EFAULT;
2073 len++;
2074 }
2075 *lenp = len;
2076 *ppos += len;
2077 }
2078 return 0;
2079}
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/**
2082 * proc_dostring - read a string sysctl
2083 * @table: the sysctl table
2084 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2088 *
2089 * Reads/writes a string from/to the user buffer. If the kernel
2090 * buffer provided is not large enough to hold the string, the
2091 * string is truncated. The copied string is %NULL-terminated.
2092 * If the string is being read by the user process, it is copied
2093 * and a newline '\n' is added. It is truncated if the buffer is
2094 * not large enough.
2095 *
2096 * Returns 0 on success.
2097 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002098int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 void __user *buffer, size_t *lenp, loff_t *ppos)
2100{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002101 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002102 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
Amerigo Wang00b7c332010-05-05 00:26:45 +00002105static size_t proc_skip_spaces(char **buf)
2106{
2107 size_t ret;
2108 char *tmp = skip_spaces(*buf);
2109 ret = tmp - *buf;
2110 *buf = tmp;
2111 return ret;
2112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002114static void proc_skip_char(char **buf, size_t *size, const char v)
2115{
2116 while (*size) {
2117 if (**buf != v)
2118 break;
2119 (*size)--;
2120 (*buf)++;
2121 }
2122}
2123
Amerigo Wang00b7c332010-05-05 00:26:45 +00002124#define TMPBUFLEN 22
2125/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002126 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002127 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002128 * @buf: a kernel buffer
2129 * @size: size of the kernel buffer
2130 * @val: this is where the number will be stored
2131 * @neg: set to %TRUE if number is negative
2132 * @perm_tr: a vector which contains the allowed trailers
2133 * @perm_tr_len: size of the perm_tr vector
2134 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002136 * In case of success %0 is returned and @buf and @size are updated with
2137 * the amount of bytes read. If @tr is non-NULL and a trailing
2138 * character exists (size is non-zero after returning from this
2139 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002140 */
2141static int proc_get_long(char **buf, size_t *size,
2142 unsigned long *val, bool *neg,
2143 const char *perm_tr, unsigned perm_tr_len, char *tr)
2144{
2145 int len;
2146 char *p, tmp[TMPBUFLEN];
2147
2148 if (!*size)
2149 return -EINVAL;
2150
2151 len = *size;
2152 if (len > TMPBUFLEN - 1)
2153 len = TMPBUFLEN - 1;
2154
2155 memcpy(tmp, *buf, len);
2156
2157 tmp[len] = 0;
2158 p = tmp;
2159 if (*p == '-' && *size > 1) {
2160 *neg = true;
2161 p++;
2162 } else
2163 *neg = false;
2164 if (!isdigit(*p))
2165 return -EINVAL;
2166
2167 *val = simple_strtoul(p, &p, 0);
2168
2169 len = p - tmp;
2170
2171 /* We don't know if the next char is whitespace thus we may accept
2172 * invalid integers (e.g. 1234...a) or two integers instead of one
2173 * (e.g. 123...1). So lets not allow such large numbers. */
2174 if (len == TMPBUFLEN - 1)
2175 return -EINVAL;
2176
2177 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2178 return -EINVAL;
2179
2180 if (tr && (len < *size))
2181 *tr = *p;
2182
2183 *buf += len;
2184 *size -= len;
2185
2186 return 0;
2187}
2188
2189/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002190 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002192 * @buf: the user buffer
2193 * @size: the size of the user buffer
2194 * @val: the integer to be converted
2195 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002197 * In case of success %0 is returned and @buf and @size are updated with
2198 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002199 */
2200static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2201 bool neg)
2202{
2203 int len;
2204 char tmp[TMPBUFLEN], *p = tmp;
2205
2206 sprintf(p, "%s%lu", neg ? "-" : "", val);
2207 len = strlen(tmp);
2208 if (len > *size)
2209 len = *size;
2210 if (copy_to_user(*buf, tmp, len))
2211 return -EFAULT;
2212 *size -= len;
2213 *buf += len;
2214 return 0;
2215}
2216#undef TMPBUFLEN
2217
2218static int proc_put_char(void __user **buf, size_t *size, char c)
2219{
2220 if (*size) {
2221 char __user **buffer = (char __user **)buf;
2222 if (put_user(c, *buffer))
2223 return -EFAULT;
2224 (*size)--, (*buffer)++;
2225 *buf = *buffer;
2226 }
2227 return 0;
2228}
2229
2230static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 int *valp,
2232 int write, void *data)
2233{
2234 if (write) {
2235 *valp = *negp ? -*lvalp : *lvalp;
2236 } else {
2237 int val = *valp;
2238 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 *lvalp = (unsigned long)-val;
2241 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 *lvalp = (unsigned long)val;
2244 }
2245 }
2246 return 0;
2247}
2248
Amerigo Wang00b7c332010-05-05 00:26:45 +00002249static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2250
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002251static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002252 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002253 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002254 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 int write, void *data),
2256 void *data)
2257{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258 int *i, vleft, first = 1, err = 0;
2259 unsigned long page = 0;
2260 size_t left;
2261 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *lenp = 0;
2265 return 0;
2266 }
2267
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002268 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 vleft = table->maxlen / sizeof(*i);
2270 left = *lenp;
2271
2272 if (!conv)
2273 conv = do_proc_dointvec_conv;
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002276 if (left > PAGE_SIZE - 1)
2277 left = PAGE_SIZE - 1;
2278 page = __get_free_page(GFP_TEMPORARY);
2279 kbuf = (char *) page;
2280 if (!kbuf)
2281 return -ENOMEM;
2282 if (copy_from_user(kbuf, buffer, left)) {
2283 err = -EFAULT;
2284 goto free;
2285 }
2286 kbuf[left] = 0;
2287 }
2288
2289 for (; left && vleft--; i++, first=0) {
2290 unsigned long lval;
2291 bool neg;
2292
2293 if (write) {
2294 left -= proc_skip_spaces(&kbuf);
2295
J. R. Okajima563b0462010-05-25 16:10:14 -07002296 if (!left)
2297 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002298 err = proc_get_long(&kbuf, &left, &lval, &neg,
2299 proc_wspace_sep,
2300 sizeof(proc_wspace_sep), NULL);
2301 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 if (conv(&neg, &lval, i, 1, data)) {
2304 err = -EINVAL;
2305 break;
2306 }
2307 } else {
2308 if (conv(&neg, &lval, i, 0, data)) {
2309 err = -EINVAL;
2310 break;
2311 }
2312 if (!first)
2313 err = proc_put_char(&buffer, &left, '\t');
2314 if (err)
2315 break;
2316 err = proc_put_long(&buffer, &left, lval, neg);
2317 if (err)
2318 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002321
2322 if (!write && !first && left && !err)
2323 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002324 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 left -= proc_skip_spaces(&kbuf);
2326free:
2327 if (write) {
2328 free_page(page);
2329 if (first)
2330 return err ? : -EINVAL;
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 *lenp -= left;
2333 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002337static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002340 int write, void *data),
2341 void *data)
2342{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002343 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002344 buffer, lenp, ppos, conv, data);
2345}
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347/**
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: file position
2354 *
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2357 *
2358 * Returns 0 on success.
2359 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002360int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 void __user *buffer, size_t *lenp, loff_t *ppos)
2362{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002363 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 NULL,NULL);
2365}
2366
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002368 * Taint values can only be increased
2369 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002370 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002371static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372 void __user *buffer, size_t *lenp, loff_t *ppos)
2373{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002374 struct ctl_table t;
2375 unsigned long tmptaint = get_taint();
2376 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002377
Bastian Blank91fcd412007-04-23 14:41:14 -07002378 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002379 return -EPERM;
2380
Andi Kleen25ddbb12008-10-15 22:01:41 -07002381 t = *table;
2382 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002383 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002384 if (err < 0)
2385 return err;
2386
2387 if (write) {
2388 /*
2389 * Poor man's atomic or. Not worth adding a primitive
2390 * to everyone's atomic.h for this
2391 */
2392 int i;
2393 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2394 if ((tmptaint >> i) & 1)
2395 add_taint(i);
2396 }
2397 }
2398
2399 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002400}
2401
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002402#ifdef CONFIG_PRINTK
2403static int proc_dmesg_restrict(struct ctl_table *table, int write,
2404 void __user *buffer, size_t *lenp, loff_t *ppos)
2405{
2406 if (write && !capable(CAP_SYS_ADMIN))
2407 return -EPERM;
2408
2409 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2410}
2411#endif
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413struct do_proc_dointvec_minmax_conv_param {
2414 int *min;
2415 int *max;
2416};
2417
Amerigo Wang00b7c332010-05-05 00:26:45 +00002418static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2419 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 int write, void *data)
2421{
2422 struct do_proc_dointvec_minmax_conv_param *param = data;
2423 if (write) {
2424 int val = *negp ? -*lvalp : *lvalp;
2425 if ((param->min && *param->min > val) ||
2426 (param->max && *param->max < val))
2427 return -EINVAL;
2428 *valp = val;
2429 } else {
2430 int val = *valp;
2431 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002432 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 *lvalp = (unsigned long)-val;
2434 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002435 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 *lvalp = (unsigned long)val;
2437 }
2438 }
2439 return 0;
2440}
2441
2442/**
2443 * proc_dointvec_minmax - read a vector of integers with min/max values
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2449 *
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2452 *
2453 * This routine will ensure the values are within the range specified by
2454 * table->extra1 (min) and table->extra2 (max).
2455 *
2456 * Returns 0 on success.
2457 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002458int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *buffer, size_t *lenp, loff_t *ppos)
2460{
2461 struct do_proc_dointvec_minmax_conv_param param = {
2462 .min = (int *) table->extra1,
2463 .max = (int *) table->extra2,
2464 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002465 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 do_proc_dointvec_minmax_conv, &param);
2467}
2468
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002469static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 void __user *buffer,
2471 size_t *lenp, loff_t *ppos,
2472 unsigned long convmul,
2473 unsigned long convdiv)
2474{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002475 unsigned long *i, *min, *max;
2476 int vleft, first = 1, err = 0;
2477 unsigned long page = 0;
2478 size_t left;
2479 char *kbuf;
2480
2481 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 *lenp = 0;
2483 return 0;
2484 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002485
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002486 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 min = (unsigned long *) table->extra1;
2488 max = (unsigned long *) table->extra2;
2489 vleft = table->maxlen / sizeof(unsigned long);
2490 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002491
2492 if (write) {
2493 if (left > PAGE_SIZE - 1)
2494 left = PAGE_SIZE - 1;
2495 page = __get_free_page(GFP_TEMPORARY);
2496 kbuf = (char *) page;
2497 if (!kbuf)
2498 return -ENOMEM;
2499 if (copy_from_user(kbuf, buffer, left)) {
2500 err = -EFAULT;
2501 goto free;
2502 }
2503 kbuf[left] = 0;
2504 }
2505
Eric Dumazet27b3d802010-10-07 12:59:29 -07002506 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002507 unsigned long val;
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002510 bool neg;
2511
2512 left -= proc_skip_spaces(&kbuf);
2513
2514 err = proc_get_long(&kbuf, &left, &val, &neg,
2515 proc_wspace_sep,
2516 sizeof(proc_wspace_sep), NULL);
2517 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 break;
2519 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 continue;
2521 if ((min && val < *min) || (max && val > *max))
2522 continue;
2523 *i = val;
2524 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002525 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002527 err = proc_put_char(&buffer, &left, '\t');
2528 err = proc_put_long(&buffer, &left, val, false);
2529 if (err)
2530 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
2532 }
2533
Amerigo Wang00b7c332010-05-05 00:26:45 +00002534 if (!write && !first && left && !err)
2535 err = proc_put_char(&buffer, &left, '\n');
2536 if (write && !err)
2537 left -= proc_skip_spaces(&kbuf);
2538free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002540 free_page(page);
2541 if (first)
2542 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 *lenp -= left;
2545 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002546 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002549static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002550 void __user *buffer,
2551 size_t *lenp, loff_t *ppos,
2552 unsigned long convmul,
2553 unsigned long convdiv)
2554{
2555 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002556 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002557}
2558
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559/**
2560 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2561 * @table: the sysctl table
2562 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2566 *
2567 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2568 * values from/to the user buffer, treated as an ASCII string.
2569 *
2570 * This routine will ensure the values are within the range specified by
2571 * table->extra1 (min) and table->extra2 (max).
2572 *
2573 * Returns 0 on success.
2574 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002575int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 void __user *buffer, size_t *lenp, loff_t *ppos)
2577{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002578 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579}
2580
2581/**
2582 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2583 * @table: the sysctl table
2584 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2588 *
2589 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2590 * values from/to the user buffer, treated as an ASCII string. The values
2591 * are treated as milliseconds, and converted to jiffies when they are stored.
2592 *
2593 * This routine will ensure the values are within the range specified by
2594 * table->extra1 (min) and table->extra2 (max).
2595 *
2596 * Returns 0 on success.
2597 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002598int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 void __user *buffer,
2600 size_t *lenp, loff_t *ppos)
2601{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002602 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 lenp, ppos, HZ, 1000l);
2604}
2605
2606
Amerigo Wang00b7c332010-05-05 00:26:45 +00002607static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 int *valp,
2609 int write, void *data)
2610{
2611 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002612 if (*lvalp > LONG_MAX / HZ)
2613 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2615 } else {
2616 int val = *valp;
2617 unsigned long lval;
2618 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 lval = (unsigned long)-val;
2621 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002622 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 lval = (unsigned long)val;
2624 }
2625 *lvalp = lval / HZ;
2626 }
2627 return 0;
2628}
2629
Amerigo Wang00b7c332010-05-05 00:26:45 +00002630static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 int *valp,
2632 int write, void *data)
2633{
2634 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002635 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2636 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2638 } else {
2639 int val = *valp;
2640 unsigned long lval;
2641 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002642 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 lval = (unsigned long)-val;
2644 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002645 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 lval = (unsigned long)val;
2647 }
2648 *lvalp = jiffies_to_clock_t(lval);
2649 }
2650 return 0;
2651}
2652
Amerigo Wang00b7c332010-05-05 00:26:45 +00002653static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 int *valp,
2655 int write, void *data)
2656{
2657 if (write) {
2658 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2659 } else {
2660 int val = *valp;
2661 unsigned long lval;
2662 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002663 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 lval = (unsigned long)-val;
2665 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002666 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 lval = (unsigned long)val;
2668 }
2669 *lvalp = jiffies_to_msecs(lval);
2670 }
2671 return 0;
2672}
2673
2674/**
2675 * proc_dointvec_jiffies - read a vector of integers as seconds
2676 * @table: the sysctl table
2677 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 * @buffer: the user buffer
2679 * @lenp: the size of the user buffer
2680 * @ppos: file position
2681 *
2682 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2683 * values from/to the user buffer, treated as an ASCII string.
2684 * The values read are assumed to be in seconds, and are converted into
2685 * jiffies.
2686 *
2687 * Returns 0 on success.
2688 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002689int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 void __user *buffer, size_t *lenp, loff_t *ppos)
2691{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002692 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 do_proc_dointvec_jiffies_conv,NULL);
2694}
2695
2696/**
2697 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2698 * @table: the sysctl table
2699 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 * @buffer: the user buffer
2701 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002702 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 *
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/USER_HZ seconds, and
2707 * are converted into jiffies.
2708 *
2709 * Returns 0 on success.
2710 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 void __user *buffer, size_t *lenp, loff_t *ppos)
2713{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002714 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 do_proc_dointvec_userhz_jiffies_conv,NULL);
2716}
2717
2718/**
2719 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002724 * @ppos: file position
2725 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 *
2727 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2728 * values from/to the user buffer, treated as an ASCII string.
2729 * The values read are assumed to be in 1/1000 seconds, and
2730 * are converted into jiffies.
2731 *
2732 * Returns 0 on success.
2733 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002734int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 void __user *buffer, size_t *lenp, loff_t *ppos)
2736{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002737 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 do_proc_dointvec_ms_jiffies_conv, NULL);
2739}
2740
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002741static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002742 void __user *buffer, size_t *lenp, loff_t *ppos)
2743{
2744 struct pid *new_pid;
2745 pid_t tmp;
2746 int r;
2747
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002748 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002749
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002750 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002751 lenp, ppos, NULL, NULL);
2752 if (r || !write)
2753 return r;
2754
2755 new_pid = find_get_pid(tmp);
2756 if (!new_pid)
2757 return -ESRCH;
2758
2759 put_pid(xchg(&cad_pid, new_pid));
2760 return 0;
2761}
2762
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002763/**
2764 * proc_do_large_bitmap - read/write from/to a large bitmap
2765 * @table: the sysctl table
2766 * @write: %TRUE if this is a write to the sysctl file
2767 * @buffer: the user buffer
2768 * @lenp: the size of the user buffer
2769 * @ppos: file position
2770 *
2771 * The bitmap is stored at table->data and the bitmap length (in bits)
2772 * in table->maxlen.
2773 *
2774 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2775 * large bitmaps may be represented in a compact manner. Writing into
2776 * the file will clear the bitmap then update it with the given input.
2777 *
2778 * Returns 0 on success.
2779 */
2780int proc_do_large_bitmap(struct ctl_table *table, int write,
2781 void __user *buffer, size_t *lenp, loff_t *ppos)
2782{
2783 int err = 0;
2784 bool first = 1;
2785 size_t left = *lenp;
2786 unsigned long bitmap_len = table->maxlen;
2787 unsigned long *bitmap = (unsigned long *) table->data;
2788 unsigned long *tmp_bitmap = NULL;
2789 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2790
2791 if (!bitmap_len || !left || (*ppos && !write)) {
2792 *lenp = 0;
2793 return 0;
2794 }
2795
2796 if (write) {
2797 unsigned long page = 0;
2798 char *kbuf;
2799
2800 if (left > PAGE_SIZE - 1)
2801 left = PAGE_SIZE - 1;
2802
2803 page = __get_free_page(GFP_TEMPORARY);
2804 kbuf = (char *) page;
2805 if (!kbuf)
2806 return -ENOMEM;
2807 if (copy_from_user(kbuf, buffer, left)) {
2808 free_page(page);
2809 return -EFAULT;
2810 }
2811 kbuf[left] = 0;
2812
2813 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2814 GFP_KERNEL);
2815 if (!tmp_bitmap) {
2816 free_page(page);
2817 return -ENOMEM;
2818 }
2819 proc_skip_char(&kbuf, &left, '\n');
2820 while (!err && left) {
2821 unsigned long val_a, val_b;
2822 bool neg;
2823
2824 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2825 sizeof(tr_a), &c);
2826 if (err)
2827 break;
2828 if (val_a >= bitmap_len || neg) {
2829 err = -EINVAL;
2830 break;
2831 }
2832
2833 val_b = val_a;
2834 if (left) {
2835 kbuf++;
2836 left--;
2837 }
2838
2839 if (c == '-') {
2840 err = proc_get_long(&kbuf, &left, &val_b,
2841 &neg, tr_b, sizeof(tr_b),
2842 &c);
2843 if (err)
2844 break;
2845 if (val_b >= bitmap_len || neg ||
2846 val_a > val_b) {
2847 err = -EINVAL;
2848 break;
2849 }
2850 if (left) {
2851 kbuf++;
2852 left--;
2853 }
2854 }
2855
2856 while (val_a <= val_b)
2857 set_bit(val_a++, tmp_bitmap);
2858
2859 first = 0;
2860 proc_skip_char(&kbuf, &left, '\n');
2861 }
2862 free_page(page);
2863 } else {
2864 unsigned long bit_a, bit_b = 0;
2865
2866 while (left) {
2867 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2868 if (bit_a >= bitmap_len)
2869 break;
2870 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2871 bit_a + 1) - 1;
2872
2873 if (!first) {
2874 err = proc_put_char(&buffer, &left, ',');
2875 if (err)
2876 break;
2877 }
2878 err = proc_put_long(&buffer, &left, bit_a, false);
2879 if (err)
2880 break;
2881 if (bit_a != bit_b) {
2882 err = proc_put_char(&buffer, &left, '-');
2883 if (err)
2884 break;
2885 err = proc_put_long(&buffer, &left, bit_b, false);
2886 if (err)
2887 break;
2888 }
2889
2890 first = 0; bit_b++;
2891 }
2892 if (!err)
2893 err = proc_put_char(&buffer, &left, '\n');
2894 }
2895
2896 if (!err) {
2897 if (write) {
2898 if (*ppos)
2899 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2900 else
2901 memcpy(bitmap, tmp_bitmap,
2902 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2903 }
2904 kfree(tmp_bitmap);
2905 *lenp -= left;
2906 *ppos += *lenp;
2907 return 0;
2908 } else {
2909 kfree(tmp_bitmap);
2910 return err;
2911 }
2912}
2913
Jovi Zhang55610502011-01-12 17:00:45 -08002914#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002916int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 void __user *buffer, size_t *lenp, loff_t *ppos)
2918{
2919 return -ENOSYS;
2920}
2921
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002922int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 void __user *buffer, size_t *lenp, loff_t *ppos)
2924{
2925 return -ENOSYS;
2926}
2927
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer, size_t *lenp, loff_t *ppos)
2930{
2931 return -ENOSYS;
2932}
2933
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002934int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 void __user *buffer, size_t *lenp, loff_t *ppos)
2936{
2937 return -ENOSYS;
2938}
2939
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 void __user *buffer, size_t *lenp, loff_t *ppos)
2942{
2943 return -ENOSYS;
2944}
2945
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002946int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *buffer, size_t *lenp, loff_t *ppos)
2948{
2949 return -ENOSYS;
2950}
2951
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002952int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 void __user *buffer, size_t *lenp, loff_t *ppos)
2954{
2955 return -ENOSYS;
2956}
2957
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002958int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 void __user *buffer,
2960 size_t *lenp, loff_t *ppos)
2961{
2962 return -ENOSYS;
2963}
2964
2965
Jovi Zhang55610502011-01-12 17:00:45 -08002966#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968/*
2969 * No sense putting this after each symbol definition, twice,
2970 * exception granted :-)
2971 */
2972EXPORT_SYMBOL(proc_dointvec);
2973EXPORT_SYMBOL(proc_dointvec_jiffies);
2974EXPORT_SYMBOL(proc_dointvec_minmax);
2975EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2976EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2977EXPORT_SYMBOL(proc_dostring);
2978EXPORT_SYMBOL(proc_doulongvec_minmax);
2979EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2980EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002981EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982EXPORT_SYMBOL(unregister_sysctl_table);