blob: c6811ee2092b165216a09bcd69153e2c0e1093c6 [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
173static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
174
175static int sysrq_sysctl_handler(ctl_table *table, int write,
176 void __user *buffer, size_t *lenp,
177 loff_t *ppos)
178{
179 int error;
180
181 error = proc_dointvec(table, write, buffer, lenp, ppos);
182 if (error)
183 return error;
184
185 if (write)
186 sysrq_toggle_support(__sysrq_enabled);
187
188 return 0;
189}
190
191#endif
192
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700193static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100194static struct ctl_table_root sysctl_table_root;
195static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100196 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100197 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400198 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100199 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400200 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201};
202static struct ctl_table_root sysctl_table_root = {
203 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400204 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100205};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700207static struct ctl_table kern_table[];
208static struct ctl_table vm_table[];
209static struct ctl_table fs_table[];
210static struct ctl_table debug_table[];
211static struct ctl_table dev_table[];
212extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800213#ifdef CONFIG_EPOLL
214extern struct ctl_table epoll_table[];
215#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
218int sysctl_legacy_va_layout;
219#endif
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/* The default sysctl tables: */
222
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700223static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .procname = "kernel",
226 .mode = 0555,
227 .child = kern_table,
228 },
229 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 .procname = "vm",
231 .mode = 0555,
232 .child = vm_table,
233 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .procname = "fs",
236 .mode = 0555,
237 .child = fs_table,
238 },
239 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .procname = "debug",
241 .mode = 0555,
242 .child = debug_table,
243 },
244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .procname = "dev",
246 .mode = 0555,
247 .child = dev_table,
248 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700249/*
250 * NOTE: do not add new entries to this table unless you have read
251 * Documentation/sysctl/ctl_unnumbered.txt
252 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700253 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254};
255
Ingo Molnar77e54a12007-07-09 18:52:00 +0200256#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100257static int min_sched_granularity_ns = 100000; /* 100 usecs */
258static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
259static int min_wakeup_granularity_ns; /* 0 usecs */
260static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100261static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
262static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263#endif
264
Mel Gorman5e771902010-05-24 14:32:31 -0700265#ifdef CONFIG_COMPACTION
266static int min_extfrag_threshold;
267static int max_extfrag_threshold = 1000;
268#endif
269
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700270static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200271 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200272 .procname = "sched_child_runs_first",
273 .data = &sysctl_sched_child_runs_first,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800276 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200277 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278#ifdef CONFIG_SCHED_DEBUG
279 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100280 .procname = "sched_min_granularity_ns",
281 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800284 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287 },
288 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200289 .procname = "sched_latency_ns",
290 .data = &sysctl_sched_latency,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800293 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
296 },
297 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200298 .procname = "sched_wakeup_granularity_ns",
299 .data = &sysctl_sched_wakeup_granularity,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800302 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200303 .extra1 = &min_wakeup_granularity_ns,
304 .extra2 = &max_wakeup_granularity_ns,
305 },
306 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100307 .procname = "sched_tunable_scaling",
308 .data = &sysctl_sched_tunable_scaling,
309 .maxlen = sizeof(enum sched_tunable_scaling),
310 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800311 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100312 .extra1 = &min_sched_tunable_scaling,
313 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200314 },
315 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800320 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200321 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100322 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100326 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800327 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100328 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530329 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200330 .procname = "sched_time_avg",
331 .data = &sysctl_sched_time_avg,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800334 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200335 },
336 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800337 .procname = "sched_shares_window",
338 .data = &sysctl_sched_shares_window,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
341 .proc_handler = proc_dointvec,
342 },
343 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530344 .procname = "timer_migration",
345 .data = &sysctl_timer_migration,
346 .maxlen = sizeof(unsigned int),
347 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800348 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530349 .extra1 = &zero,
350 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530351 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200352#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200353 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100354 .procname = "sched_rt_period_us",
355 .data = &sysctl_sched_rt_period,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800358 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100359 },
360 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100361 .procname = "sched_rt_runtime_us",
362 .data = &sysctl_sched_rt_runtime,
363 .maxlen = sizeof(int),
364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800365 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100366 },
367 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200368 .procname = "sched_compat_yield",
369 .data = &sysctl_sched_compat_yield,
370 .maxlen = sizeof(unsigned int),
371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800372 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200373 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100374#ifdef CONFIG_SCHED_AUTOGROUP
375 {
376 .procname = "sched_autogroup_enabled",
377 .data = &sysctl_sched_autogroup_enabled,
378 .maxlen = sizeof(unsigned int),
379 .mode = 0644,
380 .proc_handler = proc_dointvec,
381 .extra1 = &zero,
382 .extra2 = &one,
383 },
384#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700385#ifdef CONFIG_PROVE_LOCKING
386 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700387 .procname = "prove_locking",
388 .data = &prove_locking,
389 .maxlen = sizeof(int),
390 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800391 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700392 },
393#endif
394#ifdef CONFIG_LOCK_STAT
395 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700396 .procname = "lock_stat",
397 .data = &lock_stat,
398 .maxlen = sizeof(int),
399 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800400 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700401 },
402#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200403 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .procname = "panic",
405 .data = &panic_timeout,
406 .maxlen = sizeof(int),
407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800408 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 },
410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "core_uses_pid",
412 .data = &core_uses_pid,
413 .maxlen = sizeof(int),
414 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800415 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 },
417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .procname = "core_pattern",
419 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700420 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800422 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 },
Neil Hormana2939802009-09-23 15:56:56 -0700424 {
Neil Hormana2939802009-09-23 15:56:56 -0700425 .procname = "core_pipe_limit",
426 .data = &core_pipe_limit,
427 .maxlen = sizeof(unsigned int),
428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800429 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700430 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800431#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700434 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800438#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100439#ifdef CONFIG_LATENCYTOP
440 {
441 .procname = "latencytop",
442 .data = &latencytop_enabled,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800445 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100446 },
447#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#ifdef CONFIG_BLK_DEV_INITRD
449 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 .procname = "real-root-dev",
451 .data = &real_root_dev,
452 .maxlen = sizeof(int),
453 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800454 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 },
456#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700457 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700458 .procname = "print-fatal-signals",
459 .data = &print_fatal_signals,
460 .maxlen = sizeof(int),
461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800462 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700463 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700464#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .procname = "reboot-cmd",
467 .data = reboot_command,
468 .maxlen = 256,
469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800470 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 },
472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "stop-a",
474 .data = &stop_a_enabled,
475 .maxlen = sizeof (int),
476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800477 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .procname = "scons-poweroff",
481 .data = &scons_pwroff,
482 .maxlen = sizeof (int),
483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800484 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
486#endif
David S. Miller08714202008-11-16 23:49:24 -0800487#ifdef CONFIG_SPARC64
488 {
David S. Miller08714202008-11-16 23:49:24 -0800489 .procname = "tsb-ratio",
490 .data = &sysctl_tsb_ratio,
491 .maxlen = sizeof (int),
492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800494 },
495#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#ifdef __hppa__
497 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .procname = "soft-power",
499 .data = &pwrsw_enabled,
500 .maxlen = sizeof (int),
501 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800502 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
504 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .procname = "unaligned-trap",
506 .data = &unaligned_enabled,
507 .maxlen = sizeof (int),
508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800509 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 },
511#endif
512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .procname = "ctrl-alt-del",
514 .data = &C_A_D,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400519#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200520 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200521 .procname = "ftrace_enabled",
522 .data = &ftrace_enabled,
523 .maxlen = sizeof(int),
524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800525 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200526 },
527#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500528#ifdef CONFIG_STACK_TRACER
529 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500530 .procname = "stack_tracer_enabled",
531 .data = &stack_tracer_enabled,
532 .maxlen = sizeof(int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500535 },
536#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400537#ifdef CONFIG_TRACING
538 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100539 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400540 .data = &ftrace_dump_on_oops,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800543 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400544 },
545#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200546#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .procname = "modprobe",
549 .data = &modprobe_path,
550 .maxlen = KMOD_PATH_LEN,
551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800552 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 },
Kees Cook3d433212009-04-02 15:49:29 -0700554 {
Kees Cook3d433212009-04-02 15:49:29 -0700555 .procname = "modules_disabled",
556 .data = &modules_disabled,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800560 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700561 .extra1 = &one,
562 .extra2 = &one,
563 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100565#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100568 .data = &uevent_helper,
569 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800571 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 },
573#endif
574#ifdef CONFIG_CHR_DEV_SG
575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 .procname = "sg-big-buff",
577 .data = &sg_big_buff,
578 .maxlen = sizeof (int),
579 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800580 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 },
582#endif
583#ifdef CONFIG_BSD_PROCESS_ACCT
584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .procname = "acct",
586 .data = &acct_parm,
587 .maxlen = 3*sizeof(int),
588 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800589 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 },
591#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#ifdef CONFIG_MAGIC_SYSRQ
593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800595 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 .maxlen = sizeof (int),
597 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700598 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
600#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700601#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700604 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 .maxlen = sizeof (int),
606 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800607 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "threads-max",
612 .data = &max_threads,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800615 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 },
617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .procname = "random",
619 .mode = 0555,
620 .child = random_table,
621 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 .procname = "overflowuid",
624 .data = &overflowuid,
625 .maxlen = sizeof(int),
626 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800627 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .extra1 = &minolduid,
629 .extra2 = &maxolduid,
630 },
631 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .procname = "overflowgid",
633 .data = &overflowgid,
634 .maxlen = sizeof(int),
635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800636 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 .extra1 = &minolduid,
638 .extra2 = &maxolduid,
639 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800640#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#ifdef CONFIG_MATHEMU
642 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 .procname = "ieee_emulation_warnings",
644 .data = &sysctl_ieee_emulation_warnings,
645 .maxlen = sizeof(int),
646 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800647 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 },
649#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200652 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .maxlen = sizeof(int),
654 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800655 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 },
657#endif
658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .procname = "pid_max",
660 .data = &pid_max,
661 .maxlen = sizeof (int),
662 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800663 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .extra1 = &pid_max_min,
665 .extra2 = &pid_max_max,
666 },
667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "panic_on_oops",
669 .data = &panic_on_oops,
670 .maxlen = sizeof(int),
671 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800674#if defined CONFIG_PRINTK
675 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800676 .procname = "printk",
677 .data = &console_loglevel,
678 .maxlen = 4*sizeof(int),
679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800681 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700684 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .maxlen = sizeof(int),
686 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800687 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 },
689 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700691 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 .maxlen = sizeof(int),
693 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800694 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 },
Dave Youngaf913222009-09-22 16:43:33 -0700696 {
Dave Youngaf913222009-09-22 16:43:33 -0700697 .procname = "printk_delay",
698 .data = &printk_delay_msec,
699 .maxlen = sizeof(int),
700 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800701 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700702 .extra1 = &zero,
703 .extra2 = &ten_thousand,
704 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800706 .procname = "dmesg_restrict",
707 .data = &dmesg_restrict,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = proc_dointvec_minmax,
711 .extra1 = &zero,
712 .extra2 = &one,
713 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800714 {
715 .procname = "kptr_restrict",
716 .data = &kptr_restrict,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = proc_dointvec_minmax,
720 .extra1 = &zero,
721 .extra2 = &two,
722 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800723#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .procname = "ngroups_max",
726 .data = &ngroups_max,
727 .maxlen = sizeof (int),
728 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800729 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 },
Don Zickus58687ac2010-05-07 17:11:44 -0400731#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500732 {
Don Zickus58687ac2010-05-07 17:11:44 -0400733 .procname = "watchdog",
734 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500735 .maxlen = sizeof (int),
736 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400737 .proc_handler = proc_dowatchdog_enabled,
738 },
739 {
740 .procname = "watchdog_thresh",
741 .data = &softlockup_thresh,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dowatchdog_thresh,
745 .extra1 = &neg_one,
746 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500747 },
Don Zickus2508ce12010-05-07 17:11:46 -0400748 {
749 .procname = "softlockup_panic",
750 .data = &softlockup_panic,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec_minmax,
754 .extra1 = &zero,
755 .extra2 = &one,
756 },
Don Zickus5dc30552010-11-29 17:07:17 -0500757 {
758 .procname = "nmi_watchdog",
759 .data = &watchdog_enabled,
760 .maxlen = sizeof (int),
761 .mode = 0644,
762 .proc_handler = proc_dowatchdog_enabled,
763 },
764#endif
765#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
766 {
767 .procname = "unknown_nmi_panic",
768 .data = &unknown_nmi_panic,
769 .maxlen = sizeof (int),
770 .mode = 0644,
771 .proc_handler = proc_dointvec,
772 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500773#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774#if defined(CONFIG_X86)
775 {
Don Zickus8da5add2006-09-26 10:52:27 +0200776 .procname = "panic_on_unrecovered_nmi",
777 .data = &panic_on_unrecovered_nmi,
778 .maxlen = sizeof(int),
779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200781 },
782 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700783 .procname = "panic_on_io_nmi",
784 .data = &panic_on_io_nmi,
785 .maxlen = sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700788 },
789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .procname = "bootloader_type",
791 .data = &bootloader_type,
792 .maxlen = sizeof (int),
793 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100796 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700797 .procname = "bootloader_version",
798 .data = &bootloader_version,
799 .maxlen = sizeof (int),
800 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700802 },
803 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100804 .procname = "kstack_depth_to_print",
805 .data = &kstack_depth_to_print,
806 .maxlen = sizeof(int),
807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100809 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100810 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100811 .procname = "io_delay_type",
812 .data = &io_delay_type,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100816 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800818#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 .procname = "randomize_va_space",
821 .data = &randomize_va_space,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800824 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800826#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800827#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700828 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700829 .procname = "spin_retry",
830 .data = &spin_retry,
831 .maxlen = sizeof (int),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700834 },
835#endif
Len Brown673d5b42007-07-28 03:33:16 -0400836#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800837 {
Pavel Machekc255d842006-02-20 18:27:58 -0800838 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700839 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800840 .maxlen = sizeof (unsigned long),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800843 },
844#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800845#ifdef CONFIG_IA64
846 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800847 .procname = "ignore-unaligned-usertrap",
848 .data = &no_unaligned_warning,
849 .maxlen = sizeof (int),
850 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800851 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800852 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800853 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800859 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800860#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800861#ifdef CONFIG_DETECT_HUNG_TASK
862 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800863 .procname = "hung_task_panic",
864 .data = &sysctl_hung_task_panic,
865 .maxlen = sizeof(int),
866 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800867 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800868 .extra1 = &zero,
869 .extra2 = &one,
870 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100871 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100872 .procname = "hung_task_check_count",
873 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100874 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800876 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100877 },
878 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .procname = "hung_task_timeout_secs",
880 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100881 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800883 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100884 },
885 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100886 .procname = "hung_task_warnings",
887 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100888 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100889 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800890 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100891 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700892#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200893#ifdef CONFIG_COMPAT
894 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200895 .procname = "compat-log",
896 .data = &compat_log,
897 .maxlen = sizeof (int),
898 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800899 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200900 },
901#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700902#ifdef CONFIG_RT_MUTEXES
903 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700904 .procname = "max_lock_depth",
905 .data = &max_lock_depth,
906 .maxlen = sizeof(int),
907 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800908 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700909 },
910#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700911 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700912 .procname = "poweroff_cmd",
913 .data = &poweroff_cmd,
914 .maxlen = POWEROFF_CMD_PATH_LEN,
915 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700917 },
David Howells0b77f5b2008-04-29 01:01:32 -0700918#ifdef CONFIG_KEYS
919 {
David Howells0b77f5b2008-04-29 01:01:32 -0700920 .procname = "keys",
921 .mode = 0555,
922 .child = key_sysctls,
923 },
924#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700925#ifdef CONFIG_RCU_TORTURE_TEST
926 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700927 .procname = "rcutorture_runnable",
928 .data = &rcutorture_runnable,
929 .maxlen = sizeof(int),
930 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800931 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700932 },
933#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200934#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200935 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200936 .procname = "perf_event_paranoid",
937 .data = &sysctl_perf_event_paranoid,
938 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200939 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800940 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200941 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200942 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200943 .procname = "perf_event_mlock_kb",
944 .data = &sysctl_perf_event_mlock,
945 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200946 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800947 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200948 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200949 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200950 .procname = "perf_event_max_sample_rate",
951 .data = &sysctl_perf_event_sample_rate,
952 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200953 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800954 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200955 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200956#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200957#ifdef CONFIG_KMEMCHECK
958 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200959 .procname = "kmemcheck",
960 .data = &kmemcheck_enabled,
961 .maxlen = sizeof(int),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200964 },
965#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200966#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200967 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200968 .procname = "blk_iopoll",
969 .data = &blk_iopoll_enabled,
970 .maxlen = sizeof(int),
971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200973 },
Jens Axboecb684b52009-09-15 21:53:11 +0200974#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700975/*
976 * NOTE: do not add new entries to this table unless you have read
977 * Documentation/sysctl/ctl_unnumbered.txt
978 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700979 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980};
981
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700982static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 .procname = "overcommit_memory",
985 .data = &sysctl_overcommit_memory,
986 .maxlen = sizeof(sysctl_overcommit_memory),
987 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800988 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 },
990 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700991 .procname = "panic_on_oom",
992 .data = &sysctl_panic_on_oom,
993 .maxlen = sizeof(sysctl_panic_on_oom),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700996 },
997 {
David Rientjesfe071d72007-10-16 23:25:56 -0700998 .procname = "oom_kill_allocating_task",
999 .data = &sysctl_oom_kill_allocating_task,
1000 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001003 },
1004 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001005 .procname = "oom_dump_tasks",
1006 .data = &sysctl_oom_dump_tasks,
1007 .maxlen = sizeof(sysctl_oom_dump_tasks),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "overcommit_ratio",
1013 .data = &sysctl_overcommit_ratio,
1014 .maxlen = sizeof(sysctl_overcommit_ratio),
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 = "page-cluster",
1020 .data = &page_cluster,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 },
1025 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 .procname = "dirty_background_ratio",
1027 .data = &dirty_background_ratio,
1028 .maxlen = sizeof(dirty_background_ratio),
1029 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001030 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 .extra1 = &zero,
1032 .extra2 = &one_hundred,
1033 },
1034 {
David Rientjes2da02992009-01-06 14:39:31 -08001035 .procname = "dirty_background_bytes",
1036 .data = &dirty_background_bytes,
1037 .maxlen = sizeof(dirty_background_bytes),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001040 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001041 },
1042 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 .procname = "dirty_ratio",
1044 .data = &vm_dirty_ratio,
1045 .maxlen = sizeof(vm_dirty_ratio),
1046 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001047 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .extra1 = &zero,
1049 .extra2 = &one_hundred,
1050 },
1051 {
David Rientjes2da02992009-01-06 14:39:31 -08001052 .procname = "dirty_bytes",
1053 .data = &vm_dirty_bytes,
1054 .maxlen = sizeof(vm_dirty_bytes),
1055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001057 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001058 },
1059 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001061 .data = &dirty_writeback_interval,
1062 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001068 .data = &dirty_expire_interval,
1069 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 .mode = 0644,
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 = "nr_pdflush_threads",
1075 .data = &nr_pdflush_threads,
1076 .maxlen = sizeof nr_pdflush_threads,
1077 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 },
1080 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .procname = "swappiness",
1082 .data = &vm_swappiness,
1083 .maxlen = sizeof(vm_swappiness),
1084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .extra1 = &zero,
1087 .extra2 = &one_hundred,
1088 },
1089#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001090 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001092 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .maxlen = sizeof(unsigned long),
1094 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001095 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .extra1 = (void *)&hugetlb_zero,
1097 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001098 },
1099#ifdef CONFIG_NUMA
1100 {
1101 .procname = "nr_hugepages_mempolicy",
1102 .data = NULL,
1103 .maxlen = sizeof(unsigned long),
1104 .mode = 0644,
1105 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1106 .extra1 = (void *)&hugetlb_zero,
1107 .extra2 = (void *)&hugetlb_infinity,
1108 },
1109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .procname = "hugetlb_shm_group",
1112 .data = &sysctl_hugetlb_shm_group,
1113 .maxlen = sizeof(gid_t),
1114 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001115 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 },
Mel Gorman396faf02007-07-17 04:03:13 -07001117 {
Mel Gorman396faf02007-07-17 04:03:13 -07001118 .procname = "hugepages_treat_as_movable",
1119 .data = &hugepages_treat_as_movable,
1120 .maxlen = sizeof(int),
1121 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001122 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001123 },
Adam Litke54f9f802007-10-16 01:26:20 -07001124 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001125 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001126 .data = NULL,
1127 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001128 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001129 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001130 .extra1 = (void *)&hugetlb_zero,
1131 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001132 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133#endif
1134 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 .procname = "lowmem_reserve_ratio",
1136 .data = &sysctl_lowmem_reserve_ratio,
1137 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 },
1141 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001142 .procname = "drop_caches",
1143 .data = &sysctl_drop_caches,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001147 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001148#ifdef CONFIG_COMPACTION
1149 {
1150 .procname = "compact_memory",
1151 .data = &sysctl_compact_memory,
1152 .maxlen = sizeof(int),
1153 .mode = 0200,
1154 .proc_handler = sysctl_compaction_handler,
1155 },
Mel Gorman5e771902010-05-24 14:32:31 -07001156 {
1157 .procname = "extfrag_threshold",
1158 .data = &sysctl_extfrag_threshold,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = sysctl_extfrag_handler,
1162 .extra1 = &min_extfrag_threshold,
1163 .extra2 = &max_extfrag_threshold,
1164 },
1165
Mel Gorman76ab0f52010-05-24 14:32:28 -07001166#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001167 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .procname = "min_free_kbytes",
1169 .data = &min_free_kbytes,
1170 .maxlen = sizeof(min_free_kbytes),
1171 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001172 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .extra1 = &zero,
1174 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001175 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001176 .procname = "percpu_pagelist_fraction",
1177 .data = &percpu_pagelist_fraction,
1178 .maxlen = sizeof(percpu_pagelist_fraction),
1179 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001180 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001181 .extra1 = &min_percpu_pagelist_fract,
1182 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183#ifdef CONFIG_MMU
1184 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .procname = "max_map_count",
1186 .data = &sysctl_max_map_count,
1187 .maxlen = sizeof(sysctl_max_map_count),
1188 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001189 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001190 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001192#else
1193 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001194 .procname = "nr_trim_pages",
1195 .data = &sysctl_nr_trim_pages,
1196 .maxlen = sizeof(sysctl_nr_trim_pages),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001199 .extra1 = &zero,
1200 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201#endif
1202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .procname = "laptop_mode",
1204 .data = &laptop_mode,
1205 .maxlen = sizeof(laptop_mode),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 },
1209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 .procname = "block_dump",
1211 .data = &block_dump,
1212 .maxlen = sizeof(block_dump),
1213 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001214 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 .extra1 = &zero,
1216 },
1217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .procname = "vfs_cache_pressure",
1219 .data = &sysctl_vfs_cache_pressure,
1220 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001222 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .extra1 = &zero,
1224 },
1225#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .procname = "legacy_va_layout",
1228 .data = &sysctl_legacy_va_layout,
1229 .maxlen = sizeof(sysctl_legacy_va_layout),
1230 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001231 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 .extra1 = &zero,
1233 },
1234#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001235#ifdef CONFIG_NUMA
1236 {
Christoph Lameter17436602006-01-18 17:42:32 -08001237 .procname = "zone_reclaim_mode",
1238 .data = &zone_reclaim_mode,
1239 .maxlen = sizeof(zone_reclaim_mode),
1240 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001241 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001242 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001243 },
Christoph Lameter96146342006-07-03 00:24:13 -07001244 {
Christoph Lameter96146342006-07-03 00:24:13 -07001245 .procname = "min_unmapped_ratio",
1246 .data = &sysctl_min_unmapped_ratio,
1247 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1248 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001249 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001250 .extra1 = &zero,
1251 .extra2 = &one_hundred,
1252 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001253 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001254 .procname = "min_slab_ratio",
1255 .data = &sysctl_min_slab_ratio,
1256 .maxlen = sizeof(sysctl_min_slab_ratio),
1257 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001258 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001259 .extra1 = &zero,
1260 .extra2 = &one_hundred,
1261 },
Christoph Lameter17436602006-01-18 17:42:32 -08001262#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001263#ifdef CONFIG_SMP
1264 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001265 .procname = "stat_interval",
1266 .data = &sysctl_stat_interval,
1267 .maxlen = sizeof(sysctl_stat_interval),
1268 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001269 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001270 },
1271#endif
David Howells6e141542009-12-15 19:27:45 +00001272#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001273 {
Eric Parised032182007-06-28 15:55:21 -04001274 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001275 .data = &dac_mmap_min_addr,
1276 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001277 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001278 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001279 },
David Howells6e141542009-12-15 19:27:45 +00001280#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001281#ifdef CONFIG_NUMA
1282 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001283 .procname = "numa_zonelist_order",
1284 .data = &numa_zonelist_order,
1285 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1286 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001287 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001288 },
1289#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001290#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001291 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001292 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001293 .procname = "vdso_enabled",
1294 .data = &vdso_enabled,
1295 .maxlen = sizeof(vdso_enabled),
1296 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001297 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001298 .extra1 = &zero,
1299 },
1300#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001301#ifdef CONFIG_HIGHMEM
1302 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001303 .procname = "highmem_is_dirtyable",
1304 .data = &vm_highmem_is_dirtyable,
1305 .maxlen = sizeof(vm_highmem_is_dirtyable),
1306 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001307 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001308 .extra1 = &zero,
1309 .extra2 = &one,
1310 },
1311#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001312 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001313 .procname = "scan_unevictable_pages",
1314 .data = &scan_unevictable_pages,
1315 .maxlen = sizeof(scan_unevictable_pages),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001318 },
Andi Kleen6a460792009-09-16 11:50:15 +02001319#ifdef CONFIG_MEMORY_FAILURE
1320 {
Andi Kleen6a460792009-09-16 11:50:15 +02001321 .procname = "memory_failure_early_kill",
1322 .data = &sysctl_memory_failure_early_kill,
1323 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001325 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001326 .extra1 = &zero,
1327 .extra2 = &one,
1328 },
1329 {
Andi Kleen6a460792009-09-16 11:50:15 +02001330 .procname = "memory_failure_recovery",
1331 .data = &sysctl_memory_failure_recovery,
1332 .maxlen = sizeof(sysctl_memory_failure_recovery),
1333 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001334 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001335 .extra1 = &zero,
1336 .extra2 = &one,
1337 },
1338#endif
1339
Andrew Morton2be7fe02007-07-15 23:41:21 -07001340/*
1341 * NOTE: do not add new entries to this table unless you have read
1342 * Documentation/sysctl/ctl_unnumbered.txt
1343 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001344 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345};
1346
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001347#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001348static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001349 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001350};
1351#endif
1352
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001353static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "inode-nr",
1356 .data = &inodes_stat,
1357 .maxlen = 2*sizeof(int),
1358 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001359 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 },
1361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .procname = "inode-state",
1363 .data = &inodes_stat,
1364 .maxlen = 7*sizeof(int),
1365 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001366 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 },
1368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .procname = "file-nr",
1370 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001371 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001373 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 },
1375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .procname = "file-max",
1377 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001378 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001380 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 },
1382 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001383 .procname = "nr_open",
1384 .data = &sysctl_nr_open,
1385 .maxlen = sizeof(int),
1386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001388 .extra1 = &sysctl_nr_open_min,
1389 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001390 },
1391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .procname = "dentry-state",
1393 .data = &dentry_stat,
1394 .maxlen = 6*sizeof(int),
1395 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001396 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 },
1398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "overflowuid",
1400 .data = &fs_overflowuid,
1401 .maxlen = sizeof(int),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 .extra1 = &minolduid,
1405 .extra2 = &maxolduid,
1406 },
1407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .procname = "overflowgid",
1409 .data = &fs_overflowgid,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 .extra1 = &minolduid,
1414 .extra2 = &maxolduid,
1415 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001416#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "leases-enable",
1419 .data = &leases_enable,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001424#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425#ifdef CONFIG_DNOTIFY
1426 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 .procname = "dir-notify-enable",
1428 .data = &dir_notify_enable,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 },
1433#endif
1434#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001435#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 .procname = "lease-break-time",
1438 .data = &lease_break_time,
1439 .maxlen = sizeof(int),
1440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001443#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001444#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .procname = "aio-nr",
1447 .data = &aio_nr,
1448 .maxlen = sizeof(aio_nr),
1449 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001450 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 },
1452 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 .procname = "aio-max-nr",
1454 .data = &aio_max_nr,
1455 .maxlen = sizeof(aio_max_nr),
1456 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001457 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001459#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001460#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001461 {
Robert Love0399cb02005-07-13 12:38:18 -04001462 .procname = "inotify",
1463 .mode = 0555,
1464 .child = inotify_table,
1465 },
1466#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001467#ifdef CONFIG_EPOLL
1468 {
1469 .procname = "epoll",
1470 .mode = 0555,
1471 .child = epoll_table,
1472 },
1473#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001475 {
Alan Coxd6e71142005-06-23 00:09:43 -07001476 .procname = "suid_dumpable",
1477 .data = &suid_dumpable,
1478 .maxlen = sizeof(int),
1479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001480 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001481 .extra1 = &zero,
1482 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001483 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001484#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1485 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001486 .procname = "binfmt_misc",
1487 .mode = 0555,
1488 .child = binfmt_misc_table,
1489 },
1490#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001491 {
Jens Axboeff9da692010-06-03 14:54:39 +02001492 .procname = "pipe-max-size",
1493 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001494 .maxlen = sizeof(int),
1495 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001496 .proc_handler = &pipe_proc_fn,
1497 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001498 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001499/*
1500 * NOTE: do not add new entries to this table unless you have read
1501 * Documentation/sysctl/ctl_unnumbered.txt
1502 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001503 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504};
1505
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001506static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001507#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1508 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001509 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001510 .procname = "exception-trace",
1511 .data = &show_unhandled_signals,
1512 .maxlen = sizeof(int),
1513 .mode = 0644,
1514 .proc_handler = proc_dointvec
1515 },
1516#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001517#if defined(CONFIG_OPTPROBES)
1518 {
1519 .procname = "kprobes-optimization",
1520 .data = &sysctl_kprobes_optimization,
1521 .maxlen = sizeof(int),
1522 .mode = 0644,
1523 .proc_handler = proc_kprobes_optimization_handler,
1524 .extra1 = &zero,
1525 .extra2 = &one,
1526 },
1527#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001528 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529};
1530
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001531static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001532 { }
Robert Love0eeca282005-07-12 17:06:03 -04001533};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Al Viro330d57f2005-11-04 10:18:40 +00001535static DEFINE_SPINLOCK(sysctl_lock);
1536
1537/* called under sysctl_lock */
1538static int use_table(struct ctl_table_header *p)
1539{
1540 if (unlikely(p->unregistering))
1541 return 0;
1542 p->used++;
1543 return 1;
1544}
1545
1546/* called under sysctl_lock */
1547static void unuse_table(struct ctl_table_header *p)
1548{
1549 if (!--p->used)
1550 if (unlikely(p->unregistering))
1551 complete(p->unregistering);
1552}
1553
1554/* called under sysctl_lock, will reacquire if has to wait */
1555static void start_unregistering(struct ctl_table_header *p)
1556{
1557 /*
1558 * if p->used is 0, nobody will ever touch that entry again;
1559 * we'll eliminate all paths to it before dropping sysctl_lock
1560 */
1561 if (unlikely(p->used)) {
1562 struct completion wait;
1563 init_completion(&wait);
1564 p->unregistering = &wait;
1565 spin_unlock(&sysctl_lock);
1566 wait_for_completion(&wait);
1567 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001568 } else {
1569 /* anything non-NULL; we'll never dereference it */
1570 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001571 }
1572 /*
1573 * do not remove from the list until nobody holds it; walking the
1574 * list in do_sysctl() relies on that.
1575 */
1576 list_del_init(&p->ctl_entry);
1577}
1578
Al Virof7e6ced2008-07-15 01:44:23 -04001579void sysctl_head_get(struct ctl_table_header *head)
1580{
1581 spin_lock(&sysctl_lock);
1582 head->count++;
1583 spin_unlock(&sysctl_lock);
1584}
1585
1586void sysctl_head_put(struct ctl_table_header *head)
1587{
1588 spin_lock(&sysctl_lock);
1589 if (!--head->count)
1590 kfree(head);
1591 spin_unlock(&sysctl_lock);
1592}
1593
1594struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1595{
1596 if (!head)
1597 BUG();
1598 spin_lock(&sysctl_lock);
1599 if (!use_table(head))
1600 head = ERR_PTR(-ENOENT);
1601 spin_unlock(&sysctl_lock);
1602 return head;
1603}
1604
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001605void sysctl_head_finish(struct ctl_table_header *head)
1606{
1607 if (!head)
1608 return;
1609 spin_lock(&sysctl_lock);
1610 unuse_table(head);
1611 spin_unlock(&sysctl_lock);
1612}
1613
Al Viro73455092008-07-14 21:22:20 -04001614static struct ctl_table_set *
1615lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1616{
1617 struct ctl_table_set *set = &root->default_set;
1618 if (root->lookup)
1619 set = root->lookup(root, namespaces);
1620 return set;
1621}
1622
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623static struct list_head *
1624lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625{
Al Viro73455092008-07-14 21:22:20 -04001626 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1627 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001628}
1629
1630struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1631 struct ctl_table_header *prev)
1632{
1633 struct ctl_table_root *root;
1634 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001635 struct ctl_table_header *head;
1636 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001637
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001638 spin_lock(&sysctl_lock);
1639 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001640 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001641 tmp = &prev->ctl_entry;
1642 unuse_table(prev);
1643 goto next;
1644 }
1645 tmp = &root_table_header.ctl_entry;
1646 for (;;) {
1647 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1648
1649 if (!use_table(head))
1650 goto next;
1651 spin_unlock(&sysctl_lock);
1652 return head;
1653 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001654 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001655 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001656 header_list = lookup_header_list(root, namespaces);
1657 if (tmp != header_list)
1658 continue;
1659
1660 do {
1661 root = list_entry(root->root_list.next,
1662 struct ctl_table_root, root_list);
1663 if (root == &sysctl_table_root)
1664 goto out;
1665 header_list = lookup_header_list(root, namespaces);
1666 } while (list_empty(header_list));
1667 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001668 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001669out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001670 spin_unlock(&sysctl_lock);
1671 return NULL;
1672}
1673
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001674struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1675{
1676 return __sysctl_head_next(current->nsproxy, prev);
1677}
1678
1679void register_sysctl_root(struct ctl_table_root *root)
1680{
1681 spin_lock(&sysctl_lock);
1682 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1683 spin_unlock(&sysctl_lock);
1684}
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001687 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 * some sysctl variables are readonly even to root.
1689 */
1690
1691static int test_perm(int mode, int op)
1692{
David Howells76aac0e2008-11-14 10:39:12 +11001693 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 mode >>= 6;
1695 else if (in_egroup_p(0))
1696 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001697 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 return 0;
1699 return -EACCES;
1700}
1701
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001702int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
1704 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001705 int mode;
1706
Al Viroe6305c42008-07-15 21:03:57 -04001707 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 if (error)
1709 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001710
1711 if (root->permissions)
1712 mode = root->permissions(root, current->nsproxy, table);
1713 else
1714 mode = table->mode;
1715
1716 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001719static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1720{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001721 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001722 table->parent = parent;
1723 if (table->child)
1724 sysctl_set_parent(table, table->child);
1725 }
1726}
1727
1728static __init int sysctl_init(void)
1729{
1730 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001731#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001732 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001733#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001734 return 0;
1735}
1736
1737core_initcall(sysctl_init);
1738
Al Virobfbcf032008-07-27 06:31:22 +01001739static struct ctl_table *is_branch_in(struct ctl_table *branch,
1740 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001741{
1742 struct ctl_table *p;
1743 const char *s = branch->procname;
1744
1745 /* branch should have named subdirectory as its first element */
1746 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001747 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001748
1749 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001750 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001751 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001752
1753 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001754 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001755 if (!p->child)
1756 continue;
1757 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001758 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001759 }
Al Virobfbcf032008-07-27 06:31:22 +01001760 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001761}
1762
1763/* see if attaching q to p would be an improvement */
1764static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1765{
1766 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001767 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001768 int is_better = 0;
1769 int not_in_parent = !p->attached_by;
1770
Al Virobfbcf032008-07-27 06:31:22 +01001771 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001772 if (by == q->attached_by)
1773 is_better = 1;
1774 if (to == p->attached_by)
1775 not_in_parent = 1;
1776 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001777 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001778 }
1779
1780 if (is_better && not_in_parent) {
1781 q->attached_by = by;
1782 q->attached_to = to;
1783 q->parent = p;
1784 }
1785}
1786
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001788 * __register_sysctl_paths - register a sysctl hierarchy
1789 * @root: List of sysctl headers to register on
1790 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001791 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 *
1794 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001795 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001797 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1800 * enter a sysctl file
1801 *
1802 * data - a pointer to data for use by proc_handler
1803 *
1804 * maxlen - the maximum size in bytes of the data
1805 *
1806 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1807 *
1808 * child - a pointer to the child sysctl table if this entry is a directory, or
1809 * %NULL.
1810 *
1811 * proc_handler - the text handler routine (described below)
1812 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 * de - for internal use by the sysctl routines
1814 *
1815 * extra1, extra2 - extra pointers usable by the proc handler routines
1816 *
1817 * Leaf nodes in the sysctl tree will be represented by a single file
1818 * under /proc; non-leaf nodes will be represented by directories.
1819 *
1820 * sysctl(2) can automatically manage read and write requests through
1821 * the sysctl table. The data and maxlen fields of the ctl_table
1822 * struct enable minimal validation of the values being written to be
1823 * performed, and the mode field allows minimal authentication.
1824 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 * There must be a proc_handler routine for any terminal nodes
1826 * mirrored under /proc/sys (non-terminals are handled by a built-in
1827 * directory handler). Several default handlers are available to
1828 * cover common cases -
1829 *
1830 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1831 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1832 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1833 *
1834 * It is the handler's job to read the input buffer from user memory
1835 * and process it. The handler should return 0 on success.
1836 *
1837 * This routine returns %NULL on a failure to register, and a pointer
1838 * to the table header on success.
1839 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001840struct ctl_table_header *__register_sysctl_paths(
1841 struct ctl_table_root *root,
1842 struct nsproxy *namespaces,
1843 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001845 struct ctl_table_header *header;
1846 struct ctl_table *new, **prevp;
1847 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001848 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849
1850 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001851 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001852 ;
1853
1854 /*
1855 * For each path component, allocate a 2-element ctl_table array.
1856 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001857 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001858 *
1859 * We allocate everything in one go so that we don't have to
1860 * worry about freeing additional memory in unregister_sysctl_table.
1861 */
1862 header = kzalloc(sizeof(struct ctl_table_header) +
1863 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1864 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001866
1867 new = (struct ctl_table *) (header + 1);
1868
1869 /* Now connect the dots */
1870 prevp = &header->ctl_table;
1871 for (n = 0; n < npath; ++n, ++path) {
1872 /* Copy the procname */
1873 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001874 new->mode = 0555;
1875
1876 *prevp = new;
1877 prevp = &new->child;
1878
1879 new += 2;
1880 }
1881 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001882 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001883
1884 INIT_LIST_HEAD(&header->ctl_entry);
1885 header->used = 0;
1886 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001887 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001888 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001889 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001890#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001891 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001892 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001893 return NULL;
1894 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001895#endif
Al Viro330d57f2005-11-04 10:18:40 +00001896 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001897 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001898 header->attached_by = header->ctl_table;
1899 header->attached_to = root_table;
1900 header->parent = &root_table_header;
1901 for (set = header->set; set; set = set->parent) {
1902 struct ctl_table_header *p;
1903 list_for_each_entry(p, &set->list, ctl_entry) {
1904 if (p->unregistering)
1905 continue;
1906 try_attach(p, header);
1907 }
1908 }
1909 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001910 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001911 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001912
1913 return header;
1914}
1915
1916/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001917 * register_sysctl_table_path - register a sysctl table hierarchy
1918 * @path: The path to the directory the sysctl table is in.
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_paths(const struct ctl_path *path,
1927 struct ctl_table *table)
1928{
1929 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1930 path, table);
1931}
1932
1933/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001934 * register_sysctl_table - register a sysctl table hierarchy
1935 * @table: the top-level table structure
1936 *
1937 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1938 * array. A completely 0 filled entry terminates the table.
1939 *
1940 * See register_sysctl_paths for more details.
1941 */
1942struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1943{
1944 static const struct ctl_path null_path[] = { {} };
1945
1946 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947}
1948
1949/**
1950 * unregister_sysctl_table - unregister a sysctl table hierarchy
1951 * @header: the header returned from register_sysctl_table
1952 *
1953 * Unregisters the sysctl table and all children. proc entries may not
1954 * actually be removed until they are no longer used by anyone.
1955 */
1956void unregister_sysctl_table(struct ctl_table_header * header)
1957{
Al Viro330d57f2005-11-04 10:18:40 +00001958 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001959
1960 if (header == NULL)
1961 return;
1962
Al Viro330d57f2005-11-04 10:18:40 +00001963 spin_lock(&sysctl_lock);
1964 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001965 if (!--header->parent->count) {
1966 WARN_ON(1);
1967 kfree(header->parent);
1968 }
Al Virof7e6ced2008-07-15 01:44:23 -04001969 if (!--header->count)
1970 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001971 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
Al Viro9043476f2008-07-15 08:54:06 -04001974int sysctl_is_seen(struct ctl_table_header *p)
1975{
1976 struct ctl_table_set *set = p->set;
1977 int res;
1978 spin_lock(&sysctl_lock);
1979 if (p->unregistering)
1980 res = 0;
1981 else if (!set->is_seen)
1982 res = 1;
1983 else
1984 res = set->is_seen(set);
1985 spin_unlock(&sysctl_lock);
1986 return res;
1987}
1988
Al Viro73455092008-07-14 21:22:20 -04001989void setup_sysctl_set(struct ctl_table_set *p,
1990 struct ctl_table_set *parent,
1991 int (*is_seen)(struct ctl_table_set *))
1992{
1993 INIT_LIST_HEAD(&p->list);
1994 p->parent = parent ? parent : &sysctl_table_root.default_set;
1995 p->is_seen = is_seen;
1996}
1997
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001998#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001999struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002000{
2001 return NULL;
2002}
2003
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002004struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2005 struct ctl_table *table)
2006{
2007 return NULL;
2008}
2009
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002010void unregister_sysctl_table(struct ctl_table_header * table)
2011{
2012}
2013
Al Viro73455092008-07-14 21:22:20 -04002014void setup_sysctl_set(struct ctl_table_set *p,
2015 struct ctl_table_set *parent,
2016 int (*is_seen)(struct ctl_table_set *))
2017{
2018}
2019
Al Virof7e6ced2008-07-15 01:44:23 -04002020void sysctl_head_put(struct ctl_table_header *head)
2021{
2022}
2023
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002024#endif /* CONFIG_SYSCTL */
2025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026/*
2027 * /proc/sys support
2028 */
2029
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002030#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002032static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002033 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002034 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002035{
2036 size_t len;
2037 char __user *p;
2038 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002039
2040 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002041 *lenp = 0;
2042 return 0;
2043 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002044
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002045 if (write) {
2046 len = 0;
2047 p = buffer;
2048 while (len < *lenp) {
2049 if (get_user(c, p++))
2050 return -EFAULT;
2051 if (c == 0 || c == '\n')
2052 break;
2053 len++;
2054 }
2055 if (len >= maxlen)
2056 len = maxlen-1;
2057 if(copy_from_user(data, buffer, len))
2058 return -EFAULT;
2059 ((char *) data)[len] = 0;
2060 *ppos += *lenp;
2061 } else {
2062 len = strlen(data);
2063 if (len > maxlen)
2064 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002065
2066 if (*ppos > len) {
2067 *lenp = 0;
2068 return 0;
2069 }
2070
2071 data += *ppos;
2072 len -= *ppos;
2073
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002074 if (len > *lenp)
2075 len = *lenp;
2076 if (len)
2077 if(copy_to_user(buffer, data, len))
2078 return -EFAULT;
2079 if (len < *lenp) {
2080 if(put_user('\n', ((char __user *) buffer) + len))
2081 return -EFAULT;
2082 len++;
2083 }
2084 *lenp = len;
2085 *ppos += len;
2086 }
2087 return 0;
2088}
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/**
2091 * proc_dostring - read a string sysctl
2092 * @table: the sysctl table
2093 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2097 *
2098 * Reads/writes a string from/to the user buffer. If the kernel
2099 * buffer provided is not large enough to hold the string, the
2100 * string is truncated. The copied string is %NULL-terminated.
2101 * If the string is being read by the user process, it is copied
2102 * and a newline '\n' is added. It is truncated if the buffer is
2103 * not large enough.
2104 *
2105 * Returns 0 on success.
2106 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002107int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 void __user *buffer, size_t *lenp, loff_t *ppos)
2109{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002110 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002111 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112}
2113
Amerigo Wang00b7c332010-05-05 00:26:45 +00002114static size_t proc_skip_spaces(char **buf)
2115{
2116 size_t ret;
2117 char *tmp = skip_spaces(*buf);
2118 ret = tmp - *buf;
2119 *buf = tmp;
2120 return ret;
2121}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002123static void proc_skip_char(char **buf, size_t *size, const char v)
2124{
2125 while (*size) {
2126 if (**buf != v)
2127 break;
2128 (*size)--;
2129 (*buf)++;
2130 }
2131}
2132
Amerigo Wang00b7c332010-05-05 00:26:45 +00002133#define TMPBUFLEN 22
2134/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002135 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002136 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002137 * @buf: a kernel buffer
2138 * @size: size of the kernel buffer
2139 * @val: this is where the number will be stored
2140 * @neg: set to %TRUE if number is negative
2141 * @perm_tr: a vector which contains the allowed trailers
2142 * @perm_tr_len: size of the perm_tr vector
2143 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002144 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002145 * In case of success %0 is returned and @buf and @size are updated with
2146 * the amount of bytes read. If @tr is non-NULL and a trailing
2147 * character exists (size is non-zero after returning from this
2148 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002149 */
2150static int proc_get_long(char **buf, size_t *size,
2151 unsigned long *val, bool *neg,
2152 const char *perm_tr, unsigned perm_tr_len, char *tr)
2153{
2154 int len;
2155 char *p, tmp[TMPBUFLEN];
2156
2157 if (!*size)
2158 return -EINVAL;
2159
2160 len = *size;
2161 if (len > TMPBUFLEN - 1)
2162 len = TMPBUFLEN - 1;
2163
2164 memcpy(tmp, *buf, len);
2165
2166 tmp[len] = 0;
2167 p = tmp;
2168 if (*p == '-' && *size > 1) {
2169 *neg = true;
2170 p++;
2171 } else
2172 *neg = false;
2173 if (!isdigit(*p))
2174 return -EINVAL;
2175
2176 *val = simple_strtoul(p, &p, 0);
2177
2178 len = p - tmp;
2179
2180 /* We don't know if the next char is whitespace thus we may accept
2181 * invalid integers (e.g. 1234...a) or two integers instead of one
2182 * (e.g. 123...1). So lets not allow such large numbers. */
2183 if (len == TMPBUFLEN - 1)
2184 return -EINVAL;
2185
2186 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2187 return -EINVAL;
2188
2189 if (tr && (len < *size))
2190 *tr = *p;
2191
2192 *buf += len;
2193 *size -= len;
2194
2195 return 0;
2196}
2197
2198/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002199 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002200 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002201 * @buf: the user buffer
2202 * @size: the size of the user buffer
2203 * @val: the integer to be converted
2204 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002205 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002206 * In case of success %0 is returned and @buf and @size are updated with
2207 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002208 */
2209static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2210 bool neg)
2211{
2212 int len;
2213 char tmp[TMPBUFLEN], *p = tmp;
2214
2215 sprintf(p, "%s%lu", neg ? "-" : "", val);
2216 len = strlen(tmp);
2217 if (len > *size)
2218 len = *size;
2219 if (copy_to_user(*buf, tmp, len))
2220 return -EFAULT;
2221 *size -= len;
2222 *buf += len;
2223 return 0;
2224}
2225#undef TMPBUFLEN
2226
2227static int proc_put_char(void __user **buf, size_t *size, char c)
2228{
2229 if (*size) {
2230 char __user **buffer = (char __user **)buf;
2231 if (put_user(c, *buffer))
2232 return -EFAULT;
2233 (*size)--, (*buffer)++;
2234 *buf = *buffer;
2235 }
2236 return 0;
2237}
2238
2239static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 int *valp,
2241 int write, void *data)
2242{
2243 if (write) {
2244 *valp = *negp ? -*lvalp : *lvalp;
2245 } else {
2246 int val = *valp;
2247 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002248 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 *lvalp = (unsigned long)-val;
2250 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002251 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 *lvalp = (unsigned long)val;
2253 }
2254 }
2255 return 0;
2256}
2257
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2259
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002260static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002261 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002262 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 int write, void *data),
2265 void *data)
2266{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002267 int *i, vleft, first = 1, err = 0;
2268 unsigned long page = 0;
2269 size_t left;
2270 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Amerigo Wang00b7c332010-05-05 00:26:45 +00002272 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 *lenp = 0;
2274 return 0;
2275 }
2276
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002277 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 vleft = table->maxlen / sizeof(*i);
2279 left = *lenp;
2280
2281 if (!conv)
2282 conv = do_proc_dointvec_conv;
2283
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002285 if (left > PAGE_SIZE - 1)
2286 left = PAGE_SIZE - 1;
2287 page = __get_free_page(GFP_TEMPORARY);
2288 kbuf = (char *) page;
2289 if (!kbuf)
2290 return -ENOMEM;
2291 if (copy_from_user(kbuf, buffer, left)) {
2292 err = -EFAULT;
2293 goto free;
2294 }
2295 kbuf[left] = 0;
2296 }
2297
2298 for (; left && vleft--; i++, first=0) {
2299 unsigned long lval;
2300 bool neg;
2301
2302 if (write) {
2303 left -= proc_skip_spaces(&kbuf);
2304
J. R. Okajima563b0462010-05-25 16:10:14 -07002305 if (!left)
2306 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 err = proc_get_long(&kbuf, &left, &lval, &neg,
2308 proc_wspace_sep,
2309 sizeof(proc_wspace_sep), NULL);
2310 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002312 if (conv(&neg, &lval, i, 1, data)) {
2313 err = -EINVAL;
2314 break;
2315 }
2316 } else {
2317 if (conv(&neg, &lval, i, 0, data)) {
2318 err = -EINVAL;
2319 break;
2320 }
2321 if (!first)
2322 err = proc_put_char(&buffer, &left, '\t');
2323 if (err)
2324 break;
2325 err = proc_put_long(&buffer, &left, lval, neg);
2326 if (err)
2327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330
2331 if (!write && !first && left && !err)
2332 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002333 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 left -= proc_skip_spaces(&kbuf);
2335free:
2336 if (write) {
2337 free_page(page);
2338 if (first)
2339 return err ? : -EINVAL;
2340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 *lenp -= left;
2342 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002346static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002347 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002348 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002349 int write, void *data),
2350 void *data)
2351{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002352 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002353 buffer, lenp, ppos, conv, data);
2354}
2355
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356/**
2357 * proc_dointvec - read a vector of integers
2358 * @table: the sysctl table
2359 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 * @buffer: the user buffer
2361 * @lenp: the size of the user buffer
2362 * @ppos: file position
2363 *
2364 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2365 * values from/to the user buffer, treated as an ASCII string.
2366 *
2367 * Returns 0 on success.
2368 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002369int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 void __user *buffer, size_t *lenp, loff_t *ppos)
2371{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002372 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 NULL,NULL);
2374}
2375
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002376/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002377 * Taint values can only be increased
2378 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002379 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002380static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002383 struct ctl_table t;
2384 unsigned long tmptaint = get_taint();
2385 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002386
Bastian Blank91fcd412007-04-23 14:41:14 -07002387 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002388 return -EPERM;
2389
Andi Kleen25ddbb12008-10-15 22:01:41 -07002390 t = *table;
2391 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002392 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002393 if (err < 0)
2394 return err;
2395
2396 if (write) {
2397 /*
2398 * Poor man's atomic or. Not worth adding a primitive
2399 * to everyone's atomic.h for this
2400 */
2401 int i;
2402 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2403 if ((tmptaint >> i) & 1)
2404 add_taint(i);
2405 }
2406 }
2407
2408 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002409}
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411struct do_proc_dointvec_minmax_conv_param {
2412 int *min;
2413 int *max;
2414};
2415
Amerigo Wang00b7c332010-05-05 00:26:45 +00002416static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2417 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 int write, void *data)
2419{
2420 struct do_proc_dointvec_minmax_conv_param *param = data;
2421 if (write) {
2422 int val = *negp ? -*lvalp : *lvalp;
2423 if ((param->min && *param->min > val) ||
2424 (param->max && *param->max < val))
2425 return -EINVAL;
2426 *valp = val;
2427 } else {
2428 int val = *valp;
2429 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002430 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 *lvalp = (unsigned long)-val;
2432 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002433 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 *lvalp = (unsigned long)val;
2435 }
2436 }
2437 return 0;
2438}
2439
2440/**
2441 * proc_dointvec_minmax - read a vector of integers with min/max values
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2447 *
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 *
2451 * This routine will ensure the values are within the range specified by
2452 * table->extra1 (min) and table->extra2 (max).
2453 *
2454 * Returns 0 on success.
2455 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002456int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 void __user *buffer, size_t *lenp, loff_t *ppos)
2458{
2459 struct do_proc_dointvec_minmax_conv_param param = {
2460 .min = (int *) table->extra1,
2461 .max = (int *) table->extra2,
2462 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002463 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 do_proc_dointvec_minmax_conv, &param);
2465}
2466
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002467static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 void __user *buffer,
2469 size_t *lenp, loff_t *ppos,
2470 unsigned long convmul,
2471 unsigned long convdiv)
2472{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002473 unsigned long *i, *min, *max;
2474 int vleft, first = 1, err = 0;
2475 unsigned long page = 0;
2476 size_t left;
2477 char *kbuf;
2478
2479 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 *lenp = 0;
2481 return 0;
2482 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002483
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002484 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 min = (unsigned long *) table->extra1;
2486 max = (unsigned long *) table->extra2;
2487 vleft = table->maxlen / sizeof(unsigned long);
2488 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002489
2490 if (write) {
2491 if (left > PAGE_SIZE - 1)
2492 left = PAGE_SIZE - 1;
2493 page = __get_free_page(GFP_TEMPORARY);
2494 kbuf = (char *) page;
2495 if (!kbuf)
2496 return -ENOMEM;
2497 if (copy_from_user(kbuf, buffer, left)) {
2498 err = -EFAULT;
2499 goto free;
2500 }
2501 kbuf[left] = 0;
2502 }
2503
Eric Dumazet27b3d802010-10-07 12:59:29 -07002504 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002505 unsigned long val;
2506
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002508 bool neg;
2509
2510 left -= proc_skip_spaces(&kbuf);
2511
2512 err = proc_get_long(&kbuf, &left, &val, &neg,
2513 proc_wspace_sep,
2514 sizeof(proc_wspace_sep), NULL);
2515 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 break;
2517 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 continue;
2519 if ((min && val < *min) || (max && val > *max))
2520 continue;
2521 *i = val;
2522 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002523 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002525 err = proc_put_char(&buffer, &left, '\t');
2526 err = proc_put_long(&buffer, &left, val, false);
2527 if (err)
2528 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 }
2530 }
2531
Amerigo Wang00b7c332010-05-05 00:26:45 +00002532 if (!write && !first && left && !err)
2533 err = proc_put_char(&buffer, &left, '\n');
2534 if (write && !err)
2535 left -= proc_skip_spaces(&kbuf);
2536free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002538 free_page(page);
2539 if (first)
2540 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 *lenp -= left;
2543 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002544 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002547static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002548 void __user *buffer,
2549 size_t *lenp, loff_t *ppos,
2550 unsigned long convmul,
2551 unsigned long convdiv)
2552{
2553 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002554 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002555}
2556
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557/**
2558 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2559 * @table: the sysctl table
2560 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 * @buffer: the user buffer
2562 * @lenp: the size of the user buffer
2563 * @ppos: file position
2564 *
2565 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2566 * values from/to the user buffer, treated as an ASCII string.
2567 *
2568 * This routine will ensure the values are within the range specified by
2569 * table->extra1 (min) and table->extra2 (max).
2570 *
2571 * Returns 0 on success.
2572 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002573int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 void __user *buffer, size_t *lenp, loff_t *ppos)
2575{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577}
2578
2579/**
2580 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 * @buffer: the user buffer
2584 * @lenp: the size of the user buffer
2585 * @ppos: file position
2586 *
2587 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2588 * values from/to the user buffer, treated as an ASCII string. The values
2589 * are treated as milliseconds, and converted to jiffies when they are stored.
2590 *
2591 * This routine will ensure the values are within the range specified by
2592 * table->extra1 (min) and table->extra2 (max).
2593 *
2594 * Returns 0 on success.
2595 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002596int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 void __user *buffer,
2598 size_t *lenp, loff_t *ppos)
2599{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002600 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 lenp, ppos, HZ, 1000l);
2602}
2603
2604
Amerigo Wang00b7c332010-05-05 00:26:45 +00002605static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 int *valp,
2607 int write, void *data)
2608{
2609 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002610 if (*lvalp > LONG_MAX / HZ)
2611 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2613 } else {
2614 int val = *valp;
2615 unsigned long lval;
2616 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002617 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 lval = (unsigned long)-val;
2619 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002620 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 lval = (unsigned long)val;
2622 }
2623 *lvalp = lval / HZ;
2624 }
2625 return 0;
2626}
2627
Amerigo Wang00b7c332010-05-05 00:26:45 +00002628static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 int *valp,
2630 int write, void *data)
2631{
2632 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002633 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2634 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2636 } else {
2637 int val = *valp;
2638 unsigned long lval;
2639 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002640 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 lval = (unsigned long)-val;
2642 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002643 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 lval = (unsigned long)val;
2645 }
2646 *lvalp = jiffies_to_clock_t(lval);
2647 }
2648 return 0;
2649}
2650
Amerigo Wang00b7c332010-05-05 00:26:45 +00002651static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 int *valp,
2653 int write, void *data)
2654{
2655 if (write) {
2656 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2657 } else {
2658 int val = *valp;
2659 unsigned long lval;
2660 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002661 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 lval = (unsigned long)-val;
2663 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002664 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 lval = (unsigned long)val;
2666 }
2667 *lvalp = jiffies_to_msecs(lval);
2668 }
2669 return 0;
2670}
2671
2672/**
2673 * proc_dointvec_jiffies - read a vector of integers as seconds
2674 * @table: the sysctl table
2675 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 * @buffer: the user buffer
2677 * @lenp: the size of the user buffer
2678 * @ppos: file position
2679 *
2680 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2681 * values from/to the user buffer, treated as an ASCII string.
2682 * The values read are assumed to be in seconds, and are converted into
2683 * jiffies.
2684 *
2685 * Returns 0 on success.
2686 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002687int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 void __user *buffer, size_t *lenp, loff_t *ppos)
2689{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002690 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 do_proc_dointvec_jiffies_conv,NULL);
2692}
2693
2694/**
2695 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2696 * @table: the sysctl table
2697 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 * @buffer: the user buffer
2699 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002700 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 *
2702 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2703 * values from/to the user buffer, treated as an ASCII string.
2704 * The values read are assumed to be in 1/USER_HZ seconds, and
2705 * are converted into jiffies.
2706 *
2707 * Returns 0 on success.
2708 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002709int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 void __user *buffer, size_t *lenp, loff_t *ppos)
2711{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002712 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 do_proc_dointvec_userhz_jiffies_conv,NULL);
2714}
2715
2716/**
2717 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2718 * @table: the sysctl table
2719 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 * @buffer: the user buffer
2721 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002722 * @ppos: file position
2723 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 *
2725 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2726 * values from/to the user buffer, treated as an ASCII string.
2727 * The values read are assumed to be in 1/1000 seconds, and
2728 * are converted into jiffies.
2729 *
2730 * Returns 0 on success.
2731 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002732int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 void __user *buffer, size_t *lenp, loff_t *ppos)
2734{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 do_proc_dointvec_ms_jiffies_conv, NULL);
2737}
2738
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002739static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002740 void __user *buffer, size_t *lenp, loff_t *ppos)
2741{
2742 struct pid *new_pid;
2743 pid_t tmp;
2744 int r;
2745
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002746 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002747
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002748 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002749 lenp, ppos, NULL, NULL);
2750 if (r || !write)
2751 return r;
2752
2753 new_pid = find_get_pid(tmp);
2754 if (!new_pid)
2755 return -ESRCH;
2756
2757 put_pid(xchg(&cad_pid, new_pid));
2758 return 0;
2759}
2760
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002761/**
2762 * proc_do_large_bitmap - read/write from/to a large bitmap
2763 * @table: the sysctl table
2764 * @write: %TRUE if this is a write to the sysctl file
2765 * @buffer: the user buffer
2766 * @lenp: the size of the user buffer
2767 * @ppos: file position
2768 *
2769 * The bitmap is stored at table->data and the bitmap length (in bits)
2770 * in table->maxlen.
2771 *
2772 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2773 * large bitmaps may be represented in a compact manner. Writing into
2774 * the file will clear the bitmap then update it with the given input.
2775 *
2776 * Returns 0 on success.
2777 */
2778int proc_do_large_bitmap(struct ctl_table *table, int write,
2779 void __user *buffer, size_t *lenp, loff_t *ppos)
2780{
2781 int err = 0;
2782 bool first = 1;
2783 size_t left = *lenp;
2784 unsigned long bitmap_len = table->maxlen;
2785 unsigned long *bitmap = (unsigned long *) table->data;
2786 unsigned long *tmp_bitmap = NULL;
2787 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2788
2789 if (!bitmap_len || !left || (*ppos && !write)) {
2790 *lenp = 0;
2791 return 0;
2792 }
2793
2794 if (write) {
2795 unsigned long page = 0;
2796 char *kbuf;
2797
2798 if (left > PAGE_SIZE - 1)
2799 left = PAGE_SIZE - 1;
2800
2801 page = __get_free_page(GFP_TEMPORARY);
2802 kbuf = (char *) page;
2803 if (!kbuf)
2804 return -ENOMEM;
2805 if (copy_from_user(kbuf, buffer, left)) {
2806 free_page(page);
2807 return -EFAULT;
2808 }
2809 kbuf[left] = 0;
2810
2811 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2812 GFP_KERNEL);
2813 if (!tmp_bitmap) {
2814 free_page(page);
2815 return -ENOMEM;
2816 }
2817 proc_skip_char(&kbuf, &left, '\n');
2818 while (!err && left) {
2819 unsigned long val_a, val_b;
2820 bool neg;
2821
2822 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2823 sizeof(tr_a), &c);
2824 if (err)
2825 break;
2826 if (val_a >= bitmap_len || neg) {
2827 err = -EINVAL;
2828 break;
2829 }
2830
2831 val_b = val_a;
2832 if (left) {
2833 kbuf++;
2834 left--;
2835 }
2836
2837 if (c == '-') {
2838 err = proc_get_long(&kbuf, &left, &val_b,
2839 &neg, tr_b, sizeof(tr_b),
2840 &c);
2841 if (err)
2842 break;
2843 if (val_b >= bitmap_len || neg ||
2844 val_a > val_b) {
2845 err = -EINVAL;
2846 break;
2847 }
2848 if (left) {
2849 kbuf++;
2850 left--;
2851 }
2852 }
2853
2854 while (val_a <= val_b)
2855 set_bit(val_a++, tmp_bitmap);
2856
2857 first = 0;
2858 proc_skip_char(&kbuf, &left, '\n');
2859 }
2860 free_page(page);
2861 } else {
2862 unsigned long bit_a, bit_b = 0;
2863
2864 while (left) {
2865 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2866 if (bit_a >= bitmap_len)
2867 break;
2868 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2869 bit_a + 1) - 1;
2870
2871 if (!first) {
2872 err = proc_put_char(&buffer, &left, ',');
2873 if (err)
2874 break;
2875 }
2876 err = proc_put_long(&buffer, &left, bit_a, false);
2877 if (err)
2878 break;
2879 if (bit_a != bit_b) {
2880 err = proc_put_char(&buffer, &left, '-');
2881 if (err)
2882 break;
2883 err = proc_put_long(&buffer, &left, bit_b, false);
2884 if (err)
2885 break;
2886 }
2887
2888 first = 0; bit_b++;
2889 }
2890 if (!err)
2891 err = proc_put_char(&buffer, &left, '\n');
2892 }
2893
2894 if (!err) {
2895 if (write) {
2896 if (*ppos)
2897 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2898 else
2899 memcpy(bitmap, tmp_bitmap,
2900 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2901 }
2902 kfree(tmp_bitmap);
2903 *lenp -= left;
2904 *ppos += *lenp;
2905 return 0;
2906 } else {
2907 kfree(tmp_bitmap);
2908 return err;
2909 }
2910}
2911
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912#else /* CONFIG_PROC_FS */
2913
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002914int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 void __user *buffer, size_t *lenp, loff_t *ppos)
2916{
2917 return -ENOSYS;
2918}
2919
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002920int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 void __user *buffer, size_t *lenp, loff_t *ppos)
2922{
2923 return -ENOSYS;
2924}
2925
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002926int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 void __user *buffer, size_t *lenp, loff_t *ppos)
2928{
2929 return -ENOSYS;
2930}
2931
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002932int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 void __user *buffer, size_t *lenp, loff_t *ppos)
2934{
2935 return -ENOSYS;
2936}
2937
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002938int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 void __user *buffer, size_t *lenp, loff_t *ppos)
2940{
2941 return -ENOSYS;
2942}
2943
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002944int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 void __user *buffer, size_t *lenp, loff_t *ppos)
2946{
2947 return -ENOSYS;
2948}
2949
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002950int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 void __user *buffer, size_t *lenp, loff_t *ppos)
2952{
2953 return -ENOSYS;
2954}
2955
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002956int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 void __user *buffer,
2958 size_t *lenp, loff_t *ppos)
2959{
2960 return -ENOSYS;
2961}
2962
2963
2964#endif /* CONFIG_PROC_FS */
2965
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966/*
2967 * No sense putting this after each symbol definition, twice,
2968 * exception granted :-)
2969 */
2970EXPORT_SYMBOL(proc_dointvec);
2971EXPORT_SYMBOL(proc_dointvec_jiffies);
2972EXPORT_SYMBOL(proc_dointvec_minmax);
2973EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2974EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2975EXPORT_SYMBOL(proc_dostring);
2976EXPORT_SYMBOL(proc_doulongvec_minmax);
2977EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2978EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002979EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980EXPORT_SYMBOL(unregister_sysctl_table);