blob: 99aed9f8ad35cbe2f2195d2fc707ac64a6045d44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/uaccess.h>
61#include <asm/processor.h>
62
Andi Kleen29cbc782006-09-30 01:47:55 +020063#ifdef CONFIG_X86
64#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010065#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010066#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020067#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080068#ifdef CONFIG_BSD_PROCESS_ACCT
69#include <linux/acct.h>
70#endif
Dave Young4f0e0562010-03-10 15:24:09 -080071#ifdef CONFIG_RT_MUTEXES
72#include <linux/rtmutex.h>
73#endif
Dave Young2edf5e42010-03-10 15:24:10 -080074#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75#include <linux/lockdep.h>
76#endif
Dave Young15485a42010-03-10 15:24:07 -080077#ifdef CONFIG_CHR_DEV_SG
78#include <scsi/sg.h>
79#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020080
Don Zickus58687ac2010-05-07 17:11:44 -040081#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050082#include <linux/nmi.h>
83#endif
84
Eric W. Biederman7058cb02007-10-18 03:05:58 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#if defined(CONFIG_SYSCTL)
87
88/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern int sysctl_overcommit_memory;
90extern int sysctl_overcommit_ratio;
91extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070093extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070095extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern int pid_max;
97extern int min_free_kbytes;
Rik van Rieldf695fb2011-09-01 15:26:50 -040098extern int extra_free_kbytes;
Arve Hjønnevåg2a023fb2009-02-17 14:51:02 -080099extern int min_free_order_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -0800101extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800102extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200103extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100104extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400105extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000106#ifndef CONFIG_MMU
107extern int sysctl_nr_trim_pages;
108#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200109#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200110extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400114#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200116static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117#endif
118
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700120static int __maybe_unused one = 1;
121static int __maybe_unused two = 2;
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 Weinberger0fd92112011-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 Virodfef6dc2011-03-08 01:25:28 -0500204 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100205 .ctl_table = root_table,
Al Virodfef6dc2011-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 },
371 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200372 .procname = "sched_compat_yield",
373 .data = &sysctl_sched_compat_yield,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800376 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200377 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100378#ifdef CONFIG_SCHED_AUTOGROUP
379 {
380 .procname = "sched_autogroup_enabled",
381 .data = &sysctl_sched_autogroup_enabled,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = proc_dointvec,
385 .extra1 = &zero,
386 .extra2 = &one,
387 },
388#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700389#ifdef CONFIG_PROVE_LOCKING
390 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700391 .procname = "prove_locking",
392 .data = &prove_locking,
393 .maxlen = sizeof(int),
394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800395 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700396 },
397#endif
398#ifdef CONFIG_LOCK_STAT
399 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700400 .procname = "lock_stat",
401 .data = &lock_stat,
402 .maxlen = sizeof(int),
403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800404 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700405 },
406#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 .procname = "panic",
409 .data = &panic_timeout,
410 .maxlen = sizeof(int),
411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800412 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 },
414 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 .procname = "core_uses_pid",
416 .data = &core_uses_pid,
417 .maxlen = sizeof(int),
418 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800419 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 },
421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .procname = "core_pattern",
423 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700424 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800426 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 },
Neil Hormana2939802009-09-23 15:56:56 -0700428 {
Neil Hormana2939802009-09-23 15:56:56 -0700429 .procname = "core_pipe_limit",
430 .data = &core_pipe_limit,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700434 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800435#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700438 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800442#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100443#ifdef CONFIG_LATENCYTOP
444 {
445 .procname = "latencytop",
446 .data = &latencytop_enabled,
447 .maxlen = sizeof(int),
448 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800449 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100450 },
451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#ifdef CONFIG_BLK_DEV_INITRD
453 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .procname = "real-root-dev",
455 .data = &real_root_dev,
456 .maxlen = sizeof(int),
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 },
460#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700461 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700462 .procname = "print-fatal-signals",
463 .data = &print_fatal_signals,
464 .maxlen = sizeof(int),
465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800466 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700467 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700468#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 .procname = "reboot-cmd",
471 .data = reboot_command,
472 .maxlen = 256,
473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800474 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 },
476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .procname = "stop-a",
478 .data = &stop_a_enabled,
479 .maxlen = sizeof (int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 },
483 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 .procname = "scons-poweroff",
485 .data = &scons_pwroff,
486 .maxlen = sizeof (int),
487 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800488 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 },
490#endif
David S. Miller08714202008-11-16 23:49:24 -0800491#ifdef CONFIG_SPARC64
492 {
David S. Miller08714202008-11-16 23:49:24 -0800493 .procname = "tsb-ratio",
494 .data = &sysctl_tsb_ratio,
495 .maxlen = sizeof (int),
496 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800497 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800498 },
499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#ifdef __hppa__
501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "soft-power",
503 .data = &pwrsw_enabled,
504 .maxlen = sizeof (int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 },
508 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .procname = "unaligned-trap",
510 .data = &unaligned_enabled,
511 .maxlen = sizeof (int),
512 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800513 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 },
515#endif
516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .procname = "ctrl-alt-del",
518 .data = &C_A_D,
519 .maxlen = sizeof(int),
520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800521 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400523#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200524 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200525 .procname = "ftrace_enabled",
526 .data = &ftrace_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800529 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200530 },
531#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500532#ifdef CONFIG_STACK_TRACER
533 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500534 .procname = "stack_tracer_enabled",
535 .data = &stack_tracer_enabled,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800538 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500539 },
540#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400541#ifdef CONFIG_TRACING
542 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100543 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400544 .data = &ftrace_dump_on_oops,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800547 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400548 },
549#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200550#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "modprobe",
553 .data = &modprobe_path,
554 .maxlen = KMOD_PATH_LEN,
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
Kees Cook3d433212009-04-02 15:49:29 -0700558 {
Kees Cook3d433212009-04-02 15:49:29 -0700559 .procname = "modules_disabled",
560 .data = &modules_disabled,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800564 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700565 .extra1 = &one,
566 .extra2 = &one,
567 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100569#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100572 .data = &uevent_helper,
573 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800575 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
577#endif
578#ifdef CONFIG_CHR_DEV_SG
579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "sg-big-buff",
581 .data = &sg_big_buff,
582 .maxlen = sizeof (int),
583 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800584 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
586#endif
587#ifdef CONFIG_BSD_PROCESS_ACCT
588 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 .procname = "acct",
590 .data = &acct_parm,
591 .maxlen = 3*sizeof(int),
592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800593 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 },
595#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#ifdef CONFIG_MAGIC_SYSRQ
597 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800599 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .maxlen = sizeof (int),
601 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700602 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 },
604#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700605#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700608 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .maxlen = sizeof (int),
610 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 .procname = "threads-max",
616 .data = &max_threads,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800619 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 },
621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "random",
623 .mode = 0555,
624 .child = random_table,
625 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 .procname = "overflowuid",
628 .data = &overflowuid,
629 .maxlen = sizeof(int),
630 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800631 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
634 },
635 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .procname = "overflowgid",
637 .data = &overflowgid,
638 .maxlen = sizeof(int),
639 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800640 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .extra1 = &minolduid,
642 .extra2 = &maxolduid,
643 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800644#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#ifdef CONFIG_MATHEMU
646 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .procname = "ieee_emulation_warnings",
648 .data = &sysctl_ieee_emulation_warnings,
649 .maxlen = sizeof(int),
650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 },
653#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200656 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .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
662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .procname = "pid_max",
664 .data = &pid_max,
665 .maxlen = sizeof (int),
666 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800667 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .extra1 = &pid_max_min,
669 .extra2 = &pid_max_max,
670 },
671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 .procname = "panic_on_oops",
673 .data = &panic_on_oops,
674 .maxlen = sizeof(int),
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800678#if defined CONFIG_PRINTK
679 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800680 .procname = "printk",
681 .data = &console_loglevel,
682 .maxlen = 4*sizeof(int),
683 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800684 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800685 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700688 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .maxlen = sizeof(int),
690 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800691 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
693 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700695 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .maxlen = sizeof(int),
697 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800698 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 },
Dave Youngaf913222009-09-22 16:43:33 -0700700 {
Dave Youngaf913222009-09-22 16:43:33 -0700701 .procname = "printk_delay",
702 .data = &printk_delay_msec,
703 .maxlen = sizeof(int),
704 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800705 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700706 .extra1 = &zero,
707 .extra2 = &ten_thousand,
708 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800710 .procname = "dmesg_restrict",
711 .data = &dmesg_restrict,
712 .maxlen = sizeof(int),
713 .mode = 0644,
714 .proc_handler = proc_dointvec_minmax,
715 .extra1 = &zero,
716 .extra2 = &one,
717 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800718 {
719 .procname = "kptr_restrict",
720 .data = &kptr_restrict,
721 .maxlen = sizeof(int),
722 .mode = 0644,
Richard Weinberger0fd92112011-03-23 16:43:11 -0700723 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800724 .extra1 = &zero,
725 .extra2 = &two,
726 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800727#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .procname = "ngroups_max",
730 .data = &ngroups_max,
731 .maxlen = sizeof (int),
732 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800733 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 },
Don Zickus58687ac2010-05-07 17:11:44 -0400735#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500736 {
Don Zickus58687ac2010-05-07 17:11:44 -0400737 .procname = "watchdog",
738 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500739 .maxlen = sizeof (int),
740 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400741 .proc_handler = proc_dowatchdog_enabled,
742 },
743 {
744 .procname = "watchdog_thresh",
745 .data = &softlockup_thresh,
746 .maxlen = sizeof(int),
747 .mode = 0644,
748 .proc_handler = proc_dowatchdog_thresh,
749 .extra1 = &neg_one,
750 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500751 },
Don Zickus2508ce12010-05-07 17:11:46 -0400752 {
753 .procname = "softlockup_panic",
754 .data = &softlockup_panic,
755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = proc_dointvec_minmax,
758 .extra1 = &zero,
759 .extra2 = &one,
760 },
Don Zickus5dc30552010-11-29 17:07:17 -0500761 {
762 .procname = "nmi_watchdog",
763 .data = &watchdog_enabled,
764 .maxlen = sizeof (int),
765 .mode = 0644,
766 .proc_handler = proc_dowatchdog_enabled,
767 },
768#endif
769#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
770 {
771 .procname = "unknown_nmi_panic",
772 .data = &unknown_nmi_panic,
773 .maxlen = sizeof (int),
774 .mode = 0644,
775 .proc_handler = proc_dointvec,
776 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500777#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778#if defined(CONFIG_X86)
779 {
Don Zickus8da5add2006-09-26 10:52:27 +0200780 .procname = "panic_on_unrecovered_nmi",
781 .data = &panic_on_unrecovered_nmi,
782 .maxlen = sizeof(int),
783 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200785 },
786 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700787 .procname = "panic_on_io_nmi",
788 .data = &panic_on_io_nmi,
789 .maxlen = sizeof(int),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700792 },
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .procname = "bootloader_type",
795 .data = &bootloader_type,
796 .maxlen = sizeof (int),
797 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100800 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700801 .procname = "bootloader_version",
802 .data = &bootloader_version,
803 .maxlen = sizeof (int),
804 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800805 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700806 },
807 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100808 .procname = "kstack_depth_to_print",
809 .data = &kstack_depth_to_print,
810 .maxlen = sizeof(int),
811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800812 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100813 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100814 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100815 .procname = "io_delay_type",
816 .data = &io_delay_type,
817 .maxlen = sizeof(int),
818 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800819 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100820 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800822#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 .procname = "randomize_va_space",
825 .data = &randomize_va_space,
826 .maxlen = sizeof(int),
827 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800828 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800830#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800831#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700832 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700833 .procname = "spin_retry",
834 .data = &spin_retry,
835 .maxlen = sizeof (int),
836 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800837 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700838 },
839#endif
Len Brown673d5b42007-07-28 03:33:16 -0400840#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800841 {
Pavel Machekc255d842006-02-20 18:27:58 -0800842 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700843 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800844 .maxlen = sizeof (unsigned long),
845 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800846 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800847 },
848#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800849#ifdef CONFIG_IA64
850 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800851 .procname = "ignore-unaligned-usertrap",
852 .data = &no_unaligned_warning,
853 .maxlen = sizeof (int),
854 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800855 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800856 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800857 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800858 .procname = "unaligned-dump-stack",
859 .data = &unaligned_dump_stack,
860 .maxlen = sizeof (int),
861 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800863 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800864#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800865#ifdef CONFIG_DETECT_HUNG_TASK
866 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800867 .procname = "hung_task_panic",
868 .data = &sysctl_hung_task_panic,
869 .maxlen = sizeof(int),
870 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800871 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800872 .extra1 = &zero,
873 .extra2 = &one,
874 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100876 .procname = "hung_task_check_count",
877 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100878 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800880 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100881 },
882 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100883 .procname = "hung_task_timeout_secs",
884 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100885 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100886 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800887 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100888 },
889 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100890 .procname = "hung_task_warnings",
891 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100892 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100893 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800894 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100895 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700896#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200897#ifdef CONFIG_COMPAT
898 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200899 .procname = "compat-log",
900 .data = &compat_log,
901 .maxlen = sizeof (int),
902 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800903 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200904 },
905#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700906#ifdef CONFIG_RT_MUTEXES
907 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700908 .procname = "max_lock_depth",
909 .data = &max_lock_depth,
910 .maxlen = sizeof(int),
911 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800912 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700913 },
914#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700915 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700916 .procname = "poweroff_cmd",
917 .data = &poweroff_cmd,
918 .maxlen = POWEROFF_CMD_PATH_LEN,
919 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800920 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700921 },
David Howells0b77f5b2008-04-29 01:01:32 -0700922#ifdef CONFIG_KEYS
923 {
David Howells0b77f5b2008-04-29 01:01:32 -0700924 .procname = "keys",
925 .mode = 0555,
926 .child = key_sysctls,
927 },
928#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700929#ifdef CONFIG_RCU_TORTURE_TEST
930 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700931 .procname = "rcutorture_runnable",
932 .data = &rcutorture_runnable,
933 .maxlen = sizeof(int),
934 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800935 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700936 },
937#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200938#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200939 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200940 .procname = "perf_event_paranoid",
941 .data = &sysctl_perf_event_paranoid,
942 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200943 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200945 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200946 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200947 .procname = "perf_event_mlock_kb",
948 .data = &sysctl_perf_event_mlock,
949 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200950 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200952 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200953 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200954 .procname = "perf_event_max_sample_rate",
955 .data = &sysctl_perf_event_sample_rate,
956 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200957 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800958 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200959 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200960#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200961#ifdef CONFIG_KMEMCHECK
962 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200963 .procname = "kmemcheck",
964 .data = &kmemcheck_enabled,
965 .maxlen = sizeof(int),
966 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800967 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200968 },
969#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200970#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200971 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200972 .procname = "blk_iopoll",
973 .data = &blk_iopoll_enabled,
974 .maxlen = sizeof(int),
975 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800976 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200977 },
Jens Axboecb684b52009-09-15 21:53:11 +0200978#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700979 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980};
981
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700982static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 .procname = "overcommit_memory",
985 .data = &sysctl_overcommit_memory,
986 .maxlen = sizeof(sysctl_overcommit_memory),
987 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800988 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 },
990 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700991 .procname = "panic_on_oom",
992 .data = &sysctl_panic_on_oom,
993 .maxlen = sizeof(sysctl_panic_on_oom),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700996 },
997 {
David Rientjesfe071d72007-10-16 23:25:56 -0700998 .procname = "oom_kill_allocating_task",
999 .data = &sysctl_oom_kill_allocating_task,
1000 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001003 },
1004 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001005 .procname = "oom_dump_tasks",
1006 .data = &sysctl_oom_dump_tasks,
1007 .maxlen = sizeof(sysctl_oom_dump_tasks),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "overcommit_ratio",
1013 .data = &sysctl_overcommit_ratio,
1014 .maxlen = sizeof(sysctl_overcommit_ratio),
1015 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 },
1018 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .procname = "page-cluster",
1020 .data = &page_cluster,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 },
1025 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 .procname = "dirty_background_ratio",
1027 .data = &dirty_background_ratio,
1028 .maxlen = sizeof(dirty_background_ratio),
1029 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001030 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 .extra1 = &zero,
1032 .extra2 = &one_hundred,
1033 },
1034 {
David Rientjes2da02992009-01-06 14:39:31 -08001035 .procname = "dirty_background_bytes",
1036 .data = &dirty_background_bytes,
1037 .maxlen = sizeof(dirty_background_bytes),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001040 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001041 },
1042 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 .procname = "dirty_ratio",
1044 .data = &vm_dirty_ratio,
1045 .maxlen = sizeof(vm_dirty_ratio),
1046 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001047 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .extra1 = &zero,
1049 .extra2 = &one_hundred,
1050 },
1051 {
David Rientjes2da02992009-01-06 14:39:31 -08001052 .procname = "dirty_bytes",
1053 .data = &vm_dirty_bytes,
1054 .maxlen = sizeof(vm_dirty_bytes),
1055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001057 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001058 },
1059 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001061 .data = &dirty_writeback_interval,
1062 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001068 .data = &dirty_expire_interval,
1069 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 },
1073 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 .procname = "nr_pdflush_threads",
1075 .data = &nr_pdflush_threads,
1076 .maxlen = sizeof nr_pdflush_threads,
1077 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 },
1080 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .procname = "swappiness",
1082 .data = &vm_swappiness,
1083 .maxlen = sizeof(vm_swappiness),
1084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .extra1 = &zero,
1087 .extra2 = &one_hundred,
1088 },
1089#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001090 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001092 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .maxlen = sizeof(unsigned long),
1094 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001095 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .extra1 = (void *)&hugetlb_zero,
1097 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001098 },
1099#ifdef CONFIG_NUMA
1100 {
1101 .procname = "nr_hugepages_mempolicy",
1102 .data = NULL,
1103 .maxlen = sizeof(unsigned long),
1104 .mode = 0644,
1105 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1106 .extra1 = (void *)&hugetlb_zero,
1107 .extra2 = (void *)&hugetlb_infinity,
1108 },
1109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .procname = "hugetlb_shm_group",
1112 .data = &sysctl_hugetlb_shm_group,
1113 .maxlen = sizeof(gid_t),
1114 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001115 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 },
Mel Gorman396faf02007-07-17 04:03:13 -07001117 {
Mel Gorman396faf02007-07-17 04:03:13 -07001118 .procname = "hugepages_treat_as_movable",
1119 .data = &hugepages_treat_as_movable,
1120 .maxlen = sizeof(int),
1121 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001122 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001123 },
Adam Litke54f9f802007-10-16 01:26:20 -07001124 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001125 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001126 .data = NULL,
1127 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001128 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001129 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001130 .extra1 = (void *)&hugetlb_zero,
1131 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001132 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133#endif
1134 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 .procname = "lowmem_reserve_ratio",
1136 .data = &sysctl_lowmem_reserve_ratio,
1137 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 },
1141 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001142 .procname = "drop_caches",
1143 .data = &sysctl_drop_caches,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001147 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001148#ifdef CONFIG_COMPACTION
1149 {
1150 .procname = "compact_memory",
1151 .data = &sysctl_compact_memory,
1152 .maxlen = sizeof(int),
1153 .mode = 0200,
1154 .proc_handler = sysctl_compaction_handler,
1155 },
Mel Gorman5e771902010-05-24 14:32:31 -07001156 {
1157 .procname = "extfrag_threshold",
1158 .data = &sysctl_extfrag_threshold,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = sysctl_extfrag_handler,
1162 .extra1 = &min_extfrag_threshold,
1163 .extra2 = &max_extfrag_threshold,
1164 },
1165
Mel Gorman76ab0f52010-05-24 14:32:28 -07001166#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001167 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .procname = "min_free_kbytes",
1169 .data = &min_free_kbytes,
1170 .maxlen = sizeof(min_free_kbytes),
1171 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001172 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .extra1 = &zero,
1174 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001175 {
Rik van Rieldf695fb2011-09-01 15:26:50 -04001176 .procname = "extra_free_kbytes",
1177 .data = &extra_free_kbytes,
1178 .maxlen = sizeof(extra_free_kbytes),
1179 .mode = 0644,
1180 .proc_handler = min_free_kbytes_sysctl_handler,
1181 .extra1 = &zero,
1182 },
1183 {
Arve Hjønnevåg2a023fb2009-02-17 14:51:02 -08001184 .procname = "min_free_order_shift",
1185 .data = &min_free_order_shift,
1186 .maxlen = sizeof(min_free_order_shift),
1187 .mode = 0644,
1188 .proc_handler = &proc_dointvec
1189 },
1190 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001191 .procname = "percpu_pagelist_fraction",
1192 .data = &percpu_pagelist_fraction,
1193 .maxlen = sizeof(percpu_pagelist_fraction),
1194 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001195 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001196 .extra1 = &min_percpu_pagelist_fract,
1197 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198#ifdef CONFIG_MMU
1199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .procname = "max_map_count",
1201 .data = &sysctl_max_map_count,
1202 .maxlen = sizeof(sysctl_max_map_count),
1203 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001204 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001205 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001207#else
1208 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001209 .procname = "nr_trim_pages",
1210 .data = &sysctl_nr_trim_pages,
1211 .maxlen = sizeof(sysctl_nr_trim_pages),
1212 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001213 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001214 .extra1 = &zero,
1215 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216#endif
1217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .procname = "laptop_mode",
1219 .data = &laptop_mode,
1220 .maxlen = sizeof(laptop_mode),
1221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001222 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 },
1224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 .procname = "block_dump",
1226 .data = &block_dump,
1227 .maxlen = sizeof(block_dump),
1228 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001229 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 .extra1 = &zero,
1231 },
1232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 .procname = "vfs_cache_pressure",
1234 .data = &sysctl_vfs_cache_pressure,
1235 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1236 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001237 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 .extra1 = &zero,
1239 },
1240#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 .procname = "legacy_va_layout",
1243 .data = &sysctl_legacy_va_layout,
1244 .maxlen = sizeof(sysctl_legacy_va_layout),
1245 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001246 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 .extra1 = &zero,
1248 },
1249#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001250#ifdef CONFIG_NUMA
1251 {
Christoph Lameter17436602006-01-18 17:42:32 -08001252 .procname = "zone_reclaim_mode",
1253 .data = &zone_reclaim_mode,
1254 .maxlen = sizeof(zone_reclaim_mode),
1255 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001256 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001257 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001258 },
Christoph Lameter96146342006-07-03 00:24:13 -07001259 {
Christoph Lameter96146342006-07-03 00:24:13 -07001260 .procname = "min_unmapped_ratio",
1261 .data = &sysctl_min_unmapped_ratio,
1262 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1263 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001264 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001265 .extra1 = &zero,
1266 .extra2 = &one_hundred,
1267 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001268 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001269 .procname = "min_slab_ratio",
1270 .data = &sysctl_min_slab_ratio,
1271 .maxlen = sizeof(sysctl_min_slab_ratio),
1272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001273 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001274 .extra1 = &zero,
1275 .extra2 = &one_hundred,
1276 },
Christoph Lameter17436602006-01-18 17:42:32 -08001277#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001278#ifdef CONFIG_SMP
1279 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001280 .procname = "stat_interval",
1281 .data = &sysctl_stat_interval,
1282 .maxlen = sizeof(sysctl_stat_interval),
1283 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001284 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001285 },
1286#endif
David Howells6e141542009-12-15 19:27:45 +00001287#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001288 {
Eric Parised032182007-06-28 15:55:21 -04001289 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001290 .data = &dac_mmap_min_addr,
1291 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001292 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001293 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001294 },
David Howells6e141542009-12-15 19:27:45 +00001295#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001296#ifdef CONFIG_NUMA
1297 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001298 .procname = "numa_zonelist_order",
1299 .data = &numa_zonelist_order,
1300 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001303 },
1304#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001305#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001306 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001307 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001308 .procname = "vdso_enabled",
1309 .data = &vdso_enabled,
1310 .maxlen = sizeof(vdso_enabled),
1311 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001312 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001313 .extra1 = &zero,
1314 },
1315#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001316#ifdef CONFIG_HIGHMEM
1317 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001318 .procname = "highmem_is_dirtyable",
1319 .data = &vm_highmem_is_dirtyable,
1320 .maxlen = sizeof(vm_highmem_is_dirtyable),
1321 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001322 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001323 .extra1 = &zero,
1324 .extra2 = &one,
1325 },
1326#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001327 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001328 .procname = "scan_unevictable_pages",
1329 .data = &scan_unevictable_pages,
1330 .maxlen = sizeof(scan_unevictable_pages),
1331 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001332 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001333 },
Andi Kleen6a460792009-09-16 11:50:15 +02001334#ifdef CONFIG_MEMORY_FAILURE
1335 {
Andi Kleen6a460792009-09-16 11:50:15 +02001336 .procname = "memory_failure_early_kill",
1337 .data = &sysctl_memory_failure_early_kill,
1338 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001340 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001341 .extra1 = &zero,
1342 .extra2 = &one,
1343 },
1344 {
Andi Kleen6a460792009-09-16 11:50:15 +02001345 .procname = "memory_failure_recovery",
1346 .data = &sysctl_memory_failure_recovery,
1347 .maxlen = sizeof(sysctl_memory_failure_recovery),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001350 .extra1 = &zero,
1351 .extra2 = &one,
1352 },
1353#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001354 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355};
1356
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001357#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001358static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001359 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001360};
1361#endif
1362
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001363static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 .procname = "inode-nr",
1366 .data = &inodes_stat,
1367 .maxlen = 2*sizeof(int),
1368 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001369 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 },
1371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 .procname = "inode-state",
1373 .data = &inodes_stat,
1374 .maxlen = 7*sizeof(int),
1375 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001376 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 },
1378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .procname = "file-nr",
1380 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001381 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001383 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 },
1385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .procname = "file-max",
1387 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001388 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001390 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 },
1392 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001393 .procname = "nr_open",
1394 .data = &sysctl_nr_open,
1395 .maxlen = sizeof(int),
1396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001398 .extra1 = &sysctl_nr_open_min,
1399 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001400 },
1401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 .procname = "dentry-state",
1403 .data = &dentry_stat,
1404 .maxlen = 6*sizeof(int),
1405 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001406 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 },
1408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 .procname = "overflowuid",
1410 .data = &fs_overflowuid,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .extra1 = &minolduid,
1415 .extra2 = &maxolduid,
1416 },
1417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "overflowgid",
1419 .data = &fs_overflowgid,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .extra1 = &minolduid,
1424 .extra2 = &maxolduid,
1425 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001426#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 .procname = "leases-enable",
1429 .data = &leases_enable,
1430 .maxlen = sizeof(int),
1431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001432 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001434#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435#ifdef CONFIG_DNOTIFY
1436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 .procname = "dir-notify-enable",
1438 .data = &dir_notify_enable,
1439 .maxlen = sizeof(int),
1440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 },
1443#endif
1444#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001445#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .procname = "lease-break-time",
1448 .data = &lease_break_time,
1449 .maxlen = sizeof(int),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001453#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001454#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .procname = "aio-nr",
1457 .data = &aio_nr,
1458 .maxlen = sizeof(aio_nr),
1459 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 },
1462 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 .procname = "aio-max-nr",
1464 .data = &aio_max_nr,
1465 .maxlen = sizeof(aio_max_nr),
1466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001467 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001469#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001470#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001471 {
Robert Love0399cb02005-07-13 12:38:18 -04001472 .procname = "inotify",
1473 .mode = 0555,
1474 .child = inotify_table,
1475 },
1476#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001477#ifdef CONFIG_EPOLL
1478 {
1479 .procname = "epoll",
1480 .mode = 0555,
1481 .child = epoll_table,
1482 },
1483#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001485 {
Alan Coxd6e71142005-06-23 00:09:43 -07001486 .procname = "suid_dumpable",
1487 .data = &suid_dumpable,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001490 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001491 .extra1 = &zero,
1492 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001493 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001494#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1495 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001496 .procname = "binfmt_misc",
1497 .mode = 0555,
1498 .child = binfmt_misc_table,
1499 },
1500#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001501 {
Jens Axboeff9da692010-06-03 14:54:39 +02001502 .procname = "pipe-max-size",
1503 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001504 .maxlen = sizeof(int),
1505 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001506 .proc_handler = &pipe_proc_fn,
1507 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001508 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001509 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510};
1511
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001512static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001513#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1514 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001515 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001516 .procname = "exception-trace",
1517 .data = &show_unhandled_signals,
1518 .maxlen = sizeof(int),
1519 .mode = 0644,
1520 .proc_handler = proc_dointvec
1521 },
1522#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001523#if defined(CONFIG_OPTPROBES)
1524 {
1525 .procname = "kprobes-optimization",
1526 .data = &sysctl_kprobes_optimization,
1527 .maxlen = sizeof(int),
1528 .mode = 0644,
1529 .proc_handler = proc_kprobes_optimization_handler,
1530 .extra1 = &zero,
1531 .extra2 = &one,
1532 },
1533#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001534 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535};
1536
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001537static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001538 { }
Robert Love0eeca282005-07-12 17:06:03 -04001539};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Al Viro330d57f2005-11-04 10:18:40 +00001541static DEFINE_SPINLOCK(sysctl_lock);
1542
1543/* called under sysctl_lock */
1544static int use_table(struct ctl_table_header *p)
1545{
1546 if (unlikely(p->unregistering))
1547 return 0;
1548 p->used++;
1549 return 1;
1550}
1551
1552/* called under sysctl_lock */
1553static void unuse_table(struct ctl_table_header *p)
1554{
1555 if (!--p->used)
1556 if (unlikely(p->unregistering))
1557 complete(p->unregistering);
1558}
1559
1560/* called under sysctl_lock, will reacquire if has to wait */
1561static void start_unregistering(struct ctl_table_header *p)
1562{
1563 /*
1564 * if p->used is 0, nobody will ever touch that entry again;
1565 * we'll eliminate all paths to it before dropping sysctl_lock
1566 */
1567 if (unlikely(p->used)) {
1568 struct completion wait;
1569 init_completion(&wait);
1570 p->unregistering = &wait;
1571 spin_unlock(&sysctl_lock);
1572 wait_for_completion(&wait);
1573 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001574 } else {
1575 /* anything non-NULL; we'll never dereference it */
1576 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001577 }
1578 /*
1579 * do not remove from the list until nobody holds it; walking the
1580 * list in do_sysctl() relies on that.
1581 */
1582 list_del_init(&p->ctl_entry);
1583}
1584
Al Virof7e6ced2008-07-15 01:44:23 -04001585void sysctl_head_get(struct ctl_table_header *head)
1586{
1587 spin_lock(&sysctl_lock);
1588 head->count++;
1589 spin_unlock(&sysctl_lock);
1590}
1591
Al Virodfef6dc2011-03-08 01:25:28 -05001592static void free_head(struct rcu_head *rcu)
1593{
1594 kfree(container_of(rcu, struct ctl_table_header, rcu));
1595}
1596
Al Virof7e6ced2008-07-15 01:44:23 -04001597void sysctl_head_put(struct ctl_table_header *head)
1598{
1599 spin_lock(&sysctl_lock);
1600 if (!--head->count)
Al Virodfef6dc2011-03-08 01:25:28 -05001601 call_rcu(&head->rcu, free_head);
Al Virof7e6ced2008-07-15 01:44:23 -04001602 spin_unlock(&sysctl_lock);
1603}
1604
1605struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1606{
1607 if (!head)
1608 BUG();
1609 spin_lock(&sysctl_lock);
1610 if (!use_table(head))
1611 head = ERR_PTR(-ENOENT);
1612 spin_unlock(&sysctl_lock);
1613 return head;
1614}
1615
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616void sysctl_head_finish(struct ctl_table_header *head)
1617{
1618 if (!head)
1619 return;
1620 spin_lock(&sysctl_lock);
1621 unuse_table(head);
1622 spin_unlock(&sysctl_lock);
1623}
1624
Al Viro73455092008-07-14 21:22:20 -04001625static struct ctl_table_set *
1626lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1627{
1628 struct ctl_table_set *set = &root->default_set;
1629 if (root->lookup)
1630 set = root->lookup(root, namespaces);
1631 return set;
1632}
1633
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001634static struct list_head *
1635lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001636{
Al Viro73455092008-07-14 21:22:20 -04001637 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1638 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001639}
1640
1641struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1642 struct ctl_table_header *prev)
1643{
1644 struct ctl_table_root *root;
1645 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001646 struct ctl_table_header *head;
1647 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001648
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001649 spin_lock(&sysctl_lock);
1650 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001651 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001652 tmp = &prev->ctl_entry;
1653 unuse_table(prev);
1654 goto next;
1655 }
1656 tmp = &root_table_header.ctl_entry;
1657 for (;;) {
1658 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1659
1660 if (!use_table(head))
1661 goto next;
1662 spin_unlock(&sysctl_lock);
1663 return head;
1664 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001665 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001666 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001667 header_list = lookup_header_list(root, namespaces);
1668 if (tmp != header_list)
1669 continue;
1670
1671 do {
1672 root = list_entry(root->root_list.next,
1673 struct ctl_table_root, root_list);
1674 if (root == &sysctl_table_root)
1675 goto out;
1676 header_list = lookup_header_list(root, namespaces);
1677 } while (list_empty(header_list));
1678 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001679 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001680out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001681 spin_unlock(&sysctl_lock);
1682 return NULL;
1683}
1684
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001685struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1686{
1687 return __sysctl_head_next(current->nsproxy, prev);
1688}
1689
1690void register_sysctl_root(struct ctl_table_root *root)
1691{
1692 spin_lock(&sysctl_lock);
1693 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1694 spin_unlock(&sysctl_lock);
1695}
1696
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001698 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 * some sysctl variables are readonly even to root.
1700 */
1701
1702static int test_perm(int mode, int op)
1703{
David Howells76aac0e2008-11-14 10:39:12 +11001704 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 mode >>= 6;
1706 else if (in_egroup_p(0))
1707 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001708 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 return 0;
1710 return -EACCES;
1711}
1712
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001713int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714{
1715 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001716 int mode;
1717
Al Viroe6305c42008-07-15 21:03:57 -04001718 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 if (error)
1720 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001721
1722 if (root->permissions)
1723 mode = root->permissions(root, current->nsproxy, table);
1724 else
1725 mode = table->mode;
1726
1727 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001730static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1731{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001732 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001733 table->parent = parent;
1734 if (table->child)
1735 sysctl_set_parent(table, table->child);
1736 }
1737}
1738
1739static __init int sysctl_init(void)
1740{
1741 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001742#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001743 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001744#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001745 return 0;
1746}
1747
1748core_initcall(sysctl_init);
1749
Al Virobfbcf032008-07-27 06:31:22 +01001750static struct ctl_table *is_branch_in(struct ctl_table *branch,
1751 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001752{
1753 struct ctl_table *p;
1754 const char *s = branch->procname;
1755
1756 /* branch should have named subdirectory as its first element */
1757 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001758 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001759
1760 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001761 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001762 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001763
1764 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001765 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001766 if (!p->child)
1767 continue;
1768 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001769 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001770 }
Al Virobfbcf032008-07-27 06:31:22 +01001771 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001772}
1773
1774/* see if attaching q to p would be an improvement */
1775static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1776{
1777 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001778 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001779 int is_better = 0;
1780 int not_in_parent = !p->attached_by;
1781
Al Virobfbcf032008-07-27 06:31:22 +01001782 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001783 if (by == q->attached_by)
1784 is_better = 1;
1785 if (to == p->attached_by)
1786 not_in_parent = 1;
1787 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001788 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001789 }
1790
1791 if (is_better && not_in_parent) {
1792 q->attached_by = by;
1793 q->attached_to = to;
1794 q->parent = p;
1795 }
1796}
1797
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001799 * __register_sysctl_paths - register a sysctl hierarchy
1800 * @root: List of sysctl headers to register on
1801 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001802 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 *
1805 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001806 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001808 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1811 * enter a sysctl file
1812 *
1813 * data - a pointer to data for use by proc_handler
1814 *
1815 * maxlen - the maximum size in bytes of the data
1816 *
1817 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1818 *
1819 * child - a pointer to the child sysctl table if this entry is a directory, or
1820 * %NULL.
1821 *
1822 * proc_handler - the text handler routine (described below)
1823 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 * de - for internal use by the sysctl routines
1825 *
1826 * extra1, extra2 - extra pointers usable by the proc handler routines
1827 *
1828 * Leaf nodes in the sysctl tree will be represented by a single file
1829 * under /proc; non-leaf nodes will be represented by directories.
1830 *
1831 * sysctl(2) can automatically manage read and write requests through
1832 * the sysctl table. The data and maxlen fields of the ctl_table
1833 * struct enable minimal validation of the values being written to be
1834 * performed, and the mode field allows minimal authentication.
1835 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 * There must be a proc_handler routine for any terminal nodes
1837 * mirrored under /proc/sys (non-terminals are handled by a built-in
1838 * directory handler). Several default handlers are available to
1839 * cover common cases -
1840 *
1841 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1842 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1843 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1844 *
1845 * It is the handler's job to read the input buffer from user memory
1846 * and process it. The handler should return 0 on success.
1847 *
1848 * This routine returns %NULL on a failure to register, and a pointer
1849 * to the table header on success.
1850 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001851struct ctl_table_header *__register_sysctl_paths(
1852 struct ctl_table_root *root,
1853 struct nsproxy *namespaces,
1854 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001856 struct ctl_table_header *header;
1857 struct ctl_table *new, **prevp;
1858 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001859 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001860
1861 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001862 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001863 ;
1864
1865 /*
1866 * For each path component, allocate a 2-element ctl_table array.
1867 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001868 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001869 *
1870 * We allocate everything in one go so that we don't have to
1871 * worry about freeing additional memory in unregister_sysctl_table.
1872 */
1873 header = kzalloc(sizeof(struct ctl_table_header) +
1874 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1875 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001877
1878 new = (struct ctl_table *) (header + 1);
1879
1880 /* Now connect the dots */
1881 prevp = &header->ctl_table;
1882 for (n = 0; n < npath; ++n, ++path) {
1883 /* Copy the procname */
1884 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001885 new->mode = 0555;
1886
1887 *prevp = new;
1888 prevp = &new->child;
1889
1890 new += 2;
1891 }
1892 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001893 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001894
1895 INIT_LIST_HEAD(&header->ctl_entry);
1896 header->used = 0;
1897 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001898 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001899 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001900 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001901#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001902 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001903 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001904 return NULL;
1905 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001906#endif
Al Viro330d57f2005-11-04 10:18:40 +00001907 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001908 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001909 header->attached_by = header->ctl_table;
1910 header->attached_to = root_table;
1911 header->parent = &root_table_header;
1912 for (set = header->set; set; set = set->parent) {
1913 struct ctl_table_header *p;
1914 list_for_each_entry(p, &set->list, ctl_entry) {
1915 if (p->unregistering)
1916 continue;
1917 try_attach(p, header);
1918 }
1919 }
1920 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001921 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001922 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001923
1924 return header;
1925}
1926
1927/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001928 * register_sysctl_table_path - register a sysctl table hierarchy
1929 * @path: The path to the directory the sysctl table is in.
1930 * @table: the top-level table structure
1931 *
1932 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1933 * array. A completely 0 filled entry terminates the table.
1934 *
1935 * See __register_sysctl_paths for more details.
1936 */
1937struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1938 struct ctl_table *table)
1939{
1940 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1941 path, table);
1942}
1943
1944/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001945 * register_sysctl_table - register a sysctl table hierarchy
1946 * @table: the top-level table structure
1947 *
1948 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1949 * array. A completely 0 filled entry terminates the table.
1950 *
1951 * See register_sysctl_paths for more details.
1952 */
1953struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1954{
1955 static const struct ctl_path null_path[] = { {} };
1956
1957 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958}
1959
1960/**
1961 * unregister_sysctl_table - unregister a sysctl table hierarchy
1962 * @header: the header returned from register_sysctl_table
1963 *
1964 * Unregisters the sysctl table and all children. proc entries may not
1965 * actually be removed until they are no longer used by anyone.
1966 */
1967void unregister_sysctl_table(struct ctl_table_header * header)
1968{
Al Viro330d57f2005-11-04 10:18:40 +00001969 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001970
1971 if (header == NULL)
1972 return;
1973
Al Viro330d57f2005-11-04 10:18:40 +00001974 spin_lock(&sysctl_lock);
1975 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001976 if (!--header->parent->count) {
1977 WARN_ON(1);
Al Virodfef6dc2011-03-08 01:25:28 -05001978 call_rcu(&header->parent->rcu, free_head);
Al Viroae7edec2008-07-15 06:33:31 -04001979 }
Al Virof7e6ced2008-07-15 01:44:23 -04001980 if (!--header->count)
Al Virodfef6dc2011-03-08 01:25:28 -05001981 call_rcu(&header->rcu, free_head);
Al Viro330d57f2005-11-04 10:18:40 +00001982 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983}
1984
Al Viro90434762008-07-15 08:54:06 -04001985int sysctl_is_seen(struct ctl_table_header *p)
1986{
1987 struct ctl_table_set *set = p->set;
1988 int res;
1989 spin_lock(&sysctl_lock);
1990 if (p->unregistering)
1991 res = 0;
1992 else if (!set->is_seen)
1993 res = 1;
1994 else
1995 res = set->is_seen(set);
1996 spin_unlock(&sysctl_lock);
1997 return res;
1998}
1999
Al Viro73455092008-07-14 21:22:20 -04002000void setup_sysctl_set(struct ctl_table_set *p,
2001 struct ctl_table_set *parent,
2002 int (*is_seen)(struct ctl_table_set *))
2003{
2004 INIT_LIST_HEAD(&p->list);
2005 p->parent = parent ? parent : &sysctl_table_root.default_set;
2006 p->is_seen = is_seen;
2007}
2008
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002009#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002010struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002011{
2012 return NULL;
2013}
2014
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002015struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2016 struct ctl_table *table)
2017{
2018 return NULL;
2019}
2020
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002021void unregister_sysctl_table(struct ctl_table_header * table)
2022{
2023}
2024
Al Viro73455092008-07-14 21:22:20 -04002025void setup_sysctl_set(struct ctl_table_set *p,
2026 struct ctl_table_set *parent,
2027 int (*is_seen)(struct ctl_table_set *))
2028{
2029}
2030
Al Virof7e6ced2008-07-15 01:44:23 -04002031void sysctl_head_put(struct ctl_table_header *head)
2032{
2033}
2034
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002035#endif /* CONFIG_SYSCTL */
2036
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037/*
2038 * /proc/sys support
2039 */
2040
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002041#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002043static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002044 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002045 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002046{
2047 size_t len;
2048 char __user *p;
2049 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002050
2051 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002052 *lenp = 0;
2053 return 0;
2054 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002055
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002056 if (write) {
2057 len = 0;
2058 p = buffer;
2059 while (len < *lenp) {
2060 if (get_user(c, p++))
2061 return -EFAULT;
2062 if (c == 0 || c == '\n')
2063 break;
2064 len++;
2065 }
2066 if (len >= maxlen)
2067 len = maxlen-1;
2068 if(copy_from_user(data, buffer, len))
2069 return -EFAULT;
2070 ((char *) data)[len] = 0;
2071 *ppos += *lenp;
2072 } else {
2073 len = strlen(data);
2074 if (len > maxlen)
2075 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002076
2077 if (*ppos > len) {
2078 *lenp = 0;
2079 return 0;
2080 }
2081
2082 data += *ppos;
2083 len -= *ppos;
2084
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002085 if (len > *lenp)
2086 len = *lenp;
2087 if (len)
2088 if(copy_to_user(buffer, data, len))
2089 return -EFAULT;
2090 if (len < *lenp) {
2091 if(put_user('\n', ((char __user *) buffer) + len))
2092 return -EFAULT;
2093 len++;
2094 }
2095 *lenp = len;
2096 *ppos += len;
2097 }
2098 return 0;
2099}
2100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101/**
2102 * proc_dostring - read a string sysctl
2103 * @table: the sysctl table
2104 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 * @buffer: the user buffer
2106 * @lenp: the size of the user buffer
2107 * @ppos: file position
2108 *
2109 * Reads/writes a string from/to the user buffer. If the kernel
2110 * buffer provided is not large enough to hold the string, the
2111 * string is truncated. The copied string is %NULL-terminated.
2112 * If the string is being read by the user process, it is copied
2113 * and a newline '\n' is added. It is truncated if the buffer is
2114 * not large enough.
2115 *
2116 * Returns 0 on success.
2117 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002118int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 void __user *buffer, size_t *lenp, loff_t *ppos)
2120{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002121 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002122 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
Amerigo Wang00b7c332010-05-05 00:26:45 +00002125static size_t proc_skip_spaces(char **buf)
2126{
2127 size_t ret;
2128 char *tmp = skip_spaces(*buf);
2129 ret = tmp - *buf;
2130 *buf = tmp;
2131 return ret;
2132}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002134static void proc_skip_char(char **buf, size_t *size, const char v)
2135{
2136 while (*size) {
2137 if (**buf != v)
2138 break;
2139 (*size)--;
2140 (*buf)++;
2141 }
2142}
2143
Amerigo Wang00b7c332010-05-05 00:26:45 +00002144#define TMPBUFLEN 22
2145/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002146 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002147 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002148 * @buf: a kernel buffer
2149 * @size: size of the kernel buffer
2150 * @val: this is where the number will be stored
2151 * @neg: set to %TRUE if number is negative
2152 * @perm_tr: a vector which contains the allowed trailers
2153 * @perm_tr_len: size of the perm_tr vector
2154 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002155 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002156 * In case of success %0 is returned and @buf and @size are updated with
2157 * the amount of bytes read. If @tr is non-NULL and a trailing
2158 * character exists (size is non-zero after returning from this
2159 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160 */
2161static int proc_get_long(char **buf, size_t *size,
2162 unsigned long *val, bool *neg,
2163 const char *perm_tr, unsigned perm_tr_len, char *tr)
2164{
2165 int len;
2166 char *p, tmp[TMPBUFLEN];
2167
2168 if (!*size)
2169 return -EINVAL;
2170
2171 len = *size;
2172 if (len > TMPBUFLEN - 1)
2173 len = TMPBUFLEN - 1;
2174
2175 memcpy(tmp, *buf, len);
2176
2177 tmp[len] = 0;
2178 p = tmp;
2179 if (*p == '-' && *size > 1) {
2180 *neg = true;
2181 p++;
2182 } else
2183 *neg = false;
2184 if (!isdigit(*p))
2185 return -EINVAL;
2186
2187 *val = simple_strtoul(p, &p, 0);
2188
2189 len = p - tmp;
2190
2191 /* We don't know if the next char is whitespace thus we may accept
2192 * invalid integers (e.g. 1234...a) or two integers instead of one
2193 * (e.g. 123...1). So lets not allow such large numbers. */
2194 if (len == TMPBUFLEN - 1)
2195 return -EINVAL;
2196
2197 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2198 return -EINVAL;
2199
2200 if (tr && (len < *size))
2201 *tr = *p;
2202
2203 *buf += len;
2204 *size -= len;
2205
2206 return 0;
2207}
2208
2209/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002210 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002211 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002212 * @buf: the user buffer
2213 * @size: the size of the user buffer
2214 * @val: the integer to be converted
2215 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002216 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002217 * In case of success %0 is returned and @buf and @size are updated with
2218 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002219 */
2220static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2221 bool neg)
2222{
2223 int len;
2224 char tmp[TMPBUFLEN], *p = tmp;
2225
2226 sprintf(p, "%s%lu", neg ? "-" : "", val);
2227 len = strlen(tmp);
2228 if (len > *size)
2229 len = *size;
2230 if (copy_to_user(*buf, tmp, len))
2231 return -EFAULT;
2232 *size -= len;
2233 *buf += len;
2234 return 0;
2235}
2236#undef TMPBUFLEN
2237
2238static int proc_put_char(void __user **buf, size_t *size, char c)
2239{
2240 if (*size) {
2241 char __user **buffer = (char __user **)buf;
2242 if (put_user(c, *buffer))
2243 return -EFAULT;
2244 (*size)--, (*buffer)++;
2245 *buf = *buffer;
2246 }
2247 return 0;
2248}
2249
2250static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 int *valp,
2252 int write, void *data)
2253{
2254 if (write) {
2255 *valp = *negp ? -*lvalp : *lvalp;
2256 } else {
2257 int val = *valp;
2258 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002259 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 *lvalp = (unsigned long)-val;
2261 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 *lvalp = (unsigned long)val;
2264 }
2265 }
2266 return 0;
2267}
2268
Amerigo Wang00b7c332010-05-05 00:26:45 +00002269static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2270
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002271static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002272 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002273 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002274 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 int write, void *data),
2276 void *data)
2277{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002278 int *i, vleft, first = 1, err = 0;
2279 unsigned long page = 0;
2280 size_t left;
2281 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Amerigo Wang00b7c332010-05-05 00:26:45 +00002283 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 *lenp = 0;
2285 return 0;
2286 }
2287
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002288 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 vleft = table->maxlen / sizeof(*i);
2290 left = *lenp;
2291
2292 if (!conv)
2293 conv = do_proc_dointvec_conv;
2294
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002296 if (left > PAGE_SIZE - 1)
2297 left = PAGE_SIZE - 1;
2298 page = __get_free_page(GFP_TEMPORARY);
2299 kbuf = (char *) page;
2300 if (!kbuf)
2301 return -ENOMEM;
2302 if (copy_from_user(kbuf, buffer, left)) {
2303 err = -EFAULT;
2304 goto free;
2305 }
2306 kbuf[left] = 0;
2307 }
2308
2309 for (; left && vleft--; i++, first=0) {
2310 unsigned long lval;
2311 bool neg;
2312
2313 if (write) {
2314 left -= proc_skip_spaces(&kbuf);
2315
J. R. Okajima563b0462010-05-25 16:10:14 -07002316 if (!left)
2317 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 err = proc_get_long(&kbuf, &left, &lval, &neg,
2319 proc_wspace_sep,
2320 sizeof(proc_wspace_sep), NULL);
2321 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002323 if (conv(&neg, &lval, i, 1, data)) {
2324 err = -EINVAL;
2325 break;
2326 }
2327 } else {
2328 if (conv(&neg, &lval, i, 0, data)) {
2329 err = -EINVAL;
2330 break;
2331 }
2332 if (!first)
2333 err = proc_put_char(&buffer, &left, '\t');
2334 if (err)
2335 break;
2336 err = proc_put_long(&buffer, &left, lval, neg);
2337 if (err)
2338 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 }
2340 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002341
2342 if (!write && !first && left && !err)
2343 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002344 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002345 left -= proc_skip_spaces(&kbuf);
2346free:
2347 if (write) {
2348 free_page(page);
2349 if (first)
2350 return err ? : -EINVAL;
2351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 *lenp -= left;
2353 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002354 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002357static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002358 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002359 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002360 int write, void *data),
2361 void *data)
2362{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002363 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002364 buffer, lenp, ppos, conv, data);
2365}
2366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367/**
2368 * proc_dointvec - read a vector of integers
2369 * @table: the sysctl table
2370 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 * @buffer: the user buffer
2372 * @lenp: the size of the user buffer
2373 * @ppos: file position
2374 *
2375 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2376 * values from/to the user buffer, treated as an ASCII string.
2377 *
2378 * Returns 0 on success.
2379 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002380int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002383 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 NULL,NULL);
2385}
2386
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002387/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002388 * Taint values can only be increased
2389 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002390 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002391static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002392 void __user *buffer, size_t *lenp, loff_t *ppos)
2393{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002394 struct ctl_table t;
2395 unsigned long tmptaint = get_taint();
2396 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002397
Bastian Blank91fcd412007-04-23 14:41:14 -07002398 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002399 return -EPERM;
2400
Andi Kleen25ddbb12008-10-15 22:01:41 -07002401 t = *table;
2402 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002403 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002404 if (err < 0)
2405 return err;
2406
2407 if (write) {
2408 /*
2409 * Poor man's atomic or. Not worth adding a primitive
2410 * to everyone's atomic.h for this
2411 */
2412 int i;
2413 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2414 if ((tmptaint >> i) & 1)
2415 add_taint(i);
2416 }
2417 }
2418
2419 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002420}
2421
Richard Weinberger0fd92112011-03-23 16:43:11 -07002422#ifdef CONFIG_PRINTK
2423static int proc_dmesg_restrict(struct ctl_table *table, int write,
2424 void __user *buffer, size_t *lenp, loff_t *ppos)
2425{
2426 if (write && !capable(CAP_SYS_ADMIN))
2427 return -EPERM;
2428
2429 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2430}
2431#endif
2432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433struct do_proc_dointvec_minmax_conv_param {
2434 int *min;
2435 int *max;
2436};
2437
Amerigo Wang00b7c332010-05-05 00:26:45 +00002438static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2439 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 int write, void *data)
2441{
2442 struct do_proc_dointvec_minmax_conv_param *param = data;
2443 if (write) {
2444 int val = *negp ? -*lvalp : *lvalp;
2445 if ((param->min && *param->min > val) ||
2446 (param->max && *param->max < val))
2447 return -EINVAL;
2448 *valp = val;
2449 } else {
2450 int val = *valp;
2451 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002452 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 *lvalp = (unsigned long)-val;
2454 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002455 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 *lvalp = (unsigned long)val;
2457 }
2458 }
2459 return 0;
2460}
2461
2462/**
2463 * proc_dointvec_minmax - read a vector of integers with min/max values
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 * @buffer: the user buffer
2467 * @lenp: the size of the user buffer
2468 * @ppos: file position
2469 *
2470 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2471 * values from/to the user buffer, treated as an ASCII string.
2472 *
2473 * This routine will ensure the values are within the range specified by
2474 * table->extra1 (min) and table->extra2 (max).
2475 *
2476 * Returns 0 on success.
2477 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002478int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 void __user *buffer, size_t *lenp, loff_t *ppos)
2480{
2481 struct do_proc_dointvec_minmax_conv_param param = {
2482 .min = (int *) table->extra1,
2483 .max = (int *) table->extra2,
2484 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002485 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 do_proc_dointvec_minmax_conv, &param);
2487}
2488
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002489static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 void __user *buffer,
2491 size_t *lenp, loff_t *ppos,
2492 unsigned long convmul,
2493 unsigned long convdiv)
2494{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002495 unsigned long *i, *min, *max;
2496 int vleft, first = 1, err = 0;
2497 unsigned long page = 0;
2498 size_t left;
2499 char *kbuf;
2500
2501 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 *lenp = 0;
2503 return 0;
2504 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002505
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002506 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 min = (unsigned long *) table->extra1;
2508 max = (unsigned long *) table->extra2;
2509 vleft = table->maxlen / sizeof(unsigned long);
2510 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002511
2512 if (write) {
2513 if (left > PAGE_SIZE - 1)
2514 left = PAGE_SIZE - 1;
2515 page = __get_free_page(GFP_TEMPORARY);
2516 kbuf = (char *) page;
2517 if (!kbuf)
2518 return -ENOMEM;
2519 if (copy_from_user(kbuf, buffer, left)) {
2520 err = -EFAULT;
2521 goto free;
2522 }
2523 kbuf[left] = 0;
2524 }
2525
Eric Dumazet27b3d802010-10-07 12:59:29 -07002526 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002527 unsigned long val;
2528
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002530 bool neg;
2531
2532 left -= proc_skip_spaces(&kbuf);
2533
2534 err = proc_get_long(&kbuf, &left, &val, &neg,
2535 proc_wspace_sep,
2536 sizeof(proc_wspace_sep), NULL);
2537 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 break;
2539 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 continue;
2541 if ((min && val < *min) || (max && val > *max))
2542 continue;
2543 *i = val;
2544 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002545 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002547 err = proc_put_char(&buffer, &left, '\t');
2548 err = proc_put_long(&buffer, &left, val, false);
2549 if (err)
2550 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 }
2552 }
2553
Amerigo Wang00b7c332010-05-05 00:26:45 +00002554 if (!write && !first && left && !err)
2555 err = proc_put_char(&buffer, &left, '\n');
2556 if (write && !err)
2557 left -= proc_skip_spaces(&kbuf);
2558free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002560 free_page(page);
2561 if (first)
2562 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 *lenp -= left;
2565 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002566 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002569static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002570 void __user *buffer,
2571 size_t *lenp, loff_t *ppos,
2572 unsigned long convmul,
2573 unsigned long convdiv)
2574{
2575 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002577}
2578
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579/**
2580 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 * @buffer: the user buffer
2584 * @lenp: the size of the user buffer
2585 * @ppos: file position
2586 *
2587 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2588 * values from/to the user buffer, treated as an ASCII string.
2589 *
2590 * This routine will ensure the values are within the range specified by
2591 * table->extra1 (min) and table->extra2 (max).
2592 *
2593 * Returns 0 on success.
2594 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002595int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 void __user *buffer, size_t *lenp, loff_t *ppos)
2597{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002598 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599}
2600
2601/**
2602 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2603 * @table: the sysctl table
2604 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 * @buffer: the user buffer
2606 * @lenp: the size of the user buffer
2607 * @ppos: file position
2608 *
2609 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2610 * values from/to the user buffer, treated as an ASCII string. The values
2611 * are treated as milliseconds, and converted to jiffies when they are stored.
2612 *
2613 * This routine will ensure the values are within the range specified by
2614 * table->extra1 (min) and table->extra2 (max).
2615 *
2616 * Returns 0 on success.
2617 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002618int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 void __user *buffer,
2620 size_t *lenp, loff_t *ppos)
2621{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002622 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 lenp, ppos, HZ, 1000l);
2624}
2625
2626
Amerigo Wang00b7c332010-05-05 00:26:45 +00002627static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 int *valp,
2629 int write, void *data)
2630{
2631 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002632 if (*lvalp > LONG_MAX / HZ)
2633 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2635 } else {
2636 int val = *valp;
2637 unsigned long lval;
2638 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002639 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 lval = (unsigned long)-val;
2641 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002642 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 lval = (unsigned long)val;
2644 }
2645 *lvalp = lval / HZ;
2646 }
2647 return 0;
2648}
2649
Amerigo Wang00b7c332010-05-05 00:26:45 +00002650static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 int *valp,
2652 int write, void *data)
2653{
2654 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002655 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2656 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2658 } else {
2659 int val = *valp;
2660 unsigned long lval;
2661 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002662 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 lval = (unsigned long)-val;
2664 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002665 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 lval = (unsigned long)val;
2667 }
2668 *lvalp = jiffies_to_clock_t(lval);
2669 }
2670 return 0;
2671}
2672
Amerigo Wang00b7c332010-05-05 00:26:45 +00002673static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 int *valp,
2675 int write, void *data)
2676{
2677 if (write) {
2678 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2679 } else {
2680 int val = *valp;
2681 unsigned long lval;
2682 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002683 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 lval = (unsigned long)-val;
2685 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002686 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 lval = (unsigned long)val;
2688 }
2689 *lvalp = jiffies_to_msecs(lval);
2690 }
2691 return 0;
2692}
2693
2694/**
2695 * proc_dointvec_jiffies - read a vector of integers as seconds
2696 * @table: the sysctl table
2697 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 * @buffer: the user buffer
2699 * @lenp: the size of the user buffer
2700 * @ppos: file position
2701 *
2702 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2703 * values from/to the user buffer, treated as an ASCII string.
2704 * The values read are assumed to be in seconds, and are converted into
2705 * jiffies.
2706 *
2707 * Returns 0 on success.
2708 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002709int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 void __user *buffer, size_t *lenp, loff_t *ppos)
2711{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002712 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 do_proc_dointvec_jiffies_conv,NULL);
2714}
2715
2716/**
2717 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2718 * @table: the sysctl table
2719 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 * @buffer: the user buffer
2721 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002722 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 *
2724 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2725 * values from/to the user buffer, treated as an ASCII string.
2726 * The values read are assumed to be in 1/USER_HZ seconds, and
2727 * are converted into jiffies.
2728 *
2729 * Returns 0 on success.
2730 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002731int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 void __user *buffer, size_t *lenp, loff_t *ppos)
2733{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002734 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 do_proc_dointvec_userhz_jiffies_conv,NULL);
2736}
2737
2738/**
2739 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2740 * @table: the sysctl table
2741 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 * @buffer: the user buffer
2743 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002744 * @ppos: file position
2745 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 *
2747 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2748 * values from/to the user buffer, treated as an ASCII string.
2749 * The values read are assumed to be in 1/1000 seconds, and
2750 * are converted into jiffies.
2751 *
2752 * Returns 0 on success.
2753 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002754int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 void __user *buffer, size_t *lenp, loff_t *ppos)
2756{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002757 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 do_proc_dointvec_ms_jiffies_conv, NULL);
2759}
2760
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002761static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002762 void __user *buffer, size_t *lenp, loff_t *ppos)
2763{
2764 struct pid *new_pid;
2765 pid_t tmp;
2766 int r;
2767
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002768 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002769
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002770 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002771 lenp, ppos, NULL, NULL);
2772 if (r || !write)
2773 return r;
2774
2775 new_pid = find_get_pid(tmp);
2776 if (!new_pid)
2777 return -ESRCH;
2778
2779 put_pid(xchg(&cad_pid, new_pid));
2780 return 0;
2781}
2782
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002783/**
2784 * proc_do_large_bitmap - read/write from/to a large bitmap
2785 * @table: the sysctl table
2786 * @write: %TRUE if this is a write to the sysctl file
2787 * @buffer: the user buffer
2788 * @lenp: the size of the user buffer
2789 * @ppos: file position
2790 *
2791 * The bitmap is stored at table->data and the bitmap length (in bits)
2792 * in table->maxlen.
2793 *
2794 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2795 * large bitmaps may be represented in a compact manner. Writing into
2796 * the file will clear the bitmap then update it with the given input.
2797 *
2798 * Returns 0 on success.
2799 */
2800int proc_do_large_bitmap(struct ctl_table *table, int write,
2801 void __user *buffer, size_t *lenp, loff_t *ppos)
2802{
2803 int err = 0;
2804 bool first = 1;
2805 size_t left = *lenp;
2806 unsigned long bitmap_len = table->maxlen;
2807 unsigned long *bitmap = (unsigned long *) table->data;
2808 unsigned long *tmp_bitmap = NULL;
2809 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2810
2811 if (!bitmap_len || !left || (*ppos && !write)) {
2812 *lenp = 0;
2813 return 0;
2814 }
2815
2816 if (write) {
2817 unsigned long page = 0;
2818 char *kbuf;
2819
2820 if (left > PAGE_SIZE - 1)
2821 left = PAGE_SIZE - 1;
2822
2823 page = __get_free_page(GFP_TEMPORARY);
2824 kbuf = (char *) page;
2825 if (!kbuf)
2826 return -ENOMEM;
2827 if (copy_from_user(kbuf, buffer, left)) {
2828 free_page(page);
2829 return -EFAULT;
2830 }
2831 kbuf[left] = 0;
2832
2833 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2834 GFP_KERNEL);
2835 if (!tmp_bitmap) {
2836 free_page(page);
2837 return -ENOMEM;
2838 }
2839 proc_skip_char(&kbuf, &left, '\n');
2840 while (!err && left) {
2841 unsigned long val_a, val_b;
2842 bool neg;
2843
2844 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2845 sizeof(tr_a), &c);
2846 if (err)
2847 break;
2848 if (val_a >= bitmap_len || neg) {
2849 err = -EINVAL;
2850 break;
2851 }
2852
2853 val_b = val_a;
2854 if (left) {
2855 kbuf++;
2856 left--;
2857 }
2858
2859 if (c == '-') {
2860 err = proc_get_long(&kbuf, &left, &val_b,
2861 &neg, tr_b, sizeof(tr_b),
2862 &c);
2863 if (err)
2864 break;
2865 if (val_b >= bitmap_len || neg ||
2866 val_a > val_b) {
2867 err = -EINVAL;
2868 break;
2869 }
2870 if (left) {
2871 kbuf++;
2872 left--;
2873 }
2874 }
2875
2876 while (val_a <= val_b)
2877 set_bit(val_a++, tmp_bitmap);
2878
2879 first = 0;
2880 proc_skip_char(&kbuf, &left, '\n');
2881 }
2882 free_page(page);
2883 } else {
2884 unsigned long bit_a, bit_b = 0;
2885
2886 while (left) {
2887 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2888 if (bit_a >= bitmap_len)
2889 break;
2890 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2891 bit_a + 1) - 1;
2892
2893 if (!first) {
2894 err = proc_put_char(&buffer, &left, ',');
2895 if (err)
2896 break;
2897 }
2898 err = proc_put_long(&buffer, &left, bit_a, false);
2899 if (err)
2900 break;
2901 if (bit_a != bit_b) {
2902 err = proc_put_char(&buffer, &left, '-');
2903 if (err)
2904 break;
2905 err = proc_put_long(&buffer, &left, bit_b, false);
2906 if (err)
2907 break;
2908 }
2909
2910 first = 0; bit_b++;
2911 }
2912 if (!err)
2913 err = proc_put_char(&buffer, &left, '\n');
2914 }
2915
2916 if (!err) {
2917 if (write) {
2918 if (*ppos)
2919 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2920 else
2921 memcpy(bitmap, tmp_bitmap,
2922 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2923 }
2924 kfree(tmp_bitmap);
2925 *lenp -= left;
2926 *ppos += *lenp;
2927 return 0;
2928 } else {
2929 kfree(tmp_bitmap);
2930 return err;
2931 }
2932}
2933
Jovi Zhang55610502011-01-12 17:00:45 -08002934#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002936int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 void __user *buffer, size_t *lenp, loff_t *ppos)
2938{
2939 return -ENOSYS;
2940}
2941
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002942int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 void __user *buffer, size_t *lenp, loff_t *ppos)
2944{
2945 return -ENOSYS;
2946}
2947
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002948int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 void __user *buffer, size_t *lenp, loff_t *ppos)
2950{
2951 return -ENOSYS;
2952}
2953
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002954int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 void __user *buffer, size_t *lenp, loff_t *ppos)
2956{
2957 return -ENOSYS;
2958}
2959
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002960int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 void __user *buffer, size_t *lenp, loff_t *ppos)
2962{
2963 return -ENOSYS;
2964}
2965
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002966int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 void __user *buffer, size_t *lenp, loff_t *ppos)
2968{
2969 return -ENOSYS;
2970}
2971
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002972int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 void __user *buffer, size_t *lenp, loff_t *ppos)
2974{
2975 return -ENOSYS;
2976}
2977
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002978int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 void __user *buffer,
2980 size_t *lenp, loff_t *ppos)
2981{
2982 return -ENOSYS;
2983}
2984
2985
Jovi Zhang55610502011-01-12 17:00:45 -08002986#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988/*
2989 * No sense putting this after each symbol definition, twice,
2990 * exception granted :-)
2991 */
2992EXPORT_SYMBOL(proc_dointvec);
2993EXPORT_SYMBOL(proc_dointvec_jiffies);
2994EXPORT_SYMBOL(proc_dointvec_minmax);
2995EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2996EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2997EXPORT_SYMBOL(proc_dostring);
2998EXPORT_SYMBOL(proc_doulongvec_minmax);
2999EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3000EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003001EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002EXPORT_SYMBOL(unregister_sysctl_table);