blob: cbd97da7a6135789df794bc4ea5f861f37d85e04 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070028#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070040#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070043#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/times.h>
45#include <linux/limits.h>
46#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020047#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070049#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080050#include <linux/nfs_fs.h>
51#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070052#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020053#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020054#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050055#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020056#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070057#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#include <asm/uaccess.h>
60#include <asm/processor.h>
61
Andi Kleen29cbc782006-09-30 01:47:55 +020062#ifdef CONFIG_X86
63#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010064#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010065#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020066#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080067#ifdef CONFIG_BSD_PROCESS_ACCT
68#include <linux/acct.h>
69#endif
Dave Young4f0e0562010-03-10 15:24:09 -080070#ifdef CONFIG_RT_MUTEXES
71#include <linux/rtmutex.h>
72#endif
Dave Young2edf5e42010-03-10 15:24:10 -080073#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74#include <linux/lockdep.h>
75#endif
Dave Young15485a42010-03-10 15:24:07 -080076#ifdef CONFIG_CHR_DEV_SG
77#include <scsi/sg.h>
78#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020079
Don Zickus58687ac2010-05-07 17:11:44 -040080#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050081#include <linux/nmi.h>
82#endif
83
Eric W. Biederman7058cb02007-10-18 03:05:58 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#if defined(CONFIG_SYSCTL)
86
87/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern int sysctl_overcommit_memory;
89extern int sysctl_overcommit_ratio;
90extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070092extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070094extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern int pid_max;
96extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080098extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080099extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200100extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100101extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400102extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000103#ifndef CONFIG_MMU
104extern int sysctl_nr_trim_pages;
105#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200106#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200107extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700110/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400111#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200113static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700114#endif
115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700117static int __maybe_unused one = 1;
118static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800119static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700121#ifdef CONFIG_PRINTK
122static int ten_thousand = 10000;
123#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700125/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129static int maxolduid = 65535;
130static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800131static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133static int ngroups_max = NGROUPS_MAX;
134
Dave Youngd14f1722010-02-25 20:28:57 -0500135#ifdef CONFIG_INOTIFY_USER
136#include <linux/inotify.h>
137#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700138#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700139#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#endif
141
David S. Miller08714202008-11-16 23:49:24 -0800142#ifdef CONFIG_SPARC64
143extern int sysctl_tsb_ratio;
144#endif
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef __hppa__
147extern int pwrsw_enabled;
148extern int unaligned_enabled;
149#endif
150
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800151#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#ifdef CONFIG_MATHEMU
153extern int sysctl_ieee_emulation_warnings;
154#endif
155extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700156extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
Jes Sorensend2b176e2006-02-28 09:42:23 -0800159#ifdef CONFIG_IA64
160extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800161extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800162#endif
163
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700164#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700165static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800168 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700169#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700171#ifdef CONFIG_MAGIC_SYSRQ
172static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
173
174static int sysrq_sysctl_handler(ctl_table *table, int write,
175 void __user *buffer, size_t *lenp,
176 loff_t *ppos)
177{
178 int error;
179
180 error = proc_dointvec(table, write, buffer, lenp, ppos);
181 if (error)
182 return error;
183
184 if (write)
185 sysrq_toggle_support(__sysrq_enabled);
186
187 return 0;
188}
189
190#endif
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100193static struct ctl_table_root sysctl_table_root;
194static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100195 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400197 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100198 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400199 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100200};
201static struct ctl_table_root sysctl_table_root = {
202 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400203 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100204};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700206static struct ctl_table kern_table[];
207static struct ctl_table vm_table[];
208static struct ctl_table fs_table[];
209static struct ctl_table debug_table[];
210static struct ctl_table dev_table[];
211extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800212#ifdef CONFIG_EPOLL
213extern struct ctl_table epoll_table[];
214#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217int sysctl_legacy_va_layout;
218#endif
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/* The default sysctl tables: */
221
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700222static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .procname = "kernel",
225 .mode = 0555,
226 .child = kern_table,
227 },
228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .procname = "vm",
230 .mode = 0555,
231 .child = vm_table,
232 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 .procname = "fs",
235 .mode = 0555,
236 .child = fs_table,
237 },
238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .procname = "debug",
240 .mode = 0555,
241 .child = debug_table,
242 },
243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .procname = "dev",
245 .mode = 0555,
246 .child = dev_table,
247 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700248/*
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
251 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700252 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100256static int min_sched_granularity_ns = 100000; /* 100 usecs */
257static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
258static int min_wakeup_granularity_ns; /* 0 usecs */
259static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100260static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100262static int min_sched_shares_ratelimit = 100000; /* 100 usec */
263static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264#endif
265
Mel Gorman5e771902010-05-24 14:32:31 -0700266#ifdef CONFIG_COMPACTION
267static int min_extfrag_threshold;
268static int max_extfrag_threshold = 1000;
269#endif
270
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700271static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200272 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200273 .procname = "sched_child_runs_first",
274 .data = &sysctl_sched_child_runs_first,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800277 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200278 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200279#ifdef CONFIG_SCHED_DEBUG
280 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100281 .procname = "sched_min_granularity_ns",
282 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800285 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100286 .extra1 = &min_sched_granularity_ns,
287 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200288 },
289 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200290 .procname = "sched_latency_ns",
291 .data = &sysctl_sched_latency,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800294 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
297 },
298 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .procname = "sched_wakeup_granularity_ns",
300 .data = &sysctl_sched_wakeup_granularity,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800303 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200304 .extra1 = &min_wakeup_granularity_ns,
305 .extra2 = &max_wakeup_granularity_ns,
306 },
307 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200308 .procname = "sched_shares_ratelimit",
309 .data = &sysctl_sched_shares_ratelimit,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800312 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100313 .extra1 = &min_sched_shares_ratelimit,
314 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200315 },
316 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
320 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800321 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200324 },
325 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200326 .procname = "sched_shares_thresh",
327 .data = &sysctl_sched_shares_thresh,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200331 .extra1 = &zero,
332 },
333 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200334 .procname = "sched_migration_cost",
335 .data = &sysctl_sched_migration_cost,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800338 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200339 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100340 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100341 .procname = "sched_nr_migrate",
342 .data = &sysctl_sched_nr_migrate,
343 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800345 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100346 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200348 .procname = "sched_time_avg",
349 .data = &sysctl_sched_time_avg,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800352 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200353 },
354 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530355 .procname = "timer_migration",
356 .data = &sysctl_timer_migration,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800359 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530360 .extra1 = &zero,
361 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530362 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200363#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200364 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100365 .procname = "sched_rt_period_us",
366 .data = &sysctl_sched_rt_period,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800369 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100370 },
371 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100372 .procname = "sched_rt_runtime_us",
373 .data = &sysctl_sched_rt_runtime,
374 .maxlen = sizeof(int),
375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800376 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100377 },
378 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200379 .procname = "sched_compat_yield",
380 .data = &sysctl_sched_compat_yield,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800383 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200384 },
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 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800714#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .procname = "ngroups_max",
717 .data = &ngroups_max,
718 .maxlen = sizeof (int),
719 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800720 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 },
Don Zickus58687ac2010-05-07 17:11:44 -0400722#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500723 {
Don Zickus58687ac2010-05-07 17:11:44 -0400724 .procname = "watchdog",
725 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500726 .maxlen = sizeof (int),
727 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400728 .proc_handler = proc_dowatchdog_enabled,
729 },
730 {
731 .procname = "watchdog_thresh",
732 .data = &softlockup_thresh,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = proc_dowatchdog_thresh,
736 .extra1 = &neg_one,
737 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500738 },
Don Zickus2508ce12010-05-07 17:11:46 -0400739 {
740 .procname = "softlockup_panic",
741 .data = &softlockup_panic,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec_minmax,
745 .extra1 = &zero,
746 .extra2 = &one,
747 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500748#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#if defined(CONFIG_X86)
750 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200751 .procname = "panic_on_unrecovered_nmi",
752 .data = &panic_on_unrecovered_nmi,
753 .maxlen = sizeof(int),
754 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800755 .proc_handler = proc_dointvec,
Don Zickus8da5adda2006-09-26 10:52:27 +0200756 },
757 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700758 .procname = "panic_on_io_nmi",
759 .data = &panic_on_io_nmi,
760 .maxlen = sizeof(int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700763 },
764 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 .procname = "bootloader_type",
766 .data = &bootloader_type,
767 .maxlen = sizeof (int),
768 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800769 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100771 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700772 .procname = "bootloader_version",
773 .data = &bootloader_version,
774 .maxlen = sizeof (int),
775 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700777 },
778 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100779 .procname = "kstack_depth_to_print",
780 .data = &kstack_depth_to_print,
781 .maxlen = sizeof(int),
782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100784 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100785 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100786 .procname = "io_delay_type",
787 .data = &io_delay_type,
788 .maxlen = sizeof(int),
789 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800790 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100791 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800793#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "randomize_va_space",
796 .data = &randomize_va_space,
797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800801#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800802#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700803 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700804 .procname = "spin_retry",
805 .data = &spin_retry,
806 .maxlen = sizeof (int),
807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700809 },
810#endif
Len Brown673d5b42007-07-28 03:33:16 -0400811#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800812 {
Pavel Machekc255d842006-02-20 18:27:58 -0800813 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700814 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800815 .maxlen = sizeof (unsigned long),
816 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800817 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800818 },
819#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800820#ifdef CONFIG_IA64
821 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800822 .procname = "ignore-unaligned-usertrap",
823 .data = &no_unaligned_warning,
824 .maxlen = sizeof (int),
825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800827 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800828 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800829 .procname = "unaligned-dump-stack",
830 .data = &unaligned_dump_stack,
831 .maxlen = sizeof (int),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800834 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800835#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800836#ifdef CONFIG_DETECT_HUNG_TASK
837 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800838 .procname = "hung_task_panic",
839 .data = &sysctl_hung_task_panic,
840 .maxlen = sizeof(int),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800843 .extra1 = &zero,
844 .extra2 = &one,
845 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100846 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 .procname = "hung_task_check_count",
848 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100849 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100850 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800851 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100852 },
853 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 .procname = "hung_task_timeout_secs",
855 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100856 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100859 },
860 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .procname = "hung_task_warnings",
862 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100863 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100864 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800865 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100866 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700867#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200868#ifdef CONFIG_COMPAT
869 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200870 .procname = "compat-log",
871 .data = &compat_log,
872 .maxlen = sizeof (int),
873 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800874 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200875 },
876#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700877#ifdef CONFIG_RT_MUTEXES
878 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700879 .procname = "max_lock_depth",
880 .data = &max_lock_depth,
881 .maxlen = sizeof(int),
882 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800883 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700884 },
885#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700886 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700887 .procname = "poweroff_cmd",
888 .data = &poweroff_cmd,
889 .maxlen = POWEROFF_CMD_PATH_LEN,
890 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800891 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700892 },
David Howells0b77f5b2008-04-29 01:01:32 -0700893#ifdef CONFIG_KEYS
894 {
David Howells0b77f5b2008-04-29 01:01:32 -0700895 .procname = "keys",
896 .mode = 0555,
897 .child = key_sysctls,
898 },
899#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700900#ifdef CONFIG_RCU_TORTURE_TEST
901 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700902 .procname = "rcutorture_runnable",
903 .data = &rcutorture_runnable,
904 .maxlen = sizeof(int),
905 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800906 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700907 },
908#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200909#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200910 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200911 .procname = "perf_event_paranoid",
912 .data = &sysctl_perf_event_paranoid,
913 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200914 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800915 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200916 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200917 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200918 .procname = "perf_event_mlock_kb",
919 .data = &sysctl_perf_event_mlock,
920 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200921 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800922 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200923 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200924 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200925 .procname = "perf_event_max_sample_rate",
926 .data = &sysctl_perf_event_sample_rate,
927 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200928 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800929 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200930 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200931#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200932#ifdef CONFIG_KMEMCHECK
933 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200934 .procname = "kmemcheck",
935 .data = &kmemcheck_enabled,
936 .maxlen = sizeof(int),
937 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800938 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200939 },
940#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200941#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200942 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200943 .procname = "blk_iopoll",
944 .data = &blk_iopoll_enabled,
945 .maxlen = sizeof(int),
946 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800947 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200948 },
Jens Axboecb684b52009-09-15 21:53:11 +0200949#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700950/*
951 * NOTE: do not add new entries to this table unless you have read
952 * Documentation/sysctl/ctl_unnumbered.txt
953 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700954 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955};
956
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700957static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 .procname = "overcommit_memory",
960 .data = &sysctl_overcommit_memory,
961 .maxlen = sizeof(sysctl_overcommit_memory),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 },
965 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700966 .procname = "panic_on_oom",
967 .data = &sysctl_panic_on_oom,
968 .maxlen = sizeof(sysctl_panic_on_oom),
969 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800970 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700971 },
972 {
David Rientjesfe071d72007-10-16 23:25:56 -0700973 .procname = "oom_kill_allocating_task",
974 .data = &sysctl_oom_kill_allocating_task,
975 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
976 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800977 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700978 },
979 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800980 .procname = "oom_dump_tasks",
981 .data = &sysctl_oom_dump_tasks,
982 .maxlen = sizeof(sysctl_oom_dump_tasks),
983 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800984 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800985 },
986 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 .procname = "overcommit_ratio",
988 .data = &sysctl_overcommit_ratio,
989 .maxlen = sizeof(sysctl_overcommit_ratio),
990 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800991 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 },
993 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 .procname = "page-cluster",
995 .data = &page_cluster,
996 .maxlen = sizeof(int),
997 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800998 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 },
1000 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 .procname = "dirty_background_ratio",
1002 .data = &dirty_background_ratio,
1003 .maxlen = sizeof(dirty_background_ratio),
1004 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001005 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 .extra1 = &zero,
1007 .extra2 = &one_hundred,
1008 },
1009 {
David Rientjes2da02992009-01-06 14:39:31 -08001010 .procname = "dirty_background_bytes",
1011 .data = &dirty_background_bytes,
1012 .maxlen = sizeof(dirty_background_bytes),
1013 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001014 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001015 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001016 },
1017 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .procname = "dirty_ratio",
1019 .data = &vm_dirty_ratio,
1020 .maxlen = sizeof(vm_dirty_ratio),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .extra1 = &zero,
1024 .extra2 = &one_hundred,
1025 },
1026 {
David Rientjes2da02992009-01-06 14:39:31 -08001027 .procname = "dirty_bytes",
1028 .data = &vm_dirty_bytes,
1029 .maxlen = sizeof(vm_dirty_bytes),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001032 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001033 },
1034 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001036 .data = &dirty_writeback_interval,
1037 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 },
1041 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001043 .data = &dirty_expire_interval,
1044 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001046 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 },
1048 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 .procname = "nr_pdflush_threads",
1050 .data = &nr_pdflush_threads,
1051 .maxlen = sizeof nr_pdflush_threads,
1052 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 },
1055 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 .procname = "swappiness",
1057 .data = &vm_swappiness,
1058 .maxlen = sizeof(vm_swappiness),
1059 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001060 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 .extra1 = &zero,
1062 .extra2 = &one_hundred,
1063 },
1064#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001065 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001067 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .maxlen = sizeof(unsigned long),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .extra1 = (void *)&hugetlb_zero,
1072 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001073 },
1074#ifdef CONFIG_NUMA
1075 {
1076 .procname = "nr_hugepages_mempolicy",
1077 .data = NULL,
1078 .maxlen = sizeof(unsigned long),
1079 .mode = 0644,
1080 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
1083 },
1084#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .procname = "hugetlb_shm_group",
1087 .data = &sysctl_hugetlb_shm_group,
1088 .maxlen = sizeof(gid_t),
1089 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001090 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 },
Mel Gorman396faf02007-07-17 04:03:13 -07001092 {
Mel Gorman396faf02007-07-17 04:03:13 -07001093 .procname = "hugepages_treat_as_movable",
1094 .data = &hugepages_treat_as_movable,
1095 .maxlen = sizeof(int),
1096 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001097 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001098 },
Adam Litke54f9f802007-10-16 01:26:20 -07001099 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001100 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001101 .data = NULL,
1102 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001103 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001104 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001105 .extra1 = (void *)&hugetlb_zero,
1106 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001107 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108#endif
1109 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .procname = "lowmem_reserve_ratio",
1111 .data = &sysctl_lowmem_reserve_ratio,
1112 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 },
1116 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001117 .procname = "drop_caches",
1118 .data = &sysctl_drop_caches,
1119 .maxlen = sizeof(int),
1120 .mode = 0644,
1121 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001122 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001123#ifdef CONFIG_COMPACTION
1124 {
1125 .procname = "compact_memory",
1126 .data = &sysctl_compact_memory,
1127 .maxlen = sizeof(int),
1128 .mode = 0200,
1129 .proc_handler = sysctl_compaction_handler,
1130 },
Mel Gorman5e771902010-05-24 14:32:31 -07001131 {
1132 .procname = "extfrag_threshold",
1133 .data = &sysctl_extfrag_threshold,
1134 .maxlen = sizeof(int),
1135 .mode = 0644,
1136 .proc_handler = sysctl_extfrag_handler,
1137 .extra1 = &min_extfrag_threshold,
1138 .extra2 = &max_extfrag_threshold,
1139 },
1140
Mel Gorman76ab0f52010-05-24 14:32:28 -07001141#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001142 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 .procname = "min_free_kbytes",
1144 .data = &min_free_kbytes,
1145 .maxlen = sizeof(min_free_kbytes),
1146 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001147 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 .extra1 = &zero,
1149 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001150 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001151 .procname = "percpu_pagelist_fraction",
1152 .data = &percpu_pagelist_fraction,
1153 .maxlen = sizeof(percpu_pagelist_fraction),
1154 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001155 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001156 .extra1 = &min_percpu_pagelist_fract,
1157 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158#ifdef CONFIG_MMU
1159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "max_map_count",
1161 .data = &sysctl_max_map_count,
1162 .maxlen = sizeof(sysctl_max_map_count),
1163 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001164 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001165 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001167#else
1168 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001169 .procname = "nr_trim_pages",
1170 .data = &sysctl_nr_trim_pages,
1171 .maxlen = sizeof(sysctl_nr_trim_pages),
1172 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001173 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001174 .extra1 = &zero,
1175 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#endif
1177 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 .procname = "laptop_mode",
1179 .data = &laptop_mode,
1180 .maxlen = sizeof(laptop_mode),
1181 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001182 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 },
1184 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .procname = "block_dump",
1186 .data = &block_dump,
1187 .maxlen = sizeof(block_dump),
1188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001189 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 .extra1 = &zero,
1191 },
1192 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 .procname = "vfs_cache_pressure",
1194 .data = &sysctl_vfs_cache_pressure,
1195 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1196 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001197 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 .extra1 = &zero,
1199 },
1200#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1201 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 .procname = "legacy_va_layout",
1203 .data = &sysctl_legacy_va_layout,
1204 .maxlen = sizeof(sysctl_legacy_va_layout),
1205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 .extra1 = &zero,
1208 },
1209#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001210#ifdef CONFIG_NUMA
1211 {
Christoph Lameter17436602006-01-18 17:42:32 -08001212 .procname = "zone_reclaim_mode",
1213 .data = &zone_reclaim_mode,
1214 .maxlen = sizeof(zone_reclaim_mode),
1215 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001216 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001217 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001218 },
Christoph Lameter96146342006-07-03 00:24:13 -07001219 {
Christoph Lameter96146342006-07-03 00:24:13 -07001220 .procname = "min_unmapped_ratio",
1221 .data = &sysctl_min_unmapped_ratio,
1222 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001224 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001225 .extra1 = &zero,
1226 .extra2 = &one_hundred,
1227 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001228 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001229 .procname = "min_slab_ratio",
1230 .data = &sysctl_min_slab_ratio,
1231 .maxlen = sizeof(sysctl_min_slab_ratio),
1232 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001233 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001234 .extra1 = &zero,
1235 .extra2 = &one_hundred,
1236 },
Christoph Lameter17436602006-01-18 17:42:32 -08001237#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001238#ifdef CONFIG_SMP
1239 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001240 .procname = "stat_interval",
1241 .data = &sysctl_stat_interval,
1242 .maxlen = sizeof(sysctl_stat_interval),
1243 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001244 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001245 },
1246#endif
David Howells6e141542009-12-15 19:27:45 +00001247#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001248 {
Eric Parised032182007-06-28 15:55:21 -04001249 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001250 .data = &dac_mmap_min_addr,
1251 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001252 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001253 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001254 },
David Howells6e141542009-12-15 19:27:45 +00001255#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001256#ifdef CONFIG_NUMA
1257 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001258 .procname = "numa_zonelist_order",
1259 .data = &numa_zonelist_order,
1260 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1261 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001263 },
1264#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001265#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001266 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001267 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001268 .procname = "vdso_enabled",
1269 .data = &vdso_enabled,
1270 .maxlen = sizeof(vdso_enabled),
1271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001273 .extra1 = &zero,
1274 },
1275#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001276#ifdef CONFIG_HIGHMEM
1277 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001278 .procname = "highmem_is_dirtyable",
1279 .data = &vm_highmem_is_dirtyable,
1280 .maxlen = sizeof(vm_highmem_is_dirtyable),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001283 .extra1 = &zero,
1284 .extra2 = &one,
1285 },
1286#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001287 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001288 .procname = "scan_unevictable_pages",
1289 .data = &scan_unevictable_pages,
1290 .maxlen = sizeof(scan_unevictable_pages),
1291 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001292 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001293 },
Andi Kleen6a460792009-09-16 11:50:15 +02001294#ifdef CONFIG_MEMORY_FAILURE
1295 {
Andi Kleen6a460792009-09-16 11:50:15 +02001296 .procname = "memory_failure_early_kill",
1297 .data = &sysctl_memory_failure_early_kill,
1298 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001301 .extra1 = &zero,
1302 .extra2 = &one,
1303 },
1304 {
Andi Kleen6a460792009-09-16 11:50:15 +02001305 .procname = "memory_failure_recovery",
1306 .data = &sysctl_memory_failure_recovery,
1307 .maxlen = sizeof(sysctl_memory_failure_recovery),
1308 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001309 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001310 .extra1 = &zero,
1311 .extra2 = &one,
1312 },
1313#endif
1314
Andrew Morton2be7fe02007-07-15 23:41:21 -07001315/*
1316 * NOTE: do not add new entries to this table unless you have read
1317 * Documentation/sysctl/ctl_unnumbered.txt
1318 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001319 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320};
1321
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001322#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001323static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001324 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001325};
1326#endif
1327
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001328static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 .procname = "inode-nr",
1331 .data = &inodes_stat,
1332 .maxlen = 2*sizeof(int),
1333 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001334 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 },
1336 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 .procname = "inode-state",
1338 .data = &inodes_stat,
1339 .maxlen = 7*sizeof(int),
1340 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001341 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 },
1343 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 .procname = "file-nr",
1345 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001346 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001348 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 },
1350 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .procname = "file-max",
1352 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001353 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001355 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 },
1357 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001358 .procname = "nr_open",
1359 .data = &sysctl_nr_open,
1360 .maxlen = sizeof(int),
1361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001362 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001363 .extra1 = &sysctl_nr_open_min,
1364 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001365 },
1366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .procname = "dentry-state",
1368 .data = &dentry_stat,
1369 .maxlen = 6*sizeof(int),
1370 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001371 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 },
1373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .procname = "overflowuid",
1375 .data = &fs_overflowuid,
1376 .maxlen = sizeof(int),
1377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001378 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .extra1 = &minolduid,
1380 .extra2 = &maxolduid,
1381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "overflowgid",
1384 .data = &fs_overflowgid,
1385 .maxlen = sizeof(int),
1386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .extra1 = &minolduid,
1389 .extra2 = &maxolduid,
1390 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001391#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .procname = "leases-enable",
1394 .data = &leases_enable,
1395 .maxlen = sizeof(int),
1396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001399#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400#ifdef CONFIG_DNOTIFY
1401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 .procname = "dir-notify-enable",
1403 .data = &dir_notify_enable,
1404 .maxlen = sizeof(int),
1405 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001406 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 },
1408#endif
1409#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001410#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .procname = "lease-break-time",
1413 .data = &lease_break_time,
1414 .maxlen = sizeof(int),
1415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001416 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001418#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001419#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 .procname = "aio-nr",
1422 .data = &aio_nr,
1423 .maxlen = sizeof(aio_nr),
1424 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001425 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 },
1427 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 .procname = "aio-max-nr",
1429 .data = &aio_max_nr,
1430 .maxlen = sizeof(aio_max_nr),
1431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001432 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001434#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001435#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001436 {
Robert Love0399cb02005-07-13 12:38:18 -04001437 .procname = "inotify",
1438 .mode = 0555,
1439 .child = inotify_table,
1440 },
1441#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001442#ifdef CONFIG_EPOLL
1443 {
1444 .procname = "epoll",
1445 .mode = 0555,
1446 .child = epoll_table,
1447 },
1448#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001450 {
Alan Coxd6e71142005-06-23 00:09:43 -07001451 .procname = "suid_dumpable",
1452 .data = &suid_dumpable,
1453 .maxlen = sizeof(int),
1454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001455 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001456 .extra1 = &zero,
1457 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001458 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001459#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1460 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001461 .procname = "binfmt_misc",
1462 .mode = 0555,
1463 .child = binfmt_misc_table,
1464 },
1465#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001466 {
Jens Axboeff9da692010-06-03 14:54:39 +02001467 .procname = "pipe-max-size",
1468 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001469 .maxlen = sizeof(int),
1470 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001471 .proc_handler = &pipe_proc_fn,
1472 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001473 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001474/*
1475 * NOTE: do not add new entries to this table unless you have read
1476 * Documentation/sysctl/ctl_unnumbered.txt
1477 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001478 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479};
1480
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001481static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001482#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1483 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001484 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001485 .procname = "exception-trace",
1486 .data = &show_unhandled_signals,
1487 .maxlen = sizeof(int),
1488 .mode = 0644,
1489 .proc_handler = proc_dointvec
1490 },
1491#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001492#if defined(CONFIG_OPTPROBES)
1493 {
1494 .procname = "kprobes-optimization",
1495 .data = &sysctl_kprobes_optimization,
1496 .maxlen = sizeof(int),
1497 .mode = 0644,
1498 .proc_handler = proc_kprobes_optimization_handler,
1499 .extra1 = &zero,
1500 .extra2 = &one,
1501 },
1502#endif
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 dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001507 { }
Robert Love0eeca282005-07-12 17:06:03 -04001508};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
Al Viro330d57f2005-11-04 10:18:40 +00001510static DEFINE_SPINLOCK(sysctl_lock);
1511
1512/* called under sysctl_lock */
1513static int use_table(struct ctl_table_header *p)
1514{
1515 if (unlikely(p->unregistering))
1516 return 0;
1517 p->used++;
1518 return 1;
1519}
1520
1521/* called under sysctl_lock */
1522static void unuse_table(struct ctl_table_header *p)
1523{
1524 if (!--p->used)
1525 if (unlikely(p->unregistering))
1526 complete(p->unregistering);
1527}
1528
1529/* called under sysctl_lock, will reacquire if has to wait */
1530static void start_unregistering(struct ctl_table_header *p)
1531{
1532 /*
1533 * if p->used is 0, nobody will ever touch that entry again;
1534 * we'll eliminate all paths to it before dropping sysctl_lock
1535 */
1536 if (unlikely(p->used)) {
1537 struct completion wait;
1538 init_completion(&wait);
1539 p->unregistering = &wait;
1540 spin_unlock(&sysctl_lock);
1541 wait_for_completion(&wait);
1542 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001543 } else {
1544 /* anything non-NULL; we'll never dereference it */
1545 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001546 }
1547 /*
1548 * do not remove from the list until nobody holds it; walking the
1549 * list in do_sysctl() relies on that.
1550 */
1551 list_del_init(&p->ctl_entry);
1552}
1553
Al Virof7e6ced2008-07-15 01:44:23 -04001554void sysctl_head_get(struct ctl_table_header *head)
1555{
1556 spin_lock(&sysctl_lock);
1557 head->count++;
1558 spin_unlock(&sysctl_lock);
1559}
1560
1561void sysctl_head_put(struct ctl_table_header *head)
1562{
1563 spin_lock(&sysctl_lock);
1564 if (!--head->count)
1565 kfree(head);
1566 spin_unlock(&sysctl_lock);
1567}
1568
1569struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1570{
1571 if (!head)
1572 BUG();
1573 spin_lock(&sysctl_lock);
1574 if (!use_table(head))
1575 head = ERR_PTR(-ENOENT);
1576 spin_unlock(&sysctl_lock);
1577 return head;
1578}
1579
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001580void sysctl_head_finish(struct ctl_table_header *head)
1581{
1582 if (!head)
1583 return;
1584 spin_lock(&sysctl_lock);
1585 unuse_table(head);
1586 spin_unlock(&sysctl_lock);
1587}
1588
Al Viro73455092008-07-14 21:22:20 -04001589static struct ctl_table_set *
1590lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1591{
1592 struct ctl_table_set *set = &root->default_set;
1593 if (root->lookup)
1594 set = root->lookup(root, namespaces);
1595 return set;
1596}
1597
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001598static struct list_head *
1599lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001600{
Al Viro73455092008-07-14 21:22:20 -04001601 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1602 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001603}
1604
1605struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1606 struct ctl_table_header *prev)
1607{
1608 struct ctl_table_root *root;
1609 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001610 struct ctl_table_header *head;
1611 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001612
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001613 spin_lock(&sysctl_lock);
1614 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001615 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616 tmp = &prev->ctl_entry;
1617 unuse_table(prev);
1618 goto next;
1619 }
1620 tmp = &root_table_header.ctl_entry;
1621 for (;;) {
1622 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1623
1624 if (!use_table(head))
1625 goto next;
1626 spin_unlock(&sysctl_lock);
1627 return head;
1628 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001629 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001630 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001631 header_list = lookup_header_list(root, namespaces);
1632 if (tmp != header_list)
1633 continue;
1634
1635 do {
1636 root = list_entry(root->root_list.next,
1637 struct ctl_table_root, root_list);
1638 if (root == &sysctl_table_root)
1639 goto out;
1640 header_list = lookup_header_list(root, namespaces);
1641 } while (list_empty(header_list));
1642 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001643 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001644out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001645 spin_unlock(&sysctl_lock);
1646 return NULL;
1647}
1648
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001649struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1650{
1651 return __sysctl_head_next(current->nsproxy, prev);
1652}
1653
1654void register_sysctl_root(struct ctl_table_root *root)
1655{
1656 spin_lock(&sysctl_lock);
1657 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1658 spin_unlock(&sysctl_lock);
1659}
1660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001662 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 * some sysctl variables are readonly even to root.
1664 */
1665
1666static int test_perm(int mode, int op)
1667{
David Howells76aac0e2008-11-14 10:39:12 +11001668 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 mode >>= 6;
1670 else if (in_egroup_p(0))
1671 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001672 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 return 0;
1674 return -EACCES;
1675}
1676
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001677int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
1679 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001680 int mode;
1681
Al Viroe6305c42008-07-15 21:03:57 -04001682 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 if (error)
1684 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001685
1686 if (root->permissions)
1687 mode = root->permissions(root, current->nsproxy, table);
1688 else
1689 mode = table->mode;
1690
1691 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001694static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1695{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001696 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001697 table->parent = parent;
1698 if (table->child)
1699 sysctl_set_parent(table, table->child);
1700 }
1701}
1702
1703static __init int sysctl_init(void)
1704{
1705 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001706#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001707 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001708#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001709 return 0;
1710}
1711
1712core_initcall(sysctl_init);
1713
Al Virobfbcf032008-07-27 06:31:22 +01001714static struct ctl_table *is_branch_in(struct ctl_table *branch,
1715 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001716{
1717 struct ctl_table *p;
1718 const char *s = branch->procname;
1719
1720 /* branch should have named subdirectory as its first element */
1721 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001722 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001723
1724 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001725 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001726 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001727
1728 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001729 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001730 if (!p->child)
1731 continue;
1732 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001733 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001734 }
Al Virobfbcf032008-07-27 06:31:22 +01001735 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001736}
1737
1738/* see if attaching q to p would be an improvement */
1739static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1740{
1741 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001742 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001743 int is_better = 0;
1744 int not_in_parent = !p->attached_by;
1745
Al Virobfbcf032008-07-27 06:31:22 +01001746 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001747 if (by == q->attached_by)
1748 is_better = 1;
1749 if (to == p->attached_by)
1750 not_in_parent = 1;
1751 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001752 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001753 }
1754
1755 if (is_better && not_in_parent) {
1756 q->attached_by = by;
1757 q->attached_to = to;
1758 q->parent = p;
1759 }
1760}
1761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001763 * __register_sysctl_paths - register a sysctl hierarchy
1764 * @root: List of sysctl headers to register on
1765 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001766 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 *
1769 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001770 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001772 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1775 * enter a sysctl file
1776 *
1777 * data - a pointer to data for use by proc_handler
1778 *
1779 * maxlen - the maximum size in bytes of the data
1780 *
1781 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1782 *
1783 * child - a pointer to the child sysctl table if this entry is a directory, or
1784 * %NULL.
1785 *
1786 * proc_handler - the text handler routine (described below)
1787 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 * de - for internal use by the sysctl routines
1789 *
1790 * extra1, extra2 - extra pointers usable by the proc handler routines
1791 *
1792 * Leaf nodes in the sysctl tree will be represented by a single file
1793 * under /proc; non-leaf nodes will be represented by directories.
1794 *
1795 * sysctl(2) can automatically manage read and write requests through
1796 * the sysctl table. The data and maxlen fields of the ctl_table
1797 * struct enable minimal validation of the values being written to be
1798 * performed, and the mode field allows minimal authentication.
1799 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 * There must be a proc_handler routine for any terminal nodes
1801 * mirrored under /proc/sys (non-terminals are handled by a built-in
1802 * directory handler). Several default handlers are available to
1803 * cover common cases -
1804 *
1805 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1806 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1807 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1808 *
1809 * It is the handler's job to read the input buffer from user memory
1810 * and process it. The handler should return 0 on success.
1811 *
1812 * This routine returns %NULL on a failure to register, and a pointer
1813 * to the table header on success.
1814 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001815struct ctl_table_header *__register_sysctl_paths(
1816 struct ctl_table_root *root,
1817 struct nsproxy *namespaces,
1818 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001820 struct ctl_table_header *header;
1821 struct ctl_table *new, **prevp;
1822 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001823 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001824
1825 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001826 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001827 ;
1828
1829 /*
1830 * For each path component, allocate a 2-element ctl_table array.
1831 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001832 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001833 *
1834 * We allocate everything in one go so that we don't have to
1835 * worry about freeing additional memory in unregister_sysctl_table.
1836 */
1837 header = kzalloc(sizeof(struct ctl_table_header) +
1838 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1839 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001841
1842 new = (struct ctl_table *) (header + 1);
1843
1844 /* Now connect the dots */
1845 prevp = &header->ctl_table;
1846 for (n = 0; n < npath; ++n, ++path) {
1847 /* Copy the procname */
1848 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849 new->mode = 0555;
1850
1851 *prevp = new;
1852 prevp = &new->child;
1853
1854 new += 2;
1855 }
1856 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001857 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001858
1859 INIT_LIST_HEAD(&header->ctl_entry);
1860 header->used = 0;
1861 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001862 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001863 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001864 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001865#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001866 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001867 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001868 return NULL;
1869 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001870#endif
Al Viro330d57f2005-11-04 10:18:40 +00001871 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001872 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001873 header->attached_by = header->ctl_table;
1874 header->attached_to = root_table;
1875 header->parent = &root_table_header;
1876 for (set = header->set; set; set = set->parent) {
1877 struct ctl_table_header *p;
1878 list_for_each_entry(p, &set->list, ctl_entry) {
1879 if (p->unregistering)
1880 continue;
1881 try_attach(p, header);
1882 }
1883 }
1884 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001885 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001886 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001887
1888 return header;
1889}
1890
1891/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001892 * register_sysctl_table_path - register a sysctl table hierarchy
1893 * @path: The path to the directory the sysctl table is in.
1894 * @table: the top-level table structure
1895 *
1896 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1897 * array. A completely 0 filled entry terminates the table.
1898 *
1899 * See __register_sysctl_paths for more details.
1900 */
1901struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1902 struct ctl_table *table)
1903{
1904 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1905 path, table);
1906}
1907
1908/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001909 * register_sysctl_table - register a sysctl table hierarchy
1910 * @table: the top-level table structure
1911 *
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1914 *
1915 * See register_sysctl_paths for more details.
1916 */
1917struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1918{
1919 static const struct ctl_path null_path[] = { {} };
1920
1921 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922}
1923
1924/**
1925 * unregister_sysctl_table - unregister a sysctl table hierarchy
1926 * @header: the header returned from register_sysctl_table
1927 *
1928 * Unregisters the sysctl table and all children. proc entries may not
1929 * actually be removed until they are no longer used by anyone.
1930 */
1931void unregister_sysctl_table(struct ctl_table_header * header)
1932{
Al Viro330d57f2005-11-04 10:18:40 +00001933 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001934
1935 if (header == NULL)
1936 return;
1937
Al Viro330d57f2005-11-04 10:18:40 +00001938 spin_lock(&sysctl_lock);
1939 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001940 if (!--header->parent->count) {
1941 WARN_ON(1);
1942 kfree(header->parent);
1943 }
Al Virof7e6ced2008-07-15 01:44:23 -04001944 if (!--header->count)
1945 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001946 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947}
1948
Al Viro90434762008-07-15 08:54:06 -04001949int sysctl_is_seen(struct ctl_table_header *p)
1950{
1951 struct ctl_table_set *set = p->set;
1952 int res;
1953 spin_lock(&sysctl_lock);
1954 if (p->unregistering)
1955 res = 0;
1956 else if (!set->is_seen)
1957 res = 1;
1958 else
1959 res = set->is_seen(set);
1960 spin_unlock(&sysctl_lock);
1961 return res;
1962}
1963
Al Viro73455092008-07-14 21:22:20 -04001964void setup_sysctl_set(struct ctl_table_set *p,
1965 struct ctl_table_set *parent,
1966 int (*is_seen)(struct ctl_table_set *))
1967{
1968 INIT_LIST_HEAD(&p->list);
1969 p->parent = parent ? parent : &sysctl_table_root.default_set;
1970 p->is_seen = is_seen;
1971}
1972
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001973#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001974struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001975{
1976 return NULL;
1977}
1978
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001979struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1980 struct ctl_table *table)
1981{
1982 return NULL;
1983}
1984
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001985void unregister_sysctl_table(struct ctl_table_header * table)
1986{
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}
1994
Al Virof7e6ced2008-07-15 01:44:23 -04001995void sysctl_head_put(struct ctl_table_header *head)
1996{
1997}
1998
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001999#endif /* CONFIG_SYSCTL */
2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001/*
2002 * /proc/sys support
2003 */
2004
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002005#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002007static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002008 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002009 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002010{
2011 size_t len;
2012 char __user *p;
2013 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002014
2015 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002016 *lenp = 0;
2017 return 0;
2018 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002019
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002020 if (write) {
2021 len = 0;
2022 p = buffer;
2023 while (len < *lenp) {
2024 if (get_user(c, p++))
2025 return -EFAULT;
2026 if (c == 0 || c == '\n')
2027 break;
2028 len++;
2029 }
2030 if (len >= maxlen)
2031 len = maxlen-1;
2032 if(copy_from_user(data, buffer, len))
2033 return -EFAULT;
2034 ((char *) data)[len] = 0;
2035 *ppos += *lenp;
2036 } else {
2037 len = strlen(data);
2038 if (len > maxlen)
2039 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002040
2041 if (*ppos > len) {
2042 *lenp = 0;
2043 return 0;
2044 }
2045
2046 data += *ppos;
2047 len -= *ppos;
2048
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002049 if (len > *lenp)
2050 len = *lenp;
2051 if (len)
2052 if(copy_to_user(buffer, data, len))
2053 return -EFAULT;
2054 if (len < *lenp) {
2055 if(put_user('\n', ((char __user *) buffer) + len))
2056 return -EFAULT;
2057 len++;
2058 }
2059 *lenp = len;
2060 *ppos += len;
2061 }
2062 return 0;
2063}
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065/**
2066 * proc_dostring - read a string sysctl
2067 * @table: the sysctl table
2068 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 * @buffer: the user buffer
2070 * @lenp: the size of the user buffer
2071 * @ppos: file position
2072 *
2073 * Reads/writes a string from/to the user buffer. If the kernel
2074 * buffer provided is not large enough to hold the string, the
2075 * string is truncated. The copied string is %NULL-terminated.
2076 * If the string is being read by the user process, it is copied
2077 * and a newline '\n' is added. It is truncated if the buffer is
2078 * not large enough.
2079 *
2080 * Returns 0 on success.
2081 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002082int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 void __user *buffer, size_t *lenp, loff_t *ppos)
2084{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002085 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002086 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
Amerigo Wang00b7c332010-05-05 00:26:45 +00002089static size_t proc_skip_spaces(char **buf)
2090{
2091 size_t ret;
2092 char *tmp = skip_spaces(*buf);
2093 ret = tmp - *buf;
2094 *buf = tmp;
2095 return ret;
2096}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002098static void proc_skip_char(char **buf, size_t *size, const char v)
2099{
2100 while (*size) {
2101 if (**buf != v)
2102 break;
2103 (*size)--;
2104 (*buf)++;
2105 }
2106}
2107
Amerigo Wang00b7c332010-05-05 00:26:45 +00002108#define TMPBUFLEN 22
2109/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002110 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002111 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002112 * @buf: a kernel buffer
2113 * @size: size of the kernel buffer
2114 * @val: this is where the number will be stored
2115 * @neg: set to %TRUE if number is negative
2116 * @perm_tr: a vector which contains the allowed trailers
2117 * @perm_tr_len: size of the perm_tr vector
2118 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002119 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002120 * In case of success %0 is returned and @buf and @size are updated with
2121 * the amount of bytes read. If @tr is non-NULL and a trailing
2122 * character exists (size is non-zero after returning from this
2123 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002124 */
2125static int proc_get_long(char **buf, size_t *size,
2126 unsigned long *val, bool *neg,
2127 const char *perm_tr, unsigned perm_tr_len, char *tr)
2128{
2129 int len;
2130 char *p, tmp[TMPBUFLEN];
2131
2132 if (!*size)
2133 return -EINVAL;
2134
2135 len = *size;
2136 if (len > TMPBUFLEN - 1)
2137 len = TMPBUFLEN - 1;
2138
2139 memcpy(tmp, *buf, len);
2140
2141 tmp[len] = 0;
2142 p = tmp;
2143 if (*p == '-' && *size > 1) {
2144 *neg = true;
2145 p++;
2146 } else
2147 *neg = false;
2148 if (!isdigit(*p))
2149 return -EINVAL;
2150
2151 *val = simple_strtoul(p, &p, 0);
2152
2153 len = p - tmp;
2154
2155 /* We don't know if the next char is whitespace thus we may accept
2156 * invalid integers (e.g. 1234...a) or two integers instead of one
2157 * (e.g. 123...1). So lets not allow such large numbers. */
2158 if (len == TMPBUFLEN - 1)
2159 return -EINVAL;
2160
2161 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2162 return -EINVAL;
2163
2164 if (tr && (len < *size))
2165 *tr = *p;
2166
2167 *buf += len;
2168 *size -= len;
2169
2170 return 0;
2171}
2172
2173/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002174 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002175 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002176 * @buf: the user buffer
2177 * @size: the size of the user buffer
2178 * @val: the integer to be converted
2179 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002180 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002181 * In case of success %0 is returned and @buf and @size are updated with
2182 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002183 */
2184static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2185 bool neg)
2186{
2187 int len;
2188 char tmp[TMPBUFLEN], *p = tmp;
2189
2190 sprintf(p, "%s%lu", neg ? "-" : "", val);
2191 len = strlen(tmp);
2192 if (len > *size)
2193 len = *size;
2194 if (copy_to_user(*buf, tmp, len))
2195 return -EFAULT;
2196 *size -= len;
2197 *buf += len;
2198 return 0;
2199}
2200#undef TMPBUFLEN
2201
2202static int proc_put_char(void __user **buf, size_t *size, char c)
2203{
2204 if (*size) {
2205 char __user **buffer = (char __user **)buf;
2206 if (put_user(c, *buffer))
2207 return -EFAULT;
2208 (*size)--, (*buffer)++;
2209 *buf = *buffer;
2210 }
2211 return 0;
2212}
2213
2214static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 int *valp,
2216 int write, void *data)
2217{
2218 if (write) {
2219 *valp = *negp ? -*lvalp : *lvalp;
2220 } else {
2221 int val = *valp;
2222 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002223 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 *lvalp = (unsigned long)-val;
2225 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002226 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 *lvalp = (unsigned long)val;
2228 }
2229 }
2230 return 0;
2231}
2232
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2234
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002235static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002236 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002237 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002238 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 int write, void *data),
2240 void *data)
2241{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 int *i, vleft, first = 1, err = 0;
2243 unsigned long page = 0;
2244 size_t left;
2245 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Amerigo Wang00b7c332010-05-05 00:26:45 +00002247 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 *lenp = 0;
2249 return 0;
2250 }
2251
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002252 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 vleft = table->maxlen / sizeof(*i);
2254 left = *lenp;
2255
2256 if (!conv)
2257 conv = do_proc_dointvec_conv;
2258
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002260 if (left > PAGE_SIZE - 1)
2261 left = PAGE_SIZE - 1;
2262 page = __get_free_page(GFP_TEMPORARY);
2263 kbuf = (char *) page;
2264 if (!kbuf)
2265 return -ENOMEM;
2266 if (copy_from_user(kbuf, buffer, left)) {
2267 err = -EFAULT;
2268 goto free;
2269 }
2270 kbuf[left] = 0;
2271 }
2272
2273 for (; left && vleft--; i++, first=0) {
2274 unsigned long lval;
2275 bool neg;
2276
2277 if (write) {
2278 left -= proc_skip_spaces(&kbuf);
2279
J. R. Okajima563b0462010-05-25 16:10:14 -07002280 if (!left)
2281 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002282 err = proc_get_long(&kbuf, &left, &lval, &neg,
2283 proc_wspace_sep,
2284 sizeof(proc_wspace_sep), NULL);
2285 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287 if (conv(&neg, &lval, i, 1, data)) {
2288 err = -EINVAL;
2289 break;
2290 }
2291 } else {
2292 if (conv(&neg, &lval, i, 0, data)) {
2293 err = -EINVAL;
2294 break;
2295 }
2296 if (!first)
2297 err = proc_put_char(&buffer, &left, '\t');
2298 if (err)
2299 break;
2300 err = proc_put_long(&buffer, &left, lval, neg);
2301 if (err)
2302 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 }
2304 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002305
2306 if (!write && !first && left && !err)
2307 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002308 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002309 left -= proc_skip_spaces(&kbuf);
2310free:
2311 if (write) {
2312 free_page(page);
2313 if (first)
2314 return err ? : -EINVAL;
2315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 *lenp -= left;
2317 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319}
2320
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002321static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002322 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002323 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002324 int write, void *data),
2325 void *data)
2326{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002327 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002328 buffer, lenp, ppos, conv, data);
2329}
2330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331/**
2332 * proc_dointvec - read a vector of integers
2333 * @table: the sysctl table
2334 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 * @buffer: the user buffer
2336 * @lenp: the size of the user buffer
2337 * @ppos: file position
2338 *
2339 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2340 * values from/to the user buffer, treated as an ASCII string.
2341 *
2342 * Returns 0 on success.
2343 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002344int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 void __user *buffer, size_t *lenp, loff_t *ppos)
2346{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002347 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 NULL,NULL);
2349}
2350
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002351/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002352 * Taint values can only be increased
2353 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002354 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002355static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002356 void __user *buffer, size_t *lenp, loff_t *ppos)
2357{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002358 struct ctl_table t;
2359 unsigned long tmptaint = get_taint();
2360 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002361
Bastian Blank91fcd412007-04-23 14:41:14 -07002362 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002363 return -EPERM;
2364
Andi Kleen25ddbb12008-10-15 22:01:41 -07002365 t = *table;
2366 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002367 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002368 if (err < 0)
2369 return err;
2370
2371 if (write) {
2372 /*
2373 * Poor man's atomic or. Not worth adding a primitive
2374 * to everyone's atomic.h for this
2375 */
2376 int i;
2377 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2378 if ((tmptaint >> i) & 1)
2379 add_taint(i);
2380 }
2381 }
2382
2383 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002384}
2385
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386struct do_proc_dointvec_minmax_conv_param {
2387 int *min;
2388 int *max;
2389};
2390
Amerigo Wang00b7c332010-05-05 00:26:45 +00002391static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2392 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 int write, void *data)
2394{
2395 struct do_proc_dointvec_minmax_conv_param *param = data;
2396 if (write) {
2397 int val = *negp ? -*lvalp : *lvalp;
2398 if ((param->min && *param->min > val) ||
2399 (param->max && *param->max < val))
2400 return -EINVAL;
2401 *valp = val;
2402 } else {
2403 int val = *valp;
2404 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002405 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 *lvalp = (unsigned long)-val;
2407 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002408 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 *lvalp = (unsigned long)val;
2410 }
2411 }
2412 return 0;
2413}
2414
2415/**
2416 * proc_dointvec_minmax - read a vector of integers with min/max values
2417 * @table: the sysctl table
2418 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 * @buffer: the user buffer
2420 * @lenp: the size of the user buffer
2421 * @ppos: file position
2422 *
2423 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2424 * values from/to the user buffer, treated as an ASCII string.
2425 *
2426 * This routine will ensure the values are within the range specified by
2427 * table->extra1 (min) and table->extra2 (max).
2428 *
2429 * Returns 0 on success.
2430 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002431int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 void __user *buffer, size_t *lenp, loff_t *ppos)
2433{
2434 struct do_proc_dointvec_minmax_conv_param param = {
2435 .min = (int *) table->extra1,
2436 .max = (int *) table->extra2,
2437 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002438 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 do_proc_dointvec_minmax_conv, &param);
2440}
2441
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002442static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 void __user *buffer,
2444 size_t *lenp, loff_t *ppos,
2445 unsigned long convmul,
2446 unsigned long convdiv)
2447{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002448 unsigned long *i, *min, *max;
2449 int vleft, first = 1, err = 0;
2450 unsigned long page = 0;
2451 size_t left;
2452 char *kbuf;
2453
2454 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 *lenp = 0;
2456 return 0;
2457 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002458
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002459 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 min = (unsigned long *) table->extra1;
2461 max = (unsigned long *) table->extra2;
2462 vleft = table->maxlen / sizeof(unsigned long);
2463 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002464
2465 if (write) {
2466 if (left > PAGE_SIZE - 1)
2467 left = PAGE_SIZE - 1;
2468 page = __get_free_page(GFP_TEMPORARY);
2469 kbuf = (char *) page;
2470 if (!kbuf)
2471 return -ENOMEM;
2472 if (copy_from_user(kbuf, buffer, left)) {
2473 err = -EFAULT;
2474 goto free;
2475 }
2476 kbuf[left] = 0;
2477 }
2478
Eric Dumazet27b3d802010-10-07 12:59:29 -07002479 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002480 unsigned long val;
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002483 bool neg;
2484
2485 left -= proc_skip_spaces(&kbuf);
2486
2487 err = proc_get_long(&kbuf, &left, &val, &neg,
2488 proc_wspace_sep,
2489 sizeof(proc_wspace_sep), NULL);
2490 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 break;
2492 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 continue;
2494 if ((min && val < *min) || (max && val > *max))
2495 continue;
2496 *i = val;
2497 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002498 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002500 err = proc_put_char(&buffer, &left, '\t');
2501 err = proc_put_long(&buffer, &left, val, false);
2502 if (err)
2503 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
2505 }
2506
Amerigo Wang00b7c332010-05-05 00:26:45 +00002507 if (!write && !first && left && !err)
2508 err = proc_put_char(&buffer, &left, '\n');
2509 if (write && !err)
2510 left -= proc_skip_spaces(&kbuf);
2511free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513 free_page(page);
2514 if (first)
2515 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 *lenp -= left;
2518 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002519 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520}
2521
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002522static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002523 void __user *buffer,
2524 size_t *lenp, loff_t *ppos,
2525 unsigned long convmul,
2526 unsigned long convdiv)
2527{
2528 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002529 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002530}
2531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532/**
2533 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2534 * @table: the sysctl table
2535 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 * @buffer: the user buffer
2537 * @lenp: the size of the user buffer
2538 * @ppos: file position
2539 *
2540 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2541 * values from/to the user buffer, treated as an ASCII string.
2542 *
2543 * This routine will ensure the values are within the range specified by
2544 * table->extra1 (min) and table->extra2 (max).
2545 *
2546 * Returns 0 on success.
2547 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002548int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 void __user *buffer, size_t *lenp, loff_t *ppos)
2550{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002551 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/**
2555 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2556 * @table: the sysctl table
2557 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 * @buffer: the user buffer
2559 * @lenp: the size of the user buffer
2560 * @ppos: file position
2561 *
2562 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2563 * values from/to the user buffer, treated as an ASCII string. The values
2564 * are treated as milliseconds, and converted to jiffies when they are stored.
2565 *
2566 * This routine will ensure the values are within the range specified by
2567 * table->extra1 (min) and table->extra2 (max).
2568 *
2569 * Returns 0 on success.
2570 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002571int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 void __user *buffer,
2573 size_t *lenp, loff_t *ppos)
2574{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002575 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 lenp, ppos, HZ, 1000l);
2577}
2578
2579
Amerigo Wang00b7c332010-05-05 00:26:45 +00002580static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 int *valp,
2582 int write, void *data)
2583{
2584 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002585 if (*lvalp > LONG_MAX / HZ)
2586 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2588 } else {
2589 int val = *valp;
2590 unsigned long lval;
2591 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002592 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 lval = (unsigned long)-val;
2594 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002595 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 lval = (unsigned long)val;
2597 }
2598 *lvalp = lval / HZ;
2599 }
2600 return 0;
2601}
2602
Amerigo Wang00b7c332010-05-05 00:26:45 +00002603static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 int *valp,
2605 int write, void *data)
2606{
2607 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002608 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2609 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2611 } else {
2612 int val = *valp;
2613 unsigned long lval;
2614 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002615 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 lval = (unsigned long)-val;
2617 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002618 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 lval = (unsigned long)val;
2620 }
2621 *lvalp = jiffies_to_clock_t(lval);
2622 }
2623 return 0;
2624}
2625
Amerigo Wang00b7c332010-05-05 00:26:45 +00002626static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 int *valp,
2628 int write, void *data)
2629{
2630 if (write) {
2631 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2632 } else {
2633 int val = *valp;
2634 unsigned long lval;
2635 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002636 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 lval = (unsigned long)-val;
2638 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002639 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 lval = (unsigned long)val;
2641 }
2642 *lvalp = jiffies_to_msecs(lval);
2643 }
2644 return 0;
2645}
2646
2647/**
2648 * proc_dointvec_jiffies - read a vector of integers as seconds
2649 * @table: the sysctl table
2650 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 * @buffer: the user buffer
2652 * @lenp: the size of the user buffer
2653 * @ppos: file position
2654 *
2655 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2656 * values from/to the user buffer, treated as an ASCII string.
2657 * The values read are assumed to be in seconds, and are converted into
2658 * jiffies.
2659 *
2660 * Returns 0 on success.
2661 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002662int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 void __user *buffer, size_t *lenp, loff_t *ppos)
2664{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002665 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 do_proc_dointvec_jiffies_conv,NULL);
2667}
2668
2669/**
2670 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 * @buffer: the user buffer
2674 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002675 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 *
2677 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2678 * values from/to the user buffer, treated as an ASCII string.
2679 * The values read are assumed to be in 1/USER_HZ seconds, and
2680 * are converted into jiffies.
2681 *
2682 * Returns 0 on success.
2683 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002684int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 void __user *buffer, size_t *lenp, loff_t *ppos)
2686{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002687 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 do_proc_dointvec_userhz_jiffies_conv,NULL);
2689}
2690
2691/**
2692 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2693 * @table: the sysctl table
2694 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002697 * @ppos: file position
2698 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 *
2700 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2701 * values from/to the user buffer, treated as an ASCII string.
2702 * The values read are assumed to be in 1/1000 seconds, and
2703 * are converted into jiffies.
2704 *
2705 * Returns 0 on success.
2706 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002707int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 void __user *buffer, size_t *lenp, loff_t *ppos)
2709{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002710 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 do_proc_dointvec_ms_jiffies_conv, NULL);
2712}
2713
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002714static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002715 void __user *buffer, size_t *lenp, loff_t *ppos)
2716{
2717 struct pid *new_pid;
2718 pid_t tmp;
2719 int r;
2720
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002721 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002722
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002724 lenp, ppos, NULL, NULL);
2725 if (r || !write)
2726 return r;
2727
2728 new_pid = find_get_pid(tmp);
2729 if (!new_pid)
2730 return -ESRCH;
2731
2732 put_pid(xchg(&cad_pid, new_pid));
2733 return 0;
2734}
2735
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002736/**
2737 * proc_do_large_bitmap - read/write from/to a large bitmap
2738 * @table: the sysctl table
2739 * @write: %TRUE if this is a write to the sysctl file
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
2742 * @ppos: file position
2743 *
2744 * The bitmap is stored at table->data and the bitmap length (in bits)
2745 * in table->maxlen.
2746 *
2747 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2748 * large bitmaps may be represented in a compact manner. Writing into
2749 * the file will clear the bitmap then update it with the given input.
2750 *
2751 * Returns 0 on success.
2752 */
2753int proc_do_large_bitmap(struct ctl_table *table, int write,
2754 void __user *buffer, size_t *lenp, loff_t *ppos)
2755{
2756 int err = 0;
2757 bool first = 1;
2758 size_t left = *lenp;
2759 unsigned long bitmap_len = table->maxlen;
2760 unsigned long *bitmap = (unsigned long *) table->data;
2761 unsigned long *tmp_bitmap = NULL;
2762 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2763
2764 if (!bitmap_len || !left || (*ppos && !write)) {
2765 *lenp = 0;
2766 return 0;
2767 }
2768
2769 if (write) {
2770 unsigned long page = 0;
2771 char *kbuf;
2772
2773 if (left > PAGE_SIZE - 1)
2774 left = PAGE_SIZE - 1;
2775
2776 page = __get_free_page(GFP_TEMPORARY);
2777 kbuf = (char *) page;
2778 if (!kbuf)
2779 return -ENOMEM;
2780 if (copy_from_user(kbuf, buffer, left)) {
2781 free_page(page);
2782 return -EFAULT;
2783 }
2784 kbuf[left] = 0;
2785
2786 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2787 GFP_KERNEL);
2788 if (!tmp_bitmap) {
2789 free_page(page);
2790 return -ENOMEM;
2791 }
2792 proc_skip_char(&kbuf, &left, '\n');
2793 while (!err && left) {
2794 unsigned long val_a, val_b;
2795 bool neg;
2796
2797 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2798 sizeof(tr_a), &c);
2799 if (err)
2800 break;
2801 if (val_a >= bitmap_len || neg) {
2802 err = -EINVAL;
2803 break;
2804 }
2805
2806 val_b = val_a;
2807 if (left) {
2808 kbuf++;
2809 left--;
2810 }
2811
2812 if (c == '-') {
2813 err = proc_get_long(&kbuf, &left, &val_b,
2814 &neg, tr_b, sizeof(tr_b),
2815 &c);
2816 if (err)
2817 break;
2818 if (val_b >= bitmap_len || neg ||
2819 val_a > val_b) {
2820 err = -EINVAL;
2821 break;
2822 }
2823 if (left) {
2824 kbuf++;
2825 left--;
2826 }
2827 }
2828
2829 while (val_a <= val_b)
2830 set_bit(val_a++, tmp_bitmap);
2831
2832 first = 0;
2833 proc_skip_char(&kbuf, &left, '\n');
2834 }
2835 free_page(page);
2836 } else {
2837 unsigned long bit_a, bit_b = 0;
2838
2839 while (left) {
2840 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2841 if (bit_a >= bitmap_len)
2842 break;
2843 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2844 bit_a + 1) - 1;
2845
2846 if (!first) {
2847 err = proc_put_char(&buffer, &left, ',');
2848 if (err)
2849 break;
2850 }
2851 err = proc_put_long(&buffer, &left, bit_a, false);
2852 if (err)
2853 break;
2854 if (bit_a != bit_b) {
2855 err = proc_put_char(&buffer, &left, '-');
2856 if (err)
2857 break;
2858 err = proc_put_long(&buffer, &left, bit_b, false);
2859 if (err)
2860 break;
2861 }
2862
2863 first = 0; bit_b++;
2864 }
2865 if (!err)
2866 err = proc_put_char(&buffer, &left, '\n');
2867 }
2868
2869 if (!err) {
2870 if (write) {
2871 if (*ppos)
2872 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2873 else
2874 memcpy(bitmap, tmp_bitmap,
2875 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2876 }
2877 kfree(tmp_bitmap);
2878 *lenp -= left;
2879 *ppos += *lenp;
2880 return 0;
2881 } else {
2882 kfree(tmp_bitmap);
2883 return err;
2884 }
2885}
2886
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887#else /* CONFIG_PROC_FS */
2888
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002889int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 void __user *buffer, size_t *lenp, loff_t *ppos)
2891{
2892 return -ENOSYS;
2893}
2894
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002895int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 void __user *buffer, size_t *lenp, loff_t *ppos)
2897{
2898 return -ENOSYS;
2899}
2900
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002901int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 void __user *buffer, size_t *lenp, loff_t *ppos)
2903{
2904 return -ENOSYS;
2905}
2906
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002907int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 void __user *buffer, size_t *lenp, loff_t *ppos)
2909{
2910 return -ENOSYS;
2911}
2912
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002913int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 void __user *buffer, size_t *lenp, loff_t *ppos)
2915{
2916 return -ENOSYS;
2917}
2918
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002919int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 void __user *buffer, size_t *lenp, loff_t *ppos)
2921{
2922 return -ENOSYS;
2923}
2924
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002925int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 void __user *buffer, size_t *lenp, loff_t *ppos)
2927{
2928 return -ENOSYS;
2929}
2930
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002931int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 void __user *buffer,
2933 size_t *lenp, loff_t *ppos)
2934{
2935 return -ENOSYS;
2936}
2937
2938
2939#endif /* CONFIG_PROC_FS */
2940
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941/*
2942 * No sense putting this after each symbol definition, twice,
2943 * exception granted :-)
2944 */
2945EXPORT_SYMBOL(proc_dointvec);
2946EXPORT_SYMBOL(proc_dointvec_jiffies);
2947EXPORT_SYMBOL(proc_dointvec_minmax);
2948EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2949EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2950EXPORT_SYMBOL(proc_dostring);
2951EXPORT_SYMBOL(proc_doulongvec_minmax);
2952EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2953EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002954EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955EXPORT_SYMBOL(unregister_sysctl_table);