blob: 97ab1690f5ed4678d48caa75ed3b71ac5e3970dd [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/uaccess.h>
61#include <asm/processor.h>
62
Andi Kleen29cbc782006-09-30 01:47:55 +020063#ifdef CONFIG_X86
64#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010065#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010066#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020067#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080068#ifdef CONFIG_BSD_PROCESS_ACCT
69#include <linux/acct.h>
70#endif
Dave Young4f0e0562010-03-10 15:24:09 -080071#ifdef CONFIG_RT_MUTEXES
72#include <linux/rtmutex.h>
73#endif
Dave Young2edf5e42010-03-10 15:24:10 -080074#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75#include <linux/lockdep.h>
76#endif
Dave Young15485a42010-03-10 15:24:07 -080077#ifdef CONFIG_CHR_DEV_SG
78#include <scsi/sg.h>
79#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020080
Don Zickus58687ac2010-05-07 17:11:44 -040081#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050082#include <linux/nmi.h>
83#endif
84
Eric W. Biederman7058cb02007-10-18 03:05:58 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#if defined(CONFIG_SYSCTL)
87
88/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern int sysctl_overcommit_memory;
90extern int sysctl_overcommit_ratio;
91extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070093extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070095extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern int pid_max;
97extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080099extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800100extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200101extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100102extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400103extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000104#ifndef CONFIG_MMU
105extern int sysctl_nr_trim_pages;
106#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200107#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200108extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400112#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200114static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115#endif
116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700118static int __maybe_unused one = 1;
119static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700120static int __maybe_unused three = 3;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800121static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700123#ifdef CONFIG_PRINTK
124static int ten_thousand = 10000;
125#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700126
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700127/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131static int maxolduid = 65535;
132static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800133static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135static int ngroups_max = NGROUPS_MAX;
136
Dave Youngd14f1722010-02-25 20:28:57 -0500137#ifdef CONFIG_INOTIFY_USER
138#include <linux/inotify.h>
139#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700140#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700141#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
David S. Miller08714202008-11-16 23:49:24 -0800144#ifdef CONFIG_SPARC64
145extern int sysctl_tsb_ratio;
146#endif
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef __hppa__
149extern int pwrsw_enabled;
150extern int unaligned_enabled;
151#endif
152
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800153#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#ifdef CONFIG_MATHEMU
155extern int sysctl_ieee_emulation_warnings;
156#endif
157extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700158extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#endif
160
Jes Sorensend2b176e2006-02-28 09:42:23 -0800161#ifdef CONFIG_IA64
162extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800163extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800164#endif
165
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700166#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700168 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800170 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700171#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700172
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 Virodfef6dc2011-03-08 01:25:28 -0500198 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100199 .ctl_table = root_table,
Al Virodfef6dc2011-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
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700376#ifdef CONFIG_PROVE_LOCKING
377 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700378 .procname = "prove_locking",
379 .data = &prove_locking,
380 .maxlen = sizeof(int),
381 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800382 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700383 },
384#endif
385#ifdef CONFIG_LOCK_STAT
386 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700387 .procname = "lock_stat",
388 .data = &lock_stat,
389 .maxlen = sizeof(int),
390 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800391 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700392 },
393#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200394 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 .procname = "panic",
396 .data = &panic_timeout,
397 .maxlen = sizeof(int),
398 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800399 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 },
401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .procname = "core_uses_pid",
403 .data = &core_uses_pid,
404 .maxlen = sizeof(int),
405 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800406 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 },
408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .procname = "core_pattern",
410 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700411 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800413 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 },
Neil Hormana2939802009-09-23 15:56:56 -0700415 {
Neil Hormana2939802009-09-23 15:56:56 -0700416 .procname = "core_pipe_limit",
417 .data = &core_pipe_limit,
418 .maxlen = sizeof(unsigned int),
419 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800420 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700421 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800422#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700425 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800426 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800427 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800429#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100430#ifdef CONFIG_LATENCYTOP
431 {
432 .procname = "latencytop",
433 .data = &latencytop_enabled,
434 .maxlen = sizeof(int),
435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100437 },
438#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#ifdef CONFIG_BLK_DEV_INITRD
440 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .procname = "real-root-dev",
442 .data = &real_root_dev,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800445 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 },
447#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700448 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700449 .procname = "print-fatal-signals",
450 .data = &print_fatal_signals,
451 .maxlen = sizeof(int),
452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800453 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700454 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700455#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "reboot-cmd",
458 .data = reboot_command,
459 .maxlen = 256,
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "stop-a",
465 .data = &stop_a_enabled,
466 .maxlen = sizeof (int),
467 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800468 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 .procname = "scons-poweroff",
472 .data = &scons_pwroff,
473 .maxlen = sizeof (int),
474 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800475 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 },
477#endif
David S. Miller08714202008-11-16 23:49:24 -0800478#ifdef CONFIG_SPARC64
479 {
David S. Miller08714202008-11-16 23:49:24 -0800480 .procname = "tsb-ratio",
481 .data = &sysctl_tsb_ratio,
482 .maxlen = sizeof (int),
483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800484 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800485 },
486#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487#ifdef __hppa__
488 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 .procname = "soft-power",
490 .data = &pwrsw_enabled,
491 .maxlen = sizeof (int),
492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 },
495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "unaligned-trap",
497 .data = &unaligned_enabled,
498 .maxlen = sizeof (int),
499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800500 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 },
502#endif
503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .procname = "ctrl-alt-del",
505 .data = &C_A_D,
506 .maxlen = sizeof(int),
507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800508 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400510#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200511 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200512 .procname = "ftrace_enabled",
513 .data = &ftrace_enabled,
514 .maxlen = sizeof(int),
515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800516 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200517 },
518#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500519#ifdef CONFIG_STACK_TRACER
520 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500521 .procname = "stack_tracer_enabled",
522 .data = &stack_tracer_enabled,
523 .maxlen = sizeof(int),
524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800525 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500526 },
527#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400528#ifdef CONFIG_TRACING
529 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100530 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400531 .data = &ftrace_dump_on_oops,
532 .maxlen = sizeof(int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400535 },
536#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200537#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "modprobe",
540 .data = &modprobe_path,
541 .maxlen = KMOD_PATH_LEN,
542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800543 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 },
Kees Cook3d433212009-04-02 15:49:29 -0700545 {
Kees Cook3d433212009-04-02 15:49:29 -0700546 .procname = "modules_disabled",
547 .data = &modules_disabled,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800551 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700552 .extra1 = &one,
553 .extra2 = &one,
554 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100556#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100559 .data = &uevent_helper,
560 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800562 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 },
564#endif
565#ifdef CONFIG_CHR_DEV_SG
566 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .procname = "sg-big-buff",
568 .data = &sg_big_buff,
569 .maxlen = sizeof (int),
570 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800571 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 },
573#endif
574#ifdef CONFIG_BSD_PROCESS_ACCT
575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 .procname = "acct",
577 .data = &acct_parm,
578 .maxlen = 3*sizeof(int),
579 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800580 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 },
582#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#ifdef CONFIG_MAGIC_SYSRQ
584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800586 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .maxlen = sizeof (int),
588 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700589 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 },
591#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700592#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700595 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 .maxlen = sizeof (int),
597 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800598 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700600#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .procname = "threads-max",
603 .data = &max_threads,
604 .maxlen = sizeof(int),
605 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800606 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 },
608 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .procname = "random",
610 .mode = 0555,
611 .child = random_table,
612 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "overflowuid",
615 .data = &overflowuid,
616 .maxlen = sizeof(int),
617 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800618 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
621 },
622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 .procname = "overflowgid",
624 .data = &overflowgid,
625 .maxlen = sizeof(int),
626 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800627 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .extra1 = &minolduid,
629 .extra2 = &maxolduid,
630 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800631#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#ifdef CONFIG_MATHEMU
633 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .procname = "ieee_emulation_warnings",
635 .data = &sysctl_ieee_emulation_warnings,
636 .maxlen = sizeof(int),
637 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800638 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 },
640#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200643 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 .maxlen = sizeof(int),
645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800646 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 },
648#endif
649 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 .procname = "pid_max",
651 .data = &pid_max,
652 .maxlen = sizeof (int),
653 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800654 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .extra1 = &pid_max_min,
656 .extra2 = &pid_max_max,
657 },
658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .procname = "panic_on_oops",
660 .data = &panic_on_oops,
661 .maxlen = sizeof(int),
662 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800663 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800665#if defined CONFIG_PRINTK
666 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800671 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700675 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .maxlen = sizeof(int),
677 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800678 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 },
680 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700682 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .maxlen = sizeof(int),
684 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800685 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 },
Dave Youngaf913222009-09-22 16:43:33 -0700687 {
Dave Youngaf913222009-09-22 16:43:33 -0700688 .procname = "printk_delay",
689 .data = &printk_delay_msec,
690 .maxlen = sizeof(int),
691 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800692 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700693 .extra1 = &zero,
694 .extra2 = &ten_thousand,
695 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800697 .procname = "dmesg_restrict",
698 .data = &dmesg_restrict,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = proc_dointvec_minmax,
702 .extra1 = &zero,
703 .extra2 = &one,
704 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800705 {
706 .procname = "kptr_restrict",
707 .data = &kptr_restrict,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = proc_dointvec_minmax,
711 .extra1 = &zero,
712 .extra2 = &two,
713 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800714#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .procname = "ngroups_max",
717 .data = &ngroups_max,
718 .maxlen = sizeof (int),
719 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800720 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 },
Don Zickus58687ac2010-05-07 17:11:44 -0400722#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500723 {
Don Zickus58687ac2010-05-07 17:11:44 -0400724 .procname = "watchdog",
725 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500726 .maxlen = sizeof (int),
727 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400728 .proc_handler = proc_dowatchdog_enabled,
729 },
730 {
731 .procname = "watchdog_thresh",
732 .data = &softlockup_thresh,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = proc_dowatchdog_thresh,
736 .extra1 = &neg_one,
737 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500738 },
Don Zickus2508ce12010-05-07 17:11:46 -0400739 {
740 .procname = "softlockup_panic",
741 .data = &softlockup_panic,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec_minmax,
745 .extra1 = &zero,
746 .extra2 = &one,
747 },
Don Zickus5dc30552010-11-29 17:07:17 -0500748 {
749 .procname = "nmi_watchdog",
750 .data = &watchdog_enabled,
751 .maxlen = sizeof (int),
752 .mode = 0644,
753 .proc_handler = proc_dowatchdog_enabled,
754 },
755#endif
756#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
757 {
758 .procname = "unknown_nmi_panic",
759 .data = &unknown_nmi_panic,
760 .maxlen = sizeof (int),
761 .mode = 0644,
762 .proc_handler = proc_dointvec,
763 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500764#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765#if defined(CONFIG_X86)
766 {
Don Zickus8da5add2006-09-26 10:52:27 +0200767 .procname = "panic_on_unrecovered_nmi",
768 .data = &panic_on_unrecovered_nmi,
769 .maxlen = sizeof(int),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200772 },
773 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700774 .procname = "panic_on_io_nmi",
775 .data = &panic_on_io_nmi,
776 .maxlen = sizeof(int),
777 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800778 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700779 },
780 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 .procname = "bootloader_type",
782 .data = &bootloader_type,
783 .maxlen = sizeof (int),
784 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800785 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100787 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700788 .procname = "bootloader_version",
789 .data = &bootloader_version,
790 .maxlen = sizeof (int),
791 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700793 },
794 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100795 .procname = "kstack_depth_to_print",
796 .data = &kstack_depth_to_print,
797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100800 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100801 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100802 .procname = "io_delay_type",
803 .data = &io_delay_type,
804 .maxlen = sizeof(int),
805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800806 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100807 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800809#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .procname = "randomize_va_space",
812 .data = &randomize_va_space,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800817#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800818#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700819 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700820 .procname = "spin_retry",
821 .data = &spin_retry,
822 .maxlen = sizeof (int),
823 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800824 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700825 },
826#endif
Len Brown673d5b42007-07-28 03:33:16 -0400827#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800828 {
Pavel Machekc255d842006-02-20 18:27:58 -0800829 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700830 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800831 .maxlen = sizeof (unsigned long),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800834 },
835#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800836#ifdef CONFIG_IA64
837 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800838 .procname = "ignore-unaligned-usertrap",
839 .data = &no_unaligned_warning,
840 .maxlen = sizeof (int),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800843 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800844 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800845 .procname = "unaligned-dump-stack",
846 .data = &unaligned_dump_stack,
847 .maxlen = sizeof (int),
848 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800849 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800850 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800851#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800852#ifdef CONFIG_DETECT_HUNG_TASK
853 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800854 .procname = "hung_task_panic",
855 .data = &sysctl_hung_task_panic,
856 .maxlen = sizeof(int),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800859 .extra1 = &zero,
860 .extra2 = &one,
861 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100862 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 .procname = "hung_task_check_count",
864 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100865 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100866 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800867 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 },
869 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100870 .procname = "hung_task_timeout_secs",
871 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100872 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100873 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800874 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 },
876 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100877 .procname = "hung_task_warnings",
878 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100879 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100880 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800881 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700883#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200884#ifdef CONFIG_COMPAT
885 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200886 .procname = "compat-log",
887 .data = &compat_log,
888 .maxlen = sizeof (int),
889 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800890 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200891 },
892#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700893#ifdef CONFIG_RT_MUTEXES
894 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700895 .procname = "max_lock_depth",
896 .data = &max_lock_depth,
897 .maxlen = sizeof(int),
898 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800899 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700900 },
901#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700902 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700903 .procname = "poweroff_cmd",
904 .data = &poweroff_cmd,
905 .maxlen = POWEROFF_CMD_PATH_LEN,
906 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800907 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700908 },
David Howells0b77f5b2008-04-29 01:01:32 -0700909#ifdef CONFIG_KEYS
910 {
David Howells0b77f5b2008-04-29 01:01:32 -0700911 .procname = "keys",
912 .mode = 0555,
913 .child = key_sysctls,
914 },
915#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700916#ifdef CONFIG_RCU_TORTURE_TEST
917 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700918 .procname = "rcutorture_runnable",
919 .data = &rcutorture_runnable,
920 .maxlen = sizeof(int),
921 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800922 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700923 },
924#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200925#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200926 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200927 .procname = "perf_event_paranoid",
928 .data = &sysctl_perf_event_paranoid,
929 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200930 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800931 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200932 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200933 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200934 .procname = "perf_event_mlock_kb",
935 .data = &sysctl_perf_event_mlock,
936 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200937 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800938 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200939 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200940 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200941 .procname = "perf_event_max_sample_rate",
942 .data = &sysctl_perf_event_sample_rate,
943 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200944 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100945 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200946 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200947#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200948#ifdef CONFIG_KMEMCHECK
949 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200950 .procname = "kmemcheck",
951 .data = &kmemcheck_enabled,
952 .maxlen = sizeof(int),
953 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800954 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200955 },
956#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200957#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200958 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200959 .procname = "blk_iopoll",
960 .data = &blk_iopoll_enabled,
961 .maxlen = sizeof(int),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200964 },
Jens Axboecb684b52009-09-15 21:53:11 +0200965#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700966 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967};
968
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700969static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 .procname = "overcommit_memory",
972 .data = &sysctl_overcommit_memory,
973 .maxlen = sizeof(sysctl_overcommit_memory),
974 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700975 .proc_handler = proc_dointvec_minmax,
976 .extra1 = &zero,
977 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 },
979 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700980 .procname = "panic_on_oom",
981 .data = &sysctl_panic_on_oom,
982 .maxlen = sizeof(sysctl_panic_on_oom),
983 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700984 .proc_handler = proc_dointvec_minmax,
985 .extra1 = &zero,
986 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700987 },
988 {
David Rientjesfe071d72007-10-16 23:25:56 -0700989 .procname = "oom_kill_allocating_task",
990 .data = &sysctl_oom_kill_allocating_task,
991 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
992 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800993 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700994 },
995 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800996 .procname = "oom_dump_tasks",
997 .data = &sysctl_oom_dump_tasks,
998 .maxlen = sizeof(sysctl_oom_dump_tasks),
999 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001001 },
1002 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .procname = "overcommit_ratio",
1004 .data = &sysctl_overcommit_ratio,
1005 .maxlen = sizeof(sysctl_overcommit_ratio),
1006 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001007 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 },
1009 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 .procname = "page-cluster",
1011 .data = &page_cluster,
1012 .maxlen = sizeof(int),
1013 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001014 .proc_handler = proc_dointvec_minmax,
1015 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 },
1017 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .procname = "dirty_background_ratio",
1019 .data = &dirty_background_ratio,
1020 .maxlen = sizeof(dirty_background_ratio),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .extra1 = &zero,
1024 .extra2 = &one_hundred,
1025 },
1026 {
David Rientjes2da02992009-01-06 14:39:31 -08001027 .procname = "dirty_background_bytes",
1028 .data = &dirty_background_bytes,
1029 .maxlen = sizeof(dirty_background_bytes),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001032 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001033 },
1034 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 .procname = "dirty_ratio",
1036 .data = &vm_dirty_ratio,
1037 .maxlen = sizeof(vm_dirty_ratio),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .extra1 = &zero,
1041 .extra2 = &one_hundred,
1042 },
1043 {
David Rientjes2da02992009-01-06 14:39:31 -08001044 .procname = "dirty_bytes",
1045 .data = &vm_dirty_bytes,
1046 .maxlen = sizeof(vm_dirty_bytes),
1047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001049 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001050 },
1051 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001053 .data = &dirty_writeback_interval,
1054 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001060 .data = &dirty_expire_interval,
1061 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001063 .proc_handler = proc_dointvec_minmax,
1064 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "nr_pdflush_threads",
1068 .data = &nr_pdflush_threads,
1069 .maxlen = sizeof nr_pdflush_threads,
1070 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 },
1073 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 .procname = "swappiness",
1075 .data = &vm_swappiness,
1076 .maxlen = sizeof(vm_swappiness),
1077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 .extra1 = &zero,
1080 .extra2 = &one_hundred,
1081 },
1082#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001083 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001085 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .maxlen = sizeof(unsigned long),
1087 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001088 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .extra1 = (void *)&hugetlb_zero,
1090 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001091 },
1092#ifdef CONFIG_NUMA
1093 {
1094 .procname = "nr_hugepages_mempolicy",
1095 .data = NULL,
1096 .maxlen = sizeof(unsigned long),
1097 .mode = 0644,
1098 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1099 .extra1 = (void *)&hugetlb_zero,
1100 .extra2 = (void *)&hugetlb_infinity,
1101 },
1102#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 .procname = "hugetlb_shm_group",
1105 .data = &sysctl_hugetlb_shm_group,
1106 .maxlen = sizeof(gid_t),
1107 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001108 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 },
Mel Gorman396faf02007-07-17 04:03:13 -07001110 {
Mel Gorman396faf02007-07-17 04:03:13 -07001111 .procname = "hugepages_treat_as_movable",
1112 .data = &hugepages_treat_as_movable,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001115 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001116 },
Adam Litke54f9f802007-10-16 01:26:20 -07001117 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001118 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001119 .data = NULL,
1120 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001121 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001122 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001123 .extra1 = (void *)&hugetlb_zero,
1124 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001125 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126#endif
1127 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 .procname = "lowmem_reserve_ratio",
1129 .data = &sysctl_lowmem_reserve_ratio,
1130 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1131 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001132 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 },
1134 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001135 .procname = "drop_caches",
1136 .data = &sysctl_drop_caches,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
1139 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001140 .extra1 = &one,
1141 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001142 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001143#ifdef CONFIG_COMPACTION
1144 {
1145 .procname = "compact_memory",
1146 .data = &sysctl_compact_memory,
1147 .maxlen = sizeof(int),
1148 .mode = 0200,
1149 .proc_handler = sysctl_compaction_handler,
1150 },
Mel Gorman5e771902010-05-24 14:32:31 -07001151 {
1152 .procname = "extfrag_threshold",
1153 .data = &sysctl_extfrag_threshold,
1154 .maxlen = sizeof(int),
1155 .mode = 0644,
1156 .proc_handler = sysctl_extfrag_handler,
1157 .extra1 = &min_extfrag_threshold,
1158 .extra2 = &max_extfrag_threshold,
1159 },
1160
Mel Gorman76ab0f52010-05-24 14:32:28 -07001161#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001162 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 .procname = "min_free_kbytes",
1164 .data = &min_free_kbytes,
1165 .maxlen = sizeof(min_free_kbytes),
1166 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001167 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .extra1 = &zero,
1169 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001170 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001171 .procname = "percpu_pagelist_fraction",
1172 .data = &percpu_pagelist_fraction,
1173 .maxlen = sizeof(percpu_pagelist_fraction),
1174 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001175 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001176 .extra1 = &min_percpu_pagelist_fract,
1177 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178#ifdef CONFIG_MMU
1179 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 .procname = "max_map_count",
1181 .data = &sysctl_max_map_count,
1182 .maxlen = sizeof(sysctl_max_map_count),
1183 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001184 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001185 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001187#else
1188 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001189 .procname = "nr_trim_pages",
1190 .data = &sysctl_nr_trim_pages,
1191 .maxlen = sizeof(sysctl_nr_trim_pages),
1192 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001193 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001194 .extra1 = &zero,
1195 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196#endif
1197 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 .procname = "laptop_mode",
1199 .data = &laptop_mode,
1200 .maxlen = sizeof(laptop_mode),
1201 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001202 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 },
1204 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 .procname = "block_dump",
1206 .data = &block_dump,
1207 .maxlen = sizeof(block_dump),
1208 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001209 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 .extra1 = &zero,
1211 },
1212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 .procname = "vfs_cache_pressure",
1214 .data = &sysctl_vfs_cache_pressure,
1215 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1216 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001217 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .extra1 = &zero,
1219 },
1220#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1221 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 .procname = "legacy_va_layout",
1223 .data = &sysctl_legacy_va_layout,
1224 .maxlen = sizeof(sysctl_legacy_va_layout),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .extra1 = &zero,
1228 },
1229#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001230#ifdef CONFIG_NUMA
1231 {
Christoph Lameter17436602006-01-18 17:42:32 -08001232 .procname = "zone_reclaim_mode",
1233 .data = &zone_reclaim_mode,
1234 .maxlen = sizeof(zone_reclaim_mode),
1235 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001236 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001237 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001238 },
Christoph Lameter96146342006-07-03 00:24:13 -07001239 {
Christoph Lameter96146342006-07-03 00:24:13 -07001240 .procname = "min_unmapped_ratio",
1241 .data = &sysctl_min_unmapped_ratio,
1242 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1243 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001244 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001245 .extra1 = &zero,
1246 .extra2 = &one_hundred,
1247 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001248 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001249 .procname = "min_slab_ratio",
1250 .data = &sysctl_min_slab_ratio,
1251 .maxlen = sizeof(sysctl_min_slab_ratio),
1252 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001253 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001254 .extra1 = &zero,
1255 .extra2 = &one_hundred,
1256 },
Christoph Lameter17436602006-01-18 17:42:32 -08001257#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001258#ifdef CONFIG_SMP
1259 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001260 .procname = "stat_interval",
1261 .data = &sysctl_stat_interval,
1262 .maxlen = sizeof(sysctl_stat_interval),
1263 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001264 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001265 },
1266#endif
David Howells6e141542009-12-15 19:27:45 +00001267#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001268 {
Eric Parised032182007-06-28 15:55:21 -04001269 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001270 .data = &dac_mmap_min_addr,
1271 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001273 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001274 },
David Howells6e141542009-12-15 19:27:45 +00001275#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001276#ifdef CONFIG_NUMA
1277 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001278 .procname = "numa_zonelist_order",
1279 .data = &numa_zonelist_order,
1280 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001283 },
1284#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001285#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001286 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001287 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001288 .procname = "vdso_enabled",
1289 .data = &vdso_enabled,
1290 .maxlen = sizeof(vdso_enabled),
1291 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001292 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001293 .extra1 = &zero,
1294 },
1295#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001296#ifdef CONFIG_HIGHMEM
1297 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001298 .procname = "highmem_is_dirtyable",
1299 .data = &vm_highmem_is_dirtyable,
1300 .maxlen = sizeof(vm_highmem_is_dirtyable),
1301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001303 .extra1 = &zero,
1304 .extra2 = &one,
1305 },
1306#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001307 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001308 .procname = "scan_unevictable_pages",
1309 .data = &scan_unevictable_pages,
1310 .maxlen = sizeof(scan_unevictable_pages),
1311 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001312 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001313 },
Andi Kleen6a460792009-09-16 11:50:15 +02001314#ifdef CONFIG_MEMORY_FAILURE
1315 {
Andi Kleen6a460792009-09-16 11:50:15 +02001316 .procname = "memory_failure_early_kill",
1317 .data = &sysctl_memory_failure_early_kill,
1318 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1319 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001320 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001321 .extra1 = &zero,
1322 .extra2 = &one,
1323 },
1324 {
Andi Kleen6a460792009-09-16 11:50:15 +02001325 .procname = "memory_failure_recovery",
1326 .data = &sysctl_memory_failure_recovery,
1327 .maxlen = sizeof(sysctl_memory_failure_recovery),
1328 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001329 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001330 .extra1 = &zero,
1331 .extra2 = &one,
1332 },
1333#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001334 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335};
1336
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001337#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001338static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001339 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001340};
1341#endif
1342
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001343static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "inode-nr",
1346 .data = &inodes_stat,
1347 .maxlen = 2*sizeof(int),
1348 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001349 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 },
1351 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 .procname = "inode-state",
1353 .data = &inodes_stat,
1354 .maxlen = 7*sizeof(int),
1355 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001356 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 },
1358 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .procname = "file-nr",
1360 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001361 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 },
1365 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .procname = "file-max",
1367 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001368 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001370 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 },
1372 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001373 .procname = "nr_open",
1374 .data = &sysctl_nr_open,
1375 .maxlen = sizeof(int),
1376 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001377 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001378 .extra1 = &sysctl_nr_open_min,
1379 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001380 },
1381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .procname = "dentry-state",
1383 .data = &dentry_stat,
1384 .maxlen = 6*sizeof(int),
1385 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001386 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 },
1388 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 .procname = "overflowuid",
1390 .data = &fs_overflowuid,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001393 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .extra1 = &minolduid,
1395 .extra2 = &maxolduid,
1396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "overflowgid",
1399 .data = &fs_overflowgid,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001402 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .extra1 = &minolduid,
1404 .extra2 = &maxolduid,
1405 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001406#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .procname = "leases-enable",
1409 .data = &leases_enable,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415#ifdef CONFIG_DNOTIFY
1416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 .procname = "dir-notify-enable",
1418 .data = &dir_notify_enable,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
1423#endif
1424#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001425#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 .procname = "lease-break-time",
1428 .data = &lease_break_time,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001433#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001434#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 .procname = "aio-nr",
1437 .data = &aio_nr,
1438 .maxlen = sizeof(aio_nr),
1439 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001440 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 },
1442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 .procname = "aio-max-nr",
1444 .data = &aio_max_nr,
1445 .maxlen = sizeof(aio_max_nr),
1446 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001447 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001449#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001450#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001451 {
Robert Love0399cb02005-07-13 12:38:18 -04001452 .procname = "inotify",
1453 .mode = 0555,
1454 .child = inotify_table,
1455 },
1456#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001457#ifdef CONFIG_EPOLL
1458 {
1459 .procname = "epoll",
1460 .mode = 0555,
1461 .child = epoll_table,
1462 },
1463#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001465 {
Alan Coxd6e71142005-06-23 00:09:43 -07001466 .procname = "suid_dumpable",
1467 .data = &suid_dumpable,
1468 .maxlen = sizeof(int),
1469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001470 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001471 .extra1 = &zero,
1472 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001473 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001474#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1475 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001476 .procname = "binfmt_misc",
1477 .mode = 0555,
1478 .child = binfmt_misc_table,
1479 },
1480#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001481 {
Jens Axboeff9da692010-06-03 14:54:39 +02001482 .procname = "pipe-max-size",
1483 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001484 .maxlen = sizeof(int),
1485 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001486 .proc_handler = &pipe_proc_fn,
1487 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001488 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001489 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490};
1491
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001492static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001493#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1494 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001495 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001496 .procname = "exception-trace",
1497 .data = &show_unhandled_signals,
1498 .maxlen = sizeof(int),
1499 .mode = 0644,
1500 .proc_handler = proc_dointvec
1501 },
1502#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001503#if defined(CONFIG_OPTPROBES)
1504 {
1505 .procname = "kprobes-optimization",
1506 .data = &sysctl_kprobes_optimization,
1507 .maxlen = sizeof(int),
1508 .mode = 0644,
1509 .proc_handler = proc_kprobes_optimization_handler,
1510 .extra1 = &zero,
1511 .extra2 = &one,
1512 },
1513#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001514 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515};
1516
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001517static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001518 { }
Robert Love0eeca282005-07-12 17:06:03 -04001519};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Al Viro330d57f2005-11-04 10:18:40 +00001521static DEFINE_SPINLOCK(sysctl_lock);
1522
1523/* called under sysctl_lock */
1524static int use_table(struct ctl_table_header *p)
1525{
1526 if (unlikely(p->unregistering))
1527 return 0;
1528 p->used++;
1529 return 1;
1530}
1531
1532/* called under sysctl_lock */
1533static void unuse_table(struct ctl_table_header *p)
1534{
1535 if (!--p->used)
1536 if (unlikely(p->unregistering))
1537 complete(p->unregistering);
1538}
1539
1540/* called under sysctl_lock, will reacquire if has to wait */
1541static void start_unregistering(struct ctl_table_header *p)
1542{
1543 /*
1544 * if p->used is 0, nobody will ever touch that entry again;
1545 * we'll eliminate all paths to it before dropping sysctl_lock
1546 */
1547 if (unlikely(p->used)) {
1548 struct completion wait;
1549 init_completion(&wait);
1550 p->unregistering = &wait;
1551 spin_unlock(&sysctl_lock);
1552 wait_for_completion(&wait);
1553 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001554 } else {
1555 /* anything non-NULL; we'll never dereference it */
1556 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001557 }
1558 /*
1559 * do not remove from the list until nobody holds it; walking the
1560 * list in do_sysctl() relies on that.
1561 */
1562 list_del_init(&p->ctl_entry);
1563}
1564
Al Virof7e6ced2008-07-15 01:44:23 -04001565void sysctl_head_get(struct ctl_table_header *head)
1566{
1567 spin_lock(&sysctl_lock);
1568 head->count++;
1569 spin_unlock(&sysctl_lock);
1570}
1571
Al Virodfef6dc2011-03-08 01:25:28 -05001572static void free_head(struct rcu_head *rcu)
1573{
1574 kfree(container_of(rcu, struct ctl_table_header, rcu));
1575}
1576
Al Virof7e6ced2008-07-15 01:44:23 -04001577void sysctl_head_put(struct ctl_table_header *head)
1578{
1579 spin_lock(&sysctl_lock);
1580 if (!--head->count)
Al Virodfef6dc2011-03-08 01:25:28 -05001581 call_rcu(&head->rcu, free_head);
Al Virof7e6ced2008-07-15 01:44:23 -04001582 spin_unlock(&sysctl_lock);
1583}
1584
1585struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1586{
1587 if (!head)
1588 BUG();
1589 spin_lock(&sysctl_lock);
1590 if (!use_table(head))
1591 head = ERR_PTR(-ENOENT);
1592 spin_unlock(&sysctl_lock);
1593 return head;
1594}
1595
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001596void sysctl_head_finish(struct ctl_table_header *head)
1597{
1598 if (!head)
1599 return;
1600 spin_lock(&sysctl_lock);
1601 unuse_table(head);
1602 spin_unlock(&sysctl_lock);
1603}
1604
Al Viro73455092008-07-14 21:22:20 -04001605static struct ctl_table_set *
1606lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1607{
1608 struct ctl_table_set *set = &root->default_set;
1609 if (root->lookup)
1610 set = root->lookup(root, namespaces);
1611 return set;
1612}
1613
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001614static struct list_head *
1615lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616{
Al Viro73455092008-07-14 21:22:20 -04001617 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1618 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001619}
1620
1621struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1622 struct ctl_table_header *prev)
1623{
1624 struct ctl_table_root *root;
1625 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001626 struct ctl_table_header *head;
1627 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001628
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001629 spin_lock(&sysctl_lock);
1630 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001631 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001632 tmp = &prev->ctl_entry;
1633 unuse_table(prev);
1634 goto next;
1635 }
1636 tmp = &root_table_header.ctl_entry;
1637 for (;;) {
1638 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1639
1640 if (!use_table(head))
1641 goto next;
1642 spin_unlock(&sysctl_lock);
1643 return head;
1644 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001645 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001646 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001647 header_list = lookup_header_list(root, namespaces);
1648 if (tmp != header_list)
1649 continue;
1650
1651 do {
1652 root = list_entry(root->root_list.next,
1653 struct ctl_table_root, root_list);
1654 if (root == &sysctl_table_root)
1655 goto out;
1656 header_list = lookup_header_list(root, namespaces);
1657 } while (list_empty(header_list));
1658 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001659 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001660out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001661 spin_unlock(&sysctl_lock);
1662 return NULL;
1663}
1664
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001665struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1666{
1667 return __sysctl_head_next(current->nsproxy, prev);
1668}
1669
1670void register_sysctl_root(struct ctl_table_root *root)
1671{
1672 spin_lock(&sysctl_lock);
1673 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1674 spin_unlock(&sysctl_lock);
1675}
1676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001678 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 * some sysctl variables are readonly even to root.
1680 */
1681
1682static int test_perm(int mode, int op)
1683{
David Howells76aac0e2008-11-14 10:39:12 +11001684 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 mode >>= 6;
1686 else if (in_egroup_p(0))
1687 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001688 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 return 0;
1690 return -EACCES;
1691}
1692
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001693int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001695 int mode;
1696
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001697 if (root->permissions)
1698 mode = root->permissions(root, current->nsproxy, table);
1699 else
1700 mode = table->mode;
1701
1702 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001705static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1706{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001707 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001708 table->parent = parent;
1709 if (table->child)
1710 sysctl_set_parent(table, table->child);
1711 }
1712}
1713
1714static __init int sysctl_init(void)
1715{
1716 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001717#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001718 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001719#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001720 return 0;
1721}
1722
1723core_initcall(sysctl_init);
1724
Al Virobfbcf032008-07-27 06:31:22 +01001725static struct ctl_table *is_branch_in(struct ctl_table *branch,
1726 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001727{
1728 struct ctl_table *p;
1729 const char *s = branch->procname;
1730
1731 /* branch should have named subdirectory as its first element */
1732 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001733 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001734
1735 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001736 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001737 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001738
1739 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001740 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001741 if (!p->child)
1742 continue;
1743 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001744 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001745 }
Al Virobfbcf032008-07-27 06:31:22 +01001746 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001747}
1748
1749/* see if attaching q to p would be an improvement */
1750static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1751{
1752 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001753 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001754 int is_better = 0;
1755 int not_in_parent = !p->attached_by;
1756
Al Virobfbcf032008-07-27 06:31:22 +01001757 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001758 if (by == q->attached_by)
1759 is_better = 1;
1760 if (to == p->attached_by)
1761 not_in_parent = 1;
1762 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001763 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001764 }
1765
1766 if (is_better && not_in_parent) {
1767 q->attached_by = by;
1768 q->attached_to = to;
1769 q->parent = p;
1770 }
1771}
1772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001774 * __register_sysctl_paths - register a sysctl hierarchy
1775 * @root: List of sysctl headers to register on
1776 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001777 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 *
1780 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001781 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001783 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1786 * enter a sysctl file
1787 *
1788 * data - a pointer to data for use by proc_handler
1789 *
1790 * maxlen - the maximum size in bytes of the data
1791 *
1792 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1793 *
1794 * child - a pointer to the child sysctl table if this entry is a directory, or
1795 * %NULL.
1796 *
1797 * proc_handler - the text handler routine (described below)
1798 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 * de - for internal use by the sysctl routines
1800 *
1801 * extra1, extra2 - extra pointers usable by the proc handler routines
1802 *
1803 * Leaf nodes in the sysctl tree will be represented by a single file
1804 * under /proc; non-leaf nodes will be represented by directories.
1805 *
1806 * sysctl(2) can automatically manage read and write requests through
1807 * the sysctl table. The data and maxlen fields of the ctl_table
1808 * struct enable minimal validation of the values being written to be
1809 * performed, and the mode field allows minimal authentication.
1810 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 * There must be a proc_handler routine for any terminal nodes
1812 * mirrored under /proc/sys (non-terminals are handled by a built-in
1813 * directory handler). Several default handlers are available to
1814 * cover common cases -
1815 *
1816 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1817 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1818 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1819 *
1820 * It is the handler's job to read the input buffer from user memory
1821 * and process it. The handler should return 0 on success.
1822 *
1823 * This routine returns %NULL on a failure to register, and a pointer
1824 * to the table header on success.
1825 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001826struct ctl_table_header *__register_sysctl_paths(
1827 struct ctl_table_root *root,
1828 struct nsproxy *namespaces,
1829 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001831 struct ctl_table_header *header;
1832 struct ctl_table *new, **prevp;
1833 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001834 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001835
1836 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001837 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001838 ;
1839
1840 /*
1841 * For each path component, allocate a 2-element ctl_table array.
1842 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001843 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001844 *
1845 * We allocate everything in one go so that we don't have to
1846 * worry about freeing additional memory in unregister_sysctl_table.
1847 */
1848 header = kzalloc(sizeof(struct ctl_table_header) +
1849 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1850 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001852
1853 new = (struct ctl_table *) (header + 1);
1854
1855 /* Now connect the dots */
1856 prevp = &header->ctl_table;
1857 for (n = 0; n < npath; ++n, ++path) {
1858 /* Copy the procname */
1859 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001860 new->mode = 0555;
1861
1862 *prevp = new;
1863 prevp = &new->child;
1864
1865 new += 2;
1866 }
1867 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001868 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001869
1870 INIT_LIST_HEAD(&header->ctl_entry);
1871 header->used = 0;
1872 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001873 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001874 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001875 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001876#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001877 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001878 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001879 return NULL;
1880 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001881#endif
Al Viro330d57f2005-11-04 10:18:40 +00001882 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001883 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001884 header->attached_by = header->ctl_table;
1885 header->attached_to = root_table;
1886 header->parent = &root_table_header;
1887 for (set = header->set; set; set = set->parent) {
1888 struct ctl_table_header *p;
1889 list_for_each_entry(p, &set->list, ctl_entry) {
1890 if (p->unregistering)
1891 continue;
1892 try_attach(p, header);
1893 }
1894 }
1895 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001896 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001897 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001898
1899 return header;
1900}
1901
1902/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001903 * register_sysctl_table_path - register a sysctl table hierarchy
1904 * @path: The path to the directory the sysctl table is in.
1905 * @table: the top-level table structure
1906 *
1907 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1908 * array. A completely 0 filled entry terminates the table.
1909 *
1910 * See __register_sysctl_paths for more details.
1911 */
1912struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1913 struct ctl_table *table)
1914{
1915 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1916 path, table);
1917}
1918
1919/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001920 * register_sysctl_table - register a sysctl table hierarchy
1921 * @table: the top-level table structure
1922 *
1923 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1924 * array. A completely 0 filled entry terminates the table.
1925 *
1926 * See register_sysctl_paths for more details.
1927 */
1928struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1929{
1930 static const struct ctl_path null_path[] = { {} };
1931
1932 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
1935/**
1936 * unregister_sysctl_table - unregister a sysctl table hierarchy
1937 * @header: the header returned from register_sysctl_table
1938 *
1939 * Unregisters the sysctl table and all children. proc entries may not
1940 * actually be removed until they are no longer used by anyone.
1941 */
1942void unregister_sysctl_table(struct ctl_table_header * header)
1943{
Al Viro330d57f2005-11-04 10:18:40 +00001944 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001945
1946 if (header == NULL)
1947 return;
1948
Al Viro330d57f2005-11-04 10:18:40 +00001949 spin_lock(&sysctl_lock);
1950 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001951 if (!--header->parent->count) {
1952 WARN_ON(1);
Al Virodfef6dc2011-03-08 01:25:28 -05001953 call_rcu(&header->parent->rcu, free_head);
Al Viroae7edec2008-07-15 06:33:31 -04001954 }
Al Virof7e6ced2008-07-15 01:44:23 -04001955 if (!--header->count)
Al Virodfef6dc2011-03-08 01:25:28 -05001956 call_rcu(&header->rcu, free_head);
Al Viro330d57f2005-11-04 10:18:40 +00001957 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958}
1959
Al Viro90434762008-07-15 08:54:06 -04001960int sysctl_is_seen(struct ctl_table_header *p)
1961{
1962 struct ctl_table_set *set = p->set;
1963 int res;
1964 spin_lock(&sysctl_lock);
1965 if (p->unregistering)
1966 res = 0;
1967 else if (!set->is_seen)
1968 res = 1;
1969 else
1970 res = set->is_seen(set);
1971 spin_unlock(&sysctl_lock);
1972 return res;
1973}
1974
Al Viro73455092008-07-14 21:22:20 -04001975void setup_sysctl_set(struct ctl_table_set *p,
1976 struct ctl_table_set *parent,
1977 int (*is_seen)(struct ctl_table_set *))
1978{
1979 INIT_LIST_HEAD(&p->list);
1980 p->parent = parent ? parent : &sysctl_table_root.default_set;
1981 p->is_seen = is_seen;
1982}
1983
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001984#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001985struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001986{
1987 return NULL;
1988}
1989
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001990struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1991 struct ctl_table *table)
1992{
1993 return NULL;
1994}
1995
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001996void unregister_sysctl_table(struct ctl_table_header * table)
1997{
1998}
1999
Al Viro73455092008-07-14 21:22:20 -04002000void setup_sysctl_set(struct ctl_table_set *p,
2001 struct ctl_table_set *parent,
2002 int (*is_seen)(struct ctl_table_set *))
2003{
2004}
2005
Al Virof7e6ced2008-07-15 01:44:23 -04002006void sysctl_head_put(struct ctl_table_header *head)
2007{
2008}
2009
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002010#endif /* CONFIG_SYSCTL */
2011
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012/*
2013 * /proc/sys support
2014 */
2015
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002016#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002018static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002019 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002020 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002021{
2022 size_t len;
2023 char __user *p;
2024 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002025
2026 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002027 *lenp = 0;
2028 return 0;
2029 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002030
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002031 if (write) {
2032 len = 0;
2033 p = buffer;
2034 while (len < *lenp) {
2035 if (get_user(c, p++))
2036 return -EFAULT;
2037 if (c == 0 || c == '\n')
2038 break;
2039 len++;
2040 }
2041 if (len >= maxlen)
2042 len = maxlen-1;
2043 if(copy_from_user(data, buffer, len))
2044 return -EFAULT;
2045 ((char *) data)[len] = 0;
2046 *ppos += *lenp;
2047 } else {
2048 len = strlen(data);
2049 if (len > maxlen)
2050 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002051
2052 if (*ppos > len) {
2053 *lenp = 0;
2054 return 0;
2055 }
2056
2057 data += *ppos;
2058 len -= *ppos;
2059
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002060 if (len > *lenp)
2061 len = *lenp;
2062 if (len)
2063 if(copy_to_user(buffer, data, len))
2064 return -EFAULT;
2065 if (len < *lenp) {
2066 if(put_user('\n', ((char __user *) buffer) + len))
2067 return -EFAULT;
2068 len++;
2069 }
2070 *lenp = len;
2071 *ppos += len;
2072 }
2073 return 0;
2074}
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076/**
2077 * proc_dostring - read a string sysctl
2078 * @table: the sysctl table
2079 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 * @buffer: the user buffer
2081 * @lenp: the size of the user buffer
2082 * @ppos: file position
2083 *
2084 * Reads/writes a string from/to the user buffer. If the kernel
2085 * buffer provided is not large enough to hold the string, the
2086 * string is truncated. The copied string is %NULL-terminated.
2087 * If the string is being read by the user process, it is copied
2088 * and a newline '\n' is added. It is truncated if the buffer is
2089 * not large enough.
2090 *
2091 * Returns 0 on success.
2092 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002093int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 void __user *buffer, size_t *lenp, loff_t *ppos)
2095{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002096 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002097 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098}
2099
Amerigo Wang00b7c332010-05-05 00:26:45 +00002100static size_t proc_skip_spaces(char **buf)
2101{
2102 size_t ret;
2103 char *tmp = skip_spaces(*buf);
2104 ret = tmp - *buf;
2105 *buf = tmp;
2106 return ret;
2107}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002109static void proc_skip_char(char **buf, size_t *size, const char v)
2110{
2111 while (*size) {
2112 if (**buf != v)
2113 break;
2114 (*size)--;
2115 (*buf)++;
2116 }
2117}
2118
Amerigo Wang00b7c332010-05-05 00:26:45 +00002119#define TMPBUFLEN 22
2120/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002121 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002122 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002123 * @buf: a kernel buffer
2124 * @size: size of the kernel buffer
2125 * @val: this is where the number will be stored
2126 * @neg: set to %TRUE if number is negative
2127 * @perm_tr: a vector which contains the allowed trailers
2128 * @perm_tr_len: size of the perm_tr vector
2129 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002130 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002131 * In case of success %0 is returned and @buf and @size are updated with
2132 * the amount of bytes read. If @tr is non-NULL and a trailing
2133 * character exists (size is non-zero after returning from this
2134 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 */
2136static int proc_get_long(char **buf, size_t *size,
2137 unsigned long *val, bool *neg,
2138 const char *perm_tr, unsigned perm_tr_len, char *tr)
2139{
2140 int len;
2141 char *p, tmp[TMPBUFLEN];
2142
2143 if (!*size)
2144 return -EINVAL;
2145
2146 len = *size;
2147 if (len > TMPBUFLEN - 1)
2148 len = TMPBUFLEN - 1;
2149
2150 memcpy(tmp, *buf, len);
2151
2152 tmp[len] = 0;
2153 p = tmp;
2154 if (*p == '-' && *size > 1) {
2155 *neg = true;
2156 p++;
2157 } else
2158 *neg = false;
2159 if (!isdigit(*p))
2160 return -EINVAL;
2161
2162 *val = simple_strtoul(p, &p, 0);
2163
2164 len = p - tmp;
2165
2166 /* We don't know if the next char is whitespace thus we may accept
2167 * invalid integers (e.g. 1234...a) or two integers instead of one
2168 * (e.g. 123...1). So lets not allow such large numbers. */
2169 if (len == TMPBUFLEN - 1)
2170 return -EINVAL;
2171
2172 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2173 return -EINVAL;
2174
2175 if (tr && (len < *size))
2176 *tr = *p;
2177
2178 *buf += len;
2179 *size -= len;
2180
2181 return 0;
2182}
2183
2184/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002185 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002186 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002187 * @buf: the user buffer
2188 * @size: the size of the user buffer
2189 * @val: the integer to be converted
2190 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002192 * In case of success %0 is returned and @buf and @size are updated with
2193 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002194 */
2195static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2196 bool neg)
2197{
2198 int len;
2199 char tmp[TMPBUFLEN], *p = tmp;
2200
2201 sprintf(p, "%s%lu", neg ? "-" : "", val);
2202 len = strlen(tmp);
2203 if (len > *size)
2204 len = *size;
2205 if (copy_to_user(*buf, tmp, len))
2206 return -EFAULT;
2207 *size -= len;
2208 *buf += len;
2209 return 0;
2210}
2211#undef TMPBUFLEN
2212
2213static int proc_put_char(void __user **buf, size_t *size, char c)
2214{
2215 if (*size) {
2216 char __user **buffer = (char __user **)buf;
2217 if (put_user(c, *buffer))
2218 return -EFAULT;
2219 (*size)--, (*buffer)++;
2220 *buf = *buffer;
2221 }
2222 return 0;
2223}
2224
2225static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 int *valp,
2227 int write, void *data)
2228{
2229 if (write) {
2230 *valp = *negp ? -*lvalp : *lvalp;
2231 } else {
2232 int val = *valp;
2233 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002234 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 *lvalp = (unsigned long)-val;
2236 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002237 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 *lvalp = (unsigned long)val;
2239 }
2240 }
2241 return 0;
2242}
2243
Amerigo Wang00b7c332010-05-05 00:26:45 +00002244static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2245
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002246static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002247 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002248 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002249 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 int write, void *data),
2251 void *data)
2252{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002253 int *i, vleft, first = 1, err = 0;
2254 unsigned long page = 0;
2255 size_t left;
2256 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 *lenp = 0;
2260 return 0;
2261 }
2262
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002263 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 vleft = table->maxlen / sizeof(*i);
2265 left = *lenp;
2266
2267 if (!conv)
2268 conv = do_proc_dointvec_conv;
2269
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271 if (left > PAGE_SIZE - 1)
2272 left = PAGE_SIZE - 1;
2273 page = __get_free_page(GFP_TEMPORARY);
2274 kbuf = (char *) page;
2275 if (!kbuf)
2276 return -ENOMEM;
2277 if (copy_from_user(kbuf, buffer, left)) {
2278 err = -EFAULT;
2279 goto free;
2280 }
2281 kbuf[left] = 0;
2282 }
2283
2284 for (; left && vleft--; i++, first=0) {
2285 unsigned long lval;
2286 bool neg;
2287
2288 if (write) {
2289 left -= proc_skip_spaces(&kbuf);
2290
J. R. Okajima563b0462010-05-25 16:10:14 -07002291 if (!left)
2292 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002293 err = proc_get_long(&kbuf, &left, &lval, &neg,
2294 proc_wspace_sep,
2295 sizeof(proc_wspace_sep), NULL);
2296 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002298 if (conv(&neg, &lval, i, 1, data)) {
2299 err = -EINVAL;
2300 break;
2301 }
2302 } else {
2303 if (conv(&neg, &lval, i, 0, data)) {
2304 err = -EINVAL;
2305 break;
2306 }
2307 if (!first)
2308 err = proc_put_char(&buffer, &left, '\t');
2309 if (err)
2310 break;
2311 err = proc_put_long(&buffer, &left, lval, neg);
2312 if (err)
2313 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 }
2315 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002316
2317 if (!write && !first && left && !err)
2318 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002319 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002320 left -= proc_skip_spaces(&kbuf);
2321free:
2322 if (write) {
2323 free_page(page);
2324 if (first)
2325 return err ? : -EINVAL;
2326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 *lenp -= left;
2328 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002329 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002332static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002333 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002335 int write, void *data),
2336 void *data)
2337{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002338 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002339 buffer, lenp, ppos, conv, data);
2340}
2341
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342/**
2343 * proc_dointvec - read a vector of integers
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 * @buffer: the user buffer
2347 * @lenp: the size of the user buffer
2348 * @ppos: file position
2349 *
2350 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2351 * values from/to the user buffer, treated as an ASCII string.
2352 *
2353 * Returns 0 on success.
2354 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002355int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 void __user *buffer, size_t *lenp, loff_t *ppos)
2357{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002358 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 NULL,NULL);
2360}
2361
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002362/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002363 * Taint values can only be increased
2364 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002365 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002366static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367 void __user *buffer, size_t *lenp, loff_t *ppos)
2368{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002369 struct ctl_table t;
2370 unsigned long tmptaint = get_taint();
2371 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372
Bastian Blank91fcd412007-04-23 14:41:14 -07002373 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002374 return -EPERM;
2375
Andi Kleen25ddbb12008-10-15 22:01:41 -07002376 t = *table;
2377 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002378 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002379 if (err < 0)
2380 return err;
2381
2382 if (write) {
2383 /*
2384 * Poor man's atomic or. Not worth adding a primitive
2385 * to everyone's atomic.h for this
2386 */
2387 int i;
2388 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2389 if ((tmptaint >> i) & 1)
2390 add_taint(i);
2391 }
2392 }
2393
2394 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002395}
2396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397struct do_proc_dointvec_minmax_conv_param {
2398 int *min;
2399 int *max;
2400};
2401
Amerigo Wang00b7c332010-05-05 00:26:45 +00002402static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2403 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 int write, void *data)
2405{
2406 struct do_proc_dointvec_minmax_conv_param *param = data;
2407 if (write) {
2408 int val = *negp ? -*lvalp : *lvalp;
2409 if ((param->min && *param->min > val) ||
2410 (param->max && *param->max < val))
2411 return -EINVAL;
2412 *valp = val;
2413 } else {
2414 int val = *valp;
2415 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002416 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 *lvalp = (unsigned long)-val;
2418 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002419 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 *lvalp = (unsigned long)val;
2421 }
2422 }
2423 return 0;
2424}
2425
2426/**
2427 * proc_dointvec_minmax - read a vector of integers with min/max values
2428 * @table: the sysctl table
2429 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 * @buffer: the user buffer
2431 * @lenp: the size of the user buffer
2432 * @ppos: file position
2433 *
2434 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2435 * values from/to the user buffer, treated as an ASCII string.
2436 *
2437 * This routine will ensure the values are within the range specified by
2438 * table->extra1 (min) and table->extra2 (max).
2439 *
2440 * Returns 0 on success.
2441 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002442int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 void __user *buffer, size_t *lenp, loff_t *ppos)
2444{
2445 struct do_proc_dointvec_minmax_conv_param param = {
2446 .min = (int *) table->extra1,
2447 .max = (int *) table->extra2,
2448 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002449 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 do_proc_dointvec_minmax_conv, &param);
2451}
2452
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002453static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 void __user *buffer,
2455 size_t *lenp, loff_t *ppos,
2456 unsigned long convmul,
2457 unsigned long convdiv)
2458{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002459 unsigned long *i, *min, *max;
2460 int vleft, first = 1, err = 0;
2461 unsigned long page = 0;
2462 size_t left;
2463 char *kbuf;
2464
2465 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 *lenp = 0;
2467 return 0;
2468 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002469
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002470 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 min = (unsigned long *) table->extra1;
2472 max = (unsigned long *) table->extra2;
2473 vleft = table->maxlen / sizeof(unsigned long);
2474 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002475
2476 if (write) {
2477 if (left > PAGE_SIZE - 1)
2478 left = PAGE_SIZE - 1;
2479 page = __get_free_page(GFP_TEMPORARY);
2480 kbuf = (char *) page;
2481 if (!kbuf)
2482 return -ENOMEM;
2483 if (copy_from_user(kbuf, buffer, left)) {
2484 err = -EFAULT;
2485 goto free;
2486 }
2487 kbuf[left] = 0;
2488 }
2489
Eric Dumazet27b3d802010-10-07 12:59:29 -07002490 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002491 unsigned long val;
2492
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002494 bool neg;
2495
2496 left -= proc_skip_spaces(&kbuf);
2497
2498 err = proc_get_long(&kbuf, &left, &val, &neg,
2499 proc_wspace_sep,
2500 sizeof(proc_wspace_sep), NULL);
2501 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 break;
2503 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 continue;
2505 if ((min && val < *min) || (max && val > *max))
2506 continue;
2507 *i = val;
2508 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002509 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002511 err = proc_put_char(&buffer, &left, '\t');
2512 err = proc_put_long(&buffer, &left, val, false);
2513 if (err)
2514 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 }
2516 }
2517
Amerigo Wang00b7c332010-05-05 00:26:45 +00002518 if (!write && !first && left && !err)
2519 err = proc_put_char(&buffer, &left, '\n');
2520 if (write && !err)
2521 left -= proc_skip_spaces(&kbuf);
2522free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002524 free_page(page);
2525 if (first)
2526 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 *lenp -= left;
2529 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002530 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531}
2532
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002533static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002534 void __user *buffer,
2535 size_t *lenp, loff_t *ppos,
2536 unsigned long convmul,
2537 unsigned long convdiv)
2538{
2539 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002540 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002541}
2542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543/**
2544 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2550 *
2551 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2552 * values from/to the user buffer, treated as an ASCII string.
2553 *
2554 * This routine will ensure the values are within the range specified by
2555 * table->extra1 (min) and table->extra2 (max).
2556 *
2557 * Returns 0 on success.
2558 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002559int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 void __user *buffer, size_t *lenp, loff_t *ppos)
2561{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002562 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565/**
2566 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2567 * @table: the sysctl table
2568 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 * @buffer: the user buffer
2570 * @lenp: the size of the user buffer
2571 * @ppos: file position
2572 *
2573 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2574 * values from/to the user buffer, treated as an ASCII string. The values
2575 * are treated as milliseconds, and converted to jiffies when they are stored.
2576 *
2577 * This routine will ensure the values are within the range specified by
2578 * table->extra1 (min) and table->extra2 (max).
2579 *
2580 * Returns 0 on success.
2581 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002582int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 void __user *buffer,
2584 size_t *lenp, loff_t *ppos)
2585{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002586 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 lenp, ppos, HZ, 1000l);
2588}
2589
2590
Amerigo Wang00b7c332010-05-05 00:26:45 +00002591static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 int *valp,
2593 int write, void *data)
2594{
2595 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002596 if (*lvalp > LONG_MAX / HZ)
2597 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2599 } else {
2600 int val = *valp;
2601 unsigned long lval;
2602 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002603 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 lval = (unsigned long)-val;
2605 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002606 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 lval = (unsigned long)val;
2608 }
2609 *lvalp = lval / HZ;
2610 }
2611 return 0;
2612}
2613
Amerigo Wang00b7c332010-05-05 00:26:45 +00002614static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 int *valp,
2616 int write, void *data)
2617{
2618 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002619 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2620 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2622 } else {
2623 int val = *valp;
2624 unsigned long lval;
2625 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002626 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 lval = (unsigned long)-val;
2628 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002629 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 lval = (unsigned long)val;
2631 }
2632 *lvalp = jiffies_to_clock_t(lval);
2633 }
2634 return 0;
2635}
2636
Amerigo Wang00b7c332010-05-05 00:26:45 +00002637static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 int *valp,
2639 int write, void *data)
2640{
2641 if (write) {
2642 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2643 } else {
2644 int val = *valp;
2645 unsigned long lval;
2646 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002647 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 lval = (unsigned long)-val;
2649 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002650 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 lval = (unsigned long)val;
2652 }
2653 *lvalp = jiffies_to_msecs(lval);
2654 }
2655 return 0;
2656}
2657
2658/**
2659 * proc_dointvec_jiffies - read a vector of integers as seconds
2660 * @table: the sysctl table
2661 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 * @buffer: the user buffer
2663 * @lenp: the size of the user buffer
2664 * @ppos: file position
2665 *
2666 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2667 * values from/to the user buffer, treated as an ASCII string.
2668 * The values read are assumed to be in seconds, and are converted into
2669 * jiffies.
2670 *
2671 * Returns 0 on success.
2672 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002673int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 void __user *buffer, size_t *lenp, loff_t *ppos)
2675{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002676 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 do_proc_dointvec_jiffies_conv,NULL);
2678}
2679
2680/**
2681 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2682 * @table: the sysctl table
2683 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 * @buffer: the user buffer
2685 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002686 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 *
2688 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2689 * values from/to the user buffer, treated as an ASCII string.
2690 * The values read are assumed to be in 1/USER_HZ seconds, and
2691 * are converted into jiffies.
2692 *
2693 * Returns 0 on success.
2694 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002695int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 void __user *buffer, size_t *lenp, loff_t *ppos)
2697{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002698 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 do_proc_dointvec_userhz_jiffies_conv,NULL);
2700}
2701
2702/**
2703 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2704 * @table: the sysctl table
2705 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 * @buffer: the user buffer
2707 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002708 * @ppos: file position
2709 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 *
2711 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2712 * values from/to the user buffer, treated as an ASCII string.
2713 * The values read are assumed to be in 1/1000 seconds, and
2714 * are converted into jiffies.
2715 *
2716 * Returns 0 on success.
2717 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002718int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 void __user *buffer, size_t *lenp, loff_t *ppos)
2720{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002721 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 do_proc_dointvec_ms_jiffies_conv, NULL);
2723}
2724
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002725static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002726 void __user *buffer, size_t *lenp, loff_t *ppos)
2727{
2728 struct pid *new_pid;
2729 pid_t tmp;
2730 int r;
2731
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002732 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002733
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002734 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002735 lenp, ppos, NULL, NULL);
2736 if (r || !write)
2737 return r;
2738
2739 new_pid = find_get_pid(tmp);
2740 if (!new_pid)
2741 return -ESRCH;
2742
2743 put_pid(xchg(&cad_pid, new_pid));
2744 return 0;
2745}
2746
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002747/**
2748 * proc_do_large_bitmap - read/write from/to a large bitmap
2749 * @table: the sysctl table
2750 * @write: %TRUE if this is a write to the sysctl file
2751 * @buffer: the user buffer
2752 * @lenp: the size of the user buffer
2753 * @ppos: file position
2754 *
2755 * The bitmap is stored at table->data and the bitmap length (in bits)
2756 * in table->maxlen.
2757 *
2758 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2759 * large bitmaps may be represented in a compact manner. Writing into
2760 * the file will clear the bitmap then update it with the given input.
2761 *
2762 * Returns 0 on success.
2763 */
2764int proc_do_large_bitmap(struct ctl_table *table, int write,
2765 void __user *buffer, size_t *lenp, loff_t *ppos)
2766{
2767 int err = 0;
2768 bool first = 1;
2769 size_t left = *lenp;
2770 unsigned long bitmap_len = table->maxlen;
2771 unsigned long *bitmap = (unsigned long *) table->data;
2772 unsigned long *tmp_bitmap = NULL;
2773 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2774
2775 if (!bitmap_len || !left || (*ppos && !write)) {
2776 *lenp = 0;
2777 return 0;
2778 }
2779
2780 if (write) {
2781 unsigned long page = 0;
2782 char *kbuf;
2783
2784 if (left > PAGE_SIZE - 1)
2785 left = PAGE_SIZE - 1;
2786
2787 page = __get_free_page(GFP_TEMPORARY);
2788 kbuf = (char *) page;
2789 if (!kbuf)
2790 return -ENOMEM;
2791 if (copy_from_user(kbuf, buffer, left)) {
2792 free_page(page);
2793 return -EFAULT;
2794 }
2795 kbuf[left] = 0;
2796
2797 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2798 GFP_KERNEL);
2799 if (!tmp_bitmap) {
2800 free_page(page);
2801 return -ENOMEM;
2802 }
2803 proc_skip_char(&kbuf, &left, '\n');
2804 while (!err && left) {
2805 unsigned long val_a, val_b;
2806 bool neg;
2807
2808 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2809 sizeof(tr_a), &c);
2810 if (err)
2811 break;
2812 if (val_a >= bitmap_len || neg) {
2813 err = -EINVAL;
2814 break;
2815 }
2816
2817 val_b = val_a;
2818 if (left) {
2819 kbuf++;
2820 left--;
2821 }
2822
2823 if (c == '-') {
2824 err = proc_get_long(&kbuf, &left, &val_b,
2825 &neg, tr_b, sizeof(tr_b),
2826 &c);
2827 if (err)
2828 break;
2829 if (val_b >= bitmap_len || neg ||
2830 val_a > val_b) {
2831 err = -EINVAL;
2832 break;
2833 }
2834 if (left) {
2835 kbuf++;
2836 left--;
2837 }
2838 }
2839
2840 while (val_a <= val_b)
2841 set_bit(val_a++, tmp_bitmap);
2842
2843 first = 0;
2844 proc_skip_char(&kbuf, &left, '\n');
2845 }
2846 free_page(page);
2847 } else {
2848 unsigned long bit_a, bit_b = 0;
2849
2850 while (left) {
2851 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2852 if (bit_a >= bitmap_len)
2853 break;
2854 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2855 bit_a + 1) - 1;
2856
2857 if (!first) {
2858 err = proc_put_char(&buffer, &left, ',');
2859 if (err)
2860 break;
2861 }
2862 err = proc_put_long(&buffer, &left, bit_a, false);
2863 if (err)
2864 break;
2865 if (bit_a != bit_b) {
2866 err = proc_put_char(&buffer, &left, '-');
2867 if (err)
2868 break;
2869 err = proc_put_long(&buffer, &left, bit_b, false);
2870 if (err)
2871 break;
2872 }
2873
2874 first = 0; bit_b++;
2875 }
2876 if (!err)
2877 err = proc_put_char(&buffer, &left, '\n');
2878 }
2879
2880 if (!err) {
2881 if (write) {
2882 if (*ppos)
2883 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2884 else
2885 memcpy(bitmap, tmp_bitmap,
2886 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2887 }
2888 kfree(tmp_bitmap);
2889 *lenp -= left;
2890 *ppos += *lenp;
2891 return 0;
2892 } else {
2893 kfree(tmp_bitmap);
2894 return err;
2895 }
2896}
2897
Jovi Zhang55610502011-01-12 17:00:45 -08002898#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002900int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 void __user *buffer, size_t *lenp, loff_t *ppos)
2902{
2903 return -ENOSYS;
2904}
2905
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002906int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 void __user *buffer, size_t *lenp, loff_t *ppos)
2908{
2909 return -ENOSYS;
2910}
2911
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002912int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 void __user *buffer, size_t *lenp, loff_t *ppos)
2914{
2915 return -ENOSYS;
2916}
2917
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002918int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 void __user *buffer, size_t *lenp, loff_t *ppos)
2920{
2921 return -ENOSYS;
2922}
2923
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002924int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 void __user *buffer, size_t *lenp, loff_t *ppos)
2926{
2927 return -ENOSYS;
2928}
2929
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002930int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 void __user *buffer, size_t *lenp, loff_t *ppos)
2932{
2933 return -ENOSYS;
2934}
2935
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002936int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 void __user *buffer, size_t *lenp, loff_t *ppos)
2938{
2939 return -ENOSYS;
2940}
2941
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002942int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 void __user *buffer,
2944 size_t *lenp, loff_t *ppos)
2945{
2946 return -ENOSYS;
2947}
2948
2949
Jovi Zhang55610502011-01-12 17:00:45 -08002950#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952/*
2953 * No sense putting this after each symbol definition, twice,
2954 * exception granted :-)
2955 */
2956EXPORT_SYMBOL(proc_dointvec);
2957EXPORT_SYMBOL(proc_dointvec_jiffies);
2958EXPORT_SYMBOL(proc_dointvec_minmax);
2959EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2960EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2961EXPORT_SYMBOL(proc_dostring);
2962EXPORT_SYMBOL(proc_doulongvec_minmax);
2963EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2964EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002965EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966EXPORT_SYMBOL(unregister_sysctl_table);