blob: 0f1bd83db98523333b9fabde37d200512b20b77e [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;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800120static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700121static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700122#ifdef CONFIG_PRINTK
123static int ten_thousand = 10000;
124#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700125
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700126/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130static int maxolduid = 65535;
131static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800132static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134static int ngroups_max = NGROUPS_MAX;
135
Dave Youngd14f1722010-02-25 20:28:57 -0500136#ifdef CONFIG_INOTIFY_USER
137#include <linux/inotify.h>
138#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700139#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700140#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
142
David S. Miller08714202008-11-16 23:49:24 -0800143#ifdef CONFIG_SPARC64
144extern int sysctl_tsb_ratio;
145#endif
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef __hppa__
148extern int pwrsw_enabled;
149extern int unaligned_enabled;
150#endif
151
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800152#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#ifdef CONFIG_MATHEMU
154extern int sysctl_ieee_emulation_warnings;
155#endif
156extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700157extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#endif
159
Jes Sorensend2b176e2006-02-28 09:42:23 -0800160#ifdef CONFIG_IA64
161extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800162extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800163#endif
164
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700165#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700166static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700168static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800169 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700170#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700171
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700172#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800173/* Note: sysrq code uses it's own private copy */
174static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700175
176static int sysrq_sysctl_handler(ctl_table *table, int write,
177 void __user *buffer, size_t *lenp,
178 loff_t *ppos)
179{
180 int error;
181
182 error = proc_dointvec(table, write, buffer, lenp, ppos);
183 if (error)
184 return error;
185
186 if (write)
187 sysrq_toggle_support(__sysrq_enabled);
188
189 return 0;
190}
191
192#endif
193
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700194static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100195static struct ctl_table_root sysctl_table_root;
196static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100197 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100198 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400199 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100200 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400201 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100202};
203static struct ctl_table_root sysctl_table_root = {
204 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400205 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100206};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700208static struct ctl_table kern_table[];
209static struct ctl_table vm_table[];
210static struct ctl_table fs_table[];
211static struct ctl_table debug_table[];
212static struct ctl_table dev_table[];
213extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800214#ifdef CONFIG_EPOLL
215extern struct ctl_table epoll_table[];
216#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
219int sysctl_legacy_va_layout;
220#endif
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/* The default sysctl tables: */
223
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700224static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 .procname = "kernel",
227 .mode = 0555,
228 .child = kern_table,
229 },
230 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 .procname = "vm",
232 .mode = 0555,
233 .child = vm_table,
234 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 .procname = "fs",
237 .mode = 0555,
238 .child = fs_table,
239 },
240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .procname = "debug",
242 .mode = 0555,
243 .child = debug_table,
244 },
245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .procname = "dev",
247 .mode = 0555,
248 .child = dev_table,
249 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700250 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251};
252
Ingo Molnar77e54a12007-07-09 18:52:00 +0200253#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100254static int min_sched_granularity_ns = 100000; /* 100 usecs */
255static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
256static int min_wakeup_granularity_ns; /* 0 usecs */
257static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100258static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
259static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260#endif
261
Mel Gorman5e771902010-05-24 14:32:31 -0700262#ifdef CONFIG_COMPACTION
263static int min_extfrag_threshold;
264static int max_extfrag_threshold = 1000;
265#endif
266
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700267static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200268 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200269 .procname = "sched_child_runs_first",
270 .data = &sysctl_sched_child_runs_first,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800273 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200274 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200275#ifdef CONFIG_SCHED_DEBUG
276 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100277 .procname = "sched_min_granularity_ns",
278 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800281 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100282 .extra1 = &min_sched_granularity_ns,
283 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200284 },
285 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200286 .procname = "sched_latency_ns",
287 .data = &sysctl_sched_latency,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800290 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200291 .extra1 = &min_sched_granularity_ns,
292 .extra2 = &max_sched_granularity_ns,
293 },
294 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200295 .procname = "sched_wakeup_granularity_ns",
296 .data = &sysctl_sched_wakeup_granularity,
297 .maxlen = sizeof(unsigned int),
298 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800299 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200300 .extra1 = &min_wakeup_granularity_ns,
301 .extra2 = &max_wakeup_granularity_ns,
302 },
303 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100304 .procname = "sched_tunable_scaling",
305 .data = &sysctl_sched_tunable_scaling,
306 .maxlen = sizeof(enum sched_tunable_scaling),
307 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800308 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100309 .extra1 = &min_sched_tunable_scaling,
310 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200311 },
312 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200313 .procname = "sched_migration_cost",
314 .data = &sysctl_sched_migration_cost,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800317 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200318 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100319 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800324 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100325 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530326 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200327 .procname = "sched_time_avg",
328 .data = &sysctl_sched_time_avg,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800331 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200332 },
333 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800334 .procname = "sched_shares_window",
335 .data = &sysctl_sched_shares_window,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
339 },
340 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530341 .procname = "timer_migration",
342 .data = &sysctl_timer_migration,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800345 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530346 .extra1 = &zero,
347 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530348 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200349#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200350 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100351 .procname = "sched_rt_period_us",
352 .data = &sysctl_sched_rt_period,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800355 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100356 },
357 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100358 .procname = "sched_rt_runtime_us",
359 .data = &sysctl_sched_rt_runtime,
360 .maxlen = sizeof(int),
361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800362 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100363 },
364 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200365 .procname = "sched_compat_yield",
366 .data = &sysctl_sched_compat_yield,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800369 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200370 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100371#ifdef CONFIG_SCHED_AUTOGROUP
372 {
373 .procname = "sched_autogroup_enabled",
374 .data = &sysctl_sched_autogroup_enabled,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
378 .extra1 = &zero,
379 .extra2 = &one,
380 },
381#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700382#ifdef CONFIG_PROVE_LOCKING
383 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800388 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700389 },
390#endif
391#ifdef CONFIG_LOCK_STAT
392 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700393 .procname = "lock_stat",
394 .data = &lock_stat,
395 .maxlen = sizeof(int),
396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800397 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700398 },
399#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .procname = "panic",
402 .data = &panic_timeout,
403 .maxlen = sizeof(int),
404 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800405 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 },
407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 .procname = "core_uses_pid",
409 .data = &core_uses_pid,
410 .maxlen = sizeof(int),
411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800412 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 },
414 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 .procname = "core_pattern",
416 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700417 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800419 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 },
Neil Hormana2939802009-09-23 15:56:56 -0700421 {
Neil Hormana2939802009-09-23 15:56:56 -0700422 .procname = "core_pipe_limit",
423 .data = &core_pipe_limit,
424 .maxlen = sizeof(unsigned int),
425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800426 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700427 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800428#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700431 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800435#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100436#ifdef CONFIG_LATENCYTOP
437 {
438 .procname = "latencytop",
439 .data = &latencytop_enabled,
440 .maxlen = sizeof(int),
441 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800442 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100443 },
444#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#ifdef CONFIG_BLK_DEV_INITRD
446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 .procname = "real-root-dev",
448 .data = &real_root_dev,
449 .maxlen = sizeof(int),
450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800451 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 },
453#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700454 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
458 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800459 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700460 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700461#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 .procname = "reboot-cmd",
464 .data = reboot_command,
465 .maxlen = 256,
466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800467 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 },
469 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 .procname = "stop-a",
471 .data = &stop_a_enabled,
472 .maxlen = sizeof (int),
473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800474 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 },
476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 },
483#endif
David S. Miller08714202008-11-16 23:49:24 -0800484#ifdef CONFIG_SPARC64
485 {
David S. Miller08714202008-11-16 23:49:24 -0800486 .procname = "tsb-ratio",
487 .data = &sysctl_tsb_ratio,
488 .maxlen = sizeof (int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800491 },
492#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#ifdef __hppa__
494 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .procname = "soft-power",
496 .data = &pwrsw_enabled,
497 .maxlen = sizeof (int),
498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800499 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 },
501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "unaligned-trap",
503 .data = &unaligned_enabled,
504 .maxlen = sizeof (int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 },
508#endif
509 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .procname = "ctrl-alt-del",
511 .data = &C_A_D,
512 .maxlen = sizeof(int),
513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800514 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400516#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200517 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200518 .procname = "ftrace_enabled",
519 .data = &ftrace_enabled,
520 .maxlen = sizeof(int),
521 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800522 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200523 },
524#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500525#ifdef CONFIG_STACK_TRACER
526 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500527 .procname = "stack_tracer_enabled",
528 .data = &stack_tracer_enabled,
529 .maxlen = sizeof(int),
530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800531 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500532 },
533#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400534#ifdef CONFIG_TRACING
535 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100536 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400537 .data = &ftrace_dump_on_oops,
538 .maxlen = sizeof(int),
539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800540 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400541 },
542#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200543#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "modprobe",
546 .data = &modprobe_path,
547 .maxlen = KMOD_PATH_LEN,
548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
Kees Cook3d433212009-04-02 15:49:29 -0700551 {
Kees Cook3d433212009-04-02 15:49:29 -0700552 .procname = "modules_disabled",
553 .data = &modules_disabled,
554 .maxlen = sizeof(int),
555 .mode = 0644,
556 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800557 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700558 .extra1 = &one,
559 .extra2 = &one,
560 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100562#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100565 .data = &uevent_helper,
566 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800568 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 },
570#endif
571#ifdef CONFIG_CHR_DEV_SG
572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "sg-big-buff",
574 .data = &sg_big_buff,
575 .maxlen = sizeof (int),
576 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
579#endif
580#ifdef CONFIG_BSD_PROCESS_ACCT
581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "acct",
583 .data = &acct_parm,
584 .maxlen = 3*sizeof(int),
585 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800586 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#ifdef CONFIG_MAGIC_SYSRQ
590 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800592 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .maxlen = sizeof (int),
594 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700595 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 },
597#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700598#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700601 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .maxlen = sizeof (int),
603 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800604 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700606#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .procname = "threads-max",
609 .data = &max_threads,
610 .maxlen = sizeof(int),
611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800612 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 },
614 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 .procname = "random",
616 .mode = 0555,
617 .child = random_table,
618 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 .procname = "overflowuid",
621 .data = &overflowuid,
622 .maxlen = sizeof(int),
623 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800624 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 .extra1 = &minolduid,
626 .extra2 = &maxolduid,
627 },
628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .procname = "overflowgid",
630 .data = &overflowgid,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800633 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .extra1 = &minolduid,
635 .extra2 = &maxolduid,
636 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800637#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#ifdef CONFIG_MATHEMU
639 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .procname = "ieee_emulation_warnings",
641 .data = &sysctl_ieee_emulation_warnings,
642 .maxlen = sizeof(int),
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 },
646#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200649 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 .maxlen = sizeof(int),
651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 },
654#endif
655 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .procname = "pid_max",
657 .data = &pid_max,
658 .maxlen = sizeof (int),
659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800660 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 .extra1 = &pid_max_min,
662 .extra2 = &pid_max_max,
663 },
664 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 .procname = "panic_on_oops",
666 .data = &panic_on_oops,
667 .maxlen = sizeof(int),
668 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800669 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800671#if defined CONFIG_PRINTK
672 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800673 .procname = "printk",
674 .data = &console_loglevel,
675 .maxlen = 4*sizeof(int),
676 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800677 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800678 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700681 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 .maxlen = sizeof(int),
683 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800684 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 },
686 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700688 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .maxlen = sizeof(int),
690 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800691 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
Dave Youngaf913222009-09-22 16:43:33 -0700693 {
Dave Youngaf913222009-09-22 16:43:33 -0700694 .procname = "printk_delay",
695 .data = &printk_delay_msec,
696 .maxlen = sizeof(int),
697 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800698 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700699 .extra1 = &zero,
700 .extra2 = &ten_thousand,
701 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800703 .procname = "dmesg_restrict",
704 .data = &dmesg_restrict,
705 .maxlen = sizeof(int),
706 .mode = 0644,
707 .proc_handler = proc_dointvec_minmax,
708 .extra1 = &zero,
709 .extra2 = &one,
710 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800711 {
712 .procname = "kptr_restrict",
713 .data = &kptr_restrict,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = proc_dointvec_minmax,
717 .extra1 = &zero,
718 .extra2 = &two,
719 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800720#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800721 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 .procname = "ngroups_max",
723 .data = &ngroups_max,
724 .maxlen = sizeof (int),
725 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800726 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 },
Don Zickus58687ac2010-05-07 17:11:44 -0400728#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500729 {
Don Zickus58687ac2010-05-07 17:11:44 -0400730 .procname = "watchdog",
731 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500732 .maxlen = sizeof (int),
733 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400734 .proc_handler = proc_dowatchdog_enabled,
735 },
736 {
737 .procname = "watchdog_thresh",
738 .data = &softlockup_thresh,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = proc_dowatchdog_thresh,
742 .extra1 = &neg_one,
743 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500744 },
Don Zickus2508ce12010-05-07 17:11:46 -0400745 {
746 .procname = "softlockup_panic",
747 .data = &softlockup_panic,
748 .maxlen = sizeof(int),
749 .mode = 0644,
750 .proc_handler = proc_dointvec_minmax,
751 .extra1 = &zero,
752 .extra2 = &one,
753 },
Don Zickus5dc30552010-11-29 17:07:17 -0500754 {
755 .procname = "nmi_watchdog",
756 .data = &watchdog_enabled,
757 .maxlen = sizeof (int),
758 .mode = 0644,
759 .proc_handler = proc_dowatchdog_enabled,
760 },
761#endif
762#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
763 {
764 .procname = "unknown_nmi_panic",
765 .data = &unknown_nmi_panic,
766 .maxlen = sizeof (int),
767 .mode = 0644,
768 .proc_handler = proc_dointvec,
769 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500770#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771#if defined(CONFIG_X86)
772 {
Don Zickus8da5add2006-09-26 10:52:27 +0200773 .procname = "panic_on_unrecovered_nmi",
774 .data = &panic_on_unrecovered_nmi,
775 .maxlen = sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200778 },
779 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700780 .procname = "panic_on_io_nmi",
781 .data = &panic_on_io_nmi,
782 .maxlen = sizeof(int),
783 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700785 },
786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "bootloader_type",
788 .data = &bootloader_type,
789 .maxlen = sizeof (int),
790 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100793 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700794 .procname = "bootloader_version",
795 .data = &bootloader_version,
796 .maxlen = sizeof (int),
797 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700799 },
800 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100801 .procname = "kstack_depth_to_print",
802 .data = &kstack_depth_to_print,
803 .maxlen = sizeof(int),
804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800805 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100806 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100807 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100808 .procname = "io_delay_type",
809 .data = &io_delay_type,
810 .maxlen = sizeof(int),
811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800812 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100813 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800815#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 .procname = "randomize_va_space",
818 .data = &randomize_va_space,
819 .maxlen = sizeof(int),
820 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800821 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800823#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800824#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700825 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700826 .procname = "spin_retry",
827 .data = &spin_retry,
828 .maxlen = sizeof (int),
829 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800830 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700831 },
832#endif
Len Brown673d5b42007-07-28 03:33:16 -0400833#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800834 {
Pavel Machekc255d842006-02-20 18:27:58 -0800835 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700836 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800837 .maxlen = sizeof (unsigned long),
838 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800839 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800840 },
841#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800842#ifdef CONFIG_IA64
843 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800844 .procname = "ignore-unaligned-usertrap",
845 .data = &no_unaligned_warning,
846 .maxlen = sizeof (int),
847 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800848 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800849 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800850 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800851 .procname = "unaligned-dump-stack",
852 .data = &unaligned_dump_stack,
853 .maxlen = sizeof (int),
854 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800855 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800856 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800857#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800858#ifdef CONFIG_DETECT_HUNG_TASK
859 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800860 .procname = "hung_task_panic",
861 .data = &sysctl_hung_task_panic,
862 .maxlen = sizeof(int),
863 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800864 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800865 .extra1 = &zero,
866 .extra2 = &one,
867 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100869 .procname = "hung_task_check_count",
870 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100871 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100872 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800873 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100874 },
875 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100876 .procname = "hung_task_timeout_secs",
877 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100878 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800880 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100881 },
882 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100883 .procname = "hung_task_warnings",
884 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100885 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100886 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800887 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100888 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700889#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200890#ifdef CONFIG_COMPAT
891 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200892 .procname = "compat-log",
893 .data = &compat_log,
894 .maxlen = sizeof (int),
895 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800896 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200897 },
898#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700899#ifdef CONFIG_RT_MUTEXES
900 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700901 .procname = "max_lock_depth",
902 .data = &max_lock_depth,
903 .maxlen = sizeof(int),
904 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800905 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700906 },
907#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700908 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700909 .procname = "poweroff_cmd",
910 .data = &poweroff_cmd,
911 .maxlen = POWEROFF_CMD_PATH_LEN,
912 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800913 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700914 },
David Howells0b77f5b2008-04-29 01:01:32 -0700915#ifdef CONFIG_KEYS
916 {
David Howells0b77f5b2008-04-29 01:01:32 -0700917 .procname = "keys",
918 .mode = 0555,
919 .child = key_sysctls,
920 },
921#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700922#ifdef CONFIG_RCU_TORTURE_TEST
923 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700924 .procname = "rcutorture_runnable",
925 .data = &rcutorture_runnable,
926 .maxlen = sizeof(int),
927 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800928 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700929 },
930#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200931#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200932 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200933 .procname = "perf_event_paranoid",
934 .data = &sysctl_perf_event_paranoid,
935 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200936 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800937 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200938 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200939 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200940 .procname = "perf_event_mlock_kb",
941 .data = &sysctl_perf_event_mlock,
942 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200943 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200945 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200946 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200947 .procname = "perf_event_max_sample_rate",
948 .data = &sysctl_perf_event_sample_rate,
949 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200950 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200952 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200953#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200954#ifdef CONFIG_KMEMCHECK
955 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200956 .procname = "kmemcheck",
957 .data = &kmemcheck_enabled,
958 .maxlen = sizeof(int),
959 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800960 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200961 },
962#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200963#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200964 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200965 .procname = "blk_iopoll",
966 .data = &blk_iopoll_enabled,
967 .maxlen = sizeof(int),
968 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800969 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200970 },
Jens Axboecb684b52009-09-15 21:53:11 +0200971#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700972 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973};
974
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700975static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 .procname = "overcommit_memory",
978 .data = &sysctl_overcommit_memory,
979 .maxlen = sizeof(sysctl_overcommit_memory),
980 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800981 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 },
983 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700984 .procname = "panic_on_oom",
985 .data = &sysctl_panic_on_oom,
986 .maxlen = sizeof(sysctl_panic_on_oom),
987 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800988 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700989 },
990 {
David Rientjesfe071d72007-10-16 23:25:56 -0700991 .procname = "oom_kill_allocating_task",
992 .data = &sysctl_oom_kill_allocating_task,
993 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700996 },
997 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800998 .procname = "oom_dump_tasks",
999 .data = &sysctl_oom_dump_tasks,
1000 .maxlen = sizeof(sysctl_oom_dump_tasks),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001003 },
1004 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .procname = "overcommit_ratio",
1006 .data = &sysctl_overcommit_ratio,
1007 .maxlen = sizeof(sysctl_overcommit_ratio),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "page-cluster",
1013 .data = &page_cluster,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 },
1018 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .procname = "dirty_background_ratio",
1020 .data = &dirty_background_ratio,
1021 .maxlen = sizeof(dirty_background_ratio),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .extra1 = &zero,
1025 .extra2 = &one_hundred,
1026 },
1027 {
David Rientjes2da02992009-01-06 14:39:31 -08001028 .procname = "dirty_background_bytes",
1029 .data = &dirty_background_bytes,
1030 .maxlen = sizeof(dirty_background_bytes),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001033 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001034 },
1035 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .procname = "dirty_ratio",
1037 .data = &vm_dirty_ratio,
1038 .maxlen = sizeof(vm_dirty_ratio),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 .extra1 = &zero,
1042 .extra2 = &one_hundred,
1043 },
1044 {
David Rientjes2da02992009-01-06 14:39:31 -08001045 .procname = "dirty_bytes",
1046 .data = &vm_dirty_bytes,
1047 .maxlen = sizeof(vm_dirty_bytes),
1048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001050 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001051 },
1052 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001054 .data = &dirty_writeback_interval,
1055 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 },
1059 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001061 .data = &dirty_expire_interval,
1062 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dointvec,
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,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001140 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001141#ifdef CONFIG_COMPACTION
1142 {
1143 .procname = "compact_memory",
1144 .data = &sysctl_compact_memory,
1145 .maxlen = sizeof(int),
1146 .mode = 0200,
1147 .proc_handler = sysctl_compaction_handler,
1148 },
Mel Gorman5e771902010-05-24 14:32:31 -07001149 {
1150 .procname = "extfrag_threshold",
1151 .data = &sysctl_extfrag_threshold,
1152 .maxlen = sizeof(int),
1153 .mode = 0644,
1154 .proc_handler = sysctl_extfrag_handler,
1155 .extra1 = &min_extfrag_threshold,
1156 .extra2 = &max_extfrag_threshold,
1157 },
1158
Mel Gorman76ab0f52010-05-24 14:32:28 -07001159#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001160 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 .procname = "min_free_kbytes",
1162 .data = &min_free_kbytes,
1163 .maxlen = sizeof(min_free_kbytes),
1164 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001165 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 .extra1 = &zero,
1167 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001168 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001169 .procname = "percpu_pagelist_fraction",
1170 .data = &percpu_pagelist_fraction,
1171 .maxlen = sizeof(percpu_pagelist_fraction),
1172 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001173 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001174 .extra1 = &min_percpu_pagelist_fract,
1175 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#ifdef CONFIG_MMU
1177 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 .procname = "max_map_count",
1179 .data = &sysctl_max_map_count,
1180 .maxlen = sizeof(sysctl_max_map_count),
1181 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001182 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001183 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001185#else
1186 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001187 .procname = "nr_trim_pages",
1188 .data = &sysctl_nr_trim_pages,
1189 .maxlen = sizeof(sysctl_nr_trim_pages),
1190 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001191 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001192 .extra1 = &zero,
1193 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194#endif
1195 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 .procname = "laptop_mode",
1197 .data = &laptop_mode,
1198 .maxlen = sizeof(laptop_mode),
1199 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001200 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 },
1202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .procname = "block_dump",
1204 .data = &block_dump,
1205 .maxlen = sizeof(block_dump),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 .extra1 = &zero,
1209 },
1210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .procname = "vfs_cache_pressure",
1212 .data = &sysctl_vfs_cache_pressure,
1213 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1214 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001215 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .extra1 = &zero,
1217 },
1218#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1219 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 .procname = "legacy_va_layout",
1221 .data = &sysctl_legacy_va_layout,
1222 .maxlen = sizeof(sysctl_legacy_va_layout),
1223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001224 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 .extra1 = &zero,
1226 },
1227#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001228#ifdef CONFIG_NUMA
1229 {
Christoph Lameter17436602006-01-18 17:42:32 -08001230 .procname = "zone_reclaim_mode",
1231 .data = &zone_reclaim_mode,
1232 .maxlen = sizeof(zone_reclaim_mode),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001235 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001236 },
Christoph Lameter96146342006-07-03 00:24:13 -07001237 {
Christoph Lameter96146342006-07-03 00:24:13 -07001238 .procname = "min_unmapped_ratio",
1239 .data = &sysctl_min_unmapped_ratio,
1240 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1241 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001242 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001243 .extra1 = &zero,
1244 .extra2 = &one_hundred,
1245 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001246 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001247 .procname = "min_slab_ratio",
1248 .data = &sysctl_min_slab_ratio,
1249 .maxlen = sizeof(sysctl_min_slab_ratio),
1250 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001251 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001252 .extra1 = &zero,
1253 .extra2 = &one_hundred,
1254 },
Christoph Lameter17436602006-01-18 17:42:32 -08001255#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001256#ifdef CONFIG_SMP
1257 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001258 .procname = "stat_interval",
1259 .data = &sysctl_stat_interval,
1260 .maxlen = sizeof(sysctl_stat_interval),
1261 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001263 },
1264#endif
David Howells6e141542009-12-15 19:27:45 +00001265#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001266 {
Eric Parised032182007-06-28 15:55:21 -04001267 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001268 .data = &dac_mmap_min_addr,
1269 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001270 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001271 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001272 },
David Howells6e141542009-12-15 19:27:45 +00001273#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001274#ifdef CONFIG_NUMA
1275 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001276 .procname = "numa_zonelist_order",
1277 .data = &numa_zonelist_order,
1278 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001280 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001281 },
1282#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001283#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001284 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001285 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001286 .procname = "vdso_enabled",
1287 .data = &vdso_enabled,
1288 .maxlen = sizeof(vdso_enabled),
1289 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001290 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001291 .extra1 = &zero,
1292 },
1293#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001294#ifdef CONFIG_HIGHMEM
1295 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001296 .procname = "highmem_is_dirtyable",
1297 .data = &vm_highmem_is_dirtyable,
1298 .maxlen = sizeof(vm_highmem_is_dirtyable),
1299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001301 .extra1 = &zero,
1302 .extra2 = &one,
1303 },
1304#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001305 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001306 .procname = "scan_unevictable_pages",
1307 .data = &scan_unevictable_pages,
1308 .maxlen = sizeof(scan_unevictable_pages),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001311 },
Andi Kleen6a460792009-09-16 11:50:15 +02001312#ifdef CONFIG_MEMORY_FAILURE
1313 {
Andi Kleen6a460792009-09-16 11:50:15 +02001314 .procname = "memory_failure_early_kill",
1315 .data = &sysctl_memory_failure_early_kill,
1316 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1317 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001318 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001319 .extra1 = &zero,
1320 .extra2 = &one,
1321 },
1322 {
Andi Kleen6a460792009-09-16 11:50:15 +02001323 .procname = "memory_failure_recovery",
1324 .data = &sysctl_memory_failure_recovery,
1325 .maxlen = sizeof(sysctl_memory_failure_recovery),
1326 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001327 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001328 .extra1 = &zero,
1329 .extra2 = &one,
1330 },
1331#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001332 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333};
1334
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001335#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001336static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001337 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001338};
1339#endif
1340
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001341static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 .procname = "inode-nr",
1344 .data = &inodes_stat,
1345 .maxlen = 2*sizeof(int),
1346 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001347 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 },
1349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .procname = "inode-state",
1351 .data = &inodes_stat,
1352 .maxlen = 7*sizeof(int),
1353 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001354 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 },
1356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .procname = "file-nr",
1358 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001359 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001361 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 },
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .procname = "file-max",
1365 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001366 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001368 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 },
1370 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001371 .procname = "nr_open",
1372 .data = &sysctl_nr_open,
1373 .maxlen = sizeof(int),
1374 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001375 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001376 .extra1 = &sysctl_nr_open_min,
1377 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001378 },
1379 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 .procname = "dentry-state",
1381 .data = &dentry_stat,
1382 .maxlen = 6*sizeof(int),
1383 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001384 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 },
1386 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 .procname = "overflowuid",
1388 .data = &fs_overflowuid,
1389 .maxlen = sizeof(int),
1390 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001391 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .extra1 = &minolduid,
1393 .extra2 = &maxolduid,
1394 },
1395 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 .procname = "overflowgid",
1397 .data = &fs_overflowgid,
1398 .maxlen = sizeof(int),
1399 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001400 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 .extra1 = &minolduid,
1402 .extra2 = &maxolduid,
1403 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001404#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .procname = "leases-enable",
1407 .data = &leases_enable,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001410 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001412#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413#ifdef CONFIG_DNOTIFY
1414 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 .procname = "dir-notify-enable",
1416 .data = &dir_notify_enable,
1417 .maxlen = sizeof(int),
1418 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001419 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 },
1421#endif
1422#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001423#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 .procname = "lease-break-time",
1426 .data = &lease_break_time,
1427 .maxlen = sizeof(int),
1428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001431#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001432#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 .procname = "aio-nr",
1435 .data = &aio_nr,
1436 .maxlen = sizeof(aio_nr),
1437 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001438 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 },
1440 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 .procname = "aio-max-nr",
1442 .data = &aio_max_nr,
1443 .maxlen = sizeof(aio_max_nr),
1444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001445 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001447#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001448#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001449 {
Robert Love0399cb02005-07-13 12:38:18 -04001450 .procname = "inotify",
1451 .mode = 0555,
1452 .child = inotify_table,
1453 },
1454#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001455#ifdef CONFIG_EPOLL
1456 {
1457 .procname = "epoll",
1458 .mode = 0555,
1459 .child = epoll_table,
1460 },
1461#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001463 {
Alan Coxd6e71142005-06-23 00:09:43 -07001464 .procname = "suid_dumpable",
1465 .data = &suid_dumpable,
1466 .maxlen = sizeof(int),
1467 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001468 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001469 .extra1 = &zero,
1470 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001471 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001472#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1473 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001474 .procname = "binfmt_misc",
1475 .mode = 0555,
1476 .child = binfmt_misc_table,
1477 },
1478#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001479 {
Jens Axboeff9da692010-06-03 14:54:39 +02001480 .procname = "pipe-max-size",
1481 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001482 .maxlen = sizeof(int),
1483 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001484 .proc_handler = &pipe_proc_fn,
1485 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001486 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001487 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488};
1489
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001490static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001491#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1492 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001493 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001494 .procname = "exception-trace",
1495 .data = &show_unhandled_signals,
1496 .maxlen = sizeof(int),
1497 .mode = 0644,
1498 .proc_handler = proc_dointvec
1499 },
1500#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001501#if defined(CONFIG_OPTPROBES)
1502 {
1503 .procname = "kprobes-optimization",
1504 .data = &sysctl_kprobes_optimization,
1505 .maxlen = sizeof(int),
1506 .mode = 0644,
1507 .proc_handler = proc_kprobes_optimization_handler,
1508 .extra1 = &zero,
1509 .extra2 = &one,
1510 },
1511#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001512 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513};
1514
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001515static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001516 { }
Robert Love0eeca282005-07-12 17:06:03 -04001517};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Al Viro330d57f2005-11-04 10:18:40 +00001519static DEFINE_SPINLOCK(sysctl_lock);
1520
1521/* called under sysctl_lock */
1522static int use_table(struct ctl_table_header *p)
1523{
1524 if (unlikely(p->unregistering))
1525 return 0;
1526 p->used++;
1527 return 1;
1528}
1529
1530/* called under sysctl_lock */
1531static void unuse_table(struct ctl_table_header *p)
1532{
1533 if (!--p->used)
1534 if (unlikely(p->unregistering))
1535 complete(p->unregistering);
1536}
1537
1538/* called under sysctl_lock, will reacquire if has to wait */
1539static void start_unregistering(struct ctl_table_header *p)
1540{
1541 /*
1542 * if p->used is 0, nobody will ever touch that entry again;
1543 * we'll eliminate all paths to it before dropping sysctl_lock
1544 */
1545 if (unlikely(p->used)) {
1546 struct completion wait;
1547 init_completion(&wait);
1548 p->unregistering = &wait;
1549 spin_unlock(&sysctl_lock);
1550 wait_for_completion(&wait);
1551 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001552 } else {
1553 /* anything non-NULL; we'll never dereference it */
1554 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001555 }
1556 /*
1557 * do not remove from the list until nobody holds it; walking the
1558 * list in do_sysctl() relies on that.
1559 */
1560 list_del_init(&p->ctl_entry);
1561}
1562
Al Virof7e6ced2008-07-15 01:44:23 -04001563void sysctl_head_get(struct ctl_table_header *head)
1564{
1565 spin_lock(&sysctl_lock);
1566 head->count++;
1567 spin_unlock(&sysctl_lock);
1568}
1569
1570void sysctl_head_put(struct ctl_table_header *head)
1571{
1572 spin_lock(&sysctl_lock);
1573 if (!--head->count)
1574 kfree(head);
1575 spin_unlock(&sysctl_lock);
1576}
1577
1578struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1579{
1580 if (!head)
1581 BUG();
1582 spin_lock(&sysctl_lock);
1583 if (!use_table(head))
1584 head = ERR_PTR(-ENOENT);
1585 spin_unlock(&sysctl_lock);
1586 return head;
1587}
1588
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001589void sysctl_head_finish(struct ctl_table_header *head)
1590{
1591 if (!head)
1592 return;
1593 spin_lock(&sysctl_lock);
1594 unuse_table(head);
1595 spin_unlock(&sysctl_lock);
1596}
1597
Al Viro73455092008-07-14 21:22:20 -04001598static struct ctl_table_set *
1599lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1600{
1601 struct ctl_table_set *set = &root->default_set;
1602 if (root->lookup)
1603 set = root->lookup(root, namespaces);
1604 return set;
1605}
1606
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001607static struct list_head *
1608lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001609{
Al Viro73455092008-07-14 21:22:20 -04001610 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1611 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001612}
1613
1614struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1615 struct ctl_table_header *prev)
1616{
1617 struct ctl_table_root *root;
1618 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001619 struct ctl_table_header *head;
1620 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001621
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001622 spin_lock(&sysctl_lock);
1623 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001624 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625 tmp = &prev->ctl_entry;
1626 unuse_table(prev);
1627 goto next;
1628 }
1629 tmp = &root_table_header.ctl_entry;
1630 for (;;) {
1631 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1632
1633 if (!use_table(head))
1634 goto next;
1635 spin_unlock(&sysctl_lock);
1636 return head;
1637 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001638 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001639 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001640 header_list = lookup_header_list(root, namespaces);
1641 if (tmp != header_list)
1642 continue;
1643
1644 do {
1645 root = list_entry(root->root_list.next,
1646 struct ctl_table_root, root_list);
1647 if (root == &sysctl_table_root)
1648 goto out;
1649 header_list = lookup_header_list(root, namespaces);
1650 } while (list_empty(header_list));
1651 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001652 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001653out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001654 spin_unlock(&sysctl_lock);
1655 return NULL;
1656}
1657
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001658struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1659{
1660 return __sysctl_head_next(current->nsproxy, prev);
1661}
1662
1663void register_sysctl_root(struct ctl_table_root *root)
1664{
1665 spin_lock(&sysctl_lock);
1666 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1667 spin_unlock(&sysctl_lock);
1668}
1669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001671 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 * some sysctl variables are readonly even to root.
1673 */
1674
1675static int test_perm(int mode, int op)
1676{
David Howells76aac0e2008-11-14 10:39:12 +11001677 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 mode >>= 6;
1679 else if (in_egroup_p(0))
1680 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001681 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 return 0;
1683 return -EACCES;
1684}
1685
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001686int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
1688 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001689 int mode;
1690
Al Viroe6305c42008-07-15 21:03:57 -04001691 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 if (error)
1693 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001694
1695 if (root->permissions)
1696 mode = root->permissions(root, current->nsproxy, table);
1697 else
1698 mode = table->mode;
1699
1700 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001703static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1704{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001705 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001706 table->parent = parent;
1707 if (table->child)
1708 sysctl_set_parent(table, table->child);
1709 }
1710}
1711
1712static __init int sysctl_init(void)
1713{
1714 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001715#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001716 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001717#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001718 return 0;
1719}
1720
1721core_initcall(sysctl_init);
1722
Al Virobfbcf032008-07-27 06:31:22 +01001723static struct ctl_table *is_branch_in(struct ctl_table *branch,
1724 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001725{
1726 struct ctl_table *p;
1727 const char *s = branch->procname;
1728
1729 /* branch should have named subdirectory as its first element */
1730 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001731 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001732
1733 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001734 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001735 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001736
1737 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001738 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001739 if (!p->child)
1740 continue;
1741 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001742 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001743 }
Al Virobfbcf032008-07-27 06:31:22 +01001744 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001745}
1746
1747/* see if attaching q to p would be an improvement */
1748static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1749{
1750 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001751 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001752 int is_better = 0;
1753 int not_in_parent = !p->attached_by;
1754
Al Virobfbcf032008-07-27 06:31:22 +01001755 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001756 if (by == q->attached_by)
1757 is_better = 1;
1758 if (to == p->attached_by)
1759 not_in_parent = 1;
1760 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001761 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001762 }
1763
1764 if (is_better && not_in_parent) {
1765 q->attached_by = by;
1766 q->attached_to = to;
1767 q->parent = p;
1768 }
1769}
1770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001772 * __register_sysctl_paths - register a sysctl hierarchy
1773 * @root: List of sysctl headers to register on
1774 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001775 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 *
1778 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001779 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001781 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1784 * enter a sysctl file
1785 *
1786 * data - a pointer to data for use by proc_handler
1787 *
1788 * maxlen - the maximum size in bytes of the data
1789 *
1790 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1791 *
1792 * child - a pointer to the child sysctl table if this entry is a directory, or
1793 * %NULL.
1794 *
1795 * proc_handler - the text handler routine (described below)
1796 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 * de - for internal use by the sysctl routines
1798 *
1799 * extra1, extra2 - extra pointers usable by the proc handler routines
1800 *
1801 * Leaf nodes in the sysctl tree will be represented by a single file
1802 * under /proc; non-leaf nodes will be represented by directories.
1803 *
1804 * sysctl(2) can automatically manage read and write requests through
1805 * the sysctl table. The data and maxlen fields of the ctl_table
1806 * struct enable minimal validation of the values being written to be
1807 * performed, and the mode field allows minimal authentication.
1808 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 * There must be a proc_handler routine for any terminal nodes
1810 * mirrored under /proc/sys (non-terminals are handled by a built-in
1811 * directory handler). Several default handlers are available to
1812 * cover common cases -
1813 *
1814 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1815 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1816 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1817 *
1818 * It is the handler's job to read the input buffer from user memory
1819 * and process it. The handler should return 0 on success.
1820 *
1821 * This routine returns %NULL on a failure to register, and a pointer
1822 * to the table header on success.
1823 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001824struct ctl_table_header *__register_sysctl_paths(
1825 struct ctl_table_root *root,
1826 struct nsproxy *namespaces,
1827 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001829 struct ctl_table_header *header;
1830 struct ctl_table *new, **prevp;
1831 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001832 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001833
1834 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001835 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001836 ;
1837
1838 /*
1839 * For each path component, allocate a 2-element ctl_table array.
1840 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001841 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001842 *
1843 * We allocate everything in one go so that we don't have to
1844 * worry about freeing additional memory in unregister_sysctl_table.
1845 */
1846 header = kzalloc(sizeof(struct ctl_table_header) +
1847 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1848 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001850
1851 new = (struct ctl_table *) (header + 1);
1852
1853 /* Now connect the dots */
1854 prevp = &header->ctl_table;
1855 for (n = 0; n < npath; ++n, ++path) {
1856 /* Copy the procname */
1857 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001858 new->mode = 0555;
1859
1860 *prevp = new;
1861 prevp = &new->child;
1862
1863 new += 2;
1864 }
1865 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001866 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001867
1868 INIT_LIST_HEAD(&header->ctl_entry);
1869 header->used = 0;
1870 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001871 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001872 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001873 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001874#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001875 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001876 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001877 return NULL;
1878 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001879#endif
Al Viro330d57f2005-11-04 10:18:40 +00001880 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001881 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001882 header->attached_by = header->ctl_table;
1883 header->attached_to = root_table;
1884 header->parent = &root_table_header;
1885 for (set = header->set; set; set = set->parent) {
1886 struct ctl_table_header *p;
1887 list_for_each_entry(p, &set->list, ctl_entry) {
1888 if (p->unregistering)
1889 continue;
1890 try_attach(p, header);
1891 }
1892 }
1893 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001894 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001895 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001896
1897 return header;
1898}
1899
1900/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001901 * register_sysctl_table_path - register a sysctl table hierarchy
1902 * @path: The path to the directory the sysctl table is in.
1903 * @table: the top-level table structure
1904 *
1905 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1906 * array. A completely 0 filled entry terminates the table.
1907 *
1908 * See __register_sysctl_paths for more details.
1909 */
1910struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1911 struct ctl_table *table)
1912{
1913 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1914 path, table);
1915}
1916
1917/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001918 * register_sysctl_table - register a sysctl table hierarchy
1919 * @table: the top-level table structure
1920 *
1921 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1922 * array. A completely 0 filled entry terminates the table.
1923 *
1924 * See register_sysctl_paths for more details.
1925 */
1926struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1927{
1928 static const struct ctl_path null_path[] = { {} };
1929
1930 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931}
1932
1933/**
1934 * unregister_sysctl_table - unregister a sysctl table hierarchy
1935 * @header: the header returned from register_sysctl_table
1936 *
1937 * Unregisters the sysctl table and all children. proc entries may not
1938 * actually be removed until they are no longer used by anyone.
1939 */
1940void unregister_sysctl_table(struct ctl_table_header * header)
1941{
Al Viro330d57f2005-11-04 10:18:40 +00001942 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001943
1944 if (header == NULL)
1945 return;
1946
Al Viro330d57f2005-11-04 10:18:40 +00001947 spin_lock(&sysctl_lock);
1948 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001949 if (!--header->parent->count) {
1950 WARN_ON(1);
1951 kfree(header->parent);
1952 }
Al Virof7e6ced2008-07-15 01:44:23 -04001953 if (!--header->count)
1954 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001955 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
Al Viro90434762008-07-15 08:54:06 -04001958int sysctl_is_seen(struct ctl_table_header *p)
1959{
1960 struct ctl_table_set *set = p->set;
1961 int res;
1962 spin_lock(&sysctl_lock);
1963 if (p->unregistering)
1964 res = 0;
1965 else if (!set->is_seen)
1966 res = 1;
1967 else
1968 res = set->is_seen(set);
1969 spin_unlock(&sysctl_lock);
1970 return res;
1971}
1972
Al Viro73455092008-07-14 21:22:20 -04001973void setup_sysctl_set(struct ctl_table_set *p,
1974 struct ctl_table_set *parent,
1975 int (*is_seen)(struct ctl_table_set *))
1976{
1977 INIT_LIST_HEAD(&p->list);
1978 p->parent = parent ? parent : &sysctl_table_root.default_set;
1979 p->is_seen = is_seen;
1980}
1981
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001982#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001983struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001984{
1985 return NULL;
1986}
1987
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001988struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1989 struct ctl_table *table)
1990{
1991 return NULL;
1992}
1993
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001994void unregister_sysctl_table(struct ctl_table_header * table)
1995{
1996}
1997
Al Viro73455092008-07-14 21:22:20 -04001998void setup_sysctl_set(struct ctl_table_set *p,
1999 struct ctl_table_set *parent,
2000 int (*is_seen)(struct ctl_table_set *))
2001{
2002}
2003
Al Virof7e6ced2008-07-15 01:44:23 -04002004void sysctl_head_put(struct ctl_table_header *head)
2005{
2006}
2007
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002008#endif /* CONFIG_SYSCTL */
2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010/*
2011 * /proc/sys support
2012 */
2013
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002014#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002016static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002017 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002018 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002019{
2020 size_t len;
2021 char __user *p;
2022 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002023
2024 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002025 *lenp = 0;
2026 return 0;
2027 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002028
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002029 if (write) {
2030 len = 0;
2031 p = buffer;
2032 while (len < *lenp) {
2033 if (get_user(c, p++))
2034 return -EFAULT;
2035 if (c == 0 || c == '\n')
2036 break;
2037 len++;
2038 }
2039 if (len >= maxlen)
2040 len = maxlen-1;
2041 if(copy_from_user(data, buffer, len))
2042 return -EFAULT;
2043 ((char *) data)[len] = 0;
2044 *ppos += *lenp;
2045 } else {
2046 len = strlen(data);
2047 if (len > maxlen)
2048 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002049
2050 if (*ppos > len) {
2051 *lenp = 0;
2052 return 0;
2053 }
2054
2055 data += *ppos;
2056 len -= *ppos;
2057
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002058 if (len > *lenp)
2059 len = *lenp;
2060 if (len)
2061 if(copy_to_user(buffer, data, len))
2062 return -EFAULT;
2063 if (len < *lenp) {
2064 if(put_user('\n', ((char __user *) buffer) + len))
2065 return -EFAULT;
2066 len++;
2067 }
2068 *lenp = len;
2069 *ppos += len;
2070 }
2071 return 0;
2072}
2073
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074/**
2075 * proc_dostring - read a string sysctl
2076 * @table: the sysctl table
2077 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 * @buffer: the user buffer
2079 * @lenp: the size of the user buffer
2080 * @ppos: file position
2081 *
2082 * Reads/writes a string from/to the user buffer. If the kernel
2083 * buffer provided is not large enough to hold the string, the
2084 * string is truncated. The copied string is %NULL-terminated.
2085 * If the string is being read by the user process, it is copied
2086 * and a newline '\n' is added. It is truncated if the buffer is
2087 * not large enough.
2088 *
2089 * Returns 0 on success.
2090 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002091int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 void __user *buffer, size_t *lenp, loff_t *ppos)
2093{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002094 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002095 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
Amerigo Wang00b7c332010-05-05 00:26:45 +00002098static size_t proc_skip_spaces(char **buf)
2099{
2100 size_t ret;
2101 char *tmp = skip_spaces(*buf);
2102 ret = tmp - *buf;
2103 *buf = tmp;
2104 return ret;
2105}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002107static void proc_skip_char(char **buf, size_t *size, const char v)
2108{
2109 while (*size) {
2110 if (**buf != v)
2111 break;
2112 (*size)--;
2113 (*buf)++;
2114 }
2115}
2116
Amerigo Wang00b7c332010-05-05 00:26:45 +00002117#define TMPBUFLEN 22
2118/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002119 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002120 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002121 * @buf: a kernel buffer
2122 * @size: size of the kernel buffer
2123 * @val: this is where the number will be stored
2124 * @neg: set to %TRUE if number is negative
2125 * @perm_tr: a vector which contains the allowed trailers
2126 * @perm_tr_len: size of the perm_tr vector
2127 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002128 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002129 * In case of success %0 is returned and @buf and @size are updated with
2130 * the amount of bytes read. If @tr is non-NULL and a trailing
2131 * character exists (size is non-zero after returning from this
2132 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002133 */
2134static int proc_get_long(char **buf, size_t *size,
2135 unsigned long *val, bool *neg,
2136 const char *perm_tr, unsigned perm_tr_len, char *tr)
2137{
2138 int len;
2139 char *p, tmp[TMPBUFLEN];
2140
2141 if (!*size)
2142 return -EINVAL;
2143
2144 len = *size;
2145 if (len > TMPBUFLEN - 1)
2146 len = TMPBUFLEN - 1;
2147
2148 memcpy(tmp, *buf, len);
2149
2150 tmp[len] = 0;
2151 p = tmp;
2152 if (*p == '-' && *size > 1) {
2153 *neg = true;
2154 p++;
2155 } else
2156 *neg = false;
2157 if (!isdigit(*p))
2158 return -EINVAL;
2159
2160 *val = simple_strtoul(p, &p, 0);
2161
2162 len = p - tmp;
2163
2164 /* We don't know if the next char is whitespace thus we may accept
2165 * invalid integers (e.g. 1234...a) or two integers instead of one
2166 * (e.g. 123...1). So lets not allow such large numbers. */
2167 if (len == TMPBUFLEN - 1)
2168 return -EINVAL;
2169
2170 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2171 return -EINVAL;
2172
2173 if (tr && (len < *size))
2174 *tr = *p;
2175
2176 *buf += len;
2177 *size -= len;
2178
2179 return 0;
2180}
2181
2182/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002183 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002184 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002185 * @buf: the user buffer
2186 * @size: the size of the user buffer
2187 * @val: the integer to be converted
2188 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002189 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002190 * In case of success %0 is returned and @buf and @size are updated with
2191 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002192 */
2193static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2194 bool neg)
2195{
2196 int len;
2197 char tmp[TMPBUFLEN], *p = tmp;
2198
2199 sprintf(p, "%s%lu", neg ? "-" : "", val);
2200 len = strlen(tmp);
2201 if (len > *size)
2202 len = *size;
2203 if (copy_to_user(*buf, tmp, len))
2204 return -EFAULT;
2205 *size -= len;
2206 *buf += len;
2207 return 0;
2208}
2209#undef TMPBUFLEN
2210
2211static int proc_put_char(void __user **buf, size_t *size, char c)
2212{
2213 if (*size) {
2214 char __user **buffer = (char __user **)buf;
2215 if (put_user(c, *buffer))
2216 return -EFAULT;
2217 (*size)--, (*buffer)++;
2218 *buf = *buffer;
2219 }
2220 return 0;
2221}
2222
2223static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 int *valp,
2225 int write, void *data)
2226{
2227 if (write) {
2228 *valp = *negp ? -*lvalp : *lvalp;
2229 } else {
2230 int val = *valp;
2231 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002232 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 *lvalp = (unsigned long)-val;
2234 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002235 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 *lvalp = (unsigned long)val;
2237 }
2238 }
2239 return 0;
2240}
2241
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2243
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002244static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002245 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002246 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002247 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 int write, void *data),
2249 void *data)
2250{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002251 int *i, vleft, first = 1, err = 0;
2252 unsigned long page = 0;
2253 size_t left;
2254 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Amerigo Wang00b7c332010-05-05 00:26:45 +00002256 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 *lenp = 0;
2258 return 0;
2259 }
2260
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002261 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 vleft = table->maxlen / sizeof(*i);
2263 left = *lenp;
2264
2265 if (!conv)
2266 conv = do_proc_dointvec_conv;
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002269 if (left > PAGE_SIZE - 1)
2270 left = PAGE_SIZE - 1;
2271 page = __get_free_page(GFP_TEMPORARY);
2272 kbuf = (char *) page;
2273 if (!kbuf)
2274 return -ENOMEM;
2275 if (copy_from_user(kbuf, buffer, left)) {
2276 err = -EFAULT;
2277 goto free;
2278 }
2279 kbuf[left] = 0;
2280 }
2281
2282 for (; left && vleft--; i++, first=0) {
2283 unsigned long lval;
2284 bool neg;
2285
2286 if (write) {
2287 left -= proc_skip_spaces(&kbuf);
2288
J. R. Okajima563b0462010-05-25 16:10:14 -07002289 if (!left)
2290 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002291 err = proc_get_long(&kbuf, &left, &lval, &neg,
2292 proc_wspace_sep,
2293 sizeof(proc_wspace_sep), NULL);
2294 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002296 if (conv(&neg, &lval, i, 1, data)) {
2297 err = -EINVAL;
2298 break;
2299 }
2300 } else {
2301 if (conv(&neg, &lval, i, 0, data)) {
2302 err = -EINVAL;
2303 break;
2304 }
2305 if (!first)
2306 err = proc_put_char(&buffer, &left, '\t');
2307 if (err)
2308 break;
2309 err = proc_put_long(&buffer, &left, lval, neg);
2310 if (err)
2311 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 }
2313 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002314
2315 if (!write && !first && left && !err)
2316 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002317 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 left -= proc_skip_spaces(&kbuf);
2319free:
2320 if (write) {
2321 free_page(page);
2322 if (first)
2323 return err ? : -EINVAL;
2324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 *lenp -= left;
2326 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002327 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328}
2329
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002330static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002331 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002332 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002333 int write, void *data),
2334 void *data)
2335{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002336 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002337 buffer, lenp, ppos, conv, data);
2338}
2339
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340/**
2341 * proc_dointvec - read a vector of integers
2342 * @table: the sysctl table
2343 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 * @buffer: the user buffer
2345 * @lenp: the size of the user buffer
2346 * @ppos: file position
2347 *
2348 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2349 * values from/to the user buffer, treated as an ASCII string.
2350 *
2351 * Returns 0 on success.
2352 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002353int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 void __user *buffer, size_t *lenp, loff_t *ppos)
2355{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002356 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 NULL,NULL);
2358}
2359
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002360/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002361 * Taint values can only be increased
2362 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002363 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002364static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002365 void __user *buffer, size_t *lenp, loff_t *ppos)
2366{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002367 struct ctl_table t;
2368 unsigned long tmptaint = get_taint();
2369 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002370
Bastian Blank91fcd412007-04-23 14:41:14 -07002371 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372 return -EPERM;
2373
Andi Kleen25ddbb12008-10-15 22:01:41 -07002374 t = *table;
2375 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002376 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002377 if (err < 0)
2378 return err;
2379
2380 if (write) {
2381 /*
2382 * Poor man's atomic or. Not worth adding a primitive
2383 * to everyone's atomic.h for this
2384 */
2385 int i;
2386 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2387 if ((tmptaint >> i) & 1)
2388 add_taint(i);
2389 }
2390 }
2391
2392 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002393}
2394
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395struct do_proc_dointvec_minmax_conv_param {
2396 int *min;
2397 int *max;
2398};
2399
Amerigo Wang00b7c332010-05-05 00:26:45 +00002400static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2401 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 int write, void *data)
2403{
2404 struct do_proc_dointvec_minmax_conv_param *param = data;
2405 if (write) {
2406 int val = *negp ? -*lvalp : *lvalp;
2407 if ((param->min && *param->min > val) ||
2408 (param->max && *param->max < val))
2409 return -EINVAL;
2410 *valp = val;
2411 } else {
2412 int val = *valp;
2413 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002414 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 *lvalp = (unsigned long)-val;
2416 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002417 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 *lvalp = (unsigned long)val;
2419 }
2420 }
2421 return 0;
2422}
2423
2424/**
2425 * proc_dointvec_minmax - read a vector of integers with min/max values
2426 * @table: the sysctl table
2427 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 * @buffer: the user buffer
2429 * @lenp: the size of the user buffer
2430 * @ppos: file position
2431 *
2432 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2433 * values from/to the user buffer, treated as an ASCII string.
2434 *
2435 * This routine will ensure the values are within the range specified by
2436 * table->extra1 (min) and table->extra2 (max).
2437 *
2438 * Returns 0 on success.
2439 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002440int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 void __user *buffer, size_t *lenp, loff_t *ppos)
2442{
2443 struct do_proc_dointvec_minmax_conv_param param = {
2444 .min = (int *) table->extra1,
2445 .max = (int *) table->extra2,
2446 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002447 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 do_proc_dointvec_minmax_conv, &param);
2449}
2450
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002451static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 void __user *buffer,
2453 size_t *lenp, loff_t *ppos,
2454 unsigned long convmul,
2455 unsigned long convdiv)
2456{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002457 unsigned long *i, *min, *max;
2458 int vleft, first = 1, err = 0;
2459 unsigned long page = 0;
2460 size_t left;
2461 char *kbuf;
2462
2463 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 *lenp = 0;
2465 return 0;
2466 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002467
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002468 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 min = (unsigned long *) table->extra1;
2470 max = (unsigned long *) table->extra2;
2471 vleft = table->maxlen / sizeof(unsigned long);
2472 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002473
2474 if (write) {
2475 if (left > PAGE_SIZE - 1)
2476 left = PAGE_SIZE - 1;
2477 page = __get_free_page(GFP_TEMPORARY);
2478 kbuf = (char *) page;
2479 if (!kbuf)
2480 return -ENOMEM;
2481 if (copy_from_user(kbuf, buffer, left)) {
2482 err = -EFAULT;
2483 goto free;
2484 }
2485 kbuf[left] = 0;
2486 }
2487
Eric Dumazet27b3d802010-10-07 12:59:29 -07002488 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002489 unsigned long val;
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002492 bool neg;
2493
2494 left -= proc_skip_spaces(&kbuf);
2495
2496 err = proc_get_long(&kbuf, &left, &val, &neg,
2497 proc_wspace_sep,
2498 sizeof(proc_wspace_sep), NULL);
2499 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 break;
2501 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 continue;
2503 if ((min && val < *min) || (max && val > *max))
2504 continue;
2505 *i = val;
2506 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002507 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002509 err = proc_put_char(&buffer, &left, '\t');
2510 err = proc_put_long(&buffer, &left, val, false);
2511 if (err)
2512 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 }
2514 }
2515
Amerigo Wang00b7c332010-05-05 00:26:45 +00002516 if (!write && !first && left && !err)
2517 err = proc_put_char(&buffer, &left, '\n');
2518 if (write && !err)
2519 left -= proc_skip_spaces(&kbuf);
2520free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002522 free_page(page);
2523 if (first)
2524 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 *lenp -= left;
2527 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529}
2530
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002531static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002532 void __user *buffer,
2533 size_t *lenp, loff_t *ppos,
2534 unsigned long convmul,
2535 unsigned long convdiv)
2536{
2537 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002538 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002539}
2540
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541/**
2542 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2543 * @table: the sysctl table
2544 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 * @buffer: the user buffer
2546 * @lenp: the size of the user buffer
2547 * @ppos: file position
2548 *
2549 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2550 * values from/to the user buffer, treated as an ASCII string.
2551 *
2552 * This routine will ensure the values are within the range specified by
2553 * table->extra1 (min) and table->extra2 (max).
2554 *
2555 * Returns 0 on success.
2556 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002557int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 void __user *buffer, size_t *lenp, loff_t *ppos)
2559{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002560 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561}
2562
2563/**
2564 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2565 * @table: the sysctl table
2566 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 * @buffer: the user buffer
2568 * @lenp: the size of the user buffer
2569 * @ppos: file position
2570 *
2571 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2572 * values from/to the user buffer, treated as an ASCII string. The values
2573 * are treated as milliseconds, and converted to jiffies when they are stored.
2574 *
2575 * This routine will ensure the values are within the range specified by
2576 * table->extra1 (min) and table->extra2 (max).
2577 *
2578 * Returns 0 on success.
2579 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002580int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 void __user *buffer,
2582 size_t *lenp, loff_t *ppos)
2583{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002584 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 lenp, ppos, HZ, 1000l);
2586}
2587
2588
Amerigo Wang00b7c332010-05-05 00:26:45 +00002589static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 int *valp,
2591 int write, void *data)
2592{
2593 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002594 if (*lvalp > LONG_MAX / HZ)
2595 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2597 } else {
2598 int val = *valp;
2599 unsigned long lval;
2600 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002601 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 lval = (unsigned long)-val;
2603 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002604 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 lval = (unsigned long)val;
2606 }
2607 *lvalp = lval / HZ;
2608 }
2609 return 0;
2610}
2611
Amerigo Wang00b7c332010-05-05 00:26:45 +00002612static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 int *valp,
2614 int write, void *data)
2615{
2616 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002617 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2618 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2620 } else {
2621 int val = *valp;
2622 unsigned long lval;
2623 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002624 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 lval = (unsigned long)-val;
2626 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002627 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 lval = (unsigned long)val;
2629 }
2630 *lvalp = jiffies_to_clock_t(lval);
2631 }
2632 return 0;
2633}
2634
Amerigo Wang00b7c332010-05-05 00:26:45 +00002635static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 int *valp,
2637 int write, void *data)
2638{
2639 if (write) {
2640 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2641 } else {
2642 int val = *valp;
2643 unsigned long lval;
2644 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002645 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 lval = (unsigned long)-val;
2647 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002648 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 lval = (unsigned long)val;
2650 }
2651 *lvalp = jiffies_to_msecs(lval);
2652 }
2653 return 0;
2654}
2655
2656/**
2657 * proc_dointvec_jiffies - read a vector of integers as seconds
2658 * @table: the sysctl table
2659 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 * @buffer: the user buffer
2661 * @lenp: the size of the user buffer
2662 * @ppos: file position
2663 *
2664 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2665 * values from/to the user buffer, treated as an ASCII string.
2666 * The values read are assumed to be in seconds, and are converted into
2667 * jiffies.
2668 *
2669 * Returns 0 on success.
2670 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002671int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 void __user *buffer, size_t *lenp, loff_t *ppos)
2673{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002674 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 do_proc_dointvec_jiffies_conv,NULL);
2676}
2677
2678/**
2679 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2680 * @table: the sysctl table
2681 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 * @buffer: the user buffer
2683 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002684 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 *
2686 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2687 * values from/to the user buffer, treated as an ASCII string.
2688 * The values read are assumed to be in 1/USER_HZ seconds, and
2689 * are converted into jiffies.
2690 *
2691 * Returns 0 on success.
2692 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002693int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 void __user *buffer, size_t *lenp, loff_t *ppos)
2695{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002696 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 do_proc_dointvec_userhz_jiffies_conv,NULL);
2698}
2699
2700/**
2701 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2702 * @table: the sysctl table
2703 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 * @buffer: the user buffer
2705 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002706 * @ppos: file position
2707 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 *
2709 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2710 * values from/to the user buffer, treated as an ASCII string.
2711 * The values read are assumed to be in 1/1000 seconds, and
2712 * are converted into jiffies.
2713 *
2714 * Returns 0 on success.
2715 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002716int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 void __user *buffer, size_t *lenp, loff_t *ppos)
2718{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002719 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 do_proc_dointvec_ms_jiffies_conv, NULL);
2721}
2722
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002724 void __user *buffer, size_t *lenp, loff_t *ppos)
2725{
2726 struct pid *new_pid;
2727 pid_t tmp;
2728 int r;
2729
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002730 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002731
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002732 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002733 lenp, ppos, NULL, NULL);
2734 if (r || !write)
2735 return r;
2736
2737 new_pid = find_get_pid(tmp);
2738 if (!new_pid)
2739 return -ESRCH;
2740
2741 put_pid(xchg(&cad_pid, new_pid));
2742 return 0;
2743}
2744
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002745/**
2746 * proc_do_large_bitmap - read/write from/to a large bitmap
2747 * @table: the sysctl table
2748 * @write: %TRUE if this is a write to the sysctl file
2749 * @buffer: the user buffer
2750 * @lenp: the size of the user buffer
2751 * @ppos: file position
2752 *
2753 * The bitmap is stored at table->data and the bitmap length (in bits)
2754 * in table->maxlen.
2755 *
2756 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2757 * large bitmaps may be represented in a compact manner. Writing into
2758 * the file will clear the bitmap then update it with the given input.
2759 *
2760 * Returns 0 on success.
2761 */
2762int proc_do_large_bitmap(struct ctl_table *table, int write,
2763 void __user *buffer, size_t *lenp, loff_t *ppos)
2764{
2765 int err = 0;
2766 bool first = 1;
2767 size_t left = *lenp;
2768 unsigned long bitmap_len = table->maxlen;
2769 unsigned long *bitmap = (unsigned long *) table->data;
2770 unsigned long *tmp_bitmap = NULL;
2771 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2772
2773 if (!bitmap_len || !left || (*ppos && !write)) {
2774 *lenp = 0;
2775 return 0;
2776 }
2777
2778 if (write) {
2779 unsigned long page = 0;
2780 char *kbuf;
2781
2782 if (left > PAGE_SIZE - 1)
2783 left = PAGE_SIZE - 1;
2784
2785 page = __get_free_page(GFP_TEMPORARY);
2786 kbuf = (char *) page;
2787 if (!kbuf)
2788 return -ENOMEM;
2789 if (copy_from_user(kbuf, buffer, left)) {
2790 free_page(page);
2791 return -EFAULT;
2792 }
2793 kbuf[left] = 0;
2794
2795 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2796 GFP_KERNEL);
2797 if (!tmp_bitmap) {
2798 free_page(page);
2799 return -ENOMEM;
2800 }
2801 proc_skip_char(&kbuf, &left, '\n');
2802 while (!err && left) {
2803 unsigned long val_a, val_b;
2804 bool neg;
2805
2806 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2807 sizeof(tr_a), &c);
2808 if (err)
2809 break;
2810 if (val_a >= bitmap_len || neg) {
2811 err = -EINVAL;
2812 break;
2813 }
2814
2815 val_b = val_a;
2816 if (left) {
2817 kbuf++;
2818 left--;
2819 }
2820
2821 if (c == '-') {
2822 err = proc_get_long(&kbuf, &left, &val_b,
2823 &neg, tr_b, sizeof(tr_b),
2824 &c);
2825 if (err)
2826 break;
2827 if (val_b >= bitmap_len || neg ||
2828 val_a > val_b) {
2829 err = -EINVAL;
2830 break;
2831 }
2832 if (left) {
2833 kbuf++;
2834 left--;
2835 }
2836 }
2837
2838 while (val_a <= val_b)
2839 set_bit(val_a++, tmp_bitmap);
2840
2841 first = 0;
2842 proc_skip_char(&kbuf, &left, '\n');
2843 }
2844 free_page(page);
2845 } else {
2846 unsigned long bit_a, bit_b = 0;
2847
2848 while (left) {
2849 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2850 if (bit_a >= bitmap_len)
2851 break;
2852 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2853 bit_a + 1) - 1;
2854
2855 if (!first) {
2856 err = proc_put_char(&buffer, &left, ',');
2857 if (err)
2858 break;
2859 }
2860 err = proc_put_long(&buffer, &left, bit_a, false);
2861 if (err)
2862 break;
2863 if (bit_a != bit_b) {
2864 err = proc_put_char(&buffer, &left, '-');
2865 if (err)
2866 break;
2867 err = proc_put_long(&buffer, &left, bit_b, false);
2868 if (err)
2869 break;
2870 }
2871
2872 first = 0; bit_b++;
2873 }
2874 if (!err)
2875 err = proc_put_char(&buffer, &left, '\n');
2876 }
2877
2878 if (!err) {
2879 if (write) {
2880 if (*ppos)
2881 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2882 else
2883 memcpy(bitmap, tmp_bitmap,
2884 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2885 }
2886 kfree(tmp_bitmap);
2887 *lenp -= left;
2888 *ppos += *lenp;
2889 return 0;
2890 } else {
2891 kfree(tmp_bitmap);
2892 return err;
2893 }
2894}
2895
Jovi Zhang55610502011-01-12 17:00:45 -08002896#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002898int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 void __user *buffer, size_t *lenp, loff_t *ppos)
2900{
2901 return -ENOSYS;
2902}
2903
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002904int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 void __user *buffer, size_t *lenp, loff_t *ppos)
2906{
2907 return -ENOSYS;
2908}
2909
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002910int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 void __user *buffer, size_t *lenp, loff_t *ppos)
2912{
2913 return -ENOSYS;
2914}
2915
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002916int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 void __user *buffer, size_t *lenp, loff_t *ppos)
2918{
2919 return -ENOSYS;
2920}
2921
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002922int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 void __user *buffer, size_t *lenp, loff_t *ppos)
2924{
2925 return -ENOSYS;
2926}
2927
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer, size_t *lenp, loff_t *ppos)
2930{
2931 return -ENOSYS;
2932}
2933
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002934int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 void __user *buffer, size_t *lenp, loff_t *ppos)
2936{
2937 return -ENOSYS;
2938}
2939
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002940int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 void __user *buffer,
2942 size_t *lenp, loff_t *ppos)
2943{
2944 return -ENOSYS;
2945}
2946
2947
Jovi Zhang55610502011-01-12 17:00:45 -08002948#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950/*
2951 * No sense putting this after each symbol definition, twice,
2952 * exception granted :-)
2953 */
2954EXPORT_SYMBOL(proc_dointvec);
2955EXPORT_SYMBOL(proc_dointvec_jiffies);
2956EXPORT_SYMBOL(proc_dointvec_minmax);
2957EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2958EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2959EXPORT_SYMBOL(proc_dostring);
2960EXPORT_SYMBOL(proc_doulongvec_minmax);
2961EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2962EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002963EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964EXPORT_SYMBOL(unregister_sysctl_table);