blob: ae27196438541384fbfdc1a5c405681169ac8921 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040059#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070060#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#include <asm/uaccess.h>
63#include <asm/processor.h>
64
Andi Kleen29cbc782006-09-30 01:47:55 +020065#ifdef CONFIG_X86
66#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010067#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010068#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020069#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080070#ifdef CONFIG_BSD_PROCESS_ACCT
71#include <linux/acct.h>
72#endif
Dave Young4f0e0562010-03-10 15:24:09 -080073#ifdef CONFIG_RT_MUTEXES
74#include <linux/rtmutex.h>
75#endif
Dave Young2edf5e42010-03-10 15:24:10 -080076#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
77#include <linux/lockdep.h>
78#endif
Dave Young15485a42010-03-10 15:24:07 -080079#ifdef CONFIG_CHR_DEV_SG
80#include <scsi/sg.h>
81#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020082
Don Zickus58687ac2010-05-07 17:11:44 -040083#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050084#include <linux/nmi.h>
85#endif
86
Eric W. Biederman7058cb02007-10-18 03:05:58 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#if defined(CONFIG_SYSCTL)
89
90/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern int sysctl_overcommit_memory;
92extern int sysctl_overcommit_ratio;
93extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070095extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070097extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max;
99extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -0800101extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800102extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200103extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100104extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400105extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000106#ifndef CONFIG_MMU
107extern int sysctl_nr_trim_pages;
108#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200109#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200110extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400114#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200116static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117#endif
118
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700120static int __maybe_unused one = 1;
121static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700122static int __maybe_unused three = 3;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800123static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700125#ifdef CONFIG_PRINTK
126static int ten_thousand = 10000;
127#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700129/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
130static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
133static int maxolduid = 65535;
134static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800135static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700138static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dave Youngd14f1722010-02-25 20:28:57 -0500140#ifdef CONFIG_INOTIFY_USER
141#include <linux/inotify.h>
142#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700143#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700144#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif
146
David S. Miller08714202008-11-16 23:49:24 -0800147#ifdef CONFIG_SPARC64
148extern int sysctl_tsb_ratio;
149#endif
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#ifdef __hppa__
152extern int pwrsw_enabled;
153extern int unaligned_enabled;
154#endif
155
Jes Sorensend2b176e2006-02-28 09:42:23 -0800156#ifdef CONFIG_IA64
157extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800158extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800159#endif
160
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700161#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700162static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700164static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800165 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700166#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700168#ifdef CONFIG_PRINTK
169static int proc_dmesg_restrict(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171#endif
172
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700173#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800174/* Note: sysrq code uses it's own private copy */
175static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700176
177static int sysrq_sysctl_handler(ctl_table *table, int write,
178 void __user *buffer, size_t *lenp,
179 loff_t *ppos)
180{
181 int error;
182
183 error = proc_dointvec(table, write, buffer, lenp, ppos);
184 if (error)
185 return error;
186
187 if (write)
188 sysrq_toggle_support(__sysrq_enabled);
189
190 return 0;
191}
192
193#endif
194
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700195static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196static struct ctl_table_root sysctl_table_root;
197static struct ctl_table_header root_table_header = {
Al Virodfef6dcd32011-03-08 01:25:28 -0500198 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100199 .ctl_table = root_table,
Al Virodfef6dcd32011-03-08 01:25:28 -0500200 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400202 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100203};
204static struct ctl_table_root sysctl_table_root = {
205 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400206 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100207};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700209static struct ctl_table kern_table[];
210static struct ctl_table vm_table[];
211static struct ctl_table fs_table[];
212static struct ctl_table debug_table[];
213static struct ctl_table dev_table[];
214extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800215#ifdef CONFIG_EPOLL
216extern struct ctl_table epoll_table[];
217#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220int sysctl_legacy_va_layout;
221#endif
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/* The default sysctl tables: */
224
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700225static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .procname = "kernel",
228 .mode = 0555,
229 .child = kern_table,
230 },
231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .procname = "vm",
233 .mode = 0555,
234 .child = vm_table,
235 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "fs",
238 .mode = 0555,
239 .child = fs_table,
240 },
241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "debug",
243 .mode = 0555,
244 .child = debug_table,
245 },
246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "dev",
248 .mode = 0555,
249 .child = dev_table,
250 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700251 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100255static int min_sched_granularity_ns = 100000; /* 100 usecs */
256static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257static int min_wakeup_granularity_ns; /* 0 usecs */
258static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100259static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
260static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200261#endif
262
Mel Gorman5e771902010-05-24 14:32:31 -0700263#ifdef CONFIG_COMPACTION
264static int min_extfrag_threshold;
265static int max_extfrag_threshold = 1000;
266#endif
267
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700268static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200269 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200270 .procname = "sched_child_runs_first",
271 .data = &sysctl_sched_child_runs_first,
272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800274 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200275 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200276#ifdef CONFIG_SCHED_DEBUG
277 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100278 .procname = "sched_min_granularity_ns",
279 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800282 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100283 .extra1 = &min_sched_granularity_ns,
284 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200285 },
286 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200287 .procname = "sched_latency_ns",
288 .data = &sysctl_sched_latency,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800291 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200292 .extra1 = &min_sched_granularity_ns,
293 .extra2 = &max_sched_granularity_ns,
294 },
295 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 .procname = "sched_wakeup_granularity_ns",
297 .data = &sysctl_sched_wakeup_granularity,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800300 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 .extra1 = &min_wakeup_granularity_ns,
302 .extra2 = &max_wakeup_granularity_ns,
303 },
304 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100305 .procname = "sched_tunable_scaling",
306 .data = &sysctl_sched_tunable_scaling,
307 .maxlen = sizeof(enum sched_tunable_scaling),
308 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800309 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100310 .extra1 = &min_sched_tunable_scaling,
311 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200312 },
313 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200314 .procname = "sched_migration_cost",
315 .data = &sysctl_sched_migration_cost,
316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800318 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200319 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100320 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800325 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100326 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530327 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200328 .procname = "sched_time_avg",
329 .data = &sysctl_sched_time_avg,
330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800332 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200333 },
334 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800335 .procname = "sched_shares_window",
336 .data = &sysctl_sched_shares_window,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = proc_dointvec,
340 },
341 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530342 .procname = "timer_migration",
343 .data = &sysctl_timer_migration,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800346 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530347 .extra1 = &zero,
348 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530349 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200350#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200351 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100352 .procname = "sched_rt_period_us",
353 .data = &sysctl_sched_rt_period,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800356 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100357 },
358 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100359 .procname = "sched_rt_runtime_us",
360 .data = &sysctl_sched_rt_runtime,
361 .maxlen = sizeof(int),
362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100365#ifdef CONFIG_SCHED_AUTOGROUP
366 {
367 .procname = "sched_autogroup_enabled",
368 .data = &sysctl_sched_autogroup_enabled,
369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800371 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100372 .extra1 = &zero,
373 .extra2 = &one,
374 },
375#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700376#ifdef CONFIG_CFS_BANDWIDTH
377 {
378 .procname = "sched_cfs_bandwidth_slice_us",
379 .data = &sysctl_sched_cfs_bandwidth_slice,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec_minmax,
383 .extra1 = &one,
384 },
385#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700386#ifdef CONFIG_PROVE_LOCKING
387 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800392 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700393 },
394#endif
395#ifdef CONFIG_LOCK_STAT
396 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700397 .procname = "lock_stat",
398 .data = &lock_stat,
399 .maxlen = sizeof(int),
400 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800401 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700402 },
403#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .procname = "panic",
406 .data = &panic_timeout,
407 .maxlen = sizeof(int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 },
411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .procname = "core_uses_pid",
413 .data = &core_uses_pid,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800416 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 },
418 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 .procname = "core_pattern",
420 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700421 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800423 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 },
Neil Hormana2939802009-09-23 15:56:56 -0700425 {
Neil Hormana2939802009-09-23 15:56:56 -0700426 .procname = "core_pipe_limit",
427 .data = &core_pipe_limit,
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800430 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700431 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800432#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700435 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800437 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800439#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100440#ifdef CONFIG_LATENCYTOP
441 {
442 .procname = "latencytop",
443 .data = &latencytop_enabled,
444 .maxlen = sizeof(int),
445 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800446 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100447 },
448#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#ifdef CONFIG_BLK_DEV_INITRD
450 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 .procname = "real-root-dev",
452 .data = &real_root_dev,
453 .maxlen = sizeof(int),
454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800455 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 },
457#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700458 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700459 .procname = "print-fatal-signals",
460 .data = &print_fatal_signals,
461 .maxlen = sizeof(int),
462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800463 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700464 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700465#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "reboot-cmd",
468 .data = reboot_command,
469 .maxlen = 256,
470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800471 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "stop-a",
475 .data = &stop_a_enabled,
476 .maxlen = sizeof (int),
477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800478 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800485 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
487#endif
David S. Miller08714202008-11-16 23:49:24 -0800488#ifdef CONFIG_SPARC64
489 {
David S. Miller08714202008-11-16 23:49:24 -0800490 .procname = "tsb-ratio",
491 .data = &sysctl_tsb_ratio,
492 .maxlen = sizeof (int),
493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800494 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800495 },
496#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#ifdef __hppa__
498 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .procname = "soft-power",
500 .data = &pwrsw_enabled,
501 .maxlen = sizeof (int),
502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800503 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .procname = "unaligned-trap",
507 .data = &unaligned_enabled,
508 .maxlen = sizeof (int),
509 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800510 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 },
512#endif
513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .procname = "ctrl-alt-del",
515 .data = &C_A_D,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400520#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200521 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200522 .procname = "ftrace_enabled",
523 .data = &ftrace_enabled,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200527 },
528#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500529#ifdef CONFIG_STACK_TRACER
530 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500531 .procname = "stack_tracer_enabled",
532 .data = &stack_tracer_enabled,
533 .maxlen = sizeof(int),
534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800535 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500536 },
537#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400538#ifdef CONFIG_TRACING
539 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100540 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400541 .data = &ftrace_dump_on_oops,
542 .maxlen = sizeof(int),
543 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800544 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400545 },
546#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200547#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .procname = "modprobe",
550 .data = &modprobe_path,
551 .maxlen = KMOD_PATH_LEN,
552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800553 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 },
Kees Cook3d433212009-04-02 15:49:29 -0700555 {
Kees Cook3d433212009-04-02 15:49:29 -0700556 .procname = "modules_disabled",
557 .data = &modules_disabled,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800561 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700562 .extra1 = &one,
563 .extra2 = &one,
564 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100566#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100569 .data = &uevent_helper,
570 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800572 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 },
574#endif
575#ifdef CONFIG_CHR_DEV_SG
576 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 .procname = "sg-big-buff",
578 .data = &sg_big_buff,
579 .maxlen = sizeof (int),
580 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800581 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 },
583#endif
584#ifdef CONFIG_BSD_PROCESS_ACCT
585 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .procname = "acct",
587 .data = &acct_parm,
588 .maxlen = 3*sizeof(int),
589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800590 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 },
592#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#ifdef CONFIG_MAGIC_SYSRQ
594 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800596 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .maxlen = sizeof (int),
598 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700599 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 },
601#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700602#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700605 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .maxlen = sizeof (int),
607 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700610#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .procname = "threads-max",
613 .data = &max_threads,
614 .maxlen = sizeof(int),
615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800616 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 },
618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .procname = "random",
620 .mode = 0555,
621 .child = random_table,
622 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 {
Eric Paris17f60a72011-04-01 17:07:50 -0400624 .procname = "usermodehelper",
625 .mode = 0555,
626 .child = usermodehelper_table,
627 },
628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .procname = "overflowuid",
630 .data = &overflowuid,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800633 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .extra1 = &minolduid,
635 .extra2 = &maxolduid,
636 },
637 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 .procname = "overflowgid",
639 .data = &overflowgid,
640 .maxlen = sizeof(int),
641 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800642 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 .extra1 = &minolduid,
644 .extra2 = &maxolduid,
645 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800646#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#ifdef CONFIG_MATHEMU
648 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .procname = "ieee_emulation_warnings",
650 .data = &sysctl_ieee_emulation_warnings,
651 .maxlen = sizeof(int),
652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
655#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200658 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .maxlen = sizeof(int),
660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800661 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
663#endif
664 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 .procname = "pid_max",
666 .data = &pid_max,
667 .maxlen = sizeof (int),
668 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800669 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .extra1 = &pid_max_min,
671 .extra2 = &pid_max_max,
672 },
673 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .procname = "panic_on_oops",
675 .data = &panic_on_oops,
676 .maxlen = sizeof(int),
677 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800678 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800680#if defined CONFIG_PRINTK
681 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800682 .procname = "printk",
683 .data = &console_loglevel,
684 .maxlen = 4*sizeof(int),
685 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800686 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800687 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700690 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .maxlen = sizeof(int),
692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800693 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 },
695 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700697 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .maxlen = sizeof(int),
699 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
Dave Youngaf913222009-09-22 16:43:33 -0700702 {
Dave Youngaf913222009-09-22 16:43:33 -0700703 .procname = "printk_delay",
704 .data = &printk_delay_msec,
705 .maxlen = sizeof(int),
706 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800707 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700708 .extra1 = &zero,
709 .extra2 = &ten_thousand,
710 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800712 .procname = "dmesg_restrict",
713 .data = &dmesg_restrict,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = proc_dointvec_minmax,
717 .extra1 = &zero,
718 .extra2 = &one,
719 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800720 {
721 .procname = "kptr_restrict",
722 .data = &kptr_restrict,
723 .maxlen = sizeof(int),
724 .mode = 0644,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700725 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800726 .extra1 = &zero,
727 .extra2 = &two,
728 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800729#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .procname = "ngroups_max",
732 .data = &ngroups_max,
733 .maxlen = sizeof (int),
734 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800735 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 },
Dan Ballard73efc032011-10-31 17:11:20 -0700737 {
738 .procname = "cap_last_cap",
739 .data = (void *)&cap_last_cap,
740 .maxlen = sizeof(int),
741 .mode = 0444,
742 .proc_handler = proc_dointvec,
743 },
Don Zickus58687ac2010-05-07 17:11:44 -0400744#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500745 {
Don Zickus58687ac2010-05-07 17:11:44 -0400746 .procname = "watchdog",
747 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500748 .maxlen = sizeof (int),
749 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700750 .proc_handler = proc_dowatchdog,
751 .extra1 = &zero,
752 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400753 },
754 {
755 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700756 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400757 .maxlen = sizeof(int),
758 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700759 .proc_handler = proc_dowatchdog,
Don Zickus58687ac2010-05-07 17:11:44 -0400760 .extra1 = &neg_one,
761 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500762 },
Don Zickus2508ce12010-05-07 17:11:46 -0400763 {
764 .procname = "softlockup_panic",
765 .data = &softlockup_panic,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = proc_dointvec_minmax,
769 .extra1 = &zero,
770 .extra2 = &one,
771 },
Don Zickus5dc30552010-11-29 17:07:17 -0500772 {
773 .procname = "nmi_watchdog",
774 .data = &watchdog_enabled,
775 .maxlen = sizeof (int),
776 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700777 .proc_handler = proc_dowatchdog,
778 .extra1 = &zero,
779 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500780 },
781#endif
782#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
783 {
784 .procname = "unknown_nmi_panic",
785 .data = &unknown_nmi_panic,
786 .maxlen = sizeof (int),
787 .mode = 0644,
788 .proc_handler = proc_dointvec,
789 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500790#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791#if defined(CONFIG_X86)
792 {
Don Zickus8da5add2006-09-26 10:52:27 +0200793 .procname = "panic_on_unrecovered_nmi",
794 .data = &panic_on_unrecovered_nmi,
795 .maxlen = sizeof(int),
796 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800797 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200798 },
799 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700800 .procname = "panic_on_io_nmi",
801 .data = &panic_on_io_nmi,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800804 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700805 },
806 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 .procname = "bootloader_type",
808 .data = &bootloader_type,
809 .maxlen = sizeof (int),
810 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800811 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100813 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700814 .procname = "bootloader_version",
815 .data = &bootloader_version,
816 .maxlen = sizeof (int),
817 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800818 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700819 },
820 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100821 .procname = "kstack_depth_to_print",
822 .data = &kstack_depth_to_print,
823 .maxlen = sizeof(int),
824 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800825 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100826 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100827 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100828 .procname = "io_delay_type",
829 .data = &io_delay_type,
830 .maxlen = sizeof(int),
831 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800832 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100833 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800835#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .procname = "randomize_va_space",
838 .data = &randomize_va_space,
839 .maxlen = sizeof(int),
840 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800841 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800843#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800844#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700845 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700846 .procname = "spin_retry",
847 .data = &spin_retry,
848 .maxlen = sizeof (int),
849 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800850 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700851 },
852#endif
Len Brown673d5b42007-07-28 03:33:16 -0400853#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800854 {
Pavel Machekc255d842006-02-20 18:27:58 -0800855 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700856 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800857 .maxlen = sizeof (unsigned long),
858 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800859 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800860 },
861#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800862#ifdef CONFIG_IA64
863 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800864 .procname = "ignore-unaligned-usertrap",
865 .data = &no_unaligned_warning,
866 .maxlen = sizeof (int),
867 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800869 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800870 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800871 .procname = "unaligned-dump-stack",
872 .data = &unaligned_dump_stack,
873 .maxlen = sizeof (int),
874 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800875 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800876 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800877#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800878#ifdef CONFIG_DETECT_HUNG_TASK
879 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800880 .procname = "hung_task_panic",
881 .data = &sysctl_hung_task_panic,
882 .maxlen = sizeof(int),
883 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800884 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800885 .extra1 = &zero,
886 .extra2 = &one,
887 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100888 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100889 .procname = "hung_task_check_count",
890 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100891 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100892 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800893 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100894 },
895 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100896 .procname = "hung_task_timeout_secs",
897 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100898 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100899 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800900 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100901 },
902 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100903 .procname = "hung_task_warnings",
904 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100905 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100906 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800907 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100908 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700909#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200910#ifdef CONFIG_COMPAT
911 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200912 .procname = "compat-log",
913 .data = &compat_log,
914 .maxlen = sizeof (int),
915 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200917 },
918#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700919#ifdef CONFIG_RT_MUTEXES
920 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700921 .procname = "max_lock_depth",
922 .data = &max_lock_depth,
923 .maxlen = sizeof(int),
924 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800925 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700926 },
927#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700928 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700929 .procname = "poweroff_cmd",
930 .data = &poweroff_cmd,
931 .maxlen = POWEROFF_CMD_PATH_LEN,
932 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800933 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700934 },
David Howells0b77f5b2008-04-29 01:01:32 -0700935#ifdef CONFIG_KEYS
936 {
David Howells0b77f5b2008-04-29 01:01:32 -0700937 .procname = "keys",
938 .mode = 0555,
939 .child = key_sysctls,
940 },
941#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700942#ifdef CONFIG_RCU_TORTURE_TEST
943 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700944 .procname = "rcutorture_runnable",
945 .data = &rcutorture_runnable,
946 .maxlen = sizeof(int),
947 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800948 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700949 },
950#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200951#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -0400952 /*
953 * User-space scripts rely on the existence of this file
954 * as a feature check for perf_events being enabled.
955 *
956 * So it's an ABI, do not remove!
957 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200958 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200959 .procname = "perf_event_paranoid",
960 .data = &sysctl_perf_event_paranoid,
961 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200964 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200965 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200966 .procname = "perf_event_mlock_kb",
967 .data = &sysctl_perf_event_mlock,
968 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200969 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800970 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200971 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200972 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200973 .procname = "perf_event_max_sample_rate",
974 .data = &sysctl_perf_event_sample_rate,
975 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200976 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100977 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200978 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200979#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200980#ifdef CONFIG_KMEMCHECK
981 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200982 .procname = "kmemcheck",
983 .data = &kmemcheck_enabled,
984 .maxlen = sizeof(int),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200987 },
988#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200989#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200990 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200991 .procname = "blk_iopoll",
992 .data = &blk_iopoll_enabled,
993 .maxlen = sizeof(int),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200996 },
Jens Axboecb684b52009-09-15 21:53:11 +0200997#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700998 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999};
1000
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001001static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .procname = "overcommit_memory",
1004 .data = &sysctl_overcommit_memory,
1005 .maxlen = sizeof(sysctl_overcommit_memory),
1006 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001007 .proc_handler = proc_dointvec_minmax,
1008 .extra1 = &zero,
1009 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 },
1011 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001012 .procname = "panic_on_oom",
1013 .data = &sysctl_panic_on_oom,
1014 .maxlen = sizeof(sysctl_panic_on_oom),
1015 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001016 .proc_handler = proc_dointvec_minmax,
1017 .extra1 = &zero,
1018 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001019 },
1020 {
David Rientjesfe071d72007-10-16 23:25:56 -07001021 .procname = "oom_kill_allocating_task",
1022 .data = &sysctl_oom_kill_allocating_task,
1023 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1024 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001025 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001026 },
1027 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001028 .procname = "oom_dump_tasks",
1029 .data = &sysctl_oom_dump_tasks,
1030 .maxlen = sizeof(sysctl_oom_dump_tasks),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001033 },
1034 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 .procname = "overcommit_ratio",
1036 .data = &sysctl_overcommit_ratio,
1037 .maxlen = sizeof(sysctl_overcommit_ratio),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 },
1041 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 .procname = "page-cluster",
1043 .data = &page_cluster,
1044 .maxlen = sizeof(int),
1045 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001046 .proc_handler = proc_dointvec_minmax,
1047 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 },
1049 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 .procname = "dirty_background_ratio",
1051 .data = &dirty_background_ratio,
1052 .maxlen = sizeof(dirty_background_ratio),
1053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 .extra1 = &zero,
1056 .extra2 = &one_hundred,
1057 },
1058 {
David Rientjes2da02992009-01-06 14:39:31 -08001059 .procname = "dirty_background_bytes",
1060 .data = &dirty_background_bytes,
1061 .maxlen = sizeof(dirty_background_bytes),
1062 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001064 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "dirty_ratio",
1068 .data = &vm_dirty_ratio,
1069 .maxlen = sizeof(vm_dirty_ratio),
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .extra1 = &zero,
1073 .extra2 = &one_hundred,
1074 },
1075 {
David Rientjes2da02992009-01-06 14:39:31 -08001076 .procname = "dirty_bytes",
1077 .data = &vm_dirty_bytes,
1078 .maxlen = sizeof(vm_dirty_bytes),
1079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001081 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001082 },
1083 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001085 .data = &dirty_writeback_interval,
1086 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001088 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 },
1090 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001092 .data = &dirty_expire_interval,
1093 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001095 .proc_handler = proc_dointvec_minmax,
1096 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 },
1098 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 .procname = "nr_pdflush_threads",
1100 .data = &nr_pdflush_threads,
1101 .maxlen = sizeof nr_pdflush_threads,
1102 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001103 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 },
1105 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 .procname = "swappiness",
1107 .data = &vm_swappiness,
1108 .maxlen = sizeof(vm_swappiness),
1109 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001110 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .extra1 = &zero,
1112 .extra2 = &one_hundred,
1113 },
1114#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001115 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001117 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 .maxlen = sizeof(unsigned long),
1119 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001120 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 .extra1 = (void *)&hugetlb_zero,
1122 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001123 },
1124#ifdef CONFIG_NUMA
1125 {
1126 .procname = "nr_hugepages_mempolicy",
1127 .data = NULL,
1128 .maxlen = sizeof(unsigned long),
1129 .mode = 0644,
1130 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1131 .extra1 = (void *)&hugetlb_zero,
1132 .extra2 = (void *)&hugetlb_infinity,
1133 },
1134#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 .procname = "hugetlb_shm_group",
1137 .data = &sysctl_hugetlb_shm_group,
1138 .maxlen = sizeof(gid_t),
1139 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001140 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 },
Mel Gorman396faf02007-07-17 04:03:13 -07001142 {
Mel Gorman396faf02007-07-17 04:03:13 -07001143 .procname = "hugepages_treat_as_movable",
1144 .data = &hugepages_treat_as_movable,
1145 .maxlen = sizeof(int),
1146 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001147 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001148 },
Adam Litke54f9f802007-10-16 01:26:20 -07001149 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001150 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001151 .data = NULL,
1152 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001153 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001154 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001155 .extra1 = (void *)&hugetlb_zero,
1156 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001157 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158#endif
1159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "lowmem_reserve_ratio",
1161 .data = &sysctl_lowmem_reserve_ratio,
1162 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1163 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001164 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 },
1166 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001167 .procname = "drop_caches",
1168 .data = &sysctl_drop_caches,
1169 .maxlen = sizeof(int),
1170 .mode = 0644,
1171 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001172 .extra1 = &one,
1173 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001174 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001175#ifdef CONFIG_COMPACTION
1176 {
1177 .procname = "compact_memory",
1178 .data = &sysctl_compact_memory,
1179 .maxlen = sizeof(int),
1180 .mode = 0200,
1181 .proc_handler = sysctl_compaction_handler,
1182 },
Mel Gorman5e771902010-05-24 14:32:31 -07001183 {
1184 .procname = "extfrag_threshold",
1185 .data = &sysctl_extfrag_threshold,
1186 .maxlen = sizeof(int),
1187 .mode = 0644,
1188 .proc_handler = sysctl_extfrag_handler,
1189 .extra1 = &min_extfrag_threshold,
1190 .extra2 = &max_extfrag_threshold,
1191 },
1192
Mel Gorman76ab0f52010-05-24 14:32:28 -07001193#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .procname = "min_free_kbytes",
1196 .data = &min_free_kbytes,
1197 .maxlen = sizeof(min_free_kbytes),
1198 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001199 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .extra1 = &zero,
1201 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001202 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001203 .procname = "percpu_pagelist_fraction",
1204 .data = &percpu_pagelist_fraction,
1205 .maxlen = sizeof(percpu_pagelist_fraction),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001208 .extra1 = &min_percpu_pagelist_fract,
1209 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210#ifdef CONFIG_MMU
1211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 .procname = "max_map_count",
1213 .data = &sysctl_max_map_count,
1214 .maxlen = sizeof(sysctl_max_map_count),
1215 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001216 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001217 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001219#else
1220 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001221 .procname = "nr_trim_pages",
1222 .data = &sysctl_nr_trim_pages,
1223 .maxlen = sizeof(sysctl_nr_trim_pages),
1224 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001225 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001226 .extra1 = &zero,
1227 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228#endif
1229 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 .procname = "laptop_mode",
1231 .data = &laptop_mode,
1232 .maxlen = sizeof(laptop_mode),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 },
1236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 .procname = "block_dump",
1238 .data = &block_dump,
1239 .maxlen = sizeof(block_dump),
1240 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001241 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 .extra1 = &zero,
1243 },
1244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 .procname = "vfs_cache_pressure",
1246 .data = &sysctl_vfs_cache_pressure,
1247 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1248 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001249 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 .extra1 = &zero,
1251 },
1252#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1253 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 .procname = "legacy_va_layout",
1255 .data = &sysctl_legacy_va_layout,
1256 .maxlen = sizeof(sysctl_legacy_va_layout),
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#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001262#ifdef CONFIG_NUMA
1263 {
Christoph Lameter17436602006-01-18 17:42:32 -08001264 .procname = "zone_reclaim_mode",
1265 .data = &zone_reclaim_mode,
1266 .maxlen = sizeof(zone_reclaim_mode),
1267 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001268 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001269 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001270 },
Christoph Lameter96146342006-07-03 00:24:13 -07001271 {
Christoph Lameter96146342006-07-03 00:24:13 -07001272 .procname = "min_unmapped_ratio",
1273 .data = &sysctl_min_unmapped_ratio,
1274 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1275 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001276 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001277 .extra1 = &zero,
1278 .extra2 = &one_hundred,
1279 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001280 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001281 .procname = "min_slab_ratio",
1282 .data = &sysctl_min_slab_ratio,
1283 .maxlen = sizeof(sysctl_min_slab_ratio),
1284 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001285 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001286 .extra1 = &zero,
1287 .extra2 = &one_hundred,
1288 },
Christoph Lameter17436602006-01-18 17:42:32 -08001289#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001290#ifdef CONFIG_SMP
1291 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001292 .procname = "stat_interval",
1293 .data = &sysctl_stat_interval,
1294 .maxlen = sizeof(sysctl_stat_interval),
1295 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001296 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001297 },
1298#endif
David Howells6e141542009-12-15 19:27:45 +00001299#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001300 {
Eric Parised032182007-06-28 15:55:21 -04001301 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001302 .data = &dac_mmap_min_addr,
1303 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001304 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001305 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001306 },
David Howells6e141542009-12-15 19:27:45 +00001307#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001308#ifdef CONFIG_NUMA
1309 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001310 .procname = "numa_zonelist_order",
1311 .data = &numa_zonelist_order,
1312 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1313 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001314 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001315 },
1316#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001317#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001318 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001319 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001320 .procname = "vdso_enabled",
1321 .data = &vdso_enabled,
1322 .maxlen = sizeof(vdso_enabled),
1323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001324 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001325 .extra1 = &zero,
1326 },
1327#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001328#ifdef CONFIG_HIGHMEM
1329 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001330 .procname = "highmem_is_dirtyable",
1331 .data = &vm_highmem_is_dirtyable,
1332 .maxlen = sizeof(vm_highmem_is_dirtyable),
1333 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001334 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001335 .extra1 = &zero,
1336 .extra2 = &one,
1337 },
1338#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001339 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001340 .procname = "scan_unevictable_pages",
1341 .data = &scan_unevictable_pages,
1342 .maxlen = sizeof(scan_unevictable_pages),
1343 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001344 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001345 },
Andi Kleen6a460792009-09-16 11:50:15 +02001346#ifdef CONFIG_MEMORY_FAILURE
1347 {
Andi Kleen6a460792009-09-16 11:50:15 +02001348 .procname = "memory_failure_early_kill",
1349 .data = &sysctl_memory_failure_early_kill,
1350 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001353 .extra1 = &zero,
1354 .extra2 = &one,
1355 },
1356 {
Andi Kleen6a460792009-09-16 11:50:15 +02001357 .procname = "memory_failure_recovery",
1358 .data = &sysctl_memory_failure_recovery,
1359 .maxlen = sizeof(sysctl_memory_failure_recovery),
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#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001366 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367};
1368
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001369#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001370static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001371 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001372};
1373#endif
1374
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001375static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 .procname = "inode-nr",
1378 .data = &inodes_stat,
1379 .maxlen = 2*sizeof(int),
1380 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001381 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 },
1383 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 .procname = "inode-state",
1385 .data = &inodes_stat,
1386 .maxlen = 7*sizeof(int),
1387 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001388 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 },
1390 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 .procname = "file-nr",
1392 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001393 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001395 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "file-max",
1399 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001400 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001402 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 },
1404 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001405 .procname = "nr_open",
1406 .data = &sysctl_nr_open,
1407 .maxlen = sizeof(int),
1408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001409 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001410 .extra1 = &sysctl_nr_open_min,
1411 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001412 },
1413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .procname = "dentry-state",
1415 .data = &dentry_stat,
1416 .maxlen = 6*sizeof(int),
1417 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001418 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 },
1420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 .procname = "overflowuid",
1422 .data = &fs_overflowuid,
1423 .maxlen = sizeof(int),
1424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001425 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 .extra1 = &minolduid,
1427 .extra2 = &maxolduid,
1428 },
1429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "overflowgid",
1431 .data = &fs_overflowgid,
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 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001438#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 .procname = "leases-enable",
1441 .data = &leases_enable,
1442 .maxlen = sizeof(int),
1443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001444 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001446#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447#ifdef CONFIG_DNOTIFY
1448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 .procname = "dir-notify-enable",
1450 .data = &dir_notify_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 },
1455#endif
1456#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001457#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 .procname = "lease-break-time",
1460 .data = &lease_break_time,
1461 .maxlen = sizeof(int),
1462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001463 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001465#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001466#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 .procname = "aio-nr",
1469 .data = &aio_nr,
1470 .maxlen = sizeof(aio_nr),
1471 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001472 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 },
1474 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 .procname = "aio-max-nr",
1476 .data = &aio_max_nr,
1477 .maxlen = sizeof(aio_max_nr),
1478 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001479 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001481#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001482#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001483 {
Robert Love0399cb02005-07-13 12:38:18 -04001484 .procname = "inotify",
1485 .mode = 0555,
1486 .child = inotify_table,
1487 },
1488#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001489#ifdef CONFIG_EPOLL
1490 {
1491 .procname = "epoll",
1492 .mode = 0555,
1493 .child = epoll_table,
1494 },
1495#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001497 {
Alan Coxd6e71142005-06-23 00:09:43 -07001498 .procname = "suid_dumpable",
1499 .data = &suid_dumpable,
1500 .maxlen = sizeof(int),
1501 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001502 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001503 .extra1 = &zero,
1504 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001505 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001506#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1507 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001508 .procname = "binfmt_misc",
1509 .mode = 0555,
1510 .child = binfmt_misc_table,
1511 },
1512#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001513 {
Jens Axboeff9da692010-06-03 14:54:39 +02001514 .procname = "pipe-max-size",
1515 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001516 .maxlen = sizeof(int),
1517 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001518 .proc_handler = &pipe_proc_fn,
1519 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001520 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001521 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522};
1523
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001524static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001525#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
Chris Metcalf571d76a2011-05-16 14:23:44 -04001526 defined(CONFIG_S390) || defined(CONFIG_TILE)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001527 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001528 .procname = "exception-trace",
1529 .data = &show_unhandled_signals,
1530 .maxlen = sizeof(int),
1531 .mode = 0644,
1532 .proc_handler = proc_dointvec
1533 },
1534#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001535#if defined(CONFIG_OPTPROBES)
1536 {
1537 .procname = "kprobes-optimization",
1538 .data = &sysctl_kprobes_optimization,
1539 .maxlen = sizeof(int),
1540 .mode = 0644,
1541 .proc_handler = proc_kprobes_optimization_handler,
1542 .extra1 = &zero,
1543 .extra2 = &one,
1544 },
1545#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001546 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547};
1548
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001549static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001550 { }
Robert Love0eeca282005-07-12 17:06:03 -04001551};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Al Viro330d57f2005-11-04 10:18:40 +00001553static DEFINE_SPINLOCK(sysctl_lock);
1554
1555/* called under sysctl_lock */
1556static int use_table(struct ctl_table_header *p)
1557{
1558 if (unlikely(p->unregistering))
1559 return 0;
1560 p->used++;
1561 return 1;
1562}
1563
1564/* called under sysctl_lock */
1565static void unuse_table(struct ctl_table_header *p)
1566{
1567 if (!--p->used)
1568 if (unlikely(p->unregistering))
1569 complete(p->unregistering);
1570}
1571
1572/* called under sysctl_lock, will reacquire if has to wait */
1573static void start_unregistering(struct ctl_table_header *p)
1574{
1575 /*
1576 * if p->used is 0, nobody will ever touch that entry again;
1577 * we'll eliminate all paths to it before dropping sysctl_lock
1578 */
1579 if (unlikely(p->used)) {
1580 struct completion wait;
1581 init_completion(&wait);
1582 p->unregistering = &wait;
1583 spin_unlock(&sysctl_lock);
1584 wait_for_completion(&wait);
1585 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001586 } else {
1587 /* anything non-NULL; we'll never dereference it */
1588 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001589 }
1590 /*
1591 * do not remove from the list until nobody holds it; walking the
1592 * list in do_sysctl() relies on that.
1593 */
1594 list_del_init(&p->ctl_entry);
1595}
1596
Al Virof7e6ced2008-07-15 01:44:23 -04001597void sysctl_head_get(struct ctl_table_header *head)
1598{
1599 spin_lock(&sysctl_lock);
1600 head->count++;
1601 spin_unlock(&sysctl_lock);
1602}
1603
1604void sysctl_head_put(struct ctl_table_header *head)
1605{
1606 spin_lock(&sysctl_lock);
1607 if (!--head->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001608 kfree_rcu(head, rcu);
Al Virof7e6ced2008-07-15 01:44:23 -04001609 spin_unlock(&sysctl_lock);
1610}
1611
1612struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1613{
1614 if (!head)
1615 BUG();
1616 spin_lock(&sysctl_lock);
1617 if (!use_table(head))
1618 head = ERR_PTR(-ENOENT);
1619 spin_unlock(&sysctl_lock);
1620 return head;
1621}
1622
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001623void sysctl_head_finish(struct ctl_table_header *head)
1624{
1625 if (!head)
1626 return;
1627 spin_lock(&sysctl_lock);
1628 unuse_table(head);
1629 spin_unlock(&sysctl_lock);
1630}
1631
Al Viro73455092008-07-14 21:22:20 -04001632static struct ctl_table_set *
1633lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1634{
1635 struct ctl_table_set *set = &root->default_set;
1636 if (root->lookup)
1637 set = root->lookup(root, namespaces);
1638 return set;
1639}
1640
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001641static struct list_head *
1642lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001643{
Al Viro73455092008-07-14 21:22:20 -04001644 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1645 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001646}
1647
1648struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1649 struct ctl_table_header *prev)
1650{
1651 struct ctl_table_root *root;
1652 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001653 struct ctl_table_header *head;
1654 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001655
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001656 spin_lock(&sysctl_lock);
1657 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001658 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001659 tmp = &prev->ctl_entry;
1660 unuse_table(prev);
1661 goto next;
1662 }
1663 tmp = &root_table_header.ctl_entry;
1664 for (;;) {
1665 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1666
1667 if (!use_table(head))
1668 goto next;
1669 spin_unlock(&sysctl_lock);
1670 return head;
1671 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001672 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001673 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001674 header_list = lookup_header_list(root, namespaces);
1675 if (tmp != header_list)
1676 continue;
1677
1678 do {
1679 root = list_entry(root->root_list.next,
1680 struct ctl_table_root, root_list);
1681 if (root == &sysctl_table_root)
1682 goto out;
1683 header_list = lookup_header_list(root, namespaces);
1684 } while (list_empty(header_list));
1685 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001686 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001687out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001688 spin_unlock(&sysctl_lock);
1689 return NULL;
1690}
1691
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001692struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1693{
1694 return __sysctl_head_next(current->nsproxy, prev);
1695}
1696
1697void register_sysctl_root(struct ctl_table_root *root)
1698{
1699 spin_lock(&sysctl_lock);
1700 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1701 spin_unlock(&sysctl_lock);
1702}
1703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001705 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 * some sysctl variables are readonly even to root.
1707 */
1708
1709static int test_perm(int mode, int op)
1710{
David Howells76aac0e2008-11-14 10:39:12 +11001711 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 mode >>= 6;
1713 else if (in_egroup_p(0))
1714 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001715 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 return 0;
1717 return -EACCES;
1718}
1719
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001720int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001722 int mode;
1723
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001724 if (root->permissions)
1725 mode = root->permissions(root, current->nsproxy, table);
1726 else
1727 mode = table->mode;
1728
1729 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001732static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1733{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001734 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001735 table->parent = parent;
1736 if (table->child)
1737 sysctl_set_parent(table, table->child);
1738 }
1739}
1740
1741static __init int sysctl_init(void)
1742{
1743 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001744#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001745 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001746#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001747 return 0;
1748}
1749
1750core_initcall(sysctl_init);
1751
Al Virobfbcf032008-07-27 06:31:22 +01001752static struct ctl_table *is_branch_in(struct ctl_table *branch,
1753 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001754{
1755 struct ctl_table *p;
1756 const char *s = branch->procname;
1757
1758 /* branch should have named subdirectory as its first element */
1759 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001760 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001761
1762 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001763 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001764 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001765
1766 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001767 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001768 if (!p->child)
1769 continue;
1770 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001771 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001772 }
Al Virobfbcf032008-07-27 06:31:22 +01001773 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001774}
1775
1776/* see if attaching q to p would be an improvement */
1777static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1778{
1779 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001780 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001781 int is_better = 0;
1782 int not_in_parent = !p->attached_by;
1783
Al Virobfbcf032008-07-27 06:31:22 +01001784 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001785 if (by == q->attached_by)
1786 is_better = 1;
1787 if (to == p->attached_by)
1788 not_in_parent = 1;
1789 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001790 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001791 }
1792
1793 if (is_better && not_in_parent) {
1794 q->attached_by = by;
1795 q->attached_to = to;
1796 q->parent = p;
1797 }
1798}
1799
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001801 * __register_sysctl_paths - register a sysctl hierarchy
1802 * @root: List of sysctl headers to register on
1803 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001804 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 *
1807 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001808 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001810 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1813 * enter a sysctl file
1814 *
1815 * data - a pointer to data for use by proc_handler
1816 *
1817 * maxlen - the maximum size in bytes of the data
1818 *
1819 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1820 *
1821 * child - a pointer to the child sysctl table if this entry is a directory, or
1822 * %NULL.
1823 *
1824 * proc_handler - the text handler routine (described below)
1825 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 * de - for internal use by the sysctl routines
1827 *
1828 * extra1, extra2 - extra pointers usable by the proc handler routines
1829 *
1830 * Leaf nodes in the sysctl tree will be represented by a single file
1831 * under /proc; non-leaf nodes will be represented by directories.
1832 *
1833 * sysctl(2) can automatically manage read and write requests through
1834 * the sysctl table. The data and maxlen fields of the ctl_table
1835 * struct enable minimal validation of the values being written to be
1836 * performed, and the mode field allows minimal authentication.
1837 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 * There must be a proc_handler routine for any terminal nodes
1839 * mirrored under /proc/sys (non-terminals are handled by a built-in
1840 * directory handler). Several default handlers are available to
1841 * cover common cases -
1842 *
1843 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1844 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1845 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1846 *
1847 * It is the handler's job to read the input buffer from user memory
1848 * and process it. The handler should return 0 on success.
1849 *
1850 * This routine returns %NULL on a failure to register, and a pointer
1851 * to the table header on success.
1852 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001853struct ctl_table_header *__register_sysctl_paths(
1854 struct ctl_table_root *root,
1855 struct nsproxy *namespaces,
1856 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001858 struct ctl_table_header *header;
1859 struct ctl_table *new, **prevp;
1860 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001861 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862
1863 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001864 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001865 ;
1866
1867 /*
1868 * For each path component, allocate a 2-element ctl_table array.
1869 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001870 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001871 *
1872 * We allocate everything in one go so that we don't have to
1873 * worry about freeing additional memory in unregister_sysctl_table.
1874 */
1875 header = kzalloc(sizeof(struct ctl_table_header) +
1876 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1877 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001879
1880 new = (struct ctl_table *) (header + 1);
1881
1882 /* Now connect the dots */
1883 prevp = &header->ctl_table;
1884 for (n = 0; n < npath; ++n, ++path) {
1885 /* Copy the procname */
1886 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001887 new->mode = 0555;
1888
1889 *prevp = new;
1890 prevp = &new->child;
1891
1892 new += 2;
1893 }
1894 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001895 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001896
1897 INIT_LIST_HEAD(&header->ctl_entry);
1898 header->used = 0;
1899 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001900 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001901 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001902 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001903#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001904 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001905 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001906 return NULL;
1907 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001908#endif
Al Viro330d57f2005-11-04 10:18:40 +00001909 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001910 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001911 header->attached_by = header->ctl_table;
1912 header->attached_to = root_table;
1913 header->parent = &root_table_header;
1914 for (set = header->set; set; set = set->parent) {
1915 struct ctl_table_header *p;
1916 list_for_each_entry(p, &set->list, ctl_entry) {
1917 if (p->unregistering)
1918 continue;
1919 try_attach(p, header);
1920 }
1921 }
1922 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001923 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001924 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001925
1926 return header;
1927}
1928
1929/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001930 * register_sysctl_table_path - register a sysctl table hierarchy
1931 * @path: The path to the directory the sysctl table is in.
1932 * @table: the top-level table structure
1933 *
1934 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1935 * array. A completely 0 filled entry terminates the table.
1936 *
1937 * See __register_sysctl_paths for more details.
1938 */
1939struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1940 struct ctl_table *table)
1941{
1942 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1943 path, table);
1944}
1945
1946/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001947 * register_sysctl_table - register a sysctl table hierarchy
1948 * @table: the top-level table structure
1949 *
1950 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1951 * array. A completely 0 filled entry terminates the table.
1952 *
1953 * See register_sysctl_paths for more details.
1954 */
1955struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1956{
1957 static const struct ctl_path null_path[] = { {} };
1958
1959 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/**
1963 * unregister_sysctl_table - unregister a sysctl table hierarchy
1964 * @header: the header returned from register_sysctl_table
1965 *
1966 * Unregisters the sysctl table and all children. proc entries may not
1967 * actually be removed until they are no longer used by anyone.
1968 */
1969void unregister_sysctl_table(struct ctl_table_header * header)
1970{
Al Viro330d57f2005-11-04 10:18:40 +00001971 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001972
1973 if (header == NULL)
1974 return;
1975
Al Viro330d57f2005-11-04 10:18:40 +00001976 spin_lock(&sysctl_lock);
1977 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001978 if (!--header->parent->count) {
1979 WARN_ON(1);
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001980 kfree_rcu(header->parent, rcu);
Al Viroae7edec2008-07-15 06:33:31 -04001981 }
Al Virof7e6ced2008-07-15 01:44:23 -04001982 if (!--header->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001983 kfree_rcu(header, rcu);
Al Viro330d57f2005-11-04 10:18:40 +00001984 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
Al Viro90434762008-07-15 08:54:06 -04001987int sysctl_is_seen(struct ctl_table_header *p)
1988{
1989 struct ctl_table_set *set = p->set;
1990 int res;
1991 spin_lock(&sysctl_lock);
1992 if (p->unregistering)
1993 res = 0;
1994 else if (!set->is_seen)
1995 res = 1;
1996 else
1997 res = set->is_seen(set);
1998 spin_unlock(&sysctl_lock);
1999 return res;
2000}
2001
Al Viro73455092008-07-14 21:22:20 -04002002void setup_sysctl_set(struct ctl_table_set *p,
2003 struct ctl_table_set *parent,
2004 int (*is_seen)(struct ctl_table_set *))
2005{
2006 INIT_LIST_HEAD(&p->list);
2007 p->parent = parent ? parent : &sysctl_table_root.default_set;
2008 p->is_seen = is_seen;
2009}
2010
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002011#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002012struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002013{
2014 return NULL;
2015}
2016
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002017struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2018 struct ctl_table *table)
2019{
2020 return NULL;
2021}
2022
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002023void unregister_sysctl_table(struct ctl_table_header * table)
2024{
2025}
2026
Al Viro73455092008-07-14 21:22:20 -04002027void setup_sysctl_set(struct ctl_table_set *p,
2028 struct ctl_table_set *parent,
2029 int (*is_seen)(struct ctl_table_set *))
2030{
2031}
2032
Al Virof7e6ced2008-07-15 01:44:23 -04002033void sysctl_head_put(struct ctl_table_header *head)
2034{
2035}
2036
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002037#endif /* CONFIG_SYSCTL */
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039/*
2040 * /proc/sys support
2041 */
2042
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002043#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002045static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002046 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002047 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002048{
2049 size_t len;
2050 char __user *p;
2051 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002052
2053 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002054 *lenp = 0;
2055 return 0;
2056 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002057
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002058 if (write) {
2059 len = 0;
2060 p = buffer;
2061 while (len < *lenp) {
2062 if (get_user(c, p++))
2063 return -EFAULT;
2064 if (c == 0 || c == '\n')
2065 break;
2066 len++;
2067 }
2068 if (len >= maxlen)
2069 len = maxlen-1;
2070 if(copy_from_user(data, buffer, len))
2071 return -EFAULT;
2072 ((char *) data)[len] = 0;
2073 *ppos += *lenp;
2074 } else {
2075 len = strlen(data);
2076 if (len > maxlen)
2077 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002078
2079 if (*ppos > len) {
2080 *lenp = 0;
2081 return 0;
2082 }
2083
2084 data += *ppos;
2085 len -= *ppos;
2086
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002087 if (len > *lenp)
2088 len = *lenp;
2089 if (len)
2090 if(copy_to_user(buffer, data, len))
2091 return -EFAULT;
2092 if (len < *lenp) {
2093 if(put_user('\n', ((char __user *) buffer) + len))
2094 return -EFAULT;
2095 len++;
2096 }
2097 *lenp = len;
2098 *ppos += len;
2099 }
2100 return 0;
2101}
2102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103/**
2104 * proc_dostring - read a string sysctl
2105 * @table: the sysctl table
2106 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 * @buffer: the user buffer
2108 * @lenp: the size of the user buffer
2109 * @ppos: file position
2110 *
2111 * Reads/writes a string from/to the user buffer. If the kernel
2112 * buffer provided is not large enough to hold the string, the
2113 * string is truncated. The copied string is %NULL-terminated.
2114 * If the string is being read by the user process, it is copied
2115 * and a newline '\n' is added. It is truncated if the buffer is
2116 * not large enough.
2117 *
2118 * Returns 0 on success.
2119 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002120int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 void __user *buffer, size_t *lenp, loff_t *ppos)
2122{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002123 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002124 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
Amerigo Wang00b7c332010-05-05 00:26:45 +00002127static size_t proc_skip_spaces(char **buf)
2128{
2129 size_t ret;
2130 char *tmp = skip_spaces(*buf);
2131 ret = tmp - *buf;
2132 *buf = tmp;
2133 return ret;
2134}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002136static void proc_skip_char(char **buf, size_t *size, const char v)
2137{
2138 while (*size) {
2139 if (**buf != v)
2140 break;
2141 (*size)--;
2142 (*buf)++;
2143 }
2144}
2145
Amerigo Wang00b7c332010-05-05 00:26:45 +00002146#define TMPBUFLEN 22
2147/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002148 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002149 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002150 * @buf: a kernel buffer
2151 * @size: size of the kernel buffer
2152 * @val: this is where the number will be stored
2153 * @neg: set to %TRUE if number is negative
2154 * @perm_tr: a vector which contains the allowed trailers
2155 * @perm_tr_len: size of the perm_tr vector
2156 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002157 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002158 * In case of success %0 is returned and @buf and @size are updated with
2159 * the amount of bytes read. If @tr is non-NULL and a trailing
2160 * character exists (size is non-zero after returning from this
2161 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002162 */
2163static int proc_get_long(char **buf, size_t *size,
2164 unsigned long *val, bool *neg,
2165 const char *perm_tr, unsigned perm_tr_len, char *tr)
2166{
2167 int len;
2168 char *p, tmp[TMPBUFLEN];
2169
2170 if (!*size)
2171 return -EINVAL;
2172
2173 len = *size;
2174 if (len > TMPBUFLEN - 1)
2175 len = TMPBUFLEN - 1;
2176
2177 memcpy(tmp, *buf, len);
2178
2179 tmp[len] = 0;
2180 p = tmp;
2181 if (*p == '-' && *size > 1) {
2182 *neg = true;
2183 p++;
2184 } else
2185 *neg = false;
2186 if (!isdigit(*p))
2187 return -EINVAL;
2188
2189 *val = simple_strtoul(p, &p, 0);
2190
2191 len = p - tmp;
2192
2193 /* We don't know if the next char is whitespace thus we may accept
2194 * invalid integers (e.g. 1234...a) or two integers instead of one
2195 * (e.g. 123...1). So lets not allow such large numbers. */
2196 if (len == TMPBUFLEN - 1)
2197 return -EINVAL;
2198
2199 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2200 return -EINVAL;
2201
2202 if (tr && (len < *size))
2203 *tr = *p;
2204
2205 *buf += len;
2206 *size -= len;
2207
2208 return 0;
2209}
2210
2211/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002212 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002213 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002214 * @buf: the user buffer
2215 * @size: the size of the user buffer
2216 * @val: the integer to be converted
2217 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002218 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002219 * In case of success %0 is returned and @buf and @size are updated with
2220 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002221 */
2222static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2223 bool neg)
2224{
2225 int len;
2226 char tmp[TMPBUFLEN], *p = tmp;
2227
2228 sprintf(p, "%s%lu", neg ? "-" : "", val);
2229 len = strlen(tmp);
2230 if (len > *size)
2231 len = *size;
2232 if (copy_to_user(*buf, tmp, len))
2233 return -EFAULT;
2234 *size -= len;
2235 *buf += len;
2236 return 0;
2237}
2238#undef TMPBUFLEN
2239
2240static int proc_put_char(void __user **buf, size_t *size, char c)
2241{
2242 if (*size) {
2243 char __user **buffer = (char __user **)buf;
2244 if (put_user(c, *buffer))
2245 return -EFAULT;
2246 (*size)--, (*buffer)++;
2247 *buf = *buffer;
2248 }
2249 return 0;
2250}
2251
2252static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 int *valp,
2254 int write, void *data)
2255{
2256 if (write) {
2257 *valp = *negp ? -*lvalp : *lvalp;
2258 } else {
2259 int val = *valp;
2260 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002261 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 *lvalp = (unsigned long)-val;
2263 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002264 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 *lvalp = (unsigned long)val;
2266 }
2267 }
2268 return 0;
2269}
2270
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2272
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002273static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002274 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002275 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002276 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 int write, void *data),
2278 void *data)
2279{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002280 int *i, vleft, first = 1, err = 0;
2281 unsigned long page = 0;
2282 size_t left;
2283 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Amerigo Wang00b7c332010-05-05 00:26:45 +00002285 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 *lenp = 0;
2287 return 0;
2288 }
2289
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002290 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 vleft = table->maxlen / sizeof(*i);
2292 left = *lenp;
2293
2294 if (!conv)
2295 conv = do_proc_dointvec_conv;
2296
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002298 if (left > PAGE_SIZE - 1)
2299 left = PAGE_SIZE - 1;
2300 page = __get_free_page(GFP_TEMPORARY);
2301 kbuf = (char *) page;
2302 if (!kbuf)
2303 return -ENOMEM;
2304 if (copy_from_user(kbuf, buffer, left)) {
2305 err = -EFAULT;
2306 goto free;
2307 }
2308 kbuf[left] = 0;
2309 }
2310
2311 for (; left && vleft--; i++, first=0) {
2312 unsigned long lval;
2313 bool neg;
2314
2315 if (write) {
2316 left -= proc_skip_spaces(&kbuf);
2317
J. R. Okajima563b0462010-05-25 16:10:14 -07002318 if (!left)
2319 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002320 err = proc_get_long(&kbuf, &left, &lval, &neg,
2321 proc_wspace_sep,
2322 sizeof(proc_wspace_sep), NULL);
2323 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 if (conv(&neg, &lval, i, 1, data)) {
2326 err = -EINVAL;
2327 break;
2328 }
2329 } else {
2330 if (conv(&neg, &lval, i, 0, data)) {
2331 err = -EINVAL;
2332 break;
2333 }
2334 if (!first)
2335 err = proc_put_char(&buffer, &left, '\t');
2336 if (err)
2337 break;
2338 err = proc_put_long(&buffer, &left, lval, neg);
2339 if (err)
2340 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 }
2342 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343
2344 if (!write && !first && left && !err)
2345 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002346 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002347 left -= proc_skip_spaces(&kbuf);
2348free:
2349 if (write) {
2350 free_page(page);
2351 if (first)
2352 return err ? : -EINVAL;
2353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 *lenp -= left;
2355 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002356 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002359static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002360 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002361 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002362 int write, void *data),
2363 void *data)
2364{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002365 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002366 buffer, lenp, ppos, conv, data);
2367}
2368
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369/**
2370 * proc_dointvec - read a vector of integers
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 * @buffer: the user buffer
2374 * @lenp: the size of the user buffer
2375 * @ppos: file position
2376 *
2377 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2378 * values from/to the user buffer, treated as an ASCII string.
2379 *
2380 * Returns 0 on success.
2381 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002382int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 void __user *buffer, size_t *lenp, loff_t *ppos)
2384{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002385 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 NULL,NULL);
2387}
2388
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002389/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002390 * Taint values can only be increased
2391 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002392 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002393static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002394 void __user *buffer, size_t *lenp, loff_t *ppos)
2395{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002396 struct ctl_table t;
2397 unsigned long tmptaint = get_taint();
2398 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002399
Bastian Blank91fcd412007-04-23 14:41:14 -07002400 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002401 return -EPERM;
2402
Andi Kleen25ddbb12008-10-15 22:01:41 -07002403 t = *table;
2404 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002405 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002406 if (err < 0)
2407 return err;
2408
2409 if (write) {
2410 /*
2411 * Poor man's atomic or. Not worth adding a primitive
2412 * to everyone's atomic.h for this
2413 */
2414 int i;
2415 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2416 if ((tmptaint >> i) & 1)
2417 add_taint(i);
2418 }
2419 }
2420
2421 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002422}
2423
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002424#ifdef CONFIG_PRINTK
2425static int proc_dmesg_restrict(struct ctl_table *table, int write,
2426 void __user *buffer, size_t *lenp, loff_t *ppos)
2427{
2428 if (write && !capable(CAP_SYS_ADMIN))
2429 return -EPERM;
2430
2431 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2432}
2433#endif
2434
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435struct do_proc_dointvec_minmax_conv_param {
2436 int *min;
2437 int *max;
2438};
2439
Amerigo Wang00b7c332010-05-05 00:26:45 +00002440static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2441 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 int write, void *data)
2443{
2444 struct do_proc_dointvec_minmax_conv_param *param = data;
2445 if (write) {
2446 int val = *negp ? -*lvalp : *lvalp;
2447 if ((param->min && *param->min > val) ||
2448 (param->max && *param->max < val))
2449 return -EINVAL;
2450 *valp = val;
2451 } else {
2452 int val = *valp;
2453 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002454 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 *lvalp = (unsigned long)-val;
2456 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002457 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 *lvalp = (unsigned long)val;
2459 }
2460 }
2461 return 0;
2462}
2463
2464/**
2465 * proc_dointvec_minmax - read a vector of integers with min/max values
2466 * @table: the sysctl table
2467 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: file position
2471 *
2472 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2473 * values from/to the user buffer, treated as an ASCII string.
2474 *
2475 * This routine will ensure the values are within the range specified by
2476 * table->extra1 (min) and table->extra2 (max).
2477 *
2478 * Returns 0 on success.
2479 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002480int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 void __user *buffer, size_t *lenp, loff_t *ppos)
2482{
2483 struct do_proc_dointvec_minmax_conv_param param = {
2484 .min = (int *) table->extra1,
2485 .max = (int *) table->extra2,
2486 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002487 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 do_proc_dointvec_minmax_conv, &param);
2489}
2490
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002491static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 void __user *buffer,
2493 size_t *lenp, loff_t *ppos,
2494 unsigned long convmul,
2495 unsigned long convdiv)
2496{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002497 unsigned long *i, *min, *max;
2498 int vleft, first = 1, err = 0;
2499 unsigned long page = 0;
2500 size_t left;
2501 char *kbuf;
2502
2503 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 *lenp = 0;
2505 return 0;
2506 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002507
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002508 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 min = (unsigned long *) table->extra1;
2510 max = (unsigned long *) table->extra2;
2511 vleft = table->maxlen / sizeof(unsigned long);
2512 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513
2514 if (write) {
2515 if (left > PAGE_SIZE - 1)
2516 left = PAGE_SIZE - 1;
2517 page = __get_free_page(GFP_TEMPORARY);
2518 kbuf = (char *) page;
2519 if (!kbuf)
2520 return -ENOMEM;
2521 if (copy_from_user(kbuf, buffer, left)) {
2522 err = -EFAULT;
2523 goto free;
2524 }
2525 kbuf[left] = 0;
2526 }
2527
Eric Dumazet27b3d802010-10-07 12:59:29 -07002528 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002529 unsigned long val;
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002532 bool neg;
2533
2534 left -= proc_skip_spaces(&kbuf);
2535
2536 err = proc_get_long(&kbuf, &left, &val, &neg,
2537 proc_wspace_sep,
2538 sizeof(proc_wspace_sep), NULL);
2539 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 break;
2541 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 continue;
2543 if ((min && val < *min) || (max && val > *max))
2544 continue;
2545 *i = val;
2546 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002547 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002549 err = proc_put_char(&buffer, &left, '\t');
2550 err = proc_put_long(&buffer, &left, val, false);
2551 if (err)
2552 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 }
2554 }
2555
Amerigo Wang00b7c332010-05-05 00:26:45 +00002556 if (!write && !first && left && !err)
2557 err = proc_put_char(&buffer, &left, '\n');
2558 if (write && !err)
2559 left -= proc_skip_spaces(&kbuf);
2560free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002562 free_page(page);
2563 if (first)
2564 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 *lenp -= left;
2567 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002568 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569}
2570
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002571static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002572 void __user *buffer,
2573 size_t *lenp, loff_t *ppos,
2574 unsigned long convmul,
2575 unsigned long convdiv)
2576{
2577 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002578 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002579}
2580
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581/**
2582 * proc_doulongvec_minmax - read a vector of long integers 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.
2591 *
2592 * This routine will ensure the values are within the range specified by
2593 * table->extra1 (min) and table->extra2 (max).
2594 *
2595 * Returns 0 on success.
2596 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002597int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 void __user *buffer, size_t *lenp, loff_t *ppos)
2599{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002600 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601}
2602
2603/**
2604 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
2609 * @ppos: file position
2610 *
2611 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2612 * values from/to the user buffer, treated as an ASCII string. The values
2613 * are treated as milliseconds, and converted to jiffies when they are stored.
2614 *
2615 * This routine will ensure the values are within the range specified by
2616 * table->extra1 (min) and table->extra2 (max).
2617 *
2618 * Returns 0 on success.
2619 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002620int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 void __user *buffer,
2622 size_t *lenp, loff_t *ppos)
2623{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002624 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 lenp, ppos, HZ, 1000l);
2626}
2627
2628
Amerigo Wang00b7c332010-05-05 00:26:45 +00002629static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 int *valp,
2631 int write, void *data)
2632{
2633 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002634 if (*lvalp > LONG_MAX / HZ)
2635 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2637 } else {
2638 int val = *valp;
2639 unsigned long lval;
2640 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002641 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 lval = (unsigned long)-val;
2643 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002644 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 lval = (unsigned long)val;
2646 }
2647 *lvalp = lval / HZ;
2648 }
2649 return 0;
2650}
2651
Amerigo Wang00b7c332010-05-05 00:26:45 +00002652static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 int *valp,
2654 int write, void *data)
2655{
2656 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002657 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2658 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2660 } else {
2661 int val = *valp;
2662 unsigned long lval;
2663 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002664 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 lval = (unsigned long)-val;
2666 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002667 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 lval = (unsigned long)val;
2669 }
2670 *lvalp = jiffies_to_clock_t(lval);
2671 }
2672 return 0;
2673}
2674
Amerigo Wang00b7c332010-05-05 00:26:45 +00002675static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 int *valp,
2677 int write, void *data)
2678{
2679 if (write) {
2680 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2681 } else {
2682 int val = *valp;
2683 unsigned long lval;
2684 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002685 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 lval = (unsigned long)-val;
2687 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002688 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 lval = (unsigned long)val;
2690 }
2691 *lvalp = jiffies_to_msecs(lval);
2692 }
2693 return 0;
2694}
2695
2696/**
2697 * proc_dointvec_jiffies - read a vector of integers as 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
2702 * @ppos: file position
2703 *
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 seconds, and are converted into
2707 * jiffies.
2708 *
2709 * Returns 0 on success.
2710 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711int proc_dointvec_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_jiffies_conv,NULL);
2716}
2717
2718/**
2719 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
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
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002724 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 *
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in 1/USER_HZ seconds, and
2729 * are converted into jiffies.
2730 *
2731 * Returns 0 on success.
2732 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002733int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 void __user *buffer, size_t *lenp, loff_t *ppos)
2735{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002736 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 do_proc_dointvec_userhz_jiffies_conv,NULL);
2738}
2739
2740/**
2741 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002746 * @ppos: file position
2747 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 *
2749 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2750 * values from/to the user buffer, treated as an ASCII string.
2751 * The values read are assumed to be in 1/1000 seconds, and
2752 * are converted into jiffies.
2753 *
2754 * Returns 0 on success.
2755 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002756int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 void __user *buffer, size_t *lenp, loff_t *ppos)
2758{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002759 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 do_proc_dointvec_ms_jiffies_conv, NULL);
2761}
2762
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002763static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002764 void __user *buffer, size_t *lenp, loff_t *ppos)
2765{
2766 struct pid *new_pid;
2767 pid_t tmp;
2768 int r;
2769
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002770 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002771
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002772 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002773 lenp, ppos, NULL, NULL);
2774 if (r || !write)
2775 return r;
2776
2777 new_pid = find_get_pid(tmp);
2778 if (!new_pid)
2779 return -ESRCH;
2780
2781 put_pid(xchg(&cad_pid, new_pid));
2782 return 0;
2783}
2784
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002785/**
2786 * proc_do_large_bitmap - read/write from/to a large bitmap
2787 * @table: the sysctl table
2788 * @write: %TRUE if this is a write to the sysctl file
2789 * @buffer: the user buffer
2790 * @lenp: the size of the user buffer
2791 * @ppos: file position
2792 *
2793 * The bitmap is stored at table->data and the bitmap length (in bits)
2794 * in table->maxlen.
2795 *
2796 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2797 * large bitmaps may be represented in a compact manner. Writing into
2798 * the file will clear the bitmap then update it with the given input.
2799 *
2800 * Returns 0 on success.
2801 */
2802int proc_do_large_bitmap(struct ctl_table *table, int write,
2803 void __user *buffer, size_t *lenp, loff_t *ppos)
2804{
2805 int err = 0;
2806 bool first = 1;
2807 size_t left = *lenp;
2808 unsigned long bitmap_len = table->maxlen;
2809 unsigned long *bitmap = (unsigned long *) table->data;
2810 unsigned long *tmp_bitmap = NULL;
2811 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2812
2813 if (!bitmap_len || !left || (*ppos && !write)) {
2814 *lenp = 0;
2815 return 0;
2816 }
2817
2818 if (write) {
2819 unsigned long page = 0;
2820 char *kbuf;
2821
2822 if (left > PAGE_SIZE - 1)
2823 left = PAGE_SIZE - 1;
2824
2825 page = __get_free_page(GFP_TEMPORARY);
2826 kbuf = (char *) page;
2827 if (!kbuf)
2828 return -ENOMEM;
2829 if (copy_from_user(kbuf, buffer, left)) {
2830 free_page(page);
2831 return -EFAULT;
2832 }
2833 kbuf[left] = 0;
2834
2835 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2836 GFP_KERNEL);
2837 if (!tmp_bitmap) {
2838 free_page(page);
2839 return -ENOMEM;
2840 }
2841 proc_skip_char(&kbuf, &left, '\n');
2842 while (!err && left) {
2843 unsigned long val_a, val_b;
2844 bool neg;
2845
2846 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2847 sizeof(tr_a), &c);
2848 if (err)
2849 break;
2850 if (val_a >= bitmap_len || neg) {
2851 err = -EINVAL;
2852 break;
2853 }
2854
2855 val_b = val_a;
2856 if (left) {
2857 kbuf++;
2858 left--;
2859 }
2860
2861 if (c == '-') {
2862 err = proc_get_long(&kbuf, &left, &val_b,
2863 &neg, tr_b, sizeof(tr_b),
2864 &c);
2865 if (err)
2866 break;
2867 if (val_b >= bitmap_len || neg ||
2868 val_a > val_b) {
2869 err = -EINVAL;
2870 break;
2871 }
2872 if (left) {
2873 kbuf++;
2874 left--;
2875 }
2876 }
2877
2878 while (val_a <= val_b)
2879 set_bit(val_a++, tmp_bitmap);
2880
2881 first = 0;
2882 proc_skip_char(&kbuf, &left, '\n');
2883 }
2884 free_page(page);
2885 } else {
2886 unsigned long bit_a, bit_b = 0;
2887
2888 while (left) {
2889 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2890 if (bit_a >= bitmap_len)
2891 break;
2892 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2893 bit_a + 1) - 1;
2894
2895 if (!first) {
2896 err = proc_put_char(&buffer, &left, ',');
2897 if (err)
2898 break;
2899 }
2900 err = proc_put_long(&buffer, &left, bit_a, false);
2901 if (err)
2902 break;
2903 if (bit_a != bit_b) {
2904 err = proc_put_char(&buffer, &left, '-');
2905 if (err)
2906 break;
2907 err = proc_put_long(&buffer, &left, bit_b, false);
2908 if (err)
2909 break;
2910 }
2911
2912 first = 0; bit_b++;
2913 }
2914 if (!err)
2915 err = proc_put_char(&buffer, &left, '\n');
2916 }
2917
2918 if (!err) {
2919 if (write) {
2920 if (*ppos)
2921 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2922 else
2923 memcpy(bitmap, tmp_bitmap,
2924 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2925 }
2926 kfree(tmp_bitmap);
2927 *lenp -= left;
2928 *ppos += *lenp;
2929 return 0;
2930 } else {
2931 kfree(tmp_bitmap);
2932 return err;
2933 }
2934}
2935
Jovi Zhang55610502011-01-12 17:00:45 -08002936#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002938int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 void __user *buffer, size_t *lenp, loff_t *ppos)
2940{
2941 return -ENOSYS;
2942}
2943
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002944int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 void __user *buffer, size_t *lenp, loff_t *ppos)
2946{
2947 return -ENOSYS;
2948}
2949
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002950int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 void __user *buffer, size_t *lenp, loff_t *ppos)
2952{
2953 return -ENOSYS;
2954}
2955
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002956int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 void __user *buffer, size_t *lenp, loff_t *ppos)
2958{
2959 return -ENOSYS;
2960}
2961
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002962int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 void __user *buffer, size_t *lenp, loff_t *ppos)
2964{
2965 return -ENOSYS;
2966}
2967
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002968int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 void __user *buffer, size_t *lenp, loff_t *ppos)
2970{
2971 return -ENOSYS;
2972}
2973
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002974int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 void __user *buffer, size_t *lenp, loff_t *ppos)
2976{
2977 return -ENOSYS;
2978}
2979
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002980int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 void __user *buffer,
2982 size_t *lenp, loff_t *ppos)
2983{
2984 return -ENOSYS;
2985}
2986
2987
Jovi Zhang55610502011-01-12 17:00:45 -08002988#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990/*
2991 * No sense putting this after each symbol definition, twice,
2992 * exception granted :-)
2993 */
2994EXPORT_SYMBOL(proc_dointvec);
2995EXPORT_SYMBOL(proc_dointvec_jiffies);
2996EXPORT_SYMBOL(proc_dointvec_minmax);
2997EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2998EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2999EXPORT_SYMBOL(proc_dostring);
3000EXPORT_SYMBOL(proc_doulongvec_minmax);
3001EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3002EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003003EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004EXPORT_SYMBOL(unregister_sysctl_table);