blob: 2d2ecdcc8cdbb070999d46ae79b158dbbb28c8a3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040059#include <linux/kmod.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#include <asm/uaccess.h>
62#include <asm/processor.h>
63
Andi Kleen29cbc782006-09-30 01:47:55 +020064#ifdef CONFIG_X86
65#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010066#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010067#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020068#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080069#ifdef CONFIG_BSD_PROCESS_ACCT
70#include <linux/acct.h>
71#endif
Dave Young4f0e0562010-03-10 15:24:09 -080072#ifdef CONFIG_RT_MUTEXES
73#include <linux/rtmutex.h>
74#endif
Dave Young2edf5e42010-03-10 15:24:10 -080075#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
76#include <linux/lockdep.h>
77#endif
Dave Young15485a42010-03-10 15:24:07 -080078#ifdef CONFIG_CHR_DEV_SG
79#include <scsi/sg.h>
80#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020081
Don Zickus58687ac2010-05-07 17:11:44 -040082#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050083#include <linux/nmi.h>
84#endif
85
Eric W. Biederman7058cb02007-10-18 03:05:58 -070086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#if defined(CONFIG_SYSCTL)
88
89/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090extern int sysctl_overcommit_memory;
91extern int sysctl_overcommit_ratio;
92extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070094extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070096extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int pid_max;
98extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -0800100extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800101extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200102extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100103extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400104extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000105#ifndef CONFIG_MMU
106extern int sysctl_nr_trim_pages;
107#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200108#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200109extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400113#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700114static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200115static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116#endif
117
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700119static int __maybe_unused one = 1;
120static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700121static int __maybe_unused three = 3;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800122static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700124#ifdef CONFIG_PRINTK
125static int ten_thousand = 10000;
126#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700127
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700128/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
129static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
132static int maxolduid = 65535;
133static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800134static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136static int ngroups_max = NGROUPS_MAX;
137
Dave Youngd14f1722010-02-25 20:28:57 -0500138#ifdef CONFIG_INOTIFY_USER
139#include <linux/inotify.h>
140#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700141#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700142#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif
144
David S. Miller08714202008-11-16 23:49:24 -0800145#ifdef CONFIG_SPARC64
146extern int sysctl_tsb_ratio;
147#endif
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#ifdef __hppa__
150extern int pwrsw_enabled;
151extern int unaligned_enabled;
152#endif
153
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800154#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#ifdef CONFIG_MATHEMU
156extern int sysctl_ieee_emulation_warnings;
157#endif
158extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700159extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#endif
161
Jes Sorensend2b176e2006-02-28 09:42:23 -0800162#ifdef CONFIG_IA64
163extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800164extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800165#endif
166
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700167#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700168static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700169 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700170static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800171 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700172#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700173
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700174#ifdef CONFIG_PRINTK
175static int proc_dmesg_restrict(struct ctl_table *table, int write,
176 void __user *buffer, size_t *lenp, loff_t *ppos);
177#endif
178
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700179#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800180/* Note: sysrq code uses it's own private copy */
181static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700182
183static int sysrq_sysctl_handler(ctl_table *table, int write,
184 void __user *buffer, size_t *lenp,
185 loff_t *ppos)
186{
187 int error;
188
189 error = proc_dointvec(table, write, buffer, lenp, ppos);
190 if (error)
191 return error;
192
193 if (write)
194 sysrq_toggle_support(__sysrq_enabled);
195
196 return 0;
197}
198
199#endif
200
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700201static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100202static struct ctl_table_root sysctl_table_root;
203static struct ctl_table_header root_table_header = {
Al Virodfef6dcd32011-03-08 01:25:28 -0500204 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100205 .ctl_table = root_table,
Al Virodfef6dcd32011-03-08 01:25:28 -0500206 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100207 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400208 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100209};
210static struct ctl_table_root sysctl_table_root = {
211 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400212 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100213};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700215static struct ctl_table kern_table[];
216static struct ctl_table vm_table[];
217static struct ctl_table fs_table[];
218static struct ctl_table debug_table[];
219static struct ctl_table dev_table[];
220extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800221#ifdef CONFIG_EPOLL
222extern struct ctl_table epoll_table[];
223#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
226int sysctl_legacy_va_layout;
227#endif
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/* The default sysctl tables: */
230
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700231static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .procname = "kernel",
234 .mode = 0555,
235 .child = kern_table,
236 },
237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .procname = "vm",
239 .mode = 0555,
240 .child = vm_table,
241 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 .procname = "fs",
244 .mode = 0555,
245 .child = fs_table,
246 },
247 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 .procname = "debug",
249 .mode = 0555,
250 .child = debug_table,
251 },
252 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 .procname = "dev",
254 .mode = 0555,
255 .child = dev_table,
256 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700257 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100261static int min_sched_granularity_ns = 100000; /* 100 usecs */
262static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
263static int min_wakeup_granularity_ns; /* 0 usecs */
264static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100265static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
266static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267#endif
268
Mel Gorman5e771902010-05-24 14:32:31 -0700269#ifdef CONFIG_COMPACTION
270static int min_extfrag_threshold;
271static int max_extfrag_threshold = 1000;
272#endif
273
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700274static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200275 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800280 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200281 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282#ifdef CONFIG_SCHED_DEBUG
283 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800288 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291 },
292 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800297 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
300 },
301 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800306 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
309 },
310 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
314 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800315 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100316 .extra1 = &min_sched_tunable_scaling,
317 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200318 },
319 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200320 .procname = "sched_migration_cost",
321 .data = &sysctl_sched_migration_cost,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800324 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200325 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100326 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100330 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800331 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100332 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530333 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200334 .procname = "sched_time_avg",
335 .data = &sysctl_sched_time_avg,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800338 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200339 },
340 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800341 .procname = "sched_shares_window",
342 .data = &sysctl_sched_shares_window,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec,
346 },
347 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800352 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530353 .extra1 = &zero,
354 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530355 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200356#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200357 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100358 .procname = "sched_rt_period_us",
359 .data = &sysctl_sched_rt_period,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800362 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100363 },
364 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100365 .procname = "sched_rt_runtime_us",
366 .data = &sysctl_sched_rt_runtime,
367 .maxlen = sizeof(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 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100371#ifdef CONFIG_SCHED_AUTOGROUP
372 {
373 .procname = "sched_autogroup_enabled",
374 .data = &sysctl_sched_autogroup_enabled,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800377 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100378 .extra1 = &zero,
379 .extra2 = &one,
380 },
381#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700382#ifdef CONFIG_CFS_BANDWIDTH
383 {
384 .procname = "sched_cfs_bandwidth_slice_us",
385 .data = &sysctl_sched_cfs_bandwidth_slice,
386 .maxlen = sizeof(unsigned int),
387 .mode = 0644,
388 .proc_handler = proc_dointvec_minmax,
389 .extra1 = &one,
390 },
391#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700392#ifdef CONFIG_PROVE_LOCKING
393 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700394 .procname = "prove_locking",
395 .data = &prove_locking,
396 .maxlen = sizeof(int),
397 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800398 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700399 },
400#endif
401#ifdef CONFIG_LOCK_STAT
402 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700403 .procname = "lock_stat",
404 .data = &lock_stat,
405 .maxlen = sizeof(int),
406 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800407 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700408 },
409#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "panic",
412 .data = &panic_timeout,
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_uses_pid",
419 .data = &core_uses_pid,
420 .maxlen = sizeof(int),
421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800422 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 },
424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .procname = "core_pattern",
426 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700427 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800429 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 },
Neil Hormana2939802009-09-23 15:56:56 -0700431 {
Neil Hormana2939802009-09-23 15:56:56 -0700432 .procname = "core_pipe_limit",
433 .data = &core_pipe_limit,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700437 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800438#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700441 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800445#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100446#ifdef CONFIG_LATENCYTOP
447 {
448 .procname = "latencytop",
449 .data = &latencytop_enabled,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800452 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100453 },
454#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#ifdef CONFIG_BLK_DEV_INITRD
456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "real-root-dev",
458 .data = &real_root_dev,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
463#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700464 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700465 .procname = "print-fatal-signals",
466 .data = &print_fatal_signals,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800469 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700470 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700471#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "reboot-cmd",
474 .data = reboot_command,
475 .maxlen = 256,
476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800477 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .procname = "stop-a",
481 .data = &stop_a_enabled,
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .procname = "scons-poweroff",
488 .data = &scons_pwroff,
489 .maxlen = sizeof (int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 },
493#endif
David S. Miller08714202008-11-16 23:49:24 -0800494#ifdef CONFIG_SPARC64
495 {
David S. Miller08714202008-11-16 23:49:24 -0800496 .procname = "tsb-ratio",
497 .data = &sysctl_tsb_ratio,
498 .maxlen = sizeof (int),
499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800500 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800501 },
502#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#ifdef __hppa__
504 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .procname = "soft-power",
506 .data = &pwrsw_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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .procname = "unaligned-trap",
513 .data = &unaligned_enabled,
514 .maxlen = sizeof (int),
515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800516 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 },
518#endif
519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "ctrl-alt-del",
521 .data = &C_A_D,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800524 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400526#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200527 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200528 .procname = "ftrace_enabled",
529 .data = &ftrace_enabled,
530 .maxlen = sizeof(int),
531 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800532 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200533 },
534#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500535#ifdef CONFIG_STACK_TRACER
536 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500537 .procname = "stack_tracer_enabled",
538 .data = &stack_tracer_enabled,
539 .maxlen = sizeof(int),
540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500542 },
543#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400544#ifdef CONFIG_TRACING
545 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100546 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400547 .data = &ftrace_dump_on_oops,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800550 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400551 },
552#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200553#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 .procname = "modprobe",
556 .data = &modprobe_path,
557 .maxlen = KMOD_PATH_LEN,
558 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800559 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 },
Kees Cook3d433212009-04-02 15:49:29 -0700561 {
Kees Cook3d433212009-04-02 15:49:29 -0700562 .procname = "modules_disabled",
563 .data = &modules_disabled,
564 .maxlen = sizeof(int),
565 .mode = 0644,
566 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800567 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700568 .extra1 = &one,
569 .extra2 = &one,
570 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100572#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100575 .data = &uevent_helper,
576 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
580#endif
581#ifdef CONFIG_CHR_DEV_SG
582 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .procname = "sg-big-buff",
584 .data = &sg_big_buff,
585 .maxlen = sizeof (int),
586 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800587 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 },
589#endif
590#ifdef CONFIG_BSD_PROCESS_ACCT
591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "acct",
593 .data = &acct_parm,
594 .maxlen = 3*sizeof(int),
595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800596 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
598#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#ifdef CONFIG_MAGIC_SYSRQ
600 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800602 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .maxlen = sizeof (int),
604 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700605 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 },
607#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700608#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700611 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .maxlen = sizeof (int),
613 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800614 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700616#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .procname = "threads-max",
619 .data = &max_threads,
620 .maxlen = sizeof(int),
621 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800622 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 },
624 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 .procname = "random",
626 .mode = 0555,
627 .child = random_table,
628 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 {
Eric Paris17f60a72011-04-01 17:07:50 -0400630 .procname = "usermodehelper",
631 .mode = 0555,
632 .child = usermodehelper_table,
633 },
634 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 .procname = "overflowuid",
636 .data = &overflowuid,
637 .maxlen = sizeof(int),
638 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800639 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .extra1 = &minolduid,
641 .extra2 = &maxolduid,
642 },
643 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 .procname = "overflowgid",
645 .data = &overflowgid,
646 .maxlen = sizeof(int),
647 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800648 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .extra1 = &minolduid,
650 .extra2 = &maxolduid,
651 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800652#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#ifdef CONFIG_MATHEMU
654 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .procname = "ieee_emulation_warnings",
656 .data = &sysctl_ieee_emulation_warnings,
657 .maxlen = sizeof(int),
658 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800659 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 },
661#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200664 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 .maxlen = sizeof(int),
666 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800667 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 },
669#endif
670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .procname = "pid_max",
672 .data = &pid_max,
673 .maxlen = sizeof (int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .extra1 = &pid_max_min,
677 .extra2 = &pid_max_max,
678 },
679 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 .procname = "panic_on_oops",
681 .data = &panic_on_oops,
682 .maxlen = sizeof(int),
683 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800684 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800686#if defined CONFIG_PRINTK
687 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800688 .procname = "printk",
689 .data = &console_loglevel,
690 .maxlen = 4*sizeof(int),
691 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800692 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800693 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700696 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .maxlen = sizeof(int),
698 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800699 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 },
701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700703 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .maxlen = sizeof(int),
705 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800706 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Dave Youngaf913222009-09-22 16:43:33 -0700708 {
Dave Youngaf913222009-09-22 16:43:33 -0700709 .procname = "printk_delay",
710 .data = &printk_delay_msec,
711 .maxlen = sizeof(int),
712 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800713 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700714 .extra1 = &zero,
715 .extra2 = &ten_thousand,
716 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800718 .procname = "dmesg_restrict",
719 .data = &dmesg_restrict,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &zero,
724 .extra2 = &one,
725 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800726 {
727 .procname = "kptr_restrict",
728 .data = &kptr_restrict,
729 .maxlen = sizeof(int),
730 .mode = 0644,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700731 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800732 .extra1 = &zero,
733 .extra2 = &two,
734 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800735#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .procname = "ngroups_max",
738 .data = &ngroups_max,
739 .maxlen = sizeof (int),
740 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800741 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 },
Don Zickus58687ac2010-05-07 17:11:44 -0400743#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500744 {
Don Zickus58687ac2010-05-07 17:11:44 -0400745 .procname = "watchdog",
746 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500747 .maxlen = sizeof (int),
748 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700749 .proc_handler = proc_dowatchdog,
750 .extra1 = &zero,
751 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400752 },
753 {
754 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700755 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400756 .maxlen = sizeof(int),
757 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700758 .proc_handler = proc_dowatchdog,
Don Zickus58687ac2010-05-07 17:11:44 -0400759 .extra1 = &neg_one,
760 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500761 },
Don Zickus2508ce12010-05-07 17:11:46 -0400762 {
763 .procname = "softlockup_panic",
764 .data = &softlockup_panic,
765 .maxlen = sizeof(int),
766 .mode = 0644,
767 .proc_handler = proc_dointvec_minmax,
768 .extra1 = &zero,
769 .extra2 = &one,
770 },
Don Zickus5dc30552010-11-29 17:07:17 -0500771 {
772 .procname = "nmi_watchdog",
773 .data = &watchdog_enabled,
774 .maxlen = sizeof (int),
775 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700776 .proc_handler = proc_dowatchdog,
777 .extra1 = &zero,
778 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500779 },
780#endif
781#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
782 {
783 .procname = "unknown_nmi_panic",
784 .data = &unknown_nmi_panic,
785 .maxlen = sizeof (int),
786 .mode = 0644,
787 .proc_handler = proc_dointvec,
788 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500789#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790#if defined(CONFIG_X86)
791 {
Don Zickus8da5add2006-09-26 10:52:27 +0200792 .procname = "panic_on_unrecovered_nmi",
793 .data = &panic_on_unrecovered_nmi,
794 .maxlen = sizeof(int),
795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800796 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200797 },
798 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700799 .procname = "panic_on_io_nmi",
800 .data = &panic_on_io_nmi,
801 .maxlen = sizeof(int),
802 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800803 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700804 },
805 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 .procname = "bootloader_type",
807 .data = &bootloader_type,
808 .maxlen = sizeof (int),
809 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800810 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100812 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700813 .procname = "bootloader_version",
814 .data = &bootloader_version,
815 .maxlen = sizeof (int),
816 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800817 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700818 },
819 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100820 .procname = "kstack_depth_to_print",
821 .data = &kstack_depth_to_print,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800824 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100825 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100826 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100827 .procname = "io_delay_type",
828 .data = &io_delay_type,
829 .maxlen = sizeof(int),
830 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800831 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100832 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800834#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 .procname = "randomize_va_space",
837 .data = &randomize_va_space,
838 .maxlen = sizeof(int),
839 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800840 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800842#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800843#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700844 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700845 .procname = "spin_retry",
846 .data = &spin_retry,
847 .maxlen = sizeof (int),
848 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800849 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700850 },
851#endif
Len Brown673d5b42007-07-28 03:33:16 -0400852#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800853 {
Pavel Machekc255d842006-02-20 18:27:58 -0800854 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700855 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800856 .maxlen = sizeof (unsigned long),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800859 },
860#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800861#ifdef CONFIG_IA64
862 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800863 .procname = "ignore-unaligned-usertrap",
864 .data = &no_unaligned_warning,
865 .maxlen = sizeof (int),
866 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800867 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800868 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800869 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800870 .procname = "unaligned-dump-stack",
871 .data = &unaligned_dump_stack,
872 .maxlen = sizeof (int),
873 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800874 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800875 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800876#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800877#ifdef CONFIG_DETECT_HUNG_TASK
878 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800879 .procname = "hung_task_panic",
880 .data = &sysctl_hung_task_panic,
881 .maxlen = sizeof(int),
882 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800883 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800884 .extra1 = &zero,
885 .extra2 = &one,
886 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100887 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100888 .procname = "hung_task_check_count",
889 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100890 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100891 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800892 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100893 },
894 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100895 .procname = "hung_task_timeout_secs",
896 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100897 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100898 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800899 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100900 },
901 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100902 .procname = "hung_task_warnings",
903 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100904 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100905 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800906 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100907 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700908#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200909#ifdef CONFIG_COMPAT
910 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200911 .procname = "compat-log",
912 .data = &compat_log,
913 .maxlen = sizeof (int),
914 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800915 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200916 },
917#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700918#ifdef CONFIG_RT_MUTEXES
919 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700920 .procname = "max_lock_depth",
921 .data = &max_lock_depth,
922 .maxlen = sizeof(int),
923 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800924 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700925 },
926#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700927 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700928 .procname = "poweroff_cmd",
929 .data = &poweroff_cmd,
930 .maxlen = POWEROFF_CMD_PATH_LEN,
931 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800932 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700933 },
David Howells0b77f5b2008-04-29 01:01:32 -0700934#ifdef CONFIG_KEYS
935 {
David Howells0b77f5b2008-04-29 01:01:32 -0700936 .procname = "keys",
937 .mode = 0555,
938 .child = key_sysctls,
939 },
940#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700941#ifdef CONFIG_RCU_TORTURE_TEST
942 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700943 .procname = "rcutorture_runnable",
944 .data = &rcutorture_runnable,
945 .maxlen = sizeof(int),
946 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800947 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700948 },
949#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200950#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -0400951 /*
952 * User-space scripts rely on the existence of this file
953 * as a feature check for perf_events being enabled.
954 *
955 * So it's an ABI, do not remove!
956 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200957 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200958 .procname = "perf_event_paranoid",
959 .data = &sysctl_perf_event_paranoid,
960 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200961 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800962 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200963 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200964 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200965 .procname = "perf_event_mlock_kb",
966 .data = &sysctl_perf_event_mlock,
967 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200968 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800969 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200970 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200971 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200972 .procname = "perf_event_max_sample_rate",
973 .data = &sysctl_perf_event_sample_rate,
974 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200975 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100976 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200977 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200978#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200979#ifdef CONFIG_KMEMCHECK
980 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200981 .procname = "kmemcheck",
982 .data = &kmemcheck_enabled,
983 .maxlen = sizeof(int),
984 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800985 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200986 },
987#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200988#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200989 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200990 .procname = "blk_iopoll",
991 .data = &blk_iopoll_enabled,
992 .maxlen = sizeof(int),
993 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800994 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200995 },
Jens Axboecb684b52009-09-15 21:53:11 +0200996#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700997 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998};
999
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001000static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 .procname = "overcommit_memory",
1003 .data = &sysctl_overcommit_memory,
1004 .maxlen = sizeof(sysctl_overcommit_memory),
1005 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001006 .proc_handler = proc_dointvec_minmax,
1007 .extra1 = &zero,
1008 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 },
1010 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001011 .procname = "panic_on_oom",
1012 .data = &sysctl_panic_on_oom,
1013 .maxlen = sizeof(sysctl_panic_on_oom),
1014 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001015 .proc_handler = proc_dointvec_minmax,
1016 .extra1 = &zero,
1017 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001018 },
1019 {
David Rientjesfe071d72007-10-16 23:25:56 -07001020 .procname = "oom_kill_allocating_task",
1021 .data = &sysctl_oom_kill_allocating_task,
1022 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1023 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001024 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001025 },
1026 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001027 .procname = "oom_dump_tasks",
1028 .data = &sysctl_oom_dump_tasks,
1029 .maxlen = sizeof(sysctl_oom_dump_tasks),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001032 },
1033 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 .procname = "overcommit_ratio",
1035 .data = &sysctl_overcommit_ratio,
1036 .maxlen = sizeof(sysctl_overcommit_ratio),
1037 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001038 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 },
1040 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 .procname = "page-cluster",
1042 .data = &page_cluster,
1043 .maxlen = sizeof(int),
1044 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001045 .proc_handler = proc_dointvec_minmax,
1046 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 },
1048 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 .procname = "dirty_background_ratio",
1050 .data = &dirty_background_ratio,
1051 .maxlen = sizeof(dirty_background_ratio),
1052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 .extra1 = &zero,
1055 .extra2 = &one_hundred,
1056 },
1057 {
David Rientjes2da02992009-01-06 14:39:31 -08001058 .procname = "dirty_background_bytes",
1059 .data = &dirty_background_bytes,
1060 .maxlen = sizeof(dirty_background_bytes),
1061 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001062 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001063 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001064 },
1065 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 .procname = "dirty_ratio",
1067 .data = &vm_dirty_ratio,
1068 .maxlen = sizeof(vm_dirty_ratio),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .extra1 = &zero,
1072 .extra2 = &one_hundred,
1073 },
1074 {
David Rientjes2da02992009-01-06 14:39:31 -08001075 .procname = "dirty_bytes",
1076 .data = &vm_dirty_bytes,
1077 .maxlen = sizeof(vm_dirty_bytes),
1078 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001079 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001080 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001081 },
1082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001084 .data = &dirty_writeback_interval,
1085 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 },
1089 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001091 .data = &dirty_expire_interval,
1092 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001094 .proc_handler = proc_dointvec_minmax,
1095 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 },
1097 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 .procname = "nr_pdflush_threads",
1099 .data = &nr_pdflush_threads,
1100 .maxlen = sizeof nr_pdflush_threads,
1101 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001102 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 },
1104 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 .procname = "swappiness",
1106 .data = &vm_swappiness,
1107 .maxlen = sizeof(vm_swappiness),
1108 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001109 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .extra1 = &zero,
1111 .extra2 = &one_hundred,
1112 },
1113#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001114 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001116 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 .maxlen = sizeof(unsigned long),
1118 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001119 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 .extra1 = (void *)&hugetlb_zero,
1121 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001122 },
1123#ifdef CONFIG_NUMA
1124 {
1125 .procname = "nr_hugepages_mempolicy",
1126 .data = NULL,
1127 .maxlen = sizeof(unsigned long),
1128 .mode = 0644,
1129 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1130 .extra1 = (void *)&hugetlb_zero,
1131 .extra2 = (void *)&hugetlb_infinity,
1132 },
1133#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 .procname = "hugetlb_shm_group",
1136 .data = &sysctl_hugetlb_shm_group,
1137 .maxlen = sizeof(gid_t),
1138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 },
Mel Gorman396faf02007-07-17 04:03:13 -07001141 {
Mel Gorman396faf02007-07-17 04:03:13 -07001142 .procname = "hugepages_treat_as_movable",
1143 .data = &hugepages_treat_as_movable,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001146 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001147 },
Adam Litke54f9f802007-10-16 01:26:20 -07001148 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001149 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001150 .data = NULL,
1151 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001152 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001153 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001154 .extra1 = (void *)&hugetlb_zero,
1155 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001156 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157#endif
1158 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 .procname = "lowmem_reserve_ratio",
1160 .data = &sysctl_lowmem_reserve_ratio,
1161 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1162 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001163 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 },
1165 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001166 .procname = "drop_caches",
1167 .data = &sysctl_drop_caches,
1168 .maxlen = sizeof(int),
1169 .mode = 0644,
1170 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001171 .extra1 = &one,
1172 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001173 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001174#ifdef CONFIG_COMPACTION
1175 {
1176 .procname = "compact_memory",
1177 .data = &sysctl_compact_memory,
1178 .maxlen = sizeof(int),
1179 .mode = 0200,
1180 .proc_handler = sysctl_compaction_handler,
1181 },
Mel Gorman5e771902010-05-24 14:32:31 -07001182 {
1183 .procname = "extfrag_threshold",
1184 .data = &sysctl_extfrag_threshold,
1185 .maxlen = sizeof(int),
1186 .mode = 0644,
1187 .proc_handler = sysctl_extfrag_handler,
1188 .extra1 = &min_extfrag_threshold,
1189 .extra2 = &max_extfrag_threshold,
1190 },
1191
Mel Gorman76ab0f52010-05-24 14:32:28 -07001192#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .procname = "min_free_kbytes",
1195 .data = &min_free_kbytes,
1196 .maxlen = sizeof(min_free_kbytes),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 .extra1 = &zero,
1200 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001201 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001202 .procname = "percpu_pagelist_fraction",
1203 .data = &percpu_pagelist_fraction,
1204 .maxlen = sizeof(percpu_pagelist_fraction),
1205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001207 .extra1 = &min_percpu_pagelist_fract,
1208 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209#ifdef CONFIG_MMU
1210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .procname = "max_map_count",
1212 .data = &sysctl_max_map_count,
1213 .maxlen = sizeof(sysctl_max_map_count),
1214 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001215 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001216 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001218#else
1219 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001220 .procname = "nr_trim_pages",
1221 .data = &sysctl_nr_trim_pages,
1222 .maxlen = sizeof(sysctl_nr_trim_pages),
1223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001224 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001225 .extra1 = &zero,
1226 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227#endif
1228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 .procname = "laptop_mode",
1230 .data = &laptop_mode,
1231 .maxlen = sizeof(laptop_mode),
1232 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001233 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 },
1235 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 .procname = "block_dump",
1237 .data = &block_dump,
1238 .maxlen = sizeof(block_dump),
1239 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001240 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 .extra1 = &zero,
1242 },
1243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 .procname = "vfs_cache_pressure",
1245 .data = &sysctl_vfs_cache_pressure,
1246 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1247 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001248 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 .extra1 = &zero,
1250 },
1251#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1252 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 .procname = "legacy_va_layout",
1254 .data = &sysctl_legacy_va_layout,
1255 .maxlen = sizeof(sysctl_legacy_va_layout),
1256 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001257 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 .extra1 = &zero,
1259 },
1260#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001261#ifdef CONFIG_NUMA
1262 {
Christoph Lameter17436602006-01-18 17:42:32 -08001263 .procname = "zone_reclaim_mode",
1264 .data = &zone_reclaim_mode,
1265 .maxlen = sizeof(zone_reclaim_mode),
1266 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001267 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001268 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001269 },
Christoph Lameter96146342006-07-03 00:24:13 -07001270 {
Christoph Lameter96146342006-07-03 00:24:13 -07001271 .procname = "min_unmapped_ratio",
1272 .data = &sysctl_min_unmapped_ratio,
1273 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1274 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001275 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001276 .extra1 = &zero,
1277 .extra2 = &one_hundred,
1278 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001279 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001280 .procname = "min_slab_ratio",
1281 .data = &sysctl_min_slab_ratio,
1282 .maxlen = sizeof(sysctl_min_slab_ratio),
1283 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001284 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001285 .extra1 = &zero,
1286 .extra2 = &one_hundred,
1287 },
Christoph Lameter17436602006-01-18 17:42:32 -08001288#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001289#ifdef CONFIG_SMP
1290 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001291 .procname = "stat_interval",
1292 .data = &sysctl_stat_interval,
1293 .maxlen = sizeof(sysctl_stat_interval),
1294 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001295 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001296 },
1297#endif
David Howells6e141542009-12-15 19:27:45 +00001298#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001299 {
Eric Parised032182007-06-28 15:55:21 -04001300 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001301 .data = &dac_mmap_min_addr,
1302 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001303 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001304 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001305 },
David Howells6e141542009-12-15 19:27:45 +00001306#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001307#ifdef CONFIG_NUMA
1308 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001309 .procname = "numa_zonelist_order",
1310 .data = &numa_zonelist_order,
1311 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1312 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001313 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001314 },
1315#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001316#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001317 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001318 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001319 .procname = "vdso_enabled",
1320 .data = &vdso_enabled,
1321 .maxlen = sizeof(vdso_enabled),
1322 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001323 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001324 .extra1 = &zero,
1325 },
1326#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001327#ifdef CONFIG_HIGHMEM
1328 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001329 .procname = "highmem_is_dirtyable",
1330 .data = &vm_highmem_is_dirtyable,
1331 .maxlen = sizeof(vm_highmem_is_dirtyable),
1332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001333 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001334 .extra1 = &zero,
1335 .extra2 = &one,
1336 },
1337#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001338 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001339 .procname = "scan_unevictable_pages",
1340 .data = &scan_unevictable_pages,
1341 .maxlen = sizeof(scan_unevictable_pages),
1342 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001343 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001344 },
Andi Kleen6a460792009-09-16 11:50:15 +02001345#ifdef CONFIG_MEMORY_FAILURE
1346 {
Andi Kleen6a460792009-09-16 11:50:15 +02001347 .procname = "memory_failure_early_kill",
1348 .data = &sysctl_memory_failure_early_kill,
1349 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1350 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001351 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001352 .extra1 = &zero,
1353 .extra2 = &one,
1354 },
1355 {
Andi Kleen6a460792009-09-16 11:50:15 +02001356 .procname = "memory_failure_recovery",
1357 .data = &sysctl_memory_failure_recovery,
1358 .maxlen = sizeof(sysctl_memory_failure_recovery),
1359 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001360 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001361 .extra1 = &zero,
1362 .extra2 = &one,
1363 },
1364#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001365 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366};
1367
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001368#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001369static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001370 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001371};
1372#endif
1373
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001374static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .procname = "inode-nr",
1377 .data = &inodes_stat,
1378 .maxlen = 2*sizeof(int),
1379 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001380 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "inode-state",
1384 .data = &inodes_stat,
1385 .maxlen = 7*sizeof(int),
1386 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001387 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "file-nr",
1391 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001392 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 },
1396 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 .procname = "file-max",
1398 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001399 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001401 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 },
1403 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001404 .procname = "nr_open",
1405 .data = &sysctl_nr_open,
1406 .maxlen = sizeof(int),
1407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001408 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001409 .extra1 = &sysctl_nr_open_min,
1410 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001411 },
1412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 .procname = "dentry-state",
1414 .data = &dentry_stat,
1415 .maxlen = 6*sizeof(int),
1416 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001417 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 },
1419 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 .procname = "overflowuid",
1421 .data = &fs_overflowuid,
1422 .maxlen = sizeof(int),
1423 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001424 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 .extra1 = &minolduid,
1426 .extra2 = &maxolduid,
1427 },
1428 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 .procname = "overflowgid",
1430 .data = &fs_overflowgid,
1431 .maxlen = sizeof(int),
1432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001433 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 .extra1 = &minolduid,
1435 .extra2 = &maxolduid,
1436 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001437#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 .procname = "leases-enable",
1440 .data = &leases_enable,
1441 .maxlen = sizeof(int),
1442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001443 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001445#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446#ifdef CONFIG_DNOTIFY
1447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .procname = "dir-notify-enable",
1449 .data = &dir_notify_enable,
1450 .maxlen = sizeof(int),
1451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001452 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 },
1454#endif
1455#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001456#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 .procname = "lease-break-time",
1459 .data = &lease_break_time,
1460 .maxlen = sizeof(int),
1461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001462 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001464#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001465#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 .procname = "aio-nr",
1468 .data = &aio_nr,
1469 .maxlen = sizeof(aio_nr),
1470 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001471 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 },
1473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 .procname = "aio-max-nr",
1475 .data = &aio_max_nr,
1476 .maxlen = sizeof(aio_max_nr),
1477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001478 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001480#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001481#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001482 {
Robert Love0399cb02005-07-13 12:38:18 -04001483 .procname = "inotify",
1484 .mode = 0555,
1485 .child = inotify_table,
1486 },
1487#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001488#ifdef CONFIG_EPOLL
1489 {
1490 .procname = "epoll",
1491 .mode = 0555,
1492 .child = epoll_table,
1493 },
1494#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001496 {
Alan Coxd6e71142005-06-23 00:09:43 -07001497 .procname = "suid_dumpable",
1498 .data = &suid_dumpable,
1499 .maxlen = sizeof(int),
1500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001501 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001502 .extra1 = &zero,
1503 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001504 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001505#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1506 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001507 .procname = "binfmt_misc",
1508 .mode = 0555,
1509 .child = binfmt_misc_table,
1510 },
1511#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001512 {
Jens Axboeff9da692010-06-03 14:54:39 +02001513 .procname = "pipe-max-size",
1514 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001515 .maxlen = sizeof(int),
1516 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001517 .proc_handler = &pipe_proc_fn,
1518 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001519 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001520 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521};
1522
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001523static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001524#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
Chris Metcalf571d76a2011-05-16 14:23:44 -04001525 defined(CONFIG_S390) || defined(CONFIG_TILE)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001526 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001527 .procname = "exception-trace",
1528 .data = &show_unhandled_signals,
1529 .maxlen = sizeof(int),
1530 .mode = 0644,
1531 .proc_handler = proc_dointvec
1532 },
1533#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001534#if defined(CONFIG_OPTPROBES)
1535 {
1536 .procname = "kprobes-optimization",
1537 .data = &sysctl_kprobes_optimization,
1538 .maxlen = sizeof(int),
1539 .mode = 0644,
1540 .proc_handler = proc_kprobes_optimization_handler,
1541 .extra1 = &zero,
1542 .extra2 = &one,
1543 },
1544#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001545 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546};
1547
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001548static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001549 { }
Robert Love0eeca282005-07-12 17:06:03 -04001550};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Al Viro330d57f2005-11-04 10:18:40 +00001552static DEFINE_SPINLOCK(sysctl_lock);
1553
1554/* called under sysctl_lock */
1555static int use_table(struct ctl_table_header *p)
1556{
1557 if (unlikely(p->unregistering))
1558 return 0;
1559 p->used++;
1560 return 1;
1561}
1562
1563/* called under sysctl_lock */
1564static void unuse_table(struct ctl_table_header *p)
1565{
1566 if (!--p->used)
1567 if (unlikely(p->unregistering))
1568 complete(p->unregistering);
1569}
1570
1571/* called under sysctl_lock, will reacquire if has to wait */
1572static void start_unregistering(struct ctl_table_header *p)
1573{
1574 /*
1575 * if p->used is 0, nobody will ever touch that entry again;
1576 * we'll eliminate all paths to it before dropping sysctl_lock
1577 */
1578 if (unlikely(p->used)) {
1579 struct completion wait;
1580 init_completion(&wait);
1581 p->unregistering = &wait;
1582 spin_unlock(&sysctl_lock);
1583 wait_for_completion(&wait);
1584 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001585 } else {
1586 /* anything non-NULL; we'll never dereference it */
1587 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001588 }
1589 /*
1590 * do not remove from the list until nobody holds it; walking the
1591 * list in do_sysctl() relies on that.
1592 */
1593 list_del_init(&p->ctl_entry);
1594}
1595
Al Virof7e6ced2008-07-15 01:44:23 -04001596void sysctl_head_get(struct ctl_table_header *head)
1597{
1598 spin_lock(&sysctl_lock);
1599 head->count++;
1600 spin_unlock(&sysctl_lock);
1601}
1602
1603void sysctl_head_put(struct ctl_table_header *head)
1604{
1605 spin_lock(&sysctl_lock);
1606 if (!--head->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001607 kfree_rcu(head, rcu);
Al Virof7e6ced2008-07-15 01:44:23 -04001608 spin_unlock(&sysctl_lock);
1609}
1610
1611struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1612{
1613 if (!head)
1614 BUG();
1615 spin_lock(&sysctl_lock);
1616 if (!use_table(head))
1617 head = ERR_PTR(-ENOENT);
1618 spin_unlock(&sysctl_lock);
1619 return head;
1620}
1621
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001622void sysctl_head_finish(struct ctl_table_header *head)
1623{
1624 if (!head)
1625 return;
1626 spin_lock(&sysctl_lock);
1627 unuse_table(head);
1628 spin_unlock(&sysctl_lock);
1629}
1630
Al Viro73455092008-07-14 21:22:20 -04001631static struct ctl_table_set *
1632lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1633{
1634 struct ctl_table_set *set = &root->default_set;
1635 if (root->lookup)
1636 set = root->lookup(root, namespaces);
1637 return set;
1638}
1639
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001640static struct list_head *
1641lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001642{
Al Viro73455092008-07-14 21:22:20 -04001643 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1644 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001645}
1646
1647struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1648 struct ctl_table_header *prev)
1649{
1650 struct ctl_table_root *root;
1651 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001652 struct ctl_table_header *head;
1653 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001654
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001655 spin_lock(&sysctl_lock);
1656 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001657 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001658 tmp = &prev->ctl_entry;
1659 unuse_table(prev);
1660 goto next;
1661 }
1662 tmp = &root_table_header.ctl_entry;
1663 for (;;) {
1664 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1665
1666 if (!use_table(head))
1667 goto next;
1668 spin_unlock(&sysctl_lock);
1669 return head;
1670 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001671 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001672 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001673 header_list = lookup_header_list(root, namespaces);
1674 if (tmp != header_list)
1675 continue;
1676
1677 do {
1678 root = list_entry(root->root_list.next,
1679 struct ctl_table_root, root_list);
1680 if (root == &sysctl_table_root)
1681 goto out;
1682 header_list = lookup_header_list(root, namespaces);
1683 } while (list_empty(header_list));
1684 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001685 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001686out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001687 spin_unlock(&sysctl_lock);
1688 return NULL;
1689}
1690
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001691struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1692{
1693 return __sysctl_head_next(current->nsproxy, prev);
1694}
1695
1696void register_sysctl_root(struct ctl_table_root *root)
1697{
1698 spin_lock(&sysctl_lock);
1699 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1700 spin_unlock(&sysctl_lock);
1701}
1702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001704 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 * some sysctl variables are readonly even to root.
1706 */
1707
1708static int test_perm(int mode, int op)
1709{
David Howells76aac0e2008-11-14 10:39:12 +11001710 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 mode >>= 6;
1712 else if (in_egroup_p(0))
1713 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001714 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 return 0;
1716 return -EACCES;
1717}
1718
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001719int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001721 int mode;
1722
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001723 if (root->permissions)
1724 mode = root->permissions(root, current->nsproxy, table);
1725 else
1726 mode = table->mode;
1727
1728 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729}
1730
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001731static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1732{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001733 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001734 table->parent = parent;
1735 if (table->child)
1736 sysctl_set_parent(table, table->child);
1737 }
1738}
1739
1740static __init int sysctl_init(void)
1741{
1742 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001743#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001744 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001745#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001746 return 0;
1747}
1748
1749core_initcall(sysctl_init);
1750
Al Virobfbcf032008-07-27 06:31:22 +01001751static struct ctl_table *is_branch_in(struct ctl_table *branch,
1752 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001753{
1754 struct ctl_table *p;
1755 const char *s = branch->procname;
1756
1757 /* branch should have named subdirectory as its first element */
1758 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001759 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001760
1761 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001762 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001763 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001764
1765 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001766 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001767 if (!p->child)
1768 continue;
1769 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001770 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001771 }
Al Virobfbcf032008-07-27 06:31:22 +01001772 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001773}
1774
1775/* see if attaching q to p would be an improvement */
1776static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1777{
1778 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001779 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001780 int is_better = 0;
1781 int not_in_parent = !p->attached_by;
1782
Al Virobfbcf032008-07-27 06:31:22 +01001783 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001784 if (by == q->attached_by)
1785 is_better = 1;
1786 if (to == p->attached_by)
1787 not_in_parent = 1;
1788 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001789 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001790 }
1791
1792 if (is_better && not_in_parent) {
1793 q->attached_by = by;
1794 q->attached_to = to;
1795 q->parent = p;
1796 }
1797}
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001800 * __register_sysctl_paths - register a sysctl hierarchy
1801 * @root: List of sysctl headers to register on
1802 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001803 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 *
1806 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001807 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001809 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1812 * enter a sysctl file
1813 *
1814 * data - a pointer to data for use by proc_handler
1815 *
1816 * maxlen - the maximum size in bytes of the data
1817 *
1818 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1819 *
1820 * child - a pointer to the child sysctl table if this entry is a directory, or
1821 * %NULL.
1822 *
1823 * proc_handler - the text handler routine (described below)
1824 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 * de - for internal use by the sysctl routines
1826 *
1827 * extra1, extra2 - extra pointers usable by the proc handler routines
1828 *
1829 * Leaf nodes in the sysctl tree will be represented by a single file
1830 * under /proc; non-leaf nodes will be represented by directories.
1831 *
1832 * sysctl(2) can automatically manage read and write requests through
1833 * the sysctl table. The data and maxlen fields of the ctl_table
1834 * struct enable minimal validation of the values being written to be
1835 * performed, and the mode field allows minimal authentication.
1836 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 * There must be a proc_handler routine for any terminal nodes
1838 * mirrored under /proc/sys (non-terminals are handled by a built-in
1839 * directory handler). Several default handlers are available to
1840 * cover common cases -
1841 *
1842 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1843 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1844 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1845 *
1846 * It is the handler's job to read the input buffer from user memory
1847 * and process it. The handler should return 0 on success.
1848 *
1849 * This routine returns %NULL on a failure to register, and a pointer
1850 * to the table header on success.
1851 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001852struct ctl_table_header *__register_sysctl_paths(
1853 struct ctl_table_root *root,
1854 struct nsproxy *namespaces,
1855 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001857 struct ctl_table_header *header;
1858 struct ctl_table *new, **prevp;
1859 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001860 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001861
1862 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001863 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864 ;
1865
1866 /*
1867 * For each path component, allocate a 2-element ctl_table array.
1868 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001869 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001870 *
1871 * We allocate everything in one go so that we don't have to
1872 * worry about freeing additional memory in unregister_sysctl_table.
1873 */
1874 header = kzalloc(sizeof(struct ctl_table_header) +
1875 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1876 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001878
1879 new = (struct ctl_table *) (header + 1);
1880
1881 /* Now connect the dots */
1882 prevp = &header->ctl_table;
1883 for (n = 0; n < npath; ++n, ++path) {
1884 /* Copy the procname */
1885 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001886 new->mode = 0555;
1887
1888 *prevp = new;
1889 prevp = &new->child;
1890
1891 new += 2;
1892 }
1893 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001894 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001895
1896 INIT_LIST_HEAD(&header->ctl_entry);
1897 header->used = 0;
1898 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001899 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001900 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001901 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001902#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001903 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001904 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001905 return NULL;
1906 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001907#endif
Al Viro330d57f2005-11-04 10:18:40 +00001908 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001909 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001910 header->attached_by = header->ctl_table;
1911 header->attached_to = root_table;
1912 header->parent = &root_table_header;
1913 for (set = header->set; set; set = set->parent) {
1914 struct ctl_table_header *p;
1915 list_for_each_entry(p, &set->list, ctl_entry) {
1916 if (p->unregistering)
1917 continue;
1918 try_attach(p, header);
1919 }
1920 }
1921 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001922 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001923 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001924
1925 return header;
1926}
1927
1928/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001929 * register_sysctl_table_path - register a sysctl table hierarchy
1930 * @path: The path to the directory the sysctl table is in.
1931 * @table: the top-level table structure
1932 *
1933 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1934 * array. A completely 0 filled entry terminates the table.
1935 *
1936 * See __register_sysctl_paths for more details.
1937 */
1938struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1939 struct ctl_table *table)
1940{
1941 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1942 path, table);
1943}
1944
1945/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001946 * register_sysctl_table - register a sysctl table hierarchy
1947 * @table: the top-level table structure
1948 *
1949 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1950 * array. A completely 0 filled entry terminates the table.
1951 *
1952 * See register_sysctl_paths for more details.
1953 */
1954struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1955{
1956 static const struct ctl_path null_path[] = { {} };
1957
1958 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959}
1960
1961/**
1962 * unregister_sysctl_table - unregister a sysctl table hierarchy
1963 * @header: the header returned from register_sysctl_table
1964 *
1965 * Unregisters the sysctl table and all children. proc entries may not
1966 * actually be removed until they are no longer used by anyone.
1967 */
1968void unregister_sysctl_table(struct ctl_table_header * header)
1969{
Al Viro330d57f2005-11-04 10:18:40 +00001970 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001971
1972 if (header == NULL)
1973 return;
1974
Al Viro330d57f2005-11-04 10:18:40 +00001975 spin_lock(&sysctl_lock);
1976 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001977 if (!--header->parent->count) {
1978 WARN_ON(1);
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001979 kfree_rcu(header->parent, rcu);
Al Viroae7edec2008-07-15 06:33:31 -04001980 }
Al Virof7e6ced2008-07-15 01:44:23 -04001981 if (!--header->count)
Paul E. McKenneya95cded2011-05-01 23:21:00 -07001982 kfree_rcu(header, rcu);
Al Viro330d57f2005-11-04 10:18:40 +00001983 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984}
1985
Al Viro9043476f2008-07-15 08:54:06 -04001986int sysctl_is_seen(struct ctl_table_header *p)
1987{
1988 struct ctl_table_set *set = p->set;
1989 int res;
1990 spin_lock(&sysctl_lock);
1991 if (p->unregistering)
1992 res = 0;
1993 else if (!set->is_seen)
1994 res = 1;
1995 else
1996 res = set->is_seen(set);
1997 spin_unlock(&sysctl_lock);
1998 return res;
1999}
2000
Al Viro73455092008-07-14 21:22:20 -04002001void setup_sysctl_set(struct ctl_table_set *p,
2002 struct ctl_table_set *parent,
2003 int (*is_seen)(struct ctl_table_set *))
2004{
2005 INIT_LIST_HEAD(&p->list);
2006 p->parent = parent ? parent : &sysctl_table_root.default_set;
2007 p->is_seen = is_seen;
2008}
2009
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002010#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002011struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002012{
2013 return NULL;
2014}
2015
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002016struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2017 struct ctl_table *table)
2018{
2019 return NULL;
2020}
2021
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002022void unregister_sysctl_table(struct ctl_table_header * table)
2023{
2024}
2025
Al Viro73455092008-07-14 21:22:20 -04002026void setup_sysctl_set(struct ctl_table_set *p,
2027 struct ctl_table_set *parent,
2028 int (*is_seen)(struct ctl_table_set *))
2029{
2030}
2031
Al Virof7e6ced2008-07-15 01:44:23 -04002032void sysctl_head_put(struct ctl_table_header *head)
2033{
2034}
2035
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002036#endif /* CONFIG_SYSCTL */
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038/*
2039 * /proc/sys support
2040 */
2041
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002042#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002044static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002045 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002046 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002047{
2048 size_t len;
2049 char __user *p;
2050 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002051
2052 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002053 *lenp = 0;
2054 return 0;
2055 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002056
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002057 if (write) {
2058 len = 0;
2059 p = buffer;
2060 while (len < *lenp) {
2061 if (get_user(c, p++))
2062 return -EFAULT;
2063 if (c == 0 || c == '\n')
2064 break;
2065 len++;
2066 }
2067 if (len >= maxlen)
2068 len = maxlen-1;
2069 if(copy_from_user(data, buffer, len))
2070 return -EFAULT;
2071 ((char *) data)[len] = 0;
2072 *ppos += *lenp;
2073 } else {
2074 len = strlen(data);
2075 if (len > maxlen)
2076 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002077
2078 if (*ppos > len) {
2079 *lenp = 0;
2080 return 0;
2081 }
2082
2083 data += *ppos;
2084 len -= *ppos;
2085
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002086 if (len > *lenp)
2087 len = *lenp;
2088 if (len)
2089 if(copy_to_user(buffer, data, len))
2090 return -EFAULT;
2091 if (len < *lenp) {
2092 if(put_user('\n', ((char __user *) buffer) + len))
2093 return -EFAULT;
2094 len++;
2095 }
2096 *lenp = len;
2097 *ppos += len;
2098 }
2099 return 0;
2100}
2101
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102/**
2103 * proc_dostring - read a string sysctl
2104 * @table: the sysctl table
2105 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 * @buffer: the user buffer
2107 * @lenp: the size of the user buffer
2108 * @ppos: file position
2109 *
2110 * Reads/writes a string from/to the user buffer. If the kernel
2111 * buffer provided is not large enough to hold the string, the
2112 * string is truncated. The copied string is %NULL-terminated.
2113 * If the string is being read by the user process, it is copied
2114 * and a newline '\n' is added. It is truncated if the buffer is
2115 * not large enough.
2116 *
2117 * Returns 0 on success.
2118 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002119int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 void __user *buffer, size_t *lenp, loff_t *ppos)
2121{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002122 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002123 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
Amerigo Wang00b7c332010-05-05 00:26:45 +00002126static size_t proc_skip_spaces(char **buf)
2127{
2128 size_t ret;
2129 char *tmp = skip_spaces(*buf);
2130 ret = tmp - *buf;
2131 *buf = tmp;
2132 return ret;
2133}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002135static void proc_skip_char(char **buf, size_t *size, const char v)
2136{
2137 while (*size) {
2138 if (**buf != v)
2139 break;
2140 (*size)--;
2141 (*buf)++;
2142 }
2143}
2144
Amerigo Wang00b7c332010-05-05 00:26:45 +00002145#define TMPBUFLEN 22
2146/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002147 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002148 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002149 * @buf: a kernel buffer
2150 * @size: size of the kernel buffer
2151 * @val: this is where the number will be stored
2152 * @neg: set to %TRUE if number is negative
2153 * @perm_tr: a vector which contains the allowed trailers
2154 * @perm_tr_len: size of the perm_tr vector
2155 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002156 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002157 * In case of success %0 is returned and @buf and @size are updated with
2158 * the amount of bytes read. If @tr is non-NULL and a trailing
2159 * character exists (size is non-zero after returning from this
2160 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002161 */
2162static int proc_get_long(char **buf, size_t *size,
2163 unsigned long *val, bool *neg,
2164 const char *perm_tr, unsigned perm_tr_len, char *tr)
2165{
2166 int len;
2167 char *p, tmp[TMPBUFLEN];
2168
2169 if (!*size)
2170 return -EINVAL;
2171
2172 len = *size;
2173 if (len > TMPBUFLEN - 1)
2174 len = TMPBUFLEN - 1;
2175
2176 memcpy(tmp, *buf, len);
2177
2178 tmp[len] = 0;
2179 p = tmp;
2180 if (*p == '-' && *size > 1) {
2181 *neg = true;
2182 p++;
2183 } else
2184 *neg = false;
2185 if (!isdigit(*p))
2186 return -EINVAL;
2187
2188 *val = simple_strtoul(p, &p, 0);
2189
2190 len = p - tmp;
2191
2192 /* We don't know if the next char is whitespace thus we may accept
2193 * invalid integers (e.g. 1234...a) or two integers instead of one
2194 * (e.g. 123...1). So lets not allow such large numbers. */
2195 if (len == TMPBUFLEN - 1)
2196 return -EINVAL;
2197
2198 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2199 return -EINVAL;
2200
2201 if (tr && (len < *size))
2202 *tr = *p;
2203
2204 *buf += len;
2205 *size -= len;
2206
2207 return 0;
2208}
2209
2210/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002211 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002212 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002213 * @buf: the user buffer
2214 * @size: the size of the user buffer
2215 * @val: the integer to be converted
2216 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002217 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002218 * In case of success %0 is returned and @buf and @size are updated with
2219 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002220 */
2221static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2222 bool neg)
2223{
2224 int len;
2225 char tmp[TMPBUFLEN], *p = tmp;
2226
2227 sprintf(p, "%s%lu", neg ? "-" : "", val);
2228 len = strlen(tmp);
2229 if (len > *size)
2230 len = *size;
2231 if (copy_to_user(*buf, tmp, len))
2232 return -EFAULT;
2233 *size -= len;
2234 *buf += len;
2235 return 0;
2236}
2237#undef TMPBUFLEN
2238
2239static int proc_put_char(void __user **buf, size_t *size, char c)
2240{
2241 if (*size) {
2242 char __user **buffer = (char __user **)buf;
2243 if (put_user(c, *buffer))
2244 return -EFAULT;
2245 (*size)--, (*buffer)++;
2246 *buf = *buffer;
2247 }
2248 return 0;
2249}
2250
2251static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 int *valp,
2253 int write, void *data)
2254{
2255 if (write) {
2256 *valp = *negp ? -*lvalp : *lvalp;
2257 } else {
2258 int val = *valp;
2259 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002260 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 *lvalp = (unsigned long)-val;
2262 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *lvalp = (unsigned long)val;
2265 }
2266 }
2267 return 0;
2268}
2269
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2271
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002272static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002273 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002274 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002275 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 int write, void *data),
2277 void *data)
2278{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002279 int *i, vleft, first = 1, err = 0;
2280 unsigned long page = 0;
2281 size_t left;
2282 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 *lenp = 0;
2286 return 0;
2287 }
2288
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002289 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 vleft = table->maxlen / sizeof(*i);
2291 left = *lenp;
2292
2293 if (!conv)
2294 conv = do_proc_dointvec_conv;
2295
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002297 if (left > PAGE_SIZE - 1)
2298 left = PAGE_SIZE - 1;
2299 page = __get_free_page(GFP_TEMPORARY);
2300 kbuf = (char *) page;
2301 if (!kbuf)
2302 return -ENOMEM;
2303 if (copy_from_user(kbuf, buffer, left)) {
2304 err = -EFAULT;
2305 goto free;
2306 }
2307 kbuf[left] = 0;
2308 }
2309
2310 for (; left && vleft--; i++, first=0) {
2311 unsigned long lval;
2312 bool neg;
2313
2314 if (write) {
2315 left -= proc_skip_spaces(&kbuf);
2316
J. R. Okajima563b0462010-05-25 16:10:14 -07002317 if (!left)
2318 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002319 err = proc_get_long(&kbuf, &left, &lval, &neg,
2320 proc_wspace_sep,
2321 sizeof(proc_wspace_sep), NULL);
2322 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002324 if (conv(&neg, &lval, i, 1, data)) {
2325 err = -EINVAL;
2326 break;
2327 }
2328 } else {
2329 if (conv(&neg, &lval, i, 0, data)) {
2330 err = -EINVAL;
2331 break;
2332 }
2333 if (!first)
2334 err = proc_put_char(&buffer, &left, '\t');
2335 if (err)
2336 break;
2337 err = proc_put_long(&buffer, &left, lval, neg);
2338 if (err)
2339 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 }
2341 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002342
2343 if (!write && !first && left && !err)
2344 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002345 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002346 left -= proc_skip_spaces(&kbuf);
2347free:
2348 if (write) {
2349 free_page(page);
2350 if (first)
2351 return err ? : -EINVAL;
2352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 *lenp -= left;
2354 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002355 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002358static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002359 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002360 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002361 int write, void *data),
2362 void *data)
2363{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002364 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002365 buffer, lenp, ppos, conv, data);
2366}
2367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368/**
2369 * proc_dointvec - read a vector of integers
2370 * @table: the sysctl table
2371 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 * @buffer: the user buffer
2373 * @lenp: the size of the user buffer
2374 * @ppos: file position
2375 *
2376 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2377 * values from/to the user buffer, treated as an ASCII string.
2378 *
2379 * Returns 0 on success.
2380 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002381int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 void __user *buffer, size_t *lenp, loff_t *ppos)
2383{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002384 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 NULL,NULL);
2386}
2387
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002388/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002389 * Taint values can only be increased
2390 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002391 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002392static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002393 void __user *buffer, size_t *lenp, loff_t *ppos)
2394{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002395 struct ctl_table t;
2396 unsigned long tmptaint = get_taint();
2397 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002398
Bastian Blank91fcd412007-04-23 14:41:14 -07002399 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002400 return -EPERM;
2401
Andi Kleen25ddbb12008-10-15 22:01:41 -07002402 t = *table;
2403 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002404 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002405 if (err < 0)
2406 return err;
2407
2408 if (write) {
2409 /*
2410 * Poor man's atomic or. Not worth adding a primitive
2411 * to everyone's atomic.h for this
2412 */
2413 int i;
2414 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2415 if ((tmptaint >> i) & 1)
2416 add_taint(i);
2417 }
2418 }
2419
2420 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002421}
2422
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002423#ifdef CONFIG_PRINTK
2424static int proc_dmesg_restrict(struct ctl_table *table, int write,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426{
2427 if (write && !capable(CAP_SYS_ADMIN))
2428 return -EPERM;
2429
2430 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2431}
2432#endif
2433
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434struct do_proc_dointvec_minmax_conv_param {
2435 int *min;
2436 int *max;
2437};
2438
Amerigo Wang00b7c332010-05-05 00:26:45 +00002439static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2440 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 int write, void *data)
2442{
2443 struct do_proc_dointvec_minmax_conv_param *param = data;
2444 if (write) {
2445 int val = *negp ? -*lvalp : *lvalp;
2446 if ((param->min && *param->min > val) ||
2447 (param->max && *param->max < val))
2448 return -EINVAL;
2449 *valp = val;
2450 } else {
2451 int val = *valp;
2452 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002453 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 *lvalp = (unsigned long)-val;
2455 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002456 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 *lvalp = (unsigned long)val;
2458 }
2459 }
2460 return 0;
2461}
2462
2463/**
2464 * proc_dointvec_minmax - read a vector of integers with min/max values
2465 * @table: the sysctl table
2466 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
2469 * @ppos: file position
2470 *
2471 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2472 * values from/to the user buffer, treated as an ASCII string.
2473 *
2474 * This routine will ensure the values are within the range specified by
2475 * table->extra1 (min) and table->extra2 (max).
2476 *
2477 * Returns 0 on success.
2478 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002479int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 void __user *buffer, size_t *lenp, loff_t *ppos)
2481{
2482 struct do_proc_dointvec_minmax_conv_param param = {
2483 .min = (int *) table->extra1,
2484 .max = (int *) table->extra2,
2485 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002486 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 do_proc_dointvec_minmax_conv, &param);
2488}
2489
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002490static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 void __user *buffer,
2492 size_t *lenp, loff_t *ppos,
2493 unsigned long convmul,
2494 unsigned long convdiv)
2495{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002496 unsigned long *i, *min, *max;
2497 int vleft, first = 1, err = 0;
2498 unsigned long page = 0;
2499 size_t left;
2500 char *kbuf;
2501
2502 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 *lenp = 0;
2504 return 0;
2505 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002507 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 min = (unsigned long *) table->extra1;
2509 max = (unsigned long *) table->extra2;
2510 vleft = table->maxlen / sizeof(unsigned long);
2511 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002512
2513 if (write) {
2514 if (left > PAGE_SIZE - 1)
2515 left = PAGE_SIZE - 1;
2516 page = __get_free_page(GFP_TEMPORARY);
2517 kbuf = (char *) page;
2518 if (!kbuf)
2519 return -ENOMEM;
2520 if (copy_from_user(kbuf, buffer, left)) {
2521 err = -EFAULT;
2522 goto free;
2523 }
2524 kbuf[left] = 0;
2525 }
2526
Eric Dumazet27b3d802010-10-07 12:59:29 -07002527 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 unsigned long val;
2529
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002531 bool neg;
2532
2533 left -= proc_skip_spaces(&kbuf);
2534
2535 err = proc_get_long(&kbuf, &left, &val, &neg,
2536 proc_wspace_sep,
2537 sizeof(proc_wspace_sep), NULL);
2538 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 break;
2540 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 continue;
2542 if ((min && val < *min) || (max && val > *max))
2543 continue;
2544 *i = val;
2545 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002546 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002548 err = proc_put_char(&buffer, &left, '\t');
2549 err = proc_put_long(&buffer, &left, val, false);
2550 if (err)
2551 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 }
2553 }
2554
Amerigo Wang00b7c332010-05-05 00:26:45 +00002555 if (!write && !first && left && !err)
2556 err = proc_put_char(&buffer, &left, '\n');
2557 if (write && !err)
2558 left -= proc_skip_spaces(&kbuf);
2559free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002561 free_page(page);
2562 if (first)
2563 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 *lenp -= left;
2566 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002567 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002570static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002571 void __user *buffer,
2572 size_t *lenp, loff_t *ppos,
2573 unsigned long convmul,
2574 unsigned long convdiv)
2575{
2576 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002577 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002578}
2579
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580/**
2581 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 * @buffer: the user buffer
2585 * @lenp: the size of the user buffer
2586 * @ppos: file position
2587 *
2588 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2589 * values from/to the user buffer, treated as an ASCII string.
2590 *
2591 * This routine will ensure the values are within the range specified by
2592 * table->extra1 (min) and table->extra2 (max).
2593 *
2594 * Returns 0 on success.
2595 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002596int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 void __user *buffer, size_t *lenp, loff_t *ppos)
2598{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002599 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600}
2601
2602/**
2603 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2604 * @table: the sysctl table
2605 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 * @buffer: the user buffer
2607 * @lenp: the size of the user buffer
2608 * @ppos: file position
2609 *
2610 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2611 * values from/to the user buffer, treated as an ASCII string. The values
2612 * are treated as milliseconds, and converted to jiffies when they are stored.
2613 *
2614 * This routine will ensure the values are within the range specified by
2615 * table->extra1 (min) and table->extra2 (max).
2616 *
2617 * Returns 0 on success.
2618 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002619int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 void __user *buffer,
2621 size_t *lenp, loff_t *ppos)
2622{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002623 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 lenp, ppos, HZ, 1000l);
2625}
2626
2627
Amerigo Wang00b7c332010-05-05 00:26:45 +00002628static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 int *valp,
2630 int write, void *data)
2631{
2632 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002633 if (*lvalp > LONG_MAX / HZ)
2634 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2636 } else {
2637 int val = *valp;
2638 unsigned long lval;
2639 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002640 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 lval = (unsigned long)-val;
2642 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002643 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 lval = (unsigned long)val;
2645 }
2646 *lvalp = lval / HZ;
2647 }
2648 return 0;
2649}
2650
Amerigo Wang00b7c332010-05-05 00:26:45 +00002651static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 int *valp,
2653 int write, void *data)
2654{
2655 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002656 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2657 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2659 } else {
2660 int val = *valp;
2661 unsigned long lval;
2662 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002663 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 lval = (unsigned long)-val;
2665 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002666 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 lval = (unsigned long)val;
2668 }
2669 *lvalp = jiffies_to_clock_t(lval);
2670 }
2671 return 0;
2672}
2673
Amerigo Wang00b7c332010-05-05 00:26:45 +00002674static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 int *valp,
2676 int write, void *data)
2677{
2678 if (write) {
2679 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2680 } else {
2681 int val = *valp;
2682 unsigned long lval;
2683 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002684 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 lval = (unsigned long)-val;
2686 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002687 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 lval = (unsigned long)val;
2689 }
2690 *lvalp = jiffies_to_msecs(lval);
2691 }
2692 return 0;
2693}
2694
2695/**
2696 * proc_dointvec_jiffies - read a vector of integers as seconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2702 *
2703 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2704 * values from/to the user buffer, treated as an ASCII string.
2705 * The values read are assumed to be in seconds, and are converted into
2706 * jiffies.
2707 *
2708 * Returns 0 on success.
2709 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002710int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 void __user *buffer, size_t *lenp, loff_t *ppos)
2712{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002713 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 do_proc_dointvec_jiffies_conv,NULL);
2715}
2716
2717/**
2718 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 * @buffer: the user buffer
2722 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002723 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 *
2725 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2726 * values from/to the user buffer, treated as an ASCII string.
2727 * The values read are assumed to be in 1/USER_HZ seconds, and
2728 * are converted into jiffies.
2729 *
2730 * Returns 0 on success.
2731 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002732int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 void __user *buffer, size_t *lenp, loff_t *ppos)
2734{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 do_proc_dointvec_userhz_jiffies_conv,NULL);
2737}
2738
2739/**
2740 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2741 * @table: the sysctl table
2742 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 * @buffer: the user buffer
2744 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002745 * @ppos: file position
2746 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 *
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in 1/1000 seconds, and
2751 * are converted into jiffies.
2752 *
2753 * Returns 0 on success.
2754 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002755int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 void __user *buffer, size_t *lenp, loff_t *ppos)
2757{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002758 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 do_proc_dointvec_ms_jiffies_conv, NULL);
2760}
2761
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002762static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002763 void __user *buffer, size_t *lenp, loff_t *ppos)
2764{
2765 struct pid *new_pid;
2766 pid_t tmp;
2767 int r;
2768
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002769 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002770
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002771 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002772 lenp, ppos, NULL, NULL);
2773 if (r || !write)
2774 return r;
2775
2776 new_pid = find_get_pid(tmp);
2777 if (!new_pid)
2778 return -ESRCH;
2779
2780 put_pid(xchg(&cad_pid, new_pid));
2781 return 0;
2782}
2783
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002784/**
2785 * proc_do_large_bitmap - read/write from/to a large bitmap
2786 * @table: the sysctl table
2787 * @write: %TRUE if this is a write to the sysctl file
2788 * @buffer: the user buffer
2789 * @lenp: the size of the user buffer
2790 * @ppos: file position
2791 *
2792 * The bitmap is stored at table->data and the bitmap length (in bits)
2793 * in table->maxlen.
2794 *
2795 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2796 * large bitmaps may be represented in a compact manner. Writing into
2797 * the file will clear the bitmap then update it with the given input.
2798 *
2799 * Returns 0 on success.
2800 */
2801int proc_do_large_bitmap(struct ctl_table *table, int write,
2802 void __user *buffer, size_t *lenp, loff_t *ppos)
2803{
2804 int err = 0;
2805 bool first = 1;
2806 size_t left = *lenp;
2807 unsigned long bitmap_len = table->maxlen;
2808 unsigned long *bitmap = (unsigned long *) table->data;
2809 unsigned long *tmp_bitmap = NULL;
2810 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2811
2812 if (!bitmap_len || !left || (*ppos && !write)) {
2813 *lenp = 0;
2814 return 0;
2815 }
2816
2817 if (write) {
2818 unsigned long page = 0;
2819 char *kbuf;
2820
2821 if (left > PAGE_SIZE - 1)
2822 left = PAGE_SIZE - 1;
2823
2824 page = __get_free_page(GFP_TEMPORARY);
2825 kbuf = (char *) page;
2826 if (!kbuf)
2827 return -ENOMEM;
2828 if (copy_from_user(kbuf, buffer, left)) {
2829 free_page(page);
2830 return -EFAULT;
2831 }
2832 kbuf[left] = 0;
2833
2834 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2835 GFP_KERNEL);
2836 if (!tmp_bitmap) {
2837 free_page(page);
2838 return -ENOMEM;
2839 }
2840 proc_skip_char(&kbuf, &left, '\n');
2841 while (!err && left) {
2842 unsigned long val_a, val_b;
2843 bool neg;
2844
2845 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2846 sizeof(tr_a), &c);
2847 if (err)
2848 break;
2849 if (val_a >= bitmap_len || neg) {
2850 err = -EINVAL;
2851 break;
2852 }
2853
2854 val_b = val_a;
2855 if (left) {
2856 kbuf++;
2857 left--;
2858 }
2859
2860 if (c == '-') {
2861 err = proc_get_long(&kbuf, &left, &val_b,
2862 &neg, tr_b, sizeof(tr_b),
2863 &c);
2864 if (err)
2865 break;
2866 if (val_b >= bitmap_len || neg ||
2867 val_a > val_b) {
2868 err = -EINVAL;
2869 break;
2870 }
2871 if (left) {
2872 kbuf++;
2873 left--;
2874 }
2875 }
2876
2877 while (val_a <= val_b)
2878 set_bit(val_a++, tmp_bitmap);
2879
2880 first = 0;
2881 proc_skip_char(&kbuf, &left, '\n');
2882 }
2883 free_page(page);
2884 } else {
2885 unsigned long bit_a, bit_b = 0;
2886
2887 while (left) {
2888 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2889 if (bit_a >= bitmap_len)
2890 break;
2891 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2892 bit_a + 1) - 1;
2893
2894 if (!first) {
2895 err = proc_put_char(&buffer, &left, ',');
2896 if (err)
2897 break;
2898 }
2899 err = proc_put_long(&buffer, &left, bit_a, false);
2900 if (err)
2901 break;
2902 if (bit_a != bit_b) {
2903 err = proc_put_char(&buffer, &left, '-');
2904 if (err)
2905 break;
2906 err = proc_put_long(&buffer, &left, bit_b, false);
2907 if (err)
2908 break;
2909 }
2910
2911 first = 0; bit_b++;
2912 }
2913 if (!err)
2914 err = proc_put_char(&buffer, &left, '\n');
2915 }
2916
2917 if (!err) {
2918 if (write) {
2919 if (*ppos)
2920 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2921 else
2922 memcpy(bitmap, tmp_bitmap,
2923 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2924 }
2925 kfree(tmp_bitmap);
2926 *lenp -= left;
2927 *ppos += *lenp;
2928 return 0;
2929 } else {
2930 kfree(tmp_bitmap);
2931 return err;
2932 }
2933}
2934
Jovi Zhang55610502011-01-12 17:00:45 -08002935#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002937int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 void __user *buffer, size_t *lenp, loff_t *ppos)
2939{
2940 return -ENOSYS;
2941}
2942
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002943int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 void __user *buffer, size_t *lenp, loff_t *ppos)
2945{
2946 return -ENOSYS;
2947}
2948
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002949int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 void __user *buffer, size_t *lenp, loff_t *ppos)
2951{
2952 return -ENOSYS;
2953}
2954
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002955int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 void __user *buffer, size_t *lenp, loff_t *ppos)
2957{
2958 return -ENOSYS;
2959}
2960
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002961int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 void __user *buffer, size_t *lenp, loff_t *ppos)
2963{
2964 return -ENOSYS;
2965}
2966
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002967int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 void __user *buffer, size_t *lenp, loff_t *ppos)
2969{
2970 return -ENOSYS;
2971}
2972
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002973int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 void __user *buffer, size_t *lenp, loff_t *ppos)
2975{
2976 return -ENOSYS;
2977}
2978
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002979int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 void __user *buffer,
2981 size_t *lenp, loff_t *ppos)
2982{
2983 return -ENOSYS;
2984}
2985
2986
Jovi Zhang55610502011-01-12 17:00:45 -08002987#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989/*
2990 * No sense putting this after each symbol definition, twice,
2991 * exception granted :-)
2992 */
2993EXPORT_SYMBOL(proc_dointvec);
2994EXPORT_SYMBOL(proc_dointvec_jiffies);
2995EXPORT_SYMBOL(proc_dointvec_minmax);
2996EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2997EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2998EXPORT_SYMBOL(proc_dostring);
2999EXPORT_SYMBOL(proc_doulongvec_minmax);
3000EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3001EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003002EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003EXPORT_SYMBOL(unregister_sysctl_table);